@jarenjs/json 0.9.2 → 0.34.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 (74) hide show
  1. package/ARCHITECTURE.md +86 -13
  2. package/README.md +248 -23
  3. package/dist/types/canonical.d.ts +37 -0
  4. package/dist/types/cow.d.ts +28 -0
  5. package/dist/types/errors.d.ts +45 -0
  6. package/dist/types/index.d.ts +3 -0
  7. package/dist/types/jslt/errors.d.ts +15 -8
  8. package/dist/types/jslt/index.d.ts +22 -0
  9. package/dist/types/jslt/packs/finance.d.ts +119 -0
  10. package/dist/types/jslt/packs/index.d.ts +310 -0
  11. package/dist/types/jslt/packs/math.d.ts +159 -0
  12. package/dist/types/jslt/packs/stats.d.ts +48 -0
  13. package/dist/types/jslt/registry.d.ts +65 -0
  14. package/dist/types/jtlt/errors.d.ts +3 -6
  15. package/dist/types/option-variants.d.ts +29 -0
  16. package/dist/types/patch.d.ts +214 -0
  17. package/dist/types/path.d.ts +139 -9
  18. package/dist/types/pointer.d.ts +100 -9
  19. package/dist/types/query/compile.d.ts +12 -0
  20. package/dist/types/query/errors.d.ts +72 -8
  21. package/dist/types/query/index.d.ts +317 -25
  22. package/dist/types/query/normalize.d.ts +24 -0
  23. package/dist/types/query/operators.d.ts +241 -1
  24. package/dist/types/query/runtime.d.ts +5 -8
  25. package/dist/types/query/types.d.ts +34 -0
  26. package/dist/types/segments.d.ts +31 -0
  27. package/dist/types/write.d.ts +204 -0
  28. package/dist/types/xquery/parse.d.ts +2 -3
  29. package/docs/JSLT-FORMAT.md +74 -3
  30. package/docs/JSLT-PRELUDE.md +1 -1
  31. package/docs/QUERY-FORMAT.md +695 -33
  32. package/package.json +18 -4
  33. package/schemas/geojson.draft-07.schema.json +323 -0
  34. package/schemas/geojson.jaren.schema.json +863 -0
  35. package/schemas/geojson.schema.json +172 -0
  36. package/schemas/jaren-jslt.authoring.schema.json +142 -0
  37. package/schemas/jaren-jslt.draft-07.schema.json +152 -11
  38. package/schemas/jaren-jslt.llm-profile.schema.json +782 -0
  39. package/schemas/jaren-jslt.schema.json +152 -11
  40. package/schemas/jaren-query.draft-07.schema.json +152 -11
  41. package/schemas/jaren-query.llm-profile.schema.json +619 -0
  42. package/schemas/jaren-query.schema.json +82 -15
  43. package/src/basic.js +1 -1
  44. package/src/canonical.js +170 -0
  45. package/src/cow.js +106 -0
  46. package/src/errors.js +68 -0
  47. package/src/index.js +3 -0
  48. package/src/jslt/dispatch.js +178 -28
  49. package/src/jslt/errors.js +19 -14
  50. package/src/jslt/index.js +37 -29
  51. package/src/jslt/packs/finance.js +49 -0
  52. package/src/jslt/packs/index.js +18 -0
  53. package/src/jslt/packs/math.js +46 -0
  54. package/src/jslt/packs/stats.js +65 -0
  55. package/src/jslt/registry.js +200 -0
  56. package/src/jslt/stylesheet.js +14 -23
  57. package/src/jtlt/desugar.js +2 -3
  58. package/src/jtlt/errors.js +6 -12
  59. package/src/jtlt/index.js +12 -29
  60. package/src/jtlt/template.js +9 -18
  61. package/src/option-variants.js +54 -0
  62. package/src/patch.js +1052 -0
  63. package/src/path.js +319 -52
  64. package/src/pointer.js +225 -44
  65. package/src/query/compile.js +790 -75
  66. package/src/query/errors.js +72 -12
  67. package/src/query/index.js +274 -42
  68. package/src/query/normalize.js +489 -78
  69. package/src/query/operators.js +620 -23
  70. package/src/query/runtime.js +5 -19
  71. package/src/query/types.js +213 -0
  72. package/src/segments.js +409 -64
  73. package/src/write.js +660 -0
  74. package/src/xquery/parse.js +37 -53
