@elementumai/edk 0.9.18 → 0.9.20

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 (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -11,7 +11,7 @@
11
11
  import type { ApprovalChainRef, AppOrElementRef, DatamineRef, FieldRef } from "../../catalog/index.js";
12
12
  import type { UnsafePlatformId } from "../../core/platform-id.js";
13
13
  import type { RecordShape } from "../field/record-shape.js";
14
- import { type InferTriggerType, type TriggerInputFieldDef, type TriggerInputSchema } from "../../core/triggers/on-demand.js";
14
+ import { type InferTriggerType, type WithOnDemandTriggeredBy, type TriggerInputFieldDef, type TriggerInputSchema } from "../../core/triggers/on-demand.js";
15
15
  import type { TriggerFieldTypeAlias } from "../shared/types/field-types.js";
16
16
  import type { Filter } from "./filter.js";
17
17
  import { type TriggerChain } from "./build.js";
@@ -71,7 +71,9 @@ type NormalizeSpec<S extends TriggerInputSchemaSpec> = {
71
71
  type: S[K];
72
72
  } : Extract<S[K], TriggerInputFieldDef>;
73
73
  };
74
- export declare function onDemand<S extends TriggerInputSchemaSpec>(schema: S): TriggerChain<InferTriggerType<NormalizeSpec<S> & TriggerInputSchema>>;
74
+ export declare function onDemand<S extends TriggerInputSchemaSpec>(schema: S & {
75
+ readonly triggeredBy?: never;
76
+ }): TriggerChain<WithOnDemandTriggeredBy<InferTriggerType<NormalizeSpec<S> & TriggerInputSchema>, NormalizeSpec<S>>>;
75
77
  export interface WebhookTriggerOptions {
76
78
  readonly authenticated?: boolean;
77
79
  /** Pre-built wire custom-response envelope. */
@@ -1,3 +1,4 @@
1
+ import { EdkValidationError } from "../../../elementum-entity-client/errors.js";
1
2
  import { serializeOnDemandTrigger, } from "../../core/triggers/on-demand.js";
2
3
  import { chainableTrigger } from "./build.js";
3
4
  function recordTriggerFields(opts) {
@@ -65,6 +66,9 @@ export function schedule(opts) {
65
66
  });
66
67
  }
