@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
|
@@ -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 {
|
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
|
*/
|
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,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/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.6.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.6.0"
|
|
29
29
|
},
|
|
30
30
|
"main": "./lib/cjs/index.js",
|
|
31
31
|
"types": "./lib/cjs/index.d.ts",
|