@elementumai/edk 0.9.17 → 0.9.19

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 (130) hide show
  1. package/README.md +8 -3
  2. package/dist-sdk/src/catalog/factories.d.ts +11 -0
  3. package/dist-sdk/src/catalog/factories.js +6 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +2 -2
  6. package/dist-sdk/src/catalog/org.d.ts +39 -1
  7. package/dist-sdk/src/catalog/org.js +460 -50
  8. package/dist-sdk/src/catalog/types.d.ts +12 -2
  9. package/dist-sdk/src/catalog/types.js +2 -0
  10. package/dist-sdk/src/engine/pull/ref-only.js +54 -20
  11. package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
  12. package/dist-sdk/src/engine/pull/result-output.js +1 -1
  13. package/dist-sdk/src/engine/tf/expr.js +38 -13
  14. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  15. package/dist-sdk/src/engine/tf/index.js +2 -2
  16. package/dist-sdk/src/engine/tf/labels.d.ts +2 -0
  17. package/dist-sdk/src/engine/tf/labels.js +4 -0
  18. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  19. package/dist-sdk/src/engine/tf/parse.js +105 -6
  20. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +11 -4
  25. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -1
  26. package/dist-sdk/src/entities/app/build.d.ts +10 -0
  27. package/dist-sdk/src/entities/app/build.js +0 -13
  28. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
  29. package/dist-sdk/src/entities/app/from-tf.js +4 -3
  30. package/dist-sdk/src/entities/app/index.d.ts +2 -0
  31. package/dist-sdk/src/entities/app/index.js +1 -0
  32. package/dist-sdk/src/entities/app/module.js +13 -0
  33. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  34. package/dist-sdk/src/entities/automation/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/automation/build.js +27 -0
  36. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +6 -0
  37. package/dist-sdk/src/entities/automation/from-tf.js +156 -26
  38. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  39. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  40. package/dist-sdk/src/entities/automation/module.js +56 -0
  41. package/dist-sdk/src/entities/automation/output-field-types.d.ts +5 -4
  42. package/dist-sdk/src/entities/automation/output-field-types.js +23 -5
  43. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  44. package/dist-sdk/src/entities/automation/system-ref-name.js +44 -0
  45. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +15 -0
  46. package/dist-sdk/src/entities/automation/task-output-labels.js +38 -0
  47. package/dist-sdk/src/entities/automation/tasks.d.ts +37 -5
  48. package/dist-sdk/src/entities/automation/tasks.js +23 -1
  49. package/dist-sdk/src/entities/automation/to-tf.js +158 -84
  50. package/dist-sdk/src/entities/automation/types.js +1 -0
  51. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  52. package/dist-sdk/src/entities/chart/module.js +3 -1
  53. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  54. package/dist-sdk/src/entities/chart/printer.js +26 -16
  55. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  56. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  57. package/dist-sdk/src/entities/chart/to-tf.js +12 -10
  58. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  59. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  60. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  61. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  62. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  63. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +51 -2
  64. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  65. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  67. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  68. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  69. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  70. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  71. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  72. package/dist-sdk/src/entities/element/build.js +1 -0
  73. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  74. package/dist-sdk/src/entities/element/from-tf.js +6 -2
  75. package/dist-sdk/src/entities/element/index.d.ts +1 -0
  76. package/dist-sdk/src/entities/element/index.js +1 -0
  77. package/dist-sdk/src/entities/element/module.js +2 -0
  78. package/dist-sdk/src/entities/element/to-tf.js +12 -0
  79. package/dist-sdk/src/entities/field/from-tf.d.ts +2 -0
  80. package/dist-sdk/src/entities/field/from-tf.js +11 -0
  81. package/dist-sdk/src/entities/field/to-tf.js +13 -9
  82. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  83. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  84. package/dist-sdk/src/entities/relationship/to-tf.d.ts +8 -0
  85. package/dist-sdk/src/entities/relationship/to-tf.js +19 -10
  86. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -2
  87. package/dist-sdk/src/entities/shared/filters/index.d.ts +23 -2
  88. package/dist-sdk/src/entities/shared/filters/index.js +24 -1
  89. package/dist-sdk/src/entities/shared/filters/print.js +22 -4
  90. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +23 -3
  91. package/dist-sdk/src/entities/shared/filters/tf-codec.js +60 -18
  92. package/dist-sdk/src/entities/shared/filters/types.d.ts +13 -4
  93. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  94. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  95. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  96. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  97. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  98. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  99. package/dist-sdk/src/entities/skill/build.js +3 -0
  100. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  101. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +21 -0
  102. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  103. package/dist-sdk/src/entities/skill/from-tf.js +4 -9
  104. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  105. package/dist-sdk/src/entities/skill/index.js +1 -0
  106. package/dist-sdk/src/entities/skill/module.js +1 -0
  107. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  108. package/dist-sdk/src/entities/skill/to-tf.js +5 -2
  109. package/dist-sdk/src/entities/skill-tool/to-tf.js +2 -1
  110. package/dist-sdk/src/entities/table/to-tf.js +3 -3
  111. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -0
  112. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +224 -0
  113. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +36 -0
  114. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +288 -0
  115. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +121 -0
  116. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  117. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -1
  118. package/dist-sdk/src/entities/view/from-tf.js +42 -7
  119. package/dist-sdk/src/entities/view/ragnarok.d.ts +7 -0
  120. package/dist-sdk/src/entities/view/ragnarok.js +1 -0
  121. package/dist-sdk/src/entities/view/to-tf.d.ts +10 -1
  122. package/dist-sdk/src/entities/view/to-tf.js +30 -1
  123. package/dist-sdk/src/entities/view/types.js +2 -0
  124. package/dist-sdk/src/entities/widget/to-tf.js +2 -2
  125. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +815 -0
  126. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +5 -0
  127. package/dist-sdk/src/graph/index.d.ts +43 -0
  128. package/dist-sdk/src/graph/index.js +9 -0
  129. package/dist-sdk/src/graph/types.d.ts +78 -0
  130. package/package.json +11 -1
