@fireproof/core 0.20.0-dev-preview-39 → 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 +28 -11
  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 +29 -12
  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 +79 -4
@@ -6,11 +6,11 @@ import { Index, index } from "@fireproof/core";
6
6
  describe("Fresh crdt", function () {
7
7
  let crdt: CRDT;
8
8
  const sthis = ensureSuperThis();
9
- afterEach(async function () {
9
+ afterEach(async () => {
10
10
  await crdt.close();
11
11
  await crdt.destroy();
12
12
  });
13
- beforeEach(async function () {
13
+ beforeEach(async () => {
14
14
  await sthis.start();
15
15
  const dbOpts: LedgerOpts = {
16
16
  name: "test-crdt",
@@ -20,17 +20,18 @@ describe("Fresh crdt", function () {
20
20
  storeEnDe: bs.ensureStoreEnDeFile({}),
21
21
  };
22
22
  crdt = new CRDTImpl(sthis, dbOpts);
23
+ await crdt.ready();
23
24
  });
24
- it("should have an empty head", async function () {
25
+ it("should have an empty head", async () => {
25
26
  const head = crdt.clock.head;
26
27
  expect(head.length).toBe(0);
27
28
  });
28
- it("should accept put and return results", async function () {
29
+ it("should accept put and return results", async () => {
29
30
  const didPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
30
31
  const head = didPut.head;
31
32
  expect(head.length).toBe(1);
32
33
  });
33
- it("should accept multi-put and return results", async function () {
34
+ it("should accept multi-put and return results", async () => {
34
35
  const didPut = await crdt.bulk([
35
36
  { id: "ace", value: { points: 11 } },
36
37
  { id: "king", value: { points: 10 } },
@@ -49,12 +50,12 @@ describe("CRDT with one record", function () {
49
50
  let firstPut: CRDTMeta;
50
51
  const sthis = ensureSuperThis();
51
52
 
52
- afterEach(async function () {
53
+ afterEach(async () => {
53
54
  await crdt.close();
54
55
  await crdt.destroy();
55
56
  });
56
57
 
57
- beforeEach(async function () {
58
+ beforeEach(async () => {
58
59
  await sthis.start();
59
60
  const dbOpts: LedgerOpts = {
60
61
  name: "test-crdt",
@@ -66,32 +67,32 @@ describe("CRDT with one record", function () {
66
67
  crdt = new CRDTImpl(sthis, dbOpts);
67
68
  firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
68
69
  });
69
- it("should have a one-element head", async function () {
70
+ it("should have a one-element head", async () => {
70
71
  const head = crdt.clock.head;
71
72
  expect(head.length).toBe(1);
72
73
  });
73
- it("should return the head", async function () {
74
+ it("should return the head", async () => {
74
75
  expect(firstPut.head.length).toBe(1);
75
76
  });
76
- it("return the record on get", async function () {
77
+ it("return the record on get", async () => {
77
78
  const got = (await crdt.get("hello")) as DocValue<CRDTTestType>;
78
79
  expect(got).toBeTruthy();
79
80
  expect(got.doc.hello).toBe("world");
80
81
  });
81
- it("should accept another put and return results", async function () {
82
+ it("should accept another put and return results", async () => {
82
83
  const didPut = await crdt.bulk([{ id: "nice", value: { nice: "data" } }]);
83
84
  const head = didPut.head;
84
85
  expect(head.length).toBe(1);
85
86
  const { doc } = (await crdt.get("nice")) as DocValue<CRDTTestType>;
86
87
  expect(doc.nice).toBe("data");
87
88
  });
88
- it("should allow for a delete", async function () {
89
+ it("should allow for a delete", async () => {
89
90
  const didDel = await crdt.bulk([{ id: "hello", del: true }]);
90
91
  expect(didDel.head).toBeTruthy();
91
92
  const got = await crdt.get("hello");
92
93
  expect(got).toBeFalsy();
93
94
  });
94
- it("should offer changes", async function () {
95
+ it("should offer changes", async () => {
95
96
  const { result } = await crdt.changes<Partial<CRDTTestType>>([]);
96
97
  expect(result.length).toBe(1);
97
98
  expect(result[0].id).toBe("hello");
@@ -107,11 +108,11 @@ describe("CRDT with a multi-write", function () {
107
108
  let firstPut: CRDTMeta;
108
109
  const sthis = ensureSuperThis();
109
110
 
110
- afterEach(async function () {
111
+ afterEach(async () => {
111
112
  await crdt.close();
112
113
  await crdt.destroy();
113
114
  });
114
- beforeEach(async function () {
115
+ beforeEach(async () => {
115
116
  await sthis.start();
116
117
  const dbOpts: LedgerOpts = {
117
118
  name: "test-crdt",
@@ -126,12 +127,12 @@ describe("CRDT with a multi-write", function () {
126
127
  { id: "king", value: { points: 10 } },
127
128
  ]);
128
129
  });
129
- it("should have a one-element head", async function () {
130
+ it("should have a one-element head", async () => {
130
131
  const head = crdt.clock.head;
131
132
  expect(head.length).toBe(1);
132
133
  expect(firstPut.head.length).toBe(1);
133
134
  });
134
- it("return the records on get", async function () {
135
+ it("return the records on get", async () => {
135
136
  const { doc } = (await crdt.get("ace")) as DocValue<CRDTTestType>;
136
137
  expect(doc.points).toBe(11);
137
138
 
@@ -139,7 +140,7 @@ describe("CRDT with a multi-write", function () {
139
140
  expect(got2).toBeTruthy();
140
141
  expect(got2.doc.points).toBe(10);
141
142
  });
142
- it("should accept another put and return results", async function () {
143
+ it("should accept another put and return results", async () => {
143
144
  const didPut = await crdt.bulk([{ id: "queen", value: { points: 10 } }]);
144
145
  const head = didPut.head;
145
146
  expect(head.length).toBe(1);
@@ -147,14 +148,14 @@ describe("CRDT with a multi-write", function () {
147
148
  expect(got).toBeTruthy();
148
149
  expect(got.doc.points).toBe(10);
149
150
  });
150
- it("should offer changes", async function () {
151
+ it("should offer changes", async () => {
151
152
  const { result } = await crdt.changes<CRDTTestType>([]);
152
153
  expect(result.length).toBe(2);
153
154
  expect(result[0].id).toBe("ace");
154
155
  expect(result[0].value?.points).toBe(11);
155
156
  expect(result[1].id).toBe("king");
156
157
  });
157
- it("should offer changes since", async function () {
158
+ it("should offer changes since", async () => {
158
159
  /** @type {CRDTMeta} */
159
160
  const secondPut = await crdt.bulk([
160
161
  { id: "queen", value: { points: 10 } },
@@ -178,7 +179,7 @@ describe("CRDT with two multi-writes", function () {
178
179
  let firstPut: CRDTMeta;
179
180
  let secondPut: CRDTMeta;
180
181
  const sthis = ensureSuperThis();
181
- afterEach(async function () {
182
+ afterEach(async () => {
182
183
  await crdt.close();
183
184
  await crdt.destroy();
184
185
  });
@@ -201,14 +202,14 @@ describe("CRDT with two multi-writes", function () {
201
202
  { id: "jack", value: { points: 10 } },
202
203
  ]);
203
204
  });
204
- it("should have a one-element head", async function () {
205
+ it("should have a one-element head", async () => {
205
206
  const head = crdt.clock.head;
206
207
  expect(head.length).toBe(1);
207
208
  expect(firstPut.head.length).toBe(1);
208
209
  expect(secondPut.head.length).toBe(1);
209
210
  expect(firstPut.head[0]).not.toBe(secondPut.head[0]);
210
211
  });
211
- it("return the records on get", async function () {
212
+ it("return the records on get", async () => {
212
213
  const ret = await crdt.get("ace");
213
214
  expect(ret).not.toBeNull();
214
215
  const { doc } = ret as DocValue<CRDTTestType>;
@@ -219,7 +220,7 @@ describe("CRDT with two multi-writes", function () {
219
220
  expect(doc.points).toBe(10);
220
221
  }
221
222
  });
222
- it("should offer changes", async function () {
223
+ it("should offer changes", async () => {
223
224
  const { result } = await crdt.changes<CRDTTestType>();
224
225
  expect(result.length).toBe(4);
225
226
  expect(result[0].id).toBe("ace");
@@ -233,11 +234,11 @@ describe("CRDT with two multi-writes", function () {
233
234
  describe("Compact a named CRDT with writes", function () {
234
235
  let crdt: CRDT;
235
236
  const sthis = ensureSuperThis();
236
- afterEach(async function () {
237
+ afterEach(async () => {
237
238
  await crdt.close();
238
239
  await crdt.destroy();
239
240
  });
240
- beforeEach(async function () {
241
+ beforeEach(async () => {
241
242
  await sthis.start();
242
243
  const dbOpts: LedgerOpts = {
243
244
  name: "test-crdt",
@@ -255,24 +256,24 @@ describe("Compact a named CRDT with writes", function () {
255
256
  await crdt.bulk(bulk);
256
257
  }
257
258
  });
258
- it("has data", async function () {
259
+ it("has data", async () => {
259
260
  const got = (await crdt.get("ace")) as DocValue<CRDTTestType>;
260
261
  expect(got.doc).toBeTruthy();
261
262
  expect(got.doc.points).toBe(11);
262
263
  });
263
- it("should start with blocks", async function () {
264
+ it("should start with blocks", async () => {
264
265
  const blz: bs.AnyBlock[] = [];
265
266
  for await (const blk of crdt.blockstore.entries()) {
266
267
  blz.push(blk);
267
268
  }
268
269
  expect(blz.length).toBe(13);
269
270
  });
270
- it("should start with changes", async function () {
271
+ it("should start with changes", async () => {
271
272
  const { result } = await crdt.changes();
272
273
  expect(result.length).toBe(2);
273
274
  expect(result[0].id).toBe("ace");
274
275
  });
275
- it.skip("should have fewer blocks after compact", async function () {
276
+ it.skip("should have fewer blocks after compact", async () => {
276
277
  await crdt.compact();
277
278
  const blz: bs.AnyBlock[] = [];
278
279
  for await (const blk of crdt.blockstore.entries()) {
@@ -280,13 +281,13 @@ describe("Compact a named CRDT with writes", function () {
280
281
  }
281
282
  expect(blz.length).toBe(23);
282
283
  });
283
- it("should have data after compact", async function () {
284
+ it("should have data after compact", async () => {
284
285
  await crdt.compact();
285
286
  const got = (await crdt.get("ace")) as DocValue<CRDTTestType>;
286
287
  expect(got.doc).toBeTruthy();
287
288
  expect(got.doc.points).toBe(11);
288
289
  });
289
- it("should have changes after compact", async function () {
290
+ it("should have changes after compact", async () => {
290
291
  const chs = await crdt.changes();
291
292
  expect(chs.result[0].id).toBe("ace");
292
293
  });
@@ -296,11 +297,11 @@ describe("CRDT with an index", function () {
296
297
  let crdt: CRDT;
297
298
  let idx: Index<number, CRDTTestType>;
298
299
  const sthis = ensureSuperThis();
299
- afterEach(async function () {
300
+ afterEach(async () => {
300
301
  await crdt.close();
301
302
  await crdt.destroy();
302
303
  });
303
- beforeEach(async function () {
304
+ beforeEach(async () => {
304
305
  await sthis.start();
305
306
  const dbOpts: LedgerOpts = {
306
307
  name: "test-crdt",
@@ -316,13 +317,13 @@ describe("CRDT with an index", function () {
316
317
  ]);
317
318
  idx = await index<number, CRDTTestType>(crdt, "points");
318
319
  });
319
- it("should query the data", async function () {
320
+ it("should query the data", async () => {
320
321
  const got = await idx.query({ range: [9, 12] });
321
322
  expect(got.rows.length).toBe(2);
322
323
  expect(got.rows[0].id).toBe("king");
323
324
  expect(got.rows[0].key).toBe(10);
324
325
  });
325
- it("should register the index", async function () {
326
+ it("should register the index", async () => {
326
327
  const rIdx = await index<number, CRDTTestType>(crdt, "points");
327
328
  expect(rIdx).toBeTruthy();
328
329
  expect(rIdx.name).toBe("points");
@@ -331,7 +332,7 @@ describe("CRDT with an index", function () {
331
332
  expect(got.rows[0].id).toBe("king");
332
333
  expect(got.rows[0].key).toBe(10);
333
334
  });
334
- it("creating a different index with same name should not work", async function () {
335
+ it("creating a different index with same name should not work", async () => {
335
336
  const e = await index(crdt, "points", (doc) => doc._id)
336
337
  .query()
337
338
  .catch((err) => err);
@@ -346,11 +347,11 @@ describe("Loader with a committed transaction", function () {
346
347
  let done: CRDTMeta;
347
348
  const dbname = "test-loader";
348
349
  const sthis = ensureSuperThis();
349
- afterEach(async function () {
350
+ afterEach(async () => {
350
351
  await crdt.close();
351
352
  await crdt.destroy();
352
353
  });
353
- beforeEach(async function () {
354
+ beforeEach(async () => {
354
355
  await sthis.start();
355
356
  const dbOpts: LedgerOpts = {
356
357
  name: "test-crdt",
@@ -381,7 +382,7 @@ describe("Loader with a committed transaction", function () {
381
382
  it("can load the car", async () => {
382
383
  const blk = loader.carLog[0][0];
383
384
  expect(blk).toBeTruthy();
384
- const reader = await loader.loadCar(blk);
385
+ const reader = await loader.loadCar(blk, loader.attachedStores.local());
385
386
  expect(reader).toBeTruthy();
386
387
  const parsed = await bs.parseCarFile<CRDTMeta>(reader, loader.logger);
387
388
  expect(parsed.cars).toBeTruthy();
@@ -398,11 +399,11 @@ describe("Loader with two committed transactions", function () {
398
399
  let done1: CRDTMeta;
399
400
  let done2: CRDTMeta;
400
401
  const sthis = ensureSuperThis();
401
- afterEach(async function () {
402
+ afterEach(async () => {
402
403
  await crdt.close();
403
404
  await crdt.destroy();
404
405
  });
405
- beforeEach(async function () {
406
+ beforeEach(async () => {
406
407
  await sthis.start();
407
408
  const dbOpts: LedgerOpts = {
408
409
  name: "test-crdt",
@@ -432,10 +433,10 @@ describe("Loader with two committed transactions", function () {
432
433
  // expect(loader.carLog.indexOf(done2.cars)).toBe(0);
433
434
  // expect(loader.carLog.map((cs) => cs.toString()).indexOf(done2.cars.toString())).toBe(0);
434
435
  });
435
- it("can load the car", async function () {
436
+ it("can load the car", async () => {
436
437
  const blk = loader.carLog[0][0];
437
438
  expect(blk).toBeTruthy();
438
- const reader = await loader.loadCar(blk);
439
+ const reader = await loader.loadCar(blk, loader.attachedStores.local());
439
440
  expect(reader).toBeTruthy();
440
441
  const parsed = await bs.parseCarFile<CRDTMeta>(reader, loader.logger);
441
442
  expect(parsed.cars).toBeTruthy();
@@ -452,11 +453,11 @@ describe("Loader with many committed transactions", function () {
452
453
  let dones: CRDTMeta[];
453
454
  const count = 10;
454
455
  const sthis = ensureSuperThis();
455
- afterEach(async function () {
456
+ afterEach(async () => {
456
457
  await crdt.close();
457
458
  await crdt.destroy();
458
459
  });
459
- beforeEach(async function () {
460
+ beforeEach(async () => {
460
461
  await sthis.start();
461
462
  const dbOpts: LedgerOpts = {
462
463
  name: "test-crdt",
@@ -483,10 +484,10 @@ describe("Loader with many committed transactions", function () {
483
484
  expect(blockstore.transactions.size).toBe(0); // cleaned up on commit
484
485
  expect(loader.carLog.length).toBe(count);
485
486
  });
486
- it("can load the car", async function () {
487
+ it("can load the car", async () => {
487
488
  const blk = loader.carLog[2][0];
488
489
  // expect(dones[5].cars).toBeTruthy();
489
- const reader = await loader.loadCar(blk);
490
+ const reader = await loader.loadCar(blk, loader.attachedStores.local());
490
491
  expect(reader).toBeTruthy();
491
492
  const parsed = await bs.parseCarFile<CRDTMeta>(reader, loader.logger);
492
493
  expect(parsed.cars).toBeTruthy();