@elementumai/edk 0.10.4 → 0.12.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 (171) hide show
  1. package/README.md +49 -13
  2. package/dist-sdk/src/catalog/token.js +2 -1
  3. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  4. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  5. package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
  6. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  7. package/dist-sdk/src/engine/coverage-gaps.d.ts +7 -0
  8. package/dist-sdk/src/engine/coverage-gaps.js +12 -0
  9. package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
  10. package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
  11. package/dist-sdk/src/engine/ei/run.d.ts +42 -1
  12. package/dist-sdk/src/engine/ei/run.js +201 -32
  13. package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
  14. package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
  15. package/dist-sdk/src/engine/ei/state.d.ts +1 -1
  16. package/dist-sdk/src/engine/ei/state.js +17 -4
  17. package/dist-sdk/src/engine/progress.d.ts +3 -1
  18. package/dist-sdk/src/engine/progress.js +7 -3
  19. package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
  20. package/dist-sdk/src/engine/pull/authored-address.js +180 -29
  21. package/dist-sdk/src/engine/pull/context.d.ts +37 -2
  22. package/dist-sdk/src/engine/pull/context.js +7 -4
  23. package/dist-sdk/src/engine/pull/ref-only.d.ts +18 -0
  24. package/dist-sdk/src/engine/pull/ref-only.js +52 -0
  25. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  26. package/dist-sdk/src/engine/tf/index.js +2 -2
  27. package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
  28. package/dist-sdk/src/engine/tf/labels.js +50 -0
  29. package/dist-sdk/src/engine/tf/model.d.ts +2 -0
  30. package/dist-sdk/src/engine/tf/model.js +26 -0
  31. package/dist-sdk/src/engine/validation.d.ts +2 -0
  32. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +18 -0
  33. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -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 +10 -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.js +11 -5
  43. package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
  44. package/dist-sdk/src/entities/agent/tools.js +6 -2
  45. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  46. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
  47. package/dist-sdk/src/entities/agent-tool/to-tf.js +56 -3
  48. package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
  49. package/dist-sdk/src/entities/agent-tool/types.js +13 -9
  50. package/dist-sdk/src/entities/app/build.d.ts +12 -1
  51. package/dist-sdk/src/entities/app/build.js +80 -4
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +5 -7
  53. package/dist-sdk/src/entities/app/from-tf.js +17 -12
  54. package/dist-sdk/src/entities/app/stage-keys.d.ts +18 -3
  55. package/dist-sdk/src/entities/app/stage-keys.js +40 -6
  56. package/dist-sdk/src/entities/app/to-tf.js +7 -4
  57. package/dist-sdk/src/entities/automation/build.d.ts +52 -31
  58. package/dist-sdk/src/entities/automation/build.js +59 -20
  59. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
  60. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +39 -14
  61. package/dist-sdk/src/entities/automation/from-tf.d.ts +35 -2
  62. package/dist-sdk/src/entities/automation/from-tf.js +721 -93
  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 +244 -57
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +22 -2
  67. package/dist-sdk/src/entities/automation/output-key-wire-name.js +54 -3
  68. package/dist-sdk/src/entities/automation/run-target.d.ts +61 -0
  69. package/dist-sdk/src/entities/automation/run-target.js +104 -0
  70. package/dist-sdk/src/entities/automation/script-code.d.ts +11 -1
  71. package/dist-sdk/src/entities/automation/script-code.js +106 -4
  72. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  73. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  74. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -1
  75. package/dist-sdk/src/entities/automation/task-output-labels.js +58 -1
  76. package/dist-sdk/src/entities/automation/tasks.d.ts +67 -22
  77. package/dist-sdk/src/entities/automation/tasks.js +18 -4
  78. package/dist-sdk/src/entities/automation/to-tf.d.ts +1 -3
  79. package/dist-sdk/src/entities/automation/to-tf.js +354 -64
  80. package/dist-sdk/src/entities/automation/triggers.d.ts +63 -11
  81. package/dist-sdk/src/entities/automation/triggers.js +45 -5
  82. package/dist-sdk/src/entities/automation/types.d.ts +21 -0
  83. package/dist-sdk/src/entities/automation/types.js +26 -0
  84. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  85. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  86. package/dist-sdk/src/entities/chart/from-tf.js +25 -1
  87. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  88. package/dist-sdk/src/entities/chart/printer.js +5 -2
  89. package/dist-sdk/src/entities/chart/to-tf.js +19 -1
  90. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
  91. package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
  92. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  93. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +8 -2
  94. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  95. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  96. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  97. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +66 -20
  98. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  99. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
  100. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
  101. package/dist-sdk/src/entities/element/build.d.ts +10 -0
  102. package/dist-sdk/src/entities/element/build.js +1 -0
  103. package/dist-sdk/src/entities/element/from-tf.js +14 -9
  104. package/dist-sdk/src/entities/element/to-tf.js +7 -4
  105. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  106. package/dist-sdk/src/entities/field/from-tf.js +79 -1
  107. package/dist-sdk/src/entities/field/module.js +14 -1
  108. package/dist-sdk/src/entities/field/to-tf.d.ts +38 -3
  109. package/dist-sdk/src/entities/field/to-tf.js +108 -34
  110. package/dist-sdk/src/entities/file-reader/module.js +3 -3
  111. package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
  112. package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
  113. package/dist-sdk/src/entities/file-reader/types.js +7 -0
  114. package/dist-sdk/src/entities/org/group.d.ts +1 -0
  115. package/dist-sdk/src/entities/org/group.js +2 -1
  116. package/dist-sdk/src/entities/org/role.js +5 -0
  117. package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
  118. package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
  119. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
  120. package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
  121. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
  122. package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
  123. package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
  124. package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
  125. package/dist-sdk/src/entities/role/from-tf.js +24 -7
  126. package/dist-sdk/src/entities/role/to-tf.js +25 -7
  127. package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
  128. package/dist-sdk/src/entities/service-account/module.js +20 -0
  129. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  130. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  131. package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
  132. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  133. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
  135. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  136. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  137. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
  138. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
  139. package/dist-sdk/src/entities/skill/from-tf.js +10 -3
  140. package/dist-sdk/src/entities/skill/module.js +18 -0
  141. package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/skill/to-tf.js +23 -14
  143. package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
  144. package/dist-sdk/src/entities/skill/tools.js +6 -2
  145. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
  148. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  149. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +8 -2
  150. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +20 -10
  151. package/dist-sdk/src/entities/view/from-tf.d.ts +68 -4
  152. package/dist-sdk/src/entities/view/from-tf.js +394 -22
  153. package/dist-sdk/src/entities/view/module.js +20 -0
  154. package/dist-sdk/src/entities/view/portable.d.ts +11 -0
  155. package/dist-sdk/src/entities/view/portable.js +47 -0
  156. package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
  157. package/dist-sdk/src/entities/view/to-tf.js +25 -7
  158. package/dist-sdk/src/entities/view/types.js +1 -1
  159. package/dist-sdk/src/entities/widget/build.d.ts +4 -3
  160. package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
  161. package/dist-sdk/src/entities/widget/from-tf.js +100 -3
  162. package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
  163. package/dist-sdk/src/entities/widget/to-tf.js +77 -14
  164. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +30 -9
  165. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  166. package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
  167. package/dist-sdk/src/graph/field-resource-types.js +11 -0
  168. package/dist-sdk/src/graph/index.d.ts +41 -3
  169. package/dist-sdk/src/graph/index.js +24 -2
  170. package/dist-sdk/src/graph/types.d.ts +195 -5
  171. package/package.json +1 -1
