@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
@@ -13,18 +13,27 @@ declare const ConditionElseSchema: z.ZodObject<{
13
13
  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"]>;
14
14
  inputs: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
15
15
  runtime: z.ZodOptional<z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>>;
16
+ active: z.ZodOptional<z.ZodBoolean>;
17
+ stop: z.ZodOptional<z.ZodBoolean>;
18
+ stream_logs: z.ZodOptional<z.ZodBoolean>;
16
19
  }, "strip", z.ZodTypeAny, {
17
20
  name: string;
18
21
  node: string;
19
22
  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";
20
23
  inputs?: {} | undefined;
21
24
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
25
+ active?: boolean | undefined;
26
+ stop?: boolean | undefined;
27
+ stream_logs?: boolean | undefined;
22
28
  }, {
23
29
  name: string;
24
30
  node: string;
25
31
  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";
26
32
  inputs?: {} | undefined;
27
33
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
34
+ active?: boolean | undefined;
35
+ stop?: boolean | undefined;
36
+ stream_logs?: boolean | undefined;
28
37
  }>, "many">>;
29
38
  }, "strip", z.ZodTypeAny, {
30
39
  type: "if" | "else";
@@ -34,6 +43,9 @@ declare const ConditionElseSchema: z.ZodObject<{
34
43
  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";
35
44
  inputs?: {} | undefined;
36
45
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
46
+ active?: boolean | undefined;
47
+ stop?: boolean | undefined;
48
+ stream_logs?: boolean | undefined;
37
49
  }[] | undefined;
38
50
  }, {
39
51
  type: "if" | "else";
@@ -43,6 +55,9 @@ declare const ConditionElseSchema: z.ZodObject<{
43
55
  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";
44
56
  inputs?: {} | undefined;
45
57
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
58
+ active?: boolean | undefined;
59
+ stop?: boolean | undefined;
60
+ stream_logs?: boolean | undefined;
46
61
  }[] | undefined;
47
62
  }>;
48
63
  export type ConditionElseOpts = z.infer<typeof ConditionElseSchema>;
@@ -16,18 +16,27 @@ declare const ConditionSchema: z.ZodObject<{
16
16
  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"]>;
17
17
  inputs: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
18
18
  runtime: z.ZodOptional<z.ZodEnum<["nodejs", "bun", "python3", "go", "java", "rust", "php", "csharp", "ruby", "docker", "wasm"]>>;
19
+ active: z.ZodOptional<z.ZodBoolean>;
20
+ stop: z.ZodOptional<z.ZodBoolean>;
21
+ stream_logs: z.ZodOptional<z.ZodBoolean>;
19
22
  }, "strip", z.ZodTypeAny, {
20
23
  name: string;
21
24
  node: string;
22
25
  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";
23
26
  inputs?: {} | undefined;
24
27
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
28
+ active?: boolean | undefined;
29
+ stop?: boolean | undefined;
30
+ stream_logs?: boolean | undefined;
25
31
  }, {
26
32
  name: string;
27
33
  node: string;
28
34
  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";
29
35
  inputs?: {} | undefined;
30
36
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
37
+ active?: boolean | undefined;
38
+ stop?: boolean | undefined;
39
+ stream_logs?: boolean | undefined;
31
40
  }>, "many">>;
32
41
  }, "strip", z.ZodTypeAny, {
33
42
  type: "if" | "else";
@@ -38,6 +47,9 @@ declare const ConditionSchema: z.ZodObject<{
38
47
  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";
39
48
  inputs?: {} | undefined;
40
49
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
50
+ active?: boolean | undefined;
51
+ stop?: boolean | undefined;
52
+ stream_logs?: boolean | undefined;
41
53
  }[] | undefined;
42
54
  }, {
43
55
  type: "if" | "else";
@@ -48,6 +60,9 @@ declare const ConditionSchema: z.ZodObject<{
48
60
  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
61
  inputs?: {} | undefined;
50
62
  runtime?: "nodejs" | "bun" | "python3" | "go" | "java" | "rust" | "php" | "csharp" | "ruby" | "docker" | "wasm" | undefined;
63
+ active?: boolean | undefined;
64
+ stop?: boolean | undefined;
65
+ stream_logs?: boolean | undefined;
51
66
  }[] | undefined;
52
67
  }>;
