@temelj/workflow 0.0.0-alpha.3 → 0.0.0-alpha.4
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 +394 -2
- package/dist/attributes.d.mts +11 -9
- package/dist/attributes.mjs +23 -5
- package/dist/bundle.d.mts +5 -23
- package/dist/bundle.mjs +2 -18
- package/dist/client/create.d.mts +26 -23
- package/dist/client/create.mjs +26 -32
- package/dist/client/facades.d.mts +12 -18
- package/dist/client/facades.mjs +102 -93
- package/dist/client/mod.mjs +1 -2
- package/dist/client/run-handle.d.mts +17 -54
- package/dist/client/run-handle.mjs +35 -105
- package/dist/client/worker-options.d.mts +8 -8
- package/dist/client/worker-options.mjs +11 -11
- package/dist/cloudflare/cloudflare.d.mts +4 -5
- package/dist/cloudflare/codec.d.mts +28 -13
- package/dist/cloudflare/codec.mjs +40 -17
- package/dist/cloudflare/entrypoint.d.mts +3 -4
- package/dist/cloudflare/entrypoint.mjs +4 -3
- package/dist/cloudflare/execution.d.mts +3 -4
- package/dist/cloudflare/execution.mjs +20 -13
- package/dist/cloudflare/host.d.mts +6 -7
- package/dist/cloudflare/host.mjs +7 -6
- package/dist/cloudflare/mod.d.mts +4 -4
- package/dist/cloudflare/mod.mjs +2 -2
- package/dist/cloudflare/name.d.mts +3 -4
- package/dist/cloudflare/name.mjs +3 -3
- package/dist/cloudflare/registry.d.mts +3 -23
- package/dist/cloudflare/registry.mjs +2 -20
- package/dist/cloudflare/runtime.d.mts +11 -18
- package/dist/cloudflare/runtime.mjs +52 -73
- package/dist/cloudflare/step.d.mts +6 -6
- package/dist/cloudflare/step.mjs +69 -57
- package/dist/cloudflare/types.d.mts +17 -36
- package/dist/collection.d.mts +8 -11
- package/dist/collection.mjs +10 -14
- package/dist/compiled-function.d.mts +14 -19
- package/dist/compiled-function.mjs +12 -24
- package/dist/compiled.d.mts +4 -0
- package/dist/compiled.mjs +4 -0
- package/dist/compiler/ast.d.mts +26 -0
- package/dist/{vite → compiler}/ast.mjs +24 -16
- package/dist/{vite → compiler}/error.d.mts +4 -6
- package/dist/{vite → compiler}/error.mjs +14 -16
- package/dist/compiler/manifest.d.mts +6 -0
- package/dist/{vite → compiler}/manifest.mjs +9 -7
- package/dist/compiler/plugin.d.mts +7 -0
- package/dist/{vite → compiler}/plugin.mjs +45 -46
- package/dist/compiler/safety.d.mts +12 -0
- package/dist/{vite → compiler}/safety.mjs +5 -11
- package/dist/{vite → compiler}/source-edit.d.mts +3 -4
- package/dist/{vite → compiler}/source-edit.mjs +1 -1
- package/dist/{vite → compiler}/source-map.d.mts +4 -3
- package/dist/{vite → compiler}/source-map.mjs +3 -3
- package/dist/compiler/source.d.mts +7 -0
- package/dist/{vite → compiler}/source.mjs +1 -1
- package/dist/compiler/transform.d.mts +12 -0
- package/dist/{vite → compiler}/transform.mjs +37 -38
- package/dist/definition.d.mts +17 -25
- package/dist/definition.mjs +19 -35
- package/dist/engine/child-workflow.d.mts +5 -9
- package/dist/engine/child-workflow.mjs +46 -67
- package/dist/engine/command-identity.d.mts +5 -6
- package/dist/engine/command-identity.mjs +9 -5
- package/dist/engine/context.d.mts +17 -0
- package/dist/engine/create.d.mts +36 -94
- package/dist/engine/create.mjs +55 -260
- package/dist/engine/deterministic.d.mts +6 -11
- package/dist/engine/deterministic.mjs +47 -68
- package/dist/engine/durable-command.d.mts +5 -5
- package/dist/engine/durable-command.mjs +2 -2
- package/dist/engine/execution-service.d.mts +20 -24
- package/dist/engine/execution-service.mjs +54 -52
- package/dist/engine/hooks.d.mts +17 -39
- package/dist/engine/hooks.mjs +73 -94
- package/dist/engine/inspection.d.mts +23 -15
- package/dist/engine/inspection.mjs +55 -29
- package/dist/engine/lifecycle.d.mts +6 -12
- package/dist/engine/lifecycle.mjs +5 -5
- package/dist/engine/lock-replay.d.mts +8 -15
- package/dist/engine/lock-replay.mjs +12 -25
- package/dist/engine/lock.d.mts +10 -15
- package/dist/engine/lock.mjs +65 -51
- package/dist/engine/message.d.mts +14 -34
- package/dist/engine/message.mjs +94 -127
- package/dist/engine/observation.d.mts +9 -11
- package/dist/engine/observation.mjs +18 -27
- package/dist/engine/replay.d.mts +18 -19
- package/dist/engine/replay.mjs +32 -56
- package/dist/engine/resume.d.mts +16 -0
- package/dist/engine/resume.mjs +24 -0
- package/dist/engine/retry.d.mts +15 -19
- package/dist/engine/retry.mjs +17 -17
- package/dist/engine/run-data.d.mts +4 -8
- package/dist/engine/run-data.mjs +24 -22
- package/dist/engine/run-service.d.mts +24 -33
- package/dist/engine/run-service.mjs +125 -93
- package/dist/engine/run-utils.d.mts +11 -13
- package/dist/engine/run-utils.mjs +23 -46
- package/dist/engine/schedule.d.mts +8 -22
- package/dist/engine/schedule.mjs +37 -34
- package/dist/engine/serialization.d.mts +9 -6
- package/dist/engine/serialization.mjs +30 -21
- package/dist/engine/signals.d.mts +23 -0
- package/dist/engine/signals.mjs +41 -0
- package/dist/engine/start.d.mts +18 -0
- package/dist/engine/start.mjs +88 -0
- package/dist/engine/state.d.mts +37 -67
- package/dist/engine/state.mjs +119 -280
- package/dist/engine/step-api.d.mts +5 -8
- package/dist/engine/step-api.mjs +16 -16
- package/dist/engine/stream-reader.d.mts +12 -0
- package/dist/engine/stream-reader.mjs +154 -0
- package/dist/engine/stream.d.mts +9 -54
- package/dist/engine/stream.mjs +54 -196
- package/dist/engine/summary/recovery.d.mts +35 -0
- package/dist/engine/summary/recovery.mjs +363 -0
- package/dist/engine/summary/runs.d.mts +43 -0
- package/dist/engine/summary/runs.mjs +294 -0
- package/dist/engine/summary/step-attempts.d.mts +5 -10
- package/dist/engine/summary/step-attempts.mjs +157 -36
- package/dist/engine/summary/tally.d.mts +44 -0
- package/dist/engine/summary/tally.mjs +142 -0
- package/dist/engine/task.d.mts +4 -5
- package/dist/engine/task.mjs +40 -48
- package/dist/errors/base.d.mts +17 -77
- package/dist/errors/base.mjs +26 -327
- package/dist/errors/capability.d.mts +3 -6
- package/dist/errors/capability.mjs +4 -8
- package/dist/errors/codes.d.mts +116 -0
- package/dist/{types/error-code.mjs → errors/codes.mjs} +2 -17
- package/dist/errors/definition.d.mts +3 -17
- package/dist/errors/definition.mjs +5 -42
- package/dist/errors/failures.d.mts +17 -51
- package/dist/errors/failures.mjs +35 -102
- package/dist/errors/hook.d.mts +5 -9
- package/dist/errors/hook.mjs +4 -16
- package/dist/errors/implementation.d.mts +3 -6
- package/dist/errors/implementation.mjs +7 -12
- package/dist/errors/lock.d.mts +7 -20
- package/dist/errors/lock.mjs +8 -44
- package/dist/errors/message.d.mts +14 -59
- package/dist/errors/message.mjs +13 -39
- package/dist/errors/mod.d.mts +4 -5
- package/dist/errors/mod.mjs +5 -7
- package/dist/errors/records.d.mts +10 -4
- package/dist/errors/records.mjs +256 -256
- package/dist/errors/run.d.mts +27 -68
- package/dist/errors/run.mjs +31 -85
- package/dist/errors/schedule.d.mts +7 -18
- package/dist/errors/schedule.mjs +7 -39
- package/dist/errors/step.d.mts +12 -45
- package/dist/errors/step.mjs +13 -34
- package/dist/errors/stream.d.mts +8 -16
- package/dist/errors/stream.mjs +7 -41
- package/dist/esbuild.d.mts +6 -4
- package/dist/esbuild.mjs +2 -1
- package/dist/events/descriptors.d.mts +12 -241
- package/dist/events/descriptors.mjs +12 -5
- package/dist/history/projection.d.mts +4 -6
- package/dist/history/projection.mjs +22 -26
- package/dist/history/replay-projection.d.mts +44 -48
- package/dist/history/replay-projection.mjs +41 -50
- package/dist/history/{mod.d.mts → replay.d.mts} +16 -21
- package/dist/history/{mod.mjs → replay.mjs} +21 -25
- package/dist/history/sequencer.d.mts +10 -11
- package/dist/history/sequencer.mjs +11 -7
- package/dist/history/step-attempts.d.mts +4 -7
- package/dist/history/step-attempts.mjs +8 -9
- package/dist/history/timeline.d.mts +4 -13
- package/dist/history/timeline.mjs +46 -265
- package/dist/history/validator.d.mts +5 -7
- package/dist/history/validator.mjs +9 -24
- package/dist/hook-token.d.mts +7 -0
- package/dist/hook-token.mjs +32 -0
- package/dist/ids.d.mts +8 -0
- package/dist/ids.mjs +21 -0
- package/dist/message-options.d.mts +11 -5
- package/dist/message-options.mjs +9 -7
- package/dist/mod.d.mts +32 -36
- package/dist/mod.mjs +9 -13
- package/dist/otel/metrics.d.mts +31 -0
- package/dist/otel/metrics.mjs +60 -0
- package/dist/otel/mod.d.mts +3 -0
- package/dist/otel/mod.mjs +3 -0
- package/dist/otel/spans.d.mts +24 -0
- package/dist/otel/spans.mjs +218 -0
- package/dist/otel/support.d.mts +15 -8
- package/dist/otel/support.mjs +18 -40
- package/dist/{otel.d.mts → otel/telemetry.d.mts} +5 -6
- package/dist/otel/telemetry.mjs +305 -0
- package/dist/pagination.d.mts +6 -12
- package/dist/pagination.mjs +10 -14
- package/dist/registry.d.mts +8 -5
- package/dist/registry.mjs +19 -10
- package/dist/rolldown.d.mts +6 -4
- package/dist/rolldown.mjs +2 -1
- package/dist/rollup.d.mts +6 -4
- package/dist/rollup.mjs +2 -1
- package/dist/rspack.d.mts +6 -4
- package/dist/rspack.mjs +2 -1
- package/dist/run-status.d.mts +29 -0
- package/dist/run-status.mjs +42 -0
- package/dist/schema/common.d.mts +22 -0
- package/dist/schema/common.mjs +54 -0
- package/dist/schema/error.d.mts +17 -0
- package/dist/schema/error.mjs +39 -0
- package/dist/schema/events.d.mts +446 -0
- package/dist/schema/events.mjs +235 -0
- package/dist/schema/pagination.d.mts +5 -0
- package/dist/schema/pagination.mjs +11 -0
- package/dist/schema/persisted-value.d.mts +8 -0
- package/dist/schema/persisted-value.mjs +94 -0
- package/dist/schema/run.d.mts +51 -0
- package/dist/schema/run.mjs +88 -0
- package/dist/schema/store.d.mts +94 -0
- package/dist/schema/store.mjs +116 -0
- package/dist/step-definition.d.mts +4 -9
- package/dist/step-definition.mjs +2 -2
- package/dist/store/capabilities.d.mts +8 -9
- package/dist/store/capabilities.mjs +7 -7
- package/dist/store/cleanup.d.mts +9 -14
- package/dist/store/cleanup.mjs +86 -85
- package/dist/store/create.d.mts +28 -29
- package/dist/store/create.mjs +10 -11
- package/dist/store/events.d.mts +48 -0
- package/dist/store/events.mjs +263 -0
- package/dist/store/indexes.d.mts +25 -0
- package/dist/store/indexes.mjs +282 -0
- package/dist/store/instrumentation.d.mts +2 -3
- package/dist/store/instrumentation.mjs +30 -30
- package/dist/store/lock.d.mts +4 -5
- package/dist/store/lock.mjs +5 -7
- package/dist/store/materialization.d.mts +10 -17
- package/dist/store/materialization.mjs +39 -33
- package/dist/store/mod.d.mts +3 -3
- package/dist/store/mod.mjs +2 -2
- package/dist/store/query.d.mts +13 -17
- package/dist/store/query.mjs +13 -13
- package/dist/store/run.d.mts +25 -34
- package/dist/store/run.mjs +67 -108
- package/dist/store/schedule.d.mts +6 -8
- package/dist/store/schedule.mjs +11 -11
- package/dist/store/step-attempt.d.mts +9 -12
- package/dist/store/step-attempt.mjs +9 -9
- package/dist/store/storage-value.d.mts +3 -3
- package/dist/store/storage-value.mjs +17 -1
- package/dist/store/validation.d.mts +17 -20
- package/dist/store/validation.mjs +30 -33
- package/dist/store-keys.d.mts +35 -47
- package/dist/store-keys.mjs +9 -17
- package/dist/telemetry.d.mts +16 -16
- package/dist/telemetry.mjs +3 -3
- package/dist/temporal.d.mts +11 -16
- package/dist/temporal.mjs +8 -9
- package/dist/timer.d.mts +12 -10
- package/dist/timer.mjs +11 -3
- package/dist/types/cleanup.d.mts +13 -50
- package/dist/types/cleanup.mjs +1 -22
- package/dist/types/client.d.mts +101 -162
- package/dist/types/{vite.d.mts → compiler.d.mts} +17 -24
- package/dist/types/compiler.mjs +1 -0
- package/dist/types/definition.d.mts +22 -34
- package/dist/types/engine-options.d.mts +10 -17
- package/dist/types/engine.d.mts +15 -274
- package/dist/types/error.d.mts +15 -217
- package/dist/types/error.mjs +1 -48
- package/dist/types/events.d.mts +59 -2730
- package/dist/types/events.mjs +1 -283
- package/dist/types/hook.d.mts +27 -85
- package/dist/types/hook.mjs +1 -66
- package/dist/types/ids.d.mts +9 -0
- package/dist/types/ids.mjs +1 -0
- package/dist/types/lock.d.mts +8 -26
- package/dist/types/lock.mjs +1 -18
- package/dist/types/message.d.mts +29 -43
- package/dist/types/observation.d.mts +43 -58
- package/dist/types/pagination.d.mts +6 -22
- package/dist/types/pagination.mjs +1 -13
- package/dist/types/result.d.mts +11 -43
- package/dist/types/retry.d.mts +7 -14
- package/dist/types/run-list.d.mts +9 -11
- package/dist/types/run-options.d.mts +25 -32
- package/dist/types/run.d.mts +35 -315
- package/dist/types/run.mjs +1 -207
- package/dist/types/runtime.d.mts +33 -145
- package/dist/types/runtime.mjs +1 -21
- package/dist/types/schedule.d.mts +13 -72
- package/dist/types/schedule.mjs +1 -48
- package/dist/types/step-attempts.d.mts +65 -261
- package/dist/types/step-attempts.mjs +1 -43
- package/dist/types/step.d.mts +66 -77
- package/dist/types/step.mjs +1 -5
- package/dist/types/store.d.mts +50 -182
- package/dist/types/stream.d.mts +19 -40
- package/dist/types/summary.d.mts +174 -278
- package/dist/types/telemetry.d.mts +23 -28
- package/dist/types/telemetry.mjs +1 -9
- package/dist/types/timeline.d.mts +46 -233
- package/dist/types/worker.d.mts +22 -29
- package/dist/values.d.mts +15 -0
- package/dist/values.mjs +57 -0
- package/dist/vite.d.mts +5 -6
- package/dist/vite.mjs +3 -4
- package/dist/webpack.d.mts +6 -4
- package/dist/webpack.mjs +2 -1
- package/dist/worker/error.d.mts +2 -9
- package/dist/worker/error.mjs +20 -32
- package/dist/worker/missing-implementation.d.mts +19 -0
- package/dist/worker/missing-implementation.mjs +62 -0
- package/dist/worker/worker.d.mts +18 -0
- package/dist/{worker.mjs → worker/worker.mjs} +64 -118
- package/package.json +28 -47
- package/dist/engine/execution-api.d.mts +0 -29
- package/dist/engine/execution-api.mjs +0 -33
- package/dist/engine/inspection-api.d.mts +0 -34
- package/dist/engine/inspection-api.mjs +0 -78
- package/dist/engine/mod.d.mts +0 -4
- package/dist/engine/mod.mjs +0 -2
- package/dist/engine/recovery.d.mts +0 -26
- package/dist/engine/recovery.mjs +0 -92
- package/dist/engine/retry-policy.d.mts +0 -4
- package/dist/engine/retry-policy.mjs +0 -4
- package/dist/engine/start-api.d.mts +0 -30
- package/dist/engine/start-api.mjs +0 -99
- package/dist/engine/summary/active-events.d.mts +0 -34
- package/dist/engine/summary/active-events.mjs +0 -69
- package/dist/engine/summary/child-workflow-runs.d.mts +0 -24
- package/dist/engine/summary/child-workflow-runs.mjs +0 -138
- package/dist/engine/summary/child-workflow-waits.d.mts +0 -21
- package/dist/engine/summary/child-workflow-waits.mjs +0 -67
- package/dist/engine/summary/recovery-child-workflow-waits.d.mts +0 -11
- package/dist/engine/summary/recovery-child-workflow-waits.mjs +0 -89
- package/dist/engine/summary/recovery-due-runs.d.mts +0 -16
- package/dist/engine/summary/recovery-due-runs.mjs +0 -52
- package/dist/engine/summary/recovery-failed-runs.d.mts +0 -14
- package/dist/engine/summary/recovery-failed-runs.mjs +0 -33
- package/dist/engine/summary/recovery-lease-runs.d.mts +0 -16
- package/dist/engine/summary/recovery-lease-runs.mjs +0 -69
- package/dist/engine/summary/recovery-locks.d.mts +0 -18
- package/dist/engine/summary/recovery-locks.mjs +0 -100
- package/dist/engine/summary/recovery-message-waits.d.mts +0 -11
- package/dist/engine/summary/recovery-message-waits.mjs +0 -74
- package/dist/engine/summary/recovery-retry-runs.d.mts +0 -17
- package/dist/engine/summary/recovery-retry-runs.mjs +0 -65
- package/dist/engine/summary/recovery-run-timestamps.d.mts +0 -13
- package/dist/engine/summary/recovery-run-timestamps.mjs +0 -18
- package/dist/engine/summary/recovery-runs.d.mts +0 -23
- package/dist/engine/summary/recovery-runs.mjs +0 -54
- package/dist/engine/summary/recovery-schedules.d.mts +0 -10
- package/dist/engine/summary/recovery-schedules.mjs +0 -46
- package/dist/engine/summary/recovery-sleep-waits.d.mts +0 -10
- package/dist/engine/summary/recovery-sleep-waits.mjs +0 -53
- package/dist/engine/summary/recovery-waits.d.mts +0 -21
- package/dist/engine/summary/recovery-waits.mjs +0 -29
- package/dist/engine/summary/run-availability.d.mts +0 -13
- package/dist/engine/summary/run-availability.mjs +0 -37
- package/dist/engine/summary/run-cleanup.d.mts +0 -14
- package/dist/engine/summary/run-cleanup.mjs +0 -44
- package/dist/engine/summary/run-failure.d.mts +0 -14
- package/dist/engine/summary/run-failure.mjs +0 -62
- package/dist/engine/summary/run-hooks.d.mts +0 -14
- package/dist/engine/summary/run-hooks.mjs +0 -63
- package/dist/engine/summary/run-lease.d.mts +0 -11
- package/dist/engine/summary/run-lease.mjs +0 -64
- package/dist/engine/summary/run-message-waits.d.mts +0 -15
- package/dist/engine/summary/run-message-waits.mjs +0 -62
- package/dist/engine/summary/run-metrics.d.mts +0 -31
- package/dist/engine/summary/run-metrics.mjs +0 -93
- package/dist/engine/summary/run-retry.d.mts +0 -9
- package/dist/engine/summary/run-retry.mjs +0 -69
- package/dist/engine/summary/run-sleeps.d.mts +0 -15
- package/dist/engine/summary/run-sleeps.mjs +0 -61
- package/dist/engine/summary/run-state.d.mts +0 -26
- package/dist/engine/summary/run-state.mjs +0 -48
- package/dist/engine/summary/run-status.d.mts +0 -16
- package/dist/engine/summary/run-status.mjs +0 -35
- package/dist/engine/summary/run-streams.d.mts +0 -14
- package/dist/engine/summary/run-streams.mjs +0 -46
- package/dist/engine/summary/run-transition.d.mts +0 -9
- package/dist/engine/summary/run-transition.mjs +0 -39
- package/dist/engine/summary/run-workflow.d.mts +0 -9
- package/dist/engine/summary/run-workflow.mjs +0 -47
- package/dist/engine/summary/step-attempt-active-child-workflows.d.mts +0 -13
- package/dist/engine/summary/step-attempt-active-child-workflows.mjs +0 -55
- package/dist/engine/summary/step-attempt-active-fields.d.mts +0 -23
- package/dist/engine/summary/step-attempt-active-fields.mjs +0 -14
- package/dist/engine/summary/step-attempt-active-message-waits.d.mts +0 -12
- package/dist/engine/summary/step-attempt-active-message-waits.mjs +0 -47
- package/dist/engine/summary/step-attempt-active-sleeps.d.mts +0 -19
- package/dist/engine/summary/step-attempt-active-sleeps.mjs +0 -44
- package/dist/engine/summary/step-attempt-buckets.d.mts +0 -22
- package/dist/engine/summary/step-attempt-buckets.mjs +0 -152
- package/dist/engine/summary/step-attempt-failure.d.mts +0 -12
- package/dist/engine/summary/step-attempt-failure.mjs +0 -61
- package/dist/engine/summary/step-attempt-lifecycle.d.mts +0 -13
- package/dist/engine/summary/step-attempt-lifecycle.mjs +0 -19
- package/dist/engine/summary.d.mts +0 -32
- package/dist/engine/summary.mjs +0 -37
- package/dist/errors/details.d.mts +0 -13
- package/dist/errors/details.mjs +0 -66
- package/dist/errors/record-view.d.mts +0 -11
- package/dist/errors/record-view.mjs +0 -24
- package/dist/errors/runtime.d.mts +0 -12
- package/dist/errors/runtime.mjs +0 -24
- package/dist/events/mod.d.mts +0 -3
- package/dist/events/mod.mjs +0 -2
- package/dist/history/attempt-key.d.mts +0 -6
- package/dist/history/attempt-key.mjs +0 -7
- package/dist/inspection/mod.d.mts +0 -5
- package/dist/inspection/mod.mjs +0 -3
- package/dist/otel.mjs +0 -590
- package/dist/runtime.d.mts +0 -35
- package/dist/runtime.mjs +0 -198
- package/dist/store/append-projection.d.mts +0 -15
- package/dist/store/append-projection.mjs +0 -26
- package/dist/store/compaction.d.mts +0 -5
- package/dist/store/compaction.mjs +0 -8
- package/dist/store/event-append-project.d.mts +0 -15
- package/dist/store/event-append-project.mjs +0 -77
- package/dist/store/event-append.d.mts +0 -37
- package/dist/store/event-append.mjs +0 -80
- package/dist/store/event-history.d.mts +0 -22
- package/dist/store/event-history.mjs +0 -75
- package/dist/store/event.d.mts +0 -10
- package/dist/store/event.mjs +0 -28
- package/dist/store/idempotency.d.mts +0 -10
- package/dist/store/idempotency.mjs +0 -167
- package/dist/store/message-index.d.mts +0 -21
- package/dist/store/message-index.mjs +0 -122
- package/dist/store/revision.d.mts +0 -4
- package/dist/store/revision.mjs +0 -7
- package/dist/store/schema.d.mts +0 -14
- package/dist/store/schema.mjs +0 -17
- package/dist/types/common.d.mts +0 -20
- package/dist/types/common.mjs +0 -16
- package/dist/types/error-code.d.mts +0 -256
- package/dist/types/message-id.d.mts +0 -7
- package/dist/types/message-id.mjs +0 -5
- package/dist/types/run-id.d.mts +0 -7
- package/dist/types/run-id.mjs +0 -5
- package/dist/types/step-id.d.mts +0 -7
- package/dist/types/step-id.mjs +0 -5
- package/dist/types/stream-id.d.mts +0 -7
- package/dist/types/stream-id.mjs +0 -5
- package/dist/types/worker-id.d.mts +0 -7
- package/dist/types/worker-id.mjs +0 -5
- package/dist/utility.d.mts +0 -49
- package/dist/utility.mjs +0 -122
- package/dist/vite/ast.d.mts +0 -23
- package/dist/vite/generated-name.d.mts +0 -7
- package/dist/vite/generated-name.mjs +0 -9
- package/dist/vite/manifest.d.mts +0 -7
- package/dist/vite/plugin.d.mts +0 -7
- package/dist/vite/safety.d.mts +0 -12
- package/dist/vite/source.d.mts +0 -7
- package/dist/vite/transform.d.mts +0 -7
- package/dist/webhook.d.mts +0 -16
- package/dist/webhook.mjs +0 -17
- package/dist/worker.d.mts +0 -19
- /package/dist/{types/vite.mjs → engine/context.mjs} +0 -0
package/dist/runtime.mjs
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { WorkflowStateError } from "./errors/base.mjs";
|
|
2
|
-
import { WorkflowResultTimeoutError, WorkflowRunCanceledError, WorkflowRunNotFoundError } from "./errors/run.mjs";
|
|
3
|
-
import { durationTotal } from "./utility.mjs";
|
|
4
|
-
import { WorkflowDefinitionError } from "./errors/definition.mjs";
|
|
5
|
-
import { WorkflowRuntimeError } from "./errors/runtime.mjs";
|
|
6
|
-
import "./errors/mod.mjs";
|
|
7
|
-
import { getCompiledWorkflowDefinition } from "./compiled-function.mjs";
|
|
8
|
-
import { Registry } from "./registry.mjs";
|
|
9
|
-
import { createWorkflowBundleRegistry } from "./bundle.mjs";
|
|
10
|
-
import { workflowErrorFromRecord } from "./errors/records.mjs";
|
|
11
|
-
import { durationBetween } from "./temporal.mjs";
|
|
12
|
-
import { nonNegativeTimerDelay, sleep } from "./timer.mjs";
|
|
13
|
-
import { createWorkflowClient } from "./client/create.mjs";
|
|
14
|
-
import { parseWorkflowRuntime } from "./types/runtime.mjs";
|
|
15
|
-
import "temporal-polyfill/global";
|
|
16
|
-
//#region src/runtime.ts
|
|
17
|
-
const DEFAULT_RESULT_POLL_INTERVAL = Temporal.Duration.from({ milliseconds: 100 });
|
|
18
|
-
const WORKFLOW_RUNTIME_CLOCKS = /* @__PURE__ */ new WeakMap();
|
|
19
|
-
const WORKFLOW_RUNTIME_CLIENTS = /* @__PURE__ */ new WeakMap();
|
|
20
|
-
const WORKFLOW_RUNTIME_REGISTRIES = /* @__PURE__ */ new WeakMap();
|
|
21
|
-
/** Creates a workflow runtime backed by a workflow client. */
|
|
22
|
-
function createWorkflowRuntime(options = {}) {
|
|
23
|
-
return new WorkflowRuntime(options);
|
|
24
|
-
}
|
|
25
|
-
/** Workflow runtime implementation backed by a workflow client. */
|
|
26
|
-
var WorkflowRuntime = class {
|
|
27
|
-
runs;
|
|
28
|
-
schedules;
|
|
29
|
-
locks;
|
|
30
|
-
workers;
|
|
31
|
-
#client;
|
|
32
|
-
#registry;
|
|
33
|
-
constructor(options = {}) {
|
|
34
|
-
const { registry, workflows, ...runtimeOptions } = options;
|
|
35
|
-
if (registry !== void 0 && workflows !== void 0) throw new TypeError("Workflow runtime options cannot include both registry and workflows");
|
|
36
|
-
const now = options.now ?? Temporal.Now.instant;
|
|
37
|
-
this.#registry = registry ?? (workflows === void 0 ? new Registry() : createWorkflowBundleRegistry(workflows));
|
|
38
|
-
this.#client = createWorkflowClient({
|
|
39
|
-
...runtimeOptions,
|
|
40
|
-
registry: this.#registry,
|
|
41
|
-
now
|
|
42
|
-
});
|
|
43
|
-
this.runs = {
|
|
44
|
-
getHandle: async (runId) => await getWorkflowRuntimeRun(this, runId),
|
|
45
|
-
list: async (options) => await this.#client.runs.list(options)
|
|
46
|
-
};
|
|
47
|
-
this.schedules = this.#client.schedules;
|
|
48
|
-
this.locks = this.#client.locks;
|
|
49
|
-
this.workers = this.#client.workers;
|
|
50
|
-
WORKFLOW_RUNTIME_CLOCKS.set(this, now);
|
|
51
|
-
WORKFLOW_RUNTIME_CLIENTS.set(this, this.#client);
|
|
52
|
-
WORKFLOW_RUNTIME_REGISTRIES.set(this, this.#registry);
|
|
53
|
-
}
|
|
54
|
-
async close() {
|
|
55
|
-
await this.#client.close();
|
|
56
|
-
}
|
|
57
|
-
implementWorkflow(definition, handler) {
|
|
58
|
-
return this.#registry.implementWorkflow(definition, handler);
|
|
59
|
-
}
|
|
60
|
-
register(implementation) {
|
|
61
|
-
this.#registry.register(implementation);
|
|
62
|
-
}
|
|
63
|
-
async start(workflow, ...args) {
|
|
64
|
-
return await startWorkflowRuntimeRunUnknown(this, workflow, ...args);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
/** Starts a workflow through an explicit runtime and returns a client run handle. */
|
|
68
|
-
async function startWorkflowRuntimeRun(runtime, workflow, ...args) {
|
|
69
|
-
return await startWorkflowRuntimeRunUnknown(runtime, workflow, ...args);
|
|
70
|
-
}
|
|
71
|
-
async function startWorkflowRuntimeRunUnknown(runtime, workflow, ...args) {
|
|
72
|
-
parseWorkflowRuntime(runtime);
|
|
73
|
-
const client = getWorkflowRuntimeClient(runtime);
|
|
74
|
-
const registry = getWorkflowRuntimeRegistry(runtime);
|
|
75
|
-
if (typeof workflow === "function") {
|
|
76
|
-
const definition = getCompiledWorkflowDefinition(workflow);
|
|
77
|
-
if (definition === void 0) WorkflowDefinitionError.compiledMetadataMissing();
|
|
78
|
-
ensureWorkflowRegistered(registry, definition);
|
|
79
|
-
return await client.runs.start(definition.definition, args);
|
|
80
|
-
}
|
|
81
|
-
const target = workflow;
|
|
82
|
-
if (target.kind === "implementation") {
|
|
83
|
-
ensureWorkflowRegistered(registry, target);
|
|
84
|
-
return await client.runs.start(target.definition, args[0], args[1]);
|
|
85
|
-
}
|
|
86
|
-
return await client.runs.start(target, args[0], args[1]);
|
|
87
|
-
}
|
|
88
|
-
/** Returns a typed handle for an existing run through an explicit runtime. */
|
|
89
|
-
async function getWorkflowRuntimeRun(runtime, runId) {
|
|
90
|
-
parseWorkflowRuntime(runtime);
|
|
91
|
-
const run = await getWorkflowRuntimeClient(runtime).runs.get(runId);
|
|
92
|
-
if (run === void 0) WorkflowRunNotFoundError.notFound(runId);
|
|
93
|
-
return createStoredRunHandle(runtime, run);
|
|
94
|
-
}
|
|
95
|
-
function createStoredRunHandle(runtime, initialRun) {
|
|
96
|
-
const runId = initialRun.id;
|
|
97
|
-
const now = WORKFLOW_RUNTIME_CLOCKS.get(runtime) ?? Temporal.Now.instant;
|
|
98
|
-
const client = getWorkflowRuntimeClient(runtime);
|
|
99
|
-
const getRun = async () => {
|
|
100
|
-
const run = await client.runs.get(runId);
|
|
101
|
-
if (run === void 0) WorkflowRunNotFoundError.notFound(runId);
|
|
102
|
-
return run;
|
|
103
|
-
};
|
|
104
|
-
return {
|
|
105
|
-
runId,
|
|
106
|
-
workflowName: initialRun.workflowName,
|
|
107
|
-
...initialRun.workflowVersion === void 0 ? {} : { workflowVersion: initialRun.workflowVersion },
|
|
108
|
-
getRun,
|
|
109
|
-
async status() {
|
|
110
|
-
return (await getRun()).status;
|
|
111
|
-
},
|
|
112
|
-
async events() {
|
|
113
|
-
return await client.runs.events(runId);
|
|
114
|
-
},
|
|
115
|
-
async timeline() {
|
|
116
|
-
return await client.runs.timeline(runId);
|
|
117
|
-
},
|
|
118
|
-
async result(options) {
|
|
119
|
-
const pollInterval = nonNegativeTimerDelay(options?.pollInterval ?? DEFAULT_RESULT_POLL_INTERVAL, "Workflow result pollInterval").clampedDelay;
|
|
120
|
-
const timeout = options?.timeout;
|
|
121
|
-
const deadlineAt = timeout === void 0 ? void 0 : now().add(timeout);
|
|
122
|
-
while (true) {
|
|
123
|
-
const run = await client.runs.get(runId);
|
|
124
|
-
if (run === void 0) WorkflowRunNotFoundError.notFound(runId);
|
|
125
|
-
if (run.status === "completed") return run.output;
|
|
126
|
-
if (run.status === "failed") {
|
|
127
|
-
if (run.error === void 0) WorkflowStateError.failedRunMissingError(runId);
|
|
128
|
-
throw workflowErrorFromRecord(run.error);
|
|
129
|
-
}
|
|
130
|
-
if (run.status === "canceled") WorkflowRunCanceledError.canceled(runId);
|
|
131
|
-
let sleepDelay = pollInterval;
|
|
132
|
-
if (timeout !== void 0 && deadlineAt !== void 0) {
|
|
133
|
-
const remainingDelay = durationTotal(durationBetween(now(), deadlineAt));
|
|
134
|
-
if (remainingDelay <= 0) WorkflowResultTimeoutError.timedOut(runId, timeout);
|
|
135
|
-
sleepDelay = Math.min(sleepDelay, remainingDelay);
|
|
136
|
-
}
|
|
137
|
-
await sleep(sleepDelay);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
async getStreamInfo(streamIdOrName) {
|
|
141
|
-
return await client.streams.getInfo(runId, streamIdOrName);
|
|
142
|
-
},
|
|
143
|
-
followStream(streamIdOrName, options) {
|
|
144
|
-
return client.streams.follow(runId, streamIdOrName, options);
|
|
145
|
-
},
|
|
146
|
-
async waitForStream(streamIdOrName, options) {
|
|
147
|
-
return await client.streams.wait(runId, streamIdOrName, options);
|
|
148
|
-
},
|
|
149
|
-
async waitForStreamChunk(streamIdOrName, afterIndex, options) {
|
|
150
|
-
return await client.streams.waitForChunk(runId, streamIdOrName, afterIndex, options);
|
|
151
|
-
},
|
|
152
|
-
async waitForStreamTerminal(streamIdOrName, options) {
|
|
153
|
-
return await client.streams.waitForTerminal(runId, streamIdOrName, options);
|
|
154
|
-
},
|
|
155
|
-
async readStream(streamIdOrName, options) {
|
|
156
|
-
return await client.streams.read(runId, streamIdOrName, options);
|
|
157
|
-
},
|
|
158
|
-
async readStreamPage(streamIdOrName, options) {
|
|
159
|
-
return await client.streams.readPage(runId, streamIdOrName, options);
|
|
160
|
-
},
|
|
161
|
-
async reschedule(options) {
|
|
162
|
-
return await client.admin.reschedule(runId, options);
|
|
163
|
-
},
|
|
164
|
-
async releaseStaleLease(options) {
|
|
165
|
-
return await client.admin.releaseStaleLease(runId, options);
|
|
166
|
-
},
|
|
167
|
-
async retryFailed(options) {
|
|
168
|
-
return await client.admin.retryFailed(runId, options);
|
|
169
|
-
},
|
|
170
|
-
async markPermanentlyFailed(options) {
|
|
171
|
-
return await client.admin.markPermanentlyFailed(runId, options);
|
|
172
|
-
},
|
|
173
|
-
async setMetadata(metadata) {
|
|
174
|
-
return await client.admin.updateMetadata(runId, metadata);
|
|
175
|
-
},
|
|
176
|
-
async setAttributes(attributes) {
|
|
177
|
-
return await client.admin.setAttributes(runId, attributes);
|
|
178
|
-
},
|
|
179
|
-
async cancel() {
|
|
180
|
-
return await client.admin.cancel(runId);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function getWorkflowRuntimeClient(runtime) {
|
|
185
|
-
const client = WORKFLOW_RUNTIME_CLIENTS.get(runtime);
|
|
186
|
-
if (client === void 0) WorkflowRuntimeError.clientMissing();
|
|
187
|
-
return client;
|
|
188
|
-
}
|
|
189
|
-
function getWorkflowRuntimeRegistry(runtime) {
|
|
190
|
-
const registry = WORKFLOW_RUNTIME_REGISTRIES.get(runtime);
|
|
191
|
-
if (registry === void 0) WorkflowRuntimeError.registryMissing();
|
|
192
|
-
return registry;
|
|
193
|
-
}
|
|
194
|
-
function ensureWorkflowRegistered(registry, implementation) {
|
|
195
|
-
if (registry.get(implementation.definition) === void 0) registry.register(implementation);
|
|
196
|
-
}
|
|
197
|
-
//#endregion
|
|
198
|
-
export { WorkflowRuntime, createWorkflowRuntime, getWorkflowRuntimeRun, startWorkflowRuntimeRun };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RunId } from "../types/run-id.mjs";
|
|
2
|
-
import "../types/run.mjs";
|
|
3
|
-
import { EventRecord } from "../types/events.mjs";
|
|
4
|
-
import { WorkflowStorage } from "../types/store.mjs";
|
|
5
|
-
import { WorkflowEventAppendAtomicProjectionPlanner, WorkflowEventAppendSuccessOutcome } from "./event-append.mjs";
|
|
6
|
-
//#region src/store/append-projection.d.ts
|
|
7
|
-
interface WorkflowAppendProjectionPipeline {
|
|
8
|
-
readonly materializesAtomically: boolean;
|
|
9
|
-
readonly planAtomicProjections?: WorkflowEventAppendAtomicProjectionPlanner;
|
|
10
|
-
finalize(outcome: WorkflowEventAppendSuccessOutcome): Promise<readonly EventRecord[]>;
|
|
11
|
-
finalizePostCommit(outcome: WorkflowEventAppendSuccessOutcome): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
declare function createWorkflowAppendProjectionPipeline(storage: WorkflowStorage, namespace: string, runId: RunId, event: EventRecord): Promise<WorkflowAppendProjectionPipeline>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { WorkflowAppendProjectionPipeline, createWorkflowAppendProjectionPipeline };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { supportsWorkflowAtomicBatchWrite } from "./capabilities.mjs";
|
|
2
|
-
import { createWorkflowStepAttemptMaterializationStoragePlan, materializeStepAttemptForAppendOutcome } from "./materialization.mjs";
|
|
3
|
-
import { projectMessageIdempotencyIndexForAppendOutcome } from "./message-index.mjs";
|
|
4
|
-
//#region src/store/append-projection.ts
|
|
5
|
-
async function createWorkflowAppendProjectionPipeline(storage, namespace, runId, event) {
|
|
6
|
-
if (!supportsWorkflowAtomicBatchWrite(storage)) return createWorkflowAppendProjectionPipelineFromStepAttemptPlan(storage, namespace, runId, event, void 0);
|
|
7
|
-
return createWorkflowAppendProjectionPipelineFromStepAttemptPlan(storage, namespace, runId, event, await createWorkflowStepAttemptMaterializationStoragePlan(storage, namespace, runId, event));
|
|
8
|
-
}
|
|
9
|
-
function createWorkflowAppendProjectionPipelineFromStepAttemptPlan(storage, namespace, runId, event, initialStepAttemptPlan) {
|
|
10
|
-
return {
|
|
11
|
-
materializesAtomically: initialStepAttemptPlan?.materializes === true,
|
|
12
|
-
planAtomicProjections: createWorkflowAppendAtomicProjectionPlanner(storage, namespace, runId, event, initialStepAttemptPlan),
|
|
13
|
-
async finalize(outcome) {
|
|
14
|
-
return await projectMessageIdempotencyIndexForAppendOutcome(storage, namespace, runId, event, outcome);
|
|
15
|
-
},
|
|
16
|
-
async finalizePostCommit(outcome) {
|
|
17
|
-
if (!supportsWorkflowAtomicBatchWrite(storage)) await materializeStepAttemptForAppendOutcome(storage, namespace, runId, event, outcome);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function createWorkflowAppendAtomicProjectionPlanner(storage, namespace, runId, event, initialStepAttemptPlan) {
|
|
22
|
-
if (!supportsWorkflowAtomicBatchWrite(storage)) return;
|
|
23
|
-
return async (attempt) => attempt === 0 && initialStepAttemptPlan !== void 0 ? initialStepAttemptPlan : await createWorkflowStepAttemptMaterializationStoragePlan(storage, namespace, runId, event);
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { createWorkflowAppendProjectionPipeline };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
//#region src/store/compaction.d.ts
|
|
2
|
-
/** Removes undefined optional fields before persisting a workflow store record. */
|
|
3
|
-
declare function compactWorkflowStoreRecord<TRecord extends object>(record: TRecord): TRecord;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { compactWorkflowStoreRecord };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { omitUndefined } from "../collection.mjs";
|
|
2
|
-
//#region src/store/compaction.ts
|
|
3
|
-
/** Removes undefined optional fields before persisting a workflow store record. */
|
|
4
|
-
function compactWorkflowStoreRecord(record) {
|
|
5
|
-
return omitUndefined(record);
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
export { compactWorkflowStoreRecord };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RunId } from "../types/run-id.mjs";
|
|
2
|
-
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
3
|
-
import { EventRecord } from "../types/events.mjs";
|
|
4
|
-
import { WorkflowStorage } from "../types/store.mjs";
|
|
5
|
-
import { WorkflowEventAppendOutcome, WorkflowEventAppendSuccessOutcome } from "./event-append.mjs";
|
|
6
|
-
import { WorkflowAppendProjectionPipeline } from "./append-projection.mjs";
|
|
7
|
-
//#region src/store/event-append-project.d.ts
|
|
8
|
-
interface WorkflowEventAppendProjectionOutcome {
|
|
9
|
-
readonly outcome: WorkflowEventAppendOutcome;
|
|
10
|
-
readonly projectionPipeline?: WorkflowAppendProjectionPipeline;
|
|
11
|
-
}
|
|
12
|
-
declare function appendEventWithProjections(storage: WorkflowStorage, namespace: string, runId: RunId, event: EventRecord, projectionPipeline?: WorkflowAppendProjectionPipeline): Promise<WorkflowEventAppendSuccessOutcome>;
|
|
13
|
-
declare function appendEventWithProjectionPipelineIfRunCurrent(storage: WorkflowStorage, namespace: string, currentRun: WorkflowRunRecord, event: EventRecord): Promise<WorkflowEventAppendProjectionOutcome>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { WorkflowEventAppendProjectionOutcome, appendEventWithProjectionPipelineIfRunCurrent, appendEventWithProjections };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { supportsWorkflowAtomicBatchWrite, supportsWorkflowConditionalWrite } from "./capabilities.mjs";
|
|
2
|
-
import { isStoredWorkflowRunRevisionCurrent, isWorkflowRunStaleForAppend, rollbackAppendedEventIfRunStale } from "./run.mjs";
|
|
3
|
-
import { duplicateMessageAppendOutcome } from "./message-index.mjs";
|
|
4
|
-
import { createWorkflowAppendProjectionPipeline } from "./append-projection.mjs";
|
|
5
|
-
import { appendEventIfCurrent, appendEventIfRunRevisionCurrentAtomically, appendEventWithAtomicProjectionPlan, makeStaleRunAppendOutcome } from "./event-append.mjs";
|
|
6
|
-
//#region src/store/event-append-project.ts
|
|
7
|
-
async function appendEventWithProjections(storage, namespace, runId, event, projectionPipeline) {
|
|
8
|
-
const appendProjectionPipeline = projectionPipeline ?? await createWorkflowAppendProjectionPipeline(storage, namespace, runId, event);
|
|
9
|
-
const outcome = await appendEventWithAtomicProjectionPlan(storage, namespace, runId, event, appendProjectionPipeline.planAtomicProjections, duplicateMessageAppendOutcome);
|
|
10
|
-
await appendProjectionPipeline.finalizePostCommit(outcome);
|
|
11
|
-
return outcome;
|
|
12
|
-
}
|
|
13
|
-
async function appendEventWithProjectionPipelineIfRunCurrent(storage, namespace, currentRun, event) {
|
|
14
|
-
const runId = currentRun.id;
|
|
15
|
-
if (isWorkflowRunStaleForAppend(currentRun, event)) return { outcome: makeStaleRunAppendOutcome() };
|
|
16
|
-
const projectionPipeline = await createWorkflowAppendProjectionPipeline(storage, namespace, runId, event);
|
|
17
|
-
if (event.kind === "message_sent" && !supportsWorkflowAtomicBatchWrite(storage)) return await appendMessageEventIfRunCurrent(storage, namespace, currentRun, event, projectionPipeline);
|
|
18
|
-
if (!supportsWorkflowAtomicBatchWrite(storage) || projectionPipeline.materializesAtomically) return workflowEventAppendProjectionOutcome(await appendEventIfRunRevisionCurrentWithPostAppendGuard(storage, namespace, currentRun, event, projectionPipeline), projectionPipeline);
|
|
19
|
-
return workflowEventAppendProjectionOutcome(await appendEventIfRunRevisionCurrentAtomically(storage, namespace, currentRun, event, duplicateMessageAppendOutcome), projectionPipeline);
|
|
20
|
-
}
|
|
21
|
-
function workflowEventAppendProjectionOutcome(outcome, projectionPipeline) {
|
|
22
|
-
if (projectionPipeline === void 0) return { outcome };
|
|
23
|
-
return {
|
|
24
|
-
outcome,
|
|
25
|
-
projectionPipeline
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async function appendEventIfRunRevisionCurrentWithPostAppendGuard(storage, namespace, currentRun, event, projectionPipeline) {
|
|
29
|
-
const runId = currentRun.id;
|
|
30
|
-
if (!await isStoredWorkflowRunRevisionCurrent(storage, namespace, currentRun)) return makeStaleRunAppendOutcome();
|
|
31
|
-
const outcome = await appendEventWithProjections(storage, namespace, runId, event, projectionPipeline);
|
|
32
|
-
if (outcome.status !== "appended") return outcome;
|
|
33
|
-
return await guardAppendedEventAgainstStaleRun(storage, namespace, runId, event, outcome);
|
|
34
|
-
}
|
|
35
|
-
async function appendMessageEventIfRunCurrent(storage, namespace, currentRun, event, projectionPipeline) {
|
|
36
|
-
const runId = currentRun.id;
|
|
37
|
-
if (!await isStoredWorkflowRunRevisionCurrent(storage, namespace, currentRun)) return { outcome: makeStaleRunAppendOutcome() };
|
|
38
|
-
if (!supportsWorkflowConditionalWrite(storage)) {
|
|
39
|
-
const outcome = await appendEventWithProjections(storage, namespace, runId, event, projectionPipeline);
|
|
40
|
-
if (outcome.status !== "appended") return {
|
|
41
|
-
outcome,
|
|
42
|
-
projectionPipeline
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
outcome: await guardAppendedEventAgainstStaleRun(storage, namespace, runId, event, outcome),
|
|
46
|
-
projectionPipeline
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const outcome = await appendEventIfCurrent(storage, namespace, runId, event, { detectDuplicate: duplicateMessageAppendOutcome });
|
|
50
|
-
if (outcome.status !== "appended") {
|
|
51
|
-
if (!await isStoredWorkflowRunRevisionCurrent(storage, namespace, currentRun)) return {
|
|
52
|
-
outcome: makeStaleRunAppendOutcome(),
|
|
53
|
-
projectionPipeline
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
outcome,
|
|
57
|
-
projectionPipeline
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (!await isStoredWorkflowRunRevisionCurrent(storage, namespace, currentRun)) {
|
|
61
|
-
await guardAppendedEventAgainstStaleRun(storage, namespace, runId, event, outcome);
|
|
62
|
-
return {
|
|
63
|
-
outcome: makeStaleRunAppendOutcome(),
|
|
64
|
-
projectionPipeline
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
outcome: await guardAppendedEventAgainstStaleRun(storage, namespace, runId, event, outcome),
|
|
69
|
-
projectionPipeline
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
async function guardAppendedEventAgainstStaleRun(storage, namespace, runId, event, outcome) {
|
|
73
|
-
if (await rollbackAppendedEventIfRunStale(storage, namespace, runId, event, outcome.events)) return makeStaleRunAppendOutcome();
|
|
74
|
-
return outcome;
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
export { appendEventWithProjectionPipelineIfRunCurrent, appendEventWithProjections };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { RunId } from "../types/run-id.mjs";
|
|
2
|
-
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
3
|
-
import { EventRecord } from "../types/events.mjs";
|
|
4
|
-
import { WorkflowStorage } from "../types/store.mjs";
|
|
5
|
-
import { StorageCompareAndSetManyItem, StorageValue } from "@temelj/storage";
|
|
6
|
-
//#region src/store/event-append.d.ts
|
|
7
|
-
type WorkflowEventAppendSuccessOutcome = {
|
|
8
|
-
readonly status: "appended";
|
|
9
|
-
readonly events: readonly EventRecord[];
|
|
10
|
-
readonly previousEventHistory?: StorageValue;
|
|
11
|
-
} | {
|
|
12
|
-
readonly status: "duplicate";
|
|
13
|
-
readonly events: readonly EventRecord[];
|
|
14
|
-
};
|
|
15
|
-
type WorkflowEventAppendOutcome = WorkflowEventAppendSuccessOutcome | {
|
|
16
|
-
readonly status: "staleRun";
|
|
17
|
-
};
|
|
18
|
-
type WorkflowEventAppendedOutcome = Extract<WorkflowEventAppendSuccessOutcome, {
|
|
19
|
-
readonly status: "appended";
|
|
20
|
-
}>;
|
|
21
|
-
interface WorkflowEventAppendAtomicProjectionPlan {
|
|
22
|
-
readonly item?: StorageCompareAndSetManyItem<StorageValue>;
|
|
23
|
-
}
|
|
24
|
-
type WorkflowEventAppendAtomicProjectionPlanner = (attempt: number) => Promise<WorkflowEventAppendAtomicProjectionPlan | undefined>;
|
|
25
|
-
type WorkflowEventAppendDuplicateDetector = (runId: RunId, events: readonly EventRecord[], event: EventRecord) => Extract<WorkflowEventAppendSuccessOutcome, {
|
|
26
|
-
readonly status: "duplicate";
|
|
27
|
-
}> | undefined;
|
|
28
|
-
interface EventAppendOptions {
|
|
29
|
-
readonly detectDuplicate?: WorkflowEventAppendDuplicateDetector;
|
|
30
|
-
readonly previousEventHistory?: StorageValue;
|
|
31
|
-
}
|
|
32
|
-
declare function makeStaleRunAppendOutcome(): WorkflowEventAppendOutcome;
|
|
33
|
-
declare function appendEventWithAtomicProjectionPlan(storage: WorkflowStorage, namespace: string, runId: RunId, event: EventRecord, planProjection?: WorkflowEventAppendAtomicProjectionPlanner, detectDuplicate?: WorkflowEventAppendDuplicateDetector): Promise<WorkflowEventAppendSuccessOutcome>;
|
|
34
|
-
declare function appendEventIfRunRevisionCurrentAtomically(storage: WorkflowStorage, namespace: string, currentRun: WorkflowRunRecord, event: EventRecord, detectDuplicate?: WorkflowEventAppendDuplicateDetector): Promise<WorkflowEventAppendOutcome>;
|
|
35
|
-
declare function appendEventIfCurrent(storage: WorkflowStorage, namespace: string, runId: RunId, event: EventRecord, options?: EventAppendOptions): Promise<WorkflowEventAppendSuccessOutcome>;
|
|
36
|
-
//#endregion
|
|
37
|
-
export { WorkflowEventAppendAtomicProjectionPlanner, WorkflowEventAppendDuplicateDetector, WorkflowEventAppendOutcome, WorkflowEventAppendSuccessOutcome, WorkflowEventAppendedOutcome, appendEventIfCurrent, appendEventIfRunRevisionCurrentAtomically, appendEventWithAtomicProjectionPlan, makeStaleRunAppendOutcome };
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { WorkflowStateError } from "../errors/base.mjs";
|
|
2
|
-
import "../errors/mod.mjs";
|
|
3
|
-
import { supportsWorkflowAtomicBatchWrite, supportsWorkflowConditionalWrite } from "./capabilities.mjs";
|
|
4
|
-
import { makeEventsKey, makeRunKey } from "../store-keys.mjs";
|
|
5
|
-
import { toStorageValue } from "./storage-value.mjs";
|
|
6
|
-
import { createRunRevisionGuardedEventHistoryCompareAndSetItems, createWorkflowEventHistoryCompareAndSetItem, getStoredEventHistory } from "./event-history.mjs";
|
|
7
|
-
//#region src/store/event-append.ts
|
|
8
|
-
const MAX_APPEND_EVENT_ATTEMPTS = 16;
|
|
9
|
-
function makeAppendedEventOutcome(events, previousEventHistory) {
|
|
10
|
-
return {
|
|
11
|
-
status: "appended",
|
|
12
|
-
events,
|
|
13
|
-
...previousEventHistory === void 0 ? {} : { previousEventHistory }
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function makeStaleRunAppendOutcome() {
|
|
17
|
-
return { status: "staleRun" };
|
|
18
|
-
}
|
|
19
|
-
async function appendEventWithAtomicProjectionPlan(storage, namespace, runId, event, planProjection, detectDuplicate) {
|
|
20
|
-
if (!supportsWorkflowAtomicBatchWrite(storage)) return await appendEventIfCurrent(storage, namespace, runId, event, {
|
|
21
|
-
detectDuplicate,
|
|
22
|
-
previousEventHistory: await storage.get(makeEventsKey(namespace, runId))
|
|
23
|
-
});
|
|
24
|
-
const eventsStorageKey = makeEventsKey(namespace, runId);
|
|
25
|
-
for (let attempt = 0; attempt < MAX_APPEND_EVENT_ATTEMPTS; attempt++) {
|
|
26
|
-
const appendState = await readWorkflowEventAppendState(storage, eventsStorageKey, runId, event, detectDuplicate);
|
|
27
|
-
const duplicate = appendState.duplicate;
|
|
28
|
-
if (duplicate !== void 0) return duplicate;
|
|
29
|
-
const projectionPlan = await planProjection?.(attempt);
|
|
30
|
-
const items = [createWorkflowEventHistoryCompareAndSetItem(eventsStorageKey, appendState.raw, appendState.nextEvents), ...projectionPlan?.item === void 0 ? [] : [projectionPlan.item]];
|
|
31
|
-
if (await storage.compareAndSetMany(items)) return makeAppendedEventOutcome(appendState.nextEvents, appendState.raw);
|
|
32
|
-
}
|
|
33
|
-
WorkflowStateError.failedWorkflowEventAppend(runId, MAX_APPEND_EVENT_ATTEMPTS);
|
|
34
|
-
}
|
|
35
|
-
async function appendEventIfRunRevisionCurrentAtomically(storage, namespace, currentRun, event, detectDuplicate) {
|
|
36
|
-
const runId = currentRun.id;
|
|
37
|
-
const runStorageKey = makeRunKey(namespace, runId);
|
|
38
|
-
const eventsStorageKey = makeEventsKey(namespace, runId);
|
|
39
|
-
for (let attempt = 0; attempt < MAX_APPEND_EVENT_ATTEMPTS; attempt++) {
|
|
40
|
-
const appendState = await readWorkflowEventAppendState(storage, eventsStorageKey, runId, event, detectDuplicate);
|
|
41
|
-
const duplicate = appendState.duplicate;
|
|
42
|
-
if (duplicate !== void 0) {
|
|
43
|
-
if (await storage.compareAndSetMany(createRunRevisionGuardedEventHistoryCompareAndSetItems(runStorageKey, currentRun, eventsStorageKey, appendState.raw, appendState.currentEvents))) return duplicate;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (await storage.compareAndSetMany(createRunRevisionGuardedEventHistoryCompareAndSetItems(runStorageKey, currentRun, eventsStorageKey, appendState.raw, appendState.nextEvents))) return makeAppendedEventOutcome(appendState.nextEvents, appendState.raw);
|
|
47
|
-
if (event.kind === "message_sent") return makeStaleRunAppendOutcome();
|
|
48
|
-
}
|
|
49
|
-
return makeStaleRunAppendOutcome();
|
|
50
|
-
}
|
|
51
|
-
async function appendEventIfCurrent(storage, namespace, runId, event, options = {}) {
|
|
52
|
-
const key = makeEventsKey(namespace, runId);
|
|
53
|
-
if (!supportsWorkflowConditionalWrite(storage)) {
|
|
54
|
-
const current = (await getStoredEventHistory(storage, key)).events;
|
|
55
|
-
const duplicate = options.detectDuplicate?.(runId, current, event);
|
|
56
|
-
if (duplicate !== void 0) return duplicate;
|
|
57
|
-
const events = [...current, event];
|
|
58
|
-
await storage.set(key, toStorageValue(events));
|
|
59
|
-
return makeAppendedEventOutcome(events, options.previousEventHistory);
|
|
60
|
-
}
|
|
61
|
-
for (let attempt = 0; attempt < MAX_APPEND_EVENT_ATTEMPTS; attempt++) {
|
|
62
|
-
const appendState = await readWorkflowEventAppendState(storage, key, runId, event, options.detectDuplicate);
|
|
63
|
-
const duplicate = appendState.duplicate;
|
|
64
|
-
if (duplicate !== void 0) return duplicate;
|
|
65
|
-
if (await storage.compareAndSet(key, appendState.raw, toStorageValue(appendState.nextEvents))) return makeAppendedEventOutcome(appendState.nextEvents, appendState.raw);
|
|
66
|
-
}
|
|
67
|
-
WorkflowStateError.failedWorkflowEventAppend(runId, MAX_APPEND_EVENT_ATTEMPTS);
|
|
68
|
-
}
|
|
69
|
-
async function readWorkflowEventAppendState(storage, eventsStorageKey, runId, event, detectDuplicate) {
|
|
70
|
-
const { raw, events: currentEvents } = await getStoredEventHistory(storage, eventsStorageKey);
|
|
71
|
-
const duplicate = detectDuplicate?.(runId, currentEvents, event);
|
|
72
|
-
return {
|
|
73
|
-
raw,
|
|
74
|
-
currentEvents,
|
|
75
|
-
...duplicate === void 0 ? {} : { duplicate },
|
|
76
|
-
nextEvents: duplicate === void 0 ? [...currentEvents, event] : currentEvents
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
export { appendEventIfCurrent, appendEventIfRunRevisionCurrentAtomically, appendEventWithAtomicProjectionPlan, makeStaleRunAppendOutcome };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RunId } from "../types/run-id.mjs";
|
|
2
|
-
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
3
|
-
import { EventRecord } from "../types/events.mjs";
|
|
4
|
-
import { WorkflowStorage } from "../types/store.mjs";
|
|
5
|
-
import { StorageCompareAndSetManyItem, StorageValue } from "@temelj/storage";
|
|
6
|
-
//#region src/store/event-history.d.ts
|
|
7
|
-
type WorkflowEventHistoryCompareAndSetItem = StorageCompareAndSetManyItem<StorageValue>;
|
|
8
|
-
type WorkflowRunRevisionCompareAndSetItem = StorageCompareAndSetManyItem<StorageValue>;
|
|
9
|
-
declare function getStoredEventHistory(storage: WorkflowStorage, key: string): Promise<{
|
|
10
|
-
readonly raw: StorageValue | undefined;
|
|
11
|
-
readonly events: readonly EventRecord[];
|
|
12
|
-
}>;
|
|
13
|
-
declare function getStoredCleanupEventHistory(storage: WorkflowStorage, key: string): Promise<{
|
|
14
|
-
readonly raw: StorageValue | undefined;
|
|
15
|
-
readonly events: readonly EventRecord[];
|
|
16
|
-
}>;
|
|
17
|
-
declare function isSameWorkflowEventIdentity(left: EventRecord, right: EventRecord): boolean;
|
|
18
|
-
declare function rollbackAppendedEventIfCurrent(storage: WorkflowStorage, namespace: string, runId: RunId, expectedEvents: readonly EventRecord[], previousEventHistory?: StorageValue): Promise<boolean>;
|
|
19
|
-
declare function createWorkflowEventHistoryCompareAndSetItem(eventsStorageKey: string, expected: StorageValue | undefined, events: readonly EventRecord[]): WorkflowEventHistoryCompareAndSetItem;
|
|
20
|
-
declare function createRunRevisionGuardedEventHistoryCompareAndSetItems(runStorageKey: string, currentRun: WorkflowRunRecord, eventsStorageKey: string, expectedEvents: StorageValue | undefined, events: readonly EventRecord[]): readonly [WorkflowRunRevisionCompareAndSetItem, WorkflowEventHistoryCompareAndSetItem];
|
|
21
|
-
//#endregion
|
|
22
|
-
export { createRunRevisionGuardedEventHistoryCompareAndSetItems, createWorkflowEventHistoryCompareAndSetItem, getStoredCleanupEventHistory, getStoredEventHistory, isSameWorkflowEventIdentity, rollbackAppendedEventIfCurrent };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { getEventDescriptor, isCleanupEventRecord } from "../events/descriptors.mjs";
|
|
2
|
-
import { supportsWorkflowConditionalWrite } from "./capabilities.mjs";
|
|
3
|
-
import { makeEventsKey } from "../store-keys.mjs";
|
|
4
|
-
import { isSameWorkflowStorageValue } from "./revision.mjs";
|
|
5
|
-
import { toStorageValue } from "./storage-value.mjs";
|
|
6
|
-
import { isReadableEventRecord } from "./validation.mjs";
|
|
7
|
-
//#region src/store/event-history.ts
|
|
8
|
-
async function getStoredEventHistory(storage, key) {
|
|
9
|
-
const raw = await storage.get(key);
|
|
10
|
-
return {
|
|
11
|
-
raw,
|
|
12
|
-
events: Array.isArray(raw) ? raw.filter(isReadableEventRecord) : []
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
async function getStoredCleanupEventHistory(storage, key) {
|
|
16
|
-
const history = await getStoredEventHistory(storage, key);
|
|
17
|
-
return {
|
|
18
|
-
raw: history.raw,
|
|
19
|
-
events: history.events.filter(isCleanupEventRecord)
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function isSameWorkflowEventIdentity(left, right) {
|
|
23
|
-
if (left.kind !== right.kind || Temporal.Instant.compare(left.timestamp, right.timestamp) !== 0) return false;
|
|
24
|
-
const descriptor = getEventDescriptor(left.kind);
|
|
25
|
-
return isSameWorkflowEventFields(left, right, descriptor.identityFields) && isSameWorkflowEventValueFields(left, right, descriptor.valueIdentityFields) && isSameWorkflowEventStringListFields(left, right, descriptor.stringListIdentityFields);
|
|
26
|
-
}
|
|
27
|
-
function isSameWorkflowEventFields(left, right, fields = []) {
|
|
28
|
-
return fields.every((field) => Reflect.get(left, field) === Reflect.get(right, field));
|
|
29
|
-
}
|
|
30
|
-
function isSameWorkflowEventValueFields(left, right, fields = []) {
|
|
31
|
-
return fields.every((field) => isSameWorkflowStorageValue(Reflect.get(left, field), Reflect.get(right, field)));
|
|
32
|
-
}
|
|
33
|
-
function isSameWorkflowEventStringListFields(left, right, fields = []) {
|
|
34
|
-
return fields.every((field) => {
|
|
35
|
-
const leftValue = Reflect.get(left, field);
|
|
36
|
-
const rightValue = Reflect.get(right, field);
|
|
37
|
-
const leftValues = Array.isArray(leftValue) && leftValue.every((item) => typeof item === "string" && item.trim() !== "") ? leftValue : void 0;
|
|
38
|
-
const rightValues = Array.isArray(rightValue) && rightValue.every((item) => typeof item === "string" && item.trim() !== "") ? rightValue : void 0;
|
|
39
|
-
if (leftValues === void 0 || rightValues === void 0) return leftValues === rightValues;
|
|
40
|
-
if (leftValues.length !== rightValues.length) return false;
|
|
41
|
-
return leftValues.every((value, index) => value === rightValues[index]);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async function rollbackAppendedEventIfCurrent(storage, namespace, runId, expectedEvents, previousEventHistory) {
|
|
45
|
-
if (expectedEvents.length === 0) return false;
|
|
46
|
-
const key = makeEventsKey(namespace, runId);
|
|
47
|
-
const rolledBackEvents = expectedEvents.slice(0, -1);
|
|
48
|
-
if (supportsWorkflowConditionalWrite(storage)) return await storage.compareAndSet(key, toStorageValue(expectedEvents), previousEventHistory ?? toStorageValue(rolledBackEvents));
|
|
49
|
-
const current = (await getStoredEventHistory(storage, key)).events;
|
|
50
|
-
const expectedLast = expectedEvents.at(-1);
|
|
51
|
-
const currentLast = current.at(-1);
|
|
52
|
-
if (current.length !== expectedEvents.length || expectedLast === void 0 || currentLast === void 0 || !isSameWorkflowEventIdentity(currentLast, expectedLast)) return false;
|
|
53
|
-
await storage.set(key, previousEventHistory ?? toStorageValue(rolledBackEvents));
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
function createWorkflowEventHistoryCompareAndSetItem(eventsStorageKey, expected, events) {
|
|
57
|
-
return {
|
|
58
|
-
key: eventsStorageKey,
|
|
59
|
-
expected,
|
|
60
|
-
value: toStorageValue(events)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function createWorkflowRunRevisionCompareAndSetItem(runStorageKey, currentRun) {
|
|
64
|
-
const value = toStorageValue(currentRun);
|
|
65
|
-
return {
|
|
66
|
-
key: runStorageKey,
|
|
67
|
-
expected: value,
|
|
68
|
-
value
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function createRunRevisionGuardedEventHistoryCompareAndSetItems(runStorageKey, currentRun, eventsStorageKey, expectedEvents, events) {
|
|
72
|
-
return [createWorkflowRunRevisionCompareAndSetItem(runStorageKey, currentRun), createWorkflowEventHistoryCompareAndSetItem(eventsStorageKey, expectedEvents, events)];
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
export { createRunRevisionGuardedEventHistoryCompareAndSetItems, createWorkflowEventHistoryCompareAndSetItem, getStoredCleanupEventHistory, getStoredEventHistory, isSameWorkflowEventIdentity, rollbackAppendedEventIfCurrent };
|
package/dist/store/event.d.mts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RunId } from "../types/run-id.mjs";
|
|
2
|
-
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
3
|
-
import { EventRecord } from "../types/events.mjs";
|
|
4
|
-
import { WorkflowStorage } from "../types/store.mjs";
|
|
5
|
-
//#region src/store/event.d.ts
|
|
6
|
-
declare function appendWorkflowEvent(storage: WorkflowStorage, namespace: string, runId: RunId, event: EventRecord): Promise<readonly EventRecord[]>;
|
|
7
|
-
declare function appendWorkflowEventIfRunCurrent(storage: WorkflowStorage, namespace: string, current: WorkflowRunRecord, event: EventRecord): Promise<readonly EventRecord[] | undefined>;
|
|
8
|
-
declare function getWorkflowEvents(storage: WorkflowStorage, namespace: string, runId: RunId): Promise<readonly EventRecord[]>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { appendWorkflowEvent, appendWorkflowEventIfRunCurrent, getWorkflowEvents };
|
package/dist/store/event.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { WorkflowStateError } from "../errors/base.mjs";
|
|
2
|
-
import { makeEventsKey } from "../store-keys.mjs";
|
|
3
|
-
import { requireReadableStoreRun } from "./validation.mjs";
|
|
4
|
-
import { getStoredEventHistory } from "./event-history.mjs";
|
|
5
|
-
import { requireReadableStoredWorkflowRun } from "./run.mjs";
|
|
6
|
-
import { createWorkflowAppendProjectionPipeline } from "./append-projection.mjs";
|
|
7
|
-
import { appendEventWithProjectionPipelineIfRunCurrent, appendEventWithProjections } from "./event-append-project.mjs";
|
|
8
|
-
//#region src/store/event.ts
|
|
9
|
-
async function finalizeWorkflowAppendOutcome(outcome, projectionPipeline) {
|
|
10
|
-
if (outcome.status === "staleRun") return;
|
|
11
|
-
if (projectionPipeline === void 0) WorkflowStateError.appendProjectionPipelineMissing();
|
|
12
|
-
return await projectionPipeline.finalize(outcome);
|
|
13
|
-
}
|
|
14
|
-
async function appendWorkflowEvent(storage, namespace, runId, event) {
|
|
15
|
-
await requireReadableStoredWorkflowRun(storage, namespace, runId);
|
|
16
|
-
const projectionPipeline = await createWorkflowAppendProjectionPipeline(storage, namespace, runId, event);
|
|
17
|
-
return await finalizeWorkflowAppendOutcome(await appendEventWithProjections(storage, namespace, runId, event, projectionPipeline), projectionPipeline);
|
|
18
|
-
}
|
|
19
|
-
async function appendWorkflowEventIfRunCurrent(storage, namespace, current, event) {
|
|
20
|
-
requireReadableStoreRun(current, namespace);
|
|
21
|
-
const appendOutcome = await appendEventWithProjectionPipelineIfRunCurrent(storage, namespace, current, event);
|
|
22
|
-
return await finalizeWorkflowAppendOutcome(appendOutcome.outcome, appendOutcome.projectionPipeline);
|
|
23
|
-
}
|
|
24
|
-
async function getWorkflowEvents(storage, namespace, runId) {
|
|
25
|
-
return (await getStoredEventHistory(storage, makeEventsKey(namespace, runId))).events;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { appendWorkflowEvent, appendWorkflowEventIfRunCurrent, getWorkflowEvents };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
2
|
-
import { WorkflowIdempotencyKeyOptions, WorkflowStorage } from "../types/store.mjs";
|
|
3
|
-
//#region src/store/idempotency.d.ts
|
|
4
|
-
interface WorkflowIdempotencyRunReader {
|
|
5
|
-
getRun(runId: string): Promise<WorkflowRunRecord | undefined>;
|
|
6
|
-
}
|
|
7
|
-
declare function createRunWithIdempotency(storage: WorkflowStorage, namespace: string, store: WorkflowIdempotencyRunReader, run: WorkflowRunRecord): Promise<WorkflowRunRecord>;
|
|
8
|
-
declare function getRunByIdempotencyKey(storage: WorkflowStorage, namespace: string, store: WorkflowIdempotencyRunReader, options: WorkflowIdempotencyKeyOptions): Promise<WorkflowRunRecord | undefined>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { createRunWithIdempotency, getRunByIdempotencyKey };
|