@noy-db/hub 0.2.0-pre.8 → 0.3.0-pre.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 (541) hide show
  1. package/README.md +129 -3
  2. package/dist/adapter/index.d.ts +5 -0
  3. package/dist/adapter/index.js +15 -0
  4. package/dist/aggregate/index.d.ts +6 -2
  5. package/dist/aggregate/index.js +24 -16
  6. package/dist/aggregate/index.js.map +1 -1
  7. package/dist/api-RW3KP7WU.js +14 -0
  8. package/dist/as/index.d.ts +7 -0
  9. package/dist/as/index.js +24 -0
  10. package/dist/at/index.d.ts +5 -0
  11. package/dist/at/index.js +1 -0
  12. package/dist/attestation/index.d.ts +15 -47
  13. package/dist/attestation/index.js +54 -10
  14. package/dist/attestation/index.js.map +1 -1
  15. package/dist/backup-XV3IOEGB.js +217 -0
  16. package/dist/backup-XV3IOEGB.js.map +1 -0
  17. package/dist/blobs/index.d.ts +6 -8
  18. package/dist/blobs/index.js +19 -12
  19. package/dist/blobs/index.js.map +1 -1
  20. package/dist/bundle/index.d.ts +16 -70
  21. package/dist/bundle/index.js +39 -476
  22. package/dist/bundle/index.js.map +1 -1
  23. package/dist/{ulid-BFJkYRRW.d.ts → bundle-CH-H06dp.d.ts} +31 -86
  24. package/dist/by/index.d.ts +1 -0
  25. package/dist/by/index.js +11 -0
  26. package/dist/cargo/index.d.ts +9 -0
  27. package/dist/cargo/index.js +89 -0
  28. package/dist/chunk-26LGBE4T.js +42 -0
  29. package/dist/chunk-26LGBE4T.js.map +1 -0
  30. package/dist/chunk-2P2HZEXU.js +233 -0
  31. package/dist/chunk-2P2HZEXU.js.map +1 -0
  32. package/dist/{chunk-K3DK3NU5.js → chunk-3YFXJ3ZP.js} +20 -5
  33. package/dist/chunk-3YFXJ3ZP.js.map +1 -0
  34. package/dist/chunk-4Q6HSHHL.js +90 -0
  35. package/dist/chunk-4Q6HSHHL.js.map +1 -0
  36. package/dist/chunk-5LUY7UTV.js +380 -0
  37. package/dist/chunk-5LUY7UTV.js.map +1 -0
  38. package/dist/chunk-5N6CZTCY.js +367 -0
  39. package/dist/chunk-5N6CZTCY.js.map +1 -0
  40. package/dist/chunk-5O3AOPDT.js +992 -0
  41. package/dist/chunk-5O3AOPDT.js.map +1 -0
  42. package/dist/chunk-5R3ERCDH.js +239 -0
  43. package/dist/chunk-5R3ERCDH.js.map +1 -0
  44. package/dist/{chunk-6774ZOQ7.js → chunk-5R5JW2JT.js} +7095 -4769
  45. package/dist/chunk-5R5JW2JT.js.map +1 -0
  46. package/dist/chunk-5TDJ56JE.js +32 -0
  47. package/dist/chunk-5TDJ56JE.js.map +1 -0
  48. package/dist/{chunk-T7JEBOGN.js → chunk-62QYRORB.js} +18 -11
  49. package/dist/chunk-62QYRORB.js.map +1 -0
  50. package/dist/{chunk-J66GRPNH.js → chunk-6S7T6WC4.js} +2 -2
  51. package/dist/chunk-6S7T6WC4.js.map +1 -0
  52. package/dist/chunk-76722EBH.js +451 -0
  53. package/dist/chunk-76722EBH.js.map +1 -0
  54. package/dist/{chunk-Z6FNBOTC.js → chunk-AIWULCUO.js} +13 -17
  55. package/dist/chunk-AIWULCUO.js.map +1 -0
  56. package/dist/{chunk-O3VZPBZG.js → chunk-AQTBSL7R.js} +47 -11
  57. package/dist/chunk-AQTBSL7R.js.map +1 -0
  58. package/dist/chunk-AURFOK3D.js +35 -0
  59. package/dist/chunk-AURFOK3D.js.map +1 -0
  60. package/dist/{chunk-53XBRIRT.js → chunk-AXRXJTE2.js} +9 -9
  61. package/dist/chunk-AXRXJTE2.js.map +1 -0
  62. package/dist/chunk-AZAOEIKW.js +155 -0
  63. package/dist/chunk-AZAOEIKW.js.map +1 -0
  64. package/dist/{chunk-HNRHLRDC.js → chunk-BG3SPSR4.js} +3 -3
  65. package/dist/chunk-BG3SPSR4.js.map +1 -0
  66. package/dist/chunk-BGIZAFY7.js +1 -0
  67. package/dist/chunk-CHFZDSE4.js +1 -0
  68. package/dist/{chunk-DJHHA6XH.js → chunk-CMGR4ZEW.js} +50 -20
  69. package/dist/chunk-CMGR4ZEW.js.map +1 -0
  70. package/dist/chunk-CWPPNPOH.js +23 -0
  71. package/dist/chunk-CWPPNPOH.js.map +1 -0
  72. package/dist/{chunk-QODLLGQ7.js → chunk-DFEMTNPJ.js} +371 -38
  73. package/dist/chunk-DFEMTNPJ.js.map +1 -0
  74. package/dist/{chunk-ZYWZWG6G.js → chunk-DGDI2D4M.js} +10 -10
  75. package/dist/chunk-DGDI2D4M.js.map +1 -0
  76. package/dist/{chunk-SYMWGEET.js → chunk-EIZUR2XW.js} +3 -3
  77. package/dist/chunk-EIZUR2XW.js.map +1 -0
  78. package/dist/{chunk-BVRYKATC.js → chunk-FISN7WE4.js} +36 -33
  79. package/dist/chunk-FISN7WE4.js.map +1 -0
  80. package/dist/chunk-GHVIKOHT.js +1 -0
  81. package/dist/chunk-GYGWYIOZ.js +200 -0
  82. package/dist/chunk-GYGWYIOZ.js.map +1 -0
  83. package/dist/chunk-HCIPRAGS.js +45 -0
  84. package/dist/chunk-HCIPRAGS.js.map +1 -0
  85. package/dist/{chunk-PX35GA7L.js → chunk-I2NOIW44.js} +10 -10
  86. package/dist/chunk-I2NOIW44.js.map +1 -0
  87. package/dist/{chunk-OIF6LZUR.js → chunk-I3TIKTJO.js} +3 -3
  88. package/dist/chunk-I3TIKTJO.js.map +1 -0
  89. package/dist/chunk-I7FD46FF.js +9 -0
  90. package/dist/chunk-I7FD46FF.js.map +1 -0
  91. package/dist/chunk-IAGBDSCS.js +40 -0
  92. package/dist/chunk-IAGBDSCS.js.map +1 -0
  93. package/dist/{chunk-JWRVQKRZ.js → chunk-IELYAOGG.js} +6 -18
  94. package/dist/chunk-IELYAOGG.js.map +1 -0
  95. package/dist/chunk-IGUYVGGI.js +205 -0
  96. package/dist/chunk-IGUYVGGI.js.map +1 -0
  97. package/dist/{chunk-U26HQ6KJ.js → chunk-IO6GRPT6.js} +4 -4
  98. package/dist/chunk-IO6GRPT6.js.map +1 -0
  99. package/dist/chunk-IPB7FTQX.js +273 -0
  100. package/dist/chunk-IPB7FTQX.js.map +1 -0
  101. package/dist/chunk-ITNUCOXM.js +148 -0
  102. package/dist/chunk-ITNUCOXM.js.map +1 -0
  103. package/dist/{chunk-WPLVTJ5D.js → chunk-IUEN57TV.js} +10 -10
  104. package/dist/chunk-IUEN57TV.js.map +1 -0
  105. package/dist/{chunk-DL3HWOQ5.js → chunk-JNUWZ6D3.js} +9 -9
  106. package/dist/chunk-JNUWZ6D3.js.map +1 -0
  107. package/dist/chunk-K2WCO3NX.js +1 -0
  108. package/dist/chunk-KVOXU4T5.js +30 -0
  109. package/dist/chunk-KVOXU4T5.js.map +1 -0
  110. package/dist/chunk-KXGNJJXB.js +135 -0
  111. package/dist/chunk-KXGNJJXB.js.map +1 -0
  112. package/dist/chunk-LB7FD65R.js +163 -0
  113. package/dist/chunk-LB7FD65R.js.map +1 -0
  114. package/dist/{chunk-22DWZL57.js → chunk-LFLXAY2W.js} +43 -218
  115. package/dist/chunk-LFLXAY2W.js.map +1 -0
  116. package/dist/chunk-LMTH2RM6.js +129 -0
  117. package/dist/chunk-LMTH2RM6.js.map +1 -0
  118. package/dist/{aggregate/index.cjs → chunk-LV7M27WM.js} +390 -219
  119. package/dist/chunk-LV7M27WM.js.map +1 -0
  120. package/dist/{chunk-PE2FR4J3.js → chunk-LXQT4WMP.js} +16 -18
  121. package/dist/chunk-LXQT4WMP.js.map +1 -0
  122. package/dist/chunk-M2YKN37S.js +524 -0
  123. package/dist/chunk-M2YKN37S.js.map +1 -0
  124. package/dist/chunk-M6OST55S.js +14 -0
  125. package/dist/chunk-M6OST55S.js.map +1 -0
  126. package/dist/{chunk-F3GDRNUT.js → chunk-MD3Y6J3L.js} +35 -69
  127. package/dist/chunk-MD3Y6J3L.js.map +1 -0
  128. package/dist/{chunk-XJFLDA7A.js → chunk-MTMJVJ5W.js} +8 -7
  129. package/dist/chunk-MTMJVJ5W.js.map +1 -0
  130. package/dist/{chunk-DFMLEQZB.js → chunk-NF5JWERG.js} +5 -10
  131. package/dist/chunk-NF5JWERG.js.map +1 -0
  132. package/dist/{chunk-DO7C2TOG.js → chunk-PKHL44ER.js} +3 -3
  133. package/dist/{chunk-DO7C2TOG.js.map → chunk-PKHL44ER.js.map} +1 -1
  134. package/dist/chunk-PSMV73A5.js +117 -0
  135. package/dist/chunk-PSMV73A5.js.map +1 -0
  136. package/dist/chunk-PY4KJPYU.js +9 -0
  137. package/dist/chunk-PY4KJPYU.js.map +1 -0
  138. package/dist/chunk-PZ5AY32C.js +10 -0
  139. package/dist/{chunk-DE6GKS6G.js → chunk-Q7SS3IME.js} +50 -9
  140. package/dist/chunk-Q7SS3IME.js.map +1 -0
  141. package/dist/chunk-QHJW5EXU.js +54 -0
  142. package/dist/chunk-QHJW5EXU.js.map +1 -0
  143. package/dist/{chunk-NONAAENK.js → chunk-RUEKROOS.js} +11 -4
  144. package/dist/chunk-RUEKROOS.js.map +1 -0
  145. package/dist/chunk-RUIMKQTA.js +23 -0
  146. package/dist/chunk-RUIMKQTA.js.map +1 -0
  147. package/dist/{chunk-TFBP23BX.js → chunk-SKF73JOP.js} +66 -7
  148. package/dist/chunk-SKF73JOP.js.map +1 -0
  149. package/dist/chunk-SM3AVUHC.js +42 -0
  150. package/dist/chunk-SM3AVUHC.js.map +1 -0
  151. package/dist/{chunk-ML236QKC.js → chunk-SMXWYP24.js} +5 -5
  152. package/dist/chunk-SMXWYP24.js.map +1 -0
  153. package/dist/chunk-SRB2XEWB.js +148 -0
  154. package/dist/chunk-SRB2XEWB.js.map +1 -0
  155. package/dist/chunk-SVLR4POP.js +64 -0
  156. package/dist/chunk-SVLR4POP.js.map +1 -0
  157. package/dist/chunk-TA66UMI4.js +123 -0
  158. package/dist/chunk-TA66UMI4.js.map +1 -0
  159. package/dist/chunk-TEILUWOI.js +664 -0
  160. package/dist/chunk-TEILUWOI.js.map +1 -0
  161. package/dist/chunk-TJYQIGAP.js +82 -0
  162. package/dist/chunk-TJYQIGAP.js.map +1 -0
  163. package/dist/{chunk-H2X3ISXG.js → chunk-UAG5KWVA.js} +7 -7
  164. package/dist/chunk-UAG5KWVA.js.map +1 -0
  165. package/dist/chunk-UDRIWL7A.js +382 -0
  166. package/dist/chunk-UDRIWL7A.js.map +1 -0
  167. package/dist/{chunk-2GLDA55J.js → chunk-UIU2THRG.js} +498 -133
  168. package/dist/chunk-UIU2THRG.js.map +1 -0
  169. package/dist/{chunk-3YPCK6JX.js → chunk-UPJNJGGA.js} +165 -423
  170. package/dist/chunk-UPJNJGGA.js.map +1 -0
  171. package/dist/chunk-UV5MFVO3.js +21 -0
  172. package/dist/chunk-UV5MFVO3.js.map +1 -0
  173. package/dist/{chunk-2WUSG3IT.js → chunk-V7RWQRG7.js} +5 -5
  174. package/dist/chunk-V7RWQRG7.js.map +1 -0
  175. package/dist/{chunk-VTKGMEPP.js → chunk-VCTFO5CO.js} +13 -3
  176. package/dist/chunk-VCTFO5CO.js.map +1 -0
  177. package/dist/{chunk-5T22KDPN.js → chunk-VFQGRQIH.js} +8 -8
  178. package/dist/chunk-VFQGRQIH.js.map +1 -0
  179. package/dist/{chunk-2QR2PQTT.js → chunk-VQNJ7UZL.js} +5 -3
  180. package/dist/chunk-VQNJ7UZL.js.map +1 -0
  181. package/dist/{chunk-DONMZAD2.js → chunk-WWGT2MDV.js} +43 -165
  182. package/dist/chunk-WWGT2MDV.js.map +1 -0
  183. package/dist/{chunk-EMIGCR7X.js → chunk-WXSYDNBT.js} +2 -2
  184. package/dist/chunk-WXSYDNBT.js.map +1 -0
  185. package/dist/chunk-WYSO2NIH.js +30 -0
  186. package/dist/chunk-WYSO2NIH.js.map +1 -0
  187. package/dist/chunk-XXYIOFUB.js +164 -0
  188. package/dist/chunk-XXYIOFUB.js.map +1 -0
  189. package/dist/{chunk-3BFJOWSU.js → chunk-Y22T3KQE.js} +35 -7
  190. package/dist/chunk-Y22T3KQE.js.map +1 -0
  191. package/dist/{chunk-A3JMGXPG.js → chunk-YMUGBZN2.js} +2 -2
  192. package/dist/chunk-YMUGBZN2.js.map +1 -0
  193. package/dist/{chunk-I5FOWO4J.js → chunk-ZCGAHGUS.js} +52 -73
  194. package/dist/chunk-ZCGAHGUS.js.map +1 -0
  195. package/dist/{chunk-FZU343FL.js → chunk-ZJADGNYF.js} +2 -2
  196. package/dist/chunk-ZJADGNYF.js.map +1 -0
  197. package/dist/{chunk-B6PB7JLN.js → chunk-ZYUC53LT.js} +427 -6
  198. package/dist/chunk-ZYUC53LT.js.map +1 -0
  199. package/dist/collection-facade-GQAOGJP2.js +33 -0
  200. package/dist/consent/index.d.ts +5 -7
  201. package/dist/consent/index.js +7 -5
  202. package/dist/consent/index.js.map +1 -1
  203. package/dist/crdt/index.d.ts +6 -2
  204. package/dist/crdt/index.js +3 -2
  205. package/dist/crdt/index.js.map +1 -1
  206. package/dist/decrypt-partition-IHtxEnTi.d.ts +21 -0
  207. package/dist/delegation-UL5HKLER.js +19 -0
  208. package/dist/derivations/index.d.ts +7 -9
  209. package/dist/derivations/index.js +11 -6
  210. package/dist/describe/index.d.ts +1 -0
  211. package/dist/describe/index.js +1 -0
  212. package/dist/describe-aBkJR2sd.d.ts +131 -0
  213. package/dist/{dev-unlock-p3ysikWP.d.ts → dev-unlock-C9Ro3v_O.d.ts} +1 -1
  214. package/dist/discriminant-BN9REW3o.d.ts +60 -0
  215. package/dist/enclave-UL5LW66V.js +88 -0
  216. package/dist/executor-2FWQRLMG.js +15 -0
  217. package/dist/executor-QZ7BXICW.js +9 -0
  218. package/dist/executor-Z5ZLJVTV.js +9 -0
  219. package/dist/export-accessible-KRV5W4GH.js +17 -0
  220. package/dist/extract-partition-GLKBOXFQ.js +30 -0
  221. package/dist/{fanout-sidecar-OKPMMPLG.js → fanout-sidecar-GF3DJ6KR.js} +34 -14
  222. package/dist/fanout-sidecar-GF3DJ6KR.js.map +1 -0
  223. package/dist/forget/index.d.ts +36 -0
  224. package/dist/forget/index.js +19 -0
  225. package/dist/forget/index.js.map +1 -0
  226. package/dist/guards/index.d.ts +13 -9
  227. package/dist/guards/index.js +12 -5
  228. package/dist/{hash-BPsYPcv_.d.cts → hash-Cp5uwiox.d.ts} +5 -1
  229. package/dist/history/index.d.ts +6 -8
  230. package/dist/history/index.js +19 -12
  231. package/dist/history/index.js.map +1 -1
  232. package/dist/i18n/index.d.ts +5 -7
  233. package/dist/i18n/index.js +104 -15
  234. package/dist/i18n/index.js.map +1 -1
  235. package/dist/in/index.d.ts +5 -0
  236. package/dist/in/index.js +1 -0
  237. package/dist/in/index.js.map +1 -0
  238. package/dist/index-B9QdHytu.d.ts +123 -0
  239. package/dist/index-BF9_96A5.d.ts +123 -0
  240. package/dist/{types-DGU60JDt.d.ts → index-BzUo1B6n.d.ts} +16306 -8352
  241. package/dist/index.d.ts +1088 -450
  242. package/dist/index.js +1165 -293
  243. package/dist/index.js.map +1 -1
  244. package/dist/indexing/index.d.ts +6 -3
  245. package/dist/indexing/index.js +6 -5
  246. package/dist/indexing/index.js.map +1 -1
  247. package/dist/issue-Y6UVIR43.js +13 -0
  248. package/dist/issue-Y6UVIR43.js.map +1 -0
  249. package/dist/kernel/index.d.ts +32 -0
  250. package/dist/kernel/index.js +53 -0
  251. package/dist/kernel/index.js.map +1 -0
  252. package/dist/{ledger-TMRZYNVJ.js → ledger-RYI35CDS.js} +12 -9
  253. package/dist/ledger-RYI35CDS.js.map +1 -0
  254. package/dist/liberate-CRPZEV7O.js +18 -0
  255. package/dist/liberate-CRPZEV7O.js.map +1 -0
  256. package/dist/materialized-views/index.d.ts +6 -19
  257. package/dist/materialized-views/index.js +16 -12
  258. package/dist/mime-magic-CGhw37_E.d.ts +103 -0
  259. package/dist/noydb-367AM4HT.js +50 -0
  260. package/dist/noydb-367AM4HT.js.map +1 -0
  261. package/dist/on/index.d.ts +5 -0
  262. package/dist/on/index.js +11 -0
  263. package/dist/on/index.js.map +1 -0
  264. package/dist/overlay-views/index.d.ts +27 -11
  265. package/dist/overlay-views/index.js +7 -6
  266. package/dist/periods/index.d.ts +5 -7
  267. package/dist/periods/index.js +13 -9
  268. package/dist/pod/index.d.ts +63 -0
  269. package/dist/pod/index.js +61 -0
  270. package/dist/pod/index.js.map +1 -0
  271. package/dist/policy-IXK4FVXP.js +41 -0
  272. package/dist/policy-IXK4FVXP.js.map +1 -0
  273. package/dist/portability/index.d.ts +20 -0
  274. package/dist/portability/index.js +43 -0
  275. package/dist/portability/index.js.map +1 -0
  276. package/dist/{public-envelope-BW6OXORV.js → public-envelope-JHDQCPSX.js} +6 -5
  277. package/dist/public-envelope-JHDQCPSX.js.map +1 -0
  278. package/dist/query/index.d.ts +5 -3
  279. package/dist/query/index.js +21 -13
  280. package/dist/read-only-facade-5ADRJVTM.js +8 -0
  281. package/dist/read-only-facade-5ADRJVTM.js.map +1 -0
  282. package/dist/registry-45RJNWGU.js +9 -0
  283. package/dist/registry-45RJNWGU.js.map +1 -0
  284. package/dist/registry-5GRV5VXI.js +13 -0
  285. package/dist/registry-5GRV5VXI.js.map +1 -0
  286. package/dist/registry-VW6P6A3J.js +8 -0
  287. package/dist/registry-VW6P6A3J.js.map +1 -0
  288. package/dist/registry-WEUCHBO4.js +11 -0
  289. package/dist/registry-WEUCHBO4.js.map +1 -0
  290. package/dist/request-withdrawal-GBPH2FDY.js +25 -0
  291. package/dist/request-withdrawal-GBPH2FDY.js.map +1 -0
  292. package/dist/revoke-TUFRGI6S.js +18 -0
  293. package/dist/revoke-TUFRGI6S.js.map +1 -0
  294. package/dist/sealed-record/index.d.ts +69 -0
  295. package/dist/sealed-record/index.js +65 -0
  296. package/dist/sealed-record/index.js.map +1 -0
  297. package/dist/session/index.d.ts +6 -8
  298. package/dist/session/index.js +7 -5
  299. package/dist/session/index.js.map +1 -1
  300. package/dist/shadow/index.d.ts +5 -7
  301. package/dist/shadow/index.js +4 -3
  302. package/dist/shadow/index.js.map +1 -1
  303. package/dist/{signer-72QAUSVW.js → signer-PNKTBVF7.js} +6 -5
  304. package/dist/signer-PNKTBVF7.js.map +1 -0
  305. package/dist/snapshots/index.d.ts +16 -11
  306. package/dist/snapshots/index.js +49 -13
  307. package/dist/snapshots/index.js.map +1 -1
  308. package/dist/{stale-6ZDBTQT7.js → stale-3JWHNDIY.js} +3 -2
  309. package/dist/stale-3JWHNDIY.js.map +1 -0
  310. package/dist/store-coordination-provider-3I7XWZZK.js +142 -0
  311. package/dist/store-coordination-provider-3I7XWZZK.js.map +1 -0
  312. package/dist/subject-index-O75wKshW.d.ts +362 -0
  313. package/dist/sync/index.d.ts +4 -6
  314. package/dist/sync/index.js +7 -6
  315. package/dist/sync/index.js.map +1 -1
  316. package/dist/team/index.d.ts +5 -7
  317. package/dist/team/index.js +20 -16
  318. package/dist/tiers/index.d.ts +5 -0
  319. package/dist/tiers/index.js +33 -0
  320. package/dist/tiers/index.js.map +1 -0
  321. package/dist/to/index.d.ts +5 -0
  322. package/dist/to/index.js +17 -0
  323. package/dist/to/index.js.map +1 -0
  324. package/dist/transition-guard-C7ol6oPw.d.ts +165 -0
  325. package/dist/tx/index.d.ts +23 -9
  326. package/dist/tx/index.js +13 -8
  327. package/dist/tx/index.js.map +1 -1
  328. package/dist/ui/index.d.ts +1 -0
  329. package/dist/ui/index.js +1 -0
  330. package/dist/ui/index.js.map +1 -0
  331. package/dist/ulid-DRH25k3y.d.ts +66 -0
  332. package/dist/ulid-PTAIMDG4.js +10 -0
  333. package/dist/ulid-PTAIMDG4.js.map +1 -0
  334. package/dist/util/index.d.ts +2 -0
  335. package/dist/util/index.js +7 -2
  336. package/dist/util/index.js.map +1 -1
  337. package/dist/vault-diff-B5fYNBL7.d.ts +147 -0
  338. package/dist/with/index.d.ts +38 -0
  339. package/dist/with/index.js +25 -0
  340. package/dist/with/index.js.map +1 -0
  341. package/dist/{with-materialized-view-BiasFcYx.d.ts → with-materialized-view-6p0Fk8bL.d.ts} +1 -1
  342. package/dist/{with-overlayed-view-CQViuko_.d.ts → with-overlayed-view-BJ6mXGMd.d.ts} +2 -3
  343. package/dist/with-rollup-BvQo3ROo.d.ts +47 -0
  344. package/dist/withdraw-accessible-FFS46EOD.js +22 -0
  345. package/dist/withdraw-accessible-FFS46EOD.js.map +1 -0
  346. package/dist/zod-HAJM7LMS.js +14763 -0
  347. package/dist/zod-HAJM7LMS.js.map +1 -0
  348. package/package.json +121 -201
  349. package/dist/aggregate/index.cjs.map +0 -1
  350. package/dist/aggregate/index.d.cts +0 -38
  351. package/dist/attestation/index.cjs +0 -305
  352. package/dist/attestation/index.cjs.map +0 -1
  353. package/dist/attestation/index.d.cts +0 -52
  354. package/dist/blobs/index.cjs +0 -1480
  355. package/dist/blobs/index.cjs.map +0 -1
  356. package/dist/blobs/index.d.cts +0 -46
  357. package/dist/bundle/index.cjs +0 -19104
  358. package/dist/bundle/index.cjs.map +0 -1
  359. package/dist/bundle/index.d.cts +0 -176
  360. package/dist/chunk-22DWZL57.js.map +0 -1
  361. package/dist/chunk-2GLDA55J.js.map +0 -1
  362. package/dist/chunk-2QR2PQTT.js.map +0 -1
  363. package/dist/chunk-2WUSG3IT.js.map +0 -1
  364. package/dist/chunk-3BFJOWSU.js.map +0 -1
  365. package/dist/chunk-3YPCK6JX.js.map +0 -1
  366. package/dist/chunk-53XBRIRT.js.map +0 -1
  367. package/dist/chunk-5T22KDPN.js.map +0 -1
  368. package/dist/chunk-5XHKQ56N.js +0 -340
  369. package/dist/chunk-5XHKQ56N.js.map +0 -1
  370. package/dist/chunk-6774ZOQ7.js.map +0 -1
  371. package/dist/chunk-6STK5TQP.js +0 -139
  372. package/dist/chunk-6STK5TQP.js.map +0 -1
  373. package/dist/chunk-A3JMGXPG.js.map +0 -1
  374. package/dist/chunk-B6PB7JLN.js.map +0 -1
  375. package/dist/chunk-BVRYKATC.js.map +0 -1
  376. package/dist/chunk-DE6GKS6G.js.map +0 -1
  377. package/dist/chunk-DFMLEQZB.js.map +0 -1
  378. package/dist/chunk-DJHHA6XH.js.map +0 -1
  379. package/dist/chunk-DL3HWOQ5.js.map +0 -1
  380. package/dist/chunk-DONMZAD2.js.map +0 -1
  381. package/dist/chunk-EMIGCR7X.js.map +0 -1
  382. package/dist/chunk-F3GDRNUT.js.map +0 -1
  383. package/dist/chunk-FZU343FL.js.map +0 -1
  384. package/dist/chunk-H2X3ISXG.js.map +0 -1
  385. package/dist/chunk-HNRHLRDC.js.map +0 -1
  386. package/dist/chunk-I5FOWO4J.js.map +0 -1
  387. package/dist/chunk-J66GRPNH.js.map +0 -1
  388. package/dist/chunk-JWRVQKRZ.js.map +0 -1
  389. package/dist/chunk-K3DK3NU5.js.map +0 -1
  390. package/dist/chunk-ML236QKC.js.map +0 -1
  391. package/dist/chunk-NONAAENK.js.map +0 -1
  392. package/dist/chunk-O3VZPBZG.js.map +0 -1
  393. package/dist/chunk-OIF6LZUR.js.map +0 -1
  394. package/dist/chunk-OQ6PIGHA.js +0 -19
  395. package/dist/chunk-OQ6PIGHA.js.map +0 -1
  396. package/dist/chunk-PE2FR4J3.js.map +0 -1
  397. package/dist/chunk-PP6W64Y3.js +0 -275
  398. package/dist/chunk-PP6W64Y3.js.map +0 -1
  399. package/dist/chunk-PX35GA7L.js.map +0 -1
  400. package/dist/chunk-QEILDE6R.js +0 -793
  401. package/dist/chunk-QEILDE6R.js.map +0 -1
  402. package/dist/chunk-QODLLGQ7.js.map +0 -1
  403. package/dist/chunk-RAZ4OVLL.js +0 -51
  404. package/dist/chunk-RAZ4OVLL.js.map +0 -1
  405. package/dist/chunk-SYMWGEET.js.map +0 -1
  406. package/dist/chunk-T7JEBOGN.js.map +0 -1
  407. package/dist/chunk-TFBP23BX.js.map +0 -1
  408. package/dist/chunk-TV3YZ35S.js +0 -90
  409. package/dist/chunk-TV3YZ35S.js.map +0 -1
  410. package/dist/chunk-U26HQ6KJ.js.map +0 -1
  411. package/dist/chunk-UF3BUNQZ.js +0 -1
  412. package/dist/chunk-UMLVJTYV.js +0 -20
  413. package/dist/chunk-UMLVJTYV.js.map +0 -1
  414. package/dist/chunk-VTKGMEPP.js.map +0 -1
  415. package/dist/chunk-W6EQLGMB.js +0 -100
  416. package/dist/chunk-W6EQLGMB.js.map +0 -1
  417. package/dist/chunk-WIRRPTFH.js +0 -17
  418. package/dist/chunk-WIRRPTFH.js.map +0 -1
  419. package/dist/chunk-WPLVTJ5D.js.map +0 -1
  420. package/dist/chunk-XJFLDA7A.js.map +0 -1
  421. package/dist/chunk-Z6FNBOTC.js.map +0 -1
  422. package/dist/chunk-ZYWZWG6G.js.map +0 -1
  423. package/dist/consent/index.cjs +0 -204
  424. package/dist/consent/index.cjs.map +0 -1
  425. package/dist/consent/index.d.cts +0 -25
  426. package/dist/crdt/index.cjs +0 -152
  427. package/dist/crdt/index.cjs.map +0 -1
  428. package/dist/crdt/index.d.cts +0 -30
  429. package/dist/crypto-HTZ4FJOP.js +0 -44
  430. package/dist/delegation-RI54P6I5.js +0 -17
  431. package/dist/derivations/index.cjs +0 -351
  432. package/dist/derivations/index.cjs.map +0 -1
  433. package/dist/derivations/index.d.cts +0 -72
  434. package/dist/dev-unlock-M4VAWNq_.d.cts +0 -263
  435. package/dist/executor-5PNY7LGW.js +0 -8
  436. package/dist/executor-B4QIYGZX.js +0 -8
  437. package/dist/executor-BWXXDQ7K.js +0 -11
  438. package/dist/fanout-sidecar-OKPMMPLG.js.map +0 -1
  439. package/dist/guards/index.cjs +0 -322
  440. package/dist/guards/index.cjs.map +0 -1
  441. package/dist/guards/index.d.cts +0 -31
  442. package/dist/hash-C1GtiOhR.d.ts +0 -63
  443. package/dist/history/index.cjs +0 -1222
  444. package/dist/history/index.cjs.map +0 -1
  445. package/dist/history/index.d.cts +0 -63
  446. package/dist/i18n/index.cjs +0 -1100
  447. package/dist/i18n/index.cjs.map +0 -1
  448. package/dist/i18n/index.d.cts +0 -39
  449. package/dist/index-4fBVt8j9.d.cts +0 -2387
  450. package/dist/index-D8I_pyJD.d.ts +0 -2387
  451. package/dist/index.cjs +0 -24334
  452. package/dist/index.cjs.map +0 -1
  453. package/dist/index.d.cts +0 -776
  454. package/dist/indexing/index.cjs +0 -742
  455. package/dist/indexing/index.cjs.map +0 -1
  456. package/dist/indexing/index.d.cts +0 -36
  457. package/dist/issue-VGDPP4B5.js +0 -12
  458. package/dist/lazy-builder-7tIpFyWN.d.ts +0 -304
  459. package/dist/lazy-builder-wY4pMCEe.d.cts +0 -304
  460. package/dist/materialized-views/index.cjs +0 -854
  461. package/dist/materialized-views/index.cjs.map +0 -1
  462. package/dist/materialized-views/index.d.cts +0 -186
  463. package/dist/mime-magic-CBBSOkjm.d.cts +0 -50
  464. package/dist/mime-magic-CBBSOkjm.d.ts +0 -50
  465. package/dist/noydb-LZBH3XDK.js +0 -34
  466. package/dist/overlay-views/index.cjs +0 -359
  467. package/dist/overlay-views/index.cjs.map +0 -1
  468. package/dist/overlay-views/index.d.cts +0 -82
  469. package/dist/periods/index.cjs +0 -1041
  470. package/dist/periods/index.cjs.map +0 -1
  471. package/dist/periods/index.d.cts +0 -22
  472. package/dist/predicate-BSAGEyu5.d.cts +0 -209
  473. package/dist/predicate-BSAGEyu5.d.ts +0 -209
  474. package/dist/query/index.cjs +0 -2375
  475. package/dist/query/index.cjs.map +0 -1
  476. package/dist/query/index.d.cts +0 -3
  477. package/dist/read-only-facade-ITU6L7BL.js +0 -7
  478. package/dist/registry-3QP3YKQS.js +0 -8
  479. package/dist/registry-DKEXOJVO.js +0 -7
  480. package/dist/registry-OJIOSBV6.js +0 -10
  481. package/dist/registry-USRVT6YF.js +0 -8
  482. package/dist/revoke-JCC7N56X.js +0 -17
  483. package/dist/session/index.cjs +0 -495
  484. package/dist/session/index.cjs.map +0 -1
  485. package/dist/session/index.d.cts +0 -46
  486. package/dist/shadow/index.cjs +0 -133
  487. package/dist/shadow/index.cjs.map +0 -1
  488. package/dist/shadow/index.d.cts +0 -17
  489. package/dist/snapshots/index.cjs +0 -903
  490. package/dist/snapshots/index.cjs.map +0 -1
  491. package/dist/snapshots/index.d.cts +0 -21
  492. package/dist/store/index.cjs +0 -1083
  493. package/dist/store/index.cjs.map +0 -1
  494. package/dist/store/index.d.cts +0 -492
  495. package/dist/store/index.d.ts +0 -492
  496. package/dist/store/index.js +0 -37
  497. package/dist/strategy-BSxFXGzb.d.cts +0 -110
  498. package/dist/strategy-BSxFXGzb.d.ts +0 -110
  499. package/dist/strategy-DSTrsZ8t.d.cts +0 -601
  500. package/dist/strategy-DSTrsZ8t.d.ts +0 -601
  501. package/dist/sync/index.cjs +0 -1062
  502. package/dist/sync/index.cjs.map +0 -1
  503. package/dist/sync/index.d.cts +0 -43
  504. package/dist/team/index.cjs +0 -2798
  505. package/dist/team/index.cjs.map +0 -1
  506. package/dist/team/index.d.cts +0 -118
  507. package/dist/tx/index.cjs +0 -544
  508. package/dist/tx/index.cjs.map +0 -1
  509. package/dist/tx/index.d.cts +0 -21
  510. package/dist/types-DjunxzJa.d.cts +0 -12776
  511. package/dist/ulid-COREQ2RQ.js +0 -9
  512. package/dist/ulid-DPeuPgi3.d.cts +0 -603
  513. package/dist/util/index.cjs +0 -230
  514. package/dist/util/index.cjs.map +0 -1
  515. package/dist/util/index.d.cts +0 -77
  516. package/dist/with-derivation-Df0kMlED.d.cts +0 -13
  517. package/dist/with-derivation-DfOpKjFw.d.ts +0 -13
  518. package/dist/with-guard-0KksDtSR.d.ts +0 -18
  519. package/dist/with-guard-C6W5RVrH.d.cts +0 -18
  520. package/dist/with-materialized-view-BmDKyHrm.d.cts +0 -27
  521. package/dist/with-overlayed-view-CA66vhHz.d.cts +0 -13
  522. /package/dist/{store → adapter}/index.js.map +0 -0
  523. /package/dist/{chunk-UF3BUNQZ.js.map → api-RW3KP7WU.js.map} +0 -0
  524. /package/dist/{crypto-HTZ4FJOP.js.map → as/index.js.map} +0 -0
  525. /package/dist/{delegation-RI54P6I5.js.map → at/index.js.map} +0 -0
  526. /package/dist/{executor-5PNY7LGW.js.map → by/index.js.map} +0 -0
  527. /package/dist/{executor-B4QIYGZX.js.map → cargo/index.js.map} +0 -0
  528. /package/dist/{executor-BWXXDQ7K.js.map → chunk-BGIZAFY7.js.map} +0 -0
  529. /package/dist/{issue-VGDPP4B5.js.map → chunk-CHFZDSE4.js.map} +0 -0
  530. /package/dist/{ledger-TMRZYNVJ.js.map → chunk-GHVIKOHT.js.map} +0 -0
  531. /package/dist/{noydb-LZBH3XDK.js.map → chunk-K2WCO3NX.js.map} +0 -0
  532. /package/dist/{public-envelope-BW6OXORV.js.map → chunk-PZ5AY32C.js.map} +0 -0
  533. /package/dist/{read-only-facade-ITU6L7BL.js.map → collection-facade-GQAOGJP2.js.map} +0 -0
  534. /package/dist/{registry-3QP3YKQS.js.map → delegation-UL5HKLER.js.map} +0 -0
  535. /package/dist/{registry-DKEXOJVO.js.map → describe/index.js.map} +0 -0
  536. /package/dist/{registry-OJIOSBV6.js.map → enclave-UL5LW66V.js.map} +0 -0
  537. /package/dist/{registry-USRVT6YF.js.map → executor-2FWQRLMG.js.map} +0 -0
  538. /package/dist/{revoke-JCC7N56X.js.map → executor-QZ7BXICW.js.map} +0 -0
  539. /package/dist/{signer-72QAUSVW.js.map → executor-Z5ZLJVTV.js.map} +0 -0
  540. /package/dist/{stale-6ZDBTQT7.js.map → export-accessible-KRV5W4GH.js.map} +0 -0
  541. /package/dist/{ulid-COREQ2RQ.js.map → extract-partition-GLKBOXFQ.js.map} +0 -0
