@elementumai/edk 0.9.18 → 0.9.19

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 (125) hide show
  1. package/README.md +8 -3
  2. package/dist-sdk/src/catalog/factories.d.ts +11 -0
  3. package/dist-sdk/src/catalog/factories.js +6 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +2 -2
  6. package/dist-sdk/src/catalog/org.d.ts +39 -1
  7. package/dist-sdk/src/catalog/org.js +460 -50
  8. package/dist-sdk/src/catalog/types.d.ts +10 -0
  9. package/dist-sdk/src/catalog/types.js +2 -0
  10. package/dist-sdk/src/engine/pull/ref-only.js +54 -20
  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/tf/expr.js +38 -13
  14. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  15. package/dist-sdk/src/engine/tf/index.js +2 -2
  16. package/dist-sdk/src/engine/tf/labels.d.ts +2 -0
  17. package/dist-sdk/src/engine/tf/labels.js +4 -0
  18. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  19. package/dist-sdk/src/engine/tf/parse.js +105 -6
  20. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +11 -4
  25. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -1
  26. package/dist-sdk/src/entities/app/build.d.ts +10 -0
  27. package/dist-sdk/src/entities/app/build.js +0 -13
  28. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
  29. package/dist-sdk/src/entities/app/from-tf.js +4 -3
  30. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  31. package/dist-sdk/src/entities/app/index.js +1 -0
  32. package/dist-sdk/src/entities/app/module.js +13 -0
  33. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  34. package/dist-sdk/src/entities/automation/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/automation/build.js +27 -0
  36. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +6 -0
  37. package/dist-sdk/src/entities/automation/from-tf.js +135 -26
  38. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  39. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  40. package/dist-sdk/src/entities/automation/module.js +56 -0
  41. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  42. package/dist-sdk/src/entities/automation/system-ref-name.js +44 -0
  43. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +15 -0
  44. package/dist-sdk/src/entities/automation/task-output-labels.js +38 -0
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -2
  46. package/dist-sdk/src/entities/automation/to-tf.js +158 -84
  47. package/dist-sdk/src/entities/automation/types.js +1 -0
  48. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  49. package/dist-sdk/src/entities/chart/module.js +3 -1
  50. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  51. package/dist-sdk/src/entities/chart/printer.js +26 -16
  52. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  53. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  54. package/dist-sdk/src/entities/chart/to-tf.js +12 -10
  55. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  56. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  57. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  58. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  59. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  60. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +51 -2
  61. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  62. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  63. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  64. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  65. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  66. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/build.js +1 -0
  70. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  71. package/dist-sdk/src/entities/element/from-tf.js +6 -2
  72. package/dist-sdk/src/entities/element/index.d.ts +1 -0
  73. package/dist-sdk/src/entities/element/index.js +1 -0
  74. package/dist-sdk/src/entities/element/module.js +2 -0
  75. package/dist-sdk/src/entities/element/to-tf.js +12 -0
  76. package/dist-sdk/src/entities/field/from-tf.d.ts +2 -0
  77. package/dist-sdk/src/entities/field/from-tf.js +11 -0
  78. package/dist-sdk/src/entities/field/to-tf.js +13 -9
  79. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  80. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  81. package/dist-sdk/src/entities/relationship/to-tf.d.ts +8 -0
  82. package/dist-sdk/src/entities/relationship/to-tf.js +19 -10
  83. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -2
  84. package/dist-sdk/src/entities/shared/filters/index.d.ts +23 -2
  85. package/dist-sdk/src/entities/shared/filters/index.js +24 -1
  86. package/dist-sdk/src/entities/shared/filters/print.js +14 -2
  87. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +23 -3
  88. package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -14
  89. package/dist-sdk/src/entities/shared/filters/types.d.ts +13 -4
  90. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  91. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  92. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  93. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  94. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  95. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  96. package/dist-sdk/src/entities/skill/build.js +3 -0
  97. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  98. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +21 -0
  99. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  100. package/dist-sdk/src/entities/skill/from-tf.js +4 -9
  101. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  102. package/dist-sdk/src/entities/skill/index.js +1 -0
  103. package/dist-sdk/src/entities/skill/module.js +1 -0
  104. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  105. package/dist-sdk/src/entities/skill/to-tf.js +5 -2
  106. package/dist-sdk/src/entities/skill-tool/to-tf.js +2 -1
  107. package/dist-sdk/src/entities/table/to-tf.js +3 -3
  108. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -0
  109. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +224 -0
  110. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +36 -0
  111. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +288 -0
  112. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +121 -0
  113. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  114. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -1
  115. package/dist-sdk/src/entities/view/from-tf.js +42 -7
  116. package/dist-sdk/src/entities/view/to-tf.d.ts +10 -1
  117. package/dist-sdk/src/entities/view/to-tf.js +30 -1
  118. package/dist-sdk/src/entities/view/types.js +2 -0
  119. package/dist-sdk/src/entities/widget/to-tf.js +2 -2
  120. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +25 -8
  121. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  122. package/dist-sdk/src/graph/index.d.ts +43 -0
  123. package/dist-sdk/src/graph/index.js +9 -0
  124. package/dist-sdk/src/graph/types.d.ts +78 -0
  125. package/package.json +2 -1
