@fireproof/core 0.19.121 → 0.20.0-dev-preview-05
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/README.md +13 -12
 - package/deno/index.d.ts +7 -0
 - package/deno/index.js +66 -0
 - package/deno/index.js.map +1 -0
 - package/deno/metafile-esm.json +1 -0
 - package/deno.json +2 -3
 - package/index.cjs +1827 -1059
 - package/index.cjs.map +1 -1
 - package/index.d.cts +747 -334
 - package/index.d.ts +747 -334
 - package/index.js +1800 -1034
 - package/index.js.map +1 -1
 - package/metafile-cjs.json +1 -1
 - package/metafile-esm.json +1 -1
 - package/node/index.cjs +16 -293
 - package/node/index.cjs.map +1 -1
 - package/node/index.d.cts +4 -40
 - package/node/index.d.ts +4 -40
 - package/node/index.js +22 -237
 - package/node/index.js.map +1 -1
 - package/node/metafile-cjs.json +1 -1
 - package/node/metafile-esm.json +1 -1
 - package/package.json +14 -6
 - package/react/index.cjs +22 -22
 - package/react/index.cjs.map +1 -1
 - package/react/index.d.cts +7 -7
 - package/react/index.d.ts +7 -7
 - package/react/index.js +22 -22
 - package/react/index.js.map +1 -1
 - package/react/metafile-cjs.json +1 -1
 - package/react/metafile-esm.json +1 -1
 - package/tests/blockstore/fp-envelope.test.ts-off +65 -0
 - package/tests/blockstore/interceptor-gateway.test.ts +122 -0
 - package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
 - package/tests/blockstore/keyed-crypto.test.ts +73 -118
 - package/tests/blockstore/loader.test.ts +18 -9
 - package/tests/blockstore/store.test.ts +40 -31
 - package/tests/blockstore/transaction.test.ts +14 -13
 - package/tests/fireproof/all-gateway.test.ts +286 -216
 - package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
 - package/tests/fireproof/crdt.test.ts +78 -19
 - package/tests/fireproof/fireproof.test.ts +111 -92
 - package/tests/fireproof/hello.test.ts +21 -17
 - package/tests/fireproof/indexer.test.ts +74 -50
 - package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
 - package/tests/fireproof/multiple-ledger.test.ts +2 -2
 - package/tests/fireproof/utils.test.ts +47 -6
 - package/tests/gateway/file/loader-config.test.ts +307 -0
 - package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
 - package/tests/gateway/indexdb/loader-config.test.ts +79 -0
 - package/tests/helpers.ts +44 -17
 - package/tests/react/useFireproof.test.tsx +2 -2
 - package/tests/www/gallery.html +2 -2
 - package/tests/www/todo-aws.html +1 -1
 - package/tests/www/todo-ipfs.html +1 -1
 - package/tests/www/todo-local.html +1 -1
 - package/tests/www/todo.html +25 -4
 - package/web/index.cjs +102 -116
 - package/web/index.cjs.map +1 -1
 - package/web/index.d.cts +15 -29
 - package/web/index.d.ts +15 -29
 - package/web/index.js +91 -105
 - package/web/index.js.map +1 -1
 - package/web/metafile-cjs.json +1 -1
 - package/web/metafile-esm.json +1 -1
 - package/node/chunk-4A4RAVNS.js +0 -17
 - package/node/chunk-4A4RAVNS.js.map +0 -1
 - package/node/mem-filesystem-LPPT7QV5.js +0 -40
 - package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
 - package/tests/fireproof/config.test.ts +0 -163
 - /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
 
| 
         @@ -0,0 +1,307 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import { BuildURI, CoerceURI, URI } from "@adviser/cement";
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { fireproof, PARAM, rt, SuperThis } from "@fireproof/core";
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { mockSuperThis } from "../../helpers.js";
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI {
         
     | 
| 
      
 6 
     | 
    
         
            +
              if (!base) {
         
     | 
| 
      
 7 
     | 
    
         
            +
                const home = sthis.env.get("HOME") || "./";
         
     | 
| 
      
 8 
     | 
    
         
            +
                base =
         
     | 
| 
      
 9 
     | 
    
         
            +
                  sthis.env.get("FP_STORAGE_URL") ||
         
     | 
| 
      
 10 
     | 
    
         
            +
                  `file://${sthis.pathOps.join(home, ".fireproof", rt.FILESTORE_VERSION.replace(/-.*$/, ""))}?${PARAM.URL_GEN}=default`;
         
     | 
| 
      
 11 
     | 
    
         
            +
              }
         
     | 
| 
      
 12 
     | 
    
         
            +
              return URI.from(base.toString())
         
     | 
| 
      
 13 
     | 
    
         
            +
                .build()
         
     | 
| 
      
 14 
     | 
    
         
            +
                .setParam(PARAM.NAME, name || "")
         
     | 
| 
      
 15 
     | 
    
         
            +
                .URI();
         
     | 
| 
      
 16 
     | 
    
         
            +
            }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            const _my_app = "my-app";
         
     | 
