@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.
Files changed (223) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +281 -2
  3. package/dist/activation.d.ts +27 -0
  4. package/dist/activation.d.ts.map +1 -0
  5. package/dist/activation.js +24 -0
  6. package/dist/backend-runtime.d.ts +146 -0
  7. package/dist/backend-runtime.d.ts.map +1 -0
  8. package/dist/backend-runtime.js +322 -0
  9. package/dist/bounded-cache.d.ts +21 -0
  10. package/dist/bounded-cache.d.ts.map +1 -0
  11. package/dist/bounded-cache.js +42 -0
  12. package/dist/catalog-runtime.d.ts +59 -0
  13. package/dist/catalog-runtime.d.ts.map +1 -0
  14. package/dist/catalog-runtime.js +785 -0
  15. package/dist/cel-expression.d.ts +32 -0
  16. package/dist/cel-expression.d.ts.map +1 -0
  17. package/dist/cel-expression.js +29 -0
  18. package/dist/cel-map-value.d.ts +34 -0
  19. package/dist/cel-map-value.d.ts.map +1 -0
  20. package/dist/cel-map-value.js +74 -0
  21. package/dist/cel-program.d.ts +44 -0
  22. package/dist/cel-program.d.ts.map +1 -0
  23. package/dist/cel-program.js +72 -0
  24. package/dist/cel-type.d.ts +131 -0
  25. package/dist/cel-type.d.ts.map +1 -0
  26. package/dist/cel-type.js +293 -0
  27. package/dist/cel-value.d.ts +159 -0
  28. package/dist/cel-value.d.ts.map +1 -0
  29. package/dist/cel-value.js +225 -0
  30. package/dist/check-diagnostic.d.ts +53 -0
  31. package/dist/check-diagnostic.d.ts.map +1 -0
  32. package/dist/check-diagnostic.js +66 -0
  33. package/dist/checker.d.ts +77 -0
  34. package/dist/checker.d.ts.map +1 -0
  35. package/dist/checker.js +721 -0
  36. package/dist/closure-backend.d.ts +21 -0
  37. package/dist/closure-backend.d.ts.map +1 -0
  38. package/dist/closure-backend.js +436 -0
  39. package/dist/comprehension-bindings.d.ts +33 -0
  40. package/dist/comprehension-bindings.d.ts.map +1 -0
  41. package/dist/comprehension-bindings.js +50 -0
  42. package/dist/comprehension-runtime.d.ts +44 -0
  43. package/dist/comprehension-runtime.d.ts.map +1 -0
  44. package/dist/comprehension-runtime.js +137 -0
  45. package/dist/declared-chain.d.ts +35 -0
  46. package/dist/declared-chain.d.ts.map +1 -0
  47. package/dist/declared-chain.js +36 -0
  48. package/dist/duration-value.d.ts +59 -0
  49. package/dist/duration-value.d.ts.map +1 -0
  50. package/dist/duration-value.js +135 -0
  51. package/dist/emitted-module.d.ts +207 -0
  52. package/dist/emitted-module.d.ts.map +1 -0
  53. package/dist/emitted-module.js +359 -0
  54. package/dist/engine-version.d.ts +3 -0
  55. package/dist/engine-version.d.ts.map +1 -0
  56. package/dist/engine-version.js +8 -0
  57. package/dist/environment-digest.d.ts +44 -0
  58. package/dist/environment-digest.d.ts.map +1 -0
  59. package/dist/environment-digest.js +98 -0
  60. package/dist/environment.d.ts +283 -0
  61. package/dist/environment.d.ts.map +1 -0
  62. package/dist/environment.js +459 -0
  63. package/dist/function-catalog.d.ts +66 -0
  64. package/dist/function-catalog.d.ts.map +1 -0
  65. package/dist/function-catalog.js +77 -0
  66. package/dist/function-registry.d.ts +78 -0
  67. package/dist/function-registry.d.ts.map +1 -0
  68. package/dist/function-registry.js +189 -0
  69. package/dist/index.d.ts +91 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +59 -0
  72. package/dist/integer-arithmetic.d.ts +27 -0
  73. package/dist/integer-arithmetic.d.ts.map +1 -0
  74. package/dist/integer-arithmetic.js +58 -0
  75. package/dist/js-emitter.d.ts +132 -0
  76. package/dist/js-emitter.d.ts.map +1 -0
  77. package/dist/js-emitter.js +562 -0
  78. package/dist/json-schema-type.d.ts +182 -0
  79. package/dist/json-schema-type.d.ts.map +1 -0
  80. package/dist/json-schema-type.js +487 -0
  81. package/dist/json-text-scan.d.ts +28 -0
  82. package/dist/json-text-scan.d.ts.map +1 -0
  83. package/dist/json-text-scan.js +159 -0
  84. package/dist/lexer.d.ts +103 -0
  85. package/dist/lexer.d.ts.map +1 -0
  86. package/dist/lexer.js +458 -0
  87. package/dist/macro-check.d.ts +33 -0
  88. package/dist/macro-check.d.ts.map +1 -0
  89. package/dist/macro-check.js +162 -0
  90. package/dist/macro-shape.d.ts +24 -0
  91. package/dist/macro-shape.d.ts.map +1 -0
  92. package/dist/macro-shape.js +55 -0
  93. package/dist/member-read.d.ts +52 -0
  94. package/dist/member-read.d.ts.map +1 -0
  95. package/dist/member-read.js +125 -0
  96. package/dist/namespace-resolution.d.ts +35 -0
  97. package/dist/namespace-resolution.d.ts.map +1 -0
  98. package/dist/namespace-resolution.js +160 -0
  99. package/dist/nominal-type.d.ts +63 -0
  100. package/dist/nominal-type.d.ts.map +1 -0
  101. package/dist/nominal-type.js +98 -0
  102. package/dist/nullable-access.d.ts +38 -0
  103. package/dist/nullable-access.d.ts.map +1 -0
  104. package/dist/nullable-access.js +93 -0
  105. package/dist/parse-limits.d.ts +26 -0
  106. package/dist/parse-limits.d.ts.map +1 -0
  107. package/dist/parse-limits.js +21 -0
  108. package/dist/parser.d.ts +48 -0
  109. package/dist/parser.d.ts.map +1 -0
  110. package/dist/parser.js +503 -0
  111. package/dist/qualified-calls.d.ts +22 -0
  112. package/dist/qualified-calls.d.ts.map +1 -0
  113. package/dist/qualified-calls.js +27 -0
  114. package/dist/regular-expression.d.ts +48 -0
  115. package/dist/regular-expression.d.ts.map +1 -0
  116. package/dist/regular-expression.js +77 -0
  117. package/dist/reserved-words.d.ts +52 -0
  118. package/dist/reserved-words.d.ts.map +1 -0
  119. package/dist/reserved-words.js +77 -0
  120. package/dist/resolved-call.d.ts +33 -0
  121. package/dist/resolved-call.d.ts.map +1 -0
  122. package/dist/resolved-call.js +15 -0
  123. package/dist/root-references.d.ts +23 -0
  124. package/dist/root-references.d.ts.map +1 -0
  125. package/dist/root-references.js +120 -0
  126. package/dist/runtime-library.d.ts +56 -0
  127. package/dist/runtime-library.d.ts.map +1 -0
  128. package/dist/runtime-library.js +545 -0
  129. package/dist/serializer.d.ts +24 -0
  130. package/dist/serializer.d.ts.map +1 -0
  131. package/dist/serializer.js +240 -0
  132. package/dist/sha256.d.ts +20 -0
  133. package/dist/sha256.d.ts.map +1 -0
  134. package/dist/sha256.js +103 -0
  135. package/dist/signature.d.ts +72 -0
  136. package/dist/signature.d.ts.map +1 -0
  137. package/dist/signature.js +61 -0
  138. package/dist/signatures/function-catalog.json +788 -0
  139. package/dist/signatures/standard-library.json +229 -0
  140. package/dist/standard-library.d.ts +41 -0
  141. package/dist/standard-library.d.ts.map +1 -0
  142. package/dist/standard-library.js +85 -0
  143. package/dist/syntax-diagnostic.d.ts +61 -0
  144. package/dist/syntax-diagnostic.d.ts.map +1 -0
  145. package/dist/syntax-diagnostic.js +28 -0
  146. package/dist/syntax-tree.d.ts +160 -0
  147. package/dist/syntax-tree.d.ts.map +1 -0
  148. package/dist/syntax-tree.js +58 -0
  149. package/dist/timestamp-value.d.ts +53 -0
  150. package/dist/timestamp-value.d.ts.map +1 -0
  151. package/dist/timestamp-value.js +223 -0
  152. package/dist/tree-equality.d.ts +15 -0
  153. package/dist/tree-equality.d.ts.map +1 -0
  154. package/dist/tree-equality.js +105 -0
  155. package/dist/type-expression.d.ts +26 -0
  156. package/dist/type-expression.d.ts.map +1 -0
  157. package/dist/type-expression.js +134 -0
  158. package/dist/value-equality.d.ts +38 -0
  159. package/dist/value-equality.d.ts.map +1 -0
  160. package/dist/value-equality.js +196 -0
  161. package/dist/value-text.d.ts +25 -0
  162. package/dist/value-text.d.ts.map +1 -0
  163. package/dist/value-text.js +44 -0
  164. package/dist/zoned-calendar.d.ts +61 -0
  165. package/dist/zoned-calendar.d.ts.map +1 -0
  166. package/dist/zoned-calendar.js +143 -0
  167. package/package.json +56 -3
  168. package/src/activation.ts +32 -0
  169. package/src/backend-runtime.ts +454 -0
  170. package/src/bounded-cache.ts +45 -0
  171. package/src/catalog-runtime.ts +921 -0
  172. package/src/cel-expression.ts +53 -0
  173. package/src/cel-map-value.ts +86 -0
  174. package/src/cel-program.ts +103 -0
  175. package/src/cel-type.ts +359 -0
  176. package/src/cel-value.ts +353 -0
  177. package/src/check-diagnostic.ts +102 -0
  178. package/src/checker.ts +932 -0
  179. package/src/closure-backend.ts +502 -0
  180. package/src/comprehension-bindings.ts +66 -0
  181. package/src/comprehension-runtime.ts +157 -0
  182. package/src/declared-chain.ts +45 -0
  183. package/src/duration-value.ts +145 -0
  184. package/src/emitted-module.ts +494 -0
  185. package/src/engine-version.ts +9 -0
  186. package/src/environment-digest.ts +111 -0
  187. package/src/environment.ts +740 -0
  188. package/src/function-catalog.ts +140 -0
  189. package/src/function-registry.ts +229 -0
  190. package/src/index.ts +386 -0
  191. package/src/integer-arithmetic.ts +64 -0
  192. package/src/js-emitter.ts +713 -0
  193. package/src/json-schema-type.ts +664 -0
  194. package/src/json-text-scan.ts +163 -0
  195. package/src/lexer.ts +562 -0
  196. package/src/macro-check.ts +191 -0
  197. package/src/macro-shape.ts +66 -0
  198. package/src/member-read.ts +126 -0
  199. package/src/namespace-resolution.ts +167 -0
  200. package/src/nominal-type.ts +149 -0
  201. package/src/nullable-access.ts +95 -0
  202. package/src/parse-limits.ts +36 -0
  203. package/src/parser.ts +554 -0
  204. package/src/qualified-calls.ts +39 -0
  205. package/src/regular-expression.ts +101 -0
  206. package/src/reserved-words.ts +94 -0
  207. package/src/resolved-call.ts +34 -0
  208. package/src/root-references.ts +126 -0
  209. package/src/runtime-library.ts +615 -0
  210. package/src/serializer.ts +246 -0
  211. package/src/sha256.ts +112 -0
  212. package/src/signature.ts +127 -0
  213. package/src/signatures/function-catalog.json +788 -0
  214. package/src/signatures/standard-library.json +235 -0
  215. package/src/standard-library.ts +149 -0
  216. package/src/syntax-diagnostic.ts +72 -0
  217. package/src/syntax-tree.ts +229 -0
  218. package/src/timestamp-value.ts +294 -0
  219. package/src/tree-equality.ts +130 -0
  220. package/src/type-expression.ts +160 -0
  221. package/src/value-equality.ts +201 -0
  222. package/src/value-text.ts +45 -0
  223. package/src/zoned-calendar.ts +178 -0
