@xyne/workflow-sdk 3.2.53 → 3.2.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/host-agent-step.d.ts.map +1 -1
- package/dist/agents/host-agent-step.js +3 -0
- package/dist/agents/host-agent-step.js.map +1 -1
- package/dist/builder/index.d.ts +19 -2
- package/dist/builder/index.d.ts.map +1 -1
- package/dist/builder/index.js +17 -1
- package/dist/builder/index.js.map +1 -1
- package/dist/common/attachment.d.ts +9 -0
- package/dist/common/attachment.d.ts.map +1 -1
- package/dist/common/attachment.js +20 -0
- package/dist/common/attachment.js.map +1 -1
- package/dist/common/citation-ref.d.ts +4 -4
- package/dist/completion/address.d.ts +27 -0
- package/dist/completion/address.d.ts.map +1 -0
- package/dist/completion/address.js +62 -0
- package/dist/completion/address.js.map +1 -0
- package/dist/completion/attach.d.ts +32 -0
- package/dist/completion/attach.d.ts.map +1 -0
- package/dist/completion/attach.js +92 -0
- package/dist/completion/attach.js.map +1 -0
- package/dist/completion/index.d.ts +6 -0
- package/dist/completion/index.d.ts.map +1 -0
- package/dist/completion/index.js +4 -0
- package/dist/completion/index.js.map +1 -0
- package/dist/completion/types.d.ts +107 -0
- package/dist/completion/types.d.ts.map +1 -0
- package/dist/completion/types.js +35 -0
- package/dist/completion/types.js.map +1 -0
- package/dist/connectors/builtin/builtin-connector.d.ts.map +1 -1
- package/dist/connectors/builtin/builtin-connector.js +6 -2
- package/dist/connectors/builtin/builtin-connector.js.map +1 -1
- package/dist/connectors/builtin/steps/compute.step.d.ts +56 -0
- package/dist/connectors/builtin/steps/compute.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/compute.step.js +48 -0
- package/dist/connectors/builtin/steps/compute.step.js.map +1 -0
- package/dist/connectors/builtin/steps/conditional.step.d.ts +2 -2
- package/dist/connectors/builtin/steps/conditional.step.js +1 -1
- package/dist/connectors/builtin/steps/conditional.step.js.map +1 -1
- package/dist/connectors/builtin/steps/cycle.step.d.ts +36 -7
- package/dist/connectors/builtin/steps/cycle.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/cycle.step.js +89 -8
- package/dist/connectors/builtin/steps/cycle.step.js.map +1 -1
- package/dist/connectors/builtin/steps/dedup.step.js +2 -2
- package/dist/connectors/builtin/steps/dedup.step.js.map +1 -1
- package/dist/connectors/builtin/steps/delay.step.d.ts +49 -0
- package/dist/connectors/builtin/steps/delay.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/delay.step.js +40 -0
- package/dist/connectors/builtin/steps/delay.step.js.map +1 -0
- package/dist/connectors/builtin/steps/loop.step.d.ts +6 -6
- package/dist/connectors/builtin/steps/loop.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/loop.step.js +4 -2
- package/dist/connectors/builtin/steps/loop.step.js.map +1 -1
- package/dist/connectors/builtin/steps/map.step.d.ts +4 -4
- package/dist/connectors/builtin/steps/map.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/map.step.js +13 -4
- package/dist/connectors/builtin/steps/map.step.js.map +1 -1
- package/dist/connectors/builtin/steps/parallel.step.d.ts +2 -2
- package/dist/connectors/builtin/steps/parallel.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/parallel.step.js +9 -2
- package/dist/connectors/builtin/steps/parallel.step.js.map +1 -1
- package/dist/connectors/builtin/steps/switch.step.js +1 -1
- package/dist/connectors/builtin/steps/switch.step.js.map +1 -1
- package/dist/connectors/builtin/steps/wait-for-api-call.step.d.ts +80 -0
- package/dist/connectors/builtin/steps/wait-for-api-call.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/wait-for-api-call.step.js +104 -0
- package/dist/connectors/builtin/steps/wait-for-api-call.step.js.map +1 -0
- package/dist/connectors/builtin/steps/wait-for-human.step.d.ts +1057 -0
- package/dist/connectors/builtin/steps/wait-for-human.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/wait-for-human.step.js +222 -0
- package/dist/connectors/builtin/steps/wait-for-human.step.js.map +1 -0
- package/dist/connectors/builtin/steps/wait-for-webhook.step.d.ts +80 -0
- package/dist/connectors/builtin/steps/wait-for-webhook.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/wait-for-webhook.step.js +104 -0
- package/dist/connectors/builtin/steps/wait-for-webhook.step.js.map +1 -0
- package/dist/connectors/builtin/steps/wait.step.d.ts +40 -59
- package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/wait.step.js +29 -63
- package/dist/connectors/builtin/steps/wait.step.js.map +1 -1
- package/dist/conversational-flow/calls.d.ts +2 -2
- package/dist/conversational-flow/calls.d.ts.map +1 -1
- package/dist/conversational-flow/calls.js +40 -5
- package/dist/conversational-flow/calls.js.map +1 -1
- package/dist/conversational-flow/create.d.ts +2 -1
- package/dist/conversational-flow/create.d.ts.map +1 -1
- package/dist/conversational-flow/create.js +2 -2
- package/dist/conversational-flow/create.js.map +1 -1
- package/dist/conversational-flow/edit/build.js +1 -1
- package/dist/conversational-flow/edit/build.js.map +1 -1
- package/dist/conversational-flow/edit/calls.d.ts.map +1 -1
- package/dist/conversational-flow/edit/calls.js +8 -5
- package/dist/conversational-flow/edit/calls.js.map +1 -1
- package/dist/conversational-flow/edit/endings.d.ts +8 -3
- package/dist/conversational-flow/edit/endings.d.ts.map +1 -1
- package/dist/conversational-flow/edit/endings.js +17 -9
- package/dist/conversational-flow/edit/endings.js.map +1 -1
- package/dist/conversational-flow/edit/questions.d.ts +35 -0
- package/dist/conversational-flow/edit/questions.d.ts.map +1 -0
- package/dist/conversational-flow/edit/questions.js +188 -0
- package/dist/conversational-flow/edit/questions.js.map +1 -0
- package/dist/conversational-flow/edit/versions.d.ts.map +1 -1
- package/dist/conversational-flow/edit/versions.js +6 -7
- package/dist/conversational-flow/edit/versions.js.map +1 -1
- package/dist/conversational-flow/index.d.ts +2 -1
- package/dist/conversational-flow/index.d.ts.map +1 -1
- package/dist/conversational-flow/index.js +4 -0
- package/dist/conversational-flow/index.js.map +1 -1
- package/dist/conversational-flow/questions.d.ts +32 -0
- package/dist/conversational-flow/questions.d.ts.map +1 -0
- package/dist/conversational-flow/questions.js +122 -0
- package/dist/conversational-flow/questions.js.map +1 -0
- package/dist/conversational-flow/read.d.ts.map +1 -1
- package/dist/conversational-flow/read.js +20 -4
- package/dist/conversational-flow/read.js.map +1 -1
- package/dist/conversational-flow/settle.js +4 -7
- package/dist/conversational-flow/settle.js.map +1 -1
- package/dist/conversational-flow/types.d.ts +31 -8
- package/dist/conversational-flow/types.d.ts.map +1 -1
- package/dist/conversational-flow/types.js.map +1 -1
- package/dist/engine/condition-evaluator.d.ts +10 -2
- package/dist/engine/condition-evaluator.d.ts.map +1 -1
- package/dist/engine/condition-evaluator.js +36 -14
- package/dist/engine/condition-evaluator.js.map +1 -1
- package/dist/engine/config-validator.d.ts +64 -0
- package/dist/engine/config-validator.d.ts.map +1 -1
- package/dist/engine/config-validator.js +400 -30
- package/dist/engine/config-validator.js.map +1 -1
- package/dist/engine/pause-step.d.ts +21 -4
- package/dist/engine/pause-step.d.ts.map +1 -1
- package/dist/engine/pause-step.js +11 -2
- package/dist/engine/pause-step.js.map +1 -1
- package/dist/engine/read-config.d.ts +12 -0
- package/dist/engine/read-config.d.ts.map +1 -0
- package/dist/engine/read-config.js +50 -0
- package/dist/engine/read-config.js.map +1 -0
- package/dist/engine/resolve-expressions.d.ts +40 -0
- package/dist/engine/resolve-expressions.d.ts.map +1 -0
- package/dist/engine/resolve-expressions.js +186 -0
- package/dist/engine/resolve-expressions.js.map +1 -0
- package/dist/engine/variable-resolver.d.ts +27 -0
- package/dist/engine/variable-resolver.d.ts.map +1 -1
- package/dist/engine/variable-resolver.js +20 -3
- package/dist/engine/variable-resolver.js.map +1 -1
- package/dist/engine/workflow-executor.d.ts.map +1 -1
- package/dist/engine/workflow-executor.js +66 -56
- package/dist/engine/workflow-executor.js.map +1 -1
- package/dist/expression/catalogue.d.ts +36 -0
- package/dist/expression/catalogue.d.ts.map +1 -0
- package/dist/expression/catalogue.js +82 -0
- package/dist/expression/catalogue.js.map +1 -0
- package/dist/expression/form/model.d.ts +115 -0
- package/dist/expression/form/model.d.ts.map +1 -0
- package/dist/expression/form/model.js +61 -0
- package/dist/expression/form/model.js.map +1 -0
- package/dist/expression/form/read.d.ts +4 -0
- package/dist/expression/form/read.d.ts.map +1 -0
- package/dist/expression/form/read.js +283 -0
- package/dist/expression/form/read.js.map +1 -0
- package/dist/expression/form/write.d.ts +8 -0
- package/dist/expression/form/write.d.ts.map +1 -0
- package/dist/expression/form/write.js +124 -0
- package/dist/expression/form/write.js.map +1 -0
- package/dist/expression/format.d.ts +41 -0
- package/dist/expression/format.d.ts.map +1 -0
- package/dist/expression/format.js +84 -0
- package/dist/expression/format.js.map +1 -0
- package/dist/expression/index.d.ts +40 -0
- package/dist/expression/index.d.ts.map +1 -0
- package/dist/expression/index.js +35 -0
- package/dist/expression/index.js.map +1 -0
- package/dist/expression/infer.d.ts +40 -0
- package/dist/expression/infer.d.ts.map +1 -0
- package/dist/expression/infer.js +195 -0
- package/dist/expression/infer.js.map +1 -0
- package/dist/expression/parse.d.ts +60 -0
- package/dist/expression/parse.d.ts.map +1 -0
- package/dist/expression/parse.js +201 -0
- package/dist/expression/parse.js.map +1 -0
- package/dist/expression/signature.d.ts +41 -0
- package/dist/expression/signature.d.ts.map +1 -0
- package/dist/expression/signature.js +124 -0
- package/dist/expression/signature.js.map +1 -0
- package/dist/expression/signatures.d.ts +45 -0
- package/dist/expression/signatures.d.ts.map +1 -0
- package/dist/expression/signatures.js +113 -0
- package/dist/expression/signatures.js.map +1 -0
- package/dist/expression/types.d.ts +71 -0
- package/dist/expression/types.d.ts.map +1 -0
- package/dist/expression/types.js +139 -0
- package/dist/expression/types.js.map +1 -0
- package/dist/index.d.ts +32 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -3
- package/dist/index.js.map +1 -1
- package/dist/ingest/filter.d.ts +8 -2
- package/dist/ingest/filter.d.ts.map +1 -1
- package/dist/ingest/filter.js +8 -2
- package/dist/ingest/filter.js.map +1 -1
- package/dist/ingest/start-policy.d.ts +1 -1
- package/dist/ingest/start-policy.d.ts.map +1 -1
- package/dist/ingest/start-policy.js +12 -5
- package/dist/ingest/start-policy.js.map +1 -1
- package/dist/persistence/in-memory-adapter.d.ts +3 -18
- package/dist/persistence/in-memory-adapter.d.ts.map +1 -1
- package/dist/persistence/in-memory-adapter.js +9 -61
- package/dist/persistence/in-memory-adapter.js.map +1 -1
- package/dist/persistence/types.d.ts +29 -58
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/router/workflow-router.d.ts.map +1 -1
- package/dist/router/workflow-router.js +70 -28
- package/dist/router/workflow-router.js.map +1 -1
- package/dist/runtime/workflow-runtime.d.ts +22 -45
- package/dist/runtime/workflow-runtime.d.ts.map +1 -1
- package/dist/runtime/workflow-runtime.js +157 -125
- package/dist/runtime/workflow-runtime.js.map +1 -1
- package/dist/steps/base-step.d.ts +2 -4
- package/dist/steps/base-step.d.ts.map +1 -1
- package/dist/steps/base-step.js.map +1 -1
- package/dist/testing/test-connector.d.ts +1 -1
- package/dist/testing/test-connector.js +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/known-types.d.ts +51 -1
- package/dist/types/known-types.d.ts.map +1 -1
- package/dist/types/known-types.js +54 -1
- package/dist/types/known-types.js.map +1 -1
- package/dist/types/operators.d.ts +22 -0
- package/dist/types/operators.d.ts.map +1 -1
- package/dist/types/operators.js +6 -6
- package/dist/types/operators.js.map +1 -1
- package/dist/types/pause-state.d.ts +0 -8
- package/dist/types/pause-state.d.ts.map +1 -1
- package/dist/types/pause-state.js.map +1 -1
- package/dist/types/validation.d.ts +10 -1
- package/dist/types/validation.d.ts.map +1 -1
- package/dist/types/validation.js +9 -0
- package/dist/types/validation.js.map +1 -1
- package/dist/types/workflow-config.d.ts +4 -3
- package/dist/types/workflow-config.d.ts.map +1 -1
- package/dist/types/workflow-config.js +23 -8
- package/dist/types/workflow-config.js.map +1 -1
- package/dist/util/computed-value.d.ts +103 -0
- package/dist/util/computed-value.d.ts.map +1 -0
- package/dist/util/computed-value.js +453 -0
- package/dist/util/computed-value.js.map +1 -0
- package/dist/util/expression-format.d.ts +41 -0
- package/dist/util/expression-format.d.ts.map +1 -0
- package/dist/util/expression-format.js +84 -0
- package/dist/util/expression-format.js.map +1 -0
- package/dist/util/expression-functions.d.ts +35 -0
- package/dist/util/expression-functions.d.ts.map +1 -0
- package/dist/util/expression-functions.js +82 -0
- package/dist/util/expression-functions.js.map +1 -0
- package/dist/util/expression.d.ts +98 -0
- package/dist/util/expression.d.ts.map +1 -0
- package/dist/util/expression.js +395 -0
- package/dist/util/expression.js.map +1 -0
- package/dist/util/jsonata-signatures.d.ts +45 -0
- package/dist/util/jsonata-signatures.d.ts.map +1 -0
- package/dist/util/jsonata-signatures.js +113 -0
- package/dist/util/jsonata-signatures.js.map +1 -0
- package/dist/util/signature.d.ts +41 -0
- package/dist/util/signature.d.ts.map +1 -0
- package/dist/util/signature.js +124 -0
- package/dist/util/signature.js.map +1 -0
- package/dist/util/type-compat.d.ts +8 -28
- package/dist/util/type-compat.d.ts.map +1 -1
- package/dist/util/type-compat.js +22 -29
- package/dist/util/type-compat.js.map +1 -1
- package/dist/util/variable-ref.d.ts +24 -0
- package/dist/util/variable-ref.d.ts.map +1 -1
- package/dist/util/variable-ref.js +34 -9
- package/dist/util/variable-ref.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Matches a *pure* expression (the entire string is one `{% ... %}`). */
|
|
2
|
+
export declare const EXPRESSION_REGEX: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* A pure `{{ref}}` or a pure `{% expression %}`. Composed from both patterns
|
|
5
|
+
* rather than written out a third time.
|
|
6
|
+
*/
|
|
7
|
+
export declare const REF_OR_EXPRESSION_REGEX: RegExp;
|
|
8
|
+
export type ExpressionToken = {
|
|
9
|
+
kind: 'literal';
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'expression';
|
|
13
|
+
source: string;
|
|
14
|
+
raw: string;
|
|
15
|
+
};
|
|
16
|
+
/** True iff `value` is exactly one expression with no surrounding text. */
|
|
17
|
+
export declare function isExpression(value: string): boolean;
|
|
18
|
+
/** True iff `value` contains at least one expression anywhere. */
|
|
19
|
+
export declare function hasExpression(value: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The source inside a pure expression: `"{% $sum(a) %}"` → `"$sum(a)"`.
|
|
22
|
+
* Returns null if `value` isn't a pure expression.
|
|
23
|
+
*/
|
|
24
|
+
export declare function extractExpressionSource(value: string): string | null;
|
|
25
|
+
/** Split a string into literal segments and expressions. */
|
|
26
|
+
export declare function tokenizeExpressions(input: string): ExpressionToken[];
|
|
27
|
+
/** Wrap an expression source into its wire form. The one place that spells it. */
|
|
28
|
+
export declare function toExpressionValue(source: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* The context roots an expression may read — the same five `resolvePath` resolves, and nothing else.
|
|
31
|
+
*/
|
|
32
|
+
export declare const EXPRESSION_ROOTS: readonly ["trigger", "workflow", "execution", "steps", "vars"];
|
|
33
|
+
export interface FoundExpression {
|
|
34
|
+
/** The expression source, without delimiters. */
|
|
35
|
+
source: string;
|
|
36
|
+
/** JSON-pointer-style location in the config object where it lives. */
|
|
37
|
+
location: string;
|
|
38
|
+
}
|
|
39
|
+
/** Collect every `{% ... */
|
|
40
|
+
export declare function collectExpressions(value: unknown, prefix: string, skip?: ReadonlySet<unknown>): FoundExpression[];
|
|
41
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/expression/format.ts"],"names":[],"mappings":"AAUA,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,QAAsB,CAAC;AAKpD;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAEnC,CAAC;AAgBF,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGpE;AAED,4DAA4D;AAC5D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,EAAE,CAiBpE;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,gEAAiE,CAAC;AAE/F,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,4BAA4B;AAC5B,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAC1B,eAAe,EAAE,CAQnB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `{% … %}` wire format: how an expression is spelled and where one
|
|
3
|
+
* appears. Imports no parser, so the config schema, the UI and the config walk
|
|
4
|
+
* can recognise one without pulling in JSONata — only `expression.ts` does.
|
|
5
|
+
*
|
|
6
|
+
* Not `{{…}}`: every consumer of that one splits its body on `.` as a path, so
|
|
7
|
+
* a second delimiter is purely additive and needs no migration.
|
|
8
|
+
*/
|
|
9
|
+
import { VARIABLE_REF_REGEX, walkConfigStrings } from '../util/variable-ref.js';
|
|
10
|
+
/** Matches a *pure* expression (the entire string is one `{% ... %}`). */
|
|
11
|
+
export const EXPRESSION_REGEX = /^\{%([\s\S]*)%\}$/;
|
|
12
|
+
/** Drop the anchors, so a pattern can be embedded in an alternation. */
|
|
13
|
+
const unanchored = (re) => re.source.replace(/^\^/, '').replace(/\$$/, '');
|
|
14
|
+
/**
|
|
15
|
+
* A pure `{{ref}}` or a pure `{% expression %}`. Composed from both patterns
|
|
16
|
+
* rather than written out a third time.
|
|
17
|
+
*/
|
|
18
|
+
export const REF_OR_EXPRESSION_REGEX = new RegExp(`^(?:${unanchored(VARIABLE_REF_REGEX)}|${unanchored(EXPRESSION_REGEX)})$`);
|
|
19
|
+
/**
|
|
20
|
+
* Global, non-greedy — `"a {% x %} b {% y %}"` must find two expressions, not one spanning the middle.
|
|
21
|
+
*/
|
|
22
|
+
const EXPRESSION_TOKEN_REGEX = /\{%([\s\S]*?)%\}/g;
|
|
23
|
+
/**
|
|
24
|
+
* Non-global twin, for `.test()`.
|
|
25
|
+
*
|
|
26
|
+
* `.test()` on a global regex advances its `lastIndex` and resumes from there on
|
|
27
|
+
* the next call, so sharing one with the tokenizer would make the answer depend
|
|
28
|
+
* on what was asked before it.
|
|
29
|
+
*/
|
|
30
|
+
const EXPRESSION_PRESENT_REGEX = /\{%[\s\S]*?%\}/;
|
|
31
|
+
/** True iff `value` is exactly one expression with no surrounding text. */
|
|
32
|
+
export function isExpression(value) {
|
|
33
|
+
return EXPRESSION_REGEX.test(value);
|
|
34
|
+
}
|
|
35
|
+
/** True iff `value` contains at least one expression anywhere. */
|
|
36
|
+
export function hasExpression(value) {
|
|
37
|
+
return value.includes('{%') && EXPRESSION_PRESENT_REGEX.test(value);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The source inside a pure expression: `"{% $sum(a) %}"` → `"$sum(a)"`.
|
|
41
|
+
* Returns null if `value` isn't a pure expression.
|
|
42
|
+
*/
|
|
43
|
+
export function extractExpressionSource(value) {
|
|
44
|
+
const m = EXPRESSION_REGEX.exec(value);
|
|
45
|
+
return m?.[1]?.trim() ?? null;
|
|
46
|
+
}
|
|
47
|
+
/** Split a string into literal segments and expressions. */
|
|
48
|
+
export function tokenizeExpressions(input) {
|
|
49
|
+
const tokens = [];
|
|
50
|
+
let lastIndex = 0;
|
|
51
|
+
EXPRESSION_TOKEN_REGEX.lastIndex = 0;
|
|
52
|
+
let match;
|
|
53
|
+
while ((match = EXPRESSION_TOKEN_REGEX.exec(input)) !== null) {
|
|
54
|
+
if (match.index > lastIndex) {
|
|
55
|
+
tokens.push({ kind: 'literal', text: input.slice(lastIndex, match.index) });
|
|
56
|
+
}
|
|
57
|
+
tokens.push({ kind: 'expression', source: match[1].trim(), raw: match[0] });
|
|
58
|
+
lastIndex = EXPRESSION_TOKEN_REGEX.lastIndex;
|
|
59
|
+
}
|
|
60
|
+
if (lastIndex < input.length) {
|
|
61
|
+
tokens.push({ kind: 'literal', text: input.slice(lastIndex) });
|
|
62
|
+
}
|
|
63
|
+
return tokens;
|
|
64
|
+
}
|
|
65
|
+
/** Wrap an expression source into its wire form. The one place that spells it. */
|
|
66
|
+
export function toExpressionValue(source) {
|
|
67
|
+
return `{% ${source.trim()} %}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The context roots an expression may read — the same five `resolvePath` resolves, and nothing else.
|
|
71
|
+
*/
|
|
72
|
+
export const EXPRESSION_ROOTS = ['trigger', 'workflow', 'execution', 'steps', 'vars'];
|
|
73
|
+
/** Collect every `{% ... */
|
|
74
|
+
export function collectExpressions(value, prefix, skip) {
|
|
75
|
+
const out = [];
|
|
76
|
+
walkConfigStrings(value, prefix, skip, (text, location) => {
|
|
77
|
+
for (const token of tokenizeExpressions(text)) {
|
|
78
|
+
if (token.kind === 'expression')
|
|
79
|
+
out.push({ source: token.source, location });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/expression/format.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEhF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAEpD,wEAAwE;AACxE,MAAM,UAAU,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAE3F;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,MAAM,CAC/C,OAAO,UAAU,CAAC,kBAAkB,CAAC,IAAI,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAC1E,CAAC;AAEF;;GAEG;AACH,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAMlD,2EAA2E;AAC3E,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,MAAM,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,CAAC,EA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UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAU,CAAC;AAS/F,4BAA4B;AAC5B,MAAM,UAAU,kBAAkB,CAChC,KAAc,EACd,MAAc,EACd,IAA2B;IAE3B,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;QACxD,KAAK,MAAM,KAAK,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;gBAAE,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expressions: `{% … %}` over a workflow's data, in JSONata.
|
|
3
|
+
*
|
|
4
|
+
* Layered so the cheap half stands alone — `format.ts` recognises an expression
|
|
5
|
+
* and imports no parser, which is what lets the config schema and the UI handle
|
|
6
|
+
* one without the engine coming along.
|
|
7
|
+
*
|
|
8
|
+
* format the wire format, and where expressions appear in a config
|
|
9
|
+
* parse compile · cache · ast · the safety rules ← the jsonata import
|
|
10
|
+
* infer what an expression will produce
|
|
11
|
+
* types ExprType, and what may be assigned to what
|
|
12
|
+
* signature JSONata's signature notation, parsed
|
|
13
|
+
* signatures the generated table of builtin signatures
|
|
14
|
+
* catalogue the operations a menu offers
|
|
15
|
+
* form/ the subset a form can build and read back
|
|
16
|
+
*
|
|
17
|
+
* How the *engine* uses this lives in the engine — `resolve-expressions.ts` for
|
|
18
|
+
* a run, `config-validator.ts` for author time — because those depend on a
|
|
19
|
+
* workflow context, and the language must not.
|
|
20
|
+
*/
|
|
21
|
+
export { EXPRESSION_REGEX, EXPRESSION_ROOTS, REF_OR_EXPRESSION_REGEX, collectExpressions, extractExpressionSource, hasExpression, isExpression, toExpressionValue, tokenizeExpressions, } from './format.js';
|
|
22
|
+
export type { ExpressionToken, FoundExpression } from './format.js';
|
|
23
|
+
export { EXPRESSION_LIMITS, clearExpressionCache, compileExpression, expressionAst, inspectExpression, refsInExpression, } from './parse.js';
|
|
24
|
+
export type { ExpressionFault, ExpressionFaultKind } from './parse.js';
|
|
25
|
+
export { inferExpressionType } from './infer.js';
|
|
26
|
+
export type { InferredExpression, TypeFault } from './infer.js';
|
|
27
|
+
export { kindOfJsonType, kindsCompatible } from '../util/type-compat.js';
|
|
28
|
+
export type { TypeKind } from '../util/type-compat.js';
|
|
29
|
+
export { assignableToArgument, assignableToField, baseKind, elementType, sayType, unify, writeLiteralAs, } from './types.js';
|
|
30
|
+
export type { ExprType } from './types.js';
|
|
31
|
+
export { parseSignature, paramAt } from './signature.js';
|
|
32
|
+
export type { Signature, SignatureParam } from './signature.js';
|
|
33
|
+
export { BUILTIN_SIGNATURES, builtinSignature, isBuiltin } from './signatures.js';
|
|
34
|
+
export { EXPRESSION_FUNCTIONS, expressionFunction, takesOf } from './catalogue.js';
|
|
35
|
+
export type { ExpressionFunction } from './catalogue.js';
|
|
36
|
+
export { COMPARISON_OPS, FORMABLE_FUNCTIONS, argumentSlots, isFormable, takesSeveral, wantsAt, } from './form/model.js';
|
|
37
|
+
export { writeComputation, writeLiteral, writeSelection, } from './form/write.js';
|
|
38
|
+
export { readComputation, } from './form/read.js';
|
|
39
|
+
export type { Argument, Call, Computation, ComparisonOp, ItemFilter, ListFormat, ValueSelection, } from './form/model.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/expression/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACv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cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expressions: `{% … %}` over a workflow's data, in JSONata.
|
|
3
|
+
*
|
|
4
|
+
* Layered so the cheap half stands alone — `format.ts` recognises an expression
|
|
5
|
+
* and imports no parser, which is what lets the config schema and the UI handle
|
|
6
|
+
* one without the engine coming along.
|
|
7
|
+
*
|
|
8
|
+
* format the wire format, and where expressions appear in a config
|
|
9
|
+
* parse compile · cache · ast · the safety rules ← the jsonata import
|
|
10
|
+
* infer what an expression will produce
|
|
11
|
+
* types ExprType, and what may be assigned to what
|
|
12
|
+
* signature JSONata's signature notation, parsed
|
|
13
|
+
* signatures the generated table of builtin signatures
|
|
14
|
+
* catalogue the operations a menu offers
|
|
15
|
+
* form/ the subset a form can build and read back
|
|
16
|
+
*
|
|
17
|
+
* How the *engine* uses this lives in the engine — `resolve-expressions.ts` for
|
|
18
|
+
* a run, `config-validator.ts` for author time — because those depend on a
|
|
19
|
+
* workflow context, and the language must not.
|
|
20
|
+
*/
|
|
21
|
+
export { EXPRESSION_REGEX, EXPRESSION_ROOTS, REF_OR_EXPRESSION_REGEX, collectExpressions, extractExpressionSource, hasExpression, isExpression, toExpressionValue, tokenizeExpressions, } from './format.js';
|
|
22
|
+
export { EXPRESSION_LIMITS, clearExpressionCache, compileExpression, expressionAst, inspectExpression, refsInExpression, } from './parse.js';
|
|
23
|
+
export { inferExpressionType } from './infer.js';
|
|
24
|
+
// The shared type vocabulary these rules are written in. Re-exported so a
|
|
25
|
+
// consumer of this module does not need a second barrel to turn a schema's
|
|
26
|
+
// `type` keyword into something `assignableToArgument` will take.
|
|
27
|
+
export { kindOfJsonType, kindsCompatible } from '../util/type-compat.js';
|
|
28
|
+
export { assignableToArgument, assignableToField, baseKind, elementType, sayType, unify, writeLiteralAs, } from './types.js';
|
|
29
|
+
export { parseSignature, paramAt } from './signature.js';
|
|
30
|
+
export { BUILTIN_SIGNATURES, builtinSignature, isBuiltin } from './signatures.js';
|
|
31
|
+
export { EXPRESSION_FUNCTIONS, expressionFunction, takesOf } from './catalogue.js';
|
|
32
|
+
export { COMPARISON_OPS, FORMABLE_FUNCTIONS, argumentSlots, isFormable, takesSeveral, wantsAt, } from './form/model.js';
|
|
33
|
+
export { writeComputation, writeLiteral, writeSelection, } from './form/write.js';
|
|
34
|
+
export { readComputation, } from './form/read.js';
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/expression/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,0EAA0E;AAC1E,2EAA2E;AAC3E,kEAAkE;AAClE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,OAAO,EACP,KAAK,EACL,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGnF,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,YAAY,EACZ,OAAO,GACR,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ExprType } from './types.js';
|
|
2
|
+
export interface TypeFault {
|
|
3
|
+
/** Author-facing, specific enough to show as-is. */
|
|
4
|
+
message: string;
|
|
5
|
+
/** 0-based offset into the expression source, when the parser gave one. */
|
|
6
|
+
position?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface InferredExpression {
|
|
9
|
+
/** What the whole expression produces — `unknown` wherever it cannot be read. */
|
|
10
|
+
type: ExprType;
|
|
11
|
+
/** Arguments passed something their function cannot accept. */
|
|
12
|
+
faults: TypeFault[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Work out what an expression produces, and what it misuses on the way.
|
|
16
|
+
*
|
|
17
|
+
* This is what makes the typing claim true *before* a run. Without it the
|
|
18
|
+
* engine leans entirely on JSONata's own signature checks (`T0410`, `T0412`) and
|
|
19
|
+
* on zod rejecting the result — both correct, both too late, and neither
|
|
20
|
+
* visible while the workflow is being written.
|
|
21
|
+
*
|
|
22
|
+
* ## It is only ever allowed to be silent, never wrong
|
|
23
|
+
*
|
|
24
|
+
* Every node it cannot read yields `unknown`, which {@link assignableToArgument}
|
|
25
|
+
* and {@link assignableToField} treat as compatible at any depth. A relative
|
|
26
|
+
* path inside a predicate, a lambda parameter, a `$$`, a regex, an unrecognised
|
|
27
|
+
* node from a future JSONata — all `unknown`. That asymmetry is deliberate: a
|
|
28
|
+
* missed mistake costs a runtime error the author would have had anyway, while a
|
|
29
|
+
* false one blocks a correct workflow from being saved. Expression typing is a
|
|
30
|
+
* courtesy on top of a dynamically-checked language, not a gate.
|
|
31
|
+
*
|
|
32
|
+
* ## Where the types come from
|
|
33
|
+
*
|
|
34
|
+
* References resolve through `lookup`, which the caller supplies — the validator
|
|
35
|
+
* reads JSON Schema, a test can hand over a map. This module never sees a
|
|
36
|
+
* schema, for the same reason `type-compat` does not: the two schema worlds
|
|
37
|
+
* (Zod here, JSON Schema across the wire) must not leak into the rule.
|
|
38
|
+
*/
|
|
39
|
+
export declare function inferExpressionType(source: string, lookup: (path: string) => ExprType | undefined): InferredExpression;
|
|
40
|
+
//# sourceMappingURL=infer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer.d.ts","sourceRoot":"","sources":["../../src/expression/infer.ts"],"names":[],"mappings":"AAYA,OAAO,EAA+D,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIxG,MAAM,WAAW,SAAS;IACxB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,iFAAiF;IACjF,IAAI,EAAE,QAAQ,CAAC;IACf,+DAA+D;IAC/D,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,GAC7C,kBAAkB,CAgJpB"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { ROOTS, compileExpression } from './parse.js';
|
|
2
|
+
import { builtinSignature } from './signatures.js';
|
|
3
|
+
import { paramAt, parseSignature } from './signature.js';
|
|
4
|
+
import { assignableToArgument, baseKind, elementType, sayType, unify } from './types.js';
|
|
5
|
+
/** Arithmetic that only makes sense on numbers. */
|
|
6
|
+
const NUMERIC_OPERATORS = new Set(['+', '-', '*', '/', '%']);
|
|
7
|
+
/** Comparisons and tests, whatever they are given. */
|
|
8
|
+
const BOOLEAN_OPERATORS = new Set(['=', '!=', '<', '<=', '>', '>=', 'in', 'and', 'or']);
|
|
9
|
+
function at(node) {
|
|
10
|
+
const position = node['position'];
|
|
11
|
+
return typeof position === 'number' ? { position } : {};
|
|
12
|
+
}
|
|
13
|
+
/** The dotted path a `path` node names, or null when it is not a plain one. */
|
|
14
|
+
function dottedPath(node) {
|
|
15
|
+
const steps = node['steps'];
|
|
16
|
+
if (!Array.isArray(steps) || steps.length === 0)
|
|
17
|
+
return null;
|
|
18
|
+
const names = [];
|
|
19
|
+
for (const step of steps) {
|
|
20
|
+
if (step === null || typeof step !== 'object')
|
|
21
|
+
return null;
|
|
22
|
+
const record = step;
|
|
23
|
+
if (record['type'] !== 'name' || typeof record['value'] !== 'string')
|
|
24
|
+
return null;
|
|
25
|
+
names.push(record['value']);
|
|
26
|
+
}
|
|
27
|
+
return ROOTS.has(names[0]) ? names.join('.') : null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Work out what an expression produces, and what it misuses on the way.
|
|
31
|
+
*
|
|
32
|
+
* This is what makes the typing claim true *before* a run. Without it the
|
|
33
|
+
* engine leans entirely on JSONata's own signature checks (`T0410`, `T0412`) and
|
|
34
|
+
* on zod rejecting the result — both correct, both too late, and neither
|
|
35
|
+
* visible while the workflow is being written.
|
|
36
|
+
*
|
|
37
|
+
* ## It is only ever allowed to be silent, never wrong
|
|
38
|
+
*
|
|
39
|
+
* Every node it cannot read yields `unknown`, which {@link assignableToArgument}
|
|
40
|
+
* and {@link assignableToField} treat as compatible at any depth. A relative
|
|
41
|
+
* path inside a predicate, a lambda parameter, a `$$`, a regex, an unrecognised
|
|
42
|
+
* node from a future JSONata — all `unknown`. That asymmetry is deliberate: a
|
|
43
|
+
* missed mistake costs a runtime error the author would have had anyway, while a
|
|
44
|
+
* false one blocks a correct workflow from being saved. Expression typing is a
|
|
45
|
+
* courtesy on top of a dynamically-checked language, not a gate.
|
|
46
|
+
*
|
|
47
|
+
* ## Where the types come from
|
|
48
|
+
*
|
|
49
|
+
* References resolve through `lookup`, which the caller supplies — the validator
|
|
50
|
+
* reads JSON Schema, a test can hand over a map. This module never sees a
|
|
51
|
+
* schema, for the same reason `type-compat` does not: the two schema worlds
|
|
52
|
+
* (Zod here, JSON Schema across the wire) must not leak into the rule.
|
|
53
|
+
*/
|
|
54
|
+
export function inferExpressionType(source, lookup) {
|
|
55
|
+
let ast;
|
|
56
|
+
try {
|
|
57
|
+
ast = compileExpression(source).ast();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return { type: 'unknown', faults: [] };
|
|
61
|
+
}
|
|
62
|
+
const faults = [];
|
|
63
|
+
const infer = (value) => {
|
|
64
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
65
|
+
return 'unknown';
|
|
66
|
+
const node = value;
|
|
67
|
+
switch (node['type']) {
|
|
68
|
+
case 'number':
|
|
69
|
+
return 'number';
|
|
70
|
+
case 'string':
|
|
71
|
+
return 'string';
|
|
72
|
+
case 'value':
|
|
73
|
+
// `true` / `false` / `null`; only the first two have a type worth saying.
|
|
74
|
+
return node['value'] === null ? 'unknown' : 'boolean';
|
|
75
|
+
case 'path': {
|
|
76
|
+
const path = dottedPath(node);
|
|
77
|
+
return path === null ? 'unknown' : (lookup(path) ?? 'unknown');
|
|
78
|
+
}
|
|
79
|
+
case 'unary': {
|
|
80
|
+
if (node['value'] === '[') {
|
|
81
|
+
const items = node['expressions'];
|
|
82
|
+
if (!Array.isArray(items))
|
|
83
|
+
return 'array';
|
|
84
|
+
// JSONata flattens: `[theList]` is `theList`, and `[1..5]` is a flat
|
|
85
|
+
const inner = unify(items.map((item) => {
|
|
86
|
+
const type = infer(item);
|
|
87
|
+
return baseKind(type) === 'array' ? elementType(type) : type;
|
|
88
|
+
}));
|
|
89
|
+
return inner === 'unknown' ? 'array' : { array: inner };
|
|
90
|
+
}
|
|
91
|
+
if (node['value'] === '{')
|
|
92
|
+
return 'object';
|
|
93
|
+
if (node['value'] === '-')
|
|
94
|
+
return 'number';
|
|
95
|
+
return 'unknown';
|
|
96
|
+
}
|
|
97
|
+
case 'binary': {
|
|
98
|
+
const op = node['value'];
|
|
99
|
+
if (typeof op !== 'string')
|
|
100
|
+
return 'unknown';
|
|
101
|
+
if (op === '..')
|
|
102
|
+
return { array: 'number' };
|
|
103
|
+
if (op === '&')
|
|
104
|
+
return 'string';
|
|
105
|
+
if (BOOLEAN_OPERATORS.has(op)) {
|
|
106
|
+
infer(node['lhs']);
|
|
107
|
+
infer(node['rhs']);
|
|
108
|
+
return 'boolean';
|
|
109
|
+
}
|
|
110
|
+
if (NUMERIC_OPERATORS.has(op)) {
|
|
111
|
+
for (const side of ['lhs', 'rhs']) {
|
|
112
|
+
const operand = infer(node[side]);
|
|
113
|
+
if (!assignableToArgument(operand, 'number')) {
|
|
114
|
+
faults.push({
|
|
115
|
+
message: `"${op}" needs numbers, but one side is ${sayType(operand)}.`,
|
|
116
|
+
...at(node),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return 'number';
|
|
121
|
+
}
|
|
122
|
+
return 'unknown';
|
|
123
|
+
}
|
|
124
|
+
case 'condition':
|
|
125
|
+
return unify([infer(node['then']), infer(node['else'])]);
|
|
126
|
+
case 'block': {
|
|
127
|
+
const parts = node['expressions'];
|
|
128
|
+
if (!Array.isArray(parts) || parts.length === 0)
|
|
129
|
+
return 'unknown';
|
|
130
|
+
// Every part runs, but only the last one is the answer.
|
|
131
|
+
for (const part of parts.slice(0, -1))
|
|
132
|
+
infer(part);
|
|
133
|
+
return infer(parts[parts.length - 1]);
|
|
134
|
+
}
|
|
135
|
+
case 'apply': {
|
|
136
|
+
// `a ~> $sum()` — the left side becomes the call's first argument.
|
|
137
|
+
const rhs = node['rhs'];
|
|
138
|
+
const piped = infer(node['lhs']);
|
|
139
|
+
if (rhs === null || typeof rhs !== 'object')
|
|
140
|
+
return 'unknown';
|
|
141
|
+
const record = rhs;
|
|
142
|
+
if (record['type'] === 'variable') {
|
|
143
|
+
return callType({ procedure: record, arguments: [] }, piped);
|
|
144
|
+
}
|
|
145
|
+
return callType(record, piped);
|
|
146
|
+
}
|
|
147
|
+
case 'function':
|
|
148
|
+
case 'partial':
|
|
149
|
+
return callType(node, undefined);
|
|
150
|
+
default:
|
|
151
|
+
// `lambda`, `variable`, `bind`, `regex`, `wildcard`, `descendant`,
|
|
152
|
+
return 'unknown';
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* A call's result, with every argument checked against the signature JSONata publishes for it.
|
|
157
|
+
*/
|
|
158
|
+
const callType = (node, piped) => {
|
|
159
|
+
const procedure = node['procedure'];
|
|
160
|
+
const name = procedure !== null && typeof procedure === 'object'
|
|
161
|
+
? procedure['value']
|
|
162
|
+
: undefined;
|
|
163
|
+
if (typeof name !== 'string')
|
|
164
|
+
return 'unknown';
|
|
165
|
+
const args = Array.isArray(node['arguments']) ? node['arguments'] : [];
|
|
166
|
+
// Walk every argument so faults inside them are still reported, but give a
|
|
167
|
+
const argTypes = args.map((argument) => {
|
|
168
|
+
const record = argument;
|
|
169
|
+
if (record !== null && typeof record === 'object' && record['type'] === 'lambda') {
|
|
170
|
+
return 'unknown';
|
|
171
|
+
}
|
|
172
|
+
return infer(argument);
|
|
173
|
+
});
|
|
174
|
+
const definition = builtinSignature(name);
|
|
175
|
+
const signature = definition === undefined ? null : parseSignature(definition);
|
|
176
|
+
if (signature === null)
|
|
177
|
+
return 'unknown'; // unknown name, or notation we cannot read
|
|
178
|
+
const supplied = piped === undefined ? argTypes : [piped, ...argTypes];
|
|
179
|
+
supplied.forEach((type, index) => {
|
|
180
|
+
const param = paramAt(signature, index);
|
|
181
|
+
if (param === undefined)
|
|
182
|
+
return;
|
|
183
|
+
if (assignableToArgument(type, param.type))
|
|
184
|
+
return;
|
|
185
|
+
const which = supplied.length > 1 ? ` for argument ${String(index + 1)}` : '';
|
|
186
|
+
faults.push({
|
|
187
|
+
message: `$${name} needs ${sayType(param.type)}${which}, but this is ${sayType(type)}.`,
|
|
188
|
+
...at(node),
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
return signature.returns;
|
|
192
|
+
};
|
|
193
|
+
return { type: infer(ast), faults };
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=infer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer.js","sourceRoot":"","sources":["../../src/expression/infer.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAiB,MAAM,YAAY,CAAC;AAkBxG,mDAAmD;AACnD,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC7D,sDAAsD;AACtD,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAExF,SAAS,EAAE,CAAC,IAA6B;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,E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/E,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC,CAAC,2CAA2C;QAErF,MAAM,QAAQ,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;QACvE,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO;YAChC,IAAI,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;gBAAE,OAAO;YACnD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9E,MAAM,CAAC,IAAI,CAAC;gBACV,OAAO,EAAE,IAAI,IAAI,UAAU,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,iBAAiB,OAAO,CAAC,IAAI,CAAC,GAAG;gBACvF,GAAG,EAAE,CAAC,IAAI,CAAC;aACZ,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,SAAS,CAAC,OAAO,CAAC;IAC3B,CAAC,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Expression, ExprNode } from 'jsonata';
|
|
2
|
+
/** Evaluation limits, applied at compile time and enforced by JSONata while evaluating. */
|
|
3
|
+
export declare const EXPRESSION_LIMITS: {
|
|
4
|
+
readonly timeout: 1000;
|
|
5
|
+
readonly stack: 200;
|
|
6
|
+
};
|
|
7
|
+
/** Compile an expression source, memoized. */
|
|
8
|
+
export declare function compileExpression(source: string): Expression;
|
|
9
|
+
/** The parsed form of an expression, or null when it does not compile. */
|
|
10
|
+
export declare function expressionAst(source: string): ExprNode | null;
|
|
11
|
+
/** Drop every cached expression. For tests and long-idle hosts. */
|
|
12
|
+
export declare function clearExpressionCache(): void;
|
|
13
|
+
export type ExpressionFaultKind = 'syntax' | 'namedFunction' | 'eval' | 'unknownFunction';
|
|
14
|
+
export interface ExpressionFault {
|
|
15
|
+
kind: ExpressionFaultKind;
|
|
16
|
+
/** Author-facing, already specific enough to show as-is. */
|
|
17
|
+
message: string;
|
|
18
|
+
/** 0-based offset into the expression source, when the parser gave one. */
|
|
19
|
+
position?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check an expression for anything that must never run, without evaluating it.
|
|
23
|
+
* Returns the first fault, or null when the expression is safe to keep.
|
|
24
|
+
*
|
|
25
|
+
* Two things are refused:
|
|
26
|
+
*
|
|
27
|
+
* **Naming a function.** A `lambda` is allowed only as a direct argument to a
|
|
28
|
+
* call — `$filter(xs, function($x){ ... })` — and nowhere else. That one rule is
|
|
29
|
+
* what makes evaluation terminate: an expression can only loop by calling
|
|
30
|
+
* itself, calling itself needs a name to call, and the only ways to get a name
|
|
31
|
+
* are to bind a lambda (`$f := function…`), to stash one in an array or object,
|
|
32
|
+
* or to apply a lambda literal to itself. Every one of those puts a `lambda`
|
|
33
|
+
* somewhere other than an argument slot, so all of them are caught — verified
|
|
34
|
+
* against each form. Inline predicates, which is what the list functions
|
|
35
|
+
* actually need, are untouched, and so is naming a plain *value*
|
|
36
|
+
* (`$total := $sum(…)`), which cannot recurse.
|
|
37
|
+
*
|
|
38
|
+
* **`$eval`.** It compiles a string as a new expression, which is the one hole
|
|
39
|
+
* through which everything above could be re-introduced. Matched on the
|
|
40
|
+
* variable name wherever it appears, so an alias (`$g := $eval`) or a reference
|
|
41
|
+
* (`$map(xs, $eval)`) is caught too, not just a direct call. AWS blocks it in
|
|
42
|
+
* their JSONata support for the same reason.
|
|
43
|
+
*
|
|
44
|
+
* **Unknown functions.** A name JSONata does not have, so that a typo is caught
|
|
45
|
+
* while writing rather than at `T1006`. This was skipped at first on the belief
|
|
46
|
+
* that the builtins could not be enumerated — they can: every name JSONata binds
|
|
47
|
+
* resolves to an object carrying its own signature, and
|
|
48
|
+
* `jsonata-signatures.ts` is generated from them. Checked after the two bans so
|
|
49
|
+
* that `$f(0)` beside a named function reports the named function, which is the
|
|
50
|
+
* more useful of the two complaints.
|
|
51
|
+
*
|
|
52
|
+
* Note this assumes nothing is registered beyond the builtins. If the engine
|
|
53
|
+
* ever calls `registerFunction`, those names have to be known here too, or
|
|
54
|
+
* correct expressions will be refused.
|
|
55
|
+
*/
|
|
56
|
+
export declare function inspectExpression(source: string): ExpressionFault | null;
|
|
57
|
+
export declare const ROOTS: ReadonlySet<string>;
|
|
58
|
+
/** Dotted context paths an expression reads, e.g. */
|
|
59
|
+
export declare function refsInExpression(source: string): string[];
|
|
60
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/expression/parse.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMpD,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB;;;CAAyC,CAAC;AAQxE,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAe5D;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAM7D;AAED,mEAAmE;AACnE,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAID,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,eAAe,GAAG,MAAM,GAAG,iBAAiB,CAAC;AAE1F,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAgDxE;AAID,eAAO,MAAM,KAAK,EAAE,WAAW,CAAC,MAAM,CAA6B,CAAC;AAEpE,qDAAqD;AACrD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CA0BzD"}
|