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

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"inputs":{"src/react/useFireproof.ts":{"bytes":11322,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/react/useDocument.ts":{"bytes":1656,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/useLiveQuery.ts":{"bytes":1387,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/useAllDocs.ts":{"bytes":1126,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/useChanges.ts":{"bytes":1171,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/index.ts":{"bytes":971,"imports":[{"path":"src/react/useDocument.ts","kind":"import-statement","original":"./useDocument.js"},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"},{"path":"src/react/useLiveQuery.ts","kind":"import-statement","original":"./useLiveQuery.js"},{"path":"src/react/useAllDocs.ts","kind":"import-statement","original":"./useAllDocs.js"},{"path":"src/react/useChanges.ts","kind":"import-statement","original":"./useChanges.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/react/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":21356},"dist/fireproof-core/react/index.js":{"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["FireproofCtx","useAllDocs","useChanges","useDocument","useFireproof","useLiveQuery"],"entryPoint":"src/react/index.ts","inputs":{"src/react/useFireproof.ts":{"bytesInOutput":3861},"src/react/useDocument.ts":{"bytesInOutput":216},"src/react/index.ts":{"bytesInOutput":0},"src/react/useLiveQuery.ts":{"bytesInOutput":223},"src/react/useAllDocs.ts":{"bytesInOutput":209},"src/react/useChanges.ts":{"bytesInOutput":209}},"bytes":4964}}}
1
+ {"inputs":{"src/react/useFireproof.ts":{"bytes":11393,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/react/useDocument.ts":{"bytes":1680,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/useLiveQuery.ts":{"bytes":1409,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/useAllDocs.ts":{"bytes":1146,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/useChanges.ts":{"bytes":1191,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"}],"format":"esm"},"src/react/index.ts":{"bytes":971,"imports":[{"path":"src/react/useDocument.ts","kind":"import-statement","original":"./useDocument.js"},{"path":"src/react/useFireproof.ts","kind":"import-statement","original":"./useFireproof.js"},{"path":"src/react/useLiveQuery.ts","kind":"import-statement","original":"./useLiveQuery.js"},{"path":"src/react/useAllDocs.ts","kind":"import-statement","original":"./useAllDocs.js"},{"path":"src/react/useChanges.ts","kind":"import-statement","original":"./useChanges.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/react/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":21518},"dist/fireproof-core/react/index.js":{"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["FireproofCtx","useAllDocs","useChanges","useDocument","useFireproof","useLiveQuery"],"entryPoint":"src/react/index.ts","inputs":{"src/react/useFireproof.ts":{"bytesInOutput":3892},"src/react/useDocument.ts":{"bytesInOutput":222},"src/react/index.ts":{"bytesInOutput":0},"src/react/useLiveQuery.ts":{"bytesInOutput":229},"src/react/useAllDocs.ts":{"bytesInOutput":215},"src/react/useChanges.ts":{"bytesInOutput":215}},"bytes":5019}}}
@@ -54,7 +54,7 @@ class TestInterceptor extends bs.PassThroughGateway {
54
54
  describe("InterceptorGateway", () => {
55
55
  it("passthrough", async () => {
56
56
  const gwi = new TestInterceptor();
57
- const db = fireproof("interceptor-gateway", {
57
+ const db = fireproof.DB("interceptor-gateway", {
58
58
  gatewayInterceptor: gwi,
59
59
  });
60
60
  expect(
@@ -3,7 +3,7 @@ import { sha256 as hasher } from "multiformats/hashes/sha2";
3
3
  import { BlockView } from "multiformats";
4
4
  import { CID } from "multiformats/cid";
5
5
  import { MemoryBlockstore } from "@fireproof/vendor/@web3-storage/pail/block";
6
- import { CRDTMeta, IndexTransactionMeta, SuperThis, bs, ensureSuperThis, rt } from "@fireproof/core";
6
+ import { CRDTMeta, CarTransaction, IndexTransactionMeta, SuperThis, bs, ensureSuperThis, rt } from "@fireproof/core";
7
7
  import { simpleBlockOpts } from "../helpers.js";
8
8
 
9
9
  class MyMemoryBlockStore extends bs.EncryptedBlockstore {
@@ -23,7 +23,7 @@ class MyMemoryBlockStore extends bs.EncryptedBlockstore {
23
23
  close(): Promise<void> {
24
24
  return this.loader.close();
25
25
  }
26
- readonly transactions = new Set<bs.CarTransaction>();
26
+ readonly transactions = new Set<CarTransaction>();
27
27
  // readonly lastTxMeta?: TransactionMeta;
28
28
  readonly compacting: boolean = false;
29
29
 
@@ -51,7 +51,7 @@ class MyMemoryBlockStore extends bs.EncryptedBlockstore {
51
51
  describe("basic Loader simple", function () {
52
52
  let loader: bs.Loader;
53
53
  let block: BlockView;
54
- let t: bs.CarTransaction;
54
+ let t: CarTransaction;
55
55
  const sthis = ensureSuperThis();
56
56
 
57
57
  afterEach(async function () {
@@ -63,7 +63,7 @@ describe("basic Loader simple", function () {
63
63
  const testDbName = "test-loader-commit";
64
64
  await sthis.start();
65
65
  const mockM = new MyMemoryBlockStore(sthis);
66
- t = new bs.CarTransaction(mockM as bs.EncryptedBlockstore);
66
+ t = new bs.CarTransactionImpl(mockM as bs.EncryptedBlockstore);
67
67
  loader = new bs.Loader(sthis, {
68
68
  ...simpleBlockOpts(sthis, testDbName),
69
69
  public: true,
@@ -99,7 +99,7 @@ describe("basic Loader with two commits", function () {
99
99
  let block2: BlockView;
100
100
  let block3: BlockView;
101
101
  let block4: BlockView;
102
- let t: bs.CarTransaction;
102
+ let t: CarTransaction;
103
103
  let carCid: bs.CarGroup;
104
104
  let carCid0: bs.CarGroup;
105
105
 
@@ -113,7 +113,7 @@ describe("basic Loader with two commits", function () {
113
113
  beforeEach(async () => {
114
114
  await sthis.start();
115
115
  const mockM = new MyMemoryBlockStore(sthis);
116
- t = new bs.CarTransaction(mockM);
116
+ t = new bs.CarTransactionImpl(mockM);
117
117
  loader = new bs.Loader(sthis, {
118
118
  ...simpleBlockOpts(sthis, "test-loader-two-commit"),
119
119
  public: true,
@@ -1,12 +1,12 @@
1
1
  import { CID } from "multiformats";
2
- import { bs, ensureSuperThis, SuperThis } from "@fireproof/core";
2
+ import { BaseBlockstore, bs, CarTransaction, ensureSuperThis, SuperThis } from "@fireproof/core";
3
3
  import { simpleBlockOpts } from "../helpers.js";
4
4
 
5
5
  describe("Fresh TransactionBlockstore", function () {
6
- let blocks: bs.BaseBlockstore;
6
+ let blocks: BaseBlockstore;
7
7
  const sthis = ensureSuperThis();
8
8
  beforeEach(function () {
9
- blocks = new bs.BaseBlockstore(simpleBlockOpts(sthis));
9
+ blocks = new bs.BaseBlockstoreImpl(simpleBlockOpts(sthis));
10
10
  });
11
11
  // it("should not have a name", function () {
12
12
  // expect(blocks.name).toBeFalsy();
@@ -22,7 +22,7 @@ describe("Fresh TransactionBlockstore", function () {
22
22
  it("should yield a transaction", async function () {
23
23
  const txR = await blocks.transaction(async (tblocks) => {
24
24
  expect(tblocks).toBeTruthy();
25
- expect(tblocks instanceof bs.CarTransaction).toBeTruthy();
25
+ expect(tblocks instanceof bs.CarTransactionImpl).toBeTruthy();
26
26
  return { head: [] };
27
27
  });
28
28
  expect(txR).toBeTruthy();
@@ -55,12 +55,12 @@ describe("TransactionBlockstore with name", function () {
55
55
  });
56
56
 
57
57
  describe("A transaction", function () {
58
- let tblocks: bs.CarTransaction;
58
+ let tblocks: CarTransaction;
59
59
  let blocks: bs.EncryptedBlockstore;
60
60
  const sthis = ensureSuperThis();
61
61
  beforeEach(async function () {
62
62
  blocks = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis, "test"));
63
- tblocks = new bs.CarTransaction(blocks);
63
+ tblocks = new bs.CarTransactionImpl(blocks);
64
64
  blocks.transactions.add(tblocks);
65
65
  });
66
66
  it("should put and get", async function () {
@@ -80,7 +80,7 @@ function asUInt8Array(str: string, sthis: SuperThis) {
80
80
  }
81
81
 
82
82
  describe("TransactionBlockstore with a completed transaction", function () {
83
- let blocks: bs.BaseBlockstore;
83
+ let blocks: BaseBlockstore;
84
84
  let cid: CID;
85
85
  let cid2: CID;
86
86
  const sthis = ensureSuperThis();
@@ -89,7 +89,7 @@ describe("TransactionBlockstore with a completed transaction", function () {
89
89
  cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
90
90
  cid2 = CID.parse("bafybeibgouhn5ktecpjuovt52zamzvm4dlve5ak7x6d5smms3itkhplnhm");
91
91
 
92
- blocks = new bs.BaseBlockstore(simpleBlockOpts(sthis));
92
+ blocks = new bs.BaseBlockstoreImpl(simpleBlockOpts(sthis));
93
93
  await blocks.transaction(async (tblocks) => {
94
94
  await tblocks.put(cid, asUInt8Array("value", sthis));
95
95
  await tblocks.put(cid, asUInt8Array("value", sthis));
@@ -1,4 +1,4 @@
1
- import { Ledger, LedgerFactory, PARAM, bs, ensureSuperThis } from "@fireproof/core";
1
+ import { Database, Ledger, LedgerFactory, PARAM, bs, ensureSuperThis, fireproof } from "@fireproof/core";
2
2
 
3
3
  import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
4
4
  import { simpleCID } from "../helpers.js";
@@ -363,7 +363,7 @@ describe("noop Gateway", function () {
363
363
  });
364
364
 
365
365
  describe("noop Gateway subscribe", function () {
366
- let db: Ledger;
366
+ let db: Database;
367
367
 
368
368
  let metaStore: bs.MetaStore;
369
369
 
@@ -375,10 +375,10 @@ describe("noop Gateway subscribe", function () {
375
375
  await db.destroy();
376
376
  });
377
377
  beforeEach(async function () {
378
- db = LedgerFactory("test-gateway-" + sthis.nextId().str);
378
+ db = fireproof.DB("test-gateway-" + sthis.nextId().str);
379
379
 
380
380
  // Extract stores from the loader
381
- metaStore = (await db.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
381
+ metaStore = (await db.ledger.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
382
382
 
383
383
  metaGateway = metaStore.realGateway;
384
384
  });
@@ -409,7 +409,7 @@ describe("noop Gateway subscribe", function () {
409
409
  });
410
410
 
411
411
  describe("Gateway", function () {
412
- let db: Ledger;
412
+ let db: Database;
413
413
  // let carStore: ExtendedStore;
414
414
  let metaStore: bs.MetaStore;
415
415
  // let fileStore: ExtendedStore;
@@ -425,14 +425,14 @@ describe("Gateway", function () {
425
425
  await db.destroy();
426
426
  });
427
427
  beforeEach(async function () {
428
- db = LedgerFactory("test-gateway-" + sthis.nextId().str);
428
+ db = fireproof.DB("test-gateway-" + sthis.nextId().str);
429
429
  const ok = await db.put({ _id: "test", foo: "bar" });
430
430
  expect(ok).toBeTruthy();
431
431
  expect(ok.id).toBe("test");
432
432
 
433
433
  // Extract stores from the loader
434
434
  // carStore = (await db.blockstore.loader.carStore()) as unknown as ExtendedStore;
435
- metaStore = (await db.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
435
+ metaStore = (await db.ledger.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
436
436
  // fileStore = (await db.blockstore.loader.fileStore()) as unknown as ExtendedStore;
437
437
  // walStore = (await db.blockstore.loader.WALStore()) as unknown as ExtendedStore;
438
438
 
@@ -1,10 +1,10 @@
1
- import { CRDT, defaultWriteQueueOpts, ensureSuperThis, LedgerOpts, toStoreURIRuntime, rt } from "@fireproof/core";
1
+ import { CRDT, defaultWriteQueueOpts, ensureSuperThis, LedgerOpts, toStoreURIRuntime, rt, CRDTImpl } from "@fireproof/core";
2
2
  import { bs } from "@fireproof/core";
3
3
  import { CRDTMeta, DocValue } from "@fireproof/core";
4
4
  import { Index, index } from "@fireproof/core";
5
5
 
6
6
  describe("Fresh crdt", function () {
7
- let crdt: CRDT<{ hello: string } | { points: number }>;
7
+ let crdt: CRDT;
8
8
  const sthis = ensureSuperThis();
9
9
  afterEach(async function () {
10
10
  await crdt.close();
@@ -18,7 +18,7 @@ describe("Fresh crdt", function () {
18
18
  storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
19
19
  storeEnDe: bs.ensureStoreEnDeFile({}),
20
20
  };
21
- crdt = new CRDT(sthis, dbOpts);
21
+ crdt = new CRDTImpl(sthis, dbOpts);
22
22
  });
23
23
  it("should have an empty head", async function () {
24
24
  const head = crdt.clock.head;
@@ -44,7 +44,7 @@ describe("CRDT with one record", function () {
44
44
  readonly hello: string;
45
45
  readonly nice: string;
46
46
  }
47
- let crdt: CRDT<Partial<CRDTTestType>>;
47
+ let crdt: CRDT;
48
48
  let firstPut: CRDTMeta;
49
49
  const sthis = ensureSuperThis();
50
50
 
@@ -61,7 +61,7 @@ describe("CRDT with one record", function () {
61
61
  storeUrls: toStoreURIRuntime(sthis, `test@${sthis.nextId().str}`),
62
62
  storeEnDe: bs.ensureStoreEnDeFile({}),
63
63
  };
64
- crdt = new CRDT(sthis, dbOpts);
64
+ crdt = new CRDTImpl(sthis, dbOpts);
65
65
  firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
66
66
  });
67
67
  it("should have a one-element head", async function () {
@@ -90,7 +90,7 @@ describe("CRDT with one record", function () {
90
90
  expect(got).toBeFalsy();
91
91
  });
92
92
  it("should offer changes", async function () {
93
- const { result } = await crdt.changes([]);
93
+ const { result } = await crdt.changes<Partial<CRDTTestType>>([]);
94
94
  expect(result.length).toBe(1);
95
95
  expect(result[0].id).toBe("hello");
96
96
  expect(result[0].value?.hello).toBe("world");
@@ -101,7 +101,7 @@ describe("CRDT with a multi-write", function () {
101
101
  interface CRDTTestType {
102
102
  readonly points: number;
103
103
  }
104
- let crdt: CRDT<CRDTTestType>;
104
+ let crdt: CRDT;
105
105
  let firstPut: CRDTMeta;
106
106
  const sthis = ensureSuperThis();
107
107
 
@@ -117,7 +117,7 @@ describe("CRDT with a multi-write", function () {
117
117
  storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
118
118
  storeEnDe: bs.ensureStoreEnDeFile({}),
119
119
  };
120
- crdt = new CRDT(sthis, dbOpts);
120
+ crdt = new CRDTImpl(sthis, dbOpts);
121
121
  firstPut = await crdt.bulk([
122
122
  { id: "ace", value: { points: 11 } },
123
123
  { id: "king", value: { points: 10 } },
@@ -145,7 +145,7 @@ describe("CRDT with a multi-write", function () {
145
145
  expect(got.doc.points).toBe(10);
146
146
  });
147
147
  it("should offer changes", async function () {
148
- const { result } = await crdt.changes([]);
148
+ const { result } = await crdt.changes<CRDTTestType>([]);
149
149
  expect(result.length).toBe(2);
150
150
  expect(result[0].id).toBe("ace");
151
151
  expect(result[0].value?.points).toBe(11);
@@ -158,7 +158,7 @@ describe("CRDT with a multi-write", function () {
158
158
  { id: "jack", value: { points: 10 } },
159
159
  ]);
160
160
  expect(secondPut.head).toBeTruthy();
161
- const { result: r2, head: h2 } = await crdt.changes();
161
+ const { result: r2, head: h2 } = await crdt.changes<CRDTTestType>();
162
162
  expect(r2.length).toBe(4);
163
163
  const { result: r3 } = await crdt.changes(firstPut.head);
164
164
  expect(r3.length).toBe(2);
@@ -171,8 +171,7 @@ interface CRDTTestType {
171
171
  readonly points: number;
172
172
  }
173
173
  describe("CRDT with two multi-writes", function () {
174
- /** @type {CRDT} */
175
- let crdt: CRDT<CRDTTestType>;
174
+ let crdt: CRDT;
176
175
  let firstPut: CRDTMeta;
177
176
  let secondPut: CRDTMeta;
178
177
  const sthis = ensureSuperThis();
@@ -188,7 +187,7 @@ describe("CRDT with two multi-writes", function () {
188
187
  storeUrls: toStoreURIRuntime(sthis, `test-multiple-writes@${sthis.nextId().str}`),
189
188
  storeEnDe: bs.ensureStoreEnDeFile({}),
190
189
  };
191
- crdt = new CRDT(sthis, dbOpts);
190
+ crdt = new CRDTImpl(sthis, dbOpts);
192
191
  firstPut = await crdt.bulk([
193
192
  { id: "ace", value: { points: 11 } },
194
193
  { id: "king", value: { points: 10 } },
@@ -217,7 +216,7 @@ describe("CRDT with two multi-writes", function () {
217
216
  }
218
217
  });
219
218
  it("should offer changes", async function () {
220
- const { result } = await crdt.changes();
219
+ const { result } = await crdt.changes<CRDTTestType>();
221
220
  expect(result.length).toBe(4);
222
221
  expect(result[0].id).toBe("ace");
223
222
  expect(result[0].value?.points).toBe(11);
@@ -228,7 +227,7 @@ describe("CRDT with two multi-writes", function () {
228
227
  });
229
228
 
230
229
  describe("Compact a named CRDT with writes", function () {
231
- let crdt: CRDT<CRDTTestType>;
230
+ let crdt: CRDT;
232
231
  const sthis = ensureSuperThis();
233
232
  afterEach(async function () {
234
233
  await crdt.close();
@@ -242,7 +241,7 @@ describe("Compact a named CRDT with writes", function () {
242
241
  storeUrls: toStoreURIRuntime(sthis, `named-crdt-compaction`),
243
242
  storeEnDe: bs.ensureStoreEnDeFile({}),
244
243
  };
245
- crdt = new CRDT(sthis, dbOpts);
244
+ crdt = new CRDTImpl(sthis, dbOpts);
246
245
  for (let i = 0; i < 10; i++) {
247
246
  const bulk = [
248
247
  { id: "ace", value: { points: 11 } },
@@ -289,7 +288,7 @@ describe("Compact a named CRDT with writes", function () {
289
288
  });
290
289
 
291
290
  describe("CRDT with an index", function () {
292
- let crdt: CRDT<CRDTTestType>;
291
+ let crdt: CRDT;
293
292
  let idx: Index<number, CRDTTestType>;
294
293
  const sthis = ensureSuperThis();
295
294
  afterEach(async function () {
@@ -304,12 +303,12 @@ describe("CRDT with an index", function () {
304
303
  storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
305
304
  storeEnDe: bs.ensureStoreEnDeFile({}),
306
305
  };
307
- crdt = new CRDT<CRDTTestType>(sthis, dbOpts);
306
+ crdt = new CRDTImpl(sthis, dbOpts);
308
307
  await crdt.bulk([
309
308
  { id: "ace", value: { points: 11 } },
310
309
  { id: "king", value: { points: 10 } },
311
310
  ]);
312
- idx = await index<number, CRDTTestType>({ crdt: crdt }, "points");
311
+ idx = await index<number, CRDTTestType>(crdt, "points");
313
312
  });
314
313
  it("should query the data", async function () {
315
314
  const got = await idx.query({ range: [9, 12] });
@@ -318,7 +317,7 @@ describe("CRDT with an index", function () {
318
317
  expect(got.rows[0].key).toBe(10);
319
318
  });
320
319
  it("should register the index", async function () {
321
- const rIdx = await index<number, CRDTTestType>({ crdt: crdt }, "points");
320
+ const rIdx = await index<number, CRDTTestType>(crdt, "points");
322
321
  expect(rIdx).toBeTruthy();
323
322
  expect(rIdx.name).toBe("points");
324
323
  const got = await rIdx.query({ range: [9, 12] });
@@ -327,7 +326,7 @@ describe("CRDT with an index", function () {
327
326
  expect(got.rows[0].key).toBe(10);
328
327
  });
329
328
  it("creating a different index with same name should not work", async function () {
330
- const e = await index({ crdt: crdt }, "points", (doc) => doc._id)
329
+ const e = await index(crdt, "points", (doc) => doc._id)
331
330
  .query()
332
331
  .catch((err) => err);
333
332
  expect(e.message).toMatch(/cannot apply/);
@@ -335,12 +334,9 @@ describe("CRDT with an index", function () {
335
334
  });
336
335
 
337
336
  describe("Loader with a committed transaction", function () {
338
- interface CRDTTestType {
339
- readonly foo: string;
340
- }
341
337
  let loader: bs.Loader;
342
338
  let blockstore: bs.EncryptedBlockstore;
343
- let crdt: CRDT<CRDTTestType>;
339
+ let crdt: CRDT;
344
340
  let done: CRDTMeta;
345
341
  const dbname = "test-loader";
346
342
  const sthis = ensureSuperThis();
@@ -356,7 +352,7 @@ describe("Loader with a committed transaction", function () {
356
352
  storeUrls: toStoreURIRuntime(sthis, dbname),
357
353
  storeEnDe: bs.ensureStoreEnDeFile({}),
358
354
  };
359
- crdt = new CRDT(sthis, dbOpts);
355
+ crdt = new CRDTImpl(sthis, dbOpts);
360
356
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
361
357
  expect(blockstore.loader).toBeTruthy();
362
358
  loader = blockstore.loader as bs.Loader;
@@ -389,11 +385,8 @@ describe("Loader with a committed transaction", function () {
389
385
  });
390
386
 
391
387
  describe("Loader with two committed transactions", function () {
392
- interface CRDTTestType {
393
- readonly foo: string;
394
- }
395
388
  let loader: bs.Loader;
396
- let crdt: CRDT<CRDTTestType>;
389
+ let crdt: CRDT;
397
390
  let blockstore: bs.EncryptedBlockstore;
398
391
  let done1: CRDTMeta;
399
392
  let done2: CRDTMeta;
@@ -410,7 +403,7 @@ describe("Loader with two committed transactions", function () {
410
403
  storeUrls: toStoreURIRuntime(sthis, "test-loader"),
411
404
  storeEnDe: bs.ensureStoreEnDeFile({}),
412
405
  };
413
- crdt = new CRDT(sthis, dbOpts);
406
+ crdt = new CRDTImpl(sthis, dbOpts);
414
407
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
415
408
  expect(blockstore.loader).toBeTruthy();
416
409
  loader = blockstore.loader as bs.Loader;
@@ -445,12 +438,9 @@ describe("Loader with two committed transactions", function () {
445
438
  });
446
439
 
447
440
  describe("Loader with many committed transactions", function () {
448
- interface Doc {
449
- foo: string;
450
- }
451
441
  let loader: bs.Loader;
452
442
  let blockstore: bs.EncryptedBlockstore;
453
- let crdt: CRDT<Doc>;
443
+ let crdt: CRDT;
454
444
  let dones: CRDTMeta[];
455
445
  const count = 10;
456
446
  const sthis = ensureSuperThis();
@@ -466,7 +456,7 @@ describe("Loader with many committed transactions", function () {
466
456
  storeUrls: toStoreURIRuntime(sthis, "test-loader-many"),
467
457
  storeEnDe: bs.ensureStoreEnDeFile({}),
468
458
  };
469
- crdt = new CRDT(sthis, dbOpts);
459
+ crdt = new CRDTImpl(sthis, dbOpts);
470
460
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
471
461
  expect(blockstore.loader).toBeTruthy();
472
462
  loader = blockstore.loader as bs.Loader;
@@ -2,20 +2,20 @@ import { URI } from "@adviser/cement";
2
2
  import { buildBlobFiles, FileWithCid, mockSuperThis } from "../helpers.js";
3
3
  import {
4
4
  bs,
5
- Ledger,
6
5
  DocResponse,
7
6
  DocFileMeta,
8
7
  DocWithId,
9
8
  DocFiles,
10
9
  toStoreURIRuntime,
11
10
  keyConfigOpts,
12
- LedgerFactory,
13
- LedgerShell,
14
11
  ensureSuperThis,
12
+ Database,
13
+ fireproof,
14
+ LedgerShell,
15
15
  } from "@fireproof/core";
16
16
 
17
17
  describe("basic Ledger", () => {
18
- let db: Ledger;
18
+ let db: Database;
19
19
  const sthis = mockSuperThis();
20
20
  afterEach(async () => {
21
21
  await db.close();
@@ -23,7 +23,7 @@ describe("basic Ledger", () => {
23
23
  });
24
24
  beforeEach(async () => {
25
25
  await sthis.start();
26
- db = LedgerFactory(undefined, {
26
+ db = fireproof.DB(undefined as unknown as string, {
27
27
  logger: sthis.logger,
28
28
  });
29
29
  });
@@ -53,7 +53,7 @@ describe("basic Ledger with record", function () {
53
53
  interface Doc {
54
54
  readonly value: string;
55
55
  }
56
- let db: LedgerShell;
56
+ let db: Database;
57
57
  const sthis = ensureSuperThis();
58
58
  afterEach(async () => {
59
59
  await db.close();
@@ -61,7 +61,7 @@ describe("basic Ledger with record", function () {
61
61
  });
62
62
  beforeEach(async function () {
63
63
  await sthis.start();
64
- db = LedgerFactory("factory-name") as LedgerShell;
64
+ db = fireproof.DB("factory-name");
65
65
  const ok = await db.put<Doc>({ _id: "hello", value: "world" });
66
66
  expect(ok.id).toBe("hello");
67
67
  });
@@ -93,10 +93,11 @@ describe("basic Ledger with record", function () {
93
93
  expect(rows[0].value._id).toBe("hello");
94
94
  });
95
95
  it("is not persisted", async function () {
96
- const db2 = LedgerFactory("factory-name") as LedgerShell;
96
+ const db2 = fireproof.DB("factory-name");
97
97
  const { rows } = await db2.changes([]);
98
98
  expect(rows.length).toBe(1);
99
- expect(db2.ref).toBe(db.ref);
99
+ // assert((db.ledger.ref === db2.ledger.ref, "should be the same ledger");
100
+ expect((db.ledger as LedgerShell).ref).toBe((db2.ledger as LedgerShell).ref);
100
101
  const doc = await db2.get<Doc>("hello").catch((e) => e);
101
102
  expect(doc.value).toBe("world");
102
103
  await db2.close();
@@ -107,7 +108,7 @@ describe("named Ledger with record", function () {
107
108
  interface Doc {
108
109
  readonly value: string;
109
110
  }
110
- let db: Ledger;
111
+ let db: Database;
111
112
  const sthis = ensureSuperThis();
112
113
  afterEach(async () => {
113
114
  await db.close();
@@ -115,7 +116,7 @@ describe("named Ledger with record", function () {
115
116
  });
116
117
  beforeEach(async function () {
117
118
  await sthis.start();
118
- db = LedgerFactory("test-db-name");
119
+ db = fireproof.DB("test-db-name");
119
120
  /** @type {Doc} */
120
121
  const doc = { _id: "hello", value: "world" };
121
122
  const ok = await db.put(doc);
@@ -151,7 +152,7 @@ describe("named Ledger with record", function () {
151
152
  it("should have a key", async function () {
152
153
  const { rows } = await db.changes([]);
153
154
  expect(rows.length).toBe(1);
154
- const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
155
+ const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
155
156
  const loader = blocks.loader;
156
157
  expect(loader).toBeTruthy();
157
158
  await loader.ready();
@@ -233,7 +234,7 @@ describe("named Ledger with record", function () {
233
234
  // })
234
235
 
235
236
  describe("basic Ledger parallel writes / public ordered", () => {
236
- let db: Ledger;
237
+ let db: Database;
237
238
  const writes: Promise<DocResponse>[] = [];
238
239
  const sthis = mockSuperThis();
239
240
  afterEach(async () => {
@@ -242,7 +243,7 @@ describe("basic Ledger parallel writes / public ordered", () => {
242
243
  });
243
244
  beforeEach(async () => {
244
245
  await sthis.start();
245
- db = LedgerFactory("test-parallel-writes-ordered", { writeQueue: { chunkSize: 1 } });
246
+ db = fireproof.DB("test-parallel-writes-ordered", { writeQueue: { chunkSize: 1 } });
246
247
  for (let i = 0; i < 10; i++) {
247
248
  const doc = { _id: `id-${i}`, hello: "world" };
248
249
  writes.push(db.put(doc));
@@ -251,13 +252,13 @@ describe("basic Ledger parallel writes / public ordered", () => {
251
252
  });
252
253
 
253
254
  it("should have one head", () => {
254
- const crdt = db.crdt;
255
+ const crdt = db.ledger.crdt;
255
256
  expect(crdt.clock.head.length).toBe(1);
256
257
  });
257
258
 
258
259
  it("has changes ordered", async function () {
259
260
  const { rows, clock } = await db.changes([]);
260
- expect(clock[0]).toBe(db.crdt.clock.head[0]);
261
+ expect(clock[0]).toBe(db.ledger.crdt.clock.head[0]);
261
262
  expect(rows.length).toBe(10);
262
263
  for (let i = 0; i < 10; i++) {
263
264
  expect(rows[i].key).toBe("id-" + i);
@@ -267,7 +268,7 @@ describe("basic Ledger parallel writes / public ordered", () => {
267
268
  });
268
269
 
269
270
  describe("basic Ledger parallel writes / public", () => {
270
- let db: Ledger;
271
+ let db: Database;
271
272
  const writes: Promise<DocResponse>[] = [];
272
273
  const sthis = ensureSuperThis();
273
274
  afterEach(async () => {
@@ -276,7 +277,7 @@ describe("basic Ledger parallel writes / public", () => {
276
277
  });
277
278
  beforeEach(async () => {
278
279
  await sthis.start();
279
- db = LedgerFactory("test-parallel-writes", { writeQueue: { chunkSize: 32 } });
280
+ db = fireproof.DB("test-parallel-writes", { writeQueue: { chunkSize: 32 } });
280
281
  for (let i = 0; i < 10; i++) {
281
282
  const doc = { _id: `id-${i}`, hello: "world" };
282
283
  writes.push(db.put(doc));
@@ -284,7 +285,7 @@ describe("basic Ledger parallel writes / public", () => {
284
285
  await Promise.all(writes);
285
286
  });
286
287
  it("should resolve to one head", async () => {
287
- const crdt = db.crdt;
288
+ const crdt = db.ledger.crdt;
288
289
  expect(crdt.clock.head.length).toBe(9);
289
290
  await db.put({ _id: "id-10", hello: "world" });
290
291
  expect(crdt.clock.head.length).toBe(1);
@@ -323,7 +324,7 @@ describe("basic Ledger parallel writes / public", () => {
323
324
  });
324
325
  it("has changes not ordered", async function () {
325
326
  const { rows, clock } = await db.changes([]);
326
- expect(clock[0]).toBe(db.crdt.clock.head[0]);
327
+ expect(clock[0]).toBe(db.ledger.crdt.clock.head[0]);
327
328
  expect(rows.length).toBe(10);
328
329
  rows.sort((a, b) => a.key.localeCompare(b.key));
329
330
  // console.log(rows);
@@ -337,7 +338,7 @@ describe("basic Ledger parallel writes / public", () => {
337
338
  expect(rows.length).toBe(10);
338
339
  // expect(db.opts.public).toBeTruthy();
339
340
  // expect(db._crdt.opts.public).toBeTruthy();
340
- const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
341
+ const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
341
342
  const loader = blocks.loader;
342
343
  expect(loader).toBeTruthy();
343
344
  await loader.ready();
@@ -347,7 +348,7 @@ describe("basic Ledger parallel writes / public", () => {
347
348
  });
348
349
 
349
350
  describe("basic Ledger with subscription", function () {
350
- let db: Ledger;
351
+ let db: Database;
351
352
  let didRun: number;
352
353
  let unsubscribe: () => void;
353
354
  let lastDoc: DocWithId<NonNullable<unknown>>;
@@ -359,7 +360,7 @@ describe("basic Ledger with subscription", function () {
359
360
  });
360
361
  beforeEach(async function () {
361
362
  await sthis.start();
362
- db = LedgerFactory("factory-name");
363
+ db = fireproof.DB("factory-name");
363
364
  didRun = 0;
364
365
  waitForSub = new Promise((resolve) => {
365
366
  unsubscribe = db.subscribe((docs) => {
@@ -393,17 +394,16 @@ describe("basic Ledger with subscription", function () {
393
394
  });
394
395
 
395
396
  describe("basic Ledger with no update subscription", function () {
396
- let db: Ledger;
397
+ let db: Database;
397
398
  let didRun: number;
398
399
  let unsubscribe: () => void;
399
- const sthis = ensureSuperThis();
400
+ // const sthis = ensureSuperThis();
400
401
  afterEach(async () => {
401
402
  await db.close();
402
403
  await db.destroy();
403
404
  });
404
405
  beforeEach(async function () {
405
- await sthis.start();
406
- db = LedgerFactory("factory-name");
406
+ db = fireproof.DB("factory-name");
407
407
  didRun = 0;
408
408
  unsubscribe = db.subscribe(() => {
409
409
  didRun++;
@@ -429,7 +429,7 @@ describe("basic Ledger with no update subscription", function () {
429
429
  });
430
430
 
431
431
  describe("ledger with files input", () => {
432
- let db: Ledger;
432
+ let db: Database;
433
433
  let imagefiles: FileWithCid[] = [];
434
434
  let result: DocResponse;
435
435
  const sthis = ensureSuperThis();
@@ -441,7 +441,7 @@ describe("ledger with files input", () => {
441
441
  beforeEach(async function () {
442
442
  await sthis.start();
443
443
  imagefiles = await buildBlobFiles();
444
- db = LedgerFactory("fireproof-with-images");
444
+ db = fireproof.DB("fireproof-with-images");
445
445
  const doc = {
446
446
  _id: "images-main",
447
447
  type: "files",
@@ -532,6 +532,7 @@ describe("StoreURIRuntime", () => {
532
532
  await sthis.start();
533
533
  safeEnv = sthis.env.get("FP_STORAGE_URL");
534
534
  sthis.env.set("FP_STORAGE_URL", "my://bla/storage");
535
+ // console.log(">>>>>>>>>>", bs, bs.registerStoreProtocol)
535
536
  unreg = bs.registerStoreProtocol({
536
537
  protocol: "murks",
537
538
  isDefault: true,