@workflow/core 5.0.0-beta.5 → 5.0.0-beta.50
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/dist/attribute-changes.d.ts +5 -0
- package/dist/attribute-changes.d.ts.map +1 -0
- package/dist/attribute-changes.js +25 -0
- package/dist/capabilities.d.ts +35 -2
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +74 -5
- package/dist/capture-stack.d.ts +1 -1
- package/dist/capture-stack.js +2 -2
- package/dist/class-serialization.d.ts +32 -0
- package/dist/class-serialization.d.ts.map +1 -1
- package/dist/class-serialization.js +37 -1
- package/dist/classify-error.d.ts +19 -3
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +98 -6
- package/dist/context-violation-error.d.ts +5 -5
- package/dist/context-violation-error.d.ts.map +1 -1
- package/dist/context-violation-error.js +8 -6
- package/dist/create-hook.d.ts +72 -7
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +1 -1
- package/dist/define-hook.js +2 -2
- package/dist/describe-error.d.ts +7 -7
- package/dist/describe-error.d.ts.map +1 -1
- package/dist/describe-error.js +97 -12
- package/dist/encryption.d.ts +38 -4
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +96 -14
- package/dist/events-consumer.d.ts +271 -0
- package/dist/events-consumer.d.ts.map +1 -1
- package/dist/events-consumer.js +646 -42
- package/dist/flushable-stream.d.ts +56 -1
- package/dist/flushable-stream.d.ts.map +1 -1
- package/dist/flushable-stream.js +123 -11
- package/dist/global.d.ts +36 -2
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +21 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/log-format.d.ts +2 -2
- package/dist/log-format.js +7 -7
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +10 -6
- package/dist/private.d.ts +226 -9
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +626 -7
- package/dist/replay-payload-cache.d.ts +64 -0
- package/dist/replay-payload-cache.d.ts.map +1 -0
- package/dist/replay-payload-cache.js +158 -0
- package/dist/runtime/compute-instance.d.ts +13 -0
- package/dist/runtime/compute-instance.d.ts.map +1 -0
- package/dist/runtime/compute-instance.js +14 -0
- package/dist/runtime/constants.d.ts +315 -0
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +502 -16
- package/dist/runtime/count-step-started-events.d.ts +52 -0
- package/dist/runtime/count-step-started-events.d.ts.map +1 -0
- package/dist/runtime/count-step-started-events.js +72 -0
- package/dist/runtime/deployment-guard.d.ts +99 -0
- package/dist/runtime/deployment-guard.d.ts.map +1 -0
- package/dist/runtime/deployment-guard.js +154 -0
- package/dist/runtime/get-port-lazy.d.ts +15 -0
- package/dist/runtime/get-port-lazy.d.ts.map +1 -1
- package/dist/runtime/get-port-lazy.js +75 -6
- package/dist/runtime/get-world-lazy.d.ts +5 -14
- package/dist/runtime/get-world-lazy.d.ts.map +1 -1
- package/dist/runtime/get-world-lazy.js +19 -29
- package/dist/runtime/helpers.d.ts +341 -29
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +559 -57
- package/dist/runtime/quickjs-assets.generated.d.ts +14 -0
- package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
- package/dist/runtime/quickjs-assets.generated.js +30 -0
- package/dist/runtime/quickjs-entrypoint.d.ts +136 -0
- package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/quickjs-entrypoint.js +1686 -0
- package/dist/runtime/quickjs-runtime.d.ts +244 -0
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
- package/dist/runtime/quickjs-runtime.js +2427 -0
- package/dist/runtime/quickjs-serde.d.ts +107 -0
- package/dist/runtime/quickjs-serde.d.ts.map +1 -0
- package/dist/runtime/quickjs-serde.js +2159 -0
- package/dist/runtime/replay-budget.d.ts +97 -0
- package/dist/runtime/replay-budget.d.ts.map +1 -0
- package/dist/runtime/replay-budget.js +139 -0
- package/dist/runtime/replay-recovery-reporter.d.ts +36 -0
- package/dist/runtime/replay-recovery-reporter.d.ts.map +1 -0
- package/dist/runtime/replay-recovery-reporter.js +64 -0
- package/dist/runtime/resume-hook.d.ts +91 -8
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +512 -89
- package/dist/runtime/resume-latency.d.ts +150 -0
- package/dist/runtime/resume-latency.d.ts.map +1 -0
- package/dist/runtime/resume-latency.js +155 -0
- package/dist/runtime/run-id-time.d.ts +19 -0
- package/dist/runtime/run-id-time.d.ts.map +1 -0
- package/dist/runtime/run-id-time.js +42 -0
- package/dist/runtime/run.d.ts +72 -7
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +280 -53
- package/dist/runtime/runs.d.ts +54 -3
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +126 -16
- package/dist/runtime/start.d.ts +101 -2
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +352 -61
- package/dist/runtime/step-executor.d.ts +205 -5
- package/dist/runtime/step-executor.d.ts.map +1 -1
- package/dist/runtime/step-executor.js +760 -127
- package/dist/runtime/step-latency.d.ts +220 -0
- package/dist/runtime/step-latency.d.ts.map +1 -0
- package/dist/runtime/step-latency.js +215 -0
- package/dist/runtime/step-ownership.d.ts +72 -0
- package/dist/runtime/step-ownership.d.ts.map +1 -0
- package/dist/runtime/step-ownership.js +114 -0
- package/dist/runtime/step-single-flight.d.ts +12 -0
- package/dist/runtime/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/step-single-flight.js +75 -0
- package/dist/runtime/suspension-handler.d.ts +269 -7
- package/dist/runtime/suspension-handler.d.ts.map +1 -1
- package/dist/runtime/suspension-handler.js +1253 -125
- package/dist/runtime/unserializable-step.d.ts +34 -0
- package/dist/runtime/unserializable-step.d.ts.map +1 -0
- package/dist/runtime/unserializable-step.js +52 -0
- package/dist/runtime/vm-mode.d.ts +44 -0
- package/dist/runtime/vm-mode.d.ts.map +1 -0
- package/dist/runtime/vm-mode.js +62 -0
- package/dist/runtime/vm-serde-bundle.generated.d.ts +14 -0
- package/dist/runtime/vm-serde-bundle.generated.d.ts.map +1 -0
- package/dist/runtime/vm-serde-bundle.generated.js +16 -0
- package/dist/runtime/wait-continuation.d.ts +106 -0
- package/dist/runtime/wait-continuation.d.ts.map +1 -0
- package/dist/runtime/wait-continuation.js +136 -0
- package/dist/runtime/wait-until.d.ts +18 -0
- package/dist/runtime/wait-until.d.ts.map +1 -0
- package/dist/runtime/wait-until.js +42 -0
- package/dist/runtime/world-compatibility.d.ts +32 -0
- package/dist/runtime/world-compatibility.d.ts.map +1 -0
- package/dist/runtime/world-compatibility.js +44 -0
- package/dist/runtime/world-init.d.ts +17 -42
- package/dist/runtime/world-init.d.ts.map +1 -1
- package/dist/runtime/world-init.js +18 -43
- package/dist/runtime/world.d.ts +14 -2
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +75 -19
- package/dist/runtime.d.ts +10 -6
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3741 -490
- package/dist/sealed-box.d.ts +167 -0
- package/dist/sealed-box.d.ts.map +1 -0
- package/dist/sealed-box.js +571 -0
- package/dist/serialization/client.d.ts +3 -3
- package/dist/serialization/client.d.ts.map +1 -1
- package/dist/serialization/client.js +8 -4
- package/dist/serialization/codec-devalue-vm.d.ts +16 -0
- package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
- package/dist/serialization/codec-devalue-vm.js +148 -0
- package/dist/serialization/codec-devalue.d.ts +1 -1
- package/dist/serialization/codec-devalue.d.ts.map +1 -1
- package/dist/serialization/codec-devalue.js +24 -6
- package/dist/serialization/codec.d.ts +37 -2
- package/dist/serialization/codec.d.ts.map +1 -1
- package/dist/serialization/codec.js +2 -2
- package/dist/serialization/compression.d.ts +105 -0
- package/dist/serialization/compression.d.ts.map +1 -0
- package/dist/serialization/compression.js +261 -0
- package/dist/serialization/encryption.d.ts +119 -17
- package/dist/serialization/encryption.d.ts.map +1 -1
- package/dist/serialization/encryption.js +152 -17
- package/dist/serialization/errors.d.ts +13 -0
- package/dist/serialization/errors.d.ts.map +1 -1
- package/dist/serialization/errors.js +20 -2
- package/dist/serialization/format.d.ts +6 -6
- package/dist/serialization/format.js +7 -7
- package/dist/serialization/hardened.d.ts +156 -0
- package/dist/serialization/hardened.d.ts.map +1 -0
- package/dist/serialization/hardened.js +538 -0
- package/dist/serialization/index.d.ts +10 -8
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/index.js +10 -8
- package/dist/serialization/reducers/class-vm.d.ts +20 -0
- package/dist/serialization/reducers/class-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/class-vm.js +77 -0
- package/dist/serialization/reducers/class.d.ts.map +1 -1
- package/dist/serialization/reducers/class.js +11 -6
- package/dist/serialization/reducers/common-vm.d.ts +15 -0
- package/dist/serialization/reducers/common-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/common-vm.js +616 -0
- package/dist/serialization/reducers/common.d.ts +1 -1
- package/dist/serialization/reducers/common.d.ts.map +1 -1
- package/dist/serialization/reducers/common.js +202 -62
- package/dist/serialization/reducers/step-function-vm.d.ts +44 -0
- package/dist/serialization/reducers/step-function-vm.d.ts.map +1 -0
- package/dist/serialization/reducers/step-function-vm.js +97 -0
- package/dist/serialization/reducers/step-function.d.ts.map +1 -1
- package/dist/serialization/reducers/step-function.js +25 -9
- package/dist/serialization/step.d.ts +4 -4
- package/dist/serialization/step.d.ts.map +1 -1
- package/dist/serialization/step.js +9 -5
- package/dist/serialization/types.d.ts +80 -1
- package/dist/serialization/types.d.ts.map +1 -1
- package/dist/serialization/types.js +15 -1
- package/dist/serialization/workflow-vm.d.ts +29 -0
- package/dist/serialization/workflow-vm.d.ts.map +1 -0
- package/dist/serialization/workflow-vm.js +74 -0
- package/dist/serialization-format.d.ts +64 -8
- package/dist/serialization-format.d.ts.map +1 -1
- package/dist/serialization-format.js +225 -73
- package/dist/serialization.d.ts +262 -34
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +1879 -274
- package/dist/set-attributes.d.ts +13 -0
- package/dist/set-attributes.d.ts.map +1 -0
- package/dist/set-attributes.js +60 -0
- package/dist/source-map.d.ts +25 -0
- package/dist/source-map.d.ts.map +1 -1
- package/dist/source-map.js +154 -10
- package/dist/step/context-storage.d.ts +61 -2
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +7 -5
- package/dist/step/writable-stream.d.ts +3 -3
- package/dist/step/writable-stream.d.ts.map +1 -1
- package/dist/step/writable-stream.js +72 -9
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +148 -27
- package/dist/symbols.d.ts +50 -0
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +51 -1
- package/dist/telemetry/semantic-conventions.d.ts +397 -2
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +297 -3
- package/dist/telemetry.d.ts +91 -0
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +244 -17
- package/dist/test-support/orchestrator-context.d.ts +25 -0
- package/dist/test-support/orchestrator-context.d.ts.map +1 -0
- package/dist/test-support/orchestrator-context.js +101 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +23 -1
- package/dist/util.d.ts +0 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/vm/index.d.ts.map +1 -1
- package/dist/vm/index.js +84 -14
- package/dist/vm/script-cache.d.ts +26 -0
- package/dist/vm/script-cache.d.ts.map +1 -0
- package/dist/vm/script-cache.js +131 -0
- package/dist/vm/uint8array-base64.js +1 -1
- package/dist/workflow/abort-controller.d.ts +2 -2
- package/dist/workflow/abort-controller.d.ts.map +1 -1
- package/dist/workflow/abort-controller.js +88 -21
- package/dist/workflow/attribute-dispatcher.d.ts +6 -0
- package/dist/workflow/attribute-dispatcher.d.ts.map +1 -0
- package/dist/workflow/attribute-dispatcher.js +45 -0
- package/dist/workflow/create-hook.d.ts.map +1 -1
- package/dist/workflow/create-hook.js +24 -3
- package/dist/workflow/get-workflow-metadata.js +2 -2
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +304 -47
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +2 -1
- package/dist/workflow/set-attributes.d.ts +68 -0
- package/dist/workflow/set-attributes.d.ts.map +1 -0
- package/dist/workflow/set-attributes.js +60 -0
- package/dist/workflow/sleep.d.ts.map +1 -1
- package/dist/workflow/sleep.js +58 -12
- package/dist/workflow/world-init-stub.d.ts +3 -3
- package/dist/workflow/world-init-stub.js +4 -4
- package/dist/workflow.d.ts +95 -3
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +895 -561
- package/docs/api-reference/create-hook.mdx +89 -10
- package/docs/api-reference/create-webhook.mdx +16 -15
- package/docs/api-reference/define-hook.mdx +35 -33
- package/docs/api-reference/fatal-error.mdx +30 -8
- package/docs/api-reference/fetch.mdx +14 -10
- package/docs/api-reference/get-step-metadata.mdx +2 -2
- package/docs/api-reference/get-workflow-metadata.mdx +3 -3
- package/docs/api-reference/get-writable.mdx +7 -7
- package/docs/api-reference/index.mdx +4 -1
- package/docs/api-reference/retryable-error.mdx +1 -1
- package/docs/api-reference/set-attributes.mdx +61 -0
- package/docs/api-reference/sleep.mdx +4 -4
- package/docs/foundations/cancellation.mdx +31 -32
- package/docs/foundations/errors-and-retries.mdx +42 -11
- package/docs/foundations/hooks.mdx +64 -35
- package/docs/foundations/idempotency.mdx +244 -12
- package/docs/foundations/index.mdx +1 -23
- package/docs/foundations/meta.json +2 -1
- package/docs/foundations/serialization.mdx +21 -22
- package/docs/foundations/starting-workflows.mdx +106 -30
- package/docs/foundations/streaming.mdx +107 -59
- package/docs/foundations/versioning.mdx +263 -0
- package/docs/foundations/workflows-and-steps.mdx +9 -9
- package/docs/how-it-works/cancellation.mdx +63 -63
- package/docs/how-it-works/code-transform.mdx +83 -67
- package/docs/how-it-works/encryption.mdx +30 -26
- package/docs/how-it-works/event-sourcing.mdx +98 -34
- package/docs/how-it-works/framework-integrations.mdx +96 -337
- package/docs/how-it-works/understanding-directives.mdx +22 -22
- package/package.json +24 -15
- package/dist/runtime/step-handler.d.ts +0 -2
- package/dist/runtime/step-handler.d.ts.map +0 -1
- package/dist/runtime/step-handler.js +0 -776
|
@@ -21,7 +21,7 @@ This page explores how directives enable this execution model and the design pri
|
|
|
21
21
|
|
|
22
22
|
To understand how directives work, let's first understand what workflows and steps are in the Workflow SDK.
|
|
23
23
|
|
|
24
|
-
## Workflows and
|
|
24
|
+
## Workflows and steps primer
|
|
25
25
|
|
|
26
26
|
The Workflow SDK has two types of functions:
|
|
27
27
|
|
|
@@ -58,7 +58,7 @@ export async function onboardUser(userId: string) {
|
|
|
58
58
|
**The key insight:** Workflows resume from suspension by replaying their code using cached step results from the [event log](/docs/how-it-works/event-sourcing). When a step like `await fetchUserData(userId)` is called:
|
|
59
59
|
|
|
60
60
|
- **If already executed:** Returns the cached result immediately from the event log
|
|
61
|
-
- **If not yet executed:** Suspends the workflow,
|
|
61
|
+
- **If not yet executed:** Suspends the workflow, executes the step (usually inline in the same invocation, or through the queue when the invocation runs out of inline budget or nears its timeout), then resumes with the result
|
|
62
62
|
|
|
63
63
|
This replay mechanism requires deterministic code. If `Math.random()` weren't seeded, the first execution might return `0.7` (sending the email) but replay might return `0.3` (skipping it), thus breaking resumption. The Workflow SDK sandbox provides seeded `Math.random()` and `Date` to ensure consistent behavior across replays.
|
|
64
64
|
|
|
@@ -66,9 +66,9 @@ This replay mechanism requires deterministic code. If `Math.random()` weren't se
|
|
|
66
66
|
For a deeper dive into workflows and steps, see [Workflows and Steps](/docs/foundations/workflows-and-steps).
|
|
67
67
|
</Callout>
|
|
68
68
|
|
|
69
|
-
## The
|
|
69
|
+
## The core challenge
|
|
70
70
|
|
|
71
|
-
This execution model
|
|
71
|
+
This execution model provides durability: workflows can suspend for days, survive restarts, and resume from any point. However, it also requires a semantic boundary in the code that tells **the compiler, runtime, and developer** that execution semantics have changed.
|
|
72
72
|
|
|
73
73
|
The challenge: how do we mark this boundary in a way that:
|
|
74
74
|
|
|
@@ -77,7 +77,7 @@ The challenge: how do we mark this boundary in a way that:
|
|
|
77
77
|
3. Allows static analysis of workflow structure
|
|
78
78
|
4. Feels natural to JavaScript developers
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
Directives have prior uses, and we considered several alternatives:
|
|
81
81
|
|
|
82
82
|
## Prior art on directives
|
|
83
83
|
|
|
@@ -104,11 +104,11 @@ The `"use workflow"` directive is also used by the Language Server Plugin shippe
|
|
|
104
104
|
|
|
105
105
|
But we didn't get here immediately. This took some discovery to arrive at:
|
|
106
106
|
|
|
107
|
-
## Alternatives
|
|
107
|
+
## Alternatives we explored
|
|
108
108
|
|
|
109
|
-
Before settling on directives, we prototyped several other approaches. Each had
|
|
109
|
+
Before settling on directives, we prototyped several other approaches. Each had limitations that made them unsuitable for production use.
|
|
110
110
|
|
|
111
|
-
### Runtime-
|
|
111
|
+
### Runtime-only "Suspense" API
|
|
112
112
|
|
|
113
113
|
Our first proof of concept used a wrapper-based API without a build step:
|
|
114
114
|
|
|
@@ -140,7 +140,7 @@ export const myWorkflow = workflow(async () => {
|
|
|
140
140
|
});
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
This was verbose and
|
|
143
|
+
This was verbose and developers could forget it. If a developer forgot to wrap something like `Date.now()`, it led to unstable runtime behavior.
|
|
144
144
|
|
|
145
145
|
For example:
|
|
146
146
|
|
|
@@ -200,7 +200,7 @@ export const myWorkflow = workflow(async () => {
|
|
|
200
200
|
});
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
### Generator-
|
|
203
|
+
### Generator-based API
|
|
204
204
|
|
|
205
205
|
We explored using generators for explicit suspension points, inspired by libraries like Effect.ts:
|
|
206
206
|
|
|
@@ -220,7 +220,7 @@ We're big fans of [Effect.ts](https://effect.website/) and the power of generato
|
|
|
220
220
|
|
|
221
221
|
**1. Syntax felt more like a DSL than JavaScript**
|
|
222
222
|
|
|
223
|
-
Generators require a custom mental model that differs
|
|
223
|
+
Generators require a custom mental model that differs from familiar async/await patterns. The `yield*` syntax and generator delegation were unfamiliar to many developers:
|
|
224
224
|
|
|
225
225
|
{/* @skip-typecheck: incomplete code sample */}
|
|
226
226
|
```typescript lineNumbers
|
|
@@ -267,7 +267,7 @@ export const myWorkflow = workflow(function*() {
|
|
|
267
267
|
|
|
268
268
|
The generator syntax addressed suspension but didn't solve the fundamental sandboxing problem.
|
|
269
269
|
|
|
270
|
-
### File
|
|
270
|
+
### File system-based conventions
|
|
271
271
|
|
|
272
272
|
We explored using file system conventions to identify workflows and steps, similar to how modern frameworks handle routing (Next.js, Hono, Nitro, SvelteKit):
|
|
273
273
|
|
|
@@ -282,7 +282,7 @@ We explored using file system conventions to identify workflows and steps, simil
|
|
|
282
282
|
</Folder>
|
|
283
283
|
</Files>
|
|
284
284
|
|
|
285
|
-
With this approach, any function in the `workflows/` directory would be transformed as a workflow, and any function in `steps/` would be a step.
|
|
285
|
+
With this approach, any function in the `workflows/` directory would be transformed as a workflow, and any function in `steps/` would be a step. File locations would replace directives.
|
|
286
286
|
|
|
287
287
|
**Why this could work:**
|
|
288
288
|
|
|
@@ -308,9 +308,9 @@ The directive approach solved all these issues: it works in any project structur
|
|
|
308
308
|
|
|
309
309
|
### Decorators
|
|
310
310
|
|
|
311
|
-
We considered decorators, but they presented
|
|
311
|
+
We considered decorators, but they presented technical and ergonomic challenges.
|
|
312
312
|
|
|
313
|
-
**Decorators are
|
|
313
|
+
**Decorators are not-yet-standard and class-focused**
|
|
314
314
|
|
|
315
315
|
Decorators are not yet a standard syntax ([TC39 proposal](https://github.com/tc39/proposal-decorators)) and they currently only work with classes. A class decorator approach could look like this:
|
|
316
316
|
|
|
@@ -349,7 +349,7 @@ While decorators can be handled at compile-time with build tool support, they pr
|
|
|
349
349
|
See the [Macro Wrapper](#macro-wrapper-approach) section below for a deeper dive into why this approach breaks down with concrete examples.
|
|
350
350
|
</Callout>
|
|
351
351
|
|
|
352
|
-
### Macro
|
|
352
|
+
### Macro wrapper approach
|
|
353
353
|
|
|
354
354
|
We also explored compile-time macro approaches - using a compiler to transform wrapper functions or decorators into directive-based code:
|
|
355
355
|
|
|
@@ -385,7 +385,7 @@ export const processOrder = async (orderId: string) => {
|
|
|
385
385
|
};
|
|
386
386
|
```
|
|
387
387
|
|
|
388
|
-
The benefit is that macros could enforce types and provide "Go To Definition" or other LSP features
|
|
388
|
+
The benefit is that macros could enforce types and provide "Go To Definition" or other LSP features without additional configuration.
|
|
389
389
|
|
|
390
390
|
However, **the core problem remains: Workflows aren't runtime values**
|
|
391
391
|
|
|
@@ -431,7 +431,7 @@ To detect that `processOrder` is actually a workflow, the compiler would need wh
|
|
|
431
431
|
|
|
432
432
|
This level of cross-function analysis is impractical for build tools - it would require analyzing every function call chain in your entire codebase and all dependencies. The compiler can only reliably detect direct `useWorkflow` calls, not calls hidden behind abstractions.
|
|
433
433
|
|
|
434
|
-
## How
|
|
434
|
+
## How directives solve these problems
|
|
435
435
|
|
|
436
436
|
Directives address all the issues we encountered with previous approaches:
|
|
437
437
|
|
|
@@ -527,7 +527,7 @@ export async function processOrder(orderId: string) {
|
|
|
527
527
|
|
|
528
528
|
The `"use step"` directive maintains consistency. While steps run in the full Node.js runtime and *could* work without a directive, they need some way to signal to the workflow runtime that they're steps.
|
|
529
529
|
|
|
530
|
-
We could have used a function wrapper
|
|
530
|
+
We could have used a function wrapper for steps:
|
|
531
531
|
|
|
532
532
|
{/* @skip-typecheck: incomplete code sample */}
|
|
533
533
|
```typescript lineNumbers
|
|
@@ -584,7 +584,7 @@ By requiring explicit `"use step"` directives, developers have fine-grained cont
|
|
|
584
584
|
To understand how directives are transformed at compile time, see [How the Code Transform Works](/docs/how-it-works/code-transform).
|
|
585
585
|
</Callout>
|
|
586
586
|
|
|
587
|
-
## What
|
|
587
|
+
## What directives enable
|
|
588
588
|
|
|
589
589
|
Because `"use workflow"` defines a compile-time semantic boundary, we can provide:
|
|
590
590
|
|
|
@@ -603,7 +603,7 @@ Because `"use workflow"` defines a compile-time semantic boundary, we can provid
|
|
|
603
603
|
</Card>
|
|
604
604
|
</Cards>
|
|
605
605
|
|
|
606
|
-
## Directives as a JavaScript
|
|
606
|
+
## Directives as a JavaScript pattern
|
|
607
607
|
|
|
608
608
|
Directives in JavaScript have always been contracts between the developer and the execution environment. `"use strict"` made this pattern familiar - it's a string literal that changes how code is interpreted.
|
|
609
609
|
|
|
@@ -611,7 +611,7 @@ While JavaScript doesn't yet have first-class support for custom directives (lik
|
|
|
611
611
|
|
|
612
612
|
As TC39 members, we at Vercel are actively working with the standards body and broader ecosystem to explore formal specifications for pragma-like syntax or macro annotations that can express execution semantics.
|
|
613
613
|
|
|
614
|
-
## Closing
|
|
614
|
+
## Closing thoughts
|
|
615
615
|
|
|
616
616
|
Directives aren't about syntax preference, they're about expressing semantic boundaries. `"use workflow"` tells the compiler, developer, and runtime that this code is deterministic, resumable, and sandboxed.
|
|
617
617
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.50",
|
|
4
4
|
"description": "Core runtime and engine for Workflow SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"types": "./dist/runtime/helpers.d.ts",
|
|
45
45
|
"default": "./dist/runtime/helpers.js"
|
|
46
46
|
},
|
|
47
|
+
"./logger": {
|
|
48
|
+
"types": "./dist/logger.d.ts",
|
|
49
|
+
"default": "./dist/logger.js"
|
|
50
|
+
},
|
|
47
51
|
"./runtime/resume-hook": {
|
|
48
52
|
"types": "./dist/runtime/resume-hook.d.ts",
|
|
49
53
|
"default": "./dist/runtime/resume-hook.js"
|
|
@@ -76,35 +80,40 @@
|
|
|
76
80
|
"./_workflow": "./dist/workflow/index.js"
|
|
77
81
|
},
|
|
78
82
|
"dependencies": {
|
|
79
|
-
"@aws-sdk/credential-provider-web-identity": "3.972.
|
|
83
|
+
"@aws-sdk/credential-provider-web-identity": "3.972.49",
|
|
80
84
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
81
85
|
"@standard-schema/spec": "1.0.0",
|
|
82
86
|
"@types/ms": "2.1.0",
|
|
83
|
-
"@vercel/functions": "^3.
|
|
87
|
+
"@vercel/functions": "^3.8.0",
|
|
88
|
+
"@workflow/errors": "5.0.0-beta.21",
|
|
89
|
+
"@workflow/serde": "5.0.0-beta.2",
|
|
90
|
+
"@workflow/utils": "5.0.0-beta.10",
|
|
91
|
+
"@workflow/world": "5.0.0-beta.34",
|
|
92
|
+
"@workflow/world-local": "5.0.0-beta.43",
|
|
93
|
+
"@workflow/world-vercel": "5.0.0-beta.45",
|
|
84
94
|
"debug": "4.4.3",
|
|
85
|
-
"devalue": "5.
|
|
95
|
+
"devalue": "5.9.0",
|
|
86
96
|
"ms": "2.1.3",
|
|
87
97
|
"nanoid": "5.1.6",
|
|
98
|
+
"quickjs-wasi": "3.4.0",
|
|
88
99
|
"seedrandom": "3.0.5",
|
|
89
100
|
"semver": "7.7.4",
|
|
90
101
|
"ulid": "~3.0.1",
|
|
91
|
-
"zod": "4.3.6"
|
|
92
|
-
"@workflow/errors": "5.0.0-beta.2",
|
|
93
|
-
"@workflow/serde": "5.0.0-beta.1",
|
|
94
|
-
"@workflow/utils": "5.0.0-beta.2",
|
|
95
|
-
"@workflow/world": "5.0.0-beta.2",
|
|
96
|
-
"@workflow/world-local": "5.0.0-beta.4",
|
|
97
|
-
"@workflow/world-vercel": "5.0.0-beta.4"
|
|
102
|
+
"zod": "~4.3.6"
|
|
98
103
|
},
|
|
99
104
|
"devDependencies": {
|
|
100
105
|
"@opentelemetry/api": "1.9.0",
|
|
106
|
+
"@opentelemetry/context-async-hooks": "1.30.1",
|
|
107
|
+
"@opentelemetry/core": "1.30.1",
|
|
108
|
+
"@opentelemetry/sdk-trace-base": "1.30.1",
|
|
101
109
|
"@types/debug": "4.1.12",
|
|
102
|
-
"@types/semver": "7.7.1",
|
|
103
110
|
"@types/node": "22.19.0",
|
|
104
111
|
"@types/seedrandom": "3.0.8",
|
|
112
|
+
"@types/semver": "7.7.1",
|
|
113
|
+
"@workflow/tsconfig": "5.0.0-beta.0",
|
|
105
114
|
"cross-env": "10.1.0",
|
|
106
115
|
"genversion": "3.2.0",
|
|
107
|
-
"
|
|
116
|
+
"typescript": "^6.0.3"
|
|
108
117
|
},
|
|
109
118
|
"peerDependencies": {
|
|
110
119
|
"@opentelemetry/api": "1"
|
|
@@ -115,10 +124,10 @@
|
|
|
115
124
|
}
|
|
116
125
|
},
|
|
117
126
|
"scripts": {
|
|
118
|
-
"build": "genversion --es6 src/version.ts && tsc",
|
|
127
|
+
"build": "genversion --es6 src/version.ts && node scripts/build-quickjs-assets.js && tsc",
|
|
119
128
|
"dev": "genversion --es6 src/version.ts && tsc --watch",
|
|
120
129
|
"clean": "tsc --build --clean && rm -rf dist src/version.ts docs ||:",
|
|
121
|
-
"test": "cross-env WORKFLOW_TARGET_WORLD=local vitest run src",
|
|
130
|
+
"test": "cross-env WORKFLOW_TARGET_WORLD=local vitest run src e2e/utils.test.ts",
|
|
122
131
|
"test:e2e": "vitest run e2e",
|
|
123
132
|
"typecheck": "genversion --es6 src/version.ts && tsc --noEmit"
|
|
124
133
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step-handler.d.ts","sourceRoot":"","sources":["../../src/runtime/step-handler.ts"],"names":[],"mappings":"AAygCA,eAAO,MAAM,cAAc,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAM3D,CAAC"}
|