@kalada/core 0.2.0 → 0.4.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 (140) hide show
  1. package/README.md +62 -3
  2. package/dist/kalada-v1/canonical-input.cjs +133 -0
  3. package/dist/kalada-v1/canonical-input.cjs.map +1 -0
  4. package/dist/kalada-v1/canonical-input.d.cts +26 -0
  5. package/dist/kalada-v1/canonical-input.d.ts +26 -0
  6. package/dist/kalada-v1/canonical-input.js +122 -0
  7. package/dist/kalada-v1/canonical-input.js.map +1 -0
  8. package/dist/kalada-v1/canonicalize.cjs +93 -130
  9. package/dist/kalada-v1/canonicalize.cjs.map +1 -1
  10. package/dist/kalada-v1/canonicalize.d.cts +1 -0
  11. package/dist/kalada-v1/canonicalize.d.ts +1 -0
  12. package/dist/kalada-v1/canonicalize.js +71 -108
  13. package/dist/kalada-v1/canonicalize.js.map +1 -1
  14. package/dist/kalada-v1/codec.cjs +24 -0
  15. package/dist/kalada-v1/codec.cjs.map +1 -1
  16. package/dist/kalada-v1/codec.d.cts +5 -0
  17. package/dist/kalada-v1/codec.d.ts +5 -0
  18. package/dist/kalada-v1/codec.js +24 -0
  19. package/dist/kalada-v1/codec.js.map +1 -1
  20. package/dist/kalada-v1/compile.cjs +24 -1
  21. package/dist/kalada-v1/compile.cjs.map +1 -1
  22. package/dist/kalada-v1/compile.d.cts +1 -0
  23. package/dist/kalada-v1/compile.d.ts +1 -0
  24. package/dist/kalada-v1/compile.js +25 -2
  25. package/dist/kalada-v1/compile.js.map +1 -1
  26. package/dist/kalada-v1/dependencies.cjs +55 -2
  27. package/dist/kalada-v1/dependencies.cjs.map +1 -1
  28. package/dist/kalada-v1/dependencies.d.cts +1 -0
  29. package/dist/kalada-v1/dependencies.d.ts +1 -0
  30. package/dist/kalada-v1/dependencies.js +55 -2
  31. package/dist/kalada-v1/dependencies.js.map +1 -1
  32. package/dist/kalada-v1/diagnostics.cjs +29 -4
  33. package/dist/kalada-v1/diagnostics.cjs.map +1 -1
  34. package/dist/kalada-v1/diagnostics.d.cts +5 -3
  35. package/dist/kalada-v1/diagnostics.d.ts +5 -3
  36. package/dist/kalada-v1/diagnostics.js +29 -4
  37. package/dist/kalada-v1/diagnostics.js.map +1 -1
  38. package/dist/kalada-v1/evaluate.cjs +23 -117
  39. package/dist/kalada-v1/evaluate.cjs.map +1 -1
  40. package/dist/kalada-v1/evaluate.d.cts +4 -2
  41. package/dist/kalada-v1/evaluate.d.ts +4 -2
  42. package/dist/kalada-v1/evaluate.js +24 -118
  43. package/dist/kalada-v1/evaluate.js.map +1 -1
  44. package/dist/kalada-v1/evaluation-delivery.cjs +286 -0
  45. package/dist/kalada-v1/evaluation-delivery.cjs.map +1 -0
  46. package/dist/kalada-v1/evaluation-delivery.d.cts +13 -0
  47. package/dist/kalada-v1/evaluation-delivery.d.ts +13 -0
  48. package/dist/kalada-v1/evaluation-delivery.js +284 -0
  49. package/dist/kalada-v1/evaluation-delivery.js.map +1 -0
  50. package/dist/kalada-v1/evaluation-frames.cjs +16 -0
  51. package/dist/kalada-v1/evaluation-frames.cjs.map +1 -0
  52. package/dist/kalada-v1/evaluation-frames.d.cts +83 -0
  53. package/dist/kalada-v1/evaluation-frames.d.ts +83 -0
  54. package/dist/kalada-v1/evaluation-frames.js +14 -0
  55. package/dist/kalada-v1/evaluation-frames.js.map +1 -0
  56. package/dist/kalada-v1/evaluation-machine.cjs +226 -0
  57. package/dist/kalada-v1/evaluation-machine.cjs.map +1 -0
  58. package/dist/kalada-v1/evaluation-machine.d.cts +9 -0
  59. package/dist/kalada-v1/evaluation-machine.d.ts +9 -0
  60. package/dist/kalada-v1/evaluation-machine.js +224 -0
  61. package/dist/kalada-v1/evaluation-machine.js.map +1 -0
  62. package/dist/kalada-v1/evaluation-resolution.cjs +80 -0
  63. package/dist/kalada-v1/evaluation-resolution.cjs.map +1 -0
  64. package/dist/kalada-v1/evaluation-resolution.d.cts +11 -0
  65. package/dist/kalada-v1/evaluation-resolution.d.ts +11 -0
  66. package/dist/kalada-v1/evaluation-resolution.js +78 -0
  67. package/dist/kalada-v1/evaluation-resolution.js.map +1 -0
  68. package/dist/kalada-v1/evaluation-state.cjs +94 -0
  69. package/dist/kalada-v1/evaluation-state.cjs.map +1 -0
  70. package/dist/kalada-v1/evaluation-state.d.cts +38 -0
  71. package/dist/kalada-v1/evaluation-state.d.ts +38 -0
  72. package/dist/kalada-v1/evaluation-state.js +81 -0
  73. package/dist/kalada-v1/evaluation-state.js.map +1 -0
  74. package/dist/kalada-v1/factories.cjs +46 -0
  75. package/dist/kalada-v1/factories.cjs.map +1 -1
  76. package/dist/kalada-v1/factories.d.cts +24 -1
  77. package/dist/kalada-v1/factories.d.ts +24 -1
  78. package/dist/kalada-v1/factories.js +46 -0
  79. package/dist/kalada-v1/factories.js.map +1 -1
  80. package/dist/kalada-v1/function-contracts.cjs +150 -0
  81. package/dist/kalada-v1/function-contracts.cjs.map +1 -0
  82. package/dist/kalada-v1/function-contracts.d.cts +15 -0
  83. package/dist/kalada-v1/function-contracts.d.ts +15 -0
  84. package/dist/kalada-v1/function-contracts.js +144 -0
  85. package/dist/kalada-v1/function-contracts.js.map +1 -0
  86. package/dist/kalada-v1/index.cjs +30 -0
  87. package/dist/kalada-v1/index.d.cts +5 -3
  88. package/dist/kalada-v1/index.d.ts +5 -3
  89. package/dist/kalada-v1/index.js +4 -2
  90. package/dist/kalada-v1/limits.cjs +23 -2
  91. package/dist/kalada-v1/limits.cjs.map +1 -1
  92. package/dist/kalada-v1/limits.d.cts +6 -3
  93. package/dist/kalada-v1/limits.d.ts +6 -3
  94. package/dist/kalada-v1/limits.js +23 -3
  95. package/dist/kalada-v1/limits.js.map +1 -1
  96. package/dist/kalada-v1/runtime-values.cjs +112 -0
  97. package/dist/kalada-v1/runtime-values.cjs.map +1 -0
  98. package/dist/kalada-v1/runtime-values.d.cts +35 -0
  99. package/dist/kalada-v1/runtime-values.d.ts +35 -0
  100. package/dist/kalada-v1/runtime-values.js +105 -0
  101. package/dist/kalada-v1/runtime-values.js.map +1 -0
  102. package/dist/kalada-v1/schemas.cjs +136 -3
  103. package/dist/kalada-v1/schemas.cjs.map +1 -1
  104. package/dist/kalada-v1/schemas.d.cts +2 -1
  105. package/dist/kalada-v1/schemas.d.ts +2 -1
  106. package/dist/kalada-v1/schemas.js +137 -5
  107. package/dist/kalada-v1/schemas.js.map +1 -1
  108. package/dist/kalada-v1/static-analysis.cjs +177 -0
  109. package/dist/kalada-v1/static-analysis.cjs.map +1 -0
  110. package/dist/kalada-v1/static-analysis.d.cts +9 -0
  111. package/dist/kalada-v1/static-analysis.d.ts +9 -0
  112. package/dist/kalada-v1/static-analysis.js +175 -0
  113. package/dist/kalada-v1/static-analysis.js.map +1 -0
  114. package/dist/kalada-v1/static-types.cjs +229 -0
  115. package/dist/kalada-v1/static-types.cjs.map +1 -0
  116. package/dist/kalada-v1/static-types.d.cts +8 -0
  117. package/dist/kalada-v1/static-types.d.ts +8 -0
  118. package/dist/kalada-v1/static-types.js +227 -0
  119. package/dist/kalada-v1/static-types.js.map +1 -0
  120. package/dist/kalada-v1/temporal-evaluation.cjs +95 -0
  121. package/dist/kalada-v1/temporal-evaluation.cjs.map +1 -0
  122. package/dist/kalada-v1/temporal-evaluation.d.cts +18 -0
  123. package/dist/kalada-v1/temporal-evaluation.d.ts +18 -0
  124. package/dist/kalada-v1/temporal-evaluation.js +90 -0
  125. package/dist/kalada-v1/temporal-evaluation.js.map +1 -0
  126. package/dist/kalada-v1/temporal.cjs +42 -0
  127. package/dist/kalada-v1/temporal.cjs.map +1 -0
  128. package/dist/kalada-v1/temporal.d.cts +22 -0
  129. package/dist/kalada-v1/temporal.d.ts +22 -0
  130. package/dist/kalada-v1/temporal.js +37 -0
  131. package/dist/kalada-v1/temporal.js.map +1 -0
  132. package/dist/kalada-v1/types.d.cts +108 -5
  133. package/dist/kalada-v1/types.d.ts +108 -5
  134. package/dist/kalada-v1/values.cjs +13 -1
  135. package/dist/kalada-v1/values.cjs.map +1 -1
  136. package/dist/kalada-v1/values.d.cts +2 -1
  137. package/dist/kalada-v1/values.d.ts +2 -1
  138. package/dist/kalada-v1/values.js +13 -1
  139. package/dist/kalada-v1/values.js.map +1 -1
  140. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var diagnostics_js = require('./diagnostics.js');