53
68
  export type ConditionOpts = z.infer<typeof ConditionSchema>;
@@ -1,5 +1,11 @@
1
1
  import { type StepConditionOpts, type StepOpts } from "../types/StepOpts";
2
2
  import HelperResponse from "./HelperResponse";
3
+ /**
4
+ * Builder step that adds workflow steps and conditional branches.
5
+ *
6
+ * Each call returns a new {@link StepNode} carrying the accumulated config
7
+ * so workflow definitions remain immutable from the outside.
8
+ */
3
9
  export default class StepNode extends HelperResponse {
4
10
  addStep(config: StepOpts): StepNode;
5
11
  addCondition(conditions: StepConditionOpts): StepNode;
@@ -1,5 +1,11 @@
1
1
  import { StepConditionSchema, StepOptsSchema, } from "../types/StepOpts";
2
2
  import HelperResponse from "./HelperResponse";
3
+ /**
4
+ * Builder step that adds workflow steps and conditional branches.
5
+ *
6
+ * Each call returns a new {@link StepNode} carrying the accumulated config
7
+ * so workflow definitions remain immutable from the outside.
8
+ */
3
9
  export default class StepNode extends HelperResponse {
4
10
  addStep(config) {
5
11
  StepOptsSchema.parse(config);
@@ -13,6 +19,8 @@ export default class StepNode extends HelperResponse {
13
19
  node: config.node,
14
20
  type: config.type,
15
21
  runtime: config.runtime,
22
+ active: config.active,
23
+ stop: config.stop,
16
24
  });
17
25
  const helperResponse = new StepNode();
18
26
  helperResponse.setConfig(this._config);
@@ -1 +1 @@
1
- {"version":3,"file":"StepNode.js","sourceRoot":"","sources":["../../src/components/StepNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,mBAAmB,EAEnB,cAAc,GACd,MAAM,mBAAmB,CAAC;AAG3B,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,cAAc;IACnD,OAAO,CAAC,MAAgB;QACvB,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAE7B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;YACjC,MAAM,EAAE,MAAM,CAAC,MAAM;SACrB,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;YACxB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;SACvB,CAAC,CAAC;QAEH,MAAM,cAAc,GAAG,IAAI,QAAQ,EAAE,CAAC;QACtC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,cAAc,CAAC;IACvB,CAAC;IAED,YAAY,CAAC,UAA6B;QACzC,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACtC,MAAM,IAAI,GAAG,UAAoC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAA2C,CAAC;QAE5E,IAAI,IAAI,CAAC,OAAO,CAAC,KAA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YAC1C,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAmB,CAAC;YAE5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACvC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBAEtB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;oBAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;iBACnB,CAAC;gBAEF,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YACzB,CAAC;QACF,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC1C,UAAU,EAAE,QAAQ;SACpB,CAAC;QAEF,MAAM,cAAc,GAAG,IAAI,QAAQ,EAAE,CAAC;QACtC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,cAAc,CAAC;IACvB,CAAC;CACD"}
@@ -1,8 +1,16 @@
1
- import { type CronTriggerOpts, type PubSubTriggerOpts, type QueueTriggerOpts, type SSETriggerOpts, type TriggerOpts, type WebSocketTriggerOpts, type WebhookTriggerOpts, type WorkerTriggerOpts } from "../types/TriggerOpts";
1
+ import { type CronTriggerOpts, type HttpTriggerOpts, type PubSubTriggerOpts, type QueueTriggerOpts, type SSETriggerOpts, type WebSocketTriggerOpts, type WebhookTriggerOpts, type WorkerTriggerOpts } from "../types/TriggerOpts";
2
2
  import HelperResponse from "./HelperResponse";
3
3
  import StepNode from "./StepNode";
4
+ /**
5
+ * Builder step that attaches a trigger to a workflow.
6
+ *
7
+ * Returned by {@link Workflow}; chains into {@link StepNode} via
8
+ * {@link Trigger.addTrigger}. Type-safe overloads constrain the `config`
9
+ * argument shape per trigger kind; {@link validateTriggerConfig} runs the
10
+ * matching Zod schema at call time.
11
+ */
4
12
  export default class Trigger extends HelperResponse {
5
- addTrigger(name: "http", config: TriggerOpts): StepNode;
13
+ addTrigger(name: "http", config: HttpTriggerOpts): StepNode;
6
14
  addTrigger(name: "queue", config: QueueTriggerOpts): StepNode;
7
15
  addTrigger(name: "pubsub", config: PubSubTriggerOpts): StepNode;
8
16
  addTrigger(name: "cron", config: CronTriggerOpts): StepNode;
@@ -1,13 +1,24 @@
1
- import { TriggerOptsSchema, TriggersSchema, } from "../types/TriggerOpts";
1
+ import { TriggersSchema, validateTriggerConfig, } from "../types/TriggerOpts";
2
2
  import HelperResponse from "./HelperResponse";
3
3
  import StepNode from "./StepNode";
4
+ /**
5
+ * Builder step that attaches a trigger to a workflow.
6
+ *
7
+ * Returned by {@link Workflow}; chains into {@link StepNode} via
8
+ * {@link Trigger.addTrigger}. Type-safe overloads constrain the `config`
9
+ * argument shape per trigger kind; {@link validateTriggerConfig} runs the
10
+ * matching Zod schema at call time.
11
+ */
4
12
  export default class Trigger extends HelperResponse {
5
13
  addTrigger(name, config) {
14
+ // Validate the trigger NAME first so callers get a clear error for typos
15
+ // before we try to dispatch to a schema.
6
16
  TriggersSchema.parse(name);
7
- if (name === "http" && config) {
8
- TriggerOptsSchema.parse(config);
9
- }
10
- this._config.trigger = { [name]: config || {} };
17
+ // Dispatch to the per-kind schema. Returns the parsed config (with
18
+ // defaults applied) for typed triggers, or the input config for
19
+ // grpc/manual which have no schema.
20
+ const validated = validateTriggerConfig(name, config);
21
+ this._config.trigger = { [name]: validated };
11
22
  const helperResponse = new StepNode();
12
23
  helperResponse.setConfig(this._config);
13
24
  return helperResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"Trigger.js","sourceRoot":"","sources":["../../src/components/Trigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,iBAAiB,EAEjB,cAAc,GAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,cAAc;IAWlD,UAAU,CAAyB,IAAO,EAAE,MAA4B;QACvE,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE3B,IAAI,IAAI,KAAK,MAAM,IAAI,MAAM,EAAE,CAAC;YAC/B,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC;QAEhD,MAAM,cAAc,GAAG,IAAI,QAAQ,EAAE,CAAC;QACtC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,cAAc,CAAC;IACvB,CAAC;CACD"}
1
+ {"version":3,"file":"Trigger.js","sourceRoot":"","sources":["../../src/components/Trigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAQN,cAAc,EAId,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,cAAc;IAUlD,UAAU,CAAyB,IAAO,EAAE,MAA4B;QACvE,yEAAyE;QACzE,yCAAyC;QACzC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE3B,mEAAmE;QACnE,gEAAgE;QAChE,oCAAoC;QACpC,MAAM,SAAS,GAAG,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;QAE7C,MAAM,cAAc,GAAG,IAAI,QAAQ,EAAE,CAAC;QACtC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,cAAc,CAAC;IACvB,CAAC;CACD"}
@@ -0,0 +1,44 @@
1
+ import type { V2BranchStep, V2Step } from "../types/StepOpts";
2
+ /**
3
+ * Author-facing options for {@link branch}.
4
+ *
5
+ * `when` accepts either a plain string (`"$.req.method === 'POST'"`) or
6
+ * a `$` proxy expression that will compile to a string at definition
7
+ * time (`$.req.method`). Note that JavaScript's `===` operator can't be
8
+ * intercepted, so equality comparisons must be expressed as strings.
9
+ */
10
+ export interface BranchOpts {
11
+ /** Stable identifier — visible in traces, referenced as `$.state[id]`. */
12
+ id: string;
13
+ /** JS condition. Truthy → run `then`; falsy → run `else`. */
14
+ when: string | unknown;
15
+ then: V2Step[];
16
+ /** Optional. Steps to run when `when` is falsy. */
17
+ else?: V2Step[];
18
+ /** Skip this branch step at runtime. Default true (active). */
19
+ active?: boolean;
20
+ /** Halt the workflow after this branch step completes. */
21
+ stop?: boolean;
22
+ }
23
+ /**
24
+ * Create a branch step — a step that runs one of two sub-pipelines based
25
+ * on a JS condition.
26
+ *
27
+ * Compiles down to today's `@blokjs/if-else` flow node at workflow load
28
+ * time, so the runner core needs no change. Authors get a single primitive
29
+ * with the same shape as a regular step: `{ id, ... }`.
30
+ *
31
+ * @example
32
+ * branch({
33
+ * id: "route",
34
+ * when: '$.req.method === "POST"',
35
+ * then: [{ id: "create", use: "...", inputs: {...} }],
36
+ * else: [{ id: "read", use: "...", inputs: {...} }]
37
+ * })
38
+ *
39
+ * @example
40
+ * // `when` accepts a $ proxy expression — compiles to a string at
41
+ * // definition time, so `js/ctx.req.query.kind` lands in the workflow.
42
+ * branch({ id: "route-by-kind", when: $.req.query.kind, then: [...] })
43
+ */
44
+ export declare function branch(opts: BranchOpts): V2BranchStep;
@@ -0,0 +1,57 @@
1
+ import { unwrapProxies } from "../proxy/$";
2
+ /**
3
+ * Create a branch step — a step that runs one of two sub-pipelines based
4
+ * on a JS condition.
5
+ *
6
+ * Compiles down to today's `@blokjs/if-else` flow node at workflow load
7
+ * time, so the runner core needs no change. Authors get a single primitive
8
+ * with the same shape as a regular step: `{ id, ... }`.
9
+ *
10
+ * @example
11
+ * branch({
12
+ * id: "route",
13
+ * when: '$.req.method === "POST"',
14
+ * then: [{ id: "create", use: "...", inputs: {...} }],
15
+ * else: [{ id: "read", use: "...", inputs: {...} }]
16
+ * })
17
+ *
18
+ * @example
19
+ * // `when` accepts a $ proxy expression — compiles to a string at
20
+ * // definition time, so `js/ctx.req.query.kind` lands in the workflow.
21
+ * branch({ id: "route-by-kind", when: $.req.query.kind, then: [...] })
22
+ */
23
+ export function branch(opts) {
24
+ if (!opts || typeof opts !== "object") {
25
+ throw new Error("branch() requires an options object.");
26
+ }
27
+ if (!opts.id || typeof opts.id !== "string") {
28
+ throw new Error("branch() requires a non-empty `id` string.");
29
+ }
30
+ const when = unwrapProxies(opts.when);
31
+ if (typeof when !== "string" || when.length === 0) {
32
+ throw new Error(`branch("${opts.id}") requires a non-empty \`when\` string. Use a $ proxy path (e.g. $.req.query.kind) or a plain expression (e.g. '$.req.method === "POST"'). For equality comparisons, use a plain string — JavaScript's === operator can't be intercepted by the proxy.`);
33
+ }
34
+ if (!Array.isArray(opts.then)) {
35
+ throw new Error(`branch("${opts.id}") requires \`then\` to be an array of steps.`);
36
+ }
37
+ if (opts.else !== undefined && !Array.isArray(opts.else)) {
38
+ throw new Error(`branch("${opts.id}") \`else\` must be an array of steps when set.`);
39
+ }
40
+ // Walk the steps to convert any inline proxies in their inputs.
41
+ const thenSteps = unwrapProxies(opts.then);
42
+ const elseSteps = opts.else ? unwrapProxies(opts.else) : undefined;
43
+ const result = {
44
+ id: opts.id,
45
+ branch: {
46
+ when,
47
+ then: thenSteps,
48
+ ...(elseSteps ? { else: elseSteps } : {}),
49
+ },
50
+ };
51
+ if (opts.active === false)
52
+ result.active = false;
53
+ if (opts.stop === true)
54
+ result.stop = true;
55
+ return result;
56
+ }
57
+ //# sourceMappingURL=branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/components/branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAyB3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,MAAM,CAAC,IAAgB;IACtC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,OAAO,IAAI,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACd,WAAW,IAAI,CAAC,EAAE,yPAAyP,CAC3Q,CAAC;IACH,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,CAAC,EAAE,+CAA+C,CAAC,CAAC;IACpF,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,CAAC,EAAE,iDAAiD,CAAC,CAAC;IACtF,CAAC;IAED,gEAAgE;IAChE,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAa,CAAC;IACvD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAc,CAAC,CAAC,CAAC,SAAS,CAAC;IAEjF,MAAM,MAAM,GAAiB;QAC5B,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,MAAM,EAAE;YACP,IAAI;YACJ,IAAI,EAAE,SAAS;YACf,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzC;KACD,CAAC;IACF,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK;QAAG,MAA6C,CAAC,MAAM,GAAG,KAAK,CAAC;IACzF,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;QAAG,MAA2C,CAAC,IAAI,GAAG,IAAI,CAAC;IACjF,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { V2ForEachStep, V2Step } from "../types/StepOpts";
2
+ /**
3
+ * Author-facing options for {@link forEach}.
4
+ *
5
+ * `in` accepts either a literal expression string (`"$.state.items"` or
6
+ * `"js/ctx.state.items"`) or a `$` proxy expression that compiles to
7
+ * the same string at definition time.
8
+ *
9
+ * `as` is the per-iteration variable name. Each iteration sets
10
+ * `ctx.state[as]` to the current item and `ctx.state[as + "Index"]`
11
+ * to the 0-based position. Avoid using a name that collides with
12
+ * any step `id` in the surrounding workflow.
13
+ */
14
+ export interface ForEachOpts {
15
+ /** Stable identifier — visible in traces, referenced as `$.state[id]`. */
16
+ id: string;
17
+ /** Array source. Literal expression string or `$` proxy. */
18
+ in: string | unknown;
19
+ /**
20
+ * Per-iteration variable name. Each iteration sets `ctx.state[as] = item`
21
+ * and `ctx.state[as + "Index"] = i`. Must be a valid JS identifier
22
+ * (letters, digits, underscore; can't start with a digit).
23
+ */
24
+ as: string;
25
+ /** Sub-pipeline run for each item. */
26
+ do: V2Step[];
27
+ /** `"sequential"` (default) awaits each iteration; `"parallel"` runs with bounded concurrency. */
28
+ mode?: "sequential" | "parallel";
29
+ /** When `mode: "parallel"`, max concurrent inner pipelines. Default 10. */
30
+ concurrency?: number;
31
+ /** Skip this step at runtime. Default true (active). */
32
+ active?: boolean;
33
+ /** Halt the workflow after this step completes. */
34
+ stop?: boolean;
35
+ }
36
+ /**
37
+ * Create a forEach step — iterate over a collection running a sub-pipeline
38
+ * per item. Sequential by default; pass `mode: "parallel"` with a
39
+ * `concurrency` cap for parallel fan-out.
40
+ *
41
+ * @example
42
+ * forEach({
43
+ * id: "process-items",
44
+ * in: $.req.body.items,
45
+ * as: "item",
46
+ * mode: "parallel",
47
+ * concurrency: 5,
48
+ * do: [
49
+ * { id: "reserve", use: "inventory-reserve", inputs: { sku: $.state.item.sku } },
50
+ * ],
51
+ * })
52
+ */
53
+ export declare function forEach(opts: ForEachOpts): V2ForEachStep;
@@ -0,0 +1,64 @@
1
+ import { unwrapProxies } from "../proxy/$";
2
+ /**
3
+ * Create a forEach step — iterate over a collection running a sub-pipeline
4
+ * per item. Sequential by default; pass `mode: "parallel"` with a
5
+ * `concurrency` cap for parallel fan-out.
6
+ *
7
+ * @example
8
+ * forEach({
9
+ * id: "process-items",
10
+ * in: $.req.body.items,
11
+ * as: "item",
12
+ * mode: "parallel",
13
+ * concurrency: 5,
14
+ * do: [
15
+ * { id: "reserve", use: "inventory-reserve", inputs: { sku: $.state.item.sku } },
16
+ * ],
17
+ * })
18
+ */
19
+ export function forEach(opts) {
20
+ if (!opts || typeof opts !== "object") {
21
+ throw new Error("forEach() requires an options object.");
22
+ }
23
+ if (!opts.id || typeof opts.id !== "string") {
24
+ throw new Error("forEach() requires a non-empty `id` string.");
25
+ }
26
+ if (opts.in === undefined) {
27
+ throw new Error(`forEach("${opts.id}") requires \`in\` (the array source).`);
28
+ }
29
+ if (!opts.as || typeof opts.as !== "string") {
30
+ throw new Error(`forEach("${opts.id}") requires \`as\` (the per-iteration variable name).`);
31
+ }
32
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(opts.as)) {
33
+ throw new Error(`forEach("${opts.id}") \`as\` must be a valid JS identifier (got "${opts.as}").`);
34
+ }
35
+ if (!Array.isArray(opts.do) || opts.do.length === 0) {
36
+ throw new Error(`forEach("${opts.id}") requires \`do\` to be a non-empty array of steps.`);
37
+ }
38
+ if (opts.mode !== undefined && opts.mode !== "sequential" && opts.mode !== "parallel") {
39
+ throw new Error(`forEach("${opts.id}") \`mode\` must be "sequential" or "parallel" when set.`);
40
+ }
41
+ if (opts.concurrency !== undefined) {
42
+ if (typeof opts.concurrency !== "number" || opts.concurrency < 1 || !Number.isInteger(opts.concurrency)) {
43
+ throw new Error(`forEach("${opts.id}") \`concurrency\` must be a positive integer.`);
44
+ }
45
+ }
46
+ const inExpr = unwrapProxies(opts.in);
47
+ const innerSteps = unwrapProxies(opts.do);
48
+ const result = {
49
+ id: opts.id,
50
+ forEach: {
51
+ in: inExpr,
52
+ as: opts.as,
53
+ do: innerSteps,
54
+ ...(opts.mode !== undefined ? { mode: opts.mode } : {}),
55
+ ...(opts.concurrency !== undefined ? { concurrency: opts.concurrency } : {}),
56
+ },
57
+ };
58
+ if (opts.active === false)
59
+ result.active = false;
60
+ if (opts.stop === true)
61
+ result.stop = true;
62
+ return result;
63
+ }
64
+ //# sourceMappingURL=forEach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forEach.js","sourceRoot":"","sources":["../../src/components/forEach.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAsC3C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,IAAiB;IACxC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC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,CAAC,WAAW,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACzG,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,EAAE,gDAAgD,CAAC,CAAC;QACtF,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,CAAa,CAAC;IAEtD,MAAM,MAAM,GAAkB;QAC7B,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,OAAO,EAAE;YACR,EAAE,EAAE,MAAM;YACV,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,EAAE,EAAE,UAAU;YACd,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvD,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5E;KACD,CAAC;IACF,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK;QAAG,MAA8C,CAAC,MAAM,GAAG,KAAK,CAAC;IAC1F,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;QAAG,MAA4C,CAAC,IAAI,GAAG,IAAI,CAAC;IAClF,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { V2LoopStep, V2Step } from "../types/StepOpts";
2
+ /**
3
+ * Author-facing options for {@link loop}.
4
+ *
5
+ * `while` is a JS expression evaluated against `ctx` BEFORE each
6
+ * iteration. Loop continues while truthy. The loop counter is exposed
7
+ * as `ctx.state[<id>Index]` so the condition can reference it
8
+ * (e.g. `$.state.pollIndex < 5`).
9
+ *
10
+ * `maxIterations` is a HARD cap that throws `LoopMaxIterationsError`
11
+ * when exceeded — a safety net against infinite loops. Default 1000.
12
+ */
13
+ export interface LoopOpts {
14
+ /** Stable identifier. The loop counter is exposed as `ctx.state[<id>Index]`. */
15
+ id: string;
16
+ /**
17
+ * JS expression evaluated against ctx before each iteration. Loop
18
+ * continues while truthy.
19
+ */
20
+ while: string | unknown;
21
+ /** Sub-pipeline run each iteration. */
22
+ do: V2Step[];
23
+ /**
24
+ * Hard cap on iterations. Default 1000 (override via env
25
+ * `BLOK_LOOP_MAX_ITERATIONS`). Hitting the cap throws
26
+ * `LoopMaxIterationsError`.
27
+ */
28
+ maxIterations?: number;
29
+ /** Skip this step at runtime. Default true (active). */
30
+ active?: boolean;
31
+ /** Halt the workflow after this step completes. */
32
+ stop?: boolean;
33
+ }
34
+ /**
35
+ * Create a loop step — while-loop with a hard maxIterations safety cap.
36
+ *
37
+ * State mutations made inside the loop body carry forward to the next
38
+ * iteration, so condition variables can advance. The current iteration
39
+ * counter (0-based) is at `ctx.state[<id>Index]`.
40
+ *
41
+ * @example
42
+ * loop({
43
+ * id: "poll-job",
44
+ * while: '$.state["check-status"].status !== "done"',
45
+ * maxIterations: 60,
46
+ * do: [
47
+ * { id: "wait-tick", wait: { for: "2s" } },
48
+ * { id: "check-status", use: "@blokjs/api-call", inputs: { url: "..." } },
49
+ * ],
50
+ * })
51
+ */
52
+ export declare function loop(opts: LoopOpts): V2LoopStep;
@@ -0,0 +1,54 @@
1
+ import { unwrapProxies } from "../proxy/$";
2
+ /**
3
+ * Create a loop step — while-loop with a hard maxIterations safety cap.
4
+ *
5
+ * State mutations made inside the loop body carry forward to the next
6
+ * iteration, so condition variables can advance. The current iteration
7
+ * counter (0-based) is at `ctx.state[<id>Index]`.
8
+ *
9
+ * @example
10
+ * loop({
11
+ * id: "poll-job",
12
+ * while: '$.state["check-status"].status !== "done"',
13
+ * maxIterations: 60,
14
+ * do: [
15
+ * { id: "wait-tick", wait: { for: "2s" } },
16
+ * { id: "check-status", use: "@blokjs/api-call", inputs: { url: "..." } },
17
+ * ],
18
+ * })
19
+ */
20
+ export function loop(opts) {
21
+ if (!opts || typeof opts !== "object") {
22
+ throw new Error("loop() requires an options object.");
23
+ }
24
+ if (!opts.id || typeof opts.id !== "string") {
25
+ throw new Error("loop() requires a non-empty `id` string.");
26
+ }
27
+ const whileExpr = unwrapProxies(opts.while);
28
+ if (typeof whileExpr !== "string" || whileExpr.length === 0) {
29
+ throw new Error(`loop("${opts.id}") requires a non-empty \`while\` expression. Use a $ proxy path or a plain string expression.`);
30
+ }
31
+ if (!Array.isArray(opts.do) || opts.do.length === 0) {
32
+ throw new Error(`loop("${opts.id}") requires \`do\` to be a non-empty array of steps.`);
33
+ }
34
+ if (opts.maxIterations !== undefined) {
35
+ if (typeof opts.maxIterations !== "number" || opts.maxIterations < 1 || !Number.isInteger(opts.maxIterations)) {
36
+ throw new Error(`loop("${opts.id}") \`maxIterations\` must be a positive integer.`);
37
+ }
38
+ }
39
+ const innerSteps = unwrapProxies(opts.do);
40
+ const result = {
41
+ id: opts.id,
42
+ loop: {
43
+ while: whileExpr,
44
+ do: innerSteps,
45
+ ...(opts.maxIterations !== undefined ? { maxIterations: opts.maxIterations } : {}),
46
+ },
47
+ };
48
+ if (opts.active === false)
49
+ result.active = false;
50
+ if (opts.stop === true)
51
+ result.stop = true;
52
+ return result;
53
+ }
54
+ //# sourceMappingURL=loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.js","sourceRoot":"","sources":["../../src/components/loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAoC3C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAC,IAAc;IAClC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,oCA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a,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClF;KACD,CAAC;IACF,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK;QAAG,MAA2C,CAAC,MAAM,GAAG,KAAK,CAAC;IACvF,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;QAAG,MAAyC,CAAC,IAAI,GAAG,IAAI,CAAC;IAC/E,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,68 @@
1
+ import type { V2Step, V2SwitchStep } from "../types/StepOpts";
2
+ /**
3
+ * Author-facing options for {@link switchOn}.
4
+ *
5
+ * `on` accepts either a `$` proxy expression (compiles to a `js/...`
6
+ * string at definition time) or a literal value. Whatever it resolves
7
+ * to at run time is matched against each `case.when`:
8
+ *
9
+ * - `when` is a literal scalar → match if `on === when`
10
+ * - `when` is an array → match if `array.includes(on)` (group related cases)
11
+ *
12
+ * First matching case wins. Subsequent cases are not evaluated. If no
13
+ * case matches and a `default` block is provided, those steps run instead.
14
+ */
15
+ export interface SwitchCase {
16
+ /**
17
+ * Match value. Literal scalar (number/string/boolean) for strict
18
+ * equality, or an array for any-of matching. Resolved by the
19
+ * blueprint mapper before comparison — `$` proxies and `js/...`
20
+ * strings are evaluated against the live ctx.
21
+ */
22
+ when: unknown;
23
+ /** Sub-pipeline run when this case matches. */
24
+ do: V2Step[];
25
+ }
26
+ export interface SwitchOpts {
27
+ /** Stable identifier — visible in traces, referenced as `$.state[id]`. */
28
+ id: string;
29
+ /**
30
+ * Value to match against. `$` proxy expression (`$.req.headers["x-tenant-id"]`),
31
+ * `js/...` string, or any literal. Resolved at run time before matching.
32
+ */
33
+ on: unknown;
34
+ /** Ordered list of cases. First match wins. */
35
+ cases: SwitchCase[];
36
+ /** Fallback sub-pipeline when no case matches. Optional. */
37
+ default?: V2Step[];
38
+ /** Skip this step at runtime. Default true (active). */
39
+ active?: boolean;
40
+ /** Halt the workflow after this step completes. */
41
+ stop?: boolean;
42
+ }
43
+ /**
44
+ * Create a switch step — N-way branch keyed on a value. First matching
45
+ * case wins; an optional `default` block runs when no case matches.
46
+ *
47
+ * Authoring note: the function is named `switchOn` because `switch` is
48
+ * a JavaScript reserved word. The resulting step object's discriminator
49
+ * field is `switch`, matching the JSON shape exactly.
50
+ *
51
+ * @example
52
+ * switchOn({
53
+ * id: "route-by-event",
54
+ * on: $.req.headers["x-github-event"],
55
+ * cases: [
56
+ * { when: "push", do: [{ id: "h", subworkflow: "handle-push" }] },
57
+ * {
58
+ * when: ["pull_request", "pull_request_review"],
59
+ * do: [{ id: "h", subworkflow: "handle-pr-event" }],
60
+ * },
61
+ * ],
62
+ * default: [
63
+ * { id: "log-unknown", use: "@blokjs/log",
64
+ * inputs: { level: "warn", message: "unknown github event" } },
65
+ * ],
66
+ * })
67
+ */
68
+ export declare function switchOn(opts: SwitchOpts): V2SwitchStep;