@aws-lambda-powertools/jmespath 2.3.0 → 2.4.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.
@@ -1,16 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.TreeInterpreter = void 0;
16
4
  const typeutils_1 = require("@aws-lambda-powertools/commons/typeutils");
@@ -28,19 +16,18 @@ const utils_js_1 = require("./utils.js");
28
16
  * @internal
29
17
  */
30
18
  class TreeInterpreter {
19
+ #functions;
31
20
  /**
32
21
  * @param options The options to use for the interpreter.
33
22
  */
34
23
  constructor(options) {
35
- _TreeInterpreter_instances.add(this);
36
- _TreeInterpreter_functions.set(this, void 0);
37
24
  if (options?.customFunctions) {
38
- __classPrivateFieldSet(this, _TreeInterpreter_functions, options.customFunctions, "f");
25
+ this.#functions = options.customFunctions;
39
26
  }
40
27
  else {
41
- __classPrivateFieldSet(this, _TreeInterpreter_functions, new Functions_js_1.Functions(), "f");
28
+ this.#functions = new Functions_js_1.Functions();
42
29
  }
43
- __classPrivateFieldGet(this, _TreeInterpreter_functions, "f").introspectMethods();
30
+ this.#functions.introspectMethods();
44
31
  }
45
32
  /**
46
33
  * Visit a node in the AST.
@@ -53,28 +40,28 @@ class TreeInterpreter {
53
40
  visit(node, value) {
54
41
  const nodeType = node.type;
55
42
  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),
43
+ subexpression: this.#visitSubexpressionOrIndexExpressionOrPipe,
44
+ field: this.#visitField,
45
+ comparator: this.#visitComparator,
46
+ current: this.#visitCurrent,
47
+ expref: this.#visitExpref,
48
+ function_expression: this.#visitFunctionExpression,
49
+ filter_projection: this.#visitFilterProjection,
50
+ flatten: this.#visitFlatten,
51
+ identity: this.#visitIdentity,
52
+ index: this.#visitIndex,
53
+ index_expression: this.#visitSubexpressionOrIndexExpressionOrPipe,
54
+ slice: this.#visitSlice,
55
+ key_val_pair: this.#visitKeyValPair,
56
+ literal: this.#visitLiteral,
57
+ multi_select_object: this.#visitMultiSelectObject,
58
+ multi_select_list: this.#visitMultiSelectList,
59
+ or_expression: this.#visitOrExpression,
60
+ and_expression: this.#visitAndExpression,
61
+ not_expression: this.#visitNotExpression,
62
+ pipe: this.#visitSubexpressionOrIndexExpressionOrPipe,
63
+ projection: this.#visitProjection,
64
+ value_projection: this.#visitValueProjection,
78
65
  };
79
66
  const visitMethod = visitMethods[nodeType];
80
67
  if (visitMethod) {
@@ -84,230 +71,374 @@ class TreeInterpreter {
84
71
  throw new errors_js_1.JMESPathError(`Not Implemented: Invalid node type: ${node.type}`);
85
72
  }
86
73
  }
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];
74
+ /**
75
+ * Visit a subexpression, index expression, or pipe node.
76
+ *
77
+ * This method is shared between subexpression, index expression, and pipe
78
+ * since they all behave the same way in the context of an expression.
79
+ *
80
+ * They all visit their children and return the result of the last child.
81
+ *
82
+ * @param node The node to visit.
83
+ * @param value The current value to visit.
84
+ */
85
+ #visitSubexpressionOrIndexExpressionOrPipe(node, value) {
86
+ let result = value;
87
+ for (const child of node.children) {
88
+ result = this.visit(child, result);
89
+ }
90
+ return result;
102
91
  }