@@ -1,22 +1,29 @@
1
1
  import { workspaceAspectKey } from "../../engine/build/context.js";
2
2
  import { resolveForeignRef } from "../shared/foreign-ref.js";
3
- import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
+ import { expr, isCanonicalTsLabel, isTfExpr, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
+ import { filterToTf } from "../access-policy/to-tf.js";
5
+ import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE } from "../automation/types.js";
4
6
  import { fieldRefToTfValue } from "../field/to-tf.js";
7
+ import { targetFilterFieldResolver } from "../relationship/to-tf.js";
8
+ import { filterTfToWire } from "../shared/filters/tf-codec.js";
9
+ import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
5
10
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
6
11
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
7
12
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
8
- import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS, dynamicLayoutActionWidgetName, dynamicLayoutFieldComponentWireKey, } from "./dialect.js";
13
+ import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS, dynamicLayoutActionWidgetName, dynamicLayoutCompanionWidgetLabel, dynamicLayoutFieldComponentWireKey, } from "./dialect.js";
9
14
  export function dynamicLayoutsToTf(layouts, opts) {
10
15
  const blocks = [];
11
- for (const [key, layout] of Object.entries(layouts ?? {})) {
16
+ for (const [key, authored] of Object.entries(layouts ?? {})) {
12
17
  const where = `dynamicLayouts.${key}`;
13
18
  if (!isCanonicalTsLabel(key)) {
14
19
  opts.diagnostics.push(`${where}: key is not a canonical tsLabel; dropped`);
15
20
  continue;
16
21
  }
17
- const componentResult = componentMap(layout.components ?? {}, key, where, opts);
22
+ const layout = scopeOf(opts) === "element" ? withoutStageConditions(authored, where, opts.diagnostics) : authored;
23
+ const layoutLabel = scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), scopeOf(opts));
24
+ const componentResult = componentMap(layout.components ?? {}, key, layoutLabel, where, opts);
18
25
  const attrs = {
19
- app_id: opts.objectId,
26
+ [scopeOf(opts) === "element" ? "element_id" : "app_id"]: opts.objectId,
20
27
  name: layout.name ?? "",
21
28
  active: layout.active ?? true,
22
29
  document_id: layout.documentId ?? "",
@@ -26,10 +33,11 @@ export function dynamicLayoutsToTf(layouts, opts) {
26
33
  };
27
34
  if (layout.description !== undefined)
28
35
  attrs["description"] = layout.description;
29
- if (layout.stage !== undefined) {
30
- attrs["stage_id"] = expr.resourceAttr("elementum_app", opts.ownerTfLabel, [
31
- "stage_ids_by_key", { index: tsLabelToTfLabel(layout.stage) },
32
- ]);
36
+ if (layout.stage !== undefined && scopeOf(opts) === "element") {
37
+ opts.diagnostics.push(`${where}.stage: elements have no stages; omit stage for the element's default DASHBOARD layout; dropped`);
38
+ }
39
+ else if (layout.stage !== undefined) {
40
+ attrs["stage_id"] = expr.local(`${opts.ownerTfLabel}_stage_ids_by_key`, [{ index: tsLabelToTfLabel(layout.stage) }]);
33
41
  }
34
42
  if (layout.conditions !== undefined)
35
43
  attrs["conditions"] = conditionMap(layout.conditions, where, opts);
@@ -46,19 +54,112 @@ export function dynamicLayoutsToTf(layouts, opts) {
46
54
  blocks.push({
47
55
  kind: "resource",
48
56
  type: DYNAMIC_LAYOUT_RESOURCE_TYPE,
49
- label: scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), "app"),
57
+ label: layoutLabel,
50
58
  attrs,
51
59
  });
52
- blocks.push(...componentResult.companionWidgets);
60
+ blocks.push(...componentResult.companionWidgets, ...componentResult.automationLookups.values());
53
61
  }
54
62
  return blocks;
55
63
  }
