@fireproof/core 0.19.8-dev-global → 0.19.11-dev-dryrun
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 +34 -0
- package/chunk-7EWIAXTM.js +7 -0
- package/chunk-7EWIAXTM.js.map +1 -0
- package/chunk-MAK4D54P.js +280 -0
- package/chunk-MAK4D54P.js.map +1 -0
- package/chunk-PB4BKL4O.js +7 -0
- package/chunk-PB4BKL4O.js.map +1 -0
- package/chunk-XINRLWR3.js +75 -0
- package/chunk-XINRLWR3.js.map +1 -0
- package/deno.json +20 -0
- package/{store-indexdb-WLRSICCB.js → gateway-7OM6OSYK.js} +49 -82
- package/gateway-7OM6OSYK.js.map +1 -0
- package/gateway-VWWKLHUI.js +144 -0
- package/gateway-VWWKLHUI.js.map +1 -0
- package/index.cjs +2351 -1825
- package/index.cjs.map +1 -1
- package/index.d.cts +659 -535
- package/index.d.ts +659 -535
- package/index.global.js +26315 -20709
- package/index.global.js.map +1 -1
- package/index.js +1700 -1058
- package/index.js.map +1 -1
- package/key-bag-file-DFMW6ZM6.js +54 -0
- package/key-bag-file-DFMW6ZM6.js.map +1 -0
- package/key-bag-indexdb-R2RWGSQ4.js +50 -0
- package/key-bag-indexdb-R2RWGSQ4.js.map +1 -0
- package/mem-filesystem-BZQZLUR6.js +41 -0
- package/mem-filesystem-BZQZLUR6.js.map +1 -0
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/metafile-iife.json +1 -1
- package/node-filesystem-7YZR3POJ.js +45 -0
- package/node-filesystem-7YZR3POJ.js.map +1 -0
- package/package.json +12 -8
- package/tests/blockstore/fragment-gateway.test.ts +107 -0
- package/tests/blockstore/keyed-crypto.test.ts +332 -0
- package/tests/blockstore/loader.test.ts +24 -19
- package/tests/blockstore/store.test.ts +51 -40
- package/tests/blockstore/transaction.test.ts +19 -15
- package/tests/fireproof/all-gateway.test.ts +395 -0
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js +316 -0
- package/tests/fireproof/config.test.ts +94 -78
- package/tests/fireproof/convert_uint8.py +27 -0
- package/tests/fireproof/crdt.test.ts +34 -28
- package/tests/fireproof/database.test.ts +22 -14
- package/tests/fireproof/fireproof.test.fixture.ts +133 -0
- package/tests/fireproof/fireproof.test.ts +331 -219
- package/tests/fireproof/hello.test.ts +34 -18
- package/tests/fireproof/indexer.test.ts +34 -27
- package/tests/fireproof/utils.test.ts +65 -0
- package/tests/helpers.ts +28 -57
- package/utils-AISQB3PB.js +14 -0
- package/utils-AISQB3PB.js.map +1 -0
- package/chunk-BNL4PVBF.js +0 -314
- package/chunk-BNL4PVBF.js.map +0 -1
- package/chunk-JW2QT6BF.js +0 -184
- package/chunk-JW2QT6BF.js.map +0 -1
- package/node-sys-container-MIEX6ELJ.js +0 -29
- package/node-sys-container-MIEX6ELJ.js.map +0 -1
- package/store-file-VJ6BI4II.js +0 -191
- package/store-file-VJ6BI4II.js.map +0 -1
- package/store-indexdb-WLRSICCB.js.map +0 -1
@@ -0,0 +1,395 @@
|
|
1
|
+
import { Database, bs } from "@fireproof/core";
|
2
|
+
import { URI } from "@adviser/cement";
|
3
|
+
|
4
|
+
// @ts-expect-error - This import has no type definitions
|
5
|
+
import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
|
6
|
+
|
7
|
+
function customExpect(value: unknown, matcher: (val: unknown) => void, message: string): void {
|
8
|
+
try {
|
9
|
+
matcher(value);
|
10
|
+
} catch (error) {
|
11
|
+
void error;
|
12
|
+
// console.error(error);
|
13
|
+
throw new Error(message);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
interface ExtendedGateway extends bs.Gateway {
|
18
|
+
logger: { _attributes: { module: string; url?: string } };
|
19
|
+
headerSize: number;
|
20
|
+
fidLength: number;
|
21
|
+
}
|
22
|
+
|
23
|
+
interface ExtendedStore {
|
24
|
+
gateway: ExtendedGateway;
|
25
|
+
_url: URI;
|
26
|
+
name: string;
|
27
|
+
}
|
28
|
+
|
29
|
+
describe("noop Gateway", function () {
|
30
|
+
let db: Database;
|
31
|
+
let carStore: ExtendedStore;
|
32
|
+
let metaStore: ExtendedStore;
|
33
|
+
let fileStore: ExtendedStore;
|
34
|
+
let walStore: ExtendedStore;
|
35
|
+
let carGateway: ExtendedGateway;
|
36
|
+
let metaGateway: ExtendedGateway;
|
37
|
+
let fileGateway: ExtendedGateway;
|
38
|
+
let walGateway: ExtendedGateway;
|
39
|
+
|
40
|
+
afterEach(async function () {
|
41
|
+
await db.close();
|
42
|
+
await db.destroy();
|
43
|
+
});
|
44
|
+
beforeEach(async function () {
|
45
|
+
db = new Database("test-gateway-" + Math.random().toString(36).substring(7));
|
46
|
+
|
47
|
+
// Extract stores from the loader
|
48
|
+
carStore = (await db.blockstore.loader?.carStore()) as unknown as ExtendedStore;
|
49
|
+
metaStore = (await db.blockstore.loader?.metaStore()) as unknown as ExtendedStore;
|
50
|
+
fileStore = (await db.blockstore.loader?.fileStore()) as unknown as ExtendedStore;
|
51
|
+
walStore = (await db.blockstore.loader?.WALStore()) as unknown as ExtendedStore;
|
52
|
+
|
53
|
+
// Extract and log gateways
|
54
|
+
carGateway = carStore?.gateway;
|
55
|
+
metaGateway = metaStore?.gateway;
|
56
|
+
fileGateway = fileStore?.gateway;
|
57
|
+
walGateway = walStore?.gateway;
|
58
|
+
});
|
59
|
+
|
60
|
+
it("should have valid stores and gateways", async function () {
|
61
|
+
// Add assertions
|
62
|
+
expect(carStore).toBeTruthy();
|
63
|
+
expect(metaStore).toBeTruthy();
|
64
|
+
expect(fileStore).toBeTruthy();
|
65
|
+
expect(walStore).toBeTruthy();
|
66
|
+
|
67
|
+
expect(carGateway).toBeTruthy();
|
68
|
+
expect(metaGateway).toBeTruthy();
|
69
|
+
expect(fileGateway).toBeTruthy();
|
70
|
+
expect(walGateway).toBeTruthy();
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should have correct store names", async function () {
|
74
|
+
// Check that all stores have the correct name
|
75
|
+
expect(carStore?.name).toContain("test-gateway");
|
76
|
+
expect(metaStore?.name).toContain("test-gateway");
|
77
|
+
expect(fileStore?.name).toContain("test-gateway");
|
78
|
+
expect(walStore?.name).toContain("test-gateway");
|
79
|
+
});
|
80
|
+
|
81
|
+
it("should have correct store types in URLs", async function () {
|
82
|
+
// Check that all stores have the correct store type in their URL
|
83
|
+
expect(carStore?._url.toString()).toContain("store=data");
|
84
|
+
expect(metaStore?._url.toString()).toContain("store=meta");
|
85
|
+
expect(fileStore?._url.toString()).toContain("store=data");
|
86
|
+
expect(walStore?._url.toString()).toContain("store=wal");
|
87
|
+
});
|
88
|
+
|
89
|
+
it("should have version specified in URLs", async function () {
|
90
|
+
// Verify that all stores have a version specified
|
91
|
+
expect(carStore?._url.toString()).toContain("version=");
|
92
|
+
expect(metaStore?._url.toString()).toContain("version=");
|
93
|
+
expect(fileStore?._url.toString()).toContain("version=");
|
94
|
+
expect(walStore?._url.toString()).toContain("version=");
|
95
|
+
});
|
96
|
+
|
97
|
+
it("should have correct gateway types", async function () {
|
98
|
+
// Check that all gateways are instances of the expected gateway class
|
99
|
+
expect(typeof carGateway).toBe("object");
|
100
|
+
expect(typeof metaGateway).toBe("object");
|
101
|
+
expect(typeof fileGateway).toBe("object");
|
102
|
+
expect(typeof walGateway).toBe("object");
|
103
|
+
});
|
104
|
+
|
105
|
+
it("should build CAR Gateway URL", async function () {
|
106
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
107
|
+
const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
|
108
|
+
expect(carUrl?.Ok()).toBeTruthy();
|
109
|
+
});
|
110
|
+
|
111
|
+
it("should start CAR Gateway", async function () {
|
112
|
+
await carGateway?.start(carStore?._url);
|
113
|
+
});
|
114
|
+
|
115
|
+
it("should put data in CAR Gateway", async function () {
|
116
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
117
|
+
const testData = fileContent;
|
118
|
+
const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
|
119
|
+
await carGateway?.start(carStore?._url);
|
120
|
+
const carPutResult = await carGateway?.put(carUrl?.Ok(), testData);
|
121
|
+
expect(carPutResult?.Ok()).toBeFalsy();
|
122
|
+
});
|
123
|
+
|
124
|
+
it("should get data from CAR Gateway", async function () {
|
125
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
126
|
+
const testData = fileContent;
|
127
|
+
const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
|
128
|
+
await carGateway?.start(carStore?._url);
|
129
|
+
await carGateway?.put(carUrl?.Ok(), testData);
|
130
|
+
const carGetResult = await carGateway?.get(carUrl?.Ok());
|
131
|
+
customExpect(carGetResult?.Ok(), (v) => expect(v).toEqual(testData), "carGetResult should match testData");
|
132
|
+
});
|
133
|
+
|
134
|
+
it("should delete data from CAR Gateway", async function () {
|
135
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
136
|
+
const testData = fileContent;
|
137
|
+
const carUrl = await carGateway?.buildUrl(carStore?._url, testKey);
|
138
|
+
await carGateway?.start(carStore?._url);
|
139
|
+
await carGateway?.put(carUrl?.Ok(), testData);
|
140
|
+
const carDeleteResult = await carGateway?.delete(carUrl?.Ok());
|
141
|
+
expect(carDeleteResult?.Ok()).toBeFalsy();
|
142
|
+
});
|
143
|
+
|
144
|
+
it("should close CAR Gateway", async function () {
|
145
|
+
await carGateway?.close(carStore?._url);
|
146
|
+
});
|
147
|
+
it("should build Meta Gateway URL", async function () {
|
148
|
+
const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
|
149
|
+
expect(metaUrl?.Ok()).toBeTruthy();
|
150
|
+
});
|
151
|
+
|
152
|
+
it("should start Meta Gateway", async function () {
|
153
|
+
await metaGateway?.start(metaStore?._url);
|
154
|
+
});
|
155
|
+
|
156
|
+
it("should close Meta Gateway", async function () {
|
157
|
+
await metaGateway?.start(metaStore?._url);
|
158
|
+
await metaGateway?.close(metaStore?._url);
|
159
|
+
});
|
160
|
+
|
161
|
+
it("should build File Gateway URL", async function () {
|
162
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
163
|
+
const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
|
164
|
+
expect(fileUrl?.Ok()).toBeTruthy();
|
165
|
+
});
|
166
|
+
|
167
|
+
it("should start File Gateway", async function () {
|
168
|
+
await fileGateway?.start(fileStore?._url);
|
169
|
+
});
|
170
|
+
|
171
|
+
it("should put data to File Gateway", async function () {
|
172
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
173
|
+
const testData = fileContent;
|
174
|
+
const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
|
175
|
+
await fileGateway?.start(fileStore?._url);
|
176
|
+
const filePutResult = await fileGateway?.put(fileUrl?.Ok(), testData);
|
177
|
+
expect(filePutResult?.Ok()).toBeFalsy();
|
178
|
+
});
|
179
|
+
|
180
|
+
it("should get data from File Gateway", async function () {
|
181
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
182
|
+
const testData = fileContent;
|
183
|
+
const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
|
184
|
+
await fileGateway?.start(fileStore?._url);
|
185
|
+
await fileGateway?.put(fileUrl?.Ok(), testData);
|
186
|
+
const fileGetResult = await fileGateway?.get(fileUrl?.Ok());
|
187
|
+
customExpect(fileGetResult?.Ok(), (v) => expect(v).toEqual(testData), "fileGetResult should match testData");
|
188
|
+
});
|
189
|
+
|
190
|
+
it("should delete data from File Gateway", async function () {
|
191
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
192
|
+
const testData = fileContent;
|
193
|
+
const fileUrl = await fileGateway?.buildUrl(fileStore?._url, testKey);
|
194
|
+
await fileGateway?.start(fileStore?._url);
|
195
|
+
await fileGateway?.put(fileUrl?.Ok(), testData);
|
196
|
+
const fileDeleteResult = await fileGateway?.delete(fileUrl?.Ok());
|
197
|
+
expect(fileDeleteResult?.Ok()).toBeFalsy();
|
198
|
+
});
|
199
|
+
|
200
|
+
it("should close File Gateway", async function () {
|
201
|
+
await fileGateway?.close(fileStore?._url);
|
202
|
+
});
|
203
|
+
it("should build WAL Gateway URL", async function () {
|
204
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
205
|
+
const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
|
206
|
+
expect(walUrl?.Ok()).toBeTruthy();
|
207
|
+
});
|
208
|
+
|
209
|
+
it("should start WAL Gateway", async function () {
|
210
|
+
await walGateway?.start(walStore?._url);
|
211
|
+
});
|
212
|
+
|
213
|
+
it("should put data to WAL Gateway", async function () {
|
214
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
215
|
+
const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
|
216
|
+
await walGateway?.start(walStore?._url);
|
217
|
+
const walTestDataString = JSON.stringify({
|
218
|
+
operations: [],
|
219
|
+
noLoaderOps: [],
|
220
|
+
fileOperations: [],
|
221
|
+
});
|
222
|
+
const walEncoder = new TextEncoder();
|
223
|
+
const walTestData = walEncoder.encode(walTestDataString);
|
224
|
+
const walPutResult = await walGateway?.put(walUrl?.Ok(), walTestData);
|
225
|
+
expect(walPutResult?.Ok()).toBeFalsy();
|
226
|
+
});
|
227
|
+
|
228
|
+
it("should get data from WAL Gateway", async function () {
|
229
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
230
|
+
const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
|
231
|
+
await walGateway?.start(walStore?._url);
|
232
|
+
const walTestDataString = JSON.stringify({
|
233
|
+
operations: [],
|
234
|
+
noLoaderOps: [],
|
235
|
+
fileOperations: [],
|
236
|
+
});
|
237
|
+
const walEncoder = new TextEncoder();
|
238
|
+
const walTestData = walEncoder.encode(walTestDataString);
|
239
|
+
await walGateway?.put(walUrl?.Ok(), walTestData);
|
240
|
+
const walGetResult = await walGateway?.get(walUrl?.Ok());
|
241
|
+
const okResult = walGetResult?.Ok();
|
242
|
+
const decodedResult = new TextDecoder().decode(okResult);
|
243
|
+
expect(decodedResult).toEqual(walTestDataString);
|
244
|
+
});
|
245
|
+
|
246
|
+
it("should delete data from WAL Gateway", async function () {
|
247
|
+
const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
|
248
|
+
const walUrl = await walGateway?.buildUrl(walStore?._url, testKey);
|
249
|
+
await walGateway?.start(walStore?._url);
|
250
|
+
const walTestDataString = JSON.stringify({
|
251
|
+
operations: [],
|
252
|
+
noLoaderOps: [],
|
253
|
+
fileOperations: [],
|
254
|
+
});
|
255
|
+
const walEncoder = new TextEncoder();
|
256
|
+
const walTestData = walEncoder.encode(walTestDataString);
|
257
|
+
await walGateway?.put(walUrl?.Ok(), walTestData);
|
258
|
+
const walDeleteResult = await walGateway?.delete(walUrl?.Ok());
|
259
|
+
expect(walDeleteResult?.Ok()).toBeFalsy();
|
260
|
+
});
|
261
|
+
|
262
|
+
it("should close WAL Gateway", async function () {
|
263
|
+
await walGateway?.start(walStore?._url);
|
264
|
+
await walGateway?.close(walStore?._url);
|
265
|
+
});
|
266
|
+
|
267
|
+
it("should have correct CAR Gateway properties", async function () {
|
268
|
+
// CAR Gateway assertions
|
269
|
+
expect(carGateway?.fidLength).toBe(4);
|
270
|
+
expect(carGateway?.headerSize).toBe(36);
|
271
|
+
expect(carGateway?.logger._attributes).toHaveProperty("module");
|
272
|
+
expect(carGateway?.logger._attributes).toHaveProperty("url");
|
273
|
+
});
|
274
|
+
|
275
|
+
it("should have correct Meta Gateway properties", async function () {
|
276
|
+
// Meta Gateway assertions
|
277
|
+
expect(metaGateway?.fidLength).toBe(4);
|
278
|
+
expect(metaGateway?.headerSize).toBe(36);
|
279
|
+
expect(metaGateway?.logger._attributes).toHaveProperty("module");
|
280
|
+
expect(metaGateway?.logger._attributes).not.toHaveProperty("url");
|
281
|
+
});
|
282
|
+
|
283
|
+
it("should have correct File Gateway properties", async function () {
|
284
|
+
// File Gateway assertions
|
285
|
+
expect(fileGateway?.fidLength).toBe(4);
|
286
|
+
expect(fileGateway?.headerSize).toBe(36);
|
287
|
+
expect(fileGateway?.logger._attributes).toHaveProperty("module");
|
288
|
+
expect(fileGateway?.logger._attributes).toHaveProperty("url");
|
289
|
+
});
|
290
|
+
|
291
|
+
it("should have correct WAL Gateway properties", async function () {
|
292
|
+
// WAL Gateway assertions
|
293
|
+
expect(walGateway?.fidLength).toBe(4);
|
294
|
+
expect(walGateway?.headerSize).toBe(36);
|
295
|
+
expect(walGateway?.logger._attributes).toHaveProperty("module");
|
296
|
+
expect(walGateway?.logger._attributes).not.toHaveProperty("url");
|
297
|
+
});
|
298
|
+
});
|
299
|
+
|
300
|
+
describe("noop Gateway subscribe", function () {
|
301
|
+
let db: Database;
|
302
|
+
|
303
|
+
let metaStore: ExtendedStore;
|
304
|
+
|
305
|
+
let metaGateway: ExtendedGateway;
|
306
|
+
|
307
|
+
afterEach(async function () {
|
308
|
+
await db.close();
|
309
|
+
await db.destroy();
|
310
|
+
});
|
311
|
+
beforeEach(async function () {
|
312
|
+
db = new Database("test-gateway-" + Math.random().toString(36).substring(7));
|
313
|
+
|
314
|
+
// Extract stores from the loader
|
315
|
+
metaStore = (await db.blockstore.loader?.metaStore()) as unknown as ExtendedStore;
|
316
|
+
|
317
|
+
metaGateway = metaStore?.gateway;
|
318
|
+
});
|
319
|
+
it("should subscribe to meta Gateway", async function () {
|
320
|
+
const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
|
321
|
+
await metaGateway?.start(metaStore?._url);
|
322
|
+
|
323
|
+
if (metaGateway.subscribe) {
|
324
|
+
let resolve: () => void;
|
325
|
+
let didCall = false;
|
326
|
+
const p = new Promise<void>((r) => {
|
327
|
+
resolve = r;
|
328
|
+
});
|
329
|
+
const metaSubscribeResult = await metaGateway?.subscribe?.(metaUrl?.Ok(), async (data: Uint8Array) => {
|
330
|
+
const decodedData = new TextDecoder().decode(data);
|
331
|
+
expect(decodedData).toContain("[]");
|
332
|
+
didCall = true;
|
333
|
+
resolve();
|
334
|
+
});
|
335
|
+
expect(metaSubscribeResult?.Ok()).toBeTruthy();
|
336
|
+
const ok = await db.put({ _id: "key1", hello: "world1" });
|
337
|
+
expect(ok).toBeTruthy();
|
338
|
+
expect(ok.id).toBe("key1");
|
339
|
+
await p;
|
340
|
+
expect(didCall).toBeTruthy();
|
341
|
+
}
|
342
|
+
});
|
343
|
+
});
|
344
|
+
|
345
|
+
describe("Gateway", function () {
|
346
|
+
let db: Database;
|
347
|
+
// let carStore: ExtendedStore;
|
348
|
+
let metaStore: ExtendedStore;
|
349
|
+
// let fileStore: ExtendedStore;
|
350
|
+
// let walStore: ExtendedStore;
|
351
|
+
// let carGateway: ExtendedGateway;
|
352
|
+
let metaGateway: ExtendedGateway;
|
353
|
+
// let fileGateway: ExtendedGateway;
|
354
|
+
// let walGateway: ExtendedGateway;
|
355
|
+
|
356
|
+
afterEach(async function () {
|
357
|
+
await db.close();
|
358
|
+
await db.destroy();
|
359
|
+
});
|
360
|
+
beforeEach(async function () {
|
361
|
+
db = new Database("test-gateway-" + Math.random().toString(36).substring(7));
|
362
|
+
const ok = await db.put({ _id: "test", foo: "bar" });
|
363
|
+
expect(ok).toBeTruthy();
|
364
|
+
expect(ok.id).toBe("test");
|
365
|
+
|
366
|
+
// Extract stores from the loader
|
367
|
+
// carStore = (await db.blockstore.loader?.carStore()) as unknown as ExtendedStore;
|
368
|
+
metaStore = (await db.blockstore.loader?.metaStore()) as unknown as ExtendedStore;
|
369
|
+
// fileStore = (await db.blockstore.loader?.fileStore()) as unknown as ExtendedStore;
|
370
|
+
// walStore = (await db.blockstore.loader?.WALStore()) as unknown as ExtendedStore;
|
371
|
+
|
372
|
+
// Extract and log gateways
|
373
|
+
// carGateway = carStore?.gateway;
|
374
|
+
metaGateway = metaStore?.gateway;
|
375
|
+
// fileGateway = fileStore?.gateway;
|
376
|
+
// walGateway = walStore?.gateway;
|
377
|
+
});
|
378
|
+
|
379
|
+
it("should get data from Meta Gateway", async function () {
|
380
|
+
const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
|
381
|
+
await metaGateway?.start(metaStore?._url);
|
382
|
+
const metaGetResult = await metaGateway?.get(metaUrl?.Ok());
|
383
|
+
const metaGetResultOk = metaGetResult?.Ok();
|
384
|
+
const decodedMetaGetResultOk = new TextDecoder().decode(metaGetResultOk);
|
385
|
+
expect(decodedMetaGetResultOk).toContain("parents");
|
386
|
+
});
|
387
|
+
|
388
|
+
it("should delete data from Meta Gateway", async function () {
|
389
|
+
const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main");
|
390
|
+
await metaGateway?.start(metaStore?._url);
|
391
|
+
// should we be testing .destroy() instead?
|
392
|
+
const metaDeleteResult = await metaGateway?.delete(metaUrl?.Ok());
|
393
|
+
expect(metaDeleteResult?.Ok()).toBeFalsy();
|
394
|
+
});
|
395
|
+
});
|