@fireproof/core 0.19.121 → 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 (71) 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 +2 -3
  7. package/index.cjs +1827 -1059
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +747 -334
  10. package/index.d.ts +747 -334
  11. package/index.js +1800 -1034
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/index.cjs +16 -293
  16. package/node/index.cjs.map +1 -1
  17. package/node/index.d.cts +4 -40
  18. package/node/index.d.ts +4 -40
  19. package/node/index.js +22 -237
  20. package/node/index.js.map +1 -1
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +14 -6
  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 +73 -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 +102 -116
  59. package/web/index.cjs.map +1 -1
  60. package/web/index.d.cts +15 -29
  61. package/web/index.d.ts +15 -29
  62. package/web/index.js +91 -105
  63. package/web/index.js.map +1 -1
  64. package/web/metafile-cjs.json +1 -1
  65. package/web/metafile-esm.json +1 -1
  66. package/node/chunk-4A4RAVNS.js +0 -17
  67. package/node/chunk-4A4RAVNS.js.map +0 -1
  68. package/node/mem-filesystem-LPPT7QV5.js +0 -40
  69. package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
  70. package/tests/fireproof/config.test.ts +0 -163
  71. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
@@ -1,23 +1,27 @@
1
1
  import { CID } from "multiformats";
2
- import { bs, ensureSuperThis, NotFoundError, SuperThis } from "@fireproof/core";
2
+ import { rt, bs, NotFoundError, SuperThis, PARAM, DbMeta, ensureSuperThis } from "@fireproof/core";
3
+ import { noopUrl } from "../helpers.js";
4
+ import { Result } from "@adviser/cement";
3
5
 
4
6
  function runtime(sthis: SuperThis) {
5
- return bs.toStoreRuntime({}, sthis);
7
+ return bs.toStoreRuntime(sthis);
6
8
  }
7
9
 
8
- function mockLoader(sthis: SuperThis, name: string): bs.Loadable {
10
+ async function mockLoader(sthis: SuperThis, name?: string): Promise<bs.StoreFactoryItem> {
11
+ const url = noopUrl(name);
9
12
  return {
10
13
  sthis,
11
- name,
12
- ebOpts: {
13
- store: {},
14
- },
15
- } as bs.Loadable;
14
+ url: url,
15
+ loader: {
16
+ keyBag: () => rt.kb.getKeyBag(sthis),
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ handleDbMetasFromStore: (metas: DbMeta[]): Promise<void> => Promise.resolve(),
19
+ } as bs.Loader,
20
+ };
16
21
  }
17
22
 