103
- else {
104
- return null;
92
+ /**
93
+ * Visit a field node.
94
+ *
95
+ * @param node The field node to visit.
96
+ * @param value The current value to visit.
97
+ */
98
+ #visitField(node, value) {
99
+ if (!node.value)
100
+ return null;
101
+ if ((0, typeutils_1.isRecord)(value) &&
102
+ typeof node.value === 'string' &&
103
+ node.value in value) {
104
+ return value[node.value];
105
+ }
106
+ else {
107
+ return null;
108
+ }
105
109
  }
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;
110
+ /**
111
+ * Visit a comparator node.
112
+ *
113
+ * @param node The comparator node to visit.
114
+ * @param value The current value to visit.
115
+ */
116
+ #visitComparator(node, value) {
117
+ const comparator = node.value;
118
+ const left = this.visit(node.children[0], value);
119
+ const right = this.visit(node.children[1], value);
120
+ if (typeof comparator === 'string' &&
121
+ ['eq', 'ne', 'gt', 'gte', 'lt', 'lte'].includes(comparator)) {
122
+ // Common cases: comparator is == or !=
123
+ if (comparator === 'eq') {
124
+ return (0, typeutils_1.isStrictEqual)(left, right);
124
125
  }
125
- else if (comparator === 'lte') {
126
- return left <= right;
126
+ else if (comparator === 'ne') {
127
+ return !(0, typeutils_1.isStrictEqual)(left, right);
127
128
  }
128
- else if (comparator === 'gt') {
129
- return left > right;
130
- }
131
- else {
132
- return left >= right;
129
+ else if (typeof left === 'number' && typeof right === 'number') {
130
+ // Ordering operators only work on numbers. Evaluating them on other
131
+ // types will return null.
132
+ if (comparator === 'lt') {
133
+ return left < right;
134
+ }
135
+ else if (comparator === 'lte') {
136
+ return left <= right;
137
+ }
138
+ else if (comparator === 'gt') {
139
+ return left > right;
140
+ }
141
+ else {
142
+ return left >= right;
143
+ }
133
144
  }
134
145
  }
146
+ else {
147
+ throw new errors_js_1.JMESPathError(`Invalid comparator: ${comparator}`);
148
+ }
135
149
  }
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);
150
+ /**
151
+ * Visit a current node.
152
+ *
153
+ * @param node The current node to visit.
154
+ * @param value The current value to visit.
155
+ */
156
+ #visitCurrent(_node, value) {
157
+ return value;
159
158
  }
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);
159
+ /**
160
+ * Visit an expref node.
161
+ *
162
+ * @param node The expref node to visit.
163
+ * @param value The current value to visit.
164
+ */
165
+ #visitExpref(node, _value) {
166
+ return new Expression_js_1.Expression(node.children[0], this);
168
167
  }
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;
168
+ /**
169
+ * Visit a function expression node.
170
+ *
171
+ * @param node The function expression node to visit.
172
+ * @param value The current value to visit.
173
+ */
174
+ #visitFunctionExpression(node, value) {
175
+ const args = [];
176
+ for (const child of node.children) {
177
+ args.push(this.visit(child, value));
175
178
  }
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);
179
+ // check that method name is a string
180
+ if (typeof node.value !== 'string') {
181
+ throw new errors_js_1.JMESPathError(`Function name must be a string, got ${node.value}`);
182
+ }
183
+ // convert snake_case to camelCase
184
+ const normalizedFunctionName = node.value.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
185
+ // capitalize first letter & add `func` prefix
186
+ const funcName = `func${normalizedFunctionName.charAt(0).toUpperCase() +
187
+ normalizedFunctionName.slice(1)}`;
188
+ if (!this.#functions.methods.has(funcName)) {
189
+ throw new errors_js_1.UnknownFunctionError(node.value);
190
+ }
191
+ try {
192
+ // We know that methodName is a key of this.#functions, but TypeScript
193
+ // doesn't know that, so we have to use @ts-ignore to tell it that it's
194
+ // okay. We could use a type assertion like `as keyof Functions`, but
195
+ // we also want to keep the args generic, so for now we'll just ignore it.
196
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
197
+ // @ts-ignore-next-line
198
+ return this.#functions[funcName](args);
199
+ }
200
+ catch (error) {
201
+ if (error instanceof errors_js_1.JMESPathTypeError ||
202
+ error instanceof errors_js_1.VariadicArityError ||
203
+ error instanceof errors_js_1.ArityError) {
204
+ error.setEvaluatedFunctionName(node.value);
205
+ throw error;
189
206
  }
190
207
  }
