@fireproof/core 0.19.101 → 0.19.103

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/{chunk-3EB3ENHT.js → chunk-OFGPKRCM.js} +25 -54
  2. package/chunk-OFGPKRCM.js.map +1 -0
  3. package/chunk-WS3YRPIA.js +75 -0
  4. package/chunk-WS3YRPIA.js.map +1 -0
  5. package/{gateway-GK5QZ6KP.js → gateway-5FCWPX5W.js} +12 -13
  6. package/gateway-5FCWPX5W.js.map +1 -0
  7. package/{gateway-TQTGDRCN.js → gateway-H7UD6TNB.js} +8 -9
  8. package/gateway-H7UD6TNB.js.map +1 -0
  9. package/index.cjs +1571 -1992
  10. package/index.cjs.map +1 -1
  11. package/index.d.cts +117 -257
  12. package/index.d.ts +117 -257
  13. package/index.global.js +12280 -12741
  14. package/index.global.js.map +1 -1
  15. package/index.js +1463 -1790
  16. package/index.js.map +1 -1
  17. package/{key-bag-file-VOSSK46F.js → key-bag-file-WADZBHYG.js} +3 -4
  18. package/{key-bag-file-VOSSK46F.js.map → key-bag-file-WADZBHYG.js.map} +1 -1
  19. package/{key-bag-indexdb-AXTQOSMC.js → key-bag-indexdb-PGVAI3FJ.js} +3 -4
  20. package/{key-bag-indexdb-AXTQOSMC.js.map → key-bag-indexdb-PGVAI3FJ.js.map} +1 -1
  21. package/mem-filesystem-YPPJV7Q2.js +41 -0
  22. package/mem-filesystem-YPPJV7Q2.js.map +1 -0
  23. package/metafile-cjs.json +1 -1
  24. package/metafile-esm.json +1 -1
  25. package/metafile-iife.json +1 -1
  26. package/{node-filesystem-CFRXFSO7.js → node-filesystem-INX4ZTHE.js} +9 -6
  27. package/node-filesystem-INX4ZTHE.js.map +1 -0
  28. package/package.json +1 -1
  29. package/tests/blockstore/keyed-crypto.test.ts +227 -63
  30. package/tests/blockstore/loader.test.ts +11 -19
  31. package/tests/blockstore/store.test.ts +19 -23
  32. package/tests/blockstore/transaction.test.ts +12 -12
  33. package/tests/fireproof/all-gateway.test.ts +193 -201
  34. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +316 -324
  35. package/tests/fireproof/config.test.ts +172 -0
  36. package/tests/fireproof/crdt.test.ts +16 -67
  37. package/tests/fireproof/database.test.ts +21 -183
  38. package/tests/fireproof/fireproof.test.ts +74 -83
  39. package/tests/fireproof/hello.test.ts +14 -18
  40. package/tests/fireproof/indexer.test.ts +43 -53
  41. package/tests/fireproof/utils.test.ts +6 -18
  42. package/tests/helpers.ts +9 -27
  43. package/tests/react/useFireproof.test.tsx +1 -1
  44. package/{utils-STA2C35G.js → utils-QO2HIWGI.js} +3 -4
  45. package/chunk-3EB3ENHT.js.map +0 -1
  46. package/chunk-HQ7D3PEU.js +0 -61
  47. package/chunk-HQ7D3PEU.js.map +0 -1
  48. package/chunk-PZ5AY32C.js +0 -10
  49. package/deno-filesystem-Q2IJ7YDR.js +0 -57
  50. package/deno-filesystem-Q2IJ7YDR.js.map +0 -1
  51. package/gateway-GK5QZ6KP.js.map +0 -1
  52. package/gateway-TQTGDRCN.js.map +0 -1
  53. package/key-bag-memory-LWE6ARPX.js +0 -29
  54. package/key-bag-memory-LWE6ARPX.js.map +0 -1
  55. package/node-filesystem-CFRXFSO7.js.map +0 -1
  56. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +0 -129
  57. package/tests/gateway/file/loader-config.test.ts +0 -303
  58. package/tests/gateway/indexdb/loader-config.test.ts +0 -75
  59. package/utils-STA2C35G.js.map +0 -1
  60. /package/tests/fireproof/{fireproof.fixture.ts → fireproof.test.fixture.ts} +0 -0
  61. /package/{chunk-PZ5AY32C.js.map → utils-QO2HIWGI.js.map} +0 -0
