@telorun/templating 0.22.0 → 0.24.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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/builtins.d.ts +8 -0
  3. package/dist/builtins.d.ts.map +1 -1
  4. package/dist/builtins.js +13 -0
  5. package/dist/cel/analyze.d.ts +4 -0
  6. package/dist/cel/analyze.d.ts.map +1 -1
  7. package/dist/cel/analyze.js +9 -0
  8. package/dist/cel/catalog.d.ts.map +1 -1
  9. package/dist/cel/catalog.js +12 -4
  10. package/dist/cel/compile.d.ts +4 -26
  11. package/dist/cel/compile.d.ts.map +1 -1
  12. package/dist/cel/compile.js +3 -88
  13. package/dist/cel/interpolation-holes.d.ts +43 -0
  14. package/dist/cel/interpolation-holes.d.ts.map +1 -0
  15. package/dist/cel/interpolation-holes.js +121 -0
  16. package/dist/cel/walk.d.ts +7 -28
  17. package/dist/cel/walk.d.ts.map +1 -1
  18. package/dist/cel/walk.js +21 -40
  19. package/dist/engine.d.ts +14 -0
  20. package/dist/engine.d.ts.map +1 -1
  21. package/dist/engines/cel.d.ts +7 -0
  22. package/dist/engines/cel.d.ts.map +1 -1
  23. package/dist/engines/cel.js +29 -12
  24. package/dist/engines/hole-analysis.d.ts +23 -0
  25. package/dist/engines/hole-analysis.d.ts.map +1 -0
  26. package/dist/engines/hole-analysis.js +66 -0
  27. package/dist/engines/interpolate.d.ts +13 -0
  28. package/dist/engines/interpolate.d.ts.map +1 -0
  29. package/dist/engines/interpolate.js +123 -0
  30. package/dist/engines/sql.d.ts +3 -3
  31. package/dist/engines/sql.d.ts.map +1 -1
  32. package/dist/engines/sql.js +24 -58
  33. package/dist/index.d.ts +6 -4
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +4 -2
  36. package/dist/sentinel.d.ts +4 -5
  37. package/dist/sentinel.d.ts.map +1 -1
  38. package/dist/sentinel.js +6 -14
  39. package/package.json +2 -2
  40. package/src/builtins.ts +14 -0
  41. package/src/cel/analyze.ts +12 -0
  42. package/src/cel/catalog.ts +14 -4
  43. package/src/cel/compile.ts +4 -92
  44. package/src/cel/interpolation-holes.ts +138 -0
  45. package/src/cel/walk.ts +23 -56
  46. package/src/engine.ts +16 -0
  47. package/src/engines/cel.ts +36 -14
  48. package/src/engines/hole-analysis.ts +96 -0
  49. package/src/engines/interpolate.ts +139 -0
  50. package/src/engines/sql.ts +26 -67
  51. package/src/index.ts +12 -7
  52. package/src/sentinel.ts +6 -14
package/README.md CHANGED
@@ -37,7 +37,7 @@ $ telo ./examples/todo-app
37
37
 
38
38
  ## What It Does
39
39
 
40
- - **Loads** YAML resources and compiles CEL expressions (`${{ }}`) into an in-memory registry.
40
+ - **Loads** YAML resources and compiles CEL expressions (`!cel`, `!interpolate`) into an in-memory registry.
41
41
  - **Resolves** resource dependencies via a multi-pass init loop, handling ordering automatically.
42
42
  - **Indexes** resources by Kind and Name for constant-time lookup.
43
43
  - **Dispatches** execution to the controller that owns each Kind.
@@ -19,6 +19,14 @@ export declare function createDefaultRegistry(): TemplatingEngineRegistry;
19
19
  * configuration, and every host ships the same built-in set.
20
20
  */
21
21
  export declare function producedTypeOf(engineName: string): Record<string, unknown> | undefined;
