@elementumai/edk 0.9.19 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/README.md +159 -7
  2. package/dist-sdk/src/catalog/factories.d.ts +33 -2
  3. package/dist-sdk/src/catalog/factories.js +40 -1
  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/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +11 -0
  10. package/dist-sdk/src/catalog/types.d.ts +40 -1
  11. package/dist-sdk/src/catalog/types.js +12 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +40 -4
  13. package/dist-sdk/src/core/triggers/on-demand.js +17 -2
  14. package/dist-sdk/src/core/types/app.d.ts +2 -2
  15. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +86 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +156 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +169 -0
  19. package/dist-sdk/src/engine/ei/run.js +1219 -0
  20. package/dist-sdk/src/engine/logging.d.ts +17 -0
  21. package/dist-sdk/src/engine/logging.js +18 -0
  22. package/dist-sdk/src/engine/pull/catalog-ref.d.ts +16 -0
  23. package/dist-sdk/src/engine/pull/catalog-ref.js +24 -0
  24. package/dist-sdk/src/engine/pull/context.d.ts +68 -6
  25. package/dist-sdk/src/engine/pull/context.js +40 -1
  26. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +8 -0
  27. package/dist-sdk/src/engine/pull/procedure-refs.js +28 -0
  28. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  29. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  30. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  31. package/dist-sdk/src/engine/pull/result-output.js +113 -3
  32. package/dist-sdk/src/engine/tf/expr.js +1 -1
  33. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  34. package/dist-sdk/src/engine/tf/index.js +1 -1
  35. package/dist-sdk/src/engine/tf/labels.d.ts +28 -5
  36. package/dist-sdk/src/engine/tf/labels.js +54 -3
  37. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  38. package/dist-sdk/src/engine/tf/parse.js +93 -4
  39. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  40. package/dist-sdk/src/engine/tf/render.js +41 -7
  41. package/dist-sdk/src/engine/validation.d.ts +44 -0
  42. package/dist-sdk/src/engine/validation.js +95 -0
  43. package/dist-sdk/src/entities/access-policy/from-tf.js +38 -1
  44. package/dist-sdk/src/entities/access-policy/principal.d.ts +2 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  46. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  47. package/dist-sdk/src/entities/agent/build.js +40 -5
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -0
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +46 -21
  50. package/dist-sdk/src/entities/agent/from-tf.js +11 -3
  51. package/dist-sdk/src/entities/agent/module.js +2 -0
  52. package/dist-sdk/src/entities/agent/to-tf.js +20 -6
  53. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +10 -1
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +18 -6
  55. package/dist-sdk/src/entities/agent-tool/module.js +3 -0
  56. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  57. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  58. package/dist-sdk/src/entities/app/auto-share.d.ts +38 -0
  59. package/dist-sdk/src/entities/app/auto-share.js +49 -0
  60. package/dist-sdk/src/entities/app/build.d.ts +105 -22
  61. package/dist-sdk/src/entities/app/build.js +107 -10
  62. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  63. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  64. package/dist-sdk/src/entities/app/from-tf.js +11 -2
  65. package/dist-sdk/src/entities/app/index.d.ts +7 -6
  66. package/dist-sdk/src/entities/app/index.js +2 -8
  67. package/dist-sdk/src/entities/app/module.js +5 -2
  68. package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
  69. package/dist-sdk/src/entities/app/to-tf.js +40 -13
  70. package/dist-sdk/src/entities/automation/build.d.ts +56 -6
  71. package/dist-sdk/src/entities/automation/build.js +230 -26
  72. package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
  73. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +41 -5
  74. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +470 -58
  75. package/dist-sdk/src/entities/automation/from-tf.d.ts +37 -8
  76. package/dist-sdk/src/entities/automation/from-tf.js +791 -131
  77. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  78. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  79. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  80. package/dist-sdk/src/entities/automation/index.js +1 -1
  81. package/dist-sdk/src/entities/automation/module.d.ts +3 -0
  82. package/dist-sdk/src/entities/automation/module.js +107 -15
  83. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  84. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  85. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  86. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  87. package/dist-sdk/src/entities/automation/script-code.d.ts +20 -0
  88. package/dist-sdk/src/entities/automation/script-code.js +109 -5
  89. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  90. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +39 -0
  91. package/dist-sdk/src/entities/automation/task-output-labels.js +85 -0
  92. package/dist-sdk/src/entities/automation/tasks.d.ts +116 -22
  93. package/dist-sdk/src/entities/automation/tasks.js +86 -24
  94. package/dist-sdk/src/entities/automation/to-tf.d.ts +24 -3
  95. package/dist-sdk/src/entities/automation/to-tf.js +1082 -132
  96. package/dist-sdk/src/entities/automation/triggers.d.ts +12 -6
  97. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  98. package/dist-sdk/src/entities/automation/types.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/types.js +19 -0
  100. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +1 -1
  101. package/dist-sdk/src/entities/automation/value-ref-tf.js +1 -1
  102. package/dist-sdk/src/entities/chart/from-tf.js +9 -1
  103. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  104. package/dist-sdk/src/entities/data-lookup/module.js +2 -0
  105. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -5
  108. package/dist-sdk/src/entities/element/build.d.ts +28 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +62 -1
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  113. package/dist-sdk/src/entities/element/index.js +1 -0
  114. package/dist-sdk/src/entities/element/module.js +9 -3
  115. package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
  116. package/dist-sdk/src/entities/element/to-tf.js +16 -16
  117. package/dist-sdk/src/entities/field/build.d.ts +17 -3
  118. package/dist-sdk/src/entities/field/build.js +3 -0
  119. package/dist-sdk/src/entities/field/calc.d.ts +7 -7
  120. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -4
  121. package/dist-sdk/src/entities/field/from-tf.js +244 -49
  122. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  123. package/dist-sdk/src/entities/field/media-types.js +30 -0
  124. package/dist-sdk/src/entities/field/module.js +2 -0
  125. package/dist-sdk/src/entities/field/options.js +6 -1
  126. package/dist-sdk/src/entities/field/to-tf.d.ts +26 -5
  127. package/dist-sdk/src/entities/field/to-tf.js +137 -15
  128. package/dist-sdk/src/entities/field/types.d.ts +2 -0
  129. package/dist-sdk/src/entities/field/types.js +27 -0
  130. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  131. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  132. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  133. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  134. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  135. package/dist-sdk/src/entities/portal/build.js +37 -0
  136. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  137. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  138. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  139. package/dist-sdk/src/entities/portal/index.js +1 -0
  140. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  141. package/dist-sdk/src/entities/portal/module.js +28 -0
  142. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  143. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  144. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  145. package/dist-sdk/src/entities/portal/types.js +1 -0
  146. package/dist-sdk/src/entities/relationship/module.js +2 -0
  147. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  148. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  149. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  150. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  151. package/dist-sdk/src/entities/role/from-tf.js +3 -3
  152. package/dist-sdk/src/entities/role/to-tf.d.ts +2 -0
  153. package/dist-sdk/src/entities/role/to-tf.js +12 -4
  154. package/dist-sdk/src/entities/search-table/module.js +1 -0
  155. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  156. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  157. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  158. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  159. package/dist-sdk/src/entities/service-account/from-tf.js +20 -8
  160. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  161. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  162. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  163. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  164. package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +16 -0
  165. package/dist-sdk/src/entities/service-account/workspace-owner.js +22 -0
  166. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  167. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  168. package/dist-sdk/src/entities/shared/filters/ast.d.ts +23 -1
  169. package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
  170. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  171. package/dist-sdk/src/entities/shared/filters/index.js +19 -4
  172. package/dist-sdk/src/entities/shared/filters/print.js +24 -3
  173. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -0
  174. package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -7
  175. package/dist-sdk/src/entities/shared/filters/types.d.ts +15 -2
  176. package/dist-sdk/src/entities/shared/ref.d.ts +5 -7
  177. package/dist-sdk/src/entities/shared/ref.js +5 -7
  178. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +9 -0
  179. package/dist-sdk/src/entities/shared/tool-field-ref.js +35 -2
  180. package/dist-sdk/src/entities/shared/types/field-types.d.ts +20 -5
  181. package/dist-sdk/src/entities/shared/types/field-types.js +8 -0
  182. package/dist-sdk/src/entities/skill/access-policy.js +3 -3
  183. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -0
  184. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +14 -6
  185. package/dist-sdk/src/entities/skill/from-tf.js +70 -15
  186. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  187. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  188. package/dist-sdk/src/entities/skill/module.js +2 -0
  189. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  190. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  191. package/dist-sdk/src/entities/skill-tool/from-tf.js +49 -10
  192. package/dist-sdk/src/entities/skill-tool/module.js +3 -0
  193. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -8
  194. package/dist-sdk/src/entities/skill-tool/to-tf.js +49 -14
  195. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  196. package/dist-sdk/src/entities/table/catalog.js +66 -0
  197. package/dist-sdk/src/entities/table/module.js +2 -1
  198. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  199. package/dist-sdk/src/entities/task/build.d.ts +8 -0
  200. package/dist-sdk/src/entities/task/build.js +10 -1
  201. package/dist-sdk/src/entities/task/from-tf.d.ts +4 -2
  202. package/dist-sdk/src/entities/task/from-tf.js +7 -2
  203. package/dist-sdk/src/entities/task/module.js +2 -2
  204. package/dist-sdk/src/entities/task/to-tf.d.ts +8 -4
  205. package/dist-sdk/src/entities/task/to-tf.js +28 -1
  206. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  207. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  208. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  209. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  210. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  211. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  212. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  213. package/dist-sdk/src/entities/view/from-tf.js +133 -13
  214. package/dist-sdk/src/entities/view/module.js +30 -3
  215. package/dist-sdk/src/entities/view/to-tf.d.ts +20 -8
  216. package/dist-sdk/src/entities/view/to-tf.js +86 -18
  217. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  218. package/dist-sdk/src/entities/view/types.js +15 -15
  219. package/dist-sdk/src/entities/visual-flow/build.d.ts +16 -1
  220. package/dist-sdk/src/entities/visual-flow/build.js +9 -0
  221. package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +14 -0
  222. package/dist-sdk/src/entities/visual-flow/from-tf.js +51 -3
  223. package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
  224. package/dist-sdk/src/entities/visual-flow/index.js +1 -1
  225. package/dist-sdk/src/entities/visual-flow/printer.js +19 -0
  226. package/dist-sdk/src/entities/visual-flow/to-tf.js +87 -3
  227. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  228. package/dist-sdk/src/entities/widget/build.js +11 -1
  229. package/dist-sdk/src/entities/widget/from-tf.js +3 -3
  230. package/dist-sdk/src/entities/widget/to-tf.d.ts +2 -0
  231. package/dist-sdk/src/entities/widget/to-tf.js +41 -14
  232. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +148 -13
  233. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  234. package/dist-sdk/src/graph/index.d.ts +12 -0
  235. package/dist-sdk/src/graph/index.js +21 -0
  236. package/dist-sdk/src/graph/modules.js +2 -0
  237. package/dist-sdk/src/graph/types.d.ts +83 -4
  238. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  239. package/dist-sdk/src/internal/sdk-package.js +1 -0
  240. package/package.json +16 -3
