Skip to content

Commit f89f9f3

Browse files
committed
.
1 parent 0757912 commit f89f9f3

File tree

10 files changed

+305
-95
lines changed

10 files changed

+305
-95
lines changed

packages/swc-plugin-workflow/transform/src/lib.rs

Lines changed: 280 additions & 20 deletions
Large diffs are not rendered by default.

packages/swc-plugin-workflow/transform/tests/errors/non-async-functions/output-step.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function validStep() {
2222
return 42;
2323
}
2424
export const validWorkflow = async ()=>{
25-
'use workflow';
26-
return 'test';
25+
throw new Error("You attempted to execute workflow validWorkflow function directly. To start a workflow, use start(validWorkflow) from workflow/api");
2726
};
27+
validWorkflow.workflowId = "workflow//input.js//validWorkflow";
2828
registerStepFunction("step//input.js//validStep", validStep);

packages/swc-plugin-workflow/transform/tests/fixture/mixed-functions/output-step.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ async function stepFunctionWithoutExport(a, b) {
77
return a - b;
88
}
99
export async function workflowFunction(a, b) {
10-
'use workflow';
11-
const result = await stepFunction(a, b);
12-
const result2 = await stepFunctionWithoutExport(a, b);
13-
return result + result2;
10+
throw new Error("You attempted to execute workflow workflowFunction function directly. To start a workflow, use start(workflowFunction) from workflow/api");
1411
}
12+
workflowFunction.workflowId = "workflow//input.js//workflowFunction";
1513
export async function normalFunction(a, b) {
1614
return a * b;
1715
}

packages/swc-plugin-workflow/transform/tests/fixture/module-level-workflow/output-step.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ const localArrow = async (input)=>{
77
return input.bar;
88
};
99
export async function workflow(input) {
10-
return input.foo;
10+
throw new Error("You attempted to execute workflow workflow function directly. To start a workflow, use start(workflow) from workflow/api");
1111
}
12+
workflow.workflowId = "workflow//input.js//workflow";
1213
export const arrowWorkflow = async (input)=>{
13-
return input.bar;
14+
throw new Error("You attempted to execute workflow arrowWorkflow function directly. To start a workflow, use start(arrowWorkflow) from workflow/api");
1415
};
16+
arrowWorkflow.workflowId = "workflow//input.js//arrowWorkflow";

packages/swc-plugin-workflow/transform/tests/fixture/nested-step-in-workflow/output-step.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,9 @@ var helpers$objectStep = async (x, y)=>{
1111
return x + y + 10;
1212
};
1313
export async function example(a, b) {
14-
"use workflow";
15-
const step = example$step;
16-
// Arrow function with const
17-
const arrowStep = example$arrowStep;
18-
// Arrow function with let
19-
let letArrowStep = example$letArrowStep;
20-
// Arrow function with var
21-
var varArrowStep = example$varArrowStep;
22-
// Object with step method
23-
const helpers = {
24-
objectStep: helpers$objectStep
25-
};
26-
const val = await step(a, b);
27-
const val2 = await arrowStep(a, b);
28-
const val3 = await letArrowStep(a, b);
29-
const val4 = await varArrowStep(a, b);
30-
const val5 = await helpers.objectStep(a, b);
31-
return val + val2 + val3 + val4 + val5;
14+
throw new Error("You attempted to execute workflow example function directly. To start a workflow, use start(example) from workflow/api");
3215
}
16+
example.workflowId = "workflow//input.js//example";
3317
registerStepFunction("step//input.js//example/step", example$step);
3418
registerStepFunction("step//input.js//example/arrowStep", example$arrowStep);
3519
registerStepFunction("step//input.js//example/letArrowStep", example$letArrowStep);

