@jmespath-community/jmespath 1.1.0 → 1.1.2
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/jmespath.esm.js +128 -56
- package/dist/jmespath.esm.min.js +1 -1
- package/dist/jmespath.esm.min.js.map +1 -1
- package/dist/jmespath.umd.js +128 -56
- package/dist/jmespath.umd.min.js +1 -1
- package/dist/jmespath.umd.min.js.map +1 -1
- package/dist/lib/Lexer.js +22 -7
- package/dist/lib/Lexer.js.map +1 -1
- package/dist/lib/Lexer.type.js +2 -0
- package/dist/lib/Lexer.type.js.map +1 -1
- package/dist/lib/Parser.js +68 -21
- package/dist/lib/Parser.js.map +1 -1
- package/dist/lib/Runtime.js +1 -12
- package/dist/lib/Runtime.js.map +1 -1
- package/dist/lib/Scope.js +1 -1
- package/dist/lib/Scope.js.map +1 -1
- package/dist/lib/TreeInterpreter.js +30 -10
- package/dist/lib/TreeInterpreter.js.map +1 -1
- package/dist/lib/utils/strings.js +1 -4
- package/dist/lib/utils/strings.js.map +1 -1
- package/dist/lib/utils/text.js +3 -2
- package/dist/lib/utils/text.js.map +1 -1
- package/dist/types/AST.type.d.ts +15 -2
- package/dist/types/Lexer.type.d.ts +2 -0
- package/dist/types/Parser.d.ts +5 -0
- package/dist/types/Parser.type.d.ts +3 -1
- package/dist/types/Runtime.d.ts +0 -1
- package/dist/types/TreeInterpreter.d.ts +3 -2
- package/dist/types/utils/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/jmespath.umd.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
var Token;
|
|
8
8
|
(function (Token) {
|
|
9
9
|
Token["TOK_EOF"] = "EOF";
|
|
10
|
+
Token["TOK_VARIABLE"] = "Variable";
|
|
11
|
+
Token["TOK_ASSIGN"] = "Assign";
|
|
10
12
|
Token["TOK_UNQUOTEDIDENTIFIER"] = "UnquotedIdentifier";
|
|
11
13
|
Token["TOK_QUOTEDIDENTIFIER"] = "QuotedIdentifier";
|
|
12
14
|
Token["TOK_RBRACKET"] = "Rbracket";
|
|
@@ -178,7 +180,6 @@
|
|
|
178
180
|
'.': Token.TOK_DOT,
|
|
179
181
|
':': Token.TOK_COLON,
|
|
180
182
|
'@': Token.TOK_CURRENT,
|
|
181
|
-
['$']: Token.TOK_ROOT,
|
|
182
183
|
']': Token.TOK_RBRACKET,
|
|
183
184
|
'{': Token.TOK_LBRACE,
|
|
184
185
|
'}': Token.TOK_RBRACE,
|
|
@@ -233,6 +234,26 @@
|
|
|
233
234
|
});
|
|
234
235
|
this._current += 1;
|
|
235
236
|
}
|
|
237
|
+
else if (stream[this._current] === '$') {
|
|
238
|
+
start = this._current;
|
|
239
|
+
if (this._current + 1 < stream.length && isAlpha(stream[this._current + 1])) {
|
|
240
|
+
this._current += 1;
|
|
241
|
+
identifier = this.consumeUnquotedIdentifier(stream);
|
|
242
|
+
tokens.push({
|
|
243
|
+
start,
|
|
244
|
+
type: Token.TOK_VARIABLE,
|
|
245
|
+
value: identifier,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
tokens.push({
|
|
250
|
+
start: start,
|
|
251
|
+
type: Token.TOK_ROOT,
|
|
252
|
+
value: stream[this._current],
|
|
253
|
+
});
|
|
254
|
+
this._current += 1;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
236
257
|
else if (stream[this._current] === '-') {
|
|
237
258
|
if (this._current + 1 < stream.length && isNum(stream[this._current + 1])) {
|
|
238
259
|
const token = this.consumeNumber(stream);
|
|
@@ -377,11 +398,6 @@
|
|
|
377
398
|
this._current += 1;
|
|
378
399
|
return { start: start, type: orElse, value: stream.slice(start, this._current) };
|
|
379
400
|
}
|
|
380
|
-
if (token === Token.TOK_EOF) {
|
|
381
|
-
const error = new Error(`syntax: unknown incomplete token: ${stream[start]}`);
|
|
382
|
-
error.name = 'LexerError';
|
|
383
|
-
throw error;
|
|
384
|
-
}
|
|
385
401
|
return { start: start, type: token, value: stream[start] };
|
|
386
402
|
}
|
|
387
403
|
consumeOperator(stream) {
|
|
@@ -395,7 +411,7 @@
|
|
|
395
411
|
case '>':
|
|
396
412
|
return this.consumeOrElse(stream, '=', Token.TOK_GT, Token.TOK_GTE);
|
|
397
413
|
case '=':
|
|
398
|
-
return this.consumeOrElse(stream, '=', Token.
|
|
414
|
+
return this.consumeOrElse(stream, '=', Token.TOK_ASSIGN, Token.TOK_EQ);
|
|
399
415
|
case '&':
|
|
400
416
|
return this.consumeOrElse(stream, '&', Token.TOK_EXPREF, Token.TOK_AND);
|
|
401
417
|
case '|':
|
|
@@ -453,6 +469,7 @@
|
|
|
453
469
|
return true;
|
|
454
470
|
}
|
|
455
471
|
if (numberLooking.includes(literalString[0])) {
|
|
472
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
456
473
|
const [_, ok] = this.parseJSON(literalString);
|
|
457
474
|
return ok;
|
|
458
475
|
}
|
|
@@ -472,6 +489,7 @@
|
|
|
472
489
|
|
|
473
490
|
const bindingPower = {
|
|
474
491
|
[Token.TOK_EOF]: 0,
|
|
492
|
+
[Token.TOK_VARIABLE]: 0,
|
|
475
493
|
[Token.TOK_UNQUOTEDIDENTIFIER]: 0,
|
|
476
494
|
[Token.TOK_QUOTEDIDENTIFIER]: 0,
|
|
477
495
|
[Token.TOK_RBRACKET]: 0,
|
|
@@ -482,6 +500,7 @@
|
|
|
482
500
|
[Token.TOK_CURRENT]: 0,
|
|
483
501
|
[Token.TOK_EXPREF]: 0,
|
|
484
502
|
[Token.TOK_ROOT]: 0,
|
|
503
|
+
[Token.TOK_ASSIGN]: 1,
|
|
485
504
|
[Token.TOK_PIPE]: 1,
|
|
486
505
|
[Token.TOK_OR]: 2,
|
|
487
506
|
[Token.TOK_AND]: 3,
|
|
@@ -512,7 +531,7 @@
|
|
|
512
531
|
this.tokens = [];
|
|
513
532
|
}
|
|
514
533
|
parse(expression, options) {
|
|
515
|
-
this.loadTokens(expression, options || { enable_legacy_literals: false
|
|
534
|
+
this.loadTokens(expression, options || { enable_legacy_literals: false });
|
|
516
535
|
this.index = 0;
|
|
517
536
|
const ast = this.expression(0);
|
|
518
537
|
if (this.lookahead(0) !== Token.TOK_EOF) {
|
|
@@ -522,7 +541,10 @@
|
|
|
522
541
|
return ast;
|
|
523
542
|
}
|
|
524
543
|
loadTokens(expression, options) {
|
|
525
|
-
this.tokens = [
|
|
544
|
+
this.tokens = [
|
|
545
|
+
...Lexer.tokenize(expression, options),
|
|
546
|
+
{ type: Token.TOK_EOF, value: '', start: expression.length },
|
|
547
|
+
];
|
|
526
548
|
}
|
|
527
549
|
expression(rbp) {
|
|
528
550
|
const leftToken = this.lookaheadToken(0);
|
|
@@ -547,10 +569,18 @@
|
|
|
547
569
|
}
|
|
548
570
|
nud(token) {
|
|
549
571
|
switch (token.type) {
|
|
572
|
+
case Token.TOK_VARIABLE:
|
|
573
|
+
return { type: 'Variable', name: token.value };
|
|
550
574
|
case Token.TOK_LITERAL:
|
|
551
575
|
return { type: 'Literal', value: token.value };
|
|
552
|
-
case Token.TOK_UNQUOTEDIDENTIFIER:
|
|
553
|
-
|
|
576
|
+
case Token.TOK_UNQUOTEDIDENTIFIER: {
|
|
577
|
+
if (TokenParser.isKeyword(token, 'let') && this.lookahead(0) === Token.TOK_VARIABLE) {
|
|
578
|
+
return this.parseLetExpression();
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
return { type: 'Field', name: token.value };
|
|
582
|
+
}
|
|
583
|
+
}
|
|
554
584
|
case Token.TOK_QUOTEDIDENTIFIER:
|
|
555
585
|
if (this.lookahead(0) === Token.TOK_LPAREN) {
|
|
556
586
|
throw new Error('Syntax error: quoted identifier not allowed for function names.');
|
|
@@ -658,22 +688,7 @@
|
|
|
658
688
|
throw new Error('Syntax error: expected a Field node');
|
|
659
689
|
}
|
|
660
690
|
const name = left.name;
|
|
661
|
-
const args =
|
|
662
|
-
let expression;
|
|
663
|
-
while (this.lookahead(0) !== Token.TOK_RPAREN) {
|
|
664
|
-
if (this.lookahead(0) === Token.TOK_CURRENT) {
|
|
665
|
-
expression = { type: Token.TOK_CURRENT };
|
|
666
|
-
this.advance();
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
expression = this.expression(0);
|
|
670
|
-
}
|
|
671
|
-
if (this.lookahead(0) === Token.TOK_COMMA) {
|
|
672
|
-
this.match(Token.TOK_COMMA);
|
|
673
|
-
}
|
|
674
|
-
args.push(expression);
|
|
675
|
-
}
|
|
676
|
-
this.match(Token.TOK_RPAREN);
|
|
691
|
+
const args = this.parseCommaSeparatedExpressionsUntilToken(Token.TOK_RPAREN);
|
|
677
692
|
const node = { name, type: 'Function', children: args };
|
|
678
693
|
return node;
|
|
679
694
|
}
|
|
@@ -688,6 +703,15 @@
|
|
|
688
703
|
const right = this.parseProjectionRHS(bindingPower.Flatten);
|
|
689
704
|
return { type: 'Projection', left: leftNode, right };
|
|
690
705
|
}
|
|
706
|
+
case Token.TOK_ASSIGN: {
|
|
707
|
+
const leftNode = left;
|
|
708
|
+
const right = this.expression(0);
|
|
709
|
+
return {
|
|
710
|
+
type: 'Binding',
|
|
711
|
+
variable: leftNode.name,
|
|
712
|
+
reference: right,
|
|
713
|
+
};
|
|
714
|
+
}
|
|
691
715
|
case Token.TOK_EQ:
|
|
692
716
|
case Token.TOK_NE:
|
|
693
717
|
case Token.TOK_GT:
|
|
@@ -718,6 +742,9 @@
|
|
|
718
742
|
return this.errorToken(this.lookaheadToken(0));
|
|
719
743
|
}
|
|
720
744
|
}
|
|
745
|
+
static isKeyword(token, keyword) {
|
|
746
|
+
return token.type === Token.TOK_UNQUOTEDIDENTIFIER && token.value === keyword;
|
|
747
|
+
}
|
|
721
748
|
match(tokenType) {
|
|
722
749
|
if (this.lookahead(0) === tokenType) {
|
|
723
750
|
this.advance();
|
|
@@ -777,9 +804,46 @@
|
|
|
777
804
|
current = this.lookaheadToken(0);
|
|
778
805
|
}
|
|
779
806
|
this.match(Token.TOK_RBRACKET);
|
|
780
|
-
const [start
|
|
807
|
+
const [start, stop, step] = parts;
|
|
781
808
|
return { type: 'Slice', start, stop, step };
|
|
782
809
|
}
|
|
810
|
+
parseLetExpression() {
|
|
811
|
+
const separated = this.parseCommaSeparatedExpressionsUntilKeyword('in');
|
|
812
|
+
const expression = this.expression(0);
|
|
813
|
+
const bindings = separated.map(binding => binding);
|
|
814
|
+
return {
|
|
815
|
+
type: 'LetExpression',
|
|
816
|
+
bindings: bindings,
|
|
817
|
+
expression: expression,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
parseCommaSeparatedExpressionsUntilKeyword(keyword) {
|
|
821
|
+
return this.parseCommaSeparatedExpressionsUntil(() => {
|
|
822
|
+
return TokenParser.isKeyword(this.lookaheadToken(0), keyword);
|
|
823
|
+
}, () => {
|
|
824
|
+
this.advance();
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
parseCommaSeparatedExpressionsUntilToken(token) {
|
|
828
|
+
return this.parseCommaSeparatedExpressionsUntil(() => {
|
|
829
|
+
return this.lookahead(0) === token;
|
|
830
|
+
}, () => {
|
|
831
|
+
return this.match(token);
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
parseCommaSeparatedExpressionsUntil(isEndToken, matchEndToken) {
|
|
835
|
+
const args = [];
|
|
836
|
+
let expression;
|
|
837
|
+
while (!isEndToken()) {
|
|
838
|
+
expression = this.expression(0);
|
|
839
|
+
if (this.lookahead(0) === Token.TOK_COMMA) {
|
|
840
|
+
this.match(Token.TOK_COMMA);
|
|
841
|
+
}
|
|
842
|
+
args.push(expression);
|
|
843
|
+
}
|
|
844
|
+
matchEndToken();
|
|
845
|
+
return args;
|
|
846
|
+
}
|
|
783
847
|
parseComparator(left, comparator) {
|
|
784
848
|
const right = this.expression(bindingPower[comparator]);
|
|
785
849
|
return { type: 'Comparator', name: comparator, left, right };
|
|
@@ -893,14 +957,15 @@
|
|
|
893
957
|
if (leftCp[index] === rightCp[index]) {
|
|
894
958
|
continue;
|
|
895
959
|
}
|
|
896
|
-
return
|
|
960
|
+
return leftCp[index] - rightCp[index] > 0 ? 1 : -1;
|
|
897
961
|
}
|
|
898
|
-
return
|
|
962
|
+
return leftCp.length - rightCp.length > 0 ? 1 : -1;
|
|
899
963
|
}
|
|
900
964
|
reverse() {
|
|
901
965
|
return String.fromCodePoint(...this.codePoints.reverse());
|
|
902
966
|
}
|
|
903
967
|
get codePoints() {
|
|
968
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
904
969
|
const array = [...this._text].map(s => s.codePointAt(0));
|
|
905
970
|
return array;
|
|
906
971
|
}
|
|
@@ -966,10 +1031,7 @@
|
|
|
966
1031
|
return [subject];
|
|
967
1032
|
}
|
|
968
1033
|
const split = subject.split(search);
|
|
969
|
-
return [
|
|
970
|
-
...split.slice(0, count),
|
|
971
|
-
split.slice(count).join(search)
|
|
972
|
-
];
|
|
1034
|
+
return [...split.slice(0, count), split.slice(count).join(search)];
|
|
973
1035
|
};
|
|
974
1036
|
const trim = (subject, chars) => {
|
|
975
1037
|
return trimLeft(trimRight(subject, chars), chars);
|
|
@@ -1103,11 +1165,6 @@
|
|
|
1103
1165
|
}
|
|
1104
1166
|
return Object.keys(inputValue).length;
|
|
1105
1167
|
};
|
|
1106
|
-
this.functionLet = ([inputScope, exprefNode]) => {
|
|
1107
|
-
var _a;
|
|
1108
|
-
const interpreter = (_a = this._interpreter) === null || _a === void 0 ? void 0 : _a.withScope(inputScope);
|
|
1109
|
-
return interpreter.visit(exprefNode, exprefNode.context);
|
|
1110
|
-
};
|
|
1111
1168
|
this.functionLower = ([subject]) => {
|
|
1112
1169
|
return lower(subject);
|
|
1113
1170
|
};
|
|
@@ -1230,8 +1287,7 @@
|
|
|
1230
1287
|
this.functionReverse = ([inputValue]) => {
|
|
1231
1288
|
const typeName = this.getTypeName(inputValue);
|
|
1232
1289
|
if (typeName === InputArgument.TYPE_STRING) {
|
|
1233
|
-
return new Text(inputValue)
|
|
1234
|
-
.reverse();
|
|
1290
|
+
return new Text(inputValue).reverse();
|
|
1235
1291
|
}
|
|
1236
1292
|
const reversedArray = inputValue.slice(0);
|
|
1237
1293
|
reversedArray.reverse();
|
|
@@ -1482,10 +1538,6 @@
|
|
|
1482
1538
|
},
|
|
1483
1539
|
],
|
|
1484
1540
|
},
|
|
1485
|
-
let: {
|
|
1486
|
-
_func: this.functionLet,
|
|
1487
|
-
_signature: [{ types: [InputArgument.TYPE_OBJECT] }, { types: [InputArgument.TYPE_EXPREF] }],
|
|
1488
|
-
},
|
|
1489
1541
|
length: {
|
|
1490
1542
|
_func: this.functionLength,
|
|
1491
1543
|
_signature: [
|
|
@@ -1927,7 +1979,7 @@
|
|
|
1927
1979
|
getValue(identifier) {
|
|
1928
1980
|
if (identifier in this.data) {
|
|
1929
1981
|
const result = this.data[identifier];
|
|
1930
|
-
if (result) {
|
|
1982
|
+
if (result !== null && result !== undefined) {
|
|
1931
1983
|
return result;
|
|
1932
1984
|
}
|
|
1933
1985
|
}
|
|
@@ -1941,14 +1993,13 @@
|
|
|
1941
1993
|
class TreeInterpreter$1 {
|
|
1942
1994
|
constructor() {
|
|
1943
1995
|
this._rootValue = null;
|
|
1944
|
-
this._scope = undefined;
|
|
1945
1996
|
this.runtime = new Runtime(this);
|
|
1997
|
+
this._scope = new ScopeChain();
|
|
1946
1998
|
}
|
|
1947
1999
|
withScope(scope) {
|
|
1948
|
-
var _a;
|
|
1949
2000
|
const interpreter = new TreeInterpreter$1();
|
|
1950
2001
|
interpreter._rootValue = this._rootValue;
|
|
1951
|
-
interpreter._scope =
|
|
2002
|
+
interpreter._scope = this._scope.withScope(scope);
|
|
1952
2003
|
return interpreter;
|
|
1953
2004
|
}
|
|
1954
2005
|
search(node, value) {
|
|
@@ -1957,7 +2008,7 @@
|
|
|
1957
2008
|
return this.visit(node, value);
|
|
1958
2009
|
}
|
|
1959
2010
|
visit(node, value) {
|
|
1960
|
-
var _a, _b, _c
|
|
2011
|
+
var _a, _b, _c;
|
|
1961
2012
|
switch (node.type) {
|
|
1962
2013
|
case 'Field':
|
|
1963
2014
|
const identifier = node.name;
|
|
@@ -1965,22 +2016,41 @@
|
|
|
1965
2016
|
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
1966
2017
|
result = (_a = value[identifier]) !== null && _a !== void 0 ? _a : null;
|
|
1967
2018
|
}
|
|
1968
|
-
|
|
1969
|
-
|
|
2019
|
+
return result;
|
|
2020
|
+
case 'LetExpression': {
|
|
2021
|
+
const { bindings, expression } = node;
|
|
2022
|
+
let scope = {};
|
|
2023
|
+
bindings.forEach(binding => {
|
|
2024
|
+
const reference = this.visit(binding, value);
|
|
2025
|
+
scope = Object.assign(Object.assign({}, scope), reference);
|
|
2026
|
+
});
|
|
2027
|
+
return this.withScope(scope).visit(expression, value);
|
|
2028
|
+
}
|
|
2029
|
+
case 'Binding': {
|
|
2030
|
+
const { variable, reference } = node;
|
|
2031
|
+
const result = this.visit(reference, value);
|
|
2032
|
+
return { [variable]: result };
|
|
2033
|
+
}
|
|
2034
|
+
case 'Variable': {
|
|
2035
|
+
const variable = node.name;
|
|
2036
|
+
const result = (_b = this._scope.getValue(variable)) !== null && _b !== void 0 ? _b : null;
|
|
2037
|
+
if (result === null || result === undefined) {
|
|
2038
|
+
throw new Error(`Error referencing undefined variable ${variable}`);
|
|
1970
2039
|
}
|
|
1971
2040
|
return result;
|
|
2041
|
+
}
|
|
1972
2042
|
case 'IndexExpression':
|
|
1973
2043
|
return this.visit(node.right, this.visit(node.left, value));
|
|
1974
2044
|
case 'Subexpression': {
|
|
1975
2045
|
const result = this.visit(node.left, value);
|
|
1976
|
-
return result != null && this.visit(node.right, result) || null;
|
|
2046
|
+
return (result != null && this.visit(node.right, result)) || null;
|
|
1977
2047
|
}
|
|
1978
2048
|
case 'Index': {
|
|
1979
2049
|
if (!Array.isArray(value)) {
|
|
1980
2050
|
return null;
|
|
1981
2051
|
}
|
|
1982
2052
|
const index = node.value < 0 ? value.length + node.value : node.value;
|
|
1983
|
-
return (
|
|
2053
|
+
return (_c = value[index]) !== null && _c !== void 0 ? _c : null;
|
|
1984
2054
|
}
|
|
1985
2055
|
case 'Slice': {
|
|
1986
2056
|
if (!Array.isArray(value) && typeof value !== 'string') {
|
|
@@ -2014,7 +2084,9 @@
|
|
|
2014
2084
|
}
|
|
2015
2085
|
const base = this.visit(left, value);
|
|
2016
2086
|
if (allowString && typeof base === 'string') {
|
|
2017
|
-
|
|
2087
|
+
// a projection is really a sub-expression in disguise
|
|
2088
|
+
// we must evaluate the right hand expression
|
|
2089
|
+
return this.visit(right, base);
|
|
2018
2090
|
}
|
|
2019
2091
|
if (!Array.isArray(base)) {
|
|
2020
2092
|
return null;
|
|
@@ -2170,7 +2242,7 @@
|
|
|
2170
2242
|
return this.runtime.callFunction(node.name, args);
|
|
2171
2243
|
}
|
|
2172
2244
|
case 'ExpressionReference':
|
|
2173
|
-
return Object.assign({ expref: true
|
|
2245
|
+
return Object.assign({ expref: true }, node.child);
|
|
2174
2246
|
case 'Current':
|
|
2175
2247
|
case 'Identity':
|
|
2176
2248
|
return value;
|
package/dist/jmespath.umd.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jmespath={})}(this,(function(t){"use strict";var e;!function(t){t.TOK_EOF="EOF",t.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",t.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",t.TOK_RBRACKET="Rbracket",t.TOK_RPAREN="Rparen",t.TOK_COMMA="Comma",t.TOK_COLON="Colon",t.TOK_RBRACE="Rbrace",t.TOK_NUMBER="Number",t.TOK_CURRENT="Current",t.TOK_ROOT="Root",t.TOK_EXPREF="Expref",t.TOK_PIPE="Pipe",t.TOK_OR="Or",t.TOK_AND="And",t.TOK_EQ="EQ",t.TOK_GT="GT",t.TOK_LT="LT",t.TOK_GTE="GTE",t.TOK_LTE="LTE",t.TOK_NE="NE",t.TOK_PLUS="Plus",t.TOK_MINUS="Minus",t.TOK_MULTIPLY="Multiply",t.TOK_DIVIDE="Divide",t.TOK_MODULO="Modulo",t.TOK_DIV="Div",t.TOK_FLATTEN="Flatten",t.TOK_STAR="Star",t.TOK_FILTER="Filter",t.TOK_DOT="Dot",t.TOK_NOT="Not",t.TOK_LBRACE="Lbrace",t.TOK_LBRACKET="Lbracket",t.TOK_LPAREN="Lparen",t.TOK_LITERAL="Literal"}(e||(e={}));const r=t=>null!==t&&"[object Object]"===Object.prototype.toString.call(t),n=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r+=1)if(!n(t[r],e[r]))return!1;return!0}if(r(t)&&r(e)){const r=Object.entries(t),i=new Set(Object.keys(e));if(r.length!==i.size)return!1;for(const[t,s]of r){if(!n(s,e[t]))return!1;i.delete(t)}return 0===i.size}return!1},i=t=>{if("object"==typeof t){if(null===t)return!0;if(Array.isArray(t))return 0===t.length;for(const e in t)return!1;return!0}return!("number"==typeof t||t)},s=t=>t>="0"&&t<="9"||"-"===t,o=t=>{if("number"!=typeof t||Math.floor(t)!==t)throw new Error("invalid-value: expecting an integer.");return t},a=t=>{if("number"!=typeof t||t<0||Math.floor(t)!==t)throw new Error("invalid-value: expecting a non-negative integer.");return t},u=(...t)=>{for(let e=0;e<t.length;e++){if(null===t[e]||void 0===t[e])throw new Error("not-a-number: undefined");if("number"!=typeof t[e])throw new Error("not-a-number")}},c=t=>{if(!(t=+t))throw new Error("not-a-number: divide by zero");return t},h={"(":e.TOK_LPAREN,")":e.TOK_RPAREN,"*":e.TOK_STAR,",":e.TOK_COMMA,".":e.TOK_DOT,":":e.TOK_COLON,"@":e.TOK_CURRENT,$:e.TOK_ROOT,"]":e.TOK_RBRACKET,"{":e.TOK_LBRACE,"}":e.TOK_RBRACE,"+":e.TOK_PLUS,"%":e.TOK_MODULO,"−":e.TOK_MINUS,"×":e.TOK_MULTIPLY,"÷":e.TOK_DIVIDE},T={"!":!0,"<":!0,"=":!0,">":!0,"&":!0,"|":!0,"/":!0},_={"\t":!0,"\n":!0,"\r":!0," ":!0};const l=new class{constructor(){this._current=0,this._enable_legacy_literals=!1}tokenize(t,r){const n=[];let i,o,a;for(this._current=0,this._enable_legacy_literals=(null==r?void 0:r.enable_legacy_literals)||!1;this._current<t.length;)if((u=t[this._current])>="a"&&u<="z"||u>="A"&&u<="Z"||"_"===u)i=this._current,o=this.consumeUnquotedIdentifier(t),n.push({start:i,type:e.TOK_UNQUOTEDIDENTIFIER,value:o});else if(void 0!==h[t[this._current]])n.push({start:this._current,type:h[t[this._current]],value:t[this._current]}),this._current+=1;else if("-"===t[this._current])if(this._current+1<t.length&&s(t[this._current+1])){const e=this.consumeNumber(t);e&&n.push(e)}else{const t={start:this._current,type:e.TOK_MINUS,value:"-"};n.push(t),this._current+=1}else if(s(t[this._current]))a=this.consumeNumber(t),n.push(a);else if("["===t[this._current])a=this.consumeLBracket(t),n.push(a);else if('"'===t[this._current])i=this._current,o=this.consumeQuotedIdentifier(t),n.push({start:i,type:e.TOK_QUOTEDIDENTIFIER,value:o});else if("'"===t[this._current])i=this._current,o=this.consumeRawStringLiteral(t),n.push({start:i,type:e.TOK_LITERAL,value:o});else if("`"===t[this._current]){i=this._current;const r=this.consumeLiteral(t);n.push({start:i,type:e.TOK_LITERAL,value:r})}else if(void 0!==T[t[this._current]])a=this.consumeOperator(t),a&&n.push(a);else{if(void 0===_[t[this._current]]){const e=new Error(`Syntax error: unknown character: ${t[this._current]}`);throw e.name="LexerError",e}this._current+=1}var u;return n}consumeUnquotedIdentifier(t){const e=this._current;for(this._current+=1;this._current<t.length&&((r=t[this._current])>="a"&&r<="z"||r>="A"&&r<="Z"||r>="0"&&r<="9"||"_"===r);)this._current+=1;var r;return t.slice(e,this._current)}consumeQuotedIdentifier(t){const e=this._current;this._current+=1;const r=t.length;for(;'"'!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&'"'!==t[e+1]?e+=1:e+=2,this._current=e}this._current+=1;const[n,i]=this.parseJSON(t.slice(e,this._current));if(!i){const t=new Error("syntax: unexpected end of JSON input");throw t.name="LexerError",t}return n}consumeRawStringLiteral(t){const e=this._current;this._current+=1;const r=t.length;for(;"'"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"'"!==t[e+1]?e+=1:e+=2,this._current=e}this._current+=1;return t.slice(e+1,this._current-1).replace("\\'","'").replace("\\\\","\\")}consumeNumber(t){const r=this._current;this._current+=1;const n=t.length;for(;s(t[this._current])&&this._current<n;)this._current+=1;return{start:r,value:parseInt(t.slice(r,this._current),10),type:e.TOK_NUMBER}}consumeLBracket(t){const r=this._current;return this._current+=1,"?"===t[this._current]?(this._current+=1,{start:r,type:e.TOK_FILTER,value:"[?"}):"]"===t[this._current]?(this._current+=1,{start:r,type:e.TOK_FLATTEN,value:"[]"}):{start:r,type:e.TOK_LBRACKET,value:"["}}consumeOrElse(t,r,n,i){const s=this._current;if(this._current+=1,this._current<t.length&&t[this._current]===r)return this._current+=1,{start:s,type:i,value:t.slice(s,this._current)};if(n===e.TOK_EOF){const e=new Error(`syntax: unknown incomplete token: ${t[s]}`);throw e.name="LexerError",e}return{start:s,type:n,value:t[s]}}consumeOperator(t){switch(t[this._current]){case"!":return this.consumeOrElse(t,"=",e.TOK_NOT,e.TOK_NE);case"<":return this.consumeOrElse(t,"=",e.TOK_LT,e.TOK_LTE);case">":return this.consumeOrElse(t,"=",e.TOK_GT,e.TOK_GTE);case"=":return this.consumeOrElse(t,"=",e.TOK_EOF,e.TOK_EQ);case"&":return this.consumeOrElse(t,"&",e.TOK_EXPREF,e.TOK_AND);case"|":return this.consumeOrElse(t,"|",e.TOK_PIPE,e.TOK_OR);case"/":return this.consumeOrElse(t,"/",e.TOK_DIVIDE,e.TOK_DIV)}}consumeLiteral(t){this._current+=1;const e=this._current,r=t.length;for(;"`"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"`"!==t[e+1]?e+=1:e+=2,this._current=e}let n=t.slice(e,this._current).trimStart();n=n.replace("\\`","`");let i=null,s=!1;if(this.looksLikeJSON(n)&&([i,s]=this.parseJSON(n)),!s&&this._enable_legacy_literals&&([i,s]=this.parseJSON(`"${n}"`)),!s){const e=new Error(`Syntax error: unexpected end of JSON input or invalid format for a JSON literal: ${t[this._current]}`);throw e.name="LexerError",e}return this._current+=1,i}looksLikeJSON(t){if(""===t)return!1;if('[{"'.includes(t[0]))return!0;if(["true","false","null"].includes(t))return!0;if("-0123456789".includes(t[0])){const[e,r]=this.parseJSON(t);return r}return!1}parseJSON(t){try{return[JSON.parse(t),!0]}catch(t){return[null,!1]}}},E={[e.TOK_EOF]:0,[e.TOK_UNQUOTEDIDENTIFIER]:0,[e.TOK_QUOTEDIDENTIFIER]:0,[e.TOK_RBRACKET]:0,[e.TOK_RPAREN]:0,[e.TOK_COMMA]:0,[e.TOK_RBRACE]:0,[e.TOK_NUMBER]:0,[e.TOK_CURRENT]:0,[e.TOK_EXPREF]:0,[e.TOK_ROOT]:0,[e.TOK_PIPE]:1,[e.TOK_OR]:2,[e.TOK_AND]:3,[e.TOK_EQ]:5,[e.TOK_GT]:5,[e.TOK_LT]:5,[e.TOK_GTE]:5,[e.TOK_LTE]:5,[e.TOK_NE]:5,[e.TOK_MINUS]:6,[e.TOK_PLUS]:6,[e.TOK_DIV]:7,[e.TOK_DIVIDE]:7,[e.TOK_MODULO]:7,[e.TOK_MULTIPLY]:7,[e.TOK_FLATTEN]:9,[e.TOK_STAR]:20,[e.TOK_FILTER]:21,[e.TOK_DOT]:40,[e.TOK_NOT]:45,[e.TOK_LBRACE]:50,[e.TOK_LBRACKET]:55,[e.TOK_LPAREN]:60};const p=new class{constructor(){this.index=0,this.tokens=[]}parse(t,r){this.loadTokens(t,r||{enable_legacy_literals:!1}),this.index=0;const n=this.expression(0);if(this.lookahead(0)!==e.TOK_EOF){const t=this.lookaheadToken(0);this.errorToken(t,`Syntax error: unexpected token type: ${t.type}, value: ${t.value}`)}return n}loadTokens(t,r){this.tokens=[...l.tokenize(t,r),{type:e.TOK_EOF,value:"",start:t.length}]}expression(t){const e=this.lookaheadToken(0);this.advance();let r=this.nud(e),n=this.lookahead(0);for(;t<E[n];)this.advance(),r=this.led(n,r),n=this.lookahead(0);return r}lookahead(t){return this.tokens[this.index+t].type}lookaheadToken(t){return this.tokens[this.index+t]}advance(){this.index+=1}nud(t){switch(t.type){case e.TOK_LITERAL:return{type:"Literal",value:t.value};case e.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:t.value};case e.TOK_QUOTEDIDENTIFIER:if(this.lookahead(0)===e.TOK_LPAREN)throw new Error("Syntax error: quoted identifier not allowed for function names.");return{type:"Field",name:t.value};case e.TOK_NOT:return{type:"NotExpression",child:this.expression(E.Not)};case e.TOK_MINUS:{const e=this.expression(E.Minus);return{type:"Unary",operator:t.type,operand:e}}case e.TOK_PLUS:{const e=this.expression(E.Plus);return{type:"Unary",operator:t.type,operand:e}}case e.TOK_STAR:{const t={type:"Identity"};return{type:"ValueProjection",left:t,right:this.lookahead(0)===e.TOK_RBRACKET?t:this.parseProjectionRHS(E.Star)}}case e.TOK_FILTER:return this.led(t.type,{type:"Identity"});case e.TOK_LBRACE:return this.parseMultiselectHash();case e.TOK_FLATTEN:return{type:"Projection",left:{type:"Flatten",child:{type:"Identity"}},right:this.parseProjectionRHS(E.Flatten)};case e.TOK_LBRACKET:if(this.lookahead(0)===e.TOK_NUMBER||this.lookahead(0)===e.TOK_COLON){const t=this.parseIndexExpression();return this.projectIfSlice({type:"Identity"},t)}if(this.lookahead(0)===e.TOK_STAR&&this.lookahead(1)===e.TOK_RBRACKET){this.advance(),this.advance();return{left:{type:"Identity"},right:this.parseProjectionRHS(E.Star),type:"Projection"}}return this.parseMultiselectList();case e.TOK_CURRENT:return{type:e.TOK_CURRENT};case e.TOK_ROOT:return{type:e.TOK_ROOT};case e.TOK_EXPREF:return{type:"ExpressionReference",child:this.expression(E.Expref)};case e.TOK_LPAREN:{const t=[];for(;this.lookahead(0)!==e.TOK_RPAREN;){let r;this.lookahead(0)===e.TOK_CURRENT?(r={type:e.TOK_CURRENT},this.advance()):r=this.expression(0),t.push(r)}return this.match(e.TOK_RPAREN),t[0]}default:this.errorToken(t)}}led(t,r){switch(t){case e.TOK_DOT:{const t=E.Dot;if(this.lookahead(0)!==e.TOK_STAR){return{type:"Subexpression",left:r,right:this.parseDotRHS(t)}}this.advance();return{type:"ValueProjection",left:r,right:this.parseProjectionRHS(t)}}case e.TOK_PIPE:return{type:"Pipe",left:r,right:this.expression(E.Pipe)};case e.TOK_OR:return{type:"OrExpression",left:r,right:this.expression(E.Or)};case e.TOK_AND:return{type:"AndExpression",left:r,right:this.expression(E.And)};case e.TOK_LPAREN:{if("Field"!==r.type)throw new Error("Syntax error: expected a Field node");const t=r.name,n=[];let i;for(;this.lookahead(0)!==e.TOK_RPAREN;)this.lookahead(0)===e.TOK_CURRENT?(i={type:e.TOK_CURRENT},this.advance()):i=this.expression(0),this.lookahead(0)===e.TOK_COMMA&&this.match(e.TOK_COMMA),n.push(i);this.match(e.TOK_RPAREN);return{name:t,type:"Function",children:n}}case e.TOK_FILTER:{const t=this.expression(0);this.match(e.TOK_RBRACKET);return{type:"FilterProjection",left:r,right:this.lookahead(0)===e.TOK_FLATTEN?{type:"Identity"}:this.parseProjectionRHS(E.Filter),condition:t}}case e.TOK_FLATTEN:return{type:"Projection",left:{type:"Flatten",child:r},right:this.parseProjectionRHS(E.Flatten)};case e.TOK_EQ:case e.TOK_NE:case e.TOK_GT:case e.TOK_GTE:case e.TOK_LT:case e.TOK_LTE:return this.parseComparator(r,t);case e.TOK_PLUS:case e.TOK_MINUS:case e.TOK_MULTIPLY:case e.TOK_STAR:case e.TOK_DIVIDE:case e.TOK_MODULO:case e.TOK_DIV:return this.parseArithmetic(r,t);case e.TOK_LBRACKET:{const t=this.lookaheadToken(0);if(t.type===e.TOK_NUMBER||t.type===e.TOK_COLON){const t=this.parseIndexExpression();return this.projectIfSlice(r,t)}this.match(e.TOK_STAR),this.match(e.TOK_RBRACKET);return{type:"Projection",left:r,right:this.parseProjectionRHS(E.Star)}}default:return this.errorToken(this.lookaheadToken(0))}}match(t){if(this.lookahead(0)!==t){const e=this.lookaheadToken(0);this.errorToken(e,`Syntax error: expected ${t}, got: ${e.type}`)}else this.advance()}errorToken(t,e=""){const r=new Error(e||`Syntax error: invalid token (${t.type}): "${t.value}"`);throw r.name="ParserError",r}parseIndexExpression(){if(this.lookahead(0)===e.TOK_COLON||this.lookahead(1)===e.TOK_COLON)return this.parseSliceExpression();const t=Number(this.lookaheadToken(0).value);return this.advance(),this.match(e.TOK_RBRACKET),{type:"Index",value:t}}projectIfSlice(t,e){const r={type:"IndexExpression",left:t,right:e};return"Slice"===e.type?{left:r,right:this.parseProjectionRHS(E.Star),type:"Projection"}:r}parseSliceExpression(){const t=[null,null,null];let r=0,n=this.lookaheadToken(0);for(;n.type!=e.TOK_RBRACKET&&r<3;){if(n.type===e.TOK_COLON)r++,3===r&&this.errorToken(this.lookaheadToken(0),"Syntax error, too many colons in slice expression"),this.advance();else if(n.type===e.TOK_NUMBER){const e=this.lookaheadToken(0).value;t[r]=e,this.advance()}else{const t=this.lookaheadToken(0);this.errorToken(t,`Syntax error, unexpected token: ${t.value}(${t.type})`)}n=this.lookaheadToken(0)}this.match(e.TOK_RBRACKET);const[i=null,s=null,o=null]=t;return{type:"Slice",start:i,stop:s,step:o}}parseComparator(t,e){return{type:"Comparator",name:e,left:t,right:this.expression(E[e])}}parseArithmetic(t,e){return{type:"Arithmetic",operator:e,left:t,right:this.expression(E[e])}}parseDotRHS(t){const r=this.lookahead(0);if([e.TOK_UNQUOTEDIDENTIFIER,e.TOK_QUOTEDIDENTIFIER,e.TOK_STAR].includes(r))return this.expression(t);if(r===e.TOK_LBRACKET)return this.match(e.TOK_LBRACKET),this.parseMultiselectList();if(r===e.TOK_LBRACE)return this.match(e.TOK_LBRACE),this.parseMultiselectHash();const n=this.lookaheadToken(0);this.errorToken(n,`Syntax error, unexpected token: ${n.value}(${n.type})`)}parseProjectionRHS(t){if(E[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===e.TOK_LBRACKET)return this.expression(t);if(this.lookahead(0)===e.TOK_FILTER)return this.expression(t);if(this.lookahead(0)===e.TOK_DOT)return this.match(e.TOK_DOT),this.parseDotRHS(t);const r=this.lookaheadToken(0);this.errorToken(r,`Syntax error, unexpected token: ${r.value}(${r.type})`)}parseMultiselectList(){const t=[];for(;this.lookahead(0)!==e.TOK_RBRACKET;){const r=this.expression(0);if(t.push(r),this.lookahead(0)===e.TOK_COMMA&&(this.match(e.TOK_COMMA),this.lookahead(0)===e.TOK_RBRACKET))throw new Error("Syntax error: unexpected token Rbracket")}return this.match(e.TOK_RBRACKET),{type:"MultiSelectList",children:t}}parseMultiselectHash(){const t=[],r=[e.TOK_UNQUOTEDIDENTIFIER,e.TOK_QUOTEDIDENTIFIER];let n,i,s;for(;;){if(n=this.lookaheadToken(0),!r.includes(n.type))throw new Error(`Syntax error: expecting an identifier token, got: ${n.type}`);if(i=n.value,this.advance(),this.match(e.TOK_COLON),s=this.expression(0),t.push({value:s,type:"KeyValuePair",name:i}),this.lookahead(0)===e.TOK_COMMA)this.match(e.TOK_COMMA);else if(this.lookahead(0)===e.TOK_RBRACE){this.match(e.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:t}}};class R{constructor(t){this._text=t}get string(){return this._text}get length(){return this.codePoints.length}compareTo(t){return R.compare(this,new R(t))}static get comparer(){return(t,e)=>new R(t).compareTo(e)}static compare(t,e){const r=t.codePoints,n=e.codePoints;for(let t=0;t<Math.min(r.length,n.length);t++)if(r[t]!==n[t])return r[t]-n[t]>0?1:-1;return r.length-n.length>0?1:-1}reverse(){return String.fromCodePoint(...this.codePoints.reverse())}get codePoints(){return[...this._text].map((t=>t.codePointAt(0)))}}const f=(t,e,r)=>{if((r=r||" ").length>1)throw new Error(`invalid value, ${t} expects its 'pad' parameter to be a valid string with a single codepoint`);return a(e),r},O=(t,e)=>A(t,(t=>new RegExp(`^[${t}]*(.*?)`)),e),y=(t,e)=>A(t,(t=>new RegExp(`(.*?)[${t}]*$`)),e),A=(t,e,r)=>{const n=r?r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"):"\\s
";return t.replace(e(n),"$1")};var P;!function(t){t[t.TYPE_NUMBER=0]="TYPE_NUMBER",t[t.TYPE_ANY=1]="TYPE_ANY",t[t.TYPE_STRING=2]="TYPE_STRING",t[t.TYPE_ARRAY=3]="TYPE_ARRAY",t[t.TYPE_OBJECT=4]="TYPE_OBJECT",t[t.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",t[t.TYPE_EXPREF=6]="TYPE_EXPREF",t[t.TYPE_NULL=7]="TYPE_NULL",t[t.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",t[t.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING",t[t.TYPE_ARRAY_OBJECT=10]="TYPE_ARRAY_OBJECT",t[t.TYPE_ARRAY_ARRAY=11]="TYPE_ARRAY_ARRAY"}(P||(P={}));class d{constructor(t){this.TYPE_NAME_TABLE={[P.TYPE_NUMBER]:"number",[P.TYPE_ANY]:"any",[P.TYPE_STRING]:"string",[P.TYPE_ARRAY]:"array",[P.TYPE_OBJECT]:"object",[P.TYPE_BOOLEAN]:"boolean",[P.TYPE_EXPREF]:"expression",[P.TYPE_NULL]:"null",[P.TYPE_ARRAY_NUMBER]:"Array<number>",[P.TYPE_ARRAY_OBJECT]:"Array<object>",[P.TYPE_ARRAY_STRING]:"Array<string>",[P.TYPE_ARRAY_ARRAY]:"Array<Array<any>>"},this.functionAbs=([t])=>Math.abs(t),this.functionAvg=([t])=>{if(!t||0==t.length)return null;let e=0;for(let r=0;r<t.length;r+=1)e+=t[r];return e/t.length},this.functionCeil=([t])=>Math.ceil(t),this.functionContains=([t,e])=>{if(Array.isArray(t)){return t.includes(e)}if("string"==typeof t){if("string"==typeof e)return t.includes(e)}return null},this.functionEndsWith=t=>{const[e,r]=t;return e.includes(r,e.length-r.length)},this.functionFindFirst=t=>((t,e,r,n)=>{if(!t||!e)return null;r=Math.max(o(r=r||0),0),n=Math.min(o(n=n||t.length),t.length);const i=t.slice(r,n).indexOf(e);return-1===i?null:i+r})(t[0],t[1],t.length>2&&t[2]||void 0,t.length>3&&t[3]||void 0),this.functionFindLast=t=>((t,e,r,n)=>{if(!t||!e)return null;r=Math.max(o(r=r||0),0),n=Math.min(o(n=n||t.length),t.length);const i=t.slice(r,n).lastIndexOf(e);return-1===i?null:i+r})(t[0],t[1],t.length>2&&t[2]||void 0,t.length>3&&t[3]||void 0),this.functionFloor=([t])=>Math.floor(t),this.functionFromItems=([t])=>(t.map((t=>{if(2!=t.length||"string"!=typeof t[0])throw new Error("invalid value, each array must contain two elements, a pair of string and value")})),Object.fromEntries(t)),this.functionGroupBy=([t,e])=>{const r=this.createKeyFunction(e,[P.TYPE_STRING]);return t.reduce(((t,e)=>{const n=r(null!=e?e:{});return(t[n]=t[n]||[]).push(e),t}),{})},this.functionItems=([t])=>Object.entries(t),this.functionJoin=t=>{const[e,r]=t;return r.join(e)},this.functionKeys=([t])=>Object.keys(t),this.functionLength=([t])=>"string"==typeof t?new R(t).length:Array.isArray(t)?t.length:Object.keys(t).length,this.functionLet=([t,e])=>{var r;return(null===(r=this._interpreter)||void 0===r?void 0:r.withScope(t)).visit(e,e.context)},this.functionLower=([t])=>(t=>t.toLowerCase())(t),this.functionMap=([t,e])=>{if(!this._interpreter)return[];const r=[],n=this._interpreter;for(let i=0;i<e.length;i+=1)r.push(n.visit(t,e[i]));return r},this.functionMax=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===P.TYPE_NUMBER)return Math.max(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)r.localeCompare(e[t])<0&&(r=e[t]);return r},this.functionMaxBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[P.TYPE_NUMBER,P.TYPE_STRING]);let i,s,o=-1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s>o&&(o=s,i=r[t]);return i||null},this.functionMerge=t=>{let e={};for(let r=0;r<t.length;r+=1){const n=t[r];e=Object.assign(e,n)}return e},this.functionMin=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===P.TYPE_NUMBER)return Math.min(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)e[t].localeCompare(r)<0&&(r=e[t]);return r},this.functionMinBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[P.TYPE_NUMBER,P.TYPE_STRING]);let i,s,o=1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s<o&&(o=s,i=r[t]);return i||null},this.functionNotNull=t=>{for(let e=0;e<t.length;e+=1)if(this.getTypeName(t[e])!==P.TYPE_NULL)return t[e];return null},this.functionPadLeft=t=>((t,e,r)=>(r=f("pad_left",e,r),t&&t.padStart(e,r)||""))(t[0],t[1],t.length>2&&t[2]||void 0),this.functionPadRight=t=>((t,e,r)=>(r=f("pad_right",e,r),t&&t.padEnd(e,r)||""))(t[0],t[1],t.length>2&&t[2]||void 0),this.functionReplace=t=>((t,e,r,n)=>0===n?t:n?(a(n),[...Array(n).keys()].map((()=>t=t.replace(e,r))),t):t.split(e).join(r))(t[0],t[1],t[2],t.length>3?t[3]:void 0),this.functionSplit=t=>((t,e,r)=>{if(0==t.length&&0===e.length)return[];if(null==r)return t.split(e);if(a(r),0===r)return[t];const n=t.split(e);return[...n.slice(0,r),n.slice(r).join(e)]})(t[0],t[1],t.length>2?t[2]:void 0),this.functionReverse=([t])=>{if(this.getTypeName(t)===P.TYPE_STRING)return new R(t).reverse();const e=t.slice(0);return e.reverse(),e},this.functionSort=([t])=>0==t.length?t:"string"==typeof t[0]?[...t].sort(R.comparer):[...t].sort(),this.functionSortBy=t=>{const e=t[0].slice(0);if(0===e.length)return e;const r=this._interpreter,n=t[1],i=this.getTypeName(r.visit(n,e[0]));if(void 0!==i&&![P.TYPE_NUMBER,P.TYPE_STRING].includes(i))throw new Error(`Invalid type: unexpected type (${this.TYPE_NAME_TABLE[i]})`);function s(t,e){throw new Error(`Invalid type: expected (${t.TYPE_NAME_TABLE[i]}), received ${t.TYPE_NAME_TABLE[t.getTypeName(e)]}`)}return e.sort(((t,e)=>{const o=r.visit(n,t),a=r.visit(n,e);return this.getTypeName(o)!==i?s(this,o):this.getTypeName(a)!==i&&s(this,a),i===P.TYPE_STRING?R.comparer(o,a):o-a}))},this.functionStartsWith=([t,e])=>t.startsWith(e),this.functionSum=([t])=>t.reduce(((t,e)=>t+e),0),this.functionToArray=([t])=>this.getTypeName(t)===P.TYPE_ARRAY?t:[t],this.functionToNumber=([t])=>{const e=this.getTypeName(t);let r;return e===P.TYPE_NUMBER?t:e!==P.TYPE_STRING||(r=+t,isNaN(r))?null:r},this.functionToString=([t])=>this.getTypeName(t)===P.TYPE_STRING?t:JSON.stringify(t),this.functionTrim=t=>((t,e)=>O(y(t,e),e))(t[0],t.length>1?t[1]:void 0),this.functionTrimLeft=t=>{const e=t[0];return O(e,t.length>1?t[1]:void 0)},this.functionTrimRight=t=>{const e=t[0];return y(e,t.length>1?t[1]:void 0)},this.functionType=([t])=>{switch(this.getTypeName(t)){case P.TYPE_NUMBER:return"number";case P.TYPE_STRING:return"string";case P.TYPE_ARRAY:return"array";case P.TYPE_OBJECT:return"object";case P.TYPE_BOOLEAN:return"boolean";case P.TYPE_NULL:return"null";default:throw new Error("invalid-type")}},this.functionUpper=([t])=>(t=>t.toUpperCase())(t),this.functionValues=([t])=>Object.values(t),this.functionZip=t=>{const e=Math.min(...t.map((t=>t.length)));return Array(e).fill(null).map(((e,r)=>t.map((t=>t[r]))))},this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[P.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[P.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[P.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[P.TYPE_STRING,P.TYPE_ARRAY]},{types:[P.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]}]},find_first:{_func:this.functionFindFirst,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]},{types:[P.TYPE_NUMBER],optional:!0},{types:[P.TYPE_NUMBER],optional:!0}]},find_last:{_func:this.functionFindLast,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]},{types:[P.TYPE_NUMBER],optional:!0},{types:[P.TYPE_NUMBER],optional:!0}]},floor:{_func:this.functionFloor,_signature:[{types:[P.TYPE_NUMBER]}]},from_items:{_func:this.functionFromItems,_signature:[{types:[P.TYPE_ARRAY_ARRAY]}]},group_by:{_func:this.functionGroupBy,_signature:[{types:[P.TYPE_ARRAY]},{types:[P.TYPE_EXPREF]}]},items:{_func:this.functionItems,_signature:[{types:[P.TYPE_OBJECT]}]},join:{_func:this.functionJoin,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[P.TYPE_OBJECT]}]},let:{_func:this.functionLet,_signature:[{types:[P.TYPE_OBJECT]},{types:[P.TYPE_EXPREF]}]},length:{_func:this.functionLength,_signature:[{types:[P.TYPE_STRING,P.TYPE_ARRAY,P.TYPE_OBJECT]}]},lower:{_func:this.functionLower,_signature:[{types:[P.TYPE_STRING]}]},map:{_func:this.functionMap,_signature:[{types:[P.TYPE_EXPREF]},{types:[P.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[P.TYPE_ARRAY_NUMBER,P.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[P.TYPE_ARRAY]},{types:[P.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[P.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[P.TYPE_ARRAY_NUMBER,P.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[P.TYPE_ARRAY]},{types:[P.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[P.TYPE_ANY],variadic:!0}]},pad_left:{_func:this.functionPadLeft,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_NUMBER]},{types:[P.TYPE_STRING],optional:!0}]},pad_right:{_func:this.functionPadRight,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_NUMBER]},{types:[P.TYPE_STRING],optional:!0}]},replace:{_func:this.functionReplace,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]},{types:[P.TYPE_NUMBER],optional:!0}]},split:{_func:this.functionSplit,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]},{types:[P.TYPE_NUMBER],optional:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[P.TYPE_STRING,P.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[P.TYPE_ARRAY_STRING,P.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[P.TYPE_ARRAY]},{types:[P.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[P.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[P.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[P.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[P.TYPE_ANY]}]},trim:{_func:this.functionTrim,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING],optional:!0}]},trim_left:{_func:this.functionTrimLeft,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING],optional:!0}]},trim_right:{_func:this.functionTrimRight,_signature:[{types:[P.TYPE_STRING]},{types:[P.TYPE_STRING],optional:!0}]},type:{_func:this.functionType,_signature:[{types:[P.TYPE_ANY]}]},upper:{_func:this.functionUpper,_signature:[{types:[P.TYPE_STRING]}]},values:{_func:this.functionValues,_signature:[{types:[P.TYPE_OBJECT]}]},zip:{_func:this.functionZip,_signature:[{types:[P.TYPE_ARRAY],variadic:!0}]}},this._interpreter=t}registerFunction(t,e,r){if(t in this.functionTable)throw new Error(`Function already defined: ${t}()`);this.functionTable[t]={_func:e.bind(this),_signature:r}}callFunction(t,e){const r=this.functionTable[t];if(void 0===r)throw new Error(`Unknown function: ${t}()`);return this.validateArgs(t,e,r._signature),r._func.call(this,e)}validateInputSignatures(t,e){for(let r=0;r<e.length;r+=1)if("variadic"in e[r]&&r!==e.length-1)throw new Error(`Invalid arity: ${t}() 'variadic' argument ${r+1} must occur last`)}validateArgs(t,e,r){var n,i;let s;this.validateInputSignatures(t,r);const o=r.filter((t=>{var e;return null!==(e=!t.optional)&&void 0!==e&&e})).length,a=null!==(i=null===(n=r[r.length-1])||void 0===n?void 0:n.variadic)&&void 0!==i&&i,u=e.length<o,c=e.length>r.length,h=u&&(!a&&o>1||a)?"at least ":"";if(a&&u||!a&&(u||c))throw s=r.length>1,new Error(`Invalid arity: ${t}() takes ${h}${o} argument${s?"s":""} but received ${e.length}`);let T,_,l;for(let n=0;n<r.length;n+=1){let i;for(l=!1,T=r[n].types,_=this.getTypeName(e[n]),i=0;i<T.length;i+=1)if(void 0!==_&&this.typeMatches(_,T[i],e[n])){l=!0;break}if(!l&&void 0!==_){const e=T.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ");throw new Error(`Invalid type: ${t}() expected argument ${n+1} to be type (${e}) but received type ${this.TYPE_NAME_TABLE[_]} instead.`)}}}typeMatches(t,e,r){if(e===P.TYPE_ANY)return!0;if(e!==P.TYPE_ARRAY_STRING&&e!==P.TYPE_ARRAY_NUMBER&&e!==P.TYPE_ARRAY_OBJECT&&e!==P.TYPE_ARRAY_ARRAY&&e!==P.TYPE_ARRAY)return t===e;if(e===P.TYPE_ARRAY)return t===P.TYPE_ARRAY;if(t===P.TYPE_ARRAY){let t;e===P.TYPE_ARRAY_NUMBER?t=P.TYPE_NUMBER:e===P.TYPE_ARRAY_OBJECT?t=P.TYPE_OBJECT:e===P.TYPE_ARRAY_STRING?t=P.TYPE_STRING:e===P.TYPE_ARRAY_ARRAY&&(t=P.TYPE_ARRAY);const n=r;for(let e=0;e<n.length;e+=1){const r=this.getTypeName(n[e]);if(void 0!==r&&void 0!==t&&!this.typeMatches(r,t,n[e]))return!1}return!0}return!1}getTypeName(t){switch(Object.prototype.toString.call(t)){case"[object String]":return P.TYPE_STRING;case"[object Number]":return P.TYPE_NUMBER;case"[object Array]":return P.TYPE_ARRAY;case"[object Boolean]":return P.TYPE_BOOLEAN;case"[object Null]":return P.TYPE_NULL;case"[object Object]":return t.expref?P.TYPE_EXPREF:P.TYPE_OBJECT;default:return}}createKeyFunction(t,e){const r=this._interpreter;return n=>{const i=r.visit(t,n);if(!e.includes(this.getTypeName(i))){const t=`Invalid type: expected one of (${e.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(i)]}`;throw new Error(t)}return i}}}class Y{constructor(){this.inner=void 0,this.data={}}withScope(t){const e=new Y;return e.inner=this,e.data=t,e}getValue(t){if(t in this.data){const e=this.data[t];if(e)return e}return this.inner?this.inner.getValue(t):null}}class N{constructor(){this._rootValue=null,this._scope=void 0,this.runtime=new d(this)}withScope(t){var e;const r=new N;return r._rootValue=this._rootValue,r._scope=null===(e=this._scope)||void 0===e?void 0:e.withScope(t),r}search(t,e){return this._rootValue=e,this._scope=new Y,this.visit(t,e)}visit(t,r){var s,o,a,h,T,_;switch(t.type){case"Field":const l=t.name;let E=null;return null===r||"object"!=typeof r||Array.isArray(r)||(E=null!==(s=r[l])&&void 0!==s?s:null),null==E&&(E=null!==(a=null===(o=this._scope)||void 0===o?void 0:o.getValue(l))&&void 0!==a?a:null),E;case"IndexExpression":return this.visit(t.right,this.visit(t.left,r));case"Subexpression":{const e=this.visit(t.left,r);return null!=e&&this.visit(t.right,e)||null}case"Index":if(!Array.isArray(r))return null;return null!==(h=r[t.value<0?r.length+t.value:t.value])&&void 0!==h?h:null;case"Slice":{if(!Array.isArray(r)&&"string"!=typeof r)return null;const{start:e,stop:n,step:i}=this.computeSliceParams(r.length,t);if("string"==typeof r){const t=[...r];return this.slice(t,e,n,i).join("")}return this.slice(r,e,n,i)}case"Projection":{const{left:e,right:n}=t;let i=!1;"IndexExpression"===e.type&&"Slice"===e.right.type&&(i=!0);const s=this.visit(e,r);if(i&&"string"==typeof s)return s;if(!Array.isArray(s))return null;const o=[];for(const t of s){const e=this.visit(n,t);null!==e&&o.push(e)}return o}case"ValueProjection":{const{left:e,right:n}=t,i=this.visit(e,r);if(null===i||"object"!=typeof i||Array.isArray(i))return null;const s=[],o=Object.values(i);for(const t of o){const e=this.visit(n,t);null!==e&&s.push(e)}return s}case"FilterProjection":{const{left:e,right:n,condition:s}=t,o=this.visit(e,r);if(!Array.isArray(o))return null;const a=[];for(const t of o){const e=this.visit(s,t);if(i(e))continue;const r=this.visit(n,t);null!==r&&a.push(r)}return a}case"Arithmetic":{const n=this.visit(t.left,r),i=this.visit(t.right,r);switch(t.operator){case e.TOK_PLUS:return u(T=n,_=i),T+_;case e.TOK_MINUS:return((t,e)=>(u(t,e),t-e))(n,i);case e.TOK_MULTIPLY:case e.TOK_STAR:return((t,e)=>(u(t,e),t*e))(n,i);case e.TOK_DIVIDE:return((t,e)=>(u(t,e),t/c(e)))(n,i);case e.TOK_MODULO:return((t,e)=>(u(t,e),t%e))(n,i);case e.TOK_DIV:return((t,e)=>(u(t,e),Math.floor(t/c(e))))(n,i);default:throw new Error(`Syntax error: unknown arithmetic operator: ${t.operator}`)}}case"Unary":{const n=this.visit(t.operand,r);switch(t.operator){case e.TOK_PLUS:return u(n),n;case e.TOK_MINUS:return u(n),-n;default:throw new Error(`Syntax error: unknown arithmetic operator: ${t.operator}`)}}case"Comparator":{const e=this.visit(t.left,r),i=this.visit(t.right,r);switch(t.name){case"EQ":return n(e,i);case"NE":return!n(e,i)}if("number"!=typeof e||"number"!=typeof i)return null;switch(t.name){case"GT":return e>i;case"GTE":return e>=i;case"LT":return e<i;case"LTE":return e<=i}}case"Flatten":{const e=this.visit(t.child,r);return Array.isArray(e)?e.flat():null}case"Root":return this._rootValue;case"MultiSelectList":{const e=[];for(const n of t.children)e.push(this.visit(n,r));return e}case"MultiSelectHash":{const e={};for(const n of t.children)e[n.name]=this.visit(n.value,r);return e}case"OrExpression":{const e=this.visit(t.left,r);return i(e)?this.visit(t.right,r):e}case"AndExpression":{const e=this.visit(t.left,r);return i(e)?e:this.visit(t.right,r)}case"NotExpression":return i(this.visit(t.child,r));case"Literal":return t.value;case"Pipe":return this.visit(t.right,this.visit(t.left,r));case"Function":{const e=[];for(const n of t.children)e.push(this.visit(n,r));return this.runtime.callFunction(t.name,e)}case"ExpressionReference":return Object.assign({expref:!0,context:r},t.child);case"Current":case"Identity":return r}}computeSliceParams(t,e){let{start:r,stop:n,step:i}=e;if(null===i)i=1;else if(0===i){const t=new Error("Invalid value: slice step cannot be 0");throw t.name="RuntimeError",t}return r=null===r?i<0?t-1:0:this.capSliceRange(t,r,i),n=null===n?i<0?-1:t:this.capSliceRange(t,n,i),{start:r,stop:n,step:i}}capSliceRange(t,e,r){let n=e;return n<0?(n+=t,n<0&&(n=r<0?-1:0)):n>=t&&(n=r<0?t-1:t),n}slice(t,e,r,n){const i=[];if(n>0)for(let s=e;s<r;s+=n)i.push(t[s]);else for(let s=e;s>r;s+=n)i.push(t[s]);return i}}const g=new N,K=P.TYPE_ANY,m=P.TYPE_ARRAY,v=P.TYPE_ARRAY_ARRAY,I=P.TYPE_ARRAY_NUMBER,S=P.TYPE_ARRAY_OBJECT,L=P.TYPE_ARRAY_STRING,M=P.TYPE_BOOLEAN,B=P.TYPE_EXPREF,U=P.TYPE_NULL,x=P.TYPE_NUMBER,k=P.TYPE_OBJECT,w=P.TYPE_STRING;function C(t,e){return p.parse(t,e)}function b(t,e){return l.tokenize(t,e)}const F=(t,e,r)=>{g.runtime.registerFunction(t,e,r)};function G(t,e,r){const n=p.parse(e,r);return g.search(n,t)}const D=g,j={compile:C,registerFunction:F,search:G,tokenize:b,TreeInterpreter:D,TYPE_ANY:K,TYPE_ARRAY_NUMBER:I,TYPE_ARRAY_STRING:L,TYPE_ARRAY:m,TYPE_BOOLEAN:M,TYPE_EXPREF:B,TYPE_NULL:U,TYPE_NUMBER:x,TYPE_OBJECT:k,TYPE_STRING:w};t.Scope=function(){return new Y},t.TYPE_ANY=K,t.TYPE_ARRAY=m,t.TYPE_ARRAY_ARRAY=v,t.TYPE_ARRAY_NUMBER=I,t.TYPE_ARRAY_OBJECT=S,t.TYPE_ARRAY_STRING=L,t.TYPE_BOOLEAN=M,t.TYPE_EXPREF=B,t.TYPE_NULL=U,t.TYPE_NUMBER=x,t.TYPE_OBJECT=k,t.TYPE_STRING=w,t.TreeInterpreter=D,t.compile=C,t.default=j,t.jmespath=j,t.registerFunction=F,t.search=G,t.tokenize=b,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jmespath={})}(this,(function(t){"use strict";var e;!function(t){t.TOK_EOF="EOF",t.TOK_VARIABLE="Variable",t.TOK_ASSIGN="Assign",t.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",t.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",t.TOK_RBRACKET="Rbracket",t.TOK_RPAREN="Rparen",t.TOK_COMMA="Comma",t.TOK_COLON="Colon",t.TOK_RBRACE="Rbrace",t.TOK_NUMBER="Number",t.TOK_CURRENT="Current",t.TOK_ROOT="Root",t.TOK_EXPREF="Expref",t.TOK_PIPE="Pipe",t.TOK_OR="Or",t.TOK_AND="And",t.TOK_EQ="EQ",t.TOK_GT="GT",t.TOK_LT="LT",t.TOK_GTE="GTE",t.TOK_LTE="LTE",t.TOK_NE="NE",t.TOK_PLUS="Plus",t.TOK_MINUS="Minus",t.TOK_MULTIPLY="Multiply",t.TOK_DIVIDE="Divide",t.TOK_MODULO="Modulo",t.TOK_DIV="Div",t.TOK_FLATTEN="Flatten",t.TOK_STAR="Star",t.TOK_FILTER="Filter",t.TOK_DOT="Dot",t.TOK_NOT="Not",t.TOK_LBRACE="Lbrace",t.TOK_LBRACKET="Lbracket",t.TOK_LPAREN="Lparen",t.TOK_LITERAL="Literal"}(e||(e={}));const r=t=>null!==t&&"[object Object]"===Object.prototype.toString.call(t),n=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r+=1)if(!n(t[r],e[r]))return!1;return!0}if(r(t)&&r(e)){const r=Object.entries(t),i=new Set(Object.keys(e));if(r.length!==i.size)return!1;for(const[t,s]of r){if(!n(s,e[t]))return!1;i.delete(t)}return 0===i.size}return!1},i=t=>{if("object"==typeof t){if(null===t)return!0;if(Array.isArray(t))return 0===t.length;for(const e in t)return!1;return!0}return!("number"==typeof t||t)},s=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||"_"===t,o=t=>t>="0"&&t<="9"||"-"===t,a=t=>{if("number"!=typeof t||Math.floor(t)!==t)throw new Error("invalid-value: expecting an integer.");return t},u=t=>{if("number"!=typeof t||t<0||Math.floor(t)!==t)throw new Error("invalid-value: expecting a non-negative integer.");return t},c=(...t)=>{for(let e=0;e<t.length;e++){if(null===t[e]||void 0===t[e])throw new Error("not-a-number: undefined");if("number"!=typeof t[e])throw new Error("not-a-number")}},h=t=>{if(!(t=+t))throw new Error("not-a-number: divide by zero");return t},T={"(":e.TOK_LPAREN,")":e.TOK_RPAREN,"*":e.TOK_STAR,",":e.TOK_COMMA,".":e.TOK_DOT,":":e.TOK_COLON,"@":e.TOK_CURRENT,"]":e.TOK_RBRACKET,"{":e.TOK_LBRACE,"}":e.TOK_RBRACE,"+":e.TOK_PLUS,"%":e.TOK_MODULO,"−":e.TOK_MINUS,"×":e.TOK_MULTIPLY,"÷":e.TOK_DIVIDE},_={"!":!0,"<":!0,"=":!0,">":!0,"&":!0,"|":!0,"/":!0},l={"\t":!0,"\n":!0,"\r":!0," ":!0};const E=new class{constructor(){this._current=0,this._enable_legacy_literals=!1}tokenize(t,r){const n=[];let i,a,u;for(this._current=0,this._enable_legacy_literals=(null==r?void 0:r.enable_legacy_literals)||!1;this._current<t.length;)if(s(t[this._current]))i=this._current,a=this.consumeUnquotedIdentifier(t),n.push({start:i,type:e.TOK_UNQUOTEDIDENTIFIER,value:a});else if(void 0!==T[t[this._current]])n.push({start:this._current,type:T[t[this._current]],value:t[this._current]}),this._current+=1;else if("$"===t[this._current])i=this._current,this._current+1<t.length&&s(t[this._current+1])?(this._current+=1,a=this.consumeUnquotedIdentifier(t),n.push({start:i,type:e.TOK_VARIABLE,value:a})):(n.push({start:i,type:e.TOK_ROOT,value:t[this._current]}),this._current+=1);else if("-"===t[this._current])if(this._current+1<t.length&&o(t[this._current+1])){const e=this.consumeNumber(t);e&&n.push(e)}else{const t={start:this._current,type:e.TOK_MINUS,value:"-"};n.push(t),this._current+=1}else if(o(t[this._current]))u=this.consumeNumber(t),n.push(u);else if("["===t[this._current])u=this.consumeLBracket(t),n.push(u);else if('"'===t[this._current])i=this._current,a=this.consumeQuotedIdentifier(t),n.push({start:i,type:e.TOK_QUOTEDIDENTIFIER,value:a});else if("'"===t[this._current])i=this._current,a=this.consumeRawStringLiteral(t),n.push({start:i,type:e.TOK_LITERAL,value:a});else if("`"===t[this._current]){i=this._current;const r=this.consumeLiteral(t);n.push({start:i,type:e.TOK_LITERAL,value:r})}else if(void 0!==_[t[this._current]])u=this.consumeOperator(t),u&&n.push(u);else{if(void 0===l[t[this._current]]){const e=new Error(`Syntax error: unknown character: ${t[this._current]}`);throw e.name="LexerError",e}this._current+=1}return n}consumeUnquotedIdentifier(t){const e=this._current;for(this._current+=1;this._current<t.length&&((r=t[this._current])>="a"&&r<="z"||r>="A"&&r<="Z"||r>="0"&&r<="9"||"_"===r);)this._current+=1;var r;return t.slice(e,this._current)}consumeQuotedIdentifier(t){const e=this._current;this._current+=1;const r=t.length;for(;'"'!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&'"'!==t[e+1]?e+=1:e+=2,this._current=e}this._current+=1;const[n,i]=this.parseJSON(t.slice(e,this._current));if(!i){const t=new Error("syntax: unexpected end of JSON input");throw t.name="LexerError",t}return n}consumeRawStringLiteral(t){const e=this._current;this._current+=1;const r=t.length;for(;"'"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"'"!==t[e+1]?e+=1:e+=2,this._current=e}this._current+=1;return t.slice(e+1,this._current-1).replace("\\'","'").replace("\\\\","\\")}consumeNumber(t){const r=this._current;this._current+=1;const n=t.length;for(;o(t[this._current])&&this._current<n;)this._current+=1;return{start:r,value:parseInt(t.slice(r,this._current),10),type:e.TOK_NUMBER}}consumeLBracket(t){const r=this._current;return this._current+=1,"?"===t[this._current]?(this._current+=1,{start:r,type:e.TOK_FILTER,value:"[?"}):"]"===t[this._current]?(this._current+=1,{start:r,type:e.TOK_FLATTEN,value:"[]"}):{start:r,type:e.TOK_LBRACKET,value:"["}}consumeOrElse(t,e,r,n){const i=this._current;return this._current+=1,this._current<t.length&&t[this._current]===e?(this._current+=1,{start:i,type:n,value:t.slice(i,this._current)}):{start:i,type:r,value:t[i]}}consumeOperator(t){switch(t[this._current]){case"!":return this.consumeOrElse(t,"=",e.TOK_NOT,e.TOK_NE);case"<":return this.consumeOrElse(t,"=",e.TOK_LT,e.TOK_LTE);case">":return this.consumeOrElse(t,"=",e.TOK_GT,e.TOK_GTE);case"=":return this.consumeOrElse(t,"=",e.TOK_ASSIGN,e.TOK_EQ);case"&":return this.consumeOrElse(t,"&",e.TOK_EXPREF,e.TOK_AND);case"|":return this.consumeOrElse(t,"|",e.TOK_PIPE,e.TOK_OR);case"/":return this.consumeOrElse(t,"/",e.TOK_DIVIDE,e.TOK_DIV)}}consumeLiteral(t){this._current+=1;const e=this._current,r=t.length;for(;"`"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"`"!==t[e+1]?e+=1:e+=2,this._current=e}let n=t.slice(e,this._current).trimStart();n=n.replace("\\`","`");let i=null,s=!1;if(this.looksLikeJSON(n)&&([i,s]=this.parseJSON(n)),!s&&this._enable_legacy_literals&&([i,s]=this.parseJSON(`"${n}"`)),!s){const e=new Error(`Syntax error: unexpected end of JSON input or invalid format for a JSON literal: ${t[this._current]}`);throw e.name="LexerError",e}return this._current+=1,i}looksLikeJSON(t){if(""===t)return!1;if('[{"'.includes(t[0]))return!0;if(["true","false","null"].includes(t))return!0;if("-0123456789".includes(t[0])){const[e,r]=this.parseJSON(t);return r}return!1}parseJSON(t){try{return[JSON.parse(t),!0]}catch(t){return[null,!1]}}},p={[e.TOK_EOF]:0,[e.TOK_VARIABLE]:0,[e.TOK_UNQUOTEDIDENTIFIER]:0,[e.TOK_QUOTEDIDENTIFIER]:0,[e.TOK_RBRACKET]:0,[e.TOK_RPAREN]:0,[e.TOK_COMMA]:0,[e.TOK_RBRACE]:0,[e.TOK_NUMBER]:0,[e.TOK_CURRENT]:0,[e.TOK_EXPREF]:0,[e.TOK_ROOT]:0,[e.TOK_ASSIGN]:1,[e.TOK_PIPE]:1,[e.TOK_OR]:2,[e.TOK_AND]:3,[e.TOK_EQ]:5,[e.TOK_GT]:5,[e.TOK_LT]:5,[e.TOK_GTE]:5,[e.TOK_LTE]:5,[e.TOK_NE]:5,[e.TOK_MINUS]:6,[e.TOK_PLUS]:6,[e.TOK_DIV]:7,[e.TOK_DIVIDE]:7,[e.TOK_MODULO]:7,[e.TOK_MULTIPLY]:7,[e.TOK_FLATTEN]:9,[e.TOK_STAR]:20,[e.TOK_FILTER]:21,[e.TOK_DOT]:40,[e.TOK_NOT]:45,[e.TOK_LBRACE]:50,[e.TOK_LBRACKET]:55,[e.TOK_LPAREN]:60};class R{constructor(){this.index=0,this.tokens=[]}parse(t,r){this.loadTokens(t,r||{enable_legacy_literals:!1}),this.index=0;const n=this.expression(0);if(this.lookahead(0)!==e.TOK_EOF){const t=this.lookaheadToken(0);this.errorToken(t,`Syntax error: unexpected token type: ${t.type}, value: ${t.value}`)}return n}loadTokens(t,r){this.tokens=[...E.tokenize(t,r),{type:e.TOK_EOF,value:"",start:t.length}]}expression(t){const e=this.lookaheadToken(0);this.advance();let r=this.nud(e),n=this.lookahead(0);for(;t<p[n];)this.advance(),r=this.led(n,r),n=this.lookahead(0);return r}lookahead(t){return this.tokens[this.index+t].type}lookaheadToken(t){return this.tokens[this.index+t]}advance(){this.index+=1}nud(t){switch(t.type){case e.TOK_VARIABLE:return{type:"Variable",name:t.value};case e.TOK_LITERAL:return{type:"Literal",value:t.value};case e.TOK_UNQUOTEDIDENTIFIER:return R.isKeyword(t,"let")&&this.lookahead(0)===e.TOK_VARIABLE?this.parseLetExpression():{type:"Field",name:t.value};case e.TOK_QUOTEDIDENTIFIER:if(this.lookahead(0)===e.TOK_LPAREN)throw new Error("Syntax error: quoted identifier not allowed for function names.");return{type:"Field",name:t.value};case e.TOK_NOT:return{type:"NotExpression",child:this.expression(p.Not)};case e.TOK_MINUS:{const e=this.expression(p.Minus);return{type:"Unary",operator:t.type,operand:e}}case e.TOK_PLUS:{const e=this.expression(p.Plus);return{type:"Unary",operator:t.type,operand:e}}case e.TOK_STAR:{const t={type:"Identity"};return{type:"ValueProjection",left:t,right:this.lookahead(0)===e.TOK_RBRACKET?t:this.parseProjectionRHS(p.Star)}}case e.TOK_FILTER:return this.led(t.type,{type:"Identity"});case e.TOK_LBRACE:return this.parseMultiselectHash();case e.TOK_FLATTEN:return{type:"Projection",left:{type:"Flatten",child:{type:"Identity"}},right:this.parseProjectionRHS(p.Flatten)};case e.TOK_LBRACKET:if(this.lookahead(0)===e.TOK_NUMBER||this.lookahead(0)===e.TOK_COLON){const t=this.parseIndexExpression();return this.projectIfSlice({type:"Identity"},t)}if(this.lookahead(0)===e.TOK_STAR&&this.lookahead(1)===e.TOK_RBRACKET){this.advance(),this.advance();return{left:{type:"Identity"},right:this.parseProjectionRHS(p.Star),type:"Projection"}}return this.parseMultiselectList();case e.TOK_CURRENT:return{type:e.TOK_CURRENT};case e.TOK_ROOT:return{type:e.TOK_ROOT};case e.TOK_EXPREF:return{type:"ExpressionReference",child:this.expression(p.Expref)};case e.TOK_LPAREN:{const t=[];for(;this.lookahead(0)!==e.TOK_RPAREN;){let r;this.lookahead(0)===e.TOK_CURRENT?(r={type:e.TOK_CURRENT},this.advance()):r=this.expression(0),t.push(r)}return this.match(e.TOK_RPAREN),t[0]}default:this.errorToken(t)}}led(t,r){switch(t){case e.TOK_DOT:{const t=p.Dot;if(this.lookahead(0)!==e.TOK_STAR){return{type:"Subexpression",left:r,right:this.parseDotRHS(t)}}this.advance();return{type:"ValueProjection",left:r,right:this.parseProjectionRHS(t)}}case e.TOK_PIPE:return{type:"Pipe",left:r,right:this.expression(p.Pipe)};case e.TOK_OR:return{type:"OrExpression",left:r,right:this.expression(p.Or)};case e.TOK_AND:return{type:"AndExpression",left:r,right:this.expression(p.And)};case e.TOK_LPAREN:if("Field"!==r.type)throw new Error("Syntax error: expected a Field node");return{name:r.name,type:"Function",children:this.parseCommaSeparatedExpressionsUntilToken(e.TOK_RPAREN)};case e.TOK_FILTER:{const t=this.expression(0);this.match(e.TOK_RBRACKET);return{type:"FilterProjection",left:r,right:this.lookahead(0)===e.TOK_FLATTEN?{type:"Identity"}:this.parseProjectionRHS(p.Filter),condition:t}}case e.TOK_FLATTEN:return{type:"Projection",left:{type:"Flatten",child:r},right:this.parseProjectionRHS(p.Flatten)};case e.TOK_ASSIGN:{const t=r,e=this.expression(0);return{type:"Binding",variable:t.name,reference:e}}case e.TOK_EQ:case e.TOK_NE:case e.TOK_GT:case e.TOK_GTE:case e.TOK_LT:case e.TOK_LTE:return this.parseComparator(r,t);case e.TOK_PLUS:case e.TOK_MINUS:case e.TOK_MULTIPLY:case e.TOK_STAR:case e.TOK_DIVIDE:case e.TOK_MODULO:case e.TOK_DIV:return this.parseArithmetic(r,t);case e.TOK_LBRACKET:{const t=this.lookaheadToken(0);if(t.type===e.TOK_NUMBER||t.type===e.TOK_COLON){const t=this.parseIndexExpression();return this.projectIfSlice(r,t)}this.match(e.TOK_STAR),this.match(e.TOK_RBRACKET);return{type:"Projection",left:r,right:this.parseProjectionRHS(p.Star)}}default:return this.errorToken(this.lookaheadToken(0))}}static isKeyword(t,r){return t.type===e.TOK_UNQUOTEDIDENTIFIER&&t.value===r}match(t){if(this.lookahead(0)!==t){const e=this.lookaheadToken(0);this.errorToken(e,`Syntax error: expected ${t}, got: ${e.type}`)}else this.advance()}errorToken(t,e=""){const r=new Error(e||`Syntax error: invalid token (${t.type}): "${t.value}"`);throw r.name="ParserError",r}parseIndexExpression(){if(this.lookahead(0)===e.TOK_COLON||this.lookahead(1)===e.TOK_COLON)return this.parseSliceExpression();const t=Number(this.lookaheadToken(0).value);return this.advance(),this.match(e.TOK_RBRACKET),{type:"Index",value:t}}projectIfSlice(t,e){const r={type:"IndexExpression",left:t,right:e};return"Slice"===e.type?{left:r,right:this.parseProjectionRHS(p.Star),type:"Projection"}:r}parseSliceExpression(){const t=[null,null,null];let r=0,n=this.lookaheadToken(0);for(;n.type!=e.TOK_RBRACKET&&r<3;){if(n.type===e.TOK_COLON)r++,3===r&&this.errorToken(this.lookaheadToken(0),"Syntax error, too many colons in slice expression"),this.advance();else if(n.type===e.TOK_NUMBER){const e=this.lookaheadToken(0).value;t[r]=e,this.advance()}else{const t=this.lookaheadToken(0);this.errorToken(t,`Syntax error, unexpected token: ${t.value}(${t.type})`)}n=this.lookaheadToken(0)}this.match(e.TOK_RBRACKET);const[i,s,o]=t;return{type:"Slice",start:i,stop:s,step:o}}parseLetExpression(){const t=this.parseCommaSeparatedExpressionsUntilKeyword("in"),e=this.expression(0);return{type:"LetExpression",bindings:t.map((t=>t)),expression:e}}parseCommaSeparatedExpressionsUntilKeyword(t){return this.parseCommaSeparatedExpressionsUntil((()=>R.isKeyword(this.lookaheadToken(0),t)),(()=>{this.advance()}))}parseCommaSeparatedExpressionsUntilToken(t){return this.parseCommaSeparatedExpressionsUntil((()=>this.lookahead(0)===t),(()=>this.match(t)))}parseCommaSeparatedExpressionsUntil(t,r){const n=[];let i;for(;!t();)i=this.expression(0),this.lookahead(0)===e.TOK_COMMA&&this.match(e.TOK_COMMA),n.push(i);return r(),n}parseComparator(t,e){return{type:"Comparator",name:e,left:t,right:this.expression(p[e])}}parseArithmetic(t,e){return{type:"Arithmetic",operator:e,left:t,right:this.expression(p[e])}}parseDotRHS(t){const r=this.lookahead(0);if([e.TOK_UNQUOTEDIDENTIFIER,e.TOK_QUOTEDIDENTIFIER,e.TOK_STAR].includes(r))return this.expression(t);if(r===e.TOK_LBRACKET)return this.match(e.TOK_LBRACKET),this.parseMultiselectList();if(r===e.TOK_LBRACE)return this.match(e.TOK_LBRACE),this.parseMultiselectHash();const n=this.lookaheadToken(0);this.errorToken(n,`Syntax error, unexpected token: ${n.value}(${n.type})`)}parseProjectionRHS(t){if(p[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===e.TOK_LBRACKET)return this.expression(t);if(this.lookahead(0)===e.TOK_FILTER)return this.expression(t);if(this.lookahead(0)===e.TOK_DOT)return this.match(e.TOK_DOT),this.parseDotRHS(t);const r=this.lookaheadToken(0);this.errorToken(r,`Syntax error, unexpected token: ${r.value}(${r.type})`)}parseMultiselectList(){const t=[];for(;this.lookahead(0)!==e.TOK_RBRACKET;){const r=this.expression(0);if(t.push(r),this.lookahead(0)===e.TOK_COMMA&&(this.match(e.TOK_COMMA),this.lookahead(0)===e.TOK_RBRACKET))throw new Error("Syntax error: unexpected token Rbracket")}return this.match(e.TOK_RBRACKET),{type:"MultiSelectList",children:t}}parseMultiselectHash(){const t=[],r=[e.TOK_UNQUOTEDIDENTIFIER,e.TOK_QUOTEDIDENTIFIER];let n,i,s;for(;;){if(n=this.lookaheadToken(0),!r.includes(n.type))throw new Error(`Syntax error: expecting an identifier token, got: ${n.type}`);if(i=n.value,this.advance(),this.match(e.TOK_COLON),s=this.expression(0),t.push({value:s,type:"KeyValuePair",name:i}),this.lookahead(0)===e.TOK_COMMA)this.match(e.TOK_COMMA);else if(this.lookahead(0)===e.TOK_RBRACE){this.match(e.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:t}}}const f=new R;class O{constructor(t){this._text=t}get string(){return this._text}get length(){return this.codePoints.length}compareTo(t){return O.compare(this,new O(t))}static get comparer(){return(t,e)=>new O(t).compareTo(e)}static compare(t,e){const r=t.codePoints,n=e.codePoints;for(let t=0;t<Math.min(r.length,n.length);t++)if(r[t]!==n[t])return r[t]-n[t]>0?1:-1;return r.length-n.length>0?1:-1}reverse(){return String.fromCodePoint(...this.codePoints.reverse())}get codePoints(){return[...this._text].map((t=>t.codePointAt(0)))}}const A=(t,e,r)=>{if((r=r||" ").length>1)throw new Error(`invalid value, ${t} expects its 'pad' parameter to be a valid string with a single codepoint`);return u(e),r},y=(t,e)=>P(t,(t=>new RegExp(`^[${t}]*(.*?)`)),e),d=(t,e)=>P(t,(t=>new RegExp(`(.*?)[${t}]*$`)),e),P=(t,e,r)=>{const n=r?r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"):"\\s
";return t.replace(e(n),"$1")};var Y;!function(t){t[t.TYPE_NUMBER=0]="TYPE_NUMBER",t[t.TYPE_ANY=1]="TYPE_ANY",t[t.TYPE_STRING=2]="TYPE_STRING",t[t.TYPE_ARRAY=3]="TYPE_ARRAY",t[t.TYPE_OBJECT=4]="TYPE_OBJECT",t[t.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",t[t.TYPE_EXPREF=6]="TYPE_EXPREF",t[t.TYPE_NULL=7]="TYPE_NULL",t[t.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",t[t.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING",t[t.TYPE_ARRAY_OBJECT=10]="TYPE_ARRAY_OBJECT",t[t.TYPE_ARRAY_ARRAY=11]="TYPE_ARRAY_ARRAY"}(Y||(Y={}));class N{constructor(t){this.TYPE_NAME_TABLE={[Y.TYPE_NUMBER]:"number",[Y.TYPE_ANY]:"any",[Y.TYPE_STRING]:"string",[Y.TYPE_ARRAY]:"array",[Y.TYPE_OBJECT]:"object",[Y.TYPE_BOOLEAN]:"boolean",[Y.TYPE_EXPREF]:"expression",[Y.TYPE_NULL]:"null",[Y.TYPE_ARRAY_NUMBER]:"Array<number>",[Y.TYPE_ARRAY_OBJECT]:"Array<object>",[Y.TYPE_ARRAY_STRING]:"Array<string>",[Y.TYPE_ARRAY_ARRAY]:"Array<Array<any>>"},this.functionAbs=([t])=>Math.abs(t),this.functionAvg=([t])=>{if(!t||0==t.length)return null;let e=0;for(let r=0;r<t.length;r+=1)e+=t[r];return e/t.length},this.functionCeil=([t])=>Math.ceil(t),this.functionContains=([t,e])=>{if(Array.isArray(t)){return t.includes(e)}if("string"==typeof t){if("string"==typeof e)return t.includes(e)}return null},this.functionEndsWith=t=>{const[e,r]=t;return e.includes(r,e.length-r.length)},this.functionFindFirst=t=>((t,e,r,n)=>{if(!t||!e)return null;r=Math.max(a(r=r||0),0),n=Math.min(a(n=n||t.length),t.length);const i=t.slice(r,n).indexOf(e);return-1===i?null:i+r})(t[0],t[1],t.length>2&&t[2]||void 0,t.length>3&&t[3]||void 0),this.functionFindLast=t=>((t,e,r,n)=>{if(!t||!e)return null;r=Math.max(a(r=r||0),0),n=Math.min(a(n=n||t.length),t.length);const i=t.slice(r,n).lastIndexOf(e);return-1===i?null:i+r})(t[0],t[1],t.length>2&&t[2]||void 0,t.length>3&&t[3]||void 0),this.functionFloor=([t])=>Math.floor(t),this.functionFromItems=([t])=>(t.map((t=>{if(2!=t.length||"string"!=typeof t[0])throw new Error("invalid value, each array must contain two elements, a pair of string and value")})),Object.fromEntries(t)),this.functionGroupBy=([t,e])=>{const r=this.createKeyFunction(e,[Y.TYPE_STRING]);return t.reduce(((t,e)=>{const n=r(null!=e?e:{});return(t[n]=t[n]||[]).push(e),t}),{})},this.functionItems=([t])=>Object.entries(t),this.functionJoin=t=>{const[e,r]=t;return r.join(e)},this.functionKeys=([t])=>Object.keys(t),this.functionLength=([t])=>"string"==typeof t?new O(t).length:Array.isArray(t)?t.length:Object.keys(t).length,this.functionLower=([t])=>(t=>t.toLowerCase())(t),this.functionMap=([t,e])=>{if(!this._interpreter)return[];const r=[],n=this._interpreter;for(let i=0;i<e.length;i+=1)r.push(n.visit(t,e[i]));return r},this.functionMax=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===Y.TYPE_NUMBER)return Math.max(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)r.localeCompare(e[t])<0&&(r=e[t]);return r},this.functionMaxBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[Y.TYPE_NUMBER,Y.TYPE_STRING]);let i,s,o=-1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s>o&&(o=s,i=r[t]);return i||null},this.functionMerge=t=>{let e={};for(let r=0;r<t.length;r+=1){const n=t[r];e=Object.assign(e,n)}return e},this.functionMin=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===Y.TYPE_NUMBER)return Math.min(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)e[t].localeCompare(r)<0&&(r=e[t]);return r},this.functionMinBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[Y.TYPE_NUMBER,Y.TYPE_STRING]);let i,s,o=1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s<o&&(o=s,i=r[t]);return i||null},this.functionNotNull=t=>{for(let e=0;e<t.length;e+=1)if(this.getTypeName(t[e])!==Y.TYPE_NULL)return t[e];return null},this.functionPadLeft=t=>((t,e,r)=>(r=A("pad_left",e,r),t&&t.padStart(e,r)||""))(t[0],t[1],t.length>2&&t[2]||void 0),this.functionPadRight=t=>((t,e,r)=>(r=A("pad_right",e,r),t&&t.padEnd(e,r)||""))(t[0],t[1],t.length>2&&t[2]||void 0),this.functionReplace=t=>((t,e,r,n)=>0===n?t:n?(u(n),[...Array(n).keys()].map((()=>t=t.replace(e,r))),t):t.split(e).join(r))(t[0],t[1],t[2],t.length>3?t[3]:void 0),this.functionSplit=t=>((t,e,r)=>{if(0==t.length&&0===e.length)return[];if(null==r)return t.split(e);if(u(r),0===r)return[t];const n=t.split(e);return[...n.slice(0,r),n.slice(r).join(e)]})(t[0],t[1],t.length>2?t[2]:void 0),this.functionReverse=([t])=>{if(this.getTypeName(t)===Y.TYPE_STRING)return new O(t).reverse();const e=t.slice(0);return e.reverse(),e},this.functionSort=([t])=>0==t.length?t:"string"==typeof t[0]?[...t].sort(O.comparer):[...t].sort(),this.functionSortBy=t=>{const e=t[0].slice(0);if(0===e.length)return e;const r=this._interpreter,n=t[1],i=this.getTypeName(r.visit(n,e[0]));if(void 0!==i&&![Y.TYPE_NUMBER,Y.TYPE_STRING].includes(i))throw new Error(`Invalid type: unexpected type (${this.TYPE_NAME_TABLE[i]})`);function s(t,e){throw new Error(`Invalid type: expected (${t.TYPE_NAME_TABLE[i]}), received ${t.TYPE_NAME_TABLE[t.getTypeName(e)]}`)}return e.sort(((t,e)=>{const o=r.visit(n,t),a=r.visit(n,e);return this.getTypeName(o)!==i?s(this,o):this.getTypeName(a)!==i&&s(this,a),i===Y.TYPE_STRING?O.comparer(o,a):o-a}))},this.functionStartsWith=([t,e])=>t.startsWith(e),this.functionSum=([t])=>t.reduce(((t,e)=>t+e),0),this.functionToArray=([t])=>this.getTypeName(t)===Y.TYPE_ARRAY?t:[t],this.functionToNumber=([t])=>{const e=this.getTypeName(t);let r;return e===Y.TYPE_NUMBER?t:e!==Y.TYPE_STRING||(r=+t,isNaN(r))?null:r},this.functionToString=([t])=>this.getTypeName(t)===Y.TYPE_STRING?t:JSON.stringify(t),this.functionTrim=t=>((t,e)=>y(d(t,e),e))(t[0],t.length>1?t[1]:void 0),this.functionTrimLeft=t=>{const e=t[0];return y(e,t.length>1?t[1]:void 0)},this.functionTrimRight=t=>{const e=t[0];return d(e,t.length>1?t[1]:void 0)},this.functionType=([t])=>{switch(this.getTypeName(t)){case Y.TYPE_NUMBER:return"number";case Y.TYPE_STRING:return"string";case Y.TYPE_ARRAY:return"array";case Y.TYPE_OBJECT:return"object";case Y.TYPE_BOOLEAN:return"boolean";case Y.TYPE_NULL:return"null";default:throw new Error("invalid-type")}},this.functionUpper=([t])=>(t=>t.toUpperCase())(t),this.functionValues=([t])=>Object.values(t),this.functionZip=t=>{const e=Math.min(...t.map((t=>t.length)));return Array(e).fill(null).map(((e,r)=>t.map((t=>t[r]))))},this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[Y.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[Y.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[Y.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[Y.TYPE_STRING,Y.TYPE_ARRAY]},{types:[Y.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]}]},find_first:{_func:this.functionFindFirst,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]},{types:[Y.TYPE_NUMBER],optional:!0},{types:[Y.TYPE_NUMBER],optional:!0}]},find_last:{_func:this.functionFindLast,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]},{types:[Y.TYPE_NUMBER],optional:!0},{types:[Y.TYPE_NUMBER],optional:!0}]},floor:{_func:this.functionFloor,_signature:[{types:[Y.TYPE_NUMBER]}]},from_items:{_func:this.functionFromItems,_signature:[{types:[Y.TYPE_ARRAY_ARRAY]}]},group_by:{_func:this.functionGroupBy,_signature:[{types:[Y.TYPE_ARRAY]},{types:[Y.TYPE_EXPREF]}]},items:{_func:this.functionItems,_signature:[{types:[Y.TYPE_OBJECT]}]},join:{_func:this.functionJoin,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[Y.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[Y.TYPE_STRING,Y.TYPE_ARRAY,Y.TYPE_OBJECT]}]},lower:{_func:this.functionLower,_signature:[{types:[Y.TYPE_STRING]}]},map:{_func:this.functionMap,_signature:[{types:[Y.TYPE_EXPREF]},{types:[Y.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[Y.TYPE_ARRAY_NUMBER,Y.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[Y.TYPE_ARRAY]},{types:[Y.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[Y.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[Y.TYPE_ARRAY_NUMBER,Y.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[Y.TYPE_ARRAY]},{types:[Y.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[Y.TYPE_ANY],variadic:!0}]},pad_left:{_func:this.functionPadLeft,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_NUMBER]},{types:[Y.TYPE_STRING],optional:!0}]},pad_right:{_func:this.functionPadRight,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_NUMBER]},{types:[Y.TYPE_STRING],optional:!0}]},replace:{_func:this.functionReplace,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]},{types:[Y.TYPE_NUMBER],optional:!0}]},split:{_func:this.functionSplit,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]},{types:[Y.TYPE_NUMBER],optional:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[Y.TYPE_STRING,Y.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[Y.TYPE_ARRAY_STRING,Y.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[Y.TYPE_ARRAY]},{types:[Y.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[Y.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[Y.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[Y.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[Y.TYPE_ANY]}]},trim:{_func:this.functionTrim,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING],optional:!0}]},trim_left:{_func:this.functionTrimLeft,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING],optional:!0}]},trim_right:{_func:this.functionTrimRight,_signature:[{types:[Y.TYPE_STRING]},{types:[Y.TYPE_STRING],optional:!0}]},type:{_func:this.functionType,_signature:[{types:[Y.TYPE_ANY]}]},upper:{_func:this.functionUpper,_signature:[{types:[Y.TYPE_STRING]}]},values:{_func:this.functionValues,_signature:[{types:[Y.TYPE_OBJECT]}]},zip:{_func:this.functionZip,_signature:[{types:[Y.TYPE_ARRAY],variadic:!0}]}},this._interpreter=t}registerFunction(t,e,r){if(t in this.functionTable)throw new Error(`Function already defined: ${t}()`);this.functionTable[t]={_func:e.bind(this),_signature:r}}callFunction(t,e){const r=this.functionTable[t];if(void 0===r)throw new Error(`Unknown function: ${t}()`);return this.validateArgs(t,e,r._signature),r._func.call(this,e)}validateInputSignatures(t,e){for(let r=0;r<e.length;r+=1)if("variadic"in e[r]&&r!==e.length-1)throw new Error(`Invalid arity: ${t}() 'variadic' argument ${r+1} must occur last`)}validateArgs(t,e,r){var n,i;let s;this.validateInputSignatures(t,r);const o=r.filter((t=>{var e;return null!==(e=!t.optional)&&void 0!==e&&e})).length,a=null!==(i=null===(n=r[r.length-1])||void 0===n?void 0:n.variadic)&&void 0!==i&&i,u=e.length<o,c=e.length>r.length,h=u&&(!a&&o>1||a)?"at least ":"";if(a&&u||!a&&(u||c))throw s=r.length>1,new Error(`Invalid arity: ${t}() takes ${h}${o} argument${s?"s":""} but received ${e.length}`);let T,_,l;for(let n=0;n<r.length;n+=1){let i;for(l=!1,T=r[n].types,_=this.getTypeName(e[n]),i=0;i<T.length;i+=1)if(void 0!==_&&this.typeMatches(_,T[i],e[n])){l=!0;break}if(!l&&void 0!==_){const e=T.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ");throw new Error(`Invalid type: ${t}() expected argument ${n+1} to be type (${e}) but received type ${this.TYPE_NAME_TABLE[_]} instead.`)}}}typeMatches(t,e,r){if(e===Y.TYPE_ANY)return!0;if(e!==Y.TYPE_ARRAY_STRING&&e!==Y.TYPE_ARRAY_NUMBER&&e!==Y.TYPE_ARRAY_OBJECT&&e!==Y.TYPE_ARRAY_ARRAY&&e!==Y.TYPE_ARRAY)return t===e;if(e===Y.TYPE_ARRAY)return t===Y.TYPE_ARRAY;if(t===Y.TYPE_ARRAY){let t;e===Y.TYPE_ARRAY_NUMBER?t=Y.TYPE_NUMBER:e===Y.TYPE_ARRAY_OBJECT?t=Y.TYPE_OBJECT:e===Y.TYPE_ARRAY_STRING?t=Y.TYPE_STRING:e===Y.TYPE_ARRAY_ARRAY&&(t=Y.TYPE_ARRAY);const n=r;for(let e=0;e<n.length;e+=1){const r=this.getTypeName(n[e]);if(void 0!==r&&void 0!==t&&!this.typeMatches(r,t,n[e]))return!1}return!0}return!1}getTypeName(t){switch(Object.prototype.toString.call(t)){case"[object String]":return Y.TYPE_STRING;case"[object Number]":return Y.TYPE_NUMBER;case"[object Array]":return Y.TYPE_ARRAY;case"[object Boolean]":return Y.TYPE_BOOLEAN;case"[object Null]":return Y.TYPE_NULL;case"[object Object]":return t.expref?Y.TYPE_EXPREF:Y.TYPE_OBJECT;default:return}}createKeyFunction(t,e){const r=this._interpreter;return n=>{const i=r.visit(t,n);if(!e.includes(this.getTypeName(i))){const t=`Invalid type: expected one of (${e.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(i)]}`;throw new Error(t)}return i}}}class g{constructor(){this.inner=void 0,this.data={}}withScope(t){const e=new g;return e.inner=this,e.data=t,e}getValue(t){if(t in this.data){const e=this.data[t];if(null!=e)return e}return this.inner?this.inner.getValue(t):null}}class K{constructor(){this._rootValue=null,this.runtime=new N(this),this._scope=new g}withScope(t){const e=new K;return e._rootValue=this._rootValue,e._scope=this._scope.withScope(t),e}search(t,e){return this._rootValue=e,this._scope=new g,this.visit(t,e)}visit(t,r){var s,o,a,u,T;switch(t.type){case"Field":const _=t.name;let l=null;return null===r||"object"!=typeof r||Array.isArray(r)||(l=null!==(s=r[_])&&void 0!==s?s:null),l;case"LetExpression":{const{bindings:e,expression:n}=t;let i={};return e.forEach((t=>{const e=this.visit(t,r);i=Object.assign(Object.assign({},i),e)})),this.withScope(i).visit(n,r)}case"Binding":{const{variable:e,reference:n}=t;return{[e]:this.visit(n,r)}}case"Variable":{const e=t.name,r=null!==(o=this._scope.getValue(e))&&void 0!==o?o:null;if(null==r)throw new Error(`Error referencing undefined variable ${e}`);return r}case"IndexExpression":return this.visit(t.right,this.visit(t.left,r));case"Subexpression":{const e=this.visit(t.left,r);return null!=e&&this.visit(t.right,e)||null}case"Index":{if(!Array.isArray(r))return null;const e=t.value<0?r.length+t.value:t.value;return null!==(a=r[e])&&void 0!==a?a:null}case"Slice":{if(!Array.isArray(r)&&"string"!=typeof r)return null;const{start:e,stop:n,step:i}=this.computeSliceParams(r.length,t);if("string"==typeof r){const t=[...r];return this.slice(t,e,n,i).join("")}return this.slice(r,e,n,i)}case"Projection":{const{left:e,right:n}=t;let i=!1;"IndexExpression"===e.type&&"Slice"===e.right.type&&(i=!0);const s=this.visit(e,r);if(i&&"string"==typeof s)return this.visit(n,s);if(!Array.isArray(s))return null;const o=[];for(const t of s){const e=this.visit(n,t);null!==e&&o.push(e)}return o}case"ValueProjection":{const{left:e,right:n}=t,i=this.visit(e,r);if(null===i||"object"!=typeof i||Array.isArray(i))return null;const s=[],o=Object.values(i);for(const t of o){const e=this.visit(n,t);null!==e&&s.push(e)}return s}case"FilterProjection":{const{left:e,right:n,condition:s}=t,o=this.visit(e,r);if(!Array.isArray(o))return null;const a=[];for(const t of o){const e=this.visit(s,t);if(i(e))continue;const r=this.visit(n,t);null!==r&&a.push(r)}return a}case"Arithmetic":{const n=this.visit(t.left,r),i=this.visit(t.right,r);switch(t.operator){case e.TOK_PLUS:return c(u=n,T=i),u+T;case e.TOK_MINUS:return((t,e)=>(c(t,e),t-e))(n,i);case e.TOK_MULTIPLY:case e.TOK_STAR:return((t,e)=>(c(t,e),t*e))(n,i);case e.TOK_DIVIDE:return((t,e)=>(c(t,e),t/h(e)))(n,i);case e.TOK_MODULO:return((t,e)=>(c(t,e),t%e))(n,i);case e.TOK_DIV:return((t,e)=>(c(t,e),Math.floor(t/h(e))))(n,i);default:throw new Error(`Syntax error: unknown arithmetic operator: ${t.operator}`)}}case"Unary":{const n=this.visit(t.operand,r);switch(t.operator){case e.TOK_PLUS:return c(n),n;case e.TOK_MINUS:return c(n),-n;default:throw new Error(`Syntax error: unknown arithmetic operator: ${t.operator}`)}}case"Comparator":{const e=this.visit(t.left,r),i=this.visit(t.right,r);switch(t.name){case"EQ":return n(e,i);case"NE":return!n(e,i)}if("number"!=typeof e||"number"!=typeof i)return null;switch(t.name){case"GT":return e>i;case"GTE":return e>=i;case"LT":return e<i;case"LTE":return e<=i}}case"Flatten":{const e=this.visit(t.child,r);return Array.isArray(e)?e.flat():null}case"Root":return this._rootValue;case"MultiSelectList":{const e=[];for(const n of t.children)e.push(this.visit(n,r));return e}case"MultiSelectHash":{const e={};for(const n of t.children)e[n.name]=this.visit(n.value,r);return e}case"OrExpression":{const e=this.visit(t.left,r);return i(e)?this.visit(t.right,r):e}case"AndExpression":{const e=this.visit(t.left,r);return i(e)?e:this.visit(t.right,r)}case"NotExpression":return i(this.visit(t.child,r));case"Literal":return t.value;case"Pipe":return this.visit(t.right,this.visit(t.left,r));case"Function":{const e=[];for(const n of t.children)e.push(this.visit(n,r));return this.runtime.callFunction(t.name,e)}case"ExpressionReference":return Object.assign({expref:!0},t.child);case"Current":case"Identity":return r}}computeSliceParams(t,e){let{start:r,stop:n,step:i}=e;if(null===i)i=1;else if(0===i){const t=new Error("Invalid value: slice step cannot be 0");throw t.name="RuntimeError",t}return r=null===r?i<0?t-1:0:this.capSliceRange(t,r,i),n=null===n?i<0?-1:t:this.capSliceRange(t,n,i),{start:r,stop:n,step:i}}capSliceRange(t,e,r){let n=e;return n<0?(n+=t,n<0&&(n=r<0?-1:0)):n>=t&&(n=r<0?t-1:t),n}slice(t,e,r,n){const i=[];if(n>0)for(let s=e;s<r;s+=n)i.push(t[s]);else for(let s=e;s>r;s+=n)i.push(t[s]);return i}}const m=new K,I=Y.TYPE_ANY,S=Y.TYPE_ARRAY,v=Y.TYPE_ARRAY_ARRAY,L=Y.TYPE_ARRAY_NUMBER,M=Y.TYPE_ARRAY_OBJECT,B=Y.TYPE_ARRAY_STRING,x=Y.TYPE_BOOLEAN,U=Y.TYPE_EXPREF,k=Y.TYPE_NULL,w=Y.TYPE_NUMBER,C=Y.TYPE_OBJECT,b=Y.TYPE_STRING;function F(t,e){return f.parse(t,e)}function G(t,e){return E.tokenize(t,e)}const D=(t,e,r)=>{m.runtime.registerFunction(t,e,r)};function j(t,e,r){const n=f.parse(e,r);return m.search(n,t)}const $=m,J={compile:F,registerFunction:D,search:j,tokenize:G,TreeInterpreter:$,TYPE_ANY:I,TYPE_ARRAY_NUMBER:L,TYPE_ARRAY_STRING:B,TYPE_ARRAY:S,TYPE_BOOLEAN:x,TYPE_EXPREF:U,TYPE_NULL:k,TYPE_NUMBER:w,TYPE_OBJECT:C,TYPE_STRING:b};t.Scope=function(){return new g},t.TYPE_ANY=I,t.TYPE_ARRAY=S,t.TYPE_ARRAY_ARRAY=v,t.TYPE_ARRAY_NUMBER=L,t.TYPE_ARRAY_OBJECT=M,t.TYPE_ARRAY_STRING=B,t.TYPE_BOOLEAN=x,t.TYPE_EXPREF=U,t.TYPE_NULL=k,t.TYPE_NUMBER=w,t.TYPE_OBJECT=C,t.TYPE_STRING=b,t.TreeInterpreter=$,t.compile=F,t.default=J,t.jmespath=J,t.registerFunction=D,t.search=j,t.tokenize=G,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=jmespath.umd.min.js.map
|