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