@uipath/solution-tool 1.200.0-preview.109 → 1.201.0-preview.115
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/{browser-strategy-brs3w53e.js → browser-strategy-yccf8mtd.js} +1 -1
- package/dist/deploy.js +5 -5
- package/dist/index-2fj08e7n.js +2058 -0
- package/dist/index-w03qc9m8.js +634 -0
- package/dist/index.js +11 -11
- package/dist/init.js +5 -5
- package/dist/js-yaml-4ypbq2tt.js +3145 -0
- package/dist/node-strategy-12qfy0nv.js +348 -0
- package/dist/pack.js +8 -20
- package/dist/{packager-tool-1ps2qeqg.js → packager-tool-5arsyj36.js} +3 -2
- package/dist/packager-tool-7eva0peq.js +265 -0
- package/dist/{packager-tool-kfzzznjr.js → packager-tool-85x8cje1.js} +2 -2
- package/dist/{packager-tool-sdhdmkt8.js → packager-tool-9vehmnke.js} +2 -1
- package/dist/{packager-tool-gnmkvkz3.js → packager-tool-9x8dbxbn.js} +675 -29
- package/dist/{packager-tool-gkwmyc48.js → packager-tool-arbagkf2.js} +28 -13
- package/dist/{packager-tool-rdxaysxe.js → packager-tool-c84z58bt.js} +65 -8
- package/dist/{packager-tool-br2aa2fh.js → packager-tool-n49qbf8m.js} +10 -18
- package/dist/{packager-tool-37g19zk3.js → packager-tool-ngh4qwjv.js} +4 -4
- package/dist/{packager-tool-y4wacqkp.js → packager-tool-r9n45rjm.js} +1059 -6017
- package/dist/{packager-tool-7efxm815.js → packager-tool-y35nbbkm.js} +6243 -5846
- package/dist/packager-tool.js +1 -1
- package/dist/publish.js +5 -5
- package/dist/resource.js +4 -4
- package/dist/services/feed-resolver.d.ts +4 -5
- package/dist/templates/AGENTS.md +2 -1
- package/dist/tool.js +11 -11
- package/package.json +2 -2
- package/dist/node-strategy-a4n0d6dx.js +0 -63
- package/dist/packager-tool-q90kqh83.js +0 -1161
|
@@ -0,0 +1,2058 @@
|
|
|
1
|
+
import"./packager-tool-0v6na3yp.js";
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/@jmespath-community/jmespath/dist/index.mjs
|
|
4
|
+
var isObject = (obj) => {
|
|
5
|
+
return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
|
|
6
|
+
};
|
|
7
|
+
var strictDeepEqual = (first, second) => {
|
|
8
|
+
if (first === second) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (typeof first !== typeof second) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(first) && Array.isArray(second)) {
|
|
15
|
+
if (first.length !== second.length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0;i < first.length; i += 1) {
|
|
19
|
+
if (!strictDeepEqual(first[i], second[i])) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (isObject(first) && isObject(second)) {
|
|
26
|
+
const firstEntries = Object.entries(first);
|
|
27
|
+
const secondKeys = new Set(Object.keys(second));
|
|
28
|
+
if (firstEntries.length !== secondKeys.size) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
for (const [key, value] of firstEntries) {
|
|
32
|
+
if (!strictDeepEqual(value, second[key])) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
secondKeys.delete(key);
|
|
36
|
+
}
|
|
37
|
+
return secondKeys.size === 0;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
var isFalse = (obj) => {
|
|
42
|
+
if (obj === null || obj === undefined || obj === false) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (typeof obj === "string") {
|
|
46
|
+
return obj === "";
|
|
47
|
+
}
|
|
48
|
+
if (typeof obj === "object") {
|
|
49
|
+
if (Array.isArray(obj)) {
|
|
50
|
+
return obj.length === 0;
|
|
51
|
+
}
|
|
52
|
+
if (obj === null) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return Object.keys(obj).length === 0;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
var isAlpha = (ch) => {
|
|
60
|
+
return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_";
|
|
61
|
+
};
|
|
62
|
+
var isNum = (ch) => {
|
|
63
|
+
return ch >= "0" && ch <= "9" || ch === "-";
|
|
64
|
+
};
|
|
65
|
+
var isAlphaNum = (ch) => {
|
|
66
|
+
return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_";
|
|
67
|
+
};
|
|
68
|
+
var ensureInteger = (value) => {
|
|
69
|
+
if (!(typeof value === "number") || Math.floor(value) !== value) {
|
|
70
|
+
throw new Error("invalid-value: expecting an integer.");
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
74
|
+
var ensurePositiveInteger = (value) => {
|
|
75
|
+
if (!(typeof value === "number") || value < 0 || Math.floor(value) !== value) {
|
|
76
|
+
throw new Error("invalid-value: expecting a non-negative integer.");
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
};
|
|
80
|
+
var ensureNumbers = (...operands) => {
|
|
81
|
+
for (let i = 0;i < operands.length; i++) {
|
|
82
|
+
if (operands[i] === null || operands[i] === undefined) {
|
|
83
|
+
throw new Error("not-a-number: undefined");
|
|
84
|
+
}
|
|
85
|
+
if (typeof operands[i] !== "number") {
|
|
86
|
+
throw new Error("not-a-number");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var notZero = (n) => {
|
|
91
|
+
n = +n;
|
|
92
|
+
if (!n) {
|
|
93
|
+
throw new Error("not-a-number: divide by zero");
|
|
94
|
+
}
|
|
95
|
+
return n;
|
|
96
|
+
};
|
|
97
|
+
var add = (left, right) => {
|
|
98
|
+
ensureNumbers(left, right);
|
|
99
|
+
const result = left + right;
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
var sub = (left, right) => {
|
|
103
|
+
ensureNumbers(left, right);
|
|
104
|
+
const result = left - right;
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
var mul = (left, right) => {
|
|
108
|
+
ensureNumbers(left, right);
|
|
109
|
+
const result = left * right;
|
|
110
|
+
return result;
|
|
111
|
+
};
|
|
112
|
+
var divide = (left, right) => {
|
|
113
|
+
ensureNumbers(left, right);
|
|
114
|
+
const result = left / notZero(right);
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
var div = (left, right) => {
|
|
118
|
+
ensureNumbers(left, right);
|
|
119
|
+
const result = Math.floor(left / notZero(right));
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
var mod = (left, right) => {
|
|
123
|
+
ensureNumbers(left, right);
|
|
124
|
+
const result = left % right;
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
var findFirst = (subject, sub2, start, end) => {
|
|
128
|
+
if (!subject || !sub2) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
start = Math.max(ensureInteger(start = start || 0), 0);
|
|
132
|
+
end = Math.min(ensureInteger(end = end || subject.length), subject.length);
|
|
133
|
+
const offset = subject.slice(start, end).indexOf(sub2);
|
|
134
|
+
return offset === -1 ? null : offset + start;
|
|
135
|
+
};
|
|
136
|
+
var findLast = (subject, sub2, start, end) => {
|
|
137
|
+
if (!subject || !sub2) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
start = Math.max(ensureInteger(start = start || 0), 0);
|
|
141
|
+
end = Math.min(ensureInteger(end = end || subject.length), subject.length);
|
|
142
|
+
const offset = subject.slice(start, end).lastIndexOf(sub2);
|
|
143
|
+
const result = offset === -1 ? null : offset + start;
|
|
144
|
+
return result;
|
|
145
|
+
};
|
|
146
|
+
var lower = (subject) => subject.toLowerCase();
|
|
147
|
+
var ensurePadFuncParams = (name, width, padding) => {
|
|
148
|
+
padding = padding || " ";
|
|
149
|
+
if (padding.length > 1) {
|
|
150
|
+
throw new Error(`invalid value, ${name} expects its 'pad' parameter to be a valid string with a single codepoint`);
|
|
151
|
+
}
|
|
152
|
+
ensurePositiveInteger(width);
|
|
153
|
+
return padding;
|
|
154
|
+
};
|
|
155
|
+
var padLeft = (subject, width, padding) => {
|
|
156
|
+
padding = ensurePadFuncParams("pad_left", width, padding);
|
|
157
|
+
return subject && subject.padStart(width, padding) || "";
|
|
158
|
+
};
|
|
159
|
+
var padRight = (subject, width, padding) => {
|
|
160
|
+
padding = ensurePadFuncParams("pad_right", width, padding);
|
|
161
|
+
return subject && subject.padEnd(width, padding) || "";
|
|
162
|
+
};
|
|
163
|
+
var replace = (subject, string, by, count) => {
|
|
164
|
+
if (count === 0) {
|
|
165
|
+
return subject;
|
|
166
|
+
}
|
|
167
|
+
if (!count) {
|
|
168
|
+
return subject.split(string).join(by);
|
|
169
|
+
}
|
|
170
|
+
ensurePositiveInteger(count);
|
|
171
|
+
[...Array(count).keys()].map(() => subject = subject.replace(string, by));
|
|
172
|
+
return subject;
|
|
173
|
+
};
|
|
174
|
+
var split = (subject, search2, count) => {
|
|
175
|
+
if (subject.length == 0 && search2.length === 0) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
if (count === null || count === undefined) {
|
|
179
|
+
return subject.split(search2);
|
|
180
|
+
}
|
|
181
|
+
ensurePositiveInteger(count);
|
|
182
|
+
if (count === 0) {
|
|
183
|
+
return [subject];
|
|
184
|
+
}
|
|
185
|
+
const split2 = subject.split(search2);
|
|
186
|
+
return [...split2.slice(0, count), split2.slice(count).join(search2)];
|
|
187
|
+
};
|
|
188
|
+
var trim = (subject, chars) => {
|
|
189
|
+
return trimLeft(trimRight(subject, chars), chars);
|
|
190
|
+
};
|
|
191
|
+
var trimLeft = (subject, chars) => {
|
|
192
|
+
return trimImpl(subject, (list) => new RegExp(`^[${list}]*(.*?)`), chars);
|
|
193
|
+
};
|
|
194
|
+
var trimRight = (subject, chars) => {
|
|
195
|
+
return trimImpl(subject, (list) => new RegExp(`(.*?)[${list}]*$`), chars);
|
|
196
|
+
};
|
|
197
|
+
var trimImpl = (subject, regExper, chars) => {
|
|
198
|
+
const pattern = chars ? chars.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&") : "\\s
";
|
|
199
|
+
return subject.replace(regExper(pattern), "$1");
|
|
200
|
+
};
|
|
201
|
+
var upper = (subject) => subject.toUpperCase();
|
|
202
|
+
var basicTokens = {
|
|
203
|
+
"(": "Lparen",
|
|
204
|
+
")": "Rparen",
|
|
205
|
+
"*": "Star",
|
|
206
|
+
",": "Comma",
|
|
207
|
+
".": "Dot",
|
|
208
|
+
":": "Colon",
|
|
209
|
+
"@": "Current",
|
|
210
|
+
"]": "Rbracket",
|
|
211
|
+
"{": "Lbrace",
|
|
212
|
+
"}": "Rbrace",
|
|
213
|
+
"+": "Plus",
|
|
214
|
+
"%": "Modulo",
|
|
215
|
+
"?": "Question",
|
|
216
|
+
"−": "Minus",
|
|
217
|
+
"×": "Multiply",
|
|
218
|
+
"÷": "Divide"
|
|
219
|
+
};
|
|
220
|
+
var operatorStartToken = {
|
|
221
|
+
"!": true,
|
|
222
|
+
"<": true,
|
|
223
|
+
"=": true,
|
|
224
|
+
">": true,
|
|
225
|
+
"&": true,
|
|
226
|
+
"|": true,
|
|
227
|
+
"/": true
|
|
228
|
+
};
|
|
229
|
+
var skipChars = {
|
|
230
|
+
"\t": true,
|
|
231
|
+
"\n": true,
|
|
232
|
+
"\r": true,
|
|
233
|
+
" ": true
|
|
234
|
+
};
|
|
235
|
+
var StreamLexer = class {
|
|
236
|
+
_current = 0;
|
|
237
|
+
_enable_legacy_literals = false;
|
|
238
|
+
tokenize(stream, options) {
|
|
239
|
+
const tokens = [];
|
|
240
|
+
this._current = 0;
|
|
241
|
+
this._enable_legacy_literals = options?.enable_legacy_literals || false;
|
|
242
|
+
let start;
|
|
243
|
+
let identifier;
|
|
244
|
+
let token;
|
|
245
|
+
while (this._current < stream.length) {
|
|
246
|
+
if (isAlpha(stream[this._current])) {
|
|
247
|
+
start = this._current;
|
|
248
|
+
identifier = this.consumeUnquotedIdentifier(stream);
|
|
249
|
+
tokens.push({
|
|
250
|
+
start,
|
|
251
|
+
type: "UnquotedIdentifier",
|
|
252
|
+
value: identifier
|
|
253
|
+
});
|
|
254
|
+
} else if (basicTokens[stream[this._current]] !== undefined) {
|
|
255
|
+
tokens.push({
|
|
256
|
+
start: this._current,
|
|
257
|
+
type: basicTokens[stream[this._current]],
|
|
258
|
+
value: stream[this._current]
|
|
259
|
+
});
|
|
260
|
+
this._current += 1;
|
|
261
|
+
} else if (stream[this._current] === "$") {
|
|
262
|
+
start = this._current;
|
|
263
|
+
if (this._current + 1 < stream.length && isAlpha(stream[this._current + 1])) {
|
|
264
|
+
this._current += 1;
|
|
265
|
+
identifier = this.consumeUnquotedIdentifier(stream);
|
|
266
|
+
tokens.push({
|
|
267
|
+
start,
|
|
268
|
+
type: "Variable",
|
|
269
|
+
value: identifier
|
|
270
|
+
});
|
|
271
|
+
} else {
|
|
272
|
+
tokens.push({
|
|
273
|
+
start,
|
|
274
|
+
type: "Root",
|
|
275
|
+
value: stream[this._current]
|
|
276
|
+
});
|
|
277
|
+
this._current += 1;
|
|
278
|
+
}
|
|
279
|
+
} else if (stream[this._current] === "-") {
|
|
280
|
+
if (this._current + 1 < stream.length && isNum(stream[this._current + 1])) {
|
|
281
|
+
const token2 = this.consumeNumber(stream);
|
|
282
|
+
token2 && tokens.push(token2);
|
|
283
|
+
} else {
|
|
284
|
+
const token2 = {
|
|
285
|
+
start: this._current,
|
|
286
|
+
type: "Minus",
|
|
287
|
+
value: "-"
|
|
288
|
+
};
|
|
289
|
+
tokens.push(token2);
|
|
290
|
+
this._current += 1;
|
|
291
|
+
}
|
|
292
|
+
} else if (isNum(stream[this._current])) {
|
|
293
|
+
token = this.consumeNumber(stream);
|
|
294
|
+
tokens.push(token);
|
|
295
|
+
} else if (stream[this._current] === "[") {
|
|
296
|
+
token = this.consumeLBracket(stream);
|
|
297
|
+
tokens.push(token);
|
|
298
|
+
} else if (stream[this._current] === '"') {
|
|
299
|
+
start = this._current;
|
|
300
|
+
identifier = this.consumeQuotedIdentifier(stream);
|
|
301
|
+
tokens.push({
|
|
302
|
+
start,
|
|
303
|
+
type: "QuotedIdentifier",
|
|
304
|
+
value: identifier
|
|
305
|
+
});
|
|
306
|
+
} else if (stream[this._current] === `'`) {
|
|
307
|
+
start = this._current;
|
|
308
|
+
identifier = this.consumeRawStringLiteral(stream);
|
|
309
|
+
tokens.push({
|
|
310
|
+
start,
|
|
311
|
+
type: "Literal",
|
|
312
|
+
value: identifier
|
|
313
|
+
});
|
|
314
|
+
} else if (stream[this._current] === "`") {
|
|
315
|
+
start = this._current;
|
|
316
|
+
const literal = this.consumeLiteral(stream);
|
|
317
|
+
tokens.push({
|
|
318
|
+
start,
|
|
319
|
+
type: "Literal",
|
|
320
|
+
value: literal
|
|
321
|
+
});
|
|
322
|
+
} else if (operatorStartToken[stream[this._current]] !== undefined) {
|
|
323
|
+
token = this.consumeOperator(stream);
|
|
324
|
+
token && tokens.push(token);
|
|
325
|
+
} else if (skipChars[stream[this._current]] !== undefined) {
|
|
326
|
+
this._current += 1;
|
|
327
|
+
} else {
|
|
328
|
+
const error = new Error(`Syntax error: unknown character: ${stream[this._current]}`);
|
|
329
|
+
error.name = "LexerError";
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return tokens;
|
|
334
|
+
}
|
|
335
|
+
consumeUnquotedIdentifier(stream) {
|
|
336
|
+
const start = this._current;
|
|
337
|
+
this._current += 1;
|
|
338
|
+
while (this._current < stream.length && isAlphaNum(stream[this._current])) {
|
|
339
|
+
this._current += 1;
|
|
340
|
+
}
|
|
341
|
+
return stream.slice(start, this._current);
|
|
342
|
+
}
|
|
343
|
+
consumeQuotedIdentifier(stream) {
|
|
344
|
+
const start = this._current;
|
|
345
|
+
this._current += 1;
|
|
346
|
+
const maxLength = stream.length;
|
|
347
|
+
while (stream[this._current] !== '"' && this._current < maxLength) {
|
|
348
|
+
let current = this._current;
|
|
349
|
+
if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === '"')) {
|
|
350
|
+
current += 2;
|
|
351
|
+
} else {
|
|
352
|
+
current += 1;
|
|
353
|
+
}
|
|
354
|
+
this._current = current;
|
|
355
|
+
}
|
|
356
|
+
this._current += 1;
|
|
357
|
+
const [value, ok] = this.parseJSON(stream.slice(start, this._current));
|
|
358
|
+
if (!ok) {
|
|
359
|
+
const error = new Error(`syntax: unexpected end of JSON input`);
|
|
360
|
+
error.name = "LexerError";
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
consumeRawStringLiteral(stream) {
|
|
366
|
+
const start = this._current;
|
|
367
|
+
this._current += 1;
|
|
368
|
+
const maxLength = stream.length;
|
|
369
|
+
while (stream[this._current] !== `'` && this._current < maxLength) {
|
|
370
|
+
let current = this._current;
|
|
371
|
+
if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === `'`)) {
|
|
372
|
+
current += 2;
|
|
373
|
+
} else {
|
|
374
|
+
current += 1;
|
|
375
|
+
}
|
|
376
|
+
this._current = current;
|
|
377
|
+
}
|
|
378
|
+
this._current += 1;
|
|
379
|
+
const literal = stream.slice(start + 1, this._current - 1);
|
|
380
|
+
return replace(replace(literal, `\\\\`, `\\`), `\\'`, `'`);
|
|
381
|
+
}
|
|
382
|
+
consumeNumber(stream) {
|
|
383
|
+
const start = this._current;
|
|
384
|
+
this._current += 1;
|
|
385
|
+
const maxLength = stream.length;
|
|
386
|
+
while (isNum(stream[this._current]) && this._current < maxLength) {
|
|
387
|
+
this._current += 1;
|
|
388
|
+
}
|
|
389
|
+
const value = parseInt(stream.slice(start, this._current), 10);
|
|
390
|
+
return { start, value, type: "Number" };
|
|
391
|
+
}
|
|
392
|
+
consumeLBracket(stream) {
|
|
393
|
+
const start = this._current;
|
|
394
|
+
this._current += 1;
|
|
395
|
+
if (stream[this._current] === "?") {
|
|
396
|
+
this._current += 1;
|
|
397
|
+
return { start, type: "Filter", value: "[?" };
|
|
398
|
+
}
|
|
399
|
+
if (stream[this._current] === "]") {
|
|
400
|
+
this._current += 1;
|
|
401
|
+
return { start, type: "Flatten", value: "[]" };
|
|
402
|
+
}
|
|
403
|
+
return { start, type: "Lbracket", value: "[" };
|
|
404
|
+
}
|
|
405
|
+
consumeOrElse(stream, peek, token, orElse) {
|
|
406
|
+
const start = this._current;
|
|
407
|
+
this._current += 1;
|
|
408
|
+
if (this._current < stream.length && stream[this._current] === peek) {
|
|
409
|
+
this._current += 1;
|
|
410
|
+
return {
|
|
411
|
+
start,
|
|
412
|
+
type: orElse,
|
|
413
|
+
value: stream.slice(start, this._current)
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return { start, type: token, value: stream[start] };
|
|
417
|
+
}
|
|
418
|
+
consumeOperator(stream) {
|
|
419
|
+
const start = this._current;
|
|
420
|
+
const startingChar = stream[start];
|
|
421
|
+
switch (startingChar) {
|
|
422
|
+
case "!":
|
|
423
|
+
return this.consumeOrElse(stream, "=", "Not", "NE");
|
|
424
|
+
case "<":
|
|
425
|
+
return this.consumeOrElse(stream, "=", "LT", "LTE");
|
|
426
|
+
case ">":
|
|
427
|
+
return this.consumeOrElse(stream, "=", "GT", "GTE");
|
|
428
|
+
case "=":
|
|
429
|
+
return this.consumeOrElse(stream, "=", "Assign", "EQ");
|
|
430
|
+
case "&":
|
|
431
|
+
return this.consumeOrElse(stream, "&", "Expref", "And");
|
|
432
|
+
case "|":
|
|
433
|
+
return this.consumeOrElse(stream, "|", "Pipe", "Or");
|
|
434
|
+
case "/":
|
|
435
|
+
return this.consumeOrElse(stream, "/", "Divide", "Div");
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
consumeLiteral(stream) {
|
|
439
|
+
this._current += 1;
|
|
440
|
+
const start = this._current;
|
|
441
|
+
const maxLength = stream.length;
|
|
442
|
+
while (stream[this._current] !== "`" && this._current < maxLength) {
|
|
443
|
+
let current = this._current;
|
|
444
|
+
if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "`")) {
|
|
445
|
+
current += 2;
|
|
446
|
+
} else {
|
|
447
|
+
current += 1;
|
|
448
|
+
}
|
|
449
|
+
this._current = current;
|
|
450
|
+
}
|
|
451
|
+
let literalString = stream.slice(start, this._current).trimStart();
|
|
452
|
+
literalString = literalString.replace("\\`", "`");
|
|
453
|
+
let literal = null;
|
|
454
|
+
let ok = false;
|
|
455
|
+
if (this.looksLikeJSON(literalString)) {
|
|
456
|
+
[literal, ok] = this.parseJSON(literalString);
|
|
457
|
+
}
|
|
458
|
+
if (!ok && this._enable_legacy_literals) {
|
|
459
|
+
[literal, ok] = this.parseJSON(`"${literalString}"`);
|
|
460
|
+
}
|
|
461
|
+
if (!ok) {
|
|
462
|
+
const error = new Error(`Syntax error: unexpected end of JSON input or invalid format for a JSON literal: ${stream[this._current]}`);
|
|
463
|
+
error.name = "LexerError";
|
|
464
|
+
throw error;
|
|
465
|
+
}
|
|
466
|
+
this._current += 1;
|
|
467
|
+
return literal;
|
|
468
|
+
}
|
|
469
|
+
looksLikeJSON(literalString) {
|
|
470
|
+
const startingChars = '[{"';
|
|
471
|
+
const jsonLiterals = ["true", "false", "null"];
|
|
472
|
+
const numberLooking = "-0123456789";
|
|
473
|
+
if (literalString === "") {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
if (startingChars.includes(literalString[0])) {
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
if (jsonLiterals.includes(literalString)) {
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
if (numberLooking.includes(literalString[0])) {
|
|
483
|
+
const [_, ok] = this.parseJSON(literalString);
|
|
484
|
+
return ok;
|
|
485
|
+
}
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
parseJSON(text) {
|
|
489
|
+
try {
|
|
490
|
+
const json = JSON.parse(text);
|
|
491
|
+
return [json, true];
|
|
492
|
+
} catch {
|
|
493
|
+
return [null, false];
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
var Lexer = new StreamLexer;
|
|
498
|
+
var Lexer_default = Lexer;
|
|
499
|
+
var bindingPower = {
|
|
500
|
+
["EOF"]: 0,
|
|
501
|
+
["Variable"]: 0,
|
|
502
|
+
["UnquotedIdentifier"]: 0,
|
|
503
|
+
["QuotedIdentifier"]: 0,
|
|
504
|
+
["Rbracket"]: 0,
|
|
505
|
+
["Rparen"]: 0,
|
|
506
|
+
["Comma"]: 0,
|
|
507
|
+
["Rbrace"]: 0,
|
|
508
|
+
["Number"]: 0,
|
|
509
|
+
["Current"]: 0,
|
|
510
|
+
["Expref"]: 0,
|
|
511
|
+
["Root"]: 0,
|
|
512
|
+
["Assign"]: 1,
|
|
513
|
+
["Pipe"]: 1,
|
|
514
|
+
["Question"]: 2,
|
|
515
|
+
["Or"]: 3,
|
|
516
|
+
["And"]: 4,
|
|
517
|
+
["EQ"]: 5,
|
|
518
|
+
["GT"]: 5,
|
|
519
|
+
["LT"]: 5,
|
|
520
|
+
["GTE"]: 5,
|
|
521
|
+
["LTE"]: 5,
|
|
522
|
+
["NE"]: 5,
|
|
523
|
+
["Minus"]: 6,
|
|
524
|
+
["Plus"]: 6,
|
|
525
|
+
["Div"]: 7,
|
|
526
|
+
["Divide"]: 7,
|
|
527
|
+
["Modulo"]: 7,
|
|
528
|
+
["Multiply"]: 7,
|
|
529
|
+
["Flatten"]: 9,
|
|
530
|
+
["Star"]: 20,
|
|
531
|
+
["Filter"]: 21,
|
|
532
|
+
["Dot"]: 40,
|
|
533
|
+
["Not"]: 45,
|
|
534
|
+
["Lbrace"]: 50,
|
|
535
|
+
["Lbracket"]: 55,
|
|
536
|
+
["Lparen"]: 60
|
|
537
|
+
};
|
|
538
|
+
var TokenParser = class _TokenParser {
|
|
539
|
+
index = 0;
|
|
540
|
+
tokens = [];
|
|
541
|
+
parse(expression, options) {
|
|
542
|
+
this.loadTokens(expression, options || { enable_legacy_literals: false });
|
|
543
|
+
this.index = 0;
|
|
544
|
+
const ast = this.expression(0);
|
|
545
|
+
if (this.lookahead(0) !== "EOF") {
|
|
546
|
+
const token = this.lookaheadToken(0);
|
|
547
|
+
this.errorToken(token, `Syntax error: unexpected token type: ${token.type}, value: ${token.value}`);
|
|
548
|
+
}
|
|
549
|
+
return ast;
|
|
550
|
+
}
|
|
551
|
+
loadTokens(expression, options) {
|
|
552
|
+
this.tokens = Lexer_default.tokenize(expression, options);
|
|
553
|
+
this.tokens.push({ type: "EOF", value: "", start: expression.length });
|
|
554
|
+
}
|
|
555
|
+
expression(rbp) {
|
|
556
|
+
const leftToken = this.lookaheadToken(0);
|
|
557
|
+
this.advance();
|
|
558
|
+
let left = this.nud(leftToken);
|
|
559
|
+
let currentTokenType = this.lookahead(0);
|
|
560
|
+
while (rbp < bindingPower[currentTokenType]) {
|
|
561
|
+
this.advance();
|
|
562
|
+
left = this.led(currentTokenType, left);
|
|
563
|
+
currentTokenType = this.lookahead(0);
|
|
564
|
+
}
|
|
565
|
+
return left;
|
|
566
|
+
}
|
|
567
|
+
lookahead(offset) {
|
|
568
|
+
return this.tokens[this.index + offset].type;
|
|
569
|
+
}
|
|
570
|
+
lookaheadToken(offset) {
|
|
571
|
+
return this.tokens[this.index + offset];
|
|
572
|
+
}
|
|
573
|
+
advance() {
|
|
574
|
+
this.index += 1;
|
|
575
|
+
}
|
|
576
|
+
nud(token) {
|
|
577
|
+
switch (token.type) {
|
|
578
|
+
case "Variable":
|
|
579
|
+
return { type: "Variable", name: token.value };
|
|
580
|
+
case "Literal":
|
|
581
|
+
return { type: "Literal", value: token.value };
|
|
582
|
+
case "UnquotedIdentifier": {
|
|
583
|
+
if (_TokenParser.isKeyword(token, "let") && this.lookahead(0) === "Variable") {
|
|
584
|
+
return this.parseLetExpression();
|
|
585
|
+
} else {
|
|
586
|
+
return { type: "Field", name: token.value };
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
case "QuotedIdentifier":
|
|
590
|
+
if (this.lookahead(0) === "Lparen") {
|
|
591
|
+
throw new Error("Syntax error: quoted identifier not allowed for function names.");
|
|
592
|
+
} else {
|
|
593
|
+
return { type: "Field", name: token.value };
|
|
594
|
+
}
|
|
595
|
+
case "Not": {
|
|
596
|
+
const child = this.expression(bindingPower.Not);
|
|
597
|
+
return { type: "NotExpression", child };
|
|
598
|
+
}
|
|
599
|
+
case "Minus": {
|
|
600
|
+
const child = this.expression(bindingPower.Minus);
|
|
601
|
+
return {
|
|
602
|
+
type: "Unary",
|
|
603
|
+
operator: token.type,
|
|
604
|
+
operand: child
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
case "Plus": {
|
|
608
|
+
const child = this.expression(bindingPower.Plus);
|
|
609
|
+
return {
|
|
610
|
+
type: "Unary",
|
|
611
|
+
operator: token.type,
|
|
612
|
+
operand: child
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
case "Star": {
|
|
616
|
+
const left = { type: "Identity" };
|
|
617
|
+
return { type: "ValueProjection", left, right: this.parseProjectionRHS(bindingPower.Star) };
|
|
618
|
+
}
|
|
619
|
+
case "Filter":
|
|
620
|
+
return this.led(token.type, { type: "Identity" });
|
|
621
|
+
case "Lbrace":
|
|
622
|
+
return this.parseMultiselectHash();
|
|
623
|
+
case "Flatten": {
|
|
624
|
+
const left = {
|
|
625
|
+
type: "Flatten",
|
|
626
|
+
child: { type: "Identity" }
|
|
627
|
+
};
|
|
628
|
+
const right = this.parseProjectionRHS(bindingPower.Flatten);
|
|
629
|
+
return { type: "Projection", left, right };
|
|
630
|
+
}
|
|
631
|
+
case "Lbracket": {
|
|
632
|
+
if (this.lookahead(0) === "Number" || this.lookahead(0) === "Colon") {
|
|
633
|
+
const right = this.parseIndexExpression();
|
|
634
|
+
return this.projectIfSlice({ type: "Identity" }, right);
|
|
635
|
+
}
|
|
636
|
+
if (this.lookahead(0) === "Star" && this.lookahead(1) === "Rbracket") {
|
|
637
|
+
this.advance();
|
|
638
|
+
this.advance();
|
|
639
|
+
const right = this.parseProjectionRHS(bindingPower.Star);
|
|
640
|
+
return {
|
|
641
|
+
left: { type: "Identity" },
|
|
642
|
+
right,
|
|
643
|
+
type: "Projection"
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return this.parseMultiselectList();
|
|
647
|
+
}
|
|
648
|
+
case "Current":
|
|
649
|
+
return { type: "Current" };
|
|
650
|
+
case "Root":
|
|
651
|
+
return { type: "Root" };
|
|
652
|
+
case "Expref": {
|
|
653
|
+
const child = this.expression(bindingPower.Expref);
|
|
654
|
+
return { type: "ExpressionReference", child };
|
|
655
|
+
}
|
|
656
|
+
case "Lparen": {
|
|
657
|
+
const expression = this.expression(0);
|
|
658
|
+
this.match("Rparen");
|
|
659
|
+
return expression;
|
|
660
|
+
}
|
|
661
|
+
default:
|
|
662
|
+
this.errorToken(token);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
led(tokenName, left) {
|
|
666
|
+
switch (tokenName) {
|
|
667
|
+
case "Question": {
|
|
668
|
+
const trueExpr = this.expression(0);
|
|
669
|
+
this.match("Colon");
|
|
670
|
+
const falseExpr = this.expression(0);
|
|
671
|
+
return {
|
|
672
|
+
type: "Ternary",
|
|
673
|
+
condition: left,
|
|
674
|
+
trueExpr,
|
|
675
|
+
falseExpr
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
case "Dot": {
|
|
679
|
+
const rbp = bindingPower.Dot;
|
|
680
|
+
if (this.lookahead(0) !== "Star") {
|
|
681
|
+
const right2 = this.parseDotRHS(rbp);
|
|
682
|
+
return { type: "Subexpression", left, right: right2 };
|
|
683
|
+
}
|
|
684
|
+
this.advance();
|
|
685
|
+
const right = this.parseProjectionRHS(rbp);
|
|
686
|
+
return { type: "ValueProjection", left, right };
|
|
687
|
+
}
|
|
688
|
+
case "Pipe": {
|
|
689
|
+
const right = this.expression(bindingPower.Pipe);
|
|
690
|
+
return { type: "Pipe", left, right };
|
|
691
|
+
}
|
|
692
|
+
case "Or": {
|
|
693
|
+
const right = this.expression(bindingPower.Or);
|
|
694
|
+
return { type: "OrExpression", left, right };
|
|
695
|
+
}
|
|
696
|
+
case "And": {
|
|
697
|
+
const right = this.expression(bindingPower.And);
|
|
698
|
+
return { type: "AndExpression", left, right };
|
|
699
|
+
}
|
|
700
|
+
case "Lparen": {
|
|
701
|
+
if (left.type !== "Field") {
|
|
702
|
+
throw new Error("Syntax error: expected a Field node");
|
|
703
|
+
}
|
|
704
|
+
const name = left.name;
|
|
705
|
+
const args = this.parseCommaSeparatedExpressionsUntilToken("Rparen");
|
|
706
|
+
const node = { name, type: "Function", children: args };
|
|
707
|
+
return node;
|
|
708
|
+
}
|
|
709
|
+
case "Filter": {
|
|
710
|
+
const condition = this.expression(0);
|
|
711
|
+
this.match("Rbracket");
|
|
712
|
+
const right = this.lookahead(0) === "Flatten" ? { type: "Identity" } : this.parseProjectionRHS(bindingPower.Filter);
|
|
713
|
+
return { type: "FilterProjection", left, right, condition };
|
|
714
|
+
}
|
|
715
|
+
case "Flatten": {
|
|
716
|
+
const leftNode = { type: "Flatten", child: left };
|
|
717
|
+
const right = this.parseProjectionRHS(bindingPower.Flatten);
|
|
718
|
+
return { type: "Projection", left: leftNode, right };
|
|
719
|
+
}
|
|
720
|
+
case "Assign": {
|
|
721
|
+
const leftNode = left;
|
|
722
|
+
const right = this.expression(0);
|
|
723
|
+
return {
|
|
724
|
+
type: "Binding",
|
|
725
|
+
variable: leftNode.name,
|
|
726
|
+
reference: right
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
case "EQ":
|
|
730
|
+
case "NE":
|
|
731
|
+
case "GT":
|
|
732
|
+
case "GTE":
|
|
733
|
+
case "LT":
|
|
734
|
+
case "LTE":
|
|
735
|
+
return this.parseComparator(left, tokenName);
|
|
736
|
+
case "Plus":
|
|
737
|
+
case "Minus":
|
|
738
|
+
case "Multiply":
|
|
739
|
+
case "Star":
|
|
740
|
+
case "Divide":
|
|
741
|
+
case "Modulo":
|
|
742
|
+
case "Div":
|
|
743
|
+
return this.parseArithmetic(left, tokenName);
|
|
744
|
+
case "Lbracket": {
|
|
745
|
+
const token = this.lookaheadToken(0);
|
|
746
|
+
if (token.type === "Number" || token.type === "Colon") {
|
|
747
|
+
const right2 = this.parseIndexExpression();
|
|
748
|
+
return this.projectIfSlice(left, right2);
|
|
749
|
+
}
|
|
750
|
+
this.match("Star");
|
|
751
|
+
this.match("Rbracket");
|
|
752
|
+
const right = this.parseProjectionRHS(bindingPower.Star);
|
|
753
|
+
return { type: "Projection", left, right };
|
|
754
|
+
}
|
|
755
|
+
default:
|
|
756
|
+
return this.errorToken(this.lookaheadToken(0));
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
static isKeyword(token, keyword) {
|
|
760
|
+
return token.type === "UnquotedIdentifier" && token.value === keyword;
|
|
761
|
+
}
|
|
762
|
+
match(tokenType) {
|
|
763
|
+
if (this.lookahead(0) === tokenType) {
|
|
764
|
+
this.advance();
|
|
765
|
+
return;
|
|
766
|
+
} else {
|
|
767
|
+
const token = this.lookaheadToken(0);
|
|
768
|
+
this.errorToken(token, `Syntax error: expected ${tokenType}, got: ${token.type}`);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
errorToken(token, message = "") {
|
|
772
|
+
const error = new Error(message || `Syntax error: invalid token (${token.type}): "${token.value}"`);
|
|
773
|
+
error.name = "ParserError";
|
|
774
|
+
throw error;
|
|
775
|
+
}
|
|
776
|
+
parseIndexExpression() {
|
|
777
|
+
if (this.lookahead(0) === "Colon" || this.lookahead(1) === "Colon") {
|
|
778
|
+
return this.parseSliceExpression();
|
|
779
|
+
}
|
|
780
|
+
const value = Number(this.lookaheadToken(0).value);
|
|
781
|
+
this.advance();
|
|
782
|
+
this.match("Rbracket");
|
|
783
|
+
return { type: "Index", value };
|
|
784
|
+
}
|
|
785
|
+
projectIfSlice(left, right) {
|
|
786
|
+
const indexExpr = {
|
|
787
|
+
type: "IndexExpression",
|
|
788
|
+
left,
|
|
789
|
+
right
|
|
790
|
+
};
|
|
791
|
+
if (right.type === "Slice") {
|
|
792
|
+
return {
|
|
793
|
+
left: indexExpr,
|
|
794
|
+
right: this.parseProjectionRHS(bindingPower.Star),
|
|
795
|
+
type: "Projection"
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
return indexExpr;
|
|
799
|
+
}
|
|
800
|
+
parseSliceExpression() {
|
|
801
|
+
const parts = [null, null, null];
|
|
802
|
+
let index = 0;
|
|
803
|
+
let current = this.lookaheadToken(0);
|
|
804
|
+
while (current.type != "Rbracket" && index < 3) {
|
|
805
|
+
if (current.type === "Colon") {
|
|
806
|
+
index++;
|
|
807
|
+
if (index === 3) {
|
|
808
|
+
this.errorToken(this.lookaheadToken(0), "Syntax error, too many colons in slice expression");
|
|
809
|
+
}
|
|
810
|
+
this.advance();
|
|
811
|
+
} else if (current.type === "Number") {
|
|
812
|
+
const part = this.lookaheadToken(0).value;
|
|
813
|
+
parts[index] = part;
|
|
814
|
+
this.advance();
|
|
815
|
+
} else {
|
|
816
|
+
const next = this.lookaheadToken(0);
|
|
817
|
+
this.errorToken(next, `Syntax error, unexpected token: ${next.value}(${next.type})`);
|
|
818
|
+
}
|
|
819
|
+
current = this.lookaheadToken(0);
|
|
820
|
+
}
|
|
821
|
+
this.match("Rbracket");
|
|
822
|
+
const [start, stop, step] = parts;
|
|
823
|
+
return { type: "Slice", start, stop, step };
|
|
824
|
+
}
|
|
825
|
+
parseLetExpression() {
|
|
826
|
+
const separated = this.parseCommaSeparatedExpressionsUntilKeyword("in");
|
|
827
|
+
const expression = this.expression(0);
|
|
828
|
+
const bindings = separated.map((binding) => binding);
|
|
829
|
+
return {
|
|
830
|
+
type: "LetExpression",
|
|
831
|
+
bindings,
|
|
832
|
+
expression
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
parseCommaSeparatedExpressionsUntilKeyword(keyword) {
|
|
836
|
+
return this.parseCommaSeparatedExpressionsUntil(() => {
|
|
837
|
+
return _TokenParser.isKeyword(this.lookaheadToken(0), keyword);
|
|
838
|
+
}, () => {
|
|
839
|
+
this.advance();
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
parseCommaSeparatedExpressionsUntilToken(token) {
|
|
843
|
+
return this.parseCommaSeparatedExpressionsUntil(() => {
|
|
844
|
+
return this.lookahead(0) === token;
|
|
845
|
+
}, () => {
|
|
846
|
+
return this.match(token);
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
parseCommaSeparatedExpressionsUntil(isEndToken, matchEndToken) {
|
|
850
|
+
const args = [];
|
|
851
|
+
let expression;
|
|
852
|
+
while (!isEndToken()) {
|
|
853
|
+
expression = this.expression(0);
|
|
854
|
+
if (this.lookahead(0) === "Comma") {
|
|
855
|
+
this.match("Comma");
|
|
856
|
+
}
|
|
857
|
+
args.push(expression);
|
|
858
|
+
}
|
|
859
|
+
matchEndToken();
|
|
860
|
+
return args;
|
|
861
|
+
}
|
|
862
|
+
parseComparator(left, comparator) {
|
|
863
|
+
const right = this.expression(bindingPower[comparator]);
|
|
864
|
+
return { type: "Comparator", name: comparator, left, right };
|
|
865
|
+
}
|
|
866
|
+
parseArithmetic(left, operator) {
|
|
867
|
+
const right = this.expression(bindingPower[operator]);
|
|
868
|
+
return { type: "Arithmetic", operator, left, right };
|
|
869
|
+
}
|
|
870
|
+
parseDotRHS(rbp) {
|
|
871
|
+
const lookahead = this.lookahead(0);
|
|
872
|
+
const exprTokens = ["UnquotedIdentifier", "QuotedIdentifier", "Star"];
|
|
873
|
+
if (exprTokens.includes(lookahead)) {
|
|
874
|
+
return this.expression(rbp);
|
|
875
|
+
}
|
|
876
|
+
if (lookahead === "Lbracket") {
|
|
877
|
+
this.match("Lbracket");
|
|
878
|
+
return this.parseMultiselectList();
|
|
879
|
+
}
|
|
880
|
+
if (lookahead === "Lbrace") {
|
|
881
|
+
this.match("Lbrace");
|
|
882
|
+
return this.parseMultiselectHash();
|
|
883
|
+
}
|
|
884
|
+
const token = this.lookaheadToken(0);
|
|
885
|
+
this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`);
|
|
886
|
+
}
|
|
887
|
+
parseProjectionRHS(rbp) {
|
|
888
|
+
if (bindingPower[this.lookahead(0)] < 10) {
|
|
889
|
+
return { type: "Identity" };
|
|
890
|
+
}
|
|
891
|
+
if (this.lookahead(0) === "Lbracket") {
|
|
892
|
+
return this.expression(rbp);
|
|
893
|
+
}
|
|
894
|
+
if (this.lookahead(0) === "Filter") {
|
|
895
|
+
return this.expression(rbp);
|
|
896
|
+
}
|
|
897
|
+
if (this.lookahead(0) === "Dot") {
|
|
898
|
+
this.match("Dot");
|
|
899
|
+
return this.parseDotRHS(rbp);
|
|
900
|
+
}
|
|
901
|
+
const token = this.lookaheadToken(0);
|
|
902
|
+
this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`);
|
|
903
|
+
}
|
|
904
|
+
parseMultiselectList() {
|
|
905
|
+
const expressions = [];
|
|
906
|
+
while (this.lookahead(0) !== "Rbracket") {
|
|
907
|
+
const expression = this.expression(0);
|
|
908
|
+
expressions.push(expression);
|
|
909
|
+
if (this.lookahead(0) === "Comma") {
|
|
910
|
+
this.match("Comma");
|
|
911
|
+
if (this.lookahead(0) === "Rbracket") {
|
|
912
|
+
throw new Error("Syntax error: unexpected token Rbracket");
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
this.match("Rbracket");
|
|
917
|
+
return { type: "MultiSelectList", children: expressions };
|
|
918
|
+
}
|
|
919
|
+
parseMultiselectHash() {
|
|
920
|
+
const pairs = [];
|
|
921
|
+
const identifierTypes = ["UnquotedIdentifier", "QuotedIdentifier"];
|
|
922
|
+
let keyToken;
|
|
923
|
+
let keyName;
|
|
924
|
+
let value;
|
|
925
|
+
for (;; ) {
|
|
926
|
+
keyToken = this.lookaheadToken(0);
|
|
927
|
+
if (!identifierTypes.includes(keyToken.type)) {
|
|
928
|
+
throw new Error(`Syntax error: expecting an identifier token, got: ${keyToken.type}`);
|
|
929
|
+
}
|
|
930
|
+
keyName = keyToken.value;
|
|
931
|
+
this.advance();
|
|
932
|
+
this.match("Colon");
|
|
933
|
+
value = this.expression(0);
|
|
934
|
+
pairs.push({ value, type: "KeyValuePair", name: keyName });
|
|
935
|
+
if (this.lookahead(0) === "Comma") {
|
|
936
|
+
this.match("Comma");
|
|
937
|
+
} else if (this.lookahead(0) === "Rbrace") {
|
|
938
|
+
this.match("Rbrace");
|
|
939
|
+
break;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return { type: "MultiSelectHash", children: pairs };
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
var Parser = new TokenParser;
|
|
946
|
+
var Parser_default = Parser;
|
|
947
|
+
var Text = class _Text {
|
|
948
|
+
_text;
|
|
949
|
+
constructor(text) {
|
|
950
|
+
this._text = text;
|
|
951
|
+
}
|
|
952
|
+
get string() {
|
|
953
|
+
return this._text;
|
|
954
|
+
}
|
|
955
|
+
get length() {
|
|
956
|
+
return this.codePoints.length;
|
|
957
|
+
}
|
|
958
|
+
compareTo(other) {
|
|
959
|
+
return _Text.compare(this, new _Text(other));
|
|
960
|
+
}
|
|
961
|
+
static get comparer() {
|
|
962
|
+
const stringComparer = (left, right) => {
|
|
963
|
+
return new _Text(left).compareTo(right);
|
|
964
|
+
};
|
|
965
|
+
return stringComparer;
|
|
966
|
+
}
|
|
967
|
+
static compare(left, right) {
|
|
968
|
+
const leftCp = left.codePoints;
|
|
969
|
+
const rightCp = right.codePoints;
|
|
970
|
+
for (let index = 0;index < Math.min(leftCp.length, rightCp.length); index++) {
|
|
971
|
+
if (leftCp[index] === rightCp[index]) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
return leftCp[index] - rightCp[index] > 0 ? 1 : -1;
|
|
975
|
+
}
|
|
976
|
+
return leftCp.length - rightCp.length > 0 ? 1 : -1;
|
|
977
|
+
}
|
|
978
|
+
reverse() {
|
|
979
|
+
return String.fromCodePoint(...this.codePoints.reverse());
|
|
980
|
+
}
|
|
981
|
+
get codePoints() {
|
|
982
|
+
const array = [...this._text].map((s) => s.codePointAt(0));
|
|
983
|
+
return array;
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
var createMathFunction = (mathFn) => ([value]) => mathFn(value);
|
|
987
|
+
var createStringFunction = (stringFn) => ([subject]) => stringFn(subject);
|
|
988
|
+
var createObjectFunction = (objFn) => ([obj]) => objFn(obj);
|
|
989
|
+
var Runtime = class {
|
|
990
|
+
_interpreter;
|
|
991
|
+
_functionTable;
|
|
992
|
+
_customFunctions = /* @__PURE__ */ new Set;
|
|
993
|
+
TYPE_NAME_TABLE = Object.freeze({
|
|
994
|
+
[0]: "number",
|
|
995
|
+
[1]: "any",
|
|
996
|
+
[2]: "string",
|
|
997
|
+
[3]: "array",
|
|
998
|
+
[4]: "object",
|
|
999
|
+
[5]: "boolean",
|
|
1000
|
+
[6]: "expression",
|
|
1001
|
+
[7]: "null",
|
|
1002
|
+
[8]: "Array<number>",
|
|
1003
|
+
[10]: "Array<object>",
|
|
1004
|
+
[9]: "Array<string>",
|
|
1005
|
+
[11]: "Array<Array<any>>"
|
|
1006
|
+
});
|
|
1007
|
+
constructor(interpreter) {
|
|
1008
|
+
this._interpreter = interpreter;
|
|
1009
|
+
this._functionTable = this.buildFunctionTable();
|
|
1010
|
+
}
|
|
1011
|
+
buildFunctionTable() {
|
|
1012
|
+
return {
|
|
1013
|
+
abs: { _func: createMathFunction(Math.abs), _signature: [{ types: [0] }] },
|
|
1014
|
+
ceil: { _func: createMathFunction(Math.ceil), _signature: [{ types: [0] }] },
|
|
1015
|
+
floor: { _func: createMathFunction(Math.floor), _signature: [{ types: [0] }] },
|
|
1016
|
+
lower: { _func: createStringFunction(lower), _signature: [{ types: [2] }] },
|
|
1017
|
+
upper: { _func: createStringFunction(upper), _signature: [{ types: [2] }] },
|
|
1018
|
+
keys: { _func: createObjectFunction(Object.keys), _signature: [{ types: [4] }] },
|
|
1019
|
+
values: { _func: createObjectFunction(Object.values), _signature: [{ types: [4] }] },
|
|
1020
|
+
avg: { _func: this.functionAvg, _signature: [{ types: [8] }] },
|
|
1021
|
+
contains: {
|
|
1022
|
+
_func: this.functionContains,
|
|
1023
|
+
_signature: [
|
|
1024
|
+
{ types: [2, 3] },
|
|
1025
|
+
{ types: [1] }
|
|
1026
|
+
]
|
|
1027
|
+
},
|
|
1028
|
+
ends_with: {
|
|
1029
|
+
_func: this.functionEndsWith,
|
|
1030
|
+
_signature: [{ types: [2] }, { types: [2] }]
|
|
1031
|
+
},
|
|
1032
|
+
find_first: {
|
|
1033
|
+
_func: this.functionFindFirst,
|
|
1034
|
+
_signature: [
|
|
1035
|
+
{ types: [2] },
|
|
1036
|
+
{ types: [2] },
|
|
1037
|
+
{ types: [0], optional: true },
|
|
1038
|
+
{ types: [0], optional: true }
|
|
1039
|
+
]
|
|
1040
|
+
},
|
|
1041
|
+
find_last: {
|
|
1042
|
+
_func: this.functionFindLast,
|
|
1043
|
+
_signature: [
|
|
1044
|
+
{ types: [2] },
|
|
1045
|
+
{ types: [2] },
|
|
1046
|
+
{ types: [0], optional: true },
|
|
1047
|
+
{ types: [0], optional: true }
|
|
1048
|
+
]
|
|
1049
|
+
},
|
|
1050
|
+
from_items: { _func: this.functionFromItems, _signature: [{ types: [11] }] },
|
|
1051
|
+
group_by: {
|
|
1052
|
+
_func: this.functionGroupBy,
|
|
1053
|
+
_signature: [{ types: [3] }, { types: [6] }]
|
|
1054
|
+
},
|
|
1055
|
+
items: { _func: this.functionItems, _signature: [{ types: [4] }] },
|
|
1056
|
+
join: {
|
|
1057
|
+
_func: this.functionJoin,
|
|
1058
|
+
_signature: [{ types: [2] }, { types: [9] }]
|
|
1059
|
+
},
|
|
1060
|
+
length: {
|
|
1061
|
+
_func: this.functionLength,
|
|
1062
|
+
_signature: [{ types: [2, 3, 4] }]
|
|
1063
|
+
},
|
|
1064
|
+
map: {
|
|
1065
|
+
_func: this.functionMap,
|
|
1066
|
+
_signature: [{ types: [6] }, { types: [3] }]
|
|
1067
|
+
},
|
|
1068
|
+
max: {
|
|
1069
|
+
_func: this.functionMax,
|
|
1070
|
+
_signature: [{ types: [8, 9] }]
|
|
1071
|
+
},
|
|
1072
|
+
max_by: {
|
|
1073
|
+
_func: this.functionMaxBy,
|
|
1074
|
+
_signature: [{ types: [3] }, { types: [6] }]
|
|
1075
|
+
},
|
|
1076
|
+
merge: { _func: this.functionMerge, _signature: [{ types: [4], variadic: true }] },
|
|
1077
|
+
min: {
|
|
1078
|
+
_func: this.functionMin,
|
|
1079
|
+
_signature: [{ types: [8, 9] }]
|
|
1080
|
+
},
|
|
1081
|
+
min_by: {
|
|
1082
|
+
_func: this.functionMinBy,
|
|
1083
|
+
_signature: [{ types: [3] }, { types: [6] }]
|
|
1084
|
+
},
|
|
1085
|
+
not_null: { _func: this.functionNotNull, _signature: [{ types: [1], variadic: true }] },
|
|
1086
|
+
pad_left: {
|
|
1087
|
+
_func: this.functionPadLeft,
|
|
1088
|
+
_signature: [
|
|
1089
|
+
{ types: [2] },
|
|
1090
|
+
{ types: [0] },
|
|
1091
|
+
{ types: [2], optional: true }
|
|
1092
|
+
]
|
|
1093
|
+
},
|
|
1094
|
+
pad_right: {
|
|
1095
|
+
_func: this.functionPadRight,
|
|
1096
|
+
_signature: [
|
|
1097
|
+
{ types: [2] },
|
|
1098
|
+
{ types: [0] },
|
|
1099
|
+
{ types: [2], optional: true }
|
|
1100
|
+
]
|
|
1101
|
+
},
|
|
1102
|
+
replace: {
|
|
1103
|
+
_func: this.functionReplace,
|
|
1104
|
+
_signature: [
|
|
1105
|
+
{ types: [2] },
|
|
1106
|
+
{ types: [2] },
|
|
1107
|
+
{ types: [2] },
|
|
1108
|
+
{ types: [0], optional: true }
|
|
1109
|
+
]
|
|
1110
|
+
},
|
|
1111
|
+
reverse: {
|
|
1112
|
+
_func: this.functionReverse,
|
|
1113
|
+
_signature: [{ types: [2, 3] }]
|
|
1114
|
+
},
|
|
1115
|
+
sort: {
|
|
1116
|
+
_func: this.functionSort,
|
|
1117
|
+
_signature: [{ types: [9, 8] }]
|
|
1118
|
+
},
|
|
1119
|
+
sort_by: {
|
|
1120
|
+
_func: this.functionSortBy,
|
|
1121
|
+
_signature: [{ types: [3] }, { types: [6] }]
|
|
1122
|
+
},
|
|
1123
|
+
split: {
|
|
1124
|
+
_func: this.functionSplit,
|
|
1125
|
+
_signature: [
|
|
1126
|
+
{ types: [2] },
|
|
1127
|
+
{ types: [2] },
|
|
1128
|
+
{ types: [0], optional: true }
|
|
1129
|
+
]
|
|
1130
|
+
},
|
|
1131
|
+
starts_with: {
|
|
1132
|
+
_func: this.functionStartsWith,
|
|
1133
|
+
_signature: [{ types: [2] }, { types: [2] }]
|
|
1134
|
+
},
|
|
1135
|
+
sum: { _func: this.functionSum, _signature: [{ types: [8] }] },
|
|
1136
|
+
to_array: { _func: this.functionToArray, _signature: [{ types: [1] }] },
|
|
1137
|
+
to_number: { _func: this.functionToNumber, _signature: [{ types: [1] }] },
|
|
1138
|
+
to_string: { _func: this.functionToString, _signature: [{ types: [1] }] },
|
|
1139
|
+
trim: {
|
|
1140
|
+
_func: this.functionTrim,
|
|
1141
|
+
_signature: [{ types: [2] }, { types: [2], optional: true }]
|
|
1142
|
+
},
|
|
1143
|
+
trim_left: {
|
|
1144
|
+
_func: this.functionTrimLeft,
|
|
1145
|
+
_signature: [{ types: [2] }, { types: [2], optional: true }]
|
|
1146
|
+
},
|
|
1147
|
+
trim_right: {
|
|
1148
|
+
_func: this.functionTrimRight,
|
|
1149
|
+
_signature: [{ types: [2] }, { types: [2], optional: true }]
|
|
1150
|
+
},
|
|
1151
|
+
type: { _func: this.functionType, _signature: [{ types: [1] }] },
|
|
1152
|
+
zip: { _func: this.functionZip, _signature: [{ types: [3], variadic: true }] }
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
registerFunction(name, customFunction, signature, options) {
|
|
1156
|
+
const result = this._registerInternal(name, customFunction, signature, options);
|
|
1157
|
+
if (!result.success) {
|
|
1158
|
+
throw new Error(result.message);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
_registerInternal(name, customFunction, signature, options = {}) {
|
|
1162
|
+
if (!name || typeof name !== "string" || name.trim() === "") {
|
|
1163
|
+
return {
|
|
1164
|
+
success: false,
|
|
1165
|
+
reason: "invalid-name",
|
|
1166
|
+
message: "Function name must be a non-empty string"
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
try {
|
|
1170
|
+
this.validateInputSignatures(name, signature);
|
|
1171
|
+
} catch (error) {
|
|
1172
|
+
return {
|
|
1173
|
+
success: false,
|
|
1174
|
+
reason: "invalid-signature",
|
|
1175
|
+
message: error instanceof Error ? error.message : "Invalid function signature"
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
const { override = false, warn = false } = options;
|
|
1179
|
+
const exists = name in this._functionTable;
|
|
1180
|
+
if (exists && !override) {
|
|
1181
|
+
return {
|
|
1182
|
+
success: false,
|
|
1183
|
+
reason: "already-exists",
|
|
1184
|
+
message: `Function already defined: ${name}(). Use { override: true } to replace it.`
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
if (exists && override && warn) {
|
|
1188
|
+
console.warn(`Warning: Overriding existing function: ${name}()`);
|
|
1189
|
+
}
|
|
1190
|
+
this._functionTable[name] = {
|
|
1191
|
+
_func: customFunction.bind(this),
|
|
1192
|
+
_signature: signature
|
|
1193
|
+
};
|
|
1194
|
+
this._customFunctions.add(name);
|
|
1195
|
+
const message = exists ? `Function ${name}() overridden successfully` : `Function ${name}() registered successfully`;
|
|
1196
|
+
return { success: true, message };
|
|
1197
|
+
}
|
|
1198
|
+
register(name, customFunction, signature, options = {}) {
|
|
1199
|
+
return this._registerInternal(name, customFunction, signature, options);
|
|
1200
|
+
}
|
|
1201
|
+
unregister(name) {
|
|
1202
|
+
if (!this._customFunctions.has(name)) {
|
|
1203
|
+
return false;
|
|
1204
|
+
}
|
|
1205
|
+
delete this._functionTable[name];
|
|
1206
|
+
this._customFunctions.delete(name);
|
|
1207
|
+
return true;
|
|
1208
|
+
}
|
|
1209
|
+
isRegistered(name) {
|
|
1210
|
+
return name in this._functionTable;
|
|
1211
|
+
}
|
|
1212
|
+
getRegistered() {
|
|
1213
|
+
return Object.keys(this._functionTable);
|
|
1214
|
+
}
|
|
1215
|
+
getCustomFunctions() {
|
|
1216
|
+
return Array.from(this._customFunctions);
|
|
1217
|
+
}
|
|
1218
|
+
clearCustomFunctions() {
|
|
1219
|
+
for (const name of this._customFunctions) {
|
|
1220
|
+
delete this._functionTable[name];
|
|
1221
|
+
}
|
|
1222
|
+
this._customFunctions.clear();
|
|
1223
|
+
}
|
|
1224
|
+
callFunction(name, resolvedArgs) {
|
|
1225
|
+
const functionEntry = this._functionTable[name];
|
|
1226
|
+
if (functionEntry === undefined) {
|
|
1227
|
+
throw new Error(`Unknown function: ${name}()`);
|
|
1228
|
+
}
|
|
1229
|
+
this.validateArgs(name, resolvedArgs, functionEntry._signature);
|
|
1230
|
+
return functionEntry._func.call(this, resolvedArgs);
|
|
1231
|
+
}
|
|
1232
|
+
validateInputSignatures(name, signature) {
|
|
1233
|
+
for (let i = 0;i < signature.length; i += 1) {
|
|
1234
|
+
if ("variadic" in signature[i] && i !== signature.length - 1) {
|
|
1235
|
+
throw new Error(`Invalid arity: ${name}() 'variadic' argument ${i + 1} must occur last`);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
validateArgs(name, args, signature) {
|
|
1240
|
+
this.validateInputSignatures(name, signature);
|
|
1241
|
+
this.validateArity(name, args, signature);
|
|
1242
|
+
this.validateTypes(name, args, signature);
|
|
1243
|
+
}
|
|
1244
|
+
validateArity(name, args, signature) {
|
|
1245
|
+
const numberOfRequiredArgs = signature.filter((argSignature) => !(argSignature.optional ?? false)).length;
|
|
1246
|
+
const lastArgIsVariadic = signature[signature.length - 1]?.variadic ?? false;
|
|
1247
|
+
const tooFewArgs = args.length < numberOfRequiredArgs;
|
|
1248
|
+
const tooManyArgs = args.length > signature.length;
|
|
1249
|
+
if (lastArgIsVariadic && tooFewArgs || !lastArgIsVariadic && (tooFewArgs || tooManyArgs)) {
|
|
1250
|
+
const tooFewModifier = tooFewArgs && (!lastArgIsVariadic && numberOfRequiredArgs > 1 || lastArgIsVariadic) ? "at least " : "";
|
|
1251
|
+
const pluralized = signature.length > 1;
|
|
1252
|
+
throw new Error(`Invalid arity: ${name}() takes ${tooFewModifier}${numberOfRequiredArgs} argument${pluralized && "s" || ""} but received ${args.length}`);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
validateTypes(name, args, signature) {
|
|
1256
|
+
for (let i = 0;i < signature.length; i += 1) {
|
|
1257
|
+
const currentSpec = signature[i].types;
|
|
1258
|
+
const actualType = this.getTypeName(args[i]);
|
|
1259
|
+
if (actualType === undefined) {
|
|
1260
|
+
continue;
|
|
1261
|
+
}
|
|
1262
|
+
const typeMatched = currentSpec.some((expectedType) => this.typeMatches(actualType, expectedType, args[i]));
|
|
1263
|
+
if (!typeMatched) {
|
|
1264
|
+
const expected = currentSpec.map((typeId) => this.TYPE_NAME_TABLE[typeId]).join(" | ");
|
|
1265
|
+
throw new Error(`Invalid type: ${name}() expected argument ${i + 1} to be type (${expected}) but received type ${this.TYPE_NAME_TABLE[actualType]} instead.`);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
typeMatches(actual, expected, argValue) {
|
|
1270
|
+
if (expected === 1) {
|
|
1271
|
+
return true;
|
|
1272
|
+
}
|
|
1273
|
+
if (expected === 9 || expected === 8 || expected === 10 || expected === 11 || expected === 3) {
|
|
1274
|
+
if (expected === 3) {
|
|
1275
|
+
return actual === 3;
|
|
1276
|
+
}
|
|
1277
|
+
if (actual === 3) {
|
|
1278
|
+
let subtype;
|
|
1279
|
+
if (expected === 8) {
|
|
1280
|
+
subtype = 0;
|
|
1281
|
+
} else if (expected === 10) {
|
|
1282
|
+
subtype = 4;
|
|
1283
|
+
} else if (expected === 9) {
|
|
1284
|
+
subtype = 2;
|
|
1285
|
+
} else if (expected === 11) {
|
|
1286
|
+
subtype = 3;
|
|
1287
|
+
}
|
|
1288
|
+
const array = argValue;
|
|
1289
|
+
for (let i = 0;i < array.length; i += 1) {
|
|
1290
|
+
const typeName = this.getTypeName(array[i]);
|
|
1291
|
+
if (typeName !== undefined && subtype !== undefined && !this.typeMatches(typeName, subtype, array[i])) {
|
|
1292
|
+
return false;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
return true;
|
|
1296
|
+
}
|
|
1297
|
+
} else {
|
|
1298
|
+
return actual === expected;
|
|
1299
|
+
}
|
|
1300
|
+
return false;
|
|
1301
|
+
}
|
|
1302
|
+
getTypeName(obj) {
|
|
1303
|
+
if (obj === null) {
|
|
1304
|
+
return 7;
|
|
1305
|
+
}
|
|
1306
|
+
if (typeof obj === "string") {
|
|
1307
|
+
return 2;
|
|
1308
|
+
}
|
|
1309
|
+
if (typeof obj === "number") {
|
|
1310
|
+
return 0;
|
|
1311
|
+
}
|
|
1312
|
+
if (typeof obj === "boolean") {
|
|
1313
|
+
return 5;
|
|
1314
|
+
}
|
|
1315
|
+
if (Array.isArray(obj)) {
|
|
1316
|
+
return 3;
|
|
1317
|
+
}
|
|
1318
|
+
if (typeof obj === "object") {
|
|
1319
|
+
if (obj.expref) {
|
|
1320
|
+
return 6;
|
|
1321
|
+
}
|
|
1322
|
+
return 4;
|
|
1323
|
+
}
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
createKeyFunction(exprefNode, allowedTypes) {
|
|
1327
|
+
const interpreter = this._interpreter;
|
|
1328
|
+
const keyFunc = (x) => {
|
|
1329
|
+
const current = interpreter.visit(exprefNode, x);
|
|
1330
|
+
if (!allowedTypes.includes(this.getTypeName(current))) {
|
|
1331
|
+
const msg = `Invalid type: expected one of (${allowedTypes.map((t) => this.TYPE_NAME_TABLE[t]).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(current)]}`;
|
|
1332
|
+
throw new Error(msg);
|
|
1333
|
+
}
|
|
1334
|
+
return current;
|
|
1335
|
+
};
|
|
1336
|
+
return keyFunc;
|
|
1337
|
+
}
|
|
1338
|
+
functionAvg = ([inputArray]) => {
|
|
1339
|
+
if (!inputArray || inputArray.length == 0) {
|
|
1340
|
+
return null;
|
|
1341
|
+
}
|
|
1342
|
+
let sum = 0;
|
|
1343
|
+
for (let i = 0;i < inputArray.length; i += 1) {
|
|
1344
|
+
sum += inputArray[i];
|
|
1345
|
+
}
|
|
1346
|
+
return sum / inputArray.length;
|
|
1347
|
+
};
|
|
1348
|
+
functionContains = ([
|
|
1349
|
+
searchable,
|
|
1350
|
+
searchValue
|
|
1351
|
+
]) => {
|
|
1352
|
+
if (Array.isArray(searchable)) {
|
|
1353
|
+
const array = searchable;
|
|
1354
|
+
return array.includes(searchValue);
|
|
1355
|
+
}
|
|
1356
|
+
if (typeof searchable === "string") {
|
|
1357
|
+
const text = searchable;
|
|
1358
|
+
if (typeof searchValue === "string") {
|
|
1359
|
+
return text.includes(searchValue);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
return null;
|
|
1363
|
+
};
|
|
1364
|
+
functionEndsWith = (resolvedArgs) => {
|
|
1365
|
+
const [searchStr, suffix] = resolvedArgs;
|
|
1366
|
+
return searchStr.includes(suffix, searchStr.length - suffix.length);
|
|
1367
|
+
};
|
|
1368
|
+
functionFindFirst = this.createFindFunction(findFirst);
|
|
1369
|
+
functionFindLast = this.createFindFunction(findLast);
|
|
1370
|
+
createFindFunction(findFn) {
|
|
1371
|
+
return (resolvedArgs) => {
|
|
1372
|
+
const subject = resolvedArgs[0];
|
|
1373
|
+
const search2 = resolvedArgs[1];
|
|
1374
|
+
const start = resolvedArgs.length > 2 ? resolvedArgs[2] : undefined;
|
|
1375
|
+
const end = resolvedArgs.length > 3 ? resolvedArgs[3] : undefined;
|
|
1376
|
+
return findFn(subject, search2, start, end);
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
functionFromItems = ([array]) => {
|
|
1380
|
+
array.map((pair) => {
|
|
1381
|
+
if (pair.length != 2 || typeof pair[0] !== "string") {
|
|
1382
|
+
throw new Error("invalid value, each array must contain two elements, a pair of string and value");
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
return Object.fromEntries(array);
|
|
1386
|
+
};
|
|
1387
|
+
functionGroupBy = ([array, exprefNode]) => {
|
|
1388
|
+
const keyFunction = this.createKeyFunction(exprefNode, [2]);
|
|
1389
|
+
return array.reduce((acc, cur) => {
|
|
1390
|
+
const k = keyFunction(cur ?? {});
|
|
1391
|
+
const target = acc[k] = acc[k] || [];
|
|
1392
|
+
target.push(cur);
|
|
1393
|
+
return acc;
|
|
1394
|
+
}, {});
|
|
1395
|
+
};
|
|
1396
|
+
functionItems = ([inputValue]) => {
|
|
1397
|
+
return Object.entries(inputValue);
|
|
1398
|
+
};
|
|
1399
|
+
functionJoin = (resolvedArgs) => {
|
|
1400
|
+
const [joinChar, listJoin] = resolvedArgs;
|
|
1401
|
+
return listJoin.join(joinChar);
|
|
1402
|
+
};
|
|
1403
|
+
functionLength = ([inputValue]) => {
|
|
1404
|
+
if (typeof inputValue === "string") {
|
|
1405
|
+
return new Text(inputValue).length;
|
|
1406
|
+
}
|
|
1407
|
+
if (Array.isArray(inputValue)) {
|
|
1408
|
+
return inputValue.length;
|
|
1409
|
+
}
|
|
1410
|
+
return Object.keys(inputValue).length;
|
|
1411
|
+
};
|
|
1412
|
+
functionMap = ([exprefNode, elements]) => {
|
|
1413
|
+
if (!this._interpreter) {
|
|
1414
|
+
return [];
|
|
1415
|
+
}
|
|
1416
|
+
const mapped = [];
|
|
1417
|
+
const interpreter = this._interpreter;
|
|
1418
|
+
for (let i = 0;i < elements.length; i += 1) {
|
|
1419
|
+
mapped.push(interpreter.visit(exprefNode, elements[i]));
|
|
1420
|
+
}
|
|
1421
|
+
return mapped;
|
|
1422
|
+
};
|
|
1423
|
+
functionMax = ([inputValue]) => {
|
|
1424
|
+
if (!inputValue.length) {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
const typeName = this.getTypeName(inputValue[0]);
|
|
1428
|
+
if (typeName === 0) {
|
|
1429
|
+
return Math.max(...inputValue);
|
|
1430
|
+
}
|
|
1431
|
+
const elements = inputValue;
|
|
1432
|
+
let maxElement = elements[0];
|
|
1433
|
+
for (let i = 1;i < elements.length; i += 1) {
|
|
1434
|
+
if (maxElement.localeCompare(elements[i]) < 0) {
|
|
1435
|
+
maxElement = elements[i];
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return maxElement;
|
|
1439
|
+
};
|
|
1440
|
+
functionMaxBy = (resolvedArgs) => {
|
|
1441
|
+
const exprefNode = resolvedArgs[1];
|
|
1442
|
+
const resolvedArray = resolvedArgs[0];
|
|
1443
|
+
const keyFunction = this.createKeyFunction(exprefNode, [0, 2]);
|
|
1444
|
+
let maxNumber = -Infinity;
|
|
1445
|
+
let maxRecord;
|
|
1446
|
+
let current;
|
|
1447
|
+
for (let i = 0;i < resolvedArray.length; i += 1) {
|
|
1448
|
+
current = keyFunction && keyFunction(resolvedArray[i]);
|
|
1449
|
+
if (current !== undefined && current > maxNumber) {
|
|
1450
|
+
maxNumber = current;
|
|
1451
|
+
maxRecord = resolvedArray[i];
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
return maxRecord || null;
|
|
1455
|
+
};
|
|
1456
|
+
functionMerge = (resolvedArgs) => {
|
|
1457
|
+
let merged = {};
|
|
1458
|
+
for (let i = 0;i < resolvedArgs.length; i += 1) {
|
|
1459
|
+
const current = resolvedArgs[i];
|
|
1460
|
+
merged = Object.assign(merged, current);
|
|
1461
|
+
}
|
|
1462
|
+
return merged;
|
|
1463
|
+
};
|
|
1464
|
+
functionMin = ([inputValue]) => {
|
|
1465
|
+
if (!inputValue.length) {
|
|
1466
|
+
return null;
|
|
1467
|
+
}
|
|
1468
|
+
const typeName = this.getTypeName(inputValue[0]);
|
|
1469
|
+
if (typeName === 0) {
|
|
1470
|
+
return Math.min(...inputValue);
|
|
1471
|
+
}
|
|
1472
|
+
const elements = inputValue;
|
|
1473
|
+
let minElement = elements[0];
|
|
1474
|
+
for (let i = 1;i < elements.length; i += 1) {
|
|
1475
|
+
if (elements[i].localeCompare(minElement) < 0) {
|
|
1476
|
+
minElement = elements[i];
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return minElement;
|
|
1480
|
+
};
|
|
1481
|
+
functionMinBy = (resolvedArgs) => {
|
|
1482
|
+
const exprefNode = resolvedArgs[1];
|
|
1483
|
+
const resolvedArray = resolvedArgs[0];
|
|
1484
|
+
const keyFunction = this.createKeyFunction(exprefNode, [0, 2]);
|
|
1485
|
+
let minNumber = Infinity;
|
|
1486
|
+
let minRecord;
|
|
1487
|
+
let current;
|
|
1488
|
+
for (let i = 0;i < resolvedArray.length; i += 1) {
|
|
1489
|
+
current = keyFunction && keyFunction(resolvedArray[i]);
|
|
1490
|
+
if (current !== undefined && current < minNumber) {
|
|
1491
|
+
minNumber = current;
|
|
1492
|
+
minRecord = resolvedArray[i];
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
return minRecord || null;
|
|
1496
|
+
};
|
|
1497
|
+
functionNotNull = (resolvedArgs) => {
|
|
1498
|
+
for (let i = 0;i < resolvedArgs.length; i += 1) {
|
|
1499
|
+
if (this.getTypeName(resolvedArgs[i]) !== 7) {
|
|
1500
|
+
return resolvedArgs[i];
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return null;
|
|
1504
|
+
};
|
|
1505
|
+
functionPadLeft = this.createPadFunction(padLeft);
|
|
1506
|
+
functionPadRight = this.createPadFunction(padRight);
|
|
1507
|
+
createPadFunction(padFn) {
|
|
1508
|
+
return (resolvedArgs) => {
|
|
1509
|
+
const subject = resolvedArgs[0];
|
|
1510
|
+
const width = resolvedArgs[1];
|
|
1511
|
+
const padding = resolvedArgs.length > 2 ? resolvedArgs[2] : undefined;
|
|
1512
|
+
return padFn(subject, width, padding);
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
functionReplace = (resolvedArgs) => {
|
|
1516
|
+
const subject = resolvedArgs[0];
|
|
1517
|
+
const string = resolvedArgs[1];
|
|
1518
|
+
const by = resolvedArgs[2];
|
|
1519
|
+
return replace(subject, string, by, resolvedArgs.length > 3 ? resolvedArgs[3] : undefined);
|
|
1520
|
+
};
|
|
1521
|
+
functionSplit = (resolvedArgs) => {
|
|
1522
|
+
const subject = resolvedArgs[0];
|
|
1523
|
+
const search2 = resolvedArgs[1];
|
|
1524
|
+
return split(subject, search2, resolvedArgs.length > 2 ? resolvedArgs[2] : undefined);
|
|
1525
|
+
};
|
|
1526
|
+
functionReverse = ([inputValue]) => {
|
|
1527
|
+
const typeName = this.getTypeName(inputValue);
|
|
1528
|
+
if (typeName === 2) {
|
|
1529
|
+
return new Text(inputValue).reverse();
|
|
1530
|
+
}
|
|
1531
|
+
const reversedArray = inputValue.slice(0);
|
|
1532
|
+
reversedArray.reverse();
|
|
1533
|
+
return reversedArray;
|
|
1534
|
+
};
|
|
1535
|
+
functionSort = ([inputValue]) => {
|
|
1536
|
+
if (inputValue.length == 0) {
|
|
1537
|
+
return inputValue;
|
|
1538
|
+
}
|
|
1539
|
+
if (typeof inputValue[0] === "string") {
|
|
1540
|
+
return [...inputValue].sort(Text.comparer);
|
|
1541
|
+
}
|
|
1542
|
+
return [...inputValue].sort();
|
|
1543
|
+
};
|
|
1544
|
+
functionSortBy = (resolvedArgs) => {
|
|
1545
|
+
const sortedArray = resolvedArgs[0].slice(0);
|
|
1546
|
+
if (sortedArray.length === 0) {
|
|
1547
|
+
return sortedArray;
|
|
1548
|
+
}
|
|
1549
|
+
const interpreter = this._interpreter;
|
|
1550
|
+
const exprefNode = resolvedArgs[1];
|
|
1551
|
+
const requiredType = this.getTypeName(interpreter.visit(exprefNode, sortedArray[0]));
|
|
1552
|
+
if (requiredType !== undefined && ![0, 2].includes(requiredType)) {
|
|
1553
|
+
throw new Error(`Invalid type: unexpected type (${this.TYPE_NAME_TABLE[requiredType]})`);
|
|
1554
|
+
}
|
|
1555
|
+
function throwInvalidTypeError(rt, item) {
|
|
1556
|
+
throw new Error(`Invalid type: expected (${rt.TYPE_NAME_TABLE[requiredType]}), received ${rt.TYPE_NAME_TABLE[rt.getTypeName(item)]}`);
|
|
1557
|
+
}
|
|
1558
|
+
return sortedArray.sort((a, b) => {
|
|
1559
|
+
const exprA = interpreter.visit(exprefNode, a);
|
|
1560
|
+
const exprB = interpreter.visit(exprefNode, b);
|
|
1561
|
+
if (this.getTypeName(exprA) !== requiredType) {
|
|
1562
|
+
throwInvalidTypeError(this, exprA);
|
|
1563
|
+
} else if (this.getTypeName(exprB) !== requiredType) {
|
|
1564
|
+
throwInvalidTypeError(this, exprB);
|
|
1565
|
+
}
|
|
1566
|
+
if (requiredType === 2) {
|
|
1567
|
+
return Text.comparer(exprA, exprB);
|
|
1568
|
+
}
|
|
1569
|
+
return exprA - exprB;
|
|
1570
|
+
});
|
|
1571
|
+
};
|
|
1572
|
+
functionStartsWith = ([searchable, searchStr]) => {
|
|
1573
|
+
return searchable.startsWith(searchStr);
|
|
1574
|
+
};
|
|
1575
|
+
functionSum = ([inputValue]) => {
|
|
1576
|
+
return inputValue.reduce((x, y) => x + y, 0);
|
|
1577
|
+
};
|
|
1578
|
+
functionToArray = ([inputValue]) => {
|
|
1579
|
+
if (this.getTypeName(inputValue) === 3) {
|
|
1580
|
+
return inputValue;
|
|
1581
|
+
}
|
|
1582
|
+
return [inputValue];
|
|
1583
|
+
};
|
|
1584
|
+
functionToNumber = ([inputValue]) => {
|
|
1585
|
+
const typeName = this.getTypeName(inputValue);
|
|
1586
|
+
let convertedValue;
|
|
1587
|
+
if (typeName === 0) {
|
|
1588
|
+
return inputValue;
|
|
1589
|
+
}
|
|
1590
|
+
if (typeName === 2) {
|
|
1591
|
+
convertedValue = +inputValue;
|
|
1592
|
+
if (!isNaN(convertedValue)) {
|
|
1593
|
+
return convertedValue;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
return null;
|
|
1597
|
+
};
|
|
1598
|
+
functionToString = ([inputValue]) => {
|
|
1599
|
+
if (this.getTypeName(inputValue) === 2) {
|
|
1600
|
+
return inputValue;
|
|
1601
|
+
}
|
|
1602
|
+
return JSON.stringify(inputValue);
|
|
1603
|
+
};
|
|
1604
|
+
functionTrim = this.createTrimFunction(trim);
|
|
1605
|
+
functionTrimLeft = this.createTrimFunction(trimLeft);
|
|
1606
|
+
functionTrimRight = this.createTrimFunction(trimRight);
|
|
1607
|
+
createTrimFunction(trimFn) {
|
|
1608
|
+
return (resolvedArgs) => {
|
|
1609
|
+
const subject = resolvedArgs[0];
|
|
1610
|
+
const chars = resolvedArgs.length > 1 ? resolvedArgs[1] : undefined;
|
|
1611
|
+
return trimFn(subject, chars);
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
functionType = ([inputValue]) => {
|
|
1615
|
+
switch (this.getTypeName(inputValue)) {
|
|
1616
|
+
case 0:
|
|
1617
|
+
return "number";
|
|
1618
|
+
case 2:
|
|
1619
|
+
return "string";
|
|
1620
|
+
case 3:
|
|
1621
|
+
return "array";
|
|
1622
|
+
case 4:
|
|
1623
|
+
return "object";
|
|
1624
|
+
case 5:
|
|
1625
|
+
return "boolean";
|
|
1626
|
+
case 7:
|
|
1627
|
+
return "null";
|
|
1628
|
+
default:
|
|
1629
|
+
throw new Error("invalid-type");
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
functionZip = (array) => {
|
|
1633
|
+
const length = Math.min(...array.map((arr) => arr.length));
|
|
1634
|
+
const result = Array(length).fill(null).map((_, index) => array.map((arr) => arr[index]));
|
|
1635
|
+
return result;
|
|
1636
|
+
};
|
|
1637
|
+
};
|
|
1638
|
+
var ScopeChain = class _ScopeChain {
|
|
1639
|
+
inner = undefined;
|
|
1640
|
+
data = {};
|
|
1641
|
+
get currentScopeData() {
|
|
1642
|
+
return this.data;
|
|
1643
|
+
}
|
|
1644
|
+
withScope(data) {
|
|
1645
|
+
const outer = new _ScopeChain;
|
|
1646
|
+
outer.inner = this;
|
|
1647
|
+
outer.data = data;
|
|
1648
|
+
return outer;
|
|
1649
|
+
}
|
|
1650
|
+
getValue(identifier) {
|
|
1651
|
+
if (Object.prototype.hasOwnProperty.call(this.data, identifier)) {
|
|
1652
|
+
return this.data[identifier];
|
|
1653
|
+
}
|
|
1654
|
+
if (this.inner) {
|
|
1655
|
+
return this.inner.getValue(identifier);
|
|
1656
|
+
}
|
|
1657
|
+
return null;
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
var emptyScopeChain = new ScopeChain;
|
|
1661
|
+
var TreeInterpreter = class _TreeInterpreter {
|
|
1662
|
+
runtime;
|
|
1663
|
+
_rootValue = null;
|
|
1664
|
+
_scope;
|
|
1665
|
+
constructor() {
|
|
1666
|
+
this.runtime = new Runtime(this);
|
|
1667
|
+
this._scope = new ScopeChain;
|
|
1668
|
+
}
|
|
1669
|
+
withScope(scope) {
|
|
1670
|
+
const interpreter = new _TreeInterpreter;
|
|
1671
|
+
interpreter.runtime._functionTable = this.runtime._functionTable;
|
|
1672
|
+
interpreter._rootValue = this._rootValue;
|
|
1673
|
+
interpreter._scope = this._scope.withScope(scope);
|
|
1674
|
+
return interpreter;
|
|
1675
|
+
}
|
|
1676
|
+
search(node, value) {
|
|
1677
|
+
this._rootValue = value;
|
|
1678
|
+
this._scope = emptyScopeChain;
|
|
1679
|
+
return this.visit(node, value);
|
|
1680
|
+
}
|
|
1681
|
+
visit(node, value) {
|
|
1682
|
+
switch (node.type) {
|
|
1683
|
+
case "Ternary": {
|
|
1684
|
+
const condition = this.visit(node.condition, value);
|
|
1685
|
+
if (!isFalse(condition)) {
|
|
1686
|
+
return this.visit(node.trueExpr, value);
|
|
1687
|
+
}
|
|
1688
|
+
return this.visit(node.falseExpr, value);
|
|
1689
|
+
}
|
|
1690
|
+
case "Field":
|
|
1691
|
+
const identifier = node.name;
|
|
1692
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
1693
|
+
return null;
|
|
1694
|
+
}
|
|
1695
|
+
return value[identifier] ?? null;
|
|
1696
|
+
case "LetExpression": {
|
|
1697
|
+
const { bindings, expression } = node;
|
|
1698
|
+
let scope = {};
|
|
1699
|
+
bindings.forEach((binding) => {
|
|
1700
|
+
const reference = this.visit(binding, value);
|
|
1701
|
+
scope = {
|
|
1702
|
+
...scope,
|
|
1703
|
+
...reference
|
|
1704
|
+
};
|
|
1705
|
+
});
|
|
1706
|
+
return this.withScope(scope).visit(expression, value);
|
|
1707
|
+
}
|
|
1708
|
+
case "Binding": {
|
|
1709
|
+
const { variable, reference } = node;
|
|
1710
|
+
const result = this.visit(reference, value);
|
|
1711
|
+
return { [variable]: result };
|
|
1712
|
+
}
|
|
1713
|
+
case "Variable": {
|
|
1714
|
+
const variable = node.name;
|
|
1715
|
+
if (!this._scope.getValue(variable) && !Object.prototype.hasOwnProperty.call(this._scope.currentScopeData, variable)) {
|
|
1716
|
+
throw new Error(`Error referencing undefined variable ${variable}`);
|
|
1717
|
+
}
|
|
1718
|
+
return this._scope.getValue(variable);
|
|
1719
|
+
}
|
|
1720
|
+
case "IndexExpression":
|
|
1721
|
+
return this.visit(node.right, this.visit(node.left, value));
|
|
1722
|
+
case "Subexpression": {
|
|
1723
|
+
const result = this.visit(node.left, value);
|
|
1724
|
+
return result != null ? this.visit(node.right, result) ?? null : null;
|
|
1725
|
+
}
|
|
1726
|
+
case "Index": {
|
|
1727
|
+
if (!Array.isArray(value)) {
|
|
1728
|
+
return null;
|
|
1729
|
+
}
|
|
1730
|
+
const index = node.value < 0 ? value.length + node.value : node.value;
|
|
1731
|
+
return value[index] ?? null;
|
|
1732
|
+
}
|
|
1733
|
+
case "Slice": {
|
|
1734
|
+
if (!Array.isArray(value) && typeof value !== "string") {
|
|
1735
|
+
return null;
|
|
1736
|
+
}
|
|
1737
|
+
const { start, stop, step } = this.computeSliceParams(value.length, node);
|
|
1738
|
+
if (typeof value === "string") {
|
|
1739
|
+
const chars = [...value];
|
|
1740
|
+
const sliced = this.slice(chars, start, stop, step);
|
|
1741
|
+
return sliced.join("");
|
|
1742
|
+
} else {
|
|
1743
|
+
return this.slice(value, start, stop, step);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
case "Projection": {
|
|
1747
|
+
const { left, right } = node;
|
|
1748
|
+
let allowString = false;
|
|
1749
|
+
if (left.type === "IndexExpression" && left.right.type === "Slice") {
|
|
1750
|
+
allowString = true;
|
|
1751
|
+
}
|
|
1752
|
+
const base = this.visit(left, value);
|
|
1753
|
+
if (allowString && typeof base === "string") {
|
|
1754
|
+
return this.visit(right, base);
|
|
1755
|
+
}
|
|
1756
|
+
if (!Array.isArray(base)) {
|
|
1757
|
+
return null;
|
|
1758
|
+
}
|
|
1759
|
+
const collected = [];
|
|
1760
|
+
for (const elem of base) {
|
|
1761
|
+
const current = this.visit(right, elem);
|
|
1762
|
+
if (current !== null) {
|
|
1763
|
+
collected.push(current);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
return collected;
|
|
1767
|
+
}
|
|
1768
|
+
case "ValueProjection": {
|
|
1769
|
+
const { left, right } = node;
|
|
1770
|
+
const base = this.visit(left, value);
|
|
1771
|
+
if (base === null || typeof base !== "object" || Array.isArray(base)) {
|
|
1772
|
+
return null;
|
|
1773
|
+
}
|
|
1774
|
+
const collected = [];
|
|
1775
|
+
const values = Object.values(base);
|
|
1776
|
+
for (const elem of values) {
|
|
1777
|
+
const current = this.visit(right, elem);
|
|
1778
|
+
if (current !== null) {
|
|
1779
|
+
collected.push(current);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
return collected;
|
|
1783
|
+
}
|
|
1784
|
+
case "FilterProjection": {
|
|
1785
|
+
const { left, right, condition } = node;
|
|
1786
|
+
const base = this.visit(left, value);
|
|
1787
|
+
if (!Array.isArray(base)) {
|
|
1788
|
+
return null;
|
|
1789
|
+
}
|
|
1790
|
+
const results = [];
|
|
1791
|
+
for (const elem of base) {
|
|
1792
|
+
const matched = this.visit(condition, elem);
|
|
1793
|
+
if (isFalse(matched)) {
|
|
1794
|
+
continue;
|
|
1795
|
+
}
|
|
1796
|
+
const result = this.visit(right, elem);
|
|
1797
|
+
if (result !== null) {
|
|
1798
|
+
results.push(result);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return results;
|
|
1802
|
+
}
|
|
1803
|
+
case "Arithmetic": {
|
|
1804
|
+
const first = this.visit(node.left, value);
|
|
1805
|
+
const second = this.visit(node.right, value);
|
|
1806
|
+
switch (node.operator) {
|
|
1807
|
+
case "Plus":
|
|
1808
|
+
return add(first, second);
|
|
1809
|
+
case "Minus":
|
|
1810
|
+
return sub(first, second);
|
|
1811
|
+
case "Multiply":
|
|
1812
|
+
case "Star":
|
|
1813
|
+
return mul(first, second);
|
|
1814
|
+
case "Divide":
|
|
1815
|
+
return divide(first, second);
|
|
1816
|
+
case "Modulo":
|
|
1817
|
+
return mod(first, second);
|
|
1818
|
+
case "Div":
|
|
1819
|
+
return div(first, second);
|
|
1820
|
+
default:
|
|
1821
|
+
throw new Error(`Syntax error: unknown arithmetic operator: ${node.operator}`);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
case "Unary": {
|
|
1825
|
+
const operand = this.visit(node.operand, value);
|
|
1826
|
+
switch (node.operator) {
|
|
1827
|
+
case "Plus":
|
|
1828
|
+
ensureNumbers(operand);
|
|
1829
|
+
return operand;
|
|
1830
|
+
case "Minus":
|
|
1831
|
+
ensureNumbers(operand);
|
|
1832
|
+
return -operand;
|
|
1833
|
+
default:
|
|
1834
|
+
throw new Error(`Syntax error: unknown arithmetic operator: ${node.operator}`);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
case "Comparator": {
|
|
1838
|
+
const first = this.visit(node.left, value);
|
|
1839
|
+
const second = this.visit(node.right, value);
|
|
1840
|
+
switch (node.name) {
|
|
1841
|
+
case "EQ":
|
|
1842
|
+
return strictDeepEqual(first, second);
|
|
1843
|
+
case "NE":
|
|
1844
|
+
return !strictDeepEqual(first, second);
|
|
1845
|
+
}
|
|
1846
|
+
if (typeof first !== "number" || typeof second !== "number") {
|
|
1847
|
+
return null;
|
|
1848
|
+
}
|
|
1849
|
+
switch (node.name) {
|
|
1850
|
+
case "GT":
|
|
1851
|
+
return first > second;
|
|
1852
|
+
case "GTE":
|
|
1853
|
+
return first >= second;
|
|
1854
|
+
case "LT":
|
|
1855
|
+
return first < second;
|
|
1856
|
+
case "LTE":
|
|
1857
|
+
return first <= second;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
case "Flatten": {
|
|
1861
|
+
const original = this.visit(node.child, value);
|
|
1862
|
+
return Array.isArray(original) ? original.flat() : null;
|
|
1863
|
+
}
|
|
1864
|
+
case "Root":
|
|
1865
|
+
return this._rootValue;
|
|
1866
|
+
case "MultiSelectList": {
|
|
1867
|
+
const collected = [];
|
|
1868
|
+
for (const child of node.children) {
|
|
1869
|
+
collected.push(this.visit(child, value));
|
|
1870
|
+
}
|
|
1871
|
+
return collected;
|
|
1872
|
+
}
|
|
1873
|
+
case "MultiSelectHash": {
|
|
1874
|
+
const collected = {};
|
|
1875
|
+
for (const child of node.children) {
|
|
1876
|
+
collected[child.name] = this.visit(child.value, value);
|
|
1877
|
+
}
|
|
1878
|
+
return collected;
|
|
1879
|
+
}
|
|
1880
|
+
case "OrExpression": {
|
|
1881
|
+
const result = this.visit(node.left, value);
|
|
1882
|
+
if (isFalse(result)) {
|
|
1883
|
+
return this.visit(node.right, value);
|
|
1884
|
+
}
|
|
1885
|
+
return result;
|
|
1886
|
+
}
|
|
1887
|
+
case "AndExpression": {
|
|
1888
|
+
const result = this.visit(node.left, value);
|
|
1889
|
+
if (isFalse(result)) {
|
|
1890
|
+
return result;
|
|
1891
|
+
}
|
|
1892
|
+
return this.visit(node.right, value);
|
|
1893
|
+
}
|
|
1894
|
+
case "NotExpression":
|
|
1895
|
+
return isFalse(this.visit(node.child, value));
|
|
1896
|
+
case "Literal":
|
|
1897
|
+
return node.value;
|
|
1898
|
+
case "Pipe":
|
|
1899
|
+
return this.visit(node.right, this.visit(node.left, value));
|
|
1900
|
+
case "Function": {
|
|
1901
|
+
const args = [];
|
|
1902
|
+
for (const child of node.children) {
|
|
1903
|
+
args.push(this.visit(child, value));
|
|
1904
|
+
}
|
|
1905
|
+
return this.runtime.callFunction(node.name, args);
|
|
1906
|
+
}
|
|
1907
|
+
case "ExpressionReference":
|
|
1908
|
+
return {
|
|
1909
|
+
expref: true,
|
|
1910
|
+
...node.child
|
|
1911
|
+
};
|
|
1912
|
+
case "Current":
|
|
1913
|
+
case "Identity":
|
|
1914
|
+
return value;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
computeSliceParams(arrayLength, sliceNode) {
|
|
1918
|
+
let { start, stop, step } = sliceNode;
|
|
1919
|
+
if (step === null) {
|
|
1920
|
+
step = 1;
|
|
1921
|
+
} else if (step === 0) {
|
|
1922
|
+
const error = new Error("Invalid value: slice step cannot be 0");
|
|
1923
|
+
error.name = "RuntimeError";
|
|
1924
|
+
throw error;
|
|
1925
|
+
}
|
|
1926
|
+
start = start === null ? step < 0 ? arrayLength - 1 : 0 : this.capSliceRange(arrayLength, start, step);
|
|
1927
|
+
stop = stop === null ? step < 0 ? -1 : arrayLength : this.capSliceRange(arrayLength, stop, step);
|
|
1928
|
+
return { start, stop, step };
|
|
1929
|
+
}
|
|
1930
|
+
capSliceRange(arrayLength, actualValue, step) {
|
|
1931
|
+
let nextActualValue = actualValue;
|
|
1932
|
+
if (nextActualValue < 0) {
|
|
1933
|
+
nextActualValue += arrayLength;
|
|
1934
|
+
if (nextActualValue < 0) {
|
|
1935
|
+
nextActualValue = step < 0 ? -1 : 0;
|
|
1936
|
+
}
|
|
1937
|
+
} else if (nextActualValue >= arrayLength) {
|
|
1938
|
+
nextActualValue = step < 0 ? arrayLength - 1 : arrayLength;
|
|
1939
|
+
}
|
|
1940
|
+
return nextActualValue;
|
|
1941
|
+
}
|
|
1942
|
+
slice(collection, start, end, step) {
|
|
1943
|
+
const result = [];
|
|
1944
|
+
if (step > 0) {
|
|
1945
|
+
for (let i = start;i < end; i += step) {
|
|
1946
|
+
result.push(collection[i]);
|
|
1947
|
+
}
|
|
1948
|
+
} else {
|
|
1949
|
+
for (let i = start;i > end; i += step) {
|
|
1950
|
+
result.push(collection[i]);
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
return result;
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
var TreeInterpreterInstance = new TreeInterpreter;
|
|
1957
|
+
var TreeInterpreter_default = TreeInterpreterInstance;
|
|
1958
|
+
var TYPE_ANY = 1;
|
|
1959
|
+
var TYPE_ARRAY = 3;
|
|
1960
|
+
var TYPE_ARRAY_ARRAY = 11;
|
|
1961
|
+
var TYPE_ARRAY_NUMBER = 8;
|
|
1962
|
+
var TYPE_ARRAY_OBJECT = 10;
|
|
1963
|
+
var TYPE_ARRAY_STRING = 9;
|
|
1964
|
+
var TYPE_BOOLEAN = 5;
|
|
1965
|
+
var TYPE_EXPREF = 6;
|
|
1966
|
+
var TYPE_NULL = 7;
|
|
1967
|
+
var TYPE_NUMBER = 0;
|
|
1968
|
+
var TYPE_OBJECT = 4;
|
|
1969
|
+
var TYPE_STRING = 2;
|
|
1970
|
+
function compile(expression, options) {
|
|
1971
|
+
const nodeTree = Parser_default.parse(expression, options);
|
|
1972
|
+
return nodeTree;
|
|
1973
|
+
}
|
|
1974
|
+
function tokenize(expression, options) {
|
|
1975
|
+
return Lexer_default.tokenize(expression, options);
|
|
1976
|
+
}
|
|
1977
|
+
var registerFunction = (functionName, customFunction, signature, options) => {
|
|
1978
|
+
TreeInterpreter_default.runtime.registerFunction(functionName, customFunction, signature, options);
|
|
1979
|
+
};
|
|
1980
|
+
var register = (name, customFunction, signature, options) => {
|
|
1981
|
+
return TreeInterpreter_default.runtime.register(name, customFunction, signature, options);
|
|
1982
|
+
};
|
|
1983
|
+
var unregisterFunction = (name) => {
|
|
1984
|
+
return TreeInterpreter_default.runtime.unregister(name);
|
|
1985
|
+
};
|
|
1986
|
+
var isRegistered = (name) => {
|
|
1987
|
+
return TreeInterpreter_default.runtime.isRegistered(name);
|
|
1988
|
+
};
|
|
1989
|
+
var getRegisteredFunctions = () => {
|
|
1990
|
+
return TreeInterpreter_default.runtime.getRegistered();
|
|
1991
|
+
};
|
|
1992
|
+
var getCustomFunctions = () => {
|
|
1993
|
+
return TreeInterpreter_default.runtime.getCustomFunctions();
|
|
1994
|
+
};
|
|
1995
|
+
var clearCustomFunctions = () => {
|
|
1996
|
+
TreeInterpreter_default.runtime.clearCustomFunctions();
|
|
1997
|
+
};
|
|
1998
|
+
function search(data, expression, options) {
|
|
1999
|
+
const nodeTree = Parser_default.parse(expression, options);
|
|
2000
|
+
return TreeInterpreter_default.search(nodeTree, data);
|
|
2001
|
+
}
|
|
2002
|
+
function Scope() {
|
|
2003
|
+
return new ScopeChain;
|
|
2004
|
+
}
|
|
2005
|
+
var TreeInterpreter2 = TreeInterpreter_default;
|
|
2006
|
+
var jmespath = {
|
|
2007
|
+
compile,
|
|
2008
|
+
registerFunction,
|
|
2009
|
+
register,
|
|
2010
|
+
unregisterFunction,
|
|
2011
|
+
isRegistered,
|
|
2012
|
+
getRegisteredFunctions,
|
|
2013
|
+
getCustomFunctions,
|
|
2014
|
+
clearCustomFunctions,
|
|
2015
|
+
search,
|
|
2016
|
+
tokenize,
|
|
2017
|
+
TreeInterpreter: TreeInterpreter2,
|
|
2018
|
+
TYPE_ANY,
|
|
2019
|
+
TYPE_ARRAY_NUMBER,
|
|
2020
|
+
TYPE_ARRAY_STRING,
|
|
2021
|
+
TYPE_ARRAY,
|
|
2022
|
+
TYPE_BOOLEAN,
|
|
2023
|
+
TYPE_EXPREF,
|
|
2024
|
+
TYPE_NULL,
|
|
2025
|
+
TYPE_NUMBER,
|
|
2026
|
+
TYPE_OBJECT,
|
|
2027
|
+
TYPE_STRING
|
|
2028
|
+
};
|
|
2029
|
+
export {
|
|
2030
|
+
unregisterFunction,
|
|
2031
|
+
tokenize,
|
|
2032
|
+
search,
|
|
2033
|
+
registerFunction,
|
|
2034
|
+
register,
|
|
2035
|
+
jmespath,
|
|
2036
|
+
isRegistered,
|
|
2037
|
+
getRegisteredFunctions,
|
|
2038
|
+
getCustomFunctions,
|
|
2039
|
+
jmespath as default,
|
|
2040
|
+
compile,
|
|
2041
|
+
clearCustomFunctions,
|
|
2042
|
+
TreeInterpreter2 as TreeInterpreter,
|
|
2043
|
+
TYPE_STRING,
|
|
2044
|
+
TYPE_OBJECT,
|
|
2045
|
+
TYPE_NUMBER,
|
|
2046
|
+
TYPE_NULL,
|
|
2047
|
+
TYPE_EXPREF,
|
|
2048
|
+
TYPE_BOOLEAN,
|
|
2049
|
+
TYPE_ARRAY_STRING,
|
|
2050
|
+
TYPE_ARRAY_OBJECT,
|
|
2051
|
+
TYPE_ARRAY_NUMBER,
|
|
2052
|
+
TYPE_ARRAY_ARRAY,
|
|
2053
|
+
TYPE_ARRAY,
|
|
2054
|
+
TYPE_ANY,
|
|
2055
|
+
Scope
|
|
2056
|
+
};
|
|
2057
|
+
|
|
2058
|
+
//# debugId=FA9FB28BF9A093C864756E2164756E21
|