@elementumai/edk 0.9.19 → 0.9.20

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 (176) hide show
  1. package/README.md +146 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +24 -1
  3. package/dist-sdk/src/catalog/factories.js +30 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +7 -0
  10. package/dist-sdk/src/catalog/types.d.ts +34 -1
  11. package/dist-sdk/src/catalog/types.js +11 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  13. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  14. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  15. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  16. package/dist-sdk/src/engine/ei/run.js +1132 -0
  17. package/dist-sdk/src/engine/logging.d.ts +17 -0
  18. package/dist-sdk/src/engine/logging.js +18 -0
  19. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  20. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  21. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  22. package/dist-sdk/src/engine/pull/result-output.js +87 -3
  23. package/dist-sdk/src/engine/tf/expr.js +1 -1
  24. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  25. package/dist-sdk/src/engine/tf/index.js +1 -1
  26. package/dist-sdk/src/engine/tf/labels.d.ts +6 -0
  27. package/dist-sdk/src/engine/tf/labels.js +9 -0
  28. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  29. package/dist-sdk/src/engine/tf/parse.js +92 -4
  30. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  31. package/dist-sdk/src/engine/tf/render.js +41 -7
  32. package/dist-sdk/src/engine/validation.d.ts +39 -0
  33. package/dist-sdk/src/engine/validation.js +85 -0
  34. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  35. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  36. package/dist-sdk/src/entities/agent/build.js +40 -5
  37. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  38. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  39. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  40. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  41. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  42. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  43. package/dist-sdk/src/entities/app/build.d.ts +89 -20
  44. package/dist-sdk/src/entities/app/build.js +51 -6
  45. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +16 -0
  46. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  47. package/dist-sdk/src/entities/app/from-tf.js +7 -2
  48. package/dist-sdk/src/entities/app/index.d.ts +6 -6
  49. package/dist-sdk/src/entities/app/index.js +1 -0
  50. package/dist-sdk/src/entities/app/module.js +5 -2
  51. package/dist-sdk/src/entities/app/to-tf.js +19 -11
  52. package/dist-sdk/src/entities/automation/build.d.ts +47 -5
  53. package/dist-sdk/src/entities/automation/build.js +137 -20
  54. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  55. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +314 -39
  56. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  57. package/dist-sdk/src/entities/automation/from-tf.js +428 -48
  58. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  59. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  60. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  61. package/dist-sdk/src/entities/automation/index.js +1 -1
  62. package/dist-sdk/src/entities/automation/module.js +37 -8
  63. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  64. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  65. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  67. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  68. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  69. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  70. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +2 -0
  71. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -0
  72. package/dist-sdk/src/entities/automation/tasks.d.ts +24 -2
  73. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  74. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  75. package/dist-sdk/src/entities/automation/to-tf.js +489 -83
  76. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  77. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  78. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  79. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  80. package/dist-sdk/src/entities/element/build.d.ts +25 -13
  81. package/dist-sdk/src/entities/element/build.js +4 -1
  82. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  83. package/dist-sdk/src/entities/element/from-tf.js +58 -1
  84. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  85. package/dist-sdk/src/entities/element/index.js +1 -0
  86. package/dist-sdk/src/entities/element/module.js +9 -3
  87. package/dist-sdk/src/entities/element/to-tf.js +8 -2
  88. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  89. package/dist-sdk/src/entities/field/build.js +3 -0
  90. package/dist-sdk/src/entities/field/from-tf.d.ts +1 -0
  91. package/dist-sdk/src/entities/field/from-tf.js +39 -1
  92. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/media-types.js +30 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  96. package/dist-sdk/src/entities/field/to-tf.js +130 -14
  97. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  98. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  99. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  100. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  101. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  102. package/dist-sdk/src/entities/portal/build.js +37 -0
  103. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  104. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  105. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  106. package/dist-sdk/src/entities/portal/index.js +1 -0
  107. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  108. package/dist-sdk/src/entities/portal/module.js +28 -0
  109. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  110. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  111. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  112. package/dist-sdk/src/entities/portal/types.js +1 -0
  113. package/dist-sdk/src/entities/relationship/module.js +2 -0
  114. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  115. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  116. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  118. package/dist-sdk/src/entities/search-table/module.js +1 -0
  119. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  120. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  121. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  122. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  123. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  124. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  125. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  126. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  127. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  128. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  129. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  130. package/dist-sdk/src/entities/shared/filters/ast.d.ts +8 -0
  131. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -0
  132. package/dist-sdk/src/entities/shared/filters/index.js +14 -4
  133. package/dist-sdk/src/entities/shared/filters/print.js +17 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +2 -0
  135. package/dist-sdk/src/entities/shared/filters/tf-codec.js +5 -1
  136. package/dist-sdk/src/entities/shared/filters/types.d.ts +9 -1
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  138. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +2 -1
  140. package/dist-sdk/src/entities/skill/from-tf.js +66 -13
  141. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  142. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  143. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  144. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +27 -5
  148. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  149. package/dist-sdk/src/entities/table/catalog.js +66 -0
  150. package/dist-sdk/src/entities/table/module.js +2 -1
  151. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  152. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  153. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  154. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  155. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  156. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  157. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  158. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  159. package/dist-sdk/src/entities/view/from-tf.js +124 -12
  160. package/dist-sdk/src/entities/view/module.js +30 -3
  161. package/dist-sdk/src/entities/view/to-tf.d.ts +14 -1
  162. package/dist-sdk/src/entities/view/to-tf.js +67 -10
  163. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  164. package/dist-sdk/src/entities/view/types.js +15 -15
  165. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  166. package/dist-sdk/src/entities/widget/build.js +11 -1
  167. package/dist-sdk/src/entities/widget/to-tf.js +34 -8
  168. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +16 -5
  169. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  170. package/dist-sdk/src/graph/index.d.ts +11 -0
  171. package/dist-sdk/src/graph/index.js +21 -0
  172. package/dist-sdk/src/graph/modules.js +2 -0
  173. package/dist-sdk/src/graph/types.d.ts +55 -2
  174. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  175. package/dist-sdk/src/internal/sdk-package.js +1 -0
  176. package/package.json +10 -1