@@ -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
+ }
@@ -5,6 +5,7 @@ import { 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,24 @@ 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 { ref, kind, id: expr.resourceAttr(type, local.tfLabel, ["id"]), tfLabel: local.tfLabel, local: true };
21
23
  }
22
24
  const name = ref.name ?? ref.refName;
25
+ if (ref.__kind === "app" || ref.__kind === "element") {
26
+ const foreign = resolveForeignRef(ref.__kind, { name, namespace: ref.namespace }, opts.orgRefs, opts.diagnostics, where);
27
+ return { ref, kind, id: foreign.value, tfLabel: foreign.tfLabel, local: false };
28
+ }
23
29
  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")
30
+ if (ref.__kind === "task")
29
31
  opts.orgRefs.rawLookup("elementum_task", label, name);
30
32
  else
31
33
  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 };
34
+ const type = ref.__kind === "task" ? "elementum_task" : TABLE_RESOURCE_TYPE;
35
+ return { ref, kind, id: expr.dataAttr(type, label, ["id"]), tfLabel: label, local: false };
34
36
  }
35
37
  function fieldId(ref, datasource, opts, where) {
36
38
  if (ref?.refName === undefined || ref.refName === "")
@@ -54,7 +56,7 @@ function fieldId(ref, datasource, opts, where) {
54
56
  if (direct !== undefined)
55
57
  return direct;
56
58
  }
57
- const label = sanitizeName(`${datasource.ref.__kind}_${datasource.ref.refName}_${ref.refName}`);
59
+ const label = foreignFieldDataLabel(datasource.kind, datasource.tfLabel, ref.name ?? ref.refName);
58
60
  opts.orgRefs.foreignField("elementum_field", label, datasource.id, ref.name ?? ref.refName);
59
61
  return expr.dataAttr("elementum_field", label, ["id"]);
60
62
  }
@@ -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,24 @@ export interface DynamicLayoutFieldComponent {
51
52
  readonly fullWidth?: boolean;
52
53
  readonly dependsOn?: readonly string[];
53
54
  }