@@ -0,0 +1,32 @@
1
+ /**
2
+ * One CEL expression, read and resolved.
3
+ *
4
+ * This is the front end's whole answer: the source as written, the canonical tree,
5
+ * the namespace set the tree was resolved under, and at most one syntax diagnostic.
6
+ * **Every expression this module hands out is already resolved** — there is no way
7
+ * to obtain an unresolved tree and then forget to resolve it, and `namespaces`
8
+ * records what it was resolved under so a consumer checking it against a different
9
+ * set can refuse rather than quietly answer the wrong question.
10
+ *
11
+ * Reading an expression never throws: a source it cannot read gives a tree for the
12
+ * longest prefix it could, plus the diagnostic saying where it stopped.
13
+ */
14
+ import type { ParseOptions } from "./parser.js";
15
+ import type { CelSyntaxDiagnostic } from "./syntax-diagnostic.js";
16
+ import type { CelNode } from "./syntax-tree.js";
17
+ export interface CelExpression {
18
+ readonly source: string;
19
+ readonly root: CelNode;
20
+ /** The namespace set the tree was resolved under, in canonical order. */
21
+ readonly namespaces: readonly string[];
22
+ /** At most one entry; one exactly when the source could not be read whole. */
23
+ readonly diagnostics: readonly CelSyntaxDiagnostic[];
24
+ }
25
+ export interface ParseExpressionOptions extends ParseOptions {
26
+ /** The names that denote namespaces rather than values at this site. */
27
+ readonly namespaces?: Iterable<string>;
28
+ }
29
+ export declare function parseExpression(source: string, options?: ParseExpressionOptions): CelExpression;
30
+ /** Whether the expression was resolved under exactly these namespaces. */
31
+ export declare function resolvedUnder(expression: CelExpression, namespaces: Iterable<string>): boolean;
32
+ //# sourceMappingURL=cel-expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel-expression.d.ts","sourceRoot":"","sources":["../src/cel-expression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,yEAAyE;IACzE,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACtD;AAED,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D,wEAAwE;IACxE,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACxC;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,aAAa,CAS/F;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO,CAE9F"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * One CEL expression, read and resolved.
3
+ *
4
+ * This is the front end's whole answer: the source as written, the canonical tree,
5
+ * the namespace set the tree was resolved under, and at most one syntax diagnostic.
6
+ * **Every expression this module hands out is already resolved** — there is no way
7
+ * to obtain an unresolved tree and then forget to resolve it, and `namespaces`
8
+ * records what it was resolved under so a consumer checking it against a different
9
+ * set can refuse rather than quietly answer the wrong question.
10
+ *
11
+ * Reading an expression never throws: a source it cannot read gives a tree for the
12
+ * longest prefix it could, plus the diagnostic saying where it stopped.
13
+ */
14
+ import { namespaceSetsEqual, normalizeNamespaces, resolveNamespaces, } from "./namespace-resolution.js";
15
+ import { parseSyntax } from "./parser.js";
16
+ export function parseExpression(source, options) {
17
+ const namespaces = normalizeNamespaces(options?.namespaces ?? []);
18
+ const parsed = parseSyntax(source, options);
19
+ return {
20
+ source,
21
+ root: resolveNamespaces(parsed.root, namespaces),
22
+ namespaces,
23
+ diagnostics: parsed.diagnostics,
24
+ };
25
+ }
26
+ /** Whether the expression was resolved under exactly these namespaces. */
27
+ export function resolvedUnder(expression, namespaces) {
28
+ return namespaceSetsEqual(expression.namespaces, normalizeNamespaces(namespaces));
29
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Building a CEL map, and the one identity a key has.
3
+ *
4
+ * A map's entries live in a `Map` keyed by the **canonical text** of each key, never by
5
+ * a property name. Two consequences, both load-bearing:
6
+ *
7
+ * - A map holds CEL's four key types (int, uint, bool, string) in one container, and an
8
+ * int key and a uint key of the same number are **one** key, because CEL equality
9
+ * makes them equal — so a literal writing both is a duplicate rather than two entries.
10
+ * - Nothing a key spells can reach a prototype, a method or an inherited member. A map
11
+ * built from `{'__proto__': 1}` holds `__proto__` as data and reads it back as data;
12
+ * dropping such a key would be swallowing what the author wrote.
13
+ */
14
+ import type { CelMap, CelMapValueEntry, CelValue } from "./cel-value.js";
15
+ import { type CelError } from "./cel-value.js";
16
+ import type { SourceRange } from "./syntax-tree.js";
17
+ /**
18
+ * The text that identifies a key. `n` covers the numeric types together: CEL equality
19
+ * makes `1`, `1u` and `1.0` one key, so a map carrying two of them is not a map and a
20
+ * lookup by any of the three finds the entry — which is what
21
+ * `{1u: 1.0, 2: 2.0, 3u: 3.0}[?3.0]` reads. A double that is not whole identifies
22
+ * nothing, since no entry can hold it.
23
+ */
24
+ export declare function mapKeyIdentity(key: CelValue): string | undefined;
25
+ /** An empty map, for a literal with no entries. */
26
+ export declare function celMapOf(entries: ReadonlyMap<string, CelMapValueEntry>): CelMap;
27
+ /**
28
+ * A map from its entries in written order, or the error that stops it: a key of a type
29
+ * no map is keyed by, or two keys CEL equality makes one.
30
+ */
31
+ export declare function celMapFromEntries(pairs: readonly (readonly [CelValue, CelValue])[], range?: SourceRange): CelMap | CelError;
32
+ /** Every key of a map, in insertion order — what a comprehension ranges over. */
33
+ export declare function celMapKeys(map: CelMap): CelValue[];
34
+ //# sourceMappingURL=cel-map-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel-map-value.d.ts","sourceRoot":"","sources":["../src/cel-map-value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAOhE;AAED,mDAAmD;AACnD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,MAAM,CAE/E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,EACjD,KAAK,CAAC,EAAE,WAAW,GAClB,MAAM,GAAG,QAAQ,CAsBnB;AAQD,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,EAAE,CAElD"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Building a CEL map, and the one identity a key has.
3
+ *
4
+ * A map's entries live in a `Map` keyed by the **canonical text** of each key, never by
5
+ * a property name. Two consequences, both load-bearing:
6
+ *
7
+ * - A map holds CEL's four key types (int, uint, bool, string) in one container, and an
8
+ * int key and a uint key of the same number are **one** key, because CEL equality
9
+ * makes them equal — so a literal writing both is a duplicate rather than two entries.
10
+ * - Nothing a key spells can reach a prototype, a method or an inherited member. A map
11
+ * built from `{'__proto__': 1}` holds `__proto__` as data and reads it back as data;
12
+ * dropping such a key would be swallowing what the author wrote.
13
+ */
14
+ import { CEL_VALUE_TYPE, celError, isCelError, isCelUint, } from "./cel-value.js";
15
+ /**
16
+ * The text that identifies a key. `n` covers the numeric types together: CEL equality
17
+ * makes `1`, `1u` and `1.0` one key, so a map carrying two of them is not a map and a
18
+ * lookup by any of the three finds the entry — which is what
19
+ * `{1u: 1.0, 2: 2.0, 3u: 3.0}[?3.0]` reads. A double that is not whole identifies
20
+ * nothing, since no entry can hold it.
21
+ */
22
+ export function mapKeyIdentity(key) {
23
+ if (typeof key === "string")
24
+ return `s${key}`;
25
+ if (typeof key === "boolean")
26
+ return `b${key}`;
27
+ if (typeof key === "bigint")
28
+ return `n${key}`;
29
+ if (isCelUint(key))
30
+ return `n${key.value}`;
31
+ if (typeof key === "number" && Number.isInteger(key))
32
+ return `n${BigInt(key)}`;
33
+ return undefined;
34
+ }
35
+ /** An empty map, for a literal with no entries. */
36
+ export function celMapOf(entries) {
37
+ return { [CEL_VALUE_TYPE]: "map", entries };
38
+ }
39
+ /**
40
+ * A map from its entries in written order, or the error that stops it: a key of a type
41
+ * no map is keyed by, or two keys CEL equality makes one.
42
+ */
43
+ export function celMapFromEntries(pairs, range) {
44
+ const entries = new Map();
45
+ for (const [key, value] of pairs) {
46
+ if (isCelError(key))
47
+ return key;
48
+ if (isCelError(value))
49
+ return value;
50
+ // A map is **built** with an int, uint, bool or string key: a double is not a key
51
+ // type, even one that is whole. It still LOOKS one up, because `{1u: …}[?1.0]` reads
52
+ // the entry — equality across the numeric types holds for a key as for a value.
53
+ const identity = typeof key === "number" ? undefined : mapKeyIdentity(key);
54
+ if (identity === undefined) {
55
+ return celError("unsupported_key_type", "a map is keyed by an int, a uint, a bool or a string", range);
56
+ }
57
+ if (entries.has(identity)) {
58
+ return celError("duplicate_map_key", `the key ${describeKey(key)} is written twice`, range);
59
+ }
60
+ entries.set(identity, { key, value });
61
+ }
62
+ return celMapOf(entries);
63
+ }
64
+ function describeKey(key) {
65
+ if (typeof key === "string")
66
+ return JSON.stringify(key);
67
+ if (isCelUint(key))
68
+ return `${key.value}u`;
69
+ return String(key);
70
+ }
71
+ /** Every key of a map, in insertion order — what a comprehension ranges over. */
72
+ export function celMapKeys(map) {
73
+ return [...map.entries.values()].map((entry) => entry.key);
74
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A compiled expression, and what happens at the top of an evaluation.
3
+ *
4
+ * An error is a **value** throughout evaluation, so that `false && <missing key>` is
5
+ * `false`. At the top there is nothing left to short-circuit, so a surviving error
6
+ * becomes a thrown failure carrying its code — the one place the engine throws about an
7
+ * expression's own data, and the only form a caller can be expected to handle.
8
+ */
9
+ import type { CelActivation } from "./activation.js";
10
+ import type { CelStep, CompileTarget, NamespaceDispatch } from "./backend-runtime.js";
11
+ import type { CelEvaluationCode, CelValue } from "./cel-value.js";
12
+ import type { CelExpression } from "./cel-expression.js";
13
+ import type { SourceRange } from "./syntax-tree.js";
14
+ /** A failure an evaluation could not carry any further. */
15
+ export declare class CelEvaluationError extends Error {
16
+ readonly code: CelEvaluationCode;
17
+ readonly range?: SourceRange;
18
+ constructor(code: CelEvaluationCode, message: string, range?: SourceRange);
19
+ }
20
+ export interface EvaluateOptions {
21
+ /**
22
+ * What a namespaced call (`Alias.fn(x)`) is dispatched through. A host binds it per
23
+ * evaluation, because which functions a scope reaches is the host's own question; a
24
+ * call nothing binds is `unbound_function`.
25
+ */
26
+ readonly namespaceFunction?: NamespaceDispatch;
27
+ }
28
+ export interface CelProgram {
29
+ readonly source: string;
30
+ /** The value, or a throw carrying the code of the error that survived to the top. */
31
+ evaluate(activation?: CelActivation, options?: EvaluateOptions): CelValue;
32
+ /** The value or the error value, for a caller that carries errors itself. */
33
+ evaluateToValue(activation?: CelActivation, options?: EvaluateOptions): CelValue;
34
+ }
35
+ export declare function compileExpression(expression: CelExpression, target: CompileTarget): CelProgram;
36
+ /**
37
+ * A program over a step a backend already built — what an emitted module's function
38
+ * becomes. The top of an evaluation is the same either way: the thenable backstop, and a
39
+ * surviving error turning into a throw. A second implementation of that top would be a
40
+ * second answer to "what does a caller see", which is the one thing two backends may not
41
+ * disagree about.
42
+ */
43
+ export declare function programOfStep(source: string, step: CelStep, slots?: number): CelProgram;
44
+ //# sourceMappingURL=cel-program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel-program.d.ts","sourceRoot":"","sources":["../src/cel-program.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,KAAK,EAAY,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,2DAA2D;AAC3D,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;gBAEjB,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW;CAM1E;AAED,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CAChD;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAC;IAC1E,6EAA6E;IAC7E,eAAe,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAC;CAClF;AAeD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,GAAG,UAAU,CAG9F;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,UAAU,CAElF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * A compiled expression, and what happens at the top of an evaluation.
3
+ *
4
+ * An error is a **value** throughout evaluation, so that `false && <missing key>` is
5
+ * `false`. At the top there is nothing left to short-circuit, so a surviving error
6
+ * becomes a thrown failure carrying its code — the one place the engine throws about an
7
+ * expression's own data, and the only form a caller can be expected to handle.
8
+ */
9
+ import { compileTree } from "./closure-backend.js";
10
+ import { celError, isCelError, isThenable } from "./cel-value.js";
11
+ /** A failure an evaluation could not carry any further. */
12
+ export class CelEvaluationError extends Error {
13
+ code;
14
+ range;
15
+ constructor(code, message, range) {
16
+ super(message);
17
+ this.name = "CelEvaluationError";
18
+ this.code = code;
19
+ if (range)
20
+ this.range = range;
21
+ }
22
+ }
23
+ /** The refusal a thenable surviving to the top is, spanning the whole expression. */
24
+ function asyncRefused(source) {
25
+ return celError("async_value_unsupported", "a value that must be awaited reached evaluation, and CEL evaluates synchronously", [0, source.length]);
26
+ }
27
+ const NO_ACTIVATION = Object.freeze(Object.create(null));
28
+ /** A frame that binds nothing needs no slots, and allocating none is measurable. */
29
+ const NO_SLOTS = [];
30
+ export function compileExpression(expression, target) {
31
+ const compiled = compileTree(expression.root, target);
32
+ return new Program(expression.source, compiled.step, compiled.slots);
33
+ }
34
+ /**
35
+ * A program over a step a backend already built — what an emitted module's function
36
+ * becomes. The top of an evaluation is the same either way: the thenable backstop, and a
37
+ * surviving error turning into a throw. A second implementation of that top would be a
38
+ * second answer to "what does a caller see", which is the one thing two backends may not
39
+ * disagree about.
40
+ */
41
+ export function programOfStep(source, step, slots = 0) {
42
+ return new Program(source, step, slots);
43
+ }
44
+ class Program {
45
+ source;
46
+ step;
47
+ slots;
48
+ constructor(source, step, slots) {
49
+ this.source = source;
50
+ this.step = step;
51
+ this.slots = slots;
52
+ }
53
+ evaluateToValue(activation = NO_ACTIVATION, options = {}) {
54
+ // One shape, every time: a frame built two ways is two shapes, and every step that
55
+ // reads one would see both.
56
+ const value = this.step({
57
+ activation,
58
+ slots: this.slots === 0 ? NO_SLOTS : new Array(this.slots),
59
+ namespaceFunction: options.namespaceFunction,
60
+ });
61
+ // The backstop, one check per evaluation: every door refuses a thenable where the value
62
+ // enters, and this is what catches a door nobody has thought of yet rather than handing a
63
+ // promise to a caller as though it were a value.
64
+ return isThenable(value) ? asyncRefused(this.source) : value;
65
+ }
66
+ evaluate(activation, options) {
67
+ const value = this.evaluateToValue(activation, options);
68
+ if (isCelError(value))
69
+ throw new CelEvaluationError(value.code, value.message, value.range);
70
+ return value;
71
+ }
72
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * CEL's types.
3
+ *
4
+ * The domain is deliberately richer than the one an expression can spell, because
5
+ * the checker's whole value is in what it can be *told*: a variable typed from a
6
+ * JSON Schema carries its nested objects, its element types and its unions, and a
7
+ * typo two levels down is then a type error rather than something only a running
8
+ * request discovers.
9
+ *
10
+ * Four shapes exist for that reason and have no syntax of their own:
11
+ *
12
+ * - `record` — an object with named fields, each typed in turn; `open` says whether
13
+ * a field it does not declare is unjudged (a schema with no `properties`) or
14
+ * undeclared (a closed schema).
15
+ * - `union` — carried as a union rather than collapsed to `dyn`, so `int|null` keeps
16
+ * both the arithmetic and the null that makes a dereference worth reporting.
17
+ * - `nominal` — a named type over a base, with invariant arguments: the mechanism a
18
+ * host registers its own vocabulary through. **A nominal is not its base**: it
19
+ * accepts only what is registered for it, which is what makes a slot expecting one
20
+ * refuse a plain value of the base. (The vectors pin this: an operator the base
21
+ * accepts is refused on the named type.)
22
+ * - `parameter` — a type variable in a signature, unified per call and invariant.
23
+ *
24
+ * `dyn` is the top: it is assignable both ways, which is what keeps an unlisted
25
+ * variable or an unknown call result from cascading into a second error.
26
+ */
27
+ export type PrimitiveName = "int" | "uint" | "double" | "bool" | "string" | "bytes" | "null" | "type" | "timestamp" | "duration";
28
+ export interface DynType {
29
+ readonly kind: "dyn";
30
+ }
31
+ export interface PrimitiveType {
32
+ readonly kind: "primitive";
33
+ readonly name: PrimitiveName;
34
+ }
35
+ export interface ListType {
36
+ readonly kind: "list";
37
+ readonly element: CelType;
38
+ }
39
+ export interface MapType {
40
+ readonly kind: "map";
41
+ readonly key: CelType;
42
+ readonly value: CelType;
43
+ }
44
+ export interface OptionalType {
45
+ readonly kind: "optional";
46
+ readonly value: CelType;
47
+ }
48
+ export interface RecordType {
49
+ readonly kind: "record";
50
+ readonly name?: string;
51
+ readonly fields: ReadonlyMap<string, CelType>;
52
+ /** A field the record does not declare is unjudged when open, undeclared when closed. */
53
+ readonly open: boolean;
54
+ }
55
+ export interface UnionType {
56
+ readonly kind: "union";
57
+ readonly members: readonly CelType[];
58
+ }
59
+ export interface NominalType {
60
+ readonly kind: "nominal";
61
+ readonly name: string;
62
+ readonly base: CelType;
63
+ readonly args: readonly CelType[];
64
+ }
65
+ export interface ParameterType {
66
+ readonly kind: "parameter";
67
+ readonly name: string;
68
+ }
69
+ export type CelType = DynType | PrimitiveType | ListType | MapType | OptionalType | RecordType | UnionType | NominalType | ParameterType;
70
+ export declare const DYN: DynType;
71
+ export declare const INT: PrimitiveType;
72
+ export declare const UINT: PrimitiveType;
73
+ export declare const DOUBLE: PrimitiveType;
74
+ export declare const BOOL: PrimitiveType;
75
+ export declare const STRING: PrimitiveType;
76
+ export declare const BYTES: PrimitiveType;
77
+ export declare const NULL: PrimitiveType;
78
+ export declare const TYPE: PrimitiveType;
79
+ export declare const TIMESTAMP: PrimitiveType;
80
+ export declare const DURATION: PrimitiveType;
81
+ export declare const listOf: (element: CelType) => ListType;
82
+ export declare const mapOf: (key: CelType, value: CelType) => MapType;
83
+ export declare const optionalOf: (value: CelType) => OptionalType;
84
+ export declare const parameterOf: (name: string) => ParameterType;
85
+ /** A union of its distinct members; one member is that member, none is `dyn`. */
86
+ export declare function unionOf(members: readonly CelType[]): CelType;
87
+ /** The names the timestamp and duration types are written and printed under. */
88
+ export declare const WELL_KNOWN_TYPE_NAMES: Readonly<Record<string, PrimitiveName>>;
89
+ export declare function isDyn(type: CelType): boolean;
90
+ export declare function typesEqual(left: CelType, right: CelType): boolean;
91
+ /**
92
+ * How a type is written. `top` collapses a list or map of `dyn` to its bare name,
93
+ * which is how the whole type of an expression is reported.
94
+ */
95
+ export declare function formatType(type: CelType, top?: boolean): string;
96
+ export declare function isNumeric(type: CelType): boolean;
97
+ /**
98
+ * The type with every unresolved type parameter replaced by `dyn` — the last step before a
99
+ * type is REPORTED.
100
+ *
101
+ * cel-spec's rule is that an unresolved parameter behaves as `dyn` wherever it is used, and
102
+ * the type handed out is a use like any other: a consumer that reads `list<T>` has to know
103
+ * what `T` means to this engine, and the answer is "nothing — it was never resolved". A
104
+ * parameter survives only where it is DECLARED: a signature's text, a nominal type's
105
+ * parameter list.
106
+ */
107
+ export declare function withoutParameters(type: CelType): CelType;
108
+ /** Whether `type` admits a null value — a null, or a union holding one. */
109
+ export declare function admitsNull(type: CelType): boolean;
110
+ /** The type with every null taken out of it; `dyn` and a bare null are unchanged. */
111
+ export declare function withoutNull(type: CelType): CelType;
112
+ /**
113
+ * Whether a value of `from` may stand where `to` is wanted.
114
+ *
115
+ * `dyn` passes both ways; a nominal type accepts only itself (its base is a
116
+ * different type); a union passes where every member does, and accepts a value any
117
+ * member accepts. Numeric types do **not** convert implicitly — CEL's cross-type
118
+ * arithmetic and comparison are declared overloads, not coercions.
119
+ */
120
+ export declare function assignable(from: CelType, to: CelType): boolean;
121
+ /**
122
+ * The one type both arms can be. Unlike assignability this is symmetric, and it is
123
+ * what an aggregate literal's elements and a ternary's branches are reduced through:
124
+ * nothing in common is `dyn`, which is CEL's own reading of a heterogeneous literal.
125
+ *
126
+ * **An unresolved parameter yields to the other side**, so the element type of
127
+ * `[[[[]]]], [], [[[]]]]` is the deepest list rather than `dyn`: an empty aggregate
128
+ * says nothing about its elements and must not erase what a sibling does say.
129
+ */
130
+ export declare function unify(left: CelType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