@telorun/cel 0.0.0-stage → 0.107.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/LICENSE +17 -0
- package/README.md +281 -2
- package/dist/activation.d.ts +27 -0
- package/dist/activation.d.ts.map +1 -0
- package/dist/activation.js +24 -0
- package/dist/backend-runtime.d.ts +146 -0
- package/dist/backend-runtime.d.ts.map +1 -0
- package/dist/backend-runtime.js +322 -0
- package/dist/bounded-cache.d.ts +21 -0
- package/dist/bounded-cache.d.ts.map +1 -0
- package/dist/bounded-cache.js +42 -0
- package/dist/catalog-runtime.d.ts +59 -0
- package/dist/catalog-runtime.d.ts.map +1 -0
- package/dist/catalog-runtime.js +785 -0
- package/dist/cel-expression.d.ts +32 -0
- package/dist/cel-expression.d.ts.map +1 -0
- package/dist/cel-expression.js +29 -0
- package/dist/cel-map-value.d.ts +34 -0
- package/dist/cel-map-value.d.ts.map +1 -0
- package/dist/cel-map-value.js +74 -0
- package/dist/cel-program.d.ts +44 -0
- package/dist/cel-program.d.ts.map +1 -0
- package/dist/cel-program.js +72 -0
- package/dist/cel-type.d.ts +131 -0
- package/dist/cel-type.d.ts.map +1 -0
- package/dist/cel-type.js +293 -0
- package/dist/cel-value.d.ts +159 -0
- package/dist/cel-value.d.ts.map +1 -0
- package/dist/cel-value.js +225 -0
- package/dist/check-diagnostic.d.ts +53 -0
- package/dist/check-diagnostic.d.ts.map +1 -0
- package/dist/check-diagnostic.js +66 -0
- package/dist/checker.d.ts +77 -0
- package/dist/checker.d.ts.map +1 -0
- package/dist/checker.js +721 -0
- package/dist/closure-backend.d.ts +21 -0
- package/dist/closure-backend.d.ts.map +1 -0
- package/dist/closure-backend.js +436 -0
- package/dist/comprehension-bindings.d.ts +33 -0
- package/dist/comprehension-bindings.d.ts.map +1 -0
- package/dist/comprehension-bindings.js +50 -0
- package/dist/comprehension-runtime.d.ts +44 -0
- package/dist/comprehension-runtime.d.ts.map +1 -0
- package/dist/comprehension-runtime.js +137 -0
- package/dist/declared-chain.d.ts +35 -0
- package/dist/declared-chain.d.ts.map +1 -0
- package/dist/declared-chain.js +36 -0
- package/dist/duration-value.d.ts +59 -0
- package/dist/duration-value.d.ts.map +1 -0
- package/dist/duration-value.js +135 -0
- package/dist/emitted-module.d.ts +207 -0
- package/dist/emitted-module.d.ts.map +1 -0
- package/dist/emitted-module.js +359 -0
- package/dist/engine-version.d.ts +3 -0
- package/dist/engine-version.d.ts.map +1 -0
- package/dist/engine-version.js +8 -0
- package/dist/environment-digest.d.ts +44 -0
- package/dist/environment-digest.d.ts.map +1 -0
- package/dist/environment-digest.js +98 -0
- package/dist/environment.d.ts +283 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +459 -0
- package/dist/function-catalog.d.ts +66 -0
- package/dist/function-catalog.d.ts.map +1 -0
- package/dist/function-catalog.js +77 -0
- package/dist/function-registry.d.ts +78 -0
- package/dist/function-registry.d.ts.map +1 -0
- package/dist/function-registry.js +189 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/integer-arithmetic.d.ts +27 -0
- package/dist/integer-arithmetic.d.ts.map +1 -0
- package/dist/integer-arithmetic.js +58 -0
- package/dist/js-emitter.d.ts +132 -0
- package/dist/js-emitter.d.ts.map +1 -0
- package/dist/js-emitter.js +562 -0
- package/dist/json-schema-type.d.ts +182 -0
- package/dist/json-schema-type.d.ts.map +1 -0
- package/dist/json-schema-type.js +487 -0
- package/dist/json-text-scan.d.ts +28 -0
- package/dist/json-text-scan.d.ts.map +1 -0
- package/dist/json-text-scan.js +159 -0
- package/dist/lexer.d.ts +103 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +458 -0
- package/dist/macro-check.d.ts +33 -0
- package/dist/macro-check.d.ts.map +1 -0
- package/dist/macro-check.js +162 -0
- package/dist/macro-shape.d.ts +24 -0
- package/dist/macro-shape.d.ts.map +1 -0
- package/dist/macro-shape.js +55 -0
- package/dist/member-read.d.ts +52 -0
- package/dist/member-read.d.ts.map +1 -0
- package/dist/member-read.js +125 -0
- package/dist/namespace-resolution.d.ts +35 -0
- package/dist/namespace-resolution.d.ts.map +1 -0
- package/dist/namespace-resolution.js +160 -0
- package/dist/nominal-type.d.ts +63 -0
- package/dist/nominal-type.d.ts.map +1 -0
- package/dist/nominal-type.js +98 -0
- package/dist/nullable-access.d.ts +38 -0
- package/dist/nullable-access.d.ts.map +1 -0
- package/dist/nullable-access.js +93 -0
- package/dist/parse-limits.d.ts +26 -0
- package/dist/parse-limits.d.ts.map +1 -0
- package/dist/parse-limits.js +21 -0
- package/dist/parser.d.ts +48 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +503 -0
- package/dist/qualified-calls.d.ts +22 -0
- package/dist/qualified-calls.d.ts.map +1 -0
- package/dist/qualified-calls.js +27 -0
- package/dist/regular-expression.d.ts +48 -0
- package/dist/regular-expression.d.ts.map +1 -0
- package/dist/regular-expression.js +77 -0
- package/dist/reserved-words.d.ts +52 -0
- package/dist/reserved-words.d.ts.map +1 -0
- package/dist/reserved-words.js +77 -0
- package/dist/resolved-call.d.ts +33 -0
- package/dist/resolved-call.d.ts.map +1 -0
- package/dist/resolved-call.js +15 -0
- package/dist/root-references.d.ts +23 -0
- package/dist/root-references.d.ts.map +1 -0
- package/dist/root-references.js +120 -0
- package/dist/runtime-library.d.ts +56 -0
- package/dist/runtime-library.d.ts.map +1 -0
- package/dist/runtime-library.js +545 -0
- package/dist/serializer.d.ts +24 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +240 -0
- package/dist/sha256.d.ts +20 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +103 -0
- package/dist/signature.d.ts +72 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +61 -0
- package/dist/signatures/function-catalog.json +788 -0
- package/dist/signatures/standard-library.json +229 -0
- package/dist/standard-library.d.ts +41 -0
- package/dist/standard-library.d.ts.map +1 -0
- package/dist/standard-library.js +85 -0
- package/dist/syntax-diagnostic.d.ts +61 -0
- package/dist/syntax-diagnostic.d.ts.map +1 -0
- package/dist/syntax-diagnostic.js +28 -0
- package/dist/syntax-tree.d.ts +160 -0
- package/dist/syntax-tree.d.ts.map +1 -0
- package/dist/syntax-tree.js +58 -0
- package/dist/timestamp-value.d.ts +53 -0
- package/dist/timestamp-value.d.ts.map +1 -0
- package/dist/timestamp-value.js +223 -0
- package/dist/tree-equality.d.ts +15 -0
- package/dist/tree-equality.d.ts.map +1 -0
- package/dist/tree-equality.js +105 -0
- package/dist/type-expression.d.ts +26 -0
- package/dist/type-expression.d.ts.map +1 -0
- package/dist/type-expression.js +134 -0
- package/dist/value-equality.d.ts +38 -0
- package/dist/value-equality.d.ts.map +1 -0
- package/dist/value-equality.js +196 -0
- package/dist/value-text.d.ts +25 -0
- package/dist/value-text.d.ts.map +1 -0
- package/dist/value-text.js +44 -0
- package/dist/zoned-calendar.d.ts +61 -0
- package/dist/zoned-calendar.d.ts.map +1 -0
- package/dist/zoned-calendar.js +143 -0
- package/package.json +56 -3
- package/src/activation.ts +32 -0
- package/src/backend-runtime.ts +454 -0
- package/src/bounded-cache.ts +45 -0
- package/src/catalog-runtime.ts +921 -0
- package/src/cel-expression.ts +53 -0
- package/src/cel-map-value.ts +86 -0
- package/src/cel-program.ts +103 -0
- package/src/cel-type.ts +359 -0
- package/src/cel-value.ts +353 -0
- package/src/check-diagnostic.ts +102 -0
- package/src/checker.ts +932 -0
- package/src/closure-backend.ts +502 -0
- package/src/comprehension-bindings.ts +66 -0
- package/src/comprehension-runtime.ts +157 -0
- package/src/declared-chain.ts +45 -0
- package/src/duration-value.ts +145 -0
- package/src/emitted-module.ts +494 -0
- package/src/engine-version.ts +9 -0
- package/src/environment-digest.ts +111 -0
- package/src/environment.ts +740 -0
- package/src/function-catalog.ts +140 -0
- package/src/function-registry.ts +229 -0
- package/src/index.ts +386 -0
- package/src/integer-arithmetic.ts +64 -0
- package/src/js-emitter.ts +713 -0
- package/src/json-schema-type.ts +664 -0
- package/src/json-text-scan.ts +163 -0
- package/src/lexer.ts +562 -0
- package/src/macro-check.ts +191 -0
- package/src/macro-shape.ts +66 -0
- package/src/member-read.ts +126 -0
- package/src/namespace-resolution.ts +167 -0
- package/src/nominal-type.ts +149 -0
- package/src/nullable-access.ts +95 -0
- package/src/parse-limits.ts +36 -0
- package/src/parser.ts +554 -0
- package/src/qualified-calls.ts +39 -0
- package/src/regular-expression.ts +101 -0
- package/src/reserved-words.ts +94 -0
- package/src/resolved-call.ts +34 -0
- package/src/root-references.ts +126 -0
- package/src/runtime-library.ts +615 -0
- package/src/serializer.ts +246 -0
- package/src/sha256.ts +112 -0
- package/src/signature.ts +127 -0
- package/src/signatures/function-catalog.json +788 -0
- package/src/signatures/standard-library.json +235 -0
- package/src/standard-library.ts +149 -0
- package/src/syntax-diagnostic.ts +72 -0
- package/src/syntax-tree.ts +229 -0
- package/src/timestamp-value.ts +294 -0
- package/src/tree-equality.ts +130 -0
- package/src/type-expression.ts +160 -0
- package/src/value-equality.ts +201 -0
- package/src/value-text.ts +45 -0
- package/src/zoned-calendar.ts +178 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which functions an environment has, and which one a call resolves to.
|
|
3
|
+
*
|
|
4
|
+
* **Nothing here is privileged.** The standard library registers through exactly this
|
|
5
|
+
* surface, so a host can replace one of its signatures or remove it — the capability
|
|
6
|
+
* the whole package exists for. Registration is last-wins by dispatch key
|
|
7
|
+
* (`signature.ts`), removal is by the same key, and both are per environment: a
|
|
8
|
+
* clone inherits and may then diverge without touching its parent.
|
|
9
|
+
*
|
|
10
|
+
* **Resolution answers WHY it failed**, never just "no". A call on a name nothing
|
|
11
|
+
* registers, a call written in the wrong form, and a call whose arguments no overload
|
|
12
|
+
* takes are three different mistakes with three different repairs, and the engine
|
|
13
|
+
* being replaced reported one sentence for all three — which is why a separate
|
|
14
|
+
* classifier had to re-derive the cause after the fact. The checker decides it here,
|
|
15
|
+
* once, with the candidates it considered.
|
|
16
|
+
*/
|
|
17
|
+
import type { CelType } from "./cel-type.js";
|
|
18
|
+
import type { CallForm, CelSignature, FunctionMetadata } from "./signature.js";
|
|
19
|
+
export interface RegisteredFunction {
|
|
20
|
+
readonly signature: CelSignature;
|
|
21
|
+
readonly metadata: FunctionMetadata;
|
|
22
|
+
}
|
|
23
|
+
export type ResolutionFailure =
|
|
24
|
+
/** No function of that name is registered, in any form. */
|
|
25
|
+
{
|
|
26
|
+
readonly reason: "unknown";
|
|
27
|
+
readonly candidates: readonly RegisteredFunction[];
|
|
28
|
+
}
|
|
29
|
+
/** The name is registered, but only in the other call form. */
|
|
30
|
+
| {
|
|
31
|
+
readonly reason: "wrong-form";
|
|
32
|
+
readonly candidates: readonly RegisteredFunction[];
|
|
33
|
+
}
|
|
34
|
+
/** The name and form are registered; no overload takes these arguments. */
|
|
35
|
+
| {
|
|
36
|
+
readonly reason: "no-overload";
|
|
37
|
+
readonly candidates: readonly RegisteredFunction[];
|
|
38
|
+
};
|
|
39
|
+
export interface Resolution {
|
|
40
|
+
readonly resolved: RegisteredFunction;
|
|
41
|
+
/** The return type with every type parameter substituted by what this call bound. */
|
|
42
|
+
readonly returns: CelType;
|
|
43
|
+
}
|
|
44
|
+
export declare class FunctionRegistry {
|
|
45
|
+
private readonly byName;
|
|
46
|
+
constructor(inherited?: FunctionRegistry);
|
|
47
|
+
/** Registers a function, replacing any registration answering the same call. */
|
|
48
|
+
register(signature: CelSignature, metadata?: FunctionMetadata): void;
|
|
49
|
+
/** Removes the one registration answering that call. Answers whether it was there. */
|
|
50
|
+
remove(signature: CelSignature): boolean;
|
|
51
|
+
/** Removes every registration of a name. Answers how many went. */
|
|
52
|
+
removeName(name: string): number;
|
|
53
|
+
has(name: string): boolean;
|
|
54
|
+
/** Every registration, in name order then registration order. */
|
|
55
|
+
list(): readonly RegisteredFunction[];
|
|
56
|
+
named(name: string): readonly RegisteredFunction[];
|
|
57
|
+
/**
|
|
58
|
+
* The function a call resolves to. `receiver` is the type the call is written on,
|
|
59
|
+
* absent for a global call.
|
|
60
|
+
*/
|
|
61
|
+
resolve(name: string, form: CallForm, args: readonly CelType[], receiver?: CelType): Resolution | ResolutionFailure;
|
|
62
|
+
private match;
|
|
63
|
+
/**
|
|
64
|
+
* Whether an argument fits a parameter, binding type parameters as it goes.
|
|
65
|
+
*
|
|
66
|
+
* **A type parameter is bound by the first argument that mentions it**, and a later
|
|
67
|
+
* argument does not refine it: `[] + [3, 4]` is `list<T>`, because the empty list
|
|
68
|
+
* fixed the element type as "unknown" and the second argument cannot retroactively
|
|
69
|
+
* decide what the first one held.
|
|
70
|
+
*/
|
|
71
|
+
private fits;
|
|
72
|
+
}
|
|
73
|
+
/** The type with every bound parameter replaced; an unbound one stays as it is. */
|
|
74
|
+
export declare function substitute(type: CelType, bindings: ReadonlyMap<string, CelType>): CelType;
|
|
75
|
+
/** How a resolution failure names what it looked at, for a message a human reads. */
|
|
76
|
+
export declare function describeCandidates(candidates: readonly RegisteredFunction[]): string;
|
|
77
|
+
export declare function describeArguments(args: readonly CelType[]): string;
|
|
78
|
+
//# sourceMappingURL=function-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-registry.d.ts","sourceRoot":"","sources":["../src/function-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG/E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;CACrC;AAED,MAAM,MAAM,iBAAiB;AAC3B,2DAA2D;AACzD;IAAE,QAAQ,CAAC,MAAM,EAAE,S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gB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAwBzF;AAED,qFAAqF;AACrF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,SAAS,kBAAkB,EAAE,GAAG,MAAM,CAEpF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAElE"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which functions an environment has, and which one a call resolves to.
|
|
3
|
+
*
|
|
4
|
+
* **Nothing here is privileged.** The standard library registers through exactly this
|
|
5
|
+
* surface, so a host can replace one of its signatures or remove it — the capability
|
|
6
|
+
* the whole package exists for. Registration is last-wins by dispatch key
|
|
7
|
+
* (`signature.ts`), removal is by the same key, and both are per environment: a
|
|
8
|
+
* clone inherits and may then diverge without touching its parent.
|
|
9
|
+
*
|
|
10
|
+
* **Resolution answers WHY it failed**, never just "no". A call on a name nothing
|
|
11
|
+
* registers, a call written in the wrong form, and a call whose arguments no overload
|
|
12
|
+
* takes are three different mistakes with three different repairs, and the engine
|
|
13
|
+
* being replaced reported one sentence for all three — which is why a separate
|
|
14
|
+
* classifier had to re-derive the cause after the fact. The checker decides it here,
|
|
15
|
+
* once, with the candidates it considered.
|
|
16
|
+
*/
|
|
17
|
+
import { assignable, DYN, formatType, isDyn } from "./cel-type.js";
|
|
18
|
+
import { formatSignature, signatureKey } from "./signature.js";
|
|
19
|
+
export class FunctionRegistry {
|
|
20
|
+
byName;
|
|
21
|
+
constructor(inherited) {
|
|
22
|
+
this.byName = new Map();
|
|
23
|
+
if (inherited) {
|
|
24
|
+
for (const [name, entries] of inherited.byName)
|
|
25
|
+
this.byName.set(name, [...entries]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Registers a function, replacing any registration answering the same call. */
|
|
29
|
+
register(signature, metadata = {}) {
|
|
30
|
+
const entries = this.byName.get(signature.name) ?? [];
|
|
31
|
+
const key = signatureKey(signature);
|
|
32
|
+
const at = entries.findIndex((entry) => signatureKey(entry.signature) === key);
|
|
33
|
+
const entry = { signature, metadata };
|
|
34
|
+
if (at === -1)
|
|
35
|
+
entries.push(entry);
|
|
36
|
+
else
|
|
37
|
+
entries[at] = entry;
|
|
38
|
+
this.byName.set(signature.name, entries);
|
|
39
|
+
}
|
|
40
|
+
/** Removes the one registration answering that call. Answers whether it was there. */
|
|
41
|
+
remove(signature) {
|
|
42
|
+
const entries = this.byName.get(signature.name);
|
|
43
|
+
if (!entries)
|
|
44
|
+
return false;
|
|
45
|
+
const key = signatureKey(signature);
|
|
46
|
+
const at = entries.findIndex((entry) => signatureKey(entry.signature) === key);
|
|
47
|
+
if (at === -1)
|
|
48
|
+
return false;
|
|
49
|
+
entries.splice(at, 1);
|
|
50
|
+
if (entries.length === 0)
|
|
51
|
+
this.byName.delete(signature.name);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/** Removes every registration of a name. Answers how many went. */
|
|
55
|
+
removeName(name) {
|
|
56
|
+
const entries = this.byName.get(name);
|
|
57
|
+
if (!entries)
|
|
58
|
+
return 0;
|
|
59
|
+
this.byName.delete(name);
|
|
60
|
+
return entries.length;
|
|
61
|
+
}
|
|
62
|
+
has(name) {
|
|
63
|
+
return this.byName.has(name);
|
|
64
|
+
}
|
|
65
|
+
/** Every registration, in name order then registration order. */
|
|
66
|
+
list() {
|
|
67
|
+
return [...this.byName.keys()].sort().flatMap((name) => this.byName.get(name));
|
|
68
|
+
}
|
|
69
|
+
named(name) {
|
|
70
|
+
return this.byName.get(name) ?? [];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The function a call resolves to. `receiver` is the type the call is written on,
|
|
74
|
+
* absent for a global call.
|
|
75
|
+
*/
|
|
76
|
+
resolve(name, form, args, receiver) {
|
|
77
|
+
const all = this.byName.get(name);
|
|
78
|
+
if (!all || all.length === 0)
|
|
79
|
+
return { reason: "unknown", candidates: [] };
|
|
80
|
+
const inForm = all.filter((entry) => entry.signature.form === form);
|
|
81
|
+
if (inForm.length === 0)
|
|
82
|
+
return { reason: "wrong-form", candidates: all };
|
|
83
|
+
const arity = inForm.filter((entry) => entry.signature.parameters.length === args.length);
|
|
84
|
+
const viable = arity.length === 0 ? inForm : arity;
|
|
85
|
+
// Exact first, then a candidate `dyn` makes viable, which is what keeps an
|
|
86
|
+
// unlisted variable from turning one mistake into two.
|
|
87
|
+
const exact = this.match(viable, args, receiver, false);
|
|
88
|
+
if (exact)
|
|
89
|
+
return exact;
|
|
90
|
+
const loose = this.match(viable, args, receiver, true);
|
|
91
|
+
if (loose)
|
|
92
|
+
return loose;
|
|
93
|
+
return { reason: "no-overload", candidates: inForm };
|
|
94
|
+
}
|
|
95
|
+
match(candidates, args, receiver, allowDyn) {
|
|
96
|
+
for (const candidate of candidates) {
|
|
97
|
+
const { signature } = candidate;
|
|
98
|
+
if (signature.parameters.length !== args.length)
|
|
99
|
+
continue;
|
|
100
|
+
const bindings = new Map();
|
|
101
|
+
if (signature.receiver && !this.fits(receiver ?? DYN, signature.receiver, bindings, allowDyn))
|
|
102
|
+
continue;
|
|
103
|
+
if (!signature.parameters.every((want, at) => this.fits(args[at], want, bindings, allowDyn)))
|
|
104
|
+
continue;
|
|
105
|
+
return { resolved: candidate, returns: substitute(signature.returns, bindings) };
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Whether an argument fits a parameter, binding type parameters as it goes.
|
|
111
|
+
*
|
|
112
|
+
* **A type parameter is bound by the first argument that mentions it**, and a later
|
|
113
|
+
* argument does not refine it: `[] + [3, 4]` is `list<T>`, because the empty list
|
|
114
|
+
* fixed the element type as "unknown" and the second argument cannot retroactively
|
|
115
|
+
* decide what the first one held.
|
|
116
|
+
*/
|
|
117
|
+
fits(argument, parameter, bindings, allowDyn) {
|
|
118
|
+
if (parameter.kind === "parameter") {
|
|
119
|
+
const bound = bindings.get(parameter.name);
|
|
120
|
+
if (!bound) {
|
|
121
|
+
bindings.set(parameter.name, argument);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
// A binding that holds an unresolved parameter holds no information, so a later
|
|
125
|
+
// concrete argument refines it: `optional.none().orValue(42)` is an int.
|
|
126
|
+
if (bound.kind === "parameter" && argument.kind !== "parameter") {
|
|
127
|
+
bindings.set(parameter.name, argument);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
if (bound.kind === "parameter" || argument.kind === "parameter")
|
|
131
|
+
return true;
|
|
132
|
+
return assignable(argument, bound) || (allowDyn && (isDyn(argument) || isDyn(bound)));
|
|
133
|
+
}
|
|
134
|
+
if (parameter.kind === "list" && argument.kind === "list") {
|
|
135
|
+
return this.fits(argument.element, parameter.element, bindings, allowDyn);
|
|
136
|
+
}
|
|
137
|
+
if (parameter.kind === "map" && argument.kind === "map") {
|
|
138
|
+
return (this.fits(argument.key, parameter.key, bindings, allowDyn) &&
|
|
139
|
+
this.fits(argument.value, parameter.value, bindings, allowDyn));
|
|
140
|
+
}
|
|
141
|
+
if (parameter.kind === "optional" && argument.kind === "optional") {
|
|
142
|
+
return this.fits(argument.value, parameter.value, bindings, allowDyn);
|
|
143
|
+
}
|
|
144
|
+
if (parameter.kind === "nominal" &&
|
|
145
|
+
argument.kind === "nominal" &&
|
|
146
|
+
parameter.name === argument.name &&
|
|
147
|
+
parameter.args.length === argument.args.length) {
|
|
148
|
+
// A named type's arguments are invariant, so they fit one for one — which is also
|
|
149
|
+
// where a signature written over `Self` binds its own type parameters.
|
|
150
|
+
return parameter.args.every((want, at) => this.fits(argument.args[at], want, bindings, allowDyn));
|
|
151
|
+
}
|
|
152
|
+
if (isDyn(argument))
|
|
153
|
+
return allowDyn || isDyn(parameter);
|
|
154
|
+
return assignable(argument, parameter);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** The type with every bound parameter replaced; an unbound one stays as it is. */
|
|
158
|
+
export function substitute(type, bindings) {
|
|
159
|
+
switch (type.kind) {
|
|
160
|
+
case "parameter":
|
|
161
|
+
return bindings.get(type.name) ?? type;
|
|
162
|
+
case "list": {
|
|
163
|
+
const element = substitute(type.element, bindings);
|
|
164
|
+
return element === type.element ? type : { kind: "list", element };
|
|
165
|
+
}
|
|
166
|
+
case "map": {
|
|
167
|
+
const key = substitute(type.key, bindings);
|
|
168
|
+
const value = substitute(type.value, bindings);
|
|
169
|
+
return key === type.key && value === type.value ? type : { kind: "map", key, value };
|
|
170
|
+
}
|
|
171
|
+
case "optional": {
|
|
172
|
+
const value = substitute(type.value, bindings);
|
|
173
|
+
return value === type.value ? type : { kind: "optional", value };
|
|
174
|
+
}
|
|
175
|
+
case "nominal": {
|
|
176
|
+
const args = type.args.map((argument) => substitute(argument, bindings));
|
|
177
|
+
return args.every((argument, at) => argument === type.args[at]) ? type : { ...type, args };
|
|
178
|
+
}
|
|
179
|
+
default:
|
|
180
|
+
return type;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** How a resolution failure names what it looked at, for a message a human reads. */
|
|
184
|
+
export function describeCandidates(candidates) {
|
|
185
|
+
return candidates.map((candidate) => formatSignature(candidate.signature)).join(", ");
|
|
186
|
+
}
|
|
187
|
+
export function describeArguments(args) {
|
|
188
|
+
return args.map((type) => formatType(type)).join(", ");
|
|
189
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@telorun/cel` — the CEL language.
|
|
3
|
+
*
|
|
4
|
+
* This entry is the front end: reading an expression, the canonical tree it reads
|
|
5
|
+
* into, writing a tree back as source, and the two questions a consumer asks of a
|
|
6
|
+
* tree (what it reads, and which namespaced functions it calls). It reaches no
|
|
7
|
+
* runtime of its own and no host facility — nothing here touches a filesystem, a
|
|
8
|
+
* clock or a network, so it runs unchanged in a browser.
|
|
9
|
+
*
|
|
10
|
+
* It owns CEL and nothing above it: no host's type vocabulary, no host's function
|
|
11
|
+
* catalog. Those are registered onto the engine by whoever embeds it.
|
|
12
|
+
*/
|
|
13
|
+
export { parseExpression, resolvedUnder } from "./cel-expression.js";
|
|
14
|
+
export type { CelExpression, ParseExpressionOptions } from "./cel-expression.js";
|
|
15
|
+
export { MAX_INT, MAX_UINT, MIN_INT } from "./lexer.js";
|
|
16
|
+
export { CelNamespaceError, namespaceSetsEqual, normalizeNamespaces, RESERVED_NAMESPACES, resolveNamespaces, } from "./namespace-resolution.js";
|
|
17
|
+
export { DEFAULT_PARSE_LIMITS, resolveParseLimits } from "./parse-limits.js";
|
|
18
|
+
export type { CelParseLimits } from "./parse-limits.js";
|
|
19
|
+
export { parseSyntax } from "./parser.js";
|
|
20
|
+
export type { ParseOptions, ParseResult } from "./parser.js";
|
|
21
|
+
export { qualifiedCalls } from "./qualified-calls.js";
|
|
22
|
+
export type { QualifiedCall } from "./qualified-calls.js";
|
|
23
|
+
export { isIdentifierSpelling, isReservedWord, LITERAL_WORDS, OPERATOR_WORDS, RESERVED_WORDS, } from "./reserved-words.js";
|
|
24
|
+
export { rootReferences } from "./root-references.js";
|
|
25
|
+
export { splitDeclaredChain } from "./declared-chain.js";
|
|
26
|
+
export type { DeclaredChain } from "./declared-chain.js";
|
|
27
|
+
export { CelSerializeError, serializeTree } from "./serializer.js";
|
|
28
|
+
export type { CelSyntaxCode, CelSyntaxDiagnostic } from "./syntax-diagnostic.js";
|
|
29
|
+
export { childNodes, hasUnparsed, walkTree } from "./syntax-tree.js";
|
|
30
|
+
export type { CelBinaryNode, CelBinaryOperator, CelCallNode, CelConditionalNode, CelIdentNode, CelIndexNode, CelListNode, CelLiteral, CelLiteralNode, CelMapEntry, CelMapNode, CelNode, CelQualifiedCallNode, CelReceiverCallNode, CelSelectNode, CelUnaryNode, CelUnaryOperator, CelUnparsedNode, SourceRange, } from "./syntax-tree.js";
|
|
31
|
+
export { treesEqual } from "./tree-equality.js";
|
|
32
|
+
export { admitsNull, assignable, BOOL, BYTES, DOUBLE, DURATION, DYN, formatType, INT, isDyn, isNumeric, listOf, mapOf, NULL, optionalOf, parameterOf, STRING, TIMESTAMP, TYPE, typesEqual, UINT, unify, unionOf, WELL_KNOWN_TYPE_NAMES, withoutNull, withoutParameters, } from "./cel-type.js";
|
|
33
|
+
export type { CelType, DynType, ListType, MapType, NominalType, OptionalType, ParameterType, PrimitiveName, PrimitiveType, RecordType, UnionType, } from "./cel-type.js";
|
|
34
|
+
export { CEL_CHECK_CODES, CelEngineError } from "./check-diagnostic.js";
|
|
35
|
+
export type { CelCheckCode, CelCheckDiagnostic, CelDiagnosticFix, CelEngineErrorCode, } from "./check-diagnostic.js";
|
|
36
|
+
export type { CheckResult, NamespaceFunction } from "./checker.js";
|
|
37
|
+
export { CelEnvironment, DEFAULT_COMPILED_CACHE_CAPACITY } from "./environment.js";
|
|
38
|
+
export type { CelEnvironmentOptions, Definitions, FunctionDefinition, NamespaceFunctionDeclaration, NamespaceListing, NamespaceOptions, SchemaRegistrationReport, TypeDeclaration, TypeDefinitionListing, VariableDefinition, } from "./environment.js";
|
|
39
|
+
export { FunctionRegistry } from "./function-registry.js";
|
|
40
|
+
export type { RegisteredFunction, Resolution, ResolutionFailure } from "./function-registry.js";
|
|
41
|
+
export { fieldMapType, schemaType, TYPE_CONSTRAINING_KEYWORDS, TYPE_KEYWORDS_READ, UNJUDGED_REASONS, } from "./json-schema-type.js";
|
|
42
|
+
export type { FieldDeclaration, JsonSchemaDocument, JsonSchemaNode, NamedTypeLookup, RecursiveSchemaReference, SchemaConversion, SchemaTypeAnswer, SchemaTypeResolver, SchemaTypeResult, UnjudgedReason, UnjudgedSchemaNode, } from "./json-schema-type.js";
|
|
43
|
+
export { CelTypeRegistrationError } from "./nominal-type.js";
|
|
44
|
+
export type { NominalOperatorDeclaration, NominalTypeDefinition, RegisteredType, } from "./nominal-type.js";
|
|
45
|
+
export type { ResolvedCall } from "./resolved-call.js";
|
|
46
|
+
export { formatSignature, parseSignature, signatureKey } from "./signature.js";
|
|
47
|
+
export type { CallForm, CelSignature, FunctionMetadata, LiteralArgumentCheck, } from "./signature.js";
|
|
48
|
+
export { googleTypeNames, registerStandardLibrary, standardConstants, STANDARD_LIBRARY_GENERATION, standardLibrarySignatures, } from "./standard-library.js";
|
|
49
|
+
export type { StandardConstant } from "./standard-library.js";
|
|
50
|
+
export { catalogCategories, catalogSignatures, FUNCTION_CATALOG_GENERATION, functionCatalog, registerFunctionCatalog, } from "./function-catalog.js";
|
|
51
|
+
export type { CatalogFunction, RegisterCatalogOptions } from "./function-catalog.js";
|
|
52
|
+
export { catalogGuardedNames, catalogImplementation, catalogImplementedKeys, catalogLiteralCheck, } from "./catalog-runtime.js";
|
|
53
|
+
export type { CatalogImplementation, CelCatalogHandlers } from "./catalog-runtime.js";
|
|
54
|
+
export { scanJsonPrefix } from "./json-text-scan.js";
|
|
55
|
+
export type { JsonRefusal } from "./json-text-scan.js";
|
|
56
|
+
export { civilTimeIn, dateTextIn, daysInMonth, instantOfCivilTime, isoTextIn, knownTimeZone, } from "./zoned-calendar.js";
|
|
57
|
+
export type { CivilTime } from "./zoned-calendar.js";
|
|
58
|
+
export { CelTypeExpressionError, parseTypeExpression } from "./type-expression.js";
|
|
59
|
+
export type { NominalResolver } from "./type-expression.js";
|
|
60
|
+
export type { CelActivation } from "./activation.js";
|
|
61
|
+
export { BoundedCache } from "./bounded-cache.js";
|
|
62
|
+
export { celMapFromEntries, celMapKeys, mapKeyIdentity } from "./cel-map-value.js";
|
|
63
|
+
export { CelEvaluationError, programOfStep } from "./cel-program.js";
|
|
64
|
+
export type { CelProgram, EvaluateOptions } from "./cel-program.js";
|
|
65
|
+
export { ENGINE_VERSION } from "./engine-version.js";
|
|
66
|
+
export { EMITTER_FORMAT_GENERATION, emittedModuleIdentity, emittedModuleKey, emittedModuleRefusal, programsFromEmittedModule, readEmittedHeader, } from "./emitted-module.js";
|
|
67
|
+
export type { EmittedFactory, EmittedHeader, EmittedIdentity, EmittedModule, EmittedModuleStore, EmittedRuntime, StoredEmittedModule, } from "./emitted-module.js";
|
|
68
|
+
export { environmentDigest } from "./environment-digest.js";
|
|
69
|
+
export type { DigestedEnvironment } from "./environment-digest.js";
|
|
70
|
+
/** The whole contract between an emitted module and the runtime it is handed. */
|
|
71
|
+
export { RUNTIME_BINDINGS } from "./js-emitter.js";
|
|
72
|
+
export type { RuntimeBinding } from "./js-emitter.js";
|
|
73
|
+
export { CEL_EVALUATION_CODES, CEL_VALUE_KEYS, CEL_VALUE_TYPE, celError, celNone, celSome, celTypeNameOf, celTypeValue, celUint, isCelBytes, isCelDuration, isCelError, isCelMap, isCelOptional, isCelRecord, isCelTimestamp, isCelTypeValue, isCelUint, literalValue, } from "./cel-value.js";
|
|
74
|
+
export type { CelDuration, CelError, CelEvaluationCode, CelHostValue, CelMap, CelMapValueEntry, CelOptional, CelRecord, CelTimestamp, CelTypeValue, CelUint, CelValue, CelValueKey, } from "./cel-value.js";
|
|
75
|
+
export { compileTree } from "./closure-backend.js";
|
|
76
|
+
export type { CompiledTree } from "./closure-backend.js";
|
|
77
|
+
export { CALL_SITE_CACHE_CAPACITY, CelCompileError } from "./backend-runtime.js";
|
|
78
|
+
export type { CelStep, CompileTarget, EvaluationFrame, NamespaceDispatch, } from "./backend-runtime.js";
|
|
79
|
+
export { celAll, celExists, celExistsOne, celFilter, celMapComprehension, } from "./comprehension-runtime.js";
|
|
80
|
+
export type { ComprehensionBody } from "./comprehension-runtime.js";
|
|
81
|
+
export { celDurationFromNanos, durationField, durationNanos, durationOutOfRange, formatDuration, MAX_DURATION_NANOS, MIN_DURATION_NANOS, parseDuration, } from "./duration-value.js";
|
|
82
|
+
export { celHas, celIterable, celLookup, celRead, lookupError, MISSING, OUT_OF_RANGE, UNSUPPORTED_CONTAINER, UNSUPPORTED_KEY, } from "./member-read.js";
|
|
83
|
+
export type { Lookup } from "./member-read.js";
|
|
84
|
+
export { celMatches, PATTERN_CACHE_CAPACITY, RE2_FLAG_LETTERS, RE2_PATTERN_ERROR_KINDS, re2Pattern, } from "./regular-expression.js";
|
|
85
|
+
export type { RE2Compiled, RE2PatternRefusal } from "./regular-expression.js";
|
|
86
|
+
export { base64Text, celTypeValueOf, implementationOf, jsonAsCelValue, implementedKeys, optionalOfNonZero, standardConstantValues, typeValueName, } from "./runtime-library.js";
|
|
87
|
+
export type { CelCallContext, CelImplementation } from "./runtime-library.js";
|
|
88
|
+
export { celTimestamp, formatTimestamp, MAX_TIMESTAMP_SECONDS, MIN_TIMESTAMP_SECONDS, parseTimestamp, timestampField, timestampNanos, zonedFields, } from "./timestamp-value.js";
|
|
89
|
+
export { celCompare, celEqual } from "./value-equality.js";
|
|
90
|
+
export { bytesToText, doubleText, textToBytes } from "./value-text.js";
|
|
91
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,aAAa,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CEL language.
|
|
3
|
+
*
|
|
4
|
+
* This entry is the front end: reading an expression, the canonical tree it reads
|
|
5
|
+
* into, writing a tree back as source, and the two questions a consumer asks of a
|
|
6
|
+
* tree (what it reads, and which namespaced functions it calls). It reaches no
|
|
7
|
+
* runtime of its own and no host facility — nothing here touches a filesystem, a
|
|
8
|
+
* clock or a network, so it runs unchanged in a browser.
|
|
9
|
+
*
|
|
10
|
+
* It owns CEL and nothing above it: no host's type vocabulary, no host's function
|
|
11
|
+
* catalog. Those are registered onto the engine by whoever embeds it.
|
|
12
|
+
*/
|
|
13
|
+
export { parseExpression, resolvedUnder } from "./cel-expression.js";
|
|
14
|
+
export { MAX_INT, MAX_UINT, MIN_INT } from "./lexer.js";
|
|
15
|
+
export { CelNamespaceError, namespaceSetsEqual, normalizeNamespaces, RESERVED_NAMESPACES, resolveNamespaces, } from "./namespace-resolution.js";
|
|
16
|
+
export { DEFAULT_PARSE_LIMITS, resolveParseLimits } from "./parse-limits.js";
|
|
17
|
+
export { parseSyntax } from "./parser.js";
|
|
18
|
+
export { qualifiedCalls } from "./qualified-calls.js";
|
|
19
|
+
export { isIdentifierSpelling, isReservedWord, LITERAL_WORDS, OPERATOR_WORDS, RESERVED_WORDS, } from "./reserved-words.js";
|
|
20
|
+
export { rootReferences } from "./root-references.js";
|
|
21
|
+
export { splitDeclaredChain } from "./declared-chain.js";
|
|
22
|
+
export { CelSerializeError, serializeTree } from "./serializer.js";
|
|
23
|
+
export { childNodes, hasUnparsed, walkTree } from "./syntax-tree.js";
|
|
24
|
+
export { treesEqual } from "./tree-equality.js";
|
|
25
|
+
// --- the type system, the registry and the checker -------------------------
|
|
26
|
+
export { admitsNull, assignable, BOOL, BYTES, DOUBLE, DURATION, DYN, formatType, INT, isDyn, isNumeric, listOf, mapOf, NULL, optionalOf, parameterOf, STRING, TIMESTAMP, TYPE, typesEqual, UINT, unify, unionOf, WELL_KNOWN_TYPE_NAMES, withoutNull, withoutParameters, } from "./cel-type.js";
|
|
27
|
+
export { CEL_CHECK_CODES, CelEngineError } from "./check-diagnostic.js";
|
|
28
|
+
export { CelEnvironment, DEFAULT_COMPILED_CACHE_CAPACITY } from "./environment.js";
|
|
29
|
+
export { FunctionRegistry } from "./function-registry.js";
|
|
30
|
+
export { fieldMapType, schemaType, TYPE_CONSTRAINING_KEYWORDS, TYPE_KEYWORDS_READ, UNJUDGED_REASONS, } from "./json-schema-type.js";
|
|
31
|
+
export { CelTypeRegistrationError } from "./nominal-type.js";
|
|
32
|
+
export { formatSignature, parseSignature, signatureKey } from "./signature.js";
|
|
33
|
+
export { googleTypeNames, registerStandardLibrary, standardConstants, STANDARD_LIBRARY_GENERATION, standardLibrarySignatures, } from "./standard-library.js";
|
|
34
|
+
// --- the function catalog: the dialect, registered as a host registers one ------
|
|
35
|
+
export { catalogCategories, catalogSignatures, FUNCTION_CATALOG_GENERATION, functionCatalog, registerFunctionCatalog, } from "./function-catalog.js";
|
|
36
|
+
export { catalogGuardedNames, catalogImplementation, catalogImplementedKeys, catalogLiteralCheck, } from "./catalog-runtime.js";
|
|
37
|
+
export { scanJsonPrefix } from "./json-text-scan.js";
|
|
38
|
+
export { civilTimeIn, dateTextIn, daysInMonth, instantOfCivilTime, isoTextIn, knownTimeZone, } from "./zoned-calendar.js";
|
|
39
|
+
export { CelTypeExpressionError, parseTypeExpression } from "./type-expression.js";
|
|
40
|
+
export { BoundedCache } from "./bounded-cache.js";
|
|
41
|
+
export { celMapFromEntries, celMapKeys, mapKeyIdentity } from "./cel-map-value.js";
|
|
42
|
+
export { CelEvaluationError, programOfStep } from "./cel-program.js";
|
|
43
|
+
// --- the emitter: JavaScript source, its key, and the one store seam --------
|
|
44
|
+
export { ENGINE_VERSION } from "./engine-version.js";
|
|
45
|
+
export { EMITTER_FORMAT_GENERATION, emittedModuleIdentity, emittedModuleKey, emittedModuleRefusal, programsFromEmittedModule, readEmittedHeader, } from "./emitted-module.js";
|
|
46
|
+
export { environmentDigest } from "./environment-digest.js";
|
|
47
|
+
/** The whole contract between an emitted module and the runtime it is handed. */
|
|
48
|
+
export { RUNTIME_BINDINGS } from "./js-emitter.js";
|
|
49
|
+
export { CEL_EVALUATION_CODES, CEL_VALUE_KEYS, CEL_VALUE_TYPE, celError, celNone, celSome, celTypeNameOf, celTypeValue, celUint, isCelBytes, isCelDuration, isCelError, isCelMap, isCelOptional, isCelRecord, isCelTimestamp, isCelTypeValue, isCelUint, literalValue, } from "./cel-value.js";
|
|
50
|
+
export { compileTree } from "./closure-backend.js";
|
|
51
|
+
export { CALL_SITE_CACHE_CAPACITY, CelCompileError } from "./backend-runtime.js";
|
|
52
|
+
export { celAll, celExists, celExistsOne, celFilter, celMapComprehension, } from "./comprehension-runtime.js";
|
|
53
|
+
export { celDurationFromNanos, durationField, durationNanos, durationOutOfRange, formatDuration, MAX_DURATION_NANOS, MIN_DURATION_NANOS, parseDuration, } from "./duration-value.js";
|
|
54
|
+
export { celHas, celIterable, celLookup, celRead, lookupError, MISSING, OUT_OF_RANGE, UNSUPPORTED_CONTAINER, UNSUPPORTED_KEY, } from "./member-read.js";
|
|
55
|
+
export { celMatches, PATTERN_CACHE_CAPACITY, RE2_FLAG_LETTERS, RE2_PATTERN_ERROR_KINDS, re2Pattern, } from "./regular-expression.js";
|
|
56
|
+
export { base64Text, celTypeValueOf, implementationOf, jsonAsCelValue, implementedKeys, optionalOfNonZero, standardConstantValues, typeValueName, } from "./runtime-library.js";
|
|
57
|
+
export { celTimestamp, formatTimestamp, MAX_TIMESTAMP_SECONDS, MIN_TIMESTAMP_SECONDS, parseTimestamp, timestampField, timestampNanos, zonedFields, } from "./timestamp-value.js";
|
|
58
|
+
export { celCompare, celEqual } from "./value-equality.js";
|
|
59
|
+
export { bytesToText, doubleText, textToBytes } from "./value-text.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integer arithmetic: 64-bit, checked, and **never wrapped**.
|
|
3
|
+
*
|
|
4
|
+
* CEL's `int` is a signed 64-bit integer and its `uint` an unsigned one. A result
|
|
5
|
+
* outside the range is an error, not a wrap: an engine that wraps answers a value no
|
|
6
|
+
* other engine answers, and a manifest that silently computes `-9223372036854775808`
|
|
7
|
+
* from a sum of positives is worse than one that fails. The vectors pin this as the
|
|
8
|
+
* domain-keeping answer where the engine being replaced returns a number beyond int64.
|
|
9
|
+
*
|
|
10
|
+
* Division truncates toward zero and the modulo takes the dividend's sign, which is
|
|
11
|
+
* what `BigInt` already does; division and modulo by zero are errors of their own, so a
|
|
12
|
+
* reader of the code knows which one happened.
|
|
13
|
+
*/
|
|
14
|
+
import { type CelError, type CelUint } from "./cel-value.js";
|
|
15
|
+
import type { SourceRange } from "./syntax-tree.js";
|
|
16
|
+
/** An int result, or the overflow it is outside the range. */
|
|
17
|
+
export declare function intResult(value: bigint, range?: SourceRange): bigint | CelError;
|
|
18
|
+
/** A uint result, or the overflow it is outside the range. */
|
|
19
|
+
export declare function uintResult(value: bigint, range?: SourceRange): CelUint | CelError;
|
|
20
|
+
export declare function intDivide(left: bigint, right: bigint, range?: SourceRange): bigint | CelError;
|
|
21
|
+
export declare function intModulo(left: bigint, right: bigint, range?: SourceRange): bigint | CelError;
|
|
22
|
+
export declare function uintDivide(left: bigint, right: bigint, range?: SourceRange): CelUint | CelError;
|
|
23
|
+
export declare function uintModulo(left: bigint, right: bigint, range?: SourceRange): CelUint | CelError;
|
|
24
|
+
/** Whether a magnitude fits a uint64 — used by the conversions. */
|
|
25
|
+
export declare function fitsUint(value: bigint): boolean;
|
|
26
|
+
export declare function fitsInt(value: bigint): boolean;
|
|
27
|
+
//# sourceMappingURL=integer-arithmetic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integer-arithmetic.d.ts","sourceRoot":"","sources":["../src/integer-arithmetic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAqB,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQpD,8DAA8D;AAC9D,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAG/E;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,QAAQ,CAGjF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAG7F;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAG7F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,QAAQ,CAG/F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,QAAQ,CAG/F;AAED,mEAAmE;AACnE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integer arithmetic: 64-bit, checked, and **never wrapped**.
|
|
3
|
+
*
|
|
4
|
+
* CEL's `int` is a signed 64-bit integer and its `uint` an unsigned one. A result
|
|
5
|
+
* outside the range is an error, not a wrap: an engine that wraps answers a value no
|
|
6
|
+
* other engine answers, and a manifest that silently computes `-9223372036854775808`
|
|
7
|
+
* from a sum of positives is worse than one that fails. The vectors pin this as the
|
|
8
|
+
* domain-keeping answer where the engine being replaced returns a number beyond int64.
|
|
9
|
+
*
|
|
10
|
+
* Division truncates toward zero and the modulo takes the dividend's sign, which is
|
|
11
|
+
* what `BigInt` already does; division and modulo by zero are errors of their own, so a
|
|
12
|
+
* reader of the code knows which one happened.
|
|
13
|
+
*/
|
|
14
|
+
import { celError, celUint } from "./cel-value.js";
|
|
15
|
+
import { MAX_INT, MAX_UINT, MIN_INT } from "./lexer.js";
|
|
16
|
+
const MAX_UINT_PLUS_ONE = MAX_UINT + 1n;
|
|
17
|
+
function overflow(range, result, what) {
|
|
18
|
+
return celError("numeric_overflow", `${what} overflow: ${result}`, range);
|
|
19
|
+
}
|
|
20
|
+
/** An int result, or the overflow it is outside the range. */
|
|
21
|
+
export function intResult(value, range) {
|
|
22
|
+
if (value < MIN_INT || value > MAX_INT)
|
|
23
|
+
return overflow(range, value, "integer");
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
/** A uint result, or the overflow it is outside the range. */
|
|
27
|
+
export function uintResult(value, range) {
|
|
28
|
+
if (value < 0n || value > MAX_UINT)
|
|
29
|
+
return overflow(range, value, "unsigned integer");
|
|
30
|
+
return celUint(value);
|
|
31
|
+
}
|
|
32
|
+
export function intDivide(left, right, range) {
|
|
33
|
+
if (right === 0n)
|
|
34
|
+
return celError("division_by_zero", "division by zero", range);
|
|
35
|
+
return intResult(left / right, range);
|
|
36
|
+
}
|
|
37
|
+
export function intModulo(left, right, range) {
|
|
38
|
+
if (right === 0n)
|
|
39
|
+
return celError("modulo_by_zero", "modulus by zero", range);
|
|
40
|
+
return intResult(left % right, range);
|
|
41
|
+
}
|
|
42
|
+
export function uintDivide(left, right, range) {
|
|
43
|
+
if (right === 0n)
|
|
44
|
+
return celError("division_by_zero", "division by zero", range);
|
|
45
|
+
return uintResult(left / right, range);
|
|
46
|
+
}
|
|
47
|
+
export function uintModulo(left, right, range) {
|
|
48
|
+
if (right === 0n)
|
|
49
|
+
return celError("modulo_by_zero", "modulus by zero", range);
|
|
50
|
+
return uintResult(left % right, range);
|
|
51
|
+
}
|
|
52
|
+
/** Whether a magnitude fits a uint64 — used by the conversions. */
|
|
53
|
+
export function fitsUint(value) {
|
|
54
|
+
return value >= 0n && value < MAX_UINT_PLUS_ONE;
|
|
55
|
+
}
|
|
56
|
+
export function fitsInt(value) {
|
|
57
|
+
return value >= MIN_INT && value <= MAX_INT;
|
|
58
|
+
}
|