@noy-db/hub 0.3.0-pre.1 → 0.3.0-pre.10
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.
- package/dist/aggregate/index.d.ts +3 -4
- package/dist/aggregate/index.js +9 -8
- package/dist/aggregate/index.js.map +1 -1
- package/dist/api-TX2EX2FX.js +20 -0
- package/dist/as/index.d.ts +4 -5
- package/dist/as/index.js +12 -6
- package/dist/at/index.d.ts +2 -3
- package/dist/attestation/index.d.ts +3 -4
- package/dist/attestation/index.js +19 -13
- package/dist/attestation/index.js.map +1 -1
- package/dist/{backup-XV3IOEGB.js → backup-R7NTDFKY.js} +14 -6
- package/dist/backup-R7NTDFKY.js.map +1 -0
- package/dist/blobs/index.d.ts +4 -5
- package/dist/blobs/index.js +12 -6
- package/dist/blobs/index.js.map +1 -1
- package/dist/bundle/index.d.ts +5 -6
- package/dist/bundle/index.js +21 -15
- package/dist/bundle/index.js.map +1 -1
- package/dist/{bundle-CH-H06dp.d.ts → bundle-D6GxiUfq.d.ts} +1 -1
- package/dist/by/index.js +2 -2
- package/dist/cargo/index.d.ts +4 -6
- package/dist/cargo/index.js +27 -21
- package/dist/chunk-2OV5NVE7.js +95 -0
- package/dist/chunk-2OV5NVE7.js.map +1 -0
- package/dist/{chunk-5N6CZTCY.js → chunk-2OZXVKVP.js} +3 -3
- package/dist/{chunk-BG3SPSR4.js → chunk-2REPHKET.js} +5 -4
- package/dist/chunk-2REPHKET.js.map +1 -0
- package/dist/{chunk-LXQT4WMP.js → chunk-3JXPAHOZ.js} +8 -6
- package/dist/{chunk-LXQT4WMP.js.map → chunk-3JXPAHOZ.js.map} +1 -1
- package/dist/{chunk-UAG5KWVA.js → chunk-3MATJ6O4.js} +3 -3
- package/dist/chunk-3OPY6MK2.js +404 -0
- package/dist/chunk-3OPY6MK2.js.map +1 -0
- package/dist/{chunk-62QYRORB.js → chunk-3QSIU3UT.js} +34 -63
- package/dist/chunk-3QSIU3UT.js.map +1 -0
- package/dist/{chunk-DGDI2D4M.js → chunk-4OMCIY6F.js} +29 -9
- package/dist/chunk-4OMCIY6F.js.map +1 -0
- package/dist/chunk-5I35DOHK.js +94 -0
- package/dist/chunk-5I35DOHK.js.map +1 -0
- package/dist/{chunk-2P2HZEXU.js → chunk-5VG4IJR7.js} +11 -9
- package/dist/{chunk-2P2HZEXU.js.map → chunk-5VG4IJR7.js.map} +1 -1
- package/dist/{chunk-AZAOEIKW.js → chunk-5YESYH2C.js} +2 -2
- package/dist/{chunk-GYGWYIOZ.js → chunk-6G5ORS5D.js} +7 -5
- package/dist/{chunk-GYGWYIOZ.js.map → chunk-6G5ORS5D.js.map} +1 -1
- package/dist/{chunk-VCTFO5CO.js → chunk-6P5XCKSD.js} +2 -2
- package/dist/{chunk-IO6GRPT6.js → chunk-7BWJHO2A.js} +2 -2
- package/dist/{chunk-IPB7FTQX.js → chunk-7P2SDJG3.js} +15 -9
- package/dist/chunk-7P2SDJG3.js.map +1 -0
- package/dist/{chunk-SRB2XEWB.js → chunk-ANB77BVV.js} +6 -4
- package/dist/chunk-ANB77BVV.js.map +1 -0
- package/dist/{chunk-UDRIWL7A.js → chunk-BKARNZJN.js} +3 -3
- package/dist/{chunk-Y22T3KQE.js → chunk-BQISD5ZV.js} +3 -3
- package/dist/chunk-BQISD5ZV.js.map +1 -0
- package/dist/{chunk-UIU2THRG.js → chunk-BUAQ7YI3.js} +138 -378
- package/dist/chunk-BUAQ7YI3.js.map +1 -0
- package/dist/{chunk-V7RWQRG7.js → chunk-CB7CWSKW.js} +3 -3
- package/dist/{chunk-LV7M27WM.js → chunk-DFVUTGT2.js} +14 -201
- package/dist/chunk-DFVUTGT2.js.map +1 -0
- package/dist/{chunk-CWPPNPOH.js → chunk-DJ7KIPLV.js} +2 -2
- package/dist/{chunk-5R5JW2JT.js → chunk-DSKDQP3G.js} +3480 -1916
- package/dist/chunk-DSKDQP3G.js.map +1 -0
- package/dist/{chunk-VFQGRQIH.js → chunk-DV4HUP5G.js} +7 -5
- package/dist/{chunk-VFQGRQIH.js.map → chunk-DV4HUP5G.js.map} +1 -1
- package/dist/{chunk-5LUY7UTV.js → chunk-EOXAAJTY.js} +289 -48
- package/dist/chunk-EOXAAJTY.js.map +1 -0
- package/dist/chunk-ET67AY6B.js +74 -0
- package/dist/chunk-ET67AY6B.js.map +1 -0
- package/dist/{chunk-TA66UMI4.js → chunk-F4CEK5YM.js} +2 -2
- package/dist/chunk-FORYWFN6.js +130 -0
- package/dist/chunk-FORYWFN6.js.map +1 -0
- package/dist/{chunk-IELYAOGG.js → chunk-FRP6D2DM.js} +19 -6
- package/dist/chunk-FRP6D2DM.js.map +1 -0
- package/dist/chunk-FUOE7UUV.js +341 -0
- package/dist/chunk-FUOE7UUV.js.map +1 -0
- package/dist/{chunk-SM3AVUHC.js → chunk-G4JYND6L.js} +2 -2
- package/dist/{chunk-AXRXJTE2.js → chunk-G6XV4H65.js} +5 -5
- package/dist/{chunk-I2NOIW44.js → chunk-GNMXXTMN.js} +8 -6
- package/dist/{chunk-I2NOIW44.js.map → chunk-GNMXXTMN.js.map} +1 -1
- package/dist/chunk-GYGLAVCX.js +19 -0
- package/dist/chunk-GYGLAVCX.js.map +1 -0
- package/dist/{chunk-UV5MFVO3.js → chunk-HPWKV3YB.js} +2 -2
- package/dist/chunk-HY3AUMFI.js +41 -0
- package/dist/chunk-HY3AUMFI.js.map +1 -0
- package/dist/chunk-HYR4WZZ3.js +69 -0
- package/dist/chunk-HYR4WZZ3.js.map +1 -0
- package/dist/{chunk-SKF73JOP.js → chunk-ICXIFFYZ.js} +3 -3
- package/dist/chunk-IGJCYUT5.js +99 -0
- package/dist/chunk-IGJCYUT5.js.map +1 -0
- package/dist/{chunk-MD3Y6J3L.js → chunk-IVLTXX4W.js} +7 -5
- package/dist/{chunk-MD3Y6J3L.js.map → chunk-IVLTXX4W.js.map} +1 -1
- package/dist/{chunk-WWGT2MDV.js → chunk-J4LPNIGK.js} +26 -11
- package/dist/chunk-J4LPNIGK.js.map +1 -0
- package/dist/chunk-JJZ2LW6T.js +36 -0
- package/dist/chunk-JJZ2LW6T.js.map +1 -0
- package/dist/{chunk-RUIMKQTA.js → chunk-JK733I5V.js} +1 -1
- package/dist/chunk-JK733I5V.js.map +1 -0
- package/dist/{chunk-UPJNJGGA.js → chunk-KJ2BCBTL.js} +25 -8
- package/dist/chunk-KJ2BCBTL.js.map +1 -0
- package/dist/{chunk-LMTH2RM6.js → chunk-KNZB6JMR.js} +2 -2
- package/dist/{chunk-I3TIKTJO.js → chunk-KPZS5QAQ.js} +29 -10
- package/dist/chunk-KPZS5QAQ.js.map +1 -0
- package/dist/{chunk-PKHL44ER.js → chunk-LEJIKBBB.js} +2 -2
- package/dist/{chunk-AQTBSL7R.js → chunk-LL2NIVUR.js} +14 -7
- package/dist/chunk-LL2NIVUR.js.map +1 -0
- package/dist/chunk-LP7BEXCT.js +32 -0
- package/dist/chunk-LP7BEXCT.js.map +1 -0
- package/dist/{chunk-5O3AOPDT.js → chunk-MCHVVJIA.js} +443 -467
- package/dist/chunk-MCHVVJIA.js.map +1 -0
- package/dist/chunk-NO272T7Q.js +194 -0
- package/dist/chunk-NO272T7Q.js.map +1 -0
- package/dist/{chunk-LFLXAY2W.js → chunk-NUEQU36L.js} +71 -93
- package/dist/chunk-NUEQU36L.js.map +1 -0
- package/dist/chunk-O45M6LDB.js +38 -0
- package/dist/chunk-O45M6LDB.js.map +1 -0
- package/dist/{chunk-PSMV73A5.js → chunk-OBKWYKYC.js} +5 -5
- package/dist/{chunk-CMGR4ZEW.js → chunk-OHHKHSJP.js} +2 -2
- package/dist/{chunk-HCIPRAGS.js → chunk-OT76OZL6.js} +2 -2
- package/dist/{chunk-ITNUCOXM.js → chunk-OVYRLHPE.js} +7 -5
- package/dist/{chunk-ITNUCOXM.js.map → chunk-OVYRLHPE.js.map} +1 -1
- package/dist/{chunk-SMXWYP24.js → chunk-OXCSVM3B.js} +3 -3
- package/dist/{chunk-IGUYVGGI.js → chunk-P33LUIML.js} +3 -3
- package/dist/{chunk-JNUWZ6D3.js → chunk-PLS64NCS.js} +7 -5
- package/dist/{chunk-JNUWZ6D3.js.map → chunk-PLS64NCS.js.map} +1 -1
- package/dist/{chunk-EIZUR2XW.js → chunk-PS2NEWEX.js} +2 -2
- package/dist/chunk-QA2KUPCP.js +45 -0
- package/dist/chunk-QA2KUPCP.js.map +1 -0
- package/dist/{chunk-WYSO2NIH.js → chunk-QOC3VYL2.js} +2 -2
- package/dist/{chunk-FISN7WE4.js → chunk-QSFOZUYL.js} +30 -5
- package/dist/{chunk-FISN7WE4.js.map → chunk-QSFOZUYL.js.map} +1 -1
- package/dist/{chunk-KVOXU4T5.js → chunk-RHK32N73.js} +2 -2
- package/dist/{chunk-3YFXJ3ZP.js → chunk-RW3Y22MW.js} +2 -2
- package/dist/{chunk-ZYUC53LT.js → chunk-S7VFUQM2.js} +117 -3
- package/dist/chunk-S7VFUQM2.js.map +1 -0
- package/dist/chunk-T7WSLRAU.js +49 -0
- package/dist/chunk-T7WSLRAU.js.map +1 -0
- package/dist/{chunk-IUEN57TV.js → chunk-TAKWLZZX.js} +280 -58
- package/dist/chunk-TAKWLZZX.js.map +1 -0
- package/dist/chunk-THNJ3IKU.js +17 -0
- package/dist/chunk-THNJ3IKU.js.map +1 -0
- package/dist/{chunk-MTMJVJ5W.js → chunk-TMBXVJKT.js} +5 -3
- package/dist/chunk-TMBXVJKT.js.map +1 -0
- package/dist/{chunk-QHJW5EXU.js → chunk-TWKKOM55.js} +2 -2
- package/dist/{chunk-M6OST55S.js → chunk-U3WZCU7E.js} +2 -2
- package/dist/{chunk-AIWULCUO.js → chunk-UF362QVH.js} +5 -3
- package/dist/{chunk-AIWULCUO.js.map → chunk-UF362QVH.js.map} +1 -1
- package/dist/{chunk-KXGNJJXB.js → chunk-UN4FVIBH.js} +7 -7
- package/dist/chunk-VEAVKDDB.js +29 -0
- package/dist/chunk-VEAVKDDB.js.map +1 -0
- package/dist/chunk-VEPTFUJY.js +29 -0
- package/dist/chunk-VEPTFUJY.js.map +1 -0
- package/dist/{chunk-TEILUWOI.js → chunk-VJV7GKQK.js} +10 -12
- package/dist/chunk-VJV7GKQK.js.map +1 -0
- package/dist/chunk-VQRAIPYF.js +50 -0
- package/dist/chunk-VQRAIPYF.js.map +1 -0
- package/dist/{chunk-NF5JWERG.js → chunk-VRIYFLBA.js} +2 -2
- package/dist/chunk-VWM3DAVB.js +265 -0
- package/dist/chunk-VWM3DAVB.js.map +1 -0
- package/dist/{chunk-RUEKROOS.js → chunk-VWRRVE6D.js} +2 -2
- package/dist/chunk-VYYM3MEN.js +98 -0
- package/dist/chunk-VYYM3MEN.js.map +1 -0
- package/dist/chunk-WBJIQSLL.js +167 -0
- package/dist/chunk-WBJIQSLL.js.map +1 -0
- package/dist/{chunk-XXYIOFUB.js → chunk-WIGQB62E.js} +5 -5
- package/dist/chunk-WZSCE6RM.js +466 -0
- package/dist/chunk-WZSCE6RM.js.map +1 -0
- package/dist/{chunk-5R3ERCDH.js → chunk-XGDAPN6M.js} +25 -9
- package/dist/{chunk-5R3ERCDH.js.map → chunk-XGDAPN6M.js.map} +1 -1
- package/dist/{chunk-DFEMTNPJ.js → chunk-XH7XP3OL.js} +8 -6
- package/dist/{chunk-DFEMTNPJ.js.map → chunk-XH7XP3OL.js.map} +1 -1
- package/dist/{chunk-IAGBDSCS.js → chunk-XREOISSI.js} +2 -2
- package/dist/chunk-XUBPSPKD.js +164 -0
- package/dist/chunk-XUBPSPKD.js.map +1 -0
- package/dist/chunk-Y3A5CB5G.js +247 -0
- package/dist/chunk-Y3A5CB5G.js.map +1 -0
- package/dist/{chunk-ZCGAHGUS.js → chunk-YCXCR7VG.js} +2 -2
- package/dist/{chunk-76722EBH.js → chunk-YMVQD5Q5.js} +11 -9
- package/dist/{chunk-76722EBH.js.map → chunk-YMVQD5Q5.js.map} +1 -1
- package/dist/{chunk-5TDJ56JE.js → chunk-YN5IAHN6.js} +1 -1
- package/dist/chunk-YN5IAHN6.js.map +1 -0
- package/dist/{chunk-TJYQIGAP.js → chunk-ZYJ55N7N.js} +9 -5
- package/dist/chunk-ZYJ55N7N.js.map +1 -0
- package/dist/classified/index.d.ts +16 -0
- package/dist/classified/index.js +40 -0
- package/dist/classified-marker-H6YSHYNK.js +24 -0
- package/dist/classified-marker-H6YSHYNK.js.map +1 -0
- package/dist/collection-facade-LVD22JLM.js +39 -0
- package/dist/computed-EXDMQODG.js +11 -0
- package/dist/consent/index.d.ts +3 -4
- package/dist/consent/index.js +10 -4
- package/dist/consent/index.js.map +1 -1
- package/dist/crdt/index.d.ts +3 -4
- package/dist/dead-filter-HQIE2YG7.js +28 -0
- package/dist/dead-filter-HQIE2YG7.js.map +1 -0
- package/dist/delegation-BJP73GAP.js +25 -0
- package/dist/derivations/index.d.ts +4 -5
- package/dist/derivations/index.js +13 -6
- package/dist/derive-BME7HDWO.js +21 -0
- package/dist/{dev-unlock-C9Ro3v_O.d.ts → dev-unlock-Bmm2pgJ0.d.ts} +1 -1
- package/dist/{enclave-UL5LW66V.js → enclave-NHORSWSF.js} +55 -18
- package/dist/executor-FE6X4LFX.js +9 -0
- package/dist/executor-KSHKRJXP.js +25 -0
- package/dist/executor-ZHTJJICG.js +9 -0
- package/dist/export-accessible-DACHM5VT.js +23 -0
- package/dist/extract-partition-RNENZZ4T.js +36 -0
- package/dist/{fanout-sidecar-GF3DJ6KR.js → fanout-sidecar-OFWN3NM7.js} +17 -14
- package/dist/fanout-sidecar-OFWN3NM7.js.map +1 -0
- package/dist/fence-watcher-DHQ775JB.js +69 -0
- package/dist/fence-watcher-DHQ775JB.js.map +1 -0
- package/dist/find-BNGBJNKP.js +11 -0
- package/dist/forget/index.d.ts +2 -2
- package/dist/forget/index.js +10 -4
- package/dist/forget/index.js.map +1 -1
- package/dist/guards/index.d.ts +4 -5
- package/dist/guards/index.js +4 -4
- package/dist/{hash-Cp5uwiox.d.ts → hash-DAJjMsCE.d.ts} +7 -2
- package/dist/history/index.d.ts +4 -5
- package/dist/history/index.js +12 -6
- package/dist/history/index.js.map +1 -1
- package/dist/i18n/index.d.ts +24 -5
- package/dist/i18n/index.js +50 -31
- package/dist/i18n/index.js.map +1 -1
- package/dist/in/index.d.ts +2 -3
- package/dist/{index-BzUo1B6n.d.ts → index-DjWbxsjb.d.ts} +8596 -5747
- package/dist/{index-BF9_96A5.d.ts → index-qwuNvO2B.d.ts} +26 -5
- package/dist/index.d.ts +116 -24
- package/dist/index.js +1479 -139
- package/dist/index.js.map +1 -1
- package/dist/indexing/index.d.ts +3 -4
- package/dist/indexing/index.js +4 -4
- package/dist/issue-NDI4CVZU.js +19 -0
- package/dist/json-schema-I22JCYCG.js +44 -0
- package/dist/json-schema-I22JCYCG.js.map +1 -0
- package/dist/lazy/index.d.ts +20 -0
- package/dist/lazy/index.js +12 -0
- package/dist/{ledger-RYI35CDS.js → ledger-6NDS2EO4.js} +12 -6
- package/dist/liberate-HN3RIGIP.js +24 -0
- package/dist/link-set-SJB2MVJV.js +31 -0
- package/dist/materialized-views/index.d.ts +22 -6
- package/dist/materialized-views/index.js +20 -10
- package/dist/{mime-magic-CGhw37_E.d.ts → mime-magic-bBj5OgUC.d.ts} +1 -1
- package/dist/noydb-BWF6EPIR.js +66 -0
- package/dist/on/index.d.ts +2 -3
- package/dist/on/index.js +10 -4
- package/dist/overlay-views/index.d.ts +4 -5
- package/dist/overlay-views/index.js +4 -4
- package/dist/periods/index.d.ts +3 -4
- package/dist/periods/index.js +21 -7
- package/dist/pod/index.d.ts +3 -4
- package/dist/pod/index.js +12 -6
- package/dist/{policy-IXK4FVXP.js → policy-WGNAG5H6.js} +5 -5
- package/dist/portability/index.d.ts +3 -4
- package/dist/portability/index.js +8 -8
- package/dist/post-register-CWKBQRC7.js +55 -0
- package/dist/post-register-CWKBQRC7.js.map +1 -0
- package/dist/{public-envelope-JHDQCPSX.js → public-envelope-EJLVIFX7.js} +4 -4
- package/dist/query/index.d.ts +2 -3
- package/dist/query/index.js +9 -6
- package/dist/{read-only-facade-5ADRJVTM.js → read-only-facade-CHCKSEPD.js} +2 -2
- package/dist/register-SBIX7TVV.js +23 -0
- package/dist/registry-3EQG6OOE.js +18 -0
- package/dist/registry-CA327ACV.js +9 -0
- package/dist/registry-E7OXOTSV.js +19 -0
- package/dist/request-withdrawal-KAH2AAXC.js +31 -0
- package/dist/reveal-R3JLHMUF.js +38 -0
- package/dist/reveal-R3JLHMUF.js.map +1 -0
- package/dist/revoke-IXLOJ3IH.js +24 -0
- package/dist/satellites/index.d.ts +4 -0
- package/dist/satellites/index.js +8 -0
- package/dist/sealed-record/index.d.ts +3 -4
- package/dist/sealed-record/index.js +13 -7
- package/dist/sealed-record/index.js.map +1 -1
- package/dist/session/index.d.ts +4 -5
- package/dist/session/index.js +10 -4
- package/dist/session/index.js.map +1 -1
- package/dist/shadow/index.d.ts +3 -4
- package/dist/shadow/index.js +2 -2
- package/dist/signer-Y46N2GJ3.js +25 -0
- package/dist/signer-Y46N2GJ3.js.map +1 -0
- package/dist/snapshots/index.d.ts +3 -4
- package/dist/snapshots/index.js +11 -5
- package/dist/snapshots/index.js.map +1 -1
- package/dist/{stale-3JWHNDIY.js → stale-Z7IW6RIL.js} +2 -2
- package/dist/stale-Z7IW6RIL.js.map +1 -0
- package/dist/storage-ADNP2UWI.js +23 -0
- package/dist/storage-ADNP2UWI.js.map +1 -0
- package/dist/{store-coordination-provider-3I7XWZZK.js → store-coordination-provider-DTDMI6VL.js} +3 -3
- package/dist/{subject-index-O75wKshW.d.ts → subject-index-CyOgGMJL.d.ts} +18 -0
- package/dist/sync/index.d.ts +2 -3
- package/dist/sync/index.js +10 -4
- package/dist/sync/index.js.map +1 -1
- package/dist/team/index.d.ts +45 -7
- package/dist/team/index.js +25 -12
- package/dist/tiers/index.d.ts +2 -3
- package/dist/tiers/index.js +11 -5
- package/dist/to/index.d.ts +2 -3
- package/dist/to/index.js +1 -2
- package/dist/{transition-guard-C7ol6oPw.d.ts → transition-guard-DI-krBsZ.d.ts} +1 -1
- package/dist/tx/index.d.ts +3 -4
- package/dist/tx/index.js +3 -3
- package/dist/ui/index.d.ts +4 -1
- package/dist/util/index.js +1 -1
- package/dist/validators-BUcli5Nh.d.ts +101 -0
- package/dist/{vault-diff-B5fYNBL7.d.ts → vault-diff-Z2DUayMe.d.ts} +1 -1
- package/dist/verify-JPF2YR5E.js +139 -0
- package/dist/verify-JPF2YR5E.js.map +1 -0
- package/dist/walk-XYA2O3LW.js +241 -0
- package/dist/walk-XYA2O3LW.js.map +1 -0
- package/dist/with/index.d.ts +3 -4
- package/dist/with/index.js +12 -6
- package/dist/{with-materialized-view-6p0Fk8bL.d.ts → with-materialized-view-BUmzlXue.d.ts} +1 -1
- package/dist/{with-overlayed-view-BJ6mXGMd.d.ts → with-overlayed-view-m4FaXXTO.d.ts} +1 -1
- package/dist/{with-rollup-BvQo3ROo.d.ts → with-rollup-DEKGI9vb.d.ts} +1 -1
- package/dist/withdraw-accessible-WLV4MTEN.js +28 -0
- package/dist/withdraw-accessible-WLV4MTEN.js.map +1 -0
- package/package.json +16 -16
- package/dist/adapter/index.d.ts +0 -5
- package/dist/adapter/index.js +0 -15
- package/dist/api-RW3KP7WU.js +0 -14
- package/dist/backup-XV3IOEGB.js.map +0 -1
- package/dist/chunk-26LGBE4T.js +0 -42
- package/dist/chunk-26LGBE4T.js.map +0 -1
- package/dist/chunk-5LUY7UTV.js.map +0 -1
- package/dist/chunk-5O3AOPDT.js.map +0 -1
- package/dist/chunk-5R5JW2JT.js.map +0 -1
- package/dist/chunk-5TDJ56JE.js.map +0 -1
- package/dist/chunk-62QYRORB.js.map +0 -1
- package/dist/chunk-AQTBSL7R.js.map +0 -1
- package/dist/chunk-BG3SPSR4.js.map +0 -1
- package/dist/chunk-BGIZAFY7.js +0 -1
- package/dist/chunk-DGDI2D4M.js.map +0 -1
- package/dist/chunk-I3TIKTJO.js.map +0 -1
- package/dist/chunk-IELYAOGG.js.map +0 -1
- package/dist/chunk-IPB7FTQX.js.map +0 -1
- package/dist/chunk-IUEN57TV.js.map +0 -1
- package/dist/chunk-K2WCO3NX.js +0 -1
- package/dist/chunk-LFLXAY2W.js.map +0 -1
- package/dist/chunk-LV7M27WM.js.map +0 -1
- package/dist/chunk-M2YKN37S.js +0 -524
- package/dist/chunk-M2YKN37S.js.map +0 -1
- package/dist/chunk-MTMJVJ5W.js.map +0 -1
- package/dist/chunk-Q7SS3IME.js +0 -120
- package/dist/chunk-Q7SS3IME.js.map +0 -1
- package/dist/chunk-RUIMKQTA.js.map +0 -1
- package/dist/chunk-SRB2XEWB.js.map +0 -1
- package/dist/chunk-TEILUWOI.js.map +0 -1
- package/dist/chunk-TJYQIGAP.js.map +0 -1
- package/dist/chunk-UIU2THRG.js.map +0 -1
- package/dist/chunk-UPJNJGGA.js.map +0 -1
- package/dist/chunk-WWGT2MDV.js.map +0 -1
- package/dist/chunk-Y22T3KQE.js.map +0 -1
- package/dist/chunk-ZYUC53LT.js.map +0 -1
- package/dist/collection-facade-GQAOGJP2.js +0 -33
- package/dist/delegation-UL5HKLER.js +0 -19
- package/dist/describe/index.d.ts +0 -1
- package/dist/describe/index.js +0 -1
- package/dist/describe-aBkJR2sd.d.ts +0 -131
- package/dist/executor-2FWQRLMG.js +0 -15
- package/dist/executor-QZ7BXICW.js +0 -9
- package/dist/executor-Z5ZLJVTV.js +0 -9
- package/dist/export-accessible-KRV5W4GH.js +0 -17
- package/dist/extract-partition-GLKBOXFQ.js +0 -30
- package/dist/fanout-sidecar-GF3DJ6KR.js.map +0 -1
- package/dist/issue-Y6UVIR43.js +0 -13
- package/dist/kernel/index.d.ts +0 -32
- package/dist/kernel/index.js +0 -53
- package/dist/liberate-CRPZEV7O.js +0 -18
- package/dist/noydb-367AM4HT.js +0 -50
- package/dist/registry-45RJNWGU.js +0 -9
- package/dist/registry-5GRV5VXI.js +0 -13
- package/dist/registry-WEUCHBO4.js +0 -11
- package/dist/request-withdrawal-GBPH2FDY.js +0 -25
- package/dist/revoke-TUFRGI6S.js +0 -18
- package/dist/signer-PNKTBVF7.js +0 -19
- package/dist/withdraw-accessible-FFS46EOD.js +0 -22
- /package/dist/{adapter/index.js.map → api-TX2EX2FX.js.map} +0 -0
- /package/dist/{chunk-5N6CZTCY.js.map → chunk-2OZXVKVP.js.map} +0 -0
- /package/dist/{chunk-UAG5KWVA.js.map → chunk-3MATJ6O4.js.map} +0 -0
- /package/dist/{chunk-AZAOEIKW.js.map → chunk-5YESYH2C.js.map} +0 -0
- /package/dist/{chunk-VCTFO5CO.js.map → chunk-6P5XCKSD.js.map} +0 -0
- /package/dist/{chunk-IO6GRPT6.js.map → chunk-7BWJHO2A.js.map} +0 -0
- /package/dist/{chunk-UDRIWL7A.js.map → chunk-BKARNZJN.js.map} +0 -0
- /package/dist/{chunk-V7RWQRG7.js.map → chunk-CB7CWSKW.js.map} +0 -0
- /package/dist/{chunk-CWPPNPOH.js.map → chunk-DJ7KIPLV.js.map} +0 -0
- /package/dist/{chunk-TA66UMI4.js.map → chunk-F4CEK5YM.js.map} +0 -0
- /package/dist/{chunk-SM3AVUHC.js.map → chunk-G4JYND6L.js.map} +0 -0
- /package/dist/{chunk-AXRXJTE2.js.map → chunk-G6XV4H65.js.map} +0 -0
- /package/dist/{chunk-UV5MFVO3.js.map → chunk-HPWKV3YB.js.map} +0 -0
- /package/dist/{chunk-SKF73JOP.js.map → chunk-ICXIFFYZ.js.map} +0 -0
- /package/dist/{chunk-LMTH2RM6.js.map → chunk-KNZB6JMR.js.map} +0 -0
- /package/dist/{chunk-PKHL44ER.js.map → chunk-LEJIKBBB.js.map} +0 -0
- /package/dist/{chunk-PSMV73A5.js.map → chunk-OBKWYKYC.js.map} +0 -0
- /package/dist/{chunk-CMGR4ZEW.js.map → chunk-OHHKHSJP.js.map} +0 -0
- /package/dist/{chunk-HCIPRAGS.js.map → chunk-OT76OZL6.js.map} +0 -0
- /package/dist/{chunk-SMXWYP24.js.map → chunk-OXCSVM3B.js.map} +0 -0
- /package/dist/{chunk-IGUYVGGI.js.map → chunk-P33LUIML.js.map} +0 -0
- /package/dist/{chunk-EIZUR2XW.js.map → chunk-PS2NEWEX.js.map} +0 -0
- /package/dist/{chunk-WYSO2NIH.js.map → chunk-QOC3VYL2.js.map} +0 -0
- /package/dist/{chunk-KVOXU4T5.js.map → chunk-RHK32N73.js.map} +0 -0
- /package/dist/{chunk-3YFXJ3ZP.js.map → chunk-RW3Y22MW.js.map} +0 -0
- /package/dist/{chunk-QHJW5EXU.js.map → chunk-TWKKOM55.js.map} +0 -0
- /package/dist/{chunk-M6OST55S.js.map → chunk-U3WZCU7E.js.map} +0 -0
- /package/dist/{chunk-KXGNJJXB.js.map → chunk-UN4FVIBH.js.map} +0 -0
- /package/dist/{chunk-NF5JWERG.js.map → chunk-VRIYFLBA.js.map} +0 -0
- /package/dist/{chunk-RUEKROOS.js.map → chunk-VWRRVE6D.js.map} +0 -0
- /package/dist/{chunk-XXYIOFUB.js.map → chunk-WIGQB62E.js.map} +0 -0
- /package/dist/{chunk-IAGBDSCS.js.map → chunk-XREOISSI.js.map} +0 -0
- /package/dist/{chunk-ZCGAHGUS.js.map → chunk-YCXCR7VG.js.map} +0 -0
- /package/dist/{describe → classified}/index.js.map +0 -0
- /package/dist/{api-RW3KP7WU.js.map → collection-facade-LVD22JLM.js.map} +0 -0
- /package/dist/{chunk-BGIZAFY7.js.map → computed-EXDMQODG.js.map} +0 -0
- /package/dist/{chunk-K2WCO3NX.js.map → delegation-BJP73GAP.js.map} +0 -0
- /package/dist/{collection-facade-GQAOGJP2.js.map → derive-BME7HDWO.js.map} +0 -0
- /package/dist/{delegation-UL5HKLER.js.map → enclave-NHORSWSF.js.map} +0 -0
- /package/dist/{enclave-UL5LW66V.js.map → executor-FE6X4LFX.js.map} +0 -0
- /package/dist/{executor-2FWQRLMG.js.map → executor-KSHKRJXP.js.map} +0 -0
- /package/dist/{executor-QZ7BXICW.js.map → executor-ZHTJJICG.js.map} +0 -0
- /package/dist/{executor-Z5ZLJVTV.js.map → export-accessible-DACHM5VT.js.map} +0 -0
- /package/dist/{export-accessible-KRV5W4GH.js.map → extract-partition-RNENZZ4T.js.map} +0 -0
- /package/dist/{extract-partition-GLKBOXFQ.js.map → find-BNGBJNKP.js.map} +0 -0
- /package/dist/{issue-Y6UVIR43.js.map → issue-NDI4CVZU.js.map} +0 -0
- /package/dist/{kernel → lazy}/index.js.map +0 -0
- /package/dist/{ledger-RYI35CDS.js.map → ledger-6NDS2EO4.js.map} +0 -0
- /package/dist/{liberate-CRPZEV7O.js.map → liberate-HN3RIGIP.js.map} +0 -0
- /package/dist/{noydb-367AM4HT.js.map → link-set-SJB2MVJV.js.map} +0 -0
- /package/dist/{policy-IXK4FVXP.js.map → noydb-BWF6EPIR.js.map} +0 -0
- /package/dist/{public-envelope-JHDQCPSX.js.map → policy-WGNAG5H6.js.map} +0 -0
- /package/dist/{read-only-facade-5ADRJVTM.js.map → public-envelope-EJLVIFX7.js.map} +0 -0
- /package/dist/{registry-45RJNWGU.js.map → read-only-facade-CHCKSEPD.js.map} +0 -0
- /package/dist/{registry-5GRV5VXI.js.map → register-SBIX7TVV.js.map} +0 -0
- /package/dist/{registry-WEUCHBO4.js.map → registry-3EQG6OOE.js.map} +0 -0
- /package/dist/{request-withdrawal-GBPH2FDY.js.map → registry-CA327ACV.js.map} +0 -0
- /package/dist/{revoke-TUFRGI6S.js.map → registry-E7OXOTSV.js.map} +0 -0
- /package/dist/{signer-PNKTBVF7.js.map → request-withdrawal-KAH2AAXC.js.map} +0 -0
- /package/dist/{stale-3JWHNDIY.js.map → revoke-IXLOJ3IH.js.map} +0 -0
- /package/dist/{withdraw-accessible-FFS46EOD.js.map → satellites/index.js.map} +0 -0
- /package/dist/{store-coordination-provider-3I7XWZZK.js.map → store-coordination-provider-DTDMI6VL.js.map} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VDIG_ITERATIONS,
|
|
3
|
+
normalizeForVerify,
|
|
4
|
+
pbkdf2VerifyDigest
|
|
5
|
+
} from "./chunk-LP7BEXCT.js";
|
|
6
|
+
import {
|
|
7
|
+
bufferToBase64
|
|
8
|
+
} from "./chunk-3OPY6MK2.js";
|
|
9
|
+
|
|
10
|
+
// src/kernel/enclave/classify/bidx.ts
|
|
11
|
+
var subtle = globalThis.crypto.subtle;
|
|
12
|
+
var CLASSIFY_INDEX_KEY_DOMAIN = "noydb-classify-index-v1";
|
|
13
|
+
var CLASSIFY_INDEX_SALT_DOMAIN = "noydb-classify-index-salt-v1";
|
|
14
|
+
var COST_BYTE_V1 = 1;
|
|
15
|
+
var CURRENT_COST_BYTE = COST_BYTE_V1;
|
|
16
|
+
function iterationsForCostByte(b) {
|
|
17
|
+
if (b === COST_BYTE_V1) return VDIG_ITERATIONS;
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
async function deriveClassifyIndexKey(dek, collection, field) {
|
|
21
|
+
const rawDek = await subtle.exportKey("raw", dek);
|
|
22
|
+
const hkdfKey = await subtle.importKey("raw", rawDek, "HKDF", false, ["deriveBits"]);
|
|
23
|
+
const salt = new TextEncoder().encode(CLASSIFY_INDEX_KEY_DOMAIN);
|
|
24
|
+
const info = new TextEncoder().encode(JSON.stringify([CLASSIFY_INDEX_KEY_DOMAIN, collection, field]));
|
|
25
|
+
const bits = await subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt, info }, hkdfKey, 256);
|
|
26
|
+
return subtle.importKey("raw", bits, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
27
|
+
}
|
|
28
|
+
async function deriveClassifyIndexSalt(dek, collection, field) {
|
|
29
|
+
const rawDek = await subtle.exportKey("raw", dek);
|
|
30
|
+
const hkdfKey = await subtle.importKey("raw", rawDek, "HKDF", false, ["deriveBits"]);
|
|
31
|
+
const salt = new TextEncoder().encode(CLASSIFY_INDEX_SALT_DOMAIN);
|
|
32
|
+
const info = new TextEncoder().encode(JSON.stringify([CLASSIFY_INDEX_SALT_DOMAIN, collection, field]));
|
|
33
|
+
const bits = await subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt, info }, hkdfKey, 256);
|
|
34
|
+
return new Uint8Array(bits);
|
|
35
|
+
}
|
|
36
|
+
async function mintAt(normalized, dek, collection, field, costByte) {
|
|
37
|
+
const iterations = iterationsForCostByte(costByte);
|
|
38
|
+
if (iterations == null) {
|
|
39
|
+
throw new Error(`bidx: unknown cost byte 0x${costByte.toString(16)}`);
|
|
40
|
+
}
|
|
41
|
+
const saltCf = await deriveClassifyIndexSalt(dek, collection, field);
|
|
42
|
+
const inner = await pbkdf2VerifyDigest(normalized, saltCf, iterations);
|
|
43
|
+
const kIdx = await deriveClassifyIndexKey(dek, collection, field);
|
|
44
|
+
const mac = await subtle.sign("HMAC", kIdx, inner);
|
|
45
|
+
const tag = new Uint8Array(1 + 32);
|
|
46
|
+
tag[0] = costByte;
|
|
47
|
+
tag.set(new Uint8Array(mac), 1);
|
|
48
|
+
return bufferToBase64(tag);
|
|
49
|
+
}
|
|
50
|
+
async function mintBidxTag(normalized, dek, collection, field) {
|
|
51
|
+
return mintAt(normalized, dek, collection, field, CURRENT_COST_BYTE);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/kernel/enclave/classify/find.ts
|
|
55
|
+
async function computeBidxTarget(candidate, normalize, dek, collection, field, costByte) {
|
|
56
|
+
const resolvedCostByte = costByte ?? CURRENT_COST_BYTE;
|
|
57
|
+
const iters = iterationsForCostByte(resolvedCostByte);
|
|
58
|
+
if (iters === null) return null;
|
|
59
|
+
const normalized = normalizeForVerify(normalize, candidate);
|
|
60
|
+
return mintAt(normalized, dek, collection, field, resolvedCostByte);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
deriveClassifyIndexKey,
|
|
65
|
+
deriveClassifyIndexSalt,
|
|
66
|
+
mintBidxTag,
|
|
67
|
+
computeBidxTarget
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-HYR4WZZ3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kernel/enclave/classify/bidx.ts","../src/kernel/enclave/classify/find.ts"],"sourcesContent":["/**\n * Blind-index slow-tag primitive for classified `equatable` fields (stage 2).\n *\n * `mintBidxTag` mints a deterministic, key-and-cost-gated tag —\n * `COST_BYTE ‖ HMAC-SHA256(K_idx, PBKDF2-SHA256(normalized, salt_cf))` — that\n * lets `find.ts` do blind equality lookup over an otherwise-opaque field\n * without ever storing the plaintext or a fast dictionary-crackable digest.\n *\n * Rationale (M-2/I3, spec §4/Crypto #1):\n * - The outer HMAC is **keyed** by `K_idx`, a DEK-derived key never seen by\n * the store. A key-less adversary (store access only) cannot mint a\n * candidate tag to test against the index at all — the HMAC blocks the\n * classic \"key-less dictionary attack\" a plain digest would invite.\n * - The inner `pbkdf2VerifyDigest` (stage-2, `digest.ts`) reuses the\n * existing 600K-iteration cost floor, so even a **DEK holder** who can\n * compute `K_idx` still pays the PBKDF2 cost per guess — minting is not\n * free just because you crossed the door.\n * - Neither control is the real security boundary: the DOOR (who is ever\n * handed the DEK to begin with) is. These two costs only shape the\n * economics for whoever is already inside; they do not substitute for\n * access control.\n *\n * `K_idx` and `salt_cf` are separate HKDF derivations off the same DEK\n * (L-1, #554 precedent: dedicated keys from day one, no shared/legacy form) —\n * sign-key hygiene, not `HMAC(K_idx, const)`. Both derivations are\n * domain-separated per `(collection, field)` so a tag cannot be replayed\n * across fields or collections (join-attack separation).\n *\n * `CURRENT_COST_BYTE` is a 1-byte discriminator prefixed onto every tag so a\n * future iteration-tier bump can mint new tags while old ones still parse:\n * an unknown discriminator is a cheap, immediate non-match instead of a\n * PBKDF2 run at the wrong iteration count.\n *\n * @module\n */\nimport type { EnclaveKey } from '../crypto.js'\nimport { bufferToBase64 } from '../crypto.js'\nimport { pbkdf2VerifyDigest, VDIG_ITERATIONS } from './digest.js'\n\nconst subtle = globalThis.crypto.subtle\n\n/** HKDF salt domain for the `K_idx` (blind-index HMAC key) derivation. */\nexport const CLASSIFY_INDEX_KEY_DOMAIN = 'noydb-classify-index-v1'\n\n/** HKDF salt domain for the `salt_cf` (per collection/field PBKDF2 salt) derivation. */\nexport const CLASSIFY_INDEX_SALT_DOMAIN = 'noydb-classify-index-salt-v1'\n\n/** Cost-byte discriminator: version 1, iteration-tier 600K. */\nexport const COST_BYTE_V1 = 0x01\n/** The cost byte new tags are minted at. */\nexport const CURRENT_COST_BYTE = COST_BYTE_V1\n\n/**\n * Map a tag's cost-byte discriminator to its PBKDF2 iteration count.\n * An unrecognized discriminator returns `null` — a mismatched/legacy byte\n * is a cheap non-match, never a PBKDF2 run at the wrong tier.\n */\nexport function iterationsForCostByte(b: number): number | null {\n if (b === COST_BYTE_V1) return VDIG_ITERATIONS\n return null\n}\n\n/**\n * Derive the collection+field's dedicated blind-index HMAC key `K_idx` from\n * the DEK via HKDF-SHA256. Non-extractable, `sign`-only — it never leaves\n * this module in usable form.\n */\nexport async function deriveClassifyIndexKey(\n dek: EnclaveKey,\n collection: string,\n field: string,\n): Promise<EnclaveKey> {\n const rawDek = await subtle.exportKey('raw', dek)\n const hkdfKey = await subtle.importKey('raw', rawDek, 'HKDF', false, ['deriveBits'])\n const salt = new TextEncoder().encode(CLASSIFY_INDEX_KEY_DOMAIN)\n const info = new TextEncoder().encode(JSON.stringify([CLASSIFY_INDEX_KEY_DOMAIN, collection, field]))\n const bits = await subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt, info }, hkdfKey, 256)\n return subtle.importKey('raw', bits, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])\n}\n\n/**\n * Derive the collection+field's dedicated PBKDF2 salt `salt_cf` from the DEK\n * via a SEPARATE HKDF-deriveBits (distinct from {@link deriveClassifyIndexKey}\n * — sign-key hygiene, not `HMAC(K_idx, const)`). 32 raw bytes.\n */\nexport async function deriveClassifyIndexSalt(\n dek: EnclaveKey,\n collection: string,\n field: string,\n): Promise<Uint8Array> {\n const rawDek = await subtle.exportKey('raw', dek)\n const hkdfKey = await subtle.importKey('raw', rawDek, 'HKDF', false, ['deriveBits'])\n const salt = new TextEncoder().encode(CLASSIFY_INDEX_SALT_DOMAIN)\n const info = new TextEncoder().encode(JSON.stringify([CLASSIFY_INDEX_SALT_DOMAIN, collection, field]))\n const bits = await subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt, info }, hkdfKey, 256)\n return new Uint8Array(bits)\n}\n\n/**\n * Mint a blind-index tag at a given cost byte:\n * `tag = base64(COST_BYTE ‖ HMAC(K_idx, PBKDF2(normalized, salt_cf, iterations-for(COST_BYTE))))`.\n * Factored out of {@link mintBidxTag} so `find.ts`'s `computeBidxTarget` can\n * reuse the same crypto at a caller-chosen cost byte (e.g. to evaluate a\n * legacy tier) without duplicating the derivation/digest/MAC pipeline.\n */\nexport async function mintAt(\n normalized: string,\n dek: EnclaveKey,\n collection: string,\n field: string,\n costByte: number,\n): Promise<string> {\n const iterations = iterationsForCostByte(costByte)\n if (iterations == null) {\n throw new Error(`bidx: unknown cost byte 0x${costByte.toString(16)}`)\n }\n const saltCf = await deriveClassifyIndexSalt(dek, collection, field)\n const inner = await pbkdf2VerifyDigest(normalized, saltCf, iterations)\n const kIdx = await deriveClassifyIndexKey(dek, collection, field)\n const mac = await subtle.sign('HMAC', kIdx, inner as BufferSource)\n const tag = new Uint8Array(1 + 32)\n tag[0] = costByte\n tag.set(new Uint8Array(mac), 1)\n return bufferToBase64(tag)\n}\n\n/**\n * Mint a blind-index tag for an already-normalized value at\n * {@link CURRENT_COST_BYTE}. The caller normalizes once via\n * `normalizeForVerify` (the shared pipeline with `mintVdigSlot`) —\n * `mintBidxTag` never re-normalizes.\n */\nexport async function mintBidxTag(\n normalized: string,\n dek: EnclaveKey,\n collection: string,\n field: string,\n): Promise<string> {\n return mintAt(normalized, dek, collection, field, CURRENT_COST_BYTE)\n}\n","/**\n * Query-side blind-index target derivation for classified `equatable`\n * fields (stage 2). `computeBidxTarget` normalizes a caller-supplied\n * candidate and mints it into the same 33-byte `_bidx` tag shape produced by\n * `mintBidxTag` (`bidx.ts`), so a caller can string-compare the result\n * against a stored tag to answer \"does this candidate match?\" without ever\n * decrypting or dictionary-attacking the field.\n *\n * Discriminator-scan contract (Oracle #4): a scanning caller reads each\n * stored tag's leading cost-byte discriminator and derives the target tag\n * **once per distinct discriminator present** — never per-record. `find.ts`\n * itself only computes a single target for a single requested `costByte`;\n * the batching-by-discriminator behavior belongs to the scanner\n * (`findByDigest`, a later task), which calls this function once per\n * distinct discriminator it encounters at step 2 of its scan.\n *\n * An unrecognized `costByte` (unknown or legacy tier not yet supported) is a\n * cheap `null` non-match — `computeBidxTarget` never runs PBKDF2 at a wrong\n * iteration tier just to produce a target that could not possibly match.\n * A legacy tag of a KNOWN older tier remains matchable today by passing that\n * tier's `costByte` explicitly (v1-only today: `CURRENT_COST_BYTE` is the\n * only recognized tier, so this is a future-proofing hook, not live behavior\n * yet).\n *\n * @module\n */\nimport type { EnclaveKey } from '../crypto.js'\nimport { mintAt, iterationsForCostByte, CURRENT_COST_BYTE } from './bidx.js'\nimport { normalizeForVerify, type VerifyNormalizeMode } from './normalize.js'\n\n/**\n * Normalize `candidate` and mint it into a blind-index target tag at\n * `costByte` (default {@link CURRENT_COST_BYTE}), for string-comparison\n * against a stored `_bidx` tag. Returns `null` when `costByte` is not a\n * recognized discriminator — no PBKDF2 is attempted at an unknown/wrong\n * tier (Oracle #4).\n */\nexport async function computeBidxTarget(\n candidate: string,\n normalize: VerifyNormalizeMode,\n dek: EnclaveKey,\n collection: string,\n field: string,\n costByte?: number,\n): Promise<string | null> {\n const resolvedCostByte = costByte ?? CURRENT_COST_BYTE\n const iters = iterationsForCostByte(resolvedCostByte)\n if (iters === null) return null\n const normalized = normalizeForVerify(normalize, candidate)\n return mintAt(normalized, dek, collection, field, resolvedCostByte)\n}\n"],"mappings":";;;;;;;;;;AAuCA,IAAM,SAAS,WAAW,OAAO;AAG1B,IAAM,4BAA4B;AAGlC,IAAM,6BAA6B;AAGnC,IAAM,eAAe;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QAAM,SAAS,MAAM,wBAAwB,KAAK,YAAY,KAAK;AACnE,QAAM,QAAQ,MAAM,mBAAmB,YAAY,QAAQ,UAAU;AACrE,QAAM,OAAO,MAAM,uBAAuB,KAAK,YAAY,KAAK;AAChE,QAAM,MAAM,MAAM,OAAO,KAAK,QAAQ,MAAM,KAAqB;AACjE,QAAM,MAAM,IAAI,WAAW,IAAI,EAAE;AACjC,MAAI,CAAC,IAAI;AACT,MAAI,IAAI,IAAI,WAAW,GAAG,GAAG,CAAC;AAC9B,SAAO,eAAe,GAAG;AAC3B;AAQA,eAAsB,YACpB,YACA,KACA,YACA,OACiB;AACjB,SAAO,OAAO,YAAY,KAAK,YAAY,OAAO,iBAAiB;AACrE;;;ACtGA,eAAsB,kBACpB,WACA,WACA,KACA,YACA,OACA,UACwB;AACxB,QAAM,mBAAmB,YAAY;AACrC,QAAM,QAAQ,sBAAsB,gBAAgB;AACpD,MAAI,UAAU,KAAM,QAAO;AAC3B,QAAM,aAAa,mBAAmB,WAAW,SAAS;AAC1D,SAAO,OAAO,YAAY,KAAK,YAAY,OAAO,gBAAgB;AACpE;","names":[]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ConflictError,
|
|
7
7
|
InvariantError,
|
|
8
8
|
ValidationError
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-S7VFUQM2.js";
|
|
10
10
|
|
|
11
11
|
// src/with-commit/tx/transaction.ts
|
|
12
12
|
var TxContext = class {
|
|
@@ -216,7 +216,7 @@ async function runTransaction(db, fn, options, txInvariants) {
|
|
|
216
216
|
db._clearActiveTxContext(ctx);
|
|
217
217
|
}
|
|
218
218
|
if (ctx._amendment) {
|
|
219
|
-
const { GuardExecutor } = await import("./executor-
|
|
219
|
+
const { GuardExecutor } = await import("./executor-ZHTJJICG.js");
|
|
220
220
|
try {
|
|
221
221
|
for (const [vaultName, v] of ctx._amendmentVaults) {
|
|
222
222
|
const registry = v._getGuardRegistry();
|
|
@@ -352,4 +352,4 @@ export {
|
|
|
352
352
|
runTransaction,
|
|
353
353
|
revertExecuted
|
|
354
354
|
};
|
|
355
|
-
//# sourceMappingURL=chunk-
|
|
355
|
+
//# sourceMappingURL=chunk-ICXIFFYZ.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/kernel/query/predicate.ts
|
|
2
|
+
function readPath(record, path) {
|
|
3
|
+
if (record === null || record === void 0) return void 0;
|
|
4
|
+
if (!path.includes(".")) {
|
|
5
|
+
return record[path];
|
|
6
|
+
}
|
|
7
|
+
const segments = path.split(".");
|
|
8
|
+
let cursor = record;
|
|
9
|
+
for (const segment of segments) {
|
|
10
|
+
if (cursor === null || cursor === void 0) return void 0;
|
|
11
|
+
cursor = cursor[segment];
|
|
12
|
+
}
|
|
13
|
+
return cursor;
|
|
14
|
+
}
|
|
15
|
+
function evaluateFieldClause(record, clause) {
|
|
16
|
+
const actual = readPath(record, clause.field);
|
|
17
|
+
const { op, value } = clause;
|
|
18
|
+
if (clause.via) return clause.via.evaluate(actual, op);
|
|
19
|
+
switch (op) {
|
|
20
|
+
case "==":
|
|
21
|
+
return actual === value;
|
|
22
|
+
case "!=":
|
|
23
|
+
return actual !== value;
|
|
24
|
+
case "<":
|
|
25
|
+
return isComparable(actual, value) && actual < value;
|
|
26
|
+
case "<=":
|
|
27
|
+
return isComparable(actual, value) && actual <= value;
|
|
28
|
+
case ">":
|
|
29
|
+
return isComparable(actual, value) && actual > value;
|
|
30
|
+
case ">=":
|
|
31
|
+
return isComparable(actual, value) && actual >= value;
|
|
32
|
+
case "in":
|
|
33
|
+
return Array.isArray(value) && value.includes(actual);
|
|
34
|
+
case "contains":
|
|
35
|
+
if (typeof actual === "string") return typeof value === "string" && actual.includes(value);
|
|
36
|
+
if (Array.isArray(actual)) return actual.includes(value);
|
|
37
|
+
return false;
|
|
38
|
+
case "startsWith":
|
|
39
|
+
return typeof actual === "string" && typeof value === "string" && actual.startsWith(value);
|
|
40
|
+
case "between": {
|
|
41
|
+
if (!Array.isArray(value) || value.length !== 2) return false;
|
|
42
|
+
const [lo, hi] = value;
|
|
43
|
+
if (!isComparable(actual, lo) || !isComparable(actual, hi)) return false;
|
|
44
|
+
return actual >= lo && actual <= hi;
|
|
45
|
+
}
|
|
46
|
+
default: {
|
|
47
|
+
const _exhaustive = op;
|
|
48
|
+
void _exhaustive;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isComparable(a, b) {
|
|
54
|
+
if (typeof a === "number" && typeof b === "number") return true;
|
|
55
|
+
if (typeof a === "string" && typeof b === "string") return true;
|
|
56
|
+
if (a instanceof Date && b instanceof Date) return true;
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
function evaluateClause(record, clause, fnRecord) {
|
|
60
|
+
switch (clause.type) {
|
|
61
|
+
case "field":
|
|
62
|
+
return evaluateFieldClause(record, clause);
|
|
63
|
+
case "filter":
|
|
64
|
+
return clause.fn(fnRecord !== void 0 ? fnRecord : record);
|
|
65
|
+
case "wherePredicate":
|
|
66
|
+
return clause.fn(fnRecord !== void 0 ? fnRecord : record, clause.ctx);
|
|
67
|
+
case "crossJoin":
|
|
68
|
+
throw new Error(
|
|
69
|
+
`evaluateClause: 'crossJoin' clauses are expansion primitives and are not evaluated per-record. This is a query planner routing error \u2014 crossJoin clauses must be extracted from the clause list before calling evaluateClause or filterRecords.`
|
|
70
|
+
);
|
|
71
|
+
case "group":
|
|
72
|
+
if (clause.op === "and") {
|
|
73
|
+
for (const child of clause.clauses) {
|
|
74
|
+
if (!evaluateClause(record, child, fnRecord)) return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
} else {
|
|
78
|
+
for (const child of clause.clauses) {
|
|
79
|
+
if (evaluateClause(record, child, fnRecord)) return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function hasFnClause(clauses) {
|
|
86
|
+
for (const c of clauses) {
|
|
87
|
+
if (c.type === "filter" || c.type === "wherePredicate") return true;
|
|
88
|
+
if (c.type === "group" && hasFnClause(c.clauses)) return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
readPath,
|
|
95
|
+
evaluateFieldClause,
|
|
96
|
+
evaluateClause,
|
|
97
|
+
hasFnClause
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=chunk-IGJCYUT5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kernel/query/predicate.ts"],"sourcesContent":["/**\n * Operator implementations for the query DSL.\n *\n * All predicates run client-side, AFTER decryption — they never see ciphertext.\n * Field clauses over a Via-covered field (e.g. money) carry their own\n * evaluator closure (see {@link FieldClause.via}), so this module has no\n * dependency on any Via feature's implementation — still tree-shakeable.\n */\n\n/** Comparison operators supported by the where() builder. */\nexport type Operator =\n | '=='\n | '!='\n | '<'\n | '<='\n | '>'\n | '>='\n | 'in'\n | 'contains'\n | 'startsWith'\n | 'between'\n\n/**\n * A single field comparison clause inside a query plan.\n * Plans are JSON-serializable, so this type uses primitives only.\n */\nexport interface FieldClause {\n readonly type: 'field'\n readonly field: string\n readonly op: Operator\n readonly value: unknown\n /**\n * Present when `field` is covered by a Via feature binding (e.g. a\n * declared money field): the opaque payload built by the binding's\n * `buildClause` at query BUILD time, plus a closure that evaluates it\n * per record via the binding's `evaluateClause`. Attached by\n * `Query.where()` / `ScanBuilder.where()` when `source.via` covers the\n * field. The closure keeps this module free of any dependency on a\n * Via feature's implementation — clauses are in-memory only, never\n * serialized, so carrying a function here is safe.\n */\n readonly via?: {\n readonly brand: string\n readonly payload: unknown\n readonly evaluate: (actual: unknown, op: string) => boolean\n /**\n * The binding's `indexProbe` result for this clause's op/payload\n * (#625) — the STORED-form operand `candidateRecords()` (`kernel/\n * query/builder.ts`) can hand to `CollectionIndexes.lookupEqual`/\n * `lookupIn` for a fast path. `undefined` (no `indexProbe` hook, or\n * the binding declined to probe this op) means the field must fall\n * back to a linear scan via `evaluate` above.\n */\n readonly indexValue?: unknown\n }\n}\n\n/**\n * A user-supplied predicate function escape hatch. Not serializable.\n *\n * The predicate accepts `unknown` at the type level so the surrounding\n * Clause type can stay non-parametric — this keeps Collection<T> covariant\n * in T at the public API surface. Builder methods cast user predicates\n * (typed `(record: T) => boolean`) into this shape on the way in.\n */\nexport interface FilterClause {\n readonly type: 'filter'\n readonly fn: (record: unknown) => boolean\n}\n\n/**\n * A declared deterministic predicate reference. The query\n * builder produces this via `.wherePredicate(name, ctx?)` when a\n * Query has been augmented with a predicates map (typically by the\n * materialized-view registry).\n *\n * `predicateHash` is the consumer-supplied stable hash for the\n * function body; `ctxHash` is the canonical-JSON SHA-256 of `ctx`.\n * Both fold into the MV's `queryHash` so a function or ctx change\n * forces refresh on next visit.\n *\n * `fn` is resolved at builder time from the predicates map and\n * embedded directly — so `evaluateClause` can fire it without a\n * runtime lookup.\n */\nexport interface WherePredicateClause {\n readonly type: 'wherePredicate'\n readonly name: string\n readonly ctx: unknown\n readonly predicateHash: string\n readonly ctxHash: string\n readonly fn: (record: unknown, ctx?: unknown) => boolean\n}\n\n/** A logical group of clauses combined by AND or OR. */\nexport interface GroupClause {\n readonly type: 'group'\n readonly op: 'and' | 'or'\n readonly clauses: readonly Clause[]\n}\n\n/**\n * Cartesian-product expansion clause. Appended to `QueryPlan.clauses`\n * by `Query.crossJoin()`. Processed in declaration order by\n * `executeClausePipeline` — NOT by `evaluateClause` (which is a\n * per-record predicate and throws on this type).\n */\nexport interface CrossJoinClause {\n readonly type: 'crossJoin'\n /** Target collection name to cross-join against. */\n readonly target: string\n /** Alias under which the right-side record is exposed on each result row. */\n readonly as: string\n /**\n * Lateral filter callback. `undefined` → full cartesian product.\n * Two call shapes:\n * - Subset: `(left) => TTarget[]` — returns the right rows for this left row\n * - Predicate: `(left) => (right) => boolean` — executor materializes then filters\n */\n readonly on?: (left: unknown) => unknown[] | ((right: unknown) => boolean)\n /** When `on:` was supplied as `{ predicate: name }`, the name is stored here for queryHash. */\n readonly onPredicateName?: string\n /** Per-clause row ceiling override. `undefined` → `DEFAULT_CROSS_JOIN_MAX_ROWS`. */\n readonly maxRows?: number\n}\n\nexport type Clause = FieldClause | FilterClause | WherePredicateClause | GroupClause | CrossJoinClause\n\n/**\n * Read a possibly nested field path like \"address.city\" from a record.\n * Returns undefined if any segment is missing.\n */\nexport function readPath(record: unknown, path: string): unknown {\n if (record === null || record === undefined) return undefined\n if (!path.includes('.')) {\n return (record as Record<string, unknown>)[path]\n }\n const segments = path.split('.')\n let cursor: unknown = record\n for (const segment of segments) {\n if (cursor === null || cursor === undefined) return undefined\n cursor = (cursor as Record<string, unknown>)[segment]\n }\n return cursor\n}\n\n/**\n * Evaluate a single field clause against a record.\n * Returns false on type mismatches rather than throwing — query results\n * exclude non-matching records by definition.\n */\nexport function evaluateFieldClause(record: unknown, clause: FieldClause): boolean {\n const actual = readPath(record, clause.field)\n const { op, value } = clause\n\n // A Via-covered field (e.g. money) may store a transformed\n // representation (money: BigInt-exact in scaled-integer space) that the\n // generic paths below can't compare correctly — the operand was\n // pre-built at query BUILD time and the binding's own evaluator knows\n // how to compare it against the raw stored value.\n if (clause.via) return clause.via.evaluate(actual, op)\n\n switch (op) {\n case '==':\n return actual === value\n case '!=':\n return actual !== value\n case '<':\n return isComparable(actual, value) && (actual as number) < (value as number)\n case '<=':\n return isComparable(actual, value) && (actual as number) <= (value as number)\n case '>':\n return isComparable(actual, value) && (actual as number) > (value as number)\n case '>=':\n return isComparable(actual, value) && (actual as number) >= (value as number)\n case 'in':\n return Array.isArray(value) && value.includes(actual)\n case 'contains':\n if (typeof actual === 'string') return typeof value === 'string' && actual.includes(value)\n if (Array.isArray(actual)) return actual.includes(value)\n return false\n case 'startsWith':\n return typeof actual === 'string' && typeof value === 'string' && actual.startsWith(value)\n case 'between': {\n if (!Array.isArray(value) || value.length !== 2) return false\n const [lo, hi] = value\n if (!isComparable(actual, lo) || !isComparable(actual, hi)) return false\n return (actual as number) >= (lo as number) && (actual as number) <= (hi as number)\n }\n default: {\n // Exhaustiveness — TS will error if a new operator is added without a case.\n const _exhaustive: never = op\n void _exhaustive\n return false\n }\n }\n}\n\n/**\n * Two values are \"comparable\" if they share an order-defined runtime type.\n * Strings compare lexicographically; numbers and Dates numerically; otherwise false.\n */\nfunction isComparable(a: unknown, b: unknown): boolean {\n if (typeof a === 'number' && typeof b === 'number') return true\n if (typeof a === 'string' && typeof b === 'string') return true\n if (a instanceof Date && b instanceof Date) return true\n return false\n}\n\n/**\n * Evaluate any clause (field / filter / group) against a record.\n * The recursion depth is bounded by the user's query expression — no risk of\n * blowing the stack on a 50K-record collection.\n *\n * `fnRecord`, when provided, is the view handed to USER CALLBACK clauses\n * (`filter` / `wherePredicate`) instead of `record` — the executor passes\n * the money-decoded view there so user code never sees the stored\n * scaled-int form, while field clauses keep evaluating against the raw\n * record (their money operands are pre-quantized to that space).\n */\nexport function evaluateClause(record: unknown, clause: Clause, fnRecord?: unknown): boolean {\n switch (clause.type) {\n case 'field':\n return evaluateFieldClause(record, clause)\n case 'filter':\n return clause.fn(fnRecord !== undefined ? fnRecord : record)\n case 'wherePredicate':\n return clause.fn(fnRecord !== undefined ? fnRecord : record, clause.ctx)\n case 'crossJoin':\n throw new Error(\n `evaluateClause: 'crossJoin' clauses are expansion primitives and are not ` +\n `evaluated per-record. This is a query planner routing error — ` +\n `crossJoin clauses must be extracted from the clause list before calling ` +\n `evaluateClause or filterRecords.`,\n )\n case 'group':\n if (clause.op === 'and') {\n for (const child of clause.clauses) {\n if (!evaluateClause(record, child, fnRecord)) return false\n }\n return true\n } else {\n for (const child of clause.clauses) {\n if (evaluateClause(record, child, fnRecord)) return true\n }\n return false\n }\n }\n}\n\n/**\n * Does the clause list contain any user-callback clause (filter /\n * wherePredicate), at any group nesting depth? Used by executors to\n * decide whether the per-record decoded view needs materializing.\n */\nexport function hasFnClause(clauses: readonly Clause[]): boolean {\n for (const c of clauses) {\n if (c.type === 'filter' || c.type === 'wherePredicate') return true\n if (c.type === 'group' && hasFnClause(c.clauses)) return true\n }\n return false\n}\n"],"mappings":";AAoIO,SAAS,SAAS,QAAiB,MAAuB;AAC/D,MAAI,WAAW,QAAQ,WAAW,OAAW,QAAO;AACpD,MAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AACvB,WAAQ,OAAmC,IAAI;AAAA,EACjD;AACA,QAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,MAAI,SAAkB;AACtB,aAAW,WAAW,UAAU;AAC9B,QAAI,WAAW,QAAQ,WAAW,OAAW,QAAO;AACpD,aAAU,OAAmC,OAAO;AAAA,EACtD;AACA,SAAO;AACT;AAOO,SAAS,oBAAoB,QAAiB,QAA8B;AACjF,QAAM,SAAS,SAAS,QAAQ,OAAO,KAAK;AAC5C,QAAM,EAAE,IAAI,MAAM,IAAI;AAOtB,MAAI,OAAO,IAAK,QAAO,OAAO,IAAI,SAAS,QAAQ,EAAE;AAErD,UAAQ,IAAI;AAAA,IACV,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO,aAAa,QAAQ,KAAK,KAAM,SAAqB;AAAA,IAC9D,KAAK;AACH,aAAO,aAAa,QAAQ,KAAK,KAAM,UAAsB;AAAA,IAC/D,KAAK;AACH,aAAO,aAAa,QAAQ,KAAK,KAAM,SAAqB;AAAA,IAC9D,KAAK;AACH,aAAO,aAAa,QAAQ,KAAK,KAAM,UAAsB;AAAA,IAC/D,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,MAAM;AAAA,IACtD,KAAK;AACH,UAAI,OAAO,WAAW,SAAU,QAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AACzF,UAAI,MAAM,QAAQ,MAAM,EAAG,QAAO,OAAO,SAAS,KAAK;AACvD,aAAO;AAAA,IACT,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;AACF;AAOO,SAAS,YAAY,SAAqC;AAC/D,aAAW,KAAK,SAAS;AACvB,QAAI,EAAE,SAAS,YAAY,EAAE,SAAS,iBAAkB,QAAO;AAC/D,QAAI,EAAE,SAAS,WAAW,YAAY,EAAE,OAAO,EAAG,QAAO;AAAA,EAC3D;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
decrypt,
|
|
3
2
|
isTombstone
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QA2KUPCP.js";
|
|
4
|
+
import {
|
|
5
|
+
decrypt
|
|
6
|
+
} from "./chunk-3OPY6MK2.js";
|
|
5
7
|
import {
|
|
6
8
|
NOYDB_FORMAT_VERSION
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-YN5IAHN6.js";
|
|
8
10
|
import {
|
|
9
11
|
ReadOnlyAtInstantError
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-S7VFUQM2.js";
|
|
11
13
|
|
|
12
14
|
// src/with-commit/history/history.ts
|
|
13
15
|
var HISTORY_COLLECTION = "_history";
|
|
@@ -275,4 +277,4 @@ export {
|
|
|
275
277
|
VaultInstant,
|
|
276
278
|
CollectionInstant
|
|
277
279
|
};
|
|
278
|
-
//# sourceMappingURL=chunk-
|
|
280
|
+
//# sourceMappingURL=chunk-IVLTXX4W.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/with-commit/history/history.ts","../src/with-commit/history/time-machine.ts"],"sourcesContent":["import type { NoydbStore, EncryptedEnvelope, HistoryOptions, PruneOptions } from '../../kernel/types.js'\nimport { NOYDB_FORMAT_VERSION } from '../../kernel/types.js'\nimport { isTombstone } from '../../kernel/enclave/index.js'\n\n/**\n * History storage convention:\n * Collection: `_history`\n * ID format: `{collection}:{recordId}:{paddedVersion}`\n * Version is zero-padded to 10 digits for lexicographic sorting.\n */\n\nconst HISTORY_COLLECTION = '_history'\nconst VERSION_PAD = 10\n\nfunction historyId(collection: string, recordId: string, version: number): string {\n return `${collection}:${recordId}:${String(version).padStart(VERSION_PAD, '0')}`\n}\n\n// Unused today, kept for future history-id parsing utilities.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction parseHistoryId(id: string): { collection: string; recordId: string; version: number } | null {\n const lastColon = id.lastIndexOf(':')\n if (lastColon < 0) return null\n const versionStr = id.slice(lastColon + 1)\n const rest = id.slice(0, lastColon)\n const firstColon = rest.indexOf(':')\n if (firstColon < 0) return null\n return {\n collection: rest.slice(0, firstColon),\n recordId: rest.slice(firstColon + 1),\n version: parseInt(versionStr, 10),\n }\n}\n\nfunction matchesPrefix(id: string, collection: string, recordId?: string): boolean {\n if (recordId) {\n return id.startsWith(`${collection}:${recordId}:`)\n }\n return id.startsWith(`${collection}:`)\n}\n\n/** Save a history entry (a complete encrypted envelope snapshot). */\nexport async function saveHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n envelope: EncryptedEnvelope,\n): Promise<void> {\n const id = historyId(collection, recordId, envelope._v)\n await adapter.put(vault, HISTORY_COLLECTION, id, envelope)\n}\n\n/** Get history entries for a record, sorted newest-first. */\nexport async function getHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n options?: HistoryOptions,\n): Promise<EncryptedEnvelope[]> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n const matchingIds = allIds\n .filter(id => matchesPrefix(id, collection, recordId))\n .sort()\n .reverse() // newest first\n\n const entries: EncryptedEnvelope[] = []\n\n for (const id of matchingIds) {\n const envelope = await adapter.get(vault, HISTORY_COLLECTION, id)\n if (!envelope) continue\n\n // Apply time filters\n if (options?.from && envelope._ts < options.from) continue\n if (options?.to && envelope._ts > options.to) continue\n\n entries.push(envelope)\n\n if (options?.limit && entries.length >= options.limit) break\n }\n\n return entries\n}\n\n/** Get a specific version's envelope from history. */\nexport async function getVersionEnvelope(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n version: number,\n): Promise<EncryptedEnvelope | null> {\n const id = historyId(collection, recordId, version)\n return adapter.get(vault, HISTORY_COLLECTION, id)\n}\n\n/** Prune history entries. Returns the number of entries deleted. */\nexport async function pruneHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string | undefined,\n options: PruneOptions,\n): Promise<number> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n const matchingIds = allIds\n .filter(id => recordId ? matchesPrefix(id, collection, recordId) : matchesPrefix(id, collection))\n .sort()\n\n let toDelete: string[] = []\n\n if (options.keepVersions !== undefined) {\n // Keep only the N most recent, delete the rest\n const keep = options.keepVersions\n if (matchingIds.length > keep) {\n toDelete = matchingIds.slice(0, matchingIds.length - keep)\n }\n }\n\n if (options.beforeDate) {\n // Delete entries older than the specified date\n for (const id of matchingIds) {\n if (toDelete.includes(id)) continue\n const envelope = await adapter.get(vault, HISTORY_COLLECTION, id)\n if (envelope && envelope._ts < options.beforeDate) {\n toDelete.push(id)\n }\n }\n }\n\n // Deduplicate\n const uniqueDeletes = [...new Set(toDelete)]\n\n for (const id of uniqueDeletes) {\n await adapter.delete(vault, HISTORY_COLLECTION, id)\n }\n\n return uniqueDeletes.length\n}\n\n/** Clear all history for a vault, optionally scoped to a collection or record. */\nexport async function clearHistory(\n adapter: NoydbStore,\n vault: string,\n collection?: string,\n recordId?: string,\n): Promise<number> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n let toDelete: string[]\n\n if (collection && recordId) {\n toDelete = allIds.filter(id => matchesPrefix(id, collection, recordId))\n } else if (collection) {\n toDelete = allIds.filter(id => matchesPrefix(id, collection))\n } else {\n toDelete = allIds\n }\n\n for (const id of toDelete) {\n await adapter.delete(vault, HISTORY_COLLECTION, id)\n }\n\n return toDelete.length\n}\n\n/**\n * Crypto-shred every `_history` version of a record. Each non-tombstone\n * history envelope is OVERWRITTEN in place with a tombstone\n * `{ _noydb, _v, _ts: now, _by: actor, _iv: '', _data: '' }` — dropping\n * `_iv`/`_data`/`_cek`/`_det`, so the prior ciphertext (and the wrapped CEK\n * that could decrypt it) is gone everywhere this store reaches. The version\n * counter (`_v`) is preserved so the audit trail still shows \"N versions\n * existed and were erased.\"\n *\n * Overwrite — NOT delete — so the history key itself survives as proof the\n * version existed. Already-tombstoned versions (re-run / idempotent forget)\n * are left untouched and not counted.\n *\n * Returns the number of history versions newly tombstoned.\n */\nexport async function tombstoneHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n actor: string,\n encrypted: boolean,\n): Promise<number> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n const matchingIds = allIds.filter(id => matchesPrefix(id, collection, recordId))\n\n const now = new Date().toISOString()\n let count = 0\n for (const id of matchingIds) {\n const env = await adapter.get(vault, HISTORY_COLLECTION, id)\n if (!env) continue\n // Already a tombstone (no body and no wrapped CEK)? Skip — idempotent.\n if (isTombstone(env, encrypted)) continue\n const tombstone: EncryptedEnvelope = {\n _noydb: NOYDB_FORMAT_VERSION,\n _v: env._v,\n _ts: now,\n _iv: '',\n _data: '',\n ...(actor ? { _by: actor } : {}),\n }\n await adapter.put(vault, HISTORY_COLLECTION, id, tombstone)\n count++\n }\n return count\n}\n","/**\n * Time-machine queries — point-in-time reads reconstructed from the\n * existing history + ledger infrastructure.\n *\n * ## Usage\n *\n * ```ts\n * const vault = await db.openVault('acme', { passphrase })\n * const q1End = vault.at('2026-03-31T23:59:59Z')\n * const invoice = await q1End.collection<Invoice>('invoices').get('inv-001')\n * // → the record as it stood at the close of Q1 2026\n * ```\n *\n * ## How it works\n *\n * Every write path already fans out into two persistence lanes:\n *\n * 1. `saveHistory(...)` persists a **full encrypted envelope snapshot**\n * per version under the `_history` collection (one envelope per\n * version, keyed by `{collection}:{id}:{paddedVersion}`). Each\n * envelope carries its own `_ts` (the write timestamp).\n * 2. `ledger.append(...)` appends a hash-chained audit entry that\n * records the `op` (put / delete), `version`, and `ts`.\n *\n * Reconstruction at a target timestamp T is therefore:\n *\n * - Find the newest history envelope for `(collection, id)` whose\n * `_ts ≤ T` — that's the state the record was in at T.\n * - Check the ledger for any `op: 'delete'` entry for the same\n * `(collection, id)` with `entry.ts` in `(latestEnvelope._ts, T]` —\n * if present, the record was deleted before T, so return `null`.\n * - Decrypt the surviving envelope with the current collection DEK\n * (DEKs are per-collection but stable across versions — the same\n * key encrypts v1 and v15 of a record).\n *\n * No delta replay. The existing `history.ts` module already stores\n * complete snapshots; we just pick the right one.\n *\n * ## Read-only contract\n *\n * Every write method on `CollectionInstant` throws\n * {@link ReadOnlyAtInstantError}. A historical view is a *read*\n * surface — mutating the past would require either a branch/shadow\n * mechanism (tracked under shadow vaults) or a rewrite of\n * history, which breaks the ledger's tamper-evidence guarantee.\n *\n * @module\n */\nimport type { EncryptedEnvelope, NoydbStore } from '../../kernel/types.js'\nimport type { LedgerStore } from './ledger/store.js'\nimport { getHistory } from './history.js'\nimport { decrypt, type EnclaveKey } from '../../kernel/enclave/index.js'\nimport { ReadOnlyAtInstantError } from '../../kernel/errors.js'\n\n/**\n * Narrow view of a {@link Vault}'s internals that\n * {@link VaultInstant} needs. Passed in by `Vault.at()` rather than\n * constructed here so all crypto + adapter access stays inside the\n * Vault class.\n *\n * Not exported from the public barrel — consumers should get a\n * `VaultInstant` via `vault.at(ts)`, never by constructing one\n * directly.\n */\nexport interface VaultEngine {\n readonly adapter: NoydbStore\n /** Vault name (the compartment). */\n readonly name: string\n /**\n * `true` when the vault was opened with a passphrase (the normal\n * case). `false` in plaintext-mode vaults (`encrypt: false`) — in\n * that case `envelope._data` is raw JSON and we skip the DEK lookup.\n */\n readonly encrypted: boolean\n /**\n * Resolves the DEK used to decrypt a given collection's envelopes.\n * Not called when `encrypted` is false.\n */\n getDEK(collection: string): Promise<EnclaveKey>\n /**\n * Lazily-initialised ledger. We consult it to detect deletes that\n * happened between the latest history snapshot and the target\n * timestamp. `null` when history is disabled for this vault — in\n * that case time-machine reads fall back to history-only\n * reconstruction (which may miss deletes).\n */\n getLedger(): LedgerStore | null\n}\n\n/**\n * A vault at a fixed instant. Produced by `vault.at(timestamp)`.\n * Carries no session state of its own — every read is a fresh\n * lookup through the vault's adapter.\n *\n * Cheap to construct; safe to throw away. Create one per query.\n */\nexport class VaultInstant {\n constructor(\n private readonly engine: VaultEngine,\n /** Fully-resolved target timestamp (ISO-8601 UTC). */\n public readonly timestamp: string,\n ) {}\n\n /** Get a point-in-time view of a collection. */\n collection<T = unknown>(name: string): CollectionInstant<T> {\n return new CollectionInstant<T>(this.engine, this.timestamp, name)\n }\n}\n\n/**\n * A read-only collection view anchored to a past instant.\n *\n * Every write method throws {@link ReadOnlyAtInstantError} — see the\n * module docstring for why. The read surface is intentionally smaller\n * than the live {@link Collection}: `get` and `list` cover the\n * \"what did the books look like on date X\" use case without pulling\n * in the full query DSL / joins / aggregates at this stage. Follow-up\n * work tracked under.\n */\nexport class CollectionInstant<T = unknown> {\n constructor(\n private readonly engine: VaultEngine,\n private readonly targetTs: string,\n public readonly name: string,\n ) {}\n\n /**\n * Return the record as it existed at the target timestamp, or\n * `null` if the record had not been created yet or had already been\n * deleted by then.\n */\n async get(id: string): Promise<T | null> {\n const envelope = await this.resolveEnvelope(id)\n if (!envelope) return null\n const plaintext = this.engine.encrypted\n ? await decrypt(envelope._iv, envelope._data, await this.engine.getDEK(this.name))\n : envelope._data\n return JSON.parse(plaintext) as T\n }\n\n /**\n * IDs of records that existed (had at least one `put` and were not\n * subsequently deleted) at the target timestamp.\n *\n * Implemented as a linear scan over history + ledger. Performance\n * is bounded by total history size (not live-vault size), so the\n * memory-first vault-scale cap (1K–50K records × average history\n * depth) still applies.\n */\n async list(): Promise<string[]> {\n const historyIds = await collectHistoryIds(this.engine.adapter, this.engine.name, this.name)\n const liveIds = await this.engine.adapter.list(this.engine.name, this.name)\n const candidateIds = new Set<string>([...historyIds, ...liveIds])\n const alive: string[] = []\n for (const id of candidateIds) {\n const env = await this.resolveEnvelope(id)\n if (env) alive.push(id)\n }\n return alive.sort()\n }\n\n // ── write guards ───────────────────────────────────────────────────\n\n async put(_id: string, _record: T): Promise<never> {\n throw new ReadOnlyAtInstantError('put', this.targetTs)\n }\n async delete(_id: string): Promise<never> {\n throw new ReadOnlyAtInstantError('delete', this.targetTs)\n }\n async update(_id: string, _patch: Partial<T>): Promise<never> {\n throw new ReadOnlyAtInstantError('update', this.targetTs)\n }\n\n // ── internals ─────────────────────────────────────────────────────\n\n /**\n * Return the envelope that represents the record's state at\n * `targetTs`, accounting for deletes. `null` if the record didn't\n * exist at that instant.\n *\n * ## Why we use the ledger as the authoritative timeline\n *\n * The per-version history snapshots saved by `saveHistory()` do\n * carry a `_ts` field, but that timestamp is the moment the\n * snapshot was *captured* (i.e. the instant right before the\n * subsequent overwrite), not the original write time. The ledger,\n * by contrast, records `ts` at the moment of each `put` / `delete`\n * — it's the only source that tracks the real timeline. So:\n *\n * 1. Walk the ledger; find the latest entry for `(collection, id)`\n * with `ts ≤ targetTs`.\n * 2. If that entry is a `delete`, the record was gone at the\n * target instant — return null.\n * 3. Otherwise it's a `put` with a specific `version`. Load the\n * envelope for that version from history, falling back to the\n * live collection for the most recent version.\n *\n * ## Fallback when the ledger is disabled\n *\n * If the vault has history disabled, `getLedger()` returns null and\n * we fall back to comparing envelope `_ts` fields. This is\n * approximate and gets the *last write* right but may confuse the\n * intermediate versions; adopters needing accurate time-machine\n * reads should leave history enabled.\n */\n private async resolveEnvelope(id: string): Promise<EncryptedEnvelope | null> {\n const ledger = this.engine.getLedger()\n if (ledger) {\n return this.resolveViaLedger(id, ledger)\n }\n return this.resolveViaEnvelopeTs(id)\n }\n\n private async resolveViaLedger(id: string, ledger: LedgerStore): Promise<EncryptedEnvelope | null> {\n const entries = await ledger.entries()\n // Entries are already ordered by index which is the mutation order.\n let latest: { op: 'put' | 'delete'; version: number } | null = null\n for (const e of entries) {\n if (e.collection !== this.name || e.id !== id) continue\n if (e.ts > this.targetTs) break // entries are time-ordered by index\n // `amendment` + `lifecycle` entries are audit-only summaries — they\n // carry no (collection, id) tuple of their own and would never match\n // the filter above. The narrow here is a type guard, not a runtime\n // skip.\n // `forget` is a subject-erasure summary with empty (collection, id) —\n // never matches the filter above; the narrow is a type guard.\n if (e.op === 'amendment' || e.op === 'lifecycle' || e.op === 'forget') continue\n // `migration` is a record rewrite (cutover) — resolve it like a put.\n latest = { op: e.op === 'migration' ? 'put' : e.op, version: e.version }\n }\n if (!latest) return null\n if (latest.op === 'delete') return null\n return this.loadVersion(id, latest.version)\n }\n\n private async resolveViaEnvelopeTs(id: string): Promise<EncryptedEnvelope | null> {\n const history = await getHistory(\n this.engine.adapter, this.engine.name, this.name, id,\n )\n const live = await this.engine.adapter.get(this.engine.name, this.name, id)\n const byVersion = new Map<number, EncryptedEnvelope>()\n for (const e of history) byVersion.set(e._v, e)\n if (live) byVersion.set(live._v, live)\n const sorted = [...byVersion.values()].sort((a, b) =>\n a._ts < b._ts ? 1 : a._ts > b._ts ? -1 : 0,\n )\n return sorted.find((e) => e._ts <= this.targetTs) ?? null\n }\n\n /**\n * Fetch the envelope for a specific version. The live record (most\n * recent put) lives in the main collection; prior versions live in\n * `_history`. We check live first because the common case after a\n * delete is that we're trying to load the last-live version from\n * history, and skipping live for the current-version case avoids a\n * redundant lookup.\n */\n private async loadVersion(id: string, version: number): Promise<EncryptedEnvelope | null> {\n const live = await this.engine.adapter.get(this.engine.name, this.name, id)\n if (live && live._v === version) return live\n\n // Direct lookup by (collection, id, version) — avoids scanning all history.\n const historyId = `${this.name}:${id}:${String(version).padStart(10, '0')}`\n return await this.engine.adapter.get(this.engine.name, '_history', historyId)\n }\n}\n\n/**\n * Scan the `_history` collection once and collect every distinct\n * `recordId` for the given collection. History keys follow the\n * shape `<collection>:<recordId>:<paddedVersion>`; we split on the\n * last two colons (delimiter-safe because `paddedVersion` is\n * exactly 10 digits).\n */\nasync function collectHistoryIds(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n): Promise<string[]> {\n const all = await adapter.list(vault, '_history')\n const prefix = `${collection}:`\n const seen = new Set<string>()\n for (const key of all) {\n if (!key.startsWith(prefix)) continue\n const lastColon = key.lastIndexOf(':')\n if (lastColon <= prefix.length) continue\n const middle = key.slice(prefix.length, lastColon)\n seen.add(middle)\n }\n return [...seen]\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAM,qBAAqB;AAC3B,IAAM,cAAc;AAEpB,SAAS,UAAU,YAAoB,UAAkB,SAAyB;AAChF,SAAO,GAAG,UAAU,IAAI,QAAQ,IAAI,OAAO,OAAO,EAAE,SAAS,aAAa,GAAG,CAAC;AAChF;AAkBA,SAAS,cAAc,IAAY,YAAoB,UAA4B;AACjF,MAAI,UAAU;AACZ,WAAO,GAAG,WAAW,GAAG,UAAU,IAAI,QAAQ,GAAG;AAAA,EACnD;AACA,SAAO,GAAG,WAAW,GAAG,UAAU,GAAG;AACvC;AAGA,eAAsB,YACpB,SACA,OACA,YACA,UACA,UACe;AACf,QAAM,KAAK,UAAU,YAAY,UAAU,SAAS,EAAE;AACtD,QAAM,QAAQ,IAAI,OAAO,oBAAoB,IAAI,QAAQ;AAC3D;AAGA,eAAsB,WACpB,SACA,OACA,YACA,UACA,SAC8B;AAC9B,QAAM,SAAS,MAAM,QAAQ,KAAK,OAAO,kBAAkB;AAC3D,QAAM,cAAc,OACjB,OAAO,QAAM,cAAc,IAAI,YAAY,QAAQ,CAAC,EACpD,KAAK,EACL,QAAQ;AAEX,QAAM,UAA+B,CAAC;AAEtC,aAAW,MAAM,aAAa;AAC5B,UAAM,WAAW,MAAM,QAAQ,IAAI,OAAO,oBAAoB,EAAE;AAChE,QAAI,CAAC,SAAU;AAGf,QAAI,SAAS,QAAQ,SAAS,MAAM,QAAQ,KAAM;AAClD,QAAI,SAAS,MAAM,SAAS,MAAM,QAAQ,GAAI;AAE9C,YAAQ,KAAK,QAAQ;AAErB,QAAI,SAAS,SAAS,QAAQ,UAAU,QAAQ,MAAO;AAAA,EACzD;AAEA,SAAO;AACT;AAGA,eAA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A;AAAA;AAAA;AAAA;AAAA,EAUA,MAAc,YAAY,IAAY,SAAoD;AACxF,UAAM,OAAO,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,MAAM,KAAK,MAAM,EAAE;AAC1E,QAAI,QAAQ,KAAK,OAAO,QAAS,QAAO;AAGxC,UAAMA,aAAY,GAAG,KAAK,IAAI,IAAI,EAAE,IAAI,OAAO,OAAO,EAAE,SAAS,IAAI,GAAG,CAAC;AACzE,WAAO,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,MAAM,YAAYA,UAAS;AAAA,EAC9E;AACF;AASA,eAAe,kBACb,SACA,OACA,YACmB;AACnB,QAAM,MAAM,MAAM,QAAQ,KAAK,OAAO,UAAU;AAChD,QAAM,SAAS,GAAG,UAAU;AAC5B,QAAM,OAAO,oBAAI,IAAY;AAC7B,aAAW,OAAO,KAAK;AACrB,QAAI,CAAC,IAAI,WAAW,MAAM,EAAG;AAC7B,UAAM,YAAY,IAAI,YAAY,GAAG;AACrC,QAAI,aAAa,OAAO,OAAQ;AAChC,UAAM,SAAS,IAAI,MAAM,OAAO,QAAQ,SAAS;AACjD,SAAK,IAAI,MAAM;AAAA,EACjB;AACA,SAAO,CAAC,GAAG,IAAI;AACjB;","names":["historyId"]}
|
|
1
|
+
{"version":3,"sources":["../src/with-commit/history/history.ts","../src/with-commit/history/time-machine.ts"],"sourcesContent":["import type { NoydbStore, EncryptedEnvelope, HistoryOptions, PruneOptions } from '../../kernel/types.js'\nimport { NOYDB_FORMAT_VERSION } from '../../kernel/types.js'\nimport { isTombstone } from '../../kernel/enclave/index.js'\n\n/**\n * History storage convention:\n * Collection: `_history`\n * ID format: `{collection}:{recordId}:{paddedVersion}`\n * Version is zero-padded to 10 digits for lexicographic sorting.\n */\n\nconst HISTORY_COLLECTION = '_history'\nconst VERSION_PAD = 10\n\nfunction historyId(collection: string, recordId: string, version: number): string {\n return `${collection}:${recordId}:${String(version).padStart(VERSION_PAD, '0')}`\n}\n\n// Unused today, kept for future history-id parsing utilities.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction parseHistoryId(id: string): { collection: string; recordId: string; version: number } | null {\n const lastColon = id.lastIndexOf(':')\n if (lastColon < 0) return null\n const versionStr = id.slice(lastColon + 1)\n const rest = id.slice(0, lastColon)\n const firstColon = rest.indexOf(':')\n if (firstColon < 0) return null\n return {\n collection: rest.slice(0, firstColon),\n recordId: rest.slice(firstColon + 1),\n version: parseInt(versionStr, 10),\n }\n}\n\nfunction matchesPrefix(id: string, collection: string, recordId?: string): boolean {\n if (recordId) {\n return id.startsWith(`${collection}:${recordId}:`)\n }\n return id.startsWith(`${collection}:`)\n}\n\n/** Save a history entry (a complete encrypted envelope snapshot). */\nexport async function saveHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n envelope: EncryptedEnvelope,\n): Promise<void> {\n const id = historyId(collection, recordId, envelope._v)\n await adapter.put(vault, HISTORY_COLLECTION, id, envelope)\n}\n\n/** Get history entries for a record, sorted newest-first. */\nexport async function getHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n options?: HistoryOptions,\n): Promise<EncryptedEnvelope[]> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n const matchingIds = allIds\n .filter(id => matchesPrefix(id, collection, recordId))\n .sort()\n .reverse() // newest first\n\n const entries: EncryptedEnvelope[] = []\n\n for (const id of matchingIds) {\n const envelope = await adapter.get(vault, HISTORY_COLLECTION, id)\n if (!envelope) continue\n\n // Apply time filters\n if (options?.from && envelope._ts < options.from) continue\n if (options?.to && envelope._ts > options.to) continue\n\n entries.push(envelope)\n\n if (options?.limit && entries.length >= options.limit) break\n }\n\n return entries\n}\n\n/** Get a specific version's envelope from history. */\nexport async function getVersionEnvelope(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n version: number,\n): Promise<EncryptedEnvelope | null> {\n const id = historyId(collection, recordId, version)\n return adapter.get(vault, HISTORY_COLLECTION, id)\n}\n\n/** Prune history entries. Returns the number of entries deleted. */\nexport async function pruneHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string | undefined,\n options: PruneOptions,\n): Promise<number> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n const matchingIds = allIds\n .filter(id => recordId ? matchesPrefix(id, collection, recordId) : matchesPrefix(id, collection))\n .sort()\n\n let toDelete: string[] = []\n\n if (options.keepVersions !== undefined) {\n // Keep only the N most recent, delete the rest\n const keep = options.keepVersions\n if (matchingIds.length > keep) {\n toDelete = matchingIds.slice(0, matchingIds.length - keep)\n }\n }\n\n if (options.beforeDate) {\n // Delete entries older than the specified date\n for (const id of matchingIds) {\n if (toDelete.includes(id)) continue\n const envelope = await adapter.get(vault, HISTORY_COLLECTION, id)\n if (envelope && envelope._ts < options.beforeDate) {\n toDelete.push(id)\n }\n }\n }\n\n // Deduplicate\n const uniqueDeletes = [...new Set(toDelete)]\n\n for (const id of uniqueDeletes) {\n await adapter.delete(vault, HISTORY_COLLECTION, id)\n }\n\n return uniqueDeletes.length\n}\n\n/** Clear all history for a vault, optionally scoped to a collection or record. */\nexport async function clearHistory(\n adapter: NoydbStore,\n vault: string,\n collection?: string,\n recordId?: string,\n): Promise<number> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n let toDelete: string[]\n\n if (collection && recordId) {\n toDelete = allIds.filter(id => matchesPrefix(id, collection, recordId))\n } else if (collection) {\n toDelete = allIds.filter(id => matchesPrefix(id, collection))\n } else {\n toDelete = allIds\n }\n\n for (const id of toDelete) {\n await adapter.delete(vault, HISTORY_COLLECTION, id)\n }\n\n return toDelete.length\n}\n\n/**\n * Crypto-shred every `_history` version of a record. Each non-tombstone\n * history envelope is OVERWRITTEN in place with a tombstone\n * `{ _noydb, _v, _ts: now, _by: actor, _iv: '', _data: '' }` — dropping\n * `_iv`/`_data`/`_cek`/`_det`, so the prior ciphertext (and the wrapped CEK\n * that could decrypt it) is gone everywhere this store reaches. The version\n * counter (`_v`) is preserved so the audit trail still shows \"N versions\n * existed and were erased.\"\n *\n * Overwrite — NOT delete — so the history key itself survives as proof the\n * version existed. Already-tombstoned versions (re-run / idempotent forget)\n * are left untouched and not counted.\n *\n * Returns the number of history versions newly tombstoned.\n */\nexport async function tombstoneHistory(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n recordId: string,\n actor: string,\n encrypted: boolean,\n): Promise<number> {\n const allIds = await adapter.list(vault, HISTORY_COLLECTION)\n const matchingIds = allIds.filter(id => matchesPrefix(id, collection, recordId))\n\n const now = new Date().toISOString()\n let count = 0\n for (const id of matchingIds) {\n const env = await adapter.get(vault, HISTORY_COLLECTION, id)\n if (!env) continue\n // Already a tombstone (no body and no wrapped CEK)? Skip — idempotent.\n if (isTombstone(env, encrypted)) continue\n const tombstone: EncryptedEnvelope = {\n _noydb: NOYDB_FORMAT_VERSION,\n _v: env._v,\n _ts: now,\n _iv: '',\n _data: '',\n ...(actor ? { _by: actor } : {}),\n }\n await adapter.put(vault, HISTORY_COLLECTION, id, tombstone)\n count++\n }\n return count\n}\n","/**\n * Time-machine queries — point-in-time reads reconstructed from the\n * existing history + ledger infrastructure.\n *\n * ## Usage\n *\n * ```ts\n * const vault = await db.openVault('acme', { passphrase })\n * const q1End = vault.at('2026-03-31T23:59:59Z')\n * const invoice = await q1End.collection<Invoice>('invoices').get('inv-001')\n * // → the record as it stood at the close of Q1 2026\n * ```\n *\n * ## How it works\n *\n * Every write path already fans out into two persistence lanes:\n *\n * 1. `saveHistory(...)` persists a **full encrypted envelope snapshot**\n * per version under the `_history` collection (one envelope per\n * version, keyed by `{collection}:{id}:{paddedVersion}`). Each\n * envelope carries its own `_ts` (the write timestamp).\n * 2. `ledger.append(...)` appends a hash-chained audit entry that\n * records the `op` (put / delete), `version`, and `ts`.\n *\n * Reconstruction at a target timestamp T is therefore:\n *\n * - Find the newest history envelope for `(collection, id)` whose\n * `_ts ≤ T` — that's the state the record was in at T.\n * - Check the ledger for any `op: 'delete'` entry for the same\n * `(collection, id)` with `entry.ts` in `(latestEnvelope._ts, T]` —\n * if present, the record was deleted before T, so return `null`.\n * - Decrypt the surviving envelope with the current collection DEK\n * (DEKs are per-collection but stable across versions — the same\n * key encrypts v1 and v15 of a record).\n *\n * No delta replay. The existing `history.ts` module already stores\n * complete snapshots; we just pick the right one.\n *\n * ## Read-only contract\n *\n * Every write method on `CollectionInstant` throws\n * {@link ReadOnlyAtInstantError}. A historical view is a *read*\n * surface — mutating the past would require either a branch/shadow\n * mechanism (tracked under shadow vaults) or a rewrite of\n * history, which breaks the ledger's tamper-evidence guarantee.\n *\n * @module\n */\nimport type { EncryptedEnvelope, NoydbStore } from '../../kernel/types.js'\nimport type { LedgerStore } from './ledger/store.js'\nimport { getHistory } from './history.js'\nimport { decrypt, type EnclaveKey } from '../../kernel/enclave/index.js'\nimport { ReadOnlyAtInstantError } from '../../kernel/errors.js'\n\n/**\n * Narrow view of a {@link Vault}'s internals that\n * {@link VaultInstant} needs. Passed in by `Vault.at()` rather than\n * constructed here so all crypto + adapter access stays inside the\n * Vault class.\n *\n * Not exported from the public barrel — consumers should get a\n * `VaultInstant` via `vault.at(ts)`, never by constructing one\n * directly.\n */\nexport interface VaultEngine {\n readonly adapter: NoydbStore\n /** Vault name (the compartment). */\n readonly name: string\n /**\n * `true` when the vault was opened with a passphrase (the normal\n * case). `false` in plaintext-mode vaults (`encrypt: false`) — in\n * that case `envelope._data` is raw JSON and we skip the DEK lookup.\n */\n readonly encrypted: boolean\n /**\n * Resolves the DEK used to decrypt a given collection's envelopes.\n * Not called when `encrypted` is false.\n */\n getDEK(collection: string): Promise<EnclaveKey>\n /**\n * Lazily-initialised ledger. We consult it to detect deletes that\n * happened between the latest history snapshot and the target\n * timestamp. `null` when history is disabled for this vault — in\n * that case time-machine reads fall back to history-only\n * reconstruction (which may miss deletes).\n */\n getLedger(): LedgerStore | null\n}\n\n/**\n * A vault at a fixed instant. Produced by `vault.at(timestamp)`.\n * Carries no session state of its own — every read is a fresh\n * lookup through the vault's adapter.\n *\n * Cheap to construct; safe to throw away. Create one per query.\n */\nexport class VaultInstant {\n constructor(\n private readonly engine: VaultEngine,\n /** Fully-resolved target timestamp (ISO-8601 UTC). */\n public readonly timestamp: string,\n ) {}\n\n /** Get a point-in-time view of a collection. */\n collection<T = unknown>(name: string): CollectionInstant<T> {\n return new CollectionInstant<T>(this.engine, this.timestamp, name)\n }\n}\n\n/**\n * A read-only collection view anchored to a past instant.\n *\n * Every write method throws {@link ReadOnlyAtInstantError} — see the\n * module docstring for why. The read surface is intentionally smaller\n * than the live {@link Collection}: `get` and `list` cover the\n * \"what did the books look like on date X\" use case without pulling\n * in the full query DSL / joins / aggregates at this stage. Follow-up\n * work tracked under.\n */\nexport class CollectionInstant<T = unknown> {\n constructor(\n private readonly engine: VaultEngine,\n private readonly targetTs: string,\n public readonly name: string,\n ) {}\n\n /**\n * Return the record as it existed at the target timestamp, or\n * `null` if the record had not been created yet or had already been\n * deleted by then.\n */\n async get(id: string): Promise<T | null> {\n const envelope = await this.resolveEnvelope(id)\n if (!envelope) return null\n const plaintext = this.engine.encrypted\n ? await decrypt(envelope._iv, envelope._data, await this.engine.getDEK(this.name))\n : envelope._data\n return JSON.parse(plaintext) as T\n }\n\n /**\n * IDs of records that existed (had at least one `put` and were not\n * subsequently deleted) at the target timestamp.\n *\n * Implemented as a linear scan over history + ledger. Performance\n * is bounded by total history size (not live-vault size), so the\n * memory-first vault-scale cap (1K–50K records × average history\n * depth) still applies.\n */\n async list(): Promise<string[]> {\n const historyIds = await collectHistoryIds(this.engine.adapter, this.engine.name, this.name)\n const liveIds = await this.engine.adapter.list(this.engine.name, this.name)\n const candidateIds = new Set<string>([...historyIds, ...liveIds])\n const alive: string[] = []\n for (const id of candidateIds) {\n const env = await this.resolveEnvelope(id)\n if (env) alive.push(id)\n }\n return alive.sort()\n }\n\n // ── write guards ───────────────────────────────────────────────────\n\n async put(_id: string, _record: T): Promise<never> {\n throw new ReadOnlyAtInstantError('put', this.targetTs)\n }\n async delete(_id: string): Promise<never> {\n throw new ReadOnlyAtInstantError('delete', this.targetTs)\n }\n async update(_id: string, _patch: Partial<T>): Promise<never> {\n throw new ReadOnlyAtInstantError('update', this.targetTs)\n }\n\n // ── internals ─────────────────────────────────────────────────────\n\n /**\n * Return the envelope that represents the record's state at\n * `targetTs`, accounting for deletes. `null` if the record didn't\n * exist at that instant.\n *\n * ## Why we use the ledger as the authoritative timeline\n *\n * The per-version history snapshots saved by `saveHistory()` do\n * carry a `_ts` field, but that timestamp is the moment the\n * snapshot was *captured* (i.e. the instant right before the\n * subsequent overwrite), not the original write time. The ledger,\n * by contrast, records `ts` at the moment of each `put` / `delete`\n * — it's the only source that tracks the real timeline. So:\n *\n * 1. Walk the ledger; find the latest entry for `(collection, id)`\n * with `ts ≤ targetTs`.\n * 2. If that entry is a `delete`, the record was gone at the\n * target instant — return null.\n * 3. Otherwise it's a `put` with a specific `version`. Load the\n * envelope for that version from history, falling back to the\n * live collection for the most recent version.\n *\n * ## Fallback when the ledger is disabled\n *\n * If the vault has history disabled, `getLedger()` returns null and\n * we fall back to comparing envelope `_ts` fields. This is\n * approximate and gets the *last write* right but may confuse the\n * intermediate versions; adopters needing accurate time-machine\n * reads should leave history enabled.\n */\n private async resolveEnvelope(id: string): Promise<EncryptedEnvelope | null> {\n const ledger = this.engine.getLedger()\n if (ledger) {\n return this.resolveViaLedger(id, ledger)\n }\n return this.resolveViaEnvelopeTs(id)\n }\n\n private async resolveViaLedger(id: string, ledger: LedgerStore): Promise<EncryptedEnvelope | null> {\n const entries = await ledger.entries()\n // Entries are already ordered by index which is the mutation order.\n let latest: { op: 'put' | 'delete'; version: number } | null = null\n for (const e of entries) {\n if (e.collection !== this.name || e.id !== id) continue\n if (e.ts > this.targetTs) break // entries are time-ordered by index\n // `amendment` + `lifecycle` entries are audit-only summaries — they\n // carry no (collection, id) tuple of their own and would never match\n // the filter above. The narrow here is a type guard, not a runtime\n // skip.\n // `forget` is a subject-erasure summary with empty (collection, id) —\n // never matches the filter above; the narrow is a type guard.\n if (e.op === 'amendment' || e.op === 'lifecycle' || e.op === 'forget') continue\n // `migration` is a record rewrite (cutover) — resolve it like a put.\n latest = { op: e.op === 'migration' ? 'put' : e.op, version: e.version }\n }\n if (!latest) return null\n if (latest.op === 'delete') return null\n return this.loadVersion(id, latest.version)\n }\n\n private async resolveViaEnvelopeTs(id: string): Promise<EncryptedEnvelope | null> {\n const history = await getHistory(\n this.engine.adapter, this.engine.name, this.name, id,\n )\n const live = await this.engine.adapter.get(this.engine.name, this.name, id)\n const byVersion = new Map<number, EncryptedEnvelope>()\n for (const e of history) byVersion.set(e._v, e)\n if (live) byVersion.set(live._v, live)\n const sorted = [...byVersion.values()].sort((a, b) =>\n a._ts < b._ts ? 1 : a._ts > b._ts ? -1 : 0,\n )\n return sorted.find((e) => e._ts <= this.targetTs) ?? null\n }\n\n /**\n * Fetch the envelope for a specific version. The live record (most\n * recent put) lives in the main collection; prior versions live in\n * `_history`. We check live first because the common case after a\n * delete is that we're trying to load the last-live version from\n * history, and skipping live for the current-version case avoids a\n * redundant lookup.\n */\n private async loadVersion(id: string, version: number): Promise<EncryptedEnvelope | null> {\n const live = await this.engine.adapter.get(this.engine.name, this.name, id)\n if (live && live._v === version) return live\n\n // Direct lookup by (collection, id, version) — avoids scanning all history.\n const historyId = `${this.name}:${id}:${String(version).padStart(10, '0')}`\n return await this.engine.adapter.get(this.engine.name, '_history', historyId)\n }\n}\n\n/**\n * Scan the `_history` collection once and collect every distinct\n * `recordId` for the given collection. History keys follow the\n * shape `<collection>:<recordId>:<paddedVersion>`; we split on the\n * last two colons (delimiter-safe because `paddedVersion` is\n * exactly 10 digits).\n */\nasync function collectHistoryIds(\n adapter: NoydbStore,\n vault: string,\n collection: string,\n): Promise<string[]> {\n const all = await adapter.list(vault, '_history')\n const prefix = `${collection}:`\n const seen = new Set<string>()\n for (const key of all) {\n if (!key.startsWith(prefix)) continue\n const lastColon = key.lastIndexOf(':')\n if (lastColon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IAAI,KAAK,OAAO,MAAM,KAAK,MAAM,EAAE;AAC1E,QAAI,QAAQ,KAAK,OAAO,QAAS,QAAO;AAGxC,UAAMA,aAAY,GAAG,KAAK,IAAI,IAAI,EAAE,IAAI,OAAO,OAAO,EAAE,SAAS,IAAI,GAAG,CAAC;AACzE,WAAO,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,MAAM,YAAYA,UAAS;AAAA,EAC9E;AACF;AASA,eAAe,kBACb,SACA,OACA,YACmB;AACnB,QAAM,MAAM,MAAM,QAAQ,KAAK,OAAO,UAAU;AAChD,QAAM,SAAS,GAAG,UAAU;AAC5B,QAAM,OAAO,oBAAI,IAAY;AAC7B,aAAW,OAAO,KAAK;AACrB,QAAI,CAAC,IAAI,WAAW,MAAM,EAAG;AAC7B,UAAM,YAAY,IAAI,YAAY,GAAG;AACrC,QAAI,aAAa,OAAO,OAAQ;AAChC,UAAM,SAAS,IAAI,MAAM,OAAO,QAAQ,SAAS;AACjD,SAAK,IAAI,MAAM;AAAA,EACjB;AACA,SAAO,CAAC,GAAG,IAAI;AACjB;","names":["historyId"]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
readDirectoryConfig,
|
|
6
6
|
readUserVisibility,
|
|
7
7
|
saveUserEnvelope
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OVYRLHPE.js";
|
|
9
9
|
import {
|
|
10
10
|
base64ToBuffer,
|
|
11
11
|
bufferToBase64,
|
|
@@ -16,11 +16,11 @@ import {
|
|
|
16
16
|
generateSalt,
|
|
17
17
|
unwrapKey,
|
|
18
18
|
wrapKey
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-3OPY6MK2.js";
|
|
20
20
|
import {
|
|
21
21
|
NOYDB_FORMAT_VERSION,
|
|
22
22
|
NOYDB_KEYRING_VERSION
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-YN5IAHN6.js";
|
|
24
24
|
import {
|
|
25
25
|
DirectoryDisabledError,
|
|
26
26
|
InvalidKeyError,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
PrivilegeEscalationError,
|
|
33
33
|
USER_ENVELOPE_COLLECTION,
|
|
34
34
|
ValidationError
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-S7VFUQM2.js";
|
|
36
36
|
|
|
37
37
|
// src/kernel/validation.ts
|
|
38
38
|
var WeakPassphraseError = class extends NoydbError {
|
|
@@ -106,6 +106,17 @@ function estimateEntropy(passphrase) {
|
|
|
106
106
|
return Math.round(result.words * Math.log2(7776));
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
// src/with-party/team/reserved-secret-collections.ts
|
|
110
|
+
var SYNC_CREDENTIALS_COLLECTION = "_sync_credentials";
|
|
111
|
+
var BROKER_COLLECTION = "_broker";
|
|
112
|
+
var SECRET_BEARING_RESERVED_COLLECTIONS = /* @__PURE__ */ new Set([
|
|
113
|
+
SYNC_CREDENTIALS_COLLECTION,
|
|
114
|
+
BROKER_COLLECTION
|
|
115
|
+
]);
|
|
116
|
+
function isSecretBearingReservedCollection(name) {
|
|
117
|
+
return SECRET_BEARING_RESERVED_COLLECTIONS.has(name);
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
// src/with-party/team/keyring.ts
|
|
110
121
|
var ADMIN_GRANTABLE_TARGETS = ["operator", "viewer", "client", "admin"];
|
|
111
122
|
function canGrant(callerRole, targetRole) {
|
|
@@ -276,8 +287,10 @@ async function grant(adapter, vault, callerKeyring, options) {
|
|
|
276
287
|
const permissions = resolvePermissions(options.role, options.permissions);
|
|
277
288
|
const newSalt = generateSalt();
|
|
278
289
|
const newKek = await deriveKey(options.passphrase, newSalt);
|
|
290
|
+
const granteeMayHoldSecrets = options.role === "owner" || options.role === "admin";
|
|
279
291
|
const wrappedDeks = {};
|
|
280
292
|
for (const collName of Object.keys(permissions)) {
|
|
293
|
+
if (isSecretBearingReservedCollection(collName) && !granteeMayHoldSecrets) continue;
|
|
281
294
|
const dek = callerKeyring.deks.get(collName);
|
|
282
295
|
if (dek) {
|
|
283
296
|
wrappedDeks[collName] = await wrapKey(dek, newKek);
|
|
@@ -285,15 +298,15 @@ async function grant(adapter, vault, callerKeyring, options) {
|
|
|
285
298
|
}
|
|
286
299
|
if (options.role === "owner" || options.role === "admin" || options.role === "custodian" || options.role === "viewer") {
|
|
287
300
|
for (const [collName, dek] of callerKeyring.deks) {
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
301
|
+
if (collName in wrappedDeks) continue;
|
|
302
|
+
if (isSecretBearingReservedCollection(collName) && !granteeMayHoldSecrets) continue;
|
|
303
|
+
wrappedDeks[collName] = await wrapKey(dek, newKek);
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
306
|
for (const [collName, dek] of callerKeyring.deks) {
|
|
294
|
-
if (collName.startsWith("_")
|
|
295
|
-
|
|
296
|
-
|
|
307
|
+
if (!collName.startsWith("_") || collName in wrappedDeks) continue;
|
|
308
|
+
if (isSecretBearingReservedCollection(collName) && !granteeMayHoldSecrets) continue;
|
|
309
|
+
wrappedDeks[collName] = await wrapKey(dek, newKek);
|
|
297
310
|
}
|
|
298
311
|
for (const collName of Object.keys(wrappedDeks)) {
|
|
299
312
|
if (!callerKeyring.deks.has(collName)) {
|
|
@@ -738,6 +751,8 @@ export {
|
|
|
738
751
|
validatePassphrase,
|
|
739
752
|
assertStrongPassphrase,
|
|
740
753
|
estimateEntropy,
|
|
754
|
+
SYNC_CREDENTIALS_COLLECTION,
|
|
755
|
+
isSecretBearingReservedCollection,
|
|
741
756
|
mintKeyringCanary,
|
|
742
757
|
loadKeyring,
|
|
743
758
|
assertKeyringOpenAllowed,
|
|
@@ -759,4 +774,4 @@ export {
|
|
|
759
774
|
hasImportCapability,
|
|
760
775
|
evaluateImportCapability
|
|
761
776
|
};
|
|
762
|
-
//# sourceMappingURL=chunk-
|
|
777
|
+
//# sourceMappingURL=chunk-J4LPNIGK.js.map
|