@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
@@ -1,15 +1,19 @@
1
1
  import { workspaceAspectKey } from "../../engine/build/context.js";
2
2
  import { resolveForeignRef } from "../shared/foreign-ref.js";
3
- import { expr, isCanonicalTsLabel, isTfExpr, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
+ import { expr, isCanonicalTsLabel, isTfExpr, isUuid, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { filterToTf } from "../access-policy/to-tf.js";
5
5
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, automationResourceLabel } from "../automation/types.js";
6
- import { fieldRefToTfValue } from "../field/to-tf.js";
6
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
7
+ import { droppedEntryGap, fieldRefToTfValue, UNRESOLVED_FIELD_REF } from "../field/to-tf.js";
7
8
  import { targetFilterFieldResolver } from "../relationship/to-tf.js";
8
9
  import { filterTfToWire } from "../shared/filters/tf-codec.js";
9
10
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
10
11
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
11
12
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
13
+ import { unbuiltWidgetReferenceNote } from "../widget/to-tf.js";
14
+ import { typedCoverageGap } from "../../engine/coverage-gaps.js";
12
15
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
16
+ import { EntityTfError } from "../../engine/entity.js";
13
17
  import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS, dynamicLayoutActionWidgetName, dynamicLayoutCompanionWidgetLabel, dynamicLayoutFieldComponentWireKey, } from "./dialect.js";
14
18
  export function dynamicLayoutsToTf(layouts, opts) {
15
19
  const blocks = [];
@@ -19,16 +23,18 @@ export function dynamicLayoutsToTf(layouts, opts) {
19
23
  opts.diagnostics.push(`${where}: key is not a canonical tsLabel; dropped`);
20
24
  continue;
21
25
  }
22
- const layout = scopeOf(opts) === "element" ? withoutStageConditions(authored, where, opts.diagnostics) : authored;
26
+ const staged = scopeOf(opts) === "element" ? withoutStageConditions(authored, where, opts.diagnostics) : authored;
27
+ const layout = withoutUnbuildableButtons(withoutUnresolvedFieldEntries(staged, where, opts), where, opts);
23
28
  const layoutLabel = scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), scopeOf(opts));
24
29
  const componentResult = componentMap(layout.components ?? {}, key, layoutLabel, where, opts);
30
+ const identity = requiredLayoutIdentity(layout, where, opts);
25
31
  const attrs = {
26
32
  [scopeOf(opts) === "element" ? "element_id" : "app_id"]: opts.objectId,
27
- name: layout.name ?? "",
33
+ name: identity.name,
28
34
  active: layout.active ?? true,
29
- document_id: layout.documentId ?? "",
35
+ document_id: identity.documentId,
30
36
  document_version: layout.documentVersion ?? "1.0.0",
31
- root_component: layout.rootComponent ?? "",
37
+ root_component: identity.rootComponent,
32
38
  components: componentResult.components,
33
39
  };
34
40
  if (layout.description !== undefined)
@@ -37,7 +43,19 @@ export function dynamicLayoutsToTf(layouts, opts) {
37
43
  opts.diagnostics.push(`${where}.stage: elements have no stages; omit stage for the element's default DASHBOARD layout; dropped`);
38
44
  }
39
45
  else if (layout.stage !== undefined) {
40
- attrs["stage_id"] = expr.local(`${opts.ownerTfLabel}_stage_ids_by_key`, [{ index: stageIdKey(layout.stage, opts) }]);
46
+ const rawStageId = isUnsafePlatformId(layout.stage)
47
+ ? layout.stage.value
48
+ : typeof layout.stage === "string" && isUuid(layout.stage)
49
+ ? layout.stage
50
+ : undefined;
51
+ // Export leaves stage_id as a raw platform id when the stage is not in
52
+ // the owner's stage map. Writing that id back avoids a force-new replace.
53
+ if (rawStageId !== undefined) {
54
+ attrs["stage_id"] = rawStageId;
55
+ }
56
+ else if (typeof layout.stage === "string") {
57
+ attrs["stage_id"] = expr.local(`${opts.ownerTfLabel}_stage_ids_by_key`, [{ index: stageIdKey(layout.stage, opts) }]);
58
+ }
41
59
  }
42
60
  if (layout.conditions !== undefined)
43
61
  attrs["conditions"] = conditionMap(layout.conditions, where, opts);
@@ -61,6 +79,23 @@ export function dynamicLayoutsToTf(layouts, opts) {
61
79
  }
62
80
  return blocks;
63
81
  }
