@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,32 +1,22 @@
1
1
  /**
2
2
  * Public surface of the calculated-field DSL — the `calc` namespace.
3
3
  *
4
- * v1 minimal scope:
5
- * - Arithmetic operators: plus, minus, times, dividedBy
6
- * - Comparison operators: gt, lt, gte, lte, eq, ne
7
- * - Logical operators: and, or, not
8
- * - Conditional: if
9
- * - Literals: num, dec, text, bool (mostly disambiguation helpers —
10
- * coercion handles the common case automatically)
11
- * - Sub-select projections: label, id, email, name
12
- *
13
- * Out of scope for v1 (lands in PR 3+ per the agreed scoping):
14
- * - IFS, COALESCE, NULLIF, ISBLANK, BLANK
15
- * - Aggregations (SUM, COUNT, AVG, MIN, MAX, …)
16
- * - Date functions (NOW, DATEDIF, YEAR, …)
17
- * - Text functions (CONCAT, LEN, UPPER, …)
18
- * - Regex, JSON, manifest-driven tier-2 functions
19
- * - Parameters ({{trigger}}, {{task}}), UDFs
4
+ * Covers the public Knowhere calculated-expression grammar: arithmetic and
5
+ * comparisons; logical/conditional functions; aggregate functions; date,
6
+ * text, regex, JSON, and numeric functions; literals; and field projections.
7
+ * Automation workflow parameters layer on in
8
+ * `automation/calculation-expression.ts` because they are not calculated-field
9
+ * concepts.
20
10
  *
21
11
  * Operator naming: `plus` / `minus` / `times` / `dividedBy` instead of
22
12
  * `add` / `subtract` / `multiply` / `divide` so the resulting code
23
13
  * reads close to the math expression. Same shape as the Java
24
14
  * `ExpressionUtil.addition` / `subtraction` / etc. helpers.
25
15
  */
26
- import { coerce, makeExpr } from "./runtime.js";
27
- import { concat, toText, len, trim, upper, lower, left, right, mid, substitute, find, search, splitText, regexMatch, regexReplace, regexExtract, jsonEscape, jsonUnescape, } from "./text.js";
28
- import { round, power, sqrt, mod, abs, toNumber, uuid, } from "./numeric.js";
29
- import { now, today, makeDate, dateValue, dateDif, dateTimeTrunc, weekday, year, month, day, hour, minute, second, } from "./date.js";
16
+ import { coerce, makeComposedExpr, makeExpr } from "./runtime.js";
17
+ import { concat, toText, len, trim, upper, lower, left, right, mid, substitute, find, search, split, splitText, regexMatch, regexReplace, regexExtract, jsonEscape, jsonUnescape, repeat, } from "./text.js";
18
+ import { round, power, sqrt, toNumber, uuid } from "./numeric.js";
19
+ import { now, makeDate, dateTime, dateValue, dateDiff, dateDif, truncateDateTime, dateTimeTrunc, weekday, year, month, day, hour, minute, second, } from "./date.js";
30
20
  import { countIf, sumIf, stringAgg, stringAggUnique, } from "./aggregate.js";
31
21
  // ---------------------------------------------------------------------------
32
22
  // Aggregations