@@ -2,13 +2,21 @@ import { type FromTfContext } from "../../engine/pull/context.js";
2
2
  import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
3
  import { type AccessPolicyOwner } from "../access-policy/from-tf.js";
4
4
  import type { NormalizedRelationship } from "../app/deserializer/normalize.js";
5
+ import { type UnextractedFieldOwner } from "../view/from-tf.js";
5
6
  export interface RelationshipOwner {
6
7
  /** Public EDK vocabulary; provider resource names stay at the TF boundary. */
7
8
  readonly kind: "app" | "element";
8
9
  readonly label: string;
9
10
  readonly ownerRefName: string;
11
+ /**
12
+ * The owner's TF label (`preston_high`), which its child resource labels
13
+ * carry. Never the camelCase ref: the two differ once the label has an
14
+ * underscore (#2046).
15
+ */
10
16
  readonly ownerTfLabel: string;
11
17
  readonly scope: ChildResourceScope;
18
+ /** The owner's extracted fields, so a field pull did not extract keeps its platform id (#1966). */
19
+ readonly unextracted?: UnextractedFieldOwner;
12
20
  }
13
21
  export declare function relationshipsFromTf(blocks: readonly TfBlock[], owner: RelationshipOwner, ctx: FromTfContext): NormalizedRelationship[];