@@ -4,8 +4,23 @@ declare const RESULT_OPT: () => number;
4
4
  declare const RESULT_MANY: () => number;
5
5
  declare const resultOfOperand: (cards: any) => any;
6
6
  declare const resultEmptyPropagates: (cards: any) => 1 | 2;
7
+ declare const RT_BOOLEAN: () => string;
8
+ declare const RT_NUMBER: () => string;
9
+ declare const RT_INTEGER: () => string;
10
+ declare const RT_STRING: () => string;
11
+ declare const RT_MINMAX: (types: any) => "number" | "string" | null;
7
12
  declare function compileSeqOp(gets: any, args: any): any;
8
13
  declare function compileReplace(gets: any, args: any): (f: any) => string;
14
+ /**
15
+ * Check one evaluated `$range` bound. Shared with the compiler's
16
+ * iteration fast path (compile.js), so a range that is iterated rather
17
+ * than materialized still rejects exactly the same bounds.
18
+ * @param {any} v - an evaluated bound
19
+ * @param {string} docPath - the bound's document pointer
20
+ * @returns {number} the bound
21
+ * @throws {JsonQueryRuntimeError} JQ2001 when it is not an integer
22
+ */
23
+ export declare function checkRangeBound(v: any, docPath: string): number;
9
24
  /**
10
25
  * The complete v0.1 operator vocabulary (QUERY-FORMAT.md section 8), one
11
26
  * entry per operator: `{ params, result, compile }` (see the module
@@ -47,6 +62,7 @@ export declare const OPERATORS: Readonly<{
47
62
  min: 2;
48
63
  }>;
49
64
  result: typeof RESULT_ONE;
65
+ resultType: typeof RT_BOOLEAN;
50
66
  compile: (gets: any, args: any) => (f: any) => any;
51
67
  };
52
68
  $ne: {
@@ -55,6 +71,7 @@ export declare const OPERATORS: Readonly<{
55
71
  min: 2;
56
72
  }>;
57
73
  result: typeof RESULT_ONE;
74
+ resultType: typeof RT_BOOLEAN;
58
75
  compile: (gets: any, args: any) => (f: any) => any;
59
76
  };
60
77
  $lt: {
@@ -63,6 +80,7 @@ export declare const OPERATORS: Readonly<{
63
80
  min: 2;
64
81
  }>;
65
82
  result: typeof RESULT_ONE;
83
+ resultType: typeof RT_BOOLEAN;
66
84
  compile: (gets: any, args: any) => (f: any) => any;
67
85
  };
68
86
  $le: {
@@ -71,6 +89,7 @@ export declare const OPERATORS: Readonly<{
71
89
  min: 2;
72
90
  }>;
73
91
  result: typeof RESULT_ONE;
92
+ resultType: typeof RT_BOOLEAN;
74
93
  compile: (gets: any, args: any) => (f: any) => any;
75
94
  };
76
95
  $gt: {
@@ -79,6 +98,7 @@ export declare const OPERATORS: Readonly<{
79
98
  min: 2;
80
99
  }>;
81
100
  result: typeof RESULT_ONE;
101
+ resultType: typeof RT_BOOLEAN;
82
102
  compile: (gets: any, args: any) => (f: any) => any;
83
103
  };
84
104
  $ge: {
@@ -87,6 +107,7 @@ export declare const OPERATORS: Readonly<{
87
107
  min: 2;
88
108
  }>;
89
109
  result: typeof RESULT_ONE;
110
+ resultType: typeof RT_BOOLEAN;
90
111
  compile: (gets: any, args: any) => (f: any) => any;
91
112
  };
92
113
  $add: {
@@ -95,6 +116,7 @@ export declare const OPERATORS: Readonly<{
95
116
  min: 2;
96
117
  }>;
97
118
  result: (cards: any) => 1 | 2;
119
+ resultType: typeof RT_NUMBER;
98
120
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
99
121
  };
100
122
  $sub: {
@@ -103,6 +125,7 @@ export declare const OPERATORS: Readonly<{
103
125
  min: 2;
104
126
  }>;
105
127
  result: (cards: any) => 1 | 2;
128
+ resultType: typeof RT_NUMBER;
106
129
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
107
130
  };
108
131
  $mul: {
@@ -111,6 +134,7 @@ export declare const OPERATORS: Readonly<{
111
134
  min: 2;
112
135
  }>;
113
136
  result: (cards: any) => 1 | 2;
137
+ resultType: typeof RT_NUMBER;
114
138
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
115
139
  };
116
140
  $div: {
@@ -119,6 +143,7 @@ export declare const OPERATORS: Readonly<{
119
143
  min: 2;
120
144
  }>;
121
145
  result: (cards: any) => 1 | 2;
146
+ resultType: typeof RT_NUMBER;
122
147
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
123
148
  };
124
149
  $idiv: {
@@ -127,6 +152,7 @@ export declare const OPERATORS: Readonly<{
127
152
  min: 2;
128
153
  }>;
129
154
  result: (cards: any) => 1 | 2;
155
+ resultType: typeof RT_NUMBER;
130
156
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
131
157
  };
132
158
  $mod: {
@@ -135,6 +161,7 @@ export declare const OPERATORS: Readonly<{
135
161
  min: 2;
136
162
  }>;
137
163
  result: (cards: any) => 1 | 2;
164
+ resultType: typeof RT_NUMBER;
138
165
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
139
166
  };
140
167
  $neg: {
@@ -172,6 +199,7 @@ export declare const OPERATORS: Readonly<{
172
199
  variadic: true;
173
200
  }>;
174
201
  result: typeof RESULT_ONE;
202
+ resultType: typeof RT_STRING;
175
203
  compile: (gets: any, args: any) => (f: any) => string;
176
204
  };
177
205
  '$string-join': {
@@ -180,6 +208,7 @@ export declare const OPERATORS: Readonly<{
180
208
  min: 1;
181
209
  }>;
182
210
  result: typeof RESULT_ONE;
211
+ resultType: typeof RT_STRING;
183
212
  compile: (gets: any, args: any) => (f: any) => string;
184
213
  };
185
214
  $substring: {
@@ -188,6 +217,7 @@ export declare const OPERATORS: Readonly<{
188
217
  min: 2;
189
218
  }>;
190
219
  result: typeof RESULT_ONE;
220
+ resultType: typeof RT_STRING;
191
221
  compile: (gets: any, args: any) => (f: any) => string;
192
222
  };
193
223
  $contains: {
@@ -196,6 +226,7 @@ export declare const OPERATORS: Readonly<{
196
226
  min: 2;
197
227
  }>;
198
228
  result: typeof RESULT_ONE;
229
+ resultType: typeof RT_BOOLEAN;
199
230
  compile: (gets: any, args: any) => (f: any) => any;
200
231
  };
201
232
  '$starts-with': {
@@ -204,6 +235,7 @@ export declare const OPERATORS: Readonly<{
204
235
  min: 2;
205
236
  }>;
206
237
  result: typeof RESULT_ONE;
238
+ resultType: typeof RT_BOOLEAN;
207
239
  compile: (gets: any, args: any) => (f: any) => any;
208
240
  };
209
241
  '$ends-with': {
@@ -212,26 +244,31 @@ export declare const OPERATORS: Readonly<{
212
244
  min: 2;
213
245
  }>;
214
246
  result: typeof RESULT_ONE;
247
+ resultType: typeof RT_BOOLEAN;
215
248
  compile: (gets: any, args: any) => (f: any) => any;
216
249
  };
217
250
  $upper: {
218
251
  params: string;
219
252
  result: typeof RESULT_ONE;
253
+ resultType: typeof RT_STRING;
220
254
  compile: (gets: any, args: any) => (f: any) => any;
221
255
  };
222
256
  $lower: {
223
257
  params: string;
224
258
  result: typeof RESULT_ONE;
259
+ resultType: typeof RT_STRING;
225
260
  compile: (gets: any, args: any) => (f: any) => any;
226
261
  };
227
262
  '$string-length': {
228
263
  params: string;
229
264
  result: typeof RESULT_ONE;
265
+ resultType: typeof RT_STRING;
230
266
  compile: (gets: any, args: any) => (f: any) => any;
231
267
  };
232
268
  '$normalize-space': {
233
269
  params: string;
234
270
  result: typeof RESULT_ONE;
271
+ resultType: typeof RT_STRING;
235
272
  compile: (gets: any, args: any) => (f: any) => any;
236
273
  };
237
274
  $match: {
@@ -240,6 +277,7 @@ export declare const OPERATORS: Readonly<{
240
277
  min: 2;
241
278
  }>;
242
279
  result: typeof RESULT_ONE;
280
+ resultType: typeof RT_BOOLEAN;
243
281
  compile: (gets: any, args: any) => (f: any) => any;
244
282
  };
245
283
  $search: {
@@ -248,6 +286,7 @@ export declare const OPERATORS: Readonly<{
248
286
  min: 2;
249
287
  }>;
250
288
  result: typeof RESULT_ONE;
289
+ resultType: typeof RT_BOOLEAN;
251
290
  compile: (gets: any, args: any) => (f: any) => any;
252
291
  };
253
292
  $replace: {
@@ -256,31 +295,37 @@ export declare const OPERATORS: Readonly<{
256
295
  min: 3;
257
296
  }>;
258
297
  result: typeof RESULT_ONE;
298
+ resultType: typeof RT_STRING;
259
299
  compile: typeof compileReplace;
260
300
  };
261
301
  $count: {
262
302
  params: string;
263
303
  result: typeof RESULT_ONE;
304
+ resultType: typeof RT_INTEGER;
264
305
  compile: (gets: any) => (f: any) => number;
265
306
  };
266
307
  $sum: {
267
308
  params: string;
268
309
  result: typeof RESULT_ONE;
310
+ resultType: typeof RT_NUMBER;
269
311
  compile: (gets: any, args: any) => (f: any) => number;
270
312
  };
271
313
  $avg: {
272
314
  params: string;
273
315
  result: typeof resultEmptyPropagates;
316
+ resultType: typeof RT_NUMBER;
274
317
  compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
275
318
  };
276
319
  $min: {
277
320
  params: string;
278
321
  result: typeof resultEmptyPropagates;
322
+ resultType: typeof RT_MINMAX;
279
323
  compile: (gets: any, args: any) => (f: any) => any;
280
324
  };
281
325
  $max: {
282
326
  params: string;
283
327
  result: typeof resultEmptyPropagates;
328
+ resultType: typeof RT_MINMAX;
284
329
  compile: (gets: any, args: any) => (f: any) => any;
285
330
  };
286
331
  $distinct: {
@@ -330,7 +375,7 @@ export declare const OPERATORS: Readonly<{
330
375
  min: 2;
331
376
  }>;
332
377
  result: typeof RESULT_MANY;
333
- compile: (gets: any, args: any, docPath: any) => (f: any) => any;
378
+ compile: (gets: any, args: any, docPath: any, node: any) => (f: any) => any;
334
379
  };
335
380
  $get: {
336
381
  params: Readonly<{
@@ -340,6 +385,16 @@ export declare const OPERATORS: Readonly<{
340
385
  result: typeof RESULT_OPT;
341
386
  compile: (gets: any) => (f: any) => any;
342
387
  };
388
+ $entries: {
389
+ params: string;
390
+ result: typeof RESULT_MANY;
391
+ compile: (gets: any) => (f: any) => any;
392
+ };
393
+ '$from-entries': {
394
+ params: string;
395
+ result: typeof RESULT_ONE;
396
+ compile: (gets: any) => (f: any) => Record<string, any>;
397
+ };
343
398
  '$is-string': {
344
399
  params: string;
345
400
  result: typeof RESULT_ONE;
@@ -418,6 +473,191 @@ export declare const OPERATORS: Readonly<{
418
473
  result: typeof resultOfOperand;
419
474
  compile: (gets: any, args: any, docPath: any) => (f: any) => any;
420
475
  };
476
+ '$is-date': {
477
+ params: string;
478
+ result: typeof RESULT_ONE;
479
+ compile: (gets: any) => (f: any) => any;
480
+ };
481
+ '$is-time': {
482
+ params: string;
483
+ result: typeof RESULT_ONE;
484
+ compile: (gets: any) => (f: any) => any;
485
+ };
486
+ '$is-datetime': {
487
+ params: string;
488
+ result: typeof RESULT_ONE;
489
+ compile: (gets: any) => (f: any) => any;
490
+ };
491
+ '$is-duration': {
492
+ params: string;
493
+ result: typeof RESULT_ONE;
494
+ compile: (gets: any) => (f: any) => any;
495
+ };
496
+ $bbox: {
497
+ params: string;
498
+ result: typeof resultEmptyPropagates;
499
+ compile: (gets: any, args: any) => (f: any) => any;
500
+ };
501
+ $area: {
502
+ params: string;
503
+ result: typeof resultEmptyPropagates;
504
+ compile: (gets: any, args: any) => (f: any) => any;
505
+ };
506
+ $length: {
507
+ params: string;
508
+ result: typeof resultEmptyPropagates;
509
+ compile: (gets: any, args: any) => (f: any) => any;
510
+ };
511
+ $centroid: {
512
+ params: string;
513
+ result: typeof resultEmptyPropagates;
514
+ compile: (gets: any, args: any) => (f: any) => any;
515
+ };
516
+ $distance: {
517
+ params: Readonly<{
518
+ kinds: readonly string[];
519
+ min: 2;
520
+ }>;
521
+ result: typeof RESULT_OPT;
522
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
523
+ };
524
+ $within: {
525
+ params: Readonly<{
526
+ kinds: readonly string[];
527
+ min: 2;
528
+ }>;
529
+ result: typeof RESULT_ONE;
530
+ compile: (gets: any, args: any) => (f: any) => boolean;
531
+ };
532
+ '$bbox-intersects': {
533
+ params: Readonly<{
534
+ kinds: readonly string[];
535
+ min: 2;
536
+ }>;
537
+ result: typeof RESULT_ONE;
538
+ compile: (gets: any, args: any) => (f: any) => boolean;
539
+ };
540
+ $geohash: {
541
+ params: Readonly<{
542
+ kinds: readonly string[];
543
+ min: 1;
544
+ }>;
545
+ result: typeof resultEmptyPropagates;
546
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
547
+ };
548
+ '$date-add': {
549
+ params: Readonly<{
550
+ kinds: readonly string[];
551
+ min: 2;
552
+ }>;
553
+ result: typeof resultEmptyPropagates;
554
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
555
+ };
556
+ '$date-sub': {
557
+ params: Readonly<{
558
+ kinds: readonly string[];
559
+ min: 2;
560
+ }>;
561
+ result: typeof resultEmptyPropagates;
562
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
563
+ };
564
+ '$start-of': {
565
+ params: Readonly<{
566
+ kinds: readonly string[];
567
+ min: 2;
568
+ }>;
569
+ result: typeof resultEmptyPropagates;
570
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
571
+ };
572
+ '$end-of': {
573
+ params: Readonly<{
574
+ kinds: readonly string[];
575
+ min: 2;
576
+ }>;
577
+ result: typeof resultEmptyPropagates;
578
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
579
+ };
580
+ '$date-diff': {
581
+ params: Readonly<{
582
+ kinds: readonly string[];
583
+ min: 3;
584
+ }>;
585
+ result: typeof resultEmptyPropagates;
586
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
587
+ };
588
+ '$date-format': {
589
+ params: Readonly<{
590
+ kinds: readonly string[];
591
+ min: 2;
592
+ }>;
593
+ result: typeof resultEmptyPropagates;
594
+ compile: (gets: any, args: any, docPath: any) => (f: any) => any;
595
+ };
596
+ $week: {
597
+ params: string;
598
+ result: typeof resultEmptyPropagates;
599
+ compile: (gets: any, args: any) => (f: any) => any;
600
+ };
601
+ '$week-year': {
602
+ params: string;
603
+ result: typeof resultEmptyPropagates;
604
+ compile: (gets: any, args: any) => (f: any) => any;
605
+ };
606
+ $quarter: {
607
+ params: string;
608
+ result: typeof resultEmptyPropagates;
609
+ compile: (gets: any, args: any) => (f: any) => any;
610
+ };
611
+ $weekday: {
612
+ params: string;
613
+ result: typeof resultEmptyPropagates;
614
+ compile: (gets: any, args: any) => (f: any) => any;
615
+ };
616
+ $year: {
617
+ params: string;
618
+ result: typeof resultEmptyPropagates;
619
+ compile: (gets: any, args: any) => (f: any) => any;
620
+ };
621
+ $month: {
622
+ params: string;
623
+ result: typeof resultEmptyPropagates;
624
+ compile: (gets: any, args: any) => (f: any) => any;
625
+ };
626
+ $day: {
627
+ params: string;
628
+ result: typeof resultEmptyPropagates;
629
+ compile: (gets: any, args: any) => (f: any) => any;
630
+ };
631
+ $hours: {
632
+ params: string;
633
+ result: typeof resultEmptyPropagates;
634
+ compile: (gets: any, args: any) => (f: any) => any;
635
+ };
636
+ $minutes: {
637
+ params: string;
638
+ result: typeof resultEmptyPropagates;
639
+ compile: (gets: any, args: any) => (f: any) => any;
640
+ };
641
+ $seconds: {
642
+ params: string;
643
+ result: typeof resultEmptyPropagates;
644
+ compile: (gets: any, args: any) => (f: any) => any;
645
+ };
646
+ $offset: {
647
+ params: string;
648
+ result: typeof RESULT_OPT;
649
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
650
+ };
651
+ $epoch: {
652
+ params: string;
653
+ result: typeof resultEmptyPropagates;
654
+ compile: (gets: any, args: any) => (f: any) => number | typeof EMPTY;
655
+ };
656
+ $datetime: {
657
+ params: string;
658
+ result: typeof resultEmptyPropagates;
659
+ compile: (gets: any, args: any) => (f: any) => string | typeof EMPTY;
660
+ };
421
661
  }>;
422
662
  declare function coalesceCard(cards: any): 0 | 1 | 2 | 3;
423
663
  declare function compileCoalesce(gets: any): any;
@@ -26,12 +26,6 @@ export declare function seqOf(items: any[]): any;
26
26
  * @param {any} v - a sequence value (EMPTY, item, or Seq)
27
27
  */
