@azx-pbc/axiom-runtime 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (755) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +714 -2
  3. package/dist/cache/index.d.ts +191 -0
  4. package/dist/cache/index.d.ts.map +1 -0
  5. package/dist/cache/index.js +361 -0
  6. package/dist/cache/index.js.map +1 -0
  7. package/dist/canonical/jcs.d.ts +78 -0
  8. package/dist/canonical/jcs.d.ts.map +1 -0
  9. package/dist/canonical/jcs.js +500 -0
  10. package/dist/canonical/jcs.js.map +1 -0
  11. package/dist/canonical/restricted-json.d.ts +7 -0
  12. package/dist/canonical/restricted-json.d.ts.map +1 -0
  13. package/dist/canonical/restricted-json.js +318 -0
  14. package/dist/canonical/restricted-json.js.map +1 -0
  15. package/dist/canonical/restricted-value.d.ts +59 -0
  16. package/dist/canonical/restricted-value.d.ts.map +1 -0
  17. package/dist/canonical/restricted-value.js +156 -0
  18. package/dist/canonical/restricted-value.js.map +1 -0
  19. package/dist/canonical/restricted.d.ts +85 -0
  20. package/dist/canonical/restricted.d.ts.map +1 -0
  21. package/dist/canonical/restricted.js +163 -0
  22. package/dist/canonical/restricted.js.map +1 -0
  23. package/dist/canonical/signature.d.ts +38 -0
  24. package/dist/canonical/signature.d.ts.map +1 -0
  25. package/dist/canonical/signature.js +47 -0
  26. package/dist/canonical/signature.js.map +1 -0
  27. package/dist/eval/access/delivery.d.ts +63 -0
  28. package/dist/eval/access/delivery.d.ts.map +1 -0
  29. package/dist/eval/access/delivery.js +98 -0
  30. package/dist/eval/access/delivery.js.map +1 -0
  31. package/dist/eval/access/overlay.d.ts +72 -0
  32. package/dist/eval/access/overlay.d.ts.map +1 -0
  33. package/dist/eval/access/overlay.js +402 -0
  34. package/dist/eval/access/overlay.js.map +1 -0
  35. package/dist/eval/access/projection.d.ts +159 -0
  36. package/dist/eval/access/projection.d.ts.map +1 -0
  37. package/dist/eval/access/projection.js +211 -0
  38. package/dist/eval/access/projection.js.map +1 -0
  39. package/dist/eval/access/window.d.ts +128 -0
  40. package/dist/eval/access/window.d.ts.map +1 -0
  41. package/dist/eval/access/window.js +254 -0
  42. package/dist/eval/access/window.js.map +1 -0
  43. package/dist/eval/access/write.d.ts +113 -0
  44. package/dist/eval/access/write.d.ts.map +1 -0
  45. package/dist/eval/access/write.js +119 -0
  46. package/dist/eval/access/write.js.map +1 -0
  47. package/dist/eval/addressing.d.ts +131 -0
  48. package/dist/eval/addressing.d.ts.map +1 -0
  49. package/dist/eval/addressing.js +270 -0
  50. package/dist/eval/addressing.js.map +1 -0
  51. package/dist/eval/budget.d.ts +143 -0
  52. package/dist/eval/budget.d.ts.map +1 -0
  53. package/dist/eval/budget.js +387 -0
  54. package/dist/eval/budget.js.map +1 -0
  55. package/dist/eval/computed.d.ts +46 -0
  56. package/dist/eval/computed.d.ts.map +1 -0
  57. package/dist/eval/computed.js +89 -0
  58. package/dist/eval/computed.js.map +1 -0
  59. package/dist/eval/denials.d.ts +64 -0
  60. package/dist/eval/denials.d.ts.map +1 -0
  61. package/dist/eval/denials.js +87 -0
  62. package/dist/eval/denials.js.map +1 -0
  63. package/dist/eval/engine/cancellation.d.ts +12 -0
  64. package/dist/eval/engine/cancellation.d.ts.map +1 -0
  65. package/dist/eval/engine/cancellation.js +56 -0
  66. package/dist/eval/engine/cancellation.js.map +1 -0
  67. package/dist/eval/engine/delta.d.ts +104 -0
  68. package/dist/eval/engine/delta.d.ts.map +1 -0
  69. package/dist/eval/engine/delta.js +466 -0
  70. package/dist/eval/engine/delta.js.map +1 -0
  71. package/dist/eval/engine/deps.d.ts +136 -0
  72. package/dist/eval/engine/deps.d.ts.map +1 -0
  73. package/dist/eval/engine/deps.js +345 -0
  74. package/dist/eval/engine/deps.js.map +1 -0
  75. package/dist/eval/engine/identity.d.ts +128 -0
  76. package/dist/eval/engine/identity.d.ts.map +1 -0
  77. package/dist/eval/engine/identity.js +398 -0
  78. package/dist/eval/engine/identity.js.map +1 -0
  79. package/dist/eval/engine/index.d.ts +200 -0
  80. package/dist/eval/engine/index.d.ts.map +1 -0
  81. package/dist/eval/engine/index.js +1242 -0
  82. package/dist/eval/engine/index.js.map +1 -0
  83. package/dist/eval/engine/measurement.d.ts +23 -0
  84. package/dist/eval/engine/measurement.d.ts.map +1 -0
  85. package/dist/eval/engine/measurement.js +42 -0
  86. package/dist/eval/engine/measurement.js.map +1 -0
  87. package/dist/eval/engine/naive.d.ts +19 -0
  88. package/dist/eval/engine/naive.d.ts.map +1 -0
  89. package/dist/eval/engine/naive.js +59 -0
  90. package/dist/eval/engine/naive.js.map +1 -0
  91. package/dist/eval/engine/ops.d.ts +214 -0
  92. package/dist/eval/engine/ops.d.ts.map +1 -0
  93. package/dist/eval/engine/ops.js +1422 -0
  94. package/dist/eval/engine/ops.js.map +1 -0
  95. package/dist/eval/engine/patches.d.ts +40 -0
  96. package/dist/eval/engine/patches.d.ts.map +1 -0
  97. package/dist/eval/engine/patches.js +125 -0
  98. package/dist/eval/engine/patches.js.map +1 -0
  99. package/dist/eval/engine/ports.d.ts +71 -0
  100. package/dist/eval/engine/ports.d.ts.map +1 -0
  101. package/dist/eval/engine/ports.js +2 -0
  102. package/dist/eval/engine/ports.js.map +1 -0
  103. package/dist/eval/engine/session.d.ts +116 -0
  104. package/dist/eval/engine/session.d.ts.map +1 -0
  105. package/dist/eval/engine/session.js +653 -0
  106. package/dist/eval/engine/session.js.map +1 -0
  107. package/dist/eval/engine/snapshot.d.ts +97 -0
  108. package/dist/eval/engine/snapshot.d.ts.map +1 -0
  109. package/dist/eval/engine/snapshot.js +221 -0
  110. package/dist/eval/engine/snapshot.js.map +1 -0
  111. package/dist/eval/engine/subscriptions.d.ts +47 -0
  112. package/dist/eval/engine/subscriptions.d.ts.map +1 -0
  113. package/dist/eval/engine/subscriptions.js +103 -0
  114. package/dist/eval/engine/subscriptions.js.map +1 -0
  115. package/dist/eval/engine/trace.d.ts +77 -0
  116. package/dist/eval/engine/trace.d.ts.map +1 -0
  117. package/dist/eval/engine/trace.js +140 -0
  118. package/dist/eval/engine/trace.js.map +1 -0
  119. package/dist/eval/error-diagnostic.d.ts +26 -0
  120. package/dist/eval/error-diagnostic.d.ts.map +1 -0
  121. package/dist/eval/error-diagnostic.js +63 -0
  122. package/dist/eval/error-diagnostic.js.map +1 -0
  123. package/dist/eval/evaluate-expr.d.ts +44 -0
  124. package/dist/eval/evaluate-expr.d.ts.map +1 -0
  125. package/dist/eval/evaluate-expr.js +149 -0
  126. package/dist/eval/evaluate-expr.js.map +1 -0
  127. package/dist/eval/evaluate.d.ts +282 -0
  128. package/dist/eval/evaluate.d.ts.map +1 -0
  129. package/dist/eval/evaluate.js +391 -0
  130. package/dist/eval/evaluate.js.map +1 -0
  131. package/dist/eval/evolution/relocate.d.ts +72 -0
  132. package/dist/eval/evolution/relocate.d.ts.map +1 -0
  133. package/dist/eval/evolution/relocate.js +427 -0
  134. package/dist/eval/evolution/relocate.js.map +1 -0
  135. package/dist/eval/evolution/select.d.ts +11 -0
  136. package/dist/eval/evolution/select.d.ts.map +1 -0
  137. package/dist/eval/evolution/select.js +53 -0
  138. package/dist/eval/evolution/select.js.map +1 -0
  139. package/dist/eval/evolution/upcast.d.ts +13 -0
  140. package/dist/eval/evolution/upcast.d.ts.map +1 -0
  141. package/dist/eval/evolution/upcast.js +88 -0
  142. package/dist/eval/evolution/upcast.js.map +1 -0
  143. package/dist/eval/expr/aggregates.d.ts +75 -0
  144. package/dist/eval/expr/aggregates.d.ts.map +1 -0
  145. package/dist/eval/expr/aggregates.js +991 -0
  146. package/dist/eval/expr/aggregates.js.map +1 -0
  147. package/dist/eval/expr/arithmetic.d.ts +26 -0
  148. package/dist/eval/expr/arithmetic.d.ts.map +1 -0
  149. package/dist/eval/expr/arithmetic.js +387 -0
  150. package/dist/eval/expr/arithmetic.js.map +1 -0
  151. package/dist/eval/expr/between.d.ts +17 -0
  152. package/dist/eval/expr/between.d.ts.map +1 -0
  153. package/dist/eval/expr/between.js +46 -0
  154. package/dist/eval/expr/between.js.map +1 -0
  155. package/dist/eval/expr/binder.d.ts +96 -0
  156. package/dist/eval/expr/binder.d.ts.map +1 -0
  157. package/dist/eval/expr/binder.js +253 -0
  158. package/dist/eval/expr/binder.js.map +1 -0
  159. package/dist/eval/expr/call-dispatch.d.ts +28 -0
  160. package/dist/eval/expr/call-dispatch.d.ts.map +1 -0
  161. package/dist/eval/expr/call-dispatch.js +114 -0
  162. package/dist/eval/expr/call-dispatch.js.map +1 -0
  163. package/dist/eval/expr/collections.d.ts +20 -0
  164. package/dist/eval/expr/collections.d.ts.map +1 -0
  165. package/dist/eval/expr/collections.js +66 -0
  166. package/dist/eval/expr/collections.js.map +1 -0
  167. package/dist/eval/expr/compare.d.ts +36 -0
  168. package/dist/eval/expr/compare.d.ts.map +1 -0
  169. package/dist/eval/expr/compare.js +115 -0
  170. package/dist/eval/expr/compare.js.map +1 -0
  171. package/dist/eval/expr/datasets.d.ts +28 -0
  172. package/dist/eval/expr/datasets.d.ts.map +1 -0
  173. package/dist/eval/expr/datasets.js +304 -0
  174. package/dist/eval/expr/datasets.js.map +1 -0
  175. package/dist/eval/expr/digest.d.ts +23 -0
  176. package/dist/eval/expr/digest.d.ts.map +1 -0
  177. package/dist/eval/expr/digest.js +89 -0
  178. package/dist/eval/expr/digest.js.map +1 -0
  179. package/dist/eval/expr/domains.d.ts +19 -0
  180. package/dist/eval/expr/domains.d.ts.map +1 -0
  181. package/dist/eval/expr/domains.js +18 -0
  182. package/dist/eval/expr/domains.js.map +1 -0
  183. package/dist/eval/expr/host.d.ts +152 -0
  184. package/dist/eval/expr/host.d.ts.map +1 -0
  185. package/dist/eval/expr/host.js +36 -0
  186. package/dist/eval/expr/host.js.map +1 -0
  187. package/dist/eval/expr/lists.d.ts +24 -0
  188. package/dist/eval/expr/lists.d.ts.map +1 -0
  189. package/dist/eval/expr/lists.js +155 -0
  190. package/dist/eval/expr/lists.js.map +1 -0
  191. package/dist/eval/expr/member.d.ts +15 -0
  192. package/dist/eval/expr/member.d.ts.map +1 -0
  193. package/dist/eval/expr/member.js +32 -0
  194. package/dist/eval/expr/member.js.map +1 -0
  195. package/dist/eval/expr/money-ops.d.ts +10 -0
  196. package/dist/eval/expr/money-ops.d.ts.map +1 -0
  197. package/dist/eval/expr/money-ops.js +17 -0
  198. package/dist/eval/expr/money-ops.js.map +1 -0
  199. package/dist/eval/expr/operands.d.ts +27 -0
  200. package/dist/eval/expr/operands.d.ts.map +1 -0
  201. package/dist/eval/expr/operands.js +167 -0
  202. package/dist/eval/expr/operands.js.map +1 -0
  203. package/dist/eval/expr/presence.d.ts +27 -0
  204. package/dist/eval/expr/presence.d.ts.map +1 -0
  205. package/dist/eval/expr/presence.js +140 -0
  206. package/dist/eval/expr/presence.js.map +1 -0
  207. package/dist/eval/expr/records.d.ts +22 -0
  208. package/dist/eval/expr/records.d.ts.map +1 -0
  209. package/dist/eval/expr/records.js +101 -0
  210. package/dist/eval/expr/records.js.map +1 -0
  211. package/dist/eval/expr/rule-refs.d.ts +25 -0
  212. package/dist/eval/expr/rule-refs.d.ts.map +1 -0
  213. package/dist/eval/expr/rule-refs.js +60 -0
  214. package/dist/eval/expr/rule-refs.js.map +1 -0
  215. package/dist/eval/expr/sequences.d.ts +26 -0
  216. package/dist/eval/expr/sequences.d.ts.map +1 -0
  217. package/dist/eval/expr/sequences.js +151 -0
  218. package/dist/eval/expr/sequences.js.map +1 -0
  219. package/dist/eval/expr/value.d.ts +99 -0
  220. package/dist/eval/expr/value.d.ts.map +1 -0
  221. package/dist/eval/expr/value.js +14 -0
  222. package/dist/eval/expr/value.js.map +1 -0
  223. package/dist/eval/expression.d.ts +142 -0
  224. package/dist/eval/expression.d.ts.map +1 -0
  225. package/dist/eval/expression.js +446 -0
  226. package/dist/eval/expression.js.map +1 -0
  227. package/dist/eval/firing.d.ts +68 -0
  228. package/dist/eval/firing.d.ts.map +1 -0
  229. package/dist/eval/firing.js +222 -0
  230. package/dist/eval/firing.js.map +1 -0
  231. package/dist/eval/gate.d.ts +110 -0
  232. package/dist/eval/gate.d.ts.map +1 -0
  233. package/dist/eval/gate.js +278 -0
  234. package/dist/eval/gate.js.map +1 -0
  235. package/dist/eval/layout-visibility.d.ts +18 -0
  236. package/dist/eval/layout-visibility.d.ts.map +1 -0
  237. package/dist/eval/layout-visibility.js +61 -0
  238. package/dist/eval/layout-visibility.js.map +1 -0
  239. package/dist/eval/option-availability.d.ts +26 -0
  240. package/dist/eval/option-availability.d.ts.map +1 -0
  241. package/dist/eval/option-availability.js +580 -0
  242. package/dist/eval/option-availability.js.map +1 -0
  243. package/dist/eval/options-boundary.d.ts +15 -0
  244. package/dist/eval/options-boundary.d.ts.map +1 -0
  245. package/dist/eval/options-boundary.js +40 -0
  246. package/dist/eval/options-boundary.js.map +1 -0
  247. package/dist/eval/options.d.ts +99 -0
  248. package/dist/eval/options.d.ts.map +1 -0
  249. package/dist/eval/options.js +96 -0
  250. package/dist/eval/options.js.map +1 -0
  251. package/dist/eval/overrides.d.ts +116 -0
  252. package/dist/eval/overrides.d.ts.map +1 -0
  253. package/dist/eval/overrides.js +176 -0
  254. package/dist/eval/overrides.js.map +1 -0
  255. package/dist/eval/paths.d.ts +25 -0
  256. package/dist/eval/paths.d.ts.map +1 -0
  257. package/dist/eval/paths.js +47 -0
  258. package/dist/eval/paths.js.map +1 -0
  259. package/dist/eval/presentation-reads.d.ts +20 -0
  260. package/dist/eval/presentation-reads.d.ts.map +1 -0
  261. package/dist/eval/presentation-reads.js +2 -0
  262. package/dist/eval/presentation-reads.js.map +1 -0
  263. package/dist/eval/presentation.d.ts +122 -0
  264. package/dist/eval/presentation.d.ts.map +1 -0
  265. package/dist/eval/presentation.js +255 -0
  266. package/dist/eval/presentation.js.map +1 -0
  267. package/dist/eval/reader/context-value.d.ts +41 -0
  268. package/dist/eval/reader/context-value.d.ts.map +1 -0
  269. package/dist/eval/reader/context-value.js +129 -0
  270. package/dist/eval/reader/context-value.js.map +1 -0
  271. package/dist/eval/reader/covered.d.ts +53 -0
  272. package/dist/eval/reader/covered.d.ts.map +1 -0
  273. package/dist/eval/reader/covered.js +139 -0
  274. package/dist/eval/reader/covered.js.map +1 -0
  275. package/dist/eval/reader/declarations.d.ts +182 -0
  276. package/dist/eval/reader/declarations.d.ts.map +1 -0
  277. package/dist/eval/reader/declarations.js +153 -0
  278. package/dist/eval/reader/declarations.js.map +1 -0
  279. package/dist/eval/reader/member-access.d.ts +87 -0
  280. package/dist/eval/reader/member-access.d.ts.map +1 -0
  281. package/dist/eval/reader/member-access.js +212 -0
  282. package/dist/eval/reader/member-access.js.map +1 -0
  283. package/dist/eval/reader/memo.d.ts +34 -0
  284. package/dist/eval/reader/memo.d.ts.map +1 -0
  285. package/dist/eval/reader/memo.js +67 -0
  286. package/dist/eval/reader/memo.js.map +1 -0
  287. package/dist/eval/reader/overlay.d.ts +74 -0
  288. package/dist/eval/reader/overlay.d.ts.map +1 -0
  289. package/dist/eval/reader/overlay.js +365 -0
  290. package/dist/eval/reader/overlay.js.map +1 -0
  291. package/dist/eval/reader/questions.d.ts +37 -0
  292. package/dist/eval/reader/questions.d.ts.map +1 -0
  293. package/dist/eval/reader/questions.js +78 -0
  294. package/dist/eval/reader/questions.js.map +1 -0
  295. package/dist/eval/reader/resolve.d.ts +84 -0
  296. package/dist/eval/reader/resolve.d.ts.map +1 -0
  297. package/dist/eval/reader/resolve.js +310 -0
  298. package/dist/eval/reader/resolve.js.map +1 -0
  299. package/dist/eval/reader/value-read.d.ts +50 -0
  300. package/dist/eval/reader/value-read.d.ts.map +1 -0
  301. package/dist/eval/reader/value-read.js +133 -0
  302. package/dist/eval/reader/value-read.js.map +1 -0
  303. package/dist/eval/reader/withheld.d.ts +48 -0
  304. package/dist/eval/reader/withheld.d.ts.map +1 -0
  305. package/dist/eval/reader/withheld.js +108 -0
  306. package/dist/eval/reader/withheld.js.map +1 -0
  307. package/dist/eval/reader-paths.d.ts +24 -0
  308. package/dist/eval/reader-paths.d.ts.map +1 -0
  309. package/dist/eval/reader-paths.js +23 -0
  310. package/dist/eval/reader-paths.js.map +1 -0
  311. package/dist/eval/reader.d.ts +281 -0
  312. package/dist/eval/reader.d.ts.map +1 -0
  313. package/dist/eval/reader.js +560 -0
  314. package/dist/eval/reader.js.map +1 -0
  315. package/dist/eval/receipt.d.ts +37 -0
  316. package/dist/eval/receipt.d.ts.map +1 -0
  317. package/dist/eval/receipt.js +222 -0
  318. package/dist/eval/receipt.js.map +1 -0
  319. package/dist/eval/report/assemble.d.ts +84 -0
  320. package/dist/eval/report/assemble.d.ts.map +1 -0
  321. package/dist/eval/report/assemble.js +277 -0
  322. package/dist/eval/report/assemble.js.map +1 -0
  323. package/dist/eval/report/fold.d.ts +18 -0
  324. package/dist/eval/report/fold.d.ts.map +1 -0
  325. package/dist/eval/report/fold.js +58 -0
  326. package/dist/eval/report/fold.js.map +1 -0
  327. package/dist/eval/rule/alternatives.d.ts +23 -0
  328. package/dist/eval/rule/alternatives.d.ts.map +1 -0
  329. package/dist/eval/rule/alternatives.js +46 -0
  330. package/dist/eval/rule/alternatives.js.map +1 -0
  331. package/dist/eval/rule/behaviour.d.ts +47 -0
  332. package/dist/eval/rule/behaviour.d.ts.map +1 -0
  333. package/dist/eval/rule/behaviour.js +249 -0
  334. package/dist/eval/rule/behaviour.js.map +1 -0
  335. package/dist/eval/rule/compute.d.ts +46 -0
  336. package/dist/eval/rule/compute.d.ts.map +1 -0
  337. package/dist/eval/rule/compute.js +158 -0
  338. package/dist/eval/rule/compute.js.map +1 -0
  339. package/dist/eval/rule/create-state.d.ts +42 -0
  340. package/dist/eval/rule/create-state.d.ts.map +1 -0
  341. package/dist/eval/rule/create-state.js +134 -0
  342. package/dist/eval/rule/create-state.js.map +1 -0
  343. package/dist/eval/rule/diagnostics.d.ts +24 -0
  344. package/dist/eval/rule/diagnostics.d.ts.map +1 -0
  345. package/dist/eval/rule/diagnostics.js +45 -0
  346. package/dist/eval/rule/diagnostics.js.map +1 -0
  347. package/dist/eval/rule/execution.d.ts +24 -0
  348. package/dist/eval/rule/execution.d.ts.map +1 -0
  349. package/dist/eval/rule/execution.js +495 -0
  350. package/dist/eval/rule/execution.js.map +1 -0
  351. package/dist/eval/rule/gate.d.ts +12 -0
  352. package/dist/eval/rule/gate.d.ts.map +1 -0
  353. package/dist/eval/rule/gate.js +34 -0
  354. package/dist/eval/rule/gate.js.map +1 -0
  355. package/dist/eval/rule/item.d.ts +11 -0
  356. package/dist/eval/rule/item.d.ts.map +1 -0
  357. package/dist/eval/rule/item.js +265 -0
  358. package/dist/eval/rule/item.js.map +1 -0
  359. package/dist/eval/rule/prepare.d.ts +64 -0
  360. package/dist/eval/rule/prepare.d.ts.map +1 -0
  361. package/dist/eval/rule/prepare.js +131 -0
  362. package/dist/eval/rule/prepare.js.map +1 -0
  363. package/dist/eval/rule/result.d.ts +97 -0
  364. package/dist/eval/rule/result.d.ts.map +1 -0
  365. package/dist/eval/rule/result.js +347 -0
  366. package/dist/eval/rule/result.js.map +1 -0
  367. package/dist/eval/rule/runner.d.ts +128 -0
  368. package/dist/eval/rule/runner.d.ts.map +1 -0
  369. package/dist/eval/rule/runner.js +296 -0
  370. package/dist/eval/rule/runner.js.map +1 -0
  371. package/dist/eval/rule/screen.d.ts +32 -0
  372. package/dist/eval/rule/screen.d.ts.map +1 -0
  373. package/dist/eval/rule/screen.js +73 -0
  374. package/dist/eval/rule/screen.js.map +1 -0
  375. package/dist/eval/rule/state.d.ts +137 -0
  376. package/dist/eval/rule/state.d.ts.map +1 -0
  377. package/dist/eval/rule/state.js +2 -0
  378. package/dist/eval/rule/state.js.map +1 -0
  379. package/dist/eval/rule/steps.d.ts +44 -0
  380. package/dist/eval/rule/steps.d.ts.map +1 -0
  381. package/dist/eval/rule/steps.js +367 -0
  382. package/dist/eval/rule/steps.js.map +1 -0
  383. package/dist/eval/rule/visibility.d.ts +18 -0
  384. package/dist/eval/rule/visibility.d.ts.map +1 -0
  385. package/dist/eval/rule/visibility.js +79 -0
  386. package/dist/eval/rule/visibility.js.map +1 -0
  387. package/dist/eval/seal.d.ts +74 -0
  388. package/dist/eval/seal.d.ts.map +1 -0
  389. package/dist/eval/seal.js +154 -0
  390. package/dist/eval/seal.js.map +1 -0
  391. package/dist/eval/signature-coverage.d.ts +19 -0
  392. package/dist/eval/signature-coverage.d.ts.map +1 -0
  393. package/dist/eval/signature-coverage.js +160 -0
  394. package/dist/eval/signature-coverage.js.map +1 -0
  395. package/dist/eval/state/derive.d.ts +72 -0
  396. package/dist/eval/state/derive.d.ts.map +1 -0
  397. package/dist/eval/state/derive.js +61 -0
  398. package/dist/eval/state/derive.js.map +1 -0
  399. package/dist/eval/state/describe.d.ts +18 -0
  400. package/dist/eval/state/describe.d.ts.map +1 -0
  401. package/dist/eval/state/describe.js +19 -0
  402. package/dist/eval/state/describe.js.map +1 -0
  403. package/dist/eval/state/field-state.d.ts +471 -0
  404. package/dist/eval/state/field-state.d.ts.map +1 -0
  405. package/dist/eval/state/field-state.js +1604 -0
  406. package/dist/eval/state/field-state.js.map +1 -0
  407. package/dist/eval/state/measurement.d.ts +136 -0
  408. package/dist/eval/state/measurement.d.ts.map +1 -0
  409. package/dist/eval/state/measurement.js +209 -0
  410. package/dist/eval/state/measurement.js.map +1 -0
  411. package/dist/eval/state/options.d.ts +21 -0
  412. package/dist/eval/state/options.d.ts.map +1 -0
  413. package/dist/eval/state/options.js +3 -0
  414. package/dist/eval/state/options.js.map +1 -0
  415. package/dist/eval/state/readiness.d.ts +400 -0
  416. package/dist/eval/state/readiness.d.ts.map +1 -0
  417. package/dist/eval/state/readiness.js +1067 -0
  418. package/dist/eval/state/readiness.js.map +1 -0
  419. package/dist/eval/state/snapshot.d.ts +130 -0
  420. package/dist/eval/state/snapshot.d.ts.map +1 -0
  421. package/dist/eval/state/snapshot.js +35 -0
  422. package/dist/eval/state/snapshot.js.map +1 -0
  423. package/dist/eval/state/unavailable-options.d.ts +54 -0
  424. package/dist/eval/state/unavailable-options.d.ts.map +1 -0
  425. package/dist/eval/state/unavailable-options.js +82 -0
  426. package/dist/eval/state/unavailable-options.js.map +1 -0
  427. package/dist/eval/state/value-state.d.ts +38 -0
  428. package/dist/eval/state/value-state.d.ts.map +1 -0
  429. package/dist/eval/state/value-state.js +52 -0
  430. package/dist/eval/state/value-state.js.map +1 -0
  431. package/dist/eval/submission/admission.d.ts +50 -0
  432. package/dist/eval/submission/admission.d.ts.map +1 -0
  433. package/dist/eval/submission/admission.js +174 -0
  434. package/dist/eval/submission/admission.js.map +1 -0
  435. package/dist/eval/submission/authority.d.ts +71 -0
  436. package/dist/eval/submission/authority.d.ts.map +1 -0
  437. package/dist/eval/submission/authority.js +118 -0
  438. package/dist/eval/submission/authority.js.map +1 -0
  439. package/dist/eval/submission/datasets.d.ts +28 -0
  440. package/dist/eval/submission/datasets.d.ts.map +1 -0
  441. package/dist/eval/submission/datasets.js +109 -0
  442. package/dist/eval/submission/datasets.js.map +1 -0
  443. package/dist/eval/submission/index.d.ts +15 -0
  444. package/dist/eval/submission/index.d.ts.map +1 -0
  445. package/dist/eval/submission/index.js +13 -0
  446. package/dist/eval/submission/index.js.map +1 -0
  447. package/dist/eval/submission/refusals.d.ts +103 -0
  448. package/dist/eval/submission/refusals.d.ts.map +1 -0
  449. package/dist/eval/submission/refusals.js +15 -0
  450. package/dist/eval/submission/refusals.js.map +1 -0
  451. package/dist/eval/submission/signatures.d.ts +7 -0
  452. package/dist/eval/submission/signatures.d.ts.map +1 -0
  453. package/dist/eval/submission/signatures.js +215 -0
  454. package/dist/eval/submission/signatures.js.map +1 -0
  455. package/dist/eval/submission/writes.d.ts +51 -0
  456. package/dist/eval/submission/writes.d.ts.map +1 -0
  457. package/dist/eval/submission/writes.js +203 -0
  458. package/dist/eval/submission/writes.js.map +1 -0
  459. package/dist/eval/submission.d.ts +53 -0
  460. package/dist/eval/submission.d.ts.map +1 -0
  461. package/dist/eval/submission.js +521 -0
  462. package/dist/eval/submission.js.map +1 -0
  463. package/dist/eval/suggestions-to-engine.d.ts +18 -0
  464. package/dist/eval/suggestions-to-engine.d.ts.map +1 -0
  465. package/dist/eval/suggestions-to-engine.js +40 -0
  466. package/dist/eval/suggestions-to-engine.js.map +1 -0
  467. package/dist/eval/suggestions.d.ts +17 -0
  468. package/dist/eval/suggestions.d.ts.map +1 -0
  469. package/dist/eval/suggestions.js +314 -0
  470. package/dist/eval/suggestions.js.map +1 -0
  471. package/dist/eval/undecided.d.ts +64 -0
  472. package/dist/eval/undecided.d.ts.map +1 -0
  473. package/dist/eval/undecided.js +101 -0
  474. package/dist/eval/undecided.js.map +1 -0
  475. package/dist/eval/verdict.d.ts +66 -0
  476. package/dist/eval/verdict.d.ts.map +1 -0
  477. package/dist/eval/verdict.js +106 -0
  478. package/dist/eval/verdict.js.map +1 -0
  479. package/dist/eval/verify-signature.d.ts +78 -0
  480. package/dist/eval/verify-signature.d.ts.map +1 -0
  481. package/dist/eval/verify-signature.js +185 -0
  482. package/dist/eval/verify-signature.js.map +1 -0
  483. package/dist/eval/version-dispatch.d.ts +38 -0
  484. package/dist/eval/version-dispatch.d.ts.map +1 -0
  485. package/dist/eval/version-dispatch.js +61 -0
  486. package/dist/eval/version-dispatch.js.map +1 -0
  487. package/dist/eval/visibility.d.ts +33 -0
  488. package/dist/eval/visibility.d.ts.map +1 -0
  489. package/dist/eval/visibility.js +83 -0
  490. package/dist/eval/visibility.js.map +1 -0
  491. package/dist/evaluate.d.ts +24 -0
  492. package/dist/evaluate.d.ts.map +1 -0
  493. package/dist/evaluate.js +18 -0
  494. package/dist/evaluate.js.map +1 -0
  495. package/dist/expr/builtin-docs.d.ts +51 -0
  496. package/dist/expr/builtin-docs.d.ts.map +1 -0
  497. package/dist/expr/builtin-docs.js +874 -0
  498. package/dist/expr/builtin-docs.js.map +1 -0
  499. package/dist/expr/builtins.d.ts +50 -0
  500. package/dist/expr/builtins.d.ts.map +1 -0
  501. package/dist/expr/builtins.js +966 -0
  502. package/dist/expr/builtins.js.map +1 -0
  503. package/dist/expr/decimal-precision.d.ts +39 -0
  504. package/dist/expr/decimal-precision.d.ts.map +1 -0
  505. package/dist/expr/decimal-precision.js +62 -0
  506. package/dist/expr/decimal-precision.js.map +1 -0
  507. package/dist/expr/decimal.d.ts +172 -0
  508. package/dist/expr/decimal.d.ts.map +1 -0
  509. package/dist/expr/decimal.js +782 -0
  510. package/dist/expr/decimal.js.map +1 -0
  511. package/dist/expr/deprecations.d.ts +34 -0
  512. package/dist/expr/deprecations.d.ts.map +1 -0
  513. package/dist/expr/deprecations.js +17 -0
  514. package/dist/expr/deprecations.js.map +1 -0
  515. package/dist/expr/diagnostics.d.ts +21 -0
  516. package/dist/expr/diagnostics.d.ts.map +1 -0
  517. package/dist/expr/diagnostics.js +231 -0
  518. package/dist/expr/diagnostics.js.map +1 -0
  519. package/dist/expr/direction.d.ts +30 -0
  520. package/dist/expr/direction.d.ts.map +1 -0
  521. package/dist/expr/direction.js +77 -0
  522. package/dist/expr/direction.js.map +1 -0
  523. package/dist/expr/example-expression.d.ts +62 -0
  524. package/dist/expr/example-expression.d.ts.map +1 -0
  525. package/dist/expr/example-expression.js +670 -0
  526. package/dist/expr/example-expression.js.map +1 -0
  527. package/dist/expr/instant.d.ts +49 -0
  528. package/dist/expr/instant.d.ts.map +1 -0
  529. package/dist/expr/instant.js +111 -0
  530. package/dist/expr/instant.js.map +1 -0
  531. package/dist/expr/logic.d.ts +17 -0
  532. package/dist/expr/logic.d.ts.map +1 -0
  533. package/dist/expr/logic.js +65 -0
  534. package/dist/expr/logic.js.map +1 -0
  535. package/dist/expr/messages.d.ts +45 -0
  536. package/dist/expr/messages.d.ts.map +1 -0
  537. package/dist/expr/messages.js +280 -0
  538. package/dist/expr/messages.js.map +1 -0
  539. package/dist/expr/money.d.ts +38 -0
  540. package/dist/expr/money.d.ts.map +1 -0
  541. package/dist/expr/money.js +127 -0
  542. package/dist/expr/money.js.map +1 -0
  543. package/dist/expr/ordering.d.ts +56 -0
  544. package/dist/expr/ordering.d.ts.map +1 -0
  545. package/dist/expr/ordering.js +167 -0
  546. package/dist/expr/ordering.js.map +1 -0
  547. package/dist/expr/pattern.d.ts +44 -0
  548. package/dist/expr/pattern.d.ts.map +1 -0
  549. package/dist/expr/pattern.js +458 -0
  550. package/dist/expr/pattern.js.map +1 -0
  551. package/dist/expr/plain-date.d.ts +90 -0
  552. package/dist/expr/plain-date.d.ts.map +1 -0
  553. package/dist/expr/plain-date.js +230 -0
  554. package/dist/expr/plain-date.js.map +1 -0
  555. package/dist/expr/plural-categories.d.ts +8 -0
  556. package/dist/expr/plural-categories.d.ts.map +1 -0
  557. package/dist/expr/plural-categories.js +15 -0
  558. package/dist/expr/plural-categories.js.map +1 -0
  559. package/dist/expr/plural-keys.d.ts +39 -0
  560. package/dist/expr/plural-keys.d.ts.map +1 -0
  561. package/dist/expr/plural-keys.js +46 -0
  562. package/dist/expr/plural-keys.js.map +1 -0
  563. package/dist/expr/plural.d.ts +33 -0
  564. package/dist/expr/plural.d.ts.map +1 -0
  565. package/dist/expr/plural.js +50 -0
  566. package/dist/expr/plural.js.map +1 -0
  567. package/dist/expr/quantity.d.ts +31 -0
  568. package/dist/expr/quantity.d.ts.map +1 -0
  569. package/dist/expr/quantity.js +83 -0
  570. package/dist/expr/quantity.js.map +1 -0
  571. package/dist/expr/reduce.d.ts +50 -0
  572. package/dist/expr/reduce.d.ts.map +1 -0
  573. package/dist/expr/reduce.js +236 -0
  574. package/dist/expr/reduce.js.map +1 -0
  575. package/dist/expr/regex.d.ts +108 -0
  576. package/dist/expr/regex.d.ts.map +1 -0
  577. package/dist/expr/regex.js +1207 -0
  578. package/dist/expr/regex.js.map +1 -0
  579. package/dist/expr/select-locale.d.ts +67 -0
  580. package/dist/expr/select-locale.d.ts.map +1 -0
  581. package/dist/expr/select-locale.js +219 -0
  582. package/dist/expr/select-locale.js.map +1 -0
  583. package/dist/expr/sequences.d.ts +123 -0
  584. package/dist/expr/sequences.d.ts.map +1 -0
  585. package/dist/expr/sequences.js +234 -0
  586. package/dist/expr/sequences.js.map +1 -0
  587. package/dist/expr/strings.d.ts +50 -0
  588. package/dist/expr/strings.d.ts.map +1 -0
  589. package/dist/expr/strings.js +184 -0
  590. package/dist/expr/strings.js.map +1 -0
  591. package/dist/expr/validation.d.ts +32 -0
  592. package/dist/expr/validation.d.ts.map +1 -0
  593. package/dist/expr/validation.js +182 -0
  594. package/dist/expr/validation.js.map +1 -0
  595. package/dist/graph/freeze.d.ts +4 -0
  596. package/dist/graph/freeze.d.ts.map +1 -0
  597. package/dist/graph/freeze.js +52 -0
  598. package/dist/graph/freeze.js.map +1 -0
  599. package/dist/graph/index.d.ts +15 -0
  600. package/dist/graph/index.d.ts.map +1 -0
  601. package/dist/graph/index.js +13 -0
  602. package/dist/graph/index.js.map +1 -0
  603. package/dist/graph/inspect.d.ts +76 -0
  604. package/dist/graph/inspect.d.ts.map +1 -0
  605. package/dist/graph/inspect.js +263 -0
  606. package/dist/graph/inspect.js.map +1 -0
  607. package/dist/graph/read-walk.d.ts +101 -0
  608. package/dist/graph/read-walk.d.ts.map +1 -0
  609. package/dist/graph/read-walk.js +358 -0
  610. package/dist/graph/read-walk.js.map +1 -0
  611. package/dist/graph/record-index.d.ts +24 -0
  612. package/dist/graph/record-index.d.ts.map +1 -0
  613. package/dist/graph/record-index.js +35 -0
  614. package/dist/graph/record-index.js.map +1 -0
  615. package/dist/index.d.ts +104 -0
  616. package/dist/index.d.ts.map +1 -0
  617. package/dist/index.js +139 -0
  618. package/dist/index.js.map +1 -0
  619. package/dist/lookup/digest.d.ts +51 -0
  620. package/dist/lookup/digest.d.ts.map +1 -0
  621. package/dist/lookup/digest.js +46 -0
  622. package/dist/lookup/digest.js.map +1 -0
  623. package/dist/lookup/index.d.ts +28 -0
  624. package/dist/lookup/index.d.ts.map +1 -0
  625. package/dist/lookup/index.js +27 -0
  626. package/dist/lookup/index.js.map +1 -0
  627. package/dist/lookup/install.d.ts +48 -0
  628. package/dist/lookup/install.d.ts.map +1 -0
  629. package/dist/lookup/install.js +315 -0
  630. package/dist/lookup/install.js.map +1 -0
  631. package/dist/lookup/pass.d.ts +55 -0
  632. package/dist/lookup/pass.d.ts.map +1 -0
  633. package/dist/lookup/pass.js +212 -0
  634. package/dist/lookup/pass.js.map +1 -0
  635. package/dist/lookup/pins.d.ts +34 -0
  636. package/dist/lookup/pins.d.ts.map +1 -0
  637. package/dist/lookup/pins.js +39 -0
  638. package/dist/lookup/pins.js.map +1 -0
  639. package/dist/lookup/provenance.d.ts +23 -0
  640. package/dist/lookup/provenance.d.ts.map +1 -0
  641. package/dist/lookup/provenance.js +78 -0
  642. package/dist/lookup/provenance.js.map +1 -0
  643. package/dist/lookup/readiness.d.ts +13 -0
  644. package/dist/lookup/readiness.d.ts.map +1 -0
  645. package/dist/lookup/readiness.js +57 -0
  646. package/dist/lookup/readiness.js.map +1 -0
  647. package/dist/lookup/resolve.d.ts +24 -0
  648. package/dist/lookup/resolve.d.ts.map +1 -0
  649. package/dist/lookup/resolve.js +201 -0
  650. package/dist/lookup/resolve.js.map +1 -0
  651. package/dist/lookup/store.d.ts +41 -0
  652. package/dist/lookup/store.d.ts.map +1 -0
  653. package/dist/lookup/store.js +74 -0
  654. package/dist/lookup/store.js.map +1 -0
  655. package/dist/model/access.d.ts +200 -0
  656. package/dist/model/access.d.ts.map +1 -0
  657. package/dist/model/access.js +125 -0
  658. package/dist/model/access.js.map +1 -0
  659. package/dist/model/artifact-members.d.ts +3 -0
  660. package/dist/model/artifact-members.d.ts.map +1 -0
  661. package/dist/model/artifact-members.js +38 -0
  662. package/dist/model/artifact-members.js.map +1 -0
  663. package/dist/model/composition.d.ts +47 -0
  664. package/dist/model/composition.d.ts.map +1 -0
  665. package/dist/model/composition.js +66 -0
  666. package/dist/model/composition.js.map +1 -0
  667. package/dist/model/domain.d.ts +51 -0
  668. package/dist/model/domain.d.ts.map +1 -0
  669. package/dist/model/domain.js +75 -0
  670. package/dist/model/domain.js.map +1 -0
  671. package/dist/model/duration.d.ts +31 -0
  672. package/dist/model/duration.d.ts.map +1 -0
  673. package/dist/model/duration.js +136 -0
  674. package/dist/model/duration.js.map +1 -0
  675. package/dist/model/errors.d.ts +58 -0
  676. package/dist/model/errors.d.ts.map +1 -0
  677. package/dist/model/errors.js +81 -0
  678. package/dist/model/errors.js.map +1 -0
  679. package/dist/model/evolution.d.ts +177 -0
  680. package/dist/model/evolution.d.ts.map +1 -0
  681. package/dist/model/evolution.js +5 -0
  682. package/dist/model/evolution.js.map +1 -0
  683. package/dist/model/expr-children.d.ts +15 -0
  684. package/dist/model/expr-children.d.ts.map +1 -0
  685. package/dist/model/expr-children.js +45 -0
  686. package/dist/model/expr-children.js.map +1 -0
  687. package/dist/model/guards.d.ts +9 -0
  688. package/dist/model/guards.d.ts.map +1 -0
  689. package/dist/model/guards.js +11 -0
  690. package/dist/model/guards.js.map +1 -0
  691. package/dist/model/input.d.ts +42 -0
  692. package/dist/model/input.d.ts.map +1 -0
  693. package/dist/model/input.js +26 -0
  694. package/dist/model/input.js.map +1 -0
  695. package/dist/model/integer.d.ts +14 -0
  696. package/dist/model/integer.d.ts.map +1 -0
  697. package/dist/model/integer.js +16 -0
  698. package/dist/model/integer.js.map +1 -0
  699. package/dist/model/intrinsic.d.ts +18 -0
  700. package/dist/model/intrinsic.d.ts.map +1 -0
  701. package/dist/model/intrinsic.js +21 -0
  702. package/dist/model/intrinsic.js.map +1 -0
  703. package/dist/model/layout.d.ts +129 -0
  704. package/dist/model/layout.d.ts.map +1 -0
  705. package/dist/model/layout.js +2 -0
  706. package/dist/model/layout.js.map +1 -0
  707. package/dist/model/media.d.ts +33 -0
  708. package/dist/model/media.d.ts.map +1 -0
  709. package/dist/model/media.js +86 -0
  710. package/dist/model/media.js.map +1 -0
  711. package/dist/model/members.generated.d.ts +11 -0
  712. package/dist/model/members.generated.d.ts.map +1 -0
  713. package/dist/model/members.generated.js +71 -0
  714. package/dist/model/members.generated.js.map +1 -0
  715. package/dist/model/row-address.d.ts +27 -0
  716. package/dist/model/row-address.d.ts.map +1 -0
  717. package/dist/model/row-address.js +146 -0
  718. package/dist/model/row-address.js.map +1 -0
  719. package/dist/model/schema.d.ts +108 -0
  720. package/dist/model/schema.d.ts.map +1 -0
  721. package/dist/model/schema.js +2 -0
  722. package/dist/model/schema.js.map +1 -0
  723. package/dist/model/shape.d.ts +193 -0
  724. package/dist/model/shape.d.ts.map +1 -0
  725. package/dist/model/shape.js +2 -0
  726. package/dist/model/shape.js.map +1 -0
  727. package/dist/model/time.d.ts +61 -0
  728. package/dist/model/time.d.ts.map +1 -0
  729. package/dist/model/time.js +110 -0
  730. package/dist/model/time.js.map +1 -0
  731. package/dist/model/types.d.ts +1329 -0
  732. package/dist/model/types.d.ts.map +1 -0
  733. package/dist/model/types.js +424 -0
  734. package/dist/model/types.js.map +1 -0
  735. package/dist/model/values.d.ts +91 -0
  736. package/dist/model/values.d.ts.map +1 -0
  737. package/dist/model/values.js +195 -0
  738. package/dist/model/values.js.map +1 -0
  739. package/dist/model/wire.d.ts +356 -0
  740. package/dist/model/wire.d.ts.map +1 -0
  741. package/dist/model/wire.js +1504 -0
  742. package/dist/model/wire.js.map +1 -0
  743. package/dist/offline/index.d.ts +374 -0
  744. package/dist/offline/index.d.ts.map +1 -0
  745. package/dist/offline/index.js +422 -0
  746. package/dist/offline/index.js.map +1 -0
  747. package/dist/testing.d.ts +30 -0
  748. package/dist/testing.d.ts.map +1 -0
  749. package/dist/testing.js +42 -0
  750. package/dist/testing.js.map +1 -0
  751. package/dist/version.d.ts +30 -0
  752. package/dist/version.d.ts.map +1 -0
  753. package/dist/version.js +116 -0
  754. package/dist/version.js.map +1 -0
  755. package/package.json +98 -3