14
22
  /**
@@ -1,9 +1,10 @@
1
- import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
2
- import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
1
+ import { dataRefLabel, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
2
+ import { expr, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { filterFromTf } from "../access-policy/from-tf.js";
4
4
  import { decodeForeignDataField, fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { resolveDataAspectTarget, resolveDataTaskTarget } from "../shared/aspect-target-from-tf.js";
6
6
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
7
+ import { bareForeignFieldIdRef, isBarePlatformId, resolveOwnDataFieldRef, unextractedFieldRefId } from "../view/from-tf.js";
7
8
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
8
9
  const KNOWN_ATTRS = new Set(["object_id", "related_object_id", "columns", "filter"]);
9
10
  export function relationshipsFromTf(blocks, owner, ctx) {
@@ -43,14 +44,49 @@ function relationshipFromTf(block, owner, ctx) {
43
44
  continue;
44
45
  }
45
46
  const rec = raw;
46
- const field = fieldKeyFromTfValue(rec["field_id"], owner.ownerRefName, owner.ownerTfLabel, owner.scope, ctx);
47
- const relatedField = relatedFieldRef(rec["related_field_id"], target, ctx);
47
+ // Field resource labels carry the owner's TF label, not its camelCase name (#1978).
48
+ const fieldKey = fieldKeyFromTfValue(rec["field_id"], owner.ownerRefName, owner.label, owner.scope, ctx);
49
+ // A field pull did not extract keeps its platform id: its key would print
50
+ // as nothing and build would drop the column (#1966). With no id the pull
51
+ // fails (#1978).
52
+ const field = owner.unextracted === undefined
53
+ ? fieldKey
54
+ : unextractedFieldRefId(rec["field_id"], fieldKey, owner.unextracted, ctx, `${where}.columns[${index}]`);
55
+ // A bare related id ei couldn't name resolves the same way as the owner
56
+ // side, so the join column is never dropped silently (#1991).
57
+ const relatedRaw = rec["related_field_id"];
58
+ const relatedSite = `${where}.columns[${index}].related_field_id`;
59
+ // On a relationship to its own app or element, the related side is the
60
+ // owner's field too, so an own data source resolves and fails closed the
61
+ // way the owner side does (#1991).
62
+ const ownRelated = owner.unextracted !== undefined && target.kind === owner.kind && target.key === owner.ownerRefName
63
+ ? resolveOwnDataFieldRef(relatedRaw, owner.unextracted, ctx, relatedSite)
64
+ : undefined;
65
+ const decodedRelated = ownRelated === "failedClosed" ? undefined : relatedFieldRef(relatedRaw, target, ctx);
66
+ const relatedField = (ownRelated !== undefined && ownRelated !== "failedClosed" && decodedRelated?.kind === "field" && decodedRelated.key !== ownRelated.key
67
+ ? { ...decodedRelated, key: ownRelated.key, name: ownDataName(relatedRaw, ctx) ?? ownRelated.key }
68
+ : decodedRelated)
69
+ ?? (ownRelated === undefined && typeof relatedRaw === "string" && isBarePlatformId(relatedRaw)
70
+ ? bareRelatedFieldRef(relatedRaw, target, owner, ctx, relatedSite)
71
+ : undefined);
48
72
  if (field === undefined || relatedField === undefined) {
49
73
  ctx.diagnostics.push(`${where}.columns[${index}]: field references are not resolvable; dropped`);
50
74
  continue;
51
75
  }
52
76
  columns.push({ field, relatedField });
53
77
  }
78
+ // A relationship whose columns were all dropped would print as
79
+ // `columns: []`, which reads like an exported empty list (that one stays
80
+ // as is), so it fails instead (#1991).
81
+ if (columnsRaw.length > 0 && columns.length === 0) {
82
+ reportAuthoringBlocker(ctx, {
83
+ address: where,
84
+ description: `${where}: none of its ${columnsRaw.length} join column(s) could be resolved, so it would be written with no columns`,
85
+ remedy: ctx.cloning !== undefined
86
+ ? "Check that each join column's fields still exist on both sides of the source app's relationship and run the clone again; if the export keeps naming them by an id it doesn't import, report it to the EDK maintainers."
87
+ : "Check that each join column's fields still exist on both sides and pull again; if the export keeps naming them by an id it doesn't import, report it to the EDK maintainers.",
88
+ });
89
+ }
54
90
  const key = scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", owner.scope);
55
91
  let filter;
56
92
  if (block.attrs["filter"] !== undefined) {
@@ -83,13 +119,19 @@ function relationshipFromTf(block, owner, ctx) {
83
119
  filter = filterFromTf(block.attrs["filter"], targetFilterOwner, `${where}.filter`, ctx);
84
120
  }
85
121
  catch (targetErr) {
86
- // Never let one unreconstructable filter reference crash the whole
87
- // app pull - diagnose and drop the relationship, same as the other
88
- // unresolvable cases in this function (e.g. `related_object_id is
89
- // not resolvable`), rather than risk silently rebuilding it with no
90
- // filter at all.
122
+ // Neither side decodes the filter. Writing the relationship with no
123
+ // filter would widen it on the next apply, and leaving it out of
124
+ // source drops a live, adopted relationship without a skipped gap,
125
+ // so pull fails closed naming the site (#2046).
91
126
  const err = targetErr ?? ownerErr;
92
- ctx.diagnostics.push(`${where}.filter: ${err instanceof Error ? err.message : String(err)}; skipped`);
127
+ const message = err instanceof Error ? err.message : String(err);
128
+ reportAuthoringBlocker(ctx, {
129
+ address: where,
130
+ description: `${message.startsWith(where) ? message : `${where}.filter: ${message}`}, so the relationship can't be written to source with its filter`,
131
+ remedy: ctx.cloning !== undefined
132
+ ? "Check that each field the source relationship's filter names still exists on its app or element or on the related one, and run the clone again; if the export keeps naming a field pull can't decode, report it to the EDK maintainers."
133
+ : "Check that each field the relationship's filter names still exists on its app or element or on the related one, and pull again; if the export keeps naming a field pull can't decode, report it to the EDK maintainers.",
134
+ });
93
135
  return undefined;
94
136
  }
95
137
  }
@@ -177,6 +219,42 @@ function targetDataFilterField(label, target, ctx) {
177
219
  },
178
220
  };
179
221
  }
222
+ /**
223
+ * A related field the export names by a bare platform id (#1991). An id the
224
+ * export imports as one of the target's fields becomes its key. Otherwise the
225
+ * field is the target's, so it keeps its id when the target is another owner
226
+ * (Dax, 11:45); an imported field of no known target goes through its field
227
+ * block (#1990), and anything else fails naming `site` and the id.
228
+ */
229
+ function bareRelatedFieldRef(v, target, owner, ctx, site) {
230
+ const ownTarget = target.kind === owner.kind && target.key === owner.ownerRefName;
231
+ const imported = ctx.importedResource?.(v);
232
+ const subType = imported === undefined ? undefined : SUB_TYPE_BY_RESOURCE.get(imported.type);
233
+ // Only a field whose block names the target as its owner is the target's.
234
+ const targetLabel = ownTarget ? owner.label : target.managed === true ? target.tfLabel : undefined;
235
+ if (imported !== undefined && subType !== undefined && targetLabel !== undefined && resourceRefLabel(imported.attrs["object_id"], targetResourceType(target)) === targetLabel) {
236
+ const scope = target.kind === "element" ? "element" : "app";
237
+ const key = fieldKeyFromTfRef(expr.resourceAttr(imported.type, imported.label, ["id"]), targetLabel, scope);
238
+ if (key !== undefined) {
239
+ return { kind: target.kind === "table" ? "tableColumn" : "field", key, name: key, parent: target.key, fieldType: subType.authoringType };
240
+ }
241
+ }
242
+ const unextracted = owner.unextracted ?? {
243
+ type: owner.kind === "app" ? "elementum_app" : "elementum_element",
244
+ label: owner.label,
245
+ ownerTfLabel: owner.ownerTfLabel,
246
+ scope: owner.kind,
247
+ };
248
+ return bareForeignFieldIdRef(v, unextracted, ctx, site, ownTarget ? undefined : `the relationship's target ${target.kind} ${JSON.stringify(target.name || target.key)}`);
249
+ }
250
+ /** A `data.elementum_field` lookup's own `name`, when it has one. */
251
+ function ownDataName(value, ctx) {
252
+ const label = dataRefLabel(value, "elementum_field");
253
+ return label === undefined ? undefined : ctx.dataName("elementum_field", label);
254
+ }
255
+ function targetResourceType(target) {
256
+ return target.kind === "element" ? "elementum_element" : target.kind === "table" ? "elementum_table" : target.kind === "task" ? "elementum_task" : "elementum_app";
257
+ }
180
258
  function relatedFieldRef(value, target, ctx) {
181
259
  if (value === undefined)
182
260
  return undefined;
@@ -3,6 +3,7 @@ import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engin
3
3
  import { type FilterToTfContext } from "../access-policy/to-tf.js";
4
4
  import type { Filter } from "../shared/filters/types.js";
5
5
  import { type FieldOwnership } from "../field/to-tf.js";
6
+ import { type UnsafePlatformId } from "../../core/platform-id.js";
6
7
  interface RefWire {
7
8
  readonly __kind?: string;
8
9
  readonly refName?: string;
@@ -16,8 +17,8 @@ interface RefWire {
16
17
  export interface RelationshipWire {
17
18
  readonly target?: RefWire;
18
19
  readonly columns?: readonly {
19
- readonly field?: string | RefWire;
20
- readonly relatedField?: RefWire;
20
+ readonly field?: string | RefWire | UnsafePlatformId;
21
+ readonly relatedField?: RefWire | UnsafePlatformId;
21
22
  }[];
22
23
  readonly filter?: Filter;
23
24
  }
@@ -2,11 +2,12 @@ import { workspaceAspectKey, } from "../../engine/build/context.js";
2
2
  import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
3
  import { filterToTf } from "../access-policy/to-tf.js";
4
4
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
5
- import { authoredFieldKeysFromPayload, fieldRefToTfValue, } from "../field/to-tf.js";
5
+ import { authoredFieldKeysFromPayload, droppedEntryGap, fieldLookupName, fieldRefToTfValue, skippedResourceGap, unauthoredSiblingFieldRef, UNRESOLVED_FIELD_REF, } from "../field/to-tf.js";
6
6
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
7
7
  import { autoRelationColumnError } from "./column-contract.js";
8
8
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
9
9
  import { EntityTfError } from "../../engine/entity.js";
10
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
10
11
  export function relationshipsToTf(relationships, opts) {
11
12
  const blocks = [];
12
13
  for (const [key, relationship] of Object.entries(relationships ?? {})) {
@@ -25,22 +26,52 @@ export function relationshipsToTf(relationships, opts) {
25
26
  `Model the link with a reference field on "${opts.ownerRefName}" instead, or relate through a child element.`);
26
27
  }
27
28
  const columns = [];
28
- let droppedInvalidJoin = false;
29
+ // A relationship whose every column was dropped for an invalid join is
30
+ // left out rather than built with no join at all. When a field build
31
+ // can't resolve dropped one, build fails instead (Dax, #1978): leaving
32
+ // out an adopted relationship would make plan destroy it.
33
+ let droppedColumn = false;
34
+ const unresolvedColumns = [];
29
35
  for (const [index, column] of (relationship.columns ?? []).entries()) {
30
36
  const columnWhere = `${where}.columns[${index}]`;
31
- const contractError = autoRelationColumnError(column.field, column.relatedField);
37
+ const contractError = isUnsafePlatformId(column.field) || isUnsafePlatformId(column.relatedField)
38
+ ? undefined
39
+ : autoRelationColumnError(column.field, column.relatedField);
32
40
  if (contractError !== undefined) {
33
41
  opts.diagnostics.push(`${columnWhere}: ${contractError}; dropped`);
34
- droppedInvalidJoin = true;
42
+ droppedColumn = true;
35
43
  continue;
36
44
  }
37
45
  const field = resolveOwnerField(column.field, `${columnWhere}.field`, opts);
38
- const relatedField = resolveRelatedField(column.relatedField, target, `${columnWhere}.relatedField`, opts);
46
+ // Another app's or element's field that its source doesn't have has no
47
+ // resource to reference (#1966): look it up on the platform by name, as
48
+ // the export did. A ref with no name can't be resolved, so it drops.
49
+ const unauthored = unauthoredRelatedField(column.relatedField, target, opts);
50
+ if (unauthored !== undefined && unauthored.name === undefined) {
51
+ opts.diagnostics.push(droppedEntryGap(`${columnWhere}.relatedField`, `${unauthored.reason}; column dropped`, "relationship"));
52
+ }
53
+ const relatedField = unauthored === undefined
54
+ ? resolveRelatedField(column.relatedField, target, `${columnWhere}.relatedField`, opts)
55
+ : unauthored.name === undefined
56
+ ? undefined
57
+ : relatedFieldLookup(target, unauthored.name, opts);
39
58
  if (field !== undefined && relatedField !== undefined)
40
59
  columns.push({ field_id: field, related_field_id: relatedField });
60
+ else {
61
+ droppedColumn = true;
62
+ unresolvedColumns.push(field === undefined
63
+ ? `${columnWhere}.field: ${describeFieldRef(column.field)}`
64
+ : `${columnWhere}.relatedField: ${unauthored?.reason ?? describeFieldRef(column.relatedField)}`);
65
+ }
41
66
  }
42
- if (columns.length === 0 && droppedInvalidJoin) {
43
- opts.diagnostics.push(`${where}: no valid join columns remain; dropped`);
67
+ if (columns.length === 0 && unresolvedColumns.length > 0) {
68
+ throw new EntityTfError(`${opts.ownerType === "elementum_app" ? "app" : "element"} "${opts.ownerRefName}" ${where}: no join column is left, because build ` +
69
+ `can't resolve these field references:\n${unresolvedColumns.map((column) => ` - ${column}`).join("\n")}\n` +
70
+ "Build refuses to leave the relationship out: if it is already managed, plan would destroy it. " +
71
+ "Point each column at a field in source (or its unsafePlatformId), or remove the relationship (#1978).");
72
+ }
73
+ if (columns.length === 0 && droppedColumn) {
74
+ opts.diagnostics.push(skippedResourceGap(where, "no valid join columns remain; relationship left out of build", "relationship"));
44
75
  continue;
45
76
  }
46
77
  const attrs = {
@@ -74,7 +105,20 @@ export function relationshipsToTf(relationships, opts) {
74
105
  }
75
106
  return blocks;
76
107
  }
108
+ /** How an unresolved column field reference reads in a build error (#1978). */
109
+ function describeFieldRef(value) {
110
+ if (value == null)
111
+ return UNRESOLVED_FIELD_REF;
112
+ return `field reference ${JSON.stringify(value)} does not resolve`;
113
+ }
77
114
  function resolveOwnerField(value, where, opts) {
115
+ // A field pull did not extract stays as its platform id (#1736, #1966).
116
+ if (isUnsafePlatformId(value))
117
+ return value.value;
118
+ if (value == null) {
119
+ opts.diagnostics.push(droppedEntryGap(where, `${UNRESOLVED_FIELD_REF}; column dropped`, "relationship"));
120
+ return undefined;
121
+ }
78
122
  if (typeof value === "string") {
79
123
  if (opts.scope === "element" && value !== "id" && value !== "title") {
80
124
  opts.diagnostics.push(`${where}: element relationships only support system fields "id" and "title"; dropped`);
@@ -161,7 +205,31 @@ export function targetFilterFieldResolver(targetToken, where, opts) {
161
205
  ? resolveRelatedField({ __kind: "field", ...token }, target, fieldWhere, opts)
162
206
  : undefined;
163
207
  }
208
+ /**
209
+ * A join column's related field that another app or element of this
210
+ * workspace doesn't have in source (#1966): why its resource can't be built,
211
+ * and the name to look it up by instead, if the ref has one. Undefined for the
212
+ * relationship's own owner, an unmanaged target, a kept platform id, or any
213
+ * other reference `resolveRelatedField` handles.
214
+ */
215
+ function unauthoredRelatedField(value, target, opts) {
216
+ if (value === undefined || isUnsafePlatformId(value) || value.__kind === "recordIdentity")
217
+ return undefined;
218
+ if (!target.managed || (target.kind !== "app" && target.kind !== "element"))
219
+ return undefined;
220
+ if (target.kind === opts.scope && target.refName === opts.ownerRefName)
221
+ return undefined;
222
+ const refName = value.refName ?? "";
223
+ if (refName === "" || (value.parent !== undefined && value.parent !== target.refName))
224
+ return undefined;
225
+ const reason = unauthoredSiblingFieldRef(refName, { kind: target.kind, refName: target.refName, fieldOwnership: target.fieldOwnership });
226
+ return reason === undefined ? undefined : { reason, name: fieldLookupName(value) };
227
+ }
164
228
  function resolveRelatedField(value, target, where, opts) {
229
+ // A related field pull kept by its platform id: another owner's field ei
230
+ // couldn't name (#1991).
231
+ if (isUnsafePlatformId(value))
232
+ return value.value;
165
233
  if (value?.__kind === "recordIdentity") {
166
234
  if (value.target === undefined) {
167
235
  opts.diagnostics.push(`${where}: record identity has no target; dropped`);
@@ -199,7 +267,10 @@ function resolveRelatedField(value, target, where, opts) {
199
267
  if (direct !== undefined)
200
268
  return direct;
201
269
  }
202
- const name = value?.name ?? refName;
270
+ return relatedFieldLookup(target, value?.name ?? refName, opts);
271
+ }
272
+ /** The target's field looked up on the platform by name: a `data.elementum_field`. */
273
+ function relatedFieldLookup(target, name, opts) {
203
274
  const label = foreignFieldDataLabel(target.kind, target.tfLabel ?? target.refName, name);
204
275
  opts.orgRefs.foreignField("elementum_field", label, target.value, name);
205
276
  return expr.dataAttr("elementum_field", label, ["id"]);
@@ -1,6 +1,8 @@
1
1
  import { dataRefLabel, groupCatalogKey, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { scopedLabelToBagKey } from "../../engine/tf/index.js";
3
3
  import { ROLE_RESOURCE_TYPE } from "../org/role.js";
4
+ import { finishPulledMemberList } from "../access-policy/member-list.js";
5
+ import { serviceAccountAppRefName } from "../access-policy/from-tf.js";
4
6
  const KNOWN = new Set(["id", "object_id", "name", "description", "auto_share", "user_ids", "group_ids", "service_account_ids", "permissions", "managed", "tags"]);
5
7
  function strings(value, where, ctx) {
6
8
  if (value === undefined)
@@ -30,6 +32,8 @@ function principal(value, type, where, ctx) {
30
32
  }
31
33
  if (typeof value === "string")
32
34
  ctx.diagnostics.push(`${where}: raw platform ids are not part of the public EDK API; dropped`);
35
+ else
36
+ ctx.diagnostics.push(`${where}: unrecognized principal (${JSON.stringify(value)?.slice(0, 120)}); dropped`);
33
37
  return undefined;
34
38
  }
35
39
  function principalList(value, type, where, ctx) {
@@ -42,7 +46,7 @@ function principalList(value, type, where, ctx) {
42
46
  const out = value.flatMap((item) => (type === "elementum_user"
43
47
  ? principal(item, "elementum_user", where, ctx)
44
48
  : principal(item, "elementum_group", where, ctx)) ?? []);
45
- return out.length > 0 ? out : undefined;
49
+ return finishPulledMemberList(where, out, value.length - out.length, ctx.diagnostics);
46
50
  }
47
51
  function permissions(value, where, ctx) {
48
52
  if (value === undefined)
@@ -101,23 +105,33 @@ export function rolesFromTf(blocks, owner, ctx) {
101
105
  for (const value of serviceAccountsValue) {
102
106
  const resourceLabel = resourceRefLabel(value, "elementum_service_account");
103
107
  if (resourceLabel !== undefined) {
104
- const account = blocks.find((candidate) => candidate.type === "elementum_service_account" && candidate.label === resourceLabel);
108
+ // A real pull passes only role blocks here, so read the account from
109
+ // the stream; `blocks` serves a caller that passed it in directly.
110
+ const account = ctx.resourceByAddress?.(`elementum_service_account.${resourceLabel}`)
111
+ ?? blocks.find((candidate) => candidate.type === "elementum_service_account" && candidate.label === resourceLabel);
105
112
  const explicitName = account?.attrs["name"];
106
113
  const firstName = account?.attrs["first_name"];
107
114
  const lastName = account?.attrs["last_name"];
108
115
  const name = typeof explicitName === "string"
109
116
  ? explicitName
110
117
  : typeof firstName === "string" && typeof lastName === "string" ? `${firstName} ${lastName}` : undefined;
111
- if (name !== undefined)
112
- serviceAccounts.push({ __kind: "serviceAccount", appRefName: owner.ownerRefName, name });
113
- else
118
+ const appRefName = serviceAccountAppRefName(account?.attrs["app_id"], owner, ctx);
119
+ if (name === undefined)
114
120
  ctx.diagnostics.push(`${where}.service_account_ids: ${resourceLabel} has no recoverable display name; dropped`);
121
+ else if (appRefName === undefined)
122
+ ctx.diagnostics.push(`${where}.service_account_ids: ${resourceLabel} has no resolvable app_id owner; dropped`);
123
+ else
124
+ serviceAccounts.push({ __kind: "serviceAccount", appRefName, name });
115
125
  continue;
116
126
  }
117
127
  const dataLabel = dataRefLabel(value, "elementum_service_account");
118
128
  const name = dataLabel === undefined ? undefined : ctx.dataName("elementum_service_account", dataLabel);
119
129
  if (name !== undefined) {
120
- serviceAccounts.push({ __kind: "serviceAccount", appRefName: owner.ownerRefName, name });
130
+ const appRefName = serviceAccountAppRefName(ctx.dataAttrs?.("elementum_service_account", dataLabel)?.["app_id"], owner, ctx);
131
+ if (appRefName === undefined)
132
+ ctx.diagnostics.push(`${where}.service_account_ids: data.elementum_service_account.${dataLabel} has no resolvable app_id owner; dropped`);
133
+ else
134
+ serviceAccounts.push({ __kind: "serviceAccount", appRefName, name });
121
135
  continue;
122
136
  }
123
137
  if (typeof value === "string")
@@ -127,6 +141,9 @@ export function rolesFromTf(blocks, owner, ctx) {
127
141
  }
128
142
  }
129
143
  }
144
+ if (serviceAccounts !== undefined && Array.isArray(serviceAccountsValue)) {
145
+ serviceAccounts = finishPulledMemberList(`${where}.service_account_ids`, serviceAccounts, serviceAccountsValue.length - serviceAccounts.length, ctx.diagnostics);
146
+ }
130
147
  const users = principalList(block.attrs["user_ids"], "elementum_user", `${where}.user_ids`, ctx);
131
148
  const groups = principalList(block.attrs["group_ids"], "elementum_group", `${where}.group_ids`, ctx);
132
149
  const rolePermissions = permissions(block.attrs["permissions"], `${where}.permissions`, ctx);
@@ -137,7 +154,7 @@ export function rolesFromTf(blocks, owner, ctx) {
137
154
  ...(autoShare !== undefined && { autoShare }),
138
155
  ...(users !== undefined && { users }),
139
156
  ...(groups !== undefined && { groups }),
140
- ...(serviceAccounts !== undefined && serviceAccounts.length > 0 && { serviceAccounts }),
157
+ ...(serviceAccounts !== undefined && { serviceAccounts }),
141
158
  ...(rolePermissions !== undefined && { permissions: rolePermissions }),
142
159
  }];
143
160
  });
@@ -2,10 +2,16 @@ import { expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../..
2
2
  import { ROLE_RESOURCE_TYPE } from "../org/role.js";
3
3
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
4
4
  import { serviceAccountRefToTf } from "../service-account/to-tf.js";
5
+ import { describeDroppedEntry, finishMemberList } from "../access-policy/member-list.js";
5
6
  function principals(values, type, where, orgRefs, diagnostics) {
6
- if (values === undefined || values.length === 0)
7
+ if (values === undefined)
7
8
  return undefined;
9
+ // `users: []` / `groups: []` removes every member, so it must reach the
10
+ // provider as `[]`: an omitted list changes nothing (#2158).
11
+ if (values.length === 0)
12
+ return [];
8
13
  const out = [];
14
+ const dropped = [];
9
15
  for (const value of values) {
10
16
  const user = value;
11
17
  if (type === "elementum_user" && user?.__kind === "user" && user.email) {
@@ -18,14 +24,17 @@ function principals(values, type, where, orgRefs, diagnostics) {
18
24
  if (type === "elementum_group" && token?.__kind === "group") {
19
25
  const resolved = orgRefs.byTsLabel("groups", token.refName ?? "");
20
26
  if (resolved === undefined)
21
- diagnostics.push(`${where}: group token ${JSON.stringify(token.refName ?? "")} is not in org.ts; dropped`);
27
+ dropped.push(`${where}: group token ${JSON.stringify(token.refName ?? "")} is not in org.ts; dropped`);
22
28
  else
23
29
  out.push(expr.dataAttr(type, resolved.tfLabel, ["id"]));
24
30
  continue;
25
31
  }
26
- diagnostics.push(`${where}: unrecognized typed principal; dropped`);
32
+ dropped.push(`${where}: unrecognized typed principal (${describeDroppedEntry(value)}); dropped`);
27
33
  }
28
- return out.length > 0 ? out : undefined;
34
+ // Every entry dropped: the list is left out so apply changes nothing,
35
+ // rather than emit [] and remove every member. Some dropped: the build
36
+ // fails (edk#2198).
37
+ return finishMemberList(where, out, dropped, diagnostics);
29
38
  }
30
39
  export function rolesToTf(roles, opts) {
31
40
  return Object.entries(roles ?? {}).map(([key, role]) => {
@@ -41,16 +50,18 @@ export function rolesToTf(roles, opts) {
41
50
  if (groups !== undefined)
42
51
  attrs["group_ids"] = groups;
43
52
  if (role.serviceAccounts !== undefined) {
44
- attrs["service_account_ids"] = role.serviceAccounts.flatMap((account) => {
53
+ const where = `roles.${key}.serviceAccounts`;
54
+ const dropped = [];
55
+ const built = role.serviceAccounts.flatMap((account) => {
45
56
  if (opts.scope !== "app" || account.appRefName !== opts.ownerRefName) {
46
57
  // Another app's account (or any account on an element role, which
47
58
  // owns none): resolve it under its OWNING app (#1592).
48
59
  const owning = opts.resolveServiceAccountApp?.(account.appRefName);
49
60
  if (owning === undefined) {
50
- opts.diagnostics.push(`roles.${key}.serviceAccounts: ${JSON.stringify(account.name)} belongs to app ${JSON.stringify(account.appRefName)}, which is not in this workspace; dropped`);
61
+ dropped.push(`${where}: ${JSON.stringify(account.name)} belongs to app ${JSON.stringify(account.appRefName)}, which is not in this workspace; dropped`);
51
62
  return [];
52
63
  }
53
- const value = serviceAccountRefToTf({ __kind: "serviceAccount", appRefName: account.appRefName, name: account.name }, { appRefName: account.appRefName, ...owning, orgRefs: opts.orgRefs }, `roles.${key}.serviceAccounts`, opts.diagnostics);
64
+ const value = serviceAccountRefToTf({ __kind: "serviceAccount", appRefName: account.appRefName, name: account.name }, { appRefName: account.appRefName, ...owning, orgRefs: opts.orgRefs }, where, dropped);
54
65
  return value === undefined ? [] : [value];
55
66
  }
56
67
  const local = Object.entries(opts.serviceAccounts ?? {}).find(([, candidate]) => `${candidate.firstName} ${candidate.lastName}`.trim() === account.name);
@@ -60,6 +71,13 @@ export function rolesToTf(roles, opts) {
60
71
  opts.orgRefs.rawLookup(SERVICE_ACCOUNT_RESOURCE_TYPE, label, account.name, { app_id: opts.objectId });
61
72
  return [expr.dataAttr(SERVICE_ACCOUNT_RESOURCE_TYPE, label, ["id"])];
62
73
  });
74
+ // `serviceAccounts: []` removes every member and must reach the
75
+ // provider as `[]` (#2158). Otherwise a list whose every entry was
76
+ // dropped is left out (it used to build as [] and remove every member),
77
+ // and a partly dropped list fails the build (edk#2198).
78
+ const serviceAccountIds = role.serviceAccounts.length === 0 ? [] : finishMemberList(where, built, dropped, opts.diagnostics);
79
+ if (serviceAccountIds !== undefined)
80
+ attrs["service_account_ids"] = serviceAccountIds;
63
81
  }
64
82
  if (role.permissions !== undefined)
65
83
  attrs["permissions"] = [...role.permissions].sort((a, b) => a.group.localeCompare(b.group)).map((permission) => ({
@@ -4,6 +4,7 @@ import { scopedLabelToBagKey } from "../../engine/tf/index.js";
4
4
  import { serviceAccountRoleRef, serviceAccountStatus, } from "./build.js";
5
5
  import { SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE, SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
6
6
  import { serviceAccountRoleIdMismatches } from "./role-fidelity.js";
7
+ import { finishPulledMemberList } from "../access-policy/member-list.js";
7
8
  const ACCOUNT_ATTRS = new Set(["id", "app_id", "first_name", "last_name", "purpose", "name", "status", "role_ids"]);
8
9
  const POLICY_ATTRS = new Set(["id", "app_id", "service_account_id", "user_ids", "group_ids"]);
9
10
  function principal(value, type, where, ctx) {
@@ -39,7 +40,7 @@ function principalList(value, type, where, ctx) {
39
40
  const out = value.flatMap((item) => (type === "elementum_user"
40
41
  ? principal(item, "elementum_user", where, ctx)
41
42
  : principal(item, "elementum_group", where, ctx)) ?? []);
42
- return out.length > 0 ? out : undefined;
43
+ return finishPulledMemberList(where, out, value.length - out.length, ctx.diagnostics);
43
44
  }
44
45
  function keptPlatformId(id, where, ctx) {
45
46
  ctx.diagnostics.push(`${where}: role reference has no recoverable name; kept as unsafePlatformId`);
@@ -1,4 +1,5 @@
1
1
  import { NO_CANVAS, NO_CATALOG, NO_LIFECYCLE } from "../../graph/types.js";
2
+ import { GROUP_RESOURCE_TYPE } from "../org/group.js";
2
3
  export const SERVICE_ACCOUNT_RESOURCE_TYPE = "elementum_service_account";
3
4
  export const SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE = "elementum_service_account_access_policy";
4
5
  export const serviceAccountModule = {
@@ -18,4 +19,23 @@ export const serviceAccountModule = {
18
19
  lifecycle: NO_LIFECYCLE,
19
20
  canvas: NO_CANVAS,
20
21
  catalog: NO_CATALOG,
22
+ roundtrip: {
23
+ referenceAliases: [],
24
+ // Provider set attributes (edk#2437): order carries no meaning.
25
+ unorderedListAttributes: ["role_ids", "user_ids", "group_ids"],
26
+ },
27
+ // The platform's own policy names the account's creator, a user, so it is
28
+ // always dropped; a group-only policy is kept when every group is mapped.
29
+ portable: {
30
+ principals: [
31
+ {
32
+ resourceType: SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE,
33
+ groupAttribute: "group_ids",
34
+ groupDataType: GROUP_RESOURCE_TYPE,
35
+ userAttributes: ["user_ids"],
36
+ whenDropped: "block",
37
+ noun: "service account access policy",
38
+ },
39
+ ],
40
+ },
21
41
  };
@@ -18,8 +18,8 @@ interface ExtractedServiceAccountRoles {
18
18
  readonly roles?: readonly ServiceAccountRole[];
19
19
  }
20
20
  /**
21
- * Order-sensitive comparison of each owned service account's export
22
- * `role_ids` with the roles written into source. Named roles compare by
21
+ * Order-insensitive comparison (`role_ids` is a set, edk#2437) of each owned
22
+ * service account's export `role_ids` with the roles written into source. Named roles compare by
23
23
  * display name; raw ids compare by platform id. A value the printer cannot
24
24
  * represent is a disagreement, not a quiet omission.
25
25
  */
@@ -36,9 +36,9 @@ export interface RebuiltServiceAccountRoleLookup {
36
36
  readonly resourceRoleNames: ReadonlyMap<string, string>;
37
37
  }
38
38
  /**
39
- * Same order-sensitive rule, against service-account blocks rebuilt from
40
- * the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
41
- * disagrees here even when extract mirrored the export.
39
+ * Same membership rule, against service-account blocks rebuilt from the
40
+ * pulled `.ts`. A printer or to-tf that drops or changes a raw id disagrees
41
+ * here even when extract mirrored the export.
42
42
  * When `lookup` is set, rebuilt refs resolve through it. Export refs still
43
43
  * use `ctx` and the export blocks.
44
44
  */
@@ -72,16 +72,24 @@ function mismatchLine(where, index, exported, generated, sourceFile, key) {
72
72
  return `${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids[${index}] export ${identityText(exported)} vs generated ${identityText(generated)}; ${nextStep(sourceFile, key, index)}`;
73
73
  }
74
74
  function compareRoleLists(where, key, sourceFile, exported, generated, out) {
75
+ // `role_ids` is a set in the provider (edk#2437), so compare membership,
76
+ // not position: each role pairs with one equal role on the other side, and
77
+ // an unpaired role on either side is a disagreement. A duplicate still shows.
75
78
  if (exported.length === 0 && generated.length === 0)
76
79
  return;
77
- const count = Math.max(exported.length, generated.length);
78
- for (let index = 0; index < count; index += 1) {
79
- const left = exported[index];
80
- const right = generated[index];
81
- if (left !== undefined && right !== undefined && sameIdentity(left, right))
82
- continue;
83
- out.push(mismatchLine(where, index, left, right, sourceFile, key));
84
- }
80
+ const paired = new Set();
81
+ exported.forEach((left, index) => {
82
+ const match = generated.findIndex((right, at) => !paired.has(at) && sameIdentity(left, right));
83
+ if (match >= 0) {
84
+ paired.add(match);
85
+ return;
86
+ }
87
+ out.push(mismatchLine(where, index, left, undefined, sourceFile, key));
88
+ });
89
+ generated.forEach((right, index) => {
90
+ if (!paired.has(index))
91
+ out.push(mismatchLine(where, index, undefined, right, sourceFile, key));
92
+ });
85
93
  }
86
94
  function roleListFromRebuild(value, dataQueues, resourceRoleNames) {
87
95
  if (value === undefined)
@@ -123,8 +131,8 @@ function describedRoleIds(value) {
123
131
  return value.map((item) => describeRoleValue(item)).join(", ");
124
132
  }
125
133
  /**
126
- * Order-sensitive comparison of each owned service account's export
127
- * `role_ids` with the roles written into source. Named roles compare by
134
+ * Order-insensitive comparison (`role_ids` is a set, edk#2437) of each owned
135
+ * service account's export `role_ids` with the roles written into source. Named roles compare by
128
136
  * display name; raw ids compare by platform id. A value the printer cannot
129
137
  * represent is a disagreement, not a quiet omission.
130
138
  */
@@ -132,9 +140,9 @@ export function serviceAccountRoleIdMismatches(blocks, accounts, owner, ctx) {
132
140
  return compareServiceAccountRoleIds(blocks, accounts, owner, ctx);
133
141
  }
134
142
  /**
135
- * Same order-sensitive rule, against service-account blocks rebuilt from
136
- * the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
137
- * disagrees here even when extract mirrored the export.
143
+ * Same membership rule, against service-account blocks rebuilt from the
144
+ * pulled `.ts`. A printer or to-tf that drops or changes a raw id disagrees
145
+ * here even when extract mirrored the export.
138
146
  * When `lookup` is set, rebuilt refs resolve through it. Export refs still
139
147
  * use `ctx` and the export blocks.
140
148
  */