| 
      
 19 
     | 
    
         
            +
            function my_app() {
         
     | 
| 
      
 20 
     | 
    
         
            +
              return _my_app;
         
     | 
| 
      
 21 
     | 
    
         
            +
            }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            describe("config file gateway", () => {
         
     | 
| 
      
 24 
     | 
    
         
            +
              const sthis = mockSuperThis();
         
     | 
| 
      
 25 
     | 
    
         
            +
              // const isMemFS: { fs?: string } = {};
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              beforeAll(async () => {
         
     | 
| 
      
 28 
     | 
    
         
            +
                await sthis.start();
         
     | 
| 
      
 29 
     | 
    
         
            +
                // const url = URI.from(sthis.env.get("FP_STORAGE_URL"));
         
     | 
| 
      
 30 
     | 
    
         
            +
                // if (url.getParam("fs") === "mem") {
         
     | 
| 
      
 31 
     | 
    
         
            +
                //   isMemFS.fs = "mem";
         
     | 
| 
      
 32 
     | 
    
         
            +
                // }
         
     | 
| 
      
 33 
     | 
    
         
            +
              });
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              it("loader", async () => {
         
     | 
| 
      
 36 
     | 
    
         
            +
                const db = fireproof(my_app());
         
     | 
| 
      
 37 
     | 
    
         
            +
                await db.put({ name: "my-app" });
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect(db.name).toBe(my_app());
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                const fileStore = await db.crdt.blockstore.loader?.fileStore();
         
     | 
| 
      
 41 
     | 
    
         
            +
                expect(fileStore?.url().asObj()).toEqual({
         
     | 
| 
      
 42 
     | 
    
         
            +
                  pathname: "./dist/fp-dir-file",
         
     | 
| 
      
 43 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 44 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 45 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 46 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 47 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 48 
     | 
    
         
            +
                    storekey: "@my-app-data@",
         
     | 
| 
      
 49 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 50 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 51 
     | 
    
         
            +
                  },
         
     | 
| 
      
 52 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 53 
     | 
    
         
            +
                });
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                const dataStore = await db.crdt.blockstore.loader?.carStore();
         
     | 
| 
      
 56 
     | 
    
         
            +
                expect(dataStore?.url().asObj()).toEqual({
         
     | 
| 
      
 57 
     | 
    
         
            +
                  pathname: "./dist/fp-dir-file",
         
     | 
| 
      
 58 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 59 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 60 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 61 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 62 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 63 
     | 
    
         
            +
                    suffix: ".car",
         
     | 
| 
      
 64 
     | 
    
         
            +
                    storekey: "@my-app-data@",
         
     | 
| 
      
 65 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 66 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 67 
     | 
    
         
            +
                  },
         
     | 
| 
      
 68 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 69 
     | 
    
         
            +
                });
         
     | 
| 
      
 70 
     | 
    
         
            +
                const metaStore = await db.crdt.blockstore.loader?.metaStore();
         
     | 
| 
      
 71 
     | 
    
         
            +
                expect(metaStore?.url().asObj()).toEqual({
         
     | 
| 
      
 72 
     | 
    
         
            +
                  pathname: "./dist/fp-dir-file",
         
     | 
| 
      
 73 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 74 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 75 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 76 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 77 
     | 
    
         
            +
                    store: "meta",
         
     | 
| 
      
 78 
     | 
    
         
            +
                    storekey: "@my-app-meta@",
         
     | 
| 
      
 79 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 80 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 81 
     | 
    
         
            +
                  },
         
     | 
| 
      
 82 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 83 
     | 
    
         
            +
                });
         
     | 
| 
      
 84 
     | 
    
         
            +
                const WALStore = await db.crdt.blockstore.loader?.WALStore();
         
     | 
| 
      
 85 
     | 
    
         
            +
                expect(WALStore?.url().asObj()).toEqual({
         
     | 
| 
      
 86 
     | 
    
         
            +
                  pathname: "./dist/fp-dir-file",
         
     | 
| 
      
 87 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 88 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 89 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 90 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 91 
     | 
    
         
            +
                    store: "wal",
         
     | 
| 
      
 92 
     | 
    
         
            +
                    storekey: "@my-app-wal@",
         
     | 
| 
      
 93 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 94 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 95 
     | 
    
         
            +
                  },
         
     | 
| 
      
 96 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 97 
     | 
    
         
            +
                });
         
     | 
| 
      
 98 
     | 
    
         
            +
                await db.close();
         
     | 
| 
      
 99 
     | 
    
         
            +
              });
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
              it("file path", async () => {
         
     | 
| 
      
 102 
     | 
    
         
            +
                let baseDir = "./dist/data".replace(/\?.*$/, "").replace(/^file:\/\//, "");
         
     | 
| 
      
 103 
     | 
    
         
            +
                baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
         
     | 
| 
      
 104 
     | 
    
         
            +
                const base = BuildURI.from("./dist/data");
         
     | 
| 
      
 105 
     | 
    
         
            +
                // if (isMemFS.fs) {
         
     | 
| 
      
 106 
     | 
    
         
            +
                //   base.setParam("fs", isMemFS.fs);
         
     | 
| 
      
 107 
     | 
    
         
            +
                // }
         
     | 
| 
      
 108 
     | 
    
         
            +
                const sysfs = await rt.gw.file.sysFileSystemFactory(base.URI());
         
     | 
| 
      
 109 
     | 
    
         
            +
                await sysfs.rm(baseDir, { recursive: true }).catch(() => {
         
     | 
| 
      
 110 
     | 
    
         
            +
                  /* */
         
     | 
| 
      
 111 
     | 
    
         
            +
                });
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                const db = fireproof(my_app(), { storeUrls: { base } });
         
     | 
| 
      
 114 
     | 
    
         
            +
                // console.log(`>>>>>>>>>>>>>>>file-path`)
         
     | 
| 
      
 115 
     | 
    
         
            +
                await db.put({ name: "my-app" });
         
     | 
| 
      
 116 
     | 
    
         
            +
                expect(db.name).toBe(my_app());
         
     | 
| 
      
 117 
     | 
    
         
            +
                const carStore = await db.crdt.blockstore.loader?.carStore();
         
     | 
| 
      
 118 
     | 
    
         
            +
                expect(carStore?.url().asObj()).toEqual({
         
     | 
| 
      
 119 
     | 
    
         
            +
                  pathname: "./dist/data",
         
     | 
| 
      
 120 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 121 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 122 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 123 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 124 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 125 
     | 
    
         
            +
                    storekey: "@my-app-data@",
         
     | 
| 
      
 126 
     | 
    
         
            +
                    suffix: ".car",
         
     | 
| 
      
 127 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 128 
     | 
    
         
            +
                  },
         
     | 
| 
      
 129 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 130 
     | 
    
         
            +
                });
         
     | 
| 
      
 131 
     | 
    
         
            +
                const fileStore = await db.crdt.blockstore.loader?.fileStore();
         
     | 
| 
      
 132 
     | 
    
         
            +
                expect(fileStore?.url().asObj()).toEqual({
         
     | 
| 
      
 133 
     | 
    
         
            +
                  pathname: "./dist/data",
         
     | 
| 
      
 134 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 135 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 136 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 137 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 138 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 139 
     | 
    
         
            +
                    storekey: "@my-app-data@",
         
     | 
| 
      
 140 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 141 
     | 
    
         
            +
                  },
         
     | 
| 
      
 142 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 143 
     | 
    
         
            +
                });
         
     | 
| 
      
 144 
     | 
    
         
            +
                expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
         
     | 
| 
      
 145 
     | 
    
         
            +
                const metaStore = await db.crdt.blockstore.loader?.metaStore();
         
     | 
| 
      
 146 
     | 
    
         
            +
                expect(metaStore?.url().asObj()).toEqual({
         
     | 
| 
      
 147 
     | 
    
         
            +
                  pathname: "./dist/data",
         
     | 
| 
      
 148 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 149 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 150 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 151 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 152 
     | 
    
         
            +
                    store: "meta",
         
     | 
| 
      
 153 
     | 
    
         
            +
                    storekey: "@my-app-meta@",
         
     | 
| 
      
 154 
     | 
    
         
            +
                    version: "v0.19-file",
         
     | 
| 
      
 155 
     | 
    
         
            +
                  },
         
     | 
| 
      
 156 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 157 
     | 
    
         
            +
                });
         
     | 
