@ddd-ts-kit/http 0.13.0 → 0.14.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.md +319 -9
- package/dist/controller/controller-routes.d.ts.map +1 -1
- package/dist/controller/controller-routes.js +8 -0
- package/dist/controller/controller-routes.js.map +1 -1
- package/dist/controller/controller-spec.d.ts +7 -0
- package/dist/controller/controller-spec.d.ts.map +1 -1
- package/dist/error/default-error-mapping.d.ts.map +1 -1
- package/dist/error/default-error-mapping.js +1 -0
- package/dist/error/default-error-mapping.js.map +1 -1
- package/dist/express/mount-express.d.ts +4 -2
- package/dist/express/mount-express.d.ts.map +1 -1
- package/dist/express/mount-express.js +25 -11
- package/dist/express/mount-express.js.map +1 -1
- package/dist/fastify/mount-fastify.d.ts +2 -1
- package/dist/fastify/mount-fastify.d.ts.map +1 -1
- package/dist/fastify/mount-fastify.js +23 -4
- package/dist/fastify/mount-fastify.js.map +1 -1
- package/dist/field-access/assert-writable.d.ts +8 -0
- package/dist/field-access/assert-writable.d.ts.map +1 -0
- package/dist/field-access/assert-writable.js +29 -0
- package/dist/field-access/assert-writable.js.map +1 -0
- package/dist/field-access/field-access-entry.d.ts +7 -0
- package/dist/field-access/field-access-entry.d.ts.map +1 -0
- package/dist/field-access/field-access-entry.js +2 -0
- package/dist/field-access/field-access-entry.js.map +1 -0
- package/dist/field-access/field-access.d.ts +13 -0
- package/dist/field-access/field-access.d.ts.map +1 -0
- package/dist/field-access/field-access.js +41 -0
- package/dist/field-access/field-access.js.map +1 -0
- package/dist/field-access/field-decider-of.d.ts +37 -0
- package/dist/field-access/field-decider-of.d.ts.map +1 -0
- package/dist/field-access/field-decider-of.js +30 -0
- package/dist/field-access/field-decider-of.js.map +1 -0
- package/dist/field-access/field-decider.d.ts +4 -0
- package/dist/field-access/field-decider.d.ts.map +1 -0
- package/dist/field-access/field-decider.js +2 -0
- package/dist/field-access/field-decider.js.map +1 -0
- package/dist/field-access/field-judge.d.ts +33 -0
- package/dist/field-access/field-judge.d.ts.map +1 -0
- package/dist/field-access/field-judge.js +81 -0
- package/dist/field-access/field-judge.js.map +1 -0
- package/dist/field-access/field-policy.d.ts +15 -0
- package/dist/field-access/field-policy.d.ts.map +1 -0
- package/dist/field-access/field-policy.js +2 -0
- package/dist/field-access/field-policy.js.map +1 -0
- package/dist/field-access/field-question.d.ts +18 -0
- package/dist/field-access/field-question.d.ts.map +1 -0
- package/dist/field-access/field-question.js +2 -0
- package/dist/field-access/field-question.js.map +1 -0
- package/dist/field-access/field-requirement.d.ts +13 -0
- package/dist/field-access/field-requirement.d.ts.map +1 -0
- package/dist/field-access/field-requirement.js +2 -0
- package/dist/field-access/field-requirement.js.map +1 -0
- package/dist/field-access/field-rule.d.ts +11 -0
- package/dist/field-access/field-rule.d.ts.map +1 -0
- package/dist/field-access/field-rule.js +2 -0
- package/dist/field-access/field-rule.js.map +1 -0
- package/dist/field-access/field-rules.d.ts +6 -0
- package/dist/field-access/field-rules.d.ts.map +1 -0
- package/dist/field-access/field-rules.js +2 -0
- package/dist/field-access/field-rules.js.map +1 -0
- package/dist/field-access/field-tree.d.ts +16 -0
- package/dist/field-access/field-tree.d.ts.map +1 -0
- package/dist/field-access/field-tree.js +28 -0
- package/dist/field-access/field-tree.js.map +1 -0
- package/dist/field-access/visible-body.d.ts +9 -0
- package/dist/field-access/visible-body.d.ts.map +1 -0
- package/dist/field-access/visible-body.js +42 -0
- package/dist/field-access/visible-body.js.map +1 -0
- package/dist/field-access/with-field-access.d.ts +17 -0
- package/dist/field-access/with-field-access.d.ts.map +1 -0
- package/dist/field-access/with-field-access.js +63 -0
- package/dist/field-access/with-field-access.js.map +1 -0
- package/dist/forms/assert-hints.d.ts +12 -0
- package/dist/forms/assert-hints.d.ts.map +1 -0
- package/dist/forms/assert-hints.js +32 -0
- package/dist/forms/assert-hints.js.map +1 -0
- package/dist/forms/assert-opens.d.ts +16 -0
- package/dist/forms/assert-opens.d.ts.map +1 -0
- package/dist/forms/assert-opens.js +24 -0
- package/dist/forms/assert-opens.js.map +1 -0
- package/dist/forms/constraints-of.d.ts +4 -0
- package/dist/forms/constraints-of.d.ts.map +1 -0
- package/dist/forms/constraints-of.js +24 -0
- package/dist/forms/constraints-of.js.map +1 -0
- package/dist/forms/define-form.d.ts +20 -0
- package/dist/forms/define-form.d.ts.map +1 -0
- package/dist/forms/define-form.js +8 -0
- package/dist/forms/define-form.js.map +1 -0
- package/dist/forms/field-block.d.ts +33 -0
- package/dist/forms/field-block.d.ts.map +1 -0
- package/dist/forms/field-block.js +2 -0
- package/dist/forms/field-block.js.map +1 -0
- package/dist/forms/field-hint.d.ts +18 -0
- package/dist/forms/field-hint.d.ts.map +1 -0
- package/dist/forms/field-hint.js +2 -0
- package/dist/forms/field-hint.js.map +1 -0
- package/dist/forms/field-lookup.d.ts +7 -0
- package/dist/forms/field-lookup.d.ts.map +1 -0
- package/dist/forms/field-lookup.js +2 -0
- package/dist/forms/field-lookup.js.map +1 -0
- package/dist/forms/form-block.d.ts +5 -0
- package/dist/forms/form-block.d.ts.map +1 -0
- package/dist/forms/form-block.js +2 -0
- package/dist/forms/form-block.js.map +1 -0
- package/dist/forms/form-condition.d.ts +9 -0
- package/dist/forms/form-condition.d.ts.map +1 -0
- package/dist/forms/form-condition.js +2 -0
- package/dist/forms/form-condition.js.map +1 -0
- package/dist/forms/form-describer.d.ts +35 -0
- package/dist/forms/form-describer.d.ts.map +1 -0
- package/dist/forms/form-describer.js +132 -0
- package/dist/forms/form-describer.js.map +1 -0
- package/dist/forms/form-description.d.ts +17 -0
- package/dist/forms/form-description.d.ts.map +1 -0
- package/dist/forms/form-description.js +2 -0
- package/dist/forms/form-description.js.map +1 -0
- package/dist/forms/form-document.d.ts +9 -0
- package/dist/forms/form-document.d.ts.map +1 -0
- package/dist/forms/form-document.js +2 -0
- package/dist/forms/form-document.js.map +1 -0
- package/dist/forms/form-documents-of.d.ts +10 -0
- package/dist/forms/form-documents-of.d.ts.map +1 -0
- package/dist/forms/form-documents-of.js +22 -0
- package/dist/forms/form-documents-of.js.map +1 -0
- package/dist/forms/form-format.d.ts +7 -0
- package/dist/forms/form-format.d.ts.map +1 -0
- package/dist/forms/form-format.js +3 -0
- package/dist/forms/form-format.js.map +1 -0
- package/dist/forms/form-group-hint.d.ts +8 -0
- package/dist/forms/form-group-hint.d.ts.map +1 -0
- package/dist/forms/form-group-hint.js +2 -0
- package/dist/forms/form-group-hint.js.map +1 -0
- package/dist/forms/form-hints.d.ts +16 -0
- package/dist/forms/form-hints.d.ts.map +1 -0
- package/dist/forms/form-hints.js +2 -0
- package/dist/forms/form-hints.js.map +1 -0
- package/dist/forms/form-of-route.d.ts +17 -0
- package/dist/forms/form-of-route.d.ts.map +1 -0
- package/dist/forms/form-of-route.js +47 -0
- package/dist/forms/form-of-route.js.map +1 -0
- package/dist/forms/form-query-schema.d.ts +10 -0
- package/dist/forms/form-query-schema.d.ts.map +1 -0
- package/dist/forms/form-query-schema.js +58 -0
- package/dist/forms/form-query-schema.js.map +1 -0
- package/dist/forms/form-query.d.ts +7 -0
- package/dist/forms/form-query.d.ts.map +1 -0
- package/dist/forms/form-query.js +2 -0
- package/dist/forms/form-query.js.map +1 -0
- package/dist/forms/form-requirement.d.ts +18 -0
- package/dist/forms/form-requirement.d.ts.map +1 -0
- package/dist/forms/form-requirement.js +2 -0
- package/dist/forms/form-requirement.js.map +1 -0
- package/dist/forms/form-routes.d.ts +19 -0
- package/dist/forms/form-routes.d.ts.map +1 -0
- package/dist/forms/form-routes.js +67 -0
- package/dist/forms/form-routes.js.map +1 -0
- package/dist/forms/form-schema.d.ts +4 -0
- package/dist/forms/form-schema.d.ts.map +1 -0
- package/dist/forms/form-schema.js +52 -0
- package/dist/forms/form-schema.js.map +1 -0
- package/dist/forms/group-block.d.ts +9 -0
- package/dist/forms/group-block.d.ts.map +1 -0
- package/dist/forms/group-block.js +2 -0
- package/dist/forms/group-block.js.map +1 -0
- package/dist/forms/json-form.d.ts +8 -0
- package/dist/forms/json-form.d.ts.map +1 -0
- package/dist/forms/json-form.js +2 -0
- package/dist/forms/json-form.js.map +1 -0
- package/dist/forms/json-forms-of.d.ts +12 -0
- package/dist/forms/json-forms-of.d.ts.map +1 -0
- package/dist/forms/json-forms-of.js +129 -0
- package/dist/forms/json-forms-of.js.map +1 -0
- package/dist/forms/lookups-of.d.ts +5 -0
- package/dist/forms/lookups-of.d.ts.map +1 -0
- package/dist/forms/lookups-of.js +7 -0
- package/dist/forms/lookups-of.js.map +1 -0
- package/dist/forms/widget-of.d.ts +5 -0
- package/dist/forms/widget-of.d.ts.map +1 -0
- package/dist/forms/widget-of.js +25 -0
- package/dist/forms/widget-of.js.map +1 -0
- package/dist/forms/widget.d.ts +3 -0
- package/dist/forms/widget.d.ts.map +1 -0
- package/dist/forms/widget.js +2 -0
- package/dist/forms/widget.js.map +1 -0
- package/dist/hono/mount-hono.d.ts +4 -2
- package/dist/hono/mount-hono.d.ts.map +1 -1
- package/dist/hono/mount-hono.js +19 -7
- package/dist/hono/mount-hono.js.map +1 -1
- package/dist/hono/read-body.d.ts +4 -3
- package/dist/hono/read-body.d.ts.map +1 -1
- package/dist/hono/read-body.js +12 -5
- package/dist/hono/read-body.js.map +1 -1
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/openapi/cache-response-headers.d.ts +5 -2
- package/dist/openapi/cache-response-headers.d.ts.map +1 -1
- package/dist/openapi/cache-response-headers.js +10 -5
- package/dist/openapi/cache-response-headers.js.map +1 -1
- package/dist/openapi/documenting.d.ts +11 -0
- package/dist/openapi/documenting.d.ts.map +1 -0
- package/dist/openapi/documenting.js +2 -0
- package/dist/openapi/documenting.js.map +1 -0
- package/dist/openapi/generate-open-api.d.ts +7 -0
- package/dist/openapi/generate-open-api.d.ts.map +1 -1
- package/dist/openapi/generate-open-api.js +5 -1
- package/dist/openapi/generate-open-api.js.map +1 -1
- package/dist/openapi/path-items.d.ts +2 -3
- package/dist/openapi/path-items.d.ts.map +1 -1
- package/dist/openapi/path-items.js +8 -7
- package/dist/openapi/path-items.js.map +1 -1
- package/dist/openapi/request-body.d.ts +6 -3
- package/dist/openapi/request-body.d.ts.map +1 -1
- package/dist/openapi/request-body.js +13 -3
- package/dist/openapi/request-body.js.map +1 -1
- package/dist/openapi/responses.d.ts +2 -3
- package/dist/openapi/responses.d.ts.map +1 -1
- package/dist/openapi/responses.js +40 -12
- package/dist/openapi/responses.js.map +1 -1
- package/dist/pagination/every-page.d.ts +15 -0
- package/dist/pagination/every-page.d.ts.map +1 -0
- package/dist/pagination/every-page.js +21 -0
- package/dist/pagination/every-page.js.map +1 -0
- package/dist/pagination/page-schema-of.d.ts +2 -1
- package/dist/pagination/page-schema-of.d.ts.map +1 -1
- package/dist/pagination/page-schema-of.js +6 -2
- package/dist/pagination/page-schema-of.js.map +1 -1
- package/dist/pipeline/assert-cached-routes.d.ts +4 -2
- package/dist/pipeline/assert-cached-routes.d.ts.map +1 -1
- package/dist/pipeline/assert-cached-routes.js +46 -8
- package/dist/pipeline/assert-cached-routes.js.map +1 -1
- package/dist/pipeline/conditional-answer.d.ts +7 -2
- package/dist/pipeline/conditional-answer.d.ts.map +1 -1
- package/dist/pipeline/conditional-answer.js +10 -6
- package/dist/pipeline/conditional-answer.js.map +1 -1
- package/dist/pipeline/entity-tag-of.d.ts +3 -3
- package/dist/pipeline/entity-tag-of.d.ts.map +1 -1
- package/dist/pipeline/entity-tag-of.js +4 -4
- package/dist/pipeline/entity-tag-of.js.map +1 -1
- package/dist/pipeline/error-context.d.ts +6 -1
- package/dist/pipeline/error-context.d.ts.map +1 -1
- package/dist/pipeline/execute-options.d.ts +17 -0
- package/dist/pipeline/execute-options.d.ts.map +1 -1
- package/dist/pipeline/execute-route.d.ts.map +1 -1
- package/dist/pipeline/execute-route.js +121 -35
- package/dist/pipeline/execute-route.js.map +1 -1
- package/dist/pipeline/iterated-within.d.ts +9 -0
- package/dist/pipeline/iterated-within.d.ts.map +1 -0
- package/dist/pipeline/iterated-within.js +17 -0
- package/dist/pipeline/iterated-within.js.map +1 -0
- package/dist/pipeline/negotiated-vary.d.ts +6 -0
- package/dist/pipeline/negotiated-vary.d.ts.map +1 -0
- package/dist/pipeline/negotiated-vary.js +15 -0
- package/dist/pipeline/negotiated-vary.js.map +1 -0
- package/dist/pipeline/negotiation.d.ts +19 -0
- package/dist/pipeline/negotiation.d.ts.map +1 -0
- package/dist/pipeline/negotiation.js +19 -0
- package/dist/pipeline/negotiation.js.map +1 -0
- package/dist/pipeline/primed.d.ts +6 -0
- package/dist/pipeline/primed.d.ts.map +1 -0
- package/dist/pipeline/primed.js +20 -0
- package/dist/pipeline/primed.js.map +1 -0
- package/dist/pipeline/read-body.d.ts +10 -0
- package/dist/pipeline/read-body.d.ts.map +1 -0
- package/dist/pipeline/read-body.js +33 -0
- package/dist/pipeline/read-body.js.map +1 -0
- package/dist/pipeline/reported-stream.d.ts +6 -0
- package/dist/pipeline/reported-stream.d.ts.map +1 -0
- package/dist/pipeline/reported-stream.js +14 -0
- package/dist/pipeline/reported-stream.js.map +1 -0
- package/dist/pipeline/represented-answer.d.ts +7 -0
- package/dist/pipeline/represented-answer.d.ts.map +1 -0
- package/dist/pipeline/represented-answer.js +2 -0
- package/dist/pipeline/represented-answer.js.map +1 -0
- package/dist/pipeline/represented.d.ts +7 -0
- package/dist/pipeline/represented.d.ts.map +1 -0
- package/dist/pipeline/represented.js +19 -0
- package/dist/pipeline/represented.js.map +1 -0
- package/dist/pipeline/route-response.d.ts +2 -0
- package/dist/pipeline/route-response.d.ts.map +1 -1
- package/dist/pipeline/tagged-answer.d.ts +5 -2
- package/dist/pipeline/tagged-answer.d.ts.map +1 -1
- package/dist/pipeline/tagged-answer.js +1 -1
- package/dist/pipeline/tagged-answer.js.map +1 -1
- package/dist/pipeline/write-stream.d.ts +8 -0
- package/dist/pipeline/write-stream.d.ts.map +1 -0
- package/dist/pipeline/write-stream.js +23 -0
- package/dist/pipeline/write-stream.js.map +1 -0
- package/dist/pipeline/written-in.d.ts +10 -0
- package/dist/pipeline/written-in.d.ts.map +1 -0
- package/dist/pipeline/written-in.js +17 -0
- package/dist/pipeline/written-in.js.map +1 -0
- package/dist/representation/assert-served.d.ts +10 -0
- package/dist/representation/assert-served.d.ts.map +1 -0
- package/dist/representation/assert-served.js +18 -0
- package/dist/representation/assert-served.js.map +1 -0
- package/dist/representation/body-shape.d.ts +9 -0
- package/dist/representation/body-shape.d.ts.map +1 -0
- package/dist/representation/body-shape.js +2 -0
- package/dist/representation/body-shape.js.map +1 -0
- package/dist/representation/csv/csv-cell.d.ts +8 -0
- package/dist/representation/csv/csv-cell.d.ts.map +1 -0
- package/dist/representation/csv/csv-cell.js +19 -0
- package/dist/representation/csv/csv-cell.js.map +1 -0
- package/dist/representation/csv/csv-representation.d.ts +16 -0
- package/dist/representation/csv/csv-representation.d.ts.map +1 -0
- package/dist/representation/csv/csv-representation.js +54 -0
- package/dist/representation/csv/csv-representation.js.map +1 -0
- package/dist/representation/is-json-media-type.d.ts +3 -0
- package/dist/representation/is-json-media-type.d.ts.map +1 -0
- package/dist/representation/is-json-media-type.js +5 -0
- package/dist/representation/is-json-media-type.js.map +1 -0
- package/dist/representation/json-representation.d.ts +14 -0
- package/dist/representation/json-representation.d.ts.map +1 -0
- package/dist/representation/json-representation.js +40 -0
- package/dist/representation/json-representation.js.map +1 -0
- package/dist/representation/malformed-body.d.ts +4 -0
- package/dist/representation/malformed-body.d.ts.map +1 -0
- package/dist/representation/malformed-body.js +6 -0
- package/dist/representation/malformed-body.js.map +1 -0
- package/dist/representation/media-type-of.d.ts +3 -0
- package/dist/representation/media-type-of.d.ts.map +1 -0
- package/dist/representation/media-type-of.js +7 -0
- package/dist/representation/media-type-of.js.map +1 -0
- package/dist/representation/negotiate.d.ts +8 -0
- package/dist/representation/negotiate.d.ts.map +1 -0
- package/dist/representation/negotiate.js +55 -0
- package/dist/representation/negotiate.js.map +1 -0
- package/dist/representation/not-acceptable-error.d.ts +7 -0
- package/dist/representation/not-acceptable-error.d.ts.map +1 -0
- package/dist/representation/not-acceptable-error.js +7 -0
- package/dist/representation/not-acceptable-error.js.map +1 -0
- package/dist/representation/problem-shape.d.ts +4 -0
- package/dist/representation/problem-shape.d.ts.map +1 -0
- package/dist/representation/problem-shape.js +7 -0
- package/dist/representation/problem-shape.js.map +1 -0
- package/dist/representation/representation.d.ts +20 -0
- package/dist/representation/representation.d.ts.map +1 -0
- package/dist/representation/representation.js +9 -0
- package/dist/representation/representation.js.map +1 -0
- package/dist/representation/representations.d.ts +33 -0
- package/dist/representation/representations.d.ts.map +1 -0
- package/dist/representation/representations.js +85 -0
- package/dist/representation/representations.js.map +1 -0
- package/dist/representation/represented-body.d.ts +3 -0
- package/dist/representation/represented-body.d.ts.map +1 -0
- package/dist/representation/represented-body.js +2 -0
- package/dist/representation/represented-body.js.map +1 -0
- package/dist/representation/stream-schema-of.d.ts +10 -0
- package/dist/representation/stream-schema-of.d.ts.map +1 -0
- package/dist/representation/stream-schema-of.js +31 -0
- package/dist/representation/stream-schema-of.js.map +1 -0
- package/dist/representation/unsupported-media-type-error.d.ts +7 -0
- package/dist/representation/unsupported-media-type-error.d.ts.map +1 -0
- package/dist/representation/unsupported-media-type-error.js +7 -0
- package/dist/representation/unsupported-media-type-error.js.map +1 -0
- package/dist/representation/wire-text.d.ts +7 -0
- package/dist/representation/wire-text.d.ts.map +1 -0
- package/dist/representation/wire-text.js +21 -0
- package/dist/representation/wire-text.js.map +1 -0
- package/dist/representation/xml/decode-entities.d.ts +3 -0
- package/dist/representation/xml/decode-entities.d.ts.map +1 -0
- package/dist/representation/xml/decode-entities.js +38 -0
- package/dist/representation/xml/decode-entities.js.map +1 -0
- package/dist/representation/xml/is-xml-name.d.ts +3 -0
- package/dist/representation/xml/is-xml-name.d.ts.map +1 -0
- package/dist/representation/xml/is-xml-name.js +6 -0
- package/dist/representation/xml/is-xml-name.js.map +1 -0
- package/dist/representation/xml/xml-convention.d.ts +10 -0
- package/dist/representation/xml/xml-convention.d.ts.map +1 -0
- package/dist/representation/xml/xml-convention.js +10 -0
- package/dist/representation/xml/xml-convention.js.map +1 -0
- package/dist/representation/xml/xml-element-writer.d.ts +16 -0
- package/dist/representation/xml/xml-element-writer.d.ts.map +1 -0
- package/dist/representation/xml/xml-element-writer.js +71 -0
- package/dist/representation/xml/xml-element-writer.js.map +1 -0
- package/dist/representation/xml/xml-element.d.ts +9 -0
- package/dist/representation/xml/xml-element.d.ts.map +1 -0
- package/dist/representation/xml/xml-element.js +2 -0
- package/dist/representation/xml/xml-element.js.map +1 -0
- package/dist/representation/xml/xml-parser.d.ts +27 -0
- package/dist/representation/xml/xml-parser.d.ts.map +1 -0
- package/dist/representation/xml/xml-parser.js +154 -0
- package/dist/representation/xml/xml-parser.js.map +1 -0
- package/dist/representation/xml/xml-representation.d.ts +20 -0
- package/dist/representation/xml/xml-representation.d.ts.map +1 -0
- package/dist/representation/xml/xml-representation.js +52 -0
- package/dist/representation/xml/xml-representation.js.map +1 -0
- package/dist/representation/xml/xml-syntax-error.d.ts +5 -0
- package/dist/representation/xml/xml-syntax-error.d.ts.map +1 -0
- package/dist/representation/xml/xml-syntax-error.js +8 -0
- package/dist/representation/xml/xml-syntax-error.js.map +1 -0
- package/dist/representation/xml/xml-text.d.ts +7 -0
- package/dist/representation/xml/xml-text.d.ts.map +1 -0
- package/dist/representation/xml/xml-text.js +30 -0
- package/dist/representation/xml/xml-text.js.map +1 -0
- package/dist/representation/xml/xml-value-reader.d.ts +15 -0
- package/dist/representation/xml/xml-value-reader.d.ts.map +1 -0
- package/dist/representation/xml/xml-value-reader.js +101 -0
- package/dist/representation/xml/xml-value-reader.js.map +1 -0
- package/dist/route/answers-with-schema.d.ts +7 -0
- package/dist/route/answers-with-schema.d.ts.map +1 -0
- package/dist/route/answers-with-schema.js +10 -0
- package/dist/route/answers-with-schema.js.map +1 -0
- package/dist/route/route-spec.d.ts +11 -0
- package/dist/route/route-spec.d.ts.map +1 -1
- package/dist/schema/json-schema-of.d.ts +7 -0
- package/dist/schema/json-schema-of.d.ts.map +1 -0
- package/dist/schema/json-schema-of.js +15 -0
- package/dist/schema/json-schema-of.js.map +1 -0
- package/dist/schema/schema-node.d.ts +25 -0
- package/dist/schema/schema-node.d.ts.map +1 -0
- package/dist/schema/schema-node.js +92 -0
- package/dist/schema/schema-node.js.map +1 -0
- package/dist/schema/schema-type.d.ts +3 -0
- package/dist/schema/schema-type.d.ts.map +1 -0
- package/dist/schema/schema-type.js +2 -0
- package/dist/schema/schema-type.js.map +1 -0
- package/dist/schema/xml-hints.d.ts +9 -0
- package/dist/schema/xml-hints.d.ts.map +1 -0
- package/dist/schema/xml-hints.js +2 -0
- package/dist/schema/xml-hints.js.map +1 -0
- package/dist/serialization/decimal-text.d.ts +6 -0
- package/dist/serialization/decimal-text.d.ts.map +1 -0
- package/dist/serialization/decimal-text.js +13 -0
- package/dist/serialization/decimal-text.js.map +1 -0
- package/dist/serialization/money-body.d.ts +6 -0
- package/dist/serialization/money-body.d.ts.map +1 -0
- package/dist/serialization/money-body.js +2 -0
- package/dist/serialization/money-body.js.map +1 -0
- package/dist/serialization/money.d.ts +4 -0
- package/dist/serialization/money.d.ts.map +1 -0
- package/dist/serialization/money.js +10 -0
- package/dist/serialization/money.js.map +1 -0
- package/dist/support/is-async-iterable.d.ts +3 -0
- package/dist/support/is-async-iterable.d.ts.map +1 -0
- package/dist/support/is-async-iterable.js +5 -0
- package/dist/support/is-async-iterable.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BodyShape } from '../body-shape.js';
|
|
2
|
+
import type { RepresentedBody } from '../represented-body.js';
|
|
3
|
+
import type { Representation } from '../representation.js';
|
|
4
|
+
/**
|
|
5
|
+
* `text/csv` for a list of flat rows: a page (its `items`), a list, or a list streamed as it is
|
|
6
|
+
* read. One header line with the names of the properties of a row, in the order of the schema,
|
|
7
|
+
* then one line per row, written one at a time. A body whose rows hold a list or an object is
|
|
8
|
+
* refused when the routes are mounted: CSV has no way to say it. Never read.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CsvRepresentation implements Representation {
|
|
11
|
+
readonly mediaType = "text/csv";
|
|
12
|
+
readonly problemMediaType: undefined;
|
|
13
|
+
write(body: unknown, shape: BodyShape): RepresentedBody;
|
|
14
|
+
refuses(shape: BodyShape): string | undefined;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=csv-representation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-representation.d.ts","sourceRoot":"","sources":["../../../src/representation/csv/csv-representation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACtD,QAAQ,CAAC,SAAS,cAAc;IAEhC,QAAQ,CAAC,gBAAgB,YAAa;IAEtC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,eAAe,CAEtD;IAED,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAU5C;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SchemaNode } from '../../schema/schema-node.js';
|
|
2
|
+
import { isAsyncIterable } from '../../support/is-async-iterable.js';
|
|
3
|
+
import { isRecord } from '../../support/is-record.js';
|
|
4
|
+
import { csvCell } from './csv-cell.js';
|
|
5
|
+
const LINE_END = '\r\n';
|
|
6
|
+
/**
|
|
7
|
+
* `text/csv` for a list of flat rows: a page (its `items`), a list, or a list streamed as it is
|
|
8
|
+
* read. One header line with the names of the properties of a row, in the order of the schema,
|
|
9
|
+
* then one line per row, written one at a time. A body whose rows hold a list or an object is
|
|
10
|
+
* refused when the routes are mounted: CSV has no way to say it. Never read.
|
|
11
|
+
*/
|
|
12
|
+
export class CsvRepresentation {
|
|
13
|
+
mediaType = 'text/csv';
|
|
14
|
+
problemMediaType = undefined;
|
|
15
|
+
write(body, shape) {
|
|
16
|
+
return lines(rowsOf(body), columnsOf(rowNode(shape)));
|
|
17
|
+
}
|
|
18
|
+
refuses(shape) {
|
|
19
|
+
const row = rowNode(shape);
|
|
20
|
+
if (row === undefined) {
|
|
21
|
+
return 'the body is no list and no page of items';
|
|
22
|
+
}
|
|
23
|
+
const nested = row.properties().find(([, node]) => !node.isScalar());
|
|
24
|
+
return nested === undefined ? undefined : `the column "${nested[0]}" holds a list or an object`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The schema of one row: the items of a list, or of the `items` of a page. */
|
|
28
|
+
function rowNode(shape) {
|
|
29
|
+
const node = SchemaNode.of(shape.schema);
|
|
30
|
+
if (node.type() === 'array') {
|
|
31
|
+
return node.items();
|
|
32
|
+
}
|
|
33
|
+
const items = node.properties().find(([name]) => name === 'items')?.[1];
|
|
34
|
+
return items?.type() === 'array' ? items.items() : undefined;
|
|
35
|
+
}
|
|
36
|
+
function columnsOf(row) {
|
|
37
|
+
return (row?.properties() ?? []).map(([name]) => name);
|
|
38
|
+
}
|
|
39
|
+
async function* rowsOf(body) {
|
|
40
|
+
if (isAsyncIterable(body)) {
|
|
41
|
+
yield* body;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const rows = isRecord(body) ? body['items'] : body;
|
|
45
|
+
yield* Array.isArray(rows) ? rows : [];
|
|
46
|
+
}
|
|
47
|
+
async function* lines(rows, columns) {
|
|
48
|
+
yield `${columns.map((column) => csvCell(column)).join(',')}${LINE_END}`;
|
|
49
|
+
for await (const row of rows) {
|
|
50
|
+
const record = isRecord(row) ? row : {};
|
|
51
|
+
yield `${columns.map((column) => csvCell(record[column])).join(',')}${LINE_END}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=csv-representation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-representation.js","sourceRoot":"","sources":["../../../src/representation/csv/csv-representation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAItD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACnB,SAAS,GAAG,UAAU,CAAC;IAEvB,gBAAgB,GAAG,SAAS,CAAC;IAEtC,KAAK,CAAC,IAAa,EAAE,KAAgB;QACnC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,CAAC,KAAgB;QACtB,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,0CAA0C,CAAC;QACpD,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAErE,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,MAAM,CAAC,CAAC,CAAC,6BAA6B,CAAC;IAClG,CAAC;CACF;AAED,+EAA+E;AAC/E,SAAS,OAAO,CAAC,KAAgB;IAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,KAAK,CAAC,MA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;IAEzE,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAExC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,CAAC;IACnF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-json-media-type.d.ts","sourceRoot":"","sources":["../../src/representation/is-json-media-type.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE1D"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** `application/json` and every `+json` suffix, which the JSON body parser of a framework already read. */
|
|
2
|
+
export function isJsonMediaType(mediaType) {
|
|
3
|
+
return mediaType === 'application/json' || mediaType.endsWith('+json');
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=is-json-media-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-json-media-type.js","sourceRoot":"","sources":["../../src/representation/is-json-media-type.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,OAAO,SAAS,KAAK,kBAAkB,IAAI,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RepresentedBody } from './represented-body.js';
|
|
2
|
+
import type { Representation } from './representation.js';
|
|
3
|
+
/**
|
|
4
|
+
* `application/json`, the default of every route: the value as `JSON.stringify` writes it, an
|
|
5
|
+
* instant in ISO 8601 UTC, a big integer as a string. A streamed list is written as one array,
|
|
6
|
+
* an item at a time.
|
|
7
|
+
*/
|
|
8
|
+
export declare class JsonRepresentation implements Representation {
|
|
9
|
+
readonly mediaType = "application/json";
|
|
10
|
+
readonly problemMediaType = "application/problem+json";
|
|
11
|
+
write(body: unknown): RepresentedBody;
|
|
12
|
+
read(text: string): unknown;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=json-representation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-representation.d.ts","sourceRoot":"","sources":["../../src/representation/json-representation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,QAAQ,CAAC,SAAS,sBAAc;IAEhC,QAAQ,CAAC,gBAAgB,8BAA8B;IAEvD,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,CAEpC;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM1B;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isAsyncIterable } from '../support/is-async-iterable.js';
|
|
2
|
+
import { malformedBody } from './malformed-body.js';
|
|
3
|
+
const MEDIA_TYPE = 'application/json';
|
|
4
|
+
/**
|
|
5
|
+
* `application/json`, the default of every route: the value as `JSON.stringify` writes it, an
|
|
6
|
+
* instant in ISO 8601 UTC, a big integer as a string. A streamed list is written as one array,
|
|
7
|
+
* an item at a time.
|
|
8
|
+
*/
|
|
9
|
+
export class JsonRepresentation {
|
|
10
|
+
mediaType = MEDIA_TYPE;
|
|
11
|
+
problemMediaType = 'application/problem+json';
|
|
12
|
+
write(body) {
|
|
13
|
+
return isAsyncIterable(body) ? jsonArray(body) : stringified(body);
|
|
14
|
+
}
|
|
15
|
+
read(text) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(text);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw malformedBody(MEDIA_TYPE);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function* jsonArray(items) {
|
|
25
|
+
let separator = '';
|
|
26
|
+
yield '[';
|
|
27
|
+
for await (const item of items) {
|
|
28
|
+
yield `${separator}${stringified(item)}`;
|
|
29
|
+
separator = ',';
|
|
30
|
+
}
|
|
31
|
+
yield ']';
|
|
32
|
+
}
|
|
33
|
+
function stringified(value) {
|
|
34
|
+
// An item of an array that is undefined is written null, as `JSON.stringify` writes it inside an array.
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
return 'null';
|
|
37
|
+
}
|
|
38
|
+
return JSON.stringify(value, (_key, part) => (typeof part === 'bigint' ? part.toString() : part));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=json-representation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-representation.js","sourceRoot":"","sources":["../../src/representation/json-representation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,SAAS,GAAG,UAAU,CAAC;IAEvB,gBAAgB,GAAG,0BAA0B,CAAC;IAEvD,KAAK,CAAC,IAAa;QACjB,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,CAAC,IAAY;QACf,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF;AAED,KAAK,SAAS,CAAC,CAAC,SAAS,CAAC,KAA6B;IACrD,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,MAAM,GAAG,CAAC;IAEV,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,SAAS,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,MAAM,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,wGAAwG;IACxG,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ValidationError } from '@ddd-ts-kit/validation';
|
|
2
|
+
/** A request body that cannot be read in its media type: answered as an invalid request, without quoting it. */
|
|
3
|
+
export declare function malformedBody(mediaType: string): ValidationError;
|
|
4
|
+
//# sourceMappingURL=malformed-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"malformed-body.d.ts","sourceRoot":"","sources":["../../src/representation/malformed-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,gHAAgH;AAChH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAKhE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ValidationError } from '@ddd-ts-kit/validation';
|
|
2
|
+
/** A request body that cannot be read in its media type: answered as an invalid request, without quoting it. */
|
|
3
|
+
export function malformedBody(mediaType) {
|
|
4
|
+
return new ValidationError([{ path: 'body', code: 'malformed', message: `The body is not well-formed ${mediaType}.` }], 'The request is not valid.');
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=malformed-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"malformed-body.js","sourceRoot":"","sources":["../../src/representation/malformed-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,gHAAgH;AAChH,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,OAAO,IAAI,eAAe,CACxB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,+BAA+B,SAAS,GAAG,EAAE,CAAC,EAC3F,2BAA2B,CAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-type-of.d.ts","sourceRoot":"","sources":["../../src/representation/media-type-of.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKrF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The media type of a `Content-Type` header, in lower case and without its parameters. */
|
|
2
|
+
export function mediaTypeOf(header) {
|
|
3
|
+
const value = Array.isArray(header) ? header[0] : header;
|
|
4
|
+
const mediaType = value?.split(';')[0]?.trim().toLowerCase();
|
|
5
|
+
return mediaType === undefined || mediaType === '' ? undefined : mediaType;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=media-type-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-type-of.js","sourceRoot":"","sources":["../../src/representation/media-type-of.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,UAAU,WAAW,CAAC,MAAqC;IAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzD,MAAM,SAAS,GAAG,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAE7D,OAAO,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The media type to answer in, among those the route offers in its order of preference, for an
|
|
3
|
+
* `Accept` header (RFC 9110, 12.5.1): the offer of highest quality, the most specific range of the
|
|
4
|
+
* header deciding the quality of each offer, the order of the offers breaking ties. Without the
|
|
5
|
+
* header, the first offer; `undefined` when the header accepts none of them.
|
|
6
|
+
*/
|
|
7
|
+
export declare function negotiate(accept: string | undefined, offered: readonly string[]): string | undefined;
|
|
8
|
+
//# sourceMappingURL=negotiate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"negotiate.d.ts","sourceRoot":"","sources":["../../src/representation/negotiate.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAiBpG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const NOT_ACCEPTABLE = 0;
|
|
2
|
+
const EXACT = 2;
|
|
3
|
+
const SAME_TYPE = 1;
|
|
4
|
+
/**
|
|
5
|
+
* The media type to answer in, among those the route offers in its order of preference, for an
|
|
6
|
+
* `Accept` header (RFC 9110, 12.5.1): the offer of highest quality, the most specific range of the
|
|
7
|
+
* header deciding the quality of each offer, the order of the offers breaking ties. Without the
|
|
8
|
+
* header, the first offer; `undefined` when the header accepts none of them.
|
|
9
|
+
*/
|
|
10
|
+
export function negotiate(accept, offered) {
|
|
11
|
+
if (accept === undefined || accept.trim() === '') {
|
|
12
|
+
return offered[0];
|
|
13
|
+
}
|
|
14
|
+
const ranges = accept.split(',').flatMap(mediaRangeOf);
|
|
15
|
+
let chosen;
|
|
16
|
+
for (const offer of offered) {
|
|
17
|
+
const quality = qualityOf(offer, ranges);
|
|
18
|
+
if (quality > NOT_ACCEPTABLE && quality > (chosen?.quality ?? NOT_ACCEPTABLE)) {
|
|
19
|
+
chosen = { offer, quality };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return chosen?.offer;
|
|
23
|
+
}
|
|
24
|
+
function mediaRangeOf(text) {
|
|
25
|
+
const [range = '', ...parameters] = text.split(';').map((part) => part.trim().toLowerCase());
|
|
26
|
+
const [type, subtype] = range.split('/');
|
|
27
|
+
if (type === undefined || type === '' || subtype === undefined || subtype === '') {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const weight = parameters.find((parameter) => parameter.startsWith('q='));
|
|
31
|
+
const quality = weight === undefined ? 1 : Number(weight.slice(2));
|
|
32
|
+
return [{ type, subtype, quality: Number.isFinite(quality) ? quality : NOT_ACCEPTABLE }];
|
|
33
|
+
}
|
|
34
|
+
/** The quality the most specific matching range gives the offer; 0 when none matches. */
|
|
35
|
+
function qualityOf(offer, ranges) {
|
|
36
|
+
const [type = '', subtype = ''] = offer.toLowerCase().split('/');
|
|
37
|
+
let best;
|
|
38
|
+
for (const range of ranges) {
|
|
39
|
+
const specificity = specificityOf(range, { type, subtype });
|
|
40
|
+
if (specificity !== undefined && specificity > (best?.specificity ?? -1)) {
|
|
41
|
+
best = { specificity, quality: range.quality };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return best?.quality ?? NOT_ACCEPTABLE;
|
|
45
|
+
}
|
|
46
|
+
function specificityOf(range, offer) {
|
|
47
|
+
if (range.type === offer.type && range.subtype === offer.subtype) {
|
|
48
|
+
return EXACT;
|
|
49
|
+
}
|
|
50
|
+
if (range.type === offer.type && range.subtype === '*') {
|
|
51
|
+
return SAME_TYPE;
|
|
52
|
+
}
|
|
53
|
+
return range.type === '*' && range.subtype === '*' ? 0 : undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=negotiate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"negotiate.js","sourceRoot":"","sources":["../../src/representation/negotiate.ts"],"names":[],"mappings":"AAMA,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAA0B,EAAE,OAA0B;IAC9E,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACvD,IAAI,MAAwE,CAAC;IAE7E,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAEzC,IAAI,OAAO,GAAG,cAAc,IAAI,OAAO,GAAG,CAAC,MAAM,EAAE,OAAO,IAAI,cAAc,CAAC,EAAE,CAAC;YAC9E,MAAM,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,EAAE,KAAK,CAAC;AACvB,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,CAAC,KAA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AE5D,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,GAAG,CAAC,IAAI,EAAE,WAAW,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACzE,IAAI,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,EAAE,OAAO,IAAI,cAAc,CAAC;AACzC,CAAC;AAED,SAAS,aAAa,CAAC,KAAiB,EAAE,KAA2C;IACnF,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;QACjE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;QACvD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DomainError } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export declare const NOT_ACCEPTABLE = "NOT_ACCEPTABLE";
|
|
3
|
+
/** The `Accept` header of the request names no media type the route answers in: 406. */
|
|
4
|
+
export declare class NotAcceptableError extends DomainError {
|
|
5
|
+
readonly code = "NOT_ACCEPTABLE";
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=not-acceptable-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-acceptable-error.d.ts","sourceRoot":"","sources":["../../src/representation/not-acceptable-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,wFAAwF;AACxF,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,QAAQ,CAAC,IAAI,oBAAkB;CAChC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DomainError } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export const NOT_ACCEPTABLE = 'NOT_ACCEPTABLE';
|
|
3
|
+
/** The `Accept` header of the request names no media type the route answers in: 406. */
|
|
4
|
+
export class NotAcceptableError extends DomainError {
|
|
5
|
+
code = NOT_ACCEPTABLE;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=not-acceptable-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-acceptable-error.js","sourceRoot":"","sources":["../../src/representation/not-acceptable-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAE/C,wFAAwF;AACxF,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACxC,IAAI,GAAG,cAAc,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-shape.d.ts","sourceRoot":"","sources":["../../src/representation/problem-shape.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,yHAAyH;AACzH,eAAO,MAAM,aAAa,EAAE,SAG3B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PROBLEM_SCHEMA } from '../openapi/problem-schema.js';
|
|
2
|
+
/** A refusal in any representation: the problem of RFC 9457, whose XML form is `<problem xmlns="urn:ietf:rfc:7807">`. */
|
|
3
|
+
export const PROBLEM_SHAPE = {
|
|
4
|
+
schema: { ...PROBLEM_SCHEMA, xml: { name: 'problem', namespace: 'urn:ietf:rfc:7807' } },
|
|
5
|
+
name: 'problem',
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=problem-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-shape.js","sourceRoot":"","sources":["../../src/representation/problem-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,yHAAyH;AACzH,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,MAAM,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,mBAAmB,EAAE,EAAE;IACvF,IAAI,EAAE,SAAS;CAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BodyShape } from './body-shape.js';
|
|
2
|
+
import type { RepresentedBody } from './represented-body.js';
|
|
3
|
+
/**
|
|
4
|
+
* Turns the value a route answers into the text of one media type, and back for a request body
|
|
5
|
+
* when the media type is accepted as input. The value is the one the response schema checked:
|
|
6
|
+
* a representation never sees an aggregate. Registered once in the platform (`Representations`)
|
|
7
|
+
* and chosen per request by the `Accept` header.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class Representation {
|
|
10
|
+
/** `application/xml`, without parameters. */
|
|
11
|
+
abstract readonly mediaType: string;
|
|
12
|
+
/** The media type a refusal is written in when this one was negotiated; `undefined`, `application/problem+json`. */
|
|
13
|
+
abstract readonly problemMediaType: string | undefined;
|
|
14
|
+
abstract write(body: unknown, shape: BodyShape): RepresentedBody;
|
|
15
|
+
/** The value the JSON path would have produced, before the schema validates it. Absent, the media type is never read. */
|
|
16
|
+
abstract read?(text: string, shape: BodyShape): unknown;
|
|
17
|
+
/** Why a body of this shape cannot be written in this media type, when it cannot: checked when the routes are mounted. */
|
|
18
|
+
abstract refuses?(shape: BodyShape): string | undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=representation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representation.d.ts","sourceRoot":"","sources":["../../src/representation/representation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;;GAKG;AACH,8BAAsB,cAAc;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAEpC,oHAAoH;IACpH,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvD,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,eAAe,CAAC;IAEjE,yHAAyH;IACzH,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;IAExD,0HAA0H;IAC1H,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;CACzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns the value a route answers into the text of one media type, and back for a request body
|
|
3
|
+
* when the media type is accepted as input. The value is the one the response schema checked:
|
|
4
|
+
* a representation never sees an aggregate. Registered once in the platform (`Representations`)
|
|
5
|
+
* and chosen per request by the `Accept` header.
|
|
6
|
+
*/
|
|
7
|
+
export class Representation {
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=representation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representation.js","sourceRoot":"","sources":["../../src/representation/representation.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAgB,cAAc;CAcnC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Route } from '../route/route.js';
|
|
2
|
+
import type { Representation } from './representation.js';
|
|
3
|
+
/** A representation chosen for a body, with the media type it is written under. */
|
|
4
|
+
export interface Chosen {
|
|
5
|
+
readonly mediaType: string;
|
|
6
|
+
readonly representation: Representation;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The media types an application answers and reads in, registered once in the platform and
|
|
10
|
+
* given to the adapters (`representations` of the mount options) and to the contract generator,
|
|
11
|
+
* which must be given the same. JSON is always there and always first: it is what a route
|
|
12
|
+
* answers when the request says nothing, and what it refuses in when nothing else fits.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Representations {
|
|
15
|
+
private readonly byMediaType;
|
|
16
|
+
private readonly json;
|
|
17
|
+
private constructor();
|
|
18
|
+
/** JSON, XML and CSV, the representations of the kit. */
|
|
19
|
+
static standard(): Representations;
|
|
20
|
+
/** JSON and the given ones; one given for `application/json` replaces the default. */
|
|
21
|
+
static of(...representations: readonly Representation[]): Representations;
|
|
22
|
+
/** What the route answers in, in its order of preference: JSON first, then what it declares in `produces`. */
|
|
23
|
+
offeredBy(route: Pick<Route, 'produces'>): readonly string[];
|
|
24
|
+
answerIn(mediaType: string): Chosen | undefined;
|
|
25
|
+
/** The refusals of an answer negotiated in `mediaType`: its problem media type, else `application/problem+json`. */
|
|
26
|
+
problemIn(mediaType: string | undefined): Chosen;
|
|
27
|
+
/** The representation that reads a body sent in `mediaType`: JSON always, another when the route declares it in `consumes`. */
|
|
28
|
+
readerOf(route: Pick<Route, 'consumes'>, mediaType: string): Representation | undefined;
|
|
29
|
+
/** Refuses, when the routes are mounted, a media type no representation provides and a body it cannot write or read. */
|
|
30
|
+
assertServes(routes: readonly Route[]): void;
|
|
31
|
+
private assertWrites;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=representations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representations.d.ts","sourceRoot":"","sources":["../../src/representation/representations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,mFAAmF;AACnF,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACzC;AAID;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IAEtC,OAAO,eAMN;IAED,yDAAyD;IACzD,MAAM,CAAC,QAAQ,IAAI,eAAe,CAEjC;IAED,sFAAsF;IACtF,MAAM,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,SAAS,cAAc,EAAE,GAAG,eAAe,CAExE;IAED,8GAA8G;IAC9G,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,SAAS,MAAM,EAAE,CAE3D;IAED,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI9C;IAED,oHAAoH;IACpH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQ/C;IAED,+HAA+H;IAC/H,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAQtF;IAED,wHAAwH;IACxH,YAAY,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,CAY3C;IAED,OAAO,CAAC,YAAY;CAoBrB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DeclarationError } from '@ddd-ts-kit/kernel/declarations';
|
|
2
|
+
import { isJsonMediaType } from './is-json-media-type.js';
|
|
3
|
+
import { CsvRepresentation } from './csv/csv-representation.js';
|
|
4
|
+
import { JsonRepresentation } from './json-representation.js';
|
|
5
|
+
import { XmlRepresentation } from './xml/xml-representation.js';
|
|
6
|
+
const JSON_MEDIA_TYPE = 'application/json';
|
|
7
|
+
/**
|
|
8
|
+
* The media types an application answers and reads in, registered once in the platform and
|
|
9
|
+
* given to the adapters (`representations` of the mount options) and to the contract generator,
|
|
10
|
+
* which must be given the same. JSON is always there and always first: it is what a route
|
|
11
|
+
* answers when the request says nothing, and what it refuses in when nothing else fits.
|
|
12
|
+
*/
|
|
13
|
+
export class Representations {
|
|
14
|
+
byMediaType = new Map();
|
|
15
|
+
json;
|
|
16
|
+
constructor(representations) {
|
|
17
|
+
this.json = representations.find(({ mediaType }) => mediaType === JSON_MEDIA_TYPE) ?? new JsonRepresentation();
|
|
18
|
+
for (const representation of [this.json, ...representations]) {
|
|
19
|
+
this.byMediaType.set(representation.mediaType, representation);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** JSON, XML and CSV, the representations of the kit. */
|
|
23
|
+
static standard() {
|
|
24
|
+
return new Representations([new XmlRepresentation(), new CsvRepresentation()]);
|
|
25
|
+
}
|
|
26
|
+
/** JSON and the given ones; one given for `application/json` replaces the default. */
|
|
27
|
+
static of(...representations) {
|
|
28
|
+
return new Representations(representations);
|
|
29
|
+
}
|
|
30
|
+
/** What the route answers in, in its order of preference: JSON first, then what it declares in `produces`. */
|
|
31
|
+
offeredBy(route) {
|
|
32
|
+
return [JSON_MEDIA_TYPE, ...(route.produces ?? []).filter((type) => this.byMediaType.has(type))];
|
|
33
|
+
}
|
|
34
|
+
answerIn(mediaType) {
|
|
35
|
+
const representation = this.byMediaType.get(mediaType);
|
|
36
|
+
return representation === undefined ? undefined : { mediaType, representation };
|
|
37
|
+
}
|
|
38
|
+
/** The refusals of an answer negotiated in `mediaType`: its problem media type, else `application/problem+json`. */
|
|
39
|
+
problemIn(mediaType) {
|
|
40
|
+
const negotiated = mediaType === undefined ? undefined : this.byMediaType.get(mediaType);
|
|
41
|
+
if (negotiated?.problemMediaType !== undefined) {
|
|
42
|
+
return { mediaType: negotiated.problemMediaType, representation: negotiated };
|
|
43
|
+
}
|
|
44
|
+
return { mediaType: 'application/problem+json', representation: this.json };
|
|
45
|
+
}
|
|
46
|
+
/** The representation that reads a body sent in `mediaType`: JSON always, another when the route declares it in `consumes`. */
|
|
47
|
+
readerOf(route, mediaType) {
|
|
48
|
+
const consumed = isJsonMediaType(mediaType) || route.consumes?.includes(mediaType) === true;
|
|
49
|
+
const representation = consumed
|
|
50
|
+
? this.byMediaType.get(isJsonMediaType(mediaType) ? JSON_MEDIA_TYPE : mediaType)
|
|
51
|
+
: undefined;
|
|
52
|
+
return representation?.read === undefined ? undefined : representation;
|
|
53
|
+
}
|
|
54
|
+
/** Refuses, when the routes are mounted, a media type no representation provides and a body it cannot write or read. */
|
|
55
|
+
assertServes(routes) {
|
|
56
|
+
for (const route of routes) {
|
|
57
|
+
for (const mediaType of route.produces ?? []) {
|
|
58
|
+
this.assertWrites(route, mediaType);
|
|
59
|
+
}
|
|
60
|
+
for (const mediaType of route.consumes ?? []) {
|
|
61
|
+
if (this.byMediaType.get(mediaType)?.read === undefined) {
|
|
62
|
+
throw new DeclarationError(`Route "${route.operationId}" consumes ${mediaType}, which is never read.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
assertWrites(route, mediaType) {
|
|
68
|
+
const representation = this.byMediaType.get(mediaType);
|
|
69
|
+
if (representation === undefined) {
|
|
70
|
+
throw new DeclarationError(`Route "${route.operationId}" declares ${mediaType}, and no representation of the platform provides it.`);
|
|
71
|
+
}
|
|
72
|
+
// A copy has a string index, which is how the statuses are enumerated.
|
|
73
|
+
const declared = { ...route.responses };
|
|
74
|
+
for (const response of Object.values(declared)) {
|
|
75
|
+
const reason = response.body === undefined ? undefined : representation.refuses?.(shapeOf(route, response.body));
|
|
76
|
+
if (reason !== undefined) {
|
|
77
|
+
throw new DeclarationError(`Route "${route.operationId}" cannot answer in ${mediaType}: ${reason}.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function shapeOf(route, body) {
|
|
83
|
+
return { schema: body.toJsonSchema(), name: route.operationId };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=representations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representations.js","sourceRoot":"","sources":["../../src/representation/representations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAKnE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAQhE,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACT,WAAW,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEhD,IAAI,CAAiB;IAEtC,YAAoB,eAA0C;QAC5D,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,eAAe,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAAC;QAE/G,KAAK,MAAM,cAAc,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,eAAe,CAAC,EAAE,CAAC;YAC7D,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,yDAAyD;IACzD,MAAM,CAAC,QAAQ;QACb,OAAO,IAAI,eAAe,CAAC,CAAC,IAAI,iBAAiB,EAAE,EAAE,IAAI,iBAAiB,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,EAAE,CAAC,GAAG,eAA0C;QACrD,OAAO,IAAI,eAA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C,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAEjH,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,MAAM,IAAI,gBAAgB,CAAC,UAAU,KAAK,CAAC,WAAW,sBAAsB,SAAS,KAAK,MAAM,GAAG,CAAC,CAAC;YACvG,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,SAAS,OAAO,CAAC,KAAY,EAAE,IAAqB;IAClD,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"represented-body.d.ts","sourceRoot":"","sources":["../../src/representation/represented-body.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"represented-body.js","sourceRoot":"","sources":["../../src/representation/represented-body.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Schema } from '@ddd-ts-kit/validation';
|
|
2
|
+
/**
|
|
3
|
+
* The schema of a list a route answers as it reads it (an export), from the schema of one item:
|
|
4
|
+
* the handler returns an `AsyncIterable`, every representation writes it chunk by chunk, and the
|
|
5
|
+
* contract describes it as an array. What `parse` answers checks each item as it is read; the
|
|
6
|
+
* pipeline, which writes what the handler returned, checks with `validateResponses` only that a
|
|
7
|
+
* list was returned.
|
|
8
|
+
*/
|
|
9
|
+
export declare function streamSchemaOf<T>(item: Schema<T>): Schema<AsyncIterable<T>>;
|
|
10
|
+
//# sourceMappingURL=stream-schema-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-schema-of.d.ts","sourceRoot":"","sources":["../../src/representation/stream-schema-of.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIjF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAmB3E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { err, ok } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { customSchema, parseOrThrow } from '@ddd-ts-kit/validation';
|
|
3
|
+
import { fieldAccess } from '../field-access/field-access.js';
|
|
4
|
+
import { isAsyncIterable } from '../support/is-async-iterable.js';
|
|
5
|
+
/**
|
|
6
|
+
* The schema of a list a route answers as it reads it (an export), from the schema of one item:
|
|
7
|
+
* the handler returns an `AsyncIterable`, every representation writes it chunk by chunk, and the
|
|
8
|
+
* contract describes it as an array. What `parse` answers checks each item as it is read; the
|
|
9
|
+
* pipeline, which writes what the handler returned, checks with `validateResponses` only that a
|
|
10
|
+
* list was returned.
|
|
11
|
+
*/
|
|
12
|
+
export function streamSchemaOf(item) {
|
|
13
|
+
const { $schema: _dialect, $defs, definitions, ...itemSchema } = item.toJsonSchema();
|
|
14
|
+
const stream = customSchema((input) => isAsyncIterable(input)
|
|
15
|
+
? ok(checked(input, item))
|
|
16
|
+
: err([{ path: '', code: 'invalid_stream', message: 'A list read as it comes is expected.' }]), {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: itemSchema,
|
|
19
|
+
...($defs === undefined ? {} : { $defs }),
|
|
20
|
+
...(definitions === undefined ? {} : { definitions }),
|
|
21
|
+
});
|
|
22
|
+
fieldAccess.carry(item, stream, ['*']);
|
|
23
|
+
return stream;
|
|
24
|
+
}
|
|
25
|
+
/** Each item through the schema as it is read: an item that does not match stops the list. */
|
|
26
|
+
async function* checked(items, schema) {
|
|
27
|
+
for await (const item of items) {
|
|
28
|
+
yield parseOrThrow(schema, item);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=stream-schema-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-schema-of.js","sourceRoot":"","sources":["../../src/representation/stream-schema-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAe,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAI,IAAe;IAC/C,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IAErF,MAAM,MAAM,GAAG,YAAY,CACzB,CAAC,KAAK,EAAE,EAAE,CACR,eAAe,CAAC,KAAK,CAAC;QACpB,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC1B,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,sCAAsC,EAAE,CAAC,CAAC,EAClG;QACE,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,UAAU;QACjB,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QACzC,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;KACtD,CACF,CAAC;IAEF,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEvC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,8FAA8F;AAC9F,KAAK,SAAS,CAAC,CAAC,OAAO,CAAI,KAA6B,EAAE,MAAiB;IACzE,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,MAAM,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DomainError } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export declare const UNSUPPORTED_MEDIA_TYPE = "UNSUPPORTED_MEDIA_TYPE";
|
|
3
|
+
/** The body of the request is in a media type the route does not read: 415. */
|
|
4
|
+
export declare class UnsupportedMediaTypeError extends DomainError {
|
|
5
|
+
readonly code = "UNSUPPORTED_MEDIA_TYPE";
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=unsupported-media-type-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsupported-media-type-error.d.ts","sourceRoot":"","sources":["../../src/representation/unsupported-media-type-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAE/D,+EAA+E;AAC/E,qBAAa,yBAA0B,SAAQ,WAAW;IACxD,QAAQ,CAAC,IAAI,4BAA0B;CACxC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DomainError } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export const UNSUPPORTED_MEDIA_TYPE = 'UNSUPPORTED_MEDIA_TYPE';
|
|
3
|
+
/** The body of the request is in a media type the route does not read: 415. */
|
|
4
|
+
export class UnsupportedMediaTypeError extends DomainError {
|
|
5
|
+
code = UNSUPPORTED_MEDIA_TYPE;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=unsupported-media-type-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsupported-media-type-error.js","sourceRoot":"","sources":["../../src/representation/unsupported-media-type-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,+EAA+E;AAC/E,MAAM,OAAO,yBAA0B,SAAQ,WAAW;IAC/C,IAAI,GAAG,sBAAsB,CAAC;CACxC"}
|