@xyne/workflow-sdk 3.2.52 → 3.2.54

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 (181) hide show
  1. package/dist/builder/index.d.ts +19 -2
  2. package/dist/builder/index.d.ts.map +1 -1
  3. package/dist/builder/index.js +17 -1
  4. package/dist/builder/index.js.map +1 -1
  5. package/dist/common/citation-ref.d.ts +4 -4
  6. package/dist/connectors/builtin/steps/compute.step.d.ts +56 -0
  7. package/dist/connectors/builtin/steps/compute.step.d.ts.map +1 -0
  8. package/dist/connectors/builtin/steps/compute.step.js +48 -0
  9. package/dist/connectors/builtin/steps/compute.step.js.map +1 -0
  10. package/dist/connectors/builtin/steps/conditional.step.d.ts +2 -2
  11. package/dist/connectors/builtin/steps/conditional.step.js +1 -1
  12. package/dist/connectors/builtin/steps/conditional.step.js.map +1 -1
  13. package/dist/connectors/builtin/steps/cycle.step.d.ts.map +1 -1
  14. package/dist/connectors/builtin/steps/cycle.step.js +5 -2
  15. package/dist/connectors/builtin/steps/cycle.step.js.map +1 -1
  16. package/dist/connectors/builtin/steps/dedup.step.js +2 -2
  17. package/dist/connectors/builtin/steps/dedup.step.js.map +1 -1
  18. package/dist/connectors/builtin/steps/loop.step.d.ts +6 -6
  19. package/dist/connectors/builtin/steps/loop.step.d.ts.map +1 -1
  20. package/dist/connectors/builtin/steps/loop.step.js +4 -2
  21. package/dist/connectors/builtin/steps/loop.step.js.map +1 -1
  22. package/dist/connectors/builtin/steps/map.step.d.ts +4 -4
  23. package/dist/connectors/builtin/steps/map.step.d.ts.map +1 -1
  24. package/dist/connectors/builtin/steps/map.step.js +4 -2
  25. package/dist/connectors/builtin/steps/map.step.js.map +1 -1
  26. package/dist/connectors/builtin/steps/parallel.step.d.ts +2 -2
  27. package/dist/connectors/builtin/steps/switch.step.js +1 -1
  28. package/dist/connectors/builtin/steps/switch.step.js.map +1 -1
  29. package/dist/connectors/builtin/steps/wait.step.d.ts +30 -24
  30. package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -1
  31. package/dist/connectors/builtin/steps/wait.step.js +18 -6
  32. package/dist/connectors/builtin/steps/wait.step.js.map +1 -1
  33. package/dist/conversational-flow/calls.d.ts +2 -2
  34. package/dist/conversational-flow/calls.d.ts.map +1 -1
  35. package/dist/conversational-flow/calls.js +40 -5
  36. package/dist/conversational-flow/calls.js.map +1 -1
  37. package/dist/conversational-flow/edit/calls.d.ts.map +1 -1
  38. package/dist/conversational-flow/edit/calls.js +8 -5
  39. package/dist/conversational-flow/edit/calls.js.map +1 -1
  40. package/dist/conversational-flow/edit/endings.d.ts +8 -3
  41. package/dist/conversational-flow/edit/endings.d.ts.map +1 -1
  42. package/dist/conversational-flow/edit/endings.js +17 -9
  43. package/dist/conversational-flow/edit/endings.js.map +1 -1
  44. package/dist/conversational-flow/edit/versions.d.ts.map +1 -1
  45. package/dist/conversational-flow/edit/versions.js +6 -7
  46. package/dist/conversational-flow/edit/versions.js.map +1 -1
  47. package/dist/conversational-flow/index.d.ts +2 -1
  48. package/dist/conversational-flow/index.d.ts.map +1 -1
  49. package/dist/conversational-flow/index.js +4 -0
  50. package/dist/conversational-flow/index.js.map +1 -1
  51. package/dist/conversational-flow/read.d.ts.map +1 -1
  52. package/dist/conversational-flow/read.js +20 -4
  53. package/dist/conversational-flow/read.js.map +1 -1
  54. package/dist/conversational-flow/settle.js +4 -7
  55. package/dist/conversational-flow/settle.js.map +1 -1
  56. package/dist/conversational-flow/types.d.ts +31 -8
  57. package/dist/conversational-flow/types.d.ts.map +1 -1
  58. package/dist/conversational-flow/types.js.map +1 -1
  59. package/dist/engine/condition-evaluator.d.ts +10 -2
  60. package/dist/engine/condition-evaluator.d.ts.map +1 -1
  61. package/dist/engine/condition-evaluator.js +36 -14
  62. package/dist/engine/condition-evaluator.js.map +1 -1
  63. package/dist/engine/config-validator.d.ts +64 -0
  64. package/dist/engine/config-validator.d.ts.map +1 -1
  65. package/dist/engine/config-validator.js +371 -30
  66. package/dist/engine/config-validator.js.map +1 -1
  67. package/dist/engine/resolve-expressions.d.ts +40 -0
  68. package/dist/engine/resolve-expressions.d.ts.map +1 -0
  69. package/dist/engine/resolve-expressions.js +186 -0
  70. package/dist/engine/resolve-expressions.js.map +1 -0
  71. package/dist/engine/variable-resolver.d.ts +27 -0
  72. package/dist/engine/variable-resolver.d.ts.map +1 -1
  73. package/dist/engine/variable-resolver.js +20 -3
  74. package/dist/engine/variable-resolver.js.map +1 -1
  75. package/dist/engine/workflow-executor.d.ts.map +1 -1
  76. package/dist/engine/workflow-executor.js +33 -1
  77. package/dist/engine/workflow-executor.js.map +1 -1
  78. package/dist/expression/catalogue.d.ts +36 -0
  79. package/dist/expression/catalogue.d.ts.map +1 -0
  80. package/dist/expression/catalogue.js +82 -0
  81. package/dist/expression/catalogue.js.map +1 -0
  82. package/dist/expression/form/model.d.ts +115 -0
  83. package/dist/expression/form/model.d.ts.map +1 -0
  84. package/dist/expression/form/model.js +61 -0
  85. package/dist/expression/form/model.js.map +1 -0
  86. package/dist/expression/form/read.d.ts +4 -0
  87. package/dist/expression/form/read.d.ts.map +1 -0
  88. package/dist/expression/form/read.js +283 -0
  89. package/dist/expression/form/read.js.map +1 -0
  90. package/dist/expression/form/write.d.ts +8 -0
  91. package/dist/expression/form/write.d.ts.map +1 -0
  92. package/dist/expression/form/write.js +124 -0
  93. package/dist/expression/form/write.js.map +1 -0
  94. package/dist/expression/format.d.ts +41 -0
  95. package/dist/expression/format.d.ts.map +1 -0
  96. package/dist/expression/format.js +84 -0
  97. package/dist/expression/format.js.map +1 -0
  98. package/dist/expression/index.d.ts +40 -0
  99. package/dist/expression/index.d.ts.map +1 -0
  100. package/dist/expression/index.js +35 -0
  101. package/dist/expression/index.js.map +1 -0
  102. package/dist/expression/infer.d.ts +40 -0
  103. package/dist/expression/infer.d.ts.map +1 -0
  104. package/dist/expression/infer.js +195 -0
  105. package/dist/expression/infer.js.map +1 -0
  106. package/dist/expression/parse.d.ts +60 -0
  107. package/dist/expression/parse.d.ts.map +1 -0
  108. package/dist/expression/parse.js +201 -0
  109. package/dist/expression/parse.js.map +1 -0
  110. package/dist/expression/signature.d.ts +41 -0
  111. package/dist/expression/signature.d.ts.map +1 -0
  112. package/dist/expression/signature.js +124 -0
  113. package/dist/expression/signature.js.map +1 -0
  114. package/dist/expression/signatures.d.ts +45 -0
  115. package/dist/expression/signatures.d.ts.map +1 -0
  116. package/dist/expression/signatures.js +113 -0
  117. package/dist/expression/signatures.js.map +1 -0
  118. package/dist/expression/types.d.ts +71 -0
  119. package/dist/expression/types.d.ts.map +1 -0
  120. package/dist/expression/types.js +139 -0
  121. package/dist/expression/types.js.map +1 -0
  122. package/dist/index.d.ts +21 -2
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +22 -1
  125. package/dist/index.js.map +1 -1
  126. package/dist/ingest/filter.d.ts +8 -2
  127. package/dist/ingest/filter.d.ts.map +1 -1
  128. package/dist/ingest/filter.js +8 -2
  129. package/dist/ingest/filter.js.map +1 -1
  130. package/dist/ingest/start-policy.d.ts +1 -1
  131. package/dist/ingest/start-policy.d.ts.map +1 -1
  132. package/dist/ingest/start-policy.js +12 -5
  133. package/dist/ingest/start-policy.js.map +1 -1
  134. package/dist/runtime/workflow-runtime.d.ts.map +1 -1
  135. package/dist/runtime/workflow-runtime.js +4 -2
  136. package/dist/runtime/workflow-runtime.js.map +1 -1
  137. package/dist/types/operators.d.ts +22 -0
  138. package/dist/types/operators.d.ts.map +1 -1
  139. package/dist/types/operators.js +6 -6
  140. package/dist/types/operators.js.map +1 -1
  141. package/dist/types/validation.d.ts +10 -1
  142. package/dist/types/validation.d.ts.map +1 -1
  143. package/dist/types/validation.js +9 -0
  144. package/dist/types/validation.js.map +1 -1
  145. package/dist/types/workflow-config.d.ts +4 -3
  146. package/dist/types/workflow-config.d.ts.map +1 -1
  147. package/dist/types/workflow-config.js +23 -8
  148. package/dist/types/workflow-config.js.map +1 -1
  149. package/dist/util/computed-value.d.ts +103 -0
  150. package/dist/util/computed-value.d.ts.map +1 -0
  151. package/dist/util/computed-value.js +453 -0
  152. package/dist/util/computed-value.js.map +1 -0
  153. package/dist/util/expression-format.d.ts +41 -0
  154. package/dist/util/expression-format.d.ts.map +1 -0
  155. package/dist/util/expression-format.js +84 -0
  156. package/dist/util/expression-format.js.map +1 -0
  157. package/dist/util/expression-functions.d.ts +35 -0
  158. package/dist/util/expression-functions.d.ts.map +1 -0
  159. package/dist/util/expression-functions.js +82 -0
  160. package/dist/util/expression-functions.js.map +1 -0
  161. package/dist/util/expression.d.ts +98 -0
  162. package/dist/util/expression.d.ts.map +1 -0
  163. package/dist/util/expression.js +395 -0
  164. package/dist/util/expression.js.map +1 -0
  165. package/dist/util/jsonata-signatures.d.ts +45 -0
  166. package/dist/util/jsonata-signatures.d.ts.map +1 -0
  167. package/dist/util/jsonata-signatures.js +113 -0
  168. package/dist/util/jsonata-signatures.js.map +1 -0
  169. package/dist/util/signature.d.ts +41 -0
  170. package/dist/util/signature.d.ts.map +1 -0
  171. package/dist/util/signature.js +124 -0
  172. package/dist/util/signature.js.map +1 -0
  173. package/dist/util/type-compat.d.ts +8 -28
  174. package/dist/util/type-compat.d.ts.map +1 -1
  175. package/dist/util/type-compat.js +22 -29
  176. package/dist/util/type-compat.js.map +1 -1
  177. package/dist/util/variable-ref.d.ts +24 -0
  178. package/dist/util/variable-ref.d.ts.map +1 -1
  179. package/dist/util/variable-ref.js +34 -9
  180. package/dist/util/variable-ref.js.map +1 -1
  181. package/package.json +6 -1
