@elementumai/edk 0.9.10 → 0.9.12

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 (124) hide show
  1. package/README.md +39 -5
  2. package/dist-sdk/src/catalog/factories.d.ts +42 -14
  3. package/dist-sdk/src/catalog/factories.js +77 -14
  4. package/dist-sdk/src/catalog/from-authoring.js +4 -4
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +1 -1
  7. package/dist-sdk/src/catalog/org.js +3 -2
  8. package/dist-sdk/src/catalog/token.js +4 -0
  9. package/dist-sdk/src/catalog/types.d.ts +32 -5
  10. package/dist-sdk/src/catalog/types.js +1 -0
  11. package/dist-sdk/src/core/triggers/on-demand.d.ts +4 -28
  12. package/dist-sdk/src/core/triggers/on-demand.js +2 -4
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/entity.d.ts +2 -0
  15. package/dist-sdk/src/engine/logging.d.ts +90 -0
  16. package/dist-sdk/src/engine/logging.js +124 -0
  17. package/dist-sdk/src/engine/progress.d.ts +119 -0
  18. package/dist-sdk/src/engine/progress.js +647 -0
  19. package/dist-sdk/src/engine/pull/result-output.d.ts +24 -0
  20. package/dist-sdk/src/engine/pull/result-output.js +48 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  25. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  26. package/dist-sdk/src/entities/agent/tools.d.ts +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  28. package/dist-sdk/src/entities/app/build.d.ts +22 -2
  29. package/dist-sdk/src/entities/app/build.js +6 -0
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  31. package/dist-sdk/src/entities/app/from-tf.js +10 -7
  32. package/dist-sdk/src/entities/app/to-tf.js +14 -14
  33. package/dist-sdk/src/entities/automation/build.d.ts +11 -16
  34. package/dist-sdk/src/entities/automation/build.js +38 -8
  35. package/dist-sdk/src/entities/automation/catalog-render.js +1 -1
  36. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +1 -2
  37. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +23 -5
  38. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +239 -34
  39. package/dist-sdk/src/entities/automation/from-tf.js +276 -19
  40. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  41. package/dist-sdk/src/entities/automation/module.js +3 -2
  42. package/dist-sdk/src/entities/automation/output-field-types.js +25 -13
  43. package/dist-sdk/src/entities/automation/script-code.d.ts +12 -4
  44. package/dist-sdk/src/entities/automation/script-code.js +659 -101
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -28
  46. package/dist-sdk/src/entities/automation/tasks.js +48 -15
  47. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  48. package/dist-sdk/src/entities/automation/to-tf.js +514 -103
  49. package/dist-sdk/src/entities/automation/triggers.d.ts +15 -9
  50. package/dist-sdk/src/entities/automation/triggers.js +4 -2
  51. package/dist-sdk/src/entities/automation/types.js +1 -0
  52. package/dist-sdk/src/entities/chart/build.d.ts +15 -3
  53. package/dist-sdk/src/entities/chart/build.js +6 -1
  54. package/dist-sdk/src/entities/chart/from-tf.d.ts +8 -2
  55. package/dist-sdk/src/entities/chart/from-tf.js +71 -8
  56. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  57. package/dist-sdk/src/entities/chart/index.js +1 -1
  58. package/dist-sdk/src/entities/chart/printer.js +27 -7
  59. package/dist-sdk/src/entities/chart/to-tf.js +56 -2
  60. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  61. package/dist-sdk/src/entities/datamine/from-tf.js +11 -1
  62. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  63. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  64. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  65. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/from-tf.js +4 -3
  70. package/dist-sdk/src/entities/element/module.js +1 -0
  71. package/dist-sdk/src/entities/element/to-tf.d.ts +4 -1
  72. package/dist-sdk/src/entities/element/to-tf.js +28 -2
  73. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  74. package/dist-sdk/src/entities/field/build.js +2 -1
  75. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  76. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  77. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  78. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  79. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  80. package/dist-sdk/src/entities/field/from-tf.js +73 -1
  81. package/dist-sdk/src/entities/field/metadata.d.ts +18 -0
  82. package/dist-sdk/src/entities/field/metadata.js +34 -0
  83. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  84. package/dist-sdk/src/entities/relationship/build.d.ts +27 -9
  85. package/dist-sdk/src/entities/relationship/column-contract.d.ts +24 -0
  86. package/dist-sdk/src/entities/relationship/column-contract.js +41 -0
  87. package/dist-sdk/src/entities/relationship/from-tf.js +33 -48
  88. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  89. package/dist-sdk/src/entities/relationship/to-tf.js +33 -2
  90. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  91. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  92. package/dist-sdk/src/entities/shared/context.d.ts +6 -3
  93. package/dist-sdk/src/entities/shared/context.js +19 -1
  94. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  95. package/dist-sdk/src/entities/shared/filters/index.js +28 -0
  96. package/dist-sdk/src/entities/shared/filters/print.js +2 -0
  97. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +8 -1
  98. package/dist-sdk/src/entities/shared/filters/tf-codec.js +10 -6
  99. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  100. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -0
  101. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +52 -27
  102. package/dist-sdk/src/entities/skill/module.js +1 -0
  103. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  104. package/dist-sdk/src/entities/skill/to-tf.js +17 -0
  105. package/dist-sdk/src/entities/skill/tools.d.ts +48 -12
  106. package/dist-sdk/src/entities/skill/tools.js +12 -1
  107. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -12
  108. package/dist-sdk/src/entities/skill-tool/from-tf.js +50 -46
  109. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -0
  110. package/dist-sdk/src/entities/skill-tool/to-tf.js +66 -7
  111. package/dist-sdk/src/entities/table/build.js +10 -2
  112. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  113. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  114. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  115. package/dist-sdk/src/entities/view/to-tf.js +39 -12
  116. package/dist-sdk/src/entities/widget/build.d.ts +43 -7
  117. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  118. package/dist-sdk/src/entities/widget/from-tf.js +162 -23
  119. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  120. package/dist-sdk/src/entities/widget/to-tf.js +150 -6
  121. package/dist-sdk/src/graph/types.d.ts +13 -0
  122. package/package.json +1 -1
  123. package/dist-sdk/src/core/types/platform.d.ts +0 -2
  124. package/dist-sdk/src/core/types/platform.js +0 -1