191
208
  }
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);
209
+ /**
210
+ * Visit a filter projection node.
211
+ *
212
+ * @param node The filter projection node to visit.
213
+ * @param value The current value to visit.
214
+ */
215
+ #visitFilterProjection(node, value) {
216
+ const base = this.visit(node.children[0], value);
217
+ if (!Array.isArray(base)) {
218
+ return null;
202
219
  }
203
- else {
204
- mergedList.push(item);
220
+ const comparatorNode = node.children[2];
221
+ const collected = [];
222
+ for (const item of base) {
223
+ if ((0, utils_js_1.isTruthy)(this.visit(comparatorNode, item))) {
224
+ const current = this.visit(node.children[1], item);
225
+ if (current !== null) {
226
+ collected.push(current);
227
+ }
228
+ }
205
229
  }
230
+ return collected;
206
231
  }
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}`);
232
+ /**
233
+ * Visit a flatten node.
234
+ *
235
+ * @param node The flatten node to visit.
236
+ * @param value The current value to visit.
237
+ */
238
+ #visitFlatten(node, value) {
239
+ const base = this.visit(node.children[0], value);
240
+ if (!Array.isArray(base)) {
241
+ return null;
242
+ }
243
+ const mergedList = [];
244
+ for (const item of base) {
245
+ if (Array.isArray(item)) {
246
+ mergedList.push(...item);
247
+ }
248
+ else {
249
+ mergedList.push(item);
250
+ }
251
+ }
252
+ return mergedList;
218
253
  }
219
- const index = node.value < 0 ? value.length + node.value : node.value;
220
- const found = value[index];
221
- if (found === undefined) {
222
- return null;
254
+ /**
255
+ * Visit an identity node.
256
+ *
257
+ * @param node The identity node to visit.
258
+ * @param value The current value to visit.
259
+ */
260
+ #visitIdentity(_node, value) {
261
+ return value;
223
262
  }
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');
263
+ /**
264
+ * Visit an index node.
265
+ *
266
+ * @param node The index node to visit.
267
+ * @param value The current value to visit.
268
+ */
269
+ #visitIndex(node, value) {
270
+ if (!Array.isArray(value)) {
271
+ return null;
272
+ }
273
+ // The Python implementation doesn't support string indexing
274
+ // even though we could, so we won't either for now.
275
+ if (typeof node.value !== 'number') {
276
+ throw new errors_js_1.JMESPathError(`Invalid index: ${node.value}`);
277
+ }
278
+ const index = node.value < 0 ? value.length + node.value : node.value;
279
+ const found = value[index];
280
+ if (found === undefined) {
281
+ return null;
282
+ }
283
+ return found;
229
284
  }
230
- if (!Array.isArray(value)) {
231
- return null;
285
+ /**
286
+ * Visit a slice node.
287
+ *
288
+ * @param node The slice node to visit.
289
+ * @param value The current value to visit.
290
+ */
291
+ #visitSlice(node, value) {
292
+ const step = (0, typeutils_1.isIntegerNumber)(node.children[2]) ? node.children[2] : 1;
293
+ if (step === 0) {
294
+ throw new Error('Invalid slice, step cannot be 0');
295
+ }
296
+ if (!Array.isArray(value)) {
297
+ return null;
298
+ }
299
+ if (value.length === 0) {
300
+ return [];
301
+ }
302
+ return (0, utils_js_1.sliceArray)({
303
+ array: value,
304
+ start: node.children[0],
305
+ end: node.children[1],
306
+ step,
307
+ });
232
308
  }
233
- if (value.length === 0) {
234
- return [];
309
+ /**
310
+ * Visit a key-value pair node.
311
+ *
312
+ * @param node The key-value pair node to visit.
313
+ * @param value The current value to visit.
314
+ */
315
+ #visitKeyValPair(node, value) {
316
+ return this.visit(node.children[0], value);
235
317
  }
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;
318
+ /**
319
+ * Visit a literal node.
320
+ *
321
+ * @param node The literal node to visit.
322
+ * @param value The current value to visit.
323
+ */
324
+ #visitLiteral(node, _value) {
325
+ return node.value;
249
326
  }
250
- const collected = {};
251
- for (const child of node.children) {
252
- if (typeof child.value === 'string') {
253
- collected[child.value] = this.visit(child, value);
327
+ /**
328
+ * Visit a multi-select object node.
329
+ *
330
+ * @param node The multi-select object node to visit.
331
+ * @param value The current value to visit.
332
+ */
333
+ #visitMultiSelectObject(node, value) {
334
+ if (Object.is(value, null)) {
335
+ return null;
254
336
  }
337
+ const collected = {};
338
+ for (const child of node.children) {
339
+ if (typeof child.value === 'string') {
340
+ collected[child.value] = this.visit(child, value);
341
+ }
342
+ }
343
+ return collected;
255
344
  }
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);
345
+ /**
346
+ * Visit a multi-select list node.
347
+ *
348
+ * @param node The multi-select list node to visit.
349
+ * @param value The current value to visit.
350
+ */
351
+ #visitMultiSelectList(node, value) {
352
+ if (Object.is(value, null)) {
353
+ return null;
354
+ }
355
+ const collected = [];
356
+ for (const child of node.children) {
357
+ collected.push(this.visit(child, value));
358
+ }
359
+ return collected;
270
360
  }
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)) {
361
+ /**
362
+ * Visit an or expression node.
363
+ *
364
+ * @param node The or expression node to visit.
365
+ * @param value The current value to visit.
366
+ */
367
+ #visitOrExpression(node, value) {
368
+ const matched = this.visit(node.children[0], value);
369
+ if (!(0, utils_js_1.isTruthy)(matched)) {
370
+ return this.visit(node.children[1], value);
371
+ }
275
372
  return matched;
276
373
  }
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;
374
+ /**
375
+ * Visit an and expression node.
376
+ *
377
+ * @param node The and expression node to visit.
378
+ * @param value The current value to visit.
379
+ */
380
+ #visitAndExpression(node, value) {
381
+ const matched = this.visit(node.children[0], value);
382
+ if (!(0, utils_js_1.isTruthy)(matched)) {
383
+ return matched;
384
+ }
385
+ return this.visit(node.children[1], value);
290
386
  }
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);
387
+ /**
388
+ * Visit a not expression node.
389
+ *
390
+ * @param node The not expression node to visit.
391
+ * @param value The current value to visit.
392
+ */
393
+ #visitNotExpression(node, value) {
394
+ const originalResult = this.visit(node.children[0], value);
395
+ if (typeof originalResult === 'number' && originalResult === 0) {
396
+ // Special case for 0, !0 should be false, not true.
397
+ // 0 is not a special cased integer in jmespath.
398
+ return false;
296
399
  }
400
+ return !(0, utils_js_1.isTruthy)(originalResult);
297
401
  }
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;
402
+ /**
403
+ * Visit a projection node.
404
+ *
405
+ * @param node The projection node to visit.
406
+ * @param value The current value to visit.
407
+ */
408
+ #visitProjection(node, value) {
409
+ const base = this.visit(node.children[0], value);
410
+ if (!Array.isArray(base)) {
411
+ return null;
412
+ }
413
+ const collected = [];
414
+ for (const item of base) {
415
+ const current = this.visit(node.children[1], item);
416
+ if (current !== null) {
417
+ collected.push(current);
418
+ }
419
+ }
420
+ return collected;
303
421
  }
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);
422
+ /**
423
+ * Visit a value projection node.
424
+ *
425
+ * @param node The value projection node to visit.
426
+ * @param value The current value to visit.
427
+ */
428
+ #visitValueProjection(node, value) {
429
+ const base = this.visit(node.children[0], value);
430
+ if (!(0, typeutils_1.isRecord)(base)) {
431
+ return null;
310
432
  }
433
+ const values = Object.values(base);
434
+ const collected = [];
435
+ for (const item of values) {
436
+ const current = this.visit(node.children[1], item);
437
+ if (current !== null) {
438
+ collected.push(current);
439
+ }
440
+ }
441
+ return collected;
311
442
  }
312
- return collected;
313
- };
443
+ }
444
+ exports.TreeInterpreter = TreeInterpreter;