22
+ /**
23
+ * The CEL expressions a tagged scalar holds — its whole source under `!cel`,
24
+ * each hole under a tag with holes, none under a tag holding no CEL.
25
+ *
26
+ * The single reader of `TemplatingEngine.expressionRegions`, so an analysis pass
27
+ * asking "what CEL is written here" never recognises a tag by name.
28
+ */
29
+ export declare function celExpressionsOf(engineName: string, source: string): string[];
22
30
  /** Memoized singleton: returns the default registry. Hosts that don't need
23
31
  * per-instance isolation (precompile, the analyzer's tagged-value walker)
24
32
  * should use this so they share the same registry instance the YAML tag
@@ -1 +1 @@
1
- {"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;gEAKgE;AAChE,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EAQrD,CAAC;AAEF,wBAAgB,qBAAqB,IAAI,wBAAwB,CAMhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAEtF;AAID;;;oBAGoB;AACpB,wBAAgB,eAAe,IAAI,wBAAwB,CAK1D"}
1
+ {"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;gEAKgE;AAChE,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EASrD,CAAC;AAEF,wBAAgB,qBAAqB,IAAI,wBAAwB,CAMhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAEtF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAG7E;AAID;;;oBAGoB;AACpB,wBAAgB,eAAe,IAAI,wBAAwB,CAK1D"}
package/dist/builtins.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { celEngine } from "./engines/cel.js";
2
2
  import { includeBytesEngine, includeTextEngine } from "./engines/include.js";
3
+ import { interpolateEngine } from "./engines/interpolate.js";
3
4
  import { literalEngine } from "./engines/literal.js";
4
5
  import { modulePathEngine } from "./engines/module-path.js";
5
6
  import { refEngine } from "./engines/ref.js";
@@ -15,6 +16,7 @@ export const builtinEngines = [
15
16
  celEngine,
16
17
  includeBytesEngine,
17
18
  includeTextEngine,
19
+ interpolateEngine,
18
20
  literalEngine,
19
21
  modulePathEngine,
20
22
  refEngine,
@@ -40,6 +42,17 @@ export function createDefaultRegistry() {
40
42
  export function producedTypeOf(engineName) {
41
43
  return defaultRegistry().get(engineName)?.producedType?.();
42
44
  }
45
+ /**
46
+ * The CEL expressions a tagged scalar holds — its whole source under `!cel`,
47
+ * each hole under a tag with holes, none under a tag holding no CEL.
48
+ *
49
+ * The single reader of `TemplatingEngine.expressionRegions`, so an analysis pass
50
+ * asking "what CEL is written here" never recognises a tag by name.
51
+ */
52
+ export function celExpressionsOf(engineName, source) {
53
+ const regions = defaultRegistry().get(engineName)?.expressionRegions?.(source) ?? [];
54
+ return regions.map((r) => source.slice(r.start, r.end));
55
+ }
43
56
  let defaultRegistryCache;
44
57
  /** Memoized singleton: returns the default registry. Hosts that don't need
45
58
  * per-instance isolation (precompile, the analyzer's tagged-value walker)
@@ -42,6 +42,10 @@ interface NullableIssue {
42
42
  /** The member accessed on it (e.g. "code", or "[index]"). */
43
43
  member: string;
44
44
  }
