@elementumai/edk 0.9.2 → 0.9.6

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 (296) hide show
  1. package/README.md +34 -26
  2. package/dist-sdk/elementum-entity-client/clients/automation/models/automation.d.ts +1 -1
  3. package/dist-sdk/elementum-entity-client/clients/skills/models/skill.d.ts +1 -1
  4. package/dist-sdk/elementum-entity-client/clients/skills/models/skill.js +1 -1
  5. package/dist-sdk/pull/util.d.ts +1 -1
  6. package/dist-sdk/pull/util.js +3 -3
  7. package/dist-sdk/src/catalog/factories.d.ts +49 -10
  8. package/dist-sdk/src/catalog/factories.js +94 -13
  9. package/dist-sdk/src/catalog/from-authoring.d.ts +5 -5
  10. package/dist-sdk/src/catalog/from-authoring.js +7 -7
  11. package/dist-sdk/src/catalog/index.d.ts +2 -2
  12. package/dist-sdk/src/catalog/index.js +1 -1
  13. package/dist-sdk/src/catalog/org.js +62 -4
  14. package/dist-sdk/src/catalog/render-helpers.d.ts +1 -1
  15. package/dist-sdk/src/catalog/render-helpers.js +1 -1
  16. package/dist-sdk/src/catalog/render.d.ts +1 -0
  17. package/dist-sdk/src/catalog/render.js +2 -2
  18. package/dist-sdk/src/catalog/token.js +11 -4
  19. package/dist-sdk/src/catalog/types.d.ts +33 -4
  20. package/dist-sdk/src/catalog/types.js +5 -0
  21. package/dist-sdk/src/core/index.d.ts +10 -10
  22. package/dist-sdk/src/core/index.js +9 -9
  23. package/dist-sdk/src/core/render-tree.d.ts +1 -1
  24. package/dist-sdk/src/core/render-tree.js +1 -2
  25. package/dist-sdk/src/core/types/ai-provider.d.ts +1 -1
  26. package/dist-sdk/src/core/types/ai-provider.js +1 -1
  27. package/dist-sdk/src/core/types/app.d.ts +66 -30
  28. package/dist-sdk/src/core/types/app.js +2 -2
  29. package/dist-sdk/src/core/types/aspect-category.d.ts +4 -4
  30. package/dist-sdk/src/core/types/aspect-category.js +4 -4
  31. package/dist-sdk/src/core/types/cloud-link.d.ts +3 -3
  32. package/dist-sdk/src/core/types/cloud-link.js +3 -3
  33. package/dist-sdk/src/core/types/display-block.d.ts +2 -2
  34. package/dist-sdk/src/core/types/display-block.js +2 -2
  35. package/dist-sdk/src/core/types/group.d.ts +1 -1
  36. package/dist-sdk/src/core/types/group.js +1 -1
  37. package/dist-sdk/src/core/types/user.d.ts +1 -1
  38. package/dist-sdk/src/core/types/user.js +1 -1
  39. package/dist-sdk/src/core/wire/ref-serializer.js +3 -3
  40. package/dist-sdk/src/engine/build/context.d.ts +20 -13
  41. package/dist-sdk/src/engine/entity.d.ts +1 -1
  42. package/dist-sdk/src/engine/pull/context.d.ts +34 -0
  43. package/dist-sdk/src/engine/pull/context.js +14 -0
  44. package/dist-sdk/src/engine/pull/org.d.ts +9 -0
  45. package/dist-sdk/src/engine/pull/org.js +33 -0
  46. package/dist-sdk/src/engine/pull/ref-only.d.ts +37 -0
  47. package/dist-sdk/src/engine/pull/ref-only.js +204 -0
  48. package/dist-sdk/src/engine/tf/expr.d.ts +6 -2
  49. package/dist-sdk/src/engine/tf/expr.js +18 -13
  50. package/dist-sdk/src/engine/tf/index.d.ts +1 -1
  51. package/dist-sdk/src/engine/tf/index.js +1 -1
  52. package/dist-sdk/src/engine/tf/model.d.ts +8 -1
  53. package/dist-sdk/src/engine/tf/model.js +4 -0
  54. package/dist-sdk/src/engine/tf/parse.js +13 -2
  55. package/dist-sdk/src/engine/tf/render.js +4 -0
  56. package/dist-sdk/src/entities/access-policy/build.d.ts +4 -5
  57. package/dist-sdk/src/entities/access-policy/build.js +1 -1
  58. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +4 -4
  59. package/dist-sdk/src/entities/access-policy/from-tf.js +12 -13
  60. package/dist-sdk/src/entities/access-policy/principal.d.ts +14 -4
  61. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +14 -2
  62. package/dist-sdk/src/entities/access-policy/to-tf.js +36 -6
  63. package/dist-sdk/src/entities/agent/build.d.ts +3 -3
  64. package/dist-sdk/src/entities/agent/build.js +5 -5
  65. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +6 -1
  66. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -18
  67. package/dist-sdk/src/entities/agent/from-tf.d.ts +3 -1
  68. package/dist-sdk/src/entities/agent/from-tf.js +12 -4
  69. package/dist-sdk/src/entities/agent/index.d.ts +2 -2
  70. package/dist-sdk/src/entities/agent/index.js +1 -1
  71. package/dist-sdk/src/entities/agent/module.js +2 -0
  72. package/dist-sdk/src/entities/agent/to-tf.d.ts +5 -2
  73. package/dist-sdk/src/entities/agent/to-tf.js +56 -8
  74. package/dist-sdk/src/entities/agent/tools.d.ts +38 -23
  75. package/dist-sdk/src/entities/agent/tools.js +21 -7
  76. package/dist-sdk/src/entities/agent-evaluation/build.d.ts +19 -0
  77. package/dist-sdk/src/entities/agent-evaluation/build.js +41 -0
  78. package/dist-sdk/src/entities/agent-evaluation/deserializer/print-agent-evaluation.d.ts +4 -0
  79. package/dist-sdk/src/entities/agent-evaluation/deserializer/print-agent-evaluation.js +30 -0
  80. package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +12 -0
  81. package/dist-sdk/src/entities/agent-evaluation/from-tf.js +46 -0
  82. package/dist-sdk/src/entities/agent-evaluation/index.d.ts +1 -0
  83. package/dist-sdk/src/entities/agent-evaluation/index.js +1 -0
  84. package/dist-sdk/src/entities/agent-evaluation/module.d.ts +3 -0
  85. package/dist-sdk/src/entities/agent-evaluation/module.js +58 -0
  86. package/dist-sdk/src/entities/agent-evaluation/to-tf.d.ts +12 -0
  87. package/dist-sdk/src/entities/agent-evaluation/to-tf.js +35 -0
  88. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +8 -7
  89. package/dist-sdk/src/entities/agent-tool/from-tf.js +48 -6
  90. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +10 -2
  91. package/dist-sdk/src/entities/agent-tool/to-tf.js +76 -28
  92. package/dist-sdk/src/entities/agent-tool/types.d.ts +0 -1
  93. package/dist-sdk/src/entities/agent-tool/types.js +10 -37
  94. package/dist-sdk/src/entities/app/build.d.ts +97 -42
  95. package/dist-sdk/src/entities/app/build.js +25 -14
  96. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +32 -24
  97. package/dist-sdk/src/entities/app/deserializer/pulled-expression.d.ts +1 -1
  98. package/dist-sdk/src/entities/app/deserializer/pulled-expression.js +2 -0
  99. package/dist-sdk/src/entities/app/index.d.ts +11 -8
  100. package/dist-sdk/src/entities/app/index.js +10 -7
  101. package/dist-sdk/src/entities/app/module.js +2 -2
  102. package/dist-sdk/src/entities/app/to-tf.d.ts +1 -1
  103. package/dist-sdk/src/entities/app/to-tf.js +22 -6
  104. package/dist-sdk/src/entities/approval-chain/build.d.ts +1 -1
  105. package/dist-sdk/src/entities/approval-chain/build.js +5 -5
  106. package/dist-sdk/src/entities/approval-chain/index.d.ts +1 -1
  107. package/dist-sdk/src/entities/approval-chain/index.js +1 -1
  108. package/dist-sdk/src/entities/approval-chain/printer.js +2 -2
  109. package/dist-sdk/src/entities/automation/build.d.ts +172 -94
  110. package/dist-sdk/src/entities/automation/build.js +159 -68
  111. package/dist-sdk/src/entities/automation/calculation-expression.d.ts +191 -0
  112. package/dist-sdk/src/entities/automation/calculation-expression.js +57 -0
  113. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +11 -4
  114. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +18 -14
  115. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +164 -198
  116. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -2
  117. package/dist-sdk/src/entities/automation/from-tf.js +510 -80
  118. package/dist-sdk/src/entities/automation/index.d.ts +9 -12
  119. package/dist-sdk/src/entities/automation/index.js +11 -13
  120. package/dist-sdk/src/entities/automation/module.js +74 -6
  121. package/dist-sdk/src/entities/automation/operators.d.ts +32 -48
  122. package/dist-sdk/src/entities/automation/operators.js +10 -37
  123. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +1 -1
  124. package/dist-sdk/src/entities/automation/output-key-wire-name.js +1 -1
  125. package/dist-sdk/src/entities/automation/script-code.js +13 -22
  126. package/dist-sdk/src/entities/automation/serialize.js +1 -1
  127. package/dist-sdk/src/entities/automation/tasks.d.ts +153 -89
  128. package/dist-sdk/src/entities/automation/tasks.js +64 -11
  129. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -1
  130. package/dist-sdk/src/entities/automation/to-tf.js +342 -71
  131. package/dist-sdk/src/entities/automation/triggers.d.ts +17 -10
  132. package/dist-sdk/src/entities/automation/triggers.js +7 -1
  133. package/dist-sdk/src/entities/automation/types.d.ts +3 -2
  134. package/dist-sdk/src/entities/automation/types.js +3 -2
  135. package/dist-sdk/src/entities/chart/build.d.ts +95 -0
  136. package/dist-sdk/src/entities/chart/build.js +42 -0
  137. package/dist-sdk/src/entities/chart/from-tf.d.ts +55 -0
  138. package/dist-sdk/src/entities/chart/from-tf.js +269 -0
  139. package/dist-sdk/src/entities/chart/index.d.ts +4 -0
  140. package/dist-sdk/src/entities/chart/index.js +3 -0
  141. package/dist-sdk/src/entities/chart/module.d.ts +3 -0
  142. package/dist-sdk/src/entities/chart/module.js +61 -0
  143. package/dist-sdk/src/entities/chart/printer.d.ts +5 -0
  144. package/dist-sdk/src/entities/chart/printer.js +104 -0
  145. package/dist-sdk/src/entities/chart/to-tf.d.ts +15 -0
  146. package/dist-sdk/src/entities/chart/to-tf.js +150 -0
  147. package/dist-sdk/src/entities/chart/types.d.ts +53 -0
  148. package/dist-sdk/src/entities/chart/types.js +22 -0
  149. package/dist-sdk/src/entities/dashboard/build.d.ts +34 -7
  150. package/dist-sdk/src/entities/dashboard/build.js +16 -1
  151. package/dist-sdk/src/entities/dashboard/from-tf.js +22 -4
  152. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +16 -3
  153. package/dist-sdk/src/entities/dashboard/to-tf.js +37 -10
  154. package/dist-sdk/src/entities/datamine/module.js +1 -1
  155. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +4 -3
  156. package/dist-sdk/src/entities/dynamic-layout/build.js +1 -1
  157. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +2 -0
  158. package/dist-sdk/src/entities/dynamic-layout/dialect.js +43 -5
  159. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +12 -6
  160. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +10 -10
  161. package/dist-sdk/src/entities/element/build.d.ts +25 -32
  162. package/dist-sdk/src/entities/element/build.js +15 -32
  163. package/dist-sdk/src/entities/element/index.d.ts +7 -5
  164. package/dist-sdk/src/entities/element/index.js +7 -4
  165. package/dist-sdk/src/entities/element/module.js +7 -3
  166. package/dist-sdk/src/entities/element/to-tf.d.ts +2 -1
  167. package/dist-sdk/src/entities/element/to-tf.js +7 -3
  168. package/dist-sdk/src/entities/field/build.d.ts +51 -24
  169. package/dist-sdk/src/entities/field/build.js +31 -6
  170. package/dist-sdk/src/entities/field/calc/aggregate.d.ts +52 -21
  171. package/dist-sdk/src/entities/field/calc/aggregate.js +59 -29
  172. package/dist-sdk/src/entities/field/calc/date.d.ts +78 -29
  173. package/dist-sdk/src/entities/field/calc/date.js +120 -29
  174. package/dist-sdk/src/entities/field/calc/index.d.ts +80 -85
  175. package/dist-sdk/src/entities/field/calc/index.js +82 -139
  176. package/dist-sdk/src/entities/field/calc/numeric.d.ts +8 -12
  177. package/dist-sdk/src/entities/field/calc/numeric.js +10 -27
  178. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -2
  179. package/dist-sdk/src/entities/field/calc/runtime.js +79 -8
  180. package/dist-sdk/src/entities/field/calc/text.d.ts +32 -23
  181. package/dist-sdk/src/entities/field/calc/text.js +43 -31
  182. package/dist-sdk/src/entities/field/calc/types.d.ts +36 -81
  183. package/dist-sdk/src/entities/field/calc/types.js +1 -22
  184. package/dist-sdk/src/entities/field/calc.d.ts +71 -48
  185. package/dist-sdk/src/entities/field/calc.js +5 -15
  186. package/dist-sdk/src/entities/field/calculation-types.js +10 -3
  187. package/dist-sdk/src/entities/field/from-tf.js +156 -10
  188. package/dist-sdk/src/entities/field/locals.d.ts +11 -3
  189. package/dist-sdk/src/entities/field/locals.js +15 -2
  190. package/dist-sdk/src/entities/field/module.js +23 -6
  191. package/dist-sdk/src/entities/field/record-shape.d.ts +24 -10
  192. package/dist-sdk/src/entities/field/to-tf.d.ts +40 -1
  193. package/dist-sdk/src/entities/field/to-tf.js +293 -35
  194. package/dist-sdk/src/entities/field/types.d.ts +1 -1
  195. package/dist-sdk/src/entities/field/types.js +7 -1
  196. package/dist-sdk/src/entities/file-reader/build.d.ts +5 -0
  197. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +1 -1
  198. package/dist-sdk/src/entities/org/cloud-link.js +4 -5
  199. package/dist-sdk/src/entities/org/email-alias.d.ts +2 -0
  200. package/dist-sdk/src/entities/org/email-alias.js +12 -0
  201. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  202. package/dist-sdk/src/entities/org/index.js +1 -0
  203. package/dist-sdk/src/entities/org/phone-provider.js +4 -7
  204. package/dist-sdk/src/entities/organization/build.d.ts +214 -2
  205. package/dist-sdk/src/entities/organization/build.js +145 -4
  206. package/dist-sdk/src/entities/organization/index.d.ts +1 -1
  207. package/dist-sdk/src/entities/organization/index.js +1 -1
  208. package/dist-sdk/src/entities/organization/module.js +4 -1
  209. package/dist-sdk/src/entities/organization/to-tf.d.ts +1 -0
  210. package/dist-sdk/src/entities/organization/to-tf.js +118 -1
  211. package/dist-sdk/src/entities/phone-service/build.d.ts +1 -1
  212. package/dist-sdk/src/entities/phone-service/build.js +2 -2
  213. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +5 -3
  214. package/dist-sdk/src/entities/phone-service/index.d.ts +1 -1
  215. package/dist-sdk/src/entities/phone-service/index.js +1 -1
  216. package/dist-sdk/src/entities/phone-service/types.js +1 -1
  217. package/dist-sdk/src/entities/record-create-form/to-tf.js +9 -1
  218. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  219. package/dist-sdk/src/entities/relationship/to-tf.js +5 -13
  220. package/dist-sdk/src/entities/search-table/build.d.ts +4 -4
  221. package/dist-sdk/src/entities/search-table/build.js +13 -13
  222. package/dist-sdk/src/entities/search-table/index.d.ts +2 -2
  223. package/dist-sdk/src/entities/search-table/index.js +2 -2
  224. package/dist-sdk/src/entities/search-table/printer.js +5 -5
  225. package/dist-sdk/src/entities/service-account/to-tf.d.ts +21 -0
  226. package/dist-sdk/src/entities/service-account/to-tf.js +32 -1
  227. package/dist-sdk/src/entities/shared/context.d.ts +25 -24
  228. package/dist-sdk/src/entities/shared/context.js +36 -35
  229. package/dist-sdk/src/entities/shared/filters/ast.d.ts +10 -3
  230. package/dist-sdk/src/entities/shared/filters/ast.js +1 -0
  231. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -1
  232. package/dist-sdk/src/entities/shared/filters/index.js +11 -4
  233. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +14 -0
  234. package/dist-sdk/src/entities/shared/foreign-ref.js +12 -0
  235. package/dist-sdk/src/entities/shared/ref.d.ts +26 -11
  236. package/dist-sdk/src/entities/shared/ref.js +8 -3
  237. package/dist-sdk/src/entities/shared/types/common.d.ts +2 -2
  238. package/dist-sdk/src/entities/shared/types/field-types.d.ts +1 -1
  239. package/dist-sdk/src/entities/shared/types/field-types.js +1 -1
  240. package/dist-sdk/src/entities/skill/build.d.ts +2 -2
  241. package/dist-sdk/src/entities/skill/build.js +3 -3
  242. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
  243. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +26 -7
  244. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  245. package/dist-sdk/src/entities/skill/index.js +1 -1
  246. package/dist-sdk/src/entities/skill/module.js +2 -2
  247. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  248. package/dist-sdk/src/entities/skill/to-tf.js +2 -2
  249. package/dist-sdk/src/entities/skill/tools.d.ts +4 -3
  250. package/dist-sdk/src/entities/skill/tools.js +4 -3
  251. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +13 -0
  252. package/dist-sdk/src/entities/skill-tool/from-tf.js +42 -0
  253. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -6
  254. package/dist-sdk/src/entities/table/build.d.ts +1 -1
  255. package/dist-sdk/src/entities/table/build.js +9 -9
  256. package/dist-sdk/src/entities/table/catalog-render.js +9 -1
  257. package/dist-sdk/src/entities/table/deserializer/normalize.js +4 -4
  258. package/dist-sdk/src/entities/table/fields/types.d.ts +1 -1
  259. package/dist-sdk/src/entities/table/fields/types.js +1 -1
  260. package/dist-sdk/src/entities/table/index.d.ts +2 -2
  261. package/dist-sdk/src/entities/table/index.js +3 -3
  262. package/dist-sdk/src/entities/table/module.js +1 -1
  263. package/dist-sdk/src/entities/table/to-tf.js +22 -30
  264. package/dist-sdk/src/entities/task/build.d.ts +1 -1
  265. package/dist-sdk/src/entities/task/build.js +5 -5
  266. package/dist-sdk/src/entities/task/index.d.ts +1 -1
  267. package/dist-sdk/src/entities/task/index.js +1 -1
  268. package/dist-sdk/src/entities/view/build.d.ts +46 -0
  269. package/dist-sdk/src/entities/view/build.js +19 -0
  270. package/dist-sdk/src/entities/view/from-tf.js +68 -18
  271. package/dist-sdk/src/entities/view/module.d.ts +6 -13
  272. package/dist-sdk/src/entities/view/module.js +7 -14
  273. package/dist-sdk/src/entities/view/sharing.d.ts +10 -0
  274. package/dist-sdk/src/entities/view/sharing.js +6 -0
  275. package/dist-sdk/src/entities/view/to-tf.d.ts +21 -19
  276. package/dist-sdk/src/entities/view/to-tf.js +61 -26
  277. package/dist-sdk/src/entities/view/types.js +3 -0
  278. package/dist-sdk/src/entities/visual-flow/build.d.ts +1 -1
  279. package/dist-sdk/src/entities/visual-flow/build.js +8 -8
  280. package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
  281. package/dist-sdk/src/entities/visual-flow/index.js +1 -1
  282. package/dist-sdk/src/entities/visual-flow/module.js +1 -1
  283. package/dist-sdk/src/entities/visual-flow/printer.js +3 -3
  284. package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +1 -0
  285. package/dist-sdk/src/entities/visual-flow/to-tf.js +3 -7
  286. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  287. package/dist-sdk/src/entities/widget/to-tf.js +9 -7
  288. package/dist-sdk/src/graph/index.d.ts +5 -1
  289. package/dist-sdk/src/graph/index.js +4 -1
  290. package/dist-sdk/src/graph/modules.js +6 -1
  291. package/dist-sdk/src/graph/types.d.ts +52 -1
  292. package/dist-sdk/src/internal/safe-identifier.d.ts +4 -0
  293. package/dist-sdk/src/internal/safe-identifier.js +13 -0
  294. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  295. package/dist-sdk/src/internal/sdk-package.js +1 -0
  296. package/package.json +12 -3
