@craft-ts/core 0.7.0-beta.13 → 0.7.0-beta.15
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/package.json +10 -2
- package/src/index.d.ts +156 -148
- package/src/index.js +153 -142
- package/src/lib/after-recomputation.d.ts +3 -4
- package/src/lib/after-recomputation.js +3 -4
- package/src/lib/app-checked-di.d.ts +3 -4
- package/src/lib/app-checked-di.js +0 -1
- package/src/lib/async-process.d.ts +18 -19
- package/src/lib/async-process.js +24 -25
- package/src/lib/branded-component/branded-component.d.ts +3 -4
- package/src/lib/branded-component/branded-component.js +0 -1
- package/src/lib/browser-boundaries.d.ts +6 -7
- package/src/lib/browser-boundaries.js +5 -6
- package/src/lib/client-di-requirement.d.ts +1 -2
- package/src/lib/client-di-requirement.js +0 -1
- package/src/lib/client-function-middleware.d.ts +8 -92
- package/src/lib/client-function-middleware.js +89 -90
- package/src/lib/component-monitoring.d.ts +1 -2
- package/src/lib/component-monitoring.js +2 -3
- package/src/lib/component-register.d.ts +1 -2
- package/src/lib/component-register.js +1 -2
- package/src/lib/computed-source.d.ts +3 -4
- package/src/lib/computed-source.js +2 -3
- package/src/lib/correlation-id-plugin.d.ts +1 -2
- package/src/lib/correlation-id-plugin.js +6 -7
- package/src/lib/correlation-id.d.ts +4 -5
- package/src/lib/correlation-id.js +3 -4
- package/src/lib/craft-a11y.d.ts +3 -4
- package/src/lib/craft-a11y.js +5 -6
- package/src/lib/craft-activated-route.d.ts +2 -3
- package/src/lib/craft-activated-route.js +2 -3
- package/src/lib/craft-app-config.d.ts +4 -5
- package/src/lib/craft-app-config.js +3 -4
- package/src/lib/craft-codec.d.ts +0 -1
- package/src/lib/craft-codec.js +0 -1
- package/src/lib/craft-computed.d.ts +6 -7
- package/src/lib/craft-computed.js +7 -8
- package/src/lib/craft-control-flow.d.ts +0 -1
- package/src/lib/craft-control-flow.js +2 -3
- package/src/lib/craft-effect.d.ts +2 -3
- package/src/lib/craft-effect.js +7 -8
- package/src/lib/craft-exception.d.ts +0 -1
- package/src/lib/craft-exception.js +0 -1
- package/src/lib/craft-gen.d.ts +1 -2
- package/src/lib/craft-gen.js +2 -3
- package/src/lib/craft-generator-runtime.d.ts +21 -5
- package/src/lib/craft-generator-runtime.js +28 -6
- package/src/lib/craft-guard-runtime.d.ts +4 -5
- package/src/lib/craft-guard-runtime.js +6 -7
- package/src/lib/craft-handshake.d.ts +1 -2
- package/src/lib/craft-handshake.js +0 -1
- package/src/lib/craft-http-client.d.ts +3 -4
- package/src/lib/craft-http-client.js +4 -5
- package/src/lib/craft-http-trace.d.ts +1 -2
- package/src/lib/craft-http-trace.js +5 -2
- package/src/lib/craft-hydration.d.ts +11 -0
- package/src/lib/craft-hydration.js +2 -0
- package/src/lib/craft-lazy.d.ts +3 -4
- package/src/lib/craft-lazy.js +5 -6
- package/src/lib/craft-load-retry.d.ts +2 -3
- package/src/lib/craft-load-retry.js +11 -4
- package/src/lib/craft-machine-history.d.ts +6 -7
- package/src/lib/craft-machine-history.js +6 -7
- package/src/lib/craft-match.d.ts +0 -1
- package/src/lib/craft-match.js +0 -1
- package/src/lib/craft-method.d.ts +3 -4
- package/src/lib/craft-method.js +5 -6
- package/src/lib/craft-node-directive.d.ts +3 -4
- package/src/lib/craft-node-directive.js +2 -3
- package/src/lib/craft-pending.d.ts +3 -4
- package/src/lib/craft-pending.js +2 -3
- package/src/lib/craft-pipe.d.ts +1 -2
- package/src/lib/craft-pipe.js +7 -8
- package/src/lib/craft-platform.d.ts +2 -3
- package/src/lib/craft-platform.js +2 -3
- package/src/lib/craft-primitive-gen.d.ts +7 -8
- package/src/lib/craft-primitive-gen.js +4 -5
- package/src/lib/craft-primitive-registry.d.ts +4 -2
- package/src/lib/craft-primitive-registry.js +5 -3
- package/src/lib/craft-program-operators.d.ts +3 -4
- package/src/lib/craft-program-operators.js +4 -5
- package/src/lib/craft-program-runtime.d.ts +3 -4
- package/src/lib/craft-program-runtime.js +7 -8
- package/src/lib/craft-register-for-runtime.d.ts +2 -3
- package/src/lib/craft-register-for-runtime.js +2 -3
- package/src/lib/craft-register-for.d.ts +3 -4
- package/src/lib/craft-register-for.js +6 -7
- package/src/lib/craft-render-identity.d.ts +0 -1
- package/src/lib/craft-render-identity.js +1 -2
- package/src/lib/craft-replay.d.ts +0 -1
- package/src/lib/craft-replay.js +0 -1
- package/src/lib/craft-request-context.d.ts +15 -0
- package/src/lib/craft-request-context.js +40 -0
- package/src/lib/craft-resolve.d.ts +2 -3
- package/src/lib/craft-resolve.js +0 -1
- package/src/lib/craft-resource.d.ts +2 -3
- package/src/lib/craft-resource.js +14 -6
- package/src/lib/craft-route-exceptions.d.ts +27 -28
- package/src/lib/craft-route-exceptions.js +3 -4
- package/src/lib/craft-route-load-error.d.ts +92 -93
- package/src/lib/craft-route-load-error.js +6 -7
- package/src/lib/craft-route-meta.d.ts +4 -5
- package/src/lib/craft-route-meta.js +0 -1
- package/src/lib/craft-route-target.d.ts +1 -2
- package/src/lib/craft-route-target.js +1 -2
- package/src/lib/craft-router-outlet.d.ts +7 -7
- package/src/lib/craft-router-outlet.js +24 -18
- package/src/lib/craft-router-tokens.d.ts +3 -4
- package/src/lib/craft-router-tokens.js +2 -3
- package/src/lib/craft-router-trace.d.ts +3 -4
- package/src/lib/craft-router-trace.js +9 -3
- package/src/lib/craft-router.d.ts +16 -17
- package/src/lib/craft-router.js +75 -74
- package/src/lib/craft-routes.d.ts +20 -15
- package/src/lib/craft-routes.js +13 -12
- package/src/lib/craft-runtime-mode.d.ts +13 -0
- package/src/lib/craft-runtime-mode.js +21 -0
- package/src/lib/craft-security.d.ts +87 -0
- package/src/lib/craft-security.js +117 -0
- package/src/lib/craft-service.d.ts +12 -13
- package/src/lib/craft-service.js +11 -12
- package/src/lib/craft-service.shared.d.ts +0 -1
- package/src/lib/craft-service.shared.js +0 -1
- package/src/lib/craft-settled.d.ts +23 -16
- package/src/lib/craft-settled.js +9 -10
- package/src/lib/craft-ssr.d.ts +2 -3
- package/src/lib/craft-ssr.js +4 -5
- package/src/lib/craft-state-machine-runtime.d.ts +2 -3
- package/src/lib/craft-state-machine-runtime.js +3 -4
- package/src/lib/craft-state-machine.d.ts +5 -6
- package/src/lib/craft-state-machine.js +9 -10
- package/src/lib/craft-target-runtime.d.ts +1 -2
- package/src/lib/craft-target-runtime.js +2 -3
- package/src/lib/craft-transfer-snapshot.d.ts +10 -5
- package/src/lib/craft-transfer-snapshot.js +139 -14
- package/src/lib/craft-unique.d.ts +0 -1
- package/src/lib/craft-unique.js +0 -1
- package/src/lib/craft-until-settled.d.ts +5 -6
- package/src/lib/craft-until-settled.js +4 -5
- package/src/lib/craft-use.d.ts +0 -1
- package/src/lib/craft-use.js +2 -3
- package/src/lib/craft-view-transition.d.ts +2 -3
- package/src/lib/craft-view-transition.js +2 -3
- package/src/lib/dev-tools.d.ts +7 -0
- package/src/lib/dev-tools.js +244 -0
- package/src/lib/dom-event-hook.d.ts +1 -2
- package/src/lib/dom-event-hook.js +1 -2
- package/src/lib/fn-wrapper.d.ts +2 -3
- package/src/lib/fn-wrapper.js +3 -4
- package/src/lib/form/craft-field.d.ts +2 -3
- package/src/lib/form/craft-field.directive.d.ts +6 -7
- package/src/lib/form/craft-field.directive.js +5 -6
- package/src/lib/form/craft-field.js +1 -2
- package/src/lib/form/field-exception.d.ts +4 -5
- package/src/lib/form/field-exception.js +1 -2
- package/src/lib/form/field-lens.d.ts +0 -1
- package/src/lib/form/field-lens.js +0 -1
- package/src/lib/form/insert-form-attributes.d.ts +6 -7
- package/src/lib/form/insert-form-attributes.js +5 -6
- package/src/lib/form/insert-form-internals.d.ts +11 -12
- package/src/lib/form/insert-form-internals.js +9 -10
- package/src/lib/form/insert-form-schema.d.ts +3 -4
- package/src/lib/form/insert-form-schema.js +4 -5
- package/src/lib/form/insert-form-submit.d.ts +7 -8
- package/src/lib/form/insert-form-submit.js +3 -4
- package/src/lib/form/insert-form.d.ts +6 -7
- package/src/lib/form/insert-form.js +8 -9
- package/src/lib/form/insert-select-form-tree.d.ts +2 -3
- package/src/lib/form/insert-select-form-tree.js +5 -6
- package/src/lib/form/insert-sub-form-field.d.ts +3 -4
- package/src/lib/form/insert-sub-form-field.js +6 -7
- package/src/lib/form/make-form-tree-insert.d.ts +1 -2
- package/src/lib/form/make-form-tree-insert.js +3 -4
- package/src/lib/form/target-form-field.d.ts +0 -1
- package/src/lib/form/target-form-field.js +0 -1
- package/src/lib/form/validator.d.ts +5 -6
- package/src/lib/form/validator.js +3 -4
- package/src/lib/from-event-to-source$.d.ts +2 -3
- package/src/lib/from-event-to-source$.js +3 -4
- package/src/lib/global-persister-handler.service.d.ts +1 -2
- package/src/lib/global-persister-handler.service.js +2 -3
- package/src/lib/host/craft-compat.d.ts +2 -3
- package/src/lib/host/craft-compat.js +2 -3
- package/src/lib/host/craft-dom.d.ts +0 -1
- package/src/lib/host/craft-dom.js +0 -1
- package/src/lib/host/craft-http.d.ts +0 -1
- package/src/lib/host/craft-http.js +0 -1
- package/src/lib/host/craft-injector-host.d.ts +2 -3
- package/src/lib/host/craft-injector-host.js +1 -2
- package/src/lib/host/craft-injector.d.ts +0 -1
- package/src/lib/host/craft-injector.js +0 -1
- package/src/lib/host/craft-linked-signal.d.ts +1 -2
- package/src/lib/host/craft-linked-signal.js +2 -3
- package/src/lib/host/craft-router-runtime.d.ts +0 -1
- package/src/lib/host/craft-router-runtime.js +0 -1
- package/src/lib/host/craft-router-types.d.ts +1 -2
- package/src/lib/host/craft-router-types.js +1 -2
- package/src/lib/host/craft-signal.d.ts +0 -1
- package/src/lib/host/craft-signal.js +1 -2
- package/src/lib/host/craft-test-bed.d.ts +2 -3
- package/src/lib/host/craft-test-bed.js +2 -3
- package/src/lib/host-tag.d.ts +1 -2
- package/src/lib/host-tag.js +1 -2
- package/src/lib/http-server.d.ts +156 -0
- package/src/lib/http-server.js +590 -0
- package/src/lib/insert-entities.d.ts +5 -6
- package/src/lib/insert-entities.js +1 -2
- package/src/lib/insert-noop-typing-anchor.d.ts +1 -2
- package/src/lib/insert-noop-typing-anchor.js +0 -1
- package/src/lib/insert-pagination-placeholder-data.d.ts +5 -6
- package/src/lib/insert-pagination-placeholder-data.js +5 -6
- package/src/lib/insert-react-on-mutation.d.ts +5 -6
- package/src/lib/insert-react-on-mutation.js +2 -3
- package/src/lib/insert-select-resource.d.ts +2 -3
- package/src/lib/insert-select-resource.js +1 -2
- package/src/lib/insert-select.d.ts +5 -6
- package/src/lib/insert-select.js +18 -19
- package/src/lib/insert-storage-persister.d.ts +4 -5
- package/src/lib/insert-storage-persister.js +2 -3
- package/src/lib/insert-typed-pipes.d.ts +3 -4
- package/src/lib/insert-typed-pipes.js +2 -3
- package/src/lib/lambda-adapter.d.ts +52 -0
- package/src/lib/lambda-adapter.js +101 -0
- package/src/lib/linked-source.d.ts +3 -4
- package/src/lib/linked-source.js +2 -3
- package/src/lib/local-storage-persister.d.ts +2 -3
- package/src/lib/local-storage-persister.js +3 -4
- package/src/lib/middleware-schema-shared.d.ts +9 -21
- package/src/lib/middleware-schema-shared.js +6 -1
- package/src/lib/mock-http-request-for-route.d.ts +3 -4
- package/src/lib/mock-http-request-for-route.js +0 -1
- package/src/lib/mutation.d.ts +18 -19
- package/src/lib/mutation.js +23 -24
- package/src/lib/on$.d.ts +6 -7
- package/src/lib/on$.js +4 -5
- package/src/lib/portable-server-function.d.ts +8 -9
- package/src/lib/portable-server-function.js +12 -5
- package/src/lib/preserved-resource.d.ts +2 -3
- package/src/lib/preserved-resource.js +4 -5
- package/src/lib/primitive-method-runtime-context.d.ts +1 -2
- package/src/lib/primitive-method-runtime-context.js +2 -3
- package/src/lib/primitive-resource-runtime-context.d.ts +1 -2
- package/src/lib/primitive-resource-runtime-context.js +2 -3
- package/src/lib/query-params.d.ts +12 -13
- package/src/lib/query-params.js +15 -16
- package/src/lib/query.core.d.ts +15 -14
- package/src/lib/query.core.js +1 -2
- package/src/lib/query.d.ts +19 -20
- package/src/lib/query.js +23 -24
- package/src/lib/reactive-read.d.ts +2 -3
- package/src/lib/reactive-read.js +2 -3
- package/src/lib/render/channels.d.ts +130 -0
- package/src/lib/render/channels.js +0 -0
- package/src/lib/resource-by-id.d.ts +4 -5
- package/src/lib/resource-by-id.js +4 -5
- package/src/lib/resource-exception.d.ts +2 -3
- package/src/lib/resource-exception.js +1 -2
- package/src/lib/route-checked-di.d.ts +4 -5
- package/src/lib/route-checked-di.js +0 -1
- package/src/lib/schema-validation.d.ts +4 -5
- package/src/lib/schema-validation.js +2 -3
- package/src/lib/send-context-to-ai.d.ts +3 -4
- package/src/lib/send-context-to-ai.js +1 -2
- package/src/lib/send-context-to-ai.tokens.d.ts +1 -2
- package/src/lib/send-context-to-ai.tokens.js +0 -1
- package/src/lib/server-function-client.d.ts +18 -7
- package/src/lib/server-function-client.js +31 -9
- package/src/lib/server-function-contract.d.ts +1 -2
- package/src/lib/server-function-contract.js +0 -1
- package/src/lib/server-function-middleware.d.ts +49 -132
- package/src/lib/server-function-middleware.js +83 -103
- package/src/lib/server-function.d.ts +58 -8
- package/src/lib/server-function.js +20 -6
- package/src/lib/server-layer.d.ts +3 -4
- package/src/lib/server-layer.js +1 -2
- package/src/lib/server.d.ts +39 -6
- package/src/lib/server.js +259 -27
- package/src/lib/setup-craft-service-test.d.ts +3 -4
- package/src/lib/setup-craft-service-test.js +6 -7
- package/src/lib/setup-craft-service-testing-by-register.d.ts +4 -5
- package/src/lib/setup-craft-service-testing-by-register.js +4 -5
- package/src/lib/signal-proxy.d.ts +2 -3
- package/src/lib/signal-proxy.js +1 -2
- package/src/lib/signal-source.d.ts +3 -4
- package/src/lib/signal-source.js +7 -8
- package/src/lib/source$.d.ts +3 -4
- package/src/lib/source$.js +7 -8
- package/src/lib/source-from-event.d.ts +2 -3
- package/src/lib/source-from-event.js +2 -3
- package/src/lib/stacked-source.d.ts +1 -2
- package/src/lib/stacked-source.js +1 -2
- package/src/lib/standard-schema.d.ts +0 -1
- package/src/lib/standard-schema.js +0 -1
- package/src/lib/state-method-runtime-context.d.ts +2 -3
- package/src/lib/state-method-runtime-context.js +1 -2
- package/src/lib/state.d.ts +13 -14
- package/src/lib/state.js +17 -18
- package/src/lib/storage-persister.service.d.ts +3 -4
- package/src/lib/storage-persister.service.js +3 -4
- package/src/lib/take-app-snapshot.d.ts +1 -2
- package/src/lib/take-app-snapshot.js +10 -4
- package/src/lib/template-trace.d.ts +1 -2
- package/src/lib/template-trace.js +5 -2
- package/src/lib/temporal-runtime.d.ts +1 -2
- package/src/lib/temporal-runtime.js +1 -2
- package/src/lib/to-source.d.ts +3 -4
- package/src/lib/to-source.js +2 -3
- package/src/lib/util/craft-resource-ref.d.ts +2 -3
- package/src/lib/util/craft-resource-ref.js +0 -1
- package/src/lib/util/craft-resource-status.d.ts +1 -2
- package/src/lib/util/craft-resource-status.js +0 -1
- package/src/lib/util/entities-util.d.ts +0 -1
- package/src/lib/util/entities-util.js +0 -1
- package/src/lib/util/explicit-effect.d.ts +1 -2
- package/src/lib/util/explicit-effect.js +1 -2
- package/src/lib/util/extract-signal-props-and-methods.d.ts +2 -3
- package/src/lib/util/extract-signal-props-and-methods.js +0 -1
- package/src/lib/util/method-trigger-nonce.d.ts +1 -2
- package/src/lib/util/method-trigger-nonce.js +0 -1
- package/src/lib/util/persister.type.d.ts +2 -3
- package/src/lib/util/persister.type.js +0 -1
- package/src/lib/util/persister.util.d.ts +0 -1
- package/src/lib/util/persister.util.js +0 -1
- package/src/lib/util/react-on-mutation-effect.d.ts +5 -6
- package/src/lib/util/react-on-mutation-effect.js +4 -5
- package/src/lib/util/resource-by-id-changes-tracker.util.d.ts +2 -3
- package/src/lib/util/resource-by-id-changes-tracker.util.js +2 -3
- package/src/lib/util/source.type.d.ts +2 -3
- package/src/lib/util/source.type.js +0 -1
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.d.ts +1 -2
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.js +0 -1
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.d.ts +4 -5
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.js +0 -1
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.d.ts +3 -4
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.js +0 -1
- package/src/lib/util/types/brand.d.ts +0 -1
- package/src/lib/util/types/brand.js +0 -1
- package/src/lib/util/types/object-deep-path-mapper.type.d.ts +1 -2
- package/src/lib/util/types/object-deep-path-mapper.type.js +0 -1
- package/src/lib/util/types/resource-by-id-config.type.d.ts +3 -4
- package/src/lib/util/types/resource-by-id-config.type.js +0 -1
- package/src/lib/util/types/resource-with-params-or-params-fn.type.d.ts +2 -3
- package/src/lib/util/types/resource-with-params-or-params-fn.type.js +0 -1
- package/src/lib/util/types/shared.type.d.ts +6 -7
- package/src/lib/util/types/shared.type.js +0 -1
- package/src/lib/util/types/util.d.ts +2 -3
- package/src/lib/util/types/util.js +3 -3
- package/src/lib/util/types/util.type.d.ts +3 -4
- package/src/lib/util/types/util.type.js +0 -1
- package/src/lib/util/update-state.util.d.ts +0 -1
- package/src/lib/util/update-state.util.js +0 -1
- package/src/lib/util/util.d.ts +2 -3
- package/src/lib/util/util.js +1 -2
- package/src/lib/util/util.type.d.ts +5 -6
- package/src/lib/util/util.type.js +0 -1
- package/src/lib/worker-adapter.d.ts +8 -0
- package/src/lib/worker-adapter.js +8 -0
- package/src/lib/yieldable.d.ts +4 -5
- package/src/lib/yieldable.js +4 -5
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/lib/after-recomputation.d.ts.map +0 -1
- package/src/lib/after-recomputation.js.map +0 -1
- package/src/lib/app-checked-di.d.ts.map +0 -1
- package/src/lib/app-checked-di.js.map +0 -1
- package/src/lib/async-process.d.ts.map +0 -1
- package/src/lib/async-process.js.map +0 -1
- package/src/lib/branded-component/branded-component.d.ts.map +0 -1
- package/src/lib/branded-component/branded-component.js.map +0 -1
- package/src/lib/browser-boundaries.d.ts.map +0 -1
- package/src/lib/browser-boundaries.js.map +0 -1
- package/src/lib/client-di-requirement.d.ts.map +0 -1
- package/src/lib/client-di-requirement.js.map +0 -1
- package/src/lib/client-function-middleware.d.ts.map +0 -1
- package/src/lib/client-function-middleware.js.map +0 -1
- package/src/lib/component-monitoring.d.ts.map +0 -1
- package/src/lib/component-monitoring.js.map +0 -1
- package/src/lib/component-register.d.ts.map +0 -1
- package/src/lib/component-register.js.map +0 -1
- package/src/lib/computed-source.d.ts.map +0 -1
- package/src/lib/computed-source.js.map +0 -1
- package/src/lib/correlation-id-plugin.d.ts.map +0 -1
- package/src/lib/correlation-id-plugin.js.map +0 -1
- package/src/lib/correlation-id.d.ts.map +0 -1
- package/src/lib/correlation-id.js.map +0 -1
- package/src/lib/craft-a11y.d.ts.map +0 -1
- package/src/lib/craft-a11y.js.map +0 -1
- package/src/lib/craft-activated-route.d.ts.map +0 -1
- package/src/lib/craft-activated-route.js.map +0 -1
- package/src/lib/craft-app-config.d.ts.map +0 -1
- package/src/lib/craft-app-config.js.map +0 -1
- package/src/lib/craft-codec.d.ts.map +0 -1
- package/src/lib/craft-codec.js.map +0 -1
- package/src/lib/craft-computed.d.ts.map +0 -1
- package/src/lib/craft-computed.js.map +0 -1
- package/src/lib/craft-control-flow.d.ts.map +0 -1
- package/src/lib/craft-control-flow.js.map +0 -1
- package/src/lib/craft-effect.d.ts.map +0 -1
- package/src/lib/craft-effect.js.map +0 -1
- package/src/lib/craft-exception.d.ts.map +0 -1
- package/src/lib/craft-exception.js.map +0 -1
- package/src/lib/craft-gen.d.ts.map +0 -1
- package/src/lib/craft-gen.js.map +0 -1
- package/src/lib/craft-generator-runtime.d.ts.map +0 -1
- package/src/lib/craft-generator-runtime.js.map +0 -1
- package/src/lib/craft-guard-runtime.d.ts.map +0 -1
- package/src/lib/craft-guard-runtime.js.map +0 -1
- package/src/lib/craft-handshake.d.ts.map +0 -1
- package/src/lib/craft-handshake.js.map +0 -1
- package/src/lib/craft-http-client.d.ts.map +0 -1
- package/src/lib/craft-http-client.js.map +0 -1
- package/src/lib/craft-http-trace.d.ts.map +0 -1
- package/src/lib/craft-http-trace.js.map +0 -1
- package/src/lib/craft-lazy.d.ts.map +0 -1
- package/src/lib/craft-lazy.js.map +0 -1
- package/src/lib/craft-load-retry.d.ts.map +0 -1
- package/src/lib/craft-load-retry.js.map +0 -1
- package/src/lib/craft-machine-history.d.ts.map +0 -1
- package/src/lib/craft-machine-history.js.map +0 -1
- package/src/lib/craft-match.d.ts.map +0 -1
- package/src/lib/craft-match.js.map +0 -1
- package/src/lib/craft-method.d.ts.map +0 -1
- package/src/lib/craft-method.js.map +0 -1
- package/src/lib/craft-node-directive.d.ts.map +0 -1
- package/src/lib/craft-node-directive.js.map +0 -1
- package/src/lib/craft-pending.d.ts.map +0 -1
- package/src/lib/craft-pending.js.map +0 -1
- package/src/lib/craft-pipe.d.ts.map +0 -1
- package/src/lib/craft-pipe.js.map +0 -1
- package/src/lib/craft-platform.d.ts.map +0 -1
- package/src/lib/craft-platform.js.map +0 -1
- package/src/lib/craft-primitive-gen.d.ts.map +0 -1
- package/src/lib/craft-primitive-gen.js.map +0 -1
- package/src/lib/craft-primitive-registry.d.ts.map +0 -1
- package/src/lib/craft-primitive-registry.js.map +0 -1
- package/src/lib/craft-program-operators.d.ts.map +0 -1
- package/src/lib/craft-program-operators.js.map +0 -1
- package/src/lib/craft-program-runtime.d.ts.map +0 -1
- package/src/lib/craft-program-runtime.js.map +0 -1
- package/src/lib/craft-register-for-runtime.d.ts.map +0 -1
- package/src/lib/craft-register-for-runtime.js.map +0 -1
- package/src/lib/craft-register-for.d.ts.map +0 -1
- package/src/lib/craft-register-for.js.map +0 -1
- package/src/lib/craft-render-identity.d.ts.map +0 -1
- package/src/lib/craft-render-identity.js.map +0 -1
- package/src/lib/craft-replay.d.ts.map +0 -1
- package/src/lib/craft-replay.js.map +0 -1
- package/src/lib/craft-resolve.d.ts.map +0 -1
- package/src/lib/craft-resolve.js.map +0 -1
- package/src/lib/craft-resource.d.ts.map +0 -1
- package/src/lib/craft-resource.js.map +0 -1
- package/src/lib/craft-route-exceptions.d.ts.map +0 -1
- package/src/lib/craft-route-exceptions.js.map +0 -1
- package/src/lib/craft-route-load-error.d.ts.map +0 -1
- package/src/lib/craft-route-load-error.js.map +0 -1
- package/src/lib/craft-route-meta.d.ts.map +0 -1
- package/src/lib/craft-route-meta.js.map +0 -1
- package/src/lib/craft-route-target.d.ts.map +0 -1
- package/src/lib/craft-route-target.js.map +0 -1
- package/src/lib/craft-router-outlet.d.ts.map +0 -1
- package/src/lib/craft-router-outlet.js.map +0 -1
- package/src/lib/craft-router-tokens.d.ts.map +0 -1
- package/src/lib/craft-router-tokens.js.map +0 -1
- package/src/lib/craft-router-trace.d.ts.map +0 -1
- package/src/lib/craft-router-trace.js.map +0 -1
- package/src/lib/craft-router.d.ts.map +0 -1
- package/src/lib/craft-router.js.map +0 -1
- package/src/lib/craft-routes.d.ts.map +0 -1
- package/src/lib/craft-routes.js.map +0 -1
- package/src/lib/craft-service.d.ts.map +0 -1
- package/src/lib/craft-service.js.map +0 -1
- package/src/lib/craft-service.shared.d.ts.map +0 -1
- package/src/lib/craft-service.shared.js.map +0 -1
- package/src/lib/craft-settled.d.ts.map +0 -1
- package/src/lib/craft-settled.js.map +0 -1
- package/src/lib/craft-ssr.d.ts.map +0 -1
- package/src/lib/craft-ssr.js.map +0 -1
- package/src/lib/craft-state-machine-runtime.d.ts.map +0 -1
- package/src/lib/craft-state-machine-runtime.js.map +0 -1
- package/src/lib/craft-state-machine.d.ts.map +0 -1
- package/src/lib/craft-state-machine.js.map +0 -1
- package/src/lib/craft-target-runtime.d.ts.map +0 -1
- package/src/lib/craft-target-runtime.js.map +0 -1
- package/src/lib/craft-transfer-snapshot.d.ts.map +0 -1
- package/src/lib/craft-transfer-snapshot.js.map +0 -1
- package/src/lib/craft-unique.d.ts.map +0 -1
- package/src/lib/craft-unique.js.map +0 -1
- package/src/lib/craft-until-settled.d.ts.map +0 -1
- package/src/lib/craft-until-settled.js.map +0 -1
- package/src/lib/craft-use.d.ts.map +0 -1
- package/src/lib/craft-use.js.map +0 -1
- package/src/lib/craft-view-transition.d.ts.map +0 -1
- package/src/lib/craft-view-transition.js.map +0 -1
- package/src/lib/dom-event-hook.d.ts.map +0 -1
- package/src/lib/dom-event-hook.js.map +0 -1
- package/src/lib/fn-wrapper.d.ts.map +0 -1
- package/src/lib/fn-wrapper.js.map +0 -1
- package/src/lib/form/craft-field.d.ts.map +0 -1
- package/src/lib/form/craft-field.directive.d.ts.map +0 -1
- package/src/lib/form/craft-field.directive.js.map +0 -1
- package/src/lib/form/craft-field.js.map +0 -1
- package/src/lib/form/field-exception.d.ts.map +0 -1
- package/src/lib/form/field-exception.js.map +0 -1
- package/src/lib/form/field-lens.d.ts.map +0 -1
- package/src/lib/form/field-lens.js.map +0 -1
- package/src/lib/form/insert-form-attributes.d.ts.map +0 -1
- package/src/lib/form/insert-form-attributes.js.map +0 -1
- package/src/lib/form/insert-form-internals.d.ts.map +0 -1
- package/src/lib/form/insert-form-internals.js.map +0 -1
- package/src/lib/form/insert-form-schema.d.ts.map +0 -1
- package/src/lib/form/insert-form-schema.js.map +0 -1
- package/src/lib/form/insert-form-submit.d.ts.map +0 -1
- package/src/lib/form/insert-form-submit.js.map +0 -1
- package/src/lib/form/insert-form.d.ts.map +0 -1
- package/src/lib/form/insert-form.js.map +0 -1
- package/src/lib/form/insert-select-form-tree.d.ts.map +0 -1
- package/src/lib/form/insert-select-form-tree.js.map +0 -1
- package/src/lib/form/insert-sub-form-field.d.ts.map +0 -1
- package/src/lib/form/insert-sub-form-field.js.map +0 -1
- package/src/lib/form/make-form-tree-insert.d.ts.map +0 -1
- package/src/lib/form/make-form-tree-insert.js.map +0 -1
- package/src/lib/form/target-form-field.d.ts.map +0 -1
- package/src/lib/form/target-form-field.js.map +0 -1
- package/src/lib/form/validator.d.ts.map +0 -1
- package/src/lib/form/validator.js.map +0 -1
- package/src/lib/from-event-to-source$.d.ts.map +0 -1
- package/src/lib/from-event-to-source$.js.map +0 -1
- package/src/lib/global-persister-handler.service.d.ts.map +0 -1
- package/src/lib/global-persister-handler.service.js.map +0 -1
- package/src/lib/host/craft-compat.d.ts.map +0 -1
- package/src/lib/host/craft-compat.js.map +0 -1
- package/src/lib/host/craft-dom.d.ts.map +0 -1
- package/src/lib/host/craft-dom.js.map +0 -1
- package/src/lib/host/craft-http.d.ts.map +0 -1
- package/src/lib/host/craft-http.js.map +0 -1
- package/src/lib/host/craft-injector-host.d.ts.map +0 -1
- package/src/lib/host/craft-injector-host.js.map +0 -1
- package/src/lib/host/craft-injector.d.ts.map +0 -1
- package/src/lib/host/craft-injector.js.map +0 -1
- package/src/lib/host/craft-linked-signal.d.ts.map +0 -1
- package/src/lib/host/craft-linked-signal.js.map +0 -1
- package/src/lib/host/craft-router-runtime.d.ts.map +0 -1
- package/src/lib/host/craft-router-runtime.js.map +0 -1
- package/src/lib/host/craft-router-types.d.ts.map +0 -1
- package/src/lib/host/craft-router-types.js.map +0 -1
- package/src/lib/host/craft-signal.d.ts.map +0 -1
- package/src/lib/host/craft-signal.js.map +0 -1
- package/src/lib/host/craft-test-bed.d.ts.map +0 -1
- package/src/lib/host/craft-test-bed.js.map +0 -1
- package/src/lib/host-tag.d.ts.map +0 -1
- package/src/lib/host-tag.js.map +0 -1
- package/src/lib/insert-entities.d.ts.map +0 -1
- package/src/lib/insert-entities.js.map +0 -1
- package/src/lib/insert-noop-typing-anchor.d.ts.map +0 -1
- package/src/lib/insert-noop-typing-anchor.js.map +0 -1
- package/src/lib/insert-pagination-placeholder-data.d.ts.map +0 -1
- package/src/lib/insert-pagination-placeholder-data.js.map +0 -1
- package/src/lib/insert-react-on-mutation.d.ts.map +0 -1
- package/src/lib/insert-react-on-mutation.js.map +0 -1
- package/src/lib/insert-select-resource.d.ts.map +0 -1
- package/src/lib/insert-select-resource.js.map +0 -1
- package/src/lib/insert-select.d.ts.map +0 -1
- package/src/lib/insert-select.js.map +0 -1
- package/src/lib/insert-storage-persister.d.ts.map +0 -1
- package/src/lib/insert-storage-persister.js.map +0 -1
- package/src/lib/insert-typed-pipes.d.ts.map +0 -1
- package/src/lib/insert-typed-pipes.js.map +0 -1
- package/src/lib/linked-source.d.ts.map +0 -1
- package/src/lib/linked-source.js.map +0 -1
- package/src/lib/local-storage-persister.d.ts.map +0 -1
- package/src/lib/local-storage-persister.js.map +0 -1
- package/src/lib/middleware-schema-shared.d.ts.map +0 -1
- package/src/lib/middleware-schema-shared.js.map +0 -1
- package/src/lib/mock-http-request-for-route.d.ts.map +0 -1
- package/src/lib/mock-http-request-for-route.js.map +0 -1
- package/src/lib/mutation.d.ts.map +0 -1
- package/src/lib/mutation.js.map +0 -1
- package/src/lib/on$.d.ts.map +0 -1
- package/src/lib/on$.js.map +0 -1
- package/src/lib/portable-server-function.d.ts.map +0 -1
- package/src/lib/portable-server-function.js.map +0 -1
- package/src/lib/preserved-resource.d.ts.map +0 -1
- package/src/lib/preserved-resource.js.map +0 -1
- package/src/lib/primitive-method-runtime-context.d.ts.map +0 -1
- package/src/lib/primitive-method-runtime-context.js.map +0 -1
- package/src/lib/primitive-resource-runtime-context.d.ts.map +0 -1
- package/src/lib/primitive-resource-runtime-context.js.map +0 -1
- package/src/lib/query-params.d.ts.map +0 -1
- package/src/lib/query-params.js.map +0 -1
- package/src/lib/query.core.d.ts.map +0 -1
- package/src/lib/query.core.js.map +0 -1
- package/src/lib/query.d.ts.map +0 -1
- package/src/lib/query.js.map +0 -1
- package/src/lib/reactive-read.d.ts.map +0 -1
- package/src/lib/reactive-read.js.map +0 -1
- package/src/lib/resource-by-id.d.ts.map +0 -1
- package/src/lib/resource-by-id.js.map +0 -1
- package/src/lib/resource-exception.d.ts.map +0 -1
- package/src/lib/resource-exception.js.map +0 -1
- package/src/lib/route-checked-di.d.ts.map +0 -1
- package/src/lib/route-checked-di.js.map +0 -1
- package/src/lib/schema-validation.d.ts.map +0 -1
- package/src/lib/schema-validation.js.map +0 -1
- package/src/lib/send-context-to-ai.d.ts.map +0 -1
- package/src/lib/send-context-to-ai.js.map +0 -1
- package/src/lib/send-context-to-ai.tokens.d.ts.map +0 -1
- package/src/lib/send-context-to-ai.tokens.js.map +0 -1
- package/src/lib/server-function-client.d.ts.map +0 -1
- package/src/lib/server-function-client.js.map +0 -1
- package/src/lib/server-function-contract.d.ts.map +0 -1
- package/src/lib/server-function-contract.js.map +0 -1
- package/src/lib/server-function-middleware.d.ts.map +0 -1
- package/src/lib/server-function-middleware.js.map +0 -1
- package/src/lib/server-function.d.ts.map +0 -1
- package/src/lib/server-function.js.map +0 -1
- package/src/lib/server-layer.d.ts.map +0 -1
- package/src/lib/server-layer.js.map +0 -1
- package/src/lib/server.d.ts.map +0 -1
- package/src/lib/server.js.map +0 -1
- package/src/lib/setup-craft-service-test.d.ts.map +0 -1
- package/src/lib/setup-craft-service-test.js.map +0 -1
- package/src/lib/setup-craft-service-testing-by-register.d.ts.map +0 -1
- package/src/lib/setup-craft-service-testing-by-register.js.map +0 -1
- package/src/lib/signal-proxy.d.ts.map +0 -1
- package/src/lib/signal-proxy.js.map +0 -1
- package/src/lib/signal-source.d.ts.map +0 -1
- package/src/lib/signal-source.js.map +0 -1
- package/src/lib/source$.d.ts.map +0 -1
- package/src/lib/source$.js.map +0 -1
- package/src/lib/source-from-event.d.ts.map +0 -1
- package/src/lib/source-from-event.js.map +0 -1
- package/src/lib/stacked-source.d.ts.map +0 -1
- package/src/lib/stacked-source.js.map +0 -1
- package/src/lib/standard-schema.d.ts.map +0 -1
- package/src/lib/standard-schema.js.map +0 -1
- package/src/lib/state-method-runtime-context.d.ts.map +0 -1
- package/src/lib/state-method-runtime-context.js.map +0 -1
- package/src/lib/state.d.ts.map +0 -1
- package/src/lib/state.js.map +0 -1
- package/src/lib/storage-persister.service.d.ts.map +0 -1
- package/src/lib/storage-persister.service.js.map +0 -1
- package/src/lib/take-app-snapshot.d.ts.map +0 -1
- package/src/lib/take-app-snapshot.js.map +0 -1
- package/src/lib/template-trace.d.ts.map +0 -1
- package/src/lib/template-trace.js.map +0 -1
- package/src/lib/temporal-runtime.d.ts.map +0 -1
- package/src/lib/temporal-runtime.js.map +0 -1
- package/src/lib/to-source.d.ts.map +0 -1
- package/src/lib/to-source.js.map +0 -1
- package/src/lib/util/craft-resource-ref.d.ts.map +0 -1
- package/src/lib/util/craft-resource-ref.js.map +0 -1
- package/src/lib/util/craft-resource-status.d.ts.map +0 -1
- package/src/lib/util/craft-resource-status.js.map +0 -1
- package/src/lib/util/entities-util.d.ts.map +0 -1
- package/src/lib/util/entities-util.js.map +0 -1
- package/src/lib/util/explicit-effect.d.ts.map +0 -1
- package/src/lib/util/explicit-effect.js.map +0 -1
- package/src/lib/util/extract-signal-props-and-methods.d.ts.map +0 -1
- package/src/lib/util/extract-signal-props-and-methods.js.map +0 -1
- package/src/lib/util/method-trigger-nonce.d.ts.map +0 -1
- package/src/lib/util/method-trigger-nonce.js.map +0 -1
- package/src/lib/util/persister.type.d.ts.map +0 -1
- package/src/lib/util/persister.type.js.map +0 -1
- package/src/lib/util/persister.util.d.ts.map +0 -1
- package/src/lib/util/persister.util.js.map +0 -1
- package/src/lib/util/react-on-mutation-effect.d.ts.map +0 -1
- package/src/lib/util/react-on-mutation-effect.js.map +0 -1
- package/src/lib/util/resource-by-id-changes-tracker.util.d.ts.map +0 -1
- package/src/lib/util/resource-by-id-changes-tracker.util.js.map +0 -1
- package/src/lib/util/source.type.d.ts.map +0 -1
- package/src/lib/util/source.type.js.map +0 -1
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.d.ts.map +0 -1
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.js.map +0 -1
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.d.ts.map +0 -1
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.js.map +0 -1
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.d.ts.map +0 -1
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.js.map +0 -1
- package/src/lib/util/types/brand.d.ts.map +0 -1
- package/src/lib/util/types/brand.js.map +0 -1
- package/src/lib/util/types/object-deep-path-mapper.type.d.ts.map +0 -1
- package/src/lib/util/types/object-deep-path-mapper.type.js.map +0 -1
- package/src/lib/util/types/resource-by-id-config.type.d.ts.map +0 -1
- package/src/lib/util/types/resource-by-id-config.type.js.map +0 -1
- package/src/lib/util/types/resource-with-params-or-params-fn.type.d.ts.map +0 -1
- package/src/lib/util/types/resource-with-params-or-params-fn.type.js.map +0 -1
- package/src/lib/util/types/shared.type.d.ts.map +0 -1
- package/src/lib/util/types/shared.type.js.map +0 -1
- package/src/lib/util/types/util.d.ts.map +0 -1
- package/src/lib/util/types/util.js.map +0 -1
- package/src/lib/util/types/util.type.d.ts.map +0 -1
- package/src/lib/util/types/util.type.js.map +0 -1
- package/src/lib/util/update-state.util.d.ts.map +0 -1
- package/src/lib/util/update-state.util.js.map +0 -1
- package/src/lib/util/util.d.ts.map +0 -1
- package/src/lib/util/util.js.map +0 -1
- package/src/lib/util/util.type.d.ts.map +0 -1
- package/src/lib/util/util.type.js.map +0 -1
- package/src/lib/yieldable.d.ts.map +0 -1
- package/src/lib/yieldable.js.map +0 -1
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
export class HttpRequestError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
status;
|
|
4
|
+
constructor(code, status, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'HttpRequestError';
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.status = status;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const MUTATION_METHODS = new Set([
|
|
12
|
+
'POST',
|
|
13
|
+
'PUT',
|
|
14
|
+
'PATCH',
|
|
15
|
+
'DELETE',
|
|
16
|
+
]);
|
|
17
|
+
export function createHttpServer(options) {
|
|
18
|
+
const routes = options.routes ?? [];
|
|
19
|
+
const middleware = [
|
|
20
|
+
// L'ordre est une décision de sécurité : les gardes d'entrée (hôte,
|
|
21
|
+
// origine, taille) passent avant la résolution d'identité, qui coûte
|
|
22
|
+
// souvent une vérification cryptographique ou un aller-retour réseau.
|
|
23
|
+
createRequestGuardMiddleware(options),
|
|
24
|
+
createIdentityMiddleware(options),
|
|
25
|
+
...(options.middleware ?? []),
|
|
26
|
+
];
|
|
27
|
+
const routeHandler = options.handler ?? createRouteHandler(routes);
|
|
28
|
+
const metrics = options.metrics ?? createHttpMetrics();
|
|
29
|
+
const maxConcurrent = options.maxConcurrentRequests ?? 0;
|
|
30
|
+
let inFlight = 0;
|
|
31
|
+
return {
|
|
32
|
+
metrics,
|
|
33
|
+
async handle(request) {
|
|
34
|
+
const startedAt = Date.now();
|
|
35
|
+
if (maxConcurrent > 0 && inFlight >= maxConcurrent) {
|
|
36
|
+
metrics.record({
|
|
37
|
+
method: request.method,
|
|
38
|
+
path: new URL(request.url).pathname,
|
|
39
|
+
status: 503,
|
|
40
|
+
durationMs: 0,
|
|
41
|
+
});
|
|
42
|
+
return withResponseHeaders(jsonError(503, 'HTTP_OVERLOADED', 'Server is at capacity.'), { 'retry-after': '1' });
|
|
43
|
+
}
|
|
44
|
+
inFlight += 1;
|
|
45
|
+
const requestId = requestIdFrom(request);
|
|
46
|
+
const timeout = timeoutSignal(request.signal, options.timeoutMs ?? 15_000);
|
|
47
|
+
const signal = timeout.signal;
|
|
48
|
+
const logger = options.logger ?? createJsonLogger(requestId, options.loggerSink);
|
|
49
|
+
const context = {
|
|
50
|
+
request,
|
|
51
|
+
requestId,
|
|
52
|
+
signal,
|
|
53
|
+
cspNonce: createCspNonce(),
|
|
54
|
+
params: {},
|
|
55
|
+
logger,
|
|
56
|
+
};
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await withAbort(composeServerMiddleware(middleware, () => routeHandler(request, context))(request, context), signal);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
response = errorResponse(error);
|
|
63
|
+
logger.error('http.request.failed', {
|
|
64
|
+
method: request.method,
|
|
65
|
+
path: new URL(request.url).pathname,
|
|
66
|
+
durationMs: Date.now() - startedAt,
|
|
67
|
+
error: publicErrorMessage(error),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
inFlight -= 1;
|
|
71
|
+
timeout.dispose();
|
|
72
|
+
const responseWithHeaders = withResponseHeaders(response, {
|
|
73
|
+
'x-request-id': requestId,
|
|
74
|
+
});
|
|
75
|
+
logger.info('http.request.completed', {
|
|
76
|
+
method: request.method,
|
|
77
|
+
path: new URL(request.url).pathname,
|
|
78
|
+
status: response.status,
|
|
79
|
+
durationMs: Date.now() - startedAt,
|
|
80
|
+
});
|
|
81
|
+
metrics.record({
|
|
82
|
+
method: request.method,
|
|
83
|
+
path: new URL(request.url).pathname,
|
|
84
|
+
status: response.status,
|
|
85
|
+
durationMs: Date.now() - startedAt,
|
|
86
|
+
});
|
|
87
|
+
return responseWithHeaders;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function createHttpMetrics() {
|
|
92
|
+
let requests = 0;
|
|
93
|
+
let errors = 0;
|
|
94
|
+
let totalDurationMs = 0;
|
|
95
|
+
let maxDurationMs = 0;
|
|
96
|
+
const statusCounts = {};
|
|
97
|
+
return {
|
|
98
|
+
record(entry) {
|
|
99
|
+
requests += 1;
|
|
100
|
+
if (entry.status >= 400)
|
|
101
|
+
errors += 1;
|
|
102
|
+
totalDurationMs += entry.durationMs;
|
|
103
|
+
maxDurationMs = Math.max(maxDurationMs, entry.durationMs);
|
|
104
|
+
const status = String(entry.status);
|
|
105
|
+
statusCounts[status] = (statusCounts[status] ?? 0) + 1;
|
|
106
|
+
},
|
|
107
|
+
snapshot() {
|
|
108
|
+
return {
|
|
109
|
+
requests,
|
|
110
|
+
errors,
|
|
111
|
+
totalDurationMs,
|
|
112
|
+
maxDurationMs,
|
|
113
|
+
statusCounts: { ...statusCounts },
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
reset() {
|
|
117
|
+
requests = 0;
|
|
118
|
+
errors = 0;
|
|
119
|
+
totalDurationMs = 0;
|
|
120
|
+
maxDurationMs = 0;
|
|
121
|
+
for (const status of Object.keys(statusCounts)) {
|
|
122
|
+
delete statusCounts[status];
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function createRateLimitMiddleware(options) {
|
|
128
|
+
if (!Number.isInteger(options.limit) || options.limit < 1) {
|
|
129
|
+
throw new RangeError('Rate-limit limit must be a positive integer.');
|
|
130
|
+
}
|
|
131
|
+
if (!Number.isInteger(options.windowMs) || options.windowMs < 1) {
|
|
132
|
+
throw new RangeError('Rate-limit windowMs must be a positive integer.');
|
|
133
|
+
}
|
|
134
|
+
const store = options.store ?? createInMemoryRateLimitStore();
|
|
135
|
+
const now = options.now ?? (() => Date.now());
|
|
136
|
+
const key = options.key;
|
|
137
|
+
return async (request, context, next) => {
|
|
138
|
+
if (options.skip?.(request))
|
|
139
|
+
return next();
|
|
140
|
+
const rateLimitKey = key(request, context);
|
|
141
|
+
const decision = store.consume(rateLimitKey, options.limit, options.windowMs, now());
|
|
142
|
+
const headers = rateLimitHeaders(decision);
|
|
143
|
+
if (!decision.allowed) {
|
|
144
|
+
context.logger.warn('http.rate_limit.rejected', {
|
|
145
|
+
key: rateLimitKey,
|
|
146
|
+
limit: decision.limit,
|
|
147
|
+
resetAt: decision.resetAt,
|
|
148
|
+
});
|
|
149
|
+
return withResponseHeaders(jsonError(429, 'HTTP_RATE_LIMITED', 'Too many requests.'), {
|
|
150
|
+
...headers,
|
|
151
|
+
'retry-after': String(Math.max(1, Math.ceil((decision.resetAt - now()) / 1000))),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return withResponseHeaders(await next(), headers);
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export function createInMemoryRateLimitStore() {
|
|
158
|
+
const buckets = new Map();
|
|
159
|
+
return {
|
|
160
|
+
consume(key, limit, windowMs, now) {
|
|
161
|
+
const current = buckets.get(key);
|
|
162
|
+
const bucket = current && current.resetAt > now
|
|
163
|
+
? current
|
|
164
|
+
: { count: 0, resetAt: now + windowMs };
|
|
165
|
+
bucket.count += 1;
|
|
166
|
+
buckets.set(key, bucket);
|
|
167
|
+
if (buckets.size > 1024) {
|
|
168
|
+
for (const [bucketKey, candidate] of buckets) {
|
|
169
|
+
if (candidate.resetAt <= now)
|
|
170
|
+
buckets.delete(bucketKey);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
allowed: bucket.count <= limit,
|
|
175
|
+
limit,
|
|
176
|
+
remaining: Math.max(0, limit - bucket.count),
|
|
177
|
+
resetAt: bucket.resetAt,
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function composeServerMiddleware(middleware, terminal) {
|
|
183
|
+
return async (request, context) => {
|
|
184
|
+
const dispatch = (index) => {
|
|
185
|
+
if (index === middleware.length) {
|
|
186
|
+
return Promise.resolve(terminal(request, context));
|
|
187
|
+
}
|
|
188
|
+
return Promise.resolve(middleware[index](request, context, () => dispatch(index + 1)));
|
|
189
|
+
};
|
|
190
|
+
return dispatch(0);
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
export function matchServerRoute(request, routes) {
|
|
194
|
+
const method = request.method.toUpperCase();
|
|
195
|
+
const pathname = normalizePathname(new URL(request.url).pathname);
|
|
196
|
+
for (const route of routes) {
|
|
197
|
+
if (route.method !== method)
|
|
198
|
+
continue;
|
|
199
|
+
const params = matchPath(route.path, pathname);
|
|
200
|
+
if (params)
|
|
201
|
+
return { route, params };
|
|
202
|
+
}
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
export function createRequestGuardMiddleware(options) {
|
|
206
|
+
const maxBodyBytes = options.maxBodyBytes ?? 1_048_576;
|
|
207
|
+
const allowedOrigins = new Set(options.allowedOrigins ?? []);
|
|
208
|
+
const trustedHosts = new Set(options.trustedHosts ?? []);
|
|
209
|
+
return (request, context, next) => {
|
|
210
|
+
let url;
|
|
211
|
+
try {
|
|
212
|
+
url = new URL(request.url);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return jsonError(400, 'HTTP_REQUEST_INVALID', 'Invalid request URL.');
|
|
216
|
+
}
|
|
217
|
+
if (trustedHosts.size > 0 && !trustedHosts.has(url.host)) {
|
|
218
|
+
context.logger.warn('http.host.rejected', { host: url.host });
|
|
219
|
+
return jsonError(400, 'HTTP_HOST_NOT_ALLOWED', 'Host is not allowed.');
|
|
220
|
+
}
|
|
221
|
+
const contentLength = request.headers.get('content-length');
|
|
222
|
+
if (contentLength !== null) {
|
|
223
|
+
const length = Number(contentLength);
|
|
224
|
+
if (!Number.isSafeInteger(length) || length < 0) {
|
|
225
|
+
return jsonError(400, 'HTTP_CONTENT_LENGTH_INVALID', 'Invalid Content-Length.');
|
|
226
|
+
}
|
|
227
|
+
if (length > maxBodyBytes) {
|
|
228
|
+
return jsonError(413, 'HTTP_BODY_TOO_LARGE', 'Request body is too large.');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const origin = request.headers.get('origin');
|
|
232
|
+
const sameOrigin = origin === url.origin;
|
|
233
|
+
const allowed = origin !== null && (sameOrigin || allowedOrigins.has(origin));
|
|
234
|
+
// Une origine étrangère sur une méthode mutante est refusée par défaut :
|
|
235
|
+
// c'est le seul réglage qui protège une application montée sur cookie
|
|
236
|
+
// avant qu'elle n'ait configuré quoi que ce soit.
|
|
237
|
+
if (options.csrf !== 'off' &&
|
|
238
|
+
origin !== null &&
|
|
239
|
+
!allowed &&
|
|
240
|
+
MUTATION_METHODS.has(request.method.toUpperCase())) {
|
|
241
|
+
context.logger.warn('http.origin.rejected', {
|
|
242
|
+
method: request.method,
|
|
243
|
+
origin,
|
|
244
|
+
});
|
|
245
|
+
return jsonError(403, 'HTTP_ORIGIN_NOT_ALLOWED', 'Origin is not allowed.');
|
|
246
|
+
}
|
|
247
|
+
if (origin && !allowed && allowedOrigins.size > 0) {
|
|
248
|
+
return jsonError(403, 'HTTP_ORIGIN_NOT_ALLOWED', 'Origin is not allowed.');
|
|
249
|
+
}
|
|
250
|
+
if (allowed) {
|
|
251
|
+
return withCorsHeaders(request, next(), allowedOrigins, origin);
|
|
252
|
+
}
|
|
253
|
+
return next();
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Résout l'identité et les services de la requête à l'intérieur du pipeline,
|
|
258
|
+
* pour qu'une session illisible produise une réponse d'erreur propre au lieu
|
|
259
|
+
* de rejeter la promesse du serveur.
|
|
260
|
+
*/
|
|
261
|
+
export function createIdentityMiddleware(options) {
|
|
262
|
+
return async (request, context, next) => {
|
|
263
|
+
const mutable = context;
|
|
264
|
+
if (options.user) {
|
|
265
|
+
const user = await options.user(request);
|
|
266
|
+
if (user !== undefined)
|
|
267
|
+
mutable.user = user;
|
|
268
|
+
}
|
|
269
|
+
if (options.services !== undefined) {
|
|
270
|
+
mutable.services =
|
|
271
|
+
typeof options.services === 'function'
|
|
272
|
+
? await options.services(request)
|
|
273
|
+
: options.services;
|
|
274
|
+
}
|
|
275
|
+
return next();
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
export function createCorsMiddleware(allowedOrigins) {
|
|
279
|
+
const origins = new Set(allowedOrigins);
|
|
280
|
+
return (request, _context, next) => {
|
|
281
|
+
const origin = request.headers.get('origin');
|
|
282
|
+
if (request.method === 'OPTIONS') {
|
|
283
|
+
if (!origin || !origins.has(origin)) {
|
|
284
|
+
return jsonError(403, 'HTTP_ORIGIN_NOT_ALLOWED', 'Origin is not allowed.');
|
|
285
|
+
}
|
|
286
|
+
return new Response(null, {
|
|
287
|
+
status: 204,
|
|
288
|
+
headers: corsHeaders(origin),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const response = next();
|
|
292
|
+
return response.then((value) => origin && origins.has(origin)
|
|
293
|
+
? withResponseHeaders(value, corsHeaders(origin))
|
|
294
|
+
: value);
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export function createSecurityMiddleware(options = {}) {
|
|
298
|
+
const allowedOrigins = new Set(options.allowedOrigins ?? []);
|
|
299
|
+
const useNonce = options.useNonce ?? true;
|
|
300
|
+
return (request, context, next) => {
|
|
301
|
+
if (options.forceHttps) {
|
|
302
|
+
const url = new URL(request.url);
|
|
303
|
+
if (url.protocol === 'http:' && url.hostname !== 'localhost') {
|
|
304
|
+
url.protocol = 'https:';
|
|
305
|
+
return new Response(null, {
|
|
306
|
+
status: 308,
|
|
307
|
+
headers: { location: url.toString() },
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const headers = {
|
|
312
|
+
'content-security-policy': contentSecurityPolicy(useNonce ? context.cspNonce : undefined, options.directives),
|
|
313
|
+
'x-content-type-options': 'nosniff',
|
|
314
|
+
'x-frame-options': 'SAMEORIGIN',
|
|
315
|
+
'referrer-policy': 'strict-origin-when-cross-origin',
|
|
316
|
+
'permissions-policy': 'camera=(), geolocation=(), microphone=()',
|
|
317
|
+
'cross-origin-opener-policy': 'same-origin',
|
|
318
|
+
'cross-origin-resource-policy': 'same-origin',
|
|
319
|
+
};
|
|
320
|
+
if (options.forceHttps) {
|
|
321
|
+
headers['strict-transport-security'] =
|
|
322
|
+
'max-age=31536000; includeSubDomains';
|
|
323
|
+
}
|
|
324
|
+
const origin = request.headers.get('origin');
|
|
325
|
+
if (origin && allowedOrigins.has(origin)) {
|
|
326
|
+
Object.assign(headers, corsHeaders(origin));
|
|
327
|
+
}
|
|
328
|
+
return next().then((response) => withResponseHeaders(response, headers));
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Politique de base. Les domaines appartiennent au projet : `directives`
|
|
333
|
+
* ajoute des sources, la lib ne décide que du socle restrictif.
|
|
334
|
+
*/
|
|
335
|
+
export function contentSecurityPolicy(nonce, directives = {}) {
|
|
336
|
+
const base = {
|
|
337
|
+
'default-src': ["'self'"],
|
|
338
|
+
'base-uri': ["'self'"],
|
|
339
|
+
'object-src': ["'none'"],
|
|
340
|
+
'frame-ancestors': ["'self'"],
|
|
341
|
+
'form-action': ["'self'"],
|
|
342
|
+
'script-src': ["'self'", ...(nonce ? [`'nonce-${nonce}'`] : [])],
|
|
343
|
+
'style-src': [
|
|
344
|
+
"'self'",
|
|
345
|
+
// Repli documenté quand l'application n'a pas encore de nonce.
|
|
346
|
+
// craft-security-ignore CRAFT_SECURITY_CSP_UNSAFE_INLINE
|
|
347
|
+
...(nonce ? [`'nonce-${nonce}'`] : ["'unsafe-inline'"]),
|
|
348
|
+
],
|
|
349
|
+
'img-src': ["'self'", 'data:'],
|
|
350
|
+
'connect-src': ["'self'"],
|
|
351
|
+
};
|
|
352
|
+
for (const [directive, sources] of Object.entries(directives)) {
|
|
353
|
+
base[directive] = [...(base[directive] ?? []), ...sources];
|
|
354
|
+
}
|
|
355
|
+
return Object.entries(base)
|
|
356
|
+
.map(([directive, sources]) => `${directive} ${sources.join(' ')}`)
|
|
357
|
+
.join('; ');
|
|
358
|
+
}
|
|
359
|
+
/** Nonce par requête, au format base64 accepté par `provideCraftCspNonce`. */
|
|
360
|
+
export function createCspNonce() {
|
|
361
|
+
const bytes = new Uint8Array(16);
|
|
362
|
+
if (globalThis.crypto?.getRandomValues) {
|
|
363
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
367
|
+
bytes[index] = Math.floor(Math.random() * 256);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
let binary = '';
|
|
371
|
+
for (const byte of bytes)
|
|
372
|
+
binary += String.fromCharCode(byte);
|
|
373
|
+
return btoa(binary).replace(/=+$/, '');
|
|
374
|
+
}
|
|
375
|
+
export function createCsrfMiddleware(options = {}) {
|
|
376
|
+
return async (request, context, next) => {
|
|
377
|
+
if (isSameSiteMutation(request, options.allowedOrigins))
|
|
378
|
+
return next();
|
|
379
|
+
context.logger.warn('http.csrf.rejected', { method: request.method });
|
|
380
|
+
return jsonError(403, 'HTTP_CSRF_REJECTED', 'CSRF validation failed.');
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Une mutation est acceptée quand elle ne vient pas d'un autre site. Une
|
|
385
|
+
* origine absente est refusée sur une requête porteuse de cookie : c'est le
|
|
386
|
+
* cas d'un POST de formulaire cross-site, et un client légitime en envoie une.
|
|
387
|
+
*/
|
|
388
|
+
export function isSameSiteMutation(request, allowedOrigins = []) {
|
|
389
|
+
const method = request.method.toUpperCase();
|
|
390
|
+
if (!MUTATION_METHODS.has(method))
|
|
391
|
+
return true;
|
|
392
|
+
const site = request.headers.get('sec-fetch-site');
|
|
393
|
+
if (site)
|
|
394
|
+
return site === 'same-origin' || site === 'none';
|
|
395
|
+
const origin = request.headers.get('origin');
|
|
396
|
+
if (!origin)
|
|
397
|
+
return request.headers.get('cookie') === null;
|
|
398
|
+
let requestOrigin;
|
|
399
|
+
try {
|
|
400
|
+
requestOrigin = new URL(request.url).origin;
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
return origin === requestOrigin || allowedOrigins.includes(origin);
|
|
406
|
+
}
|
|
407
|
+
function createRouteHandler(routes) {
|
|
408
|
+
return async (request, context) => {
|
|
409
|
+
const match = matchServerRoute(request, routes);
|
|
410
|
+
if (!match) {
|
|
411
|
+
const pathname = normalizePathname(new URL(request.url).pathname);
|
|
412
|
+
const methods = routes
|
|
413
|
+
.filter((route) => matchPath(route.path, pathname))
|
|
414
|
+
.map((route) => route.method);
|
|
415
|
+
if (methods.length > 0) {
|
|
416
|
+
return new Response('Method Not Allowed', {
|
|
417
|
+
status: 405,
|
|
418
|
+
headers: { allow: [...new Set(methods)].join(', ') },
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return jsonError(404, 'HTTP_ROUTE_NOT_FOUND', 'Route not found.');
|
|
422
|
+
}
|
|
423
|
+
if (match.route.auth === 'required' && context.user === undefined) {
|
|
424
|
+
return jsonError(401, 'HTTP_AUTH_REQUIRED', 'Authentication is required.');
|
|
425
|
+
}
|
|
426
|
+
if (match.route.csrf && !isSameSiteMutation(request)) {
|
|
427
|
+
context.logger.warn('http.csrf.rejected', {
|
|
428
|
+
method: request.method,
|
|
429
|
+
path: new URL(request.url).pathname,
|
|
430
|
+
});
|
|
431
|
+
return jsonError(403, 'HTTP_CSRF_REJECTED', 'CSRF validation failed.');
|
|
432
|
+
}
|
|
433
|
+
const routeContext = { ...context, params: match.params };
|
|
434
|
+
const response = await match.route.handler(request, routeContext);
|
|
435
|
+
return match.route.cache
|
|
436
|
+
? withResponseHeaders(response, { 'cache-control': match.route.cache })
|
|
437
|
+
: response;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function decodeSegment(segment) {
|
|
441
|
+
try {
|
|
442
|
+
return decodeURIComponent(segment);
|
|
443
|
+
}
|
|
444
|
+
catch {
|
|
445
|
+
throw new HttpRequestError('HTTP_PATH_INVALID', 400, 'The request path is not valid percent-encoded UTF-8.');
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function matchPath(template, pathname) {
|
|
449
|
+
const templateSegments = normalizePathname(template)
|
|
450
|
+
.split('/')
|
|
451
|
+
.filter(Boolean);
|
|
452
|
+
const pathSegments = pathname.split('/').filter(Boolean);
|
|
453
|
+
const params = {};
|
|
454
|
+
for (let index = 0; index < templateSegments.length; index += 1) {
|
|
455
|
+
const templateSegment = templateSegments[index];
|
|
456
|
+
const pathSegment = pathSegments[index];
|
|
457
|
+
if (templateSegment === '*') {
|
|
458
|
+
params['wildcard'] = pathSegments
|
|
459
|
+
.slice(index)
|
|
460
|
+
.map(decodeSegment)
|
|
461
|
+
.join('/');
|
|
462
|
+
return params;
|
|
463
|
+
}
|
|
464
|
+
if (pathSegment === undefined)
|
|
465
|
+
return undefined;
|
|
466
|
+
if (templateSegment.startsWith(':')) {
|
|
467
|
+
params[templateSegment.slice(1)] = decodeSegment(pathSegment);
|
|
468
|
+
}
|
|
469
|
+
else if (templateSegment !== decodeSegment(pathSegment)) {
|
|
470
|
+
return undefined;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return templateSegments.length === pathSegments.length ? params : undefined;
|
|
474
|
+
}
|
|
475
|
+
function normalizePathname(pathname) {
|
|
476
|
+
if (pathname === '/')
|
|
477
|
+
return '/';
|
|
478
|
+
return `/${pathname.split('/').filter(Boolean).join('/')}`;
|
|
479
|
+
}
|
|
480
|
+
function requestIdFrom(request) {
|
|
481
|
+
const candidate = request.headers.get('x-request-id');
|
|
482
|
+
if (candidate && /^[A-Za-z0-9._:-]{1,128}$/.test(candidate))
|
|
483
|
+
return candidate;
|
|
484
|
+
return (globalThis.crypto?.randomUUID?.() ?? `request-${Date.now().toString(36)}`);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Combine l'annulation du client et le délai maximal de la requête. Le repli
|
|
488
|
+
* manuel est important : sans lui, un runtime sans `AbortSignal.any` perdrait
|
|
489
|
+
* silencieusement tout timeout.
|
|
490
|
+
*/
|
|
491
|
+
function timeoutSignal(signal, timeoutMs) {
|
|
492
|
+
if (timeoutMs <= 0)
|
|
493
|
+
return { signal, dispose: () => undefined };
|
|
494
|
+
const controller = new AbortController();
|
|
495
|
+
const timer = setTimeout(() => controller.abort(new DOMException('Request timed out', 'TimeoutError')), timeoutMs);
|
|
496
|
+
const forward = () => controller.abort(signal.reason);
|
|
497
|
+
if (signal.aborted)
|
|
498
|
+
forward();
|
|
499
|
+
else
|
|
500
|
+
signal.addEventListener('abort', forward, { once: true });
|
|
501
|
+
return {
|
|
502
|
+
signal: controller.signal,
|
|
503
|
+
dispose: () => {
|
|
504
|
+
clearTimeout(timer);
|
|
505
|
+
signal.removeEventListener('abort', forward);
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
async function withAbort(response, signal) {
|
|
510
|
+
if (signal.aborted) {
|
|
511
|
+
throw new HttpRequestError('HTTP_REQUEST_TIMEOUT', 504, 'Request timed out.');
|
|
512
|
+
}
|
|
513
|
+
let onAbort;
|
|
514
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
515
|
+
onAbort = () => reject(new HttpRequestError('HTTP_REQUEST_TIMEOUT', 504, 'Request timed out.'));
|
|
516
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
517
|
+
});
|
|
518
|
+
try {
|
|
519
|
+
return await Promise.race([response, aborted]);
|
|
520
|
+
}
|
|
521
|
+
finally {
|
|
522
|
+
if (onAbort)
|
|
523
|
+
signal.removeEventListener('abort', onAbort);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function createJsonLogger(requestId, sink) {
|
|
527
|
+
const write = (level, event, data = {}) => {
|
|
528
|
+
const entry = {
|
|
529
|
+
timestamp: new Date().toISOString(),
|
|
530
|
+
level,
|
|
531
|
+
event,
|
|
532
|
+
requestId,
|
|
533
|
+
...data,
|
|
534
|
+
};
|
|
535
|
+
if (sink)
|
|
536
|
+
sink(entry);
|
|
537
|
+
else
|
|
538
|
+
console.log(JSON.stringify(entry));
|
|
539
|
+
};
|
|
540
|
+
return {
|
|
541
|
+
debug: (event, data) => write('debug', event, data),
|
|
542
|
+
info: (event, data) => write('info', event, data),
|
|
543
|
+
warn: (event, data) => write('warn', event, data),
|
|
544
|
+
error: (event, data) => write('error', event, data),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
function withCorsHeaders(request, response, allowedOrigins, directOrigin) {
|
|
548
|
+
const origin = directOrigin ?? request.headers.get('origin');
|
|
549
|
+
return Promise.resolve(response).then((value) => origin && allowedOrigins.has(origin)
|
|
550
|
+
? withResponseHeaders(value, corsHeaders(origin))
|
|
551
|
+
: value);
|
|
552
|
+
}
|
|
553
|
+
function corsHeaders(origin) {
|
|
554
|
+
return {
|
|
555
|
+
'access-control-allow-origin': origin,
|
|
556
|
+
'access-control-allow-credentials': 'true',
|
|
557
|
+
'access-control-allow-methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
|
|
558
|
+
'access-control-allow-headers': 'content-type, x-request-id, x-csrf-token',
|
|
559
|
+
vary: 'Origin',
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function rateLimitHeaders(decision) {
|
|
563
|
+
return {
|
|
564
|
+
'x-ratelimit-limit': String(decision.limit),
|
|
565
|
+
'x-ratelimit-remaining': String(decision.remaining),
|
|
566
|
+
'x-ratelimit-reset': String(Math.ceil(decision.resetAt / 1000)),
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function withResponseHeaders(response, headers) {
|
|
570
|
+
const merged = new Headers(response.headers);
|
|
571
|
+
for (const [name, value] of Object.entries(headers))
|
|
572
|
+
merged.set(name, value);
|
|
573
|
+
return new Response(response.body, {
|
|
574
|
+
status: response.status,
|
|
575
|
+
statusText: response.statusText,
|
|
576
|
+
headers: merged,
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
function jsonError(status, code, message) {
|
|
580
|
+
return Response.json({ error: { code, message } }, { status });
|
|
581
|
+
}
|
|
582
|
+
function errorResponse(error) {
|
|
583
|
+
if (error instanceof HttpRequestError) {
|
|
584
|
+
return jsonError(error.status, error.code, error.message);
|
|
585
|
+
}
|
|
586
|
+
return jsonError(500, 'HTTP_INTERNAL_ERROR', 'Internal Server Error.');
|
|
587
|
+
}
|
|
588
|
+
function publicErrorMessage(error) {
|
|
589
|
+
return error instanceof Error ? error.message : String(error);
|
|
590
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { InsertionStateFactoryContext } from './query.core';
|
|
2
|
-
import { EntitiesUtilBrand, IdSelector } from './util/entities-util';
|
|
3
|
-
import { AccessTypeObjectPropertyByDottedPath, DottedPathPathToTuple } from './util/types/access-type-object-property-by-dotted-path.type';
|
|
4
|
-
import { ObjectDeepPath } from './util/types/object-deep-path-mapper.type';
|
|
5
|
-
import { MergeObject, Prettify } from './util/util.type';
|
|
1
|
+
import { InsertionStateFactoryContext } from './query.core.js';
|
|
2
|
+
import { EntitiesUtilBrand, IdSelector } from './util/entities-util.js';
|
|
3
|
+
import { AccessTypeObjectPropertyByDottedPath, DottedPathPathToTuple } from './util/types/access-type-object-property-by-dotted-path.type.js';
|
|
4
|
+
import { ObjectDeepPath } from './util/types/object-deep-path-mapper.type.js';
|
|
5
|
+
import { MergeObject, Prettify } from './util/util.type.js';
|
|
6
6
|
type ArrayObjectDeepPath<State extends object> = ObjectDeepPath<State> extends infer Path ? Path extends string ? AccessTypeObjectPropertyByDottedPath<State, DottedPathPathToTuple<Path>> extends Array<any> ? Path : never : never : never;
|
|
7
7
|
type DottedPathToCamel<Path extends string> = Path extends `${infer Head}.${infer Tail}` ? `${Head}${Capitalize<DottedPathToCamel<Tail>>}` : Path;
|
|
8
8
|
type EntitiesUtilsToMap<EntityHelperFns, Entity, K, HasStateIdentifier, StateIdentifier, HasPath, Path, Acc = {}> = EntityHelperFns extends [infer First, ...infer Rest] ? First extends (data: infer Payload) => infer R ? R extends EntitiesUtilBrand<infer Name> ? EntitiesUtilsToMap<Rest, Entity, K, HasStateIdentifier, StateIdentifier, HasPath, Path, Acc & {
|
|
@@ -128,4 +128,3 @@ export declare function insertEntities<State, K extends string | number, Previou
|
|
|
128
128
|
testHasPath: "path" extends keyof typeof config ? true : false;
|
|
129
129
|
};
|
|
130
130
|
export {};
|
|
131
|
-
//# sourceMappingURL=insert-entities.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createNestedStateUpdate, getNestedStateValue, } from './util/update-state.util';
|
|
1
|
+
import { createNestedStateUpdate, getNestedStateValue, } from './util/update-state.util.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates an insertion that adds entity collection management methods to state, query, or queryParams primitives.
|
|
4
4
|
*
|
|
@@ -156,4 +156,3 @@ export function insertEntities(config) {
|
|
|
156
156
|
return methods;
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
//# sourceMappingURL=insert-entities.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InsertionStateFactoryContext } from './query.core';
|
|
1
|
+
import type { InsertionStateFactoryContext } from './query.core.js';
|
|
2
2
|
/**
|
|
3
3
|
* No-op insertion used to preserve contextual typing in insertion chains of
|
|
4
4
|
* the form-tree helpers (`insertForm` / `insertSelectFormTree`), which keep a
|
|
@@ -12,4 +12,3 @@ import type { InsertionStateFactoryContext } from './query.core';
|
|
|
12
12
|
* which preserves nested contextual typing by itself.
|
|
13
13
|
*/
|
|
14
14
|
export declare function insertNoopTypingAnchor<StateType, PreviousInsertionsOutputs = {}>(_context: InsertionStateFactoryContext<StateType, PreviousInsertionsOutputs>): {};
|
|
15
|
-
//# sourceMappingURL=insert-noop-typing-anchor.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Signal } from './host/craft-compat';
|
|
2
|
-
import { type CraftSettledBrand } from './craft-settled';
|
|
3
|
-
import { InsertionByIdParams, ResourceExceptionConstraints, YieldableInsertionWrite } from './query.core';
|
|
4
|
-
import { CraftResourceStatus } from './util/craft-resource-status';
|
|
5
|
-
import { type YieldableReactiveValue } from './reactive-read';
|
|
1
|
+
import { Signal } from './host/craft-compat.js';
|
|
2
|
+
import { type CraftSettledBrand } from './craft-settled.js';
|
|
3
|
+
import { InsertionByIdParams, ResourceExceptionConstraints, YieldableInsertionWrite } from './query.core.js';
|
|
4
|
+
import { CraftResourceStatus } from './util/craft-resource-status.js';
|
|
5
|
+
import { type YieldableReactiveValue } from './reactive-read.js';
|
|
6
6
|
/**
|
|
7
7
|
* Base outputs produced by {@link insertPaginationPlaceholderData}.
|
|
8
8
|
*
|
|
@@ -119,4 +119,3 @@ export declare function insertPaginationPlaceholderData<PageState, ExtraOutputs
|
|
|
119
119
|
initialValue: PageState;
|
|
120
120
|
}, build?: (context: PaginationBuildContext<PageState>) => ExtraOutputs): <GroupIdentifier extends string, ResourceParams, Exceptions extends ResourceExceptionConstraints, PreviousInsertionsOutputs, PrimitiveName extends string>(context: InsertionByIdParams<GroupIdentifier, PageState & object, ResourceParams, Exceptions, NoInfer<PreviousInsertionsOutputs>, PrimitiveName>) => PaginationBaseOutputs<PageState, PrimitiveName, Exceptions["params"] | Exceptions["loader"]> & ExtraOutputs;
|
|
121
121
|
export {};
|
|
122
|
-
//# sourceMappingURL=insert-pagination-placeholder-data.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { craftComputed } from './craft-computed';
|
|
2
|
-
import { isGenerator } from './craft-generator-runtime';
|
|
3
|
-
import { settled } from './craft-settled';
|
|
4
|
-
import { toCraftStatus, } from './util/craft-resource-status';
|
|
5
|
-
import { createYieldableReactiveFacade, rawReactiveFacade, } from './reactive-read';
|
|
1
|
+
import { craftComputed } from './craft-computed.js';
|
|
2
|
+
import { isGenerator } from './craft-generator-runtime.js';
|
|
3
|
+
import { settled } from './craft-settled.js';
|
|
4
|
+
import { toCraftStatus, } from './util/craft-resource-status.js';
|
|
5
|
+
import { createYieldableReactiveFacade, rawReactiveFacade, } from './reactive-read.js';
|
|
6
6
|
function* readPaginationReactive(reader) {
|
|
7
7
|
const value = reader();
|
|
8
8
|
return isGenerator(value) ? yield* value : value;
|
|
@@ -241,4 +241,3 @@ export function insertPaginationPlaceholderData(config, build) {
|
|
|
241
241
|
};
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
-
//# sourceMappingURL=insert-pagination-placeholder-data.js.map
|