| 
      
 158 
     | 
    
         
            +
                expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
         
     | 
| 
      
 159 
     | 
    
         
            +
                await db.close();
         
     | 
| 
      
 160 
     | 
    
         
            +
              });
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
              it("homedir default", async () => {
         
     | 
| 
      
 163 
     | 
    
         
            +
                const old = sthis.env.get("FP_STORAGE_URL");
         
     | 
| 
      
 164 
     | 
    
         
            +
                sthis.env.delete("FP_STORAGE_URL");
         
     | 
| 
      
 165 
     | 
    
         
            +
                // this switches file: protocol not memory:
         
     | 
| 
      
 166 
     | 
    
         
            +
                let baseDir = dataDir(sthis, my_app()).pathname;
         
     | 
| 
      
 167 
     | 
    
         
            +
                baseDir = sthis.pathOps.join(baseDir, my_app());
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                const base = BuildURI.from(baseDir);
         
     | 
| 
      
 170 
     | 
    
         
            +
                // if (isMemFS.fs) {
         
     | 
| 
      
 171 
     | 
    
         
            +
                //   base.setParam("fs", isMemFS.fs);
         
     | 
| 
      
 172 
     | 
    
         
            +
                // }
         
     | 
| 
      
 173 
     | 
    
         
            +
                const sysfs = await rt.gw.file.sysFileSystemFactory(base.URI());
         
     | 
| 
      
 174 
     | 
    
         
            +
                await sysfs.rm(baseDir, { recursive: true }).catch(() => {
         
     | 
| 
      
 175 
     | 
    
         
            +
                  /* */
         
     | 
| 
      
 176 
     | 
    
         
            +
                });
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
                expect(baseDir).toMatch(new RegExp(`/\\.fireproof/${rt.FILESTORE_VERSION.replace(/-file/, "")}/${my_app()}`));
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                const db = fireproof(my_app());
         
     | 
| 
      
 181 
     | 
    
         
            +
                await db.put({ name: "my-app" });
         
     | 
| 
      
 182 
     | 
    
         
            +
                expect(db.name).toBe(my_app());
         
     | 
| 
      
 183 
     | 
    
         
            +
                const carStore = await db.crdt.blockstore.loader?.carStore();
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
                expect(carStore?.url().asObj()).toEqual({
         
     | 
| 
      
 186 
     | 
    
         
            +
                  pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
         
     | 
| 
      
 187 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 188 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 189 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 190 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 191 
     | 
    
         
            +
                    suffix: ".car",
         
     | 
| 
      
 192 
     | 
    
         
            +
                    runtime: "node",
         
     | 
| 
      
 193 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 194 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 195 
     | 
    
         
            +
                    name: my_app(),
         
     | 
| 
      
 196 
     | 
    
         
            +
                    storekey: `@${my_app()}-data@`,
         
     | 
| 
      
 197 
     | 
    
         
            +
                    version: rt.FILESTORE_VERSION,
         
     | 
| 
      
 198 
     | 
    
         
            +
                  },
         
     | 
| 
      
 199 
     | 
    
         
            +
                });
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
                const fileStore = await db.crdt.blockstore.loader?.fileStore();
         
     | 
| 
      
 204 
     | 
    
         
            +
                expect(fileStore?.url().asObj()).toEqual({
         
     | 
| 
      
 205 
     | 
    
         
            +
                  pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
         
     | 
| 
      
 206 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 207 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 208 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 209 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 210 
     | 
    
         
            +
                    runtime: "node",
         
     | 
| 
      
 211 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 212 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 213 
     | 
    
         
            +
                    name: my_app(),
         
     | 
| 
      
 214 
     | 
    
         
            +
                    storekey: `@${my_app()}-data@`,
         
     | 
| 
      
 215 
     | 
    
         
            +
                    version: rt.FILESTORE_VERSION,
         
     | 
| 
      
 216 
     | 
    
         
            +
                  },
         
     | 
| 
      
 217 
     | 
    
         
            +
                });
         
     | 
| 
      
 218 
     | 
    
         
            +
                const metaStore = await db.crdt.blockstore.loader?.metaStore();
         
     | 
| 
      
 219 
     | 
    
         
            +
                expect(metaStore?.url().asObj()).toEqual({
         
     | 
| 
      
 220 
     | 
    
         
            +
                  pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
         
     | 
| 
      
 221 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 222 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 223 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 224 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 225 
     | 
    
         
            +
                    runtime: "node",
         
     | 
| 
      
 226 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 227 
     | 
    
         
            +
                    store: "meta",
         
     | 
| 
      
 228 
     | 
    
         
            +
                    name: my_app(),
         
     | 
| 
      
 229 
     | 
    
         
            +
                    storekey: `@${my_app()}-meta@`,
         
     | 
| 
      
 230 
     | 
    
         
            +
                    version: rt.FILESTORE_VERSION,
         
     | 
| 
      
 231 
     | 
    
         
            +
                  },
         
     | 
| 
      
 232 
     | 
    
         
            +
                });
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
                expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
         
     | 
| 
      
 235 
     | 
    
         
            +
                sthis.env.set("FP_STORAGE_URL", old);
         
     | 
| 
      
 236 
     | 
    
         
            +
                await db.close();
         
     | 
