@elementumai/edk 0.13.0 → 0.13.1

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 (71) hide show
  1. package/README.md +6 -2
  2. package/dist-sdk/src/catalog/factories.js +8 -2
  3. package/dist-sdk/src/catalog/types.d.ts +5 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +4 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +8 -0
  7. package/dist-sdk/src/engine/ei/run.js +46 -7
  8. package/dist-sdk/src/engine/pull/context.d.ts +24 -0
  9. package/dist-sdk/src/engine/pull/stream-root.d.ts +11 -0
  10. package/dist-sdk/src/engine/pull/stream-root.js +22 -6
  11. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  12. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -7
  13. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -1
  14. package/dist-sdk/src/entities/agent/from-tf.d.ts +2 -0
  15. package/dist-sdk/src/entities/agent/from-tf.js +28 -1
  16. package/dist-sdk/src/entities/agent/module.js +1 -0
  17. package/dist-sdk/src/entities/agent/to-tf.d.ts +3 -1
  18. package/dist-sdk/src/entities/agent/to-tf.js +21 -3
  19. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  20. package/dist-sdk/src/entities/app/from-tf.js +6 -23
  21. package/dist-sdk/src/entities/app/module.js +2 -0
  22. package/dist-sdk/src/entities/approval-chain/from-tf.js +2 -2
  23. package/dist-sdk/src/entities/automation/build.d.ts +10 -1
  24. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +1 -0
  25. package/dist-sdk/src/entities/automation/from-tf.js +72 -11
  26. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  27. package/dist-sdk/src/entities/automation/module.js +12 -0
  28. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  29. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  30. package/dist-sdk/src/entities/automation/to-tf.d.ts +5 -1
  31. package/dist-sdk/src/entities/automation/to-tf.js +227 -27
  32. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  33. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  34. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  35. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  36. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  37. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  38. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  39. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  40. package/dist-sdk/src/entities/element/from-tf.js +5 -21
  41. package/dist-sdk/src/entities/element/module.js +2 -0
  42. package/dist-sdk/src/entities/field/from-tf.d.ts +25 -2
  43. package/dist-sdk/src/entities/field/from-tf.js +119 -14
  44. package/dist-sdk/src/entities/relationship/from-tf.js +2 -2
  45. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  46. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  47. package/dist-sdk/src/entities/search-table/build.js +4 -4
  48. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  49. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  50. package/dist-sdk/src/entities/shared/context.d.ts +14 -1
  51. package/dist-sdk/src/entities/shared/filters/index.d.ts +24 -13
  52. package/dist-sdk/src/entities/shared/filters/index.js +12 -1
  53. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  54. package/dist-sdk/src/entities/shared/filters/print.js +15 -6
  55. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +4 -0
  56. package/dist-sdk/src/entities/shared/filters/tf-codec.js +16 -0
  57. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  58. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  59. package/dist-sdk/src/entities/shared/tool-field-ref.js +2 -5
  60. package/dist-sdk/src/entities/task/from-tf.js +3 -3
  61. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +6 -4
  62. package/dist-sdk/src/entities/view/custom-view-validate.js +36 -18
  63. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  64. package/dist-sdk/src/entities/view/to-tf.js +66 -47
  65. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  66. package/dist-sdk/src/entities/widget/from-tf.js +6 -6
  67. package/dist-sdk/src/graph/index.d.ts +4 -0
  68. package/dist-sdk/src/graph/index.js +1 -0
  69. package/dist-sdk/src/graph/modules.js +2 -0
  70. package/dist-sdk/src/graph/types.d.ts +36 -1
  71. package/package.json +2 -2