@@ -0,0 +1,243 @@
1
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
2
+ import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
3
+ import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
+ import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
5
+ /**
6
+ * Pull must not report success when a service account's generated roles
7
+ * disagree with the export's `role_ids`. Adoption plans the export, so a
8
+ * clean adopt does not prove the authored source kept every role.
9
+ */
10
+ export const SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX = "service-account role_ids mismatch:";
11
+ function sourceFileOf(owner) {
12
+ if (owner.sourceFile !== undefined && owner.sourceFile !== "")
13
+ return owner.sourceFile;
14
+ const ref = tfLabelToTsLabel(owner.ownerTfLabel);
15
+ return `apps/${ref}/${ref}.ts`;
16
+ }
17
+ function describeRoleValue(item) {
18
+ if (typeof item === "string")
19
+ return item;
20
+ if (isTfExpr(item) && (item.$expr === "data-attr" || item.$expr === "resource-attr")) {
21
+ const head = item.$expr === "data-attr" ? `data.${item.type}` : item.type;
22
+ return `${head}.${item.label}.${item.path.join(".")}`;
23
+ }
24
+ return JSON.stringify(item);
25
+ }
26
+ function identityText(identity) {
27
+ if (identity === undefined)
28
+ return "missing";
29
+ if (identity.kind === "unresolved")
30
+ return `unresolved (${identity.detail})`;
31
+ return `${identity.kind}:${identity.value}`;
32
+ }
33
+ function sameIdentity(left, right) {
34
+ if (left.kind === "unresolved" || right.kind === "unresolved") {
35
+ return left.kind === "unresolved" && right.kind === "unresolved" && left.detail === right.detail;
36
+ }
37
+ return left.kind === right.kind && left.value === right.value;
38
+ }
39
+ function exportRoleIdentity(item, blocks, ctx) {
40
+ const resourceLabel = resourceRefLabel(item, "elementum_role");
41
+ if (resourceLabel !== undefined) {
42
+ const role = blocks.find((candidate) => candidate.type === "elementum_role" && candidate.label === resourceLabel);
43
+ if (typeof role?.attrs["name"] === "string" && role.attrs["name"] !== "") {
44
+ return { kind: "name", value: role.attrs["name"] };
45
+ }
46
+ const id = typeof role?.attrs["id"] === "string" ? role.attrs["id"] : ctx.importId(`elementum_role.${resourceLabel}`);
47
+ if (typeof id === "string" && id.trim() !== "")
48
+ return { kind: "id", value: id };
49
+ return { kind: "unresolved", detail: describeRoleValue(item) };
50
+ }
51
+ const dataLabel = dataRefLabel(item, "elementum_role");
52
+ if (dataLabel !== undefined) {
53
+ const name = ctx.dataName("elementum_role", dataLabel);
54
+ if (name !== undefined && name !== "")
55
+ return { kind: "name", value: name };
56
+ return { kind: "unresolved", detail: describeRoleValue(item) };
57
+ }
58
+ if (typeof item === "string" && item.trim() !== "")
59
+ return { kind: "id", value: item };
60
+ return { kind: "unresolved", detail: describeRoleValue(item) };
61
+ }
62
+ function sourceRoleIdentity(role) {
63
+ if (isUnsafePlatformId(role))
64
+ return { kind: "id", value: role.value };
65
+ return { kind: "name", value: role.name };
66
+ }
67
+ function nextStep(sourceFile, key, index) {
68
+ const slot = index === undefined ? `serviceAccounts.${key}.roles` : `serviceAccounts.${key}.roles[${index}]`;
69
+ return `edit ${slot} in ${sourceFile} (add serviceAccountRoleRef("…") or unsafePlatformId("…")) before build/apply; applying as-is changes the account's live roles`;
70
+ }
71
+ function mismatchLine(where, index, exported, generated, sourceFile, key) {
72
+ return `${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids[${index}] export ${identityText(exported)} vs generated ${identityText(generated)}; ${nextStep(sourceFile, key, index)}`;
73
+ }
74
+ function compareRoleLists(where, key, sourceFile, exported, generated, out) {
75
+ if (exported.length === 0 && generated.length === 0)
76
+ return;
77
+ const count = Math.max(exported.length, generated.length);
78
+ for (let index = 0; index < count; index += 1) {
79
+ const left = exported[index];
80
+ const right = generated[index];
81
+ if (left !== undefined && right !== undefined && sameIdentity(left, right))
82
+ continue;
83
+ out.push(mismatchLine(where, index, left, right, sourceFile, key));
84
+ }
85
+ }
86
+ function roleListFromRebuild(value, dataQueues, resourceRoleNames) {
87
+ if (value === undefined)
88
+ return [];
89
+ if (!Array.isArray(value))
90
+ return "not-a-list";
91
+ return value.map((item) => {
92
+ const resourceLabel = resourceRefLabel(item, "elementum_role");
93
+ if (resourceLabel !== undefined) {
94
+ const name = resourceRoleNames.get(resourceLabel);
95
+ if (name !== undefined && name !== "")
96
+ return { kind: "name", value: name };
97
+ return { kind: "unresolved", detail: describeRoleValue(item) };
98
+ }
99
+ const dataLabel = dataRefLabel(item, "elementum_role");
100
+ if (dataLabel !== undefined) {
101
+ const name = dataQueues.get(dataLabel)?.shift();
102
+ if (name !== undefined && name !== "")
103
+ return { kind: "name", value: name };
104
+ return { kind: "unresolved", detail: describeRoleValue(item) };
105
+ }
106
+ if (typeof item === "string" && item.trim() !== "")
107
+ return { kind: "id", value: item };
108
+ return { kind: "unresolved", detail: describeRoleValue(item) };
109
+ });
110
+ }
111
+ function roleList(value, blocks, ctx) {
112
+ if (value === undefined)
113
+ return [];
114
+ if (!Array.isArray(value))
115
+ return "not-a-list";
116
+ return value.map((item) => exportRoleIdentity(item, blocks, ctx));
117
+ }
118
+ function describedRoleIds(value) {
119
+ if (value === undefined)
120
+ return "(none)";
121
+ if (!Array.isArray(value))
122
+ return "not a list";
123
+ return value.map((item) => describeRoleValue(item)).join(", ");
124
+ }
125
+ /**
126
+ * Order-sensitive comparison of each owned service account's export
127
+ * `role_ids` with the roles written into source. Named roles compare by
128
+ * display name; raw ids compare by platform id. A value the printer cannot
129
+ * represent is a disagreement, not a quiet omission.
130
+ */
131
+ export function serviceAccountRoleIdMismatches(blocks, accounts, owner, ctx) {
132
+ return compareServiceAccountRoleIds(blocks, accounts, owner, ctx);
133
+ }
134
+ /**
135
+ * Same order-sensitive rule, against service-account blocks rebuilt from
136
+ * the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
137
+ * disagrees here even when extract mirrored the export.
138
+ * When `lookup` is set, rebuilt refs resolve through it. Export refs still
139
+ * use `ctx` and the export blocks.
140
+ */
141
+ export function rebuiltServiceAccountRoleIdMismatches(exportBlocks, rebuiltBlocks, owner, ctx, lookup) {
142
+ const dataQueues = new Map();
143
+ if (lookup !== undefined) {
144
+ for (const [label, names] of lookup.dataRoleNames)
145
+ dataQueues.set(label, [...names]);
146
+ }
147
+ const rebuiltAccounts = rebuiltBlocks.flatMap((block) => {
148
+ if (block.type !== SERVICE_ACCOUNT_RESOURCE_TYPE || block.label === undefined || block.label === "")
149
+ return [];
150
+ const roles = lookup === undefined
151
+ ? roleList(block.attrs["role_ids"], exportBlocks, ctx)
152
+ : roleListFromRebuild(block.attrs["role_ids"], dataQueues, lookup.resourceRoleNames);
153
+ return [{
154
+ key: scopedLabelToBagKey(owner.ownerTfLabel, block.label, "app"),
155
+ label: block.label,
156
+ roles,
157
+ }];
158
+ });
159
+ return compareServiceAccountRoleIds(exportBlocks, rebuiltAccounts.map((account) => ({
160
+ key: account.key,
161
+ roles: account.roles === "not-a-list" ? undefined : account.roles.map((role) => {
162
+ if (role.kind === "id")
163
+ return { __unsafe: "platformId", value: role.value };
164
+ if (role.kind === "name")
165
+ return { __kind: "serviceAccountRole", name: role.value };
166
+ return undefined;
167
+ }).filter((role) => role !== undefined),
168
+ })), owner, ctx, rebuiltAccounts);
169
+ }
170
+ function compareServiceAccountRoleIds(blocks, accounts, owner, ctx, rebuilt) {
171
+ const mismatches = [];
172
+ const sourceFile = sourceFileOf(owner);
173
+ const seen = new Set();
174
+ for (const block of blocks) {
175
+ if (block.type !== SERVICE_ACCOUNT_RESOURCE_TYPE)
176
+ continue;
177
+ if (resourceRefLabel(block.attrs["app_id"], "elementum_app") !== owner.label)
178
+ continue;
179
+ const label = block.label ?? "";
180
+ const where = `${SERVICE_ACCOUNT_RESOURCE_TYPE}.${label || "?"}`;
181
+ const exported = block.attrs["role_ids"];
182
+ if (label === "") {
183
+ if (exported !== undefined) {
184
+ mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where} was not written to source (role_ids: ${describedRoleIds(exported)}); ${nextStep(sourceFile, "?", undefined)}`);
185
+ }
186
+ continue;
187
+ }
188
+ const key = scopedLabelToBagKey(owner.ownerTfLabel, label, "app");
189
+ seen.add(key);
190
+ const account = accounts.find((candidate) => candidate.key === key);
191
+ const rebuiltAccount = rebuilt?.find((candidate) => candidate.key === key);
192
+ if (!Array.isArray(exported) && exported !== undefined) {
193
+ mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids export role_ids is not a list (${describedRoleIds(exported)}); ${nextStep(sourceFile, key, undefined)}`);
194
+ continue;
195
+ }
196
+ const exportedRoles = exported === undefined ? [] : exported.map((item) => exportRoleIdentity(item, blocks, ctx));
197
+ if (rebuiltAccount !== undefined) {
198
+ if (rebuiltAccount.roles === "not-a-list") {
199
+ mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids rebuild role_ids is not a list; ${nextStep(sourceFile, key, undefined)}`);
200
+ }
201
+ else {
202
+ compareRoleLists(where, key, sourceFile, exportedRoles, rebuiltAccount.roles, mismatches);
203
+ }
204
+ continue;
205
+ }
206
+ const generatedRoles = account?.roles?.map(sourceRoleIdentity) ?? [];
207
+ if (account === undefined && exportedRoles.length > 0) {
208
+ mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where} was not written to source (role_ids: ${describedRoleIds(exported)}); ${nextStep(sourceFile, key, undefined)}`);
209
+ }
210
+ compareRoleLists(where, key, sourceFile, exportedRoles, generatedRoles, mismatches);
211
+ }
212
+ if (rebuilt === undefined) {
213
+ for (const account of accounts) {
214
+ if (seen.has(account.key) || (account.roles?.length ?? 0) === 0)
215
+ continue;
216
+ mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} serviceAccounts.${account.key} has roles with no export service account; ${nextStep(sourceFile, account.key, undefined)}`);
217
+ }
218
+ }
219
+ return mismatches;
220
+ }
221
+ /** Authoring files named by role-mismatch lines, in first-seen order. */
222
+ export function serviceAccountRoleMismatchSources(lines) {
223
+ const files = [];
224
+ for (const line of lines) {
225
+ const match = / in (\S+\.ts) /.exec(line);
226
+ if (match?.[1] !== undefined && !files.includes(match[1]))
227
+ files.push(match[1]);
228
+ }
229
+ return files;
230
+ }
231
+ /** Single-root build-vs-export lines that are a service-account `role_ids` disagreement. */
232
+ export function serviceAccountRoleRoundTripMismatches(differences, sourceFile) {
233
+ return differences
234
+ .filter((line) => line.includes("resource:elementum_service_account.") && line.includes("role_ids"))
235
+ .map((line) => `${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${line}; edit serviceAccounts in ${sourceFile} (add serviceAccountRoleRef("…") or unsafePlatformId("…")) before build/apply; applying as-is changes the account's live roles`);
236
+ }
237
+ export function serviceAccountRoleGuardBlocksSuccess(diagnostics) {
238
+ return diagnostics.some((line) => line.includes(SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX));
239
+ }
240
+ /** Adoption failure fails a pull. Role-id disagreement must too, even when adoption succeeded or was skipped. */
241
+ export function serviceAccountPullMustFail(input) {
242
+ return input.adoptionFailed || serviceAccountRoleGuardBlocksSuccess(input.diagnostics);
243
+ }
@@ -31,3 +31,17 @@ export declare function serviceAccountsToTf(accounts: Readonly<Record<string, Ap
31
31
  readonly orgRefs: OrgRefLookup;
32
32
  readonly diagnostics: string[];
33
33
  }): TfBlock[];