| 
      
 237 
     | 
    
         
            +
              });
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
              it("set by env", async () => {
         
     | 
| 
      
 240 
     | 
    
         
            +
                const old = sthis.env.get("FP_STORAGE_URL");
         
     | 
| 
      
 241 
     | 
    
         
            +
                // assert(!old, "FP_STORAGE_URL must set")
         
     | 
| 
      
 242 
     | 
    
         
            +
                const testUrl = BuildURI.from(old);
         
     | 
| 
      
 243 
     | 
    
         
            +
                // sthis.env.set("FP_STORAGE_URL", testUrl.toString());
         
     | 
| 
      
 244 
     | 
    
         
            +
             
     | 
| 
      
 245 
     | 
    
         
            +
                let baseDir = dataDir(sthis, my_app()).pathname;
         
     | 
| 
      
 246 
     | 
    
         
            +
                baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
                const sysfs = await rt.gw.file.sysFileSystemFactory(testUrl.URI());
         
     | 
| 
      
 249 
     | 
    
         
            +
                await sysfs.rm(baseDir, { recursive: true }).catch(() => {
         
     | 
| 
      
 250 
     | 
    
         
            +
                  /* */
         
     | 
| 
      
 251 
     | 
    
         
            +
                });
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
                const db = fireproof(my_app());
         
     | 
| 
      
 254 
     | 
    
         
            +
                await db.put({ name: "my-app" });
         
     | 
| 
      
 255 
     | 
    
         
            +
                expect(db.name).toBe(my_app());
         
     | 
| 
      
 256 
     | 
    
         
            +
                const carStore = await db.crdt.blockstore.loader.carStore();
         
     | 
| 
      
 257 
     | 
    
         
            +
                expect(carStore?.url().asObj()).toEqual({
         
     | 
| 
      
 258 
     | 
    
         
            +
                  pathname: "./dist/fp-dir-file",
         
     | 
| 
      
 259 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 260 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 261 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 262 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 263 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 264 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 265 
     | 
    
         
            +
                    // runtime: "node",
         
     | 
| 
      
 266 
     | 
    
         
            +
                    suffix: ".car",
         
     | 
| 
      
 267 
     | 
    
         
            +
                    name: my_app(),
         
     | 
| 
      
 268 
     | 
    
         
            +
                    storekey: `@${my_app()}-data@`,
         
     | 
| 
      
 269 
     | 
    
         
            +
                    version: rt.FILESTORE_VERSION,
         
     | 
| 
      
 270 
     | 
    
         
            +
                  },
         
     | 
| 
      
 271 
     | 
    
         
            +
                });
         
     | 
| 
      
 272 
     | 
    
         
            +
             
     | 
| 
      
 273 
     | 
    
         
            +
                expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
         
     | 
| 
      
 274 
     | 
    
         
            +
                const fileStore = await db.crdt.blockstore.loader?.fileStore();
         
     | 
| 
      
 275 
     | 
    
         
            +
                expect(fileStore?.url().asObj()).toEqual({
         
     | 
| 
      
 276 
     | 
    
         
            +
                  pathname: `./dist/fp-dir-file`,
         
     | 
| 
      
 277 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 278 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 279 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 280 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 281 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 282 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 283 
     | 
    
         
            +
                    name: my_app(),
         
     | 
| 
      
 284 
     | 
    
         
            +
                    storekey: `@${my_app()}-data@`,
         
     | 
| 
      
 285 
     | 
    
         
            +
                    version: rt.FILESTORE_VERSION,
         
     | 
| 
      
 286 
     | 
    
         
            +
                  },
         
     | 
| 
      
 287 
     | 
    
         
            +
                });
         
     | 
| 
      
 288 
     | 
    
         
            +
             
     | 
| 
      
 289 
     | 
    
         
            +
                const metaStore = await db.crdt.blockstore.loader?.metaStore();
         
     | 
| 
      
 290 
     | 
    
         
            +
                expect(metaStore?.url().asObj()).toEqual({
         
     | 
| 
      
 291 
     | 
    
         
            +
                  pathname: `./dist/fp-dir-file`,
         
     | 
| 
      
 292 
     | 
    
         
            +
                  protocol: "file:",
         
     | 
| 
      
 293 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 294 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 295 
     | 
    
         
            +
                    // ...isMemFS,
         
     | 
| 
      
 296 
     | 
    
         
            +
                    urlGen: "fromEnv",
         
     | 
| 
      
 297 
     | 
    
         
            +
                    store: "meta",
         
     | 
| 
      
 298 
     | 
    
         
            +
                    name: my_app(),
         
     | 
| 
      
 299 
     | 
    
         
            +
                    storekey: `@${my_app()}-meta@`,
         
     | 
| 
      
 300 
     | 
    
         
            +
                    version: rt.FILESTORE_VERSION,
         
     | 
| 
      
 301 
     | 
    
         
            +
                  },
         
     | 
| 
      
 302 
     | 
    
         
            +
                });
         
     | 
| 
      
 303 
     | 
    
         
            +
                expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
         
     | 
| 
      
 304 
     | 
    
         
            +
                await db.close();
         
     | 
| 
      
 305 
     | 
    
         
            +
                sthis.env.set("FP_STORAGE_URL", old);
         
     | 
| 
      
 306 
     | 
    
         
            +
              });
         
     | 
| 
      
 307 
     | 
    
         
            +
            });
         
     | 