4
+ var temporal_js = require('./temporal.js');
5
+
6
+ function temporalLeaf(node, path, instant) {
7
+ if (node.kind === "instant") return temporal_js.Instant.fromMilliseconds(node.milliseconds);
8
+ if (node.kind === "duration") return temporal_js.Duration.fromMilliseconds(node.milliseconds);
9
+ if (!instant) throw new diagnostics_js.KaladaFailure("KALADA_INSTANT_REQUIRED", path);
10
+ return instant;
11
+ }
12
+ function applyTemporalBinary(kind, operator, left, right, rightPath) {
13
+ if (!temporal_js.isInstant(left) && !temporal_js.isDuration(left)) mismatch(rightPath.slice(0, -1).concat("left"));
14
+ if (!temporal_js.isInstant(right) && !temporal_js.isDuration(right)) mismatch(rightPath);
15
+ if (kind === "temporal-comparison") {
16
+ assertSameType(left, right, rightPath);
17
+ return compare(
18
+ operator,
19
+ left.milliseconds,
20
+ right.milliseconds
21
+ );
22
+ }
23
+ return operator === "add" ? add(left, right, rightPath) : subtract(left, right, rightPath);
24
+ }
25
+ function isTemporalExpression(node) {
26
+ return node.kind === "instant" || node.kind === "duration" || node.kind === "current-instant" || node.kind === "temporal-arithmetic" || node.kind === "temporal-comparison";
27
+ }
28
+ function evaluateTemporalExpression(node, path, instant, evaluate) {
29
+ if (node.kind === "instant") return temporal_js.Instant.fromMilliseconds(node.milliseconds);
30
+ if (node.kind === "duration") return temporal_js.Duration.fromMilliseconds(node.milliseconds);
31
+ if (node.kind === "current-instant") {
32
+ if (!instant) throw new diagnostics_js.KaladaFailure("KALADA_INSTANT_REQUIRED", path);
33
+ return instant;
34
+ }
35
+ const left = temporalOperand(evaluate, node.left, [...path, "left"]);
36
+ const right = temporalOperand(evaluate, node.right, [...path, "right"]);
37
+ if (node.kind === "temporal-comparison") {
38
+ assertSameType(left, right, [...path, "right"]);
39
+ return compare(node.operator, left.milliseconds, right.milliseconds);
40
+ }
41
+ return node.operator === "add" ? add(left, right, [...path, "right"]) : subtract(left, right, [...path, "right"]);
42
+ }
43
+ function temporalOperand(evaluate, node, path) {
44
+ const value = evaluate(node, path);
45
+ if (!temporal_js.isInstant(value) && !temporal_js.isDuration(value)) mismatch(path);
46
+ return value;
47
+ }
48
+ function add(left, right, path) {
49
+ if (temporal_js.isInstant(left) && temporal_js.isDuration(right)) {
50
+ return temporal_js.Instant.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));
51
+ }
52
+ if (temporal_js.isDuration(left) && temporal_js.isDuration(right)) {
53
+ return temporal_js.Duration.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));
54
+ }
55
+ return mismatch(path);
56
+ }
57
+ function subtract(left, right, path) {
58
+ if (temporal_js.isInstant(left) && temporal_js.isInstant(right)) {
59
+ return temporal_js.Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));
60
+ }
61
+ if (temporal_js.isInstant(left) && temporal_js.isDuration(right)) {
62
+ return temporal_js.Instant.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));
63
+ }
64
+ if (temporal_js.isDuration(left) && temporal_js.isDuration(right)) {
65
+ return temporal_js.Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));
66
+ }
67
+ return mismatch(path);
68
+ }
69
+ function assertSameType(left, right, path) {
70
+ if (temporal_js.isInstant(left) && !temporal_js.isInstant(right) || temporal_js.isDuration(left) && !temporal_js.isDuration(right)) {
71
+ mismatch(path);
72
+ }
73
+ }
74
+ function compare(operator, left, right) {
75
+ if (operator === "equal") return left === right;
76
+ if (operator === "not-equal") return left !== right;
77
+ if (operator === "less-than") return left < right;
78
+ if (operator === "less-than-or-equal") return left <= right;
79
+ if (operator === "greater-than") return left > right;
80
+ return left >= right;
81
+ }
82
+ function checked(output, path) {
83
+ if (!Number.isSafeInteger(output)) throw new diagnostics_js.KaladaFailure("KALADA_TEMPORAL_OVERFLOW", path);
84
+ return Object.is(output, -0) ? 0 : output;
85
+ }
86
+ function mismatch(path) {
87
+ throw new diagnostics_js.KaladaFailure("KALADA_TEMPORAL_TYPE_MISMATCH", path);
88
+ }
89
+
90
+ exports.applyTemporalBinary = applyTemporalBinary;
91
+ exports.evaluateTemporalExpression = evaluateTemporalExpression;
92
+ exports.isTemporalExpression = isTemporalExpression;
93
+ exports.temporalLeaf = temporalLeaf;
94
+ //# sourceMappingURL=temporal-evaluation.cjs.map
95
+ //# sourceMappingURL=temporal-evaluation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kalada-v1/temporal-evaluation.ts"],"names":["Instant","Duration","KaladaFailure","isInstant","isDuration"],"mappings":";;;;;AAoBO,SAAS,YAAA,CACd,IAAA,EAIA,IAAA,EACA,OAAA,EACe;AACf,EAAA,IAAI,KAAK,IAAA,KAAS,SAAA,SAAkBA,mBAAA,CAAQ,gBAAA,CAAiB,KAAK,YAAY,CAAA;AAC9E,EAAA,IAAI,KAAK,IAAA,KAAS,UAAA,SAAmBC,oBAAA,CAAS,gBAAA,CAAiB,KAAK,YAAY,CAAA;AAChF,EAAA,IAAI,CAAC,OAAA,EAAS,MAAM,IAAIC,4BAAA,CAAc,2BAA2B,IAAI,CAAA;AACrE,EAAA,OAAO,OAAA;AACT;AAEO,SAAS,mBAAA,CACd,IAAA,EACA,QAAA,EACA,IAAA,EACA,OACA,SAAA,EACa;AACb,EAAA,IAAI,CAACC,qBAAA,CAAU,IAAI,CAAA,IAAK,CAACC,uBAAW,IAAI,CAAA,EAAG,QAAA,CAAS,SAAA,CAAU,MAAM,CAAA,EAAG,EAAE,CAAA,CAAE,MAAA,CAAO,MAAM,CAAC,CAAA;AACzF,EAAA,IAAI,CAACD,sBAAU,KAAK,CAAA,IAAK,CAACC,sBAAA,CAAW,KAAK,CAAA,EAAG,QAAA,CAAS,SAAS,CA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EAAa,OAAO,IAAA,GAAO,KAAA;AAC5C,EAAA,IAAI,QAAA,KAAa,oBAAA,EAAsB,OAAO,IAAA,IAAQ,KAAA;AACtD,EAAA,IAAI,QAAA,KAAa,cAAA,EAAgB,OAAO,IAAA,GAAO,KAAA;AAC/C,EAAA,OAAO,IAAA,IAAQ,KAAA;AACjB;AAEA,SAAS,OAAA,CAAQ,QAAgB,IAAA,EAAoB;AACnD,EAAA,IAAI,CAAC,OAAO,aAAA,CAAc,MAAM,GAAG,MAAM,IAAIF,4BAAA,CAAc,0BAAA,EAA4B,IAAI,CAAA;AAC3F,EAAA,OAAO,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,EAAE,IAAI,CAAA,GAAI,MAAA;AACrC;AAEA,SAAS,SAAS,IAAA,EAAmB;AACnC,EAAA,MAAM,IAAIA,4BAAA,CAAc,+BAAA,EAAiC,IAAI,CAAA;AAC/D","file":"temporal-evaluation.cjs","sourcesContent":["import { KaladaFailure } from \"./diagnostics.js\";\nimport type { JsonValue } from \"./json.js\";\nimport {\n Duration,\n type DurationValue,\n Instant,\n type InstantValue,\n isDuration,\n isInstant,\n} from \"./temporal.js\";\nimport type { KaladaV1Expression } from \"./types.js\";\nimport type { KaladaValue } from \"./values.js\";\n\ntype Path = readonly (string | number)[];\ntype TemporalExpression<R extends JsonValue> = Extract<\n KaladaV1Expression<R>,\n { kind: \"instant\" | \"duration\" | \"current-instant\" | `temporal-${string}` }\n>;\ntype TemporalValue = InstantValue | DurationValue;\n\nexport function temporalLeaf(\n node: Extract<\n TemporalExpression<JsonValue>,\n { kind: \"instant\" | \"duration\" | \"current-instant\" }\n >,\n path: Path,\n instant: InstantValue | undefined,\n): TemporalValue {\n if (node.kind === \"instant\") return Instant.fromMilliseconds(node.milliseconds);\n if (node.kind === \"duration\") return Duration.fromMilliseconds(node.milliseconds);\n if (!instant) throw new KaladaFailure(\"KALADA_INSTANT_REQUIRED\", path);\n return instant;\n}\n\nexport function applyTemporalBinary(\n kind: \"temporal-arithmetic\" | \"temporal-comparison\",\n operator: string,\n left: KaladaValue,\n right: KaladaValue,\n rightPath: Path,\n): KaladaValue {\n if (!isInstant(left) && !isDuration(left)) mismatch(rightPath.slice(0, -1).concat(\"left\"));\n if (!isInstant(right) && !isDuration(right)) mismatch(rightPath);\n if (kind === \"temporal-comparison\") {\n assertSameType(left, right, rightPath);\n return compare(\n operator as Parameters<typeof compare>[0],\n left.milliseconds,\n right.milliseconds,\n );\n }\n return operator === \"add\" ? add(left, right, rightPath) : subtract(left, right, rightPath);\n}\n\nexport function isTemporalExpression<R extends JsonValue>(\n node: KaladaV1Expression<R>,\n): node is TemporalExpression<R> {\n return (\n node.kind === \"instant\" ||\n node.kind === \"duration\" ||\n node.kind === \"current-instant\" ||\n node.kind === \"temporal-arithmetic\" ||\n node.kind === \"temporal-comparison\"\n );\n}\n\nexport function evaluateTemporalExpression<R extends JsonValue>(\n node: TemporalExpression<R>,\n path: Path,\n instant: InstantValue | undefined,\n evaluate: (node: KaladaV1Expression<R>, path: Path) => KaladaValue,\n): KaladaValue {\n if (node.kind === \"instant\") return Instant.fromMilliseconds(node.milliseconds);\n if (node.kind === \"duration\") return Duration.fromMilliseconds(node.milliseconds);\n if (node.kind === \"current-instant\") {\n if (!instant) throw new KaladaFailure(\"KALADA_INSTANT_REQUIRED\", path);\n return instant;\n }\n const left = temporalOperand(evaluate, node.left, [...path, \"left\"]);\n const right = temporalOperand(evaluate, node.right, [...path, \"right\"]);\n if (node.kind === \"temporal-comparison\") {\n assertSameType(left, right, [...path, \"right\"]);\n return compare(node.operator, left.milliseconds, right.milliseconds);\n }\n return node.operator === \"add\"\n ? add(left, right, [...path, \"right\"])\n : subtract(left, right, [...path, \"right\"]);\n}\n\nfunction temporalOperand<R extends JsonValue>(\n evaluate: (node: KaladaV1Expression<R>, path: Path) => KaladaValue,\n node: KaladaV1Expression<R>,\n path: Path,\n): TemporalValue {\n const value = evaluate(node, path);\n if (!isInstant(value) && !isDuration(value)) mismatch(path);\n return value;\n}\n\nfunction add(left: TemporalValue, right: TemporalValue, path: Path): TemporalValue {\n if (isInstant(left) && isDuration(right)) {\n return Instant.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));\n }\n if (isDuration(left) && isDuration(right)) {\n return Duration.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));\n }\n return mismatch(path);\n}\n\nfunction subtract(left: TemporalValue, right: TemporalValue, path: Path): TemporalValue {\n if (isInstant(left) && isInstant(right)) {\n return Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));\n }\n if (isInstant(left) && isDuration(right)) {\n return Instant.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));\n }\n if (isDuration(left) && isDuration(right)) {\n return Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));\n }\n return mismatch(path);\n}\n\nfunction assertSameType(left: TemporalValue, right: TemporalValue, path: Path): void {\n if ((isInstant(left) && !isInstant(right)) || (isDuration(left) && !isDuration(right))) {\n mismatch(path);\n }\n}\n\nfunction compare(\n operator: Extract<KaladaV1Expression, { kind: \"temporal-comparison\" }>[\"operator\"],\n left: number,\n right: number,\n): boolean {\n if (operator === \"equal\") return left === right;\n if (operator === \"not-equal\") return left !== right;\n if (operator === \"less-than\") return left < right;\n if (operator === \"less-than-or-equal\") return left <= right;\n if (operator === \"greater-than\") return left > right;\n return left >= right;\n}\n\nfunction checked(output: number, path: Path): number {\n if (!Number.isSafeInteger(output)) throw new KaladaFailure(\"KALADA_TEMPORAL_OVERFLOW\", path);\n return Object.is(output, -0) ? 0 : output;\n}\n\nfunction mismatch(path: Path): never {\n throw new KaladaFailure(\"KALADA_TEMPORAL_TYPE_MISMATCH\", path);\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { JsonValue } from './json.cjs';
2
+ import { InstantValue, DurationValue } from './temporal.cjs';
3
+ import { KaladaV1Expression } from './types.cjs';
4
+ import { KaladaValue } from './values.cjs';
5
+
6
+ type Path = readonly (string | number)[];
7
+ type TemporalExpression<R extends JsonValue> = Extract<KaladaV1Expression<R>, {
8
+ kind: "instant" | "duration" | "current-instant" | `temporal-${string}`;
9
+ }>;
10
+ type TemporalValue = InstantValue | DurationValue;
11
+ declare function temporalLeaf(node: Extract<TemporalExpression<JsonValue>, {
12
+ kind: "instant" | "duration" | "current-instant";
13
+ }>, path: Path, instant: InstantValue | undefined): TemporalValue;
14
+ declare function applyTemporalBinary(kind: "temporal-arithmetic" | "temporal-comparison", operator: string, left: KaladaValue, right: KaladaValue, rightPath: Path): KaladaValue;
15
+ declare function isTemporalExpression<R extends JsonValue>(node: KaladaV1Expression<R>): node is TemporalExpression<R>;
16
+ declare function evaluateTemporalExpression<R extends JsonValue>(node: TemporalExpression<R>, path: Path, instant: InstantValue | undefined, evaluate: (node: KaladaV1Expression<R>, path: Path) => KaladaValue): KaladaValue;
17
+
18
+ export { applyTemporalBinary, evaluateTemporalExpression, isTemporalExpression, temporalLeaf };
@@ -0,0 +1,18 @@
1
+ import { JsonValue } from './json.js';
2
+ import { InstantValue, DurationValue } from './temporal.js';
3
+ import { KaladaV1Expression } from './types.js';
4
+ import { KaladaValue } from './values.js';
5
+
6
+ type Path = readonly (string | number)[];
7
+ type TemporalExpression<R extends JsonValue> = Extract<KaladaV1Expression<R>, {
8
+ kind: "instant" | "duration" | "current-instant" | `temporal-${string}`;
9
+ }>;
10
+ type TemporalValue = InstantValue | DurationValue;
11
+ declare function temporalLeaf(node: Extract<TemporalExpression<JsonValue>, {
12
+ kind: "instant" | "duration" | "current-instant";
13
+ }>, path: Path, instant: InstantValue | undefined): TemporalValue;
14
+ declare function applyTemporalBinary(kind: "temporal-arithmetic" | "temporal-comparison", operator: string, left: KaladaValue, right: KaladaValue, rightPath: Path): KaladaValue;
15
+ declare function isTemporalExpression<R extends JsonValue>(node: KaladaV1Expression<R>): node is TemporalExpression<R>;
16
+ declare function evaluateTemporalExpression<R extends JsonValue>(node: TemporalExpression<R>, path: Path, instant: InstantValue | undefined, evaluate: (node: KaladaV1Expression<R>, path: Path) => KaladaValue): KaladaValue;
17
+
18
+ export { applyTemporalBinary, evaluateTemporalExpression, isTemporalExpression, temporalLeaf };
@@ -0,0 +1,90 @@
1
+ import { KaladaFailure } from './diagnostics.js';
2
+ import { Instant, Duration, isInstant, isDuration } from './temporal.js';
3
+
4
+ function temporalLeaf(node, path, instant) {
5
+ if (node.kind === "instant") return Instant.fromMilliseconds(node.milliseconds);
6
+ if (node.kind === "duration") return Duration.fromMilliseconds(node.milliseconds);
7
+ if (!instant) throw new KaladaFailure("KALADA_INSTANT_REQUIRED", path);
8
+ return instant;
9
+ }
10
+ function applyTemporalBinary(kind, operator, left, right, rightPath) {
11
+ if (!isInstant(left) && !isDuration(left)) mismatch(rightPath.slice(0, -1).concat("left"));
12
+ if (!isInstant(right) && !isDuration(right)) mismatch(rightPath);
13
+ if (kind === "temporal-comparison") {
14
+ assertSameType(left, right, rightPath);
15
+ return compare(
16
+ operator,
17
+ left.milliseconds,
18
+ right.milliseconds
19
+ );
20
+ }
21
+ return operator === "add" ? add(left, right, rightPath) : subtract(left, right, rightPath);
22
+ }
23
+ function isTemporalExpression(node) {
24
+ return node.kind === "instant" || node.kind === "duration" || node.kind === "current-instant" || node.kind === "temporal-arithmetic" || node.kind === "temporal-comparison";
25
+ }
26
+ function evaluateTemporalExpression(node, path, instant, evaluate) {
27
+ if (node.kind === "instant") return Instant.fromMilliseconds(node.milliseconds);
28
+ if (node.kind === "duration") return Duration.fromMilliseconds(node.milliseconds);
29
+ if (node.kind === "current-instant") {
30
+ if (!instant) throw new KaladaFailure("KALADA_INSTANT_REQUIRED", path);
31
+ return instant;
32
+ }
33
+ const left = temporalOperand(evaluate, node.left, [...path, "left"]);
34
+ const right = temporalOperand(evaluate, node.right, [...path, "right"]);
35
+ if (node.kind === "temporal-comparison") {
36
+ assertSameType(left, right, [...path, "right"]);
37
+ return compare(node.operator, left.milliseconds, right.milliseconds);
38
+ }
39
+ return node.operator === "add" ? add(left, right, [...path, "right"]) : subtract(left, right, [...path, "right"]);
40
+ }
41
+ function temporalOperand(evaluate, node, path) {
42
+ const value = evaluate(node, path);
43
+ if (!isInstant(value) && !isDuration(value)) mismatch(path);
44
+ return value;
45
+ }
46
+ function add(left, right, path) {
47
+ if (isInstant(left) && isDuration(right)) {
48
+ return Instant.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));
49
+ }
50
+ if (isDuration(left) && isDuration(right)) {
51
+ return Duration.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));
52
+ }
53
+ return mismatch(path);
54
+ }
55
+ function subtract(left, right, path) {
56
+ if (isInstant(left) && isInstant(right)) {
57
+ return Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));
58
+ }
59
+ if (isInstant(left) && isDuration(right)) {
60
+ return Instant.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));
61
+ }
62
+ if (isDuration(left) && isDuration(right)) {
63
+ return Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));
64
+ }
65
+ return mismatch(path);
66
+ }
67
+ function assertSameType(left, right, path) {
68
+ if (isInstant(left) && !isInstant(right) || isDuration(left) && !isDuration(right)) {
69
+ mismatch(path);
70
+ }
71
+ }
72
+ function compare(operator, left, right) {
73
+ if (operator === "equal") return left === right;
74
+ if (operator === "not-equal") return left !== right;
75
+ if (operator === "less-than") return left < right;
76
+ if (operator === "less-than-or-equal") return left <= right;
77
+ if (operator === "greater-than") return left > right;
78
+ return left >= right;
79
+ }
80
+ function checked(output, path) {
81
+ if (!Number.isSafeInteger(output)) throw new KaladaFailure("KALADA_TEMPORAL_OVERFLOW", path);
82
+ return Object.is(output, -0) ? 0 : output;
83
+ }
84
+ function mismatch(path) {
85
+ throw new KaladaFailure("KALADA_TEMPORAL_TYPE_MISMATCH", path);
86
+ }
87
+
88
+ export { applyTemporalBinary, evaluateTemporalExpression, isTemporalExpression, temporalLeaf };
89
+ //# sourceMappingURL=temporal-evaluation.js.map
90
+ //# sourceMappingURL=temporal-evaluation.js.map
@@ -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,IAAI,aAAA,CAAc,+BAAA,EAAiC,IAAI,CAAA;AAC/D","file":"temporal-evaluation.js","sourcesContent":["import { KaladaFailure } from \"./diagnostics.js\";\nimport type { JsonValue } from \"./json.js\";\nimport {\n Duration,\n type DurationValue,\n Instant,\n type InstantValue,\n isDuration,\n isInstant,\n} from \"./temporal.js\";\nimport type { KaladaV1Expression } from \"./types.js\";\nimport type { KaladaValue } from \"./values.js\";\n\ntype Path = readonly (string | number)[];\ntype TemporalExpression<R extends JsonValue> = Extract<\n KaladaV1Expression<R>,\n { kind: \"instant\" | \"duration\" | \"current-instant\" | `temporal-${string}` }\n>;\ntype TemporalValue = InstantValue | DurationValue;\n\nexport function temporalLeaf(\n node: Extract<\n TemporalExpression<JsonValue>,\n { kind: \"instant\" | \"duration\" | \"current-instant\" }\n >,\n path: Path,\n instant: InstantValue | undefined,\n): TemporalValue {\n if (node.kind === \"instant\") return Instant.fromMilliseconds(node.milliseconds);\n if (node.kind === \"duration\") return Duration.fromMilliseconds(node.milliseconds);\n if (!instant) throw new KaladaFailure(\"KALADA_INSTANT_REQUIRED\", path);\n return instant;\n}\n\nexport function applyTemporalBinary(\n kind: \"temporal-arithmetic\" | \"temporal-comparison\",\n operator: string,\n left: KaladaValue,\n right: KaladaValue,\n rightPath: Path,\n): KaladaValue {\n if (!isInstant(left) && !isDuration(left)) mismatch(rightPath.slice(0, -1).concat(\"left\"));\n if (!isInstant(right) && !isDuration(right)) mismatch(rightPath);\n if (kind === \"temporal-comparison\") {\n assertSameType(left, right, rightPath);\n return compare(\n operator as Parameters<typeof compare>[0],\n left.milliseconds,\n right.milliseconds,\n );\n }\n return operator === \"add\" ? add(left, right, rightPath) : subtract(left, right, rightPath);\n}\n\nexport function isTemporalExpression<R extends JsonValue>(\n node: KaladaV1Expression<R>,\n): node is TemporalExpression<R> {\n return (\n node.kind === \"instant\" ||\n node.kind === \"duration\" ||\n node.kind === \"current-instant\" ||\n node.kind === \"temporal-arithmetic\" ||\n node.kind === \"temporal-comparison\"\n );\n}\n\nexport function evaluateTemporalExpression<R extends JsonValue>(\n node: TemporalExpression<R>,\n path: Path,\n instant: InstantValue | undefined,\n evaluate: (node: KaladaV1Expression<R>, path: Path) => KaladaValue,\n): KaladaValue {\n if (node.kind === \"instant\") return Instant.fromMilliseconds(node.milliseconds);\n if (node.kind === \"duration\") return Duration.fromMilliseconds(node.milliseconds);\n if (node.kind === \"current-instant\") {\n if (!instant) throw new KaladaFailure(\"KALADA_INSTANT_REQUIRED\", path);\n return instant;\n }\n const left = temporalOperand(evaluate, node.left, [...path, \"left\"]);\n const right = temporalOperand(evaluate, node.right, [...path, \"right\"]);\n if (node.kind === \"temporal-comparison\") {\n assertSameType(left, right, [...path, \"right\"]);\n return compare(node.operator, left.milliseconds, right.milliseconds);\n }\n return node.operator === \"add\"\n ? add(left, right, [...path, \"right\"])\n : subtract(left, right, [...path, \"right\"]);\n}\n\nfunction temporalOperand<R extends JsonValue>(\n evaluate: (node: KaladaV1Expression<R>, path: Path) => KaladaValue,\n node: KaladaV1Expression<R>,\n path: Path,\n): TemporalValue {\n const value = evaluate(node, path);\n if (!isInstant(value) && !isDuration(value)) mismatch(path);\n return value;\n}\n\nfunction add(left: TemporalValue, right: TemporalValue, path: Path): TemporalValue {\n if (isInstant(left) && isDuration(right)) {\n return Instant.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));\n }\n if (isDuration(left) && isDuration(right)) {\n return Duration.fromMilliseconds(checked(left.milliseconds + right.milliseconds, path));\n }\n return mismatch(path);\n}\n\nfunction subtract(left: TemporalValue, right: TemporalValue, path: Path): TemporalValue {\n if (isInstant(left) && isInstant(right)) {\n return Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));\n }\n if (isInstant(left) && isDuration(right)) {\n return Instant.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));\n }\n if (isDuration(left) && isDuration(right)) {\n return Duration.fromMilliseconds(checked(left.milliseconds - right.milliseconds, path));\n }\n return mismatch(path);\n}\n\nfunction assertSameType(left: TemporalValue, right: TemporalValue, path: Path): void {\n if ((isInstant(left) && !isInstant(right)) || (isDuration(left) && !isDuration(right))) {\n mismatch(path);\n }\n}\n\nfunction compare(\n operator: Extract<KaladaV1Expression, { kind: \"temporal-comparison\" }>[\"operator\"],\n left: number,\n right: number,\n): boolean {\n if (operator === \"equal\") return left === right;\n if (operator === \"not-equal\") return left !== right;\n if (operator === \"less-than\") return left < right;\n if (operator === \"less-than-or-equal\") return left <= right;\n if (operator === \"greater-than\") return left > right;\n return left >= right;\n}\n\nfunction checked(output: number, path: Path): number {\n if (!Number.isSafeInteger(output)) throw new KaladaFailure(\"KALADA_TEMPORAL_OVERFLOW\", path);\n return Object.is(output, -0) ? 0 : output;\n}\n\nfunction mismatch(path: Path): never {\n throw new KaladaFailure(\"KALADA_TEMPORAL_TYPE_MISMATCH\", path);\n}\n"]}
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const instantBrands = /* @__PURE__ */ new WeakSet();
4
+ const durationBrands = /* @__PURE__ */ new WeakSet();
5
+ function milliseconds(input) {
6
+ if (!Number.isSafeInteger(input)) throw new RangeError("Milliseconds must be a safe integer.");
7
+ return Object.is(input, -0) ? 0 : input;
8
+ }
9
+ function branded(brands, value) {
10
+ Object.freeze(value);
11
+ brands.add(value);
12
+ return value;
13
+ }
14
+ const Instant = Object.freeze({
15
+ fromMilliseconds(value) {
16
+ return branded(instantBrands, {
17
+ type: "Instant",
18
+ milliseconds: milliseconds(value)
19
+ });
20
+ }
21
+ });
22
+ const Duration = Object.freeze({
23
+ fromMilliseconds(value) {
24
+ return branded(durationBrands, {
25
+ type: "Duration",
26
+ milliseconds: milliseconds(value)
27
+ });
28
+ }
29
+ });
30
+ function isInstant(value) {
31
+ return typeof value === "object" && value !== null && instantBrands.has(value);
32
+ }
33
+ function isDuration(value) {
34
+ return typeof value === "object" && value !== null && durationBrands.has(value);
35
+ }
36
+
37
+ exports.Duration = Duration;
38
+ exports.Instant = Instant;
39
+ exports.isDuration = isDuration;
40
+ exports.isInstant = isInstant;
41
+ //# sourceMappingURL=temporal.cjs.map
42
+ //# sourceMappingURL=temporal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kalada-v1/temporal.ts"],"names":[],"mappings":";;AAAA,MAAM,aAAA,uBAAoB,OAAA,EAAgB;AAC1C,MAAM,cAAA,uBAAqB,OAAA,EAAgB;AAiB3C,SAAS,aAAa,KAAA,EAAuB;AAC3C,EAAA,IAAI,CAAC,OAAO,aAAA,CAAc,KAAK,GAAG,MAAM,IAAI,WAAW,sCAAsC,CAAA;AAC7F,EAAA,OAAO,MAAA,CAAO,EAAA,CAAG,KAAA,EAAO,EAAE,IAAI,CAAA,GAAI,KAAA;AACpC;AAEA,SAAS,OAAA,CAA0B,QAAyB,KAAA,EAAa;AACvE,EAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AACnB,EAAA,MAAA,CAAO,IAAI,KAAK,CAAA;AAChB,EAAA,OAAO,KAAA;AACT;AAEO,MAAM,OAAA,GAAU,OAAO,MAAA,CAAO;AAAA,EACnC,iBAAiB,KAAA,EAA6B;AAC5C,IAAA,OAAO,QAAQ,aAAA,EAAe;AAAA,MAC5B,IAAA,EAAM,SAAA;AAAA,MACN,YAAA,EAAc,aAAa,KAAK;AAAA,KACjB,CAAA;AAAA,EACnB;AACF,CAAC;AAEM,MAAM,QAAA,GAAW,OAAO,MAAA,CAAO;AAAA,EACpC,iBAAiB,KAAA,EAA8B;AAC7C,IAAA,OAAO,QAAQ,cAAA,EAAgB;AAAA,MAC7B,IAAA,EAAM,UAAA;AAAA,MACN,YAAA,EAAc,aAAa,KAAK;AAAA,KAChB,CAAA;AAAA,EACpB;AACF,CAAC;AAEM,SAAS,UAAU,KAAA,EAAuC;AAC/D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,IAAA,IAAQ,aAAA,CAAc,IAAI,KAAK,CAAA;AAC/E;AAEO,SAAS,WAAW,KAAA,EAAwC;AACjE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,IAAA,IAAQ,cAAA,CAAe,IAAI,KAAK,CAAA;AAChF","file":"temporal.cjs","sourcesContent":["const instantBrands = new WeakSet<object>();\nconst durationBrands = new WeakSet<object>();\n\ndeclare const instantBrand: unique symbol;\ndeclare const durationBrand: unique symbol;\n\nexport interface InstantValue {\n readonly [instantBrand]: true;\n readonly type: \"Instant\";\n readonly milliseconds: number;\n}\n\nexport interface DurationValue {\n readonly [durationBrand]: true;\n readonly type: \"Duration\";\n readonly milliseconds: number;\n}\n\nfunction milliseconds(input: number): number {\n if (!Number.isSafeInteger(input)) throw new RangeError(\"Milliseconds must be a safe integer.\");\n return Object.is(input, -0) ? 0 : input;\n}\n\nfunction branded<T extends object>(brands: WeakSet<object>, value: T): T {\n Object.freeze(value);\n brands.add(value);\n return value;\n}\n\nexport const Instant = Object.freeze({\n fromMilliseconds(value: number): InstantValue {\n return branded(instantBrands, {\n type: \"Instant\",\n milliseconds: milliseconds(value),\n } as InstantValue);\n },\n});\n\nexport const Duration = Object.freeze({\n fromMilliseconds(value: number): DurationValue {\n return branded(durationBrands, {\n type: \"Duration\",\n milliseconds: milliseconds(value),\n } as DurationValue);\n },\n});\n\nexport function isInstant(value: unknown): value is InstantValue {\n return typeof value === \"object\" && value !== null && instantBrands.has(value);\n}\n\nexport function isDuration(value: unknown): value is DurationValue {\n return typeof value === \"object\" && value !== null && durationBrands.has(value);\n}\n"]}
@@ -0,0 +1,22 @@
1
+ declare const instantBrand: unique symbol;
2
+ declare const durationBrand: unique symbol;
3
+ interface InstantValue {
4
+ readonly [instantBrand]: true;
5
+ readonly type: "Instant";
6
+ readonly milliseconds: number;
7
+ }
8
+ interface DurationValue {
9
+ readonly [durationBrand]: true;
10
+ readonly type: "Duration";
11
+ readonly milliseconds: number;
12
+ }
13
+ declare const Instant: Readonly<{
14
+ fromMilliseconds(value: number): InstantValue;
15
+ }>;
16
+ declare const Duration: Readonly<{
17
+ fromMilliseconds(value: number): DurationValue;
18
+ }>;
19
+ declare function isInstant(value: unknown): value is InstantValue;
20
+ declare function isDuration(value: unknown): value is DurationValue;
21
+
22
+ export { Duration, type DurationValue, Instant, type InstantValue, isDuration, isInstant };
@@ -0,0 +1,22 @@
1
+ declare const instantBrand: unique symbol;
2
+ declare const durationBrand: unique symbol;
3
+ interface InstantValue {
4
+ readonly [instantBrand]: true;
5
+ readonly type: "Instant";
6
+ readonly milliseconds: number;
7
+ }
8
+ interface DurationValue {
9
+ readonly [durationBrand]: true;
10
+ readonly type: "Duration";
11
+ readonly milliseconds: number;
12
+ }
13
+ declare const Instant: Readonly<{
14
+ fromMilliseconds(value: number): InstantValue;
15
+ }>;
16
+ declare const Duration: Readonly<{
17
+ fromMilliseconds(value: number): DurationValue;
18
+ }>;
19
+ declare function isInstant(value: unknown): value is InstantValue;
20
+ declare function isDuration(value: unknown): value is DurationValue;
21
+
22
+ export { Duration, type DurationValue, Instant, type InstantValue, isDuration, isInstant };
@@ -0,0 +1,37 @@
1
+ const instantBrands = /* @__PURE__ */ new WeakSet();
2
+ const durationBrands = /* @__PURE__ */ new WeakSet();
3
+ function milliseconds(input) {
4
+ if (!Number.isSafeInteger(input)) throw new RangeError("Milliseconds must be a safe integer.");
5
+ return Object.is(input, -0) ? 0 : input;
6
+ }
7
+ function branded(brands, value) {
8
+ Object.freeze(value);
9
+ brands.add(value);
10
+ return value;
11
+ }
12
+ const Instant = Object.freeze({
13
+ fromMilliseconds(value) {
14
+ return branded(instantBrands, {
15
+ type: "Instant",
16
+ milliseconds: milliseconds(value)
17
+ });
18
+ }
19
+ });
20
+ const Duration = Object.freeze({
21
+ fromMilliseconds(value) {
22
+ return branded(durationBrands, {
23
+ type: "Duration",
24
+ milliseconds: milliseconds(value)
25
+ });
26
+ }
27
+ });
28
+ function isInstant(value) {
29
+ return typeof value === "object" && value !== null && instantBrands.has(value);
30
+ }
31
+ function isDuration(value) {
32
+ return typeof value === "object" && value !== null && durationBrands.has(value);
33
+ }
34
+
35
+ export { Duration, Instant, isDuration, isInstant };
36
+ //# sourceMappingURL=temporal.js.map
37
+ //# sourceMappingURL=temporal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kalada-v1/temporal.ts"],"names":[],"mappings":"AAAA,MAAM,aAAA,uBAAoB,OAAA,EAAgB;AAC1C,MAAM,cAAA,uBAAqB,OAAA,EAAgB;AAiB3C,SAAS,aAAa,KAAA,EAAuB;AAC3C,EAAA,IAAI,CAAC,OAAO,aAAA,CAAc,KAAK,GAAG,MAAM,IAAI,WAAW,sCAAsC,CAAA;AAC7F,EAAA,OAAO,MAAA,CAAO,EAAA,CAAG,KAAA,EAAO,EAAE,IAAI,CAAA,GAAI,KAAA;AACpC;AAEA,SAAS,OAAA,CAA0B,QAAyB,KAAA,EAAa;AACvE,EAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AACnB,EAAA,MAAA,CAAO,IAAI,KAAK,CAAA;AAChB,EAAA,OAAO,KAAA;AACT;AAEO,MAAM,OAAA,GAAU,OAAO,MAAA,CAAO;AAAA,EACnC,iBAAiB,KAAA,EAA6B;AAC5C,IAAA,OAAO,QAAQ,aAAA,EAAe;AAAA,MAC5B,IAAA,EAAM,SAAA;AAAA,MACN,YAAA,EAAc,aAAa,KAAK;AAAA,KACjB,CAAA;AAAA,EACnB;AACF,CAAC;AAEM,MAAM,QAAA,GAAW,OAAO,MAAA,CAAO;AAAA,EACpC,iBAAiB,KAAA,EAA8B;AAC7C,IAAA,OAAO,QAAQ,cAAA,EAAgB;AAAA,MAC7B,IAAA,EAAM,UAAA;AAAA,MACN,YAAA,EAAc,aAAa,KAAK;AAAA,KAChB,CAAA;AAAA,EACpB;AACF,CAAC;AAEM,SAAS,UAAU,KAAA,EAAuC;AAC/D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,IAAA,IAAQ,aAAA,CAAc,IAAI,KAAK,CAAA;AAC/E;AAEO,SAAS,WAAW,KAAA,EAAwC;AACjE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,IAAA,IAAQ,cAAA,CAAe,IAAI,KAAK,CAAA;AAChF","file":"temporal.js","sourcesContent":["const instantBrands = new WeakSet<object>();\nconst durationBrands = new WeakSet<object>();\n\ndeclare const instantBrand: unique symbol;\ndeclare const durationBrand: unique symbol;\n\nexport interface InstantValue {\n readonly [instantBrand]: true;\n readonly type: \"Instant\";\n readonly milliseconds: number;\n}\n\nexport interface DurationValue {\n readonly [durationBrand]: true;\n readonly type: \"Duration\";\n readonly milliseconds: number;\n}\n\nfunction milliseconds(input: number): number {\n if (!Number.isSafeInteger(input)) throw new RangeError(\"Milliseconds must be a safe integer.\");\n return Object.is(input, -0) ? 0 : input;\n}\n\nfunction branded<T extends object>(brands: WeakSet<object>, value: T): T {\n Object.freeze(value);\n brands.add(value);\n return value;\n}\n\nexport const Instant = Object.freeze({\n fromMilliseconds(value: number): InstantValue {\n return branded(instantBrands, {\n type: \"Instant\",\n milliseconds: milliseconds(value),\n } as InstantValue);\n },\n});\n\nexport const Duration = Object.freeze({\n fromMilliseconds(value: number): DurationValue {\n return branded(durationBrands, {\n type: \"Duration\",\n milliseconds: milliseconds(value),\n } as DurationValue);\n },\n});\n\nexport function isInstant(value: unknown): value is InstantValue {\n return typeof value === \"object\" && value !== null && instantBrands.has(value);\n}\n\nexport function isDuration(value: unknown): value is DurationValue {\n return typeof value === \"object\" && value !== null && durationBrands.has(value);\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { JsonValue } from './json.cjs';
2
+ import { InstantValue } from './temporal.cjs';
2
3
  import { KaladaValue } from './values.cjs';
