@fireproof/core 0.19.121 → 0.20.0-dev-preview-06
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -2
- package/deno/index.d.ts +7 -0
- package/deno/index.js +66 -0
- package/deno/index.js.map +1 -0
- package/deno/metafile-esm.json +1 -0
- package/deno.json +2 -3
- package/index.cjs +1819 -1051
- package/index.cjs.map +1 -1
- package/index.d.cts +746 -333
- package/index.d.ts +746 -333
- package/index.js +1792 -1026
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +16 -293
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +4 -40
- package/node/index.d.ts +4 -40
- package/node/index.js +22 -237
- package/node/index.js.map +1 -1
- package/node/metafile-cjs.json +1 -1
- package/node/metafile-esm.json +1 -1
- package/package.json +12 -4
- package/react/index.cjs.map +1 -1
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/fp-envelope.test.ts-off +65 -0
- package/tests/blockstore/interceptor-gateway.test.ts +122 -0
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
- package/tests/blockstore/keyed-crypto.test.ts +73 -118
- package/tests/blockstore/loader.test.ts +18 -9
- package/tests/blockstore/store.test.ts +40 -31
- package/tests/blockstore/transaction.test.ts +14 -13
- package/tests/fireproof/all-gateway.test.ts +283 -213
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
- package/tests/fireproof/crdt.test.ts +78 -19
- package/tests/fireproof/database.test.ts +225 -29
- package/tests/fireproof/fireproof.test.ts +92 -73
- package/tests/fireproof/hello.test.ts +17 -13
- package/tests/fireproof/indexer.test.ts +67 -43
- package/tests/fireproof/utils.test.ts +47 -6
- package/tests/gateway/file/loader-config.test.ts +307 -0
- package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
- package/tests/gateway/indexdb/loader-config.test.ts +79 -0
- package/tests/helpers.ts +44 -17
- package/tests/react/useFireproof.test.tsx +1 -1
- package/tests/www/todo.html +24 -3
- package/web/index.cjs +102 -116
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +15 -29
- package/web/index.d.ts +15 -29
- package/web/index.js +91 -105
- package/web/index.js.map +1 -1
- package/web/metafile-cjs.json +1 -1
- package/web/metafile-esm.json +1 -1
- package/node/chunk-4A4RAVNS.js +0 -17
- package/node/chunk-4A4RAVNS.js.map +0 -1
- package/node/mem-filesystem-LPPT7QV5.js +0 -40
- package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
- package/tests/fireproof/config.test.ts +0 -163
- /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
- /package/tests/fireproof/{multiple-ledger.test.ts → multiple-database.test.ts} +0 -0
@@ -1,18 +1,17 @@
|
|
1
|
-
import { bs, ensureSuperThis,
|
2
|
-
import { BuildURI,
|
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
6
|
import type { KeyBagProviderIndexDB } from "@fireproof/core/web";
|
7
|
-
import
|
7
|
+
import { MockSuperThis, mockSuperThis } from "../helpers.js";
|
8
8
|
|
9
9
|
describe("KeyBag", () => {
|
10
10
|
let url: URI;
|
11
|
-
let sthis:
|
12
|
-
const mockLogger = MockLogger();
|
11
|
+
let sthis: MockSuperThis;
|
13
12
|
|
14
13
|
beforeEach(async () => {
|
15
|
-
sthis =
|
14
|
+
sthis = mockSuperThis();
|
16
15
|
await sthis.start();
|
17
16
|
if (runtimeFn().isBrowser) {
|
18
17
|
url = URI.from("indexdb://fp-keybag");
|
@@ -56,7 +55,7 @@ describe("KeyBag", () => {
|
|
56
55
|
});
|
57
56
|
sthis.env.set("FP_KEYBAG_URL", old);
|
58
57
|
await sthis.logger.Flush();
|
59
|
-
expect(
|
58
|
+
expect(sthis.ctx.logCollector.Logs()).toEqual([
|
60
59
|
{
|
61
60
|
level: "warn",
|
62
61
|
module: "KeyBag",
|
@@ -94,7 +93,10 @@ describe("KeyBag", () => {
|
|
94
93
|
diskBag = await p._prepare().then((db) => db.get("bag", name));
|
95
94
|
diskBag2 = await p._prepare().then((db) => db.get("bag", name2));
|
96
95
|
} else {
|
97
|
-
const p = provider as KeyBagProviderFile;
|
96
|
+
const p = provider as rt.gw.file.KeyBagProviderFile;
|
97
|
+
if (typeof p._prepare !== "function") {
|
98
|
+
return;
|
99
|
+
}
|
98
100
|
const { sysFS } = await p._prepare(name);
|
99
101
|
|
100
102
|
diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
|
@@ -123,99 +125,83 @@ describe("KeyBag", () => {
|
|
123
125
|
});
|
124
126
|
|
125
127
|
describe("KeyedCryptoStore", () => {
|
128
|
+
let loader: bs.Loadable;
|
126
129
|
let kb: rt.kb.KeyBag;
|
127
|
-
let logger: Logger;
|
130
|
+
// let logger: Logger;
|
128
131
|
let baseUrl: URI;
|
129
132
|
const sthis = ensureSuperThis();
|
130
133
|
beforeEach(async () => {
|
131
134
|
await sthis.start();
|
132
|
-
logger = MockLogger().logger;
|
133
|
-
let kbUrl: URI;
|
134
|
-
if (runtimeFn().isBrowser) {
|
135
|
-
|
136
|
-
|
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);
|
137
149
|
} else {
|
138
|
-
|
139
|
-
// baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
140
|
-
baseUrl = URI.from(sthis.env.get("FP_STORAGE_URL"));
|
150
|
+
baseUrl = bs.getDefaultURI(sthis);
|
141
151
|
}
|
142
|
-
|
143
|
-
|
144
|
-
|
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;
|
145
157
|
});
|
146
158
|
it("no crypto", async () => {
|
147
|
-
const
|
148
|
-
|
149
|
-
name: "test",
|
150
|
-
ebOpts: {
|
151
|
-
keyBag: {
|
152
|
-
keyRuntime: kb.rt,
|
153
|
-
},
|
154
|
-
store: {
|
155
|
-
stores: {
|
156
|
-
base: baseUrl.build().setParam("storekey", "insecure"),
|
157
|
-
},
|
158
|
-
},
|
159
|
-
},
|
160
|
-
} as unknown as bs.Loadable;
|
161
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
159
|
+
const strt = bs.toStoreRuntime(sthis);
|
160
|
+
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
162
161
|
|
163
|
-
for (const pstore of [
|
162
|
+
for (const pstore of [
|
163
|
+
strt.makeDataStore({ sthis, url, loader }),
|
164
|
+
strt.makeMetaStore({ sthis, url, loader }),
|
165
|
+
strt.makeWALStore({ sthis, url, loader }),
|
166
|
+
]) {
|
164
167
|
const store = await pstore;
|
165
168
|
// await store.start();
|
166
169
|
const kc = await store.keyedCrypto();
|
167
170
|
expect(kc.constructor.name).toBe("noCrypto");
|
168
171
|
// expect(kc.isEncrypting).toBe(false);
|
172
|
+
expect(kc.constructor.name).toBe("noCrypto");
|
173
|
+
// expect(kc.isEncrypting).toBe(false);
|
169
174
|
}
|
170
175
|
});
|
171
176
|
|
172
177
|
it("create key", async () => {
|
173
|
-
const
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
store: {
|
181
|
-
stores: {
|
182
|
-
base: baseUrl,
|
183
|
-
},
|
184
|
-
},
|
185
|
-
},
|
186
|
-
} as unknown as bs.Loadable;
|
187
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
188
|
-
for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
|
189
|
-
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);
|
190
185
|
const kc = await store.keyedCrypto();
|
191
186
|
expect(kc.constructor.name).toBe("keyedCrypto");
|
192
187
|
// expect(kc.isEncrypting).toBe(true);
|
193
|
-
expect(store.url().getParam(
|
188
|
+
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@test:${store.url().getParam(PARAM.STORE)}@`);
|
194
189
|
}
|
195
190
|
});
|
196
191
|
|
197
192
|
it("key ref keybag", async () => {
|
198
193
|
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
199
194
|
const genKey = await kb.setNamedKey("@heute@", key);
|
200
|
-
const
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
store: {
|
208
|
-
stores: {
|
209
|
-
base: baseUrl.build().setParam("storekey", "@heute@").URI(),
|
210
|
-
},
|
211
|
-
},
|
212
|
-
},
|
213
|
-
} as unknown as bs.Loadable;
|
214
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
215
|
-
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
|
+
]) {
|
216
202
|
const store = await pstore;
|
217
203
|
// await store.start();
|
218
|
-
expect(store.url().getParam(
|
204
|
+
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@heute@`);
|
219
205
|
const kc = await store.keyedCrypto();
|
220
206
|
expect(kc.constructor.name).toBe("keyedCrypto");
|
221
207
|
const testData = kb.rt.crypto.randomBytes(1024);
|
@@ -231,25 +217,17 @@ describe("KeyedCryptoStore", () => {
|
|
231
217
|
|
232
218
|
it("key", async () => {
|
233
219
|
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
234
|
-
const
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
stores: {
|
243
|
-
base: BuildURI.from(baseUrl).setParam("storekey", key),
|
244
|
-
},
|
245
|
-
},
|
246
|
-
},
|
247
|
-
} as unknown as bs.Loadable;
|
248
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
249
|
-
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)]) {
|
250
228
|
const store = await pstore;
|
251
229
|
// await store.start();
|
252
|
-
expect(store.url().getParam(
|
230
|
+
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(key);
|
253
231
|
const kc = await store.keyedCrypto();
|
254
232
|
expect(kc.constructor.name).toBe("keyedCrypto");
|
255
233
|
const testData = kb.rt.crypto.randomBytes(1024);
|
@@ -268,14 +246,14 @@ describe("KeyedCrypto", () => {
|
|
268
246
|
let keyStr: string;
|
269
247
|
const sthis = ensureSuperThis();
|
270
248
|
beforeEach(async () => {
|
271
|
-
let url: URI;
|
272
|
-
if (runtimeFn().isBrowser) {
|
273
|
-
|
274
|
-
} else {
|
275
|
-
|
276
|
-
}
|
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
|
+
// }
|
277
255
|
kb = await rt.kb.getKeyBag(sthis, {
|
278
|
-
url,
|
256
|
+
// url,
|
279
257
|
});
|
280
258
|
keyStr = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
281
259
|
kycr = await rt.kc.keyedCryptoFactory(URI.from(`test://bla?storekey=${keyStr}`), kb, sthis);
|
@@ -309,26 +287,3 @@ describe("KeyedCrypto", () => {
|
|
309
287
|
expect(blk).toEqual(blk2);
|
310
288
|
});
|
311
289
|
});
|
312
|
-
|
313
|
-
// describe("KeyedCryptoStore RunLength", () => {
|
314
|
-
// const logger = MockLogger().logger;
|
315
|
-
// it("de/encode", () => {
|
316
|
-
// for (const data of [
|
317
|
-
// new Uint8Array(),
|
318
|
-
// new Uint8Array(10).fill(10),
|
319
|
-
// new Uint8Array(127).fill(127),
|
320
|
-
// new Uint8Array(128).fill(128),
|
321
|
-
// new Uint8Array(1024).fill(17),
|
322
|
-
// ]) {
|
323
|
-
// const res = rt.kc.encodeRunLength(data, logger);
|
324
|
-
// expect(res.length).toBeLessThanOrEqual(data.length + (data.length > 127 ? 4 : 1));
|
325
|
-
// for (let ofs = 0; ofs < 1024; ofs += 61) {
|
326
|
-
// const ofsRes = new Uint8Array([...new Uint8Array(ofs).fill(23), ...res]);
|
327
|
-
// const dec = rt.kc.decodeRunLength(ofsRes, ofs, logger);
|
328
|
-
// expect(dec.data).toEqual(data);
|
329
|
-
// expect(dec.data.length).toBe(data.length);
|
330
|
-
// expect(dec.next).toBe(ofs + data.length + (data.length > 127 ? 4 : 1));
|
331
|
-
// }
|
332
|
-
// }
|
333
|
-
// });
|
334
|
-
// });
|
@@ -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
|
-
|
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(
|
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(
|
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
|
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(
|
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,
|
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,
|
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 {
|
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(
|
7
|
+
return bs.toStoreRuntime(sthis);
|
6
8
|
}
|
7
9
|
|
8
|
-
function mockLoader(sthis: SuperThis, name
|
10
|
+
async function mockLoader(sthis: SuperThis, name?: string): Promise<bs.StoreFactoryItem> {
|
11
|
+
const url = noopUrl(name);
|
9
12
|
return {
|
10
13
|
sthis,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
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.
|
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
|
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
|
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.
|
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
|
123
|
-
const
|
124
|
-
|
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
|
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
|
-
|
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,
|
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,
|
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));
|