@telorun/analyzer 0.23.1 → 0.24.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/normalize-inline-resources.d.ts +3 -2
- package/dist/normalize-inline-resources.d.ts.map +1 -1
- package/dist/normalize-inline-resources.js +30 -4
- package/dist/validate-cel-context.d.ts.map +1 -1
- package/dist/validate-cel-context.js +67 -0
- package/package.json +2 -2
- package/src/normalize-inline-resources.ts +28 -4
- package/src/validate-cel-context.ts +70 -0
|
@@ -15,8 +15,9 @@ import type { AliasResolver } from "./alias-resolver.js";
|
|
|
15
15
|
* e.g. TestBasicAddition_steps_AddTwoNumbers_invoke
|
|
16
16
|
* TestBasicAddition_steps_0_invoke (when step has no name)
|
|
17
17
|
*
|
|
18
|
-
* Returns a new array
|
|
19
|
-
* extracted manifests. The
|
|
18
|
+
* Returns a new array of deep-cloned manifests (the rewrites land on the clones)
|
|
19
|
+
* plus all extracted manifests. The caller's manifests — array and elements — are
|
|
20
|
+
* never mutated; this is the analyzer's immutability boundary.
|
|
20
21
|
*/
|
|
21
22
|
export declare function normalizeInlineResources(resources: ResourceManifest[], registry: DefinitionRegistry, aliases?: AliasResolver, aliasesByModule?: Map<string, AliasResolver>): ResourceManifest[];
|
|
22
23
|
//# sourceMappingURL=normalize-inline-resources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-inline-resources.d.ts","sourceRoot":"","sources":["../src/normalize-inline-resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"normalize-inline-resources.d.ts","sourceRoot":"","sources":["../src/normalize-inline-resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA8BzD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAC3C,gBAAgB,EAAE,CAsEpB"}
|
|
@@ -9,6 +9,24 @@ const SYSTEM_KINDS = new Set([
|
|
|
9
9
|
function sanitizeName(raw) {
|
|
10
10
|
return raw.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
11
11
|
}
|
|
12
|
+
/** Deep-clones a manifest value tree so the in-place rewrites this module and
|
|
13
|
+
* `resolveRefSentinels` perform never reach caller-owned objects. Compiled-CEL
|
|
14
|
+
* nodes (`{__compiled, source, call?}`) are opaque leaves carrying functions —
|
|
15
|
+
* copied by reference, never descended into — matching how `resolveRefSentinels`
|
|
16
|
+
* and `manifest-visitor` short-circuit on `__compiled`. */
|
|
17
|
+
function cloneForMutation(value) {
|
|
18
|
+
if (value === null || typeof value !== "object")
|
|
19
|
+
return value;
|
|
20
|
+
if (value.__compiled)
|
|
21
|
+
return value;
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return value.map(cloneForMutation);
|
|
24
|
+
const out = {};
|
|
25
|
+
for (const key of Object.keys(value)) {
|
|
26
|
+
out[key] = cloneForMutation(value[key]);
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
12
30
|
/**
|
|
13
31
|
* Phase 2 — Inline resource normalization.
|
|
14
32
|
*
|
|
@@ -23,13 +41,21 @@ function sanitizeName(raw) {
|
|
|
23
41
|
* e.g. TestBasicAddition_steps_AddTwoNumbers_invoke
|
|
24
42
|
* TestBasicAddition_steps_0_invoke (when step has no name)
|
|
25
43
|
*
|
|
26
|
-
* Returns a new array
|
|
27
|
-
* extracted manifests. The
|
|
44
|
+
* Returns a new array of deep-cloned manifests (the rewrites land on the clones)
|
|
45
|
+
* plus all extracted manifests. The caller's manifests — array and elements — are
|
|
46
|
+
* never mutated; this is the analyzer's immutability boundary.
|
|
28
47
|
*/
|
|
29
48
|
export function normalizeInlineResources(resources, registry, aliases, aliasesByModule) {
|
|
30
|
-
|
|
49
|
+
// Deep-clone the input so this pass — and `resolveRefSentinels`, which runs on
|
|
50
|
+
// this output — never mutate caller-owned manifests. `extractInlinesAtPath`
|
|
51
|
+
// rewrites inline ref slots in place, so without cloning we'd corrupt shared
|
|
52
|
+
// state such as the editor's `LoadedFile.manifests` parse cache (a reused
|
|
53
|
+
// sentinel would be rewritten to `{kind, name}`, later misread as an authored
|
|
54
|
+
// reference form). The clone is the analyzer's immutability boundary.
|
|
55
|
+
const result = resources.map(cloneForMutation);
|
|
31
56
|
// Queue: all non-system resources with a name. Extracted resources are appended.
|
|
32
|
-
|
|
57
|
+
// Filter the CLONES (not the originals) so traversal mutates copies.
|
|
58
|
+
const queue = result.filter((r) => typeof r.metadata?.name === "string" && !!r.kind && !SYSTEM_KINDS.has(r.kind));
|
|
33
59
|
let i = 0;
|
|
34
60
|
while (i < queue.length) {
|
|
35
61
|
const resource = queue[i++];
|
|
@@ -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;
|
|
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;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.
|
|
3
|
+
"version": "0.24.0",
|
|
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.
|
|
45
|
+
"@telorun/templating": "0.9.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^20.0.0",
|
|
@@ -15,6 +15,22 @@ function sanitizeName(raw: string): string {
|
|
|
15
15
|
return raw.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** Deep-clones a manifest value tree so the in-place rewrites this module and
|
|
19
|
+
* `resolveRefSentinels` perform never reach caller-owned objects. Compiled-CEL
|
|
20
|
+
* nodes (`{__compiled, source, call?}`) are opaque leaves carrying functions —
|
|
21
|
+
* copied by reference, never descended into — matching how `resolveRefSentinels`
|
|
22
|
+
* and `manifest-visitor` short-circuit on `__compiled`. */
|
|
23
|
+
function cloneForMutation(value: unknown): unknown {
|
|
24
|
+
if (value === null || typeof value !== "object") return value;
|
|
25
|
+
if ((value as { __compiled?: unknown }).__compiled) return value;
|
|
26
|
+
if (Array.isArray(value)) return value.map(cloneForMutation);
|
|
27
|
+
const out: Record<string, unknown> = {};
|
|
28
|
+
for (const key of Object.keys(value)) {
|
|
29
|
+
out[key] = cloneForMutation((value as Record<string, unknown>)[key]);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
18
34
|
/**
|
|
19
35
|
* Phase 2 — Inline resource normalization.
|
|
20
36
|
*
|
|
@@ -29,8 +45,9 @@ function sanitizeName(raw: string): string {
|
|
|
29
45
|
* e.g. TestBasicAddition_steps_AddTwoNumbers_invoke
|
|
30
46
|
* TestBasicAddition_steps_0_invoke (when step has no name)
|
|
31
47
|
*
|
|
32
|
-
* Returns a new array
|
|
33
|
-
* extracted manifests. The
|
|
48
|
+
* Returns a new array of deep-cloned manifests (the rewrites land on the clones)
|
|
49
|
+
* plus all extracted manifests. The caller's manifests — array and elements — are
|
|
50
|
+
* never mutated; this is the analyzer's immutability boundary.
|
|
34
51
|
*/
|
|
35
52
|
export function normalizeInlineResources(
|
|
36
53
|
resources: ResourceManifest[],
|
|
@@ -38,10 +55,17 @@ export function normalizeInlineResources(
|
|
|
38
55
|
aliases?: AliasResolver,
|
|
39
56
|
aliasesByModule?: Map<string, AliasResolver>,
|
|
40
57
|
): ResourceManifest[] {
|
|
41
|
-
|
|
58
|
+
// Deep-clone the input so this pass — and `resolveRefSentinels`, which runs on
|
|
59
|
+
// this output — never mutate caller-owned manifests. `extractInlinesAtPath`
|
|
60
|
+
// rewrites inline ref slots in place, so without cloning we'd corrupt shared
|
|
61
|
+
// state such as the editor's `LoadedFile.manifests` parse cache (a reused
|
|
62
|
+
// sentinel would be rewritten to `{kind, name}`, later misread as an authored
|
|
63
|
+
// reference form). The clone is the analyzer's immutability boundary.
|
|
64
|
+
const result = resources.map(cloneForMutation) as ResourceManifest[];
|
|
42
65
|
|
|
43
66
|
// Queue: all non-system resources with a name. Extracted resources are appended.
|
|
44
|
-
|
|
67
|
+
// Filter the CLONES (not the originals) so traversal mutates copies.
|
|
68
|
+
const queue = result.filter(
|
|
45
69
|
(r): r is ResourceManifest & { metadata: { name: string } } =>
|
|
46
70
|
typeof r.metadata?.name === "string" && !!r.kind && !SYSTEM_KINDS.has(r.kind),
|
|
47
71
|
);
|
|
@@ -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
|