@telorun/templating 0.107.0 → 0.108.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 (60) hide show
  1. package/dist/builtins.d.ts +2 -2
  2. package/dist/builtins.d.ts.map +1 -1
  3. package/dist/cel/analyze.d.ts +6 -6
  4. package/dist/cel/analyze.d.ts.map +1 -1
  5. package/dist/cel/analyze.js +138 -183
  6. package/dist/cel/compile.d.ts +47 -17
  7. package/dist/cel/compile.d.ts.map +1 -1
  8. package/dist/cel/compile.js +135 -83
  9. package/dist/cel/diagnose.d.ts +52 -57
  10. package/dist/cel/diagnose.d.ts.map +1 -1
  11. package/dist/cel/diagnose.js +69 -291
  12. package/dist/cel/environment.d.ts +33 -37
  13. package/dist/cel/environment.d.ts.map +1 -1
  14. package/dist/cel/environment.js +54 -86
  15. package/dist/cel/module-call.d.ts +68 -79
  16. package/dist/cel/module-call.d.ts.map +1 -1
  17. package/dist/cel/module-call.js +118 -194
  18. package/dist/cel/value-brands.d.ts +14 -12
  19. package/dist/cel/value-brands.d.ts.map +1 -1
  20. package/dist/cel/value-brands.js +26 -24
  21. package/dist/cel/verdict-codes.d.ts +13 -2
  22. package/dist/cel/verdict-codes.d.ts.map +1 -1
  23. package/dist/cel/verdict-codes.js +20 -1
  24. package/dist/engine.d.ts +4 -4
  25. package/dist/engine.d.ts.map +1 -1
  26. package/dist/engines/cel.d.ts +2 -2
  27. package/dist/engines/cel.d.ts.map +1 -1
  28. package/dist/engines/cel.js +53 -81
  29. package/dist/engines/hole-analysis.d.ts +3 -3
  30. package/dist/engines/hole-analysis.d.ts.map +1 -1
  31. package/dist/engines/interpolate.js +11 -8
  32. package/dist/index.d.ts +4 -5
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +8 -5
  35. package/package.json +4 -4
  36. package/src/builtins.ts +2 -2
  37. package/src/cel/analyze.ts +152 -193
  38. package/src/cel/compile.ts +160 -77
  39. package/src/cel/diagnose.ts +115 -370
  40. package/src/cel/environment.ts +64 -87
  41. package/src/cel/module-call.ts +129 -292
  42. package/src/cel/value-brands.ts +26 -25
  43. package/src/cel/verdict-codes.ts +20 -1
  44. package/src/engine.ts +4 -4
  45. package/src/engines/cel.ts +52 -84
  46. package/src/engines/hole-analysis.ts +3 -3
  47. package/src/engines/interpolate.ts +16 -13
  48. package/src/index.ts +8 -11
  49. package/dist/cel/catalog.d.ts +0 -70
  50. package/dist/cel/catalog.d.ts.map +0 -1
  51. package/dist/cel/catalog.js +0 -1320
  52. package/dist/cel/json-prefix-scan.d.ts +0 -17
  53. package/dist/cel/json-prefix-scan.d.ts.map +0 -1
  54. package/dist/cel/json-prefix-scan.js +0 -160
  55. package/dist/cel/value-identity.d.ts +0 -18
  56. package/dist/cel/value-identity.d.ts.map +0 -1
  57. package/dist/cel/value-identity.js +0 -25
  58. package/src/cel/catalog.ts +0 -1455
  59. package/src/cel/json-prefix-scan.ts +0 -152
  60. package/src/cel/value-identity.ts +0 -34
@@ -1,31 +1,33 @@
1
1
  import { VALUE_TYPES, valueBrandBases } from "@telorun/sdk";
2
2
  /**
3
- * Register every nominal value brand on an analysis environment, with what a
4
- * brand may do: convert to its base with the base's own conversion
5
- * (`int(ports.http)`, `string(variables.dataDir)`), render as text
6
- * (`string(ports.http)`), and — for a host path — be
7
- * extended with `.joinPath(relative)` and stay one.
3
+ * Register every nominal value brand on an analysis environment, with what a brand may do:
4
+ * convert to its base with the base's own conversion (`int(ports.http)`,
5
+ * `string(variables.dataDir)`), render as text (`string(ports.http)`), and — for a host
6
+ * path — be extended with `.joinPath(relative)` and stay one.
8
7
  *
9
- * Static only: at runtime a branded value IS its base (an int, a string), so the
10
- * catalog's own overloads — `string.joinPath` among them — are what evaluate. The
11
- * implementations below exist because registration requires one; a brand's
12
- * values never reach them. `buildCelEnvironment` registers none of this: a
13
- * caller typing a site registers the brands on its own clone.
8
+ * **Declared, not implemented.** A nominal type is a checking concept: the engine takes the
9
+ * conversions and members as signatures over `Self` and needs no function body for any of
10
+ * them, because at runtime a branded value IS its base (an int, a string) and the standard
11
+ * library's own overloads are what evaluate. The previous engine required an implementation
12
+ * per registration, so this file carried three stubs a brand's values never reached.
13
+ *
14
+ * `buildCelEnvironment` registers none of it: a caller typing a site registers the brands on
15
+ * its own clone.
14
16
  */
