@aws-lambda-powertools/jmespath 0.0.0-alpha.0 → 2.1.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/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 +262 -0
- package/lib/cjs/Functions.d.ts.map +1 -0
- package/lib/cjs/Functions.js +619 -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 +84 -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 +262 -0
- package/lib/esm/Functions.d.ts.map +1 -0
- package/lib/esm/Functions.js +616 -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 +84 -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
|
@@ -0,0 +1,503 @@
|
|
|
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 _Parser_instances, _Parser_projectionStop, _Parser_cache, _Parser_maxCacheSize, _Parser_tokenizer, _Parser_tokens, _Parser_index, _Parser_doParse, _Parser_parse, _Parser_expression, _Parser_getNudFunction, _Parser_processQuotedIdentifier, _Parser_processStarToken, _Parser_processLParenTokenNud, _Parser_processFlattenTokenNud, _Parser_processLBracketTokenNud, _Parser_processDefaultToken, _Parser_getLedFunction, _Parser_processDotToken, _Parser_processPipeToken, _Parser_processOrToken, _Parser_processAndToken, _Parser_processLParenToken, _Parser_processFilterToken, _Parser_processFlattenToken, _Parser_processLBracketToken, _Parser_throwParseError, _Parser_parseIndexExpression, _Parser_parseSliceExpression, _Parser_projectIfSlice, _Parser_parseComparator, _Parser_parseMultiSelectList, _Parser_parseMultiSelectHash, _Parser_parseProjectionRhs, _Parser_parseDotRhs, _Parser_match, _Parser_matchMultipleTokens, _Parser_advance, _Parser_currentToken, _Parser_lookahead, _Parser_lookaheadToken, _Parser_evictCache;
|
|
13
|
+
import { randomInt } from 'node:crypto';
|
|
14
|
+
import { Lexer } from './Lexer.js';
|
|
15
|
+
import { ParsedResult } from './ParsedResult.js';
|
|
16
|
+
import { andExpression, comparator, currentNode, expref, field, filterProjection, flatten, functionExpression, identity, index, indexExpression, keyValPair, literal, multiSelectObject, multiSelectList, notExpression, orExpression, pipe, projection, slice, subexpression, valueProjection, } from './ast.js';
|
|
17
|
+
import { BINDING_POWER } from './constants.js';
|
|
18
|
+
import { IncompleteExpressionError, LexerError, ParseError } from './errors.js';
|
|
19
|
+
/**
|
|
20
|
+
* Top down operaotr precedence parser for JMESPath.
|
|
21
|
+
*
|
|
22
|
+
* ## References
|
|
23
|
+
* The implementation of this Parser is based on the implementation of
|
|
24
|
+
* [jmespath.py](https://github.com/jmespath/jmespath.py/), which in turn
|
|
25
|
+
* is based on [Vaughan R. Pratt's "Top Down Operator Precedence"](http://dl.acm.org/citation.cfm?doid=512927.512931).
|
|
26
|
+
*
|
|
27
|
+
* If you don't want to read the full paper, there are some other good
|
|
28
|
+
* overviews that explain the general idea:
|
|
29
|
+
* - [Pratt Parsers: Expression Parsing Made Easy](https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/)
|
|
30
|
+
* - [Simple Top-Down Parsing in Python](https://11l-lang.org/archive/simple-top-down-parsing/)
|
|
31
|
+
* - [Top Down Operator Precedence](http://javascript.crockford.com/tdop/tdop.html)
|
|
32
|
+
*/
|
|
33
|
+
class Parser {
|
|
34
|
+
constructor(lookahead = 2) {
|
|
35
|
+
_Parser_instances.add(this);
|
|
36
|
+
/**
|
|
37
|
+
* The maximum binding power for a token
|
|
38
|
+
* that can stop a projection.
|
|
39
|
+
*/
|
|
40
|
+
_Parser_projectionStop.set(this, 10);
|
|
41
|
+
/**
|
|
42
|
+
* Cache object
|
|
43
|
+
*/
|
|
44
|
+
_Parser_cache.set(this, {});
|
|
45
|
+
/**
|
|
46
|
+
* The maximum size of the cache.
|
|
47
|
+
*/
|
|
48
|
+
_Parser_maxCacheSize.set(this, 128);
|
|
49
|
+
_Parser_tokenizer.set(this, void 0);
|
|
50
|
+
_Parser_tokens.set(this, void 0);
|
|
51
|
+
_Parser_index.set(this, 0);
|
|
52
|
+
__classPrivateFieldSet(this, _Parser_tokens, Array.from({ length: lookahead }), "f");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse a JMESPath expression and return the Abstract Syntax Tree (AST)
|
|
56
|
+
* that represents the expression.
|
|
57
|
+
*
|
|
58
|
+
* The AST is cached, so if you parse the same expression multiple times,
|
|
59
|
+
* the AST will be returned from the cache.
|
|
60
|
+
*
|
|
61
|
+
* @param expression The JMESPath expression to parse.
|
|
62
|
+
*/
|
|
63
|
+
parse(expression) {
|
|
64
|
+
const cached = __classPrivateFieldGet(this, _Parser_cache, "f")[expression];
|
|
65
|
+
if (cached) {
|
|
66
|
+
return cached;
|
|
67
|
+
}
|
|
68
|
+
const parsedResult = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_doParse).call(this, expression);
|
|
69
|
+
__classPrivateFieldGet(this, _Parser_cache, "f")[expression] = parsedResult;
|
|
70
|
+
if (Object.keys(__classPrivateFieldGet(this, _Parser_cache, "f")).length > __classPrivateFieldGet(this, _Parser_maxCacheSize, "f")) {
|
|
71
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_evictCache).call(this);
|
|
72
|
+
}
|
|
73
|
+
return parsedResult;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Purge the entire cache.
|
|
77
|
+
*/
|
|
78
|
+
purgeCache() {
|
|
79
|
+
__classPrivateFieldSet(this, _Parser_cache, {}, "f");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
_Parser_projectionStop = new WeakMap(), _Parser_cache = new WeakMap(), _Parser_maxCacheSize = new WeakMap(), _Parser_tokenizer = new WeakMap(), _Parser_tokens = new WeakMap(), _Parser_index = new WeakMap(), _Parser_instances = new WeakSet(), _Parser_doParse = function _Parser_doParse(expression) {
|
|
83
|
+
try {
|
|
84
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parse).call(this, expression);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof LexerError ||
|
|
88
|
+
error instanceof IncompleteExpressionError ||
|
|
89
|
+
error instanceof ParseError) {
|
|
90
|
+
error.setExpression(expression);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}, _Parser_parse = function _Parser_parse(expression) {
|
|
96
|
+
__classPrivateFieldSet(this, _Parser_tokenizer, new Lexer(), "f");
|
|
97
|
+
__classPrivateFieldSet(this, _Parser_tokens, [...__classPrivateFieldGet(this, _Parser_tokenizer, "f").tokenize(expression)], "f");
|
|
98
|
+
__classPrivateFieldSet(this, _Parser_index, 0, "f");
|
|
99
|
+
const parsed = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, 0);
|
|
100
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) !== 'eof') {
|
|
101
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this);
|
|
102
|
+
}
|
|
103
|
+
return new ParsedResult(expression, parsed);
|
|
104
|
+
}, _Parser_expression = function _Parser_expression(bindingPower = 0) {
|
|
105
|
+
const leftToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0);
|
|
106
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
107
|
+
let left = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_getNudFunction).call(this, leftToken);
|
|
108
|
+
let currentToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
109
|
+
while (bindingPower < BINDING_POWER[currentToken]) {
|
|
110
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
111
|
+
left = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_getLedFunction).call(this, currentToken, left);
|
|
112
|
+
currentToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
113
|
+
}
|
|
114
|
+
return left;
|
|
115
|
+
}, _Parser_getNudFunction = function _Parser_getNudFunction(token) {
|
|
116
|
+
const { type: tokenType } = token;
|
|
117
|
+
switch (tokenType) {
|
|
118
|
+
case 'literal':
|
|
119
|
+
return literal(token.value);
|
|
120
|
+
case 'unquoted_identifier':
|
|
121
|
+
return field(token.value);
|
|
122
|
+
case 'quoted_identifier':
|
|
123
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processQuotedIdentifier).call(this, token);
|
|
124
|
+
case 'star':
|
|
125
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processStarToken).call(this);
|
|
126
|
+
case 'filter':
|
|
127
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_getLedFunction).call(this, tokenType, identity());
|
|
128
|
+
case 'lbrace':
|
|
129
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseMultiSelectHash).call(this);
|
|
130
|
+
case 'lparen':
|
|
131
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processLParenTokenNud).call(this);
|
|
132
|
+
case 'flatten':
|
|
133
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processFlattenTokenNud).call(this);
|
|
134
|
+
case 'not':
|
|
135
|
+
return notExpression(__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, BINDING_POWER['not']));
|
|
136
|
+
case 'lbracket':
|
|
137
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processLBracketTokenNud).call(this);
|
|
138
|
+
case 'current':
|
|
139
|
+
return currentNode();
|
|
140
|
+
case 'expref':
|
|
141
|
+
return expref(__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, BINDING_POWER['expref']));
|
|
142
|
+
default:
|
|
143
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processDefaultToken).call(this, token);
|
|
144
|
+
}
|
|
145
|
+
}, _Parser_processQuotedIdentifier = function _Parser_processQuotedIdentifier(token) {
|
|
146
|
+
const fieldValue = field(token.value);
|
|
147
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) === 'lparen') {
|
|
148
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this, {
|
|
149
|
+
lexPosition: 0,
|
|
150
|
+
reason: 'quoted identifiers cannot be used as a function name',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return fieldValue;
|
|
154
|
+
}, _Parser_processStarToken = function _Parser_processStarToken() {
|
|
155
|
+
const left = identity();
|
|
156
|
+
let right;
|
|
157
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) === 'rbracket') {
|
|
158
|
+
right = identity();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['star']);
|
|
162
|
+
}
|
|
163
|
+
return valueProjection(left, right);
|
|
164
|
+
}, _Parser_processLParenTokenNud = function _Parser_processLParenTokenNud() {
|
|
165
|
+
const expression = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this);
|
|
166
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rparen');
|
|
167
|
+
return expression;
|
|
168
|
+
}, _Parser_processFlattenTokenNud = function _Parser_processFlattenTokenNud() {
|
|
169
|
+
const left = flatten(identity());
|
|
170
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['flatten']);
|
|
171
|
+
return projection(left, right);
|
|
172
|
+
}, _Parser_processLBracketTokenNud = function _Parser_processLBracketTokenNud() {
|
|
173
|
+
if (['number', 'colon'].includes(__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this))) {
|
|
174
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseIndexExpression).call(this);
|
|
175
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_projectIfSlice).call(this, identity(), right);
|
|
176
|
+
}
|
|
177
|
+
else if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) === 'star' &&
|
|
178
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookahead).call(this, 1) === 'rbracket') {
|
|
179
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
180
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
181
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['star']);
|
|
182
|
+
return projection(identity(), right);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseMultiSelectList).call(this);
|
|
186
|
+
}
|
|
187
|
+
}, _Parser_processDefaultToken = function _Parser_processDefaultToken(token) {
|
|
188
|
+
if (token.type === 'eof') {
|
|
189
|
+
throw new IncompleteExpressionError({
|
|
190
|
+
lexPosition: token.start,
|
|
191
|
+
tokenValue: token.value,
|
|
192
|
+
tokenType: token.type,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
throw new ParseError({
|
|
196
|
+
lexPosition: token.start,
|
|
197
|
+
tokenValue: token.value,
|
|
198
|
+
tokenType: token.type,
|
|
199
|
+
});
|
|
200
|
+
}, _Parser_getLedFunction = function _Parser_getLedFunction(tokenType, leftNode) {
|
|
201
|
+
switch (tokenType) {
|
|
202
|
+
case 'dot':
|
|
203
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processDotToken).call(this, leftNode);
|
|
204
|
+
case 'pipe':
|
|
205
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processPipeToken).call(this, leftNode);
|
|
206
|
+
case 'or':
|
|
207
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processOrToken).call(this, leftNode);
|
|
208
|
+
case 'and':
|
|
209
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processAndToken).call(this, leftNode);
|
|
210
|
+
case 'lparen':
|
|
211
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processLParenToken).call(this, leftNode);
|
|
212
|
+
case 'filter':
|
|
213
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processFilterToken).call(this, leftNode);
|
|
214
|
+
case 'eq':
|
|
215
|
+
case 'ne':
|
|
216
|
+
case 'gt':
|
|
217
|
+
case 'gte':
|
|
218
|
+
case 'lt':
|
|
219
|
+
case 'lte':
|
|
220
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseComparator).call(this, leftNode, tokenType);
|
|
221
|
+
case 'flatten':
|
|
222
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processFlattenToken).call(this, leftNode);
|
|
223
|
+
case 'lbracket':
|
|
224
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_processLBracketToken).call(this, leftNode);
|
|
225
|
+
default:
|
|
226
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this);
|
|
227
|
+
}
|
|
228
|
+
}, _Parser_processDotToken = function _Parser_processDotToken(leftNode) {
|
|
229
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) !== 'star') {
|
|
230
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseDotRhs).call(this, BINDING_POWER['dot']);
|
|
231
|
+
if (leftNode.type === 'subexpression') {
|
|
232
|
+
leftNode.children.push(right);
|
|
233
|
+
return leftNode;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return subexpression([leftNode, right]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// We are creating a value projection
|
|
241
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
242
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['dot']);
|
|
243
|
+
return valueProjection(leftNode, right);
|
|
244
|
+
}
|
|
245
|
+
}, _Parser_processPipeToken = function _Parser_processPipeToken(leftNode) {
|
|
246
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, BINDING_POWER['pipe']);
|
|
247
|
+
return pipe(leftNode, right);
|
|
248
|
+
}, _Parser_processOrToken = function _Parser_processOrToken(leftNode) {
|
|
249
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, BINDING_POWER['or']);
|
|
250
|
+
return orExpression(leftNode, right);
|
|
251
|
+
}, _Parser_processAndToken = function _Parser_processAndToken(leftNode) {
|
|
252
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, BINDING_POWER['and']);
|
|
253
|
+
return andExpression(leftNode, right);
|
|
254
|
+
}, _Parser_processLParenToken = function _Parser_processLParenToken(leftNode) {
|
|
255
|
+
const name = leftNode.value;
|
|
256
|
+
const args = [];
|
|
257
|
+
while (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) !== 'rparen') {
|
|
258
|
+
const expression = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this);
|
|
259
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) === 'comma') {
|
|
260
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'comma');
|
|
261
|
+
}
|
|
262
|
+
args.push(expression);
|
|
263
|
+
}
|
|
264
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rparen');
|
|
265
|
+
return functionExpression(name, args);
|
|
266
|
+
}, _Parser_processFilterToken = function _Parser_processFilterToken(leftNode) {
|
|
267
|
+
// Filters are projections
|
|
268
|
+
const condition = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, 0);
|
|
269
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rbracket');
|
|
270
|
+
let right;
|
|
271
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) === 'flatten') {
|
|
272
|
+
right = identity();
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['flatten']);
|
|
276
|
+
}
|
|
277
|
+
return filterProjection(leftNode, right, condition);
|
|
278
|
+
}, _Parser_processFlattenToken = function _Parser_processFlattenToken(leftNode) {
|
|
279
|
+
const left = flatten(leftNode);
|
|
280
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['flatten']);
|
|
281
|
+
return projection(left, right);
|
|
282
|
+
}, _Parser_processLBracketToken = function _Parser_processLBracketToken(leftNode) {
|
|
283
|
+
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0);
|
|
284
|
+
if (['number', 'colon'].includes(token.type)) {
|
|
285
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseIndexExpression).call(this);
|
|
286
|
+
if (leftNode.type === 'index_expression') {
|
|
287
|
+
// Optimization: if the left node is an index expression
|
|
288
|
+
// we can avoid creating another node and instead just
|
|
289
|
+
// add the right node as a child of the left node.
|
|
290
|
+
leftNode.children.push(right);
|
|
291
|
+
return leftNode;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_projectIfSlice).call(this, leftNode, right);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
// We have a projection
|
|
299
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'star');
|
|
300
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rbracket');
|
|
301
|
+
const right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['star']);
|
|
302
|
+
return projection(leftNode, right);
|
|
303
|
+
}
|
|
304
|
+
}, _Parser_throwParseError = function _Parser_throwParseError(options) {
|
|
305
|
+
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0);
|
|
306
|
+
throw new ParseError({
|
|
307
|
+
lexPosition: options?.lexPosition ?? token.start,
|
|
308
|
+
tokenValue: options?.tokenValue ?? token.value,
|
|
309
|
+
tokenType: options?.tokenType ?? token.type,
|
|
310
|
+
reason: options?.reason,
|
|
311
|
+
});
|
|
312
|
+
}, _Parser_parseIndexExpression = function _Parser_parseIndexExpression() {
|
|
313
|
+
// We're here:
|
|
314
|
+
// [<current>
|
|
315
|
+
// ^
|
|
316
|
+
// | (currentToken)
|
|
317
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookahead).call(this, 0) === 'colon' || __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookahead).call(this, 1) === 'colon') {
|
|
318
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseSliceExpression).call(this);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
// Parse the syntax [number]
|
|
322
|
+
const node = index(__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0).value);
|
|
323
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
324
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rbracket');
|
|
325
|
+
return node;
|
|
326
|
+
}
|
|
327
|
+
}, _Parser_parseSliceExpression = function _Parser_parseSliceExpression() {
|
|
328
|
+
// [start:end:step]
|
|
329
|
+
// Where start, end, and step are optional.
|
|
330
|
+
// The last colon is optional as well.
|
|
331
|
+
const parts = [];
|
|
332
|
+
let index = 0;
|
|
333
|
+
let currentToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
334
|
+
while (currentToken !== 'rbracket' && index < 3) {
|
|
335
|
+
if (currentToken === 'colon') {
|
|
336
|
+
index += 1;
|
|
337
|
+
if (index === 3) {
|
|
338
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this);
|
|
339
|
+
}
|
|
340
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
341
|
+
}
|
|
342
|
+
else if (currentToken === 'number') {
|
|
343
|
+
parts[index] = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0).value;
|
|
344
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this);
|
|
348
|
+
}
|
|
349
|
+
currentToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
350
|
+
}
|
|
351
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rbracket');
|
|
352
|
+
return slice(parts[0], parts[1], parts[2]);
|
|
353
|
+
}, _Parser_projectIfSlice = function _Parser_projectIfSlice(left, right) {
|
|
354
|
+
const idxExpression = indexExpression([left, right]);
|
|
355
|
+
if (right.type === 'slice') {
|
|
356
|
+
return projection(idxExpression, __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseProjectionRhs).call(this, BINDING_POWER['star']));
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
return idxExpression;
|
|
360
|
+
}
|
|
361
|
+
}, _Parser_parseComparator = function _Parser_parseComparator(left, comparatorChar) {
|
|
362
|
+
return comparator(comparatorChar, left, __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, BINDING_POWER[comparatorChar]));
|
|
363
|
+
}, _Parser_parseMultiSelectList = function _Parser_parseMultiSelectList() {
|
|
364
|
+
const expressions = [];
|
|
365
|
+
while (true) {
|
|
366
|
+
const expression = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this);
|
|
367
|
+
expressions.push(expression);
|
|
368
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) === 'rbracket') {
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'comma');
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rbracket');
|
|
376
|
+
return multiSelectList(expressions);
|
|
377
|
+
}, _Parser_parseMultiSelectHash = function _Parser_parseMultiSelectHash() {
|
|
378
|
+
const pairs = [];
|
|
379
|
+
while (true) {
|
|
380
|
+
const keyToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0);
|
|
381
|
+
// Before getting the token value, verify it's
|
|
382
|
+
// an identifier.
|
|
383
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_matchMultipleTokens).call(this, ['quoted_identifier', 'unquoted_identifier']); // token types
|
|
384
|
+
const keyName = keyToken['value'];
|
|
385
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'colon');
|
|
386
|
+
const value = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, 0);
|
|
387
|
+
const node = keyValPair(keyName, value);
|
|
388
|
+
pairs.push(node);
|
|
389
|
+
if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) == 'comma') {
|
|
390
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'comma');
|
|
391
|
+
}
|
|
392
|
+
else if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) == 'rbrace') {
|
|
393
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'rbrace');
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return multiSelectObject(pairs);
|
|
398
|
+
}, _Parser_parseProjectionRhs = function _Parser_parseProjectionRhs(bindingPower) {
|
|
399
|
+
// Parse the right hand side of the projection.
|
|
400
|
+
let right;
|
|
401
|
+
if (BINDING_POWER[__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this)] < __classPrivateFieldGet(this, _Parser_projectionStop, "f")) {
|
|
402
|
+
// BP of 10 are all the tokens that stop a projection.
|
|
403
|
+
right = identity();
|
|
404
|
+
}
|
|
405
|
+
else if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) == 'lbracket') {
|
|
406
|
+
right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, bindingPower);
|
|
407
|
+
}
|
|
408
|
+
else if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) == 'filter') {
|
|
409
|
+
right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, bindingPower);
|
|
410
|
+
}
|
|
411
|
+
else if (__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this) == 'dot') {
|
|
412
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'dot');
|
|
413
|
+
right = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseDotRhs).call(this, bindingPower);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this);
|
|
417
|
+
}
|
|
418
|
+
return right;
|
|
419
|
+
}, _Parser_parseDotRhs = function _Parser_parseDotRhs(bindingPower) {
|
|
420
|
+
// From the grammar:
|
|
421
|
+
// expression '.' ( identifier /
|
|
422
|
+
// multi-select-list /
|
|
423
|
+
// multi-select-hash /
|
|
424
|
+
// function-expression /
|
|
425
|
+
// *
|
|
426
|
+
// In terms of tokens that means that after a '.',
|
|
427
|
+
// you can have:
|
|
428
|
+
const lookahead = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
429
|
+
// Common case "foo.bar", so first check for an identifier.
|
|
430
|
+
if (['quoted_identifier', 'unquoted_identifier', 'star'].includes(lookahead)) {
|
|
431
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_expression).call(this, bindingPower);
|
|
432
|
+
}
|
|
433
|
+
else if (lookahead == 'lbracket') {
|
|
434
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'lbracket');
|
|
435
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseMultiSelectList).call(this);
|
|
436
|
+
}
|
|
437
|
+
else if (lookahead == 'lbrace') {
|
|
438
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_match).call(this, 'lbrace');
|
|
439
|
+
return __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_parseMultiSelectHash).call(this);
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_throwParseError).call(this);
|
|
443
|
+
}
|
|
444
|
+
}, _Parser_match = function _Parser_match(tokenType) {
|
|
445
|
+
const currentToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
446
|
+
if (currentToken === tokenType) {
|
|
447
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0);
|
|
451
|
+
if (token.type === 'eof') {
|
|
452
|
+
throw new IncompleteExpressionError({
|
|
453
|
+
lexPosition: token.start,
|
|
454
|
+
tokenValue: token.value,
|
|
455
|
+
tokenType: token.type,
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
throw new ParseError({
|
|
460
|
+
lexPosition: token.start,
|
|
461
|
+
tokenValue: token.value,
|
|
462
|
+
tokenType: token.type,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}, _Parser_matchMultipleTokens = function _Parser_matchMultipleTokens(tokenTypes) {
|
|
467
|
+
const currentToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_currentToken).call(this);
|
|
468
|
+
if (!tokenTypes.includes(currentToken)) {
|
|
469
|
+
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_lookaheadToken).call(this, 0);
|
|
470
|
+
if (token.type === 'eof') {
|
|
471
|
+
throw new IncompleteExpressionError({
|
|
472
|
+
lexPosition: token.start,
|
|
473
|
+
tokenValue: token.value,
|
|
474
|
+
tokenType: token.type,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
throw new ParseError({
|
|
479
|
+
lexPosition: token.start,
|
|
480
|
+
tokenValue: token.value,
|
|
481
|
+
tokenType: token.type,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_advance).call(this);
|
|
486
|
+
}, _Parser_advance = function _Parser_advance() {
|
|
487
|
+
__classPrivateFieldSet(this, _Parser_index, __classPrivateFieldGet(this, _Parser_index, "f") + 1, "f");
|
|
488
|
+
}, _Parser_currentToken = function _Parser_currentToken() {
|
|
489
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f")[__classPrivateFieldGet(this, _Parser_index, "f")].type;
|
|
490
|
+
}, _Parser_lookahead = function _Parser_lookahead(number) {
|
|
491
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f")[__classPrivateFieldGet(this, _Parser_index, "f") + number].type;
|
|
492
|
+
}, _Parser_lookaheadToken = function _Parser_lookaheadToken(number) {
|
|
493
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f")[__classPrivateFieldGet(this, _Parser_index, "f") + number];
|
|
494
|
+
}, _Parser_evictCache = function _Parser_evictCache() {
|
|
495
|
+
const newCache = Object.keys(__classPrivateFieldGet(this, _Parser_cache, "f")).reduce((acc, key) => {
|
|
496
|
+
if (randomInt(0, 100) > 50) {
|
|
497
|
+
acc[key] = __classPrivateFieldGet(this, _Parser_cache, "f")[key];
|
|
498
|
+
}
|
|
499
|
+
return acc;
|
|
500
|
+
}, {});
|
|
501
|
+
__classPrivateFieldSet(this, _Parser_cache, newCache, "f");
|
|
502
|
+
};
|
|
503
|
+
export { Parser };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
|
|
2
|
+
import { Functions } from './Functions.js';
|
|
3
|
+
/**
|
|
4
|
+
* Custom functions for the Powertools for AWS Lambda JMESPath module.
|
|
5
|
+
*
|
|
6
|
+
* Built-in JMESPath functions include: `powertools_json`, `powertools_base64`, `powertools_base64_gzip`
|
|
7
|
+
*
|
|
8
|
+
* You can use these functions to decode and/or deserialize JSON objects when using the {@link index.search | search} function.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { search } from '@aws-lambda-powertools/jmespath';
|
|
13
|
+
* import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
|
|
14
|
+
*
|
|
15
|
+
* const data = {
|
|
16
|
+
* body: "{\"foo\": \"bar\"}"
|
|
17
|
+
* };
|
|
18
|
+
*
|
|
19
|
+
* const result = search(
|
|
20
|
+
* 'powertools_json(body)',
|
|
21
|
+
* data,
|
|
22
|
+
* { customFunctions: new PowertoolsFunctions() }
|
|
23
|
+
* );
|
|
24
|
+
* console.log(result); // { foo: 'bar' }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* When using the {@link extractDataFromEnvelope} function, the PowertoolsFunctions class is automatically used.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
declare class PowertoolsFunctions extends Functions {
|
|
31
|
+
funcPowertoolsBase64(value: string): string;
|
|
32
|
+
funcPowertoolsBase64Gzip(value: string): string;
|
|
33
|
+
funcPowertoolsJson(value: string): JSONValue;
|
|
34
|
+
}
|
|
35
|
+
export { PowertoolsFunctions };
|
|
36
|
+
//# sourceMappingURL=PowertoolsFunctions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PowertoolsFunctions.d.ts","sourceRoot":"","sources":["../../src/PowertoolsFunctions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,cAAM,mBAAoB,SAAQ,SAAS;IAIlC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAO3C,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAU/C,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS;CAGpD;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { gunzipSync } from 'node:zlib';
|
|
8
|
+
import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64';
|
|
9
|
+
import { Functions } from './Functions.js';
|
|
10
|
+
const decoder = new TextDecoder('utf-8');
|
|
11
|
+
/**
|
|
12
|
+
* Custom functions for the Powertools for AWS Lambda JMESPath module.
|
|
13
|
+
*
|
|
14
|
+
* Built-in JMESPath functions include: `powertools_json`, `powertools_base64`, `powertools_base64_gzip`
|
|
15
|
+
*
|
|
16
|
+
* You can use these functions to decode and/or deserialize JSON objects when using the {@link index.search | search} function.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { search } from '@aws-lambda-powertools/jmespath';
|
|
21
|
+
* import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
|
|
22
|
+
*
|
|
23
|
+
* const data = {
|
|
24
|
+
* body: "{\"foo\": \"bar\"}"
|
|
25
|
+
* };
|
|
26
|
+
*
|
|
27
|
+
* const result = search(
|
|
28
|
+
* 'powertools_json(body)',
|
|
29
|
+
* data,
|
|
30
|
+
* { customFunctions: new PowertoolsFunctions() }
|
|
31
|
+
* );
|
|
32
|
+
* console.log(result); // { foo: 'bar' }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* When using the {@link extractDataFromEnvelope} function, the PowertoolsFunctions class is automatically used.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
class PowertoolsFunctions extends Functions {
|
|
39
|
+
funcPowertoolsBase64(value) {
|
|
40
|
+
return decoder.decode(fromBase64(value, 'base64'));
|
|
41
|
+
}
|
|
42
|
+
funcPowertoolsBase64Gzip(value) {
|
|
43
|
+
const encoded = fromBase64(value, 'base64');
|
|
44
|
+
const uncompressed = gunzipSync(encoded);
|
|
45
|
+
return uncompressed.toString();
|
|
46
|
+
}
|
|
47
|
+
funcPowertoolsJson(value) {
|
|
48
|
+
return JSON.parse(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
__decorate([
|
|
52
|
+
Functions.signature({
|
|
53
|
+
argumentsSpecs: [['string']],
|
|
54
|
+
})
|
|
55
|
+
], PowertoolsFunctions.prototype, "funcPowertoolsBase64", null);
|
|
56
|
+
__decorate([
|
|
57
|
+
Functions.signature({
|
|
58
|
+
argumentsSpecs: [['string']],
|
|
59
|
+
})
|
|
60
|
+
], PowertoolsFunctions.prototype, "funcPowertoolsBase64Gzip", null);
|
|
61
|
+
__decorate([
|
|
62
|
+
Functions.signature({
|
|
63
|
+
argumentsSpecs: [['string']],
|
|
64
|
+
})
|
|
65
|
+
], PowertoolsFunctions.prototype, "funcPowertoolsJson", null);
|
|
66
|
+
export { PowertoolsFunctions };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Node, JMESPathParsingOptions, JSONObject } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* A tree interpreter for JMESPath ASTs.
|
|
5
|
+
*
|
|
6
|
+
* The tree interpreter is responsible for visiting nodes in the AST and
|
|
7
|
+
* evaluating them to produce a result.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare class TreeInterpreter {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* @param options The options to use for the interpreter.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: JMESPathParsingOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Visit a node in the AST.
|
|
19
|
+
*
|
|
20
|
+
* The function will call the appropriate method to visit the node based on its type.
|
|
21
|
+
*
|
|
22
|
+
* @param node The node to visit.
|
|
23
|
+
* @param value The current value to visit.
|
|
24
|
+
*/
|
|
25
|
+
visit(node: Node, value: JSONObject): JSONObject | null;
|
|
26
|
+
}
|
|
27
|
+
export { TreeInterpreter };
|
|
28
|
+
//# sourceMappingURL=TreeInterpreter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeInterpreter.d.ts","sourceRoot":"","sources":["../../src/TreeInterpreter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,UAAU,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;CA4b/D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|