@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.
Files changed (97) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +214 -5
  3. package/lib/cjs/Expression.d.ts +19 -0
  4. package/lib/cjs/Expression.d.ts.map +1 -0
  5. package/lib/cjs/Expression.js +38 -0
  6. package/lib/cjs/Functions.d.ts +242 -0
  7. package/lib/cjs/Functions.d.ts.map +1 -0
  8. package/lib/cjs/Functions.js +597 -0
  9. package/lib/cjs/Lexer.d.ts +19 -0
  10. package/lib/cjs/Lexer.d.ts.map +1 -0
  11. package/lib/cjs/Lexer.js +271 -0
  12. package/lib/cjs/ParsedResult.d.ts +15 -0
  13. package/lib/cjs/ParsedResult.d.ts.map +1 -0
  14. package/lib/cjs/ParsedResult.js +33 -0
  15. package/lib/cjs/Parser.d.ts +35 -0
  16. package/lib/cjs/Parser.d.ts.map +1 -0
  17. package/lib/cjs/Parser.js +506 -0
  18. package/lib/cjs/PowertoolsFunctions.d.ts +36 -0
  19. package/lib/cjs/PowertoolsFunctions.d.ts.map +1 -0
  20. package/lib/cjs/PowertoolsFunctions.js +69 -0
  21. package/lib/cjs/TreeInterpreter.d.ts +28 -0
  22. package/lib/cjs/TreeInterpreter.d.ts.map +1 -0
  23. package/lib/cjs/TreeInterpreter.js +313 -0
  24. package/lib/cjs/ast.d.ts +185 -0
  25. package/lib/cjs/ast.d.ts.map +1 -0
  26. package/lib/cjs/ast.js +275 -0
  27. package/lib/cjs/constants.d.ts +60 -0
  28. package/lib/cjs/constants.d.ts.map +1 -0
  29. package/lib/cjs/constants.js +96 -0
  30. package/lib/cjs/envelopes.d.ts +69 -0
  31. package/lib/cjs/envelopes.d.ts.map +1 -0
  32. package/lib/cjs/envelopes.js +90 -0
  33. package/lib/cjs/errors.d.ts +183 -0
  34. package/lib/cjs/errors.d.ts.map +1 -0
  35. package/lib/cjs/errors.js +206 -0
  36. package/lib/cjs/index.d.ts +3 -0
  37. package/lib/cjs/index.d.ts.map +1 -0
  38. package/lib/cjs/index.js +15 -0
  39. package/lib/cjs/package.json +1 -0
  40. package/lib/cjs/search.d.ts +50 -0
  41. package/lib/cjs/search.d.ts.map +1 -0
  42. package/lib/cjs/search.js +55 -0
  43. package/lib/cjs/types.d.ts +88 -0
  44. package/lib/cjs/types.d.ts.map +1 -0
  45. package/lib/cjs/types.js +2 -0
  46. package/lib/cjs/utils.d.ts +87 -0
  47. package/lib/cjs/utils.d.ts.map +1 -0
  48. package/lib/cjs/utils.js +282 -0
  49. package/lib/esm/Expression.d.ts +19 -0
  50. package/lib/esm/Expression.d.ts.map +1 -0
  51. package/lib/esm/Expression.js +35 -0
  52. package/lib/esm/Functions.d.ts +242 -0
  53. package/lib/esm/Functions.d.ts.map +1 -0
  54. package/lib/esm/Functions.js +594 -0
  55. package/lib/esm/Lexer.d.ts +19 -0
  56. package/lib/esm/Lexer.d.ts.map +1 -0
  57. package/lib/esm/Lexer.js +268 -0
  58. package/lib/esm/ParsedResult.d.ts +15 -0
  59. package/lib/esm/ParsedResult.d.ts.map +1 -0
  60. package/lib/esm/ParsedResult.js +30 -0
  61. package/lib/esm/Parser.d.ts +35 -0
  62. package/lib/esm/Parser.d.ts.map +1 -0
  63. package/lib/esm/Parser.js +503 -0
  64. package/lib/esm/PowertoolsFunctions.d.ts +36 -0
  65. package/lib/esm/PowertoolsFunctions.d.ts.map +1 -0
  66. package/lib/esm/PowertoolsFunctions.js +66 -0
  67. package/lib/esm/TreeInterpreter.d.ts +28 -0
  68. package/lib/esm/TreeInterpreter.d.ts.map +1 -0
  69. package/lib/esm/TreeInterpreter.js +310 -0
  70. package/lib/esm/ast.d.ts +185 -0
  71. package/lib/esm/ast.d.ts.map +1 -0
  72. package/lib/esm/ast.js +251 -0
  73. package/lib/esm/constants.d.ts +60 -0
  74. package/lib/esm/constants.d.ts.map +1 -0
  75. package/lib/esm/constants.js +88 -0
  76. package/lib/esm/envelopes.d.ts +69 -0
  77. package/lib/esm/envelopes.d.ts.map +1 -0
  78. package/lib/esm/envelopes.js +74 -0
  79. package/lib/esm/errors.d.ts +183 -0
  80. package/lib/esm/errors.d.ts.map +1 -0
  81. package/lib/esm/errors.js +195 -0
  82. package/lib/esm/index.d.ts +3 -0
  83. package/lib/esm/index.d.ts.map +1 -0
  84. package/lib/esm/index.js +2 -0
  85. package/lib/esm/package.json +1 -0
  86. package/lib/esm/search.d.ts +50 -0
  87. package/lib/esm/search.d.ts.map +1 -0
  88. package/lib/esm/search.js +52 -0
  89. package/lib/esm/types.d.ts +88 -0
  90. package/lib/esm/types.d.ts.map +1 -0
  91. package/lib/esm/types.js +1 -0
  92. package/lib/esm/utils.d.ts +87 -0
  93. package/lib/esm/utils.d.ts.map +1 -0
  94. package/lib/esm/utils.js +275 -0
  95. package/package.json +51 -12
  96. package/lib/index.d.ts +0 -0
  97. package/lib/index.js +0 -4
