@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,8 +1,21 @@
1
- import { mockSuperThis, sleep } from "../helpers.js";
2
- import { docs } from "./fireproof.test.fixture.js";
1
+ import { mockSuperThis, sleep, storageURL } from "../helpers.js";
2
+ import { docs } from "./fireproof.fixture.js";
3
3
  import { CID } from "multiformats/cid";
4
4
 
5
- import { Database, DocResponse, DocWithId, Index, IndexRows, MapFn, bs, fireproof, index } from "@fireproof/core";
5
+ import {
6
+ ConfigOpts,
7
+ Database,
8
+ DatabaseFactory,
9
+ DocResponse,
10
+ DocWithId,
11
+ Index,
12
+ IndexRows,
13
+ MapFn,
14
+ bs,
15
+ fireproof,
16
+ index,
17
+ isDatabase,
18
+ } from "@fireproof/core";
6
19
 
7
20
  export function carLogIncludesGroup(list: bs.AnyLink[], cid: CID) {
8
21
  return list.some((c) => c.equals(cid));
@@ -84,7 +97,7 @@ describe("public API", function () {
84
97
  });
85
98
  it("should be a database instance", function () {
86
99
  expect(db).toBeTruthy();
87
- expect(db instanceof Database).toBeTruthy();
100
+ expect(isDatabase(db)).toBeTruthy();
88
101
  });
89
102
  it("should put", function () {
90
103
  expect(ok).toBeTruthy();
@@ -113,7 +126,7 @@ describe("basic database", function () {
113
126
  });
114
127
  beforeEach(async function () {
115
128
  await sthis.start();
116
- db = new Database("test-basic");
129
+ db = DatabaseFactory("test-basic");
117
130
  });
118
131
  it("can put with id", async function () {
119
132
  const ok = await db.put({ _id: "test", foo: "bar" });
@@ -129,7 +142,7 @@ describe("basic database", function () {
129
142
  it("can define an index", async function () {
130
143
  const ok = await db.put({ _id: "test", foo: "bar" });
131
144
  expect(ok).toBeTruthy();
132
- const idx = index<string, { foo: string }>(sthis, db, "test-index", (doc) => doc.foo);
145
+ const idx = index<string, { foo: string }>(db, "test-index", (doc) => doc.foo);
133
146
  const result = await idx.query();
134
147
  expect(result).toBeTruthy();
135
148
  expect(result.rows).toBeTruthy();
@@ -139,7 +152,7 @@ describe("basic database", function () {
139
152
  it("can define an index with a default function", async function () {
140
153
  const ok = await db.put({ _id: "test", foo: "bar" });
141
154
  expect(ok).toBeTruthy();
142
- const idx = index(sthis, db, "foo");
155
+ const idx = index(db, "foo");
143
156
  const result = await idx.query();
144
157
  expect(result).toBeTruthy();
145
158
  expect(result.rows).toBeTruthy();
@@ -178,14 +191,14 @@ describe("benchmarking with compaction", function () {
178
191
  beforeEach(async function () {
179
192
  // erase the existing test data
180
193
  await sthis.start();
181
- db = new Database("test-benchmark-compaction", { autoCompact: 3 });
194
+ db = DatabaseFactory("test-benchmark-compaction", { autoCompact: 3 });
182
195
  });
183
- it("insert during compaction", async function () {
196
+ it.skip("insert during compaction", async function () {
184
197
  const ok = await db.put({ _id: "test", foo: "fast" });
185
198
  expect(ok).toBeTruthy();
186
199
  expect(ok.id).toBe("test");
187
- expect(db._crdt.clock.head).toBeTruthy();
188
- expect(db._crdt.clock.head.length).toBe(1);
200
+ expect(db.crdt.clock.head).toBeTruthy();
201
+ expect(db.crdt.clock.head.length).toBe(1);
189
202
 
190
203
  const numDocs = 20;
191
204
  const batchSize = 5;
@@ -206,7 +219,7 @@ describe("benchmarking with compaction", function () {
206
219
  }),
207
220
  );
208
221
  }
209
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
222
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
210
223
  const loader = blocks.loader;
211
224
  expect(loader).toBeTruthy();
212
225
 
@@ -233,8 +246,8 @@ describe("benchmarking a database", function () {
233
246
  beforeEach(async function () {
234
247
  await sthis.start();
235
248
  // erase the existing test data
236
- db = new Database("test-benchmark", { autoCompact: 100000, public: true });
237
- // db = new Database(null, {autoCompact: 100000})
249
+ db = DatabaseFactory("test-benchmark", { autoCompact: 100000, public: true });
250
+ // db = DatabaseFactory(null, {autoCompact: 100000})
238
251
  });
239
252
 
240
253
  // run benchmarking tests
@@ -247,8 +260,8 @@ describe("benchmarking a database", function () {
247
260
  expect(ok).toBeTruthy();
248
261
  expect(ok.id).toBe("test");
249
262
 
250
- expect(db._crdt.clock.head).toBeTruthy();
251
- expect(db._crdt.clock.head.length).toBe(1);
263
+ expect(db.crdt.clock.head).toBeTruthy();
264
+ expect(db.crdt.clock.head.length).toBe(1);
252
265
 
253
266
  const numDocs = 2500;
254
267
  const batchSize = 500;
@@ -284,7 +297,7 @@ describe("benchmarking a database", function () {
284
297
  // equals(allDocsResult2.rows.length, numDocs+1)
285
298
 
286
299
  // console.time("open new DB");
287
- const newDb = new Database("test-benchmark", { autoCompact: 100000, public: true });
300
+ const newDb = DatabaseFactory("test-benchmark", { autoCompact: 100000, public: true });
288
301
  const doc = await newDb.get<{ foo: string }>("test");
289
302
  expect(doc.foo).toBe("fast");
290
303
  // console.timeEnd("open new DB");
@@ -314,7 +327,7 @@ describe("benchmarking a database", function () {
314
327
  await db.put({ _id: "compacted-test", foo: "bar" });
315
328
 
316
329
  // console.log('car log length', db._crdt.blockstore.loader.carLog.length)
317
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
330
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
318
331
  const loader = blocks.loader;
319
332
  expect(loader).toBeTruthy();
320
333
  expect(loader.carLog.length).toBe(2);
@@ -326,10 +339,10 @@ describe("benchmarking a database", function () {
326
339
  await sleep(100);
327
340
 
328
341
  // console.time("compacted reopen again");
329
- const newDb2 = new Database("test-benchmark", { autoCompact: 100000, public: true });
342
+ const newDb2 = DatabaseFactory("test-benchmark", { autoCompact: 100000, public: true });
330
343
  const doc21 = await newDb2.get<FooType>("test");
331
344
  expect(doc21.foo).toBe("fast");
332
- const blocks2 = newDb2._crdt.blockstore as bs.EncryptedBlockstore;
345
+ const blocks2 = newDb2.crdt.blockstore as bs.EncryptedBlockstore;
333
346
  const loader2 = blocks2.loader;
334
347
  expect(loader2).toBeTruthy();
335
348
 
@@ -392,13 +405,13 @@ describe("Reopening a database", function () {
392
405
  // erase the existing test data
393
406
  await sthis.start();
394
407
 
395
- db = new Database("test-reopen", { autoCompact: 100000 });
408
+ db = DatabaseFactory("test-reopen", { autoCompact: 100000 });
396
409
  const ok = await db.put({ _id: "test", foo: "bar" });
397
410
  expect(ok).toBeTruthy();
398
411
  expect(ok.id).toBe("test");
399
412
 
400
- expect(db._crdt.clock.head).toBeDefined();
401
- expect(db._crdt.clock.head.length).toBe(1);
413
+ expect(db.crdt.clock.head).toBeDefined();
414
+ expect(db.crdt.clock.head.length).toBe(1);
402
415
  });
403
416
 
404
417
  it("should persist data", async function () {
@@ -407,18 +420,18 @@ describe("Reopening a database", function () {
407
420
  });
408
421
 
409
422
  it("should have the same data on reopen", async function () {
410
- const db2 = new Database("test-reopen");
423
+ const db2 = DatabaseFactory("test-reopen");
411
424
  const doc = await db2.get<FooType>("test");
412
425
  expect(doc.foo).toBe("bar");
413
- expect(db2._crdt.clock.head).toBeDefined();
414
- expect(db2._crdt.clock.head.length).toBe(1);
415
- expect(db2._crdt.clock.head).toEqual(db._crdt.clock.head);
426
+ expect(db2.crdt.clock.head).toBeDefined();
427
+ expect(db2.crdt.clock.head.length).toBe(1);
428
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
416
429
  await db2.close();
417
430
  });
418
431
 
419
432
  it("should have a car in the car log", async function () {
420
- await db._crdt.ready();
421
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
433
+ await db.crdt.ready();
434
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
422
435
  const loader = blocks.loader;
423
436
  expect(loader).toBeDefined();
424
437
  expect(loader.carLog).toBeDefined();
@@ -426,9 +439,9 @@ describe("Reopening a database", function () {
426
439
  });
427
440
 
428
441
  it("should have carlog after reopen", async function () {
429
- const db2 = new Database("test-reopen");
430
- await db2._crdt.ready();
431
- const blocks = db2._crdt.blockstore as bs.EncryptedBlockstore;
442
+ const db2 = DatabaseFactory("test-reopen");
443
+ await db2.crdt.ready();
444
+ const blocks = db2.crdt.blockstore as bs.EncryptedBlockstore;
432
445
  const loader = blocks.loader;
433
446
  expect(loader).toBeDefined();
434
447
  expect(loader.carLog).toBeDefined();
@@ -439,10 +452,10 @@ describe("Reopening a database", function () {
439
452
  it("faster, should have the same data on reopen after reopen and update", async function () {
440
453
  for (let i = 0; i < 4; i++) {
441
454
  // console.log('iteration', i)
442
- const db = new Database("test-reopen");
455
+ const db = DatabaseFactory("test-reopen");
443
456
  // assert(db._crdt.xready());
444
- await db._crdt.ready();
445
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
457
+ await db.crdt.ready();
458
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
446
459
  const loader = blocks.loader;
447
460
  expect(loader.carLog.length).toBe(i + 1);
448
461
  const ok = await db.put({ _id: `test${i}`, fire: "proof".repeat(50 * 1024) });
@@ -458,11 +471,11 @@ describe("Reopening a database", function () {
458
471
  for (let i = 0; i < 200; i++) {
459
472
  // console.log("iteration", i);
460
473
  // console.time("db open");
461
- const db = new Database("test-reopen", { autoCompact: 1000 }); // try with 10
474
+ const db = DatabaseFactory("test-reopen", { autoCompact: 1000 }); // try with 10
462
475
  // assert(db._crdt.ready);
463
- await db._crdt.ready();
476
+ await db.crdt.ready();
464
477
  // console.timeEnd("db open");
465
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
478
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
466
479
  const loader = blocks.loader;
467
480
  expect(loader).toBeDefined();
468
481
  expect(loader.carLog.length).toBe(i + 1);
@@ -505,13 +518,13 @@ describe("Reopening a database with indexes", function () {
505
518
  didMap = true;
506
519
  return doc.foo;
507
520
  };
508
- idx = index<string, Doc>(sthis, db, "foo", mapFn);
521
+ idx = index<string, Doc>(db, "foo", mapFn);
509
522
  });
510
523
 
511
524
  it("should persist data", async function () {
512
525
  const doc = await db.get<Doc>("test");
513
526
  expect(doc.foo).toBe("bar");
514
- const idx2 = index<string, Doc>(sthis, db, "foo");
527
+ const idx2 = index<string, Doc>(db, "foo");
515
528
  expect(idx2).toBe(idx);
516
529
  const result = await idx2.query();
517
530
  expect(result).toBeTruthy();
@@ -522,7 +535,7 @@ describe("Reopening a database with indexes", function () {
522
535
  });
523
536
 
524
537
  it("should reuse the index", async function () {
525
- const idx2 = index(sthis, db, "foo", mapFn);
538
+ const idx2 = index(db, "foo", mapFn);
526
539
  expect(idx2).toBe(idx);
527
540
  const result = await idx2.query();
528
541
  expect(result).toBeTruthy();
@@ -543,9 +556,9 @@ describe("Reopening a database with indexes", function () {
543
556
  const db2 = fireproof("test-reopen-idx");
544
557
  const doc = await db2.get<FooType>("test");
545
558
  expect(doc.foo).toBe("bar");
546
- expect(db2._crdt.clock.head).toBeTruthy();
547
- expect(db2._crdt.clock.head.length).toBe(1);
548
- expect(db2._crdt.clock.head).toEqual(db._crdt.clock.head);
559
+ expect(db2.crdt.clock.head).toBeTruthy();
560
+ expect(db2.crdt.clock.head.length).toBe(1);
561
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
549
562
  });
550
563
 
551
564
  it("should have the same data on reopen after a query", async function () {
@@ -558,9 +571,9 @@ describe("Reopening a database with indexes", function () {
558
571
  const db2 = fireproof("test-reopen-idx");
559
572
  const doc = await db2.get<FooType>("test");
560
573
  expect(doc.foo).toBe("bar");
561
- expect(db2._crdt.clock.head).toBeTruthy();
562
- expect(db2._crdt.clock.head.length).toBe(1);
563
- expect(db2._crdt.clock.head).toEqual(db._crdt.clock.head);
574
+ expect(db2.crdt.clock.head).toBeTruthy();
575
+ expect(db2.crdt.clock.head.length).toBe(1);
576
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
564
577
  });
565
578
 
566
579
  // it('should query the same data on reopen', async function () {
@@ -595,11 +608,11 @@ describe("basic js verify", function () {
595
608
  expect(ok.id).toBe("test");
596
609
  const ok2 = await db.put({ _id: "test2", foo: ["bar", "bam"] });
597
610
  expect(ok2.id).toBe("test2");
598
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
611
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
599
612
  const loader = blocks.loader;
600
613
  expect(loader).toBeTruthy();
601
614
  const cid = loader.carLog[0][0];
602
- const cid2 = db._crdt.clock.head[0];
615
+ const cid2 = db.crdt.clock.head[0];
603
616
  expect(cid).not.toBe(cid2);
604
617
  expect(cid).not.toBe(cid2);
605
618
  const cidList = [cid, cid2];
@@ -621,21 +634,17 @@ describe("same workload twice, same CID", function () {
621
634
  // let configA: any;
622
635
  // let configB: any;
623
636
 
624
- // const configA = {
625
- // store: {
626
- // stores: {
627
- // base: storageURL(sthis).build().setParam("storekey", "@test@"),
628
- // },
629
- // },
630
- // };
631
-
632
- // const configB = {
633
- // store: {
634
- // stores: {
635
- // base: storageURL(sthis).build().setParam("storekey", "@test@"),
636
- // },
637
- // },
638
- // };
637
+ const configA: ConfigOpts = {
638
+ storeUrls: {
639
+ base: storageURL(sthis).build().setParam("storekey", "@test@"),
640
+ },
641
+ };
642
+
643
+ const configB: ConfigOpts = {
644
+ storeUrls: {
645
+ base: storageURL(sthis).build().setParam("storekey", "@test@"),
646
+ },
647
+ };
639
648
 
640
649
  afterEach(async function () {
641
650
  await dbA.close();
@@ -647,22 +656,22 @@ describe("same workload twice, same CID", function () {
647
656
  let ok: DocResponse;
648
657
  await sthis.start();
649
658
  // todo this fails because the test setup doesn't properly configure both databases to use the same key
650
- dbA = fireproof("test-dual-workload-a");
659
+ dbA = fireproof("test-dual-workload-a", configA);
651
660
  for (const doc of docs) {
652
661
  ok = await dbA.put(doc);
653
662
  expect(ok).toBeTruthy();
654
663
  expect(ok.id).toBeTruthy();
655
664
  }
656
- headA = dbA._crdt.clock.head.toString();
665
+ headA = dbA.crdt.clock.head.toString();
657
666
 
658
667
  // todo this fails because the test setup doesn't properly configure both databases to use the same key
659
- dbB = fireproof("test-dual-workload-b");
668
+ dbB = fireproof("test-dual-workload-b", configB);
660
669
  for (const doc of docs) {
661
670
  ok = await dbB.put(doc);
662
671
  expect(ok).toBeTruthy();
663
672
  expect(ok.id).toBeTruthy();
664
673
  }
665
- headB = dbB._crdt.clock.head.toString();
674
+ headB = dbB.crdt.clock.head.toString();
666
675
  });
667
676
  it("should have head A and B", async function () {
668
677
  expect(headA).toBeTruthy();
@@ -671,15 +680,15 @@ describe("same workload twice, same CID", function () {
671
680
  expect(headA.length).toBeGreaterThan(10);
672
681
  });
673
682
  it("should have same car log", async function () {
674
- const logA = dbA._crdt.blockstore.loader?.carLog;
683
+ const logA = dbA.crdt.blockstore.loader?.carLog;
675
684
  expect(logA).toBeTruthy();
676
685
  assert(logA);
677
- expect(logA.length).toBe(38);
686
+ expect(logA.length).toBe(docs.length);
678
687
 
679
- const logB = dbB._crdt.blockstore.loader?.carLog;
688
+ const logB = dbB.crdt.blockstore.loader?.carLog;
680
689
  expect(logB).toBeTruthy();
681
690
  assert(logB);
682
- expect(logB.length).toBe(38);
691
+ expect(logB.length).toBe(docs.length);
683
692
 
684
693
  const logA2 = logA.map((c) => c.toString());
685
694
  const logB2 = logB.map((c) => c.toString());
@@ -693,12 +702,12 @@ describe("same workload twice, same CID", function () {
693
702
  await dbA.compact();
694
703
  await dbB.compact();
695
704
 
696
- const cmpLogA = dbA._crdt.blockstore.loader?.carLog;
705
+ const cmpLogA = dbA.crdt.blockstore.loader?.carLog;
697
706
  expect(cmpLogA).toBeTruthy();
698
707
  assert(cmpLogA);
699
708
  expect(cmpLogA.length).toBe(1);
700
709
 
701
- const cmpLogB = dbB._crdt.blockstore.loader?.carLog;
710
+ const cmpLogB = dbB.crdt.blockstore.loader?.carLog;
702
711
  expect(cmpLogB).toBeTruthy();
703
712
  assert(cmpLogB);
704
713
  expect(cmpLogB.length).toBe(1);
@@ -1,31 +1,36 @@
1
- import { fireproof as database, Database, DocResponse, DocWithId } from "@fireproof/core";
1
+ import { fireproof, Database, DocResponse, DocWithId, index, isDatabase } from "@fireproof/core";
2
+ import { mockSuperThis } from "../helpers";
2
3
 
3
4
  describe("Hello World Test", function () {
4
5
  it("should pass the hello world test", function () {
5
- const result = database("hello"); // call to your library function
6
- expect(result.name).toBe("hello");
6
+ const result = fireproof("hello"); // call to your library function
7
+ expect(result.name()).toBe("hello");
7
8
  });
8
9
  });
9
10
 
10
- describe("hello public API", function () {
11
+ describe("hello public API", () => {
11
12
  interface TestDoc {
12
13
  foo: string;
13
14
  }
14
15
  let db: Database;
15
16
  let ok: DocResponse;
16
17
  let doc: DocWithId<TestDoc>;
17
- afterEach(async function () {
18
+ // let idx: Index<string, TestDoc>;
19
+ const sthis = mockSuperThis();
20
+ afterEach(async () => {
18
21
  await db.close();
19
22
  await db.destroy();
20
23
  });
21
- beforeEach(async function () {
22
- db = database("test-public-api");
24
+ beforeEach(async () => {
25
+ await sthis.start();
26
+ db = fireproof("test-public-api");
27
+ index<string, TestDoc>(db, "test-index", (doc) => doc.foo);
23
28
  ok = await db.put({ _id: "test", foo: "bar" });
24
29
  doc = await db.get("test");
25
30
  });
26
31
  it("should have a database", function () {
27
32
  expect(db).toBeTruthy();
28
- expect(db instanceof Database).toBeTruthy();
33
+ expect(isDatabase(db)).toBeTruthy();
29
34
  });
30
35
  it("should put", function () {
31
36
  expect(ok).toBeTruthy();
@@ -34,11 +39,10 @@ describe("hello public API", function () {
34
39
  it("should get", function () {
35
40
  expect(doc.foo).toBe("bar");
36
41
  });
37
- it("should get when you open it again", async function () {
42
+ it("should get when you open it again", async () => {
38
43
  await db.close();
39
- await db.destroy();
40
- const db2 = database("test-public-api");
41
- doc = await db2.get("test");
44
+ db = fireproof("test-public-api");
45
+ doc = await db.get("test");
42
46
  expect(doc.foo).toBe("bar");
43
47
  });
44
48
  });
@@ -50,7 +54,7 @@ describe("Simplified Reopening a database", function () {
50
54
  await db.destroy();
51
55
  });
52
56
  beforeEach(async function () {
53
- db = new Database("test-reopen-simple");
57
+ db = fireproof("test-reopen-simple");
54
58
  const ok = await db.put({ _id: "test", foo: "bar" });
55
59
  expect(ok).toBeTruthy();
56
60
  expect(ok.id).toBe("test");
@@ -62,7 +66,7 @@ describe("Simplified Reopening a database", function () {
62
66
  });
63
67
 
64
68
  it("should have the same data on reopen", async function () {
65
- const db2 = new Database("test-reopen-simple");
69
+ const db2 = fireproof("test-reopen-simple");
66
70
  const doc = await db2.get<{ foo: string }>("test");
67
71
  expect(doc.foo).toBe("bar");
68
72
  await db2.close();