@fireproof/core 0.19.100 → 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.
Files changed (61) hide show
  1. package/{chunk-OFGPKRCM.js → chunk-3EB3ENHT.js} +54 -25
  2. package/chunk-3EB3ENHT.js.map +1 -0
  3. package/chunk-HQ7D3PEU.js +61 -0
  4. package/chunk-HQ7D3PEU.js.map +1 -0
  5. package/chunk-PZ5AY32C.js +10 -0
  6. package/deno-filesystem-Q2IJ7YDR.js +57 -0
  7. package/deno-filesystem-Q2IJ7YDR.js.map +1 -0
  8. package/{gateway-5FCWPX5W.js → gateway-GK5QZ6KP.js} +13 -12
  9. package/gateway-GK5QZ6KP.js.map +1 -0
  10. package/{gateway-H7UD6TNB.js → gateway-TQTGDRCN.js} +9 -8
  11. package/gateway-TQTGDRCN.js.map +1 -0
  12. package/index.cjs +2158 -1718
  13. package/index.cjs.map +1 -1
  14. package/index.d.cts +261 -117
  15. package/index.d.ts +261 -117
  16. package/index.global.js +11834 -11354
  17. package/index.global.js.map +1 -1
  18. package/index.js +1865 -1519
  19. package/index.js.map +1 -1
  20. package/{key-bag-file-WADZBHYG.js → key-bag-file-VOSSK46F.js} +4 -3
  21. package/{key-bag-file-WADZBHYG.js.map → key-bag-file-VOSSK46F.js.map} +1 -1
  22. package/{key-bag-indexdb-PGVAI3FJ.js → key-bag-indexdb-AXTQOSMC.js} +4 -3
  23. package/{key-bag-indexdb-PGVAI3FJ.js.map → key-bag-indexdb-AXTQOSMC.js.map} +1 -1
  24. package/key-bag-memory-LWE6ARPX.js +29 -0
  25. package/key-bag-memory-LWE6ARPX.js.map +1 -0
  26. package/metafile-cjs.json +1 -1
  27. package/metafile-esm.json +1 -1
  28. package/metafile-iife.json +1 -1
  29. package/{node-filesystem-INX4ZTHE.js → node-filesystem-CFRXFSO7.js} +6 -9
  30. package/node-filesystem-CFRXFSO7.js.map +1 -0
  31. package/package.json +1 -1
  32. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +129 -0
  33. package/tests/blockstore/keyed-crypto.test.ts +63 -227
  34. package/tests/blockstore/loader.test.ts +19 -11
  35. package/tests/blockstore/store.test.ts +23 -19
  36. package/tests/blockstore/transaction.test.ts +12 -12
  37. package/tests/fireproof/all-gateway.test.ts +201 -193
  38. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  39. package/tests/fireproof/crdt.test.ts +67 -16
  40. package/tests/fireproof/database.test.ts +183 -21
  41. package/tests/fireproof/fireproof.test.ts +83 -74
  42. package/tests/fireproof/hello.test.ts +18 -14
  43. package/tests/fireproof/indexer.test.ts +53 -43
  44. package/tests/fireproof/utils.test.ts +18 -6
  45. package/tests/gateway/file/loader-config.test.ts +303 -0
  46. package/tests/gateway/indexdb/loader-config.test.ts +75 -0
  47. package/tests/helpers.ts +27 -9
  48. package/tests/react/useFireproof.test.tsx +1 -1
  49. package/{utils-QO2HIWGI.js → utils-STA2C35G.js} +4 -3
  50. package/utils-STA2C35G.js.map +1 -0
  51. package/chunk-OFGPKRCM.js.map +0 -1
  52. package/chunk-WS3YRPIA.js +0 -75
  53. package/chunk-WS3YRPIA.js.map +0 -1
  54. package/gateway-5FCWPX5W.js.map +0 -1
  55. package/gateway-H7UD6TNB.js.map +0 -1
  56. package/mem-filesystem-YPPJV7Q2.js +0 -41
  57. package/mem-filesystem-YPPJV7Q2.js.map +0 -1
  58. package/node-filesystem-INX4ZTHE.js.map +0 -1
  59. package/tests/fireproof/config.test.ts +0 -172
  60. /package/{utils-QO2HIWGI.js.map → chunk-PZ5AY32C.js.map} +0 -0
  61. /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
