@telorun/templating 0.116.0 → 0.117.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.
@@ -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;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAI3D;AA4DD;+DAC+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAI3E;AA4BD,UAAU,aAAa;IACrB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AA0BD;;sBAEsB;AACtB,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,MAAM,GAAG,IAAI,CAIf;AA0DD;;;;;;;GAOG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BD;;sBAEsB;AACtB,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,MAAM,GAAG,IAAI,CAIf;AA0DD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,aAAa,EAAE,CAIjB;AA2ED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,GAAG,IAAI,CA2Cf"}
@@ -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.
@@ -456,7 +456,10 @@ export function validateChainAgainstSchema(chain, schema) {
456
456
  current = element;
457
457
  continue;
458
458
  }
459
- const props = current.properties;
459
+ // A value type declaring members is read by those members alone: they are its
460
+ // fields, closed as the CEL type the type registers.
461
+ const members = membersOf(current);
462
+ const props = members ?? current.properties;
460
463
  if (!props)
461
464
  return null;
462
465
  if (key in props) {
@@ -468,7 +471,7 @@ export function validateChainAgainstSchema(chain, schema) {
468
471
  current = propSchema;
469
472
  continue;
470
473
  }
471
- if (current.additionalProperties === true)
474
+ if (!members && current.additionalProperties === true)
472
475
  return null;
473
476
  const path = chain.slice(0, i + 1).join(".");
474
477
  const available = Object.keys(props).join(", ");
@@ -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, and the live `Stream` type. */
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;AAEtB;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,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,cAAc,CAOvF;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,IAAI,UAAU,CAAC,OAAO,eAAe,CAAC,CAEvE"}
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"}
@@ -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, and the live `Stream` type. */
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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, celFunctionCatalog, type CelHandlers, } from "./cel/environment.js";
2
2
  export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
3
- export { registerValueBrands } from "./cel/value-brands.js";
4
3
  export { interpolationShape, literalFragments, readInterpolationHoles, type HoleReading, type InterpolationHole, type InterpolationShape, } from "./cel/interpolation-holes.js";
5
4
  export { EACH_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
6
5
  export { auditCalls, explainUnresolved, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
@@ -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,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,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,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,sBAA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,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
@@ -4,7 +4,6 @@ export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions,
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
6
  export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
7
- export { registerValueBrands } from "./cel/value-brands.js";
8
7
  export { interpolationShape, literalFragments, readInterpolationHoles, } from "./cel/interpolation-holes.js";
9
8
  export { EACH_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
10
9
  export { auditCalls, explainUnresolved, } from "./cel/diagnose.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/templating",
3
- "version": "0.116.0",
3
+ "version": "0.117.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.116.0"
42
+ "@telorun/cel": "0.117.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.116.0"
49
+ "@telorun/sdk": "0.117.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@telorun/sdk": "*"
@@ -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
  /**
@@ -517,7 +517,10 @@ export function validateChainAgainstSchema(
517
517
  current = element;
518
518
  continue;
519
519
  }
520
- const props: Record<string, any> | undefined = current.properties;
520
+ // A value type declaring members is read by those members alone: they are its
521
+ // fields, closed as the CEL type the type registers.
522
+ const members = membersOf(current);
523
+ const props: Record<string, any> | undefined = members ?? current.properties;
521
524
  if (!props) return null;
522
525
  if (key in props) {
523
526
  const propSchema = props[key];
@@ -528,7 +531,7 @@ export function validateChainAgainstSchema(
528
531
  current = propSchema;
529
532
  continue;
530
533
  }
531
- if (current.additionalProperties === true) return null;
534
+ if (!members && current.additionalProperties === true) return null;
532
535
  const path = chain.slice(0, i + 1).join(".");
533
536
  const available = Object.keys(props).join(", ");
534
537
  return `'${path}' is not defined (available: ${available})`;
@@ -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, and the live `Stream` type. */
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/index.ts CHANGED
@@ -10,7 +10,6 @@ export {
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
12
  export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
13
- export { registerValueBrands } from "./cel/value-brands.js";
14
13
  export {
15
14
  interpolationShape,
16
15
  literalFragments,
@@ -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"}
@@ -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
- }
@@ -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
- }