82
+ /**
83
+ * The provider rejects an empty name (LengthAtLeast(1)) and, after trimming in
84
+ * Validate, a blank document_id or root_component, so build stops naming the layout instead of writing
85
+ * `""` that plan rejects (#2052).
86
+ */
87
+ function requiredLayoutIdentity(layout, where, opts) {
88
+ const { name, documentId, rootComponent } = layout;
89
+ // name: exact "" only; documentId/rootComponent: blank after trim, matching the provider's Validate.
90
+ const isBlank = { name: name === undefined || name === "", documentId: documentId === undefined || documentId.trim() === "", rootComponent: rootComponent === undefined || rootComponent.trim() === "" };
91
+ if (name !== undefined && documentId !== undefined && rootComponent !== undefined && !isBlank.name && !isBlank.documentId && !isBlank.rootComponent) {
92
+ return { name, documentId, rootComponent };
93
+ }
94
+ const missing = ["name", "documentId", "rootComponent"].filter((key) => isBlank[key]);
95
+ throw new EntityTfError(`${scopeOf(opts)} "${opts.ownerRefName}" ${where}: dynamic layout ${JSON.stringify(name ?? "")} has an empty ${missing.join(", ")}. ` +
96
+ "The provider requires a non-empty name, document_id and root_component. Set documentId to a stable, non-empty document id " +
97
+ "(a pulled UI-built layout uses its platform id), name to the layout's display name, and rootComponent to a components key.");
98
+ }
64
99
  function scopeOf(opts) {
65
100
  return opts.scope ?? "app";
66
101
  }
@@ -84,7 +119,24 @@ function withoutStageConditions(layout, where, diagnostics) {
84
119
  const { stage: _stage, ...rest } = condition;
85
120
  conditions.set(id, rest);
86
121
  }
