@jarenjs/json 0.9.2

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 (57) hide show
  1. package/ARCHITECTURE.md +175 -0
  2. package/LICENSE +21 -0
  3. package/README.md +471 -0
  4. package/dist/types/basic.d.ts +32 -0
  5. package/dist/types/index.d.ts +4 -0
  6. package/dist/types/jslt/dispatch.d.ts +11 -0
  7. package/dist/types/jslt/errors.d.ts +18 -0
  8. package/dist/types/jslt/index.d.ts +53 -0
  9. package/dist/types/jslt/stylesheet.d.ts +8 -0
  10. package/dist/types/jtlt/desugar.d.ts +19 -0
  11. package/dist/types/jtlt/errors.d.ts +18 -0
  12. package/dist/types/jtlt/index.d.ts +57 -0
  13. package/dist/types/jtlt/template.d.ts +8 -0
  14. package/dist/types/jtlt/writer.d.ts +6 -0
  15. package/dist/types/path.d.ts +235 -0
  16. package/dist/types/pointer.d.ts +114 -0
  17. package/dist/types/query/compile.d.ts +21 -0
  18. package/dist/types/query/errors.d.ts +18 -0
  19. package/dist/types/query/index.d.ts +70 -0
  20. package/dist/types/query/normalize.d.ts +68 -0
  21. package/dist/types/query/operators.d.ts +424 -0
  22. package/dist/types/query/runtime.d.ts +93 -0
  23. package/dist/types/segments.d.ts +62 -0
  24. package/dist/types/xquery/index.d.ts +19 -0
  25. package/dist/types/xquery/parse.d.ts +20 -0
  26. package/docs/JSLT-FORMAT.md +861 -0
  27. package/docs/JSLT-PRELUDE.md +159 -0
  28. package/docs/JTLT-FORMAT.md +659 -0
  29. package/docs/QUERY-FORMAT.md +1221 -0
  30. package/docs/XQUERY-FRONTEND.md +321 -0
  31. package/package.json +81 -0
  32. package/schemas/jaren-jslt.draft-07.schema.json +776 -0
  33. package/schemas/jaren-jslt.schema.json +776 -0
  34. package/schemas/jaren-query.draft-07.schema.json +613 -0
  35. package/schemas/jaren-query.schema.json +375 -0
  36. package/src/basic.js +300 -0
  37. package/src/index.js +4 -0
  38. package/src/jslt/dispatch.js +934 -0
  39. package/src/jslt/errors.js +34 -0
  40. package/src/jslt/index.js +121 -0
  41. package/src/jslt/stylesheet.js +234 -0
  42. package/src/jtlt/desugar.js +231 -0
  43. package/src/jtlt/errors.js +34 -0
  44. package/src/jtlt/index.js +155 -0
  45. package/src/jtlt/template.js +130 -0
  46. package/src/jtlt/writer.js +110 -0
  47. package/src/path.js +977 -0
  48. package/src/pointer.js +453 -0
  49. package/src/query/compile.js +817 -0
  50. package/src/query/errors.js +33 -0
  51. package/src/query/index.js +150 -0
  52. package/src/query/normalize.js +1047 -0
  53. package/src/query/operators.js +1253 -0
  54. package/src/query/runtime.js +233 -0
  55. package/src/segments.js +627 -0
  56. package/src/xquery/index.js +35 -0
  57. package/src/xquery/parse.js +1647 -0