@@ -1,6 +1,8 @@
1
1
  import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { fieldKeyFromTfRef } from "../field/from-tf.js";
4
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
5
+ import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
4
6
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
5
7
  import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY, } from "./dialect.js";
6
8
  const KNOWN_ATTRS = new Set([
@@ -17,6 +19,30 @@ export function dynamicLayoutsFromTf(blocks, owner, ctx) {
17
19
  }
18
20
  return out;
19
21
  }
22
+ /**
23
+ * Widget resource labels referenced by dynamic-layout automation buttons.
24
+ * The label is the companion widget's stable Terraform identity; its display
25
+ * name is mutable and cannot safely distinguish generated from authored
26
+ * widgets during pull.
27
+ */
28
+ export function dynamicLayoutCompanionWidgetLabels(blocks) {
29
+ const labels = new Set();
30
+ for (const block of blocks) {
31
+ const components = plainObject(block.attrs["components"]);
32
+ if (components === undefined)
33
+ continue;
34
+ for (const raw of Object.values(components)) {
35
+ const component = plainObject(raw);
36
+ const button = component === undefined ? undefined : plainObject(component["automation_button"]);
37
+ const label = button === undefined
38
+ ? undefined
39
+ : resourceRefLabel(button["widget_id"], WIDGET_RESOURCE_TYPE);
40
+ if (label !== undefined)
41
+ labels.add(label);
42
+ }
43
+ }
44
+ return labels;
45
+ }
20
46
  function dynamicLayoutFromTf(block, owner, ctx) {
21
47
  const where = `${DYNAMIC_LAYOUT_RESOURCE_TYPE}.${block.label ?? "?"}`;
22
48
  for (const key of Object.keys(block.attrs)) {
@@ -91,15 +117,30 @@ function componentMap(values, owner, ctx, where) {
91
117
  });
92
118
  delete update["fieldIds"];
93
119
  }
94
- const automation = plainUnknownObject(component["automationButton"]);
95
- if (automation !== undefined && automation["automationId"] !== undefined) {
96
- const label = resourceRefLabel(automation["automationId"], "elementum_automation");
120
+ const section = plainUnknownObject(component["section"]);
121
+ if (section !== undefined && section["agentId"] !== undefined) {
122
+ const label = resourceRefLabel(section["agentId"], "elementum_agent");
97
123
  if (label !== undefined) {
98
- automation["automation"] = pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName);
124
+ section["agent"] = pulledRef("agent", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName);
99
125
  }
100
126
  else
101
- ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_id is not a managed automation ref; dropped`);
102
- delete automation["automationId"];
127
+ ctx.diagnostics.push(`${where}.components.${id}.section: agent_id is not a managed agent ref; dropped`);
128
+ delete section["agentId"];
129
+ }
130
+ const automation = plainUnknownObject(component["automationButton"]);
131
+ if (automation !== undefined) {
132
+ // Build derives the backing widget from the component itself, so the
133
+ // binding is never authored and must not be printed back into source.
134
+ delete automation["widgetId"];
135
+ if (automation["automationId"] !== undefined) {
136
+ const label = resourceRefLabel(automation["automationId"], "elementum_automation");
137
+ if (label !== undefined) {
138
+ automation["automation"] = pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName);
139
+ }
140
+ else
141
+ ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_id is not a managed automation ref; dropped`);
142
+ delete automation["automationId"];
143
+ }
103
144
  }
104
145
  const create = plainUnknownObject(component["createButton"]);