@@ -5,16 +5,17 @@
5
5
  * owning app's from-tf drives this pass and says who the owner is — this
6
6
  * module never names the app's own resource type.
7
7
  */
8
- import { agentViewLayoutFromTf } from "./agent-view-layout-from-tf.js";
9
- import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
8
+ import { agentViewLayoutFromTf, viewBlocksFromTf, } from "./agent-view-layout-from-tf.js";
9
+ import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
10
10
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
11
11
  import { isTfExpr, isTfLabel, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
12
- import { fieldKeyFromTfValue } from "../field/from-tf.js";
12
+ import { decodeForeignDataField, fieldKeyFromTfValue } from "../field/from-tf.js";
13
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
13
14
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
14
15
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
15
16
  import { filterFromTf, principalList } from "../access-policy/from-tf.js";
16
17
  import { listViewDensity, } from "./build.js";
17
- import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, KNOWN_AGENT_VIEW_ATTRS, KNOWN_CALENDAR_VIEW_ATTRS, KNOWN_DASHBOARD_VIEW_ATTRS, KNOWN_KANBAN_VIEW_ATTRS, KNOWN_LAYOUT_ATTRS, KNOWN_LAYOUT_SECTION_ATTRS, KNOWN_LIST_VIEW_ATTRS, KNOWN_MANAGED_VIEW_ORDER_ATTRS, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, SECTION_TYPE_FROM_WIRE, SYSTEM_FIELD_KEY_BY_ID_ATTR, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
18
+ import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, KNOWN_AGENT_VIEW_ATTRS, KNOWN_CALENDAR_VIEW_ATTRS, KNOWN_CUSTOM_VIEW_ATTRS, KNOWN_DASHBOARD_VIEW_ATTRS, KNOWN_KANBAN_VIEW_ATTRS, KNOWN_LAYOUT_ATTRS, KNOWN_LAYOUT_SECTION_ATTRS, KNOWN_LIST_VIEW_ATTRS, KNOWN_MANAGED_VIEW_ORDER_ATTRS, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, SECTION_TYPE_FROM_WIRE, SYSTEM_FIELD_KEY_BY_ID_ATTR, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
18
19
  function viewFilter(value, owner, where, ctx) {
19
20
  return value === undefined ? undefined : filterFromTf(value, {
20
21
  type: owner.type,
@@ -26,7 +27,7 @@ function viewFilter(value, owner, where, ctx) {
26
27
  }, `${where}.filter`, ctx, { optionLookupsAreIdentities: true });
27
28
  }
28
29
  /** All three view resource kinds → the normalized shapes the app printer consumes. */
29
- export function viewsFromTf(layoutBlocks, listViewBlocks, calendarViewBlocks, kanbanViewBlocks, dashboardViewBlocks, agentViewBlocks, managedViewOrderBlocks, owner, ctx) {
30
+ export function viewsFromTf(layoutBlocks, listViewBlocks, calendarViewBlocks, kanbanViewBlocks, dashboardViewBlocks, agentViewBlocks, managedViewOrderBlocks, owner, ctx, customViewBlocks = []) {
30
31
  const layouts = [];
31
32
  for (const block of layoutBlocks) {
32
33
  const layout = layoutFromTf(block, owner, ctx);
@@ -50,6 +51,14 @@ export function viewsFromTf(layoutBlocks, listViewBlocks, calendarViewBlocks, ka
50
51
  keyByAddress.set(`${AGENT_VIEW_RESOURCE_TYPE}.${block.label ?? ""}`, view.key);
51
52
  }
52
53
  }
54
+ const customViews = [];
55
+ for (const block of customViewBlocks) {
56
+ const view = customViewFromTf(block, owner, ctx);
57
+ if (view !== undefined) {
58
+ customViews.push(view);
59
+ keyByAddress.set(`${CUSTOM_VIEW_RESOURCE_TYPE}.${block.label ?? ""}`, view.key);
60
+ }
61
+ }
53
62
  const calendarViews = [];
54
63
  for (const block of calendarViewBlocks) {
55
64
  const view = calendarViewFromTf(block, owner, ctx);
@@ -83,7 +92,68 @@ export function viewsFromTf(layoutBlocks, listViewBlocks, calendarViewBlocks, ka
83
92
  }
84
93
  viewOrder = managedViewOrderFromTf(block, owner, keyByAddress, ctx);
85
94
  }
86
- return { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, ...(viewOrder !== undefined ? { viewOrder } : {}) };
95
+ return { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews, ...(viewOrder !== undefined ? { viewOrder } : {}) };
96
+ }
97
+ function customViewFromTf(block, owner, ctx) {
98
+ const label = block.label;
99
+ if (label === undefined || label === "") {
100
+ ctx.diagnostics.push(`${CUSTOM_VIEW_RESOURCE_TYPE} block is missing its label; skipped`);
101
+ return undefined;
102
+ }
103
+ const attrs = block.attrs;
104
+ const where = `custom view "${label}"`;
105
+ reportUnknownAttrs(attrs, KNOWN_CUSTOM_VIEW_ATTRS, where, "customViewFromTf", ctx);
106
+ if (resourceRefLabel(attrs["aspect_id"], owner.type) !== owner.label) {
107
+ ctx.diagnostics.push(`${where}: aspect_id does not reference ${owner.type}.${owner.label}; skipped`);
108
+ return undefined;
109
+ }
110
+ const scope = owner.scope ?? "app";
111
+ // An unmanaged view keeps its live layout and agent; printing a partial one
112
+ // would make the next apply clear them.
113
+ const unmanaged = (reason) => {
114
+ ctx.diagnostics.push(`${where}: ${reason}; the view is left unmanaged so its live layout is not cleared`);
115
+ ctx.skipped.push(`${CUSTOM_VIEW_RESOURCE_TYPE}.${label}`);
116
+ return undefined;
117
+ };
118
+ let agentKey;
119
+ if (attrs["agent_id"] !== undefined && attrs["agent_id"] !== null) {
120
+ // Agents are app-owned: an element's view cannot name its agent in source,
121
+ // and building it without the agent would detach it on apply.
122
+ if (scope === "element")
123
+ return unmanaged("element views cannot reference an agent in source");
124
+ const agentLabel = resourceRefLabel(attrs["agent_id"], "elementum_agent");
125
+ if (agentLabel === undefined)
126
+ return unmanaged("agent_id is not an elementum_agent resource reference");
127
+ agentKey = scopedLabelToBagKey(owner.ownerTfLabel, agentLabel, scope);
128
+ }
129
+ let layout;
130
+ const layoutAttr = attrs["layout"];
131
+ if (layoutAttr !== undefined && layoutAttr !== null) {
132
+ if (!isTfExpr(layoutAttr) || layoutAttr.$expr !== "jsonencode")
133
+ return unmanaged("layout is not a jsonencode(...) expression");
134
+ const decoded = viewBlocksFromTf(layoutAttr.value, layoutRefOptions(owner, ctx));
135
+ if (!decoded.ok)
136
+ return unmanaged(decoded.reason);
137
+ layout = decoded.layout;
138
+ }
139
+ const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
140
+ const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
141
+ const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
142
+ const emptyUserIds = Array.isArray(attrs["user_ids"]) && attrs["user_ids"].length === 0;
143
+ const emptyGroupIds = Array.isArray(attrs["group_ids"]) && attrs["group_ids"].length === 0;
144
+ const filter = viewFilter(attrs["filter"], owner, where, ctx);
145
+ return {
146
+ key: scopedLabelToBagKey(owner.ownerTfLabel, label, scope),
147
+ name: optionalString(attrs, "name", where, ctx) ?? "",
148
+ ...(agentKey !== undefined && { agentKey }),
149
+ ...(layout !== undefined && { layout }),
150
+ ...(typeof attrs["allow_record_creation"] === "boolean" && { allowRecordCreation: attrs["allow_record_creation"] }),
151
+ ...(filter !== undefined && { filter }),
152
+ ...(sort !== undefined && { sort }),
153
+ ...(userIds !== undefined ? { userIds } : emptyUserIds ? { userIds: [] } : {}),
154
+ ...(groupIds !== undefined ? { groupIds } : emptyGroupIds ? { groupIds: [] } : {}),
155
+ ...(typeof attrs["display_order"] === "number" && { displayOrder: attrs["display_order"] }),
156
+ };
87
157
  }
88
158
  function dashboardViewFromTf(block, owner, ctx) {
89
159
  const label = block.label;
@@ -182,6 +252,48 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
182
252
  ...(groupIds !== undefined ? { groupIds } : emptyGroupIds ? { groupIds: [] } : {}),
183
253
  };
184
254
  }
255
+ /**
256
+ * How a blocks layout's references pull: the owner and its fields, and other
257
+ * apps and elements and their fields through the export's data lookups.
258
+ */
259
+ function layoutRefOptions(owner, ctx) {
260
+ const foreignSource = (value) => {
261
+ for (const [type, kind] of [["elementum_app", "app"], ["elementum_element", "element"]]) {
262
+ const dataLabel = dataRefLabel(value, type);
263
+ if (dataLabel === undefined)
264
+ continue;
265
+ const target = resolveDataAspectTarget(ctx, kind, dataLabel);
266
+ return { __specRef: "source", kind, key: target.key, name: target.name, ...(target.namespace !== undefined && { namespace: target.namespace }) };
267
+ }
268
+ return undefined;
269
+ };
270
+ return {
271
+ isOwnApp: (value) => resourceRefLabel(value, owner.type) === owner.label,
272
+ fieldKey: (value) => fieldRefFromTf(value, owner.label, owner.ownerTfLabel, owner.scope ?? "app", ctx),
273
+ foreignSource,
274
+ foreignField: (value) => {
275
+ const dataLabel = dataRefLabel(value, "elementum_field");
276
+ const parent = dataLabel === undefined ? undefined : foreignSource(ctx.dataAttrs?.("elementum_field", dataLabel)?.["object_id"] ?? null);
277
+ if (dataLabel === undefined || parent === undefined)
278
+ return undefined;
279
+ const field = decodeForeignDataField(dataLabel, { key: parent.key, name: parent.name, namespace: parent.namespace, kind: parent.kind }, ctx);
280
+ return {
281
+ __specRef: "foreignField",
282
+ key: field.key,
283
+ name: field.name,
284
+ // The pull's ref-only catalog normally supplies the type. Without it,
285
+ // fall back to TEXT like every other foreign field ref the EDK prints
286
+ // (widgets, relationship columns, filters): build looks a foreign
287
+ // field up by owner and name, never by type, so the guess is cosmetic.
288
+ fieldType: field.fieldType ?? "TEXT",
289
+ parent: ctx.foreignFieldRefsByDataAddress?.get(`elementum_field.${dataLabel}`)?.ownerRefName ?? parent.key,
290
+ parentKind: parent.kind,
291
+ parentName: parent.name,
292
+ ...(parent.namespace !== undefined && { parentNamespace: parent.namespace }),
293
+ };
294
+ },
295
+ };
296
+ }
185
297
  function agentViewFromTf(block, owner, ctx) {
186
298
  const label = block.label;
187
299
  if (label === undefined || label === "") {
@@ -209,10 +321,7 @@ function agentViewFromTf(block, owner, ctx) {
209
321
  const filter = viewFilter(attrs["filter"], owner, where, ctx);
210
322
  let layout;
211
323
  if (attrs["layout"] !== undefined && attrs["layout"] !== null) {
212
- const decoded = agentViewLayoutFromTf(attrs["layout"], {
213
- isOwnApp: (value) => resourceRefLabel(value, owner.type) === owner.label,
214
- fieldKey: (value) => fieldRefFromTf(value, owner.label, owner.ownerTfLabel, scope, ctx),
215
- });
324
+ const decoded = agentViewLayoutFromTf(attrs["layout"], layoutRefOptions(owner, ctx));
216
325
  if (!decoded.ok) {
217
326
  // The code owns the layout: printing the view without it would make the
218
327
  // next apply clear the live customization. Leave the view unmanaged.
@@ -539,6 +648,7 @@ function managedViewOrderFromTf(block, owner, keyByAddress, ctx) {
539
648
  const calendarLabel = resourceRefLabel(v, CALENDAR_VIEW_RESOURCE_TYPE);
540
649
  const kanbanLabel = resourceRefLabel(v, KANBAN_VIEW_RESOURCE_TYPE);
541
650
  const dashboardLabel = resourceRefLabel(v, DASHBOARD_VIEW_RESOURCE_TYPE);
651
+ const customLabel = resourceRefLabel(v, CUSTOM_VIEW_RESOURCE_TYPE);
542
652
  const key = listLabel !== undefined
543
653
  ? keyByAddress.get(`${LIST_VIEW_RESOURCE_TYPE}.${listLabel}`)
544
654
  : agentLabel !== undefined
@@ -549,9 +659,11 @@ function managedViewOrderFromTf(block, owner, keyByAddress, ctx) {
549
659
  ? keyByAddress.get(`${KANBAN_VIEW_RESOURCE_TYPE}.${kanbanLabel}`)
550
660
  : dashboardLabel !== undefined
551
661
  ? keyByAddress.get(`${DASHBOARD_VIEW_RESOURCE_TYPE}.${dashboardLabel}`)
552
- : undefined;
662
+ : customLabel !== undefined
663
+ ? keyByAddress.get(`${CUSTOM_VIEW_RESOURCE_TYPE}.${customLabel}`)
664
+ : undefined;
553
665
  if (key === undefined) {
554
- ctx.diagnostics.push(`${where}: a view_ids entry does not resolve to a known list view; dropped`);
666
+ ctx.diagnostics.push(`${where}: a view_ids entry does not resolve to a known managed view; dropped`);
555
667
  continue;
556
668
  }
557
669
  order.push(key);
@@ -1,6 +1,7 @@
1
1
  /** The view entity's registry entries (see src/graph/). */
2
+ import { asNamedRef, namedFactoryEntry } from "../../catalog/render-helpers.js";
2
3
  import { NO_CANVAS, NO_CATALOG, NO_DATA, NO_LIFECYCLE, } from "../../graph/types.js";
3
- import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, } from "./types.js";
4
+ import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, VIEW_DATA_RESOURCE_TYPE, } from "./types.js";
4
5
  /**
5
6
  * Layouts + list views are stream members folded into the app authoring file
6
7
  * (inline), extracted by `appFromTf` — not own-file kinds.
@@ -22,12 +23,38 @@ export const viewModule = {
22
23
  { key: "calendarView", resourceType: CALENDAR_VIEW_RESOURCE_TYPE, implemented: true },
23
24
  { key: "dashboardView", resourceType: DASHBOARD_VIEW_RESOURCE_TYPE, implemented: true },
24
25
  { key: "kanbanView", resourceType: KANBAN_VIEW_RESOURCE_TYPE, implemented: true },
26
+ { key: "customView", resourceType: CUSTOM_VIEW_RESOURCE_TYPE, implemented: true },
25
27
  ],
26
28
  },
27
- data: NO_DATA,
29
+ // A portal menu names a view outside the workspace by owner and name.
30
+ data: { participates: true, resourceType: VIEW_DATA_RESOURCE_TYPE, lookupAttr: "name", referencedByBuild: true },
28
31
  lifecycle: NO_LIFECYCLE,
29
32
  canvas: NO_CANVAS,
30
- catalog: NO_CATALOG,
33
+ // Inline under the app/element: generated catalogs read `views` live from
34
+ // the owner's `.ref()` (like fields), so other stream roots — a portal's
35
+ // menu — can reference a view by owner and name.
36
+ catalog: {
37
+ participates: true,
38
+ refKind: "view",
39
+ catalogBag: "views",
40
+ renderOrder: 51,
41
+ catalogRoot: "app",
42
+ fromOwnRef: true,
43
+ renderEntry: (args) => {
44
+ const named = asNamedRef(args.ref);
45
+ const viewType = args.ref.viewType;
46
+ return namedFactoryEntry({
47
+ factoryName: "viewRef",
48
+ keyName: args.keyName,
49
+ baseIndent: args.baseIndent,
50
+ name: named.name,
51
+ parent: named.parent,
52
+ ...(viewType !== undefined ? { extraParts: [`viewType: ${JSON.stringify(viewType)}`] } : {}),
53
+ });
54
+ },
55
+ stubRef: (refName, parent) => ({ __kind: "view", refName, name: refName, parent }),
56
+ refFromAuthoring: () => undefined,
57
+ },
31
58
  };
32
59
  /**
33
60
  * `elementum_managed_view_order` is a singleton per aspect with no identity
@@ -67,6 +67,19 @@ export interface AppAgentViewWire extends ManagedViewSharing {
67
67
  readonly displayOrder?: number;
68
68
  readonly layout?: AppAgentViewLayoutWire;
69
69
  }
70
+ export interface AppCustomViewWire extends ManagedViewSharing {
71
+ readonly name?: string;
72
+ readonly agent?: {
73
+ readonly refName?: string;
74
+ readonly parent?: string;
75
+ };
76
+ readonly allowRecordCreation?: boolean;
77
+ readonly filter?: Filter;
78
+ readonly sort?: ManagedViewSort;
79
+ readonly displayOrder?: number;
80
+ /** A blocks layout (the public type, unchecked). */
81
+ readonly layout?: unknown;
82
+ }
70
83
  export interface AppCalendarViewWire extends ManagedViewSharing {
71
84
  readonly name?: string;
72
85
  readonly columns?: readonly ViewFieldRefWire[];
@@ -123,5 +136,5 @@ export interface ViewToTfResult {
123
136
  readonly blocks: readonly TfBlock[];
124
137
  }
125
138
  /** `layouts`/`listViews`/`viewOrder` → their resource blocks, in ei's dialect. */
126
- export declare function viewToTf(layouts: Readonly<Record<string, AppLayoutWire>> | undefined, listViews: Readonly<Record<string, AppListViewWire>> | undefined, calendarViews: Readonly<Record<string, AppCalendarViewWire>> | undefined, kanbanViews: Readonly<Record<string, AppKanbanViewWire>> | undefined, dashboardViews: Readonly<Record<string, AppDashboardViewWire>> | undefined, agentViews: Readonly<Record<string, AppAgentViewWire>> | undefined, viewOrder: readonly string[] | undefined, opts: ViewToTfOptions): ViewToTfResult;
139
+ export declare function viewToTf(layouts: Readonly<Record<string, AppLayoutWire>> | undefined, listViews: Readonly<Record<string, AppListViewWire>> | undefined, calendarViews: Readonly<Record<string, AppCalendarViewWire>> | undefined, kanbanViews: Readonly<Record<string, AppKanbanViewWire>> | undefined, dashboardViews: Readonly<Record<string, AppDashboardViewWire>> | undefined, agentViews: Readonly<Record<string, AppAgentViewWire>> | undefined, viewOrder: readonly string[] | undefined, opts: ViewToTfOptions, customViews?: Readonly<Record<string, AppCustomViewWire>>): ViewToTfResult;
127
140
  export declare function managedViewSortToTf(sort: ManagedViewSort, ownerTfLabel: string, scope: ChildResourceScope, where: string, diagnostics: string[], fieldAddresses?: ReadonlyMap<string, string>): TfValue;
@@ -9,7 +9,7 @@
9
9
  * reported, never silent. Invalid authored filter trees fail at build time
10
10
  * with the same `EntityTfError` path used by access-policy row filters.
11
11
  */
12
- import { agentViewLayoutToTf } from "./agent-view-layout-to-tf.js";
12
+ import { agentViewLayoutToTf, viewBlocksToTf } from "./agent-view-layout-to-tf.js";
13
13
  import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
14
14
  import { fieldRefToTfValue as customFieldRefToTfValue } from "../field/to-tf.js";
15
15
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
@@ -17,7 +17,7 @@ import { filterToTf, principalListToTf } from "../access-policy/to-tf.js";
17
17
  import { SUB_TYPE_BY_AUTHORING_TYPE } from "../field/types.js";
18
18
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
19
19
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
20
- import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, LAYOUT_RESOURCE_TYPE, LAYOUT_RESTRICTED_SYSTEM_FIELD_KEYS, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, SECTION_TYPE_TO_WIRE, SYSTEM_FIELD_ID_ATTR_BY_KEY, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
20
+ import { AGENT_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, SECTION_TYPE_TO_WIRE, SYSTEM_FIELD_ID_ATTR_BY_KEY, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
21
21
  function appendViewSharingAttrs(attrs, view, where, ctx) {
22
22
  const userIds = principalListToTf(view.userIds, "elementum_user", `${where}.userIds`, ctx);
23
23
  const groupIds = principalListToTf(view.groupIds, "elementum_group", `${where}.groupIds`, ctx);
@@ -35,7 +35,7 @@ function appendViewSharingAttrs(attrs, view, where, ctx) {
35
35
  }
36
36
  }
37
37
  /** `layouts`/`listViews`/`viewOrder` → their resource blocks, in ei's dialect. */
38
- export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, viewOrder, opts) {
38
+ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, viewOrder, opts, customViews) {
39
39
  const { ownerRefName, ownerTfLabel, scope = "app", aspectName, objectId, diagnostics, fieldAddresses } = opts;
40
40
  const principalCtx = { ...opts, scope, objectId };
41
41
  const blocks = [];
@@ -225,6 +225,60 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
225
225
  blocks.push({ kind: "resource", type: AGENT_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
226
226
  viewAddressByKey.set(viewKey, { type: AGENT_VIEW_RESOURCE_TYPE, label: tfLabel });
227
227
  }
228
+ for (const [viewKey, view] of Object.entries(customViews ?? {})) {
229
+ const where = `customViews.${viewKey}`;
230
+ if (!isCanonicalTsLabel(viewKey)) {
231
+ diagnostics.push(`customViews key "${viewKey}" is not a canonical tsLabel (see src/engine/tf/labels.ts) — rename the key`);
232
+ continue;
233
+ }
234
+ if (viewAddressByKey.has(viewKey)) {
235
+ diagnostics.push(`${where} collides with another view key; dropped`);
236
+ continue;
237
+ }
238
+ const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
239
+ const attrs = {
240
+ aspect_id: objectId,
241
+ name: view.name ?? "",
242
+ allow_record_creation: view.allowRecordCreation ?? true,
243
+ };
244
+ if (view.agent !== undefined) {
245
+ const agentRefName = view.agent.refName ?? "";
246
+ if (agentRefName === "" || view.agent.parent !== ownerRefName) {
247
+ // Dropping only the agent would detach it on apply; keep the whole view out instead.
248
+ diagnostics.push(`${where}.agent must be an agent of this ${scope === "element" ? "element" : "app"}; dropped`);
249
+ continue;
250
+ }
251
+ attrs["agent_id"] = expr.resourceAttr("elementum_agent", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(agentRefName), scope), ["id"]);
252
+ }
253
+ if (view.filter !== undefined)
254
+ attrs["filter"] = filterToTf(view.filter, `${where}.filter`, { ownerTfLabel, appRefName: ownerRefName, scope, objectId, diagnostics, resolvePicklistLiterals: false, fieldAddresses });
255
+ if (view.sort !== undefined)
256
+ attrs["sort"] = managedViewSortToTf(view.sort, ownerTfLabel, scope, `${where}.sort`, diagnostics, fieldAddresses);
257
+ appendViewSharingAttrs(attrs, view, where, principalCtx);
258
+ if (view.displayOrder !== undefined)
259
+ attrs["display_order"] = view.displayOrder;
260
+ if (view.layout !== undefined) {
261
+ attrs["layout"] = expr.jsonencode(viewBlocksToTf(view.layout, `${where}.layout`, {
262
+ ownerRefName,
263
+ ownerKind: scope === "element" ? "element" : "app",
264
+ ownerTfLabel,
265
+ scope,
266
+ objectId,
267
+ diagnostics,
268
+ fieldAddresses,
269
+ orgRefs: opts.orgRefs,
270
+ workspaceAspects: opts.workspaceAspects,
271
+ resolveField: (ref, fieldWhere) => fieldRefToTfValue(ref, ownerTfLabel, scope, fieldWhere, diagnostics, fieldAddresses),
272
+ }, { editorPolicy: false }));
273
+ }
274
+ else {
275
+ // The page needs a layout document, and the platform rejects a blank
276
+ // one, so a view without a layout cannot be opened in the admin UI.
277
+ diagnostics.push(`${where} has no layout, so the admin UI cannot open this view ("This custom view could not be loaded"); add a layout`);
278
+ }
279
+ blocks.push({ kind: "resource", type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
280
+ viewAddressByKey.set(viewKey, { type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel });
281
+ }
228
282
  if (viewAddressByKey.size > 0) {
229
283
  const orderKeys = viewOrder ?? [
230
284
  ...Object.keys(listViews ?? {}),
@@ -232,6 +286,7 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
232
286
  ...Object.keys(kanbanViews ?? {}),
233
287
  ...Object.keys(dashboardViews ?? {}),
234
288
  ...Object.keys(agentViews ?? {}),
289
+ ...Object.keys(customViews ?? {}),
235
290
  ];
236
291
  const placed = new Set();
237
292
  const viewIds = [];
@@ -321,13 +376,15 @@ function layoutToTf(stageKey, layout, ownerRefName, ownerTfLabel, scope, objectI
321
376
  sec.agent_id = expr.resourceAttr("elementum_agent", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(agentRefName), "app"), ["id"]);
322
377
  }
323
378
  }
324
- const fields = (section.fields ?? []).filter((f) => {
325
- if (typeof f === "string" && LAYOUT_RESTRICTED_SYSTEM_FIELD_KEYS.has(f)) {
326
- diagnostics.push(`${where}: system field "${f}" is platform-managed and cannot be placed in a layout section; dropped`);
327
- return false;
328
- }
329
- return true;
330
- });
379
+ // System fields (ID/Title/Status included) are kept in their authored
380
+ // position as the owner's `local.<ns>_<key>_field_id`. A UI-placed
381
+ // system field is a real section member: the provider reads it back
382
+ // into `field_ids` and `ei export` emits it (as its platform id), so
383
+ // dropping it here rebuilt a shorter list, which plans a destructive
384
+ // replace that removes the field from the live section. The platform
385
+ // accepts ID/Title/Status field blocks like any field, so the
386
+ // provider re-places them when it recreates the layout.
387
+ const fields = section.fields ?? [];
331
388
  const widgetIds = [];
332
389
  for (const [index, widget] of (section.widgets ?? []).entries()) {
333
390
  const widgetWhere = `${where}.widgets[${index}]`;
@@ -13,10 +13,13 @@
13
13
  export declare const LAYOUT_RESOURCE_TYPE = "elementum_layout";
14
14
  export declare const LIST_VIEW_RESOURCE_TYPE = "elementum_list_view";
15
15
  export declare const AGENT_VIEW_RESOURCE_TYPE = "elementum_agent_view";
16
+ export declare const CUSTOM_VIEW_RESOURCE_TYPE = "elementum_custom_view";
16
17
  export declare const CALENDAR_VIEW_RESOURCE_TYPE = "elementum_calendar_view";
17
18
  export declare const KANBAN_VIEW_RESOURCE_TYPE = "elementum_kanban_view";
18
19
  export declare const DASHBOARD_VIEW_RESOURCE_TYPE = "elementum_dashboard_view";
19
20
  export declare const MANAGED_VIEW_ORDER_RESOURCE_TYPE = "elementum_managed_view_order";
21
+ /** Looks up a managed view by owner and name (a portal menu's view outside the workspace). */
22
+ export declare const VIEW_DATA_RESOURCE_TYPE = "elementum_view";
20
23
  /**
21
24
  * Layout section `type` discriminator: authoring camelCase ↔ the provider's
22
25
  * wire value, verified against `provider/internal/provider/layout_resource.go`
@@ -30,21 +33,6 @@ export declare const SECTION_TYPE_FROM_WIRE: ReadonlyMap<string, string>;
30
33
  export declare const GROUP_SECTION_WIRE_TYPE = "group";
31
34
  /** The one other section type carrying an (optional) `name`. */
32
35
  export declare const UPDATE_SECTION_WIRE_TYPE = "update";
33
- /**
34
- * System-field keys the platform refuses to accept in a layout `group`
35
- * section's `field_ids` on create — confirmed live against `prestonhigh`:
36
- * `elementum_layout` create errors "cannot place system fields in layout
37
- * sections: ID (has HANDLE, TITLE, or STATUS tag), Title (...), Status
38
- * (...)". The platform's OWN auto-provisioned default "System" section
39
- * legitimately contains them (so `ei export`/`layoutFromTf` still capture
40
- * them faithfully — this is a real, current fact about the app), but
41
- * terraform can never re-create a section containing them: `to-tf` must
42
- * drop these three specifically wherever a group section names them, or
43
- * every layout recreate (any `sections` edit forces a full replace) fails.
44
- * Audit fields (createdAt/createdBy/updatedAt/updatedBy/closedAt/closedBy)
45
- * are NOT restricted — only HANDLE/TITLE/STATUS.
46
- */
47
- export declare const LAYOUT_RESTRICTED_SYSTEM_FIELD_KEYS: ReadonlySet<string>;
48
36
  /**
49
37
  * System-field key → the `local.<ns>_<attr>` name `entities/app/locals.ts`
50
38
  * emits for it (`SYSTEM_FIELD_ID_ATTRS`'s `<tfLabel>_field_id` shape there).
@@ -59,6 +47,7 @@ export declare const KNOWN_LAYOUT_SECTION_ATTRS: ReadonlySet<string>;
59
47
  /** Attributes `listViewFromTf` understands. */
60
48
  export declare const KNOWN_LIST_VIEW_ATTRS: ReadonlySet<string>;
61
49
  export declare const KNOWN_AGENT_VIEW_ATTRS: ReadonlySet<string>;
50
+ export declare const KNOWN_CUSTOM_VIEW_ATTRS: ReadonlySet<string>;
62
51
  export declare const KNOWN_CALENDAR_VIEW_ATTRS: ReadonlySet<string>;
63
52
  export declare const KNOWN_KANBAN_VIEW_ATTRS: ReadonlySet<string>;
64
53
  export declare const KNOWN_DASHBOARD_VIEW_ATTRS: ReadonlySet<string>;
@@ -15,10 +15,13 @@ import { tsLabelToTfLabel } from "../../engine/tf/index.js";
15
15
  export const LAYOUT_RESOURCE_TYPE = "elementum_layout";
16
16
  export const LIST_VIEW_RESOURCE_TYPE = "elementum_list_view";
17
17
  export const AGENT_VIEW_RESOURCE_TYPE = "elementum_agent_view";
18
+ export const CUSTOM_VIEW_RESOURCE_TYPE = "elementum_custom_view";
18
19
  export const CALENDAR_VIEW_RESOURCE_TYPE = "elementum_calendar_view";
19
20
  export const KANBAN_VIEW_RESOURCE_TYPE = "elementum_kanban_view";
20
21
  export const DASHBOARD_VIEW_RESOURCE_TYPE = "elementum_dashboard_view";
21
22
  export const MANAGED_VIEW_ORDER_RESOURCE_TYPE = "elementum_managed_view_order";
23
+ /** Looks up a managed view by owner and name (a portal menu's view outside the workspace). */
24
+ export const VIEW_DATA_RESOURCE_TYPE = "elementum_view";
22
25
  /**
23
26
  * Layout section `type` discriminator: authoring camelCase ↔ the provider's
24
27
  * wire value, verified against `provider/internal/provider/layout_resource.go`
@@ -42,21 +45,6 @@ export const SECTION_TYPE_FROM_WIRE = new Map(Object.entries(SECTION_TYPE_TO_WIR
42
45
  export const GROUP_SECTION_WIRE_TYPE = "group";
43
46
  /** The one other section type carrying an (optional) `name`. */
44
47
  export const UPDATE_SECTION_WIRE_TYPE = "update";
45
- /**
46
- * System-field keys the platform refuses to accept in a layout `group`
47
- * section's `field_ids` on create — confirmed live against `prestonhigh`:
48
- * `elementum_layout` create errors "cannot place system fields in layout
49
- * sections: ID (has HANDLE, TITLE, or STATUS tag), Title (...), Status
50
- * (...)". The platform's OWN auto-provisioned default "System" section
51
- * legitimately contains them (so `ei export`/`layoutFromTf` still capture
52
- * them faithfully — this is a real, current fact about the app), but
53
- * terraform can never re-create a section containing them: `to-tf` must
54
- * drop these three specifically wherever a group section names them, or
55
- * every layout recreate (any `sections` edit forces a full replace) fails.
56
- * Audit fields (createdAt/createdBy/updatedAt/updatedBy/closedAt/closedBy)
57
- * are NOT restricted — only HANDLE/TITLE/STATUS.
58
- */
59
- export const LAYOUT_RESTRICTED_SYSTEM_FIELD_KEYS = new Set(["id", "title", "status"]);
60
48
  /**
61
49
  * System-field key → the `local.<ns>_<attr>` name `entities/app/locals.ts`
62
50
  * emits for it (`SYSTEM_FIELD_ID_ATTRS`'s `<tfLabel>_field_id` shape there).
@@ -105,6 +93,18 @@ export const KNOWN_AGENT_VIEW_ATTRS = new Set([
105
93
  "display_order",
106
94
  "layout",
107
95
  ]);
96
+ export const KNOWN_CUSTOM_VIEW_ATTRS = new Set([
97
+ "aspect_id",
98
+ "agent_id",
99
+ "name",
100
+ "allow_record_creation",
101
+ "filter",
102
+ "sort",
103
+ "user_ids",
104
+ "group_ids",
105
+ "display_order",
106
+ "layout",
107
+ ]);
108
108
  const COMMON_TYPED_VIEW_ATTRS = [
109
109
  "aspect_id",
110
110
  "name",
@@ -65,6 +65,18 @@ export interface CreateRecordWidget extends WidgetButtonStyle {
65
65
  readonly name: string;
66
66
  readonly target: AppOrElementRef;
67
67
  }
68
+ /**
69
+ * Values the platform resolves when the button is pressed:
70
+ * - `currentRecord` binds an `ASPECT_RECORD` (`type: "record"`) parameter to
71
+ * the record the button is on.
72
+ * - `triggeredByUser` binds a `USER_ID` (`type: "userId"`) parameter to the
73
+ * user who pressed the button.
74
+ */
75
+ export declare const runAutomationParameterValue: {
76
+ readonly currentRecord: "CURRENT_RECORD";
77
+ readonly triggeredByUser: "TRIGGERED_BY_USER";
78
+ };
79
+ export type RunAutomationParameterValue = (typeof runAutomationParameterValue)[keyof typeof runAutomationParameterValue];
68
80
  interface RunAutomationWidgetParameterBase {
69
81
  readonly name: string;
70
82
  readonly fieldType: WorkflowFieldType;
@@ -76,7 +88,10 @@ export type RunAutomationWidgetParameter = RunAutomationWidgetParameterBase & ({
76
88
  readonly field: FieldRef;
77
89
  readonly value?: never;
78
90
  } | {
79
- /** Static value; supports the provider's `{{field-id}}` interpolation syntax. */
91
+ /**
92
+ * Static value; supports the provider's `{{field-id}}` interpolation syntax,
93
+ * or a {@link runAutomationParameterValue} resolved at click time.
94
+ */
80
95
  readonly field?: never;
81
96
  readonly value: string;
82
97
  });
@@ -1 +1,11 @@
1
- export {};
1
+ /**
2
+ * Values the platform resolves when the button is pressed:
3
+ * - `currentRecord` binds an `ASPECT_RECORD` (`type: "record"`) parameter to
4
+ * the record the button is on.
5
+ * - `triggeredByUser` binds a `USER_ID` (`type: "userId"`) parameter to the
6
+ * user who pressed the button.
7
+ */
8
+ export const runAutomationParameterValue = {
9
+ currentRecord: "CURRENT_RECORD",
10
+ triggeredByUser: "TRIGGERED_BY_USER",
11
+ };
@@ -3,7 +3,8 @@ import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.
3
3
  import { appScopedResourceLabel, expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { AUTOMATION_RESOURCE_TYPE } from "../automation/types.js";
5
5
  import { fieldMetadataFromEntries } from "../field/metadata.js";
6
- import { fieldRefToTfValue } from "../field/to-tf.js";
6
+ import { authoredFieldKeysFromPayload, fieldRefToTfValue, } from "../field/to-tf.js";
7
+ import { runAutomationParameterValue } from "./build.js";
7
8
  import { WIDGET_RESOURCE_TYPE } from "./module.js";
8
9
  import { filterToTf } from "../access-policy/to-tf.js";
9
10
  export function relationshipTargetsFromBag(relationships) {
@@ -57,6 +58,7 @@ export function widgetsToTf(widgets, opts) {
57
58
  objectId: opts.objectId,
58
59
  diagnostics: opts.diagnostics,
59
60
  orgRefs: opts.orgRefs,
61
+ fieldAddresses: opts.fieldAddresses,
60
62
  });
61
63
  attrs["related_link_action"] = body;
62
64
  break;
@@ -132,7 +134,15 @@ function resolveAspect(value, where, opts) {
132
134
  const kind = value?.__kind === "element" ? "element" : "app";
133
135
  const refName = value?.refName ?? "";
134
136
  if (kind === opts.scope && refName === opts.ownerRefName) {
135
- return { value: opts.objectId, kind, refName, tfLabel: opts.ownerTfLabel, name: value?.name ?? refName, managed: true };
137
+ return {
138
+ value: opts.objectId,
139
+ kind,
140
+ refName,
141
+ tfLabel: opts.ownerTfLabel,
142
+ name: value?.name ?? refName,
143
+ managed: true,
144
+ fieldOwnership: opts.fieldAddresses,
145
+ };
136
146
  }
137
147
  const sibling = opts.workspaceAspects?.get(workspaceAspectKey(kind, refName));
138
148
  if (sibling !== undefined) {
@@ -140,7 +150,15 @@ function resolveAspect(value, where, opts) {
140
150
  const payloadName = typeof sibling.streamRootEntity?.payload === "object" && sibling.streamRootEntity.payload !== null
141
151
  ? sibling.streamRootEntity.payload.name
142
152
  : undefined;
143
- return { value: expr.resourceAttr(type, sibling.tfLabel, ["id"]), kind, refName, tfLabel: sibling.tfLabel, name: value?.name ?? payloadName, managed: true };
153
+ return {
154
+ value: expr.resourceAttr(type, sibling.tfLabel, ["id"]),
155
+ kind,
156
+ refName,
157
+ tfLabel: sibling.tfLabel,
158
+ name: value?.name ?? payloadName,
159
+ managed: true,
160
+ fieldOwnership: authoredFieldKeysFromPayload(sibling.streamRootEntity?.payload),
161
+ };
144
162
  }
145
163
  const name = value?.name ?? refName;
146
164
  if (name === "") {
@@ -166,7 +184,7 @@ function resolveAspect(value, where, opts) {
166
184
  function resolveManagedSystemColumn(key, target) {
167
185
  if (!target.managed || target.tfLabel === undefined || target.kind === undefined)
168
186
  return undefined;
169
- return fieldRefToTfValue("HANDLE", key, target.tfLabel, target.kind);
187
+ return fieldRefToTfValue("HANDLE", key, target.tfLabel, target.kind, target.fieldOwnership);
170
188
  }
171
189
  function resolveColumns(columns, target, where, opts) {
172
190
  const out = [];
@@ -217,7 +235,7 @@ function resolveColumns(columns, target, where, opts) {
217
235
  }
218
236
  if (target.managed && target.kind !== undefined && target.tfLabel !== undefined) {
219
237
  const column = resolveManagedColumn(value, refName, target, opts);
220
- const direct = fieldRefToTfValue(column.fieldType, column.refName, target.tfLabel, target.kind);
238
+ const direct = fieldRefToTfValue(column.fieldType, column.refName, target.tfLabel, target.kind, target.fieldOwnership);
221
239
  if (direct !== undefined) {
222
240
  out.push(direct);
223
241
  continue;
@@ -239,13 +257,21 @@ function runAutomationParameters(widget, where, opts) {
239
257
  if (fieldId !== undefined && parameter.value !== undefined) {
240
258
  opts.diagnostics.push(`${where}.parameters[${index}]: field and value are mutually exclusive; value dropped`);
241
259
  }
260
+ const fieldType = parameter.fieldType ?? "TEXT";
261
+ let value = fieldId === undefined ? parameter.value ?? null : null;
262
+ if (value === runAutomationParameterValue.triggeredByUser && fieldType !== "USER_ID") {
263
+ opts.diagnostics.push(`${where}.parameters[${index}]: TRIGGERED_BY_USER binds a USER_ID parameter; ` +
264
+ `${JSON.stringify(parameter.name ?? "")} is ${fieldType}. Declare the on-demand input as type "userId" ` +
265
+ `and set fieldType "USER_ID"; value dropped`);
266
+ value = null;
267
+ }
242
268
  return {
243
269
  name: parameter.name ?? "",
244
- field_type: parameter.fieldType ?? "TEXT",
270
+ field_type: fieldType,
245
271
  multiple: parameter.multiple ?? false,
246
272
  required: parameter.required ?? false,
247
273
  field_id: fieldId ?? null,
248
- value: fieldId === undefined ? parameter.value ?? null : null,
274
+ value,
249
275
  };
250
276
  });
251
277
  const recordParam = onDemandRecordParamForWidget(widget.automation, opts);
@@ -260,7 +286,7 @@ function runAutomationParameters(widget, where, opts) {
260
286
  multiple: false,
261
287
  required: false,
262
288
  field_id: null,
263
- value: "CURRENT_RECORD",
289
+ value: runAutomationParameterValue.currentRecord,
264
290
  },
265
291
  ];
266
292
  }