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

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.
Files changed (103) hide show
  1. package/README.md +13 -12
  2. package/deno/index.d.ts +7 -0
  3. package/deno/index.js +66 -0
  4. package/deno/index.js.map +1 -0
  5. package/deno/metafile-esm.json +1 -0
  6. package/deno.json +3 -4
  7. package/index.cjs +1797 -1431
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +760 -381
  10. package/index.d.ts +760 -381
  11. package/index.js +1976 -913
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/{node-filesystem.cjs → index.cjs} +17 -6
  16. package/node/index.cjs.map +1 -0
  17. package/node/index.d.cts +7 -0
  18. package/node/index.d.ts +7 -0
  19. package/node/{node-filesystem.js → index.js} +25 -5
  20. package/node/index.js.map +1 -0
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +27 -17
  24. package/react/index.cjs +22 -22
  25. package/react/index.cjs.map +1 -1
  26. package/react/index.d.cts +7 -7
  27. package/react/index.d.ts +7 -7
  28. package/react/index.js +22 -22
  29. package/react/index.js.map +1 -1
  30. package/react/metafile-cjs.json +1 -1
  31. package/react/metafile-esm.json +1 -1
  32. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  33. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  34. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  35. package/tests/blockstore/keyed-crypto.test.ts +75 -118
  36. package/tests/blockstore/loader.test.ts +18 -9
  37. package/tests/blockstore/store.test.ts +40 -31
  38. package/tests/blockstore/transaction.test.ts +14 -13
  39. package/tests/fireproof/all-gateway.test.ts +286 -216
  40. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  41. package/tests/fireproof/crdt.test.ts +78 -19
  42. package/tests/fireproof/fireproof.test.ts +111 -92
  43. package/tests/fireproof/hello.test.ts +21 -17
  44. package/tests/fireproof/indexer.test.ts +74 -50
  45. package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
  46. package/tests/fireproof/multiple-ledger.test.ts +2 -2
  47. package/tests/fireproof/utils.test.ts +47 -6
  48. package/tests/gateway/file/loader-config.test.ts +307 -0
  49. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  50. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  51. package/tests/helpers.ts +44 -17
  52. package/tests/react/useFireproof.test.tsx +2 -2
  53. package/tests/www/gallery.html +2 -2
  54. package/tests/www/todo-aws.html +1 -1
  55. package/tests/www/todo-ipfs.html +1 -1
  56. package/tests/www/todo-local.html +1 -1
  57. package/tests/www/todo.html +25 -4
  58. package/web/index.cjs +218 -0
  59. package/web/index.cjs.map +1 -0
  60. package/web/index.d.cts +30 -0
  61. package/web/index.d.ts +30 -0
  62. package/web/index.js +195 -0
  63. package/web/index.js.map +1 -0
  64. package/web/metafile-cjs.json +1 -1
  65. package/web/metafile-esm.json +1 -1
  66. package/chunk-7EWIAXTM.js +0 -7
  67. package/chunk-7EWIAXTM.js.map +0 -1
  68. package/chunk-F4FC6B2T.js +0 -63
  69. package/chunk-F4FC6B2T.js.map +0 -1
  70. package/chunk-PZ5AY32C.js +0 -10
  71. package/chunk-PZ5AY32C.js.map +0 -1
  72. package/chunk-RXC4JGJT.js +0 -301
  73. package/chunk-RXC4JGJT.js.map +0 -1
  74. package/gateway-C62S56GY.js +0 -66
  75. package/gateway-C62S56GY.js.map +0 -1
  76. package/gateway-VVS4QWDA.js +0 -145
  77. package/gateway-VVS4QWDA.js.map +0 -1
  78. package/key-bag-file-PWZ3QE7B.js +0 -55
  79. package/key-bag-file-PWZ3QE7B.js.map +0 -1
  80. package/key-bag-indexdb-SYG3YD4D.js +0 -51
  81. package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
  82. package/node/chunk-4A4RAVNS.js +0 -17
  83. package/node/chunk-4A4RAVNS.js.map +0 -1
  84. package/node/mem-filesystem.cjs +0 -72
  85. package/node/mem-filesystem.cjs.map +0 -1
  86. package/node/mem-filesystem.d.cts +0 -25
  87. package/node/mem-filesystem.d.ts +0 -25
  88. package/node/mem-filesystem.js +0 -40
  89. package/node/mem-filesystem.js.map +0 -1
  90. package/node/node-filesystem.cjs.map +0 -1
  91. package/node/node-filesystem.d.cts +0 -35
  92. package/node/node-filesystem.d.ts +0 -35
  93. package/node/node-filesystem.js.map +0 -1
  94. package/tests/fireproof/config.test.ts +0 -172
  95. package/utils-ZVVGAXFE.js +0 -13
  96. package/utils-ZVVGAXFE.js.map +0 -1
  97. package/web/gateway-impl.cjs +0 -183
  98. package/web/gateway-impl.cjs.map +0 -1
  99. package/web/gateway-impl.d.cts +0 -31
  100. package/web/gateway-impl.d.ts +0 -31
  101. package/web/gateway-impl.js +0 -162
  102. package/web/gateway-impl.js.map +0 -1
  103. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
