@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,64 @@
|
|
|
1
|
+
const literal = (value) => ({
|
|
2
|
+
kind: "literal",
|
|
3
|
+
value
|
|
4
|
+
});
|
|
5
|
+
const ref = (value) => ({
|
|
6
|
+
kind: "ref",
|
|
7
|
+
ref: value
|
|
8
|
+
});
|
|
9
|
+
const binding = (name, value, body) => ({ kind: "binding", name, value, body });
|
|
10
|
+
const some = (value) => ({
|
|
11
|
+
kind: "option",
|
|
12
|
+
variant: "some",
|
|
13
|
+
value
|
|
14
|
+
});
|
|
15
|
+
const none = () => ({
|
|
16
|
+
kind: "option",
|
|
17
|
+
variant: "none"
|
|
18
|
+
});
|
|
19
|
+
const ok = (value) => ({
|
|
20
|
+
kind: "result",
|
|
21
|
+
variant: "ok",
|
|
22
|
+
value
|
|
23
|
+
});
|
|
24
|
+
const err = (value) => ({
|
|
25
|
+
kind: "result",
|
|
26
|
+
variant: "err",
|
|
27
|
+
value
|
|
28
|
+
});
|
|
29
|
+
const arm = (variant, body, name) => ({ variant, ...name === void 0 ? {} : { binding: name }, body });
|
|
30
|
+
const match = (type, value, arms) => ({ kind: "match", type, value, arms });
|
|
31
|
+
const instant = (milliseconds) => ({
|
|
32
|
+
kind: "instant",
|
|
33
|
+
milliseconds
|
|
34
|
+
});
|
|
35
|
+
const duration = (milliseconds) => ({
|
|
36
|
+
kind: "duration",
|
|
37
|
+
milliseconds
|
|
38
|
+
});
|
|
39
|
+
const currentInstant = () => ({
|
|
40
|
+
kind: "current-instant"
|
|
41
|
+
});
|
|
42
|
+
const temporalArithmetic = (operator, left, right) => ({ kind: "temporal-arithmetic", operator, left, right });
|
|
43
|
+
const temporalComparison = (operator, left, right) => ({ kind: "temporal-comparison", operator, left, right });
|
|
44
|
+
const KaladaV1 = Object.freeze({
|
|
45
|
+
literal,
|
|
46
|
+
ref,
|
|
47
|
+
binding,
|
|
48
|
+
Option: Object.freeze({ some, none }),
|
|
49
|
+
Result: Object.freeze({ ok, err }),
|
|
50
|
+
arm,
|
|
51
|
+
match,
|
|
52
|
+
instant,
|
|
53
|
+
duration,
|
|
54
|
+
currentInstant,
|
|
55
|
+
temporalArithmetic,
|
|
56
|
+
temporalComparison,
|
|
57
|
+
program(expression) {
|
|
58
|
+
return { format: "kalada-program", version: 1, profile: "kalada-v1", expression };
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export { KaladaV1 };
|
|
63
|
+
//# sourceMappingURL=factories.js.map
|
|
64
|
+
//# sourceMappingURL=factories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kalada-v1/factories.ts"],"names":[],"mappings":"AAGA,MAAM,OAAA,GAAU,CAA+B,KAAA,MAA6C;AAAA,EAC1F,IAAA,EAAM,SAAA;AAAA,EACN;AACF,CAAA,CAAA;AACA,MAAM,G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ACA,MAAM,iBAAiB,OAA4D;AAAA,EACjF,IAAA,EAAM;AACR,CAAA,CAAA;AACA,MAAM,kBAAA,GAAqB,CACzB,QAAA,EACA,IAAA,EACA,KAAA,MAC2B,EAAE,IAAA,EAAM,qBAAA,EAAuB,QAAA,EAAU,IAAA,EAAM,KAAA,EAAM,CAAA;AAClF,MAAM,kBAAA,GAAqB,CACzB,QAAA,EACA,IAAA,EACA,KAAA,MAC2B,EAAE,IAAA,EAAM,qBAAA,EAAuB,QAAA,EAAU,IAAA,EAAM,KAAA,EAAM,CAAA;AAE3E,MAAM,QAAA,GAAW,OAAO,MAAA,CAAO;AAAA,EACpC,OAAA;AAAA,EACA,GAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAQ,MAAA,CAAO,MAAA,CAAO,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,EACpC,QAAQ,MAAA,CAAO,MAAA,CAAO,EAAE,EAAA,EAAI,KAAK,CAAA;AAAA,EACjC,GAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,cAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA,QAAsC,UAAA,EAAuD;AAC3F,IAAA,OAAO,EAAE,MAAA,EAAQ,gBAAA,EAAkB,SAAS,CAAA,EAAG,OAAA,EAAS,aAAa,UAAA,EAAW;AAAA,EAClF;AACF,CAAC","file":"factories.js","sourcesContent":["import type { JsonValue } from \"./json.js\";\nimport type { KaladaV1Expression, KaladaV1Program, MatchArm } from \"./types.js\";\n\nconst literal = <R extends JsonValue = string>(value: JsonValue): KaladaV1Expression<R> => ({\n kind: \"literal\",\n value,\n});\nconst ref = <R extends JsonValue = string>(value: R): KaladaV1Expression<R> => ({\n kind: \"ref\",\n ref: value,\n});\nconst binding = <R extends JsonValue>(\n name: string,\n value: KaladaV1Expression<R>,\n body: KaladaV1Expression<R>,\n): KaladaV1Expression<R> => ({ kind: \"binding\", name, value, body });\nconst some = <R extends JsonValue>(value: KaladaV1Expression<R>): KaladaV1Expression<R> => ({\n kind: \"option\",\n variant: \"some\",\n value,\n});\nconst none = <R extends JsonValue = string>(): KaladaV1Expression<R> => ({\n kind: \"option\",\n variant: \"none\",\n});\nconst ok = <R extends JsonValue>(value: KaladaV1Expression<R>): KaladaV1Expression<R> => ({\n kind: \"result\",\n variant: \"ok\",\n value,\n});\nconst err = <R extends JsonValue>(value: KaladaV1Expression<R>): KaladaV1Expression<R> => ({\n kind: \"result\",\n variant: \"err\",\n value,\n});\nconst arm = <R extends JsonValue>(\n variant: MatchArm<R>[\"variant\"],\n body: KaladaV1Expression<R>,\n name?: string,\n): MatchArm<R> => ({ variant, ...(name === undefined ? {} : { binding: name }), body });\nconst match = <R extends JsonValue>(\n type: \"Option\" | \"Result\",\n value: KaladaV1Expression<R>,\n arms: readonly MatchArm<R>[],\n): KaladaV1Expression<R> => ({ kind: \"match\", type, value, arms });\nconst instant = <R extends JsonValue = string>(milliseconds: number): KaladaV1Expression<R> => ({\n kind: \"instant\",\n milliseconds,\n});\nconst duration = <R extends JsonValue = string>(milliseconds: number): KaladaV1Expression<R> => ({\n kind: \"duration\",\n milliseconds,\n});\nconst currentInstant = <R extends JsonValue = string>(): KaladaV1Expression<R> => ({\n kind: \"current-instant\",\n});\nconst temporalArithmetic = <R extends JsonValue>(\n operator: \"add\" | \"subtract\",\n left: KaladaV1Expression<R>,\n right: KaladaV1Expression<R>,\n): KaladaV1Expression<R> => ({ kind: \"temporal-arithmetic\", operator, left, right });\nconst temporalComparison = <R extends JsonValue>(\n operator: Extract<KaladaV1Expression<R>, { kind: \"temporal-comparison\" }>[\"operator\"],\n left: KaladaV1Expression<R>,\n right: KaladaV1Expression<R>,\n): KaladaV1Expression<R> => ({ kind: \"temporal-comparison\", operator, left, right });\n\nexport const KaladaV1 = Object.freeze({\n literal,\n ref,\n binding,\n Option: Object.freeze({ some, none }),\n Result: Object.freeze({ ok, err }),\n arm,\n match,\n instant,\n duration,\n currentInstant,\n temporalArithmetic,\n temporalComparison,\n program<R extends JsonValue = string>(expression: KaladaV1Expression<R>): KaladaV1Program<R> {\n return { format: \"kalada-program\", version: 1, profile: \"kalada-v1\", expression };\n },\n});\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var canonicalize_js = require('./canonicalize.js');
|
|
4
|
+
var codec_js = require('./codec.js');
|
|
5
|
+
var compile_js = require('./compile.js');
|
|
6
|
+
var dependencies_js = require('./dependencies.js');
|
|
7
|
+
var factories_js = require('./factories.js');
|
|
8
|
+
var limits_js = require('./limits.js');
|
|
9
|
+
var schemas_js = require('./schemas.js');
|
|
10
|
+
var temporal_js = require('./temporal.js');
|
|
11
|
+
var values_js = require('./values.js');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Object.defineProperty(exports, "canonicalizeKaladaV1Program", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return canonicalize_js.canonicalizeKaladaV1Program; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "decodeKaladaValue", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return codec_js.decodeKaladaValue; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "encodeKaladaValue", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return codec_js.encodeKaladaValue; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "compileKaladaV1Program", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return compile_js.compileKaladaV1Program; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "collectKaladaV1Dependencies", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return dependencies_js.collectKaladaV1Dependencies; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "KaladaV1", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return factories_js.KaladaV1; }
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "DEFAULT_KALADA_V1_LIMITS", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return limits_js.DEFAULT_KALADA_V1_LIMITS; }
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "KALADA_V1_PROGRAM_SCHEMA", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () { return schemas_js.KALADA_V1_PROGRAM_SCHEMA; }
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "KALADA_VALUE_V1_SCHEMA", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () { return schemas_js.KALADA_VALUE_V1_SCHEMA; }
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "Duration", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () { return temporal_js.Duration; }
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "Instant", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () { return temporal_js.Instant; }
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(exports, "isDuration", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () { return temporal_js.isDuration; }
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "isInstant", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () { return temporal_js.isInstant; }
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "Option", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () { return values_js.Option; }
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(exports, "Result", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return values_js.Result; }
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "equalKaladaValues", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () { return values_js.equalKaladaValues; }
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "isOption", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () { return values_js.isOption; }
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "isResult", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () { return values_js.isResult; }
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=index.cjs.map
|
|
88
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs","sourcesContent":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { canonicalizeKaladaV1Program } from './canonicalize.cjs';
|
|
2
|
+
export { EncodedKaladaValueV1, decodeKaladaValue, encodeKaladaValue } from './codec.cjs';
|
|
3
|
+
export { compileKaladaV1Program } from './compile.cjs';
|
|
4
|
+
export { collectKaladaV1Dependencies } from './dependencies.cjs';
|
|
5
|
+
export { KaladaV1 } from './factories.cjs';
|
|
6
|
+
export { JsonPrimitive, JsonValue } from './json.cjs';
|
|
7
|
+
export { DEFAULT_KALADA_V1_LIMITS } from './limits.cjs';
|
|
8
|
+
export { KALADA_V1_PROGRAM_SCHEMA, KALADA_VALUE_V1_SCHEMA, KaladaV1JsonSchema } from './schemas.cjs';
|
|
9
|
+
export { Duration, DurationValue, Instant, InstantValue, isDuration, isInstant } from './temporal.cjs';
|
|
10
|
+
export { BindingExpression, CompiledKaladaV1Program, CurrentInstantExpression, DurationExpression, InstantExpression, KaladaV1Clock, KaladaV1Diagnostic, KaladaV1DiagnosticCode, KaladaV1EvaluationInputs, KaladaV1Expression, KaladaV1Limits, KaladaV1Options, KaladaV1Outcome, KaladaV1Program, KaladaV1ReferenceCodec, KaladaV1Resolution, KaladaV1Resolver, MatchArm, MatchExpression, OptionExpression, ResultExpression, TemporalArithmeticExpression, TemporalComparisonExpression } from './types.cjs';
|
|
11
|
+
export { ErrValue, KaladaValue, NoneValue, OkValue, Option, OptionValue, Result, ResultValue, SomeValue, equalKaladaValues, isOption, isResult } from './values.cjs';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { canonicalizeKaladaV1Program } from './canonicalize.js';
|
|
2
|
+
export { EncodedKaladaValueV1, decodeKaladaValue, encodeKaladaValue } from './codec.js';
|
|
3
|
+
export { compileKaladaV1Program } from './compile.js';
|
|
4
|
+
export { collectKaladaV1Dependencies } from './dependencies.js';
|
|
5
|
+
export { KaladaV1 } from './factories.js';
|
|
6
|
+
export { JsonPrimitive, JsonValue } from './json.js';
|
|
7
|
+
export { DEFAULT_KALADA_V1_LIMITS } from './limits.js';
|
|
8
|
+
export { KALADA_V1_PROGRAM_SCHEMA, KALADA_VALUE_V1_SCHEMA, KaladaV1JsonSchema } from './schemas.js';
|
|
9
|
+
export { Duration, DurationValue, Instant, InstantValue, isDuration, isInstant } from './temporal.js';
|
|
10
|
+
export { BindingExpression, CompiledKaladaV1Program, CurrentInstantExpression, DurationExpression, InstantExpression, KaladaV1Clock, KaladaV1Diagnostic, KaladaV1DiagnosticCode, KaladaV1EvaluationInputs, KaladaV1Expression, KaladaV1Limits, KaladaV1Options, KaladaV1Outcome, KaladaV1Program, KaladaV1ReferenceCodec, KaladaV1Resolution, KaladaV1Resolver, MatchArm, MatchExpression, OptionExpression, ResultExpression, TemporalArithmeticExpression, TemporalComparisonExpression } from './types.js';
|
|
11
|
+
export { ErrValue, KaladaValue, NoneValue, OkValue, Option, OptionValue, Result, ResultValue, SomeValue, equalKaladaValues, isOption, isResult } from './values.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { canonicalizeKaladaV1Program } from './canonicalize.js';
|
|
2
|
+
export { decodeKaladaValue, encodeKaladaValue } from './codec.js';
|
|
3
|
+
export { compileKaladaV1Program } from './compile.js';
|
|
4
|
+
export { collectKaladaV1Dependencies } from './dependencies.js';
|
|
5
|
+
export { KaladaV1 } from './factories.js';
|
|
6
|
+
export { DEFAULT_KALADA_V1_LIMITS } from './limits.js';
|
|
7
|
+
export { KALADA_V1_PROGRAM_SCHEMA, KALADA_VALUE_V1_SCHEMA } from './schemas.js';
|
|
8
|
+
export { Duration, Instant, isDuration, isInstant } from './temporal.js';
|
|
9
|
+
export { Option, Result, equalKaladaValues, isOption, isResult } from './values.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
4
|
+
function cloneJson(input, limits) {
|
|
5
|
+
return cloneJsonWithStats(input, limits).value;
|
|
6
|
+
}
|
|
7
|
+
function cloneJsonWithStats(input, limits) {
|
|
8
|
+
const state = {
|
|
9
|
+
...limits,
|
|
10
|
+
active: /* @__PURE__ */ new WeakSet(),
|
|
11
|
+
nodes: 0
|
|
12
|
+
};
|
|
13
|
+
const value = cloneValue(input, 0, state);
|
|
14
|
+
return { value, nodes: state.nodes };
|
|
15
|
+
}
|
|
16
|
+
function canonicalJsonIdentity(value) {
|
|
17
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
18
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJsonIdentity).join(",")}]`;
|
|
19
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonIdentity(value[key])}`).join(",")}}`;
|
|
20
|
+
}
|
|
21
|
+
function cloneValue(input, depth, state) {
|
|
22
|
+
state.nodes += 1;
|
|
23
|
+
if (depth > state.maxDepth || state.nodes > state.maxNodes) throw new RangeError("limit");
|
|
24
|
+
if (input === null || typeof input === "boolean") return input;
|
|
25
|
+
if (typeof input === "string") {
|
|
26
|
+
if ([...input].length > state.maxStringLength) throw new RangeError("limit");
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
if (typeof input === "number") {
|
|
30
|
+
if (!Number.isFinite(input)) throw new TypeError("json");
|
|
31
|
+
return Object.is(input, -0) ? 0 : input;
|
|
32
|
+
}
|
|
33
|
+
if (typeof input !== "object") throw new TypeError("json");
|
|
34
|
+
return cloneObject(input, depth, state);
|
|
35
|
+
}
|
|
36
|
+
function cloneObject(input, depth, state) {
|
|
37
|
+
if (state.active.has(input)) throw new TypeError("cycle");
|
|
38
|
+
state.active.add(input);
|
|
39
|
+
try {
|
|
40
|
+
return Array.isArray(input) ? cloneArray(input, depth, state) : cloneRecord(input, depth, state);
|
|
41
|
+
} finally {
|
|
42
|
+
state.active.delete(input);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function cloneArray(input, depth, state) {
|
|
46
|
+
const length = arrayLength(input);
|
|
47
|
+
const keys = safeKeys(input);
|
|
48
|
+
if (keys.length !== length + 1 || !keys.includes("length")) throw new TypeError("array");
|
|
49
|
+
const output = [];
|
|
50
|
+
for (let index = 0; index < length; index += 1) {
|
|
51
|
+
output.push(cloneValue(dataValue(input, String(index)), depth + 1, state));
|
|
52
|
+
}
|
|
53
|
+
return Object.freeze(output);
|
|
54
|
+
}
|
|
55
|
+
function arrayLength(input) {
|
|
56
|
+
let descriptor;
|
|
57
|
+
try {
|
|
58
|
+
descriptor = Object.getOwnPropertyDescriptor(input, "length");
|
|
59
|
+
} catch {
|
|
60
|
+
throw new TypeError("array");
|
|
61
|
+
}
|
|
62
|
+
if (!descriptor || !("value" in descriptor) || !Number.isSafeInteger(descriptor.value)) {
|
|
63
|
+
throw new TypeError("array");
|
|
64
|
+
}
|
|
65
|
+
if (descriptor.value < 0 || descriptor.value > 4294967295) throw new TypeError("array");
|
|
66
|
+
return descriptor.value;
|
|
67
|
+
}
|
|
68
|
+
function cloneRecord(input, depth, state) {
|
|
69
|
+
const prototype = safePrototype(input);
|
|
70
|
+
if (prototype !== Object.prototype && prototype !== null) throw new TypeError("object");
|
|
71
|
+
const output = /* @__PURE__ */ Object.create(null);
|
|
72
|
+
for (const key of safeKeys(input)) {
|
|
73
|
+
if (typeof key !== "string" || FORBIDDEN_KEYS.has(key)) throw new TypeError("key");
|
|
74
|
+
if ([...key].length > state.maxStringLength) throw new RangeError("limit");
|
|
75
|
+
output[key] = cloneValue(dataValue(input, key), depth + 1, state);
|
|
76
|
+
}
|
|
77
|
+
return Object.freeze(output);
|
|
78
|
+
}
|
|
79
|
+
function safeKeys(input) {
|
|
80
|
+
try {
|
|
81
|
+
return Reflect.ownKeys(input);
|
|
82
|
+
} catch {
|
|
83
|
+
throw new TypeError("object");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function safePrototype(input) {
|
|
87
|
+
try {
|
|
88
|
+
return Object.getPrototypeOf(input);
|
|
89
|
+
} catch {
|
|
90
|
+
throw new TypeError("object");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function dataValue(input, key) {
|
|
94
|
+
let descriptor;
|
|
95
|
+
try {
|
|
96
|
+
descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
97
|
+
} catch {
|
|
98
|
+
throw new TypeError("descriptor");
|
|
99
|
+
}
|
|
100
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
|
|
101
|
+
throw new TypeError("descriptor");
|
|
102
|
+
}
|
|
103
|
+
return descriptor.value;
|
|
104
|
+
}
|
|
105
|
+
function deepEqualJson(left, right) {
|
|
106
|
+
if (Object.is(left, right)) return true;
|
|
107
|
+
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
111
|
+
return Array.isArray(left) && Array.isArray(right) && equalArrays(left, right);
|
|
112
|
+
}
|
|
113
|
+
const leftKeys = Object.keys(left);
|
|
114
|
+
const rightKeys = Object.keys(right);
|
|
115
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(
|
|
116
|
+
(key) => key in right && deepEqualJson(left[key], right[key])
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
function equalArrays(left, right) {
|
|
120
|
+
return left.length === right.length && left.every((value, index) => deepEqualJson(value, right[index]));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
exports.canonicalJsonIdentity = canonicalJsonIdentity;
|
|
124
|
+
exports.cloneJson = cloneJson;
|
|
125
|
+
exports.cloneJsonWithStats = cloneJsonWithStats;
|
|
126
|
+
exports.dataValue = dataValue;
|
|
127
|
+
exports.deepEqualJson = deepEqualJson;
|
|
128
|
+
//# sourceMappingURL=json.cjs.map
|
|
129
|
+
//# sourceMappingURL=json.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kalada-v1/json.ts"],"names":[],"mappings":";;AAGA,MAAM,iCAAiB,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,aAAA,EAAe,WAAW,CAAC,CAAA;AAqBjE,SAAS,SAAA,CAAU,OAAgB,MAAA,EAAoC;AAC5E,EAAA,OAAO,kBAAA,CAAmB,KAAA,EAAO,MAAM,CAAA,CAAE,KAAA;AAC3C;AAEO,SAAS,kBAAA,CAAmB,OAAgB,MAAA,EAA0C;AAC3F,EAAA,MAAM,KAAA,GAAoB;AAAA,IACxB,GAAG,MAAA;AAAA,IACH,MAAA,sBAAY,OAAA,EAAQ;AAAA,IACpB,KAAA,EAAO;AAAA,GACT;AACA,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,KAAA,EAAO,CAAA,EAAG,KAAK,CAAA;AACxC,EAAA,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,CAAM,KAAA,EAAM;AACrC;AAEO,SAAS,sBAAsB,KAAA,EAA0B;AAC9D,EAAA,IAAI,KAAA,KAAU,QAAQ,OAAO,KAAA,KAAU,UAAU,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAC5E,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,KA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AG;AAC/C,IAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,IAAK,KAAA,CAAM,QAAQ,KAAK,CAAA,IAAK,WAAA,CAAY,IAAA,EAAM,KAAK,CAAA;AAAA,EAC/E;AACA,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AACjC,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA;AACnC,EAAA,OACE,QAAA,CAAS,MAAA,KAAW,SAAA,CAAU,MAAA,IAC9B,QAAA,CAAS,KAAA;AAAA,IACP,CAAC,GAAA,KAAQ,GAAA,IAAO,KAAA,IAAS,aAAA,CAAc,KAAK,GAAG,CAAA,EAAgB,KAAA,CAAM,GAAG,CAAc;AAAA,GACxF;AAEJ;AAEA,SAAS,WAAA,CAAY,MAAmB,KAAA,EAA6B;AACnE,EAAA,OACE,IAAA,CAAK,MAAA,KAAW,KAAA,CAAM,MAAA,IACtB,KAAK,KAAA,CAAM,CAAC,KAAA,EAAO,KAAA,KAAU,aAAA,CAAc,KAAA,EAAO,KAAA,CAAM,KAAK,CAAc,CAAC,CAAA;AAEhF","file":"json.cjs","sourcesContent":["export type JsonPrimitive = null | boolean | number | string;\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };\n\nconst FORBIDDEN_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\ninterface CloneState {\n readonly active: WeakSet<object>;\n readonly maxDepth: number;\n readonly maxNodes: number;\n readonly maxStringLength: number;\n nodes: number;\n}\n\nexport interface JsonCloneLimits {\n readonly maxDepth: number;\n readonly maxNodes: number;\n readonly maxStringLength: number;\n}\n\nexport interface JsonCloneResult {\n readonly value: JsonValue;\n readonly nodes: number;\n}\n\nexport function cloneJson(input: unknown, limits: JsonCloneLimits): JsonValue {\n return cloneJsonWithStats(input, limits).value;\n}\n\nexport function cloneJsonWithStats(input: unknown, limits: JsonCloneLimits): JsonCloneResult {\n const state: CloneState = {\n ...limits,\n active: new WeakSet(),\n nodes: 0,\n };\n const value = cloneValue(input, 0, state);\n return { value, nodes: state.nodes };\n}\n\nexport function canonicalJsonIdentity(value: JsonValue): string {\n if (value === null || typeof value !== \"object\") return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(canonicalJsonIdentity).join(\",\")}]`;\n return `{${Object.keys(value)\n .sort()\n .map((key) => `${JSON.stringify(key)}:${canonicalJsonIdentity(value[key] as JsonValue)}`)\n .join(\",\")}}`;\n}\n\nfunction cloneValue(input: unknown, depth: number, state: CloneState): JsonValue {\n state.nodes += 1;\n if (depth > state.maxDepth || state.nodes > state.maxNodes) throw new RangeError(\"limit\");\n if (input === null || typeof input === \"boolean\") return input;\n if (typeof input === \"string\") {\n if ([...input].length > state.maxStringLength) throw new RangeError(\"limit\");\n return input;\n }\n if (typeof input === \"number\") {\n if (!Number.isFinite(input)) throw new TypeError(\"json\");\n return Object.is(input, -0) ? 0 : input;\n }\n if (typeof input !== \"object\") throw new TypeError(\"json\");\n return cloneObject(input, depth, state);\n}\n\nfunction cloneObject(input: object, depth: number, state: CloneState): JsonValue {\n if (state.active.has(input)) throw new TypeError(\"cycle\");\n state.active.add(input);\n try {\n return Array.isArray(input)\n ? cloneArray(input, depth, state)\n : cloneRecord(input, depth, state);\n } finally {\n state.active.delete(input);\n }\n}\n\nfunction cloneArray(input: unknown[], depth: number, state: CloneState): JsonValue[] {\n const length = arrayLength(input);\n const keys = safeKeys(input);\n if (keys.length !== length + 1 || !keys.includes(\"length\")) throw new TypeError(\"array\");\n const output: JsonValue[] = [];\n for (let index = 0; index < length; index += 1) {\n output.push(cloneValue(dataValue(input, String(index)), depth + 1, state));\n }\n return Object.freeze(output) as JsonValue[];\n}\n\nfunction arrayLength(input: unknown[]): number {\n let descriptor: PropertyDescriptor | undefined;\n try {\n descriptor = Object.getOwnPropertyDescriptor(input, \"length\");\n } catch {\n throw new TypeError(\"array\");\n }\n if (!descriptor || !(\"value\" in descriptor) || !Number.isSafeInteger(descriptor.value)) {\n throw new TypeError(\"array\");\n }\n if (descriptor.value < 0 || descriptor.value > 0xffff_ffff) throw new TypeError(\"array\");\n return descriptor.value;\n}\n\nfunction cloneRecord(\n input: object,\n depth: number,\n state: CloneState,\n): { [key: string]: JsonValue } {\n const prototype = safePrototype(input);\n if (prototype !== Object.prototype && prototype !== null) throw new TypeError(\"object\");\n const output = Object.create(null) as Record<string, JsonValue>;\n for (const key of safeKeys(input)) {\n if (typeof key !== \"string\" || FORBIDDEN_KEYS.has(key)) throw new TypeError(\"key\");\n if ([...key].length > state.maxStringLength) throw new RangeError(\"limit\");\n output[key] = cloneValue(dataValue(input, key), depth + 1, state);\n }\n return Object.freeze(output);\n}\n\nfunction safeKeys(input: object): PropertyKey[] {\n try {\n return Reflect.ownKeys(input);\n } catch {\n throw new TypeError(\"object\");\n }\n}\n\nfunction safePrototype(input: object): object | null {\n try {\n return Object.getPrototypeOf(input);\n } catch {\n throw new TypeError(\"object\");\n }\n}\n\nexport function dataValue(input: object, key: string): unknown {\n let descriptor: PropertyDescriptor | undefined;\n try {\n descriptor = Object.getOwnPropertyDescriptor(input, key);\n } catch {\n throw new TypeError(\"descriptor\");\n }\n if (!descriptor || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw new TypeError(\"descriptor\");\n }\n return descriptor.value;\n}\n\nexport function deepEqualJson(left: JsonValue, right: JsonValue): boolean {\n if (Object.is(left, right)) return true;\n if (typeof left !== \"object\" || left === null || typeof right !== \"object\" || right === null) {\n return false;\n }\n if (Array.isArray(left) || Array.isArray(right)) {\n return Array.isArray(left) && Array.isArray(right) && equalArrays(left, right);\n }\n const leftKeys = Object.keys(left);\n const rightKeys = Object.keys(right);\n return (\n leftKeys.length === rightKeys.length &&\n leftKeys.every(\n (key) => key in right && deepEqualJson(left[key] as JsonValue, right[key] as JsonValue),\n )\n );\n}\n\nfunction equalArrays(left: JsonValue[], right: JsonValue[]): boolean {\n return (\n left.length === right.length &&\n left.every((value, index) => deepEqualJson(value, right[index] as JsonValue))\n );\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type JsonPrimitive = null | boolean | number | string;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
interface JsonCloneLimits {
|
|
6
|
+
readonly maxDepth: number;
|
|
7
|
+
readonly maxNodes: number;
|
|
8
|
+
readonly maxStringLength: number;
|
|
9
|
+
}
|
|
10
|
+
interface JsonCloneResult {
|
|
11
|
+
readonly value: JsonValue;
|
|
12
|
+
readonly nodes: number;
|
|
13
|
+
}
|
|
14
|
+
declare function cloneJson(input: unknown, limits: JsonCloneLimits): JsonValue;
|
|
15
|
+
declare function cloneJsonWithStats(input: unknown, limits: JsonCloneLimits): JsonCloneResult;
|
|
16
|
+
declare function canonicalJsonIdentity(value: JsonValue): string;
|
|
17
|
+
declare function dataValue(input: object, key: string): unknown;
|
|
18
|
+
declare function deepEqualJson(left: JsonValue, right: JsonValue): boolean;
|
|
19
|
+
|
|
20
|
+
export { type JsonCloneLimits, type JsonCloneResult, type JsonPrimitive, type JsonValue, canonicalJsonIdentity, cloneJson, cloneJsonWithStats, dataValue, deepEqualJson };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type JsonPrimitive = null | boolean | number | string;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
interface JsonCloneLimits {
|
|
6
|
+
readonly maxDepth: number;
|
|
7
|
+
readonly maxNodes: number;
|
|
8
|
+
readonly maxStringLength: number;
|
|
9
|
+
}
|
|
10
|
+
interface JsonCloneResult {
|
|
11
|
+
readonly value: JsonValue;
|
|
12
|
+
readonly nodes: number;
|
|
13
|
+
}
|
|
14
|
+
declare function cloneJson(input: unknown, limits: JsonCloneLimits): JsonValue;
|
|
15
|
+
declare function cloneJsonWithStats(input: unknown, limits: JsonCloneLimits): JsonCloneResult;
|
|
16
|
+
declare function canonicalJsonIdentity(value: JsonValue): string;
|
|
17
|
+
declare function dataValue(input: object, key: string): unknown;
|
|
18
|
+
declare function deepEqualJson(left: JsonValue, right: JsonValue): boolean;
|
|
19
|
+
|
|
20
|
+
export { type JsonCloneLimits, type JsonCloneResult, type JsonPrimitive, type JsonValue, canonicalJsonIdentity, cloneJson, cloneJsonWithStats, dataValue, deepEqualJson };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
2
|
+
function cloneJson(input, limits) {
|
|
3
|
+
return cloneJsonWithStats(input, limits).value;
|
|
4
|
+
}
|
|
5
|
+
function cloneJsonWithStats(input, limits) {
|
|
6
|
+
const state = {
|
|
7
|
+
...limits,
|
|
8
|
+
active: /* @__PURE__ */ new WeakSet(),
|
|
9
|
+
nodes: 0
|
|
10
|
+
};
|
|
11
|
+
const value = cloneValue(input, 0, state);
|
|
12
|
+
return { value, nodes: state.nodes };
|
|
13
|
+
}
|
|
14
|
+
function canonicalJsonIdentity(value) {
|
|
15
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
16
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJsonIdentity).join(",")}]`;
|
|
17
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonIdentity(value[key])}`).join(",")}}`;
|
|
18
|
+
}
|
|
19
|
+
function cloneValue(input, depth, state) {
|
|
20
|
+
state.nodes += 1;
|
|
21
|
+
if (depth > state.maxDepth || state.nodes > state.maxNodes) throw new RangeError("limit");
|
|
22
|
+
if (input === null || typeof input === "boolean") return input;
|
|
23
|
+
if (typeof input === "string") {
|
|
24
|
+
if ([...input].length > state.maxStringLength) throw new RangeError("limit");
|
|
25
|
+
return input;
|
|
26
|
+
}
|
|
27
|
+
if (typeof input === "number") {
|
|
28
|
+
if (!Number.isFinite(input)) throw new TypeError("json");
|
|
29
|
+
return Object.is(input, -0) ? 0 : input;
|
|
30
|
+
}
|
|
31
|
+
if (typeof input !== "object") throw new TypeError("json");
|
|
32
|
+
return cloneObject(input, depth, state);
|
|
33
|
+
}
|
|
34
|
+
function cloneObject(input, depth, state) {
|
|
35
|
+
if (state.active.has(input)) throw new TypeError("cycle");
|
|
36
|
+
state.active.add(input);
|
|
37
|
+
try {
|
|
38
|
+
return Array.isArray(input) ? cloneArray(input, depth, state) : cloneRecord(input, depth, state);
|
|
39
|
+
} finally {
|
|
40
|
+
state.active.delete(input);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function cloneArray(input, depth, state) {
|
|
44
|
+
const length = arrayLength(input);
|
|
45
|
+
const keys = safeKeys(input);
|
|
46
|
+
if (keys.length !== length + 1 || !keys.includes("length")) throw new TypeError("array");
|
|
47
|
+
const output = [];
|
|
48
|
+
for (let index = 0; index < length; index += 1) {
|
|
49
|
+
output.push(cloneValue(dataValue(input, String(index)), depth + 1, state));
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze(output);
|
|
52
|
+
}
|
|
53
|
+
function arrayLength(input) {
|
|
54
|
+
let descriptor;
|
|
55
|
+
try {
|
|
56
|
+
descriptor = Object.getOwnPropertyDescriptor(input, "length");
|
|
57
|
+
} catch {
|
|
58
|
+
throw new TypeError("array");
|
|
59
|
+
}
|
|
60
|
+
if (!descriptor || !("value" in descriptor) || !Number.isSafeInteger(descriptor.value)) {
|
|
61
|
+
throw new TypeError("array");
|
|
62
|
+
}
|
|
63
|
+
if (descriptor.value < 0 || descriptor.value > 4294967295) throw new TypeError("array");
|
|
64
|
+
return descriptor.value;
|
|
65
|
+
}
|
|
66
|
+
function cloneRecord(input, depth, state) {
|
|
67
|
+
const prototype = safePrototype(input);
|
|
68
|
+
if (prototype !== Object.prototype && prototype !== null) throw new TypeError("object");
|
|
69
|
+
const output = /* @__PURE__ */ Object.create(null);
|
|
70
|
+
for (const key of safeKeys(input)) {
|
|
71
|
+
if (typeof key !== "string" || FORBIDDEN_KEYS.has(key)) throw new TypeError("key");
|
|
72
|
+
if ([...key].length > state.maxStringLength) throw new RangeError("limit");
|
|
73
|
+
output[key] = cloneValue(dataValue(input, key), depth + 1, state);
|
|
74
|
+
}
|
|
75
|
+
return Object.freeze(output);
|
|
76
|
+
}
|
|
77
|
+
function safeKeys(input) {
|
|
78
|
+
try {
|
|
79
|
+
return Reflect.ownKeys(input);
|
|
80
|
+
} catch {
|
|
81
|
+
throw new TypeError("object");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function safePrototype(input) {
|
|
85
|
+
try {
|
|
86
|
+
return Object.getPrototypeOf(input);
|
|
87
|
+
} catch {
|
|
88
|
+
throw new TypeError("object");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function dataValue(input, key) {
|
|
92
|
+
let descriptor;
|
|
93
|
+
try {
|
|
94
|
+
descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
95
|
+
} catch {
|
|
96
|
+
throw new TypeError("descriptor");
|
|
97
|
+
}
|
|
98
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
|
|
99
|
+
throw new TypeError("descriptor");
|
|
100
|
+
}
|
|
101
|
+
return descriptor.value;
|
|
102
|
+
}
|
|
103
|
+
function deepEqualJson(left, right) {
|
|
104
|
+
if (Object.is(left, right)) return true;
|
|
105
|
+
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
109
|
+
return Array.isArray(left) && Array.isArray(right) && equalArrays(left, right);
|
|
110
|
+
}
|
|
111
|
+
const leftKeys = Object.keys(left);
|
|
112
|
+
const rightKeys = Object.keys(right);
|
|
113
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(
|
|
114
|
+
(key) => key in right && deepEqualJson(left[key], right[key])
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
function equalArrays(left, right) {
|
|
118
|
+
return left.length === right.length && left.every((value, index) => deepEqualJson(value, right[index]));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { canonicalJsonIdentity, cloneJson, cloneJsonWithStats, dataValue, deepEqualJson };
|
|
122
|
+
//# sourceMappingURL=json.js.map
|
|
123
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kalada-v1/json.ts"],"names":[],"mappings":"AAGA,MAAM,iCAAiB,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,aAAA,EAAe,WAAW,CAAC,CAAA;AAqBjE,SAAS,SAAA,CAAU,OAAgB,MAAA,EAAoC;AAC5E,EAAA,OAAO,kBAAA,CAAmB,KAAA,EAAO,MAAM,CAAA,CAAE,KAAA;AAC3C;AAEO,SAAS,kBAAA,CAAmB,OAAgB,MAAA,EAA0C;AAC3F,EAAA,MAAM,KAAA,GAAoB;AAAA,IACxB,GAAG,MAAA;AAAA,IACH,MAAA,sBAAY,OAAA,EAAQ;AAAA,IACpB,KAAA,EAAO;AAAA,GACT;AACA,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,KAAA,EAAO,CAAA,EAAG,KAAK,CAAA;AACxC,EAAA,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,CAAM,KAAA,EAAM;AACrC;AAEO,SAAS,sBAAsB,KAAA,EAA0B;AAC9D,EAAA,IAAI,KAAA,KAAU,QAAQ,OAAO,KAAA,KAAU,UAAU,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAC5E,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,KAAA,CAAM,GAAA,CAAI,qBAAqB,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AAC/E,EAAA,OAAO,CAAA,CAAA,EAAI,MAAA,CAAO,IAAA,CAAK,KAAK,CAA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A,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AACjC,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA;AACnC,EAAA,OACE,QAAA,CAAS,MAAA,KAAW,SAAA,CAAU,MAAA,IAC9B,QAAA,CAAS,KAAA;AAAA,IACP,CAAC,GAAA,KAAQ,GAAA,IAAO,KAAA,IAAS,aAAA,CAAc,KAAK,GAAG,CAAA,EAAgB,KAAA,CAAM,GAAG,CAAc;AAAA,GACxF;AAEJ;AAEA,SAAS,WAAA,CAAY,MAAmB,KAAA,EAA6B;AACnE,EAAA,OACE,IAAA,CAAK,MAAA,KAAW,KAAA,CAAM,MAAA,IACtB,KAAK,KAAA,CAAM,CAAC,KAAA,EAAO,KAAA,KAAU,aAAA,CAAc,KAAA,EAAO,KAAA,CAAM,KAAK,CAAc,CAAC,CAAA;AAEhF","file":"json.js","sourcesContent":["export type JsonPrimitive = null | boolean | number | string;\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };\n\nconst FORBIDDEN_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\ninterface CloneState {\n readonly active: WeakSet<object>;\n readonly maxDepth: number;\n readonly maxNodes: number;\n readonly maxStringLength: number;\n nodes: number;\n}\n\nexport interface JsonCloneLimits {\n readonly maxDepth: number;\n readonly maxNodes: number;\n readonly maxStringLength: number;\n}\n\nexport interface JsonCloneResult {\n readonly value: JsonValue;\n readonly nodes: number;\n}\n\nexport function cloneJson(input: unknown, limits: JsonCloneLimits): JsonValue {\n return cloneJsonWithStats(input, limits).value;\n}\n\nexport function cloneJsonWithStats(input: unknown, limits: JsonCloneLimits): JsonCloneResult {\n const state: CloneState = {\n ...limits,\n active: new WeakSet(),\n nodes: 0,\n };\n const value = cloneValue(input, 0, state);\n return { value, nodes: state.nodes };\n}\n\nexport function canonicalJsonIdentity(value: JsonValue): string {\n if (value === null || typeof value !== \"object\") return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(canonicalJsonIdentity).join(\",\")}]`;\n return `{${Object.keys(value)\n .sort()\n .map((key) => `${JSON.stringify(key)}:${canonicalJsonIdentity(value[key] as JsonValue)}`)\n .join(\",\")}}`;\n}\n\nfunction cloneValue(input: unknown, depth: number, state: CloneState): JsonValue {\n state.nodes += 1;\n if (depth > state.maxDepth || state.nodes > state.maxNodes) throw new RangeError(\"limit\");\n if (input === null || typeof input === \"boolean\") return input;\n if (typeof input === \"string\") {\n if ([...input].length > state.maxStringLength) throw new RangeError(\"limit\");\n return input;\n }\n if (typeof input === \"number\") {\n if (!Number.isFinite(input)) throw new TypeError(\"json\");\n return Object.is(input, -0) ? 0 : input;\n }\n if (typeof input !== \"object\") throw new TypeError(\"json\");\n return cloneObject(input, depth, state);\n}\n\nfunction cloneObject(input: object, depth: number, state: CloneState): JsonValue {\n if (state.active.has(input)) throw new TypeError(\"cycle\");\n state.active.add(input);\n try {\n return Array.isArray(input)\n ? cloneArray(input, depth, state)\n : cloneRecord(input, depth, state);\n } finally {\n state.active.delete(input);\n }\n}\n\nfunction cloneArray(input: unknown[], depth: number, state: CloneState): JsonValue[] {\n const length = arrayLength(input);\n const keys = safeKeys(input);\n if (keys.length !== length + 1 || !keys.includes(\"length\")) throw new TypeError(\"array\");\n const output: JsonValue[] = [];\n for (let index = 0; index < length; index += 1) {\n output.push(cloneValue(dataValue(input, String(index)), depth + 1, state));\n }\n return Object.freeze(output) as JsonValue[];\n}\n\nfunction arrayLength(input: unknown[]): number {\n let descriptor: PropertyDescriptor | undefined;\n try {\n descriptor = Object.getOwnPropertyDescriptor(input, \"length\");\n } catch {\n throw new TypeError(\"array\");\n }\n if (!descriptor || !(\"value\" in descriptor) || !Number.isSafeInteger(descriptor.value)) {\n throw new TypeError(\"array\");\n }\n if (descriptor.value < 0 || descriptor.value > 0xffff_ffff) throw new TypeError(\"array\");\n return descriptor.value;\n}\n\nfunction cloneRecord(\n input: object,\n depth: number,\n state: CloneState,\n): { [key: string]: JsonValue } {\n const prototype = safePrototype(input);\n if (prototype !== Object.prototype && prototype !== null) throw new TypeError(\"object\");\n const output = Object.create(null) as Record<string, JsonValue>;\n for (const key of safeKeys(input)) {\n if (typeof key !== \"string\" || FORBIDDEN_KEYS.has(key)) throw new TypeError(\"key\");\n if ([...key].length > state.maxStringLength) throw new RangeError(\"limit\");\n output[key] = cloneValue(dataValue(input, key), depth + 1, state);\n }\n return Object.freeze(output);\n}\n\nfunction safeKeys(input: object): PropertyKey[] {\n try {\n return Reflect.ownKeys(input);\n } catch {\n throw new TypeError(\"object\");\n }\n}\n\nfunction safePrototype(input: object): object | null {\n try {\n return Object.getPrototypeOf(input);\n } catch {\n throw new TypeError(\"object\");\n }\n}\n\nexport function dataValue(input: object, key: string): unknown {\n let descriptor: PropertyDescriptor | undefined;\n try {\n descriptor = Object.getOwnPropertyDescriptor(input, key);\n } catch {\n throw new TypeError(\"descriptor\");\n }\n if (!descriptor || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw new TypeError(\"descriptor\");\n }\n return descriptor.value;\n}\n\nexport function deepEqualJson(left: JsonValue, right: JsonValue): boolean {\n if (Object.is(left, right)) return true;\n if (typeof left !== \"object\" || left === null || typeof right !== \"object\" || right === null) {\n return false;\n }\n if (Array.isArray(left) || Array.isArray(right)) {\n return Array.isArray(left) && Array.isArray(right) && equalArrays(left, right);\n }\n const leftKeys = Object.keys(left);\n const rightKeys = Object.keys(right);\n return (\n leftKeys.length === rightKeys.length &&\n leftKeys.every(\n (key) => key in right && deepEqualJson(left[key] as JsonValue, right[key] as JsonValue),\n )\n );\n}\n\nfunction equalArrays(left: JsonValue[], right: JsonValue[]): boolean {\n return (\n left.length === right.length &&\n left.every((value, index) => deepEqualJson(value, right[index] as JsonValue))\n );\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_KALADA_V1_LIMITS = Object.freeze({
|
|
4
|
+
maxAstDepth: 64,
|
|
5
|
+
maxAstNodes: 1e4,
|
|
6
|
+
maxValueDepth: 64,
|
|
7
|
+
maxValueNodes: 1e4,
|
|
8
|
+
maxStringLength: 1e4,
|
|
9
|
+
maxReferenceLength: 1e3,
|
|
10
|
+
maxEvaluationSteps: 1e4
|
|
11
|
+
});
|
|
12
|
+
const MAXIMUM = Object.freeze({
|
|
13
|
+
maxAstDepth: 256,
|
|
14
|
+
maxAstNodes: 1e5,
|
|
15
|
+
maxValueDepth: 256,
|
|
16
|
+
maxValueNodes: 1e5,
|
|
17
|
+
maxStringLength: 1e6,
|
|
18
|
+
maxReferenceLength: 1e5,
|
|
19
|
+
maxEvaluationSteps: 1e5
|
|
20
|
+
});
|
|
21
|
+
function resolveLimits(input) {
|
|
22
|
+
const limits = { ...DEFAULT_KALADA_V1_LIMITS, ...input };
|
|
23
|
+
for (const key of Object.keys(limits)) {
|
|
24
|
+
const value = limits[key];
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > MAXIMUM[key])
|
|
26
|
+
throw new RangeError("limit");
|
|
27
|
+
}
|
|
28
|
+
return Object.freeze(limits);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.DEFAULT_KALADA_V1_LIMITS = DEFAULT_KALADA_V1_LIMITS;
|
|
32
|
+
exports.resolveLimits = resolveLimits;
|
|
33
|
+
//# sourceMappingURL=limits.cjs.map
|
|
34
|
+
//# sourceMappingURL=limits.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/kalada-v1/limits.ts"],"names":[],"mappings":";;AAEO,MAAM,wBAAA,GAA2C,OAAO,MAAA,CAAO;AAAA,EACpE,WAAA,EAAa,EAAA;AAAA,EACb,WAAA,EAAa,GAAA;AAAA,EACb,aAAA,EAAe,EAAA;AAAA,EACf,aAAA,EAAe,GAAA;AAAA,EACf,eAAA,EAAiB,GAAA;AAAA,EACjB,kBAAA,EAAoB,GAAA;AAAA,EACpB,kBAAA,EAAoB;AACtB,CAAC;AAED,MAAM,OAAA,GAA0B,OAAO,MAAA,CAAO;AAAA,EAC5C,WAAA,EAAa,GAAA;AAAA,EACb,WAAA,EAAa,GAAA;AAAA,EACb,aAAA,EAAe,GAAA;AAAA,EACf,aAAA,EAAe,GAAA;AAAA,EACf,eAAA,EAAiB,GAAA;AAAA,EACjB,kBAAA,EAAoB,GAAA;AAAA,EACpB,kBAAA,EAAoB;AACtB,CAAC,CAAA;AAEM,SAAS,cAAc,KAAA,EAAiD;AAC7E,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,wBAAA,EAA0B,GAAG,KAAA,EAAM;AACvD,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,EAA+B;AACjE,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,CAAC,OAAO,aAAA,CAAc,KAAK,KAAK,KAAA,GAAQ,CAAA,IAAK,KAAA,GAAQ,OAAA,CAAQ,GAAG,CAAA;AAClE,MAAA,MAAM,IAAI,WAAW,OAAO,CAAA;AAAA,EAChC;AACA,EAAA,OAAO,MAAA,CAAO,OAAO,MAAM,CAAA;AAC7B","file":"limits.cjs","sourcesContent":["import type { KaladaV1Limits } from \"./types.js\";\n\nexport const DEFAULT_KALADA_V1_LIMITS: KaladaV1Limits = Object.freeze({\n maxAstDepth: 64,\n maxAstNodes: 10_000,\n maxValueDepth: 64,\n maxValueNodes: 10_000,\n maxStringLength: 10_000,\n maxReferenceLength: 1_000,\n maxEvaluationSteps: 10_000,\n});\n\nconst MAXIMUM: KaladaV1Limits = Object.freeze({\n maxAstDepth: 256,\n maxAstNodes: 100_000,\n maxValueDepth: 256,\n maxValueNodes: 100_000,\n maxStringLength: 1_000_000,\n maxReferenceLength: 100_000,\n maxEvaluationSteps: 100_000,\n});\n\nexport function resolveLimits(input?: Partial<KaladaV1Limits>): KaladaV1Limits {\n const limits = { ...DEFAULT_KALADA_V1_LIMITS, ...input };\n for (const key of Object.keys(limits) as (keyof KaladaV1Limits)[]) {\n const value = limits[key];\n if (!Number.isSafeInteger(value) || value < 1 || value > MAXIMUM[key])\n throw new RangeError(\"limit\");\n }\n return Object.freeze(limits);\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KaladaV1Limits } from './types.cjs';
|
|
2
|
+
import './json.cjs';
|
|
3
|
+
import './temporal.cjs';
|
|
4
|
+
import './values.cjs';
|
|
5
|
+
|
|
6
|
+
declare const DEFAULT_KALADA_V1_LIMITS: KaladaV1Limits;
|
|
7
|
+
declare function resolveLimits(input?: Partial<KaladaV1Limits>): KaladaV1Limits;
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_KALADA_V1_LIMITS, resolveLimits };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KaladaV1Limits } from './types.js';
|
|
2
|
+
import './json.js';
|
|
3
|
+
import './temporal.js';
|
|
4
|
+
import './values.js';
|
|
5
|
+
|
|
6
|
+
declare const DEFAULT_KALADA_V1_LIMITS: KaladaV1Limits;
|
|
7
|
+
declare function resolveLimits(input?: Partial<KaladaV1Limits>): KaladaV1Limits;
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_KALADA_V1_LIMITS, resolveLimits };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const DEFAULT_KALADA_V1_LIMITS = Object.freeze({
|
|
2
|
+
maxAstDepth: 64,
|
|
3
|
+
maxAstNodes: 1e4,
|
|
4
|
+
maxValueDepth: 64,
|
|
5
|
+
maxValueNodes: 1e4,
|
|
6
|
+
maxStringLength: 1e4,
|
|
7
|
+
maxReferenceLength: 1e3,
|
|
8
|
+
maxEvaluationSteps: 1e4
|
|
9
|
+
});
|
|
10
|
+
const MAXIMUM = Object.freeze({
|
|
11
|
+
maxAstDepth: 256,
|
|
12
|
+
maxAstNodes: 1e5,
|
|
13
|
+
maxValueDepth: 256,
|
|
14
|
+
maxValueNodes: 1e5,
|
|
15
|
+
maxStringLength: 1e6,
|
|
16
|
+
maxReferenceLength: 1e5,
|
|
17
|
+
maxEvaluationSteps: 1e5
|
|
18
|
+
});
|
|
19
|
+
function resolveLimits(input) {
|
|
20
|
+
const limits = { ...DEFAULT_KALADA_V1_LIMITS, ...input };
|
|
21
|
+
for (const key of Object.keys(limits)) {
|
|
22
|
+
const value = limits[key];
|
|
23
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > MAXIMUM[key])
|
|
24
|
+
throw new RangeError("limit");
|
|
25
|
+
}
|
|
26
|
+
return Object.freeze(limits);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { DEFAULT_KALADA_V1_LIMITS, resolveLimits };
|
|
30
|
+
//# sourceMappingURL=limits.js.map
|
|
31
|
+
//# sourceMappingURL=limits.js.map
|