@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,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compiling an expression, and refusing the ones that are not safe to run. The
|
|
3
|
+
* only module that imports JSONata.
|
|
4
|
+
*
|
|
5
|
+
* Safety rests on two things. A `function(){}` literal is legal only as a
|
|
6
|
+
* direct call argument, which removes every route to recursion, and `$eval` is
|
|
7
|
+
* refused by name. `EXPRESSION_LIMITS` is the runtime guarantee behind both —
|
|
8
|
+
* measured, not assumed: a long expression throws D1012 at the timeout.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
import jsonata from 'jsonata';
|
|
12
|
+
import { EXPRESSION_ROOTS } from './format.js';
|
|
13
|
+
import { isBuiltin } from './signatures.js';
|
|
14
|
+
// ─── Runtime limits ───
|
|
15
|
+
/** Evaluation limits, applied at compile time and enforced by JSONata while evaluating. */
|
|
16
|
+
export const EXPRESSION_LIMITS = { timeout: 1000, stack: 200 };
|
|
17
|
+
// ─── Compilation (cached) ───
|
|
18
|
+
/** Compiled-expression cache. */
|
|
19
|
+
const CACHE_MAX = 500;
|
|
20
|
+
const cache = new Map();
|
|
21
|
+
/** Compile an expression source, memoized. */
|
|
22
|
+
export function compileExpression(source) {
|
|
23
|
+
const hit = cache.get(source);
|
|
24
|
+
if (hit !== undefined) {
|
|
25
|
+
// Re-insert so iteration order stays least-recently-used first.
|
|
26
|
+
cache.delete(source);
|
|
27
|
+
cache.set(source, hit);
|
|
28
|
+
return hit;
|
|
29
|
+
}
|
|
30
|
+
const compiled = jsonata(source, EXPRESSION_LIMITS);
|
|
31
|
+
if (cache.size >= CACHE_MAX) {
|
|
32
|
+
const oldest = cache.keys().next();
|
|
33
|
+
if (!oldest.done)
|
|
34
|
+
cache.delete(oldest.value);
|
|
35
|
+
}
|
|
36
|
+
cache.set(source, compiled);
|
|
37
|
+
return compiled;
|
|
38
|
+
}
|
|
39
|
+
/** The parsed form of an expression, or null when it does not compile. */
|
|
40
|
+
export function expressionAst(source) {
|
|
41
|
+
try {
|
|
42
|
+
return compileExpression(source).ast();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Drop every cached expression. For tests and long-idle hosts. */
|
|
49
|
+
export function clearExpressionCache() {
|
|
50
|
+
cache.clear();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Walk every node of an AST, flagging which ones sit directly in a call's argument list.
|
|
54
|
+
*/
|
|
55
|
+
function walkAst(node, inArgumentList, visit) {
|
|
56
|
+
if (node === null || typeof node !== 'object')
|
|
57
|
+
return;
|
|
58
|
+
if (Array.isArray(node)) {
|
|
59
|
+
for (const item of node)
|
|
60
|
+
walkAst(item, false, visit);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const record = node;
|
|
64
|
+
visit(record, inArgumentList);
|
|
65
|
+
const type = record['type'];
|
|
66
|
+
for (const [key, value] of Object.entries(record)) {
|
|
67
|
+
const isCallArguments = key === 'arguments' &&
|
|
68
|
+
(type === 'function' || type === 'apply') &&
|
|
69
|
+
Array.isArray(value);
|
|
70
|
+
if (isCallArguments) {
|
|
71
|
+
for (const argument of value)
|
|
72
|
+
walkAst(argument, true, visit);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
walkAst(value, false, visit);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check an expression for anything that must never run, without evaluating it.
|
|
81
|
+
* Returns the first fault, or null when the expression is safe to keep.
|
|
82
|
+
*
|
|
83
|
+
* Two things are refused:
|
|
84
|
+
*
|
|
85
|
+
* **Naming a function.** A `lambda` is allowed only as a direct argument to a
|
|
86
|
+
* call — `$filter(xs, function($x){ ... })` — and nowhere else. That one rule is
|
|
87
|
+
* what makes evaluation terminate: an expression can only loop by calling
|
|
88
|
+
* itself, calling itself needs a name to call, and the only ways to get a name
|
|
89
|
+
* are to bind a lambda (`$f := function…`), to stash one in an array or object,
|
|
90
|
+
* or to apply a lambda literal to itself. Every one of those puts a `lambda`
|
|
91
|
+
* somewhere other than an argument slot, so all of them are caught — verified
|
|
92
|
+
* against each form. Inline predicates, which is what the list functions
|
|
93
|
+
* actually need, are untouched, and so is naming a plain *value*
|
|
94
|
+
* (`$total := $sum(…)`), which cannot recurse.
|
|
95
|
+
*
|
|
96
|
+
* **`$eval`.** It compiles a string as a new expression, which is the one hole
|
|
97
|
+
* through which everything above could be re-introduced. Matched on the
|
|
98
|
+
* variable name wherever it appears, so an alias (`$g := $eval`) or a reference
|
|
99
|
+
* (`$map(xs, $eval)`) is caught too, not just a direct call. AWS blocks it in
|
|
100
|
+
* their JSONata support for the same reason.
|
|
101
|
+
*
|
|
102
|
+
* **Unknown functions.** A name JSONata does not have, so that a typo is caught
|
|
103
|
+
* while writing rather than at `T1006`. This was skipped at first on the belief
|
|
104
|
+
* that the builtins could not be enumerated — they can: every name JSONata binds
|
|
105
|
+
* resolves to an object carrying its own signature, and
|
|
106
|
+
* `jsonata-signatures.ts` is generated from them. Checked after the two bans so
|
|
107
|
+
* that `$f(0)` beside a named function reports the named function, which is the
|
|
108
|
+
* more useful of the two complaints.
|
|
109
|
+
*
|
|
110
|
+
* Note this assumes nothing is registered beyond the builtins. If the engine
|
|
111
|
+
* ever calls `registerFunction`, those names have to be known here too, or
|
|
112
|
+
* correct expressions will be refused.
|
|
113
|
+
*/
|
|
114
|
+
export function inspectExpression(source) {
|
|
115
|
+
let ast;
|
|
116
|
+
try {
|
|
117
|
+
ast = compileExpression(source).ast();
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
const error = err;
|
|
121
|
+
return {
|
|
122
|
+
kind: 'syntax',
|
|
123
|
+
message: error.message ?? 'This expression could not be read.',
|
|
124
|
+
...(typeof error.position === 'number' ? { position: error.position } : {}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
let fault = null;
|
|
128
|
+
walkAst(ast, false, (node, inArgumentList) => {
|
|
129
|
+
if (fault)
|
|
130
|
+
return;
|
|
131
|
+
const position = node['position'];
|
|
132
|
+
const at = typeof position === 'number' ? { position } : {};
|
|
133
|
+
if (node['type'] === 'variable' && node['value'] === 'eval') {
|
|
134
|
+
fault = { kind: 'eval', message: '$eval is not available in expressions.', ...at };
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (node['type'] === 'lambda' && !inArgumentList) {
|
|
138
|
+
fault = {
|
|
139
|
+
kind: 'namedFunction',
|
|
140
|
+
message: 'An expression cannot define a named function. Write the function directly where it is used, as in $filter(items, function($i){ $i.amount > 10 }).',
|
|
141
|
+
...at,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (fault)
|
|
146
|
+
return fault;
|
|
147
|
+
// A second pass, so a banned construct is reported before a name that only
|
|
148
|
+
walkAst(ast, false, (node) => {
|
|
149
|
+
if (fault || node['type'] !== 'function')
|
|
150
|
+
return;
|
|
151
|
+
const procedure = node['procedure'];
|
|
152
|
+
if (procedure === null || typeof procedure !== 'object')
|
|
153
|
+
return;
|
|
154
|
+
const name = procedure['value'];
|
|
155
|
+
if (typeof name !== 'string' || isBuiltin(name))
|
|
156
|
+
return;
|
|
157
|
+
const position = procedure['position'];
|
|
158
|
+
fault = {
|
|
159
|
+
kind: 'unknownFunction',
|
|
160
|
+
message: `$${name} is not a function.`,
|
|
161
|
+
...(typeof position === 'number' ? { position } : {}),
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
return fault;
|
|
165
|
+
}
|
|
166
|
+
// ─── References inside an expression ───
|
|
167
|
+
export const ROOTS = new Set(EXPRESSION_ROOTS);
|
|
168
|
+
/** Dotted context paths an expression reads, e.g. */
|
|
169
|
+
export function refsInExpression(source) {
|
|
170
|
+
let ast;
|
|
171
|
+
try {
|
|
172
|
+
ast = compileExpression(source).ast();
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
const found = [];
|
|
178
|
+
walkAst(ast, false, (node) => {
|
|
179
|
+
if (node['type'] !== 'path')
|
|
180
|
+
return;
|
|
181
|
+
const steps = node['steps'];
|
|
182
|
+
if (!Array.isArray(steps) || steps.length === 0)
|
|
183
|
+
return;
|
|
184
|
+
const names = [];
|
|
185
|
+
for (const step of steps) {
|
|
186
|
+
if (step === null || typeof step !== 'object')
|
|
187
|
+
return;
|
|
188
|
+
const record = step;
|
|
189
|
+
if (record['type'] !== 'name' || typeof record['value'] !== 'string')
|
|
190
|
+
return;
|
|
191
|
+
names.push(record['value']);
|
|
192
|
+
}
|
|
193
|
+
if (!ROOTS.has(names[0]))
|
|
194
|
+
return;
|
|
195
|
+
const path = names.join('.');
|
|
196
|
+
if (!found.includes(path))
|
|
197
|
+
found.push(path);
|
|
198
|
+
});
|
|
199
|
+
return found;
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/expression/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,yBAAyB;AAEzB,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAW,CAAC;AAExE,+BAA+B;AAE/B,iCAAiC;AACjC,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;AAE5C,8CAA8C;AAC9C,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,gEAAgE;QAChE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrB,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACvB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACpD,IAAI,KAAK,CAAC,IAAI,IAAI,S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CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads JSONata's signature notation — `<a<n>:n>` is "a list of numbers, giving
|
|
3
|
+
* a number".
|
|
4
|
+
*
|
|
5
|
+
* Written here because JSONata's own parser is bundled with no import path to
|
|
6
|
+
* it, and no standalone package exists; the Go port wrote its own and the Rust
|
|
7
|
+
* one dropped signatures entirely. What *is* reachable, `signature.validate`,
|
|
8
|
+
* checks values, and author-time checking has types and no values.
|
|
9
|
+
*
|
|
10
|
+
* s n b l o a f string, number, boolean, null, object, array, function
|
|
11
|
+
* u j x some scalar, any JSON, anything
|
|
12
|
+
* a<T> a list of T — the distinction the checker rests on
|
|
13
|
+
* (sf) either; read as `unknown`
|
|
14
|
+
* - ? + from context, optional, variadic
|
|
15
|
+
*/
|
|
16
|
+
import type { ExprType } from './types.js';
|
|
17
|
+
export interface SignatureParam {
|
|
18
|
+
type: ExprType;
|
|
19
|
+
/** Declared `?` — absent is fine. */
|
|
20
|
+
optional: boolean;
|
|
21
|
+
/** Declared `+` — this type, one or more times, to the end of the call. */
|
|
22
|
+
variadic: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Declared `-` — JSONata may supply this argument from the context when it is left out.
|
|
25
|
+
*/
|
|
26
|
+
fromContext: boolean;
|
|
27
|
+
/** Declared `f` — this argument is a function. */
|
|
28
|
+
isFunction: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Signature {
|
|
31
|
+
params: SignatureParam[];
|
|
32
|
+
/** `unknown` when the signature declares no return, as `<af>` does. */
|
|
33
|
+
returns: ExprType;
|
|
34
|
+
}
|
|
35
|
+
/** Read a signature, or null when it cannot be read. */
|
|
36
|
+
export declare function parseSignature(definition: string): Signature | null;
|
|
37
|
+
/**
|
|
38
|
+
* The parameter governing argument `index`, or undefined when the call has more arguments than the signature describes.
|
|
39
|
+
*/
|
|
40
|
+
export declare function paramAt(signature: Signature, index: number): SignatureParam | undefined;
|
|
41
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/expression/signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,qCAAqC;IACrC,QAAQ,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,QAAQ,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,kDAAkD;IAClD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,uEAAuE;IACvE,OAAO,EAAE,QAAQ,CAAC;CACnB;AAwED,wDAAwD;AACxD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAmCnE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAKvF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** One type, from `at`, and where reading it finished. */
|
|
2
|
+
function readType(definition, at) {
|
|
3
|
+
const char = definition[at];
|
|
4
|
+
if (char === undefined)
|
|
5
|
+
return null;
|
|
6
|
+
let i = at + 1;
|
|
7
|
+
// Either of several things — not describable, so not checked.
|
|
8
|
+
if (char === '(') {
|
|
9
|
+
for (let depth = 1; i < definition.length && depth > 0; i++) {
|
|
10
|
+
if (definition[i] === '(')
|
|
11
|
+
depth++;
|
|
12
|
+
else if (definition[i] === ')')
|
|
13
|
+
depth--;
|
|
14
|
+
}
|
|
15
|
+
return { type: 'unknown', next: i };
|
|
16
|
+
}
|
|
17
|
+
if (char === 'a') {
|
|
18
|
+
if (definition[i] !== '<')
|
|
19
|
+
return { type: 'array', next: i };
|
|
20
|
+
const inner = readType(definition, i + 1);
|
|
21
|
+
if (inner === null || definition[inner.next] !== '>')
|
|
22
|
+
return null;
|
|
23
|
+
return { type: { array: inner.type }, next: inner.next + 1 };
|
|
24
|
+
}
|
|
25
|
+
if (char === 'f') {
|
|
26
|
+
// A function, possibly with a signature of its own. Nothing in this
|
|
27
|
+
if (definition[i] === '<') {
|
|
28
|
+
for (let depth = 1; i < definition.length && depth > 0;) {
|
|
29
|
+
i++;
|
|
30
|
+
if (definition[i] === '<')
|
|
31
|
+
depth++;
|
|
32
|
+
else if (definition[i] === '>')
|
|
33
|
+
depth--;
|
|
34
|
+
}
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
return { type: 'unknown', next: i, isFunction: true };
|
|
38
|
+
}
|
|
39
|
+
switch (char) {
|
|
40
|
+
case 's':
|
|
41
|
+
return { type: 'string', next: i };
|
|
42
|
+
case 'n':
|
|
43
|
+
return { type: 'number', next: i };
|
|
44
|
+
case 'b':
|
|
45
|
+
return { type: 'boolean', next: i };
|
|
46
|
+
case 'o':
|
|
47
|
+
return { type: 'object', next: i };
|
|
48
|
+
// `l` is null, `u`/`j`/`x` are "some scalar" / "any JSON" / "anything".
|
|
49
|
+
case 'l':
|
|
50
|
+
case 'u':
|
|
51
|
+
case 'j':
|
|
52
|
+
case 'x':
|
|
53
|
+
return { type: 'unknown', next: i };
|
|
54
|
+
default:
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Where the parameters end and the return type begins, or -1 for neither. */
|
|
59
|
+
function returnSeparator(body) {
|
|
60
|
+
let depth = 0;
|
|
61
|
+
for (let i = 0; i < body.length; i++) {
|
|
62
|
+
const char = body[i];
|
|
63
|
+
if (char === '<' || char === '(')
|
|
64
|
+
depth++;
|
|
65
|
+
else if (char === '>' || char === ')')
|
|
66
|
+
depth--;
|
|
67
|
+
else if (char === ':' && depth === 0)
|
|
68
|
+
return i;
|
|
69
|
+
}
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
/** Read a signature, or null when it cannot be read. */
|
|
73
|
+
export function parseSignature(definition) {
|
|
74
|
+
if (!definition.startsWith('<') || !definition.endsWith('>'))
|
|
75
|
+
return null;
|
|
76
|
+
const body = definition.slice(1, -1);
|
|
77
|
+
const separator = returnSeparator(body);
|
|
78
|
+
const paramText = separator === -1 ? body : body.slice(0, separator);
|
|
79
|
+
const returnText = separator === -1 ? '' : body.slice(separator + 1);
|
|
80
|
+
const params = [];
|
|
81
|
+
let at = 0;
|
|
82
|
+
while (at < paramText.length) {
|
|
83
|
+
const read = readType(paramText, at);
|
|
84
|
+
if (read === null)
|
|
85
|
+
return null;
|
|
86
|
+
at = read.next;
|
|
87
|
+
const param = {
|
|
88
|
+
type: read.type,
|
|
89
|
+
optional: false,
|
|
90
|
+
variadic: false,
|
|
91
|
+
fromContext: false,
|
|
92
|
+
isFunction: read.isFunction ?? false,
|
|
93
|
+
};
|
|
94
|
+
// Modifiers follow the type, in any order and any number.
|
|
95
|
+
for (; at < paramText.length; at++) {
|
|
96
|
+
if (paramText[at] === '?')
|
|
97
|
+
param.optional = true;
|
|
98
|
+
else if (paramText[at] === '+')
|
|
99
|
+
param.variadic = true;
|
|
100
|
+
else if (paramText[at] === '-')
|
|
101
|
+
param.fromContext = true;
|
|
102
|
+
else
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
params.push(param);
|
|
106
|
+
}
|
|
107
|
+
if (returnText === '')
|
|
108
|
+
return { params, returns: 'unknown' };
|
|
109
|
+
const returned = readType(returnText, 0);
|
|
110
|
+
if (returned === null || returned.next !== returnText.length)
|
|
111
|
+
return null;
|
|
112
|
+
return { params, returns: returned.type };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The parameter governing argument `index`, or undefined when the call has more arguments than the signature describes.
|
|
116
|
+
*/
|
|
117
|
+
export function paramAt(signature, index) {
|
|
118
|
+
const exact = signature.params[index];
|
|
119
|
+
if (exact)
|
|
120
|
+
return exact;
|
|
121
|
+
const last = signature.params[signature.params.length - 1];
|
|
122
|
+
return last?.variadic ? last : undefined;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/expression/signature.ts"],"names":[],"mappings":"AAqCA,0DAA0D;AAC1D,SAAS,QAAQ,CACf,UAAkB,EAClB,EAAU;IAEV,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;IAC5B,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEf,8DAA8D;IAC9D,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5D,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG;gBAAE,KAAK,EAAE,CAAC;iBAC9B,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG;gBAAE,KAAK,EAAE,CAAC;QAC1C,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IACtC,CAAC;IAED,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QACjB,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,UA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,OAAO,IAAI,CAAC;IAC1E,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,SAAoB,EAAE,KAAa;IACzD,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3D,OAAO,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every JSONata builtin, with the signature JSONata itself declares for it.
|
|
3
|
+
*
|
|
4
|
+
* **Generated, not written.** The names come from `staticFrame.bind('…')` in the
|
|
5
|
+
* installed `jsonata`, and each signature from evaluating `$name` — a builtin
|
|
6
|
+
* resolves to an object carrying `signature.definition`. `jsonata-signatures.test.ts`
|
|
7
|
+
* re-derives this table from the installed package and fails if it has drifted,
|
|
8
|
+
* so an upgrade cannot silently leave it stale.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this is here at all
|
|
11
|
+
*
|
|
12
|
+
* The alternative was writing the types out by hand, and that was tried first:
|
|
13
|
+
* it put `object` on `$keys`, `array` on `$distinct` and `array` on `$append`,
|
|
14
|
+
* all three of which really take anything — so correct expressions were refused.
|
|
15
|
+
* A type checker that is wrong is worse than none, and the only defence is to
|
|
16
|
+
* take the types from the language rather than restate them.
|
|
17
|
+
*
|
|
18
|
+
* It also buys reach: every one of these is typed, not the twenty-odd a curated
|
|
19
|
+
* list would cover, and a name absent from this table is a name JSONata does not
|
|
20
|
+
* have — which is how a typo gets caught.
|
|
21
|
+
*
|
|
22
|
+
* ## Why generated rather than read at run time
|
|
23
|
+
*
|
|
24
|
+
* JSONata does expose these through its public API — `jsonata('$sum')
|
|
25
|
+
* .evaluate({})` resolves to the builtin object and carries
|
|
26
|
+
* `signature.definition`, no internals involved. The reason not to is that
|
|
27
|
+
* `evaluate` is **async**, and the catalogue it would feed is consulted
|
|
28
|
+
* synchronously while a menu renders. Reading them live would make building the
|
|
29
|
+
* catalogue async, or need a top-level await, to learn facts that are fixed for
|
|
30
|
+
* a given version of the dependency.
|
|
31
|
+
*
|
|
32
|
+
* So the table is a build-time snapshot of a run-time truth, and the drift test
|
|
33
|
+
* is what makes that safe: it takes the same public route on every run and
|
|
34
|
+
* fails if the two have parted. The one thing it reaches into the package for
|
|
35
|
+
* is the *list of names* — there is no public enumeration — and that stays in
|
|
36
|
+
* the test, never in what ships.
|
|
37
|
+
*
|
|
38
|
+
* Signatures are JSONata's own notation; `signature.ts` reads it.
|
|
39
|
+
*/
|
|
40
|
+
export declare const BUILTIN_SIGNATURES: Readonly<Record<string, string>>;
|
|
41
|
+
/** True when JSONata has a builtin by this name (with or without the `$`). */
|
|
42
|
+
export declare function isBuiltin(name: string): boolean;
|
|
43
|
+
/** JSONata's declared signature for a builtin, or undefined when it has none. */
|
|
44
|
+
export declare function builtinSignature(name: string): string | undefined;
|
|
45
|
+
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/expression/signatures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgE/D,CAAC;AAEF,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK/C;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjE"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every JSONata builtin, with the signature JSONata itself declares for it.
|
|
3
|
+
*
|
|
4
|
+
* **Generated, not written.** The names come from `staticFrame.bind('…')` in the
|
|
5
|
+
* installed `jsonata`, and each signature from evaluating `$name` — a builtin
|
|
6
|
+
* resolves to an object carrying `signature.definition`. `jsonata-signatures.test.ts`
|
|
7
|
+
* re-derives this table from the installed package and fails if it has drifted,
|
|
8
|
+
* so an upgrade cannot silently leave it stale.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this is here at all
|
|
11
|
+
*
|
|
12
|
+
* The alternative was writing the types out by hand, and that was tried first:
|
|
13
|
+
* it put `object` on `$keys`, `array` on `$distinct` and `array` on `$append`,
|
|
14
|
+
* all three of which really take anything — so correct expressions were refused.
|
|
15
|
+
* A type checker that is wrong is worse than none, and the only defence is to
|
|
16
|
+
* take the types from the language rather than restate them.
|
|
17
|
+
*
|
|
18
|
+
* It also buys reach: every one of these is typed, not the twenty-odd a curated
|
|
19
|
+
* list would cover, and a name absent from this table is a name JSONata does not
|
|
20
|
+
* have — which is how a typo gets caught.
|
|
21
|
+
*
|
|
22
|
+
* ## Why generated rather than read at run time
|
|
23
|
+
*
|
|
24
|
+
* JSONata does expose these through its public API — `jsonata('$sum')
|
|
25
|
+
* .evaluate({})` resolves to the builtin object and carries
|
|
26
|
+
* `signature.definition`, no internals involved. The reason not to is that
|
|
27
|
+
* `evaluate` is **async**, and the catalogue it would feed is consulted
|
|
28
|
+
* synchronously while a menu renders. Reading them live would make building the
|
|
29
|
+
* catalogue async, or need a top-level await, to learn facts that are fixed for
|
|
30
|
+
* a given version of the dependency.
|
|
31
|
+
*
|
|
32
|
+
* So the table is a build-time snapshot of a run-time truth, and the drift test
|
|
33
|
+
* is what makes that safe: it takes the same public route on every run and
|
|
34
|
+
* fails if the two have parted. The one thing it reaches into the package for
|
|
35
|
+
* is the *list of names* — there is no public enumeration — and that stays in
|
|
36
|
+
* the test, never in what ships.
|
|
37
|
+
*
|
|
38
|
+
* Signatures are JSONata's own notation; `signature.ts` reads it.
|
|
39
|
+
*/
|
|
40
|
+
export const BUILTIN_SIGNATURES = {
|
|
41
|
+
abs: '<n-:n>',
|
|
42
|
+
append: '<xx:a>',
|
|
43
|
+
assert: '<bs?:x>',
|
|
44
|
+
average: '<a<n>:n>',
|
|
45
|
+
base64decode: '<s-:s>',
|
|
46
|
+
base64encode: '<s-:s>',
|
|
47
|
+
boolean: '<x-:b>',
|
|
48
|
+
ceil: '<n-:n>',
|
|
49
|
+
clone: '<(oa)-:o>',
|
|
50
|
+
contains: '<s-(sf):b>',
|
|
51
|
+
count: '<a:n>',
|
|
52
|
+
decodeUrl: '<s-:s>',
|
|
53
|
+
decodeUrlComponent: '<s-:s>',
|
|
54
|
+
distinct: '<x:x>',
|
|
55
|
+
each: '<o-f:a>',
|
|
56
|
+
encodeUrl: '<s-:s>',
|
|
57
|
+
encodeUrlComponent: '<s-:s>',
|
|
58
|
+
error: '<s?:x>',
|
|
59
|
+
eval: '<sx?:x>',
|
|
60
|
+
exists: '<x:b>',
|
|
61
|
+
filter: '<af>',
|
|
62
|
+
floor: '<n-:n>',
|
|
63
|
+
formatBase: '<n-n?:s>',
|
|
64
|
+
formatInteger: '<n-s:s>',
|
|
65
|
+
formatNumber: '<n-so?:s>',
|
|
66
|
+
fromMillis: '<n-s?s?:s>',
|
|
67
|
+
join: '<a<s>s?:s>',
|
|
68
|
+
keys: '<x-:a<s>>',
|
|
69
|
+
length: '<s-:n>',
|
|
70
|
+
lookup: '<x-s:x>',
|
|
71
|
+
lowercase: '<s-:s>',
|
|
72
|
+
map: '<af>',
|
|
73
|
+
match: '<s-f<s:o>n?:a<o>>',
|
|
74
|
+
max: '<a<n>:n>',
|
|
75
|
+
merge: '<a<o>:o>',
|
|
76
|
+
min: '<a<n>:n>',
|
|
77
|
+
not: '<x-:b>',
|
|
78
|
+
number: '<(nsb)-:n>',
|
|
79
|
+
pad: '<s-ns?:s>',
|
|
80
|
+
parseInteger: '<s-s:n>',
|
|
81
|
+
power: '<n-n:n>',
|
|
82
|
+
random: '<:n>',
|
|
83
|
+
reduce: '<afj?:j>',
|
|
84
|
+
replace: '<s-(sf)(sf)n?:s>',
|
|
85
|
+
reverse: '<a:a>',
|
|
86
|
+
round: '<n-n?:n>',
|
|
87
|
+
shuffle: '<a:a>',
|
|
88
|
+
sift: '<o-f?:o>',
|
|
89
|
+
single: '<af?>',
|
|
90
|
+
sort: '<af?:a>',
|
|
91
|
+
split: '<s-(sf)n?:a<s>>',
|
|
92
|
+
spread: '<x-:a<o>>',
|
|
93
|
+
sqrt: '<n-:n>',
|
|
94
|
+
string: '<x-b?:s>',
|
|
95
|
+
substring: '<s-nn?:s>',
|
|
96
|
+
substringAfter: '<s-s:s>',
|
|
97
|
+
substringBefore: '<s-s:s>',
|
|
98
|
+
sum: '<a<n>:n>',
|
|
99
|
+
toMillis: '<s-s?:n>',
|
|
100
|
+
trim: '<s-:s>',
|
|
101
|
+
type: '<x:s>',
|
|
102
|
+
uppercase: '<s-:s>',
|
|
103
|
+
zip: '<a+>',
|
|
104
|
+
};
|
|
105
|
+
/** True when JSONata has a builtin by this name (with or without the `$`). */
|
|
106
|
+
export function isBuiltin(name) {
|
|
107
|
+
return Object.prototype.hasOwnProperty.call(BUILTIN_SIGNATURES, name.startsWith('$') ? name.slice(1) : name);
|
|
108
|
+
}
|
|
109
|
+
/** JSONata's declared signature for a builtin, or undefined when it has none. */
|
|
110
|
+
export function builtinSignature(name) {
|
|
111
|
+
return BUILTIN_SIGNATURES[name.startsWith('$') ? name.slice(1) : name];
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=signatures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.js","sourceRoot":"","sources":["../../src/expression/signatures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAK,EAAe,UAAU;IAC9B,OAAO,EAAa,OAAO;IAC3B,IAAI,EAAgB,UAAU;IAC9B,MAAM,EAAc,OAAO;IAC3B,IAAI,EAAgB,SAAS;IAC7B,KAAK,EAAe,iBAAiB;IACrC,MAAM,EAAc,WAAW;IAC/B,IAAI,EAAgB,QAAQ;IAC5B,MAAM,EAAc,UAAU;IAC9B,SAAS,EAAW,WAAW;IAC/B,cAAc,EAAM,SAAS;IAC7B,eAAe,EAAK,SAAS;IAC7B,GAAG,EAAiB,UAAU;IAC9B,QAAQ,EAAY,UAAU;IAC9B,IAAI,EAAgB,QAAQ;IAC5B,IAAI,EAAgB,OAAO;IAC3B,SAAS,EAAW,QAAQ;IAC5B,GAAG,EAAiB,MAAM;CAC3B,CAAC;AAEF,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CACzC,kBAAkB,EAClB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAC5C,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types as an expression sees them: a {@link TypeKind} plus one level of "a
|
|
3
|
+
* list of". Anything deeper is `unknown`, a wildcard at every depth.
|
|
4
|
+
*
|
|
5
|
+
* Two assignability rules, and the difference is the point: a *field* coerces,
|
|
6
|
+
* because the runtime stringifies whatever lands in it, and an *argument* does
|
|
7
|
+
* not, because JSONata answers a mismatched parameter with T0410.
|
|
8
|
+
*/
|
|
9
|
+
import type { TypeKind } from '../util/type-compat.js';
|
|
10
|
+
/** The type of a value an expression reads or produces. */
|
|
11
|
+
export type ExprType = TypeKind | {
|
|
12
|
+
readonly array: ExprType;
|
|
13
|
+
};
|
|
14
|
+
/** `array<number>` → `'array'`. What a field-level check compares. */
|
|
15
|
+
export declare function baseKind(type: ExprType): TypeKind;
|
|
16
|
+
/** `array<number>` → `number`; anything else → `unknown`. */
|
|
17
|
+
export declare function elementType(type: ExprType): ExprType;
|
|
18
|
+
/** Spell a type the way an author would read it: `list of numbers`. */
|
|
19
|
+
export declare function sayType(type: ExprType): string;
|
|
20
|
+
/** Can an expression's result be bound into a field of this type? */
|
|
21
|
+
export declare function assignableToField(source: ExprType, target: ExprType): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Can a value of this type be passed as a function argument?
|
|
24
|
+
*
|
|
25
|
+
* **Deliberately stricter than {@link assignableToField}, and this distinction
|
|
26
|
+
* is the point:** a field coerces, a function does not. The runtime stringifies
|
|
27
|
+
* whatever lands in a text field, which is why `kindsCompatible` lets anything
|
|
28
|
+
* into a `string` target — but JSONata performs no such favour for a parameter.
|
|
29
|
+
* `$uppercase(someNumber)` is a hard `T0410` at runtime, and going by the field
|
|
30
|
+
* rule would have declared it fine.
|
|
31
|
+
*
|
|
32
|
+
* So: kinds must match. `unknown` is still a wildcard at every depth, and
|
|
33
|
+
* `scalar` — the coarsening bucket for enums, literals and dates — is treated as
|
|
34
|
+
* unverifiable rather than as a mismatch.
|
|
35
|
+
*
|
|
36
|
+
* ## One value where a list is wanted
|
|
37
|
+
*
|
|
38
|
+
* The exception, and it is JSONata's rather than ours: an `a<T>` parameter
|
|
39
|
+
* **wraps** a single value in a list rather than refusing it, so `$sum(5)` is 5
|
|
40
|
+
* and `$reverse(5)` is `[5]`. Only the element type is enforced — `$sum("x")`
|
|
41
|
+
* is still a `T0412`.
|
|
42
|
+
*
|
|
43
|
+
* Refusing it here would have been wrong twice over. `$sum(items.amount)` is
|
|
44
|
+
* the expression this whole feature exists for, and a type lookup coarse enough
|
|
45
|
+
* to call `items.amount` a number — which any picker tree carrying JSON-Schema
|
|
46
|
+
* `type` keywords does — would see a fault in it. And a filter that matches one
|
|
47
|
+
* item returns that item rather than a list of one, so `$sum(items[id = 3].n)`
|
|
48
|
+
* is a *scalar* at runtime whenever it matches once. Both are valid; neither may
|
|
49
|
+
* be flagged.
|
|
50
|
+
*/
|
|
51
|
+
export declare function assignableToArgument(source: ExprType, target: ExprType): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The one type that describes every branch — for an array literal, or the two arms of a condition.
|
|
54
|
+
*/
|
|
55
|
+
export declare function unify(types: readonly ExprType[]): ExprType;
|
|
56
|
+
/**
|
|
57
|
+
* A literal as JSONata source, written **as the parameter wants it** rather
|
|
58
|
+
* than as it looks.
|
|
59
|
+
*
|
|
60
|
+
* Guessing from the text is unsafe in both directions, and both were measured:
|
|
61
|
+
* `$replace("a2c", 2, "X")` is a `T0410` because argument 2 must be text, and
|
|
62
|
+
* `$round(1.234, "2")` is a `T0410` because argument 2 must be a number. The
|
|
63
|
+
* same four characters have to be written two different ways depending on where
|
|
64
|
+
* they land, so only the signature can decide.
|
|
65
|
+
*
|
|
66
|
+
* `null` when the text cannot be that type — `abc` is not a number. The caller
|
|
67
|
+
* refuses to write anything rather than emitting something that fails at
|
|
68
|
+
* runtime, in front of a customer.
|
|
69
|
+
*/
|
|
70
|
+
export declare function writeLiteralAs(raw: string, want: ExprType): string | null;
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/expression/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,2DAA2D;AAC3D,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC;AAG/D,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAEjD;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAEpD;AAED,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAY9C;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAU7E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAUhF;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAW1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAuBzE"}
|