@blokjs/helper 0.2.0 → 0.4.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/dist/components/AddElse.d.ts +20 -0
- package/dist/components/AddIf.d.ts +20 -0
- package/dist/components/StepNode.d.ts +6 -0
- package/dist/components/StepNode.js +9 -0
- package/dist/components/StepNode.js.map +1 -1
- package/dist/components/Trigger.d.ts +10 -2
- package/dist/components/Trigger.js +16 -5
- package/dist/components/Trigger.js.map +1 -1
- package/dist/components/branch.d.ts +44 -0
- package/dist/components/branch.js +57 -0
- package/dist/components/branch.js.map +1 -0
- package/dist/components/workflowV2.d.ts +83 -0
- package/dist/components/workflowV2.js +84 -0
- package/dist/components/workflowV2.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/dist/proxy/$.d.ts +95 -0
- package/dist/proxy/$.js +130 -0
- package/dist/proxy/$.js.map +1 -0
- package/dist/types/StepOpts.d.ts +456 -3
- package/dist/types/StepOpts.js +456 -3
- package/dist/types/StepOpts.js.map +1 -1
- package/dist/types/TriggerOpts.d.ts +1196 -19
- package/dist/types/TriggerOpts.js +395 -19
- package/dist/types/TriggerOpts.js.map +1 -1
- package/dist/types/WorkflowOpts.d.ts +312 -28
- package/dist/types/WorkflowOpts.js +55 -3
- package/dist/types/WorkflowOpts.js.map +1 -1
- package/dist/utils/parseDuration.d.ts +33 -0
- package/dist/utils/parseDuration.js +78 -0
- package/dist/utils/parseDuration.js.map +1 -0
- package/dist/workflow.schema.json +426 -0
- package/package.json +6 -6
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validation schema for the workflow envelope (v1 — legacy).
|
|
4
|
+
*
|
|
5
|
+
* Note: `trigger` is intentionally permissive (`unknown` value) at this layer
|
|
6
|
+
* because per-kind validation lives in {@link Trigger.addTrigger} via
|
|
7
|
+
* `validateTriggerConfig`. Tightening it here would force the legacy HTTP
|
|
8
|
+
* shape onto every trigger kind.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Prefer {@link WorkflowV2Schema}. v1 shapes are still accepted
|
|
11
|
+
* and normalized at workflow load time.
|
|
12
|
+
*/
|
|
2
13
|
export declare const WorkflowOptsSchema: z.ZodObject<{
|
|
3
14
|
name: z.ZodString;
|
|
4
15
|
version: z.ZodString;
|
|
@@ -9,36 +20,33 @@ export declare const WorkflowOptsSchema: z.ZodObject<{
|
|
|
9
20
|
type: z.ZodEnum<["local", "module", "runtime.python3", "runtime.nodejs", "runtime.bun", "runtime.go", "runtime.java", "runtime.rust", "runtime.php", "runtime.csharp", "runtime.ruby", "runtime.docker", "runtime.wasm"]>;
|
|
10
21
|
inputs: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
11
22
|
runtime: z.ZodOptional<z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>>;
|
|
23
|
+
set_var: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
active: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
stop: z.ZodOptional<z.ZodBoolean>;
|
|
26
|
+
stream_logs: z.ZodOptional<z.ZodBoolean>;
|
|
12
27
|
}, "strip", z.ZodTypeAny, {
|
|
13
28
|
name: string;
|
|
14
29
|
node: string;
|
|
15
30
|
type: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm";
|
|
16
31
|
inputs?: {} | undefined;
|
|
17
32
|
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
33
|
+
set_var?: boolean | undefined;
|
|
34
|
+
active?: boolean | undefined;
|
|
35
|
+
stop?: boolean | undefined;
|
|
36
|
+
stream_logs?: boolean | undefined;
|
|
18
37
|
}, {
|
|
19
38
|
name: string;
|
|
20
39
|
node: string;
|
|
21
40
|
type: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm";
|
|
22
41
|
inputs?: {} | undefined;
|
|
23
42
|
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
43
|
+
set_var?: boolean | undefined;
|
|
44
|
+
active?: boolean | undefined;
|
|
45
|
+
stop?: boolean | undefined;
|
|
46
|
+
stream_logs?: boolean | undefined;
|
|
24
47
|
}>, "many">>;
|
|
25
48
|
nodes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>>;
|
|
26
|
-
trigger: z.ZodOptional<z.ZodRecord<z.ZodEnum<["http", "grpc", "manual", "cron", "queue", "pubsub", "worker", "webhook", "sse", "websocket"]>, z.
|
|
27
|
-
method: z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH", "ANY"]>;
|
|
28
|
-
path: z.ZodOptional<z.ZodString>;
|
|
29
|
-
accept: z.ZodDefault<z.ZodString>;
|
|
30
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
31
|
-
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "ANY";
|
|
33
|
-
accept: string;
|
|
34
|
-
path?: string | undefined;
|
|
35
|
-
headers?: Record<string, any> | undefined;
|
|
36
|
-
}, {
|
|
37
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "ANY";
|
|
38
|
-
path?: string | undefined;
|
|
39
|
-
accept?: string | undefined;
|
|
40
|
-
headers?: Record<string, any> | undefined;
|
|
41
|
-
}>>>;
|
|
49
|
+
trigger: z.ZodOptional<z.ZodRecord<z.ZodEnum<["http", "grpc", "manual", "cron", "queue", "pubsub", "worker", "webhook", "sse", "websocket"]>, z.ZodUnknown>>;
|
|
42
50
|
}, "strip", z.ZodTypeAny, {
|
|
43
51
|
name: string;
|
|
44
52
|
version: string;
|
|
@@ -48,15 +56,14 @@ export declare const WorkflowOptsSchema: z.ZodObject<{
|
|
|
48
56
|
type: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm";
|
|
49
57
|
inputs?: {} | undefined;
|
|
50
58
|
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
59
|
+
set_var?: boolean | undefined;
|
|
60
|
+
active?: boolean | undefined;
|
|
61
|
+
stop?: boolean | undefined;
|
|
62
|
+
stream_logs?: boolean | undefined;
|
|
51
63
|
}[] | undefined;
|
|
52
64
|
description?: string | undefined;
|
|
53
65
|
nodes?: Record<string, {}> | undefined;
|
|
54
|
-
trigger?: Partial<Record<"queue" | "http" | "
|
|
55
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "ANY";
|
|
56
|
-
accept: string;
|
|
57
|
-
path?: string | undefined;
|
|
58
|
-
headers?: Record<string, any> | undefined;
|
|
59
|
-
}>> | undefined;
|
|
66
|
+
trigger?: Partial<Record<"queue" | "http" | "worker" | "grpc" | "manual" | "cron" | "pubsub" | "webhook" | "sse" | "websocket", unknown>> | undefined;
|
|
60
67
|
}, {
|
|
61
68
|
name: string;
|
|
62
69
|
version: string;
|
|
@@ -66,14 +73,291 @@ export declare const WorkflowOptsSchema: z.ZodObject<{
|
|
|
66
73
|
type: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm";
|
|
67
74
|
inputs?: {} | undefined;
|
|
68
75
|
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
76
|
+
set_var?: boolean | undefined;
|
|
77
|
+
active?: boolean | undefined;
|
|
78
|
+
stop?: boolean | undefined;
|
|
79
|
+
stream_logs?: boolean | undefined;
|
|
69
80
|
}[] | undefined;
|
|
70
81
|
description?: string | undefined;
|
|
71
82
|
nodes?: Record<string, {}> | undefined;
|
|
72
|
-
trigger?: Partial<Record<"queue" | "http" | "
|
|
73
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "ANY";
|
|
74
|
-
path?: string | undefined;
|
|
75
|
-
accept?: string | undefined;
|
|
76
|
-
headers?: Record<string, any> | undefined;
|
|
77
|
-
}>> | undefined;
|
|
83
|
+
trigger?: Partial<Record<"queue" | "http" | "worker" | "grpc" | "manual" | "cron" | "pubsub" | "webhook" | "sse" | "websocket", unknown>> | undefined;
|
|
78
84
|
}>;
|
|
79
85
|
export type WorkflowOpts = z.infer<typeof WorkflowOptsSchema>;
|
|
86
|
+
/**
|
|
87
|
+
* Validation schema for the v2 workflow envelope.
|
|
88
|
+
*
|
|
89
|
+
* Differences from v1:
|
|
90
|
+
* - No top-level `nodes{}` map — `inputs` lives directly on each step.
|
|
91
|
+
* - `steps[]` is required and contains v2 step shapes (id + use + inputs)
|
|
92
|
+
* OR branch shapes ({ id, branch: { when, then, else } }).
|
|
93
|
+
* - `trigger` is required (workflows must have at least one trigger).
|
|
94
|
+
*
|
|
95
|
+
* Backward compatibility: v1 workflows are converted to v2 at workflow load
|
|
96
|
+
* time by the runner's WorkflowNormalizer.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* {
|
|
100
|
+
* name: "World Countries",
|
|
101
|
+
* version: "1.0.0",
|
|
102
|
+
* trigger: { http: { method: "GET" } },
|
|
103
|
+
* steps: [
|
|
104
|
+
* { id: "fetch", use: "@blokjs/api-call", inputs: { url: "..." } }
|
|
105
|
+
* ]
|
|
106
|
+
* }
|
|
107
|
+
*/
|
|
108
|
+
export declare const WorkflowV2Schema: z.ZodObject<{
|
|
109
|
+
name: z.ZodString;
|
|
110
|
+
version: z.ZodString;
|
|
111
|
+
description: z.ZodOptional<z.ZodString>;
|
|
112
|
+
trigger: z.ZodRecord<z.ZodEnum<["http", "grpc", "manual", "cron", "queue", "pubsub", "worker", "webhook", "sse", "websocket"]>, z.ZodUnknown>;
|
|
113
|
+
steps: z.ZodArray<z.ZodType<{
|
|
114
|
+
id: string;
|
|
115
|
+
use: string;
|
|
116
|
+
type?: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm" | undefined;
|
|
117
|
+
inputs?: Record<string, unknown> | undefined;
|
|
118
|
+
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
119
|
+
set_var?: boolean | undefined;
|
|
120
|
+
active?: boolean | undefined;
|
|
121
|
+
stop?: boolean | undefined;
|
|
122
|
+
stream_logs?: boolean | undefined;
|
|
123
|
+
as?: string | undefined;
|
|
124
|
+
spread?: boolean | undefined;
|
|
125
|
+
ephemeral?: boolean | undefined;
|
|
126
|
+
idempotencyKey?: string | undefined;
|
|
127
|
+
idempotencyKeyTTL?: number | undefined;
|
|
128
|
+
retry?: {
|
|
129
|
+
maxAttempts: number;
|
|
130
|
+
factor?: number | undefined;
|
|
131
|
+
minTimeoutInMs?: number | undefined;
|
|
132
|
+
maxTimeoutInMs?: number | undefined;
|
|
133
|
+
} | undefined;
|
|
134
|
+
maxDuration?: string | number | undefined;
|
|
135
|
+
} | {
|
|
136
|
+
id: string;
|
|
137
|
+
branch: {
|
|
138
|
+
when: string;
|
|
139
|
+
then: unknown[];
|
|
140
|
+
else?: unknown[];
|
|
141
|
+
};
|
|
142
|
+
active?: boolean;
|
|
143
|
+
stop?: boolean;
|
|
144
|
+
} | {
|
|
145
|
+
id: string;
|
|
146
|
+
subworkflow: string;
|
|
147
|
+
inputs?: Record<string, unknown>;
|
|
148
|
+
wait?: boolean;
|
|
149
|
+
as?: string;
|
|
150
|
+
spread?: boolean;
|
|
151
|
+
ephemeral?: boolean;
|
|
152
|
+
active?: boolean;
|
|
153
|
+
stop?: boolean;
|
|
154
|
+
idempotencyKey?: string;
|
|
155
|
+
idempotencyKeyTTL?: number;
|
|
156
|
+
retry?: import("./StepOpts").RetryConfig;
|
|
157
|
+
} | {
|
|
158
|
+
id: string;
|
|
159
|
+
wait: {
|
|
160
|
+
for?: string | number | undefined;
|
|
161
|
+
until?: string | number | undefined;
|
|
162
|
+
};
|
|
163
|
+
active?: boolean | undefined;
|
|
164
|
+
stop?: boolean | undefined;
|
|
165
|
+
concurrencyKey?: undefined;
|
|
166
|
+
as?: string | undefined;
|
|
167
|
+
spread?: undefined;
|
|
168
|
+
ephemeral?: boolean | undefined;
|
|
169
|
+
idempotencyKey?: undefined;
|
|
170
|
+
retry?: undefined;
|
|
171
|
+
maxDuration?: undefined;
|
|
172
|
+
}, z.ZodTypeDef, {
|
|
173
|
+
id: string;
|
|
174
|
+
use: string;
|
|
175
|
+
type?: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm" | undefined;
|
|
176
|
+
inputs?: Record<string, unknown> | undefined;
|
|
177
|
+
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
178
|
+
set_var?: boolean | undefined;
|
|
179
|
+
active?: boolean | undefined;
|
|
180
|
+
stop?: boolean | undefined;
|
|
181
|
+
stream_logs?: boolean | undefined;
|
|
182
|
+
as?: string | undefined;
|
|
183
|
+
spread?: boolean | undefined;
|
|
184
|
+
ephemeral?: boolean | undefined;
|
|
185
|
+
idempotencyKey?: string | undefined;
|
|
186
|
+
idempotencyKeyTTL?: number | undefined;
|
|
187
|
+
retry?: {
|
|
188
|
+
maxAttempts: number;
|
|
189
|
+
factor?: number | undefined;
|
|
190
|
+
minTimeoutInMs?: number | undefined;
|
|
191
|
+
maxTimeoutInMs?: number | undefined;
|
|
192
|
+
} | undefined;
|
|
193
|
+
maxDuration?: string | number | undefined;
|
|
194
|
+
} | {
|
|
195
|
+
id: string;
|
|
196
|
+
branch: {
|
|
197
|
+
when: string;
|
|
198
|
+
then: unknown[];
|
|
199
|
+
else?: unknown[];
|
|
200
|
+
};
|
|
201
|
+
active?: boolean;
|
|
202
|
+
stop?: boolean;
|
|
203
|
+
} | {
|
|
204
|
+
id: string;
|
|
205
|
+
subworkflow: string;
|
|
206
|
+
inputs?: Record<string, unknown>;
|
|
207
|
+
wait?: boolean;
|
|
208
|
+
as?: string;
|
|
209
|
+
spread?: boolean;
|
|
210
|
+
ephemeral?: boolean;
|
|
211
|
+
active?: boolean;
|
|
212
|
+
stop?: boolean;
|
|
213
|
+
idempotencyKey?: string;
|
|
214
|
+
idempotencyKeyTTL?: number;
|
|
215
|
+
retry?: import("./StepOpts").RetryConfig;
|
|
216
|
+
} | {
|
|
217
|
+
id: string;
|
|
218
|
+
wait: {
|
|
219
|
+
for?: string | number | undefined;
|
|
220
|
+
until?: string | number | undefined;
|
|
221
|
+
};
|
|
222
|
+
active?: boolean | undefined;
|
|
223
|
+
stop?: boolean | undefined;
|
|
224
|
+
concurrencyKey?: undefined;
|
|
225
|
+
as?: string | undefined;
|
|
226
|
+
spread?: undefined;
|
|
227
|
+
ephemeral?: boolean | undefined;
|
|
228
|
+
idempotencyKey?: undefined;
|
|
229
|
+
retry?: undefined;
|
|
230
|
+
maxDuration?: undefined;
|
|
231
|
+
}>, "many">;
|
|
232
|
+
}, "strip", z.ZodTypeAny, {
|
|
233
|
+
name: string;
|
|
234
|
+
steps: ({
|
|
235
|
+
id: string;
|
|
236
|
+
use: string;
|
|
237
|
+
type?: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm" | undefined;
|
|
238
|
+
inputs?: Record<string, unknown> | undefined;
|
|
239
|
+
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
240
|
+
set_var?: boolean | undefined;
|
|
241
|
+
active?: boolean | undefined;
|
|
242
|
+
stop?: boolean | undefined;
|
|
243
|
+
stream_logs?: boolean | undefined;
|
|
244
|
+
as?: string | undefined;
|
|
245
|
+
spread?: boolean | undefined;
|
|
246
|
+
ephemeral?: boolean | undefined;
|
|
247
|
+
idempotencyKey?: string | undefined;
|
|
248
|
+
idempotencyKeyTTL?: number | undefined;
|
|
249
|
+
retry?: {
|
|
250
|
+
maxAttempts: number;
|
|
251
|
+
factor?: number | undefined;
|
|
252
|
+
minTimeoutInMs?: number | undefined;
|
|
253
|
+
maxTimeoutInMs?: number | undefined;
|
|
254
|
+
} | undefined;
|
|
255
|
+
maxDuration?: string | number | undefined;
|
|
256
|
+
} | {
|
|
257
|
+
id: string;
|
|
258
|
+
branch: {
|
|
259
|
+
when: string;
|
|
260
|
+
then: unknown[];
|
|
261
|
+
else?: unknown[];
|
|
262
|
+
};
|
|
263
|
+
active?: boolean;
|
|
264
|
+
stop?: boolean;
|
|
265
|
+
} | {
|
|
266
|
+
id: string;
|
|
267
|
+
subworkflow: string;
|
|
268
|
+
inputs?: Record<string, unknown>;
|
|
269
|
+
wait?: boolean;
|
|
270
|
+
as?: string;
|
|
271
|
+
spread?: boolean;
|
|
272
|
+
ephemeral?: boolean;
|
|
273
|
+
active?: boolean;
|
|
274
|
+
stop?: boolean;
|
|
275
|
+
idempotencyKey?: string;
|
|
276
|
+
idempotencyKeyTTL?: number;
|
|
277
|
+
retry?: import("./StepOpts").RetryConfig;
|
|
278
|
+
} | {
|
|
279
|
+
id: string;
|
|
280
|
+
wait: {
|
|
281
|
+
for?: string | number | undefined;
|
|
282
|
+
until?: string | number | undefined;
|
|
283
|
+
};
|
|
284
|
+
active?: boolean | undefined;
|
|
285
|
+
stop?: boolean | undefined;
|
|
286
|
+
concurrencyKey?: undefined;
|
|
287
|
+
as?: string | undefined;
|
|
288
|
+
spread?: undefined;
|
|
289
|
+
ephemeral?: boolean | undefined;
|
|
290
|
+
idempotencyKey?: undefined;
|
|
291
|
+
retry?: undefined;
|
|
292
|
+
maxDuration?: undefined;
|
|
293
|
+
})[];
|
|
294
|
+
version: string;
|
|
295
|
+
trigger: Partial<Record<"queue" | "http" | "worker" | "grpc" | "manual" | "cron" | "pubsub" | "webhook" | "sse" | "websocket", unknown>>;
|
|
296
|
+
description?: string | undefined;
|
|
297
|
+
}, {
|
|
298
|
+
name: string;
|
|
299
|
+
steps: ({
|
|
300
|
+
id: string;
|
|
301
|
+
use: string;
|
|
302
|
+
type?: "local" | "module" | "runtime.python3" | "runtime.nodejs" | "runtime.bun" | "runtime.go" | "runtime.java" | "runtime.rust" | "runtime.php" | "runtime.csharp" | "runtime.ruby" | "runtime.docker" | "runtime.wasm" | undefined;
|
|
303
|
+
inputs?: Record<string, unknown> | undefined;
|
|
304
|
+
runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
|
|
305
|
+
set_var?: boolean | undefined;
|
|
306
|
+
active?: boolean | undefined;
|
|
307
|
+
stop?: boolean | undefined;
|
|
308
|
+
stream_logs?: boolean | undefined;
|
|
309
|
+
as?: string | undefined;
|
|
310
|
+
spread?: boolean | undefined;
|
|
311
|
+
ephemeral?: boolean | undefined;
|
|
312
|
+
idempotencyKey?: string | undefined;
|
|
313
|
+
idempotencyKeyTTL?: number | undefined;
|
|
314
|
+
retry?: {
|
|
315
|
+
maxAttempts: number;
|
|
316
|
+
factor?: number | undefined;
|
|
317
|
+
minTimeoutInMs?: number | undefined;
|
|
318
|
+
maxTimeoutInMs?: number | undefined;
|
|
319
|
+
} | undefined;
|
|
320
|
+
maxDuration?: string | number | undefined;
|
|
321
|
+
} | {
|
|
322
|
+
id: string;
|
|
323
|
+
branch: {
|
|
324
|
+
when: string;
|
|
325
|
+
then: unknown[];
|
|
326
|
+
else?: unknown[];
|
|
327
|
+
};
|
|
328
|
+
active?: boolean;
|
|
329
|
+
stop?: boolean;
|
|
330
|
+
} | {
|
|
331
|
+
id: string;
|
|
332
|
+
subworkflow: string;
|
|
333
|
+
inputs?: Record<string, unknown>;
|
|
334
|
+
wait?: boolean;
|
|
335
|
+
as?: string;
|
|
336
|
+
spread?: boolean;
|
|
337
|
+
ephemeral?: boolean;
|
|
338
|
+
active?: boolean;
|
|
339
|
+
stop?: boolean;
|
|
340
|
+
idempotencyKey?: string;
|
|
341
|
+
idempotencyKeyTTL?: number;
|
|
342
|
+
retry?: import("./StepOpts").RetryConfig;
|
|
343
|
+
} | {
|
|
344
|
+
id: string;
|
|
345
|
+
wait: {
|
|
346
|
+
for?: string | number | undefined;
|
|
347
|
+
until?: string | number | undefined;
|
|
348
|
+
};
|
|
349
|
+
active?: boolean | undefined;
|
|
350
|
+
stop?: boolean | undefined;
|
|
351
|
+
concurrencyKey?: undefined;
|
|
352
|
+
as?: string | undefined;
|
|
353
|
+
spread?: undefined;
|
|
354
|
+
ephemeral?: boolean | undefined;
|
|
355
|
+
idempotencyKey?: undefined;
|
|
356
|
+
retry?: undefined;
|
|
357
|
+
maxDuration?: undefined;
|
|
358
|
+
})[];
|
|
359
|
+
version: string;
|
|
360
|
+
trigger: Partial<Record<"queue" | "http" | "worker" | "grpc" | "manual" | "cron" | "pubsub" | "webhook" | "sse" | "websocket", unknown>>;
|
|
361
|
+
description?: string | undefined;
|
|
362
|
+
}>;
|
|
363
|
+
export type WorkflowV2 = z.infer<typeof WorkflowV2Schema>;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { StepInputsSchema, StepOptsSchema } from "./StepOpts";
|
|
3
|
-
import {
|
|
2
|
+
import { StepInputsSchema, StepOptsSchema, V2StepSchema } from "./StepOpts";
|
|
3
|
+
import { TriggersSchema } from "./TriggerOpts";
|
|
4
|
+
/**
|
|
5
|
+
* Validation schema for the workflow envelope (v1 — legacy).
|
|
6
|
+
*
|
|
7
|
+
* Note: `trigger` is intentionally permissive (`unknown` value) at this layer
|
|
8
|
+
* because per-kind validation lives in {@link Trigger.addTrigger} via
|
|
9
|
+
* `validateTriggerConfig`. Tightening it here would force the legacy HTTP
|
|
10
|
+
* shape onto every trigger kind.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Prefer {@link WorkflowV2Schema}. v1 shapes are still accepted
|
|
13
|
+
* and normalized at workflow load time.
|
|
14
|
+
*/
|
|
4
15
|
export const WorkflowOptsSchema = z.object({
|
|
5
16
|
name: z
|
|
6
17
|
.string({
|
|
@@ -17,6 +28,47 @@ export const WorkflowOptsSchema = z.object({
|
|
|
17
28
|
description: z.string().optional(),
|
|
18
29
|
steps: z.array(StepOptsSchema).optional(),
|
|
19
30
|
nodes: z.record(z.string(), StepInputsSchema).optional(),
|
|
20
|
-
trigger: z.record(TriggersSchema,
|
|
31
|
+
trigger: z.record(TriggersSchema, z.unknown()).optional(),
|
|
32
|
+
});
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// V2 — Canonical workflow shape.
|
|
35
|
+
// =============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Validation schema for the v2 workflow envelope.
|
|
38
|
+
*
|
|
39
|
+
* Differences from v1:
|
|
40
|
+
* - No top-level `nodes{}` map — `inputs` lives directly on each step.
|
|
41
|
+
* - `steps[]` is required and contains v2 step shapes (id + use + inputs)
|
|
42
|
+
* OR branch shapes ({ id, branch: { when, then, else } }).
|
|
43
|
+
* - `trigger` is required (workflows must have at least one trigger).
|
|
44
|
+
*
|
|
45
|
+
* Backward compatibility: v1 workflows are converted to v2 at workflow load
|
|
46
|
+
* time by the runner's WorkflowNormalizer.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* {
|
|
50
|
+
* name: "World Countries",
|
|
51
|
+
* version: "1.0.0",
|
|
52
|
+
* trigger: { http: { method: "GET" } },
|
|
53
|
+
* steps: [
|
|
54
|
+
* { id: "fetch", use: "@blokjs/api-call", inputs: { url: "..." } }
|
|
55
|
+
* ]
|
|
56
|
+
* }
|
|
57
|
+
*/
|
|
58
|
+
export const WorkflowV2Schema = z.object({
|
|
59
|
+
name: z.string().min(3).describe("Workflow display name. Min 3 characters. Shown in Studio."),
|
|
60
|
+
version: z
|
|
61
|
+
.string()
|
|
62
|
+
.min(5, { message: "Format required x.x.x" })
|
|
63
|
+
.describe("Semantic version (x.x.x). Used for trace recording and audit."),
|
|
64
|
+
description: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("What this workflow does. Optional but recommended — surfaces in Studio and CLI."),
|
|
68
|
+
trigger: z
|
|
69
|
+
.record(TriggersSchema, z.unknown())
|
|
70
|
+
.describe("Trigger configuration. Most workflows use { http: { method: 'GET' } }. " +
|
|
71
|
+
"See TRIGGER_SCHEMAS for per-kind shapes."),
|
|
72
|
+
steps: z.array(V2StepSchema).min(1).describe("Pipeline of steps to execute in order. At least one step required."),
|
|
21
73
|
});
|
|
22
74
|
//# sourceMappingURL=WorkflowOpts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkflowOpts.js","sourceRoot":"","sources":["../../src/types/WorkflowOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"WorkflowOpts.js","sourceRoot":"","sources":["../../src/types/WorkflowOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC;SACL,MAAM,CAAC;QACP,cAAc,EAAE,kBAAkB;QAClC,kBAAkB,EAAE,uBAAuB;KAC3C,CAAC;SACD,GAAG,CAAC,CAAC,CAAC;IACR,OAAO,EAAE,CAAC;SACR,MAAM,CAAC;QACP,cAAc,EAAE,qBAAqB;QACrC,kBAAkB,EAAE,0BAA0B;KAC9C,CAAC;SACD,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;IAC9C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE;IACzC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAC,QAAQ,EAAE;IACxD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACzD,CAAC,CAAC;AAIH,gFAAgF;AAChF,iCAAiC;AACjC,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,2DAA2D,CAAC;IAC7F,OAAO,EAAE,CAAC;SACR,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;SAC5C,QAAQ,CAAC,+DAA+D,CAAC;IAC3E,WAAW,EAAE,CAAC;SACZ,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,iFAAiF,CAAC;IAC7F,OAAO,EAAE,CAAC;SACR,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SACnC,QAAQ,CACR,yEAAyE;QACxE,0CAA0C,CAC3C;IACF,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,oEAAoE,CAAC;CAClH,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a duration value to milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* Accepts:
|
|
5
|
+
* - A non-negative finite number (interpreted as milliseconds)
|
|
6
|
+
* - A single-unit string: `"500ms"`, `"30s"`, `"5m"`, `"2h"`, `"1d"`
|
|
7
|
+
*
|
|
8
|
+
* Rejects:
|
|
9
|
+
* - Negative numbers, NaN, Infinity
|
|
10
|
+
* - Empty strings, whitespace-only strings
|
|
11
|
+
* - Multi-unit strings (`"1h30m"`) — split into separate fields if needed
|
|
12
|
+
* - Fractional values (`"1.5h"`) — express as a smaller unit (`"90m"`)
|
|
13
|
+
* - Unknown units (`"5y"`)
|
|
14
|
+
*
|
|
15
|
+
* The narrow grammar is deliberate: it makes parsing predictable and
|
|
16
|
+
* round-trippable. For arbitrarily complex schedules, use the cron trigger.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* parseDuration(5000) // → 5000
|
|
20
|
+
* parseDuration("500ms") // → 500
|
|
21
|
+
* parseDuration("30s") // → 30000
|
|
22
|
+
* parseDuration("5m") // → 300000
|
|
23
|
+
* parseDuration("2h") // → 7200000
|
|
24
|
+
* parseDuration("1d") // → 86400000
|
|
25
|
+
*
|
|
26
|
+
* @throws Error with a helpful message identifying the offending input.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseDuration(input: number | string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Same as {@link parseDuration} but returns null instead of throwing on
|
|
31
|
+
* invalid input. Useful when validating user-supplied config defensively.
|
|
32
|
+
*/
|
|
33
|
+
export declare function tryParseDuration(input: unknown): number | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a duration value to milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* Accepts:
|
|
5
|
+
* - A non-negative finite number (interpreted as milliseconds)
|
|
6
|
+
* - A single-unit string: `"500ms"`, `"30s"`, `"5m"`, `"2h"`, `"1d"`
|
|
7
|
+
*
|
|
8
|
+
* Rejects:
|
|
9
|
+
* - Negative numbers, NaN, Infinity
|
|
10
|
+
* - Empty strings, whitespace-only strings
|
|
11
|
+
* - Multi-unit strings (`"1h30m"`) — split into separate fields if needed
|
|
12
|
+
* - Fractional values (`"1.5h"`) — express as a smaller unit (`"90m"`)
|
|
13
|
+
* - Unknown units (`"5y"`)
|
|
14
|
+
*
|
|
15
|
+
* The narrow grammar is deliberate: it makes parsing predictable and
|
|
16
|
+
* round-trippable. For arbitrarily complex schedules, use the cron trigger.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* parseDuration(5000) // → 5000
|
|
20
|
+
* parseDuration("500ms") // → 500
|
|
21
|
+
* parseDuration("30s") // → 30000
|
|
22
|
+
* parseDuration("5m") // → 300000
|
|
23
|
+
* parseDuration("2h") // → 7200000
|
|
24
|
+
* parseDuration("1d") // → 86400000
|
|
25
|
+
*
|
|
26
|
+
* @throws Error with a helpful message identifying the offending input.
|
|
27
|
+
*/
|
|
28
|
+
export function parseDuration(input) {
|
|
29
|
+
if (typeof input === "number") {
|
|
30
|
+
if (!Number.isFinite(input)) {
|
|
31
|
+
throw new Error(`Invalid duration: ${input} (must be a finite number).`);
|
|
32
|
+
}
|
|
33
|
+
if (input < 0) {
|
|
34
|
+
throw new Error(`Invalid duration: ${input} (must be >= 0).`);
|
|
35
|
+
}
|
|
36
|
+
// Allow fractional ms for raw numbers (e.g. precise jitter math).
|
|
37
|
+
// Floor to integer ms — sub-ms scheduling is meaningless for setTimeout.
|
|
38
|
+
return Math.floor(input);
|
|
39
|
+
}
|
|
40
|
+
if (typeof input !== "string") {
|
|
41
|
+
throw new Error(`Invalid duration: ${typeof input} (must be a number or string).`);
|
|
42
|
+
}
|
|
43
|
+
const trimmed = input.trim();
|
|
44
|
+
if (trimmed.length === 0) {
|
|
45
|
+
throw new Error("Invalid duration: empty string.");
|
|
46
|
+
}
|
|
47
|
+
// Single-unit grammar: <integer><unit>
|
|
48
|
+
// Units: ms (milliseconds), s (seconds), m (minutes), h (hours), d (days)
|
|
49
|
+
const match = /^(\d+)(ms|s|m|h|d)$/.exec(trimmed);
|
|
50
|
+
if (!match) {
|
|
51
|
+
throw new Error(`Invalid duration: ${JSON.stringify(input)}. Expected a non-negative integer followed by a unit (ms, s, m, h, d), e.g. "500ms", "30s", "5m", "2h", "1d". Multi-unit strings ("1h30m") and fractional values ("1.5h") are not supported.`);
|
|
52
|
+
}
|
|
53
|
+
const value = Number.parseInt(match[1], 10);
|
|
54
|
+
const unit = match[2];
|
|
55
|
+
const multipliers = {
|
|
56
|
+
ms: 1,
|
|
57
|
+
s: 1000,
|
|
58
|
+
m: 60_000,
|
|
59
|
+
h: 3_600_000,
|
|
60
|
+
d: 86_400_000,
|
|
61
|
+
};
|
|
62
|
+
return value * multipliers[unit];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Same as {@link parseDuration} but returns null instead of throwing on
|
|
66
|
+
* invalid input. Useful when validating user-supplied config defensively.
|
|
67
|
+
*/
|
|
68
|
+
export function tryParseDuration(input) {
|
|
69
|
+
if (typeof input !== "number" && typeof input !== "string")
|
|
70
|
+
return null;
|
|
71
|
+
try {
|
|
72
|
+
return parseDuration(input);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=parseDuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseDuration.js","sourceRoot":"","sources":["../../src/utils/parseDuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,aAAa,CAAC,KAAsB;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,6BAA6B,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,kBAAkB,CAAC,CAAC;QAC/D,CAAC;QACD,kEAAkE;QAClE,yEAAyE;QACzE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,KAAK,gCAAgC,CAAC,CAAC;IACpF,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACpD,CAAC;IAED,uCAAuC;IACvC,0EAA0E;IAC1E,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACd,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,8LAA8L,CACxO,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAEtB,MAAM,WAAW,GAA2B;QAC3C,EAAE,EAAE,CAAC;QACL,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,SAAS;QACZ,CAAC,EAAE,UAAU;KACb,CAAC;IAEF,OAAO,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxE,IAAI,CAAC;QACJ,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
|