- function customExpect(value: unknown, matcher: (val: unknown) => void, message: string): void {
7
- try {
8
- matcher(value);
9
- } catch (error) {
10
- void error;
11
- // console.error(error);
12
- throw new Error(message);
13
- }
14
- }
15
-
16
- interface ExtendedGateway extends bs.Gateway {
17
- logger: { _attributes: { module: string; url?: string } };
18
- headerSize: number;
19
- fidLength: number;
20
- }
21
-
22
- interface ExtendedStore {
23
- gateway: ExtendedGateway;
24
- _url: URI;
25
- name: string;
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: ExtendedStore;
31
- let metaStore: ExtendedStore;
32
- let fileStore: ExtendedStore;
33
- let walStore: ExtendedStore;
34
- let carGateway: ExtendedGateway;
35
- let metaGateway: ExtendedGateway;
36
- let fileGateway: ExtendedGateway;
37
- let walGateway: ExtendedGateway;
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 = new Database("test-gateway-" + Math.random().toString(36).substring(7));
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 unknown as ExtendedStore;
48
- metaStore = (await db.blockstore.loader?.metaStore()) as unknown as ExtendedStore;
49
- fileStore = (await db.blockstore.loader?.fileStore()) as unknown as ExtendedStore;
50
- walStore = (await db.blockstore.loader?.WALStore()) as unknown as ExtendedStore;
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?.gateway;
54
- metaGateway = metaStore?.gateway;
55
- fileGateway = fileStore?.gateway;
56
- walGateway = walStore?.gateway;
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?.name).toContain("test-gateway");
75
- expect(metaStore?.name).toContain("test-gateway");
76
- expect(fileStore?.name).toContain("test-gateway");
77
- expect(walStore?.name).toContain("test-gateway");
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?._url.toString()).toContain("store=data");
83
- expect(metaStore?._url.toString()).toContain("store=meta");
84
- expect(fileStore?._url.toString()).toContain("store=data");
85
- expect(walStore?._url.toString()).toContain("store=wal");
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?._url.toString()).toContain("version=");
91
- expect(metaStore?._url.toString()).toContain("version=");
92
- expect(fileStore?._url.toString()).toContain("version=");
93
- expect(walStore?._url.toString()).toContain("version=");
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?.buildUrl(carStore?._url, testKey);
107
- expect(carUrl?.Ok()).toBeTruthy();
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?.start(carStore?._url);
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 testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
116
- const testData = fileContent;
117
- const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
118
- await carGateway?.start(carStore?._url);
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 testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
125
- const testData = fileContent;
126
- const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
127
- await carGateway?.start(carStore?._url);
128
- await carGateway?.put(carUrl?.Ok(), testData);
129
- const carGetResult = await carGateway?.get(carUrl?.Ok());
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 testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
135
- const testData = fileContent;
136
- const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
137
- await carGateway?.start(carStore?._url);
138
- await carGateway?.put(carUrl?.Ok(), testData);
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?.close(carStore?._url);
146
+ await carGateway.close(carStore.url());
145
147
  });
146
148
  it("should build Meta Gateway URL", async function () {
147
- const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
148
- expect(metaUrl?.Ok()).toBeTruthy();
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?.start(metaStore?._url);
154
+ await metaGateway.start(metaStore.url());
153
155
  });
154
156
 
155
157
  it("should close Meta Gateway", async function () {
156
- await metaGateway?.start(metaStore?._url);
157
- await metaGateway?.close(metaStore?._url);
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 testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
162
- const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
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?.start(fileStore?._url);
168
+ await fileGateway.start(fileStore.url());
168
169
  });
169
170
 
