@elementumai/edk 0.9.7 → 0.9.9

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 (148) hide show
  1. package/README.md +3 -2
  2. package/dist-sdk/src/catalog/factories.d.ts +14 -3
  3. package/dist-sdk/src/catalog/factories.js +32 -0
  4. package/dist-sdk/src/catalog/from-authoring.js +27 -33
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +2 -2
  7. package/dist-sdk/src/catalog/org.js +67 -29
  8. package/dist-sdk/src/catalog/token.js +10 -0
  9. package/dist-sdk/src/catalog/types.d.ts +20 -2
  10. package/dist-sdk/src/catalog/types.js +5 -0
  11. package/dist-sdk/src/core/index.d.ts +1 -1
  12. package/dist-sdk/src/core/index.js +1 -1
  13. package/dist-sdk/src/core/platform-id.d.ts +2 -0
  14. package/dist-sdk/src/core/platform-id.js +4 -0
  15. package/dist-sdk/src/core/system-fields.d.ts +14 -0
  16. package/dist-sdk/src/core/system-fields.js +6 -0
  17. package/dist-sdk/src/core/triggers/on-demand.d.ts +27 -24
  18. package/dist-sdk/src/core/triggers/on-demand.js +33 -12
  19. package/dist-sdk/src/core/types/aspect-category.d.ts +1 -0
  20. package/dist-sdk/src/core/types/aspect-category.js +1 -0
  21. package/dist-sdk/src/engine/build/context.d.ts +20 -8
  22. package/dist-sdk/src/engine/build/source-context.d.ts +14 -17
  23. package/dist-sdk/src/engine/build/source-context.js +1 -1
  24. package/dist-sdk/src/engine/pull/context.d.ts +9 -0
  25. package/dist-sdk/src/engine/pull/org.d.ts +4 -0
  26. package/dist-sdk/src/engine/pull/org.js +17 -2
  27. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +16 -0
  28. package/dist-sdk/src/engine/pull/procedure-refs.js +69 -0
  29. package/dist-sdk/src/engine/tf/expr.js +1 -1
  30. package/dist-sdk/src/engine/workspace/authoring-layout.d.ts +15 -0
  31. package/dist-sdk/src/engine/workspace/authoring-layout.js +33 -1
  32. package/dist-sdk/src/engine/workspace/loader.d.ts +40 -0
  33. package/dist-sdk/src/engine/workspace/loader.js +328 -0
  34. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +4 -0
  35. package/dist-sdk/src/entities/access-policy/from-tf.js +10 -2
  36. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +1 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.js +7 -2
  38. package/dist-sdk/src/entities/agent/build.d.ts +54 -8
  39. package/dist-sdk/src/entities/agent/build.js +36 -1
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +126 -2
  41. package/dist-sdk/src/entities/agent/from-tf.d.ts +7 -6
  42. package/dist-sdk/src/entities/agent/from-tf.js +176 -5
  43. package/dist-sdk/src/entities/agent/index.d.ts +2 -2
  44. package/dist-sdk/src/entities/agent/index.js +1 -1
  45. package/dist-sdk/src/entities/agent/to-tf.d.ts +4 -4
  46. package/dist-sdk/src/entities/agent/to-tf.js +185 -11
  47. package/dist-sdk/src/entities/agent/tools.d.ts +16 -5
  48. package/dist-sdk/src/entities/agent/tools.js +13 -1
  49. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +7 -0
  50. package/dist-sdk/src/entities/agent-tool/from-tf.js +29 -4
  51. package/dist-sdk/src/entities/agent-tool/to-tf.js +10 -9
  52. package/dist-sdk/src/entities/agent-tool/types.js +1 -0
  53. package/dist-sdk/src/entities/app/build.d.ts +2 -2
  54. package/dist-sdk/src/entities/app/build.js +6 -3
  55. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +5 -0
  56. package/dist-sdk/src/entities/app/display-blocks-to-layout.d.ts +45 -0
  57. package/dist-sdk/src/entities/app/display-blocks-to-layout.js +98 -0
  58. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.d.ts +55 -0
  59. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.js +99 -0
  60. package/dist-sdk/src/entities/app/from-tf.js +9 -7
  61. package/dist-sdk/src/entities/app/to-tf.js +15 -7
  62. package/dist-sdk/src/entities/automation/build.d.ts +8 -1
  63. package/dist-sdk/src/entities/automation/build.js +36 -5
  64. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -7
  65. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +2 -0
  66. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +77 -8
  67. package/dist-sdk/src/entities/automation/from-tf.d.ts +10 -1
  68. package/dist-sdk/src/entities/automation/from-tf.js +803 -62
  69. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  70. package/dist-sdk/src/entities/automation/module.js +13 -3
  71. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +12 -4
  72. package/dist-sdk/src/entities/automation/output-key-wire-name.js +17 -6
  73. package/dist-sdk/src/entities/automation/script-code.d.ts +1 -1
  74. package/dist-sdk/src/entities/automation/script-code.js +15 -11
  75. package/dist-sdk/src/entities/automation/task-label.d.ts +2 -0
  76. package/dist-sdk/src/entities/automation/task-label.js +18 -0
  77. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -9
  78. package/dist-sdk/src/entities/automation/tasks.js +16 -4
  79. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  80. package/dist-sdk/src/entities/automation/to-tf.js +385 -52
  81. package/dist-sdk/src/entities/automation/triggers.d.ts +14 -5
  82. package/dist-sdk/src/entities/automation/triggers.js +1 -1
  83. package/dist-sdk/src/entities/dashboard/from-tf.js +1 -1
  84. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  85. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +1 -1
  86. package/dist-sdk/src/entities/element/build.d.ts +30 -7
  87. package/dist-sdk/src/entities/element/build.js +6 -3
  88. package/dist-sdk/src/entities/element/from-tf.js +7 -3
  89. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  90. package/dist-sdk/src/entities/element/index.js +1 -1
  91. package/dist-sdk/src/entities/element/to-tf.js +49 -8
  92. package/dist-sdk/src/entities/field/from-tf.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/from-tf.js +12 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +1 -1
  96. package/dist-sdk/src/entities/field/to-tf.js +19 -5
  97. package/dist-sdk/src/entities/org/category-ref.d.ts +5 -0
  98. package/dist-sdk/src/entities/org/category-ref.js +12 -0
  99. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -3
  100. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +1 -0
  101. package/dist-sdk/src/entities/record-create-form/to-tf.js +13 -5
  102. package/dist-sdk/src/entities/relationship/from-tf.js +15 -4
  103. package/dist-sdk/src/entities/role/from-tf.js +10 -4
  104. package/dist-sdk/src/entities/search-table/build.d.ts +1 -1
  105. package/dist-sdk/src/entities/search-table/from-tf.d.ts +1 -0
  106. package/dist-sdk/src/entities/search-table/from-tf.js +6 -0
  107. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  108. package/dist-sdk/src/entities/search-table/to-tf.js +3 -3
  109. package/dist-sdk/src/entities/search-table/types.js +1 -0
  110. package/dist-sdk/src/entities/service-account/from-tf.js +10 -4
  111. package/dist-sdk/src/entities/service-account/to-tf.d.ts +2 -1
  112. package/dist-sdk/src/entities/service-account/to-tf.js +7 -0
  113. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -1
  114. package/dist-sdk/src/entities/shared/filters/ast.js +3 -0
  115. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -1
  116. package/dist-sdk/src/entities/shared/filters/tf-codec.js +8 -4
  117. package/dist-sdk/src/entities/shared/handle-description.d.ts +12 -0
  118. package/dist-sdk/src/entities/shared/handle-description.js +20 -0
  119. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -1
  120. package/dist-sdk/src/entities/shared/types/field-types.js +5 -8
  121. package/dist-sdk/src/entities/skill/build.d.ts +51 -2
  122. package/dist-sdk/src/entities/skill/build.js +65 -8
  123. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +35 -3
  124. package/dist-sdk/src/entities/skill/from-tf.d.ts +11 -0
  125. package/dist-sdk/src/entities/skill/from-tf.js +39 -7
  126. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  127. package/dist-sdk/src/entities/skill/index.js +1 -1
  128. package/dist-sdk/src/entities/skill/input-coverage.d.ts +21 -0
  129. package/dist-sdk/src/entities/skill/input-coverage.js +148 -5
  130. package/dist-sdk/src/entities/skill/to-tf.d.ts +6 -25
  131. package/dist-sdk/src/entities/skill/to-tf.js +22 -38
  132. package/dist-sdk/src/entities/skill/tools.d.ts +2 -1
  133. package/dist-sdk/src/entities/skill/tools.js +3 -1
  134. package/dist-sdk/src/entities/skill-tool/from-tf.js +10 -3
  135. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +5 -5
  136. package/dist-sdk/src/entities/skill-tool/to-tf.js +5 -7
  137. package/dist-sdk/src/entities/table/to-tf.js +3 -4
  138. package/dist-sdk/src/entities/task/to-tf.js +3 -2
  139. package/dist-sdk/src/entities/view/from-tf.js +36 -10
  140. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  141. package/dist-sdk/src/entities/view/to-tf.js +44 -30
  142. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  143. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  144. package/dist-sdk/src/entities/widget/to-tf.js +52 -23
  145. package/dist-sdk/src/graph/index.d.ts +19 -1
  146. package/dist-sdk/src/graph/index.js +20 -0
  147. package/dist-sdk/src/graph/types.d.ts +19 -0
  148. package/package.json +10 -5
