@elementumai/edk 0.9.9 → 0.9.11

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 (72) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +8 -1
  2. package/dist-sdk/src/catalog/factories.js +13 -1
  3. package/dist-sdk/src/catalog/index.d.ts +2 -2
  4. package/dist-sdk/src/catalog/index.js +1 -1
  5. package/dist-sdk/src/catalog/types.d.ts +19 -2
  6. package/dist-sdk/src/catalog/types.js +1 -0
  7. package/dist-sdk/src/engine/build/context.d.ts +5 -0
  8. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  9. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  10. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  11. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  12. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  13. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  14. package/dist-sdk/src/entities/app/build.d.ts +15 -2
  15. package/dist-sdk/src/entities/app/build.js +6 -0
  16. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  17. package/dist-sdk/src/entities/app/from-tf.js +6 -3
  18. package/dist-sdk/src/entities/app/to-tf.d.ts +1 -1
  19. package/dist-sdk/src/entities/app/to-tf.js +7 -1
  20. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +78 -19
  21. package/dist-sdk/src/entities/automation/from-tf.js +113 -1
  22. package/dist-sdk/src/entities/automation/module.js +1 -0
  23. package/dist-sdk/src/entities/automation/script-code.d.ts +7 -0
  24. package/dist-sdk/src/entities/automation/script-code.js +17 -3
  25. package/dist-sdk/src/entities/automation/tasks.js +17 -0
  26. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  27. package/dist-sdk/src/entities/automation/to-tf.js +162 -46
  28. package/dist-sdk/src/entities/automation/types.js +1 -0
  29. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  30. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  31. package/dist-sdk/src/entities/dashboard/to-tf.js +4 -0
  32. package/dist-sdk/src/entities/datamine/from-tf.js +23 -3
  33. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  34. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  35. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  36. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  37. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  38. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  39. package/dist-sdk/src/entities/element/build.d.ts +7 -0
  40. package/dist-sdk/src/entities/element/from-tf.js +1 -1
  41. package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
  42. package/dist-sdk/src/entities/element/to-tf.js +19 -1
  43. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  44. package/dist-sdk/src/entities/field/build.js +2 -1
  45. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  46. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  47. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  48. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  49. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  50. package/dist-sdk/src/entities/relationship/build.d.ts +14 -7
  51. package/dist-sdk/src/entities/relationship/from-tf.js +14 -14
  52. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  53. package/dist-sdk/src/entities/relationship/to-tf.js +18 -0
  54. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  55. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  56. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +16 -4
  57. package/dist-sdk/src/entities/skill/tools.d.ts +10 -0
  58. package/dist-sdk/src/entities/skill/tools.js +10 -0
  59. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +7 -0
  60. package/dist-sdk/src/entities/skill-tool/from-tf.js +22 -2
  61. package/dist-sdk/src/entities/skill-tool/to-tf.js +21 -0
  62. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  63. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  64. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  65. package/dist-sdk/src/entities/view/to-tf.js +34 -5
  66. package/dist-sdk/src/entities/widget/build.d.ts +17 -7
  67. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  68. package/dist-sdk/src/entities/widget/from-tf.js +132 -18
  69. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  70. package/dist-sdk/src/entities/widget/to-tf.js +40 -0
  71. package/dist-sdk/src/graph/types.d.ts +8 -0
  72. package/package.json +1 -1
@@ -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,13 @@ 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. A `relatedRecords` widget
119
+ * targeting another app/element lists rows through a matching entry here
120
+ * whose columns join comparable stored values, not through that child's
121
+ * `relationField` / `autoRelate`. Do not join system `"id"` (HANDLE) to a
122
+ * child `relationField`.
123
+ */
117
124
  readonly relationships?: Readonly<Record<string, AppRelationship>>;
118
125
  /** Display order of `listViews` (by key). Defaults to declaration order. */
119
126
  readonly viewOrder?: readonly string[];
@@ -144,7 +144,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
144
144
  ctx.diagnostics.push(`element "${label}": no import block in the stream — adoption has no identity to bind`);
