@craft-ts/core 0.7.0-beta.13
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/LICENSE +21 -0
- package/package.json +58 -0
- package/src/index.d.ts +148 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +150 -0
- package/src/index.js.map +1 -0
- package/src/lib/after-recomputation.d.ts +327 -0
- package/src/lib/after-recomputation.d.ts.map +1 -0
- package/src/lib/after-recomputation.js +25 -0
- package/src/lib/after-recomputation.js.map +1 -0
- package/src/lib/app-checked-di.d.ts +82 -0
- package/src/lib/app-checked-di.d.ts.map +1 -0
- package/src/lib/app-checked-di.js +1 -0
- package/src/lib/app-checked-di.js.map +1 -0
- package/src/lib/async-process.d.ts +411 -0
- package/src/lib/async-process.d.ts.map +1 -0
- package/src/lib/async-process.js +702 -0
- package/src/lib/async-process.js.map +1 -0
- package/src/lib/branded-component/branded-component.d.ts +129 -0
- package/src/lib/branded-component/branded-component.d.ts.map +1 -0
- package/src/lib/branded-component/branded-component.js +7 -0
- package/src/lib/branded-component/branded-component.js.map +1 -0
- package/src/lib/browser-boundaries.d.ts +165 -0
- package/src/lib/browser-boundaries.d.ts.map +1 -0
- package/src/lib/browser-boundaries.js +550 -0
- package/src/lib/browser-boundaries.js.map +1 -0
- package/src/lib/client-di-requirement.d.ts +28 -0
- package/src/lib/client-di-requirement.d.ts.map +1 -0
- package/src/lib/client-di-requirement.js +11 -0
- package/src/lib/client-di-requirement.js.map +1 -0
- package/src/lib/client-function-middleware.d.ts +130 -0
- package/src/lib/client-function-middleware.d.ts.map +1 -0
- package/src/lib/client-function-middleware.js +144 -0
- package/src/lib/client-function-middleware.js.map +1 -0
- package/src/lib/component-monitoring.d.ts +7 -0
- package/src/lib/component-monitoring.d.ts.map +1 -0
- package/src/lib/component-monitoring.js +28 -0
- package/src/lib/component-monitoring.js.map +1 -0
- package/src/lib/component-register.d.ts +12 -0
- package/src/lib/component-register.d.ts.map +1 -0
- package/src/lib/component-register.js +13 -0
- package/src/lib/component-register.js.map +1 -0
- package/src/lib/computed-source.d.ts +303 -0
- package/src/lib/computed-source.d.ts.map +1 -0
- package/src/lib/computed-source.js +319 -0
- package/src/lib/computed-source.js.map +1 -0
- package/src/lib/correlation-id-plugin.d.ts +3 -0
- package/src/lib/correlation-id-plugin.d.ts.map +1 -0
- package/src/lib/correlation-id-plugin.js +73 -0
- package/src/lib/correlation-id-plugin.js.map +1 -0
- package/src/lib/correlation-id.d.ts +30 -0
- package/src/lib/correlation-id.d.ts.map +1 -0
- package/src/lib/correlation-id.js +86 -0
- package/src/lib/correlation-id.js.map +1 -0
- package/src/lib/craft-a11y.d.ts +22 -0
- package/src/lib/craft-a11y.d.ts.map +1 -0
- package/src/lib/craft-a11y.js +32 -0
- package/src/lib/craft-a11y.js.map +1 -0
- package/src/lib/craft-activated-route.d.ts +21 -0
- package/src/lib/craft-activated-route.d.ts.map +1 -0
- package/src/lib/craft-activated-route.js +20 -0
- package/src/lib/craft-activated-route.js.map +1 -0
- package/src/lib/craft-app-config.d.ts +91 -0
- package/src/lib/craft-app-config.d.ts.map +1 -0
- package/src/lib/craft-app-config.js +64 -0
- package/src/lib/craft-app-config.js.map +1 -0
- package/src/lib/craft-codec.d.ts +16 -0
- package/src/lib/craft-codec.d.ts.map +1 -0
- package/src/lib/craft-codec.js +1 -0
- package/src/lib/craft-codec.js.map +1 -0
- package/src/lib/craft-computed.d.ts +31 -0
- package/src/lib/craft-computed.d.ts.map +1 -0
- package/src/lib/craft-computed.js +81 -0
- package/src/lib/craft-computed.js.map +1 -0
- package/src/lib/craft-control-flow.d.ts +14 -0
- package/src/lib/craft-control-flow.d.ts.map +1 -0
- package/src/lib/craft-control-flow.js +18 -0
- package/src/lib/craft-control-flow.js.map +1 -0
- package/src/lib/craft-effect.d.ts +13 -0
- package/src/lib/craft-effect.d.ts.map +1 -0
- package/src/lib/craft-effect.js +93 -0
- package/src/lib/craft-effect.js.map +1 -0
- package/src/lib/craft-exception.d.ts +40 -0
- package/src/lib/craft-exception.d.ts.map +1 -0
- package/src/lib/craft-exception.js +16 -0
- package/src/lib/craft-exception.js.map +1 -0
- package/src/lib/craft-gen.d.ts +123 -0
- package/src/lib/craft-gen.d.ts.map +1 -0
- package/src/lib/craft-gen.js +90 -0
- package/src/lib/craft-gen.js.map +1 -0
- package/src/lib/craft-generator-runtime.d.ts +110 -0
- package/src/lib/craft-generator-runtime.d.ts.map +1 -0
- package/src/lib/craft-generator-runtime.js +191 -0
- package/src/lib/craft-generator-runtime.js.map +1 -0
- package/src/lib/craft-guard-runtime.d.ts +70 -0
- package/src/lib/craft-guard-runtime.d.ts.map +1 -0
- package/src/lib/craft-guard-runtime.js +195 -0
- package/src/lib/craft-guard-runtime.js.map +1 -0
- package/src/lib/craft-handshake.d.ts +35 -0
- package/src/lib/craft-handshake.d.ts.map +1 -0
- package/src/lib/craft-handshake.js +34 -0
- package/src/lib/craft-handshake.js.map +1 -0
- package/src/lib/craft-http-client.d.ts +236 -0
- package/src/lib/craft-http-client.d.ts.map +1 -0
- package/src/lib/craft-http-client.js +437 -0
- package/src/lib/craft-http-client.js.map +1 -0
- package/src/lib/craft-http-trace.d.ts +12 -0
- package/src/lib/craft-http-trace.d.ts.map +1 -0
- package/src/lib/craft-http-trace.js +28 -0
- package/src/lib/craft-http-trace.js.map +1 -0
- package/src/lib/craft-lazy.d.ts +42 -0
- package/src/lib/craft-lazy.d.ts.map +1 -0
- package/src/lib/craft-lazy.js +83 -0
- package/src/lib/craft-lazy.js.map +1 -0
- package/src/lib/craft-load-retry.d.ts +76 -0
- package/src/lib/craft-load-retry.d.ts.map +1 -0
- package/src/lib/craft-load-retry.js +160 -0
- package/src/lib/craft-load-retry.js.map +1 -0
- package/src/lib/craft-machine-history.d.ts +145 -0
- package/src/lib/craft-machine-history.d.ts.map +1 -0
- package/src/lib/craft-machine-history.js +276 -0
- package/src/lib/craft-machine-history.js.map +1 -0
- package/src/lib/craft-match.d.ts +49 -0
- package/src/lib/craft-match.d.ts.map +1 -0
- package/src/lib/craft-match.js +58 -0
- package/src/lib/craft-match.js.map +1 -0
- package/src/lib/craft-method.d.ts +28 -0
- package/src/lib/craft-method.d.ts.map +1 -0
- package/src/lib/craft-method.js +45 -0
- package/src/lib/craft-method.js.map +1 -0
- package/src/lib/craft-node-directive.d.ts +32 -0
- package/src/lib/craft-node-directive.d.ts.map +1 -0
- package/src/lib/craft-node-directive.js +22 -0
- package/src/lib/craft-node-directive.js.map +1 -0
- package/src/lib/craft-pending.d.ts +115 -0
- package/src/lib/craft-pending.d.ts.map +1 -0
- package/src/lib/craft-pending.js +187 -0
- package/src/lib/craft-pending.js.map +1 -0
- package/src/lib/craft-pipe.d.ts +63 -0
- package/src/lib/craft-pipe.d.ts.map +1 -0
- package/src/lib/craft-pipe.js +57 -0
- package/src/lib/craft-pipe.js.map +1 -0
- package/src/lib/craft-platform.d.ts +50 -0
- package/src/lib/craft-platform.d.ts.map +1 -0
- package/src/lib/craft-platform.js +175 -0
- package/src/lib/craft-platform.js.map +1 -0
- package/src/lib/craft-primitive-gen.d.ts +137 -0
- package/src/lib/craft-primitive-gen.d.ts.map +1 -0
- package/src/lib/craft-primitive-gen.js +76 -0
- package/src/lib/craft-primitive-gen.js.map +1 -0
- package/src/lib/craft-primitive-registry.d.ts +113 -0
- package/src/lib/craft-primitive-registry.d.ts.map +1 -0
- package/src/lib/craft-primitive-registry.js +159 -0
- package/src/lib/craft-primitive-registry.js.map +1 -0
- package/src/lib/craft-program-operators.d.ts +101 -0
- package/src/lib/craft-program-operators.d.ts.map +1 -0
- package/src/lib/craft-program-operators.js +116 -0
- package/src/lib/craft-program-operators.js.map +1 -0
- package/src/lib/craft-program-runtime.d.ts +80 -0
- package/src/lib/craft-program-runtime.d.ts.map +1 -0
- package/src/lib/craft-program-runtime.js +166 -0
- package/src/lib/craft-program-runtime.js.map +1 -0
- package/src/lib/craft-register-for-runtime.d.ts +39 -0
- package/src/lib/craft-register-for-runtime.d.ts.map +1 -0
- package/src/lib/craft-register-for-runtime.js +96 -0
- package/src/lib/craft-register-for-runtime.js.map +1 -0
- package/src/lib/craft-register-for.d.ts +57 -0
- package/src/lib/craft-register-for.d.ts.map +1 -0
- package/src/lib/craft-register-for.js +200 -0
- package/src/lib/craft-register-for.js.map +1 -0
- package/src/lib/craft-render-identity.d.ts +19 -0
- package/src/lib/craft-render-identity.d.ts.map +1 -0
- package/src/lib/craft-render-identity.js +23 -0
- package/src/lib/craft-render-identity.js.map +1 -0
- package/src/lib/craft-replay.d.ts +5 -0
- package/src/lib/craft-replay.d.ts.map +1 -0
- package/src/lib/craft-replay.js +28 -0
- package/src/lib/craft-replay.js.map +1 -0
- package/src/lib/craft-resolve.d.ts +39 -0
- package/src/lib/craft-resolve.d.ts.map +1 -0
- package/src/lib/craft-resolve.js +9 -0
- package/src/lib/craft-resolve.js.map +1 -0
- package/src/lib/craft-resource.d.ts +11 -0
- package/src/lib/craft-resource.d.ts.map +1 -0
- package/src/lib/craft-resource.js +264 -0
- package/src/lib/craft-resource.js.map +1 -0
- package/src/lib/craft-route-exceptions.d.ts +785 -0
- package/src/lib/craft-route-exceptions.d.ts.map +1 -0
- package/src/lib/craft-route-exceptions.js +86 -0
- package/src/lib/craft-route-exceptions.js.map +1 -0
- package/src/lib/craft-route-load-error.d.ts +1145 -0
- package/src/lib/craft-route-load-error.d.ts.map +1 -0
- package/src/lib/craft-route-load-error.js +173 -0
- package/src/lib/craft-route-load-error.js.map +1 -0
- package/src/lib/craft-route-meta.d.ts +52 -0
- package/src/lib/craft-route-meta.d.ts.map +1 -0
- package/src/lib/craft-route-meta.js +16 -0
- package/src/lib/craft-route-meta.js.map +1 -0
- package/src/lib/craft-route-target.d.ts +27 -0
- package/src/lib/craft-route-target.d.ts.map +1 -0
- package/src/lib/craft-route-target.js +22 -0
- package/src/lib/craft-route-target.js.map +1 -0
- package/src/lib/craft-router-outlet.d.ts +105 -0
- package/src/lib/craft-router-outlet.d.ts.map +1 -0
- package/src/lib/craft-router-outlet.js +735 -0
- package/src/lib/craft-router-outlet.js.map +1 -0
- package/src/lib/craft-router-tokens.d.ts +49 -0
- package/src/lib/craft-router-tokens.d.ts.map +1 -0
- package/src/lib/craft-router-tokens.js +15 -0
- package/src/lib/craft-router-tokens.js.map +1 -0
- package/src/lib/craft-router-trace.d.ts +18 -0
- package/src/lib/craft-router-trace.d.ts.map +1 -0
- package/src/lib/craft-router-trace.js +54 -0
- package/src/lib/craft-router-trace.js.map +1 -0
- package/src/lib/craft-router.d.ts +248 -0
- package/src/lib/craft-router.d.ts.map +1 -0
- package/src/lib/craft-router.js +559 -0
- package/src/lib/craft-router.js.map +1 -0
- package/src/lib/craft-routes.d.ts +755 -0
- package/src/lib/craft-routes.d.ts.map +1 -0
- package/src/lib/craft-routes.js +510 -0
- package/src/lib/craft-routes.js.map +1 -0
- package/src/lib/craft-service.d.ts +1034 -0
- package/src/lib/craft-service.d.ts.map +1 -0
- package/src/lib/craft-service.js +1072 -0
- package/src/lib/craft-service.js.map +1 -0
- package/src/lib/craft-service.shared.d.ts +35 -0
- package/src/lib/craft-service.shared.d.ts.map +1 -0
- package/src/lib/craft-service.shared.js +4 -0
- package/src/lib/craft-service.shared.js.map +1 -0
- package/src/lib/craft-settled.d.ts +171 -0
- package/src/lib/craft-settled.d.ts.map +1 -0
- package/src/lib/craft-settled.js +130 -0
- package/src/lib/craft-settled.js.map +1 -0
- package/src/lib/craft-ssr.d.ts +29 -0
- package/src/lib/craft-ssr.d.ts.map +1 -0
- package/src/lib/craft-ssr.js +27 -0
- package/src/lib/craft-ssr.js.map +1 -0
- package/src/lib/craft-state-machine-runtime.d.ts +88 -0
- package/src/lib/craft-state-machine-runtime.d.ts.map +1 -0
- package/src/lib/craft-state-machine-runtime.js +167 -0
- package/src/lib/craft-state-machine-runtime.js.map +1 -0
- package/src/lib/craft-state-machine.d.ts +233 -0
- package/src/lib/craft-state-machine.d.ts.map +1 -0
- package/src/lib/craft-state-machine.js +254 -0
- package/src/lib/craft-state-machine.js.map +1 -0
- package/src/lib/craft-target-runtime.d.ts +20 -0
- package/src/lib/craft-target-runtime.d.ts.map +1 -0
- package/src/lib/craft-target-runtime.js +42 -0
- package/src/lib/craft-target-runtime.js.map +1 -0
- package/src/lib/craft-transfer-snapshot.d.ts +19 -0
- package/src/lib/craft-transfer-snapshot.d.ts.map +1 -0
- package/src/lib/craft-transfer-snapshot.js +90 -0
- package/src/lib/craft-transfer-snapshot.js.map +1 -0
- package/src/lib/craft-unique.d.ts +7 -0
- package/src/lib/craft-unique.d.ts.map +1 -0
- package/src/lib/craft-unique.js +16 -0
- package/src/lib/craft-unique.js.map +1 -0
- package/src/lib/craft-until-settled.d.ts +99 -0
- package/src/lib/craft-until-settled.d.ts.map +1 -0
- package/src/lib/craft-until-settled.js +81 -0
- package/src/lib/craft-until-settled.js.map +1 -0
- package/src/lib/craft-use.d.ts +26 -0
- package/src/lib/craft-use.d.ts.map +1 -0
- package/src/lib/craft-use.js +37 -0
- package/src/lib/craft-use.js.map +1 -0
- package/src/lib/craft-view-transition.d.ts +102 -0
- package/src/lib/craft-view-transition.d.ts.map +1 -0
- package/src/lib/craft-view-transition.js +130 -0
- package/src/lib/craft-view-transition.js.map +1 -0
- package/src/lib/dom-event-hook.d.ts +30 -0
- package/src/lib/dom-event-hook.d.ts.map +1 -0
- package/src/lib/dom-event-hook.js +16 -0
- package/src/lib/dom-event-hook.js.map +1 -0
- package/src/lib/fn-wrapper.d.ts +13 -0
- package/src/lib/fn-wrapper.d.ts.map +1 -0
- package/src/lib/fn-wrapper.js +66 -0
- package/src/lib/fn-wrapper.js.map +1 -0
- package/src/lib/form/craft-field.d.ts +155 -0
- package/src/lib/form/craft-field.d.ts.map +1 -0
- package/src/lib/form/craft-field.directive.d.ts +70 -0
- package/src/lib/form/craft-field.directive.d.ts.map +1 -0
- package/src/lib/form/craft-field.directive.js +549 -0
- package/src/lib/form/craft-field.directive.js.map +1 -0
- package/src/lib/form/craft-field.js +586 -0
- package/src/lib/form/craft-field.js.map +1 -0
- package/src/lib/form/field-exception.d.ts +62 -0
- package/src/lib/form/field-exception.d.ts.map +1 -0
- package/src/lib/form/field-exception.js +37 -0
- package/src/lib/form/field-exception.js.map +1 -0
- package/src/lib/form/field-lens.d.ts +29 -0
- package/src/lib/form/field-lens.d.ts.map +1 -0
- package/src/lib/form/field-lens.js +32 -0
- package/src/lib/form/field-lens.js.map +1 -0
- package/src/lib/form/insert-form-attributes.d.ts +69 -0
- package/src/lib/form/insert-form-attributes.d.ts.map +1 -0
- package/src/lib/form/insert-form-attributes.js +163 -0
- package/src/lib/form/insert-form-attributes.js.map +1 -0
- package/src/lib/form/insert-form-internals.d.ts +110 -0
- package/src/lib/form/insert-form-internals.d.ts.map +1 -0
- package/src/lib/form/insert-form-internals.js +276 -0
- package/src/lib/form/insert-form-internals.js.map +1 -0
- package/src/lib/form/insert-form-schema.d.ts +10 -0
- package/src/lib/form/insert-form-schema.d.ts.map +1 -0
- package/src/lib/form/insert-form-schema.js +62 -0
- package/src/lib/form/insert-form-schema.js.map +1 -0
- package/src/lib/form/insert-form-submit.d.ts +79 -0
- package/src/lib/form/insert-form-submit.d.ts.map +1 -0
- package/src/lib/form/insert-form-submit.js +126 -0
- package/src/lib/form/insert-form-submit.js.map +1 -0
- package/src/lib/form/insert-form.d.ts +39 -0
- package/src/lib/form/insert-form.d.ts.map +1 -0
- package/src/lib/form/insert-form.js +255 -0
- package/src/lib/form/insert-form.js.map +1 -0
- package/src/lib/form/insert-select-form-tree.d.ts +33 -0
- package/src/lib/form/insert-select-form-tree.d.ts.map +1 -0
- package/src/lib/form/insert-select-form-tree.js +144 -0
- package/src/lib/form/insert-select-form-tree.js.map +1 -0
- package/src/lib/form/insert-sub-form-field.d.ts +17 -0
- package/src/lib/form/insert-sub-form-field.d.ts.map +1 -0
- package/src/lib/form/insert-sub-form-field.js +41 -0
- package/src/lib/form/insert-sub-form-field.js.map +1 -0
- package/src/lib/form/make-form-tree-insert.d.ts +22 -0
- package/src/lib/form/make-form-tree-insert.d.ts.map +1 -0
- package/src/lib/form/make-form-tree-insert.js +43 -0
- package/src/lib/form/make-form-tree-insert.js.map +1 -0
- package/src/lib/form/target-form-field.d.ts +11 -0
- package/src/lib/form/target-form-field.d.ts.map +1 -0
- package/src/lib/form/target-form-field.js +1 -0
- package/src/lib/form/target-form-field.js.map +1 -0
- package/src/lib/form/validator.d.ts +174 -0
- package/src/lib/form/validator.d.ts.map +1 -0
- package/src/lib/form/validator.js +465 -0
- package/src/lib/form/validator.js.map +1 -0
- package/src/lib/from-event-to-source$.d.ts +210 -0
- package/src/lib/from-event-to-source$.d.ts.map +1 -0
- package/src/lib/from-event-to-source$.js +29 -0
- package/src/lib/from-event-to-source$.js.map +1 -0
- package/src/lib/global-persister-handler.service.d.ts +10 -0
- package/src/lib/global-persister-handler.service.d.ts.map +1 -0
- package/src/lib/global-persister-handler.service.js +40 -0
- package/src/lib/global-persister-handler.service.js.map +1 -0
- package/src/lib/host/craft-compat.d.ts +242 -0
- package/src/lib/host/craft-compat.d.ts.map +1 -0
- package/src/lib/host/craft-compat.js +444 -0
- package/src/lib/host/craft-compat.js.map +1 -0
- package/src/lib/host/craft-dom.d.ts +16 -0
- package/src/lib/host/craft-dom.d.ts.map +1 -0
- package/src/lib/host/craft-dom.js +24 -0
- package/src/lib/host/craft-dom.js.map +1 -0
- package/src/lib/host/craft-http.d.ts +22 -0
- package/src/lib/host/craft-http.d.ts.map +1 -0
- package/src/lib/host/craft-http.js +80 -0
- package/src/lib/host/craft-http.js.map +1 -0
- package/src/lib/host/craft-injector-host.d.ts +3 -0
- package/src/lib/host/craft-injector-host.d.ts.map +1 -0
- package/src/lib/host/craft-injector-host.js +2 -0
- package/src/lib/host/craft-injector-host.js.map +1 -0
- package/src/lib/host/craft-injector.d.ts +40 -0
- package/src/lib/host/craft-injector.d.ts.map +1 -0
- package/src/lib/host/craft-injector.js +318 -0
- package/src/lib/host/craft-injector.js.map +1 -0
- package/src/lib/host/craft-linked-signal.d.ts +17 -0
- package/src/lib/host/craft-linked-signal.d.ts.map +1 -0
- package/src/lib/host/craft-linked-signal.js +86 -0
- package/src/lib/host/craft-linked-signal.js.map +1 -0
- package/src/lib/host/craft-router-runtime.d.ts +61 -0
- package/src/lib/host/craft-router-runtime.d.ts.map +1 -0
- package/src/lib/host/craft-router-runtime.js +456 -0
- package/src/lib/host/craft-router-runtime.js.map +1 -0
- package/src/lib/host/craft-router-types.d.ts +84 -0
- package/src/lib/host/craft-router-types.d.ts.map +1 -0
- package/src/lib/host/craft-router-types.js +35 -0
- package/src/lib/host/craft-router-types.js.map +1 -0
- package/src/lib/host/craft-signal.d.ts +45 -0
- package/src/lib/host/craft-signal.d.ts.map +1 -0
- package/src/lib/host/craft-signal.js +161 -0
- package/src/lib/host/craft-signal.js.map +1 -0
- package/src/lib/host/craft-test-bed.d.ts +63 -0
- package/src/lib/host/craft-test-bed.d.ts.map +1 -0
- package/src/lib/host/craft-test-bed.js +114 -0
- package/src/lib/host/craft-test-bed.js.map +1 -0
- package/src/lib/host-tag.d.ts +2 -0
- package/src/lib/host-tag.d.ts.map +1 -0
- package/src/lib/host-tag.js +2 -0
- package/src/lib/host-tag.js.map +1 -0
- package/src/lib/insert-entities.d.ts +131 -0
- package/src/lib/insert-entities.d.ts.map +1 -0
- package/src/lib/insert-entities.js +159 -0
- package/src/lib/insert-entities.js.map +1 -0
- package/src/lib/insert-noop-typing-anchor.d.ts +15 -0
- package/src/lib/insert-noop-typing-anchor.d.ts.map +1 -0
- package/src/lib/insert-noop-typing-anchor.js +16 -0
- package/src/lib/insert-noop-typing-anchor.js.map +1 -0
- package/src/lib/insert-pagination-placeholder-data.d.ts +122 -0
- package/src/lib/insert-pagination-placeholder-data.d.ts.map +1 -0
- package/src/lib/insert-pagination-placeholder-data.js +244 -0
- package/src/lib/insert-pagination-placeholder-data.js.map +1 -0
- package/src/lib/insert-react-on-mutation.d.ts +261 -0
- package/src/lib/insert-react-on-mutation.d.ts.map +1 -0
- package/src/lib/insert-react-on-mutation.js +227 -0
- package/src/lib/insert-react-on-mutation.js.map +1 -0
- package/src/lib/insert-select-resource.d.ts +31 -0
- package/src/lib/insert-select-resource.d.ts.map +1 -0
- package/src/lib/insert-select-resource.js +27 -0
- package/src/lib/insert-select-resource.js.map +1 -0
- package/src/lib/insert-select.d.ts +126 -0
- package/src/lib/insert-select.d.ts.map +1 -0
- package/src/lib/insert-select.js +535 -0
- package/src/lib/insert-select.js.map +1 -0
- package/src/lib/insert-storage-persister.d.ts +27 -0
- package/src/lib/insert-storage-persister.d.ts.map +1 -0
- package/src/lib/insert-storage-persister.js +65 -0
- package/src/lib/insert-storage-persister.js.map +1 -0
- package/src/lib/insert-typed-pipes.d.ts +64 -0
- package/src/lib/insert-typed-pipes.d.ts.map +1 -0
- package/src/lib/insert-typed-pipes.js +32 -0
- package/src/lib/insert-typed-pipes.js.map +1 -0
- package/src/lib/linked-source.d.ts +8 -0
- package/src/lib/linked-source.d.ts.map +1 -0
- package/src/lib/linked-source.js +24 -0
- package/src/lib/linked-source.js.map +1 -0
- package/src/lib/local-storage-persister.d.ts +4 -0
- package/src/lib/local-storage-persister.d.ts.map +1 -0
- package/src/lib/local-storage-persister.js +342 -0
- package/src/lib/local-storage-persister.js.map +1 -0
- package/src/lib/middleware-schema-shared.d.ts +67 -0
- package/src/lib/middleware-schema-shared.d.ts.map +1 -0
- package/src/lib/middleware-schema-shared.js +34 -0
- package/src/lib/middleware-schema-shared.js.map +1 -0
- package/src/lib/mock-http-request-for-route.d.ts +173 -0
- package/src/lib/mock-http-request-for-route.d.ts.map +1 -0
- package/src/lib/mock-http-request-for-route.js +127 -0
- package/src/lib/mock-http-request-for-route.js.map +1 -0
- package/src/lib/mutation.d.ts +332 -0
- package/src/lib/mutation.d.ts.map +1 -0
- package/src/lib/mutation.js +923 -0
- package/src/lib/mutation.js.map +1 -0
- package/src/lib/on$.d.ts +26 -0
- package/src/lib/on$.d.ts.map +1 -0
- package/src/lib/on$.js +19 -0
- package/src/lib/on$.js.map +1 -0
- package/src/lib/portable-server-function.d.ts +68 -0
- package/src/lib/portable-server-function.d.ts.map +1 -0
- package/src/lib/portable-server-function.js +97 -0
- package/src/lib/portable-server-function.js.map +1 -0
- package/src/lib/preserved-resource.d.ts +4 -0
- package/src/lib/preserved-resource.d.ts.map +1 -0
- package/src/lib/preserved-resource.js +60 -0
- package/src/lib/preserved-resource.js.map +1 -0
- package/src/lib/primitive-method-runtime-context.d.ts +28 -0
- package/src/lib/primitive-method-runtime-context.d.ts.map +1 -0
- package/src/lib/primitive-method-runtime-context.js +38 -0
- package/src/lib/primitive-method-runtime-context.js.map +1 -0
- package/src/lib/primitive-resource-runtime-context.d.ts +46 -0
- package/src/lib/primitive-resource-runtime-context.d.ts.map +1 -0
- package/src/lib/primitive-resource-runtime-context.js +102 -0
- package/src/lib/primitive-resource-runtime-context.js.map +1 -0
- package/src/lib/query-params.d.ts +216 -0
- package/src/lib/query-params.d.ts.map +1 -0
- package/src/lib/query-params.js +324 -0
- package/src/lib/query-params.js.map +1 -0
- package/src/lib/query.core.d.ts +214 -0
- package/src/lib/query.core.d.ts.map +1 -0
- package/src/lib/query.core.js +210 -0
- package/src/lib/query.core.js.map +1 -0
- package/src/lib/query.d.ts +324 -0
- package/src/lib/query.d.ts.map +1 -0
- package/src/lib/query.js +971 -0
- package/src/lib/query.js.map +1 -0
- package/src/lib/reactive-read.d.ts +162 -0
- package/src/lib/reactive-read.d.ts.map +1 -0
- package/src/lib/reactive-read.js +389 -0
- package/src/lib/reactive-read.js.map +1 -0
- package/src/lib/resource-by-id.d.ts +71 -0
- package/src/lib/resource-by-id.d.ts.map +1 -0
- package/src/lib/resource-by-id.js +294 -0
- package/src/lib/resource-by-id.js.map +1 -0
- package/src/lib/resource-exception.d.ts +30 -0
- package/src/lib/resource-exception.d.ts.map +1 -0
- package/src/lib/resource-exception.js +86 -0
- package/src/lib/resource-exception.js.map +1 -0
- package/src/lib/route-checked-di.d.ts +229 -0
- package/src/lib/route-checked-di.d.ts.map +1 -0
- package/src/lib/route-checked-di.js +1 -0
- package/src/lib/route-checked-di.js.map +1 -0
- package/src/lib/schema-validation.d.ts +89 -0
- package/src/lib/schema-validation.d.ts.map +1 -0
- package/src/lib/schema-validation.js +110 -0
- package/src/lib/schema-validation.js.map +1 -0
- package/src/lib/send-context-to-ai.d.ts +20 -0
- package/src/lib/send-context-to-ai.d.ts.map +1 -0
- package/src/lib/send-context-to-ai.js +18 -0
- package/src/lib/send-context-to-ai.js.map +1 -0
- package/src/lib/send-context-to-ai.tokens.d.ts +12 -0
- package/src/lib/send-context-to-ai.tokens.d.ts.map +1 -0
- package/src/lib/send-context-to-ai.tokens.js +1 -0
- package/src/lib/send-context-to-ai.tokens.js.map +1 -0
- package/src/lib/server-function-client.d.ts +102 -0
- package/src/lib/server-function-client.d.ts.map +1 -0
- package/src/lib/server-function-client.js +106 -0
- package/src/lib/server-function-client.js.map +1 -0
- package/src/lib/server-function-contract.d.ts +42 -0
- package/src/lib/server-function-contract.d.ts.map +1 -0
- package/src/lib/server-function-contract.js +23 -0
- package/src/lib/server-function-contract.js.map +1 -0
- package/src/lib/server-function-middleware.d.ts +222 -0
- package/src/lib/server-function-middleware.d.ts.map +1 -0
- package/src/lib/server-function-middleware.js +189 -0
- package/src/lib/server-function-middleware.js.map +1 -0
- package/src/lib/server-function.d.ts +114 -0
- package/src/lib/server-function.d.ts.map +1 -0
- package/src/lib/server-function.js +80 -0
- package/src/lib/server-function.js.map +1 -0
- package/src/lib/server-layer.d.ts +185 -0
- package/src/lib/server-layer.d.ts.map +1 -0
- package/src/lib/server-layer.js +121 -0
- package/src/lib/server-layer.js.map +1 -0
- package/src/lib/server.d.ts +83 -0
- package/src/lib/server.d.ts.map +1 -0
- package/src/lib/server.js +266 -0
- package/src/lib/server.js.map +1 -0
- package/src/lib/setup-craft-service-test.d.ts +90 -0
- package/src/lib/setup-craft-service-test.d.ts.map +1 -0
- package/src/lib/setup-craft-service-test.js +193 -0
- package/src/lib/setup-craft-service-test.js.map +1 -0
- package/src/lib/setup-craft-service-testing-by-register.d.ts +245 -0
- package/src/lib/setup-craft-service-testing-by-register.d.ts.map +1 -0
- package/src/lib/setup-craft-service-testing-by-register.js +316 -0
- package/src/lib/setup-craft-service-testing-by-register.js.map +1 -0
- package/src/lib/signal-proxy.d.ts +21 -0
- package/src/lib/signal-proxy.d.ts.map +1 -0
- package/src/lib/signal-proxy.js +79 -0
- package/src/lib/signal-proxy.js.map +1 -0
- package/src/lib/signal-source.d.ts +392 -0
- package/src/lib/signal-source.d.ts.map +1 -0
- package/src/lib/signal-source.js +433 -0
- package/src/lib/signal-source.js.map +1 -0
- package/src/lib/source$.d.ts +121 -0
- package/src/lib/source$.d.ts.map +1 -0
- package/src/lib/source$.js +171 -0
- package/src/lib/source$.js.map +1 -0
- package/src/lib/source-from-event.d.ts +350 -0
- package/src/lib/source-from-event.d.ts.map +1 -0
- package/src/lib/source-from-event.js +26 -0
- package/src/lib/source-from-event.js.map +1 -0
- package/src/lib/stacked-source.d.ts +6 -0
- package/src/lib/stacked-source.d.ts.map +1 -0
- package/src/lib/stacked-source.js +29 -0
- package/src/lib/stacked-source.js.map +1 -0
- package/src/lib/standard-schema.d.ts +43 -0
- package/src/lib/standard-schema.d.ts.map +1 -0
- package/src/lib/standard-schema.js +1 -0
- package/src/lib/standard-schema.js.map +1 -0
- package/src/lib/state-method-runtime-context.d.ts +13 -0
- package/src/lib/state-method-runtime-context.d.ts.map +1 -0
- package/src/lib/state-method-runtime-context.js +11 -0
- package/src/lib/state-method-runtime-context.js.map +1 -0
- package/src/lib/state.d.ts +158 -0
- package/src/lib/state.d.ts.map +1 -0
- package/src/lib/state.js +388 -0
- package/src/lib/state.js.map +1 -0
- package/src/lib/storage-persister.service.d.ts +25 -0
- package/src/lib/storage-persister.service.d.ts.map +1 -0
- package/src/lib/storage-persister.service.js +27 -0
- package/src/lib/storage-persister.service.js.map +1 -0
- package/src/lib/take-app-snapshot.d.ts +31 -0
- package/src/lib/take-app-snapshot.d.ts.map +1 -0
- package/src/lib/take-app-snapshot.js +93 -0
- package/src/lib/take-app-snapshot.js.map +1 -0
- package/src/lib/template-trace.d.ts +37 -0
- package/src/lib/template-trace.d.ts.map +1 -0
- package/src/lib/template-trace.js +37 -0
- package/src/lib/template-trace.js.map +1 -0
- package/src/lib/temporal-runtime.d.ts +146 -0
- package/src/lib/temporal-runtime.d.ts.map +1 -0
- package/src/lib/temporal-runtime.js +375 -0
- package/src/lib/temporal-runtime.js.map +1 -0
- package/src/lib/to-source.d.ts +335 -0
- package/src/lib/to-source.d.ts.map +1 -0
- package/src/lib/to-source.js +359 -0
- package/src/lib/to-source.js.map +1 -0
- package/src/lib/util/craft-resource-ref.d.ts +29 -0
- package/src/lib/util/craft-resource-ref.d.ts.map +1 -0
- package/src/lib/util/craft-resource-ref.js +1 -0
- package/src/lib/util/craft-resource-ref.js.map +1 -0
- package/src/lib/util/craft-resource-status.d.ts +17 -0
- package/src/lib/util/craft-resource-status.d.ts.map +1 -0
- package/src/lib/util/craft-resource-status.js +14 -0
- package/src/lib/util/craft-resource-status.js.map +1 -0
- package/src/lib/util/entities-util.d.ts +340 -0
- package/src/lib/util/entities-util.d.ts.map +1 -0
- package/src/lib/util/entities-util.js +136 -0
- package/src/lib/util/entities-util.js.map +1 -0
- package/src/lib/util/explicit-effect.d.ts +42 -0
- package/src/lib/util/explicit-effect.d.ts.map +1 -0
- package/src/lib/util/explicit-effect.js +37 -0
- package/src/lib/util/explicit-effect.js.map +1 -0
- package/src/lib/util/extract-signal-props-and-methods.d.ts +20 -0
- package/src/lib/util/extract-signal-props-and-methods.d.ts.map +1 -0
- package/src/lib/util/extract-signal-props-and-methods.js +1 -0
- package/src/lib/util/extract-signal-props-and-methods.js.map +1 -0
- package/src/lib/util/method-trigger-nonce.d.ts +45 -0
- package/src/lib/util/method-trigger-nonce.d.ts.map +1 -0
- package/src/lib/util/method-trigger-nonce.js +58 -0
- package/src/lib/util/method-trigger-nonce.js.map +1 -0
- package/src/lib/util/persister.type.d.ts +37 -0
- package/src/lib/util/persister.type.d.ts.map +1 -0
- package/src/lib/util/persister.type.js +1 -0
- package/src/lib/util/persister.type.js.map +1 -0
- package/src/lib/util/persister.util.d.ts +8 -0
- package/src/lib/util/persister.util.d.ts.map +1 -0
- package/src/lib/util/persister.util.js +71 -0
- package/src/lib/util/persister.util.js.map +1 -0
- package/src/lib/util/react-on-mutation-effect.d.ts +16 -0
- package/src/lib/util/react-on-mutation-effect.d.ts.map +1 -0
- package/src/lib/util/react-on-mutation-effect.js +148 -0
- package/src/lib/util/react-on-mutation-effect.js.map +1 -0
- package/src/lib/util/resource-by-id-changes-tracker.util.d.ts +27 -0
- package/src/lib/util/resource-by-id-changes-tracker.util.d.ts.map +1 -0
- package/src/lib/util/resource-by-id-changes-tracker.util.js +97 -0
- package/src/lib/util/resource-by-id-changes-tracker.util.js.map +1 -0
- package/src/lib/util/source.type.d.ts +6 -0
- package/src/lib/util/source.type.d.ts.map +1 -0
- package/src/lib/util/source.type.js +1 -0
- package/src/lib/util/source.type.js.map +1 -0
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.d.ts +4 -0
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.d.ts.map +1 -0
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.js +1 -0
- package/src/lib/util/types/access-type-object-property-by-dotted-path.type.js.map +1 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.d.ts +27 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.d.ts.map +1 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.js +1 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path-by-id.type.js.map +1 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.d.ts +24 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.d.ts.map +1 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.js +1 -0
- package/src/lib/util/types/boolean-or-mapper-fn-by-path.type.js.map +1 -0
- package/src/lib/util/types/brand.d.ts +7 -0
- package/src/lib/util/types/brand.d.ts.map +1 -0
- package/src/lib/util/types/brand.js +9 -0
- package/src/lib/util/types/brand.js.map +1 -0
- package/src/lib/util/types/object-deep-path-mapper.type.d.ts +13 -0
- package/src/lib/util/types/object-deep-path-mapper.type.d.ts.map +1 -0
- package/src/lib/util/types/object-deep-path-mapper.type.js +1 -0
- package/src/lib/util/types/object-deep-path-mapper.type.js.map +1 -0
- package/src/lib/util/types/resource-by-id-config.type.d.ts +115 -0
- package/src/lib/util/types/resource-by-id-config.type.d.ts.map +1 -0
- package/src/lib/util/types/resource-by-id-config.type.js +1 -0
- package/src/lib/util/types/resource-by-id-config.type.js.map +1 -0
- package/src/lib/util/types/resource-with-params-or-params-fn.type.d.ts +52 -0
- package/src/lib/util/types/resource-with-params-or-params-fn.type.d.ts.map +1 -0
- package/src/lib/util/types/resource-with-params-or-params-fn.type.js +1 -0
- package/src/lib/util/types/resource-with-params-or-params-fn.type.js.map +1 -0
- package/src/lib/util/types/shared.type.d.ts +66 -0
- package/src/lib/util/types/shared.type.d.ts.map +1 -0
- package/src/lib/util/types/shared.type.js +1 -0
- package/src/lib/util/types/shared.type.js.map +1 -0
- package/src/lib/util/types/util.d.ts +16 -0
- package/src/lib/util/types/util.d.ts.map +1 -0
- package/src/lib/util/types/util.js +60 -0
- package/src/lib/util/types/util.js.map +1 -0
- package/src/lib/util/types/util.type.d.ts +67 -0
- package/src/lib/util/types/util.type.d.ts.map +1 -0
- package/src/lib/util/types/util.type.js +5 -0
- package/src/lib/util/types/util.type.js.map +1 -0
- package/src/lib/util/update-state.util.d.ts +10 -0
- package/src/lib/util/update-state.util.d.ts.map +1 -0
- package/src/lib/util/update-state.util.js +31 -0
- package/src/lib/util/update-state.util.js.map +1 -0
- package/src/lib/util/util.d.ts +19 -0
- package/src/lib/util/util.d.ts.map +1 -0
- package/src/lib/util/util.js +50 -0
- package/src/lib/util/util.js.map +1 -0
- package/src/lib/util/util.type.d.ts +107 -0
- package/src/lib/util/util.type.d.ts.map +1 -0
- package/src/lib/util/util.type.js +9 -0
- package/src/lib/util/util.type.js.map +1 -0
- package/src/lib/yieldable.d.ts +94 -0
- package/src/lib/yieldable.d.ts.map +1 -0
- package/src/lib/yieldable.js +109 -0
- package/src/lib/yieldable.js.map +1 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { inject } from './host/craft-compat';
|
|
2
|
+
import { craftException } from './craft-exception';
|
|
3
|
+
import { craftGen } from './craft-gen';
|
|
4
|
+
import { GUARD_AWAIT_REQUEST_MARKER, } from './craft-generator-runtime';
|
|
5
|
+
import { createRetryLazyLoadHelpers, CRAFT_DYNAMIC_IMPORT, CRAFT_LAZY_LOAD_RETRY, INITIAL_LAZY_LOAD_HELPERS, } from './craft-load-retry';
|
|
6
|
+
export const CRAFT_LAZY_LOAD_ERROR_CODE = 'CRAFT_LAZY_LOAD_ERROR';
|
|
7
|
+
/** Builds the `craftException` `craftLazy` returns when an import finally fails. */
|
|
8
|
+
export function createCraftLazyLoadError(cause) {
|
|
9
|
+
return craftException({ _tag: CRAFT_LAZY_LOAD_ERROR_CODE, scope: 'CraftLazy' }, { cause });
|
|
10
|
+
}
|
|
11
|
+
function guardAwaitPromise(value) {
|
|
12
|
+
return {
|
|
13
|
+
[GUARD_AWAIT_REQUEST_MARKER]: true,
|
|
14
|
+
kind: 'promise',
|
|
15
|
+
value,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Runs a lazy import with the shared retry engine. The first attempt uses the
|
|
20
|
+
* identity helpers; on failure it re-invokes the loader up to the configured
|
|
21
|
+
* attempts with cache-busting helpers. Outside an Angular injection context
|
|
22
|
+
* (e.g. a hand-driven test) it degrades to a single attempt and rethrows.
|
|
23
|
+
*/
|
|
24
|
+
function injectLazyLoad() {
|
|
25
|
+
let deps;
|
|
26
|
+
try {
|
|
27
|
+
deps = {
|
|
28
|
+
retry: inject(CRAFT_LAZY_LOAD_RETRY),
|
|
29
|
+
dynamicImport: inject(CRAFT_DYNAMIC_IMPORT),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// No injection context — keep the loader's original single-attempt semantics.
|
|
34
|
+
}
|
|
35
|
+
return async (load) => {
|
|
36
|
+
try {
|
|
37
|
+
return await load(INITIAL_LAZY_LOAD_HELPERS);
|
|
38
|
+
}
|
|
39
|
+
catch (firstError) {
|
|
40
|
+
if (!deps)
|
|
41
|
+
throw firstError;
|
|
42
|
+
const retryHelpers = createRetryLazyLoadHelpers(deps.dynamicImport);
|
|
43
|
+
return deps.retry.execute(() => load(retryHelpers), {
|
|
44
|
+
attempt: 1,
|
|
45
|
+
error: firstError,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Lazily imports a module from inside an `asyncProcess` loader, reusing the same
|
|
52
|
+
* retry/cache-busting engine as route lazy loading (`loadComponent`).
|
|
53
|
+
*
|
|
54
|
+
* `craftLazy(load)` is a `craftGen`-built program: `yield*`-composable inside an
|
|
55
|
+
* async craft loader, `.pipe(...)`-able (so `catchTag('CRAFT_LAZY_LOAD_ERROR', …)`
|
|
56
|
+
* applies directly), and it awaits the import through the async program pump. On
|
|
57
|
+
* a final import failure it returns a {@link CraftLazyLoadError} `craftException`,
|
|
58
|
+
* which `craftGen` surfaces as a short-circuit → the enclosing resource's
|
|
59
|
+
* `status()` becomes `'exception'`.
|
|
60
|
+
*
|
|
61
|
+
* It must run in an async driver (an `asyncProcess` loader); it cannot be
|
|
62
|
+
* `yield*`-ed from a synchronous `craftMethod`, whose driver throws on the
|
|
63
|
+
* await-request. A `craftMethod` may only *trigger* the enclosing `asyncProcess`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const searchProcess = craftUse(asyncProcess({
|
|
68
|
+
* method: on$(prefetch$, () => undefined),
|
|
69
|
+
* loader: function* () {
|
|
70
|
+
* return yield* craftLazy(({ withRetry }) => withRetry(import('./search')));
|
|
71
|
+
* },
|
|
72
|
+
* }));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function craftLazy(load) {
|
|
76
|
+
const invoke = craftGen(function* () {
|
|
77
|
+
const runLoad = injectLazyLoad();
|
|
78
|
+
const settled = runLoad(load).then((value) => value, (cause) => createCraftLazyLoadError(cause));
|
|
79
|
+
return (yield guardAwaitPromise(settled));
|
|
80
|
+
});
|
|
81
|
+
return invoke();
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=craft-lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"craft-lazy.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/craft-lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAA2B,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,0BAA0B,GAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,GAG1B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,0BAA0B,GAAG,uBAAgC,CAAC;AAM3E,oFAAoF;AACpF,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,OAAO,cAAc,CACnB,EAAE,IAAI,EAAE,0BAA0B,EAAE,KAAK,EAAE,WAAW,EAAE,EACxD,EAAE,KAAK,EAAsC,CAC9C,CAAC;AACJ,CAAC;AAID,SAAS,iBAAiB,CAAC,KAA2B;IACpD,OAAO;QACL,CAAC,0BAA0B,CAAC,EAAE,IAAI;QAClC,IAAI,EAAE,SAAS;QACf,KAAK;KACsB,CAAC;AAChC,CAAC;AA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port { craftException } from './craft-exception';\nimport { craftGen, type CraftGenInvocation } from './craft-gen';\nimport {\n GUARD_AWAIT_REQUEST_MARKER,\n type RuntimeGuardAwaitRequest,\n} from './craft-generator-runtime';\nimport {\n createRetryLazyLoadHelpers,\n CRAFT_DYNAMIC_IMPORT,\n CRAFT_LAZY_LOAD_RETRY,\n INITIAL_LAZY_LOAD_HELPERS,\n type CraftLazyLoadHelpers,\n type CraftLoadRetry,\n} from './craft-load-retry';\n\nexport const CRAFT_LAZY_LOAD_ERROR_CODE = 'CRAFT_LAZY_LOAD_ERROR' as const;\n\nexport interface CraftLazyLoadErrorPayload {\n readonly cause: unknown;\n}\n\n/** Builds the `craftException` `craftLazy` returns when an import finally fails. */\nexport function createCraftLazyLoadError(cause: unknown) {\n return craftException(\n { _tag: CRAFT_LAZY_LOAD_ERROR_CODE, scope: 'CraftLazy' },\n { cause } satisfies CraftLazyLoadErrorPayload,\n );\n}\n\nexport type CraftLazyLoadError = ReturnType<typeof createCraftLazyLoadError>;\n\nfunction guardAwaitPromise(value: PromiseLike<unknown>): RuntimeGuardAwaitRequest {\n return {\n [GUARD_AWAIT_REQUEST_MARKER]: true,\n kind: 'promise',\n value,\n } as RuntimeGuardAwaitRequest;\n}\n\n/**\n * Runs a lazy import with the shared retry engine. The first attempt uses the\n * identity helpers; on failure it re-invokes the loader up to the configured\n * attempts with cache-busting helpers. Outside an Angular injection context\n * (e.g. a hand-driven test) it degrades to a single attempt and rethrows.\n */\nfunction injectLazyLoad(): <T>(\n load: (helpers: CraftLazyLoadHelpers) => Promise<T>,\n) => Promise<T> {\n let deps:\n | { retry: CraftLoadRetry; dynamicImport: (url: string) => Promise<unknown> }\n | undefined;\n try {\n deps = {\n retry: inject(CRAFT_LAZY_LOAD_RETRY),\n dynamicImport: inject(CRAFT_DYNAMIC_IMPORT),\n };\n } catch {\n // No injection context — keep the loader's original single-attempt semantics.\n }\n\n return async <T>(load: (helpers: CraftLazyLoadHelpers) => Promise<T>) => {\n try {\n return await load(INITIAL_LAZY_LOAD_HELPERS);\n } catch (firstError) {\n if (!deps) throw firstError;\n\n const retryHelpers = createRetryLazyLoadHelpers(deps.dynamicImport);\n return deps.retry.execute(() => load(retryHelpers), {\n attempt: 1,\n error: firstError,\n });\n }\n };\n}\n\n/**\n * Lazily imports a module from inside an `asyncProcess` loader, reusing the same\n * retry/cache-busting engine as route lazy loading (`loadComponent`).\n *\n * `craftLazy(load)` is a `craftGen`-built program: `yield*`-composable inside an\n * async craft loader, `.pipe(...)`-able (so `catchTag('CRAFT_LAZY_LOAD_ERROR', …)`\n * applies directly), and it awaits the import through the async program pump. On\n * a final import failure it returns a {@link CraftLazyLoadError} `craftException`,\n * which `craftGen` surfaces as a short-circuit → the enclosing resource's\n * `status()` becomes `'exception'`.\n *\n * It must run in an async driver (an `asyncProcess` loader); it cannot be\n * `yield*`-ed from a synchronous `craftMethod`, whose driver throws on the\n * await-request. A `craftMethod` may only *trigger* the enclosing `asyncProcess`.\n *\n * @example\n * ```ts\n * const searchProcess = craftUse(asyncProcess({\n * method: on$(prefetch$, () => undefined),\n * loader: function* () {\n * return yield* craftLazy(({ withRetry }) => withRetry(import('./search')));\n * },\n * }));\n * ```\n */\nexport function craftLazy<T>(\n load: (helpers: CraftLazyLoadHelpers) => Promise<T>,\n): CraftGenInvocation<never, T | CraftLazyLoadError> {\n const invoke = craftGen(function* (): Generator<\n RuntimeGuardAwaitRequest,\n T | CraftLazyLoadError,\n unknown\n > {\n const runLoad = injectLazyLoad();\n const settled: Promise<T | CraftLazyLoadError> = runLoad(load).then(\n (value) => value,\n (cause) => createCraftLazyLoadError(cause),\n );\n\n return (yield guardAwaitPromise(settled)) as T | CraftLazyLoadError;\n });\n\n return invoke() as unknown as CraftGenInvocation<never, T | CraftLazyLoadError>;\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { InjectionToken, type Type } from './host/craft-compat';
|
|
2
|
+
import { type CraftTemporalRuntime } from './temporal-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* The `{ withRetry }` helpers handed to a lazy loader callback. `withRetry`
|
|
5
|
+
* wraps a dynamic `import(...)` so a chunk whose hashed URL went stale after a
|
|
6
|
+
* redeploy is re-fetched with a cache-busting query param. On the very first
|
|
7
|
+
* attempt it is the identity function; the retry engine swaps in the
|
|
8
|
+
* cache-busting variant for subsequent attempts.
|
|
9
|
+
*/
|
|
10
|
+
export interface CraftLazyLoadHelpers {
|
|
11
|
+
withRetry<T>(moduleImport: Promise<T>): Promise<T>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The injectable dynamic `import(url)`. Overridable in tests to observe the
|
|
15
|
+
* cache-busting URL {@link retryFailedDynamicImport} computes.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CRAFT_DYNAMIC_IMPORT: InjectionToken<(url: string) => Promise<unknown>>;
|
|
18
|
+
/** The base fields the retry loop itself reads and advances on every attempt. */
|
|
19
|
+
export interface CraftLoadRetryContextBase {
|
|
20
|
+
readonly attempt: number;
|
|
21
|
+
readonly error: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface CraftLoadRetry<Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase> {
|
|
24
|
+
execute<T>(loader: () => Promise<T>, context: Context): Promise<T>;
|
|
25
|
+
}
|
|
26
|
+
export interface CraftLoadRetryOptions<Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase> {
|
|
27
|
+
readonly attempts?: number;
|
|
28
|
+
readonly delayMs?: number | ((error: unknown, context: Context) => number);
|
|
29
|
+
readonly shouldRetry?: (error: unknown, context: Context) => boolean | Promise<boolean>;
|
|
30
|
+
/** Optional clock seam, primarily useful for deterministic tests. */
|
|
31
|
+
readonly temporalRuntime?: CraftTemporalRuntime;
|
|
32
|
+
}
|
|
33
|
+
export type CraftLoadRetryConfig<Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase> = CraftLoadRetry<Context> | Type<CraftLoadRetry<Context>> | CraftLoadRetryOptions<Context>;
|
|
34
|
+
export declare const DEFAULT_CRAFT_LOAD_RETRY_OPTIONS: {
|
|
35
|
+
attempts: number;
|
|
36
|
+
delayMs: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Builds the attempts/delay/shouldRetry loop shared by every craft lazy load.
|
|
40
|
+
* `execute` re-invokes `loader` up to `attempts` times, threading the caller's
|
|
41
|
+
* `Context` (only `attempt` and `error` are advanced by the engine — the rest is
|
|
42
|
+
* spread through unchanged) into the `delayMs`/`shouldRetry` callbacks. On final
|
|
43
|
+
* exhaustion it rethrows the last raw failure (callers wrap it into a domain
|
|
44
|
+
* `craftException` — a route load error or a `craftLazy` load error).
|
|
45
|
+
*/
|
|
46
|
+
export declare function createCraftLoadRetry<Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase>(options?: CraftLoadRetryOptions<Context>): CraftLoadRetry<Context>;
|
|
47
|
+
/**
|
|
48
|
+
* The retry policy `craftLazy` applies to an imperative lazy import. Defaults to
|
|
49
|
+
* the shared attempts/delay loop; override it to tune attempts, back-off, or
|
|
50
|
+
* `shouldRetry` for `craftLazy` loads specifically.
|
|
51
|
+
*/
|
|
52
|
+
export declare const CRAFT_LAZY_LOAD_RETRY: InjectionToken<CraftLoadRetry<CraftLoadRetryContextBase>>;
|
|
53
|
+
export declare function provideCraftLazyLoadRetry(retry: CraftLoadRetryConfig): {
|
|
54
|
+
provide: typeof CRAFT_LAZY_LOAD_RETRY;
|
|
55
|
+
useValue: CraftLoadRetry;
|
|
56
|
+
} | {
|
|
57
|
+
provide: typeof CRAFT_LAZY_LOAD_RETRY;
|
|
58
|
+
useClass: Type<CraftLoadRetry>;
|
|
59
|
+
};
|
|
60
|
+
export declare function isCraftLoadRetry<Context extends CraftLoadRetryContextBase>(value: CraftLoadRetryConfig<Context>): value is CraftLoadRetry<Context>;
|
|
61
|
+
export declare function isCraftLoadRetryType<Context extends CraftLoadRetryContextBase>(value: CraftLoadRetryConfig<Context>): value is Type<CraftLoadRetry<Context>>;
|
|
62
|
+
/** The identity helpers used for the first (un-busted) load attempt. */
|
|
63
|
+
export declare const INITIAL_LAZY_LOAD_HELPERS: CraftLazyLoadHelpers;
|
|
64
|
+
/**
|
|
65
|
+
* Helpers whose `withRetry` re-fetches a failed chunk with a cache-busting
|
|
66
|
+
* query param, used for every attempt after the first.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createRetryLazyLoadHelpers(dynamicImport: (url: string) => Promise<unknown>, retryParam?: string): CraftLazyLoadHelpers;
|
|
69
|
+
/**
|
|
70
|
+
* Awaits `moduleImport`; if it fails because a dynamically-imported chunk could
|
|
71
|
+
* not be fetched (a stale hashed URL after a redeploy), re-imports the same URL
|
|
72
|
+
* with an incrementing cache-busting query param. Concurrent retries of the same
|
|
73
|
+
* URL share a single in-flight import.
|
|
74
|
+
*/
|
|
75
|
+
export declare function retryFailedDynamicImport<T>(moduleImport: Promise<T>, dynamicImport: (url: string) => Promise<unknown>, retryParam?: string): Promise<T>;
|
|
76
|
+
//# sourceMappingURL=craft-load-retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"craft-load-retry.d.ts","sourceRoot":"","sources":["../../../../../libs/core/src/lib/craft-load-retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AAmB5B;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpD;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uBACzB,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAIjC,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;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O,qBAAqB,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,GACnE;IAAE,OAAO,EAAE,OAAO,qBAAqB,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;CAAE,CAQ5E;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,yBAAyB,EACxE,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,GACnC,KAAK,IAAI,cAAc,CAAC,OAAO,CAAC,CAElC;AAED,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,yBAAyB,EAC5E,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,GACnC,KAAK,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAExC;AAED,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,EAAE,oBAEvC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAChD,UAAU,SAAsB,GAC/B,oBAAoB,CAKtB;AAOD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAAC,CAAC,EAC9C,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,EACxB,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAChD,UAAU,SAAsB,GAC/B,OAAO,CAAC,CAAC,CAAC,CAyBZ"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { inject, InjectionToken } from './host/craft-compat';
|
|
2
|
+
import { CRAFT_TEMPORAL_RUNTIME, RealCraftTemporalRuntime, } from './temporal-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* The injectable dynamic `import(url)`. Overridable in tests to observe the
|
|
5
|
+
* cache-busting URL {@link retryFailedDynamicImport} computes.
|
|
6
|
+
*/
|
|
7
|
+
export const CRAFT_DYNAMIC_IMPORT = new InjectionToken('CRAFT_DYNAMIC_IMPORT', {
|
|
8
|
+
providedIn: 'root',
|
|
9
|
+
factory: () => (url) => import(/* @vite-ignore */ url),
|
|
10
|
+
});
|
|
11
|
+
export const DEFAULT_CRAFT_LOAD_RETRY_OPTIONS = {
|
|
12
|
+
attempts: 1,
|
|
13
|
+
delayMs: 250,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Builds the attempts/delay/shouldRetry loop shared by every craft lazy load.
|
|
17
|
+
* `execute` re-invokes `loader` up to `attempts` times, threading the caller's
|
|
18
|
+
* `Context` (only `attempt` and `error` are advanced by the engine — the rest is
|
|
19
|
+
* spread through unchanged) into the `delayMs`/`shouldRetry` callbacks. On final
|
|
20
|
+
* exhaustion it rethrows the last raw failure (callers wrap it into a domain
|
|
21
|
+
* `craftException` — a route load error or a `craftLazy` load error).
|
|
22
|
+
*/
|
|
23
|
+
export function createCraftLoadRetry(options = {}) {
|
|
24
|
+
const attempts = Math.max(1, Math.floor(options.attempts ?? DEFAULT_CRAFT_LOAD_RETRY_OPTIONS.attempts));
|
|
25
|
+
const delayMs = options.delayMs ?? DEFAULT_CRAFT_LOAD_RETRY_OPTIONS.delayMs;
|
|
26
|
+
const temporalRuntime = options.temporalRuntime ??
|
|
27
|
+
tryInjectTemporalRuntime() ??
|
|
28
|
+
new RealCraftTemporalRuntime();
|
|
29
|
+
return {
|
|
30
|
+
async execute(loader, baseContext) {
|
|
31
|
+
let lastError;
|
|
32
|
+
let previousError = baseContext.error;
|
|
33
|
+
for (let index = 0; index < attempts; index++) {
|
|
34
|
+
const context = {
|
|
35
|
+
...baseContext,
|
|
36
|
+
attempt: baseContext.attempt + index + 1,
|
|
37
|
+
error: previousError,
|
|
38
|
+
};
|
|
39
|
+
const shouldRetry = options.shouldRetry?.(previousError, context) ?? true;
|
|
40
|
+
if (!(await shouldRetry))
|
|
41
|
+
throw previousError;
|
|
42
|
+
const resolvedDelayMs = Math.max(0, typeof delayMs === 'function'
|
|
43
|
+
? delayMs(previousError, context)
|
|
44
|
+
: delayMs);
|
|
45
|
+
if (resolvedDelayMs > 0) {
|
|
46
|
+
await temporalRuntime.sleep(resolvedDelayMs, {
|
|
47
|
+
kind: 'retry',
|
|
48
|
+
owner: 'craft-load-retry',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return await loader();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
lastError = error;
|
|
56
|
+
previousError = error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw lastError;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function tryInjectTemporalRuntime() {
|
|
64
|
+
try {
|
|
65
|
+
return inject(CRAFT_TEMPORAL_RUNTIME, { optional: true }) ?? undefined;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The retry policy `craftLazy` applies to an imperative lazy import. Defaults to
|
|
73
|
+
* the shared attempts/delay loop; override it to tune attempts, back-off, or
|
|
74
|
+
* `shouldRetry` for `craftLazy` loads specifically.
|
|
75
|
+
*/
|
|
76
|
+
export const CRAFT_LAZY_LOAD_RETRY = new InjectionToken('CRAFT_LAZY_LOAD_RETRY', { providedIn: 'root', factory: () => createCraftLoadRetry() });
|
|
77
|
+
export function provideCraftLazyLoadRetry(retry) {
|
|
78
|
+
if (isCraftLoadRetryType(retry)) {
|
|
79
|
+
return { provide: CRAFT_LAZY_LOAD_RETRY, useClass: retry };
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
provide: CRAFT_LAZY_LOAD_RETRY,
|
|
83
|
+
useValue: isCraftLoadRetry(retry) ? retry : createCraftLoadRetry(retry),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function isCraftLoadRetry(value) {
|
|
87
|
+
return typeof value.execute === 'function';
|
|
88
|
+
}
|
|
89
|
+
export function isCraftLoadRetryType(value) {
|
|
90
|
+
return typeof value === 'function';
|
|
91
|
+
}
|
|
92
|
+
/** The identity helpers used for the first (un-busted) load attempt. */
|
|
93
|
+
export const INITIAL_LAZY_LOAD_HELPERS = {
|
|
94
|
+
withRetry: (moduleImport) => moduleImport,
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Helpers whose `withRetry` re-fetches a failed chunk with a cache-busting
|
|
98
|
+
* query param, used for every attempt after the first.
|
|
99
|
+
*/
|
|
100
|
+
export function createRetryLazyLoadHelpers(dynamicImport, retryParam = DEFAULT_RETRY_PARAM) {
|
|
101
|
+
return {
|
|
102
|
+
withRetry: (moduleImport) => retryFailedDynamicImport(moduleImport, dynamicImport, retryParam),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const DEFAULT_RETRY_PARAM = '__craft_retry';
|
|
106
|
+
const successfulRetriedImports = new Map();
|
|
107
|
+
const retryImportAttempts = new Map();
|
|
108
|
+
/**
|
|
109
|
+
* Awaits `moduleImport`; if it fails because a dynamically-imported chunk could
|
|
110
|
+
* not be fetched (a stale hashed URL after a redeploy), re-imports the same URL
|
|
111
|
+
* with an incrementing cache-busting query param. Concurrent retries of the same
|
|
112
|
+
* URL share a single in-flight import.
|
|
113
|
+
*/
|
|
114
|
+
export async function retryFailedDynamicImport(moduleImport, dynamicImport, retryParam = DEFAULT_RETRY_PARAM) {
|
|
115
|
+
try {
|
|
116
|
+
return await moduleImport;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
const failedUrl = failedDynamicImportUrl(error);
|
|
120
|
+
if (!failedUrl)
|
|
121
|
+
throw error;
|
|
122
|
+
const baseUrl = failedUrl.href;
|
|
123
|
+
const cachedRetry = successfulRetriedImports.get(baseUrl);
|
|
124
|
+
if (cachedRetry)
|
|
125
|
+
return cachedRetry;
|
|
126
|
+
const attempt = (retryImportAttempts.get(baseUrl) ?? 0) + 1;
|
|
127
|
+
retryImportAttempts.set(baseUrl, attempt);
|
|
128
|
+
failedUrl.searchParams.set(retryParam, String(attempt));
|
|
129
|
+
const retriedImport = dynamicImport(failedUrl.href);
|
|
130
|
+
successfulRetriedImports.set(baseUrl, retriedImport);
|
|
131
|
+
try {
|
|
132
|
+
return await retriedImport;
|
|
133
|
+
}
|
|
134
|
+
catch (retryError) {
|
|
135
|
+
successfulRetriedImports.delete(baseUrl);
|
|
136
|
+
throw retryError;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function failedDynamicImportUrl(error) {
|
|
141
|
+
if (!(error instanceof Error))
|
|
142
|
+
return undefined;
|
|
143
|
+
const prefix = 'Failed to fetch dynamically imported module:';
|
|
144
|
+
const prefixIndex = error.message.indexOf(prefix);
|
|
145
|
+
if (prefixIndex === -1)
|
|
146
|
+
return undefined;
|
|
147
|
+
try {
|
|
148
|
+
const url = new URL(error.message.slice(prefixIndex + prefix.length).trim());
|
|
149
|
+
const currentOrigin = globalThis.location?.origin;
|
|
150
|
+
if (currentOrigin && url.origin !== currentOrigin)
|
|
151
|
+
return undefined;
|
|
152
|
+
if (!url.pathname.endsWith('.js'))
|
|
153
|
+
return undefined;
|
|
154
|
+
return url;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=craft-load-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"craft-load-retry.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/craft-load-retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAa,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACL,sBAAsB,EACtB,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;AA8B5B;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,cAAc,CAEpD,sBAAsB,EAAE;IACxB,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,GAAG,EAAE,CAAC,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,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { inject, InjectionToken, type Type } from './host/craft-compat';\nimport {\n CRAFT_TEMPORAL_RUNTIME,\n RealCraftTemporalRuntime,\n type CraftTemporalRuntime,\n} from './temporal-runtime';\n\n// ---------------------------------------------------------------------------\n// Generic lazy-load retry engine.\n//\n// Powers both route lazy loading (`loadComponent`/`loadChildren`, see\n// craft-route-load-error.ts) and imperative service lazy loading (`craftLazy`,\n// see craft-lazy.ts). It provides:\n//\n// - `CRAFT_DYNAMIC_IMPORT` — the injectable `import(url)` used for cache-busting\n// a chunk whose first fetch failed (a stale hashed URL after a redeploy).\n// - `retryFailedDynamicImport` — re-imports a failed chunk with a cache-busting\n// query param, deduplicating concurrent retries of the same URL.\n// - `createCraftLoadRetry` — the attempts/delay/shouldRetry loop, generic over\n// the retry context the caller threads through its callbacks.\n// - `CraftLazyLoadHelpers` — the `{ withRetry }` object handed to a loader\n// callback, plus the identity/retry-flavoured factories that build it.\n// ---------------------------------------------------------------------------\n\n/**\n * The `{ withRetry }` helpers handed to a lazy loader callback. `withRetry`\n * wraps a dynamic `import(...)` so a chunk whose hashed URL went stale after a\n * redeploy is re-fetched with a cache-busting query param. On the very first\n * attempt it is the identity function; the retry engine swaps in the\n * cache-busting variant for subsequent attempts.\n */\nexport interface CraftLazyLoadHelpers {\n withRetry<T>(moduleImport: Promise<T>): Promise<T>;\n}\n\n/**\n * The injectable dynamic `import(url)`. Overridable in tests to observe the\n * cache-busting URL {@link retryFailedDynamicImport} computes.\n */\nexport const CRAFT_DYNAMIC_IMPORT = new InjectionToken<\n (url: string) => Promise<unknown>\n>('CRAFT_DYNAMIC_IMPORT', {\n providedIn: 'root',\n factory: () => (url) => import(/* @vite-ignore */ url),\n});\n\n/** The base fields the retry loop itself reads and advances on every attempt. */\nexport interface CraftLoadRetryContextBase {\n readonly attempt: number;\n readonly error: unknown;\n}\n\nexport interface CraftLoadRetry<\n Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase,\n> {\n execute<T>(loader: () => Promise<T>, context: Context): Promise<T>;\n}\n\nexport interface CraftLoadRetryOptions<\n Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase,\n> {\n readonly attempts?: number;\n readonly delayMs?: number | ((error: unknown, context: Context) => number);\n readonly shouldRetry?: (\n error: unknown,\n context: Context,\n ) => boolean | Promise<boolean>;\n /** Optional clock seam, primarily useful for deterministic tests. */\n readonly temporalRuntime?: CraftTemporalRuntime;\n}\n\nexport type CraftLoadRetryConfig<\n Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase,\n> =\n | CraftLoadRetry<Context>\n | Type<CraftLoadRetry<Context>>\n | CraftLoadRetryOptions<Context>;\n\nexport const DEFAULT_CRAFT_LOAD_RETRY_OPTIONS = {\n attempts: 1,\n delayMs: 250,\n} satisfies Required<Pick<CraftLoadRetryOptions, 'attempts' | 'delayMs'>>;\n\n/**\n * Builds the attempts/delay/shouldRetry loop shared by every craft lazy load.\n * `execute` re-invokes `loader` up to `attempts` times, threading the caller's\n * `Context` (only `attempt` and `error` are advanced by the engine — the rest is\n * spread through unchanged) into the `delayMs`/`shouldRetry` callbacks. On final\n * exhaustion it rethrows the last raw failure (callers wrap it into a domain\n * `craftException` — a route load error or a `craftLazy` load error).\n */\nexport function createCraftLoadRetry<\n Context extends CraftLoadRetryContextBase = CraftLoadRetryContextBase,\n>(options: CraftLoadRetryOptions<Context> = {}): CraftLoadRetry<Context> {\n const attempts = Math.max(\n 1,\n Math.floor(options.attempts ?? DEFAULT_CRAFT_LOAD_RETRY_OPTIONS.attempts),\n );\n const delayMs = options.delayMs ?? DEFAULT_CRAFT_LOAD_RETRY_OPTIONS.delayMs;\n const temporalRuntime =\n options.temporalRuntime ??\n tryInjectTemporalRuntime() ??\n new RealCraftTemporalRuntime();\n\n return {\n async execute<T>(\n loader: () => Promise<T>,\n baseContext: Context,\n ): Promise<T> {\n let lastError: unknown;\n let previousError = baseContext.error;\n for (let index = 0; index < attempts; index++) {\n const context = {\n ...baseContext,\n attempt: baseContext.attempt + index + 1,\n error: previousError,\n } as Context;\n const shouldRetry =\n options.shouldRetry?.(previousError, context) ?? true;\n if (!(await shouldRetry)) throw previousError;\n\n const resolvedDelayMs = Math.max(\n 0,\n typeof delayMs === 'function'\n ? delayMs(previousError, context)\n : delayMs,\n );\n if (resolvedDelayMs > 0) {\n await temporalRuntime.sleep(resolvedDelayMs, {\n kind: 'retry',\n owner: 'craft-load-retry',\n });\n }\n\n try {\n return await loader();\n } catch (error) {\n lastError = error;\n previousError = error;\n }\n }\n throw lastError;\n },\n };\n}\n\nfunction tryInjectTemporalRuntime(): CraftTemporalRuntime | undefined {\n try {\n return inject(CRAFT_TEMPORAL_RUNTIME, { optional: true }) ?? undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The retry policy `craftLazy` applies to an imperative lazy import. Defaults to\n * the shared attempts/delay loop; override it to tune attempts, back-off, or\n * `shouldRetry` for `craftLazy` loads specifically.\n */\nexport const CRAFT_LAZY_LOAD_RETRY = new InjectionToken<CraftLoadRetry>(\n 'CRAFT_LAZY_LOAD_RETRY',\n { providedIn: 'root', factory: () => createCraftLoadRetry() },\n);\n\nexport function provideCraftLazyLoadRetry(\n retry: CraftLoadRetryConfig,\n):\n | { provide: typeof CRAFT_LAZY_LOAD_RETRY; useValue: CraftLoadRetry }\n | { provide: typeof CRAFT_LAZY_LOAD_RETRY; useClass: Type<CraftLoadRetry> } {\n if (isCraftLoadRetryType(retry)) {\n return { provide: CRAFT_LAZY_LOAD_RETRY, useClass: retry };\n }\n return {\n provide: CRAFT_LAZY_LOAD_RETRY,\n useValue: isCraftLoadRetry(retry) ? retry : createCraftLoadRetry(retry),\n };\n}\n\nexport function isCraftLoadRetry<Context extends CraftLoadRetryContextBase>(\n value: CraftLoadRetryConfig<Context>,\n): value is CraftLoadRetry<Context> {\n return typeof (value as CraftLoadRetry<Context>).execute === 'function';\n}\n\nexport function isCraftLoadRetryType<Context extends CraftLoadRetryContextBase>(\n value: CraftLoadRetryConfig<Context>,\n): value is Type<CraftLoadRetry<Context>> {\n return typeof value === 'function';\n}\n\n/** The identity helpers used for the first (un-busted) load attempt. */\nexport const INITIAL_LAZY_LOAD_HELPERS: CraftLazyLoadHelpers = {\n withRetry: <T>(moduleImport: Promise<T>) => moduleImport,\n};\n\n/**\n * Helpers whose `withRetry` re-fetches a failed chunk with a cache-busting\n * query param, used for every attempt after the first.\n */\nexport function createRetryLazyLoadHelpers(\n dynamicImport: (url: string) => Promise<unknown>,\n retryParam = DEFAULT_RETRY_PARAM,\n): CraftLazyLoadHelpers {\n return {\n withRetry: <T>(moduleImport: Promise<T>) =>\n retryFailedDynamicImport(moduleImport, dynamicImport, retryParam),\n };\n}\n\nconst DEFAULT_RETRY_PARAM = '__craft_retry';\n\nconst successfulRetriedImports = new Map<string, Promise<unknown>>();\nconst retryImportAttempts = new Map<string, number>();\n\n/**\n * Awaits `moduleImport`; if it fails because a dynamically-imported chunk could\n * not be fetched (a stale hashed URL after a redeploy), re-imports the same URL\n * with an incrementing cache-busting query param. Concurrent retries of the same\n * URL share a single in-flight import.\n */\nexport async function retryFailedDynamicImport<T>(\n moduleImport: Promise<T>,\n dynamicImport: (url: string) => Promise<unknown>,\n retryParam = DEFAULT_RETRY_PARAM,\n): Promise<T> {\n try {\n return await moduleImport;\n } catch (error) {\n const failedUrl = failedDynamicImportUrl(error);\n if (!failedUrl) throw error;\n\n const baseUrl = failedUrl.href;\n const cachedRetry = successfulRetriedImports.get(baseUrl);\n if (cachedRetry) return cachedRetry as Promise<T>;\n\n const attempt = (retryImportAttempts.get(baseUrl) ?? 0) + 1;\n retryImportAttempts.set(baseUrl, attempt);\n failedUrl.searchParams.set(retryParam, String(attempt));\n\n const retriedImport = dynamicImport(failedUrl.href) as Promise<T>;\n successfulRetriedImports.set(baseUrl, retriedImport);\n\n try {\n return await retriedImport;\n } catch (retryError) {\n successfulRetriedImports.delete(baseUrl);\n throw retryError;\n }\n }\n}\n\nfunction failedDynamicImportUrl(error: unknown): URL | undefined {\n if (!(error instanceof Error)) return undefined;\n\n const prefix = 'Failed to fetch dynamically imported module:';\n const prefixIndex = error.message.indexOf(prefix);\n if (prefixIndex === -1) return undefined;\n\n try {\n const url = new URL(\n error.message.slice(prefixIndex + prefix.length).trim(),\n );\n const currentOrigin = globalThis.location?.origin;\n if (currentOrigin && url.origin !== currentOrigin) return undefined;\n if (!url.pathname.endsWith('.js')) return undefined;\n return url;\n } catch {\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { StorageService } from './browser-boundaries';
|
|
2
|
+
import type { CraftUnique } from './craft-unique';
|
|
3
|
+
import type { GetServiceYields } from './craft-service';
|
|
4
|
+
import { type CraftPrimitiveSnapshot } from './craft-primitive-registry';
|
|
5
|
+
import { type YieldableReactiveValue } from './reactive-read';
|
|
6
|
+
import type { CraftMachineControls, CraftMachineInsertionContext } from './craft-state-machine';
|
|
7
|
+
/**
|
|
8
|
+
* One recorded moment of a machine: the transition that produced it, and the
|
|
9
|
+
* value of every primitive the machine owns at that point.
|
|
10
|
+
*
|
|
11
|
+
* The step and the values are captured AFTER the transition was applied, so
|
|
12
|
+
* restoring an entry restores the state the machine was in once it had moved.
|
|
13
|
+
*
|
|
14
|
+
* Snapshot keys are RELATIVE to the machine, not absolute registry addresses.
|
|
15
|
+
* An absolute address starts with the host chain of the component that happens
|
|
16
|
+
* to hold the machine, and that prefix carries a creation ordinal which means
|
|
17
|
+
* nothing after a reload. Below the machine everything is deterministic — the
|
|
18
|
+
* same code creates the same primitives in the same order — so a relative key
|
|
19
|
+
* survives, and re-anchors onto whichever instance is restoring it.
|
|
20
|
+
*/
|
|
21
|
+
export type CraftHistoryEntry<Steps extends string = string> = Readonly<{
|
|
22
|
+
step: Steps;
|
|
23
|
+
from: Steps | undefined;
|
|
24
|
+
event: unknown;
|
|
25
|
+
at: number;
|
|
26
|
+
snapshot: CraftPrimitiveSnapshot;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* What a history feature composed into {@link withStateMachineHistory} receives. It is
|
|
30
|
+
* deliberately narrow: a feature navigates the recorded entries, it does not
|
|
31
|
+
* decide what gets recorded.
|
|
32
|
+
*/
|
|
33
|
+
export type CraftHistoryFeatureContext<Steps extends string = string> = Readonly<{
|
|
34
|
+
entries: YieldableReactiveValue<readonly CraftHistoryEntry<Steps>[], 'entries'>;
|
|
35
|
+
/** Index of the entry the machine currently sits on. */
|
|
36
|
+
cursor: YieldableReactiveValue<number, 'cursor'>;
|
|
37
|
+
/**
|
|
38
|
+
* Restores the recorded entry at `index`. Returns `false` when the index
|
|
39
|
+
* is out of range. Guards are NOT consulted: a recorded state was already
|
|
40
|
+
* accepted once, and replaying it must not depend on today's permissions.
|
|
41
|
+
*/
|
|
42
|
+
goTo(index: number): boolean;
|
|
43
|
+
controls: CraftMachineControls<Steps>;
|
|
44
|
+
}>;
|
|
45
|
+
export type CraftHistoryFeature<Output extends object> = (context: CraftHistoryFeatureContext<any>) => Output;
|
|
46
|
+
type HistoryOptions = Readonly<{
|
|
47
|
+
/**
|
|
48
|
+
* How many entries to keep. The oldest are dropped first. `Infinity` keeps
|
|
49
|
+
* everything, which is fine for a debug session and not for production.
|
|
50
|
+
*/
|
|
51
|
+
limit?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Primitives declared OUTSIDE the machine that belong to the story being
|
|
54
|
+
* recorded. A machine captures what it owns by itself; anything else has to
|
|
55
|
+
* be named, so a replay stays reproducible instead of depending on whatever
|
|
56
|
+
* happened to be in the injector.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* withStateMachineHistory({ include: [sharedFilters] }, withBackNavigation())
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
include?: readonly unknown[];
|
|
63
|
+
/**
|
|
64
|
+
* Keeps the history across a reload, under an anchor the application names.
|
|
65
|
+
*
|
|
66
|
+
* Only the ANCHOR needs a stable identity: everything the machine owns is
|
|
67
|
+
* addressed relative to it, and those keys are deterministic. `key` may be a
|
|
68
|
+
* function when the anchor comes from data — a row of a list anchors on the
|
|
69
|
+
* entity it edits, not on the order it happened to be created in.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* withStateMachineHistory(
|
|
73
|
+
* { persist: craftUnique({ storeName: 'app', key: 'book-editor' }) },
|
|
74
|
+
* withBackNavigation(),
|
|
75
|
+
* )
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
persist?: CraftUnique<CraftHistoryPersistenceStatic> | CraftHistoryPersistenceDynamic;
|
|
79
|
+
}>;
|
|
80
|
+
export type CraftHistoryPersistenceStatic = Readonly<{
|
|
81
|
+
storeName: string;
|
|
82
|
+
key: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** A data-dependent anchor cannot be verified as a static unique identity. */
|
|
85
|
+
export type CraftHistoryPersistenceDynamic = Readonly<{
|
|
86
|
+
storeName: string;
|
|
87
|
+
/** Resolved once, when the machine is built. */
|
|
88
|
+
key: () => string;
|
|
89
|
+
}>;
|
|
90
|
+
export type CraftHistoryPersistence = CraftHistoryPersistenceStatic | CraftHistoryPersistenceDynamic;
|
|
91
|
+
type HistoryOutput<Steps extends string> = {
|
|
92
|
+
readonly history: YieldableReactiveValue<readonly CraftHistoryEntry<Steps>[], 'history'>;
|
|
93
|
+
readonly historyCursor: YieldableReactiveValue<number, 'historyCursor'>;
|
|
94
|
+
};
|
|
95
|
+
/** What `withStateMachineHistory(...)` resolves to: an insertion for `craftStateMachine`. */
|
|
96
|
+
type HistoryInsertion<Steps extends string, Features> = (context: CraftMachineInsertionContext<any, Steps, any>) => Generator<GetServiceYields<typeof StorageService>, HistoryOutput<Steps> & Features, unknown>;
|
|
97
|
+
/**
|
|
98
|
+
* Records the machine's history, and composes features on top of it.
|
|
99
|
+
*
|
|
100
|
+
* History is not part of the machine core — it is an insertion, exactly like
|
|
101
|
+
* the derived values and step flags beside it:
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* craftStateMachine(
|
|
105
|
+
* contextFactory,
|
|
106
|
+
* transitions,
|
|
107
|
+
* stepContexts,
|
|
108
|
+
* withStateMachineHistory(withBackNavigation()),
|
|
109
|
+
* );
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* Every accepted transition appends an entry holding the new step and a
|
|
113
|
+
* snapshot of every primitive the machine owns, read through
|
|
114
|
+
* `CRAFT_PRIMITIVE_REGISTRY` and scoped to the machine's host chain. A
|
|
115
|
+
* primitive declared OUTSIDE the machine is not captured: pass it explicitly
|
|
116
|
+
* through `include` when it belongs to the story being replayed.
|
|
117
|
+
*/
|
|
118
|
+
export declare function withStateMachineHistory<Steps extends string = string>(): HistoryInsertion<Steps, object>;
|
|
119
|
+
export declare function withStateMachineHistory<Feature1 extends object, Steps extends string = string>(feature1: CraftHistoryFeature<Feature1>): HistoryInsertion<Steps, Feature1>;
|
|
120
|
+
export declare function withStateMachineHistory<Feature1 extends object, Feature2 extends object, Steps extends string = string>(feature1: CraftHistoryFeature<Feature1>, feature2: CraftHistoryFeature<Feature2>): HistoryInsertion<Steps, Feature1 & Feature2>;
|
|
121
|
+
export declare function withStateMachineHistory<Feature1 extends object, Feature2 extends object, Feature3 extends object, Steps extends string = string>(feature1: CraftHistoryFeature<Feature1>, feature2: CraftHistoryFeature<Feature2>, feature3: CraftHistoryFeature<Feature3>): HistoryInsertion<Steps, Feature1 & Feature2 & Feature3>;
|
|
122
|
+
export declare function withStateMachineHistory<Steps extends string = string>(options: HistoryOptions): HistoryInsertion<Steps, object>;
|
|
123
|
+
export declare function withStateMachineHistory<Feature1 extends object, Steps extends string = string>(options: HistoryOptions, feature1: CraftHistoryFeature<Feature1>): HistoryInsertion<Steps, Feature1>;
|
|
124
|
+
export declare function withStateMachineHistory<Feature1 extends object, Feature2 extends object, Steps extends string = string>(options: HistoryOptions, feature1: CraftHistoryFeature<Feature1>, feature2: CraftHistoryFeature<Feature2>): HistoryInsertion<Steps, Feature1 & Feature2>;
|
|
125
|
+
export declare function withStateMachineHistory<Feature1 extends object, Feature2 extends object, Feature3 extends object, Steps extends string = string>(options: HistoryOptions, feature1: CraftHistoryFeature<Feature1>, feature2: CraftHistoryFeature<Feature2>, feature3: CraftHistoryFeature<Feature3>): HistoryInsertion<Steps, Feature1 & Feature2 & Feature3>;
|
|
126
|
+
type BackNavigationOutput = {
|
|
127
|
+
readonly canGoBack: YieldableReactiveValue<boolean, 'canGoBack'>;
|
|
128
|
+
readonly canGoForward: YieldableReactiveValue<boolean, 'canGoForward'>;
|
|
129
|
+
readonly back: () => boolean;
|
|
130
|
+
readonly forward: () => boolean;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Step-by-step navigation through a machine's history. Composes into
|
|
134
|
+
* {@link withStateMachineHistory}, which owns the entries it walks:
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* withStateMachineHistory(withBackNavigation())
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* `back()` and `forward()` restore a recorded moment without asking the
|
|
141
|
+
* guards: that state was accepted once already.
|
|
142
|
+
*/
|
|
143
|
+
export declare function withBackNavigation(): CraftHistoryFeature<BackNavigationOutput>;
|
|
144
|
+
export {};
|
|
145
|
+
//# sourceMappingURL=craft-machine-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"craft-machine-history.d.ts","sourceRoot":"","sources":["../../../../../libs/core/src/lib/craft-machine-history.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAIL,KAAK,sBAAsB,EAC5B,MAAM,iBAAiB,CAAC;AACzB,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