@fireproof/core 0.19.121 → 0.20.0-dev-preview-06

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/README.md +3 -2
  2. package/deno/index.d.ts +7 -0
  3. package/deno/index.js +66 -0
  4. package/deno/index.js.map +1 -0
  5. package/deno/metafile-esm.json +1 -0
  6. package/deno.json +2 -3
  7. package/index.cjs +1819 -1051
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +746 -333
  10. package/index.d.ts +746 -333
  11. package/index.js +1792 -1026
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/index.cjs +16 -293
  16. package/node/index.cjs.map +1 -1
  17. package/node/index.d.cts +4 -40
  18. package/node/index.d.ts +4 -40
  19. package/node/index.js +22 -237
  20. package/node/index.js.map +1 -1
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +12 -4
  24. package/react/index.cjs.map +1 -1
  25. package/react/index.js.map +1 -1
  26. package/react/metafile-cjs.json +1 -1
  27. package/react/metafile-esm.json +1 -1
  28. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  29. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  30. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  31. package/tests/blockstore/keyed-crypto.test.ts +73 -118
  32. package/tests/blockstore/loader.test.ts +18 -9
  33. package/tests/blockstore/store.test.ts +40 -31
  34. package/tests/blockstore/transaction.test.ts +14 -13
  35. package/tests/fireproof/all-gateway.test.ts +283 -213
  36. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  37. package/tests/fireproof/crdt.test.ts +78 -19
  38. package/tests/fireproof/database.test.ts +225 -29
  39. package/tests/fireproof/fireproof.test.ts +92 -73
  40. package/tests/fireproof/hello.test.ts +17 -13
  41. package/tests/fireproof/indexer.test.ts +67 -43
  42. package/tests/fireproof/utils.test.ts +47 -6
  43. package/tests/gateway/file/loader-config.test.ts +307 -0
  44. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  45. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  46. package/tests/helpers.ts +44 -17
  47. package/tests/react/useFireproof.test.tsx +1 -1
  48. package/tests/www/todo.html +24 -3
  49. package/web/index.cjs +102 -116
  50. package/web/index.cjs.map +1 -1
  51. package/web/index.d.cts +15 -29
  52. package/web/index.d.ts +15 -29
  53. package/web/index.js +91 -105
  54. package/web/index.js.map +1 -1
  55. package/web/metafile-cjs.json +1 -1
  56. package/web/metafile-esm.json +1 -1
  57. package/node/chunk-4A4RAVNS.js +0 -17
  58. package/node/chunk-4A4RAVNS.js.map +0 -1
  59. package/node/mem-filesystem-LPPT7QV5.js +0 -40
  60. package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
  61. package/tests/fireproof/config.test.ts +0 -163
  62. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
  63. /package/tests/fireproof/{multiple-ledger.test.ts → multiple-database.test.ts} +0 -0
@@ -1,8 +1,22 @@
1
- import { sleep } from "../helpers.js";
1
+ import { sleep, storageURL } from "../helpers.js";
2
2
  import { docs } from "./fireproof.test.fixture.js";
3
3
  import { CID } from "multiformats/cid";
4
4
 
5
- import { Database, DocResponse, DocWithId, Index, IndexRows, MapFn, bs, ensureSuperThis, 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
+ ensureSuperThis,
19
+ } from "@fireproof/core";
6
20
 