| 
         @@ -0,0 +1,256 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import { rt, bs } from "@fireproof/core";
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { mockSuperThis, simpleCID } from "../helpers.js";
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { BuildURI, Result } from "@adviser/cement";
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { toJSON } from "multiformats/link";
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            const FPEnvelopeType = bs.FPEnvelopeType;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            describe("storage-content", () => {
         
     | 
| 
      
 9 
     | 
    
         
            +
              const sthis = mockSuperThis();
         
     | 
| 
      
 10 
     | 
    
         
            +
              it("car", async () => {
         
     | 
| 
      
 11 
     | 
    
         
            +
                const raw = new Uint8Array([55, 56, 57]);
         
     | 
| 
      
 12 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Result.Ok(raw));
         
     | 
| 
      
 13 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 14 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
         
     | 
| 
      
 15 
     | 
    
         
            +
                expect(res.unwrap().payload).toEqual(raw);
         
     | 
| 
      
 16 
     | 
    
         
            +
              });
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              it("file", async () => {
         
     | 
| 
      
 19 
     | 
    
         
            +
                const raw = new Uint8Array([55, 56, 57]);
         
     | 
| 
      
 20 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data").URI(), Result.Ok(raw));
         
     | 
| 
      
 21 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 22 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.FILE);
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect(res.unwrap().payload).toEqual(raw);
         
     | 
| 
      
 24 
     | 
    
         
            +
              });
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it("meta", async () => {
         
     | 
| 
      
 27 
     | 
    
         
            +
                const ref = [
         
     | 
| 
      
 28 
     | 
    
         
            +
                  {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    cid: "bafyreiaqmtw5jfudn6r6dq7mcmytc2z5z3ggohcj3gco3omjsp3hr73fpy",
         
     | 
| 
      
 30 
     | 
    
         
            +
                    data: "MomRkYXRhoWZkYk1ldGFYU3siY2FycyI6W3siLyI6ImJhZzR5dnFhYmNpcWNod29zeXQ3dTJqMmxtcHpyM2w3aWRlaTU1YzNmNnJ2Z3U3cXRmYXRoMnl2NnZuaWtjeXEifV19Z3BhcmVudHOA",
         
     | 
| 
      
 31 
     | 
    
         
            +
                    parents: [(await simpleCID(sthis)).toString(), (await simpleCID(sthis)).toString()],
         
     | 
| 
      
 32 
     | 
    
         
            +
                  },
         
     | 
| 
      
 33 
     | 
    
         
            +
                ];
         
     | 
| 
      
 34 
     | 
    
         
            +
                const raw = sthis.txt.encode(JSON.stringify(ref));
         
     | 
| 
      
 35 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=meta").URI(), Result.Ok(raw));
         
     | 
| 
      
 36 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 37 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.META);
         
     | 
| 
      
 38 
     | 
    
         
            +
                const dbMetas = res.unwrap().payload as bs.DbMetaEvent[];
         
     | 
| 
      
 39 
     | 
    
         
            +
                expect(dbMetas.length).toBe(1);
         
     | 
| 
      
 40 
     | 
    
         
            +
                const dbMeta = dbMetas[0];
         
     | 
| 
      
 41 
     | 
    
         
            +
                expect(dbMeta.parents.map((i) => i.toString())).toStrictEqual(ref[0].parents);
         
     | 
| 
      
 42 
     | 
    
         
            +
                expect(dbMeta.eventCid.toString()).toEqual("bafyreiaqmtw5jfudn6r6dq7mcmytc2z5z3ggohcj3gco3omjsp3hr73fpy");
         
     | 
| 
      
 43 
     | 
    
         
            +
                expect(dbMeta.dbMeta.cars.map((i) => i.toString())).toEqual([
         
     | 
| 
      
 44 
     | 
    
         
            +
                  "bag4yvqabciqchwosyt7u2j2lmpzr3l7idei55c3f6rvgu7qtfath2yv6vnikcyq",
         
     | 
| 
      
 45 
     | 
    
         
            +
                ]);
         
     | 
| 
      
 46 
     | 
    
         
            +
              });
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
              it("wal", async () => {
         
     | 
| 
      
 49 
     | 
    
         
            +
                const ref = {
         
     | 
| 
      
 50 
     | 
    
         
            +
                  fileOperations: [
         
     | 
| 
      
 51 
     | 
    
         
            +
                    {
         
     | 
| 
      
 52 
     | 
    
         
            +
                      cid: "bafyreiaqmtw5jfudn6r6dq7mcmytc2z5z3ggohcj3gco3omjsp3hr73fpy",
         
     | 
| 
      
 53 
     | 
    
         
            +
                      public: false,
         
     | 
| 
      
 54 
     | 
    
         
            +
                    },
         
     | 
| 
      
 55 
     | 
    
         
            +
                  ],
         
     | 
| 
      
 56 
     | 
    
         
            +
                  noLoaderOps: [
         
     | 
| 
      
 57 
     | 
    
         
            +
                    {
         
     | 
| 
      
 58 
     | 
    
         
            +
                      cars: [
         
     | 
| 
      
 59 
     | 
    
         
            +
                        {
         
     | 
| 
      
 60 
     | 
    
         
            +
                          "/": "bag4yvqabciqchwosyt7u2j2lmpzr3l7idei55c3f6rvgu7qtfath2yv6vnikcyq",
         
     | 
| 
      
 61 
     | 
    
         
            +
                        },
         
     | 
| 
      
 62 
     | 
    
         
            +
                      ],
         
     | 
| 
      
 63 
     | 
    
         
            +
                    },
         
     | 
| 
      
 64 
     | 
    
         
            +
                  ],
         
     | 
| 
      
 65 
     | 
    
         
            +
                  operations: [
         
     | 
| 
      
 66 
     | 
    
         
            +
                    {
         
     | 
| 
      
 67 
     | 
    
         
            +
                      cars: [{ "/": "bag4yvqabciqchwosyt7u2j2lmpzr3l7idei55c3f6rvgu7qtfath2yv6vnikcyq" }],
         
     | 
| 
      
 68 
     | 
    
         
            +
                    },
         
     | 
| 
      
 69 
     | 
    
         
            +
                  ],
         
     | 
| 
      
 70 
     | 
    
         
            +
                };
         
     | 
| 
      
 71 
     | 
    
         
            +
                const raw = sthis.txt.encode(JSON.stringify(ref));
         
     | 
| 
      
 72 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=wal").URI(), Result.Ok(raw));
         
     | 
| 
      
 73 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 74 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.WAL);
         
     | 
| 
      
 75 
     | 
    
         
            +
                const walstate = res.unwrap().payload as bs.WALState;
         
     | 
| 
      
 76 
     | 
    
         
            +
                expect(
         
     | 
| 
      
 77 
     | 
    
         
            +
                  walstate.fileOperations.map((i) => ({
         
     | 
| 
      
 78 
     | 
    
         
            +
                    ...i,
         
     | 
| 
      
 79 
     | 
    
         
            +
                    cid: i.cid.toString(),
         
     | 
| 
      
 80 
     | 
    
         
            +
                  })),
         
     | 
| 
      
 81 
     | 
    
         
            +
                ).toEqual(ref.fileOperations);
         
     | 
| 
      
 82 
     | 
    
         
            +
                expect(
         
     | 
| 
      
 83 
     | 
    
         
            +
                  walstate.noLoaderOps.map((i) => ({
         
     | 
| 
      
 84 
     | 
    
         
            +
                    cars: i.cars.map((i) => toJSON(i)),
         
     | 
| 
      
 85 
     | 
    
         
            +
                  })),
         
     | 
| 
      
 86 
     | 
    
         
            +
                ).toEqual(ref.noLoaderOps);
         
     | 
| 
      
 87 
     | 
    
         
            +
                expect(
         
     | 
| 
      
 88 
     | 
    
         
            +
                  walstate.operations.map((i) => ({
         
     | 
| 
      
 89 
     | 
    
         
            +
                    cars: i.cars.map((i) => toJSON(i)),
         
     | 
| 
      
 90 
     | 
    
         
            +
                  })),
         
     | 
| 
      
 91 
     | 
    
         
            +
                ).toEqual(ref.operations);
         
     | 
| 
      
 92 
     | 
    
         
            +
              });
         
     | 
