@fireproof/core 0.19.99 → 0.19.101
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/{chunk-OFGPKRCM.js → chunk-3EB3ENHT.js} +54 -25
- package/chunk-3EB3ENHT.js.map +1 -0
- package/chunk-HQ7D3PEU.js +61 -0
- package/chunk-HQ7D3PEU.js.map +1 -0
- package/chunk-PZ5AY32C.js +10 -0
- package/deno-filesystem-Q2IJ7YDR.js +57 -0
- package/deno-filesystem-Q2IJ7YDR.js.map +1 -0
- package/deno.json +3 -1
- package/{gateway-5FCWPX5W.js → gateway-GK5QZ6KP.js} +13 -12
- package/gateway-GK5QZ6KP.js.map +1 -0
- package/{gateway-H7UD6TNB.js → gateway-TQTGDRCN.js} +9 -8
- package/gateway-TQTGDRCN.js.map +1 -0
- package/index.cjs +2232 -1781
- package/index.cjs.map +1 -1
- package/index.d.cts +261 -117
- package/index.d.ts +261 -117
- package/index.global.js +12776 -11829
- package/index.global.js.map +1 -1
- package/index.js +1936 -1579
- package/index.js.map +1 -1
- package/{key-bag-file-WADZBHYG.js → key-bag-file-VOSSK46F.js} +4 -3
- package/{key-bag-file-WADZBHYG.js.map → key-bag-file-VOSSK46F.js.map} +1 -1
- package/{key-bag-indexdb-PGVAI3FJ.js → key-bag-indexdb-AXTQOSMC.js} +4 -3
- package/{key-bag-indexdb-PGVAI3FJ.js.map → key-bag-indexdb-AXTQOSMC.js.map} +1 -1
- package/key-bag-memory-LWE6ARPX.js +29 -0
- package/key-bag-memory-LWE6ARPX.js.map +1 -0
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/metafile-iife.json +1 -1
- package/{node-filesystem-INX4ZTHE.js → node-filesystem-CFRXFSO7.js} +6 -9
- package/node-filesystem-CFRXFSO7.js.map +1 -0
- package/package.json +4 -2
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +129 -0
- package/tests/blockstore/keyed-crypto.test.ts +63 -227
- package/tests/blockstore/loader.test.ts +19 -11
- package/tests/blockstore/store.test.ts +23 -19
- package/tests/blockstore/transaction.test.ts +12 -12
- package/tests/fireproof/all-gateway.test.ts +201 -193
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
- package/tests/fireproof/crdt.test.ts +67 -16
- package/tests/fireproof/database.test.ts +183 -21
- package/tests/fireproof/fireproof.test.ts +83 -74
- package/tests/fireproof/hello.test.ts +18 -14
- package/tests/fireproof/indexer.test.ts +53 -43
- package/tests/fireproof/utils.test.ts +18 -6
- package/tests/gateway/file/loader-config.test.ts +303 -0
- package/tests/gateway/indexdb/loader-config.test.ts +75 -0
- package/tests/helpers.ts +27 -9
- package/tests/react/useFireproof.test.tsx +1 -1
- package/{utils-QO2HIWGI.js → utils-STA2C35G.js} +4 -3
- package/utils-STA2C35G.js.map +1 -0
- package/chunk-OFGPKRCM.js.map +0 -1
- package/chunk-WS3YRPIA.js +0 -75
- package/chunk-WS3YRPIA.js.map +0 -1
- package/gateway-5FCWPX5W.js.map +0 -1
- package/gateway-H7UD6TNB.js.map +0 -1
- package/mem-filesystem-YPPJV7Q2.js +0 -41
- package/mem-filesystem-YPPJV7Q2.js.map +0 -1
- package/node-filesystem-INX4ZTHE.js.map +0 -1
- package/tests/fireproof/config.test.ts +0 -172
- /package/{utils-QO2HIWGI.js.map → chunk-PZ5AY32C.js.map} +0 -0
- /package/tests/fireproof/{fireproof.test.fixture.ts → fireproof.fixture.ts} +0 -0
| @@ -1,59 +1,64 @@ | |
| 1 | 
            -
            import { Database, bs } from "@fireproof/core";
         | 
| 2 | 
            -
            import { URI } from "@adviser/cement";
         | 
| 1 | 
            +
            import { Database, DatabaseFactory, bs } from "@fireproof/core";
         | 
| 3 2 |  | 
| 4 3 | 
             
            import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
         | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 4 | 
            +
            import { mockSuperThis } from "../helpers.js";
         | 
| 5 | 
            +
            import { DataStore, MetaStore, WALStore } from "../../src/blockstore/types.js";
         | 
| 6 | 
            +
            import { Gateway } from "../../src/blockstore/gateway.js";
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            // function customExpect(value: unknown, matcher: (val: unknown) => void, message: string): void {
         | 
| 9 | 
            +
            //   try {
         | 
| 10 | 
            +
            //     matcher(value);
         | 
| 11 | 
            +
            //   } catch (error) {
         | 
| 12 | 
            +
            //     void error;
         | 
| 13 | 
            +
            //     // console.error(error);
         | 
