Skip to content

Commit 9335026

Browse files
Schnizvercel[bot]
andauthored
workflow: stub workflow/api package so it can be referenced in a workflow context (#290)
* workflow: stub workflow/api package so it can be referenced in a workflow context what's not allowed is to call these functions, so let's stub them and make them fail in runtime. i guess that eventually we will actually implement some of them (start or resumeHook or whatever) in a durable way. Signed-off-by: Gal Schlezinger <gal@spitfire.co.il> * changeset Signed-off-by: Gal Schlezinger <gal@spitfire.co.il> * Update packages/workflow/src/api-workflow.ts Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Signed-off-by: Gal Schlezinger <gal@spitfire.co.il> --------- Signed-off-by: Gal Schlezinger <gal@spitfire.co.il> Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
1 parent 00b0bb9 commit 9335026

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.changeset/silver-boats-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"workflow": patch
3+
---
4+
5+
stub `workflow/api` in a workflow context with functions that fail immediately, so they can be referenced in workflow-related code but not invoked

packages/workflow/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
"require": "./dist/typescript-plugin.cjs",
2929
"default": "./dist/index.js"
3030
},
31-
"./api": "./dist/api.js",
31+
"./api": {
32+
"types": "./dist/api.d.ts",
33+
"workflow": "./dist/api-workflow.js",
34+
"default": "./dist/api.js"
35+
},
3236
"./internal/errors": "./dist/internal/errors.js",
3337
"./internal/serialization": "./dist/internal/serialization.js",
3438
"./internal/builtins": "./dist/internal/builtins.js",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export type {
2+
Event,
3+
StartOptions,
4+
WorkflowReadableStreamOptions,
5+
WorkflowRun,
6+
} from '@workflow/core/runtime';
7+
8+
const workflowStub = (item: string) => {
9+
throw new Error(
10+
`The workflow environment doesn't allow this runtime usage of ${item}.`
11+
);
12+
};
13+
14+
export class Run {
15+
constructor() {
16+
workflowStub('Run');
17+
}
18+
}
19+
export const getRun = () => workflowStub('getRun');
20+
export const getHookByToken = () => workflowStub('getHookByToken');
21+
export const resumeHook = () => workflowStub('resumeHook');
22+
export const resumeWebhook = () => workflowStub('resumeWebhook');
23+
export const runStep = () => workflowStub('runStep');
24+
export const start = () => workflowStub('start');

0 commit comments

Comments
 (0)