@telorun/analyzer 0.23.2 → 0.24.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.
@@ -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,EAAE,GAAG,CAAC,GAAG,SAAS,CAkCjC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAoBzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,IAAI,CAAC,EAAE,kBAAkB,GA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AClC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAkCjC;AA6DD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAoBzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,IAAI,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAChD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAgHrB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAQrB;AAWD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,IAAI,SAAM,GACT,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC,CAGvD"}
@@ -35,6 +35,63 @@ export function resolveTypeFieldToSchema(value, allManifests) {
35
35
  }
36
36
  return undefined;
37
37
  }
38
+ /** Pull the raw expression source from a CEL field value — a compiled value
39
+ * (`{ source }`), or a string (`!cel "x"` or `"${{ x }}"`). Strips a lone
40
+ * `${{ }}` wrapper. Returns null when no source is recoverable. */
41
+ function celExprSource(raw) {
42
+ let s;
43
+ if (typeof raw === "string")
44
+ s = raw;
45
+ else if (raw && typeof raw === "object" && typeof raw.source === "string")
46
+ s = raw.source;
47
+ if (s == null)
48
+ return null;
49
+ const exact = s.match(/^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/);
50
+ return (exact ? exact[1] : s).trim();
51
+ }
52
+ /** Member-access chain for a bare dotted-identifier expression
53
+ * (`inputs.user.tags` → ["inputs","user","tags"]). Returns null for anything
54
+ * else (literals, calls, indexing, comprehensions) — those are not statically
55
+ * reducible to a single typed path. */
56
+ function purePathChain(raw) {
57
+ const expr = celExprSource(raw);
58
+ if (expr == null)
59
+ return null;
60
+ if (!/^[A-Za-z_]\w*(\.[A-Za-z_]\w*)*$/.test(expr))
61
+ return null;
62
+ return expr.split(".");
63
+ }
64
+ /** Walk a member-access chain through a JSON Schema (descending `properties`)
65
+ * and return the terminal node, or undefined when the path leaves typed schema. */
66
+ function schemaAtChain(chain, root) {
67
+ let cur = root;
68
+ for (const key of chain) {
69
+ if (!cur || typeof cur !== "object")
70
+ return undefined;
71
+ const props = cur.properties;
72
+ if (!props || !(key in props))
73
+ return undefined;
74
+ cur = props[key];
75
+ }
76
+ return cur && typeof cur === "object" ? cur : undefined;
77
+ }
78
+ /** The element schema of a sibling collection expression, when statically known.
79
+ * Resolves `inputs.*` chains against the resource's `inputs:` contract and
80
+ * returns the array's `items`. Returns undefined for non-chain or untyped
81
+ * collections (caller substitutes `dyn`). */
82
+ function resolveCollectionElementSchema(manifestRoot, field) {
83
+ const chain = purePathChain(manifestRoot?.[field]);
84
+ if (!chain || chain[0] !== "inputs")
85
+ return undefined;
86
+ const contract = manifestRoot.inputs;
87
+ if (!contract || typeof contract !== "object")
88
+ return undefined;
89
+ const terminal = schemaAtChain(chain.slice(1), { type: "object", properties: contract });
90
+ if (terminal && terminal.type === "array" && terminal.items && typeof terminal.items === "object") {
91
+ return terminal.items;
92
+ }
93
+ return undefined;
94
+ }
38
95
  /**
39
96
  * Returns true when a CEL expression path (from walkCelExpressions, e.g. "routes[0].inputs.q")
40
97
  * falls within the scope of a context (e.g. "$.routes[*].inputs").
@@ -131,6 +188,16 @@ export function resolveContextAnnotations(schema, manifestItem, opts) {
131
188
  additionalProperties: false,
132
189
  };
133
190
  }
191
+ // Element typing: derive a variable's schema from the element type of a sibling
192
+ // collection expression (e.g. `item` from `collection`). Resolves only when the
193
+ // collection is a member-access chain into the resource's typed `inputs` contract
194
+ // (the common, statically-knowable case); list literals, comprehensions, and
195
+ // untyped sources fall back to `dyn` so a wrong element type is never invented.
196
+ const elementFrom = schema["x-telo-context-element-from"];
197
+ if (elementFrom) {
198
+ const items = resolveCollectionElementSchema(manifestRoot, elementFrom);
199
+ return items ?? {};
200
+ }
134
201
  const fromRoot = schema["x-telo-context-from-root"];
135
202
  const fromRefKindRaw = schema["x-telo-context-from-ref-kind"];
136
203
  const fromRefKinds = fromRefKindRaw == null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/analyzer",
3
- "version": "0.23.2",
3
+ "version": "0.24.1",
4
4
  "description": "Telo Analyzer - Static manifest validator for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -42,7 +42,7 @@
42
42
  "ajv-formats": "^3.0.1",
43
43
  "jsonpath-plus": "^10.3.0",
44
44
  "yaml": "^2.8.3",
45
- "@telorun/templating": "0.8.0"
45
+ "@telorun/templating": "0.10.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/node": "^20.0.0",
@@ -61,6 +61,65 @@ export function resolveTypeFieldToSchema(
61
61
  return undefined;
62
62
  }
63
63
 
64
+ /** Pull the raw expression source from a CEL field value — a compiled value
65
+ * (`{ source }`), or a string (`!cel "x"` or `"${{ x }}"`). Strips a lone
66
+ * `${{ }}` wrapper. Returns null when no source is recoverable. */
67
+ function celExprSource(raw: unknown): string | null {
68
+ let s: string | undefined;
69
+ if (typeof raw === "string") s = raw;
70
+ else if (raw && typeof raw === "object" && typeof (raw as Record<string, any>).source === "string")
71
+ s = (raw as Record<string, any>).source;
72
+ if (s == null) return null;
73
+ const exact = s.match(/^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/);
74
+ return (exact ? exact[1] : s).trim();
75
+ }
76
+
77
+ /** Member-access chain for a bare dotted-identifier expression
78
+ * (`inputs.user.tags` → ["inputs","user","tags"]). Returns null for anything
79
+ * else (literals, calls, indexing, comprehensions) — those are not statically
80
+ * reducible to a single typed path. */
81
+ function purePathChain(raw: unknown): string[] | null {
82
+ const expr = celExprSource(raw);
83
+ if (expr == null) return null;
84
+ if (!/^[A-Za-z_]\w*(\.[A-Za-z_]\w*)*$/.test(expr)) return null;
85
+ return expr.split(".");
86
+ }
87
+
88
+ /** Walk a member-access chain through a JSON Schema (descending `properties`)
89
+ * and return the terminal node, or undefined when the path leaves typed schema. */
90
+ function schemaAtChain(
91
+ chain: string[],
92
+ root: Record<string, any>,
93
+ ): Record<string, any> | undefined {
94
+ let cur: Record<string, any> | undefined = root;
95
+ for (const key of chain) {
96
+ if (!cur || typeof cur !== "object") return undefined;
97
+ const props = cur.properties as Record<string, any> | undefined;
98
+ if (!props || !(key in props)) return undefined;
99
+ cur = props[key] as Record<string, any>;
100
+ }
101
+ return cur && typeof cur === "object" ? cur : undefined;
102
+ }
103
+
104
+ /** The element schema of a sibling collection expression, when statically known.
105
+ * Resolves `inputs.*` chains against the resource's `inputs:` contract and
106
+ * returns the array's `items`. Returns undefined for non-chain or untyped
107
+ * collections (caller substitutes `dyn`). */
108
+ function resolveCollectionElementSchema(
109
+ manifestRoot: Record<string, any>,
110
+ field: string,
111
+ ): Record<string, any> | undefined {
112
+ const chain = purePathChain(manifestRoot?.[field]);
113
+ if (!chain || chain[0] !== "inputs") return undefined;
114
+ const contract = manifestRoot.inputs;
115
+ if (!contract || typeof contract !== "object") return undefined;
116
+ const terminal = schemaAtChain(chain.slice(1), { type: "object", properties: contract });
117
+ if (terminal && terminal.type === "array" && terminal.items && typeof terminal.items === "object") {
118
+ return terminal.items as Record<string, any>;
119
+ }
120
+ return undefined;
121
+ }
122
+
64
123
  /**
65
124
  * Returns true when a CEL expression path (from walkCelExpressions, e.g. "routes[0].inputs.q")
66
125
  * falls within the scope of a context (e.g. "$.routes[*].inputs").
@@ -162,6 +221,17 @@ export function resolveContextAnnotations(
162
221
  };
163
222
  }
164
223
 
224
+ // Element typing: derive a variable's schema from the element type of a sibling
225
+ // collection expression (e.g. `item` from `collection`). Resolves only when the
226
+ // collection is a member-access chain into the resource's typed `inputs` contract
227
+ // (the common, statically-knowable case); list literals, comprehensions, and
228
+ // untyped sources fall back to `dyn` so a wrong element type is never invented.
229
+ const elementFrom = schema["x-telo-context-element-from"] as string | undefined;
230
+ if (elementFrom) {
231
+ const items = resolveCollectionElementSchema(manifestRoot, elementFrom);
232
+ return items ?? {};
233
+ }
234
+
165
235
  const fromRoot = schema["x-telo-context-from-root"] as string | undefined;
166
236
  const fromRefKindRaw = schema["x-telo-context-from-ref-kind"] as
167
237
  | string