145
145
  }
146
146
  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);
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: label, scope: "element" }, ctx);
148
148
  if (viewBlocks.recordCreateFormBlocks.length > 1) {
149
149
  ctx.diagnostics.push(`element "${label}": found ${viewBlocks.recordCreateFormBlocks.length} record create forms; only the first is used`);
150
150
  }
@@ -3,7 +3,7 @@
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
8
  import { type TfBlock } from "../../engine/tf/index.js";
9
9
  export interface ElementToTfResult {
@@ -3,10 +3,12 @@
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";
12
14
  import { fieldToTf } from "../field/to-tf.js";
@@ -16,7 +18,7 @@ import { CLOUD_LINK_ORG_BAG } from "../org/cloud-link.js";
16
18
  import { recordCreateFormToTf } from "../record-create-form/to-tf.js";
17
19
  import { relationshipsToTf } from "../relationship/to-tf.js";
18
20
  import { rolesToTf } from "../role/to-tf.js";
19
- import { widgetsToTf } from "../widget/to-tf.js";
21
+ import { relationshipTargetsFromBag, widgetsToTf } from "../widget/to-tf.js";
20
22
  import { viewToTf } from "../view/to-tf.js";
21
23
  import { ELEMENT_RESOURCE_TYPE } from "./module.js";
22
24
  /** System-field tags that fold into the element resource (no field resource). */
@@ -195,6 +197,7 @@ export function elementToTf(entity, ctx) {
195
197
  workspaceAspects: ctx.workspaceAspects,
196
198
  diagnostics: ctx.diagnostics,
197
199
  fieldAddresses,
200
+ relationshipTargets: relationshipTargetsFromBag(payload.relationships),
198
201
  }));
199
202
  // An element has exactly one implicit layout (the platform's Initiate
200
203
  // stage — see layoutToTf's element-scope stage_id omission) — "layout" is
@@ -217,6 +220,7 @@ export function elementToTf(entity, ctx) {
217
220
  orgRefs: ctx.orgRefs,
218
221
  diagnostics: ctx.diagnostics,
219
222
  fieldAddresses,
223
+ widgetKeys: new Set(Object.keys(payload.widgets ?? {})),
220
224
  });
221
225
  blocks.push(...viewBlocks);
222
226
  const recordCreateFormForToTf = payload.recordCreateForm ??
@@ -254,6 +258,20 @@ export function elementToTf(entity, ctx) {
254
258
  orgRefs: ctx.orgRefs,
255
259
  diagnostics: ctx.diagnostics,
256
260
  fieldAddresses,
261
+ // An element has no service accounts of its own. Hand the sibling app's
262
+ // authored bag to the shared resolver so a managed account becomes a
263
+ // direct resource ref and Terraform sequences same-apply creation.
264
+ resolveServiceAccountApp: (appRefName) => {
265
+ const app = ctx.workspaceAspects?.get(workspaceAspectKey("app", appRefName));
266
+ if (app === undefined)
267
+ return undefined;
268
+ const serviceAccounts = app.streamRootEntity?.payload?.serviceAccounts;
269
+ return {
270
+ appTfLabel: app.tfLabel,
271
+ appId: expr.resourceAttr(APP_RESOURCE_TYPE, app.tfLabel, ["id"]),
272
+ ...(serviceAccounts !== undefined ? { serviceAccounts } : {}),
273
+ };
274
+ },
257
275
  });
258
276
  blocks.push(block);
259
277
  }