28
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
29
  /**
36
30
  * Number of items in a sequence value.
37
31
  * @param {any} v - a sequence value (EMPTY, item, or Seq)
@@ -63,8 +57,11 @@ export declare function describeItem(v: any): string;
63
57
  /**
64
58
  * Deterministic serialization of one JSON item, for `$groupby` keys
65
59
  * (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:
60
+ * format. For interchange (hashing, signing) use `canonicalizeJson`
61
+ * (canonical.js, RFC 8785), which is deliberately NOT this function: JCS
62
+ * rejects `NaN`/`Infinity` outright, where grouping needs them to be
63
+ * representable so that `NaN` groups with `NaN`. This exists solely so
64
+ * that deep-equal items (D2) map to the same string:
68
65
  *
69
66
  * - object members serialize sorted by key (code-unit order), so key
70
67
  * order never matters;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @file Optional type annotation over the published normalized form
3
+ * (QUERY-FORMAT.md Appendix C.8). The AST carries cardinality but no
4
+ * value types; a consumer that owns a type source — a store's JSON
5
+ * Schema, a model document — supplies `typeOf(pathNode)` and gets back
6
+ * a NEW frozen tree mirroring the input with a `type` tag on every
7
+ * node. The pass never mutates its input and never runs during
8
+ * compilation.
9
+ *
10
+ * The lattice is small and closed: `unknown` is the top and always a
11
+ * safe answer; a wrong tag is a defect. Operators propagate through the
12
+ * registry's declared `resultType` families (comparison, arithmetic,
13
+ * string, aggregate); everything undeclared yields `unknown` rather
14
+ * than a guess.
15
+ */
16
+ /** The closed set of type-tag names, sorted. */
17
+ export declare const TYPE_TAGS: readonly string[];
18
+ /**
19
+ * Annotate a normalized analysis with type tags (Appendix C.8): a NEW
20
+ * frozen analysis whose tree mirrors the input with `type` on every
21
+ * node. The input analysis and its tree are never mutated.
22
+ * @param {{ astVersion: number, root: any }} analysis - an
23
+ * `analyzeQuery` result (or any record carrying the frozen `root`)
24
+ * @param {{ typeOf?: (pathNode: any) => any }} [hooks] - `typeOf`
25
+ * answers for `path` nodes: a tag name, a `{ type, optional }`
26
+ * object, or `null` for unknown
27
+ * @returns {any} the annotated analysis
28
+ */
29
+ export declare function annotateTypes(analysis: {
30
+ astVersion: number;
31
+ root: any;
32
+ }, hooks?: {
33
+ typeOf?: (pathNode: any) => any;
34
+ }): any;
@@ -4,6 +4,13 @@
4
4
  * `JSONPATH_NOTHING`.