@@ -1,15 +1,28 @@
1
1
  import {
2
+ reducerBuilder,
3
+ wrapMoneyReducers
4
+ } from "./chunk-LV7M27WM.js";
5
+ import {
6
+ MoneyPrecisionError,
2
7
  evaluateClause,
8
+ formatScaledInt,
9
+ hasFnClause,
10
+ moneyFieldClause,
11
+ parseToScaledInt,
3
12
  readPath
4
- } from "./chunk-TV3YZ35S.js";
13
+ } from "./chunk-M2YKN37S.js";
14
+ import {
15
+ applyI18nLocale
16
+ } from "./chunk-5LUY7UTV.js";
5
17
  import {
6
18
  CrossJoinSourceUnknownError,
7
19
  CrossJoinTooLargeError,
8
20
  DanglingReferenceError,
9
- JoinTooLargeError
10
- } from "./chunk-B6PB7JLN.js";
21
+ JoinTooLargeError,
22
+ ValidationError
23
+ } from "./chunk-ZYUC53LT.js";
11
24
 
12
- // src/query/join.ts
25
+ // src/kernel/query/join.ts
13
26
  var DEFAULT_JOIN_MAX_ROWS = 5e4;
14
27
  var JOIN_WARN_FRACTION = 0.8;
15
28
  function coerceRefKey(value) {
@@ -37,15 +50,15 @@ function warnCeilingApproaching(target, side, rows, maxRows) {
37
50
  `[noy-db] .join() ${side} side is at ${pct}% of the ${maxRows}-row ceiling for target "${target}" (${rows} rows). Streaming joins over scan() are not yet supported for collections that need to exceed this.`
38
51
  );
39
52
  }
