@elementumai/edk 0.10.2 → 0.10.4

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 (127) 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 +69 -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 +2 -1
  18. package/dist-sdk/src/engine/tf/index.js +2 -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/tf/scan.d.ts +22 -0
  23. package/dist-sdk/src/engine/tf/scan.js +123 -0
  24. package/dist-sdk/src/engine/workspace/backend.d.ts +34 -0
  25. package/dist-sdk/src/engine/workspace/backend.js +104 -0
  26. package/dist-sdk/src/engine/workspace/generated-file.d.ts +3 -0
  27. package/dist-sdk/src/engine/workspace/generated-file.js +6 -0
  28. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  29. package/dist-sdk/src/engine/workspace/loader.js +22 -2
  30. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  31. package/dist-sdk/src/entities/agent/to-tf.js +17 -12
  32. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  33. package/dist-sdk/src/entities/agent-tool/to-tf.js +10 -1
  34. package/dist-sdk/src/entities/app/build.d.ts +36 -4
  35. package/dist-sdk/src/entities/app/build.js +67 -4
  36. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +18 -0
  37. package/dist-sdk/src/entities/app/from-tf.js +17 -9
  38. package/dist-sdk/src/entities/app/module.js +1 -0
  39. package/dist-sdk/src/entities/app/stage-keys.d.ts +82 -0
  40. package/dist-sdk/src/entities/app/stage-keys.js +160 -0
  41. package/dist-sdk/src/entities/app/to-tf.js +17 -21
  42. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +9 -1
  43. package/dist-sdk/src/entities/approval-chain/from-tf.js +31 -3
  44. package/dist-sdk/src/entities/approval-chain/module.js +12 -4
  45. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +1 -0
  46. package/dist-sdk/src/entities/approval-chain/to-tf.js +6 -1
  47. package/dist-sdk/src/entities/automation/build.js +25 -8
  48. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -0
  49. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +5 -3
  50. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +90 -17
  51. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  52. package/dist-sdk/src/entities/automation/from-tf.js +140 -23
  53. package/dist-sdk/src/entities/automation/module.js +158 -44
  54. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  55. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  56. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +2 -0
  57. package/dist-sdk/src/entities/automation/output-key-wire-name.js +18 -0
  58. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -1
  59. package/dist-sdk/src/entities/automation/to-tf.js +200 -38
  60. package/dist-sdk/src/entities/automation/triggers.d.ts +2 -0
  61. package/dist-sdk/src/entities/automation/triggers.js +1 -0
  62. package/dist-sdk/src/entities/chart/from-tf.d.ts +6 -0
  63. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  64. package/dist-sdk/src/entities/dashboard/from-tf.js +51 -4
  65. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +48 -4
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +2 -0
  68. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -2
  69. package/dist-sdk/src/entities/element/build.js +1 -1
  70. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -6
  71. package/dist-sdk/src/entities/element/from-tf.js +26 -8
  72. package/dist-sdk/src/entities/element/module.js +3 -2
  73. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -2
  74. package/dist-sdk/src/entities/element/to-tf.js +32 -25
  75. package/dist-sdk/src/entities/field/allow-list.d.ts +18 -0
  76. package/dist-sdk/src/entities/field/allow-list.js +42 -0
  77. package/dist-sdk/src/entities/field/build.d.ts +38 -3
  78. package/dist-sdk/src/entities/field/build.js +7 -2
  79. package/dist-sdk/src/entities/field/from-tf.js +178 -20
  80. package/dist-sdk/src/entities/field/module.js +2 -0
  81. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  82. package/dist-sdk/src/entities/field/order.d.ts +9 -0
  83. package/dist-sdk/src/entities/field/order.js +33 -0
  84. package/dist-sdk/src/entities/field/to-tf.d.ts +6 -0
  85. package/dist-sdk/src/entities/field/to-tf.js +87 -0
  86. package/dist-sdk/src/entities/field/types.js +3 -0
  87. package/dist-sdk/src/entities/relationship/build.d.ts +3 -3
  88. package/dist-sdk/src/entities/relationship/from-tf.js +4 -2
  89. package/dist-sdk/src/entities/relationship/to-tf.js +3 -1
  90. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +8 -3
  91. package/dist-sdk/src/entities/service-account/workspace-owner.js +12 -4
  92. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +5 -0
  93. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +13 -0
  94. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -0
  95. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +1 -1
  96. package/dist-sdk/src/entities/skill/module.js +28 -2
  97. package/dist-sdk/src/entities/skill/to-tf.js +19 -14
  98. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  99. package/dist-sdk/src/entities/skill-tool/from-tf.js +3 -0
  100. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +6 -1
  101. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -1
  102. package/dist-sdk/src/entities/task/build.js +1 -1
  103. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +2 -0
  104. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -2
  105. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +11 -0
  106. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +13 -38
  107. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +29 -0
  108. package/dist-sdk/src/entities/view/custom-view-validate.js +293 -0
  109. package/dist-sdk/src/entities/view/from-tf.d.ts +10 -0
  110. package/dist-sdk/src/entities/view/from-tf.js +164 -26
  111. package/dist-sdk/src/entities/view/to-tf.d.ts +6 -0
  112. package/dist-sdk/src/entities/view/to-tf.js +14 -6
  113. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +2 -1
  114. package/dist-sdk/src/entities/visual-flow/from-tf.js +11 -2
  115. package/dist-sdk/src/entities/visual-flow/module.js +15 -5
  116. package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/visual-flow/to-tf.js +1 -1
  118. package/dist-sdk/src/entities/widget/build.d.ts +8 -1
  119. package/dist-sdk/src/entities/widget/from-tf.js +12 -6
  120. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  121. package/dist-sdk/src/entities/widget/to-tf.js +16 -0
  122. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +8 -2
  123. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  124. package/dist-sdk/src/graph/index.d.ts +6 -0
  125. package/dist-sdk/src/graph/index.js +1 -0
  126. package/dist-sdk/src/graph/types.d.ts +66 -2
  127. package/package.json +2 -17