@@ -1,64 +1,59 @@
1
- import { Database, DatabaseFactory, bs } from "@fireproof/core";
1
+ import { Database, bs } from "@fireproof/core";
2
+ import { URI } from "@adviser/cement";
2
3
 
3
4
  import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
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
- // }
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
+ }
29
27
 
30
28
  describe("noop Gateway", function () {
31
29
  let db: Database;
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();
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;
41
38
 
42
39
  afterEach(async function () {
43
40
  await db.close();
44
41
  await db.destroy();
45
42
  });
46
43
  beforeEach(async function () {
47
- db = DatabaseFactory("test-gateway-" + sthis.nextId().str, {
48
- logger: sthis.logger,
49
- });
44
+ db = new Database("test-gateway-" + Math.random().toString(36).substring(7));
50
45
 
51
46
  // Extract stores from the loader
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;
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;
56
51
 
57
52
  // Extract and log gateways
58
- carGateway = carStore.realGateway;
59
- metaGateway = metaStore.realGateway;
60
- fileGateway = fileStore.realGateway;
61
- walGateway = walStore.realGateway;
53
+ carGateway = carStore?.gateway;
54
+ metaGateway = metaStore?.gateway;
55
+ fileGateway = fileStore?.gateway;
56
+ walGateway = walStore?.gateway;
62
57
  });
63
58
 
64
59
  it("should have valid stores and gateways", async function () {
@@ -76,27 +71,26 @@ describe("noop Gateway", function () {
76
71
 
77
72
  it("should have correct store names", async function () {
78
73
  // Check that all stores have the correct name
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");
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");
83
78
  });
84
79
 
85
80
  it("should have correct store types in URLs", async function () {
86
81
  // Check that all stores have the correct store type in their URL
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");
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");
92
86
  });
93
87
 
94
88
  it("should have version specified in URLs", async function () {
95
89
  // Verify that all stores have a version specified
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=");
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=");
100
94
  });
101
95
 
102
96
  it("should have correct gateway types", async function () {
@@ -109,105 +103,116 @@ describe("noop Gateway", function () {
109
103
 
110
104
  it("should build CAR Gateway URL", async function () {
111
105
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
112
- const carUrl = await carGateway.buildUrl(carStore.url(), testKey);
113
- expect(carUrl.Ok().hasParam("key")).toBeTruthy();
106
+ const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
107
+ expect(carUrl?.Ok()).toBeTruthy();
114
108
  });
115
109
 
116
110
  it("should start CAR Gateway", async function () {
117
- const url = await carGateway.start(carStore.url());
118
- expect(url.Ok().asObj()).toEqual(carStore.url().asObj());
111
+ await carGateway?.start(carStore?._url);
119
112
  });
120
113
 
121
114
  it("should put data in CAR Gateway", async function () {
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();
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();
126
121
  });
127
122
 
128
123
  it("should get data from CAR Gateway", async function () {
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");
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");
135
131
  });
136
132
 
137
133
  it("should delete data from CAR Gateway", async function () {
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();
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();
143
141
  });
144
142
 
145
143
  it("should close CAR Gateway", async function () {
146
- await carGateway.close(carStore.url());
144
+ await carGateway?.close(carStore?._url);
147
145
  });
148
146
  it("should build Meta Gateway URL", async function () {
149
- const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
150
- expect(metaUrl.Ok()).toBeTruthy();
147
+ const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
148
+ expect(metaUrl?.Ok()).toBeTruthy();
151
149
  });
152
150
 
153
151
  it("should start Meta Gateway", async function () {
154
- await metaGateway.start(metaStore.url());
152
+ await metaGateway?.start(metaStore?._url);
155
153
  });
156
154
 
157
155
  it("should close Meta Gateway", async function () {
158
- await metaGateway.start(metaStore.url());
159
- await metaGateway.close(metaStore.url());
156
+ await metaGateway?.start(metaStore?._url);
157
+ await metaGateway?.close(metaStore?._url);
160
158
  });
161
159
 
162
160
  it("should build File Gateway URL", async function () {
163
- const fileUrl = await fileGateway.buildUrl(fileStore.url(), fileContent.cid);
164
- expect(fileUrl.Ok()).toBeTruthy();
161
+ const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
162
+ const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
163
+ expect(fileUrl?.Ok()).toBeTruthy();
165
164
  });
166
165
 
167
166
  it("should start File Gateway", async function () {
168
- await fileGateway.start(fileStore.url());
167
+ await fileGateway?.start(fileStore?._url);
169
168
  });
170
169
 
171
170
  it("should put data to File Gateway", async function () {
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();
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();
176
177
  });
177
178
 
178
179
  it("should get data from File Gateway", async function () {
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);
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");
184
187
  });
185
188
 
186
189
  it("should delete data from File Gateway", async function () {
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();
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();
192
197
  });
193
198
 
194
199
  it("should close File Gateway", async function () {
195
- await fileGateway.close(fileStore.url());
200
+ await fileGateway?.close(fileStore?._url);
196
201
  });
197
202
  it("should build WAL Gateway URL", async function () {
198
203
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
199
- const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
200
- expect(walUrl.Ok()).toBeTruthy();
204
+ const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
205
+ expect(walUrl?.Ok()).toBeTruthy();
201
206
  });
202
207
 
203
208
  it("should start WAL Gateway", async function () {
204
- await walGateway.start(walStore.url());
209
+ await walGateway?.start(walStore?._url);
205
210
  });
206
211
 
207
212
  it("should put data to WAL Gateway", async function () {
208
213
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
209
- const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
210
- await walGateway.start(walStore.url());
214
+ const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
215
+ await walGateway?.start(walStore?._url);
211
216
  const walTestDataString = JSON.stringify({
212
217
  operations: [],
213
218
  noLoaderOps: [],
@@ -215,14 +220,14 @@ describe("noop Gateway", function () {
215
220
  });
216
221
  const walEncoder = new TextEncoder();
217
222
  const walTestData = walEncoder.encode(walTestDataString);
218
- const walPutResult = await walGateway.put(walUrl.Ok(), walTestData);
219
- expect(walPutResult.Ok()).toBeFalsy();
223
+ const walPutResult = await walGateway?.put(walUrl?.Ok(), walTestData);
224
+ expect(walPutResult?.Ok()).toBeFalsy();
220
225
  });
221
226
 
222
227
  it("should get data from WAL Gateway", async function () {
223
228
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
224
- const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
225
- await walGateway.start(walStore.url());
229
+ const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
230
+ await walGateway?.start(walStore?._url);
226
231
  const walTestDataString = JSON.stringify({
227
232
  operations: [],
228
233
  noLoaderOps: [],
@@ -230,17 +235,17 @@ describe("noop Gateway", function () {
230
235
  });
231
236
  const walEncoder = new TextEncoder();
232
237
  const walTestData = walEncoder.encode(walTestDataString);
233
- await walGateway.put(walUrl.Ok(), walTestData);
234
- const walGetResult = await walGateway.get(walUrl.Ok());
235
- const okResult = walGetResult.Ok();
238
+ await walGateway?.put(walUrl?.Ok(), walTestData);
239
+ const walGetResult = await walGateway?.get(walUrl?.Ok());
240
+ const okResult = walGetResult?.Ok();
236
241
  const decodedResult = new TextDecoder().decode(okResult);
237
242
  expect(decodedResult).toEqual(walTestDataString);
238
243
  });
239
244
 
240
245
  it("should delete data from WAL Gateway", async function () {
241
246
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
242
- const walUrl = await walGateway.buildUrl(walStore.url(), testKey);
243
- await walGateway.start(walStore.url());
247
+ const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
248
+ await walGateway?.start(walStore?._url);
244
249
  const walTestDataString = JSON.stringify({
245
250
  operations: [],
246
251
  noLoaderOps: [],
@@ -248,98 +253,85 @@ describe("noop Gateway", function () {
248
253
  });
249
254
  const walEncoder = new TextEncoder();
250
255
  const walTestData = walEncoder.encode(walTestDataString);
251
- await walGateway.put(walUrl.Ok(), walTestData);
252
- const walDeleteResult = await walGateway.delete(walUrl.Ok());
253
- expect(walDeleteResult.isOk()).toBeTruthy();
256
+ await walGateway?.put(walUrl?.Ok(), walTestData);
257
+ const walDeleteResult = await walGateway?.delete(walUrl?.Ok());
258
+ expect(walDeleteResult?.Ok()).toBeFalsy();
254
259
  });
255
260
 
256
261
  it("should close WAL Gateway", async function () {
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
- // });
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
+ });
304
297
  });
305
298
 
306
299
  describe("noop Gateway subscribe", function () {
307
300
  let db: Database;
308
301
 
309
- let metaStore: MetaStore;
302
+ let metaStore: ExtendedStore;
310
303
 
311
- let metaGateway: Gateway;
312
- const sthis = mockSuperThis();
304
+ let metaGateway: ExtendedGateway;
313
305
 
314
306
  afterEach(async function () {
315
307
  await db.close();
316
308
  await db.destroy();
317
309
  });
318
310
  beforeEach(async function () {
319
- db = DatabaseFactory("test-gateway-" + sthis.nextId().str);
311
+ db = new Database("test-gateway-" + Math.random().toString(36).substring(7));
320
312
 
321
313
  // Extract stores from the loader
322
- metaStore = (await db.crdt.blockstore.loader?.metaStore()) as MetaStore;
314
+ metaStore = (await db.blockstore.loader?.metaStore()) as unknown as ExtendedStore;
323
315
 
324
- metaGateway = metaStore.realGateway;
316
+ metaGateway = metaStore?.gateway;
325
317
  });
326
318
  it("should subscribe to meta Gateway", async function () {
327
- const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
328
- await metaGateway.start(metaStore.url());
319
+ const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
320
+ await metaGateway?.start(metaStore?._url);
329
321
 
330
322
  let resolve: () => void;
331
323
  let didCall = false;
332
324
  const p = new Promise<void>((r) => {
333
325
  resolve = r;
334
326
  });
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();
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();
343
335
  const ok = await db.put({ _id: "key1", hello: "world1" });
344
336
  expect(ok).toBeTruthy();
345
337
  expect(ok.id).toBe("key1");
@@ -352,11 +344,11 @@ describe("noop Gateway subscribe", function () {
352
344
  describe("Gateway", function () {
353
345
  let db: Database;
354
346
  // let carStore: ExtendedStore;
355
- let metaStore: MetaStore;
347
+ let metaStore: ExtendedStore;
356
348
  // let fileStore: ExtendedStore;
357
349
  // let walStore: ExtendedStore;
358
350
  // let carGateway: ExtendedGateway;
359
- let metaGateway: Gateway;
351
+ let metaGateway: ExtendedGateway;
360
352
  // let fileGateway: ExtendedGateway;
361
353
  // let walGateway: ExtendedGateway;
362
354
 
@@ -365,38 +357,38 @@ describe("Gateway", function () {
365
357
  await db.destroy();
366
358
  });
367
359
  beforeEach(async function () {
368
- db = DatabaseFactory("test-gateway-" + mockSuperThis().nextId().str);
360
+ db = new Database("test-gateway-" + Math.random().toString(36).substring(7));
369
361
  const ok = await db.put({ _id: "test", foo: "bar" });
370
362
  expect(ok).toBeTruthy();
371
363
  expect(ok.id).toBe("test");
372
364
 
373
365
  // Extract stores from the 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;
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;
378
370
 
379
371
  // Extract and log gateways
380
- // carGateway = carStore.gateway;
381
- metaGateway = metaStore.realGateway;
382
- // fileGateway = fileStore.gateway;
383
- // walGateway = walStore.gateway;
372
+ // carGateway = carStore?.gateway;
373
+ metaGateway = metaStore?.gateway;
374
+ // fileGateway = fileStore?.gateway;
375
+ // walGateway = walStore?.gateway;
384
376
  });
385
377
 
386
378
  it("should get data from Meta Gateway", async function () {
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();
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();
391
383
  const decodedMetaGetResultOk = new TextDecoder().decode(metaGetResultOk);
392
384
  expect(decodedMetaGetResultOk).toContain("parents");
393
385
  });
394
386
 
395
387
  it("should delete data from Meta Gateway", async function () {
396
- const metaUrl = await metaGateway.buildUrl(metaStore.url(), "main");
397
- await metaGateway.start(metaStore.url());
388
+ const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
389
+ await metaGateway?.start(metaStore?._url);
398
390
  // should we be testing .destroy() instead?
399
- const metaDeleteResult = await metaGateway.delete(metaUrl.Ok());
400
- expect(metaDeleteResult.isOk()).toBeTruthy();
391
+ const metaDeleteResult = await metaGateway?.delete(metaUrl?.Ok());
392
+ expect(metaDeleteResult?.Ok()).toBeFalsy();
401
393
  });
402
394
  });