@elementumai/edk 0.13.3 → 0.14.0

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 (140) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +4 -2
  2. package/dist-sdk/src/catalog/factories.js +3 -1
  3. package/dist-sdk/src/catalog/from-authoring.d.ts +8 -3
  4. package/dist-sdk/src/catalog/from-authoring.js +21 -8
  5. package/dist-sdk/src/engine/build/context.d.ts +17 -0
  6. package/dist-sdk/src/engine/coverage-gaps.d.ts +13 -0
  7. package/dist-sdk/src/engine/coverage-gaps.js +21 -0
  8. package/dist-sdk/src/engine/pull/context.d.ts +57 -1
  9. package/dist-sdk/src/engine/pull/context.js +9 -1
  10. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +14 -1
  11. package/dist-sdk/src/engine/pull/pulled-roots.js +23 -3
  12. package/dist-sdk/src/engine/pull/ref-only.d.ts +6 -1
  13. package/dist-sdk/src/engine/pull/ref-only.js +4 -1
  14. package/dist-sdk/src/engine/pull/stream-root.d.ts +17 -1
  15. package/dist-sdk/src/engine/pull/stream-root.js +57 -4
  16. package/dist-sdk/src/engine/tf/index.d.ts +1 -0
  17. package/dist-sdk/src/engine/tf/index.js +1 -0
  18. package/dist-sdk/src/engine/tf/jsonencode.d.ts +19 -0
  19. package/dist-sdk/src/engine/tf/jsonencode.js +49 -0
  20. package/dist-sdk/src/engine/validation.d.ts +36 -1
  21. package/dist-sdk/src/engine/validation.js +56 -2
  22. package/dist-sdk/src/engine/workspace/loader.d.ts +6 -0
  23. package/dist-sdk/src/engine/workspace/loader.js +87 -2
  24. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  25. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -17
  26. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +3 -1
  27. package/dist-sdk/src/entities/access-policy/to-tf.js +1 -1
  28. package/dist-sdk/src/entities/agent/build.d.ts +15 -0
  29. package/dist-sdk/src/entities/agent/build.js +139 -16
  30. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -3
  31. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +39 -25
  32. package/dist-sdk/src/entities/agent/module.js +95 -3
  33. package/dist-sdk/src/entities/agent/to-tf.js +6 -4
  34. package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +7 -0
  35. package/dist-sdk/src/entities/agent-evaluation/from-tf.js +14 -5
  36. package/dist-sdk/src/entities/agent-evaluation/module.js +4 -2
  37. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +11 -2
  38. package/dist-sdk/src/entities/agent-tool/from-tf.js +38 -40
  39. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -5
  40. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  41. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  42. package/dist-sdk/src/entities/automation/approval-trigger-refs.d.ts +20 -0
  43. package/dist-sdk/src/entities/automation/approval-trigger-refs.js +83 -0
  44. package/dist-sdk/src/entities/automation/build.d.ts +75 -42
  45. package/dist-sdk/src/entities/automation/build.js +18 -8
  46. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +14 -2
  47. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +9 -0
  48. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +64 -12
  49. package/dist-sdk/src/entities/automation/from-tf.d.ts +53 -0
  50. package/dist-sdk/src/entities/automation/from-tf.js +579 -106
  51. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  52. package/dist-sdk/src/entities/automation/index.js +1 -1
  53. package/dist-sdk/src/entities/automation/lookup-owner.d.ts +23 -0
  54. package/dist-sdk/src/entities/automation/lookup-owner.js +27 -0
  55. package/dist-sdk/src/entities/automation/module.js +265 -26
  56. package/dist-sdk/src/entities/automation/operators.d.ts +6 -2
  57. package/dist-sdk/src/entities/automation/operators.js +0 -2
  58. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +8 -0
  59. package/dist-sdk/src/entities/automation/task-output-labels.js +11 -0
  60. package/dist-sdk/src/entities/automation/tasks.d.ts +37 -2
  61. package/dist-sdk/src/entities/automation/tasks.js +38 -1
  62. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  63. package/dist-sdk/src/entities/automation/to-tf.js +576 -52
  64. package/dist-sdk/src/entities/automation/triggers.d.ts +47 -1
  65. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +10 -5
  66. package/dist-sdk/src/entities/automation/unsafe-script-output.js +10 -5
  67. package/dist-sdk/src/entities/chart/to-tf.js +18 -5
  68. package/dist-sdk/src/entities/dashboard/from-tf.js +45 -11
  69. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +5 -3
  70. package/dist-sdk/src/entities/dashboard-widget-order/order.js +6 -4
  71. package/dist-sdk/src/entities/datamine/from-tf.js +10 -3
  72. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +38 -11
  73. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +35 -7
  74. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +101 -9
  75. package/dist-sdk/src/entities/element/build.d.ts +4 -1
  76. package/dist-sdk/src/entities/element/build.js +3 -4
  77. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  78. package/dist-sdk/src/entities/field/from-tf.js +8 -1
  79. package/dist-sdk/src/entities/field/to-tf.d.ts +29 -2
  80. package/dist-sdk/src/entities/field/to-tf.js +106 -7
  81. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +7 -0
  82. package/dist-sdk/src/entities/phone-service/from-tf.js +15 -7
  83. package/dist-sdk/src/entities/phone-service/module.js +4 -2
  84. package/dist-sdk/src/entities/portal/to-tf.d.ts +1 -1
  85. package/dist-sdk/src/entities/portal/to-tf.js +61 -2
  86. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -1
  87. package/dist-sdk/src/entities/relationship/from-tf.js +34 -4
  88. package/dist-sdk/src/entities/relationship/to-tf.js +24 -6
  89. package/dist-sdk/src/entities/role/from-tf.js +3 -1
  90. package/dist-sdk/src/entities/search-table/from-tf.d.ts +3 -1
  91. package/dist-sdk/src/entities/search-table/from-tf.js +6 -3
  92. package/dist-sdk/src/entities/search-table/module.js +18 -2
  93. package/dist-sdk/src/entities/search-table/to-tf.js +10 -16
  94. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +6 -1
  95. package/dist-sdk/src/entities/shared/filters/ast.d.ts +6 -0
  96. package/dist-sdk/src/entities/shared/filters/index.d.ts +21 -4
  97. package/dist-sdk/src/entities/shared/filters/index.js +27 -3
  98. package/dist-sdk/src/entities/shared/filters/print.js +23 -7
  99. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +24 -0
  100. package/dist-sdk/src/entities/shared/filters/tf-codec.js +98 -3
  101. package/dist-sdk/src/entities/shared/filters/types.d.ts +8 -1
  102. package/dist-sdk/src/entities/shared/run-automation-requirement.d.ts +15 -0
  103. package/dist-sdk/src/entities/shared/run-automation-requirement.js +28 -0
  104. package/dist-sdk/src/entities/shared/search-table-address.d.ts +17 -0
  105. package/dist-sdk/src/entities/shared/search-table-address.js +24 -0
  106. package/dist-sdk/src/entities/shared/skip-release.d.ts +49 -0
  107. package/dist-sdk/src/entities/shared/skip-release.js +74 -0
  108. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -3
  109. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +11 -5
  110. package/dist-sdk/src/entities/skill/module.js +3 -25
  111. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +4 -2
  112. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -27
  113. package/dist-sdk/src/entities/skill-tool/to-tf.js +12 -5
  114. package/dist-sdk/src/entities/skill-tool/types.d.ts +1 -0
  115. package/dist-sdk/src/entities/skill-tool/types.js +2 -1
  116. package/dist-sdk/src/entities/table/catalog.d.ts +16 -0
  117. package/dist-sdk/src/entities/table/catalog.js +44 -2
  118. package/dist-sdk/src/entities/table/from-tf.js +30 -4
  119. package/dist-sdk/src/entities/table/keys.d.ts +27 -0
  120. package/dist-sdk/src/entities/table/keys.js +46 -0
  121. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  122. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +12 -1
  123. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +9 -4
  124. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +215 -10
  125. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +10 -4
  126. package/dist-sdk/src/entities/view/custom-view-runtime-rules.d.ts +43 -0
  127. package/dist-sdk/src/entities/view/custom-view-runtime-rules.js +285 -0
  128. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +3 -1
  129. package/dist-sdk/src/entities/view/custom-view-validate.js +24 -5
  130. package/dist-sdk/src/entities/view/from-tf.js +14 -1
  131. package/dist-sdk/src/entities/widget/from-tf.js +14 -7
  132. package/dist-sdk/src/entities/widget/to-tf.js +9 -6
  133. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +4 -2
  134. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  135. package/dist-sdk/src/graph/index.d.ts +14 -1
  136. package/dist-sdk/src/graph/index.js +2 -0
  137. package/dist-sdk/src/graph/resource-types.d.ts +2 -0
  138. package/dist-sdk/src/graph/resource-types.js +3 -0
  139. package/dist-sdk/src/graph/types.d.ts +105 -0
  140. package/package.json +1 -1
