@elementumai/edk 0.13.0 → 0.13.2

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 (101) 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 +12 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +23 -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/progress.d.ts +1 -0
  9. package/dist-sdk/src/engine/progress.js +6 -0
  10. package/dist-sdk/src/engine/pull/context.d.ts +24 -0
  11. package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
  12. package/dist-sdk/src/engine/pull/result-output.js +1 -1
  13. package/dist-sdk/src/engine/pull/stream-root.d.ts +11 -0
  14. package/dist-sdk/src/engine/pull/stream-root.js +22 -6
  15. package/dist-sdk/src/engine/tf/escape.d.ts +8 -3
  16. package/dist-sdk/src/engine/tf/escape.js +17 -4
  17. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  18. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -7
  19. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -1
  20. package/dist-sdk/src/entities/agent/from-tf.d.ts +2 -0
  21. package/dist-sdk/src/entities/agent/from-tf.js +28 -1
  22. package/dist-sdk/src/entities/agent/module.js +1 -0
  23. package/dist-sdk/src/entities/agent/to-tf.d.ts +3 -1
  24. package/dist-sdk/src/entities/agent/to-tf.js +21 -3
  25. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  26. package/dist-sdk/src/entities/app/from-tf.js +6 -23
  27. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  28. package/dist-sdk/src/entities/app/module.js +2 -0
  29. package/dist-sdk/src/entities/approval-chain/from-tf.js +2 -2
  30. package/dist-sdk/src/entities/automation/build.d.ts +10 -1
  31. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +1 -0
  32. package/dist-sdk/src/entities/automation/from-tf.js +72 -11
  33. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  34. package/dist-sdk/src/entities/automation/module.js +12 -0
  35. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  36. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  37. package/dist-sdk/src/entities/automation/to-tf.d.ts +5 -1
  38. package/dist-sdk/src/entities/automation/to-tf.js +312 -51
  39. package/dist-sdk/src/entities/automation/triggers.d.ts +5 -1
  40. package/dist-sdk/src/entities/automation/workflow-output.d.ts +7 -0
  41. package/dist-sdk/src/entities/automation/workflow-output.js +8 -0
  42. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  43. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  44. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  45. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  46. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  47. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  48. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  49. package/dist-sdk/src/entities/dynamic-layout/lint.d.ts +7 -0
  50. package/dist-sdk/src/entities/dynamic-layout/lint.js +48 -0
  51. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +2 -0
  52. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  53. package/dist-sdk/src/entities/element/from-tf.js +5 -21
  54. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  55. package/dist-sdk/src/entities/element/module.js +2 -0
  56. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  57. package/dist-sdk/src/entities/field/from-tf.d.ts +25 -2
  58. package/dist-sdk/src/entities/field/from-tf.js +119 -14
  59. package/dist-sdk/src/entities/relationship/from-tf.js +2 -2
  60. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  61. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  62. package/dist-sdk/src/entities/search-table/build.js +4 -4
  63. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  64. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  65. package/dist-sdk/src/entities/shared/context.d.ts +14 -1
  66. package/dist-sdk/src/entities/shared/filters/index.d.ts +24 -13
  67. package/dist-sdk/src/entities/shared/filters/index.js +12 -1
  68. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  69. package/dist-sdk/src/entities/shared/filters/print.js +15 -6
  70. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +4 -0
  71. package/dist-sdk/src/entities/shared/filters/tf-codec.js +16 -0
  72. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  73. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  74. package/dist-sdk/src/entities/shared/tool-field-ref.js +2 -5
  75. package/dist-sdk/src/entities/task/from-tf.js +3 -3
  76. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +3 -3
  77. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -4
  78. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +4 -2
  79. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +6 -1
  80. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +14 -2
  81. package/dist-sdk/src/entities/view/custom-view-references.d.ts +33 -0
  82. package/dist-sdk/src/entities/view/custom-view-references.js +140 -0
  83. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +16 -9
  84. package/dist-sdk/src/entities/view/custom-view-validate.js +38 -18
  85. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  86. package/dist-sdk/src/entities/view/layout-lint.d.ts +26 -0
  87. package/dist-sdk/src/entities/view/layout-lint.js +50 -0
  88. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  89. package/dist-sdk/src/entities/view/to-tf.js +69 -47
  90. package/dist-sdk/src/entities/visual-flow/build.d.ts +8 -1
  91. package/dist-sdk/src/entities/visual-flow/from-tf.js +16 -0
  92. package/dist-sdk/src/entities/visual-flow/initiate.d.ts +12 -0
  93. package/dist-sdk/src/entities/visual-flow/initiate.js +12 -0
  94. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  95. package/dist-sdk/src/entities/visual-flow/to-tf.js +16 -2
  96. package/dist-sdk/src/entities/widget/from-tf.js +6 -6
  97. package/dist-sdk/src/graph/index.d.ts +4 -0
  98. package/dist-sdk/src/graph/index.js +1 -0
  99. package/dist-sdk/src/graph/modules.js +2 -0
  100. package/dist-sdk/src/graph/types.d.ts +36 -1
  101. package/package.json +2 -2
