@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
package/src/index.ts ADDED
@@ -0,0 +1,386 @@
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
+
14
+ export { parseExpression, resolvedUnder } from "./cel-expression.js";
15
+ export type { CelExpression, ParseExpressionOptions } from "./cel-expression.js";
16
+
17
+ export { MAX_INT, MAX_UINT, MIN_INT } from "./lexer.js";
18
+
19
+ export {
20
+ CelNamespaceError,
21
+ namespaceSetsEqual,
22
+ normalizeNamespaces,
23
+ RESERVED_NAMESPACES,
24
+ resolveNamespaces,
25
+ } from "./namespace-resolution.js";
26
+
27
+ export { DEFAULT_PARSE_LIMITS, resolveParseLimits } from "./parse-limits.js";
28
+ export type { CelParseLimits } from "./parse-limits.js";
29
+
30
+ export { parseSyntax } from "./parser.js";
31
+ export type { ParseOptions, ParseResult } from "./parser.js";
32
+
33
+ export { qualifiedCalls } from "./qualified-calls.js";
34
+ export type { QualifiedCall } from "./qualified-calls.js";
35
+
36
+ export {
37
+ isIdentifierSpelling,
38
+ isReservedWord,
39
+ LITERAL_WORDS,
40
+ OPERATOR_WORDS,
41
+ RESERVED_WORDS,
42
+ } from "./reserved-words.js";
43
+
44
+ export { rootReferences } from "./root-references.js";
45
+
46
+ export { splitDeclaredChain } from "./declared-chain.js";
47
+ export type { DeclaredChain } from "./declared-chain.js";
48
+
49
+ export { CelSerializeError, serializeTree } from "./serializer.js";
50
+
51
+ export type { CelSyntaxCode, CelSyntaxDiagnostic } from "./syntax-diagnostic.js";
52
+
53
+ export { childNodes, hasUnparsed, walkTree } from "./syntax-tree.js";
54
+ export type {
55
+ CelBinaryNode,
56
+ CelBinaryOperator,
57
+ CelCallNode,
58
+ CelConditionalNode,
59
+ CelIdentNode,
60
+ CelIndexNode,
61
+ CelListNode,
62
+ CelLiteral,
63
+ CelLiteralNode,
64
+ CelMapEntry,
65
+ CelMapNode,
66
+ CelNode,
67
+ CelQualifiedCallNode,
68
+ CelReceiverCallNode,
69
+ CelSelectNode,
70
+ CelUnaryNode,
71
+ CelUnaryOperator,
72
+ CelUnparsedNode,
73
+ SourceRange,
74
+ } from "./syntax-tree.js";
75
+
76
+ export { treesEqual } from "./tree-equality.js";
77
+
78
+ // --- the type system, the registry and the checker -------------------------
79
+
80
+ export {
81
+ admitsNull,
82
+ assignable,
83
+ BOOL,
84
+ BYTES,
85
+ DOUBLE,
86
+ DURATION,
87
+ DYN,
88
+ formatType,
89
+ INT,
90
+ isDyn,
91
+ isNumeric,
92
+ listOf,
93
+ mapOf,
94
+ NULL,
95
+ optionalOf,
96
+ parameterOf,
97
+ STRING,
98
+ TIMESTAMP,
99
+ TYPE,
100
+ typesEqual,
101
+ UINT,
102
+ unify,
103
+ unionOf,
104
+ WELL_KNOWN_TYPE_NAMES,
105
+ withoutNull,
106
+ withoutParameters,
107
+ } from "./cel-type.js";
108
+ export type {
109
+ CelType,
110
+ DynType,
111
+ ListType,
112
+ MapType,
113
+ NominalType,
114
+ OptionalType,
115
+ ParameterType,
116
+ PrimitiveName,
117
+ PrimitiveType,
118
+ RecordType,
119
+ UnionType,
120
+ } from "./cel-type.js";
121
+
122
+ export { CEL_CHECK_CODES, CelEngineError } from "./check-diagnostic.js";
123
+ export type {
124
+ CelCheckCode,
125
+ CelCheckDiagnostic,
126
+ CelDiagnosticFix,
127
+ CelEngineErrorCode,
128
+ } from "./check-diagnostic.js";
129
+
130
+ export type { CheckResult, NamespaceFunction } from "./checker.js";
131
+
132
+ export { CelEnvironment, DEFAULT_COMPILED_CACHE_CAPACITY } from "./environment.js";
133
+ export type {
134
+ CelEnvironmentOptions,
135
+ Definitions,
136
+ FunctionDefinition,
137
+ NamespaceFunctionDeclaration,
138
+ NamespaceListing,
139
+ NamespaceOptions,
140
+ SchemaRegistrationReport,
141
+ TypeDeclaration,
142
+ TypeDefinitionListing,
143
+ VariableDefinition,
144
+ } from "./environment.js";
145
+
146
+ export { FunctionRegistry } from "./function-registry.js";
147
+ export type { RegisteredFunction, Resolution, ResolutionFailure } from "./function-registry.js";
148
+
149
+ export {
150
+ fieldMapType,
151
+ schemaType,
152
+ TYPE_CONSTRAINING_KEYWORDS,
153
+ TYPE_KEYWORDS_READ,
154
+ UNJUDGED_REASONS,
155
+ } from "./json-schema-type.js";
156
+ export type {
157
+ FieldDeclaration,
158
+ JsonSchemaDocument,
159
+ JsonSchemaNode,
160
+ NamedTypeLookup,
161
+ RecursiveSchemaReference,
162
+ SchemaConversion,
163
+ SchemaTypeAnswer,
164
+ SchemaTypeResolver,
165
+ SchemaTypeResult,
166
+ UnjudgedReason,
167
+ UnjudgedSchemaNode,
168
+ } from "./json-schema-type.js";
169
+
170
+ export { CelTypeRegistrationError } from "./nominal-type.js";
171
+ export type {
172
+ NominalOperatorDeclaration,
173
+ NominalTypeDefinition,
174
+ RegisteredType,
175
+ } from "./nominal-type.js";
176
+
177
+ export type { ResolvedCall } from "./resolved-call.js";
178
+
179
+ export { formatSignature, parseSignature, signatureKey } from "./signature.js";
180
+ export type {
181
+ CallForm,
182
+ CelSignature,
183
+ FunctionMetadata,
184
+ LiteralArgumentCheck,
185
+ } from "./signature.js";
186
+
187
+ export {
188
+ googleTypeNames,
189
+ registerStandardLibrary,
190
+ standardConstants,
191
+ STANDARD_LIBRARY_GENERATION,
192
+ standardLibrarySignatures,
193
+ } from "./standard-library.js";
194
+ export type { StandardConstant } from "./standard-library.js";
195
+
196
+ // --- the function catalog: the dialect, registered as a host registers one ------
197
+
198
+ export {
199
+ catalogCategories,
200
+ catalogSignatures,
201
+ FUNCTION_CATALOG_GENERATION,
202
+ functionCatalog,
203
+ registerFunctionCatalog,
204
+ } from "./function-catalog.js";
205
+ export type { CatalogFunction, RegisterCatalogOptions } from "./function-catalog.js";
206
+
207
+ export {
208
+ catalogGuardedNames,
209
+ catalogImplementation,
210
+ catalogImplementedKeys,
211
+ catalogLiteralCheck,
212
+ } from "./catalog-runtime.js";
213
+ export type { CatalogImplementation, CelCatalogHandlers } from "./catalog-runtime.js";
214
+
215
+ export { scanJsonPrefix } from "./json-text-scan.js";
216
+ export type { JsonRefusal } from "./json-text-scan.js";
217
+
218
+ export {
219
+ civilTimeIn,
220
+ dateTextIn,
221
+ daysInMonth,
222
+ instantOfCivilTime,
223
+ isoTextIn,
224
+ knownTimeZone,
225
+ } from "./zoned-calendar.js";
226
+ export type { CivilTime } from "./zoned-calendar.js";
227
+
228
+ export { CelTypeExpressionError, parseTypeExpression } from "./type-expression.js";
229
+ export type { NominalResolver } from "./type-expression.js";
230
+
231
+ // --- the value domain, the semantics and the closure backend ----------------
232
+
233
+ export type { CelActivation } from "./activation.js";
234
+
235
+ export { BoundedCache } from "./bounded-cache.js";
236
+
237
+ export { celMapFromEntries, celMapKeys, mapKeyIdentity } from "./cel-map-value.js";
238
+
239
+ export { CelEvaluationError, programOfStep } from "./cel-program.js";
240
+ export type { CelProgram, EvaluateOptions } from "./cel-program.js";
241
+
242
+ // --- the emitter: JavaScript source, its key, and the one store seam --------
243
+
244
+ export { ENGINE_VERSION } from "./engine-version.js";
245
+
246
+ export {
247
+ EMITTER_FORMAT_GENERATION,
248
+ emittedModuleIdentity,
249
+ emittedModuleKey,
250
+ emittedModuleRefusal,
251
+ programsFromEmittedModule,
252
+ readEmittedHeader,
253
+ } from "./emitted-module.js";
254
+ export type {
255
+ EmittedFactory,
256
+ EmittedHeader,
257
+ EmittedIdentity,
258
+ EmittedModule,
259
+ EmittedModuleStore,
260
+ EmittedRuntime,
261
+ StoredEmittedModule,
262
+ } from "./emitted-module.js";
263
+
264
+ export { environmentDigest } from "./environment-digest.js";
265
+ export type { DigestedEnvironment } from "./environment-digest.js";
266
+
267
+ /** The whole contract between an emitted module and the runtime it is handed. */
268
+ export { RUNTIME_BINDINGS } from "./js-emitter.js";
269
+ export type { RuntimeBinding } from "./js-emitter.js";
270
+
271
+ export {
272
+ CEL_EVALUATION_CODES,
273
+ CEL_VALUE_KEYS,
274
+ CEL_VALUE_TYPE,
275
+ celError,
276
+ celNone,
277
+ celSome,
278
+ celTypeNameOf,
279
+ celTypeValue,
280
+ celUint,
281
+ isCelBytes,
282
+ isCelDuration,
283
+ isCelError,
284
+ isCelMap,
285
+ isCelOptional,
286
+ isCelRecord,
287
+ isCelTimestamp,
288
+ isCelTypeValue,
289
+ isCelUint,
290
+ literalValue,
291
+ } from "./cel-value.js";
292
+ export type {
293
+ CelDuration,
294
+ CelError,
295
+ CelEvaluationCode,
296
+ CelHostValue,
297
+ CelMap,
298
+ CelMapValueEntry,
299
+ CelOptional,
300
+ CelRecord,
301
+ CelTimestamp,
302
+ CelTypeValue,
303
+ CelUint,
304
+ CelValue,
305
+ CelValueKey,
306
+ } from "./cel-value.js";
307
+
308
+ export { compileTree } from "./closure-backend.js";
309
+ export type { CompiledTree } from "./closure-backend.js";
310
+
311
+ export { CALL_SITE_CACHE_CAPACITY, CelCompileError } from "./backend-runtime.js";
312
+ export type {
313
+ CelStep,
314
+ CompileTarget,
315
+ EvaluationFrame,
316
+ NamespaceDispatch,
317
+ } from "./backend-runtime.js";
318
+
319
+ export {
320
+ celAll,
321
+ celExists,
322
+ celExistsOne,
323
+ celFilter,
324
+ celMapComprehension,
325
+ } from "./comprehension-runtime.js";
326
+ export type { ComprehensionBody } from "./comprehension-runtime.js";
327
+
328
+ export {
329
+ celDurationFromNanos,
330
+ durationField,
331
+ durationNanos,
332
+ durationOutOfRange,
333
+ formatDuration,
334
+ MAX_DURATION_NANOS,
335
+ MIN_DURATION_NANOS,
336
+ parseDuration,
337
+ } from "./duration-value.js";
338
+
339
+ export {
340
+ celHas,
341
+ celIterable,
342
+ celLookup,
343
+ celRead,
344
+ lookupError,
345
+ MISSING,
346
+ OUT_OF_RANGE,
347
+ UNSUPPORTED_CONTAINER,
348
+ UNSUPPORTED_KEY,
349
+ } from "./member-read.js";
350
+ export type { Lookup } from "./member-read.js";
351
+
352
+ export {
353
+ celMatches,
354
+ PATTERN_CACHE_CAPACITY,
355
+ RE2_FLAG_LETTERS,
356
+ RE2_PATTERN_ERROR_KINDS,
357
+ re2Pattern,
358
+ } from "./regular-expression.js";
359
+ export type { RE2Compiled, RE2PatternRefusal } from "./regular-expression.js";
360
+
361
+ export {
362
+ base64Text,
363
+ celTypeValueOf,
364
+ implementationOf,
365
+ jsonAsCelValue,
366
+ implementedKeys,
367
+ optionalOfNonZero,
368
+ standardConstantValues,
369
+ typeValueName,
370
+ } from "./runtime-library.js";
371
+ export type { CelCallContext, CelImplementation } from "./runtime-library.js";
372
+
373
+ export {
374
+ celTimestamp,
375
+ formatTimestamp,
376
+ MAX_TIMESTAMP_SECONDS,
377
+ MIN_TIMESTAMP_SECONDS,
378
+ parseTimestamp,
379
+ timestampField,
380
+ timestampNanos,
381
+ zonedFields,
382
+ } from "./timestamp-value.js";
383
+
384
+ export { celCompare, celEqual } from "./value-equality.js";
385
+
386
+ export { bytesToText, doubleText, textToBytes } from "./value-text.js";
@@ -0,0 +1,64 @@
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
+
15
+ import { celError, celUint, type CelError, type CelUint } from "./cel-value.js";
16
+ import { MAX_INT, MAX_UINT, MIN_INT } from "./lexer.js";
17
+ import type { SourceRange } from "./syntax-tree.js";
18
+
19
+ const MAX_UINT_PLUS_ONE = MAX_UINT + 1n;
20
+
21
+ function overflow(range: SourceRange | undefined, result: bigint, what: string): CelError {
22
+ return celError("numeric_overflow", `${what} overflow: ${result}`, range);
23
+ }
24
+
25
+ /** An int result, or the overflow it is outside the range. */
26
+ export function intResult(value: bigint, range?: SourceRange): bigint | CelError {
27
+ if (value < MIN_INT || value > MAX_INT) return overflow(range, value, "integer");
28
+ return value;
29
+ }
30
+
31
+ /** A uint result, or the overflow it is outside the range. */
32
+ export function uintResult(value: bigint, range?: SourceRange): CelUint | CelError {
33
+ if (value < 0n || value > MAX_UINT) return overflow(range, value, "unsigned integer");
34
+ return celUint(value);
35
+ }
36
+
37
+ export function intDivide(left: bigint, right: bigint, range?: SourceRange): bigint | CelError {
38
+ if (right === 0n) return celError("division_by_zero", "division by zero", range);
39
+ return intResult(left / right, range);
40
+ }
41
+
42
+ export function intModulo(left: bigint, right: bigint, range?: SourceRange): bigint | CelError {
43
+ if (right === 0n) return celError("modulo_by_zero", "modulus by zero", range);
44
+ return intResult(left % right, range);
45
+ }
46
+
47
+ export function uintDivide(left: bigint, right: bigint, range?: SourceRange): CelUint | CelError {
48
+ if (right === 0n) return celError("division_by_zero", "division by zero", range);
49
+ return uintResult(left / right, range);
50
+ }
51
+
52
+ export function uintModulo(left: bigint, right: bigint, range?: SourceRange): CelUint | CelError {
53
+ if (right === 0n) return celError("modulo_by_zero", "modulus by zero", range);
54
+ return uintResult(left % right, range);
55
+ }
56
+
57
+ /** Whether a magnitude fits a uint64 — used by the conversions. */
58
+ export function fitsUint(value: bigint): boolean {
59
+ return value >= 0n && value < MAX_UINT_PLUS_ONE;
60
+ }
61
+
62
+ export function fitsInt(value: bigint): boolean {
63
+ return value >= MIN_INT && value <= MAX_INT;
64
+ }