67
68
  export function onDemand(schema) {
69
+ if (Object.hasOwn(schema, "triggeredBy")) {
70
+ throw new EdkValidationError('onDemand input "triggeredBy" is reserved: ctx.trigger.triggeredBy is the user who ran the automation. Rename the input.');
71
+ }
68
72
  const normalized = Object.fromEntries(Object.entries(schema).map(([k, v]) => [k, typeof v === "string" ? { type: v } : v]));
69
73
  return chainableTrigger({
70
74
  wire: serializeOnDemandTrigger(normalized),
@@ -76,6 +76,7 @@ export const TASK_SUB_TYPES = [
76
76
  { typeKey: "addWatcher", resourceType: "elementum_add_watcher_task", implemented: true },
77
77
  { typeKey: "saveAttachment", resourceType: "elementum_save_attachment_task", implemented: true },
78
78
  { typeKey: "userSearch", resourceType: "elementum_user_search_task", implemented: true },
79
+ { typeKey: "userGroupSearch", resourceType: "elementum_user_group_search_task", implemented: true },
79
80
  { typeKey: "aspectRecordFieldLocking", resourceType: "elementum_aspect_record_field_locking_task", implemented: true },
80
81
  { typeKey: "initiateCall", resourceType: "elementum_initiate_call_task", implemented: true },
81
82
  // Operators (branching) — later phases:
@@ -4,6 +4,7 @@ import { FIELD_RESOURCE_TYPES } from "../field/types.js";
4
4
  import { fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { filterFromTf } from "../shared/filters/tf-codec.js";
6
6
  import { CHART_RESOURCE_TYPE } from "./types.js";
7
+ import { dataAspectDisplayName } from "../shared/aspect-target-from-tf.js";
7
8
  const APP_RESOURCE_TYPE = "elementum_app";
8
9
  const TABLE_RESOURCE_TYPE = "elementum_table";
9
10
  function decodeJson(value) {
@@ -34,22 +35,35 @@ function datasourceFromTf(value, appLabel, appRefName, ctx, where) {
34
35
  }
35
36
  const dataLabel = dataRefLabel(value, type);
36
37
  if (dataLabel !== undefined) {
38
+ if (kind === "app" || kind === "element") {
39
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
40
+ const namespace = typeof attrs?.["namespace"] === "string" && attrs["namespace"] !== "" ? attrs["namespace"] : undefined;
41
+ const name = dataAspectDisplayName(ctx, kind, dataLabel);
42
+ // The printer emits catalog members. Bind their actual keys, and never
43
+ // substitute a same-name target when the stable namespace is unknown.
44
+ const refName = namespace !== undefined
45
+ ? (kind === "app" ? ctx.foreignAppRefNamespaces : ctx.foreignElementRefNamespaces)?.get(namespace)
46
+ : name !== undefined
47
+ ? (kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames)?.get(name)
48
+ : undefined;
49
+ if (refName === undefined) {
50
+ ctx.diagnostics.push(`${where}: ${kind} datasource ${namespace ?? name ?? dataLabel} cannot be resolved to the pulled catalog; skipped`);
51
+ return undefined;
52
+ }
53
+ return { kind, refName, ...(name !== undefined ? { name } : {}), local: false, tfLabel: dataLabel };
54
+ }
37
55
  const name = ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel);
38
- const refName = kind === "app"
39
- ? ctx.foreignAppRefNames?.get(name) ?? tfLabelToTsLabel(dataLabel)
40
- : kind === "element"
41
- ? ctx.foreignElementRefNames?.get(name) ?? tfLabelToTsLabel(dataLabel)
42
- : kind === "task"
43
- ? tfLabelToTsLabel(dataLabel)
44
- : (() => {
45
- const attrs = ctx.dataAttrs?.(type, dataLabel);
46
- const id = typeof attrs?.["id"] === "string" ? attrs["id"] : ctx.importId(`data.${type}.${dataLabel}`);
47
- const byId = id === undefined ? undefined : ctx.foreignTableRefsById?.get(id);
48
- if (byId !== undefined)
49
- return byId.tableRefName;
50
- const matches = [...(ctx.foreignTableRefsById?.values() ?? [])].filter((candidate) => candidate.name === name);
51
- return matches.length === 1 ? matches[0].tableRefName : undefined;
52
- })();
56
+ const refName = kind === "task"
57
+ ? tfLabelToTsLabel(dataLabel)
58
+ : (() => {
59
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
60
+ const id = typeof attrs?.["id"] === "string" ? attrs["id"] : ctx.importId(`data.${type}.${dataLabel}`);
61
+ const byId = id === undefined ? undefined : ctx.foreignTableRefsById?.get(id);
62
+ if (byId !== undefined)
63
+ return byId.tableRefName;
64
+ const matches = [...(ctx.foreignTableRefsById?.values() ?? [])].filter((candidate) => candidate.name === name);
65
+ return matches.length === 1 ? matches[0].tableRefName : undefined;
66
+ })();
53
67
  if (refName === undefined) {
54
68
  ctx.diagnostics.push(`${where}: table datasource ${name} cannot be resolved to the org catalog; skipped`);
55
69
  return undefined;
@@ -216,8 +230,10 @@ function parseSubscription(value, appLabel, appRefName, ctx, where) {
216
230
  return undefined;
217
231
  }
218
232
  const field = column["column_id"] !== undefined ? fieldFromTf(column["column_id"], datasource, ctx, `${where}.columns[${index}].column_id`) : undefined;
219
- if (column["column_id"] !== undefined && field === undefined)
220
- continue;
233
+ if (column["column_id"] !== undefined && field === undefined) {
234
+ ctx.diagnostics.push(`${where}.columns[${index}]: unresolved field; subscription skipped to preserve all chart series`);
235
+ return undefined;
236
+ }
221
237
  if (column["expression"] !== undefined) {
222
238
  ctx.diagnostics.push(`${where}.columns[${index}].expression: unsupported chart expression; subscription skipped`);
223
239
  return undefined;
@@ -1,6 +1,7 @@
1
1
  import { bareFactoryEntry } from "../../catalog/render-helpers.js";
2
2
  import { NO_CANVAS } from "../../graph/types.js";
3
3
  import { chartFromTf } from "./from-tf.js";
4
+ import { rebindChartOwner } from "./rebind-owner.js";
4
5
  import { printChart } from "./printer.js";
5
6
  import { chartToTf } from "./to-tf.js";
6
7
  import { CHART_RESOURCE_TYPE } from "./types.js";
@@ -33,9 +34,10 @@ export const chartModule = {
33
34
  }
34
35
  return { items, skipped, diagnostics: [] };
35
36
  },
37
+ rebindOwnFileOwner: (item, from, to) => rebindChartOwner(item, from, to),
36
38
  printOwnFile: (item, opts) => ({
37
39
  refName: item.refName,
38
- source: printChart(item, { appRefName: opts.appRefName, orgImportPath: opts.orgImportPath }),
40
+ source: printChart(item, { appRefName: opts.appRefName, orgImportPath: opts.orgImportPath, elementCatalogKeys: opts.elementCatalogKeys }),
39
41
  }),
40
42
  toTf: (entity, ctx) => chartToTf(entity, {
41
43
  appRefName: ctx.appRefName,
@@ -2,4 +2,5 @@ import type { NormalizedChart } from "./from-tf.js";
2
2
  export declare function printChart(chart: NormalizedChart, opts: {
3
3
  readonly appRefName: string;
4
4
  readonly orgImportPath: string;
5
+ readonly elementCatalogKeys?: ReadonlyMap<string, string>;
5
6
  }): string;
@@ -9,13 +9,23 @@ function constantKey(values, value, domain) {
9
9
  throw new Error(`chart pull: unsupported ${domain} ${JSON.stringify(value)}`);
10
10
  return entry[0];
11
11
  }
12
- function dataExpr(value) {
13
- return value.kind === "table" ? `catalog.tables${member(value.refName)}` : `catalog${member(value.refName)}`;
12
+ function elementKey(refName, keys) {
13
+ if (keys === undefined)
14
+ return refName;
15
+ const key = keys.get(refName);
16
+ if (key === undefined)
17
+ throw new Error(`chart pull: element ${JSON.stringify(refName)} has no catalog key`);
18
+ return key;
14
19
  }
15
- function fieldExpr(value) {
20
+ function dataExpr(value, keys) {
21
+ const key = value.kind === "element" ? elementKey(value.refName, keys) : value.refName;
22
+ return value.kind === "table" ? `catalog.tables${member(key)}` : `catalog${member(key)}`;
23
+ }
24
+ function fieldExpr(value, keys) {
25
+ const key = value.parentKind === "element" ? elementKey(value.parentRefName, keys) : value.parentRefName;
16
26
  return value.kind === "tableColumn"
17
- ? `catalog.tables${member(value.parentRefName)}.columns${member(value.refName)}`
18
- : `catalog${member(value.parentRefName)}.fields${member(value.refName)}`;
27
+ ? `catalog.tables${member(key)}.columns${member(value.refName)}`
28
+ : `catalog${member(key)}.fields${member(value.refName)}`;
19
29
  }
20
30
  function printOpaqueSubscription(subscription) {
21
31
  const attrs = Object.entries(subscription.attributes)
@@ -28,10 +38,10 @@ function printOpaqueSubscription(subscription) {
28
38
  " }),",
29
39
  ];
30
40
  }
31
- function printColumn(column) {
41
+ function printColumn(column, keys) {
32
42
  const parts = [];
33
43
  if (column.field !== undefined)
34
- parts.push(`field: ${fieldExpr(column.field)}`);
44
+ parts.push(`field: ${fieldExpr(column.field, keys)}`);
35
45
  if (column.aggregation !== undefined)
36
46
  parts.push(`aggregation: chartAggregation.${constantKey(chartAggregation, column.aggregation, "aggregation")}`);
37
47
  if (column.name !== undefined)
@@ -42,18 +52,18 @@ function printColumn(column) {
42
52
  parts.push(`valueType: chartColumnValueType.${constantKey(chartColumnValueType, column.valueType, "column value type")}`);
43
53
  return `{ ${parts.join(", ")} }`;
44
54
  }
45
- function printSubscription(subscription) {
46
- const lines = [" chartSubscription({", ` datasource: ${dataExpr(subscription.datasource)},`];
47
- lines.push(` columns: [${subscription.columns.map(printColumn).join(", ")}],`);
55
+ function printSubscription(subscription, keys) {
56
+ const lines = [" chartSubscription({", ` datasource: ${dataExpr(subscription.datasource, keys)},`];
57
+ lines.push(` columns: [${subscription.columns.map((column) => printColumn(column, keys)).join(", ")}],`);
48
58
  if (subscription.groupBy !== undefined) {
49
- lines.push(` groupBy: [${subscription.groupBy.map((group) => `{ field: ${fieldExpr(group.field)} }`).join(", ")}],`);
59
+ lines.push(` groupBy: [${subscription.groupBy.map((group) => `{ field: ${fieldExpr(group.field, keys)} }`).join(", ")}],`);
50
60
  }
51
61
  if (subscription.joins !== undefined) {
52
62
  lines.push(" joins: [");
53
63
  for (const join of subscription.joins) {
54
- const parts = [`from: ${dataExpr(subscription.datasource)}`, `datasource: ${dataExpr(join.datasource)}`];
55
- parts.push(`leftField: ${fieldExpr(join.leftField)}`);
56
- parts.push(`rightField: ${fieldExpr(join.rightField)}`);
64
+ const parts = [`from: ${dataExpr(subscription.datasource, keys)}`, `datasource: ${dataExpr(join.datasource, keys)}`];
65
+ parts.push(`leftField: ${fieldExpr(join.leftField, keys)}`);
66
+ parts.push(`rightField: ${fieldExpr(join.rightField, keys)}`);
57
67
  if (join.type !== undefined)
58
68
  parts.push(`type: chartJoinType.${constantKey(chartJoinType, join.type, "join type")}`);
59
69
  lines.push(` chartJoin({ ${parts.join(", ")} }),`);
@@ -62,7 +72,7 @@ function printSubscription(subscription) {
62
72
  }
63
73
  if (subscription.filter !== undefined) {
64
74
  lines.push(` filter: ${printFilter(subscription.filter, {
65
- field: fieldExpr,
75
+ field: (field) => fieldExpr(field, keys),
66
76
  aspect: () => { throw new Error("chart pull: filter aspect overrides are unsupported"); },
67
77
  reference: () => { throw new Error("chart pull: filter references are unsupported"); },
68
78
  })},`);
@@ -117,7 +127,7 @@ export function printChart(chart, opts) {
117
127
  if (subscription.kind === "opaque")
118
128
  lines.push(...printOpaqueSubscription(subscription));
119
129
  else
120
- lines.push(...printSubscription(subscription));
130
+ lines.push(...printSubscription(subscription, opts.elementCatalogKeys));
121
131
  }
122
132
  lines.push(" ],", "});", "", "export default chart;", "");
123
133
  return lines.join("\n");
@@ -0,0 +1,3 @@
1
+ import type { NormalizedChart } from "./from-tf.js";
2
+ /** Rebind self references only; foreign roots can share the export owner's key. */
3
+ export declare function rebindChartOwner(chart: NormalizedChart, from: string, to: string): NormalizedChart;
@@ -0,0 +1,42 @@
1
+ /** Rebind self references only; foreign roots can share the export owner's key. */
2
+ export function rebindChartOwner(chart, from, to) {
3
+ if (from === to)
4
+ return chart;
5
+ const isSelf = (datasource) => datasource.local && datasource.kind === "app" && datasource.refName === from;
6
+ const datasource = (value) => isSelf(value) ? { ...value, refName: to } : value;
7
+ const field = (value, owner) => isSelf(owner) && value.parentKind === "app" && value.parentRefName === from
8
+ ? { ...value, parentRefName: to } : value;
9
+ // Filters can nest fields in composite children, leftValue, or FIELD values.
10
+ // Transform typed field nodes rather than arbitrary names/strings in the AST.
11
+ const filterFields = (value, owner) => {
12
+ if (Array.isArray(value))
13
+ return value.map((item) => filterFields(item, owner));
14
+ if (value === null || typeof value !== "object")
15
+ return value;
16
+ const node = value;
17
+ if (node["kind"] === "field" && node["parentKind"] === "app" && node["parentRefName"] === from) {
18
+ return field(value, owner);
19
+ }
20
+ return Object.fromEntries(Object.entries(node).map(([key, item]) => [key, filterFields(item, owner)]));
21
+ };
22
+ return { ...chart, subscriptions: chart.subscriptions.map((subscription) => {
23
+ if (subscription.kind === "opaque")
24
+ return subscription;
25
+ return {
26
+ ...subscription,
27
+ datasource: datasource(subscription.datasource),
28
+ columns: subscription.columns.map((column) => column.field === undefined ? column
29
+ : { ...column, field: field(column.field, subscription.datasource) }),
30
+ ...(subscription.groupBy !== undefined && { groupBy: subscription.groupBy.map((group) => ({
31
+ ...group, field: field(group.field, subscription.datasource),
32
+ })) }),
33
+ ...(subscription.filter !== undefined && { filter: filterFields(subscription.filter, subscription.datasource) }),
34
+ ...(subscription.joins !== undefined && { joins: subscription.joins.map((join) => ({
35
+ ...join,
36
+ datasource: datasource(join.datasource),
37
+ leftField: field(join.leftField, subscription.datasource),
38
+ rightField: field(join.rightField, join.datasource),
39
+ })) }),
40
+ };
41
+ }) };
42
+ }
@@ -1,10 +1,11 @@
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 { fieldRefToTfValue } from "../field/to-tf.js";
4
+ import { authoredFieldKeysFromPayload, fieldRefToTfValue, } from "../field/to-tf.js";
5
5
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
6
6
  import { isUnsafePlatformId } from "../../core/platform-id.js";
7
7
  import { CHART_RESOURCE_TYPE } from "./types.js";
8
+ import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
8
9
  const APP_RESOURCE_TYPE = "elementum_app";
9
10
  const TABLE_RESOURCE_TYPE = "elementum_table";
10
11
  function datasourceId(ref, opts, where) {
@@ -14,23 +15,31 @@ function datasourceId(ref, opts, where) {
14
15
  if (ref.__kind !== "app" && ref.__kind !== "element" && ref.__kind !== "table" && ref.__kind !== "task") {
15
16
  throw new EntityTfError(`${where}: unsupported datasource kind ${JSON.stringify(ref.__kind)}`);
16
17
  }
17
- const local = opts.workspaceAspects?.get(workspaceAspectKey(ref.__kind, ref.refName));
18
+ const kind = ref.__kind;
19
+ const local = opts.workspaceAspects?.get(workspaceAspectKey(kind, ref.refName));
18
20
  if (local !== undefined) {
19
21
  const type = ref.__kind === "app" ? APP_RESOURCE_TYPE : ref.__kind === "element" ? "elementum_element" : ref.__kind === "task" ? "elementum_task" : TABLE_RESOURCE_TYPE;
20
- return { ref, id: expr.resourceAttr(type, local.tfLabel, ["id"]), tfLabel: local.tfLabel, local: true };
22
+ return {
23
+ ref,
24
+ kind,
25
+ id: expr.resourceAttr(type, local.tfLabel, ["id"]),
26
+ tfLabel: local.tfLabel,
27
+ local: true,
28
+ fieldOwnership: authoredFieldKeysFromPayload(local.streamRootEntity?.payload),
29
+ };
21
30
  }
22
31
  const name = ref.name ?? ref.refName;
32
+ if (ref.__kind === "app" || ref.__kind === "element") {
33
+ const foreign = resolveForeignRef(ref.__kind, { name, namespace: ref.namespace }, opts.orgRefs, opts.diagnostics, where);
34
+ return { ref, kind, id: foreign.value, tfLabel: foreign.tfLabel, local: false };
35
+ }
23
36
  const label = sanitizeName(name);
24
- if (ref.__kind === "app")
25
- opts.orgRefs.foreignApp(label, name);
26
- else if (ref.__kind === "element")
27
- opts.orgRefs.foreignElement(label, name);
28
- else if (ref.__kind === "task")
37
+ if (ref.__kind === "task")
29
38
  opts.orgRefs.rawLookup("elementum_task", label, name);
30
39
  else
31
40
  opts.orgRefs.rawLookup(TABLE_RESOURCE_TYPE, label, name);
32
- const type = ref.__kind === "app" ? APP_RESOURCE_TYPE : ref.__kind === "element" ? "elementum_element" : ref.__kind === "task" ? "elementum_task" : TABLE_RESOURCE_TYPE;
33
- return { ref, id: expr.dataAttr(type, label, ["id"]), tfLabel: label, local: false };
41
+ const type = ref.__kind === "task" ? "elementum_task" : TABLE_RESOURCE_TYPE;
42
+ return { ref, kind, id: expr.dataAttr(type, label, ["id"]), tfLabel: label, local: false };
34
43
  }
35
44
  function fieldId(ref, datasource, opts, where) {
36
45
  if (ref?.refName === undefined || ref.refName === "")
@@ -50,11 +59,11 @@ function fieldId(ref, datasource, opts, where) {
50
59
  throw new EntityTfError(`${where}: app/element fields cannot belong to a table datasource`);
51
60
  if (datasource.local && datasource.ref.__kind !== "task") {
52
61
  const scope = datasource.ref.__kind === "element" ? "element" : "app";
53
- const direct = fieldRefToTfValue(ref.fieldType ?? "", ref.refName, datasource.tfLabel, scope);
62
+ const direct = fieldRefToTfValue(ref.fieldType ?? "", ref.refName, datasource.tfLabel, scope, datasource.fieldOwnership);
54
63
  if (direct !== undefined)
55
64
  return direct;
56
65
  }
57
- const label = sanitizeName(`${datasource.ref.__kind}_${datasource.ref.refName}_${ref.refName}`);
66
+ const label = foreignFieldDataLabel(datasource.kind, datasource.tfLabel, ref.name ?? ref.refName);
58
67
  opts.orgRefs.foreignField("elementum_field", label, datasource.id, ref.name ?? ref.refName);
59
68
  return expr.dataAttr("elementum_field", label, ["id"]);
60
69
  }
@@ -1,5 +1,6 @@
1
1
  import type { AppCatalogRef, AppOrElementRef, ChartRef, FieldRef } from "../../catalog/index.js";
2
2
  import type { Filter } from "../shared/filters/types.js";
3
+ import type { ManagedViewSort } from "../view/build.js";
3
4
  declare const dashboardWidgetSizeBrand: unique symbol;
4
5
  declare const dashboardWidgetBrand: unique symbol;
5
6
  type DashboardWidgetSizeValue = "EXTRA_SMALL" | "SMALL" | "MEDIUM" | "LARGE" | "EXTRA_LARGE";
@@ -24,6 +25,7 @@ export interface DashboardRecordsWidget<Target extends AppOrElementRef = AppOrEl
24
25
  readonly type: "records";
25
26
  readonly target: Target;
26
27
  readonly filter?: Filter<FieldRef<Target["refName"]>, never>;
28
+ readonly sort?: ManagedViewSort;
27
29
  }
28
30
  export interface DashboardChartWidget<Parent extends string = string> extends DashboardWidgetBase {
29
31
  readonly [dashboardWidgetBrand]: "chart";
@@ -34,6 +36,8 @@ export interface DashboardChartWidget<Parent extends string = string> extends Da
34
36
  export declare function dashboardRecordsWidget<const Target extends AppOrElementRef>(opts: DashboardWidgetBase & {
35
37
  readonly target: Target;
36
38
  readonly filter?: Filter<FieldRef<NoInfer<Target>["refName"]>, never>;
39
+ /** Record order. Fields resolve against the dashboard's own app, so a non-empty sort requires `target` to be that app. */
40
+ readonly sort?: ManagedViewSort;
37
41
  }): DashboardRecordsWidget<Target>;
38
42
  /** Build a chart widget and enforce that chart and dashboard share an app owner. */
39
43
  export declare function dashboardChartWidget<const Parent extends string>(opts: DashboardWidgetBase & {
@@ -8,6 +8,7 @@ import { DASHBOARD_RESOURCE_TYPE } from "./module.js";
8
8
  import { CHART_RESOURCE_TYPE } from "../chart/types.js";
9
9
  import { dashboardWidgetSize } from "./build.js";
10
10
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
11
+ import { managedViewSortFromTf } from "../view/from-tf.js";
11
12
  const KNOWN_DASHBOARD_ATTRS = new Set(["name", "owner_id", "owner_type", "favorite", "tags"]);
12
13
  export function dashboardsFromTf(blocks, widgetBlocks, owner, ctx) {
13
14
  const dashboards = [];
@@ -68,16 +69,26 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, owner, ctx) {
68
69
  ctx.diagnostics.push(`${where}: expected an aspect_widget or chart_widget; skipped`);
69
70
  return [];
70
71
  }
71
- if (aspect["sort"] !== undefined) {
72
- ctx.diagnostics.push(`${where}.aspect_widget.sort: dashboard record sort has no typed public contract; skipped`);
73
- return [];
74
- }
75
72
  const target = aspectRef(aspect["aspect_id"], owner, ctx);
76
73
  if (target === undefined) {
77
74
  ctx.diagnostics.push(`${where}.aspect_widget.aspect_id: unresolved; skipped`);
78
75
  return [];
79
76
  }
77
+ // An unsupported sort is dropped on its own: skipping the widget would
78
+ // make the next apply destroy it.
79
+ let sort;
80
+ if (aspect["sort"] !== undefined) {
81
+ const targetsOwner = resourceRefLabel(aspect["aspect_id"], owner.type) === owner.label;
82
+ const decoded = managedViewSortFromTf(aspect["sort"], owner, `${where}.aspect_widget.sort`, ctx);
83
+ if (decoded !== undefined && !targetsOwner && decoded.orders.length > 0) {
84
+ ctx.diagnostics.push(`${where}.aspect_widget.sort: ordering a foreign target's records has no typed public contract; sort dropped, widget kept`);
85
+ }
86
+ else {
87
+ sort = decoded;
88
+ }
89
+ }
80
90
  return [{ ...style, type: "records", target,
91
+ ...(sort !== undefined && { sort }),
81
92
  ...(aspect["filter"] !== undefined && {
82
93
  filter: filterFromTf(filterWireToTf(decodeJson(aspect["filter"])), { ...owner, ownerRefName: owner.ownerRefName ?? owner.ownerTfLabel, foreignFieldRefsById: ctx.foreignFieldRefsById }, `${where}.aspect_widget.filter`, ctx),
83
94
  }),
@@ -1,6 +1,7 @@
1
1
  import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
2
2
  import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
+ import type { ManagedViewSort } from "../view/build.js";
4
5
  export interface AppDashboardWire {
5
6
  readonly name?: string;
6
7
  readonly favorite?: boolean;
@@ -24,6 +25,7 @@ type DashboardWidgetWire = (DashboardWidgetWireBase & {
24
25
  readonly type: "records";
25
26
  readonly target?: RefWire | string;
26
27
  readonly filter?: Filter;
28
+ readonly sort?: ManagedViewSort;
27
29
  }) | (DashboardWidgetWireBase & {
28
30
  readonly type: "chart";
29
31
  readonly chart?: RefWire | string;
@@ -6,6 +6,7 @@ import { DASHBOARD_WIDGET_RESOURCE_TYPE } from "../dashboard-widget/module.js";
6
6
  import { resolveForeignRef } from "../shared/foreign-ref.js";
7
7
  import { DASHBOARD_RESOURCE_TYPE } from "./module.js";
8
8
  import { CHART_RESOURCE_TYPE } from "../chart/types.js";
9
+ import { managedViewSortToTf } from "../view/to-tf.js";
9
10
  export function dashboardsToTf(dashboards, opts) {
10
11
  const blocks = [];
11
12
  for (const [key, dashboard] of Object.entries(dashboards ?? {})) {
@@ -60,6 +61,12 @@ export function dashboardsToTf(dashboards, opts) {
60
61
  });
61
62
  body["filter"] = expr.jsonencode(filterTfToWire(hclFilter));
62
63
  }
64
+ if (widget.sort !== undefined && widget.sort.orders.length > 0 && !targetsOwner(widget.target, opts)) {
65
+ opts.diagnostics.push(`${where}.sort: sort fields resolve against the dashboard's own app; a foreign target cannot be ordered; sort dropped, widget kept`);
66
+ }
67
+ else if (widget.sort !== undefined) {
68
+ body["sort"] = managedViewSortToTf(widget.sort, opts.ownerTfLabel, opts.scope, `${where}.sort`, opts.diagnostics);
69
+ }
63
70
  widgetAttrs["aspect_widget"] = body;
64
71
  }
65
72
  else if (widget.type === "chart") {
@@ -105,6 +112,12 @@ function resolveChart(value, where, opts) {
105
112
  }
106
113
  return expr.resourceAttr(CHART_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), opts.scope), ["id"]);
107
114
  }
115
+ function targetsOwner(value, opts) {
116
+ if (typeof value === "string" || value === undefined)
117
+ return false;
118
+ const kind = value.__kind === "element" ? "element" : "app";
119
+ return kind === opts.scope && value.refName === (opts.ownerRefName ?? opts.ownerTfLabel);
120
+ }
108
121
  function resolveAspect(value, where, opts) {
109
122
  if (typeof value === "string") {
110
123
  opts.diagnostics.push(`${where}: raw aspect ids are not supported in public authoring; dropped`);
@@ -7,4 +7,8 @@ export const dashboardWidgetModule = {
7
7
  parents: [{ parent: "dashboard", child: "dashboard-widget" }],
8
8
  resource: { shape: "single", resourceType: DASHBOARD_WIDGET_RESOURCE_TYPE, adoptable: true },
9
9
  data: NO_DATA, lifecycle: NO_LIFECYCLE, canvas: NO_CANVAS, catalog: NO_CATALOG,
10
+ roundtrip: {
11
+ referenceAliases: [],
12
+ nestedOmittedDefaults: [{ attribute: "aspect_widget", defaults: { not: false, semantic: false } }],
13
+ },
10
14
  };
@@ -1,5 +1,6 @@
1
- import type { AgentRef, AppOrElementRef, AutomationRef } from "../../catalog/index.js";
1
+ import type { AgentRef, AppOrElementRef, AutomationRef, FieldRef, WidgetRef } from "../../catalog/index.js";
2
2
  import type { AppViewFieldRef } from "../app/build.js";
3
+ import type { Filter } from "../shared/filters/types.js";
3
4
  export type DynamicLayoutTypedValue = {
4
5
  readonly string: string;
5
6
  } | {
@@ -51,6 +52,35 @@ export interface DynamicLayoutFieldComponent {
51
52
  readonly fullWidth?: boolean;
52
53
  readonly dependsOn?: readonly string[];
53
54
  }
55
+ /**
56
+ * Properties the layout editor offers on every block. Most blocks render only
57
+ * `label`; the editor stores and shows the rest, so they round-trip.
58
+ */
59
+ export interface DynamicLayoutBlockCommon {
60
+ readonly label?: string;
61
+ readonly title?: string;
62
+ readonly collapsed?: boolean;
63
+ readonly hidden?: boolean;
64
+ readonly sideNavItem?: boolean;
65
+ }
66
+ /** One automation trigger parameter an automation button supplies. */
67
+ export interface DynamicLayoutAutomationButtonInput {
68
+ /** On-demand trigger parameter of the button's automation (or of `automation`). */
69
+ readonly parameterName: string;
70
+ /** Automation whose on-demand trigger declares the parameter, when it is not the button's own. */
71
+ readonly automation?: AutomationRef;
72
+ /** Platform parameter id, only for a parameter the automation's trigger does not declare by name in this source. */
73
+ readonly parameterId?: string;
74
+ readonly fieldType?: string;
75
+ readonly multiple?: boolean;
76
+ readonly required?: boolean;
77
+ /** Value template; `{{name}}` placeholders are filled from `fieldRefParams`. */
78
+ readonly value?: string;
79
+ readonly fieldRefParams?: readonly {
80
+ readonly name: string;
81
+ readonly field: AppViewFieldRef;
82
+ }[];
83
+ }
54
84
  interface DynamicLayoutComponentCommon<ComponentKey extends string = string, ConditionKey extends string = string, SaveGroupKey extends string = string> {
55
85
  readonly children?: readonly ComponentKey[];
56
86
  readonly style?: DynamicLayoutStyle;
@@ -84,9 +114,12 @@ export interface DynamicLayoutComponentVariantMap {
84
114
  readonly className?: string;
85
115
  };
86
116
  readonly row: {
117
+ /** Equal-width grid columns (1-12); the row then ignores `justifyContent` and `wrap`. */
118
+ readonly columns?: number;
87
119
  readonly gap?: DynamicLayoutCssLength;
88
120
  readonly alignItems?: "start" | "center" | "end" | "stretch" | "baseline";
89
121
  readonly justifyContent?: "start" | "center" | "end" | "between" | "around" | "evenly";
122
+ /** The renderer wraps a row that leaves this unset. */
90
123
  readonly wrap?: boolean;
91
124
  readonly className?: string;
92
125
  };
@@ -122,6 +155,16 @@ export interface DynamicLayoutComponentVariantMap {
122
155
  readonly variant?: "default" | "outline" | "ghost" | "destructive";
123
156
  readonly icon?: string;
124
157
  readonly confirmMessage?: string;
158
+ /** App or element that owns the automation, as the layout editor records it. */
159
+ readonly automationApp?: AppOrElementRef;
160
+ readonly color?: string;
161
+ /** Column count of the parent grid the button sits in (1-12). */
162
+ readonly columns?: number;
163
+ /** Grid columns the button spans (1-12). */
164
+ readonly span?: number;
165
+ readonly inputs?: readonly DynamicLayoutAutomationButtonInput[];
166
+ /** Run-automation widget the button executes through; omit to have build derive one. */
167
+ readonly widget?: WidgetRef;
125
168
  };
126
169
  readonly createButton: {
127
170
  readonly target: AppOrElementRef;
@@ -133,8 +176,7 @@ export interface DynamicLayoutComponentVariantMap {
133
176
  readonly variant?: "default" | "outline" | "ghost";
134
177
  readonly icon?: string;
135
178
  };
136
- readonly updateBlock: {
137
- readonly title?: string;
179
+ readonly updateBlock: DynamicLayoutBlockCommon & {
138
180
  readonly fields?: readonly AppViewFieldRef[];
139
181
  readonly submitLabel?: string;
140
182
  };
@@ -159,33 +201,23 @@ export interface DynamicLayoutComponentVariantMap {
159
201
  readonly currency?: string;
160
202
  readonly locale?: string;
161
203
  };
162
- readonly stageBlock: {
163
- readonly label?: string;
164
- };
165
- readonly slaBlock: {
166
- readonly label?: string;
167
- };
168
- readonly activityLogBlock: {
169
- readonly label?: string;
170
- };
171
- readonly approvalsBlock: {
172
- readonly label?: string;
173
- };
174
- readonly attachmentsBlock: {
175
- readonly label?: string;
176
- };
177
- readonly relatedTasksBlock: {
178
- readonly label?: string;
179
- };
180
- readonly relationshipsBlock: {
181
- readonly label?: string;
182
- };
183
- readonly relatedItemsBlock: {
184
- readonly label?: string;
185
- };
186
- readonly surveysBlock: {
187
- readonly label?: string;
204
+ readonly stageBlock: DynamicLayoutBlockCommon;
205
+ readonly slaBlock: DynamicLayoutBlockCommon;
206
+ readonly activityLogBlock: DynamicLayoutBlockCommon;
207
+ readonly approvalsBlock: DynamicLayoutBlockCommon;
208
+ readonly attachmentsBlock: DynamicLayoutBlockCommon;
209
+ readonly relatedTasksBlock: DynamicLayoutBlockCommon;
210
+ readonly relationshipsBlock: DynamicLayoutBlockCommon;
211
+ readonly relatedItemsBlock: DynamicLayoutBlockCommon & {
212
+ readonly fieldName?: string;
213
+ readonly color?: string;
214
+ readonly fullWidth?: boolean;
215
+ /** App or element whose related records the block lists. */
216
+ readonly related?: AppOrElementRef;
217
+ /** Record filter over the related app's or element's fields. */
218
+ readonly filter?: Filter<FieldRef, never>;
188
219
  };
220
+ readonly surveysBlock: DynamicLayoutBlockCommon;
189
221
  }
190
222
  type ExactlyOneVariant<Map extends object> = {
191
223
  [K in keyof Map]: {
@@ -290,6 +322,10 @@ export interface AppDynamicLayout {
290
322
  readonly description?: string;
291
323
  };
292
324
  }
325
+ /** Element-owned DASHBOARD layout. Elements have no stages, so it is always the element's default layout. */
326
+ export type ElementDynamicLayout = Omit<AppDynamicLayout, "stage"> & {
327
+ readonly stage?: never;
328
+ };
293
329
  type DynamicLayoutInput<Components extends Readonly<Record<string, DynamicLayoutComponent>>, Conditions extends Readonly<Record<string, DynamicLayoutCondition>>, SaveGroups extends Readonly<Record<string, DynamicLayoutSaveGroup>>> = Omit<AppDynamicLayout, "rootComponent" | "components" | "conditions" | "saveGroups"> & {
294
330
  readonly rootComponent: Extract<keyof Components, string>;
295
331
  readonly components: {
@@ -300,6 +336,12 @@ type DynamicLayoutInput<Components extends Readonly<Record<string, DynamicLayout
300
336
  };
301
337
  readonly saveGroups?: SaveGroups;
302
338
  };
339
+ /** A stage-free layout fits both owners; a staged one is app-only. */
340
+ type DynamicLayoutResult<Stage extends string | undefined> = [
341
+ Stage
342
+ ] extends [undefined] ? ElementDynamicLayout : AppDynamicLayout;
303
343
  /** Preserve graph keys so child, condition, save-group, and root references are checked. */
304
- export declare function dynamicLayout<const Components extends Readonly<Record<string, DynamicLayoutComponent>>, const Conditions extends Readonly<Record<string, DynamicLayoutCondition>> = Record<never, never>, const SaveGroups extends Readonly<Record<string, DynamicLayoutSaveGroup>> = Record<never, never>>(layout: DynamicLayoutInput<Components, Conditions, SaveGroups>): AppDynamicLayout;
344
+ export declare function dynamicLayout<const Components extends Readonly<Record<string, DynamicLayoutComponent>>, const Conditions extends Readonly<Record<string, DynamicLayoutCondition>> = Record<never, never>, const SaveGroups extends Readonly<Record<string, DynamicLayoutSaveGroup>> = Record<never, never>, const Stage extends string | undefined = undefined>(layout: DynamicLayoutInput<Components, Conditions, SaveGroups> & {
345
+ readonly stage?: Stage;
346
+ }): DynamicLayoutResult<Stage>;
305
347
  export {};