64
+ function scopeOf(opts) {
65
+ return opts.scope ?? "app";
66
+ }
67
+ const COMPONENT_CONDITION_LIST_KEYS = ["showWhen", "hideWhen", "enableWhen", "disableWhen", "requireWhen"];
68
+ /**
69
+ * Elements have no stages. Strip stage predicates, then remove every condition
70
+ * left without a variant (including `all`/`any`/`not` that only pointed at
71
+ * removed ones) and every reference to it; the provider rejects an empty
72
+ * condition and a dangling condition id.
73
+ */
74
+ function withoutStageConditions(layout, where, diagnostics) {
75
+ if (layout.conditions === undefined)
76
+ return layout;
77
+ const conditions = new Map();
78
+ for (const [id, condition] of Object.entries(layout.conditions)) {
79
+ if (condition["stage"] === undefined) {
80
+ conditions.set(id, condition);
81
+ continue;
82
+ }
83
+ diagnostics.push(`${where}.conditions.${id}.stage: elements have no stages; dropped`);
84
+ const { stage: _stage, ...rest } = condition;
85
+ conditions.set(id, rest);
86
+ }
87
+ const removed = new Set();
88
+ for (let changed = true; changed;) {
89
+ changed = false;
90
+ for (const [id, condition] of conditions) {
91
+ const pruned = pruneConditionRefs(condition, removed);
92
+ if (pruned === undefined) {
93
+ conditions.delete(id);
94
+ removed.add(id);
95
+ changed = true;
96
+ }
97
+ else {
98
+ conditions.set(id, pruned);
99
+ }
100
+ }
101
+ }
102
+ if (removed.size === 0)
103
+ return { ...layout, conditions: Object.fromEntries(conditions) };
104
+ for (const id of removed) {
105
+ diagnostics.push(`${where}.conditions.${id}: no predicate left on an element; condition and its references removed`);
106
+ }
107
+ const components = {};
108
+ for (const [componentId, component] of Object.entries(layout.components ?? {})) {
109
+ const next = { ...component };
110
+ for (const listKey of COMPONENT_CONDITION_LIST_KEYS) {
111
+ const ids = next[listKey];
112
+ if (!Array.isArray(ids))
113
+ continue;
114
+ const kept = ids.filter((id) => !removed.has(id));
115
+ if (kept.length === 0)
116
+ delete next[listKey];
117
+ else
118
+ next[listKey] = kept;
119
+ }
120
+ components[componentId] = next;
121
+ }
122
+ return {
123
+ ...layout,
124
+ components,
125
+ conditions: Object.fromEntries(conditions),
126
+ ...(layout.dependencies === undefined ? {} : {
127
+ dependencies: layout.dependencies.map((dependency) => {
128
+ if (!removed.has(dependency["condition"]))
129
+ return dependency;
130
+ const { condition: _condition, ...rest } = dependency;
131
+ return rest;
132
+ }),
133
+ }),
134
+ };
135
+ }
136
+ function pruneConditionRefs(condition, removed) {
137
+ const out = {};
138
+ for (const [key, value] of Object.entries(condition)) {
139
+ if (value === undefined)
140
+ continue;
141
+ if (key === "all" || key === "any") {
142
+ const ids = (object(value)["conditions"] ?? []).filter((id) => !removed.has(id));
143
+ if (ids.length > 0)
144
+ out[key] = { ...object(value), conditions: ids };
145
+ }
146
+ else if (key === "not") {
147
+ if (!removed.has(object(value)["condition"]))
148
+ out[key] = value;
149
+ }
150
+ else {
151
+ out[key] = value;
152
+ }
153
+ }
154
+ return Object.keys(out).length === 0 ? undefined : out;
155
+ }
56
156
  function companionWidgetLabel(layoutKey, componentId, opts) {
57
- return scopedResourceLabel(opts.ownerTfLabel, sanitizeName(dynamicLayoutActionWidgetName(layoutKey, componentId)), "app");
157
+ return dynamicLayoutCompanionWidgetLabel(opts.ownerTfLabel, layoutKey, componentId, scopeOf(opts));
58
158
  }