45
+ /** The dotted chain an expression IS, when it is a plain chain whose schema
46
+ * admits null — a value that may itself be null, rather than one dereferenced
47
+ * through a null. */
48
+ export declare function nullableValueChain(node: ASTNode, contextSchema: Record<string, any>): string | null;
45
49
  /**
46
50
  * Find member accesses on a nullable value that are not null-guarded in the
47
51
  * surrounding expression. A context field whose schema admits `null` (e.g. the
@@ -1 +1 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAIpD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAI7D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE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MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAI3E;AAqCD,UAAU,aAAa;IACrB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AA0BD;;sBAEsB;AACtB,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,MAAM,GAAG,IAAI,CAIf;AA4DD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,aAAa,EAAE,CAIjB;AA4GD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,GAAG,IAAI,CAwCf"}
@@ -221,6 +221,15 @@ function schemaAtChain(chain, schema) {
221
221
  }
222
222
  return current;
223
223
  }
224
+ /** The dotted chain an expression IS, when it is a plain chain whose schema
225
+ * admits null — a value that may itself be null, rather than one dereferenced
226
+ * through a null. */
227
+ export function nullableValueChain(node, contextSchema) {
228
+ const chain = dottedChain(node, new Set());
229
+ if (chain === null)
230
+ return null;
231
+ return schemaIsNullable(schemaAtChain(chain.split("."), contextSchema)) ? chain : null;
232
+ }
224
233
  function isNullLiteral(node) {
225
234
  return node.op === "value" && node.args === null;
226
235
  }
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/cel/catalog.ts"],"names":[],"mappings":"AAIA;;;0DAG0D;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} from "uuid";
4
+ import { PLAIN_ENCODINGS } from "@telorun/sdk";
4
5
  /** RE2 regex engine for the CEL `regex*` functions — `re2js`, a pure-JS port of
5
6
  * Google's RE2. The dialect is RE2 (linear-time, no backtracking, ReDoS-safe) —
6
7
  * never JS `RegExp` — so a manifest's regex behaves the same across runtimes.
@@ -982,15 +983,22 @@ export const CEL_FUNCTIONS = [
982
983
  // so an expiry could be computed and not stored. Semantics follow cel-go
983
984
  // exactly — RFC 3339 and epoch SECONDS — so `int(timestamp)` and
984
985
  // `timestamp(int)` round-trip in one unit.
986
+ //
987
+ // `string(duration)` is cel-spec's too, and cel-js omits it: seconds with a
988
+ // trimmed fraction, the `Telo.Duration` plain encoding, so a duration renders
989
+ // one way whether it is interpolated or serialized.
985
990
  {
986
991
  name: "string",
987
- signature: "string(timestamp): string",
988
- register: ["string(google.protobuf.Timestamp): string"],
992
+ signature: "string(timestamp | duration): string",
993
+ register: [
994
+ "string(google.protobuf.Timestamp): string",
995
+ "string(google.protobuf.Duration): string",
996
+ ],
989
997
  category: "conversion",
990
- summary: "Format an instant as RFC 3339 (ISO-8601, UTC).",
998
+ summary: "Format an instant as RFC 3339 (ISO-8601, UTC), or a duration as seconds with a trimmed fraction (`5400s`, `1.5s`).",
991
999
  deterministic: true,
992
1000
  hostBacked: false,
993
- build: () => (t) => t.toISOString(),
1001
+ build: () => (value) => value instanceof Date ? value.toISOString() : PLAIN_ENCODINGS["cel-duration"].encode(value),
994
1002
  },
995
1003
  {
996
1004
  name: "int",
@@ -1,10 +1,8 @@
1
- import { type CompiledValue } from "@telorun/sdk";
1
+ import type { CompiledValue } from "@telorun/sdk";
2
2
  import type { Environment } from "@marcbachmann/cel-js";
3
- export declare const TEMPLATE_REGEX: RegExp;
4
- export declare const EXACT_TEMPLATE_REGEX: RegExp;
5
- /** Compile a single CEL expression (no `${{ }}` wrapping) into a CompiledValue.
6
- * Throws on syntax errors. Used by the `!cel` engine where the entire tagged
7
- * scalar is treated as one expression.
3
+ /** Compile a single CEL expression into a CompiledValue. Throws on syntax
4
+ * errors. The `!cel` engine compiles its whole scalar with it, and the tags
5
+ * with holes compile each hole.
8
6
  *
9
7
  * `moduleNames` are the declaring module's own names; a call whose receiver is
10
8
  * one of them resolves to a late-bound module call HERE, on the parsed tree, so
@@ -12,24 +10,4 @@ export declare const EXACT_TEMPLATE_REGEX: RegExp;
12
10
  * kernel's dependency walk — sees the resolved shape rather than re-deriving
13
11
  * it from the source text. */
14
12
  export declare function compileExpression(expr: string, env: Environment, moduleNames?: ReadonlySet<string>): CompiledValue;
