@aws-lambda-powertools/jmespath 2.3.0 → 2.5.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/Expression.js +5 -18
- package/lib/cjs/Functions.js +4 -6
- package/lib/cjs/Lexer.js +275 -204
- package/lib/cjs/ParsedResult.js +2 -0
- package/lib/cjs/Parser.js +676 -433
- package/lib/cjs/TreeInterpreter.js +364 -233
- package/lib/cjs/errors.d.ts +0 -6
- package/lib/cjs/errors.d.ts.map +1 -1
- package/lib/cjs/errors.js +39 -0
- package/lib/esm/Expression.js +5 -18
- package/lib/esm/Functions.js +4 -6
- package/lib/esm/Lexer.js +274 -203
- package/lib/esm/ParsedResult.js +2 -0
- package/lib/esm/Parser.js +675 -432
- package/lib/esm/TreeInterpreter.js +363 -232
- package/lib/esm/errors.d.ts +0 -6
- package/lib/esm/errors.d.ts.map +1 -1
- package/lib/esm/errors.js +39 -0
- package/package.json +2 -2
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -65,12 +65,6 @@ declare class ParseError extends JMESPathError {
|
|
|
65
65
|
* Error thrown when an incomplete expression is encountered during parsing.
|
|
66
66
|
*/
|
|
67
67
|
declare class IncompleteExpressionError extends ParseError {
|
|
68
|
-
/**
|
|
69
|
-
* Expression that was being parsed when the error occurred.
|
|
70
|
-
*
|
|
71
|
-
* Can be set by whatever catches the error.
|
|
72
|
-
*/
|
|
73
|
-
expression?: string;
|
|
74
68
|
constructor(options: {
|
|
75
69
|
lexPosition: number;
|
|
76
70
|
tokenValue: Token['value'];
|
package/lib/cjs/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;GAEG;AACH,cAAM,aAAc,SAAQ,KAAK;IAC/B;;;OAGG;IACI,UAAU,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AiB1E,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAGzD;AAED;;;;;;;;;GASG;AACH,cAAM,kBAAmB,SAAQ,UAAU;gBACtB,OAAO,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;CAU3E;AAED;;;;;;;GAOG;AACH,cAAM,iBAAkB,SAAQ,aAAa;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,MAAM,EAAE,CAAC;gBAEZ,OAAO,EAAE;QAC1B,YAAY,EAAE,OAAO,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,MAAM,EAAE,CAAC;KACzB;IAeD,SAAS,CAAC,sBAAsB,IAAI,MAAM;CAQ3C;AAED;;;;;;GAMG;AACH,cAAM,oBAAqB,SAAQ,aAAa;gBAC3B,QAAQ,EAAE,MAAM;CAOpC;AAED,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,yBAAyB,EACzB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,kBAAkB,GACnB,CAAC"}
|
package/lib/cjs/errors.js
CHANGED
|
@@ -5,6 +5,11 @@ exports.VariadicArityError = exports.UnknownFunctionError = exports.ParseError =
|
|
|
5
5
|
* Base class for errors thrown during expression parsing and evaluation.
|
|
6
6
|
*/
|
|
7
7
|
class JMESPathError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Expression that was being parsed when the error occurred.
|
|
10
|
+
* Can be set by whatever catches the error.
|
|
11
|
+
*/
|
|
12
|
+
expression;
|
|
8
13
|
constructor(message) {
|
|
9
14
|
super(message);
|
|
10
15
|
this.name = 'JMESPathError';
|
|
@@ -30,6 +35,14 @@ exports.JMESPathError = JMESPathError;
|
|
|
30
35
|
* Error thrown when an unknown token is encountered during the AST construction.
|
|
31
36
|
*/
|
|
32
37
|
class LexerError extends JMESPathError {
|
|
38
|
+
/**
|
|
39
|
+
* Position in the expression where the error occurred.
|
|
40
|
+
*/
|
|
41
|
+
lexerPosition;
|
|
42
|
+
/**
|
|
43
|
+
* Token value where the error occurred.
|
|
44
|
+
*/
|
|
45
|
+
lexerValue;
|
|
33
46
|
constructor(lexerPosition, lexerValue) {
|
|
34
47
|
super('Bad jmespath expression');
|
|
35
48
|
this.name = 'LexerError';
|
|
@@ -44,6 +57,22 @@ exports.LexerError = LexerError;
|
|
|
44
57
|
* Error thrown when an invalid or unexpected token type or value is encountered during parsing.
|
|
45
58
|
*/
|
|
46
59
|
class ParseError extends JMESPathError {
|
|
60
|
+
/**
|
|
61
|
+
* Position in the expression where the error occurred.
|
|
62
|
+
*/
|
|
63
|
+
lexPosition;
|
|
64
|
+
/**
|
|
65
|
+
* Additional information about the error.
|
|
66
|
+
*/
|
|
67
|
+
reason;
|
|
68
|
+
/**
|
|
69
|
+
* Token type where the error occurred.
|
|
70
|
+
*/
|
|
71
|
+
tokenType;
|
|
72
|
+
/**
|
|
73
|
+
* Token value where the error occurred.
|
|
74
|
+
*/
|
|
75
|
+
tokenValue;
|
|
47
76
|
constructor(options) {
|
|
48
77
|
super('Invalid jmespath expression');
|
|
49
78
|
this.name = 'ParseError';
|
|
@@ -100,6 +129,11 @@ exports.EmptyExpressionError = EmptyExpressionError;
|
|
|
100
129
|
* while executing the function itself.
|
|
101
130
|
*/
|
|
102
131
|
class FunctionError extends JMESPathError {
|
|
132
|
+
/**
|
|
133
|
+
* Function that was being executed when the error occurred.
|
|
134
|
+
* Can be set by whatever catches the error.
|
|
135
|
+
*/
|
|
136
|
+
functionName;
|
|
103
137
|
constructor(message) {
|
|
104
138
|
super(message);
|
|
105
139
|
this.name = 'FunctionError';
|
|
@@ -128,6 +162,8 @@ class FunctionError extends JMESPathError {
|
|
|
128
162
|
* an `ArityError` is thrown.
|
|
129
163
|
*/
|
|
130
164
|
class ArityError extends FunctionError {
|
|
165
|
+
actualArity;
|
|
166
|
+
expectedArity;
|
|
131
167
|
constructor(options) {
|
|
132
168
|
super('Invalid arity for JMESPath function');
|
|
133
169
|
this.name = 'ArityError';
|
|
@@ -170,6 +206,9 @@ exports.VariadicArityError = VariadicArityError;
|
|
|
170
206
|
* instead, this error is thrown.
|
|
171
207
|
*/
|
|
172
208
|
class JMESPathTypeError extends FunctionError {
|
|
209
|
+
actualType;
|
|
210
|
+
currentValue;
|
|
211
|
+
expectedTypes;
|
|
173
212
|
constructor(options) {
|
|
174
213
|
super('Invalid type for JMESPath expression');
|
|
175
214
|
this.name = 'JMESPathTypeError';
|
package/lib/esm/Expression.js
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Expression_expression, _Expression_interpreter;
|
|
13
1
|
/**
|
|
14
2
|
* Apply a JMESPath expression to a JSON value.
|
|
15
3
|
*/
|
|
16
4
|
class Expression {
|
|
5
|
+
#expression;
|
|
6
|
+
#interpreter;
|
|
17
7
|
constructor(expression, interpreter) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
__classPrivateFieldSet(this, _Expression_expression, expression, "f");
|
|
21
|
-
__classPrivateFieldSet(this, _Expression_interpreter, interpreter, "f");
|
|
8
|
+
this.#expression = expression;
|
|
9
|
+
this.#interpreter = interpreter;
|
|
22
10
|
}
|
|
23
11
|
/**
|
|
24
12
|
* Evaluate the expression against a JSON value.
|
|
@@ -28,8 +16,7 @@ class Expression {
|
|
|
28
16
|
* @returns The result of applying the expression to the value.
|
|
29
17
|
*/
|
|
30
18
|
visit(value, node) {
|
|
31
|
-
return
|
|
19
|
+
return this.#interpreter.visit(node ?? this.#expression, value);
|
|
32
20
|
}
|
|
33
21
|
}
|
|
34
|
-
_Expression_expression = new WeakMap(), _Expression_interpreter = new WeakMap();
|
|
35
22
|
export { Expression };
|
package/lib/esm/Functions.js
CHANGED
|
@@ -38,12 +38,10 @@ import { arityCheck, typeCheck } from './utils.js';
|
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
class Functions {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.methods = new Set();
|
|
46
|
-
}
|
|
41
|
+
/**
|
|
42
|
+
* A set of all the custom functions available in this and all child classes.
|
|
43
|
+
*/
|
|
44
|
+
methods = new Set();
|
|
47
45
|
/**
|
|
48
46
|
* Get the absolute value of the provided number.
|
|
49
47
|
*
|