Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tsc dependency and fix path route #47

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
14 changes: 9 additions & 5 deletions examples/nextjs/app/path/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const runtime = 'nodejs';

import { serve } from '@upstash/workflow/nextjs'

const someWork = (input: string) => {
Expand All @@ -9,7 +7,13 @@ const someWork = (input: string) => {
export const { POST } = serve<string>(async (context) => {
const input = context.requestPayload
const result1 = await context.run('step1', async () => {
console.log(someWork(input));
const output = someWork(input)
console.log('step 1 input', input, 'output', output)
return output
})

await context.run('step2', async () => {
const output = someWork(result1)
console.log('step 2 input', result1, 'output', output)
})
}, {
})
})
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"husky": "^9.1.6",
"next": "^14.2.14",
"prettier": "3.3.3",
"tsc": "^2.0.4",
"tsup": "^8.3.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.8.0"
Expand Down
33 changes: 33 additions & 0 deletions src/workflow-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,39 @@ describe("Workflow Requests", () => {
expect(result.value).toBe("workflow-finished");
});

test("should call onCancel if context.cancel is called inside context.run", async () => {
const workflowRunId = nanoid();
const token = "myToken";

const context = new WorkflowContext({
qstashClient: new Client({ baseUrl: MOCK_SERVER_URL, token }),
workflowRunId: workflowRunId,
initialPayload: undefined,
headers: new Headers({}) as Headers,
steps: [],
url: WORKFLOW_ENDPOINT,
});

const finished = new FinishState();
const result = await triggerRouteFunction({
onStep: async () => {
await context.run("should call cancel", async () => {
await context.cancel();
});
},
onCleanup: async () => {
throw new Error("shouldn't call");
},
onCancel: async () => {
finished.finish();
},
});
finished.check();
expect(result.isOk()).toBeTrue();
// @ts-expect-error value will be set since result isOk
expect(result.value).toBe("workflow-finished");
});

test("should call publishJSON in triggerWorkflowDelete", async () => {
const workflowRunId = nanoid();
const token = "myToken";
Expand Down
Loading