7
21
  export function carLogIncludesGroup(list: bs.AnyLink[], cid: CID) {
8
22
  return list.some((c) => c.equals(cid));
@@ -84,7 +98,7 @@ describe("public API", function () {
84
98
  });
85
99
  it("should be a database instance", function () {
86
100
  expect(db).toBeTruthy();
87
- expect(db instanceof Database).toBeTruthy();
101
+ expect(isDatabase(db)).toBeTruthy();
88
102
  });
89
103
  it("should put", function () {
90
104
  expect(ok).toBeTruthy();
@@ -113,7 +127,7 @@ describe("basic database", function () {
113
127
  });
114
128
  beforeEach(async function () {
115
129
  await sthis.start();
116
- db = new Database("test-basic");
130
+ db = DatabaseFactory("test-basic");
117
131
  });
118
132
  it("can put with id", async function () {
119
133
  const ok = await db.put({ _id: "test", foo: "bar" });
@@ -126,10 +140,19 @@ describe("basic database", function () {
126
140
  const got = await db.get<Doc>(ok.id);
127
141
  expect(got.foo).toBe("bam");
128
142
  });
143
+ it("can bulk an array", async function () {
144
+ const ok = await db.bulk([{ foo: "cool" }, { foo: "dude" }]);
145
+ expect(ok).toBeTruthy();
146
+ expect(ok.ids.length).toBe(2);
147
+ const got = await db.get<Doc>(ok.ids[0]);
148
+ expect(got.foo).toBe("cool");
149
+ const got2 = await db.get<Doc>(ok.ids[1]);
150
+ expect(got2.foo).toBe("dude");
151
+ });
129
152
  it("can define an index", async function () {
130
153
  const ok = await db.put({ _id: "test", foo: "bar" });
131
154
  expect(ok).toBeTruthy();
132
- const idx = index<string, { foo: string }>(sthis, db, "test-index", (doc) => doc.foo);
155
+ const idx = index<string, { foo: string }>(db, "test-index", (doc) => doc.foo);
133
156
  const result = await idx.query();
134
157
  expect(result).toBeTruthy();
135
158
  expect(result.rows).toBeTruthy();
@@ -139,7 +162,7 @@ describe("basic database", function () {
139
162
  it("can define an index with a default function", async function () {
140
163
  const ok = await db.put({ _id: "test", foo: "bar" });
141
164
  expect(ok).toBeTruthy();
142
- const idx = index(sthis, db, "foo");
165
+ const idx = index(db, "foo");
143
166
  const result = await idx.query();
144
167
  expect(result).toBeTruthy();
145
168
  expect(result.rows).toBeTruthy();
@@ -178,14 +201,14 @@ describe("benchmarking with compaction", function () {
178
201
  beforeEach(async function () {
179
202
  // erase the existing test data
180
203
  await sthis.start();
181
- db = new Database("test-benchmark-compaction", { autoCompact: 3 });
204
+ db = DatabaseFactory("test-benchmark-compaction", { autoCompact: 3 });
182
205
  });
183
- it("insert during compaction", async function () {
206
+ it.skip("insert during compaction", async function () {
184
207
  const ok = await db.put({ _id: "test", foo: "fast" });
185
208
  expect(ok).toBeTruthy();
186
209
  expect(ok.id).toBe("test");
187
- expect(db._crdt.clock.head).toBeTruthy();
188
- expect(db._crdt.clock.head.length).toBe(1);
210
+ expect(db.crdt.clock.head).toBeTruthy();
211
+ expect(db.crdt.clock.head.length).toBe(1);
189
212
 
190
213
  const numDocs = 20;
191
214
  const batchSize = 5;
@@ -206,7 +229,7 @@ describe("benchmarking with compaction", function () {
206
229
  }),
207
230
  );
208
231
  }
209
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
232
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
210
233
  const loader = blocks.loader;
211
234
  expect(loader).toBeTruthy();
212
235
 
@@ -233,8 +256,8 @@ describe("benchmarking a database", function () {
233
256
  beforeEach(async function () {
234
257
  await sthis.start();
235
258
  // erase the existing test data
236
- db = new Database("test-benchmark", { autoCompact: 100000, public: true });
237
- // db = new Database(null, {autoCompact: 100000})
259
+ db = DatabaseFactory("test-benchmark", { autoCompact: 100000, public: true });
260
+ // db = DatabaseFactory(null, {autoCompact: 100000})
238
261
  });
239
262
 
240
263
  // run benchmarking tests
@@ -247,8 +270,8 @@ describe("benchmarking a database", function () {
247
270
  expect(ok).toBeTruthy();
248
271
  expect(ok.id).toBe("test");
249
272
 
250
- expect(db._crdt.clock.head).toBeTruthy();
251
- expect(db._crdt.clock.head.length).toBe(1);
273
+ expect(db.crdt.clock.head).toBeTruthy();
274
+ expect(db.crdt.clock.head.length).toBe(1);
252
275
 
253
276
  const numDocs = 2500;
254
277
  const batchSize = 500;
@@ -284,7 +307,7 @@ describe("benchmarking a database", function () {
284
307
  // equals(allDocsResult2.rows.length, numDocs+1)
285
308
 
286
309
  // console.time("open new DB");
287
- const newDb = new Database("test-benchmark", { autoCompact: 100000, public: true });
310
+ const newDb = DatabaseFactory("test-benchmark", { autoCompact: 100000, public: true });
288
311
  const doc = await newDb.get<{ foo: string }>("test");
289
312
  expect(doc.foo).toBe("fast");
290
313
  // console.timeEnd("open new DB");
@@ -314,7 +337,7 @@ describe("benchmarking a database", function () {
314
337
  await db.put({ _id: "compacted-test", foo: "bar" });
315
338
 
316
339
  // console.log('car log length', db._crdt.blockstore.loader.carLog.length)
317
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
340
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
318
341
  const loader = blocks.loader;
319
342
  expect(loader).toBeTruthy();
320
343
  expect(loader.carLog.length).toBe(2);
@@ -326,10 +349,10 @@ describe("benchmarking a database", function () {
326
349
  await sleep(100);
327
350
 
328
351
  // console.time("compacted reopen again");
329
- const newDb2 = new Database("test-benchmark", { autoCompact: 100000, public: true });
352
+ const newDb2 = DatabaseFactory("test-benchmark", { autoCompact: 100000, public: true });
330
353
  const doc21 = await newDb2.get<FooType>("test");
331
354
  expect(doc21.foo).toBe("fast");
332
- const blocks2 = newDb2._crdt.blockstore as bs.EncryptedBlockstore;
355
+ const blocks2 = newDb2.crdt.blockstore as bs.EncryptedBlockstore;
333
356
  const loader2 = blocks2.loader;
334
357
  expect(loader2).toBeTruthy();
335
358
 
@@ -392,13 +415,13 @@ describe("Reopening a database", function () {
392
415
  // erase the existing test data
393
416
  await sthis.start();
394
417
 
395
- db = new Database("test-reopen", { autoCompact: 100000 });
418
+ db = DatabaseFactory("test-reopen", { autoCompact: 100000 });
396
419
  const ok = await db.put({ _id: "test", foo: "bar" });
397
420
  expect(ok).toBeTruthy();
398
421
  expect(ok.id).toBe("test");
399
422
 
400
- expect(db._crdt.clock.head).toBeDefined();
401
- expect(db._crdt.clock.head.length).toBe(1);
423
+ expect(db.crdt.clock.head).toBeDefined();
424
+ expect(db.crdt.clock.head.length).toBe(1);
402
425
  });
403
426
 
404
427
  it("should persist data", async function () {
@@ -407,18 +430,18 @@ describe("Reopening a database", function () {
407
430
  });
408
431
 
409
432
  it("should have the same data on reopen", async function () {
410
- const db2 = new Database("test-reopen");
433
+ const db2 = DatabaseFactory("test-reopen");
411
434
  const doc = await db2.get<FooType>("test");
412
435
  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);
436
+ expect(db2.crdt.clock.head).toBeDefined();
437
+ expect(db2.crdt.clock.head.length).toBe(1);
438
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
416
439
  await db2.close();
417
440
  });
418
441
 
419
442
  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;
443
+ await db.crdt.ready();
444
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
422
445
  const loader = blocks.loader;
423
446
  expect(loader).toBeDefined();
424
447
  expect(loader.carLog).toBeDefined();
@@ -426,9 +449,9 @@ describe("Reopening a database", function () {
426
449
  });
427
450
 
428
451
  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;
452
+ const db2 = DatabaseFactory("test-reopen");
453
+ await db2.crdt.ready();
454
+ const blocks = db2.crdt.blockstore as bs.EncryptedBlockstore;
432
455
  const loader = blocks.loader;
433
456
  expect(loader).toBeDefined();
434
457
  expect(loader.carLog).toBeDefined();
@@ -439,10 +462,10 @@ describe("Reopening a database", function () {
439
462
  it("faster, should have the same data on reopen after reopen and update", async function () {
440
463
  for (let i = 0; i < 4; i++) {
441
464
  // console.log('iteration', i)
442
- const db = new Database("test-reopen");
465
+ const db = DatabaseFactory("test-reopen");
443
466
  // assert(db._crdt.xready());
444
- await db._crdt.ready();
445
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
467
+ await db.crdt.ready();
468
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
446
469
  const loader = blocks.loader;
447
470
  expect(loader.carLog.length).toBe(i + 1);
448
471
  const ok = await db.put({ _id: `test${i}`, fire: "proof".repeat(50 * 1024) });
@@ -458,11 +481,11 @@ describe("Reopening a database", function () {
458
481
  for (let i = 0; i < 200; i++) {
459
482
  // console.log("iteration", i);
460
483
  // console.time("db open");
461
- const db = new Database("test-reopen", { autoCompact: 1000 }); // try with 10
484
+ const db = DatabaseFactory("test-reopen", { autoCompact: 1000 }); // try with 10
462
485
  // assert(db._crdt.ready);
463
- await db._crdt.ready();
486
+ await db.crdt.ready();
464
487
  // console.timeEnd("db open");
465
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
488
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
466
489
  const loader = blocks.loader;
467
490
  expect(loader).toBeDefined();
468
491
  expect(loader.carLog.length).toBe(i + 1);
@@ -505,13 +528,13 @@ describe("Reopening a database with indexes", function () {
505
528
  didMap = true;
506
529
  return doc.foo;
507
530
  };
508
- idx = index<string, Doc>(sthis, db, "foo", mapFn);
531
+ idx = index<string, Doc>(db, "foo", mapFn);
509
532
  });
510
533
 
511
534
  it("should persist data", async function () {
512
535
  const doc = await db.get<Doc>("test");
513
536
  expect(doc.foo).toBe("bar");
514
- const idx2 = index<string, Doc>(sthis, db, "foo");
537
+ const idx2 = index<string, Doc>(db, "foo");
515
538
  expect(idx2).toBe(idx);
516
539
  const result = await idx2.query();
517
540
  expect(result).toBeTruthy();
@@ -522,7 +545,7 @@ describe("Reopening a database with indexes", function () {
522
545
  });
523
546
 
524
547
  it("should reuse the index", async function () {
525
- const idx2 = index(sthis, db, "foo", mapFn);
548
+ const idx2 = index(db, "foo", mapFn);
526
549
  expect(idx2).toBe(idx);
527
550
  const result = await idx2.query();
528
551
  expect(result).toBeTruthy();
@@ -543,9 +566,9 @@ describe("Reopening a database with indexes", function () {
543
566
  const db2 = fireproof("test-reopen-idx");
544
567
  const doc = await db2.get<FooType>("test");
545
568
  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);
569
+ expect(db2.crdt.clock.head).toBeTruthy();
570
+ expect(db2.crdt.clock.head.length).toBe(1);
571
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
549
572
  });
550
573
 
551
574
  it("should have the same data on reopen after a query", async function () {
@@ -558,9 +581,9 @@ describe("Reopening a database with indexes", function () {
558
581
  const db2 = fireproof("test-reopen-idx");
559
582
  const doc = await db2.get<FooType>("test");
560
583
  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);
584
+ expect(db2.crdt.clock.head).toBeTruthy();
585
+ expect(db2.crdt.clock.head.length).toBe(1);
586
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
564
587
  });
565
588
 
566
589
  // it('should query the same data on reopen', async function () {
@@ -595,11 +618,11 @@ describe("basic js verify", function () {
595
618
  expect(ok.id).toBe("test");
596
619
  const ok2 = await db.put({ _id: "test2", foo: ["bar", "bam"] });
597
620
  expect(ok2.id).toBe("test2");
598
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
621
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
599
622
  const loader = blocks.loader;
600
623
  expect(loader).toBeTruthy();
601
624
  const cid = loader.carLog[0][0];
602
- const cid2 = db._crdt.clock.head[0];
625
+ const cid2 = db.crdt.clock.head[0];
603
626
  expect(cid).not.toBe(cid2);
604
627
  expect(cid).not.toBe(cid2);
605
628
  const cidList = [cid, cid2];
@@ -621,21 +644,17 @@ describe("same workload twice, same CID", function () {
621
644
  // let configA: any;
622
645
  // let configB: any;
623
646
 
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
- // };
647
+ const configA: ConfigOpts = {
648
+ storeUrls: {
649
+ base: storageURL(sthis).build().setParam("storekey", "@test@"),
650
+ },
651
+ };
652
+
653
+ const configB: ConfigOpts = {
654
+ storeUrls: {
655
+ base: storageURL(sthis).build().setParam("storekey", "@test@"),
656
+ },
657
+ };
639
658
 
640
659
  afterEach(async function () {
641
660
  await dbA.close();
@@ -647,22 +666,22 @@ describe("same workload twice, same CID", function () {
647
666
  let ok: DocResponse;
648
667
  await sthis.start();
649
668
  // 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");
669
+ dbA = fireproof("test-dual-workload-a", configA);
651
670
  for (const doc of docs) {
652
671
  ok = await dbA.put(doc);
653
672
  expect(ok).toBeTruthy();
654
673
  expect(ok.id).toBeTruthy();
655
674
  }
656
- headA = dbA._crdt.clock.head.toString();
675
+ headA = dbA.crdt.clock.head.toString();
657
676
 
658
677
  // 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");
678
+ dbB = fireproof("test-dual-workload-b", configB);
660
679
  for (const doc of docs) {
661
680
  ok = await dbB.put(doc);
662
681
  expect(ok).toBeTruthy();
663
682
  expect(ok.id).toBeTruthy();
664
683
  }
665
- headB = dbB._crdt.clock.head.toString();
684
+ headB = dbB.crdt.clock.head.toString();
666
685
  });
667
686
  it("should have head A and B", async function () {
668
687
  expect(headA).toBeTruthy();
@@ -671,15 +690,15 @@ describe("same workload twice, same CID", function () {
671
690
  expect(headA.length).toBeGreaterThan(10);
672
691
  });
673
692
  it("should have same car log", async function () {
674
- const logA = dbA._crdt.blockstore.loader?.carLog;
693
+ const logA = dbA.crdt.blockstore.loader?.carLog;
675
694
  expect(logA).toBeTruthy();
676
695
  assert(logA);
677
- expect(logA.length).toBe(38);
696
+ expect(logA.length).toBe(docs.length);
678
697
 
679
- const logB = dbB._crdt.blockstore.loader?.carLog;
698
+ const logB = dbB.crdt.blockstore.loader?.carLog;
680
699
  expect(logB).toBeTruthy();
681
700
  assert(logB);
682
- expect(logB.length).toBe(38);
701
+ expect(logB.length).toBe(docs.length);
683
702
 
684
703
  const logA2 = logA.map((c) => c.toString());
685
704
  const logB2 = logB.map((c) => c.toString());
@@ -693,12 +712,12 @@ describe("same workload twice, same CID", function () {
693
712
  await dbA.compact();
694
713
  await dbB.compact();
695
714
 
696
- const cmpLogA = dbA._crdt.blockstore.loader?.carLog;
715
+ const cmpLogA = dbA.crdt.blockstore.loader?.carLog;
697
716
  expect(cmpLogA).toBeTruthy();
698
717
  assert(cmpLogA);
699
718
  expect(cmpLogA.length).toBe(1);
700
719
 
701
- const cmpLogB = dbB._crdt.blockstore.loader?.carLog;
720
+ const cmpLogB = dbB.crdt.blockstore.loader?.carLog;
702
721
  expect(cmpLogB).toBeTruthy();
703
722
  assert(cmpLogB);
704
723
  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.js";
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
+ const result = fireproof("hello"); // call to your library function
6
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();