@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.
- package/dist/builtins.d.ts +2 -2
- package/dist/builtins.d.ts.map +1 -1
- package/dist/cel/analyze.d.ts +6 -6
- package/dist/cel/analyze.d.ts.map +1 -1
- package/dist/cel/analyze.js +138 -183
- package/dist/cel/compile.d.ts +47 -17
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +135 -83
- package/dist/cel/diagnose.d.ts +52 -57
- package/dist/cel/diagnose.d.ts.map +1 -1
- package/dist/cel/diagnose.js +69 -291
- package/dist/cel/environment.d.ts +33 -37
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +54 -86
- package/dist/cel/module-call.d.ts +68 -79
- package/dist/cel/module-call.d.ts.map +1 -1
- package/dist/cel/module-call.js +118 -194
- package/dist/cel/value-brands.d.ts +14 -12
- package/dist/cel/value-brands.d.ts.map +1 -1
- package/dist/cel/value-brands.js +26 -24
- package/dist/cel/verdict-codes.d.ts +13 -2
- package/dist/cel/verdict-codes.d.ts.map +1 -1
- package/dist/cel/verdict-codes.js +20 -1
- package/dist/engine.d.ts +4 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.d.ts +2 -2
- package/dist/engines/cel.d.ts.map +1 -1
- package/dist/engines/cel.js +53 -81
- package/dist/engines/hole-analysis.d.ts +3 -3
- package/dist/engines/hole-analysis.d.ts.map +1 -1
- package/dist/engines/interpolate.js +11 -8
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/package.json +4 -4
- package/src/builtins.ts +2 -2
- package/src/cel/analyze.ts +152 -193
- package/src/cel/compile.ts +160 -77
- package/src/cel/diagnose.ts +115 -370
- package/src/cel/environment.ts +64 -87
- package/src/cel/module-call.ts +129 -292
- package/src/cel/value-brands.ts +26 -25
- package/src/cel/verdict-codes.ts +20 -1
- package/src/engine.ts +4 -4
- package/src/engines/cel.ts +52 -84
- package/src/engines/hole-analysis.ts +3 -3
- package/src/engines/interpolate.ts +16 -13
- package/src/index.ts +8 -11
- package/dist/cel/catalog.d.ts +0 -70
- package/dist/cel/catalog.d.ts.map +0 -1
- package/dist/cel/catalog.js +0 -1320
- package/dist/cel/json-prefix-scan.d.ts +0 -17
- package/dist/cel/json-prefix-scan.d.ts.map +0 -1
- package/dist/cel/json-prefix-scan.js +0 -160
- package/dist/cel/value-identity.d.ts +0 -18
- package/dist/cel/value-identity.d.ts.map +0 -1
- package/dist/cel/value-identity.js +0 -25
- package/src/cel/catalog.ts +0 -1455
- package/src/cel/json-prefix-scan.ts +0 -152
- package/src/cel/value-identity.ts +0 -34
package/src/cel/environment.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
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
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
}
|