@aws-lambda-powertools/jmespath 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Functions.d.ts.map +1 -1
- package/lib/cjs/Functions.js +26 -39
- package/lib/cjs/Lexer.d.ts.map +1 -1
- package/lib/cjs/Lexer.js +10 -18
- package/lib/cjs/ParsedResult.d.ts +1 -1
- package/lib/cjs/ParsedResult.d.ts.map +1 -1
- package/lib/cjs/Parser.d.ts.map +1 -1
- package/lib/cjs/Parser.js +51 -74
- package/lib/cjs/TreeInterpreter.d.ts +1 -1
- package/lib/cjs/TreeInterpreter.d.ts.map +1 -1
- package/lib/cjs/TreeInterpreter.js +8 -14
- package/lib/cjs/constants.js +2 -2
- package/lib/cjs/envelopes.js +2 -5
- package/lib/cjs/types.d.ts +2 -2
- package/lib/cjs/types.d.ts.map +1 -1
- package/lib/cjs/utils.d.ts.map +1 -1
- package/lib/cjs/utils.js +12 -11
- package/lib/esm/Functions.d.ts.map +1 -1
- package/lib/esm/Functions.js +26 -39
- package/lib/esm/Lexer.d.ts.map +1 -1
- package/lib/esm/Lexer.js +10 -18
- package/lib/esm/ParsedResult.d.ts +1 -1
- package/lib/esm/ParsedResult.d.ts.map +1 -1
- package/lib/esm/Parser.d.ts.map +1 -1
- package/lib/esm/Parser.js +52 -75
- package/lib/esm/TreeInterpreter.d.ts +1 -1
- package/lib/esm/TreeInterpreter.d.ts.map +1 -1
- package/lib/esm/TreeInterpreter.js +8 -14
- package/lib/esm/constants.js +2 -2
- package/lib/esm/envelopes.js +2 -5
- package/lib/esm/types.d.ts +2 -2
- package/lib/esm/types.d.ts.map +1 -1
- package/lib/esm/utils.d.ts.map +1 -1
- package/lib/esm/utils.js +13 -12
- package/package.json +2 -2
package/lib/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":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AAEF;;GAEG;AACH,KAAK,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAEjD,YAAY,EACV,0BAA0B,EAC1B,wBAAwB,EACxB,IAAI,EACJ,sBAAsB,EACtB,KAAK,EACL,UAAU,GACX,CAAC"}
|
package/lib/cjs/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,QAAA,MAAM,QAAQ,UAAW,OAAO,KAAG,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,QAAA,MAAM,QAAQ,UAAW,OAAO,KAAG,OAKlC,CAAC;AA6BF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,UAAU,oCAKb;IACD,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,KAAG,CAAC,EAAE,GAAG,IA0BT,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,UAAU,SACR,OAAO,EAAE,kBACC,MAAM,MAAM,MAAM,CAAC,CAAC,aACzB,OAAO,KACjB,IAcF,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,QAAA,MAAM,SAAS,SACP,OAAO,EAAE,kBACC,MAAM,MAAM,MAAM,CAAC,CAAC,KACnC,IAKF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,iBAAiB,QAAS,OAAO,gBAAgB,MAAM,MAAM,CAAC,KAAG,IAMtE,CAAC;AA+IF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/cjs/utils.js
CHANGED
|
@@ -18,9 +18,7 @@ const isTruthy = (value) => {
|
|
|
18
18
|
if ((0, typeutils_1.isNumber)(value)) {
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
return (0, typeutils_1.isTruthy)(value);
|
|
23
|
-
}
|
|
21
|
+
return (0, typeutils_1.isTruthy)(value);
|
|
24
22
|
};
|
|
25
23
|
exports.isTruthy = isTruthy;
|
|
26
24
|
/**
|
|
@@ -33,16 +31,17 @@ exports.isTruthy = isTruthy;
|
|
|
33
31
|
* @param isStepNegative Whether the step is negative
|
|
34
32
|
*/
|
|
35
33
|
const capSliceRange = (arrayLength, value, isStepNegative) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
let capValue = value;
|
|
35
|
+
if (capValue < 0) {
|
|
36
|
+
capValue += arrayLength;
|
|
37
|
+
if (capValue < 0) {
|
|
38
|
+
capValue = isStepNegative ? -1 : 0;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
|
-
else if (
|
|
43
|
-
|
|
41
|
+
else if (capValue >= arrayLength) {
|
|
42
|
+
capValue = isStepNegative ? arrayLength - 1 : arrayLength;
|
|
44
43
|
}
|
|
45
|
-
return
|
|
44
|
+
return capValue;
|
|
46
45
|
};
|
|
47
46
|
/**
|
|
48
47
|
* Given a start, stop, and step value, the sub elements in an array are extracted as follows:
|
|
@@ -196,8 +195,9 @@ const checkIfArgumentTypeIsValid = (arg, type, index, argumentSpec) => {
|
|
|
196
195
|
checkExpressionType(arg, argumentSpec, hasMoreTypesToCheck);
|
|
197
196
|
return true;
|
|
198
197
|
}
|
|
199
|
-
|
|
198
|
+
if (['string', 'number', 'boolean'].includes(type)) {
|
|
200
199
|
typeCheckType(arg, type, argumentSpec, hasMoreTypesToCheck);
|
|
200
|
+
// biome-ignore lint/suspicious/useValidTypeof: we know that `type` is one of 'string', 'number', or 'boolean' because we checked for that above
|
|
201
201
|
if (typeof arg === type)
|
|
202
202
|
return true;
|
|
203
203
|
}
|
|
@@ -216,6 +216,7 @@ const checkIfArgumentTypeIsValid = (arg, type, index, argumentSpec) => {
|
|
|
216
216
|
* @param hasMoreTypesToCheck Whether there are more types to check
|
|
217
217
|
*/
|
|
218
218
|
const typeCheckType = (arg, type, argumentSpec, hasMoreTypesToCheck) => {
|
|
219
|
+
// biome-ignore lint/suspicious/useValidTypeof: we know that `type` is one of 'string', 'number', or 'boolean' because we checked before calling this function
|
|
219
220
|
if (typeof arg !== type && !hasMoreTypesToCheck) {
|
|
220
221
|
throw new errors_js_1.JMESPathTypeError({
|
|
221
222
|
currentValue: arg,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Functions.d.ts","sourceRoot":"","sources":["../../src/Functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACV,MAAM,sCAAsC,CAAC;AAM9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EAEzB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,cAAM,SAAS;IACb;;OAEG;IACI,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAExC;;;;OAIG;IAEI,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIpC;;;;OAIG;IAII,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM;IAI3C;;;;OAIG;IAEI,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIrC;;;;;OAKG;IAII,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAI9D;;;;;OAKG;IAII,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAIzD;;;;OAI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,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IAenE;;;;;OAKG;IAII,UAAU,CACf,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EACtB,UAAU,EAAE,UAAU,GACrB,KAAK,CAAC,OAAO,CAAC;IAgCjB;;;;;OAKG;IAII,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAI3D;;;;OAIG;IAII,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM;IAI3C;;;;;;;OAOG;IAII,WAAW,CAChB,GAAG,EAAE,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,GAChC,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS;IAI/B;;;;;;;;;OASG;IAII,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI;IAYlD;;;;;;;OAOG;IAII,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM;IAI3C;;;;OAIG;IAII,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM;IAIvC;;;;OAIG;IAII,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,EAAE;IAI/C;;;;;;;;;;;;;;;;OAgBG;IACI,iBAAiB,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;IA8BxD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACW,SAAS,CACrB,OAAO,EAAE,wBAAwB,GAChC,0BAA0B;CAiB9B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/lib/esm/Functions.js
CHANGED
|
@@ -118,9 +118,7 @@ class Functions {
|
|
|
118
118
|
if (isRecord(arg)) {
|
|
119
119
|
return Object.keys(arg).length;
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
return arg.length;
|
|
123
|
-
}
|
|
121
|
+
return arg.length;
|
|
124
122
|
}
|
|
125
123
|
/**
|
|
126
124
|
* Map the provided function over the provided array.
|
|
@@ -143,13 +141,11 @@ class Functions {
|
|
|
143
141
|
return null;
|
|
144
142
|
// The signature decorator already enforces that all elements are of the same type
|
|
145
143
|
}
|
|
146
|
-
|
|
144
|
+
if (isNumber(arg[0])) {
|
|
147
145
|
return Math.max(...arg);
|
|
148
146
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return arg.reduce((a, b) => (a > b ? a : b));
|
|
152
|
-
}
|
|
147
|
+
// local compare function to handle string comparison
|
|
148
|
+
return arg.reduce((a, b) => (a > b ? a : b));
|
|
153
149
|
}
|
|
154
150
|
/**
|
|
155
151
|
* Get the item in the provided array that has the maximum value when the provided expression is evaluated.
|
|
@@ -177,14 +173,12 @@ class Functions {
|
|
|
177
173
|
if (max.visited === current.visited) {
|
|
178
174
|
return max;
|
|
179
175
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
: current;
|
|
187
|
-
}
|
|
176
|
+
// We can safely cast visited to number | string here because we've already
|
|
177
|
+
// checked the type at runtime above and we know that it's either a number or a string
|
|
178
|
+
return max.visited >
|
|
179
|
+
current.visited
|
|
180
|
+
? max
|
|
181
|
+
: current;
|
|
188
182
|
}, visitedArgs[0]);
|
|
189
183
|
return max.arg;
|
|
190
184
|
}
|
|
@@ -196,6 +190,7 @@ class Functions {
|
|
|
196
190
|
* @param args The objects to merge
|
|
197
191
|
*/
|
|
198
192
|
funcMerge(...args) {
|
|
193
|
+
// biome-ignore lint/performance/noAccumulatingSpread: This is a shallow merge so the tradeoff is acceptable
|
|
199
194
|
return args.reduce((a, b) => ({ ...a, ...b }), {});
|
|
200
195
|
}
|
|
201
196
|
/**
|
|
@@ -208,12 +203,10 @@ class Functions {
|
|
|
208
203
|
return null;
|
|
209
204
|
// The signature decorator already enforces that all elements are of the same type
|
|
210
205
|
}
|
|
211
|
-
|
|
206
|
+
if (isNumber(arg[0])) {
|
|
212
207
|
return Math.min(...arg);
|
|
213
208
|
}
|
|
214
|
-
|
|
215
|
-
return arg.reduce((a, b) => (a < b ? a : b));
|
|
216
|
-
}
|
|
209
|
+
return arg.reduce((a, b) => (a < b ? a : b));
|
|
217
210
|
}
|
|
218
211
|
/**
|
|
219
212
|
* Get the item in the provided array that has the minimum value when the provided expression is evaluated.
|
|
@@ -241,14 +234,12 @@ class Functions {
|
|
|
241
234
|
if (min.visited === current.visited) {
|
|
242
235
|
return min;
|
|
243
236
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
: current;
|
|
251
|
-
}
|
|
237
|
+
// We can safely cast visited to number | string here because we've already
|
|
238
|
+
// checked the type at runtime above and we know that it's either a number or a string
|
|
239
|
+
return min.visited <
|
|
240
|
+
current.visited
|
|
241
|
+
? min
|
|
242
|
+
: current;
|
|
252
243
|
}, visitedArgs[0]);
|
|
253
244
|
return min.arg;
|
|
254
245
|
}
|
|
@@ -317,13 +308,11 @@ class Functions {
|
|
|
317
308
|
if (a.visited === b.visited) {
|
|
318
309
|
return a.index - b.index; // Make the sort stable
|
|
319
310
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
: -1;
|
|
326
|
-
}
|
|
311
|
+
// We can safely cast visited to number | string here because we've already
|
|
312
|
+
// checked the type at runtime above and we know that it's either a number or a string
|
|
313
|
+
return a.visited > b.visited
|
|
314
|
+
? 1
|
|
315
|
+
: -1;
|
|
327
316
|
})
|
|
328
317
|
.map(({ value }) => value); // Extract the original values
|
|
329
318
|
}
|
|
@@ -369,13 +358,11 @@ class Functions {
|
|
|
369
358
|
if (typeof arg === 'number') {
|
|
370
359
|
return arg;
|
|
371
360
|
}
|
|
372
|
-
|
|
361
|
+
if (typeof arg === 'string') {
|
|
373
362
|
const num = Number(arg);
|
|
374
363
|
return Number.isNaN(num) ? null : num;
|
|
375
364
|
}
|
|
376
|
-
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
365
|
+
return null;
|
|
379
366
|
}
|
|
380
367
|
/**
|
|
381
368
|
* Convert the provided value to a string.
|
package/lib/esm/Lexer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lexer.d.ts","sourceRoot":"","sources":["../../src/Lexer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,cAAM,KAAK;;IAOT;;;;;;OAMG;IACK,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"Lexer.d.ts","sourceRoot":"","sources":["../../src/Lexer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,cAAM,KAAK;;IAOT;;;;;;OAMG;IACK,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC;CA4UvD;AAED,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/lib/esm/Lexer.js
CHANGED
|
@@ -23,9 +23,7 @@ class Lexer {
|
|
|
23
23
|
while (this.#current !== '' && this.#current !== undefined) {
|
|
24
24
|
if (SIMPLE_TOKENS.has(this.#current)) {
|
|
25
25
|
yield {
|
|
26
|
-
// We know that SIMPLE_TOKENS has this.#current as a key because
|
|
27
|
-
// we checked for that above.
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
+
// biome-ignore lint/style/noNonNullAssertion: We know that SIMPLE_TOKENS has this.#current as a key because we checked for that above.
|
|
29
27
|
type: SIMPLE_TOKENS.get(this.#current),
|
|
30
28
|
value: this.#current,
|
|
31
29
|
start: this.#position,
|
|
@@ -53,7 +51,7 @@ class Lexer {
|
|
|
53
51
|
const buff = this.#consumeNumber();
|
|
54
52
|
yield {
|
|
55
53
|
type: 'number',
|
|
56
|
-
value: parseInt(buff),
|
|
54
|
+
value: Number.parseInt(buff),
|
|
57
55
|
start: start,
|
|
58
56
|
end: start + buff.length,
|
|
59
57
|
};
|
|
@@ -113,9 +111,7 @@ class Lexer {
|
|
|
113
111
|
end: this.#position,
|
|
114
112
|
};
|
|
115
113
|
}
|
|
116
|
-
|
|
117
|
-
throw new LexerError(this.#position - 1, '=');
|
|
118
|
-
}
|
|
114
|
+
throw new LexerError(this.#position - 1, '=');
|
|
119
115
|
}
|
|
120
116
|
/**
|
|
121
117
|
* Consume an unquoted identifier.
|
|
@@ -149,15 +145,13 @@ class Lexer {
|
|
|
149
145
|
if (buff.length > 1) {
|
|
150
146
|
return {
|
|
151
147
|
type: 'number',
|
|
152
|
-
value: parseInt(buff),
|
|
148
|
+
value: Number.parseInt(buff),
|
|
153
149
|
start: start,
|
|
154
150
|
end: start + buff.length,
|
|
155
151
|
};
|
|
156
152
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
throw new LexerError(start, 'Unknown token after "-"');
|
|
160
|
-
}
|
|
153
|
+
// If the negative sign is not followed by a number, it is an error.
|
|
154
|
+
throw new LexerError(start, 'Unknown token after "-"');
|
|
161
155
|
}
|
|
162
156
|
/**
|
|
163
157
|
* Consume a raw string that is a number.
|
|
@@ -183,17 +177,15 @@ class Lexer {
|
|
|
183
177
|
#consumeSquareBracket() {
|
|
184
178
|
const start = this.#position;
|
|
185
179
|
const nextChar = this.#next();
|
|
186
|
-
if (nextChar
|
|
180
|
+
if (nextChar === ']') {
|
|
187
181
|
this.#next();
|
|
188
182
|
return { type: 'flatten', value: '[]', start: start, end: start + 2 };
|
|
189
183
|
}
|
|
190
|
-
|
|
184
|
+
if (nextChar === '?') {
|
|
191
185
|
this.#next();
|
|
192
186
|
return { type: 'filter', value: '[?', start: start, end: start + 2 };
|
|
193
187
|
}
|
|
194
|
-
|
|
195
|
-
return { type: 'lbracket', value: '[', start: start, end: start + 1 };
|
|
196
|
-
}
|
|
188
|
+
return { type: 'lbracket', value: '[', start: start, end: start + 1 };
|
|
197
189
|
}
|
|
198
190
|
/**
|
|
199
191
|
* Initializes the lexer for the given expression.
|
|
@@ -283,7 +275,7 @@ class Lexer {
|
|
|
283
275
|
*/
|
|
284
276
|
#consumeQuotedIdentifier() {
|
|
285
277
|
const start = this.#position;
|
|
286
|
-
const lexeme =
|
|
278
|
+
const lexeme = `"${this.#consumeUntil('"')}"`;
|
|
287
279
|
const tokenLen = this.#position - start;
|
|
288
280
|
return {
|
|
289
281
|
type: 'quoted_identifier',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedResult.d.ts","sourceRoot":"","sources":["../../src/ParsedResult.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ParsedResult.d.ts","sourceRoot":"","sources":["../../src/ParsedResult.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE3E,cAAM,YAAY;IACT,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,IAAI,CAAC;gBAED,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI;IAKnD;;;;;OAKG;IACI,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO;CAiB5E;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
package/lib/esm/Parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../src/Parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA6BjD;;;;;;;;;;;;;GAaG;AACH,cAAM,MAAM;;gBAkBS,SAAS,SAAI;IAIhC;;;;;;;;OAQG;IACI,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IAc9C;;OAEG;IACI,UAAU,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../src/Parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA6BjD;;;;;;;;;;;;;GAaG;AACH,cAAM,MAAM;;gBAkBS,SAAS,SAAI;IAIhC;;;;;;;;OAQG;IACI,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IAc9C;;OAEG;IACI,UAAU,IAAI,IAAI;CAutB1B;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/lib/esm/Parser.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomInt } from 'node:crypto';
|
|
2
2
|
import { Lexer } from './Lexer.js';
|
|
3
3
|
import { ParsedResult } from './ParsedResult.js';
|
|
4
|
-
import { andExpression, comparator, currentNode, expref, field, filterProjection, flatten, functionExpression, identity, index, indexExpression, keyValPair, literal,
|
|
4
|
+
import { andExpression, comparator, currentNode, expref, field, filterProjection, flatten, functionExpression, identity, index, indexExpression, keyValPair, literal, multiSelectList, multiSelectObject, notExpression, orExpression, pipe, projection, slice, subexpression, valueProjection, } from './ast.js';
|
|
5
5
|
import { BINDING_POWER } from './constants.js';
|
|
6
6
|
import { IncompleteExpressionError, LexerError, ParseError } from './errors.js';
|
|
7
7
|
/**
|
|
@@ -138,13 +138,13 @@ class Parser {
|
|
|
138
138
|
case 'flatten':
|
|
139
139
|
return this.#processFlattenTokenNud();
|
|
140
140
|
case 'not':
|
|
141
|
-
return notExpression(this.#expression(BINDING_POWER
|
|
141
|
+
return notExpression(this.#expression(BINDING_POWER.not));
|
|
142
142
|
case 'lbracket':
|
|
143
143
|
return this.#processLBracketTokenNud();
|
|
144
144
|
case 'current':
|
|
145
145
|
return currentNode();
|
|
146
146
|
case 'expref':
|
|
147
|
-
return expref(this.#expression(BINDING_POWER
|
|
147
|
+
return expref(this.#expression(BINDING_POWER.expref));
|
|
148
148
|
default:
|
|
149
149
|
return this.#processDefaultToken(token);
|
|
150
150
|
}
|
|
@@ -183,7 +183,7 @@ class Parser {
|
|
|
183
183
|
right = identity();
|
|
184
184
|
}
|
|
185
185
|
else {
|
|
186
|
-
right = this.#parseProjectionRhs(BINDING_POWER
|
|
186
|
+
right = this.#parseProjectionRhs(BINDING_POWER.star);
|
|
187
187
|
}
|
|
188
188
|
return valueProjection(left, right);
|
|
189
189
|
}
|
|
@@ -210,7 +210,7 @@ class Parser {
|
|
|
210
210
|
*/
|
|
211
211
|
#processFlattenTokenNud() {
|
|
212
212
|
const left = flatten(identity());
|
|
213
|
-
const right = this.#parseProjectionRhs(BINDING_POWER
|
|
213
|
+
const right = this.#parseProjectionRhs(BINDING_POWER.flatten);
|
|
214
214
|
return projection(left, right);
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
@@ -226,16 +226,13 @@ class Parser {
|
|
|
226
226
|
const right = this.#parseIndexExpression();
|
|
227
227
|
return this.#projectIfSlice(identity(), right);
|
|
228
228
|
}
|
|
229
|
-
|
|
230
|
-
this.#lookahead(1) === 'rbracket') {
|
|
229
|
+
if (this.#currentToken() === 'star' && this.#lookahead(1) === 'rbracket') {
|
|
231
230
|
this.#advance();
|
|
232
231
|
this.#advance();
|
|
233
|
-
const right = this.#parseProjectionRhs(BINDING_POWER
|
|
232
|
+
const right = this.#parseProjectionRhs(BINDING_POWER.star);
|
|
234
233
|
return projection(identity(), right);
|
|
235
234
|
}
|
|
236
|
-
|
|
237
|
-
return this.#parseMultiSelectList();
|
|
238
|
-
}
|
|
235
|
+
return this.#parseMultiSelectList();
|
|
239
236
|
}
|
|
240
237
|
/**
|
|
241
238
|
* Process a default token.
|
|
@@ -307,21 +304,17 @@ class Parser {
|
|
|
307
304
|
*/
|
|
308
305
|
#processDotToken(leftNode) {
|
|
309
306
|
if (this.#currentToken() !== 'star') {
|
|
310
|
-
const right = this.#parseDotRhs(BINDING_POWER
|
|
307
|
+
const right = this.#parseDotRhs(BINDING_POWER.dot);
|
|
311
308
|
if (leftNode.type === 'subexpression') {
|
|
312
309
|
leftNode.children.push(right);
|
|
313
310
|
return leftNode;
|
|
314
311
|
}
|
|
315
|
-
|
|
316
|
-
return subexpression([leftNode, right]);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
// We are creating a value projection
|
|
321
|
-
this.#advance();
|
|
322
|
-
const right = this.#parseProjectionRhs(BINDING_POWER['dot']);
|
|
323
|
-
return valueProjection(leftNode, right);
|
|
312
|
+
return subexpression([leftNode, right]);
|
|
324
313
|
}
|
|
314
|
+
// We are creating a value projection
|
|
315
|
+
this.#advance();
|
|
316
|
+
const right = this.#parseProjectionRhs(BINDING_POWER.dot);
|
|
317
|
+
return valueProjection(leftNode, right);
|
|
325
318
|
}
|
|
326
319
|
/**
|
|
327
320
|
* Process a pipe token.
|
|
@@ -334,7 +327,7 @@ class Parser {
|
|
|
334
327
|
* @param leftNode The left hand side of the expression.
|
|
335
328
|
*/
|
|
336
329
|
#processPipeToken(leftNode) {
|
|
337
|
-
const right = this.#expression(BINDING_POWER
|
|
330
|
+
const right = this.#expression(BINDING_POWER.pipe);
|
|
338
331
|
return pipe(leftNode, right);
|
|
339
332
|
}
|
|
340
333
|
/**
|
|
@@ -348,7 +341,7 @@ class Parser {
|
|
|
348
341
|
* @param leftNode The left hand side of the expression.
|
|
349
342
|
*/
|
|
350
343
|
#processOrToken(leftNode) {
|
|
351
|
-
const right = this.#expression(BINDING_POWER
|
|
344
|
+
const right = this.#expression(BINDING_POWER.or);
|
|
352
345
|
return orExpression(leftNode, right);
|
|
353
346
|
}
|
|
354
347
|
/**
|
|
@@ -362,7 +355,7 @@ class Parser {
|
|
|
362
355
|
* @param leftNode The left hand side of the expression.
|
|
363
356
|
*/
|
|
364
357
|
#processAndToken(leftNode) {
|
|
365
|
-
const right = this.#expression(BINDING_POWER
|
|
358
|
+
const right = this.#expression(BINDING_POWER.and);
|
|
366
359
|
return andExpression(leftNode, right);
|
|
367
360
|
}
|
|
368
361
|
#processLParenToken(leftNode) {
|
|
@@ -387,13 +380,13 @@ class Parser {
|
|
|
387
380
|
right = identity();
|
|
388
381
|
}
|
|
389
382
|
else {
|
|
390
|
-
right = this.#parseProjectionRhs(BINDING_POWER
|
|
383
|
+
right = this.#parseProjectionRhs(BINDING_POWER.flatten);
|
|
391
384
|
}
|
|
392
385
|
return filterProjection(leftNode, right, condition);
|
|
393
386
|
}
|
|
394
387
|
#processFlattenToken(leftNode) {
|
|
395
388
|
const left = flatten(leftNode);
|
|
396
|
-
const right = this.#parseProjectionRhs(BINDING_POWER
|
|
389
|
+
const right = this.#parseProjectionRhs(BINDING_POWER.flatten);
|
|
397
390
|
return projection(left, right);
|
|
398
391
|
}
|
|
399
392
|
#processLBracketToken(leftNode) {
|
|
@@ -407,17 +400,13 @@ class Parser {
|
|
|
407
400
|
leftNode.children.push(right);
|
|
408
401
|
return leftNode;
|
|
409
402
|
}
|
|
410
|
-
|
|
411
|
-
return this.#projectIfSlice(leftNode, right);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
// We have a projection
|
|
416
|
-
this.#match('star');
|
|
417
|
-
this.#match('rbracket');
|
|
418
|
-
const right = this.#parseProjectionRhs(BINDING_POWER['star']);
|
|
419
|
-
return projection(leftNode, right);
|
|
403
|
+
return this.#projectIfSlice(leftNode, right);
|
|
420
404
|
}
|
|
405
|
+
// We have a projection
|
|
406
|
+
this.#match('star');
|
|
407
|
+
this.#match('rbracket');
|
|
408
|
+
const right = this.#parseProjectionRhs(BINDING_POWER.star);
|
|
409
|
+
return projection(leftNode, right);
|
|
421
410
|
}
|
|
422
411
|
/**
|
|
423
412
|
* Throw a parse error.
|
|
@@ -455,13 +444,11 @@ class Parser {
|
|
|
455
444
|
if (this.#lookahead(0) === 'colon' || this.#lookahead(1) === 'colon') {
|
|
456
445
|
return this.#parseSliceExpression();
|
|
457
446
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return node;
|
|
464
|
-
}
|
|
447
|
+
// Parse the syntax [number]
|
|
448
|
+
const node = index(this.#lookaheadToken(0).value);
|
|
449
|
+
this.#advance();
|
|
450
|
+
this.#match('rbracket');
|
|
451
|
+
return node;
|
|
465
452
|
}
|
|
466
453
|
/**
|
|
467
454
|
* Process a slice expression.
|
|
@@ -519,11 +506,9 @@ class Parser {
|
|
|
519
506
|
#projectIfSlice(left, right) {
|
|
520
507
|
const idxExpression = indexExpression([left, right]);
|
|
521
508
|
if (right.type === 'slice') {
|
|
522
|
-
return projection(idxExpression, this.#parseProjectionRhs(BINDING_POWER
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
return idxExpression;
|
|
509
|
+
return projection(idxExpression, this.#parseProjectionRhs(BINDING_POWER.star));
|
|
526
510
|
}
|
|
511
|
+
return idxExpression;
|
|
527
512
|
}
|
|
528
513
|
/**
|
|
529
514
|
* Process a comparator.
|
|
@@ -553,9 +538,7 @@ class Parser {
|
|
|
553
538
|
if (this.#currentToken() === 'rbracket') {
|
|
554
539
|
break;
|
|
555
540
|
}
|
|
556
|
-
|
|
557
|
-
this.#match('comma');
|
|
558
|
-
}
|
|
541
|
+
this.#match('comma');
|
|
559
542
|
}
|
|
560
543
|
this.#match('rbracket');
|
|
561
544
|
return multiSelectList(expressions);
|
|
@@ -575,15 +558,15 @@ class Parser {
|
|
|
575
558
|
// Before getting the token value, verify it's
|
|
576
559
|
// an identifier.
|
|
577
560
|
this.#matchMultipleTokens(['quoted_identifier', 'unquoted_identifier']); // token types
|
|
578
|
-
const keyName = keyToken
|
|
561
|
+
const keyName = keyToken.value;
|
|
579
562
|
this.#match('colon');
|
|
580
563
|
const value = this.#expression(0);
|
|
581
564
|
const node = keyValPair(keyName, value);
|
|
582
565
|
pairs.push(node);
|
|
583
|
-
if (this.#currentToken()
|
|
566
|
+
if (this.#currentToken() === 'comma') {
|
|
584
567
|
this.#match('comma');
|
|
585
568
|
}
|
|
586
|
-
else if (this.#currentToken()
|
|
569
|
+
else if (this.#currentToken() === 'rbrace') {
|
|
587
570
|
this.#match('rbrace');
|
|
588
571
|
break;
|
|
589
572
|
}
|
|
@@ -602,13 +585,13 @@ class Parser {
|
|
|
602
585
|
// BP of 10 are all the tokens that stop a projection.
|
|
603
586
|
right = identity();
|
|
604
587
|
}
|
|
605
|
-
else if (this.#currentToken()
|
|
588
|
+
else if (this.#currentToken() === 'lbracket') {
|
|
606
589
|
right = this.#expression(bindingPower);
|
|
607
590
|
}
|
|
608
|
-
else if (this.#currentToken()
|
|
591
|
+
else if (this.#currentToken() === 'filter') {
|
|
609
592
|
right = this.#expression(bindingPower);
|
|
610
593
|
}
|
|
611
|
-
else if (this.#currentToken()
|
|
594
|
+
else if (this.#currentToken() === 'dot') {
|
|
612
595
|
this.#match('dot');
|
|
613
596
|
right = this.#parseDotRhs(bindingPower);
|
|
614
597
|
}
|
|
@@ -636,17 +619,15 @@ class Parser {
|
|
|
636
619
|
if (['quoted_identifier', 'unquoted_identifier', 'star'].includes(lookahead)) {
|
|
637
620
|
return this.#expression(bindingPower);
|
|
638
621
|
}
|
|
639
|
-
|
|
622
|
+
if (lookahead === 'lbracket') {
|
|
640
623
|
this.#match('lbracket');
|
|
641
624
|
return this.#parseMultiSelectList();
|
|
642
625
|
}
|
|
643
|
-
|
|
626
|
+
if (lookahead === 'lbrace') {
|
|
644
627
|
this.#match('lbrace');
|
|
645
628
|
return this.#parseMultiSelectHash();
|
|
646
629
|
}
|
|
647
|
-
|
|
648
|
-
this.#throwParseError();
|
|
649
|
-
}
|
|
630
|
+
this.#throwParseError();
|
|
650
631
|
}
|
|
651
632
|
/**
|
|
652
633
|
* Process a token and throw an error if it doesn't match the expected token.
|
|
@@ -667,13 +648,11 @@ class Parser {
|
|
|
667
648
|
tokenType: token.type,
|
|
668
649
|
});
|
|
669
650
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
});
|
|
676
|
-
}
|
|
651
|
+
throw new ParseError({
|
|
652
|
+
lexPosition: token.start,
|
|
653
|
+
tokenValue: token.value,
|
|
654
|
+
tokenType: token.type,
|
|
655
|
+
});
|
|
677
656
|
}
|
|
678
657
|
}
|
|
679
658
|
/**
|
|
@@ -692,13 +671,11 @@ class Parser {
|
|
|
692
671
|
tokenType: token.type,
|
|
693
672
|
});
|
|
694
673
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
});
|
|
701
|
-
}
|
|
674
|
+
throw new ParseError({
|
|
675
|
+
lexPosition: token.start,
|
|
676
|
+
tokenValue: token.value,
|
|
677
|
+
tokenType: token.type,
|
|
678
|
+
});
|
|
702
679
|
}
|
|
703
680
|
this.#advance();
|
|
704
681
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeInterpreter.d.ts","sourceRoot":"","sources":["../../src/TreeInterpreter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"TreeInterpreter.d.ts","sourceRoot":"","sources":["../../src/TreeInterpreter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAG3E;;;;;;;;GAQG;AACH,cAAM,eAAe;;IAGnB;;OAEG;gBACgB,OAAO,CAAC,EAAE,sBAAsB;IASnD;;;;;;;OAOG;IACI,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI;CA2b/D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|