@jmespath-community/jmespath 1.2.0 → 1.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.
- package/README.md +228 -12
- package/dist/cli.cjs +2816 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +2794 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.cjs +2699 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +464 -0
- package/dist/index.d.ts +464 -0
- package/dist/index.esm.js +2707 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +6 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/index.mjs +2697 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +2712 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +6 -0
- package/dist/index.umd.min.js.map +1 -0
- package/package.json +68 -11
- package/dist/jmespath.esm.js +0 -2369
- package/dist/jmespath.esm.min.js +0 -2
- package/dist/jmespath.esm.min.js.map +0 -1
- package/dist/jmespath.umd.js +0 -2398
- package/dist/jmespath.umd.min.js +0 -2
- package/dist/jmespath.umd.min.js.map +0 -1
- package/dist/lib/bin/jp.js +0 -127
- package/dist/lib/bin/jp.js.map +0 -1
- package/dist/lib/package.json +0 -70
- package/dist/lib/src/AST.type.js +0 -3
- package/dist/lib/src/AST.type.js.map +0 -1
- package/dist/lib/src/JSON.type.js +0 -3
- package/dist/lib/src/JSON.type.js.map +0 -1
- package/dist/lib/src/Lexer.js +0 -327
- package/dist/lib/src/Lexer.js.map +0 -1
- package/dist/lib/src/Lexer.type.js +0 -46
- package/dist/lib/src/Lexer.type.js.map +0 -1
- package/dist/lib/src/Parser.js +0 -468
- package/dist/lib/src/Parser.js.map +0 -1
- package/dist/lib/src/Parser.type.js +0 -3
- package/dist/lib/src/Parser.type.js.map +0 -1
- package/dist/lib/src/Runtime.js +0 -924
- package/dist/lib/src/Runtime.js.map +0 -1
- package/dist/lib/src/Scope.js +0 -29
- package/dist/lib/src/Scope.js.map +0 -1
- package/dist/lib/src/TreeInterpreter.js +0 -319
- package/dist/lib/src/TreeInterpreter.js.map +0 -1
- package/dist/lib/src/index.js +0 -65
- package/dist/lib/src/index.js.map +0 -1
- package/dist/lib/src/utils/index.js +0 -145
- package/dist/lib/src/utils/index.js.map +0 -1
- package/dist/lib/src/utils/strings.js +0 -92
- package/dist/lib/src/utils/strings.js.map +0 -1
- package/dist/lib/src/utils/text.js +0 -45
- package/dist/lib/src/utils/text.js.map +0 -1
- package/dist/types/bin/jp.d.ts +0 -2
- package/dist/types/src/AST.type.d.ts +0 -104
- package/dist/types/src/JSON.type.d.ts +0 -10
- package/dist/types/src/Lexer.d.ts +0 -19
- package/dist/types/src/Lexer.type.d.ts +0 -51
- package/dist/types/src/Parser.d.ts +0 -33
- package/dist/types/src/Parser.type.d.ts +0 -4
- package/dist/types/src/Runtime.d.ts +0 -87
- package/dist/types/src/Scope.d.ts +0 -8
- package/dist/types/src/TreeInterpreter.d.ts +0 -22
- package/dist/types/src/index.d.ts +0 -45
- package/dist/types/src/utils/index.d.ts +0 -16
- package/dist/types/src/utils/strings.d.ts +0 -11
- package/dist/types/src/utils/text.d.ts +0 -11
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
type JSONPrimitive = string | number | boolean | null;
|
|
2
|
+
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
3
|
+
type JSONObject = Readonly<{
|
|
4
|
+
[member: string]: JSONValue;
|
|
5
|
+
}>;
|
|
6
|
+
type JSONArray = ReadonlyArray<JSONValue>;
|
|
7
|
+
|
|
8
|
+
declare enum Token {
|
|
9
|
+
TOK_EOF = "EOF",
|
|
10
|
+
TOK_VARIABLE = "Variable",
|
|
11
|
+
TOK_ASSIGN = "Assign",
|
|
12
|
+
TOK_UNQUOTEDIDENTIFIER = "UnquotedIdentifier",
|
|
13
|
+
TOK_QUOTEDIDENTIFIER = "QuotedIdentifier",
|
|
14
|
+
TOK_RBRACKET = "Rbracket",
|
|
15
|
+
TOK_RPAREN = "Rparen",
|
|
16
|
+
TOK_COMMA = "Comma",
|
|
17
|
+
TOK_COLON = "Colon",
|
|
18
|
+
TOK_RBRACE = "Rbrace",
|
|
19
|
+
TOK_NUMBER = "Number",
|
|
20
|
+
TOK_CURRENT = "Current",
|
|
21
|
+
TOK_ROOT = "Root",
|
|
22
|
+
TOK_EXPREF = "Expref",
|
|
23
|
+
TOK_PIPE = "Pipe",
|
|
24
|
+
TOK_OR = "Or",
|
|
25
|
+
TOK_AND = "And",
|
|
26
|
+
TOK_EQ = "EQ",
|
|
27
|
+
TOK_GT = "GT",
|
|
28
|
+
TOK_LT = "LT",
|
|
29
|
+
TOK_GTE = "GTE",
|
|
30
|
+
TOK_LTE = "LTE",
|
|
31
|
+
TOK_NE = "NE",
|
|
32
|
+
TOK_PLUS = "Plus",
|
|
33
|
+
TOK_MINUS = "Minus",
|
|
34
|
+
TOK_MULTIPLY = "Multiply",
|
|
35
|
+
TOK_DIVIDE = "Divide",
|
|
36
|
+
TOK_MODULO = "Modulo",
|
|
37
|
+
TOK_DIV = "Div",
|
|
38
|
+
TOK_FLATTEN = "Flatten",
|
|
39
|
+
TOK_STAR = "Star",
|
|
40
|
+
TOK_FILTER = "Filter",
|
|
41
|
+
TOK_DOT = "Dot",
|
|
42
|
+
TOK_NOT = "Not",
|
|
43
|
+
TOK_LBRACE = "Lbrace",
|
|
44
|
+
TOK_LBRACKET = "Lbracket",
|
|
45
|
+
TOK_LPAREN = "Lparen",
|
|
46
|
+
TOK_LITERAL = "Literal",
|
|
47
|
+
TOK_QUESTION = "Question"
|
|
48
|
+
}
|
|
49
|
+
type LexerTokenValue = JSONValue;
|
|
50
|
+
interface LexerToken {
|
|
51
|
+
type: Token;
|
|
52
|
+
value: LexerTokenValue;
|
|
53
|
+
start: number;
|
|
54
|
+
}
|
|
55
|
+
interface LexerOptions {
|
|
56
|
+
enable_legacy_literals?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface FieldNode {
|
|
60
|
+
readonly type: 'Field';
|
|
61
|
+
readonly name: string;
|
|
62
|
+
}
|
|
63
|
+
interface LiteralNode {
|
|
64
|
+
readonly type: 'Literal';
|
|
65
|
+
readonly value: JSONValue;
|
|
66
|
+
}
|
|
67
|
+
interface IndexNode {
|
|
68
|
+
readonly type: 'Index';
|
|
69
|
+
readonly value: number;
|
|
70
|
+
}
|
|
71
|
+
interface FilterProjectionNode {
|
|
72
|
+
readonly type: 'FilterProjection';
|
|
73
|
+
readonly left: ExpressionNode;
|
|
74
|
+
readonly right: ExpressionNode;
|
|
75
|
+
readonly condition: ExpressionNode;
|
|
76
|
+
}
|
|
77
|
+
interface SliceNode {
|
|
78
|
+
readonly type: 'Slice';
|
|
79
|
+
readonly start: number | null;
|
|
80
|
+
readonly stop: number | null;
|
|
81
|
+
readonly step: number | null;
|
|
82
|
+
}
|
|
83
|
+
type ComparatorType = 'GT' | 'LT' | 'GTE' | 'LTE' | 'NE' | 'EQ';
|
|
84
|
+
interface ComparatorNode {
|
|
85
|
+
readonly type: 'Comparator';
|
|
86
|
+
readonly name: ComparatorType;
|
|
87
|
+
readonly left: ExpressionNode;
|
|
88
|
+
readonly right: ExpressionNode;
|
|
89
|
+
}
|
|
90
|
+
interface KeyValuePairNode {
|
|
91
|
+
readonly type: 'KeyValuePair';
|
|
92
|
+
readonly name: string;
|
|
93
|
+
readonly value: ExpressionNode;
|
|
94
|
+
}
|
|
95
|
+
interface MultiSelectHashNode {
|
|
96
|
+
type: 'MultiSelectHash';
|
|
97
|
+
children: KeyValuePairNode[];
|
|
98
|
+
}
|
|
99
|
+
interface MultiSelectListNode {
|
|
100
|
+
type: 'MultiSelectList';
|
|
101
|
+
children: ExpressionNode[];
|
|
102
|
+
}
|
|
103
|
+
interface FunctionNode {
|
|
104
|
+
readonly type: 'Function';
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly children: ExpressionNode[];
|
|
107
|
+
}
|
|
108
|
+
interface LetExpressionNode {
|
|
109
|
+
readonly type: 'LetExpression';
|
|
110
|
+
readonly bindings: BindingNode[];
|
|
111
|
+
readonly expression: ExpressionNode;
|
|
112
|
+
}
|
|
113
|
+
interface BindingNode {
|
|
114
|
+
readonly type: 'Binding';
|
|
115
|
+
readonly variable: string;
|
|
116
|
+
readonly reference: ExpressionNode;
|
|
117
|
+
}
|
|
118
|
+
interface VariableNode {
|
|
119
|
+
readonly type: 'Variable';
|
|
120
|
+
readonly name: string;
|
|
121
|
+
}
|
|
122
|
+
interface TernaryNode {
|
|
123
|
+
readonly type: 'Ternary';
|
|
124
|
+
readonly condition: ExpressionNode;
|
|
125
|
+
readonly trueExpr: ExpressionNode;
|
|
126
|
+
readonly falseExpr: ExpressionNode;
|
|
127
|
+
}
|
|
128
|
+
type BinaryExpressionType = 'AndExpression' | 'IndexExpression' | 'OrExpression' | 'Pipe' | 'Projection' | 'Subexpression' | 'ValueProjection';
|
|
129
|
+
type UnaryExpressionType = 'ExpressionReference' | 'Flatten' | 'NotExpression';
|
|
130
|
+
type SimpleExpressionType = 'Identity' | 'Current' | 'Root';
|
|
131
|
+
interface SimpleExpressionNode<T extends SimpleExpressionType = SimpleExpressionType> {
|
|
132
|
+
readonly type: T;
|
|
133
|
+
}
|
|
134
|
+
interface UnaryExpressionNode<T extends UnaryExpressionType = UnaryExpressionType> {
|
|
135
|
+
readonly type: T;
|
|
136
|
+
readonly child: ExpressionNode;
|
|
137
|
+
}
|
|
138
|
+
type UnaryOperatorType = 'Plus' | 'Minus';
|
|
139
|
+
interface UnaryArithmeticNode {
|
|
140
|
+
readonly type: 'Unary';
|
|
141
|
+
readonly operator: UnaryOperatorType;
|
|
142
|
+
readonly operand: ExpressionNode;
|
|
143
|
+
}
|
|
144
|
+
interface BinaryExpressionNode<T extends BinaryExpressionType = BinaryExpressionType> {
|
|
145
|
+
readonly type: T;
|
|
146
|
+
readonly left: ExpressionNode;
|
|
147
|
+
readonly right: ExpressionNode;
|
|
148
|
+
}
|
|
149
|
+
type BinaryOperatorType = 'Plus' | 'Minus' | 'Multiply' | Token.TOK_STAR | 'Divide' | 'Modulo' | 'Div';
|
|
150
|
+
interface BinaryArithmeticNode {
|
|
151
|
+
readonly type: 'Arithmetic';
|
|
152
|
+
readonly operator: BinaryOperatorType;
|
|
153
|
+
readonly left: ExpressionNode;
|
|
154
|
+
readonly right: ExpressionNode;
|
|
155
|
+
}
|
|
156
|
+
type ExpressionNode = SimpleExpressionNode | UnaryExpressionNode | UnaryArithmeticNode | BinaryExpressionNode | BinaryArithmeticNode | ComparatorNode | SliceNode | FilterProjectionNode | IndexNode | LiteralNode | FieldNode | MultiSelectHashNode | MultiSelectListNode | FunctionNode | LetExpressionNode | BindingNode | VariableNode | TernaryNode;
|
|
157
|
+
type ExpressionReference = {
|
|
158
|
+
expref: true;
|
|
159
|
+
} & ExpressionNode;
|
|
160
|
+
|
|
161
|
+
type ScopeEntry = JSONObject;
|
|
162
|
+
interface Options extends LexerOptions {
|
|
163
|
+
maxDepth?: number;
|
|
164
|
+
maxNodes?: number;
|
|
165
|
+
maxOutputSize?: number;
|
|
166
|
+
allowedFunctions?: string[];
|
|
167
|
+
disallowedFunctions?: string[];
|
|
168
|
+
timeoutMs?: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare enum InputArgument {
|
|
172
|
+
TYPE_NUMBER = 0,
|
|
173
|
+
TYPE_ANY = 1,
|
|
174
|
+
TYPE_STRING = 2,
|
|
175
|
+
TYPE_ARRAY = 3,
|
|
176
|
+
TYPE_OBJECT = 4,
|
|
177
|
+
TYPE_BOOLEAN = 5,
|
|
178
|
+
TYPE_EXPREF = 6,
|
|
179
|
+
TYPE_NULL = 7,
|
|
180
|
+
TYPE_ARRAY_NUMBER = 8,
|
|
181
|
+
TYPE_ARRAY_STRING = 9,
|
|
182
|
+
TYPE_ARRAY_OBJECT = 10,
|
|
183
|
+
TYPE_ARRAY_ARRAY = 11
|
|
184
|
+
}
|
|
185
|
+
interface InputSignature {
|
|
186
|
+
types: InputArgument[];
|
|
187
|
+
variadic?: boolean;
|
|
188
|
+
optional?: boolean;
|
|
189
|
+
}
|
|
190
|
+
type RuntimeFunction<T extends ReadonlyArray<JSONValue | ExpressionNode>, U> = (resolvedArgs: T) => U;
|
|
191
|
+
interface FunctionSignature {
|
|
192
|
+
_func: RuntimeFunction<any, JSONValue>;
|
|
193
|
+
_signature: InputSignature[];
|
|
194
|
+
}
|
|
195
|
+
interface FunctionTable {
|
|
196
|
+
[functionName: string]: FunctionSignature;
|
|
197
|
+
}
|
|
198
|
+
type BuiltInFunctionNames = 'abs' | 'avg' | 'ceil' | 'contains' | 'ends_with' | 'find_first' | 'find_last' | 'floor' | 'from_items' | 'group_by' | 'items' | 'join' | 'keys' | 'length' | 'lower' | 'map' | 'max' | 'max_by' | 'merge' | 'min' | 'min_by' | 'not_null' | 'pad_left' | 'pad_right' | 'replace' | 'reverse' | 'sort' | 'sort_by' | 'split' | 'starts_with' | 'sum' | 'to_array' | 'to_number' | 'to_string' | 'type' | 'upper' | 'values' | 'zip';
|
|
199
|
+
interface RegisterOptions {
|
|
200
|
+
/**
|
|
201
|
+
* Allow overriding existing functions. Default: false
|
|
202
|
+
* When true, replaces existing function without error
|
|
203
|
+
* When false, throws error if function already exists (backward compatible)
|
|
204
|
+
*/
|
|
205
|
+
override?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Emit warning when overriding existing functions. Default: false
|
|
208
|
+
* Only applies when override is true
|
|
209
|
+
*/
|
|
210
|
+
warn?: boolean;
|
|
211
|
+
}
|
|
212
|
+
type RegistrationResult = {
|
|
213
|
+
success: true;
|
|
214
|
+
message?: string;
|
|
215
|
+
} | {
|
|
216
|
+
success: false;
|
|
217
|
+
reason: 'already-exists' | 'invalid-signature' | 'invalid-name';
|
|
218
|
+
message: string;
|
|
219
|
+
};
|
|
220
|
+
interface FunctionRegistry {
|
|
221
|
+
/**
|
|
222
|
+
* Register a new function with optional override behavior
|
|
223
|
+
*/
|
|
224
|
+
register<T extends string>(name: T extends BuiltInFunctionNames ? never : T, func: RuntimeFunction<(JSONValue | ExpressionNode)[], JSONValue>, signature: InputSignature[], options?: RegisterOptions): RegistrationResult;
|
|
225
|
+
/**
|
|
226
|
+
* Unregister a custom function (built-in functions cannot be unregistered)
|
|
227
|
+
*/
|
|
228
|
+
unregister<T extends string>(name: T extends BuiltInFunctionNames ? never : T): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Check if a function is registered
|
|
231
|
+
*/
|
|
232
|
+
isRegistered(name: string): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Get list of all registered function names
|
|
235
|
+
*/
|
|
236
|
+
getRegistered(): string[];
|
|
237
|
+
/**
|
|
238
|
+
* Get list of custom (non-built-in) function names
|
|
239
|
+
*/
|
|
240
|
+
getCustomFunctions(): string[];
|
|
241
|
+
/**
|
|
242
|
+
* Clear all custom functions (built-in functions remain)
|
|
243
|
+
*/
|
|
244
|
+
clearCustomFunctions(): void;
|
|
245
|
+
}
|
|
246
|
+
declare class Runtime implements FunctionRegistry {
|
|
247
|
+
_interpreter: TreeInterpreter;
|
|
248
|
+
_functionTable: FunctionTable;
|
|
249
|
+
private _customFunctions;
|
|
250
|
+
TYPE_NAME_TABLE: Readonly<{
|
|
251
|
+
readonly 0: "number";
|
|
252
|
+
readonly 1: "any";
|
|
253
|
+
readonly 2: "string";
|
|
254
|
+
readonly 3: "array";
|
|
255
|
+
readonly 4: "object";
|
|
256
|
+
readonly 5: "boolean";
|
|
257
|
+
readonly 6: "expression";
|
|
258
|
+
readonly 7: "null";
|
|
259
|
+
readonly 8: "Array<number>";
|
|
260
|
+
readonly 10: "Array<object>";
|
|
261
|
+
readonly 9: "Array<string>";
|
|
262
|
+
readonly 11: "Array<Array<any>>";
|
|
263
|
+
}>;
|
|
264
|
+
constructor(interpreter: TreeInterpreter);
|
|
265
|
+
private buildFunctionTable;
|
|
266
|
+
/**
|
|
267
|
+
* Enhanced registerFunction with backward compatibility and new options
|
|
268
|
+
* @deprecated Use register() method for enhanced functionality
|
|
269
|
+
*/
|
|
270
|
+
registerFunction(name: string, customFunction: RuntimeFunction<(JSONValue | ExpressionNode)[], JSONValue>, signature: InputSignature[], options?: RegisterOptions): void;
|
|
271
|
+
/**
|
|
272
|
+
* Internal registration method that bypasses TypeScript type checking
|
|
273
|
+
*/
|
|
274
|
+
private _registerInternal;
|
|
275
|
+
/**
|
|
276
|
+
* Register a new function with enhanced options and type safety
|
|
277
|
+
*/
|
|
278
|
+
register<T extends string>(name: T extends BuiltInFunctionNames ? never : T, customFunction: RuntimeFunction<(JSONValue | ExpressionNode)[], JSONValue>, signature: InputSignature[], options?: RegisterOptions): RegistrationResult;
|
|
279
|
+
/**
|
|
280
|
+
* Unregister a custom function (built-in functions cannot be unregistered)
|
|
281
|
+
*/
|
|
282
|
+
unregister<T extends string>(name: T extends BuiltInFunctionNames ? never : T): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Check if a function is registered
|
|
285
|
+
*/
|
|
286
|
+
isRegistered(name: string): boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Get list of all registered function names
|
|
289
|
+
*/
|
|
290
|
+
getRegistered(): string[];
|
|
291
|
+
/**
|
|
292
|
+
* Get list of custom (non-built-in) function names
|
|
293
|
+
*/
|
|
294
|
+
getCustomFunctions(): string[];
|
|
295
|
+
/**
|
|
296
|
+
* Clear all custom functions (built-in functions remain)
|
|
297
|
+
*/
|
|
298
|
+
clearCustomFunctions(): void;
|
|
299
|
+
callFunction(name: string, resolvedArgs: (JSONValue | ExpressionNode)[]): JSONValue;
|
|
300
|
+
private validateInputSignatures;
|
|
301
|
+
private validateArgs;
|
|
302
|
+
private validateArity;
|
|
303
|
+
private validateTypes;
|
|
304
|
+
private typeMatches;
|
|
305
|
+
private getTypeName;
|
|
306
|
+
createKeyFunction(exprefNode: ExpressionNode, allowedTypes: InputArgument[]): (x: JSONValue) => JSONValue;
|
|
307
|
+
private functionAvg;
|
|
308
|
+
private functionContains;
|
|
309
|
+
private functionEndsWith;
|
|
310
|
+
private functionFindFirst;
|
|
311
|
+
private functionFindLast;
|
|
312
|
+
private createFindFunction;
|
|
313
|
+
private functionFromItems;
|
|
314
|
+
private functionGroupBy;
|
|
315
|
+
private functionItems;
|
|
316
|
+
private functionJoin;
|
|
317
|
+
private functionLength;
|
|
318
|
+
private functionMap;
|
|
319
|
+
private functionMax;
|
|
320
|
+
private functionMaxBy;
|
|
321
|
+
private functionMerge;
|
|
322
|
+
private functionMin;
|
|
323
|
+
private functionMinBy;
|
|
324
|
+
private functionNotNull;
|
|
325
|
+
private functionPadLeft;
|
|
326
|
+
private functionPadRight;
|
|
327
|
+
private createPadFunction;
|
|
328
|
+
private functionReplace;
|
|
329
|
+
private functionSplit;
|
|
330
|
+
private functionReverse;
|
|
331
|
+
private functionSort;
|
|
332
|
+
private functionSortBy;
|
|
333
|
+
private functionStartsWith;
|
|
334
|
+
private functionSum;
|
|
335
|
+
private functionToArray;
|
|
336
|
+
private functionToNumber;
|
|
337
|
+
private functionToString;
|
|
338
|
+
private functionTrim;
|
|
339
|
+
private functionTrimLeft;
|
|
340
|
+
private functionTrimRight;
|
|
341
|
+
private createTrimFunction;
|
|
342
|
+
private functionType;
|
|
343
|
+
private functionZip;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
declare class TreeInterpreter {
|
|
347
|
+
runtime: Runtime;
|
|
348
|
+
private _rootValue;
|
|
349
|
+
private _scope;
|
|
350
|
+
private _options?;
|
|
351
|
+
private _depth;
|
|
352
|
+
private _deadline;
|
|
353
|
+
constructor(options?: Options);
|
|
354
|
+
withScope(scope: ScopeEntry): TreeInterpreter;
|
|
355
|
+
search(node: ExpressionNode, value: JSONValue, options?: Options): JSONValue;
|
|
356
|
+
private checkOutputSize;
|
|
357
|
+
private collect;
|
|
358
|
+
private evaluateProjectionItems;
|
|
359
|
+
visit(node: ExpressionNode, value: JSONValue | ExpressionNode): JSONValue | ExpressionNode | ExpressionReference;
|
|
360
|
+
private evaluateNode;
|
|
361
|
+
computeSliceParams(arrayLength: number, sliceNode: SliceNode): {
|
|
362
|
+
start: number;
|
|
363
|
+
stop: number;
|
|
364
|
+
step: number;
|
|
365
|
+
};
|
|
366
|
+
capSliceRange(arrayLength: number, actualValue: number, step: number): number;
|
|
367
|
+
slice(collection: JSONArray, start: number, end: number, step: number): JSONArray;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
type NormalizePath<S extends string> = S extends `${infer Pre}[${infer Idx}]${infer Post}` ? NormalizePath<Pre extends '' ? `${Idx}${Post}` : `${Pre}.${Idx}${Post}`> : S;
|
|
371
|
+
type Split<S extends string> = S extends `${infer Head}.${infer Tail}` ? [Unquote<Head>, ...Split<Tail>] : [Unquote<S>];
|
|
372
|
+
type Unquote<S extends string> = S extends `"${infer Inner}"` ? Inner : S;
|
|
373
|
+
type IsSpecialExpression<P extends string> = P extends `${string}${'|' | '?' | '{' | '(' | '@' | '&' | '+' | '-' | '/' | '%' | '!'}${string}` ? true : false;
|
|
374
|
+
type ResolvePath<T, Segments extends string[]> = Segments extends [
|
|
375
|
+
infer Head extends string,
|
|
376
|
+
...infer Tail extends string[]
|
|
377
|
+
] ? Head extends '*' ? T extends (infer E)[] ? ResolvePath<E, Tail>[] : JSONValue : T extends (infer E)[] ? Head extends `${number}` ? ResolvePath<E, Tail> : JSONValue : T extends object ? Head extends keyof T ? undefined extends T[Head] ? ResolvePath<NonNullable<T[Head]>, Tail> | null : ResolvePath<NonNullable<T[Head]>, Tail> : JSONValue : JSONValue : T;
|
|
378
|
+
type PathValue<T, P extends string> = string extends P ? JSONValue : IsSpecialExpression<P> extends true ? JSONValue : ResolvePath<T, Split<NormalizePath<P>>>;
|
|
379
|
+
|
|
380
|
+
declare class ScopeChain {
|
|
381
|
+
private inner?;
|
|
382
|
+
private data;
|
|
383
|
+
get currentScopeData(): JSONObject;
|
|
384
|
+
withScope(data: JSONObject): ScopeChain;
|
|
385
|
+
getValue(identifier: string): JSONValue;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
type StreamSource<T = unknown> = AsyncIterable<T> | Iterable<T> | ReadableStream<T> | NodeJS.ReadableStream;
|
|
389
|
+
interface StreamOptions extends Options {
|
|
390
|
+
/**
|
|
391
|
+
* If true, splits string chunks by newline and parses each line as JSON.
|
|
392
|
+
* If 'auto', detects string lines that look like JSON objects/arrays.
|
|
393
|
+
* If false, does not parse string chunks.
|
|
394
|
+
* Defaults to 'auto'.
|
|
395
|
+
*/
|
|
396
|
+
parseJson?: boolean | 'auto';
|
|
397
|
+
/**
|
|
398
|
+
* If true, array chunks emitted by the stream are flattened so their elements
|
|
399
|
+
* are yielded individually.
|
|
400
|
+
* Defaults to true.
|
|
401
|
+
*/
|
|
402
|
+
flattenChunks?: boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Maximum number of results to yield before ending stream evaluation early.
|
|
405
|
+
*/
|
|
406
|
+
limit?: number;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Incremental Result Streaming evaluation.
|
|
410
|
+
* Evaluates a JMESPath expression incrementally over an AsyncIterable or ReadableStream source.
|
|
411
|
+
*/
|
|
412
|
+
declare function searchStream<T = JSONValue, D = unknown>(sourceOrExpression: StreamSource<D> | string | ExpressionNode, expressionOrSource: string | ExpressionNode | StreamSource<D>, options?: StreamOptions): AsyncGenerator<T, void, unknown>;
|
|
413
|
+
|
|
414
|
+
interface ValidationResult {
|
|
415
|
+
valid: boolean;
|
|
416
|
+
error?: string;
|
|
417
|
+
ast?: ExpressionNode;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
interface CompiledQuery<T = JSONValue, D = unknown> {
|
|
421
|
+
(data: D): T;
|
|
422
|
+
search: (data: D) => T;
|
|
423
|
+
searchStream: (source: StreamSource<D>, options?: StreamOptions) => AsyncGenerator<T, void, unknown>;
|
|
424
|
+
ast: ExpressionNode;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
declare function compile(expression: string, options?: Options): ExpressionNode;
|
|
428
|
+
declare function compileQuery<T = JSONValue, D = unknown>(expression: string, options?: Options): CompiledQuery<T, D>;
|
|
429
|
+
declare function validate(expression: string, options?: Options): ValidationResult;
|
|
430
|
+
declare function tokenize(expression: string, options?: LexerOptions): LexerToken[];
|
|
431
|
+
declare function search<T, P extends string>(data: T, expression: P, options?: Options): PathValue<T, P>;
|
|
432
|
+
declare function search<T = JSONValue, D = unknown>(data: D, expression: string, options?: Options): T;
|
|
433
|
+
declare function Scope(): ScopeChain;
|
|
434
|
+
declare const jmespath: {
|
|
435
|
+
compile: typeof compile;
|
|
436
|
+
compileQuery: typeof compileQuery;
|
|
437
|
+
searchStream: typeof searchStream;
|
|
438
|
+
validate: typeof validate;
|
|
439
|
+
registerFunction: (functionName: string, customFunction: RuntimeFunction<(JSONValue | ExpressionNode)[], JSONValue>, signature: InputSignature[], options?: RegisterOptions) => void;
|
|
440
|
+
register: <T extends string>(name: T extends BuiltInFunctionNames ? never : T, customFunction: RuntimeFunction<(JSONValue | ExpressionNode)[], JSONValue>, signature: InputSignature[], options?: RegisterOptions) => RegistrationResult;
|
|
441
|
+
unregisterFunction: <T extends string>(name: T extends BuiltInFunctionNames ? never : T) => boolean;
|
|
442
|
+
isRegistered: (name: string) => boolean;
|
|
443
|
+
getRegisteredFunctions: () => string[];
|
|
444
|
+
getCustomFunctions: () => string[];
|
|
445
|
+
clearCustomFunctions: () => void;
|
|
446
|
+
search: typeof search;
|
|
447
|
+
tokenize: typeof tokenize;
|
|
448
|
+
TreeInterpreter: TreeInterpreter;
|
|
449
|
+
TYPE_ANY: InputArgument;
|
|
450
|
+
TYPE_ARRAY_NUMBER: InputArgument;
|
|
451
|
+
TYPE_ARRAY_STRING: InputArgument;
|
|
452
|
+
TYPE_ARRAY: InputArgument;
|
|
453
|
+
TYPE_BOOLEAN: InputArgument;
|
|
454
|
+
TYPE_EXPREF: InputArgument;
|
|
455
|
+
TYPE_NULL: InputArgument;
|
|
456
|
+
TYPE_NUMBER: InputArgument;
|
|
457
|
+
TYPE_OBJECT: InputArgument;
|
|
458
|
+
TYPE_STRING: InputArgument;
|
|
459
|
+
TYPE_ARRAY_ARRAY: InputArgument;
|
|
460
|
+
TYPE_ARRAY_OBJECT: InputArgument;
|
|
461
|
+
Scope: typeof Scope;
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
export { type BuiltInFunctionNames, type CompiledQuery, type FunctionRegistry, type FunctionSignature, type InputSignature, type JSONArray, type JSONObject, type JSONPrimitive, type JSONValue, type Options, type PathValue, type RegisterOptions, type RegistrationResult, type RuntimeFunction, type StreamOptions, type StreamSource, type ValidationResult, jmespath as default };
|