@sonamu-kit/tasks 0.0.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/.swcrc +17 -0
- package/README.md +7 -0
- package/dist/backend.d.ts +107 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +3 -0
- package/dist/backend.js.map +1 -0
- package/dist/chaos.test.d.ts +2 -0
- package/dist/chaos.test.d.ts.map +1 -0
- package/dist/chaos.test.js +92 -0
- package/dist/chaos.test.js.map +1 -0
- package/dist/client.d.ts +178 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +223 -0
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +339 -0
- package/dist/client.test.js.map +1 -0
- package/dist/config.d.ts +22 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +23 -0
- package/dist/config.js.map +1 -0
- package/dist/config.test.d.ts +2 -0
- package/dist/config.test.d.ts.map +1 -0
- package/dist/config.test.js +24 -0
- package/dist/config.test.js.map +1 -0
- package/dist/core/duration.d.ts +22 -0
- package/dist/core/duration.d.ts.map +1 -0
- package/dist/core/duration.js +64 -0
- package/dist/core/duration.js.map +1 -0
- package/dist/core/duration.test.d.ts +2 -0
- package/dist/core/duration.test.d.ts.map +1 -0
- package/dist/core/duration.test.js +265 -0
- package/dist/core/duration.test.js.map +1 -0
- package/dist/core/error.d.ts +15 -0
- package/dist/core/error.d.ts.map +1 -0
- package/dist/core/error.js +25 -0
- package/dist/core/error.js.map +1 -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 +63 -0
- package/dist/core/error.test.js.map +1 -0
- package/dist/core/json.d.ts +5 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +3 -0
- package/dist/core/json.js.map +1 -0
- package/dist/core/result.d.ts +22 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +22 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/result.test.d.ts +2 -0
- package/dist/core/result.test.d.ts.map +1 -0
- package/dist/core/result.test.js +19 -0
- package/dist/core/result.test.js.map +1 -0
- package/dist/core/retry.d.ts +21 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +25 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/retry.test.d.ts +2 -0
- package/dist/core/retry.test.d.ts.map +1 -0
- package/dist/core/retry.test.js +37 -0
- package/dist/core/retry.test.js.map +1 -0
- package/dist/core/schema.d.ts +57 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +4 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/step.d.ts +96 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +78 -0
- package/dist/core/step.js.map +1 -0
- package/dist/core/step.test.d.ts +2 -0
- package/dist/core/step.test.d.ts.map +1 -0
- package/dist/core/step.test.js +356 -0
- package/dist/core/step.test.js.map +1 -0
- package/dist/core/workflow.d.ts +78 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +46 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/core/workflow.test.d.ts +2 -0
- package/dist/core/workflow.test.d.ts.map +1 -0
- package/dist/core/workflow.test.js +172 -0
- package/dist/core/workflow.test.js.map +1 -0
- package/dist/database/backend.d.ts +60 -0
- package/dist/database/backend.d.ts.map +1 -0
- package/dist/database/backend.js +387 -0
- package/dist/database/backend.js.map +1 -0
- package/dist/database/backend.test.d.ts +2 -0
- package/dist/database/backend.test.d.ts.map +1 -0
- package/dist/database/backend.test.js +17 -0
- package/dist/database/backend.test.js.map +1 -0
- package/dist/database/backend.testsuite.d.ts +20 -0
- package/dist/database/backend.testsuite.d.ts.map +1 -0
- package/dist/database/backend.testsuite.js +1174 -0
- package/dist/database/backend.testsuite.js.map +1 -0
- package/dist/database/base.d.ts +12 -0
- package/dist/database/base.d.ts.map +1 -0
- package/dist/database/base.js +19 -0
- package/dist/database/base.js.map +1 -0
- package/dist/database/migrations/20251212000000_0_init.js +9 -0
- package/dist/database/migrations/20251212000000_0_init.js.map +1 -0
- package/dist/database/migrations/20251212000000_1_tables.js +88 -0
- package/dist/database/migrations/20251212000000_1_tables.js.map +1 -0
- package/dist/database/migrations/20251212000000_2_fk.js +48 -0
- package/dist/database/migrations/20251212000000_2_fk.js.map +1 -0
- package/dist/database/migrations/20251212000000_3_indexes.js +107 -0
- package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -0
- package/dist/database/pubsub.d.ts +17 -0
- package/dist/database/pubsub.d.ts.map +1 -0
- package/dist/database/pubsub.js +70 -0
- package/dist/database/pubsub.js.map +1 -0
- package/dist/database/pubsub.test.d.ts +2 -0
- package/dist/database/pubsub.test.d.ts.map +1 -0
- package/dist/database/pubsub.test.js +86 -0
- package/dist/database/pubsub.test.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/execution.d.ts +82 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +182 -0
- package/dist/execution.js.map +1 -0
- package/dist/execution.test.d.ts +2 -0
- package/dist/execution.test.d.ts.map +1 -0
- package/dist/execution.test.js +556 -0
- package/dist/execution.test.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +12 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -0
- package/dist/practices/01-remote-workflow.d.ts +2 -0
- package/dist/practices/01-remote-workflow.d.ts.map +1 -0
- package/dist/practices/01-remote-workflow.js +69 -0
- package/dist/practices/01-remote-workflow.js.map +1 -0
- package/dist/practices/01-remote.d.ts +2 -0
- package/dist/practices/01-remote.d.ts.map +1 -0
- package/dist/practices/01-remote.js +87 -0
- package/dist/practices/01-remote.js.map +1 -0
- package/dist/practices/02-local.d.ts +2 -0
- package/dist/practices/02-local.d.ts.map +1 -0
- package/dist/practices/02-local.js +84 -0
- package/dist/practices/02-local.js.map +1 -0
- package/dist/practices/03-local-retry.d.ts +2 -0
- package/dist/practices/03-local-retry.d.ts.map +1 -0
- package/dist/practices/03-local-retry.js +85 -0
- package/dist/practices/03-local-retry.js.map +1 -0
- package/dist/practices/04-scheduler-dispose.d.ts +2 -0
- package/dist/practices/04-scheduler-dispose.d.ts.map +1 -0
- package/dist/practices/04-scheduler-dispose.js +65 -0
- package/dist/practices/04-scheduler-dispose.js.map +1 -0
- package/dist/practices/05-router.d.ts +2 -0
- package/dist/practices/05-router.d.ts.map +1 -0
- package/dist/practices/05-router.js +80 -0
- package/dist/practices/05-router.js.map +1 -0
- package/dist/registry.d.ts +33 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +54 -0
- package/dist/registry.js.map +1 -0
- package/dist/registry.test.d.ts +2 -0
- package/dist/registry.test.d.ts.map +1 -0
- package/dist/registry.test.js +95 -0
- package/dist/registry.test.js.map +1 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +117 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/tasks/index.d.ts +4 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +5 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/local-task.d.ts +6 -0
- package/dist/tasks/local-task.d.ts.map +1 -0
- package/dist/tasks/local-task.js +95 -0
- package/dist/tasks/local-task.js.map +1 -0
- package/dist/tasks/remote-task.d.ts +11 -0
- package/dist/tasks/remote-task.d.ts.map +1 -0
- package/dist/tasks/remote-task.js +213 -0
- package/dist/tasks/remote-task.js.map +1 -0
- package/dist/tasks/shared.d.ts +8 -0
- package/dist/tasks/shared.d.ts.map +1 -0
- package/dist/tasks/shared.js +41 -0
- package/dist/tasks/shared.js.map +1 -0
- package/dist/testing/connection.d.ts +7 -0
- package/dist/testing/connection.d.ts.map +1 -0
- package/dist/testing/connection.js +38 -0
- package/dist/testing/connection.js.map +1 -0
- package/dist/types/config.d.ts +44 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/context.d.ts +18 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +4 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/events.d.ts +43 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +3 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/task-items.d.ts +12 -0
- package/dist/types/task-items.d.ts.map +1 -0
- package/dist/types/task-items.js +3 -0
- package/dist/types/task-items.js.map +1 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +8 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/worker.d.ts +61 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +206 -0
- package/dist/worker.js.map +1 -0
- package/dist/worker.test.d.ts +2 -0
- package/dist/worker.test.d.ts.map +1 -0
- package/dist/worker.test.js +1163 -0
- package/dist/worker.test.js.map +1 -0
- package/dist/workflow.d.ts +44 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +21 -0
- package/dist/workflow.js.map +1 -0
- package/dist/workflow.test.d.ts +2 -0
- package/dist/workflow.test.d.ts.map +1 -0
- package/dist/workflow.test.js +73 -0
- package/dist/workflow.test.js.map +1 -0
- package/nodemon.json +6 -0
- package/package.json +63 -0
- package/scripts/migrate.ts +11 -0
- package/src/backend.ts +133 -0
- package/src/chaos.test.ts +108 -0
- package/src/client.test.ts +297 -0
- package/src/client.ts +331 -0
- package/src/config.test.ts +23 -0
- package/src/config.ts +35 -0
- package/src/core/duration.test.ts +326 -0
- package/src/core/duration.ts +86 -0
- package/src/core/error.test.ts +77 -0
- package/src/core/error.ts +30 -0
- package/src/core/json.ts +2 -0
- package/src/core/result.test.ts +13 -0
- package/src/core/result.ts +29 -0
- package/src/core/retry.test.ts +41 -0
- package/src/core/retry.ts +29 -0
- package/src/core/schema.ts +74 -0
- package/src/core/step.test.ts +362 -0
- package/src/core/step.ts +152 -0
- package/src/core/workflow.test.ts +184 -0
- package/src/core/workflow.ts +127 -0
- package/src/database/backend.test.ts +16 -0
- package/src/database/backend.testsuite.ts +1376 -0
- package/src/database/backend.ts +655 -0
- package/src/database/base.ts +23 -0
- package/src/database/migrations/20251212000000_0_init.ts +10 -0
- package/src/database/migrations/20251212000000_1_tables.ts +54 -0
- package/src/database/migrations/20251212000000_2_fk.ts +46 -0
- package/src/database/migrations/20251212000000_3_indexes.ts +82 -0
- package/src/database/pubsub.test.ts +92 -0
- package/src/database/pubsub.ts +92 -0
- package/src/execution.test.ts +508 -0
- package/src/execution.ts +291 -0
- package/src/index.ts +7 -0
- package/src/internal.ts +11 -0
- package/src/practices/01-remote-workflow.ts +61 -0
- package/src/registry.test.ts +122 -0
- package/src/registry.ts +65 -0
- package/src/testing/connection.ts +44 -0
- package/src/worker.test.ts +1138 -0
- package/src/worker.ts +281 -0
- package/src/workflow.test.ts +68 -0
- package/src/workflow.ts +84 -0
- package/table_ddl.sql +60 -0
- package/templates/openworkflow.config.ts +22 -0
- package/tsconfig.json +40 -0
- package/tsconfig.test.json +4 -0
- package/vite.config.ts +13 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { ok } from "./result.js";
|
|
3
|
+
import { addToStepAttemptCache, calculateSleepResumeAt, createSleepContext, createStepAttemptCacheFromAttempts, getCachedStepAttempt, hasCompletedStep, normalizeStepOutput } from "./step.js";
|
|
4
|
+
describe("createStepAttemptCacheFromAttempts", ()=>{
|
|
5
|
+
test("creates empty cache from empty array", ()=>{
|
|
6
|
+
const cache = createStepAttemptCacheFromAttempts([]);
|
|
7
|
+
expect(cache.size).toBe(0);
|
|
8
|
+
});
|
|
9
|
+
test("includes completed attempts in cache", ()=>{
|
|
10
|
+
const attempt = createMockStepAttempt({
|
|
11
|
+
stepName: "step-a",
|
|
12
|
+
status: "completed",
|
|
13
|
+
output: "result"
|
|
14
|
+
});
|
|
15
|
+
const cache = createStepAttemptCacheFromAttempts([
|
|
16
|
+
attempt
|
|
17
|
+
]);
|
|
18
|
+
expect(cache.size).toBe(1);
|
|
19
|
+
expect(cache.get("step-a")).toBe(attempt);
|
|
20
|
+
});
|
|
21
|
+
test("includes succeeded attempts in cache (deprecated status)", ()=>{
|
|
22
|
+
const attempt = createMockStepAttempt({
|
|
23
|
+
stepName: "step-b",
|
|
24
|
+
status: "succeeded",
|
|
25
|
+
output: "result"
|
|
26
|
+
});
|
|
27
|
+
const cache = createStepAttemptCacheFromAttempts([
|
|
28
|
+
attempt
|
|
29
|
+
]);
|
|
30
|
+
expect(cache.size).toBe(1);
|
|
31
|
+
expect(cache.get("step-b")).toBe(attempt);
|
|
32
|
+
});
|
|
33
|
+
test("excludes running attempts from cache", ()=>{
|
|
34
|
+
const attempt = createMockStepAttempt({
|
|
35
|
+
stepName: "step-c",
|
|
36
|
+
status: "running"
|
|
37
|
+
});
|
|
38
|
+
const cache = createStepAttemptCacheFromAttempts([
|
|
39
|
+
attempt
|
|
40
|
+
]);
|
|
41
|
+
expect(cache.size).toBe(0);
|
|
42
|
+
});
|
|
43
|
+
test("excludes failed attempts from cache", ()=>{
|
|
44
|
+
const attempt = createMockStepAttempt({
|
|
45
|
+
stepName: "step-d",
|
|
46
|
+
status: "failed",
|
|
47
|
+
error: {
|
|
48
|
+
message: "failed"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const cache = createStepAttemptCacheFromAttempts([
|
|
52
|
+
attempt
|
|
53
|
+
]);
|
|
54
|
+
expect(cache.size).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
test("filters mixed statuses correctly", ()=>{
|
|
57
|
+
const attempts = [
|
|
58
|
+
createMockStepAttempt({
|
|
59
|
+
stepName: "completed-step",
|
|
60
|
+
status: "completed"
|
|
61
|
+
}),
|
|
62
|
+
createMockStepAttempt({
|
|
63
|
+
stepName: "running-step",
|
|
64
|
+
status: "running"
|
|
65
|
+
}),
|
|
66
|
+
createMockStepAttempt({
|
|
67
|
+
stepName: "failed-step",
|
|
68
|
+
status: "failed"
|
|
69
|
+
}),
|
|
70
|
+
createMockStepAttempt({
|
|
71
|
+
stepName: "succeeded-step",
|
|
72
|
+
status: "succeeded"
|
|
73
|
+
})
|
|
74
|
+
];
|
|
75
|
+
const cache = createStepAttemptCacheFromAttempts(attempts);
|
|
76
|
+
expect(cache.size).toBe(2);
|
|
77
|
+
expect(cache.has("completed-step")).toBe(true);
|
|
78
|
+
expect(cache.has("succeeded-step")).toBe(true);
|
|
79
|
+
expect(cache.has("running-step")).toBe(false);
|
|
80
|
+
expect(cache.has("failed-step")).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
test("uses step name as cache key", ()=>{
|
|
83
|
+
const attempt = createMockStepAttempt({
|
|
84
|
+
stepName: "my-unique-step-name",
|
|
85
|
+
status: "completed"
|
|
86
|
+
});
|
|
87
|
+
const cache = createStepAttemptCacheFromAttempts([
|
|
88
|
+
attempt
|
|
89
|
+
]);
|
|
90
|
+
expect(cache.get("my-unique-step-name")).toBe(attempt);
|
|
91
|
+
expect(cache.get("other-name")).toBeUndefined();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe("getCachedStepAttempt", ()=>{
|
|
95
|
+
test("returns cached attempt when present", ()=>{
|
|
96
|
+
const attempt = createMockStepAttempt({
|
|
97
|
+
stepName: "cached-step"
|
|
98
|
+
});
|
|
99
|
+
const cache = new Map([
|
|
100
|
+
[
|
|
101
|
+
"cached-step",
|
|
102
|
+
attempt
|
|
103
|
+
]
|
|
104
|
+
]);
|
|
105
|
+
const result = getCachedStepAttempt(cache, "cached-step");
|
|
106
|
+
expect(result).toBe(attempt);
|
|
107
|
+
});
|
|
108
|
+
test("returns undefined when step not in cache", ()=>{
|
|
109
|
+
const cache = new Map();
|
|
110
|
+
const result = getCachedStepAttempt(cache, "missing-step");
|
|
111
|
+
expect(result).toBeUndefined();
|
|
112
|
+
});
|
|
113
|
+
test("returns undefined for similar but different step names", ()=>{
|
|
114
|
+
const attempt = createMockStepAttempt({
|
|
115
|
+
stepName: "step-1"
|
|
116
|
+
});
|
|
117
|
+
const cache = new Map([
|
|
118
|
+
[
|
|
119
|
+
"step-1",
|
|
120
|
+
attempt
|
|
121
|
+
]
|
|
122
|
+
]);
|
|
123
|
+
expect(getCachedStepAttempt(cache, "step-2")).toBeUndefined();
|
|
124
|
+
expect(getCachedStepAttempt(cache, "Step-1")).toBeUndefined();
|
|
125
|
+
expect(getCachedStepAttempt(cache, "step-1 ")).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe("hasCompletedStep", ()=>{
|
|
129
|
+
test("returns true when step is in cache", ()=>{
|
|
130
|
+
const attempt = createMockStepAttempt({
|
|
131
|
+
stepName: "step-x"
|
|
132
|
+
});
|
|
133
|
+
const cache = new Map([
|
|
134
|
+
[
|
|
135
|
+
"step-x",
|
|
136
|
+
attempt
|
|
137
|
+
]
|
|
138
|
+
]);
|
|
139
|
+
expect(hasCompletedStep(cache, "step-x")).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
test("returns false when step is not in cache", ()=>{
|
|
142
|
+
const cache = new Map();
|
|
143
|
+
expect(hasCompletedStep(cache, "step-y")).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
test("returns false for empty cache", ()=>{
|
|
146
|
+
const cache = new Map();
|
|
147
|
+
expect(hasCompletedStep(cache, "any-step")).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("addToStepAttemptCache", ()=>{
|
|
151
|
+
test("adds attempt to empty cache", ()=>{
|
|
152
|
+
const cache = new Map();
|
|
153
|
+
const attempt = createMockStepAttempt({
|
|
154
|
+
stepName: "new-step"
|
|
155
|
+
});
|
|
156
|
+
const newCache = addToStepAttemptCache(cache, attempt);
|
|
157
|
+
expect(newCache.size).toBe(1);
|
|
158
|
+
expect(newCache.get("new-step")).toBe(attempt);
|
|
159
|
+
});
|
|
160
|
+
test("adds attempt to existing cache", ()=>{
|
|
161
|
+
const existing = createMockStepAttempt({
|
|
162
|
+
stepName: "existing-step"
|
|
163
|
+
});
|
|
164
|
+
const cache = new Map([
|
|
165
|
+
[
|
|
166
|
+
"existing-step",
|
|
167
|
+
existing
|
|
168
|
+
]
|
|
169
|
+
]);
|
|
170
|
+
const newAttempt = createMockStepAttempt({
|
|
171
|
+
stepName: "new-step"
|
|
172
|
+
});
|
|
173
|
+
const newCache = addToStepAttemptCache(cache, newAttempt);
|
|
174
|
+
expect(newCache.size).toBe(2);
|
|
175
|
+
expect(newCache.get("existing-step")).toBe(existing);
|
|
176
|
+
expect(newCache.get("new-step")).toBe(newAttempt);
|
|
177
|
+
});
|
|
178
|
+
test("does not mutate original cache (immutable)", ()=>{
|
|
179
|
+
const existing = createMockStepAttempt({
|
|
180
|
+
stepName: "existing-step"
|
|
181
|
+
});
|
|
182
|
+
const cache = new Map([
|
|
183
|
+
[
|
|
184
|
+
"existing-step",
|
|
185
|
+
existing
|
|
186
|
+
]
|
|
187
|
+
]);
|
|
188
|
+
const newAttempt = createMockStepAttempt({
|
|
189
|
+
stepName: "new-step"
|
|
190
|
+
});
|
|
191
|
+
const newCache = addToStepAttemptCache(cache, newAttempt);
|
|
192
|
+
expect(cache.size).toBe(1);
|
|
193
|
+
expect(cache.has("new-step")).toBe(false);
|
|
194
|
+
expect(newCache.size).toBe(2);
|
|
195
|
+
});
|
|
196
|
+
test("overwrites existing entry with same step name", ()=>{
|
|
197
|
+
const original = createMockStepAttempt({
|
|
198
|
+
stepName: "step",
|
|
199
|
+
output: "original"
|
|
200
|
+
});
|
|
201
|
+
const cache = new Map([
|
|
202
|
+
[
|
|
203
|
+
"step",
|
|
204
|
+
original
|
|
205
|
+
]
|
|
206
|
+
]);
|
|
207
|
+
const replacement = createMockStepAttempt({
|
|
208
|
+
stepName: "step",
|
|
209
|
+
output: "replacement"
|
|
210
|
+
});
|
|
211
|
+
const newCache = addToStepAttemptCache(cache, replacement);
|
|
212
|
+
expect(newCache.size).toBe(1);
|
|
213
|
+
expect(newCache.get("step")?.output).toBe("replacement");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
describe("normalizeStepOutput", ()=>{
|
|
217
|
+
test("passes through string values", ()=>{
|
|
218
|
+
expect(normalizeStepOutput("hello")).toBe("hello");
|
|
219
|
+
});
|
|
220
|
+
test("passes through number values", ()=>{
|
|
221
|
+
expect(normalizeStepOutput(42)).toBe(42);
|
|
222
|
+
expect(normalizeStepOutput(3.14)).toBe(3.14);
|
|
223
|
+
expect(normalizeStepOutput(0)).toBe(0);
|
|
224
|
+
expect(normalizeStepOutput(-1)).toBe(-1);
|
|
225
|
+
});
|
|
226
|
+
test("passes through boolean values", ()=>{
|
|
227
|
+
expect(normalizeStepOutput(true)).toBe(true);
|
|
228
|
+
expect(normalizeStepOutput(false)).toBe(false);
|
|
229
|
+
});
|
|
230
|
+
test("passes through null", ()=>{
|
|
231
|
+
expect(normalizeStepOutput(null)).toBeNull();
|
|
232
|
+
});
|
|
233
|
+
test("converts undefined to null", ()=>{
|
|
234
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
235
|
+
expect(normalizeStepOutput(undefined)).toBeNull();
|
|
236
|
+
});
|
|
237
|
+
test("passes through object values", ()=>{
|
|
238
|
+
const obj = {
|
|
239
|
+
foo: "bar",
|
|
240
|
+
nested: {
|
|
241
|
+
baz: 123
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
expect(normalizeStepOutput(obj)).toBe(obj);
|
|
245
|
+
});
|
|
246
|
+
test("passes through array values", ()=>{
|
|
247
|
+
const arr = [
|
|
248
|
+
1,
|
|
249
|
+
2,
|
|
250
|
+
3
|
|
251
|
+
];
|
|
252
|
+
expect(normalizeStepOutput(arr)).toBe(arr);
|
|
253
|
+
});
|
|
254
|
+
test("passes through empty object", ()=>{
|
|
255
|
+
const obj = {};
|
|
256
|
+
expect(normalizeStepOutput(obj)).toBe(obj);
|
|
257
|
+
});
|
|
258
|
+
test("passes through empty array", ()=>{
|
|
259
|
+
const arr = [];
|
|
260
|
+
expect(normalizeStepOutput(arr)).toBe(arr);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
describe("calculateSleepResumeAt", ()=>{
|
|
264
|
+
test("calculates resume time from duration string", ()=>{
|
|
265
|
+
const now = 1_000_000;
|
|
266
|
+
const result = calculateSleepResumeAt("5s", now);
|
|
267
|
+
expect(result).toEqual(ok(new Date(now + 5000)));
|
|
268
|
+
});
|
|
269
|
+
test("calculates resume time with milliseconds", ()=>{
|
|
270
|
+
const now = 1_000_000;
|
|
271
|
+
const result = calculateSleepResumeAt("500ms", now);
|
|
272
|
+
expect(result).toEqual(ok(new Date(now + 500)));
|
|
273
|
+
});
|
|
274
|
+
test("calculates resume time with minutes", ()=>{
|
|
275
|
+
const now = 1_000_000;
|
|
276
|
+
const result = calculateSleepResumeAt("2m", now);
|
|
277
|
+
expect(result).toEqual(ok(new Date(now + 2 * 60 * 1000)));
|
|
278
|
+
});
|
|
279
|
+
test("calculates resume time with hours", ()=>{
|
|
280
|
+
const now = 1_000_000;
|
|
281
|
+
const result = calculateSleepResumeAt("1h", now);
|
|
282
|
+
expect(result).toEqual(ok(new Date(now + 60 * 60 * 1000)));
|
|
283
|
+
});
|
|
284
|
+
test("uses Date.now() when now is not provided", ()=>{
|
|
285
|
+
const before = Date.now();
|
|
286
|
+
const result = calculateSleepResumeAt("1s");
|
|
287
|
+
const after = Date.now();
|
|
288
|
+
expect(result.ok).toBe(true);
|
|
289
|
+
if (result.ok) {
|
|
290
|
+
const resumeTime = result.value.getTime();
|
|
291
|
+
expect(resumeTime).toBeGreaterThanOrEqual(before + 1000);
|
|
292
|
+
expect(resumeTime).toBeLessThanOrEqual(after + 1000);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
test("returns error for invalid duration", ()=>{
|
|
296
|
+
// @ts-expect-error testing invalid input
|
|
297
|
+
const result = calculateSleepResumeAt("invalid");
|
|
298
|
+
expect(result.ok).toBe(false);
|
|
299
|
+
if (!result.ok) {
|
|
300
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
test("returns error for empty duration", ()=>{
|
|
304
|
+
// @ts-expect-error testing invalid input
|
|
305
|
+
const result = calculateSleepResumeAt("");
|
|
306
|
+
expect(result.ok).toBe(false);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
describe("createSleepContext", ()=>{
|
|
310
|
+
test("creates sleep context with ISO string timestamp", ()=>{
|
|
311
|
+
const resumeAt = new Date("2025-06-15T10:30:00.000Z");
|
|
312
|
+
const context = createSleepContext(resumeAt);
|
|
313
|
+
expect(context).toEqual({
|
|
314
|
+
kind: "sleep",
|
|
315
|
+
resumeAt: "2025-06-15T10:30:00.000Z"
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
test("preserves millisecond precision", ()=>{
|
|
319
|
+
const resumeAt = new Date("2025-01-01T00:00:00.123Z");
|
|
320
|
+
const context = createSleepContext(resumeAt);
|
|
321
|
+
expect(context.resumeAt).toBe("2025-01-01T00:00:00.123Z");
|
|
322
|
+
});
|
|
323
|
+
test("always has kind set to sleep", ()=>{
|
|
324
|
+
const resumeAt = new Date();
|
|
325
|
+
const context = createSleepContext(resumeAt);
|
|
326
|
+
expect(context.kind).toBe("sleep");
|
|
327
|
+
});
|
|
328
|
+
test("creates context from current date", ()=>{
|
|
329
|
+
const now = new Date();
|
|
330
|
+
const context = createSleepContext(now);
|
|
331
|
+
expect(context.resumeAt).toBe(now.toISOString());
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
function createMockStepAttempt(overrides = {}) {
|
|
335
|
+
return {
|
|
336
|
+
namespaceId: "default",
|
|
337
|
+
id: "step-1",
|
|
338
|
+
workflowRunId: "workflow-1",
|
|
339
|
+
stepName: "test-step",
|
|
340
|
+
kind: "function",
|
|
341
|
+
status: "completed",
|
|
342
|
+
config: {},
|
|
343
|
+
context: null,
|
|
344
|
+
output: null,
|
|
345
|
+
error: null,
|
|
346
|
+
childWorkflowRunNamespaceId: null,
|
|
347
|
+
childWorkflowRunId: null,
|
|
348
|
+
startedAt: new Date("2025-01-01T00:00:00Z"),
|
|
349
|
+
finishedAt: new Date("2025-01-01T00:00:01Z"),
|
|
350
|
+
createdAt: new Date("2025-01-01T00:00:00Z"),
|
|
351
|
+
updatedAt: new Date("2025-01-01T00:00:01Z"),
|
|
352
|
+
...overrides
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
//# sourceMappingURL=step.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/step.test.ts"],"sourcesContent":["import { describe, expect, test } from \"vitest\";\nimport { ok } from \"./result\";\nimport type { StepAttempt, StepAttemptCache } from \"./step\";\nimport {\n addToStepAttemptCache,\n calculateSleepResumeAt,\n createSleepContext,\n createStepAttemptCacheFromAttempts,\n getCachedStepAttempt,\n hasCompletedStep,\n normalizeStepOutput,\n} from \"./step\";\n\ndescribe(\"createStepAttemptCacheFromAttempts\", () => {\n test(\"creates empty cache from empty array\", () => {\n const cache = createStepAttemptCacheFromAttempts([]);\n\n expect(cache.size).toBe(0);\n });\n\n test(\"includes completed attempts in cache\", () => {\n const attempt = createMockStepAttempt({\n stepName: \"step-a\",\n status: \"completed\",\n output: \"result\",\n });\n const cache = createStepAttemptCacheFromAttempts([attempt]);\n\n expect(cache.size).toBe(1);\n expect(cache.get(\"step-a\")).toBe(attempt);\n });\n\n test(\"includes succeeded attempts in cache (deprecated status)\", () => {\n const attempt = createMockStepAttempt({\n stepName: \"step-b\",\n status: \"succeeded\",\n output: \"result\",\n });\n const cache = createStepAttemptCacheFromAttempts([attempt]);\n\n expect(cache.size).toBe(1);\n expect(cache.get(\"step-b\")).toBe(attempt);\n });\n\n test(\"excludes running attempts from cache\", () => {\n const attempt = createMockStepAttempt({\n stepName: \"step-c\",\n status: \"running\",\n });\n const cache = createStepAttemptCacheFromAttempts([attempt]);\n\n expect(cache.size).toBe(0);\n });\n\n test(\"excludes failed attempts from cache\", () => {\n const attempt = createMockStepAttempt({\n stepName: \"step-d\",\n status: \"failed\",\n error: { message: \"failed\" },\n });\n const cache = createStepAttemptCacheFromAttempts([attempt]);\n\n expect(cache.size).toBe(0);\n });\n\n test(\"filters mixed statuses correctly\", () => {\n const attempts = [\n createMockStepAttempt({\n stepName: \"completed-step\",\n status: \"completed\",\n }),\n createMockStepAttempt({ stepName: \"running-step\", status: \"running\" }),\n createMockStepAttempt({ stepName: \"failed-step\", status: \"failed\" }),\n createMockStepAttempt({\n stepName: \"succeeded-step\",\n status: \"succeeded\",\n }),\n ];\n const cache = createStepAttemptCacheFromAttempts(attempts);\n\n expect(cache.size).toBe(2);\n expect(cache.has(\"completed-step\")).toBe(true);\n expect(cache.has(\"succeeded-step\")).toBe(true);\n expect(cache.has(\"running-step\")).toBe(false);\n expect(cache.has(\"failed-step\")).toBe(false);\n });\n\n test(\"uses step name as cache key\", () => {\n const attempt = createMockStepAttempt({\n stepName: \"my-unique-step-name\",\n status: \"completed\",\n });\n const cache = createStepAttemptCacheFromAttempts([attempt]);\n\n expect(cache.get(\"my-unique-step-name\")).toBe(attempt);\n expect(cache.get(\"other-name\")).toBeUndefined();\n });\n});\n\ndescribe(\"getCachedStepAttempt\", () => {\n test(\"returns cached attempt when present\", () => {\n const attempt = createMockStepAttempt({ stepName: \"cached-step\" });\n const cache: StepAttemptCache = new Map([[\"cached-step\", attempt]]);\n\n const result = getCachedStepAttempt(cache, \"cached-step\");\n\n expect(result).toBe(attempt);\n });\n\n test(\"returns undefined when step not in cache\", () => {\n const cache: StepAttemptCache = new Map();\n\n const result = getCachedStepAttempt(cache, \"missing-step\");\n\n expect(result).toBeUndefined();\n });\n\n test(\"returns undefined for similar but different step names\", () => {\n const attempt = createMockStepAttempt({ stepName: \"step-1\" });\n const cache: StepAttemptCache = new Map([[\"step-1\", attempt]]);\n\n expect(getCachedStepAttempt(cache, \"step-2\")).toBeUndefined();\n expect(getCachedStepAttempt(cache, \"Step-1\")).toBeUndefined();\n expect(getCachedStepAttempt(cache, \"step-1 \")).toBeUndefined();\n });\n});\n\ndescribe(\"hasCompletedStep\", () => {\n test(\"returns true when step is in cache\", () => {\n const attempt = createMockStepAttempt({ stepName: \"step-x\" });\n const cache: StepAttemptCache = new Map([[\"step-x\", attempt]]);\n\n expect(hasCompletedStep(cache, \"step-x\")).toBe(true);\n });\n\n test(\"returns false when step is not in cache\", () => {\n const cache: StepAttemptCache = new Map();\n\n expect(hasCompletedStep(cache, \"step-y\")).toBe(false);\n });\n\n test(\"returns false for empty cache\", () => {\n const cache: StepAttemptCache = new Map();\n\n expect(hasCompletedStep(cache, \"any-step\")).toBe(false);\n });\n});\n\ndescribe(\"addToStepAttemptCache\", () => {\n test(\"adds attempt to empty cache\", () => {\n const cache: StepAttemptCache = new Map();\n const attempt = createMockStepAttempt({ stepName: \"new-step\" });\n\n const newCache = addToStepAttemptCache(cache, attempt);\n\n expect(newCache.size).toBe(1);\n expect(newCache.get(\"new-step\")).toBe(attempt);\n });\n\n test(\"adds attempt to existing cache\", () => {\n const existing = createMockStepAttempt({ stepName: \"existing-step\" });\n const cache: StepAttemptCache = new Map([[\"existing-step\", existing]]);\n const newAttempt = createMockStepAttempt({ stepName: \"new-step\" });\n\n const newCache = addToStepAttemptCache(cache, newAttempt);\n\n expect(newCache.size).toBe(2);\n expect(newCache.get(\"existing-step\")).toBe(existing);\n expect(newCache.get(\"new-step\")).toBe(newAttempt);\n });\n\n test(\"does not mutate original cache (immutable)\", () => {\n const existing = createMockStepAttempt({ stepName: \"existing-step\" });\n const cache: StepAttemptCache = new Map([[\"existing-step\", existing]]);\n const newAttempt = createMockStepAttempt({ stepName: \"new-step\" });\n\n const newCache = addToStepAttemptCache(cache, newAttempt);\n\n expect(cache.size).toBe(1);\n expect(cache.has(\"new-step\")).toBe(false);\n expect(newCache.size).toBe(2);\n });\n\n test(\"overwrites existing entry with same step name\", () => {\n const original = createMockStepAttempt({\n stepName: \"step\",\n output: \"original\",\n });\n const cache: StepAttemptCache = new Map([[\"step\", original]]);\n const replacement = createMockStepAttempt({\n stepName: \"step\",\n output: \"replacement\",\n });\n\n const newCache = addToStepAttemptCache(cache, replacement);\n\n expect(newCache.size).toBe(1);\n expect(newCache.get(\"step\")?.output).toBe(\"replacement\");\n });\n});\n\ndescribe(\"normalizeStepOutput\", () => {\n test(\"passes through string values\", () => {\n expect(normalizeStepOutput(\"hello\")).toBe(\"hello\");\n });\n\n test(\"passes through number values\", () => {\n expect(normalizeStepOutput(42)).toBe(42);\n expect(normalizeStepOutput(3.14)).toBe(3.14);\n expect(normalizeStepOutput(0)).toBe(0);\n expect(normalizeStepOutput(-1)).toBe(-1);\n });\n\n test(\"passes through boolean values\", () => {\n expect(normalizeStepOutput(true)).toBe(true);\n expect(normalizeStepOutput(false)).toBe(false);\n });\n\n test(\"passes through null\", () => {\n expect(normalizeStepOutput(null)).toBeNull();\n });\n\n test(\"converts undefined to null\", () => {\n // eslint-disable-next-line unicorn/no-useless-undefined\n expect(normalizeStepOutput(undefined)).toBeNull();\n });\n\n test(\"passes through object values\", () => {\n const obj = { foo: \"bar\", nested: { baz: 123 } };\n expect(normalizeStepOutput(obj)).toBe(obj);\n });\n\n test(\"passes through array values\", () => {\n const arr = [1, 2, 3];\n expect(normalizeStepOutput(arr)).toBe(arr);\n });\n\n test(\"passes through empty object\", () => {\n const obj = {};\n expect(normalizeStepOutput(obj)).toBe(obj);\n });\n\n test(\"passes through empty array\", () => {\n const arr: unknown[] = [];\n expect(normalizeStepOutput(arr)).toBe(arr);\n });\n});\n\ndescribe(\"calculateSleepResumeAt\", () => {\n test(\"calculates resume time from duration string\", () => {\n const now = 1_000_000;\n const result = calculateSleepResumeAt(\"5s\", now);\n\n expect(result).toEqual(ok(new Date(now + 5000)));\n });\n\n test(\"calculates resume time with milliseconds\", () => {\n const now = 1_000_000;\n const result = calculateSleepResumeAt(\"500ms\", now);\n\n expect(result).toEqual(ok(new Date(now + 500)));\n });\n\n test(\"calculates resume time with minutes\", () => {\n const now = 1_000_000;\n const result = calculateSleepResumeAt(\"2m\", now);\n\n expect(result).toEqual(ok(new Date(now + 2 * 60 * 1000)));\n });\n\n test(\"calculates resume time with hours\", () => {\n const now = 1_000_000;\n const result = calculateSleepResumeAt(\"1h\", now);\n\n expect(result).toEqual(ok(new Date(now + 60 * 60 * 1000)));\n });\n\n test(\"uses Date.now() when now is not provided\", () => {\n const before = Date.now();\n const result = calculateSleepResumeAt(\"1s\");\n const after = Date.now();\n\n expect(result.ok).toBe(true);\n if (result.ok) {\n const resumeTime = result.value.getTime();\n expect(resumeTime).toBeGreaterThanOrEqual(before + 1000);\n expect(resumeTime).toBeLessThanOrEqual(after + 1000);\n }\n });\n\n test(\"returns error for invalid duration\", () => {\n // @ts-expect-error testing invalid input\n const result = calculateSleepResumeAt(\"invalid\");\n\n expect(result.ok).toBe(false);\n if (!result.ok) {\n expect(result.error).toBeInstanceOf(Error);\n }\n });\n\n test(\"returns error for empty duration\", () => {\n // @ts-expect-error testing invalid input\n const result = calculateSleepResumeAt(\"\");\n\n expect(result.ok).toBe(false);\n });\n});\n\ndescribe(\"createSleepContext\", () => {\n test(\"creates sleep context with ISO string timestamp\", () => {\n const resumeAt = new Date(\"2025-06-15T10:30:00.000Z\");\n const context = createSleepContext(resumeAt);\n\n expect(context).toEqual({\n kind: \"sleep\",\n resumeAt: \"2025-06-15T10:30:00.000Z\",\n });\n });\n\n test(\"preserves millisecond precision\", () => {\n const resumeAt = new Date(\"2025-01-01T00:00:00.123Z\");\n const context = createSleepContext(resumeAt);\n\n expect(context.resumeAt).toBe(\"2025-01-01T00:00:00.123Z\");\n });\n\n test(\"always has kind set to sleep\", () => {\n const resumeAt = new Date();\n const context = createSleepContext(resumeAt);\n\n expect(context.kind).toBe(\"sleep\");\n });\n\n test(\"creates context from current date\", () => {\n const now = new Date();\n const context = createSleepContext(now);\n\n expect(context.resumeAt).toBe(now.toISOString());\n });\n});\n\nfunction createMockStepAttempt(overrides: Partial<StepAttempt> = {}): StepAttempt {\n return {\n namespaceId: \"default\",\n id: \"step-1\",\n workflowRunId: \"workflow-1\",\n stepName: \"test-step\",\n kind: \"function\",\n status: \"completed\",\n config: {},\n context: null,\n output: null,\n error: null,\n childWorkflowRunNamespaceId: null,\n childWorkflowRunId: null,\n startedAt: new Date(\"2025-01-01T00:00:00Z\"),\n finishedAt: new Date(\"2025-01-01T00:00:01Z\"),\n createdAt: new Date(\"2025-01-01T00:00:00Z\"),\n updatedAt: new Date(\"2025-01-01T00:00:01Z\"),\n ...overrides,\n };\n}\n"],"names":["describe","expect","test","ok","addToStepAttemptCache","calculateSleepResumeAt","createSleepContext","createStepAttemptCacheFromAttempts","getCachedStepAttempt","hasCompletedStep","normalizeStepOutput","cache","size","toBe","attempt","createMockStepAttempt","stepName","status","output","get","error","message","attempts","has","toBeUndefined","Map","result","newCache","existing","newAttempt","original","replacement","toBeNull","undefined","obj","foo","nested","baz","arr","now","toEqual","Date","before","after","resumeTime","value","getTime","toBeGreaterThanOrEqual","toBeLessThanOrEqual","toBeInstanceOf","Error","resumeAt","context","kind","toISOString","overrides","namespaceId","id","workflowRunId","config","childWorkflowRunNamespaceId","childWorkflowRunId","startedAt","finishedAt","createdAt","updatedAt"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AAChD,SAASC,EAAE,QAAQ,cAAW;AAE9B,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,kBAA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,mBAAmBiC;QAEnCtC,OAAOmD,QAAQD,QAAQ,EAAEtC,IAAI,CAAC0B,IAAIe,WAAW;IAC/C;AACF;AAEA,SAASvC,sBAAsBwC,YAAkC,CAAC,CAAC;IACjE,OAAO;QACLC,aAAa;QACbC,IAAI;QACJC,eAAe;QACf1C,UAAU;QACVqC,MAAM;QACNpC,QAAQ;QACR0C,QAAQ,CAAC;QACTP,SAAS;QACTlC,QAAQ;QACRE,OAAO;QACPwC,6BAA6B;QAC7BC,oBAAoB;QACpBC,WAAW,IAAIrB,KAAK;QACpBsB,YAAY,IAAItB,KAAK;QACrBuB,WAAW,IAAIvB,KAAK;QACpBwB,WAAW,IAAIxB,KAAK;QACpB,GAAGc,SAAS;IACd;AACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { SerializedError } from "./error";
|
|
2
|
+
import type { JsonValue } from "./json";
|
|
3
|
+
import type { StandardSchemaV1 } from "./schema";
|
|
4
|
+
/**
|
|
5
|
+
* Status of a workflow run through its lifecycle.
|
|
6
|
+
*/
|
|
7
|
+
export type WorkflowRunStatus = "pending" | "running" | "sleeping" | "succeeded" | "completed" | "failed" | "canceled";
|
|
8
|
+
/**
|
|
9
|
+
* WorkflowRun represents a single execution instance of a workflow.
|
|
10
|
+
*/
|
|
11
|
+
export interface WorkflowRun {
|
|
12
|
+
namespaceId: string;
|
|
13
|
+
id: string;
|
|
14
|
+
workflowName: string;
|
|
15
|
+
version: string | null;
|
|
16
|
+
status: WorkflowRunStatus;
|
|
17
|
+
idempotencyKey: string | null;
|
|
18
|
+
config: JsonValue;
|
|
19
|
+
context: JsonValue | null;
|
|
20
|
+
input: JsonValue | null;
|
|
21
|
+
output: JsonValue | null;
|
|
22
|
+
error: SerializedError | null;
|
|
23
|
+
attempts: number;
|
|
24
|
+
parentStepAttemptNamespaceId: string | null;
|
|
25
|
+
parentStepAttemptId: string | null;
|
|
26
|
+
workerId: string | null;
|
|
27
|
+
availableAt: Date | null;
|
|
28
|
+
deadlineAt: Date | null;
|
|
29
|
+
startedAt: Date | null;
|
|
30
|
+
finishedAt: Date | null;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
updatedAt: Date;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Infers the input type from a Standard Schema.
|
|
36
|
+
*/
|
|
37
|
+
export type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : Fallback;
|
|
38
|
+
/**
|
|
39
|
+
* Infers the output type from a Standard Schema.
|
|
40
|
+
*/
|
|
41
|
+
export type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : Fallback;
|
|
42
|
+
/**
|
|
43
|
+
* Result of input validation - either success with a value or failure with an
|
|
44
|
+
* error message.
|
|
45
|
+
*/
|
|
46
|
+
export type ValidationResult<T> = {
|
|
47
|
+
success: true;
|
|
48
|
+
value: T;
|
|
49
|
+
} | {
|
|
50
|
+
success: false;
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Default configuration for result polling when awaiting workflow completion.
|
|
55
|
+
*/
|
|
56
|
+
export declare const DEFAULT_WORKFLOW_RESULT_CONFIG: {
|
|
57
|
+
/** Polling interval in milliseconds (1 second) */
|
|
58
|
+
readonly pollIntervalMs: 1000;
|
|
59
|
+
/** Timeout in milliseconds (5 minutes) */
|
|
60
|
+
readonly timeoutMs: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Validate input against a Standard Schema. Pure async function that validates
|
|
64
|
+
* input and returns a ValidationResult.
|
|
65
|
+
* @param schema - The Standard Schema to validate against (or null/undefined
|
|
66
|
+
* for no validation)
|
|
67
|
+
* @param input - The input value to validate
|
|
68
|
+
* @returns A ValidationResult containing either the validated value or an error
|
|
69
|
+
* message
|
|
70
|
+
*/
|
|
71
|
+
export declare function validateInput<RunInput, Input>(schema: StandardSchemaV1<RunInput, Input> | null | undefined, input: RunInput | undefined): Promise<ValidationResult<Input>>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a workflow run status represents a terminal state.
|
|
74
|
+
* @param status - The workflow run status
|
|
75
|
+
* @returns True if the status is terminal (completed, failed, or canceled)
|
|
76
|
+
*/
|
|
77
|
+
export declare function isTerminalStatus(status: string): status is "succeeded" | "completed" | "failed" | "canceled";
|
|
78
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/core/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,SAAS,GACT,UAAU,GACV,WAAW,GACX,WAAW,GACX,QAAQ,GACR,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,mBAAmB,EAAE,MAAM,GAAG,IAAI,CA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AU,CAI7D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration for result polling when awaiting workflow completion.
|
|
3
|
+
*/ export const DEFAULT_WORKFLOW_RESULT_CONFIG = {
|
|
4
|
+
/** Polling interval in milliseconds (1 second) */ pollIntervalMs: 1000,
|
|
5
|
+
/** Timeout in milliseconds (5 minutes) */ timeoutMs: 5 * 60 * 1000
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Validate input against a Standard Schema. Pure async function that validates
|
|
9
|
+
* input and returns a ValidationResult.
|
|
10
|
+
* @param schema - The Standard Schema to validate against (or null/undefined
|
|
11
|
+
* for no validation)
|
|
12
|
+
* @param input - The input value to validate
|
|
13
|
+
* @returns A ValidationResult containing either the validated value or an error
|
|
14
|
+
* message
|
|
15
|
+
*/ export async function validateInput(schema, input) {
|
|
16
|
+
// No schema means no validation - pass through as-is
|
|
17
|
+
if (!schema) {
|
|
18
|
+
return {
|
|
19
|
+
success: true,
|
|
20
|
+
value: input
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Validate using Standard Schema v1 protocol https://standardschema.dev
|
|
24
|
+
const result = schema["~standard"].validate(input);
|
|
25
|
+
const resolved = await Promise.resolve(result);
|
|
26
|
+
if (resolved.issues) {
|
|
27
|
+
const messages = resolved.issues.length > 0 ? resolved.issues.map((issue)=>issue.message).join("; ") : "Validation failed";
|
|
28
|
+
return {
|
|
29
|
+
success: false,
|
|
30
|
+
error: messages
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
success: true,
|
|
35
|
+
value: resolved.value
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a workflow run status represents a terminal state.
|
|
40
|
+
* @param status - The workflow run status
|
|
41
|
+
* @returns True if the status is terminal (completed, failed, or canceled)
|
|
42
|
+
*/ export function isTerminalStatus(status) {
|
|
43
|
+
return status === "succeeded" || status === "completed" || status === "failed" || status === "canceled";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/workflow.ts"],"sourcesContent":["import type { SerializedError } from \"./error\";\nimport type { JsonValue } from \"./json\";\nimport type { StandardSchemaV1 } from \"./schema\";\n\n/**\n * Status of a workflow run through its lifecycle.\n */\nexport type WorkflowRunStatus =\n | \"pending\"\n | \"running\"\n | \"sleeping\"\n | \"succeeded\" // deprecated in favor of 'completed'\n | \"completed\"\n | \"failed\"\n | \"canceled\";\n\n/**\n * WorkflowRun represents a single execution instance of a workflow.\n */\nexport interface WorkflowRun {\n namespaceId: string;\n id: string;\n workflowName: string;\n version: string | null;\n status: WorkflowRunStatus;\n idempotencyKey: string | null;\n config: JsonValue; // user-defined config\n context: JsonValue | null; // runtime execution metadata\n input: JsonValue | null;\n output: JsonValue | null;\n error: SerializedError | null;\n attempts: number;\n parentStepAttemptNamespaceId: string | null;\n parentStepAttemptId: string | null;\n workerId: string | null;\n availableAt: Date | null;\n deadlineAt: Date | null;\n startedAt: Date | null;\n finishedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Infers the input type from a Standard Schema.\n */\nexport type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferInput<TSchema>\n : Fallback;\n\n/**\n * Infers the output type from a Standard Schema.\n */\nexport type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<TSchema>\n : Fallback;\n\n/**\n * Result of input validation - either success with a value or failure with an\n * error message.\n */\nexport type ValidationResult<T> = { success: true; value: T } | { success: false; error: string };\n\n/**\n * Default configuration for result polling when awaiting workflow completion.\n */\nexport const DEFAULT_WORKFLOW_RESULT_CONFIG = {\n /** Polling interval in milliseconds (1 second) */\n pollIntervalMs: 1000,\n /** Timeout in milliseconds (5 minutes) */\n timeoutMs: 5 * 60 * 1000,\n} as const;\n\n/**\n * Validate input against a Standard Schema. Pure async function that validates\n * input and returns a ValidationResult.\n * @param schema - The Standard Schema to validate against (or null/undefined\n * for no validation)\n * @param input - The input value to validate\n * @returns A ValidationResult containing either the validated value or an error\n * message\n */\nexport async function validateInput<RunInput, Input>(\n schema: StandardSchemaV1<RunInput, Input> | null | undefined,\n input: RunInput | undefined,\n): Promise<ValidationResult<Input>> {\n // No schema means no validation - pass through as-is\n if (!schema) {\n return {\n success: true,\n value: input as unknown as Input,\n };\n }\n\n // Validate using Standard Schema v1 protocol https://standardschema.dev\n const result = schema[\"~standard\"].validate(input);\n const resolved = await Promise.resolve(result);\n\n if (resolved.issues) {\n const messages =\n resolved.issues.length > 0\n ? resolved.issues.map((issue) => issue.message).join(\"; \")\n : \"Validation failed\";\n return {\n success: false,\n error: messages,\n };\n }\n\n return {\n success: true,\n value: resolved.value,\n };\n}\n\n/**\n * Check if a workflow run status represents a terminal state.\n * @param status - The workflow run status\n * @returns True if the status is terminal (completed, failed, or canceled)\n */\nexport function isTerminalStatus(\n status: string,\n): status is \"succeeded\" | \"completed\" | \"failed\" | \"canceled\" {\n return (\n status === \"succeeded\" || status === \"completed\" || status === \"failed\" || status === \"canceled\"\n );\n}\n"],"names":["DEFAULT_WORKFLOW_RESULT_CONFIG","pollIntervalMs","timeoutMs","validateInput","schema","input","success","value","result","validate","resolved","Promise","resolve","issues","messages","length","map","issue","message","join","error","isTerminalStatus","status"],"mappings":"AA+DA;;CAEC,GACD,OAAO,MAAMA,iCAAiC;IAC5C,gDAAgD,GAChDC,gBAAgB;IAChB,wCAAwC,GACxCC,WAAW,IAAI,KAAK;AACtB,EAAW;AAEX;;;;;;;;CAQC,GACD,OAAO,eAAeC,cACpBC,MAA4D,EAC5DC,KAA2B;IAE3B,qDAAqD;IACrD,IAAI,CAACD,QAAQ;QACX,OAAO;YACLE,SAAS;YACTC,OAAOF;QACT;IACF;IAEA,wEAAwE;IACxE,MAAMG,SAASJ,MAAM,CAAC,YAAY,CAACK,QAAQ,CAACJ;IAC5C,MAAMK,WAAW,MAAMC,QAAQC,OAAO,CAACJ;IAEvC,IAAIE,SAASG,MAAM,EAAE;QACnB,MAAMC,WACJJ,SAASG,MAAM,CAACE,MAAM,GAAG,IACrBL,SAASG,MAAM,CAACG,GAAG,CAAC,CAACC,QAAUA,MAAMC,OAAO,EAAEC,IAAI,CAAC,QACnD;QACN,OAAO;YACLb,SAAS;YACTc,OAAON;QACT;IACF;IAEA,OAAO;QACLR,SAAS;QACTC,OAAOG,SAASH,KAAK;IACvB;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASc,iBACdC,MAAc;IAEd,OACEA,WAAW,eAAeA,WAAW,eAAeA,WAAW,YAAYA,WAAW;AAE1F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.test.d.ts","sourceRoot":"","sources":["../../src/core/workflow.test.ts"],"names":[],"mappings":""}
|