87
- const removed = new Set();
122
+ const { layout: pruned, removed } = withoutConditions(layout, conditions, new Set());
123
+ if (removed.size === 0)
124
+ return pruned;
125
+ for (const id of removed) {
126
+ diagnostics.push(`${where}.conditions.${id}: no predicate left on an element; condition and its references removed`);
127
+ }
128
+ return pruned;
129
+ }
130
+ /**
131
+ * Removes the conditions in `removed`, then every condition left without a
132
+ * variant because it only pointed at removed ones (`all`/`any`/`not`), and
133
+ * every reference to a removed id: component rule lists (and a
134
+ * `matchAllRules` left with no rule), and a dependency's `condition`. The
135
+ * provider rejects an empty condition and a dangling condition id.
136
+ */
137
+ function withoutConditions(layout, conditions, removed) {
138
+ for (const id of removed)
139
+ conditions.delete(id);
88
140
  for (let changed = true; changed;) {
89
141
  changed = false;
90
142
  for (const [id, condition] of conditions) {
@@ -100,10 +152,7 @@ function withoutStageConditions(layout, where, diagnostics) {
100
152
  }
101
153
  }
102
154
  if (removed.size === 0)
103
- return { ...layout, conditions: Object.fromEntries(conditions) };
104
- for (const id of removed) {
105
- diagnostics.push(`${where}.conditions.${id}: no predicate left on an element; condition and its references removed`);
106
- }
155
+ return { layout: { ...layout, conditions: Object.fromEntries(conditions) }, removed };
107
156
  const components = {};
108
157
  for (const [componentId, component] of Object.entries(layout.components ?? {})) {
109
158
  const next = { ...component };
@@ -117,21 +166,252 @@ function withoutStageConditions(layout, where, diagnostics) {
117
166
  else
118
167
  next[listKey] = kept;
119
168
  }
169
+ if (next["matchAllRules"] !== undefined && COMPONENT_CONDITION_LIST_KEYS.every((listKey) => next[listKey] === undefined)) {
170
+ delete next["matchAllRules"];
171
+ }
120
172
  components[componentId] = next;
121
173
  }
122
174
  return {
123
- ...layout,
124
- components,
125
- conditions: Object.fromEntries(conditions),
126
- ...(layout.dependencies === undefined ? {} : {
127
- dependencies: layout.dependencies.map((dependency) => {
128
- if (!removed.has(dependency["condition"]))
129
- return dependency;
130
- const { condition: _condition, ...rest } = dependency;
131
- return rest;
175
+ layout: {
176
+ ...layout,
177
+ components,
178
+ conditions: Object.fromEntries(conditions),
179
+ ...(layout.dependencies === undefined ? {} : {
180
+ dependencies: layout.dependencies.map((dependency) => {
181
+ if (!removed.has(dependency["condition"]))
182
+ return dependency;
183
+ const { condition: _condition, ...rest } = dependency;
184
+ return rest;
185
+ }),
186
+ }),
187
+ },
188
+ removed,
189
+ };
190
+ }
191
+ /**
192
+ * A field reference build can't resolve (pull kept no platform id for a field
193
+ * it did not extract, #1966) drops the whole entry that needs it: the
194
+ * provider requires `field_id` on a field component, a field comparison, a
195
+ * field validation and both sides of a dependency, so an entry without it
196
+ * fails plan (#1978). A dropped component leaves the layout as
197
+ * {@link withoutComponents} describes; a dropped condition leaves every
198
+ * reference, as for element stage conditions. An unresolved field on the
199
+ * root component fails build: dropping it would leave no layout (Dax, #1978).
200
+ */
201
+ function withoutUnresolvedFieldEntries(layout, where, opts) {
202
+ const unresolved = (value) => {
203
+ if (value == null)
204
+ return UNRESOLVED_FIELD_REF;
205
+ const scratch = [];
206
+ if (resolveField(value, "", { ...opts, diagnostics: scratch }) !== undefined)
207
+ return undefined;
208
+ return (scratch[0] ?? "field reference is unresolved").replace(/^: /, "").replace(/; dropped$/, "");
209
+ };
210
+ const droppedComponents = new Set();
211
+ for (const [componentId, component] of Object.entries(layout.components ?? {})) {
212
+ for (const [key, value] of Object.entries(component)) {
213
+ if (value === undefined || !DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS.has(key))
214
+ continue;
215
+ const cause = unresolved(object(value)["field"]);
216
+ if (cause === undefined)
217
+ continue;
218
+ if (componentId === layout.rootComponent) {
219
+ // Dropping the root leaves no layout; build fails rather than leave
220
+ // it out, which would make plan destroy an adopted one (Dax, #1978).
221
+ throw new EntityTfError(`${scopeOf(opts)} "${opts.ownerRefName}" ${where}: root component ${JSON.stringify(componentId)} has a field reference build can't resolve ` +
222
+ `(${where}.components[${JSON.stringify(componentId)}].${key}: ${cause}). ` +
223
+ "Build refuses to leave the dynamic layout out: if it is already managed, plan would destroy it. " +
224
+ "Point the field at a field in source (or its unsafePlatformId), or remove the layout (#1978).");
225
+ }
226
+ opts.diagnostics.push(droppedEntryGap(`${where}.components[${JSON.stringify(componentId)}].${key}`, `${cause}; component ${JSON.stringify(componentId)} dropped with its references`, "dynamic layout"));
227
+ droppedComponents.add(componentId);
228
+ }
229
+ }
230
+ let next = withoutComponents(layout, droppedComponents, where, opts);
231
+ if (next.conditions !== undefined) {
232
+ const conditions = new Map(Object.entries(next.conditions));
233
+ const removed = new Set();
234
+ for (const [conditionId, condition] of conditions) {
235
+ for (const [key, value] of Object.entries(condition)) {
236
+ if (value === undefined || !DYNAMIC_LAYOUT_COMPARISON_KEYS.has(key))
237
+ continue;
238
+ const cause = unresolved(object(value)["field"]);
239
+ if (cause === undefined)
240
+ continue;
241
+ opts.diagnostics.push(droppedEntryGap(`${where}.conditions.${conditionId}.${key}`, `${cause}; condition ${JSON.stringify(conditionId)} dropped with its references`, "dynamic layout"));
242
+ removed.add(conditionId);
243
+ }
244
+ }
245
+ if (removed.size > 0) {
246
+ const direct = new Set(removed);
247
+ const result = withoutConditions(next, conditions, removed);
248
+ for (const id of result.removed) {
249
+ if (!direct.has(id))
250
+ opts.diagnostics.push(droppedEntryGap(`${where}.conditions.${id}`, "only referenced dropped conditions; condition dropped with its references", "dynamic layout"));
251
+ }
252
+ next = result.layout;
253
+ }
254
+ }
255
+ const keepValidation = (validation, at) => {
256
+ const cause = unresolved(validation["field"]);
257
+ if (cause !== undefined)
258
+ opts.diagnostics.push(droppedEntryGap(`${at}.field`, `${cause}; validation dropped`, "dynamic layout"));
259
+ return cause === undefined;
260
+ };
261
+ if (next.fieldValidations !== undefined) {
262
+ next = { ...next, fieldValidations: next.fieldValidations.filter((validation, index) => keepValidation(validation, `${where}.fieldValidations[${index}]`)) };
263
+ }
264
+ if (next.saveGroups !== undefined) {
265
+ const saveGroups = {};
266
+ for (const [id, group] of Object.entries(next.saveGroups)) {
267
+ saveGroups[id] = Array.isArray(group["validations"])
268
+ ? { ...group, validations: group["validations"].filter((validation, index) => keepValidation(object(validation), `${where}.saveGroups.${id}.validations[${index}]`)) }
269
+ : group;
270
+ }
271
+ next = { ...next, saveGroups };
272
+ }
273
+ if (next.dependencies !== undefined) {
274
+ next = {
275
+ ...next,
276
+ dependencies: next.dependencies.filter((value, index) => {
277
+ for (const side of ["sourceField", "targetField"]) {
278
+ const cause = unresolved(value[side]);
279
+ if (cause !== undefined) {
280
+ opts.diagnostics.push(droppedEntryGap(`${where}.dependencies[${index}].${side}`, `${cause}; dependency dropped`, "dynamic layout"));
281
+ return false;
282
+ }
283
+ }
284
+ return true;
132
285
  }),
133
- }),
286
+ };
287
+ }
288
+ return next;
289
+ }
290
+ /**
291
+ * An automation button whose automation build can't reference (not in
292
+ * source, another owner's, or a bad key) can't be built: the provider
293
+ * requires `automation_id`, and a component with no variant fails its
294
+ * `exactly one concrete variant` check. Build leaves the whole component out
295
+ * (#1877), as {@link withoutComponents} describes. A root button fails build:
296
+ * leaving it out would leave no layout.
297
+ */
298
+ function withoutUnbuildableButtons(layout, where, opts) {
299
+ const dropped = new Set();
300
+ for (const [componentId, component] of Object.entries(layout.components ?? {})) {
301
+ if (component["automationButton"] === undefined)
302
+ continue;
303
+ const token = object(component["automationButton"])["automation"];
304
+ const problem = buttonAutomationProblem(token, opts);
305
+ if (problem === undefined)
306
+ continue;
307
+ if (componentId === layout.rootComponent) {
308
+ throw new EntityTfError(`${scopeOf(opts)} "${opts.ownerRefName}" ${where}: the root component ${JSON.stringify(componentId)} is an automation button that can't be built: ${problem}. ` +
309
+ "A layout can't be built without its root, and leaving the whole layout out would make plan destroy it if it is already managed, so build stops here. " +
310
+ "Point the button at an automation in source, or remove the layout (#1877).");
311
+ }
312
+ opts.diagnostics.push(typedCoverageGap({
313
+ kind: "skipped",
314
+ entity: `${where}.components.${componentId}.automationButton`,
315
+ detail: `${problem}, so build leaves this button's component out of the layout, with its slot in its parent`,
316
+ consequence: "if this button is already applied, the next apply removes it from the layout. Point it at an automation in source, or remove the button",
317
+ }));
318
+ dropped.add(componentId);
319
+ }
320
+ return withoutComponents(layout, dropped, where, opts);
321
+ }
322
+ /**
323
+ * Leaves the components in `dropped` out of the layout with every reference
324
+ * to them, so the provider's layout check still passes: their slots in their
325
+ * parents' `children` and every `dependsOn`. A container whose children were
326
+ * all left out is left out too (recursively), and a condition only those
327
+ * components used is removed, since the provider rejects an unreachable
328
+ * condition. Leaving out the root fails build: there would be no layout
329
+ * (Dax, #1978). The caller has already said why each of `dropped` is out.
330
+ */
331
+ function withoutComponents(layout, dropped, where, opts) {
332
+ if (dropped.size === 0)
333
+ return layout;
334
+ const all = layout.components ?? {};
335
+ const out = new Set(dropped);
336
+ for (let changed = true; changed;) {
337
+ changed = false;
338
+ for (const [componentId, component] of Object.entries(all)) {
339
+ const children = component["children"];
340
+ if (out.has(componentId) || !Array.isArray(children) || children.length === 0)
341
+ continue;
342
+ if (!children.every((id) => out.has(id)))
343
+ continue;
344
+ if (componentId === layout.rootComponent) {
345
+ throw new EntityTfError(`${scopeOf(opts)} "${opts.ownerRefName}" ${where}: build left out every child of root component ${JSON.stringify(componentId)} (see the warnings above). ` +
346
+ "Build refuses to leave an empty dynamic layout: if it is already managed, the next apply would wipe it. Fix those components, or remove the layout (#1877).");
347
+ }
348
+ out.add(componentId);
349
+ changed = true;
350
+ opts.diagnostics.push(droppedEntryGap(`${where}.components[${JSON.stringify(componentId)}]`, "build left out every child of this container, so it is left out too, with its slot in its parent", "dynamic layout"));
351
+ }
352
+ }
353
+ const components = {};
354
+ for (const [componentId, component] of Object.entries(all)) {
355
+ if (out.has(componentId))
356
+ continue;
357
+ const kept = { ...component };
358
+ if (Array.isArray(kept["children"]))
359
+ kept["children"] = kept["children"].filter((id) => !out.has(id));
360
+ for (const [key, value] of Object.entries(kept)) {
361
+ if (!DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS.has(key))
362
+ continue;
363
+ const field = object(value);
364
+ if (!Array.isArray(field["dependsOn"]))
365
+ continue;
366
+ const dependsOn = field["dependsOn"].filter((id) => !out.has(id));
367
+ const { dependsOn: _dependsOn, ...rest } = field;
368
+ kept[key] = dependsOn.length === 0 ? rest : { ...rest, dependsOn };
369
+ }
370
+ components[componentId] = kept;
371
+ }
372
+ const next = { ...layout, components };
373
+ if (layout.conditions === undefined)
374
+ return next;
375
+ const before = reachableConditions(layout);
376
+ const after = reachableConditions(next);
377
+ const conditions = {};
378
+ for (const [id, condition] of Object.entries(layout.conditions)) {
379
+ if (before.has(id) && !after.has(id)) {
380
+ opts.diagnostics.push(droppedEntryGap(`${where}.conditions.${id}`, "only components build left out used this condition, so it is removed", "dynamic layout"));
381
+ continue;
382
+ }
383
+ conditions[id] = condition;
384
+ }
385
+ return { ...next, conditions };
386
+ }
387
+ /** Condition ids a component rule or a dependency uses, directly or through `all`/`any`/`not`. */
388
+ function reachableConditions(layout) {
389
+ const conditions = layout.conditions ?? {};
390
+ const seen = new Set();
391
+ const visit = (id) => {
392
+ if (typeof id !== "string" || seen.has(id))
393
+ return;
394
+ seen.add(id);
395
+ const condition = conditions[id];
396
+ if (condition === undefined)
397
+ return;
398
+ for (const key of ["all", "any"]) {
399
+ for (const child of object(condition[key])["conditions"] ?? [])
400
+ visit(child);
401
+ }
402
+ if (condition["not"] !== undefined)
403
+ visit(object(condition["not"])["condition"]);
134
404
  };
405
+ for (const component of Object.values(layout.components ?? {})) {
406
+ for (const key of COMPONENT_CONDITION_LIST_KEYS) {
407
+ const ids = component[key];
408
+ if (Array.isArray(ids))
409
+ ids.forEach(visit);
410
+ }
411
+ }
412
+ for (const dependency of layout.dependencies ?? [])
413
+ visit(dependency["condition"]);
414
+ return seen;
135
415
  }
136
416
  function pruneConditionRefs(condition, removed) {
137
417
  const out = {};
@@ -227,6 +507,13 @@ function componentMap(components, layoutKey, layoutLabel, where, opts) {
227
507
  button["automation_id"] = automation;
228
508
  button["widget_id"] = widget;
229
509
  }
510
+ else if (automation !== undefined && rec["widget"] !== undefined) {
511
+ // The authored widget was not built (noted above). A companion would
512
+ // replace it with a widget nobody authored, so keep the automation
513
+ // and leave the button without a widget until its widget builds.
514
+ button["automation_id"] = automation;
515
+ opts.diagnostics.push(`${where}.components.${componentId}.automationButton: its widget was not built, so the button keeps its automation but is built without a widget, and cannot run until the widget builds`);
516
+ }
230
517
  else if (automation !== undefined) {
231
518
  button["automation_id"] = automation;
232
519
  // The renderer executes the automation through a widget, not the
@@ -247,7 +534,10 @@ function componentMap(components, layoutKey, layoutLabel, where, opts) {
247
534
  },
248
535
  });
249
536
  }
250
- attrs["automation_button"] = button;
537
+ // withoutUnbuildableButtons already left out every button whose
538
+ // automation does not resolve (automation_id is required).
539
+ if (automation !== undefined)
540
+ attrs["automation_button"] = button;
251
541
  }
252
542
  else if (key === "createButton") {
253
543
  const rec = object(value);
@@ -403,12 +693,19 @@ function dependency(value, where, opts) {
403
693
  return out;
404
694
  }
405
695
  function resolveFields(values, where, opts) {
406
- return values.flatMap((value) => {
407
- const resolved = resolveField(value, where, opts);
696
+ return values.flatMap((value, index) => {
697
+ const resolved = resolveField(value, `${where}[${index}]`, opts);
408
698
  return resolved === undefined ? [] : [resolved];
409
699
  });
410
700
  }
411
701
  function resolveField(value, where, opts) {
702
+ // A field pull did not extract stays as its platform id (#1736, #1966).
703
+ if (isUnsafePlatformId(value))
704
+ return value.value;
705
+ if (value == null) {
706
+ opts.diagnostics.push(droppedEntryGap(where, `${UNRESOLVED_FIELD_REF}; dropped`, "dynamic layout"));
707
+ return undefined;
708
+ }
412
709
  if (typeof value === "string") {
413
710
  if (scopeOf(opts) === "element" && !ELEMENT_SYSTEM_FIELD_KEYS.includes(value)) {
414
711
  opts.diagnostics.push(`${where}: "${value}" is not a known system field key on an element; dropped`);
@@ -443,16 +740,28 @@ function typedValue(value, fieldValue, opts) {
443
740
  }
444
741
  return snakeObject(rec, "dynamic layout typed value", opts);
445
742
  }
446
- function resolveAutomation(token, where, opts) {
743
+ /** Why a button (or input) can't reference `token`'s automation, or undefined when it can. */
744
+ function buttonAutomationProblem(token, opts) {
447
745
  const refName = token?.refName ?? "";
448
746
  if (token?.parent !== undefined && token.parent !== opts.ownerRefName) {
449
- opts.diagnostics.push(`${where}: cross-${scopeOf(opts)} automations are not supported; dropped`);
450
- return undefined;
747
+ return `its automation belongs to another ${scopeOf(opts)} (${JSON.stringify(token.parent)}), and cross-${scopeOf(opts)} automations are not supported`;
451
748
  }
452
- if (!isCanonicalTsLabel(refName)) {
453
- opts.diagnostics.push(`${where}: automation key "${refName}" is not a canonical tsLabel; dropped`);
749
+ if (!isCanonicalTsLabel(refName))
750
+ return `its automation key ${JSON.stringify(refName)} is not a canonical tsLabel`;
751
+ const authored = opts.workspaceAspects?.get(workspaceAspectKey(scopeOf(opts), opts.ownerRefName))?.automationRefNames;
752
+ // A reference to an automation build never declares would fail plan with
753
+ // `Reference to undeclared resource` (#1877).
754
+ if (authored !== undefined && !authored.has(refName))
755
+ return `its automation ${JSON.stringify(refName)} is not in source`;
756
+ return undefined;
757
+ }
758
+ function resolveAutomation(token, where, opts) {
759
+ const problem = buttonAutomationProblem(token, opts);
760
+ if (problem !== undefined) {
761
+ opts.diagnostics.push(`${where}: ${problem}; dropped`);
454
762
  return undefined;
455
763
  }
764
+ const refName = token?.refName ?? "";
456
765
  return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, automationResourceLabel(opts.ownerTfLabel, refName, scopeOf(opts), scopeOf(opts) === "element" ? opts.ownerHandle : undefined), ["id"]);
457
766
  }
458
767
  function isActiveAutomation(refName, opts) {
@@ -491,8 +800,8 @@ function resolveWidget(token, where, opts) {
491
800
  opts.diagnostics.push(`${where}: widget belongs to ${JSON.stringify(token.parent)}, not ${JSON.stringify(opts.ownerRefName)}; dropped`);
492
801
  return undefined;
493
802
  }
494
- if (opts.widgetKeys !== undefined && !opts.widgetKeys.has(key)) {
495
- opts.diagnostics.push(`${where}: widget ${JSON.stringify(key)} is not declared in this ${scopeOf(opts)}; dropped`);
803
+ if (opts.widgets !== undefined && !opts.widgets.built.has(key)) {
804
+ opts.diagnostics.push(unbuiltWidgetReferenceNote(where, key, scopeOf(opts), opts.ownerRefName, opts.widgets));
496
805
  return undefined;
497
806
  }
498
807
  return expr.resourceAttr(WIDGET_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), scopeOf(opts)), ["id"]);
@@ -146,6 +146,16 @@ interface ElementV2OptionsBase<F extends Record<string, AppField> = Record<strin
146
146
  readonly relationships?: Readonly<Record<string, AppRelationship>>;
147
147
  /** Display order of `listViews` (by key). Defaults to declaration order. */
148
148
  readonly viewOrder?: readonly string[];
149
+ /**
150
+ * Delete the platform's default "List" view (the LIST-type view named
151
+ * "List" the platform creates on every app and element), so the first entry
152
+ * of `viewOrder` is the main surface. The delete runs once: when the view
153
+ * order is created with it set, or when it changes from unset/`false` to
154
+ * `true`; later applies, including reorders, never delete a view. The plan
155
+ * warns with the view's id and name, and fails if several views qualify.
156
+ * Omitting it means `false` (nothing is deleted). No declared view may be named "List".
157
+ */
158
+ readonly deleteDefaultListView?: boolean;
149
159
  /**
150
160
  * Element-level sharing & row-level-security policies (`elementum_access_policy`), in declaration order.
151
161
  * Creating the element also has the platform mint a separate creator policy
@@ -145,6 +145,7 @@ export function element(opts) {
145
145
  ...(opts.dynamicLayouts !== undefined ? { dynamicLayouts: opts.dynamicLayouts } : {}),
146
146
  ...(opts.relationships !== undefined ? { relationships: opts.relationships } : {}),
147
147
  ...(opts.viewOrder !== undefined ? { viewOrder: opts.viewOrder } : {}),
148
+ ...(opts.deleteDefaultListView !== undefined ? { deleteDefaultListView: opts.deleteDefaultListView } : {}),
148
149
  ...(opts.accessPolicies !== undefined ? { accessPolicies: opts.accessPolicies } : {}),
149
150
  ...(opts.roles !== undefined ? { roles: opts.roles } : {}),
150
151
  };
@@ -8,14 +8,14 @@ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES } from "../../core/system-fields.js";
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
9
  import { dataRefLabel, optionalBoolean, optionalString } from "../../engine/pull/context.js";
10
10
  import { tfLabelToTsLabel } from "../../engine/tf/index.js";
11
- import { accessPolicyFromTf } from "../access-policy/from-tf.js";
11
+ import { accessPolicyBlocksInLabelOrder, accessPolicyFromTf } from "../access-policy/from-tf.js";
12
12
  import { dashboardsFromTf } from "../dashboard/from-tf.js";
13
13
  import { dynamicLayoutCompanionWidgetLabels, dynamicLayoutsFromTf } from "../dynamic-layout/from-tf.js";
14
14
  import { fieldFromTf } from "../field/from-tf.js";
15
15
  import { recordCreateFormFromTf } from "../record-create-form/from-tf.js";
16
16
  import { relationshipsFromTf } from "../relationship/from-tf.js";
17
17
  import { rolesFromTf } from "../role/from-tf.js";
18
- import { viewsFromTf } from "../view/from-tf.js";
18
+ import { fieldKeysByDisplayName, viewsFromTf } from "../view/from-tf.js";
19
19
  import { widgetsFromTf } from "../widget/from-tf.js";
20
20
  import { ELEMENT_RESOURCE_TYPE } from "./module.js";
21
21
  /** Attributes `elementFromTf` understands — anything else is dialect growth. */
@@ -148,17 +148,21 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
148
148
  if (elementId === undefined) {
149
149
  ctx.diagnostics.push(`element "${label}": no import block in the stream — adoption has no identity to bind`);
150
150
  }
151
- const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: refName, ownerRefName: refName, scope: "element", ownerType: "ELEMENT_ASPECT" }, ctx);
152
151
  const unextractedFieldIds = new Set();
153
- const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, customViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, [], viewBlocks.managedViewOrderBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "element", fieldKeys: new Set(fields.map((field) => field.key)), unextractedFieldIds }, ctx, viewBlocks.customViewBlocks);
152
+ const fieldKeys = new Set(fields.map((field) => field.key));
153
+ const fieldKeysByName = fieldKeysByDisplayName(fields);
154
+ const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, ownerRefName: refName, scope: "element", ownerType: "ELEMENT_ASPECT", fieldKeys, fieldKeysByName, unextractedFieldIds }, ctx);
155
+ // Every field reference pull writes keeps an unextracted field as its platform id (#1736, #1966).
156
+ const unextracted = { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "element", fieldKeys, fieldKeysByName, unextractedFieldIds };
157
+ const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, customViews, viewOrder, deleteDefaultListView } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, [], viewBlocks.managedViewOrderBlocks, unextracted, ctx, viewBlocks.customViewBlocks);
154
158
  if (viewBlocks.recordCreateFormBlocks.length > 1) {
155
159
  ctx.diagnostics.push(`element "${label}": found ${viewBlocks.recordCreateFormBlocks.length} record create forms; only the first is used`);
156
160
  }
