yieldstar 0.4.6 → 0.6.0
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 +57 -64
- 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 +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +791 -137
- 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 +93 -9
- package/dist/internal/step-runner.d.ts.map +1 -1
- package/dist/internal/utils.d.ts +11 -0
- package/dist/internal/utils.d.ts.map +1 -1
- package/package.json +8 -4
- 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 +159 -99
- package/src/index.ts +51 -1
- 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 +748 -53
- package/src/internal/utils.ts +24 -10
- package/dist/exports/scheduler.d.ts +0 -49
- package/dist/exports/scheduler.d.ts.map +0 -1
- package/dist/exports/simplified-types.d.ts +0 -31
- package/dist/exports/simplified-types.d.ts.map +0 -1
- package/dist/exports/types.d.ts +0 -6
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/internal/types.d.ts +0 -9
- package/dist/internal/types.d.ts.map +0 -1
- package/src/internal/serialise.ts +0 -44
- package/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ JavaScript‑native distributed workflows.
|
|
|
4
4
|
|
|
5
5
|
Write workflows as async generator functions that yield steps. Use first‑class primitives for retries, delays, and polling. .
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The resident-process runtime runs on Bun and Node with native SQLite connectors.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -16,18 +16,19 @@ bun add yieldstar
|
|
|
16
16
|
|
|
17
17
|
Depending on how you run workflows, also install:
|
|
18
18
|
|
|
19
|
-
- Local (recommended): `@yieldstar/
|
|
20
|
-
- HTTP server
|
|
19
|
+
- Local (recommended): `@yieldstar/worker-invoker` and `@yieldstar/sqlite-runtime`
|
|
20
|
+
- HTTP server: `@yieldstar/http-server` and `@yieldstar/worker-invoker`
|
|
21
21
|
|
|
22
22
|
Note: `@yieldstar/test-utils` is an internal testing helper used by this repository. For local application use, prefer the SQLite runtime.
|
|
23
23
|
|
|
24
24
|
## Quick Start: Local (SQLite)
|
|
25
25
|
|
|
26
|
-
Run a workflow locally with persistence and timers using a
|
|
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,28 +38,19 @@ 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
|
|
43
46
|
// worker.ts
|
|
44
47
|
import pino from "pino";
|
|
45
48
|
import { WorkflowRunner } from "@yieldstar/core";
|
|
46
|
-
import { createWorkflowWorker } from "@yieldstar/
|
|
47
|
-
import {
|
|
48
|
-
import { router } from "./router";
|
|
49
|
+
import { createWorkflowWorker } from "@yieldstar/worker-invoker";
|
|
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,33 +58,39 @@ createWorkflowWorker(runner, logger).listen();
|
|
|
66
58
|
```ts
|
|
67
59
|
// app.ts
|
|
68
60
|
import pino from "pino";
|
|
69
|
-
import {
|
|
61
|
+
import { ExecutionDispatcher } from "@yieldstar/core";
|
|
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
|
|
|
80
|
+
TypeScript worker paths require Node 22.6 or newer for built-in type stripping. Use compiled JavaScript workers on older Node versions.
|
|
81
|
+
|
|
86
82
|
## Pick Your Runtime
|
|
87
83
|
|
|
88
84
|
### Option A: Local Worker + SQLite (single process)
|
|
89
85
|
|
|
90
|
-
Use a
|
|
86
|
+
Use a subprocess worker to execute steps and a SQLite-backed runtime for execution records, step results, and stores.
|
|
91
87
|
|
|
92
|
-
1) Define workflows and
|
|
88
|
+
1) Define workflows, a router, and the runtime:
|
|
93
89
|
|
|
94
90
|
```ts
|
|
91
|
+
// shared.ts
|
|
95
92
|
import { workflow, createWorkflowRouter } from "yieldstar";
|
|
93
|
+
import { SqliteRuntime, createSqliteDb } from "@yieldstar/sqlite-runtime/bun";
|
|
96
94
|
|
|
97
95
|
export const dynamic = workflow<{ msg: string }, void>(async function* (step, event, logger) {
|
|
98
96
|
const n = yield* step.run(() => Math.random());
|
|
@@ -101,78 +99,69 @@ export const dynamic = workflow<{ msg: string }, void>(async function* (step, ev
|
|
|
101
99
|
});
|
|
102
100
|
|
|
103
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" }));
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
2) Create worker
|
|
107
|
+
2) Create the worker (a forked subprocess):
|
|
107
108
|
|
|
108
109
|
```ts
|
|
109
110
|
// worker.ts
|
|
110
111
|
import pino from "pino";
|
|
111
112
|
import { WorkflowRunner } from "@yieldstar/core";
|
|
112
|
-
import { createWorkflowWorker } from "@yieldstar/
|
|
113
|
-
import {
|
|
114
|
-
import { router } from "./router";
|
|
115
|
-
import { createSqliteDb } from "@yieldstar/bun-sqlite-runtime";
|
|
113
|
+
import { createWorkflowWorker } from "@yieldstar/worker-invoker";
|
|
114
|
+
import { router, runtime } from "./shared";
|
|
116
115
|
|
|
117
116
|
const logger = pino();
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const runner = new WorkflowRunner({
|
|
121
|
-
router,
|
|
122
|
-
heapClient: new SqliteHeapClient(db),
|
|
123
|
-
schedulerClient: new SqliteSchedulerClient({
|
|
124
|
-
taskQueueClient: new SqliteTaskQueueClient(db),
|
|
125
|
-
timersClient: new SqliteTimersClient(db),
|
|
126
|
-
}),
|
|
127
|
-
logger,
|
|
128
|
-
});
|
|
117
|
+
const runner = new WorkflowRunner(runtime, { router, logger });
|
|
129
118
|
|
|
130
119
|
createWorkflowWorker(runner, logger).listen();
|
|
131
120
|
```
|
|
132
121
|
|
|
133
|
-
3)
|
|
122
|
+
3) Run a dispatcher in your app and trigger workflows locally:
|
|
134
123
|
|
|
135
124
|
```ts
|
|
136
125
|
// app.ts
|
|
137
126
|
import pino from "pino";
|
|
138
|
-
import {
|
|
127
|
+
import { ExecutionDispatcher } from "@yieldstar/core";
|
|
128
|
+
import { createWorkflowInvoker } from "@yieldstar/worker-invoker";
|
|
139
129
|
import { createLocalSdk } from "yieldstar";
|
|
140
|
-
import {
|
|
130
|
+
import { runtime, type Router } from "./shared";
|
|
141
131
|
|
|
142
132
|
const logger = pino();
|
|
143
133
|
const workerPath = new URL("./worker.ts", import.meta.url).href;
|
|
144
134
|
const invoker = createWorkflowInvoker({ workerPath, logger });
|
|
145
135
|
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
eventLoop.start({ onNewEvent: invoker.execute, logger });
|
|
136
|
+
const dispatcher = new ExecutionDispatcher(runtime, { invoker, logger });
|
|
137
|
+
dispatcher.start();
|
|
149
138
|
|
|
150
|
-
const sdk = createLocalSdk<{
|
|
139
|
+
const sdk = createLocalSdk<Router>(runtime, { invoker });
|
|
151
140
|
const res = await sdk.triggerAndWait({ workflowId: "dynamic-workflow", params: { msg: "hello" } });
|
|
152
141
|
console.log(res);
|
|
142
|
+
await dispatcher.stop();
|
|
153
143
|
```
|
|
154
144
|
|
|
155
145
|
See a working reference in `examples/local-execution/`.
|
|
156
146
|
|
|
157
147
|
### Option B: HTTP Server (Bun)
|
|
158
148
|
|
|
159
|
-
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.
|
|
160
150
|
|
|
161
151
|
Server:
|
|
162
152
|
|
|
163
153
|
```ts
|
|
164
154
|
import pino from "pino";
|
|
165
|
-
import {
|
|
166
|
-
import {
|
|
167
|
-
import {
|
|
168
|
-
import {
|
|
155
|
+
import { ExecutionDispatcher } from "@yieldstar/core";
|
|
156
|
+
import { createRoutes, createMiddleware } from "@yieldstar/http-server";
|
|
157
|
+
import { createWorkflowInvoker } from "@yieldstar/worker-invoker";
|
|
158
|
+
import { runtime } from "./shared";
|
|
169
159
|
|
|
170
160
|
const logger = pino();
|
|
171
161
|
const workerPath = new URL("./worker.ts", import.meta.url).href;
|
|
172
162
|
const invoker = createWorkflowInvoker({ workerPath, logger });
|
|
173
163
|
|
|
174
|
-
|
|
175
|
-
new SqliteEventLoop(db).start({ onNewEvent: invoker.execute, logger });
|
|
164
|
+
new ExecutionDispatcher(runtime, { invoker, logger }).start();
|
|
176
165
|
|
|
177
166
|
const auth = createMiddleware(async (req, event, next) => {
|
|
178
167
|
if (!req.headers.get("Authorization")) return new Response("Unauthorized", { status: 401 });
|
|
@@ -181,7 +170,7 @@ const auth = createMiddleware(async (req, event, next) => {
|
|
|
181
170
|
|
|
182
171
|
Bun.serve({
|
|
183
172
|
port: 8080,
|
|
184
|
-
routes: { "/status": new Response("OK"), ...createRoutes({ invoker, logger, middleware: [auth] }) },
|
|
173
|
+
routes: { "/status": new Response("OK"), ...createRoutes({ runtime, invoker, logger, middleware: [auth] }) },
|
|
185
174
|
});
|
|
186
175
|
```
|
|
187
176
|
|
|
@@ -289,7 +278,7 @@ Top‑level exports from `yieldstar`:
|
|
|
289
278
|
export { createLocalSdk } from "yieldstar";
|
|
290
279
|
export { createHttpSdkFactory } from "yieldstar";
|
|
291
280
|
export { createWorkflowRouter } from "yieldstar";
|
|
292
|
-
export { RetryableError } from "yieldstar";
|
|
281
|
+
export { RetryableError, ExecutionAdmissionError } from "yieldstar";
|
|
293
282
|
export { createWorkflow, workflow } from "yieldstar";
|
|
294
283
|
export type { WorkflowFn } from "yieldstar";
|
|
295
284
|
```
|
|
@@ -334,13 +323,16 @@ new RetryableError(message, { maxAttempts: number, retryInterval: number });
|
|
|
334
323
|
|
|
335
324
|
### Local SDK
|
|
336
325
|
|
|
337
|
-
Create a client that
|
|
326
|
+
Create a client that admits executions directly into a runtime. A running `ExecutionDispatcher` delivers them.
|
|
338
327
|
|
|
339
328
|
```ts
|
|
340
|
-
const sdk = createLocalSdk<Router>(invoker);
|
|
329
|
+
const sdk = createLocalSdk<Router>(runtime, { invoker?, pollInterval? });
|
|
330
|
+
const { executionId } = await sdk.trigger({ workflowId, params?, context?, executionId? });
|
|
341
331
|
await sdk.triggerAndWait({ workflowId, params? });
|
|
342
332
|
```
|
|
343
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
|
+
|
|
344
336
|
### HTTP SDK
|
|
345
337
|
|
|
346
338
|
Factory returning a client bound to a base URL.
|
|
@@ -370,7 +362,7 @@ Use `Router` to type your SDKs so `workflowId` and `params` are enforced.
|
|
|
370
362
|
For repository development we use an in‑memory runtime driven by `@yieldstar/test-utils` to `triggerAndWait` in tests. This package is internal; application users should test against the same runtime they use in production where possible. Example (internal):
|
|
371
363
|
|
|
372
364
|
```ts
|
|
373
|
-
import { test, expect } from "
|
|
365
|
+
import { test, expect } from "vitest";
|
|
374
366
|
import { createTestSdkFactory } from "@yieldstar/test-utils";
|
|
375
367
|
import { createWorkflow } from "yieldstar";
|
|
376
368
|
|
|
@@ -392,7 +384,8 @@ See more examples in `test/*.test.ts`.
|
|
|
392
384
|
|
|
393
385
|
- In loops, always add cache keys. Missing keys trigger loop detection.
|
|
394
386
|
- `logger` is a Pino logger passed into workflows for observability.
|
|
395
|
-
- 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`.
|
|
396
389
|
|
|
397
390
|
## Contributing
|
|
398
391
|
|
|
@@ -405,4 +398,4 @@ MIT
|
|
|
405
398
|
|
|
406
399
|
## Author
|
|
407
400
|
|
|
408
|
-
[Daniel Grant](danielgrant.co)
|
|
401
|
+
[Daniel Grant](https://danielgrant.co)
|
|
@@ -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,MA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,eAAO,MAAM,cAAc,iBAAW,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +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";
|
|
8
|
+
export { defineStore } from "./internal/step-runner";
|
|
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";
|
|
7
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,EAA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