@blokjs/helper 0.2.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.
Files changed (46) hide show
  1. package/dist/components/AddElse.d.ts +15 -0
  2. package/dist/components/AddIf.d.ts +15 -0
  3. package/dist/components/StepNode.d.ts +6 -0
  4. package/dist/components/StepNode.js +8 -0
  5. package/dist/components/StepNode.js.map +1 -1
  6. package/dist/components/Trigger.d.ts +10 -2
  7. package/dist/components/Trigger.js +16 -5
  8. package/dist/components/Trigger.js.map +1 -1
  9. package/dist/components/branch.d.ts +44 -0
  10. package/dist/components/branch.js +57 -0
  11. package/dist/components/branch.js.map +1 -0
  12. package/dist/components/forEach.d.ts +53 -0
  13. package/dist/components/forEach.js +64 -0
  14. package/dist/components/forEach.js.map +1 -0
  15. package/dist/components/loop.d.ts +52 -0
  16. package/dist/components/loop.js +54 -0
  17. package/dist/components/loop.js.map +1 -0
  18. package/dist/components/switchOn.d.ts +68 -0
  19. package/dist/components/switchOn.js +76 -0
  20. package/dist/components/switchOn.js.map +1 -0
  21. package/dist/components/tryCatch.d.ts +63 -0
  22. package/dist/components/tryCatch.js +68 -0
  23. package/dist/components/tryCatch.js.map +1 -0
  24. package/dist/components/workflowV2.d.ts +83 -0
  25. package/dist/components/workflowV2.js +84 -0
  26. package/dist/components/workflowV2.js.map +1 -0
  27. package/dist/index.d.ts +12 -3
  28. package/dist/index.js +25 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/proxy/$.d.ts +102 -0
  31. package/dist/proxy/$.js +130 -0
  32. package/dist/proxy/$.js.map +1 -0
  33. package/dist/types/StepOpts.d.ts +723 -3
  34. package/dist/types/StepOpts.js +702 -3
  35. package/dist/types/StepOpts.js.map +1 -1
  36. package/dist/types/TriggerOpts.d.ts +1600 -35
  37. package/dist/types/TriggerOpts.js +601 -29
  38. package/dist/types/TriggerOpts.js.map +1 -1
  39. package/dist/types/WorkflowOpts.d.ts +478 -28
  40. package/dist/types/WorkflowOpts.js +66 -3
  41. package/dist/types/WorkflowOpts.js.map +1 -1
  42. package/dist/utils/parseDuration.d.ts +33 -0
  43. package/dist/utils/parseDuration.js +78 -0
  44. package/dist/utils/parseDuration.js.map +1 -0
  45. package/dist/workflow.schema.json +662 -0
  46. package/package.json +6 -6
@@ -2,34 +2,53 @@ import { z } from "zod";
2
2
  import type { ConditionElseOpts } from "../components/AddElse";
3
3
  import type { ConditionOpts } from "../components/AddIf";
4
4
  /**
5
- * RuntimeKind represents all supported runtime environments
6
- * Synced with @blokjs/runner RuntimeKind type
5
+ * RuntimeKind represents all supported runtime environments.
6
+ *
7
+ * Synced with `@blokjs/runner` `RuntimeKind` type.
7
8
  */
8
9
  export declare const RuntimeKindSchema: z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>;
9
10
  export type RuntimeKind = z.infer<typeof RuntimeKindSchema>;
10
11
  /**
11
- * Node type enum - includes both legacy types and new runtime types
12
+ * Node type enum includes both legacy types and new runtime types.
12
13
  */
13
14
  export declare const NodeTypeSchema: 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"]>;
14
15
  export type NodeType = z.infer<typeof NodeTypeSchema>;
16
+ /**
17
+ * Validation schema for a single workflow step (v1 — legacy).
18
+ *
19
+ * Mirrors the JSON workflow step shape so the TypeScript DSL produces
20
+ * structurally-identical output to JSON workflows.
21
+ *
22
+ * @deprecated Prefer {@link StepV2Schema}. v1 shapes are still accepted and
23
+ * normalized at workflow load time.
24
+ */
15
25
  export declare const StepOptsSchema: z.ZodObject<{
16
26
  name: z.ZodString;
17
27
  node: z.ZodString;
18
28
  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"]>;
19
29
  inputs: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
20
30
  runtime: z.ZodOptional<z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>>;
31
+ active: z.ZodOptional<z.ZodBoolean>;
32
+ stop: z.ZodOptional<z.ZodBoolean>;
33
+ stream_logs: z.ZodOptional<z.ZodBoolean>;
21
34
  }, "strip", z.ZodTypeAny, {
22
35
  name: string;
23
36
  node: string;
24
37
  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";
25
38
  inputs?: {} | undefined;
26
39
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
40
+ active?: boolean | undefined;
41
+ stop?: boolean | undefined;
42
+ stream_logs?: boolean | undefined;
27
43
  }, {
28
44
  name: string;
29
45
  node: string;
30
46
  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";
31
47
  inputs?: {} | undefined;
32
48
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
49
+ active?: boolean | undefined;
50
+ stop?: boolean | undefined;
51
+ stream_logs?: boolean | undefined;
33
52
  }>;