170
171
  it("should put data to File Gateway", async function () {
171
- const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
172
- const testData = fileContent;
173
- const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
174
- await fileGateway?.start(fileStore?._url);
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 testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
181
- const testData = fileContent;
182
- const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
183
- await fileGateway?.start(fileStore?._url);
184
- await fileGateway?.put(fileUrl?.Ok(), testData);
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 testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
191
- const testData = fileContent;
192
- const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
193
- await fileGateway?.start(fileStore?._url);
194
- await fileGateway?.put(fileUrl?.Ok(), testData);
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?.close(fileStore?._url);
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?.buildUrl(walStore?._url, testKey);
205
- expect(walUrl?.Ok()).toBeTruthy();
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?.start(walStore?._url);
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?.buildUrl(walStore?._url, testKey);
215
- await walGateway?.start(walStore?._url);
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?.put(walUrl?.Ok(), walTestData);
224
- expect(walPutResult?.Ok()).toBeFalsy();
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?.buildUrl(walStore?._url, testKey);
230
- await walGateway?.start(walStore?._url);
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?.put(walUrl?.Ok(), walTestData);
239
- const walGetResult = await walGateway?.get(walUrl?.Ok());
240
- const okResult = walGetResult?.Ok();
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?.buildUrl(walStore?._url, testKey);
248
- await walGateway?.start(walStore?._url);
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?.put(walUrl?.Ok(), walTestData);
257
- const walDeleteResult = await walGateway?.delete(walUrl?.Ok());
258
- expect(walDeleteResult?.Ok()).toBeFalsy();
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?.start(walStore?._url);
263
- await walGateway?.close(walStore?._url);
264
- });
265
-
266
- it("should have correct CAR Gateway properties", async function () {
267
- // CAR Gateway assertions
268
- expect(carGateway?.fidLength).toBe(4);
269
- expect(carGateway?.headerSize).toBe(36);
270
- expect(carGateway?.logger._attributes).toHaveProperty("module");
271
- expect(carGateway?.logger._attributes).toHaveProperty("url");
272
- });
273
-
274
- it("should have correct Meta Gateway properties", async function () {
275
- // Meta Gateway assertions
276
- expect(metaGateway?.fidLength).toBe(4);
277
- expect(metaGateway?.headerSize).toBe(36);
278
- expect(metaGateway?.logger._attributes).toHaveProperty("module");
279
- expect(metaGateway?.logger._attributes).not.toHaveProperty("url");
280
- });
281
-
282
- it("should have correct File Gateway properties", async function () {
283
- // File Gateway assertions
284
- expect(fileGateway?.fidLength).toBe(4);
285
- expect(fileGateway?.headerSize).toBe(36);
286
- expect(fileGateway?.logger._attributes).toHaveProperty("module");
287
- expect(fileGateway?.logger._attributes).toHaveProperty("url");
288
- });
289
-
290
- it("should have correct WAL Gateway properties", async function () {
291
- // WAL Gateway assertions
292
- expect(walGateway?.fidLength).toBe(4);
293
- expect(walGateway?.headerSize).toBe(36);
294
- expect(walGateway?.logger._attributes).toHaveProperty("module");
295
- expect(walGateway?.logger._attributes).not.toHaveProperty("url");
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: ExtendedStore;
309
+ let metaStore: MetaStore;
303
310
 
304
- let metaGateway: ExtendedGateway;
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 = new Database("test-gateway-" + Math.random().toString(36).substring(7));
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 unknown as ExtendedStore;
322
+ metaStore = (await db.crdt.blockstore.loader?.metaStore()) as MetaStore;
315
323
 
316
- metaGateway = metaStore?.gateway;
324
+ metaGateway = metaStore.realGateway;
317
325
  });
318
326
  it("should subscribe to meta Gateway", async function () {
319
- const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
320
- await metaGateway?.start(metaStore?._url);
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
- const metaSubscribeResult = await metaGateway?.subscribe?.(metaUrl?.Ok(), async (data: Uint8Array) => {
328
- const decodedData = new TextDecoder().decode(data);
329
- expect(decodedData).toContain("[]");
330
- didCall = true;
331
- resolve();
332
- });
333
- if (!metaSubscribeResult?.isErr()) {
334
- expect(metaSubscribeResult?.Ok()).toBeTruthy();
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: ExtendedStore;
355
+ let metaStore: MetaStore;
348
356
  // let fileStore: ExtendedStore;
349
357
  // let walStore: ExtendedStore;
350
358
  // let carGateway: ExtendedGateway;
351
- let metaGateway: ExtendedGateway;
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 = new Database("test-gateway-" + Math.random().toString(36).substring(7));
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?.carStore()) as unknown as ExtendedStore;
367
- metaStore = (await db.blockstore.loader?.metaStore()) as unknown as ExtendedStore;
368
- // fileStore = (await db.blockstore.loader?.fileStore()) as unknown as ExtendedStore;
369
- // walStore = (await db.blockstore.loader?.WALStore()) as unknown as ExtendedStore;
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?.gateway;
373
- metaGateway = metaStore?.gateway;
374
- // fileGateway = fileStore?.gateway;
375
- // walGateway = walStore?.gateway;
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?.buildUrl(metaStore?._url, "main");
380
- await metaGateway?.start(metaStore?._url);
381
- const metaGetResult = await metaGateway?.get(metaUrl?.Ok());
382
- const metaGetResultOk = metaGetResult?.Ok();
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?.buildUrl(metaStore?._url, "main");
389
- await metaGateway?.start(metaStore?._url);
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?.delete(metaUrl?.Ok());
392
- expect(metaDeleteResult?.Ok()).toBeFalsy();
399
+ const metaDeleteResult = await metaGateway.delete(metaUrl.Ok());
400
+ expect(metaDeleteResult.isOk()).toBeTruthy();
393
401
  });
394
402
  });