@noy-db/hub 0.3.0-pre.1 → 0.3.0-pre.11

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 (938) hide show
  1. package/dist/aggregate/index.js +9 -8
  2. package/dist/aggregate/index.js.map +1 -1
  3. package/dist/api-YGMINAET.js +20 -0
  4. package/dist/as/index.js +12 -6
  5. package/dist/attestation/index.js +19 -13
  6. package/dist/attestation/index.js.map +1 -1
  7. package/dist/backup-XA5STIYQ.js +225 -0
  8. package/dist/backup-XA5STIYQ.js.map +1 -0
  9. package/dist/blobs/index.js +12 -6
  10. package/dist/blobs/index.js.map +1 -1
  11. package/dist/broker/index.js +92 -0
  12. package/dist/broker/index.js.map +1 -0
  13. package/dist/bundle/index.js +21 -15
  14. package/dist/bundle/index.js.map +1 -1
  15. package/dist/by/index.js +2 -2
  16. package/dist/cargo/index.js +32 -26
  17. package/dist/chunk-25NDNMQ7.js +70 -0
  18. package/dist/chunk-25NDNMQ7.js.map +1 -0
  19. package/dist/chunk-2JMMY7HZ.js +188 -0
  20. package/dist/chunk-2JMMY7HZ.js.map +1 -0
  21. package/dist/chunk-3CNQ7FQ3.js +430 -0
  22. package/dist/chunk-3G4KMVUN.js +291 -0
  23. package/dist/chunk-3G4KMVUN.js.map +1 -0
  24. package/dist/chunk-3MSQLQNZ.js +74 -0
  25. package/dist/chunk-45ZZLTFH.js +38 -0
  26. package/dist/chunk-45ZZLTFH.js.map +1 -0
  27. package/dist/chunk-4GPE63GU.js +111 -0
  28. package/dist/chunk-4GPE63GU.js.map +1 -0
  29. package/dist/chunk-4N5QFSNQ.js +150 -0
  30. package/dist/chunk-4N5QFSNQ.js.map +1 -0
  31. package/dist/chunk-4R4Q64W5.js +34 -0
  32. package/dist/chunk-57V5S7PW.js +130 -0
  33. package/dist/chunk-57V5S7PW.js.map +1 -0
  34. package/dist/chunk-5JB73NMC.js +202 -0
  35. package/dist/chunk-5JB73NMC.js.map +1 -0
  36. package/dist/chunk-5XIPOCQC.js +155 -0
  37. package/dist/chunk-5ZOSG3RJ.js +778 -0
  38. package/dist/chunk-5ZOSG3RJ.js.map +1 -0
  39. package/dist/chunk-67TNU77I.js +36 -0
  40. package/dist/chunk-67TNU77I.js.map +1 -0
  41. package/dist/chunk-6QILBDZU.js +205 -0
  42. package/dist/chunk-7E67FJ33.js +155 -0
  43. package/dist/chunk-7ITPJFGC.js +50 -0
  44. package/dist/chunk-7ITPJFGC.js.map +1 -0
  45. package/dist/chunk-7NS43EXZ.js +117 -0
  46. package/dist/chunk-7QIXUSDQ.js +341 -0
  47. package/dist/chunk-7QIXUSDQ.js.map +1 -0
  48. package/dist/chunk-7VSGW5KJ.js +74 -0
  49. package/dist/chunk-7VSGW5KJ.js.map +1 -0
  50. package/dist/chunk-A2QF4JUE.js +14073 -0
  51. package/dist/chunk-A2QF4JUE.js.map +1 -0
  52. package/dist/chunk-A2Y6YFVN.js +209 -0
  53. package/dist/chunk-AOVDSIL3.js +1221 -0
  54. package/dist/chunk-AOVDSIL3.js.map +1 -0
  55. package/dist/chunk-ARSAMO24.js +29 -0
  56. package/dist/chunk-ARSAMO24.js.map +1 -0
  57. package/dist/chunk-AWB5JZW6.js +41 -0
  58. package/dist/chunk-AWB5JZW6.js.map +1 -0
  59. package/dist/chunk-BCYQA5BK.js +45 -0
  60. package/dist/chunk-BE7N3AXA.js +621 -0
  61. package/dist/chunk-BE7N3AXA.js.map +1 -0
  62. package/dist/chunk-BEIRE5K4.js +164 -0
  63. package/dist/chunk-BEIRE5K4.js.map +1 -0
  64. package/dist/chunk-BZO4WCJI.js +86 -0
  65. package/dist/chunk-BZO4WCJI.js.map +1 -0
  66. package/dist/chunk-C3YH34IL.js +75 -0
  67. package/dist/chunk-C3YH34IL.js.map +1 -0
  68. package/dist/chunk-C7NTK5I3.js +49 -0
  69. package/dist/chunk-C7NTK5I3.js.map +1 -0
  70. package/dist/chunk-CB25ONKC.js +129 -0
  71. package/dist/chunk-CIKY6I4W.js +21 -0
  72. package/dist/chunk-CKZW6P5V.js +32 -0
  73. package/dist/chunk-CKZW6P5V.js.map +1 -0
  74. package/dist/chunk-D26JB3LZ.js +54 -0
  75. package/dist/chunk-D3EFFFOL.js +59 -0
  76. package/dist/chunk-D3EFFFOL.js.map +1 -0
  77. package/dist/chunk-DGH65E7Q.js +466 -0
  78. package/dist/chunk-DGH65E7Q.js.map +1 -0
  79. package/dist/chunk-DIRRS7WP.js +42 -0
  80. package/dist/chunk-DJ3VKYFA.js +150 -0
  81. package/dist/chunk-DJ3VKYFA.js.map +1 -0
  82. package/dist/chunk-DMFNPHCX.js +247 -0
  83. package/dist/chunk-DMFNPHCX.js.map +1 -0
  84. package/dist/chunk-ELNBMFOS.js +392 -0
  85. package/dist/chunk-ELNBMFOS.js.map +1 -0
  86. package/dist/chunk-FH542DDY.js +1505 -0
  87. package/dist/chunk-FH542DDY.js.map +1 -0
  88. package/dist/chunk-FQQF23MC.js +45 -0
  89. package/dist/chunk-FQQF23MC.js.map +1 -0
  90. package/dist/chunk-FXK4X4BL.js +91 -0
  91. package/dist/chunk-FXK4X4BL.js.map +1 -0
  92. package/dist/chunk-GA2QHD6P.js +235 -0
  93. package/dist/chunk-GA2QHD6P.js.map +1 -0
  94. package/dist/chunk-GYGLAVCX.js +19 -0
  95. package/dist/chunk-GYGLAVCX.js.map +1 -0
  96. package/dist/chunk-H44ZE4IE.js +355 -0
  97. package/dist/chunk-H6CZSDWK.js +1697 -0
  98. package/dist/chunk-H6CZSDWK.js.map +1 -0
  99. package/dist/chunk-H6HM6CVR.js +279 -0
  100. package/dist/chunk-H6HM6CVR.js.map +1 -0
  101. package/dist/chunk-HFJIGWJC.js +382 -0
  102. package/dist/chunk-HUS3J5WM.js +404 -0
  103. package/dist/chunk-HUS3J5WM.js.map +1 -0
  104. package/dist/chunk-IDIV5NVH.js +99 -0
  105. package/dist/chunk-IDIV5NVH.js.map +1 -0
  106. package/dist/chunk-IGJCYUT5.js +99 -0
  107. package/dist/chunk-IGJCYUT5.js.map +1 -0
  108. package/dist/chunk-IGJHJYM6.js +515 -0
  109. package/dist/chunk-IGJHJYM6.js.map +1 -0
  110. package/dist/chunk-IP2QBAGS.js +589 -0
  111. package/dist/chunk-IP2QBAGS.js.map +1 -0
  112. package/dist/chunk-JK733I5V.js +23 -0
  113. package/dist/chunk-JK733I5V.js.map +1 -0
  114. package/dist/chunk-JOQ53DMI.js +255 -0
  115. package/dist/chunk-JOQ53DMI.js.map +1 -0
  116. package/dist/chunk-K62IUKOD.js +823 -0
  117. package/dist/chunk-K62IUKOD.js.map +1 -0
  118. package/dist/chunk-KPGX66PM.js +230 -0
  119. package/dist/chunk-KPZS5QAQ.js +151 -0
  120. package/dist/chunk-KPZS5QAQ.js.map +1 -0
  121. package/dist/chunk-L2SNBIV7.js +453 -0
  122. package/dist/chunk-L2SNBIV7.js.map +1 -0
  123. package/dist/chunk-LP7BEXCT.js +32 -0
  124. package/dist/chunk-LP7BEXCT.js.map +1 -0
  125. package/dist/chunk-MCEKIAO4.js +367 -0
  126. package/dist/chunk-MELR46EF.js +280 -0
  127. package/dist/chunk-MELR46EF.js.map +1 -0
  128. package/dist/chunk-MSPNM2OM.js +95 -0
  129. package/dist/chunk-MSPNM2OM.js.map +1 -0
  130. package/dist/chunk-NO272T7Q.js +194 -0
  131. package/dist/chunk-NO272T7Q.js.map +1 -0
  132. package/dist/chunk-O2DYPAZY.js +23 -0
  133. package/dist/chunk-ODJWBC5I.js +30 -0
  134. package/dist/chunk-OEAATWH5.js +686 -0
  135. package/dist/chunk-OEAATWH5.js.map +1 -0
  136. package/dist/chunk-OFJ5GPNA.js +71 -0
  137. package/dist/chunk-OOLO4LQG.js +99 -0
  138. package/dist/chunk-OOLO4LQG.js.map +1 -0
  139. package/dist/chunk-P5RY4ZWD.js +662 -0
  140. package/dist/chunk-P5RY4ZWD.js.map +1 -0
  141. package/dist/chunk-PR5LC5YX.js +265 -0
  142. package/dist/chunk-PR5LC5YX.js.map +1 -0
  143. package/dist/chunk-PXWVF7MC.js +135 -0
  144. package/dist/chunk-Q3XSMOZM.js +40 -0
  145. package/dist/chunk-QLLKLFE2.js +94 -0
  146. package/dist/chunk-QLLKLFE2.js.map +1 -0
  147. package/dist/chunk-QQJXBZCO.js +1056 -0
  148. package/dist/chunk-QQJXBZCO.js.map +1 -0
  149. package/dist/chunk-QYPKGVT4.js +261 -0
  150. package/dist/chunk-QYPKGVT4.js.map +1 -0
  151. package/dist/chunk-RKRGDAS7.js +59 -0
  152. package/dist/chunk-SRVQHVNX.js +164 -0
  153. package/dist/chunk-SYMS4546.js +29 -0
  154. package/dist/chunk-SYMS4546.js.map +1 -0
  155. package/dist/chunk-THNJ3IKU.js +17 -0
  156. package/dist/chunk-THNJ3IKU.js.map +1 -0
  157. package/dist/chunk-TPH5EO6L.js +54 -0
  158. package/dist/chunk-TPH5EO6L.js.map +1 -0
  159. package/dist/chunk-UFILRICG.js +14 -0
  160. package/dist/chunk-UTLEAJXC.js +97 -0
  161. package/dist/chunk-VA4ZWLFY.js +123 -0
  162. package/dist/chunk-VR24ILCR.js +367 -0
  163. package/dist/chunk-VYYM3MEN.js +98 -0
  164. package/dist/chunk-VYYM3MEN.js.map +1 -0
  165. package/dist/chunk-W5D62AQD.js +944 -0
  166. package/dist/chunk-W5D62AQD.js.map +1 -0
  167. package/dist/chunk-WGV4CUZT.js +167 -0
  168. package/dist/chunk-WGV4CUZT.js.map +1 -0
  169. package/dist/chunk-WTUNZACT.js +30 -0
  170. package/dist/chunk-WTUNZACT.js.map +1 -0
  171. package/dist/chunk-X6CMGUAG.js +69 -0
  172. package/dist/chunk-X6CMGUAG.js.map +1 -0
  173. package/dist/chunk-XFXUTFWQ.js +85 -0
  174. package/dist/chunk-XFXUTFWQ.js.map +1 -0
  175. package/dist/chunk-XHV25KBM.js +30 -0
  176. package/dist/chunk-YSXEFGND.js +124 -0
  177. package/dist/chunk-YXOUQ2H7.js +36 -0
  178. package/dist/chunk-ZP5PL65C.js +80 -0
  179. package/dist/classified/index.js +40 -0
  180. package/dist/classified-marker-LQWWQNIJ.js +24 -0
  181. package/dist/classified-marker-LQWWQNIJ.js.map +1 -0
  182. package/dist/collection-facade-YE2O4J4O.js +39 -0
  183. package/dist/computed-W6MVAMWZ.js +11 -0
  184. package/dist/consent/index.js +10 -4
  185. package/dist/consent/index.js.map +1 -1
  186. package/dist/crdt/index.js +1 -1
  187. package/dist/dead-filter-4KXZEB3X.js +28 -0
  188. package/dist/dead-filter-4KXZEB3X.js.map +1 -0
  189. package/dist/delegation-OPUU3R2E.js +25 -0
  190. package/dist/derivations/index.js +13 -6
  191. package/dist/derive-BGUHU663.js +21 -0
  192. package/dist/enclave-VXAQD4XJ.js +135 -0
  193. package/dist/executor-GTVSUUBX.js +25 -0
  194. package/dist/executor-GZWMTOXB.js +9 -0
  195. package/dist/executor-XXGS4S3K.js +9 -0
  196. package/dist/export-accessible-BMULIOYB.js +23 -0
  197. package/dist/extract-partition-JUQTWDXR.js +36 -0
  198. package/dist/fanout-sidecar-CKYFH33E.js +74 -0
  199. package/dist/fanout-sidecar-CKYFH33E.js.map +1 -0
  200. package/dist/fence-watcher-DHQ775JB.js +69 -0
  201. package/dist/fence-watcher-DHQ775JB.js.map +1 -0
  202. package/dist/find-XRGCNGNN.js +11 -0
  203. package/dist/forget/index.js +11 -5
  204. package/dist/forget/index.js.map +1 -1
  205. package/dist/guards/index.js +4 -4
  206. package/dist/history/index.js +12 -6
  207. package/dist/history/index.js.map +1 -1
  208. package/dist/i18n/index.js +50 -31
  209. package/dist/i18n/index.js.map +1 -1
  210. package/dist/index.d.ts +303 -1400
  211. package/dist/index.js +1525 -184
  212. package/dist/index.js.map +1 -1
  213. package/dist/indexing/index.js +4 -4
  214. package/dist/issue-UB6AA5M6.js +19 -0
  215. package/dist/json-schema-I22JCYCG.js +44 -0
  216. package/dist/json-schema-I22JCYCG.js.map +1 -0
  217. package/dist/kernel/cache/index.d.ts +10 -0
  218. package/dist/kernel/cache/lru.d.ts +97 -0
  219. package/dist/kernel/cache/policy.d.ts +32 -0
  220. package/dist/kernel/collection-config.d.ts +781 -0
  221. package/dist/kernel/collection.d.ts +1505 -0
  222. package/dist/kernel/constants.d.ts +18 -0
  223. package/dist/kernel/debug.d.ts +25 -0
  224. package/dist/kernel/enclave/broker/proof.d.ts +154 -0
  225. package/dist/kernel/enclave/classify/bidx.d.ts +77 -0
  226. package/dist/kernel/enclave/classify/compare.d.ts +10 -0
  227. package/dist/kernel/enclave/classify/digest.d.ts +8 -0
  228. package/dist/kernel/enclave/classify/find.d.ts +36 -0
  229. package/dist/kernel/enclave/classify/kofn.d.ts +7 -0
  230. package/dist/kernel/enclave/classify/normalize.d.ts +7 -0
  231. package/dist/kernel/enclave/classify/reveal.d.ts +10 -0
  232. package/dist/kernel/enclave/classify/vdig.d.ts +39 -0
  233. package/dist/kernel/enclave/classify/verify.d.ts +33 -0
  234. package/dist/kernel/enclave/classify/write.d.ts +8 -0
  235. package/dist/kernel/enclave/crypto.d.ts +263 -0
  236. package/dist/kernel/enclave/index.d.ts +78 -0
  237. package/dist/kernel/enclave/record-keys/deterministic.d.ts +54 -0
  238. package/dist/kernel/enclave/record-keys/envelope-body.d.ts +79 -0
  239. package/dist/kernel/enclave/record-keys/lifecycle.d.ts +57 -0
  240. package/dist/kernel/enclave/record-keys/record-codec.d.ts +301 -0
  241. package/dist/kernel/enclave/record-keys/sealed-slot.d.ts +14 -0
  242. package/dist/kernel/enclave/record-keys/sealed-slots.d.ts +123 -0
  243. package/dist/kernel/enclave/record-keys/sealing.d.ts +70 -0
  244. package/dist/kernel/enclave/record-keys/tombstone.d.ts +57 -0
  245. package/dist/kernel/env-check.d.ts +1 -0
  246. package/dist/kernel/errors.d.ts +1848 -0
  247. package/dist/kernel/events.d.ts +11 -0
  248. package/dist/kernel/memory-store.d.ts +17 -0
  249. package/dist/kernel/mutation.d.ts +14 -0
  250. package/dist/kernel/noydb.d.ts +818 -0
  251. package/dist/kernel/paths.d.ts +25 -0
  252. package/dist/kernel/query/builder.d.ts +520 -0
  253. package/dist/kernel/query/index.d.ts +31 -0
  254. package/dist/kernel/query/join.d.ts +205 -0
  255. package/dist/kernel/query/live.d.ts +111 -0
  256. package/dist/kernel/query/predicate.d.ts +139 -0
  257. package/dist/kernel/query/scan-builder.d.ts +334 -0
  258. package/dist/kernel/refs.d.ts +205 -0
  259. package/dist/kernel/schema.d.ts +134 -0
  260. package/dist/kernel/sync-policy.d.ts +188 -0
  261. package/dist/kernel/types.d.ts +3147 -0
  262. package/dist/kernel/util/discriminant.d.ts +58 -0
  263. package/dist/kernel/util/index.d.ts +14 -0
  264. package/dist/kernel/util/sanitize-filename.d.ts +75 -0
  265. package/dist/kernel/validation.d.ts +130 -0
  266. package/dist/kernel/vault.d.ts +1723 -0
  267. package/dist/kernel/via/compose.d.ts +144 -0
  268. package/dist/kernel/via/dispatch.d.ts +185 -0
  269. package/dist/kernel/via/graph-wiring.d.ts +145 -0
  270. package/dist/kernel/via/graph.d.ts +165 -0
  271. package/dist/kernel/via/index.d.ts +200 -0
  272. package/dist/kernel/via/pipeline.d.ts +266 -0
  273. package/dist/kernel/via/reconcile.d.ts +153 -0
  274. package/dist/kernel/via/taint-binding.d.ts +66 -0
  275. package/dist/kernel/write-queue.d.ts +46 -0
  276. package/dist/lazy/index.js +12 -0
  277. package/dist/ledger-FU6GH5EH.js +42 -0
  278. package/dist/legacy/bundle.d.ts +30 -0
  279. package/dist/legacy/kernel.d.ts +33 -0
  280. package/dist/liberate-YUN7W5QG.js +24 -0
  281. package/dist/link-set-MNADSH5M.js +31 -0
  282. package/dist/materialized-views/index.js +20 -10
  283. package/dist/noydb-6JLBZU4U.js +67 -0
  284. package/dist/on/index.js +10 -4
  285. package/dist/overlay-views/index.js +4 -4
  286. package/dist/periods/index.js +21 -7
  287. package/dist/pod/index.js +12 -6
  288. package/dist/policy-JTFOPPUU.js +41 -0
  289. package/dist/port/as/index.d.ts +26 -0
  290. package/dist/port/at/index.d.ts +18 -0
  291. package/dist/port/by/default-provider.d.ts +9 -0
  292. package/dist/port/by/index.d.ts +17 -0
  293. package/dist/port/by/types.d.ts +86 -0
  294. package/dist/port/in/index.d.ts +21 -0
  295. package/dist/port/on/index.d.ts +27 -0
  296. package/dist/port/to/index.d.ts +19 -0
  297. package/dist/port/ui/index.d.ts +21 -0
  298. package/dist/port/with/blob-strategy.d.ts +81 -0
  299. package/dist/port/with/broker-strategy.d.ts +84 -0
  300. package/dist/port/with/capabilities.d.ts +31 -0
  301. package/dist/port/with/classified-marker.d.ts +9 -0
  302. package/dist/port/with/classified-strategy.d.ts +62 -0
  303. package/dist/port/with/computed-strategy.d.ts +19 -0
  304. package/dist/port/with/i18n-strategy.d.ts +175 -0
  305. package/dist/port/with/index.d.ts +18 -0
  306. package/dist/port/with/lazy-strategy.d.ts +48 -0
  307. package/dist/port/with/lookup-strategy.d.ts +128 -0
  308. package/dist/port/with/service-bus.d.ts +156 -0
  309. package/dist/port/with/team-strategy.d.ts +36 -0
  310. package/dist/port/with/write-hooks.d.ts +34 -0
  311. package/dist/portability/index.js +8 -8
  312. package/dist/post-register-HAWO3O7O.js +55 -0
  313. package/dist/post-register-HAWO3O7O.js.map +1 -0
  314. package/dist/public-envelope-NJVB7LPA.js +32 -0
  315. package/dist/purge-scope-FGNNLWHD.js +24 -0
  316. package/dist/purge-scope-FGNNLWHD.js.map +1 -0
  317. package/dist/query/index.js +9 -6
  318. package/dist/read-only-facade-CHCKSEPD.js +8 -0
  319. package/dist/register-VCKOBWKT.js +23 -0
  320. package/dist/registry-72UKJ2L4.js +9 -0
  321. package/dist/registry-BZFLJNEH.js +18 -0
  322. package/dist/registry-YJEYSYI5.js +19 -0
  323. package/dist/request-withdrawal-6MJRMFHF.js +31 -0
  324. package/dist/reveal-BOY7XYFH.js +38 -0
  325. package/dist/reveal-BOY7XYFH.js.map +1 -0
  326. package/dist/revoke-4KUNSVJC.js +24 -0
  327. package/dist/satellites/index.js +8 -0
  328. package/dist/sealed-record/index.js +13 -7
  329. package/dist/sealed-record/index.js.map +1 -1
  330. package/dist/seed-4RRXT42N.js +231 -0
  331. package/dist/seed-4RRXT42N.js.map +1 -0
  332. package/dist/session/index.js +10 -4
  333. package/dist/session/index.js.map +1 -1
  334. package/dist/shadow/index.js +2 -2
  335. package/dist/signer-DDDXP5JD.js +25 -0
  336. package/dist/signer-DDDXP5JD.js.map +1 -0
  337. package/dist/snapshots/index.js +11 -5
  338. package/dist/snapshots/index.js.map +1 -1
  339. package/dist/stale-NXPT56JA.js +14 -0
  340. package/dist/stale-NXPT56JA.js.map +1 -0
  341. package/dist/storage-IR6EEAV2.js +23 -0
  342. package/dist/storage-IR6EEAV2.js.map +1 -0
  343. package/dist/store-coordination-provider-HPYVFJCV.js +142 -0
  344. package/dist/sync/index.js +10 -4
  345. package/dist/sync/index.js.map +1 -1
  346. package/dist/team/index.js +25 -12
  347. package/dist/tiers/index.js +11 -5
  348. package/dist/to/index.js +1 -2
  349. package/dist/tx/index.js +3 -3
  350. package/dist/util/index.js +1 -1
  351. package/dist/verify-66RHOW7N.js +139 -0
  352. package/dist/verify-66RHOW7N.js.map +1 -0
  353. package/dist/via/blob/active.d.ts +34 -0
  354. package/dist/via/blob/binding.d.ts +86 -0
  355. package/dist/via/blob/index.d.ts +34 -0
  356. package/dist/via/classified/active.d.ts +3 -0
  357. package/dist/via/classified/binding.d.ts +83 -0
  358. package/dist/via/classified/config-drift.d.ts +34 -0
  359. package/dist/via/classified/descriptor.d.ts +66 -0
  360. package/dist/via/classified/errors.d.ts +19 -0
  361. package/dist/via/classified/guards.d.ts +23 -0
  362. package/dist/via/classified/index.d.ts +11 -0
  363. package/dist/via/classified/presets.d.ts +65 -0
  364. package/dist/via/classified/resolve.d.ts +9 -0
  365. package/dist/via/classified/strategy.d.ts +11 -0
  366. package/dist/via/classified/validators.d.ts +3 -0
  367. package/dist/via/classified/write.d.ts +4 -0
  368. package/dist/via/computed/binding.d.ts +34 -0
  369. package/dist/via/computed/descriptor.d.ts +35 -0
  370. package/dist/via/i18n/active.d.ts +28 -0
  371. package/dist/via/i18n/binding.d.ts +36 -0
  372. package/dist/via/i18n/core.d.ts +267 -0
  373. package/dist/via/i18n/densify.d.ts +24 -0
  374. package/dist/via/i18n/dictionary.d.ts +200 -0
  375. package/dist/via/i18n/index.d.ts +21 -0
  376. package/dist/via/i18n/policy.d.ts +44 -0
  377. package/dist/via/i18n/script.d.ts +26 -0
  378. package/dist/via/i18n/strategy.d.ts +13 -0
  379. package/dist/via/lookup/active.d.ts +19 -0
  380. package/dist/via/lookup/binding.d.ts +99 -0
  381. package/dist/via/lookup/descriptor.d.ts +123 -0
  382. package/dist/via/lookup/handle.d.ts +220 -0
  383. package/dist/via/lookup/index.d.ts +17 -0
  384. package/dist/via/lookup/registry.d.ts +219 -0
  385. package/dist/via/lookup/snapshot.d.ts +67 -0
  386. package/dist/via/money/arith.d.ts +68 -0
  387. package/dist/via/money/binding.d.ts +21 -0
  388. package/dist/via/money/branded.d.ts +61 -0
  389. package/dist/via/money/descriptor.d.ts +73 -0
  390. package/dist/via/money/fixed-point.d.ts +51 -0
  391. package/dist/via/money/index.d.ts +15 -0
  392. package/dist/via/money/iso4217.d.ts +6 -0
  393. package/dist/via/money/money-reducer.d.ts +33 -0
  394. package/dist/via/money/normalize.d.ts +105 -0
  395. package/dist/via/money/paths.d.ts +61 -0
  396. package/dist/via/money/where.d.ts +106 -0
  397. package/dist/walk-2RWEOCAS.js +241 -0
  398. package/dist/walk-2RWEOCAS.js.map +1 -0
  399. package/dist/with/index.js +12 -6
  400. package/dist/with-audit/attestation/active.d.ts +10 -0
  401. package/dist/with-audit/attestation/index.d.ts +16 -0
  402. package/dist/with-audit/attestation/issue.d.ts +29 -0
  403. package/dist/with-audit/attestation/revoke.d.ts +15 -0
  404. package/dist/with-audit/attestation/signer.d.ts +33 -0
  405. package/dist/with-audit/attestation/strategy.d.ts +44 -0
  406. package/dist/with-audit/attestation/vault-facade.d.ts +62 -0
  407. package/dist/with-audit/consent/active.d.ts +14 -0
  408. package/dist/with-audit/consent/consent.d.ts +114 -0
  409. package/dist/with-audit/consent/index.d.ts +14 -0
  410. package/dist/with-audit/consent/strategy.d.ts +36 -0
  411. package/dist/with-audit/forget/active.d.ts +31 -0
  412. package/dist/with-audit/forget/index.d.ts +28 -0
  413. package/dist/with-audit/forget/purge-scope.d.ts +54 -0
  414. package/dist/with-audit/forget/strategy.d.ts +177 -0
  415. package/dist/with-audit/forget/subject-index.d.ts +83 -0
  416. package/dist/with-audit/guards/executor.d.ts +26 -0
  417. package/dist/with-audit/guards/immutable-guard.d.ts +63 -0
  418. package/dist/with-audit/guards/index.d.ts +10 -0
  419. package/dist/with-audit/guards/read-only-facade.d.ts +31 -0
  420. package/dist/with-audit/guards/registry.d.ts +83 -0
  421. package/dist/with-audit/guards/transition-guard.d.ts +82 -0
  422. package/dist/with-audit/guards/types.d.ts +134 -0
  423. package/dist/with-audit/guards/with-guard.d.ts +15 -0
  424. package/dist/with-audit/periods/active.d.ts +11 -0
  425. package/dist/with-audit/periods/index.d.ts +18 -0
  426. package/dist/with-audit/periods/periods.d.ts +417 -0
  427. package/dist/with-audit/periods/strategy.d.ts +32 -0
  428. package/dist/with-audit/periods/vault-facade.d.ts +95 -0
  429. package/dist/with-audit/portability/active.d.ts +11 -0
  430. package/dist/with-audit/portability/export-accessible.d.ts +46 -0
  431. package/dist/with-audit/portability/index.d.ts +18 -0
  432. package/dist/with-audit/portability/request-withdrawal.d.ts +85 -0
  433. package/dist/with-audit/portability/strategy.d.ts +31 -0
  434. package/dist/with-audit/portability/withdraw-accessible.d.ts +82 -0
  435. package/dist/with-audit/sealed-record/active.d.ts +9 -0
  436. package/dist/with-audit/sealed-record/index.d.ts +55 -0
  437. package/dist/with-audit/sealed-record/strategy.d.ts +34 -0
  438. package/dist/with-audit/sealed-record/types.d.ts +27 -0
  439. package/dist/with-audit/tiers/active.d.ts +9 -0
  440. package/dist/with-audit/tiers/index.d.ts +122 -0
  441. package/dist/with-audit/tiers/strategy.d.ts +35 -0
  442. package/dist/with-cargo/active.d.ts +11 -0
  443. package/dist/with-cargo/adopt-partition.d.ts +81 -0
  444. package/dist/with-cargo/decrypt-partition.d.ts +19 -0
  445. package/dist/with-cargo/describe-extraction.d.ts +33 -0
  446. package/dist/with-cargo/extract-partition.d.ts +147 -0
  447. package/dist/with-cargo/index.d.ts +33 -0
  448. package/dist/with-cargo/strategy.d.ts +30 -0
  449. package/dist/with-cargo/vault-diff.d.ts +144 -0
  450. package/dist/with-cargo/walk-closure.d.ts +38 -0
  451. package/dist/with-commit/crdt/active.d.ts +25 -0
  452. package/dist/with-commit/crdt/crdt.d.ts +42 -0
  453. package/dist/with-commit/crdt/index.d.ts +16 -0
  454. package/dist/with-commit/crdt/strategy.d.ts +25 -0
  455. package/dist/with-commit/history/active.d.ts +40 -0
  456. package/dist/with-commit/history/diff.d.ts +23 -0
  457. package/dist/with-commit/history/history.d.ts +27 -0
  458. package/dist/with-commit/history/index.d.ts +30 -0
  459. package/dist/with-commit/history/ledger/constants.d.ts +37 -0
  460. package/dist/with-commit/history/ledger/entry.d.ts +195 -0
  461. package/dist/with-commit/history/ledger/hash.d.ts +30 -0
  462. package/dist/with-commit/history/ledger/index.d.ts +19 -0
  463. package/dist/with-commit/history/ledger/patch.d.ts +99 -0
  464. package/dist/with-commit/history/ledger/store.d.ts +335 -0
  465. package/dist/with-commit/history/strategy.d.ts +126 -0
  466. package/dist/with-commit/history/time-machine.d.ts +179 -0
  467. package/dist/with-commit/numbering/descriptor.d.ts +27 -0
  468. package/dist/with-commit/numbering/index.d.ts +69 -0
  469. package/dist/with-commit/sequence/active.d.ts +10 -0
  470. package/dist/with-commit/sequence/index.d.ts +150 -0
  471. package/dist/with-commit/sequence/strategy.d.ts +26 -0
  472. package/dist/with-commit/tx/active.d.ts +27 -0
  473. package/dist/with-commit/tx/dry-run.d.ts +29 -0
  474. package/dist/with-commit/tx/elevated-handle.d.ts +58 -0
  475. package/dist/with-commit/tx/index.d.ts +13 -0
  476. package/dist/with-commit/tx/invariants.d.ts +68 -0
  477. package/dist/with-commit/tx/strategy.d.ts +23 -0
  478. package/dist/with-commit/tx/transaction.d.ts +207 -0
  479. package/dist/with-fork/archive/engine.d.ts +71 -0
  480. package/dist/with-fork/archive/index.d.ts +23 -0
  481. package/dist/with-fork/shadow/active.d.ts +6 -0
  482. package/dist/with-fork/shadow/index.d.ts +14 -0
  483. package/dist/with-fork/shadow/strategy.d.ts +28 -0
  484. package/dist/with-fork/shadow/vault-frame.d.ts +93 -0
  485. package/dist/with-fork/snapshots/active.d.ts +20 -0
  486. package/dist/with-fork/snapshots/engine.d.ts +36 -0
  487. package/dist/with-fork/snapshots/index.d.ts +5 -0
  488. package/dist/with-fork/snapshots/noydb-facade.d.ts +64 -0
  489. package/dist/with-fork/snapshots/policy.d.ts +23 -0
  490. package/dist/with-fork/snapshots/scheduler.d.ts +34 -0
  491. package/dist/with-fork/snapshots/strategy.d.ts +48 -0
  492. package/dist/with-formula/computed/index.d.ts +48 -0
  493. package/dist/with-formula/computed/lazy.d.ts +13 -0
  494. package/dist/with-formula/derivations/executor.d.ts +61 -0
  495. package/dist/with-formula/derivations/fanout-sidecar.d.ts +75 -0
  496. package/dist/with-formula/derivations/index.d.ts +6 -0
  497. package/dist/with-formula/derivations/registry.d.ts +67 -0
  498. package/dist/with-formula/derivations/stale.d.ts +39 -0
  499. package/dist/with-formula/derivations/strategy-hash.d.ts +1 -0
  500. package/dist/with-formula/derivations/types.d.ts +248 -0
  501. package/dist/with-formula/derivations/with-derivation.d.ts +10 -0
  502. package/dist/with-formula/derivations/with-rollup.d.ts +34 -0
  503. package/dist/with-formula/materialized-views/dependency-analyzer.d.ts +58 -0
  504. package/dist/with-formula/materialized-views/executor.d.ts +71 -0
  505. package/dist/with-formula/materialized-views/index.d.ts +11 -0
  506. package/dist/with-formula/materialized-views/query-hash.d.ts +23 -0
  507. package/dist/with-formula/materialized-views/registry.d.ts +99 -0
  508. package/dist/with-formula/materialized-views/stale.d.ts +62 -0
  509. package/dist/with-formula/materialized-views/types.d.ts +318 -0
  510. package/dist/with-formula/materialized-views/with-materialized-view.d.ts +24 -0
  511. package/dist/with-formula/overlay-views/index.d.ts +5 -0
  512. package/dist/with-formula/overlay-views/registry.d.ts +42 -0
  513. package/dist/with-formula/overlay-views/types.d.ts +97 -0
  514. package/dist/with-formula/overlay-views/virtual-collection.d.ts +90 -0
  515. package/dist/with-formula/overlay-views/with-overlayed-view.d.ts +9 -0
  516. package/dist/with-lookup/aggregate/active.d.ts +33 -0
  517. package/dist/with-lookup/aggregate/aggregation.d.ts +166 -0
  518. package/dist/with-lookup/aggregate/canonical-key.d.ts +16 -0
  519. package/dist/with-lookup/aggregate/groupby.d.ts +280 -0
  520. package/dist/with-lookup/aggregate/index.d.ts +23 -0
  521. package/dist/with-lookup/aggregate/reducers.d.ts +257 -0
  522. package/dist/with-lookup/aggregate/strategy.d.ts +59 -0
  523. package/dist/with-lookup/embeddings/cosine.d.ts +2 -0
  524. package/dist/with-lookup/embeddings/descriptor.d.ts +8 -0
  525. package/dist/with-lookup/embeddings/index.d.ts +3 -0
  526. package/dist/with-lookup/embeddings/vector-set.d.ts +19 -0
  527. package/dist/with-lookup/indexing/active.d.ts +30 -0
  528. package/dist/with-lookup/indexing/collection-facade.d.ts +120 -0
  529. package/dist/with-lookup/indexing/eager-indexes.d.ts +122 -0
  530. package/dist/with-lookup/indexing/index.d.ts +27 -0
  531. package/dist/with-lookup/indexing/lazy-builder.d.ts +69 -0
  532. package/dist/with-lookup/indexing/persisted-indexes.d.ts +186 -0
  533. package/dist/with-lookup/indexing/strategy.d.ts +56 -0
  534. package/dist/with-lookup/indexing/unique-constraints.d.ts +74 -0
  535. package/dist/with-lookup/search/active.d.ts +10 -0
  536. package/dist/with-lookup/search/build-docs.d.ts +15 -0
  537. package/dist/with-lookup/search/collection-facade.d.ts +123 -0
  538. package/dist/with-lookup/search/fuse.d.ts +22 -0
  539. package/dist/with-lookup/search/index-store.d.ts +19 -0
  540. package/dist/with-lookup/search/index.d.ts +19 -0
  541. package/dist/with-lookup/search/inverted-index.d.ts +47 -0
  542. package/dist/with-lookup/search/persisted-index-store.d.ts +41 -0
  543. package/dist/with-lookup/search/retrieve-types.d.ts +29 -0
  544. package/dist/with-lookup/search/scan.d.ts +28 -0
  545. package/dist/with-lookup/search/segment.d.ts +15 -0
  546. package/dist/with-lookup/search/serialize.d.ts +4 -0
  547. package/dist/with-lookup/search/snippet.d.ts +5 -0
  548. package/dist/with-lookup/search/strategy.d.ts +37 -0
  549. package/dist/with-lookup/search/tokenize.d.ts +12 -0
  550. package/dist/with-party/auth-introspection/index.d.ts +44 -0
  551. package/dist/with-party/broker/active.d.ts +23 -0
  552. package/dist/with-party/broker/index.d.ts +28 -0
  553. package/dist/with-party/broker/seed.d.ts +77 -0
  554. package/dist/with-party/custody/active.d.ts +10 -0
  555. package/dist/with-party/custody/index.d.ts +69 -0
  556. package/dist/with-party/custody/liberate.d.ts +64 -0
  557. package/dist/with-party/custody/strategy.d.ts +48 -0
  558. package/dist/with-party/directory/index.d.ts +11 -0
  559. package/dist/with-party/directory/public-envelope/index.d.ts +12 -0
  560. package/dist/with-party/directory/public-envelope/schema.d.ts +24 -0
  561. package/dist/with-party/directory/public-envelope/storage.d.ts +59 -0
  562. package/dist/with-party/directory/public-envelope/types.d.ts +80 -0
  563. package/dist/with-party/directory/storage.d.ts +33 -0
  564. package/dist/with-party/directory/types.d.ts +43 -0
  565. package/dist/with-party/directory/user-envelope/api.d.ts +201 -0
  566. package/dist/with-party/directory/user-envelope/index.d.ts +12 -0
  567. package/dist/with-party/directory/user-envelope/storage.d.ts +54 -0
  568. package/dist/with-party/directory/visibility.d.ts +47 -0
  569. package/dist/with-party/policy/engine.d.ts +60 -0
  570. package/dist/with-party/policy/index.d.ts +15 -0
  571. package/dist/with-party/policy/noydb-facade.d.ts +39 -0
  572. package/dist/with-party/policy/presets.d.ts +38 -0
  573. package/dist/with-party/policy/storage.d.ts +31 -0
  574. package/dist/with-party/session/active.d.ts +34 -0
  575. package/dist/with-party/session/dev-unlock.d.ts +128 -0
  576. package/dist/with-party/session/index.d.ts +23 -0
  577. package/dist/with-party/session/session-policy.d.ts +92 -0
  578. package/dist/with-party/session/session.d.ts +131 -0
  579. package/dist/with-party/session/strategy.d.ts +42 -0
  580. package/dist/with-party/session/unlock-state.d.ts +47 -0
  581. package/dist/with-party/sync/index.d.ts +31 -0
  582. package/dist/with-party/tab-coordination.d.ts +73 -0
  583. package/dist/with-party/tab-write-relay.d.ts +39 -0
  584. package/dist/with-party/team/active.d.ts +13 -0
  585. package/dist/with-party/team/authenticators.d.ts +95 -0
  586. package/dist/with-party/team/deed.d.ts +97 -0
  587. package/dist/with-party/team/delegation.d.ts +88 -0
  588. package/dist/with-party/team/index.d.ts +38 -0
  589. package/dist/with-party/team/keyring.d.ts +318 -0
  590. package/dist/with-party/team/magic-link-grant.d.ts +152 -0
  591. package/dist/with-party/team/managed-passphrase.d.ts +280 -0
  592. package/dist/with-party/team/noydb-facade.d.ts +484 -0
  593. package/dist/with-party/team/peer-recover.d.ts +81 -0
  594. package/dist/with-party/team/presence.d.ts +81 -0
  595. package/dist/with-party/team/recovery.d.ts +191 -0
  596. package/dist/with-party/team/reserved-secret-collections.d.ts +41 -0
  597. package/dist/with-party/team/rotate-recover.d.ts +275 -0
  598. package/dist/with-party/team/shamir-recovery-provider.d.ts +15 -0
  599. package/dist/with-party/team/strategy.d.ts +9 -0
  600. package/dist/with-party/team/sync-active.d.ts +33 -0
  601. package/dist/with-party/team/sync-credentials.d.ts +113 -0
  602. package/dist/with-party/team/sync-strategy.d.ts +67 -0
  603. package/dist/with-party/team/sync-transaction.d.ts +39 -0
  604. package/dist/with-party/team/sync.d.ts +165 -0
  605. package/dist/with-party/team/tiers.d.ts +39 -0
  606. package/dist/with-party/team/wrapped-deks.d.ts +86 -0
  607. package/dist/with-pod/backup.d.ts +74 -0
  608. package/dist/with-pod/bundle.d.ts +414 -0
  609. package/dist/with-pod/format.d.ts +203 -0
  610. package/dist/with-pod/index.d.ts +20 -0
  611. package/dist/with-pod/pod-store.d.ts +54 -0
  612. package/dist/with-pod/ulid.d.ts +64 -0
  613. package/dist/with-shape/blobs/blob-compaction.d.ts +170 -0
  614. package/dist/with-shape/blobs/blob-set.d.ts +342 -0
  615. package/dist/with-shape/blobs/export-blobs.d.ts +110 -0
  616. package/dist/with-shape/blobs/import-external.d.ts +50 -0
  617. package/dist/with-shape/blobs/mime-magic.d.ts +48 -0
  618. package/dist/with-shape/blobs/object-projection.d.ts +70 -0
  619. package/dist/with-shape/introspection/describe.d.ts +237 -0
  620. package/dist/with-shape/introspection/field-meta.d.ts +61 -0
  621. package/dist/with-shape/introspection/fields.d.ts +14 -0
  622. package/dist/with-shape/introspection/index.d.ts +12 -0
  623. package/dist/with-shape/introspection/json-schema.d.ts +13 -0
  624. package/dist/with-shape/introspection/meta.d.ts +22 -0
  625. package/dist/with-shape/introspection/projection.d.ts +13 -0
  626. package/dist/with-shape/introspection/types.d.ts +154 -0
  627. package/dist/with-shape/introspection/walk.d.ts +50 -0
  628. package/dist/with-shape/links/lazy-handle.d.ts +36 -0
  629. package/dist/with-shape/links/link-set.d.ts +67 -0
  630. package/dist/with-shape/links/names.d.ts +65 -0
  631. package/dist/with-shape/links/vault-facade.d.ts +211 -0
  632. package/dist/with-shape/persisted-schemas/canonicalize.d.ts +11 -0
  633. package/dist/with-shape/persisted-schemas/derive.d.ts +29 -0
  634. package/dist/with-shape/persisted-schemas/index.d.ts +21 -0
  635. package/dist/with-shape/persisted-schemas/register.d.ts +66 -0
  636. package/dist/with-shape/persisted-schemas/storage.d.ts +61 -0
  637. package/dist/with-shape/persisted-schemas/types.d.ts +54 -0
  638. package/dist/with-shape/satellites/dead-filter.d.ts +21 -0
  639. package/dist/with-shape/satellites/declare.d.ts +60 -0
  640. package/dist/with-shape/satellites/existence.d.ts +5 -0
  641. package/dist/with-shape/satellites/fanout.d.ts +37 -0
  642. package/dist/with-shape/satellites/forget.d.ts +47 -0
  643. package/dist/with-shape/satellites/index.d.ts +3 -0
  644. package/dist/with-shape/satellites/joined.d.ts +19 -0
  645. package/dist/with-shape/satellites/marker.d.ts +10 -0
  646. package/dist/with-shape/satellites/post-register.d.ts +6 -0
  647. package/dist/with-shape/satellites/proxy.d.ts +37 -0
  648. package/dist/with-shape/satellites/raw-target.d.ts +14 -0
  649. package/dist/with-shape/satellites/registry.d.ts +19 -0
  650. package/dist/with-shape/satellites/types.d.ts +26 -0
  651. package/dist/with-shape/satellites/validate.d.ts +17 -0
  652. package/dist/with-shape/schema-update/client-registry.d.ts +35 -0
  653. package/dist/with-shape/schema-update/cutover.d.ts +5 -0
  654. package/dist/with-shape/schema-update/delta.d.ts +2 -0
  655. package/dist/with-shape/schema-update/dispatch.d.ts +3 -0
  656. package/dist/with-shape/schema-update/fence-controller.d.ts +62 -0
  657. package/dist/with-shape/schema-update/fence-watcher.d.ts +37 -0
  658. package/dist/with-shape/schema-update/fence.d.ts +15 -0
  659. package/dist/with-shape/schema-update/gate.d.ts +16 -0
  660. package/dist/with-shape/schema-update/index.d.ts +6 -0
  661. package/dist/with-shape/schema-update/store-coordination-provider.d.ts +29 -0
  662. package/dist/with-shape/schema-update/strategies.d.ts +12 -0
  663. package/dist/with-shape/schema-update/types.d.ts +53 -0
  664. package/dist/with-store/index.d.ts +15 -0
  665. package/dist/with-store/lazy/active.d.ts +12 -0
  666. package/dist/with-store/lazy/index.d.ts +14 -0
  667. package/dist/with-store/lazy/strategy.d.ts +9 -0
  668. package/dist/with-store/route-store.d.ts +259 -0
  669. package/dist/with-store/store-middleware.d.ts +189 -0
  670. package/dist/withdraw-accessible-CLMZEHQT.js +28 -0
  671. package/dist/withdraw-accessible-CLMZEHQT.js.map +1 -0
  672. package/package.json +56 -52
  673. package/dist/adapter/index.d.ts +0 -5
  674. package/dist/adapter/index.js +0 -15
  675. package/dist/aggregate/index.d.ts +0 -42
  676. package/dist/api-RW3KP7WU.js +0 -14
  677. package/dist/as/index.d.ts +0 -7
  678. package/dist/at/index.d.ts +0 -5
  679. package/dist/attestation/index.d.ts +0 -20
  680. package/dist/backup-XV3IOEGB.js +0 -217
  681. package/dist/backup-XV3IOEGB.js.map +0 -1
  682. package/dist/blobs/index.d.ts +0 -44
  683. package/dist/bundle/index.d.ts +0 -122
  684. package/dist/bundle-CH-H06dp.d.ts +0 -548
  685. package/dist/by/index.d.ts +0 -1
  686. package/dist/cargo/index.d.ts +0 -9
  687. package/dist/chunk-26LGBE4T.js +0 -42
  688. package/dist/chunk-26LGBE4T.js.map +0 -1
  689. package/dist/chunk-2P2HZEXU.js +0 -233
  690. package/dist/chunk-2P2HZEXU.js.map +0 -1
  691. package/dist/chunk-3YFXJ3ZP.js +0 -97
  692. package/dist/chunk-5LUY7UTV.js +0 -380
  693. package/dist/chunk-5LUY7UTV.js.map +0 -1
  694. package/dist/chunk-5N6CZTCY.js +0 -367
  695. package/dist/chunk-5O3AOPDT.js +0 -992
  696. package/dist/chunk-5O3AOPDT.js.map +0 -1
  697. package/dist/chunk-5R3ERCDH.js +0 -239
  698. package/dist/chunk-5R3ERCDH.js.map +0 -1
  699. package/dist/chunk-5R5JW2JT.js +0 -12502
  700. package/dist/chunk-5R5JW2JT.js.map +0 -1
  701. package/dist/chunk-5TDJ56JE.js +0 -32
  702. package/dist/chunk-5TDJ56JE.js.map +0 -1
  703. package/dist/chunk-62QYRORB.js +0 -320
  704. package/dist/chunk-62QYRORB.js.map +0 -1
  705. package/dist/chunk-6S7T6WC4.js +0 -111
  706. package/dist/chunk-6S7T6WC4.js.map +0 -1
  707. package/dist/chunk-76722EBH.js +0 -451
  708. package/dist/chunk-76722EBH.js.map +0 -1
  709. package/dist/chunk-AIWULCUO.js +0 -68
  710. package/dist/chunk-AIWULCUO.js.map +0 -1
  711. package/dist/chunk-AQTBSL7R.js +0 -181
  712. package/dist/chunk-AQTBSL7R.js.map +0 -1
  713. package/dist/chunk-AXRXJTE2.js +0 -59
  714. package/dist/chunk-AZAOEIKW.js +0 -155
  715. package/dist/chunk-BG3SPSR4.js +0 -53
  716. package/dist/chunk-BG3SPSR4.js.map +0 -1
  717. package/dist/chunk-BGIZAFY7.js +0 -1
  718. package/dist/chunk-CMGR4ZEW.js +0 -209
  719. package/dist/chunk-CWPPNPOH.js +0 -23
  720. package/dist/chunk-DFEMTNPJ.js +0 -1219
  721. package/dist/chunk-DFEMTNPJ.js.map +0 -1
  722. package/dist/chunk-DGDI2D4M.js +0 -79
  723. package/dist/chunk-DGDI2D4M.js.map +0 -1
  724. package/dist/chunk-EIZUR2XW.js +0 -36
  725. package/dist/chunk-FISN7WE4.js +0 -798
  726. package/dist/chunk-FISN7WE4.js.map +0 -1
  727. package/dist/chunk-GYGWYIOZ.js +0 -200
  728. package/dist/chunk-GYGWYIOZ.js.map +0 -1
  729. package/dist/chunk-HCIPRAGS.js +0 -45
  730. package/dist/chunk-I2NOIW44.js +0 -83
  731. package/dist/chunk-I2NOIW44.js.map +0 -1
  732. package/dist/chunk-I3TIKTJO.js +0 -132
  733. package/dist/chunk-I3TIKTJO.js.map +0 -1
  734. package/dist/chunk-IAGBDSCS.js +0 -40
  735. package/dist/chunk-IELYAOGG.js +0 -78
  736. package/dist/chunk-IELYAOGG.js.map +0 -1
  737. package/dist/chunk-IGUYVGGI.js +0 -205
  738. package/dist/chunk-IO6GRPT6.js +0 -34
  739. package/dist/chunk-IPB7FTQX.js +0 -273
  740. package/dist/chunk-IPB7FTQX.js.map +0 -1
  741. package/dist/chunk-ITNUCOXM.js +0 -148
  742. package/dist/chunk-ITNUCOXM.js.map +0 -1
  743. package/dist/chunk-IUEN57TV.js +0 -722
  744. package/dist/chunk-IUEN57TV.js.map +0 -1
  745. package/dist/chunk-JNUWZ6D3.js +0 -57
  746. package/dist/chunk-JNUWZ6D3.js.map +0 -1
  747. package/dist/chunk-K2WCO3NX.js +0 -1
  748. package/dist/chunk-KVOXU4T5.js +0 -30
  749. package/dist/chunk-KXGNJJXB.js +0 -135
  750. package/dist/chunk-LFLXAY2W.js +0 -414
  751. package/dist/chunk-LFLXAY2W.js.map +0 -1
  752. package/dist/chunk-LMTH2RM6.js +0 -129
  753. package/dist/chunk-LV7M27WM.js +0 -702
  754. package/dist/chunk-LV7M27WM.js.map +0 -1
  755. package/dist/chunk-LXQT4WMP.js +0 -684
  756. package/dist/chunk-LXQT4WMP.js.map +0 -1
  757. package/dist/chunk-M2YKN37S.js +0 -524
  758. package/dist/chunk-M2YKN37S.js.map +0 -1
  759. package/dist/chunk-M6OST55S.js +0 -14
  760. package/dist/chunk-MD3Y6J3L.js +0 -278
  761. package/dist/chunk-MD3Y6J3L.js.map +0 -1
  762. package/dist/chunk-MTMJVJ5W.js +0 -73
  763. package/dist/chunk-MTMJVJ5W.js.map +0 -1
  764. package/dist/chunk-NF5JWERG.js +0 -74
  765. package/dist/chunk-PKHL44ER.js +0 -124
  766. package/dist/chunk-PSMV73A5.js +0 -117
  767. package/dist/chunk-Q7SS3IME.js +0 -120
  768. package/dist/chunk-Q7SS3IME.js.map +0 -1
  769. package/dist/chunk-QHJW5EXU.js +0 -54
  770. package/dist/chunk-RUEKROOS.js +0 -80
  771. package/dist/chunk-RUIMKQTA.js +0 -23
  772. package/dist/chunk-RUIMKQTA.js.map +0 -1
  773. package/dist/chunk-SKF73JOP.js +0 -355
  774. package/dist/chunk-SM3AVUHC.js +0 -42
  775. package/dist/chunk-SMXWYP24.js +0 -155
  776. package/dist/chunk-SRB2XEWB.js +0 -148
  777. package/dist/chunk-SRB2XEWB.js.map +0 -1
  778. package/dist/chunk-TA66UMI4.js +0 -123
  779. package/dist/chunk-TEILUWOI.js +0 -664
  780. package/dist/chunk-TEILUWOI.js.map +0 -1
  781. package/dist/chunk-TJYQIGAP.js +0 -82
  782. package/dist/chunk-TJYQIGAP.js.map +0 -1
  783. package/dist/chunk-UAG5KWVA.js +0 -367
  784. package/dist/chunk-UDRIWL7A.js +0 -382
  785. package/dist/chunk-UIU2THRG.js +0 -1937
  786. package/dist/chunk-UIU2THRG.js.map +0 -1
  787. package/dist/chunk-UPJNJGGA.js +0 -572
  788. package/dist/chunk-UPJNJGGA.js.map +0 -1
  789. package/dist/chunk-UV5MFVO3.js +0 -21
  790. package/dist/chunk-V7RWQRG7.js +0 -430
  791. package/dist/chunk-VCTFO5CO.js +0 -71
  792. package/dist/chunk-VFQGRQIH.js +0 -97
  793. package/dist/chunk-VFQGRQIH.js.map +0 -1
  794. package/dist/chunk-WWGT2MDV.js +0 -762
  795. package/dist/chunk-WWGT2MDV.js.map +0 -1
  796. package/dist/chunk-WYSO2NIH.js +0 -30
  797. package/dist/chunk-XXYIOFUB.js +0 -164
  798. package/dist/chunk-Y22T3KQE.js +0 -261
  799. package/dist/chunk-Y22T3KQE.js.map +0 -1
  800. package/dist/chunk-ZCGAHGUS.js +0 -230
  801. package/dist/chunk-ZYUC53LT.js +0 -1370
  802. package/dist/chunk-ZYUC53LT.js.map +0 -1
  803. package/dist/collection-facade-GQAOGJP2.js +0 -33
  804. package/dist/consent/index.d.ts +0 -23
  805. package/dist/crdt/index.d.ts +0 -34
  806. package/dist/decrypt-partition-IHtxEnTi.d.ts +0 -21
  807. package/dist/delegation-UL5HKLER.js +0 -19
  808. package/dist/derivations/index.d.ts +0 -70
  809. package/dist/describe/index.d.ts +0 -1
  810. package/dist/describe/index.js +0 -1
  811. package/dist/describe-aBkJR2sd.d.ts +0 -131
  812. package/dist/dev-unlock-C9Ro3v_O.d.ts +0 -263
  813. package/dist/discriminant-BN9REW3o.d.ts +0 -60
  814. package/dist/enclave-UL5LW66V.js +0 -88
  815. package/dist/executor-2FWQRLMG.js +0 -15
  816. package/dist/executor-QZ7BXICW.js +0 -9
  817. package/dist/executor-Z5ZLJVTV.js +0 -9
  818. package/dist/export-accessible-KRV5W4GH.js +0 -17
  819. package/dist/extract-partition-GLKBOXFQ.js +0 -30
  820. package/dist/fanout-sidecar-GF3DJ6KR.js +0 -71
  821. package/dist/fanout-sidecar-GF3DJ6KR.js.map +0 -1
  822. package/dist/forget/index.d.ts +0 -36
  823. package/dist/guards/index.d.ts +0 -35
  824. package/dist/hash-Cp5uwiox.d.ts +0 -67
  825. package/dist/history/index.d.ts +0 -61
  826. package/dist/i18n/index.d.ts +0 -37
  827. package/dist/in/index.d.ts +0 -5
  828. package/dist/index-B9QdHytu.d.ts +0 -123
  829. package/dist/index-BF9_96A5.d.ts +0 -123
  830. package/dist/index-BzUo1B6n.d.ts +0 -20730
  831. package/dist/indexing/index.d.ts +0 -39
  832. package/dist/issue-Y6UVIR43.js +0 -13
  833. package/dist/kernel/index.d.ts +0 -32
  834. package/dist/kernel/index.js +0 -53
  835. package/dist/ledger-RYI35CDS.js +0 -36
  836. package/dist/liberate-CRPZEV7O.js +0 -18
  837. package/dist/materialized-views/index.d.ts +0 -173
  838. package/dist/mime-magic-CGhw37_E.d.ts +0 -103
  839. package/dist/noydb-367AM4HT.js +0 -50
  840. package/dist/on/index.d.ts +0 -5
  841. package/dist/overlay-views/index.d.ts +0 -98
  842. package/dist/periods/index.d.ts +0 -20
  843. package/dist/pod/index.d.ts +0 -63
  844. package/dist/policy-IXK4FVXP.js +0 -41
  845. package/dist/portability/index.d.ts +0 -20
  846. package/dist/public-envelope-JHDQCPSX.js +0 -32
  847. package/dist/query/index.d.ts +0 -5
  848. package/dist/read-only-facade-5ADRJVTM.js +0 -8
  849. package/dist/registry-45RJNWGU.js +0 -9
  850. package/dist/registry-5GRV5VXI.js +0 -13
  851. package/dist/registry-WEUCHBO4.js +0 -11
  852. package/dist/request-withdrawal-GBPH2FDY.js +0 -25
  853. package/dist/revoke-TUFRGI6S.js +0 -18
  854. package/dist/sealed-record/index.d.ts +0 -69
  855. package/dist/session/index.d.ts +0 -44
  856. package/dist/shadow/index.d.ts +0 -15
  857. package/dist/signer-PNKTBVF7.js +0 -19
  858. package/dist/snapshots/index.d.ts +0 -26
  859. package/dist/stale-3JWHNDIY.js +0 -14
  860. package/dist/store-coordination-provider-3I7XWZZK.js +0 -142
  861. package/dist/subject-index-O75wKshW.d.ts +0 -362
  862. package/dist/sync/index.d.ts +0 -41
  863. package/dist/team/index.d.ts +0 -116
  864. package/dist/tiers/index.d.ts +0 -5
  865. package/dist/to/index.d.ts +0 -5
  866. package/dist/transition-guard-C7ol6oPw.d.ts +0 -165
  867. package/dist/tx/index.d.ts +0 -35
  868. package/dist/ui/index.d.ts +0 -1
  869. package/dist/ulid-DRH25k3y.d.ts +0 -66
  870. package/dist/util/index.d.ts +0 -79
  871. package/dist/vault-diff-B5fYNBL7.d.ts +0 -147
  872. package/dist/with/index.d.ts +0 -38
  873. package/dist/with-materialized-view-6p0Fk8bL.d.ts +0 -27
  874. package/dist/with-overlayed-view-BJ6mXGMd.d.ts +0 -12
  875. package/dist/with-rollup-BvQo3ROo.d.ts +0 -47
  876. package/dist/withdraw-accessible-FFS46EOD.js +0 -22
  877. /package/dist/{adapter/index.js.map → api-YGMINAET.js.map} +0 -0
  878. /package/dist/{chunk-V7RWQRG7.js.map → chunk-3CNQ7FQ3.js.map} +0 -0
  879. /package/dist/{chunk-NF5JWERG.js.map → chunk-3MSQLQNZ.js.map} +0 -0
  880. /package/dist/{chunk-IO6GRPT6.js.map → chunk-4R4Q64W5.js.map} +0 -0
  881. /package/dist/{chunk-SMXWYP24.js.map → chunk-5XIPOCQC.js.map} +0 -0
  882. /package/dist/{chunk-IGUYVGGI.js.map → chunk-6QILBDZU.js.map} +0 -0
  883. /package/dist/{chunk-AZAOEIKW.js.map → chunk-7E67FJ33.js.map} +0 -0
  884. /package/dist/{chunk-PSMV73A5.js.map → chunk-7NS43EXZ.js.map} +0 -0
  885. /package/dist/{chunk-CMGR4ZEW.js.map → chunk-A2Y6YFVN.js.map} +0 -0
  886. /package/dist/{chunk-HCIPRAGS.js.map → chunk-BCYQA5BK.js.map} +0 -0
  887. /package/dist/{chunk-LMTH2RM6.js.map → chunk-CB25ONKC.js.map} +0 -0
  888. /package/dist/{chunk-UV5MFVO3.js.map → chunk-CIKY6I4W.js.map} +0 -0
  889. /package/dist/{chunk-QHJW5EXU.js.map → chunk-D26JB3LZ.js.map} +0 -0
  890. /package/dist/{chunk-SM3AVUHC.js.map → chunk-DIRRS7WP.js.map} +0 -0
  891. /package/dist/{chunk-SKF73JOP.js.map → chunk-H44ZE4IE.js.map} +0 -0
  892. /package/dist/{chunk-UDRIWL7A.js.map → chunk-HFJIGWJC.js.map} +0 -0
  893. /package/dist/{chunk-ZCGAHGUS.js.map → chunk-KPGX66PM.js.map} +0 -0
  894. /package/dist/{chunk-5N6CZTCY.js.map → chunk-MCEKIAO4.js.map} +0 -0
  895. /package/dist/{chunk-CWPPNPOH.js.map → chunk-O2DYPAZY.js.map} +0 -0
  896. /package/dist/{chunk-KVOXU4T5.js.map → chunk-ODJWBC5I.js.map} +0 -0
  897. /package/dist/{chunk-VCTFO5CO.js.map → chunk-OFJ5GPNA.js.map} +0 -0
  898. /package/dist/{chunk-KXGNJJXB.js.map → chunk-PXWVF7MC.js.map} +0 -0
  899. /package/dist/{chunk-IAGBDSCS.js.map → chunk-Q3XSMOZM.js.map} +0 -0
  900. /package/dist/{chunk-AXRXJTE2.js.map → chunk-RKRGDAS7.js.map} +0 -0
  901. /package/dist/{chunk-XXYIOFUB.js.map → chunk-SRVQHVNX.js.map} +0 -0
  902. /package/dist/{chunk-M6OST55S.js.map → chunk-UFILRICG.js.map} +0 -0
  903. /package/dist/{chunk-3YFXJ3ZP.js.map → chunk-UTLEAJXC.js.map} +0 -0
  904. /package/dist/{chunk-TA66UMI4.js.map → chunk-VA4ZWLFY.js.map} +0 -0
  905. /package/dist/{chunk-UAG5KWVA.js.map → chunk-VR24ILCR.js.map} +0 -0
  906. /package/dist/{chunk-WYSO2NIH.js.map → chunk-XHV25KBM.js.map} +0 -0
  907. /package/dist/{chunk-PKHL44ER.js.map → chunk-YSXEFGND.js.map} +0 -0
  908. /package/dist/{chunk-EIZUR2XW.js.map → chunk-YXOUQ2H7.js.map} +0 -0
  909. /package/dist/{chunk-RUEKROOS.js.map → chunk-ZP5PL65C.js.map} +0 -0
  910. /package/dist/{describe → classified}/index.js.map +0 -0
  911. /package/dist/{api-RW3KP7WU.js.map → collection-facade-YE2O4J4O.js.map} +0 -0
  912. /package/dist/{chunk-BGIZAFY7.js.map → computed-W6MVAMWZ.js.map} +0 -0
  913. /package/dist/{chunk-K2WCO3NX.js.map → delegation-OPUU3R2E.js.map} +0 -0
  914. /package/dist/{collection-facade-GQAOGJP2.js.map → derive-BGUHU663.js.map} +0 -0
  915. /package/dist/{delegation-UL5HKLER.js.map → enclave-VXAQD4XJ.js.map} +0 -0
  916. /package/dist/{enclave-UL5LW66V.js.map → executor-GTVSUUBX.js.map} +0 -0
  917. /package/dist/{executor-2FWQRLMG.js.map → executor-GZWMTOXB.js.map} +0 -0
  918. /package/dist/{executor-QZ7BXICW.js.map → executor-XXGS4S3K.js.map} +0 -0
  919. /package/dist/{executor-Z5ZLJVTV.js.map → export-accessible-BMULIOYB.js.map} +0 -0
  920. /package/dist/{export-accessible-KRV5W4GH.js.map → extract-partition-JUQTWDXR.js.map} +0 -0
  921. /package/dist/{extract-partition-GLKBOXFQ.js.map → find-XRGCNGNN.js.map} +0 -0
  922. /package/dist/{issue-Y6UVIR43.js.map → issue-UB6AA5M6.js.map} +0 -0
  923. /package/dist/{kernel → lazy}/index.js.map +0 -0
  924. /package/dist/{ledger-RYI35CDS.js.map → ledger-FU6GH5EH.js.map} +0 -0
  925. /package/dist/{liberate-CRPZEV7O.js.map → liberate-YUN7W5QG.js.map} +0 -0
  926. /package/dist/{noydb-367AM4HT.js.map → link-set-MNADSH5M.js.map} +0 -0
  927. /package/dist/{policy-IXK4FVXP.js.map → noydb-6JLBZU4U.js.map} +0 -0
  928. /package/dist/{public-envelope-JHDQCPSX.js.map → policy-JTFOPPUU.js.map} +0 -0
  929. /package/dist/{read-only-facade-5ADRJVTM.js.map → public-envelope-NJVB7LPA.js.map} +0 -0
  930. /package/dist/{registry-45RJNWGU.js.map → read-only-facade-CHCKSEPD.js.map} +0 -0
  931. /package/dist/{registry-5GRV5VXI.js.map → register-VCKOBWKT.js.map} +0 -0
  932. /package/dist/{registry-WEUCHBO4.js.map → registry-72UKJ2L4.js.map} +0 -0
  933. /package/dist/{request-withdrawal-GBPH2FDY.js.map → registry-BZFLJNEH.js.map} +0 -0
  934. /package/dist/{revoke-TUFRGI6S.js.map → registry-YJEYSYI5.js.map} +0 -0
  935. /package/dist/{signer-PNKTBVF7.js.map → request-withdrawal-6MJRMFHF.js.map} +0 -0
  936. /package/dist/{stale-3JWHNDIY.js.map → revoke-4KUNSVJC.js.map} +0 -0
  937. /package/dist/{withdraw-accessible-FFS46EOD.js.map → satellites/index.js.map} +0 -0
  938. /package/dist/{store-coordination-provider-3I7XWZZK.js.map → store-coordination-provider-HPYVFJCV.js.map} +0 -0