@@ -0,0 +1,313 @@
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 _TreeInterpreter_instances, _TreeInterpreter_functions, _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe, _TreeInterpreter_visitField, _TreeInterpreter_visitComparator, _TreeInterpreter_visitCurrent, _TreeInterpreter_visitExpref, _TreeInterpreter_visitFunctionExpression, _TreeInterpreter_visitFilterProjection, _TreeInterpreter_visitFlatten, _TreeInterpreter_visitIdentity, _TreeInterpreter_visitIndex, _TreeInterpreter_visitSlice, _TreeInterpreter_visitKeyValPair, _TreeInterpreter_visitLiteral, _TreeInterpreter_visitMultiSelectObject, _TreeInterpreter_visitMultiSelectList, _TreeInterpreter_visitOrExpression, _TreeInterpreter_visitAndExpression, _TreeInterpreter_visitNotExpression, _TreeInterpreter_visitProjection, _TreeInterpreter_visitValueProjection;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TreeInterpreter = void 0;
16
+ const typeutils_1 = require("@aws-lambda-powertools/commons/typeutils");
17
+ const errors_js_1 = require("./errors.js");
18
+ const Expression_js_1 = require("./Expression.js");
19
+ const Functions_js_1 = require("./Functions.js");
20
+ const utils_js_1 = require("./utils.js");
21
+ /**
22
+ *
23
+ * A tree interpreter for JMESPath ASTs.
24
+ *
25
+ * The tree interpreter is responsible for visiting nodes in the AST and
26
+ * evaluating them to produce a result.
27
+ *
28
+ * @internal
29
+ */
30
+ class TreeInterpreter {
31
+ /**
32
+ * @param options The options to use for the interpreter.
33
+ */
34
+ constructor(options) {
35
+ _TreeInterpreter_instances.add(this);
36
+ _TreeInterpreter_functions.set(this, void 0);
37
+ if (options?.customFunctions) {
38
+ __classPrivateFieldSet(this, _TreeInterpreter_functions, options.customFunctions, "f");
39
+ }
40
+ else {
41
+ __classPrivateFieldSet(this, _TreeInterpreter_functions, new Functions_js_1.Functions(), "f");
42
+ }
43
+ __classPrivateFieldGet(this, _TreeInterpreter_functions, "f").introspectMethods();
44
+ }
45
+ /**
46
+ * Visit a node in the AST.
47
+ *
48
+ * The function will call the appropriate method to visit the node based on its type.
49
+ *
50
+ * @param node The node to visit.
51
+ * @param value The current value to visit.
52
+ */
53
+ visit(node, value) {
54
+ const nodeType = node.type;
55
+ const visitMethods = {
56
+ subexpression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe),
57
+ field: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitField),
58
+ comparator: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitComparator),
59
+ current: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitCurrent),
60
+ expref: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitExpref),
61
+ function_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitFunctionExpression),
62
+ filter_projection: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitFilterProjection),
63
+ flatten: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitFlatten),
64
+ identity: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitIdentity),
65
+ index: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitIndex),
66
+ index_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe),
67
+ slice: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSlice),
68
+ key_val_pair: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitKeyValPair),
69
+ literal: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitLiteral),
70
+ multi_select_object: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitMultiSelectObject),
71
+ multi_select_list: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitMultiSelectList),
72
+ or_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitOrExpression),
73
+ and_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitAndExpression),
74
+ not_expression: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitNotExpression),
75
+ pipe: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe),
76
+ projection: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitProjection),
77
+ value_projection: __classPrivateFieldGet(this, _TreeInterpreter_instances, "m", _TreeInterpreter_visitValueProjection),
78
+ };
79
+ const visitMethod = visitMethods[nodeType];
80
+ if (visitMethod) {
81
+ return visitMethod.call(this, node, value);
82
+ }
83
+ else {
84
+ throw new errors_js_1.JMESPathError(`Not Implemented: Invalid node type: ${node.type}`);
85
+ }
86
+ }
87
+ }
88
+ exports.TreeInterpreter = TreeInterpreter;
89
+ _TreeInterpreter_functions = new WeakMap(), _TreeInterpreter_instances = new WeakSet(), _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe = function _TreeInterpreter_visitSubexpressionOrIndexExpressionOrPipe(node, value) {
90
+ let result = value;
91
+ for (const child of node.children) {
92
+ result = this.visit(child, result);
93
+ }
94
+ return result;
95
+ }, _TreeInterpreter_visitField = function _TreeInterpreter_visitField(node, value) {
96
+ if (!node.value)
97
+ return null;
98
+ if ((0, typeutils_1.isRecord)(value) &&
99
+ typeof node.value === 'string' &&
100
+ node.value in value) {
101
+ return value[node.value];
102
+ }
103
+ else {
104
+ return null;
105
+ }
106
+ }, _TreeInterpreter_visitComparator = function _TreeInterpreter_visitComparator(node, value) {
107
+ const comparator = node.value;
108
+ const left = this.visit(node.children[0], value);
109
+ const right = this.visit(node.children[1], value);
110
+ if (typeof comparator === 'string' &&
111
+ ['eq', 'ne', 'gt', 'gte', 'lt', 'lte'].includes(comparator)) {
112
+ // Common cases: comparator is == or !=
113
+ if (comparator === 'eq') {
114
+ return (0, typeutils_1.isStrictEqual)(left, right);
115
+ }
116
+ else if (comparator === 'ne') {
117
+ return !(0, typeutils_1.isStrictEqual)(left, right);
118
+ }
119
+ else if (typeof left === 'number' && typeof right === 'number') {
120
+ // Ordering operators only work on numbers. Evaluating them on other
121
+ // types will return null.
122
+ if (comparator === 'lt') {
123
+ return left < right;
124
+ }
125
+ else if (comparator === 'lte') {
126
+ return left <= right;
127
+ }
128
+ else if (comparator === 'gt') {
129
+ return left > right;
130
+ }
131
+ else {
132
+ return left >= right;
133
+ }
134
+ }
135
+ }
136
+ else {
137
+ throw new errors_js_1.JMESPathError(`Invalid comparator: ${comparator}`);
138
+ }
139
+ }, _TreeInterpreter_visitCurrent = function _TreeInterpreter_visitCurrent(_node, value) {
140
+ return value;
141
+ }, _TreeInterpreter_visitExpref = function _TreeInterpreter_visitExpref(node, _value) {
142
+ return new Expression_js_1.Expression(node.children[0], this);
143
+ }, _TreeInterpreter_visitFunctionExpression = function _TreeInterpreter_visitFunctionExpression(node, value) {
144
+ const args = [];
145
+ for (const child of node.children) {
146
+ args.push(this.visit(child, value));
147
+ }
148
+ // check that method name is a string
149
+ if (typeof node.value !== 'string') {
150
+ throw new errors_js_1.JMESPathError(`Function name must be a string, got ${node.value}`);
151
+ }
152
+ // convert snake_case to camelCase
153
+ const normalizedFunctionName = node.value.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
154
+ // capitalize first letter & add `func` prefix
155
+ const funcName = `func${normalizedFunctionName.charAt(0).toUpperCase() +
156
+ normalizedFunctionName.slice(1)}`;
157
+ if (!__classPrivateFieldGet(this, _TreeInterpreter_functions, "f").methods.has(funcName)) {
158
+ throw new errors_js_1.UnknownFunctionError(node.value);
159
+ }
160
+ try {
161
+ // We know that methodName is a key of this.#functions, but TypeScript
162
+ // doesn't know that, so we have to use @ts-ignore to tell it that it's
163
+ // okay. We could use a type assertion like `as keyof Functions`, but
164
+ // we also want to keep the args generic, so for now we'll just ignore it.
165
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
166
+ // @ts-ignore-next-line
167
+ return __classPrivateFieldGet(this, _TreeInterpreter_functions, "f")[funcName](args);
168
+ }
169
+ catch (error) {
170
+ if (error instanceof errors_js_1.JMESPathTypeError ||
171
+ error instanceof errors_js_1.VariadicArityError ||
172
+ error instanceof errors_js_1.ArityError) {
173
+ error.setEvaluatedFunctionName(node.value);
174
+ throw error;
175
+ }
176
+ }
177
+ }, _TreeInterpreter_visitFilterProjection = function _TreeInterpreter_visitFilterProjection(node, value) {
178
+ const base = this.visit(node.children[0], value);
179
+ if (!Array.isArray(base)) {
180
+ return null;
181
+ }
182
+ const comparatorNode = node.children[2];
183
+ const collected = [];
184
+ for (const item of base) {
185
+ if ((0, utils_js_1.isTruthy)(this.visit(comparatorNode, item))) {
186
+ const current = this.visit(node.children[1], item);
187
+ if (current !== null) {
188
+ collected.push(current);
189
+ }
190
+ }
191
+ }
192
+ return collected;
193
+ }, _TreeInterpreter_visitFlatten = function _TreeInterpreter_visitFlatten(node, value) {
194
+ const base = this.visit(node.children[0], value);
195
+ if (!Array.isArray(base)) {
196
+ return null;
197
+ }
198
+ const mergedList = [];
199
+ for (const item of base) {
200
+ if (Array.isArray(item)) {
201
+ mergedList.push(...item);
202
+ }
203
+ else {
204
+ mergedList.push(item);
205
+ }
206
+ }
207
+ return mergedList;
208
+ }, _TreeInterpreter_visitIdentity = function _TreeInterpreter_visitIdentity(_node, value) {
209
+ return value;
210
+ }, _TreeInterpreter_visitIndex = function _TreeInterpreter_visitIndex(node, value) {
211
+ if (!Array.isArray(value)) {
212
+ return null;
213
+ }
214
+ // The Python implementation doesn't support string indexing
215
+ // even though we could, so we won't either for now.
216
+ if (typeof node.value !== 'number') {
217
+ throw new errors_js_1.JMESPathError(`Invalid index: ${node.value}`);
218
+ }
219
+ const index = node.value < 0 ? value.length + node.value : node.value;
220
+ const found = value[index];
221
+ if (found === undefined) {
222
+ return null;
223
+ }
224
+ return found;
225
+ }, _TreeInterpreter_visitSlice = function _TreeInterpreter_visitSlice(node, value) {
226
+ const step = (0, typeutils_1.isIntegerNumber)(node.children[2]) ? node.children[2] : 1;
227
+ if (step === 0) {
228
+ throw new Error('Invalid slice, step cannot be 0');
229
+ }
230
+ if (!Array.isArray(value)) {
231
+ return null;
232
+ }
233
+ if (value.length === 0) {
234
+ return [];
235
+ }
236
+ return (0, utils_js_1.sliceArray)({
237
+ array: value,
238
+ start: node.children[0],
239
+ end: node.children[1],
240
+ step,
241
+ });
242
+ }, _TreeInterpreter_visitKeyValPair = function _TreeInterpreter_visitKeyValPair(node, value) {
243
+ return this.visit(node.children[0], value);
244
+ }, _TreeInterpreter_visitLiteral = function _TreeInterpreter_visitLiteral(node, _value) {
245
+ return node.value;
246
+ }, _TreeInterpreter_visitMultiSelectObject = function _TreeInterpreter_visitMultiSelectObject(node, value) {
247
+ if (Object.is(value, null)) {
248
+ return null;
249
+ }
250
+ const collected = {};
251
+ for (const child of node.children) {
252
+ if (typeof child.value === 'string') {
253
+ collected[child.value] = this.visit(child, value);
254
+ }
255
+ }
256
+ return collected;
257
+ }, _TreeInterpreter_visitMultiSelectList = function _TreeInterpreter_visitMultiSelectList(node, value) {
258
+ if (Object.is(value, null)) {
259
+ return null;
260
+ }
261
+ const collected = [];
262
+ for (const child of node.children) {
263
+ collected.push(this.visit(child, value));
264
+ }
265
+ return collected;
266
+ }, _TreeInterpreter_visitOrExpression = function _TreeInterpreter_visitOrExpression(node, value) {
267
+ const matched = this.visit(node.children[0], value);
268
+ if (!(0, utils_js_1.isTruthy)(matched)) {
269
+ return this.visit(node.children[1], value);
270
+ }
271
+ return matched;
272
+ }, _TreeInterpreter_visitAndExpression = function _TreeInterpreter_visitAndExpression(node, value) {
273
+ const matched = this.visit(node.children[0], value);
274
+ if (!(0, utils_js_1.isTruthy)(matched)) {
275
+ return matched;
276
+ }
277
+ return this.visit(node.children[1], value);
278
+ }, _TreeInterpreter_visitNotExpression = function _TreeInterpreter_visitNotExpression(node, value) {
279
+ const originalResult = this.visit(node.children[0], value);
280
+ if (typeof originalResult === 'number' && originalResult === 0) {
281
+ // Special case for 0, !0 should be false, not true.
282
+ // 0 is not a special cased integer in jmespath.
283
+ return false;
284
+ }
285
+ return !(0, utils_js_1.isTruthy)(originalResult);
286
+ }, _TreeInterpreter_visitProjection = function _TreeInterpreter_visitProjection(node, value) {
287
+ const base = this.visit(node.children[0], value);
288
+ if (!Array.isArray(base)) {
289
+ return null;
290
+ }
291
+ const collected = [];
292
+ for (const item of base) {
293
+ const current = this.visit(node.children[1], item);
294
+ if (current !== null) {
295
+ collected.push(current);
296
+ }
297
+ }
298
+ return collected;
299
+ }, _TreeInterpreter_visitValueProjection = function _TreeInterpreter_visitValueProjection(node, value) {
300
+ const base = this.visit(node.children[0], value);
301
+ if (!(0, typeutils_1.isRecord)(base)) {
302
+ return null;
303
+ }
304
+ const values = Object.values(base);
305
+ const collected = [];
306
+ for (const item of values) {
307
+ const current = this.visit(node.children[1], item);
308
+ if (current !== null) {
309
+ collected.push(current);
310
+ }
311
+ }
312
+ return collected;
313
+ };
@@ -0,0 +1,185 @@
1
+ import type { JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { Node } from './types.js';
3
+ /**
4
+ * AST node representing a comparator expression.
5
+ *
6
+ * A comparator expression is a binary expression that compares two values.
7
+ *
8
+ * @param name The name of the comparator
9
+ * @param first The left-hand side of the comparator
10
+ * @param second The right-hand side of the comparator
11
+ */
12
+ declare const comparator: (name: string, first: Node, second: Node) => Node;
13
+ /**
14
+ * AST node representing the current node.
15
+ *
16
+ * The current node is a reference to the current value being processed.
17
+ * In JMESPath, the current node is represented by the `@` symbol.
18
+ */
19
+ declare const currentNode: () => Node;
20
+ /**
21
+ * AST node representing an expression reference.
22
+ *
23
+ * An expression reference is a reference to another expression.
24
+ * In JMESPath, an expression reference is represented by the `&` symbol.
25
+ *
26
+ * @param expression The expression to reference
27
+ */
28
+ declare const expref: (expression: Node) => Node;
29
+ /**
30
+ * AST node representing a function expression.
31
+ *
32
+ * A function expression is a reference to a function and its arguments.
33
+ * The JMESPath specification defines a set of built-in functions that can
34
+ * be used in expressions like `length(@)`, `map(@, &foo)`, etc.
35
+ *
36
+ * Custom functions can be added by extending the `Functions` class.
37
+ *
38
+ * @param name The name of the function
39
+ * @param args The arguments to the function
40
+ */
41
+ declare const functionExpression: (name: string, args: Node[]) => Node;
42
+ /**
43
+ * AST node representing a field reference.
44
+ *
45
+ * A field reference is a reference to a field in an object.
46
+ */
47
+ declare const field: (name: JSONValue) => Node;
48
+ /**
49
+ * AST node representing a filter projection.
50
+ *
51
+ * A filter projection is a binary expression that filters the left-hand side
52
+ * based on the right-hand side.
53
+ *
54
+ * In JMESPath, a filter projection is represented by the `[]` operator.
55
+ * For example, `people[?age > 18]` filters the `people` array based on the
56
+ * `age` field.
57
+ *
58
+ * @param left The left-hand side of the filter projection
59
+ * @param right The right-hand side of the filter projection
60
+ * @param comparator The comparator to use for the filter
61
+ */
62
+ declare const filterProjection: (left: Node, right: Node, comparator: Node) => Node;
63
+ /**
64
+ * AST node representing a flatten expression.
65
+ *
66
+ * A flatten expression is a unary expression that flattens an array of arrays
67
+ * into a single array.
68
+ *
69
+ * In JMESPath, a flatten expression is represented by the `[]` operator.
70
+ * For example, `people[].name` flattens the `people` array and returns the
71
+ * `name` field of each object in the array.
72
+ *
73
+ * @param node The node to flatten
74
+ */
75
+ declare const flatten: (node: Node) => Node;
76
+ /**
77
+ * AST node representing an identity expression.
78
+ */
79
+ declare const identity: () => Node;
80
+ /**
81
+ * AST node representing an index reference.
82
+ *
83
+ * An index reference is a reference to an index in an array.
84
+ * For example, `people[0]` references the first element in the `people` array.
85
+ *
86
+ * @param index The index to reference
87
+ */
88
+ declare const index: (index: JSONValue) => Node;
89
+ /**
90
+ * AST node representing an index expression.
91
+ *
92
+ * An index expression holds the index and the children of the expression.
93
+ *
94
+ * @param children The children of the index expression
95
+ */
96
+ declare const indexExpression: (children: Node[]) => Node;
97
+ /**
98
+ * AST node representing a key-value pair.
99
+ *
100
+ * @param keyName The name of the key
101
+ * @param node The value of the key
102
+ */
103
+ declare const keyValPair: (keyName: JSONValue, node: Node) => Node;
104
+ /**
105
+ * AST node representing a literal value.
106
+ *
107
+ * A literal value is a value that is not a reference to another node.
108
+ *
109
+ * @param literalValue The value of the literal
110
+ */
111
+ declare const literal: (literalValue: JSONValue) => Node;
112
+ /**
113
+ * AST node representing a multi-select object.
114
+ *
115
+ * A multi-select object is a reference to multiple nodes in an object.
116
+ *
117
+ * @param nodes
118
+ */
119
+ declare const multiSelectObject: (nodes: Node[]) => Node;
120
+ /**
121
+ * AST node representing a multi-select list.
122
+ *
123
+ * @param nodes
124
+ */
125
+ declare const multiSelectList: (nodes: Node[]) => Node;
126
+ /**
127
+ * AST node representing an or expression.
128
+ *
129
+ * @param left The left-hand side of the or expression
130
+ * @param right The right-hand side of the or expression
131
+ */
132
+ declare const orExpression: (left: Node, right: Node) => Node;
133
+ /**
134
+ * AST node representing an and expression.
135
+ *
136
+ * @param left The left-hand side of the and expression
137
+ * @param right The right-hand side of the and expression
138
+ */
139
+ declare const andExpression: (left: Node, right: Node) => Node;
140
+ /**
141
+ * AST node representing a not expression.
142
+ *
143
+ * @param left The left-hand side of the not expression
144
+ * @param right The right-hand side of the not expression
145
+ */
146
+ declare const notExpression: (expr: Node) => Node;
147
+ /**
148
+ * AST node representing a pipe expression.
149
+ *
150
+ * @param left The left-hand side of the pipe expression
151
+ * @param right The right-hand side of the pipe expression
152
+ */
153
+ declare const pipe: (left: Node, right: Node) => Node;
154
+ /**
155
+ * AST node representing a projection.
156
+ *
157
+ * @param left The left-hand side of the projection
158
+ * @param right The right-hand side of the projection
159
+ */
160
+ declare const projection: (left: Node, right: Node) => Node;
161
+ /**
162
+ * AST node representing a subexpression.
163
+ *
164
+ * @param children The children of the subexpression
165
+ */
166
+ declare const subexpression: (children: Node[]) => Node;
167
+ /**
168
+ * AST node representing a slice.
169
+ *
170
+ * A slice is a reference to a range of values in an array.
171
+ *
172
+ * @param start The start of the slice
173
+ * @param end The end of the slice
174
+ * @param step The step of the slice
175
+ */
176
+ declare const slice: (start: JSONValue, end: JSONValue, step: JSONValue) => Node;
177
+ /**
178
+ * AST node representing a value projection.
179
+ *
180
+ * @param left The left-hand side of the value projection
181
+ * @param right The right-hand side of the value projection
182
+ */
183
+ declare const valueProjection: (left: Node, right: Node) => Node;
184
+ export { andExpression, comparator, currentNode, expref, field, filterProjection, flatten, functionExpression, identity, index, indexExpression, keyValPair, literal, multiSelectObject, multiSelectList, notExpression, orExpression, pipe, projection, slice, subexpression, valueProjection, };
185
+ //# sourceMappingURL=ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;;;;;GAQG;AACH,QAAA,MAAM,UAAU,SAAU,MAAM,SAAS,IAAI,UAAU,IAAI,KAAG,IAI5D,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,WAAW,QAAO,IAGtB,CAAC;AAEH;;;;;;;GAOG;AACH,QAAA,MAAM,MAAM,eAAgB,IAAI,KAAG,IAGjC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,kBAAkB,SAAU,MAAM,QAAQ,IAAI,EAAE,KAAG,IAIvD,CAAC;AAEH;;;;GAIG;AACH,QAAA,MAAM,KAAK,SAAU,SAAS,KAAG,IAI/B,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,gBAAgB,SAAU,IAAI,SAAS,IAAI,cAAc,IAAI,KAAG,IAGpE,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,OAAO,SAAU,IAAI,KAAG,IAG5B,CAAC;AAEH;;GAEG;AACH,QAAA,MAAM,QAAQ,QAAO,IAA4C,CAAC;AAElE;;;;;;;GAOG;AACH,QAAA,MAAM,KAAK,UAAW,SAAS,KAAG,IAIhC,CAAC;AAEH;;;;;;GAMG;AACH,QAAA,MAAM,eAAe,aAAc,IAAI,EAAE,KAAG,IAG1C,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,UAAU,YAAa,SAAS,QAAQ,IAAI,KAAG,IAInD,CAAC;AAEH;;;;;;GAMG;AACH,QAAA,MAAM,OAAO,iBAAkB,SAAS,KAAG,IAIzC,CAAC;AAEH;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,UAAW,IAAI,EAAE,KAAG,IAGzC,CAAC;AAEH;;;;GAIG;AACH,QAAA,MAAM,eAAe,UAAW,IAAI,EAAE,KAAG,IAGvC,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,YAAY,SAAU,IAAI,SAAS,IAAI,KAAG,IAG9C,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,aAAa,SAAU,IAAI,SAAS,IAAI,KAAG,IAG/C,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,aAAa,SAAU,IAAI,KAAG,IAGlC,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,IAAI,SAAU,IAAI,SAAS,IAAI,KAAG,IAGtC,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,UAAU,SAAU,IAAI,SAAS,IAAI,KAAG,IAG5C,CAAC;AAEH;;;;GAIG;AACH,QAAA,MAAM,aAAa,aAAc,IAAI,EAAE,KAAG,IAGxC,CAAC;AAEH;;;;;;;;GAQG;AACH,QAAA,MAAM,KAAK,UAAW,SAAS,OAAO,SAAS,QAAQ,SAAS,KAAG,IAGjE,CAAC;AAEH;;;;;GAKG;AACH,QAAA,MAAM,eAAe,SAAU,IAAI,SAAS,IAAI,KAAG,IAGjD,CAAC;AAEH,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,kBAAkB,EAClB,QAAQ,EACR,KAAK,EACL,eAAe,EACf,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,aAAa,EACb,eAAe,GAChB,CAAC"}