157
- const recordCreateForm = recordCreateFormFromTf(viewBlocks.recordCreateFormBlocks[0], { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: refName, scope: "element" }, ctx);
158
- const relationships = relationshipsFromTf(viewBlocks.relationshipBlocks, { kind: "element", label, ownerRefName: refName, ownerTfLabel: refName, scope: "element" }, ctx);
161
+ const recordCreateForm = recordCreateFormFromTf(viewBlocks.recordCreateFormBlocks[0], { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "element", unextracted }, ctx);
162
+ const relationships = relationshipsFromTf(viewBlocks.relationshipBlocks, { kind: "element", label, ownerRefName: refName, ownerTfLabel: label, scope: "element", unextracted }, ctx);
159
163
  const dynamicLayoutBlocks = viewBlocks.dynamicLayoutBlocks ?? [];
160
- const dynamicLayouts = dynamicLayoutsFromTf(dynamicLayoutBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }, ctx);
161
- const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }, ctx, dynamicLayoutCompanionWidgetLabels(dynamicLayoutBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }));
164
+ const dynamicLayouts = dynamicLayoutsFromTf(dynamicLayoutBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element", unextracted }, ctx);
165
+ const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element", unextracted }, ctx, dynamicLayoutCompanionWidgetLabels(dynamicLayoutBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }));
162
166
  const accessPolicyOwner = {
163
167
  type: ELEMENT_RESOURCE_TYPE,
164
168
  label,
@@ -167,7 +171,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
167
171
  scope: "element",
168
172
  };
169
173
  const accessPolicies = [];
170
- for (const block of accessPolicyBlocks) {
174
+ for (const block of accessPolicyBlocksInLabelOrder(accessPolicyBlocks)) {
171
175
  const entry = accessPolicyFromTf(block, accessPolicyOwner, ctx);
172
176
  if (entry !== undefined)
173
177
  accessPolicies.push(entry);
@@ -210,6 +214,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
210
214
  ...(dynamicLayouts.length > 0 && { dynamicLayouts }),
211
215
  ...(relationships.length > 0 && { relationships }),
212
216
  ...(viewOrder !== undefined && { viewOrder }),
217
+ ...(deleteDefaultListView !== undefined && { deleteDefaultListView }),
213
218
  ...(accessPolicies.length > 0 && { accessPolicies }),
214
219
  ...(roles.length > 0 && { roles }),
215
220
  };
@@ -184,6 +184,7 @@ export function elementToTf(entity, ctx) {
184
184
  const field = fieldToTf(typeKey, inner, {
185
185
  ownerTfLabel: ctx.appTfLabel,
186
186
  appRefName: ctx.appRefName,
187
+ ...(payload.name !== undefined && { ownerName: payload.name }),
187
188
  scope: "element",
188
189
  objectId,
189
190
  diagnostics: ctx.diagnostics,
@@ -211,7 +212,7 @@ export function elementToTf(entity, ctx) {
211
212
  workspaceAspects: ctx.workspaceAspects,
212
213
  diagnostics: ctx.diagnostics,
213
214
  }));
214
- blocks.push(...widgetsToTf(payload.widgets, {
215
+ const widgets = widgetsToTf(payload.widgets, {
215
216
  ownerRefName: ctx.appRefName,
216
217
  ownerTfLabel: ctx.appTfLabel,
217
218
  ownerHandle: payload.handle,
@@ -223,7 +224,8 @@ export function elementToTf(entity, ctx) {
223
224
  diagnostics: ctx.diagnostics,
224
225
  fieldAddresses,
225
226
  relationshipTargets: relationshipTargetsFromBag(payload.relationships),
226
- }));
227
+ });
228
+ blocks.push(...widgets.blocks);
227
229
  // An element has exactly one implicit layout (the platform's Initiate
228
230
  // stage — see layoutToTf's element-scope stage_id omission) — "layout" is
229
231
  // a synthetic bag key here, not a real stage reference. It must match the
@@ -247,7 +249,8 @@ export function elementToTf(entity, ctx) {
247
249
  fieldAddresses,
248
250
  fieldNames,
249
251
  fieldMetadata,
250
- widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
252
+ widgets: widgets.widgets,
253
+ ...(payload.deleteDefaultListView !== undefined ? { deleteDefaultListView: payload.deleteDefaultListView } : {}),
251
254
  }, payload.customViews);
252
255
  blocks.push(...viewBlocks);
253
256
  const recordCreateFormForToTf = payload.recordCreateForm ??
@@ -274,7 +277,7 @@ export function elementToTf(entity, ctx) {
274
277
  orgRefs: ctx.orgRefs,
275
278
  workspaceAspects: ctx.workspaceAspects,
276
279
  fieldAddresses,
277
- widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
280
+ widgets: widgets.widgets,
278
281
  }));
279
282
  blocks.push(...relationshipsToTf(payload.relationships, {
280
283
  ownerRefName: ctx.appRefName,