@temelj/workflow 0.0.0-alpha.2 → 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 +127 -282
- 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
|
@@ -1,26 +1,8 @@
|
|
|
1
|
-
import { WorkflowDefinitionError } from "../errors/definition.mjs";
|
|
2
|
-
import "../errors/mod.mjs";
|
|
3
|
-
import { getCompiledWorkflowDefinition } from "../compiled-function.mjs";
|
|
4
|
-
import { Registry } from "../registry.mjs";
|
|
5
1
|
//#region src/cloudflare/registry.ts
|
|
6
|
-
/** Creates a registry shared by the Cloudflare entrypoint and runtime facade. */
|
|
7
|
-
function createCloudflareWorkflowRegistry(entries = []) {
|
|
8
|
-
const registry = new Registry();
|
|
9
|
-
for (const entry of entries) {
|
|
10
|
-
if (typeof entry === "function") {
|
|
11
|
-
const implementation = getCompiledWorkflowDefinition(entry);
|
|
12
|
-
if (implementation === void 0) WorkflowDefinitionError.compiledMetadataMissing();
|
|
13
|
-
registry.register(implementation);
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
registry.register(entry);
|
|
17
|
-
}
|
|
18
|
-
return registry;
|
|
19
|
-
}
|
|
20
2
|
function resolveCloudflareWorkflowImplementation(registry, name, version) {
|
|
21
|
-
const implementation =
|
|
3
|
+
const implementation = registry.getByName(name, version);
|
|
22
4
|
if (implementation === void 0) throw new TypeError(`Cloudflare Workflow implementation is not registered: ${version === void 0 ? name : `${name}@${version}`}`);
|
|
23
5
|
return implementation;
|
|
24
6
|
}
|
|
25
7
|
//#endregion
|
|
26
|
-
export {
|
|
8
|
+
export { resolveCloudflareWorkflowImplementation };
|
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
import { RunId } from "../types/
|
|
2
|
-
import { RegistryLike,
|
|
3
|
-
import {
|
|
4
|
-
import "../types/
|
|
5
|
-
import { WorkflowRunHandle } from "../types/client.mjs";
|
|
6
|
-
import { WorkflowRuntime, WorkflowRuntimeRunsApi } from "../types/runtime.mjs";
|
|
1
|
+
import { RunId } from "../types/ids.mjs";
|
|
2
|
+
import { RegistryLike, StartTarget } from "../types/definition.mjs";
|
|
3
|
+
import { MessageSender } from "../types/message.mjs";
|
|
4
|
+
import { RunHandle, RuntimeRunsApi, WorkflowRuntime } from "../types/runtime.mjs";
|
|
7
5
|
import { CloudflareWorkflowBinding } from "./types.mjs";
|
|
8
6
|
//#region src/cloudflare/runtime.d.ts
|
|
9
|
-
interface CreateCloudflareWorkflowRuntimeOptions {
|
|
7
|
+
export interface CreateCloudflareWorkflowRuntimeOptions {
|
|
10
8
|
readonly binding: CloudflareWorkflowBinding;
|
|
11
9
|
readonly registry?: RegistryLike;
|
|
12
10
|
readonly resultPollInterval?: Temporal.Duration;
|
|
13
11
|
/** Controls whether workflows absent from the initial registry may be registered at runtime. */
|
|
14
12
|
readonly registration?: "dynamic" | "static";
|
|
15
13
|
}
|
|
16
|
-
interface CloudflareWorkflowRuntimeRunsApi extends
|
|
17
|
-
get<TInput, TOutput, TRawInput = TInput>(workflow:
|
|
14
|
+
export interface CloudflareWorkflowRuntimeRunsApi extends RuntimeRunsApi {
|
|
15
|
+
get<TInput, TOutput, TRawInput = TInput>(workflow: StartTarget<TInput, TOutput, TRawInput>, runId: RunId): Promise<RunHandle<TOutput>>;
|
|
18
16
|
}
|
|
19
|
-
interface
|
|
20
|
-
send(runId: RunId, options: SendMessageInput): Promise<void>;
|
|
21
|
-
send<TPayload, TKey = void>(runId: RunId, channel: MessageChannel<TPayload, TKey>, options?: SendMessageChannelOptions<TPayload, TKey>): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
interface CloudflareWorkflowRuntime extends WorkflowRuntime {
|
|
17
|
+
export interface CloudflareWorkflowRuntime extends WorkflowRuntime {
|
|
24
18
|
readonly runs: CloudflareWorkflowRuntimeRunsApi;
|
|
25
|
-
readonly messages:
|
|
19
|
+
readonly messages: MessageSender;
|
|
26
20
|
}
|
|
27
21
|
/** Creates a runtime facade over a generic Cloudflare Workflow binding. */
|
|
28
|
-
declare function createCloudflareWorkflowRuntime(options: CreateCloudflareWorkflowRuntimeOptions): CloudflareWorkflowRuntime;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { CloudflareWorkflowMessagesApi, CloudflareWorkflowRuntime, CloudflareWorkflowRuntimeRunsApi, CreateCloudflareWorkflowRuntimeOptions, createCloudflareWorkflowRuntime };
|
|
22
|
+
export declare function createCloudflareWorkflowRuntime(options: CreateCloudflareWorkflowRuntimeOptions): CloudflareWorkflowRuntime;
|
|
23
|
+
//#endregion
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import { WorkflowResultTimeoutError, WorkflowRunCanceledError } from "../errors/run.mjs";
|
|
2
|
-
import { durationTotal } from "../utility.mjs";
|
|
3
1
|
import { WorkflowCapabilityError } from "../errors/capability.mjs";
|
|
4
2
|
import { WorkflowDefinitionError } from "../errors/definition.mjs";
|
|
3
|
+
import { WorkflowResultTimeoutError, WorkflowRunCanceledError } from "../errors/run.mjs";
|
|
5
4
|
import "../errors/mod.mjs";
|
|
6
|
-
import {
|
|
5
|
+
import { getCompiledDefinition } from "../compiled-function.mjs";
|
|
7
6
|
import { Registry } from "../registry.mjs";
|
|
8
|
-
import {
|
|
7
|
+
import { defineFromTarget } from "../definition.mjs";
|
|
9
8
|
import { resolveSendMessageInput } from "../message-options.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
import { parseInput } from "../engine/serialization.mjs";
|
|
10
|
+
import { decodeCloudflareResult, durationMilliseconds, encodeCloudflareValue } from "./codec.mjs";
|
|
11
|
+
import { makeCloudflareEventType } from "./name.mjs";
|
|
12
|
+
import { isFunction } from "@temelj/value";
|
|
13
13
|
//#region src/cloudflare/runtime.ts
|
|
14
14
|
const DEFAULT_RESULT_POLL_INTERVAL = 100;
|
|
15
15
|
const CLOUDFLARE_INSTANCE_ID_PATTERN = /^[a-zA-Z0-9_][a-zA-Z0-9-_]*$/;
|
|
16
16
|
/** Creates a runtime facade over a generic Cloudflare Workflow binding. */
|
|
17
17
|
function createCloudflareWorkflowRuntime(options) {
|
|
18
|
-
return new
|
|
18
|
+
return new CloudflareRuntimeImpl(options);
|
|
19
19
|
}
|
|
20
|
-
var
|
|
20
|
+
var CloudflareRuntimeImpl = class {
|
|
21
21
|
runs;
|
|
22
22
|
messages;
|
|
23
|
-
schedules = unsupportedApi("Cloudflare workflow schedules");
|
|
24
|
-
locks = unsupportedApi("Cloudflare workflow locks");
|
|
25
|
-
workers = unsupportedApi("Cloudflare workflow workers");
|
|
26
23
|
#binding;
|
|
27
24
|
#registry;
|
|
28
25
|
#registration;
|
|
@@ -32,16 +29,27 @@ var CloudflareWorkflowRuntimeImpl = class {
|
|
|
32
29
|
this.#registry = options.registry ?? new Registry();
|
|
33
30
|
this.#registration = options.registration ?? "dynamic";
|
|
34
31
|
this.#resultPollInterval = options.resultPollInterval === void 0 ? DEFAULT_RESULT_POLL_INTERVAL : durationMilliseconds(options.resultPollInterval, "Cloudflare result poll interval");
|
|
32
|
+
const runtime = this;
|
|
33
|
+
async function start(workflow, ...args) {
|
|
34
|
+
if (isFunction(workflow)) {
|
|
35
|
+
const implementation = getCompiledDefinition(workflow);
|
|
36
|
+
if (implementation === void 0) WorkflowDefinitionError.compiledMetadataMissing();
|
|
37
|
+
runtime.register(implementation);
|
|
38
|
+
return await runtime.#startTarget(implementation, args, void 0);
|
|
39
|
+
}
|
|
40
|
+
const [input, options] = args;
|
|
41
|
+
if (workflow.kind === "implementation") runtime.register(workflow);
|
|
42
|
+
return await runtime.#startTarget(workflow, input, options);
|
|
43
|
+
}
|
|
35
44
|
this.runs = {
|
|
36
|
-
|
|
37
|
-
list: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow run listing"),
|
|
45
|
+
start,
|
|
38
46
|
get: async (workflow, runId) => this.#createHandle(workflow, runId)
|
|
39
47
|
};
|
|
40
48
|
this.messages = { send: async (runId, input, channelOptions) => {
|
|
41
49
|
const message = await resolveSendMessageInput(input, channelOptions);
|
|
42
50
|
await (await this.#binding.get(runId)).sendEvent({
|
|
43
|
-
type:
|
|
44
|
-
payload:
|
|
51
|
+
type: makeCloudflareEventType(message.messageId),
|
|
52
|
+
payload: encodeCloudflareValue(message.payload)
|
|
45
53
|
});
|
|
46
54
|
} };
|
|
47
55
|
}
|
|
@@ -60,38 +68,29 @@ var CloudflareWorkflowRuntimeImpl = class {
|
|
|
60
68
|
this.#registry.register(implementation);
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
|
-
async start(workflow, ...args) {
|
|
64
|
-
if (typeof workflow === "function") {
|
|
65
|
-
const implementation = getCompiledWorkflowDefinition(workflow);
|
|
66
|
-
if (implementation === void 0) WorkflowDefinitionError.compiledMetadataMissing();
|
|
67
|
-
this.register(implementation);
|
|
68
|
-
return await this.#startTarget(implementation, args, void 0);
|
|
69
|
-
}
|
|
70
|
-
const target = workflow;
|
|
71
|
-
if (target.kind === "implementation") this.register(target);
|
|
72
|
-
return await this.#startTarget(target, args[0], args[1]);
|
|
73
|
-
}
|
|
74
71
|
async #startTarget(target, rawInput, startOptions) {
|
|
75
72
|
rejectUnsupportedStartOptions(startOptions);
|
|
76
|
-
|
|
77
|
-
const implementation =
|
|
73
|
+
if (startOptions?.workflowVersion !== void 0 && startOptions.workflowVersion !== target.version) throw new WorkflowDefinitionError("Cloudflare start target version mismatch");
|
|
74
|
+
const implementation = this.#registeredImplementation(target);
|
|
78
75
|
if (implementation.config.retry !== void 0) WorkflowCapabilityError.unsupported("Cloudflare workflow-level retry configuration");
|
|
79
|
-
|
|
76
|
+
await parseInput(implementation.definition, rawInput);
|
|
80
77
|
const envelope = {
|
|
81
78
|
kind: "temelj-workflow",
|
|
82
79
|
version: 1,
|
|
83
80
|
workflowName: implementation.name,
|
|
84
|
-
|
|
85
|
-
input:
|
|
81
|
+
workflowVersion: implementation.version,
|
|
82
|
+
input: encodeCloudflareValue(rawInput)
|
|
86
83
|
};
|
|
87
84
|
const id = await resolveInstanceId(implementation.name, implementation.version, startOptions);
|
|
88
85
|
const createdAt = Temporal.Now.instant();
|
|
89
86
|
let instance;
|
|
90
|
-
if (startOptions?.idempotencyKey === void 0)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
if (startOptions?.idempotencyKey === void 0) {
|
|
88
|
+
const createOptions = {
|
|
89
|
+
id,
|
|
90
|
+
params: envelope
|
|
91
|
+
};
|
|
92
|
+
instance = await this.#binding.create(createOptions);
|
|
93
|
+
} else {
|
|
95
94
|
if (id === void 0) throw new TypeError("Cloudflare idempotent workflow start requires a resolved instance id");
|
|
96
95
|
instance = (await this.#binding.createBatch([{
|
|
97
96
|
id,
|
|
@@ -101,35 +100,25 @@ var CloudflareWorkflowRuntimeImpl = class {
|
|
|
101
100
|
return this.#handle(implementation.definition, instance, createdAt);
|
|
102
101
|
}
|
|
103
102
|
async #createHandle(workflow, runId) {
|
|
104
|
-
const implementation =
|
|
103
|
+
const implementation = this.#registeredImplementation(workflow);
|
|
105
104
|
const instance = await this.#binding.get(runId);
|
|
106
105
|
return this.#handle(implementation.definition, instance, Temporal.Now.instant());
|
|
107
106
|
}
|
|
107
|
+
#registeredImplementation(target) {
|
|
108
|
+
const implementation = this.#registry.get(defineFromTarget(target));
|
|
109
|
+
if (implementation === void 0) throw new TypeError("Cloudflare Workflow target must use its registered definition: " + target.name);
|
|
110
|
+
return implementation;
|
|
111
|
+
}
|
|
108
112
|
#handle(definition, instance, createdAt) {
|
|
109
|
-
const status =
|
|
113
|
+
const status = () => instance.status();
|
|
110
114
|
const record = async () => workflowRunRecord(definition, instance.id, createdAt, await status());
|
|
111
115
|
return {
|
|
112
116
|
runId: instance.id,
|
|
113
117
|
workflowName: definition.name,
|
|
114
|
-
|
|
118
|
+
workflowVersion: definition.version,
|
|
115
119
|
getRun: record,
|
|
116
120
|
status: async () => cloudflareRunStatus((await status()).status),
|
|
117
|
-
|
|
118
|
-
timeline: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow timeline"),
|
|
119
|
-
result: async (options) => await cloudflareWorkflowResult(instance, options, this.#resultPollInterval),
|
|
120
|
-
getStreamInfo: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
121
|
-
followStream: () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
122
|
-
waitForStream: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
123
|
-
waitForStreamChunk: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
124
|
-
waitForStreamTerminal: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
125
|
-
readStream: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
126
|
-
readStreamPage: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow streams"),
|
|
127
|
-
reschedule: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow rescheduling"),
|
|
128
|
-
releaseStaleLease: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow worker leases"),
|
|
129
|
-
retryFailed: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow manual retries"),
|
|
130
|
-
markPermanentlyFailed: async () => WorkflowCapabilityError.unsupported("Cloudflare permanent workflow failure"),
|
|
131
|
-
setMetadata: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow metadata"),
|
|
132
|
-
setAttributes: async () => WorkflowCapabilityError.unsupported("Cloudflare workflow attributes"),
|
|
121
|
+
result: (options) => cloudflareResult(definition, instance, options, this.#resultPollInterval),
|
|
133
122
|
async cancel() {
|
|
134
123
|
if (!isTerminalCloudflareStatus((await instance.status()).status)) await instance.terminate();
|
|
135
124
|
return await record();
|
|
@@ -143,13 +132,13 @@ function workflowImplementationKey(name, version) {
|
|
|
143
132
|
function isTerminalCloudflareStatus(status) {
|
|
144
133
|
return status === "complete" || status === "errored" || status === "terminated";
|
|
145
134
|
}
|
|
146
|
-
async function
|
|
135
|
+
async function cloudflareResult(definition, instance, options, defaultPollInterval) {
|
|
147
136
|
const pollInterval = options?.pollInterval === void 0 ? defaultPollInterval : durationMilliseconds(options.pollInterval, "Cloudflare result poll interval");
|
|
148
137
|
const timeout = options?.timeout === void 0 ? void 0 : durationMilliseconds(options.timeout, "Cloudflare result timeout");
|
|
149
138
|
const startedAt = Date.now();
|
|
150
139
|
while (true) {
|
|
151
140
|
const state = await instance.status();
|
|
152
|
-
if (state.status === "complete") return
|
|
141
|
+
if (state.status === "complete") return decodeCloudflareResult(state, definition);
|
|
153
142
|
if (state.status === "errored") {
|
|
154
143
|
const error = new Error(state.error?.message ?? "Cloudflare Workflow failed");
|
|
155
144
|
error.name = state.error?.name ?? "Error";
|
|
@@ -168,18 +157,18 @@ function workflowRunRecord(definition, runId, createdAt, state) {
|
|
|
168
157
|
id: runId,
|
|
169
158
|
namespace: "cloudflare",
|
|
170
159
|
workflowName: definition.name,
|
|
171
|
-
|
|
160
|
+
workflowVersion: definition.version,
|
|
172
161
|
status,
|
|
173
|
-
|
|
174
|
-
|
|
162
|
+
output: state.status === "complete" ? decodeCloudflareResult(state, definition) : void 0,
|
|
163
|
+
error: state.error !== void 0 ? {
|
|
175
164
|
name: state.error.name,
|
|
176
165
|
message: state.error.message
|
|
177
|
-
}
|
|
166
|
+
} : void 0,
|
|
178
167
|
createdAt,
|
|
179
168
|
updatedAt: now,
|
|
180
169
|
lastTransitionAt: now,
|
|
181
170
|
lastTransitionReason: status === "completed" ? "completed" : status === "failed" ? "failed" : status === "canceled" ? "canceled" : status === "waiting" ? "waiting" : status === "running" ? "started" : "created",
|
|
182
|
-
|
|
171
|
+
finishedAt: status === "completed" || status === "failed" || status === "canceled" ? now : void 0
|
|
183
172
|
};
|
|
184
173
|
}
|
|
185
174
|
function cloudflareRunStatus(status) {
|
|
@@ -212,15 +201,5 @@ function validateInstanceId(id) {
|
|
|
212
201
|
function rejectUnsupportedStartOptions(options) {
|
|
213
202
|
if (options?.availableAt !== void 0 || options?.deadlineAt !== void 0 || options?.context !== void 0 || options?.parent !== void 0 || options?.workflowVersionResolver !== void 0) WorkflowCapabilityError.unsupported("Cloudflare start context, parent, delayed availability, deadline, or version resolver");
|
|
214
203
|
}
|
|
215
|
-
function durationMilliseconds(duration, label) {
|
|
216
|
-
const milliseconds = durationTotal(duration);
|
|
217
|
-
if (!Number.isSafeInteger(milliseconds) || milliseconds < 0) throw new RangeError(`${label} must resolve to non-negative whole milliseconds`);
|
|
218
|
-
return milliseconds;
|
|
219
|
-
}
|
|
220
|
-
function unsupportedApi(capability) {
|
|
221
|
-
return new Proxy({}, { get() {
|
|
222
|
-
return () => WorkflowCapabilityError.unsupported(capability);
|
|
223
|
-
} });
|
|
224
|
-
}
|
|
225
204
|
//#endregion
|
|
226
205
|
export { createCloudflareWorkflowRuntime };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { WorkflowContext } from "../types/definition.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { StepApi } from "../types/step.mjs";
|
|
3
3
|
import { CloudflareNonRetryableErrorConstructor, CloudflareWorkflowStep } from "./types.mjs";
|
|
4
4
|
import { Logger } from "@temelj/log";
|
|
5
5
|
//#region src/cloudflare/step.d.ts
|
|
6
|
-
interface
|
|
6
|
+
interface CreateCloudflareStepApiOptions {
|
|
7
7
|
readonly step: CloudflareWorkflowStep;
|
|
8
8
|
readonly logger?: Logger;
|
|
9
9
|
readonly nonRetryableError?: CloudflareNonRetryableErrorConstructor;
|
|
10
10
|
}
|
|
11
11
|
/** Creates the Temelj durable command API backed by one Cloudflare Workflow step object. */
|
|
12
|
-
declare function
|
|
13
|
-
interface
|
|
12
|
+
export declare function createCloudflareStepApi(options: CreateCloudflareStepApiOptions): StepApi;
|
|
13
|
+
export interface CreateCloudflareContextOptions<TInput> extends CreateCloudflareStepApiOptions {
|
|
14
14
|
readonly input: TInput;
|
|
15
15
|
readonly runId: string;
|
|
16
16
|
readonly workflowName: string;
|
|
17
17
|
readonly workflowVersion?: string;
|
|
18
18
|
readonly createdAt: Temporal.Instant;
|
|
19
19
|
}
|
|
20
|
-
declare function
|
|
20
|
+
export declare function createCloudflareContext<TInput>(options: CreateCloudflareContextOptions<TInput>): WorkflowContext<TInput>;
|
|
21
21
|
//#endregion
|
|
22
|
-
export {
|
|
22
|
+
export {};
|
package/dist/cloudflare/step.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { WorkflowNonRetryableError } from "../errors/failures.mjs";
|
|
2
|
-
import { durationTotal } from "../utility.mjs";
|
|
3
1
|
import { WorkflowCapabilityError } from "../errors/capability.mjs";
|
|
2
|
+
import { WorkflowNonRetryableError } from "../errors/failures.mjs";
|
|
4
3
|
import "../errors/mod.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { createMessageWait } from "../message-options.mjs";
|
|
5
|
+
import { resolveRetryConfig } from "../engine/retry.mjs";
|
|
6
|
+
import { decodeCloudflareValue, durationMilliseconds, encodeCloudflareValue } from "./codec.mjs";
|
|
7
|
+
import { makeCloudflareEventType, makeCloudflareStepName } from "./name.mjs";
|
|
9
8
|
import { validateStandardSchema } from "@temelj/standard-schema";
|
|
10
9
|
import { createNoopLogger } from "@temelj/log";
|
|
11
10
|
//#region src/cloudflare/step.ts
|
|
@@ -18,23 +17,23 @@ const MAXIMUM_CLOUDFLARE_DELAY_MILLISECONDS = 31536e6;
|
|
|
18
17
|
const MAXIMUM_CLOUDFLARE_STEP_TIMEOUT_MILLISECONDS = 18e5;
|
|
19
18
|
const MAXIMUM_EVENT_WAIT_MILLISECONDS = 31536e6;
|
|
20
19
|
/** Creates the Temelj durable command API backed by one Cloudflare Workflow step object. */
|
|
21
|
-
function
|
|
20
|
+
function createCloudflareStepApi(options) {
|
|
22
21
|
const logger = options.logger ?? createNoopLogger();
|
|
23
22
|
const runTask = async (config, callback) => {
|
|
24
23
|
const commandName = config.commandId ?? config.name;
|
|
25
24
|
if (commandName === void 0) throw new TypeError("Cloudflare durable task requires a name or commandId");
|
|
26
|
-
const retry =
|
|
27
|
-
const stepName =
|
|
25
|
+
const retry = resolveRetryConfig(config.retry, DEFAULT_STEP_RETRY, "Cloudflare Workflow step retry");
|
|
26
|
+
const stepName = makeCloudflareStepName(commandName);
|
|
28
27
|
const encoded = await options.step.do(stepName, cloudflareStepConfig(config, retry), async (cloudflareContext) => {
|
|
29
28
|
const context = workflowStepContext(commandName, retry, cloudflareContext, logger);
|
|
30
29
|
try {
|
|
31
|
-
return
|
|
30
|
+
return encodeCloudflareValue(await callback(context));
|
|
32
31
|
} catch (error) {
|
|
33
32
|
if (error instanceof WorkflowNonRetryableError && options.nonRetryableError !== void 0) throw new options.nonRetryableError(error.message, error.name);
|
|
34
33
|
throw error;
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
|
-
return
|
|
36
|
+
return decodeCloudflareValue(encoded, `Cloudflare step ${commandName} result`);
|
|
38
37
|
};
|
|
39
38
|
const deterministic = {
|
|
40
39
|
now: async (commandId = "now") => await runTask({ commandId: `deterministic:${commandId}` }, () => Temporal.Now.instant()),
|
|
@@ -48,65 +47,73 @@ function createCloudflareWorkflowStepApi(options) {
|
|
|
48
47
|
return bytes;
|
|
49
48
|
})
|
|
50
49
|
};
|
|
51
|
-
const waitMessage = (async (
|
|
52
|
-
const wait = resolveWaitForMessageInput(messageInput, channelOptions);
|
|
50
|
+
const waitMessage = createMessageWait(async (wait) => {
|
|
53
51
|
const timeout = wait.timeout === void 0 ? MAXIMUM_EVENT_WAIT_MILLISECONDS : durationMilliseconds(wait.timeout, "Cloudflare Workflow message timeout");
|
|
54
52
|
if (timeout < 1e3 || timeout > MAXIMUM_EVENT_WAIT_MILLISECONDS) throw new RangeError("Cloudflare Workflow message timeout must be between 1 second and 365 days");
|
|
55
|
-
const event = await options.step.waitForEvent(
|
|
56
|
-
type:
|
|
53
|
+
const event = await options.step.waitForEvent(makeCloudflareStepName(wait.commandId ?? wait.name ?? wait.messageId), {
|
|
54
|
+
type: makeCloudflareEventType(wait.messageId),
|
|
57
55
|
timeout
|
|
58
56
|
});
|
|
59
|
-
const decoded =
|
|
57
|
+
const decoded = decodeCloudflareValue(event.payload, `Cloudflare message ${wait.messageId} payload`);
|
|
60
58
|
if (wait.schema === void 0) return decoded;
|
|
61
59
|
return await validateStandardSchema(wait.schema, decoded, "Workflow message validation failed");
|
|
62
60
|
});
|
|
63
61
|
return {
|
|
64
62
|
log: logger,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return await
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
run: runTask,
|
|
64
|
+
async call(definition, ...args) {
|
|
65
|
+
return await runTask(definition.config, async (context) => {
|
|
66
|
+
return await definition.handler(context, ...args);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
async sleep(commandId, duration) {
|
|
70
|
+
await options.step.sleep(makeCloudflareStepName(commandId), durationMilliseconds(duration, "Cloudflare Workflow sleep"));
|
|
71
|
+
},
|
|
72
|
+
async sleepUntil(commandId, timestamp) {
|
|
73
|
+
await options.step.sleepUntil(makeCloudflareStepName(commandId), timestamp.epochMilliseconds);
|
|
74
|
+
},
|
|
75
|
+
workflow: {
|
|
76
|
+
run: unsupportedWorkflow,
|
|
77
|
+
start: unsupportedWorkflow
|
|
78
78
|
},
|
|
79
|
-
workflow: unsupportedFacet("child workflows"),
|
|
80
79
|
message: {
|
|
81
80
|
send: async () => WorkflowCapabilityError.unsupported("Cloudflare in-workflow message send"),
|
|
82
81
|
wait: waitMessage
|
|
83
82
|
},
|
|
84
|
-
lock:
|
|
85
|
-
|
|
83
|
+
lock: {
|
|
84
|
+
acquire: unsupportedLock,
|
|
85
|
+
release: unsupportedLock,
|
|
86
|
+
with: unsupportedLock
|
|
87
|
+
},
|
|
88
|
+
runData: {
|
|
89
|
+
setMetadata: unsupportedRunData,
|
|
90
|
+
setAttributes: unsupportedRunData
|
|
91
|
+
},
|
|
86
92
|
deterministic,
|
|
87
|
-
stream:
|
|
88
|
-
hook:
|
|
93
|
+
stream: { create: unsupportedStream },
|
|
94
|
+
hook: {
|
|
95
|
+
create: unsupportedHook,
|
|
96
|
+
createWebhook: unsupportedHook
|
|
97
|
+
}
|
|
89
98
|
};
|
|
90
99
|
}
|
|
91
|
-
function
|
|
100
|
+
function createCloudflareContext(options) {
|
|
92
101
|
const logger = options.logger ?? createNoopLogger();
|
|
93
|
-
const step =
|
|
102
|
+
const step = createCloudflareStepApi({
|
|
94
103
|
...options,
|
|
95
104
|
logger
|
|
96
105
|
});
|
|
106
|
+
const run = {
|
|
107
|
+
id: options.runId,
|
|
108
|
+
workflowName: options.workflowName,
|
|
109
|
+
workflowVersion: options.workflowVersion,
|
|
110
|
+
createdAt: options.createdAt
|
|
111
|
+
};
|
|
97
112
|
return {
|
|
98
113
|
input: options.input,
|
|
99
114
|
step,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
run: {
|
|
103
|
-
id: options.runId,
|
|
104
|
-
workflowName: options.workflowName,
|
|
105
|
-
...options.workflowVersion === void 0 ? {} : { workflowVersion: options.workflowVersion },
|
|
106
|
-
createdAt: options.createdAt
|
|
107
|
-
},
|
|
108
|
-
signal: new AbortController().signal,
|
|
109
|
-
version: options.workflowVersion
|
|
115
|
+
run,
|
|
116
|
+
signal: new AbortController().signal
|
|
110
117
|
};
|
|
111
118
|
}
|
|
112
119
|
function cloudflareStepConfig(config, retry) {
|
|
@@ -122,7 +129,7 @@ function cloudflareStepConfig(config, retry) {
|
|
|
122
129
|
limit: retry.maximumAttempts,
|
|
123
130
|
delay: ({ ctx }) => retryDelay(initialDelay, retry, ctx.attempt, maximumDelay)
|
|
124
131
|
},
|
|
125
|
-
|
|
132
|
+
timeout
|
|
126
133
|
};
|
|
127
134
|
}
|
|
128
135
|
function retryDelay(initialDelay, retry, attempt, maximumDelay) {
|
|
@@ -143,18 +150,23 @@ function workflowStepContext(commandName, retry, context, logger) {
|
|
|
143
150
|
log: logger
|
|
144
151
|
};
|
|
145
152
|
}
|
|
146
|
-
function durationMilliseconds(duration, label) {
|
|
147
|
-
const milliseconds = durationTotal(duration);
|
|
148
|
-
if (!Number.isSafeInteger(milliseconds) || milliseconds < 0) throw new RangeError(`${label} must resolve to non-negative whole milliseconds`);
|
|
149
|
-
return milliseconds;
|
|
150
|
-
}
|
|
151
153
|
function assertMaximumDuration(value, maximum, label) {
|
|
152
154
|
if (value > maximum) throw new RangeError(`${label} must not exceed ${maximum} milliseconds`);
|
|
153
155
|
}
|
|
154
|
-
function
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
function unsupportedWorkflow() {
|
|
157
|
+
return WorkflowCapabilityError.unsupported("child workflows");
|
|
158
|
+
}
|
|
159
|
+
function unsupportedLock() {
|
|
160
|
+
return WorkflowCapabilityError.unsupported("Cloudflare workflow locks");
|
|
161
|
+
}
|
|
162
|
+
function unsupportedRunData() {
|
|
163
|
+
return WorkflowCapabilityError.unsupported("Cloudflare workflow run data");
|
|
164
|
+
}
|
|
165
|
+
function unsupportedStream() {
|
|
166
|
+
return WorkflowCapabilityError.unsupported("Cloudflare workflow streams");
|
|
167
|
+
}
|
|
168
|
+
function unsupportedHook() {
|
|
169
|
+
return WorkflowCapabilityError.unsupported("Cloudflare workflow hooks");
|
|
158
170
|
}
|
|
159
171
|
//#endregion
|
|
160
|
-
export {
|
|
172
|
+
export { createCloudflareContext, createCloudflareStepApi };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { CloudflareWorkersModule } from "@cloudflare/workers-types";
|
|
1
2
|
//#region src/cloudflare/types.d.ts
|
|
2
3
|
/** Minimal Cloudflare Workflow binding used by the Temelj adapter. */
|
|
3
|
-
interface CloudflareWorkflowBinding {
|
|
4
|
+
export interface CloudflareWorkflowBinding {
|
|
4
5
|
create(options?: CloudflareWorkflowInstanceCreateOptions): Promise<CloudflareWorkflowInstance>;
|
|
5
6
|
createBatch(items: readonly CloudflareWorkflowInstanceCreateOptions[]): Promise<readonly CloudflareWorkflowInstance[]>;
|
|
6
7
|
get(id: string): Promise<CloudflareWorkflowInstance>;
|
|
7
8
|
}
|
|
8
9
|
/** Parameters accepted when creating a Cloudflare Workflow instance. */
|
|
9
|
-
interface CloudflareWorkflowInstanceCreateOptions {
|
|
10
|
+
export interface CloudflareWorkflowInstanceCreateOptions {
|
|
10
11
|
readonly id?: string;
|
|
11
12
|
readonly params?: unknown;
|
|
12
13
|
}
|
|
13
14
|
/** Minimal Cloudflare Workflow instance used by the Temelj adapter. */
|
|
14
|
-
interface CloudflareWorkflowInstance {
|
|
15
|
+
export interface CloudflareWorkflowInstance {
|
|
15
16
|
readonly id: string;
|
|
16
17
|
status(): Promise<CloudflareWorkflowInstanceStatus>;
|
|
17
18
|
terminate(options?: {
|
|
@@ -22,8 +23,7 @@ interface CloudflareWorkflowInstance {
|
|
|
22
23
|
readonly payload?: unknown;
|
|
23
24
|
}): Promise<void>;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
interface CloudflareWorkflowInstanceStatus {
|
|
26
|
+
export interface CloudflareWorkflowInstanceStatus {
|
|
27
27
|
readonly status: "queued" | "running" | "paused" | "errored" | "terminated" | "complete" | "waiting" | "waitingForPause" | "unknown";
|
|
28
28
|
readonly error?: {
|
|
29
29
|
readonly name: string;
|
|
@@ -31,45 +31,28 @@ interface CloudflareWorkflowInstanceStatus {
|
|
|
31
31
|
};
|
|
32
32
|
readonly output?: unknown;
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
readonly step: {
|
|
37
|
-
readonly name: string;
|
|
38
|
-
readonly count: number;
|
|
39
|
-
};
|
|
40
|
-
readonly attempt: number;
|
|
41
|
-
readonly config: CloudflareWorkflowStepConfig;
|
|
42
|
-
}
|
|
34
|
+
/** Cloudflare's context for static and dynamic retry configurations. */
|
|
35
|
+
export type CloudflareWorkflowStepContext = CloudflareWorkersModule.WorkflowStepContext<CloudflareWorkersModule.WorkflowDelayDuration | CloudflareWorkersModule.WorkflowDelayFunction>;
|
|
43
36
|
/** Cloudflare retry and timeout configuration used by a durable step. */
|
|
44
|
-
|
|
45
|
-
readonly retries?: {
|
|
46
|
-
readonly limit: number;
|
|
47
|
-
readonly delay: number | ((input: {
|
|
48
|
-
readonly ctx: CloudflareWorkflowStepContext;
|
|
49
|
-
readonly error: Error;
|
|
50
|
-
}) => number | Promise<number>);
|
|
51
|
-
readonly backoff?: "constant" | "linear" | "exponential";
|
|
52
|
-
};
|
|
53
|
-
readonly timeout?: number;
|
|
54
|
-
}
|
|
37
|
+
export type CloudflareWorkflowStepConfig = CloudflareWorkersModule.WorkflowStepConfig;
|
|
55
38
|
/** Event returned by Cloudflare after a matching `waitForEvent` call. */
|
|
56
|
-
interface CloudflareWorkflowStepEvent<TPayload = unknown> {
|
|
39
|
+
export interface CloudflareWorkflowStepEvent<TPayload = unknown> {
|
|
57
40
|
readonly payload: TPayload;
|
|
58
41
|
readonly timestamp: Date;
|
|
59
42
|
readonly type: string;
|
|
60
43
|
}
|
|
61
44
|
/** Minimal Cloudflare durable step API used by the Temelj adapter. */
|
|
62
|
-
interface CloudflareWorkflowStep {
|
|
63
|
-
do
|
|
45
|
+
export interface CloudflareWorkflowStep {
|
|
46
|
+
do(name: string, config: CloudflareWorkflowStepConfig, callback: (context: CloudflareWorkflowStepContext) => Promise<string>): Promise<string>;
|
|
64
47
|
sleep(name: string, duration: number): Promise<void>;
|
|
65
48
|
sleepUntil(name: string, timestamp: number): Promise<void>;
|
|
66
|
-
waitForEvent
|
|
49
|
+
waitForEvent(name: string, options: {
|
|
67
50
|
readonly type: string;
|
|
68
|
-
readonly timeout:
|
|
69
|
-
}): Promise<CloudflareWorkflowStepEvent
|
|
51
|
+
readonly timeout: number;
|
|
52
|
+
}): Promise<CloudflareWorkflowStepEvent>;
|
|
70
53
|
}
|
|
71
54
|
/** Event delivered to the generic Temelj Cloudflare entrypoint. */
|
|
72
|
-
interface CloudflareWorkflowEvent<TPayload = unknown> {
|
|
55
|
+
export interface CloudflareWorkflowEvent<TPayload = unknown> {
|
|
73
56
|
readonly payload: TPayload;
|
|
74
57
|
readonly timestamp: Date;
|
|
75
58
|
readonly instanceId: string;
|
|
@@ -79,9 +62,7 @@ interface CloudflareWorkflowEvent<TPayload = unknown> {
|
|
|
79
62
|
readonly scheduledTime: number;
|
|
80
63
|
};
|
|
81
64
|
}
|
|
82
|
-
|
|
83
|
-
interface CloudflareNonRetryableErrorConstructor {
|
|
65
|
+
export interface CloudflareNonRetryableErrorConstructor {
|
|
84
66
|
new (message: string, name?: string): Error;
|
|
85
67
|
}
|
|
86
|
-
//#endregion
|
|
87
|
-
export { CloudflareNonRetryableErrorConstructor, CloudflareWorkflowBinding, CloudflareWorkflowEvent, CloudflareWorkflowInstance, CloudflareWorkflowInstanceCreateOptions, CloudflareWorkflowInstanceStatus, CloudflareWorkflowStep, CloudflareWorkflowStepConfig, CloudflareWorkflowStepContext, CloudflareWorkflowStepEvent };
|
|
68
|
+
//#endregion
|
package/dist/collection.d.mts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
//#region src/collection.d.ts
|
|
2
2
|
/** Returns whether a value matches one expected value or any value in an expected list. */
|
|
3
|
-
declare function matchesOptionalValue<T>(value: T, expected: T | readonly T[]): boolean;
|
|
3
|
+
export declare function matchesOptionalValue<T>(value: T, expected: T | readonly T[]): boolean;
|
|
4
4
|
/** Returns the first item for each key while preserving input order. */
|
|
5
|
-
declare function uniqueBy<T>(items: readonly T[], key: (item: T) => string): readonly T[];
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
declare function
|
|
10
|
-
|
|
11
|
-
declare function sortedStringSet(values: ReadonlySet<string>): readonly string[];
|
|
12
|
-
/** Returns an object containing a sorted string set only when the set is not empty. */
|
|
13
|
-
declare function optionalSortedStringSetProperty<TKey extends string>(key: TKey, values: ReadonlySet<string>): Partial<Record<TKey, readonly string[]>>;
|
|
5
|
+
export declare function uniqueBy<T>(items: readonly T[], key: (item: T) => string): readonly T[];
|
|
6
|
+
/** Own record fields after removing undefined values. */
|
|
7
|
+
type DefinedProperties<T> = { [K in keyof T as undefined extends T[K] ? never : K]: T[K]; } & { [K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>; };
|
|
8
|
+
/** Copies the defined own enumerable fields of a plain record. */
|
|
9
|
+
export declare function omitUndefined<T extends object>(value: T): DefinedProperties<T>;
|
|
10
|
+
export declare function limitItems<T>(items: readonly T[], limit: number | undefined): readonly T[];
|
|
14
11
|
//#endregion
|
|
15
|
-
export {
|
|
12
|
+
export {};
|