| 
      
 93 
     | 
    
         
            +
            });
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            describe("de-serialize", () => {
         
     | 
| 
      
 96 
     | 
    
         
            +
              const sthis = mockSuperThis();
         
     | 
| 
      
 97 
     | 
    
         
            +
              it("car", async () => {
         
     | 
| 
      
 98 
     | 
    
         
            +
                const msg = {
         
     | 
| 
      
 99 
     | 
    
         
            +
                  type: FPEnvelopeType.CAR,
         
     | 
| 
      
 100 
     | 
    
         
            +
                  payload: new Uint8Array([55, 56, 57]),
         
     | 
| 
      
 101 
     | 
    
         
            +
                } satisfies bs.FPEnvelopeCar;
         
     | 
| 
      
 102 
     | 
    
         
            +
                const res = await rt.gw.fpSerialize(sthis, msg);
         
     | 
| 
      
 103 
     | 
    
         
            +
                expect(res.Ok()).toEqual(msg.payload);
         
     | 
| 
      
 104 
     | 
    
         
            +
              });
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
              it("file", async () => {
         
     | 
| 
      
 107 
     | 
    
         
            +
                const msg = {
         
     | 
| 
      
 108 
     | 
    
         
            +
                  type: FPEnvelopeType.FILE,
         
     | 
| 
      
 109 
     | 
    
         
            +
                  payload: new Uint8Array([55, 56, 57]),
         
     | 
| 
      
 110 
     | 
    
         
            +
                } satisfies bs.FPEnvelopeFile;
         
     | 
| 
      
 111 
     | 
    
         
            +
                const res = await rt.gw.fpSerialize(sthis, msg);
         
     | 
| 
      
 112 
     | 
    
         
            +
                expect(res.Ok()).toEqual(msg.payload);
         
     | 
| 
      
 113 
     | 
    
         
            +
              });
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
              it("meta", async () => {
         
     | 
| 
      
 116 
     | 
    
         
            +
                const msg = {
         
     | 
| 
      
 117 
     | 
    
         
            +
                  type: FPEnvelopeType.META,
         
     | 
| 
      
 118 
     | 
    
         
            +
                  payload: [
         
     | 
| 
      
 119 
     | 
    
         
            +
                    await bs.createDbMetaEvent(
         
     | 
| 
      
 120 
     | 
    
         
            +
                      sthis,
         
     | 
| 
      
 121 
     | 
    
         
            +
                      {
         
     | 
| 
      
 122 
     | 
    
         
            +
                        cars: [await simpleCID(sthis)],
         
     | 
| 
      
 123 
     | 
    
         
            +
                      },
         
     | 
| 
      
 124 
     | 
    
         
            +
                      [await simpleCID(sthis), await simpleCID(sthis)],
         
     | 
| 
      
 125 
     | 
    
         
            +
                    ),
         
     | 
| 
      
 126 
     | 
    
         
            +
                  ],
         
     | 
| 
      
 127 
     | 
    
         
            +
                } satisfies bs.FPEnvelopeMeta;
         
     | 
| 
      
 128 
     | 
    
         
            +
                const ser = await rt.gw.fpSerialize(sthis, msg);
         
     | 
| 
      
 129 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=meta").URI(), ser);
         
     | 
| 
      
 130 
     | 
    
         
            +
                const dbMetas = res.unwrap().payload as bs.DbMetaEvent[];
         
     | 
| 
      
 131 
     | 
    
         
            +
                expect(dbMetas.length).toBe(1);
         
     | 
| 
      
 132 
     | 
    
         
            +
                const dbMeta = dbMetas[0];
         
     | 
| 
      
 133 
     | 
    
         
            +
                expect(dbMeta.parents).toEqual(msg.payload[0].parents);
         
     | 
| 
      
 134 
     | 
    
         
            +
                expect(dbMeta.dbMeta).toEqual(msg.payload[0].dbMeta);
         
     | 
| 
      
 135 
     | 
    
         
            +
                expect(dbMeta.eventCid).toEqual(msg.payload[0].eventCid);
         
     | 
| 
      
 136 
     | 
    
         
            +
              });
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
              it("wal", async () => {
         
     | 
| 
      
 139 
     | 
    
         
            +
                const msg = {
         
     | 
| 
      
 140 
     | 
    
         
            +
                  type: FPEnvelopeType.WAL,
         
     | 
| 
      
 141 
     | 
    
         
            +
                  payload: {
         
     | 
| 
      
 142 
     | 
    
         
            +
                    fileOperations: [
         
     | 
| 
      
 143 
     | 
    
         
            +
                      {
         
     | 
| 
      
 144 
     | 
    
         
            +
                        cid: await simpleCID(sthis),
         
     | 
| 
      
 145 
     | 
    
         
            +
                        public: false,
         
     | 
| 
      
 146 
     | 
    
         
            +
                      },
         
     | 
| 
      
 147 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 148 
     | 
    
         
            +
                    noLoaderOps: [
         
     | 
| 
      
 149 
     | 
    
         
            +
                      {
         
     | 
| 
      
 150 
     | 
    
         
            +
                        cars: [await simpleCID(sthis)],
         
     | 
| 
      
 151 
     | 
    
         
            +
                      },
         
     | 
| 
      
 152 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 153 
     | 
    
         
            +
                    operations: [
         
     | 
| 
      
 154 
     | 
    
         
            +
                      {
         
     | 
| 
      
 155 
     | 
    
         
            +
                        cars: [await simpleCID(sthis)],
         
     | 
| 
      
 156 
     | 
    
         
            +
                      },
         
     | 
| 
      
 157 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 158 
     | 
    
         
            +
                  },
         
     | 
| 
      
 159 
     | 
    
         
            +
                } satisfies bs.FPEnvelopeWAL;
         
     | 
| 
      
 160 
     | 
    
         
            +
                const ser = await rt.gw.fpSerialize(sthis, msg);
         
     | 
| 
      
 161 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=wal").URI(), ser);
         
     | 
| 
      
 162 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 163 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual("wal");
         
     | 
| 
      
 164 
     | 
    
         
            +
                const walstate = res.unwrap().payload as bs.WALState;
         
     | 
| 
      
 165 
     | 
    
         
            +
                expect(walstate.fileOperations).toEqual(msg.payload.fileOperations);
         
     | 
| 
      
 166 
     | 
    
         
            +
                expect(walstate.noLoaderOps).toEqual(msg.payload.noLoaderOps);
         
     | 
| 
      
 167 
     | 
    
         
            +
                expect(walstate.operations).toEqual(msg.payload.operations);
         
     | 
| 
      
 168 
     | 
    
         
            +
              });
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
              it("coerce into fpDeserialize Result", async () => {
         
     | 
| 
      
 171 
     | 
    
         
            +
                const raw = new Uint8Array([55, 56, 57]);
         
     | 
| 
      
 172 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Result.Ok(raw));
         
     | 
| 
      
 173 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 174 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
         
     | 
| 
      
 175 
     | 
    
         
            +
                expect(res.unwrap().payload).toEqual(raw);
         
     | 
| 
      
 176 
     | 
    
         
            +
              });
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
              it("coerce into fpDeserialize Promise", async () => {
         
     | 
| 
      
 179 
     | 
    
         
            +
                const raw = new Uint8Array([55, 56, 57]);
         
     | 
| 
      
 180 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Promise.resolve(raw));
         
     | 
| 
      
 181 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 182 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
         
     | 
| 
      
 183 
     | 
    
         
            +
                expect(res.unwrap().payload).toEqual(raw);
         
     | 
| 
      
 184 
     | 
    
         
            +
              });
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
              it("coerce into fpDeserialize Promise Result", async () => {
         
     | 
| 
      
 187 
     | 
    
         
            +
                const raw = new Uint8Array([55, 56, 57]);
         
     | 
| 
      
 188 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(
         
     | 
| 
      
 189 
     | 
    
         
            +
                  sthis,
         
     | 
| 
      
 190 
     | 
    
         
            +
                  BuildURI.from("http://x.com?store=data&suffix=.car").URI(),
         
     | 
| 
      
 191 
     | 
    
         
            +
                  Promise.resolve(Result.Ok(raw)),
         
     | 
| 
      
 192 
     | 
    
         
            +
                );
         
     | 
| 
      
 193 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 194 
     | 
    
         
            +
                expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
         
     | 
| 
      
 195 
     | 
    
         
            +
                expect(res.unwrap().payload).toEqual(raw);
         
     | 
| 
      
 196 
     | 
    
         
            +
              });
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
              it("coerce into fpDeserialize Promise Result.Err", async () => {
         
     | 
| 
      
 199 
     | 
    
         
            +
                const raw = Promise.resolve(Result.Err<Uint8Array>("error"));
         
     | 
| 
      
 200 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), raw);
         
     | 
| 
      
 201 
     | 
    
         
            +
                expect(res.isErr()).toBeTruthy();
         
     | 
| 
      
 202 
     | 
    
         
            +
                expect(res.unwrap_err().message).toEqual("error");
         
     | 
| 
      
 203 
     | 
    
         
            +
              });
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
      
 205 
     | 
    
         
            +
              it("coerce into fpDeserialize Promise.reject", async () => {
         
     | 
| 
      
 206 
     | 
    
         
            +
                const raw = Promise.reject(new Error("error"));
         
     | 
| 
      
 207 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), raw);
         
     | 
| 
      
 208 
     | 
    
         
            +
                expect(res.isErr()).toBeTruthy();
         
     | 
| 
      
 209 
     | 
    
         
            +
                expect(res.unwrap_err().message).toEqual("error");
         
     | 
| 
      
 210 
     | 
    
         
            +
              });
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
              it("coerce into fpDeserialize Result.Err", async () => {
         
     | 
| 
      
 213 
     | 
    
         
            +
                const raw = Result.Err<Uint8Array>("error");
         
     | 
| 
      
 214 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), raw);
         
     | 
