@elementumai/edk 0.10.1 → 0.10.3

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 (125) hide show
  1. package/README.md +7 -7
  2. package/dist-sdk/src/catalog/org.d.ts +7 -5
  3. package/dist-sdk/src/catalog/org.js +14 -9
  4. package/dist-sdk/src/catalog/token.js +4 -0
  5. package/dist-sdk/src/core/types/app.d.ts +22 -0
  6. package/dist-sdk/src/engine/build/context.d.ts +8 -0
  7. package/dist-sdk/src/engine/build/source-context.d.ts +3 -4
  8. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  9. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  10. package/dist-sdk/src/engine/ei/state.d.ts +48 -0
  11. package/dist-sdk/src/engine/ei/state.js +91 -0
  12. package/dist-sdk/src/engine/pull/authored-address.d.ts +100 -0
  13. package/dist-sdk/src/engine/pull/authored-address.js +360 -0
  14. package/dist-sdk/src/engine/pull/context.d.ts +59 -0
  15. package/dist-sdk/src/engine/tf/expr.d.ts +7 -0
  16. package/dist-sdk/src/engine/tf/expr.js +62 -18
  17. package/dist-sdk/src/engine/tf/index.d.ts +1 -1
  18. package/dist-sdk/src/engine/tf/index.js +1 -1
  19. package/dist-sdk/src/engine/tf/labels.d.ts +10 -2
  20. package/dist-sdk/src/engine/tf/labels.js +15 -2
  21. package/dist-sdk/src/engine/tf/parse.js +19 -6
  22. package/dist-sdk/src/engine/workspace/backend.d.ts +34 -0
  23. package/dist-sdk/src/engine/workspace/backend.js +104 -0
  24. package/dist-sdk/src/engine/workspace/generated-file.d.ts +3 -0
  25. package/dist-sdk/src/engine/workspace/generated-file.js +6 -0
  26. package/dist-sdk/src/engine/workspace/loader.js +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +1 -1
  28. package/dist-sdk/src/entities/app/build.d.ts +36 -4
  29. package/dist-sdk/src/entities/app/build.js +67 -4
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +12 -0
  31. package/dist-sdk/src/entities/app/from-tf.js +13 -9
  32. package/dist-sdk/src/entities/app/module.js +3 -1
  33. package/dist-sdk/src/entities/app/stage-keys.d.ts +82 -0
  34. package/dist-sdk/src/entities/app/stage-keys.js +160 -0
  35. package/dist-sdk/src/entities/app/to-tf.js +21 -21
  36. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +9 -1
  37. package/dist-sdk/src/entities/approval-chain/from-tf.js +31 -3
  38. package/dist-sdk/src/entities/approval-chain/module.js +12 -4
  39. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +1 -0
  40. package/dist-sdk/src/entities/approval-chain/to-tf.js +6 -1
  41. package/dist-sdk/src/entities/automation/build.d.ts +2 -0
  42. package/dist-sdk/src/entities/automation/build.js +25 -17
  43. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -0
  44. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +5 -3
  45. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +127 -31
  46. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  47. package/dist-sdk/src/entities/automation/from-tf.js +172 -27
  48. package/dist-sdk/src/entities/automation/module.js +123 -37
  49. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +21 -0
  50. package/dist-sdk/src/entities/automation/output-key-wire-name.js +38 -0
  51. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
  52. package/dist-sdk/src/entities/automation/to-tf.js +191 -33
  53. package/dist-sdk/src/entities/automation/triggers.d.ts +2 -0
  54. package/dist-sdk/src/entities/automation/triggers.js +1 -0
  55. package/dist-sdk/src/entities/chart/from-tf.d.ts +6 -0
  56. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  57. package/dist-sdk/src/entities/dashboard/from-tf.js +51 -4
  58. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  59. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +48 -4
  60. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +2 -0
  61. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -2
  62. package/dist-sdk/src/entities/element/build.js +1 -1
  63. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -6
  64. package/dist-sdk/src/entities/element/from-tf.js +23 -7
  65. package/dist-sdk/src/entities/element/module.js +5 -3
  66. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -2
  67. package/dist-sdk/src/entities/element/to-tf.js +36 -25
  68. package/dist-sdk/src/entities/field/allow-list.d.ts +18 -0
  69. package/dist-sdk/src/entities/field/allow-list.js +42 -0
  70. package/dist-sdk/src/entities/field/build.d.ts +38 -3
  71. package/dist-sdk/src/entities/field/build.js +7 -2
  72. package/dist-sdk/src/entities/field/from-tf.js +252 -76
  73. package/dist-sdk/src/entities/field/module.d.ts +6 -0
  74. package/dist-sdk/src/entities/field/module.js +24 -2
  75. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  76. package/dist-sdk/src/entities/field/order.d.ts +25 -0
  77. package/dist-sdk/src/entities/field/order.js +74 -0
  78. package/dist-sdk/src/entities/field/to-tf.d.ts +6 -0
  79. package/dist-sdk/src/entities/field/to-tf.js +87 -0
  80. package/dist-sdk/src/entities/field/types.d.ts +5 -0
  81. package/dist-sdk/src/entities/field/types.js +8 -0
  82. package/dist-sdk/src/entities/relationship/build.d.ts +3 -3
  83. package/dist-sdk/src/entities/relationship/from-tf.js +4 -2
  84. package/dist-sdk/src/entities/relationship/to-tf.js +3 -1
  85. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +8 -3
  86. package/dist-sdk/src/entities/service-account/workspace-owner.js +12 -4
  87. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +5 -0
  88. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +13 -0
  89. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -0
  90. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +1 -1
  91. package/dist-sdk/src/entities/skill/to-tf.js +19 -14
  92. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  93. package/dist-sdk/src/entities/skill-tool/from-tf.js +3 -0
  94. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +6 -1
  95. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -1
  96. package/dist-sdk/src/entities/task/build.js +1 -1
  97. package/dist-sdk/src/entities/task/module.js +2 -1
  98. package/dist-sdk/src/entities/task/to-tf.js +4 -0
  99. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +11 -0
  100. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +13 -38
  101. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +29 -0
  102. package/dist-sdk/src/entities/view/custom-view-validate.js +292 -0
  103. package/dist-sdk/src/entities/view/from-tf.d.ts +2 -0
  104. package/dist-sdk/src/entities/view/from-tf.js +40 -6
  105. package/dist-sdk/src/entities/view/module.js +4 -1
  106. package/dist-sdk/src/entities/view/to-tf.d.ts +6 -0
  107. package/dist-sdk/src/entities/view/to-tf.js +25 -9
  108. package/dist-sdk/src/entities/view/types.d.ts +6 -0
  109. package/dist-sdk/src/entities/view/types.js +6 -0
  110. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +2 -1
  111. package/dist-sdk/src/entities/visual-flow/from-tf.js +11 -2
  112. package/dist-sdk/src/entities/visual-flow/module.js +15 -5
  113. package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +2 -0
  114. package/dist-sdk/src/entities/visual-flow/to-tf.js +1 -1
  115. package/dist-sdk/src/entities/widget/build.d.ts +8 -1
  116. package/dist-sdk/src/entities/widget/from-tf.js +12 -6
  117. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  118. package/dist-sdk/src/entities/widget/to-tf.js +16 -0
  119. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +8 -2
  120. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  121. package/dist-sdk/src/graph/index.d.ts +9 -2
  122. package/dist-sdk/src/graph/index.js +4 -0
  123. package/dist-sdk/src/graph/modules.js +2 -1
  124. package/dist-sdk/src/graph/types.d.ts +72 -3
  125. package/package.json +2 -17