15
- /** Compile a string that may contain `${{ }}`-delimited CEL segments. If the
16
- * string is exactly one expression, returns a single CompiledValue. If it
17
- * contains interpolations, returns a CompiledValue that joins literal parts
18
- * with stringified expression results. If no expressions are present, returns
19
- * the input string unchanged. Throws on CEL syntax errors. */
20
- export declare function compileString(s: string, env: Environment, moduleNames?: ReadonlySet<string>): unknown;
21
- /** Split an interpolated value into literal fragments and the evaluated values
22
- * of its embedded expressions, instead of joining them into one string. Lets a
23
- * consumer emit its own placeholders between fragments and bind the values
24
- * separately (e.g. parameterized SQL). The invariant
25
- * `fragments.length === values.length + 1` always holds.
26
- *
27
- * - plain string (no `${{ }}`) → `{ fragments: [s], values: [] }`
28
- * - bare single expression `${{ x }}` → `{ fragments: ["", ""], values: [x] }`
29
- * - interpolated `"a ${{ x }} b"` → `{ fragments: ["a ", " b"], values: [x] }`
30
- */
31
- export declare function toParameterized(value: unknown, ctx: Record<string, unknown>): {
32
- fragments: string[];
33
- values: unknown[];
34
- };
35
13
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKjE,eAAO,MAAM,cAAc,QAA8B,CAAC;AAC1D,eAAO,MAAM,oBAAoB,QAAqC,CAAC;AAoCvE;;;;;;;;+BAQ+B;AAC/B,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,aAAa,CAYf;AAED;;;;+DAI+D;AAC/D,wBAAgB,aAAa,CAC3B,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,OAAO,CAqCT;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAsB5C"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAuCjE;;;;;;;;+BAQ+B;AAC/B,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,aAAa,CAYf"}
@@ -1,9 +1,6 @@
1
- import { isCompiledValue } from "@telorun/sdk";
2
1
  import { extractAccessChains } from "./analyze.js";
3
2
  import { CEL_FUNCTIONS } from "./catalog.js";
4
3
  import { resolveModuleCalls } from "./module-call.js";
