@fireproof/core 0.20.0-dev-preview-39 → 0.20.0-dev-preview-41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/deno/index.js +2 -2
- package/deno/index.js.map +1 -1
- package/index.cjs +499 -370
- package/index.cjs.map +1 -1
- package/index.d.cts +162 -64
- package/index.d.ts +162 -64
- package/index.js +473 -344
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/react/index.cjs +28 -11
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +2 -1
- package/react/index.d.ts +2 -1
- package/react/index.js +29 -12
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/interceptor-gateway.test.ts +5 -1
- package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +8 -18
- package/tests/blockstore/keyed-crypto.test.ts +7 -30
- package/tests/blockstore/loader.test.ts +19 -17
- package/tests/blockstore/store.test.ts +48 -51
- package/tests/blockstore/transaction.test.ts +13 -11
- package/tests/fireproof/all-gateway.test.ts +49 -46
- package/tests/fireproof/attachable.test.ts +82 -0
- package/tests/fireproof/crdt.test.ts +49 -48
- package/tests/fireproof/database.test.ts +40 -40
- package/tests/fireproof/fireproof.test.ts +43 -42
- package/tests/fireproof/hello.test.ts +4 -4
- package/tests/fireproof/indexer.test.ts +44 -44
- package/tests/fireproof/utils.test.ts +4 -3
- package/tests/gateway/file/loader-config.test.ts +17 -17
- package/tests/gateway/indexeddb/loader-config.test.ts +4 -4
- package/tests/helpers.ts +80 -2
- package/tests/react/useFireproof.test.tsx +79 -4
@@ -1,9 +1,8 @@
|
|
1
1
|
import { bs, ensureSuperThis, PARAM, rt } from "@fireproof/core";
|
2
2
|
import { runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
|
3
3
|
import { base58btc } from "multiformats/bases/base58";
|
4
|
-
import { mockSuperThis } from "../helpers.js";
|
4
|
+
import { mockLoader, mockSuperThis } from "../helpers.js";
|
5
5
|
import { KeyBagProviderIndexedDB } from "@fireproof/core/indexeddb";
|
6
|
-
import { toKeyWithFingerPrint } from "../../src/runtime/key-bag.js";
|
7
6
|
|
8
7
|
describe("KeyBag indexeddb and file", () => {
|
9
8
|
let url: URI;
|
@@ -73,10 +72,10 @@ describe("KeyBag indexeddb and file", () => {
|
|
73
72
|
return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeysItem;
|
74
73
|
});
|
75
74
|
}
|
76
|
-
expect((await toKeyWithFingerPrint(kb, Object.values(diskBag.keys)[0].key)).Ok().fingerPrint).toEqual(
|
75
|
+
expect((await rt.kb.toKeyWithFingerPrint(kb, Object.values(diskBag.keys)[0].key)).Ok().fingerPrint).toEqual(
|
77
76
|
(await res.Ok().get())?.fingerPrint,
|
78
77
|
);
|
79
|
-
expect((await toKeyWithFingerPrint(kb, Object.values(diskBag2.keys)[0].key)).Ok().fingerPrint).toEqual(
|
78
|
+
expect((await rt.kb.toKeyWithFingerPrint(kb, Object.values(diskBag2.keys)[0].key)).Ok().fingerPrint).toEqual(
|
80
79
|
(await created.Ok().get())?.fingerPrint,
|
81
80
|
);
|
82
81
|
const algo = {
|
@@ -105,29 +104,20 @@ describe("KeyedCryptoStore", () => {
|
|
105
104
|
beforeEach(async () => {
|
106
105
|
await sthis.start();
|
107
106
|
// logger = MockLogger().logger;
|
108
|
-
let kbUrl: URI;
|
107
|
+
// let kbUrl: URI;
|
109
108
|
if (runtimeFn().isBrowser) {
|
110
|
-
kbUrl = URI.from("indexeddb://fp-keybag");
|
109
|
+
// kbUrl = URI.from("indexeddb://fp-keybag");
|
111
110
|
baseUrl = URI.from("indexeddb://fp-keyed-crypto-store");
|
112
111
|
} else {
|
113
|
-
kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
112
|
+
// kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
114
113
|
baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
115
114
|
}
|
116
115
|
baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
|
117
|
-
loader =
|
118
|
-
sthis,
|
119
|
-
keyBag: () => rt.kb.getKeyBag(sthis, { url: kbUrl }),
|
120
|
-
} as bs.Loadable;
|
116
|
+
loader = mockLoader(sthis);
|
121
117
|
});
|
122
118
|
it("no crypto", async () => {
|
123
|
-
const strt = bs.toStoreRuntime(sthis);
|
124
119
|
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
125
|
-
|
126
|
-
for (const pstore of [
|
127
|
-
strt.makeDataStore({ url, loader }),
|
128
|
-
strt.makeMetaStore({ url, loader }),
|
129
|
-
strt.makeWALStore({ url, loader }),
|
130
|
-
]) {
|
120
|
+
for (const pstore of (await bs.createAttachedStores(url, loader, "insecure")).stores.baseStores) {
|
131
121
|
const store = await pstore;
|
132
122
|
// await store.start();
|
133
123
|
const kc = await store.keyedCrypto();
|
@@ -4,7 +4,7 @@ import { base58btc } from "multiformats/bases/base58";
|
|
4
4
|
import { sha256 as hasher } from "multiformats/hashes/sha2";
|
5
5
|
import * as dagCodec from "@ipld/dag-cbor";
|
6
6
|
import type { KeyBagProviderIndexedDB } from "@fireproof/core/indexeddb";
|
7
|
-
import { MockSuperThis, mockSuperThis } from "../helpers.js";
|
7
|
+
import { mockLoader, MockSuperThis, mockSuperThis } from "../helpers.js";
|
8
8
|
import { KeyWithFingerPrint } from "../../src/blockstore/types.js";
|
9
9
|
import { toKeyWithFingerPrint } from "../../src/runtime/key-bag.js";
|
10
10
|
|
@@ -230,11 +230,11 @@ describe("KeyBag", () => {
|
|
230
230
|
});
|
231
231
|
|
232
232
|
describe("KeyedCryptoStore", () => {
|
233
|
-
let loader: bs.Loadable;
|
234
233
|
let kb: rt.kb.KeyBag;
|
235
234
|
// let logger: Logger;
|
236
235
|
let baseUrl: URI;
|
237
236
|
const sthis = ensureSuperThis();
|
237
|
+
let loader: bs.Loadable;
|
238
238
|
beforeEach(async () => {
|
239
239
|
await sthis.start();
|
240
240
|
// logger = MockLogger().logger;
|
@@ -256,20 +256,12 @@ describe("KeyedCryptoStore", () => {
|
|
256
256
|
}
|
257
257
|
baseUrl = baseUrl.build().setParam(PARAM.NAME, "test").URI();
|
258
258
|
kb = await rt.kb.getKeyBag(sthis, {});
|
259
|
-
loader =
|
260
|
-
sthis,
|
261
|
-
keyBag: async () => kb,
|
262
|
-
} as bs.Loadable;
|
259
|
+
loader = mockLoader(sthis);
|
263
260
|
});
|
264
261
|
it("no crypto", async () => {
|
265
|
-
const strt = bs.toStoreRuntime(sthis);
|
266
262
|
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
267
263
|
|
268
|
-
for (const pstore of
|
269
|
-
strt.makeDataStore({ url, loader }),
|
270
|
-
strt.makeMetaStore({ url, loader }),
|
271
|
-
strt.makeWALStore({ url, loader }),
|
272
|
-
]) {
|
264
|
+
for (const pstore of (await bs.createAttachedStores(url, loader, "insecure")).stores.baseStores) {
|
273
265
|
const store = await pstore;
|
274
266
|
// await store.start();
|
275
267
|
const kc = await store.keyedCrypto();
|
@@ -281,12 +273,7 @@ describe("KeyedCryptoStore", () => {
|
|
281
273
|
});
|
282
274
|
|
283
275
|
it("create key", async () => {
|
284
|
-
const
|
285
|
-
for (const pstore of [
|
286
|
-
strt.makeDataStore({ url: baseUrl, loader }),
|
287
|
-
strt.makeMetaStore({ url: baseUrl, loader }),
|
288
|
-
strt.makeWALStore({ url: baseUrl, loader }),
|
289
|
-
]) {
|
276
|
+
for (const pstore of (await bs.createAttachedStores(baseUrl, loader, "insecure")).stores.baseStores) {
|
290
277
|
const store = await pstore; // await bs.ensureStart(await pstore, logger);
|
291
278
|
const kc = await store.keyedCrypto();
|
292
279
|
expect(kc.constructor.name).toBe("cryptoAction");
|
@@ -299,12 +286,7 @@ describe("KeyedCryptoStore", () => {
|
|
299
286
|
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
300
287
|
const genKey = await kb.getNamedKey("@heute@", false, key);
|
301
288
|
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "@heute@").URI();
|
302
|
-
const
|
303
|
-
for (const pstore of [
|
304
|
-
strt.makeDataStore({ url, loader }),
|
305
|
-
strt.makeMetaStore({ url, loader }),
|
306
|
-
strt.makeWALStore({ url, loader }),
|
307
|
-
]) {
|
289
|
+
for (const pstore of (await bs.createAttachedStores(url, loader, "insecure")).stores.baseStores) {
|
308
290
|
const store = await pstore;
|
309
291
|
// await store.start();
|
310
292
|
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@heute@`);
|
@@ -324,13 +306,8 @@ describe("KeyedCryptoStore", () => {
|
|
324
306
|
|
325
307
|
it("key", async () => {
|
326
308
|
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
327
|
-
const strt = bs.toStoreRuntime(sthis);
|
328
309
|
const url = baseUrl.build().setParam(PARAM.STORE_KEY, key).URI();
|
329
|
-
for (const pstore of
|
330
|
-
strt.makeDataStore({ url, loader }),
|
331
|
-
strt.makeMetaStore({ url, loader }),
|
332
|
-
strt.makeWALStore({ url, loader }),
|
333
|
-
]) {
|
310
|
+
for (const pstore of (await bs.createAttachedStores(url, loader, "insecure")).stores.baseStores) {
|
334
311
|
// for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
|
335
312
|
const store = await pstore;
|
336
313
|
// await store.start();
|
@@ -54,12 +54,12 @@ describe("basic Loader simple", function () {
|
|
54
54
|
let t: CarTransaction;
|
55
55
|
const sthis = ensureSuperThis();
|
56
56
|
|
57
|
-
afterEach(async
|
57
|
+
afterEach(async () => {
|
58
58
|
await loader.close();
|
59
59
|
await loader.destroy();
|
60
60
|
});
|
61
61
|
|
62
|
-
beforeEach(async
|
62
|
+
beforeEach(async () => {
|
63
63
|
const testDbName = "test-loader-commit";
|
64
64
|
await sthis.start();
|
65
65
|
const mockM = new MyMemoryBlockStore(sthis);
|
@@ -80,10 +80,10 @@ describe("basic Loader simple", function () {
|
|
80
80
|
it("should have an empty car log", function () {
|
81
81
|
expect(loader.carLog.length).toBe(0);
|
82
82
|
});
|
83
|
-
it("should commit", async
|
83
|
+
it("should commit", async () => {
|
84
84
|
const carGroup = await loader.commit(t, { head: [block.cid] });
|
85
85
|
expect(loader.carLog.length).toBe(1);
|
86
|
-
const reader = await loader.loadCar(carGroup[0]);
|
86
|
+
const reader = await loader.loadCar(carGroup[0], loader.attachedStores.local());
|
87
87
|
expect(reader).toBeTruthy();
|
88
88
|
const parsed = await bs.parseCarFile<CRDTMeta>(reader, loader.logger);
|
89
89
|
expect(parsed.cars).toBeTruthy();
|
@@ -105,7 +105,7 @@ describe("basic Loader with two commits", function () {
|
|
105
105
|
|
106
106
|
const sthis = ensureSuperThis();
|
107
107
|
|
108
|
-
afterEach(async
|
108
|
+
afterEach(async () => {
|
109
109
|
await loader.close();
|
110
110
|
await loader.destroy();
|
111
111
|
});
|
@@ -118,6 +118,7 @@ describe("basic Loader with two commits", function () {
|
|
118
118
|
...simpleBlockOpts(sthis, "test-loader-two-commit"),
|
119
119
|
public: true,
|
120
120
|
});
|
121
|
+
await loader.ready();
|
121
122
|
|
122
123
|
block = await rt.mf.block.encode({
|
123
124
|
value: { hello: "world" },
|
@@ -157,8 +158,8 @@ describe("basic Loader with two commits", function () {
|
|
157
158
|
expect(loader.carLog[1].toString()).toBe(carCid0.toString());
|
158
159
|
});
|
159
160
|
|
160
|
-
it("should commit", async
|
161
|
-
const reader = await loader.loadCar(carCid[0]);
|
161
|
+
it("should commit", async () => {
|
162
|
+
const reader = await loader.loadCar(carCid[0], loader.attachedStores.local());
|
162
163
|
expect(reader).toBeTruthy();
|
163
164
|
const parsed = await bs.parseCarFile<CRDTMeta>(reader, loader.logger);
|
164
165
|
expect(parsed.cars).toBeTruthy();
|
@@ -168,11 +169,11 @@ describe("basic Loader with two commits", function () {
|
|
168
169
|
expect(parsed.meta.head).toBeTruthy();
|
169
170
|
});
|
170
171
|
|
171
|
-
it("should compact", async
|
172
|
+
it("should compact", async () => {
|
172
173
|
const compactCid = await loader.commit(t, { head: [block2.cid] }, { compact: true });
|
173
174
|
expect(loader.carLog.length).toBe(1);
|
174
175
|
|
175
|
-
const reader = await loader.loadCar(compactCid[0]);
|
176
|
+
const reader = await loader.loadCar(compactCid[0], loader.attachedStores.local());
|
176
177
|
expect(reader).toBeTruthy();
|
177
178
|
const parsed = await bs.parseCarFile<CRDTMeta>(reader, loader.logger);
|
178
179
|
expect(parsed.cars).toBeTruthy();
|
@@ -182,8 +183,8 @@ describe("basic Loader with two commits", function () {
|
|
182
183
|
expect(parsed.meta.head).toBeTruthy();
|
183
184
|
});
|
184
185
|
|
185
|
-
it("compact should erase old files", async
|
186
|
-
const cs = await loader.
|
186
|
+
it("compact should erase old files", async () => {
|
187
|
+
const cs = await loader.attachedStores.local().active.car;
|
187
188
|
await loader.commit(t, { head: [block2.cid] }, { compact: true });
|
188
189
|
expect(loader.carLog.length).toBe(1);
|
189
190
|
await loader.commit(t, { head: [block3.cid] }, { compact: false });
|
@@ -196,10 +197,10 @@ describe("basic Loader with two commits", function () {
|
|
196
197
|
await loader.commit(t, { head: [block4.cid] }, { compact: false });
|
197
198
|
expect(loader.carLog.length).toBe(2);
|
198
199
|
|
199
|
-
const e = await loader.loadCar(carCid[0]).catch((e) => e);
|
200
|
+
const e = await loader.loadCar(carCid[0], loader.attachedStores.local()).catch((e) => e);
|
200
201
|
expect(e).toBeTruthy();
|
201
202
|
expect(e instanceof Error).toBeTruthy();
|
202
|
-
expect(e.message).toMatch(
|
203
|
+
expect(e.message).toMatch(/(missing car file)|(not found)/);
|
203
204
|
}, 10000);
|
204
205
|
});
|
205
206
|
|
@@ -211,16 +212,17 @@ describe("basic Loader with index commits", function () {
|
|
211
212
|
// let indexMap: Map<string, CID>;
|
212
213
|
const sthis = ensureSuperThis();
|
213
214
|
|
214
|
-
afterEach(async
|
215
|
+
afterEach(async () => {
|
215
216
|
await ib.close();
|
216
217
|
await ib.destroy();
|
217
218
|
});
|
218
219
|
|
219
|
-
beforeEach(async
|
220
|
+
beforeEach(async () => {
|
220
221
|
const name = "test-loader-index" + Math.random();
|
221
222
|
await sthis.start();
|
222
223
|
// t = new CarTransaction()
|
223
224
|
ib = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis, name));
|
225
|
+
await ib.ready();
|
224
226
|
block = await rt.mf.block.encode({
|
225
227
|
value: { hello: "world" },
|
226
228
|
hasher,
|
@@ -248,7 +250,7 @@ describe("basic Loader with index commits", function () {
|
|
248
250
|
expect(ib.loader.carLog.length).toBe(0);
|
249
251
|
});
|
250
252
|
|
251
|
-
it("should commit the index metadata", async
|
253
|
+
it("should commit the index metadata", async () => {
|
252
254
|
const { cars: carCid } = await ib.transaction<IndexTransactionMeta>(
|
253
255
|
async (t) => {
|
254
256
|
await t.put(block.cid, block.bytes);
|
@@ -262,7 +264,7 @@ describe("basic Loader with index commits", function () {
|
|
262
264
|
|
263
265
|
expect(carLog.length).toBe(1);
|
264
266
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
265
|
-
const reader = await ib.loader.loadCar(carCid![0]);
|
267
|
+
const reader = await ib.loader.loadCar(carCid![0], ib.loader.attachedStores.local());
|
266
268
|
expect(reader).toBeTruthy();
|
267
269
|
const parsed = await bs.parseCarFile<IndexTransactionMeta>(reader, sthis.logger);
|
268
270
|
expect(parsed.cars).toBeTruthy();
|
@@ -1,30 +1,26 @@
|
|
1
1
|
import { CID } from "multiformats";
|
2
|
-
import { rt, bs, NotFoundError,
|
3
|
-
import { noopUrl } from "../helpers.js";
|
2
|
+
import { rt, bs, NotFoundError, PARAM, ensureSuperThis } from "@fireproof/core";
|
4
3
|
import { Result } from "@adviser/cement";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
} as bs.Loader,
|
21
|
-
};
|
22
|
-
}
|
4
|
+
import { createAttachedStores } from "../../src/blockstore/attachable-store.js";
|
5
|
+
import { mockLoader, noopUrl } from "../helpers.js";
|
6
|
+
|
7
|
+
// function runtime(sthis: SuperThis) {
|
8
|
+
// return bs.toStoreRuntime(sthis);
|
9
|
+
// }
|
10
|
+
|
11
|
+
// async function mockLoader(sthis: SuperThis, name?: string): Promise<bs.StoreFactoryItem> {
|
12
|
+
// const url = noopUrl(name);
|
13
|
+
// return {
|
14
|
+
// // sthis,
|
15
|
+
// url: url,
|
16
|
+
// loader:
|
17
|
+
// };
|
18
|
+
// }
|
23
19
|
|
24
20
|
describe("DataStore", function () {
|
25
21
|
let store: bs.DataStore;
|
26
22
|
const sthis = ensureSuperThis();
|
27
|
-
|
23
|
+
const loader = mockLoader(sthis);
|
28
24
|
|
29
25
|
afterEach(async () => {
|
30
26
|
await store.close();
|
@@ -33,22 +29,22 @@ describe("DataStore", function () {
|
|
33
29
|
|
34
30
|
beforeEach(async () => {
|
35
31
|
await sthis.start();
|
36
|
-
|
37
|
-
store =
|
38
|
-
await store.start();
|
32
|
+
const at = await createAttachedStores(noopUrl("test"), loader);
|
33
|
+
store = at.stores.car;
|
34
|
+
await store.start(at.stores);
|
39
35
|
});
|
40
36
|
|
41
37
|
it("should have a name", function () {
|
42
38
|
expect(store.url().getParam(PARAM.NAME)).toEqual("test");
|
43
39
|
});
|
44
40
|
|
45
|
-
it("should save a car", async
|
41
|
+
it("should save a car", async () => {
|
46
42
|
const car: bs.AnyBlock = {
|
47
43
|
cid: "cidKey" as unknown as CID,
|
48
44
|
bytes: new Uint8Array([55, 56, 57]),
|
49
45
|
};
|
50
46
|
await store.save(car);
|
51
|
-
const data = (await store.realGateway.getPlain(loader, store.url(), car.cid.toString())).Ok();
|
47
|
+
const data = (await store.realGateway.getPlain({ loader }, store.url(), car.cid.toString())).Ok();
|
52
48
|
expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
|
53
49
|
});
|
54
50
|
});
|
@@ -56,20 +52,21 @@ describe("DataStore", function () {
|
|
56
52
|
describe("DataStore with a saved car", function () {
|
57
53
|
let store: bs.DataStore;
|
58
54
|
let car: bs.AnyBlock;
|
59
|
-
let loader: bs.StoreFactoryItem;
|
60
55
|
|
61
56
|
const sthis = ensureSuperThis();
|
57
|
+
const loader = mockLoader(sthis);
|
62
58
|
|
63
59
|
afterEach(async () => {
|
64
60
|
await store.close();
|
65
61
|
await store.destroy();
|
66
62
|
});
|
67
63
|
|
68
|
-
beforeEach(async
|
64
|
+
beforeEach(async () => {
|
69
65
|
await sthis.start();
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
|
67
|
+
const at = await createAttachedStores(noopUrl("test2"), loader);
|
68
|
+
store = at.stores.car;
|
69
|
+
await store.start(at.stores);
|
73
70
|
car = {
|
74
71
|
cid: "cid" as unknown as CID,
|
75
72
|
bytes: new Uint8Array([55, 56, 57, 80]),
|
@@ -77,19 +74,19 @@ describe("DataStore with a saved car", function () {
|
|
77
74
|
await store.save(car);
|
78
75
|
});
|
79
76
|
|
80
|
-
it("should have a car", async
|
81
|
-
const data = (await store.realGateway.getPlain(loader, store.url(), car.cid.toString())).Ok();
|
77
|
+
it("should have a car", async () => {
|
78
|
+
const data = (await store.realGateway.getPlain({ loader }, store.url(), car.cid.toString())).Ok();
|
82
79
|
expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
|
83
80
|
});
|
84
81
|
|
85
|
-
it("should load a car", async
|
82
|
+
it("should load a car", async () => {
|
86
83
|
const loaded = await store.load(car.cid);
|
87
84
|
expect(loaded.cid).toEqual(car.cid);
|
88
85
|
expect(loaded.bytes.constructor.name).toEqual("Uint8Array");
|
89
86
|
expect(loaded.bytes.toString()).toEqual(car.bytes.toString());
|
90
87
|
});
|
91
88
|
|
92
|
-
it("should remove a car", async
|
89
|
+
it("should remove a car", async () => {
|
93
90
|
await store.remove(car.cid);
|
94
91
|
const { e: error } = (await store.load(car.cid).catch((e: Error) => ({ e }))) as { e: NotFoundError };
|
95
92
|
expect(error).toBeTruthy();
|
@@ -99,32 +96,32 @@ describe("DataStore with a saved car", function () {
|
|
99
96
|
describe("MetaStore", function () {
|
100
97
|
let store: bs.MetaStore;
|
101
98
|
const sthis = ensureSuperThis();
|
102
|
-
|
99
|
+
const loader = mockLoader(sthis);
|
103
100
|
|
104
101
|
afterEach(async () => {
|
105
102
|
await store.close();
|
106
103
|
await store.destroy();
|
107
104
|
});
|
108
105
|
|
109
|
-
beforeEach(async
|
106
|
+
beforeEach(async () => {
|
110
107
|
await sthis.start();
|
111
|
-
|
112
|
-
store =
|
113
|
-
await store.start();
|
108
|
+
const at = await createAttachedStores(noopUrl("test"), loader);
|
109
|
+
store = at.stores.meta;
|
110
|
+
await store.start(at.stores);
|
114
111
|
});
|
115
112
|
|
116
113
|
it("should have a name", function () {
|
117
114
|
expect(store.url().getParam(PARAM.NAME)).toEqual("test");
|
118
115
|
});
|
119
116
|
|
120
|
-
it("should save a header", async
|
117
|
+
it("should save a header", async () => {
|
121
118
|
const cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
122
119
|
const h: bs.DbMeta = {
|
123
120
|
cars: [cid],
|
124
121
|
// key: undefined,
|
125
122
|
};
|
126
123
|
await store.save(h);
|
127
|
-
const file = await store.realGateway.getPlain(loader, store.url(), "main");
|
124
|
+
const file = await store.realGateway.getPlain({ loader }, store.url(), "main");
|
128
125
|
const blockMeta = (await rt.gw.fpDeserialize(sthis, store.url(), file)) as Result<bs.FPEnvelopeMeta>;
|
129
126
|
expect(blockMeta.Ok()).toBeTruthy();
|
130
127
|
expect(blockMeta.Ok().payload.length).toEqual(1);
|
@@ -139,30 +136,30 @@ describe("MetaStore with a saved header", function () {
|
|
139
136
|
let store: bs.MetaStore;
|
140
137
|
let cid: CID;
|
141
138
|
const sthis = ensureSuperThis();
|
142
|
-
|
139
|
+
const loader = mockLoader(sthis);
|
143
140
|
|
144
141
|
afterEach(async () => {
|
145
142
|
await store.close();
|
146
143
|
await store.destroy();
|
147
144
|
});
|
148
145
|
|
149
|
-
beforeEach(async
|
146
|
+
beforeEach(async () => {
|
150
147
|
await sthis.start();
|
151
|
-
|
152
|
-
store =
|
153
|
-
await store.start();
|
148
|
+
const at = await createAttachedStores(noopUrl("test3-meta"), loader);
|
149
|
+
store = at.stores.meta;
|
150
|
+
await store.start(at.stores);
|
154
151
|
cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
155
152
|
await store.save({ cars: [cid] /*, key: undefined */ });
|
156
153
|
});
|
157
154
|
|
158
|
-
// it("should load", async
|
155
|
+
// it("should load", async () =>{
|
159
156
|
// expect(onload).toBeTruthy();
|
160
157
|
// expect(onload?.length).toEqual(1);
|
161
158
|
// expect(onload?.[0].cars.toString()).toEqual(cid.toString());
|
162
159
|
// });
|
163
160
|
|
164
|
-
it("should have a header", async
|
165
|
-
const bytes = await store.realGateway.getPlain(loader, store.url(), "main");
|
161
|
+
it("should have a header", async () => {
|
162
|
+
const bytes = await store.realGateway.getPlain({ loader }, store.url(), "main");
|
166
163
|
const data = sthis.txt.decode(bytes.Ok());
|
167
164
|
expect(data).toMatch(/parents/);
|
168
165
|
const header = JSON.parse(data)[0];
|
@@ -179,7 +176,7 @@ describe("MetaStore with a saved header", function () {
|
|
179
176
|
expect(decodedHeader.cars[0].toString()).toEqual(cid.toString());
|
180
177
|
});
|
181
178
|
|
182
|
-
it("should load a header", async
|
179
|
+
it("should load a header", async () => {
|
183
180
|
const loadeds = (await store.load()) as bs.DbMeta[];
|
184
181
|
const loaded = loadeds[0];
|
185
182
|
expect(loaded).toBeTruthy();
|
@@ -5,8 +5,9 @@ import { simpleBlockOpts } from "../helpers.js";
|
|
5
5
|
describe("Fresh TransactionBlockstore", function () {
|
6
6
|
let blocks: BaseBlockstore;
|
7
7
|
const sthis = ensureSuperThis();
|
8
|
-
beforeEach(
|
8
|
+
beforeEach(async () => {
|
9
9
|
blocks = new bs.BaseBlockstoreImpl(simpleBlockOpts(sthis));
|
10
|
+
await blocks.ready();
|
10
11
|
});
|
11
12
|
// it("should not have a name", function () {
|
12
13
|
// expect(blocks.name).toBeFalsy();
|
@@ -14,12 +15,12 @@ describe("Fresh TransactionBlockstore", function () {
|
|
14
15
|
// it("should not have a loader", function () {
|
15
16
|
// expect(blocks.loader).toBeFalsy();
|
16
17
|
// });
|
17
|
-
it("should not put", async
|
18
|
+
it("should not put", async () => {
|
18
19
|
const value = sthis.txt.encode("value");
|
19
20
|
const e = await blocks.put("key" as unknown as bs.AnyLink, value).catch((e) => e);
|
20
21
|
expect(e.message).toMatch(/transaction/g);
|
21
22
|
});
|
22
|
-
it("should yield a transaction", async
|
23
|
+
it("should yield a transaction", async () => {
|
23
24
|
const txR = await blocks.transaction(async (tblocks) => {
|
24
25
|
expect(tblocks).toBeTruthy();
|
25
26
|
expect(tblocks instanceof bs.CarTransactionImpl).toBeTruthy();
|
@@ -34,8 +35,9 @@ describe("Fresh TransactionBlockstore", function () {
|
|
34
35
|
describe("TransactionBlockstore with name", function () {
|
35
36
|
let blocks: bs.EncryptedBlockstore;
|
36
37
|
const sthis = ensureSuperThis();
|
37
|
-
beforeEach(
|
38
|
+
beforeEach(async () => {
|
38
39
|
blocks = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis));
|
40
|
+
await blocks.ready();
|
39
41
|
});
|
40
42
|
// it("should have a name", function () {
|
41
43
|
// expect(blocks.name).toEqual("test");
|
@@ -43,7 +45,7 @@ describe("TransactionBlockstore with name", function () {
|
|
43
45
|
it("should have a loader", function () {
|
44
46
|
expect(blocks.loader).toBeTruthy();
|
45
47
|
});
|
46
|
-
it("should get from loader", async
|
48
|
+
it("should get from loader", async () => {
|
47
49
|
const bytes = sthis.txt.encode("bytes");
|
48
50
|
expect(blocks.loader).toBeTruthy();
|
49
51
|
blocks.loader.getBlock = async (cid) => {
|
@@ -58,12 +60,12 @@ describe("A transaction", function () {
|
|
58
60
|
let tblocks: CarTransaction;
|
59
61
|
let blocks: bs.EncryptedBlockstore;
|
60
62
|
const sthis = ensureSuperThis();
|
61
|
-
beforeEach(async
|
63
|
+
beforeEach(async () => {
|
62
64
|
blocks = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis, "test"));
|
63
65
|
tblocks = new bs.CarTransactionImpl(blocks);
|
64
66
|
blocks.transactions.add(tblocks);
|
65
67
|
});
|
66
|
-
it("should put and get", async
|
68
|
+
it("should put and get", async () => {
|
67
69
|
const cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
68
70
|
const bytes = sthis.txt.encode("bytes");
|
69
71
|
await tblocks.put(cid, bytes);
|
@@ -85,7 +87,7 @@ describe("TransactionBlockstore with a completed transaction", function () {
|
|
85
87
|
let cid2: CID;
|
86
88
|
const sthis = ensureSuperThis();
|
87
89
|
|
88
|
-
beforeEach(async
|
90
|
+
beforeEach(async () => {
|
89
91
|
cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
|
90
92
|
cid2 = CID.parse("bafybeibgouhn5ktecpjuovt52zamzvm4dlve5ak7x6d5smms3itkhplnhm");
|
91
93
|
|
@@ -101,11 +103,11 @@ describe("TransactionBlockstore with a completed transaction", function () {
|
|
101
103
|
return { head: [] };
|
102
104
|
});
|
103
105
|
});
|
104
|
-
it("should have transactions", async
|
106
|
+
it("should have transactions", async () => {
|
105
107
|
const ts = blocks.transactions;
|
106
108
|
expect(ts.size).toEqual(2);
|
107
109
|
});
|
108
|
-
it("should get", async
|
110
|
+
it("should get", async () => {
|
109
111
|
const value = (await blocks.get(cid)) as bs.AnyBlock;
|
110
112
|
expect(value.cid).toEqual(cid);
|
111
113
|
expect(value.bytes.toString()).toEqual(asUInt8Array("value", sthis).toString());
|
@@ -113,7 +115,7 @@ describe("TransactionBlockstore with a completed transaction", function () {
|
|
113
115
|
const value2 = (await blocks.get(cid2)) as bs.AnyBlock;
|
114
116
|
expect(value2.bytes.toString()).toEqual(asUInt8Array("value2", sthis).toString());
|
115
117
|
});
|
116
|
-
it("should yield entries", async
|
118
|
+
it("should yield entries", async () => {
|
117
119
|
const blz = [];
|
118
120
|
for await (const blk of blocks.entries()) {
|
119
121
|
blz.push(blk);
|