| 
      
 215 
     | 
    
         
            +
                expect(res.isErr()).toBeTruthy();
         
     | 
| 
      
 216 
     | 
    
         
            +
                expect(res.unwrap_err().message).toEqual("error");
         
     | 
| 
      
 217 
     | 
    
         
            +
              });
         
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
      
 219 
     | 
    
         
            +
              it("attach Key to Meta", async () => {
         
     | 
| 
      
 220 
     | 
    
         
            +
                const msg = {
         
     | 
| 
      
 221 
     | 
    
         
            +
                  type: FPEnvelopeType.META,
         
     | 
| 
      
 222 
     | 
    
         
            +
                  payload: [
         
     | 
| 
      
 223 
     | 
    
         
            +
                    await bs.createDbMetaEvent(
         
     | 
| 
      
 224 
     | 
    
         
            +
                      sthis,
         
     | 
| 
      
 225 
     | 
    
         
            +
                      {
         
     | 
| 
      
 226 
     | 
    
         
            +
                        cars: [await simpleCID(sthis)],
         
     | 
| 
      
 227 
     | 
    
         
            +
                      },
         
     | 
| 
      
 228 
     | 
    
         
            +
                      [await simpleCID(sthis), await simpleCID(sthis)],
         
     | 
| 
      
 229 
     | 
    
         
            +
                    ),
         
     | 
| 
      
 230 
     | 
    
         
            +
                  ],
         
     | 
| 
      
 231 
     | 
    
         
            +
                } satisfies bs.FPEnvelopeMeta;
         
     | 
| 
      
 232 
     | 
    
         
            +
                const ser = await rt.gw.fpSerialize(sthis, msg, {
         
     | 
| 
      
 233 
     | 
    
         
            +
                  meta: async (sthis, payload) => {
         
     | 
| 
      
 234 
     | 
    
         
            +
                    return Result.Ok(sthis.txt.encode(JSON.stringify(payload.map((i) => ({ ...i, key: "key" })))));
         
     | 
| 
      
 235 
     | 
    
         
            +
                  },
         
     | 
| 
      
 236 
     | 
    
         
            +
                });
         
     | 
| 
      
 237 
     | 
    
         
            +
                let key = "";
         
     | 
| 
      
 238 
     | 
    
         
            +
                const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=meta").URI(), ser, {
         
     | 
| 
      
 239 
     | 
    
         
            +
                  meta: async (sthis, payload) => {
         
     | 
| 
      
 240 
     | 
    
         
            +
                    const json = JSON.parse(sthis.txt.decode(payload));
         
     | 
| 
      
 241 
     | 
    
         
            +
                    key = json[0].key;
         
     | 
| 
      
 242 
     | 
    
         
            +
                    return Result.Ok(
         
     | 
| 
      
 243 
     | 
    
         
            +
                      json.map((i: { key?: string }) => {
         
     | 
| 
      
 244 
     | 
    
         
            +
                        delete i.key;
         
     | 
| 
      
 245 
     | 
    
         
            +
                        return i;
         
     | 
| 
      
 246 
     | 
    
         
            +
                      }) as rt.gw.SerializedMeta[],
         
     | 
| 
      
 247 
     | 
    
         
            +
                    );
         
     | 
| 
      
 248 
     | 
    
         
            +
                  },
         
     | 
| 
      
 249 
     | 
    
         
            +
                });
         
     | 