105
146
  if (create !== undefined && create["targetAspectId"] !== undefined) {
@@ -208,13 +249,26 @@ function aspectRef(value, owner, ctx) {
208
249
  if (resourceLabel !== undefined)
209
250
  return pulledRef(kind, tfLabelToTsLabel(resourceLabel));
210
251
  const dataLabel = dataRefLabel(value, type);
211
- if (dataLabel !== undefined)
212
- return pulledRef(kind, tfLabelToTsLabel(dataLabel), undefined, ctx.dataName(type, dataLabel));
252
+ if (dataLabel !== undefined) {
253
+ // Same namespace-only foreign-target shape widget/from-tf.ts and
254
+ // dashboard/from-tf.ts resolve via the shared helper - a guessed
255
+ // tfLabel-derived name matches nothing on the platform and breaks
256
+ // elementum build/plan. No printer-side catalogRef distinction here
257
+ // (unlike widget), so only key/name/namespace are carried through.
258
+ const resolved = resolveDataAspectTarget(ctx, kind, dataLabel);
259
+ return pulledRef(kind, resolved.key, undefined, resolved.name, resolved.namespace);
260
+ }
213
261
  }
214
262
  return undefined;
215
263
  }
216
- function pulledRef(kind, key, parent, name) {
217
- return { __pulledRef: kind, key, ...(parent !== undefined && { parent }), ...(name !== undefined && { name }) };
264
+ function pulledRef(kind, key, parent, name, namespace) {
265
+ return {
266
+ __pulledRef: kind,
267
+ key,
268
+ ...(parent !== undefined && { parent }),
269
+ ...(name !== undefined && { name }),
270
+ ...(namespace !== undefined && { namespace }),
271
+ };
218
272
  }
219
273
  function camelObject(value) {
220
274
  const out = {};
@@ -1,10 +1,11 @@
1
1
  import { workspaceAspectKey } from "../../engine/build/context.js";
2
2
  import { resolveForeignRef } from "../shared/foreign-ref.js";
3
- import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
+ import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
4
  import { fieldRefToTfValue } from "../field/to-tf.js";
5
5
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
6
+ import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
6
7
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
7
- import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS, dynamicLayoutFieldComponentWireKey, } from "./dialect.js";
8
+ import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS, dynamicLayoutActionWidgetName, dynamicLayoutFieldComponentWireKey, } from "./dialect.js";
8
9
  export function dynamicLayoutsToTf(layouts, opts) {
9
10
  const blocks = [];
10
11
  for (const [key, layout] of Object.entries(layouts ?? {})) {
@@ -13,6 +14,7 @@ export function dynamicLayoutsToTf(layouts, opts) {
13
14
  opts.diagnostics.push(`${where}: key is not a canonical tsLabel; dropped`);
14
15
  continue;
15
16
  }
17
+ const componentResult = componentMap(layout.components ?? {}, key, where, opts);
16
18
  const attrs = {
17
19
  app_id: opts.objectId,
18
20
  name: layout.name ?? "",
@@ -20,7 +22,7 @@ export function dynamicLayoutsToTf(layouts, opts) {
20
22
  document_id: layout.documentId ?? "",
21
23
  document_version: layout.documentVersion ?? "1.0.0",
22
24
  root_component: layout.rootComponent ?? "",
23
- components: componentMap(layout.components ?? {}, where, opts),
25
+ components: componentResult.components,
24
26
  };
25
27
  if (layout.description !== undefined)
26
28
  attrs["description"] = layout.description;
@@ -47,11 +49,16 @@ export function dynamicLayoutsToTf(layouts, opts) {
47
49
  label: scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), "app"),
48
50
  attrs,
49
51
  });
52
+ blocks.push(...componentResult.companionWidgets);
50
53
  }
51
54
  return blocks;
52
55
  }