@@ -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>;
@@ -21,8 +21,16 @@ function serializeStructureField(f) {
21
21
  return { date: { name: f.name, format: f.format } };
22
22
  case "datetime":
23
23
  return { datetime: { name: f.name, format: f.format } };
24
- case "object":
25
- return { object: { name: f.name, properties: f.properties.map(serializeStructureField) } };
24
+ case "object": {
25
+ // ei's own export omits `properties` entirely for an object with no
26
+ // discovered sub-fields (e.g. a nested array-of-objects item type ei
27
+ // couldn't further introspect) rather than emitting an empty array —
28
+ // always including it here planned a spurious in-place update on
29
+ // every build (live-confirmed on purchaseorder/eu-sanofi's
30
+ // "New file reader"'s `to_PurchaseOrderItem` array field).
31
+ const properties = f.properties.map(serializeStructureField);
32
+ return { object: { name: f.name, ...(properties.length > 0 ? { properties } : {}) } };
33
+ }
26
34
  case "array":
27
35
  return { array: { name: f.name, arrayType: serializeStructureField(f.itemType) } };
28
36
  }
@@ -1,16 +1,23 @@
1
- import type { AppOrElementRef, FieldRef, TableColumnRef, TableRef } from "../../catalog/index.js";
1
+ import type { AppOrElementRef, FieldRef, RecordIdentityRef, TableColumnRef, TableRef } from "../../catalog/index.js";
2
2
  import type { Filter } from "../shared/filters/types.js";
3
3
  import type { AppViewFieldRef } from "../app/build.js";