40
- function applyJoins(rows, joins, context) {
53
+ function applyJoins(rows, joins, context, locale) {
41
54
  if (joins.length === 0) return [...rows];
42
55
  let result = [...rows];
43
56
  for (const leg of joins) {
44
- result = applyOneJoin(result, leg, context);
57
+ result = applyOneJoin(result, leg, context, locale);
45
58
  }
46
59
  return result;
47
60
  }
48
- function applyOneJoin(leftRows, leg, context) {
61
+ function applyOneJoin(leftRows, leg, context, locale) {
49
62
  if (leg.isDictJoin) {
50
63
  const dictSource = context.resolveDictSource?.(leg.field);
51
64
  if (!dictSource) {
@@ -100,24 +113,27 @@ function applyOneJoin(leftRows, leg, context) {
100
113
  if (rightSnapshot.length > maxRows * JOIN_WARN_FRACTION) {
101
114
  warnCeilingApproaching(leg.target, "right", rightSnapshot.length, maxRows);
102
115
  }
116
+ const effLocale = locale ?? context.defaultLocale;
117
+ const i18nResolve = effLocale !== void 0 && source.i18nFields !== void 0 ? (right) => right !== null && typeof right === "object" ? applyI18nLocale(right, source.i18nFields, effLocale, void 0, "join") : right : void 0;
103
118
  const strategy = leg.strategy ?? (source.lookupById ? "nested" : "hash");
104
119
  if (strategy === "nested" && source.lookupById) {
105
120
  const lookup = (id) => source.lookupById?.(id);
106
- return nestedLoopJoin(leftRows, leg, lookup);
121
+ return nestedLoopJoin(leftRows, leg, lookup, i18nResolve);
107
122
  }
108
- return hashJoin(leftRows, leg, rightSnapshot);
123
+ return hashJoin(leftRows, leg, rightSnapshot, i18nResolve);
109
124
  }
110
- function nestedLoopJoin(leftRows, leg, lookupById) {
125
+ function nestedLoopJoin(leftRows, leg, lookupById, i18nResolve) {
111
126
  const out = [];
112
127
  for (const left of leftRows) {
113
128
  const rawId = readPath(left, leg.field);
114
129
  const key = coerceRefKey(rawId);
115
- const right = key === null ? void 0 : lookupById(key);
130
+ let right = key === null ? void 0 : lookupById(key);
131
+ if (i18nResolve && right !== void 0) right = i18nResolve(right);
116
132
  out.push(attachJoin(left, leg, right, rawId));
117
133
  }
118
134
  return out;
119
135
  }
120
- function hashJoin(leftRows, leg, rightSnapshot) {
136
+ function hashJoin(leftRows, leg, rightSnapshot, i18nResolve) {
121
137
  const rightMap = /* @__PURE__ */ new Map();
122
138
  for (const record of rightSnapshot) {
123
139
  const rawId = readPath(record, "id");
@@ -130,7 +146,8 @@ function hashJoin(leftRows, leg, rightSnapshot) {
130
146
  for (const left of leftRows) {
131
147
  const rawId = readPath(left, leg.field);
132
148
  const key = coerceRefKey(rawId);
133
- const right = key === null ? void 0 : rightMap.get(key);
149
+ let right = key === null ? void 0 : rightMap.get(key);
150
+ if (i18nResolve && right !== void 0) right = i18nResolve(right);
134
151
  out.push(attachJoin(left, leg, right, rawId));
135
152
  }
136
153
  return out;
@@ -164,7 +181,7 @@ function resetJoinWarnings() {
164
181
  warnedCeilingKeys.clear();
165
182
  }
166
183
 
167
- // src/query/live.ts
184
+ // src/kernel/query/live.ts
168
185
  function buildLiveQuery(recompute, upstreams) {
169
186
  return new LiveQueryImpl(recompute, upstreams);
170
187
  }
@@ -235,7 +252,7 @@ var LiveQueryImpl = class {
235
252
  }
236
253
  };
237
254
 
238
- // src/aggregate/strategy.ts
255
+ // src/with-lookup/aggregate/strategy.ts
239
256
  var NOT_ENABLED = new Error(
240
257
  'Aggregate / groupBy is not enabled on this Noydb instance. Import `{ withAggregate }` from "@noy-db/hub/aggregate" and pass it to `createNoydb({ aggregateStrategy: withAggregate() })`.'
241
258
  );
@@ -254,7 +271,278 @@ var NO_AGGREGATE = {
254
271
  }
255
272
  };
256
273
 
257
- // src/query/builder.ts
274
+ // src/with-shape/money/paths.ts
275
+ var SEGMENT_RE = /^(\*|[^.[\]*]+)(\[\])?$/;
276
+ var parseCache = /* @__PURE__ */ new Map();
277
+ function parseMoneyPath(path) {
278
+ const cached = parseCache.get(path);
279
+ if (cached) return cached;
280
+ if (typeof path !== "string" || path.length === 0) {
281
+ throw new ValidationError("moneyFields: path must be a non-empty string");
282
+ }
283
+ const segments = [];
284
+ for (const part of path.split(".")) {
285
+ const m = SEGMENT_RE.exec(part);
286
+ if (!m) {
287
+ throw new ValidationError(
288
+ `moneyFields: invalid path "${path}" \u2014 segment "${part}" must be a key, "key[]", "*", or "*[]"`
289
+ );
290
+ }
291
+ const array = m[2] === "[]";
292
+ segments.push(
293
+ m[1] === "*" ? { kind: "wildcard", array } : { kind: "key", key: m[1], array }
294
+ );
295
+ }
296
+ parseCache.set(path, segments);
297
+ return segments;
298
+ }
299
+ function isSimpleMoneyPath(path) {
300
+ return !path.includes(".") && !path.includes("[") && !path.includes("*");
301
+ }
302
+ function validateMoneyFieldPaths(moneyFields) {
303
+ for (const path of Object.keys(moneyFields)) parseMoneyPath(path);
304
+ }
305
+ function transformAtMoneyPath(node, path, segments, index, visit, lenient) {
306
+ if (node === null || node === void 0) return node;
307
+ const seg = segments[index];
308
+ const last = index === segments.length - 1;
309
+ if (seg.kind === "key") {
310
+ if (typeof node !== "object" || Array.isArray(node)) {
311
+ if (lenient) return node;
312
+ throw new ValidationError(
313
+ `moneyFields: path "${path}" expected an object at segment "${seg.key}", got ${Array.isArray(node) ? "an array" : typeof node}`
314
+ );
315
+ }
316
+ const obj2 = node;
317
+ if (!(seg.key in obj2) || obj2[seg.key] === null || obj2[seg.key] === void 0) return node;
318
+ if (seg.array) {
319
+ const arr = obj2[seg.key];
320
+ if (!Array.isArray(arr)) {
321
+ if (lenient) return node;
322
+ throw new ValidationError(
323
+ `moneyFields: path "${path}" declares "${seg.key}[]" but the value is not an array`
324
+ );
325
+ }
326
+ const cloned = [...arr];
327
+ if (last) {
328
+ for (let i = 0; i < cloned.length; i++) visit(cloned, i);
329
+ } else {
330
+ for (let i = 0; i < cloned.length; i++) {
331
+ cloned[i] = transformAtMoneyPath(cloned[i], path, segments, index + 1, visit, lenient);
332
+ }
333
+ }
334
+ return { ...obj2, [seg.key]: cloned };
335
+ }
336
+ const clone2 = { ...obj2 };
337
+ if (last) {
338
+ visit(clone2, seg.key);
339
+ } else {
340
+ clone2[seg.key] = transformAtMoneyPath(clone2[seg.key], path, segments, index + 1, visit, lenient);
341
+ }
342
+ return clone2;
343
+ }
344
+ if (seg.array) {
345
+ if (!Array.isArray(node)) {
346
+ if (lenient) return node;
347
+ throw new ValidationError(`moneyFields: path "${path}" declares "*[]" but the value is not an array`);
348
+ }
349
+ const cloned = [...node];
350
+ if (last) {
351
+ for (let i = 0; i < cloned.length; i++) visit(cloned, i);
352
+ } else {
353
+ for (let i = 0; i < cloned.length; i++) {
354
+ cloned[i] = transformAtMoneyPath(cloned[i], path, segments, index + 1, visit, lenient);
355
+ }
356
+ }
357
+ return cloned;
358
+ }
359
+ if (typeof node !== "object" || Array.isArray(node)) {
360
+ if (lenient) return node;
361
+ throw new ValidationError(
362
+ `moneyFields: path "${path}" applies "*" to a non-object (${Array.isArray(node) ? 'array \u2014 use "*[]"' : typeof node})`
363
+ );
364
+ }
365
+ const obj = node;
366
+ const clone = { ...obj };
367
+ for (const key of Object.keys(obj)) {
368
+ const v = clone[key];
369
+ if (v === null || v === void 0) continue;
370
+ if (last) visit(clone, key);
371
+ else clone[key] = transformAtMoneyPath(v, path, segments, index + 1, visit, lenient);
372
+ }
373
+ return clone;
374
+ }
375
+
376
+ // src/with-shape/money/normalize.ts
377
+ function isMoneyValueObject(v) {
378
+ return typeof v === "object" && v !== null && "currency" in v;
379
+ }
380
+ function quantizeAmount(field, input, scale, rounding) {
381
+ const r = parseToScaledInt(input, scale, rounding);
382
+ if (!r.ok) {
383
+ if (r.reason === "precision") throw new MoneyPrecisionError(field, input, scale);
384
+ throw new TypeError(`money: field "${field}" value ${JSON.stringify(input)} is not a finite decimal`);
385
+ }
386
+ return r.value.toString();
387
+ }
388
+ function canonicalizeStoredMoney(record, moneyFields) {
389
+ if (record === null || record === void 0) return record;
390
+ if (!moneyFields || Object.keys(moneyFields).length === 0) return record;
391
+ return decodeMoneyFields(record, moneyFields, "raw");
392
+ }
393
+ function canonicalizeIncomingMoney(record, moneyFields) {
394
+ if (!moneyFields || Object.keys(moneyFields).length === 0) return record;
395
+ try {
396
+ return decodeMoneyFields(
397
+ quantizeMoneyFields(record, moneyFields),
398
+ moneyFields,
399
+ "raw"
400
+ );
401
+ } catch {
402
+ return record;
403
+ }
404
+ }
405
+ function quantizeValue(field, raw, desc) {
406
+ if (desc.mode === "fixed") {
407
+ const currency2 = desc.fixedCurrency;
408
+ return quantizeAmount(field, raw, desc.scaleFor(currency2), desc.rounding);
409
+ }
410
+ let amount;
411
+ let currency;
412
+ if (isMoneyValueObject(raw)) {
413
+ currency = String(raw.currency);
414
+ amount = raw.amount;
415
+ } else {
416
+ const sole = desc.soleCurrency();
417
+ if (sole === void 0) {
418
+ throw new TypeError(
419
+ `money: field "${field}" is multi-currency \u2014 write { amount, currency }, not a bare amount`
420
+ );
421
+ }
422
+ currency = sole;
423
+ amount = raw;
424
+ }
425
+ const scale = desc.scaleFor(currency);
426
+ return { amount: quantizeAmount(field, amount, scale, desc.rounding), currency };
427
+ }
428
+ function quantizeMoneyFields(record, moneyFields) {
429
+ let out = { ...record };
430
+ for (const [path, desc] of Object.entries(moneyFields)) {
431
+ if (isSimpleMoneyPath(path)) {
432
+ const raw = out[path];
433
+ if (raw === null || raw === void 0) continue;
434
+ out[path] = quantizeValue(path, raw, desc);
435
+ continue;
436
+ }
437
+ out = transformAtMoneyPath(
438
+ out,
439
+ path,
440
+ parseMoneyPath(path),
441
+ 0,
442
+ (container, key) => {
443
+ const raw = container[key];
444
+ if (raw === null || raw === void 0) return;
445
+ container[key] = quantizeValue(path, raw, desc);
446
+ },
447
+ /* lenient */
448
+ false
449
+ );
450
+ }
451
+ return out;
452
+ }
453
+ function formatCurrency(decimal, currency, scale, locale) {
454
+ const fmt = new Intl.NumberFormat(locale, {
455
+ style: "currency",
456
+ currency,
457
+ minimumFractionDigits: scale,
458
+ maximumFractionDigits: scale
459
+ });
460
+ return fmt.format(decimal);
461
+ }
462
+ function moneyScaledValue(stored, desc) {
463
+ let raw;
464
+ if (desc.mode === "fixed") {
465
+ raw = stored;
466
+ } else {
467
+ if (!isMoneyValueObject(stored)) return null;
468
+ raw = stored.amount;
469
+ }
470
+ if (typeof raw !== "string" && typeof raw !== "number") return null;
471
+ try {
472
+ return BigInt(String(raw));
473
+ } catch {
474
+ return null;
475
+ }
476
+ }
477
+ function decodeValue(stored, desc) {
478
+ let currency;
479
+ let scaledIntString;
480
+ if (desc.mode === "fixed") {
481
+ if (typeof stored !== "string" && typeof stored !== "number") return null;
482
+ currency = desc.fixedCurrency;
483
+ scaledIntString = String(stored);
484
+ } else {
485
+ if (!isMoneyValueObject(stored)) return null;
486
+ const amount = stored.amount;
487
+ if (typeof stored.currency !== "string" || typeof amount !== "string" && typeof amount !== "number") return null;
488
+ currency = stored.currency;
489
+ scaledIntString = String(amount);
490
+ }
491
+ const scale = desc.scaleFor(currency);
492
+ let decimal;
493
+ try {
494
+ decimal = formatScaledInt(BigInt(scaledIntString), scale);
495
+ } catch {
496
+ return null;
497
+ }
498
+ return {
499
+ decoded: desc.mode === "fixed" ? decimal : { amount: decimal, currency },
500
+ decimal,
501
+ currency,
502
+ scale
503
+ };
504
+ }
505
+ function decodeMoneyFields(record, moneyFields, locale) {
506
+ let out = { ...record };
507
+ const format = locale !== "raw";
508
+ const fmtLocale = typeof locale === "string" && locale !== "raw" ? locale : "en-US";
509
+ for (const [path, desc] of Object.entries(moneyFields)) {
510
+ if (isSimpleMoneyPath(path)) {
511
+ const stored = out[path];
512
+ if (stored === null || stored === void 0) continue;
513
+ const r = decodeValue(stored, desc);
514
+ if (r === null) continue;
515
+ out[path] = r.decoded;
516
+ if (format) {
517
+ out[`${path}Formatted`] = formatCurrency(r.decimal, r.currency, r.scale, fmtLocale);
518
+ out[`${path}Number`] = Number(r.decimal);
519
+ }
520
+ continue;
521
+ }
522
+ out = transformAtMoneyPath(
523
+ out,
524
+ path,
525
+ parseMoneyPath(path),
526
+ 0,
527
+ (container, key) => {
528
+ const stored = container[key];
529
+ if (stored === null || stored === void 0) return;
530
+ const r = decodeValue(stored, desc);
531
+ if (r === null) return;
532
+ container[key] = r.decoded;
533
+ if (format && typeof key === "string" && !Array.isArray(container)) {
534
+ container[`${key}Formatted`] = formatCurrency(r.decimal, r.currency, r.scale, fmtLocale);
535
+ container[`${key}Number`] = Number(r.decimal);
536
+ }
537
+ },
538
+ /* lenient */
539
+ true
540
+ );
541
+ }
542
+ return out;
543
+ }
544
+
545
+ // src/kernel/query/builder.ts
258
546
  var EMPTY_PLAN = {
259
547
  clauses: [],
260
548
  orderBy: [],
@@ -307,6 +595,36 @@ var Query = class _Query {
307
595
  predicates
308
596
  );
309
597
  }
598
+ /**
599
+ * @internal — the ids of records matching this query's plan,
600
+ * recovered by reference identity: `executePlanWithSource` returns the
601
+ * ORIGINAL snapshot record references (money-decode and joins are applied
602
+ * later, in `toArray`), so each matched record is found in the id-paired
603
+ * `snapshotEntries()` map. Used by `collection.retrieve({ within })`.
604
+ * Throws if the source is not collection-backed (no `snapshotEntries`).
605
+ */
606
+ _idArray() {
607
+ const entries = this.source.snapshotEntries?.();
608
+ if (entries === void 0) {
609
+ throw new Error(
610
+ "Query._idArray(): the query source has no snapshotEntries(); retrieve({ within }) requires a collection-backed query (collection.query())."
611
+ );
612
+ }
613
+ if (this.plan.clauses.some((c) => c.type === "crossJoin")) {
614
+ throw new Error(
615
+ "Query._idArray(): retrieve({ within }) does not support crossJoin queries (cross-join produces new row objects, breaking id recovery). Use where/filter/and/or, or a projection .join()."
616
+ );
617
+ }
618
+ const refToId = /* @__PURE__ */ new Map();
619
+ for (const { id, record } of entries) refToId.set(record, id);
620
+ const matched = executePlanWithSource(this.source, this.plan, this.joinContext);
621
+ const ids = [];
622
+ for (const r of matched) {
623
+ const id = refToId.get(r);
624
+ if (id !== void 0) ids.push(id);
625
+ }
626
+ return ids;
627
+ }
310
628
  /**
311
629
  * Filter by a registered deterministic predicate. Requires
312
630
  * the Query to have been augmented with a predicates map (typically
@@ -346,9 +664,18 @@ var Query = class _Query {
346
664
  this.predicates
347
665
  );
348
666
  }
349
- /** Add a field comparison. Multiple where() calls are AND-combined. */
667
+ /**
668
+ * Add a field comparison. Multiple where() calls are AND-combined.
669
+ *
670
+ * A declared money field compares in MAJOR units: the operand
671
+ * (`10000`, `'10000.00'`, or `{ amount, currency }` in multi mode) is
672
+ * quantized into stored scaled-int space at build time and evaluated
673
+ * BigInt-exact per record. A malformed operand or a string operator
674
+ * (`contains`/`startsWith`) throws here, at the call site.
675
+ */
350
676
  where(field, op, value) {
351
- const clause = { type: "field", field, op, value };
677
+ const desc = this.source.moneyFields?.[field];
678
+ const clause = desc ? moneyFieldClause(field, op, value, desc) : { type: "field", field, op, value };
352
679
  return new _Query(
353
680
  this.source,
354
681
  { ...this.plan, clauses: [...this.plan.clauses, clause] },
@@ -414,11 +741,16 @@ var Query = class _Query {
414
741
  this.predicates
415
742
  );
416
743
  }
417
- /** Sort by a field. Subsequent calls are tie-breakers. */
418
- orderBy(field, direction = "asc") {
744
+ /**
745
+ * Sort by a field. Subsequent calls are tie-breakers. Pass
746
+ * `{ by: 'label' }` to sort a `dictKey`/`staticDict` field by its resolved
747
+ * label at the query locale instead of the stored code.
748
+ */
749
+ orderBy(field, direction = "asc", opts) {
750
+ const entry = opts?.by === "label" ? { field, direction, by: "label" } : { field, direction };
419
751
  return new _Query(
420
752
  this.source,
421
- { ...this.plan, orderBy: [...this.plan.orderBy, { field, direction }] },
753
+ { ...this.plan, orderBy: [...this.plan.orderBy, entry] },
422
754
  this.joinContext,
423
755
  this.aggregateStrategy,
424
756
  this.predicates
@@ -621,20 +953,42 @@ var Query = class _Query {
621
953
  * carries any join legs, they are applied after `where` / `orderBy`
622
954
  * / `limit` / `offset` narrow the left set. See the `.join()` doc
623
955
  * for the ordering rationale.
956
+ *
957
+ * `opts.locale` resolves JOINED right-side i18n fields at the
958
+ * `join` layer to that locale; without it, the owning collection's default
959
+ * locale applies, and a locale-less query leaves joined i18n fields raw.
960
+ * (Left/base i18n fields are resolved by `get`/`list`, not here.)
624
961
  */
625
- toArray() {
626
- const base = executePlanWithSource(this.source, this.plan, this.joinContext);
962
+ toArray(opts) {
963
+ const base = this.decodeMoney(executePlanWithSource(this.source, this.plan, this.joinContext, opts?.locale));
627
964
  if (this.plan.joins.length === 0) return base;
628
965
  if (!this.joinContext) {
629
966
  throw new Error(
630
967
  `Query.toArray(): plan carries ${this.plan.joins.length} join leg(s) but no JoinContext is attached. This usually means the Query was constructed via the raw Query constructor with a plan that had joins pre-populated. Use collection.query().join(...) instead.`
631
968
  );
632
969
  }
633
- return applyJoins(base, this.plan.joins, this.joinContext);
970
+ return applyJoins(base, this.plan.joins, this.joinContext, opts?.locale);
634
971
  }
635
- /** Return the first matching record, or null. Joins are applied. */
636
- first() {
637
- const arr = this.limit(1).toArray();
972
+ /**
973
+ * Decode this source's money fields on read (stored scaled-int → canonical
974
+ * decimal), so `query().toArray()` agrees with `get()`/`sum()` on the value.
975
+ * No-op when the source declares no money fields.
976
+ *
977
+ * The query layer carries no locale context, so we decode with `'raw'` —
978
+ * canonical decimal, WITHOUT fabricating locale-formatted `<field>Formatted`
979
+ * / `<field>Number` virtuals. Producing a guessed-locale string here would
980
+ * reintroduce a "two read paths disagree" failure on the virtual
981
+ * field (e.g. it-IT via `get()` vs en-US here). Consumers who need formatted
982
+ * money read through `get()`/`list()` with a locale.
983
+ */
984
+ decodeMoney(records) {
985
+ const moneyFields = this.source.moneyFields;
986
+ if (!moneyFields || Object.keys(moneyFields).length === 0) return records;
987
+ return records.map((r) => decodeMoneyFields(r, moneyFields, "raw"));
988
+ }
989
+ /** Return the first matching record, or null. Joins are applied. `opts.locale` resolves joined i18n fields. */
990
+ first(opts) {
991
+ const arr = this.limit(1).toArray(opts);
638
992
  return arr[0] ?? null;
639
993
  }
640
994
  /**
@@ -657,49 +1011,14 @@ var Query = class _Query {
657
1011
  }
658
1012
  const { candidates, remainingClauses } = candidateRecords(this.source, this.plan.clauses);
659
1013
  if (remainingClauses.length === 0) return candidates.length;
660
- return filterRecords(candidates, remainingClauses).length;
1014
+ return filterRecords(candidates, remainingClauses, fnViewDecoder(this.source)).length;
661
1015
  }
662
- /**
663
- * Reduce the matching records through a named set of reducers.
664
- * the aggregation terminal.
665
- *
666
- * ```ts
667
- * const { total, n, avgAmount } = invoices.query()
668
- * .where('status', '==', 'open')
669
- * .aggregate({
670
- * total: sum('amount'),
671
- * n: count(),
672
- * avgAmount: avg('amount'),
673
- * })
674
- * .run()
675
- * ```
676
- *
677
- * Returns an `Aggregation<R>` wrapper with two terminals:
678
- * - `.run(): R` — synchronous one-shot reduction
679
- * - `.live(): LiveAggregation<R>` — reactive primitive that
680
- * re-runs the reduction whenever the source notifies of a
681
- * change. Always call `live.stop()` when finished.
682
- *
683
- * The reducer spec is bound here once and reused by both
684
- * terminals — this is why `.aggregate()` returns a wrapper instead
685
- * of being a direct terminal. Consumers who only need the static
686
- * value read `.run()`; consumers wiring a reactive UI read
687
- * `.live()`.
688
- *
689
- * Joins are intentionally NOT applied to aggregations in —
690
- * the same logic as `.count()`. Joins in are projection-only
691
- * (they attach an aliased field and never filter), so running
692
- * them just to throw the aliases away would be wasteful. If you
693
- * need a reducer that reads a joined field, open an issue —
694
- * aggregations-across-joins is explicitly out of scope for v1.
695
- *
696
- * Every reducer factory accepts an optional `{ seed }` parameter
697
- * that is plumbed through the protocol but unused by the
698
- * executor — that's constraint #2. When partition-aware
699
- * aggregation lands, the seed will carry running state across
700
- * partition boundaries without an API break.
701
- */
702
- aggregate(spec) {
1016
+ aggregate(specOrBuild) {
1017
+ let spec = typeof specOrBuild === "function" ? specOrBuild(reducerBuilder) : specOrBuild;
1018
+ const moneyFields = this.source.moneyFields;
1019
+ if (moneyFields) {
1020
+ spec = wrapMoneyReducers(spec, moneyFields);
1021
+ }
703
1022
  const source = this.source;
704
1023
  const clauses = this.plan.clauses;
705
1024
  const joinCtx = this.joinContext;
@@ -710,7 +1029,7 @@ var Query = class _Query {
710
1029
  return executeClausePipeline(source, clauses, joinCtx);
711
1030
  }
712
1031
  const { candidates, remainingClauses } = candidateRecords(source, clauses);
713
- return remainingClauses.length === 0 ? candidates : filterRecords(candidates, remainingClauses);
1032
+ return remainingClauses.length === 0 ? candidates : filterRecords(candidates, remainingClauses, fnViewDecoder(source));
714
1033
  };
715
1034
  const upstreams = [];
716
1035
  if (source.subscribe) {
@@ -733,7 +1052,7 @@ var Query = class _Query {
733
1052
  return executeClausePipeline(source, clauses, joinCtx);
734
1053
  }
735
1054
  const { candidates, remainingClauses } = candidateRecords(source, clauses);
736
- return remainingClauses.length === 0 ? candidates : filterRecords(candidates, remainingClauses);
1055
+ return remainingClauses.length === 0 ? candidates : filterRecords(candidates, remainingClauses, fnViewDecoder(source));
737
1056
  };
738
1057
  const upstreams = [];
739
1058
  if (source.subscribe) {
@@ -747,13 +1066,15 @@ var Query = class _Query {
747
1066
  executeRecords,
748
1067
  field,
749
1068
  upstreams,
750
- dictLabelResolver
1069
+ dictLabelResolver,
1070
+ this.source.moneyFields
751
1071
  );
752
1072
  }
753
1073
  return this.aggregateStrategy.groupByN(
754
1074
  executeRecords,
755
1075
  fields,
756
- upstreams
1076
+ upstreams,
1077
+ this.source.moneyFields
757
1078
  );
758
1079
  }
759
1080
  /**
@@ -871,7 +1192,7 @@ var Query = class _Query {
871
1192
  return serializePlan(this.plan);
872
1193
  }
873
1194
  };
874
- function executePlanWithSource(source, plan, joinContext) {
1195
+ function executePlanWithSource(source, plan, joinContext, locale) {
875
1196
  const hasCrossJoins = plan.clauses.some((c) => c.type === "crossJoin");
876
1197
  let result;
877
1198
  if (hasCrossJoins) {
@@ -883,10 +1204,11 @@ function executePlanWithSource(source, plan, joinContext) {
883
1204
  result = executeClausePipeline(source, plan.clauses, joinContext);
884
1205
  } else {
885
1206
  const { candidates, remainingClauses } = candidateRecords(source, plan.clauses);
886
- result = remainingClauses.length === 0 ? [...candidates] : filterRecords(candidates, remainingClauses);
1207
+ result = remainingClauses.length === 0 ? [...candidates] : filterRecords(candidates, remainingClauses, fnViewDecoder(source));
887
1208
  }
888
1209
  if (plan.orderBy.length > 0) {
889
- result = sortRecords(result, plan.orderBy);
1210
+ const labelMaps = buildOrderLabelMaps(plan.orderBy, joinContext, locale);
1211
+ result = sortRecords(result, plan.orderBy, source.moneyFields, labelMaps);
890
1212
  }
891
1213
  if (plan.offset > 0) {
892
1214
  result = result.slice(plan.offset);
@@ -906,6 +1228,7 @@ function candidateRecords(source, clauses) {
906
1228
  const clause = clauses[i];
907
1229
  if (clause.type !== "field") continue;
908
1230
  if (!indexes.has(clause.field)) continue;
1231
+ if (clause.money?.mode === "multi") continue;
909
1232
  let ids = null;
910
1233
  if (clause.op === "==") {
911
1234
  ids = indexes.lookupEqual(clause.field, clause.value);
@@ -951,13 +1274,20 @@ function executePlan(records, plan) {
951
1274
  }
952
1275
  return result;
953
1276
  }
954
- function filterRecords(records, clauses) {
1277
+ function fnViewDecoder(source) {
1278
+ const mf = source.moneyFields;
1279
+ if (!mf || Object.keys(mf).length === 0) return void 0;
1280
+ return (r) => decodeMoneyFields(r, mf, "raw");
1281
+ }
1282
+ function filterRecords(records, clauses, decodeForFns) {
955
1283
  if (clauses.length === 0) return [...records];
1284
+ const needsFnView = decodeForFns !== void 0 && hasFnClause(clauses);
956
1285
  const out = [];
957
1286
  for (const r of records) {
1287
+ const fnView = needsFnView ? decodeForFns(r) : void 0;
958
1288
  let matches = true;
959
1289
  for (const clause of clauses) {
960
- if (!evaluateClause(r, clause)) {
1290
+ if (!evaluateClause(r, clause, fnView)) {
961
1291
  matches = false;
962
1292
  break;
963
1293
  }
@@ -969,10 +1299,11 @@ function filterRecords(records, clauses) {
969
1299
  function executeClausePipeline(source, clauses, joinContext) {
970
1300
  let rel = [...source.snapshot()];
971
1301
  let filterBatch = [];
1302
+ const decodeForFns = fnViewDecoder(source);
972
1303
  for (const clause of clauses) {
973
1304
  if (clause.type === "crossJoin") {
974
1305
  if (filterBatch.length > 0) {
975
- rel = filterRecords(rel, filterBatch);
1306
+ rel = filterRecords(rel, filterBatch, decodeForFns);
976
1307
  filterBatch = [];
977
1308
  }
978
1309
  const rightSource = joinContext.resolveSource(clause.target);
@@ -985,7 +1316,7 @@ function executeClausePipeline(source, clauses, joinContext) {
985
1316
  }
986
1317
  }
987
1318
  if (filterBatch.length > 0) {
988
- rel = filterRecords(rel, filterBatch);
1319
+ rel = filterRecords(rel, filterBatch, decodeForFns);
989
1320
  }
990
1321
  return rel;
991
1322
  }
@@ -1034,17 +1365,55 @@ function applyCrossJoin(leftRel, clause, rightSource) {
1034
1365
  }
1035
1366
  return expanded;
1036
1367
  }
1037
- function sortRecords(records, orderBy) {
1368
+ function sortRecords(records, orderBy, moneyFields, labelMaps) {
1038
1369
  return [...records].sort((a, b) => {
1039
- for (const { field, direction } of orderBy) {
1040
- const av = readField(a, field);
1041
- const bv = readField(b, field);
1042
- const cmp = compareValues(av, bv);
1370
+ for (const { field, direction, by } of orderBy) {
1371
+ let av = readField(a, field);
1372
+ let bv = readField(b, field);
1373
+ const labelMap = by === "label" ? labelMaps?.get(field) : void 0;
1374
+ if (labelMap) {
1375
+ av = (typeof av === "string" ? labelMap.get(av) : void 0) ?? av;
1376
+ bv = (typeof bv === "string" ? labelMap.get(bv) : void 0) ?? bv;
1377
+ const cmp2 = compareValues(av, bv);
1378
+ if (cmp2 !== 0) return direction === "asc" ? cmp2 : -cmp2;
1379
+ continue;
1380
+ }
1381
+ const desc = moneyFields?.[field];
1382
+ const cmp = desc ? compareMoney(av, bv, desc) : compareValues(av, bv);
1043
1383
  if (cmp !== 0) return direction === "asc" ? cmp : -cmp;
1044
1384
  }
1045
1385
  return 0;
1046
1386
  });
1047
1387
  }
1388
+ function buildOrderLabelMaps(orderBy, joinContext, locale) {
1389
+ if (!joinContext?.resolveDictSource) return void 0;
1390
+ const resolveDict = joinContext.resolveDictSource.bind(joinContext);
1391
+ let maps;
1392
+ for (const { field, by } of orderBy) {
1393
+ if (by !== "label") continue;
1394
+ const dictSource = resolveDict(field);
1395
+ if (!dictSource) continue;
1396
+ const loc = locale ?? dictSource.displayLocale;
1397
+ if (loc === void 0) continue;
1398
+ const codeToLabel = /* @__PURE__ */ new Map();
1399
+ for (const entry of dictSource.snapshot()) {
1400
+ const k = entry["key"];
1401
+ const labels = entry["labels"];
1402
+ const label = labels?.[loc];
1403
+ if (typeof k === "string" && typeof label === "string") codeToLabel.set(k, label);
1404
+ }
1405
+ ;
1406
+ (maps ??= /* @__PURE__ */ new Map()).set(field, codeToLabel);
1407
+ }
1408
+ return maps;
1409
+ }
1410
+ function compareMoney(a, b, desc) {
1411
+ const av = moneyScaledValue(a, desc);
1412
+ const bv = moneyScaledValue(b, desc);
1413
+ if (av === null) return bv === null ? 0 : 1;
1414
+ if (bv === null) return -1;
1415
+ return av < bv ? -1 : av > bv ? 1 : 0;
1416
+ }
1048
1417
  function readField(record, field) {
1049
1418
  if (record === null || record === void 0) return void 0;
1050
1419
  if (!field.includes(".")) {
@@ -1131,6 +1500,7 @@ function buildDictLabelResolver(joinCtx, field) {
1131
1500
  const dictSource = joinCtx.resolveDictSource(field);
1132
1501
  if (!dictSource) return void 0;
1133
1502
  const snapshot = dictSource.snapshot();
1503
+ const displayLocale = dictSource.displayLocale;
1134
1504
  const dictMap = /* @__PURE__ */ new Map();
1135
1505
  for (const entry of snapshot) {
1136
1506
  const k = entry["key"];
@@ -1140,9 +1510,11 @@ function buildDictLabelResolver(joinCtx, field) {
1140
1510
  }
1141
1511
  }
1142
1512
  return async (key, locale, fallback) => {
1513
+ const effLocale = locale || displayLocale;
1514
+ if (!effLocale) return void 0;
1143
1515
  const labels = dictMap.get(key);
1144
1516
  if (!labels) return void 0;
1145
- if (labels[locale] !== void 0) return labels[locale];
1517
+ if (labels[effLocale] !== void 0) return labels[effLocale];
1146
1518
  const chain = Array.isArray(fallback) ? fallback : fallback ? [fallback] : [];
1147
1519
  for (const fb of chain) {
1148
1520
  if (fb === "any") {
@@ -1156,7 +1528,7 @@ function buildDictLabelResolver(joinCtx, field) {
1156
1528
  };
1157
1529
  }
1158
1530
 
1159
- // src/query/scan-builder.ts
1531
+ // src/kernel/query/scan-builder.ts
1160
1532
  var DEFAULT_SCAN_PAGE_SIZE = 100;
1161
1533
  var ScanBuilder = class _ScanBuilder {
1162
1534
  pageProvider;
@@ -1182,12 +1554,29 @@ var ScanBuilder = class _ScanBuilder {
1182
1554
  * context throws with an actionable error.
1183
1555
  */
1184
1556
  joinContext;
1185
- constructor(pageProvider, pageSize = DEFAULT_SCAN_PAGE_SIZE, clauses = [], joins = [], joinContext) {
1557
+ /**
1558
+ * Money field descriptors for the backing collection. When present, yielded
1559
+ * records are decoded (stored scaled-int → canonical decimal) so `scan()`
1560
+ * agrees with `get()`/`list()`/`query().toArray()`. Decoded with
1561
+ * `'raw'` (canonical decimal, no locale-formatted virtuals) since the scan
1562
+ * stream carries no locale context, mirroring `Query.toArray()`.
1563
+ */
1564
+ moneyFields;
1565
+ constructor(pageProvider, pageSize = DEFAULT_SCAN_PAGE_SIZE, clauses = [], joins = [], joinContext, moneyFields) {
1186
1566
  this.pageProvider = pageProvider;
1187
1567
  this.pageSize = pageSize;
1188
1568
  this.clauses = clauses;
1189
1569
  this.joins = joins;
1190
1570
  this.joinContext = joinContext;
1571
+ this.moneyFields = moneyFields;
1572
+ }
1573
+ /**
1574
+ * Decode this scan's money fields on a record (stored scaled-int → canonical
1575
+ * decimal). No-op when no money fields are declared. See {@link moneyFields}.
1576
+ */
1577
+ decodeMoney(record) {
1578
+ if (!this.moneyFields || Object.keys(this.moneyFields).length === 0) return record;
1579
+ return decodeMoneyFields(record, this.moneyFields, "raw");
1191
1580
  }
1192
1581
  /**
1193
1582
  * Add a field comparison. Runs per record as the scan stream
@@ -1203,13 +1592,15 @@ var ScanBuilder = class _ScanBuilder {
1203
1592
  * evaluates clauses per record in O(1) per clause.
1204
1593
  */
1205
1594
  where(field, op, value) {
1206
- const clause = { type: "field", field, op, value };
1595
+ const desc = this.moneyFields?.[field];
1596
+ const clause = desc ? moneyFieldClause(field, op, value, desc) : { type: "field", field, op, value };
1207
1597
  return new _ScanBuilder(
1208
1598
  this.pageProvider,
1209
1599
  this.pageSize,
1210
1600
  [...this.clauses, clause],
1211
1601
  this.joins,
1212
- this.joinContext
1602
+ this.joinContext,
1603
+ this.moneyFields
1213
1604
  );
1214
1605
  }
1215
1606
  /**
@@ -1228,7 +1619,8 @@ var ScanBuilder = class _ScanBuilder {
1228
1619
  this.pageSize,
1229
1620
  [...this.clauses, clause],
1230
1621
  this.joins,
1231
- this.joinContext
1622
+ this.joinContext,
1623
+ this.moneyFields
1232
1624
  );
1233
1625
  }
1234
1626
  /**
@@ -1339,7 +1731,8 @@ var ScanBuilder = class _ScanBuilder {
1339
1731
  this.pageSize,
1340
1732
  this.clauses,
1341
1733
  [...this.joins, leg],
1342
- this.joinContext
1734
+ this.joinContext,
1735
+ this.moneyFields
1343
1736
  );
1344
1737
  }
1345
1738
  /**
@@ -1356,10 +1749,11 @@ var ScanBuilder = class _ScanBuilder {
1356
1749
  while (true) {
1357
1750
  for (const record of page.items) {
1358
1751
  if (!this.recordMatches(record)) continue;
1752
+ const decoded = this.decodeMoney(record);
1359
1753
  if (joinResolvers === null) {
1360
- yield record;
1754
+ yield decoded;
1361
1755
  } else {
1362
- let attached = record;
1756
+ let attached = decoded;
1363
1757
  for (const resolver of joinResolvers) {
1364
1758
  attached = this.applyOneJoinStreaming(attached, resolver);
1365
1759
  }
@@ -1483,43 +1877,8 @@ var ScanBuilder = class _ScanBuilder {
1483
1877
  }
1484
1878
  return merged;
1485
1879
  }
1486
- /**
1487
- * Reduce the scan stream through a named set of reducers and
1488
- * return the final aggregated shape.
1489
- *
1490
- * Memory is O(reducers): one mutable state slot per spec key.
1491
- * Records flow through the pipeline one at a time via
1492
- * `for await` and are discarded after their `step()` is applied
1493
- * — never collected into an array. This is the distinguishing
1494
- * property from `Query.aggregate()`, which materializes the full
1495
- * match set first.
1496
- *
1497
- * Reuses the same reducer protocol as `Query.aggregate()`,
1498
- * so `count()`, `sum(field)`, `avg(field)`, `min(field)`,
1499
- * `max(field)` all work unchanged. The `{ seed }` parameter
1500
- * plumbing from constraint #2 is honored transparently — the
1501
- * factories ignore it in and the scan executor never
1502
- * touches the per-reducer state construction.
1503
- *
1504
- * **Returns a Promise**, unlike `Query.aggregate().run()` which
1505
- * is synchronous. The scan is inherently async because it walks
1506
- * adapter pages, so the terminal has to be too. Consumers
1507
- * destructure with await:
1508
- *
1509
- * ```ts
1510
- * const { total, n } = await invoices.scan()
1511
- * .where('year', '==', 2025)
1512
- * .aggregate({ total: sum('amount'), n: count() })
1513
- * ```
1514
- *
1515
- * **No `.live()` in.** `scan().aggregate().live()` would
1516
- * require reconciling an unbounded streaming iteration with a
1517
- * change-stream subscription — a design problem, not just a code
1518
- * one. Consumers with huge collections and live needs should
1519
- * narrow with `.where()` enough to fit in the 50k `query()`
1520
- * limit and use `query().aggregate().live()` instead.
1521
- */
1522
- async aggregate(spec) {
1880
+ async aggregate(specOrBuild) {
1881
+ const spec = typeof specOrBuild === "function" ? specOrBuild(reducerBuilder) : specOrBuild;
1523
1882
  const keys = Object.keys(spec);
1524
1883
  const state = {};
1525
1884
  for (const key of keys) {
@@ -1545,8 +1904,9 @@ var ScanBuilder = class _ScanBuilder {
1545
1904
  */
1546
1905
  recordMatches(record) {
1547
1906
  if (this.clauses.length === 0) return true;
1907
+ const fnView = this.moneyFields && Object.keys(this.moneyFields).length > 0 && hasFnClause(this.clauses) ? this.decodeMoney(record) : void 0;
1548
1908
  for (const clause of this.clauses) {
1549
- if (!evaluateClause(record, clause)) return false;
1909
+ if (!evaluateClause(record, clause, fnView)) return false;
1550
1910
  }
1551
1911
  return true;
1552
1912
  }
@@ -1559,6 +1919,11 @@ function coerceRefKey2(value) {
1559
1919
  }
1560
1920
 
1561
1921
  export {
1922
+ validateMoneyFieldPaths,
1923
+ canonicalizeStoredMoney,
1924
+ canonicalizeIncomingMoney,
1925
+ quantizeMoneyFields,
1926
+ decodeMoneyFields,
1562
1927
  DEFAULT_JOIN_MAX_ROWS,
1563
1928
  applyJoins,
1564
1929
  resetJoinWarnings,
@@ -1569,4 +1934,4 @@ export {
1569
1934
  executePlan,
1570
1935
  ScanBuilder
1571
1936
  };
1572
- //# sourceMappingURL=chunk-2GLDA55J.js.map
1937
+ //# sourceMappingURL=chunk-UIU2THRG.js.map