@@ -3,6 +3,7 @@ import { resolveForeignRef } from "../shared/foreign-ref.js";
3
3
  import { expr, isCanonicalTsLabel, isTfExpr, isUuid, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { filterToTf } from "../access-policy/to-tf.js";
5
5
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, automationResourceLabel } from "../automation/types.js";
6
+ import { automationLookupOwnerId } from "../automation/lookup-owner.js";
6
7
  import { isUnsafePlatformId } from "../../core/platform-id.js";
7
8
  import { droppedEntryGap, fieldRefToTfValue, UNRESOLVED_FIELD_REF } from "../field/to-tf.js";
8
9
  import { targetFilterFieldResolver } from "../relationship/to-tf.js";
@@ -658,8 +659,12 @@ function conditionMap(conditions, where, opts) {
658
659
  const field = resolveField(rec["field"], `${where}.conditions.${conditionId}.${key}`, opts);
659
660
  if (field !== undefined)
660
661
  comparison["field_id"] = field;
661
- if (rec["value"] !== undefined)
662
- comparison["value"] = typedValue(rec["value"], rec["field"], opts);
662
+ if (rec["value"] !== undefined) {
663
+ checkViewerValue(key, rec["value"], rec["field"], `${where}.conditions.${conditionId}.${key}`, opts);
664
+ checkMembershipValue(key, rec["value"], `${where}.conditions.${conditionId}.${key}`, opts);
665
+ checkContainsList(key, rec["value"], `${where}.conditions.${conditionId}.${key}`, opts);
666
+ comparison["value"] = typedValue(rec["value"], rec["field"], `${where}.conditions.${conditionId}.${key}`, opts);
667
+ }
663
668
  attrs[snakeKey(key)] = comparison;
664
669
  }