@@ -1,5 +1,5 @@
1
1
  /** The field entity's registry entry (see src/graph/). */
2
- import { rootParentFactoryEntry } from "../../catalog/render-helpers.js";
2
+ import { asNamedRef, namedFactoryEntry } from "../../catalog/render-helpers.js";
3
3
  import { NO_LIFECYCLE } from "../../graph/types.js";
4
4
  import { FIELD_SUB_TYPES } from "./types.js";
5
5
  export const FIELD_DATA_RESOURCE_TYPE = "elementum_field";
@@ -21,7 +21,16 @@ export const fieldModule = {
21
21
  },
22
22
  // Foreign relationship/relation fields are looked up by name under their
23
23
  // owning object (`object_id` is recorded by OrgRefLookup.foreignField).
24
- data: { participates: true, resourceType: FIELD_DATA_RESOURCE_TYPE, lookupAttr: "name", referencedByBuild: true },
24
+ data: {
25
+ participates: true,
26
+ resourceType: FIELD_DATA_RESOURCE_TYPE,
27
+ lookupAttr: "name",
28
+ referencedByBuild: true,
29
+ referenceLookups: [
30
+ { strategy: "owned", ownerKinds: ["app", "element"], memberAttr: "name" },
31
+ { strategy: "ownerProjection", ownerKind: "table", projectionAttr: "field_ids", memberAttr: "name" },
32
+ ],
33
+ },
25
34
  lifecycle: NO_LIFECYCLE,