@@ -1,8 +1,22 @@
1
- import { sleep } from "../helpers.js";
1
+ import { sleep, storageURL } from "../helpers.js";
2
2
  import { docs } from "./fireproof.test.fixture.js";
3
3
  import { CID } from "multiformats/cid";
4
4
 
5
- import { Database, DocResponse, DocWithId, Index, IndexRows, MapFn, bs, ensureSuperThis, fireproof, index } from "@fireproof/core";
5
+ import {
6
+ ConfigOpts,
7
+ Ledger,
8
+ LedgerFactory,
9
+ DocResponse,
10
+ DocWithId,
11
+ Index,
12
+ IndexRows,
13
+ MapFn,
14
+ bs,
15
+ fireproof,
16
+ index,
17
+ isLedger,
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));
@@ -24,7 +38,7 @@ describe("dreamcode", function () {
24
38
  let ok: DocResponse;
25
39
  let doc: DocWithId<Doc>;
26
40
  let result: IndexRows<string, Doc>;
27
- let db: Database;
41
+ let db: Ledger;
28
42
  const sthis = ensureSuperThis();
29
43
  afterEach(async function () {
30
44
  await db.close();
@@ -63,7 +77,7 @@ describe("public API", function () {
63
77
  interface Doc {
64
78
  foo: string;
65
79
  }
66
- let db: Database;
80
+ let db: Ledger;
67
81
  let ok: DocResponse;
68
82
  let doc: DocWithId<Doc>;
69
83
  let query: IndexRows<string, Doc>;
@@ -82,9 +96,9 @@ describe("public API", function () {
82
96
  doc = await db.get("test");
83
97
  query = await db.query<string, Doc>((doc) => doc.foo);
84
98
  });
85
- it("should be a database instance", function () {
99
+ it("should be a ledger instance", function () {
86
100
  expect(db).toBeTruthy();
87
- expect(db instanceof Database).toBeTruthy();
101
+ expect(isLedger(db)).toBeTruthy();
88
102
  });
89
103
  it("should put", function () {
90
104
  expect(ok).toBeTruthy();
@@ -101,11 +115,11 @@ describe("public API", function () {
101
115
  });
102
116
  });
103
117
 
104
- describe("basic database", function () {
118
+ describe("basic ledger", function () {
105
119
  interface Doc {
106
120
  foo: string;
107
121
  }
108
- let db: Database<Doc>;
122
+ let db: Ledger<Doc>;
109
123
  const sthis = ensureSuperThis();
110
124
  afterEach(async function () {
111
125
  await db.close();
@@ -113,7 +127,7 @@ describe("basic database", function () {
113
127
  });
114
128
  beforeEach(async function () {
115
129
  await sthis.start();
116
- db = new Database("test-basic");
130
+ db = LedgerFactory("test-basic");
117
131
  });
118
132
  it("can put with id", async function () {
119
133
  const ok = await db.put({ _id: "test", foo: "bar" });
@@ -126,10 +140,19 @@ describe("basic database", function () {
126
140
  const got = await db.get<Doc>(ok.id);
127
141
  expect(got.foo).toBe("bam");
128
142
  });
143
+ it("can bulk an array", async function () {
144
+ const ok = await db.bulk([{ foo: "cool" }, { foo: "dude" }]);
145
+ expect(ok).toBeTruthy();
146
+ expect(ok.ids.length).toBe(2);
147
+ const got = await db.get<Doc>(ok.ids[0]);
148
+ expect(got.foo).toBe("cool");
149
+ const got2 = await db.get<Doc>(ok.ids[1]);
150
+ expect(got2.foo).toBe("dude");
151
+ });
129
152
  it("can define an index", async function () {
130
153
  const ok = await db.put({ _id: "test", foo: "bar" });
131
154
  expect(ok).toBeTruthy();
132
- const idx = index<string, { foo: string }>(sthis, db, "test-index", (doc) => doc.foo);
155
+ const idx = index<string, { foo: string }>(db, "test-index", (doc) => doc.foo);
133
156
  const result = await idx.query();
134
157
  expect(result).toBeTruthy();
135
158
  expect(result.rows).toBeTruthy();
@@ -139,7 +162,7 @@ describe("basic database", function () {
139
162
  it("can define an index with a default function", async function () {
140
163
  const ok = await db.put({ _id: "test", foo: "bar" });
141
164
  expect(ok).toBeTruthy();
142
- const idx = index(sthis, db, "foo");
165
+ const idx = index(db, "foo");
143
166
  const result = await idx.query();
144
167
  expect(result).toBeTruthy();
145
168
  expect(result.rows).toBeTruthy();
@@ -169,7 +192,7 @@ describe("basic database", function () {
169
192
  });
170
193
 
171
194
  describe("benchmarking with compaction", function () {
172
- let db: Database;
195
+ let db: Ledger;
173
196
  const sthis = ensureSuperThis();
174
197
  afterEach(async function () {
175
198
  await db.close();
@@ -178,14 +201,14 @@ describe("benchmarking with compaction", function () {
178
201
  beforeEach(async function () {
179
202
  // erase the existing test data
180
203
  await sthis.start();
181
- db = new Database("test-benchmark-compaction", { autoCompact: 3 });
204
+ db = LedgerFactory("test-benchmark-compaction", { autoCompact: 3 });
182
205
  });
183
- it("insert during compaction", async function () {
206
+ it.skip("insert during compaction", async function () {
184
207
  const ok = await db.put({ _id: "test", foo: "fast" });
185
208
  expect(ok).toBeTruthy();
186
209
  expect(ok.id).toBe("test");
187
- expect(db._crdt.clock.head).toBeTruthy();
188
- expect(db._crdt.clock.head.length).toBe(1);
210
+ expect(db.crdt.clock.head).toBeTruthy();
211
+ expect(db.crdt.clock.head.length).toBe(1);
189
212
 
190
213
  const numDocs = 20;
191
214
  const batchSize = 5;
@@ -206,7 +229,7 @@ describe("benchmarking with compaction", function () {
206
229
  }),
207
230
  );
208
231
  }
209
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
232
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
210
233
  const loader = blocks.loader;
211
234
  expect(loader).toBeTruthy();
212
235
 
@@ -222,9 +245,9 @@ describe("benchmarking with compaction", function () {
222
245
  });
223
246
  });
224
247
 
225
- describe("benchmarking a database", function () {
226
- /** @type {Database} */
227
- let db: Database;
248
+ describe("benchmarking a ledger", function () {
249
+ /** @type {Ledger} */
250
+ let db: Ledger;
228
251
  const sthis = ensureSuperThis();
229
252
  afterEach(async function () {
230
253
  await db.close();
@@ -233,8 +256,8 @@ describe("benchmarking a database", function () {
233
256
  beforeEach(async function () {
234
257
  await sthis.start();
235
258
  // erase the existing test data
236
- db = new Database("test-benchmark", { autoCompact: 100000, public: true });
237
- // db = new Database(null, {autoCompact: 100000})
259
+ db = LedgerFactory("test-benchmark", { autoCompact: 100000, public: true });
260
+ // db = LedgerFactory(null, {autoCompact: 100000})
238
261
  });
239
262
 
240
263
  // run benchmarking tests
@@ -247,8 +270,8 @@ describe("benchmarking a database", function () {
247
270
  expect(ok).toBeTruthy();
248
271
  expect(ok.id).toBe("test");
249
272
 
250
- expect(db._crdt.clock.head).toBeTruthy();
251
- expect(db._crdt.clock.head.length).toBe(1);
273
+ expect(db.crdt.clock.head).toBeTruthy();
274
+ expect(db.crdt.clock.head.length).toBe(1);
252
275
 
253
276
  const numDocs = 2500;
254
277
  const batchSize = 500;
@@ -284,7 +307,7 @@ describe("benchmarking a database", function () {
284
307
  // equals(allDocsResult2.rows.length, numDocs+1)
285
308
 
286
309
  // console.time("open new DB");
287
- const newDb = new Database("test-benchmark", { autoCompact: 100000, public: true });
310
+ const newDb = LedgerFactory("test-benchmark", { autoCompact: 100000, public: true });
288
311
  const doc = await newDb.get<{ foo: string }>("test");
289
312
  expect(doc.foo).toBe("fast");
290
313
  // console.timeEnd("open new DB");
@@ -314,7 +337,7 @@ describe("benchmarking a database", function () {
314
337
  await db.put({ _id: "compacted-test", foo: "bar" });
315
338
 
316
339
  // console.log('car log length', db._crdt.blockstore.loader.carLog.length)
317
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
340
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
318
341
  const loader = blocks.loader;
319
342
  expect(loader).toBeTruthy();
320
343
  expect(loader.carLog.length).toBe(2);
@@ -326,10 +349,10 @@ describe("benchmarking a database", function () {
326
349
  await sleep(100);
327
350
 
328
351
  // console.time("compacted reopen again");
329
- const newDb2 = new Database("test-benchmark", { autoCompact: 100000, public: true });
352
+ const newDb2 = LedgerFactory("test-benchmark", { autoCompact: 100000, public: true });
330
353
  const doc21 = await newDb2.get<FooType>("test");
331
354
  expect(doc21.foo).toBe("fast");
332
- const blocks2 = newDb2._crdt.blockstore as bs.EncryptedBlockstore;
355
+ const blocks2 = newDb2.crdt.blockstore as bs.EncryptedBlockstore;
333
356
  const loader2 = blocks2.loader;
334
357
  expect(loader2).toBeTruthy();
335
358
 
@@ -378,11 +401,11 @@ describe("benchmarking a database", function () {
378
401
  }, 20000000);
379
402
  });
380
403
 
381
- describe("Reopening a database", function () {
404
+ describe("Reopening a ledger", function () {
382
405
  interface Doc {
383
406
  foo: string;
384
407
  }
385
- let db: Database;
408
+ let db: Ledger;
386
409
  const sthis = ensureSuperThis();
387
410
  afterEach(async function () {
388
411
  await db.close();
@@ -392,13 +415,13 @@ describe("Reopening a database", function () {
392
415
  // erase the existing test data
393
416
  await sthis.start();
394
417
 
395
- db = new Database("test-reopen", { autoCompact: 100000 });
418
+ db = LedgerFactory("test-reopen", { autoCompact: 100000 });
396
419
  const ok = await db.put({ _id: "test", foo: "bar" });
397
420
  expect(ok).toBeTruthy();
398
421
  expect(ok.id).toBe("test");
399
422
 
400
- expect(db._crdt.clock.head).toBeDefined();
401
- expect(db._crdt.clock.head.length).toBe(1);
423
+ expect(db.crdt.clock.head).toBeDefined();
424
+ expect(db.crdt.clock.head.length).toBe(1);
402
425
  });
403
426
 
404
427
  it("should persist data", async function () {
@@ -407,18 +430,18 @@ describe("Reopening a database", function () {
407
430
  });
408
431
 
409
432
  it("should have the same data on reopen", async function () {
410
- const db2 = new Database("test-reopen");
433
+ const db2 = LedgerFactory("test-reopen");
411
434
  const doc = await db2.get<FooType>("test");
412
435
  expect(doc.foo).toBe("bar");
413
- expect(db2._crdt.clock.head).toBeDefined();
414
- expect(db2._crdt.clock.head.length).toBe(1);
415
- expect(db2._crdt.clock.head).toEqual(db._crdt.clock.head);
436
+ expect(db2.crdt.clock.head).toBeDefined();
437
+ expect(db2.crdt.clock.head.length).toBe(1);
438
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
416
439
  await db2.close();
417
440
  });
418
441
 
419
442
  it("should have a car in the car log", async function () {
420
- await db._crdt.ready();
421
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
443
+ await db.crdt.ready();
444
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
422
445
  const loader = blocks.loader;
423
446
  expect(loader).toBeDefined();
424
447
  expect(loader.carLog).toBeDefined();
@@ -426,9 +449,9 @@ describe("Reopening a database", function () {
426
449
  });
427
450
 
428
451
  it("should have carlog after reopen", async function () {
429
- const db2 = new Database("test-reopen");
430
- await db2._crdt.ready();
431
- const blocks = db2._crdt.blockstore as bs.EncryptedBlockstore;
452
+ const db2 = LedgerFactory("test-reopen");
453
+ await db2.crdt.ready();
454
+ const blocks = db2.crdt.blockstore as bs.EncryptedBlockstore;
432
455
  const loader = blocks.loader;
433
456
  expect(loader).toBeDefined();
434
457
  expect(loader.carLog).toBeDefined();
@@ -439,10 +462,10 @@ describe("Reopening a database", function () {
439
462
  it("faster, should have the same data on reopen after reopen and update", async function () {
440
463
  for (let i = 0; i < 4; i++) {
441
464
  // console.log('iteration', i)
442
- const db = new Database("test-reopen");
465
+ const db = LedgerFactory("test-reopen");
443
466
  // assert(db._crdt.xready());
444
- await db._crdt.ready();
445
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
467
+ await db.crdt.ready();
468
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
446
469
  const loader = blocks.loader;
447
470
  expect(loader.carLog.length).toBe(i + 1);
448
471
  const ok = await db.put({ _id: `test${i}`, fire: "proof".repeat(50 * 1024) });
@@ -458,11 +481,11 @@ describe("Reopening a database", function () {
458
481
  for (let i = 0; i < 200; i++) {
459
482
  // console.log("iteration", i);
460
483
  // console.time("db open");
461
- const db = new Database("test-reopen", { autoCompact: 1000 }); // try with 10
484
+ const db = LedgerFactory("test-reopen", { autoCompact: 1000 }); // try with 10
462
485
  // assert(db._crdt.ready);
463
- await db._crdt.ready();
486
+ await db.crdt.ready();
464
487
  // console.timeEnd("db open");
465
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
488
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
466
489
  const loader = blocks.loader;
467
490
  expect(loader).toBeDefined();
468
491
  expect(loader.carLog.length).toBe(i + 1);
@@ -480,11 +503,11 @@ describe("Reopening a database", function () {
480
503
  }, 200000);
481
504
  });
482
505
 
483
- describe("Reopening a database with indexes", function () {
506
+ describe("Reopening a ledger with indexes", function () {
484
507
  interface Doc {
485
508
  foo: string;
486
509
  }
487
- let db: Database;
510
+ let db: Ledger;
488
511
  let idx: Index<string, Doc>;
489
512
  let didMap: boolean;
490
513
  let mapFn: MapFn<Doc>;
@@ -505,13 +528,13 @@ describe("Reopening a database with indexes", function () {
505
528
  didMap = true;
506
529
  return doc.foo;
507
530
  };
508
- idx = index<string, Doc>(sthis, db, "foo", mapFn);
531
+ idx = index<string, Doc>(db, "foo", mapFn);
509
532
  });
510
533
 
511
534
  it("should persist data", async function () {
512
535
  const doc = await db.get<Doc>("test");
513
536
  expect(doc.foo).toBe("bar");
514
- const idx2 = index<string, Doc>(sthis, db, "foo");
537
+ const idx2 = index<string, Doc>(db, "foo");
515
538
  expect(idx2).toBe(idx);
516
539
  const result = await idx2.query();
517
540
  expect(result).toBeTruthy();
@@ -522,7 +545,7 @@ describe("Reopening a database with indexes", function () {
522
545
  });
523
546
 
524
547
  it("should reuse the index", async function () {
525
- const idx2 = index(sthis, db, "foo", mapFn);
548
+ const idx2 = index(db, "foo", mapFn);
526
549
  expect(idx2).toBe(idx);
527
550
  const result = await idx2.query();
528
551
  expect(result).toBeTruthy();
@@ -543,9 +566,9 @@ describe("Reopening a database with indexes", function () {
543
566
  const db2 = fireproof("test-reopen-idx");
544
567
  const doc = await db2.get<FooType>("test");
545
568
  expect(doc.foo).toBe("bar");
546
- expect(db2._crdt.clock.head).toBeTruthy();
547
- expect(db2._crdt.clock.head.length).toBe(1);
548
- expect(db2._crdt.clock.head).toEqual(db._crdt.clock.head);
569
+ expect(db2.crdt.clock.head).toBeTruthy();
570
+ expect(db2.crdt.clock.head.length).toBe(1);
571
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
549
572
  });
550
573
 
551
574
  it("should have the same data on reopen after a query", async function () {
@@ -558,9 +581,9 @@ describe("Reopening a database with indexes", function () {
558
581
  const db2 = fireproof("test-reopen-idx");
559
582
  const doc = await db2.get<FooType>("test");
560
583
  expect(doc.foo).toBe("bar");
561
- expect(db2._crdt.clock.head).toBeTruthy();
562
- expect(db2._crdt.clock.head.length).toBe(1);
563
- expect(db2._crdt.clock.head).toEqual(db._crdt.clock.head);
584
+ expect(db2.crdt.clock.head).toBeTruthy();
585
+ expect(db2.crdt.clock.head.length).toBe(1);
586
+ expect(db2.crdt.clock.head).toEqual(db.crdt.clock.head);
564
587
  });
565
588
 
566
589
  // it('should query the same data on reopen', async function () {
@@ -595,11 +618,11 @@ describe("basic js verify", function () {
595
618
  expect(ok.id).toBe("test");
596
619
  const ok2 = await db.put({ _id: "test2", foo: ["bar", "bam"] });
597
620
  expect(ok2.id).toBe("test2");
598
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
621
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
599
622
  const loader = blocks.loader;
600
623
  expect(loader).toBeTruthy();
601
624
  const cid = loader.carLog[0][0];
602
- const cid2 = db._crdt.clock.head[0];
625
+ const cid2 = db.crdt.clock.head[0];
603
626
  expect(cid).not.toBe(cid2);
604
627
  expect(cid).not.toBe(cid2);
605
628
  const cidList = [cid, cid2];
@@ -612,8 +635,8 @@ describe("basic js verify", function () {
612
635
  });
613
636
 
614
637
  describe("same workload twice, same CID", function () {
615
- let dbA: Database;
616
- let dbB: Database;
638
+ let dbA: Ledger;
639
+ let dbB: Ledger;
617
640
  let headA: string;
618
641
  let headB: string;
619
642
 
@@ -621,21 +644,17 @@ describe("same workload twice, same CID", function () {
621
644
  // let configA: any;
622
645
  // let configB: any;
623
646
 
624
- // const configA = {
625
- // store: {
626
- // stores: {
627
- // base: storageURL(sthis).build().setParam("storekey", "@test@"),
628
- // },
629
- // },
630
- // };
631
-
632
- // const configB = {
633
- // store: {
634
- // stores: {
635
- // base: storageURL(sthis).build().setParam("storekey", "@test@"),
636
- // },
637
- // },
638
- // };
647
+ const configA: ConfigOpts = {
648
+ storeUrls: {
649
+ base: storageURL(sthis).build().setParam("storekey", "@test@"),
650
+ },
651
+ };
652
+
653
+ const configB: ConfigOpts = {
654
+ storeUrls: {
655
+ base: storageURL(sthis).build().setParam("storekey", "@test@"),
656
+ },
657
+ };
639
658
 
640
659
  afterEach(async function () {
641
660
  await dbA.close();
@@ -646,23 +665,23 @@ describe("same workload twice, same CID", function () {
646
665
  beforeEach(async function () {
647
666
  let ok: DocResponse;
648
667
  await sthis.start();
649
- // 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");
668
+ // todo this fails because the test setup doesn't properly configure both ledgers to use the same key
669
+ dbA = fireproof("test-dual-workload-a", configA);
651
670
  for (const doc of docs) {
652
671
  ok = await dbA.put(doc);
653
672
  expect(ok).toBeTruthy();
654
673
  expect(ok.id).toBeTruthy();
655
674
  }
656
- headA = dbA._crdt.clock.head.toString();
675
+ headA = dbA.crdt.clock.head.toString();
657
676
 
658
- // 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");
677
+ // todo this fails because the test setup doesn't properly configure both ledgers to use the same key
678
+ dbB = fireproof("test-dual-workload-b", configB);
660
679
  for (const doc of docs) {
661
680
  ok = await dbB.put(doc);
662
681
  expect(ok).toBeTruthy();
663
682
  expect(ok.id).toBeTruthy();
664
683
  }
665
- headB = dbB._crdt.clock.head.toString();
684
+ headB = dbB.crdt.clock.head.toString();
666
685
  });
667
686
  it("should have head A and B", async function () {
668
687
  expect(headA).toBeTruthy();
@@ -671,34 +690,34 @@ describe("same workload twice, same CID", function () {
671
690
  expect(headA.length).toBeGreaterThan(10);
672
691
  });
673
692
  it("should have same car log", async function () {
674
- const logA = dbA._crdt.blockstore.loader?.carLog;
693
+ const logA = dbA.crdt.blockstore.loader?.carLog;
675
694
  expect(logA).toBeTruthy();
676
695
  assert(logA);
677
- expect(logA.length).toBe(38);
696
+ expect(logA.length).toBe(docs.length);
678
697
 
679
- const logB = dbB._crdt.blockstore.loader?.carLog;
698
+ const logB = dbB.crdt.blockstore.loader?.carLog;
680
699
  expect(logB).toBeTruthy();
681
700
  assert(logB);
682
- expect(logB.length).toBe(38);
701
+ expect(logB.length).toBe(docs.length);
683
702
 
684
703
  const logA2 = logA.map((c) => c.toString());
685
704
  const logB2 = logB.map((c) => c.toString());
686
705
 
687
706
  expect(logA2.length).toBe(logB2.length);
688
707
 
689
- // todo this fails because the test setup doesn't properly configure both databases to use the same key
708
+ // todo this fails because the test setup doesn't properly configure both ledgers to use the same key
690
709
  // expect(logA2).toEqual(logB2);
691
710
  });
692
711
  it("should have same car log after compact", async function () {
693
712
  await dbA.compact();
694
713
  await dbB.compact();
695
714
 
696
- const cmpLogA = dbA._crdt.blockstore.loader?.carLog;
715
+ const cmpLogA = dbA.crdt.blockstore.loader?.carLog;
697
716
  expect(cmpLogA).toBeTruthy();
698
717
  assert(cmpLogA);
699
718
  expect(cmpLogA.length).toBe(1);
700
719
 
701
- const cmpLogB = dbB._crdt.blockstore.loader?.carLog;
720
+ const cmpLogB = dbB.crdt.blockstore.loader?.carLog;
702
721
  expect(cmpLogB).toBeTruthy();
703
722
  assert(cmpLogB);
704
723
  expect(cmpLogB.length).toBe(1);
@@ -708,7 +727,7 @@ describe("same workload twice, same CID", function () {
708
727
 
709
728
  expect(cmpLogA2.length).toBe(cmpLogB2.length);
710
729
 
711
- // todo this fails because the test setup doesn't properly configure both databases to use the same key
730
+ // todo this fails because the test setup doesn't properly configure both ledgers to use the same key
712
731
  // expect(cmpLogA2).toEqual(cmpLogB2);
713
732
  });
714
733
  });
@@ -1,31 +1,36 @@
1
- import { fireproof as database, Database, DocResponse, DocWithId } from "@fireproof/core";
1
+ import { fireproof, Ledger, DocResponse, DocWithId, index, isLedger } from "@fireproof/core";
2
+ import { mockSuperThis } from "../helpers.js";
2
3
 
3
4
  describe("Hello World Test", function () {
4
5
  it("should pass the hello world test", function () {
5
- const result = database("hello"); // call to your library function
6
+ const result = fireproof("hello"); // call to your library function
6
7
  expect(result.name).toBe("hello");
7
8
  });
8
9
  });
9
10
 
10
- describe("hello public API", function () {
11
+ describe("hello public API", () => {
11
12
  interface TestDoc {
12
13
  foo: string;
13
14
  }
14
- let db: Database;
15
+ let db: Ledger;
15
16
  let ok: DocResponse;
16
17
  let doc: DocWithId<TestDoc>;
17
- afterEach(async function () {
18
+ // let idx: Index<string, TestDoc>;
19
+ const sthis = mockSuperThis();
20
+ afterEach(async () => {
18
21
  await db.close();
19
22
  await db.destroy();
20
23
  });
21
- beforeEach(async function () {
22
- db = database("test-public-api");
24
+ beforeEach(async () => {
25
+ await sthis.start();
26
+ db = fireproof("test-public-api");
27
+ index<string, TestDoc>(db, "test-index", (doc) => doc.foo);
23
28
  ok = await db.put({ _id: "test", foo: "bar" });
24
29
  doc = await db.get("test");
25
30
  });
26
- it("should have a database", function () {
31
+ it("should have a ledger", function () {
27
32
  expect(db).toBeTruthy();
28
- expect(db instanceof Database).toBeTruthy();
33
+ expect(isLedger(db)).toBeTruthy();
29
34
  });
30
35
  it("should put", function () {
31
36
  expect(ok).toBeTruthy();
@@ -34,23 +39,22 @@ describe("hello public API", function () {
34
39
  it("should get", function () {
35
40
  expect(doc.foo).toBe("bar");
36
41
  });
37
- it("should get when you open it again", async function () {
42
+ it("should get when you open it again", async () => {
38
43
  await db.close();
39
- await db.destroy();
40
- const db2 = database("test-public-api");
41
- doc = await db2.get("test");
44
+ db = fireproof("test-public-api");
45
+ doc = await db.get("test");
42
46
  expect(doc.foo).toBe("bar");
43
47
  });
44
48
  });
45
49
 
46
- describe("Simplified Reopening a database", function () {
47
- let db: Database;
50
+ describe("Simplified Reopening a ledger", function () {
51
+ let db: Ledger;
48
52
  afterEach(async function () {
49
53
  await db.close();
50
54
  await db.destroy();
51
55
  });
52
56
  beforeEach(async function () {
53
- db = new Database("test-reopen-simple");
57
+ db = fireproof("test-reopen-simple");
54
58
  const ok = await db.put({ _id: "test", foo: "bar" });
55
59
  expect(ok).toBeTruthy();
56
60
  expect(ok.id).toBe("test");
@@ -62,7 +66,7 @@ describe("Simplified Reopening a database", function () {
62
66
  });
63
67
 
64
68
  it("should have the same data on reopen", async function () {
65
- const db2 = new Database("test-reopen-simple");
69
+ const db2 = fireproof("test-reopen-simple");
66
70
  const doc = await db2.get<{ foo: string }>("test");
67
71
  expect(doc.foo).toBe("bar");
68
72
  await db2.close();