@telorun/templating 0.122.0 → 0.123.1

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.
@@ -89,5 +89,17 @@ export declare function findNullableAccessIssues(node: CelNode, contextSchema: R
89
89
  * Returns null when the chain is valid or the schema is too open to judge.
90
90
  */
91
91
  export declare function validateChainAgainstSchema(chain: string[], schema: Record<string, any>): string | null;
92
+ /**
93
+ * The member chains whose last read the type checker already refused, joined with
94
+ * `.` — the select nodes whose member range is one of `ranges`, which is where the
95
+ * checker reports an unknown member. A context schema read of the same chain would
96
+ * say it a second time, in other words.
97
+ */
98
+ export declare function chainsRefusedAt(node: CelNode, ranges: ReadonlyArray<readonly [number, number]>): Set<string>;
99
+ /** {@link validateChainAgainstSchema}, with the path of the read that failed. */
100
+ export declare function chainFailureAgainstSchema(chain: string[], schema: Record<string, any>): {
101
+ path: string;
102
+ message: string;
103
+ } | null;
92
104
  export {};
93
105
  //# sourceMappingURL=analyze.d.ts.map
@@ -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;;mDAEmD;AACnD,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB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AAM,CAAC,CAab;AAED,iFAAiF;AACjF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA8C1C"}
@@ -454,6 +454,33 @@ function walkNullable(node, nonNull, boundVars, issues, schema) {
454
454
  * Returns null when the chain is valid or the schema is too open to judge.
455
455
  */
456
456
  export function validateChainAgainstSchema(chain, schema) {
457
+ return chainFailureAgainstSchema(chain, schema)?.message ?? null;
458
+ }
459
+ /**
460
+ * The member chains whose last read the type checker already refused, joined with
461
+ * `.` — the select nodes whose member range is one of `ranges`, which is where the
462
+ * checker reports an unknown member. A context schema read of the same chain would
463
+ * say it a second time, in other words.
464
+ */
465
+ export function chainsRefusedAt(node, ranges) {
466
+ const refused = new Set();
467
+ if (ranges.length === 0)
468
+ return refused;
469
+ const at = new Set(ranges.map(([start, end]) => `${start}:${end}`));
470
+ const visit = (current) => {
471
+ if (current.kind === "select" && at.has(`${current.fieldRange[0]}:${current.fieldRange[1]}`)) {
472
+ const chain = extractChain(current, new Set());
473
+ if (chain)
474
+ refused.add(chain.join("."));
475
+ }
476
+ for (const child of childNodes(current))
477
+ visit(child);
478
+ };
479
+ visit(node);
480
+ return refused;
481
+ }
482
+ /** {@link validateChainAgainstSchema}, with the path of the read that failed. */
483
+ export function chainFailureAgainstSchema(chain, schema) {
457
484
  let current = schema;
458
485
  for (let i = 0; i < chain.length; i++) {
459
486
  const key = chain[i];
@@ -487,7 +514,10 @@ export function validateChainAgainstSchema(chain, schema) {
487
514
  const propSchema = props[key];
488
515
  if (isLiveSlot(propSchema) && i < chain.length - 1) {
489
516
  const path = chain.slice(0, i + 1).join(".");
490
- return `'${path}' yields a stream — pipe it through an Encoder or iterate in a JS.Script step (no member access on stream-typed values)`;
517
+ return {
518
+ path,
519
+ message: `'${path}' yields a stream — pipe it through an Encoder or iterate in a JS.Script step (no member access on stream-typed values)`,
520
+ };
491
521
  }
492
522
  current = propSchema;
493
523
  continue;
@@ -496,7 +526,7 @@ export function validateChainAgainstSchema(chain, schema) {
496
526
  return null;
497
527
  const path = chain.slice(0, i + 1).join(".");
498
528
  const available = Object.keys(props).join(", ");
499
- return `'${path}' is not defined (available: ${available})`;
529
+ return { path, message: `'${path}' is not defined (available: ${available})` };
500
530
  }
501
531
  return null;
502
532
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cel.d.ts","sourceRoot":"","sources":["../../src/engines/cel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAYxE,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAY,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;;;;;;2BAU2B;AAC3B,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAEtF;AAED;8EAC8E;AAC9E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,GACd;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CAoL7C;AAkDD;yCACyC;AACzC,eAAO,MAAM,SAAS,EAAE,gBAmBvB,CAAC"}
1
+ {"version":3,"file":"cel.d.ts","sourceRoot":"","sources":["../../src/engines/cel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAcxE,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAY,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;;;;;;2BAU2B;AAC3B,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAEtF;AAED;8EAC8E;AAC9E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,GACd;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CA4L7C;AAkDD;yCACyC;AACzC,eAAO,MAAM,SAAS,EAAE,gBAmBvB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { qualifiedCalls } from "@telorun/cel";
2
- import { extractAccessChains, extractCallResultAccesses, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "../cel/analyze.js";
2
+ import { chainFailureAgainstSchema, chainsRefusedAt, extractAccessChains, extractCallResultAccesses, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "../cel/analyze.js";
3
3
  import { compileExpression, repeatableExpression } from "../cel/compile.js";
4
4
  import { auditCalls } from "../cel/diagnose.js";
5
5
  import { moduleNameBindings, unresolvedCallReceivers } from "../cel/module-call.js";
@@ -162,10 +162,15 @@ export function analyzeCelWithTree(source, env) {
162
162
  }
163
163
  if (env.contextSchema) {
164
164
  const contextSchema = env.contextSchema;
165
+ // A member of a closed record the type checker refused is its verdict already.
166
+ const refusedByChecker = chainsRefusedAt(ast, checked.valid
167
+ ? []
168
+ : checked.diagnostics.filter((d) => d.code === "CEL_UNKNOWN_FIELD").map((d) => d.range));
165
169
  for (const chain of extractAccessChains(ast)) {
166
- const err = validateChainAgainstSchema(chain, contextSchema);
167
- if (err && !explained.has(err))
168
- out.push({ code: "CEL_UNKNOWN_FIELD", message: err });
170
+ const failure = chainFailureAgainstSchema(chain, contextSchema);
171
+ if (!failure || explained.has(failure.message) || refusedByChecker.has(failure.path))
172
+ continue;
173
+ out.push({ code: "CEL_UNKNOWN_FIELD", message: failure.message });
169
174
  }
170
175
  for (const issue of findNullableAccessIssues(ast, contextSchema)) {
171
176
  // Index access (member "[index]") attaches without a dot; a named field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/templating",
3
- "version": "0.122.0",
3
+ "version": "0.123.1",
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.122.0"
42
+ "@telorun/cel": "0.123.1"
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.122.0"
49
+ "@telorun/sdk": "0.123.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@telorun/sdk": "*"
@@ -518,6 +518,38 @@ export function validateChainAgainstSchema(
518
518
  chain: string[],
519
519
  schema: Record<string, any>,
520
520
  ): string | null {
521
+ return chainFailureAgainstSchema(chain, schema)?.message ?? null;
522
+ }
523
+
524
+ /**
525
+ * The member chains whose last read the type checker already refused, joined with
526
+ * `.` — the select nodes whose member range is one of `ranges`, which is where the
527
+ * checker reports an unknown member. A context schema read of the same chain would
528
+ * say it a second time, in other words.
529
+ */
530
+ export function chainsRefusedAt(
531
+ node: CelNode,
532
+ ranges: ReadonlyArray<readonly [number, number]>,
533
+ ): Set<string> {
534
+ const refused = new Set<string>();
535
+ if (ranges.length === 0) return refused;
536
+ const at = new Set(ranges.map(([start, end]) => `${start}:${end}`));
537
+ const visit = (current: CelNode): void => {
538
+ if (current.kind === "select" && at.has(`${current.fieldRange[0]}:${current.fieldRange[1]}`)) {
539
+ const chain = extractChain(current, new Set());
540
+ if (chain) refused.add(chain.join("."));
541
+ }
542
+ for (const child of childNodes(current)) visit(child);
543
+ };
544
+ visit(node);
545
+ return refused;
546
+ }
547
+
548
+ /** {@link validateChainAgainstSchema}, with the path of the read that failed. */
549
+ export function chainFailureAgainstSchema(
550
+ chain: string[],
551
+ schema: Record<string, any>,
552
+ ): { path: string; message: string } | null {
521
553
  let current: Record<string, any> = schema;
522
554
  for (let i = 0; i < chain.length; i++) {
523
555
  const key = chain[i]!;
@@ -549,7 +581,10 @@ export function validateChainAgainstSchema(
549
581
  const propSchema = props[key];
550
582
  if (isLiveSlot(propSchema) && i < chain.length - 1) {
551
583
  const path = chain.slice(0, i + 1).join(".");
552
- return `'${path}' yields a stream — pipe it through an Encoder or iterate in a JS.Script step (no member access on stream-typed values)`;
584
+ return {
585
+ path,
586
+ message: `'${path}' yields a stream — pipe it through an Encoder or iterate in a JS.Script step (no member access on stream-typed values)`,
587
+ };
553
588
  }
554
589
  current = propSchema;
555
590
  continue;
@@ -557,7 +592,7 @@ export function validateChainAgainstSchema(
557
592
  if (!members && current.additionalProperties === true) return null;
558
593
  const path = chain.slice(0, i + 1).join(".");
559
594
  const available = Object.keys(props).join(", ");
560
- return `'${path}' is not defined (available: ${available})`;
595
+ return { path, message: `'${path}' is not defined (available: ${available})` };
561
596
  }
562
597
  return null;
563
598
  }
@@ -1,5 +1,7 @@
1
1
  import { formatType, qualifiedCalls, type CelNode } from "@telorun/cel";
2
2
  import {
3
+ chainFailureAgainstSchema,
4
+ chainsRefusedAt,
3
5
  extractAccessChains,
4
6
  extractCallResultAccesses,
5
7
  findNullableAccessIssues,
@@ -185,9 +187,17 @@ export function analyzeCelWithTree(
185
187
 
186
188
  if (env.contextSchema) {
187
189
  const contextSchema = env.contextSchema as Record<string, any>;
190
+ // A member of a closed record the type checker refused is its verdict already.
191
+ const refusedByChecker = chainsRefusedAt(
192
+ ast,
193
+ checked.valid
194
+ ? []
195
+ : checked.diagnostics.filter((d) => d.code === "CEL_UNKNOWN_FIELD").map((d) => d.range),
196
+ );
188
197
  for (const chain of extractAccessChains(ast)) {
189
- const err = validateChainAgainstSchema(chain, contextSchema);
190
- if (err && !explained.has(err)) out.push({ code: "CEL_UNKNOWN_FIELD", message: err });
198
+ const failure = chainFailureAgainstSchema(chain, contextSchema);
199
+ if (!failure || explained.has(failure.message) || refusedByChecker.has(failure.path)) continue;
200
+ out.push({ code: "CEL_UNKNOWN_FIELD", message: failure.message });
191
201
  }
192
202
 
193
203
  for (const issue of findNullableAccessIssues(ast, contextSchema)) {