26
35
  canvas: { participates: true, label: "Fields", glyph: "▾", component: "fieldCard" },
27
36
  // Inline under app — from-authoring still reads fields from app.ref(); this
@@ -32,15 +41,23 @@ export const fieldModule = {
32
41
  catalogBag: "fields",
33
42
  renderOrder: 50,
34
43
  catalogRoot: "app",
35
- renderEntry: rootParentFactoryEntry("fieldRef", (ref) => {
36
- const field = ref;
44
+ renderEntry: (args) => {
45
+ const named = asNamedRef(args.ref);
46
+ const field = args.ref;
37
47
  const parts = [`fieldType: ${JSON.stringify(field.fieldType)}`];
38
48
  if (field.tags !== undefined)
39
49
  parts.push(`tags: ${JSON.stringify(field.tags)}`);
40
50
  if (field.options !== undefined)
41
51
  parts.push(`options: ${JSON.stringify(field.options)}`);
42
- return parts;
43
- }),
52
+ return namedFactoryEntry({
53
+ factoryName: "fieldRef",
54
+ keyName: args.keyName,
55
+ baseIndent: args.baseIndent,
56
+ name: named.name,
57
+ parent: named.parent,
58
+ extraParts: parts,
59
+ });
60
+ },
44
61
  stubRef: (refName, parent) => ({
45
62
  __kind: "field",
46
63
  refName,
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Derives the typed shape of an app/element's records from its catalog
3
- * `fields` bag — what `ctx.trigger.record` / `ctx.tasks.<name>.record` expose
3
+ * `fields` bag — what `ctx.trigger.record` / `ctx.actions.<name>.record` expose
4
4
  * for record-bearing triggers and tasks (`recordCreated`, `recordSearch`,
5
5
  * `createRecord`, …).
6
6
  *
@@ -16,9 +16,12 @@
16
16
  * value typing consumed by automations, not stream/build orchestration.
17
17
  */
18
18
  import type { FieldRef } from "../../catalog/types.js";
19
+ import type { CalculationTypedValue } from "../shared/ref.js";
19
20
  import type { Attachment, Group, PicklistValue, RichText, User } from "../shared/types/platform.js";
20
21
  /** Map a platform field type literal to the TS type exposed on a record field. */
21
- export type FieldValueType<FieldType extends string> = FieldType extends "NUMBER" | "DECIMAL" ? number : FieldType extends "BOOLEAN" ? boolean : FieldType extends "JSON" | "OBJECT" ? unknown : FieldType extends "PICKLIST" | "PICKLIST_ID" ? PicklistValue : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? readonly PicklistValue[] : FieldType extends "ATTACHMENT" | "ATTACHMENT_ID" | "FILE" ? Attachment : FieldType extends "RICH_TEXT" ? RichText : FieldType extends "USER" | "USER_ID" ? User : FieldType extends "GROUP" | "GROUP_ID" ? Group : string;
22
+ type CalculationTypeForField<FieldType extends string> = FieldType extends "NUMBER" ? "number" : FieldType extends "DECIMAL" ? "decimal" : FieldType extends "BOOLEAN" ? "bool" : FieldType extends "DATE" ? "date" : FieldType extends "DATETIME" ? "datetime" : FieldType extends "PICKLIST" | "PICKLIST_ID" ? "picklist" : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? "multiPicklist" : FieldType extends "ATTACHMENT" | "ATTACHMENT_ID" | "FILE" ? "attachment" : FieldType extends "USER" | "USER_ID" ? "user" : FieldType extends "GROUP" | "GROUP_ID" ? "group" : FieldType extends "JSON" | "OBJECT" ? "json" : FieldType extends "HTML" ? "html" : FieldType extends "HANDLE" ? "handle" : FieldType extends "RICH_TEXT" ? "text" : "text";
23
+ type RawFieldValueType<FieldType extends string> = FieldType extends "NUMBER" | "DECIMAL" ? number : FieldType extends "BOOLEAN" ? boolean : FieldType extends "JSON" | "OBJECT" ? unknown : FieldType extends "PICKLIST" | "PICKLIST_ID" ? PicklistValue : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? readonly PicklistValue[] : FieldType extends "ATTACHMENT" | "ATTACHMENT_ID" | "FILE" ? Attachment : FieldType extends "RICH_TEXT" ? RichText : FieldType extends "USER" | "USER_ID" ? User : FieldType extends "GROUP" | "GROUP_ID" ? Group : string;
24
+ export type FieldValueType<FieldType extends string> = CalculationTypedValue<RawFieldValueType<FieldType>, CalculationTypeForField<FieldType>>;
22
25
  /**
23
26
  * Extract the `fields` bag off an app/element-like ref, e.g. `typeof catalog.myApp`.
24
27
  * `undefined` when the ref carries no `fields` bag (a hand-built `AppOrElementRef`
@@ -27,13 +30,20 @@ export type FieldValueType<FieldType extends string> = FieldType extends "NUMBER
27
30
  export type AppFieldsOf<A> = A extends {
28
31
  readonly fields: infer F extends Record<string, FieldRef>;
29
32
  } ? F : undefined;
33
+ declare const recordIdBrand: unique symbol;
34
+ /**
35
+ * Platform record identity (wire type ASPECT_RECORD_ID). Distinct from a
36
+ * record's TEXT `id` handle so `Ref<RecordId>` cannot be satisfied by
37
+ * `ctx.trigger.record.id` (`refs["ID"]`).
38
+ */
39
+ export type RecordId = string & {
40
+ readonly [recordIdBrand]: "recordId";
41
+ };
30
42
  /**
31
43
  * The typed record shape for an app/element ref. When `A` carries a concrete
32
44
  * `fields` bag (a real catalog app), this is a closed, per-field-typed object —
33
- * an unknown field name is a compile error. Otherwise (no `fields` bag known,
34
- * e.g. a caller that can't supply one, like `aiSearchTable`'s search-table
35
- * ref) it falls back to an open `Record<string, unknown>`, matching the
36
- * pre-existing loose behavior rather than forcing an unusable empty shape.
45
+ * an unknown field name is a compile error. Otherwise (no `fields` bag known)
46
+ * extra names are not indexed: a `string` index would poison {@link RecordId}.
37
47
  *
38
48
  * Every record also carries its own HANDLE/ID under two different synthetic
39
49
  * keys, matching two independent (and both intentional) wire conventions —
@@ -41,17 +51,21 @@ export type AppFieldsOf<A> = A extends {
41
51
  * - `id` — for a trigger-sourced record (`ctx.trigger.record.id`), per
42
52
  * `normalizeTriggerRefPath`'s `recordIdFieldClientHandle` → `"id"` case
43
53
  * in `automations/materialize/ref-deserializer.ts`.
44
- * - `recordId` — for a task-output record (`ctx.tasks.<t>.record.recordId`,
54
+ * - `recordId` — branded {@link RecordId} (ASPECT_RECORD_ID) for a
55
+ * task-output record (`ctx.actions.<t>.record.recordId`,
45
56
  * `recordSearch`/`createRecord`/`findRelatedRecords`), per
46
57
  * `rewriteForwardTaskRefName`'s `record.recordId` → wire `recordId`
47
58
  * collapse in `automations/build.ts` (and its inverse in
48
59
  * `ref-deserializer.ts`'s `buildTaskRef`).
49
60
  * `RecordShape` backs both trigger and task record accessors, so both keys
50
- * live here regardless of which context a given call site is in.
61
+ * live here regardless of which context a given call site is in. The brand
62
+ * on `recordId` is what lets `updateField.record` accept `.recordId` and
63
+ * reject TEXT `.id` (edk#295).
51
64
  */
52
65
  export type RecordShape<A> = {
53
66
  readonly id: string;
54
- readonly recordId: string;
67
+ readonly recordId: RecordId;
55
68
  } & (AppFieldsOf<A> extends Record<string, FieldRef> ? {
56
69
  readonly [K in keyof AppFieldsOf<A>]: FieldValueType<AppFieldsOf<A>[K]["fieldType"]>;
57
- } : Record<string, unknown>);
70
+ } : {});
71
+ export {};
@@ -17,6 +17,7 @@ interface AspectTokenWire {
17
17
  readonly __kind?: string;
18
18
  readonly refName?: string;
19
19
  readonly name?: string;
20
+ readonly namespace?: string;
20
21
  }
21
22
  /** Slim `FieldRef` token shape as it appears in a def() payload. */
22
23
  interface FieldTokenWire {
@@ -24,8 +25,46 @@ interface FieldTokenWire {
24
25
  readonly refName?: string;
25
26
  readonly name?: string;
26
27
  readonly parent?: string;
28
+ readonly parentNamespace?: string;
27
29
  readonly fieldType?: string;
28
30
  }
31
+ /**
32
+ * One entry of `sort.orders` in the shape actually observed live on a
33
+ * dynamic picklist (issue #433/#484) — `field` is a catalog token or raw
34
+ * platform id, same convention as `relatedLabelFieldId`; everything else
35
+ * (`direction`, `aggregation`, …) is opaque pass-through data.
36
+ */
37
+ interface DynamicPicklistSortOrderWire {
38
+ readonly field?: FieldTokenWire | string;
39
+ readonly [k: string]: unknown;
40
+ }
41
+ /**
42
+ * Slim `AppPicklistDynamicConfig` shape as it appears in a def() payload
43
+ * (post-`slimTokens`) — `relatedAspectId`/`relatedLabelFieldId`/
44
+ * `parentFieldId` are catalog tokens or raw platform ids, same convention as
45
+ * RELATION's `relatedObject`/`relatedLabelField`. `filter` is the `Filter`
46
+ * DSL's own wire shape (opaque here — `filterToTf` interprets it); `sort` is
47
+ * pass-through JSON EXCEPT for the one known `{ orders: [{ field, ... }] }`
48
+ * shape, whose `field` resolves like any other field token (issue #484 —
49
+ * a bare field name/id there can't survive a fresh deploy, and a mismatched
50
+ * platform shape trips the provider's post-apply consistency check).
51
+ */
52
+ interface DynamicPicklistConfigWire {
53
+ readonly relatedAspectId?: AspectTokenWire | string;
54
+ readonly relatedLabelFieldId?: FieldTokenWire | string;
55
+ readonly parentFieldId?: FieldTokenWire | string;
56
+ readonly autoRelate?: boolean;
57
+ readonly valuesRenderType?: string;
58
+ readonly filter?: unknown;
59
+ readonly sort?: {
60
+ readonly orders: readonly DynamicPicklistSortOrderWire[];
61
+ } | Record<string, unknown>;
62
+ }
63
+ /** Slim `AppPicklistConfig` shape — only `dynamic` round-trips through the terraform path (see fieldToTf's config handling). */
64
+ interface FieldConfigWire {
65
+ readonly dynamic?: DynamicPicklistConfigWire;
66
+ readonly static?: unknown;
67
+ }
29
68
  /** The authored field shape (post-`slimTokens` compose body). Deliberately loose — degrade, don't assert. */
30
69
  export interface FieldInnerWire {
31
70
  readonly name?: string;
@@ -39,7 +78,7 @@ export interface FieldInnerWire {
39
78
  readonly defaultValue?: unknown;
40
79
  readonly tags?: readonly string[];
41
80
  readonly picklistValues?: readonly PicklistValueWire[];
42
- readonly config?: unknown;
81
+ readonly config?: FieldConfigWire;
43
82
  readonly format?: unknown;
44
83
  readonly calculation?: unknown;
45
84
  /**
@@ -13,6 +13,7 @@ import { EntityTfError } from "../../engine/entity.js";
13
13
  import { workspaceAspectKey } from "../../engine/build/context.js";
14
14
  import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
15
15
  import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
16
+ import { filterToTf as filterWireToTfCodec } from "../shared/filters/tf-codec.js";
16
17
  import { picklistLabel } from "./options.js";
17
18
  import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
18
19
  /** `unknown` → the tagged org-field-ref shape, or undefined for anything else. */
@@ -21,6 +22,61 @@ function asOrgFieldRef(v) {
21
22
  return undefined;
22
23
  return v;
23
24
  }
25
+ /**
26
+ * True when `sort` is the one known `{ orders: [{ field, ... }] }` shape —
27
+ * a single `orders` key whose value is an array of objects each carrying a
28
+ * `field`. Anything else (including an empty/absent `orders`) is opaque data
29
+ * and passes through unresolved, same as before #484.
30
+ */
31
+ function isDynamicPicklistOrdersSort(sort) {
32
+ const keys = Object.keys(sort);
33
+ const orders = sort.orders;
34
+ return keys.length === 1 && keys[0] === "orders" && Array.isArray(orders) &&
35
+ orders.length > 0 && orders.every((o) => typeof o === "object" && o !== null && "field" in o);
36
+ }
37
+ /**
38
+ * Project the subset of the public numeric-format contract that the field
39
+ * resources own today. Unsupported properties are diagnosed individually so
40
+ * supported siblings still survive the build.
41
+ */
42
+ function numericFormatToTf(typeKey, format, attrs, diagnostics, name) {
43
+ if (typeof format !== "object" || format === null || Array.isArray(format)) {
44
+ diagnostics.push(`field "${name}": numericFormat must be an object; dropped`);
45
+ return;
46
+ }
47
+ for (const [key, value] of Object.entries(format)) {
48
+ if (value === undefined)
49
+ continue;
50
+ switch (key) {
51
+ case "currency":
52
+ if (typeof value === "string")
53
+ attrs["currency"] = value;
54
+ else
55
+ diagnostics.push(`field "${name}": numericFormat.currency must be a currency code string; dropped`);
56
+ break;
57
+ case "percentage":
58
+ case "delimiter":
59
+ if (typeof value === "boolean")
60
+ attrs[key] = value;
61
+ else
62
+ diagnostics.push(`field "${name}": numericFormat.${key} must be boolean; dropped`);
63
+ break;
64
+ case "decimalPlaces":
65
+ if (typeKey === "number") {
66
+ diagnostics.push(`field "${name}": numericFormat.decimalPlaces is not supported for NUMBER fields; dropped`);
67
+ }
68
+ else if (typeof value === "number" && Number.isInteger(value) && value >= 0) {
69
+ attrs["decimal_places"] = value;
70
+ }
71
+ else {
72
+ diagnostics.push(`field "${name}": numericFormat.decimalPlaces must be a non-negative integer; dropped`);
73
+ }
74
+ break;
75
+ default:
76
+ diagnostics.push(`field "${name}": numericFormat.${key} is not supported by the terraform field resources; dropped`);
77
+ }
78
+ }
79
+ }
24
80
  /**
25
81
  * `relatedObject` (RELATION fields only) → its `related_object_id` value. A
26
82
  * raw string passes through literally (unchanged, backward-compatible
@@ -37,8 +93,10 @@ function asOrgFieldRef(v) {
37
93
  * the ONE case that requires the target to already exist live.
38
94
  */
39
95
  function resolveRelatedObject(token, opts, where) {
40
- if (typeof token === "string")
96
+ if (typeof token === "string") {
97
+ opts.diagnostics.push(`${where}: raw UUID fallback ${JSON.stringify(token)} is source-org-only and non-portable`);
41
98
  return { value: token };
99
+ }
42
100
  const refName = token.refName ?? "";
43
101
  const kind = token.__kind === "element" ? "element" : "app";
44
102
  if (kind === (opts.scope ?? "app") && refName === opts.appRefName) {
@@ -58,59 +116,71 @@ function resolveRelatedObject(token, opts, where) {
58
116
  opts.diagnostics.push(`${where}: relatedObject references a foreign object but no org context is available; dropped`);
59
117
  return undefined;
60
118
  }
61
- const tfLabel = sanitizeName(name);
119
+ const tfLabel = sanitizeName(token.namespace ?? name);
62
120
  if (kind === "element") {
63
- opts.orgRefs.foreignElement(tfLabel, name);
121
+ opts.orgRefs.foreignElement(tfLabel, name, token.namespace);
122
+ if (token.namespace === undefined)
123
+ opts.diagnostics.push(`${where}: foreign element ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
64
124
  return { value: expr.dataAttr("elementum_element", tfLabel, ["id"]), refName, kind };
65
125
  }
66
- opts.orgRefs.foreignApp(tfLabel, name);
126
+ opts.orgRefs.foreignApp(tfLabel, name, token.namespace);
127
+ if (token.namespace === undefined)
128
+ opts.diagnostics.push(`${where}: foreign app ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
67
129
  return { value: expr.dataAttr("elementum_app", tfLabel, ["id"]), refName, kind };
68
130
  }
69
131
  /**
70
- * `relatedLabelField` (RELATION fields only) → its `related_label_field_id`
71
- * value. A raw string passes through literally. A `FieldRef` token resolves
72
- * via the shared field resolver (`fieldRefToTfValue`) when the (already-
73
- * resolved) `relatedObject` target is known — the owner itself or a
74
- * SIBLING stream root in this build, both real resources — a direct
75
- * resource reference either way; otherwise it's a genuinely foreign field,
76
- * resolved via a `data.elementum_field` lookup keyed by `object_id` (the
77
- * already-resolved `related_object_id` value, reused verbatim) + `name` —
78
- * the one case agent-tool/to-tf.ts's `fieldRefValue` explicitly declines
79
- * ("cross-app field refs are not supported... yet"). The lookup LABEL
80
- * includes the resolved object's kind (when known) — `elementum_field` is
81
- * one shared data-source type for app- and element-owned fields alike (see
82
- * the provider's `field_data_source.go`), so an app and an element sharing
83
- * a refName would otherwise both register the same label and silently
84
- * overwrite each other's `object_id` (`loadOrgRefs.record` dedupes by
85
- * `type.tfLabel`).
132
+ * A field token naming a field on an already-resolved target aspect →
133
+ * its terraform value. Shared by `relatedLabelField`, `parentFieldId`, and
134
+ * (as the `filterToTf` `field` codec callback) every field reference inside
135
+ * a dynamic picklist's `filter` — all three name a field belonging to the
136
+ * SAME already-resolved `object` (RELATION's `relatedObject`, or a dynamic
137
+ * picklist config's `relatedAspectId`), so one resolver covers all of them.
138
+ * `attrName` only changes the diagnostic wording.
139
+ *
140
+ * A raw string passes through literally. A `FieldRef` token resolves via the
141
+ * shared field resolver (`fieldRefToTfValue`) when the (already-resolved)
142
+ * target is known — the owner itself or a SIBLING stream root in this
143
+ * build, both real resources — a direct resource reference either way;
144
+ * otherwise it's a genuinely foreign field, resolved via a
145
+ * `data.elementum_field` lookup keyed by `object_id` (the already-resolved
146
+ * target's value, reused verbatim) + `name` — the one case agent-tool/
147
+ * to-tf.ts's `fieldRefValue` explicitly declines ("cross-app field refs are
148
+ * not supported... yet"). The lookup LABEL includes the resolved object's
149
+ * kind (when known) — `elementum_field` is one shared data-source type for
150
+ * app- and element-owned fields alike (see the provider's
151
+ * `field_data_source.go`), so an app and an element sharing a refName would
152
+ * otherwise both register the same label and silently overwrite each
153
+ * other's `object_id` (`loadOrgRefs.record` dedupes by `type.tfLabel`).
86
154
  */
87
- function resolveRelatedLabelField(token, object, opts, where) {
88
- if (typeof token === "string")
155
+ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLabelField") {
156
+ if (typeof token === "string") {
157
+ opts.diagnostics.push(`${where}: raw field UUID fallback ${JSON.stringify(token)} is source-org-only and non-portable`);
89
158
  return token;
159
+ }
90
160
  const refName = token.refName ?? "";
91
161
  if (refName === "") {
92
- opts.diagnostics.push(`${where}: relatedLabelField token has no refName; dropped`);
162
+ opts.diagnostics.push(`${where}: ${attrName} token has no refName; dropped`);
93
163
  return undefined;
94
164
  }
95
165
  if (object.refName !== undefined && token.parent !== undefined && token.parent !== object.refName) {
96
- opts.diagnostics.push(`${where}: relatedLabelField token "${refName}" belongs to "${token.parent}", not relatedObject's target "${object.refName}"; dropped`);
166
+ opts.diagnostics.push(`${where}: ${attrName} token "${refName}" belongs to "${token.parent}", not the resolved target "${object.refName}"; dropped`);
97
167
  return undefined;
98
168
  }
99
169
  if (object.target !== undefined) {
100
170
  // A field belongs to an app or element; a table exposes columns, not fields.
101
171
  // Guard rather than widen fieldRefToTfValue's scope parameter.
102
172
  if (object.target.kind === "table") {
103
- opts.diagnostics.push(`${where}: relatedLabelField token "${refName}" resolves to table "${object.target.tfLabel}" — tables expose columns, not fields; dropped`);
173
+ opts.diagnostics.push(`${where}: ${attrName} token "${refName}" resolves to table "${object.target.tfLabel}" — tables expose columns, not fields; dropped`);
104
174
  return undefined;
105
175
  }
106
176
  const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind);
107
177
  if (value === undefined) {
108
- opts.diagnostics.push(`${where}: relatedLabelField token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(token.fieldType ?? "")}); dropped`);
178
+ opts.diagnostics.push(`${where}: ${attrName} token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(token.fieldType ?? "")}); dropped`);
109
179
  }
110
180
  return value;
111
181
  }
112
182
  if (opts.orgRefs === undefined) {
113
- opts.diagnostics.push(`${where}: relatedLabelField references a foreign field but no org context is available; dropped`);
183
+ opts.diagnostics.push(`${where}: ${attrName} references a foreign field but no org context is available; dropped`);
114
184
  return undefined;
115
185
  }
116
186
  const name = token.name ?? refName;
@@ -119,21 +189,161 @@ function resolveRelatedLabelField(token, object, opts, where) {
119
189
  opts.orgRefs.foreignField("elementum_field", tfLabel, object.value, name);
120
190
  return expr.dataAttr("elementum_field", tfLabel, ["id"]);
121
191
  }
192
+ /**
193
+ * Wraps an `OrgRefLookup` so the `foreignApp`/`foreignElement`/`foreignField`
194
+ * data-block registrations it records are buffered instead of applied
195
+ * immediately, and only actually recorded against `real` when `commit()` is
196
+ * called. `buildDynamicPicklistConfigAttr` resolves a whole tree of tokens
197
+ * (relatedAspectId, relatedLabelFieldId, every field a compound filter
198
+ * names) before knowing whether the WHOLE config resolves — a field deep in
199
+ * an AND/OR filter can fail after earlier siblings already registered a
200
+ * `data.elementum_field` block, and dropping the field (as an unresolvable
201
+ * config must) should not leave that now-unreferenced block behind in
202
+ * `data.tf`. `byTsLabel`/`byName`/`foreignSkill`/`rawLookup` aren't reached
203
+ * by this resolution path, so they pass straight through.
204
+ */
205
+ function stageOrgRefs(real) {
206
+ const pending = [];
207
+ const orgRefs = {
208
+ resolveForeignRoot: (kind, identity) => {
209
+ const resolved = real.resolveForeignRoot(kind, identity, { record: false });
210
+ pending.push(() => { real.resolveForeignRoot(kind, identity); });
211
+ return resolved;
212
+ },
213
+ byTsLabel: (bag, tsLabel) => real.byTsLabel(bag, tsLabel),
214
+ byName: (bag, name) => real.byName(bag, name),
215
+ foreignSkill: (tfLabel, name, appId) => pending.push(() => real.foreignSkill(tfLabel, name, appId)),
216
+ rawLookup: (type, tfLabel, value, extraAttrs) => pending.push(() => real.rawLookup(type, tfLabel, value, extraAttrs)),
217
+ foreignApp: (tfLabel, name) => pending.push(() => real.foreignApp(tfLabel, name)),
218
+ foreignElement: (tfLabel, name) => pending.push(() => real.foreignElement(tfLabel, name)),
219
+ foreignField: (type, tfLabel, objectId, name) => pending.push(() => real.foreignField(type, tfLabel, objectId, name)),
220
+ };
221
+ return { orgRefs, commit: () => { for (const apply of pending)
222
+ apply(); } };
223
+ }
224
+ /**
225
+ * A dynamic picklist's `config.dynamic` → the `dynamic_config` attribute
226
+ * (picklist/multiPicklist sub-types only — see `hasOptions`). `relatedAspectId`
227
+ * resolves exactly like RELATION's `relatedObject` (`resolveRelatedObject`);
228
+ * `relatedLabelFieldId`/`parentFieldId`, and every field the `filter` tree
229
+ * references, resolve against that SAME resolved target via
230
+ * `resolveFieldOnObject` — a dynamic picklist's filter always filters the
231
+ * related aspect's own records, never the field's own owning app. `sort` has
232
+ * no DSL (mirrors the provider's own plain-JSON-string convention for it) —
233
+ * passed through as `jsonencode(...)`. Every foreign-object/foreign-field
234
+ * data-block registration triggered while resolving is staged (`stageOrgRefs`)
235
+ * and committed only once the ENTIRE config resolves — an early `undefined`
236
+ * return anywhere below leaves no orphaned `data.tf` block behind.
237
+ */
238
+ function buildDynamicPicklistConfigAttr(cfg, opts, where) {
239
+ if (cfg.relatedAspectId === undefined || cfg.relatedLabelFieldId === undefined) {
240
+ opts.diagnostics.push(`${where}: dynamic picklist config requires relatedAspectId and relatedLabelFieldId; dropped`);
241
+ return undefined;
242
+ }
243
+ const staged = opts.orgRefs === undefined ? undefined : stageOrgRefs(opts.orgRefs);
244
+ const opts_ = staged === undefined ? opts : { ...opts, orgRefs: staged.orgRefs };
245
+ const resolvedObject = resolveRelatedObject(cfg.relatedAspectId, opts_, where);
246
+ if (resolvedObject === undefined)
247
+ return undefined;
248
+ const relatedLabelFieldId = resolveFieldOnObject(cfg.relatedLabelFieldId, resolvedObject, opts_, where, "relatedLabelFieldId");
249
+ if (relatedLabelFieldId === undefined)
250
+ return undefined;
251
+ const attrs = {
252
+ related_aspect_id: resolvedObject.value,
253
+ related_label_field_id: relatedLabelFieldId,
254
+ };
255
+ if (cfg.parentFieldId !== undefined) {
256
+ // parentFieldId names a field on the OWNING aspect (the picklist
257
+ // field's own app/element) — a cascading-parent trigger, not a field
258
+ // on relatedAspectId's target. See `AppField.parentField`'s doc
259
+ // comment (the sibling STATIC mechanism this mirrors).
260
+ const owner = { value: opts.objectId, refName: opts.appRefName, kind: opts.scope ?? "app", target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel } };
261
+ const parentFieldId = resolveFieldOnObject(cfg.parentFieldId, owner, opts_, where, "parentFieldId");
262
+ if (parentFieldId === undefined)
263
+ return undefined;
264
+ attrs["parent_field_id"] = parentFieldId;
265
+ }
266
+ if (cfg.autoRelate !== undefined)
267
+ attrs["auto_relate"] = cfg.autoRelate;
268
+ if (cfg.valuesRenderType !== undefined)
269
+ attrs["values_render_type"] = cfg.valuesRenderType;
270
+ if (cfg.filter !== undefined) {
271
+ let unresolvedField = false;
272
+ try {
273
+ const filterValue = filterWireToTfCodec(cfg.filter, {
274
+ field: (token) => {
275
+ const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
276
+ if (value === undefined) {
277
+ // resolveFieldOnObject already pushed a diagnostic — this
278
+ // placeholder only satisfies the codec's TfValue return type
279
+ // long enough to unwind via the unresolvedField check below.
280
+ unresolvedField = true;
281
+ return "";
282
+ }
283
+ return value;
284
+ },
285
+ reference: () => {
286
+ throw new EntityTfError(`${where}: dynamic picklist filter does not support value references`);
287
+ },
288
+ });
289
+ if (unresolvedField)
290
+ return undefined;
291
+ attrs["filter"] = filterValue;
292
+ }
293
+ catch (e) {
294
+ opts.diagnostics.push(`${where}: filter ${e instanceof Error ? e.message : String(e)}; dropped`);
295
+ return undefined;
296
+ }
297
+ }
298
+ if (cfg.sort !== undefined) {
299
+ if (isDynamicPicklistOrdersSort(cfg.sort)) {
300
+ const orders = [];
301
+ for (const order of cfg.sort.orders) {
302
+ const { field, ...rest } = order;
303
+ if (field === undefined) {
304
+ opts.diagnostics.push(`${where}: sort order has no field; dropped`);
305
+ return undefined;
306
+ }
307
+ const fieldValue = resolveFieldOnObject(field, resolvedObject, opts_, where, "sort field");
308
+ if (fieldValue === undefined)
309
+ return undefined;
310
+ // The platform always echoes `aggregation` back on Read (defaulting
311
+ // to null when unset) — send it explicitly so a plan that omitted
312
+ // it doesn't mismatch that Read on apply's post-apply consistency
313
+ // check (issue #484, round two: the field-id fix alone still left
314
+ // planned `{direction,field}` vs. read-back `{aggregation,direction,field}`).
315
+ const aggregation = "aggregation" in rest ? rest["aggregation"] : null;
316
+ orders.push({ ...rest, aggregation: aggregation, field: fieldValue });
317
+ }
318
+ attrs["sort"] = expr.jsonencode({ orders });
319
+ }
320
+ else {
321
+ attrs["sort"] = expr.jsonencode(cfg.sort);
322
+ }
323
+ }
324
+ staged?.commit();
325
+ return attrs;
326
+ }
122
327
  /** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
123
328
  export function fieldToTf(typeKey, inner, opts) {
124
329
  const { ownerTfLabel, scope = "app", objectId, diagnostics } = opts;
125
330
  const name = inner.name ?? "";
126
- if (inner.config !== undefined) {
127
- diagnostics.push(`field "${name}": dependent/dynamic picklist config is not supported by the terraform provider yet; dropped`);
128
- return undefined;
129
- }
130
331
  const subType = SUB_TYPE_BY_TYPE_KEY.get(typeKey);
131
332
  if (subType === undefined) {
132
333
  diagnostics.push(`field "${name}": field type key "${typeKey}" has no terraform field resource mapping; dropped`);
133
334
  return undefined;
134
335
  }
135
- if (inner.format !== undefined) {
136
- diagnostics.push(`field "${name}": numeric/QR format is not supported on the terraform path yet; dropped`);
336
+ if (inner.config !== undefined && (subType.hasOptions !== true || inner.config.dynamic === undefined)) {
337
+ // Only `hasOptions` fields with a `dynamic` config are supported. That
338
+ // excludes non-picklist fields, `config.static`, and any other
339
+ // unmodeled config shape (e.g. an `api`/`stage` variant) — all three
340
+ // must degrade here, not fall through as if config were absent.
341
+ diagnostics.push(`field "${name}": ${subType.hasOptions === true ? "static/dependent" : "dependent/dynamic"} picklist config is not supported by the terraform provider yet; dropped`);
342
+ return undefined;
343
+ }
344
+ if (subType.hasOptions === true && inner.config?.dynamic !== undefined && inner.picklistValues !== undefined && inner.picklistValues.length > 0) {
345
+ diagnostics.push(`field "${name}": config.dynamic and options are mutually exclusive; dropped`);
346
+ return undefined;
137
347
  }
138
348
  const bagKey = inner.__refName ?? snakeSlug(name);
139
349
  // The bag key IS the field's terraform label (via the bijection — the
@@ -147,8 +357,16 @@ export function fieldToTf(typeKey, inner, opts) {
147
357
  object_id: objectId,
148
358
  name,
149
359
  };
360
+ if (inner.format !== undefined) {
361
+ if (typeKey === "number" || typeKey === "decimal") {
362
+ numericFormatToTf(typeKey, inner.format, attrs, diagnostics, name);
363
+ }
364
+ else {
365
+ diagnostics.push(`field "${name}": QR format is not supported on the terraform path yet; dropped`);
366
+ }
367
+ }
150
368
  // Always emitted, mirroring ei's exporter (hcl_app.go): these four are
151
- // Optional+Computed with NO schema Default in the frozen provider, so an
369
+ // Optional+Computed with NO schema Default in the provider, so an
152
370
  // omitted attr plans as unknown instead of preserving the stored false.
153
371
  // Authoring keeps them optional — absent means false.
154
372
  attrs["required"] = inner.required ?? false;
@@ -165,6 +383,36 @@ export function fieldToTf(typeKey, inner, opts) {
165
383
  return undefined;
166
384
  }
167
385
  attrs["calculation"] = calculation.text;
386
+ const includeTypes = calculation.includeTypes;
387
+ if (Array.isArray(includeTypes)) {
388
+ let hasAuto = false;
389
+ let hasManual = false;
390
+ for (const entry of includeTypes) {
391
+ if (typeof entry !== "object" || entry === null)
392
+ continue;
393
+ const include = entry;
394
+ if (include.auto !== undefined)
395
+ hasAuto = true;
396
+ if (include.manual !== undefined)
397
+ hasManual = true;
398
+ if (typeof include.picklist === "object" && include.picklist !== null) {
399
+ const field = include.picklist.picklistFieldId;
400
+ if (field?.refName !== undefined) {
401
+ const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope);
402
+ if (value !== undefined) {
403
+ attrs["include_type"] = "PICKLIST";
404
+ attrs["picklist_field_id"] = value;
405
+ }
406
+ }
407
+ }
408
+ }
409
+ if (attrs["include_type"] !== "PICKLIST") {
410
+ if (hasAuto && hasManual)
411
+ attrs["include_type"] = "BOTH";
412
+ else if (hasManual)
413
+ attrs["include_type"] = "MANUAL";
414
+ }
415
+ }
168
416
  }
169
417
  if (inner.description !== undefined)
170
418
  attrs["description"] = inner.description;
@@ -198,6 +446,9 @@ export function fieldToTf(typeKey, inner, opts) {
198
446
  attrs["field_role"] = [...inner.tags];
199
447
  }
200
448
  if (typeKey === "decimal" && inner.decimalPlaces !== undefined) {
449
+ if (attrs["decimal_places"] !== undefined && attrs["decimal_places"] !== inner.decimalPlaces) {
450
+ diagnostics.push(`field "${name}": decimalPlaces conflicts with numericFormat.decimalPlaces; decimalPlaces wins`);
451
+ }
201
452
  attrs["decimal_places"] = inner.decimalPlaces;
202
453
  }
203
454
  if (subType.hasRelation === true) {
@@ -209,7 +460,7 @@ export function fieldToTf(typeKey, inner, opts) {
209
460
  const resolvedObject = resolveRelatedObject(inner.relatedObject, opts, where);
210
461
  if (resolvedObject === undefined)
211
462
  return undefined;
212
- const relatedLabelFieldId = resolveRelatedLabelField(inner.relatedLabelField, resolvedObject, opts, where);
463
+ const relatedLabelFieldId = resolveFieldOnObject(inner.relatedLabelField, resolvedObject, opts, where);
213
464
  if (relatedLabelFieldId === undefined)
214
465
  return undefined;
215
466
  const relatedObjectId = resolvedObject.value;
@@ -218,6 +469,13 @@ export function fieldToTf(typeKey, inner, opts) {
218
469
  if (inner.autoRelate !== undefined)
219
470
  attrs["auto_relate"] = inner.autoRelate;
220
471
  }
472
+ if (subType.hasOptions === true && inner.config?.dynamic !== undefined) {
473
+ const where = `field "${name}"`;
474
+ const dynamicConfig = buildDynamicPicklistConfigAttr(inner.config.dynamic, opts, where);
475
+ if (dynamicConfig === undefined)
476
+ return undefined;
477
+ attrs["dynamic_config"] = dynamicConfig;
478
+ }
221
479
  if (subType.hasOptions === true && inner.picklistValues !== undefined) {
222
480
  if (inner.picklistValues.some((pv) => pv.relatedParentValues !== undefined)) {
223
481
  diagnostics.push(`field "${name}": dependent option links (parentValues) are not supported by the terraform provider yet; dropped`);
@@ -28,7 +28,7 @@ export interface FieldSubType {
28
28
  readonly typeKey: string;
29
29
  /** Terraform resource type ("elementum_longtext_field"). */
30
30
  readonly resourceType: string;
31
- /** Canonical authoring field type on the normalized shape ("HTML"). */
31
+ /** Canonical authoring field type on the normalized shape ("RICH_TEXT"). */
32
32
  readonly authoringType: string;
33
33
  /** Carries an `options` attribute (the picklist kinds). */
34
34
  readonly hasOptions?: true;