@fireproof/core 0.20.0-dev-preview-40 → 0.20.0-dev-preview-41

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 (38) hide show
  1. package/README.md +6 -4
  2. package/deno/index.js +2 -2
  3. package/deno/index.js.map +1 -1
  4. package/index.cjs +499 -370
  5. package/index.cjs.map +1 -1
  6. package/index.d.cts +162 -64
  7. package/index.d.ts +162 -64
  8. package/index.js +473 -344
  9. package/index.js.map +1 -1
  10. package/metafile-cjs.json +1 -1
  11. package/metafile-esm.json +1 -1
  12. package/package.json +3 -3
  13. package/react/index.cjs +17 -9
  14. package/react/index.cjs.map +1 -1
  15. package/react/index.d.cts +2 -1
  16. package/react/index.d.ts +2 -1
  17. package/react/index.js +17 -9
  18. package/react/index.js.map +1 -1
  19. package/react/metafile-cjs.json +1 -1
  20. package/react/metafile-esm.json +1 -1
  21. package/tests/blockstore/interceptor-gateway.test.ts +5 -1
  22. package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +8 -18
  23. package/tests/blockstore/keyed-crypto.test.ts +7 -30
  24. package/tests/blockstore/loader.test.ts +19 -17
  25. package/tests/blockstore/store.test.ts +48 -51
  26. package/tests/blockstore/transaction.test.ts +13 -11
  27. package/tests/fireproof/all-gateway.test.ts +49 -46
  28. package/tests/fireproof/attachable.test.ts +82 -0
  29. package/tests/fireproof/crdt.test.ts +49 -48
  30. package/tests/fireproof/database.test.ts +40 -40
  31. package/tests/fireproof/fireproof.test.ts +43 -42
  32. package/tests/fireproof/hello.test.ts +4 -4
  33. package/tests/fireproof/indexer.test.ts +44 -44
  34. package/tests/fireproof/utils.test.ts +4 -3
  35. package/tests/gateway/file/loader-config.test.ts +17 -17
  36. package/tests/gateway/indexeddb/loader-config.test.ts +4 -4
  37. package/tests/helpers.ts +80 -2
  38. package/tests/react/useFireproof.test.tsx +40 -4
