@fireproof/core 0.20.0-dev-preview-06 → 0.20.0-dev-preview-11
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 +9 -9
- package/index.cjs +3221 -3166
- package/index.cjs.map +1 -1
- package/index.d.cts +241 -189
- package/index.d.ts +241 -189
- package/index.js +3211 -3156
- 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.map +1 -1
- package/react/index.js.map +1 -1
- package/tests/blockstore/loader.test.ts +6 -6
- package/tests/blockstore/transaction.test.ts +8 -8
- package/tests/fireproof/all-gateway.test.ts +7 -7
- package/tests/fireproof/crdt.test.ts +35 -45
- package/tests/fireproof/database.test.ts +34 -33
- package/tests/fireproof/fireproof.test.ts +58 -60
- package/tests/fireproof/hello.test.ts +3 -3
- package/tests/fireproof/indexer.test.ts +37 -36
- package/tests/gateway/file/loader-config.test.ts +17 -17
- package/tests/gateway/indexdb/loader-config.test.ts +5 -5
- package/tests/www/gallery.html +2 -2
- package/tests/www/todo-aws.html +1 -1
- package/tests/www/todo-ipfs.html +1 -1
- package/tests/www/todo-local.html +1 -1
- package/tests/www/todo.html +1 -1
- /package/tests/fireproof/{multiple-database.test.ts → multiple-ledger.test.ts} +0 -0
@@ -4,18 +4,17 @@ import { CID } from "multiformats/cid";
|
|
4
4
|
|
5
5
|
import {
|
6
6
|
ConfigOpts,
|
7
|
-
Database,
|
8
|
-
DatabaseFactory,
|
9
7
|
DocResponse,
|
10
8
|
DocWithId,
|
11
9
|
Index,
|
12
10
|
IndexRows,
|
13
11
|
MapFn,
|
14
12
|
bs,
|
15
|
-
fireproof,
|
16
13
|
index,
|
17
|
-
isDatabase,
|
18
14
|
ensureSuperThis,
|
15
|
+
fireproof,
|
16
|
+
Database,
|
17
|
+
isDatabase,
|
19
18
|
} from "@fireproof/core";
|
20
19
|
|
21
20
|
export function carLogIncludesGroup(list: bs.AnyLink[], cid: CID) {
|
@@ -96,7 +95,7 @@ describe("public API", function () {
|
|
96
95
|
doc = await db.get("test");
|
97
96
|
query = await db.query<string, Doc>((doc) => doc.foo);
|
98
97
|
});
|
99
|
-
it("should be a
|
98
|
+
it("should be a ledger instance", function () {
|
100
99
|
expect(db).toBeTruthy();
|
101
100
|
expect(isDatabase(db)).toBeTruthy();
|
102
101
|
});
|
@@ -115,11 +114,11 @@ describe("public API", function () {
|
|
115
114
|
});
|
116
115
|
});
|
117
116
|
|
118
|
-
describe("basic
|
117
|
+
describe("basic ledger", function () {
|
119
118
|
interface Doc {
|
120
119
|
foo: string;
|
121
120
|
}
|
122
|
-
let db: Database
|
121
|
+
let db: Database;
|
123
122
|
const sthis = ensureSuperThis();
|
124
123
|
afterEach(async function () {
|
125
124
|
await db.close();
|
@@ -127,7 +126,7 @@ describe("basic database", function () {
|
|
127
126
|
});
|
128
127
|
beforeEach(async function () {
|
129
128
|
await sthis.start();
|
130
|
-
db =
|
129
|
+
db = fireproof("test-basic");
|
131
130
|
});
|
132
131
|
it("can put with id", async function () {
|
133
132
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
@@ -201,14 +200,14 @@ describe("benchmarking with compaction", function () {
|
|
201
200
|
beforeEach(async function () {
|
202
201
|
// erase the existing test data
|
203
202
|
await sthis.start();
|
204
|
-
db =
|
203
|
+
db = fireproof("test-benchmark-compaction", { autoCompact: 3 });
|
205
204
|
});
|
206
205
|
it.skip("insert during compaction", async function () {
|
207
206
|
const ok = await db.put({ _id: "test", foo: "fast" });
|
208
207
|
expect(ok).toBeTruthy();
|
209
208
|
expect(ok.id).toBe("test");
|
210
|
-
expect(db.crdt.clock.head).toBeTruthy();
|
211
|
-
expect(db.crdt.clock.head.length).toBe(1);
|
209
|
+
expect(db.ledger.crdt.clock.head).toBeTruthy();
|
210
|
+
expect(db.ledger.crdt.clock.head.length).toBe(1);
|
212
211
|
|
213
212
|
const numDocs = 20;
|
214
213
|
const batchSize = 5;
|
@@ -229,7 +228,7 @@ describe("benchmarking with compaction", function () {
|
|
229
228
|
}),
|
230
229
|
);
|
231
230
|
}
|
232
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
231
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
233
232
|
const loader = blocks.loader;
|
234
233
|
expect(loader).toBeTruthy();
|
235
234
|
|
@@ -245,8 +244,7 @@ describe("benchmarking with compaction", function () {
|
|
245
244
|
});
|
246
245
|
});
|
247
246
|
|
248
|
-
describe("benchmarking a
|
249
|
-
/** @type {Database} */
|
247
|
+
describe("benchmarking a ledger", function () {
|
250
248
|
let db: Database;
|
251
249
|
const sthis = ensureSuperThis();
|
252
250
|
afterEach(async function () {
|
@@ -256,8 +254,8 @@ describe("benchmarking a database", function () {
|
|
256
254
|
beforeEach(async function () {
|
257
255
|
await sthis.start();
|
258
256
|
// erase the existing test data
|
259
|
-
db =
|
260
|
-
// db =
|
257
|
+
db = fireproof("test-benchmark", { autoCompact: 100000, public: true });
|
258
|
+
// db = fireproof(null, {autoCompact: 100000})
|
261
259
|
});
|
262
260
|
|
263
261
|
// run benchmarking tests
|
@@ -270,8 +268,8 @@ describe("benchmarking a database", function () {
|
|
270
268
|
expect(ok).toBeTruthy();
|
271
269
|
expect(ok.id).toBe("test");
|
272
270
|
|
273
|
-
expect(db.crdt.clock.head).toBeTruthy();
|
274
|
-
expect(db.crdt.clock.head.length).toBe(1);
|
271
|
+
expect(db.ledger.crdt.clock.head).toBeTruthy();
|
272
|
+
expect(db.ledger.crdt.clock.head.length).toBe(1);
|
275
273
|
|
276
274
|
const numDocs = 2500;
|
277
275
|
const batchSize = 500;
|
@@ -307,7 +305,7 @@ describe("benchmarking a database", function () {
|
|
307
305
|
// equals(allDocsResult2.rows.length, numDocs+1)
|
308
306
|
|
309
307
|
// console.time("open new DB");
|
310
|
-
const newDb =
|
308
|
+
const newDb = fireproof("test-benchmark", { autoCompact: 100000, public: true });
|
311
309
|
const doc = await newDb.get<{ foo: string }>("test");
|
312
310
|
expect(doc.foo).toBe("fast");
|
313
311
|
// console.timeEnd("open new DB");
|
@@ -337,7 +335,7 @@ describe("benchmarking a database", function () {
|
|
337
335
|
await db.put({ _id: "compacted-test", foo: "bar" });
|
338
336
|
|
339
337
|
// console.log('car log length', db._crdt.blockstore.loader.carLog.length)
|
340
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
338
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
341
339
|
const loader = blocks.loader;
|
342
340
|
expect(loader).toBeTruthy();
|
343
341
|
expect(loader.carLog.length).toBe(2);
|
@@ -349,10 +347,10 @@ describe("benchmarking a database", function () {
|
|
349
347
|
await sleep(100);
|
350
348
|
|
351
349
|
// console.time("compacted reopen again");
|
352
|
-
const newDb2 =
|
350
|
+
const newDb2 = fireproof("test-benchmark", { autoCompact: 100000, public: true });
|
353
351
|
const doc21 = await newDb2.get<FooType>("test");
|
354
352
|
expect(doc21.foo).toBe("fast");
|
355
|
-
const blocks2 = newDb2.crdt.blockstore as bs.EncryptedBlockstore;
|
353
|
+
const blocks2 = newDb2.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
356
354
|
const loader2 = blocks2.loader;
|
357
355
|
expect(loader2).toBeTruthy();
|
358
356
|
|
@@ -401,7 +399,7 @@ describe("benchmarking a database", function () {
|
|
401
399
|
}, 20000000);
|
402
400
|
});
|
403
401
|
|
404
|
-
describe("Reopening a
|
402
|
+
describe("Reopening a ledger", function () {
|
405
403
|
interface Doc {
|
406
404
|
foo: string;
|
407
405
|
}
|
@@ -415,13 +413,13 @@ describe("Reopening a database", function () {
|
|
415
413
|
// erase the existing test data
|
416
414
|
await sthis.start();
|
417
415
|
|
418
|
-
db =
|
416
|
+
db = fireproof("test-reopen", { autoCompact: 100000 });
|
419
417
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
420
418
|
expect(ok).toBeTruthy();
|
421
419
|
expect(ok.id).toBe("test");
|
422
420
|
|
423
|
-
expect(db.crdt.clock.head).toBeDefined();
|
424
|
-
expect(db.crdt.clock.head.length).toBe(1);
|
421
|
+
expect(db.ledger.crdt.clock.head).toBeDefined();
|
422
|
+
expect(db.ledger.crdt.clock.head.length).toBe(1);
|
425
423
|
});
|
426
424
|
|
427
425
|
it("should persist data", async function () {
|
@@ -430,18 +428,18 @@ describe("Reopening a database", function () {
|
|
430
428
|
});
|
431
429
|
|
432
430
|
it("should have the same data on reopen", async function () {
|
433
|
-
const db2 =
|
431
|
+
const db2 = fireproof("test-reopen");
|
434
432
|
const doc = await db2.get<FooType>("test");
|
435
433
|
expect(doc.foo).toBe("bar");
|
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);
|
434
|
+
expect(db2.ledger.crdt.clock.head).toBeDefined();
|
435
|
+
expect(db2.ledger.crdt.clock.head.length).toBe(1);
|
436
|
+
expect(db2.ledger.crdt.clock.head).toEqual(db.ledger.crdt.clock.head);
|
439
437
|
await db2.close();
|
440
438
|
});
|
441
439
|
|
442
440
|
it("should have a car in the car log", async function () {
|
443
|
-
await db.crdt.ready();
|
444
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
441
|
+
await db.ledger.crdt.ready();
|
442
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
445
443
|
const loader = blocks.loader;
|
446
444
|
expect(loader).toBeDefined();
|
447
445
|
expect(loader.carLog).toBeDefined();
|
@@ -449,9 +447,9 @@ describe("Reopening a database", function () {
|
|
449
447
|
});
|
450
448
|
|
451
449
|
it("should have carlog after reopen", async function () {
|
452
|
-
const db2 =
|
453
|
-
await db2.crdt.ready();
|
454
|
-
const blocks = db2.crdt.blockstore as bs.EncryptedBlockstore;
|
450
|
+
const db2 = fireproof("test-reopen");
|
451
|
+
await db2.ledger.crdt.ready();
|
452
|
+
const blocks = db2.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
455
453
|
const loader = blocks.loader;
|
456
454
|
expect(loader).toBeDefined();
|
457
455
|
expect(loader.carLog).toBeDefined();
|
@@ -462,10 +460,10 @@ describe("Reopening a database", function () {
|
|
462
460
|
it("faster, should have the same data on reopen after reopen and update", async function () {
|
463
461
|
for (let i = 0; i < 4; i++) {
|
464
462
|
// console.log('iteration', i)
|
465
|
-
const db =
|
463
|
+
const db = fireproof("test-reopen");
|
466
464
|
// assert(db._crdt.xready());
|
467
|
-
await db.
|
468
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
465
|
+
await db.ready();
|
466
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
469
467
|
const loader = blocks.loader;
|
470
468
|
expect(loader.carLog.length).toBe(i + 1);
|
471
469
|
const ok = await db.put({ _id: `test${i}`, fire: "proof".repeat(50 * 1024) });
|
@@ -481,11 +479,11 @@ describe("Reopening a database", function () {
|
|
481
479
|
for (let i = 0; i < 200; i++) {
|
482
480
|
// console.log("iteration", i);
|
483
481
|
// console.time("db open");
|
484
|
-
const db =
|
482
|
+
const db = fireproof("test-reopen", { autoCompact: 1000 }); // try with 10
|
485
483
|
// assert(db._crdt.ready);
|
486
|
-
await db.
|
484
|
+
await db.ready();
|
487
485
|
// console.timeEnd("db open");
|
488
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
486
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
489
487
|
const loader = blocks.loader;
|
490
488
|
expect(loader).toBeDefined();
|
491
489
|
expect(loader.carLog.length).toBe(i + 1);
|
@@ -503,7 +501,7 @@ describe("Reopening a database", function () {
|
|
503
501
|
}, 200000);
|
504
502
|
});
|
505
503
|
|
506
|
-
describe("Reopening a
|
504
|
+
describe("Reopening a ledger with indexes", function () {
|
507
505
|
interface Doc {
|
508
506
|
foo: string;
|
509
507
|
}
|
@@ -566,9 +564,9 @@ describe("Reopening a database with indexes", function () {
|
|
566
564
|
const db2 = fireproof("test-reopen-idx");
|
567
565
|
const doc = await db2.get<FooType>("test");
|
568
566
|
expect(doc.foo).toBe("bar");
|
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);
|
567
|
+
expect(db2.ledger.crdt.clock.head).toBeTruthy();
|
568
|
+
expect(db2.ledger.crdt.clock.head.length).toBe(1);
|
569
|
+
expect(db2.ledger.crdt.clock.head).toEqual(db.ledger.crdt.clock.head);
|
572
570
|
});
|
573
571
|
|
574
572
|
it("should have the same data on reopen after a query", async function () {
|
@@ -581,9 +579,9 @@ describe("Reopening a database with indexes", function () {
|
|
581
579
|
const db2 = fireproof("test-reopen-idx");
|
582
580
|
const doc = await db2.get<FooType>("test");
|
583
581
|
expect(doc.foo).toBe("bar");
|
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);
|
582
|
+
expect(db2.ledger.crdt.clock.head).toBeTruthy();
|
583
|
+
expect(db2.ledger.crdt.clock.head.length).toBe(1);
|
584
|
+
expect(db2.ledger.crdt.clock.head).toEqual(db.ledger.crdt.clock.head);
|
587
585
|
});
|
588
586
|
|
589
587
|
// it('should query the same data on reopen', async function () {
|
@@ -618,11 +616,11 @@ describe("basic js verify", function () {
|
|
618
616
|
expect(ok.id).toBe("test");
|
619
617
|
const ok2 = await db.put({ _id: "test2", foo: ["bar", "bam"] });
|
620
618
|
expect(ok2.id).toBe("test2");
|
621
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
619
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
622
620
|
const loader = blocks.loader;
|
623
621
|
expect(loader).toBeTruthy();
|
624
622
|
const cid = loader.carLog[0][0];
|
625
|
-
const cid2 = db.crdt.clock.head[0];
|
623
|
+
const cid2 = db.ledger.crdt.clock.head[0];
|
626
624
|
expect(cid).not.toBe(cid2);
|
627
625
|
expect(cid).not.toBe(cid2);
|
628
626
|
const cidList = [cid, cid2];
|
@@ -665,23 +663,23 @@ describe("same workload twice, same CID", function () {
|
|
665
663
|
beforeEach(async function () {
|
666
664
|
let ok: DocResponse;
|
667
665
|
await sthis.start();
|
668
|
-
// todo this fails because the test setup doesn't properly configure both
|
666
|
+
// todo this fails because the test setup doesn't properly configure both ledgers to use the same key
|
669
667
|
dbA = fireproof("test-dual-workload-a", configA);
|
670
668
|
for (const doc of docs) {
|
671
669
|
ok = await dbA.put(doc);
|
672
670
|
expect(ok).toBeTruthy();
|
673
671
|
expect(ok.id).toBeTruthy();
|
674
672
|
}
|
675
|
-
headA = dbA.crdt.clock.head.toString();
|
673
|
+
headA = dbA.ledger.crdt.clock.head.toString();
|
676
674
|
|
677
|
-
// todo this fails because the test setup doesn't properly configure both
|
675
|
+
// todo this fails because the test setup doesn't properly configure both ledgers to use the same key
|
678
676
|
dbB = fireproof("test-dual-workload-b", configB);
|
679
677
|
for (const doc of docs) {
|
680
678
|
ok = await dbB.put(doc);
|
681
679
|
expect(ok).toBeTruthy();
|
682
680
|
expect(ok.id).toBeTruthy();
|
683
681
|
}
|
684
|
-
headB = dbB.crdt.clock.head.toString();
|
682
|
+
headB = dbB.ledger.crdt.clock.head.toString();
|
685
683
|
});
|
686
684
|
it("should have head A and B", async function () {
|
687
685
|
expect(headA).toBeTruthy();
|
@@ -690,12 +688,12 @@ describe("same workload twice, same CID", function () {
|
|
690
688
|
expect(headA.length).toBeGreaterThan(10);
|
691
689
|
});
|
692
690
|
it("should have same car log", async function () {
|
693
|
-
const logA = dbA.crdt.blockstore.loader?.carLog;
|
691
|
+
const logA = dbA.ledger.crdt.blockstore.loader?.carLog;
|
694
692
|
expect(logA).toBeTruthy();
|
695
693
|
assert(logA);
|
696
694
|
expect(logA.length).toBe(docs.length);
|
697
695
|
|
698
|
-
const logB = dbB.crdt.blockstore.loader?.carLog;
|
696
|
+
const logB = dbB.ledger.crdt.blockstore.loader?.carLog;
|
699
697
|
expect(logB).toBeTruthy();
|
700
698
|
assert(logB);
|
701
699
|
expect(logB.length).toBe(docs.length);
|
@@ -705,19 +703,19 @@ describe("same workload twice, same CID", function () {
|
|
705
703
|
|
706
704
|
expect(logA2.length).toBe(logB2.length);
|
707
705
|
|
708
|
-
// todo this fails because the test setup doesn't properly configure both
|
706
|
+
// todo this fails because the test setup doesn't properly configure both ledgers to use the same key
|
709
707
|
// expect(logA2).toEqual(logB2);
|
710
708
|
});
|
711
709
|
it("should have same car log after compact", async function () {
|
712
710
|
await dbA.compact();
|
713
711
|
await dbB.compact();
|
714
712
|
|
715
|
-
const cmpLogA = dbA.crdt.blockstore.loader?.carLog;
|
713
|
+
const cmpLogA = dbA.ledger.crdt.blockstore.loader?.carLog;
|
716
714
|
expect(cmpLogA).toBeTruthy();
|
717
715
|
assert(cmpLogA);
|
718
716
|
expect(cmpLogA.length).toBe(1);
|
719
717
|
|
720
|
-
const cmpLogB = dbB.crdt.blockstore.loader?.carLog;
|
718
|
+
const cmpLogB = dbB.ledger.crdt.blockstore.loader?.carLog;
|
721
719
|
expect(cmpLogB).toBeTruthy();
|
722
720
|
assert(cmpLogB);
|
723
721
|
expect(cmpLogB.length).toBe(1);
|
@@ -727,7 +725,7 @@ describe("same workload twice, same CID", function () {
|
|
727
725
|
|
728
726
|
expect(cmpLogA2.length).toBe(cmpLogB2.length);
|
729
727
|
|
730
|
-
// todo this fails because the test setup doesn't properly configure both
|
728
|
+
// todo this fails because the test setup doesn't properly configure both ledgers to use the same key
|
731
729
|
// expect(cmpLogA2).toEqual(cmpLogB2);
|
732
730
|
});
|
733
731
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { fireproof,
|
1
|
+
import { fireproof, DocResponse, DocWithId, index, Database, isDatabase } from "@fireproof/core";
|
2
2
|
import { mockSuperThis } from "../helpers.js";
|
3
3
|
|
4
4
|
describe("Hello World Test", function () {
|
@@ -28,7 +28,7 @@ describe("hello public API", () => {
|
|
28
28
|
ok = await db.put({ _id: "test", foo: "bar" });
|
29
29
|
doc = await db.get("test");
|
30
30
|
});
|
31
|
-
it("should have a
|
31
|
+
it("should have a ledger", function () {
|
32
32
|
expect(db).toBeTruthy();
|
33
33
|
expect(isDatabase(db)).toBeTruthy();
|
34
34
|
});
|
@@ -47,7 +47,7 @@ describe("hello public API", () => {
|
|
47
47
|
});
|
48
48
|
});
|
49
49
|
|
50
|
-
describe("Simplified Reopening a
|
50
|
+
describe("Simplified Reopening a ledger", function () {
|
51
51
|
let db: Database;
|
52
52
|
afterEach(async function () {
|
53
53
|
await db.close();
|
@@ -1,16 +1,17 @@
|
|
1
1
|
import {
|
2
2
|
Index,
|
3
3
|
index,
|
4
|
-
Database,
|
5
4
|
CRDT,
|
6
5
|
IndexRows,
|
7
6
|
toStoreURIRuntime,
|
8
7
|
bs,
|
9
8
|
rt,
|
10
|
-
DatabaseFactory,
|
11
9
|
defaultWriteQueueOpts,
|
12
10
|
ensureSuperThis,
|
13
|
-
|
11
|
+
LedgerOpts,
|
12
|
+
Database,
|
13
|
+
CRDTImpl,
|
14
|
+
fireproof,
|
14
15
|
} from "@fireproof/core";
|
15
16
|
|
16
17
|
interface TestType {
|
@@ -19,7 +20,7 @@ interface TestType {
|
|
19
20
|
}
|
20
21
|
|
21
22
|
describe("basic Index", () => {
|
22
|
-
let db: Database
|
23
|
+
let db: Database;
|
23
24
|
let indexer: Index<string, TestType>;
|
24
25
|
let didMap: boolean;
|
25
26
|
const sthis = ensureSuperThis();
|
@@ -31,18 +32,18 @@ describe("basic Index", () => {
|
|
31
32
|
});
|
32
33
|
beforeEach(async function () {
|
33
34
|
await sthis.start();
|
34
|
-
db =
|
35
|
+
db = fireproof("test-indexer");
|
35
36
|
await db.put({ title: "amazing" });
|
36
37
|
await db.put({ title: "creative" });
|
37
38
|
await db.put({ title: "bazillas" });
|
38
|
-
indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
|
39
|
+
indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "hello", (doc) => {
|
39
40
|
didMap = true;
|
40
41
|
return doc.title;
|
41
42
|
});
|
42
43
|
await indexer.ready();
|
43
44
|
});
|
44
45
|
it("should have properties", function () {
|
45
|
-
expect(indexer.crdt).toBe(db.crdt);
|
46
|
+
expect(indexer.crdt).toBe(db.ledger.crdt);
|
46
47
|
// expect(indexer.crdt.name).toBe("test-indexer");
|
47
48
|
expect(indexer.name).toBe("hello");
|
48
49
|
expect(indexer.mapFn).toBeTruthy();
|
@@ -107,7 +108,7 @@ describe("basic Index", () => {
|
|
107
108
|
});
|
108
109
|
|
109
110
|
describe("Index query with compound key", function () {
|
110
|
-
let db: Database
|
111
|
+
let db: Database;
|
111
112
|
let indexer: Index<[string, number], TestType>;
|
112
113
|
const sthis = ensureSuperThis();
|
113
114
|
afterEach(async function () {
|
@@ -118,12 +119,12 @@ describe("Index query with compound key", function () {
|
|
118
119
|
});
|
119
120
|
beforeEach(async function () {
|
120
121
|
await sthis.start();
|
121
|
-
db =
|
122
|
+
db = fireproof("test-indexer");
|
122
123
|
await db.put({ title: "amazing", score: 1 });
|
123
124
|
await db.put({ title: "creative", score: 2 });
|
124
125
|
await db.put({ title: "creative", score: 20 });
|
125
126
|
await db.put({ title: "bazillas", score: 3 });
|
126
|
-
indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc) => {
|
127
|
+
indexer = new Index<[string, number], TestType>(sthis, db.ledger.crdt, "hello", (doc) => {
|
127
128
|
return [doc.title, doc.score];
|
128
129
|
});
|
129
130
|
await indexer.ready();
|
@@ -137,7 +138,7 @@ describe("Index query with compound key", function () {
|
|
137
138
|
});
|
138
139
|
|
139
140
|
describe("basic Index with map fun", function () {
|
140
|
-
let db: Database
|
141
|
+
let db: Database;
|
141
142
|
let indexer: Index<string, TestType>;
|
142
143
|
const sthis = ensureSuperThis();
|
143
144
|
afterEach(async function () {
|
@@ -148,11 +149,11 @@ describe("basic Index with map fun", function () {
|
|
148
149
|
});
|
149
150
|
beforeEach(async function () {
|
150
151
|
await sthis.start();
|
151
|
-
db =
|
152
|
+
db = fireproof("test-indexer");
|
152
153
|
await db.put({ title: "amazing" });
|
153
154
|
await db.put({ title: "creative" });
|
154
155
|
await db.put({ title: "bazillas" });
|
155
|
-
indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc, map) => {
|
156
|
+
indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "hello", (doc, map) => {
|
156
157
|
map(doc.title);
|
157
158
|
});
|
158
159
|
await indexer.ready();
|
@@ -167,7 +168,7 @@ describe("basic Index with map fun", function () {
|
|
167
168
|
});
|
168
169
|
|
169
170
|
describe("basic Index with map fun with value", function () {
|
170
|
-
let db: Database
|
171
|
+
let db: Database;
|
171
172
|
let indexer: Index<string, TestType, number>;
|
172
173
|
const sthis = ensureSuperThis();
|
173
174
|
afterEach(async function () {
|
@@ -176,11 +177,11 @@ describe("basic Index with map fun with value", function () {
|
|
176
177
|
});
|
177
178
|
beforeEach(async function () {
|
178
179
|
await sthis.start();
|
179
|
-
db =
|
180
|
+
db = fireproof("test-indexer");
|
180
181
|
await db.put({ title: "amazing" });
|
181
182
|
await db.put({ title: "creative" });
|
182
183
|
await db.put({ title: "bazillas" });
|
183
|
-
indexer = new Index<string, TestType, number>(sthis, db.crdt, "hello", (doc, map) => {
|
184
|
+
indexer = new Index<string, TestType, number>(sthis, db.ledger.crdt, "hello", (doc, map) => {
|
184
185
|
map(doc.title, doc.title.length);
|
185
186
|
});
|
186
187
|
});
|
@@ -205,7 +206,7 @@ describe("basic Index with map fun with value", function () {
|
|
205
206
|
});
|
206
207
|
|
207
208
|
describe("Index query with map and compound key", function () {
|
208
|
-
let db: Database
|
209
|
+
let db: Database;
|
209
210
|
let indexer: Index<[string, number], TestType>;
|
210
211
|
const sthis = ensureSuperThis();
|
211
212
|
afterEach(async function () {
|
@@ -216,12 +217,12 @@ describe("Index query with map and compound key", function () {
|
|
216
217
|
});
|
217
218
|
beforeEach(async function () {
|
218
219
|
await sthis.start();
|
219
|
-
db =
|
220
|
+
db = fireproof("test-indexer");
|
220
221
|
await db.put({ title: "amazing", score: 1 });
|
221
222
|
await db.put({ title: "creative", score: 2 });
|
222
223
|
await db.put({ title: "creative", score: 20 });
|
223
224
|
await db.put({ title: "bazillas", score: 3 });
|
224
|
-
indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc, emit) => {
|
225
|
+
indexer = new Index<[string, number], TestType>(sthis, db.ledger.crdt, "hello", (doc, emit) => {
|
225
226
|
emit([doc.title, doc.score]);
|
226
227
|
});
|
227
228
|
await indexer.ready();
|
@@ -235,7 +236,7 @@ describe("Index query with map and compound key", function () {
|
|
235
236
|
});
|
236
237
|
|
237
238
|
describe("basic Index with string fun", function () {
|
238
|
-
let db: Database
|
239
|
+
let db: Database;
|
239
240
|
let indexer: Index<string, TestType>;
|
240
241
|
const sthis = ensureSuperThis();
|
241
242
|
afterEach(async function () {
|
@@ -246,11 +247,11 @@ describe("basic Index with string fun", function () {
|
|
246
247
|
});
|
247
248
|
beforeEach(async function () {
|
248
249
|
await sthis.start();
|
249
|
-
db =
|
250
|
+
db = fireproof("test-indexer");
|
250
251
|
await db.put({ title: "amazing" });
|
251
252
|
await db.put({ title: "creative" });
|
252
253
|
await db.put({ title: "bazillas" });
|
253
|
-
indexer = new Index(sthis, db.crdt, "title");
|
254
|
+
indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "title");
|
254
255
|
await indexer.ready();
|
255
256
|
});
|
256
257
|
it("should get results", async function () {
|
@@ -271,13 +272,13 @@ describe("basic Index upon cold start", function () {
|
|
271
272
|
title: string;
|
272
273
|
score?: number;
|
273
274
|
}
|
274
|
-
let crdt: CRDT
|
275
|
+
let crdt: CRDT;
|
275
276
|
let indexer: Index<string, TestType>;
|
276
277
|
let didMap: number;
|
277
278
|
let mapFn: (doc: TestType) => string;
|
278
279
|
let result: IndexRows<string, TestType>;
|
279
280
|
const sthis = ensureSuperThis();
|
280
|
-
let dbOpts:
|
281
|
+
let dbOpts: LedgerOpts;
|
281
282
|
// result, mapFn;
|
282
283
|
afterEach(async function () {
|
283
284
|
await crdt.close();
|
@@ -295,7 +296,7 @@ describe("basic Index upon cold start", function () {
|
|
295
296
|
storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"),
|
296
297
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
297
298
|
};
|
298
|
-
crdt = new
|
299
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
299
300
|
await crdt.bulk([
|
300
301
|
{ id: "abc1", value: { title: "amazing" } },
|
301
302
|
{ id: "abc2", value: { title: "creative" } },
|
@@ -307,7 +308,7 @@ describe("basic Index upon cold start", function () {
|
|
307
308
|
didMap++;
|
308
309
|
return doc.title;
|
309
310
|
};
|
310
|
-
indexer = await index<string, TestType>(
|
311
|
+
indexer = await index<string, TestType>(crdt, "hello", mapFn);
|
311
312
|
logger.Debug().Msg("post index beforeEach");
|
312
313
|
await indexer.ready();
|
313
314
|
logger.Debug().Msg("post indexer.ready beforeEach");
|
@@ -327,12 +328,12 @@ describe("basic Index upon cold start", function () {
|
|
327
328
|
expect(result.rows.length).toEqual(3);
|
328
329
|
});
|
329
330
|
it("should work on cold load", async function () {
|
330
|
-
const crdt2 = new
|
331
|
+
const crdt2 = new CRDTImpl(sthis, dbOpts);
|
331
332
|
await crdt2.ready();
|
332
333
|
const { result, head } = await crdt2.changes();
|
333
334
|
expect(result).toBeTruthy();
|
334
335
|
await crdt2.ready();
|
335
|
-
const indexer2 = await index<string, TestType>(
|
336
|
+
const indexer2 = await index<string, TestType>(crdt2, "hello", mapFn);
|
336
337
|
await indexer2.ready();
|
337
338
|
const result2 = await indexer2.query();
|
338
339
|
expect(indexer2.indexHead).toEqual(head);
|
@@ -342,8 +343,8 @@ describe("basic Index upon cold start", function () {
|
|
342
343
|
});
|
343
344
|
it.skip("should not rerun the map function on seen changes", async function () {
|
344
345
|
didMap = 0;
|
345
|
-
const crdt2 = new
|
346
|
-
const indexer2 = await index(
|
346
|
+
const crdt2 = new CRDTImpl(sthis, dbOpts);
|
347
|
+
const indexer2 = await index(crdt2, "hello", mapFn);
|
347
348
|
const { result, head } = await crdt2.changes([]);
|
348
349
|
expect(result.length).toEqual(3);
|
349
350
|
expect(head.length).toEqual(1);
|
@@ -367,15 +368,15 @@ describe("basic Index upon cold start", function () {
|
|
367
368
|
expect(didMap).toEqual(1);
|
368
369
|
});
|
369
370
|
it("should ignore meta when map function definiton changes", async function () {
|
370
|
-
const crdt2 = new
|
371
|
-
const result = await index<string, TestType>(
|
371
|
+
const crdt2 = new CRDTImpl(sthis, dbOpts);
|
372
|
+
const result = await index<string, TestType>(crdt2, "hello", (doc) => doc.title.split("").reverse().join("")).query();
|
372
373
|
expect(result.rows.length).toEqual(3);
|
373
374
|
expect(result.rows[0].key).toEqual("evitaerc"); // creative
|
374
375
|
});
|
375
376
|
});
|
376
377
|
|
377
378
|
describe("basic Index with no data", function () {
|
378
|
-
let db: Database
|
379
|
+
let db: Database;
|
379
380
|
let indexer: Index<string, TestType>;
|
380
381
|
let didMap: boolean;
|
381
382
|
const sthis = ensureSuperThis();
|
@@ -387,15 +388,15 @@ describe("basic Index with no data", function () {
|
|
387
388
|
});
|
388
389
|
beforeEach(async function () {
|
389
390
|
await sthis.start();
|
390
|
-
db =
|
391
|
-
indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
|
391
|
+
db = fireproof("test-indexer");
|
392
|
+
indexer = new Index<string, TestType>(sthis, db.ledger.crdt, "hello", (doc) => {
|
392
393
|
didMap = true;
|
393
394
|
return doc.title;
|
394
395
|
});
|
395
396
|
await indexer.ready();
|
396
397
|
});
|
397
398
|
it("should have properties", function () {
|
398
|
-
expect(indexer.crdt).toEqual(db.crdt);
|
399
|
+
expect(indexer.crdt).toEqual(db.ledger.crdt);
|
399
400
|
expect(indexer.name).toEqual("hello");
|
400
401
|
expect(indexer.mapFn).toBeTruthy();
|
401
402
|
});
|