@noy-db/hub 0.4.0-pre.5 → 0.4.0-pre.7

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 (534) hide show
  1. package/dist/api-3NKVNZPM.js +20 -0
  2. package/dist/attestation/index.js +20 -20
  3. package/dist/{backup-YCHAC575.js → backup-PTSVXDDW.js} +13 -13
  4. package/dist/blobs/index.js +15 -12
  5. package/dist/blobs/index.js.map +1 -1
  6. package/dist/broker/index.js +12 -12
  7. package/dist/cargo/index.js +36 -36
  8. package/dist/{chunk-5WLDZZ6S.js → chunk-35NMVJ7I.js} +3 -3
  9. package/dist/{chunk-TNATF3HB.js → chunk-3HUYRN24.js} +4 -4
  10. package/dist/chunk-3HUYRN24.js.map +1 -0
  11. package/dist/{chunk-TNJVDG2B.js → chunk-3XKESW5E.js} +3 -3
  12. package/dist/{chunk-MUPZ6IZX.js → chunk-4JQK3L4V.js} +2 -2
  13. package/dist/{chunk-Z4D3YGAB.js → chunk-4ZKNC6A6.js} +2 -2
  14. package/dist/{chunk-ONB627HU.js → chunk-55LX6FSX.js} +2 -2
  15. package/dist/{chunk-QMZ5A6FQ.js → chunk-56IIVAEO.js} +2 -2
  16. package/dist/chunk-5D2ALSM5.js +19 -0
  17. package/dist/chunk-5D2ALSM5.js.map +1 -0
  18. package/dist/{chunk-FHHYCBBP.js → chunk-5DRROK5W.js} +2 -2
  19. package/dist/{chunk-GTNRMJYH.js → chunk-5GQEU4DN.js} +2 -2
  20. package/dist/{chunk-YQQPNXNO.js → chunk-6L3DKWRY.js} +6 -6
  21. package/dist/chunk-6LJY7X5A.js +18 -0
  22. package/dist/chunk-6LJY7X5A.js.map +1 -0
  23. package/dist/{chunk-M6QA2KK2.js → chunk-6M2I3DKF.js} +2 -2
  24. package/dist/{chunk-FTCGEUOY.js → chunk-6R6Q3MRN.js} +7 -7
  25. package/dist/{chunk-ZUDAK436.js → chunk-6UBZ6I5Z.js} +2 -2
  26. package/dist/{chunk-SEU6QHH4.js → chunk-6ZNSB3H6.js} +5 -17
  27. package/dist/chunk-6ZNSB3H6.js.map +1 -0
  28. package/dist/chunk-AFHQATY4.js +47 -0
  29. package/dist/chunk-AFHQATY4.js.map +1 -0
  30. package/dist/{chunk-7U6AB7DZ.js → chunk-AKKRXT23.js} +2 -2
  31. package/dist/{chunk-2PDBYF2O.js → chunk-AT2JJEKJ.js} +4 -4
  32. package/dist/chunk-AT2JJEKJ.js.map +1 -0
  33. package/dist/{chunk-OWLZONGX.js → chunk-BLBAQRBM.js} +2 -2
  34. package/dist/{chunk-QBOQI6PG.js → chunk-BN4HRYAZ.js} +2 -2
  35. package/dist/{chunk-QVGEVZ5F.js → chunk-BQ6DHN4I.js} +3 -3
  36. package/dist/{chunk-GP54LU5N.js → chunk-BYFXLDVV.js} +9 -9
  37. package/dist/{chunk-FIP7KI2P.js → chunk-C25JXSOR.js} +337 -21
  38. package/dist/chunk-C25JXSOR.js.map +1 -0
  39. package/dist/chunk-CADUYBQD.js +151 -0
  40. package/dist/chunk-CADUYBQD.js.map +1 -0
  41. package/dist/{chunk-HAPY7WFP.js → chunk-CCDP6EPB.js} +13 -355
  42. package/dist/chunk-CCDP6EPB.js.map +1 -0
  43. package/dist/{chunk-QRHEAZ2Q.js → chunk-CUZLNGD5.js} +1 -1
  44. package/dist/{chunk-YXIVUWDU.js → chunk-DGBIHDVK.js} +5 -5
  45. package/dist/chunk-DSDXAKIP.js +50 -0
  46. package/dist/chunk-DSDXAKIP.js.map +1 -0
  47. package/dist/{chunk-QZJEYZ4I.js → chunk-DZAF24PG.js} +5 -5
  48. package/dist/chunk-DZFQVICS.js +23 -0
  49. package/dist/chunk-DZFQVICS.js.map +1 -0
  50. package/dist/chunk-E23UGFVC.js +63 -0
  51. package/dist/chunk-E23UGFVC.js.map +1 -0
  52. package/dist/{chunk-X3MWEFPT.js → chunk-EBKCYQ2D.js} +14 -14
  53. package/dist/chunk-EBKCYQ2D.js.map +1 -0
  54. package/dist/chunk-EP5L47XV.js +22 -0
  55. package/dist/chunk-EP5L47XV.js.map +1 -0
  56. package/dist/{chunk-TMR64XPL.js → chunk-EZNTORXE.js} +2 -2
  57. package/dist/{chunk-JAMDDLIM.js → chunk-FMNU7IUG.js} +3 -3
  58. package/dist/{chunk-YXZNGHID.js → chunk-FO6RNKKW.js} +8 -46
  59. package/dist/chunk-FO6RNKKW.js.map +1 -0
  60. package/dist/{chunk-YMUGBZN2.js → chunk-FQ5CHJR7.js} +1 -1
  61. package/dist/chunk-FQ5CHJR7.js.map +1 -0
  62. package/dist/{chunk-YZN6NRTR.js → chunk-FRMW23UK.js} +13 -11
  63. package/dist/chunk-FRMW23UK.js.map +1 -0
  64. package/dist/chunk-GJW4HX2O.js +1 -0
  65. package/dist/{chunk-7BIJS6II.js → chunk-GP3UWP22.js} +4 -4
  66. package/dist/{chunk-YTW6ZIPD.js → chunk-GZACYEOB.js} +1 -1
  67. package/dist/chunk-GZACYEOB.js.map +1 -0
  68. package/dist/{chunk-JIHH26WQ.js → chunk-HFUAFR6B.js} +6 -6
  69. package/dist/{chunk-J5TEU77Q.js → chunk-IF6WNGAK.js} +59 -4
  70. package/dist/chunk-IF6WNGAK.js.map +1 -0
  71. package/dist/{chunk-ZX5FNWH7.js → chunk-IG6KUWBX.js} +2 -2
  72. package/dist/chunk-IG6KUWBX.js.map +1 -0
  73. package/dist/{chunk-CKUYQO2P.js → chunk-IMRB2C4O.js} +7 -5
  74. package/dist/chunk-IMRB2C4O.js.map +1 -0
  75. package/dist/{chunk-RWW3I3PO.js → chunk-ISRKW4YN.js} +3 -3
  76. package/dist/{chunk-P4NUJVWL.js → chunk-IXNCZTWA.js} +2 -2
  77. package/dist/{chunk-YFFEF6HR.js → chunk-JIDLU57U.js} +3 -3
  78. package/dist/{chunk-PTT2NB46.js → chunk-JYJFGD2H.js} +2 -2
  79. package/dist/{chunk-3OWYOECI.js → chunk-JYV4JJV2.js} +5 -5
  80. package/dist/{chunk-OGVE4IJW.js → chunk-KBPU5M2E.js} +7 -7
  81. package/dist/{chunk-I2XEBEEF.js → chunk-KFRPNHWR.js} +4 -4
  82. package/dist/chunk-KFRPNHWR.js.map +1 -0
  83. package/dist/{chunk-3LJYHE7S.js → chunk-KPXM4WO6.js} +64 -57
  84. package/dist/chunk-KPXM4WO6.js.map +1 -0
  85. package/dist/{chunk-QMMOMBH6.js → chunk-KRCBZYTZ.js} +26 -177
  86. package/dist/chunk-KRCBZYTZ.js.map +1 -0
  87. package/dist/{chunk-UTEATWHO.js → chunk-KW42W6SV.js} +6 -6
  88. package/dist/{chunk-BY5YBSXA.js → chunk-L3YYLT4E.js} +15 -2
  89. package/dist/chunk-L3YYLT4E.js.map +1 -0
  90. package/dist/{chunk-UVBHM7AK.js → chunk-MANUDU7I.js} +6 -6
  91. package/dist/{chunk-YJ3TREAC.js → chunk-MHMLXJ3I.js} +2 -2
  92. package/dist/chunk-MHMLXJ3I.js.map +1 -0
  93. package/dist/{chunk-D4LAJ737.js → chunk-MSMJJB4J.js} +2 -2
  94. package/dist/chunk-MSMJJB4J.js.map +1 -0
  95. package/dist/{chunk-DYZ5CCVM.js → chunk-MXUT7FTE.js} +2 -2
  96. package/dist/chunk-MXUT7FTE.js.map +1 -0
  97. package/dist/{chunk-7ICV4ASA.js → chunk-N5PLUFH2.js} +27 -5
  98. package/dist/chunk-N5PLUFH2.js.map +1 -0
  99. package/dist/{chunk-K7BADAOS.js → chunk-NEX7JCMO.js} +4 -4
  100. package/dist/{chunk-5HSSTOOG.js → chunk-NFZGZ4AK.js} +2 -2
  101. package/dist/{chunk-XUFAFHQM.js → chunk-NJ4DYYO5.js} +7 -4
  102. package/dist/chunk-NJ4DYYO5.js.map +1 -0
  103. package/dist/{chunk-VEGQYPCP.js → chunk-NQSO4UAH.js} +8 -8
  104. package/dist/chunk-NQSO4UAH.js.map +1 -0
  105. package/dist/{chunk-GHEMAVTN.js → chunk-NYEFP7DY.js} +4 -4
  106. package/dist/chunk-NYEFP7DY.js.map +1 -0
  107. package/dist/{chunk-S4YERMGJ.js → chunk-OBPVWOSQ.js} +4 -4
  108. package/dist/{chunk-OHV6T5JB.js → chunk-OLIWCCFM.js} +2 -5
  109. package/dist/{chunk-2CRZOVDI.js → chunk-OLSARBZU.js} +2 -2
  110. package/dist/chunk-PEOZ34EM.js +13 -0
  111. package/dist/chunk-PEOZ34EM.js.map +1 -0
  112. package/dist/{chunk-KJTIAECI.js → chunk-PT4XLP6I.js} +171 -12
  113. package/dist/chunk-PT4XLP6I.js.map +1 -0
  114. package/dist/{chunk-LC7DSMHR.js → chunk-PTHKZWEH.js} +2 -14
  115. package/dist/{chunk-LC7DSMHR.js.map → chunk-PTHKZWEH.js.map} +1 -1
  116. package/dist/chunk-PVEWA2DU.js +23 -0
  117. package/dist/chunk-PVEWA2DU.js.map +1 -0
  118. package/dist/chunk-QADFHRQM.js +367 -0
  119. package/dist/chunk-QADFHRQM.js.map +1 -0
  120. package/dist/{chunk-7LP7FFJ2.js → chunk-QD46HPZG.js} +2 -2
  121. package/dist/{chunk-G4MFQXYX.js → chunk-QJNCB5SK.js} +2 -2
  122. package/dist/{chunk-6SYOHUHM.js → chunk-QZWTRENR.js} +2 -2
  123. package/dist/chunk-QZWTRENR.js.map +1 -0
  124. package/dist/{chunk-TSNRZSRC.js → chunk-RO5NM6UI.js} +2 -2
  125. package/dist/chunk-RO5NM6UI.js.map +1 -0
  126. package/dist/{chunk-GEEJPID6.js → chunk-RZPOZPZU.js} +8 -8
  127. package/dist/chunk-SGDPRCC4.js +1075 -0
  128. package/dist/chunk-SGDPRCC4.js.map +1 -0
  129. package/dist/{chunk-YCAJDK4O.js → chunk-SGQ4N5FS.js} +5 -5
  130. package/dist/{chunk-522MBPE5.js → chunk-SHEEBRZ4.js} +2 -2
  131. package/dist/{chunk-YWZEDG7F.js → chunk-SHYIA73K.js} +6 -6
  132. package/dist/{chunk-L2CAWCQL.js → chunk-SKM35Y4Q.js} +17 -26
  133. package/dist/chunk-SKM35Y4Q.js.map +1 -0
  134. package/dist/chunk-SMY5X46Z.js +14 -0
  135. package/dist/chunk-SMY5X46Z.js.map +1 -0
  136. package/dist/{chunk-K4BWPNJO.js → chunk-TE6LH6J2.js} +5 -5
  137. package/dist/{chunk-AFAPBZAA.js → chunk-TG634KCO.js} +11 -2
  138. package/dist/chunk-TG634KCO.js.map +1 -0
  139. package/dist/{chunk-V5JUAW4M.js → chunk-TIVK6PRK.js} +9 -10
  140. package/dist/chunk-TIVK6PRK.js.map +1 -0
  141. package/dist/{chunk-JN3SGXJE.js → chunk-UADPR6F4.js} +3 -3
  142. package/dist/{chunk-JN3SGXJE.js.map → chunk-UADPR6F4.js.map} +1 -1
  143. package/dist/{chunk-SBOHNJUD.js → chunk-V6UQZA2H.js} +2 -2
  144. package/dist/chunk-VG2ZSFYD.js +32 -0
  145. package/dist/chunk-VG2ZSFYD.js.map +1 -0
  146. package/dist/{chunk-SC4JLMZI.js → chunk-VH6SOCXH.js} +2 -2
  147. package/dist/chunk-VKQCVU2Z.js +21 -0
  148. package/dist/chunk-VKQCVU2Z.js.map +1 -0
  149. package/dist/chunk-VSRSQ2CR.js +654 -0
  150. package/dist/chunk-VSRSQ2CR.js.map +1 -0
  151. package/dist/{chunk-WQN5SM7P.js → chunk-W3G5REIU.js} +2 -2
  152. package/dist/{chunk-EGU4PWQW.js → chunk-W66AM5IB.js} +2 -2
  153. package/dist/chunk-W66AM5IB.js.map +1 -0
  154. package/dist/{chunk-HQKRZIX6.js → chunk-WBKZUO5V.js} +26 -43
  155. package/dist/chunk-WBKZUO5V.js.map +1 -0
  156. package/dist/{chunk-OMSKGLYA.js → chunk-WO4T4OD5.js} +2 -2
  157. package/dist/{chunk-6RPWILRH.js → chunk-WZ3NCMK6.js} +6 -5
  158. package/dist/{chunk-BAAUFCJK.js → chunk-X4MVWPHV.js} +3 -3
  159. package/dist/{chunk-R2N37AA6.js → chunk-XIDQKFZF.js} +3 -3
  160. package/dist/{chunk-EEZCB74X.js → chunk-XOBHRD2M.js} +575 -651
  161. package/dist/chunk-XOBHRD2M.js.map +1 -0
  162. package/dist/chunk-XZHEOSQ2.js +16 -0
  163. package/dist/chunk-XZHEOSQ2.js.map +1 -0
  164. package/dist/chunk-Y2NBBT6K.js +18 -0
  165. package/dist/chunk-Y2NBBT6K.js.map +1 -0
  166. package/dist/{chunk-OWOT7CFC.js → chunk-Y6B6HVKC.js} +2 -2
  167. package/dist/{chunk-5ATANZSW.js → chunk-Y6VZQGGH.js} +6 -6
  168. package/dist/chunk-YMUFFJCO.js +23 -0
  169. package/dist/chunk-YMUFFJCO.js.map +1 -0
  170. package/dist/{chunk-YZNKFYDC.js → chunk-ZFUFAHZ3.js} +4 -4
  171. package/dist/{chunk-PWWWMRT7.js → chunk-ZTLOXFPB.js} +2 -2
  172. package/dist/chunk-ZTLOXFPB.js.map +1 -0
  173. package/dist/{walk-E3OVLBFR.js → chunk-ZWBKDKXC.js} +4 -13
  174. package/dist/{walk-E3OVLBFR.js.map → chunk-ZWBKDKXC.js.map} +1 -1
  175. package/dist/classified/index.js +5 -5
  176. package/dist/{classified-marker-52P3D72W.js → classified-marker-EOOSMWFC.js} +3 -3
  177. package/dist/collection-facade-TTRF5NFJ.js +45 -0
  178. package/dist/{computed-33DRJDOC.js → computed-AB45PS4V.js} +3 -3
  179. package/dist/consent/index.js +13 -9
  180. package/dist/consent/index.js.map +1 -1
  181. package/dist/{cover-5BSNJREH.js → cover/index.js} +7 -6
  182. package/dist/crdt/index.js +4 -0
  183. package/dist/crdt/index.js.map +1 -1
  184. package/dist/custody/index.js +26 -0
  185. package/dist/{dead-filter-JXVCKS6W.js → dead-filter-6DYY7S64.js} +2 -2
  186. package/dist/{chunk-ILM6X6CP.js → delegation-ONOZVPIP.js} +12 -6
  187. package/dist/{chunk-ILM6X6CP.js.map → delegation-ONOZVPIP.js.map} +1 -1
  188. package/dist/derivations/index.js +12 -12
  189. package/dist/derive-IGGVSUPH.js +22 -0
  190. package/dist/directory/index.js +46 -0
  191. package/dist/{dispatch-PKQQFDBT.js → dispatch-7T45NN7C.js} +19 -18
  192. package/dist/{dispatch-PKQQFDBT.js.map → dispatch-7T45NN7C.js.map} +1 -1
  193. package/dist/{dispatch-SMXUO7W5.js → dispatch-RPTLK7LJ.js} +5 -5
  194. package/dist/{enclave-I5H3GINP.js → enclave-CLJVSDFG.js} +9 -9
  195. package/dist/executor-IEBLTBCW.js +9 -0
  196. package/dist/executor-RM7XWQDU.js +9 -0
  197. package/dist/executor-XZYM4KHT.js +28 -0
  198. package/dist/export-accessible-24XCCD3A.js +23 -0
  199. package/dist/extract-partition-H2TPEEOF.js +38 -0
  200. package/dist/{fanout-sidecar-WWXVHHUH.js → fanout-sidecar-TV7CXAJ6.js} +9 -9
  201. package/dist/find-OZMTRIK3.js +11 -0
  202. package/dist/forget/index.js +11 -11
  203. package/dist/forget/index.js.map +1 -1
  204. package/dist/guards/index.js +4 -4
  205. package/dist/history/index.js +16 -12
  206. package/dist/history/index.js.map +1 -1
  207. package/dist/i18n/index.js +16 -14
  208. package/dist/i18n/index.js.map +1 -1
  209. package/dist/index.d.ts +18 -24
  210. package/dist/index.js +212 -2045
  211. package/dist/index.js.map +1 -1
  212. package/dist/indexing/index.js +4 -2
  213. package/dist/indexing/index.js.map +1 -1
  214. package/dist/introspection/index.js +28 -0
  215. package/dist/issue-55HJE7JF.js +19 -0
  216. package/dist/kernel/collection-config.d.ts +1 -1
  217. package/dist/kernel/collection.d.ts +2 -2
  218. package/dist/kernel/errors.d.ts +2 -2
  219. package/dist/kernel/lazy.d.ts +30 -0
  220. package/dist/kernel/noydb.d.ts +22 -11
  221. package/dist/kernel/query/builder.d.ts +10 -10
  222. package/dist/kernel/query/index.d.ts +0 -6
  223. package/dist/kernel/query/scan-builder.d.ts +4 -4
  224. package/dist/kernel/types.d.ts +25 -25
  225. package/dist/kernel/vault.d.ts +10 -10
  226. package/dist/{ledger-M2BKCNVS.js → ledger-XY6NP3J2.js} +11 -11
  227. package/dist/liberate-LXOJ2EMB.js +24 -0
  228. package/dist/{link-set-ZU4E5J5S.js → link-set-POQB7BU5.js} +11 -11
  229. package/dist/materialized-views/index.js +22 -19
  230. package/dist/money/index.js +31 -0
  231. package/dist/noydb-KXS35UJS.js +82 -0
  232. package/dist/overlay-views/index.js +4 -4
  233. package/dist/periods/index.js +15 -13
  234. package/dist/pod/index.js +11 -12
  235. package/dist/{policy-IY2YEA3A.js → policy/index.js} +6 -6
  236. package/dist/port/with/blob-strategy.d.ts +15 -5
  237. package/dist/port/with/collection-registries.d.ts +62 -0
  238. package/dist/port/with/strategies.d.ts +11 -11
  239. package/dist/port/with/team-strategy.d.ts +2 -1
  240. package/dist/portability/index.js +8 -8
  241. package/dist/{post-register-XIAHB6KF.js → post-register-URQANI3B.js} +6 -6
  242. package/dist/query/index.js +6 -46
  243. package/dist/{aggregate → reduce}/index.js +24 -17
  244. package/dist/reduce/index.js.map +1 -0
  245. package/dist/register-5W6CG4RM.js +25 -0
  246. package/dist/registry-7Y5WF7GS.js +9 -0
  247. package/dist/{registry-VW6P6A3J.js → registry-BWD2ED52.js} +2 -2
  248. package/dist/registry-MCSGBZXI.js +18 -0
  249. package/dist/registry-UJFP3NWF.js +19 -0
  250. package/dist/request-withdrawal-IWYDM4SO.js +31 -0
  251. package/dist/{reveal-VWXRV2XU.js → reveal-BXZGWIOP.js} +6 -6
  252. package/dist/revoke-TINYPHYY.js +24 -0
  253. package/dist/satellites/index.js +1 -1
  254. package/dist/schema-update/index.js +26 -0
  255. package/dist/sealed-record/index.js +12 -12
  256. package/dist/search/index.js +36 -0
  257. package/dist/{seed-CDBFOTIK.js → seed-F7YYQTRC.js} +11 -11
  258. package/dist/sequence/index.js +30 -0
  259. package/dist/session/index.js +13 -9
  260. package/dist/session/index.js.map +1 -1
  261. package/dist/shadow/index.js +6 -2
  262. package/dist/shadow/index.js.map +1 -1
  263. package/dist/signer-WMZKCNKC.js +25 -0
  264. package/dist/snapshots/index.js +14 -10
  265. package/dist/snapshots/index.js.map +1 -1
  266. package/dist/{stale-NBROTA66.js → stale-JOE7GBAE.js} +11 -10
  267. package/dist/storage-B3WBKXKT.js +23 -0
  268. package/dist/store/index.js +22 -0
  269. package/dist/{store-coordination-provider-P3IU5JHD.js → store-coordination-provider-5LX2UFU2.js} +3 -3
  270. package/dist/sync/index.js +14 -10
  271. package/dist/sync/index.js.map +1 -1
  272. package/dist/team/index.js +36 -29
  273. package/dist/tiers/index.js +10 -10
  274. package/dist/to/index.js +1 -1
  275. package/dist/{tx → transactions}/index.js +7 -3
  276. package/dist/transactions/index.js.map +1 -0
  277. package/dist/util/index.js +1 -1
  278. package/dist/{verify-5X37OXRY.js → verify-7XWHJWUN.js} +5 -5
  279. package/dist/via/blob/active.d.ts +7 -18
  280. package/dist/via/blob/binding.d.ts +1 -1
  281. package/dist/via/blob/index.d.ts +4 -2
  282. package/dist/via/i18n/core.d.ts +1 -1
  283. package/dist/via/i18n/index.d.ts +2 -0
  284. package/dist/via/money/money-reducer.d.ts +2 -2
  285. package/dist/walk-6OHAWGBS.js +21 -0
  286. package/dist/with-audit/consent/index.d.ts +2 -0
  287. package/dist/with-audit/forget/active.d.ts +3 -3
  288. package/dist/with-audit/forget/index.d.ts +4 -4
  289. package/dist/with-audit/forget/strategy.d.ts +3 -3
  290. package/dist/with-audit/guards/executor.d.ts +4 -4
  291. package/dist/with-audit/guards/immutable-guard.d.ts +3 -3
  292. package/dist/with-audit/guards/index.d.ts +1 -1
  293. package/dist/with-audit/guards/registry.d.ts +3 -3
  294. package/dist/with-audit/guards/transition-guard.d.ts +3 -3
  295. package/dist/with-audit/guards/types.d.ts +10 -10
  296. package/dist/with-audit/guards/with-guard.d.ts +2 -2
  297. package/dist/with-audit/periods/index.d.ts +2 -0
  298. package/dist/with-cargo/floor.d.ts +3 -3
  299. package/dist/with-commit/crdt/index.d.ts +2 -0
  300. package/dist/with-commit/history/index.d.ts +2 -0
  301. package/dist/with-commit/numbering/descriptor.d.ts +16 -6
  302. package/dist/with-commit/tx/active.d.ts +5 -5
  303. package/dist/with-commit/tx/index.d.ts +2 -2
  304. package/dist/with-commit/tx/invariants.d.ts +1 -1
  305. package/dist/with-commit/tx/strategy.d.ts +3 -3
  306. package/dist/with-fork/shadow/index.d.ts +2 -0
  307. package/dist/with-fork/snapshots/active.d.ts +2 -2
  308. package/dist/with-fork/snapshots/index.d.ts +3 -1
  309. package/dist/with-fork/snapshots/noydb-facade.d.ts +3 -3
  310. package/dist/with-fork/snapshots/strategy.d.ts +2 -2
  311. package/dist/with-formula/derivations/executor.d.ts +2 -2
  312. package/dist/with-formula/derivations/index.d.ts +2 -1
  313. package/dist/with-formula/derivations/registry.d.ts +3 -3
  314. package/dist/with-formula/derivations/stale.d.ts +2 -2
  315. package/dist/with-formula/derivations/types.d.ts +3 -3
  316. package/dist/with-formula/derivations/with-derivation.d.ts +2 -2
  317. package/dist/with-formula/derivations/with-rollup.d.ts +15 -8
  318. package/dist/with-formula/materialized-views/dependency-analyzer.d.ts +3 -3
  319. package/dist/with-formula/materialized-views/index.d.ts +1 -1
  320. package/dist/with-formula/materialized-views/registry.d.ts +4 -4
  321. package/dist/with-formula/materialized-views/types.d.ts +11 -11
  322. package/dist/with-formula/materialized-views/with-materialized-view.d.ts +2 -2
  323. package/dist/with-formula/overlay-views/index.d.ts +1 -1
  324. package/dist/with-formula/overlay-views/registry.d.ts +4 -4
  325. package/dist/with-formula/overlay-views/types.d.ts +3 -3
  326. package/dist/with-formula/overlay-views/virtual-collection.d.ts +2 -2
  327. package/dist/with-formula/overlay-views/with-overlayed-view.d.ts +2 -2
  328. package/dist/with-lookup/indexing/active.d.ts +5 -5
  329. package/dist/with-lookup/indexing/index.d.ts +3 -1
  330. package/dist/with-lookup/indexing/strategy.d.ts +3 -3
  331. package/dist/with-lookup/{aggregate → reduce}/active.d.ts +8 -8
  332. package/dist/with-lookup/{aggregate → reduce}/groupby.d.ts +21 -21
  333. package/dist/with-lookup/reduce/index.d.ts +34 -0
  334. package/dist/with-lookup/{aggregate → reduce}/reducers.d.ts +10 -10
  335. package/dist/with-lookup/{aggregate/aggregation.d.ts → reduce/reduction.d.ts} +21 -21
  336. package/dist/with-lookup/{aggregate → reduce}/strategy.d.ts +15 -15
  337. package/dist/with-lookup/search/build-docs.d.ts +7 -2
  338. package/dist/with-lookup/search/index.d.ts +1 -1
  339. package/dist/with-party/directory/cover/index.d.ts +1 -0
  340. package/dist/with-party/directory/index.d.ts +2 -0
  341. package/dist/with-party/session/index.d.ts +2 -0
  342. package/dist/with-party/sync/index.d.ts +2 -0
  343. package/dist/with-party/team/index.d.ts +2 -0
  344. package/dist/with-party/team/keyring.d.ts +68 -20
  345. package/dist/with-party/team/noydb-facade.d.ts +2 -1
  346. package/dist/with-shape/blobs/blob-set.d.ts +1 -1
  347. package/dist/with-shape/introspection/index.d.ts +6 -0
  348. package/dist/with-shape/schema-update/index.d.ts +1 -0
  349. package/dist/with-store/index.d.ts +3 -2
  350. package/dist/withdraw-accessible-DEUCOO4F.js +28 -0
  351. package/dist/withdraw-accessible-DEUCOO4F.js.map +1 -0
  352. package/package.json +42 -30
  353. package/dist/aggregate/index.js.map +0 -1
  354. package/dist/api-22ES33N3.js +0 -20
  355. package/dist/as/index.js +0 -30
  356. package/dist/at/index.js +0 -1
  357. package/dist/by/index.js +0 -11
  358. package/dist/chunk-2PDBYF2O.js.map +0 -1
  359. package/dist/chunk-2YELV6TV.js +0 -1
  360. package/dist/chunk-3LJYHE7S.js.map +0 -1
  361. package/dist/chunk-6SYOHUHM.js.map +0 -1
  362. package/dist/chunk-7ICV4ASA.js.map +0 -1
  363. package/dist/chunk-AFAPBZAA.js.map +0 -1
  364. package/dist/chunk-BY5YBSXA.js.map +0 -1
  365. package/dist/chunk-CJVEAVYH.js +0 -205
  366. package/dist/chunk-CJVEAVYH.js.map +0 -1
  367. package/dist/chunk-CKUYQO2P.js.map +0 -1
  368. package/dist/chunk-D4LAJ737.js.map +0 -1
  369. package/dist/chunk-DYZ5CCVM.js.map +0 -1
  370. package/dist/chunk-EEZCB74X.js.map +0 -1
  371. package/dist/chunk-EGU4PWQW.js.map +0 -1
  372. package/dist/chunk-FIP7KI2P.js.map +0 -1
  373. package/dist/chunk-GHEMAVTN.js.map +0 -1
  374. package/dist/chunk-HAPY7WFP.js.map +0 -1
  375. package/dist/chunk-HQKRZIX6.js.map +0 -1
  376. package/dist/chunk-I2XEBEEF.js.map +0 -1
  377. package/dist/chunk-IGLU4ME7.js +0 -255
  378. package/dist/chunk-IGLU4ME7.js.map +0 -1
  379. package/dist/chunk-J5TEU77Q.js.map +0 -1
  380. package/dist/chunk-KJTIAECI.js.map +0 -1
  381. package/dist/chunk-L2CAWCQL.js.map +0 -1
  382. package/dist/chunk-LB7FD65R.js +0 -163
  383. package/dist/chunk-LB7FD65R.js.map +0 -1
  384. package/dist/chunk-PWWWMRT7.js.map +0 -1
  385. package/dist/chunk-QMMOMBH6.js.map +0 -1
  386. package/dist/chunk-SEU6QHH4.js.map +0 -1
  387. package/dist/chunk-TNATF3HB.js.map +0 -1
  388. package/dist/chunk-TSNRZSRC.js.map +0 -1
  389. package/dist/chunk-V5JUAW4M.js.map +0 -1
  390. package/dist/chunk-VEGQYPCP.js.map +0 -1
  391. package/dist/chunk-X3MWEFPT.js.map +0 -1
  392. package/dist/chunk-XUFAFHQM.js.map +0 -1
  393. package/dist/chunk-YJ3TREAC.js.map +0 -1
  394. package/dist/chunk-YMUGBZN2.js.map +0 -1
  395. package/dist/chunk-YTW6ZIPD.js.map +0 -1
  396. package/dist/chunk-YXZNGHID.js.map +0 -1
  397. package/dist/chunk-YZN6NRTR.js.map +0 -1
  398. package/dist/chunk-ZX5FNWH7.js.map +0 -1
  399. package/dist/collection-facade-XKCFHSLR.js +0 -44
  400. package/dist/delegation-WWZPEDK2.js +0 -25
  401. package/dist/derive-CWWFEQ4N.js +0 -21
  402. package/dist/executor-FCJEH3FU.js +0 -9
  403. package/dist/executor-OHET7TF7.js +0 -9
  404. package/dist/executor-SHYLIBOM.js +0 -26
  405. package/dist/export-accessible-FBL6TDSK.js +0 -23
  406. package/dist/extract-partition-ZYIRYMTI.js +0 -38
  407. package/dist/find-LEBUXVL7.js +0 -11
  408. package/dist/in/index.js +0 -1
  409. package/dist/issue-F76PAGIR.js +0 -19
  410. package/dist/liberate-ZP7UB57K.js +0 -24
  411. package/dist/noydb-BNDGEK5X.js +0 -71
  412. package/dist/on/index.js +0 -17
  413. package/dist/port/as/index.d.ts +0 -26
  414. package/dist/port/at/index.d.ts +0 -18
  415. package/dist/port/in/index.d.ts +0 -21
  416. package/dist/port/on/index.d.ts +0 -27
  417. package/dist/port/ui/index.d.ts +0 -21
  418. package/dist/port/with/index.d.ts +0 -18
  419. package/dist/register-HB4TQZSV.js +0 -23
  420. package/dist/registry-6BMBFEXT.js +0 -19
  421. package/dist/registry-7CZWF3EQ.js +0 -9
  422. package/dist/registry-JOFO7RAH.js +0 -18
  423. package/dist/request-withdrawal-UN3TRHWI.js +0 -31
  424. package/dist/revoke-OLO2OVR7.js +0 -24
  425. package/dist/signer-MGGKPYAN.js +0 -25
  426. package/dist/storage-3R37QZLA.js +0 -23
  427. package/dist/tx/index.js.map +0 -1
  428. package/dist/ui/index.js +0 -1
  429. package/dist/with/index.js +0 -31
  430. package/dist/with-lookup/aggregate/index.d.ts +0 -23
  431. package/dist/withdraw-accessible-Q2EMATCU.js +0 -28
  432. /package/dist/{api-22ES33N3.js.map → api-3NKVNZPM.js.map} +0 -0
  433. /package/dist/{backup-YCHAC575.js.map → backup-PTSVXDDW.js.map} +0 -0
  434. /package/dist/{chunk-5WLDZZ6S.js.map → chunk-35NMVJ7I.js.map} +0 -0
  435. /package/dist/{chunk-TNJVDG2B.js.map → chunk-3XKESW5E.js.map} +0 -0
  436. /package/dist/{chunk-MUPZ6IZX.js.map → chunk-4JQK3L4V.js.map} +0 -0
  437. /package/dist/{chunk-Z4D3YGAB.js.map → chunk-4ZKNC6A6.js.map} +0 -0
  438. /package/dist/{chunk-ONB627HU.js.map → chunk-55LX6FSX.js.map} +0 -0
  439. /package/dist/{chunk-QMZ5A6FQ.js.map → chunk-56IIVAEO.js.map} +0 -0
  440. /package/dist/{chunk-FHHYCBBP.js.map → chunk-5DRROK5W.js.map} +0 -0
  441. /package/dist/{chunk-GTNRMJYH.js.map → chunk-5GQEU4DN.js.map} +0 -0
  442. /package/dist/{chunk-YQQPNXNO.js.map → chunk-6L3DKWRY.js.map} +0 -0
  443. /package/dist/{chunk-M6QA2KK2.js.map → chunk-6M2I3DKF.js.map} +0 -0
  444. /package/dist/{chunk-FTCGEUOY.js.map → chunk-6R6Q3MRN.js.map} +0 -0
  445. /package/dist/{chunk-ZUDAK436.js.map → chunk-6UBZ6I5Z.js.map} +0 -0
  446. /package/dist/{chunk-7U6AB7DZ.js.map → chunk-AKKRXT23.js.map} +0 -0
  447. /package/dist/{chunk-OWLZONGX.js.map → chunk-BLBAQRBM.js.map} +0 -0
  448. /package/dist/{chunk-QBOQI6PG.js.map → chunk-BN4HRYAZ.js.map} +0 -0
  449. /package/dist/{chunk-QVGEVZ5F.js.map → chunk-BQ6DHN4I.js.map} +0 -0
  450. /package/dist/{chunk-GP54LU5N.js.map → chunk-BYFXLDVV.js.map} +0 -0
  451. /package/dist/{chunk-QRHEAZ2Q.js.map → chunk-CUZLNGD5.js.map} +0 -0
  452. /package/dist/{chunk-YXIVUWDU.js.map → chunk-DGBIHDVK.js.map} +0 -0
  453. /package/dist/{chunk-QZJEYZ4I.js.map → chunk-DZAF24PG.js.map} +0 -0
  454. /package/dist/{chunk-TMR64XPL.js.map → chunk-EZNTORXE.js.map} +0 -0
  455. /package/dist/{chunk-JAMDDLIM.js.map → chunk-FMNU7IUG.js.map} +0 -0
  456. /package/dist/{as/index.js.map → chunk-GJW4HX2O.js.map} +0 -0
  457. /package/dist/{chunk-7BIJS6II.js.map → chunk-GP3UWP22.js.map} +0 -0
  458. /package/dist/{chunk-JIHH26WQ.js.map → chunk-HFUAFR6B.js.map} +0 -0
  459. /package/dist/{chunk-RWW3I3PO.js.map → chunk-ISRKW4YN.js.map} +0 -0
  460. /package/dist/{chunk-P4NUJVWL.js.map → chunk-IXNCZTWA.js.map} +0 -0
  461. /package/dist/{chunk-YFFEF6HR.js.map → chunk-JIDLU57U.js.map} +0 -0
  462. /package/dist/{chunk-PTT2NB46.js.map → chunk-JYJFGD2H.js.map} +0 -0
  463. /package/dist/{chunk-3OWYOECI.js.map → chunk-JYV4JJV2.js.map} +0 -0
  464. /package/dist/{chunk-OGVE4IJW.js.map → chunk-KBPU5M2E.js.map} +0 -0
  465. /package/dist/{chunk-UTEATWHO.js.map → chunk-KW42W6SV.js.map} +0 -0
  466. /package/dist/{chunk-UVBHM7AK.js.map → chunk-MANUDU7I.js.map} +0 -0
  467. /package/dist/{chunk-K7BADAOS.js.map → chunk-NEX7JCMO.js.map} +0 -0
  468. /package/dist/{chunk-5HSSTOOG.js.map → chunk-NFZGZ4AK.js.map} +0 -0
  469. /package/dist/{chunk-S4YERMGJ.js.map → chunk-OBPVWOSQ.js.map} +0 -0
  470. /package/dist/{chunk-OHV6T5JB.js.map → chunk-OLIWCCFM.js.map} +0 -0
  471. /package/dist/{chunk-2CRZOVDI.js.map → chunk-OLSARBZU.js.map} +0 -0
  472. /package/dist/{chunk-7LP7FFJ2.js.map → chunk-QD46HPZG.js.map} +0 -0
  473. /package/dist/{chunk-G4MFQXYX.js.map → chunk-QJNCB5SK.js.map} +0 -0
  474. /package/dist/{chunk-GEEJPID6.js.map → chunk-RZPOZPZU.js.map} +0 -0
  475. /package/dist/{chunk-YCAJDK4O.js.map → chunk-SGQ4N5FS.js.map} +0 -0
  476. /package/dist/{chunk-522MBPE5.js.map → chunk-SHEEBRZ4.js.map} +0 -0
  477. /package/dist/{chunk-YWZEDG7F.js.map → chunk-SHYIA73K.js.map} +0 -0
  478. /package/dist/{chunk-K4BWPNJO.js.map → chunk-TE6LH6J2.js.map} +0 -0
  479. /package/dist/{chunk-SBOHNJUD.js.map → chunk-V6UQZA2H.js.map} +0 -0
  480. /package/dist/{chunk-SC4JLMZI.js.map → chunk-VH6SOCXH.js.map} +0 -0
  481. /package/dist/{chunk-WQN5SM7P.js.map → chunk-W3G5REIU.js.map} +0 -0
  482. /package/dist/{chunk-OMSKGLYA.js.map → chunk-WO4T4OD5.js.map} +0 -0
  483. /package/dist/{chunk-6RPWILRH.js.map → chunk-WZ3NCMK6.js.map} +0 -0
  484. /package/dist/{chunk-BAAUFCJK.js.map → chunk-X4MVWPHV.js.map} +0 -0
  485. /package/dist/{chunk-R2N37AA6.js.map → chunk-XIDQKFZF.js.map} +0 -0
  486. /package/dist/{chunk-OWOT7CFC.js.map → chunk-Y6B6HVKC.js.map} +0 -0
  487. /package/dist/{chunk-5ATANZSW.js.map → chunk-Y6VZQGGH.js.map} +0 -0
  488. /package/dist/{chunk-YZNKFYDC.js.map → chunk-ZFUFAHZ3.js.map} +0 -0
  489. /package/dist/{classified-marker-52P3D72W.js.map → classified-marker-EOOSMWFC.js.map} +0 -0
  490. /package/dist/{at/index.js.map → collection-facade-TTRF5NFJ.js.map} +0 -0
  491. /package/dist/{by/index.js.map → computed-AB45PS4V.js.map} +0 -0
  492. /package/dist/{in → cover}/index.js.map +0 -0
  493. /package/dist/{on → custody}/index.js.map +0 -0
  494. /package/dist/{dead-filter-JXVCKS6W.js.map → dead-filter-6DYY7S64.js.map} +0 -0
  495. /package/dist/{chunk-2YELV6TV.js.map → derive-IGGVSUPH.js.map} +0 -0
  496. /package/dist/{ui → directory}/index.js.map +0 -0
  497. /package/dist/{dispatch-SMXUO7W5.js.map → dispatch-RPTLK7LJ.js.map} +0 -0
  498. /package/dist/{collection-facade-XKCFHSLR.js.map → enclave-CLJVSDFG.js.map} +0 -0
  499. /package/dist/{computed-33DRJDOC.js.map → executor-IEBLTBCW.js.map} +0 -0
  500. /package/dist/{cover-5BSNJREH.js.map → executor-RM7XWQDU.js.map} +0 -0
  501. /package/dist/{delegation-WWZPEDK2.js.map → executor-XZYM4KHT.js.map} +0 -0
  502. /package/dist/{derive-CWWFEQ4N.js.map → export-accessible-24XCCD3A.js.map} +0 -0
  503. /package/dist/{enclave-I5H3GINP.js.map → extract-partition-H2TPEEOF.js.map} +0 -0
  504. /package/dist/{fanout-sidecar-WWXVHHUH.js.map → fanout-sidecar-TV7CXAJ6.js.map} +0 -0
  505. /package/dist/{executor-FCJEH3FU.js.map → find-OZMTRIK3.js.map} +0 -0
  506. /package/dist/{with → introspection}/index.js.map +0 -0
  507. /package/dist/{executor-OHET7TF7.js.map → issue-55HJE7JF.js.map} +0 -0
  508. /package/dist/{executor-SHYLIBOM.js.map → ledger-XY6NP3J2.js.map} +0 -0
  509. /package/dist/{export-accessible-FBL6TDSK.js.map → liberate-LXOJ2EMB.js.map} +0 -0
  510. /package/dist/{extract-partition-ZYIRYMTI.js.map → link-set-POQB7BU5.js.map} +0 -0
  511. /package/dist/{find-LEBUXVL7.js.map → money/index.js.map} +0 -0
  512. /package/dist/{issue-F76PAGIR.js.map → noydb-KXS35UJS.js.map} +0 -0
  513. /package/dist/{ledger-M2BKCNVS.js.map → policy/index.js.map} +0 -0
  514. /package/dist/{post-register-XIAHB6KF.js.map → post-register-URQANI3B.js.map} +0 -0
  515. /package/dist/{liberate-ZP7UB57K.js.map → register-5W6CG4RM.js.map} +0 -0
  516. /package/dist/{link-set-ZU4E5J5S.js.map → registry-7Y5WF7GS.js.map} +0 -0
  517. /package/dist/{noydb-BNDGEK5X.js.map → registry-BWD2ED52.js.map} +0 -0
  518. /package/dist/{policy-IY2YEA3A.js.map → registry-MCSGBZXI.js.map} +0 -0
  519. /package/dist/{register-HB4TQZSV.js.map → registry-UJFP3NWF.js.map} +0 -0
  520. /package/dist/{registry-6BMBFEXT.js.map → request-withdrawal-IWYDM4SO.js.map} +0 -0
  521. /package/dist/{reveal-VWXRV2XU.js.map → reveal-BXZGWIOP.js.map} +0 -0
  522. /package/dist/{registry-7CZWF3EQ.js.map → revoke-TINYPHYY.js.map} +0 -0
  523. /package/dist/{registry-JOFO7RAH.js.map → schema-update/index.js.map} +0 -0
  524. /package/dist/{registry-VW6P6A3J.js.map → search/index.js.map} +0 -0
  525. /package/dist/{seed-CDBFOTIK.js.map → seed-F7YYQTRC.js.map} +0 -0
  526. /package/dist/{request-withdrawal-UN3TRHWI.js.map → sequence/index.js.map} +0 -0
  527. /package/dist/{revoke-OLO2OVR7.js.map → signer-WMZKCNKC.js.map} +0 -0
  528. /package/dist/{signer-MGGKPYAN.js.map → stale-JOE7GBAE.js.map} +0 -0
  529. /package/dist/{stale-NBROTA66.js.map → storage-B3WBKXKT.js.map} +0 -0
  530. /package/dist/{storage-3R37QZLA.js.map → store/index.js.map} +0 -0
  531. /package/dist/{store-coordination-provider-P3IU5JHD.js.map → store-coordination-provider-5LX2UFU2.js.map} +0 -0
  532. /package/dist/{verify-5X37OXRY.js.map → verify-7XWHJWUN.js.map} +0 -0
  533. /package/dist/{withdraw-accessible-Q2EMATCU.js.map → walk-6OHAWGBS.js.map} +0 -0
  534. /package/dist/with-lookup/{aggregate → reduce}/canonical-key.d.ts +0 -0
