@telorun/templating 0.107.0 → 0.109.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,11 +1,27 @@
1
- import { Environment } from "@marcbachmann/cel-js";
2
- import { Stream } from "@telorun/sdk";
3
- import { CEL_FUNCTIONS, type CelHandlers } from "./catalog.js";
4
- import { assertCelValueIdentity, SDK_CEL_VALUE_CLASSES } from "./value-identity.js";
5
-
6
- export type { CelHandlers } from "./catalog.js";
1
+ /**
2
+ * The two environments, now built on `@telorun/cel`.
3
+ *
4
+ * **The dialect is no longer declared here.** Telo's 67 functions and their 86 signatures
5
+ * ship inside the engine as data plus implementations, registered through the very
6
+ * `registerFunction` a host uses, so this package no longer carries a catalog table of its
7
+ * own: `registerFunctionCatalog` is what the dialect IS, and `functionCatalog()` is the one
8
+ * listing surface `telo cel functions` reads. What is left here is the pair of environments
9
+ * and the host handlers — the only part that was ever this package's.
10
+ *
11
+ * A second engine reproduces the two separately, so they stay named separately:
12
+ * `buildCelLanguageEnvironment()` is CEL under Telo's options and nothing else, and
13
+ * `buildCelEnvironment(handlers?)` is the dialect built on it.
14
+ */
15
+ import {
16
+ CelEnvironment,
17
+ functionCatalog,
18
+ registerFunctionCatalog,
19
+ type CelCatalogHandlers,
20
+ } from "@telorun/cel";
7
21
 
8
- assertCelValueIdentity(SDK_CEL_VALUE_CLASSES);
22
+ /** The nine functions the host answers for. The engine's own seam, re-exported so a
23
+ * consumer naming it does not have to name the engine. */
24
+ export type CelHandlers = CelCatalogHandlers;
9
25
 
