@telorun/analyzer 0.28.0 → 0.28.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.
@@ -20,7 +20,7 @@ export interface ContextResolveOpts {
20
20
  * - Object with `kind` + `schema`: inline type definition → return the `schema`
21
21
  * - Object with `type` or `properties`: raw JSON Schema, return as-is
22
22
  */
23
- export declare function resolveTypeFieldToSchema(value: unknown, allManifests: Record<string, any>[]): Record<string, any> | undefined;
23
+ export declare function resolveTypeFieldToSchema(value: unknown, allManifests: Record<string, any>[], ancestry?: ReadonlySet<string>): Record<string, any> | undefined;
24
24
  /**
25
25
  * Returns true when a CEL expression path (from walkCelExpressions, e.g. "routes[0].inputs.q")
26
26
  * falls within the scope of a context (e.g. "$.routes[*].inputs").
@@ -1 +1 @@
1
- {"version":3,"file":"validate-cel-context.d.ts","sourceRoot":"","sources":["../src/validate-cel-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEtF,MAAM,WAAW,kBAAkB;IACjC;mEAC+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC;;kDAE8C;IAC9C,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;KACxD,CAAC;IACF,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KAC/C,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CACtC;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAClC,MAAM,CAAC,MAAM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GACT,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC,CAGvD"}
@@ -1,27 +1,33 @@
1
1
  export { extractAccessChains, validateChainAgainstSchema } from "@telorun/templating";
2
+ import { mergeTypeSchemas } from "@telorun/sdk";
2
3
  /**
3
4
  * Resolve a type field value (string name, inline type, or raw schema) to a JSON Schema.
4
5
  * - String: look up the named type in allManifests (Type.JsonSchema resources)
5
6
  * - Object with `kind` + `schema`: inline type definition → return the `schema`
6
7
  * - Object with `type` or `properties`: raw JSON Schema, return as-is
7
8
  */
8
- export function resolveTypeFieldToSchema(value, allManifests) {
9
+ export function resolveTypeFieldToSchema(value, allManifests, ancestry = new Set()) {
9
10
  if (!value)
10
11
  return undefined;
11
12
  if (typeof value === "string") {
13
+ // Cycle guard: a type already on the resolution path can't extend back into it.
14
+ if (ancestry.has(value))
15
+ return undefined;
12
16
  // Named type reference — find a Telo.Type resource by name
13
17
  const typeManifest = allManifests.find((m) => m.metadata?.name === value &&
14
18
  typeof m.kind === "string" &&
15
19
  /\bType\b/.test(m.kind) &&
16
20
  typeof m.schema === "object" &&
17
21
  m.schema !== null);
18
- return typeManifest?.schema;
22
+ if (!typeManifest)
23
+ return undefined;
24
+ return applyExtends(typeManifest.schema, typeManifest.extends, allManifests, new Set(ancestry).add(value));
19
25
  }
20
26
  if (typeof value === "object" && value !== null) {
21
27
  const obj = value;
22
28
  // Inline type resource: { kind: "Type.JsonSchema", schema: {...} }
23
29
  if (obj.schema && typeof obj.schema === "object") {
24
- return obj.schema;
30
+ return applyExtends(obj.schema, obj.extends, allManifests, ancestry);
25
31
  }
26
32
  // Raw JSON Schema (has type or properties)
27
33
  if (obj.type || obj.properties) {
@@ -30,11 +36,34 @@ export function resolveTypeFieldToSchema(value, allManifests) {
30
36
  // Named type reference resolved from a `!ref` → { kind, name } — resolve the
31
37
  // named Telo.Type the same way as the bare-string form.
32
38
  if (typeof obj.name === "string") {
33
- return resolveTypeFieldToSchema(obj.name, allManifests);
39
+ return resolveTypeFieldToSchema(obj.name, allManifests, ancestry);
34
40
  }
35
41
  }
36
42
  return undefined;
37
43
  }
44
+ /**
45
+ * Fold a `Type.JsonSchema`'s `extends` parents into its own schema, matching the
46
+ * runtime `type` controller exactly — both call the shared `mergeTypeSchemas`, so
47
+ * static analysis and runtime validation can never disagree on a type's effective
48
+ * shape. Without this the analyzer would see only a child type's own properties
49
+ * and reject valid access to an inherited field with a false `CEL_UNKNOWN_FIELD`.
50
+ * `ancestry` carries the resolution path for cycle detection (siblings share it
51
+ * unmutated, so diamond inheritance still re-includes a shared grandparent).
52
+ */
53
+ function applyExtends(ownSchema, extendsField, allManifests, ancestry) {
54
+ if (!extendsField)
55
+ return ownSchema;
56
+ const parents = Array.isArray(extendsField) ? extendsField : [extendsField];
57
+ const resolved = [];
58
+ for (const parent of parents) {
59
+ const parentSchema = resolveTypeFieldToSchema(parent, allManifests, ancestry);
60
+ if (parentSchema)
61
+ resolved.push(parentSchema);
62
+ }
63
+ if (resolved.length === 0)
64
+ return ownSchema;
65
+ return mergeTypeSchemas([...resolved, ownSchema]);
66
+ }
38
67
  /** Pull the raw expression source from a CEL field value — a compiled value
39
68
  * (`{ source }`), or a string (`!cel "x"` or `"${{ x }}"`). Strips a lone
40
69
  * `${{ }}` wrapper. Returns null when no source is recoverable. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/analyzer",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "Telo Analyzer - Static manifest validator for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -48,7 +48,7 @@
48
48
  "@types/node": "^20.0.0",
49
49
  "typescript": "^5.0.0",
50
50
  "vitest": "^2.1.8",
51
- "@telorun/sdk": "0.36.0"
51
+ "@telorun/sdk": "0.38.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@telorun/sdk": "*"
@@ -1,4 +1,5 @@
1
1
  export { extractAccessChains, validateChainAgainstSchema } from "@telorun/templating";
2
+ import { mergeTypeSchemas } from "@telorun/sdk";
2
3
 
3
4
  export interface ContextResolveOpts {
4
5
  /** When provided, used to resolve `x-telo-context-from-root` annotations against the
@@ -25,10 +26,13 @@ export interface ContextResolveOpts {
25
26
  export function resolveTypeFieldToSchema(
26
27
  value: unknown,
27
28
  allManifests: Record<string, any>[],
29
+ ancestry: ReadonlySet<string> = new Set(),
28
30
  ): Record<string, any> | undefined {
29
31
  if (!value) return undefined;
30
32
 
31
33
  if (typeof value === "string") {
34
+ // Cycle guard: a type already on the resolution path can't extend back into it.
35
+ if (ancestry.has(value)) return undefined;
32
36
  // Named type reference — find a Telo.Type resource by name
33
37
  const typeManifest = allManifests.find(
34
38
  (m) =>
@@ -38,14 +42,20 @@ export function resolveTypeFieldToSchema(
38
42
  typeof m.schema === "object" &&
39
43
  m.schema !== null,
40
44
  );
41
- return typeManifest?.schema as Record<string, any> | undefined;
45
+ if (!typeManifest) return undefined;
46
+ return applyExtends(
47
+ typeManifest.schema as Record<string, any>,
48
+ typeManifest.extends,
49
+ allManifests,
50
+ new Set(ancestry).add(value),
51
+ );
42
52
  }
43
53
 
44
54
  if (typeof value === "object" && value !== null) {
45
55
  const obj = value as Record<string, any>;
46
56
  // Inline type resource: { kind: "Type.JsonSchema", schema: {...} }
47
57
  if (obj.schema && typeof obj.schema === "object") {
48
- return obj.schema as Record<string, any>;
58
+ return applyExtends(obj.schema as Record<string, any>, obj.extends, allManifests, ancestry);
49
59
  }
50
60
  // Raw JSON Schema (has type or properties)
51
61
  if (obj.type || obj.properties) {
@@ -54,13 +64,39 @@ export function resolveTypeFieldToSchema(
54
64
  // Named type reference resolved from a `!ref` → { kind, name } — resolve the
55
65
  // named Telo.Type the same way as the bare-string form.
56
66
  if (typeof obj.name === "string") {
57
- return resolveTypeFieldToSchema(obj.name, allManifests);
67
+ return resolveTypeFieldToSchema(obj.name, allManifests, ancestry);
58
68
  }
59
69
  }
60
70
 
61
71
  return undefined;
62
72
  }
63
73
 
74
+ /**
75
+ * Fold a `Type.JsonSchema`'s `extends` parents into its own schema, matching the
76
+ * runtime `type` controller exactly — both call the shared `mergeTypeSchemas`, so
77
+ * static analysis and runtime validation can never disagree on a type's effective
78
+ * shape. Without this the analyzer would see only a child type's own properties
79
+ * and reject valid access to an inherited field with a false `CEL_UNKNOWN_FIELD`.
80
+ * `ancestry` carries the resolution path for cycle detection (siblings share it
81
+ * unmutated, so diamond inheritance still re-includes a shared grandparent).
82
+ */
83
+ function applyExtends(
84
+ ownSchema: Record<string, any>,
85
+ extendsField: unknown,
86
+ allManifests: Record<string, any>[],
87
+ ancestry: ReadonlySet<string>,
88
+ ): Record<string, any> {
89
+ if (!extendsField) return ownSchema;
90
+ const parents = Array.isArray(extendsField) ? extendsField : [extendsField];
91
+ const resolved: Record<string, any>[] = [];
92
+ for (const parent of parents) {
93
+ const parentSchema = resolveTypeFieldToSchema(parent, allManifests, ancestry);
94
+ if (parentSchema) resolved.push(parentSchema);
95
+ }
96
+ if (resolved.length === 0) return ownSchema;
97
+ return mergeTypeSchemas([...resolved, ownSchema]) as Record<string, any>;
98
+ }
99
+
64
100
  /** Pull the raw expression source from a CEL field value — a compiled value
65
101
  * (`{ source }`), or a string (`!cel "x"` or `"${{ x }}"`). Strips a lone
66
102
  * `${{ }}` wrapper. Returns null when no source is recoverable. */