@@ -0,0 +1,424 @@
1
+ import { EMPTY } from './runtime.js';
2
+ declare const RESULT_ONE: () => number;
3
+ declare const RESULT_OPT: () => number;
4
+ declare const RESULT_MANY: () => number;
5
+ declare const resultOfOperand: (cards: any) => any;
6
+ declare const resultEmptyPropagates: (cards: any) => 1 | 2;
7
+ declare function compileSeqOp(gets: any, args: any): any;
8
+ declare function compileReplace(gets: any, args: any): (f: any) => string;
9
+ /**
10
+ * The complete v0.1 operator vocabulary (QUERY-FORMAT.md section 8), one
11
+ * entry per operator: `{ params, result, compile }` (see the module
12
+ * comment for the descriptor contract). Frozen; the closed vocabulary is
13
+ * exactly the keys of this table plus the phrase keys and escape hatches
14
+ * handled by normalize.js.
15
+ */
16
+ export declare const OPERATORS: Readonly<{
17
+ $seq: {
18
+ params: Readonly<{
19
+ kinds: readonly string[];
20
+ min: 0;
21
+ variadic: true;
22
+ }>;
23
+ result: (cards: any) => number;
24
+ compile: typeof compileSeqOp;
25
+ };
26
+ $exists: {
27
+ params: string;
28
+ result: typeof RESULT_ONE;
29
+ compile: (gets: any, args: any) => (frame: any[]) => boolean;
30
+ };
31
+ $empty: {
32
+ params: string;
33
+ result: typeof RESULT_ONE;
34
+ compile: (gets: any, args: any) => (f: any) => boolean;
35
+ };
36
+ $if: {
37
+ params: Readonly<{
38
+ kinds: readonly string[];
39
+ min: 2;
40
+ }>;
41
+ result: (cards: any) => number;
42
+ compile: (gets: any, args: any) => (f: any) => any;
43
+ };
44
+ $eq: {
45
+ params: Readonly<{
46
+ kinds: readonly string[];
47
+ min: 2;
48
+ }>;
49
+ result: typeof RESULT_ONE;
50
+ compile: (gets: any, args: any) => (f: any) => any;
51
+ };
52
+ $ne: {
53
+ params: Readonly<{
54
+ kinds: readonly string[];
55
+ min: 2;
56
+ }>;
57
+ result: typeof RESULT_ONE;
58
+ compile: (gets: any, args: any) => (f: any) => any;
59
+ };
60
+ $lt: {
61
+ params: Readonly<{
62
+ kinds: readonly string[];
63
+ min: 2;
64
+ }>;
65
+ result: typeof RESULT_ONE;
66
+ compile: (gets: any, args: any) => (f: any) => any;
67
+ };
68
+ $le: {
69
+ params: Readonly<{
70
+ kinds: readonly string[];
71
+ min: 2;
72
+ }>;
73
+ result: typeof RESULT_ONE;
74
+ compile: (gets: any, args: any) => (f: any) => any;
75
+ };
76
+ $gt: {
77
+ params: Readonly<{
78
+ kinds: readonly string[];
79
+ min: 2;
80
+ }>;
81
+ result: typeof RESULT_ONE;
82
+ compile: (gets: any, args: any) => (f: any) => any;
83
+ };
84
+ $ge: {
85
+ params: Readonly<{
86
+ kinds: readonly string[];
87
+ min: 2;
88
+ }>;
89
+ result: typeof RESULT_ONE;
90
+ compile: (gets: any, args: any) => (f: any) => any;
91
+ };
92
+ $add: {
93
+ params: Readonly<{
94
+ kinds: readonly string[];
95
+ min: 2;
96
+ }>;
97
+ result: (cards: any) => 1 | 2;
98
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
99
+ };
100
+ $sub: {
101
+ params: Readonly<{
102
+ kinds: readonly string[];
103
+ min: 2;
104
+ }>;
105
+ result: (cards: any) => 1 | 2;
106
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
107
+ };
108
+ $mul: {
109
+ params: Readonly<{
110
+ kinds: readonly string[];
111
+ min: 2;
112
+ }>;
113
+ result: (cards: any) => 1 | 2;
114
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
115
+ };
116
+ $div: {
117
+ params: Readonly<{
118
+ kinds: readonly string[];
119
+ min: 2;
120
+ }>;
121
+ result: (cards: any) => 1 | 2;
122
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
123
+ };
124
+ $idiv: {
125
+ params: Readonly<{
126
+ kinds: readonly string[];
127
+ min: 2;
128
+ }>;
129
+ result: (cards: any) => 1 | 2;
130
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
131
+ };
132
+ $mod: {
133
+ params: Readonly<{
134
+ kinds: readonly string[];
135
+ min: 2;
136
+ }>;
137
+ result: (cards: any) => 1 | 2;
138
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
139
+ };
140
+ $neg: {
141
+ params: string;
142
+ result: typeof resultEmptyPropagates;
143
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
144
+ };
145
+ $and: {
146
+ params: Readonly<{
147
+ kinds: readonly string[];
148
+ min: 1;
149
+ variadic: true;
150
+ }>;
151
+ result: typeof RESULT_ONE;
152
+ compile: (gets: any, args: any) => (f: any) => any;
153
+ };
154
+ $or: {
155
+ params: Readonly<{
156
+ kinds: readonly string[];
157
+ min: 1;
158
+ variadic: true;
159
+ }>;
160
+ result: typeof RESULT_ONE;
161
+ compile: (gets: any, args: any) => (f: any) => any;
162
+ };
163
+ $not: {
164
+ params: string;
165
+ result: typeof RESULT_ONE;
166
+ compile: (gets: any, args: any) => (f: any) => boolean;
167
+ };
168
+ $concat: {
169
+ params: Readonly<{
170
+ kinds: readonly string[];
171
+ min: 0;
172
+ variadic: true;
173
+ }>;
174
+ result: typeof RESULT_ONE;
175
+ compile: (gets: any, args: any) => (f: any) => string;
176
+ };
177
+ '$string-join': {
178
+ params: Readonly<{
179
+ kinds: readonly string[];
180
+ min: 1;
181
+ }>;
182
+ result: typeof RESULT_ONE;
183
+ compile: (gets: any, args: any) => (f: any) => string;
184
+ };
185
+ $substring: {
186
+ params: Readonly<{
187
+ kinds: readonly string[];
188
+ min: 2;
189
+ }>;
190
+ result: typeof RESULT_ONE;
191
+ compile: (gets: any, args: any) => (f: any) => string;
192
+ };
193
+ $contains: {
194
+ params: Readonly<{
195
+ kinds: readonly string[];
196
+ min: 2;
197
+ }>;
198
+ result: typeof RESULT_ONE;
199
+ compile: (gets: any, args: any) => (f: any) => any;
200
+ };
201
+ '$starts-with': {
202
+ params: Readonly<{
203
+ kinds: readonly string[];
204
+ min: 2;
205
+ }>;
206
+ result: typeof RESULT_ONE;
207
+ compile: (gets: any, args: any) => (f: any) => any;
208
+ };
209
+ '$ends-with': {
210
+ params: Readonly<{
211
+ kinds: readonly string[];
212
+ min: 2;
213
+ }>;
214
+ result: typeof RESULT_ONE;
215
+ compile: (gets: any, args: any) => (f: any) => any;
216
+ };
217
+ $upper: {
218
+ params: string;
219
+ result: typeof RESULT_ONE;
220
+ compile: (gets: any, args: any) => (f: any) => any;
221
+ };
222
+ $lower: {
223
+ params: string;
224
+ result: typeof RESULT_ONE;
225
+ compile: (gets: any, args: any) => (f: any) => any;
226
+ };
227
+ '$string-length': {
228
+ params: string;
229
+ result: typeof RESULT_ONE;
230
+ compile: (gets: any, args: any) => (f: any) => any;
231
+ };
232
+ '$normalize-space': {
233
+ params: string;
234
+ result: typeof RESULT_ONE;
235
+ compile: (gets: any, args: any) => (f: any) => any;
236
+ };
237
+ $match: {
238
+ params: Readonly<{
239
+ kinds: readonly string[];
240
+ min: 2;
241
+ }>;
242
+ result: typeof RESULT_ONE;
243
+ compile: (gets: any, args: any) => (f: any) => any;
244
+ };
245
+ $search: {
246
+ params: Readonly<{
247
+ kinds: readonly string[];
248
+ min: 2;
249
+ }>;
250
+ result: typeof RESULT_ONE;
251
+ compile: (gets: any, args: any) => (f: any) => any;
252
+ };
253
+ $replace: {
254
+ params: Readonly<{
255
+ kinds: readonly string[];
256
+ min: 3;
257
+ }>;
258
+ result: typeof RESULT_ONE;
259
+ compile: typeof compileReplace;
260
+ };
261
+ $count: {
262
+ params: string;
263
+ result: typeof RESULT_ONE;
264
+ compile: (gets: any) => (f: any) => number;
265
+ };
266
+ $sum: {
267
+ params: string;
268
+ result: typeof RESULT_ONE;
269
+ compile: (gets: any, args: any) => (f: any) => number;
270
+ };
271
+ $avg: {
272
+ params: string;
273
+ result: typeof resultEmptyPropagates;
274
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
275
+ };
276
+ $min: {
277
+ params: string;
278
+ result: typeof resultEmptyPropagates;
279
+ compile: (gets: any, args: any) => (f: any) => any;
280
+ };
281
+ $max: {
282
+ params: string;
283
+ result: typeof resultEmptyPropagates;
284
+ compile: (gets: any, args: any) => (f: any) => any;
285
+ };
286
+ $distinct: {
287
+ params: string;
288
+ result: typeof resultOfOperand;
289
+ compile: (gets: any) => (f: any) => any;
290
+ };
291
+ $reverse: {
292
+ params: string;
293
+ result: typeof resultOfOperand;
294
+ compile: (gets: any) => (f: any) => any;
295
+ };
296
+ $sort: {
297
+ params: string;
298
+ result: typeof resultOfOperand;
299
+ compile: (gets: any, args: any) => (f: any) => any;
300
+ };
301
+ $head: {
302
+ params: string;
303
+ result: (cards: any) => any;
304
+ compile: (gets: any) => (f: any) => any;
305
+ };
306
+ $tail: {
307
+ params: string;
308
+ result: (cards: any) => 0 | 3;
309
+ compile: (gets: any) => (f: any) => any;
310
+ };
311
+ $subsequence: {
312
+ params: Readonly<{
313
+ kinds: readonly string[];
314
+ min: 2;
315
+ }>;
316
+ result: (cards: any) => 0 | 2 | 3;
317
+ compile: (gets: any, args: any) => (f: any) => any;
318
+ };
319
+ '$index-of': {
320
+ params: Readonly<{
321
+ kinds: readonly string[];
322
+ min: 2;
323
+ }>;
324
+ result: (cards: any) => 0 | 2 | 3;
325
+ compile: (gets: any, args: any) => (f: any) => any;
326
+ };
327
+ $range: {
328
+ params: Readonly<{
329
+ kinds: readonly string[];
330
+ min: 2;
331
+ }>;
332
+ result: typeof RESULT_MANY;
333
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
334
+ };
335
+ $get: {
336
+ params: Readonly<{
337
+ kinds: readonly string[];
338
+ min: 2;
339
+ }>;
340
+ result: typeof RESULT_OPT;
341
+ compile: (gets: any) => (f: any) => any;
342
+ };
343
+ '$is-string': {
344
+ params: string;
345
+ result: typeof RESULT_ONE;
346
+ compile: (gets: any) => (f: any) => any;
347
+ };
348
+ '$is-number': {
349
+ params: string;
350
+ result: typeof RESULT_ONE;
351
+ compile: (gets: any) => (f: any) => any;
352
+ };
353
+ '$is-boolean': {
354
+ params: string;
355
+ result: typeof RESULT_ONE;
356
+ compile: (gets: any) => (f: any) => any;
357
+ };
358
+ '$is-null': {
359
+ params: string;
360
+ result: typeof RESULT_ONE;
361
+ compile: (gets: any) => (f: any) => any;
362
+ };
363
+ '$is-array': {
364
+ params: string;
365
+ result: typeof RESULT_ONE;
366
+ compile: (gets: any) => (f: any) => any;
367
+ };
368
+ '$is-object': {
369
+ params: string;
370
+ result: typeof RESULT_ONE;
371
+ compile: (gets: any) => (f: any) => any;
372
+ };
373
+ $string: {
374
+ params: string;
375
+ result: typeof resultEmptyPropagates;
376
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
377
+ };
378
+ $number: {
379
+ params: string;
380
+ result: typeof resultEmptyPropagates;
381
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
382
+ };
383
+ $boolean: {
384
+ params: string;
385
+ result: typeof RESULT_ONE;
386
+ compile: (gets: any, args: any) => (f: any) => boolean;
387
+ };
388
+ $coalesce: {
389
+ params: Readonly<{
390
+ kinds: readonly string[];
391
+ min: 1;
392
+ variadic: true;
393
+ }>;
394
+ result: typeof coalesceCard;
395
+ compile: typeof compileCoalesce;
396
+ };
397
+ $default: {
398
+ params: Readonly<{
399
+ kinds: readonly string[];
400
+ min: 2;
401
+ }>;
402
+ result: typeof coalesceCard;
403
+ compile: typeof compileCoalesce;
404
+ };
405
+ $valid: {
406
+ params: Readonly<{
407
+ kinds: readonly string[];
408
+ min: 2;
409
+ }>;
410
+ result: typeof RESULT_ONE;
411
+ compile: (gets: any, args: any) => (f: any) => any;
412
+ };
413
+ $assert: {
414
+ params: Readonly<{
415
+ kinds: readonly string[];
416
+ min: 2;
417
+ }>;
418
+ result: typeof resultOfOperand;
419
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
420
+ };
421
+ }>;
422
+ declare function coalesceCard(cards: any): 0 | 1 | 2 | 3;
423
+ declare function compileCoalesce(gets: any): any;
424
+ export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The empty sequence `()` (same singleton-sentinel pattern as
3
+ * `JSONPATH_NOTHING`).
4
+ */
5
+ export declare const EMPTY: unique symbol;
6
+ /**
7
+ * A sequence of two or more items. Never constructed directly by
8
+ * operator code - use `seqOf` so the flatness invariant holds.
9
+ */
10
+ export declare class Seq {
11
+ items: any;
12
+ constructor(items: any);
13
+ }
14
+ /**
15
+ * Build a sequence value from a flat accumulator array of items.
16
+ * Returns EMPTY for zero items, the raw item for one, a Seq otherwise.
17
+ * The array is adopted, not copied; callers hand over ownership.
18
+ * @param {any[]} items - flat array of items (no Seq, no EMPTY inside)
19
+ * @returns {any} EMPTY, a single item, or a Seq
20
+ */
21
+ export declare function seqOf(items: any[]): any;
22
+ /**
23
+ * Append a sequence value's items to a plain accumulator array
24
+ * (the shared flattening step of array constructors and `$seq`).
25
+ * @param {any[]} list - accumulator array of items
26
+ * @param {any} v - a sequence value (EMPTY, item, or Seq)
27
+ */
28
+ export declare function appendItem(list: any[], v: any): void;
29
+ /**
30
+ * Invoke `fn(item)` for each item of a sequence value, in order.
31
+ * @param {any} v - a sequence value (EMPTY, item, or Seq)
32
+ * @param {(item: any) => void} fn
33
+ */
34
+ export declare function forEachItem(v: any, fn: (item: any) => void): void;
35
+ /**
36
+ * Number of items in a sequence value.
37
+ * @param {any} v - a sequence value (EMPTY, item, or Seq)
38
+ * @returns {number}
39
+ */
40
+ export declare function itemCount(v: any): number;
41
+ /**
42
+ * First item of a sequence value, or EMPTY for the empty sequence.
43
+ * @param {any} v - a sequence value (EMPTY, item, or Seq)
44
+ * @returns {any}
45
+ */
46
+ export declare function firstItem(v: any): any;
47
+ /**
48
+ * Effective boolean value of a sequence value per the EBV table of
49
+ * QUERY-FORMAT.md section 2.2 (D3: singleton array/object is true).
50
+ * @param {any} v - a sequence value (EMPTY, item, or Seq)
51
+ * @param {string} docPath - RFC 6901 pointer for the JQ2003 error
52
+ * @returns {boolean}
53
+ * @throws {JsonQueryRuntimeError} JQ2003 on a sequence of two or more items
54
+ */
55
+ export declare function ebv(v: any, docPath: string): boolean;
56
+ /**
57
+ * Describe a sequence value for a runtime error message (non-normative,
58
+ * human-readable).
59
+ * @param {any} v - a sequence value (EMPTY, item, or Seq)
60
+ * @returns {string}
61
+ */
62
+ export declare function describeItem(v: any): string;
63
+ /**
64
+ * Deterministic serialization of one JSON item, for `$groupby` keys
65
+ * (QUERY-FORMAT.md section 6.5) — **engine-internal**, not an interchange
66
+ * format (related to the roadmap's canonical-JSON item). It exists solely
67
+ * so that deep-equal items (D2) map to the same string:
68
+ *
69
+ * - object members serialize sorted by key (code-unit order), so key
70
+ * order never matters;
71
+ * - `-0` normalizes to `0` (D2: `-0` equals `0`);
72
+ * - strings serialize via `JSON.stringify` (its escape discipline means
73
+ * no raw control character ever appears in the output, so a control
74
+ * character is safe as a composite-key separator);
75
+ * - numbers serialize bare via `String(n)` — `NaN` and `±Infinity`
76
+ * (reachable through `$div`) serialize as `NaN`/`Infinity`, which
77
+ * cannot collide with quoted strings. Note this makes `NaN` group
78
+ * with `NaN`, the XQuery grouping rule, even though `NaN` never
79
+ * equals itself under `$eq`.
80
+ *
81
+ * @param {any} value - a JSON item (not EMPTY, not a Seq)
82
+ * @returns {string} a deterministic serialization for grouping
83
+ */
84
+ export declare function stableKeyString(value: any): string;
85
+ /**
86
+ * Debug-only invariant check: asserts a sequence value is well-formed
87
+ * (a Seq holds 2+ items and contains no nested Seq or EMPTY). Used by
88
+ * tests; never called on hot paths.
89
+ * @param {any} v - a sequence value to check
90
+ * @returns {any} v itself when well-formed
91
+ * @throws {Error} when the flatness invariant is violated
92
+ */
93
+ export declare function assertSeqInvariant(v: any): any;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Sentinel for the absence of a value ("Nothing" in RFC 9535 terms), as
3
+ * distinct from the JSON value `null`. Re-exported from path.js as
4
+ * `JSONPATH_NOTHING`.
5
+ */
6
+ export declare const NOTHING: unique symbol;
7
+ /**
8
+ * Returns true when every segment is a child segment with exactly one
9
+ * name or index selector (a "singular query", RFC 9535 section 2.3.5.1).
10
+ * @param {object[]} segments - Parsed query segments
11
+ * @returns {boolean}
12
+ */
13
+ export declare function isSingularSegments(segments: object[]): boolean;
14
+ /**
15
+ * Compile a singular query into a direct property walk.
16
+ * @returns {(current: any, root: any) => any} getter returning the value or NOTHING
17
+ */
18
+ export declare function compileSingularGetter(segments: any, relative: any): (current: any, root: any) => any;
19
+ /**
20
+ * Run a chain of compiled value-mode segment functions over a start value.
21
+ * @returns {any[]} the resulting nodelist as an array of values
22
+ */
23
+ export declare function runSegmentsV(segs: any, start: any, root: any): any[];
24
+ /**
25
+ * Compile an existence test for a filter query; singular queries never
26
+ * materialize nodelists.
27
+ * @returns {(current: any, root: any) => boolean}
28
+ */
29
+ export declare function compileExists(query: any): (current: any, root: any) => boolean;
30
+ /**
31
+ * Compile a filter logical expression to a predicate.
32
+ * @returns {(current: any, root: any) => boolean}
33
+ */
34
+ export declare function compileLogicalExpr(expr: any): (current: any, root: any) => boolean;
35
+ export declare function compileSelectorNodeV(sel: any): (v: any, out: any, root: any) => void;
36
+ export declare function descendV(v: any, output: any, root: any, apply: any): void;
37
+ export declare function compileSegmentV(seg: any): (input: any, output: any, root: any) => void;
38
+ export declare const RE_NAME_NEEDS_ESCAPE: RegExp;
39
+ /**
40
+ * Escape a member name for use inside a normalized path name selector
41
+ * (RFC 9535 section 2.7).
42
+ */
43
+ export declare function escapeNormalizedName(name: any): any;
44
+ export declare function appendName(path: any, name: any): string;
45
+ export declare function compileSelectorNodeP(sel: any): (v: any, p: any, outV: any, outP: any, root: any) => void;
46
+ export declare function descendP(v: any, p: any, outV: any, outP: any, root: any, apply: any): void;
47
+ export declare function compileSegmentP(seg: any): (inV: any, inP: any, outV: any, outP: any, root: any) => void;
48
+ /**
49
+ * Run a chain of compiled nodes-mode segment functions over a start
50
+ * value, threading normalized paths alongside values.
51
+ * @param {Function[]} segs - segment functions from compileSegmentP
52
+ * @param {any} startValue - the value the first segment applies to
53
+ * @param {string} startPath - the base normalized path of startValue
54
+ * (`'$'` for the document root)
55
+ * @param {any} root - the query root (`$` inside embedded filters)
56
+ * @returns {{ vals: any[], paths: string[] }} parallel arrays of the
57
+ * resulting nodelist's values and normalized paths
58
+ */
59
+ export declare function runSegmentsP(segs: Function[], startValue: any, startPath: string, root: any): {
60
+ vals: any[];
61
+ paths: string[];
62
+ };
@@ -0,0 +1,19 @@
1
+ export { parseXQuery, XQuerySyntaxError } from './parse.js';
2
+ /**
3
+ * Parse XQuery text and compile the resulting query document in one call.
4
+ * Returns the engine's compiled query function (see `compileJsonQuery`):
5
+ * `query(data, externals?)` plus the `first`/`exists`/`externals`/`doc`
6
+ * helpers - `doc` holds the emitted query document.
7
+ * @param {string} text - XQuery text in the supported subset
8
+ * @param {object} [options] - passed through to `compileJsonQuery`
9
+ * @returns {function} the compiled query function
10
+ * @throws {XQuerySyntaxError} when the text is invalid or outside the subset
11
+ * @throws {import('../query/errors.js').JsonQueryCompileError} when the
12
+ * emitted document is rejected by the compiler (e.g. duplicate variable
13
+ * bindings, JQ0007)
14
+ * @example
15
+ * const q = compileXQuery('for $b in $doc?store?book?* where $b?price lt 10 return $b?title');
16
+ * q.externals; // ['doc']
17
+ * q(null, { doc: data }); // ['Sayings of the Century', 'Moby Dick']
18
+ */
19
+ export declare function compileXQuery(text: string, options?: object): Function;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Error thrown when XQuery text is not valid for the supported subset -
3
+ * either invalid XQuery 3.1 syntax or a recognized construct outside the
4
+ * subset (mirrors JSONPathSyntaxError: `source` and `position` locate the
5
+ * offending token).
6
+ */
7
+ export declare class XQuerySyntaxError extends SyntaxError {
8
+ source: any;
9
+ position: any;
10
+ constructor(message: any, source: any, position: any);
11
+ }
12
+ /**
13
+ * Parse XQuery 3.1 text (the supported subset, see XQUERY-FRONTEND.md)
14
+ * into a Jaren JSON Query document.
15
+ * @param {string} source - the XQuery text (e.g. `for $b in $doc?store?book?* return $b?title`)
16
+ * @returns {any} a valid query document for `compileJsonQuery` (envelope omitted)
17
+ * @throws {XQuerySyntaxError} when the text is invalid or uses a construct
18
+ * outside the subset (named `unsupported ...` messages)
19
+ */
20
+ export declare function parseXQuery(source: string): any;