@jarenjs/json 0.9.2 → 0.34.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.
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
@@ -0,0 +1,863 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://jarenjs.dev/schemas/geojson-jaren",
4
+ "title": "GeoJSON (RFC 7946), fully validated",
5
+ "description": "GeoJSON with the two invariants plain JSON Schema cannot express, added through the Jaren $query keyword: every linear ring is closed (its first position equals its last), and rings follow the right-hand rule of RFC 7946 section 3.1.6 (the exterior ring winds counter-clockwise, holes wind clockwise). Structurally this is geojson.schema.json unchanged; a validator without $query support sees the same grammar. Winding is decided by the sign of the shoelace sum, and rings are addressed by index because the D4 iteration rule would unpack a ring into its positions.",
6
+ "allOf": [
7
+ {
8
+ "$ref": "#/$defs/geoJsonObject"
9
+ }
10
+ ],
11
+ "$defs": {
12
+ "geoJsonObject": {
13
+ "description": "Any GeoJSON object: a geometry, a Feature, or a FeatureCollection.",
14
+ "oneOf": [
15
+ {
16
+ "$ref": "#/$defs/geometry"
17
+ },
18
+ {
19
+ "$ref": "#/$defs/feature"
20
+ },
21
+ {
22
+ "$ref": "#/$defs/featureCollection"
23
+ }
24
+ ]
25
+ },
26
+ "geometry": {
27
+ "description": "One of the seven geometry types of RFC 7946 section 3.1.",
28
+ "oneOf": [
29
+ {
30
+ "$ref": "#/$defs/point"
31
+ },
32
+ {
33
+ "$ref": "#/$defs/multiPoint"
34
+ },
35
+ {
36
+ "$ref": "#/$defs/lineString"
37
+ },
38
+ {
39
+ "$ref": "#/$defs/multiLineString"
40
+ },
41
+ {
42
+ "$ref": "#/$defs/polygon"
43
+ },
44
+ {
45
+ "$ref": "#/$defs/multiPolygon"
46
+ },
47
+ {
48
+ "$ref": "#/$defs/geometryCollection"
49
+ }
50
+ ]
51
+ },
52
+ "position": {
53
+ "description": "A position: longitude, latitude, and optionally altitude, in that order (RFC 7946 section 3.1.1). Longitude and latitude are bounded because the coordinate reference system is fixed to WGS 84.",
54
+ "type": "array",
55
+ "minItems": 2,
56
+ "maxItems": 3,
57
+ "prefixItems": [
58
+ {
59
+ "type": "number",
60
+ "minimum": -180,
61
+ "maximum": 180
62
+ },
63
+ {
64
+ "type": "number",
65
+ "minimum": -90,
66
+ "maximum": 90
67
+ }
68
+ ],
69
+ "items": {
70
+ "type": "number"
71
+ }
72
+ },
73
+ "linearRing": {
74
+ "description": "A closed LineString of four or more positions. JSON Schema can require the count but NOT that the first and last positions are equal, which is why this artifact alone cannot fully validate a polygon.",
75
+ "type": "array",
76
+ "minItems": 4,
77
+ "items": {
78
+ "$ref": "#/$defs/position"
79
+ }
80
+ },
81
+ "bbox": {
82
+ "description": "All axes of the most south-westerly position followed by all axes of the more north-easterly one (RFC 7946 section 5): four numbers in two dimensions, six in three.",
83
+ "type": "array",
84
+ "oneOf": [
85
+ {
86
+ "minItems": 4,
87
+ "maxItems": 4
88
+ },
89
+ {
90
+ "minItems": 6,
91
+ "maxItems": 6
92
+ }
93
+ ],
94
+ "items": {
95
+ "type": "number"
96
+ }
97
+ },
98
+ "point": {
99
+ "type": "object",
100
+ "properties": {
101
+ "type": {
102
+ "const": "Point"
103
+ },
104
+ "coordinates": {
105
+ "$ref": "#/$defs/position"
106
+ },
107
+ "bbox": {
108
+ "$ref": "#/$defs/bbox"
109
+ }
110
+ },
111
+ "required": [
112
+ "type",
113
+ "coordinates"
114
+ ],
115
+ "additionalProperties": false
116
+ },
117
+ "multiPoint": {
118
+ "type": "object",
119
+ "properties": {
120
+ "type": {
121
+ "const": "MultiPoint"
122
+ },
123
+ "coordinates": {
124
+ "type": "array",
125
+ "items": {
126
+ "$ref": "#/$defs/position"
127
+ }
128
+ },
129
+ "bbox": {
130
+ "$ref": "#/$defs/bbox"
131
+ }
132
+ },
133
+ "required": [
134
+ "type",
135
+ "coordinates"
136
+ ],
137
+ "additionalProperties": false
138
+ },
139
+ "lineString": {
140
+ "description": "Two or more positions (RFC 7946 section 3.1.4).",
141
+ "type": "object",
142
+ "properties": {
143
+ "type": {
144
+ "const": "LineString"
145
+ },
146
+ "coordinates": {
147
+ "type": "array",
148
+ "minItems": 2,
149
+ "items": {
150
+ "$ref": "#/$defs/position"
151
+ }
152
+ },
153
+ "bbox": {
154
+ "$ref": "#/$defs/bbox"
155
+ }
156
+ },
157
+ "required": [
158
+ "type",
159
+ "coordinates"
160
+ ],
161
+ "additionalProperties": false
162
+ },
163
+ "multiLineString": {
164
+ "type": "object",
165
+ "properties": {
166
+ "type": {
167
+ "const": "MultiLineString"
168
+ },
169
+ "coordinates": {
170
+ "type": "array",
171
+ "items": {
172
+ "type": "array",
173
+ "minItems": 2,
174
+ "items": {
175
+ "$ref": "#/$defs/position"
176
+ }
177
+ }
178
+ },
179
+ "bbox": {
180
+ "$ref": "#/$defs/bbox"
181
+ }
182
+ },
183
+ "required": [
184
+ "type",
185
+ "coordinates"
186
+ ],
187
+ "additionalProperties": false
188
+ },
189
+ "polygon": {
190
+ "description": "An array of linear rings: the exterior ring first, then holes (RFC 7946 section 3.1.6). Ring closure and the right-hand rule are NOT checked here - see this schema's description.",
191
+ "type": "object",
192
+ "properties": {
193
+ "type": {
194
+ "const": "Polygon"
195
+ },
196
+ "coordinates": {
197
+ "type": "array",
198
+ "items": {
199
+ "$ref": "#/$defs/linearRing"
200
+ }
201
+ },
202
+ "bbox": {
203
+ "$ref": "#/$defs/bbox"
204
+ }
205
+ },
206
+ "required": [
207
+ "type",
208
+ "coordinates"
209
+ ],
210
+ "additionalProperties": false,
211
+ "$query": {
212
+ "$let": {
213
+ "rings": "$.coordinates"
214
+ },
215
+ "$return": {
216
+ "$and": [
217
+ {
218
+ "$every": {
219
+ "i": {
220
+ "$range": [
221
+ 0,
222
+ {
223
+ "$sub": [
224
+ {
225
+ "$count": "$rings[*]"
226
+ },
227
+ 1
228
+ ]
229
+ }
230
+ ]
231
+ }
232
+ },
233
+ "$satisfies": {
234
+ "$let": {
235
+ "r": {
236
+ "$get": [
237
+ "$rings",
238
+ "$i"
239
+ ]
240
+ }
241
+ },
242
+ "$return": {
243
+ "$eq": [
244
+ {
245
+ "$get": [
246
+ "$r",
247
+ 0
248
+ ]
249
+ },
250
+ {
251
+ "$get": [
252
+ "$r",
253
+ -1
254
+ ]
255
+ }
256
+ ]
257
+ }
258
+ }
259
+ },
260
+ {
261
+ "$gt": [
262
+ {
263
+ "$let": {
264
+ "r": {
265
+ "$get": [
266
+ "$rings",
267
+ 0
268
+ ]
269
+ }
270
+ },
271
+ "$return": {
272
+ "$fold": {
273
+ "s": 0
274
+ },
275
+ "$for": {
276
+ "i": {
277
+ "$range": [
278
+ 0,
279
+ {
280
+ "$sub": [
281
+ {
282
+ "$count": "$r[*]"
283
+ },
284
+ 2
285
+ ]
286
+ }
287
+ ]
288
+ }
289
+ },
290
+ "$let": {
291
+ "p": {
292
+ "$get": [
293
+ "$r",
294
+ "$i"
295
+ ]
296
+ },
297
+ "q": {
298
+ "$get": [
299
+ "$r",
300
+ {
301
+ "$add": [
302
+ "$i",
303
+ 1
304
+ ]
305
+ }
306
+ ]
307
+ }
308
+ },
309
+ "$return": {
310
+ "$add": [
311
+ "$s",
312
+ {
313
+ "$sub": [
314
+ {
315
+ "$mul": [
316
+ {
317
+ "$get": [
318
+ "$p",
319
+ 0
320
+ ]
321
+ },
322
+ {
323
+ "$get": [
324
+ "$q",
325
+ 1
326
+ ]
327
+ }
328
+ ]
329
+ },
330
+ {
331
+ "$mul": [
332
+ {
333
+ "$get": [
334
+ "$q",
335
+ 0
336
+ ]
337
+ },
338
+ {
339
+ "$get": [
340
+ "$p",
341
+ 1
342
+ ]
343
+ }
344
+ ]
345
+ }
346
+ ]
347
+ }
348
+ ]
349
+ }
350
+ }
351
+ },
352
+ 0
353
+ ]
354
+ },
355
+ {
356
+ "$every": {
357
+ "h": {
358
+ "$range": [
359
+ 1,
360
+ {
361
+ "$sub": [
362
+ {
363
+ "$count": "$rings[*]"
364
+ },
365
+ 1
366
+ ]
367
+ }
368
+ ]
369
+ }
370
+ },
371
+ "$satisfies": {
372
+ "$lt": [
373
+ {
374
+ "$let": {
375
+ "r": {
376
+ "$get": [
377
+ "$rings",
378
+ "$h"
379
+ ]
380
+ }
381
+ },
382
+ "$return": {
383
+ "$fold": {
384
+ "s": 0
385
+ },
386
+ "$for": {
387
+ "i": {
388
+ "$range": [
389
+ 0,
390
+ {
391
+ "$sub": [
392
+ {
393
+ "$count": "$r[*]"
394
+ },
395
+ 2
396
+ ]
397
+ }
398
+ ]
399
+ }
400
+ },
401
+ "$let": {
402
+ "p": {
403
+ "$get": [
404
+ "$r",
405
+ "$i"
406
+ ]
407
+ },
408
+ "q": {
409
+ "$get": [
410
+ "$r",
411
+ {
412
+ "$add": [
413
+ "$i",
414
+ 1
415
+ ]
416
+ }
417
+ ]
418
+ }
419
+ },
420
+ "$return": {
421
+ "$add": [
422
+ "$s",
423
+ {
424
+ "$sub": [
425
+ {
426
+ "$mul": [
427
+ {
428
+ "$get": [
429
+ "$p",
430
+ 0
431
+ ]
432
+ },
433
+ {
434
+ "$get": [
435
+ "$q",
436
+ 1
437
+ ]
438
+ }
439
+ ]
440
+ },
441
+ {
442
+ "$mul": [
443
+ {
444
+ "$get": [
445
+ "$q",
446
+ 0
447
+ ]
448
+ },
449
+ {
450
+ "$get": [
451
+ "$p",
452
+ 1
453
+ ]
454
+ }
455
+ ]
456
+ }
457
+ ]
458
+ }
459
+ ]
460
+ }
461
+ }
462
+ },
463
+ 0
464
+ ]
465
+ }
466
+ }
467
+ ]
468
+ }
469
+ }
470
+ },
471
+ "multiPolygon": {
472
+ "type": "object",
473
+ "properties": {
474
+ "type": {
475
+ "const": "MultiPolygon"
476
+ },
477
+ "coordinates": {
478
+ "type": "array",
479
+ "items": {
480
+ "type": "array",
481
+ "items": {
482
+ "$ref": "#/$defs/linearRing"
483
+ }
484
+ }
485
+ },
486
+ "bbox": {
487
+ "$ref": "#/$defs/bbox"
488
+ }
489
+ },
490
+ "required": [
491
+ "type",
492
+ "coordinates"
493
+ ],
494
+ "additionalProperties": false,
495
+ "$query": {
496
+ "$every": {
497
+ "p": {
498
+ "$range": [
499
+ 0,
500
+ {
501
+ "$sub": [
502
+ {
503
+ "$count": "$.coordinates[*]"
504
+ },
505
+ 1
506
+ ]
507
+ }
508
+ ]
509
+ }
510
+ },
511
+ "$satisfies": {
512
+ "$let": {
513
+ "rings": {
514
+ "$get": [
515
+ "$.coordinates",
516
+ "$p"
517
+ ]
518
+ }
519
+ },
520
+ "$return": {
521
+ "$and": [
522
+ {
523
+ "$every": {
524
+ "i": {
525
+ "$range": [
526
+ 0,
527
+ {
528
+ "$sub": [
529
+ {
530
+ "$count": "$rings[*]"
531
+ },
532
+ 1
533
+ ]
534
+ }
535
+ ]
536
+ }
537
+ },
538
+ "$satisfies": {
539
+ "$let": {
540
+ "r": {
541
+ "$get": [
542
+ "$rings",
543
+ "$i"
544
+ ]
545
+ }
546
+ },
547
+ "$return": {
548
+ "$eq": [
549
+ {
550
+ "$get": [
551
+ "$r",
552
+ 0
553
+ ]
554
+ },
555
+ {
556
+ "$get": [
557
+ "$r",
558
+ -1
559
+ ]
560
+ }
561
+ ]
562
+ }
563
+ }
564
+ },
565
+ {
566
+ "$gt": [
567
+ {
568
+ "$let": {
569
+ "r": {
570
+ "$get": [
571
+ "$rings",
572
+ 0
573
+ ]
574
+ }
575
+ },
576
+ "$return": {
577
+ "$fold": {
578
+ "s": 0
579
+ },
580
+ "$for": {
581
+ "i": {
582
+ "$range": [
583
+ 0,
584
+ {
585
+ "$sub": [
586
+ {
587
+ "$count": "$r[*]"
588
+ },
589
+ 2
590
+ ]
591
+ }
592
+ ]
593
+ }
594
+ },
595
+ "$let": {
596
+ "p": {
597
+ "$get": [
598
+ "$r",
599
+ "$i"
600
+ ]
601
+ },
602
+ "q": {
603
+ "$get": [
604
+ "$r",
605
+ {
606
+ "$add": [
607
+ "$i",
608
+ 1
609
+ ]
610
+ }
611
+ ]
612
+ }
613
+ },
614
+ "$return": {
615
+ "$add": [
616
+ "$s",
617
+ {
618
+ "$sub": [
619
+ {
620
+ "$mul": [
621
+ {
622
+ "$get": [
623
+ "$p",
624
+ 0
625
+ ]
626
+ },
627
+ {
628
+ "$get": [
629
+ "$q",
630
+ 1
631
+ ]
632
+ }
633
+ ]
634
+ },
635
+ {
636
+ "$mul": [
637
+ {
638
+ "$get": [
639
+ "$q",
640
+ 0
641
+ ]
642
+ },
643
+ {
644
+ "$get": [
645
+ "$p",
646
+ 1
647
+ ]
648
+ }
649
+ ]
650
+ }
651
+ ]
652
+ }
653
+ ]
654
+ }
655
+ }
656
+ },
657
+ 0
658
+ ]
659
+ },
660
+ {
661
+ "$every": {
662
+ "h": {
663
+ "$range": [
664
+ 1,
665
+ {
666
+ "$sub": [
667
+ {
668
+ "$count": "$rings[*]"
669
+ },
670
+ 1
671
+ ]
672
+ }
673
+ ]
674
+ }
675
+ },
676
+ "$satisfies": {
677
+ "$lt": [
678
+ {
679
+ "$let": {
680
+ "r": {
681
+ "$get": [
682
+ "$rings",
683
+ "$h"
684
+ ]
685
+ }
686
+ },
687
+ "$return": {
688
+ "$fold": {
689
+ "s": 0
690
+ },
691
+ "$for": {
692
+ "i": {
693
+ "$range": [
694
+ 0,
695
+ {
696
+ "$sub": [
697
+ {
698
+ "$count": "$r[*]"
699
+ },
700
+ 2
701
+ ]
702
+ }
703
+ ]
704
+ }
705
+ },
706
+ "$let": {
707
+ "p": {
708
+ "$get": [
709
+ "$r",
710
+ "$i"
711
+ ]
712
+ },
713
+ "q": {
714
+ "$get": [
715
+ "$r",
716
+ {
717
+ "$add": [
718
+ "$i",
719
+ 1
720
+ ]
721
+ }
722
+ ]
723
+ }
724
+ },
725
+ "$return": {
726
+ "$add": [
727
+ "$s",
728
+ {
729
+ "$sub": [
730
+ {
731
+ "$mul": [
732
+ {
733
+ "$get": [
734
+ "$p",
735
+ 0
736
+ ]
737
+ },
738
+ {
739
+ "$get": [
740
+ "$q",
741
+ 1
742
+ ]
743
+ }
744
+ ]
745
+ },
746
+ {
747
+ "$mul": [
748
+ {
749
+ "$get": [
750
+ "$q",
751
+ 0
752
+ ]
753
+ },
754
+ {
755
+ "$get": [
756
+ "$p",
757
+ 1
758
+ ]
759
+ }
760
+ ]
761
+ }
762
+ ]
763
+ }
764
+ ]
765
+ }
766
+ }
767
+ },
768
+ 0
769
+ ]
770
+ }
771
+ }
772
+ ]
773
+ }
774
+ }
775
+ }
776
+ },
777
+ "geometryCollection": {
778
+ "description": "A heterogeneous collection of geometries. RFC 7946 section 3.1.8 advises against nesting one inside another.",
779
+ "type": "object",
780
+ "properties": {
781
+ "type": {
782
+ "const": "GeometryCollection"
783
+ },
784
+ "geometries": {
785
+ "type": "array",
786
+ "items": {
787
+ "$ref": "#/$defs/geometry"
788
+ }
789
+ },
790
+ "bbox": {
791
+ "$ref": "#/$defs/bbox"
792
+ }
793
+ },
794
+ "required": [
795
+ "type",
796
+ "geometries"
797
+ ],
798
+ "additionalProperties": false
799
+ },
800
+ "feature": {
801
+ "description": "A geometry with properties. Both members are REQUIRED and both are nullable (RFC 7946 section 3.2).",
802
+ "type": "object",
803
+ "properties": {
804
+ "type": {
805
+ "const": "Feature"
806
+ },
807
+ "geometry": {
808
+ "oneOf": [
809
+ {
810
+ "type": "null"
811
+ },
812
+ {
813
+ "$ref": "#/$defs/geometry"
814
+ }
815
+ ]
816
+ },
817
+ "properties": {
818
+ "type": [
819
+ "object",
820
+ "null"
821
+ ]
822
+ },
823
+ "id": {
824
+ "type": [
825
+ "string",
826
+ "number"
827
+ ]
828
+ },
829
+ "bbox": {
830
+ "$ref": "#/$defs/bbox"
831
+ }
832
+ },
833
+ "required": [
834
+ "type",
835
+ "geometry",
836
+ "properties"
837
+ ],
838
+ "additionalProperties": false
839
+ },
840
+ "featureCollection": {
841
+ "type": "object",
842
+ "properties": {
843
+ "type": {
844
+ "const": "FeatureCollection"
845
+ },
846
+ "features": {
847
+ "type": "array",
848
+ "items": {
849
+ "$ref": "#/$defs/feature"
850
+ }
851
+ },
852
+ "bbox": {
853
+ "$ref": "#/$defs/bbox"
854
+ }
855
+ },
856
+ "required": [
857
+ "type",
858
+ "features"
859
+ ],
860
+ "additionalProperties": false
861
+ }
862
+ }
863
+ }