@hatua/expressions 0.0.0 → 0.1.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.js ADDED
@@ -0,0 +1,2452 @@
1
+ //#region src/generated/builtins.ts
2
+ var e = [
3
+ {
4
+ namespace: "dt",
5
+ summary: "Dates and times. Read them, move them forwards or backwards, and measure how far apart two of them are."
6
+ },
7
+ {
8
+ namespace: "json",
9
+ summary: "JSON text. Read a value out of it when something arrives as JSON, or write one back to it."
10
+ },
11
+ {
12
+ namespace: "list",
13
+ summary: "Lists. Count one, take a piece out of it, sort it, or join it into text. To do something to every item in turn, use a loop step rather than a function."
14
+ },
15
+ {
16
+ namespace: "num",
17
+ summary: "Numbers. Dividing always gives a decimal — 7 / 2 is 3.5 — and a half always rounds away from zero, so -0.5 rounds to -1."
18
+ },
19
+ {
20
+ namespace: "text",
21
+ summary: "Text. Change its case, trim it, split it, join it, and test what it holds. Changing case works the same everywhere and never depends on a language or region."
22
+ }
23
+ ], t = [
24
+ {
25
+ namespace: "dt",
26
+ name: "add",
27
+ qualified: "dt.add",
28
+ summary: "Move a date and time forwards or backwards.",
29
+ params: [
30
+ {
31
+ name: "value",
32
+ type: "datetime",
33
+ description: "The date and time to move.",
34
+ optional: !1,
35
+ variadic: !1
36
+ },
37
+ {
38
+ name: "amount",
39
+ type: "number",
40
+ description: "How many units to move by. A negative amount moves backwards.",
41
+ optional: !1,
42
+ variadic: !1
43
+ },
44
+ {
45
+ name: "unit",
46
+ type: "text",
47
+ description: "One of seconds, minutes, hours or days.",
48
+ optional: !1,
49
+ variadic: !1
50
+ }
51
+ ],
52
+ returns: "datetime"
53
+ },
54
+ {
55
+ namespace: "dt",
56
+ name: "diff",
57
+ qualified: "dt.diff",
58
+ summary: "How many whole units separate two dates and times. Anything left over is dropped.",
59
+ params: [
60
+ {
61
+ name: "a",
62
+ type: "datetime",
63
+ description: "The date and time measured to.",
64
+ optional: !1,
65
+ variadic: !1
66
+ },
67
+ {
68
+ name: "b",
69
+ type: "datetime",
70
+ description: "The date and time measured from. Later than the first gives a negative answer.",
71
+ optional: !1,
72
+ variadic: !1
73
+ },
74
+ {
75
+ name: "unit",
76
+ type: "text",
77
+ description: "One of seconds, minutes, hours or days.",
78
+ optional: !1,
79
+ variadic: !1
80
+ }
81
+ ],
82
+ returns: "number"
83
+ },
84
+ {
85
+ namespace: "dt",
86
+ name: "iso",
87
+ qualified: "dt.iso",
88
+ summary: "Write a date and time as text, in UTC.",
89
+ params: [{
90
+ name: "value",
91
+ type: "datetime",
92
+ description: "The date and time to write.",
93
+ optional: !1,
94
+ variadic: !1
95
+ }],
96
+ returns: "text"
97
+ },
98
+ {
99
+ namespace: "dt",
100
+ name: "now",
101
+ qualified: "dt.now",
102
+ summary: "The date and time this run started.",
103
+ params: [],
104
+ returns: "datetime"
105
+ },
106
+ {
107
+ namespace: "dt",
108
+ name: "parse",
109
+ qualified: "dt.parse",
110
+ summary: "Read a date and time from text, written like `2026-08-22T05:14:00Z`.",
111
+ params: [{
112
+ name: "value",
113
+ type: "text",
114
+ description: "The date and time to read, written like `2026-08-22T05:14:00Z`.",
115
+ optional: !1,
116
+ variadic: !1
117
+ }],
118
+ returns: "datetime"
119
+ },
120
+ {
121
+ namespace: "json",
122
+ name: "parse",
123
+ qualified: "json.parse",
124
+ summary: "Read a value from JSON text.",
125
+ params: [{
126
+ name: "value",
127
+ type: "text",
128
+ description: "The JSON text to read.",
129
+ optional: !1,
130
+ variadic: !1
131
+ }],
132
+ returns: "unknown"
133
+ },
134
+ {
135
+ namespace: "json",
136
+ name: "stringify",
137
+ qualified: "json.stringify",
138
+ summary: "Write a value as JSON text.",
139
+ params: [{
140
+ name: "value",
141
+ type: "unknown",
142
+ description: "The value to write. Lists and objects are written out whole.",
143
+ optional: !1,
144
+ variadic: !1
145
+ }],
146
+ returns: "text"
147
+ },
148
+ {
149
+ namespace: "list",
150
+ name: "contains",
151
+ qualified: "list.contains",
152
+ summary: "Whether the list holds this value. Two values match only when they are the same type.",
153
+ params: [{
154
+ name: "value",
155
+ type: "list",
156
+ description: "The list to search.",
157
+ optional: !1,
158
+ variadic: !1
159
+ }, {
160
+ name: "needle",
161
+ type: "unknown",
162
+ description: "The value to look for.",
163
+ optional: !1,
164
+ variadic: !1
165
+ }],
166
+ returns: "boolean"
167
+ },
168
+ {
169
+ namespace: "list",
170
+ name: "first",
171
+ qualified: "list.first",
172
+ summary: "The first item, or null when the list is empty.",
173
+ params: [{
174
+ name: "value",
175
+ type: "list",
176
+ description: "The list to read from.",
177
+ optional: !1,
178
+ variadic: !1
179
+ }],
180
+ returns: "unknown"
181
+ },
182
+ {
183
+ namespace: "list",
184
+ name: "join",
185
+ qualified: "list.join",
186
+ summary: "Write every item as text, with a separator between them.",
187
+ params: [{
188
+ name: "value",
189
+ type: "list",
190
+ description: "The list whose items are written out and joined.",
191
+ optional: !1,
192
+ variadic: !1
193
+ }, {
194
+ name: "separator",
195
+ type: "text",
196
+ description: "Goes between items, and never before the first or after the last.",
197
+ optional: !1,
198
+ variadic: !1
199
+ }],
200
+ returns: "text"
201
+ },
202
+ {
203
+ namespace: "list",
204
+ name: "last",
205
+ qualified: "list.last",
206
+ summary: "The last item, or null when the list is empty.",
207
+ params: [{
208
+ name: "value",
209
+ type: "list",
210
+ description: "The list to read from.",
211
+ optional: !1,
212
+ variadic: !1
213
+ }],
214
+ returns: "unknown"
215
+ },
216
+ {
217
+ namespace: "list",
218
+ name: "len",
219
+ qualified: "list.len",
220
+ summary: "How many items the list holds.",
221
+ params: [{
222
+ name: "value",
223
+ type: "list",
224
+ description: "The list to measure.",
225
+ optional: !1,
226
+ variadic: !1
227
+ }],
228
+ returns: "number"
229
+ },
230
+ {
231
+ namespace: "list",
232
+ name: "slice",
233
+ qualified: "list.slice",
234
+ summary: "The items from one position up to, but not including, another.",
235
+ params: [
236
+ {
237
+ name: "value",
238
+ type: "list",
239
+ description: "The list to take items from.",
240
+ optional: !1,
241
+ variadic: !1
242
+ },
243
+ {
244
+ name: "start",
245
+ type: "number",
246
+ description: "Position of the first item kept, counting from zero.",
247
+ optional: !1,
248
+ variadic: !1
249
+ },
250
+ {
251
+ name: "end",
252
+ type: "number",
253
+ description: "Position to stop before. Leave it out to run to the end.",
254
+ optional: !0,
255
+ variadic: !1
256
+ }
257
+ ],
258
+ returns: "list"
259
+ },
260
+ {
261
+ namespace: "list",
262
+ name: "sort",
263
+ qualified: "list.sort",
264
+ summary: "The list in ascending order. Every item has to be the same kind of value.",
265
+ params: [{
266
+ name: "value",
267
+ type: "list",
268
+ description: "The list to sort.",
269
+ optional: !1,
270
+ variadic: !1
271
+ }],
272
+ returns: "list"
273
+ },
274
+ {
275
+ namespace: "list",
276
+ name: "unique",
277
+ qualified: "list.unique",
278
+ summary: "The list with repeats removed, keeping the first of each and the original order.",
279
+ params: [{
280
+ name: "value",
281
+ type: "list",
282
+ description: "The list to remove repeats from.",
283
+ optional: !1,
284
+ variadic: !1
285
+ }],
286
+ returns: "list"
287
+ },
288
+ {
289
+ namespace: "num",
290
+ name: "abs",
291
+ qualified: "num.abs",
292
+ summary: "The number without its sign.",
293
+ params: [{
294
+ name: "value",
295
+ type: "number",
296
+ description: "The number to take the sign off.",
297
+ optional: !1,
298
+ variadic: !1
299
+ }],
300
+ returns: "number"
301
+ },
302
+ {
303
+ namespace: "num",
304
+ name: "ceil",
305
+ qualified: "num.ceil",
306
+ summary: "The nearest whole number at or above this one.",
307
+ params: [{
308
+ name: "value",
309
+ type: "number",
310
+ description: "The number to round up.",
311
+ optional: !1,
312
+ variadic: !1
313
+ }],
314
+ returns: "number"
315
+ },
316
+ {
317
+ namespace: "num",
318
+ name: "floor",
319
+ qualified: "num.floor",
320
+ summary: "The nearest whole number at or below this one.",
321
+ params: [{
322
+ name: "value",
323
+ type: "number",
324
+ description: "The number to round down.",
325
+ optional: !1,
326
+ variadic: !1
327
+ }],
328
+ returns: "number"
329
+ },
330
+ {
331
+ namespace: "num",
332
+ name: "max",
333
+ qualified: "num.max",
334
+ summary: "The largest of the numbers given.",
335
+ params: [{
336
+ name: "values",
337
+ type: "number",
338
+ description: "The numbers to compare, each one its own argument.",
339
+ optional: !1,
340
+ variadic: !0
341
+ }],
342
+ returns: "number"
343
+ },
344
+ {
345
+ namespace: "num",
346
+ name: "min",
347
+ qualified: "num.min",
348
+ summary: "The smallest of the numbers given.",
349
+ params: [{
350
+ name: "values",
351
+ type: "number",
352
+ description: "The numbers to compare, each one its own argument.",
353
+ optional: !1,
354
+ variadic: !0
355
+ }],
356
+ returns: "number"
357
+ },
358
+ {
359
+ namespace: "num",
360
+ name: "parse",
361
+ qualified: "num.parse",
362
+ summary: "Read a number out of text. Text never becomes a number on its own, so this is how.",
363
+ params: [{
364
+ name: "value",
365
+ type: "text",
366
+ description: "The text to read a number from.",
367
+ optional: !1,
368
+ variadic: !1
369
+ }],
370
+ returns: "number"
371
+ },
372
+ {
373
+ namespace: "num",
374
+ name: "round",
375
+ qualified: "num.round",
376
+ summary: "The nearest whole number. A half rounds away from zero.",
377
+ params: [{
378
+ name: "value",
379
+ type: "number",
380
+ description: "The number to round.",
381
+ optional: !1,
382
+ variadic: !1
383
+ }],
384
+ returns: "number"
385
+ },
386
+ {
387
+ namespace: "text",
388
+ name: "concat",
389
+ qualified: "text.concat",
390
+ summary: "Join values end to end. `+` adds numbers and never joins text, so this is how text is joined.",
391
+ params: [{
392
+ name: "parts",
393
+ type: "text",
394
+ description: "The pieces to join, in order, each one its own argument.",
395
+ optional: !1,
396
+ variadic: !0
397
+ }],
398
+ returns: "text"
399
+ },
400
+ {
401
+ namespace: "text",
402
+ name: "contains",
403
+ qualified: "text.contains",
404
+ summary: "Whether the text holds this piece somewhere inside it.",
405
+ params: [{
406
+ name: "value",
407
+ type: "text",
408
+ description: "The text to search in.",
409
+ optional: !1,
410
+ variadic: !1
411
+ }, {
412
+ name: "search",
413
+ type: "text",
414
+ description: "The piece to look for.",
415
+ optional: !1,
416
+ variadic: !1
417
+ }],
418
+ returns: "boolean"
419
+ },
420
+ {
421
+ namespace: "text",
422
+ name: "ends_with",
423
+ qualified: "text.ends_with",
424
+ summary: "Whether the text ends with this piece.",
425
+ params: [{
426
+ name: "value",
427
+ type: "text",
428
+ description: "The text to test.",
429
+ optional: !1,
430
+ variadic: !1
431
+ }, {
432
+ name: "suffix",
433
+ type: "text",
434
+ description: "The piece it should end with.",
435
+ optional: !1,
436
+ variadic: !1
437
+ }],
438
+ returns: "boolean"
439
+ },
440
+ {
441
+ namespace: "text",
442
+ name: "join",
443
+ qualified: "text.join",
444
+ summary: "Join a list into one piece of text, with a separator between the items.",
445
+ params: [{
446
+ name: "values",
447
+ type: "list",
448
+ description: "The list whose items are joined.",
449
+ optional: !1,
450
+ variadic: !1
451
+ }, {
452
+ name: "separator",
453
+ type: "text",
454
+ description: "Goes between items, and never before the first or after the last.",
455
+ optional: !1,
456
+ variadic: !1
457
+ }],
458
+ returns: "text"
459
+ },
460
+ {
461
+ namespace: "text",
462
+ name: "len",
463
+ qualified: "text.len",
464
+ summary: "How many characters the text holds.",
465
+ params: [{
466
+ name: "value",
467
+ type: "text",
468
+ description: "The text to measure.",
469
+ optional: !1,
470
+ variadic: !1
471
+ }],
472
+ returns: "number"
473
+ },
474
+ {
475
+ namespace: "text",
476
+ name: "lower",
477
+ qualified: "text.lower",
478
+ summary: "The text in lower case.",
479
+ params: [{
480
+ name: "value",
481
+ type: "text",
482
+ description: "The text to convert.",
483
+ optional: !1,
484
+ variadic: !1
485
+ }],
486
+ returns: "text"
487
+ },
488
+ {
489
+ namespace: "text",
490
+ name: "replace",
491
+ qualified: "text.replace",
492
+ summary: "Replace every occurrence, not only the first.",
493
+ params: [
494
+ {
495
+ name: "value",
496
+ type: "text",
497
+ description: "The text to search in.",
498
+ optional: !1,
499
+ variadic: !1
500
+ },
501
+ {
502
+ name: "search",
503
+ type: "text",
504
+ description: "The text to look for. Every occurrence is replaced.",
505
+ optional: !1,
506
+ variadic: !1
507
+ },
508
+ {
509
+ name: "replacement",
510
+ type: "text",
511
+ description: "What each occurrence becomes.",
512
+ optional: !1,
513
+ variadic: !1
514
+ }
515
+ ],
516
+ returns: "text"
517
+ },
518
+ {
519
+ namespace: "text",
520
+ name: "slice",
521
+ qualified: "text.slice",
522
+ summary: "The characters from one position up to, but not including, another.",
523
+ params: [
524
+ {
525
+ name: "value",
526
+ type: "text",
527
+ description: "The text to take characters from.",
528
+ optional: !1,
529
+ variadic: !1
530
+ },
531
+ {
532
+ name: "start",
533
+ type: "number",
534
+ description: "Position of the first character kept, counting from zero.",
535
+ optional: !1,
536
+ variadic: !1
537
+ },
538
+ {
539
+ name: "end",
540
+ type: "number",
541
+ description: "Position to stop before. Leave it out to run to the end.",
542
+ optional: !0,
543
+ variadic: !1
544
+ }
545
+ ],
546
+ returns: "text"
547
+ },
548
+ {
549
+ namespace: "text",
550
+ name: "split",
551
+ qualified: "text.split",
552
+ summary: "Break text into a list wherever a separator appears.",
553
+ params: [{
554
+ name: "value",
555
+ type: "text",
556
+ description: "The text to break up.",
557
+ optional: !1,
558
+ variadic: !1
559
+ }, {
560
+ name: "separator",
561
+ type: "text",
562
+ description: "Where to break. It does not appear in the result.",
563
+ optional: !1,
564
+ variadic: !1
565
+ }],
566
+ returns: "list"
567
+ },
568
+ {
569
+ namespace: "text",
570
+ name: "starts_with",
571
+ qualified: "text.starts_with",
572
+ summary: "Whether the text begins with this piece.",
573
+ params: [{
574
+ name: "value",
575
+ type: "text",
576
+ description: "The text to test.",
577
+ optional: !1,
578
+ variadic: !1
579
+ }, {
580
+ name: "prefix",
581
+ type: "text",
582
+ description: "The piece it should begin with.",
583
+ optional: !1,
584
+ variadic: !1
585
+ }],
586
+ returns: "boolean"
587
+ },
588
+ {
589
+ namespace: "text",
590
+ name: "trim",
591
+ qualified: "text.trim",
592
+ summary: "The text with any spaces at either end removed.",
593
+ params: [{
594
+ name: "value",
595
+ type: "text",
596
+ description: "The text to trim.",
597
+ optional: !1,
598
+ variadic: !1
599
+ }],
600
+ returns: "text"
601
+ },
602
+ {
603
+ namespace: "text",
604
+ name: "upper",
605
+ qualified: "text.upper",
606
+ summary: "The text in upper case.",
607
+ params: [{
608
+ name: "value",
609
+ type: "text",
610
+ description: "The text to convert.",
611
+ optional: !1,
612
+ variadic: !1
613
+ }],
614
+ returns: "text"
615
+ }
616
+ ], n = {
617
+ EXPR_PARSE_ERROR: {
618
+ code: "EXPR_PARSE_ERROR",
619
+ severity: "error",
620
+ phase: "check",
621
+ message: "{detail}"
622
+ },
623
+ EXPR_UNKNOWN_REFERENCE: {
624
+ code: "EXPR_UNKNOWN_REFERENCE",
625
+ severity: "error",
626
+ phase: "check",
627
+ message: "Nothing named {name} is in scope here."
628
+ },
629
+ EXPR_UNKNOWN_FUNCTION: {
630
+ code: "EXPR_UNKNOWN_FUNCTION",
631
+ severity: "error",
632
+ phase: "check",
633
+ message: "There is no function {name}."
634
+ },
635
+ EXPR_ARITY_MISMATCH: {
636
+ code: "EXPR_ARITY_MISMATCH",
637
+ severity: "error",
638
+ phase: "check",
639
+ message: "{name} takes {expected} arguments, not {actual}."
640
+ },
641
+ EXPR_ARGUMENT_TYPE: {
642
+ code: "EXPR_ARGUMENT_TYPE",
643
+ severity: "error",
644
+ phase: "check",
645
+ message: "{name} expects {expected} for {param}, not {actual}."
646
+ },
647
+ EXPR_TYPE_MISMATCH: {
648
+ code: "EXPR_TYPE_MISMATCH",
649
+ severity: "error",
650
+ phase: "check",
651
+ message: "{name} expects {expected}, but this produces {actual}."
652
+ },
653
+ EXPR_TYPE_UNKNOWN: {
654
+ code: "EXPR_TYPE_UNKNOWN",
655
+ severity: "warning",
656
+ phase: "check",
657
+ message: "{name} expects {expected}; this type is only known at run time."
658
+ },
659
+ EXPR_OPERAND_TYPE: {
660
+ code: "EXPR_OPERAND_TYPE",
661
+ severity: "error",
662
+ phase: "check",
663
+ message: "{op} expects {expected}, not {actual}."
664
+ },
665
+ EXPR_FUNCTION_COLLISION: {
666
+ code: "EXPR_FUNCTION_COLLISION",
667
+ severity: "error",
668
+ phase: "check",
669
+ message: "{name} is declared twice."
670
+ },
671
+ EVAL_MISSING_PATH: {
672
+ code: "EVAL_MISSING_PATH",
673
+ severity: "error",
674
+ phase: "eval",
675
+ message: "{name} is not present."
676
+ },
677
+ EVAL_TYPE_MISMATCH: {
678
+ code: "EVAL_TYPE_MISMATCH",
679
+ severity: "error",
680
+ phase: "eval",
681
+ message: "{name} expects {expected}, but this produced {actual}."
682
+ },
683
+ EVAL_OPERAND_TYPE: {
684
+ code: "EVAL_OPERAND_TYPE",
685
+ severity: "error",
686
+ phase: "eval",
687
+ message: "{op} expects {expected}, not {actual}."
688
+ },
689
+ EVAL_COMPARE_NULL: {
690
+ code: "EVAL_COMPARE_NULL",
691
+ severity: "error",
692
+ phase: "eval",
693
+ message: "{op} cannot compare null."
694
+ },
695
+ EVAL_COMPARE_TYPES: {
696
+ code: "EVAL_COMPARE_TYPES",
697
+ severity: "error",
698
+ phase: "eval",
699
+ message: "{op} cannot compare {expected} with {actual}."
700
+ },
701
+ EVAL_NUMERIC_OVERFLOW: {
702
+ code: "EVAL_NUMERIC_OVERFLOW",
703
+ severity: "error",
704
+ phase: "eval",
705
+ message: "{op} produced a number too large to represent."
706
+ },
707
+ EVAL_DIVISION_BY_ZERO: {
708
+ code: "EVAL_DIVISION_BY_ZERO",
709
+ severity: "error",
710
+ phase: "eval",
711
+ message: "Division by zero."
712
+ },
713
+ EVAL_UNKNOWN_FUNCTION: {
714
+ code: "EVAL_UNKNOWN_FUNCTION",
715
+ severity: "error",
716
+ phase: "eval",
717
+ message: "There is no function {name}."
718
+ },
719
+ EVAL_ARITY_MISMATCH: {
720
+ code: "EVAL_ARITY_MISMATCH",
721
+ severity: "error",
722
+ phase: "eval",
723
+ message: "{name} takes {expected} arguments, not {actual}."
724
+ },
725
+ EVAL_BAD_ARGUMENT: {
726
+ code: "EVAL_BAD_ARGUMENT",
727
+ severity: "error",
728
+ phase: "eval",
729
+ message: "{name} cannot accept {actual} for {param}."
730
+ }
731
+ };
732
+ //#endregion
733
+ //#region src/errors.ts
734
+ function r(e, t = {}) {
735
+ return e.replace(/\{([a-z_]+)\}/g, (e, n) => Object.hasOwn(t, n) ? t[n] : e);
736
+ }
737
+ function i(e, t, i = {}, a) {
738
+ let o = n[e];
739
+ return {
740
+ code: e,
741
+ severity: o.severity,
742
+ at: t,
743
+ ...a === void 0 ? {} : { slot: a },
744
+ message: r(o.message, i)
745
+ };
746
+ }
747
+ var a = class extends Error {
748
+ diagnostics;
749
+ constructor(e) {
750
+ super(e.map((e) => e.message).join("; ")), this.name = "ExpressionError", this.diagnostics = e;
751
+ }
752
+ get code() {
753
+ return this.diagnostics[0]?.code;
754
+ }
755
+ }, o = (e) => e.filter((e) => e.severity === "error"), s = (e) => e.some((e) => e.severity === "error");
756
+ //#endregion
757
+ //#region src/value.ts
758
+ function c(e) {
759
+ return e === null ? "null" : typeof e == "string" ? "text" : typeof e == "number" ? "number" : typeof e == "boolean" ? "boolean" : e instanceof Date ? "datetime" : Array.isArray(e) ? "list" : "object";
760
+ }
761
+ function l(e, t) {
762
+ if (t === "unknown" || t === "item" || e === null) return !0;
763
+ let n = c(e);
764
+ return n === t || t === "text" && u(n);
765
+ }
766
+ function u(e) {
767
+ return e === "text" || e === "number" || e === "boolean" || e === "datetime";
768
+ }
769
+ function d(e) {
770
+ return e === null ? "" : typeof e == "string" ? e : typeof e == "number" ? g(e) : typeof e == "boolean" ? e ? "true" : "false" : e instanceof Date ? f(e) : p(e);
771
+ }
772
+ function f(e) {
773
+ return e.toISOString().replace(/\.(\d*?)0*Z$/, (e, t) => t === "" ? "Z" : `.${t}Z`);
774
+ }
775
+ function p(e) {
776
+ return e === null ? "null" : typeof e == "string" ? te(e) : typeof e == "number" ? g(e) : typeof e == "boolean" ? e ? "true" : "false" : e instanceof Date ? te(f(e)) : Array.isArray(e) ? `[${e.map(p).join(",")}]` : `{${Object.keys(e).sort(m).map((t) => `${te(t)}:${p(e[t])}`).join(",")}}`;
777
+ }
778
+ var ee = {
779
+ "\"": "\\\"",
780
+ "\\": "\\\\",
781
+ "\n": "\\n",
782
+ "\r": "\\r",
783
+ " ": "\\t",
784
+ "\b": "\\b",
785
+ "\f": "\\f"
786
+ };
787
+ function te(e) {
788
+ let t = "";
789
+ for (let n of e) {
790
+ let e = ee[n];
791
+ if (e) {
792
+ t += e;
793
+ continue;
794
+ }
795
+ let r = n.codePointAt(0) ?? 0;
796
+ t += r < 32 ? `\\u${r.toString(16).padStart(4, "0")}` : n;
797
+ }
798
+ return `"${t}"`;
799
+ }
800
+ function m(e, t) {
801
+ let n = 0, r = 0;
802
+ for (; n < e.length && r < t.length;) {
803
+ let i = e.codePointAt(n), a = t.codePointAt(r);
804
+ if (i !== a) return i < a ? -1 : 1;
805
+ n += i > 65535 ? 2 : 1, r += a > 65535 ? 2 : 1;
806
+ }
807
+ return e.length - n - (t.length - r);
808
+ }
809
+ function h(e) {
810
+ return e < 0 ? -Math.round(-e) : Math.round(e);
811
+ }
812
+ function g(e) {
813
+ return String(e);
814
+ }
815
+ //#endregion
816
+ //#region src/functions/dt.ts
817
+ var _ = /^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/, ne = 864e13, re = [
818
+ 31,
819
+ 28,
820
+ 31,
821
+ 30,
822
+ 31,
823
+ 30,
824
+ 31,
825
+ 31,
826
+ 30,
827
+ 31,
828
+ 30,
829
+ 31
830
+ ], ie = (e) => e % 4 == 0 && e % 100 != 0 || e % 400 == 0;
831
+ function ae(e) {
832
+ let t = Number(e.slice(0, 4)), n = Number(e.slice(5, 7)), r = Number(e.slice(8, 10));
833
+ if (n < 1 || n > 12) return !1;
834
+ let i = n === 2 && ie(t) ? 29 : re[n - 1];
835
+ return r >= 1 && r <= i;
836
+ }
837
+ var oe = {
838
+ seconds: 1e3,
839
+ minutes: 6e4,
840
+ hours: 36e5,
841
+ days: 864e5
842
+ };
843
+ function se(e, t) {
844
+ let n = oe[e];
845
+ if (n === void 0) throw A(t, "unit", e);
846
+ return n;
847
+ }
848
+ var ce = {
849
+ "dt.now": (e, t) => {
850
+ if (!t.now) throw A("dt.now", "clock", "no clock in the context");
851
+ return new Date(t.now.getTime());
852
+ },
853
+ "dt.parse": (e) => {
854
+ let t = e[0], n = Date.parse(t);
855
+ if (!_.test(t) || Number.isNaN(n) || !ae(t)) throw A("dt.parse", "value", t);
856
+ return new Date(n);
857
+ },
858
+ "dt.iso": (e) => f(e[0]),
859
+ "dt.add": (e) => {
860
+ let [t, n, r] = e, i = se(r, "dt.add"), a = t.getTime() + h(n * i);
861
+ if (!Number.isFinite(a) || Math.abs(a) > ne) throw A("dt.add", "amount", String(n));
862
+ return new Date(a);
863
+ },
864
+ "dt.diff": (e) => {
865
+ let [t, n, r] = e, i = se(r, "dt.diff");
866
+ return Math.trunc((t.getTime() - n.getTime()) / i);
867
+ }
868
+ }, le = {
869
+ "json.parse": (e) => {
870
+ let t;
871
+ try {
872
+ t = JSON.parse(e[0]);
873
+ } catch {
874
+ throw A("json.parse", "value", "text that is not JSON");
875
+ }
876
+ if (ue(t)) throw A("json.parse", "value", "a number out of range");
877
+ return t;
878
+ },
879
+ "json.stringify": (e) => p(e[0])
880
+ };
881
+ function ue(e) {
882
+ return typeof e == "number" ? !Number.isFinite(e) : Array.isArray(e) ? e.some(ue) : typeof e == "object" && e && !(e instanceof Date) ? Object.values(e).some(ue) : !1;
883
+ }
884
+ //#endregion
885
+ //#region src/nodes.ts
886
+ function v(e) {
887
+ return e == null ? "" : typeof e == "string" ? e : Array.isArray(e) ? e.map(v).join("") : String(e);
888
+ }
889
+ function y(e) {
890
+ return e == null ? [] : Array.isArray(e) ? e : [e];
891
+ }
892
+ function de(e) {
893
+ return e && typeof e == "object" && "at" in e ? e.at : 0;
894
+ }
895
+ function b(...e) {
896
+ return v(e);
897
+ }
898
+ function fe(e) {
899
+ return {
900
+ kind: "Template",
901
+ segments: y(e)
902
+ };
903
+ }
904
+ function pe(e, t) {
905
+ return {
906
+ kind: "Hole",
907
+ at: e,
908
+ expr: t
909
+ };
910
+ }
911
+ function me(e) {
912
+ return {
913
+ kind: "Text",
914
+ value: v(e)
915
+ };
916
+ }
917
+ function he(e, t) {
918
+ let n = y(t);
919
+ return n.length === 0 ? e : {
920
+ kind: "Ternary",
921
+ at: de(e),
922
+ cond: e,
923
+ whenTrue: n[1],
924
+ whenFalse: n[3]
925
+ };
926
+ }
927
+ function x(e, t) {
928
+ let n = e;
929
+ for (let e of y(t)) {
930
+ let t = y(e);
931
+ n = {
932
+ kind: "Binary",
933
+ at: de(n),
934
+ op: v(t[0]),
935
+ left: n,
936
+ right: t[1]
937
+ };
938
+ }
939
+ return n;
940
+ }
941
+ function ge(e, t, n) {
942
+ return {
943
+ kind: "Unary",
944
+ at: e,
945
+ op: v(t),
946
+ operand: n
947
+ };
948
+ }
949
+ function _e(e) {
950
+ return e;
951
+ }
952
+ function ve(e, t) {
953
+ let n = e;
954
+ for (let e of y(t)) {
955
+ let t = e;
956
+ t.object = n, t.at = de(n), n = t;
957
+ }
958
+ return n;
959
+ }
960
+ function ye(e, t) {
961
+ return {
962
+ kind: "Member",
963
+ at: e,
964
+ name: v(t)
965
+ };
966
+ }
967
+ function be(e) {
968
+ return {
969
+ kind: "Project",
970
+ at: e
971
+ };
972
+ }
973
+ function xe(e, t) {
974
+ return {
975
+ kind: "Index",
976
+ at: e,
977
+ index: t
978
+ };
979
+ }
980
+ function Se(e, t) {
981
+ return {
982
+ kind: "Call",
983
+ at: e,
984
+ args: y(t)
985
+ };
986
+ }
987
+ function Ce(e, t) {
988
+ let n = [e];
989
+ for (let e of y(t)) n.push(y(e)[1]);
990
+ return n;
991
+ }
992
+ function we(e, t) {
993
+ return {
994
+ kind: "Name",
995
+ at: e,
996
+ name: v(t)
997
+ };
998
+ }
999
+ function Te(e) {
1000
+ return {
1001
+ kind: "Literal",
1002
+ at: e,
1003
+ type: "null",
1004
+ value: null
1005
+ };
1006
+ }
1007
+ function Ee(e, t) {
1008
+ return {
1009
+ kind: "Literal",
1010
+ at: e,
1011
+ type: "boolean",
1012
+ value: v(t) === "true"
1013
+ };
1014
+ }
1015
+ function De(e, t, n, r) {
1016
+ let i = v(t) + v(n) + v(r), a = Number(i);
1017
+ if (!Number.isFinite(a)) throw Error(`${i} is out of range`);
1018
+ return {
1019
+ kind: "Literal",
1020
+ at: e,
1021
+ type: "number",
1022
+ value: a
1023
+ };
1024
+ }
1025
+ function Oe(e, t) {
1026
+ return {
1027
+ kind: "Literal",
1028
+ at: e,
1029
+ type: "text",
1030
+ value: v(t)
1031
+ };
1032
+ }
1033
+ var ke = {
1034
+ n: "\n",
1035
+ t: " ",
1036
+ r: "\r",
1037
+ "\\": "\\",
1038
+ "'": "'",
1039
+ "\"": "\""
1040
+ };
1041
+ function Ae(e) {
1042
+ let t = v(e), n = ke[t];
1043
+ if (n === void 0) throw Error(`unknown escape \\${t}`);
1044
+ return n;
1045
+ }
1046
+ //#endregion
1047
+ //#region src/generated/parser.js
1048
+ var je = class extends SyntaxError {
1049
+ constructor(e, t, n, r) {
1050
+ super(e), this.expected = t, this.found = n, this.location = r, this.name = "SyntaxError";
1051
+ }
1052
+ format(e) {
1053
+ let t = "Error: " + this.message;
1054
+ if (this.location) {
1055
+ let n = null, r = e.find((e) => e.source === this.location.source);
1056
+ r && (n = r.text.split(/\r\n|\n|\r/g));
1057
+ let i = this.location.start, a = this.location.source && typeof this.location.source.offset == "function" ? this.location.source.offset(i) : i, o = this.location.source + ":" + a.line + ":" + a.column;
1058
+ if (n) {
1059
+ let e = this.location.end, r = "".padEnd(a.line.toString().length, " "), s = n[i.line - 1], c = (i.line === e.line ? e.column : s.length + 1) - i.column || 1;
1060
+ t += "\n --> " + o + "\n" + r + " |\n" + a.line + " | " + s + "\n" + r + " | " + "".padEnd(i.column - 1, " ") + "".padEnd(c, "^");
1061
+ } else t += "\n at " + o;
1062
+ }
1063
+ return t;
1064
+ }
1065
+ static buildMessage(e, t) {
1066
+ function n(e) {
1067
+ return e.codePointAt(0).toString(16).toUpperCase();
1068
+ }
1069
+ let r = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode") ? /* @__PURE__ */ RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu") : null;
1070
+ function i(e) {
1071
+ return r ? e.replace(r, (e) => "\\u{" + n(e) + "}") : e;
1072
+ }
1073
+ function a(e) {
1074
+ return i(e.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (e) => "\\x0" + n(e)).replace(/[\x10-\x1F\x7F-\x9F]/g, (e) => "\\x" + n(e)));
1075
+ }
1076
+ function o(e) {
1077
+ return i(e.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (e) => "\\x0" + n(e)).replace(/[\x10-\x1F\x7F-\x9F]/g, (e) => "\\x" + n(e)));
1078
+ }
1079
+ let s = {
1080
+ literal(e) {
1081
+ return "\"" + a(e.text) + "\"";
1082
+ },
1083
+ class(e) {
1084
+ let t = e.parts.map((e) => Array.isArray(e) ? o(e[0]) + "-" + o(e[1]) : o(e));
1085
+ return "[" + (e.inverted ? "^" : "") + t.join("") + "]" + (e.unicode ? "u" : "");
1086
+ },
1087
+ any() {
1088
+ return "any character";
1089
+ },
1090
+ end() {
1091
+ return "end of input";
1092
+ },
1093
+ other(e) {
1094
+ return e.description;
1095
+ }
1096
+ };
1097
+ function c(e) {
1098
+ return s[e.type](e);
1099
+ }
1100
+ function l(e) {
1101
+ let t = e.map(c);
1102
+ if (t.sort(), t.length > 0) {
1103
+ let e = 1;
1104
+ for (let n = 1; n < t.length; n++) t[n - 1] !== t[n] && (t[e] = t[n], e++);
1105
+ t.length = e;
1106
+ }
1107
+ switch (t.length) {
1108
+ case 1: return t[0];
1109
+ case 2: return t[0] + " or " + t[1];
1110
+ default: return t.slice(0, -1).join(", ") + ", or " + t[t.length - 1];
1111
+ }
1112
+ }
1113
+ function u(e) {
1114
+ return e ? "\"" + a(e) + "\"" : "end of input";
1115
+ }
1116
+ return "Expected " + l(e) + " but " + u(t) + " found.";
1117
+ }
1118
+ };
1119
+ function Me(e, t) {
1120
+ t = t === void 0 ? {} : t;
1121
+ let n = {}, r = t.grammarSource, i = {
1122
+ Template: Mt,
1123
+ ExpressionEntry: Lt
1124
+ }, a = Mt, o = "true", s = "false", c = "null", l = /^[<>]/, u = /^[+\-]/, d = /^[%*\/]/, f = /^[a-zA-Z_]/, p = /^[a-zA-Z0-9_]/, ee = /^[0-9]/, te = /^[eE]/, m = /^[ \t\r\n]/, h = H("{{", !1), g = H("}}", !1), _ = W(), ne = H("(", !1), re = H(")", !1), ie = H("?", !1), ae = H(":", !1), oe = H("??", !1), se = H("||", !1), ce = H("&&", !1), le = H("==", !1), ue = H("!=", !1), v = H("<=", !1), y = H(">=", !1), de = U(["<", ">"], !1, !1, !1), ke = U(["+", "-"], !1, !1, !1), Me = U([
1125
+ "%",
1126
+ "*",
1127
+ "/"
1128
+ ], !1, !1, !1), Ne = H("!", !1), Pe = H("=", !1), Fe = H("-", !1), S = H(".", !1), Ie = H("[", !1), Le = H("]", !1), Re = H(",", !1), ze = U([
1129
+ ["a", "z"],
1130
+ ["A", "Z"],
1131
+ "_"
1132
+ ], !1, !1, !1), Be = U([
1133
+ ["a", "z"],
1134
+ ["A", "Z"],
1135
+ ["0", "9"],
1136
+ "_"
1137
+ ], !1, !1, !1), Ve = H("true", !1), He = H("false", !1), Ue = H("null", !1), C = U([["0", "9"]], !1, !1, !1), w = U(["e", "E"], !1, !1, !1), T = H("'", !1), We = H("\"", !1), E = H("\\", !1), Ge = U([
1138
+ " ",
1139
+ " ",
1140
+ "\r",
1141
+ "\n"
1142
+ ], !1, !1, !1);
1143
+ function Ke(e) {
1144
+ return fe(e);
1145
+ }
1146
+ function qe(e, t) {
1147
+ return pe(e, t);
1148
+ }
1149
+ function Je(e) {
1150
+ return me(e);
1151
+ }
1152
+ function Ye(e) {
1153
+ return b(e);
1154
+ }
1155
+ function Xe(e) {
1156
+ return _e(e);
1157
+ }
1158
+ function Ze(e, t) {
1159
+ return he(e, t);
1160
+ }
1161
+ function Qe(e, t) {
1162
+ return x(e, t);
1163
+ }
1164
+ function $e(e, t) {
1165
+ return x(e, t);
1166
+ }
1167
+ function D(e, t) {
1168
+ return x(e, t);
1169
+ }
1170
+ function et(e, t) {
1171
+ return x(e, t);
1172
+ }
1173
+ function tt(e, t) {
1174
+ return x(e, t);
1175
+ }
1176
+ function nt(e, t) {
1177
+ return x(e, t);
1178
+ }
1179
+ function rt(e, t) {
1180
+ return x(e, t);
1181
+ }
1182
+ function it(e, t, n) {
1183
+ return ge(e, t, n);
1184
+ }
1185
+ function at(e, t) {
1186
+ return ve(e, t);
1187
+ }
1188
+ function ot(e) {
1189
+ return _e(e);
1190
+ }
1191
+ function st(e) {
1192
+ return b(e);
1193
+ }
1194
+ function ct(e) {
1195
+ return b(e);
1196
+ }
1197
+ function O(e) {
1198
+ return b(e);
1199
+ }
1200
+ function k(e) {
1201
+ return b(e);
1202
+ }
1203
+ function lt(e) {
1204
+ return b(e);
1205
+ }
1206
+ function ut(e) {
1207
+ return b(e);
1208
+ }
1209
+ function dt(e) {
1210
+ return b(e);
1211
+ }
1212
+ function ft(e) {
1213
+ return b(e);
1214
+ }
1215
+ function pt(e, t) {
1216
+ return ye(e, t);
1217
+ }
1218
+ function mt(e) {
1219
+ return be(e);
1220
+ }
1221
+ function ht(e, t) {
1222
+ return xe(e, t);
1223
+ }
1224
+ function gt(e, t) {
1225
+ return Se(e, t);
1226
+ }
1227
+ function _t(e, t) {
1228
+ return Ce(e, t);
1229
+ }
1230
+ function vt(e, t) {
1231
+ return we(e, t);
1232
+ }
1233
+ function A(e, t) {
1234
+ return b(e, t);
1235
+ }
1236
+ function yt(e) {
1237
+ return Te(e);
1238
+ }
1239
+ function bt(e, t) {
1240
+ return Ee(e, t);
1241
+ }
1242
+ function xt(e, t, n, r) {
1243
+ return De(e, t, n, r);
1244
+ }
1245
+ function j(e) {
1246
+ return b(e);
1247
+ }
1248
+ function M(e) {
1249
+ return b(".", e);
1250
+ }
1251
+ function St(e, t, n) {
1252
+ return b(e, t, n);
1253
+ }
1254
+ function Ct(e, t) {
1255
+ return Oe(e, t);
1256
+ }
1257
+ function N(e, t) {
1258
+ return Oe(e, t);
1259
+ }
1260
+ function wt(e) {
1261
+ return b(e);
1262
+ }
1263
+ function Tt(e) {
1264
+ return b(e);
1265
+ }
1266
+ function Et(e) {
1267
+ return Ae(e);
1268
+ }
1269
+ function Dt() {
1270
+ return V();
1271
+ }
1272
+ let P = t.peg$currPos | 0, F = P, I = [{
1273
+ line: 1,
1274
+ column: 1
1275
+ }], L = P, R = t.peg$maxFailExpected || [], z = t.peg$silentFails | 0, B;
1276
+ if (t.startRule) {
1277
+ if (!(t.startRule in i)) throw Error("Can't start parsing from rule \"" + t.startRule + "\".");
1278
+ a = i[t.startRule];
1279
+ }
1280
+ function V() {
1281
+ return F;
1282
+ }
1283
+ function Ot(t = P) {
1284
+ let n = e.codePointAt(t);
1285
+ return n === void 0 ? "" : String.fromCodePoint(n);
1286
+ }
1287
+ function H(e, t) {
1288
+ return {
1289
+ type: "literal",
1290
+ text: e,
1291
+ ignoreCase: t
1292
+ };
1293
+ }
1294
+ function U(e, t, n, r) {
1295
+ return {
1296
+ type: "class",
1297
+ parts: e,
1298
+ inverted: t,
1299
+ ignoreCase: n,
1300
+ unicode: r
1301
+ };
1302
+ }
1303
+ function W() {
1304
+ return { type: "any" };
1305
+ }
1306
+ function kt() {
1307
+ return { type: "end" };
1308
+ }
1309
+ function G(t) {
1310
+ let n = I[t], r;
1311
+ if (n) return n;
1312
+ if (t >= I.length) r = I.length - 1;
1313
+ else for (r = t; !I[--r];);
1314
+ for (n = I[r], n = {
1315
+ line: n.line,
1316
+ column: n.column
1317
+ }; r < t;) e.charCodeAt(r) === 10 ? (n.line++, n.column = 1) : n.column++, r++;
1318
+ return I[t] = n, n;
1319
+ }
1320
+ function At(e, t, n) {
1321
+ let i = G(e), a = G(t), o = {
1322
+ source: r,
1323
+ start: {
1324
+ offset: e,
1325
+ line: i.line,
1326
+ column: i.column
1327
+ },
1328
+ end: {
1329
+ offset: t,
1330
+ line: a.line,
1331
+ column: a.column
1332
+ }
1333
+ };
1334
+ return n && r && typeof r.offset == "function" && (o.start = r.offset(o.start), o.end = r.offset(o.end)), o;
1335
+ }
1336
+ function K(e) {
1337
+ P < L || (P > L && (L = P, R = []), R.push(e));
1338
+ }
1339
+ function jt(e, t, n) {
1340
+ return new je(je.buildMessage(e, t), e, t, n);
1341
+ }
1342
+ function Mt() {
1343
+ let e, t, r;
1344
+ for (e = P, t = [], r = Nt(); r !== n;) t.push(r), r = Nt();
1345
+ return r = kn(), r === n ? (P = e, e = n) : (F = e, e = Ke(t)), e;
1346
+ }
1347
+ function Nt() {
1348
+ let e;
1349
+ return e = Pt(), e === n && (e = Ft()), e;
1350
+ }
1351
+ function Pt() {
1352
+ let t, r, i, a, o;
1353
+ return t = P, e.substr(P, 2) === "{{" ? (r = "{{", P += 2) : (r = n, z === 0 && K(h)), r === n ? (P = t, t = n) : (Q(), i = $(), a = q(), a === n ? (P = t, t = n) : (Q(), e.substr(P, 2) === "}}" ? (o = "}}", P += 2) : (o = n, z === 0 && K(g)), o === n ? (P = t, t = n) : (F = t, t = qe(i, a)))), t;
1354
+ }
1355
+ function Ft() {
1356
+ let e, t, r;
1357
+ if (e = P, t = [], r = It(), r !== n) for (; r !== n;) t.push(r), r = It();
1358
+ else t = n;
1359
+ return t !== n && (F = e, t = Je(t)), e = t, e;
1360
+ }
1361
+ function It() {
1362
+ let t, r, i;
1363
+ return t = P, r = P, z++, e.substr(P, 2) === "{{" ? (i = "{{", P += 2) : (i = n, z === 0 && K(h)), z--, i === n ? r = void 0 : (P = r, r = n), r === n ? (P = t, t = n) : (e.length > P ? (i = e.charAt(P), P++) : (i = n, z === 0 && K(_)), i === n ? (P = t, t = n) : (F = t, t = Ye(i))), t;
1364
+ }
1365
+ function Lt() {
1366
+ let e, t, r;
1367
+ return e = P, t = q(), t === n ? (P = e, e = n) : (r = kn(), r === n ? (P = e, e = n) : (F = e, e = Xe(t))), e;
1368
+ }
1369
+ function q() {
1370
+ let e, t, r, i, a, o, s;
1371
+ return e = P, t = J(), t === n ? (P = e, e = n) : (r = P, i = Kt(), i === n ? (P = r, r = n) : (a = q(), a === n ? (P = r, r = n) : (o = qt(), o === n ? (P = r, r = n) : (s = q(), s === n ? (P = r, r = n) : (i = [
1372
+ i,
1373
+ a,
1374
+ o,
1375
+ s
1376
+ ], r = i)))), r === n && (r = null), F = e, e = Ze(t, r)), e;
1377
+ }
1378
+ function J() {
1379
+ let e, t, r, i, a, o;
1380
+ if (e = P, t = Y(), t !== n) {
1381
+ for (r = [], i = P, a = Jt(), a === n ? (P = i, i = n) : (o = Y(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = Jt(), a === n ? (P = i, i = n) : (o = Y(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1382
+ F = e, e = Qe(t, r);
1383
+ } else P = e, e = n;
1384
+ return e;
1385
+ }
1386
+ function Y() {
1387
+ let e, t, r, i, a, o;
1388
+ if (e = P, t = Rt(), t !== n) {
1389
+ for (r = [], i = P, a = Yt(), a === n ? (P = i, i = n) : (o = Rt(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = Yt(), a === n ? (P = i, i = n) : (o = Rt(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1390
+ F = e, e = $e(t, r);
1391
+ } else P = e, e = n;
1392
+ return e;
1393
+ }
1394
+ function Rt() {
1395
+ let e, t, r, i, a, o;
1396
+ if (e = P, t = zt(), t !== n) {
1397
+ for (r = [], i = P, a = Xt(), a === n ? (P = i, i = n) : (o = zt(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = Xt(), a === n ? (P = i, i = n) : (o = zt(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1398
+ F = e, e = D(t, r);
1399
+ } else P = e, e = n;
1400
+ return e;
1401
+ }
1402
+ function zt() {
1403
+ let e, t, r, i, a, o;
1404
+ if (e = P, t = Bt(), t !== n) {
1405
+ for (r = [], i = P, a = Zt(), a === n ? (P = i, i = n) : (o = Bt(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = Zt(), a === n ? (P = i, i = n) : (o = Bt(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1406
+ F = e, e = et(t, r);
1407
+ } else P = e, e = n;
1408
+ return e;
1409
+ }
1410
+ function Bt() {
1411
+ let e, t, r, i, a, o;
1412
+ if (e = P, t = Vt(), t !== n) {
1413
+ for (r = [], i = P, a = Qt(), a === n ? (P = i, i = n) : (o = Vt(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = Qt(), a === n ? (P = i, i = n) : (o = Vt(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1414
+ F = e, e = tt(t, r);
1415
+ } else P = e, e = n;
1416
+ return e;
1417
+ }
1418
+ function Vt() {
1419
+ let e, t, r, i, a, o;
1420
+ if (e = P, t = Ht(), t !== n) {
1421
+ for (r = [], i = P, a = $t(), a === n ? (P = i, i = n) : (o = Ht(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = $t(), a === n ? (P = i, i = n) : (o = Ht(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1422
+ F = e, e = nt(t, r);
1423
+ } else P = e, e = n;
1424
+ return e;
1425
+ }
1426
+ function Ht() {
1427
+ let e, t, r, i, a, o;
1428
+ if (e = P, t = X(), t !== n) {
1429
+ for (r = [], i = P, a = en(), a === n ? (P = i, i = n) : (o = X(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = en(), a === n ? (P = i, i = n) : (o = X(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1430
+ F = e, e = rt(t, r);
1431
+ } else P = e, e = n;
1432
+ return e;
1433
+ }
1434
+ function X() {
1435
+ let e, t, r, i;
1436
+ return e = P, t = $(), r = tn(), r === n ? (P = e, e = n) : (i = X(), i === n ? (P = e, e = n) : (F = e, e = it(t, r, i))), e === n && (e = Ut()), e;
1437
+ }
1438
+ function Ut() {
1439
+ let e, t, r, i;
1440
+ if (e = P, t = Wt(), t !== n) {
1441
+ for (r = [], i = nn(); i !== n;) r.push(i), i = nn();
1442
+ F = e, e = at(t, r);
1443
+ } else P = e, e = n;
1444
+ return e;
1445
+ }
1446
+ function Wt() {
1447
+ let e;
1448
+ return e = Gt(), e === n && (e = mn(), e === n && (e = un())), e;
1449
+ }
1450
+ function Gt() {
1451
+ let t, r, i, a;
1452
+ return t = P, e.charCodeAt(P) === 40 ? (r = "(", P++) : (r = n, z === 0 && K(ne)), r === n ? (P = t, t = n) : (Q(), i = q(), i === n ? (P = t, t = n) : (Q(), e.charCodeAt(P) === 41 ? (a = ")", P++) : (a = n, z === 0 && K(re)), a === n ? (P = t, t = n) : (F = t, t = ot(i)))), t;
1453
+ }
1454
+ function Kt() {
1455
+ let t, r, i, a, o;
1456
+ return t = P, r = Q(), e.charCodeAt(P) === 63 ? (i = "?", P++) : (i = n, z === 0 && K(ie)), i === n ? (P = t, t = n) : (a = P, z++, e.charCodeAt(P) === 63 ? (o = "?", P++) : (o = n, z === 0 && K(ie)), z--, o === n ? a = void 0 : (P = a, a = n), a === n ? (P = t, t = n) : (o = Q(), r = [
1457
+ r,
1458
+ i,
1459
+ a,
1460
+ o
1461
+ ], t = r)), t;
1462
+ }
1463
+ function qt() {
1464
+ let t, r, i, a;
1465
+ return t = P, r = Q(), e.charCodeAt(P) === 58 ? (i = ":", P++) : (i = n, z === 0 && K(ae)), i === n ? (P = t, t = n) : (a = Q(), r = [
1466
+ r,
1467
+ i,
1468
+ a
1469
+ ], t = r), t;
1470
+ }
1471
+ function Jt() {
1472
+ let t, r;
1473
+ return t = P, Q(), e.substr(P, 2) === "??" ? (r = "??", P += 2) : (r = n, z === 0 && K(oe)), r === n ? (P = t, t = n) : (Q(), F = t, t = st(r)), t;
1474
+ }
1475
+ function Yt() {
1476
+ let t, r;
1477
+ return t = P, Q(), e.substr(P, 2) === "||" ? (r = "||", P += 2) : (r = n, z === 0 && K(se)), r === n ? (P = t, t = n) : (Q(), F = t, t = ct(r)), t;
1478
+ }
1479
+ function Xt() {
1480
+ let t, r;
1481
+ return t = P, Q(), e.substr(P, 2) === "&&" ? (r = "&&", P += 2) : (r = n, z === 0 && K(ce)), r === n ? (P = t, t = n) : (Q(), F = t, t = O(r)), t;
1482
+ }
1483
+ function Zt() {
1484
+ let t, r;
1485
+ return t = P, Q(), e.substr(P, 2) === "==" ? (r = "==", P += 2) : (r = n, z === 0 && K(le)), r === n && (e.substr(P, 2) === "!=" ? (r = "!=", P += 2) : (r = n, z === 0 && K(ue))), r === n ? (P = t, t = n) : (Q(), F = t, t = k(r)), t;
1486
+ }
1487
+ function Qt() {
1488
+ let t, r;
1489
+ return t = P, Q(), e.substr(P, 2) === "<=" ? (r = "<=", P += 2) : (r = n, z === 0 && K(v)), r === n && (e.substr(P, 2) === ">=" ? (r = ">=", P += 2) : (r = n, z === 0 && K(y)), r === n && (r = e.charAt(P), l.test(r) ? P++ : (r = n, z === 0 && K(de)))), r === n ? (P = t, t = n) : (Q(), F = t, t = lt(r)), t;
1490
+ }
1491
+ function $t() {
1492
+ let t, r;
1493
+ return t = P, Q(), r = e.charAt(P), u.test(r) ? P++ : (r = n, z === 0 && K(ke)), r === n ? (P = t, t = n) : (Q(), F = t, t = ut(r)), t;
1494
+ }
1495
+ function en() {
1496
+ let t, r;
1497
+ return t = P, Q(), r = e.charAt(P), d.test(r) ? P++ : (r = n, z === 0 && K(Me)), r === n ? (P = t, t = n) : (Q(), F = t, t = dt(r)), t;
1498
+ }
1499
+ function tn() {
1500
+ let t, r, i, a, o;
1501
+ return t = P, r = P, e.charCodeAt(P) === 33 ? (i = "!", P++) : (i = n, z === 0 && K(Ne)), i === n ? (P = r, r = n) : (a = P, z++, e.charCodeAt(P) === 61 ? (o = "=", P++) : (o = n, z === 0 && K(Pe)), z--, o === n ? a = void 0 : (P = a, a = n), a === n ? (P = r, r = n) : (i = [i, a], r = i)), r === n && (e.charCodeAt(P) === 45 ? (r = "-", P++) : (r = n, z === 0 && K(Fe))), r === n ? (P = t, t = n) : (i = Q(), F = t, t = ft(r)), t;
1502
+ }
1503
+ function nn() {
1504
+ let e;
1505
+ return e = rn(), e === n && (e = an(), e === n && (e = on(), e === n && (e = sn()))), e;
1506
+ }
1507
+ function rn() {
1508
+ let t, r, i, a;
1509
+ return t = P, r = $(), e.charCodeAt(P) === 46 ? (i = ".", P++) : (i = n, z === 0 && K(S)), i === n ? (P = t, t = n) : (a = dn(), a === n ? (P = t, t = n) : (F = t, t = pt(r, a))), t;
1510
+ }
1511
+ function an() {
1512
+ let t, r, i, a;
1513
+ return t = P, r = $(), e.charCodeAt(P) === 91 ? (i = "[", P++) : (i = n, z === 0 && K(Ie)), i === n ? (P = t, t = n) : (Q(), e.charCodeAt(P) === 93 ? (a = "]", P++) : (a = n, z === 0 && K(Le)), a === n ? (P = t, t = n) : (F = t, t = mt(r))), t;
1514
+ }
1515
+ function on() {
1516
+ let t, r, i, a, o;
1517
+ return t = P, r = $(), e.charCodeAt(P) === 91 ? (i = "[", P++) : (i = n, z === 0 && K(Ie)), i === n ? (P = t, t = n) : (Q(), a = q(), a === n ? (P = t, t = n) : (Q(), e.charCodeAt(P) === 93 ? (o = "]", P++) : (o = n, z === 0 && K(Le)), o === n ? (P = t, t = n) : (F = t, t = ht(r, a)))), t;
1518
+ }
1519
+ function sn() {
1520
+ let t, r, i, a, o;
1521
+ return t = P, r = $(), e.charCodeAt(P) === 40 ? (i = "(", P++) : (i = n, z === 0 && K(ne)), i === n ? (P = t, t = n) : (Q(), a = cn(), a === n && (a = null), Q(), e.charCodeAt(P) === 41 ? (o = ")", P++) : (o = n, z === 0 && K(re)), o === n ? (P = t, t = n) : (F = t, t = gt(r, a))), t;
1522
+ }
1523
+ function cn() {
1524
+ let e, t, r, i, a, o;
1525
+ if (e = P, t = q(), t !== n) {
1526
+ for (r = [], i = P, a = ln(), a === n ? (P = i, i = n) : (o = q(), o === n ? (P = i, i = n) : (a = [a, o], i = a)); i !== n;) r.push(i), i = P, a = ln(), a === n ? (P = i, i = n) : (o = q(), o === n ? (P = i, i = n) : (a = [a, o], i = a));
1527
+ F = e, e = _t(t, r);
1528
+ } else P = e, e = n;
1529
+ return e;
1530
+ }
1531
+ function ln() {
1532
+ let t, r, i, a;
1533
+ return t = P, r = Q(), e.charCodeAt(P) === 44 ? (i = ",", P++) : (i = n, z === 0 && K(Re)), i === n ? (P = t, t = n) : (a = Q(), r = [
1534
+ r,
1535
+ i,
1536
+ a
1537
+ ], t = r), t;
1538
+ }
1539
+ function un() {
1540
+ let e, t, r, i;
1541
+ return e = P, t = $(), r = P, z++, i = pn(), z--, i === n ? r = void 0 : (P = r, r = n), r === n ? (P = e, e = n) : (i = dn(), i === n ? (P = e, e = n) : (F = e, e = vt(t, i))), e;
1542
+ }
1543
+ function dn() {
1544
+ let e, t, r, i;
1545
+ if (e = P, t = fn(), t !== n) {
1546
+ for (r = [], i = Z(); i !== n;) r.push(i), i = Z();
1547
+ F = e, e = A(t, r);
1548
+ } else P = e, e = n;
1549
+ return e;
1550
+ }
1551
+ function fn() {
1552
+ let t;
1553
+ return t = e.charAt(P), f.test(t) ? P++ : (t = n, z === 0 && K(ze)), t;
1554
+ }
1555
+ function Z() {
1556
+ let t;
1557
+ return t = e.charAt(P), p.test(t) ? P++ : (t = n, z === 0 && K(Be)), t;
1558
+ }
1559
+ function pn() {
1560
+ let t, r, i, a;
1561
+ return t = P, e.substr(P, 4) === o ? (r = o, P += 4) : (r = n, z === 0 && K(Ve)), r === n && (e.substr(P, 5) === s ? (r = s, P += 5) : (r = n, z === 0 && K(He)), r === n && (e.substr(P, 4) === c ? (r = c, P += 4) : (r = n, z === 0 && K(Ue)))), r === n ? (P = t, t = n) : (i = P, z++, a = Z(), z--, a === n ? i = void 0 : (P = i, i = n), i === n ? (P = t, t = n) : (r = [r, i], t = r)), t;
1562
+ }
1563
+ function mn() {
1564
+ let e;
1565
+ return e = hn(), e === n && (e = gn(), e === n && (e = _n(), e === n && (e = wn()))), e;
1566
+ }
1567
+ function hn() {
1568
+ let t, r, i, a, o;
1569
+ return t = P, r = $(), e.substr(P, 4) === c ? (i = c, P += 4) : (i = n, z === 0 && K(Ue)), i === n ? (P = t, t = n) : (a = P, z++, o = Z(), z--, o === n ? a = void 0 : (P = a, a = n), a === n ? (P = t, t = n) : (F = t, t = yt(r))), t;
1570
+ }
1571
+ function gn() {
1572
+ let t, r, i, a, c;
1573
+ return t = P, r = $(), e.substr(P, 4) === o ? (i = o, P += 4) : (i = n, z === 0 && K(Ve)), i === n && (e.substr(P, 5) === s ? (i = s, P += 5) : (i = n, z === 0 && K(He))), i === n ? (P = t, t = n) : (a = P, z++, c = Z(), z--, c === n ? a = void 0 : (P = a, a = n), a === n ? (P = t, t = n) : (F = t, t = bt(r, i))), t;
1574
+ }
1575
+ function _n() {
1576
+ let e, t, r, i, a;
1577
+ return e = P, t = $(), r = vn(), r === n ? (P = e, e = n) : (i = bn(), i === n && (i = null), a = xn(), a === n && (a = null), F = e, e = xt(t, r, i, a)), e;
1578
+ }
1579
+ function vn() {
1580
+ let e, t, r;
1581
+ if (e = P, t = [], r = yn(), r !== n) for (; r !== n;) t.push(r), r = yn();
1582
+ else t = n;
1583
+ return t !== n && (F = e, t = j(t)), e = t, e;
1584
+ }
1585
+ function yn() {
1586
+ let t;
1587
+ return t = e.charAt(P), ee.test(t) ? P++ : (t = n, z === 0 && K(C)), t;
1588
+ }
1589
+ function bn() {
1590
+ let t, r, i;
1591
+ return t = P, e.charCodeAt(P) === 46 ? (r = ".", P++) : (r = n, z === 0 && K(S)), r === n ? (P = t, t = n) : (i = vn(), i === n ? (P = t, t = n) : (F = t, t = M(i))), t;
1592
+ }
1593
+ function xn() {
1594
+ let e, t, r, i;
1595
+ return e = P, t = Sn(), t === n ? (P = e, e = n) : (r = Cn(), r === n && (r = null), i = vn(), i === n ? (P = e, e = n) : (F = e, e = St(t, r, i))), e;
1596
+ }
1597
+ function Sn() {
1598
+ let t;
1599
+ return t = e.charAt(P), te.test(t) ? P++ : (t = n, z === 0 && K(w)), t;
1600
+ }
1601
+ function Cn() {
1602
+ let t;
1603
+ return t = e.charAt(P), u.test(t) ? P++ : (t = n, z === 0 && K(ke)), t;
1604
+ }
1605
+ function wn() {
1606
+ let t, r, i, a, o;
1607
+ if (t = P, r = $(), e.charCodeAt(P) === 39 ? (i = "'", P++) : (i = n, z === 0 && K(T)), i !== n) {
1608
+ for (a = [], o = Tn(); o !== n;) a.push(o), o = Tn();
1609
+ e.charCodeAt(P) === 39 ? (o = "'", P++) : (o = n, z === 0 && K(T)), o === n ? (P = t, t = n) : (F = t, t = Ct(r, a));
1610
+ } else P = t, t = n;
1611
+ if (t === n) {
1612
+ if (t = P, r = $(), e.charCodeAt(P) === 34 ? (i = "\"", P++) : (i = n, z === 0 && K(We)), i !== n) {
1613
+ for (a = [], o = En(); o !== n;) a.push(o), o = En();
1614
+ e.charCodeAt(P) === 34 ? (o = "\"", P++) : (o = n, z === 0 && K(We)), o === n ? (P = t, t = n) : (F = t, t = N(r, a));
1615
+ } else P = t, t = n;
1616
+ }
1617
+ return t;
1618
+ }
1619
+ function Tn() {
1620
+ let t, r, i, a;
1621
+ return t = Dn(), t === n && (t = P, r = P, z++, e.charCodeAt(P) === 39 ? (i = "'", P++) : (i = n, z === 0 && K(T)), z--, i === n ? r = void 0 : (P = r, r = n), r === n ? (P = t, t = n) : (i = P, z++, e.charCodeAt(P) === 92 ? (a = "\\", P++) : (a = n, z === 0 && K(E)), z--, a === n ? i = void 0 : (P = i, i = n), i === n ? (P = t, t = n) : (e.length > P ? (a = e.charAt(P), P++) : (a = n, z === 0 && K(_)), a === n ? (P = t, t = n) : (F = t, t = wt(a))))), t;
1622
+ }
1623
+ function En() {
1624
+ let t, r, i, a;
1625
+ return t = Dn(), t === n && (t = P, r = P, z++, e.charCodeAt(P) === 34 ? (i = "\"", P++) : (i = n, z === 0 && K(We)), z--, i === n ? r = void 0 : (P = r, r = n), r === n ? (P = t, t = n) : (i = P, z++, e.charCodeAt(P) === 92 ? (a = "\\", P++) : (a = n, z === 0 && K(E)), z--, a === n ? i = void 0 : (P = i, i = n), i === n ? (P = t, t = n) : (e.length > P ? (a = e.charAt(P), P++) : (a = n, z === 0 && K(_)), a === n ? (P = t, t = n) : (F = t, t = Tt(a))))), t;
1626
+ }
1627
+ function Dn() {
1628
+ let t, r, i;
1629
+ return t = P, e.charCodeAt(P) === 92 ? (r = "\\", P++) : (r = n, z === 0 && K(E)), r === n ? (P = t, t = n) : (e.length > P ? (i = e.charAt(P), P++) : (i = n, z === 0 && K(_)), i === n ? (P = t, t = n) : (F = t, t = Et(i))), t;
1630
+ }
1631
+ function Q() {
1632
+ let e, t;
1633
+ for (e = [], t = On(); t !== n;) e.push(t), t = On();
1634
+ return e;
1635
+ }
1636
+ function On() {
1637
+ let t;
1638
+ return t = e.charAt(P), m.test(t) ? P++ : (t = n, z === 0 && K(Ge)), t;
1639
+ }
1640
+ function kn() {
1641
+ let t, r;
1642
+ return t = P, z++, e.length > P ? (r = e.charAt(P), P++) : (r = n, z === 0 && K(_)), z--, r === n ? t = void 0 : (P = t, t = n), t;
1643
+ }
1644
+ function $() {
1645
+ let e, t;
1646
+ return e = P, t = "", F = e, t = Dt(), e = t, e;
1647
+ }
1648
+ B = a();
1649
+ let An = B !== n && P === e.length;
1650
+ function jn() {
1651
+ throw B !== n && P < e.length && K(kt()), jt(R, L < e.length ? Ot(L) : null, L < e.length ? At(L, L + 1) : At(L, L));
1652
+ }
1653
+ if (t.peg$library) return {
1654
+ peg$result: B,
1655
+ peg$currPos: P,
1656
+ peg$FAILED: n,
1657
+ peg$maxFailExpected: R,
1658
+ peg$maxFailPos: L,
1659
+ peg$success: An,
1660
+ peg$throw: An ? void 0 : jn
1661
+ };
1662
+ if (An) return B;
1663
+ jn();
1664
+ }
1665
+ //#endregion
1666
+ //#region src/parse.ts
1667
+ var Ne = (e) => e?.location?.start?.offset ?? 0;
1668
+ function Pe(e) {
1669
+ try {
1670
+ return Me(e, { startRule: "Template" });
1671
+ } catch (e) {
1672
+ throw new a([i("EXPR_PARSE_ERROR", Ne(e), { detail: Ie(e) })]);
1673
+ }
1674
+ }
1675
+ function Fe(e) {
1676
+ try {
1677
+ return Me(e, { startRule: "ExpressionEntry" });
1678
+ } catch (e) {
1679
+ throw new a([i("EXPR_PARSE_ERROR", Ne(e), { detail: Ie(e) })]);
1680
+ }
1681
+ }
1682
+ function S(e) {
1683
+ try {
1684
+ return {
1685
+ ok: !0,
1686
+ template: Pe(e)
1687
+ };
1688
+ } catch (e) {
1689
+ if (e instanceof a) return {
1690
+ ok: !1,
1691
+ diagnostics: e.diagnostics
1692
+ };
1693
+ throw e;
1694
+ }
1695
+ }
1696
+ var Ie = (e) => e instanceof Error ? e.message : String(e);
1697
+ //#endregion
1698
+ //#region src/resolve.ts
1699
+ function Le(e, t) {
1700
+ let n = ze(e, t);
1701
+ if (n.diagnostics.length > 0) throw new a(n.diagnostics);
1702
+ return n.value;
1703
+ }
1704
+ function Re(e, t) {
1705
+ let n = {}, r = [];
1706
+ for (let i of t) {
1707
+ let t = ze(e, i);
1708
+ r.push(...t.diagnostics), t.diagnostics.length === 0 && (n[i.name] = t.value);
1709
+ }
1710
+ if (r.length > 0) throw new a(r);
1711
+ return n;
1712
+ }
1713
+ function ze(e, t) {
1714
+ try {
1715
+ return {
1716
+ value: Be(e, t),
1717
+ diagnostics: []
1718
+ };
1719
+ } catch (e) {
1720
+ if (e instanceof a) return {
1721
+ value: null,
1722
+ diagnostics: e.diagnostics.map((e) => ({
1723
+ ...e,
1724
+ slot: t.name
1725
+ }))
1726
+ };
1727
+ throw e;
1728
+ }
1729
+ }
1730
+ function Be(e, t) {
1731
+ let n = Pe(t.template), r = Ve(n);
1732
+ return r ? Ue(T(r, e), t.expectedType, r.at) : Ue(He(n, e), t.expectedType, 0);
1733
+ }
1734
+ function Ve(e) {
1735
+ let [t] = e.segments;
1736
+ return e.segments.length === 1 && t?.kind === "Hole" ? t.expr : null;
1737
+ }
1738
+ function He(e, t) {
1739
+ let n = "";
1740
+ for (let r of e.segments) {
1741
+ if (r.kind === "Text") {
1742
+ n += r.value;
1743
+ continue;
1744
+ }
1745
+ let e = T(r.expr, t);
1746
+ if (e !== null) {
1747
+ if (!u(c(e))) throw k("EVAL_TYPE_MISMATCH", r.at, {
1748
+ name: "this text",
1749
+ expected: "text",
1750
+ actual: c(e)
1751
+ });
1752
+ n += d(e);
1753
+ }
1754
+ }
1755
+ return n;
1756
+ }
1757
+ function Ue(e, t, n) {
1758
+ if (!l(e, t)) throw k("EVAL_TYPE_MISMATCH", n, {
1759
+ name: "this value",
1760
+ expected: t,
1761
+ actual: c(e)
1762
+ });
1763
+ return t === "text" && e !== null && typeof e != "string" ? d(e) : e;
1764
+ }
1765
+ var C = Symbol("missing"), w = class {
1766
+ items;
1767
+ constructor(e) {
1768
+ this.items = e;
1769
+ }
1770
+ };
1771
+ function T(e, t) {
1772
+ return We(E(e, t), e, t);
1773
+ }
1774
+ function We(e, t, n) {
1775
+ if (e === C) {
1776
+ if (n.onMissing === "null") return null;
1777
+ throw k("EVAL_MISSING_PATH", t.at, { name: O(t) });
1778
+ }
1779
+ return e instanceof w ? [...e.items] : e;
1780
+ }
1781
+ function E(e, t) {
1782
+ switch (e.kind) {
1783
+ case "Literal": return e.value;
1784
+ case "Name": return Ke(e.name, t);
1785
+ case "Member": return Ge(E(e.object, t), (t) => qe(t, e.name));
1786
+ case "Index": return Ge(E(e.object, t), (n) => Je(n, T(e.index, t), e.at));
1787
+ case "Project": return Ye(E(e.object, t), e.at);
1788
+ case "Call": return at(e, t);
1789
+ case "Unary": return Xe(e.op, T(e.operand, t), e.at);
1790
+ case "Binary": return Ze(e, t);
1791
+ case "Ternary": return Qe(e.cond, t) ? T(e.whenTrue, t) : T(e.whenFalse, t);
1792
+ }
1793
+ }
1794
+ function Ge(e, t) {
1795
+ return e === C ? C : e instanceof w ? new w(e.items.map((e) => {
1796
+ let n = t(e);
1797
+ return n === C ? null : n instanceof w ? [...n.items] : n;
1798
+ })) : t(e);
1799
+ }
1800
+ function Ke(e, t) {
1801
+ return e === "TRIGGER" ? t.TRIGGER ? t.TRIGGER : C : e === "triggers" ? t.triggers ?? {} : e === "var" ? t.var ?? {} : e === "run" ? t.run ?? {} : e === "steps" ? t.steps ?? {} : e === "params" ? t.params ?? {} : C;
1802
+ }
1803
+ function qe(e, t) {
1804
+ return e === null ? null : typeof e != "object" || Array.isArray(e) || e instanceof Date ? C : Object.hasOwn(e, t) ? e[t] : C;
1805
+ }
1806
+ function Je(e, t, n) {
1807
+ if (e === null) return null;
1808
+ if (typeof t == "number") {
1809
+ if (!Array.isArray(e)) throw k("EVAL_OPERAND_TYPE", n, {
1810
+ op: "[]",
1811
+ expected: "list",
1812
+ actual: c(e)
1813
+ });
1814
+ if (!Number.isInteger(t)) throw k("EVAL_OPERAND_TYPE", n, {
1815
+ op: "[]",
1816
+ expected: "a whole number",
1817
+ actual: "a fraction"
1818
+ });
1819
+ let r = t < 0 ? e.length + t : t;
1820
+ return r >= 0 && r < e.length ? e[r] : C;
1821
+ }
1822
+ if (typeof t == "string") return qe(e, t);
1823
+ throw k("EVAL_OPERAND_TYPE", n, {
1824
+ op: "[]",
1825
+ expected: "number or text",
1826
+ actual: c(t)
1827
+ });
1828
+ }
1829
+ function Ye(e, t) {
1830
+ if (e === C) return C;
1831
+ if (e instanceof w) return e;
1832
+ if (e === null) return null;
1833
+ if (!Array.isArray(e)) throw k("EVAL_OPERAND_TYPE", t, {
1834
+ op: "[]",
1835
+ expected: "list",
1836
+ actual: c(e)
1837
+ });
1838
+ return new w(e);
1839
+ }
1840
+ function Xe(e, t, n) {
1841
+ if (e === "!") {
1842
+ if (typeof t != "boolean") throw k("EVAL_OPERAND_TYPE", n, {
1843
+ op: "!",
1844
+ expected: "boolean",
1845
+ actual: c(t)
1846
+ });
1847
+ return !t;
1848
+ }
1849
+ if (typeof t != "number") throw k("EVAL_OPERAND_TYPE", n, {
1850
+ op: "-",
1851
+ expected: "number",
1852
+ actual: c(t)
1853
+ });
1854
+ return -t;
1855
+ }
1856
+ function Ze(e, t) {
1857
+ let { op: n, at: r } = e;
1858
+ if (n === "??") {
1859
+ let n = T(e.left, t);
1860
+ return n === null ? T(e.right, t) : n;
1861
+ }
1862
+ if (n === "&&" || n === "||") {
1863
+ let r = $e(T(e.left, t), n, e.left.at);
1864
+ return n === "&&" && !r ? !1 : n === "||" && r ? !0 : $e(T(e.right, t), n, e.right.at);
1865
+ }
1866
+ let i = T(e.left, t), a = T(e.right, t);
1867
+ return n === "==" ? D(i, a) : n === "!=" ? !D(i, a) : n === "<" || n === "<=" || n === ">" || n === ">=" ? tt(n, i, a, r) : rt(n, i, a, r);
1868
+ }
1869
+ function Qe(e, t) {
1870
+ return $e(T(e, t), "? :", e.at);
1871
+ }
1872
+ function $e(e, t, n) {
1873
+ if (typeof e != "boolean") throw k("EVAL_OPERAND_TYPE", n, {
1874
+ op: t,
1875
+ expected: "boolean",
1876
+ actual: c(e)
1877
+ });
1878
+ return e;
1879
+ }
1880
+ function D(e, t) {
1881
+ let n = c(e);
1882
+ if (n !== c(t)) return !1;
1883
+ switch (n) {
1884
+ case "null": return !0;
1885
+ case "datetime": return e.getTime() === t.getTime();
1886
+ case "list": {
1887
+ let n = e, r = t;
1888
+ return n.length === r.length && n.every((e, t) => D(e, r[t]));
1889
+ }
1890
+ case "object": {
1891
+ let n = e, r = t, i = Object.keys(n);
1892
+ return i.length === Object.keys(r).length && i.every((e) => Object.hasOwn(r, e) && D(n[e], r[e]));
1893
+ }
1894
+ default: return e === t;
1895
+ }
1896
+ }
1897
+ var et = /* @__PURE__ */ new Set([
1898
+ "number",
1899
+ "text",
1900
+ "datetime"
1901
+ ]);
1902
+ function tt(e, t, n, r) {
1903
+ if (t === null || n === null) throw k("EVAL_COMPARE_NULL", r, { op: e });
1904
+ let i = c(t);
1905
+ if (i !== c(n)) throw k("EVAL_COMPARE_TYPES", r, {
1906
+ op: e,
1907
+ expected: i,
1908
+ actual: c(n)
1909
+ });
1910
+ if (!et.has(i)) throw k("EVAL_OPERAND_TYPE", r, {
1911
+ op: e,
1912
+ expected: "number, text or datetime",
1913
+ actual: i
1914
+ });
1915
+ let a = i === "text" ? m(t, n) : nt(i === "datetime" ? t.getTime() : t, i === "datetime" ? n.getTime() : n);
1916
+ switch (e) {
1917
+ case "<": return a < 0;
1918
+ case "<=": return a <= 0;
1919
+ case ">": return a > 0;
1920
+ default: return a >= 0;
1921
+ }
1922
+ }
1923
+ function nt(e, t) {
1924
+ return e === t ? 0 : e < t ? -1 : 1;
1925
+ }
1926
+ function rt(e, t, n, r) {
1927
+ if (typeof t != "number") throw k("EVAL_OPERAND_TYPE", r, {
1928
+ op: e,
1929
+ expected: "number",
1930
+ actual: c(t)
1931
+ });
1932
+ if (typeof n != "number") throw k("EVAL_OPERAND_TYPE", r, {
1933
+ op: e,
1934
+ expected: "number",
1935
+ actual: c(n)
1936
+ });
1937
+ if ((e === "/" || e === "%") && n === 0) throw k("EVAL_DIVISION_BY_ZERO", r, {});
1938
+ let i = it(e, t, n);
1939
+ if (!Number.isFinite(i)) throw k("EVAL_NUMERIC_OVERFLOW", r, { op: e });
1940
+ return i;
1941
+ }
1942
+ function it(e, t, n) {
1943
+ switch (e) {
1944
+ case "+": return t + n;
1945
+ case "-": return t - n;
1946
+ case "*": return t * n;
1947
+ case "/": return t / n;
1948
+ default: return t % n;
1949
+ }
1950
+ }
1951
+ function at(e, t) {
1952
+ let n = O(e.object), r = t.functions?.get(n);
1953
+ if (!r) throw k("EVAL_UNKNOWN_FUNCTION", e.at, { name: n });
1954
+ let i = e.args.map((e) => T(e, t)), o = st(r.spec, i, e.at);
1955
+ try {
1956
+ return r.impl(o, t);
1957
+ } catch (t) {
1958
+ throw t instanceof a ? ot(t, e.at) : t;
1959
+ }
1960
+ }
1961
+ function ot(e, t) {
1962
+ return new a(e.diagnostics.map((e) => e.at === 0 ? {
1963
+ ...e,
1964
+ at: t
1965
+ } : e));
1966
+ }
1967
+ function st(e, t, n) {
1968
+ let r = e.params.at(-1)?.variadic === !0, i = e.params.filter((e) => !e.optional).length, a = r ? Infinity : e.params.length;
1969
+ if (t.length < i || t.length > a) throw k("EVAL_ARITY_MISMATCH", n, {
1970
+ name: e.qualified,
1971
+ expected: r ? `at least ${i}` : ct(i, e.params.length),
1972
+ actual: String(t.length)
1973
+ });
1974
+ return t.map((t, r) => {
1975
+ let i = e.params[Math.min(r, e.params.length - 1)];
1976
+ if (!i || i.type === "unknown") return t;
1977
+ if (t === null || !l(t, i.type)) throw k("EVAL_BAD_ARGUMENT", n, {
1978
+ name: e.qualified,
1979
+ param: i.name,
1980
+ actual: c(t)
1981
+ });
1982
+ return i.type === "text" && typeof t != "string" ? d(t) : t;
1983
+ });
1984
+ }
1985
+ var ct = (e, t) => e === t ? String(e) : `${e} to ${t}`;
1986
+ function O(e) {
1987
+ switch (e.kind) {
1988
+ case "Name": return e.name;
1989
+ case "Member": return `${O(e.object)}.${e.name}`;
1990
+ case "Project": return `${O(e.object)}[]`;
1991
+ case "Index": return `${O(e.object)}[…]`;
1992
+ case "Call": return `${O(e.object)}()`;
1993
+ default: return "this expression";
1994
+ }
1995
+ }
1996
+ function k(e, t, n) {
1997
+ return new a([i(e, t, n)]);
1998
+ }
1999
+ //#endregion
2000
+ //#region src/functions/list.ts
2001
+ var lt = (e, t) => Math.min(Math.max(Math.trunc(e), 0), t);
2002
+ function ut(e, t, n) {
2003
+ let r = lt(t < 0 ? e + t : t, e), i = n === null ? e : lt(n < 0 ? e + n : n, e);
2004
+ return [r, Math.max(r, i)];
2005
+ }
2006
+ var dt = [
2007
+ "number",
2008
+ "text",
2009
+ "datetime"
2010
+ ], ft = {
2011
+ "list.len": (e) => e[0].length,
2012
+ "list.first": (e) => e[0][0] ?? null,
2013
+ "list.last": (e) => e[0].at(-1) ?? null,
2014
+ "list.slice": (e) => {
2015
+ let [t, n, r] = e, [i, a] = ut(t.length, n, r === void 0 ? null : r);
2016
+ return t.slice(i, a);
2017
+ },
2018
+ "list.contains": (e) => {
2019
+ let [t, n] = e;
2020
+ return t.some((e) => D(e, n));
2021
+ },
2022
+ "list.join": (e) => {
2023
+ let [t, n] = e;
2024
+ return t.map((e) => {
2025
+ if (e !== null && !u(c(e))) throw A("list.join", "value", `a list of ${c(e)}`);
2026
+ return d(e);
2027
+ }).join(n);
2028
+ },
2029
+ "list.unique": (e) => {
2030
+ let t = [];
2031
+ for (let n of e[0]) t.some((e) => D(e, n)) || t.push(n);
2032
+ return t;
2033
+ },
2034
+ "list.sort": (e) => {
2035
+ let t = e[0];
2036
+ if (t.length === 0) return [];
2037
+ let n = c(t[0]);
2038
+ if (!dt.includes(n)) throw A("list.sort", "value", `a list of ${n}`);
2039
+ if (t.some((e) => c(e) !== n)) throw A("list.sort", "value", "a list of mixed types");
2040
+ if (n === "text") return [...t].sort((e, t) => m(e, t));
2041
+ let r = (e) => n === "datetime" ? e.getTime() : e;
2042
+ return [...t].sort((e, t) => {
2043
+ let n = r(e), i = r(t);
2044
+ return n < i ? -1 : +(n > i);
2045
+ });
2046
+ }
2047
+ }, pt = /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/, mt = {
2048
+ "num.round": (e) => h(e[0]),
2049
+ "num.floor": (e) => Math.floor(e[0]),
2050
+ "num.ceil": (e) => Math.ceil(e[0]),
2051
+ "num.abs": (e) => Math.abs(e[0]),
2052
+ "num.min": (e) => Math.min(...e),
2053
+ "num.max": (e) => Math.max(...e),
2054
+ "num.parse": (e) => {
2055
+ let t = e[0].trim();
2056
+ if (!pt.test(t)) throw A("num.parse", "value", t);
2057
+ let n = Number(t);
2058
+ if (!Number.isFinite(n)) throw A("num.parse", "value", t);
2059
+ return n;
2060
+ }
2061
+ }, ht = (e) => Array.from(e);
2062
+ function gt(e, t, n) {
2063
+ let r = _t(t < 0 ? e + t : t, e), i = n === null ? e : _t(n < 0 ? e + n : n, e);
2064
+ return [r, Math.max(r, i)];
2065
+ }
2066
+ var _t = (e, t) => Math.min(Math.max(Math.trunc(e), 0), t), vt = {
2067
+ "text.upper": (e) => e[0].toUpperCase(),
2068
+ "text.lower": (e) => e[0].toLowerCase(),
2069
+ "text.trim": (e) => e[0].trim(),
2070
+ "text.concat": (e) => e.map((e) => e).join(""),
2071
+ "text.split": (e) => {
2072
+ let [t, n] = e;
2073
+ return n === "" ? ht(t) : t.split(n);
2074
+ },
2075
+ "text.join": (e) => {
2076
+ let [t, n] = e;
2077
+ return t.map(d).join(n);
2078
+ },
2079
+ "text.replace": (e) => {
2080
+ let [t, n, r] = e;
2081
+ return n === "" ? t : t.split(n).join(r);
2082
+ },
2083
+ "text.contains": (e) => {
2084
+ let [t, n] = e;
2085
+ return t.includes(n);
2086
+ },
2087
+ "text.starts_with": (e) => {
2088
+ let [t, n] = e;
2089
+ return t.startsWith(n);
2090
+ },
2091
+ "text.ends_with": (e) => {
2092
+ let [t, n] = e;
2093
+ return t.endsWith(n);
2094
+ },
2095
+ "text.slice": (e) => {
2096
+ let [t, n, r] = e, i = ht(t), [a, o] = gt(i.length, n, r === void 0 ? null : r);
2097
+ return i.slice(a, o).join("");
2098
+ },
2099
+ "text.len": (e) => ht(e[0]).length
2100
+ };
2101
+ //#endregion
2102
+ //#region src/functions/registry.ts
2103
+ function A(e, t, n) {
2104
+ return new a([i("EVAL_BAD_ARGUMENT", 0, {
2105
+ name: e,
2106
+ param: t,
2107
+ actual: n
2108
+ })]);
2109
+ }
2110
+ function yt() {
2111
+ let e = {
2112
+ ...ce,
2113
+ ...vt,
2114
+ ...mt,
2115
+ ...ft,
2116
+ ...le
2117
+ }, n = /* @__PURE__ */ new Map(), r = [];
2118
+ for (let i of t) {
2119
+ let t = e[i.qualified];
2120
+ if (!t) {
2121
+ r.push(i.qualified);
2122
+ continue;
2123
+ }
2124
+ n.set(i.qualified, {
2125
+ spec: i,
2126
+ impl: t
2127
+ });
2128
+ }
2129
+ let i = Object.keys(e).filter((e) => !n.has(e));
2130
+ if (r.length > 0 || i.length > 0) throw Error([
2131
+ "the function registry disagrees with schemas/functions/*.yaml:",
2132
+ ...r.map((e) => ` declared but not implemented: ${e}`),
2133
+ ...i.map((e) => ` implemented but not declared: ${e}`)
2134
+ ].join("\n"));
2135
+ return n;
2136
+ }
2137
+ function bt(...e) {
2138
+ let t = /* @__PURE__ */ new Map();
2139
+ for (let n of e) for (let [e, r] of n) {
2140
+ if (t.has(e)) throw new a([i("EXPR_FUNCTION_COLLISION", 0, { name: e })]);
2141
+ t.set(e, r);
2142
+ }
2143
+ return t;
2144
+ }
2145
+ function xt(e, t) {
2146
+ let n = /* @__PURE__ */ new Map();
2147
+ for (let r of e) {
2148
+ let e = t[r.qualified];
2149
+ if (!e) throw Error(`${r.qualified} is declared but not implemented`);
2150
+ n.set(r.qualified, {
2151
+ spec: r,
2152
+ impl: e
2153
+ });
2154
+ }
2155
+ return n;
2156
+ }
2157
+ //#endregion
2158
+ //#region src/reference.ts
2159
+ function j(e) {
2160
+ switch (e.kind) {
2161
+ case "Name": return !0;
2162
+ case "Member":
2163
+ case "Project": return j(e.object);
2164
+ case "Index": return e.index.kind === "Literal" && j(e.object);
2165
+ default: return !1;
2166
+ }
2167
+ }
2168
+ function M(e) {
2169
+ return j(e) ? O(e) : null;
2170
+ }
2171
+ function St(e) {
2172
+ let [t] = e.segments;
2173
+ return e.segments.length !== 1 || t?.kind !== "Hole" ? null : M(t.expr);
2174
+ }
2175
+ function Ct(e) {
2176
+ let t = S(e);
2177
+ return t.ok ? St(t.template) : null;
2178
+ }
2179
+ function N(e) {
2180
+ if (j(e)) return [e];
2181
+ switch (e.kind) {
2182
+ case "Member":
2183
+ case "Project": return N(e.object);
2184
+ case "Index": return [...N(e.object), ...N(e.index)];
2185
+ case "Call": return [...N(e.object), ...e.args.flatMap(N)];
2186
+ case "Unary": return N(e.operand);
2187
+ case "Binary": return [...N(e.left), ...N(e.right)];
2188
+ case "Ternary": return [
2189
+ ...N(e.cond),
2190
+ ...N(e.whenTrue),
2191
+ ...N(e.whenFalse)
2192
+ ];
2193
+ default: return [];
2194
+ }
2195
+ }
2196
+ function wt(e, t, n) {
2197
+ if (t === n) return e;
2198
+ let r = S(e);
2199
+ if (!r.ok) return e;
2200
+ let i = [];
2201
+ for (let a of r.template.segments) if (a.kind === "Hole") for (let r of N(a.expr)) {
2202
+ let a = M(r);
2203
+ a !== null && Tt(a, t) && e.slice(r.at, r.at + t.length) === t && i.push({
2204
+ at: r.at,
2205
+ length: t.length,
2206
+ text: n
2207
+ });
2208
+ }
2209
+ let a = e;
2210
+ for (let e of i.sort((e, t) => t.at - e.at)) a = a.slice(0, e.at) + e.text + a.slice(e.at + e.length);
2211
+ return a;
2212
+ }
2213
+ var Tt = (e, t) => e === t || e.startsWith(`${t}.`) || e.startsWith(`${t}[`);
2214
+ //#endregion
2215
+ //#region src/sexp.ts
2216
+ function Et(e, t = {}) {
2217
+ return e.segments.length === 0 ? "(template)" : `(template ${e.segments.map((e) => Dt(e, t)).join(" ")})`;
2218
+ }
2219
+ function Dt(e, t) {
2220
+ return e.kind === "Text" ? `(text ${L(e.value)})` : `(hole${F(e.at, t)} ${P(e.expr, t)})`;
2221
+ }
2222
+ function P(e, t = {}) {
2223
+ let n = F(e.at, t), r = (e) => P(e, t);
2224
+ switch (e.kind) {
2225
+ case "Name": return `${e.name}${n}`;
2226
+ case "Literal": return `${I(e.type, e.value)}${n}`;
2227
+ case "Member": return `(.${n} ${r(e.object)} ${e.name})`;
2228
+ case "Index": return `([]${n} ${r(e.object)} ${r(e.index)})`;
2229
+ case "Project": return `(project${n} ${r(e.object)})`;
2230
+ case "Call": return `(call${n} ${[e.object, ...e.args].map(r).join(" ")})`;
2231
+ case "Unary": return `(${e.op === "-" ? "neg" : e.op}${n} ${r(e.operand)})`;
2232
+ case "Binary": return `(${e.op}${n} ${r(e.left)} ${r(e.right)})`;
2233
+ case "Ternary": return `(?:${n} ${r(e.cond)} ${r(e.whenTrue)} ${r(e.whenFalse)})`;
2234
+ }
2235
+ }
2236
+ var F = (e, t) => t.offsets ? `@${e}` : "";
2237
+ function I(e, t) {
2238
+ return e === "text" ? L(String(t)) : e === "number" ? g(t) : String(t);
2239
+ }
2240
+ function L(e) {
2241
+ return `"${e.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")}"`;
2242
+ }
2243
+ //#endregion
2244
+ //#region src/types.ts
2245
+ function R(e, t) {
2246
+ return e === "unknown" || e === "item" ? "unknown" : t === "unknown" || t === "item" || e === "null" || e === t || t === "text" && u(e) ? "matches" : "conflicts";
2247
+ }
2248
+ var z = [
2249
+ "number",
2250
+ "text",
2251
+ "datetime"
2252
+ ], B = (e) => e === "unknown" || e === "item" || z.includes(e), V = (e) => ({
2253
+ type: "object",
2254
+ ...e.members ? { members: e.members } : {}
2255
+ });
2256
+ //#endregion
2257
+ //#region src/validate.ts
2258
+ function Ot(e, t, n) {
2259
+ let r = S(e);
2260
+ return r.ok ? H(r.template, t, n) : [...r.diagnostics];
2261
+ }
2262
+ function H(e, t, n) {
2263
+ let r = [], [i] = e.segments, a = e.segments.length === 1 && i?.kind === "Hole" ? i : null;
2264
+ if (a) {
2265
+ let e = G(a.expr, n, r);
2266
+ return e.kind !== "broken" && U(r, kt(e), t, a.at, "this expression"), r;
2267
+ }
2268
+ for (let t of e.segments) t.kind === "Hole" && W(t.expr, n, r);
2269
+ return e.segments.length > 0 && U(r, "text", t, 0, "this template"), r;
2270
+ }
2271
+ function U(e, t, n, r, a) {
2272
+ let o = R(t, n);
2273
+ o !== "matches" && e.push(o === "conflicts" ? i("EXPR_TYPE_MISMATCH", r, {
2274
+ name: a,
2275
+ expected: n,
2276
+ actual: t
2277
+ }) : i("EXPR_TYPE_UNKNOWN", r, {
2278
+ name: a,
2279
+ expected: n
2280
+ }));
2281
+ }
2282
+ function W(e, t, n) {
2283
+ return kt(G(e, t, n));
2284
+ }
2285
+ function kt(e) {
2286
+ return e.kind === "value" ? e.projected ? "list" : e.node.type : "unknown";
2287
+ }
2288
+ function G(e, t, n) {
2289
+ switch (e.kind) {
2290
+ case "Literal": return {
2291
+ kind: "value",
2292
+ node: { type: e.type },
2293
+ projected: !1
2294
+ };
2295
+ case "Name": return At(e.name, e.at, t, n);
2296
+ case "Member": return K(e, t, n);
2297
+ case "Index": return Mt(e, t, n);
2298
+ case "Project": return Nt(e, t, n);
2299
+ case "Call": return Pt(e, t, n);
2300
+ case "Unary": return Ft(e, t, n);
2301
+ case "Binary": return It(e, t, n);
2302
+ case "Ternary": return Lt(e, t, n);
2303
+ }
2304
+ }
2305
+ function At(e, t, n, r) {
2306
+ let a = n.scope.find((t) => t.path === e);
2307
+ if (a) return {
2308
+ kind: "value",
2309
+ node: a.type,
2310
+ projected: !1
2311
+ };
2312
+ if (n.scope.some((t) => t.path.startsWith(`${e}.`))) return {
2313
+ kind: "prefix",
2314
+ path: e
2315
+ };
2316
+ for (let t of n.functions.keys()) if (t.startsWith(`${e}.`)) return {
2317
+ kind: "namespace",
2318
+ name: e
2319
+ };
2320
+ return r.push(i("EXPR_UNKNOWN_REFERENCE", t, { name: e })), { kind: "broken" };
2321
+ }
2322
+ function K(e, t, n) {
2323
+ let r = G(e.object, t, n);
2324
+ switch (r.kind) {
2325
+ case "prefix": {
2326
+ let a = `${r.path}.${e.name}`, o = t.scope.find((e) => e.path === a);
2327
+ return o ? {
2328
+ kind: "value",
2329
+ node: o.type,
2330
+ projected: !1
2331
+ } : t.scope.some((e) => e.path.startsWith(`${a}.`)) ? {
2332
+ kind: "prefix",
2333
+ path: a
2334
+ } : (n.push(i("EXPR_UNKNOWN_REFERENCE", e.at, { name: a })), { kind: "broken" });
2335
+ }
2336
+ case "namespace": {
2337
+ let a = `${r.name}.${e.name}`, o = t.functions.get(a);
2338
+ return o ? {
2339
+ kind: "function",
2340
+ spec: o.spec
2341
+ } : (n.push(i("EXPR_UNKNOWN_FUNCTION", e.at, { name: a })), { kind: "broken" });
2342
+ }
2343
+ case "value": return jt(r, e.name, e.at, n);
2344
+ default: return r.kind === "broken" ? r : { kind: "unknown" };
2345
+ }
2346
+ }
2347
+ function jt(e, t, n, r) {
2348
+ if (!e.projected && e.node.type === "list") return r.push(i("EXPR_OPERAND_TYPE", n, {
2349
+ op: ".",
2350
+ expected: "object",
2351
+ actual: "list"
2352
+ })), { kind: "broken" };
2353
+ let a = e.projected ? V(e.node) : e.node;
2354
+ return a.type === "unknown" || a.type === "item" || !a.members || !Object.hasOwn(a.members, t) ? { kind: "unknown" } : {
2355
+ kind: "value",
2356
+ node: a.members[t],
2357
+ projected: e.projected
2358
+ };
2359
+ }
2360
+ function Mt(e, t, n) {
2361
+ let r = G(e.object, t, n);
2362
+ return W(e.index, t, n), r.kind === "value" ? r.node.type === "list" ? {
2363
+ kind: "value",
2364
+ node: V(r.node),
2365
+ projected: r.projected
2366
+ } : { kind: "unknown" } : r.kind === "broken" ? r : { kind: "unknown" };
2367
+ }
2368
+ function Nt(e, t, n) {
2369
+ let r = G(e.object, t, n);
2370
+ return r.kind === "value" ? r.projected ? r : r.node.type !== "list" && r.node.type !== "unknown" ? (n.push(i("EXPR_OPERAND_TYPE", e.at, {
2371
+ op: "[]",
2372
+ expected: "list",
2373
+ actual: r.node.type
2374
+ })), { kind: "broken" }) : {
2375
+ kind: "value",
2376
+ node: V(r.node),
2377
+ projected: !0
2378
+ } : r.kind === "broken" ? r : { kind: "unknown" };
2379
+ }
2380
+ function Pt(e, t, n) {
2381
+ let r = G(e.object, t, n), a = e.args.map((e) => W(e, t, n));
2382
+ if (r.kind !== "function") return r.kind !== "broken" && n.push(i("EXPR_UNKNOWN_FUNCTION", e.at, { name: "this call" })), { kind: "broken" };
2383
+ let { spec: o } = r, s = o.params.at(-1)?.variadic === !0, c = o.params.filter((e) => !e.optional).length, l = s ? Infinity : o.params.length;
2384
+ return a.length < c || a.length > l ? (n.push(i("EXPR_ARITY_MISMATCH", e.at, {
2385
+ name: o.qualified,
2386
+ expected: s ? `at least ${c}` : q(c, o.params.length),
2387
+ actual: String(a.length)
2388
+ })), {
2389
+ kind: "value",
2390
+ node: { type: o.returns },
2391
+ projected: !1
2392
+ }) : (a.forEach((t, r) => {
2393
+ let a = o.params[Math.min(r, o.params.length - 1)];
2394
+ a && R(t, a.type) === "conflicts" && n.push(i("EXPR_ARGUMENT_TYPE", e.at, {
2395
+ name: o.qualified,
2396
+ param: a.name,
2397
+ expected: a.type,
2398
+ actual: t
2399
+ }));
2400
+ }), {
2401
+ kind: "value",
2402
+ node: { type: o.returns },
2403
+ projected: !1
2404
+ });
2405
+ }
2406
+ function Ft(e, t, n) {
2407
+ let r = W(e.operand, t, n), i = e.op === "!" ? "boolean" : "number";
2408
+ return Y(n, r, i, e.op, e.at), {
2409
+ kind: "value",
2410
+ node: { type: i },
2411
+ projected: !1
2412
+ };
2413
+ }
2414
+ function It(e, t, n) {
2415
+ let r = W(e.left, t, n), a = W(e.right, t, n), { op: o, at: s } = e;
2416
+ if (o === "??") return J(r === a ? r : "unknown");
2417
+ if (o === "&&" || o === "||") return Y(n, r, "boolean", o, s), Y(n, a, "boolean", o, s), J("boolean");
2418
+ if (o === "==" || o === "!=") return J("boolean");
2419
+ if (o === "<" || o === "<=" || o === ">" || o === ">=") {
2420
+ let e = !0;
2421
+ for (let t of [r, a]) B(t) || (e = !1, n.push(i("EXPR_OPERAND_TYPE", s, {
2422
+ op: o,
2423
+ expected: "number, text or datetime",
2424
+ actual: t
2425
+ })));
2426
+ return e && r !== "unknown" && a !== "unknown" && r !== a && n.push(i("EXPR_OPERAND_TYPE", s, {
2427
+ op: o,
2428
+ expected: r,
2429
+ actual: a
2430
+ })), J("boolean");
2431
+ }
2432
+ return Y(n, r, "number", o, s), Y(n, a, "number", o, s), J("number");
2433
+ }
2434
+ function Lt(e, t, n) {
2435
+ Y(n, W(e.cond, t, n), "boolean", "? :", e.at);
2436
+ let r = W(e.whenTrue, t, n);
2437
+ return J(r === W(e.whenFalse, t, n) ? r : "unknown");
2438
+ }
2439
+ var q = (e, t) => e === t ? String(e) : `${e} to ${t}`, J = (e) => ({
2440
+ kind: "value",
2441
+ node: { type: e },
2442
+ projected: !1
2443
+ });
2444
+ function Y(e, t, n, r, a) {
2445
+ t !== "unknown" && t !== "item" && t !== "null" && t !== n && e.push(i("EXPR_OPERAND_TYPE", a, {
2446
+ op: r,
2447
+ expected: n,
2448
+ actual: t
2449
+ }));
2450
+ }
2451
+ //#endregion
2452
+ export { t as CORE_FUNCTIONS, e as CORE_NAMESPACES, n as DIAGNOSTICS, a as ExpressionError, z as ORDERED_TYPES, d as asText, s as blocksPublish, B as canOrder, m as compareText, yt as coreFunctions, f as datetimeToText, i as diagnostic, V as elementOf, D as equals, o as errorsIn, T as evaluate, r as formatMessage, xt as hostFunctions, W as inferType, j as isReference, u as isScalar, R as match, bt as mergeRegistries, g as numberToText, Fe as parseExpression, Pe as parseTemplate, O as pathText, M as referencePath, N as referencesIn, wt as renamePath, Le as resolve, Re as resolveAll, h as roundHalfAwayFromZero, l as satisfies, Ct as sourceReference, St as templateReference, Et as templateToSexp, p as toJson, P as toSexp, S as tryParseTemplate, c as typeOf, Ot as validate };