@noy-db/hub 0.10.0-pre.1 → 0.10.0-pre.2
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/CHANGELOG.md +81 -0
- package/dist/api-QSEKT4KS.js +15 -0
- package/dist/as/index.js +19 -12
- package/dist/as/index.js.map +1 -1
- package/dist/at/index.js +6 -9
- package/dist/attestation/index.js +16 -19
- package/dist/attestation/index.js.map +1 -1
- package/dist/{backup-6EKBNC67.js → backup-BHKVK5SD.js} +9 -12
- package/dist/{backup-6EKBNC67.js.map → backup-BHKVK5SD.js.map} +1 -1
- package/dist/blobs/index.js +10 -13
- package/dist/blobs/index.js.map +1 -1
- package/dist/broker/index.js +11 -14
- package/dist/broker/index.js.map +1 -1
- package/dist/by/index.js +2 -2
- package/dist/capsule/contract.d.ts +176 -16
- package/dist/capsule/contract.js +35 -30
- package/dist/capsule/enclave-aes/bound.d.ts +11 -1
- package/dist/capsule/enclave-aes/classify/digest.d.ts +4 -2
- package/dist/capsule/enclave-aes/index.d.ts +9 -0
- package/dist/capsule/enclave-aes/index.js +643 -78
- package/dist/capsule/enclave-aes/index.js.map +1 -1
- package/dist/capsule/enclave-aes/primitives.d.ts +2 -2
- package/dist/capsule/index.d.ts +1 -1
- package/dist/capsule/plumbing/classify-reveal.d.ts +29 -0
- package/dist/capsule/plumbing/classify-verify.d.ts +53 -0
- package/dist/capsule/plumbing/index.d.ts +17 -0
- package/dist/{capsule-QJJFUUSH.js → capsule-YAITMH77.js} +16 -9
- package/dist/cargo/index.js +34 -36
- package/dist/{chunk-J57OMNJ4.js → chunk-23A4SBRR.js} +3 -4
- package/dist/{chunk-J57OMNJ4.js.map → chunk-23A4SBRR.js.map} +1 -1
- package/dist/{chunk-E3CUGBGW.js → chunk-24AGG4PP.js} +3 -3
- package/dist/{chunk-M2VLXPRU.js → chunk-24IJZA4M.js} +14 -8
- package/dist/chunk-24IJZA4M.js.map +1 -0
- package/dist/{chunk-BCJAUHSG.js → chunk-2NVQ5SEA.js} +15 -5
- package/dist/chunk-2NVQ5SEA.js.map +1 -0
- package/dist/{chunk-MRVQKRXI.js → chunk-2SIREKBR.js} +2 -2
- package/dist/{chunk-CE443VXM.js → chunk-37FOG6AE.js} +14 -7
- package/dist/chunk-37FOG6AE.js.map +1 -0
- package/dist/{chunk-ZZZVNHN2.js → chunk-3M2KK7O7.js} +3 -3
- package/dist/{chunk-P6FATPXQ.js → chunk-3ZCVY3T6.js} +2 -2
- package/dist/{chunk-I7NDTNHK.js → chunk-4CGWLHPQ.js} +6 -6
- package/dist/{chunk-PVQIME6P.js → chunk-56Z4NOC6.js} +3 -3
- package/dist/{chunk-XBG6YJPK.js → chunk-5AVIUJP4.js} +11 -9
- package/dist/{chunk-XBG6YJPK.js.map → chunk-5AVIUJP4.js.map} +1 -1
- package/dist/{chunk-HQFTE3DX.js → chunk-5BGHAVBN.js} +2 -2
- package/dist/{chunk-QHG7GQKM.js → chunk-5JNEDW7I.js} +2 -2
- package/dist/{chunk-NC6CF37L.js → chunk-5OWJSDTO.js} +4 -4
- package/dist/{chunk-NC6CF37L.js.map → chunk-5OWJSDTO.js.map} +1 -1
- package/dist/{chunk-YAYDDYRU.js → chunk-5Y4MO7UQ.js} +4 -4
- package/dist/{chunk-TLIFNRU5.js → chunk-63LZLRWG.js} +2 -2
- package/dist/{chunk-BUFFPAR2.js → chunk-74W56QPY.js} +4 -4
- package/dist/{chunk-VPG2UJYR.js → chunk-7KNYLHVX.js} +3 -3
- package/dist/chunk-7KNYLHVX.js.map +1 -0
- package/dist/{chunk-LFUID7OW.js → chunk-7VJ2SIEI.js} +42 -22
- package/dist/chunk-7VJ2SIEI.js.map +1 -0
- package/dist/{chunk-U2N7DH4S.js → chunk-AHA7UALU.js} +4 -4
- package/dist/{chunk-NB2DYYZL.js → chunk-AIHBYQHF.js} +254 -118
- package/dist/chunk-AIHBYQHF.js.map +1 -0
- package/dist/{chunk-RNQ7V4LH.js → chunk-ANYX2M6P.js} +3 -3
- package/dist/{chunk-VFGLMRO2.js → chunk-ATKYMRBC.js} +4 -4
- package/dist/{chunk-7UHLO4ZN.js → chunk-B2HU55QD.js} +2 -2
- package/dist/{chunk-RKOXA5GZ.js → chunk-BEKMLYQ4.js} +4 -4
- package/dist/{chunk-AYUMAPOS.js → chunk-BPFXD4EX.js} +23 -3
- package/dist/chunk-BPFXD4EX.js.map +1 -0
- package/dist/{chunk-R4PDYYK5.js → chunk-C2NXAR3D.js} +5 -5
- package/dist/{chunk-XBOGGTUJ.js → chunk-CJBWJO5P.js} +6 -6
- package/dist/{chunk-XBOGGTUJ.js.map → chunk-CJBWJO5P.js.map} +1 -1
- package/dist/{chunk-44CU4N7N.js → chunk-CQLMRCKX.js} +2 -2
- package/dist/{chunk-VUBRHJ4H.js → chunk-CR5UPYIJ.js} +1 -1
- package/dist/chunk-CR5UPYIJ.js.map +1 -0
- package/dist/{chunk-4XXRPSPS.js → chunk-DS2JXSUA.js} +6 -6
- package/dist/{chunk-X6Z2SIRF.js → chunk-E2JIE4S3.js} +2 -2
- package/dist/{chunk-EQ6C2ZPT.js → chunk-E7Y4J4GL.js} +2 -2
- package/dist/{chunk-ZMDSBTFT.js → chunk-ECDM6YRX.js} +2 -2
- package/dist/{chunk-WRLWEYHY.js → chunk-EFINFZIF.js} +11 -1
- package/dist/chunk-EFINFZIF.js.map +1 -0
- package/dist/{chunk-JM72WDAY.js → chunk-EM56MHN5.js} +6 -6
- package/dist/{chunk-YWJMM2WY.js → chunk-EQXOJH6O.js} +4 -4
- package/dist/{chunk-ME6LY5UG.js → chunk-ET3U2C3A.js} +2 -2
- package/dist/{chunk-G2KLVCKO.js → chunk-EU4G7PQH.js} +2 -2
- package/dist/{chunk-WJXLTO43.js → chunk-EUCUYK5E.js} +10 -10
- package/dist/{chunk-EPMX3SCC.js → chunk-EWSIJDWO.js} +4 -4
- package/dist/{chunk-KFYUQMF5.js → chunk-F2FD4LSB.js} +2 -2
- package/dist/{chunk-L4UL4IAR.js → chunk-F7ENMZYJ.js} +2 -2
- package/dist/{chunk-5OG7YQX5.js → chunk-FIIVYQOW.js} +5 -5
- package/dist/{chunk-4RF7DVH2.js → chunk-FPK2LPLR.js} +8 -8
- package/dist/chunk-FPK2LPLR.js.map +1 -0
- package/dist/{chunk-2EF2Z4UN.js → chunk-FQEUJGBV.js} +2 -2
- package/dist/{chunk-UORWAG7K.js → chunk-FY4FFNKK.js} +2 -2
- package/dist/{chunk-WA4ZPMKP.js → chunk-GDCYZGPB.js} +2 -2
- package/dist/{chunk-3HDBDUX2.js → chunk-H6Q7GKLI.js} +2 -2
- package/dist/{chunk-654RE5YC.js → chunk-HDAPQF6Q.js} +3 -3
- package/dist/{chunk-B5PWQMZN.js → chunk-HRLMUZLI.js} +5 -5
- package/dist/{chunk-QWC2PRUR.js → chunk-HRNQYGLQ.js} +2 -2
- package/dist/{chunk-YIVAKBCW.js → chunk-I4S7IZSS.js} +321 -235
- package/dist/chunk-I4S7IZSS.js.map +1 -0
- package/dist/{chunk-7DWAYY45.js → chunk-IN4XZJYD.js} +4 -3
- package/dist/{chunk-7DWAYY45.js.map → chunk-IN4XZJYD.js.map} +1 -1
- package/dist/{chunk-JGYCKX56.js → chunk-ISIXU45J.js} +1 -1
- package/dist/{chunk-JGYCKX56.js.map → chunk-ISIXU45J.js.map} +1 -1
- package/dist/{chunk-7PFOKQOJ.js → chunk-J4L4AS2W.js} +2 -2
- package/dist/{chunk-PZZWAHEJ.js → chunk-JPSOFWJR.js} +2 -2
- package/dist/{chunk-B24ODIKE.js → chunk-JRCO67NG.js} +2 -2
- package/dist/{chunk-PNEBCVXP.js → chunk-JW3I3NNZ.js} +2 -2
- package/dist/{chunk-MXNYMFHE.js → chunk-JZMPSQBH.js} +4 -4
- package/dist/{chunk-IIQMNZXT.js → chunk-K5TVSOPQ.js} +5 -5
- package/dist/{chunk-ZPXCQNXJ.js → chunk-K75SL74I.js} +2 -2
- package/dist/{chunk-TA5VTIC4.js → chunk-KA4AAUST.js} +2 -2
- package/dist/chunk-KHSBMLQE.js +161 -0
- package/dist/chunk-KHSBMLQE.js.map +1 -0
- package/dist/{chunk-JWLVBYP4.js → chunk-KUGUML7H.js} +3 -3
- package/dist/{chunk-GWYZEPBY.js → chunk-L4J5NC2Q.js} +2 -2
- package/dist/{chunk-PIF3TNU2.js → chunk-LIX4QPMM.js} +2 -2
- package/dist/{chunk-LCY6ANV2.js → chunk-LWQFGR34.js} +3 -3
- package/dist/{chunk-HQPS27BT.js → chunk-MMSSHMHW.js} +2 -2
- package/dist/{chunk-T5EXREMW.js → chunk-N25Z6PR4.js} +6 -5
- package/dist/chunk-N25Z6PR4.js.map +1 -0
- package/dist/{chunk-ND6S2DKC.js → chunk-N5S2BCW3.js} +2 -2
- package/dist/{chunk-63INIVE4.js → chunk-NIZH2TYZ.js} +2 -2
- package/dist/{chunk-WQHEEYQA.js → chunk-NLDBQHDV.js} +2 -2
- package/dist/{chunk-SKSHWV3E.js → chunk-NQQ4MOPC.js} +4 -4
- package/dist/{chunk-B6EWMGFX.js → chunk-NUBI6PYH.js} +2 -2
- package/dist/{chunk-VWUSOPBF.js → chunk-NYEXUZDW.js} +4 -4
- package/dist/{chunk-GU6QXHPZ.js → chunk-OIBFIWVJ.js} +4 -4
- package/dist/chunk-OIBFIWVJ.js.map +1 -0
- package/dist/{chunk-PIEX7WSG.js → chunk-OOLF5FU2.js} +2 -2
- package/dist/{chunk-HOK5KGBO.js → chunk-OQA7UF2Q.js} +3 -3
- package/dist/{chunk-JMMG7UWR.js → chunk-ORJPICJI.js} +2 -2
- package/dist/{chunk-IF2M43G4.js → chunk-PBRD75JF.js} +2 -2
- package/dist/{chunk-X7Q2XL5U.js → chunk-PDCBL23X.js} +39 -17
- package/dist/chunk-PDCBL23X.js.map +1 -0
- package/dist/{chunk-PR2R57YF.js → chunk-PR36DD2X.js} +7 -7
- package/dist/{chunk-LFCX2JAV.js → chunk-PV4HIC4E.js} +2 -2
- package/dist/{chunk-SKF3DF7M.js → chunk-PZNK4HTV.js} +3 -3
- package/dist/{chunk-5F3KYRG6.js → chunk-QBLPLNPE.js} +3 -3
- package/dist/{chunk-4ZRNXWF6.js → chunk-QZXUISRF.js} +5 -5
- package/dist/{chunk-7Q72NTBE.js → chunk-RBXYO7MD.js} +5 -5
- package/dist/{chunk-S2BQV6HM.js → chunk-RIACRFWA.js} +4 -4
- package/dist/{chunk-DO33YCSZ.js → chunk-RL6RNDJQ.js} +8 -8
- package/dist/{chunk-2SPWVX6W.js → chunk-SJ2P7UXD.js} +7 -7
- package/dist/{chunk-26FMWFAW.js → chunk-SWXS4LV3.js} +11 -11
- package/dist/{chunk-J3ECXFU7.js → chunk-TOTCZFRF.js} +2 -2
- package/dist/{chunk-AN4GUUQM.js → chunk-TT4D52EK.js} +6 -6
- package/dist/{chunk-KOJHCSGS.js → chunk-U7CMJY5P.js} +10 -10
- package/dist/{chunk-DDR6SCG7.js → chunk-UNKTZDA2.js} +11 -11
- package/dist/{chunk-DDR6SCG7.js.map → chunk-UNKTZDA2.js.map} +1 -1
- package/dist/{chunk-WVML7HUZ.js → chunk-UXH4AKH3.js} +95 -151
- package/dist/chunk-UXH4AKH3.js.map +1 -0
- package/dist/{chunk-MKQHIYUY.js → chunk-UZVHSYIF.js} +2 -2
- package/dist/{chunk-FDGE56FS.js → chunk-VHKAW5OI.js} +29 -5
- package/dist/chunk-VHKAW5OI.js.map +1 -0
- package/dist/{chunk-OCSKQUNE.js → chunk-VKZ3TDET.js} +3 -3
- package/dist/{chunk-ESDYDGPH.js → chunk-VLZPUG5A.js} +4 -4
- package/dist/{chunk-PCYIDPFM.js → chunk-VSN5FLMI.js} +2 -2
- package/dist/{chunk-S4QDN4IQ.js → chunk-VYBBE7RN.js} +5 -5
- package/dist/{chunk-XBFJRCRW.js → chunk-WHK4JVKF.js} +8 -8
- package/dist/{chunk-CZEWEOOV.js → chunk-X4LDBALX.js} +2 -2
- package/dist/{chunk-YWEPWJRG.js → chunk-X67E7NIJ.js} +3 -3
- package/dist/{chunk-RRI3JBD6.js → chunk-XMARKBUC.js} +3 -3
- package/dist/{chunk-B3B6HV5S.js → chunk-XMBBTETD.js} +2 -2
- package/dist/{chunk-GQ4MF3CM.js → chunk-XMBTAN5E.js} +28 -14
- package/dist/chunk-XMBTAN5E.js.map +1 -0
- package/dist/{chunk-GEICXZCQ.js → chunk-XROQP6IQ.js} +4 -4
- package/dist/chunk-XWWDZKLS.js +196 -0
- package/dist/chunk-XWWDZKLS.js.map +1 -0
- package/dist/{chunk-VX72USUQ.js → chunk-Y2RYUWSQ.js} +10 -10
- package/dist/{chunk-6I5RRBPP.js → chunk-YCTSQV7K.js} +5 -5
- package/dist/{chunk-7WV6R7RG.js → chunk-YF7P2DG7.js} +2 -2
- package/dist/{chunk-ZZLIFVZG.js → chunk-ZG7DBIVX.js} +2 -2
- package/dist/{chunk-Y6WJJRVV.js → chunk-ZGJ775X7.js} +2 -2
- package/dist/{chunk-PQGCWTTI.js → chunk-ZQQLOEWN.js} +3 -3
- package/dist/classified/index.js +5 -5
- package/dist/{classified-marker-LY7KQFPH.js → classified-marker-HKMRC7SC.js} +3 -3
- package/dist/{reveal-LK3GX4L6.js → classify-reveal-YSJKJEIR.js} +7 -12
- package/dist/classify-reveal-YSJKJEIR.js.map +1 -0
- package/dist/{verify-FT5COLP2.js → classify-verify-ZCTKYQ43.js} +31 -41
- package/dist/classify-verify-ZCTKYQ43.js.map +1 -0
- package/dist/collection-facade-PPKNUR2J.js +38 -0
- package/dist/{computed-XG7LFB7A.js → computed-UCYVPMZA.js} +3 -3
- package/dist/consent/index.js +6 -9
- package/dist/consent/index.js.map +1 -1
- package/dist/cover/index.js +6 -9
- package/dist/custody/index.js +11 -13
- package/dist/{dead-filter-F4EKHDQY.js → dead-filter-YOBWRG4O.js} +8 -11
- package/dist/{dead-filter-F4EKHDQY.js.map → dead-filter-YOBWRG4O.js.map} +1 -1
- package/dist/debug/index.js +5 -8
- package/dist/debug/index.js.map +1 -1
- package/dist/delegation-SNALWRMO.js +24 -0
- package/dist/derivations/index.js +20 -23
- package/dist/derive-4GNU4E4I.js +17 -0
- package/dist/directory/index.js +7 -10
- package/dist/{dispatch-YNHZLB72.js → dispatch-QW32QBLW.js} +17 -20
- package/dist/{dispatch-YNHZLB72.js.map → dispatch-QW32QBLW.js.map} +1 -1
- package/dist/{dispatch-URNW4Q2T.js → dispatch-V5WLDTVX.js} +5 -5
- package/dist/executor-7QN22OKI.js +8 -0
- package/dist/executor-BJZJNVBB.js +8 -0
- package/dist/executor-JEAAEJUM.js +32 -0
- package/dist/export-accessible-TVO2KQPG.js +20 -0
- package/dist/extract-partition-43CLDRN4.js +33 -0
- package/dist/{fanout-sidecar-6CSMTIVB.js → fanout-sidecar-DDONAFJT.js} +6 -9
- package/dist/{fanout-sidecar-6CSMTIVB.js.map → fanout-sidecar-DDONAFJT.js.map} +1 -1
- package/dist/forget/index.js +6 -9
- package/dist/forget/index.js.map +1 -1
- package/dist/guards/index.js +4 -4
- package/dist/history/index.js +11 -14
- package/dist/history/index.js.map +1 -1
- package/dist/i18n/index.js +11 -14
- package/dist/i18n/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +122 -123
- package/dist/index.js.map +1 -1
- package/dist/indexing/index.js +5 -5
- package/dist/introspection/index.js +8 -11
- package/dist/issue-EIHEDAXM.js +16 -0
- package/dist/kernel/capsule-requirements.d.ts +84 -0
- package/dist/kernel/errors.d.ts +15 -0
- package/dist/kernel/export-scope.d.ts +28 -1
- package/dist/kernel/store-segment-guard.d.ts +29 -0
- package/dist/kernel/types.d.ts +164 -8
- package/dist/kernel/validation.d.ts +32 -0
- package/dist/kernel/vault.d.ts +3 -3
- package/dist/{ledger-FV6NFTOR.js → ledger-BMVUFQ3R.js} +8 -11
- package/dist/liberate-7KHXCLNJ.js +23 -0
- package/dist/link-set-PC2EJRKL.js +26 -0
- package/dist/{managed-secret-PBJZHPQO.js → managed-secret-RPRVEYZA.js} +7 -10
- package/dist/materialized-views/index.js +23 -26
- package/dist/{migrate-cek-J634S4NU.js → migrate-cek-DTSCWGEF.js} +2 -2
- package/dist/money/index.js +5 -5
- package/dist/noydb-AYDNOXAX.js +98 -0
- package/dist/on/index.js +11 -13
- package/dist/overlay-views/index.js +4 -4
- package/dist/periods/index.js +9 -12
- package/dist/pod/index.js +65 -67
- package/dist/{pod-handle-IOEYUDCA.js → pod-handle-KBPQRN6Q.js} +6 -9
- package/dist/{pod-handle-IOEYUDCA.js.map → pod-handle-KBPQRN6Q.js.map} +1 -1
- package/dist/policy/index.js +7 -10
- package/dist/port/at/index.d.ts +1 -0
- package/dist/port/with/collection-registries.d.ts +37 -0
- package/dist/portability/index.js +8 -8
- package/dist/{post-register-L42VXYFB.js → post-register-RITSNASO.js} +6 -6
- package/dist/query/all/index.js +15 -15
- package/dist/query/index.js +7 -7
- package/dist/query/live/index.js +7 -7
- package/dist/query/reduce/index.js +10 -10
- package/dist/query/relate/index.js +9 -9
- package/dist/reduce/index.js +8 -8
- package/dist/register-BB34SK7E.js +27 -0
- package/dist/registry-65L6V5TO.js +20 -0
- package/dist/registry-HU62GPWA.js +32 -0
- package/dist/registry-SMNK6UM4.js +8 -0
- package/dist/registry-X5VPBKCO.js +8 -0
- package/dist/request-withdrawal-4SKAH46W.js +26 -0
- package/dist/{restore-to-ZQ2MXOFO.js → restore-to-VQHT67OH.js} +7 -10
- package/dist/{restore-to-ZQ2MXOFO.js.map → restore-to-VQHT67OH.js.map} +1 -1
- package/dist/revoke-IF5PX2JY.js +21 -0
- package/dist/satellites/index.js +1 -1
- package/dist/schema-update/index.js +2 -2
- package/dist/sealed-record/index.js +9 -12
- package/dist/sealed-record/index.js.map +1 -1
- package/dist/search/index.js +4 -4
- package/dist/{seed-XHQQF6LJ.js → seed-F2OSDZJR.js} +11 -13
- package/dist/{seed-XHQQF6LJ.js.map → seed-F2OSDZJR.js.map} +1 -1
- package/dist/sequence/index.js +6 -9
- package/dist/session/index.js +6 -9
- package/dist/session/index.js.map +1 -1
- package/dist/shadow/index.js +2 -2
- package/dist/signer-5P7IZC2K.js +20 -0
- package/dist/snapshots/index.js +8 -10
- package/dist/snapshots/index.js.map +1 -1
- package/dist/{stale-XY2QUSGU.js → stale-PUCZH5GJ.js} +7 -10
- package/dist/storage-5EGY5OYE.js +18 -0
- package/dist/store/index.js +1 -1
- package/dist/{store-coordination-provider-F7YG22D3.js → store-coordination-provider-SEQM7SHJ.js} +7 -10
- package/dist/{store-coordination-provider-F7YG22D3.js.map → store-coordination-provider-SEQM7SHJ.js.map} +1 -1
- package/dist/sync/index.js +13 -15
- package/dist/sync/index.js.map +1 -1
- package/dist/team/index.js +14 -16
- package/dist/tiers/index.js +8 -11
- package/dist/to/index.js +2 -2
- package/dist/transactions/index.js +3 -3
- package/dist/util/index.js +1 -1
- package/dist/vault-diff-H7LT5ZBJ.js +8 -0
- package/dist/vault-head/index.js +5 -8
- package/dist/vault-head/index.js.map +1 -1
- package/dist/walk-Z4N7PCZ2.js +17 -0
- package/dist/with-audit/portability/export-accessible.d.ts +3 -1
- package/dist/with-cargo/vault-diff.d.ts +28 -0
- package/dist/with-commit/sequence/index.d.ts +22 -0
- package/dist/with-party/team/keyring.d.ts +77 -0
- package/dist/with-party/team/managed-secret.d.ts +40 -3
- package/dist/with-shape/manifest/storage.d.ts +2 -2
- package/dist/with-shape/manifest/writer.d.ts +2 -2
- package/dist/with-store/store-middleware.d.ts +18 -5
- package/dist/withdraw-accessible-CRCIQSTL.js +23 -0
- package/package.json +3 -3
- package/dist/api-ARU35MCC.js +0 -18
- package/dist/capsule/enclave-aes/classify/reveal.d.ts +0 -10
- package/dist/capsule/enclave-aes/classify/verify.d.ts +0 -36
- package/dist/chunk-4RF7DVH2.js.map +0 -1
- package/dist/chunk-6B4X447I.js +0 -40
- package/dist/chunk-6B4X447I.js.map +0 -1
- package/dist/chunk-6Y3UJT5H.js +0 -157
- package/dist/chunk-6Y3UJT5H.js.map +0 -1
- package/dist/chunk-AYUMAPOS.js.map +0 -1
- package/dist/chunk-BCJAUHSG.js.map +0 -1
- package/dist/chunk-CE443VXM.js.map +0 -1
- package/dist/chunk-FDGE56FS.js.map +0 -1
- package/dist/chunk-GLSRKIU3.js +0 -591
- package/dist/chunk-GLSRKIU3.js.map +0 -1
- package/dist/chunk-GQ4MF3CM.js.map +0 -1
- package/dist/chunk-GU6QXHPZ.js.map +0 -1
- package/dist/chunk-LFUID7OW.js.map +0 -1
- package/dist/chunk-M2VLXPRU.js.map +0 -1
- package/dist/chunk-NB2DYYZL.js.map +0 -1
- package/dist/chunk-NH2UOV3B.js +0 -18
- package/dist/chunk-NH2UOV3B.js.map +0 -1
- package/dist/chunk-OJAFKGI7.js +0 -27
- package/dist/chunk-OJAFKGI7.js.map +0 -1
- package/dist/chunk-PVBKEBJU.js +0 -22
- package/dist/chunk-PVBKEBJU.js.map +0 -1
- package/dist/chunk-RQLCOSEJ.js +0 -78
- package/dist/chunk-RQLCOSEJ.js.map +0 -1
- package/dist/chunk-T5EXREMW.js.map +0 -1
- package/dist/chunk-VPG2UJYR.js.map +0 -1
- package/dist/chunk-VUBRHJ4H.js.map +0 -1
- package/dist/chunk-WRLWEYHY.js.map +0 -1
- package/dist/chunk-WVML7HUZ.js.map +0 -1
- package/dist/chunk-X7Q2XL5U.js.map +0 -1
- package/dist/chunk-YIVAKBCW.js.map +0 -1
- package/dist/collection-facade-SETOHJ3R.js +0 -41
- package/dist/delegation-JIQCMKW6.js +0 -26
- package/dist/derive-45KCFFOS.js +0 -20
- package/dist/executor-BVVZ5UHG.js +0 -8
- package/dist/executor-R25UN3FA.js +0 -8
- package/dist/executor-SIYBLT3P.js +0 -35
- package/dist/export-accessible-P672FZEJ.js +0 -22
- package/dist/extract-partition-DQ3FVL6H.js +0 -35
- package/dist/find-HHF2HBAC.js +0 -10
- package/dist/issue-NPLQHB3S.js +0 -19
- package/dist/liberate-A7WASOCG.js +0 -25
- package/dist/link-set-UMRSGMQ5.js +0 -29
- package/dist/noydb-V23UJKHT.js +0 -100
- package/dist/register-2VINJWYJ.js +0 -30
- package/dist/registry-3VLHDUID.js +0 -8
- package/dist/registry-6HVHDR3P.js +0 -35
- package/dist/registry-V4FQUMYP.js +0 -23
- package/dist/registry-Z2E6ZCPM.js +0 -8
- package/dist/request-withdrawal-PSIHKQP4.js +0 -28
- package/dist/reveal-LK3GX4L6.js.map +0 -1
- package/dist/revoke-2NYMID63.js +0 -24
- package/dist/signer-CP6XZLE3.js +0 -23
- package/dist/storage-QTM6JYQF.js +0 -21
- package/dist/vault-diff-C6WUJFNP.js +0 -8
- package/dist/verify-FT5COLP2.js.map +0 -1
- package/dist/walk-52FW6EKP.js +0 -20
- package/dist/withdraw-accessible-IVMKJGEN.js +0 -25
- package/dist/withdraw-accessible-IVMKJGEN.js.map +0 -1
- /package/dist/{api-ARU35MCC.js.map → api-QSEKT4KS.js.map} +0 -0
- /package/dist/{capsule-QJJFUUSH.js.map → capsule-YAITMH77.js.map} +0 -0
- /package/dist/{chunk-E3CUGBGW.js.map → chunk-24AGG4PP.js.map} +0 -0
- /package/dist/{chunk-MRVQKRXI.js.map → chunk-2SIREKBR.js.map} +0 -0
- /package/dist/{chunk-ZZZVNHN2.js.map → chunk-3M2KK7O7.js.map} +0 -0
- /package/dist/{chunk-P6FATPXQ.js.map → chunk-3ZCVY3T6.js.map} +0 -0
- /package/dist/{chunk-I7NDTNHK.js.map → chunk-4CGWLHPQ.js.map} +0 -0
- /package/dist/{chunk-PVQIME6P.js.map → chunk-56Z4NOC6.js.map} +0 -0
- /package/dist/{chunk-HQFTE3DX.js.map → chunk-5BGHAVBN.js.map} +0 -0
- /package/dist/{chunk-QHG7GQKM.js.map → chunk-5JNEDW7I.js.map} +0 -0
- /package/dist/{chunk-YAYDDYRU.js.map → chunk-5Y4MO7UQ.js.map} +0 -0
- /package/dist/{chunk-TLIFNRU5.js.map → chunk-63LZLRWG.js.map} +0 -0
- /package/dist/{chunk-BUFFPAR2.js.map → chunk-74W56QPY.js.map} +0 -0
- /package/dist/{chunk-U2N7DH4S.js.map → chunk-AHA7UALU.js.map} +0 -0
- /package/dist/{chunk-RNQ7V4LH.js.map → chunk-ANYX2M6P.js.map} +0 -0
- /package/dist/{chunk-VFGLMRO2.js.map → chunk-ATKYMRBC.js.map} +0 -0
- /package/dist/{chunk-7UHLO4ZN.js.map → chunk-B2HU55QD.js.map} +0 -0
- /package/dist/{chunk-RKOXA5GZ.js.map → chunk-BEKMLYQ4.js.map} +0 -0
- /package/dist/{chunk-R4PDYYK5.js.map → chunk-C2NXAR3D.js.map} +0 -0
- /package/dist/{chunk-44CU4N7N.js.map → chunk-CQLMRCKX.js.map} +0 -0
- /package/dist/{chunk-4XXRPSPS.js.map → chunk-DS2JXSUA.js.map} +0 -0
- /package/dist/{chunk-X6Z2SIRF.js.map → chunk-E2JIE4S3.js.map} +0 -0
- /package/dist/{chunk-EQ6C2ZPT.js.map → chunk-E7Y4J4GL.js.map} +0 -0
- /package/dist/{chunk-ZMDSBTFT.js.map → chunk-ECDM6YRX.js.map} +0 -0
- /package/dist/{chunk-JM72WDAY.js.map → chunk-EM56MHN5.js.map} +0 -0
- /package/dist/{chunk-YWJMM2WY.js.map → chunk-EQXOJH6O.js.map} +0 -0
- /package/dist/{chunk-ME6LY5UG.js.map → chunk-ET3U2C3A.js.map} +0 -0
- /package/dist/{chunk-G2KLVCKO.js.map → chunk-EU4G7PQH.js.map} +0 -0
- /package/dist/{chunk-WJXLTO43.js.map → chunk-EUCUYK5E.js.map} +0 -0
- /package/dist/{chunk-EPMX3SCC.js.map → chunk-EWSIJDWO.js.map} +0 -0
- /package/dist/{chunk-KFYUQMF5.js.map → chunk-F2FD4LSB.js.map} +0 -0
- /package/dist/{chunk-L4UL4IAR.js.map → chunk-F7ENMZYJ.js.map} +0 -0
- /package/dist/{chunk-5OG7YQX5.js.map → chunk-FIIVYQOW.js.map} +0 -0
- /package/dist/{chunk-2EF2Z4UN.js.map → chunk-FQEUJGBV.js.map} +0 -0
- /package/dist/{chunk-UORWAG7K.js.map → chunk-FY4FFNKK.js.map} +0 -0
- /package/dist/{chunk-WA4ZPMKP.js.map → chunk-GDCYZGPB.js.map} +0 -0
- /package/dist/{chunk-3HDBDUX2.js.map → chunk-H6Q7GKLI.js.map} +0 -0
- /package/dist/{chunk-654RE5YC.js.map → chunk-HDAPQF6Q.js.map} +0 -0
- /package/dist/{chunk-B5PWQMZN.js.map → chunk-HRLMUZLI.js.map} +0 -0
- /package/dist/{chunk-QWC2PRUR.js.map → chunk-HRNQYGLQ.js.map} +0 -0
- /package/dist/{chunk-7PFOKQOJ.js.map → chunk-J4L4AS2W.js.map} +0 -0
- /package/dist/{chunk-PZZWAHEJ.js.map → chunk-JPSOFWJR.js.map} +0 -0
- /package/dist/{chunk-B24ODIKE.js.map → chunk-JRCO67NG.js.map} +0 -0
- /package/dist/{chunk-PNEBCVXP.js.map → chunk-JW3I3NNZ.js.map} +0 -0
- /package/dist/{chunk-MXNYMFHE.js.map → chunk-JZMPSQBH.js.map} +0 -0
- /package/dist/{chunk-IIQMNZXT.js.map → chunk-K5TVSOPQ.js.map} +0 -0
- /package/dist/{chunk-ZPXCQNXJ.js.map → chunk-K75SL74I.js.map} +0 -0
- /package/dist/{chunk-TA5VTIC4.js.map → chunk-KA4AAUST.js.map} +0 -0
- /package/dist/{chunk-JWLVBYP4.js.map → chunk-KUGUML7H.js.map} +0 -0
- /package/dist/{chunk-GWYZEPBY.js.map → chunk-L4J5NC2Q.js.map} +0 -0
- /package/dist/{chunk-PIF3TNU2.js.map → chunk-LIX4QPMM.js.map} +0 -0
- /package/dist/{chunk-LCY6ANV2.js.map → chunk-LWQFGR34.js.map} +0 -0
- /package/dist/{chunk-HQPS27BT.js.map → chunk-MMSSHMHW.js.map} +0 -0
- /package/dist/{chunk-ND6S2DKC.js.map → chunk-N5S2BCW3.js.map} +0 -0
- /package/dist/{chunk-63INIVE4.js.map → chunk-NIZH2TYZ.js.map} +0 -0
- /package/dist/{chunk-WQHEEYQA.js.map → chunk-NLDBQHDV.js.map} +0 -0
- /package/dist/{chunk-SKSHWV3E.js.map → chunk-NQQ4MOPC.js.map} +0 -0
- /package/dist/{chunk-B6EWMGFX.js.map → chunk-NUBI6PYH.js.map} +0 -0
- /package/dist/{chunk-VWUSOPBF.js.map → chunk-NYEXUZDW.js.map} +0 -0
- /package/dist/{chunk-PIEX7WSG.js.map → chunk-OOLF5FU2.js.map} +0 -0
- /package/dist/{chunk-HOK5KGBO.js.map → chunk-OQA7UF2Q.js.map} +0 -0
- /package/dist/{chunk-JMMG7UWR.js.map → chunk-ORJPICJI.js.map} +0 -0
- /package/dist/{chunk-IF2M43G4.js.map → chunk-PBRD75JF.js.map} +0 -0
- /package/dist/{chunk-PR2R57YF.js.map → chunk-PR36DD2X.js.map} +0 -0
- /package/dist/{chunk-LFCX2JAV.js.map → chunk-PV4HIC4E.js.map} +0 -0
- /package/dist/{chunk-SKF3DF7M.js.map → chunk-PZNK4HTV.js.map} +0 -0
- /package/dist/{chunk-5F3KYRG6.js.map → chunk-QBLPLNPE.js.map} +0 -0
- /package/dist/{chunk-4ZRNXWF6.js.map → chunk-QZXUISRF.js.map} +0 -0
- /package/dist/{chunk-7Q72NTBE.js.map → chunk-RBXYO7MD.js.map} +0 -0
- /package/dist/{chunk-S2BQV6HM.js.map → chunk-RIACRFWA.js.map} +0 -0
- /package/dist/{chunk-DO33YCSZ.js.map → chunk-RL6RNDJQ.js.map} +0 -0
- /package/dist/{chunk-2SPWVX6W.js.map → chunk-SJ2P7UXD.js.map} +0 -0
- /package/dist/{chunk-26FMWFAW.js.map → chunk-SWXS4LV3.js.map} +0 -0
- /package/dist/{chunk-J3ECXFU7.js.map → chunk-TOTCZFRF.js.map} +0 -0
- /package/dist/{chunk-AN4GUUQM.js.map → chunk-TT4D52EK.js.map} +0 -0
- /package/dist/{chunk-KOJHCSGS.js.map → chunk-U7CMJY5P.js.map} +0 -0
- /package/dist/{chunk-MKQHIYUY.js.map → chunk-UZVHSYIF.js.map} +0 -0
- /package/dist/{chunk-OCSKQUNE.js.map → chunk-VKZ3TDET.js.map} +0 -0
- /package/dist/{chunk-ESDYDGPH.js.map → chunk-VLZPUG5A.js.map} +0 -0
- /package/dist/{chunk-PCYIDPFM.js.map → chunk-VSN5FLMI.js.map} +0 -0
- /package/dist/{chunk-S4QDN4IQ.js.map → chunk-VYBBE7RN.js.map} +0 -0
- /package/dist/{chunk-XBFJRCRW.js.map → chunk-WHK4JVKF.js.map} +0 -0
- /package/dist/{chunk-CZEWEOOV.js.map → chunk-X4LDBALX.js.map} +0 -0
- /package/dist/{chunk-YWEPWJRG.js.map → chunk-X67E7NIJ.js.map} +0 -0
- /package/dist/{chunk-RRI3JBD6.js.map → chunk-XMARKBUC.js.map} +0 -0
- /package/dist/{chunk-B3B6HV5S.js.map → chunk-XMBBTETD.js.map} +0 -0
- /package/dist/{chunk-GEICXZCQ.js.map → chunk-XROQP6IQ.js.map} +0 -0
- /package/dist/{chunk-VX72USUQ.js.map → chunk-Y2RYUWSQ.js.map} +0 -0
- /package/dist/{chunk-6I5RRBPP.js.map → chunk-YCTSQV7K.js.map} +0 -0
- /package/dist/{chunk-7WV6R7RG.js.map → chunk-YF7P2DG7.js.map} +0 -0
- /package/dist/{chunk-ZZLIFVZG.js.map → chunk-ZG7DBIVX.js.map} +0 -0
- /package/dist/{chunk-Y6WJJRVV.js.map → chunk-ZGJ775X7.js.map} +0 -0
- /package/dist/{chunk-PQGCWTTI.js.map → chunk-ZQQLOEWN.js.map} +0 -0
- /package/dist/{classified-marker-LY7KQFPH.js.map → classified-marker-HKMRC7SC.js.map} +0 -0
- /package/dist/{collection-facade-SETOHJ3R.js.map → collection-facade-PPKNUR2J.js.map} +0 -0
- /package/dist/{computed-XG7LFB7A.js.map → computed-UCYVPMZA.js.map} +0 -0
- /package/dist/{delegation-JIQCMKW6.js.map → delegation-SNALWRMO.js.map} +0 -0
- /package/dist/{derive-45KCFFOS.js.map → derive-4GNU4E4I.js.map} +0 -0
- /package/dist/{dispatch-URNW4Q2T.js.map → dispatch-V5WLDTVX.js.map} +0 -0
- /package/dist/{executor-BVVZ5UHG.js.map → executor-7QN22OKI.js.map} +0 -0
- /package/dist/{executor-R25UN3FA.js.map → executor-BJZJNVBB.js.map} +0 -0
- /package/dist/{executor-SIYBLT3P.js.map → executor-JEAAEJUM.js.map} +0 -0
- /package/dist/{export-accessible-P672FZEJ.js.map → export-accessible-TVO2KQPG.js.map} +0 -0
- /package/dist/{extract-partition-DQ3FVL6H.js.map → extract-partition-43CLDRN4.js.map} +0 -0
- /package/dist/{find-HHF2HBAC.js.map → issue-EIHEDAXM.js.map} +0 -0
- /package/dist/{issue-NPLQHB3S.js.map → ledger-BMVUFQ3R.js.map} +0 -0
- /package/dist/{ledger-FV6NFTOR.js.map → liberate-7KHXCLNJ.js.map} +0 -0
- /package/dist/{liberate-A7WASOCG.js.map → link-set-PC2EJRKL.js.map} +0 -0
- /package/dist/{link-set-UMRSGMQ5.js.map → managed-secret-RPRVEYZA.js.map} +0 -0
- /package/dist/{migrate-cek-J634S4NU.js.map → migrate-cek-DTSCWGEF.js.map} +0 -0
- /package/dist/{managed-secret-PBJZHPQO.js.map → noydb-AYDNOXAX.js.map} +0 -0
- /package/dist/{post-register-L42VXYFB.js.map → post-register-RITSNASO.js.map} +0 -0
- /package/dist/{noydb-V23UJKHT.js.map → register-BB34SK7E.js.map} +0 -0
- /package/dist/{register-2VINJWYJ.js.map → registry-65L6V5TO.js.map} +0 -0
- /package/dist/{registry-3VLHDUID.js.map → registry-HU62GPWA.js.map} +0 -0
- /package/dist/{registry-6HVHDR3P.js.map → registry-SMNK6UM4.js.map} +0 -0
- /package/dist/{registry-V4FQUMYP.js.map → registry-X5VPBKCO.js.map} +0 -0
- /package/dist/{registry-Z2E6ZCPM.js.map → request-withdrawal-4SKAH46W.js.map} +0 -0
- /package/dist/{request-withdrawal-PSIHKQP4.js.map → revoke-IF5PX2JY.js.map} +0 -0
- /package/dist/{revoke-2NYMID63.js.map → signer-5P7IZC2K.js.map} +0 -0
- /package/dist/{signer-CP6XZLE3.js.map → stale-PUCZH5GJ.js.map} +0 -0
- /package/dist/{stale-XY2QUSGU.js.map → storage-5EGY5OYE.js.map} +0 -0
- /package/dist/{storage-QTM6JYQF.js.map → vault-diff-H7LT5ZBJ.js.map} +0 -0
- /package/dist/{vault-diff-C6WUJFNP.js.map → walk-Z4N7PCZ2.js.map} +0 -0
- /package/dist/{walk-52FW6EKP.js.map → withdraw-accessible-CRCIQSTL.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
1
|
# Changelog — hub
|
|
2
2
|
|
|
3
|
+
## 0.10.0-pre.2
|
|
4
|
+
|
|
5
|
+
**The capsule seam closes, and four correctness fixes land on paths every vault takes.**
|
|
6
|
+
|
|
7
|
+
User-visible behaviour changes, each of which can change what your code does:
|
|
8
|
+
|
|
9
|
+
- **`saveAll` REPLACES.** A collection absent from the snapshot is gone afterwards, and an empty
|
|
10
|
+
record set empties its collection. Reserved `_`-prefixed collections are carried forward unless
|
|
11
|
+
the snapshot names them — a snapshot carrying `_keyring` replaces the live keyring without
|
|
12
|
+
passing through any keyring code path (family#147).
|
|
13
|
+
- **An absent record is at version 0.** `put` with `expectedVersion: 0` is a sentinel-free "write
|
|
14
|
+
only if absent"; a NONZERO expectation against nothing now **throws `ConflictError`** instead of
|
|
15
|
+
upserting (family#147, core#134).
|
|
16
|
+
- **A push whose CAS is refused against an empty remote now CREATES**, rather than leaving the
|
|
17
|
+
entry dirty forever and conflicting on every subsequent push (family#147).
|
|
18
|
+
- **A capsule that lacks a group is refused at startup**, in three places: `createNoydb()` for an
|
|
19
|
+
enabled service, `vault.collection()` for a declared field form, and the keyring entries for the
|
|
20
|
+
`authenticate`/`seal` posture groups — before any keyring is read or written (family#156).
|
|
21
|
+
- **An export secret must be at least 12 characters**, with no opt-out, and so must every string
|
|
22
|
+
`recipients[].secret`. Any characters qualify — a passphrase, a generated token, a
|
|
23
|
+
password-manager string. This is deliberately NOT the owner phrase rule: a `.noydb` bundle is
|
|
24
|
+
built to travel (family#177).
|
|
25
|
+
- **`attachSyncTarget` refuses a peer this device has diverged from.** A device that opened the
|
|
26
|
+
vault before attaching its peer self-provisioned a keyring and then diverged silently; the attach
|
|
27
|
+
now throws, naming both supported paths (family#178).
|
|
28
|
+
- **`EnclaveNotSupportedError` is deprecated.** `CapsuleNotSupportedError` is canonical and the
|
|
29
|
+
conformance kit accepts both codes, so an existing fork keeps passing (family#168).
|
|
30
|
+
- **A computed `dateField` no longer dodges a closed period.** The `beforePut` gate judged the record
|
|
31
|
+
*before* computed fields applied, and an absent date reads as outside every period — so the
|
|
32
|
+
closed-period guard never fired. Two bypasses are closed: a create, and **back-dating an update**
|
|
33
|
+
into a sealed period (family#202).
|
|
34
|
+
- **`transitionGuard`'s `initial` no longer rejects pulled records.** It constrains local creates
|
|
35
|
+
only; the arc check on updates still runs on every origin (family#188).
|
|
36
|
+
- **A guard no longer sees a change on every pulled record with a `money()` field** — it compared
|
|
37
|
+
`"100000"` against `"1000.00"` for the same value, so an issued (WORM) record never synced
|
|
38
|
+
(family#187).
|
|
39
|
+
- **An unchanged re-put of a nested money field is accepted.** `put(id, await get(id, { locale }))`
|
|
40
|
+
was refused outright on an issued record, because the read's `<path>Formatted`/`<path>Number`
|
|
41
|
+
virtuals survived ingest and the frozen-field compare saw them as a change. Those virtuals are
|
|
42
|
+
also no longer **persisted** — raw storage stays clean across a round-trip (family#201).
|
|
43
|
+
- **`first-writer-wins` gives a version tie to the remote.** On a tie the local copy won, which is
|
|
44
|
+
the second writer, overwriting the first on the remote (family#209).
|
|
45
|
+
- **A changed materialized-view definition is detected on reopen.** The stored `queryHash` was
|
|
46
|
+
written and never compared, so a view kept serving rows built under the old definition until an
|
|
47
|
+
unrelated source write refreshed it. ⚠️ A changed `rowKey` is **not** covered — it is not part of
|
|
48
|
+
the hash (family#204, and family#211 for `rowKey`).
|
|
49
|
+
- **A schema-manifest write and its ledger append are one unit.** The append re-read the record and
|
|
50
|
+
hashed whatever it found, recording that hash against *our* version, so a concurrent sync could
|
|
51
|
+
make a restore report `BACKUP_CORRUPTED` on untampered data (family#197). ⚠️ Cross-process
|
|
52
|
+
ordering of the two appends remains open (family#212).
|
|
53
|
+
- **A declaration-only option on a reconcile `vault.collection()` is no longer dropped in silence.**
|
|
54
|
+
`archive` now attaches; `schemaUpdate` is refused with a message naming the option and the way out.
|
|
55
|
+
⚠️ `schema` on a reconcile is **still** dropped — it needs a late-attach door (family#194, and
|
|
56
|
+
family#208 for `schema`).
|
|
57
|
+
|
|
58
|
+
**Known limitations in this release, stated because you will meet them before the fixes:**
|
|
59
|
+
|
|
60
|
+
- ⛔ **`vault.sequence()` is unique per DEVICE, not across devices.** Counters are CASed against the
|
|
61
|
+
local store and `_sequences` never syncs, so two devices issue the same numbers. Measured: A
|
|
62
|
+
`next()` → 1, A pushes, B pulls the whole vault, B `next()` → 1. Do not use it for a fleet-unique
|
|
63
|
+
invoice number until family#206 lands — it is the first item of the next cycle.
|
|
64
|
+
- ⚠️ **`schema` passed to a second `vault.collection(name, { schema })` call has no effect** and is
|
|
65
|
+
not yet refused, because a materialized view opens its source collection first and makes the
|
|
66
|
+
consumer's own declaration the reconcile call (family#208).
|
|
67
|
+
- ⚠️ **A changed materialized-view `rowKey` is not detected** — old-key rows survive beside new ones
|
|
68
|
+
until a full refresh (family#211).
|
|
69
|
+
- **`rotateKeys` CASes each record it rewrites.** A concurrent write during a rotation was silently
|
|
70
|
+
lost, and the stored version regressed with it (family#163).
|
|
71
|
+
- **Two concurrent first opens both succeed.** The loser of the keyring-create race now loads
|
|
72
|
+
rather than surfacing a raw `ConflictError` (family#164).
|
|
73
|
+
- **The `.join()` dangling-ref warning no longer logs a decrypted value**, and its dedup set no
|
|
74
|
+
longer retains one for the process lifetime (family#167).
|
|
75
|
+
- **One central segment check** around the mounted store: a vault or collection that is not a single
|
|
76
|
+
segment, and an id with an empty, `.` or `..` component, are refused before any store sees them.
|
|
77
|
+
A `/` and a NUL in an id stay legal — hub emits both (family#133, family#174).
|
|
78
|
+
- **`vault.export()` records an audit entry**, appended after the decrypt and before `encode`, and
|
|
79
|
+
`exportAccessibleData` records the access it made before building (family#151, family#175).
|
|
80
|
+
- Additive: `ExportChunk` carries `ids` always and `envelopeMeta` on request; `PRIMITIVE_GROUPS`,
|
|
81
|
+
`GROUPS_WITHOUT_PRIMITIVES` and `VDIG_ITERATIONS` publish on `@noy-db/hub/capsule`; a sealer takes
|
|
82
|
+
an optional vault context (family#151, family#166, family#168, family#157).
|
|
83
|
+
|
|
3
84
|
## 0.10.0-pre.1
|
|
4
85
|
|
|
5
86
|
**The first-entry pre-release.** Hub source since `0.10.0-pre.0`: two exports nothing could import are
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UserApi,
|
|
3
|
+
createUserApi
|
|
4
|
+
} from "./chunk-ANYX2M6P.js";
|
|
5
|
+
import "./chunk-ZQQLOEWN.js";
|
|
6
|
+
import "./chunk-EFINFZIF.js";
|
|
7
|
+
import "./chunk-I4S7IZSS.js";
|
|
8
|
+
import "./chunk-XWWDZKLS.js";
|
|
9
|
+
import "./chunk-CR5UPYIJ.js";
|
|
10
|
+
import "./chunk-ISIXU45J.js";
|
|
11
|
+
export {
|
|
12
|
+
UserApi,
|
|
13
|
+
createUserApi
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=api-QSEKT4KS.js.map
|
package/dist/as/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../chunk-2DX4JCRI.js";
|
|
2
|
-
import "../chunk-
|
|
2
|
+
import "../chunk-HDAPQF6Q.js";
|
|
3
3
|
import {
|
|
4
4
|
applyListProjection
|
|
5
5
|
} from "../chunk-VG2ZSFYD.js";
|
|
@@ -9,19 +9,16 @@ import {
|
|
|
9
9
|
import "../chunk-RXLYKVTF.js";
|
|
10
10
|
import "../chunk-QJNAHPVT.js";
|
|
11
11
|
import "../chunk-VYYM3MEN.js";
|
|
12
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-FY4FFNKK.js";
|
|
13
13
|
import "../chunk-Y2NBBT6K.js";
|
|
14
|
-
import "../chunk-
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-
|
|
17
|
-
import "../chunk-
|
|
18
|
-
import "../chunk-
|
|
19
|
-
import "../chunk-YIVAKBCW.js";
|
|
20
|
-
import "../chunk-6Y3UJT5H.js";
|
|
21
|
-
import "../chunk-VUBRHJ4H.js";
|
|
14
|
+
import "../chunk-PBRD75JF.js";
|
|
15
|
+
import "../chunk-EFINFZIF.js";
|
|
16
|
+
import "../chunk-I4S7IZSS.js";
|
|
17
|
+
import "../chunk-XWWDZKLS.js";
|
|
18
|
+
import "../chunk-CR5UPYIJ.js";
|
|
22
19
|
import {
|
|
23
20
|
ValidationError
|
|
24
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-ISIXU45J.js";
|
|
25
22
|
|
|
26
23
|
// src/port/as/active.ts
|
|
27
24
|
function redactChunk(chunk, ctx, redact) {
|
|
@@ -82,7 +79,7 @@ function contextFor(vault) {
|
|
|
82
79
|
// export fails instead.
|
|
83
80
|
describe: (collection) => vault.collection(collection).describe(),
|
|
84
81
|
plan: async (records, policy, formatId, idKey) => {
|
|
85
|
-
const { diffVault } = await import("../vault-diff-
|
|
82
|
+
const { diffVault } = await import("../vault-diff-H7LT5ZBJ.js");
|
|
86
83
|
const plan = await diffVault(vault, records, idKey ? { idKey } : {});
|
|
87
84
|
return {
|
|
88
85
|
plan,
|
|
@@ -122,6 +119,16 @@ function withFormats() {
|
|
|
122
119
|
for await (const chunk of ctx.chunks(options.collections)) {
|
|
123
120
|
chunks.push(redactChunk(chunk, ctx, options.redact));
|
|
124
121
|
}
|
|
122
|
+
const { keyring } = vault._introspectState();
|
|
123
|
+
await vault._getLedgerOrNull()?.append({
|
|
124
|
+
op: "lifecycle",
|
|
125
|
+
collection: "",
|
|
126
|
+
id: "",
|
|
127
|
+
version: 0,
|
|
128
|
+
actor: keyring.userId,
|
|
129
|
+
payloadHash: "",
|
|
130
|
+
reason: `${format.tier ?? "plaintext"}-export:${format.id}`
|
|
131
|
+
});
|
|
125
132
|
return format.encode(chunks);
|
|
126
133
|
},
|
|
127
134
|
async importWith(vault, format, input, options = {}) {
|
package/dist/as/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/port/as/active.ts"],"sourcesContent":["/**\n * `withFormats()` — the service that consumes the `as-*` port.\n *\n * Everything with a correctness or security consequence lives here rather\n * than in each format: the capability gate, the vault read, and redaction.\n * A {@link NoydbFormat} receives records and returns bytes.\n *\n * That is the whole point of the inversion (ADR 0004). The conformance kit it\n * replaces could only check implementors who ran it; a format that cannot\n * reach a vault is gated whether its author cooperated or not.\n *\n * @module\n */\nimport type { NoydbFormat, ImportPlan } from './types.js'\nimport type {\n FormatsStrategy,\n FormatsContext,\n FormatExportOptions,\n FormatImportOptions,\n} from '../with/formats-strategy.js'\nimport type { ExportChunk } from '../../kernel/types.js'\nimport type { Vault } from '../../kernel/vault.js'\nimport type { ImportPolicy } from './types.js'\nimport { applyListProjection } from '../../with-shape/introspection/index.js'\nimport type { CollectionDescription, ListProjectionOptions } from '../../with-shape/introspection/index.js'\nimport { ValidationError } from '../../kernel/errors.js'\n\n/** Apply the redaction projection hub owns, so a format never asks for it. */\nfunction redactChunk(\n chunk: ExportChunk,\n ctx: FormatsContext,\n redact: FormatExportOptions['redact'],\n): ExportChunk {\n if (redact === undefined) return chunk\n const described = ctx.describe(chunk.collection) as CollectionDescription | undefined\n if (!described) {\n throw new Error(\n `vault.export: redaction was requested but '${chunk.collection}' has no description to redact against. ` +\n 'Open the collection with its classifiedFields / fieldMeta options first.',\n )\n }\n const opts: ListProjectionOptions | undefined =\n redact === true ? undefined : { sensitivity: redact.sensitivity as never }\n const records = chunk.records.map((r) =>\n applyListProjection(described, r as Record<string, unknown>, opts),\n )\n return { ...chunk, records: records as typeof chunk.records }\n}\n\n/**\n * Derive the narrow, format-facing capability from the vault.\n *\n * Lives here rather than on `Vault` because `kernel-surface` said so, and it\n * was right: this is service capability, not spine. The spine keeps two\n * delegating methods and nothing else.\n */\nfunction contextFor(vault: Vault): FormatsContext {\n return {\n // The empty-id guards are NOT defensive padding. The\n // plaintext tier is gated per-format, so a missing id means the calling\n // binding is broken — and without this it would reach the gate, miss the\n // allowlist, and surface as `ExportCapabilityError`: \"the owner did not\n // grant this\", which sends the reader to the keyring instead of to the\n // format. A loud TypeError names the real fault.\n assertCanExport: (tier, format) => {\n if (tier === 'bundle') return vault.assertCanExport('bundle')\n if (!format) throw new TypeError(\"assertCanExport('plaintext') requires a non-empty format id\")\n vault.assertCanExport('plaintext', format)\n },\n assertCanImport: (tier, format) => {\n if (tier === 'bundle') return vault.assertCanImport('bundle')\n if (!format) throw new TypeError(\"assertCanImport('plaintext') requires a non-empty format id\")\n vault.assertCanImport('plaintext', format)\n },\n // ⭐ PASSED DOWN, not filtered here (core#45b). `ExportStreamOptions` now\n // carries `collections` and narrows the read, so an excluded collection is\n // neither fetched nor decrypted.\n //\n // ⚠️ The history is worth keeping, because the obvious edit here is the\n // wrong one twice over. The option was first passed to `exportStream`\n // when that interface had no field for it — silently dropped, every\n // collection read, caught only by an as-json test expecting ['invoices']\n // and getting ['invoices','payments']. The fix then was to filter after\n // the read, which was correct output and a full decrypt: for a\n // zero-knowledge store, a caller scoping an export to limit exposure got\n // no limit at all. Neither the compiler nor any chunk-level assertion can\n // tell these three implementations apart — only a store observation can\n // (`__tests__/45-export-scope-narrows-read.test.ts`).\n chunks: async function* (collections) {\n yield* vault.exportStream({\n granularity: 'collection',\n ...(collections ? { collections } : {}),\n })\n },\n // NOT swallowed. A caller who asked for redaction and silently got\n // unredacted output is the exact failure this port exists to remove — a\n // security duty that fails quiet. If the description cannot be read, the\n // export fails instead.\n describe: (collection) => vault.collection(collection).describe() as never,\n plan: async (records, policy: ImportPolicy, formatId: string, idKey?: string) => {\n const { diffVault } = await import('../../with-cargo/vault-diff.js')\n const plan = await diffVault(vault, records as never, idKey ? { idKey } : {})\n return {\n plan,\n policy,\n // The apply walk every as-* package had independently: added always,\n // modified unless insert-only, deleted only on replace — in one\n // transaction so a partial failure rolls back. Owned once, here.\n apply: async () => {\n await vault.noydb.transaction((tx) => {\n const txVault = tx.vault(vault.name)\n const reason = `import:${formatId}`\n for (const e of plan.added) {\n txVault.collection(e.collection).put(e.id, e.record as never, { reason })\n }\n if (policy !== 'insert-only') {\n for (const e of plan.modified) {\n txVault.collection(e.collection).put(e.id, e.record as never, { reason })\n }\n }\n if (policy === 'replace') {\n for (const e of plan.deleted) txVault.collection(e.collection).delete(e.id)\n }\n })\n },\n }\n },\n }\n}\n\n/**\n * Enable `vault.export()` / `vault.import()`.\n *\n * ```ts\n * const db = await createNoydb({ store, user, secret, formatsStrategy: withFormats() })\n * const csv = await vault.export(asCsv(), { collections: ['invoices'] })\n * ```\n *\n * ⭐ `collections` scopes the READ: an excluded collection is neither fetched\n * nor decrypted (core#45b, since 0.8 — through 0.7 it filtered output after a\n * full decrypt).\n */\nexport function withFormats(): FormatsStrategy {\n return {\n enabled: true,\n\n async exportWith<Out extends string | Uint8Array>(\n vault: Vault,\n format: NoydbFormat<Out>,\n options: FormatExportOptions = {},\n ): Promise<Out> {\n const ctx = contextFor(vault)\n // FIRST, and before a single record is read. The format is not in scope\n // yet and could not reach the vault if it were.\n if (format.tier === 'bundle') ctx.assertCanExport('bundle')\n else ctx.assertCanExport('plaintext', format.id)\n\n const chunks: ExportChunk[] = []\n for await (const chunk of ctx.chunks(options.collections)) {\n chunks.push(redactChunk(chunk, ctx, options.redact))\n }\n return format.encode(chunks)\n },\n\n async importWith<Out extends string | Uint8Array>(\n vault: Vault,\n format: NoydbFormat<Out>,\n input: Out,\n options: FormatImportOptions = {},\n ): Promise<ImportPlan> {\n const ctx = contextFor(vault)\n // Mirrors the export side: the import gate is two-tier as well, and a\n // bundle format importing under the plaintext tier would be a silent\n // downgrade in the other direction.\n if (format.tier === 'bundle') ctx.assertCanImport('bundle')\n else ctx.assertCanImport('plaintext', format.id)\n if (!format.decode) {\n throw new ValidationError(\n `vault.import: the '${format.id}' format is export-only — it declares no decode(). ` +\n 'Pick a format that round-trips, or write the records directly.',\n )\n }\n const decoded = await format.decode(input)\n const candidate: Record<string, readonly unknown[]> = {}\n for (const chunk of decoded) {\n const target = chunk.collection || options.collection\n if (!target) {\n throw new ValidationError(\n `vault.import: the '${format.id}' input names no collection and none was supplied. ` +\n 'Pass { collection } for formats whose payload is collection-less.',\n )\n }\n candidate[target] = [...(candidate[target] ?? []), ...chunk.records]\n }\n return ctx.plan(candidate, options.policy ?? 'merge', format.id, options.idKey)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAS,YACP,OACA,KACA,QACa;AACb,MAAI,WAAW,OAAW,QAAO;AACjC,QAAM,YAAY,IAAI,SAAS,MAAM,UAAU;AAC/C,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR,8CAA8C,MAAM,UAAU;AAAA,IAEhE;AAAA,EACF;AACA,QAAM,OACJ,WAAW,OAAO,SAAY,EAAE,aAAa,OAAO,YAAqB;AAC3E,QAAM,UAAU,MAAM,QAAQ;AAAA,IAAI,CAAC,MACjC,oBAAoB,WAAW,GAA8B,IAAI;AAAA,EACnE;AACA,SAAO,EAAE,GAAG,OAAO,QAAyC;AAC9D;AASA,SAAS,WAAW,OAA8B;AAChD,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOL,iBAAiB,CAAC,MAAM,WAAW;AACjC,UAAI,SAAS,SAAU,QAAO,MAAM,gBAAgB,QAAQ;AAC5D,UAAI,CAAC,OAAQ,OAAM,IAAI,UAAU,6DAA6D;AAC9F,YAAM,gBAAgB,aAAa,MAAM;AAAA,IAC3C;AAAA,IACA,iBAAiB,CAAC,MAAM,WAAW;AACjC,UAAI,SAAS,SAAU,QAAO,MAAM,gBAAgB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src/port/as/active.ts"],"sourcesContent":["/**\n * `withFormats()` — the service that consumes the `as-*` port.\n *\n * Everything with a correctness or security consequence lives here rather\n * than in each format: the capability gate, the vault read, and redaction.\n * A {@link NoydbFormat} receives records and returns bytes.\n *\n * That is the whole point of the inversion (ADR 0004). The conformance kit it\n * replaces could only check implementors who ran it; a format that cannot\n * reach a vault is gated whether its author cooperated or not.\n *\n * @module\n */\nimport type { NoydbFormat, ImportPlan } from './types.js'\nimport type {\n FormatsStrategy,\n FormatsContext,\n FormatExportOptions,\n FormatImportOptions,\n} from '../with/formats-strategy.js'\nimport type { ExportChunk } from '../../kernel/types.js'\nimport type { Vault } from '../../kernel/vault.js'\nimport type { ImportPolicy } from './types.js'\nimport { applyListProjection } from '../../with-shape/introspection/index.js'\nimport type { CollectionDescription, ListProjectionOptions } from '../../with-shape/introspection/index.js'\nimport { ValidationError } from '../../kernel/errors.js'\n\n/** Apply the redaction projection hub owns, so a format never asks for it. */\nfunction redactChunk(\n chunk: ExportChunk,\n ctx: FormatsContext,\n redact: FormatExportOptions['redact'],\n): ExportChunk {\n if (redact === undefined) return chunk\n const described = ctx.describe(chunk.collection) as CollectionDescription | undefined\n if (!described) {\n throw new Error(\n `vault.export: redaction was requested but '${chunk.collection}' has no description to redact against. ` +\n 'Open the collection with its classifiedFields / fieldMeta options first.',\n )\n }\n const opts: ListProjectionOptions | undefined =\n redact === true ? undefined : { sensitivity: redact.sensitivity as never }\n const records = chunk.records.map((r) =>\n applyListProjection(described, r as Record<string, unknown>, opts),\n )\n return { ...chunk, records: records as typeof chunk.records }\n}\n\n/**\n * Derive the narrow, format-facing capability from the vault.\n *\n * Lives here rather than on `Vault` because `kernel-surface` said so, and it\n * was right: this is service capability, not spine. The spine keeps two\n * delegating methods and nothing else.\n */\nfunction contextFor(vault: Vault): FormatsContext {\n return {\n // The empty-id guards are NOT defensive padding. The\n // plaintext tier is gated per-format, so a missing id means the calling\n // binding is broken — and without this it would reach the gate, miss the\n // allowlist, and surface as `ExportCapabilityError`: \"the owner did not\n // grant this\", which sends the reader to the keyring instead of to the\n // format. A loud TypeError names the real fault.\n assertCanExport: (tier, format) => {\n if (tier === 'bundle') return vault.assertCanExport('bundle')\n if (!format) throw new TypeError(\"assertCanExport('plaintext') requires a non-empty format id\")\n vault.assertCanExport('plaintext', format)\n },\n assertCanImport: (tier, format) => {\n if (tier === 'bundle') return vault.assertCanImport('bundle')\n if (!format) throw new TypeError(\"assertCanImport('plaintext') requires a non-empty format id\")\n vault.assertCanImport('plaintext', format)\n },\n // ⭐ PASSED DOWN, not filtered here (core#45b). `ExportStreamOptions` now\n // carries `collections` and narrows the read, so an excluded collection is\n // neither fetched nor decrypted.\n //\n // ⚠️ The history is worth keeping, because the obvious edit here is the\n // wrong one twice over. The option was first passed to `exportStream`\n // when that interface had no field for it — silently dropped, every\n // collection read, caught only by an as-json test expecting ['invoices']\n // and getting ['invoices','payments']. The fix then was to filter after\n // the read, which was correct output and a full decrypt: for a\n // zero-knowledge store, a caller scoping an export to limit exposure got\n // no limit at all. Neither the compiler nor any chunk-level assertion can\n // tell these three implementations apart — only a store observation can\n // (`__tests__/45-export-scope-narrows-read.test.ts`).\n chunks: async function* (collections) {\n yield* vault.exportStream({\n granularity: 'collection',\n ...(collections ? { collections } : {}),\n })\n },\n // NOT swallowed. A caller who asked for redaction and silently got\n // unredacted output is the exact failure this port exists to remove — a\n // security duty that fails quiet. If the description cannot be read, the\n // export fails instead.\n describe: (collection) => vault.collection(collection).describe() as never,\n plan: async (records, policy: ImportPolicy, formatId: string, idKey?: string) => {\n const { diffVault } = await import('../../with-cargo/vault-diff.js')\n const plan = await diffVault(vault, records as never, idKey ? { idKey } : {})\n return {\n plan,\n policy,\n // The apply walk every as-* package had independently: added always,\n // modified unless insert-only, deleted only on replace — in one\n // transaction so a partial failure rolls back. Owned once, here.\n apply: async () => {\n await vault.noydb.transaction((tx) => {\n const txVault = tx.vault(vault.name)\n const reason = `import:${formatId}`\n for (const e of plan.added) {\n txVault.collection(e.collection).put(e.id, e.record as never, { reason })\n }\n if (policy !== 'insert-only') {\n for (const e of plan.modified) {\n txVault.collection(e.collection).put(e.id, e.record as never, { reason })\n }\n }\n if (policy === 'replace') {\n for (const e of plan.deleted) txVault.collection(e.collection).delete(e.id)\n }\n })\n },\n }\n },\n }\n}\n\n/**\n * Enable `vault.export()` / `vault.import()`.\n *\n * ```ts\n * const db = await createNoydb({ store, user, secret, formatsStrategy: withFormats() })\n * const csv = await vault.export(asCsv(), { collections: ['invoices'] })\n * ```\n *\n * ⭐ `collections` scopes the READ: an excluded collection is neither fetched\n * nor decrypted (core#45b, since 0.8 — through 0.7 it filtered output after a\n * full decrypt).\n */\nexport function withFormats(): FormatsStrategy {\n return {\n enabled: true,\n\n async exportWith<Out extends string | Uint8Array>(\n vault: Vault,\n format: NoydbFormat<Out>,\n options: FormatExportOptions = {},\n ): Promise<Out> {\n const ctx = contextFor(vault)\n // FIRST, and before a single record is read. The format is not in scope\n // yet and could not reach the vault if it were.\n if (format.tier === 'bundle') ctx.assertCanExport('bundle')\n else ctx.assertCanExport('plaintext', format.id)\n\n const chunks: ExportChunk[] = []\n for await (const chunk of ctx.chunks(options.collections)) {\n chunks.push(redactChunk(chunk, ctx, options.redact))\n }\n\n // family#151 — THE AUDIT ENTRY BELONGS HERE, not in each `as-*` package.\n // Every format goes through this one method, so a per-package write is a\n // duty each author can forget silently: a vault's ledger would then record\n // some plaintext exports and not others, which is worse than recording\n // none, because the gap is invisible.\n //\n // ⚠️ APPENDED AFTER THE DECRYPT AND BEFORE `encode`, deliberately. The\n // chunks above are plaintext; that is the disclosure the entry exists to\n // record, and a format whose `encode` throws has not un-disclosed it. The\n // nearest analogue, `exportAccessibleData`, appends after its bytes are\n // built and would under-record the same way — reported, not changed here.\n //\n // ⛔ `_getLedgerOrNull()`, so this is a NO-OP without a history strategy.\n // Minting a `_ledger` DEK as a side effect of an export would create the\n // audit trail the caller never opted into, on their first export.\n //\n // The reason carries the TIER as well as the format id: `plaintext-` is\n // the privacy-relevant one, and `assertCanExport` above already treats\n // the two as different grants.\n const { keyring } = vault._introspectState()\n await vault._getLedgerOrNull()?.append({\n op: 'lifecycle',\n collection: '',\n id: '',\n version: 0,\n actor: keyring.userId,\n payloadHash: '',\n reason: `${format.tier ?? 'plaintext'}-export:${format.id}`,\n })\n\n return format.encode(chunks)\n },\n\n async importWith<Out extends string | Uint8Array>(\n vault: Vault,\n format: NoydbFormat<Out>,\n input: Out,\n options: FormatImportOptions = {},\n ): Promise<ImportPlan> {\n const ctx = contextFor(vault)\n // Mirrors the export side: the import gate is two-tier as well, and a\n // bundle format importing under the plaintext tier would be a silent\n // downgrade in the other direction.\n if (format.tier === 'bundle') ctx.assertCanImport('bundle')\n else ctx.assertCanImport('plaintext', format.id)\n if (!format.decode) {\n throw new ValidationError(\n `vault.import: the '${format.id}' format is export-only — it declares no decode(). ` +\n 'Pick a format that round-trips, or write the records directly.',\n )\n }\n const decoded = await format.decode(input)\n const candidate: Record<string, readonly unknown[]> = {}\n for (const chunk of decoded) {\n const target = chunk.collection || options.collection\n if (!target) {\n throw new ValidationError(\n `vault.import: the '${format.id}' input names no collection and none was supplied. ` +\n 'Pass { collection } for formats whose payload is collection-less.',\n )\n }\n candidate[target] = [...(candidate[target] ?? []), ...chunk.records]\n }\n return ctx.plan(candidate, options.policy ?? 'merge', format.id, options.idKey)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAS,YACP,OACA,KACA,QACa;AACb,MAAI,WAAW,OAAW,QAAO;AACjC,QAAM,YAAY,IAAI,SAAS,MAAM,UAAU;AAC/C,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR,8CAA8C,MAAM,UAAU;AAAA,IAEhE;AAAA,EACF;AACA,QAAM,OACJ,WAAW,OAAO,SAAY,EAAE,aAAa,OAAO,YAAqB;AAC3E,QAAM,UAAU,MAAM,QAAQ;AAAA,IAAI,CAAC,MACjC,oBAAoB,WAAW,GAA8B,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MAAM,WAAW,KAAK;AAI5B,UAAI,OAAO,SAAS,SAAU,KAAI,gBAAgB,QAAQ;AAAA,UACrD,KAAI,gBAAgB,aAAa,OAAO,EAAE;AAC/C,UAAI,CAAC,OAAO,QAAQ;AAClB,cAAM,IAAI;AAAA,UACR,sBAAsB,OAAO,EAAE;AAAA,QAEjC;AAAA,MACF;AACA,YAAM,UAAU,MAAM,OAAO,OAAO,KAAK;AACzC,YAAM,YAAgD,CAAC;AACvD,iBAAW,SAAS,SAAS;AAC3B,cAAM,SAAS,MAAM,cAAc,QAAQ;AAC3C,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,sBAAsB,OAAO,EAAE;AAAA,UAEjC;AAAA,QACF;AACA,kBAAU,MAAM,IAAI,CAAC,GAAI,UAAU,MAAM,KAAK,CAAC,GAAI,GAAG,MAAM,OAAO;AAAA,MACrE;AACA,aAAO,IAAI,KAAK,WAAW,QAAQ,UAAU,SAAS,OAAO,IAAI,QAAQ,KAAK;AAAA,IAChF;AAAA,EACF;AACF;","names":[]}
|
package/dist/at/index.js
CHANGED
|
@@ -3,15 +3,12 @@ import {
|
|
|
3
3
|
MemorySealer,
|
|
4
4
|
SEALED_SECRET_RECORD_ID,
|
|
5
5
|
parseSealedEnvelope
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-6Y3UJT5H.js";
|
|
13
|
-
import "../chunk-VUBRHJ4H.js";
|
|
14
|
-
import "../chunk-JGYCKX56.js";
|
|
6
|
+
} from "../chunk-OIBFIWVJ.js";
|
|
7
|
+
import "../chunk-EFINFZIF.js";
|
|
8
|
+
import "../chunk-I4S7IZSS.js";
|
|
9
|
+
import "../chunk-XWWDZKLS.js";
|
|
10
|
+
import "../chunk-CR5UPYIJ.js";
|
|
11
|
+
import "../chunk-ISIXU45J.js";
|
|
15
12
|
export {
|
|
16
13
|
MemoryRecipientSealer,
|
|
17
14
|
MemorySealer,
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
issueAttestationCore
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-HRLMUZLI.js";
|
|
4
4
|
import {
|
|
5
5
|
getRevokedDocIdsCore,
|
|
6
6
|
publishRevocationListCore,
|
|
7
7
|
revokeDocCore,
|
|
8
8
|
unrevokeDocCore
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-QZXUISRF.js";
|
|
10
|
+
import "../chunk-NUBI6PYH.js";
|
|
11
11
|
import {
|
|
12
12
|
ATTESTATIONS_COLLECTION
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-XMARKBUC.js";
|
|
14
14
|
import {
|
|
15
15
|
NO_ATTESTATION
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-ECDM6YRX.js";
|
|
17
17
|
import {
|
|
18
18
|
decodeQr,
|
|
19
19
|
isRevoked,
|
|
@@ -22,27 +22,24 @@ import {
|
|
|
22
22
|
verifyRevocationList
|
|
23
23
|
} from "../chunk-GMKGGY7V.js";
|
|
24
24
|
import "../chunk-4AOERLTV.js";
|
|
25
|
-
import "../chunk-
|
|
26
|
-
import "../chunk-
|
|
27
|
-
import "../chunk-
|
|
28
|
-
import "../chunk-
|
|
29
|
-
import "../chunk-YIVAKBCW.js";
|
|
30
|
-
import "../chunk-6Y3UJT5H.js";
|
|
31
|
-
import "../chunk-VUBRHJ4H.js";
|
|
25
|
+
import "../chunk-EFINFZIF.js";
|
|
26
|
+
import "../chunk-I4S7IZSS.js";
|
|
27
|
+
import "../chunk-XWWDZKLS.js";
|
|
28
|
+
import "../chunk-CR5UPYIJ.js";
|
|
32
29
|
import {
|
|
33
30
|
AttestationError,
|
|
34
31
|
AttestationNotEnabledError
|
|
35
|
-
} from "../chunk-
|
|
32
|
+
} from "../chunk-ISIXU45J.js";
|
|
36
33
|
|
|
37
34
|
// src/with-audit/attestation/active.ts
|
|
38
35
|
function withAttestation() {
|
|
39
36
|
return {
|
|
40
37
|
async issueAttestation(ctx, args) {
|
|
41
|
-
const { issueAttestationCore: issueAttestationCore2 } = await import("../issue-
|
|
38
|
+
const { issueAttestationCore: issueAttestationCore2 } = await import("../issue-EIHEDAXM.js");
|
|
42
39
|
return issueAttestationCore2(ctx, args);
|
|
43
40
|
},
|
|
44
41
|
async getDocumentSigningPublicKey(deps) {
|
|
45
|
-
const { loadSigner, loadOrCreateSigner } = await import("../signer-
|
|
42
|
+
const { loadSigner, loadOrCreateSigner } = await import("../signer-5P7IZC2K.js");
|
|
46
43
|
const existing = await loadSigner(deps.adapter, deps.vault, deps.getDEK);
|
|
47
44
|
if (existing) return { keyId: existing.keyId, publicKeyB64: existing.publicKeyB64 };
|
|
48
45
|
if (deps.role !== "owner") {
|
|
@@ -52,19 +49,19 @@ function withAttestation() {
|
|
|
52
49
|
return { keyId: signer.keyId, publicKeyB64: signer.publicKeyB64 };
|
|
53
50
|
},
|
|
54
51
|
async revokeAttestation(ctx, docId) {
|
|
55
|
-
const { revokeDocCore: revokeDocCore2 } = await import("../revoke-
|
|
52
|
+
const { revokeDocCore: revokeDocCore2 } = await import("../revoke-IF5PX2JY.js");
|
|
56
53
|
return revokeDocCore2(ctx, docId);
|
|
57
54
|
},
|
|
58
55
|
async unrevokeAttestation(ctx, docId) {
|
|
59
|
-
const { unrevokeDocCore: unrevokeDocCore2 } = await import("../revoke-
|
|
56
|
+
const { unrevokeDocCore: unrevokeDocCore2 } = await import("../revoke-IF5PX2JY.js");
|
|
60
57
|
return unrevokeDocCore2(ctx, docId);
|
|
61
58
|
},
|
|
62
59
|
async getRevokedDocIds(ctx) {
|
|
63
|
-
const { getRevokedDocIdsCore: getRevokedDocIdsCore2 } = await import("../revoke-
|
|
60
|
+
const { getRevokedDocIdsCore: getRevokedDocIdsCore2 } = await import("../revoke-IF5PX2JY.js");
|
|
64
61
|
return getRevokedDocIdsCore2(ctx);
|
|
65
62
|
},
|
|
66
63
|
async publishRevocationList(ctx) {
|
|
67
|
-
const { publishRevocationListCore: publishRevocationListCore2 } = await import("../revoke-
|
|
64
|
+
const { publishRevocationListCore: publishRevocationListCore2 } = await import("../revoke-IF5PX2JY.js");
|
|
68
65
|
return publishRevocationListCore2(ctx);
|
|
69
66
|
}
|
|
70
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/with-audit/attestation/active.ts","../../src/with-audit/attestation/verifier.ts"],"sourcesContent":["import { AttestationError } from '../../kernel/errors.js'\nimport type { AttestationStrategy } from './strategy.js'\n\n/**\n * Enable the attestation capability.\n * Pass to `createNoydb({ attestationStrategy: withAttestation() })` to make the\n * vault's `issueAttestation` / `getDocumentSigningPublicKey` / `revokeAttestation`\n * / `unrevokeAttestation` / `getRevokedDocIds` / `publishRevocationList` methods\n * live. The issue/revoke/signer engines are dynamically imported here, so they\n * stay out of the floor bundle until opted in.\n */\nexport function withAttestation(): AttestationStrategy {\n return {\n async issueAttestation(ctx, args) {\n const { issueAttestationCore } = await import('./issue.js')\n return issueAttestationCore(ctx, args)\n },\n async getDocumentSigningPublicKey(deps) {\n const { loadSigner, loadOrCreateSigner } = await import('./signer.js')\n // Reading an existing public key is open to any role that holds the\n // _attestations DEK — the public key is not secret. But MINTING the\n // signer is the firm's identity operation (same rule as issueAttestation):\n // a non-owner read must not silently create it.\n const existing = await loadSigner(deps.adapter, deps.vault, deps.getDEK)\n if (existing) return { keyId: existing.keyId, publicKeyB64: existing.publicKeyB64 }\n if (deps.role !== 'owner') {\n throw new AttestationError(`getDocumentSigningPublicKey: no document-signing key exists yet; only the 'owner' may mint it. Caller is '${deps.role}'. Have the owner issue an attestation (or call this) first.`)\n }\n const signer = await loadOrCreateSigner(deps.adapter, deps.vault, deps.getDEK)\n return { keyId: signer.keyId, publicKeyB64: signer.publicKeyB64 }\n },\n async revokeAttestation(ctx, docId) {\n const { revokeDocCore } = await import('./revoke.js')\n return revokeDocCore(ctx, docId)\n },\n async unrevokeAttestation(ctx, docId) {\n const { unrevokeDocCore } = await import('./revoke.js')\n return unrevokeDocCore(ctx, docId)\n },\n async getRevokedDocIds(ctx) {\n const { getRevokedDocIdsCore } = await import('./revoke.js')\n return getRevokedDocIdsCore(ctx)\n },\n async publishRevocationList(ctx) {\n const { publishRevocationListCore } = await import('./revoke.js')\n return publishRevocationListCore(ctx)\n },\n }\n}\n","/**\n * The pure verifier surface, re-exported through hub-owned signatures.\n *\n * `export { … } from '@noy-db/attestation'` would compile fine and bundle\n * fine — but tsc emits that specifier verbatim into hub's `.d.ts`, so a\n * consumer would need `@noy-db/attestation` installed just to TYPECHECK\n * against a package that bundles it. Binding each value to a locally-typed\n * `const` makes the declaration name only `./types.js`.\n * `__tests__/no-runtime-dependencies.test.ts` asserts the emitted `dist`\n * never names the package, and pins these types assignable to attestation's.\n */\nimport {\n verifyAttestation as _verifyAttestation,\n decodeQr as _decodeQr,\n verifyRevocationList as _verifyRevocationList,\n isRevoked as _isRevoked,\n signRevocationList as _signRevocationList,\n} from '@noy-db/attestation'\nimport type {\n QrPayload,\n RevocationList,\n SignatureScheme,\n VerifyInput,\n VerifyResult,\n} from './types.js'\n\nexport const verifyAttestation: (\n input: VerifyInput,\n scheme?: SignatureScheme,\n) => Promise<VerifyResult> = _verifyAttestation\n\nexport const decodeQr: (s: string) => QrPayload = _decodeQr\n\nexport const verifyRevocationList: (\n list: RevocationList,\n publicKeyB64: string,\n scheme?: SignatureScheme,\n) => Promise<boolean> = _verifyRevocationList\n\nexport const isRevoked: (docId: string, list: RevocationList) => boolean = _isRevoked\n\nexport const signRevocationList: (\n revokedDocIds: readonly string[],\n asOf: string,\n keyId: string,\n privateKeyPkcs8B64: string,\n scheme?: SignatureScheme,\n) => Promise<RevocationList> = _signRevocationList\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/with-audit/attestation/active.ts","../../src/with-audit/attestation/verifier.ts"],"sourcesContent":["import { AttestationError } from '../../kernel/errors.js'\nimport type { AttestationStrategy } from './strategy.js'\n\n/**\n * Enable the attestation capability.\n * Pass to `createNoydb({ attestationStrategy: withAttestation() })` to make the\n * vault's `issueAttestation` / `getDocumentSigningPublicKey` / `revokeAttestation`\n * / `unrevokeAttestation` / `getRevokedDocIds` / `publishRevocationList` methods\n * live. The issue/revoke/signer engines are dynamically imported here, so they\n * stay out of the floor bundle until opted in.\n */\nexport function withAttestation(): AttestationStrategy {\n return {\n async issueAttestation(ctx, args) {\n const { issueAttestationCore } = await import('./issue.js')\n return issueAttestationCore(ctx, args)\n },\n async getDocumentSigningPublicKey(deps) {\n const { loadSigner, loadOrCreateSigner } = await import('./signer.js')\n // Reading an existing public key is open to any role that holds the\n // _attestations DEK — the public key is not secret. But MINTING the\n // signer is the firm's identity operation (same rule as issueAttestation):\n // a non-owner read must not silently create it.\n const existing = await loadSigner(deps.adapter, deps.vault, deps.getDEK)\n if (existing) return { keyId: existing.keyId, publicKeyB64: existing.publicKeyB64 }\n if (deps.role !== 'owner') {\n throw new AttestationError(`getDocumentSigningPublicKey: no document-signing key exists yet; only the 'owner' may mint it. Caller is '${deps.role}'. Have the owner issue an attestation (or call this) first.`)\n }\n const signer = await loadOrCreateSigner(deps.adapter, deps.vault, deps.getDEK)\n return { keyId: signer.keyId, publicKeyB64: signer.publicKeyB64 }\n },\n async revokeAttestation(ctx, docId) {\n const { revokeDocCore } = await import('./revoke.js')\n return revokeDocCore(ctx, docId)\n },\n async unrevokeAttestation(ctx, docId) {\n const { unrevokeDocCore } = await import('./revoke.js')\n return unrevokeDocCore(ctx, docId)\n },\n async getRevokedDocIds(ctx) {\n const { getRevokedDocIdsCore } = await import('./revoke.js')\n return getRevokedDocIdsCore(ctx)\n },\n async publishRevocationList(ctx) {\n const { publishRevocationListCore } = await import('./revoke.js')\n return publishRevocationListCore(ctx)\n },\n }\n}\n","/**\n * The pure verifier surface, re-exported through hub-owned signatures.\n *\n * `export { … } from '@noy-db/attestation'` would compile fine and bundle\n * fine — but tsc emits that specifier verbatim into hub's `.d.ts`, so a\n * consumer would need `@noy-db/attestation` installed just to TYPECHECK\n * against a package that bundles it. Binding each value to a locally-typed\n * `const` makes the declaration name only `./types.js`.\n * `__tests__/no-runtime-dependencies.test.ts` asserts the emitted `dist`\n * never names the package, and pins these types assignable to attestation's.\n */\nimport {\n verifyAttestation as _verifyAttestation,\n decodeQr as _decodeQr,\n verifyRevocationList as _verifyRevocationList,\n isRevoked as _isRevoked,\n signRevocationList as _signRevocationList,\n} from '@noy-db/attestation'\nimport type {\n QrPayload,\n RevocationList,\n SignatureScheme,\n VerifyInput,\n VerifyResult,\n} from './types.js'\n\nexport const verifyAttestation: (\n input: VerifyInput,\n scheme?: SignatureScheme,\n) => Promise<VerifyResult> = _verifyAttestation\n\nexport const decodeQr: (s: string) => QrPayload = _decodeQr\n\nexport const verifyRevocationList: (\n list: RevocationList,\n publicKeyB64: string,\n scheme?: SignatureScheme,\n) => Promise<boolean> = _verifyRevocationList\n\nexport const isRevoked: (docId: string, list: RevocationList) => boolean = _isRevoked\n\nexport const signRevocationList: (\n revokedDocIds: readonly string[],\n asOf: string,\n keyId: string,\n privateKeyPkcs8B64: string,\n scheme?: SignatureScheme,\n) => Promise<RevocationList> = _signRevocationList\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,SAAS,kBAAuC;AACrD,SAAO;AAAA,IACL,MAAM,iBAAiB,KAAK,MAAM;AAChC,YAAM,EAAE,sBAAAA,sBAAqB,IAAI,MAAM,OAAO,sBAAY;AAC1D,aAAOA,sBAAqB,KAAK,IAAI;AAAA,IACvC;AAAA,IACA,MAAM,4BAA4B,MAAM;AACtC,YAAM,EAAE,YAAY,mBAAmB,IAAI,MAAM,OAAO,uBAAa;AAKrE,YAAM,WAAW,MAAM,WAAW,KAAK,SAAS,KAAK,OAAO,KAAK,MAAM;AACvE,UAAI,SAAU,QAAO,EAAE,OAAO,SAAS,OAAO,cAAc,SAAS,aAAa;AAClF,UAAI,KAAK,SAAS,SAAS;AACzB,cAAM,IAAI,iBAAiB,6GAA6G,KAAK,IAAI,8DAA8D;AAAA,MACjN;AACA,YAAM,SAAS,MAAM,mBAAmB,KAAK,SAAS,KAAK,OAAO,KAAK,MAAM;AAC7E,aAAO,EAAE,OAAO,OAAO,OAAO,cAAc,OAAO,aAAa;AAAA,IAClE;AAAA,IACA,MAAM,kBAAkB,KAAK,OAAO;AAClC,YAAM,EAAE,eAAAC,eAAc,IAAI,MAAM,OAAO,uBAAa;AACpD,aAAOA,eAAc,KAAK,KAAK;AAAA,IACjC;AAAA,IACA,MAAM,oBAAoB,KAAK,OAAO;AACpC,YAAM,EAAE,iBAAAC,iBAAgB,IAAI,MAAM,OAAO,uBAAa;AACtD,aAAOA,iBAAgB,KAAK,KAAK;AAAA,IACnC;AAAA,IACA,MAAM,iBAAiB,KAAK;AAC1B,YAAM,EAAE,sBAAAC,sBAAqB,IAAI,MAAM,OAAO,uBAAa;AAC3D,aAAOA,sBAAqB,GAAG;AAAA,IACjC;AAAA,IACA,MAAM,sBAAsB,KAAK;AAC/B,YAAM,EAAE,2BAAAC,2BAA0B,IAAI,MAAM,OAAO,uBAAa;AAChE,aAAOA,2BAA0B,GAAG;AAAA,IACtC;AAAA,EACF;AACF;;;ACtBO,IAAMC,qBAGgB;AAEtB,IAAMC,YAAqC;AAE3C,IAAMC,wBAIW;AAEjB,IAAMC,aAA8D;AAEpE,IAAMC,sBAMkB;","names":["issueAttestationCore","revokeDocCore","unrevokeDocCore","getRevokedDocIdsCore","publishRevocationListCore","verifyAttestation","decodeQr","verifyRevocationList","isRevoked","signRevocationList"]}
|
|
@@ -3,36 +3,33 @@ import {
|
|
|
3
3
|
} from "./chunk-EPFF7LOX.js";
|
|
4
4
|
import {
|
|
5
5
|
SCHEMAS_COLLECTION
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PBRD75JF.js";
|
|
7
7
|
import {
|
|
8
8
|
PERIODS_COLLECTION,
|
|
9
9
|
PERIOD_ARCHIVES_COLLECTION,
|
|
10
10
|
PERIOD_FREEZES_COLLECTION,
|
|
11
11
|
PERIOD_REOPENS_COLLECTION,
|
|
12
12
|
PERIOD_TARGET_PURGES_COLLECTION
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-JRCO67NG.js";
|
|
14
14
|
import {
|
|
15
15
|
SEQUENCE_COLLECTION
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-7KNYLHVX.js";
|
|
17
17
|
import {
|
|
18
18
|
LEDGER_COLLECTION,
|
|
19
19
|
LEDGER_DELTAS_COLLECTION
|
|
20
20
|
} from "./chunk-I7FD46FF.js";
|
|
21
21
|
import {
|
|
22
22
|
buildRecordEnvelope
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-
|
|
26
|
-
import "./chunk-NH2UOV3B.js";
|
|
27
|
-
import "./chunk-YIVAKBCW.js";
|
|
28
|
-
import "./chunk-6Y3UJT5H.js";
|
|
23
|
+
} from "./chunk-EFINFZIF.js";
|
|
24
|
+
import "./chunk-I4S7IZSS.js";
|
|
25
|
+
import "./chunk-XWWDZKLS.js";
|
|
29
26
|
import {
|
|
30
27
|
NOYDB_BACKUP_VERSION
|
|
31
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-CR5UPYIJ.js";
|
|
32
29
|
import {
|
|
33
30
|
BackupCorruptedError,
|
|
34
31
|
BackupLedgerError
|
|
35
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-ISIXU45J.js";
|
|
36
33
|
|
|
37
34
|
// src/with-pod/backup.ts
|
|
38
35
|
function internalCollectionNames(dataCollections) {
|
|
@@ -327,4 +324,4 @@ export {
|
|
|
327
324
|
loadVault,
|
|
328
325
|
verifyBackupIntegrity
|
|
329
326
|
};
|
|
330
|
-
//# sourceMappingURL=backup-
|
|
327
|
+
//# sourceMappingURL=backup-BHKVK5SD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/with-pod/backup.ts"],"sourcesContent":["/**\n * Vault backup / restore / integrity.\n *\n * Holds `dump()` (verifiable encrypted JSON backup, including the blob\n * collections so blob \"covers\" travel in the bundle), `load()` (restore +\n * post-load integrity gate), `verifyBackupIntegrity()` (chain + data-envelope\n * cross-check), and `exportJSON()` (plaintext per-collection export, built on\n * the vault's `exportStream`). Behaviour is byte-identical to the inline\n * `Vault` methods these functions replaced — every dependency the moving code\n * touched on `this.*` arrives via {@link BackupContext}. `Vault` keeps the\n * public methods as thin delegators.\n *\n * Internal — reached through `vault.dump()` / `vault.load()` / etc.\n */\nimport { NOYDB_BACKUP_VERSION } from '../kernel/types.js'\nimport { BackupLedgerError, BackupCorruptedError } from '../kernel/errors.js'\nimport { LEDGER_COLLECTION, LEDGER_DELTAS_COLLECTION } from '../with-commit/history/ledger/constants.js'\nimport { SCHEMAS_COLLECTION } from '../with-shape/persisted-schemas/storage.js'\nimport { SEQUENCE_COLLECTION } from '../with-commit/sequence/index.js'\nimport { MANIFEST_COLLECTION } from '../with-shape/manifest/reserved-collections.js'\n// #1025 — imported from the dependency-light `window.ts`, not `periods.ts`: that\n// module exists precisely so a consumer can name the period collections without\n// dragging the ledger hash-chain machinery (`sha256Hex`/`canonicalJson`) into a\n// bundle that opted out of the periods service. Same reason the sync engine's\n// period-scoped pull imports it.\nimport {\n PERIODS_COLLECTION,\n PERIOD_FREEZES_COLLECTION,\n PERIOD_ARCHIVES_COLLECTION,\n PERIOD_TARGET_PURGES_COLLECTION,\n PERIOD_REOPENS_COLLECTION,\n} from '../with-audit/periods/window.js'\nimport type {\n NoydbStore,\n EncryptedEnvelope,\n VaultBackup,\n VaultSnapshot,\n LoadPodOptions,\n LoadPodResult,\n ExportStreamOptions,\n ExportChunk,\n} from '../kernel/types.js'\nimport type { LedgerStore } from '../with-commit/history/ledger/store.js'\nimport { buildRecordEnvelope } from '../capsule/index.js'\n\n/** Everything the moving backup methods touched on the vault's `this.*`. */\nexport interface BackupContext {\n /** The ciphertext store. */\n readonly adapter: NoydbStore\n /** Vault namespace name. */\n readonly vault: string\n /** The invoking keyring's user id (read fresh per call). */\n userId(): string\n /** The vault's ledger store, or null when history is off. */\n getLedgerOrNull(): LedgerStore | null\n /** Recompute an envelope's `payloadHash` (bound `historyStrategy.envelopePayloadHash`). */\n envelopePayloadHash(envelope: EncryptedEnvelope): Promise<string>\n /**\n * Refresh the in-memory keyring from the freshly-loaded keyring file and\n * rebuild the DEK resolver. No-op when the vault has no `reloadKeyring`\n * callback (plaintext vaults / test constructions).\n */\n reloadKeyringAndRebuildDEK(): Promise<void>\n /**\n * core#71 — reset every sync engine attached to the vault after a restore:\n * the dirty log, the watermarks, the adopted epoch. A restore is a new base;\n * the pre-restore dirty entries refer to records the load just replaced.\n * Absent on test constructions without sync.\n */\n resetSync?(): Promise<void>\n /** Clear the vault's collection cache (post-load). */\n clearCollectionCache(): void\n /** Reset the ledger store so the next `ledger()` rebuilds its head cache. */\n resetLedgerStore(): void\n /** The vault's decrypt+ACL export stream (used by `exportJSON`). */\n exportStream(opts: ExportStreamOptions): AsyncIterableIterator<ExportChunk>\n}\n\n/** Result of {@link verifyBackupIntegrity}. */\nexport type VerifyBackupResult =\n | { readonly ok: true; readonly head: string; readonly length: number }\n | {\n readonly ok: false\n readonly kind: 'chain'\n readonly divergedAt: number\n readonly message: string\n }\n | {\n readonly ok: false\n readonly kind: 'data'\n readonly collection: string\n readonly id: string\n readonly message: string\n }\n\n/**\n * Dump vault as a verifiable encrypted JSON backup string.\n *\n * backups embed the current ledger head and the full `_ledger` +\n * `_ledger_deltas` internal collections so the receiver can run\n * `verifyBackupIntegrity()` after `load()` and detect any tampering between\n * dump and restore. Backups produced without a ledger skip the integrity check\n * with a warning — both modes round-trip cleanly.\n */\n/**\n * core#111 — the internal collections a pod carries, derived from its DATA\n * collection names. ⭐ ONE definition, used by the dump AND by the load's\n * clear step: they must agree or a restore leaves rows behind that the pod\n * says should not exist.\n *\n * ⛔ The load side CANNOT just clear what the pod carries. The dump skips a\n * collection with no rows (`if (ids.length === 0) continue`), so a pod taken\n * while `_periods` was empty does not mention `_periods` at all — and a store\n * that has since closed a period would keep those rows through a restore.\n * Absence in a pod means \"empty at dump time\", never \"leave whatever is there\".\n */\nfunction internalCollectionNames(dataCollections: readonly string[]): string[] {\n return [\n LEDGER_COLLECTION, LEDGER_DELTAS_COLLECTION, SCHEMAS_COLLECTION, SEQUENCE_COLLECTION,\n MANIFEST_COLLECTION, // #941: the pod's manifest-set record(s) travel in the bundle too\n // #1025: the accounting-period close state + its companions. The bundle is\n // the backup/restore path, so without these a restore discarded the\n // hash-chained evidence that a month was ever closed — the artifact\n // `closePeriod` exists to produce — and dropped the write gate with it, so\n // the restored vault silently accepted back-dated writes into a sealed\n // month. The companions matter as much as the close: a bounded reopen\n // window (`reopenPeriod({ until })`) is state a restore must not lose.\n PERIODS_COLLECTION,\n PERIOD_REOPENS_COLLECTION,\n PERIOD_FREEZES_COLLECTION,\n PERIOD_ARCHIVES_COLLECTION,\n PERIOD_TARGET_PURGES_COLLECTION,\n '_history', // full-snapshot version history — so history()/getVersion()/diff() survive the bundle\n '_blob_index', '_blob_chunks', '_blob_eviction_audit',\n // #753 spec §7 Q3: `_blob_intent` markers travel too — restoring mid-op\n // state (a blob row without its marker) would reproduce the ambiguity\n // the journal exists to prevent. Note: `_mv_stale` does NOT travel\n // today (a pre-existing, separate gap) — observed here, tracked on\n // #761, not fixed in this pass.\n '_blob_intent',\n // #769: `_blob_slots_<c>` envelopes travel verbatim (raw ciphertext,\n // same DEK, same vault) — including any `SlotRecord.pendingRelease`\n // resume breadcrumb they carry. This is INTENTIONALLY the opposite of\n // `extract-partition`'s `reKeyBlobs`, which STRIPS `pendingRelease`:\n // a full-vault backup restores into the SAME vault it was taken from,\n // so a breadcrumb taken mid-rehome (together with its `_blob_intent`\n // marker, carried above) is resumable on restore — carry-and-resume is\n // correct here. A partition extraction crosses vaults: the breadcrumb's\n // old eTag may not exist in the destination, so it must be stripped\n // there instead. Asymmetry: backup = same-vault-resumable = carry;\n // partition = cross-vault = strip-breadcrumb-carry-marker.\n ...dataCollections.flatMap((c) => [`_blob_slots_${c}`, `_blob_versions_${c}`]),\n ]\n}\n\nexport async function dumpVault(ctx: BackupContext): Promise<string> {\n const snapshot = await ctx.adapter.loadAll(ctx.vault)\n\n // Load keyrings (separate path because loadAll filters them out\n // along with all other underscore-prefixed internal collections).\n const keyringIds = await ctx.adapter.list(ctx.vault, '_keyring')\n const keyrings: Record<string, unknown> = {}\n for (const keyringId of keyringIds) {\n const envelope = await ctx.adapter.get(ctx.vault, '_keyring', keyringId)\n if (envelope) {\n keyrings[keyringId] = JSON.parse(envelope._data ?? '')\n }\n }\n\n // Load the ledger entries + deltas so the receiver can replay\n // the chain after restore. Without this, `load()` would have an\n // empty ledger and `verifyBackupIntegrity()` would have nothing\n // to compare against.\n //\n // Also enumerate the blob collections so blob content (\"covers\")\n // travels in the bundle (the blob DEK already travels in `_keyring`).\n // Literals are inlined (not imported from blobs/blob-set.ts) to keep\n // the blob runtime out of this kernel hot path — they mirror\n // BLOB_INDEX/CHUNKS/EVICTION_AUDIT_COLLECTION and SLOTS/VERSIONS_PREFIX.\n // The collect-loop skips empty ids, so this no-ops without blobs.\n const internalSnapshot: VaultSnapshot = {}\n const internalNames = internalCollectionNames(Object.keys(snapshot))\n for (const internalName of internalNames) {\n const ids = await ctx.adapter.list(ctx.vault, internalName)\n if (ids.length === 0) continue\n const records: Record<string, EncryptedEnvelope> = {}\n for (const id of ids) {\n const envelope = await ctx.adapter.get(ctx.vault, internalName, id)\n if (envelope) records[id] = envelope\n }\n internalSnapshot[internalName] = records\n }\n\n // Embed the ledger head if there's a chain. An empty ledger\n // (fresh vault) leaves `ledgerHead` undefined, which\n // load() treats the same as a legacy backup (no integrity\n // check, console warning). If history is not opted in,\n // `getLedgerOrNull` returns null and we skip embedding entirely\n // — the backup is still valid, just without the integrity head.\n const ledgerForHead = ctx.getLedgerOrNull()\n const head = ledgerForHead ? await ledgerForHead.head() : null\n const backup: VaultBackup = {\n _noydb_backup: NOYDB_BACKUP_VERSION,\n _compartment: ctx.vault,\n _exported_at: new Date().toISOString(),\n _exported_by: ctx.userId(),\n keyrings: keyrings as VaultBackup['keyrings'],\n collections: snapshot,\n ...(Object.keys(internalSnapshot).length > 0\n ? { _internal: internalSnapshot }\n : {}),\n ...(head\n ? {\n ledgerHead: {\n hash: head.hash,\n index: head.entry.index,\n ts: head.entry.ts,\n },\n }\n : {}),\n }\n\n return JSON.stringify(backup)\n}\n\n/**\n * Restore a vault from a verifiable backup. After loading, runs\n * `verifyBackupIntegrity()` to confirm the hash chain, the embedded head, and\n * every data envelope's payload hash. Legacy backups (no `ledgerHead`) load\n * with a console warning and skip the integrity check.\n */\n/**\n * core#77 — reconcile ONE collection against the pod's rows: write what\n * differs, delete what the pod does not carry, leave the rest untouched.\n *\n * Identity is `(id, _v)`, not a content hash — chunk rows are not\n * content-addressed today. That is enough to avoid rewriting 10 GB that has\n * not changed; it is NOT enough to dedupe across records, and nothing here\n * claims otherwise.\n *\n * ⛔ The DELETE half is what keeps this a restore rather than a merge: an id\n * the store holds and the pod does not is removed, exactly as `saveAll`\n * removes it in replace mode (core#111 — a restore rewinds).\n */\nasync function reconcileCollection(\n ctx: BackupContext,\n collection: string,\n podRows: Record<string, EncryptedEnvelope>,\n): Promise<{ written: number; skipped: number; deleted: number }> {\n let written = 0, skipped = 0, deleted = 0\n for (const [id, envelope] of Object.entries(podRows)) {\n const local = await ctx.adapter.get(ctx.vault, collection, id)\n if (local && local._v === envelope._v) { skipped++; continue }\n await ctx.adapter.put(ctx.vault, collection, id, envelope)\n written++\n }\n for (const id of await ctx.adapter.list(ctx.vault, collection)) {\n if (id in podRows) continue\n await ctx.adapter.delete(ctx.vault, collection, id)\n deleted++\n }\n return { written, skipped, deleted }\n}\n\n/** Fold the per-collection counters into the returned report. */\nfunction podReport(mode: 'replace' | 'incremental', per: Record<string, { written: number; skipped: number; deleted: number }>): LoadPodResult {\n let written = 0, skipped = 0, deleted = 0\n for (const r of Object.values(per)) { written += r.written; skipped += r.skipped; deleted += r.deleted }\n return { mode, written, skipped, deleted, collections: per }\n}\n\nexport async function loadVault(\n ctx: BackupContext,\n backupJson: string,\n options?: LoadPodOptions,\n): Promise<LoadPodResult> {\n const backup = JSON.parse(backupJson) as VaultBackup\n const mode = options?.mode ?? 'replace'\n const per: Record<string, { written: number; skipped: number; deleted: number }> = {}\n\n // core#77 — a pod from ANOTHER vault is refused in incremental mode. In\n // replace mode `saveAll` overwrites wholesale and the result is at least\n // coherent; \"write only the differences\" between unrelated vaults is not a\n // restore, it is a silent union of two histories, and the keyrings that\n // arrive with it would not open what is already here.\n if (mode === 'incremental' && backup._compartment !== ctx.vault) {\n throw new BackupLedgerError(\n `Incremental load refused: this pod was taken from vault \"${backup._compartment}\" ` +\n `and is being loaded into \"${ctx.vault}\". Incremental mode reconciles a vault against ` +\n `its OWN pod; use mode: 'replace' to overwrite this vault with a foreign pod.`,\n )\n }\n\n // 1. Restore data collections.\n if (mode === 'incremental') {\n const localData = await ctx.adapter.loadAll(ctx.vault)\n const names = new Set([...Object.keys(backup.collections), ...Object.keys(localData)])\n for (const name of names) {\n const r = await reconcileCollection(ctx, name, backup.collections[name] ?? {})\n if (r.written || r.skipped || r.deleted) per[name] = r\n }\n } else {\n await ctx.adapter.saveAll(ctx.vault, backup.collections)\n }\n\n // 2. Restore keyrings.\n for (const [userId, keyringFile] of Object.entries(backup.keyrings)) {\n // ⛔ core#132 — NO CAS HERE, deliberately. A pod restore is state\n // REPLACEMENT (core#111 made the internal collections wholesale too): the\n // pod is authoritative and there is no \"version this was based on\" to\n // compare against. CASing a restore would make it fail precisely when the\n // store has drifted, which is the case it exists to fix.\n const envelope = buildRecordEnvelope({ collection: '_keyring', id: userId, version: 1 },\n { iv: '', data: JSON.stringify(keyringFile) })\n await ctx.adapter.put(ctx.vault, '_keyring', userId, envelope)\n }\n\n // 3. Restore internal collections (`_ledger`, `_ledger_deltas`, history,\n // periods, blobs). Required so verifyBackupIntegrity has the chain to walk.\n //\n // ⛔⛔ CLEAR FIRST (core#111). This used to `put` the pod's rows id by id and\n // leave everything else, so entries written AFTER the pod survived the\n // restore. With history on that is not a cosmetic leftover: the ledger chain\n // still named `notes/n2`, whose envelope `saveAll` had just removed, and the\n // integrity check refused the restore outright —\n // BackupCorruptedError: Ledger expects data record \"notes/n2\" to exist …\n // which made restoring an OLDER pod possible only onto a store whose ledger\n // had not moved. That is never the case that matters: a restore is a step\n // BACK (core#71/#72).\n //\n // ⭐ A restore rewinds the ledger too, and now says so. The internal\n // collections are replaced wholesale, the way `saveAll` already treats the\n // data ones — anything else asks the chain to describe a store it does not\n // match. The names come from `internalCollectionNames`, NOT from the pod's\n // own keys: see the ⛔ on that function for why absence in a pod cannot mean\n // \"leave it alone\".\n //\n // ⚠️ Known residue, deliberately not chased here: `_blob_slots_<c>` /\n // `_blob_versions_<c>` for a DATA collection the pod does not carry are not\n // cleared, because the names are derived from the pod's collections and the\n // store contract has no way to enumerate `_`-prefixed collections\n // (`loadAll` skips them). Those rows are already orphaned — `saveAll` has\n // just removed the collection they describe — so they are unreachable\n // rather than misleading.\n //\n // core#77 — in INCREMENTAL mode the same names are reconciled instead of\n // cleared and rewritten. ⭐ This is the half that matters for the 10 GB\n // case: `_blob_chunks` is an internal collection, so a clear-and-rewrite\n // here would re-upload every chunk and leave \"incremental\" saving only the\n // record envelopes. Reconciling reaches the SAME end state — extras are\n // still deleted, so the restore still rewinds — at a cost proportional to\n // what actually differs.\n const internalNamesToLoad = internalCollectionNames(Object.keys(backup.collections))\n if (mode === 'incremental') {\n for (const internalName of internalNamesToLoad) {\n const r = await reconcileCollection(ctx, internalName, backup._internal?.[internalName] ?? {})\n if (r.written || r.skipped || r.deleted) per[internalName] = r\n }\n } else {\n for (const internalName of internalNamesToLoad) {\n for (const id of await ctx.adapter.list(ctx.vault, internalName)) {\n await ctx.adapter.delete(ctx.vault, internalName, id)\n }\n }\n if (backup._internal) {\n for (const [internalName, records] of Object.entries(backup._internal)) {\n for (const [id, envelope] of Object.entries(records)) {\n await ctx.adapter.put(ctx.vault, internalName, id, envelope)\n }\n }\n }\n }\n\n // 4. Refresh the in-memory keyring from the freshly-loaded\n // keyring file. Without this, the Vault's getDEK\n // closure still holds the OLD session's DEKs, and every\n // decrypt of a loaded ledger entry / data envelope fails\n // with TamperedError because the DEK doesn't match the\n // ciphertext that was encrypted with the SOURCE user's DEK.\n // Skipped for plaintext vaults and for tests that\n // construct Vault without a reloadKeyring callback.\n await ctx.reloadKeyringAndRebuildDEK()\n\n // 5. Clear collection cache + reset the ledger store so the\n // next ledger() call rebuilds its head cache from the\n // freshly-loaded entries.\n ctx.clearCollectionCache()\n ctx.resetLedgerStore()\n\n // 6. core#71 — a restore is a new base for sync: the pre-restore dirty log\n // named records the load replaced, and the watermarks described a state\n // that is gone. `replaceRemote` (core#72) is the explicit act that makes\n // the restore authoritative on the target; without it, `load()` stays a\n // local view — and now says so in `syncTargetStatus()` instead of pushing\n // stale entries.\n await ctx.resetSync?.()\n\n // 5. Run the verification gate. A backup with no ledgerHead cannot be\n // integrity-checked, and skipping silently would collapse\n // *unverifiable* into *clean* — so it always warns. But the REMEDY\n // depends on the reader, not the pod (#1303): the pod cannot say\n // whether its exporter predates the ledger or never enabled it, and\n // the reader knows its own configuration.\n //\n // - Reader HAS the ledger: the pod is behind it. \"Re-export\" is\n // actionable; keep the migration wording.\n // - Reader has NO ledger: nothing is stale and nothing is migrating —\n // the consumer priced the ledger (#1248 measured ~2.4x) and declined.\n // Prescribing a re-export is advice they should not take, and\n // repeating it on every read trains people to filter the one line\n // that also fires on a genuinely stale pod. State the consequence,\n // name the discriminator, prescribe nothing.\n if (!backup.ledgerHead) {\n if (ctx.getLedgerOrNull()) {\n console.warn(\n `[noy-db] Loaded a legacy backup with no ledgerHead — ` +\n `verifiable-backup integrity check skipped. ` +\n `Re-export with a ledger-aware build to get tamper detection.`,\n )\n } else {\n console.warn(\n `[noy-db] Loaded a backup with no ledgerHead — this pod is not integrity-checked. ` +\n `This reader has no ledger enabled (withHistory() is not configured), so nothing is stale: ` +\n `enable the ledger on both the exporter and this reader if tamper detection is wanted.`,\n )\n }\n return podReport(mode, per)\n }\n\n const result = await verifyBackupIntegrity(ctx)\n if (!result.ok) {\n // Surface the most specific error class we can. The result\n // shape carries enough info for callers to inspect.\n if (result.kind === 'data') {\n throw new BackupCorruptedError(\n result.collection,\n result.id,\n result.message,\n )\n }\n throw new BackupLedgerError(result.message, result.divergedAt)\n }\n\n // 6. Cross-check: the freshly-verified head must match the\n // value embedded at dump time. A mismatch means someone\n // truncated or extended the chain after dump.\n if (result.head !== backup.ledgerHead.hash) {\n throw new BackupLedgerError(\n `Backup ledger head mismatch: embedded \"${backup.ledgerHead.hash}\" ` +\n `but reconstructed \"${result.head}\".`,\n )\n }\n return podReport(mode, per)\n}\n\n/**\n * End-to-end backup integrity check: `ledger.verify()` (hash chain) plus a data\n * envelope cross-check (every current record's `_data` hash must match the\n * latest `put` entry's `payloadHash`). Returns a discriminated union so callers\n * can distinguish chain vs data failures.\n */\nexport async function verifyBackupIntegrity(ctx: BackupContext): Promise<VerifyBackupResult> {\n // Step 1: chain verification. Without the history strategy there\n // is no ledger; an unaudited backup verifies trivially as `ok`\n // because there's nothing to diverge from.\n const ledgerForVerify = ctx.getLedgerOrNull()\n if (!ledgerForVerify) {\n return { ok: true, head: '', length: 0 }\n }\n const chainResult = await ledgerForVerify.verify()\n if (!chainResult.ok) {\n return {\n ok: false,\n kind: 'chain',\n divergedAt: chainResult.divergedAt,\n message:\n `Ledger chain diverged at index ${chainResult.divergedAt}: ` +\n `expected prevHash \"${chainResult.expected}\" but found \"${chainResult.actual}\".`,\n }\n }\n\n // Step 2: data envelope cross-check. Walk every entry in the\n // ledger and, for the LATEST `put` per (collection, id), recompute\n // the data envelope's payloadHash and compare. Earlier puts of the\n // same id are skipped because the data collection only holds the\n // current version — historical envelopes live in the deltas\n // collection (which is itself protected by the chain).\n // Reuse the ledger we already resolved in step 1.\n const allEntries = await ledgerForVerify.loadAllEntries()\n\n // Find the latest non-delete entry per (collection, id). Walk\n // the entries in reverse so we hit the latest first; mark each\n // (collection, id) as seen and skip subsequent entries.\n const seen = new Set<string>()\n const latest = new Map<\n string,\n { collection: string; id: string; expectedHash: string }\n >()\n for (let i = allEntries.length - 1; i >= 0; i--) {\n const entry = allEntries[i]\n if (!entry) continue\n // Amendment entries are multi-record audit entries whose\n // `collection` and `id` are empty strings — building a `\"/\"`\n // key here would mark that synthetic slot as seen and falsely\n // trip the data check on a record that never existed. Skip\n // them BEFORE the key/seen bookkeeping so they neither\n // tombstone real entries nor enter the latest map.\n if (entry.op === 'amendment' || entry.op === 'lifecycle') continue\n const key = `${entry.collection}/${entry.id}`\n if (seen.has(key)) continue\n seen.add(key)\n // For deletes the data collection should NOT have the record,\n // so we skip — there's nothing to cross-check. Marking the key\n // as seen above ensures any earlier `put` of the same id is\n // also skipped (the record was subsequently deleted).\n if (entry.op === 'delete') continue\n latest.set(key, {\n collection: entry.collection,\n id: entry.id,\n expectedHash: entry.payloadHash,\n })\n }\n\n for (const { collection, id, expectedHash } of latest.values()) {\n const envelope = await ctx.adapter.get(ctx.vault, collection, id)\n if (!envelope) {\n return {\n ok: false,\n kind: 'data',\n collection,\n id,\n message:\n `Ledger expects data record \"${collection}/${id}\" to exist, ` +\n `but the adapter has no envelope for it.`,\n }\n }\n const actualHash = await ctx.envelopePayloadHash(envelope)\n if (actualHash !== expectedHash) {\n return {\n ok: false,\n kind: 'data',\n collection,\n id,\n message:\n `Data envelope \"${collection}/${id}\" has been tampered with: ` +\n `expected payloadHash \"${expectedHash}\", got \"${actualHash}\".`,\n }\n }\n }\n\n return {\n ok: true,\n head: chainResult.head,\n length: chainResult.length,\n }\n}\n\n/**\n * Plaintext per-collection export, built on the vault's `exportStream`. Forces\n * collection granularity (record-by-record output makes no sense in a single\n * string) and merges dictionary snapshots across collections.\n */\nexport async function exportVaultJSON(ctx: BackupContext, opts: ExportStreamOptions = {}): Promise<string> {\n // Force per-collection granularity regardless of caller setting:\n // record-by-record output doesn't make sense in a single string.\n const collections: Record<\n string,\n {\n schema: null\n refs: Record<string, { target: string; mode: 'strict' | 'warn' | 'cascade' }>\n records: unknown[]\n }\n > = {}\n let ledgerHead: ExportChunk['ledgerHead'] | undefined\n // Merged dictionary snapshot across all collections.\n // Only populated when `resolveLabels` is not set.\n const allDictionaries: Record<\n string, // collection name\n Record<string, Record<string, Record<string, string>>>\n > = {}\n\n for await (const chunk of ctx.exportStream({\n granularity: 'collection',\n withLedgerHead: opts.withLedgerHead === true,\n // Thread the export locale so records are read at the\n // `export` layer (i18nText collapsed + dictKey/staticDict labels resolved).\n ...(opts.resolveLabels !== undefined ? { resolveLabels: opts.resolveLabels } : {}),\n })) {\n collections[chunk.collection] = {\n schema: null, // Standard Schema validators are not JSON-serializable\n refs: chunk.refs,\n records: chunk.records,\n }\n if (chunk.ledgerHead) ledgerHead = chunk.ledgerHead\n // Collect dictionary snapshots unless resolveLabels is set\n if (!opts.resolveLabels && chunk.dictionaries) {\n allDictionaries[chunk.collection] = chunk.dictionaries\n }\n }\n\n const hasDictionaries = Object.keys(allDictionaries).length > 0\n return JSON.stringify({\n _noydb_export: 1,\n _compartment: ctx.vault,\n _exported_at: new Date().toISOString(),\n _exported_by: ctx.userId(),\n collections,\n ...(hasDictionaries ? { _dictionaries: allDictionaries } : {}),\n ...(ledgerHead ? { ledgerHead } : {}),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,SAAS,wBAAwB,iBAA8C;AAC7E,SAAO;AAAA,IACL;AAAA,IAAmB;AAAA,IAA0B;AAAA,IAAoB;AAAA,IACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA;AAAA,IACA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
1
|
+
{"version":3,"sources":["../src/with-pod/backup.ts"],"sourcesContent":["/**\n * Vault backup / restore / integrity.\n *\n * Holds `dump()` (verifiable encrypted JSON backup, including the blob\n * collections so blob \"covers\" travel in the bundle), `load()` (restore +\n * post-load integrity gate), `verifyBackupIntegrity()` (chain + data-envelope\n * cross-check), and `exportJSON()` (plaintext per-collection export, built on\n * the vault's `exportStream`). Behaviour is byte-identical to the inline\n * `Vault` methods these functions replaced — every dependency the moving code\n * touched on `this.*` arrives via {@link BackupContext}. `Vault` keeps the\n * public methods as thin delegators.\n *\n * Internal — reached through `vault.dump()` / `vault.load()` / etc.\n */\nimport { NOYDB_BACKUP_VERSION } from '../kernel/types.js'\nimport { BackupLedgerError, BackupCorruptedError } from '../kernel/errors.js'\nimport { LEDGER_COLLECTION, LEDGER_DELTAS_COLLECTION } from '../with-commit/history/ledger/constants.js'\nimport { SCHEMAS_COLLECTION } from '../with-shape/persisted-schemas/storage.js'\nimport { SEQUENCE_COLLECTION } from '../with-commit/sequence/index.js'\nimport { MANIFEST_COLLECTION } from '../with-shape/manifest/reserved-collections.js'\n// #1025 — imported from the dependency-light `window.ts`, not `periods.ts`: that\n// module exists precisely so a consumer can name the period collections without\n// dragging the ledger hash-chain machinery (`sha256Hex`/`canonicalJson`) into a\n// bundle that opted out of the periods service. Same reason the sync engine's\n// period-scoped pull imports it.\nimport {\n PERIODS_COLLECTION,\n PERIOD_FREEZES_COLLECTION,\n PERIOD_ARCHIVES_COLLECTION,\n PERIOD_TARGET_PURGES_COLLECTION,\n PERIOD_REOPENS_COLLECTION,\n} from '../with-audit/periods/window.js'\nimport type {\n NoydbStore,\n EncryptedEnvelope,\n VaultBackup,\n VaultSnapshot,\n LoadPodOptions,\n LoadPodResult,\n ExportStreamOptions,\n ExportChunk,\n} from '../kernel/types.js'\nimport type { LedgerStore } from '../with-commit/history/ledger/store.js'\nimport { buildRecordEnvelope } from '../capsule/index.js'\n\n/** Everything the moving backup methods touched on the vault's `this.*`. */\nexport interface BackupContext {\n /** The ciphertext store. */\n readonly adapter: NoydbStore\n /** Vault namespace name. */\n readonly vault: string\n /** The invoking keyring's user id (read fresh per call). */\n userId(): string\n /** The vault's ledger store, or null when history is off. */\n getLedgerOrNull(): LedgerStore | null\n /** Recompute an envelope's `payloadHash` (bound `historyStrategy.envelopePayloadHash`). */\n envelopePayloadHash(envelope: EncryptedEnvelope): Promise<string>\n /**\n * Refresh the in-memory keyring from the freshly-loaded keyring file and\n * rebuild the DEK resolver. No-op when the vault has no `reloadKeyring`\n * callback (plaintext vaults / test constructions).\n */\n reloadKeyringAndRebuildDEK(): Promise<void>\n /**\n * core#71 — reset every sync engine attached to the vault after a restore:\n * the dirty log, the watermarks, the adopted epoch. A restore is a new base;\n * the pre-restore dirty entries refer to records the load just replaced.\n * Absent on test constructions without sync.\n */\n resetSync?(): Promise<void>\n /** Clear the vault's collection cache (post-load). */\n clearCollectionCache(): void\n /** Reset the ledger store so the next `ledger()` rebuilds its head cache. */\n resetLedgerStore(): void\n /** The vault's decrypt+ACL export stream (used by `exportJSON`). */\n exportStream(opts: ExportStreamOptions): AsyncIterableIterator<ExportChunk>\n}\n\n/** Result of {@link verifyBackupIntegrity}. */\nexport type VerifyBackupResult =\n | { readonly ok: true; readonly head: string; readonly length: number }\n | {\n readonly ok: false\n readonly kind: 'chain'\n readonly divergedAt: number\n readonly message: string\n }\n | {\n readonly ok: false\n readonly kind: 'data'\n readonly collection: string\n readonly id: string\n readonly message: string\n }\n\n/**\n * Dump vault as a verifiable encrypted JSON backup string.\n *\n * backups embed the current ledger head and the full `_ledger` +\n * `_ledger_deltas` internal collections so the receiver can run\n * `verifyBackupIntegrity()` after `load()` and detect any tampering between\n * dump and restore. Backups produced without a ledger skip the integrity check\n * with a warning — both modes round-trip cleanly.\n */\n/**\n * core#111 — the internal collections a pod carries, derived from its DATA\n * collection names. ⭐ ONE definition, used by the dump AND by the load's\n * clear step: they must agree or a restore leaves rows behind that the pod\n * says should not exist.\n *\n * ⛔ The load side CANNOT just clear what the pod carries. The dump skips a\n * collection with no rows (`if (ids.length === 0) continue`), so a pod taken\n * while `_periods` was empty does not mention `_periods` at all — and a store\n * that has since closed a period would keep those rows through a restore.\n * Absence in a pod means \"empty at dump time\", never \"leave whatever is there\".\n */\nfunction internalCollectionNames(dataCollections: readonly string[]): string[] {\n return [\n LEDGER_COLLECTION, LEDGER_DELTAS_COLLECTION, SCHEMAS_COLLECTION, SEQUENCE_COLLECTION,\n MANIFEST_COLLECTION, // #941: the pod's manifest-set record(s) travel in the bundle too\n // #1025: the accounting-period close state + its companions. The bundle is\n // the backup/restore path, so without these a restore discarded the\n // hash-chained evidence that a month was ever closed — the artifact\n // `closePeriod` exists to produce — and dropped the write gate with it, so\n // the restored vault silently accepted back-dated writes into a sealed\n // month. The companions matter as much as the close: a bounded reopen\n // window (`reopenPeriod({ until })`) is state a restore must not lose.\n PERIODS_COLLECTION,\n PERIOD_REOPENS_COLLECTION,\n PERIOD_FREEZES_COLLECTION,\n PERIOD_ARCHIVES_COLLECTION,\n PERIOD_TARGET_PURGES_COLLECTION,\n '_history', // full-snapshot version history — so history()/getVersion()/diff() survive the bundle\n '_blob_index', '_blob_chunks', '_blob_eviction_audit',\n // #753 spec §7 Q3: `_blob_intent` markers travel too — restoring mid-op\n // state (a blob row without its marker) would reproduce the ambiguity\n // the journal exists to prevent. Note: `_mv_stale` does NOT travel\n // today (a pre-existing, separate gap) — observed here, tracked on\n // #761, not fixed in this pass.\n '_blob_intent',\n // #769: `_blob_slots_<c>` envelopes travel verbatim (raw ciphertext,\n // same DEK, same vault) — including any `SlotRecord.pendingRelease`\n // resume breadcrumb they carry. This is INTENTIONALLY the opposite of\n // `extract-partition`'s `reKeyBlobs`, which STRIPS `pendingRelease`:\n // a full-vault backup restores into the SAME vault it was taken from,\n // so a breadcrumb taken mid-rehome (together with its `_blob_intent`\n // marker, carried above) is resumable on restore — carry-and-resume is\n // correct here. A partition extraction crosses vaults: the breadcrumb's\n // old eTag may not exist in the destination, so it must be stripped\n // there instead. Asymmetry: backup = same-vault-resumable = carry;\n // partition = cross-vault = strip-breadcrumb-carry-marker.\n ...dataCollections.flatMap((c) => [`_blob_slots_${c}`, `_blob_versions_${c}`]),\n ]\n}\n\nexport async function dumpVault(ctx: BackupContext): Promise<string> {\n const snapshot = await ctx.adapter.loadAll(ctx.vault)\n\n // Load keyrings (separate path because loadAll filters them out\n // along with all other underscore-prefixed internal collections).\n const keyringIds = await ctx.adapter.list(ctx.vault, '_keyring')\n const keyrings: Record<string, unknown> = {}\n for (const keyringId of keyringIds) {\n const envelope = await ctx.adapter.get(ctx.vault, '_keyring', keyringId)\n if (envelope) {\n keyrings[keyringId] = JSON.parse(envelope._data ?? '')\n }\n }\n\n // Load the ledger entries + deltas so the receiver can replay\n // the chain after restore. Without this, `load()` would have an\n // empty ledger and `verifyBackupIntegrity()` would have nothing\n // to compare against.\n //\n // Also enumerate the blob collections so blob content (\"covers\")\n // travels in the bundle (the blob DEK already travels in `_keyring`).\n // Literals are inlined (not imported from blobs/blob-set.ts) to keep\n // the blob runtime out of this kernel hot path — they mirror\n // BLOB_INDEX/CHUNKS/EVICTION_AUDIT_COLLECTION and SLOTS/VERSIONS_PREFIX.\n // The collect-loop skips empty ids, so this no-ops without blobs.\n const internalSnapshot: VaultSnapshot = {}\n const internalNames = internalCollectionNames(Object.keys(snapshot))\n for (const internalName of internalNames) {\n const ids = await ctx.adapter.list(ctx.vault, internalName)\n if (ids.length === 0) continue\n const records: Record<string, EncryptedEnvelope> = {}\n for (const id of ids) {\n const envelope = await ctx.adapter.get(ctx.vault, internalName, id)\n if (envelope) records[id] = envelope\n }\n internalSnapshot[internalName] = records\n }\n\n // Embed the ledger head if there's a chain. An empty ledger\n // (fresh vault) leaves `ledgerHead` undefined, which\n // load() treats the same as a legacy backup (no integrity\n // check, console warning). If history is not opted in,\n // `getLedgerOrNull` returns null and we skip embedding entirely\n // — the backup is still valid, just without the integrity head.\n const ledgerForHead = ctx.getLedgerOrNull()\n const head = ledgerForHead ? await ledgerForHead.head() : null\n const backup: VaultBackup = {\n _noydb_backup: NOYDB_BACKUP_VERSION,\n _compartment: ctx.vault,\n _exported_at: new Date().toISOString(),\n _exported_by: ctx.userId(),\n keyrings: keyrings as VaultBackup['keyrings'],\n collections: snapshot,\n ...(Object.keys(internalSnapshot).length > 0\n ? { _internal: internalSnapshot }\n : {}),\n ...(head\n ? {\n ledgerHead: {\n hash: head.hash,\n index: head.entry.index,\n ts: head.entry.ts,\n },\n }\n : {}),\n }\n\n return JSON.stringify(backup)\n}\n\n/**\n * Restore a vault from a verifiable backup. After loading, runs\n * `verifyBackupIntegrity()` to confirm the hash chain, the embedded head, and\n * every data envelope's payload hash. Legacy backups (no `ledgerHead`) load\n * with a console warning and skip the integrity check.\n */\n/**\n * core#77 — reconcile ONE collection against the pod's rows: write what\n * differs, delete what the pod does not carry, leave the rest untouched.\n *\n * Identity is `(id, _v)`, not a content hash — chunk rows are not\n * content-addressed today. That is enough to avoid rewriting 10 GB that has\n * not changed; it is NOT enough to dedupe across records, and nothing here\n * claims otherwise.\n *\n * ⛔ The DELETE half is what keeps this a restore rather than a merge: an id\n * the store holds and the pod does not is removed, exactly as `saveAll`\n * removes it in replace mode (core#111 — a restore rewinds).\n */\nasync function reconcileCollection(\n ctx: BackupContext,\n collection: string,\n podRows: Record<string, EncryptedEnvelope>,\n): Promise<{ written: number; skipped: number; deleted: number }> {\n let written = 0, skipped = 0, deleted = 0\n for (const [id, envelope] of Object.entries(podRows)) {\n const local = await ctx.adapter.get(ctx.vault, collection, id)\n if (local && local._v === envelope._v) { skipped++; continue }\n await ctx.adapter.put(ctx.vault, collection, id, envelope)\n written++\n }\n for (const id of await ctx.adapter.list(ctx.vault, collection)) {\n if (id in podRows) continue\n await ctx.adapter.delete(ctx.vault, collection, id)\n deleted++\n }\n return { written, skipped, deleted }\n}\n\n/** Fold the per-collection counters into the returned report. */\nfunction podReport(mode: 'replace' | 'incremental', per: Record<string, { written: number; skipped: number; deleted: number }>): LoadPodResult {\n let written = 0, skipped = 0, deleted = 0\n for (const r of Object.values(per)) { written += r.written; skipped += r.skipped; deleted += r.deleted }\n return { mode, written, skipped, deleted, collections: per }\n}\n\nexport async function loadVault(\n ctx: BackupContext,\n backupJson: string,\n options?: LoadPodOptions,\n): Promise<LoadPodResult> {\n const backup = JSON.parse(backupJson) as VaultBackup\n const mode = options?.mode ?? 'replace'\n const per: Record<string, { written: number; skipped: number; deleted: number }> = {}\n\n // core#77 — a pod from ANOTHER vault is refused in incremental mode. In\n // replace mode `saveAll` overwrites wholesale and the result is at least\n // coherent; \"write only the differences\" between unrelated vaults is not a\n // restore, it is a silent union of two histories, and the keyrings that\n // arrive with it would not open what is already here.\n if (mode === 'incremental' && backup._compartment !== ctx.vault) {\n throw new BackupLedgerError(\n `Incremental load refused: this pod was taken from vault \"${backup._compartment}\" ` +\n `and is being loaded into \"${ctx.vault}\". Incremental mode reconciles a vault against ` +\n `its OWN pod; use mode: 'replace' to overwrite this vault with a foreign pod.`,\n )\n }\n\n // 1. Restore data collections.\n if (mode === 'incremental') {\n const localData = await ctx.adapter.loadAll(ctx.vault)\n const names = new Set([...Object.keys(backup.collections), ...Object.keys(localData)])\n for (const name of names) {\n const r = await reconcileCollection(ctx, name, backup.collections[name] ?? {})\n if (r.written || r.skipped || r.deleted) per[name] = r\n }\n } else {\n await ctx.adapter.saveAll(ctx.vault, backup.collections)\n }\n\n // 2. Restore keyrings.\n for (const [userId, keyringFile] of Object.entries(backup.keyrings)) {\n // ⛔ core#132 — NO CAS HERE, deliberately. A pod restore is state\n // REPLACEMENT (core#111 made the internal collections wholesale too): the\n // pod is authoritative and there is no \"version this was based on\" to\n // compare against. CASing a restore would make it fail precisely when the\n // store has drifted, which is the case it exists to fix.\n const envelope = buildRecordEnvelope({ collection: '_keyring', id: userId, version: 1 },\n { iv: '', data: JSON.stringify(keyringFile) })\n await ctx.adapter.put(ctx.vault, '_keyring', userId, envelope)\n }\n\n // 3. Restore internal collections (`_ledger`, `_ledger_deltas`, history,\n // periods, blobs). Required so verifyBackupIntegrity has the chain to walk.\n //\n // ⛔⛔ CLEAR FIRST (core#111). This used to `put` the pod's rows id by id and\n // leave everything else, so entries written AFTER the pod survived the\n // restore. With history on that is not a cosmetic leftover: the ledger chain\n // still named `notes/n2`, whose envelope `saveAll` had just removed, and the\n // integrity check refused the restore outright —\n // BackupCorruptedError: Ledger expects data record \"notes/n2\" to exist …\n // which made restoring an OLDER pod possible only onto a store whose ledger\n // had not moved. That is never the case that matters: a restore is a step\n // BACK (core#71/#72).\n //\n // ⭐ A restore rewinds the ledger too, and now says so. The internal\n // collections are replaced wholesale, the way `saveAll` already treats the\n // data ones — anything else asks the chain to describe a store it does not\n // match. The names come from `internalCollectionNames`, NOT from the pod's\n // own keys: see the ⛔ on that function for why absence in a pod cannot mean\n // \"leave it alone\".\n //\n // ⚠️ Known residue, deliberately not chased here: `_blob_slots_<c>` /\n // `_blob_versions_<c>` for a DATA collection the pod does not carry are not\n // cleared, because the names are derived from the pod's collections and the\n // store contract has no way to enumerate `_`-prefixed collections\n // (`loadAll` skips them). Those rows are already orphaned — `saveAll` has\n // just removed the collection they describe — so they are unreachable\n // rather than misleading.\n //\n // core#77 — in INCREMENTAL mode the same names are reconciled instead of\n // cleared and rewritten. ⭐ This is the half that matters for the 10 GB\n // case: `_blob_chunks` is an internal collection, so a clear-and-rewrite\n // here would re-upload every chunk and leave \"incremental\" saving only the\n // record envelopes. Reconciling reaches the SAME end state — extras are\n // still deleted, so the restore still rewinds — at a cost proportional to\n // what actually differs.\n const internalNamesToLoad = internalCollectionNames(Object.keys(backup.collections))\n if (mode === 'incremental') {\n for (const internalName of internalNamesToLoad) {\n const r = await reconcileCollection(ctx, internalName, backup._internal?.[internalName] ?? {})\n if (r.written || r.skipped || r.deleted) per[internalName] = r\n }\n } else {\n for (const internalName of internalNamesToLoad) {\n for (const id of await ctx.adapter.list(ctx.vault, internalName)) {\n await ctx.adapter.delete(ctx.vault, internalName, id)\n }\n }\n if (backup._internal) {\n for (const [internalName, records] of Object.entries(backup._internal)) {\n for (const [id, envelope] of Object.entries(records)) {\n await ctx.adapter.put(ctx.vault, internalName, id, envelope)\n }\n }\n }\n }\n\n // 4. Refresh the in-memory keyring from the freshly-loaded\n // keyring file. Without this, the Vault's getDEK\n // closure still holds the OLD session's DEKs, and every\n // decrypt of a loaded ledger entry / data envelope fails\n // with TamperedError because the DEK doesn't match the\n // ciphertext that was encrypted with the SOURCE user's DEK.\n // Skipped for plaintext vaults and for tests that\n // construct Vault without a reloadKeyring callback.\n await ctx.reloadKeyringAndRebuildDEK()\n\n // 5. Clear collection cache + reset the ledger store so the\n // next ledger() call rebuilds its head cache from the\n // freshly-loaded entries.\n ctx.clearCollectionCache()\n ctx.resetLedgerStore()\n\n // 6. core#71 — a restore is a new base for sync: the pre-restore dirty log\n // named records the load replaced, and the watermarks described a state\n // that is gone. `replaceRemote` (core#72) is the explicit act that makes\n // the restore authoritative on the target; without it, `load()` stays a\n // local view — and now says so in `syncTargetStatus()` instead of pushing\n // stale entries.\n await ctx.resetSync?.()\n\n // 5. Run the verification gate. A backup with no ledgerHead cannot be\n // integrity-checked, and skipping silently would collapse\n // *unverifiable* into *clean* — so it always warns. But the REMEDY\n // depends on the reader, not the pod (#1303): the pod cannot say\n // whether its exporter predates the ledger or never enabled it, and\n // the reader knows its own configuration.\n //\n // - Reader HAS the ledger: the pod is behind it. \"Re-export\" is\n // actionable; keep the migration wording.\n // - Reader has NO ledger: nothing is stale and nothing is migrating —\n // the consumer priced the ledger (#1248 measured ~2.4x) and declined.\n // Prescribing a re-export is advice they should not take, and\n // repeating it on every read trains people to filter the one line\n // that also fires on a genuinely stale pod. State the consequence,\n // name the discriminator, prescribe nothing.\n if (!backup.ledgerHead) {\n if (ctx.getLedgerOrNull()) {\n console.warn(\n `[noy-db] Loaded a legacy backup with no ledgerHead — ` +\n `verifiable-backup integrity check skipped. ` +\n `Re-export with a ledger-aware build to get tamper detection.`,\n )\n } else {\n console.warn(\n `[noy-db] Loaded a backup with no ledgerHead — this pod is not integrity-checked. ` +\n `This reader has no ledger enabled (withHistory() is not configured), so nothing is stale: ` +\n `enable the ledger on both the exporter and this reader if tamper detection is wanted.`,\n )\n }\n return podReport(mode, per)\n }\n\n const result = await verifyBackupIntegrity(ctx)\n if (!result.ok) {\n // Surface the most specific error class we can. The result\n // shape carries enough info for callers to inspect.\n if (result.kind === 'data') {\n throw new BackupCorruptedError(\n result.collection,\n result.id,\n result.message,\n )\n }\n throw new BackupLedgerError(result.message, result.divergedAt)\n }\n\n // 6. Cross-check: the freshly-verified head must match the\n // value embedded at dump time. A mismatch means someone\n // truncated or extended the chain after dump.\n if (result.head !== backup.ledgerHead.hash) {\n throw new BackupLedgerError(\n `Backup ledger head mismatch: embedded \"${backup.ledgerHead.hash}\" ` +\n `but reconstructed \"${result.head}\".`,\n )\n }\n return podReport(mode, per)\n}\n\n/**\n * End-to-end backup integrity check: `ledger.verify()` (hash chain) plus a data\n * envelope cross-check (every current record's `_data` hash must match the\n * latest `put` entry's `payloadHash`). Returns a discriminated union so callers\n * can distinguish chain vs data failures.\n */\nexport async function verifyBackupIntegrity(ctx: BackupContext): Promise<VerifyBackupResult> {\n // Step 1: chain verification. Without the history strategy there\n // is no ledger; an unaudited backup verifies trivially as `ok`\n // because there's nothing to diverge from.\n const ledgerForVerify = ctx.getLedgerOrNull()\n if (!ledgerForVerify) {\n return { ok: true, head: '', length: 0 }\n }\n const chainResult = await ledgerForVerify.verify()\n if (!chainResult.ok) {\n return {\n ok: false,\n kind: 'chain',\n divergedAt: chainResult.divergedAt,\n message:\n `Ledger chain diverged at index ${chainResult.divergedAt}: ` +\n `expected prevHash \"${chainResult.expected}\" but found \"${chainResult.actual}\".`,\n }\n }\n\n // Step 2: data envelope cross-check. Walk every entry in the\n // ledger and, for the LATEST `put` per (collection, id), recompute\n // the data envelope's payloadHash and compare. Earlier puts of the\n // same id are skipped because the data collection only holds the\n // current version — historical envelopes live in the deltas\n // collection (which is itself protected by the chain).\n // Reuse the ledger we already resolved in step 1.\n const allEntries = await ledgerForVerify.loadAllEntries()\n\n // Find the latest non-delete entry per (collection, id). Walk\n // the entries in reverse so we hit the latest first; mark each\n // (collection, id) as seen and skip subsequent entries.\n const seen = new Set<string>()\n const latest = new Map<\n string,\n { collection: string; id: string; expectedHash: string }\n >()\n for (let i = allEntries.length - 1; i >= 0; i--) {\n const entry = allEntries[i]\n if (!entry) continue\n // Amendment entries are multi-record audit entries whose\n // `collection` and `id` are empty strings — building a `\"/\"`\n // key here would mark that synthetic slot as seen and falsely\n // trip the data check on a record that never existed. Skip\n // them BEFORE the key/seen bookkeeping so they neither\n // tombstone real entries nor enter the latest map.\n if (entry.op === 'amendment' || entry.op === 'lifecycle') continue\n const key = `${entry.collection}/${entry.id}`\n if (seen.has(key)) continue\n seen.add(key)\n // For deletes the data collection should NOT have the record,\n // so we skip — there's nothing to cross-check. Marking the key\n // as seen above ensures any earlier `put` of the same id is\n // also skipped (the record was subsequently deleted).\n if (entry.op === 'delete') continue\n latest.set(key, {\n collection: entry.collection,\n id: entry.id,\n expectedHash: entry.payloadHash,\n })\n }\n\n for (const { collection, id, expectedHash } of latest.values()) {\n const envelope = await ctx.adapter.get(ctx.vault, collection, id)\n if (!envelope) {\n return {\n ok: false,\n kind: 'data',\n collection,\n id,\n message:\n `Ledger expects data record \"${collection}/${id}\" to exist, ` +\n `but the adapter has no envelope for it.`,\n }\n }\n const actualHash = await ctx.envelopePayloadHash(envelope)\n if (actualHash !== expectedHash) {\n return {\n ok: false,\n kind: 'data',\n collection,\n id,\n message:\n `Data envelope \"${collection}/${id}\" has been tampered with: ` +\n `expected payloadHash \"${expectedHash}\", got \"${actualHash}\".`,\n }\n }\n }\n\n return {\n ok: true,\n head: chainResult.head,\n length: chainResult.length,\n }\n}\n\n/**\n * Plaintext per-collection export, built on the vault's `exportStream`. Forces\n * collection granularity (record-by-record output makes no sense in a single\n * string) and merges dictionary snapshots across collections.\n */\nexport async function exportVaultJSON(ctx: BackupContext, opts: ExportStreamOptions = {}): Promise<string> {\n // Force per-collection granularity regardless of caller setting:\n // record-by-record output doesn't make sense in a single string.\n const collections: Record<\n string,\n {\n schema: null\n refs: Record<string, { target: string; mode: 'strict' | 'warn' | 'cascade' }>\n records: unknown[]\n }\n > = {}\n let ledgerHead: ExportChunk['ledgerHead'] | undefined\n // Merged dictionary snapshot across all collections.\n // Only populated when `resolveLabels` is not set.\n const allDictionaries: Record<\n string, // collection name\n Record<string, Record<string, Record<string, string>>>\n > = {}\n\n for await (const chunk of ctx.exportStream({\n granularity: 'collection',\n withLedgerHead: opts.withLedgerHead === true,\n // Thread the export locale so records are read at the\n // `export` layer (i18nText collapsed + dictKey/staticDict labels resolved).\n ...(opts.resolveLabels !== undefined ? { resolveLabels: opts.resolveLabels } : {}),\n })) {\n collections[chunk.collection] = {\n schema: null, // Standard Schema validators are not JSON-serializable\n refs: chunk.refs,\n records: chunk.records,\n }\n if (chunk.ledgerHead) ledgerHead = chunk.ledgerHead\n // Collect dictionary snapshots unless resolveLabels is set\n if (!opts.resolveLabels && chunk.dictionaries) {\n allDictionaries[chunk.collection] = chunk.dictionaries\n }\n }\n\n const hasDictionaries = Object.keys(allDictionaries).length > 0\n return JSON.stringify({\n _noydb_export: 1,\n _compartment: ctx.vault,\n _exported_at: new Date().toISOString(),\n _exported_by: ctx.userId(),\n collections,\n ...(hasDictionaries ? { _dictionaries: allDictionaries } : {}),\n ...(ledgerHead ? { ledgerHead } : {}),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,SAAS,wBAAwB,iBAA8C;AAC7E,SAAO;AAAA,IACL;AAAA,IAAmB;AAAA,IAA0B;AAAA,IAAoB;AAAA,IACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IACA;AAAA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