@gabrielbryk/jq-ts 1.1.0 → 1.3.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/dist/index.cjs +2403 -737
- package/dist/index.d.cts +171 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +171 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2403 -737
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -33
package/dist/index.d.cts
CHANGED
|
@@ -1,56 +1,97 @@
|
|
|
1
1
|
//#region src/span.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Represents a range of characters in the source text.
|
|
4
|
+
*/
|
|
2
5
|
interface Span {
|
|
3
6
|
start: number;
|
|
4
7
|
end: number;
|
|
5
8
|
}
|
|
6
9
|
//#endregion
|
|
7
10
|
//#region src/ast.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Represents a literal value in the jq AST.
|
|
13
|
+
* Can be null, boolean, number, or string.
|
|
14
|
+
*/
|
|
8
15
|
type LiteralValue = null | boolean | number | string;
|
|
16
|
+
/**
|
|
17
|
+
* Represents the identity filter `.`
|
|
18
|
+
* Returns the input unchanged.
|
|
19
|
+
*/
|
|
9
20
|
interface IdentityNode {
|
|
10
21
|
kind: 'Identity';
|
|
11
22
|
span: Span;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents a literal value filter (e.g., `1`, `"hello"`, `true`, `null`).
|
|
26
|
+
* Outputs the literal value, ignoring the input.
|
|
27
|
+
*/
|
|
13
28
|
interface LiteralNode {
|
|
14
29
|
kind: 'Literal';
|
|
15
30
|
value: LiteralValue;
|
|
16
31
|
span: Span;
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Represents a variable reference (e.g., `$v`).
|
|
35
|
+
*/
|
|
18
36
|
interface VarNode {
|
|
19
37
|
kind: 'Var';
|
|
20
38
|
name: string;
|
|
21
39
|
span: Span;
|
|
22
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Represents field access using dot notation (e.g., `.foo`).
|
|
43
|
+
*/
|
|
23
44
|
interface FieldAccessNode {
|
|
24
45
|
kind: 'FieldAccess';
|
|
25
46
|
target: FilterNode;
|
|
26
47
|
field: string;
|
|
27
48
|
span: Span;
|
|
28
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents index access (e.g., `.[0]`, `.["foo"]`).
|
|
52
|
+
*/
|
|
29
53
|
interface IndexAccessNode {
|
|
30
54
|
kind: 'IndexAccess';
|
|
31
55
|
target: FilterNode;
|
|
32
56
|
index: FilterNode;
|
|
33
57
|
span: Span;
|
|
34
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Represents an iterator (e.g., `.[]`).
|
|
61
|
+
* Iterates over the values of an array or object.
|
|
62
|
+
*/
|
|
35
63
|
interface IterateNode {
|
|
36
64
|
kind: 'Iterate';
|
|
37
65
|
target: FilterNode;
|
|
38
66
|
span: Span;
|
|
39
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents an array construction (e.g., `[ .a, .b ]`).
|
|
70
|
+
*/
|
|
40
71
|
interface ArrayNode {
|
|
41
72
|
kind: 'Array';
|
|
42
73
|
items: FilterNode[];
|
|
43
74
|
span: Span;
|
|
44
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Represents an object entry in an object construction.
|
|
78
|
+
*/
|
|
45
79
|
interface ObjectEntry {
|
|
46
80
|
key: ObjectKey;
|
|
47
81
|
value: FilterNode;
|
|
48
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Represents an object construction (e.g., `{ a: 1, b: 2 }`).
|
|
85
|
+
*/
|
|
49
86
|
interface ObjectNode {
|
|
50
87
|
kind: 'Object';
|
|
51
88
|
entries: ObjectEntry[];
|
|
52
89
|
span: Span;
|
|
53
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents a key in an object construction.
|
|
93
|
+
* Can be a simple identifier, a string literal, or a parenthesized expression.
|
|
94
|
+
*/
|
|
54
95
|
type ObjectKey = {
|
|
55
96
|
kind: 'KeyIdentifier';
|
|
56
97
|
name: string;
|
|
@@ -64,30 +105,48 @@ type ObjectKey = {
|
|
|
64
105
|
expr: FilterNode;
|
|
65
106
|
span: Span;
|
|
66
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Represents the pipe operator `|`.
|
|
110
|
+
* Passes the output of the left filter as input to the right filter.
|
|
111
|
+
*/
|
|
67
112
|
interface PipeNode {
|
|
68
113
|
kind: 'Pipe';
|
|
69
114
|
left: FilterNode;
|
|
70
115
|
right: FilterNode;
|
|
71
116
|
span: Span;
|
|
72
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Represents the comma operator `,`.
|
|
120
|
+
* Outputs the results of the left filter followed by the results of the right filter.
|
|
121
|
+
*/
|
|
73
122
|
interface CommaNode {
|
|
74
123
|
kind: 'Comma';
|
|
75
124
|
left: FilterNode;
|
|
76
125
|
right: FilterNode;
|
|
77
126
|
span: Span;
|
|
78
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Represents the alternative operator `//`.
|
|
130
|
+
* If the left filter yields empty or false/null, runs the right filter.
|
|
131
|
+
*/
|
|
79
132
|
interface AltNode {
|
|
80
133
|
kind: 'Alt';
|
|
81
134
|
left: FilterNode;
|
|
82
135
|
right: FilterNode;
|
|
83
136
|
span: Span;
|
|
84
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Represents unary operators (e.g., `-`, `not`).
|
|
140
|
+
*/
|
|
85
141
|
interface UnaryNode {
|
|
86
142
|
kind: 'Unary';
|
|
87
143
|
op: 'Neg' | 'Not';
|
|
88
144
|
expr: FilterNode;
|
|
89
145
|
span: Span;
|
|
90
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Represents binary operators (arithmetic, comparison).
|
|
149
|
+
*/
|
|
91
150
|
interface BinaryNode {
|
|
92
151
|
kind: 'Binary';
|
|
93
152
|
op: '+' | '-' | '*' | '/' | '%' | 'Eq' | 'Neq' | 'Lt' | 'Lte' | 'Gt' | 'Gte';
|
|
@@ -95,6 +154,10 @@ interface BinaryNode {
|
|
|
95
154
|
right: FilterNode;
|
|
96
155
|
span: Span;
|
|
97
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Represents boolean binary operators (`and`, `or`).
|
|
159
|
+
* These have short-circuiting behavior.
|
|
160
|
+
*/
|
|
98
161
|
interface BoolNode {
|
|
99
162
|
kind: 'Bool';
|
|
100
163
|
op: 'And' | 'Or';
|
|
@@ -106,12 +169,20 @@ interface IfBranch {
|
|
|
106
169
|
cond: FilterNode;
|
|
107
170
|
then: FilterNode;
|
|
108
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Represents an if-then-else expression within jq.
|
|
174
|
+
* `if cond then true_branch else false_branch end`
|
|
175
|
+
*/
|
|
109
176
|
interface IfNode {
|
|
110
177
|
kind: 'If';
|
|
111
178
|
branches: IfBranch[];
|
|
112
179
|
else: FilterNode;
|
|
113
180
|
span: Span;
|
|
114
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Represents a variable binding expression.
|
|
184
|
+
* `expression as $var | body`
|
|
185
|
+
*/
|
|
115
186
|
interface AsNode {
|
|
116
187
|
kind: 'As';
|
|
117
188
|
bind: FilterNode;
|
|
@@ -119,12 +190,20 @@ interface AsNode {
|
|
|
119
190
|
body: FilterNode;
|
|
120
191
|
span: Span;
|
|
121
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Represents a function call.
|
|
195
|
+
* `funcname(arg1; arg2)`
|
|
196
|
+
*/
|
|
122
197
|
interface CallNode {
|
|
123
198
|
kind: 'Call';
|
|
124
199
|
name: string;
|
|
125
200
|
args: FilterNode[];
|
|
126
201
|
span: Span;
|
|
127
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Represents the `reduce` expression.
|
|
205
|
+
* `reduce inputs as $var (init; update)`
|
|
206
|
+
*/
|
|
128
207
|
interface ReduceNode {
|
|
129
208
|
kind: 'Reduce';
|
|
130
209
|
source: FilterNode;
|
|
@@ -133,6 +212,10 @@ interface ReduceNode {
|
|
|
133
212
|
update: FilterNode;
|
|
134
213
|
span: Span;
|
|
135
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Represents the `foreach` expression.
|
|
217
|
+
* `foreach inputs as $var (init; update; extract)`
|
|
218
|
+
*/
|
|
136
219
|
interface ForeachNode {
|
|
137
220
|
kind: 'Foreach';
|
|
138
221
|
source: FilterNode;
|
|
@@ -142,17 +225,80 @@ interface ForeachNode {
|
|
|
142
225
|
extract?: FilterNode;
|
|
143
226
|
span: Span;
|
|
144
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Represents a `try-catch` expression.
|
|
230
|
+
* `try body catch handler` or `try body` (handler is null)
|
|
231
|
+
*/
|
|
145
232
|
interface TryNode {
|
|
146
233
|
kind: 'Try';
|
|
147
234
|
body: FilterNode;
|
|
148
235
|
handler?: FilterNode;
|
|
149
236
|
span: Span;
|
|
150
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Represents the `recurse` builtin when used as a node (deprecated/internal mainly, usually Call).
|
|
240
|
+
* KEPT FOR COMPATIBILITY/Internal use.
|
|
241
|
+
*/
|
|
151
242
|
interface RecurseNode {
|
|
152
243
|
kind: 'Recurse';
|
|
153
244
|
span: Span;
|
|
154
245
|
}
|
|
155
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Represents assignment operators (e.g., `=`, `|=`, `+=`).
|
|
248
|
+
*/
|
|
249
|
+
interface AssignmentNode {
|
|
250
|
+
kind: 'Assignment';
|
|
251
|
+
op: '=' | '|=' | '+=' | '-=' | '*=' | '/=' | '%=' | '//=';
|
|
252
|
+
left: FilterNode;
|
|
253
|
+
right: FilterNode;
|
|
254
|
+
span: Span;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Represents a function definition.
|
|
258
|
+
* `def name(args): body; next`
|
|
259
|
+
*/
|
|
260
|
+
interface DefNode {
|
|
261
|
+
kind: 'Def';
|
|
262
|
+
name: string;
|
|
263
|
+
args: string[];
|
|
264
|
+
body: FilterNode;
|
|
265
|
+
next: FilterNode;
|
|
266
|
+
span: Span;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Represents a named label for breaking.
|
|
270
|
+
* `label $out | ... break $out ...`
|
|
271
|
+
*/
|
|
272
|
+
interface LabelNode {
|
|
273
|
+
kind: 'Label';
|
|
274
|
+
label: string;
|
|
275
|
+
body: FilterNode;
|
|
276
|
+
span: Span;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Represents a break statement targeting a label.
|
|
280
|
+
* `break $out`
|
|
281
|
+
*/
|
|
282
|
+
interface BreakNode {
|
|
283
|
+
kind: 'Break';
|
|
284
|
+
label: string;
|
|
285
|
+
span: Span;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Represents an array slice operation.
|
|
289
|
+
* `.[start:end]`
|
|
290
|
+
*/
|
|
291
|
+
interface SliceNode {
|
|
292
|
+
kind: 'Slice';
|
|
293
|
+
target: FilterNode;
|
|
294
|
+
start: FilterNode | null;
|
|
295
|
+
end: FilterNode | null;
|
|
296
|
+
span: Span;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Union of all possible AST nodes in the jq syntax tree.
|
|
300
|
+
*/
|
|
301
|
+
type FilterNode = IdentityNode | LiteralNode | VarNode | FieldAccessNode | IndexAccessNode | IterateNode | ArrayNode | ObjectNode | PipeNode | CommaNode | AltNode | UnaryNode | BinaryNode | BoolNode | IfNode | AsNode | AssignmentNode | CallNode | ReduceNode | ForeachNode | TryNode | RecurseNode | DefNode | LabelNode | BreakNode | SliceNode;
|
|
156
302
|
//#endregion
|
|
157
303
|
//#region src/parser.d.ts
|
|
158
304
|
/**
|
|
@@ -251,11 +397,33 @@ interface ValueObject {
|
|
|
251
397
|
[key: string]: Value;
|
|
252
398
|
}
|
|
253
399
|
//#endregion
|
|
254
|
-
//#region src/eval.d.ts
|
|
400
|
+
//#region src/eval/types.d.ts
|
|
401
|
+
/**
|
|
402
|
+
* Options passed to the evaluator.
|
|
403
|
+
*/
|
|
255
404
|
interface EvalOptions {
|
|
256
405
|
limits?: LimitsConfig;
|
|
257
406
|
}
|
|
258
|
-
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/eval/dispatch.d.ts
|
|
409
|
+
/**
|
|
410
|
+
* Configuration options for the evaluation engine.
|
|
411
|
+
*/
|
|
412
|
+
interface EvalOptions$1 {
|
|
413
|
+
/**
|
|
414
|
+
* Limit configuration to prevent infinite loops or excessive resource usage.
|
|
415
|
+
*/
|
|
416
|
+
limits?: LimitsConfig;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Runs a jq AST against an input value.
|
|
420
|
+
*
|
|
421
|
+
* @param ast - The parsed AST.
|
|
422
|
+
* @param input - The initial input value (JSON).
|
|
423
|
+
* @param options - Execution options.
|
|
424
|
+
* @returns An array of all values yielded by the filter.
|
|
425
|
+
*/
|
|
426
|
+
declare const runAst: (ast: FilterNode, input: Value, options?: EvalOptions$1) => Value[];
|
|
259
427
|
//#endregion
|
|
260
428
|
//#region src/errors.d.ts
|
|
261
429
|
/**
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/span.ts","../src/ast.ts","../src/parser.ts","../src/validate.ts","../src/limits.ts","../src/value.ts","../src/eval.ts","../src/errors.ts","../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/span.ts","../src/ast.ts","../src/parser.ts","../src/validate.ts","../src/limits.ts","../src/value.ts","../src/eval/types.ts","../src/eval/dispatch.ts","../src/errors.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;AAGA;;UAAiB,IAAA;;ECGL,GAAA,EAAA,MAAA;AAMZ;;;ADTA;;;;ACGY,KAAA,YAAA,GAAY,IAAA,GAAA,OAAA,GAAA,MAAA,GAAA,MAAA;AAMxB;AASA;AASA;AASA;AA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ea;EAC4B,IAAA,EO1EzC,IP0EyC;EACH,WAAA,CAAA,IAAA,EOzE1B,SPyE0B,EAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EOzEQ,IPyER;;;;AAO9C;AAEQ,cOtEK,QAAA,SAAiB,SAAA,CPsEtB;EACC,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EOtE4B,IPsE5B;;;AAQT;;AAGS,cOzEI,UAAA,SAAmB,SAAA,CPyEvB;EACD,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EOzE6B,IPyE7B;;AAOR;;;AAIQ,cO5EK,eAAA,SAAwB,SAAA,CP4E7B;EAAI,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EO3EyB,IP2EzB;AAMZ;AAUA;;;AAKQ,cOxFK,YAAA,SAAqB,SAAA,CPwF1B;EAAI,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EOvFyB,IPuFzB;AAOZ;;;AAxHA;AAUA;;;;;AAWA;AASA;AASA;AAQA;AAUA;;AAE8C,cQ3EjC,GR2EiC,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EQ3EH,KR2EG,EAAA,OAAA,CAAA,EQ3Ea,WR2Eb,EAAA,GQ3EgC,KR2EhC,EAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,56 +1,97 @@
|
|
|
1
1
|
//#region src/span.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Represents a range of characters in the source text.
|
|
4
|
+
*/
|
|
2
5
|
interface Span {
|
|
3
6
|
start: number;
|
|
4
7
|
end: number;
|
|
5
8
|
}
|
|
6
9
|
//#endregion
|
|
7
10
|
//#region src/ast.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Represents a literal value in the jq AST.
|
|
13
|
+
* Can be null, boolean, number, or string.
|
|
14
|
+
*/
|
|
8
15
|
type LiteralValue = null | boolean | number | string;
|
|
16
|
+
/**
|
|
17
|
+
* Represents the identity filter `.`
|
|
18
|
+
* Returns the input unchanged.
|
|
19
|
+
*/
|
|
9
20
|
interface IdentityNode {
|
|
10
21
|
kind: 'Identity';
|
|
11
22
|
span: Span;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents a literal value filter (e.g., `1`, `"hello"`, `true`, `null`).
|
|
26
|
+
* Outputs the literal value, ignoring the input.
|
|
27
|
+
*/
|
|
13
28
|
interface LiteralNode {
|
|
14
29
|
kind: 'Literal';
|
|
15
30
|
value: LiteralValue;
|
|
16
31
|
span: Span;
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Represents a variable reference (e.g., `$v`).
|
|
35
|
+
*/
|
|
18
36
|
interface VarNode {
|
|
19
37
|
kind: 'Var';
|
|
20
38
|
name: string;
|
|
21
39
|
span: Span;
|
|
22
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Represents field access using dot notation (e.g., `.foo`).
|
|
43
|
+
*/
|
|
23
44
|
interface FieldAccessNode {
|
|
24
45
|
kind: 'FieldAccess';
|
|
25
46
|
target: FilterNode;
|
|
26
47
|
field: string;
|
|
27
48
|
span: Span;
|
|
28
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents index access (e.g., `.[0]`, `.["foo"]`).
|
|
52
|
+
*/
|
|
29
53
|
interface IndexAccessNode {
|
|
30
54
|
kind: 'IndexAccess';
|
|
31
55
|
target: FilterNode;
|
|
32
56
|
index: FilterNode;
|
|
33
57
|
span: Span;
|
|
34
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Represents an iterator (e.g., `.[]`).
|
|
61
|
+
* Iterates over the values of an array or object.
|
|
62
|
+
*/
|
|
35
63
|
interface IterateNode {
|
|
36
64
|
kind: 'Iterate';
|
|
37
65
|
target: FilterNode;
|
|
38
66
|
span: Span;
|
|
39
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents an array construction (e.g., `[ .a, .b ]`).
|
|
70
|
+
*/
|
|
40
71
|
interface ArrayNode {
|
|
41
72
|
kind: 'Array';
|
|
42
73
|
items: FilterNode[];
|
|
43
74
|
span: Span;
|
|
44
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Represents an object entry in an object construction.
|
|
78
|
+
*/
|
|
45
79
|
interface ObjectEntry {
|
|
46
80
|
key: ObjectKey;
|
|
47
81
|
value: FilterNode;
|
|
48
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Represents an object construction (e.g., `{ a: 1, b: 2 }`).
|
|
85
|
+
*/
|
|
49
86
|
interface ObjectNode {
|
|
50
87
|
kind: 'Object';
|
|
51
88
|
entries: ObjectEntry[];
|
|
52
89
|
span: Span;
|
|
53
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents a key in an object construction.
|
|
93
|
+
* Can be a simple identifier, a string literal, or a parenthesized expression.
|
|
94
|
+
*/
|
|
54
95
|
type ObjectKey = {
|
|
55
96
|
kind: 'KeyIdentifier';
|
|
56
97
|
name: string;
|
|
@@ -64,30 +105,48 @@ type ObjectKey = {
|
|
|
64
105
|
expr: FilterNode;
|
|
65
106
|
span: Span;
|
|
66
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Represents the pipe operator `|`.
|
|
110
|
+
* Passes the output of the left filter as input to the right filter.
|
|
111
|
+
*/
|
|
67
112
|
interface PipeNode {
|
|
68
113
|
kind: 'Pipe';
|
|
69
114
|
left: FilterNode;
|
|
70
115
|
right: FilterNode;
|
|
71
116
|
span: Span;
|
|
72
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Represents the comma operator `,`.
|
|
120
|
+
* Outputs the results of the left filter followed by the results of the right filter.
|
|
121
|
+
*/
|
|
73
122
|
interface CommaNode {
|
|
74
123
|
kind: 'Comma';
|
|
75
124
|
left: FilterNode;
|
|
76
125
|
right: FilterNode;
|
|
77
126
|
span: Span;
|
|
78
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Represents the alternative operator `//`.
|
|
130
|
+
* If the left filter yields empty or false/null, runs the right filter.
|
|
131
|
+
*/
|
|
79
132
|
interface AltNode {
|
|
80
133
|
kind: 'Alt';
|
|
81
134
|
left: FilterNode;
|
|
82
135
|
right: FilterNode;
|
|
83
136
|
span: Span;
|
|
84
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Represents unary operators (e.g., `-`, `not`).
|
|
140
|
+
*/
|
|
85
141
|
interface UnaryNode {
|
|
86
142
|
kind: 'Unary';
|
|
87
143
|
op: 'Neg' | 'Not';
|
|
88
144
|
expr: FilterNode;
|
|
89
145
|
span: Span;
|
|
90
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Represents binary operators (arithmetic, comparison).
|
|
149
|
+
*/
|
|
91
150
|
interface BinaryNode {
|
|
92
151
|
kind: 'Binary';
|
|
93
152
|
op: '+' | '-' | '*' | '/' | '%' | 'Eq' | 'Neq' | 'Lt' | 'Lte' | 'Gt' | 'Gte';
|
|
@@ -95,6 +154,10 @@ interface BinaryNode {
|
|
|
95
154
|
right: FilterNode;
|
|
96
155
|
span: Span;
|
|
97
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Represents boolean binary operators (`and`, `or`).
|
|
159
|
+
* These have short-circuiting behavior.
|
|
160
|
+
*/
|
|
98
161
|
interface BoolNode {
|
|
99
162
|
kind: 'Bool';
|
|
100
163
|
op: 'And' | 'Or';
|
|
@@ -106,12 +169,20 @@ interface IfBranch {
|
|
|
106
169
|
cond: FilterNode;
|
|
107
170
|
then: FilterNode;
|
|
108
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Represents an if-then-else expression within jq.
|
|
174
|
+
* `if cond then true_branch else false_branch end`
|
|
175
|
+
*/
|
|
109
176
|
interface IfNode {
|
|
110
177
|
kind: 'If';
|
|
111
178
|
branches: IfBranch[];
|
|
112
179
|
else: FilterNode;
|
|
113
180
|
span: Span;
|
|
114
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Represents a variable binding expression.
|
|
184
|
+
* `expression as $var | body`
|
|
185
|
+
*/
|
|
115
186
|
interface AsNode {
|
|
116
187
|
kind: 'As';
|
|
117
188
|
bind: FilterNode;
|
|
@@ -119,12 +190,20 @@ interface AsNode {
|
|
|
119
190
|
body: FilterNode;
|
|
120
191
|
span: Span;
|
|
121
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Represents a function call.
|
|
195
|
+
* `funcname(arg1; arg2)`
|
|
196
|
+
*/
|
|
122
197
|
interface CallNode {
|
|
123
198
|
kind: 'Call';
|
|
124
199
|
name: string;
|
|
125
200
|
args: FilterNode[];
|
|
126
201
|
span: Span;
|
|
127
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Represents the `reduce` expression.
|
|
205
|
+
* `reduce inputs as $var (init; update)`
|
|
206
|
+
*/
|
|
128
207
|
interface ReduceNode {
|
|
129
208
|
kind: 'Reduce';
|
|
130
209
|
source: FilterNode;
|
|
@@ -133,6 +212,10 @@ interface ReduceNode {
|
|
|
133
212
|
update: FilterNode;
|
|
134
213
|
span: Span;
|
|
135
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Represents the `foreach` expression.
|
|
217
|
+
* `foreach inputs as $var (init; update; extract)`
|
|
218
|
+
*/
|
|
136
219
|
interface ForeachNode {
|
|
137
220
|
kind: 'Foreach';
|
|
138
221
|
source: FilterNode;
|
|
@@ -142,17 +225,80 @@ interface ForeachNode {
|
|
|
142
225
|
extract?: FilterNode;
|
|
143
226
|
span: Span;
|
|
144
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Represents a `try-catch` expression.
|
|
230
|
+
* `try body catch handler` or `try body` (handler is null)
|
|
231
|
+
*/
|
|
145
232
|
interface TryNode {
|
|
146
233
|
kind: 'Try';
|
|
147
234
|
body: FilterNode;
|
|
148
235
|
handler?: FilterNode;
|
|
149
236
|
span: Span;
|
|
150
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Represents the `recurse` builtin when used as a node (deprecated/internal mainly, usually Call).
|
|
240
|
+
* KEPT FOR COMPATIBILITY/Internal use.
|
|
241
|
+
*/
|
|
151
242
|
interface RecurseNode {
|
|
152
243
|
kind: 'Recurse';
|
|
153
244
|
span: Span;
|
|
154
245
|
}
|
|
155
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Represents assignment operators (e.g., `=`, `|=`, `+=`).
|
|
248
|
+
*/
|
|
249
|
+
interface AssignmentNode {
|
|
250
|
+
kind: 'Assignment';
|
|
251
|
+
op: '=' | '|=' | '+=' | '-=' | '*=' | '/=' | '%=' | '//=';
|
|
252
|
+
left: FilterNode;
|
|
253
|
+
right: FilterNode;
|
|
254
|
+
span: Span;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Represents a function definition.
|
|
258
|
+
* `def name(args): body; next`
|
|
259
|
+
*/
|
|
260
|
+
interface DefNode {
|
|
261
|
+
kind: 'Def';
|
|
262
|
+
name: string;
|
|
263
|
+
args: string[];
|
|
264
|
+
body: FilterNode;
|
|
265
|
+
next: FilterNode;
|
|
266
|
+
span: Span;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Represents a named label for breaking.
|
|
270
|
+
* `label $out | ... break $out ...`
|
|
271
|
+
*/
|
|
272
|
+
interface LabelNode {
|
|
273
|
+
kind: 'Label';
|
|
274
|
+
label: string;
|
|
275
|
+
body: FilterNode;
|
|
276
|
+
span: Span;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Represents a break statement targeting a label.
|
|
280
|
+
* `break $out`
|
|
281
|
+
*/
|
|
282
|
+
interface BreakNode {
|
|
283
|
+
kind: 'Break';
|
|
284
|
+
label: string;
|
|
285
|
+
span: Span;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Represents an array slice operation.
|
|
289
|
+
* `.[start:end]`
|
|
290
|
+
*/
|
|
291
|
+
interface SliceNode {
|
|
292
|
+
kind: 'Slice';
|
|
293
|
+
target: FilterNode;
|
|
294
|
+
start: FilterNode | null;
|
|
295
|
+
end: FilterNode | null;
|
|
296
|
+
span: Span;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Union of all possible AST nodes in the jq syntax tree.
|
|
300
|
+
*/
|
|
301
|
+
type FilterNode = IdentityNode | LiteralNode | VarNode | FieldAccessNode | IndexAccessNode | IterateNode | ArrayNode | ObjectNode | PipeNode | CommaNode | AltNode | UnaryNode | BinaryNode | BoolNode | IfNode | AsNode | AssignmentNode | CallNode | ReduceNode | ForeachNode | TryNode | RecurseNode | DefNode | LabelNode | BreakNode | SliceNode;
|
|
156
302
|
//#endregion
|
|
157
303
|
//#region src/parser.d.ts
|
|
158
304
|
/**
|
|
@@ -251,11 +397,33 @@ interface ValueObject {
|
|
|
251
397
|
[key: string]: Value;
|
|
252
398
|
}
|
|
253
399
|
//#endregion
|
|
254
|
-
//#region src/eval.d.ts
|
|
400
|
+
//#region src/eval/types.d.ts
|
|
401
|
+
/**
|
|
402
|
+
* Options passed to the evaluator.
|
|
403
|
+
*/
|
|
255
404
|
interface EvalOptions {
|
|
256
405
|
limits?: LimitsConfig;
|
|
257
406
|
}
|
|
258
|
-
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/eval/dispatch.d.ts
|
|
409
|
+
/**
|
|
410
|
+
* Configuration options for the evaluation engine.
|
|
411
|
+
*/
|
|
412
|
+
interface EvalOptions$1 {
|
|
413
|
+
/**
|
|
414
|
+
* Limit configuration to prevent infinite loops or excessive resource usage.
|
|
415
|
+
*/
|
|
416
|
+
limits?: LimitsConfig;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Runs a jq AST against an input value.
|
|
420
|
+
*
|
|
421
|
+
* @param ast - The parsed AST.
|
|
422
|
+
* @param input - The initial input value (JSON).
|
|
423
|
+
* @param options - Execution options.
|
|
424
|
+
* @returns An array of all values yielded by the filter.
|
|
425
|
+
*/
|
|
426
|
+
declare const runAst: (ast: FilterNode, input: Value, options?: EvalOptions$1) => Value[];
|
|
259
427
|
//#endregion
|
|
260
428
|
//#region src/errors.d.ts
|
|
261
429
|
/**
|