5
- export const TEMPLATE_REGEX = /\$\{\{\s*([^}]+?)\s*\}\}/g;
6
- export const EXACT_TEMPLATE_REGEX = /^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/;
7
4
  /** Root variable identifiers an expression reads, from its parsed AST — the
8
5
  * first element of every member-access chain (`self.table` → `self`). Returns
9
6
  * undefined when the parse result carries no AST so consumers can tell "no
@@ -37,9 +34,9 @@ function callsNonDeterministic(root) {
37
34
  };
38
35
  return visit(root);
39
36
  }
40
- /** Compile a single CEL expression (no `${{ }}` wrapping) into a CompiledValue.
41
- * Throws on syntax errors. Used by the `!cel` engine where the entire tagged
42
- * scalar is treated as one expression.
37
+ /** Compile a single CEL expression into a CompiledValue. Throws on syntax
38
+ * errors. The `!cel` engine compiles its whole scalar with it, and the tags
39
+ * with holes compile each hole.
43
40
  *
44
41
  * `moduleNames` are the declaring module's own names; a call whose receiver is
45
42
  * one of them resolves to a late-bound module call HERE, on the parsed tree, so
@@ -59,85 +56,3 @@ export function compileExpression(expr, env, moduleNames) {
59
56
  call: (ctx) => fn(ctx),
60
57
  };
61
58
  }
62
- /** Compile a string that may contain `${{ }}`-delimited CEL segments. If the
63
- * string is exactly one expression, returns a single CompiledValue. If it
64
- * contains interpolations, returns a CompiledValue that joins literal parts
65
- * with stringified expression results. If no expressions are present, returns
66
- * the input string unchanged. Throws on CEL syntax errors. */
67
- export function compileString(s, env, moduleNames) {
68
- if (!s.includes("${{"))
69
- return s;
70
- const exact = s.match(EXACT_TEMPLATE_REGEX);
71
- if (exact) {
72
- return compileExpression(exact[1].trim(), env, moduleNames);
73
- }
74
- const parts = [];
75
- let last = 0;
76
- for (const m of s.matchAll(TEMPLATE_REGEX)) {
77
- if (m.index > last)
78
- parts.push(s.slice(last, m.index));
79
- parts.push(compileExpression(m[1].trim(), env, moduleNames));
80
- last = m.index + m[0].length;
81
- }
82
- if (last < s.length)
83
- parts.push(s.slice(last));
84
- const refs = new Set();
85
- const calls = new Set();
86
- let volatile = false;
87
- for (const p of parts) {
88
- if (typeof p === "string")
89
- continue;
90
- if (p.refs)
91
- for (const r of p.refs)
92
- refs.add(r);
93
- if (p.calls)
94
- for (const c of p.calls)
95
- calls.add(c);
96
- if (p.volatile)
97
- volatile = true;
98
- }
99
- return {
100
- __compiled: true,
101
- source: s,
102
- parts,
103
- refs: [...refs],
104
- calls: [...calls],
105
- ...(volatile ? { volatile: true } : {}),
106
- call: (ctx) => parts.map((p) => (typeof p === "string" ? p : String(p.call(ctx) ?? ""))).join(""),
107
- };
108
- }
109
- /** Split an interpolated value into literal fragments and the evaluated values
110
- * of its embedded expressions, instead of joining them into one string. Lets a
111
- * consumer emit its own placeholders between fragments and bind the values
112
- * separately (e.g. parameterized SQL). The invariant
113
- * `fragments.length === values.length + 1` always holds.
114
- *
115
- * - plain string (no `${{ }}`) → `{ fragments: [s], values: [] }`
116
- * - bare single expression `${{ x }}` → `{ fragments: ["", ""], values: [x] }`
117
- * - interpolated `"a ${{ x }} b"` → `{ fragments: ["a ", " b"], values: [x] }`
118
- */
119
- export function toParameterized(value, ctx) {
120
- if (typeof value === "string")
121
- return { fragments: [value], values: [] };
122
- if (!isCompiledValue(value)) {
123
- throw new Error("toParameterized expects a string or CompiledValue");
124
- }
125
- if (!value.parts) {
126
- return { fragments: ["", ""], values: [value.call(ctx)] };
127
- }
128
- const fragments = [];
129
- const values = [];
130
- let current = "";
131
- for (const p of value.parts) {
132
- if (typeof p === "string") {
133
- current += p;
134
- }
135
- else {
136
- fragments.push(current);
137
- current = "";
138
- values.push(p.call(ctx));
139
- }
140
- }
141
- fragments.push(current);
142
- return { fragments, values };
143
- }
@@ -0,0 +1,43 @@
1
+ /** One `${{ expr }}` hole in a scalar. Offsets index the scalar's source. */
2
+ export interface InterpolationHole {
3
+ /** Offset of the opening `${{`. */
4
+ readonly start: number;
5
+ /** Offset just past the closing `}}`. */
6
+ readonly end: number;
7
+ /** The expression, trimmed of the whitespace inside the delimiters. */
8
+ readonly expr: string;
9
+ /** Offset of {@link expr} within the source. */
10
+ readonly exprStart: number;
11
+ }
12
+ export type HoleReading = {
13
+ readonly ok: true;
14
+ readonly holes: readonly InterpolationHole[];
15
+ } | {
16
+ readonly ok: false;
17
+ readonly offset: number;
18
+ readonly message: string;
19
+ };
20
+ /** How a scalar's text relates to holes: none at all, exactly one hole with only
21
+ * whitespace around it, holes among text, or a `${{` that opens no readable
22
+ * hole. */
23
+ export type InterpolationShape = "none" | "lone-hole" | "interpolated" | "malformed";
24
+ /**
25
+ * Every `${{ expr }}` hole in `source` — the one hole grammar every tag with
26
+ * holes (`!interpolate`, `!sql`) and the untagged-interpolation migration read.
27
+ *
28
+ * A hole opens at `${{` and closes at the first `}}` that is outside a CEL
29
+ * string literal and outside any `{` the expression itself opened, so a map
30
+ * literal or a string holding braces is read whole. String literals follow CEL's
31
+ * lexical grammar: `'`, `"`, their triple-quoted forms, and the `r`/`b` prefixes,
32
+ * where a raw string takes no escapes. Outside a hole nothing is special but
33
+ * `${{`; a literal `${{` is written as a hole yielding it (`${{ '${{' }}`).
34
+ *
35
+ * A hole that never closes is a reading failure at its opening offset, never a
36
+ * guess at where it meant to end.
37
+ */
38
+ export declare function readInterpolationHoles(source: string): HoleReading;
39
+ /** The shape of `source` under {@link readInterpolationHoles}. */
40
+ export declare function interpolationShape(source: string): InterpolationShape;
41
+ /** The literal text between holes: always `holes.length + 1` fragments. */
42
+ export declare function literalFragments(source: string, holes: readonly InterpolationHole[]): string[];
43
+ //# sourceMappingURL=interpolation-holes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolation-holes.d.ts","sourceRoot":"","sources":["../../src/cel/interpolation-holes.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,GACnE;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E;;YAEY;AACZ,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,WAAW,GAAG,cAAc,GAAG,WAAW,CAAC;AAIrF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAwBlE;AAED,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAWrE;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,iBAAiB,EAAE,GAAG,MAAM,EAAE,CAS9F"}
@@ -0,0 +1,121 @@
1
+ const OPEN = "${{";
2
+ /**
3
+ * Every `${{ expr }}` hole in `source` — the one hole grammar every tag with
4
+ * holes (`!interpolate`, `!sql`) and the untagged-interpolation migration read.
5
+ *
6
+ * A hole opens at `${{` and closes at the first `}}` that is outside a CEL
7
+ * string literal and outside any `{` the expression itself opened, so a map
8
+ * literal or a string holding braces is read whole. String literals follow CEL's
9
+ * lexical grammar: `'`, `"`, their triple-quoted forms, and the `r`/`b` prefixes,
10
+ * where a raw string takes no escapes. Outside a hole nothing is special but
11
+ * `${{`; a literal `${{` is written as a hole yielding it (`${{ '${{' }}`).
12
+ *
13
+ * A hole that never closes is a reading failure at its opening offset, never a
14
+ * guess at where it meant to end.
15
+ */
16
+ export function readInterpolationHoles(source) {
17
+ const holes = [];
18
+ let from = 0;
19
+ for (;;) {
20
+ const start = source.indexOf(OPEN, from);
21
+ if (start === -1)
22
+ return { ok: true, holes };
23
+ const close = closingOffset(source, start + OPEN.length);
24
+ if (close === undefined) {
25
+ return {
26
+ ok: false,
27
+ offset: start,
28
+ message: `the hole opened at offset ${start} never closes — a hole ends at the first '}}' outside a string literal and outside any braces it opened`,
29
+ };
30
+ }
31
+ const body = source.slice(start + OPEN.length, close);
32
+ const lead = body.length - body.trimStart().length;
33
+ holes.push({
34
+ start,
35
+ end: close + 2,
36
+ expr: body.trim(),
37
+ exprStart: start + OPEN.length + lead,
38
+ });
39
+ from = close + 2;
40
+ }
41
+ }
42
+ /** The shape of `source` under {@link readInterpolationHoles}. */
43
+ export function interpolationShape(source) {
44
+ if (!source.includes(OPEN))
45
+ return "none";
46
+ const reading = readInterpolationHoles(source);
47
+ if (!reading.ok)
48
+ return "malformed";
49
+ const [only, ...rest] = reading.holes;
50
+ if (!only)
51
+ return "none";
52
+ const lone = rest.length === 0 &&
53
+ source.slice(0, only.start).trim() === "" &&
54
+ source.slice(only.end).trim() === "";
55
+ return lone ? "lone-hole" : "interpolated";
56
+ }
57
+ /** The literal text between holes: always `holes.length + 1` fragments. */
58
+ export function literalFragments(source, holes) {
59
+ const out = [];
60
+ let last = 0;
61
+ for (const hole of holes) {
62
+ out.push(source.slice(last, hole.start));
63
+ last = hole.end;
64
+ }
65
+ out.push(source.slice(last));
66
+ return out;
67
+ }
68
+ /** Offset of the `}}` closing a hole whose body starts at `from`. */
69
+ function closingOffset(source, from) {
70
+ let depth = 0;
71
+ let i = from;
72
+ while (i < source.length) {
73
+ const c = source[i];
74
+ if (c === "'" || c === '"') {
75
+ const after = skipString(source, i);
76
+ if (after === undefined)
77
+ return undefined;
78
+ i = after;
79
+ continue;
80
+ }
81
+ if (c === "{")
82
+ depth++;
83
+ else if (c === "}") {
84
+ if (depth === 0)
85
+ return source[i + 1] === "}" ? i : undefined;
86
+ depth--;
87
+ }
88
+ i++;
89
+ }
90
+ return undefined;
91
+ }
92
+ /** Offset just past the string literal whose opening quote is at `quoteAt`. */
93
+ function skipString(source, quoteAt) {
94
+ const quote = source[quoteAt];
95
+ const raw = /[rR]/.test(literalPrefix(source, quoteAt));
96
+ const triple = source.startsWith(quote.repeat(3), quoteAt);
97
+ const delimiter = triple ? quote.repeat(3) : quote;
98
+ let i = quoteAt + delimiter.length;
99
+ while (i < source.length) {
100
+ if (!raw && source[i] === "\\") {
101
+ i += 2;
102
+ continue;
103
+ }
104
+ if (!triple && source[i] === "\n")
105
+ return undefined;
106
+ if (source.startsWith(delimiter, i))
107
+ return i + delimiter.length;
108
+ i++;
109
+ }
110
+ return undefined;
111
+ }
112
+ /** The `r`/`b` prefix letters written immediately before a quote, when they are
113
+ * a prefix rather than the tail of an identifier. */
114
+ function literalPrefix(source, quoteAt) {
115
+ let i = quoteAt;
116
+ while (i > 0 && quoteAt - i < 2 && /[rRbB]/.test(source[i - 1]))
117
+ i--;
118
+ if (i > 0 && /[A-Za-z0-9_]/.test(source[i - 1]))
119
+ return "";
120
+ return source.slice(i, quoteAt);
121
+ }
@@ -1,29 +1,8 @@
1
- /** How an emitted expression sits in the scalar it came from. A repair can be
2
- * applied by replacing the scalar only when the expression covers all of it;
3
- * otherwise the literal text around it would be lost.
4
- *
5
- * `wrapper` is the delimiter text to restore around a corrected expression —
6
- * empty for a tagged sentinel (whose scalar *is* the expression), `${{` / `}}`
7
- * for the legacy interpolation form. Carrying it as data rather than letting
8
- * each consumer re-derive it is what keeps `${{ … }}` a first-class fix site
9
- * instead of an exclusion: the two surfaces differ only by these delimiters. */
10
- export interface CelSurface {
11
- readonly whole: boolean;
12
- readonly wrapper?: {
13
- readonly prefix: string;
14
- readonly suffix: string;
15
- };
16
- }
17
- /** Walks `value` and emits each templated source segment with its dotted
18
- * path (e.g. `routes[0].handler.body`) and the engine that owns it.
19
- *
20
- * - Untagged strings: every `${{ ... }}` segment is emitted with
21
- * `engineName = "cel"` (the implicit engine for the legacy interpolation
22
- * syntax).
23
- * - Tagged sentinels: emitted once with the sentinel's declared engine.
24
- * This includes engines that may produce no diagnostics (`literal`) —
25
- * routing through the registry stays generic so adding a third engine
26
- * that wants real analysis doesn't require touching the walker.
27
- * - Compiled values are skipped so a precompiled tree won't be re-walked. */
28
- export declare function walkCelExpressions(value: unknown, path: string, cb: (source: string, path: string, engineName: string, surface: CelSurface) => void): void;
1
+ /** Walks `value` and emits each tagged scalar with its dotted path (e.g.
2
+ * `routes[0].handler.body`) and the engine that owns it — including engines
3
+ * that produce no diagnostics (`literal`), so routing through the registry
4
+ * stays generic and a new engine needs no change here. A plain string is
5
+ * never a value's expression, and compiled values are skipped so a
6
+ * precompiled tree is not re-walked. */
7
+ export declare function walkCelExpressions(value: unknown, path: string, cb: (source: string, path: string, engineName: string) => void): void;
29
8
  //# sourceMappingURL=walk.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/cel/walk.ts"],"names":[],"mappings":"AAGA;;;;;;;;iFAQiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACzE;AAID;;;;;;;;;;8EAU8E;AAC9E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,KAAK,IAAI,GAClF,IAAI,CAyCN"}
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/cel/walk.ts"],"names":[],"mappings":"AAEA;;;;;yCAKyC;AACzC,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,GAC7D,IAAI,CAsBN"}
package/dist/cel/walk.js CHANGED
@@ -1,43 +1,13 @@
1
1
  import { isTaggedSentinel } from "../sentinel.js";
