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