18
23
  describe("DataStore", function () {
19
24
  let store: bs.DataStore;
20
- let raw: bs.TestGateway;
21
25
 
22
26
  const sthis = ensureSuperThis();
23
27
  afterEach(async () => {
@@ -27,13 +31,12 @@ describe("DataStore", function () {
27
31
 
28
32
  beforeEach(async () => {
29
33
  await sthis.start();
30
- store = await runtime(sthis).makeDataStore(mockLoader(sthis, "test"));
34
+ store = await runtime(sthis).makeDataStore(await mockLoader(sthis));
31
35
  await store.start();
32
- raw = await bs.testStoreFactory(store.url(), sthis);
33
36
  });
34
37
 
35
38
  it("should have a name", function () {
36
- expect(store.name).toEqual("test");
39
+ expect(store.url().getParam(PARAM.NAME)).toEqual("test");
37
40
  });
38
41
 
39
42
  it("should save a car", async function () {
@@ -42,14 +45,13 @@ describe("DataStore", function () {
42
45
  bytes: new Uint8Array([55, 56, 57]),
43
46
  };
44
47
  await store.save(car);
45
- const data = await raw.get(store.url(), car.cid.toString());
48
+ const data = (await store.realGateway.getPlain(sthis, store.url(), car.cid.toString())).Ok();
46
49
  expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
47
50
  });
48
51
  });
49
52
 
50
53
  describe("DataStore with a saved car", function () {
51
54
  let store: bs.DataStore;
52
- let raw: bs.TestGateway;
53
55
  let car: bs.AnyBlock;
54
56
 
55
57
  const sthis = ensureSuperThis();
@@ -61,9 +63,8 @@ describe("DataStore with a saved car", function () {
61
63
 
62
64
  beforeEach(async function () {
63
65
  await sthis.start();
64
- store = await runtime(sthis).makeDataStore(mockLoader(sthis, "test2"));
66
+ store = await runtime(sthis).makeDataStore(await mockLoader(sthis, "test2"));
65
67
  await store.start();
66
- raw = await bs.testStoreFactory(store.url(), sthis);
67
68
  car = {
68
69
  cid: "cid" as unknown as CID,
69
70
  bytes: new Uint8Array([55, 56, 57, 80]),
@@ -72,7 +73,7 @@ describe("DataStore with a saved car", function () {
72
73
  });
73
74
 
74
75
  it("should have a car", async function () {
75
- const data = await raw.get(store.url(), car.cid.toString());
76
+ const data = (await store.realGateway.getPlain(sthis, store.url(), car.cid.toString())).Ok();
76
77
  expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
77
78
  });
78
79
 
@@ -92,7 +93,6 @@ describe("DataStore with a saved car", function () {
92
93
 
93
94
  describe("MetaStore", function () {
94
95
  let store: bs.MetaStore;
95
- let raw: bs.TestGateway;
96
96
 
97
97
  const sthis = ensureSuperThis();
98
98
 
@@ -103,13 +103,12 @@ describe("MetaStore", function () {
103
103
 
104
104
  beforeEach(async function () {
105
105
  await sthis.start();
106
- store = await runtime(sthis).makeMetaStore(mockLoader(sthis, "test"));
106
+ store = await runtime(sthis).makeMetaStore(await mockLoader(sthis, "test"));
107
107
  await store.start();
108
- raw = await bs.testStoreFactory(store.url(), sthis);
109
108
  });
110
109
 
111
110
  it("should have a name", function () {
112
- expect(store.name).toEqual("test");
111
+ expect(store.url().getParam(PARAM.NAME)).toEqual("test");
113
112
  });
114
113
 
115
114
  it("should save a header", async function () {
@@ -119,9 +118,11 @@ describe("MetaStore", function () {
119
118
  // key: undefined,
120
119
  };
121
120
  await store.save(h);
122
- const file = await raw.get(store.url(), "main");
123
- const [blockMeta] = await store.handleByteHeads(file);
124
- const decodedHeader = blockMeta.dbMeta;
121
+ const file = await store.realGateway.getPlain(sthis, store.url(), "main");
122
+ const blockMeta = (await rt.gw.fpDeserialize(sthis, store.url(), file)) as Result<bs.FPEnvelopeMeta>;
123
+ expect(blockMeta.Ok()).toBeTruthy();
124
+ expect(blockMeta.Ok().payload.length).toEqual(1);
125
+ const decodedHeader = blockMeta.Ok().payload[0].dbMeta;
125
126
  expect(decodedHeader).toBeTruthy();
126
127
  expect(decodedHeader.cars).toBeTruthy();
127
128
  expect(decodedHeader.cars[0].toString()).toEqual(cid.toString());
@@ -130,7 +131,6 @@ describe("MetaStore", function () {
130
131
 
131
132
  describe("MetaStore with a saved header", function () {
132
133
  let store: bs.MetaStore;
133
- let raw: bs.TestGateway;
134
134
  let cid: CID;
135
135
  const sthis = ensureSuperThis();
136
136
 
@@ -141,22 +141,31 @@ describe("MetaStore with a saved header", function () {
141
141
 
142
142
  beforeEach(async function () {
143
143
  await sthis.start();
144
- store = await runtime(sthis).makeMetaStore(mockLoader(sthis, "test-saved-header"));
144
+ store = await runtime(sthis).makeMetaStore(await mockLoader(sthis, "test-saved-header"));
145
145
  await store.start();
146
- raw = await bs.testStoreFactory(store.url(), sthis);
147
146
  cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
148
147
  await store.save({ cars: [cid] /*, key: undefined */ });
149
148
  });
150
149
 
150
+ // it("should load", async function () {
151
+ // expect(onload).toBeTruthy();
152
+ // expect(onload?.length).toEqual(1);
153
+ // expect(onload?.[0].cars.toString()).toEqual(cid.toString());
154
+ // });
155
+
151
156
  it("should have a header", async function () {
152
- const bytes = await raw.get(store.url(), "main");
153
- const data = sthis.txt.decode(bytes);
157
+ const bytes = await store.realGateway.getPlain(sthis, store.url(), "main");
158
+ const data = sthis.txt.decode(bytes.Ok());
154
159
  expect(data).toMatch(/parents/);
155
160
  const header = JSON.parse(data)[0];
156
161
  expect(header).toBeDefined();
157
162
  expect(header.parents).toBeDefined();
158
- const [blockMeta] = await store.handleByteHeads(bytes);
159
- const decodedHeader = blockMeta.dbMeta;
163
+ // const [blockMeta] = await store.handleByteHeads(bytes);
164
+
165
+ const blockMeta = (await rt.gw.fpDeserialize(sthis, store.url(), bytes)) as Result<bs.FPEnvelopeMeta>;
166
+ expect(blockMeta.Ok()).toBeTruthy();
167
+ expect(blockMeta.Ok().payload.length).toEqual(1);
168
+ const decodedHeader = blockMeta.Ok().payload[0].dbMeta;
160
169
  expect(decodedHeader).toBeDefined();
161
170
  expect(decodedHeader.cars).toBeDefined();
162
171
  expect(decodedHeader.cars[0].toString()).toEqual(cid.toString());
@@ -1,18 +1,19 @@
1
1
  import { CID } from "multiformats";
2
2
  import { bs, ensureSuperThis, SuperThis } from "@fireproof/core";
3
+ import { simpleBlockOpts } from "../helpers.js";
3
4
 
4
5
  describe("Fresh TransactionBlockstore", function () {
5
6
  let blocks: bs.BaseBlockstore;
6
7
  const sthis = ensureSuperThis();
7
8
  beforeEach(function () {
8
- blocks = new bs.BaseBlockstore();
9
- });
10
- it("should not have a name", function () {
11
- expect(blocks.name).toBeFalsy();
12
- });
13
- it("should not have a loader", function () {
14
- expect(blocks.loader).toBeFalsy();
9
+ blocks = new bs.BaseBlockstore(simpleBlockOpts(sthis));
15
10
  });
11
+ // it("should not have a name", function () {
12
+ // expect(blocks.name).toBeFalsy();
13
+ // });
14
+ // it("should not have a loader", function () {
15
+ // expect(blocks.loader).toBeFalsy();
16
+ // });
16
17
  it("should not put", async function () {
17
18
  const value = sthis.txt.encode("value");
18
19
  const e = await blocks.put("key" as unknown as bs.AnyLink, value).catch((e) => e);
@@ -34,11 +35,11 @@ describe("TransactionBlockstore with name", function () {
34
35
  let blocks: bs.EncryptedBlockstore;
35
36
  const sthis = ensureSuperThis();
36
37
  beforeEach(function () {
37
- blocks = new bs.EncryptedBlockstore(sthis, { name: "test" });
38
- });
39
- it("should have a name", function () {
40
- expect(blocks.name).toEqual("test");
38
+ blocks = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis));
41
39
  });
40
+ // it("should have a name", function () {
41
+ // expect(blocks.name).toEqual("test");
42
+ // });
42
43
  it("should have a loader", function () {
43
44
  expect(blocks.loader).toBeTruthy();
44
45
  });
@@ -58,7 +59,7 @@ describe("A transaction", function () {
58
59
  let blocks: bs.EncryptedBlockstore;
59
60
  const sthis = ensureSuperThis();
60
61
  beforeEach(async function () {
61
- blocks = new bs.EncryptedBlockstore(sthis, { name: "test" });
62
+ blocks = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis, "test"));
62
63
  tblocks = new bs.CarTransaction(blocks);
63
64
  blocks.transactions.add(tblocks);
64
65
  });
@@ -88,7 +89,7 @@ describe("TransactionBlockstore with a completed transaction", function () {
88
89
  cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
89
90
  cid2 = CID.parse("bafybeibgouhn5ktecpjuovt52zamzvm4dlve5ak7x6d5smms3itkhplnhm");
90
91
 
91
- blocks = new bs.BaseBlockstore();
92
+ blocks = new bs.BaseBlockstore(simpleBlockOpts(sthis));
92
93
  await blocks.transaction(async (tblocks) => {
93
94
  await tblocks.put(cid, asUInt8Array("value", sthis));
94
95
  await tblocks.put(cid, asUInt8Array("value", sthis));