@elementumai/edk 0.13.4 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +4 -2
  2. package/dist-sdk/src/catalog/factories.js +3 -1
  3. package/dist-sdk/src/catalog/from-authoring.d.ts +8 -3
  4. package/dist-sdk/src/catalog/from-authoring.js +21 -8
  5. package/dist-sdk/src/engine/build/context.d.ts +17 -0
  6. package/dist-sdk/src/engine/coverage-gaps.d.ts +10 -0
  7. package/dist-sdk/src/engine/coverage-gaps.js +16 -0
  8. package/dist-sdk/src/engine/pull/context.d.ts +56 -0
  9. package/dist-sdk/src/engine/pull/context.js +8 -0
  10. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +14 -1
  11. package/dist-sdk/src/engine/pull/pulled-roots.js +23 -3
  12. package/dist-sdk/src/engine/pull/ref-only.d.ts +6 -1
  13. package/dist-sdk/src/engine/pull/ref-only.js +4 -1
  14. package/dist-sdk/src/engine/pull/stream-root.d.ts +13 -1
  15. package/dist-sdk/src/engine/pull/stream-root.js +54 -4
  16. package/dist-sdk/src/engine/validation.d.ts +36 -1
  17. package/dist-sdk/src/engine/validation.js +56 -2
  18. package/dist-sdk/src/engine/workspace/loader.d.ts +6 -0
  19. package/dist-sdk/src/engine/workspace/loader.js +87 -2
  20. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -17
  22. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +3 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.js +1 -1
  24. package/dist-sdk/src/entities/agent/build.d.ts +15 -0
  25. package/dist-sdk/src/entities/agent/build.js +139 -16
  26. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -3
  27. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +39 -25
  28. package/dist-sdk/src/entities/agent/module.js +95 -3
  29. package/dist-sdk/src/entities/agent/to-tf.js +6 -4
  30. package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +7 -0
  31. package/dist-sdk/src/entities/agent-evaluation/from-tf.js +14 -5
  32. package/dist-sdk/src/entities/agent-evaluation/module.js +4 -2
  33. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +11 -2
  34. package/dist-sdk/src/entities/agent-tool/from-tf.js +38 -40
  35. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -5
  36. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  37. package/dist-sdk/src/entities/automation/build.d.ts +75 -42
  38. package/dist-sdk/src/entities/automation/build.js +17 -7
  39. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +14 -2
  40. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +9 -0
  41. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +57 -12
  42. package/dist-sdk/src/entities/automation/from-tf.d.ts +51 -0
  43. package/dist-sdk/src/entities/automation/from-tf.js +476 -93
  44. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  45. package/dist-sdk/src/entities/automation/index.js +1 -1
  46. package/dist-sdk/src/entities/automation/module.js +90 -9
  47. package/dist-sdk/src/entities/automation/operators.d.ts +6 -2
  48. package/dist-sdk/src/entities/automation/operators.js +0 -2
  49. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +8 -0
  50. package/dist-sdk/src/entities/automation/task-output-labels.js +11 -0
  51. package/dist-sdk/src/entities/automation/tasks.d.ts +37 -2
  52. package/dist-sdk/src/entities/automation/tasks.js +38 -1
  53. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  54. package/dist-sdk/src/entities/automation/to-tf.js +413 -47
  55. package/dist-sdk/src/entities/chart/to-tf.js +18 -5
  56. package/dist-sdk/src/entities/dashboard/from-tf.js +45 -11
  57. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +5 -3
  58. package/dist-sdk/src/entities/dashboard-widget-order/order.js +6 -4
  59. package/dist-sdk/src/entities/datamine/from-tf.js +10 -3
  60. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +9 -2
  61. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +35 -7
  62. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +63 -7
  63. package/dist-sdk/src/entities/element/build.d.ts +4 -1
  64. package/dist-sdk/src/entities/element/build.js +3 -4
  65. package/dist-sdk/src/entities/field/from-tf.js +8 -1
  66. package/dist-sdk/src/entities/field/to-tf.d.ts +29 -2
  67. package/dist-sdk/src/entities/field/to-tf.js +106 -7
  68. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +7 -0
  69. package/dist-sdk/src/entities/phone-service/from-tf.js +15 -7
  70. package/dist-sdk/src/entities/phone-service/module.js +4 -2
  71. package/dist-sdk/src/entities/portal/to-tf.d.ts +1 -1
  72. package/dist-sdk/src/entities/portal/to-tf.js +61 -2
  73. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -1
  74. package/dist-sdk/src/entities/relationship/from-tf.js +34 -4
  75. package/dist-sdk/src/entities/relationship/to-tf.js +24 -6
  76. package/dist-sdk/src/entities/role/from-tf.js +3 -1
  77. package/dist-sdk/src/entities/search-table/from-tf.d.ts +3 -1
  78. package/dist-sdk/src/entities/search-table/from-tf.js +6 -3
  79. package/dist-sdk/src/entities/search-table/module.js +18 -2
  80. package/dist-sdk/src/entities/search-table/to-tf.js +10 -16
  81. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +6 -1
  82. package/dist-sdk/src/entities/shared/filters/index.d.ts +6 -1
  83. package/dist-sdk/src/entities/shared/filters/index.js +8 -2
  84. package/dist-sdk/src/entities/shared/filters/print.js +18 -7
  85. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +11 -0
  86. package/dist-sdk/src/entities/shared/filters/tf-codec.js +24 -2
  87. package/dist-sdk/src/entities/shared/run-automation-requirement.d.ts +15 -0
  88. package/dist-sdk/src/entities/shared/run-automation-requirement.js +28 -0
  89. package/dist-sdk/src/entities/shared/search-table-address.d.ts +17 -0
  90. package/dist-sdk/src/entities/shared/search-table-address.js +24 -0
  91. package/dist-sdk/src/entities/shared/skip-release.d.ts +49 -0
  92. package/dist-sdk/src/entities/shared/skip-release.js +74 -0
  93. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -3
  94. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +11 -5
  95. package/dist-sdk/src/entities/skill/module.js +3 -25
  96. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +4 -2
  97. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -27
  98. package/dist-sdk/src/entities/skill-tool/to-tf.js +12 -5
  99. package/dist-sdk/src/entities/skill-tool/types.d.ts +1 -0
  100. package/dist-sdk/src/entities/skill-tool/types.js +2 -1
  101. package/dist-sdk/src/entities/table/catalog.d.ts +16 -0
  102. package/dist-sdk/src/entities/table/catalog.js +44 -2
  103. package/dist-sdk/src/entities/table/from-tf.js +30 -4
  104. package/dist-sdk/src/entities/table/keys.d.ts +27 -0
  105. package/dist-sdk/src/entities/table/keys.js +46 -0
  106. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  107. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +12 -1
  108. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +9 -4
  109. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +215 -10
  110. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +10 -4
  111. package/dist-sdk/src/entities/view/custom-view-runtime-rules.d.ts +43 -0
  112. package/dist-sdk/src/entities/view/custom-view-runtime-rules.js +285 -0
  113. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +3 -1
  114. package/dist-sdk/src/entities/view/custom-view-validate.js +24 -5
  115. package/dist-sdk/src/entities/view/from-tf.js +14 -1
  116. package/dist-sdk/src/entities/widget/from-tf.js +14 -7
  117. package/dist-sdk/src/entities/widget/to-tf.js +7 -5
  118. package/dist-sdk/src/graph/index.d.ts +14 -1
  119. package/dist-sdk/src/graph/index.js +2 -0
  120. package/dist-sdk/src/graph/resource-types.d.ts +2 -0
  121. package/dist-sdk/src/graph/resource-types.js +3 -0
  122. package/dist-sdk/src/graph/types.d.ts +82 -0
  123. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { workspaceAspectKey, } from "../../engine/build/context.js";
