@elementumai/edk 0.10.3 → 0.11.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.
Files changed (155) hide show
  1. package/README.md +11 -7
  2. package/dist-sdk/src/catalog/token.js +2 -1
  3. package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
  4. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  5. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  6. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  7. package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
  8. package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
  9. package/dist-sdk/src/engine/ei/run.d.ts +22 -0
  10. package/dist-sdk/src/engine/ei/run.js +99 -18
  11. package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
  12. package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
  13. package/dist-sdk/src/engine/ei/state.d.ts +1 -1
  14. package/dist-sdk/src/engine/ei/state.js +17 -4
  15. package/dist-sdk/src/engine/progress.d.ts +3 -1
  16. package/dist-sdk/src/engine/progress.js +7 -3
  17. package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
  18. package/dist-sdk/src/engine/pull/authored-address.js +180 -29
  19. package/dist-sdk/src/engine/pull/context.d.ts +52 -7
  20. package/dist-sdk/src/engine/pull/context.js +7 -4
  21. package/dist-sdk/src/engine/tf/index.d.ts +3 -2
  22. package/dist-sdk/src/engine/tf/index.js +3 -2
  23. package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
  24. package/dist-sdk/src/engine/tf/labels.js +50 -0
  25. package/dist-sdk/src/engine/tf/model.d.ts +2 -0
  26. package/dist-sdk/src/engine/tf/model.js +26 -0
  27. package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
  28. package/dist-sdk/src/engine/tf/scan.js +123 -0
  29. package/dist-sdk/src/engine/validation.d.ts +2 -0
  30. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  31. package/dist-sdk/src/engine/workspace/loader.js +20 -0
  32. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
  33. package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
  34. package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
  35. package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
  36. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
  39. package/dist-sdk/src/entities/agent/build.js +7 -5
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
  41. package/dist-sdk/src/entities/agent/from-tf.js +13 -3
  42. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  43. package/dist-sdk/src/entities/agent/to-tf.js +28 -17
  44. package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
  45. package/dist-sdk/src/entities/agent/tools.js +6 -2
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -3
  50. package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
  51. package/dist-sdk/src/entities/agent-tool/types.js +13 -9
  52. package/dist-sdk/src/entities/app/build.d.ts +11 -0
  53. package/dist-sdk/src/entities/app/build.js +1 -0
  54. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +11 -7
  55. package/dist-sdk/src/entities/app/from-tf.js +19 -9
  56. package/dist-sdk/src/entities/app/to-tf.js +6 -4
  57. package/dist-sdk/src/entities/automation/build.d.ts +2 -7
  58. package/dist-sdk/src/entities/automation/build.js +55 -16
  59. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
  60. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
  61. package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
  62. package/dist-sdk/src/entities/automation/from-tf.js +456 -34
  63. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  64. package/dist-sdk/src/entities/automation/module.d.ts +22 -2
  65. package/dist-sdk/src/entities/automation/module.js +273 -58
  66. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  67. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  68. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
  69. package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -3
  70. package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
  71. package/dist-sdk/src/entities/automation/run-target.js +99 -0
  72. package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
  73. package/dist-sdk/src/entities/automation/script-code.js +24 -3
  74. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
  75. package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
  76. package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
  77. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -3
  78. package/dist-sdk/src/entities/automation/to-tf.js +171 -58
  79. package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
  80. package/dist-sdk/src/entities/automation/triggers.js +40 -0
  81. package/dist-sdk/src/entities/automation/types.d.ts +21 -0
  82. package/dist-sdk/src/entities/automation/types.js +26 -0
  83. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
  84. package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
  85. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  86. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
  87. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  88. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
  89. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
  90. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
  91. package/dist-sdk/src/entities/element/build.d.ts +10 -0
  92. package/dist-sdk/src/entities/element/build.js +1 -0
  93. package/dist-sdk/src/entities/element/from-tf.js +16 -9
  94. package/dist-sdk/src/entities/element/to-tf.js +6 -4
  95. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  96. package/dist-sdk/src/entities/field/from-tf.js +79 -1
  97. package/dist-sdk/src/entities/field/module.js +7 -0
  98. package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
  99. package/dist-sdk/src/entities/field/to-tf.js +51 -0
  100. package/dist-sdk/src/entities/file-reader/module.js +3 -3
  101. package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
  102. package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
  103. package/dist-sdk/src/entities/file-reader/types.js +7 -0
  104. package/dist-sdk/src/entities/org/group.d.ts +1 -0
  105. package/dist-sdk/src/entities/org/group.js +2 -1
  106. package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
  107. package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
  108. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
  109. package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
  110. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
  111. package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
  112. package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
  113. package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
  114. package/dist-sdk/src/entities/role/from-tf.js +24 -7
  115. package/dist-sdk/src/entities/role/to-tf.js +25 -7
  116. package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
  117. package/dist-sdk/src/entities/service-account/module.js +15 -0
  118. package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
  119. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  120. package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
  121. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
  122. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
  123. package/dist-sdk/src/entities/skill/from-tf.js +10 -3
  124. package/dist-sdk/src/entities/skill/module.js +44 -2
  125. package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
  126. package/dist-sdk/src/entities/skill/to-tf.js +23 -14
  127. package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
  128. package/dist-sdk/src/entities/skill/tools.js +6 -2
  129. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  130. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  131. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
  132. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +10 -2
  133. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
  134. package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
  135. package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
  136. package/dist-sdk/src/entities/view/from-tf.js +503 -25
  137. package/dist-sdk/src/entities/view/module.js +15 -0
  138. package/dist-sdk/src/entities/view/portable.d.ts +11 -0
  139. package/dist-sdk/src/entities/view/portable.js +47 -0
  140. package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
  141. package/dist-sdk/src/entities/view/to-tf.js +25 -7
  142. package/dist-sdk/src/entities/view/types.js +1 -1
  143. package/dist-sdk/src/entities/widget/build.d.ts +4 -3
  144. package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
  145. package/dist-sdk/src/entities/widget/from-tf.js +100 -3
  146. package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
  147. package/dist-sdk/src/entities/widget/to-tf.js +77 -14
  148. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
  149. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  150. package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
  151. package/dist-sdk/src/graph/field-resource-types.js +11 -0
  152. package/dist-sdk/src/graph/index.d.ts +28 -3
  153. package/dist-sdk/src/graph/index.js +12 -2
  154. package/dist-sdk/src/graph/types.d.ts +164 -5
  155. package/package.json +1 -1
