@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
@@ -0,0 +1 @@
1
+ export const PORTAL_RESOURCE_TYPE = "elementum_portal";
@@ -1,5 +1,6 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
- import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
2
+ import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
+ import { type AccessPolicyOwner } from "../access-policy/from-tf.js";
3
4
  import type { NormalizedRelationship } from "../app/deserializer/normalize.js";
4
5
  export interface RelationshipOwner {
5
6
  /** Public EDK vocabulary; provider resource names stay at the TF boundary. */
@@ -10,3 +11,9 @@ export interface RelationshipOwner {
10
11
  readonly scope: ChildResourceScope;
11
12
  }
12
13
  export declare function relationshipsFromTf(blocks: readonly TfBlock[], owner: RelationshipOwner, ctx: FromTfContext): NormalizedRelationship[];
14
+ /**
15
+ * Filter-field scope for records of the app or element `aspectId` points at,
16
+ * managed or data-sourced. Other filters over a target's records (dynamic
17
+ * layout related-items blocks) decode their fields the same way.
18
+ */
19
+ export declare function filterOwnerForAspect(aspectId: TfValue, ctx: FromTfContext): AccessPolicyOwner | undefined;
@@ -76,16 +76,7 @@ function relationshipFromTf(block, owner, ctx) {
76
76
  // Only "app"/"element" targets carry a resolvable field scope here -
77
77
  // a table target has no fallback, since table columns never go
78
78
  // through this `_field` resource-attr path anyway.
79
- const targetFilterOwner = target.kind === "app" || target.kind === "element"
80
- ? {
81
- type: target.kind === "element" ? "elementum_element" : "elementum_app",
82
- label: target.tfLabel ?? target.key,
83
- ownerRefName: target.key,
84
- ownerTfLabel: target.tfLabel ?? target.key,
85
- scope: target.kind,
86
- foreignFieldRefsById: ctx.foreignFieldRefsById,
87
- }
88
- : undefined;
79
+ const targetFilterOwner = filterOwnerForTarget(target, ctx);
89
80
  try {
90
81
  if (targetFilterOwner === undefined)
91
82
  throw ownerErr;
@@ -105,6 +96,37 @@ function relationshipFromTf(block, owner, ctx) {
105
96
  }
106
97
  return { key, target, columns, ...(filter !== undefined && { filter }) };
107
98
  }
99
+ function filterOwnerForTarget(target, ctx) {
100
+ return target.kind === "app" || target.kind === "element"
101
+ ? {
102
+ type: target.kind === "element" ? "elementum_element" : "elementum_app",
103
+ label: target.tfLabel ?? target.key,
104
+ ownerRefName: target.key,
105
+ ownerTfLabel: target.tfLabel ?? target.key,
106
+ scope: target.kind,
107
+ foreignFieldRefsById: ctx.foreignFieldRefsById,
108
+ dataField: (label) => targetDataFilterField(label, target, ctx),
109
+ }
110
+ : undefined;
111
+ }
112
+ /**
113
+ * Filter-field scope for records of the app or element `aspectId` points at,
114
+ * managed or data-sourced. Other filters over a target's records (dynamic
115
+ * layout related-items blocks) decode their fields the same way.
116
+ */
117
+ export function filterOwnerForAspect(aspectId, ctx) {
118
+ for (const [type, kind] of [["elementum_app", "app"], ["elementum_element", "element"]]) {
119
+ const resourceLabel = resourceRefLabel(aspectId, type);
120
+ if (resourceLabel !== undefined) {
121
+ return filterOwnerForTarget({ kind, key: tfLabelToTsLabel(resourceLabel), name: tfLabelToTsLabel(resourceLabel), tfLabel: resourceLabel, managed: true }, ctx);
122
+ }
123
+ const dataLabel = dataRefLabel(aspectId, type);
124
+ if (dataLabel !== undefined) {
125
+ return filterOwnerForTarget({ kind, tfLabel: dataLabel, managed: false, ...resolveDataAspectTarget(ctx, kind, dataLabel) }, ctx);
126
+ }
127
+ }
128
+ return undefined;
129
+ }
108
130
  function targetRef(value, owner, ctx) {
109
131
  if (value === undefined)
110
132
  return undefined;
@@ -132,6 +154,27 @@ function targetRef(value, owner, ctx) {
132
154
  }
133
155
  return undefined;
134
156
  }
157
+ /** A relationship filter on the unmanaged target's own field, decoded like a join column's related field. */
158
+ function targetDataFilterField(label, target, ctx) {
159
+ const field = relatedFieldRef({ $expr: "data-attr", type: "elementum_field", label, path: ["id"] }, target, ctx);
160
+ if (field === undefined || field.kind !== "field" || field.parent === undefined)
161
+ return undefined;
162
+ const entityType = field.parentKind ?? (target.kind === "app" || target.kind === "element" ? target.kind : undefined);
163
+ if (entityType === undefined)
164
+ return undefined;
165
+ return {
166
+ kind: "field",
167
+ appHandle: field.parent,
168
+ fieldKey: field.key,
169
+ foreign: {
170
+ entityType,
171
+ name: field.parentName ?? target.name ?? field.parent,
172
+ ...(field.parentNamespace !== undefined ? { namespace: field.parentNamespace } : {}),
173
+ fieldName: field.name,
174
+ ...(field.fieldType !== undefined ? { fieldType: field.fieldType } : {}),
175
+ },
176
+ };
177
+ }
135
178
  function relatedFieldRef(value, target, ctx) {
136
179
  if (value === undefined)
137
180
  return undefined;
@@ -1,4 +1,5 @@
1
1
  import { NO_CANVAS, NO_CATALOG, NO_LIFECYCLE } from "../../graph/types.js";
2
+ import { relationshipPairErrors } from "./pair-check.js";
2
3
  export const RELATIONSHIP_RESOURCE_TYPE = "elementum_relationship";
3
4
  export const relationshipModule = {
4
5
  kind: "relationship",
@@ -13,4 +14,5 @@ export const relationshipModule = {
13
14
  lifecycle: NO_LIFECYCLE,
14
15
  canvas: NO_CANVAS,
15
16
  catalog: NO_CATALOG,
17
+ buildChecks: { validateBuiltBlocks: relationshipPairErrors },
16
18
  };
@@ -0,0 +1,7 @@
1
+ import { type TfBlock } from "../../engine/tf/index.js";
2
+ /**
3
+ * A relationship between two managed roots is two platform records, one per side, whose columns the platform
4
+ * mirrors: changing one side changes the other. Each side lives in its owner's source, so the two must mirror
5
+ * each other or the next plan reverts a one-sided edit. Returns one error per root pair that disagrees.
6
+ */
7
+ export declare function relationshipPairErrors(blocks: readonly TfBlock[]): string[];
@@ -0,0 +1,68 @@
1
+ import { isTfExpr } from "../../engine/tf/index.js";
2
+ import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
3
+ function managedLabel(value) {
4
+ return value !== undefined && isTfExpr(value) && value.$expr === "resource-attr" ? `${value.type}.${value.label}` : undefined;
5
+ }
6
+ function columnLabel(value) {
7
+ return value !== undefined && isTfExpr(value) && (value.$expr === "resource-attr" || value.$expr === "data-attr") ? value.label : JSON.stringify(value);
8
+ }
9
+ function sideOf(block) {
10
+ const owner = managedLabel(block.attrs["object_id"]);
11
+ const target = managedLabel(block.attrs["related_object_id"]);
12
+ if (owner === undefined || target === undefined || owner === target || block.label === undefined)
13
+ return undefined;
14
+ const columns = (Array.isArray(block.attrs["columns"]) ? block.attrs["columns"] : []).map((column) => {
15
+ const attrs = (column ?? {});
16
+ return [columnLabel(attrs["field_id"]), columnLabel(attrs["related_field_id"])];
17
+ });
18
+ return { label: block.label, owner, target, columns };
19
+ }
20
+ /** Columns as one comparable key, oriented from `from`'s side. */
21
+ function joinKey(side, from) {
22
+ const pairs = side.columns.map(([own, related]) => (side.owner === from ? `${own} ↔ ${related}` : `${related} ↔ ${own}`));
23
+ return [...pairs].sort().join(", ");
24
+ }
25
+ function describe(side) {
26
+ return `[${side.columns.map(([own, related]) => `${own} ↔ ${related}`).join(", ")}]`;
27
+ }
28
+ /**
29
+ * A relationship between two managed roots is two platform records, one per side, whose columns the platform
30
+ * mirrors: changing one side changes the other. Each side lives in its owner's source, so the two must mirror
31
+ * each other or the next plan reverts a one-sided edit. Returns one error per root pair that disagrees.
32
+ */
33
+ export function relationshipPairErrors(blocks) {
34
+ const sides = blocks
35
+ .filter((block) => block.kind === "resource" && block.type === RELATIONSHIP_RESOURCE_TYPE)
36
+ .map(sideOf)
37
+ .filter((side) => side !== undefined);
38
+ const byPair = new Map();
39
+ for (const side of sides) {
40
+ const pair = [side.owner, side.target].sort().join(" <> ");
41
+ byPair.set(pair, [...(byPair.get(pair) ?? []), side]);
42
+ }
43
+ const errors = [];
44
+ for (const [pair, pairSides] of byPair) {
45
+ const [first] = pair.split(" <> ");
46
+ const a = pairSides.filter((side) => side.owner === first);
47
+ const b = pairSides.filter((side) => side.owner !== first);
48
+ if (a.length === 0 || b.length === 0)
49
+ continue; // the other side isn't authored here
50
+ const keysA = a.map((side) => joinKey(side, first)).sort();
51
+ const keysB = b.map((side) => joinKey(side, first)).sort();
52
+ if (keysA.join(" | ") === keysB.join(" | "))
53
+ continue;
54
+ if (a.length === 1 && b.length === 1) {
55
+ const [left, right] = [a[0], b[0]];
56
+ const mirrored = `[${left.columns.map(([own, related]) => `${related} ↔ ${own}`).join(", ")}]`;
57
+ errors.push(`relationship ${left.label} joins ${describe(left)} but its counterpart ${right.label} joins ${describe(right)}. ` +
58
+ `The platform mirrors the two sides, so change both: ${right.label} should join ${mirrored} ` +
59
+ `(or ${left.label} should mirror ${right.label}).`);
60
+ }
61
+ else {
62
+ errors.push(`relationships between ${a[0].owner} and ${b[0].owner} don't mirror each other: ` +
63
+ `${a.map((side) => `${side.label} ${describe(side)}`).join("; ")} vs ` +
64
+ `${b.map((side) => `${side.label} ${describe(side)}`).join("; ")}. The platform mirrors the two sides, so change both.`);
65
+ }
66
+ }
67
+ return errors;
68
+ }
@@ -1,6 +1,8 @@
1
1
  import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
2
2
  import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
+ import { type FilterToTfContext } from "../access-policy/to-tf.js";
3
4
  import type { Filter } from "../shared/filters/types.js";
5
+ import { type FieldOwnership } from "../field/to-tf.js";
4
6
  interface RefWire {
5
7
  readonly __kind?: string;
6
8
  readonly refName?: string;
@@ -28,6 +30,14 @@ export interface RelationshipsToTfOptions {
28
30
  readonly orgRefs: OrgRefLookup;
29
31
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
30
32
  readonly diagnostics: string[];
33
+ readonly fieldOwnership?: FieldOwnership;
31
34
  }
35
+ type TargetResolutionOptions = Omit<RelationshipsToTfOptions, "ownerType">;
32
36
  export declare function relationshipsToTf(relationships: Readonly<Record<string, RelationshipWire>> | undefined, opts: RelationshipsToTfOptions): TfBlock[];
37
+ /**
38
+ * `filterToTf` hook for a filter over the records of `targetToken`, so the
39
+ * target's own fields (system fields included) resolve against the target
40
+ * instead of the filter's owner.
41
+ */
42
+ export declare function targetFilterFieldResolver(targetToken: RefWire, where: string, opts: TargetResolutionOptions): NonNullable<FilterToTfContext["foreignField"]> | undefined;
33
43
  export {};
@@ -1,11 +1,12 @@
1
1
  import { workspaceAspectKey, } from "../../engine/build/context.js";
2
- import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
2
+ import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
3
  import { filterToTf } from "../access-policy/to-tf.js";
4
- import { resolveForeignRef } from "../shared/foreign-ref.js";
5
- import { fieldRefToTfValue } from "../field/to-tf.js";
4
+ import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
5
+ import { authoredFieldKeysFromPayload, fieldRefToTfValue, } from "../field/to-tf.js";
6
6
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
7
7
  import { autoRelationColumnError } from "./column-contract.js";
8
8
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
9
+ import { EntityTfError } from "../../engine/entity.js";
9
10
  export function relationshipsToTf(relationships, opts) {
10
11
  const blocks = [];
11
12
  for (const [key, relationship] of Object.entries(relationships ?? {})) {
@@ -17,6 +18,12 @@ export function relationshipsToTf(relationships, opts) {
17
18
  const target = resolveTarget(relationship.target, where, opts);
18
19
  if (target === undefined)
19
20
  continue;
21
+ // The platform rejects object_id = related_object_id with "Invalid request".
22
+ if (target.kind === (opts.ownerType === "elementum_app" ? "app" : "element") && target.refName === opts.ownerRefName) {
23
+ throw new EntityTfError(`${opts.ownerType === "elementum_app" ? "app" : "element"} "${opts.ownerRefName}" ${where}: a relationship's two sides ` +
24
+ `cannot be the same ${target.kind}; the platform rejects it. ` +
25
+ `Model the link with a reference field on "${opts.ownerRefName}" instead, or relate through a child element.`);
26
+ }
20
27
  const columns = [];
21
28
  let droppedInvalidJoin = false;
22
29
  for (const [index, column] of (relationship.columns ?? []).entries()) {
@@ -49,6 +56,9 @@ export function relationshipsToTf(relationships, opts) {
49
56
  objectId: opts.objectId,
50
57
  orgRefs: opts.orgRefs,
51
58
  diagnostics: opts.diagnostics,
59
+ foreignField: (token, fieldWhere) => token.parent === target.refName
60
+ ? resolveRelatedField({ __kind: "field", ...token }, target, fieldWhere, opts)
61
+ : undefined,
52
62
  });
53
63
  }
54
64
  const tfKey = tsLabelToTfLabel(key);
@@ -82,7 +92,7 @@ function resolveOwnerField(value, where, opts) {
82
92
  opts.diagnostics.push(`${where}: field "${refName}" belongs to a different aspect; dropped`);
83
93
  return undefined;
84
94
  }
85
- const result = fieldRefToTfValue(value?.fieldType ?? "", refName, opts.ownerTfLabel, opts.scope);
95
+ const result = fieldRefToTfValue(value?.fieldType ?? "", refName, opts.ownerTfLabel, opts.scope, opts.fieldOwnership);
86
96
  if (result === undefined)
87
97
  opts.diagnostics.push(`${where}: field "${refName}" has no Terraform mapping; dropped`);
88
98
  return result;
@@ -103,6 +113,7 @@ function resolveTarget(value, where, opts) {
103
113
  refName,
104
114
  tfLabel: opts.ownerTfLabel,
105
115
  managed: true,
116
+ fieldOwnership: opts.fieldOwnership,
106
117
  };
107
118
  }
108
119
  if (kind !== "table") {
@@ -118,6 +129,7 @@ function resolveTarget(value, where, opts) {
118
129
  refName,
119
130
  tfLabel: sibling.tfLabel,
120
131
  managed: true,
132
+ fieldOwnership: authoredFieldKeysFromPayload(sibling.streamRootEntity?.payload),
121
133
  };
122
134
  }
123
135
  }
@@ -136,6 +148,19 @@ function resolveTarget(value, where, opts) {
136
148
  managed: false,
137
149
  };
138
150
  }
151
+ /**
152
+ * `filterToTf` hook for a filter over the records of `targetToken`, so the
153
+ * target's own fields (system fields included) resolve against the target
154
+ * instead of the filter's owner.
155
+ */
156
+ export function targetFilterFieldResolver(targetToken, where, opts) {
157
+ const target = resolveTarget(targetToken, where, opts);
158
+ if (target === undefined)
159
+ return undefined;
160
+ return (token, fieldWhere) => token.parent === target.refName
161
+ ? resolveRelatedField({ __kind: "field", ...token }, target, fieldWhere, opts)
162
+ : undefined;
163
+ }
139
164
  function resolveRelatedField(value, target, where, opts) {
140
165
  if (value?.__kind === "recordIdentity") {
141
166
  if (value.target === undefined) {
@@ -168,19 +193,12 @@ function resolveRelatedField(value, target, where, opts) {
168
193
  target.kind !== "table" &&
169
194
  target.kind !== "task" &&
170
195
  target.tfLabel !== undefined) {
171
- const direct = fieldRefToTfValue(value?.fieldType ?? "", refName, target.tfLabel, target.kind);
196
+ const direct = fieldRefToTfValue(value?.fieldType ?? "", refName, target.tfLabel, target.kind, target.fieldOwnership);
172
197
  if (direct !== undefined)
173
198
  return direct;
174
199
  }
175
200
  const name = value?.name ?? refName;
176
- const targetResourceType = target.kind === "app"
177
- ? "elementum_app"
178
- : target.kind === "element"
179
- ? "elementum_element"
180
- : target.kind === "task"
181
- ? "elementum_task"
182
- : "elementum_table";
183
- const label = sanitizeName(`${targetResourceType}_${target.tfLabel ?? target.refName}_${name}`);
201
+ const label = foreignFieldDataLabel(target.kind, target.tfLabel ?? target.refName, name);
184
202
  opts.orgRefs.foreignField("elementum_field", label, target.value, name);
185
203
  return expr.dataAttr("elementum_field", label, ["id"]);
186
204
  }
@@ -115,6 +115,7 @@ export const searchTableModule = {
115
115
  parentScope: ctx.parentScope ?? "app",
116
116
  orgRefs: ctx.orgRefs,
117
117
  diagnostics: ctx.diagnostics,
118
+ fieldAddresses: ctx.fieldAddresses,
118
119
  }),
119
120
  },
120
121
  canvas: { participates: true, label: "Search tables", glyph: "⌕", component: "generic" },
@@ -7,6 +7,7 @@ export interface SearchTableToTfContext {
7
7
  readonly parentScope: ChildResourceScope | "table";
8
8
  readonly orgRefs: OrgRefLookup;
9
9
  readonly diagnostics: string[];
10
+ readonly fieldAddresses?: ReadonlyMap<string, string>;
10
11
  }
11
12
  export declare function searchTableToTf(entity: DeployableEntity, ctx: SearchTableToTfContext): {
12
13
  readonly blocks: readonly TfBlock[];
@@ -10,7 +10,7 @@ function fieldValue(token, ctx, where) {
10
10
  if (token.parent !== undefined && token.parent !== ctx.appRefName) {
11
11
  throw new EntityTfError(`${where}: cross-aspect field token ${token.parent}.${token.refName} is not supported`);
12
12
  }
13
- const value = fieldRefToTfValue(token.fieldType ?? "", token.refName, ctx.appTfLabel, ctx.parentScope);
13
+ const value = fieldRefToTfValue(token.fieldType ?? "", token.refName, ctx.appTfLabel, ctx.parentScope, ctx.fieldAddresses);
14
14
  if (value === undefined)
15
15
  throw new EntityTfError(`${where}: field ${token.refName} has no Terraform resource mapping`);
16
16
  return value;
@@ -1,4 +1,5 @@
1
1
  import type { GroupRef } from "../../catalog/index.js";
2
+ import type { UnsafePlatformId } from "../../core/platform-id.js";
2
3
  import type { RoleUserRef } from "../role/build.js";
3
4
  declare const serviceAccountStatusBrand: unique symbol;
4
5
  export type ServiceAccountStatus = string & {
@@ -14,6 +15,13 @@ export interface ServiceAccountRoleRef {
14
15
  readonly name: string;
15
16
  }
16
17
  export declare function serviceAccountRoleRef(name: string): ServiceAccountRoleRef;
18
+ /**
19
+ * A role named on this app, or a platform id pull could not name.
20
+ * `unsafePlatformId` is the escape for a role that lives on another app,
21
+ * element, or table: the export only has the id, and dropping it would strip
22
+ * the role from the live account on the next apply.
23
+ */
24
+ export type ServiceAccountRole = ServiceAccountRoleRef | UnsafePlatformId;
17
25
  export interface ServiceAccountAccessPolicy {
18
26
  readonly users?: readonly RoleUserRef[];
19
27
  readonly groups?: readonly GroupRef[];
@@ -24,8 +32,13 @@ export interface AppServiceAccount {
24
32
  readonly lastName: string;
25
33
  readonly purpose: string;
26
34
  readonly status?: ServiceAccountStatus;
27
- /** Custom or managed roles, both resolved by name within this app. */
28
- readonly roles?: readonly ServiceAccountRoleRef[];
35
+ /**
36
+ * Roles assigned to this account, in platform order.
37
+ * Name a role on this app with `serviceAccountRoleRef`. Pull keeps a role
38
+ * it cannot name — one owned by another app, element, or table — as
39
+ * `unsafePlatformId(...)`.
40
+ */
41
+ readonly roles?: readonly ServiceAccountRole[];
29
42
  /** Users/groups allowed to select and run as this identity. */
30
43
  readonly accessPolicies?: readonly ServiceAccountAccessPolicy[];
31
44
  }
@@ -1,10 +1,8 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
2
  import { type TfBlock } from "../../engine/tf/index.js";
3
3
  import { type AppServiceAccount } from "./build.js";
4
+ import { type ServiceAccountRoleOwner } from "./role-fidelity.js";
4
5
  export interface NormalizedServiceAccount extends AppServiceAccount {
5
6
  readonly key: string;
6
7
  }
7
- export declare function serviceAccountsFromTf(blocks: readonly TfBlock[], owner: {
8
- readonly label: string;
9
- readonly ownerTfLabel: string;
10
- }, ctx: FromTfContext): NormalizedServiceAccount[];
8
+ export declare function serviceAccountsFromTf(blocks: readonly TfBlock[], owner: ServiceAccountRoleOwner, ctx: FromTfContext): NormalizedServiceAccount[];
@@ -1,7 +1,9 @@
1
+ import { unsafePlatformId } from "../../core/platform-id.js";
1
2
  import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
2
3
  import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
3
4
  import { serviceAccountRoleRef, serviceAccountStatus, } from "./build.js";
4
5
  import { SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE, SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
6
+ import { serviceAccountRoleIdMismatches } from "./role-fidelity.js";
5
7
  const ACCOUNT_ATTRS = new Set(["id", "app_id", "first_name", "last_name", "purpose", "name", "status", "role_ids"]);
6
8
  const POLICY_ATTRS = new Set(["id", "app_id", "service_account_id", "user_ids", "group_ids"]);
7
9
  function principal(value, type, where, ctx) {
@@ -39,6 +41,10 @@ function principalList(value, type, where, ctx) {
39
41
  : principal(item, "elementum_group", where, ctx)) ?? []);
40
42
  return out.length > 0 ? out : undefined;
41
43
  }
44
+ function keptPlatformId(id, where, ctx) {
45
+ ctx.diagnostics.push(`${where}: role reference has no recoverable name; kept as unsafePlatformId`);
46
+ return unsafePlatformId(id);
47
+ }
42
48
  function roleRefs(value, blocks, where, ctx) {
43
49
  if (value === undefined)
44
50
  return undefined;
@@ -53,23 +59,26 @@ function roleRefs(value, blocks, where, ctx) {
53
59
  const role = blocks.find((candidate) => candidate.type === "elementum_role" && candidate.label === resourceLabel);
54
60
  if (typeof role?.attrs["name"] === "string")
55
61
  out.push(serviceAccountRoleRef(role.attrs["name"]));
56
- else
57
- ctx.diagnostics.push(`${where}: ${resourceLabel} has no recoverable role name; dropped`);
62
+ else {
63
+ const id = typeof role?.attrs["id"] === "string" ? role.attrs["id"] : ctx.importId(`elementum_role.${resourceLabel}`);
64
+ if (typeof id === "string" && id.trim() !== "")
65
+ out.push(keptPlatformId(id, where, ctx));
66
+ }
58
67
  continue;
59
68
  }
60
69
  const dataLabel = dataRefLabel(item, "elementum_role");
61
70
  const name = dataLabel === undefined ? undefined : ctx.dataName("elementum_role", dataLabel);
62
71
  if (name !== undefined)
63
72
  out.push(serviceAccountRoleRef(name));
64
- else
65
- ctx.diagnostics.push(`${where}: role reference has no recoverable name; dropped`);
73
+ else if (typeof item === "string" && item.trim() !== "")
74
+ out.push(keptPlatformId(item, where, ctx));
66
75
  }
67
76
  return out.length > 0 ? out : undefined;
68
77
  }
69
78
  export function serviceAccountsFromTf(blocks, owner, ctx) {
70
79
  const accounts = blocks.filter((block) => block.type === SERVICE_ACCOUNT_RESOURCE_TYPE);
71
80
  const policies = blocks.filter((block) => block.type === SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE);
72
- return accounts.flatMap((block) => {
81
+ const extracted = accounts.flatMap((block) => {
73
82
  const label = block.label ?? "";
74
83
  const where = `${SERVICE_ACCOUNT_RESOURCE_TYPE}.${label || "?"}`;
75
84
  if (label === "" || resourceRefLabel(block.attrs["app_id"], "elementum_app") !== owner.label)
@@ -112,4 +121,7 @@ export function serviceAccountsFromTf(blocks, owner, ctx) {
112
121
  ...(accessPolicies.length > 0 && { accessPolicies }),
113
122
  }];
114
123
  });
124
+ for (const mismatch of serviceAccountRoleIdMismatches(blocks, extracted, owner, ctx))
125
+ ctx.diagnostics.push(mismatch);
126
+ return extracted;
115
127
  }
@@ -0,0 +1,56 @@
1
+ import { type FromTfContext } from "../../engine/pull/context.js";
2
+ import { type TfBlock } from "../../engine/tf/index.js";
3
+ import type { ServiceAccountRole } from "./build.js";
4
+ /**
5
+ * Pull must not report success when a service account's generated roles
6
+ * disagree with the export's `role_ids`. Adoption plans the export, so a
7
+ * clean adopt does not prove the authored source kept every role.
8
+ */
9
+ export declare const SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX = "service-account role_ids mismatch:";
10
+ export interface ServiceAccountRoleOwner {
11
+ readonly label: string;
12
+ readonly ownerTfLabel: string;
13
+ /** Authoring file to edit, relative to the org root when known. */
14
+ readonly sourceFile?: string;
15
+ }
16
+ interface ExtractedServiceAccountRoles {
17
+ readonly key: string;
18
+ readonly roles?: readonly ServiceAccountRole[];
19
+ }
20
+ /**
21
+ * Order-sensitive comparison of each owned service account's export
22
+ * `role_ids` with the roles written into source. Named roles compare by
23
+ * display name; raw ids compare by platform id. A value the printer cannot
24
+ * represent is a disagreement, not a quiet omission.
25
+ */
26
+ export declare function serviceAccountRoleIdMismatches(blocks: readonly TfBlock[], accounts: readonly ExtractedServiceAccountRoles[], owner: ServiceAccountRoleOwner, ctx: FromTfContext): readonly string[];
27
+ /**
28
+ * Role names the service-account rebuild actually emitted.
29
+ * Export labels are a different namespace: a name with no ASCII letters, or
30
+ * two names that sanitize to one label, must be read from these lookups.
31
+ */
32
+ export interface RebuiltServiceAccountRoleLookup {
33
+ /** Managed-role display names in `rawLookup` order, keyed by the data label the rebuild emitted. */
34
+ readonly dataRoleNames: ReadonlyMap<string, readonly string[]>;
35
+ /** Custom-role display names keyed by the resource label the rebuild emitted. */
36
+ readonly resourceRoleNames: ReadonlyMap<string, string>;
37
+ }
38
+ /**
39
+ * Same order-sensitive rule, against service-account blocks rebuilt from
40
+ * the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
41
+ * disagrees here even when extract mirrored the export.
42
+ * When `lookup` is set, rebuilt refs resolve through it. Export refs still
43
+ * use `ctx` and the export blocks.
44
+ */
45
+ export declare function rebuiltServiceAccountRoleIdMismatches(exportBlocks: readonly TfBlock[], rebuiltBlocks: readonly TfBlock[], owner: ServiceAccountRoleOwner, ctx: FromTfContext, lookup?: RebuiltServiceAccountRoleLookup): readonly string[];
46
+ /** Authoring files named by role-mismatch lines, in first-seen order. */
47
+ export declare function serviceAccountRoleMismatchSources(lines: readonly string[]): readonly string[];
48
+ /** Single-root build-vs-export lines that are a service-account `role_ids` disagreement. */
49
+ export declare function serviceAccountRoleRoundTripMismatches(differences: readonly string[], sourceFile: string): readonly string[];
50
+ export declare function serviceAccountRoleGuardBlocksSuccess(diagnostics: readonly string[]): boolean;
51
+ /** Adoption failure fails a pull. Role-id disagreement must too, even when adoption succeeded or was skipped. */
52
+ export declare function serviceAccountPullMustFail(input: {
53
+ readonly adoptionFailed: boolean;
54
+ readonly diagnostics: readonly string[];
55
+ }): boolean;
56
+ export {};