yieldstar 0.5.0 → 0.6.1
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/README.md +43 -52
- package/dist/exports/errors.d.ts.map +1 -1
- package/dist/exports/sdk-http.d.ts +8 -0
- package/dist/exports/sdk-http.d.ts.map +1 -1
- package/dist/exports/sdk-local.d.ts +19 -2
- package/dist/exports/sdk-local.d.ts.map +1 -1
- package/dist/exports/workflow.d.ts +14 -2
- package/dist/exports/workflow.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +664 -214
- package/dist/internal/effect-call.d.ts +60 -0
- package/dist/internal/effect-call.d.ts.map +1 -0
- package/dist/internal/runtime-call.d.ts +39 -0
- package/dist/internal/runtime-call.d.ts.map +1 -0
- package/dist/internal/serialise.d.ts.map +1 -1
- package/dist/internal/step-record.d.ts +13 -0
- package/dist/internal/step-record.d.ts.map +1 -0
- package/dist/internal/step-runner.d.ts +77 -14
- package/dist/internal/step-runner.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/exports/errors.ts +4 -0
- package/src/exports/sdk-http.ts +60 -27
- package/src/exports/sdk-local.ts +41 -15
- package/src/exports/workflow.ts +157 -101
- package/src/index.ts +34 -2
- package/src/internal/effect-call.ts +217 -0
- package/src/internal/runtime-call.ts +95 -0
- package/src/internal/step-record.ts +110 -0
- package/src/internal/step-runner.ts +515 -191
- package/src/internal/serialise.ts +0 -47
- package/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -26,8 +26,9 @@ Note: `@yieldstar/test-utils` is an internal testing helper used by this reposit
|
|
|
26
26
|
Run a workflow locally with persistence and timers using a subprocess worker and the SQLite runtime. The example uses the Bun connector; Node applications use `@yieldstar/sqlite-runtime/node` with otherwise identical runtime wiring.
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
//
|
|
29
|
+
// shared.ts
|
|
30
30
|
import { workflow, createWorkflowRouter } from "yieldstar";
|
|
31
|
+
import { SqliteRuntime, createSqliteDb } from "@yieldstar/sqlite-runtime/bun";
|
|
31
32
|
|
|
32
33
|
export const simple = workflow(async function* (step, event, logger) {
|
|
33
34
|
const n = yield* step.run(() => 1);
|
|
@@ -37,6 +38,8 @@ export const simple = workflow(async function* (step, event, logger) {
|
|
|
37
38
|
|
|
38
39
|
export const router = createWorkflowRouter({ "simple-workflow": simple });
|
|
39
40
|
export type Router = typeof router;
|
|
41
|
+
|
|
42
|
+
export const runtime = new SqliteRuntime(createSqliteDb({ path: "./.db/local.sqlite" }));
|
|
40
43
|
```
|
|
41
44
|
|
|
42
45
|
```ts
|
|
@@ -44,21 +47,10 @@ export type Router = typeof router;
|
|
|
44
47
|
import pino from "pino";
|
|
45
48
|
import { WorkflowRunner } from "@yieldstar/core";
|
|
46
49
|
import { createWorkflowWorker } from "@yieldstar/worker-invoker";
|
|
47
|
-
import {
|
|
48
|
-
import { router } from "./router";
|
|
50
|
+
import { router, runtime } from "./shared";
|
|
49
51
|
|
|
50
52
|
const logger = pino();
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const runner = new WorkflowRunner({
|
|
54
|
-
router,
|
|
55
|
-
heapClient: new SqliteHeapClient(db),
|
|
56
|
-
schedulerClient: new SqliteSchedulerClient({
|
|
57
|
-
taskQueueClient: new SqliteTaskQueueClient(db),
|
|
58
|
-
timersClient: new SqliteTimersClient(db),
|
|
59
|
-
}),
|
|
60
|
-
logger,
|
|
61
|
-
});
|
|
53
|
+
const runner = new WorkflowRunner(runtime, { router, logger });
|
|
62
54
|
|
|
63
55
|
createWorkflowWorker(runner, logger).listen();
|
|
64
56
|
```
|
|
@@ -66,21 +58,23 @@ createWorkflowWorker(runner, logger).listen();
|
|
|
66
58
|
```ts
|
|
67
59
|
// app.ts
|
|
68
60
|
import pino from "pino";
|
|
61
|
+
import { ExecutionDispatcher } from "@yieldstar/core";
|
|
69
62
|
import { createWorkflowInvoker } from "@yieldstar/worker-invoker";
|
|
70
63
|
import { createLocalSdk } from "yieldstar";
|
|
71
|
-
import {
|
|
64
|
+
import { runtime, type Router } from "./shared";
|
|
72
65
|
|
|
73
66
|
const logger = pino();
|
|
74
67
|
const workerPath = new URL("./worker.ts", import.meta.url).href;
|
|
75
68
|
const invoker = createWorkflowInvoker({ workerPath, logger });
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
70
|
+
// The dispatcher delivers due executions to workers; the SDK only admits them.
|
|
71
|
+
const dispatcher = new ExecutionDispatcher(runtime, { invoker, logger });
|
|
72
|
+
dispatcher.start();
|
|
80
73
|
|
|
81
|
-
const sdk = createLocalSdk<
|
|
74
|
+
const sdk = createLocalSdk<Router>(runtime, { invoker });
|
|
82
75
|
const result = await sdk.triggerAndWait({ workflowId: "simple-workflow" });
|
|
83
76
|
console.log(result); // 2
|
|
77
|
+
await dispatcher.stop();
|
|
84
78
|
```
|
|
85
79
|
|
|
86
80
|
TypeScript worker paths require Node 22.6 or newer for built-in type stripping. Use compiled JavaScript workers on older Node versions.
|
|
@@ -89,12 +83,14 @@ TypeScript worker paths require Node 22.6 or newer for built-in type stripping.
|
|
|
89
83
|
|
|
90
84
|
### Option A: Local Worker + SQLite (single process)
|
|
91
85
|
|
|
92
|
-
Use a subprocess worker to execute steps and a SQLite-backed runtime for
|
|
86
|
+
Use a subprocess worker to execute steps and a SQLite-backed runtime for execution records, step results, and stores.
|
|
93
87
|
|
|
94
|
-
1) Define workflows and
|
|
88
|
+
1) Define workflows, a router, and the runtime:
|
|
95
89
|
|
|
96
90
|
```ts
|
|
91
|
+
// shared.ts
|
|
97
92
|
import { workflow, createWorkflowRouter } from "yieldstar";
|
|
93
|
+
import { SqliteRuntime, createSqliteDb } from "@yieldstar/sqlite-runtime/bun";
|
|
98
94
|
|
|
99
95
|
export const dynamic = workflow<{ msg: string }, void>(async function* (step, event, logger) {
|
|
100
96
|
const n = yield* step.run(() => Math.random());
|
|
@@ -103,78 +99,69 @@ export const dynamic = workflow<{ msg: string }, void>(async function* (step, ev
|
|
|
103
99
|
});
|
|
104
100
|
|
|
105
101
|
export const router = createWorkflowRouter({ "dynamic-workflow": dynamic });
|
|
102
|
+
export type Router = typeof router;
|
|
103
|
+
|
|
104
|
+
export const runtime = new SqliteRuntime(createSqliteDb({ path: "./.db/local.sqlite" }));
|
|
106
105
|
```
|
|
107
106
|
|
|
108
|
-
2) Create worker
|
|
107
|
+
2) Create the worker (a forked subprocess):
|
|
109
108
|
|
|
110
109
|
```ts
|
|
111
110
|
// worker.ts
|
|
112
111
|
import pino from "pino";
|
|
113
112
|
import { WorkflowRunner } from "@yieldstar/core";
|
|
114
113
|
import { createWorkflowWorker } from "@yieldstar/worker-invoker";
|
|
115
|
-
import {
|
|
116
|
-
import { router } from "./router";
|
|
117
|
-
import { createSqliteDb } from "@yieldstar/sqlite-runtime/bun";
|
|
114
|
+
import { router, runtime } from "./shared";
|
|
118
115
|
|
|
119
116
|
const logger = pino();
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const runner = new WorkflowRunner({
|
|
123
|
-
router,
|
|
124
|
-
heapClient: new SqliteHeapClient(db),
|
|
125
|
-
schedulerClient: new SqliteSchedulerClient({
|
|
126
|
-
taskQueueClient: new SqliteTaskQueueClient(db),
|
|
127
|
-
timersClient: new SqliteTimersClient(db),
|
|
128
|
-
}),
|
|
129
|
-
logger,
|
|
130
|
-
});
|
|
117
|
+
const runner = new WorkflowRunner(runtime, { router, logger });
|
|
131
118
|
|
|
132
119
|
createWorkflowWorker(runner, logger).listen();
|
|
133
120
|
```
|
|
134
121
|
|
|
135
|
-
3)
|
|
122
|
+
3) Run a dispatcher in your app and trigger workflows locally:
|
|
136
123
|
|
|
137
124
|
```ts
|
|
138
125
|
// app.ts
|
|
139
126
|
import pino from "pino";
|
|
127
|
+
import { ExecutionDispatcher } from "@yieldstar/core";
|
|
140
128
|
import { createWorkflowInvoker } from "@yieldstar/worker-invoker";
|
|
141
129
|
import { createLocalSdk } from "yieldstar";
|
|
142
|
-
import {
|
|
130
|
+
import { runtime, type Router } from "./shared";
|
|
143
131
|
|
|
144
132
|
const logger = pino();
|
|
145
133
|
const workerPath = new URL("./worker.ts", import.meta.url).href;
|
|
146
134
|
const invoker = createWorkflowInvoker({ workerPath, logger });
|
|
147
135
|
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
eventLoop.start({ onNewEvent: invoker.execute, logger });
|
|
136
|
+
const dispatcher = new ExecutionDispatcher(runtime, { invoker, logger });
|
|
137
|
+
dispatcher.start();
|
|
151
138
|
|
|
152
|
-
const sdk = createLocalSdk<{
|
|
139
|
+
const sdk = createLocalSdk<Router>(runtime, { invoker });
|
|
153
140
|
const res = await sdk.triggerAndWait({ workflowId: "dynamic-workflow", params: { msg: "hello" } });
|
|
154
141
|
console.log(res);
|
|
142
|
+
await dispatcher.stop();
|
|
155
143
|
```
|
|
156
144
|
|
|
157
145
|
See a working reference in `examples/local-execution/`.
|
|
158
146
|
|
|
159
147
|
### Option B: HTTP Server (Bun)
|
|
160
148
|
|
|
161
|
-
Expose routes to
|
|
149
|
+
Expose routes to admit executions and await their outcomes. Use the HTTP SDK as a client. `/trigger` responds `202 { executionId }` once the execution is admitted, and `409` when the supplied `executionId` is already in use.
|
|
162
150
|
|
|
163
151
|
Server:
|
|
164
152
|
|
|
165
153
|
```ts
|
|
166
154
|
import pino from "pino";
|
|
155
|
+
import { ExecutionDispatcher } from "@yieldstar/core";
|
|
167
156
|
import { createRoutes, createMiddleware } from "@yieldstar/http-server";
|
|
168
157
|
import { createWorkflowInvoker } from "@yieldstar/worker-invoker";
|
|
169
|
-
import {
|
|
170
|
-
import { router } from "./router";
|
|
158
|
+
import { runtime } from "./shared";
|
|
171
159
|
|
|
172
160
|
const logger = pino();
|
|
173
161
|
const workerPath = new URL("./worker.ts", import.meta.url).href;
|
|
174
162
|
const invoker = createWorkflowInvoker({ workerPath, logger });
|
|
175
163
|
|
|
176
|
-
|
|
177
|
-
new SqliteEventLoop(db).start({ onNewEvent: invoker.execute, logger });
|
|
164
|
+
new ExecutionDispatcher(runtime, { invoker, logger }).start();
|
|
178
165
|
|
|
179
166
|
const auth = createMiddleware(async (req, event, next) => {
|
|
180
167
|
if (!req.headers.get("Authorization")) return new Response("Unauthorized", { status: 401 });
|
|
@@ -183,7 +170,7 @@ const auth = createMiddleware(async (req, event, next) => {
|
|
|
183
170
|
|
|
184
171
|
Bun.serve({
|
|
185
172
|
port: 8080,
|
|
186
|
-
routes: { "/status": new Response("OK"), ...createRoutes({ invoker, logger, middleware: [auth] }) },
|
|
173
|
+
routes: { "/status": new Response("OK"), ...createRoutes({ runtime, invoker, logger, middleware: [auth] }) },
|
|
187
174
|
});
|
|
188
175
|
```
|
|
189
176
|
|
|
@@ -291,7 +278,7 @@ Top‑level exports from `yieldstar`:
|
|
|
291
278
|
export { createLocalSdk } from "yieldstar";
|
|
292
279
|
export { createHttpSdkFactory } from "yieldstar";
|
|
293
280
|
export { createWorkflowRouter } from "yieldstar";
|
|
294
|
-
export { RetryableError } from "yieldstar";
|
|
281
|
+
export { RetryableError, ExecutionAdmissionError } from "yieldstar";
|
|
295
282
|
export { createWorkflow, workflow } from "yieldstar";
|
|
296
283
|
export type { WorkflowFn } from "yieldstar";
|
|
297
284
|
```
|
|
@@ -336,13 +323,16 @@ new RetryableError(message, { maxAttempts: number, retryInterval: number });
|
|
|
336
323
|
|
|
337
324
|
### Local SDK
|
|
338
325
|
|
|
339
|
-
Create a client that
|
|
326
|
+
Create a client that admits executions directly into a runtime. A running `ExecutionDispatcher` delivers them.
|
|
340
327
|
|
|
341
328
|
```ts
|
|
342
|
-
const sdk = createLocalSdk<Router>(invoker);
|
|
329
|
+
const sdk = createLocalSdk<Router>(runtime, { invoker?, pollInterval? });
|
|
330
|
+
const { executionId } = await sdk.trigger({ workflowId, params?, context?, executionId? });
|
|
343
331
|
await sdk.triggerAndWait({ workflowId, params? });
|
|
344
332
|
```
|
|
345
333
|
|
|
334
|
+
`trigger` resolves once admission commits. `triggerAndWait` resolves with the result recorded on the execution record, or rejects with the recorded error. Both throw `ExecutionAdmissionError` when the `executionId` is already in use (`EXECUTION_ID_CONFLICT`) or `params`/`context` are not durable values (`INVALID_EXECUTION_EVENT`).
|
|
335
|
+
|
|
346
336
|
### HTTP SDK
|
|
347
337
|
|
|
348
338
|
Factory returning a client bound to a base URL.
|
|
@@ -394,7 +384,8 @@ See more examples in `test/*.test.ts`.
|
|
|
394
384
|
|
|
395
385
|
- In loops, always add cache keys. Missing keys trigger loop detection.
|
|
396
386
|
- `logger` is a Pino logger passed into workflows for observability.
|
|
397
|
-
- HTTP middleware can read/set `event.context` before
|
|
387
|
+
- HTTP middleware can read/set `event.context` before the execution is admitted.
|
|
388
|
+
- Execution IDs are never reused. Triggering with an ID that was already admitted throws `ExecutionAdmissionError`.
|
|
398
389
|
|
|
399
390
|
## Contributing
|
|
400
391
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/exports/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/exports/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAe,SAAQ,KAAK;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;gBAEpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE;CAOvD"}
|
|
@@ -11,6 +11,14 @@ export declare function createHttpSdkFactory<W extends WorkflowRouter>(): (param
|
|
|
11
11
|
url: string;
|
|
12
12
|
fetchOptions?: Omit<RequestInit, "body" | "method">;
|
|
13
13
|
}) => {
|
|
14
|
+
/**
|
|
15
|
+
* Admits an execution through the trigger route. When `executionId` is
|
|
16
|
+
* omitted the runtime chooses one, which the response carries. The body
|
|
17
|
+
* is encoded with the durable value codec, so params and context reach
|
|
18
|
+
* the runtime unchanged.
|
|
19
|
+
* @throws {ExecutionAdmissionError} on `409 Conflict` or an invalid event,
|
|
20
|
+
* including params or context the codec rejects, before any request
|
|
21
|
+
*/
|
|
14
22
|
trigger<K extends string & keyof W>(event: TriggerEvent<K, EventParamsOf<W[K]>>): Promise<TriggerResponse<W, K>>;
|
|
15
23
|
waitForResult<K extends string & keyof W>(ack: TriggerAck): Promise<WorkflowGeneratorReturnType<W[K]>>;
|
|
16
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-http.d.ts","sourceRoot":"","sources":["../../src/exports/sdk-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,
|
|
1
|
+
{"version":3,"file":"sdk-http.d.ts","sourceRoot":"","sources":["../../src/exports/sdk-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,2BAA2B,EAE5B,MAAM,iBAAiB,CAAC;AAMzB,KAAK,UAAU,GAAG;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,IAAI;IAC3E,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,aAAa,EAAE,MAAM,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjE,CAAC;AAOF,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,cAAc,MACnD,QAAQ;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;CACrD;IAEG;;;;;;;OAOG;YACW,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,SAC/B,YAAY,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;kBAoCb,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,OACvC,UAAU,GACd,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;EA8BlD"}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import type { EventParamsOf, WorkflowRouter, WorkflowInvoker, TriggerEvent, WorkflowGeneratorReturnType } from "@yieldstar/core";
|
|
1
|
+
import type { EventParamsOf, ExecutionClient, WorkflowRouter, WorkflowInvoker, TriggerEvent, WorkflowGeneratorReturnType } from "@yieldstar/core";
|
|
2
2
|
type TriggerAck = {
|
|
3
3
|
executionId: string;
|
|
4
4
|
};
|
|
5
|
-
export declare function createLocalSdk<W extends WorkflowRouter>(
|
|
5
|
+
export declare function createLocalSdk<W extends WorkflowRouter>(runtime: {
|
|
6
|
+
executions: ExecutionClient;
|
|
7
|
+
}, options?: {
|
|
8
|
+
/** Lets `triggerAndWait` settle as soon as the dispatcher acknowledges. */
|
|
9
|
+
invoker?: WorkflowInvoker;
|
|
10
|
+
/** Milliseconds between reads of the execution record. @default 25 */
|
|
11
|
+
pollInterval?: number;
|
|
12
|
+
}): {
|
|
13
|
+
/**
|
|
14
|
+
* Admits an execution and resolves once admission commits. A dispatcher
|
|
15
|
+
* delivers it; this does not wait for a worker to start.
|
|
16
|
+
* @throws {ExecutionAdmissionError} when the ID is already in use or the
|
|
17
|
+
* event cannot be stored without loss
|
|
18
|
+
*/
|
|
6
19
|
trigger<K extends string & keyof W>(event: TriggerEvent<K, EventParamsOf<W[K]>>): Promise<TriggerAck>;
|
|
20
|
+
/**
|
|
21
|
+
* Admits an execution and waits for its record to reach a terminal
|
|
22
|
+
* status. Resolves with the result, or rejects with the recorded error.
|
|
23
|
+
*/
|
|
7
24
|
triggerAndWait<K extends string & keyof W>(event: TriggerEvent<K, EventParamsOf<W[K]>>): Promise<WorkflowGeneratorReturnType<W[K]>>;
|
|
8
25
|
};
|
|
9
26
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-local.d.ts","sourceRoot":"","sources":["../../src/exports/sdk-local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,YAAY,
|
|
1
|
+
{"version":3,"file":"sdk-local.d.ts","sourceRoot":"","sources":["../../src/exports/sdk-local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,YAAY,EACZ,2BAA2B,EAC5B,MAAM,iBAAiB,CAAC;AAMzB,KAAK,UAAU,GAAG;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,cAAc,CAAC,CAAC,SAAS,cAAc,EACrD,OAAO,EAAE;IAAE,UAAU,EAAE,eAAe,CAAA;CAAE,EACxC,OAAO,CAAC,EAAE;IACR,2EAA2E;IAC3E,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;IAKC;;;;;OAKG;YACW,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,SAC/B,YAAY,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,UAAU,CAAC;IAYtB;;;OAGG;mBACkB,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,SACtC,YAAY,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;EAahD"}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import type { Logger } from "pino";
|
|
2
|
-
import type { WorkflowEvent, WorkflowGenerator, EventParams, EventContext } from "@yieldstar/core";
|
|
2
|
+
import type { Durable, WorkflowEvent, WorkflowGenerator, EventParams, EventContext, IfDurable } from "@yieldstar/core";
|
|
3
3
|
import type { StepRunner } from "../internal/step-runner";
|
|
4
4
|
export type WorkflowFn<Params extends EventParams, Result, Context extends EventContext> = (step: StepRunner, event: WorkflowEvent<Params, Context>, logger: Logger) => AsyncGenerator<any, Result>;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A workflow function whose params and result are durable values. Params are
|
|
7
|
+
* an input, so a function type cannot check them; a missing property named
|
|
8
|
+
* for the problem does instead.
|
|
9
|
+
*/
|
|
10
|
+
export type DurableWorkflowFn<Params, Result> = IfDurable<Params, {
|
|
11
|
+
"Workflow params must be durable values": Durable<Params>;
|
|
12
|
+
}> & IfDurable<Result, (step: any, event: any, logger: any) => AsyncGenerator<any, Durable<Result>>>;
|
|
13
|
+
/**
|
|
14
|
+
* Wraps a workflow function in a generator that advances its steps and yields
|
|
15
|
+
* control to the executor whenever a step needs async work.
|
|
16
|
+
*/
|
|
17
|
+
export declare function workflow<Params extends EventParams, Result, Context extends EventContext>(workflowFn: WorkflowFn<Params, Result, Context> & DurableWorkflowFn<Params, Result>): WorkflowGenerator<Params, Result, Context>;
|
|
6
18
|
export declare const createWorkflow: typeof workflow;
|
|
7
19
|
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/exports/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,YAAY,
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/exports/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AA4B1D,MAAM,MAAM,UAAU,CACpB,MAAM,SAAS,WAAW,EAC1B,MAAM,EACN,OAAO,SAAS,YAAY,IAC1B,CACF,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,MAAM,EAAE,MAAM,KACX,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,IAAI,SAAS,CACvD,MAAM,EACN;IAAE,wCAAwC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAC9D,GACC,SAAS,CACP,MAAM,EACN,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAC7E,CAAC;AAEJ;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,MAAM,SAAS,WAAW,EAC1B,MAAM,EACN,OAAO,SAAS,YAAY,EAE5B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,GAC7C,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CA2N5C;AAED,eAAO,MAAM,cAAc,iBAAW,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ export { createLocalSdk } from "./exports/sdk-local";
|
|
|
2
2
|
export { createHttpSdkFactory } from "./exports/sdk-http";
|
|
3
3
|
export { createWorkflowRouter } from "./exports/router";
|
|
4
4
|
export { RetryableError } from "./exports/errors";
|
|
5
|
+
export { EffectClientInvariantError, EffectDeliveryError, ExecutionAdmissionError, WORKFLOW_RESULT_STEP_KEY, WorkflowEffectError, WorkflowStartError, WorkflowValueError, registerErrorClass, } from "@yieldstar/core";
|
|
5
6
|
export { createWorkflow, workflow } from "./exports/workflow";
|
|
6
|
-
export type { WorkflowFn } from "./exports/workflow";
|
|
7
|
+
export type { DurableWorkflowFn, WorkflowFn } from "./exports/workflow";
|
|
7
8
|
export { defineStore } from "./internal/step-runner";
|
|
8
|
-
export type { WorkflowStore } from "./internal/step-runner";
|
|
9
|
-
export type { Draft, RuntimeStore, StandardSchemaV1, StoreDefinition, StoreDeleteFromResult, StoreKey, StorePath, StoreSelector, StoreSnapshot, StoreState, StoreUpdateFromResult, StoreUpdateResult, StoreVersion, WorkflowEvent, } from "@yieldstar/core";
|
|
9
|
+
export type { DurableStepFn, EffectDescriptor, EffectLookup, StepRunner, StepRunOptions, WorkflowStore, } from "./internal/step-runner";
|
|
10
|
+
export type { Draft, RuntimeStore, StandardSchemaV1, StoreDefinition, StoreDeleteFromResult, StoreKey, StorePath, StoreSelector, StoreSnapshot, StoreState, DurableStoreSchema, StoreUpdateFromResult, StoreUpdateResult, StoreVersion, WorkflowEvent, ExecutionAdmissionErrorCode, ExecutionOutcome, ExecutionRecord, ExecutionStatus, ExecutionParent, Durable, DurableObject, DurableValue, ErrorClass, WorkflowValueErrorCode, WorkflowStartErrorCode, EffectDeliveryErrorCode, EffectRecord, WorkflowEffectErrorCode, } from "@yieldstar/core";
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,KAAK,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,aAAa,EACb,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,2BAA2B,EAC3B,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,OAAO,EACP,aAAa,EACb,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
|