@@ -71,13 +61,30 @@ function text(value) {
71
61
  function bool(value) {
72
62
  return coerce(value);
73
63
  }
64
+ // ---------------------------------------------------------------------------
65
+ // Arithmetic
66
+ // ---------------------------------------------------------------------------
67
+ // Arithmetic statically follows Knowhere's promotion rules: integer-only
68
+ // operations stay NUMBER, any DECIMAL operand promotes to DECIMAL, and
69
+ // division always yields DECIMAL. The server remains authoritative and
70
+ // validates the inferred type at compose time.
71
+ // plus and minus are overloaded for date/datetime arithmetic:
72
+ // - date + numeric → date (e.g. "Due Date" + 5 → 5 days later)
73
+ // - datetime + numeric → datetime
74
+ // - numeric + numeric → numeric (default arithmetic)
75
+ //
76
+ // DATE plus a decimal promotes to DATETIME because fractional days do not fit
77
+ // in a DATE; DATE plus a NUMBER remains DATE. DATETIME remains DATETIME.
78
+ //
79
+ // times and dividedBy stay numeric-only — date * number and
80
+ // date / number aren't valid in the calc grammar.
74
81
  function plus(a, b) {
75
82
  const ae = coerce(a);
76
83
  const be = coerce(b);
77
84
  const brand = ae.__exprType === "date" ? "date" :
78
85
  ae.__exprType === "datetime" ? "datetime" :
79
86
  "decimal";
80
- return makeExpr(brand, () => `(${ae.toCalcString()} + ${be.toCalcString()})`);
87
+ return makeComposedExpr(brand, [ae, be], () => `(${ae.toCalcString()} + ${be.toCalcString()})`);
81
88
  }
82
89
  function minus(a, b) {
83
90
  const ae = coerce(a);
@@ -85,118 +92,74 @@ function minus(a, b) {
85
92
  const brand = ae.__exprType === "date" ? "date" :
86
93
  ae.__exprType === "datetime" ? "datetime" :
87
94
  "decimal";
88
- return makeExpr(brand, () => `(${ae.toCalcString()} - ${be.toCalcString()})`);
95
+ return makeComposedExpr(brand, [ae, be], () => `(${ae.toCalcString()} - ${be.toCalcString()})`);
89
96
  }
90
97
  function times(a, b) {
91
98
  const ae = coerce(a);
92
99
  const be = coerce(b);
93
- return makeExpr("decimal", () => `(${ae.toCalcString()} * ${be.toCalcString()})`);
100
+ const type = ae.__exprType === "decimal" || be.__exprType === "decimal" ? "decimal" : "number";
101
+ return makeComposedExpr(type, [ae, be], () => `(${ae.toCalcString()} * ${be.toCalcString()})`);
94
102
  }
95
103
  function dividedBy(a, b) {
96
104
  const ae = coerce(a);
97
105
  const be = coerce(b);
98
- return makeExpr("decimal", () => `(${ae.toCalcString()} / ${be.toCalcString()})`);
106
+ return makeComposedExpr("decimal", [ae, be], () => `(${ae.toCalcString()} / ${be.toCalcString()})`);
99
107
  }
100
- // ---------------------------------------------------------------------------
101
- // Comparison
102
- // ---------------------------------------------------------------------------
103
- // `gt` / `lt` / `gte` / `lte` are restricted to ComparableExprType
104
- // (number, decimal, text, date, datetime). `eq` / `ne` widen to any
105
- // `ExprType` so authors can compare booleans, picklist ids, user ids,
106
- // etc. — anything assignable from one side is assignable from the other.
107
- //
108
- // Wire format: comparison expressions are emitted BARE — no
109
- // surrounding parens. The ANTLR grammar's "expression" production
110
- // covers arithmetic / column refs / literals but NOT comparisons; a
111
- // comparison is a "boolean expression," a separate production. So
112
- // `(a > b)` fails to parse — the parser sees `(` and expects an
113
- // expression, then chokes on `>`. Authors compose comparisons with
114
- // `and` / `or` / `not` / `if` etc., never inside parens.
115
108
  function gt(a, b) {
116
109
  const ae = coerce(a);
117
110
  const be = coerce(b);
118
- return makeExpr("bool", () => `${ae.toCalcString()} > ${be.toCalcString()}`);
111
+ return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} > ${be.toCalcString()}`);
119
112
  }
120
113
  function lt(a, b) {
121
114
  const ae = coerce(a);
122
115
  const be = coerce(b);
123
- return makeExpr("bool", () => `${ae.toCalcString()} < ${be.toCalcString()}`);
116
+ return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} < ${be.toCalcString()}`);
124
117
  }
125
118
  function gte(a, b) {
126
119
  const ae = coerce(a);
127
120
  const be = coerce(b);
128
- return makeExpr("bool", () => `${ae.toCalcString()} >= ${be.toCalcString()}`);
121
+ return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} >= ${be.toCalcString()}`);
129
122
  }
130
123
  function lte(a, b) {
131
124
  const ae = coerce(a);
132
125
  const be = coerce(b);
133
- return makeExpr("bool", () => `${ae.toCalcString()} <= ${be.toCalcString()}`);
126
+ return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} <= ${be.toCalcString()}`);
134
127
  }