@@ -0,0 +1,1075 @@
1
+ import {
2
+ readPath
3
+ } from "./chunk-IGJCYUT5.js";
4
+ import {
5
+ installViaBinder
6
+ } from "./chunk-6UBZ6I5Z.js";
7
+ import {
8
+ NoydbError,
9
+ ValidationError
10
+ } from "./chunk-QZWTRENR.js";
11
+
12
+ // src/via/money/iso4217.ts
13
+ var MINOR_UNITS = {
14
+ // 2-decimal majors
15
+ EUR: 2,
16
+ USD: 2,
17
+ GBP: 2,
18
+ CHF: 2,
19
+ CAD: 2,
20
+ AUD: 2,
21
+ NZD: 2,
22
+ SGD: 2,
23
+ HKD: 2,
24
+ CNY: 2,
25
+ INR: 2,
26
+ BRL: 2,
27
+ MXN: 2,
28
+ ZAR: 2,
29
+ RUB: 2,
30
+ TRY: 2,
31
+ PLN: 2,
32
+ SEK: 2,
33
+ NOK: 2,
34
+ DKK: 2,
35
+ CZK: 2,
36
+ HUF: 2,
37
+ RON: 2,
38
+ ILS: 2,
39
+ THB: 2,
40
+ PHP: 2,
41
+ MYR: 2,
42
+ IDR: 2,
43
+ AED: 2,
44
+ SAR: 2,
45
+ QAR: 2,
46
+ EGP: 2,
47
+ // 0-decimal
48
+ JPY: 0,
49
+ KRW: 0,
50
+ ISK: 0,
51
+ CLP: 0,
52
+ VND: 0,
53
+ XOF: 0,
54
+ XAF: 0,
55
+ PYG: 0,
56
+ // 3-decimal
57
+ BHD: 3,
58
+ KWD: 3,
59
+ OMR: 3,
60
+ TND: 3,
61
+ JOD: 3,
62
+ IQD: 3,
63
+ LYD: 3
64
+ };
65
+ function scaleForCurrency(code) {
66
+ const v = MINOR_UNITS[code];
67
+ return v === void 0 ? null : v;
68
+ }
69
+
70
+ // src/via/money/fixed-point.ts
71
+ function expandExponent(s) {
72
+ const m = /^([+-]?)(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/.exec(s);
73
+ if (!m) return s;
74
+ const sign = m[1] === "-" ? "-" : "";
75
+ const intp = m[2];
76
+ const frac = m[3] ?? "";
77
+ const exp = Number(m[4]);
78
+ const digits = intp + frac;
79
+ const pointPos = intp.length + exp;
80
+ let body;
81
+ if (pointPos <= 0) {
82
+ body = "0." + "0".repeat(-pointPos) + digits;
83
+ } else if (pointPos >= digits.length) {
84
+ body = digits + "0".repeat(pointPos - digits.length);
85
+ } else {
86
+ body = digits.slice(0, pointPos) + "." + digits.slice(pointPos);
87
+ }
88
+ return sign + body;
89
+ }
90
+ function toCanonicalDecimalString(input) {
91
+ let s;
92
+ if (typeof input === "number") {
93
+ if (!Number.isFinite(input)) return null;
94
+ s = String(input);
95
+ } else {
96
+ s = input.trim();
97
+ }
98
+ s = expandExponent(s);
99
+ if (s.startsWith("+")) s = s.slice(1);
100
+ if (!/^-?(\d+(\.\d*)?|\.\d+)$/.test(s)) return null;
101
+ return s;
102
+ }
103
+ function shouldRoundUp(negative, lastKeptDigit, firstDiscarded, hasMoreNonZeroAfterFirst, mode) {
104
+ switch (mode) {
105
+ case "up":
106
+ return true;
107
+ case "down":
108
+ return false;
109
+ case "ceil":
110
+ return !negative;
111
+ case "floor":
112
+ return negative;
113
+ case "half-up":
114
+ return firstDiscarded >= 5;
115
+ case "half-down":
116
+ return firstDiscarded > 5 || firstDiscarded === 5 && hasMoreNonZeroAfterFirst;
117
+ case "half-even":
118
+ if (firstDiscarded > 5) return true;
119
+ if (firstDiscarded < 5) return false;
120
+ return hasMoreNonZeroAfterFirst || lastKeptDigit % 2 === 1;
121
+ }
122
+ }
123
+ function parseToScaledInt(input, scale, rounding) {
124
+ const canonical = toCanonicalDecimalString(input);
125
+ if (canonical === null) return { ok: false, reason: "nonfinite" };
126
+ const negative = canonical.startsWith("-");
127
+ const unsigned = negative ? canonical.slice(1) : canonical;
128
+ const dot = unsigned.indexOf(".");
129
+ const intPart = dot === -1 ? unsigned : unsigned.slice(0, dot);
130
+ const fracPart = dot === -1 ? "" : unsigned.slice(dot + 1);
131
+ const intDigits = intPart === "" ? "0" : intPart;
132
+ if (fracPart.length <= scale) {
133
+ const keep2 = fracPart.padEnd(scale, "0");
134
+ const magnitude2 = BigInt(intDigits + keep2);
135
+ return { ok: true, value: negative && magnitude2 !== 0n ? -magnitude2 : magnitude2 };
136
+ }
137
+ const keep = fracPart.slice(0, scale);
138
+ const tail = fracPart.slice(scale);
139
+ const magnitudeDigits = intDigits + keep;
140
+ let magnitude = BigInt(magnitudeDigits);
141
+ if (/^0+$/.test(tail)) {
142
+ return { ok: true, value: negative && magnitude !== 0n ? -magnitude : magnitude };
143
+ }
144
+ if (rounding === void 0) return { ok: false, reason: "precision" };
145
+ const lastKeptDigit = Number(magnitudeDigits[magnitudeDigits.length - 1]);
146
+ const firstDiscarded = Number(tail[0]);
147
+ const hasMoreNonZeroAfterFirst = /[1-9]/.test(tail.slice(1));
148
+ if (shouldRoundUp(negative, lastKeptDigit, firstDiscarded, hasMoreNonZeroAfterFirst, rounding)) {
149
+ magnitude += 1n;
150
+ }
151
+ return { ok: true, value: negative && magnitude !== 0n ? -magnitude : magnitude };
152
+ }
153
+ function decimalScaleOf(input) {
154
+ const s = toCanonicalDecimalString(input);
155
+ if (s === null) return null;
156
+ const dot = s.indexOf(".");
157
+ return dot === -1 ? 0 : s.length - dot - 1;
158
+ }
159
+ function rescaleScaledInt(value, fromScale, toScale, rounding = "half-up") {
160
+ if (toScale >= fromScale) return value * 10n ** BigInt(toScale - fromScale);
161
+ const drop = fromScale - toScale;
162
+ const negative = value < 0n;
163
+ const absStr = (negative ? -value : value).toString().padStart(drop + 1, "0");
164
+ const keptStr = absStr.slice(0, absStr.length - drop);
165
+ const tail = absStr.slice(absStr.length - drop);
166
+ let magnitude = BigInt(keptStr);
167
+ if (!/^0+$/.test(tail)) {
168
+ const lastKeptDigit = Number(keptStr[keptStr.length - 1]);
169
+ const firstDiscarded = Number(tail[0]);
170
+ const hasMoreNonZeroAfterFirst = /[1-9]/.test(tail.slice(1));
171
+ if (shouldRoundUp(negative, lastKeptDigit, firstDiscarded, hasMoreNonZeroAfterFirst, rounding)) {
172
+ magnitude += 1n;
173
+ }
174
+ }
175
+ return negative && magnitude !== 0n ? -magnitude : magnitude;
176
+ }
177
+ function formatScaledInt(value, scale) {
178
+ const negative = value < 0n;
179
+ const abs = (negative ? -value : value).toString();
180
+ if (scale === 0) return (negative ? "-" : "") + abs;
181
+ const padded = abs.padStart(scale + 1, "0");
182
+ const cut = padded.length - scale;
183
+ const intPart = padded.slice(0, cut);
184
+ const fracPart = padded.slice(cut);
185
+ return (negative ? "-" : "") + intPart + "." + fracPart;
186
+ }
187
+
188
+ // src/via/money/paths.ts
189
+ var SEGMENT_RE = /^(\*|[^.[\]*]+)(\[\])?$/;
190
+ var parseCache = /* @__PURE__ */ new Map();
191
+ function parseMoneyPath(path) {
192
+ const cached = parseCache.get(path);
193
+ if (cached) return cached;
194
+ if (typeof path !== "string" || path.length === 0) {
195
+ throw new ValidationError("moneyFields: path must be a non-empty string");
196
+ }
197
+ const segments = [];
198
+ for (const part of path.split(".")) {
199
+ const m = SEGMENT_RE.exec(part);
200
+ if (!m) {
201
+ throw new ValidationError(
202
+ `moneyFields: invalid path "${path}" \u2014 segment "${part}" must be a key, "key[]", "*", or "*[]"`
203
+ );
204
+ }
205
+ const array = m[2] === "[]";
206
+ segments.push(
207
+ m[1] === "*" ? { kind: "wildcard", array } : { kind: "key", key: m[1], array }
208
+ );
209
+ }
210
+ parseCache.set(path, segments);
211
+ return segments;
212
+ }
213
+ function isSimpleMoneyPath(path) {
214
+ return !path.includes(".") && !path.includes("[") && !path.includes("*");
215
+ }
216
+ function validateMoneyFieldPaths(moneyFields) {
217
+ for (const path of Object.keys(moneyFields)) parseMoneyPath(path);
218
+ }
219
+ function transformAtMoneyPath(node, path, segments, index, visit, lenient) {
220
+ if (node === null || node === void 0) return node;
221
+ const seg = segments[index];
222
+ const last = index === segments.length - 1;
223
+ if (seg.kind === "key") {
224
+ if (typeof node !== "object" || Array.isArray(node)) {
225
+ if (lenient) return node;
226
+ throw new ValidationError(
227
+ `moneyFields: path "${path}" expected an object at segment "${seg.key}", got ${Array.isArray(node) ? "an array" : typeof node}`
228
+ );
229
+ }
230
+ const obj2 = node;
231
+ if (!(seg.key in obj2) || obj2[seg.key] === null || obj2[seg.key] === void 0) return node;
232
+ if (seg.array) {
233
+ const arr = obj2[seg.key];
234
+ if (!Array.isArray(arr)) {
235
+ if (lenient) return node;
236
+ throw new ValidationError(
237
+ `moneyFields: path "${path}" declares "${seg.key}[]" but the value is not an array`
238
+ );
239
+ }
240
+ const cloned = [...arr];
241
+ if (last) {
242
+ for (let i = 0; i < cloned.length; i++) visit(cloned, i);
243
+ } else {
244
+ for (let i = 0; i < cloned.length; i++) {
245
+ cloned[i] = transformAtMoneyPath(cloned[i], path, segments, index + 1, visit, lenient);
246
+ }
247
+ }
248
+ return { ...obj2, [seg.key]: cloned };
249
+ }
250
+ const clone2 = { ...obj2 };
251
+ if (last) {
252
+ visit(clone2, seg.key);
253
+ } else {
254
+ clone2[seg.key] = transformAtMoneyPath(clone2[seg.key], path, segments, index + 1, visit, lenient);
255
+ }
256
+ return clone2;
257
+ }
258
+ if (seg.array) {
259
+ if (!Array.isArray(node)) {
260
+ if (lenient) return node;
261
+ throw new ValidationError(`moneyFields: path "${path}" declares "*[]" but the value is not an array`);
262
+ }
263
+ const cloned = [...node];
264
+ if (last) {
265
+ for (let i = 0; i < cloned.length; i++) visit(cloned, i);
266
+ } else {
267
+ for (let i = 0; i < cloned.length; i++) {
268
+ cloned[i] = transformAtMoneyPath(cloned[i], path, segments, index + 1, visit, lenient);
269
+ }
270
+ }
271
+ return cloned;
272
+ }
273
+ if (typeof node !== "object" || Array.isArray(node)) {
274
+ if (lenient) return node;
275
+ throw new ValidationError(
276
+ `moneyFields: path "${path}" applies "*" to a non-object (${Array.isArray(node) ? 'array \u2014 use "*[]"' : typeof node})`
277
+ );
278
+ }
279
+ const obj = node;
280
+ const clone = { ...obj };
281
+ for (const key of Object.keys(obj)) {
282
+ const v = clone[key];
283
+ if (v === null || v === void 0) continue;
284
+ if (last) visit(clone, key);
285
+ else clone[key] = transformAtMoneyPath(v, path, segments, index + 1, visit, lenient);
286
+ }
287
+ return clone;
288
+ }
289
+
290
+ // src/via/money/normalize.ts
291
+ function isMoneyValueObject(v) {
292
+ return typeof v === "object" && v !== null && "currency" in v;
293
+ }
294
+ function quantizeAmount(field, input, scale, rounding) {
295
+ const r = parseToScaledInt(input, scale, rounding);
296
+ if (!r.ok) {
297
+ if (r.reason === "precision") throw new MoneyPrecisionError(field, input, scale);
298
+ throw new TypeError(`money: field "${field}" value ${JSON.stringify(input)} is not a finite decimal`);
299
+ }
300
+ return r.value.toString();
301
+ }
302
+ function canonicalizeStoredMoney(record, moneyFields) {
303
+ if (record === null || record === void 0) return record;
304
+ if (!moneyFields || Object.keys(moneyFields).length === 0) return record;
305
+ return decodeMoneyFields(record, moneyFields, "raw");
306
+ }
307
+ function canonicalizeIncomingMoney(record, moneyFields) {
308
+ if (!moneyFields || Object.keys(moneyFields).length === 0) return record;
309
+ try {
310
+ return decodeMoneyFields(
311
+ quantizeMoneyFields(record, moneyFields),
312
+ moneyFields,
313
+ "raw"
314
+ );
315
+ } catch {
316
+ return record;
317
+ }
318
+ }
319
+ function quantizeValue(field, raw, desc) {
320
+ if (desc.mode === "fixed") {
321
+ const currency2 = desc.fixedCurrency;
322
+ return quantizeAmount(field, raw, desc.scaleFor(currency2), desc.rounding);
323
+ }
324
+ let amount;
325
+ let currency;
326
+ if (isMoneyValueObject(raw)) {
327
+ currency = String(raw.currency);
328
+ amount = raw.amount;
329
+ } else {
330
+ const sole = desc.soleCurrency();
331
+ if (sole === void 0) {
332
+ throw new TypeError(
333
+ `money: field "${field}" is multi-currency \u2014 write { amount, currency }, not a bare amount`
334
+ );
335
+ }
336
+ currency = sole;
337
+ amount = raw;
338
+ }
339
+ const scale = desc.scaleFor(currency);
340
+ return { amount: quantizeAmount(field, amount, scale, desc.rounding), currency };
341
+ }
342
+ function quantizeMoneyFields(record, moneyFields) {
343
+ let out = { ...record };
344
+ for (const [path, desc] of Object.entries(moneyFields)) {
345
+ if (isSimpleMoneyPath(path)) {
346
+ const raw = out[path];
347
+ if (raw === null || raw === void 0) continue;
348
+ out[path] = quantizeValue(path, raw, desc);
349
+ continue;
350
+ }
351
+ out = transformAtMoneyPath(
352
+ out,
353
+ path,
354
+ parseMoneyPath(path),
355
+ 0,
356
+ (container, key) => {
357
+ const raw = container[key];
358
+ if (raw === null || raw === void 0) return;
359
+ container[key] = quantizeValue(path, raw, desc);
360
+ },
361
+ /* lenient */
362
+ false
363
+ );
364
+ }
365
+ return out;
366
+ }
367
+ function formatCurrency(decimal, currency, scale, locale) {
368
+ const fmt = new Intl.NumberFormat(locale, {
369
+ style: "currency",
370
+ currency,
371
+ minimumFractionDigits: scale,
372
+ maximumFractionDigits: scale
373
+ });
374
+ return fmt.format(decimal);
375
+ }
376
+ function moneyScaledValue(stored, desc) {
377
+ let raw;
378
+ if (desc.mode === "fixed") {
379
+ raw = stored;
380
+ } else {
381
+ if (!isMoneyValueObject(stored)) return null;
382
+ raw = stored.amount;
383
+ }
384
+ if (typeof raw !== "string" && typeof raw !== "number") return null;
385
+ try {
386
+ return BigInt(String(raw));
387
+ } catch {
388
+ return null;
389
+ }
390
+ }
391
+ function canonicalizeMoneyIndexKey(field, rawValue, moneyFields) {
392
+ const desc = moneyFields[field];
393
+ if (!desc || desc.mode !== "fixed") return void 0;
394
+ return moneyScaledValue(rawValue, desc)?.toString();
395
+ }
396
+ function decodeValue(stored, desc) {
397
+ let currency;
398
+ let scaledIntString;
399
+ if (desc.mode === "fixed") {
400
+ if (typeof stored !== "string" && typeof stored !== "number") return null;
401
+ currency = desc.fixedCurrency;
402
+ scaledIntString = String(stored);
403
+ } else {
404
+ if (!isMoneyValueObject(stored)) return null;
405
+ const amount = stored.amount;
406
+ if (typeof stored.currency !== "string" || typeof amount !== "string" && typeof amount !== "number") return null;
407
+ currency = stored.currency;
408
+ scaledIntString = String(amount);
409
+ }
410
+ const scale = desc.scaleFor(currency);
411
+ let decimal;
412
+ try {
413
+ decimal = formatScaledInt(BigInt(scaledIntString), scale);
414
+ } catch {
415
+ return null;
416
+ }
417
+ return {
418
+ decoded: desc.mode === "fixed" ? decimal : { amount: decimal, currency },
419
+ decimal,
420
+ currency,
421
+ scale
422
+ };
423
+ }
424
+ function presentVirtualMoneyFields(record, moneyFields, virtualMoney, locale) {
425
+ let out = record;
426
+ const format = locale !== "raw";
427
+ const fmtLocale = typeof locale === "string" && locale !== "raw" ? locale : "en-US";
428
+ for (const field of virtualMoney) {
429
+ const desc = moneyFields[field];
430
+ if (!desc || desc.mode !== "fixed") continue;
431
+ const raw = out[field];
432
+ if (raw === null || raw === void 0) continue;
433
+ if (typeof raw !== "number" && typeof raw !== "string") continue;
434
+ const currency = desc.fixedCurrency;
435
+ const scale = desc.scaleFor(currency);
436
+ const r = parseToScaledInt(raw, scale, desc.rounding);
437
+ if (!r.ok) continue;
438
+ if (out === record) out = { ...record };
439
+ const decimal = formatScaledInt(r.value, scale);
440
+ out[field] = decimal;
441
+ if (format) {
442
+ out[`${field}Formatted`] = formatCurrency(decimal, currency, scale, fmtLocale);
443
+ out[`${field}Number`] = Number(decimal);
444
+ }
445
+ }
446
+ return out;
447
+ }
448
+ function decodeMoneyFields(record, moneyFields, locale) {
449
+ let out = { ...record };
450
+ const format = locale !== "raw";
451
+ const fmtLocale = typeof locale === "string" && locale !== "raw" ? locale : "en-US";
452
+ for (const [path, desc] of Object.entries(moneyFields)) {
453
+ if (isSimpleMoneyPath(path)) {
454
+ const stored = out[path];
455
+ if (stored === null || stored === void 0) continue;
456
+ const r = decodeValue(stored, desc);
457
+ if (r === null) continue;
458
+ out[path] = r.decoded;
459
+ if (format) {
460
+ out[`${path}Formatted`] = formatCurrency(r.decimal, r.currency, r.scale, fmtLocale);
461
+ out[`${path}Number`] = Number(r.decimal);
462
+ }
463
+ continue;
464
+ }
465
+ out = transformAtMoneyPath(
466
+ out,
467
+ path,
468
+ parseMoneyPath(path),
469
+ 0,
470
+ (container, key) => {
471
+ const stored = container[key];
472
+ if (stored === null || stored === void 0) return;
473
+ const r = decodeValue(stored, desc);
474
+ if (r === null) return;
475
+ container[key] = r.decoded;
476
+ if (format && typeof key === "string" && !Array.isArray(container)) {
477
+ container[`${key}Formatted`] = formatCurrency(r.decimal, r.currency, r.scale, fmtLocale);
478
+ container[`${key}Number`] = Number(r.decimal);
479
+ }
480
+ },
481
+ /* lenient */
482
+ true
483
+ );
484
+ }
485
+ return out;
486
+ }
487
+
488
+ // src/via/money/where.ts
489
+ function isMoneyValueObject2(v) {
490
+ return typeof v === "object" && v !== null && "currency" in v;
491
+ }
492
+ function parseOperand(field, raw, desc) {
493
+ let amount;
494
+ let currency;
495
+ if (desc.mode === "fixed") {
496
+ currency = desc.fixedCurrency;
497
+ amount = raw;
498
+ } else if (isMoneyValueObject2(raw)) {
499
+ currency = String(raw.currency);
500
+ amount = raw.amount;
501
+ } else {
502
+ const sole = desc.soleCurrency();
503
+ if (sole === void 0) {
504
+ throw new MoneyUnsupportedError(
505
+ `where("${field}"): field is multi-currency \u2014 compare against { amount, currency }, not a bare amount`
506
+ );
507
+ }
508
+ currency = sole;
509
+ amount = raw;
510
+ }
511
+ if (typeof amount !== "number" && typeof amount !== "string") {
512
+ throw new MoneyUnsupportedError(
513
+ `where("${field}"): operand ${JSON.stringify(raw)} is not a money amount`
514
+ );
515
+ }
516
+ const r = parseToScaledInt(amount, desc.scaleFor(currency), desc.rounding);
517
+ if (!r.ok) {
518
+ throw new MoneyUnsupportedError(
519
+ `where("${field}"): operand ${JSON.stringify(amount)} is not a finite decimal`
520
+ );
521
+ }
522
+ return { scaled: r.value.toString(), currency };
523
+ }
524
+ function moneyFieldClause(field, op, value, desc) {
525
+ switch (op) {
526
+ case "==":
527
+ case "!=":
528
+ case "<":
529
+ case "<=":
530
+ case ">":
531
+ case ">=": {
532
+ const e = parseOperand(field, value, desc);
533
+ return { mode: desc.mode, entries: [e] };
534
+ }
535
+ case "between": {
536
+ if (!Array.isArray(value) || value.length !== 2) {
537
+ throw new MoneyUnsupportedError(`where("${field}"): 'between' needs a [lo, hi] tuple`);
538
+ }
539
+ const lo = parseOperand(field, value[0], desc);
540
+ const hi = parseOperand(field, value[1], desc);
541
+ if (lo.currency !== hi.currency) {
542
+ throw new MoneyUnsupportedError(
543
+ `where("${field}"): 'between' bounds mix currencies (${lo.currency} vs ${hi.currency})`
544
+ );
545
+ }
546
+ return { mode: desc.mode, entries: [lo, hi] };
547
+ }
548
+ case "in": {
549
+ if (!Array.isArray(value)) {
550
+ throw new MoneyUnsupportedError(`where("${field}"): 'in' needs an array of amounts`);
551
+ }
552
+ return { mode: desc.mode, entries: value.map((v) => parseOperand(field, v, desc)) };
553
+ }
554
+ default:
555
+ throw new MoneyUnsupportedError(
556
+ `where("${field}"): operator '${op}' is not supported on a money field`
557
+ );
558
+ }
559
+ }
560
+ function moneyIndexProbe(op, payload) {
561
+ if (payload.mode !== "fixed") return void 0;
562
+ if (op === "==") return payload.entries[0]?.scaled;
563
+ if (op === "in") return payload.entries.map((e) => e.scaled);
564
+ return void 0;
565
+ }
566
+ function readStored(actual, operand) {
567
+ let amount;
568
+ let currency;
569
+ if (operand.mode === "fixed") {
570
+ if (typeof actual !== "string" && typeof actual !== "number") return null;
571
+ amount = actual;
572
+ currency = operand.entries[0]?.currency ?? "";
573
+ } else {
574
+ if (!isMoneyValueObject2(actual)) return null;
575
+ if (typeof actual.currency !== "string") return null;
576
+ amount = actual.amount;
577
+ currency = actual.currency;
578
+ }
579
+ if (typeof amount !== "string" && typeof amount !== "number") return null;
580
+ try {
581
+ return { scaled: BigInt(amount).toString(), currency };
582
+ } catch {
583
+ return null;
584
+ }
585
+ }
586
+ function evaluateMoneyClause(actual, op, operand) {
587
+ const stored = readStored(actual, operand);
588
+ if (stored === null) return op === "!=";
589
+ const a = BigInt(stored.scaled);
590
+ if (op === "in") {
591
+ return operand.entries.some(
592
+ (e2) => e2.currency === stored.currency && BigInt(e2.scaled) === a
593
+ );
594
+ }
595
+ if (op === "between") {
596
+ const [lo, hi] = operand.entries;
597
+ if (!lo || !hi || lo.currency !== stored.currency) return false;
598
+ return a >= BigInt(lo.scaled) && a <= BigInt(hi.scaled);
599
+ }
600
+ const e = operand.entries[0];
601
+ if (!e) return false;
602
+ if (e.currency !== stored.currency) return op === "!=";
603
+ const b = BigInt(e.scaled);
604
+ switch (op) {
605
+ case "==":
606
+ return a === b;
607
+ case "!=":
608
+ return a !== b;
609
+ case "<":
610
+ return a < b;
611
+ case "<=":
612
+ return a <= b;
613
+ case ">":
614
+ return a > b;
615
+ case ">=":
616
+ return a >= b;
617
+ default:
618
+ return false;
619
+ }
620
+ }
621
+
622
+ // src/via/money/money-reducer.ts
623
+ function toScaledIntFromAny(v, scale) {
624
+ if (typeof v === "bigint") return v;
625
+ if (typeof v === "number") {
626
+ const r = parseToScaledInt(v, scale);
627
+ return r.ok ? r.value : null;
628
+ }
629
+ if (typeof v === "string") {
630
+ if (!v.includes(".")) {
631
+ try {
632
+ return BigInt(v);
633
+ } catch {
634
+ return null;
635
+ }
636
+ }
637
+ const r = parseToScaledInt(v, scale);
638
+ return r.ok ? r.value : null;
639
+ }
640
+ return null;
641
+ }
642
+ function readMoney(record, field, desc) {
643
+ const raw = readPath(record, field);
644
+ if (raw === null || raw === void 0) return null;
645
+ if (desc.mode === "fixed") {
646
+ const cur = desc.fixedCurrency;
647
+ const value2 = toScaledIntFromAny(raw, desc.scaleFor(cur));
648
+ return value2 === null ? null : { currency: cur, value: value2 };
649
+ }
650
+ if (typeof raw !== "object") return null;
651
+ const o = raw;
652
+ if (typeof o.currency !== "string") return null;
653
+ const scale = desc.allows(o.currency) ? desc.scaleFor(o.currency) : 0;
654
+ const value = toScaledIntFromAny(o.amount, scale);
655
+ return value === null ? null : { currency: o.currency, value };
656
+ }
657
+ function targetScaleFor(desc, currency) {
658
+ if (desc.allows(currency)) return desc.scaleFor(currency);
659
+ const s = scaleForCurrency(currency);
660
+ if (s === null) {
661
+ throw new Error(`money: cannot determine scale for conversion target "${currency}"`);
662
+ }
663
+ return s;
664
+ }
665
+ function parseRate(rate) {
666
+ const s = String(rate).trim();
667
+ const neg = s.startsWith("-");
668
+ const body = neg ? s.slice(1) : s;
669
+ const dot = body.indexOf(".");
670
+ const intPart = dot === -1 ? body : body.slice(0, dot);
671
+ const fracPart = dot === -1 ? "" : body.slice(dot + 1);
672
+ const int = BigInt((intPart === "" ? "0" : intPart) + fracPart);
673
+ return { int: neg ? -int : int, scale: fracPart.length };
674
+ }
675
+ function divRoundHalfEven(n, d) {
676
+ const q = n / d;
677
+ const r = n % d;
678
+ const twiceR = (r < 0n ? -r : r) * 2n;
679
+ if (twiceR < d) return q;
680
+ if (twiceR > d) return q + (n < 0n ? -1n : 1n);
681
+ return q % 2n === 0n ? q : q + (n < 0n ? -1n : 1n);
682
+ }
683
+ function convertScaled(value, srcScale, rate, targetScale) {
684
+ const { int: rateInt, scale: rateScale } = parseRate(rate);
685
+ const product = value * rateInt;
686
+ const curScale = srcScale + rateScale;
687
+ if (curScale === targetScale) return product;
688
+ if (curScale < targetScale) return product * 10n ** BigInt(targetScale - curScale);
689
+ return divRoundHalfEven(product, 10n ** BigInt(curScale - targetScale));
690
+ }
691
+ function finalizeSum(state, desc, convertTo, fx) {
692
+ if (convertTo !== void 0) {
693
+ if (fx === void 0) {
694
+ throw new Error(`money: sum convertTo "${convertTo}" requires an fx rate map`);
695
+ }
696
+ const targetScale = targetScaleFor(desc, convertTo);
697
+ let total = 0n;
698
+ for (const [cur, v] of state) {
699
+ if (cur === convertTo) {
700
+ total += convertScaled(v, desc.scaleFor(cur), 1, targetScale);
701
+ continue;
702
+ }
703
+ const rate = fx[`${cur}->${convertTo}`];
704
+ if (rate === void 0) {
705
+ throw new Error(`money: no fx rate for "${cur}->${convertTo}"`);
706
+ }
707
+ total += convertScaled(v, desc.scaleFor(cur), rate, targetScale);
708
+ }
709
+ return formatScaledInt(total, targetScale);
710
+ }
711
+ if (desc.mode === "fixed") {
712
+ const cur = desc.fixedCurrency;
713
+ return formatScaledInt(state.get(cur) ?? 0n, desc.scaleFor(cur));
714
+ }
715
+ const out = {};
716
+ for (const [cur, v] of state) out[cur] = formatScaledInt(v, desc.scaleFor(cur));
717
+ return out;
718
+ }
719
+ function moneySumReducer(field, desc, convertTo, fx) {
720
+ return {
721
+ op: "sum",
722
+ field,
723
+ init: () => /* @__PURE__ */ new Map(),
724
+ step: (state, record) => {
725
+ const m = readMoney(record, field, desc);
726
+ if (m) state.set(m.currency, (state.get(m.currency) ?? 0n) + m.value);
727
+ return state;
728
+ },
729
+ remove: (state, record) => {
730
+ const m = readMoney(record, field, desc);
731
+ if (m) state.set(m.currency, (state.get(m.currency) ?? 0n) - m.value);
732
+ return state;
733
+ },
734
+ finalize: (state) => finalizeSum(state, desc, convertTo, fx)
735
+ };
736
+ }
737
+ function extremum(values, op) {
738
+ let out = values[0];
739
+ for (let i = 1; i < values.length; i++) {
740
+ const v = values[i];
741
+ if (op === "min" ? v < out : v > out) out = v;
742
+ }
743
+ return out;
744
+ }
745
+ function moneyMinMaxReducer(op, field, desc) {
746
+ return {
747
+ op,
748
+ field,
749
+ init: () => /* @__PURE__ */ new Map(),
750
+ step: (state, record) => {
751
+ const m = readMoney(record, field, desc);
752
+ if (m) {
753
+ const arr = state.get(m.currency);
754
+ if (arr) arr.push(m.value);
755
+ else state.set(m.currency, [m.value]);
756
+ }
757
+ return state;
758
+ },
759
+ remove: (state, record) => {
760
+ const m = readMoney(record, field, desc);
761
+ if (m) {
762
+ const arr = state.get(m.currency);
763
+ if (arr) {
764
+ const idx = arr.indexOf(m.value);
765
+ if (idx >= 0) arr.splice(idx, 1);
766
+ }
767
+ }
768
+ return state;
769
+ },
770
+ finalize: (state) => {
771
+ if (desc.mode === "fixed") {
772
+ const cur = desc.fixedCurrency;
773
+ const arr = state.get(cur);
774
+ if (!arr || arr.length === 0) return null;
775
+ return formatScaledInt(extremum(arr, op), desc.scaleFor(cur));
776
+ }
777
+ const out = {};
778
+ for (const [cur, arr] of state) {
779
+ if (arr.length > 0) out[cur] = formatScaledInt(extremum(arr, op), desc.scaleFor(cur));
780
+ }
781
+ return out;
782
+ }
783
+ };
784
+ }
785
+ function wrapMoneyReducers(spec, moneyFields) {
786
+ let changed = false;
787
+ const out = {};
788
+ for (const [key, reducer] of Object.entries(spec)) {
789
+ const field = reducer.field;
790
+ const desc = field ? moneyFields[field] : void 0;
791
+ if (desc && reducer.op === "avg") {
792
+ throw new MoneyUnsupportedError(
793
+ field,
794
+ `avg() is not supported on money field "${field}" in v1 \u2014 use sum() and count() and divide at the boundary.`
795
+ );
796
+ }
797
+ if (desc && (reducer.op === "sum" || reducer.op === "min" || reducer.op === "max")) {
798
+ changed = true;
799
+ out[key] = reducer.op === "sum" ? moneySumReducer(field, desc, reducer.convertTo, reducer.fx) : moneyMinMaxReducer(reducer.op, field, desc);
800
+ } else {
801
+ out[key] = reducer;
802
+ }
803
+ }
804
+ return changed ? out : spec;
805
+ }
806
+
807
+ // src/via/money/binding.ts
808
+ function moneyBinding(moneyFields, virtualMoneyFields) {
809
+ validateMoneyFieldPaths(moneyFields);
810
+ const hasVirtualMoney = virtualMoneyFields !== void 0 && virtualMoneyFields.size > 0;
811
+ const ordinaryPresentFields = hasVirtualMoney ? Object.fromEntries(Object.entries(moneyFields).filter(([f]) => !virtualMoneyFields.has(f))) : moneyFields;
812
+ return {
813
+ brand: "money",
814
+ posture: { encryptedAtRest: "envelope", queryable: "ordered", exportable: true, forgettable: true },
815
+ covers: (field) => field in moneyFields,
816
+ ingest: (r) => canonicalizeIncomingMoney(r, moneyFields),
817
+ canonicalizeStored: (r) => canonicalizeStoredMoney(r, moneyFields),
818
+ encodeWrite: (r) => quantizeMoneyFields(r, moneyFields),
819
+ present: (r, ctx) => decodeMoneyFields(r, ordinaryPresentFields, typeof ctx.locale === "string" ? ctx.locale : void 0),
820
+ ...hasVirtualMoney ? {
821
+ presentLate: (r, ctx) => presentVirtualMoneyFields(r, moneyFields, virtualMoneyFields, typeof ctx.locale === "string" ? ctx.locale : void 0)
822
+ } : {},
823
+ buildClause: (field, op, value) => {
824
+ const desc = moneyFields[field];
825
+ if (!desc) return void 0;
826
+ return moneyFieldClause(field, op, value, desc);
827
+ },
828
+ evaluateClause: (actual, op, payload) => evaluateMoneyClause(actual, op, payload),
829
+ indexProbe: (op, payload) => moneyIndexProbe(op, payload),
830
+ canonicalizeIndexKey: (field, rawValue) => canonicalizeMoneyIndexKey(field, rawValue, moneyFields),
831
+ decodeResults: (r) => decodeMoneyFields(r, moneyFields, "raw"),
832
+ compareForOrder: (field, a, b) => {
833
+ const desc = moneyFields[field];
834
+ if (!desc) return void 0;
835
+ const av = moneyScaledValue(a, desc);
836
+ const bv = moneyScaledValue(b, desc);
837
+ if (av === null) return bv === null ? 0 : 1;
838
+ if (bv === null) return -1;
839
+ return av < bv ? -1 : av > bv ? 1 : 0;
840
+ },
841
+ wrapReducers: (spec) => wrapMoneyReducers(spec, moneyFields)
842
+ };
843
+ }
844
+ function linkMoneyVia() {
845
+ installViaBinder("money", (cfg) => {
846
+ const c = cfg;
847
+ return moneyBinding(c.moneyFields, c.virtualMoneyFields);
848
+ });
849
+ }
850
+
851
+ // src/via/money/descriptor.ts
852
+ var MoneyPrecisionError = class extends NoydbError {
853
+ constructor(field, value, scale) {
854
+ super(
855
+ "MONEY_PRECISION",
856
+ `money: value ${JSON.stringify(value)} for field "${field}" exceeds scale ${scale} and no rounding mode is configured`
857
+ );
858
+ this.field = field;
859
+ this.value = value;
860
+ this.scale = scale;
861
+ this.name = "MoneyPrecisionError";
862
+ }
863
+ field;
864
+ value;
865
+ scale;
866
+ };
867
+ var MoneyCurrencyError = class extends NoydbError {
868
+ constructor(currency, reason, field) {
869
+ super(
870
+ "MONEY_CURRENCY",
871
+ reason === "not-allowed" ? `money: currency "${currency}" is not allowed${field ? ` for field "${field}"` : ""}` : `money: no scale known for currency "${currency}"${field ? ` (field "${field}")` : ""} \u2014 pass an explicit scale / scaleOverrides`
872
+ );
873
+ this.currency = currency;
874
+ this.reason = reason;
875
+ this.field = field;
876
+ this.name = "MoneyCurrencyError";
877
+ }
878
+ currency;
879
+ reason;
880
+ field;
881
+ };
882
+ var MoneyUnsupportedError = class extends NoydbError {
883
+ constructor(field, message) {
884
+ super(
885
+ "MONEY_UNSUPPORTED",
886
+ message ?? `money: operation is not supported on field "${field}" \u2014 use sum() and count() and divide at the boundary`
887
+ );
888
+ this.field = field;
889
+ this.name = "MoneyUnsupportedError";
890
+ }
891
+ field;
892
+ };
893
+ function isMultiOptions(o) {
894
+ return "currencies" in o;
895
+ }
896
+ function money(options) {
897
+ linkMoneyVia();
898
+ const hasFixed = "currency" in options;
899
+ const hasMulti = "currencies" in options;
900
+ if (hasFixed && hasMulti) {
901
+ throw new TypeError("money: `currency` and `currencies` are mutually exclusive");
902
+ }
903
+ if (!hasFixed && !hasMulti) {
904
+ throw new TypeError("money: one of `currency` or `currencies` is required");
905
+ }
906
+ const rounding = options.rounding;
907
+ if (isMultiOptions(options)) {
908
+ const overrides = options.scaleOverrides ?? {};
909
+ const allowList = options.currencies;
910
+ const allows = (c) => allowList === "any" ? true : allowList.includes(c);
911
+ const scaleFor = (c) => {
912
+ if (!allows(c)) throw new MoneyCurrencyError(c, "not-allowed");
913
+ const s = overrides[c] ?? scaleForCurrency(c);
914
+ if (s === null || s === void 0) throw new MoneyCurrencyError(c, "unknown-scale");
915
+ return s;
916
+ };
917
+ if (allowList !== "any") for (const c of allowList) scaleFor(c);
918
+ const soleCurrency = () => allowList !== "any" && allowList.length === 1 ? allowList[0] : void 0;
919
+ return {
920
+ _noydbMoney: true,
921
+ _viaBrand: "money",
922
+ mode: "multi",
923
+ options,
924
+ rounding,
925
+ fixedCurrency: void 0,
926
+ scaleFor,
927
+ allows,
928
+ soleCurrency
929
+ };
930
+ }
931
+ const currency = options.currency;
932
+ const resolvedScale = options.scale ?? scaleForCurrency(currency);
933
+ if (resolvedScale === null || resolvedScale === void 0) {
934
+ throw new MoneyCurrencyError(currency, "unknown-scale");
935
+ }
936
+ return {
937
+ _noydbMoney: true,
938
+ _viaBrand: "money",
939
+ mode: "fixed",
940
+ options,
941
+ rounding,
942
+ fixedCurrency: currency,
943
+ scaleFor(c) {
944
+ if (c !== currency) throw new MoneyCurrencyError(c, "not-allowed");
945
+ return resolvedScale;
946
+ },
947
+ allows: (c) => c === currency,
948
+ soleCurrency: () => currency
949
+ };
950
+ }
951
+ function isMoneyDescriptor(x) {
952
+ return typeof x === "object" && x !== null && x._noydbMoney === true;
953
+ }
954
+
955
+ // src/via/money/arith.ts
956
+ function parseAmount(label, amount, scale, rounding) {
957
+ const r = parseToScaledInt(amount, scale, rounding);
958
+ if (!r.ok) {
959
+ throw new MoneyUnsupportedError(
960
+ r.reason === "precision" ? `${label}: amount ${JSON.stringify(amount)} has more precision than scale ${scale} and no rounding mode is configured` : `${label}: amount ${JSON.stringify(amount)} is not a finite decimal`
961
+ );
962
+ }
963
+ return r.value;
964
+ }
965
+ function resolveScale(label, amount, explicit) {
966
+ if (explicit !== void 0) {
967
+ if (!Number.isInteger(explicit) || explicit < 0) {
968
+ throw new MoneyUnsupportedError(`${label}: scale must be a non-negative integer`);
969
+ }
970
+ return explicit;
971
+ }
972
+ const inferred = decimalScaleOf(amount);
973
+ if (inferred === null) {
974
+ throw new MoneyUnsupportedError(`${label}: amount ${JSON.stringify(amount)} is not a finite decimal`);
975
+ }
976
+ return inferred;
977
+ }
978
+ function mulRate(amount, rate, opts = {}) {
979
+ const scale = resolveScale("mulRate", amount, opts.scale);
980
+ const rounding = opts.rounding ?? "half-up";
981
+ const a = parseAmount("mulRate", amount, scale, rounding);
982
+ const rateScale = decimalScaleOf(rate);
983
+ if (rateScale === null) {
984
+ throw new MoneyUnsupportedError(`mulRate: rate ${JSON.stringify(rate)} is not a finite decimal`);
985
+ }
986
+ const r = parseToScaledInt(rate, rateScale);
987
+ if (!r.ok) {
988
+ throw new MoneyUnsupportedError(`mulRate: rate ${JSON.stringify(rate)} is not a finite decimal`);
989
+ }
990
+ const product = a * r.value;
991
+ return formatScaledInt(rescaleScaledInt(product, scale + rateScale, scale, rounding), scale);
992
+ }
993
+ function allocate(amount, weights, opts = {}) {
994
+ if (weights.length === 0) {
995
+ throw new MoneyUnsupportedError("allocate: weights must not be empty");
996
+ }
997
+ const scale = resolveScale("allocate", amount, opts.scale);
998
+ const a = parseAmount("allocate", amount, scale);
999
+ let weightScale = 0;
1000
+ for (const w of weights) {
1001
+ const s = decimalScaleOf(w);
1002
+ if (s === null) {
1003
+ throw new MoneyUnsupportedError(`allocate: weight ${JSON.stringify(w)} is not a finite decimal`);
1004
+ }
1005
+ if (s > weightScale) weightScale = s;
1006
+ }
1007
+ const scaledWeights = weights.map((w) => {
1008
+ const r = parseToScaledInt(w, weightScale);
1009
+ if (!r.ok || r.value < 0n) {
1010
+ throw new MoneyUnsupportedError(`allocate: weight ${JSON.stringify(w)} must be a non-negative decimal`);
1011
+ }
1012
+ return r.value;
1013
+ });
1014
+ const sumW = scaledWeights.reduce((acc, w) => acc + w, 0n);
1015
+ if (sumW === 0n) {
1016
+ throw new MoneyUnsupportedError("allocate: weights must not all be zero");
1017
+ }
1018
+ const negative = a < 0n;
1019
+ const mag = negative ? -a : a;
1020
+ const base = [];
1021
+ const remainders = [];
1022
+ let distributed = 0n;
1023
+ for (let i = 0; i < scaledWeights.length; i++) {
1024
+ const product = mag * scaledWeights[i];
1025
+ const share = product / sumW;
1026
+ base.push(share);
1027
+ distributed += share;
1028
+ remainders.push({ index: i, rem: product % sumW });
1029
+ }
1030
+ let leftover = mag - distributed;
1031
+ remainders.sort((x, y) => y.rem > x.rem ? 1 : y.rem < x.rem ? -1 : x.index - y.index);
1032
+ for (const { index } of remainders) {
1033
+ if (leftover === 0n) break;
1034
+ base[index] = base[index] + 1n;
1035
+ leftover -= 1n;
1036
+ }
1037
+ return base.map((p) => formatScaledInt(negative && p !== 0n ? -p : p, scale));
1038
+ }
1039
+
1040
+ // src/via/money/branded.ts
1041
+ function asMoney(value) {
1042
+ if (!isMoneyLike(value)) {
1043
+ throw new MoneyUnsupportedError(`asMoney: ${JSON.stringify(value)} is not a finite decimal`);
1044
+ }
1045
+ return String(value).trim();
1046
+ }
1047
+ function isMoneyString(value) {
1048
+ return typeof value === "string" && isMoneyLike(value);
1049
+ }
1050
+ function moneyNumber(value) {
1051
+ if (!isMoneyLike(value)) {
1052
+ throw new MoneyUnsupportedError(`moneyNumber: ${JSON.stringify(value)} is not a finite decimal`);
1053
+ }
1054
+ return Number(value);
1055
+ }
1056
+ function isMoneyLike(value) {
1057
+ if (typeof value === "number") return Number.isFinite(value);
1058
+ if (typeof value !== "string") return false;
1059
+ return decimalScaleOf(value) !== null;
1060
+ }
1061
+
1062
+ export {
1063
+ scaleForCurrency,
1064
+ MoneyPrecisionError,
1065
+ MoneyCurrencyError,
1066
+ MoneyUnsupportedError,
1067
+ money,
1068
+ isMoneyDescriptor,
1069
+ mulRate,
1070
+ allocate,
1071
+ asMoney,
1072
+ isMoneyString,
1073
+ moneyNumber
1074
+ };
1075
+ //# sourceMappingURL=chunk-SGDPRCC4.js.map