@ddd-ts-kit/http 0.0.0-stage → 0.1.1
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 +388 -2
- package/dist/criteria/coerce-value.d.ts +8 -0
- package/dist/criteria/coerce-value.d.ts.map +1 -0
- package/dist/criteria/coerce-value.js +29 -0
- package/dist/criteria/coerce-value.js.map +1 -0
- package/dist/criteria/criteria-from.d.ts +11 -0
- package/dist/criteria/criteria-from.d.ts.map +1 -0
- package/dist/criteria/criteria-from.js +17 -0
- package/dist/criteria/criteria-from.js.map +1 -0
- package/dist/criteria/criteria-parameters.d.ts +10 -0
- package/dist/criteria/criteria-parameters.d.ts.map +1 -0
- package/dist/criteria/criteria-parameters.js +45 -0
- package/dist/criteria/criteria-parameters.js.map +1 -0
- package/dist/criteria/criteria-query-options.d.ts +6 -0
- package/dist/criteria/criteria-query-options.d.ts.map +1 -0
- package/dist/criteria/criteria-query-options.js +2 -0
- package/dist/criteria/criteria-query-options.js.map +1 -0
- package/dist/criteria/criteria-query-schema.d.ts +10 -0
- package/dist/criteria/criteria-query-schema.d.ts.map +1 -0
- package/dist/criteria/criteria-query-schema.js +12 -0
- package/dist/criteria/criteria-query-schema.js.map +1 -0
- package/dist/criteria/filter-entries.d.ts +9 -0
- package/dist/criteria/filter-entries.d.ts.map +1 -0
- package/dist/criteria/filter-entries.js +28 -0
- package/dist/criteria/filter-entries.js.map +1 -0
- package/dist/criteria/filter-entry.d.ts +6 -0
- package/dist/criteria/filter-entry.d.ts.map +1 -0
- package/dist/criteria/filter-entry.js +2 -0
- package/dist/criteria/filter-entry.js.map +1 -0
- package/dist/criteria/parse-condition.d.ts +7 -0
- package/dist/criteria/parse-condition.d.ts.map +1 -0
- package/dist/criteria/parse-condition.js +52 -0
- package/dist/criteria/parse-condition.js.map +1 -0
- package/dist/criteria/parse-criteria-query.d.ts +5 -0
- package/dist/criteria/parse-criteria-query.d.ts.map +1 -0
- package/dist/criteria/parse-criteria-query.js +31 -0
- package/dist/criteria/parse-criteria-query.js.map +1 -0
- package/dist/criteria/parse-filters.d.ts +15 -0
- package/dist/criteria/parse-filters.d.ts.map +1 -0
- package/dist/criteria/parse-filters.js +52 -0
- package/dist/criteria/parse-filters.js.map +1 -0
- package/dist/criteria/sortable-fields.d.ts +4 -0
- package/dist/criteria/sortable-fields.d.ts.map +1 -0
- package/dist/criteria/sortable-fields.js +6 -0
- package/dist/criteria/sortable-fields.js.map +1 -0
- package/dist/criteria/split-list.d.ts +3 -0
- package/dist/criteria/split-list.d.ts.map +1 -0
- package/dist/criteria/split-list.js +19 -0
- package/dist/criteria/split-list.js.map +1 -0
- package/dist/docs/docs-page.d.ts +11 -0
- package/dist/docs/docs-page.d.ts.map +1 -0
- package/dist/docs/docs-page.js +18 -0
- package/dist/docs/docs-page.js.map +1 -0
- package/dist/docs/docs-ui.d.ts +2 -0
- package/dist/docs/docs-ui.d.ts.map +1 -0
- package/dist/docs/docs-ui.js +2 -0
- package/dist/docs/docs-ui.js.map +1 -0
- package/dist/docs/open-api-docs-routes.d.ts +22 -0
- package/dist/docs/open-api-docs-routes.d.ts.map +1 -0
- package/dist/docs/open-api-docs-routes.js +54 -0
- package/dist/docs/open-api-docs-routes.js.map +1 -0
- package/dist/docs.d.ts +3 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +2 -0
- package/dist/docs.js.map +1 -0
- package/dist/error/create-error-mapper.d.ts +10 -0
- package/dist/error/create-error-mapper.d.ts.map +1 -0
- package/dist/error/create-error-mapper.js +12 -0
- package/dist/error/create-error-mapper.js.map +1 -0
- package/dist/error/default-error-mapping.d.ts +3 -0
- package/dist/error/default-error-mapping.d.ts.map +1 -0
- package/dist/error/default-error-mapping.js +9 -0
- package/dist/error/default-error-mapping.js.map +1 -0
- package/dist/error/error-mapper.d.ts +12 -0
- package/dist/error/error-mapper.d.ts.map +1 -0
- package/dist/error/error-mapper.js +8 -0
- package/dist/error/error-mapper.js.map +1 -0
- package/dist/error/error-mapping.d.ts +3 -0
- package/dist/error/error-mapping.d.ts.map +1 -0
- package/dist/error/error-mapping.js +2 -0
- package/dist/error/error-mapping.js.map +1 -0
- package/dist/error/forbidden-error.d.ts +5 -0
- package/dist/error/forbidden-error.d.ts.map +1 -0
- package/dist/error/forbidden-error.js +5 -0
- package/dist/error/forbidden-error.js.map +1 -0
- package/dist/error/internal-error-code.d.ts +2 -0
- package/dist/error/internal-error-code.d.ts.map +1 -0
- package/dist/error/internal-error-code.js +2 -0
- package/dist/error/internal-error-code.js.map +1 -0
- package/dist/error/problem.d.ts +11 -0
- package/dist/error/problem.d.ts.map +1 -0
- package/dist/error/problem.js +2 -0
- package/dist/error/problem.js.map +1 -0
- package/dist/error/response-contract-error.d.ts +7 -0
- package/dist/error/response-contract-error.d.ts.map +1 -0
- package/dist/error/response-contract-error.js +10 -0
- package/dist/error/response-contract-error.js.map +1 -0
- package/dist/error/status-title.d.ts +2 -0
- package/dist/error/status-title.d.ts.map +1 -0
- package/dist/error/status-title.js +28 -0
- package/dist/error/status-title.js.map +1 -0
- package/dist/error/to-problem.d.ts +4 -0
- package/dist/error/to-problem.d.ts.map +1 -0
- package/dist/error/to-problem.js +34 -0
- package/dist/error/to-problem.js.map +1 -0
- package/dist/error/unauthorized-error.d.ts +5 -0
- package/dist/error/unauthorized-error.d.ts.map +1 -0
- package/dist/error/unauthorized-error.js +5 -0
- package/dist/error/unauthorized-error.js.map +1 -0
- package/dist/express/mount-express.d.ts +10 -0
- package/dist/express/mount-express.d.ts.map +1 -0
- package/dist/express/mount-express.js +38 -0
- package/dist/express/mount-express.js.map +1 -0
- package/dist/express.d.ts +2 -0
- package/dist/express.d.ts.map +1 -0
- package/dist/express.js +2 -0
- package/dist/express.js.map +1 -0
- package/dist/fastify/fastify-mount-options.d.ts +3 -0
- package/dist/fastify/fastify-mount-options.d.ts.map +1 -0
- package/dist/fastify/fastify-mount-options.js +2 -0
- package/dist/fastify/fastify-mount-options.js.map +1 -0
- package/dist/fastify/fastify-routes.d.ts +6 -0
- package/dist/fastify/fastify-routes.d.ts.map +1 -0
- package/dist/fastify/fastify-routes.js +10 -0
- package/dist/fastify/fastify-routes.js.map +1 -0
- package/dist/fastify/mount-fastify.d.ts +6 -0
- package/dist/fastify/mount-fastify.d.ts.map +1 -0
- package/dist/fastify/mount-fastify.js +19 -0
- package/dist/fastify/mount-fastify.js.map +1 -0
- package/dist/fastify.d.ts +4 -0
- package/dist/fastify.d.ts.map +1 -0
- package/dist/fastify.js +3 -0
- package/dist/fastify.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/nest/create-routes-module.d.ts +15 -0
- package/dist/nest/create-routes-module.d.ts.map +1 -0
- package/dist/nest/create-routes-module.js +54 -0
- package/dist/nest/create-routes-module.js.map +1 -0
- package/dist/nest/routes-factory.d.ts +8 -0
- package/dist/nest/routes-factory.d.ts.map +1 -0
- package/dist/nest/routes-factory.js +2 -0
- package/dist/nest/routes-factory.js.map +1 -0
- package/dist/nest/routes-mounter.d.ts +9 -0
- package/dist/nest/routes-mounter.d.ts.map +1 -0
- package/dist/nest/routes-mounter.js +8 -0
- package/dist/nest/routes-mounter.js.map +1 -0
- package/dist/nest.d.ts +4 -0
- package/dist/nest.d.ts.map +1 -0
- package/dist/nest.js +3 -0
- package/dist/nest.js.map +1 -0
- package/dist/openapi/check-open-api-drift.d.ts +6 -0
- package/dist/openapi/check-open-api-drift.d.ts.map +1 -0
- package/dist/openapi/check-open-api-drift.js +6 -0
- package/dist/openapi/check-open-api-drift.js.map +1 -0
- package/dist/openapi/compare.d.ts +3 -0
- package/dist/openapi/compare.d.ts.map +1 -0
- package/dist/openapi/compare.js +5 -0
- package/dist/openapi/compare.js.map +1 -0
- package/dist/openapi/definitions.d.ts +14 -0
- package/dist/openapi/definitions.d.ts.map +1 -0
- package/dist/openapi/definitions.js +61 -0
- package/dist/openapi/definitions.js.map +1 -0
- package/dist/openapi/generate-open-api.d.ts +21 -0
- package/dist/openapi/generate-open-api.d.ts.map +1 -0
- package/dist/openapi/generate-open-api.js +43 -0
- package/dist/openapi/generate-open-api.js.map +1 -0
- package/dist/openapi/open-api-document.d.ts +18 -0
- package/dist/openapi/open-api-document.d.ts.map +1 -0
- package/dist/openapi/open-api-document.js +2 -0
- package/dist/openapi/open-api-document.js.map +1 -0
- package/dist/openapi/open-api-info.d.ts +6 -0
- package/dist/openapi/open-api-info.d.ts.map +1 -0
- package/dist/openapi/open-api-info.js +2 -0
- package/dist/openapi/open-api-info.js.map +1 -0
- package/dist/openapi/open-api-path.d.ts +2 -0
- package/dist/openapi/open-api-path.d.ts.map +1 -0
- package/dist/openapi/open-api-path.js +4 -0
- package/dist/openapi/open-api-path.js.map +1 -0
- package/dist/openapi/open-api-server.d.ts +5 -0
- package/dist/openapi/open-api-server.d.ts.map +1 -0
- package/dist/openapi/open-api-server.js +2 -0
- package/dist/openapi/open-api-server.js.map +1 -0
- package/dist/openapi/path-items.d.ts +7 -0
- package/dist/openapi/path-items.d.ts.map +1 -0
- package/dist/openapi/path-items.js +43 -0
- package/dist/openapi/path-items.js.map +1 -0
- package/dist/openapi/path-parameters.d.ts +4 -0
- package/dist/openapi/path-parameters.d.ts.map +1 -0
- package/dist/openapi/path-parameters.js +13 -0
- package/dist/openapi/path-parameters.js.map +1 -0
- package/dist/openapi/problem-schema.d.ts +3 -0
- package/dist/openapi/problem-schema.d.ts.map +1 -0
- package/dist/openapi/problem-schema.js +27 -0
- package/dist/openapi/problem-schema.js.map +1 -0
- package/dist/openapi/requirement.d.ts +3 -0
- package/dist/openapi/requirement.d.ts.map +1 -0
- package/dist/openapi/requirement.js +5 -0
- package/dist/openapi/requirement.js.map +1 -0
- package/dist/openapi/responses.d.ts +7 -0
- package/dist/openapi/responses.d.ts.map +1 -0
- package/dist/openapi/responses.js +50 -0
- package/dist/openapi/responses.js.map +1 -0
- package/dist/openapi/schema-parameters.d.ts +5 -0
- package/dist/openapi/schema-parameters.d.ts.map +1 -0
- package/dist/openapi/schema-parameters.js +24 -0
- package/dist/openapi/schema-parameters.js.map +1 -0
- package/dist/openapi/stringify-open-api.d.ts +4 -0
- package/dist/openapi/stringify-open-api.d.ts.map +1 -0
- package/dist/openapi/stringify-open-api.js +5 -0
- package/dist/openapi/stringify-open-api.js.map +1 -0
- package/dist/openapi.d.ts +7 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +4 -0
- package/dist/openapi.js.map +1 -0
- package/dist/pagination/issue.d.ts +3 -0
- package/dist/pagination/issue.d.ts.map +1 -0
- package/dist/pagination/issue.js +4 -0
- package/dist/pagination/issue.js.map +1 -0
- package/dist/pagination/limits-of.d.ts +3 -0
- package/dist/pagination/limits-of.d.ts.map +1 -0
- package/dist/pagination/limits-of.js +8 -0
- package/dist/pagination/limits-of.js.map +1 -0
- package/dist/pagination/page-body.d.ts +7 -0
- package/dist/pagination/page-body.d.ts.map +1 -0
- package/dist/pagination/page-body.js +2 -0
- package/dist/pagination/page-body.js.map +1 -0
- package/dist/pagination/page-query-options.d.ts +8 -0
- package/dist/pagination/page-query-options.d.ts.map +1 -0
- package/dist/pagination/page-query-options.js +2 -0
- package/dist/pagination/page-query-options.js.map +1 -0
- package/dist/pagination/page-query-schema.d.ts +6 -0
- package/dist/pagination/page-query-schema.d.ts.map +1 -0
- package/dist/pagination/page-query-schema.js +8 -0
- package/dist/pagination/page-query-schema.js.map +1 -0
- package/dist/pagination/page-request-from.d.ts +9 -0
- package/dist/pagination/page-request-from.d.ts.map +1 -0
- package/dist/pagination/page-request-from.js +16 -0
- package/dist/pagination/page-request-from.js.map +1 -0
- package/dist/pagination/page-request-parameters.d.ts +9 -0
- package/dist/pagination/page-request-parameters.d.ts.map +1 -0
- package/dist/pagination/page-request-parameters.js +30 -0
- package/dist/pagination/page-request-parameters.js.map +1 -0
- package/dist/pagination/page-response.d.ts +5 -0
- package/dist/pagination/page-response.d.ts.map +1 -0
- package/dist/pagination/page-response.js +9 -0
- package/dist/pagination/page-response.js.map +1 -0
- package/dist/pagination/page-schema-of.d.ts +9 -0
- package/dist/pagination/page-schema-of.d.ts.map +1 -0
- package/dist/pagination/page-schema-of.js +60 -0
- package/dist/pagination/page-schema-of.js.map +1 -0
- package/dist/pagination/parse-page-query.d.ts +5 -0
- package/dist/pagination/parse-page-query.d.ts.map +1 -0
- package/dist/pagination/parse-page-query.js +108 -0
- package/dist/pagination/parse-page-query.js.map +1 -0
- package/dist/pipeline/assert-declared-response.d.ts +4 -0
- package/dist/pipeline/assert-declared-response.d.ts.map +1 -0
- package/dist/pipeline/assert-declared-response.js +18 -0
- package/dist/pipeline/assert-declared-response.js.map +1 -0
- package/dist/pipeline/correlation-header.d.ts +2 -0
- package/dist/pipeline/correlation-header.d.ts.map +1 -0
- package/dist/pipeline/correlation-header.js +2 -0
- package/dist/pipeline/correlation-header.js.map +1 -0
- package/dist/pipeline/correlation-id-of.d.ts +4 -0
- package/dist/pipeline/correlation-id-of.d.ts.map +1 -0
- package/dist/pipeline/correlation-id-of.js +7 -0
- package/dist/pipeline/correlation-id-of.js.map +1 -0
- package/dist/pipeline/error-context.d.ts +15 -0
- package/dist/pipeline/error-context.d.ts.map +1 -0
- package/dist/pipeline/error-context.js +2 -0
- package/dist/pipeline/error-context.js.map +1 -0
- package/dist/pipeline/execute-options.d.ts +40 -0
- package/dist/pipeline/execute-options.d.ts.map +1 -0
- package/dist/pipeline/execute-options.js +2 -0
- package/dist/pipeline/execute-options.js.map +1 -0
- package/dist/pipeline/execute-route.d.ts +6 -0
- package/dist/pipeline/execute-route.d.ts.map +1 -0
- package/dist/pipeline/execute-route.js +108 -0
- package/dist/pipeline/execute-route.js.map +1 -0
- package/dist/pipeline/execution-of-request.d.ts +16 -0
- package/dist/pipeline/execution-of-request.d.ts.map +1 -0
- package/dist/pipeline/execution-of-request.js +44 -0
- package/dist/pipeline/execution-of-request.js.map +1 -0
- package/dist/pipeline/raw-request.d.ts +10 -0
- package/dist/pipeline/raw-request.d.ts.map +1 -0
- package/dist/pipeline/raw-request.js +2 -0
- package/dist/pipeline/raw-request.js.map +1 -0
- package/dist/pipeline/report-http-errors.d.ts +11 -0
- package/dist/pipeline/report-http-errors.d.ts.map +1 -0
- package/dist/pipeline/report-http-errors.js +17 -0
- package/dist/pipeline/report-http-errors.js.map +1 -0
- package/dist/pipeline/route-around.d.ts +5 -0
- package/dist/pipeline/route-around.d.ts.map +1 -0
- package/dist/pipeline/route-around.js +2 -0
- package/dist/pipeline/route-around.js.map +1 -0
- package/dist/pipeline/route-response.d.ts +7 -0
- package/dist/pipeline/route-response.d.ts.map +1 -0
- package/dist/pipeline/route-response.js +2 -0
- package/dist/pipeline/route-response.js.map +1 -0
- package/dist/pipeline/serialize-body.d.ts +7 -0
- package/dist/pipeline/serialize-body.d.ts.map +1 -0
- package/dist/pipeline/serialize-body.js +16 -0
- package/dist/pipeline/serialize-body.js.map +1 -0
- package/dist/pipeline/validate-request.d.ts +8 -0
- package/dist/pipeline/validate-request.d.ts.map +1 -0
- package/dist/pipeline/validate-request.js +30 -0
- package/dist/pipeline/validate-request.js.map +1 -0
- package/dist/pipeline/well-formed-identifier.d.ts +3 -0
- package/dist/pipeline/well-formed-identifier.d.ts.map +1 -0
- package/dist/pipeline/well-formed-identifier.js +6 -0
- package/dist/pipeline/well-formed-identifier.js.map +1 -0
- package/dist/route/assert-unique-routes.d.ts +3 -0
- package/dist/route/assert-unique-routes.d.ts.map +1 -0
- package/dist/route/assert-unique-routes.js +22 -0
- package/dist/route/assert-unique-routes.js.map +1 -0
- package/dist/route/define-route.d.ts +7 -0
- package/dist/route/define-route.d.ts.map +1 -0
- package/dist/route/define-route.js +17 -0
- package/dist/route/define-route.js.map +1 -0
- package/dist/route/define-routes.d.ts +4 -0
- package/dist/route/define-routes.d.ts.map +1 -0
- package/dist/route/define-routes.js +11 -0
- package/dist/route/define-routes.js.map +1 -0
- package/dist/route/duplicate-route-error.d.ts +4 -0
- package/dist/route/duplicate-route-error.d.ts.map +1 -0
- package/dist/route/duplicate-route-error.js +7 -0
- package/dist/route/duplicate-route-error.js.map +1 -0
- package/dist/route/handler-input.d.ts +23 -0
- package/dist/route/handler-input.d.ts.map +1 -0
- package/dist/route/handler-input.js +2 -0
- package/dist/route/handler-input.js.map +1 -0
- package/dist/route/handler-result.d.ts +20 -0
- package/dist/route/handler-result.d.ts.map +1 -0
- package/dist/route/handler-result.js +2 -0
- package/dist/route/handler-result.js.map +1 -0
- package/dist/route/http-method.d.ts +2 -0
- package/dist/route/http-method.d.ts.map +1 -0
- package/dist/route/http-method.js +2 -0
- package/dist/route/http-method.js.map +1 -0
- package/dist/route/prefix-routes.d.ts +4 -0
- package/dist/route/prefix-routes.d.ts.map +1 -0
- package/dist/route/prefix-routes.js +10 -0
- package/dist/route/prefix-routes.js.map +1 -0
- package/dist/route/raw-headers.d.ts +2 -0
- package/dist/route/raw-headers.d.ts.map +1 -0
- package/dist/route/raw-headers.js +2 -0
- package/dist/route/raw-headers.js.map +1 -0
- package/dist/route/request-context.d.ts +13 -0
- package/dist/route/request-context.d.ts.map +1 -0
- package/dist/route/request-context.js +2 -0
- package/dist/route/request-context.js.map +1 -0
- package/dist/route/request-schemas.d.ts +8 -0
- package/dist/route/request-schemas.d.ts.map +1 -0
- package/dist/route/request-schemas.js +2 -0
- package/dist/route/request-schemas.js.map +1 -0
- package/dist/route/response-spec.d.ts +6 -0
- package/dist/route/response-spec.d.ts.map +1 -0
- package/dist/route/response-spec.js +2 -0
- package/dist/route/response-spec.js.map +1 -0
- package/dist/route/responses-spec.d.ts +5 -0
- package/dist/route/responses-spec.d.ts.map +1 -0
- package/dist/route/responses-spec.js +2 -0
- package/dist/route/responses-spec.js.map +1 -0
- package/dist/route/route-handler.d.ts +6 -0
- package/dist/route/route-handler.d.ts.map +1 -0
- package/dist/route/route-handler.js +2 -0
- package/dist/route/route-handler.js.map +1 -0
- package/dist/route/route-input.d.ts +10 -0
- package/dist/route/route-input.d.ts.map +1 -0
- package/dist/route/route-input.js +2 -0
- package/dist/route/route-input.js.map +1 -0
- package/dist/route/route-output.d.ts +6 -0
- package/dist/route/route-output.d.ts.map +1 -0
- package/dist/route/route-output.js +2 -0
- package/dist/route/route-output.js.map +1 -0
- package/dist/route/route-spec.d.ts +23 -0
- package/dist/route/route-spec.d.ts.map +1 -0
- package/dist/route/route-spec.js +2 -0
- package/dist/route/route-spec.js.map +1 -0
- package/dist/route/route.d.ts +11 -0
- package/dist/route/route.d.ts.map +1 -0
- package/dist/route/route.js +2 -0
- package/dist/route/route.js.map +1 -0
- package/dist/route/without-trailing-slashes.d.ts +3 -0
- package/dist/route/without-trailing-slashes.d.ts.map +1 -0
- package/dist/route/without-trailing-slashes.js +9 -0
- package/dist/route/without-trailing-slashes.js.map +1 -0
- package/dist/support/is-record.d.ts +2 -0
- package/dist/support/is-record.d.ts.map +1 -0
- package/dist/support/is-record.js +4 -0
- package/dist/support/is-record.js.map +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue.js","sourceRoot":"","sources":["../../src/pagination/issue.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,IAAY,EAAE,OAAe;IAC/D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits-of.d.ts","sourceRoot":"","sources":["../../src/pagination/limits-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE1E,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAKjE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DEFAULT_PAGE_LIMITS } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export function limitsOf(options) {
|
|
3
|
+
return {
|
|
4
|
+
defaultSize: options.defaultSize ?? DEFAULT_PAGE_LIMITS.defaultSize,
|
|
5
|
+
maxSize: options.maxSize ?? DEFAULT_PAGE_LIMITS.maxSize,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=limits-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits-of.js","sourceRoot":"","sources":["../../src/pagination/limits-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAmB,MAAM,oBAAoB,CAAC;AAE1E,MAAM,UAAU,QAAQ,CAAC,OAA4B;IACnD,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAAC,WAAW;QACnE,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAAC,OAAO;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-body.d.ts","sourceRoot":"","sources":["../../src/pagination/page-body.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-body.js","sourceRoot":"","sources":["../../src/pagination/page-body.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PageLimits, PageRequest } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export interface PageQueryOptions<Field extends string = never> extends Partial<PageLimits> {
|
|
3
|
+
/** The closed list of fields a client may sort by. Without it, a `sort` parameter is refused. */
|
|
4
|
+
readonly sortable?: readonly Field[];
|
|
5
|
+
/** The variant of a query that names neither `offset` nor `cursor`. Default `offset`. */
|
|
6
|
+
readonly kind?: PageRequest['kind'];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=page-query-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-query-options.d.ts","sourceRoot":"","sources":["../../src/pagination/page-query-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAElE,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,CAAE,SAAQ,OAAO,CAAC,UAAU,CAAC;IACzF,iGAAiG;IACjG,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IACrC,yFAAyF;IACzF,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-query-options.js","sourceRoot":"","sources":["../../src/pagination/page-query-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PageRequest } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { type Schema } from '@ddd-ts-kit/validation';
|
|
3
|
+
import type { PageQueryOptions } from './page-query-options.js';
|
|
4
|
+
/** The same reading as a `Schema`, for a route whose whole query is the page: `request: { query }`. */
|
|
5
|
+
export declare function pageQuerySchema<Field extends string = never>(options?: PageQueryOptions<Field>): Schema<PageRequest<Field>>;
|
|
6
|
+
//# sourceMappingURL=page-query-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-query-schema.d.ts","sourceRoot":"","sources":["../../src/pagination/page-query-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,EAC1D,OAAO,GAAE,gBAAgB,CAAC,KAAK,CAAM,GACpC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAE5B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { customSchema } from '@ddd-ts-kit/validation';
|
|
2
|
+
import { pageRequestParameters } from './page-request-parameters.js';
|
|
3
|
+
import { parsePageQuery } from './parse-page-query.js';
|
|
4
|
+
/** The same reading as a `Schema`, for a route whose whole query is the page: `request: { query }`. */
|
|
5
|
+
export function pageQuerySchema(options = {}) {
|
|
6
|
+
return customSchema((query) => parsePageQuery(query, options), pageRequestParameters(options));
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=page-query-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-query-schema.js","sourceRoot":"","sources":["../../src/pagination/page-query-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,uGAAuG;AACvG,MAAM,UAAU,eAAe,CAC7B,OAAO,GAA4B,EAAE;IAErC,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;AACjG,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PageRequest } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { PageQueryOptions } from './page-query-options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads `limit`, `offset`, `cursor` and `sort` (`placedAt,-total`: a leading `-` is
|
|
5
|
+
* descending) from a query, as strings or already coerced. Throws the `ValidationError` of the
|
|
6
|
+
* pipeline, so a wrong parameter is answered 422 with one issue per parameter.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pageRequestFrom<Field extends string = never>(query: unknown, options?: PageQueryOptions<Field>): PageRequest<Field>;
|
|
9
|
+
//# sourceMappingURL=page-request-from.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-request-from.d.ts","sourceRoot":"","sources":["../../src/pagination/page-request-from.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,EAC1D,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,gBAAgB,CAAC,KAAK,CAAM,GACpC,WAAW,CAAC,KAAK,CAAC,CAUpB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValidationError } from '@ddd-ts-kit/validation';
|
|
2
|
+
import { parsePageQuery } from './parse-page-query.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads `limit`, `offset`, `cursor` and `sort` (`placedAt,-total`: a leading `-` is
|
|
5
|
+
* descending) from a query, as strings or already coerced. Throws the `ValidationError` of the
|
|
6
|
+
* pipeline, so a wrong parameter is answered 422 with one issue per parameter.
|
|
7
|
+
*/
|
|
8
|
+
export function pageRequestFrom(query, options = {}) {
|
|
9
|
+
const parsed = parsePageQuery(query, options);
|
|
10
|
+
if (parsed.ok) {
|
|
11
|
+
return parsed.value;
|
|
12
|
+
}
|
|
13
|
+
const issues = parsed.error.map((issue) => ({ ...issue, path: `query.${issue.path}` }));
|
|
14
|
+
throw new ValidationError(issues, 'The request is not valid.');
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=page-request-from.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-request-from.js","sourceRoot":"","sources":["../../src/pagination/page-request-from.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,OAAO,GAA4B,EAAE;IAErC,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAE9C,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAExF,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsonSchema } from '@ddd-ts-kit/validation';
|
|
2
|
+
import type { PageQueryOptions } from './page-query-options.js';
|
|
3
|
+
/**
|
|
4
|
+
* The query parameters of a page as a JSON Schema object: one OpenAPI parameter per property
|
|
5
|
+
* once it is the `toJsonSchema()` of a query schema. Merge `properties` into a wider schema
|
|
6
|
+
* when the route has filters too.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pageRequestParameters(options?: PageQueryOptions<string>): JsonSchema;
|
|
9
|
+
//# sourceMappingURL=page-request-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-request-parameters.d.ts","sourceRoot":"","sources":["../../src/pagination/page-request-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,gBAAgB,CAAC,MAAM,CAAM,GAAG,UAAU,CAiBxF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { limitsOf } from './limits-of.js';
|
|
2
|
+
/**
|
|
3
|
+
* The query parameters of a page as a JSON Schema object: one OpenAPI parameter per property
|
|
4
|
+
* once it is the `toJsonSchema()` of a query schema. Merge `properties` into a wider schema
|
|
5
|
+
* when the route has filters too.
|
|
6
|
+
*/
|
|
7
|
+
export function pageRequestParameters(options = {}) {
|
|
8
|
+
const { defaultSize, maxSize } = limitsOf(options);
|
|
9
|
+
const sortable = options.sortable ?? [];
|
|
10
|
+
return {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
limit: { type: 'integer', minimum: 1, maximum: maxSize, default: defaultSize, description: 'Size of the page.' },
|
|
14
|
+
offset: { type: 'integer', minimum: 0, description: 'Items to skip. Not with `cursor`.' },
|
|
15
|
+
cursor: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
minLength: 1,
|
|
18
|
+
description: 'The `nextCursor` of the previous page. Not with `offset`.',
|
|
19
|
+
},
|
|
20
|
+
...(sortable.length === 0 ? {} : { sort: sortParameter(sortable) }),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function sortParameter(sortable) {
|
|
25
|
+
return {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: `Comma-separated fields, a leading "-" for descending. Sortable: ${sortable.join(', ')}.`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=page-request-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-request-parameters.js","sourceRoot":"","sources":["../../src/pagination/page-request-parameters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAO,GAA6B,EAAE;IAC1E,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IAExC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE;YAChH,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE;YACzF,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,CAAC;gBACZ,WAAW,EAAE,2DAA2D;aACzE;YACD,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;SACpE;KACF,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,QAA2B;IAChD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,mEAAmE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;KACvG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Page } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { PageBody } from './page-body.js';
|
|
3
|
+
/** The body of a search answer: the items through `map`, `total` and `nextCursor` when the page has them. */
|
|
4
|
+
export declare function pageResponse<T, U>(page: Page<T>, map: (item: T) => U): PageBody<U>;
|
|
5
|
+
//# sourceMappingURL=page-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-response.d.ts","sourceRoot":"","sources":["../../src/pagination/page-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,6GAA6G;AAC7G,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAMlF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The body of a search answer: the items through `map`, `total` and `nextCursor` when the page has them. */
|
|
2
|
+
export function pageResponse(page, map) {
|
|
3
|
+
return {
|
|
4
|
+
items: page.items.map(map),
|
|
5
|
+
...(page.total === undefined ? {} : { total: page.total }),
|
|
6
|
+
...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=page-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-response.js","sourceRoot":"","sources":["../../src/pagination/page-response.ts"],"names":[],"mappings":"AAGA,6GAA6G;AAC7G,MAAM,UAAU,YAAY,CAAO,IAAa,EAAE,GAAmB;IACnE,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;QAC1B,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1D,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Schema } from '@ddd-ts-kit/validation';
|
|
2
|
+
import type { PageBody } from './page-body.js';
|
|
3
|
+
/**
|
|
4
|
+
* The schema of a page of items, from the schema of one item: validates the envelope and each
|
|
5
|
+
* item, and describes both in the contract. Local `$defs` of the item schema move to the top,
|
|
6
|
+
* where the OpenAPI generator collects them.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pageSchemaOf<T>(item: Schema<T>): Schema<PageBody<T>>;
|
|
9
|
+
//# sourceMappingURL=page-schema-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-schema-of.d.ts","sourceRoot":"","sources":["../../src/pagination/page-schema-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,KAAK,MAAM,EAAwB,MAAM,wBAAwB,CAAC;AAG1G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEpE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { err, ok } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { customSchema } from '@ddd-ts-kit/validation';
|
|
3
|
+
import { isRecord } from '../support/is-record.js';
|
|
4
|
+
import { issue } from './issue.js';
|
|
5
|
+
/**
|
|
6
|
+
* The schema of a page of items, from the schema of one item: validates the envelope and each
|
|
7
|
+
* item, and describes both in the contract. Local `$defs` of the item schema move to the top,
|
|
8
|
+
* where the OpenAPI generator collects them.
|
|
9
|
+
*/
|
|
10
|
+
export function pageSchemaOf(item) {
|
|
11
|
+
return customSchema((input) => parsePageBody(input, item), pageJsonSchema(item.toJsonSchema()));
|
|
12
|
+
}
|
|
13
|
+
function parsePageBody(input, item) {
|
|
14
|
+
if (!isRecord(input) || !Array.isArray(input['items'])) {
|
|
15
|
+
return err([issue('items', 'invalid_page', 'A page has a list of items.')]);
|
|
16
|
+
}
|
|
17
|
+
const issues = [];
|
|
18
|
+
const items = itemsOf(input['items'], item, issues);
|
|
19
|
+
const more = moreOf(input, issues);
|
|
20
|
+
return issues.length > 0 ? err(issues) : ok({ items, ...more });
|
|
21
|
+
}
|
|
22
|
+
function itemsOf(inputs, item, issues) {
|
|
23
|
+
return inputs.flatMap((input, index) => {
|
|
24
|
+
const parsed = item.parse(input);
|
|
25
|
+
if (parsed.ok) {
|
|
26
|
+
return [parsed.value];
|
|
27
|
+
}
|
|
28
|
+
for (const found of parsed.error) {
|
|
29
|
+
const path = found.path === '' ? `items.${String(index)}` : `items.${String(index)}.${found.path}`;
|
|
30
|
+
issues.push({ ...found, path });
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function moreOf(input, issues) {
|
|
36
|
+
const { total, nextCursor } = input;
|
|
37
|
+
const counted = typeof total === 'number' && Number.isSafeInteger(total) && total >= 0;
|
|
38
|
+
if (total !== undefined && !counted) {
|
|
39
|
+
issues.push(issue('total', 'invalid_page', 'Must be a non-negative integer.'));
|
|
40
|
+
}
|
|
41
|
+
if (nextCursor !== undefined && typeof nextCursor !== 'string') {
|
|
42
|
+
issues.push(issue('nextCursor', 'invalid_page', 'Must be a string.'));
|
|
43
|
+
}
|
|
44
|
+
return { ...(counted ? { total } : {}), ...(typeof nextCursor === 'string' ? { nextCursor } : {}) };
|
|
45
|
+
}
|
|
46
|
+
function pageJsonSchema(itemSchema) {
|
|
47
|
+
const { $schema: _dialect, $defs, definitions, ...item } = itemSchema;
|
|
48
|
+
return {
|
|
49
|
+
type: 'object',
|
|
50
|
+
required: ['items'],
|
|
51
|
+
properties: {
|
|
52
|
+
items: { type: 'array', items: item },
|
|
53
|
+
total: { type: 'integer', minimum: 0, description: 'Present when it is cheap to count.' },
|
|
54
|
+
nextCursor: { type: 'string', description: 'Present when more items follow.' },
|
|
55
|
+
},
|
|
56
|
+
...($defs === undefined ? {} : { $defs }),
|
|
57
|
+
...(definitions === undefined ? {} : { definitions }),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=page-schema-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-schema-of.js","sourceRoot":"","sources":["../../src/pagination/page-schema-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAsD,MAAM,wBAAwB,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAI,IAAe;IAC7C,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;AAClG,CAAC;AAED,SAAS,aAAa,CAAI,KAAc,EAAE,IAAe;IACvD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAEnC,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,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ueryOptions } from './page-query-options.js';
|
|
4
|
+
export declare function parsePageQuery<Field extends string>(input: unknown, options: PageQueryOptions<Field>): Result<PageRequest<Field>, ValidationIssue[]>;
|
|
5
|
+
//# sourceMappingURL=parse-page-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-page-query.d.ts","sourceRoot":"","sources":["../../src/pagination/parse-page-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAgBhE,wBAAgB,cAAc,CAAC,KAAK,SAAS,MAAM,EACjD,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC/B,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC,CAoB/C"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { cursorPage, err, offsetPage, ok, } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { isRecord } from '../support/is-record.js';
|
|
3
|
+
import { issue } from './issue.js';
|
|
4
|
+
import { limitsOf } from './limits-of.js';
|
|
5
|
+
export function parsePageQuery(input, options) {
|
|
6
|
+
const reading = { query: isRecord(input) ? input : {}, issues: [] };
|
|
7
|
+
const limits = limitsOf(options);
|
|
8
|
+
const asked = {
|
|
9
|
+
limit: limitOf(reading, limits),
|
|
10
|
+
offset: offsetOf(reading),
|
|
11
|
+
cursor: cursorOf(reading),
|
|
12
|
+
sort: sortOf(reading, options.sortable ?? []),
|
|
13
|
+
};
|
|
14
|
+
if (asked.offset !== undefined && asked.cursor !== undefined) {
|
|
15
|
+
reading.issues.push(issue('cursor', 'offset_with_cursor', 'A page is asked by offset or by cursor, not both.'));
|
|
16
|
+
}
|
|
17
|
+
if (reading.issues.length > 0) {
|
|
18
|
+
return err(reading.issues);
|
|
19
|
+
}
|
|
20
|
+
return ok(options.kind === 'cursor' ? cursorFirst(asked, limits) : offsetFirst(asked, limits));
|
|
21
|
+
}
|
|
22
|
+
function limitOf({ query, issues }, limits) {
|
|
23
|
+
if (query['limit'] === undefined) {
|
|
24
|
+
return limits.defaultSize;
|
|
25
|
+
}
|
|
26
|
+
const limit = integerOf(query['limit']);
|
|
27
|
+
if (limit !== undefined && limit >= 1 && limit <= limits.maxSize) {
|
|
28
|
+
return limit;
|
|
29
|
+
}
|
|
30
|
+
issues.push(issue('limit', 'invalid_limit', `Must be an integer between 1 and ${String(limits.maxSize)}.`));
|
|
31
|
+
return limits.defaultSize;
|
|
32
|
+
}
|
|
33
|
+
function integerOf(value) {
|
|
34
|
+
const text = typeof value === 'number' ? String(value) : value;
|
|
35
|
+
if (typeof text !== 'string' || !/^\d{1,15}$/.test(text)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return Number(text);
|
|
39
|
+
}
|
|
40
|
+
function offsetOf({ query, issues }) {
|
|
41
|
+
if (query['offset'] === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const offset = integerOf(query['offset']);
|
|
45
|
+
if (offset !== undefined && offset >= 0) {
|
|
46
|
+
return offset;
|
|
47
|
+
}
|
|
48
|
+
issues.push(issue('offset', 'invalid_offset', 'Must be a non-negative integer.'));
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
function cursorOf({ query, issues }) {
|
|
52
|
+
const cursor = query['cursor'];
|
|
53
|
+
if (cursor === undefined) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (typeof cursor === 'string' && cursor !== '') {
|
|
57
|
+
return cursor;
|
|
58
|
+
}
|
|
59
|
+
issues.push(issue('cursor', 'invalid_cursor', 'Must be the nextCursor of a previous page.'));
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
function sortOf({ query, issues }, sortable) {
|
|
63
|
+
const terms = sortTermsOf(query['sort']);
|
|
64
|
+
if (terms === undefined) {
|
|
65
|
+
issues.push(issue('sort', 'invalid_sort', 'Must be a comma-separated list of fields.'));
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
return terms.flatMap((term) => {
|
|
69
|
+
const descending = term.startsWith('-');
|
|
70
|
+
const field = sortable.find((allowed) => allowed === (descending ? term.slice(1) : term));
|
|
71
|
+
if (field !== undefined) {
|
|
72
|
+
return [{ field, direction: descending ? 'desc' : 'asc' }];
|
|
73
|
+
}
|
|
74
|
+
issues.push(issue('sort', 'unsortable_field', `Sortable fields: ${sortable.join(', ') || 'none'}.`));
|
|
75
|
+
return [];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** `sort=a,-b` and a repeated `sort=a&sort=-b` read the same. `undefined` for anything else. */
|
|
79
|
+
function sortTermsOf(sort) {
|
|
80
|
+
if (sort === undefined) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const values = Array.isArray(sort) ? sort : [sort];
|
|
84
|
+
if (!values.every((value) => typeof value === 'string')) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return values
|
|
88
|
+
.flatMap((value) => value.split(','))
|
|
89
|
+
.map((term) => term.trim())
|
|
90
|
+
.filter((term) => term !== '');
|
|
91
|
+
}
|
|
92
|
+
/** A cursor page unless the query names an offset. */
|
|
93
|
+
function cursorFirst(asked, limits) {
|
|
94
|
+
const { limit, sort, offset, cursor } = asked;
|
|
95
|
+
if (offset !== undefined) {
|
|
96
|
+
return offsetPage({ limit, sort, offset }, limits);
|
|
97
|
+
}
|
|
98
|
+
return cursorPage({ limit, sort, ...(cursor === undefined ? {} : { cursor }) }, limits);
|
|
99
|
+
}
|
|
100
|
+
/** An offset page unless the query names a cursor. */
|
|
101
|
+
function offsetFirst(asked, limits) {
|
|
102
|
+
const { limit, sort, offset, cursor } = asked;
|
|
103
|
+
if (cursor !== undefined) {
|
|
104
|
+
return cursorPage({ limit, sort, cursor }, limits);
|
|
105
|
+
}
|
|
106
|
+
return offsetPage({ limit, sort, ...(offset === undefined ? {} : { offset }) }, limits);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=parse-page-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-page-query.js","sourceRoot":"","sources":["../../src/pagination/parse-page-query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,GAAG,EACH,UAAU,EACV,EAAE,GAKH,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAiB1C,MAAM,UAAU,cAAc,CAC5B,KAAc,EACd,OAAgC;IAEhC,MAAM,OAAO,GAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC7E,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAEjC,MAAM,KAAK,GAAiB;QAC1B,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;QAC/B,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;QACzB,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;KAC9C,CAAC;IAEF,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC7D,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,oBAAoB,EAAE,mDA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],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,GAAG,IAAI,CAyBxF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ResponseContractError } from '../error/response-contract-error.js';
|
|
2
|
+
export function assertDeclaredResponse(route, { status, body }) {
|
|
3
|
+
const declared = route.responses[status];
|
|
4
|
+
if (declared === undefined) {
|
|
5
|
+
throw new ResponseContractError(`Route "${route.operationId}" answered ${status}, which it does not declare.`);
|
|
6
|
+
}
|
|
7
|
+
if (declared.body === undefined) {
|
|
8
|
+
if (body !== undefined) {
|
|
9
|
+
throw new ResponseContractError(`Route "${route.operationId}" answered ${status} with a body, but declares none.`);
|
|
10
|
+
}
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const result = declared.body.parse(body);
|
|
14
|
+
if (!result.ok) {
|
|
15
|
+
throw new ResponseContractError(`Route "${route.operationId}" answered ${status} with a body that does not match its schema.`, result.error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=assert-declared-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-declared-response.js","sourceRoot":"","sources":["../../src/pipeline/assert-declared-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAI5E,MAAM,UAAU,sBAAsB,CAAC,KAAY,EAAE,EAAE,MAAM,EAAE,IAAI,EAAe;IAChF,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAEzC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,qBAAqB,CAAC,UAAU,KAAK,CAAC,WAAW,cAAc,MAAM,8BAA8B,CAAC,CAAC;IACjH,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAChC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,qBAAqB,CAC7B,UAAU,KAAK,CAAC,WAAW,cAAc,MAAM,kCAAkC,CAClF,CAAC;QACJ,CAAC;QAED,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,qBAAqB,CAC7B,UAAU,KAAK,CAAC,WAAW,cAAc,MAAM,8CAA8C,EAC7F,MAAM,CAAC,KAAK,CACb,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation-header.d.ts","sourceRoot":"","sources":["../../src/pipeline/correlation-header.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation-header.js","sourceRoot":"","sources":["../../src/pipeline/correlation-header.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RawHeaders } from '../route/raw-headers.js';
|
|
2
|
+
/** The incoming `x-correlation-id` when it is well formed; otherwise the request starts the chain. */
|
|
3
|
+
export declare function correlationIdOf(headers: Readonly<RawHeaders>, requestId: string): string;
|
|
4
|
+
//# sourceMappingURL=correlation-id-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation-id-of.d.ts","sourceRoot":"","sources":["../../src/pipeline/correlation-id-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAExF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CORRELATION_HEADER } from './correlation-header.js';
|
|
2
|
+
import { wellFormedIdentifier } from './well-formed-identifier.js';
|
|
3
|
+
/** The incoming `x-correlation-id` when it is well formed; otherwise the request starts the chain. */
|
|
4
|
+
export function correlationIdOf(headers, requestId) {
|
|
5
|
+
return wellFormedIdentifier(headers[CORRELATION_HEADER]) ?? requestId;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=correlation-id-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation-id-of.js","sourceRoot":"","sources":["../../src/pipeline/correlation-id-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,sGAAsG;AACtG,MAAM,UAAU,eAAe,CAAC,OAA6B,EAAE,SAAiB;IAC9E,OAAO,oBAAoB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,SAAS,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ExecutionContext } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { Problem } from '../error/problem.js';
|
|
3
|
+
import type { HttpMethod } from '../route/http-method.js';
|
|
4
|
+
export interface ErrorContext {
|
|
5
|
+
readonly requestId: string;
|
|
6
|
+
readonly correlationId: string;
|
|
7
|
+
readonly operationId: string;
|
|
8
|
+
readonly method: HttpMethod;
|
|
9
|
+
readonly path: string;
|
|
10
|
+
/** The response the client receives for this error. */
|
|
11
|
+
readonly problem: Problem;
|
|
12
|
+
/** The execution context of the request, when the failure happened after it was built: not for a refused credential or an invalid request. */
|
|
13
|
+
readonly execution?: ExecutionContext;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=error-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-context.d.ts","sourceRoot":"","sources":["../../src/pipeline/error-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,8IAA8I;IAC9I,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-context.js","sourceRoot":"","sources":["../../src/pipeline/error-context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Clock, ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { ErrorMapper } from '../error/error-mapper.js';
|
|
3
|
+
import type { ErrorContext } from './error-context.js';
|
|
4
|
+
import type { RawRequest } from './raw-request.js';
|
|
5
|
+
import type { RouteAround } from './route-around.js';
|
|
6
|
+
export interface ExecuteOptions {
|
|
7
|
+
readonly errorMapper?: ErrorMapper;
|
|
8
|
+
/** Authenticates the request; throw `UnauthorizedError` to refuse it. */
|
|
9
|
+
readonly resolvePrincipal?: (raw: unknown) => unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Runs every handler inside a scope that knows the principal, typically an ambient actor
|
|
12
|
+
* context, so that no route can forget to open it.
|
|
13
|
+
*/
|
|
14
|
+
readonly withPrincipal?: <T>(principal: unknown, work: () => Promise<T>) => Promise<T>;
|
|
15
|
+
/** Called for every error answered as a problem, expected or not. Meant for logging. */
|
|
16
|
+
readonly onError?: (error: unknown, context: ErrorContext) => void;
|
|
17
|
+
/** Checks each response against the route declaration. Meant for tests. */
|
|
18
|
+
readonly validateResponses?: boolean;
|
|
19
|
+
/** Defaults to the incoming `x-request-id` header when it is well formed, else a UUID. */
|
|
20
|
+
readonly requestId?: (request: RawRequest) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Runs every handler inside `scope.run(execution, ...)`, so loggers, audit columns and tenant
|
|
23
|
+
* scoping read the execution context of the request. Opened outside of `withPrincipal`.
|
|
24
|
+
*/
|
|
25
|
+
readonly executionScope?: ExecutionScope;
|
|
26
|
+
/**
|
|
27
|
+
* Gives every request a `deadline` in its execution context, this many milliseconds after it
|
|
28
|
+
* arrived. The pipeline does not interrupt a handler: what honours the deadline reads it.
|
|
29
|
+
*/
|
|
30
|
+
readonly requestTimeoutMs?: number;
|
|
31
|
+
/** The instant a request arrived at, for `requestTimeoutMs`. Defaults to the system clock. */
|
|
32
|
+
readonly clock?: Clock;
|
|
33
|
+
/**
|
|
34
|
+
* Wraps the whole handling of each request, from authentication to the answer, refusals
|
|
35
|
+
* included. This is where a tracer names the request after its route: `tracedRoutes()` of
|
|
36
|
+
* `@ddd-ts-kit/tracing` fits as it is.
|
|
37
|
+
*/
|
|
38
|
+
readonly around?: RouteAround;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=execute-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-options.d.ts","sourceRoot":"","sources":["../../src/pipeline/execute-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EA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line/execute-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Route } from '../route/route.js';
|
|
2
|
+
import type { ExecuteOptions } from './execute-options.js';
|
|
3
|
+
import type { RawRequest } from './raw-request.js';
|
|
4
|
+
import type { RouteResponse } from './route-response.js';
|
|
5
|
+
export declare function executeRoute(route: Route, request: RawRequest, options?: ExecuteOptions): Promise<RouteResponse>;
|
|
6
|
+
//# sourceMappingURL=execute-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-route.d.ts","sourceRoot":"","sources":["../../src/pipeline/execute-route.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAkBzD,wBAAsB,YAAY,CAChC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,UAAU,EACnB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAOxB"}
|