@ddd-ts-kit/http 0.114.1 → 0.116.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 +35 -11
- package/README.md +31 -11
- package/dist/error/answered-edge-error.d.ts +10 -2
- package/dist/error/answered-edge-error.d.ts.map +1 -1
- package/dist/error/answered-edge-error.js +17 -5
- package/dist/error/answered-edge-error.js.map +1 -1
- package/dist/error/create-error-mapper.d.ts.map +1 -1
- package/dist/error/create-error-mapper.js +2 -1
- package/dist/error/create-error-mapper.js.map +1 -1
- package/dist/error/default-error-mapping.d.ts.map +1 -1
- package/dist/error/default-error-mapping.js +2 -0
- package/dist/error/default-error-mapping.js.map +1 -1
- package/dist/error/edge-refusal.d.ts +5 -7
- package/dist/error/edge-refusal.d.ts.map +1 -1
- package/dist/error/edge-refusal.js.map +1 -1
- package/dist/error/mapped-status.d.ts +8 -0
- package/dist/error/mapped-status.d.ts.map +1 -0
- package/dist/error/mapped-status.js +9 -0
- package/dist/error/mapped-status.js.map +1 -0
- package/dist/error/to-problem.d.ts.map +1 -1
- package/dist/error/to-problem.js +2 -1
- package/dist/error/to-problem.js.map +1 -1
- package/dist/express/express-mount-options.d.ts +11 -0
- package/dist/express/express-mount-options.d.ts.map +1 -0
- package/dist/express/express-mount-options.js +2 -0
- package/dist/express/express-mount-options.js.map +1 -0
- package/dist/express/mount-express.d.ts +11 -9
- package/dist/express/mount-express.d.ts.map +1 -1
- package/dist/express/mount-express.js +33 -23
- package/dist/express/mount-express.js.map +1 -1
- package/dist/express.d.ts +2 -1
- package/dist/express.d.ts.map +1 -1
- package/dist/express.js.map +1 -1
- package/dist/fastify/mount-fastify.d.ts +2 -2
- package/dist/fastify/mount-fastify.d.ts.map +1 -1
- package/dist/fastify/mount-fastify.js +14 -20
- package/dist/fastify/mount-fastify.js.map +1 -1
- package/dist/hono/hono-mount-options.d.ts +1 -1
- package/dist/hono/mount-hono.d.ts.map +1 -1
- package/dist/hono/mount-hono.js +6 -14
- package/dist/hono/mount-hono.js.map +1 -1
- package/dist/hono/read-body.d.ts.map +1 -1
- package/dist/hono/read-body.js +3 -3
- package/dist/hono/read-body.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/nest/is-unread-json-body.d.ts.map +1 -1
- package/dist/nest/is-unread-json-body.js +2 -2
- package/dist/nest/is-unread-json-body.js.map +1 -1
- package/dist/orpc/orpc-router.js +1 -1
- package/dist/orpc/orpc-router.js.map +1 -1
- package/dist/pipeline/admitted-caller.d.ts +3 -5
- package/dist/pipeline/admitted-caller.d.ts.map +1 -1
- package/dist/pipeline/admitted-caller.js +2 -2
- package/dist/pipeline/admitted-caller.js.map +1 -1
- package/dist/pipeline/closing-with.d.ts +7 -0
- package/dist/pipeline/closing-with.d.ts.map +1 -0
- package/dist/pipeline/closing-with.js +21 -0
- package/dist/pipeline/closing-with.js.map +1 -0
- package/dist/pipeline/conditional-answer.d.ts +1 -1
- package/dist/pipeline/conditional-answer.d.ts.map +1 -1
- package/dist/pipeline/conditional-answer.js +12 -3
- package/dist/pipeline/conditional-answer.js.map +1 -1
- package/dist/pipeline/entity-tag-of.d.ts +4 -3
- package/dist/pipeline/entity-tag-of.d.ts.map +1 -1
- package/dist/pipeline/entity-tag-of.js +5 -4
- package/dist/pipeline/entity-tag-of.js.map +1 -1
- package/dist/pipeline/execute-route.d.ts.map +1 -1
- package/dist/pipeline/execute-route.js +44 -58
- package/dist/pipeline/execute-route.js.map +1 -1
- package/dist/pipeline/is-listed.d.ts +3 -0
- package/dist/pipeline/is-listed.d.ts.map +1 -0
- package/dist/pipeline/is-listed.js +7 -0
- package/dist/pipeline/is-listed.js.map +1 -0
- package/dist/pipeline/payload.d.ts +22 -0
- package/dist/pipeline/payload.d.ts.map +1 -0
- package/dist/pipeline/payload.js +2 -0
- package/dist/pipeline/payload.js.map +1 -0
- package/dist/pipeline/progress.d.ts +16 -0
- package/dist/pipeline/progress.d.ts.map +1 -0
- package/dist/pipeline/progress.js +24 -0
- package/dist/pipeline/progress.js.map +1 -0
- package/dist/pipeline/reported-stream.d.ts.map +1 -1
- package/dist/pipeline/reported-stream.js +18 -8
- package/dist/pipeline/reported-stream.js.map +1 -1
- package/dist/pipeline/represented-answer.d.ts +3 -3
- package/dist/pipeline/represented-answer.d.ts.map +1 -1
- package/dist/pipeline/represented.d.ts +8 -3
- package/dist/pipeline/represented.d.ts.map +1 -1
- package/dist/pipeline/represented.js +35 -9
- package/dist/pipeline/represented.js.map +1 -1
- package/dist/pipeline/route-response.d.ts +10 -3
- package/dist/pipeline/route-response.d.ts.map +1 -1
- package/dist/pipeline/whole-of.d.ts +9 -0
- package/dist/pipeline/whole-of.d.ts.map +1 -0
- package/dist/pipeline/whole-of.js +8 -0
- package/dist/pipeline/whole-of.js.map +1 -0
- package/dist/pipeline/writing.d.ts +11 -0
- package/dist/pipeline/writing.d.ts.map +1 -0
- package/dist/pipeline/writing.js +2 -0
- package/dist/pipeline/writing.js.map +1 -0
- package/dist/pipeline/written-in.d.ts +10 -4
- package/dist/pipeline/written-in.d.ts.map +1 -1
- package/dist/pipeline/written-in.js +12 -10
- package/dist/pipeline/written-in.js.map +1 -1
- package/dist/representation/is-json-content-type.d.ts +3 -0
- package/dist/representation/is-json-content-type.d.ts.map +1 -0
- package/dist/representation/is-json-content-type.js +7 -0
- package/dist/representation/is-json-content-type.js.map +1 -0
- package/dist/representation/json-representation.js +9 -1
- package/dist/representation/json-representation.js.map +1 -1
- package/dist/route/reads-its-stream.d.ts +4 -0
- package/dist/route/reads-its-stream.d.ts.map +1 -0
- package/dist/route/reads-its-stream.js +5 -0
- package/dist/route/reads-its-stream.js.map +1 -0
- package/dist/rpc/rpc-answer.d.ts.map +1 -1
- package/dist/rpc/rpc-answer.js +18 -17
- package/dist/rpc/rpc-answer.js.map +1 -1
- package/dist/testing/written-text.d.ts +10 -0
- package/dist/testing/written-text.d.ts.map +1 -0
- package/dist/testing/written-text.js +17 -0
- package/dist/testing/written-text.js.map +1 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -0
- package/dist/testing.js.map +1 -1
- package/dist/trpc/trpc-router.js +1 -1
- package/dist/trpc/trpc-router.js.map +1 -1
- package/package.json +11 -11
- package/dist/pipeline/serialize-body.d.ts +0 -7
- package/dist/pipeline/serialize-body.d.ts.map +0 -1
- package/dist/pipeline/serialize-body.js +0 -16
- package/dist/pipeline/serialize-body.js.map +0 -1
- package/dist/pipeline/write-stream.d.ts +0 -8
- package/dist/pipeline/write-stream.d.ts.map +0 -1
- package/dist/pipeline/write-stream.js +0 -23
- package/dist/pipeline/write-stream.js.map +0 -1
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:5267bd6b2d861de6 -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/http
|
|
5
5
|
|
|
@@ -166,6 +166,7 @@ anonyme atteindre `handle`.
|
|
|
166
166
|
| `HttpRequest<{ params, query, headers, body }>` | la requête HTTP telle que `handle`, un *mapper* ou une garde la nomment, avec `actor` et `context` |
|
|
167
167
|
| `controllerRoutes(controllers, { resolve, security, guards })` | la `Route` de chaque contrôleur, donné comme classe (construite par `resolve`) ou comme instance ; `security` nomme les schémas de sécurité de l'application (`['bearer']` par défaut) ; `guards: 'skip'` sert à la *spec* d'un contrôleur seul |
|
|
168
168
|
| `controllerRoute(controller, options)` | l'unique route d'un contrôleur, pour une *spec* |
|
|
169
|
+
| `writtenText(response)` | (`@ddd-ts-kit/http/testing`) le texte qu'un adaptateur écrit pour une réponse, lu jusqu'au bout : le XML ou le CSV d'une représentation, une liste en flux ; `response.body` est la valeur avant son écriture |
|
|
169
170
|
| `routeOf(controller or route, options)` | (`@ddd-ts-kit/http/testing`) la route d'une *spec* et `send(request)`, par tout le pipeline au nom d'un `caller` authentifié, gardes comprises sauf si `guards: 'skip'` dit le contraire, réponses vérifiées : voir [La *spec* d'une route](#la-spec-dune-route--routeof) |
|
|
170
171
|
|
|
171
172
|
Un contrôleur sans groupe et sans garde est refusé dès que sa classe est définie. Les gardes
|
|
@@ -187,7 +188,13 @@ brut reste une fonction `defineRoute`. Les raisons sont sur la page
|
|
|
187
188
|
`executeRoute(route, request, options)` est tout le comportement du package : un adaptateur ne
|
|
188
189
|
fait que copier la requête HTTP de son framework dans une `RawRequest` (`params`, `query`,
|
|
189
190
|
`headers`, `body`, `raw`, et le flux du corps, `stream`), l'appeler, et réécrire la
|
|
190
|
-
`RouteResponse` qu'elle renvoie
|
|
191
|
+
`RouteResponse` qu'elle renvoie : un `status`, des `headers` et un `payload` déjà décidé,
|
|
192
|
+
`{ kind: 'none' }`, `{ kind: 'text', text }` (du JSON, une autre représentation, un *problem*),
|
|
193
|
+
`{ kind: 'bytes', bytes }` ou `{ kind: 'stream', stream }` (un fichier, ou les morceaux d'une
|
|
194
|
+
liste en flux). Un adaptateur ne sérialise rien : une valeur qui ne peut pas être écrite (un
|
|
195
|
+
cycle) échoue dans le pipeline, est signalée à `onError` et reçoit un 500 sous forme de
|
|
196
|
+
*problem*, avec les en-têtes d'un refus. `body` porte la valeur répondue, avant toute écriture,
|
|
197
|
+
pour une *spec* et pour une procédure RPC.
|
|
191
198
|
|
|
192
199
|

|
|
193
200
|
|
|
@@ -1051,9 +1058,11 @@ plus de JSON (`consumes`), sur `@Controller` comme sur `defineRoute` :
|
|
|
1051
1058
|
`produces` et `consumes` ou non. Sans `representations`, le contrat ne dit que JSON et aucun
|
|
1052
1059
|
des deux statuts, comme répond le serveur.
|
|
1053
1060
|
- **Sans `representations`**, rien ne change : chaque réponse est en JSON, quoi que la requête
|
|
1054
|
-
HTTP accepte
|
|
1055
|
-
`
|
|
1056
|
-
|
|
1061
|
+
HTTP accepte, une liste en flux comprise, écrite comme un seul tableau JSON. Avec ou sans
|
|
1062
|
+
elles, `body` de la `RouteResponse` est la valeur répondue (une *spec* qui appelle
|
|
1063
|
+
`executeRoute` la lit comme avant) et `payload` ce qui est écrit : `writtenText(response)` de
|
|
1064
|
+
`@ddd-ts-kit/http/testing` le lit jusqu'au bout, le XML ou le CSV d'une réponse, les morceaux
|
|
1065
|
+
d'une liste en flux.
|
|
1057
1066
|
|
|
1058
1067
|
### Les règles de sérialisation, les mêmes dans chaque représentation
|
|
1059
1068
|
|
|
@@ -1288,16 +1297,26 @@ declare const options: ExecuteOptions;
|
|
|
1288
1297
|
declare const logger: Logger;
|
|
1289
1298
|
|
|
1290
1299
|
const app = express();
|
|
1291
|
-
app
|
|
1292
|
-
mountExpress(app, routes, options); // un express.Router() convient aussi
|
|
1300
|
+
mountExpress(app, routes, options); // un express.Router() convient aussi ; lit lui-même les corps
|
|
1293
1301
|
app.use(problemNotFoundHandler({ logger })); // après les routes : un chemin qu'aucune ne sert
|
|
1294
1302
|
app.use(problemErrorHandler({ logger })); // en dernier : ce qu'Express refuse avant une route
|
|
1295
1303
|
app.listen(3000);
|
|
1296
1304
|
```
|
|
1297
1305
|
|
|
1306
|
+
L'adaptateur lit lui-même le corps de chaque route, jusqu'à `bodyLimit` octets (1 Mio par
|
|
1307
|
+
défaut, comme Fastify et Hono) : du JSON quelle que soit sa valeur, un objet ou `null`, un
|
|
1308
|
+
nombre, un texte, pour que le schéma de la route décide (422), et un type de média que la route
|
|
1309
|
+
consomme, en texte. Une route qui lit son propre flux (un téléversement, un corps brut) ne
|
|
1310
|
+
reçoit aucun analyseur. Un analyseur de l'application passé avant l'emporte : `express.json()`
|
|
1311
|
+
refuse avec 400 une valeur JSON qui n'est ni un objet ni un tableau, sauf avec `strict: false`,
|
|
1312
|
+
et lit au plus 100 ko.
|
|
1313
|
+
|
|
1298
1314
|
`problemErrorHandler` répond sous forme de *problem* à ce qui atteint Express avant une route du
|
|
1299
|
-
kit : un corps
|
|
1300
|
-
au-delà de
|
|
1315
|
+
kit : un corps qui n'est pas du JSON reçoit un 400 `MALFORMED_BODY`, un corps
|
|
1316
|
+
au-delà de la limite un 413 `BODY_TOO_LARGE`, une erreur du kit qu'un middleware passe à `next`
|
|
1317
|
+
(`UnauthorizedError`, `ForbiddenError`, une `DomainError` du projet) le *problem* qu'une route
|
|
1318
|
+
répond pour elle, sous le statut que `errorMapper` donne à son code (la correspondance par
|
|
1319
|
+
défaut s'il est omis), une autre erreur porteuse d'un
|
|
1301
1320
|
statut (`status` ou `statusCode`, 4xx ou 5xx) ce statut, avec le code que le kit lui donne
|
|
1302
1321
|
(`UNAUTHORIZED`, `VALIDATION_FAILED` pour 422, `SERVICE_UNAVAILABLE` pour le 503 d'un stockage
|
|
1303
1322
|
en panne) et les en-têtes qu'elle porte pour son client (`WWW-Authenticate`, `Allow`,
|
|
@@ -1366,7 +1385,7 @@ serve({ fetch: app.fetch, port: 3000 });
|
|
|
1366
1385
|
```
|
|
1367
1386
|
|
|
1368
1387
|
L'adaptateur lit lui-même le corps JSON, morceau par morceau et jusqu'à `bodyLimit` octets
|
|
1369
|
-
(1 Mio par défaut, comme Fastify
|
|
1388
|
+
(1 Mio par défaut, comme Fastify et Express) : un corps plus grand reçoit un 413
|
|
1370
1389
|
sous forme de *problem* (`BODY_TOO_LARGE`), un corps qui n'est pas du JSON un 400
|
|
1371
1390
|
(`MALFORMED_BODY`), les deux avant le pipeline et sans garder le corps en entier. Un corps dans
|
|
1372
1391
|
un type de média que la route consomme (`consumes`) est lu comme du texte sous la même limite,
|
|
@@ -1428,6 +1447,11 @@ trop grand reçoit un 413 `BODY_TOO_LARGE`, un chemin qu'aucune route ne sert un
|
|
|
1428
1447
|
un corps qui n'est pas du JSON un 400 `MALFORMED_BODY` comme sur les autres frameworks : Nest
|
|
1429
1448
|
enveloppe l'erreur de son analyseur dans une exception à lui avant tout filtre, que le filtre
|
|
1430
1449
|
reconnaît à son statut, à son message et à une requête JSON dont le corps n'a jamais été lu.
|
|
1450
|
+
Sur Express, l'analyseur de Nest refuse avec 400 une valeur JSON qui n'est ni un objet ni un
|
|
1451
|
+
tableau (`null`, un nombre, un texte), là où le schéma de la route répond 422 sur les autres
|
|
1452
|
+
frameworks : `app.useBodyParser('json', { strict: false })`, avant que l'application n'écoute,
|
|
1453
|
+
laisse la route décider. Le filtre prend l'`errorMapper` de l'application comme
|
|
1454
|
+
`problemErrorHandler`, pour une erreur du kit levée par un middleware.
|
|
1431
1455
|
|
|
1432
1456
|
### Contrôleurs Nest servis par le kit
|
|
1433
1457
|
|
|
@@ -1935,7 +1959,7 @@ l'application sert elle-même, le répertoire local du développement ou la mém
|
|
|
1935
1959
|
`GET /files?token=` télécharge (en pièce jointe, `nosniff`, `no-store`), `PUT /files?token=`
|
|
1936
1960
|
téléverse, refusé avec 413 au-delà de la taille pour laquelle le lien a été signé. Ces routes
|
|
1937
1961
|
sont publiques, le jeton étant l'autorisation, et ne font pas partie du contrat. Avec
|
|
1938
|
-
Express, montez-les avant `express.json()` : cet analyseur lit d'abord un corps JSON. Un
|
|
1962
|
+
Express, montez-les avant un `express.json()` de l'application, si elle en a un : cet analyseur lit d'abord un corps JSON. Un
|
|
1939
1963
|
stockage objet répond à ses propres liens et n'a besoin d'aucune route.
|
|
1940
1964
|
|
|
1941
1965
|
Un gestionnaire peut répondre un flux (`Readable`) comme corps : il est envoyé dans la réponse,
|
package/README.md
CHANGED
|
@@ -157,6 +157,7 @@ It answers 201 with `{ id }`, documents `OUT_OF_STOCK` (its own), `FORBIDDEN` (i
|
|
|
157
157
|
| `HttpRequest<{ params, query, headers, body }>` | the request as `handle`, a mapper or a guard names it, with `actor` and `context` |
|
|
158
158
|
| `controllerRoutes(controllers, { resolve, security, guards })` | the `Route` of each controller, given as a class (built by `resolve`) or as an instance; `security` names the schemes of the application (`['bearer']` by default); `guards: 'skip'` is for the spec of a controller alone |
|
|
159
159
|
| `controllerRoute(controller, options)` | the one route of one controller, for a spec |
|
|
160
|
+
| `writtenText(response)` | (`@ddd-ts-kit/http/testing`) the text an adapter writes for an answer, read to its end: the XML or the CSV of a representation, a list read as it comes; `response.body` is the value before it was written |
|
|
160
161
|
| `routeOf(controller or route, options)` | (`@ddd-ts-kit/http/testing`) the route of a spec and `send(request)`, through the whole pipeline as an authenticated `caller`, guards included unless `guards: 'skip'` says otherwise, answers checked: see [The spec of a route](#the-spec-of-a-route-routeof) |
|
|
161
162
|
|
|
162
163
|
A controller with no group and no guard is refused when its class is defined. Guards run in
|
|
@@ -176,7 +177,13 @@ are on the [presentation layer](../../docs/concepts/presentation-layer.md) page.
|
|
|
176
177
|
|
|
177
178
|
`executeRoute(route, request, options)` is the whole behaviour of the package: an adapter only
|
|
178
179
|
copies the request of its framework into a `RawRequest` (`params`, `query`, `headers`, `body`,
|
|
179
|
-
`raw`, and the body `stream`), calls it, and writes back the `RouteResponse` it returns
|
|
180
|
+
`raw`, and the body `stream`), calls it, and writes back the `RouteResponse` it returns: a
|
|
181
|
+
`status`, `headers` and a `payload` already decided, `{ kind: 'none' }`, `{ kind: 'text', text }`
|
|
182
|
+
(JSON, another representation, a problem document), `{ kind: 'bytes', bytes }` or
|
|
183
|
+
`{ kind: 'stream', stream }` (a file, or the chunks of a list read as it comes). An adapter
|
|
184
|
+
serializes nothing: a value that cannot be written (a cycle) fails inside the pipeline, is told
|
|
185
|
+
to `onError` and answered 500 as a problem, under the headers of a refusal. `body` holds the
|
|
186
|
+
value answered, before anything wrote it, for a spec and for an RPC procedure.
|
|
180
187
|
|
|
181
188
|

|
|
182
189
|
|
|
@@ -1006,9 +1013,10 @@ JSON (`consumes`), on `@Controller` or on `defineRoute` alike:
|
|
|
1006
1013
|
on every route that reads a body, declared in `produces` and `consumes` or not. Without
|
|
1007
1014
|
`representations`, the contract says JSON only and neither status, as the server answers.
|
|
1008
1015
|
- **Without `representations`**, nothing changes: every answer is JSON, whatever the request
|
|
1009
|
-
accepts
|
|
1010
|
-
spec calling `executeRoute` reads it as
|
|
1011
|
-
`
|
|
1016
|
+
accepts, a list read as it comes included, written as one JSON array. With or without them,
|
|
1017
|
+
`body` of the `RouteResponse` is the value answered (a spec calling `executeRoute` reads it as
|
|
1018
|
+
before) and `payload` what is written: `writtenText(response)` of `@ddd-ts-kit/http/testing`
|
|
1019
|
+
reads it to its end, the XML or the CSV of an answer, the chunks of a streamed list.
|
|
1012
1020
|
|
|
1013
1021
|
### The serialization rules, the same in every representation
|
|
1014
1022
|
|
|
@@ -1233,16 +1241,24 @@ declare const options: ExecuteOptions;
|
|
|
1233
1241
|
declare const logger: Logger;
|
|
1234
1242
|
|
|
1235
1243
|
const app = express();
|
|
1236
|
-
app
|
|
1237
|
-
mountExpress(app, routes, options); // an express.Router() works too
|
|
1244
|
+
mountExpress(app, routes, options); // an express.Router() works too; reads the bodies itself
|
|
1238
1245
|
app.use(problemNotFoundHandler({ logger })); // after the routes: a path none serves
|
|
1239
1246
|
app.use(problemErrorHandler({ logger })); // last: what Express refuses before a route
|
|
1240
1247
|
app.listen(3000);
|
|
1241
1248
|
```
|
|
1242
1249
|
|
|
1250
|
+
The adapter reads the body of each route itself, up to `bodyLimit` bytes (1 MiB by default, as
|
|
1251
|
+
Fastify and Hono): JSON whatever its value, an object or `null`, a number, a text, for the schema
|
|
1252
|
+
of the route to decide (422), and a media type the route consumes as text. A route that reads its
|
|
1253
|
+
own stream (an upload, a raw body) gets no parser. A parser of the application that ran first
|
|
1254
|
+
wins: `express.json()` refuses a JSON value that is no object or array with 400 unless it is given
|
|
1255
|
+
`strict: false`, and reads at most 100 kB.
|
|
1256
|
+
|
|
1243
1257
|
`problemErrorHandler` answers as a problem what reaches Express before a route of the kit: a body
|
|
1244
|
-
|
|
1245
|
-
413 `BODY_TOO_LARGE`,
|
|
1258
|
+
that is not JSON is 400 `MALFORMED_BODY`, a body over the limit
|
|
1259
|
+
413 `BODY_TOO_LARGE`, an error of the kit a middleware passes to `next` (`UnauthorizedError`,
|
|
1260
|
+
`ForbiddenError`, a `DomainError` of the project) the problem a route answers for it, under the
|
|
1261
|
+
status `errorMapper` gives its code (the default mapping when left out), another error that carries a status (`status` or `statusCode`, 4xx or 5xx)
|
|
1246
1262
|
that status, with the code the kit gives it (`UNAUTHORIZED`, `VALIDATION_FAILED` for 422,
|
|
1247
1263
|
`SERVICE_UNAVAILABLE` for the 503 of a store down) and the headers it carries for its client
|
|
1248
1264
|
(`WWW-Authenticate`, `Allow`, `Retry-After`), and any other error a middleware passes to `next`
|
|
@@ -1308,7 +1324,7 @@ serve({ fetch: app.fetch, port: 3000 });
|
|
|
1308
1324
|
```
|
|
1309
1325
|
|
|
1310
1326
|
The adapter reads the JSON body itself, chunk by chunk and up to `bodyLimit` bytes (1 MiB by
|
|
1311
|
-
default, as Fastify
|
|
1327
|
+
default, as Fastify and Express): a larger body is answered 413 as a problem
|
|
1312
1328
|
(`BODY_TOO_LARGE`), a body that is not JSON 400 (`MALFORMED_BODY`), both before the pipeline and
|
|
1313
1329
|
without holding the body whole. A body in a media type the route consumes (`consumes`) is read
|
|
1314
1330
|
as text under the same limit, for its representation; another media type is not read, and the
|
|
@@ -1364,7 +1380,11 @@ problem instead, on Express and on Fastify, and logs it as `problemErrorHandler`
|
|
|
1364
1380
|
large is 413 `BODY_TOO_LARGE`, a path no route serves 404 `NOT_FOUND`, a body that is not JSON
|
|
1365
1381
|
400 `MALFORMED_BODY` as on the other frameworks: Nest wraps the error of its parser in an
|
|
1366
1382
|
exception of its own before any filter, which the filter tells by its status, its message and a
|
|
1367
|
-
JSON request whose body was never read.
|
|
1383
|
+
JSON request whose body was never read. Over Express, the parser of Nest refuses a JSON value
|
|
1384
|
+
that is no object or array (`null`, a number, a text) with 400, where the schema of the route
|
|
1385
|
+
answers 422 on the other frameworks: `app.useBodyParser('json', { strict: false })`, before the
|
|
1386
|
+
application listens, lets the route decide. The filter takes the `errorMapper` of the application
|
|
1387
|
+
as `problemErrorHandler` does, for an error of the kit a middleware raises.
|
|
1368
1388
|
|
|
1369
1389
|
### Nest controllers served by the kit
|
|
1370
1390
|
|
|
@@ -1858,7 +1878,7 @@ rejects instead of waiting forever.
|
|
|
1858
1878
|
application serves itself, the local directory of development or the memory of the tests:
|
|
1859
1879
|
`GET /files?token=` downloads (as an attachment, `nosniff`, `no-store`), `PUT /files?token=`
|
|
1860
1880
|
uploads, refused with 413 beyond the size the link was signed for. They are public, the token being the grant, and are not part of the contract. With
|
|
1861
|
-
Express, mount them before `express.json()
|
|
1881
|
+
Express, mount them before an `express.json()` of the application, if it has one: that parser reads a JSON body first. An object
|
|
1862
1882
|
store answers its own links and needs no route.
|
|
1863
1883
|
|
|
1864
1884
|
A handler may answer a stream (`Readable`) as its body: it is piped to the response, with its
|
|
@@ -2,6 +2,7 @@ import { type Logger } from '@ddd-ts-kit/kernel';
|
|
|
2
2
|
import type { RawHeaders } from '../route/raw-headers.js';
|
|
3
3
|
import { type EdgeAnswer } from './edge-answer.js';
|
|
4
4
|
import { type EdgeRefusal } from './edge-refusal.js';
|
|
5
|
+
import type { ErrorMapper } from './error-mapper.js';
|
|
5
6
|
export interface EdgeErrorOptions {
|
|
6
7
|
/**
|
|
7
8
|
* Where each error is written: its type (`entity.parse.failed`, `FST_ERR_CTP_BODY_TOO_LARGE`,
|
|
@@ -11,6 +12,12 @@ export interface EdgeErrorOptions {
|
|
|
11
12
|
* Left out, nothing is written.
|
|
12
13
|
*/
|
|
13
14
|
readonly logger?: Logger;
|
|
15
|
+
/**
|
|
16
|
+
* The mapper the routes are mounted with: an error of the domain a middleware in front of them
|
|
17
|
+
* raises (`UnauthorizedError`, `ForbiddenError`, one of the project) is answered under the
|
|
18
|
+
* status it gives its code, as a route answers it. Left out, the default mapping.
|
|
19
|
+
*/
|
|
20
|
+
readonly errorMapper?: ErrorMapper;
|
|
14
21
|
}
|
|
15
22
|
/** What reached the framework, and the request it came with. */
|
|
16
23
|
export interface EdgeError {
|
|
@@ -21,8 +28,9 @@ export interface EdgeError {
|
|
|
21
28
|
}
|
|
22
29
|
/**
|
|
23
30
|
* The answer to an error the framework raised before a route of the kit ran, or a middleware
|
|
24
|
-
* passed on: a body refused by its parser, the failure of a middleware.
|
|
25
|
-
*
|
|
31
|
+
* passed on: a body refused by its parser, the failure of a middleware. An error of the domain
|
|
32
|
+
* (`DomainError`) is the problem a route answers for it, under the status the error mapper gives
|
|
33
|
+
* its code. A body that is not JSON is `MALFORMED_BODY` (400), an error with the status 413 `BODY_TOO_LARGE`, another error that
|
|
26
34
|
* carries a status of a refusal or of a failure (`status` or `statusCode`, 4xx or 5xx) that
|
|
27
35
|
* status, its code the one the kit gives it (`NOT_FOUND`, `VALIDATION_FAILED` for 422,
|
|
28
36
|
* `SERVICE_UNAVAILABLE` for the 503 of a store down), anything else `INTERNAL_ERROR` (500). The
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"answered-edge-error.d.ts","sourceRoot":"","sources":["../../src/error/answered-edge-error.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"answered-edge-error.d.ts","sourceRoot":"","sources":["../../src/error/answered-edge-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAgB,KAAK,WAAW,EAAkB,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD,MAAM,WAAW,gBAAgB;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;CACpC;AAED,gEAAgE;AAChE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IACvC,iHAAiH;IACjH,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;CAChC;AAgBD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAiB/G"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { identifyError } from '@ddd-ts-kit/kernel';
|
|
1
|
+
import { DomainError, identifyError } from '@ddd-ts-kit/kernel';
|
|
2
2
|
import { codeOfStatus } from './code-of-status.js';
|
|
3
|
+
import { createErrorMapper } from './create-error-mapper.js';
|
|
3
4
|
import { edgeAnswer } from './edge-answer.js';
|
|
4
5
|
import { bodyTooLarge, MALFORMED_BODY } from './edge-refusal.js';
|
|
5
6
|
import { INTERNAL_ERROR_CODE } from './internal-error-code.js';
|
|
6
7
|
import { refusalHeaders } from './refusal-headers.js';
|
|
7
8
|
import { statusTitle } from './status-title.js';
|
|
9
|
+
import { toProblem } from './to-problem.js';
|
|
8
10
|
/** What `express.json()` (body-parser) and the parser of Fastify name a body that is not JSON; an empty body is not one. */
|
|
9
11
|
const MALFORMED_KINDS = new Set(['entity.parse.failed', 'FST_ERR_CTP_INVALID_JSON_BODY']);
|
|
10
12
|
const KIND = /^[A-Za-z0-9_.]{1,64}$/;
|
|
@@ -12,11 +14,13 @@ const NOT_FOUND = 404;
|
|
|
12
14
|
const CONTENT_TOO_LARGE = 413;
|
|
13
15
|
const FIRST_REFUSAL = 400;
|
|
14
16
|
const LAST_FAILURE = 599;
|
|
17
|
+
const defaultErrorMapper = createErrorMapper();
|
|
15
18
|
const INTERNAL = { status: 500, title: statusTitle(500), code: INTERNAL_ERROR_CODE };
|
|
16
19
|
/**
|
|
17
20
|
* The answer to an error the framework raised before a route of the kit ran, or a middleware
|
|
18
|
-
* passed on: a body refused by its parser, the failure of a middleware.
|
|
19
|
-
*
|
|
21
|
+
* passed on: a body refused by its parser, the failure of a middleware. An error of the domain
|
|
22
|
+
* (`DomainError`) is the problem a route answers for it, under the status the error mapper gives
|
|
23
|
+
* its code. A body that is not JSON is `MALFORMED_BODY` (400), an error with the status 413 `BODY_TOO_LARGE`, another error that
|
|
20
24
|
* carries a status of a refusal or of a failure (`status` or `statusCode`, 4xx or 5xx) that
|
|
21
25
|
* status, its code the one the kit gives it (`NOT_FOUND`, `VALIDATION_FAILED` for 422,
|
|
22
26
|
* `SERVICE_UNAVAILABLE` for the 503 of a store down), anything else `INTERNAL_ERROR` (500). The
|
|
@@ -24,7 +28,7 @@ const INTERNAL = { status: 500, title: statusTitle(500), code: INTERNAL_ERROR_CO
|
|
|
24
28
|
* a status carries for its client (`WWW-Authenticate`, `Allow`, `Retry-After`) are kept.
|
|
25
29
|
*/
|
|
26
30
|
export function answeredEdgeError({ error, headers, refusal }, options) {
|
|
27
|
-
const refused = edgeAnswer(headers, refusal ?? refusalOf(error));
|
|
31
|
+
const refused = edgeAnswer(headers, refusal ?? refusalOf(error, options.errorMapper ?? defaultErrorMapper));
|
|
28
32
|
// The headers of the refusal under those of the problem: a challenge kept, the media type and the identifiers the problem's.
|
|
29
33
|
const kept = statusOf(error) === undefined ? {} : refusalHeaders(error);
|
|
30
34
|
const answer = { ...refused, headers: { ...kept, ...refused.headers } };
|
|
@@ -41,7 +45,10 @@ export function answeredEdgeError({ error, headers, refusal }, options) {
|
|
|
41
45
|
}
|
|
42
46
|
return answer;
|
|
43
47
|
}
|
|
44
|
-
function refusalOf(error) {
|
|
48
|
+
function refusalOf(error, mapper) {
|
|
49
|
+
if (error instanceof DomainError) {
|
|
50
|
+
return domainRefusal(error, mapper);
|
|
51
|
+
}
|
|
45
52
|
const kind = kindOf(error);
|
|
46
53
|
if (kind !== undefined && MALFORMED_KINDS.has(kind)) {
|
|
47
54
|
return MALFORMED_BODY;
|
|
@@ -55,6 +62,11 @@ function refusalOf(error) {
|
|
|
55
62
|
}
|
|
56
63
|
return { status, title: statusTitle(status), code: codeOfStatus(status) };
|
|
57
64
|
}
|
|
65
|
+
/** A refusal in the vocabulary of the kit, as the pipeline answers it: its type, its detail, its issues. */
|
|
66
|
+
function domainRefusal(error, mapper) {
|
|
67
|
+
const { requestId, ...refusal } = toProblem(error, mapper, '');
|
|
68
|
+
return refusal;
|
|
69
|
+
}
|
|
58
70
|
/** The status the error carries (`status`, else `statusCode`), when it is one of a refusal or of a failure. */
|
|
59
71
|
function statusOf(error) {
|
|
60
72
|
const status = numberAt(error, 'status') ?? numberAt(error, 'statusCode');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"answered-edge-error.js","sourceRoot":"","sources":["../../src/error/answered-edge-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"answered-edge-error.js","sourceRoot":"","sources":["../../src/error/answered-edge-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAe,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAmB,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAoB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AA2BzC,4HAA4H;AAC5H,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,qBAAqB,EAAE,+BAA+B,CAAC,CAAC,CAAC;AAE1F,MAAM,IAAI,G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,CAAC;IAElC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,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":"create-error-mapper.d.ts","sourceRoot":"","sources":["../../src/error/create-error-mapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-error-mapper.d.ts","sourceRoot":"","sources":["../../src/error/create-error-mapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5C;AAED,wBAAgB,iBAAiB,CAAC,SAAS,GAAE,YAAiB,EAAE,OAAO,GAAE,kBAAuB,GAAG,WAAW,CAW7G"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_ERROR_MAPPING } from './default-error-mapping.js';
|
|
2
|
+
import { mappedStatus } from './mapped-status.js';
|
|
2
3
|
export function createErrorMapper(overrides = {}, options = {}) {
|
|
3
4
|
const mapping = { ...DEFAULT_ERROR_MAPPING, ...overrides };
|
|
4
5
|
const fallbackStatus = options.fallbackStatus ?? 422;
|
|
5
6
|
const typeOf = options.typeOf ?? ((code) => `urn:problem:${code.toLowerCase().replaceAll('_', '-')}`);
|
|
6
7
|
return {
|
|
7
8
|
mapping,
|
|
8
|
-
statusOf: (code) => mapping
|
|
9
|
+
statusOf: (code) => mappedStatus(mapping, code) ?? fallbackStatus,
|
|
9
10
|
typeOf,
|
|
10
11
|
};
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-error-mapper.js","sourceRoot":"","sources":["../../src/error/create-error-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-error-mapper.js","sourceRoot":"","sources":["../../src/error/create-error-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C,MAAM,UAAU,iBAAiB,CAAC,SAAS,GAAiB,EAAE,EAAE,OAAO,GAAuB,EAAE;IAC9F,MAAM,OAAO,GAAiB,EAAE,GAAG,qBAAqB,EAAE,GAAG,SAAS,EAAE,CAAC;IACzE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,GAAG,CAAC;IAErD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,eAAe,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAE9G,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,cAAc;QACjE,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-error-mapping.d.ts","sourceRoot":"","sources":["../../src/error/default-error-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"default-error-mapping.d.ts","sourceRoot":"","sources":["../../src/error/default-error-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,EAAE,YAkBnC,CAAC"}
|
|
@@ -14,5 +14,7 @@ export const DEFAULT_ERROR_MAPPING = {
|
|
|
14
14
|
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
15
15
|
// A unit of work the database could not serve in time (`TransactionTimeoutError`): try again later.
|
|
16
16
|
SERVICE_UNAVAILABLE: 503,
|
|
17
|
+
// What was generated and is not written yet (`UndecidedError`): the route exists, its behaviour does not.
|
|
18
|
+
NOT_IMPLEMENTED: 501,
|
|
17
19
|
};
|
|
18
20
|
//# sourceMappingURL=default-error-mapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-error-mapping.js","sourceRoot":"","sources":["../../src/error/default-error-mapping.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAiB;IACjD,iBAAiB,EAAE,GAAG;IACtB,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,mBAAmB,EAAE,GAAG;IACxB,YAAY,EAAE,GAAG;IACjB,SAAS,EAAE,GAAG;IACd,cAAc,EAAE,GAAG;IACnB,mBAAmB,EAAE,GAAG;IACxB,qBAAqB,EAAE,GAAG;IAC1B,cAAc,EAAE,GAAG;IACnB,cAAc,EAAE,GAAG;IACnB,sBAAsB,EAAE,GAAG;IAC3B,oGAAoG;IACpG,mBAAmB,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"default-error-mapping.js","sourceRoot":"","sources":["../../src/error/default-error-mapping.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAiB;IACjD,iBAAiB,EAAE,GAAG;IACtB,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,mBAAmB,EAAE,GAAG;IACxB,YAAY,EAAE,GAAG;IACjB,SAAS,EAAE,GAAG;IACd,cAAc,EAAE,GAAG;IACnB,mBAAmB,EAAE,GAAG;IACxB,qBAAqB,EAAE,GAAG;IAC1B,cAAc,EAAE,GAAG;IACnB,cAAc,EAAE,GAAG;IACnB,sBAAsB,EAAE,GAAG;IAC3B,oGAAoG;IACpG,mBAAmB,EAAE,GAAG;IACxB,0GAA0G;IAC1G,eAAe,EAAE,GAAG;CACrB,CAAC"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import type { Problem } from './problem.js';
|
|
1
2
|
/**
|
|
2
3
|
* A request refused before the pipeline runs, by an adapter or by the framework under it: a body
|
|
3
|
-
* that is not JSON, a body too large
|
|
4
|
-
* request
|
|
4
|
+
* that is not JSON, a body too large, the refusal of a middleware. What its problem says, but
|
|
5
|
+
* the request it answers; its `type` is `about:blank` unless it names one.
|
|
5
6
|
*/
|
|
6
|
-
export interface EdgeRefusal {
|
|
7
|
-
readonly
|
|
8
|
-
readonly title: string;
|
|
9
|
-
readonly code: string;
|
|
10
|
-
readonly detail?: string;
|
|
7
|
+
export interface EdgeRefusal extends Omit<Problem, 'type' | 'requestId'> {
|
|
8
|
+
readonly type?: string;
|
|
11
9
|
}
|
|
12
10
|
export declare const MALFORMED_BODY: EdgeRefusal;
|
|
13
11
|
/** A body beyond what the server reads: the limit is said when the framework tells it. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-refusal.d.ts","sourceRoot":"","sources":["../../src/error/edge-refusal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edge-refusal.d.ts","sourceRoot":"","sources":["../../src/error/edge-refusal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC;IACtE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD,eAAO,MAAM,cAAc,EAAE,WAK5B,CAAC;AAEF,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CASnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-refusal.js","sourceRoot":"","sources":["../../src/error/edge-refusal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"edge-refusal.js","sourceRoot":"","sources":["../../src/error/edge-refusal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAW7C,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAM,CAAC,MAAM,cAAc,GAAgB;IACzC,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,WAAW,CAAC,WAAW,CAAC;IAC/B,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE,6BAA6B;CACtC,CAAC;AAEF,0FAA0F;AAC1F,MAAM,UAAU,YAAY,CAAC,KAAyB;IACpD,MAAM,MAAM,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;IAExF,OAAO;QACL,MAAM,EAAE,iBAAiB;QACzB,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC;QACrC,IAAI,EAAE,YAAY,CAAC,iBAAiB,CAAC;QACrC,MAAM,EAAE,2BAA2B,MAAM,GAAG;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ErrorMapping } from './error-mapping.js';
|
|
2
|
+
/**
|
|
3
|
+
* The status the mapping itself gives a code, `undefined` when it names none. A code is data, a
|
|
4
|
+
* text an error carries: it is never read among what every object inherits (`constructor`,
|
|
5
|
+
* `toString`).
|
|
6
|
+
*/
|
|
7
|
+
export declare function mappedStatus(mapping: ErrorMapping, code: string): number | undefined;
|
|
8
|
+
//# sourceMappingURL=mapped-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapped-status.d.ts","sourceRoot":"","sources":["../../src/error/mapped-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEpF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The status the mapping itself gives a code, `undefined` when it names none. A code is data, a
|
|
3
|
+
* text an error carries: it is never read among what every object inherits (`constructor`,
|
|
4
|
+
* `toString`).
|
|
5
|
+
*/
|
|
6
|
+
export function mappedStatus(mapping, code) {
|
|
7
|
+
return Object.hasOwn(mapping, code) ? mapping[code] : undefined;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=mapped-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapped-status.js","sourceRoot":"","sources":["../../src/error/mapped-status.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAqB,EAAE,IAAY;IAC9D,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-problem.d.ts","sourceRoot":"","sources":["../../src/error/to-problem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"to-problem.d.ts","sourceRoot":"","sources":["../../src/error/to-problem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAsBzF"}
|
package/dist/error/to-problem.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DomainError, FactualRefusal } from '@ddd-ts-kit/kernel';
|
|
2
2
|
import { ValidationError } from '@ddd-ts-kit/validation';
|
|
3
3
|
import { INTERNAL_ERROR_CODE } from './internal-error-code.js';
|
|
4
|
+
import { mappedStatus } from './mapped-status.js';
|
|
4
5
|
import { statusTitle } from './status-title.js';
|
|
5
6
|
export function toProblem(error, mapper, requestId) {
|
|
6
7
|
if (!(error instanceof DomainError)) {
|
|
@@ -69,7 +70,7 @@ function exposedFacts(error) {
|
|
|
69
70
|
*/
|
|
70
71
|
function serverFaultProblem(error, mapper, requestId) {
|
|
71
72
|
const code = error instanceof Error ? Reflect.get(error, 'code') : undefined;
|
|
72
|
-
const status = typeof code === 'string' ? mapper.mapping
|
|
73
|
+
const status = typeof code === 'string' ? mappedStatus(mapper.mapping, code) : undefined;
|
|
73
74
|
if (typeof code !== 'string' || status === undefined || status < 500) {
|
|
74
75
|
return internalProblem(requestId);
|
|
75
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-problem.js","sourceRoot":"","sources":["../../src/error/to-problem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"to-problem.js","sourceRoot":"","sources":["../../src/error/to-problem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,MAAmB,EAAE,SAAiB;IAC9E,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC,EAAE,CAAC;QACpC,OAAO,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAClB,8EAA8E;QAC9E,OAAO,EAAE,GAAG,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IACjG,CAAC;IAED,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QAC/B,KAAK,EAAE,WAAW,CAAC,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,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtF,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEzF,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACrE,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,EAAE,GAAG,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;AACrF,CAAC;AAED,6FAA6F;AAC7F,SAAS,eAAe,CAAC,SAAiB;IACxC,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,uBAAuB;QAC9B,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,mBAAmB;QACzB,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExecuteOptions } from '../pipeline/execute-options.js';
|
|
2
|
+
export interface ExpressMountOptions extends ExecuteOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The largest body the adapter reads, in bytes, JSON or a media type a route consumes: a larger
|
|
5
|
+
* one is answered 413 as a problem (`BODY_TOO_LARGE`) by `problemErrorHandler`. 1 MiB by default,
|
|
6
|
+
* what Fastify and Hono read. A body a parser of the application read first has that parser's
|
|
7
|
+
* limit, and an upload the limit its route declares.
|
|
8
|
+
*/
|
|
9
|
+
readonly bodyLimit?: number;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=express-mount-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express-mount-options.d.ts","sourceRoot":"","sources":["../../src/express/express-mount-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express-mount-options.js","sourceRoot":"","sources":["../../src/express/express-mount-options.ts"],"names":[],"mappings":""}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { type IRouter } from 'express';
|
|
2
|
-
import type { ExecuteOptions } from '../pipeline/execute-options.js';
|
|
3
2
|
import type { Route } from '../route/route.js';
|
|
4
|
-
|
|
3
|
+
import type { ExpressMountOptions } from './express-mount-options.js';
|
|
5
4
|
/**
|
|
6
|
-
* Registers the routes on an Express 5 application or router.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* (`express.json(
|
|
11
|
-
*
|
|
12
|
-
*
|
|
5
|
+
* Registers the routes on an Express 5 application or router. The adapter reads the body of each
|
|
6
|
+
* route itself, up to `bodyLimit` (1 MiB by default): JSON whatever its value, an object or not,
|
|
7
|
+
* for the schema of the route to decide as on the other frameworks, and a media type the route
|
|
8
|
+
* consumes (`consumes`) as text, for its representation. A body a parser of the application read
|
|
9
|
+
* first (`express.json()`, which refuses a JSON value that is no object or array unless given
|
|
10
|
+
* `strict: false`) is taken as that parser read it. An upload and a raw body are read from the
|
|
11
|
+
* request stream, which no parser of the adapter touches; behind a JSON parser of the
|
|
12
|
+
* application, a raw body takes the bytes that parser kept in `request.rawBody`
|
|
13
|
+
* (`express.json({ verify: (request, _, bytes) => { request.rawBody = bytes; } })`). A file and a
|
|
14
|
+
* list read as it comes are piped to the response, at the pace the client reads them.
|
|
13
15
|
*/
|
|
14
16
|
export declare function mountExpress(target: IRouter, routes: readonly Route[], options?: ExpressMountOptions): void;
|
|
15
17
|
//# sourceMappingURL=mount-express.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount-express.d.ts","sourceRoot":"","sources":["../../src/express/mount-express.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAE,KAAK,OAAO,EAAoD,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"mount-express.d.ts","sourceRoot":"","sources":["../../src/express/mount-express.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAE,KAAK,OAAO,EAAoD,MAAM,SAAS,CAAC;AASlG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAWnE;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAW/G"}
|