55
+ /** One automation trigger parameter an automation button supplies. */
56
+ export interface DynamicLayoutAutomationButtonInput {
57
+ /** On-demand trigger parameter of the button's automation (or of `automation`). */
58
+ readonly parameterName: string;
59
+ /** Automation whose on-demand trigger declares the parameter, when it is not the button's own. */
60
+ readonly automation?: AutomationRef;
61
+ /** Platform parameter id, only for a parameter the automation's trigger does not declare by name in this source. */
62
+ readonly parameterId?: string;
63
+ readonly fieldType?: string;
64
+ readonly multiple?: boolean;
65
+ readonly required?: boolean;
66
+ /** Value template; `{{name}}` placeholders are filled from `fieldRefParams`. */
67
+ readonly value?: string;
68
+ readonly fieldRefParams?: readonly {
69
+ readonly name: string;
70
+ readonly field: AppViewFieldRef;
71
+ }[];
72
+ }
54
73
  interface DynamicLayoutComponentCommon<ComponentKey extends string = string, ConditionKey extends string = string, SaveGroupKey extends string = string> {
55
74
  readonly children?: readonly ComponentKey[];
56
75
  readonly style?: DynamicLayoutStyle;
@@ -122,6 +141,16 @@ export interface DynamicLayoutComponentVariantMap {
122
141
  readonly variant?: "default" | "outline" | "ghost" | "destructive";
123
142
  readonly icon?: string;
124
143
  readonly confirmMessage?: string;
144
+ /** App or element that owns the automation, as the layout editor records it. */
145
+ readonly automationApp?: AppOrElementRef;
146
+ readonly color?: string;
147
+ /** Column count of the parent grid the button sits in (1-12). */
148
+ readonly columns?: number;
149
+ /** Grid columns the button spans (1-12). */
150
+ readonly span?: number;
151
+ readonly inputs?: readonly DynamicLayoutAutomationButtonInput[];
152
+ /** Run-automation widget the button executes through; omit to have build derive one. */
153
+ readonly widget?: WidgetRef;
125
154
  };
126
155
  readonly createButton: {
127
156
  readonly target: AppOrElementRef;
@@ -167,12 +196,14 @@ export interface DynamicLayoutComponentVariantMap {
167
196
  };
168
197
  readonly activityLogBlock: {
169
198
  readonly label?: string;
199
+ readonly title?: string;
170
200
  };
171
201
  readonly approvalsBlock: {
172
202
  readonly label?: string;
173
203
  };
174
204
  readonly attachmentsBlock: {
175
205
  readonly label?: string;
206
+ readonly title?: string;
176
207
  };
177
208
  readonly relatedTasksBlock: {
178
209
  readonly label?: string;
@@ -182,6 +213,14 @@ export interface DynamicLayoutComponentVariantMap {
182
213
  };
183
214
  readonly relatedItemsBlock: {
184
215
  readonly label?: string;
216
+ readonly title?: string;
217
+ readonly fieldName?: string;
218
+ readonly color?: string;
219
+ readonly fullWidth?: boolean;
220
+ /** App or element whose related records the block lists. */
221
+ readonly related?: AppOrElementRef;
222
+ /** Record filter over the related app's or element's fields. */
223
+ readonly filter?: Filter<FieldRef, never>;
185
224
  };
186
225
  readonly surveysBlock: {
187
226
  readonly label?: string;
@@ -290,6 +329,10 @@ export interface AppDynamicLayout {
290
329
  readonly description?: string;
291
330
  };
292
331
  }
332
+ /** Element-owned DASHBOARD layout. Elements have no stages, so it is always the element's default layout. */
333
+ export type ElementDynamicLayout = Omit<AppDynamicLayout, "stage"> & {
334
+ readonly stage?: never;
335
+ };
293
336
  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
337
  readonly rootComponent: Extract<keyof Components, string>;
295
338
  readonly components: {
@@ -300,6 +343,12 @@ type DynamicLayoutInput<Components extends Readonly<Record<string, DynamicLayout
300
343
  };
301
344
  readonly saveGroups?: SaveGroups;
302
345
  };
346
+ /** A stage-free layout fits both owners; a staged one is app-only. */
347
+ type DynamicLayoutResult<Stage extends string | undefined> = [
348
+ Stage
349
+ ] extends [undefined] ? ElementDynamicLayout : AppDynamicLayout;
303
350
  /** 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;
351
+ 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> & {
352
+ readonly stage?: Stage;
353
+ }): DynamicLayoutResult<Stage>;
305
354
  export {};
@@ -1,3 +1,4 @@
1
+ import { type ChildResourceScope } from "../../engine/tf/index.js";
1
2
  export declare const DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY: ReadonlyMap<string, string>;
2
3
  export declare const DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS: ReadonlySet<string>;
3
4
  export declare function dynamicLayoutFieldComponentWireKey(publicKey: string): string;
@@ -10,3 +11,5 @@ export declare const DYNAMIC_LAYOUT_COMPARISON_KEYS: ReadonlySet<string>;
10
11
  */
11
12
  export declare const DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX = "EDK dynamic layout action ";
12
13
  export declare function dynamicLayoutActionWidgetName(layoutKey: string, componentId: string): string;
14
+ /** Terraform label of the companion widget build derives for one automation button. */
15
+ export declare function dynamicLayoutCompanionWidgetLabel(ownerTfLabel: string, layoutKey: string, componentId: string, scope: ChildResourceScope): string;
@@ -1,3 +1,4 @@
1
+ import { sanitizeName, scopedResourceLabel } from "../../engine/tf/index.js";
1
2
  import { splitCamelCase } from "../../engine/tf/labels.js";
2
3
  /**
3
4
  * Public field-component keys are listed exhaustively against the authoring
@@ -57,3 +58,7 @@ export function dynamicLayoutActionWidgetName(layoutKey, componentId) {
57
58
  const words = (value) => splitCamelCase(value.replace(/[_-]+/g, " ")).toLowerCase();
58
59
  return `${DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX}${words(layoutKey)} ${words(componentId)}`;
59
60
  }
61
+ /** Terraform label of the companion widget build derives for one automation button. */
62
+ export function dynamicLayoutCompanionWidgetLabel(ownerTfLabel, layoutKey, componentId, scope) {
63
+ return scopedResourceLabel(ownerTfLabel, sanitizeName(dynamicLayoutActionWidgetName(layoutKey, componentId)), scope);
64
+ }
@@ -1,17 +1,20 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
- import { type TfBlock } from "../../engine/tf/index.js";
2
+ import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
3
3
  import type { NormalizedDynamicLayout } from "../app/deserializer/normalize.js";
4
4
  export interface DynamicLayoutOwner {
5
5
  readonly type: string;
6
6
  readonly label: string;
7
7
  readonly ownerRefName: string;
8
8
  readonly ownerTfLabel: string;
9
+ /** Owning stream root kind; defaults to `"app"`. */
10
+ readonly scope?: ChildResourceScope;
9
11
  }
10
12
  export declare function dynamicLayoutsFromTf(blocks: readonly TfBlock[], owner: DynamicLayoutOwner, ctx: FromTfContext): NormalizedDynamicLayout[];
11
13
  /**
12
- * Widget resource labels referenced by dynamic-layout automation buttons.
13
- * The label is the companion widget's stable Terraform identity; its display
14
- * name is mutable and cannot safely distinguish generated from authored
15
- * widgets during pull.
14
+ * Labels of the companion widgets build derives for dynamic-layout automation
15
+ * buttons, among those the buttons reference. The label is the companion's
16
+ * stable Terraform identity; its display name is mutable and cannot safely
17
+ * distinguish generated from authored widgets during pull. A button bound to
18
+ * any other widget keeps that widget as authored source.
16
19
  */
17
- export declare function dynamicLayoutCompanionWidgetLabels(blocks: readonly TfBlock[]): ReadonlySet<string>;
20
+ export declare function dynamicLayoutCompanionWidgetLabels(blocks: readonly TfBlock[], owner: DynamicLayoutOwner): ReadonlySet<string>;