n8n-workflow 2.42.2 → 2.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/build.tsbuildinfo +1 -1
- package/dist/cjs/common/get-runnable-nodes.d.ts +31 -0
- package/dist/cjs/common/get-runnable-nodes.d.ts.map +1 -0
- package/dist/cjs/common/get-runnable-nodes.js +97 -0
- package/dist/cjs/common/get-runnable-nodes.js.map +1 -0
- package/dist/cjs/common/index.d.ts +1 -0
- package/dist/cjs/common/index.d.ts.map +1 -1
- package/dist/cjs/common/index.js +1 -0
- package/dist/cjs/common/index.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +4 -3
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/errors/abstract/execution-base.error.d.ts +1 -1
- package/dist/cjs/errors/abstract/execution-base.error.d.ts.map +1 -1
- package/dist/cjs/errors/abstract/execution-base.error.js +2 -2
- package/dist/cjs/errors/abstract/execution-base.error.js.map +1 -1
- package/dist/cjs/errors/db-connection-timeout-error.d.ts +1 -1
- package/dist/cjs/errors/db-connection-timeout-error.d.ts.map +1 -1
- package/dist/cjs/errors/db-connection-timeout-error.js +2 -2
- package/dist/cjs/errors/db-connection-timeout-error.js.map +1 -1
- package/dist/cjs/errors/index.d.ts +1 -5
- package/dist/cjs/errors/index.d.ts.map +1 -1
- package/dist/cjs/errors/index.js +7 -11
- package/dist/cjs/errors/index.js.map +1 -1
- package/dist/cjs/errors/node-operation.error.js +2 -2
- package/dist/cjs/errors/node-operation.error.js.map +1 -1
- package/dist/cjs/errors/node-version-not-found.error.d.ts +1 -1
- package/dist/cjs/errors/node-version-not-found.error.d.ts.map +1 -1
- package/dist/cjs/errors/node-version-not-found.error.js +2 -2
- package/dist/cjs/errors/node-version-not-found.error.js.map +1 -1
- package/dist/cjs/errors/trigger-close.error.d.ts +1 -1
- package/dist/cjs/errors/trigger-close.error.d.ts.map +1 -1
- package/dist/cjs/errors/trigger-close.error.js +2 -2
- package/dist/cjs/errors/trigger-close.error.js.map +1 -1
- package/dist/cjs/expression.d.ts +6 -0
- package/dist/cjs/expression.d.ts.map +1 -1
- package/dist/cjs/expression.js +22 -7
- package/dist/cjs/expression.js.map +1 -1
- package/dist/cjs/expressions/native-evaluation/evaluator.d.ts +21 -0
- package/dist/cjs/expressions/native-evaluation/evaluator.d.ts.map +1 -0
- package/dist/cjs/expressions/native-evaluation/evaluator.js +372 -0
- package/dist/cjs/expressions/native-evaluation/evaluator.js.map +1 -0
- package/dist/cjs/expressions/native-evaluation/grammar.d.ts +63 -0
- package/dist/cjs/expressions/native-evaluation/grammar.d.ts.map +1 -0
- package/dist/cjs/expressions/native-evaluation/grammar.js +113 -0
- package/dist/cjs/expressions/native-evaluation/grammar.js.map +1 -0
- package/dist/cjs/expressions/native-evaluation/index.d.ts +17 -0
- package/dist/cjs/expressions/native-evaluation/index.d.ts.map +1 -0
- package/dist/cjs/expressions/native-evaluation/index.js +144 -0
- package/dist/cjs/expressions/native-evaluation/index.js.map +1 -0
- package/dist/cjs/expressions/native-evaluation/parser.d.ts +6 -0
- package/dist/cjs/expressions/native-evaluation/parser.d.ts.map +1 -0
- package/dist/cjs/expressions/native-evaluation/parser.js +159 -0
- package/dist/cjs/expressions/native-evaluation/parser.js.map +1 -0
- package/dist/cjs/extensions/date-extensions.js +2 -2
- package/dist/cjs/extensions/number-extensions.js +2 -2
- package/dist/cjs/extensions/string-extensions.js +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces.d.ts +27 -6
- package/dist/cjs/interfaces.d.ts.map +1 -1
- package/dist/cjs/interfaces.js +3 -0
- package/dist/cjs/interfaces.js.map +1 -1
- package/dist/cjs/native-methods/array.methods.js +4 -4
- package/dist/cjs/node-helpers.d.ts +13 -1
- package/dist/cjs/node-helpers.d.ts.map +1 -1
- package/dist/cjs/node-helpers.js +3 -1
- package/dist/cjs/node-helpers.js.map +1 -1
- package/dist/cjs/node-parameters/filter-parameter.d.ts +1 -1
- package/dist/cjs/node-parameters/filter-parameter.d.ts.map +1 -1
- package/dist/cjs/node-parameters/filter-parameter.js +2 -2
- package/dist/cjs/node-parameters/filter-parameter.js.map +1 -1
- package/dist/cjs/node-validation.d.ts +17 -5
- package/dist/cjs/node-validation.d.ts.map +1 -1
- package/dist/cjs/node-validation.js +39 -16
- package/dist/cjs/node-validation.js.map +1 -1
- package/dist/cjs/run-execution-data/run-execution-data.v1.d.ts +13 -0
- package/dist/cjs/run-execution-data/run-execution-data.v1.d.ts.map +1 -1
- package/dist/cjs/run-execution-data/run-execution-data.v1.js.map +1 -1
- package/dist/cjs/run-execution-data-factory.d.ts +1 -0
- package/dist/cjs/run-execution-data-factory.d.ts.map +1 -1
- package/dist/cjs/run-execution-data-factory.js +1 -0
- package/dist/cjs/run-execution-data-factory.js.map +1 -1
- package/dist/cjs/sub-workflow-output.d.ts +13 -1
- package/dist/cjs/sub-workflow-output.d.ts.map +1 -1
- package/dist/cjs/sub-workflow-output.js +64 -0
- package/dist/cjs/sub-workflow-output.js.map +1 -1
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/webhook-description-fields.d.ts +31 -0
- package/dist/cjs/webhook-description-fields.d.ts.map +1 -1
- package/dist/cjs/webhook-description-fields.js +34 -0
- package/dist/cjs/webhook-description-fields.js.map +1 -1
- package/dist/esm/common/get-runnable-nodes.d.ts +31 -0
- package/dist/esm/common/get-runnable-nodes.d.ts.map +1 -0
- package/dist/esm/common/get-runnable-nodes.js +93 -0
- package/dist/esm/common/get-runnable-nodes.js.map +1 -0
- package/dist/esm/common/index.d.ts +1 -0
- package/dist/esm/common/index.d.ts.map +1 -1
- package/dist/esm/common/index.js +1 -0
- package/dist/esm/common/index.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +1 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/errors/abstract/execution-base.error.d.ts +1 -1
- package/dist/esm/errors/abstract/execution-base.error.d.ts.map +1 -1
- package/dist/esm/errors/abstract/execution-base.error.js +1 -1
- package/dist/esm/errors/abstract/execution-base.error.js.map +1 -1
- package/dist/esm/errors/db-connection-timeout-error.d.ts +1 -1
- package/dist/esm/errors/db-connection-timeout-error.d.ts.map +1 -1
- package/dist/esm/errors/db-connection-timeout-error.js +1 -1
- package/dist/esm/errors/db-connection-timeout-error.js.map +1 -1
- package/dist/esm/errors/index.d.ts +1 -5
- package/dist/esm/errors/index.d.ts.map +1 -1
- package/dist/esm/errors/index.js +1 -5
- package/dist/esm/errors/index.js.map +1 -1
- package/dist/esm/errors/node-operation.error.js +1 -1
- package/dist/esm/errors/node-operation.error.js.map +1 -1
- package/dist/esm/errors/node-version-not-found.error.d.ts +1 -1
- package/dist/esm/errors/node-version-not-found.error.d.ts.map +1 -1
- package/dist/esm/errors/node-version-not-found.error.js +1 -1
- package/dist/esm/errors/node-version-not-found.error.js.map +1 -1
- package/dist/esm/errors/trigger-close.error.d.ts +1 -1
- package/dist/esm/errors/trigger-close.error.d.ts.map +1 -1
- package/dist/esm/errors/trigger-close.error.js +1 -1
- package/dist/esm/errors/trigger-close.error.js.map +1 -1
- package/dist/esm/expression.d.ts +6 -0
- package/dist/esm/expression.d.ts.map +1 -1
- package/dist/esm/expression.js +22 -7
- package/dist/esm/expression.js.map +1 -1
- package/dist/esm/expressions/native-evaluation/evaluator.d.ts +21 -0
- package/dist/esm/expressions/native-evaluation/evaluator.d.ts.map +1 -0
- package/dist/esm/expressions/native-evaluation/evaluator.js +366 -0
- package/dist/esm/expressions/native-evaluation/evaluator.js.map +1 -0
- package/dist/esm/expressions/native-evaluation/grammar.d.ts +63 -0
- package/dist/esm/expressions/native-evaluation/grammar.d.ts.map +1 -0
- package/dist/esm/expressions/native-evaluation/grammar.js +108 -0
- package/dist/esm/expressions/native-evaluation/grammar.js.map +1 -0
- package/dist/esm/expressions/native-evaluation/index.d.ts +17 -0
- package/dist/esm/expressions/native-evaluation/index.d.ts.map +1 -0
- package/dist/esm/expressions/native-evaluation/index.js +137 -0
- package/dist/esm/expressions/native-evaluation/index.js.map +1 -0
- package/dist/esm/expressions/native-evaluation/parser.d.ts +6 -0
- package/dist/esm/expressions/native-evaluation/parser.d.ts.map +1 -0
- package/dist/esm/expressions/native-evaluation/parser.js +156 -0
- package/dist/esm/expressions/native-evaluation/parser.js.map +1 -0
- package/dist/esm/extensions/date-extensions.js +2 -2
- package/dist/esm/extensions/number-extensions.js +2 -2
- package/dist/esm/extensions/string-extensions.js +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.d.ts +27 -6
- package/dist/esm/interfaces.d.ts.map +1 -1
- package/dist/esm/interfaces.js +3 -0
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/native-methods/array.methods.js +4 -4
- package/dist/esm/node-helpers.d.ts +13 -1
- package/dist/esm/node-helpers.d.ts.map +1 -1
- package/dist/esm/node-helpers.js +3 -1
- package/dist/esm/node-helpers.js.map +1 -1
- package/dist/esm/node-parameters/filter-parameter.d.ts +1 -1
- package/dist/esm/node-parameters/filter-parameter.d.ts.map +1 -1
- package/dist/esm/node-parameters/filter-parameter.js +1 -1
- package/dist/esm/node-parameters/filter-parameter.js.map +1 -1
- package/dist/esm/node-validation.d.ts +17 -5
- package/dist/esm/node-validation.d.ts.map +1 -1
- package/dist/esm/node-validation.js +39 -16
- package/dist/esm/node-validation.js.map +1 -1
- package/dist/esm/run-execution-data/run-execution-data.v1.d.ts +13 -0
- package/dist/esm/run-execution-data/run-execution-data.v1.d.ts.map +1 -1
- package/dist/esm/run-execution-data/run-execution-data.v1.js.map +1 -1
- package/dist/esm/run-execution-data-factory.d.ts +1 -0
- package/dist/esm/run-execution-data-factory.d.ts.map +1 -1
- package/dist/esm/run-execution-data-factory.js +1 -0
- package/dist/esm/run-execution-data-factory.js.map +1 -1
- package/dist/esm/sub-workflow-output.d.ts +13 -1
- package/dist/esm/sub-workflow-output.d.ts.map +1 -1
- package/dist/esm/sub-workflow-output.js +60 -0
- package/dist/esm/sub-workflow-output.js.map +1 -1
- package/dist/esm/typecheck.tsbuildinfo +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/webhook-description-fields.d.ts +31 -0
- package/dist/esm/webhook-description-fields.d.ts.map +1 -1
- package/dist/esm/webhook-description-fields.js +33 -0
- package/dist/esm/webhook-description-fields.js.map +1 -1
- package/package.json +15 -14
- package/dist/cjs/errors/base/base.error.d.ts +0 -26
- package/dist/cjs/errors/base/base.error.d.ts.map +0 -1
- package/dist/cjs/errors/base/base.error.js +0 -43
- package/dist/cjs/errors/base/base.error.js.map +0 -1
- package/dist/cjs/errors/base/operational.error.d.ts +0 -16
- package/dist/cjs/errors/base/operational.error.d.ts.map +0 -1
- package/dist/cjs/errors/base/operational.error.js +0 -19
- package/dist/cjs/errors/base/operational.error.js.map +0 -1
- package/dist/cjs/errors/base/unexpected.error.d.ts +0 -16
- package/dist/cjs/errors/base/unexpected.error.d.ts.map +0 -1
- package/dist/cjs/errors/base/unexpected.error.js +0 -19
- package/dist/cjs/errors/base/unexpected.error.js.map +0 -1
- package/dist/cjs/errors/base/user.error.d.ts +0 -18
- package/dist/cjs/errors/base/user.error.d.ts.map +0 -1
- package/dist/cjs/errors/base/user.error.js +0 -19
- package/dist/cjs/errors/base/user.error.js.map +0 -1
- package/dist/esm/errors/base/base.error.d.ts +0 -26
- package/dist/esm/errors/base/base.error.d.ts.map +0 -1
- package/dist/esm/errors/base/base.error.js +0 -36
- package/dist/esm/errors/base/base.error.js.map +0 -1
- package/dist/esm/errors/base/operational.error.d.ts +0 -16
- package/dist/esm/errors/base/operational.error.d.ts.map +0 -1
- package/dist/esm/errors/base/operational.error.js +0 -15
- package/dist/esm/errors/base/operational.error.js.map +0 -1
- package/dist/esm/errors/base/unexpected.error.d.ts +0 -16
- package/dist/esm/errors/base/unexpected.error.d.ts.map +0 -1
- package/dist/esm/errors/base/unexpected.error.js +0 -15
- package/dist/esm/errors/base/unexpected.error.js.map +0 -1
- package/dist/esm/errors/base/user.error.d.ts +0 -18
- package/dist/esm/errors/base/user.error.d.ts.map +0 -1
- package/dist/esm/errors/base/user.error.js +0 -15
- package/dist/esm/errors/base/user.error.js.map +0 -1
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { ExpressionExtensionError } from '../../errors/expression-extension.error';
|
|
2
|
+
import { ExpressionError } from '../../errors/expression.error';
|
|
3
|
+
import { ARRAY_METHODS, MAX_DEPTH, MAX_RESULT_LENGTH, NUMBER_METHODS, STRING_METHODS, hasOwn, isArray, isObj, toNum, toStr, } from './grammar';
|
|
4
|
+
// ── Evaluation: total over the grammar. ────────────────────────────────────
|
|
5
|
+
//
|
|
6
|
+
// evalNode reads only fields parseSimple constructed, because those are the
|
|
7
|
+
// only fields that exist. The switch has no default branch: adding a kind to
|
|
8
|
+
// the grammar stops compilation until it is handled here.
|
|
9
|
+
/**
|
|
10
|
+
* Thrown when a runtime value falls outside what parsing proved statically
|
|
11
|
+
* (a whitelisted string method on a non-string receiver, an operator on an
|
|
12
|
+
* object operand, a result above MAX_RESULT_LENGTH). The whole evaluation is
|
|
13
|
+
* abandoned and the caller re-runs the expression through the regular engine
|
|
14
|
+
* pipeline. Anything evaluated before the bail runs again in the engine: a
|
|
15
|
+
* nested `$parameter` expression, or a getter on a data object. Expressions
|
|
16
|
+
* are pure and workflow data is JSON, so the only cost is the repeated work.
|
|
17
|
+
*/
|
|
18
|
+
export class EngineFallbackError extends Error {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Thrown by an optional member/call on a nullish receiver and caught by the
|
|
22
|
+
* enclosing chain node, which yields undefined for the whole chain. One
|
|
23
|
+
* shared instance: a missing optional hop is ordinary data, not an error.
|
|
24
|
+
*/
|
|
25
|
+
class ChainShortCircuit extends Error {
|
|
26
|
+
}
|
|
27
|
+
const chainShortCircuit = new ChainShortCircuit();
|
|
28
|
+
/**
|
|
29
|
+
* Property lookup on a non-nullish primitive is well-defined and side-effect
|
|
30
|
+
* free, so primitives are indexable here even though the predicate's type
|
|
31
|
+
* only names objects.
|
|
32
|
+
*/
|
|
33
|
+
const isIndexable = (value) => value !== null && value !== undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Operators only ever see primitives. An object operand would coerce through
|
|
36
|
+
* its valueOf/toString on the host, where the engine sees a structured-clone
|
|
37
|
+
* copy; a reference comparison would differ from the engine's copy semantics.
|
|
38
|
+
*/
|
|
39
|
+
const isPrimitive = (value) => value === null || (typeof value !== 'object' && typeof value !== 'function');
|
|
40
|
+
export function bounded(value) {
|
|
41
|
+
const isSizeable = typeof value === 'string' || isArray(value);
|
|
42
|
+
if (isSizeable && value.length > MAX_RESULT_LENGTH) {
|
|
43
|
+
throw new EngineFallbackError();
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
// Operand casts are intentional: the interpreter must reproduce JS coercion
|
|
48
|
+
// semantics exactly (parity with the engines), not re-implement them.
|
|
49
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
50
|
+
const binaryOps = Object.freeze({
|
|
51
|
+
'===': (l, r) => l === r,
|
|
52
|
+
'!==': (l, r) => l !== r,
|
|
53
|
+
// eslint-disable-next-line eqeqeq
|
|
54
|
+
'==': (l, r) => l == r,
|
|
55
|
+
// eslint-disable-next-line eqeqeq
|
|
56
|
+
'!=': (l, r) => l != r,
|
|
57
|
+
'<': (l, r) => l < r,
|
|
58
|
+
'<=': (l, r) => l <= r,
|
|
59
|
+
'>': (l, r) => l > r,
|
|
60
|
+
'>=': (l, r) => l >= r,
|
|
61
|
+
'+': (l, r) => bounded(l + r),
|
|
62
|
+
'-': (l, r) => l - r,
|
|
63
|
+
'*': (l, r) => l * r,
|
|
64
|
+
'/': (l, r) => l / r,
|
|
65
|
+
'%': (l, r) => l % r,
|
|
66
|
+
});
|
|
67
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
68
|
+
function evalMember(node, data) {
|
|
69
|
+
const object = evalNode(node.object, data);
|
|
70
|
+
if (node.optional && (object === null || object === undefined)) {
|
|
71
|
+
throw chainShortCircuit;
|
|
72
|
+
}
|
|
73
|
+
if (!isIndexable(object)) {
|
|
74
|
+
throw new TypeError(`Cannot read properties of ${toStr(object)} (reading '${node.key}')`);
|
|
75
|
+
}
|
|
76
|
+
// Below the roots (get-trap proxies, where Object.hasOwn misreports every
|
|
77
|
+
// key) the data is plain JSON, so an inherited property is a host prototype
|
|
78
|
+
// the isolates never see. The engine decides what it yields.
|
|
79
|
+
const inherited = node.object.kind !== 'root' &&
|
|
80
|
+
typeof object === 'object' &&
|
|
81
|
+
node.key in object &&
|
|
82
|
+
!hasOwn(object, node.key);
|
|
83
|
+
if (inherited) {
|
|
84
|
+
throw new EngineFallbackError();
|
|
85
|
+
}
|
|
86
|
+
const value = object[node.key];
|
|
87
|
+
// Neither crosses an engine boundary the same way twice (the vm bridge
|
|
88
|
+
// drops a nested function but fails on an inherited one; legacy throws),
|
|
89
|
+
// so the configured engine decides rather than this module guessing.
|
|
90
|
+
if (typeof value === 'function' || typeof value === 'symbol') {
|
|
91
|
+
throw new EngineFallbackError();
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parsing only proves the method name; the receiver's type is data. A
|
|
97
|
+
* receiver whose type has no allowlist entry for the method could be
|
|
98
|
+
* intercepted by extensions, so it hands the whole expression to the engine.
|
|
99
|
+
*/
|
|
100
|
+
function methodFor(receiver, name) {
|
|
101
|
+
let method;
|
|
102
|
+
if (typeof receiver === 'string') {
|
|
103
|
+
method = STRING_METHODS.get(name);
|
|
104
|
+
}
|
|
105
|
+
else if (typeof receiver === 'number') {
|
|
106
|
+
method = NUMBER_METHODS.get(name);
|
|
107
|
+
}
|
|
108
|
+
else if (isArray(receiver)) {
|
|
109
|
+
method = ARRAY_METHODS.get(name);
|
|
110
|
+
}
|
|
111
|
+
if (method === undefined)
|
|
112
|
+
throw new EngineFallbackError();
|
|
113
|
+
return method;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Arguments are primitives, plus arrays for concat. An object argument would
|
|
117
|
+
* compare by live reference where the isolate compares copies (includes/
|
|
118
|
+
* indexOf) or coerce on the host where the isolate sees a copy.
|
|
119
|
+
*/
|
|
120
|
+
function isAllowedArgument(method, arg) {
|
|
121
|
+
if (isPrimitive(arg))
|
|
122
|
+
return true;
|
|
123
|
+
return method === 'concat' && isArray(arg);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The engine runs under a timeout; a synchronous native call cannot be
|
|
127
|
+
* interrupted, so the input size is the budget. A receiver above the result
|
|
128
|
+
* cap goes to the engine before any work is done, and the amplifying methods
|
|
129
|
+
* (which can allocate far beyond MAX_RESULT_LENGTH before bounded() sees the
|
|
130
|
+
* result) bail on an upper bound of their output.
|
|
131
|
+
*/
|
|
132
|
+
function assertPreflightSize(receiver, method, args) {
|
|
133
|
+
let upperBound = typeof receiver === 'number' ? 0 : receiver.length;
|
|
134
|
+
if (method === 'concat') {
|
|
135
|
+
for (const arg of args) {
|
|
136
|
+
upperBound += isArray(arg) ? arg.length : 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (method === 'flat' && isArray(receiver)) {
|
|
140
|
+
const depth = args.length === 0 ? 1 : toNum(args[0]);
|
|
141
|
+
upperBound = flatSize(receiver, depth);
|
|
142
|
+
}
|
|
143
|
+
else if ((method === 'replace' || method === 'replaceAll') && typeof receiver === 'string') {
|
|
144
|
+
// A missing replacement inserts the string "undefined".
|
|
145
|
+
const replacement = args.length < 2 ? 'undefined' : toStr(args[1]);
|
|
146
|
+
// Three replacement tokens expand: `$&`, `$\`` and `$'` insert match
|
|
147
|
+
// context, so the output is not bounded by the replacement's length.
|
|
148
|
+
// `$$` is an escaped literal `$`; strip those pairs first so that `$$&`
|
|
149
|
+
// (a literal "$&") stays native while `$$$&` (a literal "$" then `$&`)
|
|
150
|
+
// bails. With a string pattern every other `$` is literal.
|
|
151
|
+
if (/\$[&`']/.test(replacement.replaceAll('$$', '')))
|
|
152
|
+
throw new EngineFallbackError();
|
|
153
|
+
upperBound =
|
|
154
|
+
method === 'replace'
|
|
155
|
+
? receiver.length + replacement.length
|
|
156
|
+
: (receiver.length + 1) * (replacement.length + 1);
|
|
157
|
+
}
|
|
158
|
+
else if (method === 'join' && isArray(receiver)) {
|
|
159
|
+
// Only an undefined separator means ","; null joins with "null".
|
|
160
|
+
const separator = args[0] === undefined ? ',' : toStr(args[0]);
|
|
161
|
+
upperBound = separator.length * Math.max(receiver.length - 1, 0);
|
|
162
|
+
for (const element of receiver) {
|
|
163
|
+
upperBound += toStr(element ?? '').length;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (upperBound > MAX_RESULT_LENGTH) {
|
|
167
|
+
throw new EngineFallbackError();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Element count of `array.flat(depth)`, stopping early once past the cap
|
|
172
|
+
* (a nested structure can flatten to far more elements than the outer
|
|
173
|
+
* array holds).
|
|
174
|
+
*/
|
|
175
|
+
function flatSize(array, depth) {
|
|
176
|
+
let size = 0;
|
|
177
|
+
for (const element of array) {
|
|
178
|
+
size += depth >= 1 && isArray(element) ? flatSize(element, depth - 1) : 1;
|
|
179
|
+
if (size > MAX_RESULT_LENGTH)
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
return size;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Array methods that call toString on their elements: join() on every
|
|
186
|
+
* element, toSorted()'s default comparator on both operands per comparison.
|
|
187
|
+
* On nested arrays that work is proportional to the nested size, which no
|
|
188
|
+
* element count bounds, so these run natively over primitive elements only.
|
|
189
|
+
*/
|
|
190
|
+
const STRINGIFIES_ELEMENTS = new Set(['join', 'toSorted']);
|
|
191
|
+
/**
|
|
192
|
+
* Hands off to the engine unless every element is a primitive. O(n) over a
|
|
193
|
+
* receiver the size cap already limits, and runs before anything is
|
|
194
|
+
* stringified.
|
|
195
|
+
*/
|
|
196
|
+
function assertPrimitiveElements(receiver) {
|
|
197
|
+
// The receiver cap applies before the scan, so the scan never walks more
|
|
198
|
+
// than the cap either.
|
|
199
|
+
if (receiver.length > MAX_RESULT_LENGTH)
|
|
200
|
+
throw new EngineFallbackError();
|
|
201
|
+
for (const element of receiver) {
|
|
202
|
+
if (!isPrimitive(element))
|
|
203
|
+
throw new EngineFallbackError();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Content size of a JSON value: string lengths plus one per element and
|
|
208
|
+
* key, stopping early past the budget. Deeper than the grammar's own depth
|
|
209
|
+
* cap hands off: the engine owns data that deep.
|
|
210
|
+
*/
|
|
211
|
+
function contentWeight(value, budget, depth = 0) {
|
|
212
|
+
if (depth > MAX_DEPTH)
|
|
213
|
+
throw new EngineFallbackError();
|
|
214
|
+
if (typeof value === 'string')
|
|
215
|
+
return value.length;
|
|
216
|
+
if (!isObj(value))
|
|
217
|
+
return 1;
|
|
218
|
+
let weight = 1;
|
|
219
|
+
if (isArray(value)) {
|
|
220
|
+
for (const element of value) {
|
|
221
|
+
weight += contentWeight(element, budget - weight, depth + 1);
|
|
222
|
+
if (weight > budget)
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
return weight;
|
|
226
|
+
}
|
|
227
|
+
// Walk keys without materialising an entries array: an object with many
|
|
228
|
+
// keys would otherwise be copied before the budget is checked.
|
|
229
|
+
for (const key in value) {
|
|
230
|
+
if (!hasOwn(value, key))
|
|
231
|
+
continue;
|
|
232
|
+
weight += key.length + contentWeight(value[key], budget - weight, depth + 1);
|
|
233
|
+
if (weight > budget)
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
return weight;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* concat() is the one method that can hold more content than the payload
|
|
240
|
+
* delivered: N arguments that reference one large string become N copies
|
|
241
|
+
* when the result is cloned (copyResult) and N operands for every method
|
|
242
|
+
* downstream (join, toSorted, includes). Element count does not see that,
|
|
243
|
+
* so concat is bounded by the content size of receiver plus arguments.
|
|
244
|
+
*/
|
|
245
|
+
function assertConcatWeight(receiver, args) {
|
|
246
|
+
let weight = contentWeight(receiver, MAX_RESULT_LENGTH);
|
|
247
|
+
for (const arg of args) {
|
|
248
|
+
if (weight > MAX_RESULT_LENGTH)
|
|
249
|
+
break;
|
|
250
|
+
weight += contentWeight(arg, MAX_RESULT_LENGTH - weight);
|
|
251
|
+
}
|
|
252
|
+
if (weight > MAX_RESULT_LENGTH)
|
|
253
|
+
throw new EngineFallbackError();
|
|
254
|
+
}
|
|
255
|
+
function evalCall(node, data) {
|
|
256
|
+
const receiver = evalNode(node.receiver, data);
|
|
257
|
+
const receiverMissing = receiver === null || receiver === undefined;
|
|
258
|
+
if (node.optional && receiverMissing) {
|
|
259
|
+
throw chainShortCircuit;
|
|
260
|
+
}
|
|
261
|
+
if (receiverMissing) {
|
|
262
|
+
throw new TypeError(`Cannot read properties of ${toStr(receiver)} (reading '${node.method}')`);
|
|
263
|
+
}
|
|
264
|
+
// An own property shadowing the method (an engine-resolved $parameter value
|
|
265
|
+
// can carry one) would take precedence in the engines.
|
|
266
|
+
if (hasOwn(receiver, node.method)) {
|
|
267
|
+
throw new EngineFallbackError();
|
|
268
|
+
}
|
|
269
|
+
const method = methodFor(receiver, node.method);
|
|
270
|
+
const args = node.args.map((argument) => evalNode(argument, data));
|
|
271
|
+
if (!args.every((arg) => isAllowedArgument(node.method, arg))) {
|
|
272
|
+
throw new EngineFallbackError();
|
|
273
|
+
}
|
|
274
|
+
if (isArray(receiver)) {
|
|
275
|
+
if (STRINGIFIES_ELEMENTS.has(node.method))
|
|
276
|
+
assertPrimitiveElements(receiver);
|
|
277
|
+
if (node.method === 'concat')
|
|
278
|
+
assertConcatWeight(receiver, args);
|
|
279
|
+
}
|
|
280
|
+
assertPreflightSize(receiver, node.method, args);
|
|
281
|
+
return bounded(method.apply(receiver, args));
|
|
282
|
+
}
|
|
283
|
+
function evalChain(node, data) {
|
|
284
|
+
try {
|
|
285
|
+
return evalNode(node.expression, data);
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error === chainShortCircuit)
|
|
289
|
+
return undefined;
|
|
290
|
+
throw error;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function evalUnary(node, data) {
|
|
294
|
+
const argument = evalNode(node.argument, data);
|
|
295
|
+
if (node.op === '!') {
|
|
296
|
+
return !argument;
|
|
297
|
+
}
|
|
298
|
+
if (!isPrimitive(argument)) {
|
|
299
|
+
throw new EngineFallbackError();
|
|
300
|
+
}
|
|
301
|
+
return node.op === '-' ? -toNum(argument) : toNum(argument);
|
|
302
|
+
}
|
|
303
|
+
function evalBinary(node, data) {
|
|
304
|
+
const left = evalNode(node.left, data);
|
|
305
|
+
const right = evalNode(node.right, data);
|
|
306
|
+
if (!isPrimitive(left) || !isPrimitive(right)) {
|
|
307
|
+
throw new EngineFallbackError();
|
|
308
|
+
}
|
|
309
|
+
return binaryOps[node.op](left, right);
|
|
310
|
+
}
|
|
311
|
+
function evalLogical(node, data) {
|
|
312
|
+
const left = evalNode(node.left, data);
|
|
313
|
+
switch (node.op) {
|
|
314
|
+
case '&&':
|
|
315
|
+
return left ? evalNode(node.right, data) : left;
|
|
316
|
+
case '||':
|
|
317
|
+
return left ? left : evalNode(node.right, data);
|
|
318
|
+
case '??':
|
|
319
|
+
return left ?? evalNode(node.right, data);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function evalNode(node, data) {
|
|
323
|
+
switch (node.kind) {
|
|
324
|
+
case 'literal':
|
|
325
|
+
return node.value;
|
|
326
|
+
case 'root':
|
|
327
|
+
return node.name === '$json' ? data.$json : data.$parameter;
|
|
328
|
+
case 'undefined':
|
|
329
|
+
return undefined;
|
|
330
|
+
case 'member':
|
|
331
|
+
return evalMember(node, data);
|
|
332
|
+
case 'chain':
|
|
333
|
+
return evalChain(node, data);
|
|
334
|
+
case 'unary':
|
|
335
|
+
return evalUnary(node, data);
|
|
336
|
+
case 'binary':
|
|
337
|
+
return evalBinary(node, data);
|
|
338
|
+
case 'logical':
|
|
339
|
+
return evalLogical(node, data);
|
|
340
|
+
case 'conditional':
|
|
341
|
+
return evalNode(node.test, data)
|
|
342
|
+
? evalNode(node.consequent, data)
|
|
343
|
+
: evalNode(node.alternate, data);
|
|
344
|
+
case 'call':
|
|
345
|
+
return evalCall(node, data);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Tournament wraps each code chunk in try/catch and routes errors to the E()
|
|
350
|
+
* handler, which rethrows ExpressionErrors and swallows everything else (the
|
|
351
|
+
* chunk then yields undefined). Mirror that exactly.
|
|
352
|
+
*/
|
|
353
|
+
export function evalChunk(node, data) {
|
|
354
|
+
try {
|
|
355
|
+
return evalNode(node, data);
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
const rethrow = error instanceof EngineFallbackError ||
|
|
359
|
+
error instanceof ExpressionError ||
|
|
360
|
+
error instanceof ExpressionExtensionError;
|
|
361
|
+
if (rethrow)
|
|
362
|
+
throw error;
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../../../src/expressions/native-evaluation/evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAA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AC,CAAC;QACnC,KAAK,MAAM;YACV,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAgB,EAAE,IAA4B;IACvE,IAAI,CAAC;QACJ,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,OAAO,GACZ,KAAK,YAAY,mBAAmB;YACpC,KAAK,YAAY,eAAe;YAChC,KAAK,YAAY,wBAAwB,CAAC;QAE3C,IAAI,OAAO;YAAE,MAAM,KAAK,CAAC;QAEzB,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { namedTypes } from 'ast-types';
|
|
2
|
+
export declare const BINARY_OPS: readonly ['===', '!==', '==', '!=', '<', '<=', '>', '>=', '+', '-', '*', '/', '%'];
|
|
3
|
+
export declare const UNARY_OPS: readonly ['!', '-', '+'];
|
|
4
|
+
export type BinaryOp = (typeof BINARY_OPS)[number];
|
|
5
|
+
export type LogicalOp = namedTypes.LogicalExpression['operator'];
|
|
6
|
+
export type UnaryOp = (typeof UNARY_OPS)[number];
|
|
7
|
+
export type SimpleNode = {
|
|
8
|
+
kind: 'literal';
|
|
9
|
+
value: string | number | boolean | null;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'root';
|
|
12
|
+
name: '$json' | '$parameter';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'undefined';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'member';
|
|
17
|
+
object: SimpleNode;
|
|
18
|
+
key: string | number;
|
|
19
|
+
optional: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'chain';
|
|
22
|
+
expression: SimpleNode;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'unary';
|
|
25
|
+
op: UnaryOp;
|
|
26
|
+
argument: SimpleNode;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'binary';
|
|
29
|
+
op: BinaryOp;
|
|
30
|
+
left: SimpleNode;
|
|
31
|
+
right: SimpleNode;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'logical';
|
|
34
|
+
op: LogicalOp;
|
|
35
|
+
left: SimpleNode;
|
|
36
|
+
right: SimpleNode;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'conditional';
|
|
39
|
+
test: SimpleNode;
|
|
40
|
+
consequent: SimpleNode;
|
|
41
|
+
alternate: SimpleNode;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'call';
|
|
44
|
+
receiver: SimpleNode;
|
|
45
|
+
method: string;
|
|
46
|
+
args: SimpleNode[];
|
|
47
|
+
optional: boolean;
|
|
48
|
+
};
|
|
49
|
+
export declare const isArray: (arg: any) => arg is any[];
|
|
50
|
+
export declare const hasOwn: (o: object, v: PropertyKey) => boolean;
|
|
51
|
+
export declare const toStr: StringConstructor;
|
|
52
|
+
export declare const toNum: NumberConstructor;
|
|
53
|
+
export declare const clone: typeof structuredClone;
|
|
54
|
+
export type NativeMethod = (this: unknown, ...args: unknown[]) => unknown;
|
|
55
|
+
export declare const STRING_METHODS: ReadonlyMap<string, NativeMethod>;
|
|
56
|
+
export declare const NUMBER_METHODS: ReadonlyMap<string, NativeMethod>;
|
|
57
|
+
export declare const ARRAY_METHODS: ReadonlyMap<string, NativeMethod>;
|
|
58
|
+
export declare const CALLABLE_METHODS: Set<string>;
|
|
59
|
+
export declare const MAX_RESULT_LENGTH = 1000000;
|
|
60
|
+
export declare const MAX_DEPTH = 64;
|
|
61
|
+
export declare const isObj: (value: unknown) => value is Record<string, unknown>;
|
|
62
|
+
export declare const isOneOf: <T extends string>(ops: readonly T[], op: unknown) => op is T;
|
|
63
|
+
//# sourceMappingURL=grammar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../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G,EAAE,IAAI,CACf,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// The closed subset grammar, its operator and method allowlists, and the
|
|
2
|
+
// limits the parser and the evaluator share. See index.ts for the overview.
|
|
3
|
+
export const BINARY_OPS = [
|
|
4
|
+
'===',
|
|
5
|
+
'!==',
|
|
6
|
+
'==',
|
|
7
|
+
'!=',
|
|
8
|
+
'<',
|
|
9
|
+
'<=',
|
|
10
|
+
'>',
|
|
11
|
+
'>=',
|
|
12
|
+
'+',
|
|
13
|
+
'-',
|
|
14
|
+
'*',
|
|
15
|
+
'/',
|
|
16
|
+
'%',
|
|
17
|
+
];
|
|
18
|
+
export const UNARY_OPS = ['!', '-', '+'];
|
|
19
|
+
// Roots are `$json` and `$parameter` only (the literal comparisons in
|
|
20
|
+
// parseIdentifier). More roots are CAT-4697. `$now`/`$today` are excluded on
|
|
21
|
+
// purpose: they are Luxon DateTimes whose methods would make every useful
|
|
22
|
+
// expression on them a CallExpression anyway.
|
|
23
|
+
//
|
|
24
|
+
// Note on $parameter: the proxy resolves nested `=` parameter values by
|
|
25
|
+
// re-entering resolveSimpleParameterValue - a nested non-simple value simply
|
|
26
|
+
// takes the engine path there (under lazy acquisition, creating the bridge on
|
|
27
|
+
// demand).
|
|
28
|
+
// Intrinsics are captured at import so a later patch to a prototype or a
|
|
29
|
+
// global (a polyfill, a community package) does not change what the native
|
|
30
|
+
// path runs; the isolates never see such a patch either.
|
|
31
|
+
export const { isArray } = Array;
|
|
32
|
+
export const { hasOwn } = Object;
|
|
33
|
+
export const toStr = String;
|
|
34
|
+
export const toNum = Number;
|
|
35
|
+
export const clone = structuredClone;
|
|
36
|
+
const captureMethods = (proto, names) => {
|
|
37
|
+
const methods = new Map();
|
|
38
|
+
for (const name of names) {
|
|
39
|
+
const method = Reflect.get(proto, name);
|
|
40
|
+
if (typeof method === 'function')
|
|
41
|
+
methods.set(name, method);
|
|
42
|
+
}
|
|
43
|
+
return methods;
|
|
44
|
+
};
|
|
45
|
+
// Native prototype methods callable on a receiver of the matching type.
|
|
46
|
+
// Every name here must stay disjoint from the expression-extension method
|
|
47
|
+
// names (extendSyntax rewrites extension calls into `extend()` dispatch;
|
|
48
|
+
// natives pass through untouched) - pinned by a test in the parity corpus.
|
|
49
|
+
// The receiver's type is only known at runtime: a receiver whose type has no
|
|
50
|
+
// allowlist entry for the method makes the evaluation bail to the engine
|
|
51
|
+
// (EngineFallbackError below). Callback-taking forms (regex/function args,
|
|
52
|
+
// array callbacks) are unrepresentable: those argument nodes decline parsing.
|
|
53
|
+
// Accepting callbacks is CAT-4698.
|
|
54
|
+
export const STRING_METHODS = captureMethods(String.prototype, [
|
|
55
|
+
'toUpperCase',
|
|
56
|
+
'toLowerCase',
|
|
57
|
+
'trim',
|
|
58
|
+
'trimStart',
|
|
59
|
+
'trimEnd',
|
|
60
|
+
'includes',
|
|
61
|
+
'startsWith',
|
|
62
|
+
'endsWith',
|
|
63
|
+
'slice',
|
|
64
|
+
'indexOf',
|
|
65
|
+
'charAt',
|
|
66
|
+
'replace',
|
|
67
|
+
'replaceAll',
|
|
68
|
+
]);
|
|
69
|
+
export const NUMBER_METHODS = captureMethods(Number.prototype, [
|
|
70
|
+
'toFixed',
|
|
71
|
+
'toPrecision',
|
|
72
|
+
'toString',
|
|
73
|
+
]);
|
|
74
|
+
// Non-mutating methods only: the receiver is the live workflow data (the vm
|
|
75
|
+
// engine evaluates a copy inside the isolate), so an in-place mutator like
|
|
76
|
+
// sort()/reverse()/fill() would corrupt execution data as a side effect. Use
|
|
77
|
+
// the toSorted()/toReversed() immutable variants instead. Iterator-returning
|
|
78
|
+
// methods (entries/values/keys) are also excluded: a live iterator has no
|
|
79
|
+
// equivalent representation across the engine boundary.
|
|
80
|
+
export const ARRAY_METHODS = captureMethods(Array.prototype, [
|
|
81
|
+
'includes',
|
|
82
|
+
'indexOf',
|
|
83
|
+
'lastIndexOf',
|
|
84
|
+
'join',
|
|
85
|
+
'slice',
|
|
86
|
+
'at',
|
|
87
|
+
'concat',
|
|
88
|
+
'flat',
|
|
89
|
+
'toSorted',
|
|
90
|
+
'toReversed',
|
|
91
|
+
]);
|
|
92
|
+
export const CALLABLE_METHODS = new Set([
|
|
93
|
+
...STRING_METHODS.keys(),
|
|
94
|
+
...NUMBER_METHODS.keys(),
|
|
95
|
+
...ARRAY_METHODS.keys(),
|
|
96
|
+
]);
|
|
97
|
+
// The engine evaluates under a timeout and a memory limit; this interpreter
|
|
98
|
+
// has neither. A string or array result above this length is handed to the
|
|
99
|
+
// engine so those limits apply (nested replaceAll('', ...) or concat chains
|
|
100
|
+
// can otherwise expand without bound on the main thread).
|
|
101
|
+
export const MAX_RESULT_LENGTH = 1_000_000;
|
|
102
|
+
// Nesting depth of the subset grammar. Parsing and evaluation both recurse
|
|
103
|
+
// once per level, so this keeps a pathological expression off the host stack;
|
|
104
|
+
// real expressions are a handful of levels deep.
|
|
105
|
+
export const MAX_DEPTH = 64;
|
|
106
|
+
export const isObj = (value) => typeof value === 'object' && value !== null;
|
|
107
|
+
export const isOneOf = (ops, op) => typeof op === 'string' && ops.includes(op);
|
|
108
|
+
//# sourceMappingURL=grammar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../../../../src/expressions/native-evaluation/grammar.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,4EAA4E;AAE5E,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,IAAI;IACJ,GAAG;IACH,IAAI;IACJ,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;CACM,CAAC;AACX,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAqBlD,sEAAsE;AACtE,6EAA6E;AAC7E,0EAA0E;AAC1E,8CAA8C;AAC9C,EAAE;AACF,wEAAwE;AACxE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CAAC;AAEH,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,0EAA0E;AAC1E,wDAAwD;AACxD,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE;IAC5D,UAAU;IACV,SAAS;IACT,aAAa;IACb,MAAM;IACN,OAAO;IACP,IAAI;IACJ,QAAQ;IACR,MAAM;IACN,UAAU;IACV,YAAY;CACZ,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IACvC,GAAG,cAAc,CAAC,IAAI,EAAE;IACxB,GAAG,cAAc,CAAC,IAAI,EAAE;IACxB,GAAG,aAAa,CAAC,IAAI,EAAE;CACvB,CAAC,CAAC;AAEH,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C,2EAA2E;AAC3E,8EAA8E;AAC9E,iDAAiD;AACjD,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAc,EAAoC,EAAE,CACzE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AAE7C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAmB,GAAiB,EAAE,EAAW,EAAW,EAAE,CACpF,OAAO,EAAE,KAAK,QAAQ,IAAK,GAAyB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IWorkflowDataProxyData } from '../../interfaces';
|
|
2
|
+
export { CALLABLE_METHODS, MAX_RESULT_LENGTH } from './grammar';
|
|
3
|
+
/** Does the expression (leading `=` stripped) fit the native subset? */
|
|
4
|
+
export declare function isNativelyEvaluable(expression: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Evaluate an expression (with the leading `=` already stripped) in-process.
|
|
7
|
+
* Returns `{ handled: false }` when the expression is outside the subset or a
|
|
8
|
+
* runtime value fell outside what parsing proved; the caller must then run
|
|
9
|
+
* the regular pipeline.
|
|
10
|
+
*/
|
|
11
|
+
export declare function evaluateNatively(expression: string, data: IWorkflowDataProxyData): {
|
|
12
|
+
handled: true;
|
|
13
|
+
value: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
handled: false;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/expressions/native-evaluation/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAyGhE,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,sBAAsB,GAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAA;CAAE,CAYxD"}
|