665
670
  else if (key === "stage") {
@@ -746,17 +751,104 @@ function resolveField(value, where, opts) {
746
751
  opts.diagnostics.push(`${where}: field "${refName}" has no Terraform mapping; dropped`);
747
752
  return resolved;
748
753
  }
749
- function typedValue(value, fieldValue, opts) {
754
+ /**
755
+ * The layout editor offers Current User only on a user field with equals /
756
+ * not equals, and Current User's Groups only on a group field with equals /
757
+ * not equals / in / not in (edk#3038). The provider rejects any other
758
+ * operator; a field of another type still applies but never matches as
759
+ * intended, so build says so.
760
+ */
761
+ const VIEWER_VALUE_RULES = {
762
+ currentUser: { operators: new Set(["equals", "notEquals"]), fieldTypes: new Set(["USER", "USER_ID"]), label: "a user field" },
763
+ currentUserGroups: { operators: new Set(["equals", "notEquals", "in", "notIn"]), fieldTypes: new Set(["GROUP", "GROUP_ID"]), label: "a group field" },
764
+ };
765
+ /**
766
+ * The layout editor stores a single value for `in` / `notIn` when it shows a
767
+ * plain input (edk#3043), and the provider reads it, but the record page only
768
+ * treats a string or a list as "one of": a single number or boolean never
769
+ * matches `in` and always matches `notIn`. Build keeps it as written, so a
770
+ * pulled layout round-trips, and says so.
771
+ */
772
+ function checkMembershipValue(operator, value, where, opts) {
773
+ if (operator !== "in" && operator !== "notIn")
774
+ return;
775
+ const rec = object(value);
776
+ const kind = typeof rec["number"] === "number" ? "number" : typeof rec["boolean"] === "boolean" ? "boolean" : undefined;
777
+ if (kind === undefined)
778
+ return;
779
+ const effect = operator === "in" ? "never matches" : "always matches";
780
+ const instead = operator === "in" ? "equals (any of several equals for more values)" : "notEquals (all of several notEquals for more values)";
781
+ opts.diagnostics.push(`${where}: the record page reads only a string or a list as "one of", so ${operator} with a single ${kind} ${effect}; use ${instead}`);
782
+ }
783
+ /**
784
+ * The layout editor stores a list for `contains` / `notContains` on a
785
+ * Multi-Select field (edk#3044), and the provider reads it, but the record
786
+ * page compares each selected option with the whole list, so `contains`
787
+ * never matches and `notContains` always does. Build keeps it as written, so
788
+ * a pulled layout round-trips, and says so.
789
+ */
790
+ function checkContainsList(operator, value, where, opts) {
791
+ if ((operator !== "contains" && operator !== "notContains") || !Array.isArray(object(value)["strings"]))
792
+ return;
793
+ const effect = operator === "contains" ? "never matches" : "always matches";
794
+ const instead = operator === "contains" ? "in" : "notIn";
795
+ opts.diagnostics.push(`${where}: the record page compares each option with the whole list, so ${operator} with a list ${effect}; use ${instead}`);
796
+ }
797
+ function checkViewerValue(operator, value, fieldValue, where, opts) {
798
+ const rec = object(value);
799
+ for (const [marker, rule] of Object.entries(VIEWER_VALUE_RULES)) {
800
+ // An undefined key is absent, as everywhere else in this file.
801
+ if (rec[marker] === undefined)
802
+ continue;
803
+ if (rec[marker] !== true) {
804
+ throw new EntityTfError(`${where}: ${marker} must be true`);
805
+ }
806
+ const others = Object.keys(rec).filter((key) => key !== marker && rec[key] !== undefined);
807
+ if (others.length > 0) {
808
+ throw new EntityTfError(`${where}: ${marker} is the whole value; remove ${others.join(", ")}`);
809
+ }
810
+ if (!rule.operators.has(operator)) {
811
+ throw new EntityTfError(`${where}: ${marker} can't be used with ${operator}; use ${[...rule.operators].join(", ")}`);
812
+ }
813
+ const fieldType = fieldValue?.fieldType;
814
+ if (fieldType !== undefined && !rule.fieldTypes.has(fieldType)) {
815
+ opts.diagnostics.push(`${where}: ${marker} compares ${rule.label}, but this field is ${fieldType}; the condition will not match the viewer as intended`);
816
+ }
817
+ }
818
+ }
819
+ function typedValue(value, fieldValue, where, opts) {
750
820
  const rec = object(value);
751
821
  const token = fieldValue;
752
- if (typeof rec["string"] === "string" && token?.options?.includes(rec["string"])) {
753
- const childPart = tsLabelToTfLabel(token.resourceKey ?? token.refName ?? "");
754
- const localName = token.tags?.includes("STATUS")
822
+ // On a field with options the value is option labels; anything else is
823
+ // built as written and compares that text, which no record ever holds (a
824
+ // typo, or the id of a deleted option).
825
+ const options = token?.options;
826
+ if (options !== undefined) {
827
+ const items = typeof rec["string"] === "string" ? [rec["string"]] : Array.isArray(rec["strings"]) ? rec["strings"] : [];
828
+ const unknown = items.filter((item) => typeof item === "string" && !options.includes(item));
829
+ if (unknown.length > 0) {
830
+ opts.diagnostics.push(`${where}: ${unknown.map((item) => JSON.stringify(item)).join(", ")} ${unknown.length === 1 ? "is not an option" : "are not options"} of this field; built as written, no record ever holds that value (equals / in never match it; notEquals / notIn always do)`);
831
+ }
832
+ }
833
+ const option = (label) => {
834
+ const childPart = tsLabelToTfLabel(token?.resourceKey ?? token?.refName ?? "");
835
+ const localName = token?.tags?.includes("STATUS")
755
836
  ? `${opts.ownerTfLabel}_status_options_by_label`
756
- : token.tags?.includes("STAGE")
837
+ : token?.tags?.includes("STAGE")
757
838
  ? `${opts.ownerTfLabel}_stage_options_by_label`
758
839
  : `${scopedResourceLabel(opts.ownerTfLabel, childPart, scopeOf(opts))}_options_by_label`;
759
- return { string: expr.local(localName, [{ index: rec["string"] }]) };
840
+ return expr.local(localName, [{ index: label }]);
841
+ };
842
+ if (typeof rec["string"] === "string" && token?.options?.includes(rec["string"])) {
843
+ return { string: option(rec["string"]) };
844
+ }
845
+ // A Multi-Select condition stores a list of options (edk#3044); each label
846
+ // resolves like a single option, and anything else is written as it is.
847
+ const strings = rec["strings"];
848
+ if (Array.isArray(strings) && token?.options !== undefined && strings.some((item) => typeof item === "string" && token.options.includes(item))) {
849
+ return {
850
+ strings: strings.map((item) => typeof item === "string" && token.options.includes(item) ? option(item) : item),
851
+ };
760
852
  }
761
853
  return snakeObject(rec, "dynamic layout typed value", opts);
762
854
  }
@@ -801,7 +893,7 @@ function resolveAutomation(token, where, opts) {
801
893
  const platformName = platformAutomationName(token, opts);
802
894
  if (platformName !== undefined) {
803
895
  const label = `${opts.ownerTfLabel}_${tsLabelToTfLabel(refName)}`;
804
- opts.orgRefs.rawLookup(AUTOMATION_RESOURCE_TYPE, label, platformName, { app_id: opts.objectId });
896
+ opts.orgRefs.rawLookup(AUTOMATION_RESOURCE_TYPE, label, platformName, { app_id: automationLookupOwnerId(scopeOf(opts), opts.ownerTfLabel, opts.orgRefs) });
805
897
  return expr.dataAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
806
898
  }
807
899
  return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, automationResourceLabel(opts.ownerTfLabel, refName, scopeOf(opts), scopeOf(opts) === "element" ? opts.ownerHandle : undefined), ["id"]);
@@ -78,7 +78,10 @@ interface ElementV2OptionsBase<F extends Record<string, AppField> = Record<strin
78
78
  readonly commentsEnabled?: boolean;
79
79
  /** Automatic record sharing toggles. Omit to leave the platform setting untouched. */
80
80
  readonly autoShare?: AutoShareOptions;
81
- /** Fields keyed by ref name. At least one required by the compose API. */
81
+ /**
82
+ * Custom fields keyed by ref name. May be empty (`fields: {}`): the
83
+ * platform always makes the element's ID and Title fields itself.
84
+ */
82
85
  readonly fields: F;
83
86
  /**
84
87
  * Overrides for the platform's auto-provisioned `id`/`title` fields.
@@ -45,11 +45,10 @@ function serializeElementSystemFields(overrides) {
45
45
  }
46
46
  /** Build a v2 element entity: org-owned, compose-body payload. Exposes `.ref(refName)` and `.def(refName)`. */
47
47
  export function element(opts) {
48
+ // No "at least one field" rule: the platform makes every element with its
49
+ // ID and Title fields (the `id`/`title` system keys), and an element can
50
+ // keep only those, as the web app's Create New Element leaves it (#2817).
48
51
  validateElementOptions(opts);
49
- const fieldEntries = Object.values(opts.fields);
50
- if (fieldEntries.length === 0) {
51
- throw new Error(`element "${opts.name}" requires at least one field.`);
52
- }
53
52
  return {
54
53
  ref(refName) {
55
54
  // See `app`'s `ref()` for why `handle` here is the bag key —
@@ -11,7 +11,7 @@ export { type AppRecordCreateForm, type AppRecordCreateFormSection } from "../ap
11
11
  export { listViewDensity, managedViewSortAggregation, managedViewSortDirection, type ListViewDensity, type ManagedViewSort, type ManagedViewSortAggregation, type ManagedViewSortDirection, type ManagedViewSortField, type ManagedViewSortOrder, } from "../view/build.js";
12
12
  export { type AppRelationship, type AppRelationshipColumn } from "../relationship/build.js";
13
13
  export { runAutomationParameterValue, type RunAutomationParameterValue } from "../widget/build.js";
14
- export { type DynamicLayoutBlockCommon, type DynamicLayoutComponent, type DynamicLayoutCondition, type DynamicLayoutCssLength, type DynamicLayoutDependency, type DynamicLayoutFieldComponent, type DynamicLayoutFieldValidation, type DynamicLayoutSaveGroup, type DynamicLayoutStyle, type DynamicLayoutTypedValue, type DynamicLayoutValidationRule, type ElementDynamicLayout, dynamicLayout, } from "../dynamic-layout/build.js";
14
+ export { type DynamicLayoutBlockCommon, type DynamicLayoutComponent, type DynamicLayoutCondition, type DynamicLayoutCssLength, type DynamicLayoutDependency, type DynamicLayoutFieldComponent, type DynamicLayoutFieldValidation, type DynamicLayoutSaveGroup, type DynamicLayoutStyle, type DynamicLayoutTypedValue, type DynamicLayoutCurrentUserValue, type DynamicLayoutCurrentUserGroupsValue, type DynamicLayoutEqualityComparison, type DynamicLayoutMembershipComparison, type DynamicLayoutValidationRule, type ElementDynamicLayout, dynamicLayout, } from "../dynamic-layout/build.js";
15
15
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, type DashboardChartWidget, type DashboardRecordsWidget, type DashboardWidget, type DashboardWidgetSize, } from "../dashboard/build.js";
16
16
  export { attachmentField, booleanField, calculatedField, dateField, dateTimeField, decimalField, dropdownDisplay, dropdownField, dropdownOption, dropdownValue, groupField, jsonField, multiSelectField, numberField, relationField, richTextField, textField, userField, type AttachmentFieldOptions, type BaseFieldOptions, type CalculatedFieldOptions, type InferredCalculatedField, type NumericFieldFormat, type DropdownConfig, type DropdownDisplay, type DropdownFieldOptions, type DropdownOption, type DropdownParentValueRef, type DynamicDropdownConfig, type DynamicDropdownParent, type DynamicDropdownParentMapping, type MultiSelectFieldOptions, type NumericFieldOptions, type RelationFieldOptions, type QrFieldFormat, type TextFieldOptions, } from "../field/build.js";
17
17
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, type ConcatExprType, type DateDifUnit, type DateTimeTruncPrecision, type Expr, type ExprType, type FieldRefExprType, type OrderByDirection, type Predicate, type PredicateOp, type StringAggOptions, type StringAggOrderBy, type WeekdayMode, } from "../field/calc.js";
@@ -400,7 +400,8 @@ function resolveRelatedField(v, ctx) {
400
400
  const taskAttrs = ctx.dataAttrs?.("elementum_task", objectId.label);
401
401
  const taskName = ctx.dataName("elementum_task", objectId.label) ?? (typeof taskAttrs?.name === "string" ? taskAttrs.name : objectId.label);
402
402
  const taskNamespace = typeof taskAttrs?.namespace === "string" ? taskAttrs.namespace : undefined;
403
- const taskRefName = (taskNamespace !== undefined ? ctx.foreignTaskRefNamespaces?.get(taskNamespace) : undefined) ?? (taskName !== undefined ? ctx.foreignTaskRefNames?.get(taskName) : undefined) ?? tfLabelToTsLabel(objectId.label);
403
+ // The same identity the Dropdown's target resolves to (edk#3146).
404
+ const taskRefName = resolveDataTaskTarget(ctx, objectId.label).key;
404
405
  const fieldName = typeof attrs?.name === "string" ? attrs.name : undefined;
405
406
  const strippedKey = fieldKeyFromForeignDataLabel(v.label, { key: taskRefName, name: taskName, kind: "task" });
406
407
  const fieldKey = strippedKey ?? tfLabelToTsLabel(v.label);
@@ -1259,6 +1260,12 @@ export function decodeForeignDataField(dataLabel, target, ctx) {
1259
1260
  const fieldType = fieldTypeFromRegistry(ctx, target.key, catalogFieldKey);
1260
1261
  return { key: catalogFieldKey, name, ...(fieldType !== undefined ? { fieldType } : {}) };
1261
1262
  }
1263
+ // A renamed Title or ID (#3145) has no field block, so the catalog index
1264
+ // can't name it; the owner's own source keys it `title`/`id`.
1265
+ const systemKey = ctx.renamedSystemFieldKeysByOwnerRefName?.get(target.key)?.get(name.toLowerCase());
1266
+ if (systemKey !== undefined) {
1267
+ return { key: systemKey, name, fieldType: fieldTypeFromRegistry(ctx, target.key, systemKey) ?? (systemKey === "id" ? "HANDLE" : "TEXT") };
1268
+ }
1262
1269
  const stripped = fieldKeyFromForeignDataLabel(dataLabel, { ...target, ownerDataLabel: foreignFieldOwnerDataLabel(dataLabel, ctx) });
1263
1270
  if (stripped !== undefined) {
1264
1271
  const fieldType = fieldTypeFromRegistry(ctx, target.key, stripped);
@@ -25,9 +25,32 @@ import { type PicklistValueWire } from "./options.js";
25
25
  export interface FieldOwnership {
26
26
  has(refName: string): boolean;
27
27
  get?(refName: string): string | undefined;
28
+ /**
29
+ * The system key (`title`/`id`) a reference names by the field's renamed
30
+ * display name rather than its key (#3145), when no authored field claims
31
+ * that name. With the reference's display `name`, that name must equal the
32
+ * renamed one (ignoring case); without it, the ref key is compared by
33
+ * letters and digits.
34
+ */
35
+ systemKey?(refName: string, name?: string): "title" | "id" | undefined;
28
36
  }
29
37
  /** Reconstruct custom-field ownership from a loaded app/element payload. */
30
38
  export declare function authoredFieldKeysFromPayload(payload: unknown): ReadonlySet<string> | undefined;
39
+ /**
40
+ * A workspace sibling's authored fields, each with the resource address its
41
+ * own build gives it (#3075). A reference to another root's field carries the
42
+ * type the export reported for it, which isn't always the type the owner
43
+ * declares: a pulled ref to another element's User field says `USER_ID`, a
44
+ * Calculated field says its result type. Building the address from that type
45
+ * names a resource the owner doesn't declare, or none at all, and the two
46
+ * sides of a relationship stop naming the same field.
47
+ *
48
+ * An element's STATUS dropdown counts too: it is system-tagged, so
49
+ * {@link authoredFieldKeysFromPayload} leaves it out, but the element's build
50
+ * emits it as a dropdown resource (`element/to-tf.ts`) rather than folding it
51
+ * into the element, so the element's own side resolves it to that resource.
52
+ */
53
+ export declare function siblingFieldOwnership(payload: unknown, ownerTfLabel: string, scope: FieldOwnerScope): FieldOwnership | undefined;
31
54
  /** Slim `AppOrElementRef` token shape as it appears in a def() payload (post-`slimTokens`). */
32
55
  interface AspectTokenWire {
33
56
  readonly __kind?: string;
@@ -172,7 +195,9 @@ export interface FieldToTfResult {
172
195
  */
173
196
  export declare function claimFieldDisplayName(seen: Map<string, string>, field: FieldToTfResult): void;
174
197
  export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
175
- export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership, resourceKey?: string): TfExpr | undefined;
198
+ export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership, resourceKey?: string,
199
+ /** The reference's display name, when it carries one: it identifies a sibling's renamed Title/ID (#3145). */
200
+ displayName?: string): TfExpr | undefined;
176
201
  /**
177
202
  * Why build leaves out an entry: its field reference has no field in source
178
203
  * and no platform id (#1966, #1978). The gaps below state what apply then
@@ -193,7 +218,9 @@ export declare function unauthoredSiblingFieldRef(refName: string, sibling: {
193
218
  readonly kind: ChildResourceScope;
194
219
  readonly refName: string;
195
220
  readonly fieldOwnership?: FieldOwnership;
196
- }): string | undefined;
221
+ },
222
+ /** The reference's display name, when it carries one (#3145). */
223
+ displayName?: string): string | undefined;
197
224
  /** A field ref's name, when it has one build can look the field up by. */
198
225
  export declare function fieldLookupName(value: {
199
226
  readonly name?: string;
@@ -17,7 +17,7 @@ import { EntityTfError } from "../../engine/entity.js";
17
17
  import { typedCoverageGap } from "../../engine/coverage-gaps.js";
18
18
  import { workspaceAspectKey } from "../../engine/build/context.js";
19
19
  import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
20
- import { SYSTEM_FIELD_KEY_SET, systemFieldTag } from "../../core/system-fields.js";
20
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET, systemFieldTag } from "../../core/system-fields.js";
21
21
  import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS, ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
22
22
  import { filterToTf as filterWireToTfCodec } from "../shared/filters/tf-codec.js";
23
23
  import { optionSelectionLiteral, optionsLocalName } from "../shared/filters/option-lookups.js";
@@ -26,6 +26,10 @@ import { isAttachmentMediaType } from "./media-types.js";
26
26
  import { picklistLabel } from "./options.js";
27
27
  import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
28
28
  import { tfChildPartForFieldBagKey } from "./from-tf.js";
29
+ /** A field name or ref key reduced to letters and digits, so "EMAIL_PRIMARY_WORK" and `emailPrimaryWork` compare equal. */
30
+ function fieldNameMatchKey(value) {
31
+ return value.toLowerCase().replace(/[^a-z0-9]/g, "");
32
+ }
29
33
  /** Reconstruct custom-field ownership from a loaded app/element payload. */
30
34
  export function authoredFieldKeysFromPayload(payload) {
31
35
  if (typeof payload !== "object" || payload === null)
@@ -42,8 +46,93 @@ export function authoredFieldKeysFromPayload(payload) {
42
46
  }
43
47
  return keys;
44
48
  }
45
- function workspaceFieldOwnership(aspect) {
46
- return authoredFieldKeysFromPayload(aspect.streamRootEntity?.payload);
49
+ /**
50
+ * A workspace sibling's authored fields, each with the resource address its
51
+ * own build gives it (#3075). A reference to another root's field carries the
52
+ * type the export reported for it, which isn't always the type the owner
53
+ * declares: a pulled ref to another element's User field says `USER_ID`, a
54
+ * Calculated field says its result type. Building the address from that type
55
+ * names a resource the owner doesn't declare, or none at all, and the two
56
+ * sides of a relationship stop naming the same field.
57
+ *
58
+ * An element's STATUS dropdown counts too: it is system-tagged, so
59
+ * {@link authoredFieldKeysFromPayload} leaves it out, but the element's build
60
+ * emits it as a dropdown resource (`element/to-tf.ts`) rather than folding it
61
+ * into the element, so the element's own side resolves it to that resource.
62
+ */
63
+ export function siblingFieldOwnership(payload, ownerTfLabel, scope) {
64
+ const authored = authoredFieldKeysFromPayload(payload);
65
+ if (authored === undefined)
66
+ return undefined;
67
+ const keys = new Set(authored);
68
+ const addresses = new Map();
69
+ // A renamed Title or ID (#3145): another root's pull can only name it by
70
+ // its display name (`EMAIL` → `email`), while this root builds it as its
71
+ // `title`/`id` system field. A Title and ID whose names collide are left
72
+ // out rather than one silently winning, and a key an authored field also
73
+ // matches stays that field's.
74
+ const renamed = [];
75
+ for (const entry of payload.fields ?? []) {
76
+ const inner = Object.values(entry)[0];
77
+ const tag = inner === undefined ? undefined : systemFieldTag(inner);
78
+ const systemKey = tag === "TITLE" ? "title" : tag === "HANDLE" ? "id" : undefined;
79
+ const name = inner?.name;
80
+ if (systemKey === undefined || name === undefined || name.trim() === "")
81
+ continue;
82
+ const matchKey = fieldNameMatchKey(name);
83
+ if (matchKey !== systemKey)
84
+ renamed.push({ key: systemKey, lower: name.toLowerCase(), matchKey });
85
+ }
86
+ // The other field's current name: its rename, or its default ("Title"/"ID").
87
+ const otherName = (key) => {
88
+ const other = key === "title" ? "id" : "title";
89
+ const entry = renamed.find((candidate) => candidate.key === other);
90
+ return entry ?? { lower: DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[other].toLowerCase(), matchKey: fieldNameMatchKey(DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[other]) };
91
+ };
92
+ const collides = (entry) => {
93
+ const other = otherName(entry.key);
94
+ return other.lower === entry.lower || other.matchKey === entry.matchKey;
95
+ };
96
+ const authoredMatchKeys = new Set([...authored].map(fieldNameMatchKey));
97
+ const renamedByName = new Map();
98
+ const renamedByMatchKey = new Map();
99
+ for (const entry of renamed) {
100
+ if (collides(entry))
101
+ continue;
102
+ renamedByName.set(entry.lower, entry.key);
103
+ if (!authoredMatchKeys.has(entry.matchKey))
104
+ renamedByMatchKey.set(entry.matchKey, entry.key);
105
+ }
106
+ for (const entry of payload.fields ?? []) {
107
+ const typeKey = Object.keys(entry)[0];
108
+ const inner = typeKey === undefined ? undefined : entry[typeKey];
109
+ const subType = typeKey === undefined ? undefined : SUB_TYPE_BY_TYPE_KEY.get(typeKey);
110
+ if (inner === undefined || subType === undefined)
111
+ continue;
112
+ const key = inner.__refName ?? snakeSlug(inner.name ?? "");
113
+ if (scope === "element" && typeKey === "picklist" && systemFieldTag(inner) === "STATUS" && key !== "")
114
+ keys.add(key);
115
+ if (!keys.has(key) || addresses.has(key) || !isCanonicalTsLabel(key))
116
+ continue;
117
+ addresses.set(key, `${subType.resourceType}.${scopedResourceLabel(ownerTfLabel, tfChildPartForFieldBagKey(key, inner.__resourceKey), scope)}`);
118
+ }
119
+ return {
120
+ has: (refName) => keys.has(refName),
121
+ get: (refName) => addresses.get(refName),
122
+ systemKey: (refName, name) => keys.has(refName)
123
+ ? undefined
124
+ : name !== undefined && name.trim() !== ""
125
+ ? renamedByName.get(name.toLowerCase())
126
+ : renamedByMatchKey.get(fieldNameMatchKey(refName)),
127
+ };
128
+ }
129
+ /**
130
+ * A workspace sibling's authored fields with the addresses its own build
131
+ * gives them (#3088), so a related label or dynamic-picklist field resolves
132
+ * to the resource the sibling declares, whatever type the reference carries.
133
+ */
134
+ function workspaceFieldOwnership(aspect, kind) {
135
+ return siblingFieldOwnership(aspect.streamRootEntity?.payload, aspect.tfLabel, kind);
47
136
  }
48
137
  /** `unknown` → the tagged org-field-ref shape, or undefined for anything else. */
49
138
  function asOrgFieldRef(v) {
@@ -133,7 +222,7 @@ function resolveRelatedObject(token, opts, where) {
133
222
  refName,
134
223
  kind,
135
224
  target: sibling,
136
- fieldOwnership: workspaceFieldOwnership(sibling),
225
+ fieldOwnership: kind === "task" ? undefined : workspaceFieldOwnership(sibling, kind),
137
226
  };
138
227
  }
139
228
  const name = token.name ?? refName;
@@ -212,7 +301,7 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
212
301
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" resolves to table "${object.target.tfLabel}" — tables expose columns, not fields; dropped`);
213
302
  return undefined;
214
303
  }
215
- const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind, object.fieldOwnership, token.resourceKey);
304
+ const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind, object.fieldOwnership, token.resourceKey, token.name);
216
305
  if (value === undefined) {
217
306
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(token.fieldType ?? "")}); dropped`);
218
307
  }
@@ -888,7 +977,9 @@ function scalarOrUndefined(v) {
888
977
  */
889
978
  const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
890
979
  const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
891
- export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldOwnership, resourceKey) {
980
+ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldOwnership, resourceKey,
981
+ /** The reference's display name, when it carries one: it identifies a sibling's renamed Title/ID (#3145). */
982
+ displayName) {
892
983
  if (!isCanonicalTsLabel(refName))
893
984
  return undefined;
894
985
  if (scope === "element" &&
@@ -906,6 +997,10 @@ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app
906
997
  if (isSystemField) {
907
998
  return expr.local(`${ownerTfLabel}_${tsLabelToTfLabel(refName)}_field_id`);
908
999
  }
1000
+ const renamedSystemKey = fieldOwnership?.systemKey?.(refName, displayName);
1001
+ if (renamedSystemKey !== undefined) {
1002
+ return expr.local(`${ownerTfLabel}_${renamedSystemKey}_field_id`);
1003
+ }
909
1004
  const knownAddress = fieldOwnership?.get?.(refName);
910
1005
  if (knownAddress !== undefined) {
911
1006
  const dotIndex = knownAddress.indexOf(".");
@@ -934,9 +1029,13 @@ export const UNRESOLVED_FIELD_REF = "field reference is unresolved (skipped duri
934
1029
  * it up by. Undefined when the root's fields are unknown, when `refName` is
935
1030
  * one of them, or when it is a system field.
936
1031
  */
937
- export function unauthoredSiblingFieldRef(refName, sibling) {
1032
+ export function unauthoredSiblingFieldRef(refName, sibling,
1033
+ /** The reference's display name, when it carries one (#3145). */
1034
+ displayName) {
938
1035
  if (sibling.fieldOwnership === undefined || sibling.fieldOwnership.has(refName))
939
1036
  return undefined;
1037
+ if (sibling.fieldOwnership.systemKey?.(refName, displayName) !== undefined)
1038
+ return undefined;
940
1039
  const systemField = sibling.kind === "element"
941
1040
  ? ELEMENT_SYSTEM_FIELD_KEY_SET.has(refName)
942
1041
  : SYSTEM_FIELD_KEY_SET.has(refName);
@@ -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 { QuarantinedOwnFile } from "../../graph/types.js";
3
4
  import { type CallerAccessMode, type E164PhoneNumber } from "./types.js";
4
5
  export interface NormalizedPhoneService {
5
6
  readonly refName: string;
@@ -21,6 +22,12 @@ export interface NormalizedPhoneService {
21
22
  readonly preferredLanguages?: readonly string[];
22
23
  };
23
24
  }
25
+ /**
26
+ * One phone service block → its normalized shape; undefined = skipped. A
27
+ * service written to no source is also left out of adoption, or released if
28
+ * state has it, and its earlier file is archived (edk#3172).
29
+ */
24
30
  export declare function phoneServiceFromTf(block: TfBlock, opts: {
25
31
  readonly appLabel: string;
32
+ readonly quarantineOwnFiles: QuarantinedOwnFile[];
26
33
  }, ctx: FromTfContext): NormalizedPhoneService | undefined;
@@ -3,6 +3,7 @@ import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js"
3
3
  import { AGENT_RESOURCE_TYPE } from "../agent/module.js";
4
4
  import { APP_RESOURCE_TYPE } from "../app/module.js";
5
5
  import { VOICE_AUTH_RESOURCE_TYPE } from "../org/voice-auth.js";
6
+ import { skipOwnFileAndRelease, unresolvedReferenceName } from "../shared/skip-release.js";
6
7
  import { callerAccessMode } from "./types.js";
7
8
  const KNOWN_ATTRS = new Set([
8
9
  "app_id", "provider_id", "agent_id", "caller_access_mode", "voice_auth_config_id", "twilio_existing_number",
@@ -12,9 +13,19 @@ const CALLER_ACCESS_MODES = new Set(Object.values(callerAccessMode));
12
13
  function isCallerAccessMode(value) {
13
14
  return CALLER_ACCESS_MODES.has(value);
14
15
  }
16
+ /**
17
+ * One phone service block → its normalized shape; undefined = skipped. A
18
+ * service written to no source is also left out of adoption, or released if
19
+ * state has it, and its earlier file is archived (edk#3172).
20
+ */
15
21
  export function phoneServiceFromTf(block, opts, ctx) {
16
22
  const label = block.label ?? "";
17
23
  const where = `phone service "${label}"`;
24
+ const refName = scopedLabelToBagKey(opts.appLabel, label, "app");
25
+ const skip = (why, fallback) => {
26
+ skipOwnFileAndRelease(ctx, `${block.type}.${label}`, why, fallback, { kind: "phone-service", refName }, opts.quarantineOwnFiles);
27
+ return undefined;
28
+ };
18
29
  for (const key of Object.keys(block.attrs)) {
19
30
  if (!KNOWN_ATTRS.has(key))
20
31
  ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — extend phoneServiceFromTf deliberately`);
@@ -25,14 +36,12 @@ export function phoneServiceFromTf(block, opts, ctx) {
25
36
  }
26
37
  const agentLabel = resourceRefLabel(block.attrs["agent_id"], AGENT_RESOURCE_TYPE);
27
38
  if (agentLabel === undefined) {
28
- ctx.diagnostics.push(`${where}: agent_id is not a managed ${AGENT_RESOURCE_TYPE} reference; skipped`);
29
- return undefined;
39
+ return skip({ reference: unresolvedReferenceName(block.attrs["agent_id"], "agent_id") }, `${where}: agent_id is not a managed ${AGENT_RESOURCE_TYPE} reference; skipped`);
30
40
  }
31
41
  const providerLabel = dataRefLabel(block.attrs["provider_id"], "elementum_phone_provider");
32
42
  const providerName = providerLabel !== undefined ? ctx.dataName("elementum_phone_provider", providerLabel) : undefined;
33
43
  if (providerLabel === undefined || providerName === undefined) {
34
- ctx.diagnostics.push(`${where}: provider_id is not a resolvable elementum_phone_provider data reference; skipped`);
35
- return undefined;
44
+ return skip({ reference: unresolvedReferenceName(block.attrs["provider_id"], "provider_id") }, `${where}: provider_id is not a resolvable elementum_phone_provider data reference; skipped`);
36
45
  }
37
46
  const existing = plainObject(block.attrs["twilio_existing_number"]);
38
47
  const created = plainObject(block.attrs["twilio_new_number"]);
@@ -41,8 +50,7 @@ export function phoneServiceFromTf(block, opts, ctx) {
41
50
  const hasExisting = typeof existingNumber === "string" && /^\+[1-9]\d{7,14}$/.test(existingNumber);
42
51
  const hasCreated = typeof areaCode === "number" && Number.isInteger(areaCode);
43
52
  if (hasExisting === hasCreated) {
44
- ctx.diagnostics.push(`${where}: expected exactly one valid Twilio existing number or new area code; skipped`);
45
- return undefined;
53
+ return skip({ problem: "the export gives it neither exactly one valid Twilio existing number nor one new area code" }, `${where}: expected exactly one valid Twilio existing number or new area code; skipped`);
46
54
  }
47
55
  const voiceAuthLabel = dataRefLabel(block.attrs["voice_auth_config_id"], VOICE_AUTH_RESOURCE_TYPE)
48
56
  ?? resourceRefLabel(block.attrs["voice_auth_config_id"], VOICE_AUTH_RESOURCE_TYPE);
@@ -62,7 +70,7 @@ export function phoneServiceFromTf(block, opts, ctx) {
62
70
  ctx.diagnostics.push(`${where}: preferred_languages is not a string list; omitted`);
63
71
  }
64
72
  return {
65
- refName: scopedLabelToBagKey(opts.appLabel, label, "app"),
73
+ refName,
66
74
  agentKey: scopedLabelToBagKey(opts.appLabel, agentLabel, "app"),
67
75
  providerKey: tfLabelToTsLabel(providerLabel),
68
76
  ...(voiceAuthLabel !== undefined ? { voiceAuthKey: tfLabelToTsLabel(voiceAuthLabel) } : {}),
@@ -22,12 +22,14 @@ export const phoneServiceModule = {
22
22
  participates: true,
23
23
  extractOwnFile: (ownBlocks, _stream, ctx) => {
24
24
  const items = [];
25
+ const quarantineOwnFiles = [];
25
26
  for (const block of ownBlocks) {
26
- const service = phoneServiceFromTf(block, { appLabel: ctx.appTfLabel }, ctx);
27
+ const service = phoneServiceFromTf(block, { appLabel: ctx.appTfLabel, quarantineOwnFiles }, ctx);
27
28
  if (service !== undefined)
28
29
  items.push(service);
29
30
  }
30
- return { items, skipped: [], diagnostics: [] };
31
+ // A skipped one is in ctx.skipped and ctx.releaseIfManaged (skipOwnFileAndRelease).
32
+ return { items, skipped: [], diagnostics: [], ...(quarantineOwnFiles.length > 0 && { quarantineOwnFiles }) };
31
33
  },
32
34
  printOwnFile: (item, opts) => {
33
35
  const service = item;
@@ -5,7 +5,7 @@ export interface PortalToTfContext {
5
5
  readonly tfLabel: string;
6
6
  readonly orgRefs: OrgRefLookup;
7
7
  readonly diagnostics: string[];
8
- readonly workspaceAspects?: ReadonlyMap<string, Pick<WorkspaceAspect, "tfLabel">>;
8
+ readonly workspaceAspects?: ReadonlyMap<string, Pick<WorkspaceAspect, "tfLabel" | "streamRootEntity">>;
9
9
  }
10
10
  export declare function portalToTf(entity: DeployableEntity, ctx: PortalToTfContext): {
11
11
  blocks: readonly TfBlock[];
@@ -13,8 +13,10 @@ const VIEW_RESOURCE_BY_TYPE = {
13
13
  };
14
14
  /**
15
15
  * A catalog view whose owner is built in this workspace is referenced as a
16
- * resource, so the portal is created after it. Any other view is looked up by
17
- * its owner's namespace and its name; without a namespace it can't be found.
16
+ * resource, so the portal is created after it. So is a view named by its
17
+ * owner's namespace when that owner is built here and its source has exactly
18
+ * one view of that name (#3208). Any other view is looked up by its owner's
19
+ * namespace and its name; without a namespace it can't be found.
18
20
  */
19
21
  function viewIdOf(view, ctx) {
20
22
  const ownerKind = view.parentKind ?? "app";
@@ -28,6 +30,13 @@ function viewIdOf(view, ctx) {
28
30
  if (view.parentNamespace === undefined) {
29
31
  return { problem: `view ${JSON.stringify(view.name)} names owner ${JSON.stringify(view.parent)}, which is not in this workspace; use viewRef({ name, parentKind, parentNamespace })` };
30
32
  }
33
+ // A view named by its owner's namespace whose owner is built in this
34
+ // workspace: reference the view's resource, as the catalog form does, so
35
+ // the portal is created after it. A lookup can't find an app the same apply
36
+ // creates ("App Not Found", #3208).
37
+ const inWorkspace = workspaceViewByName(view, ownerKind, ctx);
38
+ if (inWorkspace !== undefined)
39
+ return inWorkspace;
31
40
  const owner = ctx.orgRefs.resolveForeignRoot(ownerKind, {
32
41
  name: view.parentName ?? view.parentNamespace,
33
42
  namespace: view.parentNamespace,
@@ -37,6 +46,56 @@ function viewIdOf(view, ctx) {
37
46
  ctx.orgRefs.rawLookup(VIEW_DATA_RESOURCE_TYPE, label, view.name, { owner_id: expr.dataAttr(owner.resourceType, owner.tfLabel, ["id"]) });
38
47
  return { id: expr.dataAttr(VIEW_DATA_RESOURCE_TYPE, label, ["id"]) };
39
48
  }
49
+ /** View bags of an app or element payload, and the view type each holds. */
50
+ const VIEW_BAGS = {
51
+ listViews: "list",
52
+ calendarViews: "calendar",
53
+ kanbanViews: "kanban",
54
+ dashboardViews: "dashboard",
55
+ agentViews: "agent",
56
+ customViews: "custom",
57
+ };
58
+ /**
59
+ * The view resource for `viewRef({ name, parentKind, parentNamespace })` when
60
+ * that namespace is an app or element of this workspace whose source has
61
+ * exactly one view of that name; a problem when it has several (the lookup
62
+ * would refuse them too). Undefined otherwise, which keeps the lookup: the
63
+ * owner isn't here, or its source doesn't hold the view (pull portal prints
64
+ * this form for a view pull left out of the owner's source, which the live
65
+ * owner still has).
66
+ */
67
+ function workspaceViewByName(view, ownerKind, ctx) {
68
+ for (const aspect of ctx.workspaceAspects?.values() ?? []) {
69
+ const root = aspect.streamRootEntity;
70
+ if (root === undefined || root.kind !== ownerKind)
71
+ continue;
72
+ const payload = root.payload;
73
+ if (payload?.namespace !== view.parentNamespace)
74
+ continue;
75
+ const matches = [];
76
+ for (const [bag, type] of Object.entries(VIEW_BAGS)) {
77
+ const views = payload?.[bag];
78
+ for (const [key, candidate] of Object.entries(views ?? {})) {
79
+ if (candidate?.name === view.name)
80
+ matches.push({ key, type });
81
+ }
82
+ }
83
+ if (matches.length === 0)
84
+ return undefined;
85
+ if (matches.length > 1) {
86
+ return {
87
+ problem: `${ownerKind} ${JSON.stringify(view.parentNamespace)} has several views named ${JSON.stringify(view.name)} (${matches.map((m) => m.key).join(", ")}); use catalog.<${ownerKind}>.views.<view>`,
88
+ };
89
+ }
90
+ const match = matches[0];
91
+ const resourceType = VIEW_RESOURCE_BY_TYPE[match.type];
92
+ // A key build drops (not canonical) declares no resource: keep the lookup.
93
+ if (resourceType === undefined || !isCanonicalTsLabel(match.key))
94
+ return undefined;
95
+ return { id: expr.resourceAttr(resourceType, scopedResourceLabel(aspect.tfLabel, tsLabelToTfLabel(match.key), ownerKind), ["id"]) };
96
+ }
97
+ return undefined;
98
+ }
40
99
  export function portalToTf(entity, ctx) {
41
100
  if (entity.kind !== "portal")
42
101
  throw new EntityTfError(`portalToTf expects portal; got ${entity.kind}`);