@@ -65,6 +65,70 @@ export declare class ConfigValidator {
65
65
  */
66
66
  private validateCitations;
67
67
  private validateRefs;
68
+ /**
69
+ * Expressions in a step's own config: can they be read, may they run, and do
70
+ * the references inside them lead anywhere.
71
+ *
72
+ * Three checks, in the order that makes the *first* message the useful one —
73
+ * there is no point reporting an unknown reference inside an expression that
74
+ * does not parse.
75
+ */
76
+ /**
77
+ * A reference's type, as an expression sees it.
78
+ *
79
+ * Only the explicit roots: inside `{% … %}` there is no bare-step shorthand,
80
+ * which is what makes a leading name unambiguous there. `workflow` and
81
+ * `execution` describe nothing, so they read as unknown — same as a `{{ref}}`
82
+ * into them is left unchecked.
83
+ */
84
+ private expressionTypes;
85
+ /**
86
+ * Every check that applies to one expression, wherever it sits.
87
+ *
88
+ * One method rather than one per surface, because "is this expression valid"
89
+ * must not have two answers. It was a per-step walk first, which left the
90
+ * trigger's filter and its delayed-start anchor evaluating expressions that
91
+ * nothing had read — no syntax check, no ban on naming a function, no types.
92
+ *
93
+ * `consumer` is the Zod schema the result is bound into, or null where there
94
+ * is nothing to bind to (a condition's own slot, a reference inside another
95
+ * expression).
96
+ *
97
+ * Returns what the expression produces, so a caller with a rule of its own can
98
+ * apply it — a delayed start, for instance, knows that a list can never be a
99
+ * moment in time, which no schema of `z.string()` will ever say.
100
+ */
101
+ private checkExpression;
102
+ /** Every expression in a step's own config, checked where it sits. */
103
+ private validateExpressions;
104
+ /**
105
+ * What a condition's left side will produce, as far as can be told.
106
+ *
107
+ * An expression's type is computed; a reference's is read from the schema. A
108
+ * literal cannot appear here — the schema accepts only the two.
109
+ */
110
+ private conditionVariableType;
111
+ /**
112
+ * One condition leaf: can its operator hold against what is on the left?
113
+ *
114
+ * Only where the operator is unambiguous about it — see `needs` on
115
+ * `OperatorDescriptor`. "is greater than" against text, or "starts with"
116
+ * against a number, is not a near miss: the comparison can never be true, so
117
+ * the branch is unreachable and the author almost certainly meant something
118
+ * else.
119
+ *
120
+ * Deliberately *not* checked: the comparison value against the left side.
121
+ * `looseEquals` coerces on purpose — `5` equals `"5"` here — so refusing a
122
+ * number against text would refuse something that works.
123
+ */
124
+ private checkConditionLeaf;
125
+ /**
126
+ * Every condition leaf reachable in a value.
127
+ *
128
+ * Conditions are found structurally, by the same predicate the resolver and
129
+ * the expression pre-pass use, so the three cannot disagree about what one is.
130
+ */
131
+ private validateConditions;
68
132
  private checkRef;
69
133
  private getConsumerInnerSchema;
70
134
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config-validator.d.ts","sourceRoot":"","sources":["../../src/engine/config-validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,6BAA6B,CAAC;AAQrC,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAElF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AA0Q9D;;;;;;;;;GASG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,iBAAiB;IAGhD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,EAAE;IAclD,OAAO,CAAC,YAAY;IAiCpB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB;IA8DlD,OAAO,CAAC,SAAS;IAmHjB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA2B5B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAwD5B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IA+C7B;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IA0CpB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IA8CzB,OAAO,CAAC,YAAY;IA4BpB,OAAO,CAAC,QAAQ;IAqGhB,OAAO,CAAC,sBAAsB;CAmB/B"}
1
+ {"version":3,"file":"config-validator.d.ts","sourceRoot":"","sources":["../../src/engine/config-validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,6BAA6B,CAAC;AAQrC,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAElF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AA+V9D;;;;;;;;;GASG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,iBAAiB;IAGhD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,EAAE;IAclD,OAAO,CAAC,YAAY;IAiCpB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB;IA8DlD,OAAO,CAAC,SAAS;IA4IjB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA2B5B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAmG5B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IA0F7B;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IA0CpB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IA8CzB,OAAO,CAAC,YAAY;IA4BpB;;;;;;;OAOG;IACH;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IA6BvB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,eAAe;IAkEvB,sEAAsE;IACtE,OAAO,CAAC,mBAAmB;IAuB3B;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAW7B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAyC1B,OAAO,CAAC,QAAQ;IAiHhB,OAAO,CAAC,sBAAsB;CAmB/B"}
@@ -7,8 +7,14 @@ import { ValidationIssueCode } from '../types/validation.js';
7
7
  import { BaseControlFlowStep } from '../steps/base-step.js';
8
8
  import { isJumpingStep } from './branch-signal.js';
9
9
  import { collectRefs, isPureRef } from '../util/variable-ref.js';
10
+ import { OPERATOR_DESCRIPTORS } from '../types/operators.js';
11
+ import { isCondition } from './variable-resolver.js';
12
+ import { inspectExpression, refsInExpression } from '../expression/parse.js';
13
+ import { inferExpressionType } from '../expression/infer.js';
14
+ import { collectExpressions, extractExpressionSource } from '../expression/format.js';
10
15
  import { zodToJsonSchemaRecord } from '../util/schema-convert.js';
11
- import { kindsCompatible } from '../util/type-compat.js';
16
+ import { kindOfJsonType, kindsCompatible } from '../util/type-compat.js';
17
+ import { assignableToArgument, assignableToField, baseKind, sayType } from '../expression/types.js';
12
18
  import { resolveOutputJsonSchemaOf } from './available-context.js';
13
19
  import { varsJsonSchema } from '../types/workflow-variable.js';
14
20
  const FORBIDDEN_KEYS = new Set([
@@ -133,11 +139,25 @@ function unwrapJsonSchema(schema) {
133
139
  * `additionalProperties`) — those can't be statically known and resolve
134
140
  * dynamically at runtime (e.g. an HTTP `body` with no author-declared shape).
135
141
  */
136
- function walkJsonSchemaPath(schema, segments) {
142
+ function walkJsonSchemaPath(schema, segments,
143
+ /**
144
+ * Treat a property access on an array as reading that property from each
145
+ * element — JSONata's rule, and NOT the `{{ref}}` rule, so it is off by
146
+ * default.
147
+ *
148
+ * `{{steps.a.output.items.amount}}` really is wrong: `resolvePath` does a
149
+ * property lookup on the array itself and finds nothing. The same path inside
150
+ * an expression is right, and is how anyone would write "the amounts" before
151
+ * summing them. The two grammars genuinely differ here, so the walk has to be
152
+ * told which one it is serving — otherwise the validator rejects every
153
+ * correct `$sum` over a list.
154
+ */
155
+ mapArrays = false) {
137
156
  if (segments.some((s) => FORBIDDEN_KEYS.has(s)))
138
157
  return null;
139
158
  let current = schema;
140
- for (const segment of segments) {
159
+ for (let i = 0; i < segments.length; i++) {
160
+ const segment = segments[i];
141
161
  current = unwrapJsonSchema(current);
142
162
  const type = current['type'];
143
163
  const props = current['properties'];
@@ -167,6 +187,11 @@ function walkJsonSchemaPath(schema, segments) {
167
187
  current = items ?? {};
168
188
  continue;
169
189
  }
190
+ // Re-read this same segment against the element schema; an array with no
191
+ // declared `items` has unknown elements, so the rest is unverifiable.
192
+ if (mapArrays) {
193
+ return items ? walkJsonSchemaPath(items, segments.slice(i), true) : {};
194
+ }
170
195
  return null;
171
196
  }
172
197
  // Scalar with a further segment — can't index into it.
@@ -174,15 +199,66 @@ function walkJsonSchemaPath(schema, segments) {
174
199
  }
175
200
  return unwrapJsonSchema(current);
176
201
  }
202
+ /**
203
+ * What a reference inside an expression evaluates to, including whether it is a
204
+ * *list* of that thing.
205
+ *
206
+ * Separate from {@link walkJsonSchemaPath} because the two answer different
207
+ * questions. That one asks "does this path exist", and returns the leaf. This
208
+ * asks "what will JSONata hand back", and the difference is the array step:
209
+ * `items.amount` over a list of objects does not give a number, it gives a
210
+ * number for *each* item — so the type is a list of numbers, which is exactly
211
+ * what makes `$sum` of it legal and `$round` of it not.
212
+ *
213
+ * `undefined` means "cannot be read", never "wrong": a freeform node, an
214
+ * undeclared property, a path through something scalar. The caller turns that
215
+ * into `unknown`, which checks nothing.
216
+ */
217
+ /** How many nested lists a single path step will be followed through. */
218
+ const MAX_SCHEMA_DEPTH = 10;
219
+ function expressionPathType(schema, segments) {
220
+ if (segments.some((segment) => FORBIDDEN_KEYS.has(segment)))
221
+ return undefined;
222
+ let current = schema;
223
+ /** Set once the path steps through a list, because results then come as one. */
224
+ let mapped = false;
225
+ for (const segment of segments) {
226
+ // Step through any number of nested lists before looking for the segment:
227
+ // in JSONata a property access reaches the elements, however deep the
228
+ // nesting goes. Bounded so that a self-referential schema cannot spin.
229
+ for (let unwrapped = 0; unwrapped < MAX_SCHEMA_DEPTH; unwrapped++) {
230
+ current = unwrapJsonSchema(current);
231
+ if (current['type'] !== 'array')
232
+ break;
233
+ const items = current['items'];
234
+ if (!items)
235
+ return undefined; // elements never declared
236
+ mapped = true;
237
+ current = items;
238
+ }
239
+ const props = current['properties'];
240
+ if (!props || !Object.prototype.hasOwnProperty.call(props, segment)) {
241
+ return undefined; // freeform, open record, or simply not declared
242
+ }
243
+ current = props[segment];
244
+ }
245
+ const leaf = unwrapJsonSchema(current);
246
+ const leafItems = leaf['items'];
247
+ const type = jsonSchemaKind(leaf) === 'array'
248
+ ? { array: leafItems ? jsonSchemaKind(unwrapJsonSchema(leafItems)) : 'unknown' }
249
+ : jsonSchemaKind(leaf);
250
+ // A list of lists is flattened by JSONata, so mapping an already-list leaf
251
+ // changes nothing.
252
+ return mapped && baseKind(type) !== 'array' ? { array: type } : type;
253
+ }
177
254
  /** Coarse kind of a JSON-schema leaf, for loose type compatibility. */
255
+ /**
256
+ * A schema node's kind. The rule lives in {@link kindOfJsonType}; this is the
257
+ * node-shaped way to ask it, which is what a schema walk has in hand.
258
+ */
178
259
  function jsonSchemaKind(schema) {
179
- const t = schema['type'];
180
- if (t === 'integer')
181
- return 'number';
182
- if (t === 'string' || t === 'number' || t === 'boolean' || t === 'array' || t === 'object') {
183
- return t;
184
- }
185
- return 'unknown'; // no type / union / freeform
260
+ const declared = schema['type'];
261
+ return kindOfJsonType(typeof declared === 'string' ? declared : undefined);
186
262
  }
187
263
  const JSON_HUMAN_TYPE = {
188
264
  string: 'text',
@@ -342,7 +418,7 @@ export class ConfigValidator {
342
418
  this.checkCredentialSlots(triggerImpl.credentialSlots, config.trigger.config, 'trigger.config', { scope: 'trigger' }, issues);
343
419
  outputSchemas.set('trigger', resolveOutputJsonSchemaOf(triggerImpl, (config.trigger.config ?? {})));
344
420
  }
345
- this.validateTriggerFilter(config.trigger.filter, issues);
421
+ this.validateTriggerFilter(config.trigger.filter, outputSchemas, issues);
346
422
  this.validateTriggerStart(config.trigger.start, outputSchemas, issues);
347
423
  }
348
424
  // --- Steps validation ---
@@ -392,8 +468,15 @@ export class ConfigValidator {
392
468
  const branches = stepImpl instanceof BaseControlFlowStep && stepImpl.getBranches
393
469
  ? stepImpl.getBranches(stepConfig)
394
470
  : undefined;
395
- // Ref validation for the step's own config
396
- this.validateRefs(stepConfig, `${stepPath}.config`, stepImpl.configSchema, outputSchemas, issues, step.id, branches ? new Set(Object.values(branches)) : undefined);
471
+ // Ref and expression validation for the step's own config. A control
472
+ // step's branch arrays are left out of both — their steps are checked in
473
+ // their own scope, where the refs visible to them are known.
474
+ const ownScopeOnly = branches
475
+ ? new Set(Object.values(branches))
476
+ : undefined;
477
+ this.validateRefs(stepConfig, `${stepPath}.config`, stepImpl.configSchema, outputSchemas, issues, step.id, ownScopeOnly);
478
+ this.validateExpressions(stepConfig, `${stepPath}.config`, stepImpl.configSchema, outputSchemas, issues, step.id, ownScopeOnly);
479
+ this.validateConditions(stepConfig, `${stepPath}.config`, { scope: 'step', stepId: step.id }, outputSchemas, issues, ownScopeOnly);
397
480
  if (isJumpingStep(stepImpl)) {
398
481
  this.validateJump(step, stepPath, stepImpl.jumpKind, enclosing, issues);
399
482
  }
@@ -470,6 +553,41 @@ export class ConfigValidator {
470
553
  }
471
554
  if (parsed.data.kind !== 'at')
472
555
  return;
556
+ // Worked out rather than read. `readAnchor` resolves an expression here, so
557
+ // it gets the same reading as one anywhere else — including whether what it
558
+ // produces can be a moment in time.
559
+ const computed = extractExpressionSource(parsed.data.anchor);
560
+ if (computed !== null) {
561
+ // No consumer schema: the anchor is declared `z.string()`, and text is the
562
+ // universal sink, so a generic field check here would accept everything.
563
+ // The real rule is the one below, which is the same one the reference
564
+ // branch applies.
565
+ const produced = this.checkExpression(computed, 'trigger.start.anchor', location, outputSchemas, issues, null);
566
+ const kind = baseKind(produced);
567
+ if (kind === 'boolean' || kind === 'object' || kind === 'array') {
568
+ issues.push({
569
+ path: 'trigger.start.anchor',
570
+ code: ValidationIssueCode.TYPE_MISMATCH,
571
+ message: `{% ${computed} %} gives ${sayType(produced)}, which cannot be a date and time.`,
572
+ location,
573
+ });
574
+ }
575
+ // The same confinement the schema puts on a plain reference, extended to
576
+ // every reference inside the expression: before a run there is nothing
577
+ // but the event and the workflow's variables.
578
+ for (const refPath of refsInExpression(computed)) {
579
+ const head = refPath.split('.')[0];
580
+ if (head !== 'trigger' && head !== 'vars') {
581
+ issues.push({
582
+ path: 'trigger.start.anchor',
583
+ code: ValidationIssueCode.SHAPE,
584
+ message: `An anchor can only read trigger data or a workflow variable, not "${refPath}"`,
585
+ location,
586
+ });
587
+ }
588
+ }
589
+ return;
590
+ }
473
591
  // A literal timestamp passes the schema above and has nothing to resolve;
474
592
  // checkRef ignores anything that is not a reference.
475
593
  const before = issues.length;
@@ -503,7 +621,7 @@ export class ConfigValidator {
503
621
  * A trigger filter must be well formed, and may only read what exists before
504
622
  * a run: the trigger's output and workflow variables.
505
623
  */
506
- validateTriggerFilter(filter, issues) {
624
+ validateTriggerFilter(filter, outputSchemas, issues) {
507
625
  if (filter === undefined)
508
626
  return;
509
627
  const location = { scope: 'trigger', field: 'filter' };
@@ -528,6 +646,34 @@ export class ConfigValidator {
528
646
  condition.any.forEach((child, i) => visit(child, `${path}.any[${i}]`));
529
647
  return;
530
648
  }
649
+ /**
650
+ * A filter may only read what exists before a run — the event's payload
651
+ * and the workflow's variables. There are no step outputs yet.
652
+ *
653
+ * Enforced over *every* reference rather than just the leading one, so
654
+ * that an expression cannot reach further than a plain reference can.
655
+ */
656
+ const confine = (refPath, said) => {
657
+ const head = refPath.split('.')[0];
658
+ if (head !== 'trigger' && head !== 'vars') {
659
+ issues.push({
660
+ path: `${path}.variable`,
661
+ code: ValidationIssueCode.INVALID_FILTER,
662
+ message: `Filters can only use trigger data and workflow variables, not "${said}"`,
663
+ location,
664
+ });
665
+ }
666
+ };
667
+ // Something worked out, rather than read. The schema accepts one here and
668
+ // `ConditionEvaluator` evaluates it, so refusing it as "no value chosen"
669
+ // — which is what reading it as a reference used to do — was wrong.
670
+ const computed = extractExpressionSource(condition.variable);
671
+ if (computed !== null) {
672
+ this.checkExpression(computed, `${path}.variable`, location, outputSchemas, issues, null);
673
+ for (const refPath of refsInExpression(computed))
674
+ confine(refPath, refPath);
675
+ return;
676
+ }
531
677
  const refPath = extractRefPath(condition.variable);
532
678
  if (!refPath) {
533
679
  issues.push({
@@ -538,18 +684,14 @@ export class ConfigValidator {
538
684
  });
539
685
  return;
540
686
  }
541
- const head = refPath.split('.')[0];
542
- if (head !== 'trigger' && head !== 'vars') {
543
- issues.push({
544
- path: `${path}.variable`,
545
- code: ValidationIssueCode.INVALID_FILTER,
546
- message: `Filters can only use trigger data and workflow variables, not "{{${refPath}}}"`,
547
- location,
548
- });
549
- }
687
+ confine(refPath, `{{${refPath}}}`);
550
688
  };
551
- if (parsed.data.conditions)
689
+ if (parsed.data.conditions) {
552
690
  visit(parsed.data.conditions, 'trigger.filter.conditions');
691
+ // The same reading a step's conditions get: an operator that can never
692
+ // hold is a filter that can never admit anything.
693
+ this.validateConditions(parsed.data.conditions, 'trigger.filter.conditions', location, outputSchemas, issues);
694
+ }
553
695
  }
554
696
  /**
555
697
  * A GO_TO/FINISH must name a step around it that catches jumps
@@ -637,11 +779,210 @@ export class ConfigValidator {
637
779
  stepRefLocation(stepId, prefix, location));
638
780
  }
639
781
  }
640
- checkRef(refString, location, outputSchemas, issues, consumerInnerSchema, issueLocation) {
782
+ /**
783
+ * Expressions in a step's own config: can they be read, may they run, and do
784
+ * the references inside them lead anywhere.
785
+ *
786
+ * Three checks, in the order that makes the *first* message the useful one —
787
+ * there is no point reporting an unknown reference inside an expression that
788
+ * does not parse.
789
+ */
790
+ /**
791
+ * A reference's type, as an expression sees it.
792
+ *
793
+ * Only the explicit roots: inside `{% … %}` there is no bare-step shorthand,
794
+ * which is what makes a leading name unambiguous there. `workflow` and
795
+ * `execution` describe nothing, so they read as unknown — same as a `{{ref}}`
796
+ * into them is left unchecked.
797
+ */
798
+ expressionTypes(outputSchemas) {
799
+ return (path) => {
800
+ const segments = path.split('.').filter((segment) => segment.length > 0);
801
+ const head = segments[0];
802
+ if (head === 'trigger') {
803
+ const schema = outputSchemas.get('trigger');
804
+ return schema ? expressionPathType(schema, segments.slice(1)) : undefined;
805
+ }
806
+ if (head === 'vars') {
807
+ const schema = outputSchemas.get('vars');
808
+ return schema ? expressionPathType(schema, segments.slice(1)) : undefined;
809
+ }
810
+ if (head === 'steps') {
811
+ const stepId = segments[1];
812
+ if (!stepId)
813
+ return undefined;
814
+ const role = segments[2];
815
+ const addressed = role === 'input' || role === 'output';
816
+ const schema = outputSchemas.get(addressed ? `${stepId}.${role}` : `${stepId}.output`);
817
+ return schema
818
+ ? expressionPathType(schema, segments.slice(addressed ? 3 : 2))
819
+ : undefined;
820
+ }
821
+ return undefined;
822
+ };
823
+ }
824
+ /**
825
+ * Every check that applies to one expression, wherever it sits.
826
+ *
827
+ * One method rather than one per surface, because "is this expression valid"
828
+ * must not have two answers. It was a per-step walk first, which left the
829
+ * trigger's filter and its delayed-start anchor evaluating expressions that
830
+ * nothing had read — no syntax check, no ban on naming a function, no types.
831
+ *
832
+ * `consumer` is the Zod schema the result is bound into, or null where there
833
+ * is nothing to bind to (a condition's own slot, a reference inside another
834
+ * expression).
835
+ *
836
+ * Returns what the expression produces, so a caller with a rule of its own can
837
+ * apply it — a delayed start, for instance, knows that a list can never be a
838
+ * moment in time, which no schema of `z.string()` will ever say.
839
+ */
840
+ checkExpression(source, path, location, outputSchemas, issues, consumer) {
841
+ const fault = inspectExpression(source);
842
+ if (fault) {
843
+ issues.push({
844
+ path,
845
+ code: ValidationIssueCode.INVALID_EXPRESSION,
846
+ message: `{% ${source} %} — ${fault.message}`,
847
+ location,
848
+ });
849
+ return 'unknown';
850
+ }
851
+ // Existence and ordering of each reference — note the `null` consumer
852
+ // schema passed on. A reference inside an expression is NOT bound to the
853
+ // field: the expression transforms it, so `$sum` over a list of numbers
854
+ // belongs in a number field even though the list does not. Whether the
855
+ // *result* fits is a separate question, answered below.
856
+ for (const refPath of refsInExpression(source)) {
857
+ this.checkRef(`{{context.${refPath}}}`, path, outputSchemas, issues, null, location, source);
858
+ }
859
+ // What the expression produces, and what it misuses getting there. This is
860
+ // what makes the typing promise hold *before* a run: without it the engine
861
+ // leans on JSONata's own signature errors and on zod rejecting the result,
862
+ // which are both correct and both too late to help anyone writing.
863
+ const { type, faults } = inferExpressionType(source, this.expressionTypes(outputSchemas));
864
+ for (const typeFault of faults) {
865
+ issues.push({
866
+ path,
867
+ code: ValidationIssueCode.TYPE_MISMATCH,
868
+ message: `{% ${source} %} — ${typeFault.message}`,
869
+ location,
870
+ });
871
+ }
872
+ // Only when the inside is sound: one mistake should be reported once, and a
873
+ // bad argument already explains the wrong result.
874
+ if (faults.length === 0 && consumer !== null) {
875
+ if (!assignableToField(type, zodConsumerKind(consumer))) {
876
+ issues.push({
877
+ path,
878
+ code: ValidationIssueCode.TYPE_MISMATCH,
879
+ message: `{% ${source} %} gives ${sayType(type)}, but this field expects a ${humanZodType(consumer)}.`,
880
+ location,
881
+ });
882
+ }
883
+ }
884
+ return type;
885
+ }
886
+ /** Every expression in a step's own config, checked where it sits. */
887
+ validateExpressions(config, prefix, configSchema, outputSchemas, issues, stepId, skip) {
888
+ // Conditions included — a condition's own slots accept an expression, which
889
+ // `ConditionEvaluator` resolves.
890
+ for (const { source, location } of collectExpressions(config, prefix, skip)) {
891
+ this.checkExpression(source, location, stepRefLocation(stepId, prefix, location), outputSchemas, issues, this.getConsumerInnerSchema(configSchema, location, prefix));
892
+ }
893
+ }
894
+ /**
895
+ * What a condition's left side will produce, as far as can be told.
896
+ *
897
+ * An expression's type is computed; a reference's is read from the schema. A
898
+ * literal cannot appear here — the schema accepts only the two.
899
+ */
900
+ conditionVariableType(variable, outputSchemas) {
901
+ const lookup = this.expressionTypes(outputSchemas);
902
+ const computed = extractExpressionSource(variable);
903
+ if (computed !== null)
904
+ return inferExpressionType(computed, lookup).type;
905
+ const refPath = extractRefPath(variable);
906
+ return refPath === null ? 'unknown' : (lookup(refPath) ?? 'unknown');
907
+ }
908
+ /**
909
+ * One condition leaf: can its operator hold against what is on the left?
910
+ *
911
+ * Only where the operator is unambiguous about it — see `needs` on
912
+ * `OperatorDescriptor`. "is greater than" against text, or "starts with"
913
+ * against a number, is not a near miss: the comparison can never be true, so
914
+ * the branch is unreachable and the author almost certainly meant something
915
+ * else.
916
+ *
917
+ * Deliberately *not* checked: the comparison value against the left side.
918
+ * `looseEquals` coerces on purpose — `5` equals `"5"` here — so refusing a
919
+ * number against text would refuse something that works.
920
+ */
921
+ checkConditionLeaf(leaf, path, location, outputSchemas, issues) {
922
+ const descriptor = OPERATOR_DESCRIPTORS.find((entry) => entry.value === leaf.operator);
923
+ const needs = descriptor?.needs;
924
+ if (descriptor === undefined || needs === undefined)
925
+ return;
926
+ const type = this.conditionVariableType(leaf.variable, outputSchemas);
927
+ if (assignableToArgument(type, needs))
928
+ return;
929
+ issues.push({
930
+ path: `${path}.variable`,
931
+ code: ValidationIssueCode.TYPE_MISMATCH,
932
+ message: `"${descriptor.label}" needs ${sayType(needs)}, but this is ${sayType(type)} — the condition can never be true.`,
933
+ location,
934
+ });
935
+ }
936
+ /**
937
+ * Every condition leaf reachable in a value.
938
+ *
939
+ * Conditions are found structurally, by the same predicate the resolver and
940
+ * the expression pre-pass use, so the three cannot disagree about what one is.
941
+ */
942
+ validateConditions(value, prefix, location, outputSchemas, issues, skip) {
943
+ const walk = (node, path) => {
944
+ if (skip?.has(node))
945
+ return;
946
+ if (Array.isArray(node)) {
947
+ node.forEach((item, index) => walk(item, `${path}[${index}]`));
948
+ return;
949
+ }
950
+ if (node === null || typeof node !== 'object')
951
+ return;
952
+ const record = node;
953
+ if (isCondition(record)) {
954
+ for (const join of ['all', 'any']) {
955
+ const parts = record[join];
956
+ if (Array.isArray(parts)) {
957
+ parts.forEach((part, index) => walk(part, `${path}.${join}[${index}]`));
958
+ return;
959
+ }
960
+ }
961
+ this.checkConditionLeaf(record, path, location, outputSchemas, issues);
962
+ return;
963
+ }
964
+ for (const [key, child] of Object.entries(record)) {
965
+ walk(child, path ? `${path}.${key}` : key);
966
+ }
967
+ };
968
+ walk(value, prefix);
969
+ }
970
+ checkRef(refString, location, outputSchemas, issues, consumerInnerSchema, issueLocation,
971
+ /**
972
+ * The expression this reference came out of, when it did.
973
+ *
974
+ * One parameter rather than two flags, because both differences it causes
975
+ * have the same cause: a path inside an expression maps over arrays, and
976
+ * the author never wrote `{{context....}}`, so quoting it back at them
977
+ * would be a riddle. Callers pass the reference in `{{...}}` form either
978
+ * way so that the parsing below stays single-form.
979
+ */
980
+ expression) {
641
981
  const inner = refString.match(/^\{\{(?:context\.)?([^}]+)\}\}$/);
642
982
  if (!inner?.[1])
643
983
  return;
644
984
  const refPath = inner[1];
985
+ const display = expression !== undefined ? `"${refPath}" in {% ${expression} %}` : `"${refString}"`;
645
986
  const segments = refPath.split('.');
646
987
  const sourceKey = segments[0];
647
988
  if (!sourceKey)
@@ -682,7 +1023,7 @@ export class ConfigValidator {
682
1023
  issues.push({
683
1024
  path: location,
684
1025
  code: ValidationIssueCode.UNKNOWN_REFERENCE,
685
- message: `"${refString}" references an undeclared workflow variable "vars.${key ?? ''}". Declare it in the workflow's Variables.`,
1026
+ message: `${display} references an undeclared workflow variable "vars.${key ?? ''}". Declare it in the workflow's Variables.`,
686
1027
  location: issueLocation,
687
1028
  });
688
1029
  }
@@ -704,18 +1045,18 @@ export class ConfigValidator {
704
1045
  issues.push({
705
1046
  path: location,
706
1047
  code: ValidationIssueCode.FORWARD_REFERENCE,
707
- message: `"${refString}" references "${sourceKey}" which is not yet available at this point in the workflow (forward reference, or unknown step / trigger ID).`,
1048
+ message: `${display} references "${sourceKey}" which is not yet available at this point in the workflow (forward reference, or unknown step / trigger ID).`,
708
1049
  location: issueLocation,
709
1050
  });
710
1051
  return;
711
1052
  }
712
1053
  const sourceSchema = outputSchemas.get(resolverKey);
713
- const leafSchema = walkJsonSchemaPath(sourceSchema, pathSegments);
1054
+ const leafSchema = walkJsonSchemaPath(sourceSchema, pathSegments, expression !== undefined);
714
1055
  if (leafSchema === null) {
715
1056
  issues.push({
716
1057
  path: location,
717
1058
  code: ValidationIssueCode.UNKNOWN_REFERENCE,
718
- message: `"${refString}" — path "${pathSegments.join('.')}" does not exist in the schema of "${resolverKey}".`,
1059
+ message: `${display} — path "${pathSegments.join('.')}" does not exist in the schema of "${resolverKey}".`,
719
1060
  location: issueLocation,
720
1061
  });
721
1062
  return;
@@ -725,7 +1066,7 @@ export class ConfigValidator {
725
1066
  issues.push({
726
1067
  path: location,
727
1068
  code: ValidationIssueCode.TYPE_MISMATCH,
728
- message: `"${refString}" is a ${humanJsonType(leafSchema)} but this field expects a ${humanZodType(consumerInnerSchema)}.`,
1069
+ message: `${display} is a ${humanJsonType(leafSchema)} but this field expects a ${humanZodType(consumerInnerSchema)}.`,
729
1070
  location: issueLocation,
730
1071
  });
731
1072
  }