| 
      
 250 
     | 
    
         
            +
                expect(res.isOk()).toBeTruthy();
         
     | 
| 
      
 251 
     | 
    
         
            +
                const meta = res.unwrap() as bs.FPEnvelopeMeta;
         
     | 
| 
      
 252 
     | 
    
         
            +
                expect(meta.type).toEqual("meta");
         
     | 
| 
      
 253 
     | 
    
         
            +
                expect(Object.keys(meta.payload).includes("key")).toBeFalsy();
         
     | 
| 
      
 254 
     | 
    
         
            +
                expect(key).toEqual("key");
         
     | 
| 
      
 255 
     | 
    
         
            +
              });
         
     | 
| 
      
 256 
     | 
    
         
            +
            });
         
     | 
| 
         @@ -0,0 +1,79 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import { fireproof } from "@fireproof/core";
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { mockSuperThis } from "../../helpers.js";
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe("fireproof config indexdb", () => {
         
     | 
| 
      
 5 
     | 
    
         
            +
              const _my_app = "my-app";
         
     | 
| 
      
 6 
     | 
    
         
            +
              function my_app() {
         
     | 
| 
      
 7 
     | 
    
         
            +
                return _my_app;
         
     | 
| 
      
 8 
     | 
    
         
            +
              }
         
     | 
| 
      
 9 
     | 
    
         
            +
              const sthis = mockSuperThis();
         
     | 
| 
      
 10 
     | 
    
         
            +
              beforeAll(async () => {
         
     | 
| 
      
 11 
     | 
    
         
            +
                await sthis.start();
         
     | 
| 
      
 12 
     | 
    
         
            +
              });
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              it("indexdb-loader", async () => {
         
     | 
| 
      
 15 
     | 
    
         
            +
                const db = fireproof(my_app());
         
     | 
| 
      
 16 
     | 
    
         
            +
                await db.put({ name: "my-app" });
         
     | 
| 
      
 17 
     | 
    
         
            +
                expect(db.name).toBe(my_app());
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                const fileStore = await db.crdt.blockstore.loader.fileStore();
         
     | 
| 
      
 20 
     | 
    
         
            +
                expect(fileStore?.url().asObj()).toEqual({
         
     | 
| 
      
 21 
     | 
    
         
            +
                  pathname: "fp",
         
     | 
| 
      
 22 
     | 
    
         
            +
                  protocol: "indexdb:",
         
     | 
| 
      
 23 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 24 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 25 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 26 
     | 
    
         
            +
                    runtime: "browser",
         
     | 
| 
      
 27 
     | 
    
         
            +
                    storekey: "@my-app-data@",
         
     | 
| 
      
 28 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: "v0.19-indexdb",
         
     | 
| 
      
 30 
     | 
    
         
            +
                  },
         
     | 
| 
      
 31 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 32 
     | 
    
         
            +
                });
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                const dataStore = await db.crdt.blockstore.loader.carStore();
         
     | 
| 
      
 35 
     | 
    
         
            +
                expect(dataStore?.url().asObj()).toEqual({
         
     | 
| 
      
 36 
     | 
    
         
            +
                  pathname: "fp",
         
     | 
| 
      
 37 
     | 
    
         
            +
                  protocol: "indexdb:",
         
     | 
| 
      
 38 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 39 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 40 
     | 
    
         
            +
                    store: "data",
         
     | 
| 
      
 41 
     | 
    
         
            +
                    runtime: "browser",
         
     | 
| 
      
 42 
     | 
    
         
            +
                    storekey: "@my-app-data@",
         
     | 
| 
      
 43 
     | 
    
         
            +
                    suffix: ".car",
         
     | 
| 
      
 44 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 45 
     | 
    
         
            +
                    version: "v0.19-indexdb",
         
     | 
| 
      
 46 
     | 
    
         
            +
                  },
         
     | 
| 
      
 47 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 48 
     | 
    
         
            +
                });
         
     | 
| 
      
 49 
     | 
    
         
            +
                const metaStore = await db.crdt.blockstore.loader.metaStore();
         
     | 
| 
      
 50 
     | 
    
         
            +
                expect(metaStore?.url().asObj()).toEqual({
         
     | 
| 
      
 51 
     | 
    
         
            +
                  pathname: "fp",
         
     | 
| 
      
 52 
     | 
    
         
            +
                  protocol: "indexdb:",
         
     | 
| 
      
 53 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 54 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 55 
     | 
    
         
            +
                    store: "meta",
         
     | 
| 
      
 56 
     | 
    
         
            +
                    runtime: "browser",
         
     | 
| 
      
 57 
     | 
    
         
            +
                    storekey: "@my-app-meta@",
         
     | 
| 
      
 58 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 59 
     | 
    
         
            +
                    version: "v0.19-indexdb",
         
     | 
| 
      
 60 
     | 
    
         
            +
                  },
         
     | 
| 
      
 61 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 62 
     | 
    
         
            +
                });
         
     | 
| 
      
 63 
     | 
    
         
            +
                const WALStore = await db.crdt.blockstore.loader.WALStore();
         
     | 
| 
      
 64 
     | 
    
         
            +
                expect(WALStore?.url().asObj()).toEqual({
         
     | 
| 
      
 65 
     | 
    
         
            +
                  pathname: "fp",
         
     | 
| 
      
 66 
     | 
    
         
            +
                  protocol: "indexdb:",
         
     | 
| 
      
 67 
     | 
    
         
            +
                  searchParams: {
         
     | 
| 
      
 68 
     | 
    
         
            +
                    name: "my-app",
         
     | 
| 
      
 69 
     | 
    
         
            +
                    store: "wal",
         
     | 
| 
      
 70 
     | 
    
         
            +
                    runtime: "browser",
         
     | 
| 
      
 71 
     | 
    
         
            +
                    storekey: "@my-app-wal@",
         
     | 
| 
      
 72 
     | 
    
         
            +
                    urlGen: "default",
         
     | 
| 
      
 73 
     | 
    
         
            +
                    version: "v0.19-indexdb",
         
     | 
| 
      
 74 
     | 
    
         
            +
                  },
         
     | 
| 
      
 75 
     | 
    
         
            +
                  style: "path",
         
     | 
| 
      
 76 
     | 
    
         
            +
                });
         
     | 
| 
      
 77 
     | 
    
         
            +
                await db.close();
         
     | 
| 
      
 78 
     | 
    
         
            +
              });
         
     | 
| 
      
 79 
     | 
    
         
            +
            });
         
     |