@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,16 +1,17 @@
1
- import { bs, ensureSuperThis, rt, SuperThis } from "@fireproof/core";
2
- import { BuildURI, Logger, MockLogger, runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
1
+ import { bs, ensureSuperThis, PARAM, rt } from "@fireproof/core";
2
+ import { BuildURI, runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
3
3
  import { base58btc } from "multiformats/bases/base58";
4
4
  import { sha256 as hasher } from "multiformats/hashes/sha2";
5
5
  import * as dagCodec from "@fireproof/vendor/@ipld/dag-cbor";
6
+ import type { KeyBagProviderIndexDB } from "@fireproof/core/web";
7
+ import { MockSuperThis, mockSuperThis } from "../helpers.js";
6
8
 
7
9
  describe("KeyBag", () => {
8
10
  let url: URI;
9
- let sthis: SuperThis;
10
- const mockLogger = MockLogger();
11
+ let sthis: MockSuperThis;
11
12
 
12
13
  beforeEach(async () => {
13
- sthis = ensureSuperThis({ logger: mockLogger.logger });
14
+ sthis = mockSuperThis();
14
15
  await sthis.start();
15
16
  if (runtimeFn().isBrowser) {
16
17
  url = URI.from("indexdb://fp-keybag");
@@ -54,7 +55,7 @@ describe("KeyBag", () => {
54
55
  });
55
56
  sthis.env.set("FP_KEYBAG_URL", old);
56
57
  await sthis.logger.Flush();
57
- expect(mockLogger.logCollector.Logs()).toEqual([
58
+ expect(sthis.ctx.logCollector.Logs()).toEqual([
58
59
  {
59
60
  level: "warn",
60
61
  module: "KeyBag",
@@ -88,11 +89,14 @@ describe("KeyBag", () => {
88
89
  let diskBag2: rt.kb.KeyItem;
89
90
  const provider = await kb.rt.getBag();
90
91
  if (runtimeFn().isBrowser) {
91
- const p = provider as rt.kb.KeyBagProviderIndexDB;
92
+ const p = provider as KeyBagProviderIndexDB;
92
93
  diskBag = await p._prepare().then((db) => db.get("bag", name));
93
94
  diskBag2 = await p._prepare().then((db) => db.get("bag", name2));
94
95
  } else {
95
- const p = provider as rt.kb.KeyBagProviderFile;
96
+ const p = provider as rt.gw.file.KeyBagProviderFile;
97
+ if (typeof p._prepare !== "function") {
98
+ return;
99
+ }
96
100
  const { sysFS } = await p._prepare(name);
97
101
 
98
102
  diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
@@ -121,99 +125,83 @@ describe("KeyBag", () => {
121
125
  });
122
126
 
123
127
  describe("KeyedCryptoStore", () => {
128
+ let loader: bs.Loadable;
124
129
  let kb: rt.kb.KeyBag;
125
- let logger: Logger;
130
+ // let logger: Logger;
126
131
  let baseUrl: URI;
127
132
  const sthis = ensureSuperThis();
128
133
  beforeEach(async () => {
129
134
  await sthis.start();
130
- logger = MockLogger().logger;
131
- let kbUrl: URI;
132
- if (runtimeFn().isBrowser) {
133
- kbUrl = URI.from("indexdb://fp-keybag");
134
- baseUrl = URI.from("indexdb://fp-keyed-crypto-store");
135
+ // logger = MockLogger().logger;
136
+ // let kbUrl: URI;
137
+ // if (runtimeFn().isBrowser) {
138
+ // kbUrl = URI.from("indexdb://fp-keybag");
139
+ // baseUrl = URI.from("indexdb://fp-keyed-crypto-store");
140
+ // } else {
141
+ // kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
142
+ // baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
143
+ // }
144
+ // baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
145
+
146
+ const envURL = sthis.env.get("FP_KEYBAG_URL");
147
+ if (envURL) {
148
+ baseUrl = bs.getDefaultURI(sthis, URI.from(envURL).protocol);
135
149
  } else {
136
- kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
137
- // baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
138
- baseUrl = URI.from(sthis.env.get("FP_STORAGE_URL"));
150
+ baseUrl = bs.getDefaultURI(sthis);
139
151
  }
140
- kb = await rt.kb.getKeyBag(sthis, {
141
- url: kbUrl,
142
- });
152
+ baseUrl = baseUrl.build().setParam(PARAM.NAME, "test").URI();
153
+ kb = await rt.kb.getKeyBag(sthis, {});
154
+ loader = {
155
+ keyBag: async () => kb,
156
+ } as bs.Loadable;
143
157
  });
144
158
  it("no crypto", async () => {
145
- const loader = {
146
- sthis,
147
- name: "test",
148
- ebOpts: {
149
- keyBag: {
150
- keyRuntime: kb.rt,
151
- },
152
- store: {
153
- stores: {
154
- base: baseUrl.build().setParam("storekey", "insecure"),
155
- },
156
- },
157
- },
158
- } as unknown as bs.Loadable;
159
- const strt = bs.toStoreRuntime({}, sthis);
159
+ const strt = bs.toStoreRuntime(sthis);
160
+ const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
160
161
 
161
- for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
162
+ for (const pstore of [
163
+ strt.makeDataStore({ sthis, url, loader }),
164
+ strt.makeMetaStore({ sthis, url, loader }),
165
+ strt.makeWALStore({ sthis, url, loader }),
166
+ ]) {
162
167
  const store = await pstore;
163
168
  // await store.start();
164
169
  const kc = await store.keyedCrypto();
165
170
  expect(kc.constructor.name).toBe("noCrypto");
166
171
  // expect(kc.isEncrypting).toBe(false);
172
+ expect(kc.constructor.name).toBe("noCrypto");
173
+ // expect(kc.isEncrypting).toBe(false);
167
174
  }
168
175
  });
169
176
 
170
177
  it("create key", async () => {
171
- const loader = {
172
- sthis,
173
- name: "test",
174
- ebOpts: {
175
- keyBag: {
176
- keyRuntime: kb.rt,
177
- },
178
- store: {
179
- stores: {
180
- base: baseUrl,
181
- },
182
- },
183
- },
184
- } as unknown as bs.Loadable;
185
- const strt = bs.toStoreRuntime({}, sthis);
186
- for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
187
- const store = await bs.ensureStart(await pstore, logger);
178
+ const strt = bs.toStoreRuntime(sthis);
179
+ for (const pstore of [
180
+ strt.makeDataStore({ sthis, url: baseUrl, loader }),
181
+ strt.makeMetaStore({ sthis, url: baseUrl, loader }),
182
+ strt.makeWALStore({ sthis, url: baseUrl, loader }),
183
+ ]) {
184
+ const store = await pstore; // await bs.ensureStart(await pstore, logger);
188
185
  const kc = await store.keyedCrypto();
189
186
  expect(kc.constructor.name).toBe("keyedCrypto");
190
187
  // expect(kc.isEncrypting).toBe(true);
191
- expect(store.url().getParam("storekey")).toBe(`@test:${store.url().getParam("store")}@`);
188
+ expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@test:${store.url().getParam(PARAM.STORE)}@`);
192
189
  }
193
190
  });
194
191
 
195
192
  it("key ref keybag", async () => {
196
193
  const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
197
194
  const genKey = await kb.setNamedKey("@heute@", key);
198
- const loader = {
199
- sthis,
200
- name: "test",
201
- ebOpts: {
202
- keyBag: {
203
- keyRuntime: kb.rt,
204
- },
205
- store: {
206
- stores: {
207
- base: baseUrl.build().setParam("storekey", "@heute@").URI(),
208
- },
209
- },
210
- },
211
- } as unknown as bs.Loadable;
212
- const strt = bs.toStoreRuntime({}, sthis);
213
- for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
195
+ const url = baseUrl.build().setParam(PARAM.STORE_KEY, "@heute@").URI();
196
+ const strt = bs.toStoreRuntime(sthis);
197
+ for (const pstore of [
198
+ strt.makeDataStore({ sthis, url, loader }),
199
+ strt.makeMetaStore({ sthis, url, loader }),
200
+ strt.makeWALStore({ sthis, url, loader }),
201
+ ]) {
214
202
  const store = await pstore;
215
203
  // await store.start();
216
- expect(store.url().getParam("storekey")).toBe(`@heute@`);
204
+ expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@heute@`);
217
205
  const kc = await store.keyedCrypto();
218
206
  expect(kc.constructor.name).toBe("keyedCrypto");
219
207
  const testData = kb.rt.crypto.randomBytes(1024);
@@ -229,25 +217,17 @@ describe("KeyedCryptoStore", () => {
229
217
 
230
218
  it("key", async () => {
231
219
  const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
232
- const loader = {
233
- sthis,
234
- name: "test",
235
- ebOpts: {
236
- keyBag: {
237
- keyRuntime: kb.rt,
238
- },
239
- store: {
240
- stores: {
241
- base: BuildURI.from(baseUrl).setParam("storekey", key),
242
- },
243
- },
244
- },
245
- } as unknown as bs.Loadable;
246
- const strt = bs.toStoreRuntime({}, sthis);
247
- for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
220
+ const strt = bs.toStoreRuntime(sthis);
221
+ const url = baseUrl.build().setParam(PARAM.STORE_KEY, key).URI();
222
+ for (const pstore of [
223
+ strt.makeDataStore({ sthis, url, loader }),
224
+ strt.makeMetaStore({ sthis, url, loader }),
225
+ strt.makeWALStore({ sthis, url, loader }),
226
+ ]) {
227
+ // for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
248
228
  const store = await pstore;
249
229
  // await store.start();
250
- expect(store.url().getParam("storekey")).toBe(key);
230
+ expect(store.url().getParam(PARAM.STORE_KEY)).toBe(key);
251
231
  const kc = await store.keyedCrypto();
252
232
  expect(kc.constructor.name).toBe("keyedCrypto");
253
233
  const testData = kb.rt.crypto.randomBytes(1024);
@@ -266,14 +246,14 @@ describe("KeyedCrypto", () => {
266
246
  let keyStr: string;
267
247
  const sthis = ensureSuperThis();
268
248
  beforeEach(async () => {
269
- let url: URI;
270
- if (runtimeFn().isBrowser) {
271
- url = URI.from("indexdb://fp-keybag");
272
- } else {
273
- url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
274
- }
249
+ // let url: URI;
250
+ // if (runtimeFn().isBrowser) {
251
+ // url = URI.from("indexdb://fp-keybag");
252
+ // } else {
253
+ // url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
254
+ // }
275
255
  kb = await rt.kb.getKeyBag(sthis, {
276
- url,
256
+ // url,
277
257
  });
278
258
  keyStr = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
279
259
  kycr = await rt.kc.keyedCryptoFactory(URI.from(`test://bla?storekey=${keyStr}`), kb, sthis);
@@ -307,26 +287,3 @@ describe("KeyedCrypto", () => {
307
287
  expect(blk).toEqual(blk2);
308
288
  });
309
289
  });
310
-
311
- // describe("KeyedCryptoStore RunLength", () => {
312
- // const logger = MockLogger().logger;
313
- // it("de/encode", () => {
314
- // for (const data of [
315
- // new Uint8Array(),
316
- // new Uint8Array(10).fill(10),
317
- // new Uint8Array(127).fill(127),
318
- // new Uint8Array(128).fill(128),
319
- // new Uint8Array(1024).fill(17),
320
- // ]) {
321
- // const res = rt.kc.encodeRunLength(data, logger);
322
- // expect(res.length).toBeLessThanOrEqual(data.length + (data.length > 127 ? 4 : 1));
323
- // for (let ofs = 0; ofs < 1024; ofs += 61) {
324
- // const ofsRes = new Uint8Array([...new Uint8Array(ofs).fill(23), ...res]);
325
- // const dec = rt.kc.decodeRunLength(ofsRes, ofs, logger);
326
- // expect(dec.data).toEqual(data);
327
- // expect(dec.data.length).toBe(data.length);
328
- // expect(dec.next).toBe(ofs + data.length + (data.length > 127 ? 4 : 1));
329
- // }
330
- // }
331
- // });
332
- // });
@@ -4,16 +4,18 @@ import { BlockView } from "multiformats";
4
4
  import { CID } from "multiformats/cid";
5
5
  import { MemoryBlockstore } from "@fireproof/vendor/@web3-storage/pail/block";
6
6
  import { CRDTMeta, IndexTransactionMeta, SuperThis, bs, ensureSuperThis, rt } from "@fireproof/core";
7
+ import { simpleBlockOpts } from "../helpers.js";
7
8
 
8
9
  class MyMemoryBlockStore extends bs.EncryptedBlockstore {
9
10
  readonly memblock = new MemoryBlockstore();
10
11
  loader: bs.Loader;
11
12
  constructor(sthis: SuperThis) {
12
- const ebOpts = {
13
- name: "MyMemoryBlockStore",
14
- };
13
+ const ebOpts = simpleBlockOpts(sthis, "MyMemoryBlockStore"); //, "MyMemoryBlockStore");
14
+ // const ebOpts = {
15
+ // name: "MyMemoryBlockStore",
16
+ // } as bs.BlockstoreOpts;
15
17
  super(sthis, ebOpts);
16
- this.loader = new bs.Loader("MyMemoryBlockStore", {}, sthis);
18
+ this.loader = new bs.Loader(sthis, ebOpts);
17
19
  }
18
20
  ready(): Promise<void> {
19
21
  return Promise.resolve();
@@ -62,7 +64,10 @@ describe("basic Loader simple", function () {
62
64
  await sthis.start();
63
65
  const mockM = new MyMemoryBlockStore(sthis);
64
66
  t = new bs.CarTransaction(mockM as bs.EncryptedBlockstore);
65
- loader = new bs.Loader(testDbName, { public: true }, sthis);
67
+ loader = new bs.Loader(sthis, {
68
+ ...simpleBlockOpts(sthis, testDbName),
69
+ public: true,
70
+ });
66
71
  await loader.ready();
67
72
  block = await rt.mf.block.encode({
68
73
  value: { hello: "world" },
@@ -105,11 +110,15 @@ describe("basic Loader with two commits", function () {
105
110
  await loader.destroy();
106
111
  });
107
112
 
108
- beforeEach(async function () {
113
+ beforeEach(async () => {
109
114
  await sthis.start();
110
115
  const mockM = new MyMemoryBlockStore(sthis);
111
116
  t = new bs.CarTransaction(mockM);
112
- loader = new bs.Loader("test-loader-two-commit", { public: true }, sthis);
117
+ loader = new bs.Loader(sthis, {
118
+ ...simpleBlockOpts(sthis, "test-loader-two-commit"),
119
+ public: true,
120
+ });
121
+
113
122
  block = await rt.mf.block.encode({
114
123
  value: { hello: "world" },
115
124
  hasher,
@@ -211,7 +220,7 @@ describe("basic Loader with index commits", function () {
211
220
  const name = "test-loader-index" + Math.random();
212
221
  await sthis.start();
213
222
  // t = new CarTransaction()
214
- ib = new bs.EncryptedBlockstore(sthis, { name });
223
+ ib = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis, name));
215
224
  block = await rt.mf.block.encode({
216
225
  value: { hello: "world" },
217
226
  hasher,
@@ -255,7 +264,7 @@ describe("basic Loader with index commits", function () {
255
264
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
256
265
  const reader = await ib.loader.loadCar(carCid![0]);
257
266
  expect(reader).toBeTruthy();
258
- const parsed = await bs.parseCarFile<IndexTransactionMeta>(reader, ib.loader.logger);
267
+ const parsed = await bs.parseCarFile<IndexTransactionMeta>(reader, sthis.logger);
259
268
  expect(parsed.cars).toBeTruthy();
260
269
  expect(parsed.cars.length).toBe(0);
261
270
  expect(parsed.meta).toBeTruthy();
@@ -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));