@elementumai/edk 0.13.4 → 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 (123) 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 +10 -0
  7. package/dist-sdk/src/engine/coverage-gaps.js +16 -0
  8. package/dist-sdk/src/engine/pull/context.d.ts +56 -0
  9. package/dist-sdk/src/engine/pull/context.js +8 -0
  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 +13 -1
  15. package/dist-sdk/src/engine/pull/stream-root.js +54 -4
  16. package/dist-sdk/src/engine/validation.d.ts +36 -1
  17. package/dist-sdk/src/engine/validation.js +56 -2
  18. package/dist-sdk/src/engine/workspace/loader.d.ts +6 -0
  19. package/dist-sdk/src/engine/workspace/loader.js +87 -2
  20. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -17
  22. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +3 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.js +1 -1
  24. package/dist-sdk/src/entities/agent/build.d.ts +15 -0
  25. package/dist-sdk/src/entities/agent/build.js +139 -16
  26. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -3
  27. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +39 -25
  28. package/dist-sdk/src/entities/agent/module.js +95 -3
  29. package/dist-sdk/src/entities/agent/to-tf.js +6 -4
  30. package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +7 -0
  31. package/dist-sdk/src/entities/agent-evaluation/from-tf.js +14 -5
  32. package/dist-sdk/src/entities/agent-evaluation/module.js +4 -2
  33. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +11 -2
  34. package/dist-sdk/src/entities/agent-tool/from-tf.js +38 -40
  35. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -5
  36. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  37. package/dist-sdk/src/entities/automation/build.d.ts +75 -42
  38. package/dist-sdk/src/entities/automation/build.js +17 -7
  39. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +14 -2
  40. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +9 -0
  41. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +57 -12
  42. package/dist-sdk/src/entities/automation/from-tf.d.ts +51 -0
  43. package/dist-sdk/src/entities/automation/from-tf.js +476 -93
  44. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  45. package/dist-sdk/src/entities/automation/index.js +1 -1
  46. package/dist-sdk/src/entities/automation/module.js +90 -9
  47. package/dist-sdk/src/entities/automation/operators.d.ts +6 -2
  48. package/dist-sdk/src/entities/automation/operators.js +0 -2
  49. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +8 -0
  50. package/dist-sdk/src/entities/automation/task-output-labels.js +11 -0
  51. package/dist-sdk/src/entities/automation/tasks.d.ts +37 -2
  52. package/dist-sdk/src/entities/automation/tasks.js +38 -1
  53. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  54. package/dist-sdk/src/entities/automation/to-tf.js +413 -47
  55. package/dist-sdk/src/entities/chart/to-tf.js +18 -5
  56. package/dist-sdk/src/entities/dashboard/from-tf.js +45 -11
  57. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +5 -3
  58. package/dist-sdk/src/entities/dashboard-widget-order/order.js +6 -4
  59. package/dist-sdk/src/entities/datamine/from-tf.js +10 -3
  60. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +9 -2
  61. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +35 -7
  62. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +63 -7
  63. package/dist-sdk/src/entities/element/build.d.ts +4 -1
  64. package/dist-sdk/src/entities/element/build.js +3 -4
  65. package/dist-sdk/src/entities/field/from-tf.js +8 -1
  66. package/dist-sdk/src/entities/field/to-tf.d.ts +29 -2
  67. package/dist-sdk/src/entities/field/to-tf.js +106 -7
  68. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +7 -0
  69. package/dist-sdk/src/entities/phone-service/from-tf.js +15 -7
  70. package/dist-sdk/src/entities/phone-service/module.js +4 -2
  71. package/dist-sdk/src/entities/portal/to-tf.d.ts +1 -1
  72. package/dist-sdk/src/entities/portal/to-tf.js +61 -2
  73. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -1
  74. package/dist-sdk/src/entities/relationship/from-tf.js +34 -4
  75. package/dist-sdk/src/entities/relationship/to-tf.js +24 -6
  76. package/dist-sdk/src/entities/role/from-tf.js +3 -1
  77. package/dist-sdk/src/entities/search-table/from-tf.d.ts +3 -1
  78. package/dist-sdk/src/entities/search-table/from-tf.js +6 -3
  79. package/dist-sdk/src/entities/search-table/module.js +18 -2
  80. package/dist-sdk/src/entities/search-table/to-tf.js +10 -16
  81. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +6 -1
  82. package/dist-sdk/src/entities/shared/filters/index.d.ts +6 -1
  83. package/dist-sdk/src/entities/shared/filters/index.js +8 -2
  84. package/dist-sdk/src/entities/shared/filters/print.js +18 -7
  85. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +11 -0
  86. package/dist-sdk/src/entities/shared/filters/tf-codec.js +24 -2
  87. package/dist-sdk/src/entities/shared/run-automation-requirement.d.ts +15 -0
  88. package/dist-sdk/src/entities/shared/run-automation-requirement.js +28 -0
  89. package/dist-sdk/src/entities/shared/search-table-address.d.ts +17 -0
  90. package/dist-sdk/src/entities/shared/search-table-address.js +24 -0
  91. package/dist-sdk/src/entities/shared/skip-release.d.ts +49 -0
  92. package/dist-sdk/src/entities/shared/skip-release.js +74 -0
  93. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -3
  94. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +11 -5
  95. package/dist-sdk/src/entities/skill/module.js +3 -25
  96. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +4 -2
  97. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -27
  98. package/dist-sdk/src/entities/skill-tool/to-tf.js +12 -5
  99. package/dist-sdk/src/entities/skill-tool/types.d.ts +1 -0
  100. package/dist-sdk/src/entities/skill-tool/types.js +2 -1
  101. package/dist-sdk/src/entities/table/catalog.d.ts +16 -0
  102. package/dist-sdk/src/entities/table/catalog.js +44 -2
  103. package/dist-sdk/src/entities/table/from-tf.js +30 -4
  104. package/dist-sdk/src/entities/table/keys.d.ts +27 -0
  105. package/dist-sdk/src/entities/table/keys.js +46 -0
  106. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  107. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +12 -1
  108. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +9 -4
  109. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +215 -10
  110. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +10 -4
  111. package/dist-sdk/src/entities/view/custom-view-runtime-rules.d.ts +43 -0
  112. package/dist-sdk/src/entities/view/custom-view-runtime-rules.js +285 -0
  113. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +3 -1
  114. package/dist-sdk/src/entities/view/custom-view-validate.js +24 -5
  115. package/dist-sdk/src/entities/view/from-tf.js +14 -1
  116. package/dist-sdk/src/entities/widget/from-tf.js +14 -7
  117. package/dist-sdk/src/entities/widget/to-tf.js +7 -5
  118. package/dist-sdk/src/graph/index.d.ts +14 -1
  119. package/dist-sdk/src/graph/index.js +2 -0
  120. package/dist-sdk/src/graph/resource-types.d.ts +2 -0
  121. package/dist-sdk/src/graph/resource-types.js +3 -0
  122. package/dist-sdk/src/graph/types.d.ts +82 -0
  123. package/package.json +1 -1
