added doga

This commit is contained in:
szabomarton
2025-02-25 09:55:29 +01:00
parent 5174ab4cc4
commit 13254e5623
1149 changed files with 80161 additions and 0 deletions

21
25_02_24/node_modules/@tinyhttp/send/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 v 1 r t l
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.

110
25_02_24/node_modules/@tinyhttp/send/README.md generated vendored Normal file
View File

@@ -0,0 +1,110 @@
# @tinyhttp/send
[![npm (scoped)][npm-badge]](https://npmjs.com/package/@tinyhttp/send)
[![npm][dl-badge]](https://npmjs.com/package/@tinyhttp/send)
[![][web-badge]](https://tinyhttp.v1rtl.site/mw/send)
Extensions for sending a response, including `send`, `sendStatus`, `status`,
`sendFile` and `json`. Works with any backend framework.
## Install
```sh
pnpm i @tinyhttp/send
```
## API
```js
import { json, send, sendStatus, status } from '@tinyhttp/send'
```
### `send(body)` [![][doc-badge]](https://tinyhttp.v1rtl.site/docs#ressend)
Sends the HTTP response.
The body parameter can be a Buffer object, a string, an object, or an array.
##### Example
```ts
res.send(Buffer.from('whoop'))
res.send({ some: 'json' })
res.send('<p>some html</p>')
res.status(404).send('Sorry, we cannot find that!')
res.status(500).send({ error: 'something blew up' })
```
### `json(body)` [![][doc-badge]](https://tinyhttp.v1rtl.site/docs#resjson)
Sends a JSON response. This method sends a response (with the correct
content-type) that is the parameter converted to a JSON string using
[`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
The parameter can be any JSON type, including object, array, string, boolean,
number, or null, and you can also use it to convert other values to JSON.
##### Example
```ts
res.json(null)
res.json({ user: 'tobi' })
res.status(500).json({ error: 'message' })
```
### `status(number)` [![][doc-badge]](https://tinyhttp.v1rtl.site/docs#resstatus)
Sets the HTTP status for the response. It is a chainable alias of Nodes
`response.statusCode`.
##### Example
```ts
res.status(403).end()
res.status(400).send('Bad Request')
```
### `sendStatus` [![][doc-badge]](https://tinyhttp.v1rtl.site/docs#ressendstatus)
Sets the response HTTP status code to statusCode and send its string
representation as the response body.
##### Example
```ts
res.sendStatus(200) // equivalent to res.status(200).send('OK')
res.sendStatus(403) // equivalent to res.status(403).send('Forbidden')
res.sendStatus(404) // equivalent to res.status(404).send('Not Found')
res.sendStatus(500) // equivalent to res.status(500).send('Internal Server Error')
```
If an unsupported status code is specified, the HTTP status is still set to
statusCode and the string version of the code is sent as the response body.
### `sendFile` [![][doc-badge]](https://tinyhttp.v1rtl.site/docs#ressendfile)
Sends a file by piping a stream to response. It also checks for extension to set
a proper `Content-Type` header.
> Path argument must be absolute. To use a relative path, specify the `root`
> option first.
##### Example
```js
res.sendFile('song.mp3', { root: process.cwd() }, (err) => console.log(err))
```
## Example
```js
import { createServer } from 'node:http'
import { send } from '@tinyhttp/send'
createServer((req, res) => send(req, res)('Hello World')).listen(3000)
```
[npm-badge]: https://img.shields.io/npm/v/@tinyhttp/send?style=flat-square
[dl-badge]: https://img.shields.io/npm/dt/@tinyhttp/send?style=flat-square
[web-badge]: https://img.shields.io/badge/website-visit-hotpink?style=flat-square
[doc-badge]: https://img.shields.io/badge/-docs-hotpink?style=flat-square

6
25_02_24/node_modules/@tinyhttp/send/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
export * from './json.js';
export * from './send.js';
export * from './sendStatus.js';
export * from './status.js';
export * from './sendFile.js';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}

6
25_02_24/node_modules/@tinyhttp/send/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
export * from './json.js';
export * from './send.js';
export * from './sendStatus.js';
export * from './status.js';
export * from './sendFile.js';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}

9
25_02_24/node_modules/@tinyhttp/send/dist/json.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { ServerResponse as S } from 'node:http';
type Res = Pick<S, 'setHeader' | 'end' | 'removeHeader'>;
/**
* Respond with stringified JSON object
* @param res Response
*/
export declare const json: <Response extends Res = Res>(res: Response) => (body: any, ...args: any[]) => Response;
export {};
//# sourceMappingURL=json.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AAEpD,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,cAAc,CAAC,CAAA;AAExD;;;GAGG;AACH,eAAO,MAAM,IAAI,GACd,QAAQ,SAAS,GAAG,aAAa,QAAQ,YACnC,GAAG,WAAW,GAAG,EAAE,KAAG,QAY5B,CAAA"}

18
25_02_24/node_modules/@tinyhttp/send/dist/json.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
/**
* Respond with stringified JSON object
* @param res Response
*/
export const json = (res) => (body, ...args) => {
res.setHeader('Content-Type', 'application/json');
if ((typeof body === 'number' || typeof body === 'boolean' || typeof body === 'object') && body != null)
res.end(JSON.stringify(body, null, 2), ...args);
else if (typeof body === 'string')
res.end(body, ...args);
else {
res.removeHeader('Content-Length');
res.removeHeader('Transfer-Encoding');
res.end(null, ...args);
}
return res;
};
//# sourceMappingURL=json.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GACf,CAA6B,GAAa,EAAE,EAAE,CAC9C,CAAC,IAAS,EAAE,GAAG,IAAW,EAAY,EAAE;IACtC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;IACjD,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,IAAI,IAAI;QACrG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;SAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;SACpD,CAAC;QACJ,GAAG,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;QAClC,GAAG,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAA;QACrC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}

19
25_02_24/node_modules/@tinyhttp/send/dist/send.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import type { IncomingMessage as I, ServerResponse as S } from 'node:http';
type Req = Pick<I, 'method'> & {
fresh?: boolean;
};
type Res = Pick<S, 'setHeader' | 'removeHeader' | 'end' | 'getHeader' | 'statusCode'>;
/**
* Sends the HTTP response.
*
* The body parameter can be a Buffer object, a string, an object, or an array.
*
* This method performs many useful tasks for simple non-streaming responses.
* For example, it automatically assigns the Content-Length HTTP response header field (unless previously defined) and provides automatic HEAD and HTTP cache freshness support.
*
* @param req Request
* @param res Response
*/
export declare const send: <Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response) => (body: any) => Response;
export {};
//# sourceMappingURL=send.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../src/send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,IAAI,CAAC,EAAE,cAAc,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AAI1E,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAElD,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,cAAc,GAAG,KAAK,GAAG,WAAW,GAAG,YAAY,CAAC,CAAA;AAErF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI,GACd,OAAO,SAAS,GAAG,QAAQ,QAAQ,SAAS,GAAG,aAAa,OAAO,OAAO,QAAQ,YAC5E,GAAG,KAAG,QA0DZ,CAAA"}

73
25_02_24/node_modules/@tinyhttp/send/dist/send.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
import { json } from './json.js';
import { createETag, setCharset } from './utils.js';
/**
* Sends the HTTP response.
*
* The body parameter can be a Buffer object, a string, an object, or an array.
*
* This method performs many useful tasks for simple non-streaming responses.
* For example, it automatically assigns the Content-Length HTTP response header field (unless previously defined) and provides automatic HEAD and HTTP cache freshness support.
*
* @param req Request
* @param res Response
*/
export const send = (req, res) => (body) => {
let bodyToSend = body;
if (Buffer.isBuffer(body)) {
bodyToSend = body;
}
else if (typeof body === 'object' && body !== null) {
// in case of object - turn it to json
bodyToSend = JSON.stringify(body, null, 2);
}
else if (typeof body === 'string') {
// reflect this in content-type
const type = res.getHeader('Content-Type');
if (type && typeof type === 'string') {
res.setHeader('Content-Type', setCharset(type, 'utf-8'));
}
else
res.setHeader('Content-Type', setCharset('text/html', 'utf-8'));
}
// Set encoding
const encoding = 'utf8';
// populate ETag
let etag;
if (body && !res.getHeader('etag') && (etag = createETag(bodyToSend, encoding))) {
res.setHeader('etag', etag);
}
// freshness
if (req.fresh)
res.statusCode = 304;
// strip irrelevant headers
if (res.statusCode === 204 || res.statusCode === 304) {
res.removeHeader('Content-Type');
res.removeHeader('Content-Length');
res.removeHeader('Transfer-Encoding');
bodyToSend = '';
}
if (req.method === 'HEAD') {
res.end('');
return res;
}
if (typeof body === 'object') {
if (body == null) {
res.end('');
return res;
}
if (Buffer.isBuffer(body)) {
if (!res.getHeader('Content-Type'))
res.setHeader('content-type', 'application/octet-stream');
res.end(bodyToSend);
}
else
json(res)(bodyToSend, encoding);
}
else {
if (typeof bodyToSend !== 'string')
bodyToSend = bodyToSend.toString();
res.end(bodyToSend, encoding);
}
return res;
};
//# sourceMappingURL=send.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"send.js","sourceRoot":"","sources":["../src/send.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAMnD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,IAAI,GACf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U,KAAK,GAAG,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;QACrD,GAAG,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;QAChC,GAAG,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;QAClC,GAAG,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAA;QACrC,UAAU,GAAG,EAAE,CAAA;IACjB,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACX,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC;gBAAE,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,0BAA0B,CAAC,CAAA;YAC7F,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACrB,CAAC;;YAAM,IAAI,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACxC,CAAC;SAAM,CAAC;QACN,IAAI,OAAO,UAAU,KAAK,QAAQ;YAAE,UAAU,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAA;QAEtE,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}

View File

@@ -0,0 +1,39 @@
import type { IncomingMessage as I, ServerResponse as S } from 'node:http';
export type ReadStreamOptions = Partial<{
flags: string;
encoding: BufferEncoding;
fd: number;
mode: number;
autoClose: boolean;
emitClose: boolean;
start: number;
end: number;
highWaterMark: number;
}>;
export type SendFileOptions = ReadStreamOptions & Partial<{
root: string;
headers: Record<string, any>;
caching: Partial<{
maxAge: number;
immutable: boolean;
}>;
}>;
export type Caching = Partial<{
maxAge: number;
immutable: boolean;
}>;
type Req = Pick<I, 'headers'>;
type Res = Pick<S, 'setHeader' | 'statusCode' | 'writeHead' | 'getHeader'> & NodeJS.WritableStream;
export declare const enableCaching: (res: Res, caching: Caching) => void;
/**
* Sends a file by piping a stream to response.
*
* It also checks for extension to set a proper `Content-Type` header.
*
* Path argument must be absolute. To use a relative path, specify the `root` option first.
*
* @param res Response
*/
export declare const sendFile: <Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response) => (path: string, opts?: SendFileOptions, cb?: (err?: any) => void) => Response;
export {};
//# sourceMappingURL=sendFile.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sendFile.d.ts","sourceRoot":"","sources":["../src/sendFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,IAAI,CAAC,EAAE,cAAc,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AAM1E,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,cAAc,CAAA;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,EAAE,MAAM,CAAA;CACtB,CAAC,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAC7C,OAAO,CAAC;IACN,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,OAAO,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,MAAM,CAAA;QACd,SAAS,EAAE,OAAO,CAAA;KACnB,CAAC,CAAA;CACH,CAAC,CAAA;AAEJ,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;CACnB,CAAC,CAAA;AAEF,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AAE7B,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,MAAM,CAAC,cAAc,CAAA;AAElG,eAAO,MAAM,aAAa,QAAS,GAAG,WAAW,OAAO,KAAG,IAM1D,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,GAClB,OAAO,SAAS,GAAG,QAAQ,QAAQ,SAAS,GAAG,aAAa,OAAO,OAAO,QAAQ,YAC5E,MAAM,SAAQ,eAAe,OAAY,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,KAAG,QAqDrE,CAAA"}

67
25_02_24/node_modules/@tinyhttp/send/dist/sendFile.js generated vendored Normal file
View File

@@ -0,0 +1,67 @@
import { createReadStream, statSync } from 'node:fs';
import { extname, isAbsolute } from 'node:path';
import { join } from 'node:path';
import mime from 'mime';
import { createETag } from './utils.js';
export const enableCaching = (res, caching) => {
let cc = caching.maxAge != null && `public,max-age=${caching.maxAge}`;
if (cc && caching.immutable)
cc += ',immutable';
else if (cc && caching.maxAge === 0)
cc += ',must-revalidate';
if (cc)
res.setHeader('Cache-Control', cc);
};
/**
* Sends a file by piping a stream to response.
*
* It also checks for extension to set a proper `Content-Type` header.
*
* Path argument must be absolute. To use a relative path, specify the `root` option first.
*
* @param res Response
*/
export const sendFile = (req, res) => (path, opts = {}, cb) => {
const { root, headers = {}, encoding = 'utf-8', caching, ...options } = opts;
if (!isAbsolute(path) && !root)
throw new TypeError('path must be absolute');
if (caching)
enableCaching(res, caching);
const filePath = root ? join(root, path) : path;
const stats = statSync(filePath);
headers['Content-Encoding'] = encoding;
headers['Last-Modified'] = stats.mtime.toUTCString();
headers.ETag = createETag(stats, encoding);
if (!res.getHeader('Content-Type'))
headers['Content-Type'] = `${mime.getType(extname(path))}; charset=utf-8`;
let status = res.statusCode || 200;
if (req.headers.range) {
status = 206;
const [x, y] = req.headers.range.replace('bytes=', '').split('-');
const end = (options.end = Number.parseInt(y, 10) || stats.size - 1);
const start = (options.start = Number.parseInt(x, 10) || 0);
if (start >= stats.size || end >= stats.size) {
res
.writeHead(416, {
'Content-Range': `bytes */${stats.size}`
})
.end();
return res;
}
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
headers['Content-Length'] = end - start + 1;
headers['Accept-Ranges'] = 'bytes';
}
else {
headers['Content-Length'] = stats.size;
}
for (const [k, v] of Object.entries(headers))
res.setHeader(k, v);
res.writeHead(status, headers);
const stream = createReadStream(filePath, options);
if (cb)
stream.on('error', (err) => cb(err)).on('end', () => cb());
stream.pipe(res);
return res;
};
//# sourceMappingURL=sendFile.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sendFile.js","sourceRoot":"","sources":["../src/sendFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAiCvC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAE,OAAgB,EAAQ,EAAE;IAChE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,IAAI,kBAAkB,OAAO,CAAC,MAAM,EAAE,CAAA;IACrE,IAAI,EAAE,IAAI,OAAO,CAAC,SAAS;QA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;QAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEjE,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE9B,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAElD,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IAElE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEhB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}

View File

@@ -0,0 +1,14 @@
import type { IncomingMessage as I, ServerResponse as S } from 'node:http';
type Req = Pick<I, 'method'>;
type Res = Pick<S, 'setHeader' | 'removeHeader' | 'end' | 'getHeader' | 'statusCode'>;
/**
* Sets the response HTTP status code to statusCode and send its string representation as the response body.
*
* If an unsupported status code is specified, the HTTP status is still set to statusCode and the string version of the code is sent as the response body.
*
* @param req Request
* @param res Response
*/
export declare const sendStatus: <Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response) => (statusCode: number) => Response;
export {};
//# sourceMappingURL=sendStatus.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sendStatus.d.ts","sourceRoot":"","sources":["../src/sendStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,IAAI,CAAC,EAAE,cAAc,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AAI1E,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AAE5B,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,cAAc,GAAG,KAAK,GAAG,WAAW,GAAG,YAAY,CAAC,CAAA;AAErF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACpB,OAAO,SAAS,GAAG,QAAQ,QAAQ,SAAS,GAAG,aAAa,OAAO,OAAO,QAAQ,kBACtE,MAAM,KAAG,QAQrB,CAAA"}

View File

@@ -0,0 +1,17 @@
import { STATUS_CODES } from 'node:http';
import { send } from './send.js';
/**
* Sets the response HTTP status code to statusCode and send its string representation as the response body.
*
* If an unsupported status code is specified, the HTTP status is still set to statusCode and the string version of the code is sent as the response body.
*
* @param req Request
* @param res Response
*/
export const sendStatus = (req, res) => (statusCode) => {
const body = STATUS_CODES[statusCode] || String(statusCode);
res.statusCode = statusCode;
res.setHeader('Content-Type', 'text/plain');
return send(req, res)(body);
};
//# sourceMappingURL=sendStatus.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sendStatus.js","sourceRoot":"","sources":["../src/sendStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAMhC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,CAAwD,GAAY,EAAE,GAAa,EAAE,EAAE,CACvF,CAAC,UAAkB,EAAY,EAAE;IAC/B,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,CAAA;IAE3D,GAAG,CAAC,UAAU,GAAG,UAAU,CAAA;IAE3B,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;IAE3C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC,CAAA"}

10
25_02_24/node_modules/@tinyhttp/send/dist/status.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import type { ServerResponse } from 'node:http';
type Res = Pick<ServerResponse, 'statusCode'>;
/**
* Sets the HTTP status for the response. It is a chainable alias of Nodes `response.statusCode`.
*
* @param res Response
*/
export declare const status: <Response extends Res = Res>(res: Response) => (status: number) => Response;
export {};
//# sourceMappingURL=status.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,KAAK,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;AAE7C;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAChB,QAAQ,SAAS,GAAG,aAAa,QAAQ,cACjC,MAAM,KAAG,QAIjB,CAAA"}

10
25_02_24/node_modules/@tinyhttp/send/dist/status.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
/**
* Sets the HTTP status for the response. It is a chainable alias of Nodes `response.statusCode`.
*
* @param res Response
*/
export const status = (res) => (status) => {
res.statusCode = status;
return res;
};
//# sourceMappingURL=status.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"status.js","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,CAA6B,GAAa,EAAE,EAAE,CAC9C,CAAC,MAAc,EAAY,EAAE;IAC3B,GAAG,CAAC,UAAU,GAAG,MAAM,CAAA;IAEvB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}

4
25_02_24/node_modules/@tinyhttp/send/dist/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { Stats } from 'node:fs';
export declare const createETag: (body: Buffer | string | Stats, encoding: BufferEncoding) => string;
export declare function setCharset(type: string, charset: string): string;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAI/B,eAAO,MAAM,UAAU,SAAU,MAAM,GAAG,MAAM,GAAG,KAAK,YAAY,cAAc,KAAG,MAKpF,CAAA;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIhE"}

15
25_02_24/node_modules/@tinyhttp/send/dist/utils.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import { Stats } from 'node:fs';
import { format, parse } from '@tinyhttp/content-type';
import { eTag } from '@tinyhttp/etag';
export const createETag = (body, encoding) => {
if (body instanceof Stats) {
return eTag(body, { weak: true });
}
return eTag(!Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body, { weak: true });
};
export function setCharset(type, charset) {
const parsed = parse(type);
parsed.parameters.charset = charset;
return format(parsed);
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAErC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA6B,EAAE,QAAwB,EAAU,EAAE;IAC5F,IAAI,IAAI,YAAY,KAAK,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACnC,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;AAC1F,CAAC,CAAA;AAED,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,OAAe;IACtD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CACzB;IAAC,MAAM,CAAC,UAAqC,CAAC,OAAO,GAAG,OAAO,CAAA;IAChE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;AACvB,CAAC"}

37
25_02_24/node_modules/@tinyhttp/send/package.json generated vendored Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "@tinyhttp/send",
"version": "2.2.3",
"type": "module",
"description": "json, send, sendFile, status and sendStatus methods for tinyhttp",
"homepage": "https://tinyhttp.v1rtl.site",
"repository": {
"type": "git",
"url": "https://github.com/tinyhttp/tinyhttp.git",
"directory": "packages/res"
},
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"keywords": [
"tinyhttp",
"node.js",
"web framework",
"web",
"backend",
"res",
"send",
"send-file"
],
"engines": {
"node": ">=12.20.0"
},
"author": "v1rtl",
"license": "MIT",
"dependencies": {
"@tinyhttp/content-type": "^0.1.4",
"mime": "4.0.4",
"@tinyhttp/etag": "2.1.2"
},
"scripts": {
"build": "tsc"
}
}

File diff suppressed because one or more lines are too long