You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/swc-plugin-workflow/spec.md
+23-9Lines changed: 23 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ The swc plugin has 3 modes - 'step' mode, 'workflow' mode, and 'client' mode
6
6
7
7
## Step Mode
8
8
9
-
When executed in 'step' mode, step definitions is kept as is and are simply registered using `registerStepFunction` from `@workflow/core/private`. The directives are removed. For example:
9
+
When executed in 'step' mode, step definitions is kept as is and are simply registered using `registerStepFunction` from `workflow/internal/private`. The directives are removed. For example:
10
10
11
11
Input code:
12
12
@@ -20,14 +20,18 @@ export async function add(a, b) {
20
20
Output code
21
21
22
22
```
23
-
import { registerStepFunction } from "@workflow/core/private"
23
+
import { registerStepFunction } from "workflow/internal/private"
24
24
25
25
export async function add(a, b) {
26
26
return a + b
27
27
}
28
-
registerStepFunction(add)
28
+
registerStepFunction("step//input.js//add", add)
29
29
```
30
30
31
+
**ID Generation:** Step IDs are generated using the format `step//{filepath}//{functionName}`, where:
32
+
-`filepath` is the relative path to the file from the project root
33
+
-`functionName` is the name of the step function
34
+
31
35
Workflow definitions are left untouched in step mode, including leaving the directives intact.
32
36
33
37
Upstream, a bundler will use this plugin in step mode to create a server bundle of multiple steps and serve it via an API endpoint at `.well-known/workflow/v1/step`
**ID Generation:** Workflow IDs are generated using the format `workflow//{filepath}//{functionName}` and attached as a property to the function.
83
+
75
84
Upstream, a bundler will use this plugin in workflow mode to create a server bundle of all the workflows and serve it via an API endpoint at `.well-known/workflow/v1/flow`. The workflow endpoint handler encapsulates logic to execute the correct workflow using the function name, which is why nothing needs to be done to the workflows themselves. They just need to be exported.
76
85
77
86
## Client Mode
78
87
79
-
When executed in 'client' mode, step and workflow definitions have their bodies replaced with a call to `runStep` and `start`respectively. Both these helper functions are exported from the `@workflow/core` package. They effectively proxy the requests to execute steps and workflows on the server (using the bundles created in the other two modes).
88
+
When executed in 'client' mode, step and workflow definitions have their bodies replaced with a call to `runStep` and throw statements respectively. `runStep` is exported from `workflow/api`. It effectively proxies the requests to execute steps on the server (using the bundles created in the other modes).
80
89
81
90
Input code
82
91
@@ -97,18 +106,23 @@ Output code
97
106
98
107
```
99
108
// workflow/main.js
100
-
import { start as __private_workflow_start, runStep as __private_run_step } from "@workflow/core/runtime"
109
+
import { runStep as __private_run_step } from "workflow/api"
Upstream, this mode is typically used by a framework loader (like a NextJS/webpack loader) to JIT transform workflow executions into proxied start calls.
121
+
**ID Generation:**
122
+
- Step functions use `runStep` with the function name (not the full ID)
123
+
- Workflow functions throw an error if called directly and have the `workflowId` property attached using the format `workflow//{filepath}//{functionName}`
124
+
125
+
Upstream, this mode is typically used by a framework loader (like a Next.js/webpack loader) to JIT transform workflow executions into proxied calls.
0 commit comments