@@ -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}`);
@@ -3,6 +3,7 @@ import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
3
3
  import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
4
  import { elementAuditFieldReference, fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { unextractedFieldRefId } from "../view/from-tf.js";
6
+ import { skipAndRelease } from "../shared/skip-release.js";
6
7
  import { RECORD_CREATE_FORM_RESOURCE_TYPE } from "./module.js";
7
8
  const KNOWN_ATTRS = new Set(["app_id", "sections"]);
8
9
  const KNOWN_SECTION_ATTRS = new Set([
@@ -21,7 +22,8 @@ export function recordCreateFormFromTf(block, owner, ctx) {
21
22
  }
22
23
  const rawSections = block.attrs["sections"];
23
24
  if (!Array.isArray(rawSections)) {
24
- ctx.diagnostics.push(`${where}: sections is not a list; skipped`);
25
+ // Written to no source, so also left out of adoption (edk#3172).
26
+ skipAndRelease(ctx, `${RECORD_CREATE_FORM_RESOURCE_TYPE}.${block.label ?? ""}`, { problem: "its sections is not a list" }, `${where}: sections is not a list; skipped`);
25
27
  return undefined;
26
28
  }
27
29
  const sections = [];
@@ -1,6 +1,7 @@
1
1
  import { dataRefLabel, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
2
+ import { skipAndRelease, unresolvedReferenceName } from "../shared/skip-release.js";
2
3
  import { expr, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
- import { filterFromTf } from "../access-policy/from-tf.js";
4
+ import { filterFromTf, filterFromTfOfOwners } from "../access-policy/from-tf.js";
4
5
  import { decodeForeignDataField, elementAuditFieldReference, fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
6
  import { resolveDataAspectTarget, resolveDataTaskTarget } from "../shared/aspect-target-from-tf.js";
6
7
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
@@ -27,14 +28,17 @@ function relationshipFromTf(block, owner, ctx) {
27
28
  ctx.diagnostics.push(`${where}: object_id does not reference ${ownerResourceType}.${owner.label}; skipped`);
28
29
  return undefined;
29
30
  }
31
+ // A relationship written to no source is also left out of adoption, or
32
+ // the next plan destroys it (edk#3166).
33
+ const address = `${RELATIONSHIP_RESOURCE_TYPE}.${block.label ?? ""}`;
30
34
  const target = targetRef(block.attrs["related_object_id"], owner, ctx);
31
35
  if (target === undefined) {
32
- ctx.diagnostics.push(`${where}: related_object_id is not resolvable; skipped`);
36
+ skipAndRelease(ctx, address, { reference: unresolvedReferenceName(block.attrs["related_object_id"], "related_object_id") }, `${where}: related_object_id is not resolvable; skipped`);
33
37
  return undefined;
34
38
  }
35
39
  const columnsRaw = block.attrs["columns"];
36
40
  if (!Array.isArray(columnsRaw)) {
37
- ctx.diagnostics.push(`${where}: columns is not a list; skipped`);
41
+ skipAndRelease(ctx, address, { problem: "the export doesn't give its columns as a list" }, `${where}: columns is not a list; skipped`);
38
42
  return undefined;
39
43
  }
40
44
  const columns = [];
@@ -121,7 +125,7 @@ function relationshipFromTf(block, owner, ctx) {
121
125
  try {
122
126
  if (targetFilterOwner === undefined)
123
127
  throw ownerErr;
124
- filter = filterFromTf(block.attrs["filter"], targetFilterOwner, `${where}.filter`, ctx);
128
+ filter = targetOrBothSidesFilter(block.attrs["filter"], ownerFilterOwner, targetFilterOwner, `${where}.filter`, ctx);
125
129
  }
126
130
  catch (targetErr) {
127
131
  // Neither side decodes the filter. Writing the relationship with no
@@ -143,6 +147,28 @@ function relationshipFromTf(block, owner, ctx) {
143
147
  }
144
148
  return { key, target, columns, ...(filter !== undefined && { filter }) };
145
149
  }
150
+ /**
151
+ * A relationship filter over the target's fields, else over both sides'. A
152
+ * condition can compare a field of one side with a field of the other ("PR
153
+ * ID equals the related record's ID"), and the platform keeps that same
154
+ * filter on both sides, so each field resolves against the side it belongs
155
+ * to (#3144). Only a filter neither side decodes alone reaches the second
156
+ * decode, so every one-sided filter decodes as before; when that fails too,
157
+ * the target's error stands.
158
+ */
159
+ function targetOrBothSidesFilter(value, owner, target, where, ctx) {
160
+ try {
161
+ return filterFromTf(value, target, where, ctx);
162
+ }
163
+ catch (targetErr) {
164
+ try {
165
+ return filterFromTfOfOwners(value, [owner, target], where, ctx);
166
+ }
167
+ catch {
168
+ throw targetErr;
169
+ }
170
+ }
171
+ }
146
172
  function filterOwnerForTarget(target, ctx) {
147
173
  return target.kind === "app" || target.kind === "element"
148
174
  ? {
@@ -263,6 +289,10 @@ function targetResourceType(target) {
263
289
  function relatedFieldRef(value, target, ctx) {
264
290
  if (value === undefined)
265
291
  return undefined;
292
+ // Not reached from a live export: the platform refuses an object's own id as
293
+ // a join column's related field ("Field with ID ... was not found", #3203),
294
+ // and a join on the target's ID field exports as that field. Kept for HCL
295
+ // written by hand; build turns recordIdentity into the target's ID field.
266
296
  if (isTfExpr(value) && (value.$expr === "resource-attr" || value.$expr === "data-attr") && value.path.length === 1 && value.path[0] === "id") {
267
297
  const targetType = target.kind === "app"
268
298
  ? "elementum_app"
@@ -1,8 +1,8 @@
1
1
  import { workspaceAspectKey, } from "../../engine/build/context.js";
2
- import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
2
+ import { expr, isTfExpr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
3
  import { filterToTf } from "../access-policy/to-tf.js";
4
4
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
5
- import { authoredFieldKeysFromPayload, droppedEntryGap, fieldLookupName, fieldRefToTfValue, skippedResourceGap, unauthoredSiblingFieldRef, UNRESOLVED_FIELD_REF, } from "../field/to-tf.js";
5
+ import { droppedEntryGap, fieldLookupName, fieldRefToTfValue, siblingFieldOwnership, skippedResourceGap, unauthoredSiblingFieldRef, UNRESOLVED_FIELD_REF, } from "../field/to-tf.js";
6
6
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
7
7
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
8
8
  import { autoRelationColumnError } from "./column-contract.js";
@@ -176,7 +176,10 @@ function resolveTarget(value, where, opts) {
176
176
  refName,
177
177
  tfLabel: sibling.tfLabel,
178
178
  managed: true,
179
- fieldOwnership: authoredFieldKeysFromPayload(sibling.streamRootEntity?.payload),
179
+ // Each related field resolves to the address the sibling's own build
180
+ // gives it, whatever type the reference carries, so both sides of a
181
+ // pair name the same field (#3075).
182
+ fieldOwnership: siblingFieldOwnership(sibling.streamRootEntity?.payload, sibling.tfLabel, kind),
180
183
  };
181
184
  }
182
185
  }
@@ -225,7 +228,7 @@ function unauthoredRelatedField(value, target, opts) {
225
228
  const refName = value.refName ?? "";
226
229
  if (refName === "" || (value.parent !== undefined && value.parent !== target.refName))
227
230
  return undefined;
228
- const reason = unauthoredSiblingFieldRef(refName, { kind: target.kind, refName: target.refName, fieldOwnership: target.fieldOwnership });
231
+ const reason = unauthoredSiblingFieldRef(refName, { kind: target.kind, refName: target.refName, fieldOwnership: target.fieldOwnership }, fieldLookupName(value));
229
232
  return reason === undefined ? undefined : { reason, name: fieldLookupName(value) };
230
233
  }
231
234
  function resolveRelatedField(value, target, where, opts) {
@@ -249,7 +252,22 @@ function resolveRelatedField(value, target, where, opts) {
249
252
  opts.diagnostics.push(`${where}: record identity target does not match relationship target; dropped`);
250
253
  return undefined;
251
254
  }
252
- return target.value;
255
+ // A join column names a field: a record's identity is its system ID
256
+ // (HANDLE) field. The target's own id is not a field, and the platform
257
+ // refuses it ("Field with ID ... was not found").
258
+ // Fail rather than drop the column: a join that loses a column applies
259
+ // with a looser match.
260
+ if (target.kind === "table") {
261
+ throw new EntityTfError(`${where}: recordIdentity(<table>): a table has no record identity; name the table's ID column instead`);
262
+ }
263
+ // A task can rename its ID field, so read the managed task's own id_field_id
264
+ // rather than looking the field up by name.
265
+ if (target.kind === "task" && target.managed && isTfExpr(target.value) && target.value.$expr === "resource-attr") {
266
+ return expr.resourceAttr(target.value.type, target.value.label, ["id_field_id"]);
267
+ }
268
+ // A managed app or element builds its id field local; any other target
269
+ // looks the field up by its default name "ID".
270
+ return resolveRelatedField({ __kind: "field", refName: "id", name: "ID", fieldType: "HANDLE" }, target, where, opts);
253
271
  }