34
53
  export type StepOpts = z.infer<typeof StepOptsSchema>;
35
54
  export declare const StepInputsSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
@@ -41,18 +60,27 @@ export declare const StepConditionSchema: z.ZodObject<{
41
60
  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"]>;
42
61
  inputs: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
43
62
  runtime: z.ZodOptional<z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>>;
63
+ active: z.ZodOptional<z.ZodBoolean>;
64
+ stop: z.ZodOptional<z.ZodBoolean>;
65
+ stream_logs: z.ZodOptional<z.ZodBoolean>;
44
66
  }, "strip", z.ZodTypeAny, {
45
67
  name: string;
46
68
  node: string;
47
69
  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";
48
70
  inputs?: {} | undefined;
49
71
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
72
+ active?: boolean | undefined;
73
+ stop?: boolean | undefined;
74
+ stream_logs?: boolean | undefined;
50
75
  }, {
51
76
  name: string;
52
77
  node: string;
53
78
  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";
54
79
  inputs?: {} | undefined;
55
80
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
81
+ active?: boolean | undefined;
82
+ stop?: boolean | undefined;
83
+ stream_logs?: boolean | undefined;
56
84
  }>;
57
85
  conditions: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
58
86
  }, "strip", z.ZodTypeAny, {
@@ -62,6 +90,9 @@ export declare const StepConditionSchema: z.ZodObject<{
62
90
  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";
63
91
  inputs?: {} | undefined;
64
92
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
93
+ active?: boolean | undefined;
94
+ stop?: boolean | undefined;
95
+ stream_logs?: boolean | undefined;
65
96
  };
66
97
  conditions?: ((...args: unknown[]) => unknown) | undefined;
67
98
  }, {
@@ -71,6 +102,9 @@ export declare const StepConditionSchema: z.ZodObject<{
71
102
  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";
72
103
  inputs?: {} | undefined;
73
104
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
105
+ active?: boolean | undefined;
106
+ stop?: boolean | undefined;
107
+ stream_logs?: boolean | undefined;
74
108
  };
75
109
  conditions?: ((...args: unknown[]) => unknown) | undefined;
76
110
  }>;
@@ -78,3 +112,689 @@ export interface IConditions {
78
112
  conditions: () => ConditionOpts[] | ConditionElseOpts[];
79
113
  }
80
114
  export type StepConditionOpts = z.infer<typeof StepConditionSchema>;
