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