34
+ /**
35
+ * Service-account blocks for one app. `appToTf` and the pull role rebuild
36
+ * both call this, so the `roles` bag and the other arguments cannot drift
37
+ * between build and the guard.
38
+ */
39
+ export declare function appServiceAccountBlocks(payload: {
40
+ readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
41
+ readonly roles?: Readonly<Record<string, AppRole>>;
42
+ }, opts: {
43
+ readonly ownerTfLabel: string;
44
+ readonly appId: TfValue;
45
+ readonly orgRefs: OrgRefLookup;
46
+ readonly diagnostics: string[];
47
+ }): TfBlock[];
@@ -1,3 +1,4 @@
1
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
1
2
  import { appScopedResourceLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
2
3
  import { SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE, SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
3
4
  /**
@@ -64,6 +65,8 @@ function principalValues(values, type, where, orgRefs, diagnostics) {
64
65
  return out.length > 0 ? out : undefined;
65
66
  }
66
67
  function roleValue(value, roles, ownerTfLabel, appId, orgRefs) {
68
+ if (isUnsafePlatformId(value))
69
+ return value.value;
67
70
  const local = Object.entries(roles ?? {}).find(([, role]) => role.name === value.name);
68
71
  if (local !== undefined) {
69
72
  return expr.resourceAttr("elementum_role", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(local[0]), "app"), ["id"]);
@@ -108,3 +111,17 @@ export function serviceAccountsToTf(accounts, opts) {
108
111
  }
109
112
  return blocks;
110
113
  }
114
+ /**
115
+ * Service-account blocks for one app. `appToTf` and the pull role rebuild
116
+ * both call this, so the `roles` bag and the other arguments cannot drift
117
+ * between build and the guard.
118
+ */
119
+ export function appServiceAccountBlocks(payload, opts) {
120
+ return serviceAccountsToTf(payload.serviceAccounts, {
121
+ ownerTfLabel: opts.ownerTfLabel,
122
+ appId: opts.appId,
123
+ roles: payload.roles,
124
+ orgRefs: opts.orgRefs,
125
+ diagnostics: opts.diagnostics,
126
+ });
127
+ }
@@ -0,0 +1,16 @@
1
+ import { type WorkspaceAspect } from "../../engine/build/context.js";
2
+ import { type TfValue } from "../../engine/tf/index.js";
3
+ import type { AppServiceAccount } from "./build.js";
4
+ /** The app that owns a service account, as a role or policy on another object resolves it. */
5
+ export interface ServiceAccountOwningApp {
6
+ readonly appTfLabel: string;
7
+ readonly appId: TfValue;
8
+ readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
9
+ }
10
+ /**
11
+ * Resolve the workspace app that owns a `serviceAccountRef` named from a
12
+ * different object (another app or an element), so its lookup is scoped to the
13
+ * OWNING app (#1592), not the object that grants it access. A managed account
14
+ * becomes a direct resource ref, so same-apply creation is sequenced.
15
+ */
16
+ export declare function workspaceServiceAccountAppResolver(workspaceAspects: ReadonlyMap<string, WorkspaceAspect> | undefined): (appRefName: string) => ServiceAccountOwningApp | undefined;
@@ -0,0 +1,22 @@
1
+ import { workspaceAspectKey } from "../../engine/build/context.js";
2
+ import { expr } from "../../engine/tf/index.js";
3
+ import { APP_RESOURCE_TYPE } from "../app/module.js";
4
+ /**
5
+ * Resolve the workspace app that owns a `serviceAccountRef` named from a
6
+ * different object (another app or an element), so its lookup is scoped to the
7
+ * OWNING app (#1592), not the object that grants it access. A managed account
8
+ * becomes a direct resource ref, so same-apply creation is sequenced.
9
+ */
10
+ export function workspaceServiceAccountAppResolver(workspaceAspects) {
11
+ return (appRefName) => {
12
+ const app = workspaceAspects?.get(workspaceAspectKey("app", appRefName));
13
+ if (app === undefined)
14
+ return undefined;
15
+ const serviceAccounts = app.streamRootEntity?.payload?.serviceAccounts;
16
+ return {
17
+ appTfLabel: app.tfLabel,
18
+ appId: expr.resourceAttr(APP_RESOURCE_TYPE, app.tfLabel, ["id"]),
19
+ ...(serviceAccounts !== undefined ? { serviceAccounts } : {}),
20
+ };
21
+ };
22
+ }
@@ -11,7 +11,7 @@ export interface ResolvedAspectTarget {
11
11
  readonly key: string;
12
12
  readonly name: string;
13
13
  readonly namespace?: string;
14
- /** `key`/`name` are the target's real pulled catalog identity, not a guess. */
14
+ /** `key` is the target's real catalog identity: pulled, or derived from its namespace (its stream label). */
15
15
  readonly catalogRef?: true;
16
16
  }
17
17
  /**
@@ -1,4 +1,4 @@
1
- import { tfLabelToTsLabel } from "../../engine/tf/index.js";
1
+ import { sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
2
2
  /**
3
3
  * Resolve a foreign app/element data lookup to its display name. Ref-only
4
4
  * lookups are intentionally namespace-only, so fall back through the
@@ -40,7 +40,10 @@ export function dataAspectRefName(ctx, kind, label, displayName) {
40
40
  }
41
41
  const name = displayName ?? dataAspectDisplayName(ctx, kind, label);
42
42
  const byName = kind === "app" ? ctx.foreignAppRefNames : kind === "element" ? ctx.foreignElementRefNames : undefined;
43
- return name === undefined ? undefined : byName?.get(name);
43
+ const pulled = name === undefined ? undefined : byName?.get(name);
44
+ // An app's or element's stream label is its sanitized namespace (ei AppResourceName /
45
+ // ElementResourceName), so the namespace alone gives the real refName before the target is pulled.
46
+ return pulled ?? (namespace === undefined ? undefined : tfLabelToTsLabel(sanitizeName(namespace)));
44
47
  }
45
48
  /**
46
49
  * Resolve a foreign app/element data lookup to the full identity a caller
@@ -42,6 +42,8 @@ export interface AppRefAst {
42
42
  readonly entityType?: "app" | "element" | "task";
43
43
  /** Provider lookup name for that foreign app/element. */
44
44
  readonly name?: string;
45
+ /** Set when the export looked the foreign root up by namespace; build then does too. */
46
+ readonly namespace?: string;
45
47
  }
46
48
  /** Reference to an app field: `<appHandle>.fields.<fieldKey>`. */
47
49
  export interface FieldRefAst {
@@ -82,6 +84,14 @@ export interface SearchTableRefAst {
82
84
  readonly kind: "searchTable";
83
85
  readonly appHandle: string;
84
86
  readonly tableKey: string;
87
+ /** Table-owned lookup. Element-owned catalog refs leave this unset. */
88
+ readonly ownerKind?: "table" | "element";
89
+ /** Display name of the search table, when the reference is not a catalog key. */
90
+ readonly name?: string;
91
+ /** Display name of a table owner. */
92
+ readonly parentName?: string;
93
+ /** Set when the search table's name is not unique on its owner. */
94
+ readonly id?: string;
85
95
  }
86
96
  /** Reference to an app-owned phone service. */
87
97
  export interface PhoneServiceRefAst {
@@ -94,6 +104,18 @@ export interface UserRefAst {
94
104
  readonly kind: "user";
95
105
  readonly email: string;
96
106
  }
107
+ /** Reference to an existing vault entry by key: `secret("<key>")`. */
108
+ export interface SecretRefAst {
109
+ readonly kind: "secret";
110
+ readonly key: string;
111
+ }
112
+ /** Organization group from the org catalog's `groups` bag (`org.groups.<key>`). */
113
+ export interface GroupRefAst {
114
+ readonly kind: "orgGroup";
115
+ readonly groupKey: string;
116
+ /** The group's display name — the lookup value. */
117
+ readonly name: string;
118
+ }
97
119
  /** Reference to a sub-automation via the app's `automations` bag. */
98
120
  export interface AutomationRefAst {
99
121
  readonly kind: "automation";
@@ -251,7 +273,7 @@ export type RefExpr =
251
273
  | {
252
274
  kind: "template";
253
275
  parts: readonly (string | RefExpr)[];
254
- } | FieldRefAst | UserFieldRefAst | UserGroupFieldRefAst | AppRefAst | AgentRefAst | AutomationRefAst | DocumentModelRefAst | DocumentModelFieldRefAst | ApprovalChainRefAst | DatamineRefAst | TableRefAst | TableColumnRefAst | SearchTableRefAst | ConnectorRefAst | CloudLinkRefAst | ProcedureRefAst | PhoneServiceRefAst | UserRefAst | UnresolvedRefAst
276
+ } | FieldRefAst | UserFieldRefAst | UserGroupFieldRefAst | AppRefAst | AgentRefAst | AutomationRefAst | DocumentModelRefAst | DocumentModelFieldRefAst | ApprovalChainRefAst | DatamineRefAst | TableRefAst | TableColumnRefAst | SearchTableRefAst | ConnectorRefAst | CloudLinkRefAst | ProcedureRefAst | PhoneServiceRefAst | UserRefAst | SecretRefAst | GroupRefAst | UnresolvedRefAst
255
277
  /** Preserved terraform local expression for round-trip (e.g. status option ids by label). */
256
278
  | {
257
279
  kind: "localRef";
@@ -69,5 +69,7 @@ export function isRefExpr(value) {
69
69
  kind === "procedure" ||
70
70
  kind === "phoneService" ||
71
71
  kind === "user" ||
72
+ kind === "secret" ||
73
+ kind === "orgGroup" ||
72
74
  kind === "unresolved");
73
75
  }
@@ -23,6 +23,8 @@ export interface FilterReferenceInput {
23
23
  readonly [FILTER_REFERENCE_BRAND]: true;
24
24
  readonly ref: Ref<unknown> | string;
25
25
  readonly valueType: ValueType;
26
+ /** The caller named this type. Build must not replace it with field metadata. */
27
+ readonly explicit: true;
26
28
  readonly multiple?: boolean;
27
29
  }
28
30
  export declare function boolean(ref: Ref<unknown> | string, options?: {
@@ -78,9 +80,14 @@ export declare function fieldValue(value: FilterField, options?: {
78
80
  * Compare against a field on the record being edited — a dynamic Dropdown
79
81
  * filter such as "source Process Area equals this record's Process Area".
80
82
  * `field` must belong to the Dropdown's own app or element.
83
+ *
84
+ * `includeOwner` stores the Dropdown's own app or element alongside the field,
85
+ * the form some existing filters were saved in. Pull keeps whichever form the
86
+ * platform holds, so adopting the filter changes nothing.
81
87
  */
82
88
  export declare function recordField(field: FilterField, options?: {
83
89
  readonly required?: boolean;
90
+ readonly includeOwner?: boolean;
84
91
  }): Extract<FilterValue<FilterField, FilterReferenceValue>, {
85
92
  type: "RECORD_FIELD";
86
93
  }>;
@@ -52,7 +52,7 @@ export function referenceValueTypeForField(fieldType, suffix = "") {
52
52
  }
53
53
  const FILTER_REFERENCE_BRAND = Symbol("FilterReferenceInput");
54
54
  function referenceInput(ref, valueType, options) {
55
- return { [FILTER_REFERENCE_BRAND]: true, ref, valueType, ...(options?.multiple === true && { multiple: true }) };
55
+ return { [FILTER_REFERENCE_BRAND]: true, ref, valueType, explicit: true, ...(options?.multiple === true && { multiple: true }) };
56
56
  }
57
57
  export function boolean(ref, options) {
58
58
  return referenceInput(ref, "BOOLEAN", options);
@@ -105,11 +105,16 @@ export function fieldValue(value, options) {
105
105
  * Compare against a field on the record being edited — a dynamic Dropdown
106
106
  * filter such as "source Process Area equals this record's Process Area".
107
107
  * `field` must belong to the Dropdown's own app or element.
108
+ *
109
+ * `includeOwner` stores the Dropdown's own app or element alongside the field,
110
+ * the form some existing filters were saved in. Pull keeps whichever form the
111
+ * platform holds, so adopting the filter changes nothing.
108
112
  */
109
113
  export function recordField(field, options) {
110
114
  return {
111
115
  type: "RECORD_FIELD",
112
116
  field: fieldWireValue(field),
117
+ ...(options?.includeOwner === true && { includeOwner: true }),
113
118
  ...(options?.required !== undefined && { required: options.required }),
114
119
  };
115
120
  }
@@ -174,15 +179,25 @@ function leftType(left, fallback, explicit) {
174
179
  return fallback;
175
180
  return fieldTypeToValueType(isAppField(left) ? left.type : "fieldType" in left ? left.fieldType : undefined);
176
181
  }
182
+ function referenceValue(realType, value, explicit) {
183
+ return {
184
+ type: "REFERENCE",
185
+ realType,
186
+ // A passed comparison type (`filter.eq(ref, value, "TEXT")`) is authored.
187
+ // An omitted type is the operator fallback, which field metadata may replace.
188
+ ...(explicit !== undefined ? { explicit: true } : {}),
189
+ value,
190
+ };
191
+ }
177
192
  function leftDescriptor(left, fallback, explicit) {
178
193
  if (isFieldLeftValue(left))
179
194
  return { leftValue: left };
180
195
  if (isFilterReferenceInput(left))
181
196
  return { leftValue: toFilterValue(left) };
182
197
  if (isRef(left))
183
- return { leftValue: { type: "REFERENCE", realType: explicit ?? fallback, value: refDataToFilterReference(left.__data) } };
198
+ return { leftValue: referenceValue(explicit ?? fallback, refDataToFilterReference(left.__data), explicit) };
184
199
  if (typeof left === "string" && left.startsWith(UNRESOLVED_REFERENCE_MARKER)) {
185
- return { leftValue: { type: "REFERENCE", realType: explicit ?? fallback, value: { __rawFilterReference: left.slice(UNRESOLVED_REFERENCE_MARKER.length) } } };
200
+ return { leftValue: referenceValue(explicit ?? fallback, { __rawFilterReference: left.slice(UNRESOLVED_REFERENCE_MARKER.length) }, explicit) };
186
201
  }
187
202
  return { field: fieldWireValue(left) };
188
203
  }
@@ -204,7 +219,7 @@ export function toFilterValue(input, valueType = "TEXT") {
204
219
  : typeof input.ref === "string"
205
220
  ? { __rawFilterReference: input.ref }
206
221
  : refDataToFilterReference(input.ref.__data);
207
- return { type: "REFERENCE", realType: input.valueType, value, ...(input.multiple === true && { multiple: true }) };
222
+ return { type: "REFERENCE", realType: input.valueType, explicit: true, value, ...(input.multiple === true && { multiple: true }) };
208
223
  }
209
224
  if (isRef(input)) {
210
225
  if (input.__data.kind === "static")
@@ -13,9 +13,12 @@ export function printFilter(filter, codec) {
13
13
  : "min" in filter ? [filter.min, filter.max] : [];
14
14
  const uuidValues = literals.length > 0 && literals.every((literal) => literal.type === "UUID");
15
15
  const explicitType = uuidValues ? `, ${quote("UUID")}` : "";
16
+ const impliedLiteralType = stringLiteralTypeImpliedBy(filter, uuidValues);
16
17
  const value = (input) => input.type === "UUID"
17
18
  ? uuidValues ? quote(input.value) : `{ type: "UUID", value: ${quote(input.value)} }`
18
- : printFilterValue(input, codec, call, quote);
19
+ : (input.type === "TEXT" || input.type === "DATE" || input.type === "DATETIME") && impliedLiteralType !== undefined && input.type !== impliedLiteralType
20
+ ? `{ type: ${quote(input.type)}, value: ${quote(input.value)} }`
21
+ : printFilterValue(input, codec, call, quote);
19
22
  if ("leftValue" in filter && filter.leftValue?.type === "FIELD") {
20
23
  const operand = filter.leftValue;
21
24
  if ((operand.aspect != null && operand.aspect !== "") || (operand.treatNullAsEquals != null && operand.treatNullAsEquals !== true)) {
@@ -76,6 +79,19 @@ export function printFilter(filter, codec) {
76
79
  ];
77
80
  return options.length === 0 ? printed : call("withOptions", `${printed}, { ${options.join(", ")} }`);
78
81
  }
82
+ /**
83
+ * The type `filter.*` gives a bare string literal when the left operand prints as a typed reference wrapper
84
+ * (`filter.uuid(…)`, `filter.date(…)`): the wrapper's type, narrowed to the string-valued ones, else TEXT.
85
+ * Undefined for every other left operand, whose literals already print as before.
86
+ */
87
+ function stringLiteralTypeImpliedBy(filter, uuidValues) {
88
+ if (!("leftValue" in filter) || filter.leftValue?.type !== "REFERENCE" || filter.leftValue.realType === undefined)
89
+ return undefined;
90
+ if (uuidValues)
91
+ return "UUID";
92
+ const realType = filter.leftValue.realType;
93
+ return realType === "UUID" || realType === "DATE" || realType === "DATETIME" ? realType : "TEXT";
94
+ }
79
95
  function printLikeOptions(filter, quote) {
80
96
  const options = [];
81
97
  if (filter.not === true)
@@ -145,8 +161,13 @@ function printFilterValue(value, codec, call, quote) {
145
161
  if (typeof value.field === "string")
146
162
  return `${JSON.stringify(value)} as const`;
147
163
  const { type: _type, field, required, ...rest } = value;
148
- if (Object.keys(rest).length === 0) {
149
- return call("recordField", `${codec.field(field)}${required !== undefined ? `, { required: ${required} }` : ""}`);
164
+ const { includeOwner, ...unhelped } = rest;
165
+ if (Object.keys(unhelped).length === 0) {
166
+ const options = [
167
+ ...(required !== undefined ? [`required: ${required}`] : []),
168
+ ...(includeOwner === true ? ["includeOwner: true"] : []),
169
+ ];
170
+ return call("recordField", `${codec.field(field)}${options.length > 0 ? `, { ${options.join(", ")} }` : ""}`);
150
171
  }
151
172
  const extras = Object.entries({ ...rest, ...(required !== undefined && { required }) })
152
173
  .map(([key, item]) => `${key}: ${JSON.stringify(item)}`);
@@ -98,12 +98,16 @@ export interface FilterToTfCodec {
98
98
  readonly literal?: (value: TfValue, field: unknown | undefined, valueType: string, isOptionLabel: boolean) => TfValue;
99
99
  /** A RECORD_FIELD value's source-record field; without it only raw platform ids encode. */
100
100
  readonly recordField?: (value: unknown) => TfValue;
101
+ /** The owning app or element an `includeOwner` RECORD_FIELD value stores; without it such a value cannot encode. */
102
+ readonly recordFieldOwner?: () => TfValue;
101
103
  readonly fieldFromLeftValue?: (value: unknown) => unknown | undefined;
102
104
  /**
103
105
  * Override the REFERENCE `real_type` that would otherwise default to TEXT.
104
106
  * Return a GraphQL ValueType (TEXT/UUID/NUMBER/…) or undefined to keep the
105
107
  * authored/default value. Used when a trigger-record Ref's field metadata
106
108
  * is a better authority than `isNull`'s TEXT operator fallback.
109
+ * Not called for an explicit wrapper (`filter.text()`, `filter.uuid()`, …):
110
+ * that authored type is kept as written.
107
111
  */
108
112
  readonly referenceRealType?: (reference: unknown, role: "left" | "value", authored: string | undefined) => string | undefined;
109
113
  }
@@ -122,6 +126,8 @@ export interface FilterFromTfCodec<Field = string, ReferenceValue = never> {
122
126
  readonly literal?: (value: TfValue, valueType: string) => TfValue;
123
127
  /** Decode a RECORD_FIELD value's source-record field reference; without it only raw platform ids decode. */
124
128
  readonly recordField?: (value: TfValue) => Field;
129
+ /** Whether a RECORD_FIELD `object` reference names the owning app or element; without it only raw platform ids decode. */
130
+ readonly recordFieldOwner?: (value: TfValue) => boolean;
125
131
  /**
126
132
  * A TEXT-wrapped literal `literal` resolved from an option-id lookup is an
127
133
  * option LABEL, not a stored word. Set this when the owner cannot rebuild a
@@ -145,6 +151,7 @@ export type WireFilterValue = Readonly<{
145
151
  dynamicFieldAspect?: TfValue;
146
152
  sourceFieldType?: string;
147
153
  required?: boolean;
154
+ includeOwner?: boolean;
148
155
  }>;
149
156
  type WireFilterBase = Readonly<{
150
157
  field?: TfValue;