@@ -266,3 +266,53 @@ export function stableIdSuffix(id) {
266
266
  export function scopedLabelToBagKey(ownerTfLabel, scopedLabel, scope = "app") {
267
267
  return tfLabelToTsLabel(childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope));
268
268
  }
269
+ /**
270
+ * The `N` of an export label `<base>_<N>` (N ≥ 1), or undefined when `label`
271
+ * is `base` itself or not derived from it. Pull reads a tool's pinned
272
+ * `labelSuffix` this way (edk#1987). An `N` above `Number.MAX_SAFE_INTEGER`
273
+ * is not a pin either: as a number it would round to a different label, so
274
+ * the tool stays unpinned rather than being silently renumbered.
275
+ */
276
+ export function exportLabelSuffix(base, label) {
277
+ if (!label.startsWith(`${base}_`))
278
+ return undefined;
279
+ const rest = label.slice(base.length + 1);
280
+ if (!/^[1-9][0-9]*$/.test(rest))
281
+ return undefined;
282
+ const count = Number(rest);
283
+ return Number.isSafeInteger(count) ? count : undefined;
284
+ }
285
+ /**
286
+ * `_N` suffixes, by position, for one owner's tools whose labels share a
287
+ * `base` (edk#1987). A tool with a pinned `labelSuffix` keeps exactly that
288
+ * `_N`. Every other tool takes the lowest count its group has not used or
289
+ * pinned, in list order, so the first unpinned one keeps the bare label.
290
+ * ei counts the same way in the platform's order; pull pins every tool ei
291
+ * gave a suffix, so tools ei counted but pull doesn't print (unimplemented
292
+ * kinds, dropped tools) still leave their slots free. `undefined` entries
293
+ * (tools ei doesn't count) get no suffix.
294
+ */
295
+ export function collisionLabelSuffixes(entries) {
296
+ const taken = new Map();
297
+ const takenFor = (base) => {
298
+ const set = taken.get(base) ?? new Set();
299
+ taken.set(base, set);
300
+ return set;
301
+ };
302
+ for (const entry of entries) {
303
+ if (entry?.pinned !== undefined)
304
+ takenFor(entry.base).add(entry.pinned);
305
+ }
306
+ return entries.map((entry) => {
307
+ if (entry === undefined)
308
+ return "";
309
+ if (entry.pinned !== undefined)
310
+ return `_${entry.pinned}`;
311
+ const used = takenFor(entry.base);
312
+ let count = 0;
313
+ while (used.has(count))
314
+ count++;
315
+ used.add(count);
316
+ return count > 0 ? `_${count}` : "";
317
+ });
318
+ }
@@ -110,3 +110,5 @@ export declare const expr: {
110
110
  scopedAttr(name: string, path?: PathSeg[]): TfExpr;
111
111
  forObject(variable: string, collection: TfExpr, key: TfExpr, value: TfExpr): TfExpr;
112
112
  };