@@ -24,13 +24,13 @@ describe("basic Index", () => {
24
24
  let indexer: Index<string, TestType>;
25
25
  let didMap: boolean;
26
26
  const sthis = ensureSuperThis();
27
- afterEach(async function () {
27
+ afterEach(async () => {
28
28
  await db.close();
29
29
  await db.destroy();
30
30
  // await indexer.close();
31
31
  // await indexer.destroy();
32
32
  });
33
- beforeEach(async function () {
33
+ beforeEach(async () => {
34
34
  await sthis.start();
35
35
  db = fireproof("test-indexer");
36
36
  await db.put({ title: "amazing" });
@@ -48,41 +48,41 @@ describe("basic Index", () => {
48
48
  expect(indexer.name).toBe("hello");
49
49
  expect(indexer.mapFn).toBeTruthy();
50
50
  });
51
- it("should call the map function on first query", async function () {
51
+ it("should call the map function on first query", async () => {
52
52
  didMap = false;
53
53
  await indexer.query();
54
54
  expect(didMap).toBeTruthy();
55
55
  });
56
- it("should not call the map function on second query", async function () {
56
+ it("should not call the map function on second query", async () => {
57
57
  await indexer.query();
58
58
  didMap = false;
59
59
  await indexer.query();
60
60
  expect(didMap).toBeFalsy();
61
61
  });
62
- it("should get results", async function () {
62
+ it("should get results", async () => {
63
63
  const result = await indexer.query();
64
64
  expect(result).toBeTruthy();
65
65
  expect(result.rows).toBeTruthy();
66
66
  expect(result.rows.length).toBe(3);
67
67
  });
68
- it("should be in order", async function () {
68
+ it("should be in order", async () => {
69
69
  const { rows } = await indexer.query();
70
70
  expect(rows[0].key).toBe("amazing");
71
71
  });
72
- it("should work with limit", async function () {
72
+ it("should work with limit", async () => {
73
73
  const { rows } = await indexer.query({ limit: 1 });
74
74
  expect(rows.length).toBe(1);
75
75
  });
76
- it("should work with descending", async function () {
76
+ it("should work with descending", async () => {
77
77
  const { rows } = await indexer.query({ descending: true });
78
78
  expect(rows[0].key).toBe("creative");
79
79
  });
80
- it("should range query all", async function () {
80
+ it("should range query all", async () => {
81
81
  const { rows } = await indexer.query({ range: ["a", "z"] });
82
82
  expect(rows.length).toBe(3);
83
83
  expect(rows[0].key).toBe("amazing");
84
84
  });
85
- it("should range query all twice", async function () {
85
+ it("should range query all twice", async () => {
86
86
  const { rows } = await indexer.query({ range: ["a", "z"] });
87
87
  expect(rows.length).toBe(3);
88
88
  expect(rows[0].key).toBe("amazing");
@@ -90,15 +90,15 @@ describe("basic Index", () => {
90
90
  expect(rows2.length).toBe(3);
91
91
  expect(rows2[0].key).toBe("amazing");
92
92
  });
93
- it("should range query", async function () {
93
+ it("should range query", async () => {
94
94
  const { rows } = await indexer.query({ range: ["b", "d"] });
95
95
  expect(rows[0].key).toBe("bazillas");
96
96
  });
97
- it("should key query", async function () {
97
+ it("should key query", async () => {
98
98
  const { rows } = await indexer.query({ key: "bazillas" });
99
99
  expect(rows.length).toBe(1);
100
100
  });
101
- it("should include docs", async function () {
101
+ it("should include docs", async () => {
102
102
  const { rows } = await indexer.query({ includeDocs: true });
103
103
  expect(rows[0]).toBeTruthy();
104
104
  expect(rows[0].id).toBeTruthy();
@@ -111,13 +111,13 @@ describe("Index query with compound key", function () {
111
111
  let db: Database;
112
112
  let indexer: Index<[string, number], TestType>;
113
113
  const sthis = ensureSuperThis();
114
- afterEach(async function () {
114
+ afterEach(async () => {
115
115
  await db.close();
116
116
  await db.destroy();
117
117
  // await indexer.close();
118
118
  // await indexer.destroy();
119
119
  });
120
- beforeEach(async function () {
120
+ beforeEach(async () => {
121
121
  await sthis.start();
122
122
  db = fireproof("test-indexer");
123
123
  await db.put({ title: "amazing", score: 1 });
@@ -129,7 +129,7 @@ describe("Index query with compound key", function () {
129
129
  });
130
130
  await indexer.ready();
131
131
  });
132
- it("should prefix query", async function () {
132
+ it("should prefix query", async () => {
133
133
  const { rows } = await indexer.query({ prefix: "creative" });
134
134
  expect(rows.length).toBe(2);
135
135
  expect(rows[0].key).toEqual(["creative", 2]);
@@ -141,13 +141,13 @@ describe("basic Index with map fun", function () {
141
141
  let db: Database;
142
142
  let indexer: Index<string, TestType>;
143
143
  const sthis = ensureSuperThis();
144
- afterEach(async function () {
144
+ afterEach(async () => {
145
145
  await db.close();
146
146
  await db.destroy();
147
147
  // await indexer.close();
148
148
  // await indexer.destroy();
149
149
  });
150
- beforeEach(async function () {
150
+ beforeEach(async () => {
151
151
  await sthis.start();
152
152
  db = fireproof("test-indexer");
153
153
  await db.put({ title: "amazing" });
@@ -158,7 +158,7 @@ describe("basic Index with map fun", function () {
158
158
  });
159
159
  await indexer.ready();
160
160
  });
161
- it("should get results", async function () {
161
+ it("should get results", async () => {
162
162
  const result = await indexer.query();
163
163
  expect(result).toBeTruthy();
164
164
  expect(result.rows).toBeTruthy();
@@ -171,11 +171,11 @@ describe("basic Index with map fun with value", function () {
171
171
  let db: Database;
172
172
  let indexer: Index<string, TestType, number>;
173
173
  const sthis = ensureSuperThis();
174
- afterEach(async function () {
174
+ afterEach(async () => {
175
175
  await db.close();
176
176
  await db.destroy();
177
177
  });
178
- beforeEach(async function () {
178
+ beforeEach(async () => {
179
179
  await sthis.start();
180
180
  db = fireproof("test-indexer");
181
181
  await db.put({ title: "amazing" });
@@ -185,7 +185,7 @@ describe("basic Index with map fun with value", function () {
185
185
  map(doc.title, doc.title.length);
186
186
  });
187
187
  });
188
- it("should get results", async function () {
188
+ it("should get results", async () => {
189
189
  const result = await indexer.query();
190
190
  expect(result).toBeTruthy();
191
191
  expect(result.rows).toBeTruthy();
@@ -194,7 +194,7 @@ describe("basic Index with map fun with value", function () {
194
194
  // @jchris why is this not a object?
195
195
  expect(result.rows[0].value).toBe(7);
196
196
  });
197
- it("should include docs", async function () {
197
+ it("should include docs", async () => {
198
198
  const { rows } = await indexer.query({ includeDocs: true });
199
199
  expect(rows[0].doc).toBeTruthy();
200
200
  expect(rows[0].doc?._id).toBe(rows[0].id);
@@ -209,13 +209,13 @@ describe("Index query with map and compound key", function () {
209
209
  let db: Database;
210
210
  let indexer: Index<[string, number], TestType>;
211
211
  const sthis = ensureSuperThis();
212
- afterEach(async function () {
212
+ afterEach(async () => {
213
213
  await db.close();
214
214
  await db.destroy();
215
215
  // await indexer.close();
216
216
  // await indexer.destroy();
217
217
  });
218
- beforeEach(async function () {
218
+ beforeEach(async () => {
219
219
  await sthis.start();
220
220
  db = fireproof("test-indexer");
221
221
  await db.put({ title: "amazing", score: 1 });
@@ -227,7 +227,7 @@ describe("Index query with map and compound key", function () {
227
227
  });
228
228
  await indexer.ready();
229
229
  });
230
- it("should prefix query", async function () {
230
+ it("should prefix query", async () => {
231
231
  const { rows } = await indexer.query({ prefix: "creative" });
232
232
  expect(rows.length).toBe(2);
233
233
  expect(rows[0].key).toEqual(["creative", 2]);
@@ -239,13 +239,13 @@ describe("basic Index with string fun", function () {
239
239
  let db: Database;
240
240
  let indexer: Index<string, TestType>;
241
241
  const sthis = ensureSuperThis();
242
- afterEach(async function () {
242
+ afterEach(async () => {
243
243
  await db.close();
244
244
  await db.destroy();
245
245
  // await indexer.close();
246
246
  // await indexer.destroy();
247
247
  });
248
- beforeEach(async function () {
248
+ beforeEach(async () => {
249
249
  await sthis.start();
250
250
  db = fireproof("test-indexer");
251
251
  await db.put({ title: "amazing" });
@@ -254,13 +254,13 @@ describe("basic Index with string fun", function () {
254
254
  indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "title");
255
255
  await indexer.ready();
256
256
  });
257
- it("should get results", async function () {
257
+ it("should get results", async () => {
258
258
  const result = await indexer.query();
259
259
  expect(result).toBeTruthy();
260
260
  expect(result.rows).toBeTruthy();
261
261
  expect(result.rows.length).toBe(3);
262
262
  });
263
- it("should include docs", async function () {
263
+ it("should include docs", async () => {
264
264
  const { rows } = await indexer.query();
265
265
  expect(rows.length).toBeTruthy();
266
266
  expect(rows[0].doc).toBeTruthy();
@@ -271,13 +271,13 @@ describe("basic Index with string fun and numeric keys", function () {
271
271
  let db: Database;
272
272
  let indexer: Index<string, TestType>;
273
273
  const sthis = ensureSuperThis();
274
- afterEach(async function () {
274
+ afterEach(async () => {
275
275
  await db.close();
276
276
  await db.destroy();
277
277
  // await indexer.close();
278
278
  // await indexer.destroy();
279
279
  });
280
- beforeEach(async function () {
280
+ beforeEach(async () => {
281
281
  await sthis.start();
282
282
  db = fireproof("test-indexer");
283
283
  await db.put({ points: 0 });
@@ -287,13 +287,13 @@ describe("basic Index with string fun and numeric keys", function () {
287
287
  indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "points");
288
288
  await indexer.ready();
289
289
  });
290
- it("should get results", async function () {
290
+ it("should get results", async () => {
291
291
  const result = await indexer.query();
292
292
  expect(result).toBeTruthy();
293
293
  expect(result.rows).toBeTruthy();
294
294
  expect(result.rows.length).toBe(4);
295
295
  });
296
- it("should include docs", async function () {
296
+ it("should include docs", async () => {
297
297
  const { rows } = await indexer.query();
298
298
  expect(rows.length).toBeTruthy();
299
299
  expect(rows[0].doc).toBeTruthy();
@@ -313,13 +313,13 @@ describe("basic Index upon cold start", function () {
313
313
  const sthis = ensureSuperThis();
314
314
  let dbOpts: LedgerOpts;
315
315
  // result, mapFn;
316
- afterEach(async function () {
316
+ afterEach(async () => {
317
317
  await crdt.close();
318
318
  await crdt.destroy();
319
319
  // await indexer.close();
320
320
  // await indexer.destroy();
321
321
  });
322
- beforeEach(async function () {
322
+ beforeEach(async () => {
323
323
  await sthis.start();
324
324
  const logger = sthis.logger.With().Module("IndexerTest").Logger();
325
325
  logger.Debug().Msg("enter beforeEach");
@@ -361,7 +361,7 @@ describe("basic Index upon cold start", function () {
361
361
  expect(result.rows).toBeTruthy();
362
362
  expect(result.rows.length).toEqual(3);
363
363
  });
364
- it("should work on cold load", async function () {
364
+ it("should work on cold load", async () => {
365
365
  const crdt2 = new CRDTImpl(sthis, dbOpts);
366
366
  await crdt2.ready();
367
367
  const { result, head } = await crdt2.changes();
@@ -375,7 +375,7 @@ describe("basic Index upon cold start", function () {
375
375
  expect(result2.rows.length).toEqual(3);
376
376
  expect(indexer2.indexHead).toEqual(head);
377
377
  });
378
- it.skip("should not rerun the map function on seen changes", async function () {
378
+ it.skip("should not rerun the map function on seen changes", async () => {
379
379
  didMap = 0;
380
380
  const crdt2 = new CRDTImpl(sthis, dbOpts);
381
381
  const indexer2 = await index(crdt2, "hello", mapFn);
@@ -401,7 +401,7 @@ describe("basic Index upon cold start", function () {
401
401
  expect(result3.rows.length).toEqual(4);
402
402
  expect(didMap).toEqual(1);
403
403
  });
404
- it("should ignore meta when map function definiton changes", async function () {
404
+ it("should ignore meta when map function definiton changes", async () => {
405
405
  const crdt2 = new CRDTImpl(sthis, dbOpts);
406
406
  const result = await index<string, TestType>(crdt2, "hello", (doc) => doc.title.split("").reverse().join("")).query();
407
407
  expect(result.rows.length).toEqual(3);
@@ -414,13 +414,13 @@ describe("basic Index with no data", function () {
414
414
  let indexer: Index<string, TestType>;
415
415
  let didMap: boolean;
416
416
  const sthis = ensureSuperThis();
417
- afterEach(async function () {
417
+ afterEach(async () => {
418
418
  await db.close();
419
419
  await db.destroy();
420
420
  // await indexer.close();
421
421
  // await indexer.destroy();
422
422
  });
423
- beforeEach(async function () {
423
+ beforeEach(async () => {
424
424
  await sthis.start();
425
425
  db = fireproof("test-indexer");
426
426
  indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "hello", (doc) => {
@@ -434,18 +434,18 @@ describe("basic Index with no data", function () {
434
434
  expect(indexer.name).toEqual("hello");
435
435
  expect(indexer.mapFn).toBeTruthy();
436
436
  });
437
- it("should not call the map function on first query", async function () {
437
+ it("should not call the map function on first query", async () => {
438
438
  didMap = false;
439
439
  await indexer.query();
440
440
  expect(didMap).toBeFalsy();
441
441
  });
442
- it("should not call the map function on second query", async function () {
442
+ it("should not call the map function on second query", async () => {
443
443
  await indexer.query();
444
444
  didMap = false;
445
445
  await indexer.query();
446
446
  expect(didMap).toBeFalsy();
447
447
  });
448
- it("should get results", async function () {
448
+ it("should get results", async () => {
449
449
  const result = await indexer.query();
450
450
  expect(result).toBeTruthy();
451
451
  expect(result.rows).toBeTruthy();
@@ -112,11 +112,12 @@ describe("utils", () => {
112
112
 
113
113
  describe("runtime", () => {
114
114
  it("runtime", () => {
115
- const isNode = !!(typeof process === "object" && process.versions?.node);
115
+ const isDeno = !!(typeof process === "object" && process.versions?.deno);
116
+ const isNode = !isDeno && !!(typeof process === "object" && process.versions?.node);
116
117
  expect(runtimeFn()).toEqual({
117
- isBrowser: !isNode,
118
+ isBrowser: !(isNode || isDeno),
118
119
  isCFWorker: false,
119
- isDeno: false,
120
+ isDeno: isDeno,
120
121
  isNodeIsh: isNode,
121
122
  isReactNative: false,
122
123
  });
@@ -1,4 +1,4 @@
1
- import { BuildURI, CoerceURI, URI } from "@adviser/cement";
1
+ import { BuildURI, CoerceURI, runtimeFn, URI } from "@adviser/cement";
2
2
  import { fireproof, PARAM, rt, SuperThis } from "@fireproof/core";
3
3
  import { mockSuperThis } from "../../helpers.js";
4
4
 
@@ -37,7 +37,7 @@ describe("config file gateway", () => {
37
37
  await db.put({ name: "my-app" });
38
38
  expect(db.ledger.name).toBe(my_app());
39
39
 
40
- const fileStore = await db.ledger.crdt.blockstore.loader?.fileStore();
40
+ const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
41
41
  expect(fileStore?.url().asObj()).toEqual({
42
42
  pathname: "./dist/fp-dir-file",
43
43
  protocol: "file:",
@@ -52,7 +52,7 @@ describe("config file gateway", () => {
52
52
  style: "path",
53
53
  });
54
54
 
55
- const dataStore = await db.ledger.crdt.blockstore.loader?.carStore();
55
+ const dataStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
56
56
  expect(dataStore?.url().asObj()).toEqual({
57
57
  pathname: "./dist/fp-dir-file",
58
58
  protocol: "file:",
@@ -67,7 +67,7 @@ describe("config file gateway", () => {
67
67
  },
68
68
  style: "path",
69
69
  });
70
- const metaStore = await db.ledger.crdt.blockstore.loader?.metaStore();
70
+ const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
71
71
  expect(metaStore?.url().asObj()).toEqual({
72
72
  pathname: "./dist/fp-dir-file",
73
73
  protocol: "file:",
@@ -81,7 +81,7 @@ describe("config file gateway", () => {
81
81
  },
82
82
  style: "path",
83
83
  });
84
- const WALStore = await db.ledger.crdt.blockstore.loader?.WALStore();
84
+ const WALStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.wal;
85
85
  expect(WALStore?.url().asObj()).toEqual({
86
86
  pathname: "./dist/fp-dir-file",
87
87
  protocol: "file:",
@@ -114,7 +114,7 @@ describe("config file gateway", () => {
114
114
  // console.log(`>>>>>>>>>>>>>>>file-path`)
115
115
  await db.put({ name: "my-app" });
116
116
  expect(db.ledger.name).toBe(my_app());
117
- const carStore = await db.ledger.crdt.blockstore.loader?.carStore();
117
+ const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
118
118
  expect(carStore?.url().asObj()).toEqual({
119
119
  pathname: "./dist/data",
120
120
  protocol: "file:",
@@ -128,7 +128,7 @@ describe("config file gateway", () => {
128
128
  },
129
129
  style: "path",
130
130
  });
131
- const fileStore = await db.ledger.crdt.blockstore.loader?.fileStore();
131
+ const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
132
132
  expect(fileStore?.url().asObj()).toEqual({
133
133
  pathname: "./dist/data",
134
134
  protocol: "file:",
@@ -142,7 +142,7 @@ describe("config file gateway", () => {
142
142
  style: "path",
143
143
  });
144
144
  expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
145
- const metaStore = await db.ledger.crdt.blockstore.loader?.metaStore();
145
+ const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
146
146
  expect(metaStore?.url().asObj()).toEqual({
147
147
  pathname: "./dist/data",
148
148
  protocol: "file:",
@@ -180,7 +180,7 @@ describe("config file gateway", () => {
180
180
  const db = fireproof(my_app());
181
181
  await db.put({ name: "my-app" });
182
182
  expect(db.ledger.name).toBe(my_app());
183
- const carStore = await db.ledger.crdt.blockstore.loader?.carStore();
183
+ const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
184
184
 
185
185
  expect(carStore?.url().asObj()).toEqual({
186
186
  pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
@@ -189,7 +189,7 @@ describe("config file gateway", () => {
189
189
  searchParams: {
190
190
  // ...isMemFS,
191
191
  suffix: ".car",
192
- runtime: "node",
192
+ runtime: runtimeFn().isDeno ? "deno" : "node",
193
193
  urlGen: "default",
194
194
  store: "data",
195
195
  name: my_app(),
@@ -200,14 +200,14 @@ describe("config file gateway", () => {
200
200
 
201
201
  expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
202
202
 
203
- const fileStore = await db.ledger.crdt.blockstore.loader?.fileStore();
203
+ const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
204
204
  expect(fileStore?.url().asObj()).toEqual({
205
205
  pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
206
206
  protocol: "file:",
207
207
  style: "path",
208
208
  searchParams: {
209
209
  // ...isMemFS,
210
- runtime: "node",
210
+ runtime: runtimeFn().isDeno ? "deno" : "node",
211
211
  urlGen: "default",
212
212
  store: "data",
213
213
  name: my_app(),
@@ -215,14 +215,14 @@ describe("config file gateway", () => {
215
215
  version: rt.FILESTORE_VERSION,
216
216
  },
217
217
  });
218
- const metaStore = await db.ledger.crdt.blockstore.loader?.metaStore();
218
+ const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
219
219
  expect(metaStore?.url().asObj()).toEqual({
220
220
  pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
221
221
  protocol: "file:",
222
222
  style: "path",
223
223
  searchParams: {
224
224
  // ...isMemFS,
225
- runtime: "node",
225
+ runtime: runtimeFn().isDeno ? "deno" : "node",
226
226
  urlGen: "default",
227
227
  store: "meta",
228
228
  name: my_app(),
@@ -253,7 +253,7 @@ describe("config file gateway", () => {
253
253
  const db = fireproof(my_app());
254
254
  await db.put({ name: "my-app" });
255
255
  expect(db.ledger.name).toBe(my_app());
256
- const carStore = await db.ledger.crdt.blockstore.loader.carStore();
256
+ const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
257
257
  expect(carStore?.url().asObj()).toEqual({
258
258
  pathname: "./dist/fp-dir-file",
259
259
  protocol: "file:",
@@ -271,7 +271,7 @@ describe("config file gateway", () => {
271
271
  });
272
272
 
273
273
  expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
274
- const fileStore = await db.ledger.crdt.blockstore.loader?.fileStore();
274
+ const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
275
275
  expect(fileStore?.url().asObj()).toEqual({
276
276
  pathname: `./dist/fp-dir-file`,
277
277
  protocol: "file:",
@@ -286,7 +286,7 @@ describe("config file gateway", () => {
286
286
  },
287
287
  });
288
288
 
289
- const metaStore = await db.ledger.crdt.blockstore.loader?.metaStore();
289
+ const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
290
290
  expect(metaStore?.url().asObj()).toEqual({
291
291
  pathname: `./dist/fp-dir-file`,
292
292
  protocol: "file:",
@@ -16,7 +16,7 @@ describe("fireproof config indexeddb", () => {
16
16
  await db.put({ name: "my-app" });
17
17
  expect(db.ledger.name).toBe(my_app());
18
18
 
19
- const fileStore = await db.ledger.crdt.blockstore.loader.fileStore();
19
+ const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
20
20
  expect(fileStore?.url().asObj()).toEqual({
21
21
  pathname: "fp",
22
22
  protocol: "indexeddb:",
@@ -31,7 +31,7 @@ describe("fireproof config indexeddb", () => {
31
31
  style: "path",
32
32
  });
33
33
 
34
- const dataStore = await db.ledger.crdt.blockstore.loader.carStore();
34
+ const dataStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
35
35
  expect(dataStore?.url().asObj()).toEqual({
36
36
  pathname: "fp",
37
37
  protocol: "indexeddb:",
@@ -46,7 +46,7 @@ describe("fireproof config indexeddb", () => {
46
46
  },
47
47
  style: "path",
48
48
  });
49
- const metaStore = await db.ledger.crdt.blockstore.loader.metaStore();
49
+ const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
50
50
  expect(metaStore?.url().asObj()).toEqual({
51
51
  pathname: "fp",
52
52
  protocol: "indexeddb:",
@@ -60,7 +60,7 @@ describe("fireproof config indexeddb", () => {
60
60
  },
61
61
  style: "path",
62
62
  });
63
- const WALStore = await db.ledger.crdt.blockstore.loader.WALStore();
63
+ const WALStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.wal;
64
64
  expect(WALStore?.url().asObj()).toEqual({
65
65
  pathname: "fp",
66
66
  protocol: "indexeddb:",
package/tests/helpers.ts CHANGED
@@ -1,8 +1,21 @@
1
1
  import { BuildURI, MockLogger, runtimeFn, toCryptoRuntime, URI, utils, LogCollector } from "@adviser/cement";
2
- import { ensureSuperThis, rt, SuperThis, SuperThisOpts, bs, PARAM } from "@fireproof/core";
2
+ import {
3
+ ensureSuperThis,
4
+ rt,
5
+ SuperThis,
6
+ SuperThisOpts,
7
+ bs,
8
+ PARAM,
9
+ Attachable,
10
+ Attached,
11
+ CarTransaction,
12
+ Falsy,
13
+ } from "@fireproof/core";
3
14
  import { CID } from "multiformats";
4
15
  import { sha256 } from "multiformats/hashes/sha2";
5
16
  import * as json from "multiformats/codecs/json";
17
+ import { CarReader } from "@ipld/car";
18
+ import { TaskManager } from "../src/blockstore/task-manager.js";
6
19
 
7
20
  export function sleep(ms: number) {
8
21
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -67,7 +80,7 @@ export function simpleBlockOpts(sthis: SuperThis, name?: string) {
67
80
  file: url,
68
81
  wal: url,
69
82
  meta: url,
70
- data: url,
83
+ car: url,
71
84
  },
72
85
  };
73
86
  }
@@ -77,3 +90,68 @@ export async function simpleCID(sthis: SuperThis) {
77
90
  const hash = await sha256.digest(bytes);
78
91
  return CID.create(1, json.code, hash);
79
92
  }
93
+
94
+ class MockLoader implements bs.Loadable {
95
+ readonly sthis: SuperThis;
96
+ readonly ebOpts: bs.BlockstoreRuntime;
97
+ readonly carLog: bs.CarLog;
98
+ readonly attachedStores: bs.AttachedStores;
99
+ readonly taskManager: TaskManager;
100
+
101
+ constructor(sthis: SuperThis) {
102
+ this.sthis = sthis;
103
+ this.ebOpts = {} as bs.BlockstoreRuntime;
104
+ this.carLog = [];
105
+ this.taskManager = new TaskManager(sthis, () => Promise.resolve());
106
+ this.attachedStores = new bs.AttachedRemotesImpl(this);
107
+ }
108
+
109
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
110
+ attach(attached: Attachable): Promise<Attached> {
111
+ throw new Error("Method not implemented.");
112
+ }
113
+ ready(): Promise<void> {
114
+ throw new Error("Method not implemented.");
115
+ }
116
+ close(): Promise<void> {
117
+ throw new Error("Method not implemented.");
118
+ }
119
+ keyBag(): Promise<rt.KeyBag> {
120
+ return rt.kb.getKeyBag(this.sthis, {});
121
+ }
122
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
123
+ handleDbMetasFromStore(metas: bs.DbMeta[], store: bs.ActiveStore): Promise<void> {
124
+ // throw new Error("Method not implemented.");
125
+ return Promise.resolve();
126
+ }
127
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
128
+ commit<T = unknown>(t: CarTransaction, done: T, opts: bs.CommitOpts): Promise<bs.CarGroup> {
129
+ throw new Error("Method not implemented.");
130
+ }
131
+ destroy(): Promise<void> {
132
+ throw new Error("Method not implemented.");
133
+ }
134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
135
+ getBlock(cid: bs.AnyLink, store: bs.ActiveStore): Promise<bs.AnyBlock | Falsy> {
136
+ throw new Error("Method not implemented.");
137
+ }
138
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
+ loadFileCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<CarReader> {
140
+ throw new Error("Method not implemented.");
141
+ }
142
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
143
+ loadCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<CarReader> {
144
+ throw new Error("Method not implemented.");
145
+ }
146
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
147
+ commitFiles(t: CarTransaction, done: bs.TransactionMeta): Promise<bs.CarGroup> {
148
+ throw new Error("Method not implemented.");
149
+ }
150
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
151
+ entries(cache?: boolean): AsyncIterableIterator<bs.AnyBlock> {
152
+ throw new Error("Method not implemented.");
153
+ }
154
+ }
155
+ export function mockLoader(sthis: SuperThis): bs.Loadable {
156
+ return new MockLoader(sthis);
157
+ }