| 14 | 
            +
            //     throw new Error(message);
         | 
| 15 | 
            +
            //   }
         | 
| 16 | 
            +
            // }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            // interface ExtendedGateway extends bs.Gateway {
         | 
| 19 | 
            +
            //   readonly logger: Logger;
         | 
| 20 | 
            +
            //   readonly headerSize: number;
         | 
| 21 | 
            +
            //   readonly fidLength: number;
         | 
| 22 | 
            +
            // }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            // interface ExtendedStore {
         | 
| 25 | 
            +
            //   readonly gateway: ExtendedGateway;
         | 
| 26 | 
            +
            //   readonly _url: URI;
         | 
| 27 | 
            +
            //   readonly name: string;
         | 
| 28 | 
            +
            // }
         | 
| 27 29 |  | 
| 28 30 | 
             
            describe("noop Gateway", function () {
         | 
| 29 31 | 
             
              let db: Database;
         | 
| 30 | 
            -
              let carStore:  | 
| 31 | 
            -
              let metaStore:  | 
| 32 | 
            -
              let fileStore:  | 
| 33 | 
            -
              let walStore:  | 
| 34 | 
            -
              let carGateway:  | 
| 35 | 
            -
              let metaGateway:  | 
| 36 | 
            -
              let fileGateway:  | 
| 37 | 
            -
              let walGateway:  | 
| 32 | 
            +
              let carStore: DataStore;
         | 
| 33 | 
            +
              let metaStore: MetaStore;
         | 
| 34 | 
            +
              let fileStore: DataStore;
         | 
| 35 | 
            +
              let walStore: WALStore;
         | 
| 36 | 
            +
              let carGateway: Gateway;
         | 
| 37 | 
            +
              let metaGateway: Gateway;
         | 
| 38 | 
            +
              let fileGateway: Gateway;
         | 
| 39 | 
            +
              let walGateway: Gateway;
         | 
| 40 | 
            +
              const sthis = mockSuperThis();
         | 
| 38 41 |  | 
| 39 42 | 
             
              afterEach(async function () {
         | 
| 40 43 | 
             
                await db.close();
         | 
| 41 44 | 
             
                await db.destroy();
         | 
| 42 45 | 
             
              });
         | 
| 43 46 | 
             
              beforeEach(async function () {
         | 
| 44 | 
            -
                db =  | 
| 47 | 
            +
                db = DatabaseFactory("test-gateway-" + sthis.nextId().str, {
         | 
| 48 | 
            +
                  logger: sthis.logger,
         | 
| 49 | 
            +
                });
         | 
| 45 50 |  | 
| 46 51 | 
             
                // Extract stores from the loader
         | 
| 47 | 
            -
                carStore = (await db.blockstore.loader?.carStore()) as  | 
| 48 | 
            -
                metaStore = (await db.blockstore.loader?.metaStore()) as  | 
| 49 | 
            -
                fileStore = (await db.blockstore.loader?.fileStore()) as  | 
| 50 | 
            -
                walStore = (await db.blockstore.loader?.WALStore()) as  | 
| 52 | 
            +
                carStore = (await db.crdt.blockstore.loader?.carStore()) as DataStore;
         | 
| 53 | 
            +
                metaStore = (await db.crdt.blockstore.loader?.metaStore()) as MetaStore;
         | 
| 54 | 
            +
                fileStore = (await db.crdt.blockstore.loader?.fileStore()) as DataStore;
         | 
| 55 | 
            +
                walStore = (await db.crdt.blockstore.loader?.WALStore()) as WALStore;
         | 
| 51 56 |  | 
| 52 57 | 
             
                // Extract and log gateways
         | 
| 53 | 
            -
                carGateway = carStore | 
| 54 | 
            -
                metaGateway = metaStore | 
| 55 | 
            -
                fileGateway = fileStore | 
| 56 | 
            -
                walGateway = walStore | 
| 58 | 
            +
                carGateway = carStore.realGateway;
         | 
| 59 | 
            +
                metaGateway = metaStore.realGateway;
         | 
| 60 | 
            +
                fileGateway = fileStore.realGateway;
         | 
| 61 | 
            +
                walGateway = walStore.realGateway;
         | 
| 57 62 | 
             
              });
         | 
| 58 63 |  | 
| 59 64 | 
             
              it("should have valid stores and gateways", async function () {
         | 
| @@ -71,26 +76,27 @@ describe("noop Gateway", function () { | |
| 71 76 |  | 
| 72 77 | 
             
              it("should have correct store names", async function () {
         | 
| 73 78 | 
             
                // Check that all stores have the correct name
         | 
| 74 | 
            -
                expect(carStore | 
| 75 | 
            -
                expect(metaStore | 
| 76 | 
            -
                expect(fileStore | 
| 77 | 
            -
                expect(walStore | 
| 79 | 
            +
                expect(carStore.name).toContain("test-gateway");
         | 
| 80 | 
            +
                expect(metaStore.name).toContain("test-gateway");
         | 
| 81 | 
            +
                expect(fileStore.name).toContain("test-gateway");
         | 
| 82 | 
            +
                expect(walStore.name).toContain("test-gateway");
         | 
| 78 83 | 
             
              });
         | 
| 79 84 |  | 
| 80 85 | 
             
              it("should have correct store types in URLs", async function () {
         | 
| 81 86 | 
             
                // Check that all stores have the correct store type in their URL
         | 
| 82 | 
            -
                expect(carStore | 
| 83 | 
            -
                expect( | 
| 84 | 
            -
                expect( | 
| 85 | 
            -
                expect( | 
| 87 | 
            +
                expect(carStore.url().toString()).toContain("store=data");
         | 
| 88 | 
            +
                expect(carStore.url().toString()).toContain("suffix=.car");
         | 
| 89 | 
            +
                expect(metaStore.url().toString()).toContain("store=meta");
         | 
| 90 | 
            +
                expect(fileStore.url().toString()).toContain("store=data");
         | 
| 91 | 
            +
                expect(walStore.url().toString()).toContain("store=wal");
         | 
| 86 92 | 
             
              });
         | 
| 87 93 |  | 
| 88 94 | 
             
              it("should have version specified in URLs", async function () {
         | 
| 89 95 | 
             
                // Verify that all stores have a version specified
         | 
| 90 | 
            -
                expect(carStore | 
| 91 | 
            -
                expect(metaStore | 
| 92 | 
            -
                expect(fileStore | 
| 93 | 
            -
                expect(walStore | 
| 96 | 
            +
                expect(carStore.url().toString()).toContain("version=");
         | 
| 97 | 
            +
                expect(metaStore.url().toString()).toContain("version=");
         | 
| 98 | 
            +
                expect(fileStore.url().toString()).toContain("version=");
         | 
| 99 | 
            +
                expect(walStore.url().toString()).toContain("version=");
         | 
| 94 100 | 
             
              });
         | 
| 95 101 |  | 
| 96 102 | 
             
              it("should have correct gateway types", async function () {
         | 
| @@ -103,116 +109,105 @@ describe("noop Gateway", function () { | |
| 103 109 |  | 
| 104 110 | 
             
              it("should build CAR Gateway URL", async function () {
         | 
| 105 111 | 
             
                const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
         | 
| 106 | 
            -
                const carUrl = await carGateway | 
| 107 | 
            -
                expect(carUrl | 
| 112 | 
            +
                const carUrl = await carGateway.buildUrl(carStore.url(), testKey);
         | 
| 113 | 
            +
                expect(carUrl.Ok().hasParam("key")).toBeTruthy();
         | 
| 108 114 | 
             
              });
         | 
| 109 115 |  | 
| 110 116 | 
             
              it("should start CAR Gateway", async function () {
         | 
| 111 | 
            -
                await carGateway | 
| 117 | 
            +
                const url = await carGateway.start(carStore.url());
         | 
| 118 | 
            +
                expect(url.Ok().asObj()).toEqual(carStore.url().asObj());
         | 
| 112 119 | 
             
              });
         | 
| 113 120 |  | 
| 114 121 | 
             
              it("should put data in CAR Gateway", async function () {
         | 
| 115 | 
            -
                const  | 
| 116 | 
            -
                 | 
| 117 | 
            -
                const  | 
| 118 | 
            -
                 | 
| 119 | 
            -
                const carPutResult = await carGateway?.put(carUrl?.Ok(), testData);
         | 
| 120 | 
            -
                expect(carPutResult?.Ok()).toBeFalsy();
         | 
| 122 | 
            +
                const carUrl = await carGateway.buildUrl(carStore.url(), fileContent.cid);
         | 
| 123 | 
            +
                await carGateway.start(carStore.url());
         | 
| 124 | 
            +
                const carPutResult = await carGateway.put(carUrl.Ok(), fileContent.block);
         | 
| 125 | 
            +
                expect(carPutResult.isOk()).toBeTruthy();
         | 
| 121 126 | 
             
              });
         | 
| 122 127 |  | 
| 123 128 | 
             
              it("should get data from CAR Gateway", async function () {
         | 
| 124 | 
            -
                const  | 
| 125 | 
            -
                 | 
| 126 | 
            -
                 | 
| 127 | 
            -
                await carGateway | 
| 128 | 
            -
                 | 
| 129 | 
            -
                 | 
| 130 | 
            -
                customExpect(carGetResult?.Ok(), (v) => expect(v).toEqual(testData), "carGetResult should match testData");
         | 
| 129 | 
            +
                const carUrl = await carGateway.buildUrl(carStore.url(), fileContent.cid);
         | 
| 130 | 
            +
                await carGateway.start(carStore.url());
         | 
| 131 | 
            +
                await carGateway.put(carUrl.Ok(), fileContent.block);
         | 
| 132 | 
            +
                const carGetResult = await carGateway.get(carUrl.Ok());
         | 
| 133 | 
            +
                expect(carGetResult.Ok()).toEqual(fileContent.block);
         | 
| 134 | 
            +
                // customExpect(carGetResult.Ok(), (v) => expect(v).toEqual(testData), "carGetResult should match testData");
         | 
| 131 135 | 
             
              });
         | 
| 132 136 |  | 
| 133 137 | 
             
              it("should delete data from CAR Gateway", async function () {
         | 
| 134 | 
            -
                const  | 
| 135 | 
            -
                 | 
| 136 | 
            -
                 | 
| 137 | 
            -
                await carGateway | 
| 138 | 
            -
                 | 
| 139 | 
            -
                const carDeleteResult = await carGateway?.delete(carUrl?.Ok());
         | 
| 140 | 
            -
                expect(carDeleteResult?.Ok()).toBeFalsy();
         | 
| 138 | 
            +
                const carUrl = await carGateway.buildUrl(carStore.url(), fileContent.cid);
         | 
| 139 | 
            +
                await carGateway.start(carStore.url());
         | 
| 140 | 
            +
                await carGateway.put(carUrl.Ok(), fileContent.block);
         | 
| 141 | 
            +
                const carDeleteResult = await carGateway.delete(carUrl.Ok());
         | 
| 142 | 
            +
                expect(carDeleteResult.isOk()).toBeTruthy();
         | 
| 141 143 | 
             
              });
         | 
| 142 144 |  | 
| 143 145 | 
             
              it("should close CAR Gateway", async function () {
         | 
| 144 | 
            -
                await carGateway | 
| 146 | 
            +
                await carGateway.close(carStore.url());
         | 
| 145 147 | 
             
              });
         | 
| 146 148 | 
             
              it("should build Meta Gateway URL", async function () {
         | 
| 147 | 
            -
                const metaUrl = await metaGateway | 
| 148 | 
            -
                expect(metaUrl | 
| 149 | 
            +
                const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
         | 
| 150 | 
            +
                expect(metaUrl.Ok()).toBeTruthy();
         | 
| 149 151 | 
             
              });
         | 
| 150 152 |  | 
| 151 153 | 
             
              it("should start Meta Gateway", async function () {
         | 
| 152 | 
            -
                await metaGateway | 
| 154 | 
            +
                await metaGateway.start(metaStore.url());
         | 
| 153 155 | 
             
              });
         | 
| 154 156 |  | 
| 155 157 | 
             
              it("should close Meta Gateway", async function () {
         | 
| 156 | 
            -
                await metaGateway | 
| 157 | 
            -
                await metaGateway | 
| 158 | 
            +
                await metaGateway.start(metaStore.url());
         | 
| 159 | 
            +
                await metaGateway.close(metaStore.url());
         | 
| 158 160 | 
             
              });
         | 
| 159 161 |  | 
| 160 162 | 
             
              it("should build File Gateway URL", async function () {
         | 
| 161 | 
            -
                const  | 
| 162 | 
            -
                 | 
| 163 | 
            -
                expect(fileUrl?.Ok()).toBeTruthy();
         | 
| 163 | 
            +
                const fileUrl = await fileGateway.buildUrl(fileStore.url(), fileContent.cid);
         | 
| 164 | 
            +
                expect(fileUrl.Ok()).toBeTruthy();
         | 
| 164 165 | 
             
              });
         | 
| 165 166 |  | 
| 166 167 | 
             
              it("should start File Gateway", async function () {
         | 
| 167 | 
            -
                await fileGateway | 
| 168 | 
            +
                await fileGateway.start(fileStore.url());
         | 
| 168 169 | 
             
              });
         | 
| 169 170 |  | 
| 170 171 | 
             
              it("should put data to File Gateway", async function () {
         | 
| 171 | 
            -
                const  | 
| 172 | 
            -
                 | 
| 173 | 
            -
                const  | 
| 174 | 
            -
                 | 
| 175 | 
            -
                const filePutResult = await fileGateway?.put(fileUrl?.Ok(), testData);
         | 
| 176 | 
            -
                expect(filePutResult?.Ok()).toBeFalsy();
         | 
| 172 | 
            +
                const fileUrl = await fileGateway.buildUrl(fileStore.url(), fileContent.cid);
         | 
| 173 | 
            +
                await fileGateway.start(fileStore.url());
         | 
| 174 | 
            +
                const filePutResult = await fileGateway.put(fileUrl.Ok(), fileContent.block);
         | 
| 175 | 
            +
                expect(filePutResult.Ok()).toBeFalsy();
         | 
| 177 176 | 
             
              });
         | 
| 178 177 |  | 
| 179 178 | 
             
              it("should get data from File Gateway", async function () {
         | 
| 180 | 
            -
                const  | 
| 181 | 
            -
                 | 
| 182 | 
            -
                 | 
| 183 | 
            -
                await fileGateway | 
| 184 | 
            -
                 | 
| 185 | 
            -
                const fileGetResult = await fileGateway?.get(fileUrl?.Ok());
         | 
| 186 | 
            -
                customExpect(fileGetResult?.Ok(), (v) => expect(v).toEqual(testData), "fileGetResult should match testData");
         | 
| 179 | 
            +
                const fileUrl = await fileGateway.buildUrl(fileStore.url(), fileContent.cid);
         | 
| 180 | 
            +
                await fileGateway.start(fileStore.url());
         | 
| 181 | 
            +
                await fileGateway.put(fileUrl.Ok(), fileContent.block);
         | 
| 182 | 
            +
                const fileGetResult = await fileGateway.get(fileUrl.Ok());
         | 
| 183 | 
            +
                expect(fileGetResult.Ok()).toEqual(fileContent.block);
         | 
| 187 184 | 
             
              });
         | 
| 188 185 |  | 
| 189 186 | 
             
              it("should delete data from File Gateway", async function () {
         | 
| 190 | 
            -
                const  | 
| 191 | 
            -
                 | 
| 192 | 
            -
                 | 
| 193 | 
            -
                await fileGateway | 
| 194 | 
            -
                 | 
| 195 | 
            -
                const fileDeleteResult = await fileGateway?.delete(fileUrl?.Ok());
         | 
| 196 | 
            -
                expect(fileDeleteResult?.Ok()).toBeFalsy();
         | 
| 187 | 
            +
                const fileUrl = await fileGateway.buildUrl(fileStore.url(), fileContent.cid);
         | 
| 188 | 
            +
                await fileGateway.start(fileStore.url());
         | 
| 189 | 
            +
                await fileGateway.put(fileUrl.Ok(), fileContent.block);
         | 
| 190 | 
            +
                const fileDeleteResult = await fileGateway.delete(fileUrl.Ok());
         | 
| 191 | 
            +
                expect(fileDeleteResult.isOk()).toBeTruthy();
         | 
| 197 192 | 
             
              });
         | 
| 198 193 |  | 
| 199 194 | 
             
              it("should close File Gateway", async function () {
         | 
| 200 | 
            -
                await fileGateway | 
| 195 | 
            +
                await fileGateway.close(fileStore.url());
         | 
| 201 196 | 
             
              });
         | 
| 202 197 | 
             
              it("should build WAL Gateway URL", async function () {
         | 
| 203 198 | 
             
                const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
         | 
| 204 | 
            -
                const walUrl = await walGateway | 
| 205 | 
            -
                expect(walUrl | 
| 199 | 
            +
                const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
         | 
| 200 | 
            +
                expect(walUrl.Ok()).toBeTruthy();
         | 
| 206 201 | 
             
              });
         | 
| 207 202 |  | 
| 208 203 | 
             
              it("should start WAL Gateway", async function () {
         | 
| 209 | 
            -
                await walGateway | 
| 204 | 
            +
                await walGateway.start(walStore.url());
         | 
| 210 205 | 
             
              });
         | 
| 211 206 |  | 
| 212 207 | 
             
              it("should put data to WAL Gateway", async function () {
         | 
| 213 208 | 
             
                const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
         | 
| 214 | 
            -
                const walUrl = await walGateway | 
| 215 | 
            -
                await walGateway | 
| 209 | 
            +
                const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
         | 
| 210 | 
            +
                await walGateway.start(walStore.url());
         | 
| 216 211 | 
             
                const walTestDataString = JSON.stringify({
         | 
| 217 212 | 
             
                  operations: [],
         | 
| 218 213 | 
             
                  noLoaderOps: [],
         | 
| @@ -220,14 +215,14 @@ describe("noop Gateway", function () { | |
| 220 215 | 
             
                });
         | 
| 221 216 | 
             
                const walEncoder = new TextEncoder();
         | 
| 222 217 | 
             
                const walTestData = walEncoder.encode(walTestDataString);
         | 
| 223 | 
            -
                const walPutResult = await walGateway | 
| 224 | 
            -
                expect(walPutResult | 
| 218 | 
            +
                const walPutResult = await walGateway.put(walUrl.Ok(), walTestData);
         | 
| 219 | 
            +
                expect(walPutResult.Ok()).toBeFalsy();
         | 
| 225 220 | 
             
              });
         | 
| 226 221 |  | 
| 227 222 | 
             
              it("should get data from WAL Gateway", async function () {
         | 
| 228 223 | 
             
                const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
         | 
| 229 | 
            -
                const walUrl = await walGateway | 
| 230 | 
            -
                await walGateway | 
| 224 | 
            +
                const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
         | 
| 225 | 
            +
                await walGateway.start(walStore.url());
         | 
| 231 226 | 
             
                const walTestDataString = JSON.stringify({
         | 
| 232 227 | 
             
                  operations: [],
         | 
| 233 228 | 
             
                  noLoaderOps: [],
         | 
| @@ -235,17 +230,17 @@ describe("noop Gateway", function () { | |
| 235 230 | 
             
                });
         | 
| 236 231 | 
             
                const walEncoder = new TextEncoder();
         | 
| 237 232 | 
             
                const walTestData = walEncoder.encode(walTestDataString);
         | 
| 238 | 
            -
                await walGateway | 
| 239 | 
            -
                const walGetResult = await walGateway | 
| 240 | 
            -
                const okResult = walGetResult | 
| 233 | 
            +
                await walGateway.put(walUrl.Ok(), walTestData);
         | 
| 234 | 
            +
                const walGetResult = await walGateway.get(walUrl.Ok());
         | 
| 235 | 
            +
                const okResult = walGetResult.Ok();
         | 
| 241 236 | 
             
                const decodedResult = new TextDecoder().decode(okResult);
         | 
| 242 237 | 
             
                expect(decodedResult).toEqual(walTestDataString);
         | 
| 243 238 | 
             
              });
         | 
| 244 239 |  | 
| 245 240 | 
             
              it("should delete data from WAL Gateway", async function () {
         | 
| 246 241 | 
             
                const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
         | 
| 247 | 
            -
                const walUrl = await walGateway | 
| 248 | 
            -
                await walGateway | 
| 242 | 
            +
                const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
         | 
| 243 | 
            +
                await walGateway.start(walStore.url());
         | 
| 249 244 | 
             
                const walTestDataString = JSON.stringify({
         | 
| 250 245 | 
             
                  operations: [],
         | 
| 251 246 | 
             
                  noLoaderOps: [],
         | 
| @@ -253,85 +248,98 @@ describe("noop Gateway", function () { | |
| 253 248 | 
             
                });
         | 
| 254 249 | 
             
                const walEncoder = new TextEncoder();
         | 
| 255 250 | 
             
                const walTestData = walEncoder.encode(walTestDataString);
         | 
| 256 | 
            -
                await walGateway | 
| 257 | 
            -
                const walDeleteResult = await walGateway | 
| 258 | 
            -
                expect(walDeleteResult | 
| 251 | 
            +
                await walGateway.put(walUrl.Ok(), walTestData);
         | 
| 252 | 
            +
                const walDeleteResult = await walGateway.delete(walUrl.Ok());
         | 
| 253 | 
            +
                expect(walDeleteResult.isOk()).toBeTruthy();
         | 
| 259 254 | 
             
              });
         | 
| 260 255 |  | 
| 261 256 | 
             
              it("should close WAL Gateway", async function () {
         | 
| 262 | 
            -
                await walGateway | 
| 263 | 
            -
                await walGateway | 
| 264 | 
            -
              });
         | 
| 265 | 
            -
             | 
| 266 | 
            -
              it("should have correct CAR Gateway properties", async function () {
         | 
| 267 | 
            -
             | 
| 268 | 
            -
             | 
| 269 | 
            -
             | 
| 270 | 
            -
             | 
| 271 | 
            -
             | 
| 272 | 
            -
               | 
| 273 | 
            -
             | 
| 274 | 
            -
               | 
| 275 | 
            -
             | 
| 276 | 
            -
             | 
| 277 | 
            -
             | 
| 278 | 
            -
             | 
| 279 | 
            -
             | 
| 280 | 
            -
               | 
| 281 | 
            -
             | 
| 282 | 
            -
               | 
| 283 | 
            -
             | 
| 284 | 
            -
             | 
| 285 | 
            -
             | 
| 286 | 
            -
             | 
| 287 | 
            -
             | 
| 288 | 
            -
               | 
| 289 | 
            -
             | 
| 290 | 
            -
               | 
| 291 | 
            -
             | 
| 292 | 
            -
             | 
| 293 | 
            -
             | 
| 294 | 
            -
             | 
| 295 | 
            -
             | 
| 296 | 
            -
               | 
| 257 | 
            +
                await walGateway.start(walStore.url());
         | 
| 258 | 
            +
                await walGateway.close(walStore.url());
         | 
| 259 | 
            +
              });
         | 
| 260 | 
            +
             | 
| 261 | 
            +
              // it("should have correct CAR Gateway properties", async function () {
         | 
| 262 | 
            +
              //   // CAR Gateway assertions
         | 
| 263 | 
            +
              //   expect(carGateway.fidLength).toBe(4);
         | 
| 264 | 
            +
              //   expect(carGateway.headerSize).toBe(36);
         | 
| 265 | 
            +
              //   carGateway.logger.Error().Msg("CAR Gateway properties");
         | 
| 266 | 
            +
              //   await sthis.logger.Flush();
         | 
| 267 | 
            +
              //   const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
         | 
| 268 | 
            +
              //   expect(last).toHaveProperty("module");
         | 
| 269 | 
            +
              //   expect(carStore.).toHaveProperty("url");
         | 
| 270 | 
            +
              // });
         | 
| 271 | 
            +
             | 
| 272 | 
            +
              // it("should have correct Meta Gateway properties", async function () {
         | 
| 273 | 
            +
              //   // Meta Gateway assertions
         | 
| 274 | 
            +
              //   expect(metaGateway.fidLength).toBe(4);
         | 
| 275 | 
            +
              //   expect(metaGateway.headerSize).toBe(36);
         | 
| 276 | 
            +
              //   metaGateway.logger.Error().Msg("CAR Gateway properties");
         | 
| 277 | 
            +
              //   await sthis.logger.Flush();
         | 
| 278 | 
            +
              //   const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
         | 
| 279 | 
            +
              //   expect(last).toHaveProperty("module");
         | 
| 280 | 
            +
              //   expect(last).not.toHaveProperty("url");
         | 
| 281 | 
            +
              // });
         | 
| 282 | 
            +
             | 
| 283 | 
            +
              // it("should have correct File Gateway properties", async function () {
         | 
| 284 | 
            +
              //   // File Gateway assertions
         | 
| 285 | 
            +
              //   expect(fileGateway.fidLength).toBe(4);
         | 
| 286 | 
            +
              //   expect(fileGateway.headerSize).toBe(36);
         | 
| 287 | 
            +
              //   fileGateway.logger.Error().Msg("CAR Gateway properties");
         | 
| 288 | 
            +
              //   await sthis.logger.Flush();
         | 
| 289 | 
            +
              //   const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
         | 
| 290 | 
            +
              //   expect(last).toHaveProperty("module");
         | 
| 291 | 
            +
              //   expect(last).toHaveProperty("url");
         | 
| 292 | 
            +
              // });
         | 
| 293 | 
            +
             | 
| 294 | 
            +
              // it("should have correct WAL Gateway properties", async function () {
         | 
| 295 | 
            +
              //   // WAL Gateway assertions
         | 
| 296 | 
            +
              //   expect(walGateway.fidLength).toBe(4);
         | 
| 297 | 
            +
              //   expect(walGateway.headerSize).toBe(36);
         | 
| 298 | 
            +
              //   walGateway.logger.Error().Msg("CAR Gateway properties");
         | 
| 299 | 
            +
              //   await sthis.logger.Flush();
         | 
| 300 | 
            +
              //   const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
         | 
| 301 | 
            +
              //   expect(last).toHaveProperty("module");
         | 
| 302 | 
            +
              //   expect(last).not.toHaveProperty("url");
         | 
| 303 | 
            +
              // });
         | 
| 297 304 | 
             
            });
         | 
| 298 305 |  | 
| 299 306 | 
             
            describe("noop Gateway subscribe", function () {
         | 
| 300 307 | 
             
              let db: Database;
         | 
| 301 308 |  | 
| 302 | 
            -
              let metaStore:  | 
| 309 | 
            +
              let metaStore: MetaStore;
         | 
| 303 310 |  | 
| 304 | 
            -
              let metaGateway:  | 
| 311 | 
            +
              let metaGateway: Gateway;
         | 
| 312 | 
            +
              const sthis = mockSuperThis();
         | 
| 305 313 |  | 
| 306 314 | 
             
              afterEach(async function () {
         | 
| 307 315 | 
             
                await db.close();
         | 
| 308 316 | 
             
                await db.destroy();
         | 
| 309 317 | 
             
              });
         | 
| 310 318 | 
             
              beforeEach(async function () {
         | 
| 311 | 
            -
                db =  | 
| 319 | 
            +
                db = DatabaseFactory("test-gateway-" + sthis.nextId().str);
         | 
| 312 320 |  | 
| 313 321 | 
             
                // Extract stores from the loader
         | 
| 314 | 
            -
                metaStore = (await db.blockstore.loader?.metaStore()) as  | 
| 322 | 
            +
                metaStore = (await db.crdt.blockstore.loader?.metaStore()) as MetaStore;
         | 
| 315 323 |  | 
| 316 | 
            -
                metaGateway = metaStore | 
| 324 | 
            +
                metaGateway = metaStore.realGateway;
         | 
| 317 325 | 
             
              });
         | 
| 318 326 | 
             
              it("should subscribe to meta Gateway", async function () {
         | 
| 319 | 
            -
                const metaUrl = await metaGateway | 
| 320 | 
            -
                await metaGateway | 
| 327 | 
            +
                const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
         | 
| 328 | 
            +
                await metaGateway.start(metaStore.url());
         | 
| 321 329 |  | 
| 322 330 | 
             
                let resolve: () => void;
         | 
| 323 331 | 
             
                let didCall = false;
         | 
| 324 332 | 
             
                const p = new Promise<void>((r) => {
         | 
| 325 333 | 
             
                  resolve = r;
         | 
| 326 334 | 
             
                });
         | 
| 327 | 
            -
                 | 
| 328 | 
            -
                  const  | 
| 329 | 
            -
             | 
| 330 | 
            -
             | 
| 331 | 
            -
             | 
| 332 | 
            -
             | 
| 333 | 
            -
             | 
| 334 | 
            -
                  expect(metaSubscribeResult | 
| 335 | 
            +
                if (metaGateway.subscribe) {
         | 
| 336 | 
            +
                  const metaSubscribeResult = (await metaGateway.subscribe(metaUrl.Ok(), async (data: Uint8Array) => {
         | 
| 337 | 
            +
                    const decodedData = sthis.txt.decode(data);
         | 
| 338 | 
            +
                    expect(decodedData).toContain("[]");
         | 
| 339 | 
            +
                    didCall = true;
         | 
| 340 | 
            +
                    resolve();
         | 
| 341 | 
            +
                  })) as bs.UnsubscribeResult;
         | 
| 342 | 
            +
                  expect(metaSubscribeResult.isOk()).toBeTruthy();
         | 
| 335 343 | 
             
                  const ok = await db.put({ _id: "key1", hello: "world1" });
         | 
| 336 344 | 
             
                  expect(ok).toBeTruthy();
         | 
| 337 345 | 
             
                  expect(ok.id).toBe("key1");
         | 
| @@ -344,11 +352,11 @@ describe("noop Gateway subscribe", function () { | |
| 344 352 | 
             
            describe("Gateway", function () {
         | 
| 345 353 | 
             
              let db: Database;
         | 
| 346 354 | 
             
              // let carStore: ExtendedStore;
         | 
| 347 | 
            -
              let metaStore:  | 
| 355 | 
            +
              let metaStore: MetaStore;
         | 
| 348 356 | 
             
              // let fileStore: ExtendedStore;
         | 
| 349 357 | 
             
              // let walStore: ExtendedStore;
         | 
| 350 358 | 
             
              // let carGateway: ExtendedGateway;
         | 
| 351 | 
            -
              let metaGateway:  | 
| 359 | 
            +
              let metaGateway: Gateway;
         | 
| 352 360 | 
             
              // let fileGateway: ExtendedGateway;
         | 
| 353 361 | 
             
              // let walGateway: ExtendedGateway;
         | 
| 354 362 |  | 
| @@ -357,38 +365,38 @@ describe("Gateway", function () { | |
| 357 365 | 
             
                await db.destroy();
         | 
| 358 366 | 
             
              });
         | 
| 359 367 | 
             
              beforeEach(async function () {
         | 
| 360 | 
            -
                db =  | 
| 368 | 
            +
                db = DatabaseFactory("test-gateway-" + mockSuperThis().nextId().str);
         | 
| 361 369 | 
             
                const ok = await db.put({ _id: "test", foo: "bar" });
         | 
| 362 370 | 
             
                expect(ok).toBeTruthy();
         | 
| 363 371 | 
             
                expect(ok.id).toBe("test");
         | 
| 364 372 |  | 
| 365 373 | 
             
                // Extract stores from the loader
         | 
| 366 | 
            -
                // carStore = (await db.blockstore.loader | 
| 367 | 
            -
                metaStore = (await db.blockstore.loader?.metaStore()) as  | 
| 368 | 
            -
                // fileStore = (await db.blockstore.loader | 
| 369 | 
            -
                // walStore = (await db.blockstore.loader | 
| 374 | 
            +
                // carStore = (await db.blockstore.loader.carStore()) as unknown as ExtendedStore;
         | 
| 375 | 
            +
                metaStore = (await db.crdt.blockstore.loader?.metaStore()) as MetaStore;
         | 
| 376 | 
            +
                // fileStore = (await db.blockstore.loader.fileStore()) as unknown as ExtendedStore;
         | 
| 377 | 
            +
                // walStore = (await db.blockstore.loader.WALStore()) as unknown as ExtendedStore;
         | 
| 370 378 |  | 
| 371 379 | 
             
                // Extract and log gateways
         | 
| 372 | 
            -
                // carGateway = carStore | 
| 373 | 
            -
                metaGateway = metaStore | 
| 374 | 
            -
                // fileGateway = fileStore | 
| 375 | 
            -
                // walGateway = walStore | 
| 380 | 
            +
                // carGateway = carStore.gateway;
         | 
| 381 | 
            +
                metaGateway = metaStore.realGateway;
         | 
| 382 | 
            +
                // fileGateway = fileStore.gateway;
         | 
| 383 | 
            +
                // walGateway = walStore.gateway;
         | 
| 376 384 | 
             
              });
         | 
| 377 385 |  | 
| 378 386 | 
             
              it("should get data from Meta Gateway", async function () {
         | 
| 379 | 
            -
                const metaUrl = await metaGateway | 
| 380 | 
            -
                await metaGateway | 
| 381 | 
            -
                const metaGetResult = await metaGateway | 
| 382 | 
            -
                const metaGetResultOk = metaGetResult | 
| 387 | 
            +
                const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
         | 
| 388 | 
            +
                await metaGateway.start(metaStore.url());
         | 
| 389 | 
            +
                const metaGetResult = await metaGateway.get(metaUrl.Ok());
         | 
| 390 | 
            +
                const metaGetResultOk = metaGetResult.Ok();
         | 
| 383 391 | 
             
                const decodedMetaGetResultOk = new TextDecoder().decode(metaGetResultOk);
         | 
| 384 392 | 
             
                expect(decodedMetaGetResultOk).toContain("parents");
         | 
| 385 393 | 
             
              });
         | 
| 386 394 |  | 
| 387 395 | 
             
              it("should delete data from Meta Gateway", async function () {
         | 
| 388 | 
            -
                const metaUrl = await metaGateway | 
| 389 | 
            -
                await metaGateway | 
| 396 | 
            +
                const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
         | 
| 397 | 
            +
                await metaGateway.start(metaStore.url());
         | 
| 390 398 | 
             
                // should we be testing .destroy() instead?
         | 
| 391 | 
            -
                const metaDeleteResult = await metaGateway | 
| 392 | 
            -
                expect(metaDeleteResult | 
| 399 | 
            +
                const metaDeleteResult = await metaGateway.delete(metaUrl.Ok());
         | 
| 400 | 
            +
                expect(metaDeleteResult.isOk()).toBeTruthy();
         | 
| 393 401 | 
             
              });
         | 
| 394 402 | 
             
            });
         |