@telorun/templating 0.116.0 → 0.118.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/cel/analyze.d.ts +6 -0
- package/dist/cel/analyze.d.ts.map +1 -1
- package/dist/cel/analyze.js +27 -3
- package/dist/cel/compile.d.ts +18 -3
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +40 -15
- package/dist/cel/environment.d.ts +2 -1
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +4 -1
- package/dist/cel/value-types.d.ts +19 -0
- package/dist/cel/value-types.d.ts.map +1 -0
- package/dist/cel/value-types.js +80 -0
- package/dist/engine.d.ts +4 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.js +1 -1
- package/dist/engines/hole-analysis.js +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/package.json +3 -3
- package/src/cel/analyze.ts +29 -3
- package/src/cel/compile.ts +56 -13
- package/src/cel/environment.ts +4 -1
- package/src/cel/value-types.ts +90 -0
- package/src/engine.ts +4 -0
- package/src/engines/cel.ts +1 -1
- package/src/engines/hole-analysis.ts +1 -1
- package/src/index.ts +7 -2
- package/dist/cel/value-brands.d.ts +0 -18
- package/dist/cel/value-brands.d.ts.map +0 -1
- package/dist/cel/value-brands.js +0 -33
- package/src/cel/value-brands.ts +0 -34
package/dist/cel/analyze.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export declare const INDEX_SEGMENT = "[*]";
|
|
|
27
27
|
/** Chain segment for "each element of the collection reached so far": what a
|
|
28
28
|
* comprehension's iteration variable stands for. */
|
|
29
29
|
export declare const EACH_SEGMENT = "[]";
|
|
30
|
+
/** Chain segment for "whether the member exists": the last segment of a chain a
|
|
31
|
+
* presence test (`has(a.b)`) reads, which depends on the KEYS of what the chain
|
|
32
|
+
* before it reaches and on none of its values. */
|
|
33
|
+
export declare const PRESENCE_SEGMENT = "?";
|
|
30
34
|
/**
|
|
31
35
|
* What an expression READS of the values its roots name, as member chains —
|
|
32
36
|
* {@link extractAccessChains} with a comprehension's iteration variable followed
|
|
@@ -38,6 +42,8 @@ export declare const EACH_SEGMENT = "[]";
|
|
|
38
42
|
* its elements: the chain ends in {@link EACH_SEGMENT}.
|
|
39
43
|
* - A bare use of the variable reads the element whole, so the range is read
|
|
40
44
|
* whole, as it is by any other use of the collection.
|
|
45
|
+
* - A presence test reads only whether the member exists: `has(a.b)` reads
|
|
46
|
+
* `a.?` ({@link PRESENCE_SEGMENT}), never the value of `a.b`.
|
|
41
47
|
*
|
|
42
48
|
* A variable whose range is not a plain chain (a call's result, another macro's
|
|
43
49
|
* output) names nothing a root holds, and a read through it contributes nothing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;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,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAS5F;AA8FD;;+DAE+D;AAC/D,eAAO,MAAM,aAAa,QAAQ,CAAC;AA6BnC;qDACqD;AACrD,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAI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/dist/cel/analyze.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { childNodes, namespaceMacroBinding, receiverMacroBinding, } from "@telorun/cel";
|
|
2
|
-
import { isLiveSlot } from "@telorun/sdk";
|
|
2
|
+
import { isLiveSlot, membersOf } from "@telorun/sdk";
|
|
3
3
|
import { moduleCallOf } from "./module-call.js";
|
|
4
4
|
/**
|
|
5
5
|
* Extract all member-access chains from a CEL AST.
|
|
@@ -152,6 +152,10 @@ function extractChain(node, boundVars) {
|
|
|
152
152
|
/** Chain segment for "each element of the collection reached so far": what a
|
|
153
153
|
* comprehension's iteration variable stands for. */
|
|
154
154
|
export const EACH_SEGMENT = "[]";
|
|
155
|
+
/** Chain segment for "whether the member exists": the last segment of a chain a
|
|
156
|
+
* presence test (`has(a.b)`) reads, which depends on the KEYS of what the chain
|
|
157
|
+
* before it reaches and on none of its values. */
|
|
158
|
+
export const PRESENCE_SEGMENT = "?";
|
|
155
159
|
/**
|
|
156
160
|
* What an expression READS of the values its roots name, as member chains —
|
|
157
161
|
* {@link extractAccessChains} with a comprehension's iteration variable followed
|
|
@@ -163,6 +167,8 @@ export const EACH_SEGMENT = "[]";
|
|
|
163
167
|
* its elements: the chain ends in {@link EACH_SEGMENT}.
|
|
164
168
|
* - A bare use of the variable reads the element whole, so the range is read
|
|
165
169
|
* whole, as it is by any other use of the collection.
|
|
170
|
+
* - A presence test reads only whether the member exists: `has(a.b)` reads
|
|
171
|
+
* `a.?` ({@link PRESENCE_SEGMENT}), never the value of `a.b`.
|
|
166
172
|
*
|
|
167
173
|
* A variable whose range is not a plain chain (a call's result, another macro's
|
|
168
174
|
* output) names nothing a root holds, and a read through it contributes nothing.
|
|
@@ -203,6 +209,14 @@ function visitReads(node, chains, bound) {
|
|
|
203
209
|
chains.push(chain[chain.length - 1] === EACH_SEGMENT ? chain.slice(0, -1) : chain);
|
|
204
210
|
return;
|
|
205
211
|
}
|
|
212
|
+
const presence = presenceOperand(node);
|
|
213
|
+
if (presence) {
|
|
214
|
+
const owner = readChainOf(presence, bound);
|
|
215
|
+
if (owner !== null) {
|
|
216
|
+
chains.push([...owner, PRESENCE_SEGMENT]);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
206
220
|
const moduleCall = moduleCallOf(node);
|
|
207
221
|
if (moduleCall) {
|
|
208
222
|
for (const arg of moduleCall.args)
|
|
@@ -230,6 +244,13 @@ function visitReads(node, chains, bound) {
|
|
|
230
244
|
for (const child of childNodes(node))
|
|
231
245
|
visitReads(child, chains, bound);
|
|
232
246
|
}
|
|
247
|
+
/** What a presence test `has(<operand>.<member>)` asks the keys of. */
|
|
248
|
+
function presenceOperand(node) {
|
|
249
|
+
if (node.kind !== "call" || node.name !== "has" || node.args.length !== 1)
|
|
250
|
+
return undefined;
|
|
251
|
+
const arg = node.args[0];
|
|
252
|
+
return arg.kind === "select" && !arg.optional ? arg.operand : undefined;
|
|
253
|
+
}
|
|
233
254
|
/**
|
|
234
255
|
* Every member access whose base is a module call, longest first — the chains
|
|
235
256
|
* {@link extractAccessChains} deliberately skips, since their root is a value
|
|
@@ -456,7 +477,10 @@ export function validateChainAgainstSchema(chain, schema) {
|
|
|
456
477
|
current = element;
|
|
457
478
|
continue;
|
|
458
479
|
}
|
|
459
|
-
|
|
480
|
+
// A value type declaring members is read by those members alone: they are its
|
|
481
|
+
// fields, closed as the CEL type the type registers.
|
|
482
|
+
const members = membersOf(current);
|
|
483
|
+
const props = members ?? current.properties;
|
|
460
484
|
if (!props)
|
|
461
485
|
return null;
|
|
462
486
|
if (key in props) {
|
|
@@ -468,7 +492,7 @@ export function validateChainAgainstSchema(chain, schema) {
|
|
|
468
492
|
current = propSchema;
|
|
469
493
|
continue;
|
|
470
494
|
}
|
|
471
|
-
if (current.additionalProperties === true)
|
|
495
|
+
if (!members && current.additionalProperties === true)
|
|
472
496
|
return null;
|
|
473
497
|
const path = chain.slice(0, i + 1).join(".");
|
|
474
498
|
const available = Object.keys(props).join(", ");
|
package/dist/cel/compile.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* silently answering a different question. What is left here is reading the result.
|
|
12
12
|
*/
|
|
13
13
|
import { type CompiledValue } from "@telorun/sdk";
|
|
14
|
-
import { type CelEnvironment, type CelExpression, type NamespaceImplementation } from "@telorun/cel";
|
|
14
|
+
import { type CelEnvironment, type CelExpression, type CelProgram, type NamespaceImplementation } from "@telorun/cel";
|
|
15
15
|
import { type ModuleCallDispatch } from "./module-call.js";
|
|
16
16
|
/**
|
|
17
17
|
* Whether an expression's text, written twice in one value, means one value both times: it
|
|
@@ -23,6 +23,21 @@ import { type ModuleCallDispatch } from "./module-call.js";
|
|
|
23
23
|
* unreadable thing is one ranged diagnostic and the tree keeps the longest prefix.
|
|
24
24
|
*/
|
|
25
25
|
export declare function repeatableExpression(expr: string, environment: CelEnvironment): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* One compiled expression whose program a host may replace with an equivalent one compiled
|
|
28
|
+
* against the same environment — the kernel swaps in the program from an emitted module.
|
|
29
|
+
*/
|
|
30
|
+
export interface CelProgramSite {
|
|
31
|
+
readonly source: string;
|
|
32
|
+
readonly environment: CelEnvironment;
|
|
33
|
+
use(program: CelProgram): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The environment an expression at a site with these module names compiles against: the
|
|
37
|
+
* environment itself when it already declares all of them, otherwise a clone carrying them. A host compiling many expressions of one site builds it once with this, so
|
|
38
|
+
* they all share one environment.
|
|
39
|
+
*/
|
|
40
|
+
export declare function siteEnvironment(environment: CelEnvironment, moduleNames?: ReadonlySet<string>): CelEnvironment;
|
|
26
41
|
/**
|
|
27
42
|
* Compile one CEL expression into a `CompiledValue`. The `!cel` engine compiles its whole
|
|
28
43
|
* scalar with it, and the tags with holes compile each hole.
|
|
@@ -32,9 +47,9 @@ export declare function repeatableExpression(expr: string, environment: CelEnvir
|
|
|
32
47
|
* references below, the analyzer's passes, the kernel's dependency walk — sees the resolved
|
|
33
48
|
* shape rather than re-deriving it from the source text.
|
|
34
49
|
*/
|
|
35
|
-
export declare function compileExpression(expr: string, environment: CelEnvironment, moduleNames?: ReadonlySet<string
|
|
50
|
+
export declare function compileExpression(expr: string, environment: CelEnvironment, moduleNames?: ReadonlySet<string>, programSites?: CelProgramSite[]): CompiledValue;
|
|
36
51
|
/** A `CompiledValue` over an expression already read against its site's names. */
|
|
37
|
-
export declare function compiledValueOf(expr: string, parsed: CelExpression, environment: CelEnvironment): CompiledValue;
|
|
52
|
+
export declare function compiledValueOf(expr: string, parsed: CelExpression, environment: CelEnvironment, programSites?: CelProgramSite[]): CompiledValue;
|
|
38
53
|
/**
|
|
39
54
|
* A scope's module functions as the engine's own per-evaluation dispatch — **the one
|
|
40
55
|
* adapter**, so every host that binds a table converts its arguments the same way.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,KAAK,uBAAuB,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAwC1B;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,OAAO,CAIvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,cAAc,EAC3B,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,c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|
|
|
62
62
|
return !callsNonDeterministic(parsed.root) && !callsOnBareReceiver(parsed.root);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* `moduleNames` are the declaring module's own names; a call whose receiver is one of them
|
|
69
|
-
* is resolved to a `qcall` as the expression is READ, so every later reader — the root
|
|
70
|
-
* references below, the analyzer's passes, the kernel's dependency walk — sees the resolved
|
|
71
|
-
* shape rather than re-deriving it from the source text.
|
|
65
|
+
* The environment an expression at a site with these module names compiles against: the
|
|
66
|
+
* environment itself when it already declares all of them, otherwise a clone carrying them. A host compiling many expressions of one site builds it once with this, so
|
|
67
|
+
* they all share one environment.
|
|
72
68
|
*/
|
|
73
|
-
export function
|
|
69
|
+
export function siteEnvironment(environment, moduleNames) {
|
|
74
70
|
// Only the names CEL can read as a namespace: a set holding `my-module` is refused WHOLE
|
|
75
71
|
// at registration, and a name that cannot be one resolves no call anyway.
|
|
76
72
|
const namespaces = moduleNames === undefined ? NO_NAMESPACES : celNamespaceNames(moduleNames);
|
|
77
|
-
if (namespaces.size === 0)
|
|
78
|
-
return
|
|
79
|
-
|
|
73
|
+
if (namespaces.size === 0)
|
|
74
|
+
return environment;
|
|
75
|
+
// An environment already declaring every one of the names resolves the tree as a clone
|
|
76
|
+
// would, since the clone inherits its declarations.
|
|
77
|
+
const declared = new Set(environment.namespaces());
|
|
78
|
+
if ([...namespaces].every((name) => declared.has(name)))
|
|
79
|
+
return environment;
|
|
80
80
|
// A clone carrying the site's names: the tree is resolved under them, and the environment
|
|
81
81
|
// that compiles it must declare the same set or it refuses the tree.
|
|
82
82
|
const site = environment.clone();
|
|
83
83
|
for (const name of namespaces)
|
|
84
84
|
site.registerNamespace(name);
|
|
85
|
-
return
|
|
85
|
+
return site;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Compile one CEL expression into a `CompiledValue`. The `!cel` engine compiles its whole
|
|
89
|
+
* scalar with it, and the tags with holes compile each hole.
|
|
90
|
+
*
|
|
91
|
+
* `moduleNames` are the declaring module's own names; a call whose receiver is one of them
|
|
92
|
+
* is resolved to a `qcall` as the expression is READ, so every later reader — the root
|
|
93
|
+
* references below, the analyzer's passes, the kernel's dependency walk — sees the resolved
|
|
94
|
+
* shape rather than re-deriving it from the source text.
|
|
95
|
+
*/
|
|
96
|
+
export function compileExpression(expr, environment, moduleNames, programSites) {
|
|
97
|
+
const site = siteEnvironment(environment, moduleNames);
|
|
98
|
+
return compiledValueOf(expr, site.parse(expr), site, programSites);
|
|
86
99
|
}
|
|
87
100
|
/** A `CompiledValue` over an expression already read against its site's names. */
|
|
88
|
-
export function compiledValueOf(expr, parsed, environment) {
|
|
89
|
-
|
|
101
|
+
export function compiledValueOf(expr, parsed, environment, programSites) {
|
|
102
|
+
// Where a host may swap in an emitted program, the closure is built only if nothing was
|
|
103
|
+
// swapped in by the first evaluation. An unreadable expression is still compiled — and so
|
|
104
|
+
// refused — here, where it is written.
|
|
105
|
+
let program = programSites && parsed.diagnostics.length === 0 ? undefined : environment.compile(parsed);
|
|
106
|
+
programSites?.push({
|
|
107
|
+
source: expr,
|
|
108
|
+
environment,
|
|
109
|
+
use: (replacement) => {
|
|
110
|
+
program = replacement;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
90
113
|
// As written — `CompiledValue.calls` is the qualified spellings, not their shapes.
|
|
91
114
|
const calls = qualifiedCalls(parsed.root).map((call) => call.qualifiedName);
|
|
92
115
|
return {
|
|
@@ -99,7 +122,9 @@ export function compiledValueOf(expr, parsed, environment) {
|
|
|
99
122
|
// the owning scope bound on the activation. Evaluating without it reaches no function at
|
|
100
123
|
// all: the engine would answer its own `unbound_function` for every qualified call,
|
|
101
124
|
// whatever the kernel bound, so the whole dispatch is silently dead.
|
|
102
|
-
call: (ctx) => hostValueOf(program.evaluate(ctx, {
|
|
125
|
+
call: (ctx) => hostValueOf((program ??= environment.compile(parsed)).evaluate(ctx, {
|
|
126
|
+
namespaceFunction: dispatchFrom(ctx),
|
|
127
|
+
})),
|
|
103
128
|
};
|
|
104
129
|
}
|
|
105
130
|
/**
|
|
@@ -28,7 +28,8 @@ export declare function buildCelLanguageEnvironment(): CelEnvironment;
|
|
|
28
28
|
* normalized — so the base set is asked for directly.
|
|
29
29
|
*/
|
|
30
30
|
export declare function celBuiltinFunctions(): ReturnType<CelEnvironment["definitions"]>["functions"];
|
|
31
|
-
/** Telo's dialect: the language, the function catalog,
|
|
31
|
+
/** Telo's dialect: the language, the function catalog, every value type's CEL face, and
|
|
32
|
+
* the live `Stream` type. */
|
|
32
33
|
export declare function buildCelEnvironment(handlers?: Partial<CelHandlers>): CelEnvironment;
|
|
33
34
|
/** The dialect's functions as the one listing surface answers them. */
|
|
34
35
|
export declare function celFunctionCatalog(): ReturnType<typeof functionCatalog>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/cel/environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,cAAc,EACd,eAAe,EAEf,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/cel/environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,cAAc,EACd,eAAe,EAEf,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AAGtB;2DAC2D;AAC3D,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAyC7C;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,cAAc,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,UAAU,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,CAE5F;AAED;8BAC8B;AAC9B,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,cAAc,CAQvF;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,IAAI,UAAU,CAAC,OAAO,eAAe,CAAC,CAEvE"}
|
package/dist/cel/environment.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* `buildCelEnvironment(handlers?)` is the dialect built on it.
|
|
14
14
|
*/
|
|
15
15
|
import { CelEnvironment, functionCatalog, registerFunctionCatalog, } from "@telorun/cel";
|
|
16
|
+
import { registerValueTypes } from "./value-types.js";
|
|
16
17
|
const stub = (name) => () => {
|
|
17
18
|
throw new Error(`${name}() is not available in this environment. ` +
|
|
18
19
|
`Construct StaticAnalyzer or Loader with celHandlers to enable it.`);
|
|
@@ -63,10 +64,12 @@ export function buildCelLanguageEnvironment() {
|
|
|
63
64
|
export function celBuiltinFunctions() {
|
|
64
65
|
return buildCelLanguageEnvironment().definitions().functions;
|
|
65
66
|
}
|
|
66
|
-
/** Telo's dialect: the language, the function catalog,
|
|
67
|
+
/** Telo's dialect: the language, the function catalog, every value type's CEL face, and
|
|
68
|
+
* the live `Stream` type. */
|
|
67
69
|
export function buildCelEnvironment(handlers = {}) {
|
|
68
70
|
const environment = buildCelLanguageEnvironment();
|
|
69
71
|
registerFunctionCatalog(environment, { handlers: { ...STUB_HANDLERS, ...handlers } });
|
|
72
|
+
registerValueTypes(environment);
|
|
70
73
|
// A live handle: `dyn` underneath with no conversion and no member, so reading anything
|
|
71
74
|
// off one is refused at check. It needs no constructor — identity by class is what the
|
|
72
75
|
// engine replaced, and at runtime a stream is whatever the producer handed over.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CelEnvironment } from "@telorun/cel";
|
|
2
|
+
/**
|
|
3
|
+
* Register the CEL face of every value type, from the entries alone — one registration,
|
|
4
|
+
* made where the dialect environment is built, so the runtime environment and every
|
|
5
|
+
* analyzer clone carry the same types and no type is named here.
|
|
6
|
+
*
|
|
7
|
+
* - **A nominal brand** (a `json` entry with no `celType`) is a type of its own over its
|
|
8
|
+
* base: it converts to its base with the base's own conversion (`int(ports.http)`,
|
|
9
|
+
* `string(variables.dataDir)`), renders as text (`string(ports.http)`), and — for a host
|
|
10
|
+
* path — is extended with `.joinPath(relative)` and stays one. Declared, not
|
|
11
|
+
* implemented: at runtime a branded value IS its base, so the standard library's own
|
|
12
|
+
* overloads are what evaluate.
|
|
13
|
+
* - **An instance declaring `members`** is a type whose values carry its own type key, so
|
|
14
|
+
* its members are the type's FIELDS, read by `.`, `.?` and `has()` through the engine's
|
|
15
|
+
* member-read seam, and `string(value)` is its plain encoding's text — a conversion
|
|
16
|
+
* registered WITH that encoder as its implementation, dispatched on the value's key.
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerValueTypes(environment: CelEnvironment): void;
|
|
19
|
+
//# sourceMappingURL=value-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-types.d.ts","sourceRoot":"","sources":["../../src/cel/value-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAUnD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,cAAc,GAAG,IAAI,CAyBpE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { celTypeOfValueType, PLAIN_ENCODINGS, VALUE_TYPES, valueBrandBases, valueTypeOf, } from "@telorun/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Register the CEL face of every value type, from the entries alone — one registration,
|
|
4
|
+
* made where the dialect environment is built, so the runtime environment and every
|
|
5
|
+
* analyzer clone carry the same types and no type is named here.
|
|
6
|
+
*
|
|
7
|
+
* - **A nominal brand** (a `json` entry with no `celType`) is a type of its own over its
|
|
8
|
+
* base: it converts to its base with the base's own conversion (`int(ports.http)`,
|
|
9
|
+
* `string(variables.dataDir)`), renders as text (`string(ports.http)`), and — for a host
|
|
10
|
+
* path — is extended with `.joinPath(relative)` and stays one. Declared, not
|
|
11
|
+
* implemented: at runtime a branded value IS its base, so the standard library's own
|
|
12
|
+
* overloads are what evaluate.
|
|
13
|
+
* - **An instance declaring `members`** is a type whose values carry its own type key, so
|
|
14
|
+
* its members are the type's FIELDS, read by `.`, `.?` and `has()` through the engine's
|
|
15
|
+
* member-read seam, and `string(value)` is its plain encoding's text — a conversion
|
|
16
|
+
* registered WITH that encoder as its implementation, dispatched on the value's key.
|
|
17
|
+
*/
|
|
18
|
+
export function registerValueTypes(environment) {
|
|
19
|
+
for (const [brand, base] of Object.entries(valueBrandBases())) {
|
|
20
|
+
const conversions = [`${base}(Self): ${base}`];
|
|
21
|
+
// Every base CEL can render as text renders its brand too — the runtime value IS the
|
|
22
|
+
// base — so `string(ports.http)` and a port in an `!interpolate` hole convert as the
|
|
23
|
+
// integer they are.
|
|
24
|
+
if (base !== "string")
|
|
25
|
+
conversions.push("string(Self): string");
|
|
26
|
+
const fromHost = VALUE_TYPES.get(brand)?.fromHost !== undefined;
|
|
27
|
+
environment.registerType({
|
|
28
|
+
name: brand,
|
|
29
|
+
base,
|
|
30
|
+
conversions,
|
|
31
|
+
...(fromHost ? { members: ["Self.joinPath(string): Self"] } : {}),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
for (const entry of VALUE_TYPES.values()) {
|
|
35
|
+
if (entry.members === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
const name = celTypeOfValueType(entry);
|
|
38
|
+
const encoding = PLAIN_ENCODINGS[entry.encoding];
|
|
39
|
+
environment.registerType({ name, base: "dyn", fields: fieldTypes(entry), description: entry.description });
|
|
40
|
+
environment.registerFunction(`string(${name}): string`, {
|
|
41
|
+
implementation: (ctx, value) => encoding.encode(value),
|
|
42
|
+
description: `The text of a ${name}, in its plain encoding.`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Each member of an entry as the CEL type its field reads as. */
|
|
47
|
+
function fieldTypes(entry) {
|
|
48
|
+
return Object.fromEntries(Object.entries(entry.members).map(([member, schema]) => [member, celTypeOfSchema(schema)]));
|
|
49
|
+
}
|
|
50
|
+
/** The CEL type a member's schema declares: a value type's own, a scalar's, a list's
|
|
51
|
+
* element and a map's value read in turn; anything else `dyn`. */
|
|
52
|
+
function celTypeOfSchema(schema) {
|
|
53
|
+
const entry = valueTypeOf(schema);
|
|
54
|
+
if (entry)
|
|
55
|
+
return celTypeOfValueType(entry);
|
|
56
|
+
switch (schema.type) {
|
|
57
|
+
case "string":
|
|
58
|
+
return "string";
|
|
59
|
+
case "integer":
|
|
60
|
+
return "int";
|
|
61
|
+
case "number":
|
|
62
|
+
return "double";
|
|
63
|
+
case "boolean":
|
|
64
|
+
return "bool";
|
|
65
|
+
case "array": {
|
|
66
|
+
const items = schema.items;
|
|
67
|
+
return items && typeof items === "object" && !Array.isArray(items)
|
|
68
|
+
? `list<${celTypeOfSchema(items)}>`
|
|
69
|
+
: "list<dyn>";
|
|
70
|
+
}
|
|
71
|
+
case "object": {
|
|
72
|
+
const values = schema.additionalProperties;
|
|
73
|
+
return values && typeof values === "object"
|
|
74
|
+
? `map<string, ${celTypeOfSchema(values)}>`
|
|
75
|
+
: "map<string, dyn>";
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
return "dyn";
|
|
79
|
+
}
|
|
80
|
+
}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CelEnvironment } from "@telorun/cel";
|
|
2
2
|
import type { CompiledValue } from "@telorun/sdk";
|
|
3
|
+
import type { CelProgramSite } from "./cel/compile.js";
|
|
3
4
|
import type { ModuleCallFlags } from "./cel/diagnose.js";
|
|
4
5
|
import type { ModuleCallTypeResolver } from "./cel/module-call.js";
|
|
5
6
|
/** Compile-time environment passed to `engine.compile`. Engines that need to
|
|
@@ -19,6 +20,9 @@ export interface CompileEnv {
|
|
|
19
20
|
* before module functions existed.
|
|
20
21
|
*/
|
|
21
22
|
readonly moduleNames?: ReadonlySet<string>;
|
|
23
|
+
/** Receives every CEL expression compiled here, so a host can replace each
|
|
24
|
+
* program with one from an emitted module. */
|
|
25
|
+
readonly programSites?: CelProgramSite[];
|
|
22
26
|
}
|
|
23
27
|
/** Analyze-time environment passed to `engine.analyze`. The walker resolves
|
|
24
28
|
* the path-specific effective context (kernel globals merged in, x-telo-context
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;wEAEwE;AACxE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;wEAEwE;AACxE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3C;mDAC+C;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rE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B;;qCAEiC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;cACc;AACd,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;wBAEwB;AACxB,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;2EAKuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;yDAGqD;IACrD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,aAAa,GAAG,OAAO,CAAC;IAElE;;iEAE6D;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,aAAa,CAAC;IAExD;;;;;;;;;;;;uBAYmB;IACnB,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAAC;IAExD;;;;;;;;;;;;;;;;;2CAiBuC;IACvC,YAAY,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC;;;;;;qDAMiD;IACjD,iBAAiB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,gBAAgB,EAAE,CAAC;IAEhE;;;;;;;;;iEAS6D;IAC7D,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC;CAC9D"}
|
package/dist/engines/cel.js
CHANGED
|
@@ -243,7 +243,7 @@ export const celEngine = {
|
|
|
243
243
|
name: "cel",
|
|
244
244
|
language: "cel",
|
|
245
245
|
compile(source, env) {
|
|
246
|
-
return compileExpression(source, env.celEnv, env.moduleNames);
|
|
246
|
+
return compileExpression(source, env.celEnv, env.moduleNames, env.programSites);
|
|
247
247
|
},
|
|
248
248
|
analyze(source, env) {
|
|
249
249
|
return analyzeCelExpression(source, env);
|
|
@@ -12,7 +12,7 @@ export function requireHoles(tag, source) {
|
|
|
12
12
|
/** Every hole compiled as its own CEL expression, with the roots, module calls
|
|
13
13
|
* and volatility of all of them carried together. */
|
|
14
14
|
export function compileHoles(holes, env) {
|
|
15
|
-
const compiled = holes.map((h) => compileExpression(h.expr, env.celEnv, env.moduleNames));
|
|
15
|
+
const compiled = holes.map((h) => compileExpression(h.expr, env.celEnv, env.moduleNames, env.programSites));
|
|
16
16
|
const refs = new Set();
|
|
17
17
|
const calls = new Set();
|
|
18
18
|
let volatile = false;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, celFunctionCatalog, type CelHandlers, } from "./cel/environment.js";
|
|
2
|
-
export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
|
|
3
|
-
export { registerValueBrands } from "./cel/value-brands.js";
|
|
2
|
+
export { compileExpression, namespaceDispatchOf, siteEnvironment, type CelProgramSite, } from "./cel/compile.js";
|
|
4
3
|
export { interpolationShape, literalFragments, readInterpolationHoles, type HoleReading, type InterpolationHole, type InterpolationShape, } from "./cel/interpolation-holes.js";
|
|
5
|
-
export { EACH_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
4
|
+
export { EACH_SEGMENT, PRESENCE_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
6
5
|
export { auditCalls, explainUnresolved, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
|
|
7
6
|
export { celNamespaceNames, MODULE_CALL_DISPATCH_KEY, moduleCallNames, moduleCallOf, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
|
|
8
7
|
export { walkCelExpressions } from "./cel/walk.js";
|
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,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,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,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,9 @@ export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions,
|
|
|
3
3
|
// become the engine's namespace seam — exported because the analyzer evaluates
|
|
4
4
|
// rule conditions and function bodies through the same table, and a second
|
|
5
5
|
// adapter is what let it convert arguments differently from the kernel.
|
|
6
|
-
export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
|
|
7
|
-
export { registerValueBrands } from "./cel/value-brands.js";
|
|
6
|
+
export { compileExpression, namespaceDispatchOf, siteEnvironment, } from "./cel/compile.js";
|
|
8
7
|
export { interpolationShape, literalFragments, readInterpolationHoles, } from "./cel/interpolation-holes.js";
|
|
9
|
-
export { EACH_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
8
|
+
export { EACH_SEGMENT, PRESENCE_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
10
9
|
export { auditCalls, explainUnresolved, } from "./cel/diagnose.js";
|
|
11
10
|
// The rewrite, its reader, and the activation key the kernel binds a scope's
|
|
12
11
|
// dispatch table under. The unbound message and the receiver and bound-name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/templating",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.118.0",
|
|
4
4
|
"description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"re2js": "2.8.3",
|
|
40
40
|
"uuid": "14.0.1",
|
|
41
41
|
"yaml": "^2.8.3",
|
|
42
|
-
"@telorun/cel": "0.
|
|
42
|
+
"@telorun/cel": "0.118.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/d3-format": "^3.0.4",
|
|
46
46
|
"@types/node": "^20.0.0",
|
|
47
47
|
"typescript": "^5.0.0",
|
|
48
48
|
"vitest": "^2.1.8",
|
|
49
|
-
"@telorun/sdk": "0.
|
|
49
|
+
"@telorun/sdk": "0.118.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@telorun/sdk": "*"
|
package/src/cel/analyze.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
receiverMacroBinding,
|
|
5
5
|
type CelNode,
|
|
6
6
|
} from "@telorun/cel";
|
|
7
|
-
import { isLiveSlot } from "@telorun/sdk";
|
|
7
|
+
import { isLiveSlot, membersOf } from "@telorun/sdk";
|
|
8
8
|
import { moduleCallOf } from "./module-call.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -171,6 +171,11 @@ function extractChain(node: CelNode, boundVars: ReadonlySet<string>): string[] |
|
|
|
171
171
|
* comprehension's iteration variable stands for. */
|
|
172
172
|
export const EACH_SEGMENT = "[]";
|
|
173
173
|
|
|
174
|
+
/** Chain segment for "whether the member exists": the last segment of a chain a
|
|
175
|
+
* presence test (`has(a.b)`) reads, which depends on the KEYS of what the chain
|
|
176
|
+
* before it reaches and on none of its values. */
|
|
177
|
+
export const PRESENCE_SEGMENT = "?";
|
|
178
|
+
|
|
174
179
|
/**
|
|
175
180
|
* What an expression READS of the values its roots name, as member chains —
|
|
176
181
|
* {@link extractAccessChains} with a comprehension's iteration variable followed
|
|
@@ -182,6 +187,8 @@ export const EACH_SEGMENT = "[]";
|
|
|
182
187
|
* its elements: the chain ends in {@link EACH_SEGMENT}.
|
|
183
188
|
* - A bare use of the variable reads the element whole, so the range is read
|
|
184
189
|
* whole, as it is by any other use of the collection.
|
|
190
|
+
* - A presence test reads only whether the member exists: `has(a.b)` reads
|
|
191
|
+
* `a.?` ({@link PRESENCE_SEGMENT}), never the value of `a.b`.
|
|
185
192
|
*
|
|
186
193
|
* A variable whose range is not a plain chain (a call's result, another macro's
|
|
187
194
|
* output) names nothing a root holds, and a read through it contributes nothing.
|
|
@@ -224,6 +231,15 @@ function visitReads(node: CelNode, chains: string[][], bound: BoundRanges): void
|
|
|
224
231
|
return;
|
|
225
232
|
}
|
|
226
233
|
|
|
234
|
+
const presence = presenceOperand(node);
|
|
235
|
+
if (presence) {
|
|
236
|
+
const owner = readChainOf(presence, bound);
|
|
237
|
+
if (owner !== null) {
|
|
238
|
+
chains.push([...owner, PRESENCE_SEGMENT]);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
227
243
|
const moduleCall = moduleCallOf(node);
|
|
228
244
|
if (moduleCall) {
|
|
229
245
|
for (const arg of moduleCall.args) visitReads(arg, chains, bound);
|
|
@@ -250,6 +266,13 @@ function visitReads(node: CelNode, chains: string[][], bound: BoundRanges): void
|
|
|
250
266
|
for (const child of childNodes(node)) visitReads(child, chains, bound);
|
|
251
267
|
}
|
|
252
268
|
|
|
269
|
+
/** What a presence test `has(<operand>.<member>)` asks the keys of. */
|
|
270
|
+
function presenceOperand(node: CelNode): CelNode | undefined {
|
|
271
|
+
if (node.kind !== "call" || node.name !== "has" || node.args.length !== 1) return undefined;
|
|
272
|
+
const arg = node.args[0]!;
|
|
273
|
+
return arg.kind === "select" && !arg.optional ? arg.operand : undefined;
|
|
274
|
+
}
|
|
275
|
+
|
|
253
276
|
/** A member access on a module call's result: the call, and the members read
|
|
254
277
|
* off it in order (`Billing.total(xs).amount` → `amount`). */
|
|
255
278
|
export interface CallResultAccess {
|
|
@@ -517,7 +540,10 @@ export function validateChainAgainstSchema(
|
|
|
517
540
|
current = element;
|
|
518
541
|
continue;
|
|
519
542
|
}
|
|
520
|
-
|
|
543
|
+
// A value type declaring members is read by those members alone: they are its
|
|
544
|
+
// fields, closed as the CEL type the type registers.
|
|
545
|
+
const members = membersOf(current);
|
|
546
|
+
const props: Record<string, any> | undefined = members ?? current.properties;
|
|
521
547
|
if (!props) return null;
|
|
522
548
|
if (key in props) {
|
|
523
549
|
const propSchema = props[key];
|
|
@@ -528,7 +554,7 @@ export function validateChainAgainstSchema(
|
|
|
528
554
|
current = propSchema;
|
|
529
555
|
continue;
|
|
530
556
|
}
|
|
531
|
-
if (current.additionalProperties === true) return null;
|
|
557
|
+
if (!members && current.additionalProperties === true) return null;
|
|
532
558
|
const path = chain.slice(0, i + 1).join(".");
|
|
533
559
|
const available = Object.keys(props).join(", ");
|
|
534
560
|
return `'${path}' is not defined (available: ${available})`;
|
package/src/cel/compile.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
type CelEnvironment,
|
|
20
20
|
type CelExpression,
|
|
21
21
|
type CelNode,
|
|
22
|
+
type CelProgram,
|
|
22
23
|
type NamespaceImplementation,
|
|
23
24
|
} from "@telorun/cel";
|
|
24
25
|
import {
|
|
@@ -80,6 +81,40 @@ export function repeatableExpression(expr: string, environment: CelEnvironment):
|
|
|
80
81
|
return !callsNonDeterministic(parsed.root) && !callsOnBareReceiver(parsed.root);
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
/**
|
|
85
|
+
* One compiled expression whose program a host may replace with an equivalent one compiled
|
|
86
|
+
* against the same environment — the kernel swaps in the program from an emitted module.
|
|
87
|
+
*/
|
|
88
|
+
export interface CelProgramSite {
|
|
89
|
+
readonly source: string;
|
|
90
|
+
readonly environment: CelEnvironment;
|
|
91
|
+
use(program: CelProgram): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The environment an expression at a site with these module names compiles against: the
|
|
96
|
+
* environment itself when it already declares all of them, otherwise a clone carrying them. A host compiling many expressions of one site builds it once with this, so
|
|
97
|
+
* they all share one environment.
|
|
98
|
+
*/
|
|
99
|
+
export function siteEnvironment(
|
|
100
|
+
environment: CelEnvironment,
|
|
101
|
+
moduleNames?: ReadonlySet<string>,
|
|
102
|
+
): CelEnvironment {
|
|
103
|
+
// Only the names CEL can read as a namespace: a set holding `my-module` is refused WHOLE
|
|
104
|
+
// at registration, and a name that cannot be one resolves no call anyway.
|
|
105
|
+
const namespaces = moduleNames === undefined ? NO_NAMESPACES : celNamespaceNames(moduleNames);
|
|
106
|
+
if (namespaces.size === 0) return environment;
|
|
107
|
+
// An environment already declaring every one of the names resolves the tree as a clone
|
|
108
|
+
// would, since the clone inherits its declarations.
|
|
109
|
+
const declared = new Set(environment.namespaces());
|
|
110
|
+
if ([...namespaces].every((name) => declared.has(name))) return environment;
|
|
111
|
+
// A clone carrying the site's names: the tree is resolved under them, and the environment
|
|
112
|
+
// that compiles it must declare the same set or it refuses the tree.
|
|
113
|
+
const site = environment.clone();
|
|
114
|
+
for (const name of namespaces) site.registerNamespace(name);
|
|
115
|
+
return site;
|
|
116
|
+
}
|
|
117
|
+
|
|
83
118
|
/**
|
|
84
119
|
* Compile one CEL expression into a `CompiledValue`. The `!cel` engine compiles its whole
|
|
85
120
|
* scalar with it, and the tags with holes compile each hole.
|
|
@@ -93,18 +128,10 @@ export function compileExpression(
|
|
|
93
128
|
expr: string,
|
|
94
129
|
environment: CelEnvironment,
|
|
95
130
|
moduleNames?: ReadonlySet<string>,
|
|
131
|
+
programSites?: CelProgramSite[],
|
|
96
132
|
): CompiledValue {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const namespaces = moduleNames === undefined ? NO_NAMESPACES : celNamespaceNames(moduleNames);
|
|
100
|
-
if (namespaces.size === 0) {
|
|
101
|
-
return compiledValueOf(expr, environment.parse(expr), environment);
|
|
102
|
-
}
|
|
103
|
-
// A clone carrying the site's names: the tree is resolved under them, and the environment
|
|
104
|
-
// that compiles it must declare the same set or it refuses the tree.
|
|
105
|
-
const site = environment.clone();
|
|
106
|
-
for (const name of namespaces) site.registerNamespace(name);
|
|
107
|
-
return compiledValueOf(expr, site.parse(expr), site);
|
|
133
|
+
const site = siteEnvironment(environment, moduleNames);
|
|
134
|
+
return compiledValueOf(expr, site.parse(expr), site, programSites);
|
|
108
135
|
}
|
|
109
136
|
|
|
110
137
|
/** A `CompiledValue` over an expression already read against its site's names. */
|
|
@@ -112,8 +139,20 @@ export function compiledValueOf(
|
|
|
112
139
|
expr: string,
|
|
113
140
|
parsed: CelExpression,
|
|
114
141
|
environment: CelEnvironment,
|
|
142
|
+
programSites?: CelProgramSite[],
|
|
115
143
|
): CompiledValue {
|
|
116
|
-
|
|
144
|
+
// Where a host may swap in an emitted program, the closure is built only if nothing was
|
|
145
|
+
// swapped in by the first evaluation. An unreadable expression is still compiled — and so
|
|
146
|
+
// refused — here, where it is written.
|
|
147
|
+
let program: CelProgram | undefined =
|
|
148
|
+
programSites && parsed.diagnostics.length === 0 ? undefined : environment.compile(parsed);
|
|
149
|
+
programSites?.push({
|
|
150
|
+
source: expr,
|
|
151
|
+
environment,
|
|
152
|
+
use: (replacement) => {
|
|
153
|
+
program = replacement;
|
|
154
|
+
},
|
|
155
|
+
});
|
|
117
156
|
// As written — `CompiledValue.calls` is the qualified spellings, not their shapes.
|
|
118
157
|
const calls = qualifiedCalls(parsed.root).map((call) => call.qualifiedName);
|
|
119
158
|
return {
|
|
@@ -127,7 +166,11 @@ export function compiledValueOf(
|
|
|
127
166
|
// all: the engine would answer its own `unbound_function` for every qualified call,
|
|
128
167
|
// whatever the kernel bound, so the whole dispatch is silently dead.
|
|
129
168
|
call: (ctx: Record<string, unknown>) =>
|
|
130
|
-
hostValueOf(
|
|
169
|
+
hostValueOf(
|
|
170
|
+
(program ??= environment.compile(parsed)).evaluate(ctx as never, {
|
|
171
|
+
namespaceFunction: dispatchFrom(ctx),
|
|
172
|
+
}),
|
|
173
|
+
),
|
|
131
174
|
};
|
|
132
175
|
}
|
|
133
176
|
|
package/src/cel/environment.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
registerFunctionCatalog,
|
|
19
19
|
type CelCatalogHandlers,
|
|
20
20
|
} from "@telorun/cel";
|
|
21
|
+
import { registerValueTypes } from "./value-types.js";
|
|
21
22
|
|
|
22
23
|
/** The nine functions the host answers for. The engine's own seam, re-exported so a
|
|
23
24
|
* consumer naming it does not have to name the engine. */
|
|
@@ -80,10 +81,12 @@ export function celBuiltinFunctions(): ReturnType<CelEnvironment["definitions"]>
|
|
|
80
81
|
return buildCelLanguageEnvironment().definitions().functions;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
/** Telo's dialect: the language, the function catalog,
|
|
84
|
+
/** Telo's dialect: the language, the function catalog, every value type's CEL face, and
|
|
85
|
+
* the live `Stream` type. */
|
|
84
86
|
export function buildCelEnvironment(handlers: Partial<CelHandlers> = {}): CelEnvironment {
|
|
85
87
|
const environment = buildCelLanguageEnvironment();
|
|
86
88
|
registerFunctionCatalog(environment, { handlers: { ...STUB_HANDLERS, ...handlers } });
|
|
89
|
+
registerValueTypes(environment);
|
|
87
90
|
// A live handle: `dyn` underneath with no conversion and no member, so reading anything
|
|
88
91
|
// off one is refused at check. It needs no constructor — identity by class is what the
|
|
89
92
|
// engine replaced, and at runtime a stream is whatever the producer handed over.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CelEnvironment } from "@telorun/cel";
|
|
2
|
+
import {
|
|
3
|
+
celTypeOfValueType,
|
|
4
|
+
PLAIN_ENCODINGS,
|
|
5
|
+
VALUE_TYPES,
|
|
6
|
+
valueBrandBases,
|
|
7
|
+
valueTypeOf,
|
|
8
|
+
type ValueTypeEntry,
|
|
9
|
+
} from "@telorun/sdk";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Register the CEL face of every value type, from the entries alone — one registration,
|
|
13
|
+
* made where the dialect environment is built, so the runtime environment and every
|
|
14
|
+
* analyzer clone carry the same types and no type is named here.
|
|
15
|
+
*
|
|
16
|
+
* - **A nominal brand** (a `json` entry with no `celType`) is a type of its own over its
|
|
17
|
+
* base: it converts to its base with the base's own conversion (`int(ports.http)`,
|
|
18
|
+
* `string(variables.dataDir)`), renders as text (`string(ports.http)`), and — for a host
|
|
19
|
+
* path — is extended with `.joinPath(relative)` and stays one. Declared, not
|
|
20
|
+
* implemented: at runtime a branded value IS its base, so the standard library's own
|
|
21
|
+
* overloads are what evaluate.
|
|
22
|
+
* - **An instance declaring `members`** is a type whose values carry its own type key, so
|
|
23
|
+
* its members are the type's FIELDS, read by `.`, `.?` and `has()` through the engine's
|
|
24
|
+
* member-read seam, and `string(value)` is its plain encoding's text — a conversion
|
|
25
|
+
* registered WITH that encoder as its implementation, dispatched on the value's key.
|
|
26
|
+
*/
|
|
27
|
+
export function registerValueTypes(environment: CelEnvironment): void {
|
|
28
|
+
for (const [brand, base] of Object.entries(valueBrandBases())) {
|
|
29
|
+
const conversions = [`${base}(Self): ${base}`];
|
|
30
|
+
// Every base CEL can render as text renders its brand too — the runtime value IS the
|
|
31
|
+
// base — so `string(ports.http)` and a port in an `!interpolate` hole convert as the
|
|
32
|
+
// integer they are.
|
|
33
|
+
if (base !== "string") conversions.push("string(Self): string");
|
|
34
|
+
const fromHost = VALUE_TYPES.get(brand)?.fromHost !== undefined;
|
|
35
|
+
environment.registerType({
|
|
36
|
+
name: brand,
|
|
37
|
+
base,
|
|
38
|
+
conversions,
|
|
39
|
+
...(fromHost ? { members: ["Self.joinPath(string): Self"] } : {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
for (const entry of VALUE_TYPES.values()) {
|
|
43
|
+
if (entry.members === undefined) continue;
|
|
44
|
+
const name = celTypeOfValueType(entry);
|
|
45
|
+
const encoding = PLAIN_ENCODINGS[entry.encoding!]!;
|
|
46
|
+
environment.registerType({ name, base: "dyn", fields: fieldTypes(entry), description: entry.description });
|
|
47
|
+
environment.registerFunction(`string(${name}): string`, {
|
|
48
|
+
implementation: (ctx, value) => encoding.encode(value),
|
|
49
|
+
description: `The text of a ${name}, in its plain encoding.`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Each member of an entry as the CEL type its field reads as. */
|
|
55
|
+
function fieldTypes(entry: ValueTypeEntry): Record<string, string> {
|
|
56
|
+
return Object.fromEntries(
|
|
57
|
+
Object.entries(entry.members!).map(([member, schema]) => [member, celTypeOfSchema(schema)]),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The CEL type a member's schema declares: a value type's own, a scalar's, a list's
|
|
62
|
+
* element and a map's value read in turn; anything else `dyn`. */
|
|
63
|
+
function celTypeOfSchema(schema: Readonly<Record<string, unknown>>): string {
|
|
64
|
+
const entry = valueTypeOf(schema);
|
|
65
|
+
if (entry) return celTypeOfValueType(entry);
|
|
66
|
+
switch (schema.type) {
|
|
67
|
+
case "string":
|
|
68
|
+
return "string";
|
|
69
|
+
case "integer":
|
|
70
|
+
return "int";
|
|
71
|
+
case "number":
|
|
72
|
+
return "double";
|
|
73
|
+
case "boolean":
|
|
74
|
+
return "bool";
|
|
75
|
+
case "array": {
|
|
76
|
+
const items = schema.items;
|
|
77
|
+
return items && typeof items === "object" && !Array.isArray(items)
|
|
78
|
+
? `list<${celTypeOfSchema(items as Record<string, unknown>)}>`
|
|
79
|
+
: "list<dyn>";
|
|
80
|
+
}
|
|
81
|
+
case "object": {
|
|
82
|
+
const values = schema.additionalProperties;
|
|
83
|
+
return values && typeof values === "object"
|
|
84
|
+
? `map<string, ${celTypeOfSchema(values as Record<string, unknown>)}>`
|
|
85
|
+
: "map<string, dyn>";
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return "dyn";
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/engine.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CelEnvironment } from "@telorun/cel";
|
|
2
2
|
import type { CompiledValue } from "@telorun/sdk";
|
|
3
|
+
import type { CelProgramSite } from "./cel/compile.js";
|
|
3
4
|
import type { ModuleCallFlags } from "./cel/diagnose.js";
|
|
4
5
|
import type { ModuleCallTypeResolver } from "./cel/module-call.js";
|
|
5
6
|
|
|
@@ -20,6 +21,9 @@ export interface CompileEnv {
|
|
|
20
21
|
* before module functions existed.
|
|
21
22
|
*/
|
|
22
23
|
readonly moduleNames?: ReadonlySet<string>;
|
|
24
|
+
/** Receives every CEL expression compiled here, so a host can replace each
|
|
25
|
+
* program with one from an emitted module. */
|
|
26
|
+
readonly programSites?: CelProgramSite[];
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/** Analyze-time environment passed to `engine.analyze`. The walker resolves
|
package/src/engines/cel.ts
CHANGED
|
@@ -270,7 +270,7 @@ export const celEngine: TemplatingEngine = {
|
|
|
270
270
|
language: "cel",
|
|
271
271
|
|
|
272
272
|
compile(source, env) {
|
|
273
|
-
return compileExpression(source, env.celEnv, env.moduleNames);
|
|
273
|
+
return compileExpression(source, env.celEnv, env.moduleNames, env.programSites);
|
|
274
274
|
},
|
|
275
275
|
|
|
276
276
|
analyze(source, env) {
|
|
@@ -28,7 +28,7 @@ export function compileHoles(
|
|
|
28
28
|
readonly calls: readonly string[];
|
|
29
29
|
readonly volatile: boolean;
|
|
30
30
|
} {
|
|
31
|
-
const compiled = holes.map((h) => compileExpression(h.expr, env.celEnv, env.moduleNames));
|
|
31
|
+
const compiled = holes.map((h) => compileExpression(h.expr, env.celEnv, env.moduleNames, env.programSites));
|
|
32
32
|
const refs = new Set<string>();
|
|
33
33
|
const calls = new Set<string>();
|
|
34
34
|
let volatile = false;
|
package/src/index.ts
CHANGED
|
@@ -9,8 +9,12 @@ export {
|
|
|
9
9
|
// become the engine's namespace seam — exported because the analyzer evaluates
|
|
10
10
|
// rule conditions and function bodies through the same table, and a second
|
|
11
11
|
// adapter is what let it convert arguments differently from the kernel.
|
|
12
|
-
export {
|
|
13
|
-
|
|
12
|
+
export {
|
|
13
|
+
compileExpression,
|
|
14
|
+
namespaceDispatchOf,
|
|
15
|
+
siteEnvironment,
|
|
16
|
+
type CelProgramSite,
|
|
17
|
+
} from "./cel/compile.js";
|
|
14
18
|
export {
|
|
15
19
|
interpolationShape,
|
|
16
20
|
literalFragments,
|
|
@@ -21,6 +25,7 @@ export {
|
|
|
21
25
|
} from "./cel/interpolation-holes.js";
|
|
22
26
|
export {
|
|
23
27
|
EACH_SEGMENT,
|
|
28
|
+
PRESENCE_SEGMENT,
|
|
24
29
|
extractAccessChains,
|
|
25
30
|
extractReadChains,
|
|
26
31
|
findNullableAccessIssues,
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CelEnvironment } from "@telorun/cel";
|
|
2
|
-
/**
|
|
3
|
-
* Register every nominal value brand on an analysis environment, with what a brand may do:
|
|
4
|
-
* convert to its base with the base's own conversion (`int(ports.http)`,
|
|
5
|
-
* `string(variables.dataDir)`), render as text (`string(ports.http)`), and — for a host
|
|
6
|
-
* path — be extended with `.joinPath(relative)` and stay one.
|
|
7
|
-
*
|
|
8
|
-
* **Declared, not implemented.** A nominal type is a checking concept: the engine takes the
|
|
9
|
-
* conversions and members as signatures over `Self` and needs no function body for any of
|
|
10
|
-
* them, because at runtime a branded value IS its base (an int, a string) and the standard
|
|
11
|
-
* library's own overloads are what evaluate. The previous engine required an implementation
|
|
12
|
-
* per registration, so this file carried three stubs a brand's values never reached.
|
|
13
|
-
*
|
|
14
|
-
* `buildCelEnvironment` registers none of it: a caller typing a site registers the brands on
|
|
15
|
-
* its own clone.
|
|
16
|
-
*/
|
|
17
|
-
export declare function registerValueBrands(environment: CelEnvironment): void;
|
|
18
|
-
//# sourceMappingURL=value-brands.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"value-brands.d.ts","sourceRoot":"","sources":["../../src/cel/value-brands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,cAAc,GAAG,IAAI,CAerE"}
|
package/dist/cel/value-brands.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { VALUE_TYPES, valueBrandBases } from "@telorun/sdk";
|
|
2
|
-
/**
|
|
3
|
-
* Register every nominal value brand on an analysis environment, with what a brand may do:
|
|
4
|
-
* convert to its base with the base's own conversion (`int(ports.http)`,
|
|
5
|
-
* `string(variables.dataDir)`), render as text (`string(ports.http)`), and — for a host
|
|
6
|
-
* path — be extended with `.joinPath(relative)` and stay one.
|
|
7
|
-
*
|
|
8
|
-
* **Declared, not implemented.** A nominal type is a checking concept: the engine takes the
|
|
9
|
-
* conversions and members as signatures over `Self` and needs no function body for any of
|
|
10
|
-
* them, because at runtime a branded value IS its base (an int, a string) and the standard
|
|
11
|
-
* library's own overloads are what evaluate. The previous engine required an implementation
|
|
12
|
-
* per registration, so this file carried three stubs a brand's values never reached.
|
|
13
|
-
*
|
|
14
|
-
* `buildCelEnvironment` registers none of it: a caller typing a site registers the brands on
|
|
15
|
-
* its own clone.
|
|
16
|
-
*/
|
|
17
|
-
export function registerValueBrands(environment) {
|
|
18
|
-
for (const [brand, base] of Object.entries(valueBrandBases())) {
|
|
19
|
-
const conversions = [`${base}(Self): ${base}`];
|
|
20
|
-
// Every base CEL can render as text renders its brand too — the runtime value IS the
|
|
21
|
-
// base — so `string(ports.http)` and a port in an `!interpolate` hole convert as the
|
|
22
|
-
// integer they are.
|
|
23
|
-
if (base !== "string")
|
|
24
|
-
conversions.push("string(Self): string");
|
|
25
|
-
const fromHost = VALUE_TYPES.get(brand)?.fromHost !== undefined;
|
|
26
|
-
environment.registerType({
|
|
27
|
-
name: brand,
|
|
28
|
-
base,
|
|
29
|
-
conversions,
|
|
30
|
-
...(fromHost ? { members: ["Self.joinPath(string): Self"] } : {}),
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/cel/value-brands.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { CelEnvironment } from "@telorun/cel";
|
|
2
|
-
import { VALUE_TYPES, valueBrandBases } from "@telorun/sdk";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Register every nominal value brand on an analysis environment, with what a brand may do:
|
|
6
|
-
* convert to its base with the base's own conversion (`int(ports.http)`,
|
|
7
|
-
* `string(variables.dataDir)`), render as text (`string(ports.http)`), and — for a host
|
|
8
|
-
* path — be extended with `.joinPath(relative)` and stay one.
|
|
9
|
-
*
|
|
10
|
-
* **Declared, not implemented.** A nominal type is a checking concept: the engine takes the
|
|
11
|
-
* conversions and members as signatures over `Self` and needs no function body for any of
|
|
12
|
-
* them, because at runtime a branded value IS its base (an int, a string) and the standard
|
|
13
|
-
* library's own overloads are what evaluate. The previous engine required an implementation
|
|
14
|
-
* per registration, so this file carried three stubs a brand's values never reached.
|
|
15
|
-
*
|
|
16
|
-
* `buildCelEnvironment` registers none of it: a caller typing a site registers the brands on
|
|
17
|
-
* its own clone.
|
|
18
|
-
*/
|
|
19
|
-
export function registerValueBrands(environment: CelEnvironment): void {
|
|
20
|
-
for (const [brand, base] of Object.entries(valueBrandBases())) {
|
|
21
|
-
const conversions = [`${base}(Self): ${base}`];
|
|
22
|
-
// Every base CEL can render as text renders its brand too — the runtime value IS the
|
|
23
|
-
// base — so `string(ports.http)` and a port in an `!interpolate` hole convert as the
|
|
24
|
-
// integer they are.
|
|
25
|
-
if (base !== "string") conversions.push("string(Self): string");
|
|
26
|
-
const fromHost = VALUE_TYPES.get(brand)?.fromHost !== undefined;
|
|
27
|
-
environment.registerType({
|
|
28
|
-
name: brand,
|
|
29
|
-
base,
|
|
30
|
-
conversions,
|
|
31
|
-
...(fromHost ? { members: ["Self.joinPath(string): Self"] } : {}),
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|