@@ -1,1937 +0,0 @@
1
- import {
2
- reducerBuilder,
3
- wrapMoneyReducers
4
- } from "./chunk-LV7M27WM.js";
5
- import {
6
- MoneyPrecisionError,
7
- evaluateClause,
8
- formatScaledInt,
9
- hasFnClause,
10
- moneyFieldClause,
11
- parseToScaledInt,
12
- readPath
13
- } from "./chunk-M2YKN37S.js";
14
- import {
15
- applyI18nLocale
16
- } from "./chunk-5LUY7UTV.js";
17
- import {
18
- CrossJoinSourceUnknownError,
19
- CrossJoinTooLargeError,
20
- DanglingReferenceError,
21
- JoinTooLargeError,
22
- ValidationError
23
- } from "./chunk-ZYUC53LT.js";
24
-
25
- // src/kernel/query/join.ts
26
- var DEFAULT_JOIN_MAX_ROWS = 5e4;
27
- var JOIN_WARN_FRACTION = 0.8;
28
- function coerceRefKey(value) {
29
- if (value === null || value === void 0) return null;
30
- if (typeof value === "string") return value;
31
- if (typeof value === "number" || typeof value === "bigint") return String(value);
32
- return null;
33
- }
34
- var warnedDanglingKeys = /* @__PURE__ */ new Set();
35
- function warnOnceDangling(field, target, refId) {
36
- const key = `${field}\u2192${target}:${refId}`;
37
- if (warnedDanglingKeys.has(key)) return;
38
- warnedDanglingKeys.add(key);
39
- console.warn(
40
- `[noy-db] .join() encountered dangling ref in 'warn' mode: field "${field}" \u2192 "${target}:${refId}" not found. Attaching null.`
41
- );
42
- }
43
- var warnedCeilingKeys = /* @__PURE__ */ new Set();
44
- function warnCeilingApproaching(target, side, rows, maxRows) {
45
- const key = `${target}:${side}`;
46
- if (warnedCeilingKeys.has(key)) return;
47
- warnedCeilingKeys.add(key);
48
- const pct = Math.round(rows / maxRows * 100);
49
- console.warn(
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.`
51
- );
52
- }
53
- function applyJoins(rows, joins, context, locale) {
54
- if (joins.length === 0) return [...rows];
55
- let result = [...rows];
56
- for (const leg of joins) {
57
- result = applyOneJoin(result, leg, context, locale);
58
- }
59
- return result;
60
- }
61
- function applyOneJoin(leftRows, leg, context, locale) {
62
- if (leg.isDictJoin) {
63
- const dictSource = context.resolveDictSource?.(leg.field);
64
- if (!dictSource) {
65
- throw new Error(
66
- `.join() field "${leg.field}" on "${context.leftCollection}" is declared as a dictKey join but the dict source could not be resolved. Ensure the dictionary has at least one entry.`
67
- );
68
- }
69
- const out = [];
70
- const snapshot = dictSource.snapshot();
71
- const dictMap = /* @__PURE__ */ new Map();
72
- for (const entry of snapshot) {
73
- const k = readPath(entry, "key");
74
- if (typeof k === "string") dictMap.set(k, entry);
75
- }
76
- for (const left of leftRows) {
77
- const rawId = readPath(left, leg.field);
78
- const key = coerceRefKey(rawId);
79
- const dictEntry = key === null ? void 0 : dictMap.get(key);
80
- out.push({ ...left, [leg.as]: dictEntry ?? null });
81
- }
82
- return out;
83
- }
84
- const source = context.resolveSource(leg.target);
85
- if (!source) {
86
- throw new Error(
87
- `.join() cannot resolve target collection "${leg.target}" (referenced from field "${leg.field}" on "${context.leftCollection}"). Make sure the target collection has been opened via vault.collection() at least once before running the query.`
88
- );
89
- }
90
- const maxRows = leg.maxRows ?? DEFAULT_JOIN_MAX_ROWS;
91
- if (leftRows.length > maxRows) {
92
- throw new JoinTooLargeError({
93
- leftRows: leftRows.length,
94
- rightRows: -1,
95
- maxRows,
96
- side: "left",
97
- message: `.join() left side has ${leftRows.length} rows, exceeding the ${maxRows}-row ceiling for target "${leg.target}". Filter the left side further with where()/limit() before joining, or raise the ceiling via { maxRows }. Streaming joins over scan() are not yet supported.`
98
- });
99
- }
100
- if (leftRows.length > maxRows * JOIN_WARN_FRACTION) {
101
- warnCeilingApproaching(leg.target, "left", leftRows.length, maxRows);
102
- }
103
- const rightSnapshot = source.snapshot();
104
- if (rightSnapshot.length > maxRows) {
105
- throw new JoinTooLargeError({
106
- leftRows: leftRows.length,
107
- rightRows: rightSnapshot.length,
108
- maxRows,
109
- side: "right",
110
- message: `.join() right side "${leg.target}" has ${rightSnapshot.length} rows, exceeding the ${maxRows}-row ceiling. Raise the ceiling via { maxRows } if the data genuinely fits in memory, or track for streaming joins.`
111
- });
112
- }
113
- if (rightSnapshot.length > maxRows * JOIN_WARN_FRACTION) {
114
- warnCeilingApproaching(leg.target, "right", rightSnapshot.length, maxRows);
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;
118
- const strategy = leg.strategy ?? (source.lookupById ? "nested" : "hash");
119
- if (strategy === "nested" && source.lookupById) {
120
- const lookup = (id) => source.lookupById?.(id);
121
- return nestedLoopJoin(leftRows, leg, lookup, i18nResolve);
122
- }
123
- return hashJoin(leftRows, leg, rightSnapshot, i18nResolve);
124
- }
125
- function nestedLoopJoin(leftRows, leg, lookupById, i18nResolve) {
126
- const out = [];
127
- for (const left of leftRows) {
128
- const rawId = readPath(left, leg.field);
129
- const key = coerceRefKey(rawId);
130
- let right = key === null ? void 0 : lookupById(key);
131
- if (i18nResolve && right !== void 0) right = i18nResolve(right);
132
- out.push(attachJoin(left, leg, right, rawId));
133
- }
134
- return out;
135
- }
136
- function hashJoin(leftRows, leg, rightSnapshot, i18nResolve) {
137
- const rightMap = /* @__PURE__ */ new Map();
138
- for (const record of rightSnapshot) {
139
- const rawId = readPath(record, "id");
140
- const key = coerceRefKey(rawId);
141
- if (key !== null) {
142
- rightMap.set(key, record);
143
- }
144
- }
145
- const out = [];
146
- for (const left of leftRows) {
147
- const rawId = readPath(left, leg.field);
148
- const key = coerceRefKey(rawId);
149
- let right = key === null ? void 0 : rightMap.get(key);
150
- if (i18nResolve && right !== void 0) right = i18nResolve(right);
151
- out.push(attachJoin(left, leg, right, rawId));
152
- }
153
- return out;
154
- }
155
- function attachJoin(left, leg, right, rawId) {
156
- if (left === null || typeof left !== "object") {
157
- return left;
158
- }
159
- const merged = { ...left };
160
- const refKey = coerceRefKey(rawId);
161
- if (right === void 0) {
162
- if (refKey !== null && leg.mode === "strict") {
163
- throw new DanglingReferenceError({
164
- field: leg.field,
165
- target: leg.target,
166
- refId: refKey,
167
- message: `.join() strict dangling: record references "${leg.target}:${refKey}" via field "${leg.field}", but no such record exists. Use ref() mode 'warn' or 'cascade' if dangling refs are acceptable, or run vault.checkIntegrity() to find and fix the orphans.`
168
- });
169
- }
170
- if (refKey !== null && leg.mode === "warn") {
171
- warnOnceDangling(leg.field, leg.target, refKey);
172
- }
173
- merged[leg.as] = null;
174
- } else {
175
- merged[leg.as] = right;
176
- }
177
- return merged;
178
- }
179
- function resetJoinWarnings() {
180
- warnedDanglingKeys.clear();
181
- warnedCeilingKeys.clear();
182
- }
183
-
184
- // src/kernel/query/live.ts
185
- function buildLiveQuery(recompute, upstreams) {
186
- return new LiveQueryImpl(recompute, upstreams);
187
- }
188
- var LiveQueryImpl = class {
189
- constructor(recompute, upstreams) {
190
- this.recompute = recompute;
191
- this.refresh();
192
- for (const upstream of upstreams) {
193
- try {
194
- this.unsubs.push(upstream.subscribe(this.onUpstreamChange));
195
- } catch (err) {
196
- this._error = err instanceof Error ? err : new Error(String(err));
197
- }
198
- }
199
- }
200
- recompute;
201
- _value = [];
202
- _error = null;
203
- listeners = /* @__PURE__ */ new Set();
204
- unsubs = [];
205
- stopped = false;
206
- get value() {
207
- return this._value;
208
- }
209
- get error() {
210
- return this._error;
211
- }
212
- /**
213
- * Bound change handler — used as the callback passed to every
214
- * upstream's subscribe. Bound via class field so the `this`
215
- * context survives the indirect call from arbitrary upstreams.
216
- */
217
- onUpstreamChange = () => {
218
- this.refresh();
219
- for (const cb of this.listeners) {
220
- try {
221
- cb();
222
- } catch {
223
- }
224
- }
225
- };
226
- refresh() {
227
- if (this.stopped) return;
228
- try {
229
- this._value = this.recompute();
230
- this._error = null;
231
- } catch (err) {
232
- this._error = err instanceof Error ? err : new Error(String(err));
233
- }
234
- }
235
- subscribe(cb) {
236
- if (this.stopped) return () => {
237
- };
238
- this.listeners.add(cb);
239
- return () => this.listeners.delete(cb);
240
- }
241
- stop() {
242
- if (this.stopped) return;
243
- this.stopped = true;
244
- for (const unsub of this.unsubs) {
245
- try {
246
- unsub();
247
- } catch {
248
- }
249
- }
250
- this.unsubs.length = 0;
251
- this.listeners.clear();
252
- }
253
- };
254
-
255
- // src/with-lookup/aggregate/strategy.ts
256
- var NOT_ENABLED = new Error(
257
- 'Aggregate / groupBy is not enabled on this Noydb instance. Import `{ withAggregate }` from "@noy-db/hub/aggregate" and pass it to `createNoydb({ aggregateStrategy: withAggregate() })`.'
258
- );
259
- var NO_AGGREGATE = {
260
- aggregate() {
261
- throw NOT_ENABLED;
262
- },
263
- groupBy() {
264
- throw NOT_ENABLED;
265
- },
266
- groupByN() {
267
- throw NOT_ENABLED;
268
- },
269
- scanAggregate() {
270
- throw NOT_ENABLED;
271
- }
272
- };
273
-
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
546
- var EMPTY_PLAN = {
547
- clauses: [],
548
- orderBy: [],
549
- limit: void 0,
550
- offset: 0,
551
- joins: []
552
- };
553
- var DEFAULT_CROSS_JOIN_MAX_ROWS = 5e4;
554
- var Query = class _Query {
555
- source;
556
- plan;
557
- joinContext;
558
- aggregateStrategy;
559
- predicates;
560
- constructor(source, plan = EMPTY_PLAN, joinContext, aggregateStrategy = NO_AGGREGATE, predicates) {
561
- this.source = source;
562
- this.plan = plan;
563
- this.joinContext = joinContext;
564
- this.aggregateStrategy = aggregateStrategy;
565
- this.predicates = predicates;
566
- }
567
- /**
568
- * @internal — accessor for the materialized-view dependency
569
- * analyzer. Not part of the public API; consumers should use the
570
- * builder methods, not inspect the plan directly.
571
- */
572
- _plan() {
573
- return this.plan;
574
- }
575
- /**
576
- * @internal — accessor for the materialized-view dependency
577
- * analyzer. Returns the join resolution context (or `undefined` for
578
- * queries constructed without a Collection backing).
579
- */
580
- _joinContext() {
581
- return this.joinContext;
582
- }
583
- /**
584
- * @internal — clone this Query with a declared-predicate map
585
- * attached. Used by the materialized-view registry to enable
586
- * `.wherePredicate(name, ctx?)` for the MV's query callback.
587
- * Consumers don't call this directly.
588
- */
589
- _withPredicates(predicates) {
590
- return new _Query(
591
- this.source,
592
- this.plan,
593
- this.joinContext,
594
- this.aggregateStrategy,
595
- predicates
596
- );
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
- }
628
- /**
629
- * Filter by a registered deterministic predicate. Requires
630
- * the Query to have been augmented with a predicates map (typically
631
- * via the materialized-view registry — bare Queries constructed
632
- * outside an MV throw on `.wherePredicate()`).
633
- *
634
- * `ctx` is an optional opaque value passed verbatim to the predicate
635
- * function. Both `predicateHash` (from the registration) and a
636
- * canonical-JSON hash of `ctx` fold into the MV's `queryHash`, so
637
- * either changing forces refresh on next visit.
638
- */
639
- wherePredicate(name, ctx) {
640
- if (!this.predicates) {
641
- throw new Error(
642
- `.wherePredicate("${name}"): no predicates registered on this Query. Function-based predicates require the Query to be obtained from inside a materialized-view query() callback whose strategy declares \`predicates: { ${name}: { hash, fn } }\`.`
643
- );
644
- }
645
- const decl = this.predicates.get(name);
646
- if (!decl) {
647
- throw new Error(
648
- `.wherePredicate("${name}"): predicate not registered. Available: ${[...this.predicates.keys()].join(", ") || "(none)"}.`
649
- );
650
- }
651
- const clause = {
652
- type: "wherePredicate",
653
- name,
654
- ctx,
655
- predicateHash: decl.hash,
656
- ctxHash: canonicalCtxHash(ctx),
657
- fn: decl.fn
658
- };
659
- return new _Query(
660
- this.source,
661
- { ...this.plan, clauses: [...this.plan.clauses, clause] },
662
- this.joinContext,
663
- this.aggregateStrategy,
664
- this.predicates
665
- );
666
- }
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
- */
676
- where(field, op, value) {
677
- const desc = this.source.moneyFields?.[field];
678
- const clause = desc ? moneyFieldClause(field, op, value, desc) : { type: "field", field, op, value };
679
- return new _Query(
680
- this.source,
681
- { ...this.plan, clauses: [...this.plan.clauses, clause] },
682
- this.joinContext,
683
- this.aggregateStrategy,
684
- this.predicates
685
- );
686
- }
687
- /**
688
- * Logical OR group. Pass a callback that builds a sub-query.
689
- * Each clause inside the callback is OR-combined; the group itself
690
- * joins the parent plan with AND.
691
- */
692
- or(builder) {
693
- const sub = builder(
694
- new _Query(this.source, EMPTY_PLAN, this.joinContext, this.aggregateStrategy, this.predicates)
695
- );
696
- const group = {
697
- type: "group",
698
- op: "or",
699
- clauses: sub.plan.clauses
700
- };
701
- return new _Query(
702
- this.source,
703
- { ...this.plan, clauses: [...this.plan.clauses, group] },
704
- this.joinContext,
705
- this.aggregateStrategy,
706
- this.predicates
707
- );
708
- }
709
- /**
710
- * Logical AND group. Same shape as `or()` but every clause inside the group
711
- * must match. Useful for explicit grouping inside a larger OR.
712
- */
713
- and(builder) {
714
- const sub = builder(
715
- new _Query(this.source, EMPTY_PLAN, this.joinContext, this.aggregateStrategy, this.predicates)
716
- );
717
- const group = {
718
- type: "group",
719
- op: "and",
720
- clauses: sub.plan.clauses
721
- };
722
- return new _Query(
723
- this.source,
724
- { ...this.plan, clauses: [...this.plan.clauses, group] },
725
- this.joinContext,
726
- this.aggregateStrategy,
727
- this.predicates
728
- );
729
- }
730
- /** Escape hatch: add an arbitrary predicate function. Not serializable. */
731
- filter(fn) {
732
- const clause = {
733
- type: "filter",
734
- fn
735
- };
736
- return new _Query(
737
- this.source,
738
- { ...this.plan, clauses: [...this.plan.clauses, clause] },
739
- this.joinContext,
740
- this.aggregateStrategy,
741
- this.predicates
742
- );
743
- }
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 };
751
- return new _Query(
752
- this.source,
753
- { ...this.plan, orderBy: [...this.plan.orderBy, entry] },
754
- this.joinContext,
755
- this.aggregateStrategy,
756
- this.predicates
757
- );
758
- }
759
- /** Cap the result size. */
760
- limit(n) {
761
- return new _Query(
762
- this.source,
763
- { ...this.plan, limit: n },
764
- this.joinContext,
765
- this.aggregateStrategy,
766
- this.predicates
767
- );
768
- }
769
- /** Skip the first N matching records (after ordering). */
770
- offset(n) {
771
- return new _Query(
772
- this.source,
773
- { ...this.plan, offset: n },
774
- this.joinContext,
775
- this.aggregateStrategy,
776
- this.predicates
777
- );
778
- }
779
- /**
780
- * Resolve a `ref()`-declared foreign key and attach the right-side
781
- * record under `opts.as`. — eager, single-FK, intra-
782
- * vault joins.
783
- *
784
- * ```ts
785
- * const rows = invoices.query()
786
- * .where('status', '==', 'open')
787
- * .join('clientId', { as: 'client' })
788
- * .toArray()
789
- * // → [{ id, amount, client: { id, name, ... } }, ...]
790
- * ```
791
- *
792
- * Preconditions:
793
- * - The Query must have a `joinContext` (constructed via
794
- * `Collection.query()`, not `new Query`).
795
- * - `field` must have a matching `refs: { [field]: ref('<target>') }`
796
- * declaration on the left collection.
797
- * - The target collection must be reachable via the vault
798
- * (either currently open or openable on demand).
799
- *
800
- * Strategy:
801
- * - Nested-loop against `lookupById` when the target source
802
- * provides it (the common path for Collection targets).
803
- * - Hash join otherwise, or when `{ strategy: 'hash' }` is
804
- * explicitly passed for test purposes.
805
- *
806
- * Ref-mode semantics on dangling refs (left record has a non-null
807
- * FK value pointing at a right-side id that doesn't exist):
808
- * - `strict` → throws `DanglingReferenceError` with the full
809
- * field / target / refId context.
810
- * - `warn` → attaches `null` and emits a one-shot warning per
811
- * unique dangling pair.
812
- * - `cascade` → attaches `null` silently. Cascade is a
813
- * delete-time mode; dangling refs visible at read time are
814
- * either mid-flight cascades or pre-existing orphans, not a
815
- * DSL-level error.
816
- *
817
- * A left-side record whose FK field is `null` / `undefined` is NOT
818
- * a dangling ref — it's "no reference at all", always allowed
819
- * regardless of mode.
820
- *
821
- * The return type widens `T` with `Record<As, R | null>`. The `R`
822
- * parameter is optional — supply it explicitly for type-checked
823
- * access to the joined fields:
824
- *
825
- * ```ts
826
- * invoices.query().join<'client', Client>('clientId', { as: 'client' })
827
- * // ^^^^^^^^^^^^^^^^^^^ alias literal + right-side type
828
- * ```
829
- *
830
- * Without the generic, the joined field is typed as `unknown`, which
831
- * still works but requires a cast to access its properties.
832
- *
833
- * Joins stay intra-vault by construction — cross-vault
834
- * correlation goes through `Noydb.queryAcross`, not
835
- * `.join()`.
836
- */
837
- join(field, opts) {
838
- if (!this.joinContext) {
839
- throw new Error(
840
- `Query.join() requires a join context. Use collection.query() to construct a join-capable Query instead of the Query constructor directly (the direct constructor is only used for tests with plain-object sources).`
841
- );
842
- }
843
- const descriptor = this.joinContext.resolveRef(field);
844
- const isDictJoinField = !descriptor && this.joinContext.resolveDictSource?.(field) != null;
845
- if (!descriptor && !isDictJoinField) {
846
- throw new Error(
847
- `Query.join(): no ref() declared for field "${field}" on collection "${this.joinContext.leftCollection}". Add refs: { ${field}: ref('<target-collection>') } to the collection options, then retry. See the ref() docs for the full list of modes.`
848
- );
849
- }
850
- const leg = descriptor ? {
851
- field,
852
- as: opts.as,
853
- target: descriptor.target,
854
- mode: descriptor.mode,
855
- strategy: opts.strategy,
856
- maxRows: opts.maxRows,
857
- // constraint #1 — always 'all' in. Do not remove.
858
- partitionScope: "all"
859
- } : {
860
- // Dict join leg
861
- field,
862
- as: opts.as,
863
- target: field,
864
- // dict name = field name for dictKey
865
- mode: "strict",
866
- strategy: opts.strategy,
867
- maxRows: opts.maxRows,
868
- partitionScope: "all",
869
- isDictJoin: true
870
- };
871
- return new _Query(
872
- this.source,
873
- { ...this.plan, joins: [...this.plan.joins, leg] },
874
- this.joinContext,
875
- this.aggregateStrategy,
876
- this.predicates
877
- );
878
- }
879
- /**
880
- * Cartesian-product cross-join against `target` collection. Each result row
881
- * carries the original `T` fields plus `result[as]` populated from every
882
- * right-side row (or the filtered subset when `on:` is supplied).
883
- *
884
- * **Order matters:** `.where().crossJoin()` filters BEFORE expanding (cheaper);
885
- * `.crossJoin().where('alias.field', ...)` filters AFTER (required when the
886
- * where clause references the aliased fields).
887
- *
888
- * **Cost ceiling:** `CrossJoinTooLargeError` fires before allocation when
889
- * `leftRows × rightRows` (or the cumulative lateral count) exceeds the limit.
890
- * Default: 50,000 rows. Override per-clause with `{ maxRows: N }`.
891
- *
892
- * **`on:` shapes:**
893
- * - `on: (left) => TTarget[]` — subset form (most efficient)
894
- * - `on: (left) => (right) => boolean` — predicate form
895
- * - `on: { predicate: 'name' }` — MV-safe, hash-tracked form
896
- * (requires the Query to have been augmented via `_withPredicates`)
897
- *
898
- * Requires a JoinContext (constructed via `collection.query()`).
899
- */
900
- crossJoin(target, opts) {
901
- if (!this.joinContext) {
902
- throw new Error(
903
- `Query.crossJoin("${target}"): requires a join context. Use collection.query() to construct a cross-join-capable Query instead of the Query constructor directly.`
904
- );
905
- }
906
- let onFn;
907
- let onPredicateName;
908
- if (opts.on !== void 0) {
909
- if (typeof opts.on === "function") {
910
- onFn = opts.on;
911
- if (this.predicates) {
912
- console.warn(
913
- `Query.crossJoin("${target}", { on: callback }): inline on: callback inside a withMaterializedView query() disables queryHash drift detection for this cross-join. Use on: { predicate: '<name>' } to enable it.`
914
- );
915
- }
916
- } else {
917
- const predName = opts.on.predicate;
918
- if (!this.predicates) {
919
- throw new Error(
920
- `Query.crossJoin("${target}", { on: { predicate: "${predName}" } }): the { predicate } form requires a predicates map. Use this form inside a withMaterializedView query() callback that declares predicates: { ${predName}: { hash, fn } }.`
921
- );
922
- }
923
- const decl = this.predicates.get(predName);
924
- if (!decl) {
925
- throw new Error(
926
- `Query.crossJoin("${target}"): predicate "${predName}" not registered. Available: ${[...this.predicates.keys()].join(", ") || "(none)"}.`
927
- );
928
- }
929
- const as = opts.as;
930
- const predicateFn = decl.fn;
931
- onFn = (_left) => (right) => predicateFn({ ..._left, [as]: right });
932
- onPredicateName = predName;
933
- }
934
- }
935
- const clause = {
936
- type: "crossJoin",
937
- target,
938
- as: opts.as,
939
- ...onFn !== void 0 && { on: onFn },
940
- ...onPredicateName !== void 0 && { onPredicateName },
941
- ...opts.maxRows !== void 0 && { maxRows: opts.maxRows }
942
- };
943
- return new _Query(
944
- this.source,
945
- { ...this.plan, clauses: [...this.plan.clauses, clause] },
946
- this.joinContext,
947
- this.aggregateStrategy,
948
- this.predicates
949
- );
950
- }
951
- /**
952
- * Execute the plan and return the matching records. When the plan
953
- * carries any join legs, they are applied after `where` / `orderBy`
954
- * / `limit` / `offset` narrow the left set. See the `.join()` doc
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.)
961
- */
962
- toArray(opts) {
963
- const base = this.decodeMoney(executePlanWithSource(this.source, this.plan, this.joinContext, opts?.locale));
964
- if (this.plan.joins.length === 0) return base;
965
- if (!this.joinContext) {
966
- throw new Error(
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.`
968
- );
969
- }
970
- return applyJoins(base, this.plan.joins, this.joinContext, opts?.locale);
971
- }
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);
992
- return arr[0] ?? null;
993
- }
994
- /**
995
- * Return the number of matching records (after where/filter,
996
- * before limit). **Joins are NOT applied** — count() reports the
997
- * left-side cardinality, because joins in are projection-only
998
- * (they attach an aliased field; they never filter). Running joins
999
- * here just to discard the aliases would be wasteful, and in strict
1000
- * mode it could throw `DanglingReferenceError` for a call whose
1001
- * intent is purely to count.
1002
- */
1003
- count() {
1004
- if (this.plan.clauses.some((c) => c.type === "crossJoin")) {
1005
- if (!this.joinContext) {
1006
- throw new Error(
1007
- `Query.count(): plan contains crossJoin clauses but no JoinContext is attached.`
1008
- );
1009
- }
1010
- return executeClausePipeline(this.source, this.plan.clauses, this.joinContext).length;
1011
- }
1012
- const { candidates, remainingClauses } = candidateRecords(this.source, this.plan.clauses);
1013
- if (remainingClauses.length === 0) return candidates.length;
1014
- return filterRecords(candidates, remainingClauses, fnViewDecoder(this.source)).length;
1015
- }
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
- }
1022
- const source = this.source;
1023
- const clauses = this.plan.clauses;
1024
- const joinCtx = this.joinContext;
1025
- const hasCrossJoins = clauses.some((c) => c.type === "crossJoin");
1026
- const executeRecords = () => {
1027
- if (hasCrossJoins) {
1028
- if (!joinCtx) throw new Error("Query.aggregate(): crossJoin requires a join context");
1029
- return executeClausePipeline(source, clauses, joinCtx);
1030
- }
1031
- const { candidates, remainingClauses } = candidateRecords(source, clauses);
1032
- return remainingClauses.length === 0 ? candidates : filterRecords(candidates, remainingClauses, fnViewDecoder(source));
1033
- };
1034
- const upstreams = [];
1035
- if (source.subscribe) {
1036
- const subscribe = source.subscribe.bind(source);
1037
- upstreams.push({ subscribe: (cb) => subscribe(cb) });
1038
- }
1039
- return this.aggregateStrategy.aggregate(executeRecords, spec, upstreams);
1040
- }
1041
- groupBy(...fields) {
1042
- if (fields.length === 0) {
1043
- throw new Error(".groupBy() requires at least one field");
1044
- }
1045
- const source = this.source;
1046
- const clauses = this.plan.clauses;
1047
- const joinCtx = this.joinContext;
1048
- const hasCrossJoins = clauses.some((c) => c.type === "crossJoin");
1049
- const executeRecords = () => {
1050
- if (hasCrossJoins) {
1051
- if (!joinCtx) throw new Error("Query.groupBy(): crossJoin requires a join context");
1052
- return executeClausePipeline(source, clauses, joinCtx);
1053
- }
1054
- const { candidates, remainingClauses } = candidateRecords(source, clauses);
1055
- return remainingClauses.length === 0 ? candidates : filterRecords(candidates, remainingClauses, fnViewDecoder(source));
1056
- };
1057
- const upstreams = [];
1058
- if (source.subscribe) {
1059
- const subscribe = source.subscribe.bind(source);
1060
- upstreams.push({ subscribe: (cb) => subscribe(cb) });
1061
- }
1062
- if (fields.length === 1) {
1063
- const field = fields[0];
1064
- const dictLabelResolver = buildDictLabelResolver(this.joinContext, field);
1065
- return this.aggregateStrategy.groupBy(
1066
- executeRecords,
1067
- field,
1068
- upstreams,
1069
- dictLabelResolver,
1070
- this.source.moneyFields
1071
- );
1072
- }
1073
- return this.aggregateStrategy.groupByN(
1074
- executeRecords,
1075
- fields,
1076
- upstreams,
1077
- this.source.moneyFields
1078
- );
1079
- }
1080
- /**
1081
- * Re-run the query whenever the source notifies of changes.
1082
- * Returns an unsubscribe function. The callback receives the latest result.
1083
- * Throws if the source does not support subscriptions.
1084
- *
1085
- * **For joined queries, prefer `.live()`** — `subscribe()`
1086
- * only re-fires on LEFT-side changes, so joined data can be
1087
- * stale if the right side mutates between emissions. `.live()`
1088
- * merges change streams from every join target.
1089
- */
1090
- subscribe(cb) {
1091
- if (!this.source.subscribe) {
1092
- throw new Error("Query source does not support subscriptions. Pass a source with a subscribe() method.");
1093
- }
1094
- cb(this.toArray());
1095
- return this.source.subscribe(() => cb(this.toArray()));
1096
- }
1097
- /**
1098
- * Reactive terminal — returns a `LiveQuery<T>` that re-runs the
1099
- * query and updates its `value` whenever any source feeding it
1100
- * mutates..
1101
- *
1102
- * For non-joined queries, `.live()` is a convenience over the
1103
- * existing `.subscribe()` callback shape: a hand-rolled reactive
1104
- * primitive with `value` / `error` fields and a `subscribe(cb)`
1105
- * notification channel. Frame-agnostic — Vue / React / Solid
1106
- * adapters wrap it in their own primitive.
1107
- *
1108
- * For joined queries, `.live()` additionally subscribes to every
1109
- * join target's change stream. Mutations on a right-side
1110
- * collection (insert / update / delete of a client referenced by
1111
- * an invoice) re-fire the live query and re-evaluate every
1112
- * dependent left row. Right-side targets are deduped by
1113
- * collection name, so a chain that joins the same target twice
1114
- * (e.g. billing client + shipping client → both 'clients') only
1115
- * subscribes once.
1116
- *
1117
- * **Ref-mode behavior on right-side disappearance** — matches the
1118
- * eager `.toArray()` contract from :
1119
- * - `strict` → re-run throws `DanglingReferenceError`. The
1120
- * LiveQuery catches the throw, stores it in `live.error`, and
1121
- * notifies listeners (the throw does NOT propagate out of
1122
- * the source's change handler — that would tear down the
1123
- * emitter). Consumers check `live.error` after each
1124
- * notification and render an error state in the UI.
1125
- * - `warn` → joined value flips to `null`; the existing
1126
- * warn-channel deduplication keeps repeated re-runs from
1127
- * spamming the console.
1128
- * - `cascade` → no special handling needed; the cascade-
1129
- * delete mechanism propagates the right-side delete into the
1130
- * left collection on the next tick, and the live query
1131
- * naturally re-fires with the orphaned left rows gone.
1132
- *
1133
- * Always call `live.stop()` when finished — it tears down every
1134
- * upstream subscription. The Vue layer's `onUnmounted` hook
1135
- * should call `stop()` automatically; raw consumers must do it
1136
- * themselves.
1137
- *
1138
- * **Limitations:**
1139
- * - No granular delta updates — the whole query re-runs on
1140
- * every change.
1141
- * - No microtask batching — bursty changes produce one re-run
1142
- * per change.
1143
- * - No re-planning under live mutations — the planner picks
1144
- * once at subscription time and reuses the same plan.
1145
- * - Streaming live joins are deferred.
1146
- */
1147
- live() {
1148
- const upstreams = [];
1149
- if (this.source.subscribe) {
1150
- const leftSubscribe = this.source.subscribe.bind(this.source);
1151
- upstreams.push({
1152
- subscribe: (cb) => leftSubscribe(cb)
1153
- });
1154
- }
1155
- if (this.plan.joins.length > 0 && this.joinContext) {
1156
- const subscribed = /* @__PURE__ */ new Set();
1157
- for (const leg of this.plan.joins) {
1158
- if (subscribed.has(leg.target)) continue;
1159
- subscribed.add(leg.target);
1160
- const rightSource = this.joinContext.resolveSource(leg.target);
1161
- if (rightSource?.subscribe) {
1162
- const rightSubscribe = rightSource.subscribe.bind(rightSource);
1163
- upstreams.push({
1164
- subscribe: (cb) => rightSubscribe(cb)
1165
- });
1166
- }
1167
- }
1168
- }
1169
- if (this.joinContext) {
1170
- const subscribedCross = /* @__PURE__ */ new Set();
1171
- for (const clause of this.plan.clauses) {
1172
- if (clause.type !== "crossJoin") continue;
1173
- if (subscribedCross.has(clause.target)) continue;
1174
- subscribedCross.add(clause.target);
1175
- const rightSource = this.joinContext.resolveSource(clause.target);
1176
- if (rightSource?.subscribe) {
1177
- const rightSubscribe = rightSource.subscribe.bind(rightSource);
1178
- upstreams.push({
1179
- subscribe: (cb) => rightSubscribe(cb)
1180
- });
1181
- }
1182
- }
1183
- }
1184
- return buildLiveQuery(() => this.toArray(), upstreams);
1185
- }
1186
- /**
1187
- * Return the plan as a JSON-friendly object. FilterClause entries are
1188
- * stripped (their `fn` cannot be serialized) and replaced with
1189
- * { type: 'filter', fn: '[function]' } so devtools can still see them.
1190
- */
1191
- toPlan() {
1192
- return serializePlan(this.plan);
1193
- }
1194
- };
1195
- function executePlanWithSource(source, plan, joinContext, locale) {
1196
- const hasCrossJoins = plan.clauses.some((c) => c.type === "crossJoin");
1197
- let result;
1198
- if (hasCrossJoins) {
1199
- if (!joinContext) {
1200
- throw new Error(
1201
- `Query.toArray(): plan contains crossJoin clauses but no JoinContext is attached. Use collection.query() instead of new Query() for cross-join support.`
1202
- );
1203
- }
1204
- result = executeClausePipeline(source, plan.clauses, joinContext);
1205
- } else {
1206
- const { candidates, remainingClauses } = candidateRecords(source, plan.clauses);
1207
- result = remainingClauses.length === 0 ? [...candidates] : filterRecords(candidates, remainingClauses, fnViewDecoder(source));
1208
- }
1209
- if (plan.orderBy.length > 0) {
1210
- const labelMaps = buildOrderLabelMaps(plan.orderBy, joinContext, locale);
1211
- result = sortRecords(result, plan.orderBy, source.moneyFields, labelMaps);
1212
- }
1213
- if (plan.offset > 0) {
1214
- result = result.slice(plan.offset);
1215
- }
1216
- if (plan.limit !== void 0) {
1217
- result = result.slice(0, plan.limit);
1218
- }
1219
- return result;
1220
- }
1221
- function candidateRecords(source, clauses) {
1222
- const indexes = source.getIndexes?.();
1223
- if (!indexes || !source.lookupById || clauses.length === 0) {
1224
- return { candidates: source.snapshot(), remainingClauses: clauses };
1225
- }
1226
- const lookupById = (id) => source.lookupById?.(id);
1227
- for (let i = 0; i < clauses.length; i++) {
1228
- const clause = clauses[i];
1229
- if (clause.type !== "field") continue;
1230
- if (!indexes.has(clause.field)) continue;
1231
- if (clause.money?.mode === "multi") continue;
1232
- let ids = null;
1233
- if (clause.op === "==") {
1234
- ids = indexes.lookupEqual(clause.field, clause.value);
1235
- } else if (clause.op === "in" && Array.isArray(clause.value)) {
1236
- ids = indexes.lookupIn(clause.field, clause.value);
1237
- }
1238
- if (ids !== null) {
1239
- const remaining = [];
1240
- for (let j = 0; j < clauses.length; j++) {
1241
- if (j !== i) remaining.push(clauses[j]);
1242
- }
1243
- return {
1244
- candidates: materializeIds(ids, lookupById),
1245
- remainingClauses: remaining
1246
- };
1247
- }
1248
- }
1249
- return { candidates: source.snapshot(), remainingClauses: clauses };
1250
- }
1251
- function materializeIds(ids, lookupById) {
1252
- const out = [];
1253
- for (const id of ids) {
1254
- const record = lookupById(id);
1255
- if (record !== void 0) out.push(record);
1256
- }
1257
- return out;
1258
- }
1259
- function executePlan(records, plan) {
1260
- if (plan.clauses.some((c) => c.type === "crossJoin")) {
1261
- throw new Error(
1262
- `executePlan(): does not support crossJoin clauses. executePlan is a stateless pure function \u2014 it cannot resolve cross-join right-side collections. Use Query.toArray() (via collection.query()) instead.`
1263
- );
1264
- }
1265
- let result = filterRecords(records, plan.clauses);
1266
- if (plan.orderBy.length > 0) {
1267
- result = sortRecords(result, plan.orderBy);
1268
- }
1269
- if (plan.offset > 0) {
1270
- result = result.slice(plan.offset);
1271
- }
1272
- if (plan.limit !== void 0) {
1273
- result = result.slice(0, plan.limit);
1274
- }
1275
- return result;
1276
- }
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) {
1283
- if (clauses.length === 0) return [...records];
1284
- const needsFnView = decodeForFns !== void 0 && hasFnClause(clauses);
1285
- const out = [];
1286
- for (const r of records) {
1287
- const fnView = needsFnView ? decodeForFns(r) : void 0;
1288
- let matches = true;
1289
- for (const clause of clauses) {
1290
- if (!evaluateClause(r, clause, fnView)) {
1291
- matches = false;
1292
- break;
1293
- }
1294
- }
1295
- if (matches) out.push(r);
1296
- }
1297
- return out;
1298
- }
1299
- function executeClausePipeline(source, clauses, joinContext) {
1300
- let rel = [...source.snapshot()];
1301
- let filterBatch = [];
1302
- const decodeForFns = fnViewDecoder(source);
1303
- for (const clause of clauses) {
1304
- if (clause.type === "crossJoin") {
1305
- if (filterBatch.length > 0) {
1306
- rel = filterRecords(rel, filterBatch, decodeForFns);
1307
- filterBatch = [];
1308
- }
1309
- const rightSource = joinContext.resolveSource(clause.target);
1310
- if (!rightSource) {
1311
- throw new CrossJoinSourceUnknownError(clause.target, joinContext.leftCollection);
1312
- }
1313
- rel = applyCrossJoin(rel, clause, rightSource);
1314
- } else {
1315
- filterBatch.push(clause);
1316
- }
1317
- }
1318
- if (filterBatch.length > 0) {
1319
- rel = filterRecords(rel, filterBatch, decodeForFns);
1320
- }
1321
- return rel;
1322
- }
1323
- function applyCrossJoin(leftRel, clause, rightSource) {
1324
- const rightRows = rightSource.snapshot();
1325
- const maxRows = clause.maxRows ?? DEFAULT_CROSS_JOIN_MAX_ROWS;
1326
- const { as } = clause;
1327
- if (!clause.on) {
1328
- const product = leftRel.length * rightRows.length;
1329
- if (product > maxRows) {
1330
- throw new CrossJoinTooLargeError({ target: clause.target, expected: product, limit: maxRows });
1331
- }
1332
- const expanded2 = [];
1333
- for (const left of leftRel) {
1334
- const leftObj = left;
1335
- for (const right of rightRows) {
1336
- expanded2.push({ ...leftObj, [as]: right });
1337
- }
1338
- }
1339
- return expanded2;
1340
- }
1341
- const expanded = [];
1342
- let cumulative = 0;
1343
- for (const left of leftRel) {
1344
- const callbackResult = clause.on(left);
1345
- let filteredRight;
1346
- if (Array.isArray(callbackResult)) {
1347
- filteredRight = callbackResult;
1348
- } else {
1349
- filteredRight = rightRows.filter(
1350
- callbackResult
1351
- );
1352
- }
1353
- cumulative += filteredRight.length;
1354
- if (cumulative > maxRows) {
1355
- throw new CrossJoinTooLargeError({
1356
- target: clause.target,
1357
- expected: cumulative,
1358
- limit: maxRows
1359
- });
1360
- }
1361
- const leftObj = left;
1362
- for (const right of filteredRight) {
1363
- expanded.push({ ...leftObj, [as]: right });
1364
- }
1365
- }
1366
- return expanded;
1367
- }
1368
- function sortRecords(records, orderBy, moneyFields, labelMaps) {
1369
- return [...records].sort((a, b) => {
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);
1383
- if (cmp !== 0) return direction === "asc" ? cmp : -cmp;
1384
- }
1385
- return 0;
1386
- });
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
- }
1417
- function readField(record, field) {
1418
- if (record === null || record === void 0) return void 0;
1419
- if (!field.includes(".")) {
1420
- return record[field];
1421
- }
1422
- const segments = field.split(".");
1423
- let cursor = record;
1424
- for (const segment of segments) {
1425
- if (cursor === null || cursor === void 0) return void 0;
1426
- cursor = cursor[segment];
1427
- }
1428
- return cursor;
1429
- }
1430
- function compareValues(a, b) {
1431
- if (a === void 0 || a === null) return b === void 0 || b === null ? 0 : 1;
1432
- if (b === void 0 || b === null) return -1;
1433
- if (typeof a === "number" && typeof b === "number") return a - b;
1434
- if (typeof a === "string" && typeof b === "string") return a < b ? -1 : a > b ? 1 : 0;
1435
- if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();
1436
- return 0;
1437
- }
1438
- function serializePlan(plan) {
1439
- return {
1440
- clauses: plan.clauses.map(serializeClause),
1441
- orderBy: plan.orderBy,
1442
- limit: plan.limit,
1443
- offset: plan.offset,
1444
- joins: plan.joins
1445
- };
1446
- }
1447
- function serializeClause(clause) {
1448
- if (clause.type === "filter") {
1449
- return { type: "filter", fn: "[function]" };
1450
- }
1451
- if (clause.type === "wherePredicate") {
1452
- return {
1453
- type: "wherePredicate",
1454
- name: clause.name,
1455
- ctx: clause.ctx,
1456
- predicateHash: clause.predicateHash,
1457
- ctxHash: clause.ctxHash,
1458
- fn: "[function]"
1459
- };
1460
- }
1461
- if (clause.type === "group") {
1462
- return {
1463
- type: "group",
1464
- op: clause.op,
1465
- clauses: clause.clauses.map(serializeClause)
1466
- };
1467
- }
1468
- if (clause.type === "crossJoin") {
1469
- return {
1470
- type: "crossJoin",
1471
- target: clause.target,
1472
- as: clause.as,
1473
- on: clause.on ? "[function]" : void 0,
1474
- onPredicateName: clause.onPredicateName,
1475
- maxRows: clause.maxRows
1476
- };
1477
- }
1478
- return clause;
1479
- }
1480
- function canonicalCtxHash(ctx) {
1481
- if (ctx === void 0) return "";
1482
- const canonical = JSON.stringify(ctx, (_key, value) => {
1483
- if (value && typeof value === "object" && !Array.isArray(value)) {
1484
- const sorted = {};
1485
- for (const k of Object.keys(value).sort()) {
1486
- sorted[k] = value[k];
1487
- }
1488
- return sorted;
1489
- }
1490
- return value;
1491
- });
1492
- let h = 5381;
1493
- for (let i = 0; i < canonical.length; i++) {
1494
- h = (h << 5) + h ^ canonical.charCodeAt(i);
1495
- }
1496
- return (h >>> 0).toString(16).padStart(8, "0");
1497
- }
1498
- function buildDictLabelResolver(joinCtx, field) {
1499
- if (!joinCtx?.resolveDictSource) return void 0;
1500
- const dictSource = joinCtx.resolveDictSource(field);
1501
- if (!dictSource) return void 0;
1502
- const snapshot = dictSource.snapshot();
1503
- const displayLocale = dictSource.displayLocale;
1504
- const dictMap = /* @__PURE__ */ new Map();
1505
- for (const entry of snapshot) {
1506
- const k = entry["key"];
1507
- const labels = entry["labels"];
1508
- if (typeof k === "string" && labels && typeof labels === "object") {
1509
- dictMap.set(k, labels);
1510
- }
1511
- }
1512
- return async (key, locale, fallback) => {
1513
- const effLocale = locale || displayLocale;
1514
- if (!effLocale) return void 0;
1515
- const labels = dictMap.get(key);
1516
- if (!labels) return void 0;
1517
- if (labels[effLocale] !== void 0) return labels[effLocale];
1518
- const chain = Array.isArray(fallback) ? fallback : fallback ? [fallback] : [];
1519
- for (const fb of chain) {
1520
- if (fb === "any") {
1521
- const any = Object.values(labels)[0];
1522
- if (any !== void 0) return any;
1523
- } else if (labels[fb] !== void 0) {
1524
- return labels[fb];
1525
- }
1526
- }
1527
- return void 0;
1528
- };
1529
- }
1530
-
1531
- // src/kernel/query/scan-builder.ts
1532
- var DEFAULT_SCAN_PAGE_SIZE = 100;
1533
- var ScanBuilder = class _ScanBuilder {
1534
- pageProvider;
1535
- pageSize;
1536
- clauses;
1537
- /**
1538
- * Zero-or-more join legs to apply per record as the stream flows.
1539
- * Each leg attaches the resolved right-side record (or null) under
1540
- * its alias. — streaming joins.
1541
- *
1542
- * Joins are evaluated AFTER clauses, so a `where()` filtered-out
1543
- * record never triggers a right-side lookup. This is the same
1544
- * ordering as `Query.toArray()` (clauses first, joins after) and
1545
- * keeps the streaming path from doing wasted work.
1546
- */
1547
- joins;
1548
- /**
1549
- * Join resolution context. Required for `.join()` to translate a
1550
- * field name into a target collection + ref mode and to resolve
1551
- * the right-side `JoinableSource`. Optional because tests
1552
- * construct ScanBuilder directly with synthetic page providers
1553
- * that don't know about ref() — calling `.join()` without a
1554
- * context throws with an actionable error.
1555
- */
1556
- 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) {
1566
- this.pageProvider = pageProvider;
1567
- this.pageSize = pageSize;
1568
- this.clauses = clauses;
1569
- this.joins = joins;
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");
1580
- }
1581
- /**
1582
- * Add a field comparison. Runs per record as the scan stream
1583
- * flows through, so non-matching records are dropped before they
1584
- * reach `.aggregate()` or the iteration consumer. Multiple
1585
- * `.where()` calls are AND-combined — same semantics as
1586
- * `Query.where()`.
1587
- *
1588
- * Clauses cannot use the secondary-index fast path here because
1589
- * the scan sources records from the adapter's paginator, not from
1590
- * the in-memory cache where indexes live. Index-accelerated scans
1591
- * are a future optimization — the current implementation
1592
- * evaluates clauses per record in O(1) per clause.
1593
- */
1594
- where(field, op, value) {
1595
- const desc = this.moneyFields?.[field];
1596
- const clause = desc ? moneyFieldClause(field, op, value, desc) : { type: "field", field, op, value };
1597
- return new _ScanBuilder(
1598
- this.pageProvider,
1599
- this.pageSize,
1600
- [...this.clauses, clause],
1601
- this.joins,
1602
- this.joinContext,
1603
- this.moneyFields
1604
- );
1605
- }
1606
- /**
1607
- * Escape hatch: add an arbitrary predicate function. Same
1608
- * non-serializable caveat as `Query.filter()` — filter clauses
1609
- * don't round-trip through `toPlan()`. Prefer `.where()` when
1610
- * possible.
1611
- */
1612
- filter(fn) {
1613
- const clause = {
1614
- type: "filter",
1615
- fn
1616
- };
1617
- return new _ScanBuilder(
1618
- this.pageProvider,
1619
- this.pageSize,
1620
- [...this.clauses, clause],
1621
- this.joins,
1622
- this.joinContext,
1623
- this.moneyFields
1624
- );
1625
- }
1626
- /**
1627
- * Resolve a `ref()`-declared foreign key per record as the scan
1628
- * stream flows, attaching the right-side record (or null) under
1629
- * `opts.as`. — streaming joins over `scan()`.
1630
- *
1631
- * ```ts
1632
- * for await (const inv of invoices.scan().join('clientId', { as: 'client' })) {
1633
- * await processInvoice(inv) // inv.client is attached
1634
- * }
1635
- *
1636
- * // Or terminate with .aggregate() for streaming joined aggregation
1637
- * const { total } = await invoices.scan()
1638
- * .where('status', '==', 'open')
1639
- * .join('clientId', { as: 'client' })
1640
- * .aggregate({ total: sum('amount') })
1641
- * ```
1642
- *
1643
- * **The key difference from eager `.join()`:** the LEFT
1644
- * side streams page-by-page from the adapter and is never
1645
- * materialized. Memory ceiling on the left is O(pageSize), not
1646
- * O(rowCount). This is what makes streaming joins suitable for
1647
- * collections that exceed the eager join's 50_000-row ceiling.
1648
- *
1649
- * **Right-side strategy** is auto-selected per leg:
1650
- * - **Indexed** — right source exposes `lookupById`, so each
1651
- * left row costs O(1). This is the common path for
1652
- * Collection right sides, which back `lookupById` with a Map
1653
- * lookup over the in-memory cache. The right collection must
1654
- * be in eager mode (the same constraint as eager join's
1655
- * `querySourceForJoin` from ).
1656
- * - **Hash** — right source has only `snapshot()`. Build a
1657
- * `Map<id, record>` once at iteration start, probe per left
1658
- * row. Same correctness, same per-row cost as the indexed
1659
- * path; the difference is the upfront cost of materializing
1660
- * the right side once.
1661
- *
1662
- * Both strategies hold the right side in memory for the duration
1663
- * of the iteration. The "streaming" property applies to the LEFT
1664
- * side only — true left-and-right streaming joins (where neither
1665
- * side fits in memory) require a sort-merge join planner that's
1666
- * out of scope for.
1667
- *
1668
- * **Ref-mode semantics** match eager `.join()` exactly:
1669
- * - `strict` → throws `DanglingReferenceError` mid-stream
1670
- * when a left record points at a non-existent right id.
1671
- * The throw aborts the async iterator — consumers should
1672
- * wrap the `for await` in try/catch if they want to recover.
1673
- * - `warn` → attaches `null` and emits a one-shot warning
1674
- * per unique dangling pair (deduped via the same warn
1675
- * channel as eager join).
1676
- * - `cascade` → attaches `null` silently. A delete-time mode;
1677
- * dangling refs at read time are mid-flight or pre-existing
1678
- * orphans, not a DSL error.
1679
- *
1680
- * Left records with null/undefined FK values attach `null`
1681
- * regardless of mode — same "no reference at all" policy as
1682
- * eager join and write-time `enforceRefsOnPut`.
1683
- *
1684
- * **Multi-FK chaining** is supported via repeated `.join()`
1685
- * calls: each leg resolves an independent ref. Each leg
1686
- * independently picks its right-side strategy and applies its
1687
- * own ref mode.
1688
- *
1689
- * **Joins are NOT applied** to a `.aggregate()` terminal that
1690
- * doesn't reference joined fields — wait, that's not quite
1691
- * right. The streaming path actually DOES apply joins before
1692
- * `.aggregate()` because the join attaches a field that the
1693
- * spec might reference. Unlike `Query.aggregate()` (which skips
1694
- * joins entirely as a projection-only short-circuit), the
1695
- * streaming aggregation can't know whether the spec touches a
1696
- * joined field, so it always applies joins. Consumers who want
1697
- * unjoined streaming aggregation should leave `.join()` off the
1698
- * chain — the chain is composable for a reason.
1699
- *
1700
- * constraint #1 — every JoinLeg carries `partitionScope:
1701
- * 'all'` plumbed through but never read by. Same seam as
1702
- * eager join.
1703
- */
1704
- join(field, opts) {
1705
- if (!this.joinContext) {
1706
- throw new Error(
1707
- `ScanBuilder.join() requires a join context. Use collection.scan() to construct a join-capable scan instead of the ScanBuilder constructor directly (the direct constructor is only used for tests with synthetic page providers).`
1708
- );
1709
- }
1710
- const descriptor = this.joinContext.resolveRef(field);
1711
- if (!descriptor) {
1712
- throw new Error(
1713
- `ScanBuilder.join(): no ref() declared for field "${field}" on collection "${this.joinContext.leftCollection}". Add refs: { ${field}: ref('<target-collection>') } to the collection options, then retry.`
1714
- );
1715
- }
1716
- const leg = {
1717
- field,
1718
- as: opts.as,
1719
- target: descriptor.target,
1720
- mode: descriptor.mode,
1721
- strategy: void 0,
1722
- maxRows: void 0,
1723
- // constraint #1 — always 'all' in, never read by
1724
- // the streaming executor. partition-aware scan joins
1725
- // will populate this from where() predicates without
1726
- // changing the planner shape.
1727
- partitionScope: "all"
1728
- };
1729
- return new _ScanBuilder(
1730
- this.pageProvider,
1731
- this.pageSize,
1732
- this.clauses,
1733
- [...this.joins, leg],
1734
- this.joinContext,
1735
- this.moneyFields
1736
- );
1737
- }
1738
- /**
1739
- * Iterate the scan as an async iterable. Walks the page
1740
- * provider's cursors forward until exhaustion, applying every
1741
- * clause per record — only matching records are yielded.
1742
- *
1743
- * Backward-compatible with the previous async-generator `scan()`
1744
- * return type for `for await … of` consumers.
1745
- */
1746
- async *[Symbol.asyncIterator]() {
1747
- const joinResolvers = this.joins.length === 0 ? null : this.buildJoinResolvers();
1748
- let page = await this.pageProvider.listPage({ limit: this.pageSize });
1749
- while (true) {
1750
- for (const record of page.items) {
1751
- if (!this.recordMatches(record)) continue;
1752
- const decoded = this.decodeMoney(record);
1753
- if (joinResolvers === null) {
1754
- yield decoded;
1755
- } else {
1756
- let attached = decoded;
1757
- for (const resolver of joinResolvers) {
1758
- attached = this.applyOneJoinStreaming(attached, resolver);
1759
- }
1760
- yield attached;
1761
- }
1762
- }
1763
- if (page.nextCursor === null) return;
1764
- page = await this.pageProvider.listPage({
1765
- cursor: page.nextCursor,
1766
- limit: this.pageSize
1767
- });
1768
- }
1769
- }
1770
- /**
1771
- * Per-leg right-side resolution state. Built once at iteration
1772
- * start and reused for every left record. Two strategies:
1773
- *
1774
- * - `lookupById`: present when the right source exposes the
1775
- * hook directly (typical Collection right side). Per-row
1776
- * cost is O(1).
1777
- * - `hashByPrimaryKey`: built from `snapshot()` when no
1778
- * lookupById. Per-row cost is O(1) after the upfront O(N)
1779
- * materialization. Same as eager join's hash strategy.
1780
- *
1781
- * `warnedKeys` is the per-leg dedup set for ref-mode 'warn'. We
1782
- * key on `field→target:refId` so the same dangling pair only
1783
- * warns once per iteration. The dedup is per-iteration, not
1784
- * per-process — a long-running scan that re-iterates would warn
1785
- * again, which is the desired behavior (the data may have
1786
- * changed between iterations).
1787
- */
1788
- buildJoinResolvers() {
1789
- if (!this.joinContext) {
1790
- throw new Error(
1791
- `ScanBuilder iterator: ${this.joins.length} join leg(s) present but no JoinContext attached. Use collection.scan() to construct a join-capable scan.`
1792
- );
1793
- }
1794
- const resolvers = [];
1795
- for (const leg of this.joins) {
1796
- const source = this.joinContext.resolveSource(leg.target);
1797
- if (!source) {
1798
- throw new Error(
1799
- `ScanBuilder.join() cannot resolve target collection "${leg.target}" (referenced from field "${leg.field}" on "${this.joinContext.leftCollection}"). Make sure the target collection has been opened via vault.collection() at least once before iterating the scan.`
1800
- );
1801
- }
1802
- let lookupById = null;
1803
- let hashByPrimaryKey = null;
1804
- if (source.lookupById) {
1805
- const fn = source.lookupById.bind(source);
1806
- lookupById = (id) => fn(id);
1807
- } else {
1808
- const map = /* @__PURE__ */ new Map();
1809
- for (const record of source.snapshot()) {
1810
- const rawId = readPath(record, "id");
1811
- const key = coerceRefKey2(rawId);
1812
- if (key !== null) map.set(key, record);
1813
- }
1814
- hashByPrimaryKey = map;
1815
- }
1816
- resolvers.push({
1817
- leg,
1818
- source,
1819
- lookupById,
1820
- hashByPrimaryKey,
1821
- warnedKeys: /* @__PURE__ */ new Set()
1822
- });
1823
- }
1824
- return resolvers;
1825
- }
1826
- /**
1827
- * Resolve a single join leg for one left record and return the
1828
- * left record with the joined field attached under
1829
- * `leg.as`. Pure function over `(left, resolver)`; never
1830
- * mutates the input.
1831
- *
1832
- * Ref-mode dispatch matches eager `applyJoins` from :
1833
- * - null/undefined FK → attach null silently (always allowed)
1834
- * - dangling FK + strict → throw `DanglingReferenceError`
1835
- * - dangling FK + warn → attach null, warn-once per pair
1836
- * - dangling FK + cascade → attach null silently
1837
- */
1838
- applyOneJoinStreaming(left, resolver) {
1839
- if (left === null || typeof left !== "object") {
1840
- return left;
1841
- }
1842
- const { leg } = resolver;
1843
- const rawId = readPath(left, leg.field);
1844
- const refKey = coerceRefKey2(rawId);
1845
- let right = void 0;
1846
- if (refKey !== null) {
1847
- if (resolver.lookupById !== null) {
1848
- right = resolver.lookupById(refKey);
1849
- } else if (resolver.hashByPrimaryKey !== null) {
1850
- right = resolver.hashByPrimaryKey.get(refKey);
1851
- }
1852
- }
1853
- const merged = {
1854
- ...left
1855
- };
1856
- if (right === void 0) {
1857
- if (refKey !== null && leg.mode === "strict") {
1858
- throw new DanglingReferenceError({
1859
- field: leg.field,
1860
- target: leg.target,
1861
- refId: refKey,
1862
- message: `ScanBuilder.join() strict dangling: record references "${leg.target}:${refKey}" via field "${leg.field}", but no such record exists. Use ref() mode 'warn' or 'cascade' if dangling refs are acceptable, or run vault.checkIntegrity() to find and fix the orphans.`
1863
- });
1864
- }
1865
- if (refKey !== null && leg.mode === "warn") {
1866
- const dedupKey = `${leg.field}\u2192${leg.target}:${refKey}`;
1867
- if (!resolver.warnedKeys.has(dedupKey)) {
1868
- resolver.warnedKeys.add(dedupKey);
1869
- console.warn(
1870
- `[noy-db] ScanBuilder.join() encountered dangling ref in 'warn' mode: field "${leg.field}" \u2192 "${leg.target}:${refKey}" not found. Attaching null.`
1871
- );
1872
- }
1873
- }
1874
- merged[leg.as] = null;
1875
- } else {
1876
- merged[leg.as] = right;
1877
- }
1878
- return merged;
1879
- }
1880
- async aggregate(specOrBuild) {
1881
- const spec = typeof specOrBuild === "function" ? specOrBuild(reducerBuilder) : specOrBuild;
1882
- const keys = Object.keys(spec);
1883
- const state = {};
1884
- for (const key of keys) {
1885
- state[key] = spec[key].init();
1886
- }
1887
- for await (const record of this) {
1888
- for (const key of keys) {
1889
- state[key] = spec[key].step(state[key], record);
1890
- }
1891
- }
1892
- const result = {};
1893
- for (const key of keys) {
1894
- result[key] = spec[key].finalize(state[key]);
1895
- }
1896
- return result;
1897
- }
1898
- /**
1899
- * Evaluate the clause list against a single record. Linear in
1900
- * the clause count; short-circuits on first false. Clauses on a
1901
- * scan are always re-evaluated per record — no index-accelerated
1902
- * path, because the stream sources records from the adapter
1903
- * paginator, not from the in-memory cache where indexes live.
1904
- */
1905
- recordMatches(record) {
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;
1908
- for (const clause of this.clauses) {
1909
- if (!evaluateClause(record, clause, fnView)) return false;
1910
- }
1911
- return true;
1912
- }
1913
- };
1914
- function coerceRefKey2(value) {
1915
- if (value === null || value === void 0) return null;
1916
- if (typeof value === "string") return value;
1917
- if (typeof value === "number" || typeof value === "bigint") return String(value);
1918
- return null;
1919
- }
1920
-
1921
- export {
1922
- validateMoneyFieldPaths,
1923
- canonicalizeStoredMoney,
1924
- canonicalizeIncomingMoney,
1925
- quantizeMoneyFields,
1926
- decodeMoneyFields,
1927
- DEFAULT_JOIN_MAX_ROWS,
1928
- applyJoins,
1929
- resetJoinWarnings,
1930
- buildLiveQuery,
1931
- NO_AGGREGATE,
1932
- DEFAULT_CROSS_JOIN_MAX_ROWS,
1933
- Query,
1934
- executePlan,
1935
- ScanBuilder
1936
- };
1937
- //# sourceMappingURL=chunk-UIU2THRG.js.map