@aws-lambda-powertools/jmespath 2.5.0 → 2.7.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/README.md +24 -20
- 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 -15
- package/lib/cjs/constants.js +2 -2
- package/lib/cjs/envelopes.d.ts.map +1 -1
- 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 -15
- package/lib/esm/constants.js +2 -2
- package/lib/esm/envelopes.d.ts.map +1 -1
- 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/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;CA0b/D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isIntegerNumber, isRecord, isStrictEqual, } from '@aws-lambda-powertools/commons/typeutils';
|
|
2
|
-
import { ArityError, JMESPathError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
|
|
3
2
|
import { Expression } from './Expression.js';
|
|
4
3
|
import { Functions } from './Functions.js';
|
|
4
|
+
import { ArityError, JMESPathError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
|
|
5
5
|
import { isTruthy, sliceArray } from './utils.js';
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -64,9 +64,7 @@ class TreeInterpreter {
|
|
|
64
64
|
if (visitMethod) {
|
|
65
65
|
return visitMethod.call(this, node, value);
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
throw new JMESPathError(`Not Implemented: Invalid node type: ${node.type}`);
|
|
69
|
-
}
|
|
67
|
+
throw new JMESPathError(`Not Implemented: Invalid node type: ${node.type}`);
|
|
70
68
|
}
|
|
71
69
|
/**
|
|
72
70
|
* Visit a subexpression, index expression, or pipe node.
|
|
@@ -100,9 +98,7 @@ class TreeInterpreter {
|
|
|
100
98
|
node.value in value) {
|
|
101
99
|
return value[node.value];
|
|
102
100
|
}
|
|
103
|
-
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
101
|
+
return null;
|
|
106
102
|
}
|
|
107
103
|
/**
|
|
108
104
|
* Visit a comparator node.
|
|
@@ -120,24 +116,22 @@ class TreeInterpreter {
|
|
|
120
116
|
if (comparator === 'eq') {
|
|
121
117
|
return isStrictEqual(left, right);
|
|
122
118
|
}
|
|
123
|
-
|
|
119
|
+
if (comparator === 'ne') {
|
|
124
120
|
return !isStrictEqual(left, right);
|
|
125
121
|
}
|
|
126
|
-
|
|
122
|
+
if (typeof left === 'number' && typeof right === 'number') {
|
|
127
123
|
// Ordering operators only work on numbers. Evaluating them on other
|
|
128
124
|
// types will return null.
|
|
129
125
|
if (comparator === 'lt') {
|
|
130
126
|
return left < right;
|
|
131
127
|
}
|
|
132
|
-
|
|
128
|
+
if (comparator === 'lte') {
|
|
133
129
|
return left <= right;
|
|
134
130
|
}
|
|
135
|
-
|
|
131
|
+
if (comparator === 'gt') {
|
|
136
132
|
return left > right;
|
|
137
133
|
}
|
|
138
|
-
|
|
139
|
-
return left >= right;
|
|
140
|
-
}
|
|
134
|
+
return left >= right;
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
137
|
else {
|
|
@@ -190,7 +184,6 @@ class TreeInterpreter {
|
|
|
190
184
|
// doesn't know that, so we have to use @ts-ignore to tell it that it's
|
|
191
185
|
// okay. We could use a type assertion like `as keyof Functions`, but
|
|
192
186
|
// we also want to keep the args generic, so for now we'll just ignore it.
|
|
193
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
194
187
|
// @ts-ignore-next-line
|
|
195
188
|
return this.#functions[funcName](args);
|
|
196
189
|
}
|
package/lib/esm/constants.js
CHANGED
|
@@ -56,11 +56,11 @@ const DIGITS = '0123456789';
|
|
|
56
56
|
/**
|
|
57
57
|
* The set of ASCII letters and digits allowed in JMESPath identifiers.
|
|
58
58
|
*/
|
|
59
|
-
const START_IDENTIFIER = new Set(ASCII_LETTERS
|
|
59
|
+
const START_IDENTIFIER = new Set(`${ASCII_LETTERS}_`);
|
|
60
60
|
/**
|
|
61
61
|
* The set of ASCII letters and digits allowed in JMESPath identifiers.
|
|
62
62
|
*/
|
|
63
|
-
const VALID_IDENTIFIER = new Set(ASCII_LETTERS
|
|
63
|
+
const VALID_IDENTIFIER = new Set(`${ASCII_LETTERS}${DIGITS}_`);
|
|
64
64
|
/**
|
|
65
65
|
* The set of ASCII digits allowed in JMESPath identifiers.
|
|
66
66
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelopes.d.ts","sourceRoot":"","sources":["../../src/envelopes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,QAAA,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"envelopes.d.ts","sourceRoot":"","sources":["../../src/envelopes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,QAAA,MAAM,uBAAuB,GAAI,CAAC,QAC1B,UAAU,YACN,MAAM,YACN,sBAAsB,KAC/B,CAMF,CAAC;AAEF,QAAA,MAAM,gBAAgB,0BAA0B,CAAC;AACjD,QAAA,MAAM,gBAAgB,0BAA0B,CAAC;AACjD,QAAA,MAAM,GAAG,qCAAqC,CAAC;AAC/C,QAAA,MAAM,GAAG,gDAAgD,CAAC;AAC1D,QAAA,MAAM,WAAW,WAAW,CAAC;AAC7B,QAAA,MAAM,2BAA2B,WAAW,CAAC;AAC7C,QAAA,MAAM,mBAAmB,gEACsC,CAAC;AAChE,QAAA,MAAM,eAAe,2EACqD,CAAC;AAC3E,QAAA,MAAM,UAAU,yEACwD,CAAC;AACzE,QAAA,MAAM,MAAM,gDAAgD,CAAC;AAC7D,QAAA,MAAM,uBAAuB,4FAC8D,CAAC;AAC5F,QAAA,MAAM,mBAAmB,mEACyC,CAAC;AACnE,QAAA,MAAM,kBAAkB,4CAA4C,CAAC;AAErE,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,GAAG,EACH,GAAG,EACH,WAAW,EACX,2BAA2B,EAC3B,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,MAAM,EACN,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,GACnB,CAAC"}
|
package/lib/esm/envelopes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { search } from './search.js';
|
|
2
1
|
import { PowertoolsFunctions } from './PowertoolsFunctions.js';
|
|
2
|
+
import { search } from './search.js';
|
|
3
3
|
/**
|
|
4
4
|
* Searches and extracts data using JMESPath
|
|
5
5
|
*
|
|
@@ -53,10 +53,7 @@ import { PowertoolsFunctions } from './PowertoolsFunctions.js';
|
|
|
53
53
|
* @param options The parsing options to use
|
|
54
54
|
*/
|
|
55
55
|
const extractDataFromEnvelope = (data, envelope, options) => {
|
|
56
|
-
|
|
57
|
-
options = { customFunctions: new PowertoolsFunctions() };
|
|
58
|
-
}
|
|
59
|
-
return search(envelope, data, options);
|
|
56
|
+
return search(envelope, data, options || { customFunctions: new PowertoolsFunctions() });
|
|
60
57
|
};
|
|
61
58
|
const API_GATEWAY_REST = 'powertools_json(body)';
|
|
62
59
|
const API_GATEWAY_HTTP = 'powertools_json(body)';
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JSONArray, JSONValue } from '@aws-lambda-powertools/commons/types';
|
|
2
2
|
import type { Functions } from './Functions.js';
|
|
3
|
-
import { BINDING_POWER } from './constants.js';
|
|
3
|
+
import type { BINDING_POWER } from './constants.js';
|
|
4
4
|
/**
|
|
5
5
|
* A token in the JMESPath AST.
|
|
6
6
|
*/
|
package/lib/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,OAAO,aAAa,CAAC;IACjC,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,KAAK,sBAAsB,GAAG;IAC5B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,SAAS,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,KAAK,0BAA0B,GAAG,CAChC,MAAM,EAAE,SAAS,GAAG,OAAO,SAAS,EACpC,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,UAAU,EAAE,kBAAkB,KAC3B,IAAI,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,KAAK,wBAAwB,GAAG;IAC9B,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;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/esm/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,GAAI,CAAC,gCAKlB;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,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,aACzB,OAAO,KACjB,IAcF,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,QAAA,MAAM,SAAS,SACP,OAAO,EAAE,kBACC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KACnC,IAKF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,iBAAiB,QAAS,OAAO,gBAAgB,KAAK,CAAC,MAAM,CAAC,KAAG,IAMtE,CAAC;AA+IF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getType, isIntegerNumber, isRecord, isTruthy as isTruthyJS,
|
|
1
|
+
import { getType, isIntegerNumber, isNumber, isRecord, isTruthy as isTruthyJS, } from '@aws-lambda-powertools/commons/typeutils';
|
|
2
2
|
import { Expression } from './Expression.js';
|
|
3
3
|
import { ArityError, JMESPathTypeError, VariadicArityError } from './errors.js';
|
|
4
4
|
/**
|
|
@@ -15,9 +15,7 @@ const isTruthy = (value) => {
|
|
|
15
15
|
if (isNumber(value)) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
return isTruthyJS(value);
|
|
20
|
-
}
|
|
18
|
+
return isTruthyJS(value);
|
|
21
19
|
};
|
|
22
20
|
/**
|
|
23
21
|
* @internal
|
|
@@ -29,16 +27,17 @@ const isTruthy = (value) => {
|
|
|
29
27
|
* @param isStepNegative Whether the step is negative
|
|
30
28
|
*/
|
|
31
29
|
const capSliceRange = (arrayLength, value, isStepNegative) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
let capValue = value;
|
|
31
|
+
if (capValue < 0) {
|
|
32
|
+
capValue += arrayLength;
|
|
33
|
+
if (capValue < 0) {
|
|
34
|
+
capValue = isStepNegative ? -1 : 0;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
else if (
|
|
39
|
-
|
|
37
|
+
else if (capValue >= arrayLength) {
|
|
38
|
+
capValue = isStepNegative ? arrayLength - 1 : arrayLength;
|
|
40
39
|
}
|
|
41
|
-
return
|
|
40
|
+
return capValue;
|
|
42
41
|
};
|
|
43
42
|
/**
|
|
44
43
|
* Given a start, stop, and step value, the sub elements in an array are extracted as follows:
|
|
@@ -188,8 +187,9 @@ const checkIfArgumentTypeIsValid = (arg, type, index, argumentSpec) => {
|
|
|
188
187
|
checkExpressionType(arg, argumentSpec, hasMoreTypesToCheck);
|
|
189
188
|
return true;
|
|
190
189
|
}
|
|
191
|
-
|
|
190
|
+
if (['string', 'number', 'boolean'].includes(type)) {
|
|
192
191
|
typeCheckType(arg, type, argumentSpec, hasMoreTypesToCheck);
|
|
192
|
+
// biome-ignore lint/suspicious/useValidTypeof: we know that `type` is one of 'string', 'number', or 'boolean' because we checked for that above
|
|
193
193
|
if (typeof arg === type)
|
|
194
194
|
return true;
|
|
195
195
|
}
|
|
@@ -208,6 +208,7 @@ const checkIfArgumentTypeIsValid = (arg, type, index, argumentSpec) => {
|
|
|
208
208
|
* @param hasMoreTypesToCheck Whether there are more types to check
|
|
209
209
|
*/
|
|
210
210
|
const typeCheckType = (arg, type, argumentSpec, hasMoreTypesToCheck) => {
|
|
211
|
+
// biome-ignore lint/suspicious/useValidTypeof: we know that `type` is one of 'string', 'number', or 'boolean' because we checked before calling this function
|
|
211
212
|
if (typeof arg !== type && !hasMoreTypesToCheck) {
|
|
212
213
|
throw new JMESPathTypeError({
|
|
213
214
|
currentValue: arg,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-lambda-powertools/jmespath",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "A type safe and modern jmespath module to parse and extract data from JSON documents using JMESPath",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Amazon Web Services",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"nodejs"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-lambda-powertools/commons": "^2.
|
|
28
|
+
"@aws-lambda-powertools/commons": "^2.7.0"
|
|
29
29
|
},
|
|
30
30
|
"main": "./lib/cjs/index.js",
|
|
31
31
|
"types": "./lib/cjs/index.d.ts",
|