@kalada/core 0.1.0 → 0.3.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/README.md +25 -0
- package/dist/kalada-v1/canonical-input.cjs +133 -0
- package/dist/kalada-v1/canonical-input.cjs.map +1 -0
- package/dist/kalada-v1/canonical-input.d.cts +25 -0
- package/dist/kalada-v1/canonical-input.d.ts +25 -0
- package/dist/kalada-v1/canonical-input.js +122 -0
- package/dist/kalada-v1/canonical-input.js.map +1 -0
- package/dist/kalada-v1/canonicalize.cjs +214 -0
- package/dist/kalada-v1/canonicalize.cjs.map +1 -0
- package/dist/kalada-v1/canonicalize.d.cts +8 -0
- package/dist/kalada-v1/canonicalize.d.ts +8 -0
- package/dist/kalada-v1/canonicalize.js +212 -0
- package/dist/kalada-v1/canonicalize.js.map +1 -0
- package/dist/kalada-v1/codec.cjs +173 -0
- package/dist/kalada-v1/codec.cjs.map +1 -0
- package/dist/kalada-v1/codec.d.cts +32 -0
- package/dist/kalada-v1/codec.d.ts +32 -0
- package/dist/kalada-v1/codec.js +170 -0
- package/dist/kalada-v1/codec.js.map +1 -0
- package/dist/kalada-v1/compile.cjs +45 -0
- package/dist/kalada-v1/compile.cjs.map +1 -0
- package/dist/kalada-v1/compile.d.cts +8 -0
- package/dist/kalada-v1/compile.d.ts +8 -0
- package/dist/kalada-v1/compile.js +43 -0
- package/dist/kalada-v1/compile.js.map +1 -0
- package/dist/kalada-v1/dependencies.cjs +58 -0
- package/dist/kalada-v1/dependencies.cjs.map +1 -0
- package/dist/kalada-v1/dependencies.d.cts +8 -0
- package/dist/kalada-v1/dependencies.d.ts +8 -0
- package/dist/kalada-v1/dependencies.js +56 -0
- package/dist/kalada-v1/dependencies.js.map +1 -0
- package/dist/kalada-v1/diagnostics.cjs +49 -0
- package/dist/kalada-v1/diagnostics.cjs.map +1 -0
- package/dist/kalada-v1/diagnostics.d.cts +14 -0
- package/dist/kalada-v1/diagnostics.d.ts +14 -0
- package/dist/kalada-v1/diagnostics.js +45 -0
- package/dist/kalada-v1/diagnostics.js.map +1 -0
- package/dist/kalada-v1/evaluate.cjs +176 -0
- package/dist/kalada-v1/evaluate.cjs.map +1 -0
- package/dist/kalada-v1/evaluate.d.cts +8 -0
- package/dist/kalada-v1/evaluate.d.ts +8 -0
- package/dist/kalada-v1/evaluate.js +174 -0
- package/dist/kalada-v1/evaluate.js.map +1 -0
- package/dist/kalada-v1/factories.cjs +66 -0
- package/dist/kalada-v1/factories.cjs.map +1 -0
- package/dist/kalada-v1/factories.d.cts +30 -0
- package/dist/kalada-v1/factories.d.ts +30 -0
- package/dist/kalada-v1/factories.js +64 -0
- package/dist/kalada-v1/factories.js.map +1 -0
- package/dist/kalada-v1/index.cjs +88 -0
- package/dist/kalada-v1/index.cjs.map +1 -0
- package/dist/kalada-v1/index.d.cts +11 -0
- package/dist/kalada-v1/index.d.ts +11 -0
- package/dist/kalada-v1/index.js +11 -0
- package/dist/kalada-v1/index.js.map +1 -0
- package/dist/kalada-v1/json.cjs +129 -0
- package/dist/kalada-v1/json.cjs.map +1 -0
- package/dist/kalada-v1/json.d.cts +20 -0
- package/dist/kalada-v1/json.d.ts +20 -0
- package/dist/kalada-v1/json.js +123 -0
- package/dist/kalada-v1/json.js.map +1 -0
- package/dist/kalada-v1/limits.cjs +34 -0
- package/dist/kalada-v1/limits.cjs.map +1 -0
- package/dist/kalada-v1/limits.d.cts +9 -0
- package/dist/kalada-v1/limits.d.ts +9 -0
- package/dist/kalada-v1/limits.js +31 -0
- package/dist/kalada-v1/limits.js.map +1 -0
- package/dist/kalada-v1/schemas.cjs +182 -0
- package/dist/kalada-v1/schemas.cjs.map +1 -0
- package/dist/kalada-v1/schemas.d.cts +5 -0
- package/dist/kalada-v1/schemas.d.ts +5 -0
- package/dist/kalada-v1/schemas.js +179 -0
- package/dist/kalada-v1/schemas.js.map +1 -0
- package/dist/kalada-v1/temporal-evaluation.cjs +74 -0
- package/dist/kalada-v1/temporal-evaluation.cjs.map +1 -0
- package/dist/kalada-v1/temporal-evaluation.d.cts +13 -0
- package/dist/kalada-v1/temporal-evaluation.d.ts +13 -0
- package/dist/kalada-v1/temporal-evaluation.js +71 -0
- package/dist/kalada-v1/temporal-evaluation.js.map +1 -0
- package/dist/kalada-v1/temporal.cjs +42 -0
- package/dist/kalada-v1/temporal.cjs.map +1 -0
- package/dist/kalada-v1/temporal.d.cts +22 -0
- package/dist/kalada-v1/temporal.d.ts +22 -0
- package/dist/kalada-v1/temporal.js +37 -0
- package/dist/kalada-v1/temporal.js.map +1 -0
- package/dist/kalada-v1/types.cjs +4 -0
- package/dist/kalada-v1/types.cjs.map +1 -0
- package/dist/kalada-v1/types.d.cts +120 -0
- package/dist/kalada-v1/types.d.ts +120 -0
- package/dist/kalada-v1/types.js +3 -0
- package/dist/kalada-v1/types.js.map +1 -0
- package/dist/kalada-v1/values.cjs +112 -0
- package/dist/kalada-v1/values.cjs.map +1 -0
- package/dist/kalada-v1/values.d.cts +49 -0
- package/dist/kalada-v1/values.d.ts +49 -0
- package/dist/kalada-v1/values.js +105 -0
- package/dist/kalada-v1/values.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kalada-v1/temporal-evaluation.ts"],"names":[],"mappings":";;;AAoBO,SAAS,qBACd,IAAA,EAC+B;AAC/B,EAAA,OACE,IAAA,CAAK,IAAA,KAAS,SAAA,IACd,IAAA,CAAK,IAAA,KAAS,UAAA,IACd,IAAA,CAAK,IAAA,KAAS,iBAAA,IACd,IAAA,CAAK,IAAA,KAAS,qBAAA,IACd,KAAK,IAAA,KAAS,qBAAA;AAElB;AAEO,SAAS,0BAAA,CACd,IAAA,EACA,IAAA,EACA,OAAA,EACA,QAAA,EACa;AACb,EAAA,IAAI,KAAK,IAAA,KAAS,SAAA,SAAkB,OAAA,CAAQ,gBAAA,CAAiB,KAAK,YAAY,CAAA;AAC9E,EAAA,IAAI,KAAK,IAAA,KA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,IAAI,CAAA,IAAK,CAAC,SAAA,CAAU,KAAK,CAAA,IAAO,UAAA,CAAW,IAAI,CAAA,IAAK,CAAC,UAAA,CAAW,KAAK,CAAA,EAAI;AACtF,IAAA,QAAA,CAAS,IAAI,CAAA;AAAA,EACf;AACF;AAEA,SAAS,OAAA,CACP,QAAA,EACA,IAAA,EACA,KAAA,EACS;AACT,EAAA,IAAI,QAAA,KAAa,OAAA,EAAS,OAAO,IAAA,KAAS,KAAA;AAC1C,EAAA,IAAI,QAAA,KAAa,WAAA,EAAa,OAAO,IAAA,KAAS,KAAA;AAC9C,EAAA,IAAI,QAAA,KAAa,WAAA,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,IAAI,aAAA,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,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 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
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AO,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.cjs"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { JsonValue } from './json.cjs';
|
|
2
|
+
import { InstantValue } from './temporal.cjs';
|
|
3
|
+
import { KaladaValue } from './values.cjs';
|
|
4
|
+
|
|
5
|
+
type KaladaV1Expression<R extends JsonValue = string> = {
|
|
6
|
+
readonly kind: "literal";
|
|
7
|
+
readonly value: JsonValue;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "ref";
|
|
10
|
+
readonly ref: R;
|
|
11
|
+
} | BindingExpression<R> | OptionExpression<R> | ResultExpression<R> | MatchExpression<R> | InstantExpression | DurationExpression | CurrentInstantExpression | TemporalArithmeticExpression<R> | TemporalComparisonExpression<R>;
|
|
12
|
+
interface InstantExpression {
|
|
13
|
+
readonly kind: "instant";
|
|
14
|
+
readonly milliseconds: number;
|
|
15
|
+
}
|
|
16
|
+
interface DurationExpression {
|
|
17
|
+
readonly kind: "duration";
|
|
18
|
+
readonly milliseconds: number;
|
|
19
|
+
}
|
|
20
|
+
interface CurrentInstantExpression {
|
|
21
|
+
readonly kind: "current-instant";
|
|
22
|
+
}
|
|
23
|
+
interface TemporalArithmeticExpression<R extends JsonValue> {
|
|
24
|
+
readonly kind: "temporal-arithmetic";
|
|
25
|
+
readonly operator: "add" | "subtract";
|
|
26
|
+
readonly left: KaladaV1Expression<R>;
|
|
27
|
+
readonly right: KaladaV1Expression<R>;
|
|
28
|
+
}
|
|
29
|
+
interface TemporalComparisonExpression<R extends JsonValue> {
|
|
30
|
+
readonly kind: "temporal-comparison";
|
|
31
|
+
readonly operator: "equal" | "not-equal" | "less-than" | "less-than-or-equal" | "greater-than" | "greater-than-or-equal";
|
|
32
|
+
readonly left: KaladaV1Expression<R>;
|
|
33
|
+
readonly right: KaladaV1Expression<R>;
|
|
34
|
+
}
|
|
35
|
+
interface BindingExpression<R extends JsonValue> {
|
|
36
|
+
readonly kind: "binding";
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly value: KaladaV1Expression<R>;
|
|
39
|
+
readonly body: KaladaV1Expression<R>;
|
|
40
|
+
}
|
|
41
|
+
type OptionExpression<R extends JsonValue> = {
|
|
42
|
+
readonly kind: "option";
|
|
43
|
+
readonly variant: "none";
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "option";
|
|
46
|
+
readonly variant: "some";
|
|
47
|
+
readonly value: KaladaV1Expression<R>;
|
|
48
|
+
};
|
|
49
|
+
interface ResultExpression<R extends JsonValue> {
|
|
50
|
+
readonly kind: "result";
|
|
51
|
+
readonly variant: "ok" | "err";
|
|
52
|
+
readonly value: KaladaV1Expression<R>;
|
|
53
|
+
}
|
|
54
|
+
interface MatchExpression<R extends JsonValue> {
|
|
55
|
+
readonly kind: "match";
|
|
56
|
+
readonly type: "Option" | "Result";
|
|
57
|
+
readonly value: KaladaV1Expression<R>;
|
|
58
|
+
readonly arms: readonly MatchArm<R>[];
|
|
59
|
+
}
|
|
60
|
+
interface MatchArm<R extends JsonValue> {
|
|
61
|
+
readonly variant: "some" | "none" | "ok" | "err";
|
|
62
|
+
readonly binding?: string;
|
|
63
|
+
readonly body: KaladaV1Expression<R>;
|
|
64
|
+
}
|
|
65
|
+
interface KaladaV1Program<R extends JsonValue = string> {
|
|
66
|
+
readonly format: "kalada-program";
|
|
67
|
+
readonly version: 1;
|
|
68
|
+
readonly profile: "kalada-v1";
|
|
69
|
+
readonly expression: KaladaV1Expression<R>;
|
|
70
|
+
}
|
|
71
|
+
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";
|
|
72
|
+
interface KaladaV1Diagnostic {
|
|
73
|
+
readonly code: KaladaV1DiagnosticCode;
|
|
74
|
+
readonly path: readonly (string | number)[];
|
|
75
|
+
readonly message: string;
|
|
76
|
+
}
|
|
77
|
+
type KaladaV1Outcome<T> = {
|
|
78
|
+
readonly ok: true;
|
|
79
|
+
readonly value: T;
|
|
80
|
+
} | {
|
|
81
|
+
readonly ok: false;
|
|
82
|
+
readonly diagnostic: KaladaV1Diagnostic;
|
|
83
|
+
};
|
|
84
|
+
interface KaladaV1Limits {
|
|
85
|
+
readonly maxAstDepth: number;
|
|
86
|
+
readonly maxAstNodes: number;
|
|
87
|
+
readonly maxValueDepth: number;
|
|
88
|
+
readonly maxValueNodes: number;
|
|
89
|
+
readonly maxStringLength: number;
|
|
90
|
+
readonly maxReferenceLength: number;
|
|
91
|
+
readonly maxEvaluationSteps: number;
|
|
92
|
+
}
|
|
93
|
+
interface KaladaV1ReferenceCodec<R extends JsonValue> {
|
|
94
|
+
readonly validate: (input: unknown) => input is R;
|
|
95
|
+
readonly canonicalize?: (reference: R) => R;
|
|
96
|
+
}
|
|
97
|
+
interface KaladaV1Options<R extends JsonValue> {
|
|
98
|
+
readonly reference?: KaladaV1ReferenceCodec<R>;
|
|
99
|
+
readonly limits?: Partial<KaladaV1Limits>;
|
|
100
|
+
}
|
|
101
|
+
type KaladaV1Resolution = {
|
|
102
|
+
readonly found: true;
|
|
103
|
+
readonly value: KaladaValue;
|
|
104
|
+
} | {
|
|
105
|
+
readonly found: false;
|
|
106
|
+
readonly reason?: "missing" | "denied";
|
|
107
|
+
};
|
|
108
|
+
type KaladaV1Resolver<R extends JsonValue> = (reference: R) => KaladaV1Resolution;
|
|
109
|
+
interface KaladaV1EvaluationInputs {
|
|
110
|
+
readonly instant?: InstantValue;
|
|
111
|
+
}
|
|
112
|
+
type KaladaV1Clock = () => InstantValue;
|
|
113
|
+
interface CompiledKaladaV1Program<R extends JsonValue> {
|
|
114
|
+
readonly program: KaladaV1Program<R>;
|
|
115
|
+
readonly dependencies: readonly R[];
|
|
116
|
+
evaluate(resolve: KaladaV1Resolver<R>, inputs?: KaladaV1EvaluationInputs): KaladaV1Outcome<KaladaValue>;
|
|
117
|
+
evaluateWithClock(resolve: KaladaV1Resolver<R>, clock: KaladaV1Clock): KaladaV1Outcome<KaladaValue>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type { BindingExpression, CompiledKaladaV1Program, CurrentInstantExpression, DurationExpression, InstantExpression, KaladaV1Clock, KaladaV1Diagnostic, KaladaV1DiagnosticCode, KaladaV1EvaluationInputs, KaladaV1Expression, KaladaV1Limits, KaladaV1Options, KaladaV1Outcome, KaladaV1Program, KaladaV1ReferenceCodec, KaladaV1Resolution, KaladaV1Resolver, MatchArm, MatchExpression, OptionExpression, ResultExpression, TemporalArithmeticExpression, TemporalComparisonExpression };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { JsonValue } from './json.js';
|
|
2
|
+
import { InstantValue } from './temporal.js';
|
|
3
|
+
import { KaladaValue } from './values.js';
|
|
4
|
+
|
|
5
|
+
type KaladaV1Expression<R extends JsonValue = string> = {
|
|
6
|
+
readonly kind: "literal";
|
|
7
|
+
readonly value: JsonValue;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "ref";
|
|
10
|
+
readonly ref: R;
|
|
11
|
+
} | BindingExpression<R> | OptionExpression<R> | ResultExpression<R> | MatchExpression<R> | InstantExpression | DurationExpression | CurrentInstantExpression | TemporalArithmeticExpression<R> | TemporalComparisonExpression<R>;
|
|
12
|
+
interface InstantExpression {
|
|
13
|
+
readonly kind: "instant";
|
|
14
|
+
readonly milliseconds: number;
|
|
15
|
+
}
|
|
16
|
+
interface DurationExpression {
|
|
17
|
+
readonly kind: "duration";
|
|
18
|
+
readonly milliseconds: number;
|
|
19
|
+
}
|
|
20
|
+
interface CurrentInstantExpression {
|
|
21
|
+
readonly kind: "current-instant";
|
|
22
|
+
}
|
|
23
|
+
interface TemporalArithmeticExpression<R extends JsonValue> {
|
|
24
|
+
readonly kind: "temporal-arithmetic";
|
|
25
|
+
readonly operator: "add" | "subtract";
|
|
26
|
+
readonly left: KaladaV1Expression<R>;
|
|
27
|
+
readonly right: KaladaV1Expression<R>;
|
|
28
|
+
}
|
|
29
|
+
interface TemporalComparisonExpression<R extends JsonValue> {
|
|
30
|
+
readonly kind: "temporal-comparison";
|
|
31
|
+
readonly operator: "equal" | "not-equal" | "less-than" | "less-than-or-equal" | "greater-than" | "greater-than-or-equal";
|
|
32
|
+
readonly left: KaladaV1Expression<R>;
|
|
33
|
+
readonly right: KaladaV1Expression<R>;
|
|
34
|
+
}
|
|
35
|
+
interface BindingExpression<R extends JsonValue> {
|
|
36
|
+
readonly kind: "binding";
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly value: KaladaV1Expression<R>;
|
|
39
|
+
readonly body: KaladaV1Expression<R>;
|
|
40
|
+
}
|
|
41
|
+
type OptionExpression<R extends JsonValue> = {
|
|
42
|
+
readonly kind: "option";
|
|
43
|
+
readonly variant: "none";
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "option";
|
|
46
|
+
readonly variant: "some";
|
|
47
|
+
readonly value: KaladaV1Expression<R>;
|
|
48
|
+
};
|
|
49
|
+
interface ResultExpression<R extends JsonValue> {
|
|
50
|
+
readonly kind: "result";
|
|
51
|
+
readonly variant: "ok" | "err";
|
|
52
|
+
readonly value: KaladaV1Expression<R>;
|
|
53
|
+
}
|
|
54
|
+
interface MatchExpression<R extends JsonValue> {
|
|
55
|
+
readonly kind: "match";
|
|
56
|
+
readonly type: "Option" | "Result";
|
|
57
|
+
readonly value: KaladaV1Expression<R>;
|
|
58
|
+
readonly arms: readonly MatchArm<R>[];
|
|
59
|
+
}
|
|
60
|
+
interface MatchArm<R extends JsonValue> {
|
|
61
|
+
readonly variant: "some" | "none" | "ok" | "err";
|
|
62
|
+
readonly binding?: string;
|
|
63
|
+
readonly body: KaladaV1Expression<R>;
|
|
64
|
+
}
|
|
65
|
+
interface KaladaV1Program<R extends JsonValue = string> {
|
|
66
|
+
readonly format: "kalada-program";
|
|
67
|
+
readonly version: 1;
|
|
68
|
+
readonly profile: "kalada-v1";
|
|
69
|
+
readonly expression: KaladaV1Expression<R>;
|
|
70
|
+
}
|
|
71
|
+
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";
|
|
72
|
+
interface KaladaV1Diagnostic {
|
|
73
|
+
readonly code: KaladaV1DiagnosticCode;
|
|
74
|
+
readonly path: readonly (string | number)[];
|
|
75
|
+
readonly message: string;
|
|
76
|
+
}
|
|
77
|
+
type KaladaV1Outcome<T> = {
|
|
78
|
+
readonly ok: true;
|
|
79
|
+
readonly value: T;
|
|
80
|
+
} | {
|
|
81
|
+
readonly ok: false;
|
|
82
|
+
readonly diagnostic: KaladaV1Diagnostic;
|
|
83
|
+
};
|
|
84
|
+
interface KaladaV1Limits {
|
|
85
|
+
readonly maxAstDepth: number;
|
|
86
|
+
readonly maxAstNodes: number;
|
|
87
|
+
readonly maxValueDepth: number;
|
|
88
|
+
readonly maxValueNodes: number;
|
|
89
|
+
readonly maxStringLength: number;
|
|
90
|
+
readonly maxReferenceLength: number;
|
|
91
|
+
readonly maxEvaluationSteps: number;
|
|
92
|
+
}
|
|
93
|
+
interface KaladaV1ReferenceCodec<R extends JsonValue> {
|
|
94
|
+
readonly validate: (input: unknown) => input is R;
|
|
95
|
+
readonly canonicalize?: (reference: R) => R;
|
|
96
|
+
}
|
|
97
|
+
interface KaladaV1Options<R extends JsonValue> {
|
|
98
|
+
readonly reference?: KaladaV1ReferenceCodec<R>;
|
|
99
|
+
readonly limits?: Partial<KaladaV1Limits>;
|
|
100
|
+
}
|
|
101
|
+
type KaladaV1Resolution = {
|
|
102
|
+
readonly found: true;
|
|
103
|
+
readonly value: KaladaValue;
|
|
104
|
+
} | {
|
|
105
|
+
readonly found: false;
|
|
106
|
+
readonly reason?: "missing" | "denied";
|
|
107
|
+
};
|
|
108
|
+
type KaladaV1Resolver<R extends JsonValue> = (reference: R) => KaladaV1Resolution;
|
|
109
|
+
interface KaladaV1EvaluationInputs {
|
|
110
|
+
readonly instant?: InstantValue;
|
|
111
|
+
}
|
|
112
|
+
type KaladaV1Clock = () => InstantValue;
|
|
113
|
+
interface CompiledKaladaV1Program<R extends JsonValue> {
|
|
114
|
+
readonly program: KaladaV1Program<R>;
|
|
115
|
+
readonly dependencies: readonly R[];
|
|
116
|
+
evaluate(resolve: KaladaV1Resolver<R>, inputs?: KaladaV1EvaluationInputs): KaladaV1Outcome<KaladaValue>;
|
|
117
|
+
evaluateWithClock(resolve: KaladaV1Resolver<R>, clock: KaladaV1Clock): KaladaV1Outcome<KaladaValue>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type { BindingExpression, CompiledKaladaV1Program, CurrentInstantExpression, DurationExpression, InstantExpression, KaladaV1Clock, KaladaV1Diagnostic, KaladaV1DiagnosticCode, KaladaV1EvaluationInputs, KaladaV1Expression, KaladaV1Limits, KaladaV1Options, KaladaV1Outcome, KaladaV1Program, KaladaV1ReferenceCodec, KaladaV1Resolution, KaladaV1Resolver, MatchArm, MatchExpression, OptionExpression, ResultExpression, TemporalArithmeticExpression, TemporalComparisonExpression };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var json_js = require('./json.js');
|
|
4
|
+
var temporal_js = require('./temporal.js');
|
|
5
|
+
|
|
6
|
+
const optionBrands = /* @__PURE__ */ new WeakSet();
|
|
7
|
+
const resultBrands = /* @__PURE__ */ new WeakSet();
|
|
8
|
+
const DEFAULT_VALUE_LIMITS = Object.freeze({
|
|
9
|
+
maxDepth: 64,
|
|
10
|
+
maxNodes: 1e4,
|
|
11
|
+
maxStringLength: 1e4
|
|
12
|
+
});
|
|
13
|
+
function branded(brand, value) {
|
|
14
|
+
Object.freeze(value);
|
|
15
|
+
brand.add(value);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function snapshot(value) {
|
|
19
|
+
if (isOption(value) || isResult(value) || temporal_js.isInstant(value) || temporal_js.isDuration(value)) return value;
|
|
20
|
+
return json_js.cloneJson(value, DEFAULT_VALUE_LIMITS);
|
|
21
|
+
}
|
|
22
|
+
const NONE = branded(optionBrands, { type: "Option", variant: "none" });
|
|
23
|
+
const Option = Object.freeze({
|
|
24
|
+
some(value) {
|
|
25
|
+
return branded(optionBrands, {
|
|
26
|
+
type: "Option",
|
|
27
|
+
variant: "some",
|
|
28
|
+
value: snapshot(value)
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
none() {
|
|
32
|
+
return NONE;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const Result = Object.freeze({
|
|
36
|
+
ok(value) {
|
|
37
|
+
return branded(resultBrands, {
|
|
38
|
+
type: "Result",
|
|
39
|
+
variant: "ok",
|
|
40
|
+
value: snapshot(value)
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
err(value) {
|
|
44
|
+
return branded(resultBrands, {
|
|
45
|
+
type: "Result",
|
|
46
|
+
variant: "err",
|
|
47
|
+
value: snapshot(value)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
function isOption(value) {
|
|
52
|
+
return typeof value === "object" && value !== null && optionBrands.has(value);
|
|
53
|
+
}
|
|
54
|
+
function isResult(value) {
|
|
55
|
+
return typeof value === "object" && value !== null && resultBrands.has(value);
|
|
56
|
+
}
|
|
57
|
+
function equalKaladaValues(left, right) {
|
|
58
|
+
if (temporal_js.isInstant(left) || temporal_js.isInstant(right))
|
|
59
|
+
return temporal_js.isInstant(left) && temporal_js.isInstant(right) && left.milliseconds === right.milliseconds;
|
|
60
|
+
if (temporal_js.isDuration(left) || temporal_js.isDuration(right))
|
|
61
|
+
return temporal_js.isDuration(left) && temporal_js.isDuration(right) && left.milliseconds === right.milliseconds;
|
|
62
|
+
if (isOption(left) || isOption(right)) return equalOptions(left, right);
|
|
63
|
+
if (isResult(left) || isResult(right)) return equalResults(left, right);
|
|
64
|
+
return json_js.deepEqualJson(left, right);
|
|
65
|
+
}
|
|
66
|
+
function validateKaladaValueLimits(value, limits) {
|
|
67
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
68
|
+
let current = value;
|
|
69
|
+
let depth = 0;
|
|
70
|
+
let nodes = 0;
|
|
71
|
+
while (isOption(current) || isResult(current)) {
|
|
72
|
+
nodes += 1;
|
|
73
|
+
if (depth > limits.maxDepth || nodes > limits.maxNodes) throw new RangeError("limit");
|
|
74
|
+
if (seen.has(current)) throw new TypeError("cycle");
|
|
75
|
+
seen.add(current);
|
|
76
|
+
if (isOption(current) && current.variant === "none") return;
|
|
77
|
+
current = current.value;
|
|
78
|
+
depth += 1;
|
|
79
|
+
}
|
|
80
|
+
if (temporal_js.isInstant(current) || temporal_js.isDuration(current)) {
|
|
81
|
+
validateTemporalLeaf(depth, nodes, limits);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const remainingDepth = limits.maxDepth - depth;
|
|
85
|
+
if (remainingDepth < 0) throw new RangeError("limit");
|
|
86
|
+
json_js.cloneJsonWithStats(current, {
|
|
87
|
+
maxDepth: remainingDepth,
|
|
88
|
+
maxNodes: limits.maxNodes - nodes,
|
|
89
|
+
maxStringLength: limits.maxStringLength
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function validateTemporalLeaf(depth, nodes, limits) {
|
|
93
|
+
if (depth > limits.maxDepth || nodes + 1 > limits.maxNodes) throw new RangeError("limit");
|
|
94
|
+
}
|
|
95
|
+
function equalOptions(left, right) {
|
|
96
|
+
if (!isOption(left) || !isOption(right) || left.variant !== right.variant) return false;
|
|
97
|
+
if (left.variant === "none" || right.variant === "none") return true;
|
|
98
|
+
return equalKaladaValues(left.value, right.value);
|
|
99
|
+
}
|
|
100
|
+
function equalResults(left, right) {
|
|
101
|
+
if (!isResult(left) || !isResult(right) || left.variant !== right.variant) return false;
|
|
102
|
+
return equalKaladaValues(left.value, right.value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.Option = Option;
|
|
106
|
+
exports.Result = Result;
|
|
107
|
+
exports.equalKaladaValues = equalKaladaValues;
|
|
108
|
+
exports.isOption = isOption;
|
|
109
|
+
exports.isResult = isResult;
|
|
110
|
+
exports.validateKaladaValueLimits = validateKaladaValueLimits;
|
|
111
|
+
//# sourceMappingURL=values.cjs.map
|
|
112
|
+
//# sourceMappingURL=values.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kalada-v1/values.ts"],"names":["isInstant","isDuration","cloneJson","deepEqualJson","cloneJsonWithStats"],"mappings":";;;;;AAqCA,MAAM,YAAA,uBAAmB,OAAA,EAAgB;AACzC,MAAM,YAAA,uBAAmB,OAAA,EAAgB;AACzC,MAAM,oBAAA,GAAuB,OAAO,MAAA,CAAO;AAAA,EACzC,QAAA,EAAU,EAAA;AAAA,EACV,QAAA,EAAU,GAAA;AAAA,EACV,eAAA,EAAiB;AACnB,CAAC,CAAA;AAED,SAAS,OAAA,CAA0B,OAAwB,KAAA,EAAa;AACtE,EAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AACnB,EAAA,KAAA,CAAM,IAAI,KAAK,CAAA;AACf,EAAA,OAAO,KAAA;AACT;AAEA,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AA,KAAY,MAAA,IAAU,KAAA,CAAM,OAAA,KAAY,QAAQ,OAAO,IAAA;AAChE,EAAA,OAAO,iBAAA,CAAkB,IAAA,CAAK,KAAA,EAAO,KAAA,CAAM,KAAK,CAAA;AAClD;AAEA,SAAS,YAAA,CAAa,MAAmB,KAAA,EAA6B;AACpE,EAAA,IAAI,CAAC,QAAA,CAAS,IAAI,CAAA,IAAK,CAAC,QAAA,CAAS,KAAK,CAAA,IAAK,IAAA,CAAK,OAAA,KAAY,KAAA,CAAM,OAAA,EAAS,OAAO,KAAA;AAClF,EAAA,OAAO,iBAAA,CAAkB,IAAA,CAAK,KAAA,EAAO,KAAA,CAAM,KAAK,CAAA;AAClD","file":"values.cjs","sourcesContent":["import { cloneJson, cloneJsonWithStats, deepEqualJson, type JsonValue } from \"./json.js\";\nimport { type DurationValue, type InstantValue, isDuration, isInstant } from \"./temporal.js\";\n\nexport type KaladaValue = JsonValue | OptionValue | ResultValue | InstantValue | DurationValue;\nexport type OptionValue = SomeValue | NoneValue;\nexport type ResultValue = OkValue | ErrValue;\n\ndeclare const optionBrand: unique symbol;\ndeclare const resultBrand: unique symbol;\n\nexport interface SomeValue {\n readonly [optionBrand]: true;\n readonly type: \"Option\";\n readonly variant: \"some\";\n readonly value: KaladaValue;\n}\n\nexport interface NoneValue {\n readonly [optionBrand]: true;\n readonly type: \"Option\";\n readonly variant: \"none\";\n}\n\nexport interface OkValue {\n readonly [resultBrand]: true;\n readonly type: \"Result\";\n readonly variant: \"ok\";\n readonly value: KaladaValue;\n}\n\nexport interface ErrValue {\n readonly [resultBrand]: true;\n readonly type: \"Result\";\n readonly variant: \"err\";\n readonly value: KaladaValue;\n}\n\nconst optionBrands = new WeakSet<object>();\nconst resultBrands = new WeakSet<object>();\nconst DEFAULT_VALUE_LIMITS = Object.freeze({\n maxDepth: 64,\n maxNodes: 10_000,\n maxStringLength: 10_000,\n});\n\nfunction branded<T extends object>(brand: WeakSet<object>, value: T): T {\n Object.freeze(value);\n brand.add(value);\n return value;\n}\n\nfunction snapshot(value: KaladaValue): KaladaValue {\n if (isOption(value) || isResult(value) || isInstant(value) || isDuration(value)) return value;\n return cloneJson(value, DEFAULT_VALUE_LIMITS);\n}\n\nconst NONE = branded(optionBrands, { type: \"Option\", variant: \"none\" } as unknown as NoneValue);\n\nexport const Option = Object.freeze({\n some(value: KaladaValue): SomeValue {\n return branded(optionBrands, {\n type: \"Option\",\n variant: \"some\",\n value: snapshot(value),\n } as unknown as SomeValue);\n },\n none(): NoneValue {\n return NONE;\n },\n});\n\nexport const Result = Object.freeze({\n ok(value: KaladaValue): OkValue {\n return branded(resultBrands, {\n type: \"Result\",\n variant: \"ok\",\n value: snapshot(value),\n } as unknown as OkValue);\n },\n err(value: KaladaValue): ErrValue {\n return branded(resultBrands, {\n type: \"Result\",\n variant: \"err\",\n value: snapshot(value),\n } as unknown as ErrValue);\n },\n});\n\nexport function isOption(value: unknown): value is OptionValue {\n return typeof value === \"object\" && value !== null && optionBrands.has(value);\n}\n\nexport function isResult(value: unknown): value is ResultValue {\n return typeof value === \"object\" && value !== null && resultBrands.has(value);\n}\n\nexport function equalKaladaValues(left: KaladaValue, right: KaladaValue): boolean {\n if (isInstant(left) || isInstant(right))\n return isInstant(left) && isInstant(right) && left.milliseconds === right.milliseconds;\n if (isDuration(left) || isDuration(right))\n return isDuration(left) && isDuration(right) && left.milliseconds === right.milliseconds;\n if (isOption(left) || isOption(right)) return equalOptions(left, right);\n if (isResult(left) || isResult(right)) return equalResults(left, right);\n return deepEqualJson(left, right);\n}\n\nexport function validateKaladaValueLimits(\n value: KaladaValue,\n limits: {\n readonly maxDepth: number;\n readonly maxNodes: number;\n readonly maxStringLength: number;\n },\n): void {\n const seen = new WeakSet<object>();\n let current = value;\n let depth = 0;\n let nodes = 0;\n while (isOption(current) || isResult(current)) {\n nodes += 1;\n if (depth > limits.maxDepth || nodes > limits.maxNodes) throw new RangeError(\"limit\");\n if (seen.has(current)) throw new TypeError(\"cycle\");\n seen.add(current);\n if (isOption(current) && current.variant === \"none\") return;\n current = current.value;\n depth += 1;\n }\n if (isInstant(current) || isDuration(current)) {\n validateTemporalLeaf(depth, nodes, limits);\n return;\n }\n const remainingDepth = limits.maxDepth - depth;\n if (remainingDepth < 0) throw new RangeError(\"limit\");\n cloneJsonWithStats(current, {\n maxDepth: remainingDepth,\n maxNodes: limits.maxNodes - nodes,\n maxStringLength: limits.maxStringLength,\n });\n}\n\nfunction validateTemporalLeaf(\n depth: number,\n nodes: number,\n limits: { readonly maxDepth: number; readonly maxNodes: number },\n): void {\n if (depth > limits.maxDepth || nodes + 1 > limits.maxNodes) throw new RangeError(\"limit\");\n}\n\nfunction equalOptions(left: KaladaValue, right: KaladaValue): boolean {\n if (!isOption(left) || !isOption(right) || left.variant !== right.variant) return false;\n if (left.variant === \"none\" || right.variant === \"none\") return true;\n return equalKaladaValues(left.value, right.value);\n}\n\nfunction equalResults(left: KaladaValue, right: KaladaValue): boolean {\n if (!isResult(left) || !isResult(right) || left.variant !== right.variant) return false;\n return equalKaladaValues(left.value, right.value);\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { JsonValue } from './json.cjs';
|
|
2
|
+
import { InstantValue, DurationValue } from './temporal.cjs';
|
|
3
|
+
|
|
4
|
+
type KaladaValue = JsonValue | OptionValue | ResultValue | InstantValue | DurationValue;
|
|
5
|
+
type OptionValue = SomeValue | NoneValue;
|
|
6
|
+
type ResultValue = OkValue | ErrValue;
|
|
7
|
+
declare const optionBrand: unique symbol;
|
|
8
|
+
declare const resultBrand: unique symbol;
|
|
9
|
+
interface SomeValue {
|
|
10
|
+
readonly [optionBrand]: true;
|
|
11
|
+
readonly type: "Option";
|
|
12
|
+
readonly variant: "some";
|
|
13
|
+
readonly value: KaladaValue;
|
|
14
|
+
}
|
|
15
|
+
interface NoneValue {
|
|
16
|
+
readonly [optionBrand]: true;
|
|
17
|
+
readonly type: "Option";
|
|
18
|
+
readonly variant: "none";
|
|
19
|
+
}
|
|
20
|
+
interface OkValue {
|
|
21
|
+
readonly [resultBrand]: true;
|
|
22
|
+
readonly type: "Result";
|
|
23
|
+
readonly variant: "ok";
|
|
24
|
+
readonly value: KaladaValue;
|
|
25
|
+
}
|
|
26
|
+
interface ErrValue {
|
|
27
|
+
readonly [resultBrand]: true;
|
|
28
|
+
readonly type: "Result";
|
|
29
|
+
readonly variant: "err";
|
|
30
|
+
readonly value: KaladaValue;
|
|
31
|
+
}
|
|
32
|
+
declare const Option: Readonly<{
|
|
33
|
+
some(value: KaladaValue): SomeValue;
|
|
34
|
+
none(): NoneValue;
|
|
35
|
+
}>;
|
|
36
|
+
declare const Result: Readonly<{
|
|
37
|
+
ok(value: KaladaValue): OkValue;
|
|
38
|
+
err(value: KaladaValue): ErrValue;
|
|
39
|
+
}>;
|
|
40
|
+
declare function isOption(value: unknown): value is OptionValue;
|
|
41
|
+
declare function isResult(value: unknown): value is ResultValue;
|
|
42
|
+
declare function equalKaladaValues(left: KaladaValue, right: KaladaValue): boolean;
|
|
43
|
+
declare function validateKaladaValueLimits(value: KaladaValue, limits: {
|
|
44
|
+
readonly maxDepth: number;
|
|
45
|
+
readonly maxNodes: number;
|
|
46
|
+
readonly maxStringLength: number;
|
|
47
|
+
}): void;
|
|
48
|
+
|
|
49
|
+
export { type ErrValue, type KaladaValue, type NoneValue, type OkValue, Option, type OptionValue, Result, type ResultValue, type SomeValue, equalKaladaValues, isOption, isResult, validateKaladaValueLimits };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { JsonValue } from './json.js';
|
|
2
|
+
import { InstantValue, DurationValue } from './temporal.js';
|
|
3
|
+
|
|
4
|
+
type KaladaValue = JsonValue | OptionValue | ResultValue | InstantValue | DurationValue;
|
|
5
|
+
type OptionValue = SomeValue | NoneValue;
|
|
6
|
+
type ResultValue = OkValue | ErrValue;
|
|
7
|
+
declare const optionBrand: unique symbol;
|
|
8
|
+
declare const resultBrand: unique symbol;
|
|
9
|
+
interface SomeValue {
|
|
10
|
+
readonly [optionBrand]: true;
|
|
11
|
+
readonly type: "Option";
|
|
12
|
+
readonly variant: "some";
|
|
13
|
+
readonly value: KaladaValue;
|
|
14
|
+
}
|
|
15
|
+
interface NoneValue {
|
|
16
|
+
readonly [optionBrand]: true;
|
|
17
|
+
readonly type: "Option";
|
|
18
|
+
readonly variant: "none";
|
|
19
|
+
}
|
|
20
|
+
interface OkValue {
|
|
21
|
+
readonly [resultBrand]: true;
|
|
22
|
+
readonly type: "Result";
|
|
23
|
+
readonly variant: "ok";
|
|
24
|
+
readonly value: KaladaValue;
|
|
25
|
+
}
|
|
26
|
+
interface ErrValue {
|
|
27
|
+
readonly [resultBrand]: true;
|
|
28
|
+
readonly type: "Result";
|
|
29
|
+
readonly variant: "err";
|
|
30
|
+
readonly value: KaladaValue;
|
|
31
|
+
}
|
|
32
|
+
declare const Option: Readonly<{
|
|
33
|
+
some(value: KaladaValue): SomeValue;
|
|
34
|
+
none(): NoneValue;
|
|
35
|
+
}>;
|
|
36
|
+
declare const Result: Readonly<{
|
|
37
|
+
ok(value: KaladaValue): OkValue;
|
|
38
|
+
err(value: KaladaValue): ErrValue;
|
|
39
|
+
}>;
|
|
40
|
+
declare function isOption(value: unknown): value is OptionValue;
|
|
41
|
+
declare function isResult(value: unknown): value is ResultValue;
|
|
42
|
+
declare function equalKaladaValues(left: KaladaValue, right: KaladaValue): boolean;
|
|
43
|
+
declare function validateKaladaValueLimits(value: KaladaValue, limits: {
|
|
44
|
+
readonly maxDepth: number;
|
|
45
|
+
readonly maxNodes: number;
|
|
46
|
+
readonly maxStringLength: number;
|
|
47
|
+
}): void;
|
|
48
|
+
|
|
49
|
+
export { type ErrValue, type KaladaValue, type NoneValue, type OkValue, Option, type OptionValue, Result, type ResultValue, type SomeValue, equalKaladaValues, isOption, isResult, validateKaladaValueLimits };
|