53
- function componentMap(components, where, opts) {
56
+ function companionWidgetLabel(layoutKey, componentId, opts) {
57
+ return scopedResourceLabel(opts.ownerTfLabel, sanitizeName(dynamicLayoutActionWidgetName(layoutKey, componentId)), "app");
58
+ }
59
+ function componentMap(components, layoutKey, where, opts) {
54
60
  const out = {};
61
+ const companionWidgets = [];
55
62
  for (const [componentId, component] of Object.entries(components)) {
56
63
  const attrs = {};
57
64
  for (const [key, value] of Object.entries(component)) {
@@ -64,6 +71,17 @@ function componentMap(components, where, opts) {
64
71
  const wireKey = dynamicLayoutFieldComponentWireKey(key);
65
72
  attrs[snakeKey(wireKey)] = fieldComponent(value, `${where}.components[${JSON.stringify(componentId)}].${key}`, opts);
66
73
  }
74
+ else if (key === "section") {
75
+ const rec = object(value);
76
+ const section = snakeObject(rec, where, opts);
77
+ delete section["agent"];
78
+ if (rec["agent"] !== undefined) {
79
+ const agent = resolveAgent(rec["agent"], `${where}.components.${componentId}.section`, opts);
80
+ if (agent !== undefined)
81
+ section["agent_id"] = agent;
82
+ }
83
+ attrs["section"] = section;
84
+ }
67
85
  else if (key === "updateBlock") {
68
86
  const rec = object(value);
69
87
  const block = {};
@@ -83,8 +101,26 @@ function componentMap(components, where, opts) {
83
101
  delete button["automation"];
84
102
  const token = rec["automation"];
85
103
  const automation = resolveAutomation(token, `${where}.components.${componentId}.automationButton`, opts);
86
- if (automation !== undefined)
104
+ if (automation !== undefined) {
87
105
  button["automation_id"] = automation;
106
+ // The renderer executes the automation through a widget, not the
107
+ // automation id; without this binding it reports the button as not
108
+ // ready to run. Points at the companion widget build emits alongside.
109
+ button["widget_id"] = expr.resourceAttr(WIDGET_RESOURCE_TYPE, companionWidgetLabel(layoutKey, componentId, opts), ["id"]);
110
+ companionWidgets.push({
111
+ kind: "resource",
112
+ type: WIDGET_RESOURCE_TYPE,
113
+ label: companionWidgetLabel(layoutKey, componentId, opts),
114
+ attrs: {
115
+ object_id: opts.objectId,
116
+ run_automation_action: {
117
+ name: dynamicLayoutActionWidgetName(layoutKey, componentId),
118
+ automation_id: automation,
119
+ button_type: "PRIMARY",
120
+ },
121
+ },
122
+ });
123
+ }
88
124
  attrs["automation_button"] = button;
89
125
  }
90
126
  else if (key === "createButton") {
@@ -102,7 +138,7 @@ function componentMap(components, where, opts) {
102
138
  }
103
139
  out[componentId] = attrs;
104
140
  }
105
- return out;
141
+ return { components: out, companionWidgets };
106
142
  }
107
143
  function fieldComponent(value, where, opts) {
108
144
  const rec = object(value);
@@ -228,6 +264,18 @@ function resolveAutomation(token, where, opts) {
228
264
  }
229
265
  return expr.resourceAttr("elementum_automation", scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), "app"), ["id"]);
230
266
  }
267
+ function resolveAgent(token, where, opts) {
268
+ const refName = token?.refName ?? "";
269
+ if (token?.parent !== undefined && token.parent !== opts.ownerRefName) {
270
+ opts.diagnostics.push(`${where}: agent targets a different app; dropped`);
271
+ return undefined;
272
+ }
273
+ if (!isCanonicalTsLabel(refName)) {
274
+ opts.diagnostics.push(`${where}: agent key "${refName}" is not a canonical tsLabel; dropped`);
275
+ return undefined;
276
+ }
277
+ return expr.resourceAttr("elementum_agent", scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), "app"), ["id"]);
278
+ }
231
279
  function resolveAspect(token, where, opts) {
232
280
  const kind = token?.__kind === "element" ? "element" : "app";
233
281
  const refName = token?.refName ?? "";
@@ -114,6 +114,14 @@ export interface ElementV2Options<F extends Record<string, AppField> = Record<st
114
114
  * not both.
115
115
  */
116
116
  readonly recordCreateForm?: AppRecordCreateForm;
117
+ /**
118
+ * Parent-owned joins keyed by stable ref name. Same join contract as apps:
119
+ * a `relatedRecords` widget targeting another app/element lists rows through
120
+ * a matching entry here whose columns join comparable stored values, not
121
+ * through that child's `relationField` / `autoRelate`. Do not join system
122
+ * `"id"` (HANDLE) to a `relationField` or dynamic dropdown on the related
123
+ * side.
124
+ */
117
125
  readonly relationships?: Readonly<Record<string, AppRelationship>>;
118
126
  /** Display order of `listViews` (by key). Defaults to declaration order. */
119
127
  readonly viewOrder?: readonly string[];
@@ -3,6 +3,7 @@
3
3
  * `NormalizedApp` shape (`type: "ELEMENT"`) that `printElementV2` consumes.
4
4
  * Mirrors `app/from-tf.ts` without app-only status/stages dialect.
5
5
  */
6
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES } from "../../core/system-fields.js";
6
7
  import { EntityTfError } from "../../engine/entity.js";
7
8
  import { dataRefLabel, optionalBoolean, optionalString } from "../../engine/pull/context.js";
8
9
  import { tfLabelToTsLabel } from "../../engine/tf/index.js";
@@ -127,11 +128,11 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
127
128
  const fields = [];
128
129
  const titleName = optionalString(attrs, "title_field_name", `element "${label}"`, ctx);
129
130
  if (titleName !== undefined || titleFieldDescription !== undefined) {
130
- fields.push(systemEntry("title", titleName ?? "Title", "TEXT", "TITLE", titleFieldDescription));
131
+ fields.push(systemEntry("title", titleName ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.title, "TEXT", "TITLE", titleFieldDescription));
131
132
  }
132
133
  const idName = optionalString(attrs, "id_field_name", `element "${label}"`, ctx);
133
134
  if (idName !== undefined || idFieldDescription !== undefined) {
134
- fields.push(systemEntry("id", idName ?? "ID", "TEXT", "HANDLE", idFieldDescription));
135
+ fields.push(systemEntry("id", idName ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.id, "TEXT", "HANDLE", idFieldDescription));
135
136
  }
