@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
package/lib/cjs/ast.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.valueProjection = exports.subexpression = exports.slice = exports.projection = exports.pipe = exports.orExpression = exports.notExpression = exports.multiSelectList = exports.multiSelectObject = exports.literal = exports.keyValPair = exports.indexExpression = exports.index = exports.identity = exports.functionExpression = exports.flatten = exports.filterProjection = exports.field = exports.expref = exports.currentNode = exports.comparator = exports.andExpression = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* AST node representing a comparator expression.
|
|
6
|
+
*
|
|
7
|
+
* A comparator expression is a binary expression that compares two values.
|
|
8
|
+
*
|
|
9
|
+
* @param name The name of the comparator
|
|
10
|
+
* @param first The left-hand side of the comparator
|
|
11
|
+
* @param second The right-hand side of the comparator
|
|
12
|
+
*/
|
|
13
|
+
const comparator = (name, first, second) => ({
|
|
14
|
+
type: 'comparator',
|
|
15
|
+
children: [first, second],
|
|
16
|
+
value: name,
|
|
17
|
+
});
|
|
18
|
+
exports.comparator = comparator;
|
|
19
|
+
/**
|
|
20
|
+
* AST node representing the current node.
|
|
21
|
+
*
|
|
22
|
+
* The current node is a reference to the current value being processed.
|
|
23
|
+
* In JMESPath, the current node is represented by the `@` symbol.
|
|
24
|
+
*/
|
|
25
|
+
const currentNode = () => ({
|
|
26
|
+
type: 'current',
|
|
27
|
+
children: [],
|
|
28
|
+
});
|
|
29
|
+
exports.currentNode = currentNode;
|
|
30
|
+
/**
|
|
31
|
+
* AST node representing an expression reference.
|
|
32
|
+
*
|
|
33
|
+
* An expression reference is a reference to another expression.
|
|
34
|
+
* In JMESPath, an expression reference is represented by the `&` symbol.
|
|
35
|
+
*
|
|
36
|
+
* @param expression The expression to reference
|
|
37
|
+
*/
|
|
38
|
+
const expref = (expression) => ({
|
|
39
|
+
type: 'expref',
|
|
40
|
+
children: [expression],
|
|
41
|
+
});
|
|
42
|
+
exports.expref = expref;
|
|
43
|
+
/**
|
|
44
|
+
* AST node representing a function expression.
|
|
45
|
+
*
|
|
46
|
+
* A function expression is a reference to a function and its arguments.
|
|
47
|
+
* The JMESPath specification defines a set of built-in functions that can
|
|
48
|
+
* be used in expressions like `length(@)`, `map(@, &foo)`, etc.
|
|
49
|
+
*
|
|
50
|
+
* Custom functions can be added by extending the `Functions` class.
|
|
51
|
+
*
|
|
52
|
+
* @param name The name of the function
|
|
53
|
+
* @param args The arguments to the function
|
|
54
|
+
*/
|
|
55
|
+
const functionExpression = (name, args) => ({
|
|
56
|
+
type: 'function_expression',
|
|
57
|
+
children: args,
|
|
58
|
+
value: name,
|
|
59
|
+
});
|
|
60
|
+
exports.functionExpression = functionExpression;
|
|
61
|
+
/**
|
|
62
|
+
* AST node representing a field reference.
|
|
63
|
+
*
|
|
64
|
+
* A field reference is a reference to a field in an object.
|
|
65
|
+
*/
|
|
66
|
+
const field = (name) => ({
|
|
67
|
+
type: 'field',
|
|
68
|
+
children: [],
|
|
69
|
+
value: name,
|
|
70
|
+
});
|
|
71
|
+
exports.field = field;
|
|
72
|
+
/**
|
|
73
|
+
* AST node representing a filter projection.
|
|
74
|
+
*
|
|
75
|
+
* A filter projection is a binary expression that filters the left-hand side
|
|
76
|
+
* based on the right-hand side.
|
|
77
|
+
*
|
|
78
|
+
* In JMESPath, a filter projection is represented by the `[]` operator.
|
|
79
|
+
* For example, `people[?age > 18]` filters the `people` array based on the
|
|
80
|
+
* `age` field.
|
|
81
|
+
*
|
|
82
|
+
* @param left The left-hand side of the filter projection
|
|
83
|
+
* @param right The right-hand side of the filter projection
|
|
84
|
+
* @param comparator The comparator to use for the filter
|
|
85
|
+
*/
|
|
86
|
+
const filterProjection = (left, right, comparator) => ({
|
|
87
|
+
type: 'filter_projection',
|
|
88
|
+
children: [left, right, comparator],
|
|
89
|
+
});
|
|
90
|
+
exports.filterProjection = filterProjection;
|
|
91
|
+
/**
|
|
92
|
+
* AST node representing a flatten expression.
|
|
93
|
+
*
|
|
94
|
+
* A flatten expression is a unary expression that flattens an array of arrays
|
|
95
|
+
* into a single array.
|
|
96
|
+
*
|
|
97
|
+
* In JMESPath, a flatten expression is represented by the `[]` operator.
|
|
98
|
+
* For example, `people[].name` flattens the `people` array and returns the
|
|
99
|
+
* `name` field of each object in the array.
|
|
100
|
+
*
|
|
101
|
+
* @param node The node to flatten
|
|
102
|
+
*/
|
|
103
|
+
const flatten = (node) => ({
|
|
104
|
+
type: 'flatten',
|
|
105
|
+
children: [node],
|
|
106
|
+
});
|
|
107
|
+
exports.flatten = flatten;
|
|
108
|
+
/**
|
|
109
|
+
* AST node representing an identity expression.
|
|
110
|
+
*/
|
|
111
|
+
const identity = () => ({ type: 'identity', children: [] });
|
|
112
|
+
exports.identity = identity;
|
|
113
|
+
/**
|
|
114
|
+
* AST node representing an index reference.
|
|
115
|
+
*
|
|
116
|
+
* An index reference is a reference to an index in an array.
|
|
117
|
+
* For example, `people[0]` references the first element in the `people` array.
|
|
118
|
+
*
|
|
119
|
+
* @param index The index to reference
|
|
120
|
+
*/
|
|
121
|
+
const index = (index) => ({
|
|
122
|
+
type: 'index',
|
|
123
|
+
value: index,
|
|
124
|
+
children: [],
|
|
125
|
+
});
|
|
126
|
+
exports.index = index;
|
|
127
|
+
/**
|
|
128
|
+
* AST node representing an index expression.
|
|
129
|
+
*
|
|
130
|
+
* An index expression holds the index and the children of the expression.
|
|
131
|
+
*
|
|
132
|
+
* @param children The children of the index expression
|
|
133
|
+
*/
|
|
134
|
+
const indexExpression = (children) => ({
|
|
135
|
+
type: 'index_expression',
|
|
136
|
+
children: children,
|
|
137
|
+
});
|
|
138
|
+
exports.indexExpression = indexExpression;
|
|
139
|
+
/**
|
|
140
|
+
* AST node representing a key-value pair.
|
|
141
|
+
*
|
|
142
|
+
* @param keyName The name of the key
|
|
143
|
+
* @param node The value of the key
|
|
144
|
+
*/
|
|
145
|
+
const keyValPair = (keyName, node) => ({
|
|
146
|
+
type: 'key_val_pair',
|
|
147
|
+
children: [node],
|
|
148
|
+
value: keyName,
|
|
149
|
+
});
|
|
150
|
+
exports.keyValPair = keyValPair;
|
|
151
|
+
/**
|
|
152
|
+
* AST node representing a literal value.
|
|
153
|
+
*
|
|
154
|
+
* A literal value is a value that is not a reference to another node.
|
|
155
|
+
*
|
|
156
|
+
* @param literalValue The value of the literal
|
|
157
|
+
*/
|
|
158
|
+
const literal = (literalValue) => ({
|
|
159
|
+
type: 'literal',
|
|
160
|
+
value: literalValue,
|
|
161
|
+
children: [],
|
|
162
|
+
});
|
|
163
|
+
exports.literal = literal;
|
|
164
|
+
/**
|
|
165
|
+
* AST node representing a multi-select object.
|
|
166
|
+
*
|
|
167
|
+
* A multi-select object is a reference to multiple nodes in an object.
|
|
168
|
+
*
|
|
169
|
+
* @param nodes
|
|
170
|
+
*/
|
|
171
|
+
const multiSelectObject = (nodes) => ({
|
|
172
|
+
type: 'multi_select_object',
|
|
173
|
+
children: nodes,
|
|
174
|
+
});
|
|
175
|
+
exports.multiSelectObject = multiSelectObject;
|
|
176
|
+
/**
|
|
177
|
+
* AST node representing a multi-select list.
|
|
178
|
+
*
|
|
179
|
+
* @param nodes
|
|
180
|
+
*/
|
|
181
|
+
const multiSelectList = (nodes) => ({
|
|
182
|
+
type: 'multi_select_list',
|
|
183
|
+
children: nodes,
|
|
184
|
+
});
|
|
185
|
+
exports.multiSelectList = multiSelectList;
|
|
186
|
+
/**
|
|
187
|
+
* AST node representing an or expression.
|
|
188
|
+
*
|
|
189
|
+
* @param left The left-hand side of the or expression
|
|
190
|
+
* @param right The right-hand side of the or expression
|
|
191
|
+
*/
|
|
192
|
+
const orExpression = (left, right) => ({
|
|
193
|
+
type: 'or_expression',
|
|
194
|
+
children: [left, right],
|
|
195
|
+
});
|
|
196
|
+
exports.orExpression = orExpression;
|
|
197
|
+
/**
|
|
198
|
+
* AST node representing an and expression.
|
|
199
|
+
*
|
|
200
|
+
* @param left The left-hand side of the and expression
|
|
201
|
+
* @param right The right-hand side of the and expression
|
|
202
|
+
*/
|
|
203
|
+
const andExpression = (left, right) => ({
|
|
204
|
+
type: 'and_expression',
|
|
205
|
+
children: [left, right],
|
|
206
|
+
});
|
|
207
|
+
exports.andExpression = andExpression;
|
|
208
|
+
/**
|
|
209
|
+
* AST node representing a not expression.
|
|
210
|
+
*
|
|
211
|
+
* @param left The left-hand side of the not expression
|
|
212
|
+
* @param right The right-hand side of the not expression
|
|
213
|
+
*/
|
|
214
|
+
const notExpression = (expr) => ({
|
|
215
|
+
type: 'not_expression',
|
|
216
|
+
children: [expr],
|
|
217
|
+
});
|
|
218
|
+
exports.notExpression = notExpression;
|
|
219
|
+
/**
|
|
220
|
+
* AST node representing a pipe expression.
|
|
221
|
+
*
|
|
222
|
+
* @param left The left-hand side of the pipe expression
|
|
223
|
+
* @param right The right-hand side of the pipe expression
|
|
224
|
+
*/
|
|
225
|
+
const pipe = (left, right) => ({
|
|
226
|
+
type: 'pipe',
|
|
227
|
+
children: [left, right],
|
|
228
|
+
});
|
|
229
|
+
exports.pipe = pipe;
|
|
230
|
+
/**
|
|
231
|
+
* AST node representing a projection.
|
|
232
|
+
*
|
|
233
|
+
* @param left The left-hand side of the projection
|
|
234
|
+
* @param right The right-hand side of the projection
|
|
235
|
+
*/
|
|
236
|
+
const projection = (left, right) => ({
|
|
237
|
+
type: 'projection',
|
|
238
|
+
children: [left, right],
|
|
239
|
+
});
|
|
240
|
+
exports.projection = projection;
|
|
241
|
+
/**
|
|
242
|
+
* AST node representing a subexpression.
|
|
243
|
+
*
|
|
244
|
+
* @param children The children of the subexpression
|
|
245
|
+
*/
|
|
246
|
+
const subexpression = (children) => ({
|
|
247
|
+
type: 'subexpression',
|
|
248
|
+
children: children,
|
|
249
|
+
});
|
|
250
|
+
exports.subexpression = subexpression;
|
|
251
|
+
/**
|
|
252
|
+
* AST node representing a slice.
|
|
253
|
+
*
|
|
254
|
+
* A slice is a reference to a range of values in an array.
|
|
255
|
+
*
|
|
256
|
+
* @param start The start of the slice
|
|
257
|
+
* @param end The end of the slice
|
|
258
|
+
* @param step The step of the slice
|
|
259
|
+
*/
|
|
260
|
+
const slice = (start, end, step) => ({
|
|
261
|
+
type: 'slice',
|
|
262
|
+
children: [start, end, step],
|
|
263
|
+
});
|
|
264
|
+
exports.slice = slice;
|
|
265
|
+
/**
|
|
266
|
+
* AST node representing a value projection.
|
|
267
|
+
*
|
|
268
|
+
* @param left The left-hand side of the value projection
|
|
269
|
+
* @param right The right-hand side of the value projection
|
|
270
|
+
*/
|
|
271
|
+
const valueProjection = (left, right) => ({
|
|
272
|
+
type: 'value_projection',
|
|
273
|
+
children: [left, right],
|
|
274
|
+
});
|
|
275
|
+
exports.valueProjection = valueProjection;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The binding powers for the various tokens in the JMESPath grammar.
|
|
3
|
+
*
|
|
4
|
+
* The binding powers are used to determine the order of operations for
|
|
5
|
+
* the parser. The higher the binding power, the more tightly the token
|
|
6
|
+
* binds to its arguments.
|
|
7
|
+
*/
|
|
8
|
+
declare const BINDING_POWER: {
|
|
9
|
+
readonly eof: 0;
|
|
10
|
+
readonly unquoted_identifier: 0;
|
|
11
|
+
readonly quoted_identifier: 0;
|
|
12
|
+
readonly literal: 0;
|
|
13
|
+
readonly rbracket: 0;
|
|
14
|
+
readonly rparen: 0;
|
|
15
|
+
readonly comma: 0;
|
|
16
|
+
readonly rbrace: 0;
|
|
17
|
+
readonly number: 0;
|
|
18
|
+
readonly current: 0;
|
|
19
|
+
readonly expref: 0;
|
|
20
|
+
readonly colon: 0;
|
|
21
|
+
readonly pipe: 1;
|
|
22
|
+
readonly or: 2;
|
|
23
|
+
readonly and: 3;
|
|
24
|
+
readonly eq: 5;
|
|
25
|
+
readonly gt: 5;
|
|
26
|
+
readonly lt: 5;
|
|
27
|
+
readonly gte: 5;
|
|
28
|
+
readonly lte: 5;
|
|
29
|
+
readonly ne: 5;
|
|
30
|
+
readonly flatten: 9;
|
|
31
|
+
readonly star: 20;
|
|
32
|
+
readonly filter: 21;
|
|
33
|
+
readonly dot: 40;
|
|
34
|
+
readonly not: 45;
|
|
35
|
+
readonly lbrace: 50;
|
|
36
|
+
readonly lbracket: 55;
|
|
37
|
+
readonly lparen: 60;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
|
|
41
|
+
*/
|
|
42
|
+
declare const START_IDENTIFIER: Set<string>;
|
|
43
|
+
/**
|
|
44
|
+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
|
|
45
|
+
*/
|
|
46
|
+
declare const VALID_IDENTIFIER: Set<string>;
|
|
47
|
+
/**
|
|
48
|
+
* The set of ASCII digits allowed in JMESPath identifiers.
|
|
49
|
+
*/
|
|
50
|
+
declare const VALID_NUMBER: Set<string>;
|
|
51
|
+
/**
|
|
52
|
+
* The set of ASCII whitespace characters allowed in JMESPath identifiers.
|
|
53
|
+
*/
|
|
54
|
+
declare const WHITESPACE: Set<string>;
|
|
55
|
+
/**
|
|
56
|
+
* The set of simple tokens in the JMESPath grammar.
|
|
57
|
+
*/
|
|
58
|
+
declare const SIMPLE_TOKENS: Map<string, keyof typeof BINDING_POWER>;
|
|
59
|
+
export { BINDING_POWER, SIMPLE_TOKENS, START_IDENTIFIER, VALID_IDENTIFIER, VALID_NUMBER, WHITESPACE, };
|
|
60
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BT,CAAC;AAkBX;;GAEG;AACH,QAAA,MAAM,gBAAgB,aAA+B,CAAC;AACtD;;GAEG;AACH,QAAA,MAAM,gBAAgB,aAAwC,CAAC;AAC/D;;GAEG;AACH,QAAA,MAAM,YAAY,aAAkB,CAAC;AACrC;;GAEG;AACH,QAAA,MAAM,UAAU,aAAqB,CAAC;AACtC;;GAEG;AACH,QAAA,MAAM,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,OAAO,aAAa,CAYzD,CAAC;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,UAAU,GACX,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WHITESPACE = exports.VALID_NUMBER = exports.VALID_IDENTIFIER = exports.START_IDENTIFIER = exports.SIMPLE_TOKENS = exports.BINDING_POWER = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The binding powers for the various tokens in the JMESPath grammar.
|
|
6
|
+
*
|
|
7
|
+
* The binding powers are used to determine the order of operations for
|
|
8
|
+
* the parser. The higher the binding power, the more tightly the token
|
|
9
|
+
* binds to its arguments.
|
|
10
|
+
*/
|
|
11
|
+
const BINDING_POWER = {
|
|
12
|
+
eof: 0,
|
|
13
|
+
unquoted_identifier: 0,
|
|
14
|
+
quoted_identifier: 0,
|
|
15
|
+
literal: 0,
|
|
16
|
+
rbracket: 0,
|
|
17
|
+
rparen: 0,
|
|
18
|
+
comma: 0,
|
|
19
|
+
rbrace: 0,
|
|
20
|
+
number: 0,
|
|
21
|
+
current: 0,
|
|
22
|
+
expref: 0,
|
|
23
|
+
colon: 0,
|
|
24
|
+
pipe: 1,
|
|
25
|
+
or: 2,
|
|
26
|
+
and: 3,
|
|
27
|
+
eq: 5,
|
|
28
|
+
gt: 5,
|
|
29
|
+
lt: 5,
|
|
30
|
+
gte: 5,
|
|
31
|
+
lte: 5,
|
|
32
|
+
ne: 5,
|
|
33
|
+
flatten: 9,
|
|
34
|
+
// Everything above stops a projection.
|
|
35
|
+
star: 20,
|
|
36
|
+
filter: 21,
|
|
37
|
+
dot: 40,
|
|
38
|
+
not: 45,
|
|
39
|
+
lbrace: 50,
|
|
40
|
+
lbracket: 55,
|
|
41
|
+
lparen: 60,
|
|
42
|
+
};
|
|
43
|
+
exports.BINDING_POWER = BINDING_POWER;
|
|
44
|
+
/**
|
|
45
|
+
* The set of ASCII lowercase letters allowed in JMESPath identifiers.
|
|
46
|
+
*/
|
|
47
|
+
const ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
|
|
48
|
+
/**
|
|
49
|
+
* The set of ASCII uppercase letters allowed in JMESPath identifiers.
|
|
50
|
+
*/
|
|
51
|
+
const ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
52
|
+
/**
|
|
53
|
+
* The set of ASCII letters allowed in JMESPath identifiers.
|
|
54
|
+
*/
|
|
55
|
+
const ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE;
|
|
56
|
+
/**
|
|
57
|
+
* The set of ASCII digits allowed in JMESPath identifiers.
|
|
58
|
+
*/
|
|
59
|
+
const DIGITS = '0123456789';
|
|
60
|
+
/**
|
|
61
|
+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
|
|
62
|
+
*/
|
|
63
|
+
const START_IDENTIFIER = new Set(ASCII_LETTERS + '_');
|
|
64
|
+
exports.START_IDENTIFIER = START_IDENTIFIER;
|
|
65
|
+
/**
|
|
66
|
+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
|
|
67
|
+
*/
|
|
68
|
+
const VALID_IDENTIFIER = new Set(ASCII_LETTERS + DIGITS + '_');
|
|
69
|
+
exports.VALID_IDENTIFIER = VALID_IDENTIFIER;
|
|
70
|
+
/**
|
|
71
|
+
* The set of ASCII digits allowed in JMESPath identifiers.
|
|
72
|
+
*/
|
|
73
|
+
const VALID_NUMBER = new Set(DIGITS);
|
|
74
|
+
exports.VALID_NUMBER = VALID_NUMBER;
|
|
75
|
+
/**
|
|
76
|
+
* The set of ASCII whitespace characters allowed in JMESPath identifiers.
|
|
77
|
+
*/
|
|
78
|
+
const WHITESPACE = new Set(' \t\n\r');
|
|
79
|
+
exports.WHITESPACE = WHITESPACE;
|
|
80
|
+
/**
|
|
81
|
+
* The set of simple tokens in the JMESPath grammar.
|
|
82
|
+
*/
|
|
83
|
+
const SIMPLE_TOKENS = new Map([
|
|
84
|
+
['.', 'dot'],
|
|
85
|
+
['*', 'star'],
|
|
86
|
+
[':', 'colon'],
|
|
87
|
+
[']', 'rbracket'],
|
|
88
|
+
[',', 'comma'],
|
|
89
|
+
[':', 'colon'],
|
|
90
|
+
['@', 'current'],
|
|
91
|
+
['(', 'lparen'],
|
|
92
|
+
[')', 'rparen'],
|
|
93
|
+
['{', 'lbrace'],
|
|
94
|
+
['}', 'rbrace'],
|
|
95
|
+
]);
|
|
96
|
+
exports.SIMPLE_TOKENS = SIMPLE_TOKENS;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { JMESPathParsingOptions, JSONObject } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Searches and extracts data using JMESPath
|
|
4
|
+
*
|
|
5
|
+
* Envelope being the JMESPath expression to extract the data you're after
|
|
6
|
+
*
|
|
7
|
+
* Built-in JMESPath functions include: `powertools_json`, `powertools_base64`, `powertools_base64_gzip`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';
|
|
12
|
+
*
|
|
13
|
+
* type CustomEvent = {
|
|
14
|
+
* body: string; // "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}"
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* type EventBody = {
|
|
18
|
+
* customerId: string;
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* export const handler = async (event: CustomEvent): Promise<unknown> => {
|
|
22
|
+
* const payload = extractDataFromEnvelope<EventBody>(event, "powertools_json(body)");
|
|
23
|
+
* const { customerId } = payload; // now deserialized
|
|
24
|
+
* // ...
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* We provide built-in envelopes for popular AWS Lambda event sources to easily decode and/or deserialize JSON objects.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import {
|
|
33
|
+
* extractDataFromEnvelope,
|
|
34
|
+
* SQS,
|
|
35
|
+
* } from '@aws-lambda-powertools/jmespath/envelopes';
|
|
36
|
+
* import type { SQSEvent } from 'aws-lambda';
|
|
37
|
+
*
|
|
38
|
+
* type MessageBody = {
|
|
39
|
+
* customerId: string;
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* export const handler = async (event: SQSEvent): Promise<unknown> => {
|
|
43
|
+
* const records = extractDataFromEnvelope<Array<MessageBody>>(event, SQS);
|
|
44
|
+
* for (const record in records) { // records is now a list containing the deserialized body of each message
|
|
45
|
+
* const { customerId } = record;
|
|
46
|
+
* }
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param data The JSON object to search
|
|
51
|
+
* @param envelope The JMESPath expression to use
|
|
52
|
+
* @param options The parsing options to use
|
|
53
|
+
*/
|
|
54
|
+
declare const extractDataFromEnvelope: <T>(data: JSONObject, envelope: string, options?: JMESPathParsingOptions) => T;
|
|
55
|
+
declare const API_GATEWAY_REST = "powertools_json(body)";
|
|
56
|
+
declare const API_GATEWAY_HTTP = "powertools_json(body)";
|
|
57
|
+
declare const SQS = "Records[*].powertools_json(body)";
|
|
58
|
+
declare const SNS = "Records[0].Sns.Message | powertools_json(@)";
|
|
59
|
+
declare const EVENTBRIDGE = "detail";
|
|
60
|
+
declare const CLOUDWATCH_EVENTS_SCHEDULED = "detail";
|
|
61
|
+
declare const KINESIS_DATA_STREAM = "Records[*].kinesis.powertools_json(powertools_base64(data))";
|
|
62
|
+
declare const CLOUDWATCH_LOGS = "awslogs.powertools_base64_gzip(data) | powertools_json(@).logEvents[*]";
|
|
63
|
+
declare const S3_SNS_SQS = "Records[*].powertools_json(body).powertools_json(Message).Records[0]";
|
|
64
|
+
declare const S3_SQS = "Records[*].powertools_json(body).Records[0]";
|
|
65
|
+
declare const S3_SNS_KINESIS_FIREHOSE = "records[*].powertools_json(powertools_base64(data)).powertools_json(Message).Records[0]";
|
|
66
|
+
declare const S3_KINESIS_FIREHOSE = "records[*].powertools_json(powertools_base64(data)).Records[0]";
|
|
67
|
+
declare const S3_EVENTBRIDGE_SQS = "Records[*].powertools_json(body).detail";
|
|
68
|
+
export { extractDataFromEnvelope, API_GATEWAY_REST, API_GATEWAY_HTTP, SQS, SNS, EVENTBRIDGE, CLOUDWATCH_EVENTS_SCHEDULED, KINESIS_DATA_STREAM, CLOUDWATCH_LOGS, S3_SNS_SQS, S3_SQS, S3_SNS_KINESIS_FIREHOSE, S3_KINESIS_FIREHOSE, S3_EVENTBRIDGE_SQS, };
|
|
69
|
+
//# sourceMappingURL=envelopes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelopes.d.ts","sourceRoot":"","sources":["../../src/envelopes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,QAAA,MAAM,uBAAuB,YACrB,UAAU,YACN,MAAM,YACN,sBAAsB,KAC/B,CAMF,CAAC;AAEF,QAAA,MAAM,gBAAgB,0BAA0B,CAAC;AACjD,QAAA,MAAM,gBAAgB,0BAA0B,CAAC;AACjD,QAAA,MAAM,GAAG,qCAAqC,CAAC;AAC/C,QAAA,MAAM,GAAG,gDAAgD,CAAC;AAC1D,QAAA,MAAM,WAAW,WAAW,CAAC;AAC7B,QAAA,MAAM,2BAA2B,WAAW,CAAC;AAC7C,QAAA,MAAM,mBAAmB,gEACsC,CAAC;AAChE,QAAA,MAAM,eAAe,2EACqD,CAAC;AAC3E,QAAA,MAAM,UAAU,yEACwD,CAAC;AACzE,QAAA,MAAM,MAAM,gDAAgD,CAAC;AAC7D,QAAA,MAAM,uBAAuB,4FAC8D,CAAC;AAC5F,QAAA,MAAM,mBAAmB,mEACyC,CAAC;AACnE,QAAA,MAAM,kBAAkB,4CAA4C,CAAC;AAErE,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,GAAG,EACH,GAAG,EACH,WAAW,EACX,2BAA2B,EAC3B,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,MAAM,EACN,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,GACnB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.S3_EVENTBRIDGE_SQS = exports.S3_KINESIS_FIREHOSE = exports.S3_SNS_KINESIS_FIREHOSE = exports.S3_SQS = exports.S3_SNS_SQS = exports.CLOUDWATCH_LOGS = exports.KINESIS_DATA_STREAM = exports.CLOUDWATCH_EVENTS_SCHEDULED = exports.EVENTBRIDGE = exports.SNS = exports.SQS = exports.API_GATEWAY_HTTP = exports.API_GATEWAY_REST = exports.extractDataFromEnvelope = void 0;
|
|
4
|
+
const search_js_1 = require("./search.js");
|
|
5
|
+
const PowertoolsFunctions_js_1 = require("./PowertoolsFunctions.js");
|
|
6
|
+
/**
|
|
7
|
+
* Searches and extracts data using JMESPath
|
|
8
|
+
*
|
|
9
|
+
* Envelope being the JMESPath expression to extract the data you're after
|
|
10
|
+
*
|
|
11
|
+
* Built-in JMESPath functions include: `powertools_json`, `powertools_base64`, `powertools_base64_gzip`
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';
|
|
16
|
+
*
|
|
17
|
+
* type CustomEvent = {
|
|
18
|
+
* body: string; // "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}"
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* type EventBody = {
|
|
22
|
+
* customerId: string;
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* export const handler = async (event: CustomEvent): Promise<unknown> => {
|
|
26
|
+
* const payload = extractDataFromEnvelope<EventBody>(event, "powertools_json(body)");
|
|
27
|
+
* const { customerId } = payload; // now deserialized
|
|
28
|
+
* // ...
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* We provide built-in envelopes for popular AWS Lambda event sources to easily decode and/or deserialize JSON objects.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import {
|
|
37
|
+
* extractDataFromEnvelope,
|
|
38
|
+
* SQS,
|
|
39
|
+
* } from '@aws-lambda-powertools/jmespath/envelopes';
|
|
40
|
+
* import type { SQSEvent } from 'aws-lambda';
|
|
41
|
+
*
|
|
42
|
+
* type MessageBody = {
|
|
43
|
+
* customerId: string;
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* export const handler = async (event: SQSEvent): Promise<unknown> => {
|
|
47
|
+
* const records = extractDataFromEnvelope<Array<MessageBody>>(event, SQS);
|
|
48
|
+
* for (const record in records) { // records is now a list containing the deserialized body of each message
|
|
49
|
+
* const { customerId } = record;
|
|
50
|
+
* }
|
|
51
|
+
* };
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param data The JSON object to search
|
|
55
|
+
* @param envelope The JMESPath expression to use
|
|
56
|
+
* @param options The parsing options to use
|
|
57
|
+
*/
|
|
58
|
+
const extractDataFromEnvelope = (data, envelope, options) => {
|
|
59
|
+
if (!options) {
|
|
60
|
+
options = { customFunctions: new PowertoolsFunctions_js_1.PowertoolsFunctions() };
|
|
61
|
+
}
|
|
62
|
+
return (0, search_js_1.search)(envelope, data, options);
|
|
63
|
+
};
|
|
64
|
+
exports.extractDataFromEnvelope = extractDataFromEnvelope;
|
|
65
|
+
const API_GATEWAY_REST = 'powertools_json(body)';
|
|
66
|
+
exports.API_GATEWAY_REST = API_GATEWAY_REST;
|
|
67
|
+
const API_GATEWAY_HTTP = 'powertools_json(body)';
|
|
68
|
+
exports.API_GATEWAY_HTTP = API_GATEWAY_HTTP;
|
|
69
|
+
const SQS = 'Records[*].powertools_json(body)';
|
|
70
|
+
exports.SQS = SQS;
|
|
71
|
+
const SNS = 'Records[0].Sns.Message | powertools_json(@)';
|
|
72
|
+
exports.SNS = SNS;
|
|
73
|
+
const EVENTBRIDGE = 'detail';
|
|
74
|
+
exports.EVENTBRIDGE = EVENTBRIDGE;
|
|
75
|
+
const CLOUDWATCH_EVENTS_SCHEDULED = 'detail';
|
|
76
|
+
exports.CLOUDWATCH_EVENTS_SCHEDULED = CLOUDWATCH_EVENTS_SCHEDULED;
|
|
77
|
+
const KINESIS_DATA_STREAM = 'Records[*].kinesis.powertools_json(powertools_base64(data))';
|
|
78
|
+
exports.KINESIS_DATA_STREAM = KINESIS_DATA_STREAM;
|
|
79
|
+
const CLOUDWATCH_LOGS = 'awslogs.powertools_base64_gzip(data) | powertools_json(@).logEvents[*]';
|
|
80
|
+
exports.CLOUDWATCH_LOGS = CLOUDWATCH_LOGS;
|
|
81
|
+
const S3_SNS_SQS = 'Records[*].powertools_json(body).powertools_json(Message).Records[0]';
|
|
82
|
+
exports.S3_SNS_SQS = S3_SNS_SQS;
|
|
83
|
+
const S3_SQS = 'Records[*].powertools_json(body).Records[0]';
|
|
84
|
+
exports.S3_SQS = S3_SQS;
|
|
85
|
+
const S3_SNS_KINESIS_FIREHOSE = 'records[*].powertools_json(powertools_base64(data)).powertools_json(Message).Records[0]';
|
|
86
|
+
exports.S3_SNS_KINESIS_FIREHOSE = S3_SNS_KINESIS_FIREHOSE;
|
|
87
|
+
const S3_KINESIS_FIREHOSE = 'records[*].powertools_json(powertools_base64(data)).Records[0]';
|
|
88
|
+
exports.S3_KINESIS_FIREHOSE = S3_KINESIS_FIREHOSE;
|
|
89
|
+
const S3_EVENTBRIDGE_SQS = 'Records[*].powertools_json(body).detail';
|
|
90
|
+
exports.S3_EVENTBRIDGE_SQS = S3_EVENTBRIDGE_SQS;
|