@temelj/workflow 0.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/attributes.d.mts +15 -0
- package/dist/attributes.mjs +30 -0
- package/dist/client/create.d.mts +31 -0
- package/dist/client/create.mjs +67 -0
- package/dist/client/facades.d.mts +21 -0
- package/dist/client/facades.mjs +142 -0
- package/dist/client/mod.d.mts +2 -0
- package/dist/client/mod.mjs +2 -0
- package/dist/client/run-handle.d.mts +66 -0
- package/dist/client/run-handle.mjs +156 -0
- package/dist/client/worker-options.d.mts +17 -0
- package/dist/client/worker-options.mjs +25 -0
- package/dist/collection.d.mts +15 -0
- package/dist/collection.mjs +33 -0
- package/dist/compiled-function.d.mts +27 -0
- package/dist/compiled-function.mjs +54 -0
- package/dist/definition.d.mts +37 -0
- package/dist/definition.mjs +83 -0
- package/dist/engine/child-workflow.d.mts +10 -0
- package/dist/engine/child-workflow.mjs +333 -0
- package/dist/engine/command-identity.d.mts +9 -0
- package/dist/engine/command-identity.mjs +14 -0
- package/dist/engine/create.d.mts +106 -0
- package/dist/engine/create.mjs +402 -0
- package/dist/engine/deterministic.d.mts +12 -0
- package/dist/engine/deterministic.mjs +102 -0
- package/dist/engine/durable-command.d.mts +10 -0
- package/dist/engine/durable-command.mjs +17 -0
- package/dist/engine/execution-api.d.mts +29 -0
- package/dist/engine/execution-api.mjs +33 -0
- package/dist/engine/execution-service.d.mts +41 -0
- package/dist/engine/execution-service.mjs +288 -0
- package/dist/engine/hooks.d.mts +56 -0
- package/dist/engine/hooks.mjs +237 -0
- package/dist/engine/inspection-api.d.mts +34 -0
- package/dist/engine/inspection-api.mjs +77 -0
- package/dist/engine/inspection.d.mts +18 -0
- package/dist/engine/inspection.mjs +149 -0
- package/dist/engine/lifecycle.d.mts +18 -0
- package/dist/engine/lifecycle.mjs +38 -0
- package/dist/engine/lock-replay.d.mts +30 -0
- package/dist/engine/lock-replay.mjs +38 -0
- package/dist/engine/lock.d.mts +21 -0
- package/dist/engine/lock.mjs +197 -0
- package/dist/engine/message.d.mts +47 -0
- package/dist/engine/message.mjs +357 -0
- package/dist/engine/mod.d.mts +4 -0
- package/dist/engine/mod.mjs +2 -0
- package/dist/engine/observation.d.mts +35 -0
- package/dist/engine/observation.mjs +201 -0
- package/dist/engine/recovery.d.mts +26 -0
- package/dist/engine/recovery.mjs +92 -0
- package/dist/engine/replay.d.mts +41 -0
- package/dist/engine/replay.mjs +122 -0
- package/dist/engine/retry-policy.d.mts +4 -0
- package/dist/engine/retry-policy.mjs +4 -0
- package/dist/engine/retry.d.mts +23 -0
- package/dist/engine/retry.mjs +75 -0
- package/dist/engine/run-data.d.mts +9 -0
- package/dist/engine/run-data.mjs +74 -0
- package/dist/engine/run-service.d.mts +38 -0
- package/dist/engine/run-service.mjs +133 -0
- package/dist/engine/run-utils.d.mts +16 -0
- package/dist/engine/run-utils.mjs +83 -0
- package/dist/engine/schedule.d.mts +25 -0
- package/dist/engine/schedule.mjs +207 -0
- package/dist/engine/serialization.d.mts +9 -0
- package/dist/engine/serialization.mjs +85 -0
- package/dist/engine/start-api.d.mts +30 -0
- package/dist/engine/start-api.mjs +98 -0
- package/dist/engine/state.d.mts +77 -0
- package/dist/engine/state.mjs +464 -0
- package/dist/engine/step-api.d.mts +9 -0
- package/dist/engine/step-api.mjs +25 -0
- package/dist/engine/stream.d.mts +55 -0
- package/dist/engine/stream.mjs +333 -0
- package/dist/engine/summary/active-events.d.mts +34 -0
- package/dist/engine/summary/active-events.mjs +69 -0
- package/dist/engine/summary/child-workflow-runs.d.mts +24 -0
- package/dist/engine/summary/child-workflow-runs.mjs +138 -0
- package/dist/engine/summary/child-workflow-waits.d.mts +21 -0
- package/dist/engine/summary/child-workflow-waits.mjs +67 -0
- package/dist/engine/summary/recovery-child-workflow-waits.d.mts +11 -0
- package/dist/engine/summary/recovery-child-workflow-waits.mjs +89 -0
- package/dist/engine/summary/recovery-due-runs.d.mts +16 -0
- package/dist/engine/summary/recovery-due-runs.mjs +52 -0
- package/dist/engine/summary/recovery-failed-runs.d.mts +14 -0
- package/dist/engine/summary/recovery-failed-runs.mjs +33 -0
- package/dist/engine/summary/recovery-lease-runs.d.mts +16 -0
- package/dist/engine/summary/recovery-lease-runs.mjs +69 -0
- package/dist/engine/summary/recovery-locks.d.mts +18 -0
- package/dist/engine/summary/recovery-locks.mjs +100 -0
- package/dist/engine/summary/recovery-message-waits.d.mts +11 -0
- package/dist/engine/summary/recovery-message-waits.mjs +74 -0
- package/dist/engine/summary/recovery-retry-runs.d.mts +17 -0
- package/dist/engine/summary/recovery-retry-runs.mjs +65 -0
- package/dist/engine/summary/recovery-run-timestamps.d.mts +13 -0
- package/dist/engine/summary/recovery-run-timestamps.mjs +18 -0
- package/dist/engine/summary/recovery-runs.d.mts +23 -0
- package/dist/engine/summary/recovery-runs.mjs +54 -0
- package/dist/engine/summary/recovery-schedules.d.mts +10 -0
- package/dist/engine/summary/recovery-schedules.mjs +46 -0
- package/dist/engine/summary/recovery-sleep-waits.d.mts +10 -0
- package/dist/engine/summary/recovery-sleep-waits.mjs +53 -0
- package/dist/engine/summary/recovery-waits.d.mts +21 -0
- package/dist/engine/summary/recovery-waits.mjs +29 -0
- package/dist/engine/summary/run-availability.d.mts +13 -0
- package/dist/engine/summary/run-availability.mjs +37 -0
- package/dist/engine/summary/run-cleanup.d.mts +14 -0
- package/dist/engine/summary/run-cleanup.mjs +44 -0
- package/dist/engine/summary/run-failure.d.mts +14 -0
- package/dist/engine/summary/run-failure.mjs +62 -0
- package/dist/engine/summary/run-hooks.d.mts +14 -0
- package/dist/engine/summary/run-hooks.mjs +63 -0
- package/dist/engine/summary/run-lease.d.mts +11 -0
- package/dist/engine/summary/run-lease.mjs +64 -0
- package/dist/engine/summary/run-message-waits.d.mts +15 -0
- package/dist/engine/summary/run-message-waits.mjs +62 -0
- package/dist/engine/summary/run-metrics.d.mts +31 -0
- package/dist/engine/summary/run-metrics.mjs +93 -0
- package/dist/engine/summary/run-retry.d.mts +9 -0
- package/dist/engine/summary/run-retry.mjs +69 -0
- package/dist/engine/summary/run-sleeps.d.mts +15 -0
- package/dist/engine/summary/run-sleeps.mjs +61 -0
- package/dist/engine/summary/run-state.d.mts +26 -0
- package/dist/engine/summary/run-state.mjs +48 -0
- package/dist/engine/summary/run-status.d.mts +16 -0
- package/dist/engine/summary/run-status.mjs +35 -0
- package/dist/engine/summary/run-streams.d.mts +14 -0
- package/dist/engine/summary/run-streams.mjs +46 -0
- package/dist/engine/summary/run-transition.d.mts +9 -0
- package/dist/engine/summary/run-transition.mjs +39 -0
- package/dist/engine/summary/run-workflow.d.mts +9 -0
- package/dist/engine/summary/run-workflow.mjs +47 -0
- package/dist/engine/summary/step-attempt-active-child-workflows.d.mts +13 -0
- package/dist/engine/summary/step-attempt-active-child-workflows.mjs +55 -0
- package/dist/engine/summary/step-attempt-active-fields.d.mts +23 -0
- package/dist/engine/summary/step-attempt-active-fields.mjs +14 -0
- package/dist/engine/summary/step-attempt-active-message-waits.d.mts +12 -0
- package/dist/engine/summary/step-attempt-active-message-waits.mjs +47 -0
- package/dist/engine/summary/step-attempt-active-sleeps.d.mts +19 -0
- package/dist/engine/summary/step-attempt-active-sleeps.mjs +44 -0
- package/dist/engine/summary/step-attempt-buckets.d.mts +22 -0
- package/dist/engine/summary/step-attempt-buckets.mjs +152 -0
- package/dist/engine/summary/step-attempt-failure.d.mts +12 -0
- package/dist/engine/summary/step-attempt-failure.mjs +61 -0
- package/dist/engine/summary/step-attempt-lifecycle.d.mts +13 -0
- package/dist/engine/summary/step-attempt-lifecycle.mjs +19 -0
- package/dist/engine/summary/step-attempts.d.mts +11 -0
- package/dist/engine/summary/step-attempts.mjs +43 -0
- package/dist/engine/summary.d.mts +32 -0
- package/dist/engine/summary.mjs +37 -0
- package/dist/engine/task.d.mts +6 -0
- package/dist/engine/task.mjs +207 -0
- package/dist/errors/base.d.mts +99 -0
- package/dist/errors/base.mjs +426 -0
- package/dist/errors/capability.d.mts +11 -0
- package/dist/errors/capability.mjs +23 -0
- package/dist/errors/definition.d.mts +21 -0
- package/dist/errors/definition.mjs +51 -0
- package/dist/errors/details.d.mts +13 -0
- package/dist/errors/details.mjs +65 -0
- package/dist/errors/failures.d.mts +81 -0
- package/dist/errors/failures.mjs +168 -0
- package/dist/errors/hook.d.mts +14 -0
- package/dist/errors/hook.mjs +30 -0
- package/dist/errors/implementation.d.mts +11 -0
- package/dist/errors/implementation.mjs +25 -0
- package/dist/errors/lock.d.mts +28 -0
- package/dist/errors/lock.mjs +70 -0
- package/dist/errors/message.d.mts +106 -0
- package/dist/errors/message.mjs +122 -0
- package/dist/errors/mod.d.mts +17 -0
- package/dist/errors/mod.mjs +17 -0
- package/dist/errors/record-view.d.mts +11 -0
- package/dist/errors/record-view.mjs +24 -0
- package/dist/errors/records.d.mts +7 -0
- package/dist/errors/records.mjs +280 -0
- package/dist/errors/run.d.mts +116 -0
- package/dist/errors/run.mjs +232 -0
- package/dist/errors/runtime.d.mts +12 -0
- package/dist/errors/runtime.mjs +24 -0
- package/dist/errors/schedule.d.mts +27 -0
- package/dist/errors/schedule.mjs +65 -0
- package/dist/errors/step.d.mts +76 -0
- package/dist/errors/step.mjs +113 -0
- package/dist/errors/stream.d.mts +24 -0
- package/dist/errors/stream.mjs +64 -0
- package/dist/esbuild.d.mts +7 -0
- package/dist/esbuild.mjs +6 -0
- package/dist/events/descriptors.d.mts +245 -0
- package/dist/events/descriptors.mjs +405 -0
- package/dist/events/mod.d.mts +3 -0
- package/dist/events/mod.mjs +2 -0
- package/dist/history/attempt-key.d.mts +6 -0
- package/dist/history/attempt-key.mjs +7 -0
- package/dist/history/mod.d.mts +71 -0
- package/dist/history/mod.mjs +195 -0
- package/dist/history/projection.d.mts +8 -0
- package/dist/history/projection.mjs +259 -0
- package/dist/history/replay-projection.d.mts +88 -0
- package/dist/history/replay-projection.mjs +369 -0
- package/dist/history/sequencer.d.mts +16 -0
- package/dist/history/sequencer.mjs +78 -0
- package/dist/history/step-attempts.d.mts +9 -0
- package/dist/history/step-attempts.mjs +50 -0
- package/dist/history/timeline.d.mts +16 -0
- package/dist/history/timeline.mjs +272 -0
- package/dist/history/validator.d.mts +9 -0
- package/dist/history/validator.mjs +110 -0
- package/dist/inspection/mod.d.mts +5 -0
- package/dist/inspection/mod.mjs +3 -0
- package/dist/message-options.d.mts +8 -0
- package/dist/message-options.mjs +25 -0
- package/dist/mod.d.mts +52 -0
- package/dist/mod.mjs +26 -0
- package/dist/otel/support.d.mts +18 -0
- package/dist/otel/support.mjs +102 -0
- package/dist/otel.d.mts +30 -0
- package/dist/otel.mjs +588 -0
- package/dist/pagination.d.mts +25 -0
- package/dist/pagination.mjs +73 -0
- package/dist/registry.d.mts +20 -0
- package/dist/registry.mjs +48 -0
- package/dist/rolldown.d.mts +7 -0
- package/dist/rolldown.mjs +6 -0
- package/dist/rollup.d.mts +7 -0
- package/dist/rollup.mjs +6 -0
- package/dist/rspack.d.mts +7 -0
- package/dist/rspack.mjs +6 -0
- package/dist/runtime.d.mts +34 -0
- package/dist/runtime.mjs +194 -0
- package/dist/step-definition.d.mts +10 -0
- package/dist/step-definition.mjs +15 -0
- package/dist/store/append-projection.d.mts +15 -0
- package/dist/store/append-projection.mjs +26 -0
- package/dist/store/capabilities.d.mts +14 -0
- package/dist/store/capabilities.mjs +42 -0
- package/dist/store/cleanup.d.mts +18 -0
- package/dist/store/cleanup.mjs +338 -0
- package/dist/store/compaction.d.mts +5 -0
- package/dist/store/compaction.mjs +8 -0
- package/dist/store/create.d.mts +52 -0
- package/dist/store/create.mjs +159 -0
- package/dist/store/event-append-project.d.mts +15 -0
- package/dist/store/event-append-project.mjs +77 -0
- package/dist/store/event-append.d.mts +37 -0
- package/dist/store/event-append.mjs +80 -0
- package/dist/store/event-history.d.mts +22 -0
- package/dist/store/event-history.mjs +75 -0
- package/dist/store/event.d.mts +10 -0
- package/dist/store/event.mjs +28 -0
- package/dist/store/idempotency.d.mts +10 -0
- package/dist/store/idempotency.mjs +167 -0
- package/dist/store/instrumentation.d.mts +7 -0
- package/dist/store/instrumentation.mjs +123 -0
- package/dist/store/lock.d.mts +8 -0
- package/dist/store/lock.mjs +28 -0
- package/dist/store/materialization.d.mts +30 -0
- package/dist/store/materialization.mjs +127 -0
- package/dist/store/message-index.d.mts +21 -0
- package/dist/store/message-index.mjs +121 -0
- package/dist/store/mod.d.mts +5 -0
- package/dist/store/mod.mjs +4 -0
- package/dist/store/query.d.mts +24 -0
- package/dist/store/query.mjs +82 -0
- package/dist/store/revision.d.mts +4 -0
- package/dist/store/revision.mjs +7 -0
- package/dist/store/run.d.mts +49 -0
- package/dist/store/run.mjs +236 -0
- package/dist/store/schedule.d.mts +12 -0
- package/dist/store/schedule.mjs +41 -0
- package/dist/store/schema.d.mts +14 -0
- package/dist/store/schema.mjs +17 -0
- package/dist/store/step-attempt.d.mts +14 -0
- package/dist/store/step-attempt.mjs +23 -0
- package/dist/store/storage-value.d.mts +5 -0
- package/dist/store/storage-value.mjs +6 -0
- package/dist/store/validation.d.mts +35 -0
- package/dist/store/validation.mjs +77 -0
- package/dist/store-keys.d.mts +49 -0
- package/dist/store-keys.mjs +63 -0
- package/dist/telemetry.d.mts +132 -0
- package/dist/telemetry.mjs +172 -0
- package/dist/temporal.d.mts +23 -0
- package/dist/temporal.mjs +59 -0
- package/dist/timer.d.mts +12 -0
- package/dist/timer.mjs +28 -0
- package/dist/types/cleanup.d.mts +112 -0
- package/dist/types/cleanup.mjs +22 -0
- package/dist/types/client.d.mts +270 -0
- package/dist/types/client.mjs +1 -0
- package/dist/types/common.d.mts +19 -0
- package/dist/types/common.mjs +15 -0
- package/dist/types/definition.d.mts +92 -0
- package/dist/types/definition.mjs +1 -0
- package/dist/types/engine-options.d.mts +76 -0
- package/dist/types/engine-options.mjs +1 -0
- package/dist/types/engine.d.mts +309 -0
- package/dist/types/engine.mjs +1 -0
- package/dist/types/error-code.d.mts +256 -0
- package/dist/types/error-code.mjs +131 -0
- package/dist/types/error.d.mts +236 -0
- package/dist/types/error.mjs +48 -0
- package/dist/types/events.d.mts +2869 -0
- package/dist/types/events.mjs +283 -0
- package/dist/types/hook.d.mts +149 -0
- package/dist/types/hook.mjs +66 -0
- package/dist/types/lock.d.mts +63 -0
- package/dist/types/lock.mjs +18 -0
- package/dist/types/message-id.d.mts +7 -0
- package/dist/types/message-id.mjs +5 -0
- package/dist/types/message.d.mts +87 -0
- package/dist/types/message.mjs +1 -0
- package/dist/types/observation.d.mts +146 -0
- package/dist/types/observation.mjs +1 -0
- package/dist/types/pagination.d.mts +32 -0
- package/dist/types/pagination.mjs +13 -0
- package/dist/types/result.d.mts +62 -0
- package/dist/types/result.mjs +1 -0
- package/dist/types/retry.d.mts +48 -0
- package/dist/types/retry.mjs +1 -0
- package/dist/types/run-id.d.mts +7 -0
- package/dist/types/run-id.mjs +5 -0
- package/dist/types/run-list.d.mts +43 -0
- package/dist/types/run-list.mjs +1 -0
- package/dist/types/run-options.d.mts +86 -0
- package/dist/types/run-options.mjs +1 -0
- package/dist/types/run.d.mts +355 -0
- package/dist/types/run.mjs +207 -0
- package/dist/types/runtime.d.mts +143 -0
- package/dist/types/runtime.mjs +21 -0
- package/dist/types/schedule.d.mts +127 -0
- package/dist/types/schedule.mjs +48 -0
- package/dist/types/step-attempts.d.mts +326 -0
- package/dist/types/step-attempts.mjs +43 -0
- package/dist/types/step-id.d.mts +7 -0
- package/dist/types/step-id.mjs +5 -0
- package/dist/types/step.d.mts +183 -0
- package/dist/types/step.mjs +5 -0
- package/dist/types/store.d.mts +254 -0
- package/dist/types/store.mjs +1 -0
- package/dist/types/stream-id.d.mts +7 -0
- package/dist/types/stream-id.mjs +5 -0
- package/dist/types/stream.d.mts +126 -0
- package/dist/types/stream.mjs +1 -0
- package/dist/types/summary.d.mts +318 -0
- package/dist/types/summary.mjs +1 -0
- package/dist/types/telemetry.d.mts +74 -0
- package/dist/types/telemetry.mjs +9 -0
- package/dist/types/timeline.d.mts +237 -0
- package/dist/types/timeline.mjs +1 -0
- package/dist/types/vite.d.mts +65 -0
- package/dist/types/vite.mjs +1 -0
- package/dist/types/worker-id.d.mts +7 -0
- package/dist/types/worker-id.mjs +5 -0
- package/dist/types/worker.d.mts +94 -0
- package/dist/types/worker.mjs +1 -0
- package/dist/utility.d.mts +49 -0
- package/dist/utility.mjs +122 -0
- package/dist/vite/ast.d.mts +23 -0
- package/dist/vite/ast.mjs +73 -0
- package/dist/vite/error.d.mts +19 -0
- package/dist/vite/error.mjs +47 -0
- package/dist/vite/generated-name.d.mts +7 -0
- package/dist/vite/generated-name.mjs +9 -0
- package/dist/vite/manifest.d.mts +7 -0
- package/dist/vite/manifest.mjs +106 -0
- package/dist/vite/plugin.d.mts +7 -0
- package/dist/vite/plugin.mjs +190 -0
- package/dist/vite/safety.d.mts +12 -0
- package/dist/vite/safety.mjs +96 -0
- package/dist/vite/source-edit.d.mts +12 -0
- package/dist/vite/source-edit.mjs +44 -0
- package/dist/vite/source-map.d.mts +11 -0
- package/dist/vite/source-map.mjs +53 -0
- package/dist/vite/source.d.mts +7 -0
- package/dist/vite/source.mjs +14 -0
- package/dist/vite/transform.d.mts +7 -0
- package/dist/vite/transform.mjs +405 -0
- package/dist/vite.d.mts +6 -0
- package/dist/vite.mjs +5 -0
- package/dist/webhook.d.mts +16 -0
- package/dist/webhook.mjs +17 -0
- package/dist/webpack.d.mts +7 -0
- package/dist/webpack.mjs +6 -0
- package/dist/worker/error.d.mts +11 -0
- package/dist/worker/error.mjs +40 -0
- package/dist/worker.d.mts +18 -0
- package/dist/worker.mjs +427 -0
- package/package.json +144 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tin Rabzelj
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center" style="text-decoration:none;">@temelj/workflow</h1>
|
|
3
|
+
<br/>
|
|
4
|
+
<p align="center">
|
|
5
|
+
Durable, vendor-agnostic workflows for TypeScript.
|
|
6
|
+
</p>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://twitter.com/tinrab" rel="nofollow"><img src="https://img.shields.io/badge/created%20by-@tinrab-1d9bf0.svg" alt="Created by Tin Rabzelj"></a>
|
|
11
|
+
<a href="https://jsr.io/@temelj/workflow" rel="nofollow"><img src="https://jsr.io/badges/@temelj/workflow" alt="jsr"></a>
|
|
12
|
+
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/tinrab/temelj" alt="License"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
<a href="https://jsr.io/@temelj/workflow">jsr</a>
|
|
17
|
+
<span> • </span>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@temelj/workflow">npm</a>
|
|
19
|
+
<span> • </span>
|
|
20
|
+
<a href="https://github.com/tinrab/temelj/issues/new">Issues</a>
|
|
21
|
+
<span> • </span>
|
|
22
|
+
<a href="https://twitter.com/tinrab">@tinrab</a>
|
|
23
|
+
<br />
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<br/>
|
|
27
|
+
<br/>
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
# npm
|
|
33
|
+
$ npm install @temelj/workflow
|
|
34
|
+
# pnpm
|
|
35
|
+
$ pnpm add @temelj/workflow
|
|
36
|
+
# jsr
|
|
37
|
+
$ deno add jsr:@temelj/workflow # or jsr add @temelj/workflow
|
|
38
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WorkflowAttributePatch, WorkflowRunAttributes } from "./types/run.mjs";
|
|
2
|
+
import { EventRecord } from "./types/events.mjs";
|
|
3
|
+
//#region src/attributes.d.ts
|
|
4
|
+
interface WorkflowAttributeEventPatch {
|
|
5
|
+
readonly attributes?: WorkflowRunAttributes;
|
|
6
|
+
readonly removeAttributes?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
declare function normalizeWorkflowAttributePatch(value: WorkflowAttributePatch): WorkflowAttributePatch;
|
|
9
|
+
declare function workflowAttributeEventPatch(patch: WorkflowAttributePatch): WorkflowAttributeEventPatch;
|
|
10
|
+
declare function workflowAttributePatchFromEvent(event: Extract<EventRecord, {
|
|
11
|
+
readonly kind: "attributes_set";
|
|
12
|
+
}>): WorkflowAttributePatch;
|
|
13
|
+
declare function applyWorkflowAttributePatch(current: WorkflowRunAttributes | undefined, patch: WorkflowAttributePatch): WorkflowRunAttributes | undefined;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { WorkflowAttributeEventPatch, applyWorkflowAttributePatch, normalizeWorkflowAttributePatch, workflowAttributeEventPatch, workflowAttributePatchFromEvent };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { workflowAttributePatchSchema } from "./types/run.mjs";
|
|
2
|
+
//#region src/attributes.ts
|
|
3
|
+
function normalizeWorkflowAttributePatch(value) {
|
|
4
|
+
workflowAttributePatchSchema.parse(value);
|
|
5
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)));
|
|
6
|
+
}
|
|
7
|
+
function workflowAttributeEventPatch(patch) {
|
|
8
|
+
const attributes = Object.fromEntries(Object.entries(patch).filter((entry) => entry[1] !== void 0));
|
|
9
|
+
const removeAttributes = Object.entries(patch).filter(([, value]) => value === void 0).map(([key]) => key);
|
|
10
|
+
return {
|
|
11
|
+
...Object.keys(attributes).length > 0 && { attributes },
|
|
12
|
+
...removeAttributes.length > 0 && { removeAttributes }
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function workflowAttributePatchFromEvent(event) {
|
|
16
|
+
return {
|
|
17
|
+
...event.attributes,
|
|
18
|
+
...Object.fromEntries((event.removeAttributes ?? []).map((key) => [key, void 0]))
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function applyWorkflowAttributePatch(current, patch) {
|
|
22
|
+
const next = { ...current };
|
|
23
|
+
for (const [key, value] of Object.entries(patch)) if (value === void 0) delete next[key];
|
|
24
|
+
else next[key] = value;
|
|
25
|
+
const entries = Object.entries(next).sort(([left], [right]) => left.localeCompare(right));
|
|
26
|
+
if (entries.length === 0) return;
|
|
27
|
+
return Object.fromEntries(entries);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { applyWorkflowAttributePatch, normalizeWorkflowAttributePatch, workflowAttributeEventPatch, workflowAttributePatchFromEvent };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RegistryLike, WorkflowDefinition, WorkflowHandler, WorkflowImplementation } from "../types/definition.mjs";
|
|
2
|
+
import { CreateWorkflowEngineOptions } from "../types/engine-options.mjs";
|
|
3
|
+
import { WorkflowClientEngine, WorkflowWorkerEngine } from "../types/engine.mjs";
|
|
4
|
+
import { WorkflowClient as WorkflowClient$1, WorkflowClientAdminApi, WorkflowClientHooksApi, WorkflowClientLocksApi, WorkflowClientMessagesApi, WorkflowClientRunsApi, WorkflowClientSchedulesApi, WorkflowClientStreamsApi, WorkflowClientWorkersApi, WorkflowRunnable } from "../types/client.mjs";
|
|
5
|
+
//#region src/client/create.d.ts
|
|
6
|
+
type WorkflowClientEngineOptions = Omit<CreateWorkflowEngineOptions, "storage" | "store">;
|
|
7
|
+
interface CreateWorkflowClientOptions extends WorkflowClientEngineOptions {
|
|
8
|
+
readonly engine?: WorkflowClientEngine;
|
|
9
|
+
readonly workerEngine?: WorkflowWorkerEngine;
|
|
10
|
+
readonly registry?: RegistryLike;
|
|
11
|
+
}
|
|
12
|
+
declare function createWorkflowClient(options?: CreateWorkflowClientOptions): WorkflowClient$1;
|
|
13
|
+
/** Workflow client facade implementation. */
|
|
14
|
+
declare class WorkflowClient implements WorkflowClient$1 {
|
|
15
|
+
#private;
|
|
16
|
+
readonly runs: WorkflowClientRunsApi;
|
|
17
|
+
readonly admin: WorkflowClientAdminApi;
|
|
18
|
+
readonly schedules: WorkflowClientSchedulesApi;
|
|
19
|
+
readonly locks: WorkflowClientLocksApi;
|
|
20
|
+
readonly hooks: WorkflowClientHooksApi;
|
|
21
|
+
readonly streams: WorkflowClientStreamsApi;
|
|
22
|
+
readonly messages: WorkflowClientMessagesApi;
|
|
23
|
+
readonly workers: WorkflowClientWorkersApi;
|
|
24
|
+
constructor(options?: CreateWorkflowClientOptions);
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
implementWorkflow<TInput, TOutput, TRawInput = TInput>(definition: WorkflowDefinition<TInput, TOutput, TRawInput>, handler: WorkflowHandler<TInput, TOutput>): WorkflowImplementation<TInput, TOutput, TRawInput>;
|
|
27
|
+
register<TInput, TOutput, TRawInput = TInput>(implementation: WorkflowImplementation<TInput, TOutput, TRawInput>): void;
|
|
28
|
+
workflow<TInput, TOutput, TRawInput = TInput>(definition: WorkflowDefinition<TInput, TOutput, TRawInput>, handler: WorkflowHandler<TInput, TOutput>): WorkflowRunnable<TInput, TOutput, TRawInput>;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CreateWorkflowClientOptions, WorkflowClient, createWorkflowClient };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createWorkflowClientAdminApi, createWorkflowClientHooksApi, createWorkflowClientLocksApi, createWorkflowClientMessagesApi, createWorkflowClientRunsApi, createWorkflowClientSchedulesApi, createWorkflowClientStreamsApi, createWorkflowClientWorkersApi } from "./facades.mjs";
|
|
2
|
+
import { createWorkflowEngine } from "../engine/create.mjs";
|
|
3
|
+
import { Registry } from "../registry.mjs";
|
|
4
|
+
//#region src/client/create.ts
|
|
5
|
+
function createWorkflowClient(options = {}) {
|
|
6
|
+
return new WorkflowClient(options);
|
|
7
|
+
}
|
|
8
|
+
/** Workflow client facade implementation. */
|
|
9
|
+
var WorkflowClient = class {
|
|
10
|
+
runs;
|
|
11
|
+
admin;
|
|
12
|
+
schedules;
|
|
13
|
+
locks;
|
|
14
|
+
hooks;
|
|
15
|
+
streams;
|
|
16
|
+
messages;
|
|
17
|
+
workers;
|
|
18
|
+
#engine;
|
|
19
|
+
#workerEngine;
|
|
20
|
+
#now;
|
|
21
|
+
#registry;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
const { engine, workerEngine, registry, now, ...engineOptions } = options;
|
|
24
|
+
this.#now = now ?? Temporal.Now.instant;
|
|
25
|
+
this.#engine = engine ?? createWorkflowEngine({
|
|
26
|
+
...engineOptions,
|
|
27
|
+
now: this.#now
|
|
28
|
+
});
|
|
29
|
+
this.#workerEngine = workerEngine ?? workflowWorkerEngineFromCandidate(this.#engine);
|
|
30
|
+
this.#registry = registry ?? new Registry();
|
|
31
|
+
this.runs = createWorkflowClientRunsApi(() => this.#engine, this.#now);
|
|
32
|
+
this.admin = createWorkflowClientAdminApi(() => this.#engine, this.#now);
|
|
33
|
+
this.schedules = createWorkflowClientSchedulesApi(() => this.#engine, this.#now);
|
|
34
|
+
this.locks = createWorkflowClientLocksApi(() => this.#engine);
|
|
35
|
+
this.hooks = createWorkflowClientHooksApi(() => this.#engine);
|
|
36
|
+
this.streams = createWorkflowClientStreamsApi(() => this.#engine);
|
|
37
|
+
this.messages = createWorkflowClientMessagesApi(() => this.#engine);
|
|
38
|
+
this.workers = createWorkflowClientWorkersApi(() => this.#workerEngine, () => this.#registry, this.#now);
|
|
39
|
+
}
|
|
40
|
+
async close() {
|
|
41
|
+
await this.#engine.close?.();
|
|
42
|
+
}
|
|
43
|
+
implementWorkflow(definition, handler) {
|
|
44
|
+
return this.#registry.implementWorkflow(definition, handler);
|
|
45
|
+
}
|
|
46
|
+
register(implementation) {
|
|
47
|
+
if (this.#registry.get(implementation.definition) === implementation) return;
|
|
48
|
+
this.#registry.register(implementation);
|
|
49
|
+
}
|
|
50
|
+
workflow(definition, handler) {
|
|
51
|
+
this.#registry.implementWorkflow(definition, handler);
|
|
52
|
+
return {
|
|
53
|
+
definition,
|
|
54
|
+
run: (...runArgs) => this.runs.start(definition, ...runArgs)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function workflowWorkerEngineFromCandidate(engine) {
|
|
59
|
+
return isWorkflowWorkerEngine(engine) ? engine : void 0;
|
|
60
|
+
}
|
|
61
|
+
function isWorkflowWorkerEngine(candidate) {
|
|
62
|
+
const engine = candidate;
|
|
63
|
+
if (typeof engine.resumeWorkflow !== "function" || typeof engine.getRun !== "function" || typeof engine.getRunSummary !== "function" || typeof engine.listSchedules !== "function" || typeof engine.tickSchedules !== "function" || engine.store === void 0) return false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { WorkflowClient, createWorkflowClient };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RegistryLike } from "../types/definition.mjs";
|
|
2
|
+
import { LockManager, WorkflowCleanupAdmin, WorkflowHookManager, WorkflowMessageSender, WorkflowRunHandleReader, WorkflowRunMaintenance, WorkflowRunReader, WorkflowRunRerunner, WorkflowScheduler, WorkflowStarter, WorkflowStepAttemptReader, WorkflowStreamReader, WorkflowWorkerEngine } from "../types/engine.mjs";
|
|
3
|
+
import { WorkflowClientAdminApi, WorkflowClientHooksApi, WorkflowClientLocksApi, WorkflowClientMessagesApi, WorkflowClientRunsApi, WorkflowClientSchedulesApi, WorkflowClientStreamsApi, WorkflowClientWorkersApi } from "../types/client.mjs";
|
|
4
|
+
//#region src/client/facades.d.ts
|
|
5
|
+
type WorkflowRunHandleEngine = WorkflowRunMaintenance & WorkflowRunHandleReader & WorkflowStreamReader;
|
|
6
|
+
type WorkflowClientRunsEngine = WorkflowStarter & WorkflowRunReader & WorkflowRunHandleEngine & WorkflowStepAttemptReader;
|
|
7
|
+
type WorkflowClientAdminEngine = WorkflowCleanupAdmin & WorkflowRunRerunner & WorkflowRunHandleEngine;
|
|
8
|
+
type WorkflowClientSchedulesEngine = WorkflowRunHandleEngine & WorkflowScheduler;
|
|
9
|
+
type WorkflowWorkerEngineAccessor = () => WorkflowWorkerEngine | undefined;
|
|
10
|
+
type WorkflowRegistryAccessor = () => RegistryLike;
|
|
11
|
+
type WorkflowClockAccessor = () => Temporal.Instant;
|
|
12
|
+
declare function createWorkflowClientRunsApi(getEngine: () => WorkflowClientRunsEngine, now: WorkflowClockAccessor): WorkflowClientRunsApi;
|
|
13
|
+
declare function createWorkflowClientAdminApi(getEngine: () => WorkflowClientAdminEngine, now: WorkflowClockAccessor): WorkflowClientAdminApi;
|
|
14
|
+
declare function createWorkflowClientSchedulesApi(getEngine: () => WorkflowClientSchedulesEngine, now: WorkflowClockAccessor): WorkflowClientSchedulesApi;
|
|
15
|
+
declare function createWorkflowClientLocksApi(getEngine: () => LockManager): WorkflowClientLocksApi;
|
|
16
|
+
declare function createWorkflowClientHooksApi(getEngine: () => WorkflowHookManager): WorkflowClientHooksApi;
|
|
17
|
+
declare function createWorkflowClientStreamsApi(getEngine: () => WorkflowStreamReader): WorkflowClientStreamsApi;
|
|
18
|
+
declare function createWorkflowClientMessagesApi(getEngine: () => WorkflowMessageSender): WorkflowClientMessagesApi;
|
|
19
|
+
declare function createWorkflowClientWorkersApi(getEngine: WorkflowWorkerEngineAccessor, getRegistry: WorkflowRegistryAccessor, now: WorkflowClockAccessor): WorkflowClientWorkersApi;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createWorkflowClientAdminApi, createWorkflowClientHooksApi, createWorkflowClientLocksApi, createWorkflowClientMessagesApi, createWorkflowClientRunsApi, createWorkflowClientSchedulesApi, createWorkflowClientStreamsApi, createWorkflowClientWorkersApi };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { resolvePositiveSafeIntegerOption } from "../utility.mjs";
|
|
2
|
+
import { WorkflowCapabilityError } from "../errors/capability.mjs";
|
|
3
|
+
import { defineWorkflowFromName, defineWorkflowFromTarget } from "../definition.mjs";
|
|
4
|
+
import { resolveBroadcastMessageInput, resolveSendMessageInput } from "../message-options.mjs";
|
|
5
|
+
import { createWorkflowRunHandle } from "./run-handle.mjs";
|
|
6
|
+
import { workerOptionsFromClientOptions, workerOptionsFromWakeOptions } from "./worker-options.mjs";
|
|
7
|
+
import { resolveScheduleNextOptions } from "../engine/start-api.mjs";
|
|
8
|
+
import { WorkflowWorker } from "../worker.mjs";
|
|
9
|
+
//#region src/client/facades.ts
|
|
10
|
+
function requireWorkflowWorkerEngine(engine) {
|
|
11
|
+
if (engine === void 0) WorkflowCapabilityError.unsupported("workflow worker engine");
|
|
12
|
+
return engine;
|
|
13
|
+
}
|
|
14
|
+
function createWorkflowClientRunsApi(getEngine, now) {
|
|
15
|
+
return {
|
|
16
|
+
async start(workflow, ...runArgs) {
|
|
17
|
+
const [input, runOptions] = runArgs;
|
|
18
|
+
const definition = defineWorkflowFromTarget(workflow);
|
|
19
|
+
const handle = await getEngine().startWorkflow(definition, input, runOptions);
|
|
20
|
+
return createWorkflowRunHandle(getEngine(), definition, handle.runId, now);
|
|
21
|
+
},
|
|
22
|
+
async startBatch(workflow, items) {
|
|
23
|
+
const definition = defineWorkflowFromTarget(workflow);
|
|
24
|
+
return (await getEngine().startWorkflows(definition, items)).map((handle) => createWorkflowRunHandle(getEngine(), definition, handle.runId, now));
|
|
25
|
+
},
|
|
26
|
+
get: async (runId) => await getEngine().getRun(runId),
|
|
27
|
+
events: async (runId) => await getEngine().getEvents(runId),
|
|
28
|
+
eventsPage: async (runId, options) => await getEngine().listEventsPage(runId, options),
|
|
29
|
+
list: async (options) => await getEngine().listRuns(options),
|
|
30
|
+
page: async (options) => await getEngine().listRunsPage(options),
|
|
31
|
+
count: async (options) => await getEngine().countRuns(options),
|
|
32
|
+
summary: async (options) => await getEngine().getRunSummary(options),
|
|
33
|
+
recovery: async (options) => await getEngine().getRecoverySummary(options),
|
|
34
|
+
timeline: async (runId) => await getEngine().getTimeline(runId),
|
|
35
|
+
listStepAttempts: async (runId, options) => await getEngine().listStepAttempts(runId, options),
|
|
36
|
+
listStepAttemptsPage: async (runId, options) => await getEngine().listStepAttemptsPage(runId, options),
|
|
37
|
+
countStepAttempts: async (runId, options) => await getEngine().countStepAttempts(runId, options),
|
|
38
|
+
stepAttemptSummary: async (runId, options) => await getEngine().getStepAttemptSummary(runId, options)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createWorkflowClientAdminApi(getEngine, now) {
|
|
42
|
+
return {
|
|
43
|
+
cleanup: async (options) => await getEngine().cleanupRuns(options),
|
|
44
|
+
cleanupMarkers: async () => await getEngine().listCleanupMarkers(),
|
|
45
|
+
applyRetentionPolicy: async (options) => await getEngine().applyRetentionPolicy(options),
|
|
46
|
+
rerun: async (runId, options) => {
|
|
47
|
+
const handle = await getEngine().rerunWorkflow(runId, options);
|
|
48
|
+
return createWorkflowRunHandle(getEngine(), defineWorkflowFromName(handle.workflowName, handle.workflowVersion), handle.runId, now);
|
|
49
|
+
},
|
|
50
|
+
reschedule: async (runId, options) => await getEngine().rescheduleRun(runId, options),
|
|
51
|
+
releaseStaleLease: async (runId, options) => await getEngine().releaseStaleRunLease(runId, options),
|
|
52
|
+
retryFailed: async (runId, options) => await getEngine().retryFailedRun(runId, options),
|
|
53
|
+
markPermanentlyFailed: async (runId, options) => await getEngine().markRunPermanentlyFailed(runId, options),
|
|
54
|
+
updateMetadata: async (runId, metadata) => await getEngine().updateRunMetadata(runId, metadata),
|
|
55
|
+
setAttributes: async (runId, attributes) => await getEngine().setRunAttributes(runId, attributes),
|
|
56
|
+
cancel: async (runId) => await getEngine().cancelRun(runId)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function createWorkflowClientSchedulesApi(getEngine, now) {
|
|
60
|
+
return {
|
|
61
|
+
async next(workflow, input, scheduleOptions) {
|
|
62
|
+
const definition = defineWorkflowFromTarget(workflow);
|
|
63
|
+
const options = resolveScheduleNextOptions(scheduleOptions, now);
|
|
64
|
+
const handle = await getEngine().scheduleNextWorkflow(definition, input, options.schedule);
|
|
65
|
+
return createWorkflowRunHandle(getEngine(), definition, handle.runId, now);
|
|
66
|
+
},
|
|
67
|
+
create: async (workflow, options) => await getEngine().createSchedule(workflow, options),
|
|
68
|
+
upsert: async (workflow, options) => await getEngine().upsertSchedule(workflow, options),
|
|
69
|
+
get: async (scheduleId) => await getEngine().getSchedule(scheduleId),
|
|
70
|
+
list: async (options) => await getEngine().listSchedules(options),
|
|
71
|
+
page: async (options) => await getEngine().listSchedulesPage(options),
|
|
72
|
+
pause: async (scheduleId) => await getEngine().pauseSchedule(scheduleId),
|
|
73
|
+
resume: async (scheduleId) => await getEngine().resumeSchedule(scheduleId),
|
|
74
|
+
archive: async (scheduleId) => await getEngine().archiveSchedule(scheduleId),
|
|
75
|
+
delete: async (scheduleId) => await getEngine().deleteSchedule(scheduleId),
|
|
76
|
+
tick: async (options) => await getEngine().tickSchedules(options)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function createWorkflowClientLocksApi(getEngine) {
|
|
80
|
+
return {
|
|
81
|
+
acquire: async (key, options) => await getEngine().acquireLock(key, options),
|
|
82
|
+
get: async (key) => await getEngine().getLock(key),
|
|
83
|
+
list: async () => await getEngine().listLocks(),
|
|
84
|
+
release: async (key, options) => await getEngine().releaseLock(key, options),
|
|
85
|
+
releaseStale: async (key, options) => await getEngine().releaseStaleLock(key, options)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createWorkflowClientHooksApi(getEngine) {
|
|
89
|
+
return {
|
|
90
|
+
resume: async (token, options) => await getEngine().resumeHook(token, options),
|
|
91
|
+
resumeWebhook: async (token, options) => await getEngine().resumeWebhook(token, options),
|
|
92
|
+
dispose: async (token) => await getEngine().disposeHook(token),
|
|
93
|
+
disposeWebhook: async (token) => await getEngine().disposeWebhook(token),
|
|
94
|
+
getByToken: async (token) => await getEngine().getHookByToken(token)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function createWorkflowClientStreamsApi(getEngine) {
|
|
98
|
+
return {
|
|
99
|
+
getInfo: async (runId, streamIdOrName) => await getEngine().getStreamInfo(runId, streamIdOrName),
|
|
100
|
+
follow: (runId, streamIdOrName, options) => getEngine().followStream(runId, streamIdOrName, options),
|
|
101
|
+
wait: async (runId, streamIdOrName, options) => await getEngine().waitForStream(runId, streamIdOrName, options),
|
|
102
|
+
waitForChunk: async (runId, streamIdOrName, afterIndex, options) => await getEngine().waitForStreamChunk(runId, streamIdOrName, afterIndex, options),
|
|
103
|
+
waitForTerminal: async (runId, streamIdOrName, options) => await getEngine().waitForStreamTerminal(runId, streamIdOrName, options),
|
|
104
|
+
read: async (runId, streamIdOrName, options) => await getEngine().readStream(runId, streamIdOrName, options),
|
|
105
|
+
readPage: async (runId, streamIdOrName, options) => await getEngine().readStreamPage(runId, streamIdOrName, options)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function createWorkflowClientMessagesApi(getEngine) {
|
|
109
|
+
return {
|
|
110
|
+
async send(runId, messageInput, channelOptions) {
|
|
111
|
+
const options = await resolveSendMessageInput(messageInput, channelOptions);
|
|
112
|
+
await getEngine().sendMessage(runId, options);
|
|
113
|
+
},
|
|
114
|
+
async broadcast(messageInput, channelOptions) {
|
|
115
|
+
const options = await resolveBroadcastMessageInput(messageInput, channelOptions);
|
|
116
|
+
return getEngine().broadcastMessage(options);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function createWorkflowClientWorkersApi(getEngine, getRegistry, now) {
|
|
121
|
+
return {
|
|
122
|
+
create: (options) => {
|
|
123
|
+
return new WorkflowWorker(workerOptionsFromClientOptions(requireWorkflowWorkerEngine(getEngine()), getRegistry(), now, options));
|
|
124
|
+
},
|
|
125
|
+
processRun: async (runId, options) => {
|
|
126
|
+
await new WorkflowWorker(workerOptionsFromClientOptions(requireWorkflowWorkerEngine(getEngine()), getRegistry(), now, workerOptionsFromWakeOptions(options))).processRun(runId);
|
|
127
|
+
},
|
|
128
|
+
wakeDueRuns: async (options) => {
|
|
129
|
+
const worker = new WorkflowWorker(workerOptionsFromClientOptions(requireWorkflowWorkerEngine(getEngine()), getRegistry(), now, workerOptionsFromWakeOptions(options)));
|
|
130
|
+
const filters = options === void 0 ? {} : options;
|
|
131
|
+
const maxRuns = resolvePositiveSafeIntegerOption(options?.maxRuns, "Workflow worker maxRuns") ?? 1;
|
|
132
|
+
let processedRuns = 0;
|
|
133
|
+
while (options?.signal?.aborted !== true && processedRuns < maxRuns) {
|
|
134
|
+
if (await worker.processNextRun(filters) === void 0) break;
|
|
135
|
+
processedRuns++;
|
|
136
|
+
}
|
|
137
|
+
return { processedRuns };
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { createWorkflowClientAdminApi, createWorkflowClientHooksApi, createWorkflowClientLocksApi, createWorkflowClientMessagesApi, createWorkflowClientRunsApi, createWorkflowClientSchedulesApi, createWorkflowClientStreamsApi, createWorkflowClientWorkersApi };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { RunId } from "../types/run-id.mjs";
|
|
2
|
+
import { WorkflowDefinition } from "../types/definition.mjs";
|
|
3
|
+
import { StreamIdOrName } from "../types/stream-id.mjs";
|
|
4
|
+
import { FollowStreamOptions, ReadStreamOptions, ReadStreamPageOptions, StreamChunk, StreamInfo, StreamPage, StreamState, StreamUpdate, WaitStreamOptions } from "../types/stream.mjs";
|
|
5
|
+
import { Timeline } from "../types/timeline.mjs";
|
|
6
|
+
import { ResultOptions } from "../types/result.mjs";
|
|
7
|
+
import { WorkflowAttributePatch, WorkflowRunRecord, WorkflowRunStatus } from "../types/run.mjs";
|
|
8
|
+
import { EventRecord } from "../types/events.mjs";
|
|
9
|
+
import { WorkflowMarkRunPermanentlyFailedOptions, WorkflowReleaseStaleLeaseOptions, WorkflowRescheduleRunOptions, WorkflowRetryFailedRunOptions } from "../types/run-options.mjs";
|
|
10
|
+
import { WorkflowRunHandleReader, WorkflowRunMaintenance, WorkflowStreamReader } from "../types/engine.mjs";
|
|
11
|
+
import { WorkflowRunHandle as WorkflowRunHandle$1 } from "../types/client.mjs";
|
|
12
|
+
import "../mod.mjs";
|
|
13
|
+
import { StorageValue } from "@temelj/storage";
|
|
14
|
+
//#region src/client/run-handle.d.ts
|
|
15
|
+
type WorkflowRunHandleEngine = WorkflowRunHandleReader & WorkflowStreamReader & WorkflowRunMaintenance;
|
|
16
|
+
declare function createWorkflowRunHandle<TOutput>(engine: WorkflowRunHandleEngine, definition: WorkflowDefinition<unknown, TOutput>, runId: RunId, now: () => Temporal.Instant): WorkflowRunHandle$1<TOutput>;
|
|
17
|
+
declare class WorkflowRunHandle<TOutput> implements WorkflowRunHandle$1<TOutput> {
|
|
18
|
+
#private;
|
|
19
|
+
/** @inheritdoc */
|
|
20
|
+
readonly runId: RunId;
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
readonly workflowName: string;
|
|
23
|
+
/** @inheritdoc */
|
|
24
|
+
readonly workflowVersion?: string;
|
|
25
|
+
constructor(engine: WorkflowRunHandleEngine, definition: WorkflowDefinition<unknown, TOutput>, runId: RunId, now: () => Temporal.Instant);
|
|
26
|
+
/** @inheritdoc */
|
|
27
|
+
getRun(): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
status(): Promise<WorkflowRunStatus>;
|
|
30
|
+
/** @inheritdoc */
|
|
31
|
+
events(): Promise<readonly EventRecord[]>;
|
|
32
|
+
/** @inheritdoc */
|
|
33
|
+
timeline(): Promise<Timeline>;
|
|
34
|
+
/** @inheritdoc */
|
|
35
|
+
result(options?: ResultOptions): Promise<TOutput>;
|
|
36
|
+
/** @inheritdoc */
|
|
37
|
+
getStreamInfo(streamIdOrName: StreamIdOrName): Promise<StreamInfo>;
|
|
38
|
+
/** @inheritdoc */
|
|
39
|
+
followStream<TChunk = unknown>(streamIdOrName: StreamIdOrName, followOptions?: FollowStreamOptions): AsyncIterable<StreamUpdate<TChunk>>;
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
waitForStream(streamIdOrName: StreamIdOrName, waitOptions?: WaitStreamOptions): Promise<StreamInfo | undefined>;
|
|
42
|
+
/** @inheritdoc */
|
|
43
|
+
waitForStreamChunk<TChunk = unknown>(streamIdOrName: StreamIdOrName, afterIndex: number, waitOptions?: WaitStreamOptions): Promise<StreamChunk<TChunk> | undefined>;
|
|
44
|
+
/** @inheritdoc */
|
|
45
|
+
waitForStreamTerminal(streamIdOrName: StreamIdOrName, waitOptions?: WaitStreamOptions): Promise<StreamInfo | undefined>;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
readStream<TChunk = unknown>(streamIdOrName: StreamIdOrName, readOptions?: ReadStreamOptions): Promise<StreamState<TChunk>>;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
readStreamPage<TChunk = unknown>(streamIdOrName: StreamIdOrName, readOptions?: ReadStreamPageOptions): Promise<StreamPage<TChunk>>;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
reschedule(options?: WorkflowRescheduleRunOptions): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
52
|
+
/** @inheritdoc */
|
|
53
|
+
releaseStaleLease(options?: WorkflowReleaseStaleLeaseOptions): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
54
|
+
/** @inheritdoc */
|
|
55
|
+
retryFailed(options?: WorkflowRetryFailedRunOptions): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
56
|
+
/** @inheritdoc */
|
|
57
|
+
markPermanentlyFailed(options: WorkflowMarkRunPermanentlyFailedOptions): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
58
|
+
/** @inheritdoc */
|
|
59
|
+
setMetadata(metadata: unknown): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
60
|
+
/** @inheritdoc */
|
|
61
|
+
setAttributes(attributes: WorkflowAttributePatch): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
62
|
+
/** @inheritdoc */
|
|
63
|
+
cancel(): Promise<WorkflowRunRecord<StorageValue, StorageValue>>;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { WorkflowRunHandle, createWorkflowRunHandle };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { WorkflowResultTimeoutError, WorkflowRunCanceledError, WorkflowRunNotFoundError } from "../errors/run.mjs";
|
|
2
|
+
import { durationTotal } from "../utility.mjs";
|
|
3
|
+
import "../errors/mod.mjs";
|
|
4
|
+
import { workflowErrorFromRecord } from "../errors/records.mjs";
|
|
5
|
+
import { durationBetween } from "../temporal.mjs";
|
|
6
|
+
import { nonNegativeTimerDelay, sleep } from "../timer.mjs";
|
|
7
|
+
//#region src/client/run-handle.ts
|
|
8
|
+
const DEFAULT_RESULT_POLL_INTERVAL = Temporal.Duration.from({ milliseconds: 100 });
|
|
9
|
+
function createWorkflowRunHandle(engine, definition, runId, now) {
|
|
10
|
+
return new WorkflowRunHandle(engine, definition, runId, now);
|
|
11
|
+
}
|
|
12
|
+
var WorkflowRunHandle = class {
|
|
13
|
+
/** @inheritdoc */
|
|
14
|
+
runId;
|
|
15
|
+
/** @inheritdoc */
|
|
16
|
+
workflowName;
|
|
17
|
+
/** @inheritdoc */
|
|
18
|
+
workflowVersion;
|
|
19
|
+
#engine;
|
|
20
|
+
#now;
|
|
21
|
+
constructor(engine, definition, runId, now) {
|
|
22
|
+
this.#engine = engine;
|
|
23
|
+
this.#now = now;
|
|
24
|
+
this.runId = runId;
|
|
25
|
+
this.workflowName = definition.name;
|
|
26
|
+
if (definition.version !== void 0) this.workflowVersion = definition.version;
|
|
27
|
+
}
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
async getRun() {
|
|
30
|
+
const run = await this.#engine.getRun(this.runId);
|
|
31
|
+
if (run === void 0) WorkflowRunNotFoundError.notFound(this.runId);
|
|
32
|
+
return run;
|
|
33
|
+
}
|
|
34
|
+
/** @inheritdoc */
|
|
35
|
+
async status() {
|
|
36
|
+
const run = await this.#engine.getRun(this.runId);
|
|
37
|
+
if (run === void 0) WorkflowRunNotFoundError.notFound(this.runId);
|
|
38
|
+
return run.status;
|
|
39
|
+
}
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
async events() {
|
|
42
|
+
return await this.#engine.getEvents(this.runId);
|
|
43
|
+
}
|
|
44
|
+
/** @inheritdoc */
|
|
45
|
+
async timeline() {
|
|
46
|
+
return await this.#engine.getTimeline(this.runId);
|
|
47
|
+
}
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
async result(options) {
|
|
50
|
+
const pollInterval = nonNegativeTimerDelay(options?.pollInterval ?? DEFAULT_RESULT_POLL_INTERVAL, "Workflow result pollInterval").clampedDelay;
|
|
51
|
+
const timeout = options?.timeout;
|
|
52
|
+
const deadlineAt = timeout === void 0 ? void 0 : this.#now().add(timeout);
|
|
53
|
+
while (true) {
|
|
54
|
+
const run = await this.#engine.getRun(this.runId);
|
|
55
|
+
if (run === void 0) WorkflowRunNotFoundError.notFound(this.runId);
|
|
56
|
+
if (run.status === "canceled") WorkflowRunCanceledError.canceled(this.runId);
|
|
57
|
+
const result = runToResult(run, this.runId, this.#now());
|
|
58
|
+
if (result.kind === "completed") return result.output;
|
|
59
|
+
if (result.kind === "failed") throw workflowErrorFromRecord(result.error);
|
|
60
|
+
let sleepDelay = pollInterval;
|
|
61
|
+
if (timeout !== void 0 && deadlineAt !== void 0) {
|
|
62
|
+
const remainingDelay = durationTotal(durationBetween(this.#now(), deadlineAt));
|
|
63
|
+
if (remainingDelay <= 0) WorkflowResultTimeoutError.timedOut(this.runId, timeout);
|
|
64
|
+
sleepDelay = Math.min(sleepDelay, remainingDelay);
|
|
65
|
+
}
|
|
66
|
+
await sleep(sleepDelay);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** @inheritdoc */
|
|
70
|
+
async getStreamInfo(streamIdOrName) {
|
|
71
|
+
return await this.#engine.getStreamInfo(this.runId, streamIdOrName);
|
|
72
|
+
}
|
|
73
|
+
/** @inheritdoc */
|
|
74
|
+
followStream(streamIdOrName, followOptions) {
|
|
75
|
+
return this.#engine.followStream(this.runId, streamIdOrName, followOptions);
|
|
76
|
+
}
|
|
77
|
+
/** @inheritdoc */
|
|
78
|
+
async waitForStream(streamIdOrName, waitOptions) {
|
|
79
|
+
return await this.#engine.waitForStream(this.runId, streamIdOrName, waitOptions);
|
|
80
|
+
}
|
|
81
|
+
/** @inheritdoc */
|
|
82
|
+
async waitForStreamChunk(streamIdOrName, afterIndex, waitOptions) {
|
|
83
|
+
return await this.#engine.waitForStreamChunk(this.runId, streamIdOrName, afterIndex, waitOptions);
|
|
84
|
+
}
|
|
85
|
+
/** @inheritdoc */
|
|
86
|
+
async waitForStreamTerminal(streamIdOrName, waitOptions) {
|
|
87
|
+
return await this.#engine.waitForStreamTerminal(this.runId, streamIdOrName, waitOptions);
|
|
88
|
+
}
|
|
89
|
+
/** @inheritdoc */
|
|
90
|
+
async readStream(streamIdOrName, readOptions) {
|
|
91
|
+
return await this.#engine.readStream(this.runId, streamIdOrName, readOptions);
|
|
92
|
+
}
|
|
93
|
+
/** @inheritdoc */
|
|
94
|
+
async readStreamPage(streamIdOrName, readOptions) {
|
|
95
|
+
return await this.#engine.readStreamPage(this.runId, streamIdOrName, readOptions);
|
|
96
|
+
}
|
|
97
|
+
/** @inheritdoc */
|
|
98
|
+
async reschedule(options) {
|
|
99
|
+
return await this.#engine.rescheduleRun(this.runId, options);
|
|
100
|
+
}
|
|
101
|
+
/** @inheritdoc */
|
|
102
|
+
async releaseStaleLease(options) {
|
|
103
|
+
return await this.#engine.releaseStaleRunLease(this.runId, options);
|
|
104
|
+
}
|
|
105
|
+
/** @inheritdoc */
|
|
106
|
+
async retryFailed(options) {
|
|
107
|
+
return await this.#engine.retryFailedRun(this.runId, options);
|
|
108
|
+
}
|
|
109
|
+
/** @inheritdoc */
|
|
110
|
+
async markPermanentlyFailed(options) {
|
|
111
|
+
return await this.#engine.markRunPermanentlyFailed(this.runId, options);
|
|
112
|
+
}
|
|
113
|
+
/** @inheritdoc */
|
|
114
|
+
async setMetadata(metadata) {
|
|
115
|
+
return await this.#engine.updateRunMetadata(this.runId, metadata);
|
|
116
|
+
}
|
|
117
|
+
/** @inheritdoc */
|
|
118
|
+
async setAttributes(attributes) {
|
|
119
|
+
return await this.#engine.setRunAttributes(this.runId, attributes);
|
|
120
|
+
}
|
|
121
|
+
/** @inheritdoc */
|
|
122
|
+
async cancel() {
|
|
123
|
+
return await this.#engine.cancelRun(this.runId);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function runToResult(run, runId, fallbackAvailableAt) {
|
|
127
|
+
if (run === void 0) WorkflowRunNotFoundError.notFound(runId);
|
|
128
|
+
if (run.status === "completed") return {
|
|
129
|
+
kind: "completed",
|
|
130
|
+
run,
|
|
131
|
+
output: run.output
|
|
132
|
+
};
|
|
133
|
+
if (run.status === "failed") return {
|
|
134
|
+
kind: "failed",
|
|
135
|
+
run,
|
|
136
|
+
error: run.error ?? {
|
|
137
|
+
name: "WorkflowError",
|
|
138
|
+
message: `Workflow run failed: ${run.id}`
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
if (run.status === "canceled") return {
|
|
142
|
+
kind: "failed",
|
|
143
|
+
run,
|
|
144
|
+
error: run.error ?? {
|
|
145
|
+
name: "WorkflowRunCanceledError",
|
|
146
|
+
message: `Workflow run was canceled: ${run.id}`
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
kind: "waiting",
|
|
151
|
+
run,
|
|
152
|
+
availableAt: run.availableAt ?? fallbackAvailableAt
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { WorkflowRunHandle, createWorkflowRunHandle };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WorkflowMissingImplementationRetryConfig } from "../types/retry.mjs";
|
|
2
|
+
import { RegistryLike } from "../types/definition.mjs";
|
|
3
|
+
import { WorkflowWorkerEngine } from "../types/engine.mjs";
|
|
4
|
+
import { CreateWorkflowWorkerOptions } from "../types/worker.mjs";
|
|
5
|
+
import { WorkflowClientWorkerOptions } from "../types/client.mjs";
|
|
6
|
+
//#region src/client/worker-options.d.ts
|
|
7
|
+
interface WorkflowWorkerFacetOptions {
|
|
8
|
+
readonly workerId?: string;
|
|
9
|
+
readonly leaseDuration?: Temporal.Duration;
|
|
10
|
+
readonly heartbeatInterval?: Temporal.Duration;
|
|
11
|
+
readonly stopDrainTimeout?: Temporal.Duration;
|
|
12
|
+
readonly missingImplementationRetry?: WorkflowMissingImplementationRetryConfig;
|
|
13
|
+
}
|
|
14
|
+
declare function workerOptionsFromClientOptions(engine: WorkflowWorkerEngine, registry: RegistryLike, now: () => Temporal.Instant, options: WorkflowClientWorkerOptions | undefined): CreateWorkflowWorkerOptions;
|
|
15
|
+
declare function workerOptionsFromWakeOptions(options: WorkflowWorkerFacetOptions | undefined): WorkflowClientWorkerOptions;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { workerOptionsFromClientOptions, workerOptionsFromWakeOptions };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/client/worker-options.ts
|
|
2
|
+
function workerOptionsFromClientOptions(engine, registry, now, options) {
|
|
3
|
+
return {
|
|
4
|
+
engine,
|
|
5
|
+
registry,
|
|
6
|
+
now,
|
|
7
|
+
...options?.workerId === void 0 ? {} : { workerId: options.workerId },
|
|
8
|
+
...options?.leaseDuration === void 0 ? {} : { leaseDuration: options.leaseDuration },
|
|
9
|
+
...options?.pollInterval === void 0 ? {} : { pollInterval: options.pollInterval },
|
|
10
|
+
...options?.heartbeatInterval === void 0 ? {} : { heartbeatInterval: options.heartbeatInterval },
|
|
11
|
+
...options?.stopDrainTimeout === void 0 ? {} : { stopDrainTimeout: options.stopDrainTimeout },
|
|
12
|
+
...options?.missingImplementationRetry === void 0 ? {} : { missingImplementationRetry: options.missingImplementationRetry }
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function workerOptionsFromWakeOptions(options) {
|
|
16
|
+
return {
|
|
17
|
+
...options?.workerId === void 0 ? {} : { workerId: options.workerId },
|
|
18
|
+
...options?.leaseDuration === void 0 ? {} : { leaseDuration: options.leaseDuration },
|
|
19
|
+
...options?.heartbeatInterval === void 0 ? {} : { heartbeatInterval: options.heartbeatInterval },
|
|
20
|
+
...options?.stopDrainTimeout === void 0 ? {} : { stopDrainTimeout: options.stopDrainTimeout },
|
|
21
|
+
...options?.missingImplementationRetry === void 0 ? {} : { missingImplementationRetry: options.missingImplementationRetry }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { workerOptionsFromClientOptions, workerOptionsFromWakeOptions };
|