@@ -8,7 +8,7 @@
8
8
  * it's reference-model-agnostic (typed params, no id resolution), so there's
9
9
  * nothing to retarget; it relocates to a shared home at the cutover.
10
10
  */
11
- import type { AppOrElementRef, DatamineRef, FieldRef } from "../../catalog/index.js";
11
+ import type { ApprovalChainRef, AppOrElementRef, DatamineRef, FieldRef } from "../../catalog/index.js";
12
12
  import type { UnsafePlatformId } from "../../core/platform-id.js";
13
13
  import type { RecordShape } from "../field/record-shape.js";
14
14
  import { type InferTriggerType, type OnDemandTriggerOptions, type TriggerInputFieldDef, type TriggerInputSchema } from "../../core/triggers/on-demand.js";
@@ -63,14 +63,15 @@ export declare function schedule(opts: ScheduleTriggerOptions): TriggerChain<Sch
63
63
  * the wire trigger-parameter declarations — a bare type parameter would be
64
64
  * erased and deploy a trigger with no declared inputs.
65
65
  */
66
- export type TriggerInputSchemaSpec = Record<string, TriggerInputFieldDef | TriggerFieldTypeAlias>;
66
+ type TriggerInputShorthand = Exclude<TriggerFieldTypeAlias, "record">;
67
+ export type TriggerInputSchemaSpec = Record<string, TriggerInputFieldDef | TriggerInputShorthand>;
67
68
  /** Normalize a spec entry to the full def shape (type level). */
