This commit is contained in:
2025-05-12 05:38:44 +09:00
parent dced21c3f8
commit 6d78bfa46e
8120 changed files with 1161564 additions and 0 deletions

86
book/node_modules/responselike/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,86 @@
import {Buffer} from 'node:buffer';
import {Readable as ReadableStream} from 'node:stream';
export type Options = {
/**
The HTTP response status code.
*/
readonly statusCode: number;
/**
The HTTP headers object.
Keys are in lowercase.
*/
readonly headers: Record<string, string>;
/**
The response body.
The contents will be streamable but is also exposed directly as `response.body`.
*/
readonly body: Buffer;
/**
The request URL string.
*/
readonly url: string;
};
/**
Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage).
@example
```
import Response from 'responselike';
const response = new Response({
statusCode: 200,
headers: {
foo: 'bar'
},
body: Buffer.from('Hi!'),
url: 'https://example.com'
});
response.statusCode;
// 200
response.headers;
// {foo: 'bar'}
response.body;
// <Buffer 48 69 21>
response.url;
// 'https://example.com'
response.pipe(process.stdout);
// 'Hi!'
```
*/
export default class Response extends ReadableStream {
/**
The HTTP response status code.
*/
readonly statusCode: number;
/**
The HTTP headers.
Keys will be automatically lowercased.
*/
readonly headers: Record<string, string>;
/**
The response body.
*/
readonly body: Buffer;
/**
The request URL string.
*/
readonly url: string;
constructor(options?: Options);
}

39
book/node_modules/responselike/index.js generated vendored Normal file
View File

@ -0,0 +1,39 @@
import {Readable as ReadableStream} from 'node:stream';
import lowercaseKeys from 'lowercase-keys';
export default class Response extends ReadableStream {
statusCode;
headers;
body;
url;
constructor({statusCode, headers, body, url}) {
if (typeof statusCode !== 'number') {
throw new TypeError('Argument `statusCode` should be a number');
}
if (typeof headers !== 'object') {
throw new TypeError('Argument `headers` should be an object');
}
if (!(body instanceof Uint8Array)) {
throw new TypeError('Argument `body` should be a buffer');
}
if (typeof url !== 'string') {
throw new TypeError('Argument `url` should be a string');
}
super({
read() {
this.push(body);
this.push(null);
},
});
this.statusCode = statusCode;
this.headers = lowercaseKeys(headers);
this.body = body;
this.url = url;
}
}

10
book/node_modules/responselike/license generated vendored Normal file
View File

@ -0,0 +1,10 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Copyright (c) Luke Childs <lukechilds123@gmail.com> (https://lukechilds.co.uk)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

39
book/node_modules/responselike/package.json generated vendored Normal file
View File

@ -0,0 +1,39 @@
{
"name": "responselike",
"version": "3.0.0",
"description": "A response-like object for mocking a Node.js HTTP response stream",
"license": "MIT",
"repository": "sindresorhus/responselike",
"funding": "https://github.com/sponsors/sindresorhus",
"author": "Luke Childs <lukechilds123@gmail.com> (https://lukechilds.co.uk)",
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"http",
"https",
"response",
"mock",
"test",
"request",
"responselike"
],
"dependencies": {
"lowercase-keys": "^3.0.0"
},
"devDependencies": {
"ava": "^4.3.1",
"get-stream": "^6.0.1",
"tsd": "^0.22.0",
"xo": "^0.50.0"
}
}

75
book/node_modules/responselike/readme.md generated vendored Normal file
View File

@ -0,0 +1,75 @@
# responselike
> A response-like object for mocking a Node.js HTTP response stream
Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage). Useful for formatting cached responses so they can be consumed by code expecting a real response.
## Install
```sh
npm install responselike
```
## Usage
```js
import Response from 'responselike';
const response = new Response({
statusCode: 200,
headers: {
foo: 'bar'
},
body: Buffer.from('Hi!'),
url: 'https://example.com'
});
response.statusCode;
// 200
response.headers;
// {foo: 'bar'}
response.body;
// <Buffer 48 69 21>
response.url;
// 'https://example.com'
response.pipe(process.stdout);
// 'Hi!'
```
## API
### new Response(options?)
Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage).
#### options
Type: `object`
##### statusCode
Type: `number`
The HTTP response status code.
##### headers
Type: `object`
The HTTP headers. Keys will be automatically lowercased.
##### body
Type: `Buffer`
The response body. The Buffer contents will be streamable but is also exposed directly as `response.body`.
##### url
Type: `string`
The request URL string.