@@ -11,18 +11,22 @@ export function printFilter(filter, codec) {
11
11
  const literals = "value" in filter ? [filter.value]
12
12
  : "values" in filter ? filter.values
13
13
  : "min" in filter ? [filter.min, filter.max] : [];
14
- const uuidValues = literals.length > 0 && literals.every((literal) => literal.type === "UUID");
14
+ const uuidValues = literals.length > 0 && literals.every((literal) => literal.type === "UUID" || (literal.type === "USER" && literal.valueType === "UUID"));
15
15
  const explicitType = uuidValues ? `, ${quote("UUID")}` : "";
16
16
  const impliedLiteralType = stringLiteralTypeImpliedBy(filter, uuidValues);
17
17
  // An option selection prints as `filter.textOption(label)` whatever the
18
18
  // left side implies: a bare or wrapped TEXT literal builds as a raw word (#1733).
19
19
  const value = (input) => input.type === "TEXT" && input.option === true
20
20
  ? printFilterValue(input, codec, call, quote)
21
- : input.type === "UUID"
22
- ? uuidValues ? quote(input.value) : `{ type: "UUID", value: ${quote(input.value)} }`
23
- : (input.type === "TEXT" || input.type === "DATE" || input.type === "DATETIME") && impliedLiteralType !== undefined && input.type !== impliedLiteralType
24
- ? `{ type: ${quote(input.type)}, value: ${quote(input.value)} }`
25
- : printFilterValue(input, codec, call, quote);
21
+ // A UUID-wrapped user among other value types would rebuild as TEXT from
22
+ // a bare `userRef(...)`: name the wrapper, as a UUID literal does.
23
+ : input.type === "USER" && input.valueType === "UUID" && !uuidValues
24
+ ? `{ type: "USER", email: ${quote(input.email)}, valueType: "UUID" }`
25
+ : input.type === "UUID"
26
+ ? uuidValues ? quote(input.value) : `{ type: "UUID", value: ${quote(input.value)} }`
27
+ : (input.type === "TEXT" || input.type === "DATE" || input.type === "DATETIME") && impliedLiteralType !== undefined && input.type !== impliedLiteralType
28
+ ? `{ type: ${quote(input.type)}, value: ${quote(input.value)} }`
29
+ : printFilterValue(input, codec, call, quote);
26
30
  if ("leftValue" in filter && filter.leftValue?.type === "FIELD") {
27
31
  const operand = filter.leftValue;
28
32
  if ((operand.aspect != null && operand.aspect !== "") || (operand.treatNullAsEquals != null && operand.treatNullAsEquals !== true)) {
@@ -127,6 +131,11 @@ function printFilterValue(value, codec, call, quote) {
127
131
  return call("fieldValue", `${codec.field(value.value)}, { ${options.join(", ")} }`);
128
132
  }
129
133
  case "CURRENT_USER": return call("currentUser", quote(value.valueType ?? "ID"));
134
+ case "USER": {
135
+ if (codec.user === undefined)
136
+ throw new EntityTfError(`a user filter value (${value.email}) has no printed form here`);
137
+ return codec.user(value.email);
138
+ }
130
139
  case "REFERENCE": {
131
140
  const options = value.multiple === true ? ", { multiple: true }" : "";
132
141
  // Stored HCL real_type is uppercased as-is. DECIMAL and INTEGER are
@@ -96,6 +96,8 @@ export interface FilterToTfCodec {
96
96
  * lookup, whichever wrapper that is.
97
97
  */
98
98
  readonly literal?: (value: TfValue, field: unknown | undefined, valueType: string, isOptionLabel: boolean) => TfValue;
99
+ /** A `userRef(email)` value's user id; without it such a value cannot encode (#2891). */
100
+ readonly user?: (email: string) => TfValue;
99
101
  /**
100
102
  * The owner keeps an option label its field no longer lists as written
101
103
  * (a pulled automation, #1733), and its `literal` hook already warned.
@@ -129,6 +131,8 @@ export interface FilterFromTfCodec<Field = string, ReferenceValue = never> {
129
131
  */
130
132
  readonly referenceType?: (value: TfValue, fallback: ValueType) => ValueType;
131
133
  readonly literal?: (value: TfValue, valueType: string, field?: Field) => TfValue;
134
+ /** The email of a user lookup a TEXT or UUID value holds, or undefined when it holds none (#2891). */
135
+ readonly user?: (value: TfValue) => string | undefined;
132
136
  /** Decode a RECORD_FIELD value's source-record field reference; without it only raw platform ids decode. */
133
137
  readonly recordField?: (value: TfValue) => Field;
134
138
  /** Whether a RECORD_FIELD `object` reference names the owning app or element; without it only raw platform ids decode. */
@@ -199,6 +199,17 @@ function wireFilterValueToTf(value, field, codec, role = "value", operator) {
199
199
  }
200
200
  return { type, current_user_type: currentUserType.toLowerCase() };
201
201
  }
202
+ if (type === "user") {
203
+ if (typeof raw.email !== "string" || raw.email === "")
204
+ throw new EntityTfError("userRef filter value requires an email");
205
+ if (codec.user === undefined) {
206
+ throw new EntityTfError(`userRef(${JSON.stringify(raw.email)}) as a filter value is supported only in automation filters`);
207
+ }
208
+ const valueType = String(raw.valueType ?? "TEXT").toLowerCase();
209
+ if (valueType !== "text" && valueType !== "uuid")
210
+ throw new EntityTfError(`userRef filter value type must be TEXT or UUID, not ${valueType.toUpperCase()}`);
211
+ return { type: valueType, value: codec.user(raw.email) };
212
+ }
202
213
  if (type === "reference") {
203
214
  const reference = raw.value ?? raw.valueReference ?? raw.value_reference;
204
215
  if (reference === undefined)
@@ -564,6 +575,11 @@ export function filterFromTf(value, codec, fieldScope = "app") {
564
575
  }
565
576
  function filterValueFromTf(value, codec, fieldScope, field) {
566
577
  const type = value.type.toLowerCase();
578
+ if ((type === "text" || type === "uuid") && codec.user !== undefined && value.value !== undefined) {
579
+ const email = codec.user(value.value);
580
+ if (email !== undefined)
581
+ return { type: "USER", email, valueType: type === "uuid" ? "UUID" : "TEXT" };
582
+ }
567
583
  const literal = codec.literal?.(value.value, type, field) ?? value.value;
568
584
  if (["text", "uuid", "number", "boolean", "date", "datetime"].includes(type) && typeof literal === "object" && literal !== null) {
569
585
  throw new EntityTfError(`${type} filter literal contains an unresolved expression or object`);
@@ -69,6 +69,10 @@ export type FilterValue<FieldValue = string, ReferenceValue = FilterReference> =
69
69
  } | {
70
70
  type: "CURRENT_USER";
71
71
  valueType?: "ID" | "EMAIL" | "DOMAIN";
72
+ } | {
73
+ type: "USER";
74
+ email: string;
75
+ valueType: "TEXT" | "UUID";
72
76
  } | ({
73
77
  type: "RECORD_FIELD";
74
78
  field: FieldValue | string;
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import type { FromTfContext } from "../../engine/pull/context.js";
18
18
  import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
19
- export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task", ctx?: Pick<FromTfContext, "dataAttrs" | "foreignFieldRefsByDataAddress">): string | undefined;
19
+ export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task", ctx?: Pick<FromTfContext, "dataAttrs" | "foreignFieldRefsByDataAddress" | "resourcesOfType">): string | undefined;
20
20
  /**
21
21
  * When `fieldRef` is a field resource whose scoped label names a different
22
22
  * owner than the tool's resolved target, return that owner as
@@ -1,7 +1,5 @@
1
1
  import { isTfExpr, ownerFromScopedChildLabel, tfLabelToTsLabel } from "../../engine/tf/index.js";
2
- import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
3
- import { bagKeyForPulledCustomField } from "../field/from-tf.js";
4
- import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
2
+ import { pulledFieldBagKey } from "../field/from-tf.js";
5
3
  import { SUB_TYPE_BY_RESOURCE as FIELD_SUB_TYPE_BY_RESOURCE } from "../field/types.js";
6
4
  export function resolveToolFieldKey(fieldRef, scopeTfLabel, scope = "app", ctx) {
7
5
  if (fieldRef === undefined)
@@ -11,8 +9,7 @@ export function resolveToolFieldKey(fieldRef, scopeTfLabel, scope = "app", ctx)
11
9
  // into a key on this tool's target (edk#1403 review S1).
12
10
  if (toolFieldRefOtherOwner(fieldRef, scopeTfLabel, scope) !== undefined)
13
11
  return undefined;
14
- const reserved = scope === "element" ? new Set(ELEMENT_SYSTEM_FIELD_KEYS) : SYSTEM_FIELD_KEY_SET;
15
- return bagKeyForPulledCustomField(scopeTfLabel, fieldRef.label, scope, reserved);
12
+ return pulledFieldBagKey(scopeTfLabel, fieldRef.label, scope, ctx);
16
13
  }
17
14
  if (isTfExpr(fieldRef) && fieldRef.$expr === "data-attr" && fieldRef.type === "elementum_field") {
18
15
  const fieldAttrs = ctx?.dataAttrs?.("elementum_field", fieldRef.label);
@@ -1,6 +1,6 @@
1
1
  import { dataRefLabel, optionalBoolean, optionalString, plainObject } from "../../engine/pull/context.js";
2
2
  import { tfLabelToTsLabel } from "../../engine/tf/index.js";
3
- import { fieldFromTf } from "../field/from-tf.js";
3
+ import { fieldsFromTf } from "../field/from-tf.js";
4
4
  import { TASK_RESOURCE_TYPE } from "./module.js";
5
5
  const KNOWN = new Set(["id", "name", "handle", "namespace", "category_id", "cloud_link_id", "description", "icon", "color", "title_field_name", "title_field_description", "id_field_name", "id_field_description", "status_field_name", "status_field_description", "status_options", "status_option_ids_by_label", "title_field_id", "id_field_id", "status_field_id", "comments_enabled", "comments_display_block_id"]);
6
6
  export function taskFromTf(block, ctx, fieldBlocks = []) {
@@ -28,8 +28,8 @@ export function taskFromTf(block, ctx, fieldBlocks = []) {
28
28
  const statusDescription = optionalString(block.attrs, "status_field_description", `task ${block.label}`, ctx);
29
29
  const refName = tfLabelToTsLabel(block.label);
30
30
  const owner = { type: TASK_RESOURCE_TYPE, label: block.label, scope: "task", refName };
31
- const usedFieldKeys = new Set();
32
- const fields = fieldBlocks.flatMap((fieldBlock) => fieldFromTf(fieldBlock, owner, ctx, usedFieldKeys) ?? []);
31
+ // Keys claimed two-pass like apps and elements, printed in the live field order (#1871 B1, edk#2933).
32
+ const fields = fieldsFromTf(fieldBlocks, owner, ctx);
33
33
  return { refName, name, handle, namespace,
34
34
  ...(fields.length > 0 && { fields }),
35
35
  ...(categoryLabel !== undefined && { categoryRef: tfLabelToTsLabel(categoryLabel) }),
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * check.mjs-parity structure checks for Custom managed views (#1771 / #1758).
3
3
  * Hard structural failures (missing root/type, cycles, broken filters) fail the
4
- * build as EntityTfError. Reachability and live-list selection gaps match
5
- * check.mjs `warn` — they push to diagnostics so a pulled live layout still
6
- * builds and plans clean (Blueprint Supplier Workspace has both). Agent views
7
- * keep the softer diagnostics in checkStructure / reportStructureProblems.
4
+ * build as EntityTfError. Reachability, live-list selection gaps and bindings
5
+ * to a path missing from spec.state are warnings — they push to diagnostics so
6
+ * a pulled live layout still builds and plans clean (Blueprint Supplier
7
+ * Workspace has the first two; Under Armour Activity the third, edk#2923: the
8
+ * page reads a missing path as undefined). Agent views keep the softer
9
+ * diagnostics in checkStructure / reportStructureProblems.
8
10
  *
9
11
  * Layer 3 catalog checks (calc field names, option ids, tag helpers against
10
12
  * the live App) need aspect-aware resolution; typed field refs already fail
@@ -15,6 +15,18 @@ function isObj(v) {
15
15
  function isBinding(v) {
16
16
  return isObj(v) && ("$state" in v || "$bindState" in v || "$item" in v || "$index" in v);
17
17
  }
18
+ /**
19
+ * A $state / $bindState binding's state path, exactly as the Go provider's
20
+ * bindingTarget: a string $state wins, else a string $bindState; "" is no target.
21
+ */
22
+ function bindingTarget(v) {
23
+ if (!isObj(v))
24
+ return undefined;
25
+ const state = v["$state"];
26
+ const bind = v["$bindState"];
27
+ const target = typeof state === "string" ? state : typeof bind === "string" ? bind : undefined;
28
+ return target === "" ? undefined : target;
29
+ }
18
30
  /** Selection props must be $state / $bindState — $item / $index do not drive the details pane. */
19
31
  function isStateBinding(v) {
20
32
  return isObj(v) && ("$state" in v || "$bindState" in v);
@@ -156,9 +168,25 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
156
168
  return { found: true, value: node };
157
169
  };
158
170
  const walkedState = new Set();
159
- const walkFilter = (node, filterWhere) => {
171
+ const walkFilter = (node, filterWhere, fromState = false) => {
160
172
  if (node == null)
161
173
  return;
174
+ // In element props, a binding stands for the filter held in state, at the top
175
+ // of filterJson or as a child of an AND/OR group (edk#2923): the page resolves
176
+ // prop bindings. Check its initial value once, at its state path; a missing
177
+ // path is the binding scan's warning. Nothing shows the page resolving a
178
+ // binding inside a state value, so there it stays a filter node missing "type".
179
+ if (!fromState && isBinding(node)) {
180
+ const target = bindingTarget(node);
181
+ if (typeof target !== "string" || walkedState.has(target))
182
+ return;
183
+ const initial = readState(target);
184
+ if (initial.found && initial.value != null) {
185
+ walkedState.add(target);
186
+ walkFilter(initial.value, `${where}.state${target.replaceAll("/", ".")}`, true);
187
+ }
188
+ return;
189
+ }
162
190
  if (!isObj(node)) {
163
191
  note(filterWhere, "a filter must be an object");
164
192
  return;
@@ -174,7 +202,7 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
174
202
  note(filterWhere, `${node["type"]} needs a "children" list`);
175
203
  return;
176
204
  }
177
- node["children"].forEach((c, i) => walkFilter(c, `${filterWhere}.children[${i}]`));
205
+ node["children"].forEach((c, i) => walkFilter(c, `${filterWhere}.children[${i}]`, fromState));
178
206
  return;
179
207
  }
180
208
  if (typeof node["type"] !== "string") {
@@ -190,9 +218,11 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
190
218
  const type = raw["type"];
191
219
  const scan = (value, path) => {
192
220
  if (isBinding(value)) {
193
- const target = value["$state"] ?? value["$bindState"];
221
+ const target = bindingTarget(value);
194
222
  if (typeof target === "string" && !target.startsWith("/host/") && !readState(target).found) {
195
- note(`${elWhere}.${path}`, `binds to "${target}", which is not in spec.state. Add an initial value there.`);
223
+ // Warn, not fail (edk#2923): the page reads a missing path as undefined,
224
+ // and pulled live layouts rely on that, so failing would block the build.
225
+ warn(`${elWhere}.${path}`, `binds to "${target}", which is not in spec.state, so it starts undefined. Add an initial value there to set its default.`);
196
226
  }
197
227
  return;
198
228
  }
@@ -204,20 +234,8 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
204
234
  };
205
235
  for (const [key, value] of Object.entries(props))
206
236
  scan(value, key);
207
- if (props["filterJson"] !== undefined) {
208
- if (isBinding(props["filterJson"])) {
209
- const target = props["filterJson"]["$bindState"]
210
- ?? props["filterJson"]["$state"];
211
- const initial = typeof target === "string" ? readState(target) : { found: false };
212
- if (initial.found && initial.value != null && typeof target === "string" && !walkedState.has(target)) {
213
- walkedState.add(target);
214
- walkFilter(initial.value, `${where}.state${target.replaceAll("/", ".")}`);
215
- }
216
- }
217
- else {
218
- walkFilter(props["filterJson"], `${elWhere}.filterJson`);
219
- }
220
- }
237
+ if (props["filterJson"] !== undefined)
238
+ walkFilter(props["filterJson"], `${elWhere}.filterJson`);
221
239
  if (typeof props["calc"] === "string") {
222
240
  const calc = props["calc"];
223
241
  if (AVG_CALL.test(calc))
@@ -701,6 +701,15 @@ function ownDataFieldRef(v, owner, ctx, site, failClosed) {
701
701
  const field = ownDataFieldKey(v.label, owner, ctx);
702
702
  if (field.extracted)
703
703
  return field.key;
704
+ // The live id of the field the lookup finds, when pull knows it (#2815: an
705
+ // element's Closed at / Closed by): keep the reference by it, as for any
706
+ // other field pull did not extract (#1978). A clone never copies the field.
707
+ const liveId = ctx.cloning === undefined ? ctx.ownFieldIdsByDataAddress?.get(`${v.type}.${v.label}`) : undefined;
708
+ if (liveId !== undefined) {
709
+ reportUnextractedField(ctx, unkeptFieldAddress(v), liveId, site, failClosed);
710
+ owner.unextractedFieldIds?.add(liveId);
711
+ return liveId;
712
+ }
704
713
  if (!failClosed && ctx.cloning === undefined)
705
714
  return undefined;
706
715
  // Not `unextractedFieldId`: with an unmatched name, the label's key may be
@@ -10,7 +10,7 @@
10
10
  * with the same `EntityTfError` path used by access-policy row filters.
11
11
  */
12
12
  import { agentViewLayoutToTf, viewBlocksToTf } from "./agent-view-layout-to-tf.js";
13
- import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
13
+ import { expr, isCanonicalTsLabel, isTfLabel, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
14
14
  import { fieldRefToTfValue as customFieldRefToTfValue } from "../field/to-tf.js";
15
15
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
16
16
  import { filterToTf, principalListToTf } from "../access-policy/to-tf.js";
@@ -41,15 +41,20 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
41
41
  const { ownerRefName, ownerTfLabel, scope = "app", objectId, diagnostics, fieldAddresses } = opts;
42
42
  const principalCtx = { ...opts, scope, objectId };
43
43
  const blocks = [];
44
+ // A layout key that names no stage fails the build: dropping the layout
45
+ // would plan the deletion of a live one (#2894).
46
+ const validLayoutKeys = () => opts.stageTfLabels === undefined
47
+ ? ""
48
+ : ` Use one of: ${[...new Set([...opts.stageTfLabels].filter(isTfLabel).map(tfLabelToTsLabel))].sort().join(", ")}.`;
44
49
  for (const [stageKey, layout] of Object.entries(layouts ?? {})) {
45
50
  if (!isCanonicalTsLabel(stageKey)) {
46
- diagnostics.push(`layouts key "${stageKey}" is not a canonical tsLabel (see src/engine/tf/labels.ts) — rename the key`);
47
- continue;
51
+ throw new EntityTfError(opts.stageTfLabels === undefined
52
+ ? `${ownerRefName}: layouts key "${stageKey}" is not a valid key (keys are camelCase, with "_" before a digit; see src/engine/tf/labels.ts)`
53
+ : `${ownerRefName}: layouts key "${stageKey}" is not a stage key: a stage key is the stage's name in camelCase, with "_" before a digit (see src/engine/tf/labels.ts).${validLayoutKeys()}`);
48
54
  }
49
55
  const stageTfLabel = tsLabelToTfLabel(stageKey);
50
56
  if (opts.stageTfLabels !== undefined && !opts.stageTfLabels.has(stageTfLabel)) {
51
- diagnostics.push(`layouts.${stageKey} has no matching authored stage option; dropped`);
52
- continue;
57
+ throw new EntityTfError(`${ownerRefName}: layouts.${stageKey} matches none of its stages.${validLayoutKeys()}`);
53
58
  }
54
59
  blocks.push(layoutToTf(stageKey, layout, ownerRefName, ownerTfLabel, scope, objectId, diagnostics, fieldAddresses, opts.widgets, opts.stageKeyByTfLabel?.get(stageTfLabel)));
55
60
  }
@@ -236,6 +241,9 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
236
241
  blocks.push({ kind: "resource", type: AGENT_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
237
242
  viewAddressByKey.set(viewKey, { type: AGENT_VIEW_RESOURCE_TYPE, label: tfLabel });
238
243
  }
244
+ // Every custom view's problems (layout, filter, sort, sharing) are reported
245
+ // together, not only the first failing view's (edk#2923).
246
+ const customViewProblems = [];
239
247
  for (const [viewKey, view] of Object.entries(customViews ?? {})) {
240
248
  const where = `customViews.${viewKey}`;
241
249
  if (!isCanonicalTsLabel(viewKey)) {
@@ -246,52 +254,63 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
246
254
  diagnostics.push(`${where} collides with another view key; dropped`);
247
255
  continue;
248
256
  }
249
- const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
250
- const attrs = {
251
- aspect_id: objectId,
252
- name: view.name ?? "",
253
- allow_record_creation: view.allowRecordCreation ?? true,
254
- };
255
- if (view.agent !== undefined) {
256
- const agentRefName = view.agent.refName ?? "";
257
- if (agentRefName === "" || view.agent.parent !== ownerRefName) {
258
- // Dropping only the agent would detach it on apply; keep the whole view out instead.
259
- diagnostics.push(`${where}.agent must be an agent of this ${scope === "element" ? "element" : "app"}; dropped`);
260
- continue;
257
+ try {
258
+ const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
259
+ const attrs = {
260
+ aspect_id: objectId,
261
+ name: view.name ?? "",
262
+ allow_record_creation: view.allowRecordCreation ?? true,
263
+ };
264
+ if (view.agent !== undefined) {
265
+ const agentRefName = view.agent.refName ?? "";
266
+ if (agentRefName === "" || view.agent.parent !== ownerRefName) {
267
+ // Dropping only the agent would detach it on apply; keep the whole view out instead.
268
+ diagnostics.push(`${where}.agent must be an agent of this ${scope === "element" ? "element" : "app"}; dropped`);
269
+ continue;
270
+ }
271
+ attrs["agent_id"] = expr.resourceAttr("elementum_agent", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(agentRefName), scope), ["id"]);
261
272
  }
262
- attrs["agent_id"] = expr.resourceAttr("elementum_agent", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(agentRefName), scope), ["id"]);
263
- }
264
- if (view.filter !== undefined)
265
- attrs["filter"] = filterToTf(view.filter, `${where}.filter`, { ownerTfLabel, appRefName: ownerRefName, scope, objectId, diagnostics, resolvePicklistLiterals: false, fieldAddresses });
266
- if (view.sort !== undefined)
267
- attrs["sort"] = managedViewSortToTf(view.sort, ownerTfLabel, scope, `${where}.sort`, diagnostics, fieldAddresses);
268
- appendViewSharingAttrs(attrs, view, where, principalCtx);
269
- if (view.displayOrder !== undefined)
270
- attrs["display_order"] = view.displayOrder;
271
- if (view.layout !== undefined) {
272
- attrs["layout"] = expr.jsonencode(viewBlocksToTf(view.layout, `${where}.layout`, {
273
- ownerRefName,
274
- ownerKind: scope === "element" ? "element" : "app",
275
- ownerTfLabel,
276
- scope,
277
- objectId,
278
- diagnostics,
279
- fieldAddresses,
280
- fieldNames: opts.fieldNames,
281
- fieldMetadata: opts.fieldMetadata,
282
- orgRefs: opts.orgRefs,
283
- workspaceAspects: opts.workspaceAspects,
284
- resolveField: (ref, fieldWhere) => fieldRefToTfValue(ref, ownerTfLabel, scope, fieldWhere, diagnostics, fieldAddresses),
285
- }, { editorPolicy: false, strictStructure: true }));
273
+ if (view.filter !== undefined)
274
+ attrs["filter"] = filterToTf(view.filter, `${where}.filter`, { ownerTfLabel, appRefName: ownerRefName, scope, objectId, diagnostics, resolvePicklistLiterals: false, fieldAddresses });
275
+ if (view.sort !== undefined)
276
+ attrs["sort"] = managedViewSortToTf(view.sort, ownerTfLabel, scope, `${where}.sort`, diagnostics, fieldAddresses);
277
+ appendViewSharingAttrs(attrs, view, where, principalCtx);
278
+ if (view.displayOrder !== undefined)
279
+ attrs["display_order"] = view.displayOrder;
280
+ if (view.layout !== undefined) {
281
+ attrs["layout"] = expr.jsonencode(viewBlocksToTf(view.layout, `${where}.layout`, {
282
+ ownerRefName,
283
+ ownerKind: scope === "element" ? "element" : "app",
284
+ ownerTfLabel,
285
+ scope,
286
+ objectId,
287
+ diagnostics,
288
+ fieldAddresses,
289
+ fieldNames: opts.fieldNames,
290
+ fieldMetadata: opts.fieldMetadata,
291
+ orgRefs: opts.orgRefs,
292
+ workspaceAspects: opts.workspaceAspects,
293
+ resolveField: (ref, fieldWhere) => fieldRefToTfValue(ref, ownerTfLabel, scope, fieldWhere, diagnostics, fieldAddresses),
294
+ }, { editorPolicy: false, strictStructure: true }));
295
+ }
296
+ else {
297
+ // The page needs a layout document, and the platform rejects a blank
298
+ // one, so a view without a layout cannot be opened in the admin UI.
299
+ diagnostics.push(`${where} has no layout, so the admin UI cannot open this view ("This custom view could not be loaded"); add a layout`);
300
+ }
301
+ blocks.push({ kind: "resource", type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
302
+ viewAddressByKey.set(viewKey, { type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel });
286
303
  }
287
- else {
288
- // The page needs a layout document, and the platform rejects a blank
289
- // one, so a view without a layout cannot be opened in the admin UI.
290
- diagnostics.push(`${where} has no layout, so the admin UI cannot open this view ("This custom view could not be loaded"); add a layout`);
304
+ catch (err) {
305
+ if (!(err instanceof EntityTfError))
306
+ throw err;
307
+ // Codec errors (e.g. `unsupported filter type "X"`) carry no location; name the view.
308
+ const located = err.message.startsWith(`${where}.`) || err.message.startsWith(`${where}:`) || err.message.startsWith(`${where} `);
309
+ customViewProblems.push(located ? err.message : `${where}: ${err.message}`);
291
310
  }
292
- blocks.push({ kind: "resource", type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
293
- viewAddressByKey.set(viewKey, { type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel });
294
311
  }
312
+ if (customViewProblems.length > 0)
313
+ throw new EntityTfError(customViewProblems.join("\n"));
295
314
  if (opts.deleteDefaultListView === true && viewAddressByKey.size === 0) {
296
315
  throw new EntityTfError(`${ownerRefName}: deleteDefaultListView needs at least one declared view; without one there is no view order to apply and the "${PLATFORM_DEFAULT_LIST_VIEW_NAME}" view would stay.`);
297
316
  }
@@ -1,3 +1,4 @@
1
+ import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
1
2
  import { NO_CATALOG, NO_DATA } from "../../graph/types.js";
2
3
  import { APP_RESOURCE_TYPE } from "../app/module.js";
3
4
  import { ELEMENT_RESOURCE_TYPE } from "../element/module.js";
@@ -6,6 +7,54 @@ import { printVisualFlow } from "./printer.js";
6
7
  import { appStageKeyByHandle, LostStageHandleError, stageHandleIndexFromTfStages } from "../app/stage-keys.js";
7
8
  import { visualFlowToTf } from "./to-tf.js";
8
9
  export const VISUAL_FLOW_RESOURCE_TYPE = "elementum_flow";
10
+ /**
11
+ * Every automation or agent a flow's blocks run is a requirement of the flow:
12
+ * when pull leaves it out, the printed flow would point at something that
13
+ * isn't in source and fail to load. The flow is then left out and released
14
+ * from state like it, rather than destroyed (#2892).
15
+ */
16
+ function requireFlowAutomations(block, refName, ctx) {
17
+ if (block.type === undefined || block.label === undefined)
18
+ return;
19
+ const address = `${block.type}.${block.label}`;
20
+ const seen = new Set();
21
+ for (const stage of listOf(block.attrs["stages"])) {
22
+ for (const node of listOf(objectOf(stage)?.["nodes"])) {
23
+ const action = objectOf(objectOf(node)?.["action"]);
24
+ for (const [kind, attr, type] of RUN_ACTIONS) {
25
+ const target = objectOf(action?.[kind])?.[attr];
26
+ if (target === undefined || !isTfExpr(target) || target.$expr !== "resource-attr" || target.type !== type)
27
+ continue;
28
+ const requires = `${target.type}.${target.label}`;
29
+ if (seen.has(requires))
30
+ continue;
31
+ seen.add(requires);
32
+ ctx.requiresExtracted?.push({
33
+ address,
34
+ requires,
35
+ requiresOwnFile: { kind, refName: scopedLabelToBagKey(ctx.appTfLabel, target.label) },
36
+ prune: (root) => root,
37
+ pruneOwnFile: {
38
+ kind: "visual-flow",
39
+ prune: (items) => items.filter((item) => item.refName !== refName),
40
+ archiveRefName: refName,
41
+ },
42
+ });
43
+ }
44
+ }
45
+ }
46
+ }
47
+ /** Block actions that run an own-file resource of the app: the action variant, its id attribute, and the resource type. */
48
+ const RUN_ACTIONS = [
49
+ ["automation", "automation_id", "elementum_automation"],
50
+ ["agent", "agent_id", "elementum_agent"],
51
+ ];
52
+ function listOf(value) {
53
+ return Array.isArray(value) ? value : [];
54
+ }
55
+ function objectOf(value) {
56
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isTfExpr(value) ? value : undefined;
57
+ }
9
58
  function extract(blocks, _stream, ctx) {
10
59
  const items = [];
11
60
  const skipped = [];
@@ -18,7 +67,9 @@ function extract(blocks, _stream, ctx) {
18
67
  const releaseIfManaged = [];
19
68
  for (const block of blocks) {
20
69
  try {
21
- items.push(visualFlowFromTf(block, ownerType, ctx.appTfLabel, ctx.parentScope, ctx, stageHandles));
70
+ const flow = visualFlowFromTf(block, ownerType, ctx.appTfLabel, ctx.parentScope, ctx, stageHandles);
71
+ items.push(flow);
72
+ requireFlowAutomations(block, flow.refName, ctx);
22
73
  }
23
74
  catch (error) {
24
75
  const address = `${block.type}.${block.label ?? "?"}`;
@@ -231,7 +231,7 @@ function widgetFieldRef(value, target, owner, ctx) {
231
231
  : target.namespace ?? tsLabelToTfLabel(target.key);
232
232
  const targetScope = typeof target === "string" || target.kind === "automation" || target.kind === "field" || target.kind === "recordIdentity" || target.kind === "task" ? owner.scope : target.kind;
233
233
  if (targetLabel !== undefined) {
234
- const key = fieldKeyFromTfRef(value, targetLabel, targetScope);
234
+ const key = fieldKeyFromTfRef(value, targetLabel, targetScope, ctx);
235
235
  if (key !== undefined) {
236
236
  // HANDLE system field (`local.<target>_id_field_id`) round-trips as
237
237
  // recordIdentity(target) — same catalog token widgets author with.
@@ -338,7 +338,7 @@ function ownerFieldRef(value, owner, ctx) {
338
338
  return undefined;
339
339
  if (typeof value === "string")
340
340
  return fieldRefFromRawId(value, owner.ownerRefName, owner, ctx) ?? value;
341
- const key = fieldKeyFromTfRef(value, owner.ownerTfLabel, owner.scope);
341
+ const key = fieldKeyFromTfRef(value, owner.ownerTfLabel, owner.scope, ctx);
342
342
  return key === undefined ? undefined : { kind: "field", key, name: key, parent: owner.ownerRefName, fieldType: "TEXT" };
343
343
  }
344
344
  /**
@@ -427,7 +427,7 @@ function fieldRefFromRawId(id, target, owner, ctx) {
427
427
  const subType = SUB_TYPE_BY_RESOURCE.get(imported.type);
428
428
  if (subType === undefined)
429
429
  return undefined;
430
- const ownerKey = fieldKeyIfScopedTo(imported.type, imported.label, owner.ownerTfLabel, owner.scope);
430
+ const ownerKey = fieldKeyIfScopedTo(imported.type, imported.label, owner.ownerTfLabel, owner.scope, ctx);
431
431
  if (ownerKey !== undefined) {
432
432
  return {
433
433
  kind: "field",
@@ -441,7 +441,7 @@ function fieldRefFromRawId(id, target, owner, ctx) {
441
441
  const targetTfLabel = target.key === owner.ownerRefName
442
442
  ? owner.ownerTfLabel
443
443
  : target.namespace ?? tsLabelToTfLabel(target.key);
444
- const targetKey = fieldKeyIfScopedTo(imported.type, imported.label, targetTfLabel, target.kind);
444
+ const targetKey = fieldKeyIfScopedTo(imported.type, imported.label, targetTfLabel, target.kind, ctx);
445
445
  if (targetKey !== undefined) {
446
446
  return {
447
447
  kind: "field",
@@ -455,8 +455,8 @@ function fieldRefFromRawId(id, target, owner, ctx) {
455
455
  return undefined;
456
456
  }
457
457
  /** `fieldKeyFromTfRef` camelCases any label; only treat it as owned when the scoped prefix was actually stripped. */
458
- function fieldKeyIfScopedTo(type, label, ownerTfLabel, scope) {
458
+ function fieldKeyIfScopedTo(type, label, ownerTfLabel, scope, ctx) {
459
459
  if (bareChildResourceLabel(ownerTfLabel, label, scope) === label)
460
460
  return undefined;
461
- return fieldKeyFromTfRef({ $expr: "resource-attr", type, label, path: ["id"] }, ownerTfLabel, scope);
461
+ return fieldKeyFromTfRef({ $expr: "resource-attr", type, label, path: ["id"] }, ownerTfLabel, scope, ctx);
462
462
  }
@@ -88,6 +88,10 @@ export declare const BUILD_VS_EXPORT_RECORD_FIELD_OUTPUT_KEYS: {
88
88
  readonly nameAttribute: string;
89
89
  readonly ownerAttribute: string;
90
90
  }[];
91
+ export declare const BUILD_VS_EXPORT_MAP_KEY_ALIASES: {
92
+ readonly attribute: string;
93
+ readonly canonicalKey: (key: string) => string | undefined;
94
+ }[];
91
95
  export declare const BUILD_VS_EXPORT_ATTRIBUTE_LOCALS: {
92
96
  readonly resourceType: string;
93
97
  readonly attribute: string;
@@ -63,6 +63,7 @@ export const BUILD_VS_EXPORT_COMPUTED_MAP_ATTRIBUTES = KIND_MODULES.flatMap((mod
63
63
  export const BUILD_VS_EXPORT_NESTED_OMITTED_DEFAULTS = KIND_MODULES.flatMap((module) => (module.roundtrip?.nestedOmittedDefaults ?? []).flatMap((declared) => implementedResourceTypes(module.resource).map((blockType) => ({ blockType, ...declared }))));
64
64
  export const BUILD_VS_EXPORT_COMPUTED_REFERENCE_MAPS = KIND_MODULES.flatMap((module) => module.roundtrip?.computedReferenceMaps ?? []);
65
65
  export const BUILD_VS_EXPORT_RECORD_FIELD_OUTPUT_KEYS = KIND_MODULES.flatMap((module) => module.roundtrip?.recordFieldOutputKeys ?? []);
66
+ export const BUILD_VS_EXPORT_MAP_KEY_ALIASES = KIND_MODULES.flatMap((module) => module.roundtrip?.mapKeyAliases ?? []);
66
67
  export const BUILD_VS_EXPORT_ATTRIBUTE_LOCALS = KIND_MODULES.flatMap((module) => module.roundtrip?.exportedAttributeLocals ?? []);
67
68
  export const BUILD_VS_EXPORT_PICKLIST_LABEL_ASSIGNMENTS = KIND_MODULES.flatMap((module) => module.roundtrip?.picklistLabelAssignments ?? []);
68
69
  export const BUILD_VS_EXPORT_STATE_EVALUATED_MAPS = KIND_MODULES.flatMap((module) => module.roundtrip?.stateEvaluatedMaps ?? []);
@@ -17,6 +17,7 @@ import { elementModule } from "../entities/element/module.js";
17
17
  import { dynamicLayoutModule } from "../entities/dynamic-layout/module.js";
18
18
  import { dashboardModule } from "../entities/dashboard/module.js";
19
19
  import { dashboardWidgetModule } from "../entities/dashboard-widget/module.js";
20
+ import { dashboardWidgetOrderModule } from "../entities/dashboard-widget-order/module.js";
20
21
  import { datamineModule } from "../entities/datamine/module.js";
21
22
  import { dataLookupModules } from "../entities/data-lookup/module.js";
22
23
  import { fieldModule, managedFieldOrderModule } from "../entities/field/module.js";
@@ -60,6 +61,7 @@ export const KIND_MODULES = [
60
61
  dynamicLayoutModule,
61
62
  dashboardModule,
62
63
  dashboardWidgetModule,
64
+ dashboardWidgetOrderModule,
63
65
  datamineModule,
64
66
  ...dataLookupModules,
65
67
  widgetModule,