15
- export function registerValueBrands(env) {
17
+ export function registerValueBrands(environment) {
16
18
  for (const [brand, base] of Object.entries(valueBrandBases())) {
17
- env.registerType(brand, { fields: {} });
18
- env.registerFunction(`${base}(${brand}): ${base}`, (value) => value);
19
- // Every base CEL can render as text renders its brand too — the runtime
20
- // value IS the base — so `string(ports.http)` and a port in an
21
- // `!interpolate` hole convert as the integer they are.
22
- if (base !== "string") {
23
- env.registerFunction(`string(${brand}): string`, (value) => String(value));
24
- }
25
- if (VALUE_TYPES.get(brand)?.fromHost !== undefined) {
26
- env.registerFunction(`${brand}.joinPath(string): ${brand}`, () => {
27
- throw new Error("joinPath() is evaluated by the runtime, not the analyzer.");
28
- });
29
- }
19
+ const conversions = [`${base}(Self): ${base}`];
20
+ // Every base CEL can render as text renders its brand too — the runtime value IS the
21
+ // base — so `string(ports.http)` and a port in an `!interpolate` hole convert as the
22
+ // integer they are.
23
+ if (base !== "string")
24
+ conversions.push("string(Self): string");
25
+ const fromHost = VALUE_TYPES.get(brand)?.fromHost !== undefined;
26
+ environment.registerType({
27
+ name: brand,
28
+ base,
29
+ conversions,
30
+ ...(fromHost ? { members: ["Self.joinPath(string): Self"] } : {}),
31
+ });
30
32
  }
31
33
  }
@@ -4,9 +4,20 @@ import type { CallAudit } from "./diagnose.js";
4
4
  /** Every code the `!cel`, `!interpolate` and `!sql` engines emit: `diagnostics`
5
5
  * from `analyze`, `errors` thrown by compiling or evaluating. Stated once here;
6
6
  * the types below hold every emit site to it, and the conformance runner
7
- * requires a `verdicts.json` row for each. */
7
+ * requires a `verdicts.json` row for each.
8
+ *
9
+ * **Four codes the ENGINE decides are deliberately absent**, because these engines cannot
10
+ * reach them and a code no row can pin is a claim the gate can never satisfy:
11
+ * `FUNCTION_UNRESOLVED`, `FUNCTION_ARITY_MISMATCH` and `FUNCTION_ARGUMENT_MISMATCH` need a
12
+ * namespace declared CLOSED and with a parameter list, and a module's names are registered
13
+ * open and withhold their parameters on purpose — whether a call reaches a function, and
14
+ * whether its arity and arguments fit, rest on the export gate, the dependency edge and a
15
+ * JSON Schema per parameter, which are the analyzer's verdicts. `CEL_TYPE_ARGUMENT_MISMATCH`
16
+ * needs a parameterized value type on both sides, and the brands registered here are
17
+ * nominal with a base and no parameters. Each is still reported where it IS decided — by
18
+ * the analyzer, against its own environment. */
8
19
  export declare const CEL_VERDICT_CODES: {
9
- readonly diagnostics: readonly ["BINDING_NAME_RESERVED", "CEL_INVALID_ARGUMENT", "CEL_NULLABLE_ACCESS", "CEL_SYNTAX_ERROR", "CEL_TYPE_ERROR", "CEL_UNKNOWN_FIELD", "CEL_UNKNOWN_FUNCTION", "CEL_UNKNOWN_IDENTIFIER", "CEL_WRONG_CALL_FORM", "INTERPOLATION_HOLE_NOT_CONVERTIBLE"];
20
+ readonly diagnostics: readonly ["BINDING_NAME_RESERVED", "CEL_INVALID_ARGUMENT", "CEL_NULLABLE_ACCESS", "CEL_SYNTAX_ERROR", "CEL_TYPE_ARGUMENT_MISMATCH", "CEL_TYPE_ERROR", "CEL_UNKNOWN_FIELD", "CEL_UNKNOWN_FUNCTION", "CEL_UNKNOWN_IDENTIFIER", "CEL_WRONG_CALL_FORM", "FUNCTION_ARGUMENT_MISMATCH", "FUNCTION_ARITY_MISMATCH", "FUNCTION_UNRESOLVED", "INTERPOLATION_HOLE_NOT_CONVERTIBLE"];
10
21
  readonly errors: readonly ["ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE"];
11
22
  };
12
23
  export type CelDiagnosticCode = (typeof CEL_VERDICT_CODES.diagnostics)[number];
@@ -1 +1 @@
1
- {"version":3,"file":"verdict-codes.d.ts","sourceRoot":"","sources":["../../src/cel/verdict-codes.ts"],"names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AAiB;;;CAsBpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,oDAAoD;AACpD,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;CAClC;AAED,6CAA6C;AAC7C,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAC;CAChD;AAED,gDAAgD;AAChD,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAC;IAC/C,QAAQ,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;CACnD;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAEjF"}
@@ -2,18 +2,37 @@ import { RuntimeError } from "@telorun/sdk";
2
2
  /** Every code the `!cel`, `!interpolate` and `!sql` engines emit: `diagnostics`
3
3
  * from `analyze`, `errors` thrown by compiling or evaluating. Stated once here;
4
4
  * the types below hold every emit site to it, and the conformance runner
5
- * requires a `verdicts.json` row for each. */
5
+ * requires a `verdicts.json` row for each.
6
+ *
7
+ * **Four codes the ENGINE decides are deliberately absent**, because these engines cannot
8
+ * reach them and a code no row can pin is a claim the gate can never satisfy:
9
+ * `FUNCTION_UNRESOLVED`, `FUNCTION_ARITY_MISMATCH` and `FUNCTION_ARGUMENT_MISMATCH` need a
10
+ * namespace declared CLOSED and with a parameter list, and a module's names are registered
11
+ * open and withhold their parameters on purpose — whether a call reaches a function, and
12
+ * whether its arity and arguments fit, rest on the export gate, the dependency edge and a
13
+ * JSON Schema per parameter, which are the analyzer's verdicts. `CEL_TYPE_ARGUMENT_MISMATCH`
14
+ * needs a parameterized value type on both sides, and the brands registered here are
15
+ * nominal with a base and no parameters. Each is still reported where it IS decided — by
16
+ * the analyzer, against its own environment. */
6
17
  export const CEL_VERDICT_CODES = {
7
18
  diagnostics: [
8
19
  "BINDING_NAME_RESERVED",
9
20
  "CEL_INVALID_ARGUMENT",
10
21
  "CEL_NULLABLE_ACCESS",
11
22
  "CEL_SYNTAX_ERROR",
23
+ "CEL_TYPE_ARGUMENT_MISMATCH",
12
24
  "CEL_TYPE_ERROR",
13
25
  "CEL_UNKNOWN_FIELD",
14
26
  "CEL_UNKNOWN_FUNCTION",
15
27
  "CEL_UNKNOWN_IDENTIFIER",
16
28
  "CEL_WRONG_CALL_FORM",
29
+ // Forwarded from the engine's checker, which decides them. Whether a module call
30
+ // REACHES a function, and whether its arity and arguments fit, is still the analyzer's
31
+ // verdict against its own environment — these engines register a module's names open and
32
+ // withhold their parameters, so they pass the engine's codes through rather than deciding.
33
+ "FUNCTION_ARGUMENT_MISMATCH",
34
+ "FUNCTION_ARITY_MISMATCH",
35
+ "FUNCTION_UNRESOLVED",
17
36
  "INTERPOLATION_HOLE_NOT_CONVERTIBLE",
18
37
  ],
19
38
  errors: ["ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE"],
package/dist/engine.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Environment } from "@marcbachmann/cel-js";
1
+ import type { CelEnvironment } from "@telorun/cel";
2
2
  import type { CompiledValue } from "@telorun/sdk";
3
3
  import type { ModuleCallFlags } from "./cel/diagnose.js";
4
4
  import type { ModuleCallTypeResolver } from "./cel/module-call.js";
@@ -6,7 +6,7 @@ import type { ModuleCallTypeResolver } from "./cel/module-call.js";
6
6
  * parse against a CEL environment (the `cel` engine) read it from `celEnv`;
7
7
  * engines that resolve fully at compile time (`literal`) ignore it. */
8
8
  export interface CompileEnv {
9
- readonly celEnv: Environment;
9
+ readonly celEnv: CelEnvironment;
10
10
  /**
11
11
  * The names a call's receiver may be for the call to resolve as a MODULE
12
12
  * call — the declaring module's `imports:` keys, `Self`, its `metadata.name`
@@ -31,7 +31,7 @@ export interface CompileEnv {
31
31
  * expression again against a different environment. One expression, one
32
32
  * verdict. */
33
33
  export interface AnalyzeEnv {
34
- readonly celEnv: Environment;
34
+ readonly celEnv: CelEnvironment;
35
35
  readonly contextSchema: Record<string, unknown> | null;
36
36
  /**
37
37
  * The caller vouches that `celEnv` declares EVERY name legal at this site, so
@@ -275,6 +275,6 @@ export interface TemplatingEngine {
275
275
  * they are equal without evaluating either. Absent on an engine that gives no
276
276
  * such verdict, which reads as "not repeatable". A source the engine cannot
277
277
  * read is not repeatable; `analyze` is what reports why. */
278
- repeatable?(source: string, celEnv: Environment): boolean;
278
+ repeatable?(source: string, celEnv: CelEnvironment): boolean;
279
279
  }
280
280
  //# sourceMappingURL=engine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;wEAEwE;AACxE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED;;;;;;;;;eASe;AACf,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACv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AAC,EAAE,OAAO,CAAC;IAC7B;;qCAEiC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;cACc;AACd,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;wBAEwB;AACxB,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;2EAKuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;yDAGqD;IACrD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,aAAa,GAAG,OAAO,CAAC;IAElE;;iEAE6D;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,aAAa,CAAC;IAExD;;;;;;;;;;;;uBAYmB;IACnB,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAAC;IAExD;;;;;;;;;;;;;;;;;2CAiBuC;IACvC,YAAY,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC;;;;;;qDAMiD;IACjD,iBAAiB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,gBAAgB,EAAE,CAAC;IAEhE;;;;;;;;;iEAS6D;IAC7D,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC;CAC9D"}
@@ -1,4 +1,4 @@
1
- import type { ASTNode } from "@marcbachmann/cel-js";
1
+ import { type CelNode } from "@telorun/cel";
2
2
  import type { CelAnalyzeResult } from "../cel/verdict-codes.js";
3
3
  import type { AnalyzeEnv, TemplatingEngine } from "../engine.js";
4
4
  /** Statically analyze one CEL expression against the effective context schema:
@@ -17,7 +17,7 @@ export declare function analyzeCelExpression(source: string, env: AnalyzeEnv): C
17
17
  * that asks its own questions of one expression without parsing it again. */
18
18
  export declare function analyzeCelWithTree(source: string, env: AnalyzeEnv): {
19
19
  result: CelAnalyzeResult;
20
- ast?: ASTNode;
20
+ ast?: CelNode;
21
21
  };
22
22
  /** The `!cel` engine. Treats the entire tagged scalar as a single CEL
23
23
  * expression — no `${{ }}` wrapping. */
@@ -1 +1 @@
1
- {"version":3,"file":"cel.d.ts","sourceRoot":"","sources":["../../src/engines/cel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAkBpD,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAY,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;;;;;;2BAU2B;AAC3B,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAEtF;AAED;8EAC8E;AAC9E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,GACd;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CAoL7C;AA4ED;yCACyC;AACzC,eAAO,MAAM,SAAS,EAAE,gBAmBvB,CAAC"}
1
+ {"version":3,"file":"cel.d.ts","sourceRoot":"","sources":["../../src/engines/cel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAYxE,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAY,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;;;;;;2BAU2B;AAC3B,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAEtF;AAED;8EAC8E;AAC9E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,GACd;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CAoL7C;AAkDD;yCACyC;AACzC,eAAO,MAAM,SAAS,EAAE,gBAmBvB,CAAC"}
@@ -1,7 +1,8 @@
1
- import { extractAccessChains, extractCallResultAccesses, findNullableAccessIssues, INDEX_SEGMENT, moduleCallArgumentChains, validateChainAgainstSchema, } from "../cel/analyze.js";
1
+ import { qualifiedCalls } from "@telorun/cel";
2
+ import { extractAccessChains, extractCallResultAccesses, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "../cel/analyze.js";
2
3
  import { compileExpression, repeatableExpression } from "../cel/compile.js";
3
- import { auditCalls, explainUnresolved } from "../cel/diagnose.js";
4
- import { moduleCallNodes, moduleNameBindings, resolveModuleCalls, unresolvedCallReceivers, } from "../cel/module-call.js";
4
+ import { auditCalls } from "../cel/diagnose.js";
5
+ import { moduleNameBindings, unresolvedCallReceivers } from "../cel/module-call.js";
5
6
  /** Statically analyze one CEL expression against the effective context schema:
6
7
  * parse → classify every call → type-check → validate member-access chains →
7
8
  * flag nullable access. Single source of truth shared by the `!cel` engine
@@ -20,29 +21,29 @@ export function analyzeCelExpression(source, env) {
20
21
  * that asks its own questions of one expression without parsing it again. */
21
22
  export function analyzeCelWithTree(source, env) {
22
23
  const out = [];
23
- let parsed;
24
- try {
25
- parsed = env.celEnv.parse(source);
26
- }
27
- catch (e) {
24
+ // **Reading never throws and never discards what it read**: the first unreadable thing is
25
+ // one ranged diagnostic and the tree keeps the longest prefix, so a scalar an author is
26
+ // mid-way through typing still reports its chains and its calls.
27
+ const parsed = env.celEnv.parse(source);
28
+ if (parsed.diagnostics.length > 0) {
29
+ const first = parsed.diagnostics[0];
28
30
  return {
29
31
  result: {
30
- diagnostics: [{ code: "CEL_SYNTAX_ERROR", message: e instanceof Error ? e.message : String(e) }],
32
+ diagnostics: [{ code: "CEL_SYNTAX_ERROR", message: first.message }],
31
33
  calls: [],
32
34
  },
33
35
  };
34
36
  }
35
- const ast = parsed.ast;
36
- // Resolution, before anything reads the tree — the audit, the type check and
37
- // every chain walk below all see the resolved shape, so none of them has to
38
- // know a module name from a variable.
39
- // The walks that read resolved calls below are skipped when there are none.
40
- const resolvedCalls = resolveModuleCalls(parsed.ast, env.moduleNames, env.moduleCallType).length > 0;
37
+ const ast = parsed.root;
38
+ // Resolution happened as the expression was READ, over the environment's own namespaces —
39
+ // `qcall` is a node of its own rather than a rewrite — so every walk below already sees
40
+ // the resolved shape and none of them has to know a module name from a variable.
41
+ const resolvedCalls = qualifiedCalls(ast).length > 0;
41
42
  // A name bound inside the expression can never be read once a module owns it:
42
43
  // `Billing.f(x)` under a comprehension variable named `Billing` resolves to
43
44
  // the module. Reported rather than silently shadowed, the rule every other
44
45
  // name in CEL scope follows.
45
- for (const name of moduleNameBindings(parsed.ast, env.moduleNames)) {
46
+ for (const name of moduleNameBindings(ast, env.moduleNames)) {
46
47
  out.push({
47
48
  code: "BINDING_NAME_RESERVED",
48
49
  message: `'${name}' names a module here (an imports: alias, Self, or this module's own name), ` +
@@ -50,7 +51,8 @@ export function analyzeCelWithTree(source, env) {
50
51
  `be read. Rename the bound variable.`,
51
52
  });
52
53
  }
53
- const audit = auditCalls(source, parsed.ast, env.celEnv, env.moduleCallFlags);
54
+ const checked = env.celEnv.check(parsed);
55
+ const audit = auditCalls(source, ast, env.celEnv, env.moduleCallFlags, checked);
54
56
  // Reported whatever the type-checker concludes. A literal argument a guard
55
57
  // will refuse is a defect the manifest states outright, and leaving it to the
56
58
  // run is the thing static analysis exists to prevent — so it is not gated on
@@ -59,16 +61,25 @@ export function analyzeCelWithTree(source, env) {
59
61
  let type;
60
62
  let checkError;
61
63
  try {
62
- // `parsed.check()`, never `celEnv.check(source)`: the latter RE-PARSES, so
63
- // it would type a tree in which no module call was ever resolved — every
64
- // one of them reported as a missing method on an unknown receiver.
65
- const result = parsed.check();
66
- if (result.valid)
67
- type = result.type;
68
- else if (result.error) {
69
- checkError = String(result.error.message ?? result.error)
70
- .split("\n")[0]
71
- .trim();
64
+ // The TREE is checked, never the source again: `check(source)` would re-read it, and a
65
+ // tree resolved under another site's names is refused rather than answered about.
66
+ if (checked.valid)
67
+ type = checked.typeName;
68
+ else {
69
+ // **Every verdict is the engine's, coded and ranged.** This used to be one opaque
70
+ // sentence — `found no matching overload for 'f(...)'` for three unrelated mistakes —
71
+ // which is why a classifier sat beside it rewriting the message. The engine decides an
72
+ // unknown name, a name called in the other form, an unknown field, a type no overload
73
+ // takes and a refusal over a literal argument each where its cause is known, so they
74
+ // come through as they are.
75
+ for (const diagnostic of checked.diagnostics) {
76
+ out.push({
77
+ code: diagnostic.code,
78
+ message: diagnostic.message,
79
+ ...(diagnostic.fix ? { fix: diagnostic.fix } : {}),
80
+ });
81
+ }
82
+ checkError = checked.diagnostics[0]?.message;
72
83
  }
73
84
  }
74
85
  catch (e) {
@@ -97,22 +108,9 @@ export function analyzeCelWithTree(source, env) {
97
108
  // this analyzer refuses and the kernel would run fine.
98
109
  // What explaining a rejection already reported, so the context's own chain
99
110
  // check below does not report it twice.
100
- const explained = new Set();
101
- if (checkError !== undefined) {
102
- // `check()` stops at its first problem; the audit enumerates every bad call,
103
- // which is the whole reason it exists as more than a message rewriter.
104
- out.push(...audit.diagnostics);
105
- const unknownFields = audit.diagnostics.length === 0 ? explainUnknownFields(parsed.ast, env) : [];
106
- out.push(...unknownFields);
107
- for (const d of unknownFields)
108
- explained.add(d.message);
109
- if (audit.diagnostics.length === 0 && unknownFields.length === 0) {
110
- out.push({
111
- code: "CEL_TYPE_ERROR",
112
- message: checkError + explainUnresolved(audit.unresolved, env.celEnv) + DYN_HINT(checkError),
113
- });
114
- }
115
- }
111
+ // What the engine already said, so the host's own schema reading below does not say it
112
+ // twice in different words.
113
+ const explained = new Set(out.map((diagnostic) => diagnostic.message));
116
114
  // An undeclared ROOT identifier. cel-js types an unknown name as `dyn` and
117
115
  // accepts it, so `!cel "fff"` type-checked, reached the runtime and resolved
118
116
  // to nothing — the one CEL mistake with no static report at all. Member
@@ -130,12 +128,12 @@ export function analyzeCelWithTree(source, env) {
130
128
  // Walked only once a root is unknown, which a correct expression never has.
131
129
  let callReceivers;
132
130
  const reported = new Set();
133
- for (const chain of extractAccessChains(parsed.ast)) {
131
+ for (const chain of extractAccessChains(ast)) {
134
132
  const root = chain[0];
135
133
  if (!root || reported.has(root) || env.celEnv.hasVariable(root))
136
134
  continue;
137
135
  reported.add(root);
138
- callReceivers ??= unresolvedCallReceivers(parsed.ast, env.moduleNames);
136
+ callReceivers ??= unresolvedCallReceivers(ast, env.moduleNames);
139
137
  out.push({
140
138
  code: "CEL_UNKNOWN_IDENTIFIER",
141
139
  message: `unknown identifier '${root}' — nothing by that name is in scope here.` +
@@ -149,7 +147,7 @@ export function analyzeCelWithTree(source, env) {
149
147
  // caller resolves: member access on it is checked exactly as a read off the
150
148
  // context would be, under the call as written.
151
149
  if (resolvedCalls && env.moduleCallResult) {
152
- for (const access of extractCallResultAccesses(parsed.ast)) {
150
+ for (const access of extractCallResultAccesses(ast)) {
153
151
  const schema = env.moduleCallResult(access.qualified);
154
152
  if (!schema)
155
153
  continue;
@@ -164,12 +162,12 @@ export function analyzeCelWithTree(source, env) {
164
162
  }
165
163
  if (env.contextSchema) {
166
164
  const contextSchema = env.contextSchema;
167
- for (const chain of extractAccessChains(parsed.ast)) {
165
+ for (const chain of extractAccessChains(ast)) {
168
166
  const err = validateChainAgainstSchema(chain, contextSchema);
169
167
  if (err && !explained.has(err))
170
168
  out.push({ code: "CEL_UNKNOWN_FIELD", message: err });
171
169
  }
172
- for (const issue of findNullableAccessIssues(parsed.ast, contextSchema)) {
170
+ for (const issue of findNullableAccessIssues(ast, contextSchema)) {
173
171
  // Index access (member "[index]") attaches without a dot; a named field
174
172
  // attaches with one — so the suggested CEL stays valid either way.
175
173
  const access = issue.member === "[index]" ? issue.member : `.${issue.member}`;
@@ -182,10 +180,12 @@ export function analyzeCelWithTree(source, env) {
182
180
  return {
183
181
  result: {
184
182
  diagnostics: out,
185
- calls: resolvedCalls ? withCallArguments(audit.calls, parsed.ast) : audit.calls,
183
+ calls: audit.calls,
186
184
  ...(type === undefined ? {} : { type }),
187
- ...(ast.op === "value" && typeof ast.args === "string" ? { stringLiteral: ast.args } : {}),
188
- ...(checkError === undefined ? {} : { readTypes: chainTypes(parsed.ast, env) }),
185
+ ...(ast.kind === "literal" && ast.literal.type === "string"
186
+ ? { stringLiteral: ast.literal.value }
187
+ : {}),
188
+ ...(checkError === undefined ? {} : { readTypes: chainTypes(ast, env) }),
189
189
  },
190
190
  ast,
191
191
  };
@@ -217,8 +217,8 @@ function chainTypes(ast, env) {
217
217
  if (chain.includes(INDEX_SEGMENT))
218
218
  continue;
219
219
  const result = env.celEnv.check(chain.join("."));
220
- if (result.valid && result.type !== undefined)
221
- types.add(result.type);
220
+ if (result.valid)
221
+ types.add(result.typeName);
222
222
  }
223
223
  return [...types];
224
224
  }
@@ -228,34 +228,6 @@ function checkerRejects(chain, env) {
228
228
  const named = end === -1 ? chain : chain.slice(0, end);
229
229
  return !env.celEnv.check(named.join(".")).valid;
230
230
  }
231
- /** The audited call sites, each module call carrying its arguments as the type
232
- * check saw them. Matched by position, which is what identifies one call among
233
- * several of the same name. */
234
- function withCallArguments(calls, ast) {
235
- const byStart = new Map();
236
- for (const { node, call } of moduleCallNodes(ast))
237
- byStart.set(node.start, call);
238
- const chainsByStart = new Map();
239
- for (const [node, chains] of moduleCallArgumentChains(ast))
240
- chainsByStart.set(node.start, chains);
241
- return calls.map((site) => {
242
- const call = site.moduleCall ? byStart.get(site.start) : undefined;
243
- if (!call)
244
- return site;
245
- const chains = chainsByStart.get(site.start);
246
- return {
247
- ...site,
248
- arguments: call.args.map((arg, index) => {
249
- const type = call.argumentTypes?.[index];
250
- const chain = chains?.[index] ?? null;
251
- return {
252
- ...(type !== undefined ? { type } : {}),
253
- ...(chain && !chain.includes(INDEX_SEGMENT) ? { chain } : {}),
254
- };
255
- }),
256
- };
257
- });
258
- }
259
231
  /** `dyn` in a checker message means an operand whose type is unknown here —
260
232
  * almost always a step result whose invoked resource declares no
261
233
  * `outputType:`. Without this, the reader takes `dyn` for a cast problem. */
@@ -1,4 +1,4 @@
1
- import type { ASTNode, Environment } from "@marcbachmann/cel-js";
1
+ import type { CelEnvironment, CelNode } from "@telorun/cel";
2
2
  import type { CompiledValue } from "@telorun/sdk";
3
3
  import { type InterpolationHole } from "../cel/interpolation-holes.js";
4
4
  import type { CelAnalyzeResult, CelDiagnostic } from "../cel/verdict-codes.js";
@@ -18,10 +18,10 @@ export declare function compileHoles(holes: readonly InterpolationHole[], env: C
18
18
  * as they do under `!cel`; a fix computed against one hole's expression is
19
19
  * re-anchored onto the whole scalar, and call offsets onto the scalar too.
20
20
  * `perHole` adds a tag's own verdict on a hole that analyzed clean. */
21
- export declare function analyzeHoles(source: string, env: AnalyzeEnv, perHole?: (hole: InterpolationHole, result: CelAnalyzeResult, ast: ASTNode | undefined) => readonly CelDiagnostic[]): CelAnalyzeResult;
21
+ export declare function analyzeHoles(source: string, env: AnalyzeEnv, perHole?: (hole: InterpolationHole, result: CelAnalyzeResult, ast: CelNode | undefined) => readonly CelDiagnostic[]): CelAnalyzeResult;
22
22
  /** The CEL expressions of a hole-bearing scalar, by offset. */
23
23
  export declare function holeRegions(source: string): readonly ExpressionRegion[];
24
24
  /** Whether every hole of a hole-bearing scalar is repeatable; the literal text
25
25
  * between them always is. */
26
- export declare function holesRepeatable(source: string, celEnv: Environment): boolean;
26
+ export declare function holesRepeatable(source: string, celEnv: CelEnvironment): boolean;
27
27
  //# sourceMappingURL=hole-analysis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hole-analysis.d.ts","sourceRoot":"","sources":["../../src/engines/hole-analysis.ts"],"names":[],"mappings":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,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAG/E"}
@@ -1,4 +1,4 @@
1
- import { EvaluationError } from "@marcbachmann/cel-js";
1
+ import { CelEvaluationError, isCelMap, isCelRecord } from "@telorun/cel";
2
2
  import { nullableValueChain } from "../cel/analyze.js";
3
3
  import { literalFragments } from "../cel/interpolation-holes.js";
4
4
  import { celVerdictError } from "../cel/verdict-codes.js";
@@ -83,9 +83,9 @@ function convertibleTypes(env) {
83
83
  if (cached)
84
84
  return cached;
85
85
  const types = new Set(["dyn"]);
86
- for (const fn of env.getDefinitions().functions) {
87
- if (fn.name === "string" && fn.receiverType === null && fn.params?.length === 1) {
88
- types.add(fn.params[0].type);
86
+ for (const fn of env.definitions().functions) {
87
+ if (fn.name === "string" && fn.receiverType === null && fn.parameters.length === 1) {
88
+ types.add(fn.parameters[0]);
89
89
  }
90
90
  }
91
91
  CONVERTIBLE.set(env, types);
@@ -97,15 +97,15 @@ function stringConversion(env) {
97
97
  const cached = CONVERSIONS.get(env);
98
98
  if (cached)
99
99
  return cached;
100
- const program = env.parse("string(value)");
100
+ const program = env.compile("string(value)");
101
101
  const conversion = (value, hole, source) => {
102
102
  if (typeof value === "string")
103
103
  return value;
104
104
  try {
105
- return program({ value });
105
+ return program.evaluate({ value });
106
106
  }
107
107
  catch (error) {
108
- if (!(error instanceof EvaluationError))
108
+ if (!(error instanceof CelEvaluationError))
109
109
  throw error;
110
110
  throw celVerdictError("ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE", `the hole '\${{ ${hole.expr} }}' at offset ${hole.start} of !interpolate ${JSON.stringify(source)} ` +
111
111
  `evaluated to ${runtimeTypeOf(value)}, which CEL's string() cannot convert to text. ` +
@@ -120,7 +120,10 @@ function runtimeTypeOf(value) {
120
120
  return "null";
121
121
  if (Array.isArray(value))
122
122
  return "a list";
123
- if (value instanceof Map || Object.getPrototypeOf(value) === Object.prototype)
123
+ // Both of the value domain's map representations, asked of the domain rather than of the
124
+ // prototype: a branded value is a plain object, so a prototype test named an optional, a
125
+ // type and every host named type "a map".
126
+ if (isCelMap(value) || isCelRecord(value))
124
127
  return "a map";
125
128
  return `a value of type ${value.constructor?.name ?? typeof value}`;
126
129
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, deriveSignatures, type CelHandlers, } from "./cel/environment.js";
2
- export { celFunctionCatalog, CEL_FUNCTIONS, type CelFunctionInfo, type CelFunctionDoc, type CelFunctionCategory, } from "./cel/catalog.js";
3
- export { compileExpression } from "./cel/compile.js";
1
+ export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, celFunctionCatalog, type CelHandlers, } from "./cel/environment.js";
2
+ export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
4
3
  export { registerValueBrands } from "./cel/value-brands.js";
5
4
  export { interpolationShape, literalFragments, readInterpolationHoles, type HoleReading, type InterpolationHole, type InterpolationShape, } from "./cel/interpolation-holes.js";
6
5
  export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
7
- export { auditCalls, explainUnresolved, functionIndex, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
8
- export { MODULE_CALL_DISPATCH_KEY, moduleCallOf, resolveModuleCalls, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
6
+ export { auditCalls, explainUnresolved, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
7
+ export { celNamespaceNames, MODULE_CALL_DISPATCH_KEY, moduleCallNames, moduleCallOf, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
9
8
  export { walkCelExpressions } from "./cel/walk.js";
10
9
  export { celEngine } from "./engines/cel.js";
11
10
  export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, type NormalizedIncludePath, } from "./engines/include.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sour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AAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,0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kB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,19 @@
1
- export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, deriveSignatures, } from "./cel/environment.js";
2
- export { celFunctionCatalog, CEL_FUNCTIONS, } from "./cel/catalog.js";
3
- export { compileExpression } from "./cel/compile.js";
1
+ export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, celFunctionCatalog, } from "./cel/environment.js";
2
+ // `namespaceDispatchOf` is the ONE adapter a host's dispatch table crosses to
3
+ // become the engine's namespace seam — exported because the analyzer evaluates
4
+ // rule conditions and function bodies through the same table, and a second
5
+ // adapter is what let it convert arguments differently from the kernel.
6
+ export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
4
7
  export { registerValueBrands } from "./cel/value-brands.js";
5
8
  export { interpolationShape, literalFragments, readInterpolationHoles, } from "./cel/interpolation-holes.js";
6
9
  export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
7
- export { auditCalls, explainUnresolved, functionIndex, } from "./cel/diagnose.js";
10
+ export { auditCalls, explainUnresolved, } from "./cel/diagnose.js";
8
11
  // The rewrite, its reader, and the activation key the kernel binds a scope's
9
12
  // dispatch table under. The unbound message and the receiver and bound-name
10
13
  // walks are read inside this package only.
11
14
  // `ModuleCallTypeResolver` is here because `AnalyzeEnv` names it: an exported
12
15
  // interface whose field type cannot be named is not usable from outside.
13
- export { MODULE_CALL_DISPATCH_KEY, moduleCallOf, resolveModuleCalls, } from "./cel/module-call.js";
16
+ export { celNamespaceNames, MODULE_CALL_DISPATCH_KEY, moduleCallNames, moduleCallOf, } from "./cel/module-call.js";
14
17
  export { walkCelExpressions } from "./cel/walk.js";
15
18
  export { celEngine } from "./engines/cel.js";
16
19
  export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, } from "./engines/include.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/templating",
3
- "version": "0.107.0",
3
+ "version": "0.108.0",
4
4
  "description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -35,18 +35,18 @@
35
35
  "src/**"
36
36
  ],
37
37
  "dependencies": {
38
- "@marcbachmann/cel-js": "7.6.1",
39
38
  "d3-format": "3.1.2",
40
39
  "re2js": "2.8.3",
41
40
  "uuid": "14.0.1",
42
- "yaml": "^2.8.3"
41
+ "yaml": "^2.8.3",
42
+ "@telorun/cel": "0.108.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/d3-format": "^3.0.4",
46
46
  "@types/node": "^20.0.0",
47
47
  "typescript": "^5.0.0",
48
48
  "vitest": "^2.1.8",
49
- "@telorun/sdk": "0.107.0"
49
+ "@telorun/sdk": "0.108.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@telorun/sdk": "*"
package/src/builtins.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Environment } from "@marcbachmann/cel-js";
1
+ import type { CelEnvironment } from "@telorun/cel";
2
2
  import { celEngine } from "./engines/cel.js";
3
3
  import { includeBytesEngine, includeTextEngine } from "./engines/include.js";
4
4
  import { interpolateEngine } from "./engines/interpolate.js";
@@ -67,7 +67,7 @@ export function celExpressionsOf(engineName: string, source: string): string[] {
67
67
  * The single reader of `TemplatingEngine.repeatable`, so a consumer comparing
68
68
  * two tagged scalars never recognises a tag by name.
69
69
  */
70
- export function repeatableSource(engineName: string, source: string, celEnv: Environment): boolean {
70
+ export function repeatableSource(engineName: string, source: string, celEnv: CelEnvironment): boolean {
71
71
  return defaultRegistry().get(engineName)?.repeatable?.(source, celEnv) ?? false;
72
72
  }
73
73