@elementumai/edk 0.9.18 → 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 (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -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/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -12,10 +12,32 @@
12
12
  import { EntityTfError } from "../../engine/entity.js";
13
13
  import { workspaceAspectKey } from "../../engine/build/context.js";
14
14
  import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
15
- import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
15
+ import { SYSTEM_FIELD_KEY_SET, systemFieldTag } from "../../core/system-fields.js";
16
+ import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS, ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
16
17
  import { filterToTf as filterWireToTfCodec } from "../shared/filters/tf-codec.js";
18
+ import { foreignFieldDataLabel } from "../shared/foreign-ref.js";
19
+ import { isAttachmentMediaType } from "./media-types.js";
17
20
  import { picklistLabel } from "./options.js";
18
21
  import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
22
+ /** Reconstruct custom-field ownership from a loaded app/element payload. */
23
+ export function authoredFieldKeysFromPayload(payload) {
24
+ if (typeof payload !== "object" || payload === null)
25
+ return undefined;
26
+ const fields = payload.fields;
27
+ const keys = new Set();
28
+ for (const entry of fields ?? []) {
29
+ const inner = Object.values(entry)[0];
30
+ if (inner === undefined || systemFieldTag(inner) !== undefined)
31
+ continue;
32
+ const key = inner.__refName ?? snakeSlug(inner.name ?? "");
33
+ if (key !== "")
34
+ keys.add(key);
35
+ }
36
+ return keys;
37
+ }
38
+ function workspaceFieldOwnership(aspect) {
39
+ return authoredFieldKeysFromPayload(aspect.streamRootEntity?.payload);
40
+ }
19
41
  /** `unknown` → the tagged org-field-ref shape, or undefined for anything else. */
20
42
  function asOrgFieldRef(v) {
21
43
  if (typeof v !== "object" || v === null || v.__kind !== "orgFieldRef")
@@ -88,12 +110,24 @@ function resolveRelatedObject(token, opts, where) {
88
110
  const refName = token.refName ?? "";
89
111
  const kind = token.__kind === "element" ? "element" : token.__kind === "task" ? "task" : "app";
90
112
  if (kind === (opts.scope ?? "app") && refName === opts.appRefName) {
91
- return { value: opts.objectId, refName, kind, target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel } };
113
+ return {
114
+ value: opts.objectId,
115
+ refName,
116
+ kind,
117
+ target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
118
+ fieldOwnership: opts.fieldOwnership,
119
+ };
92
120
  }
93
121
  const sibling = kind !== "task" ? opts.workspaceAspects?.get(workspaceAspectKey(kind, refName)) : undefined;
94
122
  if (sibling !== undefined) {
95
123
  const resourceType = kind === "element" ? "elementum_element" : "elementum_app";
96
- return { value: expr.resourceAttr(resourceType, sibling.tfLabel, ["id"]), refName, kind, target: sibling };
124
+ return {
125
+ value: expr.resourceAttr(resourceType, sibling.tfLabel, ["id"]),
126
+ refName,
127
+ kind,
128
+ target: sibling,
129
+ fieldOwnership: workspaceFieldOwnership(sibling),
130
+ };
97
131
  }
98
132
  const name = token.name ?? refName;
99
133
  if (name === "") {
@@ -167,7 +201,7 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
167
201
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" resolves to table "${object.target.tfLabel}" — tables expose columns, not fields; dropped`);
168
202
  return undefined;
169
203
  }
170
- const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind);
204
+ const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind, object.fieldOwnership);
171
205
  if (value === undefined) {
172
206
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(token.fieldType ?? "")}); dropped`);
173
207
  }
@@ -178,16 +212,10 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
178
212
  return undefined;
179
213
  }
180
214
  const name = token.name ?? refName;
181
- // Match ei export and every other object-scoped field lookup: the label is
182
- // based on the provider root type + the ACTUAL root lookup label + field
183
- // display name. Re-deriving it from the public refName produces a second,
184
- // semantically identical data block when (for example) a relationship and
185
- // a dynamic Dropdown both reference the same foreign field.
186
- const ownerType = object.kind === "element" ? "elementum_element" : object.kind === "app" ? "elementum_app" : object.kind === "task" ? "elementum_task" : undefined;
187
215
  const parentLabel = object.foreignTfLabel ?? (token.parent !== undefined ? tsLabelToTfLabel(token.parent) : "related");
188
- const tfLabel = ownerType === undefined
189
- ? sanitizeName(`${parentLabel}_${name}`)
190
- : sanitizeName(`${ownerType}_${parentLabel}_${name}`);
216
+ const tfLabel = object.kind === "element" || object.kind === "app" || object.kind === "task"
217
+ ? foreignFieldDataLabel(object.kind, parentLabel, name)
218
+ : sanitizeName(`${parentLabel}_${name}`);
191
219
  opts.orgRefs.foreignField("elementum_field", tfLabel, object.value, name);
192
220
  return expr.dataAttr("elementum_field", tfLabel, ["id"]);
193
221
  }
@@ -219,7 +247,7 @@ function stageOrgRefs(real) {
219
247
  foreignApp: (tfLabel, name, namespace) => pending.push(() => real.foreignApp(tfLabel, name, namespace)),
220
248
  foreignTask: (tfLabel, name, namespace) => pending.push(() => real.foreignTask(tfLabel, name, namespace)),
221
249
  foreignElement: (tfLabel, name, namespace) => pending.push(() => real.foreignElement(tfLabel, name, namespace)),
222
- foreignField: (type, tfLabel, objectId, name) => pending.push(() => real.foreignField(type, tfLabel, objectId, name)),
250
+ foreignField: (type, tfLabel, objectId, name, extraAttrs) => pending.push(() => real.foreignField(type, tfLabel, objectId, name, extraAttrs)),
223
251
  };
224
252
  return { orgRefs, commit: () => { for (const apply of pending)
225
253
  apply(); } };
@@ -260,7 +288,13 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
260
288
  // field's own app/element) — a cascading-parent trigger, not a field
261
289
  // on relatedAspectId's target. See `AppField.parentField`'s doc
262
290
  // comment (the sibling STATIC mechanism this mirrors).
263
- const owner = { value: opts.objectId, refName: opts.appRefName, kind: opts.scope ?? "app", target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel } };
291
+ const owner = {
292
+ value: opts.objectId,
293
+ refName: opts.appRefName,
294
+ kind: opts.scope ?? "app",
295
+ target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
296
+ fieldOwnership: opts.fieldOwnership,
297
+ };
264
298
  const parentFieldId = resolveFieldOnObject(cfg.parentFieldId, owner, opts_, where, "parentFieldId");
265
299
  if (parentFieldId === undefined)
266
300
  return undefined;
@@ -297,8 +331,23 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
297
331
  attrs["values_render_type"] = cfg.valuesRenderType;
298
332
  if (cfg.filter !== undefined) {
299
333
  let unresolvedField = false;
334
+ const owner = {
335
+ value: opts.objectId,
336
+ refName: opts.appRefName,
337
+ kind: opts.scope ?? "app",
338
+ target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
339
+ fieldOwnership: opts.fieldOwnership,
340
+ };
300
341
  try {
301
342
  const filterValue = filterWireToTfCodec(cfg.filter, {
343
+ recordField: (token) => {
344
+ const value = resolveFieldOnObject(token, owner, opts_, where, "filter record field");
345
+ if (value === undefined) {
346
+ unresolvedField = true;
347
+ return "";
348
+ }
349
+ return value;
350
+ },
302
351
  field: (token) => {
303
352
  const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
304
353
  if (value === undefined) {
@@ -342,6 +391,7 @@ function resolveDynamicMappingFieldOwner(token, opts, where) {
342
391
  refName: opts.appRefName,
343
392
  kind: opts.scope ?? "app",
344
393
  target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
394
+ fieldOwnership: opts.fieldOwnership,
345
395
  };
346
396
  }
347
397
  if (token.parent === undefined || token.parentKind === undefined) {
@@ -388,6 +438,7 @@ function buildStaticPicklistConfigAttr(cfg, opts, where) {
388
438
  refName: opts.appRefName,
389
439
  kind: opts.scope ?? "app",
390
440
  target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
441
+ fieldOwnership: opts.fieldOwnership,
391
442
  };
392
443
  if (cfg.parentFieldId !== undefined) {
393
444
  const parentFieldId = resolveFieldOnObject(cfg.parentFieldId, owner, opts, where, "parentFieldId");
@@ -406,6 +457,28 @@ function buildStaticPicklistConfigAttr(cfg, opts, where) {
406
457
  return attrs;
407
458
  }
408
459
  /** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
460
+ /** Field resources whose provider schema has no `default_value`; the platform default for these is an option/record id the provider does not manage. */
461
+ const NO_DEFAULT_VALUE_RESOURCES = new Map([
462
+ ["elementum_dropdown_field", "Dropdown"],
463
+ ["elementum_multiselect_field", "Multi-select"],
464
+ ["elementum_relation_field", "Relation"],
465
+ ["elementum_attachment_field", "Attachment"],
466
+ ]);
467
+ /**
468
+ * Field display names must be unique within an app or element. The platform rejects the second one only at
469
+ * apply ("Duplicate key found.", naming neither field) after the rest of the apply has landed, so fail the build
470
+ * first and name both fields.
471
+ */
472
+ export function claimFieldDisplayName(seen, field) {
473
+ const name = field.block.attrs["name"];
474
+ if (typeof name !== "string")
475
+ return;
476
+ const prior = seen.get(name);
477
+ if (prior !== undefined) {
478
+ throw new EntityTfError(`fields.${field.bagKey} and fields.${prior} both have the display name ${JSON.stringify(name)}; field display names must be unique within an app or element`);
479
+ }
480
+ seen.set(name, field.bagKey);
481
+ }
409
482
  export function fieldToTf(typeKey, inner, opts) {
410
483
  const { ownerTfLabel, scope = "app", objectId, diagnostics } = opts;
411
484
  const name = inner.name ?? "";
@@ -482,7 +555,7 @@ export function fieldToTf(typeKey, inner, opts) {
482
555
  if (typeof include.picklist === "object" && include.picklist !== null) {
483
556
  const field = include.picklist.picklistFieldId;
484
557
  if (field?.refName !== undefined) {
485
- const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope);
558
+ const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope, opts.fieldOwnership);
486
559
  if (value !== undefined) {
487
560
  attrs["include_type"] = "PICKLIST";
488
561
  attrs["picklist_field_id"] = value;
@@ -505,7 +578,10 @@ export function fieldToTf(typeKey, inner, opts) {
505
578
  if (subType.typeKey === "calculated" && inner.defaultValue !== undefined) {
506
579
  diagnostics.push(`field "${name}": calculated fields do not support defaultValue; dropped`);
507
580
  }
508
- if (subType.typeKey !== "calculated" && inner.defaultValue !== undefined) {
581
+ else if (NO_DEFAULT_VALUE_RESOURCES.has(subType.resourceType) && inner.defaultValue !== undefined) {
582
+ diagnostics.push(`field "${name}": ${NO_DEFAULT_VALUE_RESOURCES.get(subType.resourceType)} fields cannot set defaultValue; defaultValue dropped`);
583
+ }
584
+ if (subType.typeKey !== "calculated" && !NO_DEFAULT_VALUE_RESOURCES.has(subType.resourceType) && inner.defaultValue !== undefined) {
509
585
  const orgRef = asOrgFieldRef(inner.defaultValue);
510
586
  if (orgRef !== undefined) {
511
587
  if (opts.orgRefs === undefined) {
@@ -529,6 +605,16 @@ export function fieldToTf(typeKey, inner, opts) {
529
605
  if (inner.tags !== undefined && inner.tags.length > 0) {
530
606
  attrs["field_role"] = [...inner.tags];
531
607
  }
608
+ if (inner.mediaTypes !== undefined) {
609
+ if (subType.typeKey !== "attachment") {
610
+ diagnostics.push(`field "${name}": mediaTypes is only valid on attachment fields; dropped`);
611
+ }
612
+ else {
613
+ const mediaTypes = attachmentMediaTypes(inner.mediaTypes, diagnostics, name);
614
+ if (mediaTypes !== undefined)
615
+ attrs["media_types"] = mediaTypes;
616
+ }
617
+ }
532
618
  if (typeKey === "decimal" && inner.decimalPlaces !== undefined) {
533
619
  if (attrs["decimal_places"] !== undefined && attrs["decimal_places"] !== inner.decimalPlaces) {
534
620
  diagnostics.push(`field "${name}": decimalPlaces conflicts with numericFormat.decimalPlaces; decimalPlaces wins`);
@@ -622,6 +708,26 @@ export function fieldToTf(typeKey, inner, opts) {
622
708
  const block = { kind: "resource", type: subType.resourceType, label: tfLabel, attrs };
623
709
  return { block, bagKey, address: `${subType.resourceType}.${tfLabel}` };
624
710
  }
711
+ /**
712
+ * Attachment `media_types`. An unset or empty list stays omitted so a field
713
+ * without a restriction keeps its previous HCL. A value that is not
714
+ * `type/subtype` drops the attribute rather than emitting a list that
715
+ * matches no upload.
716
+ */
717
+ function attachmentMediaTypes(value, diagnostics, name) {
718
+ if (!Array.isArray(value)) {
719
+ diagnostics.push(`field "${name}": mediaTypes must be a list of MIME types; dropped`);
720
+ return undefined;
721
+ }
722
+ const badAt = value.findIndex((entry) => !isAttachmentMediaType(entry));
723
+ if (badAt !== -1) {
724
+ diagnostics.push(`field "${name}": mediaTypes entry ${JSON.stringify(value[badAt])} is not a MIME type (expected type/subtype); dropped`);
725
+ return undefined;
726
+ }
727
+ if (value.length === 0)
728
+ return undefined;
729
+ return [...value];
730
+ }
625
731
  function scalarOrUndefined(v) {
626
732
  return typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? v : undefined;
627
733
  }
@@ -639,16 +745,30 @@ function scalarOrUndefined(v) {
639
745
  * diagnostic wording since the two failure cases usually read differently
640
746
  * at each call site.
641
747
  */
642
- /** Elements only have `id`/`title` as real system fields (no status/stage/audit fields) — see `element/locals.ts`. */
643
- const ELEMENT_SYSTEM_FIELD_KEYS = new Set(["id", "title"]);
644
- export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldAddresses) {
748
+ /**
749
+ * Element system fields resolve through their `element/locals.ts` locals.
750
+ * Elements have no status/stage fields; the audit fields exist only on some
751
+ * elements, which the build checks against `systemFields.audit`. An element
752
+ * may author its own field under an audit key (`createdAt: dateTimeField(…)`),
753
+ * which shadows the audit field, so a key in `fieldAddresses` is that field.
754
+ */
755
+ const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
756
+ const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
757
+ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldOwnership) {
645
758
  if (!isCanonicalTsLabel(refName))
646
759
  return undefined;
647
- const isSystemField = scope === "element" ? ELEMENT_SYSTEM_FIELD_KEYS.has(refName) : SYSTEM_FIELD_KEY_SET.has(refName);
760
+ if (scope === "element" &&
761
+ ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET.has(refName) &&
762
+ fieldOwnership === undefined) {
763
+ throw new EntityTfError(`element field "${refName}" requires authored-field ownership metadata to distinguish a custom field from the platform audit field`);
764
+ }
765
+ const isSystemField = scope === "element"
766
+ ? ELEMENT_SYSTEM_FIELD_KEY_SET.has(refName) && !(ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET.has(refName) && fieldOwnership?.has(refName) === true)
767
+ : SYSTEM_FIELD_KEY_SET.has(refName);
648
768
  if (isSystemField) {
649
769
  return expr.local(`${ownerTfLabel}_${tsLabelToTfLabel(refName)}_field_id`);
650
770
  }
651
- const knownAddress = fieldAddresses?.get(refName);
771
+ const knownAddress = fieldOwnership?.get?.(refName);
652
772
  if (knownAddress !== undefined) {
653
773
  const dotIndex = knownAddress.indexOf(".");
654
774
  if (dotIndex !== -1) {
@@ -151,14 +151,22 @@ export function fileReaderFromTf(block, appTfLabel, _ctx) {
151
151
  const fields = parseExcelFields(attrs.fields ?? [], where);
152
152
  // document_content/document_name/file_type are never returned by
153
153
  // Read() on an already-imported resource (the provider's schema docs
154
- // say so), yet ei's export still emits placeholders for them - even
154
+ // say so), and older exports emitted placeholders for them - even
155
155
  // document_content's empty-string placeholder counts as a change on
156
- // this always-forces-replacement attribute, so reproducing any of the
157
- // three plans a spurious destroy+recreate. Never extract them; the
158
- // printer leaves a comment for anyone authoring a genuinely NEW reader.
159
- // Adoption separately strips these placeholders from `.tf/in/` itself
156
+ // this always-forces-replacement attribute, so reproducing them plans a
157
+ // spurious destroy+recreate. Only a real document is extracted: one a
158
+ // re-pull filled from this workspace's own state
159
+ // (alignExportWithState), which is what the reader holds.
160
+ // Adoption separately strips these attributes from `.tf/in/` itself
160
161
  // (stripUnrecoverableExcelFileReaderAttrs in engine/adopt/adopt.ts),
161
162
  // since its gate plans against ei's raw export, not this extractor.
163
+ const document = typeof attrs.document_content === "string" && attrs.document_content !== ""
164
+ ? {
165
+ documentContent: attrs.document_content,
166
+ ...(typeof attrs.document_name === "string" && { documentName: attrs.document_name }),
167
+ ...(typeof attrs.file_type === "string" && { fileType: attrs.file_type }),
168
+ }
169
+ : {};
162
170
  return {
163
171
  fileReader: {
164
172
  refName,
@@ -167,6 +175,7 @@ export function fileReaderFromTf(block, appTfLabel, _ctx) {
167
175
  name,
168
176
  firstRowIsHeader: attrs.first_row_is_header,
169
177
  fields,
178
+ ...document,
170
179
  },
171
180
  },
172
181
  };
@@ -87,6 +87,7 @@ export const fileReaderModule = {
87
87
  key: t.typeKey,
88
88
  resourceType: t.resourceType,
89
89
  implemented: t.implemented === true,
90
+ ...(t.unreadableAttributes !== undefined && { unreadableAttributes: t.unreadableAttributes }),
90
91
  })),
91
92
  },
92
93
  data: { participates: true, resourceType: "elementum_ai_file_reader", lookupAttr: "name", referencedByBuild: false },
@@ -21,6 +21,8 @@ export interface FileReaderSubType {
21
21
  readonly resourceType: string;
22
22
  /** Round-trips on the terraform path (to-tf + from-tf + printer). */
23
23
  readonly implemented?: true;
24
+ /** Attributes the platform never returns on read; a re-pull fills them from state. */
25
+ readonly unreadableAttributes?: readonly string[];
24
26
  }
25
27
  export declare const FILE_READER_SUB_TYPES: readonly FileReaderSubType[];
26
28
  export declare const FILE_READER_SUB_TYPE_BY_TYPE_KEY: ReadonlyMap<string, FileReaderSubType>;
@@ -15,7 +15,7 @@
15
15
  * provider's `values` attribute.
16
16
  */
17
17
  export const FILE_READER_SUB_TYPES = [
18
- { typeKey: "excel", resourceType: "elementum_excel_file_reader", implemented: true },
18
+ { typeKey: "excel", resourceType: "elementum_excel_file_reader", implemented: true, unreadableAttributes: ["document_content", "document_name", "file_type"] },
19
19
  { typeKey: "json", resourceType: "elementum_json_file_reader", implemented: true },
20
20
  { typeKey: "text", resourceType: "elementum_text_file_reader", implemented: true },
21
21
  { typeKey: "xml", resourceType: "elementum_xml_file_reader", implemented: true },
@@ -0,0 +1,26 @@
1
+ import { type ViewRef } from "../../catalog/index.js";
2
+ import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
3
+ /** One portal menu entry: a managed view under its own slug. */
4
+ export interface PortalMenuItem {
5
+ readonly view: ViewRef;
6
+ readonly slug: string;
7
+ /** Menu text; the platform shows the view's name when omitted. */
8
+ readonly label?: string;
9
+ /** Opens this view when the portal opens. At most one item. */
10
+ readonly home?: boolean;
11
+ }
12
+ export interface DefinePortalOptions extends EntityDeployOptions {
13
+ readonly name: string;
14
+ readonly slug: string;
15
+ /** Once set, the platform can change it but not clear it. */
16
+ readonly description?: string;
17
+ /** Once set, the platform can change it but not clear it. */
18
+ readonly icon?: string;
19
+ /** Once set, the platform can change it but not clear it. */
20
+ readonly color?: string;
21
+ readonly menu?: readonly PortalMenuItem[];
22
+ }
23
+ export interface PortalConfigured {
24
+ def(refName: string): DeployableEntity;
25
+ }
26
+ export declare function portal(opts: DefinePortalOptions): PortalConfigured;
@@ -0,0 +1,37 @@
1
+ import { slimTokens } from "../../catalog/index.js";
2
+ // View names aren't unique, so a catalog view is identified by its owner, bag
3
+ // and key; only a viewRef outside the workspace falls back to its name.
4
+ const viewKey = (view) => view.viewType !== undefined
5
+ ? `${view.parentKind ?? "app"}:${view.parent}:${view.viewType}:${view.refName}`
6
+ : `${view.parentKind ?? "app"}:${view.parentNamespace ?? view.parent}:${view.name}`;
7
+ export function portal(opts) {
8
+ const where = `portal ${JSON.stringify(opts.name)}`;
9
+ if (opts.name.trim() === "")
10
+ throw new Error("portal requires a non-empty name.");
11
+ if (opts.slug.trim() === "")
12
+ throw new Error(`${where}: slug is required.`);
13
+ for (const key of ["description", "icon", "color"]) {
14
+ if (opts[key]?.trim() === "")
15
+ throw new Error(`${where}: ${key} can't be empty; leave it out instead.`);
16
+ }
17
+ const menu = opts.menu ?? [];
18
+ const slugs = new Set();
19
+ const views = new Set();
20
+ for (const item of menu) {
21
+ if (item.slug.trim() === "")
22
+ throw new Error(`${where}: menu item for view ${JSON.stringify(item.view.name)} needs a slug.`);
23
+ if (item.label?.trim() === "")
24
+ throw new Error(`${where}: menu item ${JSON.stringify(item.slug)} has an empty label; leave it out to show the view's name.`);
25
+ if (slugs.has(item.slug))
26
+ throw new Error(`${where}: menu slug ${JSON.stringify(item.slug)} is used twice.`);
27
+ if (views.has(viewKey(item.view)))
28
+ throw new Error(`${where}: view ${JSON.stringify(item.view.name)} is in the menu twice.`);
29
+ slugs.add(item.slug);
30
+ views.add(viewKey(item.view));
31
+ }
32
+ if (menu.filter((item) => item.home === true).length > 1)
33
+ throw new Error(`${where}: only one menu item can be the homepage.`);
34
+ return { def(refName) {
35
+ return { kind: "portal", parent: "org", refName, payload: slimTokens(opts), ...(opts.enabled !== undefined ? { enabled: opts.enabled } : {}) };
36
+ } };
37
+ }
@@ -0,0 +1,27 @@
1
+ import { type FromTfContext } from "../../engine/pull/context.js";
2
+ import { type TfBlock } from "../../engine/tf/index.js";
3
+ /** A view's owner as the export looks it up: an app or element by namespace, a task by name. */
4
+ export type PortalViewOwner = {
5
+ readonly kind: "app" | "element";
6
+ readonly namespace: string;
7
+ } | {
8
+ readonly kind: "task";
9
+ readonly name: string;
10
+ };
11
+ export interface NormalizedPortalItem {
12
+ readonly owner: PortalViewOwner;
13
+ readonly viewName: string;
14
+ readonly slug: string;
15
+ readonly label?: string;
16
+ readonly home?: true;
17
+ }
18
+ export interface NormalizedPortal {
19
+ readonly refName: string;
20
+ readonly name: string;
21
+ readonly slug: string;
22
+ readonly description?: string;
23
+ readonly icon?: string;
24
+ readonly color?: string;
25
+ readonly items: readonly NormalizedPortalItem[];
26
+ }
27
+ export declare function portalFromTf(block: TfBlock, ctx: FromTfContext): NormalizedPortal;
@@ -0,0 +1,75 @@
1
+ import { optionalBoolean, optionalString, plainObject } from "../../engine/pull/context.js";
2
+ import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
3
+ import { VIEW_DATA_RESOURCE_TYPE } from "../view/types.js";
4
+ import { PORTAL_RESOURCE_TYPE } from "./types.js";
5
+ function ownerOf(type, attrs) {
6
+ const namespace = attrs?.["namespace"];
7
+ const name = attrs?.["name"];
8
+ if (type === "elementum_app" && typeof namespace === "string")
9
+ return { kind: "app", namespace };
10
+ if (type === "elementum_element" && typeof namespace === "string")
11
+ return { kind: "element", namespace };
12
+ if (type === "elementum_task" && typeof name === "string")
13
+ return { kind: "task", name };
14
+ return undefined;
15
+ }
16
+ const KNOWN = new Set(["id", "url", "name", "slug", "description", "icon", "color", "menu_item"]);
17
+ const KNOWN_ITEM = new Set(["view_id", "slug", "label", "home"]);
18
+ /** A menu view reaches the portal as `data.elementum_view.<label>.id`, whose owner is itself a lookup. */
19
+ function viewOf(value, where, ctx) {
20
+ if (value === undefined || !isTfExpr(value) || value.$expr !== "data-attr" || value.type !== VIEW_DATA_RESOURCE_TYPE) {
21
+ throw new Error(`${where}: view_id must reference data.${VIEW_DATA_RESOURCE_TYPE}, got ${JSON.stringify(value)}`);
22
+ }
23
+ const view = ctx.dataAttrs?.(VIEW_DATA_RESOURCE_TYPE, value.label);
24
+ const viewName = view?.["name"];
25
+ const owner = view?.["owner_id"];
26
+ if (typeof viewName !== "string" || owner === undefined || !isTfExpr(owner) || owner.$expr !== "data-attr") {
27
+ throw new Error(`${where}: data.${VIEW_DATA_RESOURCE_TYPE}.${value.label} needs a name and an owner_id lookup`);
28
+ }
29
+ const viewOwner = ownerOf(owner.type, ctx.dataAttrs?.(owner.type, owner.label));
30
+ if (viewOwner === undefined) {
31
+ throw new Error(`${where}: the owner of view ${JSON.stringify(viewName)} must be an app or element looked up by namespace, or a task looked up by name`);
32
+ }
33
+ return { owner: viewOwner, viewName };
34
+ }
35
+ export function portalFromTf(block, ctx) {
36
+ if (block.type !== PORTAL_RESOURCE_TYPE || !block.label)
37
+ throw new Error(`expected ${PORTAL_RESOURCE_TYPE}`);
38
+ const where = `portal ${block.label}`;
39
+ for (const key of Object.keys(block.attrs))
40
+ if (!KNOWN.has(key))
41
+ ctx.diagnostics.push(`${block.type}.${block.label}: unhandled attribute ${key}`);
42
+ const rawItems = block.attrs["menu_item"];
43
+ const items = (Array.isArray(rawItems) ? rawItems : []).map((raw, index) => {
44
+ const itemWhere = `${where} menu_item[${index}]`;
45
+ const item = plainObject(raw);
46
+ if (item === undefined)
47
+ throw new Error(`${itemWhere}: expected an object`);
48
+ for (const key of Object.keys(item))
49
+ if (!KNOWN_ITEM.has(key))
50
+ ctx.diagnostics.push(`${itemWhere}: unhandled attribute ${key}`);
51
+ const slug = optionalString(item, "slug", itemWhere, ctx);
52
+ if (slug === undefined)
53
+ throw new Error(`${itemWhere}: slug is required`);
54
+ const label = optionalString(item, "label", itemWhere, ctx);
55
+ return {
56
+ ...viewOf(item["view_id"], itemWhere, ctx),
57
+ slug,
58
+ ...(label !== undefined && { label }),
59
+ ...(optionalBoolean(item, "home", itemWhere, ctx) === true && { home: true }),
60
+ };
61
+ });
62
+ const optional = (key) => {
63
+ const value = optionalString(block.attrs, key, where, ctx);
64
+ return value !== undefined ? { [key]: value } : {};
65
+ };
66
+ return {
67
+ refName: tfLabelToTsLabel(block.label),
68
+ name: optionalString(block.attrs, "name", where, ctx) ?? "",
69
+ slug: optionalString(block.attrs, "slug", where, ctx) ?? "",
70
+ ...optional("description"),
71
+ ...optional("icon"),
72
+ ...optional("color"),
73
+ items,
74
+ };
75
+ }
@@ -0,0 +1 @@
1
+ export { portal, type DefinePortalOptions, type PortalConfigured, type PortalMenuItem } from "./build.js";
@@ -0,0 +1 @@
1
+ export { portal } from "./build.js";
@@ -0,0 +1,3 @@
1
+ import { type EntityKindModule } from "../../graph/types.js";
2
+ /** An org-level portal: `portals/<ref>/<ref>.ts`, labelled by its refName. */
3
+ export declare const portalModule: EntityKindModule;
@@ -0,0 +1,28 @@
1
+ import { tsLabelToTfLabel } from "../../engine/tf/index.js";
2
+ import { NO_CATALOG } from "../../graph/types.js";
3
+ import { portalFromTf } from "./from-tf.js";
4
+ import { portalToTf } from "./to-tf.js";
5
+ import { PORTAL_RESOURCE_TYPE } from "./types.js";
6
+ function extract(stream, ctx) {
7
+ const blocks = stream.byKind.get("portal") ?? [];
8
+ if (blocks.length !== 1)
9
+ throw new Error(`expected exactly one ${PORTAL_RESOURCE_TYPE}, found ${blocks.length}`);
10
+ return { instance: portalFromTf(blocks[0], ctx) };
11
+ }
12
+ /** An org-level portal: `portals/<ref>/<ref>.ts`, labelled by its refName. */
13
+ export const portalModule = {
14
+ kind: "portal", stream: { role: "streamRoot", exportVerb: "portals" }, authoring: { unit: "ownFile", bag: "portals" }, parents: [{ parent: "org", child: "portal" }],
15
+ resource: { shape: "single", resourceType: PORTAL_RESOURCE_TYPE, adoptable: true },
16
+ data: { participates: false },
17
+ lifecycle: {
18
+ participates: true,
19
+ extractStreamRoot: extract,
20
+ toTf: (entity, ctx) => portalToTf(entity, {
21
+ tfLabel: tsLabelToTfLabel(entity.refName),
22
+ orgRefs: ctx.orgRefs,
23
+ diagnostics: ctx.diagnostics,
24
+ ...(ctx.workspaceAspects !== undefined && { workspaceAspects: ctx.workspaceAspects }),
25
+ }),
26
+ },
27
+ canvas: { participates: true, label: "Portals", glyph: "▦", component: "appDetail" }, catalog: NO_CATALOG,
28
+ };
@@ -0,0 +1,12 @@
1
+ import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
2
+ import { type DeployableEntity } from "../../engine/entity.js";
3
+ import { type TfBlock } from "../../engine/tf/index.js";
4
+ export interface PortalToTfContext {
5
+ readonly tfLabel: string;
6
+ readonly orgRefs: OrgRefLookup;
7
+ readonly diagnostics: string[];
8
+ readonly workspaceAspects?: ReadonlyMap<string, Pick<WorkspaceAspect, "tfLabel">>;
9
+ }
10
+ export declare function portalToTf(entity: DeployableEntity, ctx: PortalToTfContext): {
11
+ blocks: readonly TfBlock[];
12
+ };
@@ -0,0 +1,73 @@
1
+ import { workspaceAspectKey } from "../../engine/build/context.js";
2
+ import { EntityTfError } from "../../engine/entity.js";
3
+ import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
4
+ import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, VIEW_DATA_RESOURCE_TYPE, } from "../view/types.js";
5
+ import { PORTAL_RESOURCE_TYPE } from "./types.js";
6
+ const VIEW_RESOURCE_BY_TYPE = {
7
+ list: LIST_VIEW_RESOURCE_TYPE,
8
+ calendar: CALENDAR_VIEW_RESOURCE_TYPE,
9
+ kanban: KANBAN_VIEW_RESOURCE_TYPE,
10
+ dashboard: DASHBOARD_VIEW_RESOURCE_TYPE,
11
+ agent: AGENT_VIEW_RESOURCE_TYPE,
12
+ custom: CUSTOM_VIEW_RESOURCE_TYPE,
13
+ };
14
+ /**
15
+ * A catalog view whose owner is built in this workspace is referenced as a
16
+ * resource, so the portal is created after it. Any other view is looked up by
17
+ * its owner's namespace and its name; without a namespace it can't be found.
18
+ */
19
+ function viewIdOf(view, ctx) {
20
+ const ownerKind = view.parentKind ?? "app";
21
+ const resourceType = view.viewType !== undefined ? VIEW_RESOURCE_BY_TYPE[view.viewType] : undefined;
22
+ const sibling = resourceType !== undefined ? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, view.parent)) : undefined;
23
+ if (resourceType !== undefined && sibling !== undefined) {
24
+ if (!isCanonicalTsLabel(view.refName))
25
+ return { problem: `view ${JSON.stringify(view.name)} has no catalog key; use catalog.<app>.views.<view>` };
26
+ return { id: expr.resourceAttr(resourceType, scopedResourceLabel(sibling.tfLabel, tsLabelToTfLabel(view.refName), ownerKind), ["id"]) };
27
+ }
28
+ if (view.parentNamespace === undefined) {
29
+ return { problem: `view ${JSON.stringify(view.name)} names owner ${JSON.stringify(view.parent)}, which is not in this workspace; use viewRef({ name, parentKind, parentNamespace })` };
30
+ }
31
+ const owner = ctx.orgRefs.resolveForeignRoot(ownerKind, {
32
+ name: view.parentName ?? view.parentNamespace,
33
+ namespace: view.parentNamespace,
34
+ tfLabel: sanitizeName(view.parentNamespace),
35
+ });
36
+ const label = `${owner.tfLabel}_${sanitizeName(view.name)}`;
37
+ ctx.orgRefs.rawLookup(VIEW_DATA_RESOURCE_TYPE, label, view.name, { owner_id: expr.dataAttr(owner.resourceType, owner.tfLabel, ["id"]) });
38
+ return { id: expr.dataAttr(VIEW_DATA_RESOURCE_TYPE, label, ["id"]) };
39
+ }
40
+ export function portalToTf(entity, ctx) {
41
+ if (entity.kind !== "portal")
42
+ throw new EntityTfError(`portalToTf expects portal; got ${entity.kind}`);
43
+ const p = entity.payload;
44
+ if (p === null || !p.name || !p.slug)
45
+ throw new EntityTfError(`portal ${entity.refName}: name and slug are required`);
46
+ const attrs = { name: p.name, slug: p.slug };
47
+ if (p.description !== undefined)
48
+ attrs["description"] = p.description;
49
+ if (p.icon !== undefined)
50
+ attrs["icon"] = p.icon;
51
+ if (p.color !== undefined)
52
+ attrs["color"] = p.color;
53
+ // The menu list is the whole desired menu: an item left out would be removed
54
+ // from the portal, so an item that can't be emitted fails the build.
55
+ const items = (p.menu ?? []).map((item) => {
56
+ if (item.view === undefined || item.slug === undefined) {
57
+ throw new EntityTfError(`portal ${JSON.stringify(p.name)}: a menu item has no view or slug`);
58
+ }
59
+ const view = viewIdOf(item.view, ctx);
60
+ if ("problem" in view) {
61
+ throw new EntityTfError(`portal ${JSON.stringify(p.name)}: menu item ${JSON.stringify(item.slug)}: ${view.problem}`);
62
+ }
63
+ return {
64
+ view_id: view.id,
65
+ slug: item.slug,
66
+ ...(item.label !== undefined && { label: item.label }),
67
+ ...(item.home === true && { home: true }),
68
+ };
69
+ });
70
+ if (items.length > 0)
71
+ attrs["menu_item"] = items;
72
+ return { blocks: [{ kind: "resource", type: PORTAL_RESOURCE_TYPE, label: ctx.tfLabel, attrs }] };
73
+ }
@@ -0,0 +1 @@
1
+ export declare const PORTAL_RESOURCE_TYPE = "elementum_portal";