@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,41 +1,44 @@
|
|
1
|
-
import { Database, bs, ensureSuperThis } from "@fireproof/core";
|
2
|
-
import { URI } from "@adviser/cement";
|
1
|
+
import { Database, DatabaseFactory, PARAM, bs, ensureSuperThis } from "@fireproof/core";
|
3
2
|
|
4
3
|
import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
4
|
+
import { simpleCID } from "../helpers.js";
|
5
|
+
|
6
|
+
// import { DataStore, MetaStore, WALState, WALStore } from "../../src/blockstore/types.js";
|
7
|
+
// import { Gateway } from "../../src/blockstore/gateway.js";
|
8
|
+
// import { FPEnvelopeMeta, FPEnvelopeType } from "../../src/blockstore/fp-envelope.js";
|
9
|
+
|
10
|
+
// function customExpect(value: unknown, matcher: (val: unknown) => void, message: string): void {
|
11
|
+
// try {
|
12
|
+
// matcher(value);
|
13
|
+
// } catch (error) {
|
14
|
+
// void error;
|
15
|
+
// // console.error(error);
|
16
|
+
// throw new Error(message);
|
17
|
+
// }
|
18
|
+
// }
|
19
|
+
|
20
|
+
// interface ExtendedGateway extends bs.Gateway {
|
21
|
+
// readonly logger: Logger;
|
22
|
+
// readonly headerSize: number;
|
23
|
+
// readonly fidLength: number;
|
24
|
+
// }
|
25
|
+
|
26
|
+
// interface ExtendedStore {
|
27
|
+
// readonly gateway: ExtendedGateway;
|
28
|
+
// readonly _url: URI;
|
29
|
+
// readonly name: string;
|
30
|
+
// }
|
27
31
|
|
28
32
|
describe("noop Gateway", function () {
|
29
33
|
let db: Database;
|
30
|
-
let carStore:
|
31
|
-
let metaStore:
|
32
|
-
let fileStore:
|
33
|
-
let walStore:
|
34
|
-
let carGateway:
|
35
|
-
let metaGateway:
|
36
|
-
let fileGateway:
|
37
|
-
let walGateway:
|
38
|
-
|
34
|
+
let carStore: bs.DataStore;
|
35
|
+
let metaStore: bs.MetaStore;
|
36
|
+
let fileStore: bs.DataStore;
|
37
|
+
let walStore: bs.WALStore;
|
38
|
+
let carGateway: bs.SerdeGateway;
|
39
|
+
let metaGateway: bs.SerdeGateway;
|
40
|
+
let fileGateway: bs.SerdeGateway;
|
41
|
+
let walGateway: bs.SerdeGateway;
|
39
42
|
const sthis = ensureSuperThis();
|
40
43
|
|
41
44
|
afterEach(async function () {
|
@@ -43,19 +46,21 @@ describe("noop Gateway", function () {
|
|
43
46
|
await db.destroy();
|
44
47
|
});
|
45
48
|
beforeEach(async function () {
|
46
|
-
db =
|
49
|
+
db = DatabaseFactory("test-gateway-" + sthis.nextId().str, {
|
50
|
+
logger: sthis.logger,
|
51
|
+
});
|
47
52
|
|
48
53
|
// Extract stores from the loader
|
49
|
-
carStore = (await db.blockstore.loader?.carStore()) as
|
50
|
-
metaStore = (await db.blockstore.loader?.metaStore()) as
|
51
|
-
fileStore = (await db.blockstore.loader?.fileStore()) as
|
52
|
-
walStore = (await db.blockstore.loader?.WALStore()) as
|
54
|
+
carStore = (await db.crdt.blockstore.loader?.carStore()) as bs.DataStore;
|
55
|
+
metaStore = (await db.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
|
56
|
+
fileStore = (await db.crdt.blockstore.loader?.fileStore()) as bs.DataStore;
|
57
|
+
walStore = (await db.crdt.blockstore.loader?.WALStore()) as bs.WALStore;
|
53
58
|
|
54
59
|
// Extract and log gateways
|
55
|
-
carGateway = carStore
|
56
|
-
metaGateway = metaStore
|
57
|
-
fileGateway = fileStore
|
58
|
-
walGateway = walStore
|
60
|
+
carGateway = carStore.realGateway;
|
61
|
+
metaGateway = metaStore.realGateway;
|
62
|
+
fileGateway = fileStore.realGateway;
|
63
|
+
walGateway = walStore.realGateway;
|
59
64
|
});
|
60
65
|
|
61
66
|
it("should have valid stores and gateways", async function () {
|
@@ -73,26 +78,27 @@ describe("noop Gateway", function () {
|
|
73
78
|
|
74
79
|
it("should have correct store names", async function () {
|
75
80
|
// Check that all stores have the correct name
|
76
|
-
expect(carStore
|
77
|
-
expect(metaStore
|
78
|
-
expect(fileStore
|
79
|
-
expect(walStore
|
81
|
+
expect(carStore.url().getParam(PARAM.NAME)).toContain("test-gateway");
|
82
|
+
expect(metaStore.url().getParam(PARAM.NAME)).toContain("test-gateway");
|
83
|
+
expect(fileStore.url().getParam(PARAM.NAME)).toContain("test-gateway");
|
84
|
+
expect(walStore.url().getParam(PARAM.NAME)).toContain("test-gateway");
|
80
85
|
});
|
81
86
|
|
82
87
|
it("should have correct store types in URLs", async function () {
|
83
88
|
// Check that all stores have the correct store type in their URL
|
84
|
-
expect(carStore
|
85
|
-
expect(
|
86
|
-
expect(
|
87
|
-
expect(
|
89
|
+
expect(carStore.url().toString()).toContain("store=data");
|
90
|
+
expect(carStore.url().toString()).toContain("suffix=.car");
|
91
|
+
expect(metaStore.url().toString()).toContain("store=meta");
|
92
|
+
expect(fileStore.url().toString()).toContain("store=data");
|
93
|
+
expect(walStore.url().toString()).toContain("store=wal");
|
88
94
|
});
|
89
95
|
|
90
96
|
it("should have version specified in URLs", async function () {
|
91
97
|
// Verify that all stores have a version specified
|
92
|
-
expect(carStore
|
93
|
-
expect(metaStore
|
94
|
-
expect(fileStore
|
95
|
-
expect(walStore
|
98
|
+
expect(carStore.url().toString()).toContain("version=");
|
99
|
+
expect(metaStore.url().toString()).toContain("version=");
|
100
|
+
expect(fileStore.url().toString()).toContain("version=");
|
101
|
+
expect(walStore.url().toString()).toContain("version=");
|
96
102
|
});
|
97
103
|
|
98
104
|
it("should have correct gateway types", async function () {
|
@@ -105,202 +111,263 @@ describe("noop Gateway", function () {
|
|
105
111
|
|
106
112
|
it("should build CAR Gateway URL", async function () {
|
107
113
|
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
108
|
-
const carUrl = await carGateway
|
109
|
-
expect(carUrl
|
114
|
+
const carUrl = await carGateway.buildUrl(sthis, carStore.url(), testKey);
|
115
|
+
expect(carUrl.Ok().hasParam("key")).toBeTruthy();
|
110
116
|
});
|
111
117
|
|
112
118
|
it("should start CAR Gateway", async function () {
|
113
|
-
await carGateway
|
119
|
+
const url = await carGateway.start(sthis, carStore.url());
|
120
|
+
expect(url.Ok().asObj()).toEqual(carStore.url().asObj());
|
114
121
|
});
|
115
122
|
|
116
123
|
it("should put data in CAR Gateway", async function () {
|
117
|
-
const
|
118
|
-
|
119
|
-
const
|
120
|
-
|
121
|
-
|
122
|
-
|
124
|
+
const carUrl = await carGateway.buildUrl(sthis, carStore.url(), fileContent.cid);
|
125
|
+
await carGateway.start(sthis, carStore.url());
|
126
|
+
const carPutResult = await carGateway.put(sthis, carUrl.Ok(), {
|
127
|
+
type: bs.FPEnvelopeType.CAR,
|
128
|
+
payload: fileContent.block,
|
129
|
+
});
|
130
|
+
expect(carPutResult.isOk()).toBeTruthy();
|
123
131
|
});
|
124
132
|
|
125
133
|
it("should get data from CAR Gateway", async function () {
|
126
|
-
const
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
134
|
+
const carUrl = await carGateway.buildUrl(sthis, carStore.url(), fileContent.cid);
|
135
|
+
await carGateway.start(sthis, carStore.url());
|
136
|
+
await carGateway.put(sthis, carUrl.Ok(), {
|
137
|
+
type: bs.FPEnvelopeType.CAR,
|
138
|
+
payload: fileContent.block,
|
139
|
+
});
|
140
|
+
const carGetResult = await carGateway.get(sthis, carUrl.Ok());
|
141
|
+
expect(carGetResult.Ok().type).toEqual("car");
|
142
|
+
expect(carGetResult.Ok().payload).toEqual(fileContent.block);
|
143
|
+
// customExpect(carGetResult.Ok(), (v) => expect(v).toEqual(testData), "carGetResult should match testData");
|
133
144
|
});
|
134
145
|
|
135
146
|
it("should delete data from CAR Gateway", async function () {
|
136
|
-
const
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
147
|
+
const carUrl = await carGateway.buildUrl(sthis, carStore.url(), fileContent.cid);
|
148
|
+
await carGateway.start(sthis, carStore.url());
|
149
|
+
await carGateway.put(sthis, carUrl.Ok(), {
|
150
|
+
type: bs.FPEnvelopeType.CAR,
|
151
|
+
payload: fileContent.block,
|
152
|
+
});
|
153
|
+
const carDeleteResult = await carGateway.delete(sthis, carUrl.Ok());
|
154
|
+
expect(carDeleteResult.isOk()).toBeTruthy();
|
143
155
|
});
|
144
156
|
|
145
157
|
it("should close CAR Gateway", async function () {
|
146
|
-
await carGateway
|
158
|
+
await carGateway.close(sthis, carStore.url());
|
147
159
|
});
|
148
160
|
it("should build Meta Gateway URL", async function () {
|
149
|
-
const metaUrl = await metaGateway
|
150
|
-
expect(metaUrl
|
161
|
+
const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
|
162
|
+
expect(metaUrl.Ok()).toBeTruthy();
|
151
163
|
});
|
152
164
|
|
153
165
|
it("should start Meta Gateway", async function () {
|
154
|
-
await metaGateway
|
166
|
+
await metaGateway.start(sthis, metaStore.url());
|
155
167
|
});
|
156
168
|
|
157
169
|
it("should close Meta Gateway", async function () {
|
158
|
-
await metaGateway
|
159
|
-
await metaGateway
|
170
|
+
await metaGateway.start(sthis, metaStore.url());
|
171
|
+
await metaGateway.close(sthis, metaStore.url());
|
160
172
|
});
|
161
173
|
|
162
174
|
it("should build File Gateway URL", async function () {
|
163
|
-
const
|
164
|
-
|
165
|
-
expect(fileUrl?.Ok()).toBeTruthy();
|
175
|
+
const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
|
176
|
+
expect(fileUrl.Ok()).toBeTruthy();
|
166
177
|
});
|
167
178
|
|
168
179
|
it("should start File Gateway", async function () {
|
169
|
-
await fileGateway
|
180
|
+
await fileGateway.start(sthis, fileStore.url());
|
170
181
|
});
|
171
182
|
|
172
183
|
it("should put data to File Gateway", async function () {
|
173
|
-
const
|
174
|
-
|
175
|
-
const
|
176
|
-
|
177
|
-
|
178
|
-
|
184
|
+
const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
|
185
|
+
await fileGateway.start(sthis, fileStore.url());
|
186
|
+
const filePutResult = await fileGateway.put(sthis, fileUrl.Ok(), {
|
187
|
+
type: bs.FPEnvelopeType.FILE,
|
188
|
+
payload: fileContent.block,
|
189
|
+
});
|
190
|
+
expect(filePutResult.Ok()).toBeFalsy();
|
179
191
|
});
|
180
192
|
|
181
193
|
it("should get data from File Gateway", async function () {
|
182
|
-
const
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
194
|
+
const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
|
195
|
+
await fileGateway.start(sthis, fileStore.url());
|
196
|
+
await fileGateway.put(sthis, fileUrl.Ok(), {
|
197
|
+
type: bs.FPEnvelopeType.FILE,
|
198
|
+
payload: fileContent.block,
|
199
|
+
});
|
200
|
+
const fileGetResult = await fileGateway.get(sthis, fileUrl.Ok());
|
201
|
+
expect(fileGetResult.Ok().type).toEqual("file");
|
202
|
+
expect(fileGetResult.Ok().payload).toEqual(fileContent.block);
|
189
203
|
});
|
190
204
|
|
191
205
|
it("should delete data from File Gateway", async function () {
|
192
|
-
const
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
206
|
+
const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
|
207
|
+
await fileGateway.start(sthis, fileStore.url());
|
208
|
+
await fileGateway.put(sthis, fileUrl.Ok(), {
|
209
|
+
type: bs.FPEnvelopeType.FILE,
|
210
|
+
payload: fileContent.block,
|
211
|
+
});
|
212
|
+
const fileDeleteResult = await fileGateway.delete(sthis, fileUrl.Ok());
|
213
|
+
expect(fileDeleteResult.isOk()).toBeTruthy();
|
199
214
|
});
|
200
215
|
|
201
216
|
it("should close File Gateway", async function () {
|
202
|
-
await fileGateway
|
217
|
+
await fileGateway.close(sthis, fileStore.url());
|
203
218
|
});
|
204
219
|
it("should build WAL Gateway URL", async function () {
|
205
220
|
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
206
|
-
const walUrl = await walGateway
|
207
|
-
expect(walUrl
|
221
|
+
const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
|
222
|
+
expect(walUrl.Ok()).toBeTruthy();
|
208
223
|
});
|
209
224
|
|
210
225
|
it("should start WAL Gateway", async function () {
|
211
|
-
await walGateway
|
226
|
+
await walGateway.start(sthis, walStore.url());
|
212
227
|
});
|
213
228
|
|
214
229
|
it("should put data to WAL Gateway", async function () {
|
215
230
|
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
216
|
-
const walUrl = await walGateway
|
217
|
-
await walGateway
|
218
|
-
const walTestDataString = JSON.stringify(
|
219
|
-
|
220
|
-
|
221
|
-
|
231
|
+
const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
|
232
|
+
await walGateway.start(sthis, walStore.url());
|
233
|
+
// const walTestDataString = JSON.stringify();
|
234
|
+
// const walTestData = sthis.txt.encode(walTestDataString);
|
235
|
+
const walPutResult = await walGateway.put(sthis, walUrl.Ok(), {
|
236
|
+
type: bs.FPEnvelopeType.WAL,
|
237
|
+
payload: {
|
238
|
+
operations: [],
|
239
|
+
noLoaderOps: [],
|
240
|
+
fileOperations: [],
|
241
|
+
},
|
222
242
|
});
|
223
|
-
|
224
|
-
const walPutResult = await walGateway?.put(walUrl?.Ok(), walTestData);
|
225
|
-
expect(walPutResult?.Ok()).toBeFalsy();
|
243
|
+
expect(walPutResult.Ok()).toBeFalsy();
|
226
244
|
});
|
227
245
|
|
228
246
|
it("should get data from WAL Gateway", async function () {
|
229
247
|
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
230
|
-
const walUrl = await walGateway
|
231
|
-
await walGateway
|
232
|
-
const
|
233
|
-
operations: [
|
234
|
-
|
235
|
-
|
248
|
+
const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
|
249
|
+
await walGateway.start(sthis, walStore.url());
|
250
|
+
const ref: bs.WALState = {
|
251
|
+
operations: [
|
252
|
+
{
|
253
|
+
cars: [await simpleCID(sthis)],
|
254
|
+
},
|
255
|
+
],
|
256
|
+
noLoaderOps: [
|
257
|
+
{
|
258
|
+
cars: [await simpleCID(sthis)],
|
259
|
+
},
|
260
|
+
],
|
261
|
+
fileOperations: [
|
262
|
+
{
|
263
|
+
cid: await simpleCID(sthis),
|
264
|
+
public: false,
|
265
|
+
},
|
266
|
+
],
|
267
|
+
};
|
268
|
+
// const walTestDataString = JSON.stringify({
|
269
|
+
// operations: [],
|
270
|
+
// noLoaderOps: [],
|
271
|
+
// fileOperations: [],
|
272
|
+
// });
|
273
|
+
// const walTestData = sthis.txt.encode(walTestDataString);
|
274
|
+
await walGateway.put(sthis, walUrl.Ok(), {
|
275
|
+
type: bs.FPEnvelopeType.WAL,
|
276
|
+
payload: ref,
|
236
277
|
});
|
237
|
-
const
|
238
|
-
|
239
|
-
const
|
240
|
-
const
|
241
|
-
|
242
|
-
expect(decodedResult).toEqual(walTestDataString);
|
278
|
+
const walGetResult = await walGateway.get(sthis, walUrl.Ok());
|
279
|
+
expect(walGetResult.isOk()).toBeTruthy();
|
280
|
+
// const okResult = walGetResult.Ok();
|
281
|
+
// const decodedResult = sthis.txt.decode(okResult);
|
282
|
+
expect(ref).toEqual(walGetResult.Ok().payload);
|
243
283
|
});
|
244
284
|
|
245
285
|
it("should delete data from WAL Gateway", async function () {
|
246
286
|
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
247
|
-
const walUrl = await walGateway
|
248
|
-
await walGateway
|
249
|
-
const
|
250
|
-
operations: [
|
251
|
-
|
252
|
-
|
287
|
+
const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
|
288
|
+
await walGateway.start(sthis, walStore.url());
|
289
|
+
const ref: bs.WALState = {
|
290
|
+
operations: [
|
291
|
+
{
|
292
|
+
cars: [await simpleCID(sthis)],
|
293
|
+
},
|
294
|
+
],
|
295
|
+
noLoaderOps: [
|
296
|
+
{
|
297
|
+
cars: [await simpleCID(sthis)],
|
298
|
+
},
|
299
|
+
],
|
300
|
+
fileOperations: [
|
301
|
+
{
|
302
|
+
cid: await simpleCID(sthis),
|
303
|
+
public: false,
|
304
|
+
},
|
305
|
+
],
|
306
|
+
};
|
307
|
+
await walGateway.put(sthis, walUrl.Ok(), {
|
308
|
+
type: bs.FPEnvelopeType.WAL,
|
309
|
+
payload: ref,
|
253
310
|
});
|
254
|
-
const
|
255
|
-
|
256
|
-
const walDeleteResult = await walGateway?.delete(walUrl?.Ok());
|
257
|
-
expect(walDeleteResult?.Ok()).toBeFalsy();
|
311
|
+
const walDeleteResult = await walGateway.delete(sthis, walUrl.Ok());
|
312
|
+
expect(walDeleteResult.isOk()).toBeTruthy();
|
258
313
|
});
|
259
314
|
|
260
315
|
it("should close WAL Gateway", async function () {
|
261
|
-
await walGateway
|
262
|
-
await walGateway
|
263
|
-
});
|
264
|
-
|
265
|
-
it("should have correct CAR Gateway properties", async function () {
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
316
|
+
await walGateway.start(sthis, walStore.url());
|
317
|
+
await walGateway.close(sthis, walStore.url());
|
318
|
+
});
|
319
|
+
|
320
|
+
// it("should have correct CAR Gateway properties", async function () {
|
321
|
+
// // CAR Gateway assertions
|
322
|
+
// expect(carGateway.fidLength).toBe(4);
|
323
|
+
// expect(carGateway.headerSize).toBe(36);
|
324
|
+
// carGateway.logger.Error().Msg("CAR Gateway properties");
|
325
|
+
// await sthis.logger.Flush();
|
326
|
+
// const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
|
327
|
+
// expect(last).toHaveProperty("module");
|
328
|
+
// expect(carStore.).toHaveProperty("url");
|
329
|
+
// });
|
330
|
+
|
331
|
+
// it("should have correct Meta Gateway properties", async function () {
|
332
|
+
// // Meta Gateway assertions
|
333
|
+
// expect(metaGateway.fidLength).toBe(4);
|
334
|
+
// expect(metaGateway.headerSize).toBe(36);
|
335
|
+
// metaGateway.logger.Error().Msg("CAR Gateway properties");
|
336
|
+
// await sthis.logger.Flush();
|
337
|
+
// const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
|
338
|
+
// expect(last).toHaveProperty("module");
|
339
|
+
// expect(last).not.toHaveProperty("url");
|
340
|
+
// });
|
341
|
+
|
342
|
+
// it("should have correct File Gateway properties", async function () {
|
343
|
+
// // File Gateway assertions
|
344
|
+
// expect(fileGateway.fidLength).toBe(4);
|
345
|
+
// expect(fileGateway.headerSize).toBe(36);
|
346
|
+
// fileGateway.logger.Error().Msg("CAR Gateway properties");
|
347
|
+
// await sthis.logger.Flush();
|
348
|
+
// const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
|
349
|
+
// expect(last).toHaveProperty("module");
|
350
|
+
// expect(last).toHaveProperty("url");
|
351
|
+
// });
|
352
|
+
|
353
|
+
// it("should have correct WAL Gateway properties", async function () {
|
354
|
+
// // WAL Gateway assertions
|
355
|
+
// expect(walGateway.fidLength).toBe(4);
|
356
|
+
// expect(walGateway.headerSize).toBe(36);
|
357
|
+
// walGateway.logger.Error().Msg("CAR Gateway properties");
|
358
|
+
// await sthis.logger.Flush();
|
359
|
+
// const last = sthis.ctx.logCollector.Logs().slice(-1)[0];
|
360
|
+
// expect(last).toHaveProperty("module");
|
361
|
+
// expect(last).not.toHaveProperty("url");
|
362
|
+
// });
|
296
363
|
});
|
297
364
|
|
298
365
|
describe("noop Gateway subscribe", function () {
|
299
366
|
let db: Database;
|
300
367
|
|
301
|
-
let metaStore:
|
368
|
+
let metaStore: bs.MetaStore;
|
302
369
|
|
303
|
-
let metaGateway:
|
370
|
+
let metaGateway: bs.SerdeGateway;
|
304
371
|
const sthis = ensureSuperThis();
|
305
372
|
|
306
373
|
afterEach(async function () {
|
@@ -308,30 +375,30 @@ describe("noop Gateway subscribe", function () {
|
|
308
375
|
await db.destroy();
|
309
376
|
});
|
310
377
|
beforeEach(async function () {
|
311
|
-
db =
|
378
|
+
db = DatabaseFactory("test-gateway-" + sthis.nextId().str);
|
312
379
|
|
313
380
|
// Extract stores from the loader
|
314
|
-
metaStore = (await db.blockstore.loader?.metaStore()) as
|
381
|
+
metaStore = (await db.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
|
315
382
|
|
316
|
-
metaGateway = metaStore
|
383
|
+
metaGateway = metaStore.realGateway;
|
317
384
|
});
|
318
385
|
it("should subscribe to meta Gateway", async function () {
|
319
|
-
const metaUrl = await metaGateway
|
320
|
-
await metaGateway
|
386
|
+
const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
|
387
|
+
await metaGateway.start(sthis, metaStore.url());
|
321
388
|
|
322
389
|
let resolve: () => void;
|
323
390
|
let didCall = false;
|
324
391
|
const p = new Promise<void>((r) => {
|
325
392
|
resolve = r;
|
326
393
|
});
|
327
|
-
|
328
|
-
const
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
expect(metaSubscribeResult
|
394
|
+
if (metaGateway.subscribe) {
|
395
|
+
const metaSubscribeResult = (await metaGateway.subscribe(sthis, metaUrl.Ok(), async (data: bs.FPEnvelopeMeta) => {
|
396
|
+
// const decodedData = sthis.txt.decode(data);
|
397
|
+
expect(data.payload).toContain("[]");
|
398
|
+
didCall = true;
|
399
|
+
resolve();
|
400
|
+
})) as bs.UnsubscribeResult;
|
401
|
+
expect(metaSubscribeResult.isOk()).toBeTruthy();
|
335
402
|
const ok = await db.put({ _id: "key1", hello: "world1" });
|
336
403
|
expect(ok).toBeTruthy();
|
337
404
|
expect(ok.id).toBe("key1");
|
@@ -344,11 +411,11 @@ describe("noop Gateway subscribe", function () {
|
|
344
411
|
describe("Gateway", function () {
|
345
412
|
let db: Database;
|
346
413
|
// let carStore: ExtendedStore;
|
347
|
-
let metaStore:
|
414
|
+
let metaStore: bs.MetaStore;
|
348
415
|
// let fileStore: ExtendedStore;
|
349
416
|
// let walStore: ExtendedStore;
|
350
417
|
// let carGateway: ExtendedGateway;
|
351
|
-
let metaGateway:
|
418
|
+
let metaGateway: bs.SerdeGateway;
|
352
419
|
// let fileGateway: ExtendedGateway;
|
353
420
|
// let walGateway: ExtendedGateway;
|
354
421
|
const sthis = ensureSuperThis();
|
@@ -358,38 +425,41 @@ describe("Gateway", function () {
|
|
358
425
|
await db.destroy();
|
359
426
|
});
|
360
427
|
beforeEach(async function () {
|
361
|
-
db =
|
428
|
+
db = DatabaseFactory("test-gateway-" + sthis.nextId().str);
|
362
429
|
const ok = await db.put({ _id: "test", foo: "bar" });
|
363
430
|
expect(ok).toBeTruthy();
|
364
431
|
expect(ok.id).toBe("test");
|
365
432
|
|
366
433
|
// Extract stores from the loader
|
367
|
-
// carStore = (await db.blockstore.loader
|
368
|
-
metaStore = (await db.blockstore.loader?.metaStore()) as
|
369
|
-
// fileStore = (await db.blockstore.loader
|
370
|
-
// walStore = (await db.blockstore.loader
|
434
|
+
// carStore = (await db.blockstore.loader.carStore()) as unknown as ExtendedStore;
|
435
|
+
metaStore = (await db.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
|
436
|
+
// fileStore = (await db.blockstore.loader.fileStore()) as unknown as ExtendedStore;
|
437
|
+
// walStore = (await db.blockstore.loader.WALStore()) as unknown as ExtendedStore;
|
371
438
|
|
372
439
|
// Extract and log gateways
|
373
|
-
// carGateway = carStore
|
374
|
-
metaGateway = metaStore
|
375
|
-
// fileGateway = fileStore
|
376
|
-
// walGateway = walStore
|
440
|
+
// carGateway = carStore.gateway;
|
441
|
+
metaGateway = metaStore.realGateway;
|
442
|
+
// fileGateway = fileStore.gateway;
|
443
|
+
// walGateway = walStore.gateway;
|
377
444
|
});
|
378
445
|
|
379
446
|
it("should get data from Meta Gateway", async function () {
|
380
|
-
const metaUrl = await metaGateway
|
381
|
-
await metaGateway
|
382
|
-
const metaGetResult = await metaGateway
|
383
|
-
|
384
|
-
const
|
385
|
-
|
447
|
+
const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
|
448
|
+
await metaGateway.start(sthis, metaStore.url());
|
449
|
+
const metaGetResult = await metaGateway.get(sthis, metaUrl.Ok());
|
450
|
+
expect(metaGetResult.isOk()).toBeTruthy();
|
451
|
+
const meta = metaGetResult.Ok().payload as bs.DbMetaEvent[];
|
452
|
+
// const metaGetResultOk = metaGetResult.Ok();
|
453
|
+
// const decodedMetaGetResultOk = sthis.txt.decode(metaGetResultOk);
|
454
|
+
expect(meta.length).toBe(1);
|
455
|
+
expect(Object.keys(meta[0])).toEqual(["eventCid", "parents", "dbMeta"]);
|
386
456
|
});
|
387
457
|
|
388
458
|
it("should delete data from Meta Gateway", async function () {
|
389
|
-
const metaUrl = await metaGateway
|
390
|
-
await metaGateway
|
459
|
+
const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
|
460
|
+
await metaGateway.start(sthis, metaStore.url());
|
391
461
|
// should we be testing .destroy() instead?
|
392
|
-
const metaDeleteResult = await metaGateway
|
393
|
-
expect(metaDeleteResult
|
462
|
+
const metaDeleteResult = await metaGateway.delete(sthis, metaUrl.Ok());
|
463
|
+
expect(metaDeleteResult.isOk()).toBeTruthy();
|
394
464
|
});
|
395
465
|
});
|