2
- import { TEMPLATE_REGEX } from "./compile.js";
3
- const OPEN = "${{";
4
- /** Walks `value` and emits each templated source segment with its dotted
5
- * path (e.g. `routes[0].handler.body`) and the engine that owns it.
6
- *
7
- * - Untagged strings: every `${{ ... }}` segment is emitted with
8
- * `engineName = "cel"` (the implicit engine for the legacy interpolation
9
- * syntax).
10
- * - Tagged sentinels: emitted once with the sentinel's declared engine.
11
- * This includes engines that may produce no diagnostics (`literal`) —
12
- * routing through the registry stays generic so adding a third engine
13
- * that wants real analysis doesn't require touching the walker.
14
- * - Compiled values are skipped so a precompiled tree won't be re-walked. */
2
+ /** Walks `value` and emits each tagged scalar with its dotted path (e.g.
3
+ * `routes[0].handler.body`) and the engine that owns it — including engines
4
+ * that produce no diagnostics (`literal`), so routing through the registry
5
+ * stays generic and a new engine needs no change here. A plain string is
6
+ * never a value's expression, and compiled values are skipped so a
7
+ * precompiled tree is not re-walked. */
15
8
  export function walkCelExpressions(value, path, cb) {
16
9
  if (isTaggedSentinel(value)) {
17
- cb(value.source, path, value.engine, { whole: true });
18
- return;
19
- }
20
- if (typeof value === "string") {
21
- const matches = [...value.matchAll(TEMPLATE_REGEX)];
22
- for (const m of matches) {
23
- const expr = m[1].trim();
24
- // A string that is nothing but one interpolation is as whole as a
25
- // tagged scalar — the delimiters are the only difference, and they are
26
- // handed back as the wrapper.
27
- const only = matches.length === 1 && m.index === 0 && m[0].length === value.length;
28
- const lead = /^\s*/.exec(m[0].slice(OPEN.length))[0].length;
29
- cb(expr, path, "cel", {
30
- whole: only,
31
- ...(only
32
- ? {
33
- wrapper: {
34
- prefix: value.slice(0, OPEN.length + lead),
35
- suffix: value.slice(OPEN.length + lead + expr.length),
36
- },
37
- }
38
- : {}),
39
- });
40
- }
10
+ cb(value.source, path, value.engine);
41
11
  return;
42
12
  }
43
13
  if (Array.isArray(value)) {
@@ -46,9 +16,20 @@ export function walkCelExpressions(value, path, cb) {
46
16
  }
47
17
  if (value !== null &&
48
18
  typeof value === "object" &&
49
- !value.__compiled) {
50
- for (const [k, v] of Object.entries(value)) {
51
- walkCelExpressions(v, path ? `${path}.${k}` : k, cb);
19
+ !value.__compiled &&
20
+ isPlainObject(value)) {
21
+ // `for…in` over a plain object sees exactly its own enumerable keys, without
22
+ // the array `Object.entries` allocates — this walk runs over every resource
23
+ // a context creates.
24
+ for (const k in value) {
25
+ walkCelExpressions(value[k], path ? `${path}.${k}` : k, cb);
52
26
  }
53
27
  }
54
28
  }
29
+ /** A template body forwards `self.<ref>` as the LIVE instance, whose object graph
30
+ * is cyclic and holds no authored expression — walking it overflows the stack.
31
+ * The rule the include walk and `compileWalker` follow. */
32
+ function isPlainObject(value) {
33
+ const proto = Object.getPrototypeOf(value);
34
+ return proto === Object.prototype || proto === null;
35
+ }
package/dist/engine.d.ts CHANGED
@@ -176,6 +176,12 @@ export interface EngineFileClaim {
176
176
  * Whether it does is a question for whoever holds the directory. */
177
177
  readonly directory?: boolean;
178
178
  }
179
+ /** One CEL expression inside a tagged scalar, by offset into the scalar's
180
+ * source. */
181
+ export interface ExpressionRegion {
182
+ readonly start: number;
183
+ readonly end: number;
184
+ }
179
185
  /** Per-property templating engine. Matches a YAML tag (`!<name>`); the kernel
180
186
  * and analyzer dispatch through the registry rather than knowing about
181
187
  * specific engines. */
@@ -231,5 +237,13 @@ export interface TemplatingEngine {
231
237
  * byte slot both fail statically, through the ordinary schema check and with
232
238
  * no diagnostic code of their own. */
233
239
  producedType?(): Record<string, unknown>;
240
+ /** Where the CEL expressions sit inside the tagged scalar — the whole source
241
+ * for `!cel`, each hole's expression for a tag with holes.
242
+ *
243
+ * What an editor colours, completes, hovers and renames against, so it finds
244
+ * the expressions of any tag without recognising the tag. Absent on an
245
+ * engine whose scalar holds no CEL. A source the engine cannot read yields
246
+ * no regions; `analyze` is what reports why. */
247
+ expressionRegions?(source: string): readonly ExpressionReg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