@ddd-ts-kit/http 0.98.0 → 0.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.fr.md +119 -8
- package/README.md +108 -6
- package/dist/error/answered-edge-error.d.ts +32 -0
- package/dist/error/answered-edge-error.d.ts.map +1 -0
- package/dist/error/answered-edge-error.js +79 -0
- package/dist/error/answered-edge-error.js.map +1 -0
- package/dist/error/code-of-status.d.ts +3 -0
- package/dist/error/code-of-status.d.ts.map +1 -0
- package/dist/error/code-of-status.js +7 -0
- package/dist/error/code-of-status.js.map +1 -0
- package/dist/error/edge-answer.d.ts +12 -0
- package/dist/error/edge-answer.d.ts.map +1 -0
- package/dist/error/edge-answer.js +18 -0
- package/dist/error/edge-answer.js.map +1 -0
- package/dist/error/edge-refusal.d.ts +15 -0
- package/dist/error/edge-refusal.d.ts.map +1 -0
- package/dist/error/edge-refusal.js +21 -0
- package/dist/error/edge-refusal.js.map +1 -0
- package/dist/error/refusal-headers.d.ts +9 -0
- package/dist/error/refusal-headers.d.ts.map +1 -0
- package/dist/error/refusal-headers.js +37 -0
- package/dist/error/refusal-headers.js.map +1 -0
- package/dist/error/status-title.d.ts.map +1 -1
- package/dist/error/status-title.js +2 -25
- package/dist/error/status-title.js.map +1 -1
- package/dist/error/statuses.d.ts +14 -0
- package/dist/error/statuses.d.ts.map +1 -0
- package/dist/error/statuses.js +33 -0
- package/dist/error/statuses.js.map +1 -0
- package/dist/express/mount-express.js +2 -1
- package/dist/express/mount-express.js.map +1 -1
- package/dist/express/problem-error-handler.d.ts +12 -0
- package/dist/express/problem-error-handler.d.ts.map +1 -0
- package/dist/express/problem-error-handler.js +22 -0
- package/dist/express/problem-error-handler.js.map +1 -0
- package/dist/express.d.ts +2 -0
- package/dist/express.d.ts.map +1 -1
- package/dist/express.js +1 -0
- package/dist/express.js.map +1 -1
- package/dist/fastify/mount-fastify.d.ts +4 -3
- package/dist/fastify/mount-fastify.d.ts.map +1 -1
- package/dist/fastify/mount-fastify.js +27 -4
- package/dist/fastify/mount-fastify.js.map +1 -1
- package/dist/fastify/problem-error-handler.d.ts +13 -0
- package/dist/fastify/problem-error-handler.d.ts.map +1 -0
- package/dist/fastify/problem-error-handler.js +15 -0
- package/dist/fastify/problem-error-handler.js.map +1 -0
- package/dist/fastify.d.ts +2 -0
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +1 -0
- package/dist/fastify.js.map +1 -1
- package/dist/hono/edge-problem.d.ts +1 -7
- package/dist/hono/edge-problem.d.ts.map +1 -1
- package/dist/hono/edge-problem.js +3 -11
- package/dist/hono/edge-problem.js.map +1 -1
- package/dist/hono/problem-error-handler.d.ts +12 -0
- package/dist/hono/problem-error-handler.d.ts.map +1 -0
- package/dist/hono/problem-error-handler.js +14 -0
- package/dist/hono/problem-error-handler.js.map +1 -0
- package/dist/hono/read-body.d.ts +1 -1
- package/dist/hono/read-body.d.ts.map +1 -1
- package/dist/hono/read-body.js +3 -16
- package/dist/hono/read-body.js.map +1 -1
- package/dist/hono.d.ts +2 -0
- package/dist/hono.d.ts.map +1 -1
- package/dist/hono.js +1 -0
- package/dist/hono.js.map +1 -1
- package/dist/nest/is-unread-json-body.d.ts +9 -0
- package/dist/nest/is-unread-json-body.d.ts.map +1 -0
- package/dist/nest/is-unread-json-body.js +26 -0
- package/dist/nest/is-unread-json-body.js.map +1 -0
- package/dist/nest/problem-exception-filter.d.ts +19 -0
- package/dist/nest/problem-exception-filter.d.ts.map +1 -0
- package/dist/nest/problem-exception-filter.js +45 -0
- package/dist/nest/problem-exception-filter.js.map +1 -0
- package/dist/nest.d.ts +2 -0
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +1 -0
- package/dist/nest.js.map +1 -1
- package/dist/pipeline/execute-route.d.ts.map +1 -1
- package/dist/pipeline/execute-route.js +1 -1
- package/dist/pipeline/execute-route.js.map +1 -1
- package/dist/pipeline/problem-content-type.d.ts +3 -0
- package/dist/pipeline/problem-content-type.d.ts.map +1 -0
- package/dist/pipeline/problem-content-type.js +3 -0
- package/dist/pipeline/problem-content-type.js.map +1 -0
- package/dist/testing/route-of-options.d.ts +18 -0
- package/dist/testing/route-of-options.d.ts.map +1 -0
- package/dist/testing/route-of-options.js +2 -0
- package/dist/testing/route-of-options.js.map +1 -0
- package/dist/testing/route-of.d.ts +21 -0
- package/dist/testing/route-of.d.ts.map +1 -0
- package/dist/testing/route-of.js +49 -0
- package/dist/testing/route-of.js.map +1 -0
- package/dist/testing/route-under-test.d.ts +13 -0
- package/dist/testing/route-under-test.d.ts.map +1 -0
- package/dist/testing/route-under-test.js +2 -0
- package/dist/testing/route-under-test.js.map +1 -0
- package/dist/testing/sent-request.d.ts +13 -0
- package/dist/testing/sent-request.d.ts.map +1 -0
- package/dist/testing/sent-request.js +2 -0
- package/dist/testing/sent-request.js.map +1 -0
- package/dist/testing.d.ts +5 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +2 -0
- package/dist/testing.js.map +1 -0
- package/package.json +8 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The headers a refusal carries for its client, by lower-case name: `headers` of an error of
|
|
3
|
+
* http-errors (Express, Nest over Express) or of Fastify, the headers of the response a Hono
|
|
4
|
+
* `HTTPException` holds (`res`). A 401 keeps its `WWW-Authenticate`, a 405 its `Allow`, a 429 or a
|
|
5
|
+
* 503 its `Retry-After`. A value that is not a text or a number is left out, and so is a header no
|
|
6
|
+
* response could write.
|
|
7
|
+
*/
|
|
8
|
+
export declare function refusalHeaders(error: unknown): Record<string, string>;
|
|
9
|
+
//# sourceMappingURL=refusal-headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusal-headers.d.ts","sourceRoot":"","sources":["../../src/error/refusal-headers.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYrE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** A header name as HTTP writes it (a token), and a value with no line break nor control character in it. */
|
|
2
|
+
const NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
3
|
+
const VALUE = /^[\t\x20-\x7e\x80-\xff]*$/;
|
|
4
|
+
/** What described the body of the error, not the problem written in its place. */
|
|
5
|
+
const OF_THE_BODY = new Set(['content-type', 'content-length', 'content-encoding', 'transfer-encoding']);
|
|
6
|
+
/**
|
|
7
|
+
* The headers a refusal carries for its client, by lower-case name: `headers` of an error of
|
|
8
|
+
* http-errors (Express, Nest over Express) or of Fastify, the headers of the response a Hono
|
|
9
|
+
* `HTTPException` holds (`res`). A 401 keeps its `WWW-Authenticate`, a 405 its `Allow`, a 429 or a
|
|
10
|
+
* 503 its `Retry-After`. A value that is not a text or a number is left out, and so is a header no
|
|
11
|
+
* response could write.
|
|
12
|
+
*/
|
|
13
|
+
export function refusalHeaders(error) {
|
|
14
|
+
const kept = {};
|
|
15
|
+
for (const [name, value] of carried(error)) {
|
|
16
|
+
const lowered = name.toLowerCase();
|
|
17
|
+
if (NAME.test(name) && VALUE.test(value) && !OF_THE_BODY.has(lowered)) {
|
|
18
|
+
kept[lowered] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return kept;
|
|
22
|
+
}
|
|
23
|
+
function carried(error) {
|
|
24
|
+
const response = valueAt(error, 'res');
|
|
25
|
+
if (response instanceof Response) {
|
|
26
|
+
return [...response.headers.entries()];
|
|
27
|
+
}
|
|
28
|
+
const headers = valueAt(error, 'headers');
|
|
29
|
+
if (typeof headers !== 'object' || headers === null) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
return Object.entries(headers).flatMap(([name, value]) => typeof value === 'string' || typeof value === 'number' ? [[name, String(value)]] : []);
|
|
33
|
+
}
|
|
34
|
+
function valueAt(error, key) {
|
|
35
|
+
return typeof error === 'object' && error !== null ? Reflect.get(error, key) : undefined;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=refusal-headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusal-headers.js","sourceRoot":"","sources":["../../src/error/refusal-headers.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,MAAM,IAAI,GAAG,+BAA+B,CAAC;AAC7C,MAAM,KAAK,GAAG,2BAA2B,CAAC;AAE1C,kFAAkF;AAClF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAEzG;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,IAAI,GAA2B,EAAE,CAAC;IAExC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEnC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACtE,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAEvC,IAAI,QAAQ,YAAY,QAAQ,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAE1C,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACpD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAoB,EAAE,EAAE,CAC1E,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAC/F,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,KAAc,EAAE,GAAW;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-title.d.ts","sourceRoot":"","sources":["../../src/error/status-title.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"status-title.d.ts","sourceRoot":"","sources":["../../src/error/status-title.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
400: 'Bad Request',
|
|
3
|
-
401: 'Unauthorized',
|
|
4
|
-
402: 'Payment Required',
|
|
5
|
-
403: 'Forbidden',
|
|
6
|
-
404: 'Not Found',
|
|
7
|
-
405: 'Method Not Allowed',
|
|
8
|
-
406: 'Not Acceptable',
|
|
9
|
-
408: 'Request Timeout',
|
|
10
|
-
409: 'Conflict',
|
|
11
|
-
410: 'Gone',
|
|
12
|
-
412: 'Precondition Failed',
|
|
13
|
-
413: 'Content Too Large',
|
|
14
|
-
415: 'Unsupported Media Type',
|
|
15
|
-
422: 'Unprocessable Content',
|
|
16
|
-
423: 'Locked',
|
|
17
|
-
428: 'Precondition Required',
|
|
18
|
-
429: 'Too Many Requests',
|
|
19
|
-
500: 'Internal Server Error',
|
|
20
|
-
501: 'Not Implemented',
|
|
21
|
-
502: 'Bad Gateway',
|
|
22
|
-
503: 'Service Unavailable',
|
|
23
|
-
504: 'Gateway Timeout',
|
|
24
|
-
};
|
|
1
|
+
import { FIRST_SERVER_STATUS, STATUSES } from './statuses.js';
|
|
25
2
|
export function statusTitle(status) {
|
|
26
|
-
return
|
|
3
|
+
return STATUSES[status]?.title ?? (status >= FIRST_SERVER_STATUS ? 'Server Error' : 'Client Error');
|
|
27
4
|
}
|
|
28
5
|
//# sourceMappingURL=status-title.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-title.js","sourceRoot":"","sources":["../../src/error/status-title.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"status-title.js","sourceRoot":"","sources":["../../src/error/status-title.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,IAAI,mBAAmB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** What the kit names a status: its title, and the code of a problem answered with it and nothing more precise. */
|
|
2
|
+
export interface StatusNames {
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The statuses the kit names, the one table the titles of its problems and the codes of its
|
|
8
|
+
* refusals at the edge are read from. A code is the one the pipeline answers for that status
|
|
9
|
+
* (`VALIDATION_FAILED` for 422, `RATE_LIMITED` for 429 as the limit of the callers), so that a
|
|
10
|
+
* client tells a refusal by its code wherever it was refused.
|
|
11
|
+
*/
|
|
12
|
+
export declare const STATUSES: Readonly<Record<number, StatusNames>>;
|
|
13
|
+
export declare const FIRST_SERVER_STATUS = 500;
|
|
14
|
+
//# sourceMappingURL=statuses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statuses.d.ts","sourceRoot":"","sources":["../../src/error/statuses.ts"],"names":[],"mappings":"AAEA,mHAAmH;AACnH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAuB1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { INTERNAL_ERROR_CODE } from './internal-error-code.js';
|
|
2
|
+
/**
|
|
3
|
+
* The statuses the kit names, the one table the titles of its problems and the codes of its
|
|
4
|
+
* refusals at the edge are read from. A code is the one the pipeline answers for that status
|
|
5
|
+
* (`VALIDATION_FAILED` for 422, `RATE_LIMITED` for 429 as the limit of the callers), so that a
|
|
6
|
+
* client tells a refusal by its code wherever it was refused.
|
|
7
|
+
*/
|
|
8
|
+
export const STATUSES = {
|
|
9
|
+
400: { title: 'Bad Request', code: 'BAD_REQUEST' },
|
|
10
|
+
401: { title: 'Unauthorized', code: 'UNAUTHORIZED' },
|
|
11
|
+
402: { title: 'Payment Required', code: 'PAYMENT_REQUIRED' },
|
|
12
|
+
403: { title: 'Forbidden', code: 'FORBIDDEN' },
|
|
13
|
+
404: { title: 'Not Found', code: 'NOT_FOUND' },
|
|
14
|
+
405: { title: 'Method Not Allowed', code: 'METHOD_NOT_ALLOWED' },
|
|
15
|
+
406: { title: 'Not Acceptable', code: 'NOT_ACCEPTABLE' },
|
|
16
|
+
408: { title: 'Request Timeout', code: 'REQUEST_TIMEOUT' },
|
|
17
|
+
409: { title: 'Conflict', code: 'CONFLICT' },
|
|
18
|
+
410: { title: 'Gone', code: 'GONE' },
|
|
19
|
+
412: { title: 'Precondition Failed', code: 'PRECONDITION_FAILED' },
|
|
20
|
+
413: { title: 'Content Too Large', code: 'BODY_TOO_LARGE' },
|
|
21
|
+
415: { title: 'Unsupported Media Type', code: 'UNSUPPORTED_MEDIA_TYPE' },
|
|
22
|
+
422: { title: 'Unprocessable Content', code: 'VALIDATION_FAILED' },
|
|
23
|
+
423: { title: 'Locked', code: 'LOCKED' },
|
|
24
|
+
428: { title: 'Precondition Required', code: 'PRECONDITION_REQUIRED' },
|
|
25
|
+
429: { title: 'Too Many Requests', code: 'RATE_LIMITED' },
|
|
26
|
+
500: { title: 'Internal Server Error', code: INTERNAL_ERROR_CODE },
|
|
27
|
+
501: { title: 'Not Implemented', code: 'NOT_IMPLEMENTED' },
|
|
28
|
+
502: { title: 'Bad Gateway', code: 'BAD_GATEWAY' },
|
|
29
|
+
503: { title: 'Service Unavailable', code: 'SERVICE_UNAVAILABLE' },
|
|
30
|
+
504: { title: 'Gateway Timeout', code: 'GATEWAY_TIMEOUT' },
|
|
31
|
+
};
|
|
32
|
+
export const FIRST_SERVER_STATUS = 500;
|
|
33
|
+
//# sourceMappingURL=statuses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statuses.js","sourceRoot":"","sources":["../../src/error/statuses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAQ5D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAA0C;IAC7D,GAAG,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE;IAClD,GAAG,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc,EAAE;IACpD,G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KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE;IAC1D,GAAG,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE;IAClD,GAAG,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,qBAAqB,EAAE;IAClE,GAAG,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE;CAC3D,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC"}
|
|
@@ -43,7 +43,8 @@ function registrarOf(target) {
|
|
|
43
43
|
function handlerOf(route, options) {
|
|
44
44
|
return async (request, response) => {
|
|
45
45
|
const { params, query, headers } = request;
|
|
46
|
-
|
|
46
|
+
// A parser reads an empty body as `{}`: a request that declares no bytes has no body, as on the other frameworks.
|
|
47
|
+
const body = headers['content-length'] === '0' ? undefined : request.body;
|
|
47
48
|
const result = await executeRoute(route, { params, query, headers, body, raw: request, stream: streamOf(request) }, options);
|
|
48
49
|
response.status(result.status);
|
|
49
50
|
for (const [name, value] of Object.entries(result.headers)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount-express.js","sourceRoot":"","sources":["../../src/express/mount-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,OAAO,EAAE,EAAkE,MAAM,SAAS,CAAC;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,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,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3D,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;YACpC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACxE,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACvC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,OAAgB;IAChC,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAEtD,OAAO,OAAO,CAAC,aAAa,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ErrorRequestHandler } from 'express';
|
|
2
|
+
import { type EdgeErrorOptions } from '../error/answered-edge-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* The last middleware of an Express application: answers as a problem what reached Express before
|
|
5
|
+
* a route of the kit could, a body `express.json()` refused (`MALFORMED_BODY` 400,
|
|
6
|
+
* `BODY_TOO_LARGE` 413) or the error a middleware passed to `next`, instead of the final handler
|
|
7
|
+
* of Express, which answers an HTML page with the stack outside production and writes the error,
|
|
8
|
+
* the body it quotes included, to stderr. Installed after every route:
|
|
9
|
+
* `app.use(problemErrorHandler({ logger }))`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function problemErrorHandler(options?: EdgeErrorOptions): ErrorRequestHandler;
|
|
12
|
+
//# sourceMappingURL=problem-error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-error-handler.d.ts","sourceRoot":"","sources":["../../src/express/problem-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAExF;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,gBAAqB,GAAG,mBAAmB,CAcvF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { answeredEdgeError } from '../error/answered-edge-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The last middleware of an Express application: answers as a problem what reached Express before
|
|
4
|
+
* a route of the kit could, a body `express.json()` refused (`MALFORMED_BODY` 400,
|
|
5
|
+
* `BODY_TOO_LARGE` 413) or the error a middleware passed to `next`, instead of the final handler
|
|
6
|
+
* of Express, which answers an HTML page with the stack outside production and writes the error,
|
|
7
|
+
* the body it quotes included, to stderr. Installed after every route:
|
|
8
|
+
* `app.use(problemErrorHandler({ logger }))`.
|
|
9
|
+
*/
|
|
10
|
+
export function problemErrorHandler(options = {}) {
|
|
11
|
+
// eslint-disable-next-line ddd-ts-kit/clean-function-size -- Express tells an error middleware by its four parameters
|
|
12
|
+
return (error, request, response, _next) => {
|
|
13
|
+
const answer = answeredEdgeError({ error, headers: request.headers }, options);
|
|
14
|
+
if (response.headersSent) {
|
|
15
|
+
// Too late for a problem: the client gets a response cut short, as for a failed stream.
|
|
16
|
+
response.destroy();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
response.status(answer.status).set(answer.headers).send(JSON.stringify(answer.problem));
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=problem-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-error-handler.js","sourceRoot":"","sources":["../../src/express/problem-error-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;AAExF;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAAqB,EAAE;IAChE,sHAAsH;IACtH,OAAO,CAAC,KAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QAE/E,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YACzB,wFAAwF;YACxF,QAAQ,CAAC,OAAO,EAAE,CAAC;YAEnB,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/express.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export type { EdgeErrorOptions } from './error/answered-edge-error.js';
|
|
1
2
|
export { mountExpress, type ExpressMountOptions } from './express/mount-express.js';
|
|
3
|
+
export { problemErrorHandler } from './express/problem-error-handler.js';
|
|
2
4
|
//# sourceMappingURL=express.d.ts.map
|
package/dist/express.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/express.js
CHANGED
package/dist/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA4B,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -3,9 +3,10 @@ import type { Route } from '../route/route.js';
|
|
|
3
3
|
import type { FastifyMountOptions } from './fastify-mount-options.js';
|
|
4
4
|
/**
|
|
5
5
|
* Registers the routes on a Fastify 5 instance. Validation stays in the shared pipeline. The
|
|
6
|
-
* routes
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* routes are registered in a context of their own: where they read JSON, an empty body reaches
|
|
7
|
+
* them as absent, as on Express and Hono; those that read their body as a stream (an upload, a raw
|
|
8
|
+
* body) in another, where no body parser runs. The rest of the instance keeps its parsers. A media
|
|
9
|
+
* type a route consumes (`consumes`) is given a parser that hands the body over as text.
|
|
9
10
|
*/
|
|
10
11
|
export declare function mountFastify(instance: FastifyInstance, routes: readonly Route[], options?: FastifyMountOptions): void;
|
|
11
12
|
//# sourceMappingURL=mount-fastify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount-fastify.d.ts","sourceRoot":"","sources":["../../src/fastify/mount-fastify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAO/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE
|
|
1
|
+
{"version":3,"file":"mount-fastify.d.ts","sourceRoot":"","sources":["../../src/fastify/mount-fastify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAO/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,OAAO,GAAE,mBAAwB,GAChC,IAAI,CA0BN"}
|
|
@@ -6,9 +6,10 @@ import { assertServed } from '../representation/assert-served.js';
|
|
|
6
6
|
import { assertUniqueRoutes } from '../route/assert-unique-routes.js';
|
|
7
7
|
/**
|
|
8
8
|
* Registers the routes on a Fastify 5 instance. Validation stays in the shared pipeline. The
|
|
9
|
-
* routes
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* routes are registered in a context of their own: where they read JSON, an empty body reaches
|
|
10
|
+
* them as absent, as on Express and Hono; those that read their body as a stream (an upload, a raw
|
|
11
|
+
* body) in another, where no body parser runs. The rest of the instance keeps its parsers. A media
|
|
12
|
+
* type a route consumes (`consumes`) is given a parser that hands the body over as text.
|
|
12
13
|
*/
|
|
13
14
|
export function mountFastify(instance, routes, options = {}) {
|
|
14
15
|
assertUniqueRoutes(routes);
|
|
@@ -17,7 +18,10 @@ export function mountFastify(instance, routes, options = {}) {
|
|
|
17
18
|
const streamed = routes.filter(readsItsStream);
|
|
18
19
|
const parsed = routes.filter((route) => !readsItsStream(route));
|
|
19
20
|
readAsText(instance, parsed);
|
|
20
|
-
register(
|
|
21
|
+
void instance.register(async (scope) => {
|
|
22
|
+
readEmptyJsonAsAbsent(scope);
|
|
23
|
+
register(scope, parsed, options);
|
|
24
|
+
});
|
|
21
25
|
if (streamed.length > 0) {
|
|
22
26
|
void instance.register(async (unparsed) => {
|
|
23
27
|
unparsed.removeAllContentTypeParsers();
|
|
@@ -31,6 +35,25 @@ export function mountFastify(instance, routes, options = {}) {
|
|
|
31
35
|
function readsItsStream(route) {
|
|
32
36
|
return route.upload !== undefined || route.rawBody === true;
|
|
33
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The JSON parser of Fastify refuses an empty body (`FST_ERR_CTP_EMPTY_JSON_BODY`), which Express
|
|
40
|
+
* and Hono hand over as absent: in the context of the routes, an empty body is absent, any other
|
|
41
|
+
* read by the parser of Fastify, so that the validation of the route decides on every framework.
|
|
42
|
+
*/
|
|
43
|
+
function readEmptyJsonAsAbsent(scope) {
|
|
44
|
+
const { onProtoPoisoning, onConstructorPoisoning } = scope.initialConfig;
|
|
45
|
+
const parse = scope.getDefaultJsonParser(onProtoPoisoning ?? 'error', onConstructorPoisoning ?? 'error');
|
|
46
|
+
scope.removeContentTypeParser('application/json');
|
|
47
|
+
scope.addContentTypeParser('application/json', { parseAs: 'string' }, (request, body, done) => {
|
|
48
|
+
const text = String(body);
|
|
49
|
+
if (text === '') {
|
|
50
|
+
done(null, undefined);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
void parse(request, text, done);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
34
57
|
function readAsText(instance, routes) {
|
|
35
58
|
const consumed = new Set(routes.flatMap((route) => route.consumes ?? []));
|
|
36
59
|
for (const mediaType of [...consumed].filter((type) => !instance.hasContentTypeParser(type))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount-fastify.js","sourceRoot":"","sources":["../../src/fastify/mount-fastify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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,OAAO,CAAC,GAAG,EAAE,CAAC;gBAChF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;gBAEvD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YAChF,CAAC;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,4FAA4F;AAC5F,SAAS,MAAM,CAAC,MAAqB;IACnC,IAAI,MAAM,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5F,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import { type EdgeErrorOptions } from '../error/answered-edge-error.js';
|
|
3
|
+
type FastifyErrorHandler = (error: unknown, request: FastifyRequest, reply: FastifyReply) => FastifyReply;
|
|
4
|
+
/**
|
|
5
|
+
* The error handler of a Fastify instance: answers as a problem what reached Fastify before a
|
|
6
|
+
* route of the kit could, a body its parser refused (`MALFORMED_BODY` 400, `BODY_TOO_LARGE` 413,
|
|
7
|
+
* another media type 415) or the failure of a hook, instead of the default handler of Fastify,
|
|
8
|
+
* which answers `{ statusCode, code, error, message }` and the message of an unexpected error.
|
|
9
|
+
* Set before the routes are mounted: `app.setErrorHandler(problemErrorHandler({ logger }))`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function problemErrorHandler(options?: EdgeErrorOptions): FastifyErrorHandler;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=problem-error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-error-handler.d.ts","sourceRoot":"","sources":["../../src/fastify/problem-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAExF,KAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,YAAY,CAAC;AAE1G;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,gBAAqB,GAAG,mBAAmB,CAMvF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { answeredEdgeError } from '../error/answered-edge-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The error handler of a Fastify instance: answers as a problem what reached Fastify before a
|
|
4
|
+
* route of the kit could, a body its parser refused (`MALFORMED_BODY` 400, `BODY_TOO_LARGE` 413,
|
|
5
|
+
* another media type 415) or the failure of a hook, instead of the default handler of Fastify,
|
|
6
|
+
* which answers `{ statusCode, code, error, message }` and the message of an unexpected error.
|
|
7
|
+
* Set before the routes are mounted: `app.setErrorHandler(problemErrorHandler({ logger }))`.
|
|
8
|
+
*/
|
|
9
|
+
export function problemErrorHandler(options = {}) {
|
|
10
|
+
return (error, request, reply) => {
|
|
11
|
+
const answer = answeredEdgeError({ error, headers: request.headers }, options);
|
|
12
|
+
return reply.code(answer.status).headers(answer.headers).send(JSON.stringify(answer.problem));
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=problem-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-error-handler.js","sourceRoot":"","sources":["../../src/fastify/problem-error-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;AAIxF;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAAqB,EAAE;IAChE,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAC/B,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QAE/E,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAChG,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export type { EdgeErrorOptions } from './error/answered-edge-error.js';
|
|
1
2
|
export type { FastifyMountOptions } from './fastify/fastify-mount-options.js';
|
|
2
3
|
export { fastifyRoutes } from './fastify/fastify-routes.js';
|
|
3
4
|
export { mountFastify } from './fastify/mount-fastify.js';
|
|
5
|
+
export { problemErrorHandler } from './fastify/problem-error-handler.js';
|
|
4
6
|
//# sourceMappingURL=fastify.d.ts.map
|
package/dist/fastify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/fastify.js
CHANGED
package/dist/fastify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
+
import type { EdgeRefusal } from '../error/edge-refusal.js';
|
|
1
2
|
import type { RawHeaders } from '../route/raw-headers.js';
|
|
2
|
-
/** A request the adapter refuses before the pipeline runs: its status, its code and what is wrong. */
|
|
3
|
-
export interface EdgeRefusal {
|
|
4
|
-
readonly status: number;
|
|
5
|
-
readonly title: string;
|
|
6
|
-
readonly code: string;
|
|
7
|
-
readonly detail: string;
|
|
8
|
-
}
|
|
9
3
|
/** The answer to a request refused at the edge: a problem document, as every other refusal. */
|
|
10
4
|
export declare function edgeProblem(headers: RawHeaders, refusal: EdgeRefusal): Response;
|
|
11
5
|
//# sourceMappingURL=edge-problem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-problem.d.ts","sourceRoot":"","sources":["../../src/hono/edge-problem.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edge-problem.d.ts","sourceRoot":"","sources":["../../src/hono/edge-problem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,CAI/E"}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { wellFormedIdentifier } from '../pipeline/well-formed-identifier.js';
|
|
1
|
+
import { edgeAnswer } from '../error/edge-answer.js';
|
|
3
2
|
/** The answer to a request refused at the edge: a problem document, as every other refusal. */
|
|
4
3
|
export function edgeProblem(headers, refusal) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
return new Response(JSON.stringify(problem), {
|
|
8
|
-
status: refusal.status,
|
|
9
|
-
headers: {
|
|
10
|
-
'content-type': 'application/problem+json',
|
|
11
|
-
[CORRELATION_HEADER]: wellFormedIdentifier(headers[CORRELATION_HEADER]) ?? requestId,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
4
|
+
const answer = edgeAnswer(headers, refusal);
|
|
5
|
+
return new Response(JSON.stringify(answer.problem), { status: answer.status, headers: answer.headers });
|
|
14
6
|
}
|
|
15
7
|
//# sourceMappingURL=edge-problem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-problem.js","sourceRoot":"","sources":["../../src/hono/edge-problem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"edge-problem.js","sourceRoot":"","sources":["../../src/hono/edge-problem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,+FAA+F;AAC/F,MAAM,UAAU,WAAW,CAAC,OAAmB,EAAE,OAAoB;IACnE,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE5C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AAC1G,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { type EdgeErrorOptions } from '../error/answered-edge-error.js';
|
|
3
|
+
type HonoErrorHandler = (error: Error, context: Context) => Response;
|
|
4
|
+
/**
|
|
5
|
+
* The error handler of a Hono application: answers as a problem the failure of a middleware in
|
|
6
|
+
* front of the routes, instead of the default handler of Hono, which answers a text and writes
|
|
7
|
+
* the error to stderr. The routes of the kit answer their own refusals, a body included:
|
|
8
|
+
* `app.onError(problemErrorHandler({ logger }))`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function problemErrorHandler(options?: EdgeErrorOptions): HonoErrorHandler;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=problem-error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-error-handler.d.ts","sourceRoot":"","sources":["../../src/hono/problem-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAExF,KAAK,gBAAgB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,gBAAqB,GAAG,gBAAgB,CAMpF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { answeredEdgeError } from '../error/answered-edge-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The error handler of a Hono application: answers as a problem the failure of a middleware in
|
|
4
|
+
* front of the routes, instead of the default handler of Hono, which answers a text and writes
|
|
5
|
+
* the error to stderr. The routes of the kit answer their own refusals, a body included:
|
|
6
|
+
* `app.onError(problemErrorHandler({ logger }))`.
|
|
7
|
+
*/
|
|
8
|
+
export function problemErrorHandler(options = {}) {
|
|
9
|
+
return (error, context) => {
|
|
10
|
+
const answer = answeredEdgeError({ error, headers: context.req.header() }, options);
|
|
11
|
+
return new Response(JSON.stringify(answer.problem), { status: answer.status, headers: answer.headers });
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=problem-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-error-handler.js","sourceRoot":"","sources":["../../src/hono/problem-error-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;AAIxF;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAAqB,EAAE;IAChE,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAEpF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1G,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/hono/read-body.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-body.d.ts","sourceRoot":"","sources":["../../src/hono/read-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"read-body.d.ts","sourceRoot":"","sources":["../../src/hono/read-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAgB,KAAK,WAAW,EAAkB,MAAM,uBAAuB,CAAC;AAEvF,MAAM,MAAM,QAAQ,GAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAI5D;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmBnH"}
|
package/dist/hono/read-body.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { mediaTypeOf } from '../representation/media-type-of.js';
|
|
2
|
+
import { bodyTooLarge, MALFORMED_BODY } from '../error/edge-refusal.js';
|
|
2
3
|
const JSON_MEDIA = /[/+]json\b/;
|
|
3
|
-
const MALFORMED = {
|
|
4
|
-
status: 400,
|
|
5
|
-
title: 'Bad Request',
|
|
6
|
-
code: 'MALFORMED_BODY',
|
|
7
|
-
detail: 'The body is not valid JSON.',
|
|
8
|
-
};
|
|
9
4
|
/**
|
|
10
5
|
* The JSON body of the request, `undefined` when there is none; a body in a media type the route
|
|
11
6
|
* consumes (`consumes`), as text, for its representation to read; not read in any other media
|
|
@@ -19,7 +14,7 @@ export async function readBody(context, limit, consumed = []) {
|
|
|
19
14
|
}
|
|
20
15
|
const text = await boundedText(context.req.raw, limit);
|
|
21
16
|
if (text === undefined) {
|
|
22
|
-
return { read: false, refusal:
|
|
17
|
+
return { read: false, refusal: bodyTooLarge(limit) };
|
|
23
18
|
}
|
|
24
19
|
if (text === '') {
|
|
25
20
|
return { read: true, value: undefined };
|
|
@@ -51,15 +46,7 @@ function parsed(text) {
|
|
|
51
46
|
return { read: true, value };
|
|
52
47
|
}
|
|
53
48
|
catch {
|
|
54
|
-
return { read: false, refusal:
|
|
49
|
+
return { read: false, refusal: MALFORMED_BODY };
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
|
-
function tooLarge(limit) {
|
|
58
|
-
return {
|
|
59
|
-
status: 413,
|
|
60
|
-
title: 'Payload Too Large',
|
|
61
|
-
code: 'BODY_TOO_LARGE',
|
|
62
|
-
detail: `The body is larger than ${String(limit)} bytes.`,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
52
|
//# sourceMappingURL=read-body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-body.js","sourceRoot":"","sources":["../../src/hono/read-body.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"read-body.js","sourceRoot":"","sources":["../../src/hono/read-body.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAoB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAMvF,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAgB,EAAE,KAAa,EAAE,QAAQ,GAAsB,EAAE;IAC9F,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAC7D,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE1C,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC1C,CAAC;IAED,MAAM,IAAI,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AAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAExC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAClD,CAAC;AACH,CAAC"}
|
package/dist/hono.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export type { EdgeErrorOptions } from './error/answered-edge-error.js';
|
|
1
2
|
export type { HonoMountOptions } from './hono/hono-mount-options.js';
|
|
2
3
|
export type { HonoRaw } from './hono/hono-raw.js';
|
|
3
4
|
export { mountHono } from './hono/mount-hono.js';
|
|
5
|
+
export { problemErrorHandler } from './hono/problem-error-handler.js';
|
|
4
6
|
//# sourceMappingURL=hono.d.ts.map
|
package/dist/hono.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/hono.js
CHANGED
package/dist/hono.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
|