@@ -3,6 +3,7 @@ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_REQU
3
3
  import { serializeDisplayBlocks } from "./display-blocks.js";
4
4
  import { assertCalculatedFieldRoot } from "../field/calc/runtime.js";
5
5
  import { assertAttachmentMediaTypes } from "../field/media-types.js";
6
+ import { assertFieldAllowList } from "../field/allow-list.js";
6
7
  /** Where a classic layout section renders: the main area or the record side panel. */
7
8
  export const layoutSectionDisplayLocation = {
8
9
  center: "CENTER",
@@ -99,6 +100,11 @@ function assertSystemFieldRules(field) {
99
100
  function shouldSerializePicklistOptions(field) {
100
101
  return field.type === "PICKLIST" || field.type === "MULTI_PICKLIST";
101
102
  }
103
+ /** A stage option's wire value; only stages carry the explicit `key` alias (#1136). */
104
+ function stagePicklistValue(opt) {
105
+ const value = picklistValue(opt);
106
+ return typeof opt !== "string" && opt.key !== undefined ? { ...value, __stageKey: opt.key } : value;
107
+ }
102
108
  function picklistValue(opt) {
103
109
  if (typeof opt === "string")
104
110
  return { value: opt, label: opt };
@@ -123,6 +129,47 @@ function unwrapUnsafePlatformIds(value) {
123
129
  }
124
130
  return value;
125
131
  }
132
+ /**
133
+ * The refs a dynamic Dropdown or Multi-Select names directly in
134
+ * `config.dynamic` must be present (edk#1780): `source`, `label`,
135
+ * `parent.field`, each `parent.mappings[i]` side and each `sort[i].field`. A
136
+ * catalog path to a field or app/element/task that was removed or renamed (or
137
+ * added without re-running `elementum generate`) evaluates to `undefined`; the
138
+ * TF emitter then drops the whole dynamic config, omits the field resource,
139
+ * and the plan destroys the field. Throw instead, naming the owner, the
140
+ * field's bag key and the missing ref, so the build fails closed. `filter`
141
+ * operands are NOT checked here (out of scope for #1780).
142
+ */
143
+ function assertDynamicPicklistRefs(field, dynamic, refName, owner) {
144
+ const typeLabel = field.type === "MULTI_PICKLIST" ? "Multi-Select" : "Dropdown";
145
+ const where = `${owner !== undefined ? `${owner} ` : ""}${refName !== undefined ? `fields.${refName}` : "field"} ` +
146
+ `(${JSON.stringify(field.name)}, dynamic ${typeLabel})`;
147
+ const missing = (path) => {
148
+ throw new Error(`${where}: ${path} is undefined. The catalog ref it names doesn't resolve: the referenced field, app, element ` +
149
+ `or task was removed or renamed, or it was just added and the catalog hasn't been regenerated (run ` +
150
+ `\`elementum generate\`, then build again). Building would drop this field's dynamic config and the plan ` +
151
+ `would destroy the field; fix or remove the ref.`);
152
+ };
153
+ if (dynamic.relatedAspectId == null)
154
+ missing("config.dynamic.source");
155
+ if (dynamic.relatedLabelFieldId == null)
156
+ missing("config.dynamic.label");
157
+ if (Object.hasOwn(dynamic, "parentFieldId") && dynamic.parentFieldId == null)
158
+ missing("config.dynamic.parent.field");
159
+ dynamic.parentMappings?.forEach((mapping, i) => {
160
+ if (mapping.parentAspectFieldId == null)
161
+ missing(`config.dynamic.parent.mappings[${i}].parentSourceField`);
162
+ if (mapping.relatedAspectFieldId == null)
163
+ missing(`config.dynamic.parent.mappings[${i}].sourceField`);
164
+ });
165
+ const orders = dynamic.sort?.orders;
166
+ if (Array.isArray(orders)) {
167
+ orders.forEach((order, i) => {
168
+ if (order.field == null)
169
+ missing(`config.dynamic.sort[${i}].field`);
170
+ });
171
+ }
172
+ }
126
173
  /**
127
174
  * Serialize an authored field to its `AspectFieldInput` wire shape — shared
128
175
  * with `element`. `refName` is the field's bag key in `app`'s
@@ -134,9 +181,11 @@ function unwrapUnsafePlatformIds(value) {
134
181
  * else. Matching on the bag key instead of `name` is what lets a field's
135
182
  * identity survive a display-`name` rename instead of being keyed by the
136
183
  * mutable `name` (#230); the bag key itself is never rewritten by a rename,
137
- * since it's just the field's fixed key in `fields: {}`.
184
+ * since it's just the field's fixed key in `fields: {}`. `owner` (e.g.
185
+ * `app "Vendor Onboarding"`) only labels authoring errors, so fields that
186
+ * share a display name in different owners can be told apart.
138
187
  */
139
- export function serializeField(field, refName) {
188
+ export function serializeField(field, refName, owner) {
140
189
  assertSystemFieldRules(field);
141
190
  const key = TYPE_TO_KEY[field.type] ?? "text";
142
191
  const base = {
@@ -172,6 +221,8 @@ export function serializeField(field, refName) {
172
221
  base.picklistValues = field.options.map(picklistValue);
173
222
  }
174
223
  if (field.config !== undefined) {
224
+ if (field.config.dynamic !== undefined)
225
+ assertDynamicPicklistRefs(field, field.config.dynamic, refName, owner);
175
226
  base.config = unwrapUnsafePlatformIds(field.config);
176
227
  }
177
228
  else if (field.parentField !== undefined) {
@@ -195,6 +246,18 @@ export function serializeField(field, refName) {
195
246
  if ((key === "text" || key === "html") && field.qrFormat !== undefined) {
196
247
  base.format = field.qrFormat;
197
248
  }
249
+ if (key === "group" || key === "user") {
250
+ assertFieldAllowList(field, key);
251
+ if (field.allowedGroups !== undefined)
252
+ base.allowedGroups = [...field.allowedGroups];
253
+ if (key === "user" && field.allowedUsers !== undefined)
254
+ base.allowedUsers = [...field.allowedUsers];
255
+ if (key === "user" && field.parentGroupField !== undefined)
256
+ base.parentGroupField = field.parentGroupField;
257
+ }
258
+ else if (field.allowedGroups !== undefined || field.allowedUsers !== undefined || field.parentGroupField !== undefined) {
259
+ throw new Error(`field "${field.name}": allowedGroups, allowedUsers and parentGroupField are only valid on group and user fields.`);
260
+ }
198
261
  if (key === "relation") {
199
262
  if (field.relatedObject !== undefined)
200
263
  base.relatedObject = unwrapUnsafePlatformIds(field.relatedObject);
@@ -257,7 +320,7 @@ export function serializeSystemFields(overrides) {
257
320
  ...flags,
258
321
  tags: [tag],
259
322
  __refName: key,
260
- picklistValues: override.options.map(picklistValue),
323
+ picklistValues: override.options.map(stagePicklistValue),
261
324
  },
262
325
  };
263
326
  }
@@ -508,7 +571,7 @@ export function app(opts) {
508
571
  ...(opts.autoShare !== undefined ? { autoShare: opts.autoShare } : {}),
509
572
  fields: [
510
573
  ...serializeSystemFields(opts.systemFields),
511
- ...Object.entries(opts.fields).map(([bagKey, field]) => serializeField(field, bagKey)),
574
+ ...Object.entries(opts.fields).map(([bagKey, field]) => serializeField(field, bagKey, `app ${JSON.stringify(opts.name)}`)),
512
575
  ],
513
576
  ...(displayBlocks !== undefined ? { displayBlocks } : {}),
514
577
  ...(recordCreateDisplayBlocks !== undefined ? { recordCreateDisplayBlocks } : {}),
@@ -39,6 +39,12 @@ export interface NormalizedField {
39
39
  readonly calculationInclude?: "manual" | "both" | {
40
40
  readonly picklistFieldId: string;
41
41
  };
42
+ /**
43
+ * User fields only (edk#1776): the same-owner group field whose selected
44
+ * group's members are the only pickable users. A bag key, resolved by the
45
+ * printer to a hoisted FieldRef const; `null` = an explicit clear.
46
+ */
47
+ readonly parentGroupFieldKey?: string | null;
42
48
  /**
43
49
  * Side-channel pull annotation for dependent-picklist linkage.
44
50
  * Typed-ref `parentField` / `parentValues` on the runtime AppField
@@ -215,6 +221,12 @@ export interface NormalizedWidgetRef {
215
221
  readonly kind: "app" | "element" | "task" | "automation" | "field" | "recordIdentity";
216
222
  readonly key: string;
217
223
  readonly name: string;
224
+ /**
225
+ * Export display name, present only when pull read one. Build uses it to
226
+ * look up an automation that is not in source. Absent means `name` is not
227
+ * a display name.
228
+ */
229
+ readonly displayName?: string;
218
230
  readonly parent?: string;
219
231
  readonly fieldType?: string;
220
232
  readonly target?: NormalizedWidgetRef;
@@ -375,6 +387,12 @@ export interface NormalizedApp {
375
387
  readonly layouts?: readonly NormalizedLayout[];
376
388
  /** Saved list views (`elementum_list_view`). */
377
389
  readonly listViews?: readonly NormalizedListView[];
390
+ /**
391
+ * Platform ids pull kept in view field references because it did not
392
+ * extract their field (#1736). Print marks them as intentional instead of
393
+ * #1178's "replace with a real ref" TODO, which would drop the column.
394
+ */
395
+ readonly unextractedFieldIds?: readonly string[];
378
396
  /** Calendar views (`elementum_calendar_view`). */
379
397
  readonly calendarViews?: readonly NormalizedCalendarView[];
380
398
  /** Kanban views (`elementum_kanban_view`). */
@@ -11,7 +11,7 @@ import { autoShareFromTf } from "./auto-share.js";
11
11
  import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_KEY_BY_HCL_KEY, SYSTEM_FIELD_TAG_BY_KEY, } from "../../core/system-fields.js";
12
12
  import { EntityTfError } from "../../engine/entity.js";
13
13
  import { dataRefLabel, optionalString, plainObject } from "../../engine/pull/context.js";
14
- import { snakeSlug, tfLabelToTsLabel } from "../../engine/tf/index.js";
14
+ import { tfLabelToTsLabel } from "../../engine/tf/index.js";
15
15
  import { accessPolicyFromTf } from "../access-policy/from-tf.js";
16
16
  import { dynamicLayoutCompanionWidgetLabels, dynamicLayoutsFromTf, } from "../dynamic-layout/from-tf.js";
17
17
  import { dashboardsFromTf } from "../dashboard/from-tf.js";
@@ -24,6 +24,7 @@ import { serviceAccountsFromTf } from "../service-account/from-tf.js";
24
24
  import { viewsFromTf } from "../view/from-tf.js";
25
25
  import { widgetsFromTf } from "../widget/from-tf.js";
26
26
  import { APP_RESOURCE_TYPE } from "./module.js";
27
+ import { stageHandleIndex } from "./stage-keys.js";
27
28
  /** Attributes `appFromTf` understands — anything else is dialect growth, reported loudly. */
28
29
  const KNOWN_APP_ATTRS = new Set([
29
30
  "name",
@@ -196,12 +197,9 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
196
197
  ctx.diagnostics.push(`app "${label}": stages item has an unrecognized shape; dropped`);
197
198
  continue;
198
199
  }
199
- if (stageKey !== snakeSlug(stageName)) {
200
- // Build derives stage keys from names (snakeSlug) — a stream key that
201
- // doesn't match means a renamed stage, and a rebuilt stream will
202
- // differ there. Surface it now instead of failing the build-vs-export blind.
203
- ctx.diagnostics.push(`app "${label}": stage "${stageName}" has key "${stageKey}" but build derives "${snakeSlug(stageName)}" — was the stage renamed on the platform?`);
204
- }
200
+ // A stream key that isn't snakeSlug(name) (imported punctuation keys
201
+ // like "approval_&_execution") is carried verbatim: print emits it as
202
+ // the stage option's `key`, and build uses it instead of re-deriving (#1136).
205
203
  stages.push({ key: stageKey, stage: { id: "", name: stageName } });
206
204
  }
207
205
  }
@@ -214,14 +212,23 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
214
212
  if (appId === undefined) {
215
213
  ctx.diagnostics.push(`app "${label}": no import block in the stream — adoption has no identity to bind`);
216
214
  }
215
+ // One stage-handle map for every stage reference this app pulls (#1136).
216
+ const stageHandles = stageHandleIndex(stages.map((stage) => ({ key: stage.key, name: stage.stage.name })), ctx.diagnostics);
217
217
  // --- View pass: layouts / list views / view order (entities/view), owner passed in.
218
218
  const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: refName, ownerRefName: refName, scope: "app", ownerType: "APP_ASPECT" }, ctx);
219
- const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app", stageKeys: new Set(stages.map((stage) => stage.key)) }, ctx, viewBlocks.customViewBlocks);
219
+ const unextractedFieldIds = new Set();
220
+ const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, {
221
+ type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app",
222
+ stageKeys: stageHandles.keys,
223
+ stageKeyByHandle: stageHandles.byHandle,
224
+ fieldKeys: new Set(fields.map((field) => field.key)),
225
+ unextractedFieldIds,
226
+ }, ctx, viewBlocks.customViewBlocks);
220
227
  if (viewBlocks.recordCreateFormBlocks.length > 1) {
221
228
  ctx.diagnostics.push(`app "${label}": found ${viewBlocks.recordCreateFormBlocks.length} record create forms; only the first is used`);
222
229
  }
223
230
  const recordCreateForm = recordCreateFormFromTf(viewBlocks.recordCreateFormBlocks[0], { type: APP_RESOURCE_TYPE, label, ownerTfLabel: refName, scope: "app" }, ctx);
224
- const dynamicLayoutOwner = { type: APP_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label };
231
+ const dynamicLayoutOwner = { type: APP_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, stageHandles };
225
232
  const dynamicLayouts = dynamicLayoutsFromTf(viewBlocks.dynamicLayoutBlocks, dynamicLayoutOwner, ctx);
226
233
  const relationships = relationshipsFromTf(viewBlocks.relationshipBlocks, { kind: "app", label, ownerRefName: refName, ownerTfLabel: refName, scope: "app" }, ctx);
227
234
  const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: APP_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "app" }, ctx, dynamicLayoutCompanionWidgetLabels(viewBlocks.dynamicLayoutBlocks, dynamicLayoutOwner));
@@ -264,6 +271,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
264
271
  ...(autoShare !== undefined && { autoShare }),
265
272
  ...(layouts.length > 0 && { layouts }),
266
273
  ...(listViews.length > 0 && { listViews }),
274
+ ...(unextractedFieldIds.size > 0 && { unextractedFieldIds: [...unextractedFieldIds] }),
267
275
  ...(calendarViews.length > 0 && { calendarViews }),
268
276
  ...(kanbanViews.length > 0 && { kanbanViews }),
269
277
  ...(dashboardViews.length > 0 && { dashboardViews }),
@@ -77,6 +77,7 @@ export const appModule = {
77
77
  orgRefs: ctx.orgRefs,
78
78
  diagnostics: ctx.diagnostics,
79
79
  workspaceAspects: ctx.workspaceAspects,
80
+ ...(ctx.outOfScopeApps !== undefined && { outOfScopeApps: ctx.outOfScopeApps }),
80
81
  });
81
82
  return {
82
83
  blocks: result.blocks,
@@ -0,0 +1,82 @@
1
+ import { EntityTfError } from "../../engine/entity.js";
2
+ import { type PicklistValueWire } from "../field/options.js";
3
+ /** One app stage as build emits it: the real `stage_ids_by_key` key and its display name. */
4
+ export interface AppStageKey {
5
+ readonly key: string;
6
+ readonly name: string;
7
+ }
8
+ /** The provider's default stages when an app authors none. */
9
+ export declare const DEFAULT_APP_STAGES: readonly AppStageKey[];
10
+ /** A stage's real key: the imported alias when pull kept one, otherwise `snakeSlug(label)`. */
11
+ export declare function stageKeyFromPicklistValue(pv: PicklistValueWire): AppStageKey;
12
+ /**
13
+ * Every tf-label handle that authored source or pull can use for a stage,
14
+ * mapped to the stage's real `stage_ids_by_key` key (#1136). A layout bag key,
15
+ * a dynamic-layout `stage`, an approval chain `stage` or a visual-flow
16
+ * `stage` resolves through this map. Handles:
17
+ * - the real key itself, when it is a tf label. This covers renamed stages
18
+ * (`legacy_key` for "Renamed stage") and keys such as `foo__bar` that are
19
+ * legal tf labels but not the slug;
20
+ * - `snakeSlug(key)`, when the real key keeps punctuation
21
+ * (`enrichment_&_validation` -> `enrichment_validation`), which is the
22
+ * handle pull writes for it;
23
+ * - `snakeSlug(name)`, the handle authored apps use;
24
+ * - `SanitizeName(name)`, ei's classic-layout label, only where no other
25
+ * handle claimed it.
26
+ *
27
+ * A stage's own key always wins over a derived handle. When two stages
28
+ * derive the same handle, the first keeps it and a diagnostic says so,
29
+ * instead of silently rebinding. A stage left with no handle that maps to
30
+ * its own key (a punctuation key whose only handle is another stage's key,
31
+ * e.g. `pre-approval` next to `pre_approval`) is diagnosed too. Pull never
32
+ * writes another stage's handle for it: see {@link pulledStageHandle}.
33
+ */
34
+ export declare function stageKeyByHandle(stages: readonly AppStageKey[], diagnostics?: string[]): Map<string, string>;
35
+ /** An app's stage handles plus its real stage keys, for pull-side resolution (#1136). */
36
+ export interface StageHandleIndex {
37
+ readonly byHandle: ReadonlyMap<string, string>;
38
+ readonly keys: ReadonlySet<string>;
39
+ }
40
+ /** {@link stageKeyByHandle} plus the real key set. */
41
+ export declare function stageHandleIndex(stages: readonly AppStageKey[], diagnostics?: string[]): StageHandleIndex;
42
+ /** The stage handles of an `elementum_app` block's `stages` attribute, or undefined when it has none. */
43
+ export declare function stageHandleIndexFromTfStages(value: unknown): StageHandleIndex | undefined;
44
+ export type PulledStageHandle = {
45
+ readonly kind: "handle";
46
+ readonly handle: string;
47
+ }
48
+ /** The stage's only handle is another stage's: pull must not write it. */
49
+ | {
50
+ readonly kind: "lost";
51
+ readonly handle: string;
52
+ readonly owner: string;
53
+ } | {
54
+ readonly kind: "none";
55
+ };
56
+ /**
57
+ * The handle pull writes for a `stage_ids_by_key` index (#1136): one that
58
+ * build maps back to this same stage. Prefers `stageHandleTfLabel(index)`,
59
+ * then any other handle bound to the stage. When the stage has none (its
60
+ * slug is another stage's own key, e.g. `pre-approval` next to
61
+ * `pre_approval`), returns `lost`: writing that handle would bind the
62
+ * reference to the other stage on build, so the caller leaves the
63
+ * reference out with a diagnostic instead. Without an index (or for an
64
+ * index that is not one of the app's stages) this is `stageHandleTfLabel`.
65
+ */
66
+ export declare function pulledStageHandle(index: string, stages: StageHandleIndex | undefined): PulledStageHandle;
67
+ /**
68
+ * Thrown by an own-file extractor whose resource is left unmanaged because
69
+ * its stage lost its only handle (#1136). The extractor skips the resource
70
+ * AND releases it from state if an earlier pull adopted it, so the next plan
71
+ * does not destroy the live resource.
72
+ */
73
+ export declare class LostStageHandleError extends EntityTfError {
74
+ constructor(message: string);
75
+ }
76
+ /** The per-reference warning for a `lost` {@link pulledStageHandle}. */
77
+ export declare function lostStageMessage(where: string, index: string, lost: {
78
+ readonly handle: string;
79
+ readonly owner: string;
80
+ }, outcome: string): string;
81
+ /** The owning app's stage handles (see {@link stageKeyByHandle}) from its built payload, for child entities. */
82
+ export declare function appStageKeyByHandle(payload: unknown): Map<string, string> | undefined;
@@ -0,0 +1,160 @@
1
+ import { EntityTfError } from "../../engine/entity.js";
2
+ import { isTfLabel, sanitizeName, snakeSlug, stageHandleTfLabel } from "../../engine/tf/index.js";
3
+ import { picklistLabel } from "../field/options.js";
4
+ /** The provider's default stages when an app authors none. */
5
+ export const DEFAULT_APP_STAGES = [
6
+ { key: "stage_1", name: "Stage 1" },
7
+ { key: "stage_2", name: "Stage 2" },
8
+ ];
9
+ /** A stage's real key: the imported alias when pull kept one, otherwise `snakeSlug(label)`. */
10
+ export function stageKeyFromPicklistValue(pv) {
11
+ const name = picklistLabel(pv);
12
+ return { key: pv.__stageKey ?? snakeSlug(name), name };
13
+ }
14
+ /**
15
+ * Every tf-label handle that authored source or pull can use for a stage,
16
+ * mapped to the stage's real `stage_ids_by_key` key (#1136). A layout bag key,
17
+ * a dynamic-layout `stage`, an approval chain `stage` or a visual-flow
18
+ * `stage` resolves through this map. Handles:
19
+ * - the real key itself, when it is a tf label. This covers renamed stages
20
+ * (`legacy_key` for "Renamed stage") and keys such as `foo__bar` that are
21
+ * legal tf labels but not the slug;
22
+ * - `snakeSlug(key)`, when the real key keeps punctuation
23
+ * (`enrichment_&_validation` -> `enrichment_validation`), which is the
24
+ * handle pull writes for it;
25
+ * - `snakeSlug(name)`, the handle authored apps use;
26
+ * - `SanitizeName(name)`, ei's classic-layout label, only where no other
27
+ * handle claimed it.
28
+ *
29
+ * A stage's own key always wins over a derived handle. When two stages
30
+ * derive the same handle, the first keeps it and a diagnostic says so,
31
+ * instead of silently rebinding. A stage left with no handle that maps to
32
+ * its own key (a punctuation key whose only handle is another stage's key,
33
+ * e.g. `pre-approval` next to `pre_approval`) is diagnosed too. Pull never
34
+ * writes another stage's handle for it: see {@link pulledStageHandle}.
35
+ */
36
+ export function stageKeyByHandle(stages, diagnostics) {
37
+ const byHandle = new Map();
38
+ for (const stage of stages) {
39
+ if (isTfLabel(stage.key) && !byHandle.has(stage.key))
40
+ byHandle.set(stage.key, stage.key);
41
+ }
42
+ const derived = new Set();
43
+ const reported = new Set();
44
+ const lostTo = new Map();
45
+ for (const stage of stages) {
46
+ const handles = new Set();
47
+ if (!isTfLabel(stage.key)) {
48
+ const handle = stageHandleTfLabel(stage.key);
49
+ if (handle !== undefined)
50
+ handles.add(handle);
51
+ }
52
+ // Only tf labels are handles: `snakeSlug("1st Review")` is `1st_review`,
53
+ // which no source can carry (its handle is `_1st_review`, below).
54
+ const nameHandle = snakeSlug(stage.name);
55
+ if (isTfLabel(nameHandle))
56
+ handles.add(nameHandle);
57
+ for (const handle of handles) {
58
+ const existing = byHandle.get(handle);
59
+ if (existing === undefined) {
60
+ byHandle.set(handle, stage.key);
61
+ derived.add(handle);
62
+ }
63
+ else if (existing !== stage.key && derived.has(handle)) {
64
+ reported.add(stage.key);
65
+ diagnostics?.push(`systemFields.stage: stages "${existing}" and "${stage.key}" both derive the handle "${handle}"; it stays bound to "${existing}". Give the other stage an explicit key to reference it; until then pull leaves references that only that handle could carry unmanaged.`);
66
+ }
67
+ else if (existing !== stage.key && !lostTo.has(stage.key)) {
68
+ lostTo.set(stage.key, { handle, owner: existing });
69
+ }
70
+ }
71
+ }
72
+ // ei labels a stage's classic layout SanitizeName(stage name), which pull
73
+ // keeps as the layout bag key when it is a handle for that stage. Add it
74
+ // last and only where free, so it never displaces a key or slug handle.
75
+ for (const stage of stages) {
76
+ const exportHandle = sanitizeName(stage.name);
77
+ if (isTfLabel(exportHandle) && !byHandle.has(exportHandle))
78
+ byHandle.set(exportHandle, stage.key);
79
+ }
80
+ const bound = new Set(byHandle.values());
81
+ for (const stage of stages) {
82
+ const lost = lostTo.get(stage.key);
83
+ if (bound.has(stage.key) || reported.has(stage.key) || lost === undefined)
84
+ continue;
85
+ diagnostics?.push(`systemFields.stage: stage "${stage.key}" has no handle of its own: its handle "${lost.handle}" is stage "${lost.owner}"'s key. Source cannot reference "${stage.key}", so pull leaves its layouts, dynamic layouts, approval chains and flows unmanaged (each one warned) instead of binding them to "${lost.owner}". Rename one of the stages so each has its own handle.`);
86
+ }
87
+ return byHandle;
88
+ }
89
+ /** {@link stageKeyByHandle} plus the real key set. */
90
+ export function stageHandleIndex(stages, diagnostics) {
91
+ return { byHandle: stageKeyByHandle(stages, diagnostics), keys: new Set(stages.map((stage) => stage.key)) };
92
+ }
93
+ /** The stage handles of an `elementum_app` block's `stages` attribute, or undefined when it has none. */
94
+ export function stageHandleIndexFromTfStages(value) {
95
+ if (!Array.isArray(value))
96
+ return undefined;
97
+ const stages = [];
98
+ for (const item of value) {
99
+ if (typeof item !== "object" || item === null)
100
+ continue;
101
+ const { key, name } = item;
102
+ if (typeof key === "string" && typeof name === "string")
103
+ stages.push({ key, name });
104
+ }
105
+ return stageHandleIndex(stages);
106
+ }
107
+ /**
108
+ * The handle pull writes for a `stage_ids_by_key` index (#1136): one that
109
+ * build maps back to this same stage. Prefers `stageHandleTfLabel(index)`,
110
+ * then any other handle bound to the stage. When the stage has none (its
111
+ * slug is another stage's own key, e.g. `pre-approval` next to
112
+ * `pre_approval`), returns `lost`: writing that handle would bind the
113
+ * reference to the other stage on build, so the caller leaves the
114
+ * reference out with a diagnostic instead. Without an index (or for an
115
+ * index that is not one of the app's stages) this is `stageHandleTfLabel`.
116
+ */
117
+ export function pulledStageHandle(index, stages) {
118
+ const preferred = stageHandleTfLabel(index);
119
+ if (stages === undefined || !stages.keys.has(index))
120
+ return preferred === undefined ? { kind: "none" } : { kind: "handle", handle: preferred };
121
+ if (preferred !== undefined && stages.byHandle.get(preferred) === index)
122
+ return { kind: "handle", handle: preferred };
123
+ for (const [handle, key] of stages.byHandle)
124
+ if (key === index && isTfLabel(handle))
125
+ return { kind: "handle", handle };
126
+ if (preferred === undefined)
127
+ return { kind: "none" };
128
+ const owner = stages.byHandle.get(preferred);
129
+ return owner === undefined ? { kind: "handle", handle: preferred } : { kind: "lost", handle: preferred, owner };
130
+ }
131
+ /**
132
+ * Thrown by an own-file extractor whose resource is left unmanaged because
133
+ * its stage lost its only handle (#1136). The extractor skips the resource
134
+ * AND releases it from state if an earlier pull adopted it, so the next plan
135
+ * does not destroy the live resource.
136
+ */
137
+ export class LostStageHandleError extends EntityTfError {
138
+ constructor(message) {
139
+ super(message);
140
+ this.name = "LostStageHandleError";
141
+ }
142
+ }
143
+ /** The per-reference warning for a `lost` {@link pulledStageHandle}. */
144
+ export function lostStageMessage(where, index, lost, outcome) {
145
+ return `${where}: stage "${index}" has no handle of its own (its handle "${lost.handle}" is stage "${lost.owner}"'s key); ${outcome} instead of binding it to "${lost.owner}" (#1136)`;
146
+ }
147
+ /** The owning app's stage handles (see {@link stageKeyByHandle}) from its built payload, for child entities. */
148
+ export function appStageKeyByHandle(payload) {
149
+ if (typeof payload !== "object" || payload === null)
150
+ return undefined;
151
+ for (const entry of payload.fields ?? []) {
152
+ for (const inner of Object.values(entry)) {
153
+ if (inner?.tags?.includes("STAGE") !== true)
154
+ continue;
155
+ const values = inner.picklistValues ?? [];
156
+ return stageKeyByHandle(values.length === 0 ? DEFAULT_APP_STAGES : values.map(stageKeyFromPicklistValue));
157
+ }
158
+ }
159
+ return stageKeyByHandle(DEFAULT_APP_STAGES);
160
+ }
@@ -38,6 +38,7 @@ import { appServiceAccountBlocks } from "../service-account/to-tf.js";
38
38
  import { relationshipTargetsFromBag, widgetsToTf } from "../widget/to-tf.js";
39
39
  import { viewToTf } from "../view/to-tf.js";
40
40
  import { APP_RESOURCE_TYPE } from "./module.js";
41
+ import { DEFAULT_APP_STAGES, stageKeyByHandle, stageKeyFromPicklistValue } from "./stage-keys.js";
41
42
  /**
42
43
  * The named gap for a system-field tag with no canonical key (edk#1480).
43
44
  * Defensive: every tag in SYSTEM_FIELD_TAGS maps today, so a new tag lands
@@ -137,9 +138,8 @@ export function appToTf(entity, ctx) {
137
138
  const fieldMetadata = fieldMetadataFromEntries(payload.fields);
138
139
  const fieldNames = new Map();
139
140
  let statusOptions;
140
- let stages;
141
141
  const systemFieldConfig = {};
142
- const stageTfLabels = new Set();
142
+ let stageKeys;
143
143
  const objectId = expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]);
144
144
  const fieldDisplayNames = new Map();
145
145
  for (const fieldEntry of payload.fields ?? []) {
@@ -208,12 +208,9 @@ export function appToTf(entity, ctx) {
208
208
  ctx.diagnostics.push(`systemFields.stage: the provider has no stage field name attribute; authored name "${name}" dropped (field stays "Stage")`);
209
209
  }
210
210
  if (inner.picklistValues !== undefined) {
211
- stages = inner.picklistValues.map((pv) => {
212
- const label = picklistLabel(pv);
213
- const key = snakeSlug(label);
214
- stageTfLabels.add(key);
215
- return { key, name: label };
216
- });
211
+ // An imported stage keeps its alias (`__stageKey`, #1136); an
212
+ // authored one derives snakeSlug(label).
213
+ stageKeys = inner.picklistValues.map(stageKeyFromPicklistValue);
217
214
  }
218
215
  break;
219
216
  default: {
@@ -254,17 +251,12 @@ export function appToTf(entity, ctx) {
254
251
  appAttrs["status_options"] = statusOptions === undefined || statusOptions.length === 0
255
252
  ? DEPLOY_DEFAULT_STATUS_OPTION_VALUES.map((option) => ({ ...option, tags: [...option.tags] }))
256
253
  : statusOptions;
257
- if (stages === undefined || stages.length === 0) {
258
- appAttrs["stages"] = [
259
- { key: "stage_1", name: "Stage 1" },
260
- { key: "stage_2", name: "Stage 2" },
261
- ];
262
- stageTfLabels.add("stage_1");
263
- stageTfLabels.add("stage_2");
264
- }
265
- else {
266
- appAttrs["stages"] = stages;
267
- }
254
+ const emittedStages = stageKeys === undefined || stageKeys.length === 0 ? DEFAULT_APP_STAGES : stageKeys;
255
+ appAttrs["stages"] = emittedStages.map((stage) => ({ key: stage.key, name: stage.name }));
256
+ // Every handle a layout or dynamic layout can name a stage by → the stage's
257
+ // real stage_ids_by_key key (#1136). Membership is checked against the same map.
258
+ const stageKeyByTfLabel = stageKeyByHandle(emittedStages, ctx.diagnostics);
259
+ const stageTfLabels = new Set(stageKeyByTfLabel.keys());
268
260
  // --- View pass: layouts / list views / view order (entities/view), owner passed in.
269
261
  blocks.push(...dashboardsToTf(payload.dashboards, {
270
262
  ownerTfLabel: ctx.appTfLabel,
@@ -295,11 +287,14 @@ export function appToTf(entity, ctx) {
295
287
  ownerTfLabel: ctx.appTfLabel,
296
288
  objectId,
297
289
  stageTfLabels,
290
+ stageKeyByTfLabel,
298
291
  dashboardKeys: new Set(Object.keys(payload.dashboards ?? {})),
299
292
  orgRefs: ctx.orgRefs,
300
293
  workspaceAspects: ctx.workspaceAspects,
301
294
  diagnostics: ctx.diagnostics,
302
295
  fieldAddresses,
296
+ fieldNames,
297
+ fieldMetadata,
303
298
  widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
304
299
  }, payload.customViews);
305
300
  blocks.push(...viewBlocks);
@@ -322,6 +317,7 @@ export function appToTf(entity, ctx) {
322
317
  workspaceAspects: ctx.workspaceAspects,
323
318
  fieldAddresses,
324
319
  widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
320
+ stageKeyByTfLabel,
325
321
  }));
326
322
  blocks.push(...relationshipsToTf(payload.relationships, {
327
323
  ownerRefName: ctx.appRefName,
@@ -349,7 +345,7 @@ export function appToTf(entity, ctx) {
349
345
  appRefName: ctx.appRefName,
350
346
  serviceAccounts: payload.serviceAccounts,
351
347
  fieldAddresses,
352
- resolveServiceAccountApp: workspaceServiceAccountAppResolver(ctx.workspaceAspects),
348
+ resolveServiceAccountApp: workspaceServiceAccountAppResolver(ctx.workspaceAspects, { apps: ctx.outOfScopeApps, orgRefs: ctx.orgRefs }),
353
349
  });
354
350
  blocks.push(block);
355
351
  }
@@ -361,7 +357,7 @@ export function appToTf(entity, ctx) {
361
357
  serviceAccounts: payload.serviceAccounts,
362
358
  orgRefs: ctx.orgRefs,
363
359
  diagnostics: ctx.diagnostics,
364
- resolveServiceAccountApp: workspaceServiceAccountAppResolver(ctx.workspaceAspects),
360
+ resolveServiceAccountApp: workspaceServiceAccountAppResolver(ctx.workspaceAspects, { apps: ctx.outOfScopeApps, orgRefs: ctx.orgRefs }),
365
361
  }));
366
362
  blocks.push(...appServiceAccountBlocks(payload, {
367
363
  ownerTfLabel: ctx.appTfLabel,
@@ -1,5 +1,6 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
2
  import { type TfBlock } from "../../engine/tf/index.js";
3
+ import { type StageHandleIndex } from "../app/stage-keys.js";
3
4
  export interface NormalizedApprovalChain {
4
5
  readonly refName: string;
5
6
  readonly name: string;
@@ -15,4 +16,11 @@ export interface NormalizedApprovalChain {
15
16
  readonly lockedFields: readonly string[];
16
17
  readonly unsafeLockedFieldIds?: readonly string[];
17
18
  }
18
- export declare function approvalChainFromTf(block: TfBlock, appTfLabel: string, ctx: FromTfContext): NormalizedApprovalChain;
19
+ /**
20
+ * The lost-stage warning when an approval process sits on a stage with no
21
+ * handle of its own (see `pulledStageHandle`, #1136), else undefined. Such a
22
+ * chain is left unmanaged, so anything that references it (an automation's
23
+ * approval task or trigger) cannot be authored either.
24
+ */
25
+ export declare function approvalChainLostStage(block: Pick<TfBlock, "type" | "label" | "attrs">, appTfLabel: string, stageHandles: StageHandleIndex | undefined): string | undefined;
26
+ export declare function approvalChainFromTf(block: TfBlock, appTfLabel: string, ctx: FromTfContext, stageHandles?: StageHandleIndex): NormalizedApprovalChain;