@@ -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) }),
@@ -3,9 +3,9 @@
3
3
  * `elementum_agent_view.layout` → `agentViews.<key>.layout`;
4
4
  * `elementum_custom_view.layout` → `customViews.<key>.layout` (see
5
5
  * `viewBlocksFromTf`). References become typed markers at the per-block id
6
- * positions, inside nested filters and inside actions; a raw platform id there
7
- * becomes the owner's field ref when it names one of its fields (#2155), else
8
- * `unsafePlatformId(...)`. A layout this cannot represent makes the
6
+ * positions, inside nested filters, inside `spec.state` and inside actions; a
7
+ * raw platform id there becomes the owner's field ref when it names one of its
8
+ * fields (#2155), else `unsafePlatformId(...)`. A layout this cannot represent makes the
9
9
  * whole view unmanaged (skipped), never silently dropped: the code owns the
10
10
  * layout, so a dropped detail would be cleared on the next apply.
11
11
  */
@@ -3,9 +3,9 @@
3
3
  * `elementum_agent_view.layout` → `agentViews.<key>.layout`;
4
4
  * `elementum_custom_view.layout` → `customViews.<key>.layout` (see
5
5
  * `viewBlocksFromTf`). References become typed markers at the per-block id
6
- * positions, inside nested filters and inside actions; a raw platform id there
7
- * becomes the owner's field ref when it names one of its fields (#2155), else
8
- * `unsafePlatformId(...)`. A layout this cannot represent makes the
6
+ * positions, inside nested filters, inside `spec.state` and inside actions; a
7
+ * raw platform id there becomes the owner's field ref when it names one of its
8
+ * fields (#2155), else `unsafePlatformId(...)`. A layout this cannot represent makes the
9
9
  * whole view unmanaged (skipped), never silently dropped: the code owns the
10
10
  * layout, so a dropped detail would be cleared on the next apply.
11
11
  */
@@ -88,7 +88,9 @@ function decodeSpec(value, opts, root = "custom_view") {
88
88
  const out = {};
89
89
  for (const [key, child] of Object.entries(spec)) {
90
90
  if (key !== "elements") {
91
- out[key] = literal(child, `${root}.${key}`);
91
+ // `spec.state` holds the filter trees blocks bind to, so references may
92
+ // sit at any depth there, as inside a filter prop (#1770).
93
+ out[key] = key === "state" ? deepRefs(child, `${root}.${key}`, opts) : literal(child, `${root}.${key}`);
92
94
  continue;
93
95
  }
94
96
  const elements = plain(child);
@@ -3,8 +3,8 @@
3
3
  * attribute of `elementum_agent_view` (its custom view is a blocks layout);
4
4
  * `customViews.<key>.layout` → the `layout` attribute of
5
5
  * `elementum_custom_view` (see `viewBlocksToTf`). Platform ids resolve from
6
- * typed references at the per-block id positions, inside nested filters and
7
- * inside actions; a structurally broken layout fails the build, because
6
+ * typed references at the per-block id positions, inside nested filters,
7
+ * inside `spec.state` and inside actions; a structurally broken layout fails the build, because
8
8
  * dropping it would make apply clear the live one.
9
9
  */
10
10
  import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
@@ -14,6 +14,8 @@ export interface AgentViewLayoutToTfOptions {
14
14
  readonly ownerRefName: string;
15
15
  /** The view owner's kind; an agent view's owner is always an app. */
16
16
  readonly ownerKind?: "app" | "element";
17
+ /** Element owners only: the element declares `systemFields.audit`. */
18
+ readonly ownerAuditFields?: boolean;
17
19
  readonly ownerTfLabel: string;
18
20
  readonly scope: ChildResourceScope;
19
21
  readonly objectId: TfValue;
@@ -71,6 +71,9 @@ export function viewBlocksToTf(spec, where, opts, policy) {
71
71
  throw new EntityTfError(`${where}.elements must have at least one element`);
72
72
  if (policy.strictStructure) {
73
73
  validateCustomViewLayout(doc, where, {
74
+ ownerRefName: opts.ownerRefName,
75
+ ...(opts.ownerKind !== undefined ? { ownerKind: opts.ownerKind } : {}),
76
+ ...(opts.ownerAuditFields !== undefined ? { ownerAuditFields: opts.ownerAuditFields } : {}),
74
77
  ...(opts.fieldNames !== undefined ? { fieldNames: opts.fieldNames } : {}),
75
78
  ...(opts.fieldMetadata !== undefined ? { fieldMetadata: opts.fieldMetadata } : {}),
76
79
  diagnostics: opts.diagnostics,
@@ -83,7 +86,9 @@ export function viewBlocksToTf(spec, where, opts, policy) {
83
86
  for (const [key, value] of Object.entries(doc)) {
84
87
  if (key === "elements")
85
88
  continue;
86
- out[key] = literal(value, `${where}.${key}`, opts);
89
+ // `spec.state` holds the filter trees blocks bind to (`$bindState`), so
90
+ // references may sit at any depth there, as inside a filter prop (#1770).
91
+ out[key] = key === "state" ? deepRefs(value, `${where}.${key}`, opts) : literal(value, `${where}.${key}`, opts);
87
92
  }
88
93
  const outElements = {};
89
94
  for (const [id, raw] of Object.entries(elements)) {
@@ -10,7 +10,8 @@
10
10
  * A blocks layout is an Elementum Blocks (Ragnarok) spec — the generated
11
11
  * `ElementumBlocksSpec` — with platform ids replaced by typed references at
12
12
  * the per-block id positions listed in `AGENT_VIEW_SPEC_ID_PROPS`, inside
13
- * nested filters, and inside actions (`on` events, button `onPress`).
13
+ * nested filters, inside `spec.state`, and inside actions (`on` events,
14
+ * button `onPress`).
14
15
  */
15
16
  import type { AppCatalogRef, ElementCatalogRef, FieldRef } from "../../catalog/types.js";
16
17
  import type { UnsafePlatformId } from "../../core/platform-id.js";
@@ -127,8 +128,19 @@ type MapElement<E> = E extends {
127
128
  } : E;
128
129
  /** One block of a blocks layout. */
129
130
  export type ViewBlock = MapElement<ElementumBlocksElement>;
131
+ /**
132
+ * A value held in `spec.state`. Blocks read it through `$state` / `$bindState`
133
+ * bindings, so a section's filter tree lives here (`/sections/s1/filter`).
134
+ * References may sit at any depth, as inside a filter prop (#1770).
135
+ */
136
+ export type ViewBlocksStateValue = string | number | boolean | null | ViewBlocksFilterRef | ReadonlyArray<ViewBlocksStateValue> | {
137
+ readonly [key: string]: ViewBlocksStateValue;
138
+ };
130
139
  /** A blocks layout: an Elementum Blocks spec with typed references. */
131
- export type ViewBlocksLayout = Omit<ElementumBlocksSpec, "elements"> & {
140
+ export type ViewBlocksLayout = Omit<ElementumBlocksSpec, "elements" | "state"> & {
141
+ readonly state?: {
142
+ readonly [key: string]: ViewBlocksStateValue;
143
+ };
132
144
  readonly elements: {
133
145
  readonly [key: string]: ViewBlock;
134
146
  };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * check.mjs Layer 3 at build, from source (#1784 items 1-2, part of #1758):
3
+ *
4
+ * - calc names: every `"Name"` inside a block's `calc` should be a field of
5
+ * the app or element the block reads from. Build knows only the owner's
6
+ * authored fields, and pull can leave some fields unextracted (#1736/#1966),
7
+ * so build warns; plan fails a calc name that is not an exact live field
8
+ * name, including a case difference. A block that reads
9
+ * from another app or a raw id is checked only at plan.
10
+ * - tag-dependent helpers: a preset, sort option or table column that needs a
11
+ * tagged field the owner does not have. Warnings, as in check.mjs. App
12
+ * system tags (STATUS, CREATED_AT, CLOSED_AT, ...) exist on every app, so
13
+ * build skips them for apps; an element has only HANDLE and TITLE, plus the
14
+ * audit tags when it declares `systemFields.audit`. The Open/Closed toggle's
15
+ * STATUS option tagged CLOSED is only checked at plan.
16
+ *
17
+ * Typed field refs already fail the build when they don't resolve, and field
18
+ * and option ids written as unsafePlatformId(...) can only be checked against
19
+ * the live App, so the provider does those at plan.
20
+ */
21
+ import type { BuildFieldMetadata } from "../../graph/types.js";
22
+ export interface CustomViewReferenceOptions {
23
+ /** The view owner's catalog key and kind; blocks reading another source are checked at plan. */
24
+ readonly ownerRefName?: string;
25
+ readonly ownerKind?: "app" | "element";
26
+ /** Element owners only: the element declares `systemFields.audit` (Created/Updated on/by). */
27
+ readonly ownerAuditFields?: boolean;
28
+ /** Field bag key → display name (system keys included when source names them). */
29
+ readonly fieldNames?: ReadonlyMap<string, string>;
30
+ readonly fieldMetadata?: ReadonlyMap<string, BuildFieldMetadata>;
31
+ }
32
+ /** Layer 3 from source. Everything here is a build warning; plan is authoritative against the live App. */
33
+ export declare function checkCustomViewReferences(elements: Readonly<Record<string, unknown>>, where: string, opts: CustomViewReferenceOptions, warn: (at: string, msg: string) => void): void;
@@ -0,0 +1,140 @@
1
+ import { DEFAULT_SYSTEM_FIELD_NAME_BY_TAG, DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_TAG_BY_KEY, } from "../../core/system-fields.js";
2
+ import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
3
+ /** check.mjs SYSTEM_KEY_TAG: system keys in sort options and table columns, and the tag each needs. */
4
+ const SYSTEM_KEY_TAG = {
5
+ handle: "HANDLE",
6
+ title: "TITLE",
7
+ status: "STATUS",
8
+ priority: "PRIORITY",
9
+ stage: "STAGE",
10
+ assignee: "ASSIGNEE",
11
+ assignmentGroup: "ASSIGNMENT_GROUP",
12
+ createdBy: "CREATED_BY",
13
+ createdTime: "CREATED_AT",
14
+ updatedAt: "UPDATED_AT",
15
+ };
16
+ /** Tags every app has as a system field; plan checks these against the live App. */
17
+ const APP_SYSTEM_TAGS = new Set(Object.values(SYSTEM_FIELD_TAG_BY_KEY));
18
+ /** The system fields an element has: id and title, plus the audit fields when it declares them. */
19
+ function elementSystemKeys(auditFields) {
20
+ return auditFields ? ELEMENT_SYSTEM_FIELD_KEYS : ["id", "title"];
21
+ }
22
+ function ownerSystemKeys(opts) {
23
+ return opts.ownerKind === "element" ? elementSystemKeys(opts.ownerAuditFields === true) : SYSTEM_FIELD_KEYS;
24
+ }
25
+ const CALC_NAME = /"([^"]+)"/g;
26
+ /** check.mjs PRESET_TAG. */
27
+ function presetTag(preset) {
28
+ if (preset.startsWith("created"))
29
+ return preset === "createdByCurrentUser" ? "CREATED_BY" : "CREATED_AT";
30
+ if (preset.startsWith("closed"))
31
+ return "CLOSED_AT";
32
+ return "ASSIGNEE";
33
+ }
34
+ function isObj(v) {
35
+ return v !== null && typeof v === "object" && !Array.isArray(v);
36
+ }
37
+ /**
38
+ * Whether a block reads from the view's owner: no source prop, the host
39
+ * binding (`{ $state: "/host/aspectId" }`), or a typed ref to the owner.
40
+ * A raw id or another app's ref is someone else's fields.
41
+ */
42
+ function readsOwner(props, opts) {
43
+ const source = props["aspectId"] ?? props["filterAspectId"];
44
+ if (source == null)
45
+ return true;
46
+ if (!isObj(source))
47
+ return false;
48
+ if (source["$state"] === "/host/aspectId" || source["$bindState"] === "/host/aspectId")
49
+ return true;
50
+ const kind = source["__kind"];
51
+ return (kind === "app" || kind === "element")
52
+ && kind === (opts.ownerKind ?? "app")
53
+ && opts.ownerRefName !== undefined
54
+ && source["refName"] === opts.ownerRefName;
55
+ }
56
+ /** Every name a field of the owner may carry: authored names, plus defaults for the owner's system fields source leaves unnamed. */
57
+ function ownerFieldNames(opts) {
58
+ const names = new Set(opts.fieldNames?.values() ?? []);
59
+ for (const key of ownerSystemKeys(opts)) {
60
+ if (opts.fieldNames?.has(key) === true)
61
+ continue;
62
+ const tag = SYSTEM_FIELD_TAG_BY_KEY[key];
63
+ // A platform-composed app and an EDK deploy name system fields differently.
64
+ names.add(DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[key]);
65
+ const composed = DEFAULT_SYSTEM_FIELD_NAME_BY_TAG[tag];
66
+ if (composed !== undefined)
67
+ names.add(composed);
68
+ }
69
+ return names;
70
+ }
71
+ /** Layer 3 from source. Everything here is a build warning; plan is authoritative against the live App. */
72
+ export function checkCustomViewReferences(elements, where, opts, warn) {
73
+ if (opts.fieldNames === undefined)
74
+ return;
75
+ const owner = opts.ownerKind === "element" ? "this element" : "this app";
76
+ const names = ownerFieldNames(opts);
77
+ const lowerNames = new Map([...names].map((name) => [name.toLowerCase(), name]));
78
+ // Tags the owner has: authored ones, plus its system fields'. Every app has
79
+ // all the system tags, so for an app those are plan's to check.
80
+ const ownerTags = new Set(opts.ownerKind === "element" ? ownerSystemKeys(opts).map((key) => SYSTEM_FIELD_TAG_BY_KEY[key]) : APP_SYSTEM_TAGS);
81
+ for (const meta of opts.fieldMetadata?.values() ?? [])
82
+ for (const tag of meta.tags ?? [])
83
+ ownerTags.add(tag);
84
+ const grouped = new Map();
85
+ const need = (at, tag, what) => {
86
+ if (ownerTags.has(tag))
87
+ return;
88
+ const message = `${what} relies on a field tagged ${tag}, and ${owner} has none, so it will show nothing or do nothing`;
89
+ let places = grouped.get(message);
90
+ if (places === undefined)
91
+ grouped.set(message, (places = new Set()));
92
+ places.add(at);
93
+ };
94
+ for (const [id, raw] of Object.entries(elements)) {
95
+ if (!isObj(raw) || !isObj(raw["props"]))
96
+ continue;
97
+ const props = raw["props"];
98
+ if (!readsOwner(props, opts))
99
+ continue;
100
+ const elWhere = `${where}.elements.${id}`;
101
+ if (typeof props["calc"] === "string") {
102
+ for (const match of props["calc"].matchAll(CALC_NAME)) {
103
+ const name = match[1];
104
+ if (names.has(name))
105
+ continue;
106
+ const loose = lowerNames.get(name.toLowerCase());
107
+ // A warning, not an error: a pulled owner can have live fields pull left
108
+ // unextracted (#1736/#1966). Plan fails a calc name that is not an exact
109
+ // live field name, including a case difference.
110
+ warn(`${elWhere}.calc`, loose !== undefined
111
+ ? `no field "${name}"; did you mean "${loose}"? Calc names are field display names and are case-sensitive. Plan fails a calc name that is not an exact live field name, including a case difference`
112
+ : `no field named "${name}" among ${owner}'s authored fields; calc names a field by its display name. Plan fails a calc name that is not an exact live field name, including a case difference`);
113
+ }
114
+ }
115
+ const presets = [props["filterPreset"]].flat().filter((v) => typeof v === "string");
116
+ for (const preset of presets)
117
+ need(elWhere, presetTag(preset), `preset "${preset}"`);
118
+ if (Array.isArray(props["sortByOptions"])) {
119
+ for (const option of props["sortByOptions"]) {
120
+ const value = isObj(option) ? option["value"] : undefined;
121
+ const tag = typeof value === "string" ? SYSTEM_KEY_TAG[value] : undefined;
122
+ if (tag !== undefined)
123
+ need(elWhere, tag, `sort option "${value}"`);
124
+ }
125
+ }
126
+ if (raw["type"] === "DataTableBlock" && Array.isArray(props["columns"])) {
127
+ for (const column of props["columns"]) {
128
+ const key = typeof column === "string" ? column : isObj(column) ? column["key"] : undefined;
129
+ const tag = typeof key === "string" ? SYSTEM_KEY_TAG[key] : undefined;
130
+ if (tag !== undefined)
131
+ need(elWhere, tag, `column "${key}"`);
132
+ }
133
+ }
134
+ }
135
+ // Group identical problems so a repeated section reports once (check.mjs).
136
+ for (const [message, places] of grouped) {
137
+ const list = [...places];
138
+ warn(list.length > 3 ? `${list.slice(0, 3).join(", ")} and ${list.length - 3} more` : list.join(", "), message);
139
+ }
140
+ }
@@ -1,19 +1,26 @@
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
- * Layer 3 catalog checks (calc field names, option ids, tag helpers against
10
- * the live App) need aspect-aware resolution; typed field refs already fail
11
- * via resolveField. Syntax-only calc rules (AVG / empty COUNT) live here.
12
- * TODO(#1784): consume fieldNames / fieldMetadata for Layer 3 + tag helpers.
11
+ * Layer 3 from source (calc names, tag-dependent helpers) is in
12
+ * custom-view-references.ts (#1784); typed field refs already fail via
13
+ * resolveField, and raw ids are checked at plan against the live App.
14
+ * Syntax-only calc rules (AVG / empty COUNT) live here.
13
15
  */
14
16
  import type { BuildFieldMetadata } from "../../graph/types.js";
15
17
  export interface CustomViewValidateOptions {
16
- /** TODO(#1784): aspect-aware Layer 3 once #1770 lands Preston custom views. */
18
+ /** The view owner; Layer 3 checks blocks that read from it (#1784). */
19
+ readonly ownerRefName?: string;
20
+ readonly ownerKind?: "app" | "element";
21
+ /** Element owners only: the element declares `systemFields.audit`. */
22
+ readonly ownerAuditFields?: boolean;
23
+ /** Owner field bag key → display name, for calc names (#1784). */
17
24
  readonly fieldNames?: ReadonlyMap<string, string>;
18
25
  readonly fieldMetadata?: ReadonlyMap<string, BuildFieldMetadata>;
19
26
  /** Build warnings (check.mjs `warn`); pushed, never thrown. */
@@ -1,4 +1,5 @@
1
1
  import { EntityTfError } from "../../engine/entity.js";
2
+ import { checkCustomViewReferences } from "./custom-view-references.js";
2
3
  const CONTAINERS = new Set(["PanesBlock", "StackBlock", "RowBlock", "CardBlock"]);
3
4
  const LIST_BLOCKS = new Set(["ListCollectionBlock", "DataTableBlock"]);
4
5
  const FILTER_GROUPS = new Set(["AND", "OR"]);
@@ -15,6 +16,18 @@ function isObj(v) {
15
16
  function isBinding(v) {
16
17
  return isObj(v) && ("$state" in v || "$bindState" in v || "$item" in v || "$index" in v);
17
18
  }
19
+ /**
20
+ * A $state / $bindState binding's state path, exactly as the Go provider's
21
+ * bindingTarget: a string $state wins, else a string $bindState; "" is no target.
22
+ */
23
+ function bindingTarget(v) {
24
+ if (!isObj(v))
25
+ return undefined;
26
+ const state = v["$state"];
27
+ const bind = v["$bindState"];
28
+ const target = typeof state === "string" ? state : typeof bind === "string" ? bind : undefined;
29
+ return target === "" ? undefined : target;
30
+ }
18
31
  /** Selection props must be $state / $bindState — $item / $index do not drive the details pane. */
19
32
  function isStateBinding(v) {
20
33
  return isObj(v) && ("$state" in v || "$bindState" in v);
@@ -156,9 +169,25 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
156
169
  return { found: true, value: node };
157
170
  };
158
171
  const walkedState = new Set();
159
- const walkFilter = (node, filterWhere) => {
172
+ const walkFilter = (node, filterWhere, fromState = false) => {
160
173
  if (node == null)
161
174
  return;
175
+ // In element props, a binding stands for the filter held in state, at the top
176
+ // of filterJson or as a child of an AND/OR group (edk#2923): the page resolves
177
+ // prop bindings. Check its initial value once, at its state path; a missing
178
+ // path is the binding scan's warning. Nothing shows the page resolving a
179
+ // binding inside a state value, so there it stays a filter node missing "type".
180
+ if (!fromState && isBinding(node)) {
181
+ const target = bindingTarget(node);
182
+ if (typeof target !== "string" || walkedState.has(target))
183
+ return;
184
+ const initial = readState(target);
185
+ if (initial.found && initial.value != null) {
186
+ walkedState.add(target);
187
+ walkFilter(initial.value, `${where}.state${target.replaceAll("/", ".")}`, true);
188
+ }
189
+ return;
190
+ }
162
191
  if (!isObj(node)) {
163
192
  note(filterWhere, "a filter must be an object");
164
193
  return;
@@ -174,7 +203,7 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
174
203
  note(filterWhere, `${node["type"]} needs a "children" list`);
175
204
  return;
176
205
  }
177
- node["children"].forEach((c, i) => walkFilter(c, `${filterWhere}.children[${i}]`));
206
+ node["children"].forEach((c, i) => walkFilter(c, `${filterWhere}.children[${i}]`, fromState));
178
207
  return;
179
208
  }
180
209
  if (typeof node["type"] !== "string") {
@@ -190,9 +219,11 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
190
219
  const type = raw["type"];
191
220
  const scan = (value, path) => {
192
221
  if (isBinding(value)) {
193
- const target = value["$state"] ?? value["$bindState"];
222
+ const target = bindingTarget(value);
194
223
  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.`);
224
+ // Warn, not fail (edk#2923): the page reads a missing path as undefined,
225
+ // and pulled live layouts rely on that, so failing would block the build.
226
+ 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
227
  }
197
228
  return;
198
229
  }
@@ -204,20 +235,8 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
204
235
  };
205
236
  for (const [key, value] of Object.entries(props))
206
237
  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
- }
238
+ if (props["filterJson"] !== undefined)
239
+ walkFilter(props["filterJson"], `${elWhere}.filterJson`);
221
240
  if (typeof props["calc"] === "string") {
222
241
  const calc = props["calc"];
223
242
  if (AVG_CALL.test(calc))
@@ -247,6 +266,7 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
247
266
  }
248
267
  }
249
268
  }
269
+ checkCustomViewReferences(elements, where, opts, warn);
250
270
  throwIf(problems);
251
271
  }
252
272
  function throwIf(problems) {
@@ -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
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Build checks for record details layouts that read badly (#1774).
3
+ *
4
+ * Classic `layouts` get the checks below (typed `dynamicLayouts` get theirs
5
+ * in `src/entities/dynamic-layout/lint.ts`), the same ones the generated
6
+ * layout avoids (`src/scripts/lib/record-layout-scaffold.ts`):
7
+ * - a group section that renders empty;
8
+ * - one long column of fields instead of labeled groups;
9
+ * - a right-panel section that shares a `displayOrder` with a main-area
10
+ * section, which the platform reads back in a different order, so plan
11
+ * replaces the layout.
12
+ *
13
+ * Those are advisories (`ADVISORY_DIAGNOSTICS` in
14
+ * `src/engine/coverage-gaps.ts`): the layout is built and applied exactly as
15
+ * authored, so they are printed but never counted as coverage gaps.
16
+ *
17
+ * `maxColumns` on a non-group section is the one real coverage gap here:
18
+ * `layoutToTf` emits `max_columns` only on group sections, so build drops it.
19
+ */
20
+ import type { AppLayoutWire } from "./to-tf.js";
21
+ /** More fields than this in a one-column stack reads as one long column. */
22
+ export declare const LONG_COLUMN_FIELD_COUNT = 8;
23
+ /** More fields than this in one group should be split into labeled groups. */
24
+ export declare const LONG_GROUP_FIELD_COUNT = 12;
25
+ /** Checks for one stage's classic layout, pushed onto `diagnostics`. */
26
+ export declare function lintClassicLayout(where: string, layout: AppLayoutWire, diagnostics: string[]): void;
@@ -0,0 +1,50 @@
1
+ /** More fields than this in a one-column stack reads as one long column. */
2
+ export const LONG_COLUMN_FIELD_COUNT = 8;
3
+ /** More fields than this in one group should be split into labeled groups. */
4
+ export const LONG_GROUP_FIELD_COUNT = 12;
5
+ /** Checks for one stage's classic layout, pushed onto `diagnostics`. */
6
+ export function lintClassicLayout(where, layout, diagnostics) {
7
+ const at = (index) => {
8
+ const name = layout.sections[index]?.name;
9
+ return `${where}.sections[${index}]${name ? ` ("${name}")` : ""}`;
10
+ };
11
+ for (const [index, section] of layout.sections.entries()) {
12
+ const type = section.type ?? "group";
13
+ if (type !== "group") {
14
+ if (section.maxColumns !== undefined) {
15
+ diagnostics.push(`${at(index)}: maxColumns only applies to group sections, so build dropped it from this ${type} section; remove it`);
16
+ }
17
+ continue;
18
+ }
19
+ const fields = section.fields?.length ?? 0;
20
+ const widgets = section.widgets?.length ?? 0;
21
+ if (fields === 0 && widgets === 0 && section.agent === undefined) {
22
+ diagnostics.push(`${at(index)}: group section has no fields, widgets or agent, so the record page shows an empty section; add fields or remove it`);
23
+ continue;
24
+ }
25
+ if (fields > LONG_GROUP_FIELD_COUNT) {
26
+ diagnostics.push(`${at(index)}: group section holds ${fields} fields; split them into labeled groups (key fields first) so the record page doesn't read as one long list`);
27
+ }
28
+ else if (fields > LONG_COLUMN_FIELD_COUNT && section.maxColumns === 1) {
29
+ diagnostics.push(`${at(index)}: group section stacks ${fields} fields in one column (maxColumns: 1); use maxColumns: 2 or split it into labeled groups`);
30
+ }
31
+ }
32
+ // displayOrder ranks sections across both locations (the provider writes
33
+ // the omitted values as CENTER and 0), and the platform reads the layout
34
+ // back sorted by it, so a tie between the panels can come back reordered.
35
+ const centerByOrder = new Map();
36
+ for (const [index, section] of layout.sections.entries()) {
37
+ const order = section.displayOrder ?? 0;
38
+ if ((section.displayLocation ?? "CENTER") !== "RIGHT" && !centerByOrder.has(order))
39
+ centerByOrder.set(order, index);
40
+ }
41
+ for (const [index, section] of layout.sections.entries()) {
42
+ if (section.displayLocation !== "RIGHT")
43
+ continue;
44
+ const order = section.displayOrder ?? 0;
45
+ const center = centerByOrder.get(order);
46
+ if (center === undefined)
47
+ continue;
48
+ diagnostics.push(`${at(index)}: right-panel section shares displayOrder ${order} with main-area ${at(center)}; the platform reads sections back by displayOrder, so plan replaces this layout on every run. Give each section its own displayOrder, counted across both panels`);
49
+ }
50
+ }
@@ -131,6 +131,8 @@ export interface ViewToTfOptions {
131
131
  readonly fieldAddresses?: ReadonlyMap<string, string>;
132
132
  /** Field bag key → display name (custom-view calc checks). */
133
133
  readonly fieldNames?: ReadonlyMap<string, string>;
134
+ /** Element owners only: the element declares `systemFields.audit` (custom-view calc and tag checks). */
135
+ readonly ownerAuditFields?: boolean;
134
136
  /** Field bag key → metadata (custom-view tag / calc checks). */
135
137
  readonly fieldMetadata?: ReadonlyMap<string, import("../../graph/types.js").BuildFieldMetadata>;
136
138
  /** Declared sibling widget keys, for typed classic-layout placement. */