115
+ /**
116
+ * Retry configuration for a v2 step.
117
+ *
118
+ * Wraps `step.process(ctx, step)` in a retry loop with capped exponential
119
+ * backoff. Per-attempt failures emit `NODE_ATTEMPT_FAILED` trace events.
120
+ *
121
+ * Defaults applied by the runner when fields are omitted:
122
+ * - `minTimeoutInMs`: 1000
123
+ * - `maxTimeoutInMs`: 30000
124
+ * - `factor`: 2
125
+ *
126
+ * Shape mirrors Trigger.dev's `retry` config so authors moving between
127
+ * platforms read familiar semantics. No jitter is added — matches
128
+ * Trigger.dev's default.
129
+ */
130
+ export declare const RetryConfigSchema: z.ZodEffects<z.ZodObject<{
131
+ maxAttempts: z.ZodNumber;
132
+ minTimeoutInMs: z.ZodOptional<z.ZodNumber>;
133
+ maxTimeoutInMs: z.ZodOptional<z.ZodNumber>;
134
+ factor: z.ZodOptional<z.ZodNumber>;
135
+ }, "strip", z.ZodTypeAny, {
136
+ maxAttempts: number;
137
+ factor?: number | undefined;
138
+ minTimeoutInMs?: number | undefined;
139
+ maxTimeoutInMs?: number | undefined;
140
+ }, {
141
+ maxAttempts: number;
142
+ factor?: number | undefined;
143
+ minTimeoutInMs?: number | undefined;
144
+ maxTimeoutInMs?: number | undefined;
145
+ }>, {
146
+ maxAttempts: number;
147
+ factor?: number | undefined;
148
+ minTimeoutInMs?: number | undefined;
149
+ maxTimeoutInMs?: number | undefined;
150
+ }, {
151
+ maxAttempts: number;
152
+ factor?: number | undefined;
153
+ minTimeoutInMs?: number | undefined;
154
+ maxTimeoutInMs?: number | undefined;
155
+ }>;
156
+ export type RetryConfig = z.infer<typeof RetryConfigSchema>;
157
+ /**
158
+ * V2 regular step — invokes a node with inputs.
159
+ *
160
+ * **Identity**
161
+ * - `id` is the step's stable identifier. Other steps reference this step's
162
+ * output as `$.state[id]`.
163
+ * - `use` is the node reference (e.g. `@blokjs/api-call`).
164
+ *
165
+ * **Persistence (default-store rule)**
166
+ * Every step's `result.data` is automatically stored in `ctx.state[id]`
167
+ * after execution. This is the 95% case. The four declarative knobs:
168
+ * - `as: "<name>"` — store at `state[name]` instead of `state[id]`.
169
+ * - `spread: true` — shallow-merge keys of `result.data` into `state`
170
+ * (data-pipeline pattern). Mutually exclusive with `as`.
171
+ * - `ephemeral: true` — skip storage; only `ctx.prev` carries the result
172
+ * to the next step.
173
+ *
174
+ * @example
175
+ * { id: "fetch-users", use: "postgres-query", inputs: { sql: "..." } }
176
+ * // state["fetch-users"] = result.data
177
+ *
178
+ * @example
179
+ * { id: "step-1", use: "...", as: "users" }
180
+ * // state.users = result.data
181
+ *
182
+ * @example
183
+ * { id: "load", use: "fetch-user-and-profile", spread: true }
184
+ * // result.data = { user, profile } -> state.user + state.profile
185
+ */
186
+ export declare const V2RegularStepSchema: z.ZodEffects<z.ZodObject<{
187
+ id: z.ZodString;
188
+ use: z.ZodString;
189
+ type: z.ZodOptional<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"]>>;
190
+ inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
191
+ as: z.ZodOptional<z.ZodString>;
192
+ spread: z.ZodOptional<z.ZodBoolean>;
193
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
194
+ runtime: z.ZodOptional<z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>>;
195
+ active: z.ZodOptional<z.ZodBoolean>;
196
+ stop: z.ZodOptional<z.ZodBoolean>;
197
+ stream_logs: z.ZodOptional<z.ZodBoolean>;
198
+ idempotencyKey: z.ZodOptional<z.ZodString>;
199
+ idempotencyKeyTTL: z.ZodOptional<z.ZodNumber>;
200
+ retry: z.ZodOptional<z.ZodEffects<z.ZodObject<{
201
+ maxAttempts: z.ZodNumber;
202
+ minTimeoutInMs: z.ZodOptional<z.ZodNumber>;
203
+ maxTimeoutInMs: z.ZodOptional<z.ZodNumber>;
204
+ factor: z.ZodOptional<z.ZodNumber>;
205
+ }, "strip", z.ZodTypeAny, {
206
+ maxAttempts: number;
207
+ factor?: number | undefined;
208
+ minTimeoutInMs?: number | undefined;
209
+ maxTimeoutInMs?: number | undefined;
210
+ }, {
211
+ maxAttempts: number;
212
+ factor?: number | undefined;
213
+ minTimeoutInMs?: number | undefined;
214
+ maxTimeoutInMs?: number | undefined;
215
+ }>, {
216
+ maxAttempts: number;
217
+ factor?: number | undefined;
218
+ minTimeoutInMs?: number | undefined;
219
+ maxTimeoutInMs?: number | undefined;
220
+ }, {
221
+ maxAttempts: number;
222
+ factor?: number | undefined;
223
+ minTimeoutInMs?: number | undefined;
224
+ maxTimeoutInMs?: number | undefined;
225
+ }>>;
226
+ maxDuration: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
227
+ }, "strip", z.ZodTypeAny, {
228
+ id: string;
229
+ use: string;
230
+ 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;
231
+ inputs?: Record<string, unknown> | undefined;
232
+ runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
233
+ active?: boolean | undefined;
234
+ stop?: boolean | undefined;
235
+ stream_logs?: boolean | undefined;
236
+ idempotencyKey?: string | undefined;
237
+ as?: string | undefined;
238
+ spread?: boolean | undefined;
239
+ ephemeral?: boolean | undefined;
240
+ idempotencyKeyTTL?: number | undefined;
241
+ retry?: {
242
+ maxAttempts: number;
243
+ factor?: number | undefined;
244
+ minTimeoutInMs?: number | undefined;
245
+ maxTimeoutInMs?: number | undefined;
246
+ } | undefined;
247
+ maxDuration?: string | number | undefined;
248
+ }, {
249
+ id: string;
250
+ use: string;
251
+ 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;
252
+ inputs?: Record<string, unknown> | undefined;
253
+ runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
254
+ active?: boolean | undefined;
255
+ stop?: boolean | undefined;
256
+ stream_logs?: boolean | undefined;
257
+ idempotencyKey?: string | undefined;
258
+ as?: string | undefined;
259
+ spread?: boolean | undefined;
260
+ ephemeral?: boolean | undefined;
261
+ idempotencyKeyTTL?: number | undefined;
262
+ retry?: {
263
+ maxAttempts: number;
264
+ factor?: number | undefined;
265
+ minTimeoutInMs?: number | undefined;
266
+ maxTimeoutInMs?: number | undefined;
267
+ } | undefined;
268
+ maxDuration?: string | number | undefined;
269
+ }>, {
270
+ id: string;
271
+ use: string;
272
+ 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;
273
+ inputs?: Record<string, unknown> | undefined;
274
+ runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
275
+ active?: boolean | undefined;
276
+ stop?: boolean | undefined;
277
+ stream_logs?: boolean | undefined;
278
+ idempotencyKey?: string | undefined;
279
+ as?: string | undefined;
280
+ spread?: boolean | undefined;
281
+ ephemeral?: boolean | undefined;
282
+ idempotencyKeyTTL?: number | undefined;
283
+ retry?: {
284
+ maxAttempts: number;
285
+ factor?: number | undefined;
286
+ minTimeoutInMs?: number | undefined;
287
+ maxTimeoutInMs?: number | undefined;
288
+ } | undefined;
289
+ maxDuration?: string | number | undefined;
290
+ }, {
291
+ id: string;
292
+ use: string;
293
+ 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;
294
+ inputs?: Record<string, unknown> | undefined;
295
+ runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
296
+ active?: boolean | undefined;
297
+ stop?: boolean | undefined;
298
+ stream_logs?: boolean | undefined;
299
+ idempotencyKey?: string | undefined;
300
+ as?: string | undefined;
301
+ spread?: boolean | undefined;
302
+ ephemeral?: boolean | undefined;
303
+ idempotencyKeyTTL?: number | undefined;
304
+ retry?: {
305
+ maxAttempts: number;
306
+ factor?: number | undefined;
307
+ minTimeoutInMs?: number | undefined;
308
+ maxTimeoutInMs?: number | undefined;
309
+ } | undefined;
310
+ maxDuration?: string | number | undefined;
311
+ }>;
312
+ export type V2RegularStep = z.infer<typeof V2RegularStepSchema>;
313
+ /**
314
+ * V2 branch step — `branch({when, then, else})`.
315
+ *
316
+ * Replaces the legacy `addCondition + new AddIf().addStep().build()` pattern.
317
+ * Compiles down to the existing `@blokjs/if-else` flow node at workflow
318
+ * load time, so the runner core needs no change.
319
+ *
320
+ * @example
321
+ * {
322
+ * id: "route-by-method",
323
+ * branch: {
324
+ * when: '$.req.method === "POST"',
325
+ * then: [{ id: "create", use: "...", inputs: {...} }],
326
+ * else: [{ id: "read", use: "...", inputs: {...} }]
327
+ * }
328
+ * }
329
+ */
330
+ export declare const V2BranchStepSchema: z.ZodType<{
331
+ id: string;
332
+ branch: {
333
+ when: string;
334
+ then: unknown[];
335
+ else?: unknown[];
336
+ };
337
+ active?: boolean;
338
+ stop?: boolean;
339
+ }>;
340
+ export type V2BranchStep = z.infer<typeof V2BranchStepSchema>;
341
+ /**
342
+ * V2 sub-workflow step — invoke another named workflow inline.
343
+ *
344
+ * The parent step blocks until the child workflow completes (`wait: true`,
345
+ * the default). The child gets its own `ctx`, its own trace run record,
346
+ * and runs through the same `RunnerSteps` machinery as a top-level run.
347
+ * The child's `ctx.response` becomes the parent step's output, so it
348
+ * lands on `state[<id>]` like any other step (mirrors HTTP semantics:
349
+ * sub-workflow looks like a function call).
350
+ *
351
+ * Inputs flow from parent → child as `ctx.request.body` — the child
352
+ * reads them via `$.req.body.<key>` exactly as if it had been
353
+ * HTTP-triggered.
354
+ *
355
+ * **Composition with Tier 1**:
356
+ * - `idempotencyKey` on this step caches the entire sub-workflow's
357
+ * result. Cache hit = child workflow is NEVER invoked (no side
358
+ * effects fire on rerun). Documented footgun + headline pattern.
359
+ * - `retry` retries the whole sub-workflow on failure.
360
+ * - Replay re-creates fresh sub-run lineage automatically.
361
+ *
362
+ * @example
363
+ * {
364
+ * id: "send-receipt",
365
+ * subworkflow: "send-receipt-email",
366
+ * inputs: { user: $.state.user, order: $.state.order },
367
+ * wait: true, // default; `wait: false` deferred to a follow-up
368
+ * idempotencyKey: $.req.body.requestId,
369
+ * }
370
+ */
371
+ export declare const V2SubworkflowStepSchema: z.ZodType<{
372
+ id: string;
373
+ subworkflow: string;
374
+ inputs?: Record<string, unknown>;
375
+ wait?: boolean;
376
+ as?: string;
377
+ spread?: boolean;
378
+ ephemeral?: boolean;
379
+ active?: boolean;
380
+ stop?: boolean;
381
+ idempotencyKey?: string;
382
+ idempotencyKeyTTL?: number;
383
+ retry?: RetryConfig;
384
+ allowList?: readonly string[];
385
+ /**
386
+ * G2 (v0.6) — dispatch strategy. `in-process` (default) runs the
387
+ * child workflow in the same Node process; `http-self` makes an
388
+ * HTTP self-call to the deployment so multi-process deployments
389
+ * can isolate child execution. Requires the child to have an HTTP
390
+ * trigger (`trigger.http.path` set).
391
+ */
392
+ dispatch?: "in-process" | "http-self";
393
+ }>;
394
+ export type V2SubworkflowStep = z.infer<typeof V2SubworkflowStepSchema>;
395
+ /**
396
+ * V2 wait step (PR 4 · `wait.for(duration)` / `wait.until(date)`).
397
+ *
398
+ * Pauses workflow execution mid-run for the specified duration (or until
399
+ * the absolute deadline). Composes with the durable scheduler — long
400
+ * waits survive process restart via the existing
401
+ * `scheduled_dispatches` infrastructure (PR 4 P3 adds
402
+ * `last_completed_step_index` so the runner skips past completed
403
+ * pre-wait steps on resume).
404
+ *
405
+ * Author surface:
406
+ * ```ts
407
+ * { id: "wait-3d", wait: { for: "3d" } }
408
+ * { id: "wait-deadline", wait: { until: $.req.body.scheduledAt } }
409
+ * ```
410
+ *
411
+ * Cannot combine with `idempotencyKey` (the wait IS the checkpoint) or
412
+ * `retry` (waits don't fail in a retryable way).
413
+ */
414
+ export declare const V2WaitStepSchema: z.ZodEffects<z.ZodObject<{
415
+ id: z.ZodString;
416
+ wait: z.ZodObject<{
417
+ for: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
418
+ until: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
419
+ }, "strict", z.ZodTypeAny, {
420
+ for?: string | number | undefined;
421
+ until?: string | number | undefined;
422
+ }, {
423
+ for?: string | number | undefined;
424
+ until?: string | number | undefined;
425
+ }>;
426
+ as: z.ZodOptional<z.ZodString>;
427
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
428
+ active: z.ZodOptional<z.ZodBoolean>;
429
+ stop: z.ZodOptional<z.ZodBoolean>;
430
+ idempotencyKey: z.ZodOptional<z.ZodNever>;
431
+ retry: z.ZodOptional<z.ZodNever>;
432
+ maxDuration: z.ZodOptional<z.ZodNever>;
433
+ concurrencyKey: z.ZodOptional<z.ZodNever>;
434
+ spread: z.ZodOptional<z.ZodNever>;
435
+ }, "strict", z.ZodTypeAny, {
436
+ id: string;
437
+ wait: {
438
+ for?: string | number | undefined;
439
+ until?: string | number | undefined;
440
+ };
441
+ active?: boolean | undefined;
442
+ stop?: boolean | undefined;
443
+ concurrencyKey?: undefined;
444
+ idempotencyKey?: undefined;
445
+ as?: string | undefined;
446
+ spread?: undefined;
447
+ ephemeral?: boolean | undefined;
448
+ retry?: undefined;
449
+ maxDuration?: undefined;
450
+ }, {
451
+ id: string;
452
+ wait: {
453
+ for?: string | number | undefined;
454
+ until?: string | number | undefined;
455
+ };
456
+ active?: boolean | undefined;
457
+ stop?: boolean | undefined;
458
+ concurrencyKey?: undefined;
459
+ idempotencyKey?: undefined;
460
+ as?: string | undefined;
461
+ spread?: undefined;
462
+ ephemeral?: boolean | undefined;
463
+ retry?: undefined;
464
+ maxDuration?: undefined;
465
+ }>, {
466
+ id: string;
467
+ wait: {
468
+ for?: string | number | undefined;
469
+ until?: string | number | undefined;
470
+ };
471
+ active?: boolean | undefined;
472
+ stop?: boolean | undefined;
473
+ concurrencyKey?: undefined;
474
+ idempotencyKey?: undefined;
475
+ as?: string | undefined;
476
+ spread?: undefined;
477
+ ephemeral?: boolean | undefined;
478
+ retry?: undefined;
479
+ maxDuration?: undefined;
480
+ }, {
481
+ id: string;
482
+ wait: {
483
+ for?: string | number | undefined;
484
+ until?: string | number | undefined;
485
+ };
486
+ active?: boolean | undefined;
487
+ stop?: boolean | undefined;
488
+ concurrencyKey?: undefined;
489
+ idempotencyKey?: undefined;
490
+ as?: string | undefined;
491
+ spread?: undefined;
492
+ ephemeral?: boolean | undefined;
493
+ retry?: undefined;
494
+ maxDuration?: undefined;
495
+ }>;
496
+ export type V2WaitStep = z.infer<typeof V2WaitStepSchema>;
497
+ /**
498
+ * V2 forEach step — iterate over a collection running a sub-pipeline
499
+ * per item. Sequential (default) or parallel with bounded concurrency.
500
+ *
501
+ * @example
502
+ * forEach({
503
+ * id: "process-orders",
504
+ * in: $.state.orders,
505
+ * as: "order",
506
+ * mode: "parallel",
507
+ * concurrency: 5,
508
+ * do: [
509
+ * { id: "charge", use: "stripe-charge", inputs: { amount: $.state.order.total } },
510
+ * ],
511
+ * })
512
+ */
513
+ export declare const V2ForEachStepSchema: z.ZodLazy<z.ZodObject<{
514
+ id: z.ZodString;
515
+ forEach: z.ZodObject<{
516
+ in: z.ZodUnknown;
517
+ as: z.ZodString;
518
+ mode: z.ZodOptional<z.ZodEnum<["sequential", "parallel"]>>;
519
+ concurrency: z.ZodOptional<z.ZodNumber>;
520
+ do: z.ZodArray<z.ZodUnknown, "many">;
521
+ }, "strip", z.ZodTypeAny, {
522
+ as: string;
523
+ do: unknown[];
524
+ mode?: "sequential" | "parallel" | undefined;
525
+ concurrency?: number | undefined;
526
+ in?: unknown;
527
+ }, {
528
+ as: string;
529
+ do: unknown[];
530
+ mode?: "sequential" | "parallel" | undefined;
531
+ concurrency?: number | undefined;
532
+ in?: unknown;
533
+ }>;
534
+ active: z.ZodOptional<z.ZodBoolean>;
535
+ stop: z.ZodOptional<z.ZodBoolean>;
536
+ }, "strip", z.ZodTypeAny, {
537
+ forEach: {
538
+ as: string;
539
+ do: unknown[];
540
+ mode?: "sequential" | "parallel" | undefined;
541
+ concurrency?: number | undefined;
542
+ in?: unknown;
543
+ };
544
+ id: string;
545
+ active?: boolean | undefined;
546
+ stop?: boolean | undefined;
547
+ }, {
548
+ forEach: {
549
+ as: string;
550
+ do: unknown[];
551
+ mode?: "sequential" | "parallel" | undefined;
552
+ concurrency?: number | undefined;
553
+ in?: unknown;
554
+ };
555
+ id: string;
556
+ active?: boolean | undefined;
557
+ stop?: boolean | undefined;
558
+ }>>;
559
+ export type V2ForEachStep = z.infer<typeof V2ForEachStepSchema>;
560
+ /**
561
+ * V2 loop step — while-loop with hard maxIterations safety cap.
562
+ *
563
+ * @example
564
+ * loop({
565
+ * id: "poll",
566
+ * while: '$.state["check-status"].status !== "done"',
567
+ * maxIterations: 60,
568
+ * do: [
569
+ * { id: "wait-tick", wait: { for: "2s" } },
570
+ * { id: "check-status", use: "@blokjs/api-call", inputs: { url: $.state.url } },
571
+ * ],
572
+ * })
573
+ */
574
+ export declare const V2LoopStepSchema: z.ZodLazy<z.ZodObject<{
575
+ id: z.ZodString;
576
+ loop: z.ZodObject<{
577
+ while: z.ZodString;
578
+ maxIterations: z.ZodOptional<z.ZodNumber>;
579
+ do: z.ZodArray<z.ZodUnknown, "many">;
580
+ }, "strip", z.ZodTypeAny, {
581
+ do: unknown[];
582
+ while: string;
583
+ maxIterations?: number | undefined;
584
+ }, {
585
+ do: unknown[];
586
+ while: string;
587
+ maxIterations?: number | undefined;
588
+ }>;
589
+ active: z.ZodOptional<z.ZodBoolean>;
590
+ stop: z.ZodOptional<z.ZodBoolean>;
591
+ }, "strip", z.ZodTypeAny, {
592
+ id: string;
593
+ loop: {
594
+ do: unknown[];
595
+ while: string;
596
+ maxIterations?: number | undefined;
597
+ };
598
+ active?: boolean | undefined;
599
+ stop?: boolean | undefined;
600
+ }, {
601
+ id: string;
602
+ loop: {
603
+ do: unknown[];
604
+ while: string;
605
+ maxIterations?: number | undefined;
606
+ };
607
+ active?: boolean | undefined;
608
+ stop?: boolean | undefined;
609
+ }>>;
610
+ export type V2LoopStep = z.infer<typeof V2LoopStepSchema>;
611
+ /**
612
+ * V2 switch step — N-way branch keyed on a value. First matching case wins.
613
+ *
614
+ * `on` resolves to a value at run time (literal, `$` proxy expression, or
615
+ * `js/...` string). Each case carries a `when` and a `do` sub-pipeline:
616
+ * - `when` is a literal → match if `on === when`.
617
+ * - `when` is an array → match if `array.includes(on)` (group related cases).
618
+ * - `default` runs when no case matches. Optional.
619
+ *
620
+ * @example
621
+ * switchOn({
622
+ * id: "route-by-tenant",
623
+ * on: $.req.headers["x-tenant-id"],
624
+ * cases: [
625
+ * { when: "acme", do: [{ id: "x", subworkflow: "acme-process" }] },
626
+ * { when: ["a","b"], do: [{ id: "y", subworkflow: "shared" }] },
627
+ * ],
628
+ * default: [{ id: "respond-403", use: "@blokjs/respond", stop: true,
629
+ * inputs: { status: 403, body: { error: "Unknown tenant" } } }],
630
+ * })
631
+ */
632
+ export declare const V2SwitchStepSchema: z.ZodLazy<z.ZodObject<{
633
+ id: z.ZodString;
634
+ switch: z.ZodObject<{
635
+ on: z.ZodUnknown;
636
+ cases: z.ZodArray<z.ZodObject<{
637
+ when: z.ZodUnknown;
638
+ do: z.ZodArray<z.ZodUnknown, "many">;
639
+ }, "strip", z.ZodTypeAny, {
640
+ do: unknown[];
641
+ when?: unknown;
642
+ }, {
643
+ do: unknown[];
644
+ when?: unknown;
645
+ }>, "many">;
646
+ default: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
647
+ }, "strip", z.ZodTypeAny, {
648
+ cases: {
649
+ do: unknown[];
650
+ when?: unknown;
651
+ }[];
652
+ on?: unknown;
653
+ default?: unknown[] | undefined;
654
+ }, {
655
+ cases: {
656
+ do: unknown[];
657
+ when?: unknown;
658
+ }[];
659
+ on?: unknown;
660
+ default?: unknown[] | undefined;
661
+ }>;
662
+ active: z.ZodOptional<z.ZodBoolean>;
663
+ stop: z.ZodOptional<z.ZodBoolean>;
664
+ }, "strip", z.ZodTypeAny, {
665
+ id: string;
666
+ switch: {
667
+ cases: {
668
+ do: unknown[];
669
+ when?: unknown;
670
+ }[];
671
+ on?: unknown;
672
+ default?: unknown[] | undefined;
673
+ };
674
+ active?: boolean | undefined;
675
+ stop?: boolean | undefined;
676
+ }, {
677
+ id: string;
678
+ switch: {
679
+ cases: {
680
+ do: unknown[];
681
+ when?: unknown;
682
+ }[];
683
+ on?: unknown;
684
+ default?: unknown[] | undefined;
685
+ };
686
+ active?: boolean | undefined;
687
+ stop?: boolean | undefined;
688
+ }>>;
689
+ export type V2SwitchStep = z.infer<typeof V2SwitchStepSchema>;
690
+ /**
691
+ * V2 tryCatch step — JS-like exception handling for sub-pipelines.
692
+ *
693
+ * - `try` block runs first.
694
+ * - On error, the `catch` block runs with `ctx.error` populated
695
+ * (`$.error.message`, `$.error.name`, `$.error.stack`). Errors thrown
696
+ * inside `catch` propagate to the next outer handler — they DO NOT
697
+ * re-trigger `catch`.
698
+ * - `finally` (if provided) runs unconditionally after try/catch — on
699
+ * normal completion, after a caught error, AND after an uncaught
700
+ * error from inside `catch`. Errors from `finally` propagate.
701
+ *
702
+ * State mutations from any block are visible to subsequent top-level
703
+ * steps (passthrough flow, like switch).
704
+ *
705
+ * @example
706
+ * tryCatch({
707
+ * id: "saga",
708
+ * try: [
709
+ * { id: "create", use: "user-create", inputs: { email: $.req.body.email } },
710
+ * { id: "notify", use: "email-send", inputs: { to: $.state.create.email } },
711
+ * ],
712
+ * catch: [
713
+ * { id: "rollback", use: "user-delete",
714
+ * inputs: { userId: $.state.create.id, reason: $.error.message } },
715
+ * ],
716
+ * finally: [
717
+ * { id: "metric", use: "@blokjs/metrics-emit", inputs: { event: "saga-attempt" } },
718
+ * ],
719
+ * })
720
+ */
721
+ export declare const V2TryCatchStepSchema: z.ZodLazy<z.ZodObject<{
722
+ id: z.ZodString;
723
+ tryCatch: z.ZodObject<{
724
+ try: z.ZodArray<z.ZodUnknown, "many">;
725
+ catch: z.ZodArray<z.ZodUnknown, "many">;
726
+ finally: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
727
+ }, "strip", z.ZodTypeAny, {
728
+ try: unknown[];
729
+ catch: unknown[];
730
+ finally?: unknown[] | undefined;
731
+ }, {
732
+ try: unknown[];
733
+ catch: unknown[];
734
+ finally?: unknown[] | undefined;
735
+ }>;
736
+ active: z.ZodOptional<z.ZodBoolean>;
737
+ stop: z.ZodOptional<z.ZodBoolean>;
738
+ }, "strip", z.ZodTypeAny, {
739
+ id: string;
740
+ tryCatch: {
741
+ try: unknown[];
742
+ catch: unknown[];
743
+ finally?: unknown[] | undefined;
744
+ };
745
+ active?: boolean | undefined;
746
+ stop?: boolean | undefined;
747
+ }, {
748
+ id: string;
749
+ tryCatch: {
750
+ try: unknown[];
751
+ catch: unknown[];
752
+ finally?: unknown[] | undefined;
753
+ };
754
+ active?: boolean | undefined;
755
+ stop?: boolean | undefined;
756
+ }>>;
757
+ export type V2TryCatchStep = z.infer<typeof V2TryCatchStepSchema>;
758
+ /**
759
+ * Discriminated v2 step — regular, branch, sub-workflow, wait, forEach, loop, switch, or tryCatch.
760
+ *
761
+ * Discriminators (no `kind` field needed):
762
+ * - presence of `branch` → branch step
763
+ * - presence of `subworkflow` → sub-workflow step
764
+ * - presence of `wait` (object) → wait step
765
+ * - presence of `forEach` → forEach step (v0.5)
766
+ * - presence of `loop` → loop step (v0.5)
767
+ * - presence of `switch` → switch step (v0.5)
768
+ * - presence of `tryCatch` → tryCatch step (v0.5)
769
+ * - otherwise → regular step
770
+ */
771
+ export declare const V2StepSchema: z.ZodType<V2RegularStep | V2BranchStep | V2SubworkflowStep | V2WaitStep | V2ForEachStep | V2LoopStep | V2SwitchStep | V2TryCatchStep>;
772
+ export type V2Step = V2RegularStep | V2BranchStep | V2SubworkflowStep | V2WaitStep | V2ForEachStep | V2LoopStep | V2SwitchStep | V2TryCatchStep;
773
+ /**
774
+ * Type guard — true when the step is a branch.
775
+ */
776
+ export declare function isBranchStep(step: V2Step): step is V2BranchStep;
777
+ /**
778
+ * Type guard — true when the step is a wait (PR 4 `wait.for` / `wait.until`).
779
+ */
780
+ export declare function isWaitStep(step: V2Step): step is V2WaitStep;
781
+ /**
782
+ * Type guard — true when the step is a sub-workflow invocation.
783
+ */
784
+ export declare function isSubworkflowStep(step: V2Step): step is V2SubworkflowStep;
785
+ /**
786
+ * Type guard — true when the step is a forEach iteration (v0.5).
787
+ */
788
+ export declare function isForEachStep(step: V2Step): step is V2ForEachStep;
789
+ /**
790
+ * Type guard — true when the step is a while-loop (v0.5).
791
+ */
792
+ export declare function isLoopStep(step: V2Step): step is V2LoopStep;
793
+ /**
794
+ * Type guard — true when the step is an N-way switch (v0.5).
795
+ */
796
+ export declare function isSwitchStep(step: V2Step): step is V2SwitchStep;
797
+ /**
798
+ * Type guard — true when the step is a tryCatch (v0.5).
799
+ */
800
+ export declare function isTryCatchStep(step: V2Step): step is V2TryCatchStep;