@elementumai/edk 0.9.19 → 0.10.1

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 (240) hide show
  1. package/README.md +159 -7
  2. package/dist-sdk/src/catalog/factories.d.ts +33 -2
  3. package/dist-sdk/src/catalog/factories.js +40 -1
  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 +11 -0
  10. package/dist-sdk/src/catalog/types.d.ts +40 -1
  11. package/dist-sdk/src/catalog/types.js +12 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +40 -4
  13. package/dist-sdk/src/core/triggers/on-demand.js +17 -2
  14. package/dist-sdk/src/core/types/app.d.ts +2 -2
  15. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +86 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +156 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +169 -0
  19. package/dist-sdk/src/engine/ei/run.js +1219 -0
  20. package/dist-sdk/src/engine/logging.d.ts +17 -0
  21. package/dist-sdk/src/engine/logging.js +18 -0
  22. package/dist-sdk/src/engine/pull/catalog-ref.d.ts +16 -0
  23. package/dist-sdk/src/engine/pull/catalog-ref.js +24 -0
  24. package/dist-sdk/src/engine/pull/context.d.ts +68 -6
  25. package/dist-sdk/src/engine/pull/context.js +40 -1
  26. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +8 -0
  27. package/dist-sdk/src/engine/pull/procedure-refs.js +28 -0
  28. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  29. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  30. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  31. package/dist-sdk/src/engine/pull/result-output.js +113 -3
  32. package/dist-sdk/src/engine/tf/expr.js +1 -1
  33. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  34. package/dist-sdk/src/engine/tf/index.js +1 -1
  35. package/dist-sdk/src/engine/tf/labels.d.ts +28 -5
  36. package/dist-sdk/src/engine/tf/labels.js +54 -3
  37. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  38. package/dist-sdk/src/engine/tf/parse.js +93 -4
  39. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  40. package/dist-sdk/src/engine/tf/render.js +41 -7
  41. package/dist-sdk/src/engine/validation.d.ts +44 -0
  42. package/dist-sdk/src/engine/validation.js +95 -0
  43. package/dist-sdk/src/entities/access-policy/from-tf.js +38 -1
  44. package/dist-sdk/src/entities/access-policy/principal.d.ts +2 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  46. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  47. package/dist-sdk/src/entities/agent/build.js +40 -5
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -0
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +46 -21
  50. package/dist-sdk/src/entities/agent/from-tf.js +11 -3
  51. package/dist-sdk/src/entities/agent/module.js +2 -0
  52. package/dist-sdk/src/entities/agent/to-tf.js +20 -6
  53. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +10 -1
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +18 -6
  55. package/dist-sdk/src/entities/agent-tool/module.js +3 -0
  56. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  57. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  58. package/dist-sdk/src/entities/app/auto-share.d.ts +38 -0
  59. package/dist-sdk/src/entities/app/auto-share.js +49 -0
  60. package/dist-sdk/src/entities/app/build.d.ts +105 -22
  61. package/dist-sdk/src/entities/app/build.js +107 -10
  62. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  63. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  64. package/dist-sdk/src/entities/app/from-tf.js +11 -2
  65. package/dist-sdk/src/entities/app/index.d.ts +7 -6
  66. package/dist-sdk/src/entities/app/index.js +2 -8
  67. package/dist-sdk/src/entities/app/module.js +5 -2
  68. package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
  69. package/dist-sdk/src/entities/app/to-tf.js +40 -13
  70. package/dist-sdk/src/entities/automation/build.d.ts +56 -6
  71. package/dist-sdk/src/entities/automation/build.js +230 -26
  72. package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
  73. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +41 -5
  74. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +470 -58
  75. package/dist-sdk/src/entities/automation/from-tf.d.ts +37 -8
  76. package/dist-sdk/src/entities/automation/from-tf.js +791 -131
  77. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  78. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  79. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  80. package/dist-sdk/src/entities/automation/index.js +1 -1
  81. package/dist-sdk/src/entities/automation/module.d.ts +3 -0
  82. package/dist-sdk/src/entities/automation/module.js +107 -15
  83. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  84. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  85. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  86. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  87. package/dist-sdk/src/entities/automation/script-code.d.ts +20 -0
  88. package/dist-sdk/src/entities/automation/script-code.js +109 -5
  89. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  90. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +39 -0
  91. package/dist-sdk/src/entities/automation/task-output-labels.js +85 -0
  92. package/dist-sdk/src/entities/automation/tasks.d.ts +116 -22
  93. package/dist-sdk/src/entities/automation/tasks.js +86 -24
  94. package/dist-sdk/src/entities/automation/to-tf.d.ts +24 -3
  95. package/dist-sdk/src/entities/automation/to-tf.js +1082 -132
  96. package/dist-sdk/src/entities/automation/triggers.d.ts +12 -6
  97. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  98. package/dist-sdk/src/entities/automation/types.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/types.js +19 -0
  100. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +1 -1
  101. package/dist-sdk/src/entities/automation/value-ref-tf.js +1 -1
  102. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  103. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  104. package/dist-sdk/src/entities/data-lookup/module.js +2 -0
  105. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -5
  108. package/dist-sdk/src/entities/element/build.d.ts +28 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +62 -1
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  113. package/dist-sdk/src/entities/element/index.js +1 -0
  114. package/dist-sdk/src/entities/element/module.js +9 -3
  115. package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
  116. package/dist-sdk/src/entities/element/to-tf.js +16 -16
  117. package/dist-sdk/src/entities/field/build.d.ts +17 -3
  118. package/dist-sdk/src/entities/field/build.js +3 -0
  119. package/dist-sdk/src/entities/field/calc.d.ts +7 -7
  120. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -4
  121. package/dist-sdk/src/entities/field/from-tf.js +244 -49
  122. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  123. package/dist-sdk/src/entities/field/media-types.js +30 -0
  124. package/dist-sdk/src/entities/field/module.js +2 -0
  125. package/dist-sdk/src/entities/field/options.js +6 -1
  126. package/dist-sdk/src/entities/field/to-tf.d.ts +26 -5
  127. package/dist-sdk/src/entities/field/to-tf.js +137 -15
  128. package/dist-sdk/src/entities/field/types.d.ts +2 -0
  129. package/dist-sdk/src/entities/field/types.js +27 -0
  130. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  131. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  132. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  133. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  134. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  135. package/dist-sdk/src/entities/portal/build.js +37 -0
  136. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  137. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  138. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  139. package/dist-sdk/src/entities/portal/index.js +1 -0
  140. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  141. package/dist-sdk/src/entities/portal/module.js +28 -0
  142. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  143. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  144. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  145. package/dist-sdk/src/entities/portal/types.js +1 -0
  146. package/dist-sdk/src/entities/relationship/module.js +2 -0
  147. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  148. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  149. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  150. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  151. package/dist-sdk/src/entities/role/from-tf.js +3 -3
  152. package/dist-sdk/src/entities/role/to-tf.d.ts +2 -0
  153. package/dist-sdk/src/entities/role/to-tf.js +12 -4
  154. package/dist-sdk/src/entities/search-table/module.js +1 -0
  155. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  156. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  157. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  158. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  159. package/dist-sdk/src/entities/service-account/from-tf.js +20 -8
  160. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  161. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  162. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  163. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  164. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +16 -0
  165. package/dist-sdk/src/entities/service-account/workspace-owner.js +22 -0
  166. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  167. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  168. package/dist-sdk/src/entities/shared/filters/ast.d.ts +23 -1
  169. package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
  170. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  171. package/dist-sdk/src/entities/shared/filters/index.js +19 -4
  172. package/dist-sdk/src/entities/shared/filters/print.js +24 -3
  173. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -0
  174. package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -7
  175. package/dist-sdk/src/entities/shared/filters/types.d.ts +15 -2
  176. package/dist-sdk/src/entities/shared/ref.d.ts +5 -7
  177. package/dist-sdk/src/entities/shared/ref.js +5 -7
  178. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +9 -0
  179. package/dist-sdk/src/entities/shared/tool-field-ref.js +35 -2
  180. package/dist-sdk/src/entities/shared/types/field-types.d.ts +20 -5
  181. package/dist-sdk/src/entities/shared/types/field-types.js +8 -0
  182. package/dist-sdk/src/entities/skill/access-policy.js +3 -3
  183. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -0
  184. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +14 -6
  185. package/dist-sdk/src/entities/skill/from-tf.js +70 -15
  186. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  187. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  188. package/dist-sdk/src/entities/skill/module.js +2 -0
  189. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  190. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  191. package/dist-sdk/src/entities/skill-tool/from-tf.js +49 -10
  192. package/dist-sdk/src/entities/skill-tool/module.js +3 -0
  193. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -8
  194. package/dist-sdk/src/entities/skill-tool/to-tf.js +49 -14
  195. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  196. package/dist-sdk/src/entities/table/catalog.js +66 -0
  197. package/dist-sdk/src/entities/table/module.js +2 -1
  198. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  199. package/dist-sdk/src/entities/task/build.d.ts +8 -0
  200. package/dist-sdk/src/entities/task/build.js +10 -1
  201. package/dist-sdk/src/entities/task/from-tf.d.ts +4 -2
  202. package/dist-sdk/src/entities/task/from-tf.js +7 -2
  203. package/dist-sdk/src/entities/task/module.js +2 -2
  204. package/dist-sdk/src/entities/task/to-tf.d.ts +8 -4
  205. package/dist-sdk/src/entities/task/to-tf.js +28 -1
  206. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  207. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  208. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  209. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  210. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  211. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  212. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  213. package/dist-sdk/src/entities/view/from-tf.js +133 -13
  214. package/dist-sdk/src/entities/view/module.js +30 -3
  215. package/dist-sdk/src/entities/view/to-tf.d.ts +20 -8
  216. package/dist-sdk/src/entities/view/to-tf.js +86 -18
  217. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  218. package/dist-sdk/src/entities/view/types.js +15 -15
  219. package/dist-sdk/src/entities/visual-flow/build.d.ts +16 -1
  220. package/dist-sdk/src/entities/visual-flow/build.js +9 -0
  221. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +14 -0
  222. package/dist-sdk/src/entities/visual-flow/from-tf.js +51 -3
  223. package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
  224. package/dist-sdk/src/entities/visual-flow/index.js +1 -1
  225. package/dist-sdk/src/entities/visual-flow/printer.js +19 -0
  226. package/dist-sdk/src/entities/visual-flow/to-tf.js +87 -3
  227. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  228. package/dist-sdk/src/entities/widget/build.js +11 -1
  229. package/dist-sdk/src/entities/widget/from-tf.js +3 -3
  230. package/dist-sdk/src/entities/widget/to-tf.d.ts +2 -0
  231. package/dist-sdk/src/entities/widget/to-tf.js +41 -14
  232. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +148 -13
  233. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  234. package/dist-sdk/src/graph/index.d.ts +12 -0
  235. package/dist-sdk/src/graph/index.js +21 -0
  236. package/dist-sdk/src/graph/modules.js +2 -0
  237. package/dist-sdk/src/graph/types.d.ts +83 -4
  238. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  239. package/dist-sdk/src/internal/sdk-package.js +1 -0
  240. package/package.json +16 -3