@@ -0,0 +1,230 @@
1
+ import { AxiomError } from '../model/errors.js';
2
+ import { PLAIN_DATE_PATTERN } from '../model/types.js';
3
+ const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
4
+ const DAYS_PER_ERA = 146097;
5
+ const DAYS_PER_CYCLE = 1460;
6
+ const DAYS_PER_CENTURY = 36524;
7
+ const LAST_DAY_OF_ERA = 146096;
8
+ /** True for a Gregorian leap year. */
9
+ export function isLeapYear(year) {
10
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
11
+ }
12
+ /** The number of days in a civil month. */
13
+ export function daysInMonth(year, month) {
14
+ if (month === 2 && isLeapYear(year))
15
+ return 29;
16
+ return DAYS_IN_MONTH[month - 1] ?? 0;
17
+ }
18
+ /**
19
+ * Days since 1970-01-01 for a civil date — Howard Hinnant's `days_from_civil`.
20
+ * The inverse of `civilFromDays`, and the primitive every other operation uses.
21
+ */
22
+ export function daysFromCivil(year, month, day) {
23
+ const shiftedYear = year - (month <= 2 ? 1 : 0);
24
+ const era = Math.floor(shiftedYear / 400);
25
+ const yearOfEra = shiftedYear - era * 400;
26
+ const dayOfYear = Math.trunc((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;
27
+ const dayOfEra = yearOfEra * 365 + Math.trunc(yearOfEra / 4) - Math.trunc(yearOfEra / 100) + dayOfYear;
28
+ return era * DAYS_PER_ERA + dayOfEra - 719468;
29
+ }
30
+ /** The civil date `days` days after 1970-01-01 — Howard Hinnant's `civil_from_days`. */
31
+ export function civilFromDays(days) {
32
+ const shifted = days + 719468;
33
+ const era = Math.floor(shifted / DAYS_PER_ERA);
34
+ const dayOfEra = shifted - era * DAYS_PER_ERA;
35
+ const yearOfEra = Math.trunc((dayOfEra -
36
+ Math.trunc(dayOfEra / DAYS_PER_CYCLE) +
37
+ Math.trunc(dayOfEra / DAYS_PER_CENTURY) -
38
+ Math.trunc(dayOfEra / LAST_DAY_OF_ERA)) /
39
+ 365);
40
+ const year = yearOfEra + era * 400;
41
+ const dayOfYear = dayOfEra - (365 * yearOfEra + Math.trunc(yearOfEra / 4) - Math.trunc(yearOfEra / 100));
42
+ const monthPrime = Math.trunc((5 * dayOfYear + 2) / 153);
43
+ const day = dayOfYear - Math.trunc((153 * monthPrime + 2) / 5) + 1;
44
+ const month = monthPrime + (monthPrime < 10 ? 3 : -9);
45
+ return { year: year + (month <= 2 ? 1 : 0), month, day };
46
+ }
47
+ /**
48
+ * Parses `YYYY-MM-DD`. An impossible date such as `2026-02-30` is refused rather than
49
+ * normalised into a neighbouring day.
50
+ *
51
+ * The refusal repeats the text because its caller is an author — a document's `recordDate`, a
52
+ * literal in an expression, a table's window bound — reading a diagnostic about a value they
53
+ * wrote. A value a person *submitted* is a different caller: `parseWirePlainDate` is that door.
54
+ */
55
+ export function parsePlainDate(text, path = '') {
56
+ const match = PLAIN_DATE_PATTERN.exec(text);
57
+ if (match === null) {
58
+ throw new AxiomError('ENGINE_ERROR', `not a plain date: ${text}`, path, 'not a plain date');
59
+ }
60
+ const date = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };
61
+ assertCivilDate(date, path);
62
+ return date;
63
+ }
64
+ /**
65
+ * The wire reader's civil-date parser: the same grammar and the same calendar rules as
66
+ * `parsePlainDate`, with a refusal that never repeats the submitted text.
67
+ *
68
+ * Every date a record supplies — a `date` field, a `timeslot.localDate` — is read through here,
69
+ * so the refusal a host relays as a 400 (or logs) names the seat and the cause and never the
70
+ * value. A `date` declaration can carry a personal fact (a date of birth, a review date), and a
71
+ * `write_only` one is a value the artifact has decided this caller may not read. The reason the
72
+ * text is omitted is the reason `asWireDecimalString` states for decimals: the path already says
73
+ * where the value came from, so quoting it adds nothing an operator can act on and everything a
74
+ * hidden field must not disclose.
75
+ *
76
+ * An impossible date is refused by naming the component that is wrong rather than the date,
77
+ * because for a well-formed spelling the rendered date *is* the submitted value.
78
+ */
79
+ export function parseWirePlainDate(text, path) {
80
+ const match = PLAIN_DATE_PATTERN.exec(text);
81
+ if (match === null) {
82
+ throw new AxiomError('ENGINE_ERROR', 'not a plain date', path);
83
+ }
84
+ const date = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };
85
+ const problem = civilDateProblem(date);
86
+ if (problem !== undefined) {
87
+ throw new AxiomError('ENGINE_ERROR', `not a civil date: the ${problem} is outside the calendar`, path);
88
+ }
89
+ return date;
90
+ }
91
+ /**
92
+ * The civil date `YYYY-MM-DD` names, or `undefined` when the text is not one.
93
+ *
94
+ * The grammar and the calendar check are the same ones `parsePlainDate` applies, but the answer
95
+ * is a returned value rather than a throw: a renderer that offers a text entry must refuse an
96
+ * impossible day without treating the reader's spelling as a programmer error. A caller that
97
+ * needs the diagnostic keeps `parsePlainDate`; a caller that only needs the decision reads this.
98
+ */
99
+ export function tryParsePlainDate(text) {
100
+ const match = PLAIN_DATE_PATTERN.exec(text);
101
+ if (match === null)
102
+ return undefined;
103
+ const date = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };
104
+ return civilDateProblem(date) === undefined ? date : undefined;
105
+ }
106
+ /**
107
+ * A civil date the wire can spell: four-digit years only and a day that
108
+ * exists in its month. The whole date is checked, not only its year, so the renderer and
109
+ * the parser accept exactly the same set: the engine never reports a date it cannot read
110
+ * back, and a host cannot persist `2026-13-40` because a computation produced one.
111
+ */
112
+ const MIN_YEAR = 0;
113
+ const MAX_YEAR = 9999;
114
+ /** Which component of a civil date no calendar can carry, or `undefined` when all are legal. */
115
+ function civilDateProblem(date) {
116
+ const { year, month, day } = date;
117
+ if (!Number.isInteger(year) || year < MIN_YEAR || year > MAX_YEAR)
118
+ return 'year';
119
+ if (!Number.isInteger(month) || month < 1 || month > 12)
120
+ return 'month';
121
+ if (!Number.isInteger(day) || day < 1 || day > daysInMonth(year, month))
122
+ return 'day';
123
+ return undefined;
124
+ }
125
+ /** Refuses a date no `YYYY-MM-DD` spelling can carry, as `parsePlainDate` refuses it. */
126
+ export function assertCivilDate(date, path = '') {
127
+ const { year, month, day } = date;
128
+ if (!Number.isInteger(year) || year < MIN_YEAR || year > MAX_YEAR) {
129
+ throw new AxiomError('ENGINE_ERROR', `civil date year ${String(year)} is outside ${String(MIN_YEAR)}..${String(MAX_YEAR)}`, path);
130
+ }
131
+ if (!Number.isInteger(month) || month < 1 || month > 12) {
132
+ throw new AxiomError('ENGINE_ERROR', `not a civil date: month ${String(month)}`, path);
133
+ }
134
+ if (!Number.isInteger(day) || day < 1 || day > daysInMonth(year, month)) {
135
+ throw new AxiomError('ENGINE_ERROR', `not a civil date: ${formatUnchecked(date)}`, path);
136
+ }
137
+ }
138
+ /** `YYYY-MM-DD` for a date the caller has already validated. */
139
+ function formatUnchecked(date) {
140
+ const year = String(date.year).padStart(4, '0');
141
+ const month = String(date.month).padStart(2, '0');
142
+ const day = String(date.day).padStart(2, '0');
143
+ return `${year}-${month}-${day}`;
144
+ }
145
+ /** Renders a civil date as `YYYY-MM-DD`; every date it emits `parsePlainDate` accepts. */
146
+ export function formatPlainDate(date, path = '') {
147
+ assertCivilDate(date, path);
148
+ return formatUnchecked(date);
149
+ }
150
+ /** Shifts a civil date by whole days. */
151
+ export function addDays(date, days, path = '') {
152
+ if (!Number.isInteger(days)) {
153
+ throw new AxiomError('ENGINE_ERROR', 'add_days requires a whole number of days', path);
154
+ }
155
+ const shifted = civilFromDays(daysFromCivil(date.year, date.month, date.day) + days);
156
+ assertCivilDate(shifted, path);
157
+ return shifted;
158
+ }
159
+ /**
160
+ * Shifts a civil date by whole months, clamping to the last day of the target month
161
+ * `2026-01-31` plus one month is `2026-02-28`.
162
+ */
163
+ export function addMonths(date, months, path = '') {
164
+ if (!Number.isInteger(months)) {
165
+ throw new AxiomError('ENGINE_ERROR', 'add_months requires a whole number of months', path);
166
+ }
167
+ const monthIndex = date.year * 12 + (date.month - 1) + months;
168
+ const year = Math.floor(monthIndex / 12);
169
+ const month = monthIndex - year * 12 + 1;
170
+ const shifted = { year, month, day: Math.min(date.day, daysInMonth(year, month)) };
171
+ assertCivilDate(shifted, path);
172
+ return shifted;
173
+ }
174
+ /** Signed whole days from `a` to `b`. */
175
+ export function daysBetween(a, b) {
176
+ return daysFromCivil(b.year, b.month, b.day) - daysFromCivil(a.year, a.month, a.day);
177
+ }
178
+ /**
179
+ * Signed whole months from `a` to `b`, truncated toward zero (`EXPR-13.1.4`). A month is
180
+ * completed when shifting `a` by it, with the clamping `addMonths` applies, lands on or
181
+ * before `b`: `2026-01-31` to `2026-02-28` is one month because `addMonths` clamps
182
+ * Jan 31 + 1 month to Feb 28, while `2026-01-31` to `2026-02-27` is zero.
183
+ *
184
+ * This is the language's rule, not `Temporal.PlainDate.until`'s: `until` compares the day of
185
+ * the month and reports Feb 28 as an unfinished month, so the two disagree exactly when the
186
+ * start day exceeds the target month's length and the end day is that last day.
187
+ */
188
+ export function monthsBetween(a, b) {
189
+ const forward = daysBetween(a, b) > 0;
190
+ const from = forward ? a : b;
191
+ const to = forward ? b : a;
192
+ let months = (to.year - from.year) * 12 + (to.month - from.month);
193
+ if (months !== 0) {
194
+ // The day `addMonths(from, months)` lands on: the start day, clamped by the target
195
+ // month. Comparing against that value is what counts a clamped month as whole.
196
+ const landingDay = Math.min(from.day, daysInMonth(to.year, to.month));
197
+ if (to.day < landingDay)
198
+ months -= 1;
199
+ }
200
+ // A zero count is `0` for a reversed pair too: canonical JSON has no `-0`.
201
+ if (months === 0)
202
+ return 0;
203
+ return forward ? months : -months;
204
+ }
205
+ /**
206
+ * `add_years(d, n)`: `d` shifted by `n` whole years, clamping 29 February to 28 February in a
207
+ * non-leap target year (`EXPR-13.1.9`).
208
+ *
209
+ * The clamp is the rule `add_months` already states, applied to one year rather than to twelve
210
+ * months: `2024-02-29` plus one year is `2025-02-28`, and plus four is `2028-02-29`. It is
211
+ * written year-first rather than as `add_months(d, n * 12)` so a large `n` cannot overflow the
212
+ * month count before the year range refuses it.
213
+ */
214
+ export function addYears(date, years, path = '') {
215
+ if (!Number.isInteger(years)) {
216
+ throw new AxiomError('ENGINE_ERROR', 'add_years requires a whole number of years', path);
217
+ }
218
+ const target = date.year + years;
219
+ // A shift a four-digit year cannot state is refused before the calendar is consulted, so a
220
+ // value far outside the range reports the year rather than a month.
221
+ assertCivilDate({ year: target, month: date.month, day: 1 }, path);
222
+ const shifted = {
223
+ year: target,
224
+ month: date.month,
225
+ day: Math.min(date.day, daysInMonth(target, date.month)),
226
+ };
227
+ assertCivilDate(shifted, path);
228
+ return shifted;
229
+ }
230
+ //# sourceMappingURL=plain-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plain-date.js","sourceRoot":"","sources":["../../src/expr/plain-date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAavD,MAAM,aAAa,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAU,CAAC;AAEhF,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,sCAAsC;AACtC,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,IAAI,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC;AAClE,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAa;IACrD,IAAI,KAAK,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAC/C,OAAO,aAAa,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IACpE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC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I,UAAU,CAAC,cAAc,EAAE,4CAA4C,EAAE,IAAI,CAAC,CAAC;IAC3F,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACjC,2FAA2F;IAC3F,oEAAoE;IACpE,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;KACzD,CAAC;IACF,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/B,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { AxiomError } from '../model/errors.js';\nimport { PLAIN_DATE_PATTERN } from '../model/types.js';\n\n/**\n * A civil date with no time and no zone, `spec/semantics/model-v1.md`.\n * Arithmetic here is proleptic Gregorian and depends on no time zone and no locale\n * database, so no host `Intl` data can change it.\n */\nexport interface PlainDate {\n readonly year: number;\n readonly month: number;\n readonly day: number;\n}\n\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] as const;\n\nconst DAYS_PER_ERA = 146097;\nconst DAYS_PER_CYCLE = 1460;\nconst DAYS_PER_CENTURY = 36524;\nconst LAST_DAY_OF_ERA = 146096;\n\n/** True for a Gregorian leap year. */\nexport function isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\n/** The number of days in a civil month. */\nexport function daysInMonth(year: number, month: number): number {\n if (month === 2 && isLeapYear(year)) return 29;\n return DAYS_IN_MONTH[month - 1] ?? 0;\n}\n\n/**\n * Days since 1970-01-01 for a civil date — Howard Hinnant's `days_from_civil`.\n * The inverse of `civilFromDays`, and the primitive every other operation uses.\n */\nexport function daysFromCivil(year: number, month: number, day: number): number {\n const shiftedYear = year - (month <= 2 ? 1 : 0);\n const era = Math.floor(shiftedYear / 400);\n const yearOfEra = shiftedYear - era * 400;\n const dayOfYear = Math.trunc((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;\n const dayOfEra =\n yearOfEra * 365 + Math.trunc(yearOfEra / 4) - Math.trunc(yearOfEra / 100) + dayOfYear;\n return era * DAYS_PER_ERA + dayOfEra - 719468;\n}\n\n/** The civil date `days` days after 1970-01-01 — Howard Hinnant's `civil_from_days`. */\nexport function civilFromDays(days: number): PlainDate {\n const shifted = days + 719468;\n const era = Math.floor(shifted / DAYS_PER_ERA);\n const dayOfEra = shifted - era * DAYS_PER_ERA;\n const yearOfEra = Math.trunc(\n (dayOfEra -\n Math.trunc(dayOfEra / DAYS_PER_CYCLE) +\n Math.trunc(dayOfEra / DAYS_PER_CENTURY) -\n Math.trunc(dayOfEra / LAST_DAY_OF_ERA)) /\n 365,\n );\n const year = yearOfEra + era * 400;\n const dayOfYear =\n dayOfEra - (365 * yearOfEra + Math.trunc(yearOfEra / 4) - Math.trunc(yearOfEra / 100));\n const monthPrime = Math.trunc((5 * dayOfYear + 2) / 153);\n const day = dayOfYear - Math.trunc((153 * monthPrime + 2) / 5) + 1;\n const month = monthPrime + (monthPrime < 10 ? 3 : -9);\n return { year: year + (month <= 2 ? 1 : 0), month, day };\n}\n\n/**\n * Parses `YYYY-MM-DD`. An impossible date such as `2026-02-30` is refused rather than\n * normalised into a neighbouring day.\n *\n * The refusal repeats the text because its caller is an author — a document's `recordDate`, a\n * literal in an expression, a table's window bound — reading a diagnostic about a value they\n * wrote. A value a person *submitted* is a different caller: `parseWirePlainDate` is that door.\n */\nexport function parsePlainDate(text: string, path = ''): PlainDate {\n const match = PLAIN_DATE_PATTERN.exec(text);\n if (match === null) {\n throw new AxiomError('ENGINE_ERROR', `not a plain date: ${text}`, path, 'not a plain date');\n }\n const date = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };\n assertCivilDate(date, path);\n return date;\n}\n\n/**\n * The wire reader's civil-date parser: the same grammar and the same calendar rules as\n * `parsePlainDate`, with a refusal that never repeats the submitted text.\n *\n * Every date a record supplies — a `date` field, a `timeslot.localDate` — is read through here,\n * so the refusal a host relays as a 400 (or logs) names the seat and the cause and never the\n * value. A `date` declaration can carry a personal fact (a date of birth, a review date), and a\n * `write_only` one is a value the artifact has decided this caller may not read. The reason the\n * text is omitted is the reason `asWireDecimalString` states for decimals: the path already says\n * where the value came from, so quoting it adds nothing an operator can act on and everything a\n * hidden field must not disclose.\n *\n * An impossible date is refused by naming the component that is wrong rather than the date,\n * because for a well-formed spelling the rendered date *is* the submitted value.\n */\nexport function parseWirePlainDate(text: string, path: string): PlainDate {\n const match = PLAIN_DATE_PATTERN.exec(text);\n if (match === null) {\n throw new AxiomError('ENGINE_ERROR', 'not a plain date', path);\n }\n const date = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };\n const problem = civilDateProblem(date);\n if (problem !== undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `not a civil date: the ${problem} is outside the calendar`,\n path,\n );\n }\n return date;\n}\n\n/**\n * The civil date `YYYY-MM-DD` names, or `undefined` when the text is not one.\n *\n * The grammar and the calendar check are the same ones `parsePlainDate` applies, but the answer\n * is a returned value rather than a throw: a renderer that offers a text entry must refuse an\n * impossible day without treating the reader's spelling as a programmer error. A caller that\n * needs the diagnostic keeps `parsePlainDate`; a caller that only needs the decision reads this.\n */\nexport function tryParsePlainDate(text: string): PlainDate | undefined {\n const match = PLAIN_DATE_PATTERN.exec(text);\n if (match === null) return undefined;\n const date = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };\n return civilDateProblem(date) === undefined ? date : undefined;\n}\n\n/**\n * A civil date the wire can spell: four-digit years only and a day that\n * exists in its month. The whole date is checked, not only its year, so the renderer and\n * the parser accept exactly the same set: the engine never reports a date it cannot read\n * back, and a host cannot persist `2026-13-40` because a computation produced one.\n */\nconst MIN_YEAR = 0;\nconst MAX_YEAR = 9999;\n\n/** Which component of a civil date no calendar can carry, or `undefined` when all are legal. */\nfunction civilDateProblem(date: PlainDate): 'year' | 'month' | 'day' | undefined {\n const { year, month, day } = date;\n if (!Number.isInteger(year) || year < MIN_YEAR || year > MAX_YEAR) return 'year';\n if (!Number.isInteger(month) || month < 1 || month > 12) return 'month';\n if (!Number.isInteger(day) || day < 1 || day > daysInMonth(year, month)) return 'day';\n return undefined;\n}\n\n/** Refuses a date no `YYYY-MM-DD` spelling can carry, as `parsePlainDate` refuses it. */\nexport function assertCivilDate(date: PlainDate, path = ''): void {\n const { year, month, day } = date;\n if (!Number.isInteger(year) || year < MIN_YEAR || year > MAX_YEAR) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `civil date year ${String(year)} is outside ${String(MIN_YEAR)}..${String(MAX_YEAR)}`,\n path,\n );\n }\n if (!Number.isInteger(month) || month < 1 || month > 12) {\n throw new AxiomError('ENGINE_ERROR', `not a civil date: month ${String(month)}`, path);\n }\n if (!Number.isInteger(day) || day < 1 || day > daysInMonth(year, month)) {\n throw new AxiomError('ENGINE_ERROR', `not a civil date: ${formatUnchecked(date)}`, path);\n }\n}\n\n/** `YYYY-MM-DD` for a date the caller has already validated. */\nfunction formatUnchecked(date: PlainDate): string {\n const year = String(date.year).padStart(4, '0');\n const month = String(date.month).padStart(2, '0');\n const day = String(date.day).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\n/** Renders a civil date as `YYYY-MM-DD`; every date it emits `parsePlainDate` accepts. */\nexport function formatPlainDate(date: PlainDate, path = ''): string {\n assertCivilDate(date, path);\n return formatUnchecked(date);\n}\n\n/** Shifts a civil date by whole days. */\nexport function addDays(date: PlainDate, days: number, path = ''): PlainDate {\n if (!Number.isInteger(days)) {\n throw new AxiomError('ENGINE_ERROR', 'add_days requires a whole number of days', path);\n }\n const shifted = civilFromDays(daysFromCivil(date.year, date.month, date.day) + days);\n assertCivilDate(shifted, path);\n return shifted;\n}\n\n/**\n * Shifts a civil date by whole months, clamping to the last day of the target month\n * `2026-01-31` plus one month is `2026-02-28`.\n */\nexport function addMonths(date: PlainDate, months: number, path = ''): PlainDate {\n if (!Number.isInteger(months)) {\n throw new AxiomError('ENGINE_ERROR', 'add_months requires a whole number of months', path);\n }\n const monthIndex = date.year * 12 + (date.month - 1) + months;\n const year = Math.floor(monthIndex / 12);\n const month = monthIndex - year * 12 + 1;\n const shifted = { year, month, day: Math.min(date.day, daysInMonth(year, month)) };\n assertCivilDate(shifted, path);\n return shifted;\n}\n\n/** Signed whole days from `a` to `b`. */\nexport function daysBetween(a: PlainDate, b: PlainDate): number {\n return daysFromCivil(b.year, b.month, b.day) - daysFromCivil(a.year, a.month, a.day);\n}\n\n/**\n * Signed whole months from `a` to `b`, truncated toward zero (`EXPR-13.1.4`). A month is\n * completed when shifting `a` by it, with the clamping `addMonths` applies, lands on or\n * before `b`: `2026-01-31` to `2026-02-28` is one month because `addMonths` clamps\n * Jan 31 + 1 month to Feb 28, while `2026-01-31` to `2026-02-27` is zero.\n *\n * This is the language's rule, not `Temporal.PlainDate.until`'s: `until` compares the day of\n * the month and reports Feb 28 as an unfinished month, so the two disagree exactly when the\n * start day exceeds the target month's length and the end day is that last day.\n */\nexport function monthsBetween(a: PlainDate, b: PlainDate): number {\n const forward = daysBetween(a, b) > 0;\n const from = forward ? a : b;\n const to = forward ? b : a;\n let months = (to.year - from.year) * 12 + (to.month - from.month);\n if (months !== 0) {\n // The day `addMonths(from, months)` lands on: the start day, clamped by the target\n // month. Comparing against that value is what counts a clamped month as whole.\n const landingDay = Math.min(from.day, daysInMonth(to.year, to.month));\n if (to.day < landingDay) months -= 1;\n }\n // A zero count is `0` for a reversed pair too: canonical JSON has no `-0`.\n if (months === 0) return 0;\n return forward ? months : -months;\n}\n\n/**\n * `add_years(d, n)`: `d` shifted by `n` whole years, clamping 29 February to 28 February in a\n * non-leap target year (`EXPR-13.1.9`).\n *\n * The clamp is the rule `add_months` already states, applied to one year rather than to twelve\n * months: `2024-02-29` plus one year is `2025-02-28`, and plus four is `2028-02-29`. It is\n * written year-first rather than as `add_months(d, n * 12)` so a large `n` cannot overflow the\n * month count before the year range refuses it.\n */\nexport function addYears(date: PlainDate, years: number, path = ''): PlainDate {\n if (!Number.isInteger(years)) {\n throw new AxiomError('ENGINE_ERROR', 'add_years requires a whole number of years', path);\n }\n const target = date.year + years;\n // A shift a four-digit year cannot state is refused before the calendar is consulted, so a\n // value far outside the range reports the year rather than a month.\n assertCivilDate({ year: target, month: date.month, day: 1 }, path);\n const shifted = {\n year: target,\n month: date.month,\n day: Math.min(date.day, daysInMonth(target, date.month)),\n };\n assertCivilDate(shifted, path);\n return shifted;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { PluralCategory } from './plural.js';
2
+ /**
3
+ * The cardinal categories `locale` distinguishes, from the registry the renderer reads. The
4
+ * compiler checks a plural branch against this set at publish time, so a branch no
5
+ * locale can ever select is refused rather than kept as dead message text.
6
+ */
7
+ export declare function cardinalCategories(locale: string): readonly PluralCategory[];
8
+ //# sourceMappingURL=plural-categories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural-categories.d.ts","sourceRoot":"","sources":["../../src/expr/plural-categories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAyBlD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAI5E"}
@@ -0,0 +1,15 @@
1
+ import * as pluralCategoryLists from 'make-plural/pluralCategories';
2
+ import { resolveLocaleEntry, unresolvedLocale } from './plural-keys.js';
3
+ const CARDINAL_CATEGORIES = pluralCategoryLists;
4
+ /**
5
+ * The cardinal categories `locale` distinguishes, from the registry the renderer reads. The
6
+ * compiler checks a plural branch against this set at publish time, so a branch no
7
+ * locale can ever select is refused rather than kept as dead message text.
8
+ */
9
+ export function cardinalCategories(locale) {
10
+ const resolved = resolveLocaleEntry(CARDINAL_CATEGORIES, locale);
11
+ if (resolved === undefined)
12
+ throw unresolvedLocale(locale);
13
+ return resolved.entry.cardinal;
14
+ }
15
+ //# sourceMappingURL=plural-categories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural-categories.js","sourceRoot":"","sources":["../../src/expr/plural-categories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,mBAAmB,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAwBxE,MAAM,mBAAmB,GAA4C,mBAAmB,CAAC;AAEzF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IACjE,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;AACjC,CAAC","sourcesContent":["import * as pluralCategoryLists from 'make-plural/pluralCategories';\nimport { resolveLocaleEntry, unresolvedLocale } from './plural-keys.js';\nimport type { PluralCategory } from './plural.js';\n\n/**\n * The cardinal category lists, the compiler half of the CLDR contract.\n *\n * The lists come from the same pinned `cldr-core` release as the rules the device renders\n * with, which is what lets a branch be refused at publish time against the categories that\n * will actually select it. They are a separate entry from `./plural.js` because only the\n * compiler reads them: a device bundle that renders messages must not carry ~1.8 KB of lists\n * it never calls, and a module that imports them beside the rules keeps a namespace import\n * from being tree-shaken away.\n *\n * A locale resolves through the same key helper as the rules, so both sides answer for the\n * same locale; `packages/runtime/src/__tests__/messages.test.ts` holds the two registries to\n * identical keys and to agreement between each locale's list and the categories its rule can\n * return, so a branch the compiler admits is a branch the renderer can select.\n */\n\n/** One locale's category lists, reduced to the cardinal list this product selects on. */\ninterface CategoryLists {\n readonly cardinal: readonly PluralCategory[];\n}\n\nconst CARDINAL_CATEGORIES: Readonly<Record<string, CategoryLists>> = pluralCategoryLists;\n\n/**\n * The cardinal categories `locale` distinguishes, from the registry the renderer reads. The\n * compiler checks a plural branch against this set at publish time, so a branch no\n * locale can ever select is refused rather than kept as dead message text.\n */\nexport function cardinalCategories(locale: string): readonly PluralCategory[] {\n const resolved = resolveLocaleEntry(CARDINAL_CATEGORIES, locale);\n if (resolved === undefined) throw unresolvedLocale(locale);\n return resolved.entry.cardinal;\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { AxiomError } from '../model/errors.js';
2
+ /**
3
+ * Locale-key resolution shared by the two `make-plural` registries the product reads.
4
+ *
5
+ * A CLDR entry is addressed by the registry's own spelling (`pt_PT`), which is not the
6
+ * spelling a document uses (`pt-PT`). Both readers resolve through this module so the
7
+ * device's rules and the compiler's category lists answer for the same locale, and so a
8
+ * tag that a rule resolves to is the identity the rule cache is keyed by.
9
+ */
10
+ /**
11
+ * The keys `locale` is looked up under, most specific first: the full tag as the registry
12
+ * spells it, then the language subtag. A tag with no entry of its own (`en-AU`) still
13
+ * resolves to its language.
14
+ */
15
+ export declare function localeKeys(locale: string): readonly string[];
16
+ /** One registry entry, beside the key it was found under. */
17
+ export interface ResolvedLocale<Entry> {
18
+ /** The key the entry was found under, which is the bounded identity of that entry. */
19
+ readonly key: string;
20
+ readonly entry: Entry;
21
+ }
22
+ /**
23
+ * The first entry `locale` resolves to, or `undefined` when the registry carries none.
24
+ *
25
+ * The read is behind `Object.hasOwn` because the two shapes a registry arrives in disagree:
26
+ * Node hands a module namespace, whose prototype is null, while a bundler inlines the same
27
+ * module into an object literal that carries `Object.prototype`. Without the guard, a host
28
+ * that passes `toString` as a locale resolves to an inherited member in the bundled build
29
+ * and to nothing in Node — so one target refuses the locale and the other renders a branch
30
+ * the registry never named.
31
+ */
32
+ export declare function resolveLocaleEntry<Entry>(registry: Readonly<Record<string, Entry>>, locale: string): ResolvedLocale<Entry> | undefined;
33
+ /**
34
+ * The refusal both registries report for a locale neither carries. A declared locale must
35
+ * name a CLDR locale, and the compiler turns this text into the diagnostic that says so,
36
+ * so it is stated once rather than per registry.
37
+ */
38
+ export declare function unresolvedLocale(locale: string): AxiomError;
39
+ //# sourceMappingURL=plural-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural-keys.d.ts","sourceRoot":"","sources":["../../src/expr/plural-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;GAOG;AAEH;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAI5D;AAED,6DAA6D;AAC7D,MAAM,WAAW,cAAc,CAAC,KAAK;IACnC,sFAAsF;IACtF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EACtC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EACzC,MAAM,EAAE,MAAM,GACb,cAAc,CAAC,KAAK,CAAC,GAAG,SAAS,CAMnC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAK3D"}
@@ -0,0 +1,46 @@
1
+ import { AxiomError } from '../model/errors.js';
2
+ /**
3
+ * Locale-key resolution shared by the two `make-plural` registries the product reads.
4
+ *
5
+ * A CLDR entry is addressed by the registry's own spelling (`pt_PT`), which is not the
6
+ * spelling a document uses (`pt-PT`). Both readers resolve through this module so the
7
+ * device's rules and the compiler's category lists answer for the same locale, and so a
8
+ * tag that a rule resolves to is the identity the rule cache is keyed by.
9
+ */
10
+ /**
11
+ * The keys `locale` is looked up under, most specific first: the full tag as the registry
12
+ * spells it, then the language subtag. A tag with no entry of its own (`en-AU`) still
13
+ * resolves to its language.
14
+ */
15
+ export function localeKeys(locale) {
16
+ const tag = locale.replaceAll('-', '_');
17
+ const separator = tag.indexOf('_');
18
+ return separator === -1 ? [tag] : [tag, tag.slice(0, separator)];
19
+ }
20
+ /**
21
+ * The first entry `locale` resolves to, or `undefined` when the registry carries none.
22
+ *
23
+ * The read is behind `Object.hasOwn` because the two shapes a registry arrives in disagree:
24
+ * Node hands a module namespace, whose prototype is null, while a bundler inlines the same
25
+ * module into an object literal that carries `Object.prototype`. Without the guard, a host
26
+ * that passes `toString` as a locale resolves to an inherited member in the bundled build
27
+ * and to nothing in Node — so one target refuses the locale and the other renders a branch
28
+ * the registry never named.
29
+ */
30
+ export function resolveLocaleEntry(registry, locale) {
31
+ for (const key of localeKeys(locale)) {
32
+ const entry = Object.hasOwn(registry, key) ? registry[key] : undefined;
33
+ if (entry !== undefined)
34
+ return { key, entry };
35
+ }
36
+ return undefined;
37
+ }
38
+ /**
39
+ * The refusal both registries report for a locale neither carries. A declared locale must
40
+ * name a CLDR locale, and the compiler turns this text into the diagnostic that says so,
41
+ * so it is stated once rather than per registry.
42
+ */
43
+ export function unresolvedLocale(locale) {
44
+ return new AxiomError('ENGINE_ERROR', `no CLDR plural rules for locale ${locale}; a declared locale must be one the CLDR cardinal registry carries`);
45
+ }
46
+ //# sourceMappingURL=plural-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural-keys.js","sourceRoot":"","sources":["../../src/expr/plural-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;AACnE,CAAC;AASD;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAyC,EACzC,MAAc;IAEd,KAAK,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,IAAI,UAAU,CACnB,cAAc,EACd,mCAAmC,MAAM,oEAAoE,CAC9G,CAAC;AACJ,CAAC","sourcesContent":["import { AxiomError } from '../model/errors.js';\n\n/**\n * Locale-key resolution shared by the two `make-plural` registries the product reads.\n *\n * A CLDR entry is addressed by the registry's own spelling (`pt_PT`), which is not the\n * spelling a document uses (`pt-PT`). Both readers resolve through this module so the\n * device's rules and the compiler's category lists answer for the same locale, and so a\n * tag that a rule resolves to is the identity the rule cache is keyed by.\n */\n\n/**\n * The keys `locale` is looked up under, most specific first: the full tag as the registry\n * spells it, then the language subtag. A tag with no entry of its own (`en-AU`) still\n * resolves to its language.\n */\nexport function localeKeys(locale: string): readonly string[] {\n const tag = locale.replaceAll('-', '_');\n const separator = tag.indexOf('_');\n return separator === -1 ? [tag] : [tag, tag.slice(0, separator)];\n}\n\n/** One registry entry, beside the key it was found under. */\nexport interface ResolvedLocale<Entry> {\n /** The key the entry was found under, which is the bounded identity of that entry. */\n readonly key: string;\n readonly entry: Entry;\n}\n\n/**\n * The first entry `locale` resolves to, or `undefined` when the registry carries none.\n *\n * The read is behind `Object.hasOwn` because the two shapes a registry arrives in disagree:\n * Node hands a module namespace, whose prototype is null, while a bundler inlines the same\n * module into an object literal that carries `Object.prototype`. Without the guard, a host\n * that passes `toString` as a locale resolves to an inherited member in the bundled build\n * and to nothing in Node — so one target refuses the locale and the other renders a branch\n * the registry never named.\n */\nexport function resolveLocaleEntry<Entry>(\n registry: Readonly<Record<string, Entry>>,\n locale: string,\n): ResolvedLocale<Entry> | undefined {\n for (const key of localeKeys(locale)) {\n const entry = Object.hasOwn(registry, key) ? registry[key] : undefined;\n if (entry !== undefined) return { key, entry };\n }\n return undefined;\n}\n\n/**\n * The refusal both registries report for a locale neither carries. A declared locale must\n * name a CLDR locale, and the compiler turns this text into the diagnostic that says so,\n * so it is stated once rather than per registry.\n */\nexport function unresolvedLocale(locale: string): AxiomError {\n return new AxiomError(\n 'ENGINE_ERROR',\n `no CLDR plural rules for locale ${locale}; a declared locale must be one the CLDR cardinal registry carries`,\n );\n}\n"]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Cardinal plural selection, the device half of the CLDR contract.
3
+ *
4
+ * The vendored CLDR registry is the contract, and the only source: a document must render the
5
+ * same text on every host, and a device's ICU data changes with its OS. `make-plural` is
6
+ * generated from a pinned `cldr-core` release and shipped with the runtime, so a platform
7
+ * upgrade cannot change a message. `pt-PT` is resolved before `pt`, because CLDR gives them
8
+ * different rules.
9
+ *
10
+ * Only the rules are imported here. The category lists — which the compiler reads to refuse a
11
+ * branch no locale can select — live on `./plural-categories.js` and reach the device only
12
+ * through the compiler-facing subpath, so a bundle that renders messages never carries them.
13
+ *
14
+ * There is no platform call. `Intl.PluralRules` is absent on Hermes, its CLDR data is the
15
+ * device's rather than the artifact's, and measured on V8 a verified platform path is slower
16
+ * than reading the registry — so a second authority would buy nothing and cost determinism.
17
+ *
18
+ * A count reaches the rule as its magnitude, because CLDR defines the operand its rules read as
19
+ * the absolute value of the source number (`n` in UTS #35 Part 3), and a rule that takes the
20
+ * sign from the text it is handed would answer for a question CLDR never asks. The text is
21
+ * passed through otherwise, so the rule sees the visible fraction digits (`pl` puts `1` in
22
+ * `one` and `1.0` in `other`).
23
+ */
24
+ /** A CLDR cardinal plural category. */
25
+ export type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
26
+ /**
27
+ * The cardinal category for `count` in `locale`.
28
+ *
29
+ * The vendored rule answers every count: integer, decimal, or an integer wider than 2^53, which
30
+ * a platform call would have to round.
31
+ */
32
+ export declare function cardinalCategory(locale: string, count: string | number): PluralCategory;
33
+ //# sourceMappingURL=plural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../src/expr/plural.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,uCAAuC;AACvC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AA0C/E;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAEvF"}
@@ -0,0 +1,50 @@
1
+ import * as pluralRules from 'make-plural/cardinals';
2
+ import { resolveLocaleEntry, unresolvedLocale } from './plural-keys.js';
3
+ /** Every CLDR cardinal rule `make-plural` carries, keyed as that package spells a locale. */
4
+ const CARDINALS = pluralRules;
5
+ /**
6
+ * Bounded cache of resolved rules keyed by the caller's tag.
7
+ *
8
+ * Checking the cache before `resolveLocaleEntry` avoids per-call string replacement and registry
9
+ * lookup on hot paths, while the cap keeps a host that forwards arbitrary tags (`en-001`,
10
+ * `en-002`, ...) from growing the map without bound. Unresolved tags throw and are never stored.
11
+ */
12
+ const MAX_CACHED_LOCALES = 256;
13
+ const LOCALE_RULES = new Map();
14
+ /** The CLDR rule for `locale`, cached by tag under a bounded capacity. */
15
+ function localeRule(locale) {
16
+ const cached = LOCALE_RULES.get(locale);
17
+ if (cached !== undefined)
18
+ return cached;
19
+ const resolved = resolveLocaleEntry(CARDINALS, locale);
20
+ if (resolved === undefined)
21
+ throw unresolvedLocale(locale);
22
+ if (LOCALE_RULES.size >= MAX_CACHED_LOCALES) {
23
+ const oldest = LOCALE_RULES.keys().next().value;
24
+ if (oldest !== undefined)
25
+ LOCALE_RULES.delete(oldest);
26
+ }
27
+ LOCALE_RULES.set(locale, resolved.entry);
28
+ return resolved.entry;
29
+ }
30
+ /**
31
+ * The count as CLDR defines the operand of its rules: the absolute value of the source number.
32
+ *
33
+ * `-1` and `1` select the same branch, and the decimal spelling is preserved (`-1.0` reaches the
34
+ * rule as `1.0`, whose visible fraction digit still decides the category).
35
+ */
36
+ function magnitudeOf(count) {
37
+ if (typeof count === 'number')
38
+ return Math.abs(count);
39
+ return count.startsWith('-') ? count.slice(1) : count;
40
+ }
41
+ /**
42
+ * The cardinal category for `count` in `locale`.
43
+ *
44
+ * The vendored rule answers every count: integer, decimal, or an integer wider than 2^53, which
45
+ * a platform call would have to round.
46
+ */
47
+ export function cardinalCategory(locale, count) {
48
+ return localeRule(locale)(magnitudeOf(count));
49
+ }
50
+ //# sourceMappingURL=plural.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural.js","sourceRoot":"","sources":["../../src/expr/plural.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA+BxE,6FAA6F;AAC7F,MAAM,SAAS,GAA2C,WAAW,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,YAAY,GAA8B,IAAI,GAAG,EAAE,CAAC;AAE1D,0EAA0E;AAC1E,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,YAAY,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAChD,IAAI,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IACD,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAsB;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,KAAsB;IACrE,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import * as pluralRules from 'make-plural/cardinals';\nimport { resolveLocaleEntry, unresolvedLocale } from './plural-keys.js';\n\n/**\n * Cardinal plural selection, the device half of the CLDR contract.\n *\n * The vendored CLDR registry is the contract, and the only source: a document must render the\n * same text on every host, and a device's ICU data changes with its OS. `make-plural` is\n * generated from a pinned `cldr-core` release and shipped with the runtime, so a platform\n * upgrade cannot change a message. `pt-PT` is resolved before `pt`, because CLDR gives them\n * different rules.\n *\n * Only the rules are imported here. The category lists — which the compiler reads to refuse a\n * branch no locale can select — live on `./plural-categories.js` and reach the device only\n * through the compiler-facing subpath, so a bundle that renders messages never carries them.\n *\n * There is no platform call. `Intl.PluralRules` is absent on Hermes, its CLDR data is the\n * device's rather than the artifact's, and measured on V8 a verified platform path is slower\n * than reading the registry — so a second authority would buy nothing and cost determinism.\n *\n * A count reaches the rule as its magnitude, because CLDR defines the operand its rules read as\n * the absolute value of the source number (`n` in UTS #35 Part 3), and a rule that takes the\n * sign from the text it is handed would answer for a question CLDR never asks. The text is\n * passed through otherwise, so the rule sees the visible fraction digits (`pl` puts `1` in\n * `one` and `1.0` in `other`).\n */\n\n/** A CLDR cardinal plural category. */\nexport type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';\n\ntype CardinalRule = (count: string | number) => PluralCategory;\n\n/** Every CLDR cardinal rule `make-plural` carries, keyed as that package spells a locale. */\nconst CARDINALS: Readonly<Record<string, CardinalRule>> = pluralRules;\n\n/**\n * Bounded cache of resolved rules keyed by the caller's tag.\n *\n * Checking the cache before `resolveLocaleEntry` avoids per-call string replacement and registry\n * lookup on hot paths, while the cap keeps a host that forwards arbitrary tags (`en-001`,\n * `en-002`, ...) from growing the map without bound. Unresolved tags throw and are never stored.\n */\nconst MAX_CACHED_LOCALES = 256;\nconst LOCALE_RULES: Map<string, CardinalRule> = new Map();\n\n/** The CLDR rule for `locale`, cached by tag under a bounded capacity. */\nfunction localeRule(locale: string): CardinalRule {\n const cached = LOCALE_RULES.get(locale);\n if (cached !== undefined) return cached;\n const resolved = resolveLocaleEntry(CARDINALS, locale);\n if (resolved === undefined) throw unresolvedLocale(locale);\n if (LOCALE_RULES.size >= MAX_CACHED_LOCALES) {\n const oldest = LOCALE_RULES.keys().next().value;\n if (oldest !== undefined) LOCALE_RULES.delete(oldest);\n }\n LOCALE_RULES.set(locale, resolved.entry);\n return resolved.entry;\n}\n\n/**\n * The count as CLDR defines the operand of its rules: the absolute value of the source number.\n *\n * `-1` and `1` select the same branch, and the decimal spelling is preserved (`-1.0` reaches the\n * rule as `1.0`, whose visible fraction digit still decides the category).\n */\nfunction magnitudeOf(count: string | number): string | number {\n if (typeof count === 'number') return Math.abs(count);\n return count.startsWith('-') ? count.slice(1) : count;\n}\n\n/**\n * The cardinal category for `count` in `locale`.\n *\n * The vendored rule answers every count: integer, decimal, or an integer wider than 2^53, which\n * a platform call would have to round.\n */\nexport function cardinalCategory(locale: string, count: string | number): PluralCategory {\n return localeRule(locale)(magnitudeOf(count));\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { DecimalString } from '../model/types.js';
2
+ /** A measured quantity: canonical decimal text and the unit it is measured in, `MODEL-2.1.21`. */
3
+ export interface QuantityLike {
4
+ readonly value: DecimalString;
5
+ readonly unit: string;
6
+ }
7
+ /**
8
+ * Reads a quantity value from a value the engine produced.
9
+ *
10
+ * The wire reader has already checked a captured value against its declaration; this reads the
11
+ * shape and the canonical spelling, so an operation on two quantities never compares a float or
12
+ * a spelling that is not canonical. It does not enforce a field's scale: a computed quantity is
13
+ * exact, and `round(q.value, …)` is the author's explicit reduction.
14
+ */
15
+ export declare function toQuantityValue(value: unknown, path?: string): QuantityLike;
16
+ /**
17
+ * Reads a quantity value from untrusted input, with the value-free refusal `asWireDecimalString`
18
+ * gives. The shape rules are `readQuantity`'s, so the wire check is not a second implementation.
19
+ */
20
+ export declare function toWireQuantityValue(value: unknown, path: string): QuantityLike;
21
+ /** The exact sum of two quantities of one unit. */
22
+ export declare function quantityAdd(left: QuantityLike, right: QuantityLike, path?: string): QuantityLike;
23
+ /** The exact difference of two quantities of one unit. */
24
+ export declare function quantitySub(left: QuantityLike, right: QuantityLike, path?: string): QuantityLike;
25
+ /** The order of two quantities of one unit; a mixed pair is refused rather than compared. */
26
+ export declare function compareQuantities(left: unknown, right: unknown, path?: string): number;
27
+ /** The zero of one unit, for `sum` over a single-unit quantity list. */
28
+ export declare function quantityZero(unit: string): QuantityLike;
29
+ /** The amount as canonical decimal text: `q.value` is the decimal and this is the same read. */
30
+ export declare function quantityAmount(quantity: QuantityLike, path?: string): DecimalString;
31
+ //# sourceMappingURL=quantity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantity.d.ts","sourceRoot":"","sources":["../../src/expr/quantity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAUvD,kGAAkG;AAClG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAgCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAK,GAAG,YAAY,CAEvE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAE9E;AAYD,mDAAmD;AACnD,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,SAAK,GAAG,YAAY,CAK5F;AAED,0DAA0D;AAC1D,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,SAAK,GAAG,YAAY,CAK5F;AAED,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,SAAK,GAAG,MAAM,CAKlF;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAEvD;AAED,gGAAgG;AAChG,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,SAAK,GAAG,aAAa,CAE/E"}
@@ -0,0 +1,83 @@
1
+ import { AxiomError } from '../model/errors.js';
2
+ import { isRecord } from '../model/guards.js';
3
+ import { UNIT_CODE_PATTERN } from '../model/types.js';
4
+ import { asDecimalString, asWireDecimalString, compareDecimalTexts, subtractDecimalTexts, sumDecimalTexts, } from './decimal.js';
5
+ /**
6
+ * The quantity shape, read once for both doors.
7
+ *
8
+ * The member set, the unit code and the canonical-decimal rule are one implementation: the
9
+ * engine's reader reaches it with the authoring decimal constructor and the wire reader with the
10
+ * value-free one, so the two cannot disagree about a shape while only one of them echoes a
11
+ * submitted value.
12
+ */
13
+ function readQuantity(value, path, readDecimal) {
14
+ if (!isRecord(value)) {
15
+ throw new AxiomError('ENGINE_ERROR', 'quantity must be an object', path);
16
+ }
17
+ const memberKeys = Object.keys(value).sort();
18
+ if (memberKeys.length !== 2 || memberKeys.join(',') !== 'unit,value') {
19
+ throw new AxiomError('ENGINE_ERROR', 'quantity must declare exactly value and unit', path);
20
+ }
21
+ const amount = value['value'];
22
+ const unit = value['unit'];
23
+ if (typeof amount !== 'string') {
24
+ throw new AxiomError('ENGINE_ERROR', 'quantity value must be canonical decimal text', path);
25
+ }
26
+ if (typeof unit !== 'string' || !UNIT_CODE_PATTERN.test(unit)) {
27
+ throw new AxiomError('ENGINE_ERROR', 'quantity unit must be a lower-case unit code', path);
28
+ }
29
+ return { value: readDecimal(amount, path), unit };
30
+ }
31
+ /**
32
+ * Reads a quantity value from a value the engine produced.
33
+ *
34
+ * The wire reader has already checked a captured value against its declaration; this reads the
35
+ * shape and the canonical spelling, so an operation on two quantities never compares a float or
36
+ * a spelling that is not canonical. It does not enforce a field's scale: a computed quantity is
37
+ * exact, and `round(q.value, …)` is the author's explicit reduction.
38
+ */
39
+ export function toQuantityValue(value, path = '') {
40
+ return readQuantity(value, path, asDecimalString);
41
+ }
42
+ /**
43
+ * Reads a quantity value from untrusted input, with the value-free refusal `asWireDecimalString`
44
+ * gives. The shape rules are `readQuantity`'s, so the wire check is not a second implementation.
45
+ */
46
+ export function toWireQuantityValue(value, path) {
47
+ return readQuantity(value, path, asWireDecimalString);
48
+ }
49
+ function assertSameUnit(left, right, path) {
50
+ if (left.unit !== right.unit) {
51
+ throw new AxiomError('ENGINE_ERROR', `quantity operands differ in unit: ${left.unit} and ${right.unit}; v1 defines no unit conversion`, path);
52
+ }
53
+ }
54
+ /** The exact sum of two quantities of one unit. */
55
+ export function quantityAdd(left, right, path = '') {
56
+ const a = toQuantityValue(left, path);
57
+ const b = toQuantityValue(right, path);
58
+ assertSameUnit(a, b, path);
59
+ return { value: sumDecimalTexts([a.value, b.value], path), unit: a.unit };
60
+ }
61
+ /** The exact difference of two quantities of one unit. */
62
+ export function quantitySub(left, right, path = '') {
63
+ const a = toQuantityValue(left, path);
64
+ const b = toQuantityValue(right, path);
65
+ assertSameUnit(a, b, path);
66
+ return { value: subtractDecimalTexts(a.value, b.value, path), unit: a.unit };
67
+ }
68
+ /** The order of two quantities of one unit; a mixed pair is refused rather than compared. */
69
+ export function compareQuantities(left, right, path = '') {
70
+ const a = toQuantityValue(left, path);
71
+ const b = toQuantityValue(right, path);
72
+ assertSameUnit(a, b, path);
73
+ return compareDecimalTexts(a.value, b.value, path);
74
+ }
75
+ /** The zero of one unit, for `sum` over a single-unit quantity list. */
76
+ export function quantityZero(unit) {
77
+ return { value: asDecimalString('0'), unit };
78
+ }
79
+ /** The amount as canonical decimal text: `q.value` is the decimal and this is the same read. */
80
+ export function quantityAmount(quantity, path = '') {
81
+ return toQuantityValue(quantity, path).value;
82
+ }
83
+ //# sourceMappingURL=quantity.js.map