openworkflow 0.4.1 → 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 +43 -345
- package/dist/backend-test/backend.testsuite.d.ts +20 -0
- package/dist/backend-test/backend.testsuite.d.ts.map +1 -0
- package/dist/{core → backend-test}/backend.testsuite.js +191 -59
- package/dist/backend-test/index.d.ts +2 -0
- package/dist/backend-test/index.d.ts.map +1 -0
- package/dist/backend-test/index.js +1 -0
- package/dist/{core/backend.d.ts → backend.d.ts} +7 -5
- package/dist/backend.d.ts.map +1 -0
- package/dist/{core/backend.js → backend.js} +0 -1
- package/dist/backend.testsuite.d.ts +20 -0
- package/dist/backend.testsuite.d.ts.map +1 -0
- package/dist/{core/backend-test-suite.js → backend.testsuite.js} +301 -171
- package/dist/bin/openworkflow.d.ts +3 -0
- package/dist/bin/openworkflow.d.ts.map +1 -0
- package/dist/bin/openworkflow.js +43 -0
- package/dist/chaos.test.d.ts +2 -0
- package/dist/chaos.test.d.ts.map +1 -0
- package/dist/chaos.test.js +88 -0
- package/dist/client.d.ts +141 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/{sdk/sdk.js → client.js} +43 -71
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/{sdk/sdk.test.js → client.test.js} +130 -14
- package/dist/core/duration.d.ts +4 -2
- package/dist/core/duration.d.ts.map +1 -1
- package/dist/core/duration.js +3 -2
- package/dist/core/duration.test.js +0 -1
- package/dist/core/error.d.ts +14 -0
- package/dist/core/error.d.ts.map +1 -0
- package/dist/core/error.js +17 -0
- package/dist/core/error.test.d.ts +2 -0
- package/dist/core/error.test.d.ts.map +1 -0
- package/dist/core/error.test.js +60 -0
- package/dist/core/json.js +0 -1
- package/dist/core/result.d.ts +14 -4
- package/dist/core/result.d.ts.map +1 -1
- package/dist/core/result.js +10 -1
- package/dist/core/result.test.js +2 -2
- package/dist/core/retry.d.ts +0 -9
- package/dist/core/retry.d.ts.map +1 -1
- package/dist/core/retry.js +0 -15
- package/dist/core/schema.js +0 -1
- package/dist/core/step.d.ts +1 -32
- package/dist/core/step.d.ts.map +1 -1
- package/dist/core/step.js +0 -36
- package/dist/core/step.test.js +1 -75
- package/dist/core/workflow.d.ts +2 -47
- package/dist/core/workflow.d.ts.map +1 -1
- package/dist/core/workflow.js +0 -45
- package/dist/core/workflow.test.js +1 -104
- package/dist/driver.d.ts +116 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +1 -0
- package/dist/{execution/execution.d.ts → execution.d.ts} +4 -26
- package/dist/execution.d.ts.map +1 -0
- package/dist/{execution/execution.js → execution.js} +4 -5
- package/dist/execution.test.d.ts.map +1 -0
- package/dist/{execution/execution.test.js → execution.test.js} +4 -5
- package/dist/factory.d.ts +74 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +72 -0
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -5
- package/dist/internal.d.ts +7 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/node-sqlite/backend.d.ts +52 -0
- package/dist/node-sqlite/backend.d.ts.map +1 -0
- package/dist/node-sqlite/backend.js +673 -0
- package/dist/node-sqlite/index.d.ts +11 -0
- package/dist/node-sqlite/index.d.ts.map +1 -0
- package/dist/node-sqlite/index.js +7 -0
- package/dist/node-sqlite/sqlite.d.ts +60 -0
- package/dist/node-sqlite/sqlite.d.ts.map +1 -0
- package/dist/{backend-sqlite → node-sqlite}/sqlite.js +20 -3
- package/dist/postgres/backend.d.ts +44 -0
- package/dist/postgres/backend.d.ts.map +1 -0
- package/dist/postgres/backend.js +534 -0
- package/dist/postgres/backend.test.d.ts +2 -0
- package/dist/postgres/backend.test.d.ts.map +1 -0
- package/dist/postgres/backend.test.js +19 -0
- package/dist/postgres/driver.d.ts +81 -0
- package/dist/postgres/driver.d.ts.map +1 -0
- package/dist/postgres/driver.js +63 -0
- package/dist/postgres/index.d.ts +11 -0
- package/dist/postgres/index.d.ts.map +1 -0
- package/dist/postgres/index.js +7 -0
- package/dist/postgres/internal.d.ts +2 -0
- package/dist/postgres/internal.d.ts.map +1 -0
- package/dist/postgres/internal.js +1 -0
- package/dist/postgres/postgres.d.ts +42 -0
- package/dist/postgres/postgres.d.ts.map +1 -0
- package/dist/postgres/postgres.js +233 -0
- package/dist/postgres/postgres.test.d.ts +2 -0
- package/dist/postgres/postgres.test.d.ts.map +1 -0
- package/dist/postgres/postgres.test.js +45 -0
- package/dist/postgres/scripts/db-migrate.d.ts +2 -0
- package/dist/postgres/scripts/db-migrate.d.ts.map +1 -0
- package/dist/postgres/scripts/db-migrate.js +4 -0
- package/dist/postgres/scripts/db-reset.d.ts +2 -0
- package/dist/postgres/scripts/db-reset.d.ts.map +1 -0
- package/dist/postgres/scripts/db-reset.js +5 -0
- package/dist/postgres/scripts/squawk.d.ts +2 -0
- package/dist/postgres/scripts/squawk.d.ts.map +1 -0
- package/dist/postgres/scripts/squawk.js +16 -0
- package/dist/postgres/vitest.global-setup.d.ts +3 -0
- package/dist/postgres/vitest.global-setup.d.ts.map +1 -0
- package/dist/postgres/vitest.global-setup.js +7 -0
- package/dist/postgres.d.ts +2 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/postgres.js +1 -0
- package/dist/registry.d.ts +27 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +48 -0
- package/dist/registry.test.d.ts +2 -0
- package/dist/registry.test.d.ts.map +1 -0
- package/dist/registry.test.js +109 -0
- package/dist/{backend-sqlite → sqlite}/backend.d.ts +8 -4
- package/dist/sqlite/backend.d.ts.map +1 -0
- package/dist/{backend-sqlite → sqlite}/backend.js +35 -9
- package/dist/sqlite/backend.test.d.ts +2 -0
- package/dist/sqlite/backend.test.d.ts.map +1 -0
- package/dist/sqlite/backend.test.js +50 -0
- package/dist/sqlite/driver.d.ts +79 -0
- package/dist/sqlite/driver.d.ts.map +1 -0
- package/dist/sqlite/driver.js +62 -0
- package/dist/sqlite/index.d.ts +13 -0
- package/dist/sqlite/index.d.ts.map +1 -0
- package/dist/sqlite/index.js +11 -0
- package/dist/sqlite/internal.d.ts +2 -0
- package/dist/sqlite/internal.d.ts.map +1 -0
- package/dist/sqlite/internal.js +1 -0
- package/dist/{backend-sqlite → sqlite}/sqlite.d.ts +18 -2
- package/dist/sqlite/sqlite.d.ts.map +1 -0
- package/dist/sqlite/sqlite.js +246 -0
- package/dist/sqlite/sqlite.test.d.ts +2 -0
- package/dist/sqlite/sqlite.test.d.ts.map +1 -0
- package/dist/sqlite/sqlite.test.js +171 -0
- package/dist/sqlite.d.ts +2 -0
- package/dist/sqlite.d.ts.map +1 -0
- package/dist/sqlite.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/{worker/worker.d.ts → worker.d.ts} +11 -4
- package/dist/worker.d.ts.map +1 -0
- package/dist/{worker/worker.js → worker.js} +20 -11
- package/dist/{worker/worker.test.d.ts.map → worker.test.d.ts.map} +1 -1
- package/dist/{worker/worker.test.js → worker.test.js} +136 -22
- package/dist/workflow.d.ts +60 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +48 -0
- package/dist/workflow.test.d.ts +2 -0
- package/dist/workflow.test.d.ts.map +1 -0
- package/dist/workflow.test.js +84 -0
- package/package.json +28 -4
- package/dist/backend-sqlite/backend.d.ts.map +0 -1
- package/dist/backend-sqlite/backend.js.map +0 -1
- package/dist/backend-sqlite/index.d.ts +0 -2
- package/dist/backend-sqlite/index.d.ts.map +0 -1
- package/dist/backend-sqlite/index.js +0 -2
- package/dist/backend-sqlite/index.js.map +0 -1
- package/dist/backend-sqlite/sqlite.d.ts.map +0 -1
- package/dist/backend-sqlite/sqlite.js.map +0 -1
- package/dist/config/config.d.ts +0 -102
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -29
- package/dist/config/config.js.map +0 -1
- package/dist/config/index.d.ts +0 -3
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -2
- package/dist/config/index.js.map +0 -1
- package/dist/config.d.ts +0 -28
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -41
- package/dist/config.js.map +0 -1
- package/dist/core/backend-test-suite.d.ts +0 -22
- package/dist/core/backend-test-suite.d.ts.map +0 -1
- package/dist/core/backend-test-suite.js.map +0 -1
- package/dist/core/backend.d.ts.map +0 -1
- package/dist/core/backend.js.map +0 -1
- package/dist/core/backend.testsuite.d.ts +0 -21
- package/dist/core/backend.testsuite.d.ts.map +0 -1
- package/dist/core/backend.testsuite.js.map +0 -1
- package/dist/core/duration.js.map +0 -1
- package/dist/core/duration.test.js.map +0 -1
- package/dist/core/json.js.map +0 -1
- package/dist/core/result.js.map +0 -1
- package/dist/core/result.test.js.map +0 -1
- package/dist/core/retry.js.map +0 -1
- package/dist/core/retry.test.d.ts +0 -2
- package/dist/core/retry.test.d.ts.map +0 -1
- package/dist/core/retry.test.js +0 -36
- package/dist/core/retry.test.js.map +0 -1
- package/dist/core/schema.js.map +0 -1
- package/dist/core/step.js.map +0 -1
- package/dist/core/step.test.js.map +0 -1
- package/dist/core/workflow.js.map +0 -1
- package/dist/core/workflow.test.js.map +0 -1
- package/dist/execution/execution.d.ts.map +0 -1
- package/dist/execution/execution.js.map +0 -1
- package/dist/execution/execution.test.d.ts.map +0 -1
- package/dist/execution/execution.test.js.map +0 -1
- package/dist/global.d.ts +0 -62
- package/dist/global.d.ts.map +0 -1
- package/dist/global.js +0 -78
- package/dist/global.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/sdk/sdk.d.ts +0 -182
- package/dist/sdk/sdk.d.ts.map +0 -1
- package/dist/sdk/sdk.js.map +0 -1
- package/dist/sdk/sdk.test.d.ts +0 -2
- package/dist/sdk/sdk.test.d.ts.map +0 -1
- package/dist/sdk/sdk.test.js.map +0 -1
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/worker.js.map +0 -1
- package/dist/worker/worker.test.js.map +0 -1
- /package/dist/{execution/execution.test.d.ts → execution.test.d.ts} +0 -0
- /package/dist/{worker/worker.test.d.ts → worker.test.d.ts} +0 -0
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { OpenWorkflow } from "./client.js";
|
|
2
|
+
import { BackendPostgres } from "./postgres.js";
|
|
3
|
+
import { DEFAULT_POSTGRES_URL } from "./postgres/postgres.js";
|
|
4
|
+
import { defineWorkflowSpec } from "./workflow.js";
|
|
4
5
|
import { type as arkType } from "arktype";
|
|
5
6
|
import { randomUUID } from "node:crypto";
|
|
6
7
|
import * as v from "valibot";
|
|
7
|
-
import {
|
|
8
|
+
import { describe, expect, test } from "vitest";
|
|
8
9
|
import { number as yupNumber, object as yupObject, string as yupString, } from "yup";
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
describe("OpenWorkflow", () => {
|
|
11
|
-
let backend;
|
|
12
|
-
beforeAll(async () => {
|
|
13
|
-
backend = await BackendPostgres.connect(DEFAULT_DATABASE_URL, {
|
|
14
|
-
namespaceId: randomUUID(),
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
afterAll(async () => {
|
|
18
|
-
await backend.stop();
|
|
19
|
-
});
|
|
20
12
|
test("enqueues workflow runs via backend", async () => {
|
|
13
|
+
const backend = await createBackend();
|
|
21
14
|
const client = new OpenWorkflow({ backend });
|
|
22
15
|
const workflow = client.defineWorkflow({ name: "enqueue-test" }, noopFn);
|
|
23
16
|
await workflow.run({ docUrl: "https://example.com" });
|
|
@@ -37,6 +30,7 @@ describe("OpenWorkflow", () => {
|
|
|
37
30
|
count: z.number().int().positive(),
|
|
38
31
|
});
|
|
39
32
|
test("accepts valid input", async () => {
|
|
33
|
+
const backend = await createBackend();
|
|
40
34
|
const client = new OpenWorkflow({ backend });
|
|
41
35
|
const workflow = client.defineWorkflow({ name: "schema-zod-valid", schema }, noopFn);
|
|
42
36
|
const handle = await workflow.run({
|
|
@@ -46,6 +40,7 @@ describe("OpenWorkflow", () => {
|
|
|
46
40
|
await handle.cancel();
|
|
47
41
|
});
|
|
48
42
|
test("rejects invalid input", async () => {
|
|
43
|
+
const backend = await createBackend();
|
|
49
44
|
const client = new OpenWorkflow({ backend });
|
|
50
45
|
const workflow = client.defineWorkflow({ name: "schema-zod-invalid", schema }, noopFn);
|
|
51
46
|
await expect(workflow.run({ userId: "not-a-uuid", count: 0 })).rejects.toThrow();
|
|
@@ -57,6 +52,7 @@ describe("OpenWorkflow", () => {
|
|
|
57
52
|
platform: "'android' | 'ios'",
|
|
58
53
|
});
|
|
59
54
|
test("accepts valid input", async () => {
|
|
55
|
+
const backend = await createBackend();
|
|
60
56
|
const client = new OpenWorkflow({ backend });
|
|
61
57
|
const workflow = client.defineWorkflow({ name: "schema-arktype-valid", schema }, noopFn);
|
|
62
58
|
const handle = await workflow.run({
|
|
@@ -66,6 +62,7 @@ describe("OpenWorkflow", () => {
|
|
|
66
62
|
await handle.cancel();
|
|
67
63
|
});
|
|
68
64
|
test("rejects invalid input", async () => {
|
|
65
|
+
const backend = await createBackend();
|
|
69
66
|
const client = new OpenWorkflow({ backend });
|
|
70
67
|
const workflow = client.defineWorkflow({ name: "schema-arktype-invalid", schema }, noopFn);
|
|
71
68
|
await expect(workflow.run({ name: "Riley", platform: "web" })).rejects.toThrow();
|
|
@@ -77,6 +74,7 @@ describe("OpenWorkflow", () => {
|
|
|
77
74
|
key2: v.number(),
|
|
78
75
|
});
|
|
79
76
|
test("accepts valid input", async () => {
|
|
77
|
+
const backend = await createBackend();
|
|
80
78
|
const client = new OpenWorkflow({ backend });
|
|
81
79
|
const workflow = client.defineWorkflow({ name: "schema-valibot-valid", schema }, noopFn);
|
|
82
80
|
const handle = await workflow.run({
|
|
@@ -86,6 +84,7 @@ describe("OpenWorkflow", () => {
|
|
|
86
84
|
await handle.cancel();
|
|
87
85
|
});
|
|
88
86
|
test("rejects invalid input", async () => {
|
|
87
|
+
const backend = await createBackend();
|
|
89
88
|
const client = new OpenWorkflow({ backend });
|
|
90
89
|
const workflow = client.defineWorkflow({ name: "schema-valibot-invalid", schema }, noopFn);
|
|
91
90
|
await expect(workflow.run({ key1: "value", key2: "oops" })).rejects.toThrow();
|
|
@@ -97,6 +96,7 @@ describe("OpenWorkflow", () => {
|
|
|
97
96
|
age: yupNumber().required().integer().positive(),
|
|
98
97
|
});
|
|
99
98
|
test("accepts valid input", async () => {
|
|
99
|
+
const backend = await createBackend();
|
|
100
100
|
const client = new OpenWorkflow({ backend });
|
|
101
101
|
const workflow = client.defineWorkflow({ name: "schema-yup-valid", schema }, noopFn);
|
|
102
102
|
const handle = await workflow.run({
|
|
@@ -106,6 +106,7 @@ describe("OpenWorkflow", () => {
|
|
|
106
106
|
await handle.cancel();
|
|
107
107
|
});
|
|
108
108
|
test("rejects invalid input", async () => {
|
|
109
|
+
const backend = await createBackend();
|
|
109
110
|
const client = new OpenWorkflow({ backend });
|
|
110
111
|
const workflow = client.defineWorkflow({ name: "schema-yup-invalid", schema }, noopFn);
|
|
111
112
|
await expect(workflow.run({ name: "Mona", age: -10 })).rejects.toThrow();
|
|
@@ -113,6 +114,7 @@ describe("OpenWorkflow", () => {
|
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
116
|
test("result resolves when workflow succeeds", async () => {
|
|
117
|
+
const backend = await createBackend();
|
|
116
118
|
const client = new OpenWorkflow({ backend });
|
|
117
119
|
const workflow = client.defineWorkflow({ name: "result-success" }, noopFn);
|
|
118
120
|
const handle = await workflow.run({ value: 1 });
|
|
@@ -134,6 +136,7 @@ describe("OpenWorkflow", () => {
|
|
|
134
136
|
expect(result).toEqual({ ok: true });
|
|
135
137
|
});
|
|
136
138
|
test("result rejects when workflow fails", async () => {
|
|
139
|
+
const backend = await createBackend();
|
|
137
140
|
const client = new OpenWorkflow({ backend });
|
|
138
141
|
const workflow = client.defineWorkflow({ name: "result-failure" }, noopFn);
|
|
139
142
|
await workflow.run({ value: 1 });
|
|
@@ -158,6 +161,7 @@ describe("OpenWorkflow", () => {
|
|
|
158
161
|
expect(rescheduled?.error).toEqual({ message: "boom" });
|
|
159
162
|
});
|
|
160
163
|
test("creates workflow run with deadline", async () => {
|
|
164
|
+
const backend = await createBackend();
|
|
161
165
|
const client = new OpenWorkflow({ backend });
|
|
162
166
|
const workflow = client.defineWorkflow({ name: "deadline-test" }, noopFn);
|
|
163
167
|
const deadline = new Date(Date.now() + 60_000); // in 1 minute
|
|
@@ -166,18 +170,21 @@ describe("OpenWorkflow", () => {
|
|
|
166
170
|
expect(handle.workflowRun.deadlineAt?.getTime()).toBe(deadline.getTime());
|
|
167
171
|
});
|
|
168
172
|
test("creates workflow run with version", async () => {
|
|
173
|
+
const backend = await createBackend();
|
|
169
174
|
const client = new OpenWorkflow({ backend });
|
|
170
175
|
const workflow = client.defineWorkflow({ name: "versioned-test", version: "v2.0" }, noopFn);
|
|
171
176
|
const handle = await workflow.run({ value: 1 });
|
|
172
177
|
expect(handle.workflowRun.version).toBe("v2.0");
|
|
173
178
|
});
|
|
174
179
|
test("creates workflow run without version", async () => {
|
|
180
|
+
const backend = await createBackend();
|
|
175
181
|
const client = new OpenWorkflow({ backend });
|
|
176
182
|
const workflow = client.defineWorkflow({ name: "unversioned-test" }, noopFn);
|
|
177
183
|
const handle = await workflow.run({ value: 1 });
|
|
178
184
|
expect(handle.workflowRun.version).toBeNull();
|
|
179
185
|
});
|
|
180
186
|
test("cancels workflow run via handle", async () => {
|
|
187
|
+
const backend = await createBackend();
|
|
181
188
|
const client = new OpenWorkflow({ backend });
|
|
182
189
|
const workflow = client.defineWorkflow({ name: "cancel-test" }, noopFn);
|
|
183
190
|
const handle = await workflow.run({ value: 1 });
|
|
@@ -188,8 +195,117 @@ describe("OpenWorkflow", () => {
|
|
|
188
195
|
expect(workflowRun?.status).toBe("canceled");
|
|
189
196
|
expect(workflowRun?.finishedAt).not.toBeNull();
|
|
190
197
|
});
|
|
198
|
+
describe("defineWorkflowSpec / implementWorkflow API", () => {
|
|
199
|
+
test("defineWorkflowSpec returns a spec that can be used to schedule runs", async () => {
|
|
200
|
+
const backend = await createBackend();
|
|
201
|
+
const client = new OpenWorkflow({ backend });
|
|
202
|
+
const spec = defineWorkflowSpec({ name: "declare-test" });
|
|
203
|
+
const handle = await client.runWorkflow(spec, { message: "hello" });
|
|
204
|
+
expect(handle.workflowRun.workflowName).toBe("declare-test");
|
|
205
|
+
await handle.cancel();
|
|
206
|
+
});
|
|
207
|
+
test("implementWorkflow registers the workflow for worker execution", async () => {
|
|
208
|
+
const backend = await createBackend();
|
|
209
|
+
const client = new OpenWorkflow({ backend });
|
|
210
|
+
const spec = defineWorkflowSpec({ name: "implement-test" });
|
|
211
|
+
client.implementWorkflow(spec, ({ input }) => {
|
|
212
|
+
return { received: input };
|
|
213
|
+
});
|
|
214
|
+
const handle = await client.runWorkflow(spec, { data: 42 });
|
|
215
|
+
const worker = client.newWorker();
|
|
216
|
+
await worker.tick();
|
|
217
|
+
await sleep(100); // wait for background execution
|
|
218
|
+
const result = await handle.result();
|
|
219
|
+
expect(result).toEqual({ received: { data: 42 } });
|
|
220
|
+
});
|
|
221
|
+
test("implementWorkflow throws when workflow is already registered", async () => {
|
|
222
|
+
const backend = await createBackend();
|
|
223
|
+
const client = new OpenWorkflow({ backend });
|
|
224
|
+
const spec = defineWorkflowSpec({ name: "duplicate-test" });
|
|
225
|
+
client.implementWorkflow(spec, noopFn);
|
|
226
|
+
expect(() => {
|
|
227
|
+
client.implementWorkflow(spec, noopFn);
|
|
228
|
+
}).toThrow('Workflow "duplicate-test" is already registered');
|
|
229
|
+
});
|
|
230
|
+
test("implementWorkflow allows registering different versions of the same workflow", async () => {
|
|
231
|
+
const backend = await createBackend();
|
|
232
|
+
const client = new OpenWorkflow({ backend });
|
|
233
|
+
const specV1 = defineWorkflowSpec({
|
|
234
|
+
name: "multi-version",
|
|
235
|
+
version: "v1",
|
|
236
|
+
});
|
|
237
|
+
const specV2 = defineWorkflowSpec({
|
|
238
|
+
name: "multi-version",
|
|
239
|
+
version: "v2",
|
|
240
|
+
});
|
|
241
|
+
// no throwing...
|
|
242
|
+
client.implementWorkflow(specV1, noopFn);
|
|
243
|
+
client.implementWorkflow(specV2, noopFn);
|
|
244
|
+
});
|
|
245
|
+
test("implementWorkflow throws for same name+version combination", async () => {
|
|
246
|
+
const backend = await createBackend();
|
|
247
|
+
const client = new OpenWorkflow({ backend });
|
|
248
|
+
const spec1 = defineWorkflowSpec({
|
|
249
|
+
name: "version-duplicate",
|
|
250
|
+
version: "v1",
|
|
251
|
+
});
|
|
252
|
+
const spec2 = defineWorkflowSpec({
|
|
253
|
+
name: "version-duplicate",
|
|
254
|
+
version: "v1",
|
|
255
|
+
});
|
|
256
|
+
client.implementWorkflow(spec1, noopFn);
|
|
257
|
+
expect(() => {
|
|
258
|
+
client.implementWorkflow(spec2, noopFn);
|
|
259
|
+
}).toThrow('Workflow "version-duplicate" (version: v1) is already registered');
|
|
260
|
+
});
|
|
261
|
+
test("defineWorkflowSpec with schema validates input on runWorkflow", async () => {
|
|
262
|
+
const backend = await createBackend();
|
|
263
|
+
const client = new OpenWorkflow({ backend });
|
|
264
|
+
const schema = z.object({
|
|
265
|
+
email: z.email(),
|
|
266
|
+
});
|
|
267
|
+
const spec = defineWorkflowSpec({
|
|
268
|
+
name: "declare-schema-test",
|
|
269
|
+
schema,
|
|
270
|
+
});
|
|
271
|
+
const handle = await client.runWorkflow(spec, {
|
|
272
|
+
email: "test@example.com",
|
|
273
|
+
});
|
|
274
|
+
await handle.cancel();
|
|
275
|
+
await expect(client.runWorkflow(spec, { email: "not-an-email" })).rejects.toThrow();
|
|
276
|
+
});
|
|
277
|
+
test("defineWorkflowSpec with version sets version on workflow run", async () => {
|
|
278
|
+
const backend = await createBackend();
|
|
279
|
+
const client = new OpenWorkflow({ backend });
|
|
280
|
+
const spec = defineWorkflowSpec({
|
|
281
|
+
name: "declare-version-test",
|
|
282
|
+
version: "v1.2.3",
|
|
283
|
+
});
|
|
284
|
+
const handle = await client.runWorkflow(spec);
|
|
285
|
+
expect(handle.workflowRun.version).toBe("v1.2.3");
|
|
286
|
+
await handle.cancel();
|
|
287
|
+
});
|
|
288
|
+
test("defineWorkflow defines a workflow", async () => {
|
|
289
|
+
const backend = await createBackend();
|
|
290
|
+
const client = new OpenWorkflow({ backend });
|
|
291
|
+
const workflow = client.defineWorkflow({ name: "define-wrap-test" }, ({ input }) => ({ doubled: input.n * 2 }));
|
|
292
|
+
const handle = await workflow.run({ n: 21 });
|
|
293
|
+
const worker = client.newWorker();
|
|
294
|
+
await worker.tick();
|
|
295
|
+
await sleep(100); // wait for background execution
|
|
296
|
+
const result = await handle.result();
|
|
297
|
+
expect(result).toEqual({ doubled: 42 });
|
|
298
|
+
});
|
|
299
|
+
});
|
|
191
300
|
});
|
|
301
|
+
async function createBackend() {
|
|
302
|
+
return await BackendPostgres.connect(DEFAULT_POSTGRES_URL, {
|
|
303
|
+
namespaceId: randomUUID(), // unique namespace per test
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function sleep(ms) {
|
|
307
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
308
|
+
}
|
|
192
309
|
async function noopFn() {
|
|
193
310
|
// no-op
|
|
194
311
|
}
|
|
195
|
-
//# sourceMappingURL=sdk.test.js.map
|
package/dist/core/duration.d.ts
CHANGED
|
@@ -11,10 +11,12 @@ type Unit = Years | Months | Weeks | Days | Hours | Minutes | Seconds | Millisec
|
|
|
11
11
|
type UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Lowercase<Unit>;
|
|
12
12
|
export type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;
|
|
13
13
|
/**
|
|
14
|
-
* Parse a duration string into milliseconds.
|
|
14
|
+
* Parse a duration string into milliseconds. Examples:
|
|
15
15
|
* - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
|
|
16
16
|
* - long units: "1 millisecond", "5 seconds", "30 minutes", "2 hours", "7 days", "3 weeks", "1 year"
|
|
17
|
+
* @param str - Duration string
|
|
18
|
+
* @returns Milliseconds
|
|
17
19
|
*/
|
|
18
|
-
export declare function parseDuration(str: DurationString): Result<number
|
|
20
|
+
export declare function parseDuration(str: DurationString): Result<number>;
|
|
19
21
|
export {};
|
|
20
22
|
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../core/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;AACnD,KAAK,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;AACxC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;AACpC,KAAK,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AACjC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;AACnD,KAAK,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AAC3D,KAAK,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AAC3D,KAAK,YAAY,GAAG,cAAc,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;AAC7E,KAAK,IAAI,GACL,KAAK,GACL,MAAM,GACN,KAAK,GACL,IAAI,GACJ,KAAK,GACL,OAAO,GACP,OAAO,GACP,YAAY,CAAC;AACjB,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AACxE,MAAM,MAAM,c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AgB,aAAa,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAiEjE"}
|
package/dist/core/duration.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ok, err } from "./result.js";
|
|
2
2
|
/**
|
|
3
|
-
* Parse a duration string into milliseconds.
|
|
3
|
+
* Parse a duration string into milliseconds. Examples:
|
|
4
4
|
* - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
|
|
5
5
|
* - long units: "1 millisecond", "5 seconds", "30 minutes", "2 hours", "7 days", "3 weeks", "1 year"
|
|
6
|
+
* @param str - Duration string
|
|
7
|
+
* @returns Milliseconds
|
|
6
8
|
*/
|
|
7
9
|
export function parseDuration(str) {
|
|
8
10
|
if (typeof str !== "string") {
|
|
@@ -59,4 +61,3 @@ export function parseDuration(str) {
|
|
|
59
61
|
}
|
|
60
62
|
return ok(numValue * multiplier);
|
|
61
63
|
}
|
|
62
|
-
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JsonValue } from "./json.js";
|
|
2
|
+
export interface SerializedError {
|
|
3
|
+
name?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
stack?: string;
|
|
6
|
+
[key: string]: JsonValue;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Serialize an error to a JSON-compatible format.
|
|
10
|
+
* @param error - The error to serialize (can be Error instance or any value)
|
|
11
|
+
* @returns A JSON-serializable error object
|
|
12
|
+
*/
|
|
13
|
+
export declare function serializeError(error: unknown): SerializedError;
|
|
14
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../core/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAc9D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize an error to a JSON-compatible format.
|
|
3
|
+
* @param error - The error to serialize (can be Error instance or any value)
|
|
4
|
+
* @returns A JSON-serializable error object
|
|
5
|
+
*/
|
|
6
|
+
export function serializeError(error) {
|
|
7
|
+
if (error instanceof Error) {
|
|
8
|
+
const { name, message, stack } = error;
|
|
9
|
+
if (stack) {
|
|
10
|
+
return { name, message, stack };
|
|
11
|
+
}
|
|
12
|
+
return { name, message };
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
message: String(error),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../../core/error.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { serializeError } from "./error.js";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
describe("serializeError", () => {
|
|
4
|
+
test("serializes Error instance with name, message, and stack", () => {
|
|
5
|
+
const error = new Error("Something went wrong");
|
|
6
|
+
const result = serializeError(error);
|
|
7
|
+
expect(result.name).toBe("Error");
|
|
8
|
+
expect(result.message).toBe("Something went wrong");
|
|
9
|
+
expect(result.stack).toBeDefined();
|
|
10
|
+
expect(typeof result.stack).toBe("string");
|
|
11
|
+
});
|
|
12
|
+
test("serializes TypeError with correct name", () => {
|
|
13
|
+
const error = new TypeError("Invalid type");
|
|
14
|
+
const result = serializeError(error);
|
|
15
|
+
expect(result.name).toBe("TypeError");
|
|
16
|
+
expect(result.message).toBe("Invalid type");
|
|
17
|
+
});
|
|
18
|
+
test("serializes custom Error subclass", () => {
|
|
19
|
+
class CustomError extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "CustomError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const error = new CustomError("Custom error message");
|
|
26
|
+
const result = serializeError(error);
|
|
27
|
+
expect(result.name).toBe("CustomError");
|
|
28
|
+
expect(result.message).toBe("Custom error message");
|
|
29
|
+
});
|
|
30
|
+
test("serializes Error without stack as undefined", () => {
|
|
31
|
+
const error = new Error("No stack");
|
|
32
|
+
// @ts-expect-error testing edge case
|
|
33
|
+
error.stack = undefined;
|
|
34
|
+
const result = serializeError(error);
|
|
35
|
+
expect(result.stack).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
test("serializes string to message", () => {
|
|
38
|
+
const result = serializeError("string error");
|
|
39
|
+
expect(result.message).toBe("string error");
|
|
40
|
+
expect(result.name).toBeUndefined();
|
|
41
|
+
expect(result.stack).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
test("serializes number to message", () => {
|
|
44
|
+
const result = serializeError(42);
|
|
45
|
+
expect(result.message).toBe("42");
|
|
46
|
+
});
|
|
47
|
+
test("serializes null to message", () => {
|
|
48
|
+
const result = serializeError(null);
|
|
49
|
+
expect(result.message).toBe("null");
|
|
50
|
+
});
|
|
51
|
+
test("serializes undefined to message", () => {
|
|
52
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
53
|
+
const result = serializeError(undefined);
|
|
54
|
+
expect(result.message).toBe("undefined");
|
|
55
|
+
});
|
|
56
|
+
test("serializes object to message using String()", () => {
|
|
57
|
+
const result = serializeError({ foo: "bar" });
|
|
58
|
+
expect(result.message).toBe("[object Object]");
|
|
59
|
+
});
|
|
60
|
+
});
|
package/dist/core/json.js
CHANGED
package/dist/core/result.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
export type Result<T
|
|
1
|
+
export type Result<T> = Ok<T> | Err;
|
|
2
2
|
export interface Ok<T> {
|
|
3
3
|
ok: true;
|
|
4
4
|
value: T;
|
|
5
5
|
}
|
|
6
|
-
export interface Err
|
|
6
|
+
export interface Err {
|
|
7
7
|
ok: false;
|
|
8
|
-
error:
|
|
8
|
+
error: Error;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Create an Ok result.
|
|
12
|
+
* @param value - Result value
|
|
13
|
+
* @returns Ok result
|
|
14
|
+
*/
|
|
10
15
|
export declare function ok<T>(value: T): Ok<T>;
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Create an Err result.
|
|
18
|
+
* @param error - Result error
|
|
19
|
+
* @returns Err result
|
|
20
|
+
*/
|
|
21
|
+
export declare function err(error: Readonly<Error>): Err;
|
|
12
22
|
//# sourceMappingURL=result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../core/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../core/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAEpC,MAAM,WAAW,EAAE,CAAC,CAAC;IACnB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAErC;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAE/C"}
|
package/dist/core/result.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an Ok result.
|
|
3
|
+
* @param value - Result value
|
|
4
|
+
* @returns Ok result
|
|
5
|
+
*/
|
|
1
6
|
export function ok(value) {
|
|
2
7
|
return { ok: true, value };
|
|
3
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Create an Err result.
|
|
11
|
+
* @param error - Result error
|
|
12
|
+
* @returns Err result
|
|
13
|
+
*/
|
|
4
14
|
export function err(error) {
|
|
5
15
|
return { ok: false, error };
|
|
6
16
|
}
|
|
7
|
-
//# sourceMappingURL=result.js.map
|
package/dist/core/result.test.js
CHANGED
|
@@ -5,7 +5,7 @@ describe("Result helpers", () => {
|
|
|
5
5
|
expect(ok(123)).toEqual({ ok: true, value: 123 });
|
|
6
6
|
});
|
|
7
7
|
test("err creates error result", () => {
|
|
8
|
-
|
|
8
|
+
const error = new Error("oops");
|
|
9
|
+
expect(err(error)).toEqual({ ok: false, error });
|
|
9
10
|
});
|
|
10
11
|
});
|
|
11
|
-
//# sourceMappingURL=result.test.js.map
|
package/dist/core/retry.d.ts
CHANGED
|
@@ -4,13 +4,4 @@ export declare const DEFAULT_RETRY_POLICY: {
|
|
|
4
4
|
readonly maximumIntervalMs: number;
|
|
5
5
|
readonly maximumAttempts: number;
|
|
6
6
|
};
|
|
7
|
-
export type RetryPolicy = typeof DEFAULT_RETRY_POLICY;
|
|
8
|
-
/**
|
|
9
|
-
* Calculate the next retry delay using exponential backoff.
|
|
10
|
-
*/
|
|
11
|
-
export declare function calculateRetryDelayMs(attemptNumber: number): number;
|
|
12
|
-
/**
|
|
13
|
-
* Check if an operation should be retried based on the retry policy.
|
|
14
|
-
*/
|
|
15
|
-
export declare function shouldRetry(retryPolicy: RetryPolicy, attemptNumber: number): boolean;
|
|
16
7
|
//# sourceMappingURL=retry.d.ts.map
|
package/dist/core/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../core/retry.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../core/retry.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC"}
|
package/dist/core/retry.js
CHANGED
|
@@ -4,18 +4,3 @@ export const DEFAULT_RETRY_POLICY = {
|
|
|
4
4
|
maximumIntervalMs: 100 * 1000, // 100s
|
|
5
5
|
maximumAttempts: Infinity, // unlimited
|
|
6
6
|
};
|
|
7
|
-
/**
|
|
8
|
-
* Calculate the next retry delay using exponential backoff.
|
|
9
|
-
*/
|
|
10
|
-
export function calculateRetryDelayMs(attemptNumber) {
|
|
11
|
-
const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;
|
|
12
|
-
const backoffMs = initialIntervalMs * Math.pow(backoffCoefficient, attemptNumber - 1);
|
|
13
|
-
return Math.min(backoffMs, maximumIntervalMs);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Check if an operation should be retried based on the retry policy.
|
|
17
|
-
*/
|
|
18
|
-
export function shouldRetry(retryPolicy, attemptNumber) {
|
|
19
|
-
return attemptNumber < retryPolicy.maximumAttempts;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=retry.js.map
|
package/dist/core/schema.js
CHANGED
package/dist/core/step.d.ts
CHANGED
|
@@ -41,51 +41,23 @@ export interface StepAttempt {
|
|
|
41
41
|
* Immutable cache for step attempts, keyed by step name.
|
|
42
42
|
*/
|
|
43
43
|
export type StepAttemptCache = ReadonlyMap<string, StepAttempt>;
|
|
44
|
-
/**
|
|
45
|
-
* Serialized error format for JSON compatibility.
|
|
46
|
-
*/
|
|
47
|
-
export interface SerializedError {
|
|
48
|
-
message: string;
|
|
49
|
-
name?: string;
|
|
50
|
-
stack?: string | null;
|
|
51
|
-
[key: string]: JsonValue;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Serialize an error to a JSON-compatible format. Pure function that converts
|
|
55
|
-
* any error into a SerializedError object.
|
|
56
|
-
*
|
|
57
|
-
* @param error - The error to serialize (can be Error instance or any value)
|
|
58
|
-
* @returns A JSON-serializable error object
|
|
59
|
-
*/
|
|
60
|
-
export declare function serializeError(error: unknown): SerializedError;
|
|
61
44
|
/**
|
|
62
45
|
* Create a step attempt cache from an array of attempts. Only includes
|
|
63
46
|
* successful attempts (completed or succeeded status).
|
|
64
|
-
*
|
|
65
47
|
* @param attempts - Array of step attempts to cache
|
|
66
48
|
* @returns An immutable map of step name to successful attempt
|
|
67
49
|
*/
|
|
68
50
|
export declare function createStepAttemptCacheFromAttempts(attempts: readonly StepAttempt[]): StepAttemptCache;
|
|
69
51
|
/**
|
|
70
52
|
* Get a cached step attempt by name.
|
|
71
|
-
*
|
|
72
53
|
* @param cache - The step attempt cache
|
|
73
54
|
* @param stepName - The name of the step to look up
|
|
74
55
|
* @returns The cached attempt or undefined if not found
|
|
75
56
|
*/
|
|
76
57
|
export declare function getCachedStepAttempt(cache: StepAttemptCache, stepName: string): StepAttempt | undefined;
|
|
77
|
-
/**
|
|
78
|
-
* Check if a step attempt is cached (has completed successfully).
|
|
79
|
-
*
|
|
80
|
-
* @param cache - The step attempt cache
|
|
81
|
-
* @param stepName - The name of the step to check
|
|
82
|
-
* @returns True if the step has a cached successful result
|
|
83
|
-
*/
|
|
84
|
-
export declare function hasCompletedStep(cache: StepAttemptCache, stepName: string): boolean;
|
|
85
58
|
/**
|
|
86
59
|
* Add a step attempt to the cache (returns new cache, original unchanged). This
|
|
87
60
|
* is an immutable operation.
|
|
88
|
-
*
|
|
89
61
|
* @param cache - The existing step attempt cache
|
|
90
62
|
* @param attempt - The attempt to add
|
|
91
63
|
* @returns A new cache with the attempt added
|
|
@@ -94,22 +66,19 @@ export declare function addToStepAttemptCache(cache: StepAttemptCache, attempt:
|
|
|
94
66
|
/**
|
|
95
67
|
* Convert a step function result to a JSON-compatible value. Undefined values
|
|
96
68
|
* are converted to null for JSON serialization.
|
|
97
|
-
*
|
|
98
69
|
* @param result - The result from a step function
|
|
99
70
|
* @returns A JSON-serializable value
|
|
100
71
|
*/
|
|
101
72
|
export declare function normalizeStepOutput(result: unknown): JsonValue;
|
|
102
73
|
/**
|
|
103
74
|
* Calculate the resume time for a sleep step.
|
|
104
|
-
*
|
|
105
75
|
* @param duration - The duration string to sleep for
|
|
106
76
|
* @param now - The current timestamp (defaults to Date.now())
|
|
107
77
|
* @returns A Result containing the resume Date or an Error
|
|
108
78
|
*/
|
|
109
|
-
export declare function calculateSleepResumeAt(duration: DurationString, now?: number): Result<Date
|
|
79
|
+
export declare function calculateSleepResumeAt(duration: DurationString, now?: number): Result<Date>;
|
|
110
80
|
/**
|
|
111
81
|
* Create the context object for a sleep step attempt.
|
|
112
|
-
*
|
|
113
82
|
* @param resumeAt - The time when the sleep should resume
|
|
114
83
|
* @returns The context object for the sleep step
|
|
115
84
|
*/
|
package/dist/core/step.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../core/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,WAAW,GACX,WAAW,GACX,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAA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