@lostgradient/weft 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -43
- package/dist/cli/conformance.js +7 -1
- package/dist/cli/generated/operation-client.generated.d.ts +55 -13
- package/dist/cli/generated/operation-client.generated.js +3 -0
- package/dist/cli/help-text.d.ts +1 -1
- package/dist/cli/help-text.js +1 -0
- package/dist/cli/operation-catalog-snapshot.d.ts +8 -0
- package/dist/cli/operation-catalog-snapshot.js +11 -0
- package/dist/cli/parse-schedule-arguments.js +3 -1
- package/dist/cli/schedule.js +2 -1
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli-main.js +80 -79
- package/dist/client/handle-delegation.d.ts +7 -2
- package/dist/client/handle-delegation.js +9 -1
- package/dist/client/http-client-requests.d.ts +4 -1
- package/dist/client/http-client-requests.js +10 -0
- package/dist/client/http-client.d.ts +10 -4
- package/dist/client/http-client.js +18 -1
- package/dist/client/http-request.d.ts +11 -1
- package/dist/client/http-request.js +17 -7
- package/dist/client/index.d.ts +1 -1
- package/dist/client/interface.d.ts +100 -4
- package/dist/client/local.d.ts +7 -1
- package/dist/client/local.js +17 -2
- package/dist/client/start-body.d.ts +9 -2
- package/dist/client/start-body.js +13 -4
- package/dist/core/byte-arrays.d.ts +5 -0
- package/dist/core/byte-arrays.js +5 -0
- package/dist/core/checkpoint/lifecycle.d.ts +3 -0
- package/dist/core/checkpoint/lifecycle.js +9 -4
- package/dist/core/checkpoint/serialization.js +12 -5
- package/dist/core/codec/extension-codec.d.ts +16 -0
- package/dist/core/codec/extension-codec.js +104 -8
- package/dist/core/codec/index.d.ts +1 -0
- package/dist/core/codec/index.js +1 -0
- package/dist/core/codec/serializer-registry.d.ts +122 -0
- package/dist/core/codec/serializer-registry.js +51 -0
- package/dist/core/context/activity-retry-state.d.ts +38 -0
- package/dist/core/context/activity-retry-state.js +89 -0
- package/dist/core/context/activity-schedule-to-close.d.ts +159 -0
- package/dist/core/context/activity-schedule-to-close.js +69 -0
- package/dist/core/context/child-workflow-pipe.d.ts +5 -5
- package/dist/core/context/child-workflow-pipe.js +15 -2
- package/dist/core/context/context-presence.d.ts +19 -0
- package/dist/core/context/context-presence.js +13 -0
- package/dist/core/context/durable-operations.d.ts +25 -0
- package/dist/core/context/durable-operations.js +64 -0
- package/dist/core/context/index.d.ts +18 -5
- package/dist/core/context/index.js +17 -12
- package/dist/core/context/internals.d.ts +29 -0
- package/dist/core/context/internals.js +6 -1
- package/dist/core/context/operation-request.d.ts +35 -0
- package/dist/core/context/parallel-cache-entry.d.ts +14 -5
- package/dist/core/context/run-operation.d.ts +21 -3
- package/dist/core/context/run-operation.js +56 -93
- package/dist/core/context/session-state.js +7 -8
- package/dist/core/context/speculative-child.js +2 -0
- package/dist/core/context/types.d.ts +15 -0
- package/dist/core/context/version-patching.d.ts +8 -0
- package/dist/core/context/version-patching.js +40 -0
- package/dist/core/context/workflow-logger.d.ts +98 -0
- package/dist/core/context/workflow-logger.js +68 -0
- package/dist/core/engine/activity-heartbeat-tracking.d.ts +64 -0
- package/dist/core/engine/activity-heartbeat-tracking.js +42 -0
- package/dist/core/engine/activity-per-attempt-timeout.d.ts +41 -0
- package/dist/core/engine/activity-per-attempt-timeout.js +36 -0
- package/dist/core/engine/activity-reconciliation.d.ts +1 -0
- package/dist/core/engine/activity-reconciliation.js +12 -1
- package/dist/core/engine/activity-resolution.d.ts +23 -0
- package/dist/core/engine/activity-resolution.js +37 -0
- package/dist/core/engine/aggregate.js +66 -30
- package/dist/core/engine/async-activity-completion.d.ts +23 -6
- package/dist/core/engine/async-activity-completion.js +53 -12
- package/dist/core/engine/attributes-tags.js +9 -4
- package/dist/core/engine/bulk-operations-purge.d.ts +26 -0
- package/dist/core/engine/bulk-operations-purge.js +38 -3
- package/dist/core/engine/bulk-operations-shared.d.ts +2 -0
- package/dist/core/engine/bulk-operations-shared.js +8 -2
- package/dist/core/engine/bulk-operations.d.ts +4 -1
- package/dist/core/engine/bulk-operations.js +235 -24
- package/dist/core/engine/callback-creators-bundles.d.ts +9 -0
- package/dist/core/engine/callback-creators-bundles.js +30 -2
- package/dist/core/engine/callback-creators-core.js +6 -4
- package/dist/core/engine/callback-creators-router.js +10 -0
- package/dist/core/engine/callback-creators-schedule.d.ts +2 -2
- package/dist/core/engine/callback-creators-schedule.js +12 -8
- package/dist/core/engine/candidate-read-batching.d.ts +6 -0
- package/dist/core/engine/candidate-read-batching.js +1 -0
- package/dist/core/engine/checkpoint-io.js +61 -25
- package/dist/core/engine/checkpoint-reads.js +3 -2
- package/dist/core/engine/checkpoint-replay.d.ts +20 -0
- package/dist/core/engine/checkpoint-replay.js +242 -0
- package/dist/core/engine/checkpoint-side-effects.d.ts +23 -0
- package/dist/core/engine/checkpoint-side-effects.js +35 -0
- package/dist/core/engine/child-workflow-cancellation.d.ts +10 -0
- package/dist/core/engine/child-workflow-cancellation.js +40 -0
- package/dist/core/engine/child-workflow.js +27 -4
- package/dist/core/engine/condition-waiters.d.ts +14 -0
- package/dist/core/engine/condition-waiters.js +5 -0
- package/dist/core/engine/construction.d.ts +3 -1
- package/dist/core/engine/construction.js +30 -8
- package/dist/core/engine/coordination-branch-executors.d.ts +70 -0
- package/dist/core/engine/coordination-branch-executors.js +107 -0
- package/dist/core/engine/deferred-consume-envelope.d.ts +59 -0
- package/dist/core/engine/deferred-consume-envelope.js +14 -0
- package/dist/core/engine/disposal.js +25 -0
- package/dist/core/engine/engine-create-types.d.ts +14 -18
- package/dist/core/engine/engine-internal-types.d.ts +38 -3
- package/dist/core/engine/engine-leak-warnings.d.ts +6 -0
- package/dist/core/engine/engine-leak-warnings.js +4 -0
- package/dist/core/engine/engine-runtime-helpers.d.ts +17 -0
- package/dist/core/engine/engine-runtime-helpers.js +26 -5
- package/dist/core/engine/errors.d.ts +121 -0
- package/dist/core/engine/errors.js +45 -1
- package/dist/core/engine/event-log-compaction.d.ts +8 -0
- package/dist/core/engine/event-log-compaction.js +20 -2
- package/dist/core/engine/fenced-write.d.ts +65 -0
- package/dist/core/engine/fenced-write.js +71 -0
- package/dist/core/engine/finalizer-state.d.ts +28 -0
- package/dist/core/engine/finalizer-state.js +16 -0
- package/dist/core/engine/handle-result.js +1 -1
- package/dist/core/engine/handles.d.ts +97 -40
- package/dist/core/engine/handles.js +25 -27
- package/dist/core/engine/index.d.ts +125 -15
- package/dist/core/engine/index.js +207 -11
- package/dist/core/engine/inline-launch-queue.d.ts +14 -0
- package/dist/core/engine/inline-launch-queue.js +32 -7
- package/dist/core/engine/inline-parking.js +3 -2
- package/dist/core/engine/internals.d.ts +125 -13
- package/dist/core/engine/lease-codec.d.ts +35 -0
- package/dist/core/engine/lease-codec.js +32 -0
- package/dist/core/engine/lease-deposition.d.ts +66 -0
- package/dist/core/engine/lease-deposition.js +10 -0
- package/dist/core/engine/lease-errors.d.ts +99 -0
- package/dist/core/engine/lease-errors.js +30 -0
- package/dist/core/engine/lease-manager.d.ts +114 -0
- package/dist/core/engine/lease-manager.js +135 -0
- package/dist/core/engine/lifecycle/fork-helpers.js +1 -7
- package/dist/core/engine/lifecycle/persist.js +15 -52
- package/dist/core/engine/lifecycle/recovered-services.d.ts +8 -6
- package/dist/core/engine/lifecycle/recovered-services.js +18 -3
- package/dist/core/engine/lifecycle/resume.js +39 -11
- package/dist/core/engine/lifecycle/shared.d.ts +8 -1
- package/dist/core/engine/lifecycle/start-batch.d.ts +1 -1
- package/dist/core/engine/lifecycle/start-batch.js +2 -1
- package/dist/core/engine/lifecycle/start-commit.d.ts +56 -0
- package/dist/core/engine/lifecycle/start-commit.js +69 -0
- package/dist/core/engine/lifecycle/start-exec.d.ts +30 -2
- package/dist/core/engine/lifecycle/start-exec.js +38 -0
- package/dist/core/engine/lifecycle/start-or-signal-create.d.ts +58 -0
- package/dist/core/engine/lifecycle/start-or-signal-create.js +95 -0
- package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +79 -0
- package/dist/core/engine/lifecycle/start-or-signal-resolution.js +60 -0
- package/dist/core/engine/lifecycle/start-or-signal.d.ts +46 -0
- package/dist/core/engine/lifecycle/start-or-signal.js +71 -0
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +39 -0
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +28 -0
- package/dist/core/engine/lifecycle/start.d.ts +6 -6
- package/dist/core/engine/lifecycle/start.js +47 -45
- package/dist/core/engine/lifecycle/transition.js +17 -5
- package/dist/core/engine/lifecycle.d.ts +3 -2
- package/dist/core/engine/lifecycle.js +9 -2
- package/dist/core/engine/list-candidate-resolution.js +2 -2
- package/dist/core/engine/listing.js +10 -6
- package/dist/core/engine/operations-activity.d.ts +4 -11
- package/dist/core/engine/operations-activity.js +22 -49
- package/dist/core/engine/operations-coordination.d.ts +10 -0
- package/dist/core/engine/operations-coordination.js +43 -8
- package/dist/core/engine/operations-router.d.ts +6 -0
- package/dist/core/engine/operations-router.js +2 -0
- package/dist/core/engine/operations-speculate.js +6 -2
- package/dist/core/engine/operations-stream.js +12 -2
- package/dist/core/engine/operations-time.d.ts +4 -2
- package/dist/core/engine/operations-time.js +14 -2
- package/dist/core/engine/operations-wait-condition.d.ts +23 -0
- package/dist/core/engine/operations-wait-condition.js +62 -0
- package/dist/core/engine/ownership-options.d.ts +23 -0
- package/dist/core/engine/ownership-options.js +26 -0
- package/dist/core/engine/payload-size-policy.d.ts +3 -0
- package/dist/core/engine/payload-size-policy.js +4 -0
- package/dist/core/engine/pending-updates.d.ts +17 -0
- package/dist/core/engine/pending-updates.js +33 -11
- package/dist/core/engine/persisted-data-version.d.ts +5 -9
- package/dist/core/engine/persisted-data-version.js +4 -5
- package/dist/core/engine/queries.js +1 -1
- package/dist/core/engine/registration.d.ts +1 -0
- package/dist/core/engine/registration.js +18 -3
- package/dist/core/engine/schedule-handle.d.ts +45 -0
- package/dist/core/engine/schedule-handle.js +26 -0
- package/dist/core/engine/schedule-jitter.d.ts +5 -0
- package/dist/core/engine/schedule-jitter.js +10 -0
- package/dist/core/engine/schedule-run.d.ts +17 -0
- package/dist/core/engine/schedule-run.js +38 -0
- package/dist/core/engine/schedule-timer.js +81 -17
- package/dist/core/engine/schedules.d.ts +8 -5
- package/dist/core/engine/schedules.js +44 -19
- package/dist/core/engine/search-attribute-records.d.ts +4 -0
- package/dist/core/engine/search-attribute-records.js +17 -0
- package/dist/core/engine/second-instance-detector.d.ts +96 -0
- package/dist/core/engine/second-instance-detector.js +108 -0
- package/dist/core/engine/signals.d.ts +38 -0
- package/dist/core/engine/signals.js +55 -19
- package/dist/core/engine/state-utilities.d.ts +49 -2
- package/dist/core/engine/state-utilities.js +114 -3
- package/dist/core/engine/storage-io.d.ts +16 -2
- package/dist/core/engine/storage-io.js +26 -5
- package/dist/core/engine/stream-chunk-loading.d.ts +2 -0
- package/dist/core/engine/stream-chunk-loading.js +24 -1
- package/dist/core/engine/sub-operation.js +22 -3
- package/dist/core/engine/termination/cleanup.d.ts +28 -1
- package/dist/core/engine/termination/cleanup.js +44 -2
- package/dist/core/engine/termination/complete.js +48 -9
- package/dist/core/engine/termination/finalizer-activity.d.ts +53 -0
- package/dist/core/engine/termination/finalizer-activity.js +30 -0
- package/dist/core/engine/termination/finalizer-claim.d.ts +110 -0
- package/dist/core/engine/termination/finalizer-claim.js +80 -0
- package/dist/core/engine/termination/finalizer.d.ts +48 -0
- package/dist/core/engine/termination/finalizer.js +159 -0
- package/dist/core/engine/termination/suspend.d.ts +70 -0
- package/dist/core/engine/termination/suspend.js +41 -0
- package/dist/core/engine/termination.d.ts +5 -2
- package/dist/core/engine/termination.js +6 -0
- package/dist/core/engine/updates.js +5 -25
- package/dist/core/engine/validation/schedule.d.ts +2 -1
- package/dist/core/engine/validation/schedule.js +51 -2
- package/dist/core/engine/validation.js +54 -3
- package/dist/core/engine/waiting-update-response.d.ts +8 -0
- package/dist/core/engine/waiting-update-response.js +22 -0
- package/dist/core/engine/workflow-concurrency.d.ts +10 -0
- package/dist/core/engine/workflow-concurrency.js +136 -0
- package/dist/core/engine/workflow-feed.d.ts +9 -8
- package/dist/core/engine/workflow-feed.js +4 -1
- package/dist/core/engine/workflow-indexes.d.ts +9 -0
- package/dist/core/engine/workflow-indexes.js +10 -0
- package/dist/core/engine/workflow-state-stream.js +33 -13
- package/dist/core/engine/workflow-visibility-queries.d.ts +2 -2
- package/dist/core/engine-helpers.js +1 -0
- package/dist/core/events/activity-events.d.ts +43 -12
- package/dist/core/events/activity-events.js +28 -0
- package/dist/core/events/attribute-events.d.ts +2 -3
- package/dist/core/events/event-map.d.ts +19 -12
- package/dist/core/events/index.d.ts +1 -0
- package/dist/core/events/index.js +1 -0
- package/dist/core/events/schedule-events.d.ts +71 -0
- package/dist/core/events/schedule-events.js +29 -0
- package/dist/core/events/signal-events.d.ts +4 -6
- package/dist/core/events/system-events.d.ts +29 -19
- package/dist/core/events/system-events.js +26 -0
- package/dist/core/events/update-events.d.ts +6 -8
- package/dist/core/events/workflow-events.d.ts +108 -20
- package/dist/core/events/workflow-events.js +35 -0
- package/dist/core/failure-categories.js +5 -17
- package/dist/core/fault-code.d.ts +9 -3
- package/dist/core/fault-code.js +1 -0
- package/dist/core/inline-execution-strategy.context-options.d.ts +69 -0
- package/dist/core/inline-execution-strategy.context-options.js +56 -0
- package/dist/core/inline-execution-strategy.d.ts +31 -36
- package/dist/core/inline-execution-strategy.js +16 -27
- package/dist/core/list-filter-validation.d.ts +1 -1
- package/dist/core/list-filter-validation.js +2 -1
- package/dist/core/payload-size.d.ts +1 -1
- package/dist/core/persisted-data-incompatible-error.d.ts +9 -7
- package/dist/core/review/events.d.ts +6 -8
- package/dist/core/scheduler/scheduler-class.d.ts +10 -1
- package/dist/core/scheduler/scheduler-class.js +38 -11
- package/dist/core/scheduler/timer-batch.js +9 -1
- package/dist/core/scheduler/timer-sources.d.ts +1 -0
- package/dist/core/scheduler/timer-sources.js +11 -5
- package/dist/core/session-state.d.ts +0 -1
- package/dist/core/session-state.js +2 -2
- package/dist/core/start-workflow-validation.d.ts +56 -0
- package/dist/core/start-workflow-validation.js +30 -1
- package/dist/core/step-context.d.ts +10 -6
- package/dist/core/step-context.js +7 -15
- package/dist/core/types/activity-verification.d.ts +67 -0
- package/dist/core/types/activity-verification.js +0 -0
- package/dist/core/types/activity.d.ts +86 -64
- package/dist/core/types/bulk.d.ts +50 -9
- package/dist/core/types/checkpoint.d.ts +44 -8
- package/dist/core/types/identity.d.ts +8 -1
- package/dist/core/types/launch-metadata.d.ts +33 -0
- package/dist/core/types/launch-metadata.js +0 -0
- package/dist/core/types/list-options.d.ts +146 -0
- package/dist/core/types/list-options.js +0 -0
- package/dist/core/types/message-handles.d.ts +25 -0
- package/dist/core/types/options.d.ts +165 -215
- package/dist/core/types/reviews.d.ts +2 -1
- package/dist/core/types/schedules.d.ts +39 -3
- package/dist/core/types/services-resolution.d.ts +47 -0
- package/dist/core/types/services-resolution.js +0 -0
- package/dist/core/types/state.d.ts +11 -11
- package/dist/core/types/workflow-builder-runtime.d.ts +12 -3
- package/dist/core/types/workflow-builder-runtime.js +11 -2
- package/dist/core/types/workflow-builder.d.ts +47 -15
- package/dist/core/types/workflow-concurrency.d.ts +39 -0
- package/dist/core/types/workflow-concurrency.js +0 -0
- package/dist/core/types/workflow-context.d.ts +157 -14
- package/dist/core/types/workflow-definition.d.ts +53 -10
- package/dist/core/types/workflow-function.d.ts +101 -9
- package/dist/core/types/workflow-log.d.ts +98 -0
- package/dist/core/types/workflow-log.js +0 -0
- package/dist/core/types/workflow-registries.d.ts +14 -3
- package/dist/core/types/workflow-registry.d.ts +3 -0
- package/dist/core/types/workflow-snapshot.d.ts +29 -0
- package/dist/core/types/workflow-snapshot.js +0 -0
- package/dist/core/types.d.ts +7 -0
- package/dist/core/types.js +7 -0
- package/dist/core/versioning.d.ts +9 -39
- package/dist/core/versioning.js +2 -12
- package/dist/core/weft-error.d.ts +44 -1
- package/dist/core/weft-error.js +19 -1
- package/dist/core/worker-execution-strategy-options.d.ts +26 -0
- package/dist/core/worker-execution-strategy.js +40 -36
- package/dist/core/worker-inbound-message.d.ts +38 -0
- package/dist/core/worker-inbound-message.js +37 -0
- package/dist/core/worker-log-abuse-counter.d.ts +175 -0
- package/dist/core/worker-log-abuse-counter.js +107 -0
- package/dist/core/worker-message-helpers.d.ts +47 -0
- package/dist/core/worker-message-helpers.js +26 -0
- package/dist/core/worker-protocol-guard.js +1 -1
- package/dist/core/worker-protocol-log.d.ts +56 -0
- package/dist/core/worker-protocol-log.js +18 -0
- package/dist/core/worker-protocol.d.ts +23 -0
- package/dist/core/worker-protocol.js +12 -2
- package/dist/core/workflow-version-tuple.d.ts +3 -9
- package/dist/core/workflow-version-tuple.js +2 -3
- package/dist/diagnostics/doctor.js +6 -3
- package/dist/diagnostics/format.js +3 -8
- package/dist/diagnostics/types.d.ts +5 -5
- package/dist/diagnostics/validate.d.ts +0 -1
- package/dist/diagnostics/version-check.d.ts +1 -1
- package/dist/diagnostics/version-check.js +10 -13
- package/dist/index.d.ts +13 -11
- package/dist/index.js +39 -4
- package/dist/json-schema.js +3 -3
- package/dist/mcp/cli.js +35 -35
- package/dist/mcp/dispatcher.js +1 -1
- package/dist/mcp/http.js +16 -6
- package/dist/mcp/list-filter.js +2 -1
- package/dist/mcp/protocol.d.ts +2 -0
- package/dist/mcp/protocol.js +1 -1
- package/dist/mcp/session.d.ts +16 -0
- package/dist/mcp/session.js +60 -6
- package/dist/mcp/tools.js +73 -6
- package/dist/observability/index.js +2 -2
- package/dist/server/asyncapi-channels.js +5 -2
- package/dist/server/attribute-filters.d.ts +8 -3
- package/dist/server/attribute-filters.js +6 -1
- package/dist/server/authentication/api-key.d.ts +2 -1
- package/dist/server/authentication/api-key.js +5 -2
- package/dist/server/authentication/constant-time-api-key.d.ts +15 -0
- package/dist/server/authentication/constant-time-api-key.js +24 -0
- package/dist/server/authentication/index.d.ts +1 -1
- package/dist/server/authentication/index.js +7 -4
- package/dist/server/authentication/rotating-api-key-store.d.ts +5 -3
- package/dist/server/authentication/rotating-api-key-store.js +19 -11
- package/dist/server/engine-event-feed-backend.d.ts +4 -5
- package/dist/server/fault-to-http.js +8 -1
- package/dist/server/fault-to-json-rpc.js +1 -0
- package/dist/server/fleet-event-feed.d.ts +31 -0
- package/dist/server/fleet-event-feed.js +157 -0
- package/dist/server/handler/index.js +1 -1
- package/dist/server/handler/response-helpers.js +2 -1
- package/dist/server/handler/route-dispatch.d.ts +6 -3
- package/dist/server/handler/route-dispatch.js +2 -2
- package/dist/server/handler.js +31 -31
- package/dist/server/index.d.ts +32 -2
- package/dist/server/index.js +35 -35
- package/dist/server/interactive-operations.js +1 -0
- package/dist/server/json-rpc-transport-helpers.d.ts +1 -0
- package/dist/server/json-rpc-transport-helpers.js +2 -1
- package/dist/server/json-rpc-websocket-runtime.d.ts +11 -2
- package/dist/server/json-rpc-websocket-runtime.js +1 -0
- package/dist/server/json-rpc-websocket-subscriptions.d.ts +10 -0
- package/dist/server/json-rpc-websocket-subscriptions.js +29 -0
- package/dist/server/json-rpc-websocket-types.d.ts +22 -0
- package/dist/server/json-rpc-websocket-types.js +0 -0
- package/dist/server/json-rpc-websocket-validation.js +20 -4
- package/dist/server/json-rpc-websocket.d.ts +2 -43
- package/dist/server/json-rpc-websocket.js +57 -74
- package/dist/server/openapi.d.ts +2 -1
- package/dist/server/openapi.js +1 -3
- package/dist/server/openrpc-document-schema.d.ts +78 -0
- package/dist/server/openrpc-document-schema.js +27 -1
- package/dist/server/openrpc-errors.d.ts +3 -0
- package/dist/server/openrpc-errors.js +2 -1
- package/dist/server/openrpc.js +32 -0
- package/dist/server/operation-catalog/index.d.ts +1 -1
- package/dist/server/operation-catalog/pipeline-helpers.js +1 -0
- package/dist/server/operation-catalog/pipeline-stages.js +26 -12
- package/dist/server/operation-catalog/pipeline.js +8 -1
- package/dist/server/operation-catalog/registry.js +13 -0
- package/dist/server/operation-catalog/types.d.ts +20 -9
- package/dist/server/operation-fault.d.ts +10 -0
- package/dist/server/operation-fault.js +2 -0
- package/dist/server/operation-registry.d.ts +12 -11
- package/dist/server/operation-registry.js +12 -3
- package/dist/server/operations/aggregate-workflows.d.ts +15 -15
- package/dist/server/operations/async-activity.d.ts +2 -2
- package/dist/server/operations/async-activity.js +12 -7
- package/dist/server/operations/bulk-cancel-workflows.d.ts +1 -1
- package/dist/server/operations/bulk-cancel-workflows.js +2 -2
- package/dist/server/operations/bulk-delete-workflows.d.ts +1 -1
- package/dist/server/operations/bulk-delete-workflows.js +2 -2
- package/dist/server/operations/bulk-filter-helpers.d.ts +8 -6
- package/dist/server/operations/bulk-filter-helpers.js +54 -24
- package/dist/server/operations/bulk-mutate-workflow-tags.d.ts +11 -9
- package/dist/server/operations/bulk-mutate-workflow-tags.js +2 -2
- package/dist/server/operations/bulk-operation-helpers.d.ts +2 -2
- package/dist/server/operations/bulk-retry-failed-workflows.d.ts +7 -0
- package/dist/server/operations/bulk-retry-failed-workflows.js +64 -0
- package/dist/server/operations/bulk-signal-workflows.d.ts +11 -9
- package/dist/server/operations/bulk-signal-workflows.js +2 -2
- package/dist/server/operations/cancel-schedule.d.ts +1 -1
- package/dist/server/operations/create-schedule.d.ts +3 -1
- package/dist/server/operations/create-schedule.js +29 -11
- package/dist/server/operations/fleet-events-subscription.d.ts +54 -0
- package/dist/server/operations/fleet-events-subscription.js +99 -0
- package/dist/server/operations/fork-workflow.d.ts +1 -1
- package/dist/server/operations/fork-workflow.js +3 -2
- package/dist/server/operations/get-checkpoint-at.d.ts +1 -1
- package/dist/server/operations/get-registry.d.ts +1 -1
- package/dist/server/operations/get-retention-overview.d.ts +1 -1
- package/dist/server/operations/get-review.d.ts +1 -1
- package/dist/server/operations/get-schedule.d.ts +1 -1
- package/dist/server/operations/get-stream-chunks.d.ts +1 -1
- package/dist/server/operations/get-system-metrics.d.ts +2 -2
- package/dist/server/operations/get-task-diagnostics.d.ts +45 -6
- package/dist/server/operations/get-task-diagnostics.js +101 -7
- package/dist/server/operations/get-update-result.d.ts +1 -1
- package/dist/server/operations/get-workflow-attributes.d.ts +1 -1
- package/dist/server/operations/get-workflow-events.d.ts +1 -1
- package/dist/server/operations/get-workflow-result.d.ts +1 -1
- package/dist/server/operations/get-workflow-timeline.d.ts +1 -1
- package/dist/server/operations/get-workflow.d.ts +1 -1
- package/dist/server/operations/list-checkpoints.d.ts +1 -1
- package/dist/server/operations/list-reviews.d.ts +1 -1
- package/dist/server/operations/list-schedules.d.ts +1 -1
- package/dist/server/operations/list-task-queues.d.ts +2 -2
- package/dist/server/operations/list-workers.d.ts +2 -2
- package/dist/server/operations/list-workflows.d.ts +1 -1
- package/dist/server/operations/operation-helpers.d.ts +16 -1
- package/dist/server/operations/operation-helpers.js +15 -3
- package/dist/server/operations/pause-schedule.d.ts +1 -1
- package/dist/server/operations/purge-workflows.d.ts +5 -5
- package/dist/server/operations/purge-workflows.js +2 -2
- package/dist/server/operations/query-workflow.d.ts +1 -1
- package/dist/server/operations/query-workflow.js +3 -2
- package/dist/server/operations/recover-all.d.ts +1 -1
- package/dist/server/operations/replay-workflow.d.ts +1 -1
- package/dist/server/operations/resume-schedule.d.ts +1 -1
- package/dist/server/operations/resume-workflow.js +2 -2
- package/dist/server/operations/set-workflow-attributes.d.ts +1 -1
- package/dist/server/operations/set-workflow-attributes.js +6 -3
- package/dist/server/operations/signal-workflow.js +8 -3
- package/dist/server/operations/single-workflow-tag-mutation.js +13 -3
- package/dist/server/operations/start-or-signal-workflow.d.ts +44 -0
- package/dist/server/operations/start-or-signal-workflow.js +130 -0
- package/dist/server/operations/start-workflow-options.d.ts +38 -0
- package/dist/server/operations/start-workflow-options.js +63 -0
- package/dist/server/operations/start-workflow-rest-input.d.ts +14 -0
- package/dist/server/operations/start-workflow-rest-input.js +31 -0
- package/dist/server/operations/start-workflow.d.ts +1 -1
- package/dist/server/operations/start-workflow.js +15 -92
- package/dist/server/operations/storage.d.ts +6 -6
- package/dist/server/operations/storage.js +24 -14
- package/dist/server/operations/stream-workflow-sse.d.ts +1 -1
- package/dist/server/operations/submit-review-decision.d.ts +1 -1
- package/dist/server/operations/submit-review-decision.js +6 -3
- package/dist/server/operations/suspend-workflow.d.ts +13 -0
- package/dist/server/operations/suspend-workflow.js +36 -0
- package/dist/server/operations/update-schedule.d.ts +1 -1
- package/dist/server/operations/update-schedule.js +7 -4
- package/dist/server/operations/update-workflow.d.ts +1 -1
- package/dist/server/operations/update-workflow.js +7 -3
- package/dist/server/operations/worker-drain.d.ts +8 -8
- package/dist/server/operations/worker-drain.js +11 -8
- package/dist/server/operations/workflow-events-subscription.d.ts +7 -8
- package/dist/server/operations/workflow-events-subscription.js +43 -8
- package/dist/server/rest-binding.d.ts +21 -8
- package/dist/server/rest-bindings.js +24 -0
- package/dist/server/rest-body.d.ts +10 -0
- package/dist/server/rest-body.js +80 -0
- package/dist/server/runtime/authentication-bridge.d.ts +1 -0
- package/dist/server/runtime/authentication-bridge.js +33 -6
- package/dist/server/runtime/client-visible-events.d.ts +3 -0
- package/dist/server/runtime/client-visible-events.js +65 -0
- package/dist/server/runtime/context.d.ts +7 -0
- package/dist/server/runtime/event-broadcasting.d.ts +6 -0
- package/dist/server/runtime/event-broadcasting.js +72 -38
- package/dist/server/runtime/retry.d.ts +1 -0
- package/dist/server/runtime/retry.js +14 -0
- package/dist/server/runtime/shutdown.d.ts +7 -6
- package/dist/server/runtime/shutdown.js +6 -1
- package/dist/server/runtime/task-dispatch.js +5 -3
- package/dist/server/runtime/task-polling.d.ts +16 -2
- package/dist/server/runtime/task-polling.js +80 -24
- package/dist/server/runtime/task-reconciliation.js +9 -1
- package/dist/server/runtime/task-result-resolution.d.ts +15 -0
- package/dist/server/runtime/task-result-resolution.js +81 -0
- package/dist/server/runtime/websocket-stream.d.ts +20 -1
- package/dist/server/runtime/websocket-stream.js +173 -7
- package/dist/server/runtime/websocket-upgrade.js +22 -3
- package/dist/server/runtime/websocket-worker.d.ts +1 -1
- package/dist/server/runtime/websocket-worker.js +46 -30
- package/dist/server/serve-internals.d.ts +11 -1
- package/dist/server/serve-internals.js +20 -2
- package/dist/server/task-state.d.ts +38 -0
- package/dist/server/task-state.js +28 -0
- package/dist/server/workflow-event-feed.d.ts +36 -115
- package/dist/server/workflow-event-feed.js +92 -27
- package/dist/service-worker/index.js +31 -31
- package/dist/storage/auto.js +1 -1
- package/dist/storage/bun-sql.js +24 -0
- package/dist/storage/capabilities.d.ts +10 -2
- package/dist/storage/capabilities.js +2 -2
- package/dist/storage/compressed-storage.js +1 -1
- package/dist/storage/default-scope.d.ts +7 -4
- package/dist/storage/http.js +2 -2
- package/dist/storage/index.d.ts +81 -4
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/interface.d.ts +189 -0
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +12 -0
- package/dist/storage/lmdb.d.ts +4 -3
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon-batch.d.ts +30 -0
- package/dist/storage/neon-batch.js +30 -0
- package/dist/storage/neon-value-mapping.d.ts +74 -0
- package/dist/storage/neon-value-mapping.js +23 -0
- package/dist/storage/neon.d.ts +124 -0
- package/dist/storage/neon.js +15 -0
- package/dist/storage/node-sqlite-loader.d.ts +71 -0
- package/dist/storage/node-sqlite-loader.js +41 -0
- package/dist/storage/node-sqlite.d.ts +1 -19
- package/dist/storage/node-sqlite.js +61 -32
- package/dist/storage/postgres-key-value-queries.d.ts +104 -0
- package/dist/storage/postgres-key-value-queries.js +101 -0
- package/dist/storage/resolve.d.ts +2 -165
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/storage-configuration.d.ts +209 -0
- package/dist/storage/storage-configuration.js +0 -0
- package/dist/storage/testing.d.ts +168 -0
- package/dist/storage/testing.js +2 -0
- package/dist/storage/text-value-store.d.ts +9 -9
- package/dist/storage/turso.d.ts +8 -0
- package/dist/storage/turso.js +2 -2
- package/dist/storage/typed-storage.js +1 -1
- package/dist/storage/web-extension.js +1 -1
- package/dist/testing/index.js +35 -35
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/index.js +9 -5
- package/dist/worker/long-poll.js +4 -0
- package/dist/worker/protocol-messages.d.ts +20 -0
- package/dist/worker/protocol-schemas.d.ts +32 -0
- package/dist/worker/protocol-schemas.js +8 -4
- package/dist/worker/protocol-task-result.d.ts +28 -0
- package/dist/worker/protocol-task-result.js +76 -0
- package/dist/worker/protocol.d.ts +4 -15
- package/dist/worker/protocol.js +1 -1
- package/dist/worker/registry/fair-share.d.ts +29 -0
- package/dist/worker/registry/fair-share.js +30 -0
- package/dist/worker/registry/routing.d.ts +18 -0
- package/dist/worker/registry/routing.js +14 -0
- package/dist/worker/registry/types.d.ts +7 -0
- package/dist/worker/registry.d.ts +16 -1
- package/dist/worker/registry.js +24 -36
- package/dist/workers/worker-replay-state.d.ts +32 -0
- package/dist/workers/worker-replay-state.js +35 -0
- package/dist/workers/worker-state-namespace.d.ts +21 -0
- package/dist/workers/worker-state-namespace.js +13 -0
- package/dist/workers/workflow-runner.d.ts +19 -15
- package/dist/workers/workflow-runner.js +72 -60
- package/dist/workers/workflow-worker-entry.js +5 -2
- package/package.json +21 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function stageAtomicWorkflowCommitSideEffects(internals, workflowId, sideEffects) {
|
|
2
|
+
if (sideEffects.conditions.length === 0 && sideEffects.operations.length === 0)
|
|
3
|
+
return;
|
|
4
|
+
const pending = internals.pendingAtomicWorkflowCommitSideEffects.get(workflowId);
|
|
5
|
+
if (pending === void 0) {
|
|
6
|
+
internals.pendingAtomicWorkflowCommitSideEffects.set(workflowId, {
|
|
7
|
+
conditions: [...sideEffects.conditions],
|
|
8
|
+
operations: [...sideEffects.operations]
|
|
9
|
+
});
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
pending.conditions.push(...sideEffects.conditions);
|
|
13
|
+
pending.operations.push(...sideEffects.operations);
|
|
14
|
+
}
|
|
15
|
+
export function takePendingAtomicWorkflowCommitSideEffects(internals, workflowId) {
|
|
16
|
+
const pending = internals.pendingAtomicWorkflowCommitSideEffects.get(workflowId);
|
|
17
|
+
if (pending === void 0)
|
|
18
|
+
return;
|
|
19
|
+
internals.pendingAtomicWorkflowCommitSideEffects.delete(workflowId);
|
|
20
|
+
if (pending.conditions.length === 0 && pending.operations.length === 0)
|
|
21
|
+
return;
|
|
22
|
+
return {
|
|
23
|
+
conditions: [...pending.conditions],
|
|
24
|
+
operations: [...pending.operations]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function clearPendingAtomicWorkflowCommitSideEffects(internals, workflowId) {
|
|
28
|
+
internals.pendingAtomicWorkflowCommitSideEffects.delete(workflowId);
|
|
29
|
+
}
|
|
30
|
+
export function pendingAtomicWorkflowCommitSideEffectsStagePut(internals, workflowId, key) {
|
|
31
|
+
const pending = internals.pendingAtomicWorkflowCommitSideEffects.get(workflowId);
|
|
32
|
+
if (pending === void 0)
|
|
33
|
+
return !1;
|
|
34
|
+
return pending.operations.some((operation) => operation.type === "put" && operation.key === key);
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type BatchOperation } from '../../storage/interface.ts';
|
|
2
|
+
import type { WorkflowHandle } from './handles.ts';
|
|
3
|
+
import type { EngineInternals } from './internals.ts';
|
|
4
|
+
type ChildCancellationCallbacks = {
|
|
5
|
+
getHandle: (workflowId: string) => WorkflowHandle;
|
|
6
|
+
};
|
|
7
|
+
export declare function buildChildCancellationOperations(internals: EngineInternals, workflowId: string, childWorkflowId: string): BatchOperation[];
|
|
8
|
+
export declare function registerChildCancellationHandler(internals: EngineInternals, workflowId: string, childWorkflowId: string, callbacks: ChildCancellationCallbacks): void;
|
|
9
|
+
export declare function rehydrateChildCancellationHandlers(internals: EngineInternals, workflowId: string, callbacks: ChildCancellationCallbacks): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { KEYS, decodeStorageKeyComponent } from "../../storage/interface.js";
|
|
2
|
+
import { registerCancelHandler } from "./cancel-handlers.js";
|
|
3
|
+
import { EMPTY_STORAGE_VALUE } from "./lifecycle/shared.js";
|
|
4
|
+
export function buildChildCancellationOperations(internals, workflowId, childWorkflowId) {
|
|
5
|
+
const operations = [
|
|
6
|
+
{
|
|
7
|
+
type: "put",
|
|
8
|
+
key: KEYS.childCancellation(workflowId, childWorkflowId),
|
|
9
|
+
value: EMPTY_STORAGE_VALUE
|
|
10
|
+
}
|
|
11
|
+
], needsCleanupMarker = !internals.workflowsNeedingTerminalCleanup.has(workflowId);
|
|
12
|
+
internals.workflowsNeedingTerminalCleanup.add(workflowId);
|
|
13
|
+
if (needsCleanupMarker)
|
|
14
|
+
operations.push({
|
|
15
|
+
type: "put",
|
|
16
|
+
key: KEYS.terminalCleanupNeeded(workflowId),
|
|
17
|
+
value: EMPTY_STORAGE_VALUE
|
|
18
|
+
});
|
|
19
|
+
return operations;
|
|
20
|
+
}
|
|
21
|
+
export function registerChildCancellationHandler(internals, workflowId, childWorkflowId, callbacks) {
|
|
22
|
+
registerCancelHandler(internals, workflowId, () => callbacks.getHandle(childWorkflowId).cancel());
|
|
23
|
+
}
|
|
24
|
+
export async function rehydrateChildCancellationHandlers(internals, workflowId, callbacks) {
|
|
25
|
+
for await (const [key] of internals.storage.scan(KEYS.childCancellationPrefix(workflowId))) {
|
|
26
|
+
const childWorkflowId = decodeChildCancellationKey(workflowId, key);
|
|
27
|
+
if (childWorkflowId === null)
|
|
28
|
+
continue;
|
|
29
|
+
registerChildCancellationHandler(internals, workflowId, childWorkflowId, callbacks);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function decodeChildCancellationKey(workflowId, key) {
|
|
33
|
+
const prefix = KEYS.childCancellationPrefix(workflowId);
|
|
34
|
+
if (!key.startsWith(prefix))
|
|
35
|
+
return null;
|
|
36
|
+
const encodedChildWorkflowId = key.slice(prefix.length);
|
|
37
|
+
if (encodedChildWorkflowId.length === 0 || encodedChildWorkflowId.includes(":"))
|
|
38
|
+
return null;
|
|
39
|
+
return decodeStorageKeyComponent(encodedChildWorkflowId);
|
|
40
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { assertOnTerminalConflictUnsupported } from "../start-workflow-validation.js";
|
|
2
|
+
import { stageAtomicWorkflowCommitSideEffects } from "./checkpoint-side-effects.js";
|
|
3
|
+
import {
|
|
4
|
+
buildChildCancellationOperations,
|
|
5
|
+
registerChildCancellationHandler
|
|
6
|
+
} from "./child-workflow-cancellation.js";
|
|
1
7
|
import { WorkflowAlreadyExistsError } from "./errors.js";
|
|
2
8
|
import { encodedValuesEqual } from "./state-utilities.js";
|
|
3
9
|
export async function processChildWorkflowOperation(internals, workflowId, operation, callbacks) {
|
|
@@ -37,6 +43,7 @@ async function resolveCollisionChildHandle(childWorkflowId, operation, execution
|
|
|
37
43
|
return callbacks.getHandle(childWorkflowId);
|
|
38
44
|
}
|
|
39
45
|
async function dispatchChildWorkflowStart(internals, childWorkflowId, operation, context, callbacks) {
|
|
46
|
+
assertOnTerminalConflictUnsupported(operation.options, "ctx.startChild");
|
|
40
47
|
applyPendingChildExecutionContext(internals, context);
|
|
41
48
|
try {
|
|
42
49
|
return await callbacks.start(operation.workflowType, operation.input, {
|
|
@@ -45,19 +52,29 @@ async function dispatchChildWorkflowStart(internals, childWorkflowId, operation,
|
|
|
45
52
|
} catch (error) {
|
|
46
53
|
if (!(error instanceof WorkflowAlreadyExistsError))
|
|
47
54
|
throw error;
|
|
48
|
-
return resolveCollisionChildHandle(childWorkflowId, operation, context.pendingExecutionStateOwnerId, error, callbacks);
|
|
55
|
+
return resolveCollisionChildHandle(childWorkflowId, operation, context.pendingExecutionStateOwnerId ?? void 0, error, callbacks);
|
|
49
56
|
} finally {
|
|
50
57
|
clearPendingChildExecutionContext(internals, context);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
export async function executeChildWorkflow(internals, workflowId, operation, currentDepth, callbacks) {
|
|
54
|
-
const rawId = operation.options?.id, childWorkflowId = typeof rawId === "string" ? rawId : crypto.randomUUID(), parentHeaders = internals.workflowHeaders.get(workflowId) ?? new Map,
|
|
61
|
+
const rawId = operation.options?.id, childWorkflowId = typeof rawId === "string" ? rawId : crypto.randomUUID(), parentHeaders = internals.workflowHeaders.get(workflowId) ?? new Map, parentState = await callbacks.loadWorkflowState(workflowId), parentClosePolicy = resolveChildWorkflowParentClosePolicy(operation), executionStateOwnerId = parentClosePolicy === "abandon" ? null : parentState?.executionStateOwnerId ?? workflowId, executeChild = async () => {
|
|
55
62
|
const context = {
|
|
56
63
|
pendingNestingDepth: currentDepth + 1,
|
|
57
64
|
pendingParentHeaders: internals.workflowHeaders.get(workflowId),
|
|
58
65
|
pendingExecutionStateOwnerId: executionStateOwnerId
|
|
59
|
-
};
|
|
60
|
-
|
|
66
|
+
}, childHandle = await dispatchChildWorkflowStart(internals, childWorkflowId, operation, context, callbacks);
|
|
67
|
+
if (parentClosePolicy === "abandon")
|
|
68
|
+
return createChildWorkflowHandleReference(childHandle.id);
|
|
69
|
+
if (parentClosePolicy === "request-cancel") {
|
|
70
|
+
stageAtomicWorkflowCommitSideEffects(internals, workflowId, {
|
|
71
|
+
conditions: [],
|
|
72
|
+
operations: buildChildCancellationOperations(internals, workflowId, childHandle.id)
|
|
73
|
+
});
|
|
74
|
+
registerChildCancellationHandler(internals, workflowId, childHandle.id, callbacks);
|
|
75
|
+
return createChildWorkflowHandleReference(childHandle.id);
|
|
76
|
+
}
|
|
77
|
+
return childHandle.result();
|
|
61
78
|
}, composedInterceptor = callbacks.getComposedWorkflowInterceptor();
|
|
62
79
|
if (!composedInterceptor)
|
|
63
80
|
return executeChild();
|
|
@@ -70,3 +87,9 @@ export async function executeChildWorkflow(internals, workflowId, operation, cur
|
|
|
70
87
|
parentHeaders
|
|
71
88
|
}, executeChild);
|
|
72
89
|
}
|
|
90
|
+
function resolveChildWorkflowParentClosePolicy(operation) {
|
|
91
|
+
return operation.options?.parentClosePolicy ?? "await";
|
|
92
|
+
}
|
|
93
|
+
function createChildWorkflowHandleReference(workflowId) {
|
|
94
|
+
return { id: workflowId };
|
|
95
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EngineInternals } from './internals.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Re-drive every in-process `ctx.waitUntil` waiter registered for a workflow.
|
|
4
|
+
* Called after an inline `onUpdate` handler runs (`tryInlineUpdateHandler`),
|
|
5
|
+
* since the handler may have mutated the workflow-local state a predicate reads.
|
|
6
|
+
* Each call wakes the parked `processWaitConditionOperation`, which re-evaluates
|
|
7
|
+
* its predicate against the (possibly mutated) state.
|
|
8
|
+
*
|
|
9
|
+
* Weft signals are pull-only (`ctx.waitForSignal`) and run no state-mutating
|
|
10
|
+
* handler, so signal delivery is intentionally NOT a re-drive trigger — `onUpdate`
|
|
11
|
+
* is the push path. Lives in its own module so `updates.ts` can call it without
|
|
12
|
+
* an import cycle through `operations-coordination.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function notifyConditionWaiters(internals: EngineInternals, workflowId: string): void;
|
|
@@ -3,6 +3,7 @@ import type { Storage as WeftStorage } from '../../storage/interface.ts';
|
|
|
3
3
|
import { ActivityWorkerDispatcher } from '../../workers/activity-worker-dispatcher.ts';
|
|
4
4
|
import type { ComposedWorkflowInterceptor, Interceptor } from '../interceptor.ts';
|
|
5
5
|
import { type AnyActivityDefinition, type AnyWorkflowDefinition, type EngineOptions, type RegisteredWorkflowDefinition } from '../types.ts';
|
|
6
|
+
import type { WorkflowLogRecord } from '../types/workflow-log.ts';
|
|
6
7
|
import type { EngineConstructorOptions, ExecutionStrategyBundle, RegistrationEntry, ResolvedOptions } from './engine-internal-types.ts';
|
|
7
8
|
export type KnownWorkflowNames<TWorkflows extends object> = Extract<keyof TWorkflows, string>;
|
|
8
9
|
declare const emptyWorkflowDefinitions: unique symbol;
|
|
@@ -18,7 +19,6 @@ export type EngineCreateRuntimeOptions = EngineConstructorOptions & {
|
|
|
18
19
|
workflows?: Record<string, AnyWorkflowDefinition> | undefined;
|
|
19
20
|
recover?: boolean | undefined;
|
|
20
21
|
acknowledgeUnknownWorkflowTypes?: boolean | undefined;
|
|
21
|
-
allowLegacyData?: boolean | undefined;
|
|
22
22
|
};
|
|
23
23
|
export type NormalizedWorkerExecutionConfiguration = {
|
|
24
24
|
mode: 'inline';
|
|
@@ -54,7 +54,9 @@ export declare function createExecutionStrategyBundle(parameters: {
|
|
|
54
54
|
getComposedWorkflowInterceptor?: () => ComposedWorkflowInterceptor | null;
|
|
55
55
|
resolveWorkflowType: (target: string | Function) => string;
|
|
56
56
|
registerCancelHandler?: (workflowId: string, handler: () => Promise<void> | void) => () => void;
|
|
57
|
+
recordFinalizerState?: (workflowId: string, value: unknown) => void;
|
|
57
58
|
getWorkflowServices?: (workflowId: string) => unknown;
|
|
59
|
+
getLogSink?: () => ((record: WorkflowLogRecord) => void) | undefined;
|
|
58
60
|
}): ExecutionStrategyBundle;
|
|
59
61
|
export declare function createActivityWorkerDispatcher(activityExecution: EngineConstructorOptions['activityExecution']): ActivityWorkerDispatcher | null;
|
|
60
62
|
export declare function createAlertManagerForEngine(engine: EventTarget, alerts: EngineOptions['alerts'] | undefined, getNow: () => number): AlertManager | null;
|
|
@@ -3,6 +3,7 @@ import { CompressedStorage } from "../../storage/compressed-storage.js";
|
|
|
3
3
|
import { MemoryStorage } from "../../storage/memory.js";
|
|
4
4
|
import { ActivityWorkerDispatcher } from "../../workers/activity-worker-dispatcher.js";
|
|
5
5
|
import { WorkerPool } from "../../workers/pool.js";
|
|
6
|
+
import { optionalInlineDependencies } from "../inline-execution-strategy.context-options.js";
|
|
6
7
|
import { InlineExecutionStrategy } from "../inline-execution-strategy.js";
|
|
7
8
|
import {
|
|
8
9
|
DEFAULT_RETENTION_SWEEP_BATCH_SIZE,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
DEFAULT_WORKER_TURN_TIMEOUT_MS,
|
|
15
16
|
MIN_WORKER_PROTOCOL_MESSAGE_BYTES
|
|
16
17
|
} from "../worker-protocol.js";
|
|
18
|
+
import { resolveOwnershipFields } from "./ownership-options.js";
|
|
17
19
|
import {
|
|
18
20
|
normalizeHistoryPolicy,
|
|
19
21
|
normalizePayloadSizePolicy,
|
|
@@ -70,7 +72,8 @@ export function copyWorkflowDefinition(type, registration) {
|
|
|
70
72
|
...registration.description === void 0 ? {} : { description: registration.description },
|
|
71
73
|
...registration.inputSchema === void 0 ? {} : { inputSchema: registration.inputSchema },
|
|
72
74
|
...registration.outputSchema === void 0 ? {} : { outputSchema: registration.outputSchema },
|
|
73
|
-
...registration.searchAttributes === void 0 ? {} : { searchAttributes: registration.searchAttributes }
|
|
75
|
+
...registration.searchAttributes === void 0 ? {} : { searchAttributes: registration.searchAttributes },
|
|
76
|
+
...registration.concurrency === void 0 ? {} : { concurrency: registration.concurrency }
|
|
74
77
|
};
|
|
75
78
|
}
|
|
76
79
|
function resolveRetentionFields(options) {
|
|
@@ -103,15 +106,26 @@ function resolveHistoryFields(options) {
|
|
|
103
106
|
payloadSizePolicy: normalizePayloadSizePolicy(options?.payloadSize, "options.payloadSize")
|
|
104
107
|
};
|
|
105
108
|
}
|
|
109
|
+
const DEFAULT_SECOND_INSTANCE_HEARTBEAT_INTERVAL_MS = 15000;
|
|
110
|
+
function resolveSecondInstanceFields(options) {
|
|
111
|
+
const enabled = defaultTo(options?.detectSecondInstance, !1), intervalMs = enabled ? normalizeRetentionDuration(options?.secondInstanceHeartbeatInterval, "options.secondInstanceHeartbeatInterval") ?? DEFAULT_SECOND_INSTANCE_HEARTBEAT_INTERVAL_MS : DEFAULT_SECOND_INSTANCE_HEARTBEAT_INTERVAL_MS;
|
|
112
|
+
return {
|
|
113
|
+
secondInstanceDetectionEnabled: enabled,
|
|
114
|
+
secondInstanceHeartbeatIntervalMs: intervalMs
|
|
115
|
+
};
|
|
116
|
+
}
|
|
106
117
|
export function resolveEngineOptions(storage, options, getNow) {
|
|
107
118
|
return {
|
|
108
119
|
storage,
|
|
109
120
|
getNow,
|
|
110
121
|
resolveWorkflowServices: options?.resolveWorkflowServices ?? null,
|
|
122
|
+
onLog: options?.onLog ?? null,
|
|
111
123
|
...resolveBooleanDefaults(options),
|
|
112
124
|
...resolveNumericDefaults(options),
|
|
113
125
|
...resolveRetentionFields(options),
|
|
114
|
-
...resolveHistoryFields(options)
|
|
126
|
+
...resolveHistoryFields(options),
|
|
127
|
+
...resolveSecondInstanceFields(options),
|
|
128
|
+
...resolveOwnershipFields(options)
|
|
115
129
|
};
|
|
116
130
|
}
|
|
117
131
|
export function normalizeWorkerExecutionConfiguration(options) {
|
|
@@ -171,19 +185,23 @@ export function createExecutionStrategyBundle(parameters) {
|
|
|
171
185
|
getComposedWorkflowInterceptor,
|
|
172
186
|
resolveWorkflowType,
|
|
173
187
|
registerCancelHandler,
|
|
174
|
-
|
|
188
|
+
recordFinalizerState,
|
|
189
|
+
getWorkflowServices,
|
|
190
|
+
getLogSink
|
|
175
191
|
} = parameters, workerExecutionConfiguration = normalizeWorkerExecutionConfiguration(options);
|
|
176
192
|
if (workerExecutionConfiguration.mode === "worker") {
|
|
177
193
|
const pool = new WorkerPool({
|
|
178
194
|
workerUrl: workerExecutionConfiguration.workerExecution.workerUrl,
|
|
179
195
|
concurrency: workerExecutionConfiguration.workerExecution.poolSize ?? 4,
|
|
180
196
|
smol: workerExecutionConfiguration.workerExecution.smol ?? !1
|
|
181
|
-
}), strategyOptions = {
|
|
197
|
+
}), logSink = getLogSink?.(), strategyOptions = {
|
|
182
198
|
broadcastEvents,
|
|
183
199
|
requireProtocolVersion: workerExecutionConfiguration.requireProtocolVersion,
|
|
184
200
|
discardOnCancel: workerExecutionConfiguration.discardOnCancel,
|
|
185
201
|
workflowTurnTimeoutMs: workerExecutionConfiguration.workflowTurnTimeoutMs,
|
|
186
|
-
maxProtocolMessageBytes: workerExecutionConfiguration.maxProtocolMessageBytes
|
|
202
|
+
maxProtocolMessageBytes: workerExecutionConfiguration.maxProtocolMessageBytes,
|
|
203
|
+
getNow,
|
|
204
|
+
...logSink !== void 0 && { onLog: logSink }
|
|
187
205
|
};
|
|
188
206
|
return {
|
|
189
207
|
strategy: new WorkerExecutionStrategy(pool, strategyOptions),
|
|
@@ -192,13 +210,17 @@ export function createExecutionStrategyBundle(parameters) {
|
|
|
192
210
|
}
|
|
193
211
|
const inlineStrategy = new InlineExecutionStrategy({
|
|
194
212
|
getRegistration,
|
|
195
|
-
...getComposedWorkflowInterceptor !== void 0 && { getComposedWorkflowInterceptor },
|
|
196
213
|
getNow,
|
|
197
214
|
maxNestingDepth,
|
|
198
215
|
development,
|
|
199
216
|
resolveWorkflowType,
|
|
200
|
-
...
|
|
201
|
-
|
|
217
|
+
...optionalInlineDependencies({
|
|
218
|
+
getComposedWorkflowInterceptor,
|
|
219
|
+
registerCancelHandler,
|
|
220
|
+
recordFinalizerState,
|
|
221
|
+
getWorkflowServices,
|
|
222
|
+
getLogSink
|
|
223
|
+
})
|
|
202
224
|
});
|
|
203
225
|
return { strategy: inlineStrategy, inlineStrategy };
|
|
204
226
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ContextOperationRequest } from '../context.ts';
|
|
2
|
+
import type { EngineInternals } from './internals.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The largest delay a host `setTimeout` can hold without overflow. Node and Bun
|
|
5
|
+
* store the delay in a 32-bit signed integer, so a value above this wraps and
|
|
6
|
+
* the timer fires almost immediately. A multi-day race-branch sleep must be
|
|
7
|
+
* chunked under this ceiling and re-armed, or it would win its race instantly.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_TIMER_DELAY_MS = 2147483647;
|
|
10
|
+
/**
|
|
11
|
+
* Compute the next host-timer delay for a race-branch sleep: the milliseconds
|
|
12
|
+
* remaining until the deterministic `scheduledFireAt` deadline, clamped to
|
|
13
|
+
* `[0, MAX_TIMER_DELAY_MS]`. Clamping to the ceiling is what prevents a multi-day
|
|
14
|
+
* sleep from overflowing `setTimeout` and firing instantly — the caller re-arms
|
|
15
|
+
* against the same deadline until the remaining delay reaches `0`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function nextSleepTimerDelayMs(scheduledFireAt: number, now: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Abortable in-process `sleep` branch for `ctx.race` / `ctx.all`.
|
|
20
|
+
*
|
|
21
|
+
* Unlike a top-level `ctx.sleep` (which arms a durable timer and parks the whole
|
|
22
|
+
* generator), a sleep branch inside a coordination operation is a TRANSIENT
|
|
23
|
+
* in-process wait: the coordination operation as a whole is the durable unit, and
|
|
24
|
+
* on replay the cached winner short-circuits before any branch re-runs. So this
|
|
25
|
+
* must NOT touch `internals.scheduler` (a durable timer write would corrupt the
|
|
26
|
+
* timer index) — it waits with a plain timer that the race's AbortController can
|
|
27
|
+
* cancel when another branch wins.
|
|
28
|
+
*
|
|
29
|
+
* The deadline is the operation's deterministic `scheduledFireAt`, compared
|
|
30
|
+
* against the engine clock (`internals.options.getNow()`), not wall-clock
|
|
31
|
+
* `Date.now()`, so a clock-overriding deployment stays consistent. The remaining
|
|
32
|
+
* delay is recomputed against that absolute deadline on every chunk, which both
|
|
33
|
+
* chunks delays beyond {@link MAX_TIMER_DELAY_MS} (so a multi-day sleep does not
|
|
34
|
+
* overflow `setTimeout` and fire instantly) and self-corrects for timer drift.
|
|
35
|
+
*
|
|
36
|
+
* Note: because the timer is a real event-loop timer, a long sleep that WINS its
|
|
37
|
+
* race is not driven by a virtual-clock `advanceTime`; tests should use short
|
|
38
|
+
* real durations for sleep-wins paths (sleep-loses paths need no timing — the
|
|
39
|
+
* abort fires).
|
|
40
|
+
*
|
|
41
|
+
* The timer also observes the engine abort signal so a long sleep branch does
|
|
42
|
+
* not outlive engine disposal. `ctx.all` does not abort siblings (it has no
|
|
43
|
+
* loser), so without watching `internals.abortController.signal` a multi-day
|
|
44
|
+
* `ctx.all([ctx.sleep('30d')])` branch would keep a host timer alive after the
|
|
45
|
+
* engine is gone.
|
|
46
|
+
*/
|
|
47
|
+
export declare function executeSleepSubOperation(internals: EngineInternals, operation: Extract<ContextOperationRequest, {
|
|
48
|
+
type: 'sleep';
|
|
49
|
+
}>, signal?: AbortSignal): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Abortable in-process `wait-signal` branch for `ctx.race` / `ctx.all`.
|
|
52
|
+
*
|
|
53
|
+
* A wait-signal branch must never consume its durable signal record itself —
|
|
54
|
+
* when it is woken it does not yet know whether it WON its race. So on delivery
|
|
55
|
+
* it resolves with a {@link createDeferredConsumeEnvelope | deferred-consume
|
|
56
|
+
* envelope}: the single atomic {@link consumeSignalWithAtomicWorkflowCommit} is wrapped in
|
|
57
|
+
* `finalize` and performed ONLY by the coordinator, on the winner, strictly
|
|
58
|
+
* after `Promise.race` / `Promise.all` settles. A losing branch (race settled by
|
|
59
|
+
* a sibling → `signal` aborts) drops its envelope unfinalized and releases its
|
|
60
|
+
* waiter via {@link releaseSignalWaiter} WITHOUT consuming, so the signal
|
|
61
|
+
* survives for a later `waitForSignal` or a replay.
|
|
62
|
+
*
|
|
63
|
+
* Reads are non-destructive {@link peekSignal}s until the coordinator finalizes;
|
|
64
|
+
* the identity-guarded release (`expectedResolve === deliver`) ensures a loser
|
|
65
|
+
* never clobbers another waiter (e.g. a later top-level `waitForSignal`) that
|
|
66
|
+
* reused the shared `${workflowId}:${signalName}` key.
|
|
67
|
+
*/
|
|
68
|
+
export declare function executeWaitSignalSubOperation(internals: EngineInternals, workflowId: string, operation: Extract<ContextOperationRequest, {
|
|
69
|
+
type: 'wait-signal';
|
|
70
|
+
}>, signal?: AbortSignal): Promise<unknown>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createDeferredConsumeEnvelope } from "./deferred-consume-envelope.js";
|
|
2
|
+
import {
|
|
3
|
+
consumeSignalWithAtomicWorkflowCommit,
|
|
4
|
+
peekSignal,
|
|
5
|
+
releaseSignalWaiter,
|
|
6
|
+
trackWaiterKey
|
|
7
|
+
} from "./signals.js";
|
|
8
|
+
export const MAX_TIMER_DELAY_MS = 2147483647;
|
|
9
|
+
export function nextSleepTimerDelayMs(scheduledFireAt, now) {
|
|
10
|
+
return Math.min(Math.max(0, scheduledFireAt - now), MAX_TIMER_DELAY_MS);
|
|
11
|
+
}
|
|
12
|
+
export function executeSleepSubOperation(internals, operation, signal) {
|
|
13
|
+
signal?.throwIfAborted();
|
|
14
|
+
const engineAbort = internals.abortController.signal;
|
|
15
|
+
if (engineAbort.aborted)
|
|
16
|
+
return Promise.reject(engineAbort.reason ?? Error("aborted"));
|
|
17
|
+
if (nextSleepTimerDelayMs(operation.scheduledFireAt, internals.options.getNow()) === 0)
|
|
18
|
+
return Promise.resolve();
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
let timer;
|
|
21
|
+
const cleanup = () => {
|
|
22
|
+
signal?.removeEventListener("abort", onAbort);
|
|
23
|
+
engineAbort.removeEventListener("abort", onAbort);
|
|
24
|
+
}, onAbort = () => {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
cleanup();
|
|
27
|
+
reject(signal?.reason ?? engineAbort.reason ?? Error("aborted"));
|
|
28
|
+
}, arm = () => {
|
|
29
|
+
const remainingMs = nextSleepTimerDelayMs(operation.scheduledFireAt, internals.options.getNow());
|
|
30
|
+
if (remainingMs === 0) {
|
|
31
|
+
cleanup();
|
|
32
|
+
resolve();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
timer = setTimeout(arm, remainingMs);
|
|
36
|
+
};
|
|
37
|
+
signal?.addEventListener("abort", onAbort, { once: !0 });
|
|
38
|
+
engineAbort.addEventListener("abort", onAbort, { once: !0 });
|
|
39
|
+
arm();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function executeWaitSignalSubOperation(internals, workflowId, operation, signal) {
|
|
43
|
+
signal?.throwIfAborted();
|
|
44
|
+
const { signalName } = operation, waiterKey = `${workflowId}:${signalName}`, engineAbort = internals.abortController.signal;
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
let settled = !1, registered = !1;
|
|
47
|
+
const { promise: delivered, resolve: deliver } = Promise.withResolvers(), cleanup = () => {
|
|
48
|
+
signal?.removeEventListener("abort", onAbort);
|
|
49
|
+
engineAbort.removeEventListener("abort", onAbort);
|
|
50
|
+
}, finalize = async () => {
|
|
51
|
+
const consumed = await consumeSignalWithAtomicWorkflowCommit(internals, workflowId, signalName);
|
|
52
|
+
return consumed.found ? consumed.payload : void 0;
|
|
53
|
+
}, onAbort = () => {
|
|
54
|
+
if (settled)
|
|
55
|
+
return;
|
|
56
|
+
settled = !0;
|
|
57
|
+
cleanup();
|
|
58
|
+
if (registered)
|
|
59
|
+
releaseSignalWaiter(internals, workflowId, waiterKey, deliver);
|
|
60
|
+
reject(signal?.reason ?? engineAbort.reason ?? Error("aborted"));
|
|
61
|
+
}, win = () => {
|
|
62
|
+
if (settled)
|
|
63
|
+
return;
|
|
64
|
+
settled = !0;
|
|
65
|
+
cleanup();
|
|
66
|
+
resolve(createDeferredConsumeEnvelope(finalize));
|
|
67
|
+
}, fail = (error) => {
|
|
68
|
+
if (settled)
|
|
69
|
+
return;
|
|
70
|
+
settled = !0;
|
|
71
|
+
cleanup();
|
|
72
|
+
if (registered)
|
|
73
|
+
releaseSignalWaiter(internals, workflowId, waiterKey, deliver);
|
|
74
|
+
reject(error);
|
|
75
|
+
};
|
|
76
|
+
signal?.addEventListener("abort", onAbort, { once: !0 });
|
|
77
|
+
engineAbort.addEventListener("abort", onAbort, { once: !0 });
|
|
78
|
+
if (engineAbort.aborted) {
|
|
79
|
+
onAbort();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
(async () => {
|
|
83
|
+
const existing = await peekSignal(internals, workflowId, signalName);
|
|
84
|
+
if (settled)
|
|
85
|
+
return;
|
|
86
|
+
if (existing.found) {
|
|
87
|
+
win();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
internals.signalWaiters.set(waiterKey, deliver);
|
|
91
|
+
trackWaiterKey(internals.signalWaitersByWorkflow, workflowId, waiterKey);
|
|
92
|
+
registered = !0;
|
|
93
|
+
const buffered = await peekSignal(internals, workflowId, signalName);
|
|
94
|
+
if (settled)
|
|
95
|
+
return;
|
|
96
|
+
if (buffered.found) {
|
|
97
|
+
releaseSignalWaiter(internals, workflowId, waiterKey, deliver);
|
|
98
|
+
win();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
await delivered;
|
|
102
|
+
if (settled)
|
|
103
|
+
return;
|
|
104
|
+
win();
|
|
105
|
+
})().catch(fail);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deferred-consume envelopes for `wait-signal` branches inside `ctx.race` /
|
|
3
|
+
* `ctx.all`.
|
|
4
|
+
*
|
|
5
|
+
* A `wait-signal` branch must NOT destructively consume its durable signal
|
|
6
|
+
* record when it is woken — at that moment it does not yet know whether it WON
|
|
7
|
+
* its race. If a losing branch consumed, it would delete a signal that a later
|
|
8
|
+
* `waitForSignal` (or a replay) still needs. So a woken wait-signal branch
|
|
9
|
+
* resolves with one of these envelopes instead of a value: the branch defers the
|
|
10
|
+
* single destructive {@link import('./signals.ts').consumeSignal} into
|
|
11
|
+
* `finalize`, and ONLY the coordinator — which authoritatively knows the race
|
|
12
|
+
* winner once `Promise.race` settles — calls `finalize()`, on the winner alone.
|
|
13
|
+
* Losing branches drop their envelope unfinalized and release their waiter
|
|
14
|
+
* without consuming, so the signal survives.
|
|
15
|
+
*
|
|
16
|
+
* The envelope is branded with a unique {@link DEFERRED_CONSUME_BRAND} symbol and
|
|
17
|
+
* detected ONLY by that symbol, never structurally — a user's signal payload can
|
|
18
|
+
* legitimately be an object shaped like `{ finalize }`, and a structural check
|
|
19
|
+
* would misfire on it.
|
|
20
|
+
*
|
|
21
|
+
* Envelopes must never reach the durable operation cache (a function cannot
|
|
22
|
+
* round-trip `encode`/`decode`), so the coordinator finalize-and-unwraps every
|
|
23
|
+
* winning branch's envelope before the operation result is written — including
|
|
24
|
+
* envelopes nested at arbitrary positions inside a `ctx.all` array result that a
|
|
25
|
+
* nested coordinator surfaces up to its parent.
|
|
26
|
+
*/
|
|
27
|
+
declare const DEFERRED_CONSUME_BRAND: unique symbol;
|
|
28
|
+
/**
|
|
29
|
+
* A branch result whose real value is produced by a single deferred consume that
|
|
30
|
+
* only the winning coordinator performs.
|
|
31
|
+
*/
|
|
32
|
+
export type DeferredConsumeEnvelope = {
|
|
33
|
+
readonly [DEFERRED_CONSUME_BRAND]: true;
|
|
34
|
+
/** Perform the single destructive consume and return the consumed payload. */
|
|
35
|
+
readonly finalize: () => Promise<unknown>;
|
|
36
|
+
};
|
|
37
|
+
/** Wrap a deferred consume into a branded envelope. */
|
|
38
|
+
export declare function createDeferredConsumeEnvelope(finalize: () => Promise<unknown>): DeferredConsumeEnvelope;
|
|
39
|
+
/** Detect an envelope by its brand symbol only (never structurally). */
|
|
40
|
+
export declare function isDeferredConsumeEnvelope(value: unknown): value is DeferredConsumeEnvelope;
|
|
41
|
+
/**
|
|
42
|
+
* Finalize-and-unwrap a coordination result before it is written to the durable
|
|
43
|
+
* cache. A winning `wait-signal` branch surfaces a {@link DeferredConsumeEnvelope}
|
|
44
|
+
* whose `finalize()` performs the single consume; a nested `ctx.all` branch
|
|
45
|
+
* surfaces an ARRAY that may hold envelopes at arbitrary positions, so arrays are
|
|
46
|
+
* walked and each element finalized. Any other value passes through untouched.
|
|
47
|
+
*
|
|
48
|
+
* This runs only on the WINNING path (race winner, or every branch of a settled
|
|
49
|
+
* `ctx.all`), so finalizing here is exactly the linearization point of "this
|
|
50
|
+
* branch won" — the consume happens strictly after the coordinator settled, and a
|
|
51
|
+
* losing branch's envelope is never reached, so its signal is never consumed.
|
|
52
|
+
*
|
|
53
|
+
* The array walk reconstructs arrays via `Promise.all(map(...))`. This is safe
|
|
54
|
+
* because coordination results are cache-safe encoded data: they round-trip
|
|
55
|
+
* `encode`/`decode` for the durable cache, so sparse holes, custom array
|
|
56
|
+
* properties, subclasses, and array identity are not preserved semantics here.
|
|
57
|
+
*/
|
|
58
|
+
export declare function finalizeAndUnwrap(value: unknown): Promise<unknown>;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const DEFERRED_CONSUME_BRAND = Symbol("weft.deferredConsume");
|
|
2
|
+
export function createDeferredConsumeEnvelope(finalize) {
|
|
3
|
+
return { [DEFERRED_CONSUME_BRAND]: !0, finalize };
|
|
4
|
+
}
|
|
5
|
+
export function isDeferredConsumeEnvelope(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && value[DEFERRED_CONSUME_BRAND] === !0;
|
|
7
|
+
}
|
|
8
|
+
export async function finalizeAndUnwrap(value) {
|
|
9
|
+
if (isDeferredConsumeEnvelope(value))
|
|
10
|
+
return value.finalize();
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return Promise.all(value.map((element) => finalizeAndUnwrap(element)));
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
@@ -10,6 +10,9 @@ export function disposeEngine(internals) {
|
|
|
10
10
|
resolveSignalWaiter();
|
|
11
11
|
internals.signalWaiters.clear();
|
|
12
12
|
internals.signalWaitersByWorkflow.clear();
|
|
13
|
+
for (const resolveConditionWaiter of internals.conditionWaiters.values())
|
|
14
|
+
resolveConditionWaiter();
|
|
15
|
+
internals.conditionWaiters.clear();
|
|
13
16
|
disposeQueuedInlineWorkflowStarts(internals);
|
|
14
17
|
internals.scheduler[Symbol.dispose]();
|
|
15
18
|
internals.strategy[Symbol.dispose]();
|
|
@@ -22,6 +25,8 @@ export function disposeEngine(internals) {
|
|
|
22
25
|
internals.retentionSweepInterval = null;
|
|
23
26
|
}
|
|
24
27
|
internals.nextRetentionSweepAt = null;
|
|
28
|
+
disposeSecondInstanceDetection(internals);
|
|
29
|
+
disposeLeaseManager(internals);
|
|
25
30
|
internals.handleCache.clear();
|
|
26
31
|
for (const waiter of internals.resultResolvers.values())
|
|
27
32
|
waiter.reject(new EngineDisposedError);
|
|
@@ -34,6 +39,7 @@ export function disposeEngine(internals) {
|
|
|
34
39
|
internals.workflowReviewIds.clear();
|
|
35
40
|
internals.parkedInlineWorkflows.clear();
|
|
36
41
|
internals.terminalizingWorkflows.clear();
|
|
42
|
+
internals.deliveredPendingUpdateIds.clear();
|
|
37
43
|
internals.reviewTimerIds.clear();
|
|
38
44
|
for (const controller of internals.pendingWebhooks)
|
|
39
45
|
controller.abort();
|
|
@@ -43,11 +49,14 @@ export function disposeEngine(internals) {
|
|
|
43
49
|
internals.checkpoints.clear();
|
|
44
50
|
internals.pendingExecutionStateOwnerId = void 0;
|
|
45
51
|
internals.workflowNestingDepths.clear();
|
|
52
|
+
internals.workflowServices.clear();
|
|
46
53
|
internals.workflowHeaders.clear();
|
|
47
54
|
internals.pendingStarts.clear();
|
|
48
55
|
internals.pendingScheduleCreations.clear();
|
|
49
56
|
internals.eventLogHeads.clear();
|
|
50
57
|
internals.pendingTimelineEntries.clear();
|
|
58
|
+
internals.pendingAtomicWorkflowCommitSideEffects.clear();
|
|
59
|
+
internals.pendingAsyncActivityResolutions.clear();
|
|
51
60
|
internals.workflowVersionTuples.clear();
|
|
52
61
|
internals.workflowFeedListeners.clear();
|
|
53
62
|
internals.activityRegistriesByWorkflow.clear();
|
|
@@ -56,3 +65,19 @@ export function disposeEngine(internals) {
|
|
|
56
65
|
internals.broadcastChannel?.close();
|
|
57
66
|
internals.broadcastChannel = null;
|
|
58
67
|
}
|
|
68
|
+
function disposeSecondInstanceDetection(internals) {
|
|
69
|
+
if (internals.secondInstanceDetectionInterval !== null) {
|
|
70
|
+
clearInterval(internals.secondInstanceDetectionInterval ?? void 0);
|
|
71
|
+
internals.secondInstanceDetectionInterval = null;
|
|
72
|
+
}
|
|
73
|
+
if (internals.secondInstanceDetector !== null) {
|
|
74
|
+
internals.secondInstanceDetector.stop();
|
|
75
|
+
internals.secondInstanceDetector = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function disposeLeaseManager(internals) {
|
|
79
|
+
if (internals.leaseManager !== null) {
|
|
80
|
+
internals.leaseManager.stop();
|
|
81
|
+
internals.leaseManager = null;
|
|
82
|
+
}
|
|
83
|
+
}
|