5
5
  */
6
6
  export declare const NOTHING: unique symbol;
7
+ /**
8
+ * Scan `source[start..end)` as an RFC 6901 array index: `0`, or a digit
9
+ * sequence without leading zeros. Returns -1 when the range is not a
10
+ * valid index (`-` is never a valid read index). Shared by the JSON
11
+ * Pointer compiler (pointer.js) and the JSON Patch engine (patch.js).
12
+ */
13
+ export declare function scanArrayIndex(source: any, start: any, end: any): number;
7
14
  /**
8
15
  * Returns true when every segment is a child segment with exactly one
9
16
  * name or index selector (a "singular query", RFC 9535 section 2.3.5.1).
@@ -24,6 +31,13 @@ export declare function runSegmentsV(segs: any, start: any, root: any): any[];
24
31
  /**
25
32
  * Compile an existence test for a filter query; singular queries never
26
33
  * materialize nodelists.
34
+ *
35
+ * The non-singular case builds its nodelist rather than pulling the
36
+ * lazy chain (compileSegmentG), even though it only needs one node: a
37
+ * filter runs this per candidate node, where nodelists are a handful of
38
+ * items and generator setup costs more than the pushes it saves - it
39
+ * benched ~9x slower on `$.items[?@.tags[*]]` over 2000 items. Laziness
40
+ * pays at the top of a query, not inside a filter.
27
41
  * @returns {(current: any, root: any) => boolean}
28
42
  */