3
4
 
4
5
  type KaladaV1Expression<R extends JsonValue = string> = {
@@ -7,7 +8,81 @@ type KaladaV1Expression<R extends JsonValue = string> = {
7
8
  } | {
8
9
  readonly kind: "ref";
9
10
  readonly ref: R;
10
- } | BindingExpression<R> | OptionExpression<R> | ResultExpression<R> | MatchExpression<R>;
11
+ } | BindingExpression<R> | OptionExpression<R> | ResultExpression<R> | MatchExpression<R> | InstantExpression | DurationExpression | CurrentInstantExpression | TemporalArithmeticExpression<R> | TemporalComparisonExpression<R> | FunctionExpression<R> | CallExpression<R> | FunctionGroupExpression<R> | CoreFunctionExpression;
12
+ type KaladaPrimitiveTypeName = "null" | "boolean" | "number" | "string" | "json" | "Instant" | "Duration";
13
+ type KaladaType = {
14
+ readonly kind: "primitive-type";
15
+ readonly name: KaladaPrimitiveTypeName;
16
+ } | {
17
+ readonly kind: "option-type";
18
+ readonly value: KaladaType;
19
+ } | {
20
+ readonly kind: "result-type";
21
+ readonly ok: KaladaType;
22
+ readonly error: KaladaType;
23
+ } | {
24
+ readonly kind: "array-type";
25
+ readonly element: KaladaType;
26
+ } | KaladaFunctionType;
27
+ interface KaladaFunctionType {
28
+ readonly kind: "function-type";
29
+ readonly parameters: readonly KaladaType[];
30
+ readonly returns: KaladaType;
31
+ }
32
+ interface KaladaFunctionParameter {
33
+ readonly name: string;
34
+ readonly type: KaladaType;
35
+ }
36
+ interface FunctionExpression<R extends JsonValue> {
37
+ readonly kind: "function";
38
+ readonly parameters: readonly KaladaFunctionParameter[];
39
+ readonly returns: KaladaType;
40
+ readonly body: KaladaV1Expression<R>;
41
+ }
42
+ interface CallExpression<R extends JsonValue> {
43
+ readonly kind: "call";
44
+ readonly callee: KaladaV1Expression<R>;
45
+ readonly arguments: readonly KaladaV1Expression<R>[];
46
+ }
47
+ interface NamedFunction<R extends JsonValue> {
48
+ readonly name: string;
49
+ readonly parameters: readonly KaladaFunctionParameter[];
50
+ readonly returns: KaladaType;
51
+ readonly body: KaladaV1Expression<R>;
52
+ }
53
+ interface FunctionGroupExpression<R extends JsonValue> {
54
+ readonly kind: "function-group";
55
+ readonly functions: readonly NamedFunction<R>[];
56
+ readonly body: KaladaV1Expression<R>;
57
+ }
58
+ type KaladaCoreFunctionName = "map" | "filter" | "some" | "every";
59
+ interface CoreFunctionExpression {
60
+ readonly kind: "core-function";
61
+ readonly name: KaladaCoreFunctionName;
62
+ }
63
+ interface InstantExpression {
64
+ readonly kind: "instant";
65
+ readonly milliseconds: number;
66
+ }
67
+ interface DurationExpression {
68
+ readonly kind: "duration";
69
+ readonly milliseconds: number;
70
+ }
71
+ interface CurrentInstantExpression {
72
+ readonly kind: "current-instant";
73
+ }
74
+ interface TemporalArithmeticExpression<R extends JsonValue> {
75
+ readonly kind: "temporal-arithmetic";
76
+ readonly operator: "add" | "subtract";
77
+ readonly left: KaladaV1Expression<R>;
78
+ readonly right: KaladaV1Expression<R>;
79
+ }
80
+ interface TemporalComparisonExpression<R extends JsonValue> {
81
+ readonly kind: "temporal-comparison";
82
+ readonly operator: "equal" | "not-equal" | "less-than" | "less-than-or-equal" | "greater-than" | "greater-than-or-equal";
83
+ readonly left: KaladaV1Expression<R>;
84
+ readonly right: KaladaV1Expression<R>;
85
+ }
11
86
  interface BindingExpression<R extends JsonValue> {
12
87
  readonly kind: "binding";
13
88
  readonly name: string;
@@ -44,11 +119,17 @@ interface KaladaV1Program<R extends JsonValue = string> {
44
119
  readonly profile: "kalada-v1";
45
120
  readonly expression: KaladaV1Expression<R>;
46
121
  }
47
- type KaladaV1DiagnosticCode = "KALADA_INVALID_INPUT" | "KALADA_LIMIT_EXCEEDED" | "KALADA_INVALID_REFERENCE" | "KALADA_MATCH_MISSING_ARM" | "KALADA_MATCH_DUPLICATE_ARM" | "KALADA_MATCH_UNKNOWN_ARM" | "KALADA_MATCH_UNREACHABLE_ARM" | "KALADA_MATCH_TYPE_MISMATCH" | "KALADA_REFERENCE_ERROR" | "KALADA_REFERENCE_MISSING" | "KALADA_REFERENCE_DENIED" | "KALADA_ASYNC_UNSUPPORTED" | "KALADA_INVALID_RESULT" | "KALADA_EVALUATION_LIMIT";
122
+ type KaladaV1DiagnosticCode = "KALADA_INVALID_INPUT" | "KALADA_LIMIT_EXCEEDED" | "KALADA_INVALID_REFERENCE" | "KALADA_MATCH_MISSING_ARM" | "KALADA_MATCH_DUPLICATE_ARM" | "KALADA_MATCH_UNKNOWN_ARM" | "KALADA_MATCH_UNREACHABLE_ARM" | "KALADA_MATCH_TYPE_MISMATCH" | "KALADA_REFERENCE_ERROR" | "KALADA_REFERENCE_MISSING" | "KALADA_REFERENCE_DENIED" | "KALADA_ASYNC_UNSUPPORTED" | "KALADA_INVALID_RESULT" | "KALADA_EVALUATION_LIMIT" | "KALADA_INSTANT_REQUIRED" | "KALADA_TEMPORAL_TYPE_MISMATCH" | "KALADA_TEMPORAL_OVERFLOW" | "KALADA_CLOCK_ERROR" | "KALADA_INVALID_CLOCK" | "KALADA_DUPLICATE_BINDING" | "KALADA_INVALID_FUNCTION_TYPE" | "KALADA_CAPTURE_LIMIT" | "KALADA_NOT_CALLABLE" | "KALADA_FUNCTION_ARITY" | "KALADA_FUNCTION_TYPE_MISMATCH" | "KALADA_CLOSURE_LIMIT" | "KALADA_CALL_DEPTH_LIMIT" | "KALADA_CONTINUATION_LIMIT" | "KALADA_COLLECTION_TYPE_MISMATCH" | "KALADA_COLLECTION_LIMIT" | "KALADA_FUNCTION_ESCAPE";
123
+ interface KaladaV1DiagnosticContextFrame {
124
+ readonly kind: "function-call" | "core-call";
125
+ readonly name: string | null;
126
+ readonly path: readonly (string | number)[];
127
+ }
48
128
  interface KaladaV1Diagnostic {
49
129
  readonly code: KaladaV1DiagnosticCode;
50
130
  readonly path: readonly (string | number)[];
51
131
  readonly message: string;
132
+ readonly context?: readonly KaladaV1DiagnosticContextFrame[];
52
133
  }
53
134
  type KaladaV1Outcome<T> = {
54
135
  readonly ok: true;
@@ -66,13 +147,29 @@ interface KaladaV1Limits {
66
147
  readonly maxReferenceLength: number;
67
148
  readonly maxEvaluationSteps: number;
68
149
  }
150
+ interface KaladaV1FunctionLimits {
151
+ readonly maxFunctionParameters: number;
152
+ readonly maxFunctionGroupSize: number;
153
+ readonly maxCapturesPerClosure: number;
154
+ readonly maxCapturedBindings: number;
155
+ readonly maxClosures: number;
156
+ readonly maxCallDepth: number;
157
+ readonly maxContinuationFrames: number;
158
+ readonly maxCollectionLength: number;
159
+ readonly maxCollectionIterations: number;
160
+ }
161
+ interface KaladaV1FunctionCapture {
162
+ readonly path: readonly (string | number)[];
163
+ readonly name: string | null;
164
+ readonly captures: readonly string[];
165
+ }
69
166
  interface KaladaV1ReferenceCodec<R extends JsonValue> {
70
167
  readonly validate: (input: unknown) => input is R;
71
168
  readonly canonicalize?: (reference: R) => R;
72
169
  }
73
170
  interface KaladaV1Options<R extends JsonValue> {
74
171
  readonly reference?: KaladaV1ReferenceCodec<R>;
75
- readonly limits?: Partial<KaladaV1Limits>;
172
+ readonly limits?: Partial<KaladaV1Limits & KaladaV1FunctionLimits>;
76
173
  }
77
174
  type KaladaV1Resolution = {
78
175
  readonly found: true;
@@ -82,10 +179,16 @@ type KaladaV1Resolution = {
82
179
  readonly reason?: "missing" | "denied";
83
180
  };
84
181
  type KaladaV1Resolver<R extends JsonValue> = (reference: R) => KaladaV1Resolution;
182
+ interface KaladaV1EvaluationInputs {
183
+ readonly instant?: InstantValue;
184
+ }
185
+ type KaladaV1Clock = () => InstantValue;
85
186
  interface CompiledKaladaV1Program<R extends JsonValue> {
86
187
  readonly program: KaladaV1Program<R>;
87
188
  readonly dependencies: readonly R[];
88
- evaluate(resolve: KaladaV1Resolver<R>): KaladaV1Outcome<KaladaValue>;
189
+ readonly functions: readonly KaladaV1FunctionCapture[];
190
+ evaluate(resolve: KaladaV1Resolver<R>, inputs?: KaladaV1EvaluationInputs): KaladaV1Outcome<KaladaValue>;
191
+ evaluateWithClock(resolve: KaladaV1Resolver<R>, clock: KaladaV1Clock): KaladaV1Outcome<KaladaValue>;
89
192
  }
90
193
 
91
- export type { BindingExpression, CompiledKaladaV1Program, KaladaV1Diagnostic, KaladaV1DiagnosticCode, KaladaV1Expression, KaladaV1Limits, KaladaV1Options, KaladaV1Outcome, KaladaV1Program, KaladaV1ReferenceCodec, KaladaV1Resolution, KaladaV1Resolver, MatchArm, MatchExpression, OptionExpression, ResultExpression };
194
+ export type { BindingExpression, CallExpression, CompiledKaladaV1Program, CoreFunctionExpression, CurrentInstantExpression, DurationExpression, FunctionExpression, FunctionGroupExpression, InstantExpression, KaladaCoreFunctionName, KaladaFunctionParameter, KaladaFunctionType, KaladaPrimitiveTypeName, KaladaType, KaladaV1Clock, KaladaV1Diagnostic, KaladaV1DiagnosticCode, KaladaV1DiagnosticContextFrame, KaladaV1EvaluationInputs, KaladaV1Expression, KaladaV1FunctionCapture, KaladaV1FunctionLimits, KaladaV1Limits, KaladaV1Options, KaladaV1Outcome, KaladaV1Program, KaladaV1ReferenceCodec, KaladaV1Resolution, KaladaV1Resolver, MatchArm, MatchExpression, NamedFunction, OptionExpression, ResultExpression, TemporalArithmeticExpression, TemporalComparisonExpression };