136
137
  const owner = { type: ELEMENT_RESOURCE_TYPE, label, scope: "element" };
137
138
  for (const block of fieldBlocks) {
@@ -144,7 +145,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
144
145
  ctx.diagnostics.push(`element "${label}": no import block in the stream — adoption has no identity to bind`);
145
146
  }
146
147
  const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: refName, ownerRefName: refName, scope: "element", ownerType: "ELEMENT_ASPECT" }, ctx);
147
- const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, [], viewBlocks.managedViewOrderBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: refName, scope: "element" }, ctx);
148
+ const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, [], viewBlocks.managedViewOrderBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "element" }, ctx);
148
149
  if (viewBlocks.recordCreateFormBlocks.length > 1) {
149
150
  ctx.diagnostics.push(`element "${label}": found ${viewBlocks.recordCreateFormBlocks.length} record create forms; only the first is used`);
150
151
  }
@@ -74,6 +74,7 @@ export const elementModule = {
74
74
  blocks: result.blocks,
75
75
  fieldAddresses: result.fieldAddresses,
76
76
  fieldNames: result.fieldNames,
77
+ fieldMetadata: result.fieldMetadata,
77
78
  };
78
79
  },
79
80
  appendLocals: (localsAttrs, ctx) => {
@@ -3,13 +3,16 @@
3
3
  * field resources in ei's dialect. No status_options/stages (apps always
4
4
  * emit those; element captures do not).
5
5
  */
6
- import type { ToTfContext } from "../../engine/build/context.js";
6
+ import { type ToTfContext } from "../../engine/build/context.js";
7
7
  import { type DeployableEntity } from "../../engine/entity.js";
8
+ import type { BuildFieldMetadata } from "../../graph/types.js";
8
9
  import { type TfBlock } from "../../engine/tf/index.js";
9
10
  export interface ElementToTfResult {
10
11
  readonly blocks: readonly TfBlock[];
11
12
  readonly fieldAddresses: ReadonlyMap<string, string>;
12
13
  readonly fieldNames: ReadonlyMap<string, string>;
14
+ /** bag key → type/options metadata, used by element-owned automation switch filters. */
15
+ readonly fieldMetadata: ReadonlyMap<string, BuildFieldMetadata>;
13
16
  }
14
17
  /** `elementum_element` + one field resource per custom field. */
15
18
  export declare function elementToTf(entity: DeployableEntity, ctx: ToTfContext): ElementToTfResult;
@@ -3,12 +3,15 @@
3
3
  * field resources in ei's dialect. No status_options/stages (apps always
4
4
  * emit those; element captures do not).
5
5
  */
6
+ import { workspaceAspectKey } from "../../engine/build/context.js";
6
7
  import { EntityTfError } from "../../engine/entity.js";
7
8
  import { expr, snakeSlug } from "../../engine/tf/index.js";
8
9
  import { accessPolicyToTf } from "../access-policy/to-tf.js";
9
10
  import { displayBlocksToLayoutSections } from "../app/display-blocks-to-layout.js";
11
+ import { APP_RESOURCE_TYPE } from "../app/module.js";
10
12
  import { displayBlocksToRecordCreateFormSections } from "../app/display-blocks-to-record-create-form.js";
11
13
  import { dashboardsToTf } from "../dashboard/to-tf.js";
14
+ import { fieldMetadataFromEntries } from "../field/metadata.js";
12
15
  import { fieldToTf } from "../field/to-tf.js";
13
16
  import { CATEGORY_ORG_BAG } from "../org/category.js";
14
17
  import { categoryIdExpr, missingCategoryDiagnostic } from "../org/category-ref.js";
@@ -16,8 +19,9 @@ import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
16
19
  import { recordCreateFormToTf } from "../record-create-form/to-tf.js";
17
20
  import { relationshipsToTf } from "../relationship/to-tf.js";
18
21
  import { rolesToTf } from "../role/to-tf.js";
19
- import { widgetsToTf } from "../widget/to-tf.js";
22
+ import { relationshipTargetsFromBag, widgetsToTf } from "../widget/to-tf.js";
20
23
  import { viewToTf } from "../view/to-tf.js";
24
+ import { SYSTEM_FIELD_KEY_BY_TAG } from "../../core/system-fields.js";
21
25
  import { ELEMENT_RESOURCE_TYPE } from "./module.js";
22
26
  /** System-field tags that fold into the element resource (no field resource). */