29
43
  export declare function compileExists(query: any): (current: any, root: any) => boolean;
@@ -35,6 +49,23 @@ export declare function compileLogicalExpr(expr: any): (current: any, root: any)
35
49
  export declare function compileSelectorNodeV(sel: any): (v: any, out: any, root: any) => void;
36
50
  export declare function descendV(v: any, output: any, root: any, apply: any): void;
37
51
  export declare function compileSegmentV(seg: any): (input: any, output: any, root: any) => void;
52
+ /**
53
+ * Compile a segment into its lazy form: a generator function yielding
54
+ * the nodes one input value contributes, in document order.
55
+ * @param {object} seg - a parsed query segment
56
+ * @returns {(value: any, root: any) => Generator<any>}
57
+ */
58
+ export declare function compileSegmentG(seg: object): (value: any, root: any) => Generator<any>;
59
+ /**
60
+ * Lazily enumerate the nodelist a compiled segment chain selects,
61
+ * yielding values in document order.
62
+ * @param {Function[]} gens - segment generators from compileSegmentG
63
+ * @param {number} i - the segment to apply (0 to start the chain)
64
+ * @param {any} value - the value this segment applies to
65
+ * @param {any} root - the query root (`$` inside embedded filters)
66
+ * @returns {Generator<any>}
67
+ */
68
+ export declare function runSegmentsG(gens: Function[], i: number, value: any, root: any): Generator<any>;
38
69
  export declare const RE_NAME_NEEDS_ESCAPE: RegExp;
39
70
  /**
40
71
  * Escape a member name for use inside a normalized path name selector