@@ -6,8 +6,8 @@
6
6
  * import blocks and stay data-side.
7
7
  */
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
- import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
10
- import { dataRefLabel, optionalString, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
9
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
10
+ import { dataRefLabel, groupCatalogKey, 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";
@@ -15,8 +15,23 @@ import { isAttachmentMediaType } from "./media-types.js";
15
15
  import { optionsFromTf } from "./options.js";
16
16
  import { isCalculationResultType } from "./calculation-types.js";
17
17
  import { KNOWN_FIELD_ATTRS, SUB_TYPE_BY_RESOURCE } from "./types.js";
18
- import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
18
+ import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS, ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
19
+ import { resolveDataAspectTarget, resolveDataTaskTarget } from "../shared/aspect-target-from-tf.js";
19
20
  const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
21
+ const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
22
+ /** A system field's authoring type, as the owner's own `fields.<key>` token carries it. */
23
+ const SYSTEM_FIELD_TYPE_BY_KEY = {
24
+ id: "HANDLE",
25
+ title: "TEXT",
26
+ status: "PICKLIST",
27
+ stage: "PICKLIST",
28
+ createdAt: "DATETIME",
29
+ createdBy: "USER",
30
+ updatedAt: "DATETIME",
31
+ updatedBy: "USER",
32
+ closedAt: "DATETIME",
33
+ closedBy: "USER",
34
+ };
20
35
  /**
21
36
  * A related_object_id/related_label_field_id value → its raw platform id, if
22
37
  * recoverable: a literal string as-is, or a `<type>.<label>.id` resource
@@ -35,23 +50,10 @@ function resolveRelatedId(v, ctx) {
35
50
  return undefined;
36
51
  }
37
52
  /**
38
- * `related_object_id` specifically (not `related_label_field_id`, which
39
- * names a field and has no equivalent name-based recovery) gets one more
40
- * fallback beyond `resolveRelatedId`: a `data.elementum_app.<label>` /
41
- * `data.elementum_element.<label>` foreign lookup carries no raw id, but the
42
- * data block's own `name = "..."` filter attribute (read via `ctx.dataName`)
43
- * IS the target's real display name - the same name `readAppNameMap`/
44
- * `readElementNameMap` index every already-pulled app/element by. When that
45
- * name matches one already in this workspace, resolve straight to a typed
46
- * `AppOrElementRef` instead of giving up - the reference then survives a
47
- * build exactly like a hand-authored `catalog.<ref>` would (see
48
- * agent-tool/from-tf.ts's `NormalizedToolTarget` for the same foreign-name
49
- * convention on tool targets). No match (the target isn't pulled into this
50
- * workspace yet, or `ctx` wasn't wired with the name maps) records the name
51
- * on `ctx.unresolvedForeignRefs` (when the caller wired it up) so
52
- * `--with-dependencies` can chase it down and pulls it as a workspace app/
53
- * element the same way it already does for agent-tool/automation targets —
54
- * then stays unresolvable this pull, same as before.
53
+ * `related_object_id` gets one more fallback beyond `resolveRelatedId`: a
54
+ * `data.elementum_app.<label>` / `data.elementum_element.<label>` foreign
55
+ * lookup carries no raw id, but its `namespace`/`name` filter attributes ARE
56
+ * the target's portable identity (see {@link dataAspectRef}).
55
57
  */
56
58
  function resolveRelatedObject(v, ctx, namespaceFallback = false) {
57
59
  const raw = resolveRelatedId(v, ctx);
@@ -59,52 +61,55 @@ function resolveRelatedObject(v, ctx, namespaceFallback = false) {
59
61
  return raw;
60
62
  if (v === undefined || !isTfExpr(v) || v.$expr !== "data-attr")
61
63
  return undefined;
62
- if (v.type === "elementum_app") {
63
- const attrs = ctx.dataAttrs?.("elementum_app", v.label);
64
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
65
- const name = ctx.dataName("elementum_app", v.label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
66
- const refName = namespace !== undefined ? ctx.foreignAppRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignAppRefNames?.get(name) : undefined;
67
- if (refName !== undefined)
68
- return { __kind: "app", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
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)
64
+ if (v.type === "elementum_app" || v.type === "elementum_element") {
65
+ const kind = v.type === "elementum_app" ? "app" : "element";
66
+ const resolved = dataAspectRef(kind, v.label, ctx);
67
+ if (resolved === undefined)
76
68
  return undefined;
77
- const derived = tfLabelToTsLabel(sanitizeName(namespace));
78
- return { __kind: "app", refName: derived, name: name ?? derived, namespace };
79
- }
80
- if (v.type === "elementum_element") {
81
- const attrs = ctx.dataAttrs?.("elementum_element", v.label);
82
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
83
- const name = ctx.dataName("elementum_element", v.label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
84
- const refName = namespace !== undefined ? ctx.foreignElementRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignElementRefNames?.get(name) : undefined;
85
- if (refName !== undefined)
86
- return { __kind: "element", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
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)
94
- return undefined;
95
- const derived = tfLabelToTsLabel(sanitizeName(namespace));
96
- return { __kind: "element", refName: derived, name: name ?? derived, namespace };
69
+ // In the workspace, or a dynamic Dropdown (`namespaceFallback` is the
70
+ // related_aspect_id caller): author the portable ref. That is #1440's
71
+ // namespace-derived dynamic_config and #1569's unpulled source.
72
+ if (resolved.inWorkspace || namespaceFallback)
73
+ return resolved.ref;
74
+ // #1484: an unpulled relation target stays unresolved so the pull
75
+ // refuses it. dataAspectRef already recorded the name for
76
+ // --with-dependencies.
77
+ return undefined;
97
78
  }
98
79
  if (v.type === "elementum_task") {
99
- const attrs = ctx.dataAttrs?.("elementum_task", v.label);
100
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
101
- const name = ctx.dataName("elementum_task", v.label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
102
- const refName = namespace !== undefined ? ctx.foreignTaskRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignTaskRefNames?.get(name) : undefined;
103
- const finalRefName = refName ?? tfLabelToTsLabel(v.label);
104
- return { __kind: "task", refName: finalRefName, name: name ?? finalRefName, ...(namespace !== undefined ? { namespace } : {}) };
80
+ const task = resolveDataTaskTarget(ctx, v.label);
81
+ return { __kind: "task", refName: task.key, name: task.name, ...(task.namespace !== undefined ? { namespace: task.namespace } : {}) };
105
82
  }
106
83
  return undefined;
107
84
  }
85
+ /**
86
+ * A `data.elementum_app|element.<label>` lookup → the aspect it names, the
87
+ * same identity views, widgets and relationships resolve: the workspace
88
+ * catalog when that app/element is pulled here, else a foreign ref build
89
+ * looks up again by the same namespace (or name) - the way automations
90
+ * author a foreign found record. A foreign one is also recorded on
91
+ * `ctx.unresolvedForeignRefs` so `pull app --with-dependencies` pulls it.
92
+ * Undefined when the export gave the lookup neither a namespace nor a name.
93
+ */
94
+ function dataAspectRef(kind, label, ctx) {
95
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
96
+ const attrs = ctx.dataAttrs?.(type, label);
97
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
98
+ const name = ctx.dataName(type, label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
99
+ if (namespace === undefined && name === undefined)
100
+ return undefined;
101
+ const target = resolveDataAspectTarget(ctx, kind, label);
102
+ const byNamespace = kind === "app" ? ctx.foreignAppRefNamespaces : ctx.foreignElementRefNamespaces;
103
+ const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
104
+ const inWorkspace = (namespace !== undefined && byNamespace?.get(namespace) === target.key) ||
105
+ (name !== undefined && byName?.get(name) === target.key);
106
+ if (!inWorkspace && name !== undefined)
107
+ (kind === "app" ? ctx.unresolvedForeignRefs?.apps : ctx.unresolvedForeignRefs?.elements)?.add(name);
108
+ return {
109
+ ref: { __kind: kind, refName: target.key, name: target.name, ...(namespace !== undefined ? { namespace } : {}) },
110
+ inWorkspace,
111
+ };
112
+ }
108
113
  /**
109
114
  * The identity a self-sourced dynamic Dropdown authors for its own owner:
110
115
  * the clone's `ctx.selfAspectRef`, else (pull, edk#1493) the owner itself,
@@ -163,15 +168,75 @@ function selfRelatedField(v, owner, ctx) {
163
168
  ...(fieldType !== undefined ? { fieldType } : {}),
164
169
  };
165
170
  }
171
+ /**
172
+ * One of the owner's own system fields (Title, ID, …), named by a
173
+ * self-sourced Dropdown's config (edk#1749). The export writes these as the
174
+ * owner's `local.<owner>_<key>_field_id`, or keeps the raw platform id, which
175
+ * pull resolves through the live system-field read (#1704). Either way the
176
+ * build writes the local back. Only for a Dropdown whose source is the owner:
177
+ * every field such a config names belongs to its source.
178
+ */
179
+ function selfSystemField(v, owner, ctx) {
180
+ const self = selfIdentity(owner, ctx);
181
+ if (self === undefined || v === undefined || owner.refName === undefined)
182
+ return undefined;
183
+ const scope = owner.scope ?? "app";
184
+ let fieldKey;
185
+ if (typeof v === "string") {
186
+ const stateRef = ctx.foreignFieldRefsById?.get(v);
187
+ if (stateRef?.ownerRefName === owner.refName)
188
+ fieldKey = stateRef.fieldKey;
189
+ }
190
+ else if (isTfExpr(v) && v.$expr === "local") {
191
+ fieldKey = fieldKeyFromTfRef(v, owner.label, scope);
192
+ }
193
+ if (fieldKey === undefined)
194
+ return undefined;
195
+ const systemKeys = scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET;
196
+ if (!systemKeys.has(fieldKey))
197
+ return undefined;
198
+ // An element's custom field may own an audit key; build then resolves that
199
+ // key to the custom field, which would retarget this reference.
200
+ if (scope === "element" && ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET.has(fieldKey) && ownerMayHaveCustomField(owner, fieldKey, ctx))
201
+ return undefined;
202
+ // Title and ID carry their display names on the owner's own block; any
203
+ // other key (or an unrenamed one) prints the platform's deploy default.
204
+ const named = ctx.resourceByAddress?.(`${owner.type}.${owner.label}`)?.attrs?.[`${tsLabelToTfLabel(fieldKey)}_field_name`];
205
+ const fieldName = typeof named === "string" ? named : DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[fieldKey];
206
+ return {
207
+ fieldName,
208
+ ownerRefName: self.refName,
209
+ ownerKind: self.__kind,
210
+ ownerName: self.name,
211
+ ...(self.namespace !== undefined ? { ownerNamespace: self.namespace } : {}),
212
+ fieldKey,
213
+ fieldType: SYSTEM_FIELD_TYPE_BY_KEY[fieldKey],
214
+ };
215
+ }
216
+ /** Whether one of the owner's own field resources is keyed `fieldKey`; true when the stream can't be listed. */
217
+ function ownerMayHaveCustomField(owner, fieldKey, ctx) {
218
+ if (ctx.resourcesOfType === undefined)
219
+ return true;
220
+ const scope = owner.scope ?? "app";
221
+ for (const type of SUB_TYPE_BY_RESOURCE.keys()) {
222
+ for (const resource of ctx.resourcesOfType(type)) {
223
+ if (resourceRefLabel(resource.attrs["object_id"], owner.type) !== owner.label)
224
+ continue;
225
+ if (scopedLabelToBagKey(owner.label, resource.label, scope) === fieldKey)
226
+ return true;
227
+ }
228
+ }
229
+ return false;
230
+ }
166
231
  /**
167
232
  * `resolveRelatedField`, else the owner's own field as `ctx.selfAspectRef`'s
168
233
  * (clone of a self-sourced Dropdown, edk#1481). Used wherever a dynamic
169
234
  * config names a field of its source, which for a self-sourced Dropdown is
170
235
  * the owner: the label field, filter fields, sort orders and parent mappings.
171
236
  */
172
- function resolveRelatedOrSelfField(v, owner, ctx) {
237
+ function resolveRelatedOrSelfField(v, owner, ctx, selfSourced) {
173
238
  // Self first: in pull the owner's own fields also have import ids (edk#1493).
174
- return selfRelatedField(v, owner, ctx) ?? resolveRelatedField(v, ctx);
239
+ return selfRelatedField(v, owner, ctx) ?? (selfSourced ? selfSystemField(v, owner, ctx) : undefined) ?? resolveRelatedField(v, ctx);
175
240
  }
176
241
  function resolveRelatedField(v, ctx) {
177
242
  const raw = resolveRelatedId(v, ctx);
@@ -202,6 +267,27 @@ function resolveRelatedField(v, ctx) {
202
267
  ...(fieldName !== undefined ? { fieldName } : {}),
203
268
  };
204
269
  }
270
+ const appLabel = dataRefLabel(objectId, "elementum_app");
271
+ const elementLabel = dataRefLabel(objectId, "elementum_element");
272
+ const ownerKind = appLabel !== undefined ? "app" : elementLabel !== undefined ? "element" : undefined;
273
+ const ownerLabel = appLabel ?? elementLabel;
274
+ const owner = ownerKind === undefined || ownerLabel === undefined ? undefined : dataAspectRef(ownerKind, ownerLabel, ctx);
275
+ if (ownerKind !== undefined && owner !== undefined && typeof attrs?.name === "string") {
276
+ const { refName, name, namespace } = owner.ref;
277
+ const field = decodeForeignDataField(v.label, { key: refName, name, ...(namespace !== undefined ? { namespace } : {}), kind: ownerKind }, ctx);
278
+ if (owner.inWorkspace)
279
+ return { ownerRefName: refName, fieldKey: field.key, fieldName: field.name };
280
+ return {
281
+ ownerRefName: refName,
282
+ ownerKind,
283
+ ownerName: name,
284
+ ...(namespace !== undefined ? { ownerNamespace: namespace } : {}),
285
+ fieldKey: field.key,
286
+ fieldName: field.name,
287
+ ...(field.fieldType !== undefined ? { fieldType: field.fieldType } : {}),
288
+ outsideWorkspace: true,
289
+ };
290
+ }
205
291
  }
206
292
  return undefined;
207
293
  }
@@ -211,8 +297,8 @@ function resolveRelatedField(v, ctx) {
211
297
  * ref-only dependency data address resolves to its generated catalog member;
212
298
  * a preserved raw id remains an explicit unresolved/unsafe fallback.
213
299
  */
214
- function dynamicPicklistFilterFieldRef(value, owner, ctx) {
215
- const resolved = resolveRelatedOrSelfField(value, owner, ctx);
300
+ function dynamicPicklistFilterFieldRef(value, owner, ctx, selfSourced) {
301
+ const resolved = resolveRelatedOrSelfField(value, owner, ctx, selfSourced);
216
302
  if (typeof resolved === "string")
217
303
  return { kind: "unresolved", uuid: resolved, hint: "field" };
218
304
  if (resolved !== undefined) {
@@ -278,16 +364,18 @@ function blockReplaceForcingDrop(ctx, site, attr, reason) {
278
364
  */
279
365
  function blockDynamicConfigDrop(ctx, site, reason, labelOnly = false) {
280
366
  // 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.
367
+ // resolved, so pulling it (again) cannot help: the export names the label
368
+ // field in a form pull cannot decode. `pull element` has no
369
+ // --with-dependencies, so the remedy names the pull itself.
283
370
  reportAuthoringBlocker(ctx, {
284
371
  address: site.address,
285
372
  description: `${site.where}: ${reason}. Dropping dynamic_config would author an empty static Dropdown, ` +
286
373
  "which plan rejects and which would replace the live dynamic options.",
287
374
  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.",
375
+ ? "The source app/element resolves, but the export's label field reference can't be decoded, so pulling the source won't help. " +
376
+ "Hand-author the Dropdown's dynamic config (source and label field) in the owning app/element file."
377
+ : "Make the Dropdown's source app/element and label field resolvable (pull the source into this workspace with " +
378
+ "`elementum pull app`/`pull element` first), then retry.",
291
379
  });
292
380
  }
293
381
  /**
@@ -301,7 +389,7 @@ function blockUnclearableParentMappings(ctx, site) {
301
389
  address: site.address,
302
390
  description: `${site.where}: dynamic_config parent mapping field IDs could not be reconstructed. The platform keeps parent mappings ` +
303
391
  `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.",
392
+ remedy: "Pull the apps/elements that own the mapped parent/source fields into this workspace (`elementum pull app`/`pull element`), or change the Dropdown's parent mappings in the Elementum UI, then pull again.",
305
393
  });
306
394
  }
307
395
  /**
@@ -328,8 +416,10 @@ function dynamicConfigFromTf(value, owner, ctx, site) {
328
416
  return undefined;
329
417
  }
330
418
  const attrs = value;
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);
419
+ const selfSource = selfRelatedObject(attrs["related_aspect_id"], owner, ctx);
420
+ const selfSourced = selfSource !== undefined;
421
+ const relatedAspectId = selfSource ?? resolveRelatedObject(attrs["related_aspect_id"], ctx, /* namespaceFallback (#1440) */ true);
422
+ const relatedLabelFieldId = resolveRelatedOrSelfField(attrs["related_label_field_id"], owner, ctx, selfSourced);
333
423
  if (relatedAspectId === undefined || relatedLabelFieldId === undefined) {
334
424
  const missing = [
335
425
  relatedAspectId === undefined && "related_aspect_id",
@@ -351,7 +441,7 @@ function dynamicConfigFromTf(value, owner, ctx, site) {
351
441
  if (attrs["filter"] !== undefined) {
352
442
  try {
353
443
  filter = deserializeFilterFromTf(attrs["filter"], {
354
- field: (v) => dynamicPicklistFilterFieldRef(v, owner, ctx),
444
+ field: (v) => dynamicPicklistFilterFieldRef(v, owner, ctx, selfSourced),
355
445
  recordField: (v) => dynamicPicklistRecordFieldRef(v, owner, ctx),
356
446
  recordFieldOwner: (v) => resourceRefLabel(v, owner.type) === owner.label,
357
447
  reference: () => {
@@ -388,7 +478,7 @@ function dynamicConfigFromTf(value, owner, ctx, site) {
388
478
  unresolvedField = true;
389
479
  return rawOrder;
390
480
  }
391
- const resolved = resolveRelatedOrSelfField(field, owner, ctx);
481
+ const resolved = resolveRelatedOrSelfField(field, owner, ctx, selfSourced);
392
482
  if (resolved === undefined)
393
483
  unresolvedField = true;
394
484
  return resolved === undefined ? rawOrder : { ...order, field: resolved };
@@ -421,8 +511,8 @@ function dynamicConfigFromTf(value, owner, ctx, site) {
421
511
  // Dropdown's sources), so resolve them like related_label_field_id:
422
512
  // raw/imported id, else the foreign data.elementum_field identity (#1404),
423
513
  // 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);
514
+ const parentAspectFieldId = resolveRelatedOrSelfField(mapping["parent_aspect_field_id"], owner, ctx, selfSourced);
515
+ const relatedAspectFieldId = resolveRelatedOrSelfField(mapping["related_aspect_field_id"], owner, ctx, selfSourced);
426
516
  if (parentAspectFieldId === undefined || relatedAspectFieldId === undefined) {
427
517
  blockUnclearableParentMappings(ctx, site);
428
518
  parentMappings = undefined;
@@ -675,6 +765,7 @@ export function fieldFromTf(block, owner, ctx) {
675
765
  }
676
766
  }
677
767
  const scope = owner.scope ?? "app";
768
+ const allowList = allowListFromTf(subType.typeKey, attrs, owner, ctx, { address: `${block.type}.${fieldLabel}`, where });
678
769
  const calculation = subType.typeKey === "calculated" ? optionalString(attrs, "calculation", where, ctx) : undefined;
679
770
  if (subType.typeKey === "calculated" && calculation === undefined) {
680
771
  blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, "calculation is missing", MALFORMED_FIELD_REMEDY);
@@ -735,9 +826,94 @@ export function fieldFromTf(block, owner, ctx) {
735
826
  ...(autoRelate !== undefined && { autoRelate }),
736
827
  ...(numericFormat !== undefined && { numericFormat }),
737
828
  ...(decimalPlaces !== undefined && { decimalPlaces }),
829
+ ...(allowList.allowedGroups !== undefined && { allowedGroups: allowList.allowedGroups }),
830
+ ...(allowList.allowedUsers !== undefined && { allowedUsers: allowList.allowedUsers }),
738
831
  },
832
+ ...(allowList.parentGroupFieldKey !== undefined && { parentGroupFieldKey: allowList.parentGroupFieldKey }),
739
833
  };
740
834
  }
835
+ /**
836
+ * Group/user field pick-list restrictions (edk#1776). Each principal must
837
+ * decode to a portable identity (a group name lookup, a user email lookup, a
838
+ * same-owner group field). One that does not is an authoring blocker, never
839
+ * dropped: printing the rest would let the next apply broaden who can be
840
+ * picked, or plan an error over the live restriction.
841
+ */
842
+ function compareText(a, b) {
843
+ return a < b ? -1 : a > b ? 1 : 0;
844
+ }
845
+ function allowListFromTf(typeKey, attrs, owner, ctx, site) {
846
+ if (typeKey !== "group" && typeKey !== "user")
847
+ return {};
848
+ const remedy = "Give each restricted group a unique name and make sure each restricted user has an email (or remove that entry from the field's " +
849
+ "restriction in the Elementum UI), then pull again.";
850
+ const block = (attr, reason) => {
851
+ reportAuthoringBlocker(ctx, {
852
+ address: site.address,
853
+ description: `${site.where}: ${attr} ${reason}; leaving it out would remove part of the live pick-list restriction.`,
854
+ remedy,
855
+ });
856
+ };
857
+ const out = {};
858
+ const groups = attrs["allowed_group_ids"];
859
+ if (groups !== undefined) {
860
+ if (!Array.isArray(groups))
861
+ block("allowed_group_ids", "is not a list");
862
+ else {
863
+ const list = [];
864
+ for (const value of groups) {
865
+ const label = dataRefLabel(value, "elementum_group");
866
+ const name = label === undefined ? undefined : ctx.dataName("elementum_group", label);
867
+ if (label === undefined || name === undefined || name.trim() === "") {
868
+ block("allowed_group_ids", "has a group without a portable name lookup");
869
+ continue;
870
+ }
871
+ list.push({ __kind: "group", refName: groupCatalogKey(ctx, label, name), name });
872
+ }
873
+ // Print in a portable order (org.ts key, then name), never platform-id
874
+ // order: ids differ per org, so id order would reprint differently there.
875
+ out.allowedGroups = list.sort((a, b) => compareText(a.refName, b.refName) || compareText(a.name ?? "", b.name ?? ""));
876
+ }
877
+ }
878
+ const users = attrs["allowed_user_ids"];
879
+ if (users !== undefined) {
880
+ if (typeKey !== "user")
881
+ block("allowed_user_ids", "is set on a group field");
882
+ else if (!Array.isArray(users))
883
+ block("allowed_user_ids", "is not a list");
884
+ else {
885
+ const list = [];
886
+ for (const value of users) {
887
+ const label = dataRefLabel(value, "elementum_user");
888
+ const email = label === undefined ? undefined : ctx.dataName("elementum_user", label)?.trim();
889
+ if (email === undefined || !/^[^\s@]+@[^\s@]+$/.test(email)) {
890
+ block("allowed_user_ids", "has a user without a portable email lookup");
891
+ continue;
892
+ }
893
+ list.push({ __kind: "user", email });
894
+ }
895
+ out.allowedUsers = list.sort((a, b) => compareText(a.email, b.email));
896
+ }
897
+ }
898
+ const parent = attrs["parent_group_field_id"];
899
+ if (parent !== undefined) {
900
+ if (typeKey !== "user")
901
+ block("parent_group_field_id", "is set on a group field");
902
+ else if (parent === "")
903
+ out.parentGroupFieldKey = null;
904
+ else {
905
+ const isGroupFieldRef = isTfExpr(parent) && parent.$expr === "resource-attr" && parent.type === "elementum_group_field";
906
+ const key = typeof parent === "string" || isGroupFieldRef
907
+ ? fieldKeyFromTfValue(parent, owner.refName ?? "", owner.label, owner.scope ?? "app", ctx)
908
+ : undefined;
909
+ if (key === undefined)
910
+ block("parent_group_field_id", "does not resolve to a group field on the same app or element");
911
+ else
912
+ out.parentGroupFieldKey = key;
913
+ }
914
+ }
915
+ return out;
916
+ }
741
917
  /**
742
918
  * `<resourceType>.<tfLabel>.id` → the field's bag key — shared by anything
743
919
  * that names a field by ref rather than owning it directly (agent-tool
@@ -2,3 +2,9 @@
2
2
  import { type EntityKindModule } from "../../graph/types.js";
3
3
  export declare const FIELD_DATA_RESOURCE_TYPE = "elementum_field";
4
4
  export declare const fieldModule: EntityKindModule;
5
+ /**
6
+ * `elementum_managed_field_order` orders an owner's custom fields. Build emits
7
+ * it from the authored `fields` key order; pull prints fields in its order.
8
+ * Like the managed view order, its import/state id is the owner's id.
9
+ */
10
+ export declare const managedFieldOrderModule: EntityKindModule;
@@ -1,7 +1,8 @@
1
1
  /** The field entity's registry entry (see src/graph/). */
2
2
  import { asNamedRef, namedFactoryEntry } from "../../catalog/render-helpers.js";
3
- import { NO_LIFECYCLE } from "../../graph/types.js";
4
- import { FIELD_SUB_TYPES } from "./types.js";
3
+ import { NO_CANVAS, NO_CATALOG, NO_DATA, NO_LIFECYCLE } from "../../graph/types.js";
4
+ import { managedFieldOrderStateAdoption } from "./order.js";
5
+ import { FIELD_SUB_TYPES, MANAGED_FIELD_ORDER_RESOURCE_TYPE } from "./types.js";
5
6
  export const FIELD_DATA_RESOURCE_TYPE = "elementum_field";
6
7
  export const fieldModule = {
7
8
  kind: "field",
@@ -71,3 +72,24 @@ export const fieldModule = {
71
72
  refFromAuthoring: () => undefined,
72
73
  },
73
74
  };
75
+ /**
76
+ * `elementum_managed_field_order` orders an owner's custom fields. Build emits
77
+ * it from the authored `fields` key order; pull prints fields in its order.
78
+ * Like the managed view order, its import/state id is the owner's id.
79
+ */
80
+ export const managedFieldOrderModule = {
81
+ kind: "managed-field-order",
82
+ stream: { role: "streamMember" },
83
+ authoring: { unit: "inline", bag: "fields" },
84
+ parents: [
85
+ { parent: "app", child: "managed-field-order" },
86
+ { parent: "element", child: "managed-field-order" },
87
+ { parent: "task", child: "managed-field-order" },
88
+ ],
89
+ resource: { shape: "single", resourceType: MANAGED_FIELD_ORDER_RESOURCE_TYPE, adoptable: true },
90
+ data: NO_DATA,
91
+ lifecycle: NO_LIFECYCLE,
92
+ canvas: NO_CANVAS,
93
+ catalog: NO_CATALOG,
94
+ stateAdoption: managedFieldOrderStateAdoption,
95
+ };
@@ -16,6 +16,8 @@ export interface PicklistValueWire {
16
16
  readonly icon?: string;
17
17
  readonly active?: boolean;
18
18
  readonly relatedParentValues?: unknown;
19
+ /** Stage options only: explicit Terraform stage alias (AppStageOption.key). */
20
+ readonly __stageKey?: string;
19
21
  }
20
22
  export declare function picklistLabel(pv: PicklistValueWire): string;
21
23
  export declare const KNOWN_OPTION_TAGS: ReadonlySet<PicklistOptionTag>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The custom fields' order (#1670): `elementum_managed_field_order` lists an
3
+ * owner's field resources in authored `fields` key order. The platform's own
4
+ * order is whatever order the field creates finished in, so without it the
5
+ * default column order and every pull's field order drift between applies.
6
+ */
7
+ import { type TfBlock, type TfExpr } from "../../engine/tf/index.js";
8
+ import { type FieldOwnerScope } from "../../engine/tf/labels.js";
9
+ import type { StateAdoptionFacet } from "../../graph/types.js";
10
+ /** The owner's field order block, or undefined when it has no field resource. `fieldAddresses` iterates in authored order. */
11
+ export declare function managedFieldOrderToTf(ownerTfLabel: string, scope: FieldOwnerScope, objectId: TfExpr, fieldAddresses: ReadonlyMap<string, string>): TfBlock | undefined;
12
+ /**
13
+ * `fieldBlocks` in the order the owner's field order lists them, so pull prints
14
+ * fields in the platform's order instead of the parser's type-and-label order.
15
+ * Fields it doesn't list keep their relative order after the listed ones.
16
+ */
17
+ export declare function inManagedFieldOrder(fieldBlocks: readonly TfBlock[], orderBlocks: readonly TfBlock[]): readonly TfBlock[];
18
+ /**
19
+ * #1699: a workspace pulled before #1677 has no field order state, so the
20
+ * built order would plan a hidden create (a live reorder). When the owner is
21
+ * in state but its order isn't, import the live order (keyed by the owner's
22
+ * id, like the provider's ImportState); the plan then shows any reorder as a
23
+ * visible in-place `field_ids` update.
24
+ */
25
+ export declare const managedFieldOrderStateAdoption: StateAdoptionFacet;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The custom fields' order (#1670): `elementum_managed_field_order` lists an
3
+ * owner's field resources in authored `fields` key order. The platform's own
4
+ * order is whatever order the field creates finished in, so without it the
5
+ * default column order and every pull's field order drift between applies.
6
+ */
7
+ import { expr, isTfExpr } from "../../engine/tf/index.js";
8
+ import { scopedResourceLabel } from "../../engine/tf/labels.js";
9
+ import { MANAGED_FIELD_ORDER_RESOURCE_TYPE } from "./types.js";
10
+ /** The owner's field order block, or undefined when it has no field resource. `fieldAddresses` iterates in authored order. */
11
+ export function managedFieldOrderToTf(ownerTfLabel, scope, objectId, fieldAddresses) {
12
+ if (fieldAddresses.size === 0)
13
+ return undefined;
14
+ const fieldIds = [...fieldAddresses.values()].map((address) => {
15
+ const dot = address.indexOf(".");
16
+ return expr.resourceAttr(address.slice(0, dot), address.slice(dot + 1), ["id"]);
17
+ });
18
+ return {
19
+ kind: "resource",
20
+ type: MANAGED_FIELD_ORDER_RESOURCE_TYPE,
21
+ label: scopedResourceLabel(ownerTfLabel, "field_order", scope),
22
+ attrs: { object_id: objectId, field_ids: fieldIds },
23
+ };
24
+ }
25
+ /**
26
+ * `fieldBlocks` in the order the owner's field order lists them, so pull prints
27
+ * fields in the platform's order instead of the parser's type-and-label order.
28
+ * Fields it doesn't list keep their relative order after the listed ones.
29
+ */
30
+ export function inManagedFieldOrder(fieldBlocks, orderBlocks) {
31
+ const fieldIds = orderBlocks[0]?.attrs["field_ids"];
32
+ if (!Array.isArray(fieldIds))
33
+ return fieldBlocks;
34
+ const position = new Map();
35
+ for (const [index, value] of fieldIds.entries()) {
36
+ if (isTfExpr(value) && value.$expr === "resource-attr")
37
+ position.set(`${value.type}.${value.label}`, index);
38
+ }
39
+ const at = (block) => position.get(`${block.type}.${block.label}`) ?? Number.MAX_SAFE_INTEGER;
40
+ return [...fieldBlocks].sort((a, b) => at(a) - at(b));
41
+ }
42
+ /**
43
+ * #1699: a workspace pulled before #1677 has no field order state, so the
44
+ * built order would plan a hidden create (a live reorder). When the owner is
45
+ * in state but its order isn't, import the live order (keyed by the owner's
46
+ * id, like the provider's ImportState); the plan then shows any reorder as a
47
+ * visible in-place `field_ids` update.
48
+ */
49
+ export const managedFieldOrderStateAdoption = {
50
+ importsFor(blocks, state) {
51
+ const out = [];
52
+ for (const block of blocks) {
53
+ if (block.kind !== "resource" || block.type !== MANAGED_FIELD_ORDER_RESOURCE_TYPE || block.label === undefined)
54
+ continue;
55
+ if (state.has(block.type, block.label))
56
+ continue;
57
+ const owner = block.attrs["object_id"];
58
+ if (!isTfExpr(owner) || owner.$expr !== "resource-attr")
59
+ continue;
60
+ const id = state.idOf(owner.type, owner.label);
61
+ if (id !== undefined)
62
+ out.push({ type: block.type, label: block.label, id });
63
+ }
64
+ return out;
65
+ },
66
+ warning(imports) {
67
+ const names = imports.slice(0, 5).map((i) => i.label).join(", ");
68
+ const more = imports.length > 5 ? `, … (+${imports.length - 5} more)` : "";
69
+ return [
70
+ `${imports.length} owner(s) have no ${MANAGED_FIELD_ORDER_RESOURCE_TYPE} state (workspace pulled before field order was managed): ${names}${more}.`,
71
+ "Importing their live field order; any field_ids change in the plan is a real reorder. Re-pull before applying to keep the live order.",
72
+ ].join("\n");
73
+ },
74
+ };
@@ -116,6 +116,12 @@ export interface FieldInnerWire {
116
116
  readonly decimalPlaces?: number;
117
117
  /** Attachment fields only — allowed MIME types. Omitted from HCL when unset or empty. */
118
118
  readonly mediaTypes?: readonly string[];
119
+ /** Group/user fields only (edk#1776) — slim `org.groups` tokens. `[]` is an explicit clear. */
120
+ readonly allowedGroups?: readonly unknown[];
121
+ /** User fields only — `userRef(email)` tokens. `[]` is an explicit clear. */
122
+ readonly allowedUsers?: readonly unknown[];
123
+ /** User fields only — a same-owner group field token; `null` is an explicit clear. */
124
+ readonly parentGroupField?: FieldTokenWire | null;
119
125
  }
120
126
  export interface FieldToTfOptions {
121
127
  /** The owning stream root's terraform label (namespace). */