59
- function componentMap(components, layoutKey, where, opts) {
159
+ function componentMap(components, layoutKey, layoutLabel, where, opts) {
60
160
  const out = {};
61
161
  const companionWidgets = [];
162
+ const automationLookups = new Map();
62
163
  for (const [componentId, component] of Object.entries(components)) {
63
164
  const attrs = {};
64
165
  for (const [key, value] of Object.entries(component)) {
@@ -75,7 +176,10 @@ function componentMap(components, layoutKey, where, opts) {
75
176
  const rec = object(value);
76
177
  const section = snakeObject(rec, where, opts);
77
178
  delete section["agent"];
78
- if (rec["agent"] !== undefined) {
179
+ if (rec["agent"] !== undefined && scopeOf(opts) === "element") {
180
+ opts.diagnostics.push(`${where}.components.${componentId}.section.agent: agents belong to apps; elements cannot bind one; dropped`);
181
+ }
182
+ else if (rec["agent"] !== undefined) {
79
183
  const agent = resolveAgent(rec["agent"], `${where}.components.${componentId}.section`, opts);
80
184
  if (agent !== undefined)
81
185
  section["agent_id"] = agent;
@@ -99,9 +203,31 @@ function componentMap(components, layoutKey, where, opts) {
99
203
  const rec = object(value);
100
204
  const button = snakeObject(rec, where, opts);
101
205
  delete button["automation"];
206
+ delete button["automation_app"];
207
+ if (rec["automationApp"] !== undefined) {
208
+ const app = resolveAspect(rec["automationApp"], `${where}.components.${componentId}.automationButton.automationApp`, opts);
209
+ if (app !== undefined)
210
+ button["automation_app_id"] = app;
211
+ }
102
212
  const token = rec["automation"];
103
213
  const automation = resolveAutomation(token, `${where}.components.${componentId}.automationButton`, opts);
104
- if (automation !== undefined) {
214
+ if (Array.isArray(rec["inputs"])) {
215
+ const inputs = {
216
+ buttonAutomation: token === undefined ? undefined : { token, value: automation },
217
+ layoutLabel,
218
+ automationLookups,
219
+ };
220
+ button["inputs"] = rec["inputs"].flatMap((input, index) => automationButtonInput(object(input), inputs, `${where}.components.${componentId}.automationButton.inputs[${index}]`, opts));
221
+ }
222
+ delete button["widget"];
223
+ const widget = rec["widget"] === undefined
224
+ ? undefined
225
+ : resolveWidget(rec["widget"], `${where}.components.${componentId}.automationButton.widget`, opts);
226
+ if (automation !== undefined && widget !== undefined) {
227
+ button["automation_id"] = automation;
228
+ button["widget_id"] = widget;
229
+ }
230
+ else if (automation !== undefined) {
105
231
  button["automation_id"] = automation;
106
232
  // The renderer executes the automation through a widget, not the
107
233
  // automation id; without this binding it reports the button as not
@@ -132,13 +258,74 @@ function componentMap(components, layoutKey, where, opts) {
132
258
  button["target_aspect_id"] = target;
133
259
  attrs["create_button"] = button;
134
260
  }
261
+ else if (key === "relatedItemsBlock") {
262
+ attrs["related_items_block"] = relatedItemsBlock(object(value), `${where}.components.${componentId}.relatedItemsBlock`, opts);
263
+ }
135
264
  else {
136
265
  attrs[snakeKey(key)] = snakeValue(value, where, opts);
137
266
  }
138
267
  }
139
268
  out[componentId] = attrs;
140
269
  }
141
- return { components: out, companionWidgets };
270
+ return { components: out, companionWidgets, automationLookups };
271
+ }
272
+ function automationButtonInput(rec, inputs, where, opts) {
273
+ const out = snakeObject(rec, where, opts);
274
+ delete out["automation"];
275
+ if (out["parameter_id"] === undefined) {
276
+ const target = rec["automation"] === undefined
277
+ ? inputs.buttonAutomation
278
+ : {
279
+ token: rec["automation"],
280
+ value: resolveAutomation(rec["automation"], `${where}.automation`, opts),
281
+ };
282
+ const label = target?.value !== undefined && isTfExpr(target.value) && target.value.$expr === "resource-attr"
283
+ ? target.value.label
284
+ : undefined;
285
+ const name = rec["parameterName"];
286
+ if (label === undefined || typeof name !== "string") {
287
+ opts.diagnostics.push(`${where}: parameterName needs a managed button automation to bind to; dropped`);
288
+ return [];
289
+ }
290
+ out["parameter_id"] = isActiveAutomation(target?.token.refName ?? "", opts)
291
+ ? expr.dataAttr(AUTOMATION_RESOURCE_TYPE, publishedAutomationLookup(label, inputs, opts), ["parameter_ids", { index: name }])
292
+ : expr.resourceAttr("elementum_on_demand_trigger", label, ["parameter_ids", { index: name }]);
293
+ }
294
+ if (Array.isArray(rec["fieldRefParams"])) {
295
+ out["field_ref_params"] = rec["fieldRefParams"].flatMap((param, index) => {
296
+ const entry = object(param);
297
+ const field = resolveField(entry["field"], `${where}.fieldRefParams[${index}]`, opts);
298
+ return field === undefined ? [] : [{ name: entry["name"], field_id: field }];
299
+ });
300
+ }
301
+ return [out];
302
+ }
303
+ function relatedItemsBlock(rec, where, opts) {
304
+ const out = snakeObject(rec, where, opts);
305
+ delete out["related"];
306
+ delete out["filter"];
307
+ const related = rec["related"];
308
+ if (related !== undefined) {
309
+ const aspect = resolveAspect(related, `${where}.related`, opts);
310
+ if (aspect !== undefined)
311
+ out["related_aspect_id"] = aspect;
312
+ }
313
+ if (rec["filter"] !== undefined) {
314
+ const foreignField = related === undefined
315
+ ? undefined
316
+ : targetFilterFieldResolver(related, `${where}.related`, { ...opts, scope: scopeOf(opts) });
317
+ const hclFilter = filterToTf(rec["filter"], `${where}.filter`, {
318
+ ownerTfLabel: opts.ownerTfLabel,
319
+ appRefName: opts.ownerRefName,
320
+ scope: scopeOf(opts),
321
+ objectId: opts.objectId,
322
+ diagnostics: opts.diagnostics,
323
+ orgRefs: opts.orgRefs,
324
+ ...(foreignField !== undefined && { foreignField }),
325
+ });
326
+ out["filter"] = expr.jsonencode(filterTfToWire(hclFilter));
327
+ }
328
+ return out;
142
329
  }
143
330
  function fieldComponent(value, where, opts) {
144
331
  const rec = object(value);
@@ -170,7 +357,7 @@ function conditionMap(conditions, where, opts) {
170
357
  const stage = object(value)["stage"];
171
358
  if (typeof stage === "string") {
172
359
  attrs["stage"] = {
173
- stage_id: expr.resourceAttr("elementum_app", opts.ownerTfLabel, ["stage_ids_by_key", { index: tsLabelToTfLabel(stage) }]),
360
+ stage_id: expr.local(`${opts.ownerTfLabel}_stage_ids_by_key`, [{ index: tsLabelToTfLabel(stage) }]),
174
361
  };
175
362
  }
176
363
  }
@@ -223,6 +410,10 @@ function resolveFields(values, where, opts) {
223
410
  }
224
411
  function resolveField(value, where, opts) {
225
412
  if (typeof value === "string") {
413
+ if (scopeOf(opts) === "element" && !ELEMENT_SYSTEM_FIELD_KEYS.includes(value)) {
414
+ opts.diagnostics.push(`${where}: "${value}" is not a known system field key on an element; dropped`);
415
+ return undefined;
416
+ }
226
417
  const attr = SYSTEM_FIELD_ID_ATTR_BY_KEY.get(value);
227
418
  if (attr === undefined)
228
419
  opts.diagnostics.push(`${where}: "${value}" is not a known system field key; dropped`);
@@ -231,10 +422,10 @@ function resolveField(value, where, opts) {
231
422
  const token = value;
232
423
  const refName = token?.refName ?? "";
233
424
  if (token?.parent !== undefined && token.parent !== opts.ownerRefName) {
234
- opts.diagnostics.push(`${where}: field "${refName}" targets a different app; dropped`);
425
+ opts.diagnostics.push(`${where}: field "${refName}" targets a different ${scopeOf(opts)}; dropped`);
235
426
  return undefined;
236
427
  }
237
- const resolved = fieldRefToTfValue(token?.fieldType ?? "", refName, opts.ownerTfLabel, "app", opts.fieldAddresses);
428
+ const resolved = fieldRefToTfValue(token?.fieldType ?? "", refName, opts.ownerTfLabel, scopeOf(opts), opts.fieldAddresses);
238
429
  if (resolved === undefined)
239
430
  opts.diagnostics.push(`${where}: field "${refName}" has no Terraform mapping; dropped`);
240
431
  return resolved;
@@ -247,7 +438,7 @@ function typedValue(value, fieldValue, opts) {
247
438
  ? `${opts.ownerTfLabel}_status_options_by_label`
248
439
  : token.tags?.includes("STAGE")
249
440
  ? `${opts.ownerTfLabel}_stage_options_by_label`
250
- : `${scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(token.refName ?? ""), "app")}_options_by_label`;
441
+ : `${scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(token.refName ?? ""), scopeOf(opts))}_options_by_label`;
251
442
  return { string: expr.local(localName, [{ index: rec["string"] }]) };
252
443
  }
253
444
  return snakeObject(rec, "dynamic layout typed value", opts);
@@ -255,7 +446,7 @@ function typedValue(value, fieldValue, opts) {
255
446
  function resolveAutomation(token, where, opts) {
256
447
  const refName = token?.refName ?? "";
257
448
  if (token?.parent !== undefined && token.parent !== opts.ownerRefName) {
258
- opts.diagnostics.push(`${where}: cross-app automations are not supported; dropped`);
449
+ opts.diagnostics.push(`${where}: cross-${scopeOf(opts)} automations are not supported; dropped`);
259
450
  return undefined;
260
451
  }
261
452
  if (!isCanonicalTsLabel(refName)) {
@@ -264,10 +455,50 @@ function resolveAutomation(token, where, opts) {
264
455
  }
265
456
  return expr.resourceAttr("elementum_automation", scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), "app"), ["id"]);
266
457
  }
458
+ function isActiveAutomation(refName, opts) {
459
+ return opts.workspaceAspects?.get(workspaceAspectKey(scopeOf(opts), opts.ownerRefName))
460
+ ?.activeAutomationRefNames?.has(refName) === true;
461
+ }
462
+ /**
463
+ * The on-demand trigger's `parameter_ids` describe the draft workflow, but a
464
+ * button runs the published one, whose parameter ids differ. Read them back
465
+ * after publish, as run-automation tasks do. The data address is
466
+ * module-global, so it is scoped to this layout.
467
+ */
468
+ function publishedAutomationLookup(automationLabel, inputs, opts) {
469
+ const label = `${automationLabel}_for_${inputs.layoutLabel}`;
470
+ inputs.automationLookups.set(`${AUTOMATION_RESOURCE_TYPE}.${label}`, {
471
+ kind: "data",
472
+ type: AUTOMATION_RESOURCE_TYPE,
473
+ label,
474
+ attrs: {
475
+ app_id: opts.objectId,
476
+ id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, automationLabel, ["id"]),
477
+ depends_on: [expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, automationLabel)],
478
+ },
479
+ });
480
+ return label;
481
+ }
482
+ function resolveWidget(token, where, opts) {
483
+ const key = token.refName ?? "";
484
+ if (token.__kind !== "widget" || key === "") {
485
+ opts.diagnostics.push(`${where}: expected a typed widget reference; dropped`);
486
+ return undefined;
487
+ }
488
+ if (token.parent !== undefined && token.parent !== opts.ownerRefName) {
489
+ opts.diagnostics.push(`${where}: widget belongs to ${JSON.stringify(token.parent)}, not ${JSON.stringify(opts.ownerRefName)}; dropped`);
490
+ return undefined;
491
+ }
492
+ if (opts.widgetKeys !== undefined && !opts.widgetKeys.has(key)) {
493
+ opts.diagnostics.push(`${where}: widget ${JSON.stringify(key)} is not declared in this ${scopeOf(opts)}; dropped`);
494
+ return undefined;
495
+ }
496
+ return expr.resourceAttr(WIDGET_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), scopeOf(opts)), ["id"]);
497
+ }
267
498
  function resolveAgent(token, where, opts) {
268
499
  const refName = token?.refName ?? "";
269
500
  if (token?.parent !== undefined && token.parent !== opts.ownerRefName) {
270
- opts.diagnostics.push(`${where}: agent targets a different app; dropped`);
501
+ opts.diagnostics.push(`${where}: agent targets a different ${scopeOf(opts)}; dropped`);
271
502
  return undefined;
272
503
  }
273
504
  if (!isCanonicalTsLabel(refName)) {
@@ -279,7 +510,7 @@ function resolveAgent(token, where, opts) {
279
510
  function resolveAspect(token, where, opts) {
280
511
  const kind = token?.__kind === "element" ? "element" : "app";
281
512
  const refName = token?.refName ?? "";
282
- if (kind === "app" && refName === opts.ownerRefName)
513
+ if (kind === scopeOf(opts) && refName === opts.ownerRefName)
283
514
  return opts.objectId;
284
515
  const sibling = opts.workspaceAspects?.get(workspaceAspectKey(kind, refName));
285
516
  if (sibling !== undefined) {
@@ -1,6 +1,7 @@
1
1
  import { type AppOrElementRef, type CloudLinkRef, type FieldRef } from "../../catalog/index.js";
2
2
  import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
3
3
  import type { AccessPolicyOptions } from "../access-policy/build.js";
4
+ import type { ElementDynamicLayout } from "../dynamic-layout/build.js";
4
5
  import { type AppCalendarView, type AppCategory, type AppCloudOptions, type AppDashboard, type AppDashboardView, type AppField, type AppFieldRefs, type AppKanbanView, type AppLayout, type AppListView, type AppRecordCreateForm, type AppSystemFieldOverride } from "../app/build.js";
5
6
  import { type DisplayBlock } from "../app/display-blocks.js";
6
7
  import type { AppRelationship } from "../relationship/build.js";
@@ -98,6 +99,13 @@ export interface ElementV2Options<F extends Record<string, AppField> = Record<st
98
99
  * terraform address on a re-pull.
99
100
  */
100
101
  readonly layouts?: Readonly<Record<string, AppLayout>>;
102
+ /**
103
+ * Typed DASHBOARD record layouts (`elementum_dynamic_layout`) keyed by
104
+ * stable ref name. Elements have no stages, so each is an element-level
105
+ * default layout; build with `dynamicLayout(...)` to check component,
106
+ * condition, and save-group keys.
107
+ */
108
+ readonly dynamicLayouts?: Readonly<Record<string, ElementDynamicLayout>>;
101
109
  /** Saved list views, keyed by view ref name. */
102
110
  readonly listViews?: Readonly<Record<string, AppListView>>;
103
111
  /** Calendar views, keyed by stable view ref name. */
@@ -138,6 +138,7 @@ export function element(opts) {
138
138
  ...(opts.widgets !== undefined ? { widgets: opts.widgets } : {}),
139
139
  ...(opts.dashboardViews !== undefined ? { dashboardViews: opts.dashboardViews } : {}),
140
140
  ...(opts.recordCreateForm !== undefined ? { recordCreateForm: opts.recordCreateForm } : {}),
141
+ ...(opts.dynamicLayouts !== undefined ? { dynamicLayouts: opts.dynamicLayouts } : {}),
141
142
  ...(opts.relationships !== undefined ? { relationships: opts.relationships } : {}),
142
143
  ...(opts.viewOrder !== undefined ? { viewOrder: opts.viewOrder } : {}),
143
144
  ...(opts.accessPolicies !== undefined ? { accessPolicies: opts.accessPolicies } : {}),
@@ -19,6 +19,7 @@ export interface ElementFromTfViewBlocks {
19
19
  readonly dashboardViewBlocks: readonly TfBlock[];
20
20
  readonly managedViewOrderBlocks: readonly TfBlock[];
21
21
  readonly recordCreateFormBlocks: readonly TfBlock[];
22
+ readonly dynamicLayoutBlocks?: readonly TfBlock[];
22
23
  readonly relationshipBlocks: readonly TfBlock[];
23
24
  readonly dashboardBlocks: readonly TfBlock[];
24
25
  readonly dashboardWidgetBlocks: readonly TfBlock[];
@@ -9,6 +9,7 @@ import { dataRefLabel, optionalBoolean, optionalString } from "../../engine/pull
9
9
  import { tfLabelToTsLabel } from "../../engine/tf/index.js";
10
10
  import { accessPolicyFromTf } from "../access-policy/from-tf.js";
11
11
  import { dashboardsFromTf } from "../dashboard/from-tf.js";
12
+ import { dynamicLayoutCompanionWidgetLabels, dynamicLayoutsFromTf } from "../dynamic-layout/from-tf.js";
12
13
  import { fieldFromTf } from "../field/from-tf.js";
13
14
  import { recordCreateFormFromTf } from "../record-create-form/from-tf.js";
14
15
  import { relationshipsFromTf } from "../relationship/from-tf.js";
@@ -134,7 +135,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
134
135
  if (idName !== undefined || idFieldDescription !== undefined) {
135
136
  fields.push(systemEntry("id", idName ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.id, "TEXT", "HANDLE", idFieldDescription));
136
137
  }
137
- const owner = { type: ELEMENT_RESOURCE_TYPE, label, scope: "element" };
138
+ const owner = { type: ELEMENT_RESOURCE_TYPE, label, scope: "element", refName };
138
139
  for (const block of fieldBlocks) {
139
140
  const entry = fieldFromTf(block, owner, ctx);
140
141
  if (entry !== undefined)
@@ -151,7 +152,9 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
151
152
  }
152
153
  const recordCreateForm = recordCreateFormFromTf(viewBlocks.recordCreateFormBlocks[0], { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: refName, scope: "element" }, ctx);
153
154
  const relationships = relationshipsFromTf(viewBlocks.relationshipBlocks, { kind: "element", label, ownerRefName: refName, ownerTfLabel: refName, scope: "element" }, ctx);
154
- const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }, ctx);
155
+ const dynamicLayoutBlocks = viewBlocks.dynamicLayoutBlocks ?? [];
156
+ const dynamicLayouts = dynamicLayoutsFromTf(dynamicLayoutBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }, ctx);
157
+ const widgets = widgetsFromTf(viewBlocks.widgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }, ctx, dynamicLayoutCompanionWidgetLabels(dynamicLayoutBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerRefName: refName, ownerTfLabel: label, scope: "element" }));
155
158
  const accessPolicyOwner = {
156
159
  type: ELEMENT_RESOURCE_TYPE,
157
160
  label,
@@ -191,6 +194,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
191
194
  ...(dashboards.length > 0 && { dashboards }),
192
195
  ...(widgets.length > 0 && { widgets }),
193
196
  ...(recordCreateForm !== undefined && { recordCreateForm }),
197
+ ...(dynamicLayouts.length > 0 && { dynamicLayouts }),
194
198
  ...(relationships.length > 0 && { relationships }),
195
199
  ...(viewOrder !== undefined && { viewOrder }),
196
200
  ...(accessPolicies.length > 0 && { accessPolicies }),
@@ -9,6 +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 { type DynamicLayoutComponent, type DynamicLayoutCondition, type DynamicLayoutCssLength, type DynamicLayoutDependency, type DynamicLayoutFieldComponent, type DynamicLayoutFieldValidation, type DynamicLayoutSaveGroup, type DynamicLayoutStyle, type DynamicLayoutTypedValue, type DynamicLayoutValidationRule, type ElementDynamicLayout, dynamicLayout, } from "../dynamic-layout/build.js";
12
13
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, type DashboardChartWidget, type DashboardRecordsWidget, type DashboardWidget, type DashboardWidgetSize, } from "../dashboard/build.js";
13
14
  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
15
  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";
@@ -7,6 +7,7 @@
7
7
  */
8
8
  export { element, } from "./build.js";
9
9
  export { listViewDensity, managedViewSortAggregation, managedViewSortDirection, } from "../view/build.js";
10
+ export { dynamicLayout, } from "../dynamic-layout/build.js";
10
11
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, } from "../dashboard/build.js";
11
12
  export { attachmentField, booleanField, calculatedField, dateField, dateTimeField, decimalField, dropdownDisplay, dropdownField, dropdownOption, dropdownValue, groupField, jsonField, multiSelectField, numberField, relationField, richTextField, textField, userField, } from "../field/build.js";
12
13
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, } from "../field/calc.js";
@@ -25,6 +25,7 @@ function extractElementStreamRoot(stream, ctx) {
25
25
  const dashboardViewBlocks = viewBlocks.filter((b) => b.type === DASHBOARD_VIEW_RESOURCE_TYPE);
26
26
  const managedViewOrderBlocks = stream.byKind.get("managed-view-order") ?? [];
27
27
  const recordCreateFormBlocks = stream.byKind.get("record-create-form") ?? [];
28
+ const dynamicLayoutBlocks = stream.byKind.get("dynamic-layout") ?? [];
28
29
  const relationshipBlocks = stream.byKind.get("relationship") ?? [];
29
30
  const dashboardBlocks = stream.byKind.get("dashboard") ?? [];
30
31
  const dashboardWidgetBlocks = stream.byKind.get("dashboard-widget") ?? [];
@@ -39,6 +40,7 @@ function extractElementStreamRoot(stream, ctx) {
39
40
  dashboardViewBlocks,
40
41
  managedViewOrderBlocks,
41
42
  recordCreateFormBlocks,
43
+ dynamicLayoutBlocks,
42
44
  relationshipBlocks,
43
45
  dashboardBlocks,
44
46
  dashboardWidgetBlocks,
@@ -11,6 +11,7 @@ import { displayBlocksToLayoutSections } from "../app/display-blocks-to-layout.j
11
11
  import { APP_RESOURCE_TYPE } from "../app/module.js";
12
12
  import { displayBlocksToRecordCreateFormSections } from "../app/display-blocks-to-record-create-form.js";
13
13
  import { dashboardsToTf } from "../dashboard/to-tf.js";
14
+ import { dynamicLayoutsToTf } from "../dynamic-layout/to-tf.js";
14
15
  import { fieldMetadataFromEntries } from "../field/metadata.js";
15
16
  import { fieldToTf } from "../field/to-tf.js";
16
17
  import { CATEGORY_ORG_BAG } from "../org/category.js";
@@ -245,6 +246,17 @@ export function elementToTf(entity, ctx) {
245
246
  });
246
247
  if (recordCreateForm !== undefined)
247
248
  blocks.push(recordCreateForm);
249
+ blocks.push(...dynamicLayoutsToTf(payload.dynamicLayouts, {
250
+ ownerRefName: ctx.appRefName,
251
+ ownerTfLabel: ctx.appTfLabel,
252
+ scope: "element",
253
+ objectId,
254
+ diagnostics: ctx.diagnostics,
255
+ orgRefs: ctx.orgRefs,
256
+ workspaceAspects: ctx.workspaceAspects,
257
+ fieldAddresses,
258
+ widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
259
+ }));
248
260
  blocks.push(...relationshipsToTf(payload.relationships, {
249
261
  ownerRefName: ctx.appRefName,
250
262
  ownerTfLabel: ctx.appTfLabel,
@@ -15,6 +15,8 @@ export interface FieldOwner {
15
15
  readonly label: string;
16
16
  /** Scope for stripping child label prefixes (defaults to app). */
17
17
  readonly scope?: ChildResourceScope;
18
+ /** The owner's catalog refName — the `appHandle` of same-owner field RefExprs. */
19
+ readonly refName?: string;
18
20
  }
19
21
  /**
20
22
  * One field block → its normalized entry; undefined = skipped with a
@@ -152,6 +152,16 @@ function dynamicPicklistFilterFieldRef(value, ctx) {
152
152
  }
153
153
  throw new EntityTfError("dynamic picklist filter field reference cannot be reconstructed");
154
154
  }
155
+ /** A `record_field` value names a field on the Dropdown's own record, not the source. */
156
+ function dynamicPicklistRecordFieldRef(value, owner, ctx) {
157
+ if (owner.refName === undefined)
158
+ throw new EntityTfError("record_field filter value requires a known owning app or element");
159
+ const scope = owner.scope ?? "app";
160
+ const fieldKey = fieldKeyFromTfRef(value, owner.label, scope) ?? fieldKeyFromTfValue(value, owner.refName, owner.label, scope, ctx);
161
+ if (fieldKey === undefined)
162
+ throw new EntityTfError("record_field filter value field is not a field on the owning record");
163
+ return { kind: "field", appHandle: owner.refName, fieldKey };
164
+ }
155
165
  /**
156
166
  * `dynamic_config` → `AppField.config` (picklist/multiPicklist only). Mirrors
157
167
  * `related_object_id`/`related_label_field_id` resolution exactly (both are
@@ -193,6 +203,7 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
193
203
  try {
194
204
  filter = deserializeFilterFromTf(attrs["filter"], {
195
205
  field: (v) => dynamicPicklistFilterFieldRef(v, ctx),
206
+ recordField: (v) => dynamicPicklistRecordFieldRef(v, owner, ctx),
196
207
  reference: () => {
197
208
  throw new EntityTfError("dynamic picklist filter does not support value references");
198
209
  },
@@ -14,6 +14,7 @@ import { workspaceAspectKey } from "../../engine/build/context.js";
14
14
  import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
15
15
  import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
16
16
  import { filterToTf as filterWireToTfCodec } from "../shared/filters/tf-codec.js";
17
+ import { foreignFieldDataLabel } from "../shared/foreign-ref.js";
17
18
  import { picklistLabel } from "./options.js";
18
19
  import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
19
20
  /** `unknown` → the tagged org-field-ref shape, or undefined for anything else. */
@@ -178,16 +179,10 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
178
179
  return undefined;
179
180
  }
180
181
  const name = token.name ?? refName;
181
- // Match ei export and every other object-scoped field lookup: the label is
182
- // based on the provider root type + the ACTUAL root lookup label + field
183
- // display name. Re-deriving it from the public refName produces a second,
184
- // semantically identical data block when (for example) a relationship and
185
- // a dynamic Dropdown both reference the same foreign field.
186
- const ownerType = object.kind === "element" ? "elementum_element" : object.kind === "app" ? "elementum_app" : object.kind === "task" ? "elementum_task" : undefined;
187
182
  const parentLabel = object.foreignTfLabel ?? (token.parent !== undefined ? tsLabelToTfLabel(token.parent) : "related");
188
- const tfLabel = ownerType === undefined
189
- ? sanitizeName(`${parentLabel}_${name}`)
190
- : sanitizeName(`${ownerType}_${parentLabel}_${name}`);
183
+ const tfLabel = object.kind === "element" || object.kind === "app" || object.kind === "task"
184
+ ? foreignFieldDataLabel(object.kind, parentLabel, name)
185
+ : sanitizeName(`${parentLabel}_${name}`);
191
186
  opts.orgRefs.foreignField("elementum_field", tfLabel, object.value, name);
192
187
  return expr.dataAttr("elementum_field", tfLabel, ["id"]);
193
188
  }
@@ -297,8 +292,17 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
297
292
  attrs["values_render_type"] = cfg.valuesRenderType;
298
293
  if (cfg.filter !== undefined) {
299
294
  let unresolvedField = false;
295
+ const owner = { value: opts.objectId, refName: opts.appRefName, kind: opts.scope ?? "app", target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel } };
300
296
  try {
301
297
  const filterValue = filterWireToTfCodec(cfg.filter, {
298
+ recordField: (token) => {
299
+ const value = resolveFieldOnObject(token, owner, opts_, where, "filter record field");
300
+ if (value === undefined) {
301
+ unresolvedField = true;
302
+ return "";
303
+ }
304
+ return value;
305
+ },
302
306
  field: (token) => {
303
307
  const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
304
308
  if (value === undefined) {
@@ -1,5 +1,6 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
- import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
2
+ import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
+ import { type AccessPolicyOwner } from "../access-policy/from-tf.js";
3
4
  import type { NormalizedRelationship } from "../app/deserializer/normalize.js";
4
5
  export interface RelationshipOwner {
5
6
  /** Public EDK vocabulary; provider resource names stay at the TF boundary. */
@@ -10,3 +11,9 @@ export interface RelationshipOwner {
10
11
  readonly scope: ChildResourceScope;
11
12
  }
12
13
  export declare function relationshipsFromTf(blocks: readonly TfBlock[], owner: RelationshipOwner, ctx: FromTfContext): NormalizedRelationship[];
14
+ /**
15
+ * Filter-field scope for records of the app or element `aspectId` points at,
16
+ * managed or data-sourced. Other filters over a target's records (dynamic
17
+ * layout related-items blocks) decode their fields the same way.
18
+ */
19
+ export declare function filterOwnerForAspect(aspectId: TfValue, ctx: FromTfContext): AccessPolicyOwner | undefined;