@aws-lambda-powertools/jmespath 0.0.0-alpha.0 → 2.0.4
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/LICENSE +14 -0
- package/README.md +214 -5
- package/lib/cjs/Expression.d.ts +19 -0
- package/lib/cjs/Expression.d.ts.map +1 -0
- package/lib/cjs/Expression.js +38 -0
- package/lib/cjs/Functions.d.ts +242 -0
- package/lib/cjs/Functions.d.ts.map +1 -0
- package/lib/cjs/Functions.js +597 -0
- package/lib/cjs/Lexer.d.ts +19 -0
- package/lib/cjs/Lexer.d.ts.map +1 -0
- package/lib/cjs/Lexer.js +271 -0
- package/lib/cjs/ParsedResult.d.ts +15 -0
- package/lib/cjs/ParsedResult.d.ts.map +1 -0
- package/lib/cjs/ParsedResult.js +33 -0
- package/lib/cjs/Parser.d.ts +35 -0
- package/lib/cjs/Parser.d.ts.map +1 -0
- package/lib/cjs/Parser.js +506 -0
- package/lib/cjs/PowertoolsFunctions.d.ts +36 -0
- package/lib/cjs/PowertoolsFunctions.d.ts.map +1 -0
- package/lib/cjs/PowertoolsFunctions.js +69 -0
- package/lib/cjs/TreeInterpreter.d.ts +28 -0
- package/lib/cjs/TreeInterpreter.d.ts.map +1 -0
- package/lib/cjs/TreeInterpreter.js +313 -0
- package/lib/cjs/ast.d.ts +185 -0
- package/lib/cjs/ast.d.ts.map +1 -0
- package/lib/cjs/ast.js +275 -0
- package/lib/cjs/constants.d.ts +60 -0
- package/lib/cjs/constants.d.ts.map +1 -0
- package/lib/cjs/constants.js +96 -0
- package/lib/cjs/envelopes.d.ts +69 -0
- package/lib/cjs/envelopes.d.ts.map +1 -0
- package/lib/cjs/envelopes.js +90 -0
- package/lib/cjs/errors.d.ts +183 -0
- package/lib/cjs/errors.d.ts.map +1 -0
- package/lib/cjs/errors.js +206 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +15 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/search.d.ts +50 -0
- package/lib/cjs/search.d.ts.map +1 -0
- package/lib/cjs/search.js +55 -0
- package/lib/cjs/types.d.ts +88 -0
- package/lib/cjs/types.d.ts.map +1 -0
- package/lib/cjs/types.js +2 -0
- package/lib/cjs/utils.d.ts +87 -0
- package/lib/cjs/utils.d.ts.map +1 -0
- package/lib/cjs/utils.js +282 -0
- package/lib/esm/Expression.d.ts +19 -0
- package/lib/esm/Expression.d.ts.map +1 -0
- package/lib/esm/Expression.js +35 -0
- package/lib/esm/Functions.d.ts +242 -0
- package/lib/esm/Functions.d.ts.map +1 -0
- package/lib/esm/Functions.js +594 -0
- package/lib/esm/Lexer.d.ts +19 -0
- package/lib/esm/Lexer.d.ts.map +1 -0
- package/lib/esm/Lexer.js +268 -0
- package/lib/esm/ParsedResult.d.ts +15 -0
- package/lib/esm/ParsedResult.d.ts.map +1 -0
- package/lib/esm/ParsedResult.js +30 -0
- package/lib/esm/Parser.d.ts +35 -0
- package/lib/esm/Parser.d.ts.map +1 -0
- package/lib/esm/Parser.js +503 -0
- package/lib/esm/PowertoolsFunctions.d.ts +36 -0
- package/lib/esm/PowertoolsFunctions.d.ts.map +1 -0
- package/lib/esm/PowertoolsFunctions.js +66 -0
- package/lib/esm/TreeInterpreter.d.ts +28 -0
- package/lib/esm/TreeInterpreter.d.ts.map +1 -0
- package/lib/esm/TreeInterpreter.js +310 -0
- package/lib/esm/ast.d.ts +185 -0
- package/lib/esm/ast.d.ts.map +1 -0
- package/lib/esm/ast.js +251 -0
- package/lib/esm/constants.d.ts +60 -0
- package/lib/esm/constants.d.ts.map +1 -0
- package/lib/esm/constants.js +88 -0
- package/lib/esm/envelopes.d.ts +69 -0
- package/lib/esm/envelopes.d.ts.map +1 -0
- package/lib/esm/envelopes.js +74 -0
- package/lib/esm/errors.d.ts +183 -0
- package/lib/esm/errors.d.ts.map +1 -0
- package/lib/esm/errors.js +195 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/search.d.ts +50 -0
- package/lib/esm/search.d.ts.map +1 -0
- package/lib/esm/search.js +52 -0
- package/lib/esm/types.d.ts +88 -0
- package/lib/esm/types.d.ts.map +1 -0
- package/lib/esm/types.js +1 -0
- package/lib/esm/utils.d.ts +87 -0
- package/lib/esm/utils.d.ts.map +1 -0
- package/lib/esm/utils.js +275 -0
- package/package.json +51 -12
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -4
package/lib/esm/Lexer.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
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");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _Lexer_instances, _Lexer_position, _Lexer_expression, _Lexer_chars, _Lexer_current, _Lexer_length, _Lexer_consumeComparatorSigns, _Lexer_consumeEqualSign, _Lexer_consumeIdentifier, _Lexer_consumeNegativeNumber, _Lexer_consumeNumber, _Lexer_consumeSquareBracket, _Lexer_initializeForExpression, _Lexer_next, _Lexer_consumeUntil, _Lexer_consumeLiteral, _Lexer_consumeQuotedIdentifier, _Lexer_consumeRawStringLiteral, _Lexer_matchOrElse;
|
|
13
|
+
import { SIMPLE_TOKENS, START_IDENTIFIER, VALID_IDENTIFIER, VALID_NUMBER, WHITESPACE, } from './constants.js';
|
|
14
|
+
import { EmptyExpressionError, LexerError } from './errors.js';
|
|
15
|
+
/**
|
|
16
|
+
* A lexer for JMESPath expressions.
|
|
17
|
+
*
|
|
18
|
+
* This lexer tokenizes a JMESPath expression into a sequence of tokens.
|
|
19
|
+
*/
|
|
20
|
+
class Lexer {
|
|
21
|
+
constructor() {
|
|
22
|
+
_Lexer_instances.add(this);
|
|
23
|
+
_Lexer_position.set(this, void 0);
|
|
24
|
+
_Lexer_expression.set(this, void 0);
|
|
25
|
+
_Lexer_chars.set(this, void 0);
|
|
26
|
+
_Lexer_current.set(this, void 0);
|
|
27
|
+
_Lexer_length.set(this, void 0);
|
|
28
|
+
/**
|
|
29
|
+
* Consume a comparator sign.
|
|
30
|
+
*
|
|
31
|
+
* This method is called when the lexer encounters a comparator sign.
|
|
32
|
+
*
|
|
33
|
+
* @param current The current character
|
|
34
|
+
*/
|
|
35
|
+
_Lexer_consumeComparatorSigns.set(this, (current) => {
|
|
36
|
+
switch (current) {
|
|
37
|
+
case '<':
|
|
38
|
+
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'lte', 'lt');
|
|
39
|
+
case '>':
|
|
40
|
+
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'gte', 'gt');
|
|
41
|
+
case '!':
|
|
42
|
+
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'ne', 'not');
|
|
43
|
+
case '|':
|
|
44
|
+
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '|', 'or', 'pipe');
|
|
45
|
+
case '&':
|
|
46
|
+
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '&', 'and', 'expref');
|
|
47
|
+
default:
|
|
48
|
+
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeEqualSign).call(this);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Tokenize a JMESPath expression.
|
|
54
|
+
*
|
|
55
|
+
* This method is a generator that yields tokens for the given expression.
|
|
56
|
+
*
|
|
57
|
+
* @param expression The JMESPath expression to tokenize.
|
|
58
|
+
*/
|
|
59
|
+
*tokenize(expression) {
|
|
60
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_initializeForExpression).call(this, expression);
|
|
61
|
+
while (__classPrivateFieldGet(this, _Lexer_current, "f") !== '' && __classPrivateFieldGet(this, _Lexer_current, "f") !== undefined) {
|
|
62
|
+
if (SIMPLE_TOKENS.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
|
|
63
|
+
yield {
|
|
64
|
+
// We know that SIMPLE_TOKENS has this.#current as a key because
|
|
65
|
+
// we checked for that above.
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
+
type: SIMPLE_TOKENS.get(__classPrivateFieldGet(this, _Lexer_current, "f")),
|
|
68
|
+
value: __classPrivateFieldGet(this, _Lexer_current, "f"),
|
|
69
|
+
start: __classPrivateFieldGet(this, _Lexer_position, "f"),
|
|
70
|
+
end: __classPrivateFieldGet(this, _Lexer_position, "f") + 1,
|
|
71
|
+
};
|
|
72
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
73
|
+
}
|
|
74
|
+
else if (START_IDENTIFIER.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
|
|
75
|
+
yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeIdentifier).call(this);
|
|
76
|
+
}
|
|
77
|
+
else if (WHITESPACE.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
|
|
78
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
79
|
+
}
|
|
80
|
+
else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '[') {
|
|
81
|
+
yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeSquareBracket).call(this);
|
|
82
|
+
}
|
|
83
|
+
else if (__classPrivateFieldGet(this, _Lexer_current, "f") === `'`) {
|
|
84
|
+
yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeRawStringLiteral).call(this);
|
|
85
|
+
}
|
|
86
|
+
else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '`') {
|
|
87
|
+
yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeLiteral).call(this);
|
|
88
|
+
}
|
|
89
|
+
else if (VALID_NUMBER.has(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
|
|
90
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
91
|
+
const buff = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeNumber).call(this);
|
|
92
|
+
yield {
|
|
93
|
+
type: 'number',
|
|
94
|
+
value: parseInt(buff),
|
|
95
|
+
start: start,
|
|
96
|
+
end: start + buff.length,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '-') {
|
|
100
|
+
yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeNegativeNumber).call(this);
|
|
101
|
+
}
|
|
102
|
+
else if (__classPrivateFieldGet(this, _Lexer_current, "f") === '"') {
|
|
103
|
+
yield __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeQuotedIdentifier).call(this);
|
|
104
|
+
}
|
|
105
|
+
else if (['<', '>', '!', '=', '|', '&'].includes(__classPrivateFieldGet(this, _Lexer_current, "f"))) {
|
|
106
|
+
yield __classPrivateFieldGet(this, _Lexer_consumeComparatorSigns, "f").call(this, __classPrivateFieldGet(this, _Lexer_current, "f"));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw new LexerError(__classPrivateFieldGet(this, _Lexer_position, "f"), __classPrivateFieldGet(this, _Lexer_current, "f"));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
yield { type: 'eof', value: '', start: __classPrivateFieldGet(this, _Lexer_length, "f"), end: __classPrivateFieldGet(this, _Lexer_length, "f") };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
_Lexer_position = new WeakMap(), _Lexer_expression = new WeakMap(), _Lexer_chars = new WeakMap(), _Lexer_current = new WeakMap(), _Lexer_length = new WeakMap(), _Lexer_consumeComparatorSigns = new WeakMap(), _Lexer_instances = new WeakSet(), _Lexer_consumeEqualSign = function _Lexer_consumeEqualSign() {
|
|
116
|
+
if (__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this) === '=') {
|
|
117
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
118
|
+
return {
|
|
119
|
+
type: 'eq',
|
|
120
|
+
value: '==',
|
|
121
|
+
start: __classPrivateFieldGet(this, _Lexer_position, "f") - 1,
|
|
122
|
+
end: __classPrivateFieldGet(this, _Lexer_position, "f"),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
throw new LexerError(__classPrivateFieldGet(this, _Lexer_position, "f") - 1, '=');
|
|
127
|
+
}
|
|
128
|
+
}, _Lexer_consumeIdentifier = function _Lexer_consumeIdentifier() {
|
|
129
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
130
|
+
let buff = __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
131
|
+
while (VALID_IDENTIFIER.has(__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this))) {
|
|
132
|
+
buff += __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
type: 'unquoted_identifier',
|
|
136
|
+
value: buff,
|
|
137
|
+
start,
|
|
138
|
+
end: start + buff.length,
|
|
139
|
+
};
|
|
140
|
+
}, _Lexer_consumeNegativeNumber = function _Lexer_consumeNegativeNumber() {
|
|
141
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
142
|
+
const buff = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeNumber).call(this);
|
|
143
|
+
if (buff.length > 1) {
|
|
144
|
+
return {
|
|
145
|
+
type: 'number',
|
|
146
|
+
value: parseInt(buff),
|
|
147
|
+
start: start,
|
|
148
|
+
end: start + buff.length,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
// If the negative sign is not followed by a number, it is an error.
|
|
153
|
+
throw new LexerError(start, 'Unknown token after "-"');
|
|
154
|
+
}
|
|
155
|
+
}, _Lexer_consumeNumber = function _Lexer_consumeNumber() {
|
|
156
|
+
let buff = __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
157
|
+
while (VALID_NUMBER.has(__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this))) {
|
|
158
|
+
buff += __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
159
|
+
}
|
|
160
|
+
return buff;
|
|
161
|
+
}, _Lexer_consumeSquareBracket = function _Lexer_consumeSquareBracket() {
|
|
162
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
163
|
+
const nextChar = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
164
|
+
if (nextChar == ']') {
|
|
165
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
166
|
+
return { type: 'flatten', value: '[]', start: start, end: start + 2 };
|
|
167
|
+
}
|
|
168
|
+
else if (nextChar == '?') {
|
|
169
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
170
|
+
return { type: 'filter', value: '[?', start: start, end: start + 2 };
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return { type: 'lbracket', value: '[', start: start, end: start + 1 };
|
|
174
|
+
}
|
|
175
|
+
}, _Lexer_initializeForExpression = function _Lexer_initializeForExpression(expression) {
|
|
176
|
+
if (typeof expression !== 'string') {
|
|
177
|
+
throw new EmptyExpressionError();
|
|
178
|
+
}
|
|
179
|
+
__classPrivateFieldSet(this, _Lexer_position, 0, "f");
|
|
180
|
+
__classPrivateFieldSet(this, _Lexer_expression, expression, "f");
|
|
181
|
+
__classPrivateFieldSet(this, _Lexer_chars, Array.from(expression), "f");
|
|
182
|
+
__classPrivateFieldSet(this, _Lexer_current, __classPrivateFieldGet(this, _Lexer_chars, "f")[0], "f");
|
|
183
|
+
__classPrivateFieldSet(this, _Lexer_length, __classPrivateFieldGet(this, _Lexer_expression, "f").length, "f");
|
|
184
|
+
}, _Lexer_next = function _Lexer_next() {
|
|
185
|
+
if (__classPrivateFieldGet(this, _Lexer_position, "f") === __classPrivateFieldGet(this, _Lexer_length, "f") - 1) {
|
|
186
|
+
__classPrivateFieldSet(this, _Lexer_current, '', "f");
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
__classPrivateFieldSet(this, _Lexer_position, __classPrivateFieldGet(this, _Lexer_position, "f") + 1, "f");
|
|
190
|
+
__classPrivateFieldSet(this, _Lexer_current, __classPrivateFieldGet(this, _Lexer_chars, "f")[__classPrivateFieldGet(this, _Lexer_position, "f")], "f");
|
|
191
|
+
}
|
|
192
|
+
return __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
193
|
+
}, _Lexer_consumeUntil = function _Lexer_consumeUntil(delimiter) {
|
|
194
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
195
|
+
let buff = '';
|
|
196
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
197
|
+
while (__classPrivateFieldGet(this, _Lexer_current, "f") !== delimiter) {
|
|
198
|
+
if (__classPrivateFieldGet(this, _Lexer_current, "f") === '\\') {
|
|
199
|
+
buff += '\\';
|
|
200
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
201
|
+
}
|
|
202
|
+
if (__classPrivateFieldGet(this, _Lexer_current, "f") === '') {
|
|
203
|
+
// We've reached the end of the expression (EOF) before
|
|
204
|
+
// we found the delimiter. This is an error.
|
|
205
|
+
throw new LexerError(start, __classPrivateFieldGet(this, _Lexer_expression, "f").substring(start));
|
|
206
|
+
}
|
|
207
|
+
buff += __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
208
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
209
|
+
}
|
|
210
|
+
// Skip the closing delimiter
|
|
211
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
212
|
+
return buff;
|
|
213
|
+
}, _Lexer_consumeLiteral = function _Lexer_consumeLiteral() {
|
|
214
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
215
|
+
const lexeme = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeUntil).call(this, '`').replace('\\`', '`');
|
|
216
|
+
try {
|
|
217
|
+
const parsedJson = JSON.parse(lexeme);
|
|
218
|
+
return {
|
|
219
|
+
type: 'literal',
|
|
220
|
+
value: parsedJson,
|
|
221
|
+
start,
|
|
222
|
+
end: __classPrivateFieldGet(this, _Lexer_position, "f") - start,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
throw new LexerError(start, lexeme);
|
|
227
|
+
}
|
|
228
|
+
}, _Lexer_consumeQuotedIdentifier = function _Lexer_consumeQuotedIdentifier() {
|
|
229
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
230
|
+
const lexeme = '"' + __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeUntil).call(this, '"') + '"';
|
|
231
|
+
const tokenLen = __classPrivateFieldGet(this, _Lexer_position, "f") - start;
|
|
232
|
+
return {
|
|
233
|
+
type: 'quoted_identifier',
|
|
234
|
+
value: JSON.parse(lexeme),
|
|
235
|
+
start,
|
|
236
|
+
end: tokenLen,
|
|
237
|
+
};
|
|
238
|
+
}, _Lexer_consumeRawStringLiteral = function _Lexer_consumeRawStringLiteral() {
|
|
239
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
240
|
+
const lexeme = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeUntil).call(this, `'`).replace(`\\'`, `'`);
|
|
241
|
+
const tokenLen = __classPrivateFieldGet(this, _Lexer_position, "f") - start;
|
|
242
|
+
return {
|
|
243
|
+
type: 'literal',
|
|
244
|
+
value: lexeme,
|
|
245
|
+
start,
|
|
246
|
+
end: tokenLen,
|
|
247
|
+
};
|
|
248
|
+
}, _Lexer_matchOrElse = function _Lexer_matchOrElse(expected, matchType, elseType) {
|
|
249
|
+
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
250
|
+
const current = __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
251
|
+
const nextChar = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
252
|
+
if (nextChar === expected) {
|
|
253
|
+
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
254
|
+
return {
|
|
255
|
+
type: matchType,
|
|
256
|
+
value: current + nextChar,
|
|
257
|
+
start,
|
|
258
|
+
end: start + 2,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
type: elseType,
|
|
263
|
+
value: current,
|
|
264
|
+
start,
|
|
265
|
+
end: start,
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
export { Lexer };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Node, ParsingOptions, JSONObject } from './types.js';
|
|
2
|
+
declare class ParsedResult {
|
|
3
|
+
expression: string;
|
|
4
|
+
parsed: Node;
|
|
5
|
+
constructor(expression: string, parsed: Node);
|
|
6
|
+
/**
|
|
7
|
+
* Perform a JMESPath search on a JSON value.
|
|
8
|
+
*
|
|
9
|
+
* @param value The JSON value to search
|
|
10
|
+
* @param options The parsing options to use
|
|
11
|
+
*/
|
|
12
|
+
search(value: JSONObject, options?: ParsingOptions): unknown;
|
|
13
|
+
}
|
|
14
|
+
export { ParsedResult };
|
|
15
|
+
//# sourceMappingURL=ParsedResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParsedResult.d.ts","sourceRoot":"","sources":["../../src/ParsedResult.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnE,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,cAAc,GAAG,OAAO;CAiBpE;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TreeInterpreter } from './TreeInterpreter.js';
|
|
2
|
+
import { ArityError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
|
|
3
|
+
class ParsedResult {
|
|
4
|
+
constructor(expression, parsed) {
|
|
5
|
+
this.expression = expression;
|
|
6
|
+
this.parsed = parsed;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Perform a JMESPath search on a JSON value.
|
|
10
|
+
*
|
|
11
|
+
* @param value The JSON value to search
|
|
12
|
+
* @param options The parsing options to use
|
|
13
|
+
*/
|
|
14
|
+
search(value, options) {
|
|
15
|
+
const interpreter = new TreeInterpreter(options);
|
|
16
|
+
try {
|
|
17
|
+
return interpreter.visit(this.parsed, value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof JMESPathTypeError ||
|
|
21
|
+
error instanceof UnknownFunctionError ||
|
|
22
|
+
error instanceof ArityError ||
|
|
23
|
+
error instanceof VariadicArityError) {
|
|
24
|
+
error.setExpression(this.expression);
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export { ParsedResult };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ParsedResult } from './ParsedResult.js';
|
|
2
|
+
/**
|
|
3
|
+
* Top down operaotr precedence parser for JMESPath.
|
|
4
|
+
*
|
|
5
|
+
* ## References
|
|
6
|
+
* The implementation of this Parser is based on the implementation of
|
|
7
|
+
* [jmespath.py](https://github.com/jmespath/jmespath.py/), which in turn
|
|
8
|
+
* is based on [Vaughan R. Pratt's "Top Down Operator Precedence"](http://dl.acm.org/citation.cfm?doid=512927.512931).
|
|
9
|
+
*
|
|
10
|
+
* If you don't want to read the full paper, there are some other good
|
|
11
|
+
* overviews that explain the general idea:
|
|
12
|
+
* - [Pratt Parsers: Expression Parsing Made Easy](https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/)
|
|
13
|
+
* - [Simple Top-Down Parsing in Python](https://11l-lang.org/archive/simple-top-down-parsing/)
|
|
14
|
+
* - [Top Down Operator Precedence](http://javascript.crockford.com/tdop/tdop.html)
|
|
15
|
+
*/
|
|
16
|
+
declare class Parser {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(lookahead?: number);
|
|
19
|
+
/**
|
|
20
|
+
* Parse a JMESPath expression and return the Abstract Syntax Tree (AST)
|
|
21
|
+
* that represents the expression.
|
|
22
|
+
*
|
|
23
|
+
* The AST is cached, so if you parse the same expression multiple times,
|
|
24
|
+
* the AST will be returned from the cache.
|
|
25
|
+
*
|
|
26
|
+
* @param expression The JMESPath expression to parse.
|
|
27
|
+
*/
|
|
28
|
+
parse(expression: string): ParsedResult;
|
|
29
|
+
/**
|
|
30
|
+
* Purge the entire cache.
|
|
31
|
+
*/
|
|
32
|
+
purgeCache(): void;
|
|
33
|
+
}
|
|
34
|
+
export { Parser };
|
|
35
|
+
//# sourceMappingURL=Parser.d.ts.map
|
|
@@ -0,0 +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;CAkuB1B;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|