10
26
  const stub = (name: string) => () => {
11
27
  throw new Error(
@@ -14,6 +30,14 @@ const stub = (name: string) => () => {
14
30
  );
15
31
  };
16
32
 
33
+ /**
34
+ * What a host-backed function does where the host supplied nothing.
35
+ *
36
+ * The engine's own answer for a missing handler is the `unbound_function` error VALUE,
37
+ * naming the function — which is what an analyzer wants, since it never evaluates. These
38
+ * throw instead, keeping the message this package has always produced for a caller that
39
+ * built an analyzer-only environment and then evaluated through it.
40
+ */
17
41
  const STUB_HANDLERS: CelHandlers = {
18
42
  sha256: stub("sha256"),
19
43
  md5: stub("md5"),
@@ -26,94 +50,47 @@ const STUB_HANDLERS: CelHandlers = {
26
50
  joinPath: stub("joinPath"),
27
51
  };
28
52
 
29
- /** Build a CEL `Environment` with Telo's stdlib. Every function comes from the
30
- * single-source catalog (`CEL_FUNCTIONS`), so registration and the documented
31
- * surface (`telo cel functions`) can never drift. Always registers the same
32
- * signatures (so `env.check()` succeeds for type-inference); the host-injected
33
- * handlers govern what `hostBacked` functions do at runtime. Analyzer-only
34
- * callers can omit handlers (the stubs throw if such a function is evaluated);
35
- * runtime callers (kernel) supply real ones.
36
- *
37
- * Also registers the `Stream` object type, backed by the `Stream` class from
38
- * `@telorun/sdk`. CEL's type-checker rejects values whose constructor isn't
39
- * Object/Map/Array/Set/registered; producers that need to expose an
40
- * `AsyncIterable` through a stream-typed property must wrap the iterable in
41
- * `new Stream(...)` so its constructor is the registered class. The type has
42
- * no fields, so terminal access (passing the value through CEL) succeeds but
43
- * member access raises a CEL error at runtime — matching the analyzer's
44
- * static check on `x-telo-stream`-marked properties. */
45
- /** Expand a documented signature that may contain `type?`-marked optional
46
- * parameters into one cel-js registration signature per arity. For example,
47
- * `"nowIso(string?): string"` produces `["nowIso(): string",
48
- * "nowIso(string): string"]`. Required parameters must precede optional ones.
49
- * Returns `[signature]` unchanged when no `?` is present or the signature
50
- * cannot be parsed. */
51
- export function deriveSignatures(signature: string): string[] {
52
- const m = signature.match(/^(\w+)\((.*?)\):\s*(.+)$/);
53
- if (!m) return [signature];
54
- const name = m[1]!;
55
- const paramsStr = m[2]!.trim();
56
- const returnType = m[3]!.trim();
57
- if (!paramsStr.includes("?")) return [signature];
58
-
59
- const params = paramsStr.split(",").map((p) => p.trim());
60
- const required: string[] = [];
61
- const optional: string[] = [];
62
- for (const p of params) {
63
- if (p.endsWith("?")) {
64
- optional.push(p.slice(0, -1));
65
- } else {
66
- if (optional.length > 0) return [signature];
67
- required.push(p);
68
- }
69
- }
70
- if (optional.length === 0) return [signature];
71
-
72
- return Array.from({ length: optional.length + 1 }, (_, i) => {
73
- const allParams = [...required, ...optional.slice(0, i)];
74
- return `${name}(${allParams.join(", ")}): ${returnType}`;
75
- });
76
- }
77
-
78
- /** cel-go defaults HomogeneousAggregateLiterals OFF: heterogeneous list/map
79
- * literals unify to `dyn` rather than erroring. cel-js flips that default to
80
- * strict; we align with cel-go so manifests (dyn-heavy: request, rows, …)
81
- * don't hit false positives the runtime evaluates fine. */
53
+ /**
54
+ * cel-go defaults HomogeneousAggregateLiterals OFF: heterogeneous list/map literals unify
55
+ * to `dyn` rather than erroring, which is what a manifest needs (`request`, rows, …).
56
+ * `unlistedVariablesAreDyn` is on because a host types only part of what a site may read,
57
+ * and optional types are on because the manifest surface uses them.
58
+ */
82
59
  const ENVIRONMENT_OPTIONS = {
83
60
  unlistedVariablesAreDyn: true,
84
61
  enableOptionalTypes: true,
85
62
  homogeneousAggregateLiterals: false,
86
63
  } as const;
87
64
 
88
- /** The environment before any Telo function is registered — i.e. exactly
89
- * cel-js's own built-ins. Documentation needs to tell the two apart, and
90
- * subtracting by signature TEXT does not work: cel-js normalizes a declared
91
- * `list` to `list<dyn>`, so the catalog's documented spelling and the
92
- * registered one differ for a third of the entries. Asking for the base set
93
- * directly needs no matching at all. */
94
- export function celBuiltinFunctions(): ReturnType<Environment["getDefinitions"]>["functions"] {
95
- return buildCelLanguageEnvironment().getDefinitions().functions;
65
+ /**
66
+ * The bare CEL language under Telo's options: the standard library and nothing else — no
67
+ * catalog, no `Stream`. The dialect is built on it, and the language conformance vectors
68
+ * run against it.
69
+ */
70
+ export function buildCelLanguageEnvironment(): CelEnvironment {
71
+ return new CelEnvironment(ENVIRONMENT_OPTIONS);
72
+ }
73
+
74
+ /**
75
+ * Every function the LANGUAGE declares, for documentation that must tell the language and
76
+ * the dialect apart. Subtracting by signature text does not work — a declared `list` is
77
+ * normalized — so the base set is asked for directly.
78
+ */
79
+ export function celBuiltinFunctions(): ReturnType<CelEnvironment["definitions"]>["functions"] {
80
+ return buildCelLanguageEnvironment().definitions().functions;
96
81
  }
97
82
 
98
- /** The bare CEL language under Telo's options: cel-js's built-ins and nothing
99
- * else — no catalog, no `Stream`. The dialect is built on it, and the
100
- * language conformance vectors (`templating/cel-conformance/`) run against it. */
101
- export function buildCelLanguageEnvironment(): Environment {
102
- return new Environment(ENVIRONMENT_OPTIONS);
83
+ /** Telo's dialect: the language, the function catalog, and the live `Stream` type. */
84
+ export function buildCelEnvironment(handlers: Partial<CelHandlers> = {}): CelEnvironment {
85
+ const environment = buildCelLanguageEnvironment();
86
+ registerFunctionCatalog(environment, { handlers: { ...STUB_HANDLERS, ...handlers } });
87
+ // A live handle: `dyn` underneath with no conversion and no member, so reading anything
88
+ // off one is refused at check. It needs no constructor — identity by class is what the
89
+ // engine replaced, and at runtime a stream is whatever the producer handed over.
90
+ return environment.registerType({ name: "Stream", base: "dyn" });
103
91
  }
104
92
 
105
- export function buildCelEnvironment(handlers: Partial<CelHandlers> = {}): Environment {
106
- const h: CelHandlers = { ...STUB_HANDLERS, ...handlers };
107
- let env = buildCelLanguageEnvironment();
108
- for (const fn of CEL_FUNCTIONS) {
109
- const impl = fn.build(h);
110
- // `register` lists one cel-js signature per arity (overloaded functions).
111
- // When absent, `deriveSignatures` expands `type?` optional-param notation
112
- // into one registration per arity — so `nowIso(string?): string` registers
113
- // both `nowIso(): string` and `nowIso(string): string` automatically.
114
- for (const sig of fn.register ?? deriveSignatures(fn.signature)) {
115
- env = env.registerFunction(sig, impl);
116
- }
117
- }
118
- return env.registerType("Stream", Stream as unknown as new (...args: unknown[]) => unknown);
93
+ /** The dialect's functions as the one listing surface answers them. */
94
+ export function celFunctionCatalog(): ReturnType<typeof functionCatalog> {
95
+ return functionCatalog();
119
96
  }