@telorun/analyzer 0.23.1 → 0.23.2

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.
@@ -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 containing the original manifests (mutated in-place) plus all
19
- * extracted manifests. The original array is not mutated.
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;AAczD;;;;;;;;;;;;;;;;GAgBG;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,CA+DpB"}
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 containing the original manifests (mutated in-place) plus all
27
- * extracted manifests. The original array is not mutated.
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
- const result = [...resources];
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
- const queue = resources.filter((r) => typeof r.metadata?.name === "string" && !!r.kind && !SYSTEM_KINDS.has(r.kind));
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++];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/analyzer",
3
- "version": "0.23.1",
3
+ "version": "0.23.2",
4
4
  "description": "Telo Analyzer - Static manifest validator for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -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 containing the original manifests (mutated in-place) plus all
33
- * extracted manifests. The original array is not mutated.
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
- const result = [...resources];
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
- const queue = resources.filter(
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
  );