@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.
- package/README.md +3 -2
- package/deno/index.d.ts +7 -0
- package/deno/index.js +66 -0
- package/deno/index.js.map +1 -0
- package/deno/metafile-esm.json +1 -0
- package/deno.json +2 -3
- package/index.cjs +1819 -1051
- package/index.cjs.map +1 -1
- package/index.d.cts +746 -333
- package/index.d.ts +746 -333
- package/index.js +1792 -1026
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +16 -293
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +4 -40
- package/node/index.d.ts +4 -40
- package/node/index.js +22 -237
- package/node/index.js.map +1 -1
- package/node/metafile-cjs.json +1 -1
- package/node/metafile-esm.json +1 -1
- package/package.json +12 -4
- package/react/index.cjs.map +1 -1
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/fp-envelope.test.ts-off +65 -0
- package/tests/blockstore/interceptor-gateway.test.ts +122 -0
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
- package/tests/blockstore/keyed-crypto.test.ts +73 -118
- package/tests/blockstore/loader.test.ts +18 -9
- package/tests/blockstore/store.test.ts +40 -31
- package/tests/blockstore/transaction.test.ts +14 -13
- package/tests/fireproof/all-gateway.test.ts +283 -213
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
- package/tests/fireproof/crdt.test.ts +78 -19
- package/tests/fireproof/database.test.ts +225 -29
- package/tests/fireproof/fireproof.test.ts +92 -73
- package/tests/fireproof/hello.test.ts +17 -13
- package/tests/fireproof/indexer.test.ts +67 -43
- package/tests/fireproof/utils.test.ts +47 -6
- package/tests/gateway/file/loader-config.test.ts +307 -0
- package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
- package/tests/gateway/indexdb/loader-config.test.ts +79 -0
- package/tests/helpers.ts +44 -17
- package/tests/react/useFireproof.test.tsx +1 -1
- package/tests/www/todo.html +24 -3
- package/web/index.cjs +102 -116
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +15 -29
- package/web/index.d.ts +15 -29
- package/web/index.js +91 -105
- package/web/index.js.map +1 -1
- package/web/metafile-cjs.json +1 -1
- package/web/metafile-esm.json +1 -1
- package/node/chunk-4A4RAVNS.js +0 -17
- package/node/chunk-4A4RAVNS.js.map +0 -1
- package/node/mem-filesystem-LPPT7QV5.js +0 -40
- package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
- package/tests/fireproof/config.test.ts +0 -163
- /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
- /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 {
|
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
|
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 =
|
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 }>(
|
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(
|
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 =
|
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.
|
188
|
-
expect(db.
|
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.
|
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 =
|
237
|
-
// db =
|
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.
|
251
|
-
expect(db.
|
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 =
|
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.
|
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 =
|
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.
|
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 =
|
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.
|
401
|
-
expect(db.
|
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 =
|
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.
|
414
|
-
expect(db2.
|
415
|
-
expect(db2.
|
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.
|
421
|
-
const blocks = db.
|
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 =
|
430
|
-
await db2.
|
431
|
-
const blocks = db2.
|
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 =
|
465
|
+
const db = DatabaseFactory("test-reopen");
|
443
466
|
// assert(db._crdt.xready());
|
444
|
-
await db.
|
445
|
-
const blocks = db.
|
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 =
|
484
|
+
const db = DatabaseFactory("test-reopen", { autoCompact: 1000 }); // try with 10
|
462
485
|
// assert(db._crdt.ready);
|
463
|
-
await db.
|
486
|
+
await db.crdt.ready();
|
464
487
|
// console.timeEnd("db open");
|
465
|
-
const blocks = db.
|
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>(
|
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>(
|
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(
|
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.
|
547
|
-
expect(db2.
|
548
|
-
expect(db2.
|
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.
|
562
|
-
expect(db2.
|
563
|
-
expect(db2.
|
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.
|
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.
|
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
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
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.
|
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.
|
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.
|
693
|
+
const logA = dbA.crdt.blockstore.loader?.carLog;
|
675
694
|
expect(logA).toBeTruthy();
|
676
695
|
assert(logA);
|
677
|
-
expect(logA.length).toBe(
|
696
|
+
expect(logA.length).toBe(docs.length);
|
678
697
|
|
679
|
-
const logB = dbB.
|
698
|
+
const logB = dbB.crdt.blockstore.loader?.carLog;
|
680
699
|
expect(logB).toBeTruthy();
|
681
700
|
assert(logB);
|
682
|
-
expect(logB.length).toBe(
|
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.
|
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.
|
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
|
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 =
|
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",
|
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
|
-
|
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
|
22
|
-
|
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
|
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
|
42
|
+
it("should get when you open it again", async () => {
|
38
43
|
await db.close();
|
39
|
-
|
40
|
-
|
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 =
|
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 =
|
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();
|