4
- export interface AppRelationshipColumn {
4
+ export interface AppRelationshipColumn<Target extends AppOrElementRef | TableRef = AppOrElementRef | TableRef> {
5
5
  /** Field on the owning app/element. */
6
6
  readonly field: AppViewFieldRef;
7
7
  /** Field/column on `target`. */
8
- readonly relatedField: FieldRef | TableColumnRef;
8
+ readonly relatedField: FieldRef | TableColumnRef | RecordIdentityRef<Target>;
9
9
  }
10
- /** A provider AutoRelation, keyed under the owning aspect's `relationships` bag. */
11
- export interface AppRelationship {
12
- readonly target: AppOrElementRef | TableRef;
13
- readonly columns: readonly AppRelationshipColumn[];
10
+ /**
11
+ * A parent-owned join (`elementum_relationship`) keyed under this app/element's
12
+ * `relationships` bag. `relatedRecords` widgets on this object list rows
13
+ * through these joins. Columns must join comparable stored values; do not
14
+ * join this object's system `"id"` (HANDLE) to a child `relationField`.
15
+ * A child `relationField` / `autoRelate` is not a substitute for a join
16
+ * owned here.
17
+ */
18
+ export interface AppRelationship<Target extends AppOrElementRef | TableRef = AppOrElementRef | TableRef> {
19
+ readonly target: Target;
20
+ readonly columns: readonly AppRelationshipColumn<Target>[];
14
21
  /** Uses the same typed filter DSL as access policies. */
15
22
  readonly filter?: Filter;
16
23
  }
@@ -2,7 +2,7 @@ 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
4
  import { fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
- import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
5
+ import { resolveDataAspectTarget } 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";
8
8
  const KNOWN_ATTRS = new Set(["object_id", "related_object_id", "columns", "filter"]);
@@ -123,19 +123,7 @@ function targetRef(value, owner, ctx) {
123
123
  const dataLabel = dataRefLabel(value, type);
124
124
  if (dataLabel !== undefined) {
125
125
  if (kind === "app" || kind === "element") {
126
- const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
127
- const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
128
- const attrs = ctx.dataAttrs?.(type, dataLabel);
129
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
130
- return {
131
- kind,
132
- key: refName ?? tfLabelToTsLabel(dataLabel),
133
- name: displayName ?? refName ?? tfLabelToTsLabel(dataLabel),
134
- tfLabel: dataLabel,
135
- managed: false,
136
- ...(namespace !== undefined ? { namespace } : {}),
137
- ...(refName !== undefined ? { catalogRef: true } : {}),
138
- };
126
+ return { kind, tfLabel: dataLabel, managed: false, ...resolveDataAspectTarget(ctx, kind, dataLabel) };
139
127
  }
140
128
  const name = ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel);
141
129
  return { kind, key: tfLabelToTsLabel(dataLabel), name, tfLabel: dataLabel, managed: false };
@@ -146,6 +134,18 @@ function targetRef(value, owner, ctx) {
146
134
  function relatedFieldRef(value, target, ctx) {
147
135
  if (value === undefined)
148
136
  return undefined;
137
+ if (isTfExpr(value) && value.$expr === "resource-attr" && value.path.length === 1 && value.path[0] === "id") {
138
+ const targetType = target.kind === "app"
139
+ ? "elementum_app"
140
+ : target.kind === "element"
141
+ ? "elementum_element"
142
+ : target.kind === "table"
143
+ ? "elementum_table"
144
+ : undefined;
145
+ if (value.type === RELATIONSHIP_RESOURCE_TYPE || value.type === targetType) {
146
+ return { kind: "recordIdentity", key: "id", name: "Record ID", target };
147
+ }
148
+ }
149
149
  if (isTfExpr(value) && value.$expr === "resource-attr" && value.path.length === 1 && value.path[0] === "id") {
150
150
  const subType = SUB_TYPE_BY_RESOURCE.get(value.type);
151
151
  if (subType !== undefined) {
@@ -9,6 +9,7 @@ interface RefWire {
9
9
  readonly parent?: string;
10
10
  readonly fieldType?: string;
11
11
  readonly tfLabel?: string;
12
+ readonly target?: RefWire | string;
12
13
  }
13
14
  export interface RelationshipWire {
14
15
  readonly target?: RefWire;
@@ -117,6 +117,24 @@ function resolveTarget(value, where, opts) {
117
117
  };
118
118
  }
119
119
  function resolveRelatedField(value, target, where, opts) {
120
+ if (value?.__kind === "recordIdentity") {
121
+ if (value.target === undefined) {
122
+ opts.diagnostics.push(`${where}: record identity has no target; dropped`);
123
+ return undefined;
124
+ }
125
+ if (typeof value.target === "string") {
126
+ opts.diagnostics.push(`${where}: record identity target must be a typed reference, not a string; dropped`);
127
+ return undefined;
128
+ }
129
+ const identityTarget = resolveTarget(value.target, `${where}.target`, opts);
130
+ if (identityTarget === undefined)
131
+ return undefined;
132
+ if (identityTarget.kind !== target.kind || identityTarget.refName !== target.refName) {
133
+ opts.diagnostics.push(`${where}: record identity target does not match relationship target; dropped`);
134
+ return undefined;
135
+ }
136
+ return target.value;
137
+ }
120
138
  const refName = value?.refName ?? "";
121
139
  if (refName === "") {
122
140
  opts.diagnostics.push(`${where}: field has no refName; dropped`);
@@ -7,3 +7,18 @@ import type { FromTfContext } from "../../engine/pull/context.js";
7
7
  export declare function dataAspectDisplayName(ctx: FromTfContext, kind: "app" | "element", label: string): string | undefined;
8
8
  /** Resolve the stable pulled catalog key for the same foreign lookup. */
9
9
  export declare function dataAspectRefName(ctx: FromTfContext, kind: "app" | "element", label: string, displayName?: string): string | undefined;
10
+ export interface ResolvedAspectTarget {
11
+ readonly key: string;
12
+ readonly name: string;
13
+ readonly namespace?: string;
14
+ /** `key`/`name` are the target's real pulled catalog identity, not a guess. */
15
+ readonly catalogRef?: true;
16
+ }
17
+ /**
18
+ * Resolve a foreign app/element data lookup to the full identity a caller
19
+ * needs to build its own ref shape: the real display name/refName when the
20
+ * target was pulled separately, degrading to a tfLabel-derived guess (with
21
+ * the real namespace still attached) when it wasn't - never a bare guessed
22
+ * name with no namespace, which matches nothing on the platform.
23
+ */
24
+ export declare function resolveDataAspectTarget(ctx: FromTfContext, kind: "app" | "element", dataLabel: string): ResolvedAspectTarget;
@@ -1,3 +1,4 @@
1
+ import { tfLabelToTsLabel } from "../../engine/tf/index.js";
1
2
  /**
2
3
  * Resolve a foreign app/element data lookup to its display name. Ref-only
3
4
  * lookups are intentionally namespace-only, so fall back through the
@@ -37,3 +38,23 @@ export function dataAspectRefName(ctx, kind, label, displayName) {
37
38
  const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
38
39
  return name === undefined ? undefined : byName?.get(name);
39
40
  }
41
+ /**
42
+ * Resolve a foreign app/element data lookup to the full identity a caller
43
+ * needs to build its own ref shape: the real display name/refName when the
44
+ * target was pulled separately, degrading to a tfLabel-derived guess (with
45
+ * the real namespace still attached) when it wasn't - never a bare guessed
46
+ * name with no namespace, which matches nothing on the platform.
47
+ */
48
+ export function resolveDataAspectTarget(ctx, kind, dataLabel) {
49
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
50
+ const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
51
+ const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
52
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
53
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
54
+ return {
55
+ key: refName ?? tfLabelToTsLabel(dataLabel),
56
+ name: displayName ?? refName ?? tfLabelToTsLabel(dataLabel),
57
+ ...(namespace !== undefined ? { namespace } : {}),
58
+ ...(refName !== undefined ? { catalogRef: true } : {}),
59
+ };
60
+ }
@@ -51,7 +51,9 @@ export function printSkillV2(skill, opts) {
51
51
  ]),
52
52
  ].sort();
53
53
  const usesUnsafePlatformId = skill.tools.some((tool) => tool.automationRawId !== undefined ||
54
- tool.fields?.some((field) => field.rawFieldId !== undefined && !opts.foreignFieldRefsById?.has(field.rawFieldId)) === true);
54
+ tool.target?.kind === "unresolved" ||
55
+ tool.fields?.some((field) => field.rawFieldId !== undefined && !opts.foreignFieldRefsById?.has(field.rawFieldId)) === true ||
56
+ (tool.filterVariables?.length ?? 0) > 0);
55
57
  const lines = [];
56
58
  lines.push("/**");
57
59
  lines.push(` * ${skill.name}`);
@@ -227,10 +229,13 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
227
229
  }
228
230
  else if (tool.target?.kind === "unresolved") {
229
231
  // Export couldn't resolve target_id to any portable app/element
230
- // reference (board issue #648) — keep the raw platform id visible and
231
- // cast past the type system instead of silently dropping the tool.
232
+ // reference (board issue #648) — keep the raw platform id visible via
233
+ // the same unsafePlatformId() escape automation/field refs already use,
234
+ // so build round-trips it directly instead of misreading it as a named
235
+ // reference; cast past the type system since the field itself is a
236
+ // strict CatalogRef.
232
237
  const entityKind = tool.typeKey === "searchTable" ? "element" : "app";
233
- lines.push(` ${entityKind}: ${quote(tool.target.uuid)} as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
238
+ lines.push(` ${entityKind}: unsafePlatformId(${quote(tool.target.uuid)}) as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
234
239
  }
235
240
  else if (tool.target !== undefined) {
236
241
  // Board issue #42: the target can be a foreign APP or a foreign
@@ -288,6 +293,13 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
288
293
  if (tool.limit !== undefined)
289
294
  lines.push(` limit: ${tool.limit},`);
290
295
  }
296
+ if ((tool.typeKey === "searchAspect" || tool.typeKey === "searchTable") && tool.filterVariables !== undefined && tool.filterVariables.length > 0) {
297
+ lines.push(" filterVariables: [");
298
+ for (const variable of tool.filterVariables) {
299
+ lines.push(` { id: unsafePlatformId(${quote(variable.id)}), name: ${quote(variable.name)}, description: ${quote(variable.description)}, required: ${variable.required} },`);
300
+ }
301
+ lines.push(" ],");
302
+ }
291
303
  if (tool.typeKey === "updateRecord" && tool.handleDescription !== undefined) {
292
304
  lines.push(` handleDescription: ${quote(tool.handleDescription)},`);
293
305
  }