23
27
  const SYSTEM_FIELD_TAGS = new Set([
@@ -125,6 +129,7 @@ export function elementToTf(entity, ctx) {
125
129
  const blocks = [];
126
130
  const fieldAddresses = new Map();
127
131
  const fieldNames = new Map();
132
+ const fieldMetadata = fieldMetadataFromEntries(payload.fields);
128
133
  const objectId = expr.resourceAttr(ELEMENT_RESOURCE_TYPE, ctx.appTfLabel, ["id"]);
129
134
  for (const fieldEntry of payload.fields ?? []) {
130
135
  const typeKey = Object.keys(fieldEntry)[0];
@@ -137,6 +142,11 @@ export function elementToTf(entity, ctx) {
137
142
  fieldNames.set(fieldKey, name);
138
143
  const systemTag = inner.tags?.find((tag) => SYSTEM_FIELD_TAGS.has(tag));
139
144
  if (systemTag !== undefined) {
145
+ const systemKey = SYSTEM_FIELD_KEY_BY_TAG[systemTag];
146
+ // Same canonical-key guarantee as app/to-tf: cross-app .record.title
147
+ // must resolve against "title", never snakeSlug of a renamed label.
148
+ if (systemKey !== undefined && name !== "")
149
+ fieldNames.set(systemKey, name);
140
150
  switch (systemTag) {
141
151
  case "TITLE":
142
152
  if (name !== "Title")
@@ -195,6 +205,7 @@ export function elementToTf(entity, ctx) {
195
205
  workspaceAspects: ctx.workspaceAspects,
196
206
  diagnostics: ctx.diagnostics,
197
207
  fieldAddresses,
208
+ relationshipTargets: relationshipTargetsFromBag(payload.relationships),
198
209
  }));
199
210
  // An element has exactly one implicit layout (the platform's Initiate
200
211
  // stage — see layoutToTf's element-scope stage_id omission) — "layout" is
@@ -217,6 +228,7 @@ export function elementToTf(entity, ctx) {
217
228
  orgRefs: ctx.orgRefs,
218
229
  diagnostics: ctx.diagnostics,
219
230
  fieldAddresses,
231
+ widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
220
232
  });
221
233
  blocks.push(...viewBlocks);
222
234
  const recordCreateFormForToTf = payload.recordCreateForm ??
@@ -254,6 +266,20 @@ export function elementToTf(entity, ctx) {
254
266
  orgRefs: ctx.orgRefs,
255
267
  diagnostics: ctx.diagnostics,
256
268
  fieldAddresses,
269
+ // An element has no service accounts of its own. Hand the sibling app's
270
+ // authored bag to the shared resolver so a managed account becomes a
271
+ // direct resource ref and Terraform sequences same-apply creation.
272
+ resolveServiceAccountApp: (appRefName) => {
273
+ const app = ctx.workspaceAspects?.get(workspaceAspectKey("app", appRefName));
274
+ if (app === undefined)
275
+ return undefined;
276
+ const serviceAccounts = app.streamRootEntity?.payload?.serviceAccounts;
277
+ return {
278
+ appTfLabel: app.tfLabel,
279
+ appId: expr.resourceAttr(APP_RESOURCE_TYPE, app.tfLabel, ["id"]),
280
+ ...(serviceAccounts !== undefined ? { serviceAccounts } : {}),
281
+ };
282
+ },
257
283
  });
258
284
  blocks.push(block);
259
285
  }
@@ -271,5 +297,5 @@ export function elementToTf(entity, ctx) {
271
297
  label: ctx.appTfLabel,
272
298
  attrs: elementAttrs,
273
299
  });
274
- return { blocks, fieldAddresses, fieldNames };
300
+ return { blocks, fieldAddresses, fieldNames, fieldMetadata };
275
301
  }
