@fireproof/core 0.20.0-dev-preview-40 → 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.
- package/README.md +6 -4
- package/deno/index.js +2 -2
- package/deno/index.js.map +1 -1
- package/index.cjs +499 -370
- package/index.cjs.map +1 -1
- package/index.d.cts +162 -64
- package/index.d.ts +162 -64
- package/index.js +473 -344
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/react/index.cjs +17 -9
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +2 -1
- package/react/index.d.ts +2 -1
- package/react/index.js +17 -9
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/interceptor-gateway.test.ts +5 -1
- package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +8 -18
- package/tests/blockstore/keyed-crypto.test.ts +7 -30
- package/tests/blockstore/loader.test.ts +19 -17
- package/tests/blockstore/store.test.ts +48 -51
- package/tests/blockstore/transaction.test.ts +13 -11
- package/tests/fireproof/all-gateway.test.ts +49 -46
- package/tests/fireproof/attachable.test.ts +82 -0
- package/tests/fireproof/crdt.test.ts +49 -48
- package/tests/fireproof/database.test.ts +40 -40
- package/tests/fireproof/fireproof.test.ts +43 -42
- package/tests/fireproof/hello.test.ts +4 -4
- package/tests/fireproof/indexer.test.ts +44 -44
- package/tests/fireproof/utils.test.ts +4 -3
- package/tests/gateway/file/loader-config.test.ts +17 -17
- package/tests/gateway/indexeddb/loader-config.test.ts +4 -4
- package/tests/helpers.ts +80 -2
- package/tests/react/useFireproof.test.tsx +40 -4
@@ -59,19 +59,19 @@ describe("basic Ledger with record", function () {
|
|
59
59
|
await db.close();
|
60
60
|
await db.destroy();
|
61
61
|
});
|
62
|
-
beforeEach(async
|
62
|
+
beforeEach(async () => {
|
63
63
|
await sthis.start();
|
64
64
|
db = fireproof("factory-name");
|
65
65
|
const ok = await db.put<Doc>({ _id: "hello", value: "world" });
|
66
66
|
expect(ok.id).toBe("hello");
|
67
67
|
});
|
68
|
-
it("should get", async
|
68
|
+
it("should get", async () => {
|
69
69
|
const doc = await db.get<Doc>("hello");
|
70
70
|
expect(doc).toBeTruthy();
|
71
71
|
expect(doc._id).toBe("hello");
|
72
72
|
expect(doc.value).toBe("world");
|
73
73
|
});
|
74
|
-
it("should update", async
|
74
|
+
it("should update", async () => {
|
75
75
|
const ok = await db.put({ _id: "hello", value: "universe" });
|
76
76
|
expect(ok.id).toBe("hello");
|
77
77
|
const doc = await db.get<Doc>("hello");
|
@@ -79,20 +79,20 @@ describe("basic Ledger with record", function () {
|
|
79
79
|
expect(doc._id).toBe("hello");
|
80
80
|
expect(doc.value).toBe("universe");
|
81
81
|
});
|
82
|
-
it("should del last record", async
|
82
|
+
it("should del last record", async () => {
|
83
83
|
const ok = await db.del("hello");
|
84
84
|
expect(ok.id).toBe("hello");
|
85
85
|
|
86
86
|
const e = await db.get("hello").catch((e) => e);
|
87
87
|
expect(e.message).toMatch(/Not found/);
|
88
88
|
});
|
89
|
-
it("has changes", async
|
89
|
+
it("has changes", async () => {
|
90
90
|
const { rows } = await db.changes([]);
|
91
91
|
expect(rows.length).toBe(1);
|
92
92
|
expect(rows[0].key).toBe("hello");
|
93
93
|
expect(rows[0].value._id).toBe("hello");
|
94
94
|
});
|
95
|
-
it("is not persisted", async
|
95
|
+
it("is not persisted", async () => {
|
96
96
|
const db2 = fireproof("factory-name");
|
97
97
|
const { rows } = await db2.changes([]);
|
98
98
|
expect(rows.length).toBe(1);
|
@@ -114,7 +114,7 @@ describe("named Ledger with record", function () {
|
|
114
114
|
await db.close();
|
115
115
|
await db.destroy();
|
116
116
|
});
|
117
|
-
beforeEach(async
|
117
|
+
beforeEach(async () => {
|
118
118
|
await sthis.start();
|
119
119
|
db = fireproof("test-db-name");
|
120
120
|
/** @type {Doc} */
|
@@ -122,13 +122,13 @@ describe("named Ledger with record", function () {
|
|
122
122
|
const ok = await db.put(doc);
|
123
123
|
expect(ok.id).toBe("hello");
|
124
124
|
});
|
125
|
-
it("should get", async
|
125
|
+
it("should get", async () => {
|
126
126
|
const doc = await db.get<Doc>("hello");
|
127
127
|
expect(doc).toBeTruthy();
|
128
128
|
expect(doc._id).toBe("hello");
|
129
129
|
expect(doc.value).toBe("world");
|
130
130
|
});
|
131
|
-
it("should update", async
|
131
|
+
it("should update", async () => {
|
132
132
|
const ok = await db.put({ _id: "hello", value: "universe" });
|
133
133
|
expect(ok.id).toBe("hello");
|
134
134
|
const doc = await db.get<Doc>("hello");
|
@@ -136,20 +136,20 @@ describe("named Ledger with record", function () {
|
|
136
136
|
expect(doc._id).toBe("hello");
|
137
137
|
expect(doc.value).toBe("universe");
|
138
138
|
});
|
139
|
-
it("should del last record", async
|
139
|
+
it("should del last record", async () => {
|
140
140
|
const ok = await db.del("hello");
|
141
141
|
expect(ok.id).toBe("hello");
|
142
142
|
|
143
143
|
const e = await db.get("hello").catch((e) => e);
|
144
144
|
expect(e.message).toMatch(/Not found/);
|
145
145
|
});
|
146
|
-
it("has changes", async
|
146
|
+
it("has changes", async () => {
|
147
147
|
const { rows } = await db.changes([]);
|
148
148
|
expect(rows.length).toBe(1);
|
149
149
|
expect(rows[0].key).toBe("hello");
|
150
150
|
expect(rows[0].value._id).toBe("hello");
|
151
151
|
});
|
152
|
-
it("should have a key", async
|
152
|
+
it("should have a key", async () => {
|
153
153
|
const { rows } = await db.changes([]);
|
154
154
|
expect(rows.length).toBe(1);
|
155
155
|
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
@@ -161,7 +161,7 @@ describe("named Ledger with record", function () {
|
|
161
161
|
// expect(loader.keyId?.length).toBe(64);
|
162
162
|
// expect(loader.key).not.toBe(loader.keyId);
|
163
163
|
});
|
164
|
-
it("should work right with a sequence of changes", async
|
164
|
+
it("should work right with a sequence of changes", async () => {
|
165
165
|
const numDocs = 10;
|
166
166
|
for (let i = 0; i < numDocs; i++) {
|
167
167
|
const doc = { _id: `id-${i}`, hello: "world" };
|
@@ -198,7 +198,7 @@ describe("named Ledger with record", function () {
|
|
198
198
|
expect(rows4.length).toBe(5);
|
199
199
|
});
|
200
200
|
|
201
|
-
it("should work right after compaction", async
|
201
|
+
it("should work right after compaction", async () => {
|
202
202
|
const numDocs = 10;
|
203
203
|
for (let i = 0; i < numDocs; i++) {
|
204
204
|
const doc = { _id: `id-${i}`, hello: "world" };
|
@@ -222,7 +222,7 @@ describe("named Ledger with record", function () {
|
|
222
222
|
// /** @type {Ledger} */
|
223
223
|
// let db
|
224
224
|
// const writes = []
|
225
|
-
// beforeEach(async
|
225
|
+
// beforeEach(async () =>{
|
226
226
|
// await resetDirectory(dataDir, 'test-parallel-writes')
|
227
227
|
// db = new Ledger('test-parallel-writes', { public: true })
|
228
228
|
// /** @type {Doc} */
|
@@ -256,7 +256,7 @@ describe("basic Ledger parallel writes / public ordered", () => {
|
|
256
256
|
expect(crdt.clock.head.length).toBe(1);
|
257
257
|
});
|
258
258
|
|
259
|
-
it("has changes ordered", async
|
259
|
+
it("has changes ordered", async () => {
|
260
260
|
const { rows, clock } = await db.changes([]);
|
261
261
|
expect(clock[0]).toBe(db.ledger.crdt.clock.head[0]);
|
262
262
|
expect(rows.length).toBe(10);
|
@@ -299,7 +299,7 @@ describe("basic Ledger parallel writes / public", () => {
|
|
299
299
|
expect(doc.hello).toBe("world");
|
300
300
|
}
|
301
301
|
});
|
302
|
-
it("should del all", async
|
302
|
+
it("should del all", async () => {
|
303
303
|
for (let i = 0; i < 10; i++) {
|
304
304
|
const id = `id-${i}`;
|
305
305
|
const ok = await db.del(id);
|
@@ -309,7 +309,7 @@ describe("basic Ledger parallel writes / public", () => {
|
|
309
309
|
expect(e.message).toMatch(/Not found/);
|
310
310
|
}
|
311
311
|
});
|
312
|
-
it("should delete all in parallel", async
|
312
|
+
it("should delete all in parallel", async () => {
|
313
313
|
const deletes: Promise<DocResponse>[] = [];
|
314
314
|
for (let i = 0; i < 10; i++) {
|
315
315
|
const id = `id-${i}`;
|
@@ -322,7 +322,7 @@ describe("basic Ledger parallel writes / public", () => {
|
|
322
322
|
expect(e.message).toMatch(/Not found/);
|
323
323
|
}
|
324
324
|
});
|
325
|
-
it("has changes not ordered", async
|
325
|
+
it("has changes not ordered", async () => {
|
326
326
|
const { rows, clock } = await db.changes([]);
|
327
327
|
expect(clock[0]).toBe(db.ledger.crdt.clock.head[0]);
|
328
328
|
expect(rows.length).toBe(10);
|
@@ -333,7 +333,7 @@ describe("basic Ledger parallel writes / public", () => {
|
|
333
333
|
expect(rows[i].clock).toBeTruthy();
|
334
334
|
}
|
335
335
|
});
|
336
|
-
it("should not have a key", async
|
336
|
+
it("should not have a key", async () => {
|
337
337
|
const { rows } = await db.changes([]);
|
338
338
|
expect(rows.length).toBe(10);
|
339
339
|
// expect(db.opts.public).toBeTruthy();
|
@@ -358,7 +358,7 @@ describe("basic Ledger with subscription", function () {
|
|
358
358
|
await db.close();
|
359
359
|
await db.destroy();
|
360
360
|
});
|
361
|
-
beforeEach(async
|
361
|
+
beforeEach(async () => {
|
362
362
|
await sthis.start();
|
363
363
|
db = fireproof("factory-name");
|
364
364
|
didRun = 0;
|
@@ -371,7 +371,7 @@ describe("basic Ledger with subscription", function () {
|
|
371
371
|
}, true);
|
372
372
|
});
|
373
373
|
});
|
374
|
-
it("should run on put", async
|
374
|
+
it("should run on put", async () => {
|
375
375
|
const all = await db.allDocs();
|
376
376
|
expect(all.rows.length).toBe(0);
|
377
377
|
const doc = { _id: "hello", message: "world" };
|
@@ -384,7 +384,7 @@ describe("basic Ledger with subscription", function () {
|
|
384
384
|
expect(ok.id).toBe("hello");
|
385
385
|
expect(didRun).toBe(1);
|
386
386
|
});
|
387
|
-
it("should unsubscribe", async
|
387
|
+
it("should unsubscribe", async () => {
|
388
388
|
unsubscribe();
|
389
389
|
const doc = { _id: "hello", message: "again" };
|
390
390
|
const ok = await db.put(doc);
|
@@ -402,14 +402,14 @@ describe("basic Ledger with no update subscription", function () {
|
|
402
402
|
await db.close();
|
403
403
|
await db.destroy();
|
404
404
|
});
|
405
|
-
beforeEach(async
|
405
|
+
beforeEach(async () => {
|
406
406
|
db = fireproof("factory-name");
|
407
407
|
didRun = 0;
|
408
408
|
unsubscribe = db.subscribe(() => {
|
409
409
|
didRun++;
|
410
410
|
});
|
411
411
|
});
|
412
|
-
it("should run on put", async
|
412
|
+
it("should run on put", async () => {
|
413
413
|
const all = await db.allDocs();
|
414
414
|
expect(all.rows.length).toBe(0);
|
415
415
|
/** @type {Doc} */
|
@@ -419,7 +419,7 @@ describe("basic Ledger with no update subscription", function () {
|
|
419
419
|
expect(ok.id).toBe("hello");
|
420
420
|
expect(didRun).toBe(1);
|
421
421
|
});
|
422
|
-
it("should unsubscribe", async
|
422
|
+
it("should unsubscribe", async () => {
|
423
423
|
unsubscribe();
|
424
424
|
const doc = { _id: "hello", message: "again" };
|
425
425
|
const ok = await db.put(doc);
|
@@ -438,7 +438,7 @@ describe("ledger with files input", () => {
|
|
438
438
|
await db.close();
|
439
439
|
await db.destroy();
|
440
440
|
});
|
441
|
-
beforeEach(async
|
441
|
+
beforeEach(async () => {
|
442
442
|
await sthis.start();
|
443
443
|
imagefiles = await buildBlobFiles();
|
444
444
|
db = fireproof("fireproof-with-images");
|
@@ -453,11 +453,11 @@ describe("ledger with files input", () => {
|
|
453
453
|
result = await db.put(doc);
|
454
454
|
});
|
455
455
|
|
456
|
-
it("Should upload images", async
|
456
|
+
it("Should upload images", async () => {
|
457
457
|
expect(result.id).toBe("images-main");
|
458
458
|
});
|
459
459
|
|
460
|
-
it("Should fetch the images", async
|
460
|
+
it("Should fetch the images", async () => {
|
461
461
|
const doc = await db.get(result.id);
|
462
462
|
const files = doc._files as DocFiles;
|
463
463
|
expect(files).toBeTruthy();
|
@@ -488,7 +488,7 @@ describe("ledger with files input", () => {
|
|
488
488
|
// expect(file.name).toBe('fireproof.png') // see https://github.com/fireproof-storage/fireproof/issues/70
|
489
489
|
});
|
490
490
|
|
491
|
-
it("should update the file document data without changing the files", async
|
491
|
+
it("should update the file document data without changing the files", async () => {
|
492
492
|
interface Doc {
|
493
493
|
type: string;
|
494
494
|
}
|
@@ -551,13 +551,13 @@ describe("StoreURIRuntime", () => {
|
|
551
551
|
it("default toStoreURIRuntime", () => {
|
552
552
|
expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "test")))).toEqual({
|
553
553
|
data: {
|
554
|
-
|
554
|
+
car: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&suffix=.car&urlGen=fromEnv",
|
555
555
|
file: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&urlGen=fromEnv",
|
556
556
|
meta: "my://bla/storage?name=test&store=meta&storekey=%40test-meta%40&urlGen=fromEnv",
|
557
557
|
wal: "my://bla/storage?name=test&store=wal&storekey=%40test-wal%40&urlGen=fromEnv",
|
558
558
|
},
|
559
559
|
idx: {
|
560
|
-
|
560
|
+
car: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&suffix=.car&urlGen=fromEnv",
|
561
561
|
file: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&urlGen=fromEnv",
|
562
562
|
meta: "my://bla/storage?index=idx&name=test&store=meta&storekey=%40test-meta-idx%40&urlGen=fromEnv",
|
563
563
|
wal: "my://bla/storage?index=idx&name=test&store=wal&storekey=%40test-wal-idx%40&urlGen=fromEnv",
|
@@ -568,13 +568,13 @@ describe("StoreURIRuntime", () => {
|
|
568
568
|
it("no name toStoreURIRuntime(not more)", () => {
|
569
569
|
expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "gogo")))).toEqual({
|
570
570
|
data: {
|
571
|
-
|
571
|
+
car: "my://bla/storage?name=gogo&store=data&storekey=%40gogo-data%40&suffix=.car&urlGen=fromEnv",
|
572
572
|
file: "my://bla/storage?name=gogo&store=data&storekey=%40gogo-data%40&urlGen=fromEnv",
|
573
573
|
meta: "my://bla/storage?name=gogo&store=meta&storekey=%40gogo-meta%40&urlGen=fromEnv",
|
574
574
|
wal: "my://bla/storage?name=gogo&store=wal&storekey=%40gogo-wal%40&urlGen=fromEnv",
|
575
575
|
},
|
576
576
|
idx: {
|
577
|
-
|
577
|
+
car: "my://bla/storage?index=idx&name=gogo&store=data&storekey=%40gogo-data-idx%40&suffix=.car&urlGen=fromEnv",
|
578
578
|
file: "my://bla/storage?index=idx&name=gogo&store=data&storekey=%40gogo-data-idx%40&urlGen=fromEnv",
|
579
579
|
meta: "my://bla/storage?index=idx&name=gogo&store=meta&storekey=%40gogo-meta-idx%40&urlGen=fromEnv",
|
580
580
|
wal: "my://bla/storage?index=idx&name=gogo&store=wal&storekey=%40gogo-wal-idx%40&urlGen=fromEnv",
|
@@ -601,13 +601,13 @@ describe("StoreURIRuntime", () => {
|
|
601
601
|
),
|
602
602
|
).toEqual({
|
603
603
|
data: {
|
604
|
-
|
604
|
+
car: "my://storage-data?name=yyy&store=data&storekey=%40yyy-data%40&suffix=.car",
|
605
605
|
file: "my://storage-data?name=yyy&store=data&storekey=%40yyy-data%40",
|
606
606
|
meta: "my://storage-meta?name=xxx&store=meta&storekey=%40xxx-meta%40",
|
607
607
|
wal: "my://storage-base?name=xxx&store=wal&storekey=%40xxx-wal%40",
|
608
608
|
},
|
609
609
|
idx: {
|
610
|
-
|
610
|
+
car: "my://storage-idx-data?index=bla&name=yyy&store=data&storekey=%40yyy-data-idx%40&suffix=.car",
|
611
611
|
file: "my://storage-idx-data?index=bla&name=yyy&store=data&storekey=%40yyy-data-idx%40",
|
612
612
|
meta: "my://storage-idx-meta?index=idx&name=xxx&store=meta&storekey=%40xxx-meta-idx%40",
|
613
613
|
wal: "my://storage-base?index=idx&name=xxx&store=wal&storekey=%40xxx-wal-idx%40",
|
@@ -619,13 +619,13 @@ describe("StoreURIRuntime", () => {
|
|
619
619
|
sthis.env.delete("FP_STORAGE_URL");
|
620
620
|
expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "maxi")))).toEqual({
|
621
621
|
data: {
|
622
|
-
|
622
|
+
car: "murks://fp?name=maxi&store=data&storekey=%40maxi-data%40&suffix=.car&urlGen=default",
|
623
623
|
file: "murks://fp?name=maxi&store=data&storekey=%40maxi-data%40&urlGen=default",
|
624
624
|
meta: "murks://fp?name=maxi&store=meta&storekey=%40maxi-meta%40&urlGen=default",
|
625
625
|
wal: "murks://fp?name=maxi&store=wal&storekey=%40maxi-wal%40&urlGen=default",
|
626
626
|
},
|
627
627
|
idx: {
|
628
|
-
|
628
|
+
car: "murks://fp?index=idx&name=maxi&store=data&storekey=%40maxi-data-idx%40&suffix=.car&urlGen=default",
|
629
629
|
file: "murks://fp?index=idx&name=maxi&store=data&storekey=%40maxi-data-idx%40&urlGen=default",
|
630
630
|
meta: "murks://fp?index=idx&name=maxi&store=meta&storekey=%40maxi-meta-idx%40&urlGen=default",
|
631
631
|
wal: "murks://fp?index=idx&name=maxi&store=wal&storekey=%40maxi-wal-idx%40&urlGen=default",
|
@@ -642,7 +642,7 @@ describe("StoreURIRuntime", () => {
|
|
642
642
|
stores: [
|
643
643
|
{
|
644
644
|
data: {
|
645
|
-
|
645
|
+
car: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&suffix=.car&urlGen=fromEnv",
|
646
646
|
file: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&urlGen=fromEnv",
|
647
647
|
meta: "my://bla/storage?name=test&store=meta&storekey=%40test-meta%40&urlGen=fromEnv",
|
648
648
|
wal: "my://bla/storage?name=test&store=wal&storekey=%40test-wal%40&urlGen=fromEnv",
|
@@ -650,7 +650,7 @@ describe("StoreURIRuntime", () => {
|
|
650
650
|
},
|
651
651
|
{
|
652
652
|
idx: {
|
653
|
-
|
653
|
+
car: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&suffix=.car&urlGen=fromEnv",
|
654
654
|
file: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&urlGen=fromEnv",
|
655
655
|
meta: "my://bla/storage?index=idx&name=test&store=meta&storekey=%40test-meta-idx%40&urlGen=fromEnv",
|
656
656
|
wal: "my://bla/storage?index=idx&name=test&store=wal&storekey=%40test-wal-idx%40&urlGen=fromEnv",
|
@@ -41,11 +41,11 @@ describe("dreamcode", function () {
|
|
41
41
|
let result: IndexRows<string, Doc>;
|
42
42
|
let db: Database;
|
43
43
|
const sthis = ensureSuperThis();
|
44
|
-
afterEach(async
|
44
|
+
afterEach(async () => {
|
45
45
|
await db.close();
|
46
46
|
await db.destroy();
|
47
47
|
});
|
48
|
-
beforeEach(async
|
48
|
+
beforeEach(async () => {
|
49
49
|
await sthis.start();
|
50
50
|
db = fireproof("test-db");
|
51
51
|
ok = await db.put({ _id: "test-1", text: "fireproof", dream: true });
|
@@ -65,7 +65,7 @@ describe("dreamcode", function () {
|
|
65
65
|
expect(result.rows.length).toBe(1);
|
66
66
|
expect(result.rows[0].key).toBe("fireproof");
|
67
67
|
});
|
68
|
-
it("should query with function", async
|
68
|
+
it("should query with function", async () => {
|
69
69
|
const result = await db.query<boolean, Doc>((doc) => doc.dream);
|
70
70
|
expect(result).toBeTruthy();
|
71
71
|
expect(result.rows).toBeTruthy();
|
@@ -89,7 +89,7 @@ describe("public API", function () {
|
|
89
89
|
await db.destroy();
|
90
90
|
});
|
91
91
|
|
92
|
-
beforeEach(async
|
92
|
+
beforeEach(async () => {
|
93
93
|
await sthis.start();
|
94
94
|
db = fireproof("test-api");
|
95
95
|
// index = index(db, 'test-index', (doc) => doc.foo)
|
@@ -142,12 +142,13 @@ describe("database fullconfig", () => {
|
|
142
142
|
// wal: `${base}/wal?taste=${taste}`,
|
143
143
|
},
|
144
144
|
});
|
145
|
+
await db.ready();
|
145
146
|
|
146
|
-
const carStore = await db.ledger.crdt.blockstore.loader
|
147
|
+
const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
|
147
148
|
expect(carStore.url().getParam(PARAM.NAME)).toBe("my-funky-name");
|
148
|
-
const metaStore = await db.ledger.crdt.blockstore.loader
|
149
|
+
const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
|
149
150
|
expect(metaStore.url().getParam(PARAM.NAME)).toBe("my-funky-name");
|
150
|
-
const walStore = await db.ledger.crdt.blockstore.loader
|
151
|
+
const walStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.wal;
|
151
152
|
expect(walStore.url().getParam(PARAM.NAME)).toBe("my-funky-name");
|
152
153
|
|
153
154
|
expect(db).toBeTruthy();
|
@@ -163,26 +164,26 @@ describe("basic ledger", function () {
|
|
163
164
|
}
|
164
165
|
let db: Database;
|
165
166
|
const sthis = ensureSuperThis();
|
166
|
-
afterEach(async
|
167
|
+
afterEach(async () => {
|
167
168
|
await db.close();
|
168
169
|
await db.destroy();
|
169
170
|
});
|
170
|
-
beforeEach(async
|
171
|
+
beforeEach(async () => {
|
171
172
|
await sthis.start();
|
172
173
|
db = fireproof("test-basic");
|
173
174
|
});
|
174
|
-
it("can put with id", async
|
175
|
+
it("can put with id", async () => {
|
175
176
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
176
177
|
expect(ok).toBeTruthy();
|
177
178
|
expect(ok.id).toBe("test");
|
178
179
|
});
|
179
|
-
it("can put without id", async
|
180
|
+
it("can put without id", async () => {
|
180
181
|
const ok = await db.put({ foo: "bam" });
|
181
182
|
expect(ok).toBeTruthy();
|
182
183
|
const got = await db.get<Doc>(ok.id);
|
183
184
|
expect(got.foo).toBe("bam");
|
184
185
|
});
|
185
|
-
it("can bulk an array", async
|
186
|
+
it("can bulk an array", async () => {
|
186
187
|
const ok = await db.bulk([{ foo: "cool" }, { foo: "dude" }]);
|
187
188
|
expect(ok).toBeTruthy();
|
188
189
|
expect(ok.ids.length).toBe(2);
|
@@ -191,7 +192,7 @@ describe("basic ledger", function () {
|
|
191
192
|
const got2 = await db.get<Doc>(ok.ids[1]);
|
192
193
|
expect(got2.foo).toBe("dude");
|
193
194
|
});
|
194
|
-
it("can define an index", async
|
195
|
+
it("can define an index", async () => {
|
195
196
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
196
197
|
expect(ok).toBeTruthy();
|
197
198
|
const idx = index<string, { foo: string }>(db, "test-index", (doc) => doc.foo);
|
@@ -201,7 +202,7 @@ describe("basic ledger", function () {
|
|
201
202
|
expect(result.rows.length).toBe(1);
|
202
203
|
expect(result.rows[0].key).toBe("bar");
|
203
204
|
});
|
204
|
-
it("can define an index with a default function", async
|
205
|
+
it("can define an index with a default function", async () => {
|
205
206
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
206
207
|
expect(ok).toBeTruthy();
|
207
208
|
const idx = index(db, "foo");
|
@@ -211,7 +212,7 @@ describe("basic ledger", function () {
|
|
211
212
|
expect(result.rows.length).toBe(1);
|
212
213
|
expect(result.rows[0].key).toBe("bar");
|
213
214
|
});
|
214
|
-
it("should query with multiple successive functions", async
|
215
|
+
it("should query with multiple successive functions", async () => {
|
215
216
|
interface TestDoc {
|
216
217
|
_id: string;
|
217
218
|
foo: string;
|
@@ -236,16 +237,16 @@ describe("basic ledger", function () {
|
|
236
237
|
describe("benchmarking with compaction", function () {
|
237
238
|
let db: Database;
|
238
239
|
const sthis = ensureSuperThis();
|
239
|
-
afterEach(async
|
240
|
+
afterEach(async () => {
|
240
241
|
await db.close();
|
241
242
|
await db.destroy();
|
242
243
|
});
|
243
|
-
beforeEach(async
|
244
|
+
beforeEach(async () => {
|
244
245
|
// erase the existing test data
|
245
246
|
await sthis.start();
|
246
247
|
db = fireproof("test-benchmark-compaction", { autoCompact: 3 });
|
247
248
|
});
|
248
|
-
it.skip("insert during compaction", async
|
249
|
+
it.skip("insert during compaction", async () => {
|
249
250
|
const ok = await db.put({ _id: "test", foo: "fast" });
|
250
251
|
expect(ok).toBeTruthy();
|
251
252
|
expect(ok.id).toBe("test");
|
@@ -290,11 +291,11 @@ describe("benchmarking with compaction", function () {
|
|
290
291
|
describe("benchmarking a ledger", function () {
|
291
292
|
let db: Database;
|
292
293
|
const sthis = ensureSuperThis();
|
293
|
-
afterEach(async
|
294
|
+
afterEach(async () => {
|
294
295
|
await db.close();
|
295
296
|
await db.destroy();
|
296
297
|
});
|
297
|
-
beforeEach(async
|
298
|
+
beforeEach(async () => {
|
298
299
|
await sthis.start();
|
299
300
|
// erase the existing test data
|
300
301
|
db = fireproof("test-benchmark", { autoCompact: 100000, public: true });
|
@@ -448,11 +449,11 @@ describe("Reopening a ledger", function () {
|
|
448
449
|
}
|
449
450
|
let db: Database;
|
450
451
|
const sthis = ensureSuperThis();
|
451
|
-
afterEach(async
|
452
|
+
afterEach(async () => {
|
452
453
|
await db.close();
|
453
454
|
await db.destroy();
|
454
455
|
});
|
455
|
-
beforeEach(async
|
456
|
+
beforeEach(async () => {
|
456
457
|
// erase the existing test data
|
457
458
|
await sthis.start();
|
458
459
|
|
@@ -465,12 +466,12 @@ describe("Reopening a ledger", function () {
|
|
465
466
|
expect(db.ledger.crdt.clock.head.length).toBe(1);
|
466
467
|
});
|
467
468
|
|
468
|
-
it("should persist data", async
|
469
|
+
it("should persist data", async () => {
|
469
470
|
const doc = await db.get<Doc>("test");
|
470
471
|
expect(doc.foo).toBe("bar");
|
471
472
|
});
|
472
473
|
|
473
|
-
it("should have the same data on reopen", async
|
474
|
+
it("should have the same data on reopen", async () => {
|
474
475
|
const db2 = fireproof("test-reopen");
|
475
476
|
const doc = await db2.get<FooType>("test");
|
476
477
|
expect(doc.foo).toBe("bar");
|
@@ -480,7 +481,7 @@ describe("Reopening a ledger", function () {
|
|
480
481
|
await db2.close();
|
481
482
|
});
|
482
483
|
|
483
|
-
it("should have a car in the car log", async
|
484
|
+
it("should have a car in the car log", async () => {
|
484
485
|
await db.ledger.crdt.ready();
|
485
486
|
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
486
487
|
const loader = blocks.loader;
|
@@ -489,7 +490,7 @@ describe("Reopening a ledger", function () {
|
|
489
490
|
expect(loader.carLog.length).toBe(1);
|
490
491
|
});
|
491
492
|
|
492
|
-
it("should have carlog after reopen", async
|
493
|
+
it("should have carlog after reopen", async () => {
|
493
494
|
const db2 = fireproof("test-reopen");
|
494
495
|
await db2.ledger.crdt.ready();
|
495
496
|
const blocks = db2.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
@@ -500,7 +501,7 @@ describe("Reopening a ledger", function () {
|
|
500
501
|
await db2.close();
|
501
502
|
});
|
502
503
|
|
503
|
-
it("faster, should have the same data on reopen after reopen and update", async
|
504
|
+
it("faster, should have the same data on reopen after reopen and update", async () => {
|
504
505
|
for (let i = 0; i < 4; i++) {
|
505
506
|
// console.log('iteration', i)
|
506
507
|
const db = fireproof("test-reopen");
|
@@ -518,7 +519,7 @@ describe("Reopening a ledger", function () {
|
|
518
519
|
}
|
519
520
|
}, 20000);
|
520
521
|
|
521
|
-
it.skip("passing slow, should have the same data on reopen after reopen and update", async
|
522
|
+
it.skip("passing slow, should have the same data on reopen after reopen and update", async () => {
|
522
523
|
for (let i = 0; i < 200; i++) {
|
523
524
|
// console.log("iteration", i);
|
524
525
|
// console.time("db open");
|
@@ -553,11 +554,11 @@ describe("Reopening a ledger with indexes", function () {
|
|
553
554
|
let didMap: boolean;
|
554
555
|
let mapFn: MapFn<Doc>;
|
555
556
|
const sthis = ensureSuperThis();
|
556
|
-
afterEach(async
|
557
|
+
afterEach(async () => {
|
557
558
|
await db.close();
|
558
559
|
await db.destroy();
|
559
560
|
});
|
560
|
-
beforeEach(async
|
561
|
+
beforeEach(async () => {
|
561
562
|
await sthis.start();
|
562
563
|
db = fireproof("test-reopen-idx");
|
563
564
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
@@ -572,7 +573,7 @@ describe("Reopening a ledger with indexes", function () {
|
|
572
573
|
idx = index<string, Doc>(db, "foo", mapFn);
|
573
574
|
});
|
574
575
|
|
575
|
-
it("should persist data", async
|
576
|
+
it("should persist data", async () => {
|
576
577
|
const doc = await db.get<Doc>("test");
|
577
578
|
expect(doc.foo).toBe("bar");
|
578
579
|
const idx2 = index<string, Doc>(db, "foo");
|
@@ -585,7 +586,7 @@ describe("Reopening a ledger with indexes", function () {
|
|
585
586
|
expect(didMap).toBeTruthy();
|
586
587
|
});
|
587
588
|
|
588
|
-
it("should reuse the index", async
|
589
|
+
it("should reuse the index", async () => {
|
589
590
|
const idx2 = index(db, "foo", mapFn);
|
590
591
|
expect(idx2).toBe(idx);
|
591
592
|
const result = await idx2.query();
|
@@ -603,7 +604,7 @@ describe("Reopening a ledger with indexes", function () {
|
|
603
604
|
expect(didMap).toBeFalsy();
|
604
605
|
});
|
605
606
|
|
606
|
-
it("should have the same data on reopen", async
|
607
|
+
it("should have the same data on reopen", async () => {
|
607
608
|
const db2 = fireproof("test-reopen-idx");
|
608
609
|
const doc = await db2.get<FooType>("test");
|
609
610
|
expect(doc.foo).toBe("bar");
|
@@ -612,7 +613,7 @@ describe("Reopening a ledger with indexes", function () {
|
|
612
613
|
expect(db2.ledger.crdt.clock.head).toEqual(db.ledger.crdt.clock.head);
|
613
614
|
});
|
614
615
|
|
615
|
-
it("should have the same data on reopen after a query", async
|
616
|
+
it("should have the same data on reopen after a query", async () => {
|
616
617
|
const r0 = await idx.query();
|
617
618
|
expect(r0).toBeTruthy();
|
618
619
|
expect(r0.rows).toBeTruthy();
|
@@ -627,7 +628,7 @@ describe("Reopening a ledger with indexes", function () {
|
|
627
628
|
expect(db2.ledger.crdt.clock.head).toEqual(db.ledger.crdt.clock.head);
|
628
629
|
});
|
629
630
|
|
630
|
-
// it('should query the same data on reopen', async
|
631
|
+
// it('should query the same data on reopen', async () =>{
|
631
632
|
// const r0 = await idx.query()
|
632
633
|
// assert(r0)
|
633
634
|
// assert(r0.rows)
|
@@ -650,10 +651,10 @@ describe("Reopening a ledger with indexes", function () {
|
|
650
651
|
|
651
652
|
describe("basic js verify", function () {
|
652
653
|
const sthis = ensureSuperThis();
|
653
|
-
beforeAll(async
|
654
|
+
beforeAll(async () => {
|
654
655
|
await sthis.start();
|
655
656
|
});
|
656
|
-
it("should include cids in arrays", async
|
657
|
+
it("should include cids in arrays", async () => {
|
657
658
|
const db = fireproof("test-verify");
|
658
659
|
const ok = await db.put({ _id: "test", foo: ["bar", "bam"] });
|
659
660
|
expect(ok.id).toBe("test");
|
@@ -697,13 +698,13 @@ describe("same workload twice, same CID", function () {
|
|
697
698
|
},
|
698
699
|
};
|
699
700
|
|
700
|
-
afterEach(async
|
701
|
+
afterEach(async () => {
|
701
702
|
await dbA.close();
|
702
703
|
await dbA.destroy();
|
703
704
|
await dbB.close();
|
704
705
|
await dbB.destroy();
|
705
706
|
});
|
706
|
-
beforeEach(async
|
707
|
+
beforeEach(async () => {
|
707
708
|
let ok: DocResponse;
|
708
709
|
await sthis.start();
|
709
710
|
// todo this fails because the test setup doesn't properly configure both ledgers to use the same key
|
@@ -724,13 +725,13 @@ describe("same workload twice, same CID", function () {
|
|
724
725
|
}
|
725
726
|
headB = dbB.ledger.crdt.clock.head.toString();
|
726
727
|
});
|
727
|
-
it("should have head A and B", async
|
728
|
+
it("should have head A and B", async () => {
|
728
729
|
expect(headA).toBeTruthy();
|
729
730
|
expect(headB).toBeTruthy();
|
730
731
|
expect(headA).toEqual(headB);
|
731
732
|
expect(headA.length).toBeGreaterThan(10);
|
732
733
|
});
|
733
|
-
it("should have same car log", async
|
734
|
+
it("should have same car log", async () => {
|
734
735
|
const logA = dbA.ledger.crdt.blockstore.loader?.carLog;
|
735
736
|
expect(logA).toBeTruthy();
|
736
737
|
assert(logA);
|
@@ -749,7 +750,7 @@ describe("same workload twice, same CID", function () {
|
|
749
750
|
// todo this fails because the test setup doesn't properly configure both ledgers to use the same key
|
750
751
|
// expect(logA2).toEqual(logB2);
|
751
752
|
});
|
752
|
-
it("should have same car log after compact", async
|
753
|
+
it("should have same car log after compact", async () => {
|
753
754
|
await dbA.compact();
|
754
755
|
await dbB.compact();
|
755
756
|
|
@@ -49,23 +49,23 @@ describe("hello public API", () => {
|
|
49
49
|
|
50
50
|
describe("Simplified Reopening a ledger", function () {
|
51
51
|
let db: Database;
|
52
|
-
afterEach(async
|
52
|
+
afterEach(async () => {
|
53
53
|
await db.close();
|
54
54
|
await db.destroy();
|
55
55
|
});
|
56
|
-
beforeEach(async
|
56
|
+
beforeEach(async () => {
|
57
57
|
db = fireproof("test-reopen-simple");
|
58
58
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
59
59
|
expect(ok).toBeTruthy();
|
60
60
|
expect(ok.id).toBe("test");
|
61
61
|
});
|
62
62
|
|
63
|
-
it("should persist data", async
|
63
|
+
it("should persist data", async () => {
|
64
64
|
const doc = await db.get<{ foo: string }>("test");
|
65
65
|
expect(doc.foo).toBe("bar");
|
66
66
|
});
|
67
67
|
|
68
|
-
it("should have the same data on reopen", async
|
68
|
+
it("should have the same data on reopen", async () => {
|
69
69
|
const db2 = fireproof("test-reopen-simple");
|
70
70
|
const doc = await db2.get<{ foo: string }>("test");
|
71
71
|
expect(doc.foo).toBe("bar");
|