packages/swc-plugin-workflow/transform/tests/fixture/nested-step-with-closure/output-step.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,9 @@ const arrowWrapperReturnNamedFunctionVar = (a, b, c)=>{
8080
return fn;
8181
};
8282
export async function wflow() {
83-
'use workflow';
84-
let count = 42;
85-
const namedStepWithClosureVars = wflow$namedStepWithClosureVars;
86-
const agent = new DurableAgent({
87-
arrowFunctionWithClosureVars: _anonymousStep2,
88-
namedFunctionWithClosureVars: _anonymousStep3,
89-
methodWithClosureVars: _anonymousStep4
90-
});
91-
await stepWrapperReturnArrowFunctionVar(1, 2, 3)();
92-
await stepWrapperReturnNamedFunction(1, 2, 3)();
93-
await stepWrapperReturnArrowFunction(1, 2, 3)();
94-
await stepWrapperReturnNamedFunctionVar(1, 2, 3)();
95-
await arrowWrapperReturnArrowFunctionVar(1, 2, 3)();
96-
await arrowWrapperReturnNamedFunction(1, 2, 3)();
97-
await arrowWrapperReturnArrowFunction(1, 2, 3)();
98-
await arrowWrapperReturnNamedFunctionVar(1, 2, 3)();
83+
throw new Error("You attempted to execute workflow wflow function directly. To start a workflow, use start(wflow) from workflow/api");
9984
}
85+
wflow.workflowId = "workflow//input.js//wflow";
10086
registerStepFunction("step//input.js//stepWrapperReturnArrowFunctionVar/fn", stepWrapperReturnArrowFunctionVar$fn);
10187
registerStepFunction("step//input.js//stepWrapperReturnNamedFunction/f", stepWrapperReturnNamedFunction$f);
10288
registerStepFunction("step//input.js//stepWrapperReturnArrowFunction/_anonymousStep0", stepWrapperReturnArrowFunction$_anonymousStep0);

packages/swc-plugin-workflow/transform/tests/fixture/nested-steps-in-object-constructor/output-step.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,8 @@ import * as z from 'zod';
66
var test$_anonymousStep0 = async ()=>gateway('openai/gpt-5');
77
var test$_anonymousStep1 = async ({ location })=>`Weather in ${location}: Sunny, 72°F`;
88
export async function test() {
9-
'use workflow';
10-
const agent = new DurableAgent({
11-
model: _anonymousStep0,
12-
tools: {
13-
getWeather: tool({
14-
description: 'Get weather for a location',
15-
inputSchema: z.object({
16-
location: z.string()
17-
}),
18-
execute: _anonymousStep1
19-
})
20-
}
21-
});
22-
await agent.stream({
23-
messages: [
24-
{
25-
role: 'user',
26-
content: 'What is the weather in San Francisco?'
27-
}
28-
]
29-
});
9+
throw new Error("You attempted to execute workflow test function directly. To start a workflow, use start(test) from workflow/api");
3010
}
11+
test.workflowId = "workflow//input.js//test";
3112
registerStepFunction("step//input.js//test/_anonymousStep0", test$_anonymousStep0);
3213
registerStepFunction("step//input.js//test/_anonymousStep1", test$_anonymousStep1);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**__internal_workflows{"workflows":{"input.js":{"workflow":{"workflowId":"workflow//input.js//workflow"}}}}*/;
22
export async function workflow(a, b) {
3-
'use workflow';
4-
return add(a, b);
3+
throw new Error("You attempted to execute workflow workflow function directly. To start a workflow, use start(workflow) from workflow/api");
54
}
5+
workflow.workflowId = "workflow//input.js//workflow";
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**__internal_workflows{"workflows":{"input.js":{"processData":{"workflowId":"workflow//input.js//processData"}}}}*/;
22
export const processData = async (data)=>{
3-
'use workflow';
4-
return data.processed;
3+
throw new Error("You attempted to execute workflow processData function directly. To start a workflow, use start(processData) from workflow/api");
54
};
5+
processData.workflowId = "workflow//input.js//processData";

packages/swc-plugin-workflow/transform/tests/fixture/workflow-client-property/output-step.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
// Test workflow functions in client mode
22
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"default":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
33
export async function myWorkflow() {
4-
'use workflow';
5-
const result = await someStep();
6-
return result;
4+
throw new Error("You attempted to execute workflow myWorkflow function directly. To start a workflow, use start(myWorkflow) from workflow/api");
75
}
6+
myWorkflow.workflowId = "workflow//input.js//myWorkflow";
87
export const arrowWorkflow = async ()=>{
9-
'use workflow';
10-
const data = await fetchData();
11-
return data;
8+
throw new Error("You attempted to execute workflow arrowWorkflow function directly. To start a workflow, use start(arrowWorkflow) from workflow/api");
129
};
10+
arrowWorkflow.workflowId = "workflow//input.js//arrowWorkflow";
1311
export default async function defaultWorkflow() {
1412
'use workflow';
1513
return await process();
1614
}
15+
defaultWorkflow.workflowId = "workflow//input.js//defaultWorkflow";
1716
// Non-export workflow function
1817
async function internalWorkflow() {
19-
'use workflow';
20-
return 'internal';
18+
throw new Error("You attempted to execute workflow internalWorkflow function directly. To start a workflow, use start(internalWorkflow) from workflow/api");
2119
}
20+
internalWorkflow.workflowId = "workflow//input.js//internalWorkflow";
2221
// Use the internal workflow to avoid lint warning
2322
regularFunction(internalWorkflow);
2423
// Regular function should not be affected

0 commit comments

Comments
 (0)