135
128
  function eq(a, b) {
136
129
  const ae = coerce(a);
137
130
  const be = coerce(b);
138
- return makeExpr("bool", () => `${ae.toCalcString()} = ${be.toCalcString()}`);
131
+ return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} = ${be.toCalcString()}`);
139
132
  }
140
133
  function ne(a, b) {
141
134
  const ae = coerce(a);
142
135
  const be = coerce(b);
143
- return makeExpr("bool", () => `${ae.toCalcString()} <> ${be.toCalcString()}`);
136
+ return makeComposedExpr("bool", [ae, be], () => `${ae.toCalcString()} <> ${be.toCalcString()}`);
144
137
  }
145
138
  // ---------------------------------------------------------------------------
146
139
  // Logical
147
140
  // ---------------------------------------------------------------------------
148
141
  function and(a, b, ...rest) {
149
142
  const all = [a, b, ...rest].map((v) => coerce(v));
150
- return makeExpr("bool", () => `AND(${all.map((e) => e.toCalcString()).join(", ")})`);
143
+ return makeComposedExpr("bool", all, () => `AND(${all.map((e) => e.toCalcString()).join(", ")})`);
151
144
  }
152
145
  function or(a, b, ...rest) {
153
146
  const all = [a, b, ...rest].map((v) => coerce(v));
154
- return makeExpr("bool", () => `OR(${all.map((e) => e.toCalcString()).join(", ")})`);
155
- }
156
- function not(value) {
157
- const e = coerce(value);
158
- return makeExpr("bool", () => `NOT(${e.toCalcString()})`);
147
+ return makeComposedExpr("bool", all, () => `OR(${all.map((e) => e.toCalcString()).join(", ")})`);
159
148
  }
160
- // ---------------------------------------------------------------------------
161
- // Conditional
162
- // ---------------------------------------------------------------------------
163
- // `if(cond, then, else)` — both arms must produce the same brand, so
164
- // the generic infers from the wider of the two arms. The output
165
- // inherits the arms' brand.
166
149
  function if_(cond, thenArm, elseArm) {
167
150
  const c = coerce(cond);
168
151
  const t = coerce(thenArm);
169
152
  const e = coerce(elseArm);
170
- return makeExpr(t.__exprType, () => `IF(${c.toCalcString()}, ${t.toCalcString()}, ${e.toCalcString()})`);
153
+ return makeComposedExpr(t.__exprType, [c, t, e], () => `IF(${c.toCalcString()}, ${t.toCalcString()}, ${e.toCalcString()})`);
171
154
  }
172
- /**
173
- * Multi-branch conditional — `IFS(c1, v1, c2, v2, …, finalElse?)`.
174
- * Conditions are evaluated in order; the first one whose check
175
- * passes determines the result. If no condition matches and no
176
- * final-else value is supplied, the result is null (BLANK on the
177
- * wire).
178
- *
179
- * Args must come in (cond, value) pairs, optionally with one
180
- * trailing value as the final else. The typing accepts the pairs
181
- * as `[BoolLike, ExprLike<T>]` tuples plus an optional final
182
- * `ExprLike<T>` so all branches share the same result brand.
183
- *
184
- * Runtime validates parity — the EDK throws if an odd-then-even-
185
- * looking arg list slips past TS (e.g. when args is spread from an
186
- * untyped source).
187
- */
188
155
  function ifs(...args) {
189
- if (args.length === 0) {
190
- throw new Error("calc.ifs: at least one condition/value pair is required.");
156
+ if (args.length < 2 || args.length % 2 !== 0) {
157
+ throw new Error("calc.ifs: condition/value arguments must be complete pairs.");
191
158
  }
192
- // The first arg is always a condition; pairs alternate from there.
193
- // A trailing odd-positioned arg (after at least one full pair) is
194
- // the final else. Validate the shape so a malformed call surfaces
195
- // early instead of producing nonsense wire text.
196
159
  const branches = [];
197
160
  let inferredBrand = undefined;
198
161
  for (let i = 0; i < args.length; i++) {
199
- const expectBool = i % 2 === 0 && i < args.length - 1;
162
+ const expectBool = i % 2 === 0;
200
163
  if (expectBool) {
201
164
  branches.push(coerce(args[i]));
202
165
  }
@@ -210,28 +173,7 @@ function ifs(...args) {
210
173
  if (inferredBrand == null) {
211
174
  throw new Error("calc.ifs: at least one value arm is required.");
212
175
  }
213
- return makeExpr(inferredBrand, () => `IFS(${branches.map((e) => e.toCalcString()).join(", ")})`);
214
- }
215
- /**
216
- * Return the first non-null argument. All args must share the same
217
- * result brand. The wire emits `COALESCE(a, b, …)`.
218
- */
219
- function coalesce(...args) {
220
- if (args.length < 2) {
221
- throw new Error("calc.coalesce: at least two arguments are required.");
222
- }
223
- const exprs = args.map((a) => coerce(a));
224
- return makeExpr(exprs[0].__exprType, () => `COALESCE(${exprs.map((e) => e.toCalcString()).join(", ")})`);
225
- }
226
- /**
227
- * Return null when `a` and `b` are equal; otherwise return `a`.
228
- * Mirrors SQL `NULLIF`. Useful for guarding against divide-by-zero:
229
- * `calc.dividedBy(x, calc.nullIf(y, 0))`.
230
- */
231
- function nullIf(a, b) {
232
- const ae = coerce(a);
233
- const be = coerce(b);
234
- return makeExpr(ae.__exprType, () => `NULLIF(${ae.toCalcString()}, ${be.toCalcString()})`);
176
+ return makeComposedExpr(inferredBrand, branches, () => `IFS(${branches.map((e) => e.toCalcString()).join(", ")})`);
235
177
  }
236
178
  /**
237
179
  * True when the argument is null/empty. Accepts any expression type.
@@ -240,35 +182,33 @@ function nullIf(a, b) {
240
182
  */
241
183
  function isBlank(value) {
242
184
  const e = coerce(value);
243
- return makeExpr("bool", () => `ISBLANK(${e.toCalcString()})`);
185
+ return makeComposedExpr("bool", [e], () => `ISBLANK(${e.toCalcString()})`);
244
186
  }
245
- /**
246
- * Null literal — the wire `BLANK()` function. Returns an `Expr<T>`
247
- * whose brand is inferred from surrounding context (e.g. an
248
- * `if`/`ifs` arm). Standalone use requires an explicit type argument
249
- * (`calc.blank<"text">()`) because TS can't infer T from a
250
- * zero-argument call site.
251
- */
252
- function blank() {
187
+ function blank(_type) {
253
188
  // Brand carried as a generic; the runtime doesn't know which type
254
189
  // the call site expects. The wire string is the same in every
255
190
  // context — server resolves the actual type at parse time based on
256
191
  // surrounding expressions.
257
192
  return makeExpr("text", () => "BLANK()");
258
193
  }
259
- // ---------------------------------------------------------------------------
260
- // Aggregation builders
261
- // ---------------------------------------------------------------------------
262
- /**
263
- * Sum of a numeric expression across related rows. Server preserves
264
- * the input brand — `sum(NUMBER)` → NUMBER on the wire,
265
- * `sum(DECIMAL)` → DECIMAL. The DSL collapses the output to
266
- * `NumericExpr` (the number-or-decimal union) since the caller's
267
- * downstream usage typically doesn't distinguish.
268
- */
194
+ /** Explicitly typed escape hatch for pulled and legacy formula text. */
195
+ function raw(formula, resultType) {
196
+ // Raw text is the deliberately unsafe boundary: its field/context needs are
197
+ // opaque to TypeScript and remain subject to Ultron validation at build.
198
+ return makeExpr(resultType, () => formula);
199
+ }
200
+ /** Invoke a configured scalar user-defined function from its CloudLink catalog ref. */
201
+ function call(udf, ...args) {
202
+ const expressions = args.map((arg) => coerce(arg));
203
+ if (expressions.length !== udf.parameterTypes.length) {
204
+ throw new Error(`calc.call: ${udf.name} expects ${udf.parameterTypes.length} arguments, received ${expressions.length}.`);
205
+ }
206
+ const name = udf.name.replace(/"/g, '""');
207
+ return makeExpr(udf.resultType, () => `Function."${name}"(${expressions.map((expression) => expression.toCalcString()).join(", ")})`, { context: "record" });
208
+ }
269
209
  function sum(value) {
270
210
  const e = coerce(value);
271
- return makeExpr("decimal", () => `SUM(${e.toCalcString()})`);
211
+ return makeComposedExpr(e.__exprType, [e], () => `SUM(${e.toCalcString()})`);
272
212
  }
273
213
  /**
274
214
  * Count of non-null values for the argument expression across related
@@ -276,7 +216,7 @@ function sum(value) {
276
216
  */
277
217
  function count(value) {
278
218
  const e = coerce(value);
279
- return makeExpr("number", () => `COUNT(${e.toCalcString()})`);
219
+ return makeComposedExpr("number", [e], () => `COUNT(${e.toCalcString()})`);
280
220
  }
281
221
  /**
282
222
  * Distinct count of the argument expression across related rows.
@@ -285,7 +225,7 @@ function count(value) {
285
225
  */
286
226
  function countUnique(value) {
287
227
  const e = coerce(value);
288
- return makeExpr("number", () => `COUNTUNIQUE(${e.toCalcString()})`);
228
+ return makeComposedExpr("number", [e], () => `COUNTUNIQUE(${e.toCalcString()})`);
289
229
  }
290
230
  /**
291
231
  * Arithmetic mean of a numeric expression across related rows.
@@ -294,7 +234,7 @@ function countUnique(value) {
294
234
  */
295
235
  function average(value) {
296
236
  const e = coerce(value);
297
- return makeExpr("decimal", () => `AVERAGE(${e.toCalcString()})`);
237
+ return makeComposedExpr("decimal", [e], () => `AVERAGE(${e.toCalcString()})`);
298
238
  }
299
239
  /**
300
240
  * Standard deviation of a numeric expression across related rows.
@@ -302,21 +242,21 @@ function average(value) {
302
242
  */
303
243
  function stdev(value) {
304
244
  const e = coerce(value);
305
- return makeExpr("decimal", () => `STDEV(${e.toCalcString()})`);
245
+ return makeComposedExpr("decimal", [e], () => `STDEV(${e.toCalcString()})`);
306
246
  }
307
247
  function min(...args) {
308
248
  if (args.length === 0) {
309
249
  throw new Error("calc.min: at least one argument is required.");
310
250
  }
311
251
  const exprs = args.map((a) => coerce(a));
312
- return makeExpr(exprs[0].__exprType, () => `MIN(${exprs.map((e) => e.toCalcString()).join(", ")})`);
252
+ return makeComposedExpr(exprs[0].__exprType, exprs, () => `MIN(${exprs.map((e) => e.toCalcString()).join(", ")})`);
313
253
  }
314
254
  function max(...args) {
315
255
  if (args.length === 0) {
316
256
  throw new Error("calc.max: at least one argument is required.");
317
257
  }
318
258
  const exprs = args.map((a) => coerce(a));
319
- return makeExpr(exprs[0].__exprType, () => `MAX(${exprs.map((e) => e.toCalcString()).join(", ")})`);
259
+ return makeComposedExpr(exprs[0].__exprType, exprs, () => `MAX(${exprs.map((e) => e.toCalcString()).join(", ")})`);
320
260
  }
321
261
  // ---------------------------------------------------------------------------
322
262
  // Sub-select projections
@@ -327,22 +267,22 @@ function max(...args) {
327
267
  /** Project a picklist field reference to its display label (text). */
328
268
  function label(field) {
329
269
  const e = coerce(field);
330
- return makeExpr("text", () => `${e.toCalcString()}.LABEL`);
270
+ return makeComposedExpr("text", [e], () => `${e.toCalcString()}.LABEL`);
331
271
  }
332
272
  /** Project a reference-typed field to its id form (no-op for already-id refs). */
333
273
  function id(field) {
334
274
  const e = coerce(field);
335
- return makeExpr(e.__exprType, () => `${e.toCalcString()}.ID`);
275
+ return makeComposedExpr(e.__exprType, [e], () => `${e.toCalcString()}.ID`);
336
276
  }
337
277
  /** Project a user field reference to its email address (text). */
338
278
  function email(field) {
339
279
  const e = coerce(field);
340
- return makeExpr("text", () => `${e.toCalcString()}.EMAIL`);
280
+ return makeComposedExpr("text", [e], () => `${e.toCalcString()}.EMAIL`);
341
281
  }
342
282
  /** Project a group field reference to its name (text). */
343
283
  function name(field) {
344
284
  const e = coerce(field);
345
- return makeExpr("text", () => `${e.toCalcString()}.NAME`);
285
+ return makeComposedExpr("text", [e], () => `${e.toCalcString()}.NAME`);
346
286
  }
347
287
  // ---------------------------------------------------------------------------
348
288
  // Public namespace
@@ -359,6 +299,8 @@ export const calc = {
359
299
  text,
360
300
  bool,
361
301
  blank,
302
+ raw,
303
+ call,
362
304
  plus,
363
305
  minus,
364
306
  times,
@@ -371,11 +313,8 @@ export const calc = {
371
313
  ne,
372
314
  and,
373
315
  or,
374
- not,
375
316
  if: if_,
376
317
  ifs,
377
- coalesce,
378
- nullIf,
379
318
  isBlank,
380
319
  sum,
381
320
  count,
@@ -396,24 +335,26 @@ export const calc = {
396
335
  substitute,
397
336
  find,
398
337
  search,
338
+ split,
399
339
  splitText,
400
340
  regexMatch,
401
341
  regexReplace,
402
342
  regexExtract,
403
343
  jsonEscape,
404
344
  jsonUnescape,
345
+ repeat,
405
346
  round,
406
347
  power,
407
348
  sqrt,
408
- mod,
409
- abs,
410
349
  toNumber,
411
350
  uuid,
412
351
  now,
413
- today,
414
352
  makeDate,
353
+ dateTime,
415
354
  dateValue,
355
+ dateDiff,
416
356
  dateDif,
357
+ truncateDateTime,
417
358
  dateTimeTrunc,
418
359
  weekday,
419
360
  year,
@@ -431,3 +372,5 @@ export const calc = {
431
372
  email,
432
373
  name,
433
374
  };
375
+ export { dateDiffUnit, dateDifUnit, dateTimeTruncPrecision, weekdayMode, } from "./date.js";
376
+ export { orderByDirection, predicateOp } from "./aggregate.js";
@@ -3,20 +3,16 @@
3
3
  *
4
4
  * Each builder is a thin typed wrapper over a wire `FUNC(...)` form.
5
5
  * Output brands mirror the Java test's behavior:
6
- * - `round` preserves caller's brand expectation via overloads
7
- * (ROUND(x) returns the same bias as x; ROUND(x, n) returns
8
- * DECIMAL because the caller asked for decimal places).
6
+ * - `round` returns NUMBER without places and DECIMAL with places.
9
7
  * - `power`, `sqrt` return DECIMAL (fractional results possible).
10
- * - `mod`, `abs` preserve numeric brand via overload.
11
8
  * - `toNumber` coerces text → NUMBER.
12
9
  * - `uuid` is nullary and returns a `uuid`-branded expression.
13
10
  */
14
- import type { Expr, ExprLike, NumericExpr, NumericLike } from "./types.js";
15
- export declare function round(value: NumericLike): NumericExpr;
16
- export declare function round(value: NumericLike, digits: ExprLike<"number">): Expr<"decimal">;
17
- export declare function power(base: NumericLike, exponent: NumericLike): Expr<"decimal">;
18
- export declare function sqrt(value: NumericLike): Expr<"decimal">;
19
- export declare function mod(a: NumericLike, b: NumericLike): NumericExpr;
20
- export declare function abs(value: NumericLike): NumericExpr;
21
- export declare function toNumber(value: ExprLike<"text">): Expr<"number">;
11
+ import type { ComposedExpr, Expr, ExprLike, NumericLike } from "./types.js";
12
+ export declare function round<const Value extends NumericLike>(value: Value): ComposedExpr<"number", [Value]>;
13
+ export declare function round<const Value extends NumericLike>(value: Value, digits: 0): ComposedExpr<"number", [Value]>;
14
+ export declare function round<const Value extends NumericLike>(value: Value, digits: number): ComposedExpr<"decimal", [Value]>;
15
+ export declare function power<const Base extends NumericLike, const Exponent extends NumericLike>(base: Base, exponent: Exponent): ComposedExpr<"decimal", [Base, Exponent]>;
16
+ export declare function sqrt<const Value extends NumericLike>(value: Value): ComposedExpr<"decimal", [Value]>;
17
+ export declare function toNumber<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"number", [Value]>;
22
18
  export declare function uuid(): Expr<"uuid">;
@@ -3,22 +3,21 @@
3
3
  *
4
4
  * Each builder is a thin typed wrapper over a wire `FUNC(...)` form.
5
5
  * Output brands mirror the Java test's behavior:
6
- * - `round` preserves caller's brand expectation via overloads
7
- * (ROUND(x) returns the same bias as x; ROUND(x, n) returns
8
- * DECIMAL because the caller asked for decimal places).
6
+ * - `round` returns NUMBER without places and DECIMAL with places.
9
7
  * - `power`, `sqrt` return DECIMAL (fractional results possible).
10
- * - `mod`, `abs` preserve numeric brand via overload.
11
8
  * - `toNumber` coerces text → NUMBER.
12
9
  * - `uuid` is nullary and returns a `uuid`-branded expression.
13
10
  */
14
- import { coerce, makeExpr } from "./runtime.js";
11
+ import { coerce, makeComposedExpr, makeExpr } from "./runtime.js";
15
12
  export function round(value, digits) {
16
13
  const v = coerce(value);
17
14
  if (digits === undefined) {
18
- return makeExpr("decimal", () => `ROUND(${v.toCalcString()})`);
15
+ return makeComposedExpr("number", [v], () => `ROUND(${v.toCalcString()})`);
19
16
  }
20
- const d = coerce(digits);
21
- return makeExpr("decimal", () => `ROUND(${v.toCalcString()}, ${d.toCalcString()})`);
17
+ if (!Number.isInteger(digits) || digits < 0) {
18
+ throw new Error("calc.round: digits must be a non-negative integer literal.");
19
+ }
20
+ return makeComposedExpr(digits === 0 ? "number" : "decimal", [v], () => `ROUND(${v.toCalcString()}, ${digits})`);
22
21
  }
23
22
  // ---------------------------------------------------------------------------
24
23
  // POWER — base^exponent, decimal output.
@@ -26,30 +25,14 @@ export function round(value, digits) {
26
25
  export function power(base, exponent) {
27
26
  const b = coerce(base);
28
27
  const e = coerce(exponent);
29
- return makeExpr("decimal", () => `POWER(${b.toCalcString()}, ${e.toCalcString()})`);
28
+ return makeComposedExpr("decimal", [b, e], () => `POWER(${b.toCalcString()}, ${e.toCalcString()})`);
30
29
  }
31
30
  // ---------------------------------------------------------------------------
32
31
  // SQRT — square root, decimal output. Server null-guards negatives.
33
32
  // ---------------------------------------------------------------------------
34
33
  export function sqrt(value) {
35
34
  const v = coerce(value);
36
- return makeExpr("decimal", () => `SQRT(${v.toCalcString()})`);
37
- }
38
- // ---------------------------------------------------------------------------
39
- // MOD — remainder. Server emits this as the `%` operator under the
40
- // hood, but the wire grammar accepts MOD(a, b) too. Preserves brand.
41
- // ---------------------------------------------------------------------------
42
- export function mod(a, b) {
43
- const ae = coerce(a);
44
- const be = coerce(b);
45
- return makeExpr("decimal", () => `MOD(${ae.toCalcString()}, ${be.toCalcString()})`);
46
- }
47
- // ---------------------------------------------------------------------------
48
- // ABS — absolute value. Preserves brand.
49
- // ---------------------------------------------------------------------------
50
- export function abs(value) {
51
- const v = coerce(value);
52
- return makeExpr("decimal", () => `ABS(${v.toCalcString()})`);
35
+ return makeComposedExpr("decimal", [v], () => `SQRT(${v.toCalcString()})`);
53
36
  }
54
37
  // ---------------------------------------------------------------------------
55
38
  // VALUE (toNumber) — coerce text to numeric. Wire form is `VALUE(text)`.
@@ -57,7 +40,7 @@ export function abs(value) {
57
40
  // ---------------------------------------------------------------------------
58
41
  export function toNumber(value) {
59
42
  const v = coerce(value);
60
- return makeExpr("number", () => `VALUE(${v.toCalcString()})`);
43
+ return makeComposedExpr("number", [v], () => `VALUE(${v.toCalcString()})`);
61
44
  }
62
45
  // ---------------------------------------------------------------------------
63
46
  // UUID — nullary generator, returns `uuid`-branded.
@@ -21,12 +21,25 @@
21
21
  * canonical shape per the Java test).
22
22
  */
23
23
  import type { AppField, FieldScope } from "../../../core/types/app.js";
24
- import type { Expr, ExprLike, ExprType } from "./types.js";
24
+ import { type Ref } from "../../shared/ref.js";
25
+ import type { Expr, ExprCardinality, ExprContext, ExprLike, ExprType } from "./types.js";
25
26
  /**
26
27
  * Build an `Expr<T>` node from its type brand and a serializer
27
28
  * closure. Internal — public builders compose this.
28
29
  */
29
- export declare function makeExpr<T extends ExprType>(type: T, serialize: () => string): Expr<T>;
30
+ export declare function makeExpr<T extends ExprType, Cardinality extends ExprCardinality = "single", Context extends ExprContext = "standalone">(type: T, serialize: () => string, metadata?: {
31
+ readonly cardinality?: Cardinality;
32
+ readonly context?: Context;
33
+ }): Expr<T, Cardinality, Context>;
34
+ /**
35
+ * True if `value` is already an `Expr<T>` (built by a prior `calc.*`
36
+ * call or a pulled-expression marker). Discriminator-checked.
37
+ */
38
+ export declare function isExpr(value: unknown): value is Expr<ExprType, ExprCardinality, ExprContext>;
39
+ /** Aggregate runtime context metadata for a composed expression. */
40
+ export declare function expressionContext(expressions: readonly Expr<ExprType, ExprCardinality, ExprContext>[]): ExprContext;
41
+ /** Build a scalar parent node while preserving record-context metadata. */
42
+ export declare function makeComposedExpr<T extends ExprType>(type: T, expressions: readonly Expr<ExprType, ExprCardinality, ExprContext>[], serialize: () => string): Expr<T, "single", ExprContext>;
30
43
  /**
31
44
  * Emit the wire form of a field reference. UUID ids emit as
32
45
  * `"<uuid>"`; placeholder ids fall back to `"<name>"`. The server
@@ -36,6 +49,9 @@ export declare function makeExpr<T extends ExprType>(type: T, serialize: () => s
36
49
  * doubling) per the ANTLR grammar's IDENTIFIER_QUOTED rule.
37
50
  */
38
51
  export declare function emitFieldRef(field: AppField<FieldScope>): string;
52
+ type WorkflowRefRenderer = (value: Ref<unknown, string>) => string;
53
+ /** Install the automation calculation parameter collector for one render. */
54
+ export declare function withWorkflowRefRenderer<T>(renderer: WorkflowRefRenderer, render: () => T): T;
39
55
  /**
40
56
  * Quote a TS string for the wire. Single-quoted with `''` escapes per
41
57
  * the ANTLR grammar's STRING_LITERAL rule.
@@ -59,3 +75,4 @@ export declare function emitStringLiteral(value: string): string;
59
75
  * reaching here.
60
76
  */
61
77
  export declare function coerce<T extends ExprType>(value: ExprLike<T>): Expr<T>;
78
+ export {};