@@ -102,6 +102,11 @@ export interface DynamicDropdownConfig {
102
102
  readonly source: AppOrElementRef | UnsafePlatformId;
103
103
  readonly label: FieldRef | UnsafePlatformId;
104
104
  readonly parent?: DynamicDropdownParent;
105
+ /**
106
+ * When true (platform default), selecting a value creates an instance-level
107
+ * link from **this** record. It does not author a parent `relationships[]`
108
+ * join and does not populate a `relatedRecords` widget on the other object.
109
+ */
105
110
  readonly autoRelate?: boolean;
106
111
  readonly displayAs?: DropdownDisplay;
107
112
  readonly filter?: Filter;
@@ -148,7 +153,11 @@ export interface TextFieldOptions extends BaseFieldOptions {
148
153
  export interface RelationFieldOptions extends BaseFieldOptions {
149
154
  readonly relatedObject: AppOrElementRef | UnsafePlatformId;
150
155
  readonly relatedLabelField: FieldRef | UnsafePlatformId;
151
- /** Defaults to `true` on the platform. */
156
+ /**
157
+ * Defaults to `true` on the platform. Selecting a related record creates an
158
+ * instance-level link from **this** record. Reverse `relatedRecords` on the
159
+ * other object still needs that object's authored `relationships[]` join.
160
+ */
152
161
  readonly autoRelate?: boolean;
153
162
  }
154
163
  export declare function textField(opts: TextFieldOptions): AppField & {
@@ -17,7 +17,7 @@
17
17
  * literal form (`{ name, type: "TEXT" }`) remains valid where ever an
18
18
  * AppField is accepted.
19
19
  */
20
- import { coerce } from "./calc/runtime.js";
20
+ import { assertCalculatedFieldRoot, coerce } from "./calc/runtime.js";
21
21
  /** Product-visible rendering modes for dynamically sourced values. */
22
22
  export const dropdownDisplay = {
23
23
  dropdown: "DROPDOWN",
@@ -148,6 +148,7 @@ export function relationField(opts) {
148
148
  /** Create a calculated field whose platform field kind is inferred from its expression. */
149
149
  export function calculatedField(opts) {
150
150
  const expression = coerce(opts.expression);
151
+ assertCalculatedFieldRoot(expression, opts.name);
151
152
  const type = (() => {
152
153
  switch (expression.__exprType) {
153
154
  case "number": return "NUMBER";
@@ -13,7 +13,7 @@
13
13
  * reads close to the math expression. Same shape as the Java
14
14
  * `ExpressionUtil.addition` / `subtraction` / etc. helpers.
15
15
  */
16
- import { coerce, makeComposedExpr, makeExpr } from "./runtime.js";
16
+ import { coerce, makeComparisonExpr, makeComposedExpr, makeExpr } from "./runtime.js";
17
17
  import { concat, toText, len, trim, upper, lower, left, right, mid, substitute, find, search, split, splitText, regexMatch, regexReplace, regexExtract, jsonEscape, jsonUnescape, repeat, } from "./text.js";
18
18
  import { round, power, sqrt, toNumber, uuid } from "./numeric.js";
19
19
  import { now, makeDate, dateTime, dateValue, dateDiff, dateDif, truncateDateTime, dateTimeTrunc, weekday, year, month, day, hour, minute, second, } from "./date.js";
@@ -108,32 +108,32 @@ function dividedBy(a, b) {
108
108
  function gt(a, b) {
109
109
  const ae = coerce(a);
110
110
  const be = coerce(b);
111
- return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} > ${be.toCalcString()}`);
111
+ return makeComparisonExpr([ae, be], () => `${ae.toCalcString()} > ${be.toCalcString()}`);
112
112
  }
113
113
  function lt(a, b) {
114
114
  const ae = coerce(a);
115
115
  const be = coerce(b);
116
- return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} < ${be.toCalcString()}`);
116
+ return makeComparisonExpr([ae, be], () => `${ae.toCalcString()} < ${be.toCalcString()}`);
117
117
  }
118
118
  function gte(a, b) {
119
119
  const ae = coerce(a);
120
120
  const be = coerce(b);
121
- return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} >= ${be.toCalcString()}`);
121
+ return makeComparisonExpr([ae, be], () => `${ae.toCalcString()} >= ${be.toCalcString()}`);
122
122
  }
123
123
  function lte(a, b) {
124
124
  const ae = coerce(a);
125
125
  const be = coerce(b);
126
- return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} <= ${be.toCalcString()}`);
126
+ return makeComparisonExpr([ae, be], () => `${ae.toCalcString()} <= ${be.toCalcString()}`);
127
127
  }
128
128
  function eq(a, b) {
129
129
  const ae = coerce(a);
130
130
  const be = coerce(b);
131
- return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} = ${be.toCalcString()}`);
131
+ return makeComparisonExpr([ae, be], () => `${ae.toCalcString()} = ${be.toCalcString()}`);
132
132
  }
133
133
  function ne(a, b) {
134
134
  const ae = coerce(a);
135
135
  const be = coerce(b);
136
- return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} <> ${be.toCalcString()}`);
136
+ return makeComparisonExpr([ae, be], () => `${ae.toCalcString()} <> ${be.toCalcString()}`);
137
137
  }
138
138
  // ---------------------------------------------------------------------------
139
139
  // Logical
@@ -40,6 +40,25 @@ export declare function isExpr(value: unknown): value is Expr<ExprType, ExprCard
40
40
  export declare function expressionContext(expressions: readonly Expr<ExprType, ExprCardinality, ExprContext>[]): ExprContext;
41
41
  /** Build a scalar parent node while preserving record-context metadata. */
42
42
  export declare function makeComposedExpr<T extends ExprType>(type: T, expressions: readonly Expr<ExprType, ExprCardinality, ExprContext>[], serialize: () => string): Expr<T, "single", ExprContext>;
43
+ /**
44
+ * Build a comparison node, tagged so {@link assertCalculatedFieldRoot} can
45
+ * reject it at the root of a calculation. The grammar's root production is
46
+ * "expression", which covers arithmetic, function calls, column refs and
47
+ * literals but NOT comparisons — those are a separate "boolean expression"
48
+ * production reachable only as a function argument.
49
+ */
50
+ export declare function makeComparisonExpr(expressions: readonly Expr<ExprType, ExprCardinality, ExprContext>[], serialize: () => string): Expr<"bool", "single", ExprContext>;
51
+ /**
52
+ * Throw when `expression` is a comparison standing alone as a whole
53
+ * calculated field. `owner` names the field in the message so the author can
54
+ * find it without reading the generated HCL.
55
+ *
56
+ * Scoped to calculated fields: the provider runs
57
+ * `aspectFieldCalculationValidateV3` on every create and update there, so the
58
+ * shape is a hard apply failure. Automation calculation tasks validate only on
59
+ * read, where the provider degrades to a diagnostic.
60
+ */
61
+ export declare function assertCalculatedFieldRoot(expression: Expr<ExprType, ExprCardinality, ExprContext>, owner?: string): void;
43
62
  /**
44
63
  * Emit the wire form of a field reference. UUID ids emit as
45
64
  * `"<uuid>"`; placeholder ids fall back to `"<name>"`. The server
@@ -56,6 +56,38 @@ export function expressionContext(expressions) {
56
56
  export function makeComposedExpr(type, expressions, serialize) {
57
57
  return makeExpr(type, serialize, { context: expressionContext(expressions) });
58
58
  }
59
+ /**
60
+ * Build a comparison node, tagged so {@link assertCalculatedFieldRoot} can
61
+ * reject it at the root of a calculation. The grammar's root production is
62
+ * "expression", which covers arithmetic, function calls, column refs and
63
+ * literals but NOT comparisons — those are a separate "boolean expression"
64
+ * production reachable only as a function argument.
65
+ */
66
+ export function makeComparisonExpr(expressions, serialize) {
67
+ return {
68
+ ...makeComposedExpr("bool", expressions, serialize),
69
+ __exprBoolShape: "comparison",
70
+ };
71
+ }
72
+ /**
73
+ * Throw when `expression` is a comparison standing alone as a whole
74
+ * calculated field. `owner` names the field in the message so the author can
75
+ * find it without reading the generated HCL.
76
+ *
77
+ * Scoped to calculated fields: the provider runs
78
+ * `aspectFieldCalculationValidateV3` on every create and update there, so the
79
+ * shape is a hard apply failure. Automation calculation tasks validate only on
80
+ * read, where the provider degrades to a diagnostic.
81
+ */
82
+ export function assertCalculatedFieldRoot(expression, owner) {
83
+ if (expression.__exprBoolShape !== "comparison")
84
+ return;
85
+ const subject = owner === undefined ? "calculation" : `calculation "${owner}"`;
86
+ throw new Error(`${subject}: a comparison cannot be the whole calculation — the platform ` +
87
+ `parses "${expression.toCalcString()}" as a boolean expression, which its ` +
88
+ `grammar only accepts inside a function. Wrap it, e.g. ` +
89
+ `calc.if(<comparison>, true, false).`);
90
+ }
59
91
  /**
60
92
  * True if `value` looks like an `AppField`. Structural check — looks
61
93
  * for the `type` + `id` + `name` triplet every variant carries.
@@ -14,6 +14,12 @@ export interface Expr<T extends ExprType, Cardinality extends ExprCardinality =
14
14
  readonly __exprType: T;
15
15
  readonly __exprCardinality: Cardinality;
16
16
  readonly __exprContext: Context;
17
+ /**
18
+ * Set on comparison nodes (`a > b`, `a = b`, …). The platform grammar
19
+ * parses those as a "boolean expression", a production a calculation's
20
+ * root does not accept, so the root must be a function call.
21
+ */
22
+ readonly __exprBoolShape?: "comparison";
17
23
  }
18
24
  export type AnyExpr = Expr<ExprType, ExprCardinality, ExprContext>;
19
25
  export type ScalarExpr<T extends ExprType = ExprType, Context extends ExprContext = ExprContext> = Expr<T, "single", Context>;
@@ -35,3 +35,27 @@ export declare function fieldKeyFromTfRef(v: TfValue, ownerTfLabel?: string, sco
35
35
  * one app or element from becoming a same-owner field token accidentally.
36
36
  */
37
37
  export declare function fieldKeyFromTfValue(v: TfValue, ownerRefName: string, ownerTfLabel: string, scope: ChildResourceScope, ctx: FromTfContext): string | undefined;
38
+ export interface DecodedForeignDataField {
39
+ readonly key: string;
40
+ readonly name: string;
41
+ readonly fieldType?: string;
42
+ }
43
+ /**
44
+ * Decode `data.elementum_field.<label>` to the target's public field key.
45
+ * ei labels are `elementum_element_<sanitize(displayName)>_<field>` (or
46
+ * `app_<slug>_<field>`), not the catalog bag key. Treating the whole label
47
+ * as the key rebuilds a non-existent `elementum_text_field.<owner>_<label>`.
48
+ */
49
+ export declare function decodeForeignDataField(dataLabel: string, target: {
50
+ readonly key: string;
51
+ readonly name?: string;
52
+ readonly namespace?: string;
53
+ readonly kind?: string;
54
+ }, ctx: FromTfContext): DecodedForeignDataField;
55
+ /** Strip ei's owner-display prefix from a `data.elementum_field` label. */
56
+ export declare function fieldKeyFromForeignDataLabel(dataLabel: string, target: {
57
+ readonly key: string;
58
+ readonly name?: string;
59
+ readonly namespace?: string;
60
+ readonly kind?: string;
61
+ }): string | undefined;