@@ -7,10 +7,11 @@
7
7
  */
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
9
  import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
10
- import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
10
+ import { dataRefLabel, optionalString, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
11
11
  import { bareChildResourceLabel, isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
12
12
  import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-codec.js";
13
13
  import { __pulledExpression } from "../app/deserializer/pulled-expression.js";
14
+ import { isAttachmentMediaType } from "./media-types.js";
14
15
  import { optionsFromTf } from "./options.js";
15
16
  import { isCalculationResultType } from "./calculation-types.js";
16
17
  import { KNOWN_FIELD_ATTRS, SUB_TYPE_BY_RESOURCE } from "./types.js";
@@ -52,7 +53,7 @@ function resolveRelatedId(v, ctx) {
52
53
  * element the same way it already does for agent-tool/automation targets —
53
54
  * then stays unresolvable this pull, same as before.
54
55
  */
55
- function resolveRelatedObject(v, ctx) {
56
+ function resolveRelatedObject(v, ctx, namespaceFallback = false) {
56
57
  const raw = resolveRelatedId(v, ctx);
57
58
  if (raw !== undefined)
58
59
  return raw;
@@ -65,10 +66,16 @@ function resolveRelatedObject(v, ctx) {
65
66
  const refName = namespace !== undefined ? ctx.foreignAppRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignAppRefNames?.get(name) : undefined;
66
67
  if (refName !== undefined)
67
68
  return { __kind: "app", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
68
- if (name === undefined)
69
+ if (name !== undefined)
70
+ ctx.unresolvedForeignRefs?.apps.add(name);
71
+ // #1440: a data lookup that carries a namespace still names the target
72
+ // exactly. Its stream label is the sanitized namespace, so degrade to the
73
+ // namespace-derived ref (as dataAspectRefName does) instead of dropping
74
+ // dynamic_config; --with-dependencies still records the target above.
75
+ if (!namespaceFallback || namespace === undefined)
69
76
  return undefined;
70
- ctx.unresolvedForeignRefs?.apps.add(name);
71
- return undefined;
77
+ const derived = tfLabelToTsLabel(sanitizeName(namespace));
78
+ return { __kind: "app", refName: derived, name: name ?? derived, namespace };
72
79
  }
73
80
  if (v.type === "elementum_element") {
74
81
  const attrs = ctx.dataAttrs?.("elementum_element", v.label);
@@ -77,10 +84,16 @@ function resolveRelatedObject(v, ctx) {
77
84
  const refName = namespace !== undefined ? ctx.foreignElementRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignElementRefNames?.get(name) : undefined;
78
85
  if (refName !== undefined)
79
86
  return { __kind: "element", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
80
- if (name === undefined)
87
+ if (name !== undefined)
88
+ ctx.unresolvedForeignRefs?.elements.add(name);
89
+ // #1440: a data lookup that carries a namespace still names the target
90
+ // exactly. Its stream label is the sanitized namespace, so degrade to the
91
+ // namespace-derived ref (as dataAspectRefName does) instead of dropping
92
+ // dynamic_config; --with-dependencies still records the target above.
93
+ if (!namespaceFallback || namespace === undefined)
81
94
  return undefined;
82
- ctx.unresolvedForeignRefs?.elements.add(name);
83
- return undefined;
95
+ const derived = tfLabelToTsLabel(sanitizeName(namespace));
96
+ return { __kind: "element", refName: derived, name: name ?? derived, namespace };
84
97
  }
85
98
  if (v.type === "elementum_task") {
86
99
  const attrs = ctx.dataAttrs?.("elementum_task", v.label);
@@ -92,6 +105,74 @@ function resolveRelatedObject(v, ctx) {
92
105
  }
93
106
  return undefined;
94
107
  }
108
+ /**
109
+ * The identity a self-sourced dynamic Dropdown authors for its own owner:
110
+ * the clone's `ctx.selfAspectRef`, else (pull, edk#1493) the owner itself,
111
+ * named from its own resource block. Pull used to resolve these refs through
112
+ * import ids and print raw `<appId>:<fieldId>` fallbacks, which drift on the
113
+ * next plan and count as coverage gaps.
114
+ */
115
+ function selfIdentity(owner, ctx) {
116
+ if (ctx.selfAspectRef !== undefined)
117
+ return ctx.selfAspectRef;
118
+ if (owner.refName === undefined)
119
+ return undefined;
120
+ const kind = owner.type === "elementum_app" ? "app" : owner.type === "elementum_element" ? "element" : owner.type === "elementum_task" ? "task" : undefined;
121
+ if (kind === undefined)
122
+ return undefined;
123
+ const attrs = ctx.resourceByAddress?.(`${owner.type}.${owner.label}`)?.attrs;
124
+ const name = typeof attrs?.["name"] === "string" ? attrs["name"] : undefined;
125
+ if (name === undefined)
126
+ return undefined;
127
+ const namespace = typeof attrs?.["namespace"] === "string" ? attrs["namespace"] : undefined;
128
+ return { __kind: kind, refName: owner.refName, name, ...(namespace !== undefined ? { namespace } : {}) };
129
+ }
130
+ /**
131
+ * A reference to the owner itself (`elementum_app.<owner>.id`) that no import
132
+ * id resolves, authored as `ctx.selfAspectRef` (clone, edk#1437).
133
+ */
134
+ function selfRelatedObject(v, owner, ctx) {
135
+ const self = selfIdentity(owner, ctx);
136
+ if (self === undefined || v === undefined || !isTfExpr(v) || v.$expr !== "resource-attr")
137
+ return undefined;
138
+ if (v.type !== owner.type || v.label !== owner.label || v.path.join(".") !== "id")
139
+ return undefined;
140
+ return { __kind: self.__kind, refName: self.refName, name: self.name, ...(self.namespace !== undefined ? { namespace: self.namespace } : {}) };
141
+ }
142
+ /** A field of the owner that no import id resolves, as `ctx.selfAspectRef`'s catalog field (edk#1437). */
143
+ function selfRelatedField(v, owner, ctx) {
144
+ const self = selfIdentity(owner, ctx);
145
+ if (self === undefined || v === undefined)
146
+ return undefined;
147
+ const fieldKey = fieldKeyFromTfRef(v, owner.label, owner.scope ?? "app");
148
+ if (fieldKey === undefined || !isTfExpr(v) || v.$expr !== "resource-attr")
149
+ return undefined;
150
+ // A typed fieldRef, not catalog.<self>.fields.<key>: the app file cannot
151
+ // import its own catalog entry.
152
+ const fieldType = SUB_TYPE_BY_RESOURCE.get(v.type)?.authoringType;
153
+ // The field's real display name, from its own resource block; without it
154
+ // the printer falls back to the bag key ("reason" for "Reason").
155
+ const fieldName = ctx.resourceByAddress?.(`${v.type}.${v.label}`)?.attrs?.["name"];
156
+ return {
157
+ ...(typeof fieldName === "string" ? { fieldName } : {}),
158
+ ownerRefName: self.refName,
159
+ ownerKind: self.__kind,
160
+ ownerName: self.name,
161
+ ...(self.namespace !== undefined ? { ownerNamespace: self.namespace } : {}),
162
+ fieldKey,
163
+ ...(fieldType !== undefined ? { fieldType } : {}),
164
+ };
165
+ }
166
+ /**
167
+ * `resolveRelatedField`, else the owner's own field as `ctx.selfAspectRef`'s
168
+ * (clone of a self-sourced Dropdown, edk#1481). Used wherever a dynamic
169
+ * config names a field of its source, which for a self-sourced Dropdown is
170
+ * the owner: the label field, filter fields, sort orders and parent mappings.
171
+ */
172
+ function resolveRelatedOrSelfField(v, owner, ctx) {
173
+ // Self first: in pull the owner's own fields also have import ids (edk#1493).
174
+ return selfRelatedField(v, owner, ctx) ?? resolveRelatedField(v, ctx);
175
+ }
95
176
  function resolveRelatedField(v, ctx) {
96
177
  const raw = resolveRelatedId(v, ctx);
97
178
  if (raw !== undefined)
@@ -130,8 +211,8 @@ function resolveRelatedField(v, ctx) {
130
211
  * ref-only dependency data address resolves to its generated catalog member;
131
212
  * a preserved raw id remains an explicit unresolved/unsafe fallback.
132
213
  */
133
- function dynamicPicklistFilterFieldRef(value, ctx) {
134
- const resolved = resolveRelatedField(value, ctx);
214
+ function dynamicPicklistFilterFieldRef(value, owner, ctx) {
215
+ const resolved = resolveRelatedOrSelfField(value, owner, ctx);
135
216
  if (typeof resolved === "string")
136
217
  return { kind: "unresolved", uuid: resolved, hint: "field" };
137
218
  if (resolved !== undefined) {
@@ -160,40 +241,108 @@ function dynamicPicklistRecordFieldRef(value, owner, ctx) {
160
241
  const fieldKey = fieldKeyFromTfRef(value, owner.label, scope) ?? fieldKeyFromTfValue(value, owner.refName, owner.label, scope, ctx);
161
242
  if (fieldKey === undefined)
162
243
  throw new EntityTfError("record_field filter value field is not a field on the owning record");
163
- return { kind: "field", appHandle: owner.refName, fieldKey };
244
+ // A clone authors the record's fields under the clone's refName (edk#1481).
245
+ return { kind: "field", appHandle: ctx.selfAspectRef?.refName ?? owner.refName, fieldKey };
164
246
  }
165
247
  /**
166
248
  * `dynamic_config` → `AppField.config` (picklist/multiPicklist only). Mirrors
167
249
  * `related_object_id`/`related_label_field_id` resolution exactly (both are
168
250
  * required by the wire schema, so either failing to resolve drops the whole
169
- * config — same convention as RELATION's own required pair). `parent_field_id`
170
- * is same-aspect (see `fieldKeyFromTfRef`'s use here vs. `resolveRelatedId`
171
- * for the cross-aspect id's above); its own failure to resolve degrades that
172
- * ONE optional attribute rather than the whole field.
251
+ * config — same convention as RELATION's own required pair).
252
+ *
253
+ * `filter`, `sort` and `parent_field_id` are different: the provider's update
254
+ * mutation cannot clear them, so removing one from an existing dynamic
255
+ * picklist (Dropdown or multi-select) forces replacement
256
+ * (picklist_dynamic_config.go). A part pull cannot reconstruct is an
257
+ * authoring blocker ({@link blockReplaceForcingDrop}): the part is left out of
258
+ * the extract, and a caller that would author this field refuses rather than
259
+ * print source whose first plan deletes and recreates it.
260
+ * `auto_relate` and `values_render_type` update in place, so those still
261
+ * degrade with a diagnostic. `parent_mappings` updates in place too, but the
262
+ * platform will not clear them ({@link blockUnclearableParentMappings}).
263
+ */
264
+ function blockReplaceForcingDrop(ctx, site, attr, reason) {
265
+ reportAuthoringBlocker(ctx, {
266
+ address: site.address,
267
+ description: `${site.where}: dynamic_config.${attr} ${reason}. Removing dynamic_config.${attr} forces replacement of this field ` +
268
+ `(the platform cannot clear it in place), so dropping it would make the next plan delete and recreate the field.`,
269
+ remedy: "Change the filter, sort or parent field of these fields' dynamic options in the Elementum UI to a form the EDK can represent, then pull again.",
270
+ });
271
+ }
272
+ /**
273
+ * Without its dynamic_config a Dropdown prints as `config: { static: { values: [] } }`,
274
+ * which plan rejects ("options or dynamic_config is required") and which would
275
+ * turn a live dynamic Dropdown static if "fixed" by hand. Every pull-style
276
+ * caller (pull, clone, post-apply refresh) must refuse or skip rather than
277
+ * write it (#1405, #1406).
278
+ */
279
+ function blockDynamicConfigDrop(ctx, site, reason, labelOnly = false) {
280
+ // When only the label field is unresolved the source app/element itself
281
+ // resolved (it is in the workspace or was just pulled), so pulling
282
+ // dependencies again cannot help: the label metadata simply wasn't exported.
283
+ reportAuthoringBlocker(ctx, {
284
+ address: site.address,
285
+ description: `${site.where}: ${reason}. Dropping dynamic_config would author an empty static Dropdown, ` +
286
+ "which plan rejects and which would replace the live dynamic options.",
287
+ remedy: labelOnly
288
+ ? "The source app/element resolves, but its label field metadata wasn't exported, so retrying with --with-dependencies won't help. " +
289
+ "Hand-author the Dropdown's dynamic config (source and label field) in the app file, or see edk#1437 (clone/pull preserving dynamic Dropdown config)."
290
+ : "Make the Dropdown's source app/element and label field resolvable (pull them into this workspace, e.g. with --with-dependencies), then retry.",
291
+ });
292
+ }
293
+ /**
294
+ * `parent_mappings` can be changed in place, but the platform keeps existing
295
+ * mappings when the update clears them, so the provider reports
296
+ * "inconsistent result after apply" and the plan never converges (#1404).
297
+ * Dropping one in pull therefore makes source that cannot be applied: block.
173
298
  */
174
- function dynamicConfigFromTf(value, owner, ctx, where) {
299
+ function blockUnclearableParentMappings(ctx, site) {
300
+ reportAuthoringBlocker(ctx, {
301
+ address: site.address,
302
+ description: `${site.where}: dynamic_config parent mapping field IDs could not be reconstructed. The platform keeps parent mappings ` +
303
+ `when an update removes them, so dropping them would make every apply fail with "inconsistent result after apply".`,
304
+ remedy: "Pull the apps that own the mapped parent/source fields into this workspace (e.g. with --with-dependencies), or change the Dropdown's parent mappings in the Elementum UI, then pull again.",
305
+ });
306
+ }
307
+ /**
308
+ * A field pull cannot extract at all. Leaving it out of the printed source
309
+ * would let the next plan destroy a live, possibly adopted field, so the pull
310
+ * refuses instead (edk#1484). The address also goes to `skipped` so a caller
311
+ * that does not author this field keeps it out of adoption.
312
+ */
313
+ function blockUnextractableField(ctx, site, reason, remedy) {
314
+ ctx.skipped.push(site.address);
315
+ reportAuthoringBlocker(ctx, {
316
+ address: site.address,
317
+ description: `${site.where}: ${reason}, so pull cannot write this field and leaving it out would let the next plan destroy it.`,
318
+ remedy,
319
+ });
320
+ }
321
+ const MALFORMED_FIELD_REMEDY = "The export carries a field the EDK cannot reconstruct. Update the Elementum CLI and pull again; if it persists, report the field's type to the EDK maintainers.";
322
+ function dynamicConfigFromTf(value, owner, ctx, site) {
323
+ const where = site.where;
175
324
  if (value === undefined)
176
325
  return undefined;
177
326
  if (typeof value !== "object" || value === null || isTfExpr(value) || Array.isArray(value)) {
178
- ctx.diagnostics.push(`${where}: dynamic_config has an unexpected shape; dropped`);
327
+ blockDynamicConfigDrop(ctx, site, "dynamic_config has an unexpected shape");
179
328
  return undefined;
180
329
  }
181
330
  const attrs = value;
182
- const relatedAspectId = resolveRelatedObject(attrs["related_aspect_id"], ctx);
183
- const relatedLabelFieldId = resolveRelatedField(attrs["related_label_field_id"], ctx);
331
+ const relatedAspectId = selfRelatedObject(attrs["related_aspect_id"], owner, ctx) ?? resolveRelatedObject(attrs["related_aspect_id"], ctx, /* namespaceFallback (#1440) */ true);
332
+ const relatedLabelFieldId = resolveRelatedOrSelfField(attrs["related_label_field_id"], owner, ctx);
184
333
  if (relatedAspectId === undefined || relatedLabelFieldId === undefined) {
185
334
  const missing = [
186
335
  relatedAspectId === undefined && "related_aspect_id",
187
336
  relatedLabelFieldId === undefined && "related_label_field_id",
188
337
  ].filter((v) => v !== false);
189
- ctx.diagnostics.push(`${where}: dynamic_config.${missing.join(" and ")} does not resolve to a catalog reference or raw platform id; dropped`);
338
+ blockDynamicConfigDrop(ctx, site, `dynamic_config.${missing.join(" and ")} does not resolve to a catalog reference or raw platform id`, relatedAspectId !== undefined);
190
339
  return undefined;
191
340
  }
192
341
  let parentFieldId;
193
342
  if (attrs["parent_field_id"] !== undefined) {
194
343
  parentFieldId = fieldKeyFromTfRef(attrs["parent_field_id"], owner.label, owner.scope ?? "app");
195
344
  if (parentFieldId === undefined) {
196
- ctx.diagnostics.push(`${where}: dynamic_config.parent_field_id could not be resolved to a same-aspect field; dropped`);
345
+ blockReplaceForcingDrop(ctx, site, "parent_field_id", "could not be resolved to a same-aspect field");
197
346
  }
198
347
  }
199
348
  const autoRelate = typeof attrs["auto_relate"] === "boolean" ? attrs["auto_relate"] : undefined;
@@ -202,15 +351,16 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
202
351
  if (attrs["filter"] !== undefined) {
203
352
  try {
204
353
  filter = deserializeFilterFromTf(attrs["filter"], {
205
- field: (v) => dynamicPicklistFilterFieldRef(v, ctx),
354
+ field: (v) => dynamicPicklistFilterFieldRef(v, owner, ctx),
206
355
  recordField: (v) => dynamicPicklistRecordFieldRef(v, owner, ctx),
356
+ recordFieldOwner: (v) => resourceRefLabel(v, owner.type) === owner.label,
207
357
  reference: () => {
208
358
  throw new EntityTfError("dynamic picklist filter does not support value references");
209
359
  },
210
360
  });
211
361
  }
212
362
  catch (e) {
213
- ctx.diagnostics.push(`${where}: dynamic_config.filter ${e instanceof Error ? e.message : String(e)}; dropped`);
363
+ blockReplaceForcingDrop(ctx, site, "filter", e instanceof Error ? e.message : String(e));
214
364
  }
215
365
  }
216
366
  let sort;
@@ -238,21 +388,19 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
238
388
  unresolvedField = true;
239
389
  return rawOrder;
240
390
  }
241
- const resolved = resolveRelatedField(field, ctx);
391
+ const resolved = resolveRelatedOrSelfField(field, owner, ctx);
242
392
  if (resolved === undefined)
243
393
  unresolvedField = true;
244
394
  return resolved === undefined ? rawOrder : { ...order, field: resolved };
245
395
  });
246
- if (unresolvedField) {
247
- ctx.diagnostics.push(`${where}: dynamic_config.sort has an unresolved order field; dropped sort`);
248
- }
249
- else {
396
+ if (unresolvedField)
397
+ blockReplaceForcingDrop(ctx, site, "sort", "has an unresolved order field");
398
+ else
250
399
  sort = { ...rawSort, orders };
251
- }
252
400
  }
253
401
  }
254
402
  else {
255
- ctx.diagnostics.push(`${where}: dynamic_config.sort is not a jsonencode(...) object; dropped`);
403
+ blockReplaceForcingDrop(ctx, site, "sort", "is not a jsonencode(...) object");
256
404
  }
257
405
  }
258
406
  let parentMappings;
@@ -269,15 +417,20 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
269
417
  continue;
270
418
  }
271
419
  const mapping = rawMapping;
272
- const parentAspectFieldId = resolveRelatedId(mapping["parent_aspect_field_id"], ctx);
273
- const relatedAspectFieldId = resolveRelatedId(mapping["related_aspect_field_id"], ctx);
420
+ // Mapped fields usually live on another app (the parent's and this
421
+ // Dropdown's sources), so resolve them like related_label_field_id:
422
+ // raw/imported id, else the foreign data.elementum_field identity (#1404),
423
+ // else (clone) the owner's own field (edk#1481).
424
+ const parentAspectFieldId = resolveRelatedOrSelfField(mapping["parent_aspect_field_id"], owner, ctx);
425
+ const relatedAspectFieldId = resolveRelatedOrSelfField(mapping["related_aspect_field_id"], owner, ctx);
274
426
  if (parentAspectFieldId === undefined || relatedAspectFieldId === undefined) {
275
- ctx.diagnostics.push(`${where}: dynamic_config parent mapping field IDs could not be reconstructed; dropped`);
276
- continue;
427
+ blockUnclearableParentMappings(ctx, site);
428
+ parentMappings = undefined;
429
+ break;
277
430
  }
278
431
  parentMappings.push({ parentAspectFieldId, relatedAspectFieldId });
279
432
  }
280
- if (parentMappings.length === 0)
433
+ if (parentMappings !== undefined && parentMappings.length === 0)
281
434
  parentMappings = undefined;
282
435
  }
283
436
  }
@@ -348,14 +501,15 @@ function staticParentLinkageFromTf(value, optionsValue, owner, ctx, where) {
348
501
  */
349
502
  export function fieldFromTf(block, owner, ctx) {
350
503
  const subType = SUB_TYPE_BY_RESOURCE.get(block.type ?? "");
351
- if (subType === undefined) {
352
- ctx.diagnostics.push(`resource "${block.type}" is not a known field resource; skipped`);
353
- return undefined;
354
- }
355
504
  const fieldLabel = block.label;
356
505
  if (fieldLabel === undefined || fieldLabel === "") {
357
506
  throw new EntityTfError(`${block.type} block is missing its label`);
358
507
  }
508
+ if (subType === undefined) {
509
+ const address = `${block.type}.${fieldLabel}`;
510
+ blockUnextractableField(ctx, { address, where: `field (${address})` }, `resource "${block.type}" is not a known field resource`, MALFORMED_FIELD_REMEDY);
511
+ return undefined;
512
+ }
359
513
  if (subType.implemented !== true) {
360
514
  // Declared but not yet round-tripped - see FIELD_SUB_TYPES for the
361
515
  // current list of not-yet-implemented sub-types, if any.
@@ -384,7 +538,7 @@ export function fieldFromTf(block, owner, ctx) {
384
538
  const options = subType.hasOptions === true && attrs["dynamic_config"] === undefined
385
539
  ? optionsFromTf(attrs["options"], `${where} options`, ctx)
386
540
  : undefined;
387
- const config = subType.hasOptions === true ? dynamicConfigFromTf(attrs["dynamic_config"], owner, ctx, where) : undefined;
541
+ const config = subType.hasOptions === true ? dynamicConfigFromTf(attrs["dynamic_config"], owner, ctx, { address: `${block.type}.${fieldLabel}`, where }) : undefined;
388
542
  const parentLinkage = subType.hasOptions === true && attrs["dynamic_config"] === undefined
389
543
  ? staticParentLinkageFromTf(attrs["static_config"], attrs["options"], owner, ctx, where)
390
544
  : undefined;
@@ -441,8 +595,8 @@ export function fieldFromTf(block, owner, ctx) {
441
595
  // field ids are read-only outputs of that resource, never their own
442
596
  // resource address). Both properties are required by RelationFieldOptions,
443
597
  // so printing relationField(...) with either missing would be invalid
444
- // TypeScript (item 117) - skip the whole field when either side can't be
445
- // resolved, same convention as an unimplemented sub-type.
598
+ // TypeScript (item 117), and leaving the field out would let the next plan
599
+ // destroy it - refuse the pull when either side can't be resolved (#1484).
446
600
  let relatedObject;
447
601
  let relatedLabelField;
448
602
  let autoRelate;
@@ -456,8 +610,14 @@ export function fieldFromTf(block, owner, ctx) {
456
610
  relatedObject === undefined && "related_object_id",
457
611
  relatedLabelField === undefined && "related_label_field_id",
458
612
  ].filter((v) => v !== false);
459
- ctx.diagnostics.push(`${where}: ${missing.join(" and ")} does not resolve to a raw platform id - a RELATION field needs both to reconstruct relatedObject/relatedLabelField; field skipped`);
460
- ctx.skipped.push(`${block.type}.${fieldLabel}`);
613
+ const foreignTarget = attrs["related_object_id"];
614
+ const onlyForeignTargetMissing = relatedLabelField !== undefined &&
615
+ isTfExpr(foreignTarget) &&
616
+ foreignTarget.$expr === "data-attr" &&
617
+ (foreignTarget.type === "elementum_app" || foreignTarget.type === "elementum_element");
618
+ blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, `${missing.join(" and ")} does not resolve to a raw platform id or a pulled app/element, and a RELATION field needs both relatedObject and relatedLabelField`, onlyForeignTargetMissing
619
+ ? "Pull the related apps and elements into this workspace (retry with --with-dependencies), then pull again."
620
+ : "The export names these relation fields' related object or label field in a form pull cannot resolve, and --with-dependencies cannot resolve it either. Change the relation field in the Elementum UI, then pull again.");
461
621
  return undefined;
462
622
  }
463
623
  }
@@ -465,6 +625,34 @@ export function fieldFromTf(block, owner, ctx) {
465
625
  const tags = Array.isArray(fieldRole) && fieldRole.every((t) => typeof t === "string")
466
626
  ? fieldRole
467
627
  : undefined;
628
+ let mediaTypes;
629
+ if (subType.typeKey === "attachment" && attrs["media_types"] !== undefined) {
630
+ const raw = attrs["media_types"];
631
+ if (!Array.isArray(raw)) {
632
+ ctx.diagnostics.push(`${where}: media_types must be a list of MIME types; omitted`);
633
+ }
634
+ else {
635
+ // Any invalid entry drops the whole list. Printing only the valid
636
+ // entries would shrink the live restriction on the next build.
637
+ // Omitting mediaTypes leaves the live value in place (provider
638
+ // UseStateForNullSet). `*/*` is invalid here too — see media-types.ts.
639
+ const values = [];
640
+ const invalid = [];
641
+ for (const entry of raw) {
642
+ if (isAttachmentMediaType(entry))
643
+ values.push(entry);
644
+ else
645
+ invalid.push(entry);
646
+ }
647
+ if (invalid.length > 0) {
648
+ const shown = invalid.map((entry) => JSON.stringify(entry)).join(", ");
649
+ ctx.diagnostics.push(`${where}: media_types entries ${shown} are not MIME types (expected type/subtype); omitted so the live restriction is kept`);
650
+ }
651
+ else if (values.length > 0) {
652
+ mediaTypes = values;
653
+ }
654
+ }
655
+ }
468
656
  // A group/user field's default_value is a `data.elementum_group|user.<label>.id`
469
657
  // EXPRESSION on the wire (the platform has no stable raw id to hand
470
658
  // authored source, and the field is Optional-without-Computed — omitting
@@ -489,14 +677,12 @@ export function fieldFromTf(block, owner, ctx) {
489
677
  const scope = owner.scope ?? "app";
490
678
  const calculation = subType.typeKey === "calculated" ? optionalString(attrs, "calculation", where, ctx) : undefined;
491
679
  if (subType.typeKey === "calculated" && calculation === undefined) {
492
- ctx.skipped.push(`${block.type}.${fieldLabel}`);
493
- ctx.diagnostics.push(`${where}: calculation is required; skipped`);
680
+ blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, "calculation is missing", MALFORMED_FIELD_REMEDY);
494
681
  return undefined;
495
682
  }
496
683
  const calculationType = subType.typeKey === "calculated" ? attrs["calculation_type"] : undefined;
497
684
  if (subType.typeKey === "calculated" && !isCalculationResultType(calculationType)) {
498
- ctx.skipped.push(`${block.type}.${fieldLabel}`);
499
- ctx.diagnostics.push(`${where}: calculation_type is missing or unsupported; skipped rather than guessing the typed result`);
685
+ blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, `calculation_type is missing or unsupported (${JSON.stringify(calculationType ?? null)}), and pull will not guess the typed result`, MALFORMED_FIELD_REMEDY);
500
686
  return undefined;
501
687
  }
502
688
  let calculationInclude;
@@ -543,6 +729,7 @@ export function fieldFromTf(block, owner, ctx) {
543
729
  ...(options !== undefined && { options }),
544
730
  ...(config !== undefined && { config }),
545
731
  ...(tags !== undefined && tags.length > 0 && { tags }),
732
+ ...(mediaTypes !== undefined && { mediaTypes }),
546
733
  ...(relatedObject !== undefined && { relatedObject }),
547
734
  ...(relatedLabelField !== undefined && { relatedLabelField }),
548
735
  ...(autoRelate !== undefined && { autoRelate }),
@@ -620,7 +807,7 @@ export function decodeForeignDataField(dataLabel, target, ctx) {
620
807
  const fieldType = fieldTypeFromRegistry(ctx, target.key, catalogFieldKey);
621
808
  return { key: catalogFieldKey, name, ...(fieldType !== undefined ? { fieldType } : {}) };
622
809
  }
623
- const stripped = fieldKeyFromForeignDataLabel(dataLabel, target);
810
+ const stripped = fieldKeyFromForeignDataLabel(dataLabel, { ...target, ownerDataLabel: foreignFieldOwnerDataLabel(dataLabel, ctx) });
624
811
  if (stripped !== undefined) {
625
812
  const fieldType = fieldTypeFromRegistry(ctx, target.key, stripped);
626
813
  return { key: stripped, name, ...(fieldType !== undefined ? { fieldType } : {}) };
@@ -646,11 +833,19 @@ function fieldTypeFromRegistry(ctx, ownerRefName, fieldKey) {
646
833
  return "TEXT";
647
834
  return undefined;
648
835
  }
836
+ /** The label of the app/element/task lookup a foreign `data.elementum_field` reads through its `object_id`. */
837
+ function foreignFieldOwnerDataLabel(dataLabel, ctx) {
838
+ const objectId = ctx.dataAttrs?.("elementum_field", dataLabel)?.["object_id"];
839
+ return dataRefLabel(objectId, "elementum_app") ?? dataRefLabel(objectId, "elementum_element") ?? dataRefLabel(objectId, "elementum_task");
840
+ }
649
841
  /** Strip ei's owner-display prefix from a `data.elementum_field` label. */
650
842
  export function fieldKeyFromForeignDataLabel(dataLabel, target) {
651
843
  const kind = target.kind === "element" || target.kind === "app" || target.kind === "task" ? target.kind : undefined;
652
844
  const ownerType = kind === "element" ? "elementum_element" : kind === "app" ? "elementum_app" : kind === "task" ? "elementum_task" : undefined;
845
+ // ei prefixes a foreign field lookup's label with its owner lookup's label, which can differ from the
846
+ // owner's catalog key (a namespace-derived refName), so strip by that label too.
653
847
  const slugs = [
848
+ target.ownerDataLabel,
654
849
  target.name !== undefined && target.name !== "" ? sanitizeName(target.name) : undefined,
655
850
  target.namespace,
656
851
  tsLabelToTfLabel(target.key),
@@ -0,0 +1,6 @@
1
+ export declare function isAttachmentMediaType(entry: unknown): entry is string;
2
+ /**
3
+ * Throws when an authored attachment field lists nothing, or lists a value
4
+ * that is not `type/subtype`. An empty list would reject every upload.
5
+ */
6
+ export declare function assertAttachmentMediaTypes(fieldName: string, mediaTypes: readonly unknown[]): void;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Attachment `mediaTypes` entries. A value is `type/subtype`: token
3
+ * characters, no surrounding whitespace, and `*` only as the whole subtype
4
+ * (`image/*`). An extension (`pdf`, `.docx`) or a partial type (`image/`)
5
+ * is rejected so a field cannot deploy a list that matches no upload.
6
+ *
7
+ * `*`/`*` stays rejected in authoring and on pull. A null `mediaTypes` list
8
+ * rejects every upload (#1374), and there is no evidence yet that the
9
+ * platform treats `*`/`*` as allow-all. Whether it does is an open question;
10
+ * until that is confirmed, do not accept `*`/`*` as a way to clear the
11
+ * restriction.
12
+ */
13
+ const MIME_MEDIA_TYPE = /^[A-Za-z0-9][\w.+-]*\/(\*|[A-Za-z0-9][\w.+-]*)$/;
14
+ export function isAttachmentMediaType(entry) {
15
+ return typeof entry === "string" && MIME_MEDIA_TYPE.test(entry);
16
+ }
17
+ /**
18
+ * Throws when an authored attachment field lists nothing, or lists a value
19
+ * that is not `type/subtype`. An empty list would reject every upload.
20
+ */
21
+ export function assertAttachmentMediaTypes(fieldName, mediaTypes) {
22
+ if (mediaTypes.length === 0) {
23
+ throw new Error(`attachment field "${fieldName}": mediaTypes is empty; an empty list would reject every upload.`);
24
+ }
25
+ for (const entry of mediaTypes) {
26
+ if (!isAttachmentMediaType(entry)) {
27
+ throw new Error(`attachment field "${fieldName}": mediaTypes entry ${JSON.stringify(entry)} is not a MIME type (expected type/subtype).`);
28
+ }
29
+ }
30
+ }
@@ -10,6 +10,7 @@ export const fieldModule = {
10
10
  parents: [
11
11
  { parent: "app", child: "field" },
12
12
  { parent: "element", child: "field" },
13
+ { parent: "task", child: "field" },
13
14
  ],
14
15
  resource: {
15
16
  shape: "subTypes",
@@ -42,6 +43,7 @@ export const fieldModule = {
42
43
  catalogBag: "fields",
43
44
  renderOrder: 50,
44
45
  catalogRoot: "app",
46
+ fromOwnRef: true,
45
47
  renderEntry: (args) => {
46
48
  const named = asNamedRef(args.ref);
47
49
  const field = args.ref;
@@ -73,7 +73,12 @@ export function optionsFromTf(v, where, ctx) {
73
73
  return undefined;
74
74
  const out = {};
75
75
  for (const { key, item } of withUniqueKeys(parsed, (p) => p.label, "option")) {
76
- out[key] = {
76
+ // Digit-only keys are JS array indices: Object.values reorders them and
77
+ // pull prints the wrong option order (edk#1449). A leading underscore is
78
+ // outside camelCase's key space (it strips non-alphanumerics) and is not
79
+ // an integer index, so the prefix cannot collide with another option.
80
+ const bagKey = /^(0|[1-9]\d*)$/.test(key) ? `_${key}` : key;
81
+ out[bagKey] = {
77
82
  id: "",
78
83
  label: item.label,
79
84
  ...(item.color !== undefined && { color: item.color }),
@@ -10,8 +10,20 @@
10
10
  * non-canonical bag key: it has no well-defined terraform address.
11
11
  */
12
12
  import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
13
- import { type ChildResourceScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
13
+ import { type FieldOwnerScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
14
14
  import { type PicklistValueWire } from "./options.js";
15
+ /**
16
+ * The authored fields known to belong to an app/element. Maps produced by a
17
+ * root emitter also provide exact addresses; sets reconstructed from a
18
+ * workspace sibling still provide the ownership fact needed to distinguish
19
+ * an authored audit-key field from the element's platform audit field.
20
+ */
21
+ export interface FieldOwnership {
22
+ has(refName: string): boolean;
23
+ get?(refName: string): string | undefined;
24
+ }
25
+ /** Reconstruct custom-field ownership from a loaded app/element payload. */
26
+ export declare function authoredFieldKeysFromPayload(payload: unknown): ReadonlySet<string> | undefined;
15
27
  /** Slim `AppOrElementRef` token shape as it appears in a def() payload (post-`slimTokens`). */
16
28
  interface AspectTokenWire {
17
29
  readonly __kind?: string;
@@ -102,14 +114,16 @@ export interface FieldInnerWire {
102
114
  readonly autoRelate?: boolean;
103
115
  /** "decimal" fields only. */
104
116
  readonly decimalPlaces?: number;
117
+ /** Attachment fields only — allowed MIME types. Omitted from HCL when unset or empty. */
118
+ readonly mediaTypes?: readonly string[];
105
119
  }
106
120
  export interface FieldToTfOptions {
107
121
  /** The owning stream root's terraform label (namespace). */
108
122
  readonly ownerTfLabel: string;
109
123
  /** The owning stream root's refName — needed to detect a self-targeting RELATION field. */
110
124
  readonly appRefName: string;
111
- /** App children use `apps_<ns>_`; element children use `<ns>_`. */
112
- readonly scope?: ChildResourceScope;
125
+ /** App children use `apps_<ns>_<ns>_`, element children `elements_<ns>_<ns>_`, task children `tasks_<ns>_<ns>_` (edk#1464). */
126
+ readonly scope?: FieldOwnerScope;
113
127
  /** The owner's id reference, e.g. `elementum_app.<ns>.id` — computed by the owner's to-tf. */
114
128
  readonly objectId: TfValue;
115
129
  /** Degradations land here — reported by the caller, never silent. */
@@ -125,6 +139,8 @@ export interface FieldToTfOptions {
125
139
  * `data` lookup, which can only ever find something already live).
126
140
  */
127
141
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
142
+ /** All custom fields authored by the owning root, including later entries. */
143
+ readonly fieldOwnership?: FieldOwnership;
128
144
  }
129
145
  export interface FieldToTfResult {
130
146
  readonly block: TfBlock;
@@ -133,7 +149,12 @@ export interface FieldToTfResult {
133
149
  /** `<resourceType>.<tfLabel>` — locals/build-vs-export bookkeeping. */
134
150
  readonly address: string;
135
151
  }
136
- /** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
152
+ /**
153
+ * Field display names must be unique within an app or element. The platform rejects the second one only at
154
+ * apply ("Duplicate key found.", naming neither field) after the rest of the apply has landed, so fail the build
155
+ * first and name both fields.
156
+ */
157
+ export declare function claimFieldDisplayName(seen: Map<string, string>, field: FieldToTfResult): void;
137
158
  export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
138
- export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: ChildResourceScope, fieldAddresses?: ReadonlyMap<string, string>): TfExpr | undefined;
159
+ export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership): TfExpr | undefined;
139
160
  export {};