2
2
  import { EntityTfError } from "../../engine/entity.js";
3
3
  import { expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
- import { authoredFieldKeysFromPayload, fieldRefToTfValue, } from "../field/to-tf.js";
4
+ import { fieldRefToTfValue, siblingFieldOwnership, } from "../field/to-tf.js";
5
5
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
6
6
  import { optionSelectionLiteral, optionsLocalName } from "../shared/filters/option-lookups.js";
7
7
  import { isUnsafePlatformId } from "../../core/platform-id.js";
@@ -26,7 +26,13 @@ function datasourceId(ref, opts, where) {
26
26
  id: expr.resourceAttr(type, local.tfLabel, ["id"]),
27
27
  tfLabel: local.tfLabel,
28
28
  local: true,
29
- fieldOwnership: authoredFieldKeysFromPayload(local.streamRootEntity?.payload),
29
+ // The address each field's own build gives it, whatever type the
30
+ // reference carries (#3088). Only app and element datasources need it:
31
+ // a table exposes columns, not fields, and `fieldId` resolves a field
32
+ // of a task datasource through a lookup, not the task's field resources.
33
+ fieldOwnership: kind === "app" || kind === "element"
34
+ ? siblingFieldOwnership(local.streamRootEntity?.payload, local.tfLabel, kind)
35
+ : undefined,
30
36
  };
31
37
  }
32
38
  const name = ref.name ?? ref.refName;
@@ -43,7 +49,12 @@ function datasourceId(ref, opts, where) {
43
49
  return { ref, kind, id: expr.dataAttr(type, label, ["id"]), tfLabel: label, local: false };
44
50
  }
