@telorun/templating 0.23.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.
- package/README.md +1 -1
- package/dist/builtins.d.ts +8 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +13 -0
- package/dist/cel/analyze.d.ts +4 -0
- package/dist/cel/analyze.d.ts.map +1 -1
- package/dist/cel/analyze.js +9 -0
- package/dist/cel/catalog.d.ts.map +1 -1
- package/dist/cel/catalog.js +12 -4
- package/dist/cel/compile.d.ts +4 -26
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +3 -88
- package/dist/cel/interpolation-holes.d.ts +43 -0
- package/dist/cel/interpolation-holes.d.ts.map +1 -0
- package/dist/cel/interpolation-holes.js +121 -0
- package/dist/cel/walk.d.ts +7 -28
- package/dist/cel/walk.d.ts.map +1 -1
- package/dist/cel/walk.js +7 -39
- package/dist/engine.d.ts +14 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.d.ts +7 -0
- package/dist/engines/cel.d.ts.map +1 -1
- package/dist/engines/cel.js +29 -12
- package/dist/engines/hole-analysis.d.ts +23 -0
- package/dist/engines/hole-analysis.d.ts.map +1 -0
- package/dist/engines/hole-analysis.js +66 -0
- package/dist/engines/interpolate.d.ts +13 -0
- package/dist/engines/interpolate.d.ts.map +1 -0
- package/dist/engines/interpolate.js +123 -0
- package/dist/engines/sql.d.ts +3 -3
- package/dist/engines/sql.d.ts.map +1 -1
- package/dist/engines/sql.js +24 -58
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/sentinel.d.ts +4 -5
- package/dist/sentinel.d.ts.map +1 -1
- package/dist/sentinel.js +6 -14
- package/package.json +2 -2
- package/src/builtins.ts +14 -0
- package/src/cel/analyze.ts +12 -0
- package/src/cel/catalog.ts +14 -4
- package/src/cel/compile.ts +4 -92
- package/src/cel/interpolation-holes.ts +138 -0
- package/src/cel/walk.ts +8 -54
- package/src/engine.ts +16 -0
- package/src/engines/cel.ts +36 -14
- package/src/engines/hole-analysis.ts +96 -0
- package/src/engines/interpolate.ts +139 -0
- package/src/engines/sql.ts +26 -67
- package/src/index.ts +12 -7
- package/src/sentinel.ts +6 -14
package/dist/engines/cel.js
CHANGED
|
@@ -14,6 +14,11 @@ import { moduleCallNodes, moduleNameBindings, resolveModuleCalls, unresolvedCall
|
|
|
14
14
|
* explained it, and left `${{ }}` interpolations chain-validated but never
|
|
15
15
|
* type-checked at all. */
|
|
16
16
|
export function analyzeCelExpression(source, env) {
|
|
17
|
+
return analyzeCelWithTree(source, env).result;
|
|
18
|
+
}
|
|
19
|
+
/** {@link analyzeCelExpression}, with the resolved tree it built — for a tag
|
|
20
|
+
* that asks its own questions of one expression without parsing it again. */
|
|
21
|
+
export function analyzeCelWithTree(source, env) {
|
|
17
22
|
const out = [];
|
|
18
23
|
let parsed;
|
|
19
24
|
try {
|
|
@@ -21,10 +26,13 @@ export function analyzeCelExpression(source, env) {
|
|
|
21
26
|
}
|
|
22
27
|
catch (e) {
|
|
23
28
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
result: {
|
|
30
|
+
diagnostics: [{ code: "CEL_SYNTAX_ERROR", message: e instanceof Error ? e.message : String(e) }],
|
|
31
|
+
calls: [],
|
|
32
|
+
},
|
|
26
33
|
};
|
|
27
34
|
}
|
|
35
|
+
const ast = parsed.ast;
|
|
28
36
|
// Resolution, before anything reads the tree — the audit, the type check and
|
|
29
37
|
// every chain walk below all see the resolved shape, so none of them has to
|
|
30
38
|
// know a module name from a variable.
|
|
@@ -68,13 +76,16 @@ export function analyzeCelExpression(source, env) {
|
|
|
68
76
|
// crash here silently retires static typing for that expression. Report it
|
|
69
77
|
// instead: degrading is acceptable, degrading invisibly is not.
|
|
70
78
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
result: {
|
|
80
|
+
diagnostics: [
|
|
81
|
+
{
|
|
82
|
+
code: "CEL_TYPE_ERROR",
|
|
83
|
+
message: `the CEL type-checker failed on this expression: ${e instanceof Error ? e.message : String(e)}`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
calls: audit.calls,
|
|
87
|
+
},
|
|
88
|
+
ast,
|
|
78
89
|
};
|
|
79
90
|
}
|
|
80
91
|
// The audit only ever EXPLAINS a rejection — it never overrules acceptance.
|
|
@@ -162,9 +173,12 @@ export function analyzeCelExpression(source, env) {
|
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
175
|
return {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
176
|
+
result: {
|
|
177
|
+
diagnostics: out,
|
|
178
|
+
calls: resolvedCalls ? withCallArguments(audit.calls, parsed.ast) : audit.calls,
|
|
179
|
+
...(type === undefined ? {} : { type }),
|
|
180
|
+
},
|
|
181
|
+
ast,
|
|
168
182
|
};
|
|
169
183
|
}
|
|
170
184
|
/** The audited call sites, each module call carrying its arguments as the type
|
|
@@ -215,4 +229,7 @@ export const celEngine = {
|
|
|
215
229
|
analyze(source, env) {
|
|
216
230
|
return analyzeCelExpression(source, env);
|
|
217
231
|
},
|
|
232
|
+
expressionRegions(source) {
|
|
233
|
+
return [{ start: 0, end: source.length }];
|
|
234
|
+
},
|
|
218
235
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ASTNode } from "@marcbachmann/cel-js";
|
|
2
|
+
import type { CompiledValue } from "@telorun/sdk";
|
|
3
|
+
import { type InterpolationHole } from "../cel/interpolation-holes.js";
|
|
4
|
+
import type { AnalyzeEnv, AnalyzeResult, CompileEnv, EngineDiagnostic, ExpressionRegion } from "../engine.js";
|
|
5
|
+
/** The holes of a scalar a hole-bearing tag compiles, or a thrown error naming
|
|
6
|
+
* where the reading failed — a tag's scalar that cannot be read is not a value. */
|
|
7
|
+
export declare function requireHoles(tag: string, source: string): readonly InterpolationHole[];
|
|
8
|
+
/** Every hole compiled as its own CEL expression, with the roots, module calls
|
|
9
|
+
* and volatility of all of them carried together. */
|
|
10
|
+
export declare function compileHoles(holes: readonly InterpolationHole[], env: CompileEnv): {
|
|
11
|
+
readonly compiled: readonly CompiledValue[];
|
|
12
|
+
readonly refs: readonly string[];
|
|
13
|
+
readonly calls: readonly string[];
|
|
14
|
+
readonly volatile: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** Analyze each hole with the shared CEL analysis, so diagnostics read exactly
|
|
17
|
+
* as they do under `!cel`; a fix computed against one hole's expression is
|
|
18
|
+
* re-anchored onto the whole scalar, and call offsets onto the scalar too.
|
|
19
|
+
* `perHole` adds a tag's own verdict on a hole that analyzed clean. */
|
|
20
|
+
export declare function analyzeHoles(source: string, env: AnalyzeEnv, perHole?: (hole: InterpolationHole, result: AnalyzeResult, ast: ASTNode | undefined) => readonly EngineDiagnostic[]): AnalyzeResult;
|
|
21
|
+
/** The CEL expressions of a hole-bearing scalar, by offset. */
|
|
22
|
+
export declare function holeRegions(source: string): readonly ExpressionRegion[];
|
|
23
|
+
//# sourceMappingURL=hole-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hole-analysis.d.ts","sourceRoot":"","sources":["../../src/engines/hole-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EAEb,UAAU,EAEV,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB;oFACoF;AACpF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,iBAAiB,EAAE,CAItF;AAED;sDACsD;AACtD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,iBAAiB,EAAE,EACnC,GAAG,EAAE,UAAU,GACd;IACD,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAWA;AAED;;;wEAGwE;AACxE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,CACR,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,OAAO,GAAG,SAAS,KACrB,SAAS,gBAAgB,EAAE,GAC/B,aAAa,CAkBf;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,gBAAgB,EAAE,CAIvE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { compileExpression } from "../cel/compile.js";
|
|
2
|
+
import { readInterpolationHoles, } from "../cel/interpolation-holes.js";
|
|
3
|
+
import { analyzeCelWithTree } from "./cel.js";
|
|
4
|
+
/** The holes of a scalar a hole-bearing tag compiles, or a thrown error naming
|
|
5
|
+
* where the reading failed — a tag's scalar that cannot be read is not a value. */
|
|
6
|
+
export function requireHoles(tag, source) {
|
|
7
|
+
const reading = readInterpolationHoles(source);
|
|
8
|
+
if (!reading.ok)
|
|
9
|
+
throw new Error(`!${tag}: ${reading.message}`);
|
|
10
|
+
return reading.holes;
|
|
11
|
+
}
|
|
12
|
+
/** Every hole compiled as its own CEL expression, with the roots, module calls
|
|
13
|
+
* and volatility of all of them carried together. */
|
|
14
|
+
export function compileHoles(holes, env) {
|
|
15
|
+
const compiled = holes.map((h) => compileExpression(h.expr, env.celEnv, env.moduleNames));
|
|
16
|
+
const refs = new Set();
|
|
17
|
+
const calls = new Set();
|
|
18
|
+
let volatile = false;
|
|
19
|
+
for (const c of compiled) {
|
|
20
|
+
for (const r of c.refs ?? [])
|
|
21
|
+
refs.add(r);
|
|
22
|
+
for (const q of c.calls ?? [])
|
|
23
|
+
calls.add(q);
|
|
24
|
+
if (c.volatile)
|
|
25
|
+
volatile = true;
|
|
26
|
+
}
|
|
27
|
+
return { compiled, refs: [...refs], calls: [...calls], volatile };
|
|
28
|
+
}
|
|
29
|
+
/** Analyze each hole with the shared CEL analysis, so diagnostics read exactly
|
|
30
|
+
* as they do under `!cel`; a fix computed against one hole's expression is
|
|
31
|
+
* re-anchored onto the whole scalar, and call offsets onto the scalar too.
|
|
32
|
+
* `perHole` adds a tag's own verdict on a hole that analyzed clean. */
|
|
33
|
+
export function analyzeHoles(source, env, perHole) {
|
|
34
|
+
const reading = readInterpolationHoles(source);
|
|
35
|
+
if (!reading.ok) {
|
|
36
|
+
return { diagnostics: [{ code: "CEL_SYNTAX_ERROR", message: reading.message }], calls: [] };
|
|
37
|
+
}
|
|
38
|
+
const diagnostics = [];
|
|
39
|
+
const calls = [];
|
|
40
|
+
for (const hole of reading.holes) {
|
|
41
|
+
const { result, ast } = analyzeCelWithTree(hole.expr, env);
|
|
42
|
+
for (const d of result.diagnostics) {
|
|
43
|
+
diagnostics.push(d.fix ? { ...d, fix: reanchor(source, hole, d.fix) } : d);
|
|
44
|
+
}
|
|
45
|
+
for (const c of result.calls) {
|
|
46
|
+
calls.push({ ...c, start: hole.exprStart + c.start, end: hole.exprStart + c.end });
|
|
47
|
+
}
|
|
48
|
+
if (perHole && result.diagnostics.length === 0)
|
|
49
|
+
diagnostics.push(...perHole(hole, result, ast));
|
|
50
|
+
}
|
|
51
|
+
return { diagnostics, calls };
|
|
52
|
+
}
|
|
53
|
+
/** The CEL expressions of a hole-bearing scalar, by offset. */
|
|
54
|
+
export function holeRegions(source) {
|
|
55
|
+
const reading = readInterpolationHoles(source);
|
|
56
|
+
if (!reading.ok)
|
|
57
|
+
return [];
|
|
58
|
+
return reading.holes.map((h) => ({ start: h.exprStart, end: h.exprStart + h.expr.length }));
|
|
59
|
+
}
|
|
60
|
+
function reanchor(source, hole, fix) {
|
|
61
|
+
return {
|
|
62
|
+
replacement: source.slice(0, hole.exprStart) +
|
|
63
|
+
fix.replacement +
|
|
64
|
+
source.slice(hole.exprStart + hole.expr.length),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TemplatingEngine } from "../engine.js";
|
|
2
|
+
/**
|
|
3
|
+
* The `!interpolate` engine: literal text with `${{ expr }}` holes, always a
|
|
4
|
+
* string. Its meaning is exactly the CEL expression that joins the text with
|
|
5
|
+
* `string(<hole>)` for each hole — every hole converts through CEL's own
|
|
6
|
+
* `string()` overloads (RFC 3339 for a timestamp, `5400s` for a duration, UTF-8
|
|
7
|
+
* for bytes), never the host language's conversion, so any CEL engine renders
|
|
8
|
+
* the same text. A hole whose type has no `string()` overload is refused
|
|
9
|
+
* statically, and a `dyn` hole that turns out null, a list or a map is refused
|
|
10
|
+
* at runtime with the hole it came from.
|
|
11
|
+
*/
|
|
12
|
+
export declare const interpolateEngine: TemplatingEngine;
|
|
13
|
+
//# sourceMappingURL=interpolate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/engines/interpolate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA+C,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKlG;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,EAAE,gBAoC/B,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { EvaluationError } from "@marcbachmann/cel-js";
|
|
2
|
+
import { RuntimeError } from "@telorun/sdk";
|
|
3
|
+
import { nullableValueChain } from "../cel/analyze.js";
|
|
4
|
+
import { literalFragments } from "../cel/interpolation-holes.js";
|
|
5
|
+
import { analyzeHoles, compileHoles, holeRegions, requireHoles } from "./hole-analysis.js";
|
|
6
|
+
const INTERPOLATE_ENGINE = "interpolate";
|
|
7
|
+
/**
|
|
8
|
+
* The `!interpolate` engine: literal text with `${{ expr }}` holes, always a
|
|
9
|
+
* string. Its meaning is exactly the CEL expression that joins the text with
|
|
10
|
+
* `string(<hole>)` for each hole — every hole converts through CEL's own
|
|
11
|
+
* `string()` overloads (RFC 3339 for a timestamp, `5400s` for a duration, UTF-8
|
|
12
|
+
* for bytes), never the host language's conversion, so any CEL engine renders
|
|
13
|
+
* the same text. A hole whose type has no `string()` overload is refused
|
|
14
|
+
* statically, and a `dyn` hole that turns out null, a list or a map is refused
|
|
15
|
+
* at runtime with the hole it came from.
|
|
16
|
+
*/
|
|
17
|
+
export const interpolateEngine = {
|
|
18
|
+
name: INTERPOLATE_ENGINE,
|
|
19
|
+
language: "cel",
|
|
20
|
+
compile(source, env) {
|
|
21
|
+
const holes = requireHoles(INTERPOLATE_ENGINE, source);
|
|
22
|
+
const fragments = literalFragments(source, holes);
|
|
23
|
+
const { compiled, refs, calls, volatile } = compileHoles(holes, env);
|
|
24
|
+
const convert = stringConversion(env.celEnv);
|
|
25
|
+
return {
|
|
26
|
+
__compiled: true,
|
|
27
|
+
source,
|
|
28
|
+
refs,
|
|
29
|
+
calls,
|
|
30
|
+
...(volatile ? { volatile: true } : {}),
|
|
31
|
+
call: (ctx) => {
|
|
32
|
+
let out = fragments[0];
|
|
33
|
+
for (let i = 0; i < holes.length; i++) {
|
|
34
|
+
out += convert(compiled[i].call(ctx), holes[i], source) + fragments[i + 1];
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
analyze(source, env) {
|
|
41
|
+
return analyzeHoles(source, env, (hole, result, ast) => holeVerdict(hole, result, ast, env));
|
|
42
|
+
},
|
|
43
|
+
producedType() {
|
|
44
|
+
return { type: "string" };
|
|
45
|
+
},
|
|
46
|
+
expressionRegions(source) {
|
|
47
|
+
return holeRegions(source);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/** A clean hole's own checks, over the tree its analysis already built:
|
|
51
|
+
* whether it may be null, and whether CEL can turn its type into text at all. */
|
|
52
|
+
function holeVerdict(hole, result, ast, env) {
|
|
53
|
+
if (ast && env.contextSchema) {
|
|
54
|
+
const chain = nullableValueChain(ast, env.contextSchema);
|
|
55
|
+
if (chain !== null) {
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
code: "CEL_NULLABLE_ACCESS",
|
|
59
|
+
message: `'${chain}' may be null, and a null has no text — guard it in the hole ` +
|
|
60
|
+
`(e.g. '\${{ ${chain} != null ? ${chain} : "" }}').`,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (result.type === undefined || convertibleTypes(env.celEnv).has(result.type))
|
|
66
|
+
return [];
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
code: "INTERPOLATION_HOLE_NOT_CONVERTIBLE",
|
|
70
|
+
message: `the hole '\${{ ${hole.expr} }}' is ${result.type}, which CEL's string() cannot convert to text. ` +
|
|
71
|
+
`Convert it inside the hole (e.g. join a list, or read the field you meant), or write the whole value as !cel.`,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
const CONVERTIBLE = new WeakMap();
|
|
76
|
+
/** The types a `string()` overload of `env` accepts, `dyn` among them — read
|
|
77
|
+
* off the registered overloads, so the check is the one evaluation applies. */
|
|
78
|
+
function convertibleTypes(env) {
|
|
79
|
+
const cached = CONVERTIBLE.get(env);
|
|
80
|
+
if (cached)
|
|
81
|
+
return cached;
|
|
82
|
+
const types = new Set(["dyn"]);
|
|
83
|
+
for (const fn of env.getDefinitions().functions) {
|
|
84
|
+
if (fn.name === "string" && fn.receiverType === null && fn.params?.length === 1) {
|
|
85
|
+
types.add(fn.params[0].type);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
CONVERTIBLE.set(env, types);
|
|
89
|
+
return types;
|
|
90
|
+
}
|
|
91
|
+
const CONVERSIONS = new WeakMap();
|
|
92
|
+
/** CEL's `string(v)` in `env`, with every overload the environment registers. */
|
|
93
|
+
function stringConversion(env) {
|
|
94
|
+
const cached = CONVERSIONS.get(env);
|
|
95
|
+
if (cached)
|
|
96
|
+
return cached;
|
|
97
|
+
const program = env.parse("string(value)");
|
|
98
|
+
const conversion = (value, hole, source) => {
|
|
99
|
+
if (typeof value === "string")
|
|
100
|
+
return value;
|
|
101
|
+
try {
|
|
102
|
+
return program({ value });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (!(error instanceof EvaluationError))
|
|
106
|
+
throw error;
|
|
107
|
+
throw new RuntimeError("ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE", `the hole '\${{ ${hole.expr} }}' at offset ${hole.start} of !interpolate ${JSON.stringify(source)} ` +
|
|
108
|
+
`evaluated to ${runtimeTypeOf(value)}, which CEL's string() cannot convert to text. ` +
|
|
109
|
+
`Declare outputType on the resource producing it so the check sees its type, or guard it inside the hole.`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
CONVERSIONS.set(env, conversion);
|
|
113
|
+
return conversion;
|
|
114
|
+
}
|
|
115
|
+
function runtimeTypeOf(value) {
|
|
116
|
+
if (value === null || value === undefined)
|
|
117
|
+
return "null";
|
|
118
|
+
if (Array.isArray(value))
|
|
119
|
+
return "a list";
|
|
120
|
+
if (value instanceof Map || Object.getPrototypeOf(value) === Object.prototype)
|
|
121
|
+
return "a map";
|
|
122
|
+
return `a value of type ${value.constructor?.name ?? typeof value}`;
|
|
123
|
+
}
|
package/dist/engines/sql.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { isParameterizedSql, type ParameterizedSql } from "@telorun/sdk";
|
|
|
2
2
|
import type { TemplatingEngine } from "../engine.js";
|
|
3
3
|
export { isParameterizedSql, type ParameterizedSql };
|
|
4
4
|
/** The `!sql` engine. Treats the tagged scalar as a SQL string with `${{ }}`
|
|
5
|
-
*
|
|
6
|
-
* expression) it keeps the literal text and each
|
|
7
|
-
*
|
|
5
|
+
* holes whose values are *bound*, not spliced. Unlike `!cel` (one bare
|
|
6
|
+
* expression) it keeps the literal text and each hole separate: at runtime
|
|
7
|
+
* `call()` returns a {@link ParameterizedSql} the consumer turns into a
|
|
8
8
|
* parameterized query. Generic expansion passes that object through untouched
|
|
9
9
|
* (it is the `call()` result), so it survives the step-level input expansion. */
|
|
10
10
|
export declare const sqlEngine: TemplatingEngine;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/engines/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAsB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/engines/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAsB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAErD;;;;;kFAKkF;AAClF,eAAO,MAAM,SAAS,EAAE,gBAkCvB,CAAC"}
|
package/dist/engines/sql.js
CHANGED
|
@@ -1,76 +1,42 @@
|
|
|
1
1
|
import { isParameterizedSql } from "@telorun/sdk";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { literalFragments } from "../cel/interpolation-holes.js";
|
|
3
|
+
import { analyzeHoles, compileHoles, holeRegions, requireHoles } from "./hole-analysis.js";
|
|
4
4
|
export { isParameterizedSql };
|
|
5
5
|
/** The `!sql` engine. Treats the tagged scalar as a SQL string with `${{ }}`
|
|
6
|
-
*
|
|
7
|
-
* expression) it keeps the literal text and each
|
|
8
|
-
*
|
|
6
|
+
* holes whose values are *bound*, not spliced. Unlike `!cel` (one bare
|
|
7
|
+
* expression) it keeps the literal text and each hole separate: at runtime
|
|
8
|
+
* `call()` returns a {@link ParameterizedSql} the consumer turns into a
|
|
9
9
|
* parameterized query. Generic expansion passes that object through untouched
|
|
10
10
|
* (it is the `call()` result), so it survives the step-level input expansion. */
|
|
11
11
|
export const sqlEngine = {
|
|
12
12
|
name: "sql",
|
|
13
13
|
language: "sql",
|
|
14
14
|
compile(source, env) {
|
|
15
|
-
const
|
|
15
|
+
const holes = requireHoles("sql", source);
|
|
16
|
+
const fragments = literalFragments(source, holes);
|
|
17
|
+
const { compiled, refs, calls, volatile } = compileHoles(holes, env);
|
|
16
18
|
return {
|
|
17
19
|
__compiled: true,
|
|
18
20
|
source,
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
call: (ctx) => {
|
|
31
|
-
const { fragments, values } = toParameterized(inner, ctx);
|
|
32
|
-
return { __teloParameterized: true, fragments, values };
|
|
33
|
-
},
|
|
21
|
+
// Carried for the reason `!cel` carries them: a consumer asking what an
|
|
22
|
+
// expression READS or CALLS cannot re-derive it from SQL text, which
|
|
23
|
+
// cannot tell an identifier from a word inside a string literal.
|
|
24
|
+
refs,
|
|
25
|
+
calls,
|
|
26
|
+
...(volatile ? { volatile: true } : {}),
|
|
27
|
+
call: (ctx) => ({
|
|
28
|
+
__teloParameterized: true,
|
|
29
|
+
fragments: fragments.slice(),
|
|
30
|
+
values: compiled.map((c) => c.call(ctx)),
|
|
31
|
+
}),
|
|
34
32
|
};
|
|
35
33
|
},
|
|
36
34
|
analyze(source, env) {
|
|
37
|
-
//
|
|
38
|
-
// per-expression analyzer so diagnostics match the `!cel` engine exactly.
|
|
39
|
-
// Each interpolation's offset is kept so a fix computed against the bare
|
|
40
|
-
// expression is re-anchored to the whole SQL scalar — the only thing that
|
|
41
|
-
// ever made `!sql` fix-less was dropping it here.
|
|
42
|
-
const diagnostics = [];
|
|
43
|
-
const calls = [];
|
|
44
|
-
for (const { expr, start } of expressionsOf(source)) {
|
|
45
|
-
const result = analyzeCelExpression(expr, env);
|
|
46
|
-
for (const d of result.diagnostics) {
|
|
47
|
-
diagnostics.push(d.fix ? { ...d, fix: reanchor(source, expr, start, d.fix) } : d);
|
|
48
|
-
}
|
|
49
|
-
for (const c of result.calls) {
|
|
50
|
-
calls.push({ ...c, start: start + c.start, end: start + c.end });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// No `type`: a SQL template is a string built from many expressions, so
|
|
35
|
+
// No `type`: a SQL template is a query built from many expressions, so
|
|
54
36
|
// there is no single checked type to report.
|
|
55
|
-
return
|
|
37
|
+
return analyzeHoles(source, env);
|
|
38
|
+
},
|
|
39
|
+
expressionRegions(source) {
|
|
40
|
+
return holeRegions(source);
|
|
56
41
|
},
|
|
57
42
|
};
|
|
58
|
-
/** Re-anchor a fix computed against one interpolation onto the full source. */
|
|
59
|
-
function reanchor(source, expr, start, fix) {
|
|
60
|
-
return {
|
|
61
|
-
replacement: source.slice(0, start) + fix.replacement + source.slice(start + expr.length),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/** Each `${{ expr }}` body in a `!sql` template, with the body's offset in the
|
|
65
|
-
* source. The offset is derived from the opening delimiter and the leading
|
|
66
|
-
* whitespace the capture group already trims, never by searching for the
|
|
67
|
-
* body text — which a body appearing twice would defeat. */
|
|
68
|
-
function expressionsOf(source) {
|
|
69
|
-
const out = [];
|
|
70
|
-
for (const m of source.matchAll(TEMPLATE_REGEX)) {
|
|
71
|
-
const lead = /^\s*/.exec(m[0].slice(OPEN.length))[0].length;
|
|
72
|
-
out.push({ expr: m[1], start: m.index + OPEN.length + lead });
|
|
73
|
-
}
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
const OPEN = "${{";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
export { buildCelEnvironment, celBuiltinFunctions, deriveSignatures, type CelHandlers, } from "./cel/environment.js";
|
|
2
2
|
export { celFunctionCatalog, CEL_FUNCTIONS, type CelFunctionInfo, type CelFunctionDoc, type CelFunctionCategory, } from "./cel/catalog.js";
|
|
3
|
-
export { compileExpression
|
|
3
|
+
export { compileExpression } from "./cel/compile.js";
|
|
4
|
+
export { interpolationShape, literalFragments, readInterpolationHoles, type HoleReading, type InterpolationHole, type InterpolationShape, } from "./cel/interpolation-holes.js";
|
|
4
5
|
export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
5
6
|
export { auditCalls, explainUnresolved, functionIndex, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
|
|
6
7
|
export { MODULE_CALL_DISPATCH_KEY, moduleCallOf, resolveModuleCalls, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
|
|
7
|
-
export { walkCelExpressions
|
|
8
|
+
export { walkCelExpressions } from "./cel/walk.js";
|
|
8
9
|
export { celEngine } from "./engines/cel.js";
|
|
9
10
|
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, type NormalizedIncludePath, } from "./engines/include.js";
|
|
11
|
+
export { interpolateEngine } from "./engines/interpolate.js";
|
|
10
12
|
export { literalEngine } from "./engines/literal.js";
|
|
11
13
|
export { modulePathEngine } from "./engines/module-path.js";
|
|
12
14
|
export { refEngine } from "./engines/ref.js";
|
|
13
15
|
export { sqlEngine, isParameterizedSql, type ParameterizedSql } from "./engines/sql.js";
|
|
14
16
|
export { TemplatingEngineRegistry } from "./registry.js";
|
|
15
|
-
export { builtinEngines, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
16
|
-
export type { AnalyzeEnv, AnalyzeResult, CallArgument, CallSite, CompileEnv, DiagnosticFix, EngineDiagnostic, EngineFileClaim, TemplatingEngine, } from "./engine.js";
|
|
17
|
+
export { builtinEngines, celExpressionsOf, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
18
|
+
export type { AnalyzeEnv, AnalyzeResult, CallArgument, CallSite, CompileEnv, DiagnosticFix, EngineDiagnostic, EngineFileClaim, ExpressionRegion, TemplatingEngine, } from "./engine.js";
|
|
17
19
|
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isModulePathSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, MODULE_FILE_ENGINE_NAMES, MODULE_PATH_ENGINE, plainChainOf, type TaggedSentinel, } from "./sentinel.js";
|
|
18
20
|
export { buildCustomTags, defaultCustomTags } from "./yaml-tags.js";
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,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,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,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,GACf,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { buildCelEnvironment, celBuiltinFunctions, deriveSignatures, } from "./cel/environment.js";
|
|
2
2
|
export { celFunctionCatalog, CEL_FUNCTIONS, } from "./cel/catalog.js";
|
|
3
|
-
export { compileExpression
|
|
3
|
+
export { compileExpression } from "./cel/compile.js";
|
|
4
|
+
export { interpolationShape, literalFragments, readInterpolationHoles, } from "./cel/interpolation-holes.js";
|
|
4
5
|
export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
5
6
|
export { auditCalls, explainUnresolved, functionIndex, } from "./cel/diagnose.js";
|
|
6
7
|
// The rewrite, its reader, and the activation key the kernel binds a scope's
|
|
@@ -12,11 +13,12 @@ export { MODULE_CALL_DISPATCH_KEY, moduleCallOf, resolveModuleCalls, } from "./c
|
|
|
12
13
|
export { walkCelExpressions } from "./cel/walk.js";
|
|
13
14
|
export { celEngine } from "./engines/cel.js";
|
|
14
15
|
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, } from "./engines/include.js";
|
|
16
|
+
export { interpolateEngine } from "./engines/interpolate.js";
|
|
15
17
|
export { literalEngine } from "./engines/literal.js";
|
|
16
18
|
export { modulePathEngine } from "./engines/module-path.js";
|
|
17
19
|
export { refEngine } from "./engines/ref.js";
|
|
18
20
|
export { sqlEngine, isParameterizedSql } from "./engines/sql.js";
|
|
19
21
|
export { TemplatingEngineRegistry } from "./registry.js";
|
|
20
|
-
export { builtinEngines, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
22
|
+
export { builtinEngines, celExpressionsOf, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
21
23
|
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isModulePathSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, MODULE_FILE_ENGINE_NAMES, MODULE_PATH_ENGINE, plainChainOf, } from "./sentinel.js";
|
|
22
24
|
export { buildCustomTags, defaultCustomTags } from "./yaml-tags.js";
|
package/dist/sentinel.d.ts
CHANGED
|
@@ -34,11 +34,10 @@ export declare const MODULE_PATH_ENGINE = "module-path";
|
|
|
34
34
|
/**
|
|
35
35
|
* The dotted chain a value names, or undefined.
|
|
36
36
|
*
|
|
37
|
-
* Only a PLAIN CHAIN — `steps.encode.result.output
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* the analyzer knows least is the conservative direction.
|
|
37
|
+
* Only a PLAIN CHAIN written as a `!cel` value — `steps.encode.result.output`.
|
|
38
|
+
* An expression that COMPUTES rather than names has no schema to read off a
|
|
39
|
+
* context, so a caller that navigates one gets nothing and reports nothing:
|
|
40
|
+
* silence where the analyzer knows least is the conservative direction.
|
|
42
41
|
*
|
|
43
42
|
* Here rather than in each caller because "is this expression a plain chain" is
|
|
44
43
|
* one question, and two copies of the answer would eventually disagree about a
|
package/dist/sentinel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentinel.d.ts","sourceRoot":"","sources":["../src/sentinel.ts"],"names":[],"mappings":"AAAA;;;;;YAKY;AACZ,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,CAQhE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAEjF;AAED;;;;4CAI4C;AAC5C,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,CAEjF;AAED;;gDAEgD;AAChD,eAAO,MAAM,UAAU,QAAQ,CAAC;AAEhC;;wCAEwC;AACxC,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AAEpD;wDACwD;AACxD,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD
|
|
1
|
+
{"version":3,"file":"sentinel.d.ts","sourceRoot":"","sources":["../src/sentinel.ts"],"names":[],"mappings":"AAAA;;;;;YAKY;AACZ,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,CAQhE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAEjF;AAED;;;;4CAI4C;AAC5C,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,CAEjF;AAED;;gDAEgD;AAChD,eAAO,MAAM,UAAU,QAAQ,CAAC;AAEhC;;wCAEwC;AACxC,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AAEpD;wDACwD;AACxD,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAM/D;AAED;mEACmE;AACnE,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH;;;;;;;qCAOqC;AACrC,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,OAAO,mBAAmB,GAAG,OAAO,oBAAoB,CAAA;CAAE,CAI5F;AAED;;6CAE6C;AAC7C,wBAAgB,oBAAoB,CAClC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,OAAO,kBAAkB,CAAA;CAAE,CAE7D;AAED;qEACqE;AACrE,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAIvD,CAAC"}
|
package/dist/sentinel.js
CHANGED
|
@@ -31,27 +31,19 @@ export const MODULE_PATH_ENGINE = "module-path";
|
|
|
31
31
|
/**
|
|
32
32
|
* The dotted chain a value names, or undefined.
|
|
33
33
|
*
|
|
34
|
-
* Only a PLAIN CHAIN — `steps.encode.result.output
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* the analyzer knows least is the conservative direction.
|
|
34
|
+
* Only a PLAIN CHAIN written as a `!cel` value — `steps.encode.result.output`.
|
|
35
|
+
* An expression that COMPUTES rather than names has no schema to read off a
|
|
36
|
+
* context, so a caller that navigates one gets nothing and reports nothing:
|
|
37
|
+
* silence where the analyzer knows least is the conservative direction.
|
|
39
38
|
*
|
|
40
39
|
* Here rather than in each caller because "is this expression a plain chain" is
|
|
41
40
|
* one question, and two copies of the answer would eventually disagree about a
|
|
42
41
|
* shape like `a.b[0]`.
|
|
43
42
|
*/
|
|
44
43
|
export function plainChainOf(value) {
|
|
45
|
-
|
|
46
|
-
? value.engine === CEL_ENGINE
|
|
47
|
-
? value.source
|
|
48
|
-
: undefined
|
|
49
|
-
: typeof value === "string"
|
|
50
|
-
? /^\s*\$\{\{(.+)\}\}\s*$/.exec(value)?.[1]
|
|
51
|
-
: undefined;
|
|
52
|
-
if (typeof source !== "string")
|
|
44
|
+
if (!isTaggedSentinel(value) || value.engine !== CEL_ENGINE)
|
|
53
45
|
return undefined;
|
|
54
|
-
const trimmed = source.trim();
|
|
46
|
+
const trimmed = value.source.trim();
|
|
55
47
|
return /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(trimmed)
|
|
56
48
|
? trimmed
|
|
57
49
|
: undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/templating",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/node": "^20.0.0",
|
|
47
47
|
"typescript": "^5.0.0",
|
|
48
48
|
"vitest": "^2.1.8",
|
|
49
|
-
"@telorun/sdk": "0.
|
|
49
|
+
"@telorun/sdk": "0.101.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@telorun/sdk": "*"
|
package/src/builtins.ts
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";
|
|
@@ -17,6 +18,7 @@ export const builtinEngines: readonly TemplatingEngine[] = [
|
|
|
17
18
|
celEngine,
|
|
18
19
|
includeBytesEngine,
|
|
19
20
|
includeTextEngine,
|
|
21
|
+
interpolateEngine,
|
|
20
22
|
literalEngine,
|
|
21
23
|
modulePathEngine,
|
|
22
24
|
refEngine,
|
|
@@ -45,6 +47,18 @@ export function producedTypeOf(engineName: string): Record<string, unknown> | un
|
|
|
45
47
|
return defaultRegistry().get(engineName)?.producedType?.();
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The CEL expressions a tagged scalar holds — its whole source under `!cel`,
|
|
52
|
+
* each hole under a tag with holes, none under a tag holding no CEL.
|
|
53
|
+
*
|
|
54
|
+
* The single reader of `TemplatingEngine.expressionRegions`, so an analysis pass
|
|
55
|
+
* asking "what CEL is written here" never recognises a tag by name.
|
|
56
|
+
*/
|
|
57
|
+
export function celExpressionsOf(engineName: string, source: string): string[] {
|
|
58
|
+
const regions = defaultRegistry().get(engineName)?.expressionRegions?.(source) ?? [];
|
|
59
|
+
return regions.map((r) => source.slice(r.start, r.end));
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
let defaultRegistryCache: TemplatingEngineRegistry | undefined;
|
|
49
63
|
|
|
50
64
|
/** Memoized singleton: returns the default registry. Hosts that don't need
|
package/src/cel/analyze.ts
CHANGED
|
@@ -248,6 +248,18 @@ function schemaAtChain(
|
|
|
248
248
|
return current;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
/** The dotted chain an expression IS, when it is a plain chain whose schema
|
|
252
|
+
* admits null — a value that may itself be null, rather than one dereferenced
|
|
253
|
+
* through a null. */
|
|
254
|
+
export function nullableValueChain(
|
|
255
|
+
node: ASTNode,
|
|
256
|
+
contextSchema: Record<string, any>,
|
|
257
|
+
): string | null {
|
|
258
|
+
const chain = dottedChain(node, new Set());
|
|
259
|
+
if (chain === null) return null;
|
|
260
|
+
return schemaIsNullable(schemaAtChain(chain.split("."), contextSchema)) ? chain : null;
|
|
261
|
+
}
|
|
262
|
+
|
|
251
263
|
function isNullLiteral(node: ASTNode): boolean {
|
|
252
264
|
return node.op === "value" && (node.args as unknown) === null;
|
|
253
265
|
}
|