68
69
  type NormalizeSpec<S extends TriggerInputSchemaSpec> = {
69
- [K in keyof S]: S[K] extends TriggerFieldTypeAlias ? {
70
+ [K in keyof S]: S[K] extends TriggerInputShorthand ? {
70
71
  type: S[K];
71
72
  } : Extract<S[K], TriggerInputFieldDef>;
72
73
  };
73
- export declare function onDemand<S extends TriggerInputSchemaSpec, Options extends OnDemandTriggerOptions = Record<string, never>>(schema: S, options?: Options): TriggerChain<InferTriggerType<NormalizeSpec<S> & TriggerInputSchema, Options>>;
74
+ export declare function onDemand<S extends TriggerInputSchemaSpec, Options extends OnDemandTriggerOptions = Record<string, never>>(schema: S, options?: Options & Record<Exclude<keyof Options, keyof OnDemandTriggerOptions>, never>): TriggerChain<InferTriggerType<NormalizeSpec<S> & TriggerInputSchema, Options>>;
74
75
  export interface WebhookTriggerOptions {
75
76
  readonly authenticated?: boolean;
76
77
  /** Pre-built wire custom-response envelope. */
@@ -110,7 +111,15 @@ export declare function temporal<A extends AppOrElementRef>(opts: TemporalTrigge
110
111
  export type approvalProcessStatusUpdatedStatus = "ACTIVE" | "STEP_APPROVED" | "CANCELLED" | "DENIED" | "APPROVED";
111
112
  export interface approvalProcessStatusUpdatedTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
112
113
  readonly app: A;
113
- readonly approvalChain: string;
114
+ /**
115
+ * The approval chain template to watch. Optional - the platform's
116
+ * approvalChainTemplate relation is genuinely nullable (edk#712); omit it
117
+ * to fire on any approval chain template's status change. A managed
118
+ * `ApprovalChainRef` token; `unsafePlatformId(...)` is the explicit escape
119
+ * hatch for a raw platform id pulled source can't reconstruct as a ref
120
+ * (same pattern as `dataMine`'s `datamine` option) - never a bare string.
121
+ */
122
+ readonly approvalChain?: ApprovalChainRef | UnsafePlatformId;
114
123
  readonly status: approvalProcessStatusUpdatedStatus;
115
124
  }
116
125
  /** Fires when an approval chain on a record changes to the configured status. */
@@ -113,7 +113,7 @@ export function approvalProcessStatusUpdated(opts) {
113
113
  wire: {
114
114
  approvalChain: {
115
115
  aspectId: opts.app,
116
- approvalChainTemplateId: opts.approvalChain,
116
+ ...(opts.approvalChain !== undefined ? { approvalChainTemplateId: opts.approvalChain } : {}),
117
117
  status: opts.status,
118
118
  type: "APPROVAL_CHAIN_UPDATE",
119
119
  },
@@ -78,7 +78,7 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, owner, ctx) {
78
78
  }
79
79
  return [{ ...style, type: "records", target,
80
80
  ...(aspect["filter"] !== undefined && {
81
- filter: filterFromTf(filterWireToTf(decodeJson(aspect["filter"])), { ...owner, ownerRefName: owner.ownerRefName ?? owner.ownerTfLabel }, `${where}.aspect_widget.filter`),
81
+ filter: filterFromTf(filterWireToTf(decodeJson(aspect["filter"])), { ...owner, ownerRefName: owner.ownerRefName ?? owner.ownerTfLabel, foreignFieldRefsById: ctx.foreignFieldRefsById }, `${where}.aspect_widget.filter`),
82
82
  }),
83
83
  }];
84
84
  });
@@ -22,5 +22,6 @@ export interface DynamicLayoutToTfOptions {
22
22
  readonly diagnostics: string[];
23
23
  readonly orgRefs: OrgRefLookup;
24
24
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
25
+ readonly fieldAddresses?: ReadonlyMap<string, string>;
25
26
  }
26
27
  export declare function dynamicLayoutsToTf(layouts: Readonly<Record<string, DynamicLayoutWire>> | undefined, opts: DynamicLayoutToTfOptions): TfBlock[];
@@ -198,7 +198,7 @@ function resolveField(value, where, opts) {
198
198
  opts.diagnostics.push(`${where}: field "${refName}" targets a different app; dropped`);
199
199
  return undefined;
200
200
  }
201
- const resolved = fieldRefToTfValue(token?.fieldType ?? "", refName, opts.ownerTfLabel, "app");
201
+ const resolved = fieldRefToTfValue(token?.fieldType ?? "", refName, opts.ownerTfLabel, "app", opts.fieldAddresses);
202
202
  if (resolved === undefined)
203
203
  opts.diagnostics.push(`${where}: field "${refName}" has no Terraform mapping; dropped`);
204
204
  return resolved;
@@ -37,8 +37,8 @@ export interface ElementCloudConnection {
37
37
  readonly idColumnName?: string;
38
38
  }
39
39
  export interface ElementV2Options<F extends Record<string, AppField> = Record<string, AppField>, R extends Record<string, FieldRef> = Record<never, never>> extends EntityDeployOptions {
40
- /** The platform handle (business acronym, e.g. "PRD") — distinct from the refName. Omit to let the platform assign one. */
41
- readonly handle?: string;
40
+ /** Required platform handle (business acronym, e.g. "PRD") — distinct from the refName. */
41
+ readonly handle: string;
42
42
  readonly name: string;
43
43
  readonly category: AppCategory;
44
44
  readonly namespace?: string;
@@ -71,13 +71,32 @@ export interface ElementV2Options<F extends Record<string, AppField> = Record<st
71
71
  * handle, but are **never included in the deploy payload** (the platform owns them).
72
72
  */
73
73
  readonly readonlyFields?: R;
74
- /** Record-view (LAYOUT surface) display blocks. */
74
+ /**
75
+ * Record-view (LAYOUT surface) display blocks. `field`/`group` blocks map
76
+ * to an `elementum_layout` group section on the element's Initiate stage;
77
+ * `widget`/`comments` blocks and groups nested inside a group have no
78
+ * terraform layout equivalent and are diagnosed and dropped individually.
79
+ * Mutually exclusive with `layouts` — author one or the other, not both.
80
+ */
75
81
  readonly displayBlocks?: readonly DisplayBlock[];
76
- /** New-record form (CREATE surface) display blocks. */
82
+ /**
83
+ * New-record form (CREATE surface) display blocks. `field`/`group` blocks
84
+ * map to `elementum_record_create_form` sections; `widget`/`comments`
85
+ * blocks and groups nested inside a group have no terraform equivalent and
86
+ * are diagnosed and dropped individually. Mutually exclusive with
87
+ * `recordCreateForm` — both target the same new-record form; author one or
88
+ * the other, not both.
89
+ */
77
90
  readonly recordCreateDisplayBlocks?: readonly DisplayBlock[];
78
91
  /**
79
- * Per-stage record layouts (terraform-path). Elements rarely carry stages;
80
- * included for parity with app pull when layouts appear on the stream.
92
+ * The element's record-detail layout (terraform-path). Unlike apps,
93
+ * elements carry no stages at all — there is exactly one implicit layout
94
+ * (the platform's Initiate stage), so `stage_id` is always omitted on
95
+ * build (letting the provider auto-resolve it). Key this bag `layout` —
96
+ * the pull path (and the `displayBlocks` → `layouts` mapping) always uses
97
+ * that key too, matching the bridge's fixed `<ns>_layout` resource label;
98
+ * a different key still builds correctly but won't resolve to the same
99
+ * terraform address on a re-pull.
81
100
  */
82
101
  readonly layouts?: Readonly<Record<string, AppLayout>>;
83
102
  /** Saved list views, keyed by view ref name. */
@@ -89,7 +108,11 @@ export interface ElementV2Options<F extends Record<string, AppField> = Record<st
89
108
  readonly dashboards?: Readonly<Record<string, AppDashboard>>;
90
109
  readonly widgets?: Readonly<Record<string, AppWidget>>;
91
110
  readonly dashboardViews?: Readonly<Record<string, AppDashboardView>>;
92
- /** Typed new-record form (`elementum_record_create_form`). */
111
+ /**
112
+ * Typed new-record form (`elementum_record_create_form`). Mutually
113
+ * exclusive with `recordCreateDisplayBlocks` — author one or the other,
114
+ * not both.
115
+ */
93
116
  readonly recordCreateForm?: AppRecordCreateForm;
94
117
  readonly relationships?: Readonly<Record<string, AppRelationship>>;
95
118
  /** Display order of `listViews` (by key). Defaults to declaration order. */
@@ -8,13 +8,16 @@ export const ELEMENT_SYSTEM_FIELD_KEYS = ["id", "title"];
8
8
  * element validation rules, so a malformed definition fails at define time
9
9
  * rather than as an opaque platform error during apply.
10
10
  *
11
- * - `handle` — letters only (A–Z or a–z), when provided (it's optional).
11
+ * - `handle` — required and letters only (A–Z or a–z).
12
12
  * Existing elements can carry a lowercase handle (the platform doesn't
13
13
  * enforce case), so this only rejects non-letters, not case.
14
14
  * - `namespace` — lowercase letters only (a–z), when provided
15
15
  */
16
16
  function validateElementOptions(opts) {
17
- if (opts.handle !== undefined && !/^[A-Za-z]+$/.test(opts.handle)) {
17
+ if (!opts.handle) {
18
+ throw new Error(`element "${opts.name}": handle is required by the platform.`);
19
+ }
20
+ if (!/^[A-Za-z]+$/.test(opts.handle)) {
18
21
  throw new Error(`element "${opts.name}": handle "${opts.handle}" must be letters only (A–Z or a–z).`);
19
22
  }
20
23
  if (opts.namespace !== undefined && !/^[a-z]+$/.test(opts.namespace)) {
@@ -60,7 +63,7 @@ export function element(opts) {
60
63
  parent: refName,
61
64
  parentKind: "element",
62
65
  parentName: opts.name,
63
- fieldType: field.type,
66
+ fieldType: field.expression !== undefined ? "CALCULATED" : field.type,
64
67
  ...("dynamicSource" in field && field.dynamicSource === true ? { dynamicSource: true } : {}),
65
68
  ...(field.options !== undefined ? { options: picklistOptionLabels(field.options) } : {}),
66
69
  ...(field.tags !== undefined ? { tags: field.tags } : {}),
@@ -82,12 +82,12 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
82
82
  const hybridTable = optionalBoolean(attrs, "snowflake_hybrid_table", `element "${label}"`, ctx);
83
83
  const titleColumnName = optionalString(attrs, "title_column_name", `element "${label}"`, ctx);
84
84
  const idColumnName = optionalString(attrs, "id_column_name", `element "${label}"`, ctx);
85
- const cloudConnection = snowDb !== undefined ||
85
+ const hasCloudMapping = snowDb !== undefined ||
86
86
  snowSchema !== undefined ||
87
87
  snowTable !== undefined ||
88
- hybridTable !== undefined ||
89
88
  titleColumnName !== undefined ||
90
- idColumnName !== undefined
89
+ idColumnName !== undefined;
90
+ const cloudConnection = hasCloudMapping
91
91
  ? {
92
92
  kind: "snowflake",
93
93
  ...(snowDb !== undefined && { database: snowDb }),
@@ -98,6 +98,9 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
98
98
  ...(idColumnName !== undefined && { idColumnName }),
99
99
  }
100
100
  : undefined;
101
+ const cloudOptions = !hasCloudMapping && hybridTable !== undefined
102
+ ? { snowflake: { hybridTable } }
103
+ : undefined;
101
104
  let category;
102
105
  if (attrs["category_id"] !== undefined) {
103
106
  const dataLabel = dataRefLabel(attrs["category_id"], "elementum_category");
@@ -176,6 +179,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
176
179
  fields,
177
180
  stages: [],
178
181
  ...(cloudLinkId !== undefined && { cloudLinkId }),
182
+ ...(cloudOptions !== undefined && { cloudOptions }),
179
183
  ...(cloudConnection !== undefined && { cloudConnection }),
180
184
  ...(commentsEnabled !== undefined && { commentsEnabled }),
181
185
  ...(layouts.length > 0 && { layouts }),
@@ -9,7 +9,7 @@ export { element, type ElementCloudConnection, type ElementConfigured, type Elem
9
9
  export { type AppRecordCreateForm, type AppRecordCreateFormSection } from "../app/build.js";
10
10
  export { listViewDensity, managedViewSortAggregation, managedViewSortDirection, type ListViewDensity, type ManagedViewSort, type ManagedViewSortAggregation, type ManagedViewSortDirection, type ManagedViewSortField, type ManagedViewSortOrder, } from "../view/build.js";
11
11
  export { type AppRelationship, type AppRelationshipColumn } from "../relationship/build.js";
12
- export { dashboardRecordsWidget, dashboardWidgetSize, type DashboardRecordsWidget, type DashboardWidget, type DashboardWidgetSize, } from "../dashboard/build.js";
12
+ export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, type DashboardChartWidget, type DashboardRecordsWidget, type DashboardWidget, type DashboardWidgetSize, } from "../dashboard/build.js";
13
13
  export { attachmentField, booleanField, calculatedField, dateField, dateTimeField, decimalField, dropdownDisplay, dropdownField, dropdownOption, dropdownValue, groupField, jsonField, multiSelectField, numberField, relationField, richTextField, textField, userField, 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";
14
14
  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";
15
15
  export { asc, desc, sortBy, type SortDirection, type SortOrder } from "../shared/types/common.js";
@@ -7,7 +7,7 @@
7
7
  */
8
8
  export { element, } from "./build.js";
9
9
  export { listViewDensity, managedViewSortAggregation, managedViewSortDirection, } from "../view/build.js";
10
- export { dashboardRecordsWidget, dashboardWidgetSize, } from "../dashboard/build.js";
10
+ export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, } from "../dashboard/build.js";
11
11
  export { attachmentField, booleanField, calculatedField, dateField, dateTimeField, decimalField, dropdownDisplay, dropdownField, dropdownOption, dropdownValue, groupField, jsonField, multiSelectField, numberField, relationField, richTextField, textField, userField, } from "../field/build.js";
12
12
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, } from "../field/calc.js";
13
13
  export { asc, desc, sortBy } from "../shared/types/common.js";
@@ -6,9 +6,12 @@
6
6
  import { EntityTfError } from "../../engine/entity.js";
7
7
  import { expr, snakeSlug } from "../../engine/tf/index.js";
8
8
  import { accessPolicyToTf } from "../access-policy/to-tf.js";
9
+ import { displayBlocksToLayoutSections } from "../app/display-blocks-to-layout.js";
10
+ import { displayBlocksToRecordCreateFormSections } from "../app/display-blocks-to-record-create-form.js";
9
11
  import { dashboardsToTf } from "../dashboard/to-tf.js";
10
12
  import { fieldToTf } from "../field/to-tf.js";
11
13
  import { CATEGORY_ORG_BAG } from "../org/category.js";
14
+ import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.js";
12
15
  import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
13
16
  import { recordCreateFormToTf } from "../record-create-form/to-tf.js";
14
17
  import { relationshipsToTf } from "../relationship/to-tf.js";
@@ -55,6 +58,12 @@ export function elementToTf(entity, ctx) {
55
58
  elementAttrs["icon"] = payload.icon;
56
59
  if (payload.color !== undefined)
57
60
  elementAttrs["color"] = payload.color;
61
+ const hybridTable = payload.cloudOptions?.snowflake?.hybridTable;
62
+ if (payload.cloudOptions !== undefined && payload.cloudConnection !== undefined) {
63
+ throw new EntityTfError(`element "${entity.refName}": cloudOptions and cloudConnection are mutually exclusive`);
64
+ }
65
+ if (hybridTable !== undefined)
66
+ elementAttrs["snowflake_hybrid_table"] = hybridTable;
58
67
  // A LINKED element's Snowflake table mapping — create-only (the table
59
68
  // binding is immutable once set), but sent every build so a rebuild
60
69
  // doesn't null it out on an in-place update.
@@ -77,10 +86,10 @@ export function elementToTf(entity, ctx) {
77
86
  if (categoryName !== undefined && categoryName !== "") {
78
87
  const category = ctx.orgRefs.byName(CATEGORY_ORG_BAG, categoryName);
79
88
  if (category === undefined) {
80
- ctx.diagnostics.push(`category "${categoryName}" is not in the org catalog — re-run \`edk pull org --data-only\` (categories must already exist in the org)`);
89
+ ctx.diagnostics.push(missingCategoryDiagnostic(categoryName));
81
90
  }
82
91
  else {
83
- elementAttrs["category_id"] = expr.dataAttr("elementum_category", category.tfLabel, ["id"]);
92
+ elementAttrs["category_id"] = categoryIdExpr(category);
84
93
  }
85
94
  }
86
95
  const cloudLink = payload.cloudLinkId;
@@ -94,11 +103,24 @@ export function elementToTf(entity, ctx) {
94
103
  elementAttrs["cloud_link_id"] = expr.dataAttr("elementum_cloudlink", resolved.tfLabel, ["id"]);
95
104
  }
96
105
  }
97
- if (payload.cloudOptions !== undefined) {
98
- ctx.diagnostics.push("cloudOptions are not supported on the terraform path yet; dropped");
106
+ // displayBlocks (LAYOUT surface) → elementum_layout. recordCreateDisplayBlocks
107
+ // (CREATE surface) → elementum_record_create_form. Both mapped below, same
108
+ // mutual-exclusivity precedent: a surface has exactly one terraform target,
109
+ // authored either through the typed builder or through display blocks, not
110
+ // both.
111
+ if (payload.layouts !== undefined && payload.displayBlocks !== undefined) {
112
+ throw new EntityTfError(`element "${entity.refName}": both "layouts" and "displayBlocks" are authored — they both target the record-detail layout; author only one`);
113
+ }
114
+ if (payload.recordCreateForm !== undefined && payload.recordCreateDisplayBlocks !== undefined) {
115
+ throw new EntityTfError(`element "${entity.refName}": both "recordCreateForm" and "recordCreateDisplayBlocks" are authored — they both target the new-record form; author only one`);
116
+ }
117
+ let mappedLayoutSections;
118
+ if (payload.displayBlocks !== undefined) {
119
+ mappedLayoutSections = displayBlocksToLayoutSections(payload.displayBlocks, `element "${entity.refName}" displayBlocks`, ctx.diagnostics);
99
120
  }
100
- if (payload.displayBlocks !== undefined || payload.recordCreateDisplayBlocks !== undefined) {
101
- ctx.diagnostics.push("display blocks are not supported on the terraform path; dropped");
121
+ let mappedRecordCreateFormSections;
122
+ if (payload.recordCreateDisplayBlocks !== undefined) {
123
+ mappedRecordCreateFormSections = displayBlocksToRecordCreateFormSections(payload.recordCreateDisplayBlocks, `element "${entity.refName}" recordCreateDisplayBlocks`, ctx.diagnostics);
102
124
  }
103
125
  const blocks = [];
104
126
  const fieldAddresses = new Map();
@@ -172,8 +194,20 @@ export function elementToTf(entity, ctx) {
172
194
  orgRefs: ctx.orgRefs,
173
195
  workspaceAspects: ctx.workspaceAspects,
174
196
  diagnostics: ctx.diagnostics,
197
+ fieldAddresses,
175
198
  }));
176
- const { blocks: viewBlocks } = viewToTf(payload.layouts, payload.listViews, payload.calendarViews, payload.kanbanViews, payload.dashboardViews, undefined, payload.viewOrder, {
199
+ // An element has exactly one implicit layout (the platform's Initiate
200
+ // stage — see layoutToTf's element-scope stage_id omission) — "layout" is
201
+ // a synthetic bag key here, not a real stage reference. It must match the
202
+ // bridge's own fixed "<prefix>_layout" resource-label convention
203
+ // (cmd/elementum/export/hcl_app.go's generateLayoutIR) and view/from-tf.ts's
204
+ // matching pull-side fallback, so a pull → rebuild round-trip resolves to
205
+ // the same terraform address instead of planning a destroy+recreate.
206
+ const layoutsForViewToTf = payload.layouts ??
207
+ (mappedLayoutSections !== undefined && mappedLayoutSections.length > 0
208
+ ? { layout: { sections: mappedLayoutSections } }
209
+ : undefined);
210
+ const { blocks: viewBlocks } = viewToTf(layoutsForViewToTf, payload.listViews, payload.calendarViews, payload.kanbanViews, payload.dashboardViews, undefined, payload.viewOrder, {
177
211
  ownerRefName: ctx.appRefName,
178
212
  ownerTfLabel: ctx.appTfLabel,
179
213
  scope: "element",
@@ -182,14 +216,20 @@ export function elementToTf(entity, ctx) {
182
216
  dashboardKeys: new Set(Object.keys(payload.dashboards ?? {})),
183
217
  orgRefs: ctx.orgRefs,
184
218
  diagnostics: ctx.diagnostics,
219
+ fieldAddresses,
185
220
  });
186
221
  blocks.push(...viewBlocks);
187
- const recordCreateForm = recordCreateFormToTf(payload.recordCreateForm, {
222
+ const recordCreateFormForToTf = payload.recordCreateForm ??
223
+ (mappedRecordCreateFormSections !== undefined && mappedRecordCreateFormSections.length > 0
224
+ ? { sections: mappedRecordCreateFormSections }
225
+ : undefined);
226
+ const recordCreateForm = recordCreateFormToTf(recordCreateFormForToTf, {
188
227
  ownerRefName: ctx.appRefName,
189
228
  ownerTfLabel: ctx.appTfLabel,
190
229
  scope: "element",
191
230
  objectId,
192
231
  diagnostics: ctx.diagnostics,
232
+ fieldAddresses,
193
233
  });
194
234
  if (recordCreateForm !== undefined)
195
235
  blocks.push(recordCreateForm);
@@ -213,6 +253,7 @@ export function elementToTf(entity, ctx) {
213
253
  objectId,
214
254
  orgRefs: ctx.orgRefs,
215
255
  diagnostics: ctx.diagnostics,
256
+ fieldAddresses,
216
257
  });
217
258
  blocks.push(block);
218
259
  }
@@ -29,3 +29,9 @@ export declare function fieldFromTf(block: TfBlock, owner: FieldOwner, ctx: From
29
29
  * unknown resource type.
30
30
  */
31
31
  export declare function fieldKeyFromTfRef(v: TfValue, ownerTfLabel?: string, scope?: ChildResourceScope): string | undefined;
32
+ /**
33
+ * Resolve either a normal Terraform field reference or a raw platform field
34
+ * ID recovered from post-adoption state. The owner check prevents a UUID from
35
+ * one app or element from becoming a same-owner field token accidentally.
36
+ */
37
+ export declare function fieldKeyFromTfValue(v: TfValue, ownerRefName: string, ownerTfLabel: string, scope: ChildResourceScope, ctx: FromTfContext): string | undefined;
@@ -498,3 +498,15 @@ export function fieldKeyFromTfRef(v, ownerTfLabel, scope = "app") {
498
498
  const bare = ownerTfLabel !== undefined ? bareChildResourceLabel(ownerTfLabel, v.label, scope) : v.label;
499
499
  return ownerTfLabel !== undefined ? scopedLabelToBagKey(ownerTfLabel, v.label, scope) : tfLabelToTsLabel(bare);
500
500
  }
501
+ /**
502
+ * Resolve either a normal Terraform field reference or a raw platform field
503
+ * ID recovered from post-adoption state. The owner check prevents a UUID from
504
+ * one app or element from becoming a same-owner field token accidentally.
505
+ */
506
+ export function fieldKeyFromTfValue(v, ownerRefName, ownerTfLabel, scope, ctx) {
507
+ if (typeof v === "string") {
508
+ const stateRef = ctx.foreignFieldRefsById?.get(v);
509
+ return stateRef?.ownerRefName === ownerRefName ? stateRef.fieldKey : undefined;
510
+ }
511
+ return fieldKeyFromTfRef(v, ownerTfLabel, scope);
512
+ }
@@ -17,6 +17,7 @@ export const fieldModule = {
17
17
  key: t.typeKey,
18
18
  resourceType: t.resourceType,
19
19
  implemented: t.implemented === true,
20
+ authoringType: t.authoringType,
20
21
  })),
21
22
  },
22
23
  // Foreign relationship/relation fields are looked up by name under their
@@ -135,5 +135,5 @@ export interface FieldToTfResult {
135
135
  }
136
136
  /** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
137
137
  export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
138
- export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: ChildResourceScope): TfExpr | undefined;
138
+ export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: ChildResourceScope, fieldAddresses?: ReadonlyMap<string, string>): TfExpr | undefined;
139
139
  export {};
@@ -231,7 +231,7 @@ function stageOrgRefs(real) {
231
231
  * and committed only once the ENTIRE config resolves — an early `undefined`
232
232
  * return anywhere below leaves no orphaned `data.tf` block behind.
233
233
  */
234
- function buildDynamicPicklistConfigAttr(cfg, opts, where) {
234
+ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
235
235
  if (cfg.relatedAspectId === undefined || cfg.relatedLabelFieldId === undefined) {
236
236
  opts.diagnostics.push(`${where}: dynamic picklist config requires relatedAspectId and relatedLabelFieldId; dropped`);
237
237
  return undefined;
@@ -277,8 +277,15 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where) {
277
277
  }
278
278
  attrs["parent_mappings"] = mappings;
279
279
  }
280
- if (cfg.autoRelate !== undefined)
281
- attrs["auto_relate"] = cfg.autoRelate;
280
+ if (cfg.autoRelate !== undefined) {
281
+ // MULTI_PICKLIST create accepts auto_relate=true, but Read hydrates false.
282
+ if (typeKey === "multiPicklist" && cfg.autoRelate === true) {
283
+ opts.diagnostics.push(`${where}: autoRelate is not persisted on multi-select fields and was omitted`);
284
+ }
285
+ else {
286
+ attrs["auto_relate"] = cfg.autoRelate;
287
+ }
288
+ }
282
289
  if (cfg.valuesRenderType !== undefined)
283
290
  attrs["values_render_type"] = cfg.valuesRenderType;
284
291
  if (cfg.filter !== undefined) {
@@ -541,7 +548,7 @@ export function fieldToTf(typeKey, inner, opts) {
541
548
  }
542
549
  if (subType.hasOptions === true && inner.config?.dynamic !== undefined) {
543
550
  const where = `field "${name}"`;
544
- const dynamicConfig = buildDynamicPicklistConfigAttr(inner.config.dynamic, opts, where);
551
+ const dynamicConfig = buildDynamicPicklistConfigAttr(inner.config.dynamic, opts, where, typeKey);
545
552
  if (dynamicConfig === undefined)
546
553
  return undefined;
547
554
  attrs["dynamic_config"] = dynamicConfig;
@@ -627,13 +634,20 @@ function scalarOrUndefined(v) {
627
634
  */
628
635
  /** Elements only have `id`/`title` as real system fields (no status/stage/audit fields) — see `element/locals.ts`. */
629
636
  const ELEMENT_SYSTEM_FIELD_KEYS = new Set(["id", "title"]);
630
- export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app") {
637
+ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldAddresses) {
631
638
  if (!isCanonicalTsLabel(refName))
632
639
  return undefined;
633
640
  const isSystemField = scope === "element" ? ELEMENT_SYSTEM_FIELD_KEYS.has(refName) : SYSTEM_FIELD_KEY_SET.has(refName);
634
641
  if (isSystemField) {
635
642
  return expr.local(`${ownerTfLabel}_${tsLabelToTfLabel(refName)}_field_id`);
636
643
  }
644
+ const knownAddress = fieldAddresses?.get(refName);
645
+ if (knownAddress !== undefined) {
646
+ const dotIndex = knownAddress.indexOf(".");
647
+ if (dotIndex !== -1) {
648
+ return expr.resourceAttr(knownAddress.slice(0, dotIndex), knownAddress.slice(dotIndex + 1), ["id"]);
649
+ }
650
+ }
637
651
  const subType = SUB_TYPE_BY_AUTHORING_TYPE.get(fieldType);
638
652
  if (subType === undefined)
639
653
  return undefined;
@@ -0,0 +1,5 @@
1
+ import type { OrgRefResolution } from "../../engine/build/context.js";
2
+ import { type TfExpr } from "../../engine/tf/index.js";
3
+ /** Resource ID when the category is created in this apply; otherwise a live data lookup. */
4
+ export declare function categoryIdExpr(resolved: OrgRefResolution): TfExpr;
5
+ export declare function missingCategoryDiagnostic(name: string): string;
@@ -0,0 +1,12 @@
1
+ import { expr } from "../../engine/tf/index.js";
2
+ const CATEGORY_RESOURCE_TYPE = "elementum_category";
3
+ /** Resource ID when the category is created in this apply; otherwise a live data lookup. */
4
+ export function categoryIdExpr(resolved) {
5
+ return resolved.managed === true
6
+ ? expr.resourceAttr(CATEGORY_RESOURCE_TYPE, resolved.tfLabel, ["id"])
7
+ : expr.dataAttr(CATEGORY_RESOURCE_TYPE, resolved.tfLabel, ["id"]);
8
+ }
9
+ export function missingCategoryDiagnostic(name) {
10
+ return (`category ${JSON.stringify(name)} is not in organization.ts or the org catalog — ` +
11
+ `add it to organization.ts (same apply) or re-run \`elementum pull org --data-only\``);
12
+ }
@@ -1,7 +1,7 @@
1
1
  import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
3
- import { scopedLabelToBagKey } from "../../engine/tf/index.js";
4
- import { fieldKeyFromTfRef } from "../field/from-tf.js";
3
+ import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
+ import { fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { RECORD_CREATE_FORM_RESOURCE_TYPE } from "./module.js";
6
6
  const KNOWN_ATTRS = new Set(["app_id", "sections"]);
7
7
  const KNOWN_SECTION_ATTRS = new Set([
@@ -46,7 +46,7 @@ function sectionFromTf(raw, index, formWhere, owner, ctx) {
46
46
  }
47
47
  const fields = [];
48
48
  for (const fieldId of fieldIds) {
49
- const key = fieldKeyFromTfRef(fieldId, owner.ownerTfLabel, owner.scope);
49
+ const key = fieldKeyFromTfValue(fieldId, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope, ctx);
50
50
  if (key === undefined)
51
51
  ctx.diagnostics.push(`${where}: a field_ids entry is not a known field reference; dropped`);
52
52
  else
@@ -28,6 +28,7 @@ export interface RecordCreateFormToTfOptions {
28
28
  readonly scope: ChildResourceScope;
29
29
  readonly objectId: TfValue;
30
30
  readonly diagnostics: string[];
31
+ readonly fieldAddresses?: ReadonlyMap<string, string>;
31
32
  }
32
33
  /** Typed authoring form -> the provider's immutable sections resource. */
33
34
  export declare function recordCreateFormToTf(form: RecordCreateFormWire | undefined, opts: RecordCreateFormToTfOptions): TfBlock | undefined;
@@ -69,15 +69,23 @@ function resolveFields(refs, where, opts) {
69
69
  opts.diagnostics.push(`${where}: field "${refName}" targets a different aspect; dropped`);
70
70
  continue;
71
71
  }
72
- if (!SUB_TYPE_BY_AUTHORING_TYPE.has(ref.fieldType ?? "")) {
73
- opts.diagnostics.push(`${where}: field "${refName}" has no Terraform field mapping; dropped`);
74
- continue;
75
- }
76
72
  if (!isCanonicalTsLabel(refName)) {
77
73
  opts.diagnostics.push(`${where}: field key "${refName}" is not a canonical tsLabel; dropped`);
78
74
  continue;
79
75
  }
80
- const value = fieldRefToTfValue(ref.fieldType, refName, opts.ownerTfLabel, opts.scope);
76
+ const knownAddress = opts.fieldAddresses?.get(refName);
77
+ if (knownAddress !== undefined) {
78
+ const dotIndex = knownAddress.indexOf(".");
79
+ if (dotIndex !== -1) {
80
+ out.push(expr.resourceAttr(knownAddress.slice(0, dotIndex), knownAddress.slice(dotIndex + 1), ["id"]));
81
+ continue;
82
+ }
83
+ }
84
+ if (!SUB_TYPE_BY_AUTHORING_TYPE.has(ref.fieldType ?? "")) {
85
+ opts.diagnostics.push(`${where}: field "${refName}" has no Terraform field mapping; dropped`);
86
+ continue;
87
+ }
88
+ const value = fieldRefToTfValue(ref.fieldType, refName, opts.ownerTfLabel, opts.scope, opts.fieldAddresses);
81
89
  if (value !== undefined)
82
90
  out.push(value);
83
91
  }
@@ -1,7 +1,7 @@
1
1
  import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { filterFromTf } from "../access-policy/from-tf.js";
4
- import { fieldKeyFromTfRef } from "../field/from-tf.js";
4
+ import { fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
6
6
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
7
7
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
@@ -43,7 +43,7 @@ function relationshipFromTf(block, owner, ctx) {
43
43
  continue;
44
44
  }
45
45
  const rec = raw;
46
- const field = fieldKeyFromTfRef(rec["field_id"], owner.ownerTfLabel, owner.scope);
46
+ const field = fieldKeyFromTfValue(rec["field_id"], owner.ownerRefName, owner.ownerTfLabel, owner.scope, ctx);
47
47
  const relatedField = relatedFieldRef(rec["related_field_id"], target, ctx);
48
48
  if (field === undefined || relatedField === undefined) {
49
49
  ctx.diagnostics.push(`${where}.columns[${index}]: field references are not resolvable; dropped`);
@@ -54,7 +54,14 @@ function relationshipFromTf(block, owner, ctx) {
54
54
  const key = scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", owner.scope);
55
55
  let filter;
56
56
  if (block.attrs["filter"] !== undefined) {
57
- const ownerFilterOwner = { type: ownerResourceType, label: owner.label, ownerRefName: owner.ownerRefName, ownerTfLabel: owner.ownerTfLabel, scope: owner.scope };
57
+ const ownerFilterOwner = {
58
+ type: ownerResourceType,
59
+ label: owner.label,
60
+ ownerRefName: owner.ownerRefName,
61
+ ownerTfLabel: owner.ownerTfLabel,
62
+ scope: owner.scope,
63
+ foreignFieldRefsById: ctx.foreignFieldRefsById,
64
+ };
58
65
  try {
59
66
  // A relationship's filter can reference a field on its own owner
60
67
  // (row-level filtering keyed off the owner's own field - the
@@ -76,6 +83,7 @@ function relationshipFromTf(block, owner, ctx) {
76
83
  ownerRefName: target.key,
77
84
  ownerTfLabel: target.tfLabel ?? target.key,
78
85
  scope: target.kind,
86
+ foreignFieldRefsById: ctx.foreignFieldRefsById,
79
87
  }
80
88
  : undefined;
81
89
  try {
@@ -143,6 +151,9 @@ function relatedFieldRef(value, target, ctx) {
143
151
  if (subType !== undefined) {
144
152
  const scope = target.kind === "element" ? "element" : "app";
145
153
  const ownerLabel = target.tfLabel ?? target.key;
154
+ // value is already narrowed to a TfExpr above, so fieldKeyFromTfValue's
155
+ // string-literal (state-registry) branch can never fire here - a plain
156
+ // fieldKeyFromTfRef is what this branch actually needs.
146
157
  const key = fieldKeyFromTfRef(value, ownerLabel, scope);
147
158
  if (key !== undefined)
148
159
  return { kind: target.kind === "table" ? "tableColumn" : "field", key, name: key, parent: target.key, fieldType: subType.authoringType };
@@ -186,6 +197,6 @@ function relatedFieldRef(value, target, ctx) {
186
197
  return { kind: target.kind === "table" ? "tableColumn" : "field", key: tfLabelToTsLabel(dataLabel), name, parent: target.key, fieldType: "TEXT" };
187
198
  }
188
199
  const scope = target.kind === "element" ? "element" : "app";
189
- const key = fieldKeyFromTfRef(value, target.tfLabel ?? target.key, scope);
200
+ const key = fieldKeyFromTfValue(value, target.key, target.tfLabel ?? target.key, scope, ctx);
190
201
  return key === undefined ? undefined : { kind: target.kind === "table" ? "tableColumn" : "field", key, name: key, parent: target.key, fieldType: "TEXT" };
191
202
  }
@@ -15,10 +15,16 @@ function principal(value, type, where, ctx) {
15
15
  const label = dataRefLabel(value, type);
16
16
  if (label !== undefined) {
17
17
  const name = ctx.dataName(type, label);
18
- if (name !== undefined)
19
- return type === "elementum_user"
20
- ? { __kind: "user", email: name }
21
- : { __kind: "group", refName: tfLabelToTsLabel(label), name };
18
+ if (name !== undefined) {
19
+ if (type === "elementum_user") {
20
+ if (name.trim() === "" || !name.includes("@")) {
21
+ ctx.diagnostics.push(`${where}: data.${type}.${label} has invalid email ${JSON.stringify(name)}; dropped`);
22
+ return undefined;
23
+ }
24
+ return { __kind: "user", email: name.trim() };
25
+ }
26
+ return { __kind: "group", refName: tfLabelToTsLabel(label), name };
27
+ }
22
28
  ctx.diagnostics.push(`${where}: data.${type}.${label} has no lookup value; dropped`);
23
29
  return undefined;
24
30
  }
@@ -42,7 +42,7 @@ export type DefineSearchTableOptions<Owner extends SearchTableOwner = SearchTabl
42
42
  readonly attributeFields: readonly [OwnedField<Owner>, ...OwnedField<Owner>[]];
43
43
  readonly duration: SearchTableDuration;
44
44
  readonly targetLag: number;
45
- readonly textIndexFields?: readonly [OwnedField<Owner>, ...OwnedField<Owner>[]];
45
+ readonly textIndexFields?: readonly OwnedField<Owner>[];
46
46
  readonly vectorIndex: VectorIndex<Owner>;
47
47
  readonly warehouse?: string;
48
48
  readonly creationTimeout?: string;