45
51
  function fieldId(ref, datasource, opts, where) {
46
- if (ref?.refName === undefined || ref.refName === "")
52
+ if (ref === undefined) {
53
+ // Usually a catalog key the column's table or app no longer has, e.g. a
54
+ // chart pulled before its table's column keys changed (#3063).
55
+ throw new EntityTfError(`${where}: the field is undefined, so it names a catalog key its table or app does not have (pull the chart's app or dashboard again, or fix the key)`);
56
+ }
57
+ if (ref.refName === undefined || ref.refName === "")
47
58
  throw new EntityTfError(`${where}: field ref is missing its key`);
48
59
  if (ref.parent !== undefined && ref.parent !== datasource.ref.refName) {
49
60
  throw new EntityTfError(`${where}: field belongs to ${JSON.stringify(ref.parent)}, not datasource ${JSON.stringify(datasource.ref.refName)}`);
@@ -60,7 +71,7 @@ function fieldId(ref, datasource, opts, where) {
60
71
  throw new EntityTfError(`${where}: app/element fields cannot belong to a table datasource`);
61
72
  if (datasource.local && datasource.ref.__kind !== "task") {
62
73
  const scope = datasource.ref.__kind === "element" ? "element" : "app";
63
- const direct = fieldRefToTfValue(ref.fieldType ?? "", ref.refName, datasource.tfLabel, scope, datasource.fieldOwnership);
74
+ const direct = fieldRefToTfValue(ref.fieldType ?? "", ref.refName, datasource.tfLabel, scope, datasource.fieldOwnership, undefined, ref.name);
64
75
  if (direct !== undefined)
65
76
  return direct;
66
77
  }
@@ -70,7 +81,9 @@ function fieldId(ref, datasource, opts, where) {
70
81
  }
71
82
  function columnToTf(column, datasource, opts, where) {
72
83
  const out = {};
73
- if (column.field !== undefined)
84
+ // A `field` that is present but undefined is a stale catalog key, not an
85
+ // unbound column: dropping it would unbind the live chart column (#3063).
86
+ if (column.field !== undefined || Object.hasOwn(column, "field"))
74
87
  out["column_id"] = fieldId(column.field, datasource, opts, `${where}.field`);
75
88
  if (column.aggregation !== undefined)
76
89
  out["aggregation"] = column.aggregation;
@@ -12,6 +12,7 @@ import { chartRefNameFromTfLabel } from "../chart/from-tf.js";
12
12
  import { dashboardWidgetSize } from "./build.js";
13
13
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
14
14
  import { managedViewSortFromTf } from "../view/from-tf.js";
15
+ import { skipAndRelease, unresolvedReferenceName } from "../shared/skip-release.js";
15
16
  const KNOWN_DASHBOARD_ATTRS = new Set(["name", "owner_id", "owner_type", "favorite", "tags"]);
16
17
  export function dashboardsFromTf(blocks, widgetBlocks, owner, ctx,
17
18
  /** `elementum_dashboard_widget_order` blocks; each orders its dashboard's widgets. */
@@ -67,8 +68,11 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
67
68
  const key = tfLabelToTsLabel(label.startsWith(`${dashboardLabel}_`) ? label.slice(dashboardLabel.length + 1) : label);
68
69
  const name = optionalString(block.attrs, "name", where, ctx) ?? "";
69
70
  const size = optionalString(block.attrs, "size", where, ctx) ?? "MEDIUM";
71
+ // A widget written to no source is also left out of adoption, or the
72
+ // next plan destroys it (edk#3166); skipAndRelease does both.
73
+ const address = `${DASHBOARD_WIDGET_RESOURCE_TYPE}.${label}`;
70
74
  if (!Object.values(dashboardWidgetSize).includes(size)) {
71
- ctx.diagnostics.push(`${where}.size: unsupported dashboard widget size ${JSON.stringify(size)}; skipped`);
75
+ skipAndRelease(ctx, address, { problem: `its size ${JSON.stringify(size)} is not a dashboard widget size` }, `${where}.size: unsupported dashboard widget size ${JSON.stringify(size)}; skipped`);
72
76
  return [];
73
77
  }
74
78
  const color = optionalString(block.attrs, "color", where, ctx);
@@ -77,7 +81,6 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
77
81
  const style = { key, name, size, ...(color !== undefined && { color }), ...(icon !== undefined && { icon }) };
78
82
  const chart = plainObject(block.attrs["chart_widget"]);
79
83
  if (chart !== undefined) {
80
- const address = `${DASHBOARD_WIDGET_RESOURCE_TYPE}.${label}`;
81
84
  const chartLabel = resourceRefLabel(chart["chart_id"], CHART_RESOURCE_TYPE);
82
85
  if (chartLabel === undefined) {
83
86
  // A raw chart id or a data.elementum_chart ref names no chart this
@@ -106,12 +109,14 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
106
109
  return [{ ...style, type: "chart", chartKey }];
107
110
  }
108
111
  if (aspect === undefined) {
109
- ctx.diagnostics.push(`${where}: expected an aspect_widget or chart_widget; skipped`);
112
+ skipAndRelease(ctx, address, { problem: "the export gives it neither an aspect_widget nor a chart_widget" }, `${where}: expected an aspect_widget or chart_widget; skipped`);
110
113
  return [];
111
114
  }
112
115
  const target = aspectRef(aspect["aspect_id"], owner, ctx);
113
116
  if (target === undefined) {
114
- ctx.diagnostics.push(`${where}.aspect_widget.aspect_id: unresolved; skipped`);
117
+ // For example a task-type app's records: a records widget has no
118
+ // target for it yet.
119
+ skipAndRelease(ctx, address, { reference: unresolvedReferenceName(aspect["aspect_id"], "aspect_id") }, `${where}.aspect_widget.aspect_id: unresolved; skipped`);
115
120
  return [];
116
121
  }
117
122
  // An unsupported sort is dropped on its own: skipping the widget would
@@ -142,26 +147,55 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
142
147
  /**
143
148
  * The order's import lists every chart and records widget of the dashboard,
144
149
  * but build lists only the widgets source holds. A widget this pull leaves out
145
- * would therefore plan a reorder no source edit asked for, so the order is
146
- * skipped and released with it. It runs after the widgets' own requirements,
147
- * so a chart widget skipped for its chart takes the order along. The next
148
- * plan imports the order for the widgets source holds (the kind's
149
- * stateAdoption), so it plans no change.
150
+ * would therefore plan a reorder no source edit asked for. The order stays in
151
+ * source and adoption without it: adoption drops it from the export's
152
+ * `widget_ids` and imports the order as `<owner id>:<dashboard id>:<ids of the
153
+ * widgets left in>`, which tracks only those widgets (the provider's tracked
154
+ * import, also used by the kind's stateAdoption), so the next plan shows no
155
+ * change. It runs after the widgets' own requirements, so a chart widget
156
+ * skipped for its chart is left out of the order too. With no widget left,
157
+ * build writes no order, so it is skipped and released.
150
158
  */
151
159
  function requireEveryWidget(order, widgetBlocks, written, dashboardLabel, ctx) {
152
160
  if (ctx.requiresExtracted === undefined)
153
161
  return;
154
162
  const address = `${DASHBOARD_WIDGET_ORDER_RESOURCE_TYPE}.${order.label ?? ""}`;
155
163
  const writtenKeys = new Set(written.map((widget) => widget.key));
164
+ const listEntry = { attribute: "widget_ids", trackedWithout: (leftOut) => trackedOrderImport(order, address, leftOut, ctx) };
156
165
  for (const block of widgetBlocks) {
157
166
  const label = block.label ?? "";
158
167
  const key = tfLabelToTsLabel(label.startsWith(`${dashboardLabel}_`) ? label.slice(dashboardLabel.length + 1) : label);
159
168
  const requires = `${DASHBOARD_WIDGET_RESOURCE_TYPE}.${label}`;
160
169
  ctx.requiresExtracted.push(writtenKeys.has(key)
161
- ? { address, requires, prune: (root) => root }
162
- : { address, requires, unresolved: true, prune: (root) => root });
170
+ ? { address, requires, listEntry, prune: (root) => root }
171
+ : { address, requires, unresolved: true, listEntry, prune: (root) => root });
163
172
  }
164
173
  }
174
+ /**
175
+ * The order's tracked import without the `leftOut` widgets: its id and the
176
+ * widget ids it tracks, in the order's live widget order. Undefined when no
177
+ * widget is left or an id is unknown.
178
+ */
179
+ function trackedOrderImport(order, address, leftOut, ctx) {
180
+ const orderId = ctx.importId(address);
181
+ const widgetIds = order.attrs["widget_ids"];
182
+ if (orderId === undefined || orderId.split(":").length !== 2 || !Array.isArray(widgetIds))
183
+ return undefined;
184
+ const kept = [];
185
+ for (const value of widgetIds) {
186
+ const label = resourceRefLabel(value, DASHBOARD_WIDGET_RESOURCE_TYPE);
187
+ if (label === undefined)
188
+ return undefined;
189
+ const widget = `${DASHBOARD_WIDGET_RESOURCE_TYPE}.${label}`;
190
+ if (leftOut.has(widget))
191
+ continue;
192
+ const id = ctx.importId(widget)?.split(":").at(-1);
193
+ if (id === undefined || id === "")
194
+ return undefined;
195
+ kept.push(id);
196
+ }
197
+ return kept.length === 0 ? undefined : { importId: `${orderId}:${kept.join(",")}`, keptIds: kept };
198
+ }
165
199
  /**
166
200
  * The filter ranges over the target's records, so its fields may belong to
167
201
  * the target rather than to the dashboard's owner. A raw field id decodes
@@ -19,9 +19,11 @@ export declare function dashboardWidgetOrderFor(orderBlocks: readonly TfBlock[],
19
19
  export declare function inDashboardWidgetOrder(widgetBlocks: readonly TfBlock[], orderBlock: TfBlock | undefined): readonly TfBlock[];
20
20
  /**
21
21
  * A dashboard whose order has no state would plan a hidden create (a live
22
- * reorder): a workspace pulled before widget order was managed, or a pull that
23
- * left one of the dashboard's widgets out of source and released the order
24
- * with it. When the dashboard is in state but its order isn't, import the live
22
+ * reorder): a workspace pulled before widget order was managed, or by a pull
23
+ * that left one of the dashboard's widgets out of source and released the
24
+ * order with it (before #3071; a pull now adopts the order for the widgets
25
+ * source holds, the same import as below). When the dashboard is in state but
26
+ * its order isn't, import the live
25
27
  * order, keyed `<owner id>:<dashboard id>:<widget ids>` with the ids of the
26
28
  * widgets build lists that state already holds. The provider then tracks only
27
29
  * those widgets, so a widget source doesn't hold never shows as a change, and
@@ -54,9 +54,11 @@ export function inDashboardWidgetOrder(widgetBlocks, orderBlock) {
54
54
  }
55
55
  /**
56
56
  * A dashboard whose order has no state would plan a hidden create (a live
57
- * reorder): a workspace pulled before widget order was managed, or a pull that
58
- * left one of the dashboard's widgets out of source and released the order
59
- * with it. When the dashboard is in state but its order isn't, import the live
57
+ * reorder): a workspace pulled before widget order was managed, or by a pull
58
+ * that left one of the dashboard's widgets out of source and released the
59
+ * order with it (before #3071; a pull now adopts the order for the widgets
60
+ * source holds, the same import as below). When the dashboard is in state but
61
+ * its order isn't, import the live
60
62
  * order, keyed `<owner id>:<dashboard id>:<widget ids>` with the ids of the
61
63
  * widgets build lists that state already holds. The provider then tracks only
62
64
  * those widgets, so a widget source doesn't hold never shows as a change, and
@@ -95,7 +97,7 @@ export const dashboardWidgetOrderStateAdoption = {
95
97
  const names = imports.slice(0, 5).map((i) => i.label).join(", ");
96
98
  const more = imports.length > 5 ? `, … (+${imports.length - 5} more)` : "";
97
99
  return [
98
- `${imports.length} dashboard(s) have no ${DASHBOARD_WIDGET_ORDER_RESOURCE_TYPE} state (a workspace pulled before widget order was managed, or a pull that left one of the dashboard's widgets out): ${names}${more}.`,
100
+ `${imports.length} dashboard(s) have no ${DASHBOARD_WIDGET_ORDER_RESOURCE_TYPE} state (a workspace pulled before widget order was managed, or an earlier pull that left one of the dashboard's widgets out): ${names}${more}.`,
99
101
  "Importing their live widget order for the widgets in source; a widget_ids change in the plan reorders the dashboard to match the widgets' order in source.",
100
102
  ].join("\n");
101
103
  },
@@ -2,7 +2,9 @@ import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../
2
2
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
3
3
  import { EntityTfError } from "../../engine/entity.js";
4
4
  import { isTfExpr, snakeSlug, tfLabelToTsLabel } from "../../engine/tf/index.js";
5
+ import { tableColumnKey as tableColumnCatalogKey } from "../table/keys.js";
5
6
  import { filterFromTf } from "../shared/filters/tf-codec.js";
7
+ import { skipAndRelease } from "../shared/skip-release.js";
6
8
  const KNOWN_DATAMINE_ATTRS = new Set([
7
9
  "id",
8
10
  "table_id",
@@ -36,8 +38,11 @@ export function tableDataminesFromTf(blocks, tableTfLabel, columnKeyByName, ctx,
36
38
  }
37
39
  const rawNames = block.attrs["primary_column_names"];
38
40
  const rawIDs = block.attrs["primary_column_ids"];
41
+ // A datamine written to no source is also left out of adoption, or
42
+ // released if state has it, so the next plan doesn't destroy it (edk#3172).
43
+ const address = `elementum_datamine.${label}`;
39
44
  if (!Array.isArray(rawNames) && !Array.isArray(rawIDs)) {
40
- ctx.diagnostics.push(`${where}: expected primary_column_names or primary_column_ids; skipped`);
45
+ skipAndRelease(ctx, address, { problem: "the export gives it neither primary_column_names nor primary_column_ids" }, `${where}: expected primary_column_names or primary_column_ids; skipped`);
41
46
  return [];
42
47
  }
43
48
  const rawColumns = Array.isArray(rawNames) ? rawNames : rawIDs;
@@ -47,7 +52,9 @@ export function tableDataminesFromTf(blocks, tableTfLabel, columnKeyByName, ctx,
47
52
  return key === undefined ? [] : [key];
48
53
  });
49
54
  if (primaryColumns.length !== rawColumns.length) {
50
- ctx.diagnostics.push(`${where}.${Array.isArray(rawNames) ? "primary_column_names" : "primary_column_ids"}: one or more columns could not be resolved to this table; skipped`);
55
+ const attribute = Array.isArray(rawNames) ? "primary_column_names" : "primary_column_ids";
56
+ const unresolved = rawColumns.filter((value) => typeof value !== "string" || !lookup.has(value)).map((value) => JSON.stringify(value));
57
+ skipAndRelease(ctx, address, { problem: `${unresolved.length === 1 ? `its primary column ${unresolved[0]} is not a column` : `its primary columns ${unresolved.join(", ")} are not columns`} of this table that pull extracted` }, `${where}.${attribute}: one or more columns could not be resolved to this table; skipped`);
51
58
  return [];
52
59
  }
53
60
  const fixed = plainObject(block.attrs["schedule_fixed"]);
@@ -90,7 +97,7 @@ function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, ctx
90
97
  const name = typeof index === "object" && index !== null && "index" in index && typeof index.index === "string"
91
98
  ? index.index
92
99
  : typeof index === "string" ? index : undefined;
93
- const key = name === undefined ? undefined : columnKeyByName.get(name) ?? tfLabelToTsLabel(name);
100
+ const key = name === undefined ? undefined : columnKeyByName.get(name) ?? tableColumnCatalogKey(name);
94
101
  if (key !== undefined)
95
102
  return key;
96
103
  }
@@ -257,8 +257,15 @@ export type DynamicLayoutComparison<Value = DynamicLayoutTypedValue> = {
257
257
  };
258
258
  /** `equals` / `notEquals`: a typed value, the viewer, or the viewer's groups. */
259
259
  export type DynamicLayoutEqualityComparison = DynamicLayoutComparison<ExactlyOneVariant<Pick<DynamicLayoutValueMap, "string" | "number" | "boolean" | "strings" | "currentUser" | "currentUserGroups">>>;
260
- /** `in` / `notIn`: a list of strings, or the viewer's groups (the provider accepts nothing else). */
261
- export type DynamicLayoutMembershipComparison = DynamicLayoutComparison<ExactlyOneVariant<Pick<DynamicLayoutValueMap, "strings" | "currentUserGroups">>>;
260
+ /**
261
+ * `in` / `notIn`: a list of strings, a single value, or the viewer's groups.
262
+ * The layout editor stores a single value when it shows a plain input for
263
+ * the field (any field but a Dropdown or Multi-Select with options). The
264
+ * record page treats a single string as a one-item list, but not a single
265
+ * number or boolean (`in` never matches, `notIn` always does), so build warns
266
+ * about those; use `equals` / `notEquals` (lists hold strings only).
267
+ */
268
+ export type DynamicLayoutMembershipComparison = DynamicLayoutComparison<ExactlyOneVariant<Pick<DynamicLayoutValueMap, "string" | "number" | "boolean" | "strings" | "currentUserGroups">>>;
262
269
  interface DynamicLayoutConditionVariantMap<ConditionKey extends string> {
263
270
  readonly equals: DynamicLayoutEqualityComparison;
264
271
  readonly notEquals: DynamicLayoutEqualityComparison;
@@ -5,11 +5,12 @@ import { filterFromTf } from "../access-policy/from-tf.js";
5
5
  import { elementAuditFieldReference, fieldKeyFromTfValue } from "../field/from-tf.js";
6
6
  import { omittedAutomationKey } from "../automation/omitted-ref.js";
7
7
  import { filterOwnerForAspect } from "../relationship/from-tf.js";
8
- import { filterWireToTf } from "../shared/filters/tf-codec.js";
8
+ import { filterWireToTf, UnauthorableFilterValueError } from "../shared/filters/tf-codec.js";
9
9
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
10
10
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
11
11
  import { lostStageMessage, pulledStageHandle } from "../app/stage-keys.js";
12
12
  import { unextractedFieldRefId } from "../view/from-tf.js";
13
+ import { skipAndRelease } from "../shared/skip-release.js";
13
14
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
14
15
  import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY, dynamicLayoutCompanionWidgetLabel, } from "./dialect.js";
15
16
  const KNOWN_ATTRS = new Set([
@@ -69,7 +70,8 @@ function dynamicLayoutFromTf(block, owner, ctx) {
69
70
  }
70
71
  const componentsRaw = plainObject(block.attrs["components"]);
71
72
  if (componentsRaw === undefined) {
72
- ctx.diagnostics.push(`${where}: components is not an object; skipped`);
73
+ // Written to no source, so also left out of adoption (edk#3172).
74
+ skipAndRelease(ctx, `${DYNAMIC_LAYOUT_RESOURCE_TYPE}.${block.label ?? ""}`, { problem: "its components is not an object" }, `${where}: components is not an object; skipped`);
73
75
  return undefined;
74
76
  }
75
77
  // A stage reference whose only handle is another stage's own key would
@@ -355,6 +357,7 @@ function relatedItemsBlock(block, owner, ctx, where) {
355
357
  // A raw field id decodes without throwing even when it is not the owner's
356
358
  // field, so a decode that leaves one unresolved is only a fallback.
357
359
  let failure;
360
+ let unauthorable;
358
361
  let partial;
359
362
  for (const filterOwner of filterOwners) {
360
363
  try {
@@ -367,8 +370,22 @@ function relatedItemsBlock(block, owner, ctx, where) {
367
370
  }
368
371
  catch (error) {
369
372
  failure ??= error;
373
+ if (error instanceof UnauthorableFilterValueError)
374
+ unauthorable ??= error;
370
375
  }
371
376
  }
377
+ // A value source can't hold (a field value's aspect) fails the pull: the
378
+ // drop below would write the block without its filter, and the next apply
379
+ // would remove the live filter (#3144). Other undecodable filters keep
380
+ // the drop rule.
381
+ if (unauthorable !== undefined) {
382
+ reportAuthoringBlocker(ctx, {
383
+ address: where.split(".").slice(0, 2).join("."),
384
+ description: `${unauthorable.message}, so the related-items block can't be written to source with its filter`,
385
+ remedy: "Remove the app or element restriction from that field comparison in the layout editor and pull again; if the layout keeps holding it, report it to the EDK maintainers.",
386
+ });
387
+ return;
388
+ }
372
389
  if (partial !== undefined) {
373
390
  block["filter"] = partial;
374
391
  return;
@@ -397,6 +414,15 @@ function decodeJson(value) {
397
414
  }
398
415
  return value;
399
416
  }
417
+ /** The label of an option reference (`local.<field>_options_by_label["<label>"]`), or undefined. */
418
+ function optionLabel(value) {
419
+ if (value === undefined || !isTfExpr(value) || value.$expr !== "local")
420
+ return undefined;
421
+ const segment = value.path[0];
422
+ return value.path.length === 1 && typeof segment === "object" && segment !== null && "index" in segment && typeof segment.index === "string"
423
+ ? segment.index
424
+ : undefined;
425
+ }
400
426
  function conditionMap(values, owner, ctx, where) {
401
427
  const out = {};
402
428
  for (const [id, raw] of Object.entries(values)) {
@@ -408,11 +434,13 @@ function conditionMap(values, owner, ctx, where) {
408
434
  comparison["field"] = fieldKey(comparison["fieldId"], owner, ctx, `${where}.conditions.${id}.${key}`, `${where}.conditions.${id}`);
409
435
  delete comparison["fieldId"];
410
436
  const value = plainUnknownObject(comparison["value"]);
411
- const stringValue = value?.["string"];
412
- if (value !== undefined && stringValue !== undefined && isTfExpr(stringValue) && stringValue.$expr === "local") {
413
- const segment = stringValue.path[0];
414
- if (stringValue.path.length === 1 && typeof segment === "object" && segment !== null && "index" in segment) {
415
- value["string"] = segment.index;
437
+ if (value !== undefined) {
438
+ const label = optionLabel(value["string"]);
439
+ if (label !== undefined)
440
+ value["string"] = label;
441
+ // A Multi-Select condition's list of options (edk#3044).
442
+ if (Array.isArray(value["strings"])) {
443
+ value["strings"] = value["strings"].map((item) => optionLabel(item) ?? item);
416
444
  }
417
445
  }
418
446
  }
@@ -661,7 +661,9 @@ function conditionMap(conditions, where, opts) {
661
661
  comparison["field_id"] = field;
662
662
  if (rec["value"] !== undefined) {
663
663
  checkViewerValue(key, rec["value"], rec["field"], `${where}.conditions.${conditionId}.${key}`, opts);
664
- comparison["value"] = typedValue(rec["value"], rec["field"], opts);
664
+ checkMembershipValue(key, rec["value"], `${where}.conditions.${conditionId}.${key}`, opts);
665
+ checkContainsList(key, rec["value"], `${where}.conditions.${conditionId}.${key}`, opts);
666
+ comparison["value"] = typedValue(rec["value"], rec["field"], `${where}.conditions.${conditionId}.${key}`, opts);
665
667
  }
666
668
  attrs[snakeKey(key)] = comparison;
667
669
  }
@@ -760,6 +762,38 @@ const VIEWER_VALUE_RULES = {
760
762
  currentUser: { operators: new Set(["equals", "notEquals"]), fieldTypes: new Set(["USER", "USER_ID"]), label: "a user field" },
761
763
  currentUserGroups: { operators: new Set(["equals", "notEquals", "in", "notIn"]), fieldTypes: new Set(["GROUP", "GROUP_ID"]), label: "a group field" },
762
764
  };
765
+ /**
766
+ * The layout editor stores a single value for `in` / `notIn` when it shows a
767
+ * plain input (edk#3043), and the provider reads it, but the record page only
768
+ * treats a string or a list as "one of": a single number or boolean never
769
+ * matches `in` and always matches `notIn`. Build keeps it as written, so a
770
+ * pulled layout round-trips, and says so.
771
+ */
772
+ function checkMembershipValue(operator, value, where, opts) {
773
+ if (operator !== "in" && operator !== "notIn")
774
+ return;
775
+ const rec = object(value);
776
+ const kind = typeof rec["number"] === "number" ? "number" : typeof rec["boolean"] === "boolean" ? "boolean" : undefined;
777
+ if (kind === undefined)
778
+ return;
779
+ const effect = operator === "in" ? "never matches" : "always matches";
780
+ const instead = operator === "in" ? "equals (any of several equals for more values)" : "notEquals (all of several notEquals for more values)";
781
+ opts.diagnostics.push(`${where}: the record page reads only a string or a list as "one of", so ${operator} with a single ${kind} ${effect}; use ${instead}`);
782
+ }
783
+ /**
784
+ * The layout editor stores a list for `contains` / `notContains` on a
785
+ * Multi-Select field (edk#3044), and the provider reads it, but the record
786
+ * page compares each selected option with the whole list, so `contains`
787
+ * never matches and `notContains` always does. Build keeps it as written, so
788
+ * a pulled layout round-trips, and says so.
789
+ */
790
+ function checkContainsList(operator, value, where, opts) {
791
+ if ((operator !== "contains" && operator !== "notContains") || !Array.isArray(object(value)["strings"]))
792
+ return;
793
+ const effect = operator === "contains" ? "never matches" : "always matches";
794
+ const instead = operator === "contains" ? "in" : "notIn";
795
+ opts.diagnostics.push(`${where}: the record page compares each option with the whole list, so ${operator} with a list ${effect}; use ${instead}`);
796
+ }
763
797
  function checkViewerValue(operator, value, fieldValue, where, opts) {
764
798
  const rec = object(value);
765
799
  for (const [marker, rule] of Object.entries(VIEWER_VALUE_RULES)) {
@@ -782,17 +816,39 @@ function checkViewerValue(operator, value, fieldValue, where, opts) {
782
816
  }
783
817
  }
784
818
  }
785
- function typedValue(value, fieldValue, opts) {
819
+ function typedValue(value, fieldValue, where, opts) {
786
820
  const rec = object(value);
787
821
  const token = fieldValue;
788
- if (typeof rec["string"] === "string" && token?.options?.includes(rec["string"])) {
789
- const childPart = tsLabelToTfLabel(token.resourceKey ?? token.refName ?? "");
790
- const localName = token.tags?.includes("STATUS")
822
+ // On a field with options the value is option labels; anything else is
823
+ // built as written and compares that text, which no record ever holds (a
824
+ // typo, or the id of a deleted option).
825
+ const options = token?.options;
826
+ if (options !== undefined) {
827
+ const items = typeof rec["string"] === "string" ? [rec["string"]] : Array.isArray(rec["strings"]) ? rec["strings"] : [];
828
+ const unknown = items.filter((item) => typeof item === "string" && !options.includes(item));
829
+ if (unknown.length > 0) {
830
+ opts.diagnostics.push(`${where}: ${unknown.map((item) => JSON.stringify(item)).join(", ")} ${unknown.length === 1 ? "is not an option" : "are not options"} of this field; built as written, no record ever holds that value (equals / in never match it; notEquals / notIn always do)`);
831
+ }
832
+ }
833
+ const option = (label) => {
834
+ const childPart = tsLabelToTfLabel(token?.resourceKey ?? token?.refName ?? "");
835
+ const localName = token?.tags?.includes("STATUS")
791
836
  ? `${opts.ownerTfLabel}_status_options_by_label`
792
- : token.tags?.includes("STAGE")
837
+ : token?.tags?.includes("STAGE")
793
838
  ? `${opts.ownerTfLabel}_stage_options_by_label`
794
839
  : `${scopedResourceLabel(opts.ownerTfLabel, childPart, scopeOf(opts))}_options_by_label`;
795
- return { string: expr.local(localName, [{ index: rec["string"] }]) };
840
+ return expr.local(localName, [{ index: label }]);
841
+ };
842
+ if (typeof rec["string"] === "string" && token?.options?.includes(rec["string"])) {
843
+ return { string: option(rec["string"]) };
844
+ }
845
+ // A Multi-Select condition stores a list of options (edk#3044); each label
846
+ // resolves like a single option, and anything else is written as it is.
847
+ const strings = rec["strings"];
848
+ if (Array.isArray(strings) && token?.options !== undefined && strings.some((item) => typeof item === "string" && token.options.includes(item))) {
849
+ return {
850
+ strings: strings.map((item) => typeof item === "string" && token.options.includes(item) ? option(item) : item),
851
+ };
796
852
  }
797
853
  return snakeObject(rec, "dynamic layout typed value", opts);
798
854
  }
@@ -78,7 +78,10 @@ interface ElementV2OptionsBase<F extends Record<string, AppField> = Record<strin
78
78
  readonly commentsEnabled?: boolean;
79
79
  /** Automatic record sharing toggles. Omit to leave the platform setting untouched. */
80
80
  readonly autoShare?: AutoShareOptions;
81
- /** Fields keyed by ref name. At least one required by the compose API. */
81
+ /**
82
+ * Custom fields keyed by ref name. May be empty (`fields: {}`): the
83
+ * platform always makes the element's ID and Title fields itself.
84
+ */
82
85
  readonly fields: F;
83
86
  /**
84
87
  * Overrides for the platform's auto-provisioned `id`/`title` fields.
@@ -45,11 +45,10 @@ function serializeElementSystemFields(overrides) {
45
45
  }
46
46
  /** Build a v2 element entity: org-owned, compose-body payload. Exposes `.ref(refName)` and `.def(refName)`. */
47
47
  export function element(opts) {
48
+ // No "at least one field" rule: the platform makes every element with its
49
+ // ID and Title fields (the `id`/`title` system keys), and an element can
50
+ // keep only those, as the web app's Create New Element leaves it (#2817).
48
51
  validateElementOptions(opts);
49
- const fieldEntries = Object.values(opts.fields);
50
- if (fieldEntries.length === 0) {
51
- throw new Error(`element "${opts.name}" requires at least one field.`);
52
- }
53
52
  return {
54
53
  ref(refName) {
55
54
  // See `app`'s `ref()` for why `handle` here is the bag key —
@@ -400,7 +400,8 @@ function resolveRelatedField(v, ctx) {
400
400
  const taskAttrs = ctx.dataAttrs?.("elementum_task", objectId.label);
401
401
  const taskName = ctx.dataName("elementum_task", objectId.label) ?? (typeof taskAttrs?.name === "string" ? taskAttrs.name : objectId.label);
402
402
  const taskNamespace = typeof taskAttrs?.namespace === "string" ? taskAttrs.namespace : undefined;
403
- const taskRefName = (taskNamespace !== undefined ? ctx.foreignTaskRefNamespaces?.get(taskNamespace) : undefined) ?? (taskName !== undefined ? ctx.foreignTaskRefNames?.get(taskName) : undefined) ?? tfLabelToTsLabel(objectId.label);
403
+ // The same identity the Dropdown's target resolves to (edk#3146).
404
+ const taskRefName = resolveDataTaskTarget(ctx, objectId.label).key;
404
405
  const fieldName = typeof attrs?.name === "string" ? attrs.name : undefined;
405
406
  const strippedKey = fieldKeyFromForeignDataLabel(v.label, { key: taskRefName, name: taskName, kind: "task" });
406
407
  const fieldKey = strippedKey ?? tfLabelToTsLabel(v.label);
@@ -1259,6 +1260,12 @@ export function decodeForeignDataField(dataLabel, target, ctx) {
1259
1260
  const fieldType = fieldTypeFromRegistry(ctx, target.key, catalogFieldKey);
1260
1261
  return { key: catalogFieldKey, name, ...(fieldType !== undefined ? { fieldType } : {}) };
1261
1262
  }
1263
+ // A renamed Title or ID (#3145) has no field block, so the catalog index
1264
+ // can't name it; the owner's own source keys it `title`/`id`.
1265
+ const systemKey = ctx.renamedSystemFieldKeysByOwnerRefName?.get(target.key)?.get(name.toLowerCase());
1266
+ if (systemKey !== undefined) {
1267
+ return { key: systemKey, name, fieldType: fieldTypeFromRegistry(ctx, target.key, systemKey) ?? (systemKey === "id" ? "HANDLE" : "TEXT") };
1268
+ }
1262
1269
  const stripped = fieldKeyFromForeignDataLabel(dataLabel, { ...target, ownerDataLabel: foreignFieldOwnerDataLabel(dataLabel, ctx) });
1263
1270
  if (stripped !== undefined) {
1264
1271
  const fieldType = fieldTypeFromRegistry(ctx, target.key, stripped);
@@ -25,9 +25,32 @@ import { type PicklistValueWire } from "./options.js";
25
25
  export interface FieldOwnership {
26
26
  has(refName: string): boolean;
27
27
  get?(refName: string): string | undefined;
28
+ /**
29
+ * The system key (`title`/`id`) a reference names by the field's renamed
30
+ * display name rather than its key (#3145), when no authored field claims
31
+ * that name. With the reference's display `name`, that name must equal the
32
+ * renamed one (ignoring case); without it, the ref key is compared by
33
+ * letters and digits.
34
+ */
35
+ systemKey?(refName: string, name?: string): "title" | "id" | undefined;
28
36
  }
29
37
  /** Reconstruct custom-field ownership from a loaded app/element payload. */
30
38
  export declare function authoredFieldKeysFromPayload(payload: unknown): ReadonlySet<string> | undefined;
39
+ /**
40
+ * A workspace sibling's authored fields, each with the resource address its
41
+ * own build gives it (#3075). A reference to another root's field carries the
42
+ * type the export reported for it, which isn't always the type the owner
43
+ * declares: a pulled ref to another element's User field says `USER_ID`, a
44
+ * Calculated field says its result type. Building the address from that type
45
+ * names a resource the owner doesn't declare, or none at all, and the two
46
+ * sides of a relationship stop naming the same field.
47
+ *
48
+ * An element's STATUS dropdown counts too: it is system-tagged, so
49
+ * {@link authoredFieldKeysFromPayload} leaves it out, but the element's build
50
+ * emits it as a dropdown resource (`element/to-tf.ts`) rather than folding it
51
+ * into the element, so the element's own side resolves it to that resource.
52
+ */
53
+ export declare function siblingFieldOwnership(payload: unknown, ownerTfLabel: string, scope: FieldOwnerScope): FieldOwnership | undefined;
31
54
  /** Slim `AppOrElementRef` token shape as it appears in a def() payload (post-`slimTokens`). */
32
55
  interface AspectTokenWire {
33
56
  readonly __kind?: string;
@@ -172,7 +195,9 @@ export interface FieldToTfResult {
172
195
  */
173
196
  export declare function claimFieldDisplayName(seen: Map<string, string>, field: FieldToTfResult): void;
174
197
  export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
175
- export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership, resourceKey?: string): TfExpr | undefined;
198
+ export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership, resourceKey?: string,
199
+ /** The reference's display name, when it carries one: it identifies a sibling's renamed Title/ID (#3145). */
200
+ displayName?: string): TfExpr | undefined;
176
201
  /**
177
202
  * Why build leaves out an entry: its field reference has no field in source
178
203
  * and no platform id (#1966, #1978). The gaps below state what apply then
@@ -193,7 +218,9 @@ export declare function unauthoredSiblingFieldRef(refName: string, sibling: {
193
218
  readonly kind: ChildResourceScope;
194
219
  readonly refName: string;
195
220
  readonly fieldOwnership?: FieldOwnership;
196
- }): string | undefined;
221
+ },
222
+ /** The reference's display name, when it carries one (#3145). */
223
+ displayName?: string): string | undefined;
197
224
  /** A field ref's name, when it has one build can look the field up by. */
198
225
  export declare function fieldLookupName(value: {
199
226
  readonly name?: string;