113
+ /** Visits every expression leaf in a value, recursing into nested expressions. */
114
+ export declare function forEachExpr(value: TfValue, visit: (e: TfExpr) => void): void;
@@ -51,3 +51,29 @@ export const expr = {
51
51
  return { $expr: "for-object", variable, collection, key, value };
52
52
  },
53
53
  };
54
+ /** Visits every expression leaf in a value, recursing into nested expressions. */
55
+ export function forEachExpr(value, visit) {
56
+ if (isTfExpr(value)) {
57
+ visit(value);
58
+ if (value.$expr === "jsonencode") {
59
+ forEachExpr(value.value, visit);
60
+ }
61
+ else if (value.$expr === "template") {
62
+ for (const part of value.parts)
63
+ if (typeof part !== "string")
64
+ forEachExpr(part, visit);
65
+ }
66
+ else if (value.$expr === "for-object") {
67
+ forEachExpr(value.collection, visit);
68
+ forEachExpr(value.key, visit);
69
+ forEachExpr(value.value, visit);
70
+ }
71
+ return;
72
+ }
73
+ if (Array.isArray(value))
74
+ for (const item of value)
75
+ forEachExpr(item, visit);
76
+ else if (typeof value === "object" && value !== null)
77
+ for (const item of Object.values(value))
78
+ forEachExpr(item, visit);
79
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Lexical line view of HCL source for the text rewriters that must leave every
3
+ * untouched byte as ei wrote it. It locates structure only; it never parses
4
+ * values. Braces, brackets, `#`, and `resource "…"` inside a quoted string,
5
+ * a heredoc body (`<<EOT` / `<<-EOT`, e.g. execute-script JavaScript), a
6
+ * `${…}` / `%{…}` template hole, or a comment are not code.
7
+ */
8
+ /** One source line. `code` keeps only top-level code, with each string or heredoc reduced to `""`. */
9
+ export interface HclCodeLine {
10
+ readonly text: string;
11
+ readonly code: string;
12
+ /** The line begins in top-level code, not inside a string, heredoc, hole, or block comment. */
13
+ readonly startsInCode: boolean;
14
+ }
15
+ export declare function hclCodeLines(text: string): HclCodeLine[];
16
+ /** `{`/`}` and `[`/`]` depth change of a line's code. */
17
+ export declare function hclDepthDelta(line: HclCodeLine): {
18
+ readonly braces: number;
19
+ readonly brackets: number;
20
+ };
21
+ /** Index of the last line of the statement starting at `start`: a value that opens a heredoc or block comment runs past its own line. */
22
+ export declare function hclStatementEnd(lines: readonly HclCodeLine[], start: number): number;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Lexical line view of HCL source for the text rewriters that must leave every
3
+ * untouched byte as ei wrote it. It locates structure only; it never parses
4
+ * values. Braces, brackets, `#`, and `resource "…"` inside a quoted string,
5
+ * a heredoc body (`<<EOT` / `<<-EOT`, e.g. execute-script JavaScript), a
6
+ * `${…}` / `%{…}` template hole, or a comment are not code.
7
+ */
8
+ const HEREDOC_OPENER = /^<<-?([A-Za-z_][A-Za-z0-9_-]*)\r?$/;
9
+ export function hclCodeLines(text) {
10
+ const stack = [];
11
+ let inBlockComment = false;
12
+ const out = [];
13
+ for (const line of text.split("\n")) {
14
+ const top = stack.at(-1);
15
+ if (top?.kind === "heredoc" && line.trim() === top.marker) {
16
+ stack.pop();
17
+ out.push({ text: line, code: "", startsInCode: false });
18
+ continue;
19
+ }
20
+ const startsInCode = stack.length === 0 && !inBlockComment;
21
+ let code = "";
22
+ let i = 0;
23
+ while (i < line.length) {
24
+ const frame = stack.at(-1);
25
+ const ch = line[i];
26
+ if (inBlockComment) {
27
+ const end = line.indexOf("*/", i);
28
+ if (end === -1)
29
+ break;
30
+ inBlockComment = false;
31
+ i = end + 2;
32
+ continue;
33
+ }
34
+ if (frame?.kind === "string" || frame?.kind === "heredoc") {
35
+ if (frame.kind === "string" && ch === "\\") {
36
+ i += 2;
37
+ continue;
38
+ }
39
+ if ((ch === "$" || ch === "%") && line[i + 1] === ch && line[i + 2] === "{") {
40
+ i += 3;
41
+ continue;
42
+ }
43
+ if ((ch === "$" || ch === "%") && line[i + 1] === "{") {
44
+ stack.push({ kind: "hole", depth: 0 });
45
+ i += 2;
46
+ continue;
47
+ }
48
+ if (frame.kind === "string" && ch === '"') {
49
+ stack.pop();
50
+ if (stack.length === 0)
51
+ code += '"';
52
+ }
53
+ i++;
54
+ continue;
55
+ }
56
+ if (ch === "#" || (ch === "/" && line[i + 1] === "/"))
57
+ break;
58
+ if (ch === "/" && line[i + 1] === "*") {
59
+ inBlockComment = true;
60
+ i += 2;
61
+ continue;
62
+ }
63
+ if (ch === '"') {
64
+ if (stack.length === 0)
65
+ code += '"';
66
+ stack.push({ kind: "string" });
67
+ i++;
68
+ continue;
69
+ }
70
+ if (ch === "<" && line[i + 1] === "<") {
71
+ const opener = HEREDOC_OPENER.exec(line.slice(i));
72
+ if (opener !== null) {
73
+ if (stack.length === 0)
74
+ code += '""';
75
+ stack.push({ kind: "heredoc", marker: opener[1] });
76
+ break;
77
+ }
78
+ }
79
+ if (frame?.kind === "hole") {
80
+ if (ch === "{")
81
+ frame.depth++;
82
+ if (ch === "}" && frame.depth-- === 0)
83
+ stack.pop();
84
+ }
85
+ else {
86
+ code += ch;
87
+ }
88
+ i++;
89
+ }
90
+ // A quoted string cannot span lines; closing it here keeps one malformed
91
+ // line from swallowing the rest of the file.
92
+ while (stack.at(-1)?.kind === "string") {
93
+ stack.pop();
94
+ if (stack.length === 0)
95
+ code += '"';
96
+ }
97
+ out.push({ text: line, code, startsInCode });
98
+ }
99
+ return out;
100
+ }
101
+ /** `{`/`}` and `[`/`]` depth change of a line's code. */
102
+ export function hclDepthDelta(line) {
103
+ let braces = 0;
104
+ let brackets = 0;
105
+ for (const ch of line.code) {
106
+ if (ch === "{")
107
+ braces++;
108
+ else if (ch === "}")
109
+ braces--;
110
+ else if (ch === "[")
111
+ brackets++;
112
+ else if (ch === "]")
113
+ brackets--;
114
+ }
115
+ return { braces, brackets };
116
+ }
117
+ /** Index of the last line of the statement starting at `start`: a value that opens a heredoc or block comment runs past its own line. */
118
+ export function hclStatementEnd(lines, start) {
119
+ let end = start;
120
+ while (end + 1 < lines.length && !lines[end + 1].startsInCode)
121
+ end++;
122
+ return end;
123
+ }
@@ -14,6 +14,8 @@ export interface ValidationFailure {
14
14
  * these to warnings; build/plan/apply keep them fatal.
15
15
  */
16
16
  readonly staleReference?: boolean;
17
+ /** What kind of finding this is, when a caller has to treat it specially. */
18
+ readonly code?: "unresolved-task-filter-ref";
17
19
  }
18
20
  export declare function formatValidationFailure(failure: ValidationFailure): string;
19
21
  export declare class ValidationFailureError extends Error {
@@ -33,6 +33,14 @@ export interface WorkspaceLoader {
33
33
  default?: unknown;
34
34
  }>;
35
35
  }
36
+ export declare function setWorkspaceLoadGuard(guard: ((orgRoot: string) => void) | undefined): void;
37
+ /**
38
+ * Run the workspace load guard on `orgRoot` now, without loading anything.
39
+ * A command that loads source calls this before its first write (edk#1737):
40
+ * a guard failure inside a best-effort load can be caught and only logged,
41
+ * and by then the command may already have written files.
42
+ */
43
+ export declare function assertWorkspaceLoadable(orgRoot: string): void;
36
44
  /**
37
45
  * A loader scoped to one org root and one generation. Create one per build —
38
46
  * that is what makes a rebuild see edited files.
@@ -352,12 +352,32 @@ function createJitiLoader(root) {
352
352
  },
353
353
  };
354
354
  }
355
+ /**
356
+ * A check run on an org root before any of its source is loaded (edk#1737).
357
+ * The CLI sets it to the installed-SDK compatibility check; it throws to stop
358
+ * the load. Set from outside because this module can only import `node:`
359
+ * builtins (see IMPORTING_FILE_KEY).
360
+ */
361
+ let workspaceLoadGuard;
362
+ export function setWorkspaceLoadGuard(guard) {
363
+ workspaceLoadGuard = guard;
364
+ }
365
+ /**
366
+ * Run the workspace load guard on `orgRoot` now, without loading anything.
367
+ * A command that loads source calls this before its first write (edk#1737):
368
+ * a guard failure inside a best-effort load can be caught and only logged,
369
+ * and by then the command may already have written files.
370
+ */
371
+ export function assertWorkspaceLoadable(orgRoot) {
372
+ workspaceLoadGuard?.(canonical(resolve(orgRoot)));
373
+ }
355
374
  /**
356
375
  * A loader scoped to one org root and one generation. Create one per build —
357
376
  * that is what makes a rebuild see edited files.
358
377
  */
359
378
  export function createWorkspaceLoader(orgRoot) {
360
379
  const root = canonical(resolve(orgRoot));
380
+ workspaceLoadGuard?.(root);
361
381
  if (registerHooks === undefined)
362
382
  return createJitiLoader(root);
363
383
  activeRoots.add(root);
@@ -47,8 +47,25 @@ export interface FilterFromTfOptions {
47
47
  }
48
48
  /** Decode one `filter` attribute through the shared exhaustive codec. */
49
49
  export declare function filterFromTf(value: TfValue, owner: AccessPolicyOwner, where: string, ctx?: FromTfContext, options?: FilterFromTfOptions): Filter<RefExpr, RefExpr>;
50
+ /**
51
+ * The EDK ref of the app that owns a service-account block, read from the
52
+ * block's `app_id`: the owner itself when that is the app the ref points at,
53
+ * otherwise a foreign app the workspace knows by name or namespace. Undefined
54
+ * when it doesn't resolve, so the caller drops the member.
55
+ */
56
+ export declare function serviceAccountAppRefName(appId: TfValue | undefined, owner: {
57
+ readonly scope: ChildResourceScope;
58
+ readonly label: string;
59
+ readonly ownerRefName: string;
60
+ } | undefined, ctx: FromTfContext): string | undefined;
50
61
  export declare function principalList(value: TfValue | undefined, dataType: "elementum_user", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyUserRef[] | undefined;
51
62
  export declare function principalList(value: TfValue | undefined, dataType: "elementum_group", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyGroupRef[] | undefined;
52
63
  export declare function principalList(value: TfValue | undefined, dataType: "elementum_service_account", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyServiceAccountRef[] | undefined;
64
+ /**
65
+ * Export file order is not label-suffix order. Build numbers policies by
66
+ * array index (`access_policy`, then `access_policy_1`), so pull must follow
67
+ * the suffix or a later build swaps the addresses (#2088).
68
+ */
69
+ export declare function accessPolicyBlocksInLabelOrder(blocks: readonly TfBlock[]): readonly TfBlock[];
53
70
  /** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
54
71
  export declare function accessPolicyFromTf(block: TfBlock, owner: AccessPolicyOwner, ctx: FromTfContext): NormalizedAccessPolicy | undefined;
@@ -16,6 +16,7 @@ import { appResourceLabelPrefix, elementResourceLabelPrefix, isTfExpr, scopedLab
16
16
  import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-codec.js";
17
17
  import { groupId, userId, } from "./principal.js";
18
18
  import { KNOWN_ACCESS_POLICY_ATTRS } from "./types.js";
19
+ import { finishPulledMemberList } from "./member-list.js";
19
20
  function fieldRef(value, owner, where) {
20
21
  if (isTfExpr(value) && value.$expr === "resource-attr" && value.type.endsWith("_field") && value.path[0] === "id") {
21
22
  // scopedLabelToBagKey's stripping is a documented no-op when the label
@@ -117,6 +118,24 @@ function stageName(value, owner, ctx) {
117
118
  // an ambiguous selection when two stage names are identical.
118
119
  return name !== undefined && entries.filter((stage) => stage.name === name).length === 1 ? name : undefined;
119
120
  }
121
+ /**
122
+ * The EDK ref of the app that owns a service-account block, read from the
123
+ * block's `app_id`: the owner itself when that is the app the ref points at,
124
+ * otherwise a foreign app the workspace knows by name or namespace. Undefined
125
+ * when it doesn't resolve, so the caller drops the member.
126
+ */
127
+ export function serviceAccountAppRefName(appId, owner, ctx) {
128
+ const appDataLabel = dataRefLabel(appId, "elementum_app");
129
+ const appResourceLabel = resourceRefLabel(appId, "elementum_app");
130
+ const appName = appDataLabel === undefined ? undefined : ctx.dataName("elementum_app", appDataLabel);
131
+ if (appName !== undefined)
132
+ return ctx.foreignAppRefNames?.get(appName);
133
+ if (appResourceLabel === undefined)
134
+ return undefined;
135
+ if (owner?.scope === "app" && owner.label === appResourceLabel)
136
+ return owner.ownerRefName;
137
+ return ctx.foreignAppRefNamespaces?.get(appResourceLabel);
138
+ }
120
139
  function principalListItem(item, dataType, where, ctx, owner) {
121
140
  const label = dataRefLabel(item, dataType);
122
141
  if (label !== undefined) {
@@ -126,17 +145,7 @@ function principalListItem(item, dataType, where, ctx, owner) {
126
145
  return undefined;
127
146
  }
128
147
  if (dataType === "elementum_service_account") {
129
- const appId = ctx.dataAttrs?.(dataType, label)?.["app_id"];
130
- const appDataLabel = dataRefLabel(appId, "elementum_app");
131
- const appResourceLabel = resourceRefLabel(appId, "elementum_app");
132
- const appName = appDataLabel === undefined ? undefined : ctx.dataName("elementum_app", appDataLabel);
133
- const appRefName = appName !== undefined
134
- ? ctx.foreignAppRefNames?.get(appName)
135
- : appResourceLabel !== undefined && owner?.scope === "app" && owner.label === appResourceLabel
136
- ? owner.ownerRefName
137
- : appResourceLabel === undefined
138
- ? undefined
139
- : ctx.foreignAppRefNamespaces?.get(appResourceLabel);
148
+ const appRefName = serviceAccountAppRefName(ctx.dataAttrs?.(dataType, label)?.["app_id"], owner, ctx);
140
149
  if (appRefName === undefined) {
141
150
  ctx.diagnostics.push(`${where}: data.${dataType}.${label} has no resolvable app_id owner; dropped`);
142
151
  return undefined;
@@ -164,17 +173,7 @@ function principalListItem(item, dataType, where, ctx, owner) {
164
173
  ctx.diagnostics.push(`${where}: elementum_service_account.${resourceLabel} has no recoverable display name; dropped`);
165
174
  return undefined;
166
175
  }
167
- const appId = account?.attrs["app_id"];
168
- const appDataLabel = dataRefLabel(appId, "elementum_app");
169
- const appResourceLabel = resourceRefLabel(appId, "elementum_app");
170
- const appName = appDataLabel === undefined ? undefined : ctx.dataName("elementum_app", appDataLabel);
171
- const appRefName = appName !== undefined
172
- ? ctx.foreignAppRefNames?.get(appName)
173
- : appResourceLabel !== undefined && owner?.scope === "app" && owner.label === appResourceLabel
174
- ? owner.ownerRefName
175
- : appResourceLabel === undefined
176
- ? undefined
177
- : ctx.foreignAppRefNamespaces?.get(appResourceLabel);
176
+ const appRefName = serviceAccountAppRefName(account?.attrs["app_id"], owner, ctx);
178
177
  if (appRefName === undefined) {
179
178
  ctx.diagnostics.push(`${where}: elementum_service_account.${resourceLabel} has no resolvable app_id owner; dropped`);
180
179
  return undefined;
@@ -201,16 +200,45 @@ export function principalList(value, dataType, where, ctx, owner) {
201
200
  return undefined;
202
201
  }
203
202
  const items = [];
203
+ let dropped = 0;
204
204
  for (const item of value) {
205
205
  const decoded = dataType === "elementum_user"
206
206
  ? principalListItem(item, "elementum_user", where, ctx)
207
207
  : dataType === "elementum_group"
208
208
  ? principalListItem(item, "elementum_group", where, ctx)
209
209
  : principalListItem(item, "elementum_service_account", where, ctx, owner);
210
- if (decoded !== undefined)
210
+ if (decoded === undefined)
211
+ dropped += 1;
212
+ else
211
213
  items.push(decoded);
212
214
  }
213
- return items.length > 0 ? items : undefined;
215
+ // A shorter service_account_ids list is the exact set and removes whoever
216
+ // pull could not name (#2160). Users and groups may stay as raw ids; a
217
+ // service account may not (#388). Drop the whole list so apply keeps the
218
+ // live members instead of deleting the unnamed one (#2259). Every member
219
+ // list follows that rule through finishPulledMemberList (edk#2200); the
220
+ // service-account diagnostic is kept so #2259's wording still appears.
221
+ if (dataType === "elementum_service_account" && dropped > 0 && items.length > 0) {
222
+ ctx.diagnostics.push(`${where}: a service account could not be named, so the list is omitted and apply keeps the live members`);
223
+ }
224
+ return finishPulledMemberList(where, items, dropped, ctx.diagnostics);
225
+ }
226
+ /**
227
+ * Export file order is not label-suffix order. Build numbers policies by
228
+ * array index (`access_policy`, then `access_policy_1`), so pull must follow
229
+ * the suffix or a later build swaps the addresses (#2088).
230
+ */
231
+ export function accessPolicyBlocksInLabelOrder(blocks) {
232
+ return [...blocks].sort((a, b) => {
233
+ const byIndex = accessPolicyLabelIndex(a.label ?? "") - accessPolicyLabelIndex(b.label ?? "");
234
+ return byIndex !== 0 ? byIndex : (a.label ?? "").localeCompare(b.label ?? "");
235
+ });
236
+ }
237
+ function accessPolicyLabelIndex(label) {
238
+ const match = /(?:^|_)access_policy(?:_(\d+))?$/.exec(label);
239
+ if (match === null)
240
+ return Number.MAX_SAFE_INTEGER;
241
+ return match[1] === undefined ? 0 : Number.parseInt(match[1], 10);
214
242
  }
215
243
  /** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
216
244
  export function accessPolicyFromTf(block, owner, ctx) {
@@ -0,0 +1,32 @@
1
+ /**
2
+ * How the provider applies a member list, which decides what the build error
3
+ * tells the user:
4
+ * - `exact`: access-policy, role and service-account lists. A set list
5
+ * replaces the platform's members, so a partial list removes the rest.
6
+ * - `viewShare`: a view's `user_ids` / `group_ids`. An update only adds
7
+ * members, and a new view with neither list set is shared with the aspect's
8
+ * access-policy principals instead.
9
+ */
10
+ export type MemberListKind = "exact" | "viewShare";
11
+ /** A dropped list entry as text for a drop message, cut short when it is long. */
12
+ export declare function describeDroppedEntry(value: unknown): string;
13
+ /**
14
+ * Finish a built member list (access-policy, view-sharing or role
15
+ * `user_ids` / `group_ids` / `service_account_ids`). Building only some of the
16
+ * authored members must not pass silently: on an exact list apply would
17
+ * remove the rest, and on a view the user would get a different share than
18
+ * they wrote (edk#2198):
19
+ * - nothing dropped: the built list, including an empty one;
20
+ * - every entry dropped: no list (each drop becomes a diagnostic), so apply
21
+ * leaves the platform's members as they are;
22
+ * - some entries dropped: the build fails and names them.
23
+ */
24
+ export declare function finishMemberList<T>(where: string, built: T[], dropped: readonly string[], diagnostics: string[], kind?: MemberListKind): T[] | undefined;
25
+ /**
26
+ * Finish a pulled member list. Source sets an exact list, so writing only the
27
+ * members pull could decode would make the next apply remove the rest
28
+ * (edk#2200). When any member was dropped (each one already diagnosed), the
29
+ * whole list is omitted: an omitted list leaves the platform's members as
30
+ * they are (#2160).
31
+ */
32
+ export declare function finishPulledMemberList<T>(where: string, decoded: T[], droppedCount: number, diagnostics: string[]): T[] | undefined;
@@ -0,0 +1,57 @@
1
+ import { EntityTfError } from "../../engine/entity.js";
2
+ /** A dropped list entry as text for a drop message, cut short when it is long. */
3
+ export function describeDroppedEntry(value) {
4
+ let text;
5
+ try {
6
+ text = JSON.stringify(value) ?? String(value);
7
+ }
8
+ catch {
9
+ text = String(value);
10
+ }
11
+ return text.length > 120 ? `${text.slice(0, 117)}...` : text;
12
+ }
13
+ /**
14
+ * Finish a built member list (access-policy, view-sharing or role
15
+ * `user_ids` / `group_ids` / `service_account_ids`). Building only some of the
16
+ * authored members must not pass silently: on an exact list apply would
17
+ * remove the rest, and on a view the user would get a different share than
18
+ * they wrote (edk#2198):
19
+ * - nothing dropped: the built list, including an empty one;
20
+ * - every entry dropped: no list (each drop becomes a diagnostic), so apply
21
+ * leaves the platform's members as they are;
22
+ * - some entries dropped: the build fails and names them.
23
+ */
24
+ export function finishMemberList(where, built, dropped, diagnostics, kind = "exact") {
25
+ if (dropped.length === 0)
26
+ return built;
27
+ if (built.length === 0) {
28
+ diagnostics.push(...dropped);
29
+ return undefined;
30
+ }
31
+ const total = built.length + dropped.length;
32
+ const them = dropped.length === 1 ? "that member" : "those members";
33
+ const fix = `Fix ${dropped.length === 1 ? "it" : "each one"} (for an org user or group, re-run \`elementum pull org --data-only\`)`;
34
+ const consequence = kind === "exact"
35
+ ? `This list is applied exactly, so building the rest would make apply remove ${them} from the platform. ` +
36
+ `${fix}, or remove the whole list to leave its members as they are.`
37
+ : `A view share list only adds members on update, so building the rest would quietly leave ${them} out of the share you wrote. ` +
38
+ `${fix}. Removing the list is not the same: a new view with neither userIds nor groupIds is shared with its app or element's access-policy members.`;
39
+ throw new EntityTfError(`${where}: ${dropped.length} of ${total} members could not be built, so the build stops instead of writing the other ${built.length}. ` +
40
+ `${consequence} Not built: ${dropped.map((d) => d.replace(`${where}: `, "").replace(/; dropped$/, "")).join(" | ")}`);
41
+ }
42
+ /**
43
+ * Finish a pulled member list. Source sets an exact list, so writing only the
44
+ * members pull could decode would make the next apply remove the rest
45
+ * (edk#2200). When any member was dropped (each one already diagnosed), the
46
+ * whole list is omitted: an omitted list leaves the platform's members as
47
+ * they are (#2160).
48
+ */
49
+ export function finishPulledMemberList(where, decoded, droppedCount, diagnostics) {
50
+ if (droppedCount === 0)
51
+ return decoded.length > 0 ? decoded : undefined;
52
+ if (decoded.length > 0) {
53
+ diagnostics.push(`${where}: ${droppedCount} of ${decoded.length + droppedCount} live members could not be decoded (listed above), so the whole list is omitted from source. ` +
54
+ `Apply leaves this list's live members as they are; EDK manages the list again once pull can decode every member`);
55
+ }
56
+ return undefined;
57
+ }
@@ -14,4 +14,9 @@ export const accessPolicyModule = {
14
14
  lifecycle: NO_LIFECYCLE,
15
15
  canvas: { participates: true, label: "Access Policies", glyph: "🔒", component: "generic" },
16
16
  catalog: NO_CATALOG,
17
+ // The platform creates one for the creator with every app, element and task,
18
+ // and it can't be told apart from the others, so a portable source has none.
19
+ portable: {
20
+ leaveOut: [{ resourceType: ACCESS_POLICY_RESOURCE_TYPE, reason: "access policies are left to the destination org" }],
21
+ },
17
22
  };
@@ -22,6 +22,7 @@ import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engin
22
22
  import type { Filter } from "../shared/filters/types.js";
23
23
  import type { AppServiceAccount } from "../service-account/build.js";
24
24
  import type { AccessPolicyGroupRef, AccessPolicyServiceAccountRef, AccessPolicyUserRef } from "./principal.js";
25
+ import { type MemberListKind } from "./member-list.js";
25
26
  export interface AccessPolicyToTfContext {
26
27
  readonly ownerTfLabel: string;
27
28
  /** App or element refName used to verify filter-field ownership. */
@@ -92,12 +93,12 @@ export interface AccessPolicyEntryWire {
92
93
  }
93
94
  export declare function principalListToTf(items: readonly AccessPolicyUserRef[] | undefined, dataType: "elementum_user", where: string, ctx: Omit<AccessPolicyToTfContext, "orgRefs"> & {
94
95
  readonly orgRefs?: OrgRefLookup;
95
- }): TfValue[] | undefined;
96
+ }, kind?: MemberListKind): TfValue[] | undefined;
96
97
  export declare function principalListToTf(items: readonly AccessPolicyGroupRef[] | undefined, dataType: "elementum_group", where: string, ctx: Omit<AccessPolicyToTfContext, "orgRefs"> & {
97
98
  readonly orgRefs?: OrgRefLookup;
98
- }): TfValue[] | undefined;
99
+ }, kind?: MemberListKind): TfValue[] | undefined;
99
100
  export declare function principalListToTf(items: readonly AccessPolicyServiceAccountRef[] | undefined, dataType: "elementum_service_account", where: string, ctx: Omit<AccessPolicyToTfContext, "orgRefs"> & {
100
101
  readonly orgRefs?: OrgRefLookup;
101
- }): TfValue[] | undefined;
102
+ }, kind?: MemberListKind): TfValue[] | undefined;
102
103
  /** One authored access-policy entry → its resource block, positioned by `index` (0-based) for label numbering. */
103
104
  export declare function accessPolicyToTf(entry: AccessPolicyEntryWire, index: number, ctx: AccessPolicyToTfContext): AccessPolicyToTfResult;