254
272
  const refName = value?.refName ?? "";
255
273
  if (refName === "") {
@@ -266,7 +284,7 @@ function resolveRelatedField(value, target, where, opts) {
266
284
  target.kind !== "table" &&
267
285
  (target.kind !== "task" || target.fieldOwnership?.has(refName) === true) &&
268
286
  target.tfLabel !== undefined) {
269
- const direct = fieldRefToTfValue(value?.fieldType ?? "", refName, target.tfLabel, target.kind, target.fieldOwnership);
287
+ const direct = fieldRefToTfValue(value?.fieldType ?? "", refName, target.tfLabel, target.kind, target.fieldOwnership, undefined, value === undefined ? undefined : fieldLookupName(value));
270
288
  if (direct !== undefined)
271
289
  return direct;
272
290
  }
@@ -1,6 +1,7 @@
1
1
  import { dataRefLabel, groupCatalogKey, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { scopedLabelToBagKey } from "../../engine/tf/index.js";
3
3
  import { ROLE_RESOURCE_TYPE } from "../org/role.js";
4
+ import { skipAndRelease } from "../shared/skip-release.js";
4
5
  import { finishPulledMemberList } from "../access-policy/member-list.js";
5
6
  import { serviceAccountAppRefName } from "../access-policy/from-tf.js";
6
7
  const KNOWN = new Set(["id", "object_id", "name", "description", "auto_share", "user_ids", "group_ids", "service_account_ids", "permissions", "managed", "tags"]);
@@ -90,7 +91,8 @@ export function rolesFromTf(blocks, owner, ctx) {
90
91
  if (!KNOWN.has(key))
91
92
  ctx.diagnostics.push(`${where}: unhandled attribute ${JSON.stringify(key)}`);
92
93
  if (typeof block.attrs["name"] !== "string") {
93
- ctx.diagnostics.push(`${where}: name is required; skipped`);
94
+ // Written to no source, so also left out of adoption (edk#3172).
95
+ skipAndRelease(ctx, `${ROLE_RESOURCE_TYPE}.${label}`, { problem: "its name is not text" }, `${where}: name is required; skipped`);
94
96
  return [];
95
97
  }
96
98
  const autoShare = strings(block.attrs["auto_share"], `${where}.auto_share`, ctx);
@@ -35,4 +35,6 @@ export interface NormalizedTableSearchTable {
35
35
  readonly creationTimeout?: string;
36
36
  }
37
37
  export type NormalizedSearchTable = NormalizedSnowflakeSearchTable | NormalizedLinkedSearchTable | NormalizedTableSearchTable;
38
- export declare function searchTableFromTf(block: TfBlock, ownerTfLabel: string, scope: ChildResourceScope | "table", ctx: FromTfContext): NormalizedSearchTable;
38
+ export declare function searchTableFromTf(block: TfBlock, ownerTfLabel: string, scope: ChildResourceScope | "table", ctx: FromTfContext,
39
+ /** A table-owned search table's columns: display name → the key its table's source gives each one (#3167). */
40
+ columnKeyByName?: ReadonlyMap<string, string>): NormalizedSearchTable;
@@ -1,8 +1,9 @@
1
1
  import { EntityTfError } from "../../engine/entity.js";
2
2
  import { resourceRefLabel } from "../../engine/pull/context.js";
3
- import { isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
+ import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
4
4
  import { fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { KNOWN_SEARCH_TABLE_ATTRS, SEARCH_TABLE_VARIANT_BY_RESOURCE } from "./types.js";
6
+ import { tableColumnKey } from "../table/keys.js";
6
7
  import { connectorIdentityFromTf } from "../shared/connector-from-tf.js";
7
8
  function requiredString(attrs, key, where) {
8
9
  const value = attrs[key];
@@ -35,7 +36,9 @@ function connectorKey(value, ctx, where) {
35
36
  }
36
37
  return identity.catalogKey;
37
38
  }
38
- export function searchTableFromTf(block, ownerTfLabel, scope, ctx) {
39
+ export function searchTableFromTf(block, ownerTfLabel, scope, ctx,
40
+ /** A table-owned search table's columns: display name → the key its table's source gives each one (#3167). */
41
+ columnKeyByName) {
39
42
  const label = block.label;
40
43
  if (label === undefined || label === "")
41
44
  throw new EntityTfError(`${block.type} block is missing its label`);
@@ -53,7 +56,7 @@ export function searchTableFromTf(block, ownerTfLabel, scope, ctx) {
53
56
  const index = value.path[1];
54
57
  if (typeof index !== "object")
55
58
  throw new EntityTfError(`${block.type}.${label}: table column reference has no key`);
56
- return tfLabelToTsLabel(sanitizeName(index.index));
59
+ return columnKeyByName?.get(index.index) ?? tableColumnKey(index.index);
57
60
  };
58
61
  const attrs = block.attrs["attribute_field_ids"];
59
62
  if (!Array.isArray(attrs))
@@ -4,6 +4,8 @@
4
4
  */
5
5
  import { rootParentFactoryEntry } from "../../catalog/render-helpers.js";
6
6
  import { EntityTfError } from "../../engine/entity.js";
7
+ import { plainObject } from "../../engine/pull/context.js";
8
+ import { tableColumnKeysByName } from "../table/keys.js";
7
9
  import { searchTableFromTf } from "./from-tf.js";
8
10
  import { printSearchTable } from "./printer.js";
9
11
  import { searchTableToTf } from "./to-tf.js";
@@ -53,13 +55,27 @@ function searchTableRefFromAuthoring(args) {
53
55
  ...(variant !== undefined && { __variant: variant }),
54
56
  };
55
57
  }
56
- function extractSearchTables(ownBlocks, _stream, ctx) {
58
+ /** Display name → key of each column of the stream's table, as its own source keys them (#3167). */
59
+ function ownTableColumnKeys(stream) {
60
+ const fields = stream.byKind.get("table")?.[0]?.attrs["fields"];
61
+ if (!Array.isArray(fields))
62
+ return undefined;
63
+ return tableColumnKeysByName(fields.flatMap((field) => {
64
+ const name = plainObject(field)?.["name"];
65
+ return typeof name === "string" ? [name] : [];
66
+ }));
67
+ }
68
+ function extractSearchTables(ownBlocks, stream, ctx) {
57
69
  const items = [];
58
70
  const skipped = [];
59
71
  const diagnostics = [];
72
+ let columnKeys;
60
73
  for (const block of ownBlocks) {
61
74
  try {
62
- items.push(searchTableFromTf(block, ctx.appTfLabel, block.type === SEARCH_TABLE_RESOURCE_TYPES.table ? "table" : ctx.parentScope, ctx));
75
+ const tableOwned = block.type === SEARCH_TABLE_RESOURCE_TYPES.table;
76
+ if (tableOwned)
77
+ columnKeys ??= ownTableColumnKeys(stream);
78
+ items.push(searchTableFromTf(block, ctx.appTfLabel, tableOwned ? "table" : ctx.parentScope, ctx, tableOwned ? columnKeys : undefined));
63
79
  }
64
80
  catch (err) {
65
81
  const address = `${block.type}.${block.label ?? ""}`;