@fireproof/core-test 0.22.0-keybag → 0.23.1-dev-issue-1057
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/LICENSE.md +197 -228
- package/README.md +269 -0
- package/blockstore/interceptor-gateway.test.js.map +1 -1
- package/blockstore/keyed-crypto-indexeddb-file.test.js +1 -0
- package/blockstore/keyed-crypto-indexeddb-file.test.js.map +1 -1
- package/blockstore/keyed-crypto.test.js +1 -0
- package/blockstore/keyed-crypto.test.js.map +1 -1
- package/blockstore/loader.test.js.map +1 -1
- package/blockstore/standalone.test.js.map +1 -1
- package/blockstore/store.test.js.map +1 -1
- package/blockstore/transaction.test.js.map +1 -1
- package/fireproof/all-gateway.test.js.map +1 -1
- package/fireproof/attachable.test.js.map +1 -1
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js.map +1 -1
- package/fireproof/charwise-boolean.test.js.map +1 -1
- package/fireproof/compact-strategy.test.js.map +1 -1
- package/fireproof/concurrent.test.js +1 -1
- package/fireproof/concurrent.test.js.map +1 -1
- package/fireproof/crdt.test.js +1 -0
- package/fireproof/crdt.test.js.map +1 -1
- package/fireproof/database.test.js.map +1 -1
- package/fireproof/deleted-docs-handling.test.js.map +1 -1
- package/fireproof/fireproof.test.fixture.d.ts +3 -3
- package/fireproof/fireproof.test.fixture.js.map +1 -1
- package/fireproof/fireproof.test.js +1 -0
- package/fireproof/fireproof.test.js.map +1 -1
- package/fireproof/hello.test.js.map +1 -1
- package/fireproof/indexer.test.js.map +1 -1
- package/fireproof/multiple-ledger.test.js.map +1 -1
- package/fireproof/query-docs.test.js.map +1 -1
- package/fireproof/query-limit-issue.test.js.map +1 -1
- package/fireproof/query-property-inconsistency.test.js.map +1 -1
- package/fireproof/query-result-properties.test.js.map +1 -1
- package/fireproof/stable-cid.test.js.map +1 -1
- package/fireproof/utils.test.js.map +1 -1
- package/gateway/file/loader-config.test.js +2 -2
- package/gateway/file/loader-config.test.js.map +1 -1
- package/gateway/indexeddb/create-db-on-write.test.d.ts +1 -0
- package/gateway/indexeddb/create-db-on-write.test.js +145 -0
- package/gateway/indexeddb/create-db-on-write.test.js.map +1 -0
- package/gateway/indexeddb/loader-config.test.js.map +1 -1
- package/global-setup.js.map +1 -1
- package/helpers.js.map +1 -1
- package/package.json +21 -22
- package/protocols/cloud/msger.test.js.map +1 -1
- package/runtime/fp-envelope-serialize.test.js.map +1 -1
- package/runtime/key-bag.test.js.map +1 -1
- package/runtime/meta-key-hack.test.js.map +1 -1
- package/setup.file.js.map +1 -1
- package/setup.indexeddb.js.map +1 -1
- package/setup.memory.js.map +1 -1
- package/vitest.config.js.map +1 -1
- package/vitest.file.config.js.map +1 -1
- package/vitest.indexeddb.config.js.map +1 -1
- package/vitest.memory.config.js.map +1 -1
- package/blockstore/fp-envelope.test.ts-off +0 -65
- package/blockstore/fragment-gateway.test.ts-off +0 -106
- package/blockstore/interceptor-gateway.test.ts +0 -259
- package/blockstore/keyed-crypto-indexeddb-file.test.ts +0 -134
- package/blockstore/keyed-crypto.test.ts +0 -381
- package/blockstore/loader.test.ts +0 -313
- package/blockstore/standalone.test.ts +0 -156
- package/blockstore/store.test.ts +0 -199
- package/blockstore/transaction.test.ts +0 -132
- package/fireproof/all-gateway.test.ts +0 -477
- package/fireproof/attachable.test.ts +0 -677
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +0 -324
- package/fireproof/charwise-boolean.test.ts +0 -68
- package/fireproof/compact-strategy.test.ts +0 -40
- package/fireproof/concurrent.test.ts +0 -38
- package/fireproof/crdt.test.ts +0 -572
- package/fireproof/database.test.ts +0 -772
- package/fireproof/deleted-docs-handling.test.ts +0 -112
- package/fireproof/fireproof.test.fixture.ts +0 -133
- package/fireproof/fireproof.test.ts +0 -767
- package/fireproof/hello.test.ts +0 -75
- package/fireproof/indexer.test.ts +0 -459
- package/fireproof/multiple-ledger.test.ts +0 -67
- package/fireproof/query-docs.test.ts +0 -117
- package/fireproof/query-limit-issue.test.ts +0 -147
- package/fireproof/query-property-inconsistency.test.ts +0 -90
- package/fireproof/query-result-properties.test.ts +0 -43
- package/fireproof/stable-cid.test.ts +0 -72
- package/fireproof/utils.test.ts +0 -137
- package/gateway/file/loader-config.test.ts +0 -309
- package/gateway/indexeddb/loader-config.test.ts +0 -80
- package/global-setup.ts +0 -11
- package/helpers.ts +0 -177
- package/protocols/cloud/msger.test.ts +0 -559
- package/runtime/fp-envelope-serialize.test.ts +0 -266
- package/runtime/key-bag.test.ts +0 -243
- package/runtime/meta-key-hack.test.ts +0 -103
- package/setup.file.ts +0 -1
- package/setup.indexeddb.ts +0 -0
- package/setup.memory.ts +0 -2
- package/tsconfig.json +0 -18
- package/vitest.config.ts +0 -8
- package/vitest.file.config.ts +0 -11
- package/vitest.indexeddb.config.ts +0 -34
- package/vitest.memory.config.ts +0 -24
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { BuildURI, CoerceURI, runtimeFn, URI } from "@adviser/cement";
|
|
2
|
-
import { fireproof, PARAM, SuperThis } from "@fireproof/core";
|
|
3
|
-
import { mockSuperThis } from "../../helpers.js";
|
|
4
|
-
import { describe, beforeAll, it, expect } from "vitest";
|
|
5
|
-
import { FILESTORE_VERSION, sysFileSystemFactory } from "@fireproof/core-gateways-file";
|
|
6
|
-
|
|
7
|
-
function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI {
|
|
8
|
-
if (!base) {
|
|
9
|
-
const home = sthis.env.get("HOME") || "./";
|
|
10
|
-
base =
|
|
11
|
-
sthis.env.get("FP_STORAGE_URL") ||
|
|
12
|
-
`file://${sthis.pathOps.join(home, ".fireproof", FILESTORE_VERSION.replace(/-.*$/, ""))}?${PARAM.URL_GEN}=default`;
|
|
13
|
-
}
|
|
14
|
-
return URI.from(base.toString())
|
|
15
|
-
.build()
|
|
16
|
-
.setParam(PARAM.NAME, name || "")
|
|
17
|
-
.URI();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const _my_app = "my-app";
|
|
21
|
-
function my_app() {
|
|
22
|
-
return _my_app;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("config file gateway", () => {
|
|
26
|
-
const sthis = mockSuperThis();
|
|
27
|
-
// const isMemFS: { fs?: string } = {};
|
|
28
|
-
|
|
29
|
-
beforeAll(async () => {
|
|
30
|
-
await sthis.start();
|
|
31
|
-
// const url = URI.from(sthis.env.get("FP_STORAGE_URL"));
|
|
32
|
-
// if (url.getParam("fs") === "mem") {
|
|
33
|
-
// isMemFS.fs = "mem";
|
|
34
|
-
// }
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("loader", async () => {
|
|
38
|
-
const db = fireproof(my_app());
|
|
39
|
-
await db.put({ name: "my-app" });
|
|
40
|
-
expect(db.ledger.name).toBe(my_app());
|
|
41
|
-
|
|
42
|
-
const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
|
|
43
|
-
expect(fileStore?.url().asObj()).toEqual({
|
|
44
|
-
pathname: "./dist/fp-dir-file",
|
|
45
|
-
protocol: "file:",
|
|
46
|
-
searchParams: {
|
|
47
|
-
// ...isMemFS,
|
|
48
|
-
name: "my-app",
|
|
49
|
-
store: "file",
|
|
50
|
-
storekey: "@my-app-data@",
|
|
51
|
-
urlGen: "fromEnv",
|
|
52
|
-
version: "v0.19-file",
|
|
53
|
-
},
|
|
54
|
-
style: "path",
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const dataStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
|
|
58
|
-
expect(dataStore?.url().asObj()).toEqual({
|
|
59
|
-
pathname: "./dist/fp-dir-file",
|
|
60
|
-
protocol: "file:",
|
|
61
|
-
searchParams: {
|
|
62
|
-
// ...isMemFS,
|
|
63
|
-
name: "my-app",
|
|
64
|
-
store: "car",
|
|
65
|
-
suffix: ".car",
|
|
66
|
-
storekey: "@my-app-data@",
|
|
67
|
-
urlGen: "fromEnv",
|
|
68
|
-
version: "v0.19-file",
|
|
69
|
-
},
|
|
70
|
-
style: "path",
|
|
71
|
-
});
|
|
72
|
-
const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
|
|
73
|
-
expect(metaStore?.url().asObj()).toEqual({
|
|
74
|
-
pathname: "./dist/fp-dir-file",
|
|
75
|
-
protocol: "file:",
|
|
76
|
-
searchParams: {
|
|
77
|
-
// ...isMemFS,
|
|
78
|
-
name: "my-app",
|
|
79
|
-
store: "meta",
|
|
80
|
-
storekey: "@my-app-meta@",
|
|
81
|
-
urlGen: "fromEnv",
|
|
82
|
-
version: "v0.19-file",
|
|
83
|
-
},
|
|
84
|
-
style: "path",
|
|
85
|
-
});
|
|
86
|
-
const WALStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.wal;
|
|
87
|
-
expect(WALStore?.url().asObj()).toEqual({
|
|
88
|
-
pathname: "./dist/fp-dir-file",
|
|
89
|
-
protocol: "file:",
|
|
90
|
-
searchParams: {
|
|
91
|
-
// ...isMemFS,
|
|
92
|
-
name: "my-app",
|
|
93
|
-
store: "wal",
|
|
94
|
-
storekey: "@my-app-wal@",
|
|
95
|
-
urlGen: "fromEnv",
|
|
96
|
-
version: "v0.19-file",
|
|
97
|
-
},
|
|
98
|
-
style: "path",
|
|
99
|
-
});
|
|
100
|
-
await db.close();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("file path", async () => {
|
|
104
|
-
let baseDir = "./dist/data".replace(/\?.*$/, "").replace(/^file:\/\//, "");
|
|
105
|
-
baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
|
|
106
|
-
const base = BuildURI.from("./dist/data");
|
|
107
|
-
// if (isMemFS.fs) {
|
|
108
|
-
// base.setParam("fs", isMemFS.fs);
|
|
109
|
-
// }
|
|
110
|
-
const sysfs = await sysFileSystemFactory(base.URI());
|
|
111
|
-
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
|
112
|
-
/* */
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const db = fireproof(my_app(), { storeUrls: { base } });
|
|
116
|
-
// console.log(`>>>>>>>>>>>>>>>file-path`)
|
|
117
|
-
await db.put({ name: "my-app" });
|
|
118
|
-
expect(db.ledger.name).toBe(my_app());
|
|
119
|
-
const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
|
|
120
|
-
expect(carStore?.url().asObj()).toEqual({
|
|
121
|
-
pathname: "./dist/data",
|
|
122
|
-
protocol: "file:",
|
|
123
|
-
searchParams: {
|
|
124
|
-
// ...isMemFS,
|
|
125
|
-
name: "my-app",
|
|
126
|
-
store: "car",
|
|
127
|
-
storekey: "@my-app-data@",
|
|
128
|
-
suffix: ".car",
|
|
129
|
-
version: "v0.19-file",
|
|
130
|
-
},
|
|
131
|
-
style: "path",
|
|
132
|
-
});
|
|
133
|
-
const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
|
|
134
|
-
expect(fileStore?.url().asObj()).toEqual({
|
|
135
|
-
pathname: "./dist/data",
|
|
136
|
-
protocol: "file:",
|
|
137
|
-
searchParams: {
|
|
138
|
-
// ...isMemFS,
|
|
139
|
-
name: "my-app",
|
|
140
|
-
store: "file",
|
|
141
|
-
storekey: "@my-app-data@",
|
|
142
|
-
version: "v0.19-file",
|
|
143
|
-
},
|
|
144
|
-
style: "path",
|
|
145
|
-
});
|
|
146
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
|
147
|
-
const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
|
|
148
|
-
expect(metaStore?.url().asObj()).toEqual({
|
|
149
|
-
pathname: "./dist/data",
|
|
150
|
-
protocol: "file:",
|
|
151
|
-
searchParams: {
|
|
152
|
-
// ...isMemFS,
|
|
153
|
-
name: "my-app",
|
|
154
|
-
store: "meta",
|
|
155
|
-
storekey: "@my-app-meta@",
|
|
156
|
-
version: "v0.19-file",
|
|
157
|
-
},
|
|
158
|
-
style: "path",
|
|
159
|
-
});
|
|
160
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
|
161
|
-
await db.close();
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("homedir default", async () => {
|
|
165
|
-
const old = sthis.env.get("FP_STORAGE_URL");
|
|
166
|
-
sthis.env.delete("FP_STORAGE_URL");
|
|
167
|
-
// this switches file: protocol not memory:
|
|
168
|
-
let baseDir = dataDir(sthis, my_app()).pathname;
|
|
169
|
-
baseDir = sthis.pathOps.join(baseDir, my_app());
|
|
170
|
-
|
|
171
|
-
const base = BuildURI.from(baseDir);
|
|
172
|
-
// if (isMemFS.fs) {
|
|
173
|
-
// base.setParam("fs", isMemFS.fs);
|
|
174
|
-
// }
|
|
175
|
-
const sysfs = await sysFileSystemFactory(base.URI());
|
|
176
|
-
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
|
177
|
-
/* */
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
expect(baseDir).toMatch(new RegExp(`/\\.fireproof/${FILESTORE_VERSION.replace(/-file/, "")}/${my_app()}`));
|
|
181
|
-
|
|
182
|
-
const db = fireproof(my_app());
|
|
183
|
-
await db.put({ name: "my-app" });
|
|
184
|
-
expect(db.ledger.name).toBe(my_app());
|
|
185
|
-
const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
|
|
186
|
-
|
|
187
|
-
expect(carStore?.url().asObj()).toEqual({
|
|
188
|
-
pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
|
|
189
|
-
protocol: "file:",
|
|
190
|
-
style: "path",
|
|
191
|
-
searchParams: {
|
|
192
|
-
// ...isMemFS,
|
|
193
|
-
suffix: ".car",
|
|
194
|
-
runtime: runtimeFn().isDeno ? "deno" : "node",
|
|
195
|
-
urlGen: "default",
|
|
196
|
-
store: "car",
|
|
197
|
-
name: my_app(),
|
|
198
|
-
storekey: `@${my_app()}-data@`,
|
|
199
|
-
version: FILESTORE_VERSION,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
|
204
|
-
|
|
205
|
-
const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
|
|
206
|
-
expect(fileStore?.url().asObj()).toEqual({
|
|
207
|
-
pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
|
|
208
|
-
protocol: "file:",
|
|
209
|
-
style: "path",
|
|
210
|
-
searchParams: {
|
|
211
|
-
// ...isMemFS,
|
|
212
|
-
runtime: runtimeFn().isDeno ? "deno" : "node",
|
|
213
|
-
urlGen: "default",
|
|
214
|
-
store: "file",
|
|
215
|
-
name: my_app(),
|
|
216
|
-
storekey: `@${my_app()}-data@`,
|
|
217
|
-
version: FILESTORE_VERSION,
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
|
|
221
|
-
expect(metaStore?.url().asObj()).toEqual({
|
|
222
|
-
pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
|
|
223
|
-
protocol: "file:",
|
|
224
|
-
style: "path",
|
|
225
|
-
searchParams: {
|
|
226
|
-
// ...isMemFS,
|
|
227
|
-
runtime: runtimeFn().isDeno ? "deno" : "node",
|
|
228
|
-
urlGen: "default",
|
|
229
|
-
store: "meta",
|
|
230
|
-
name: my_app(),
|
|
231
|
-
storekey: `@${my_app()}-meta@`,
|
|
232
|
-
version: FILESTORE_VERSION,
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
|
237
|
-
sthis.env.set("FP_STORAGE_URL", old);
|
|
238
|
-
await db.close();
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("set by env", async () => {
|
|
242
|
-
const old = sthis.env.get("FP_STORAGE_URL");
|
|
243
|
-
// assert(!old, "FP_STORAGE_URL must set")
|
|
244
|
-
const testUrl = BuildURI.from(old);
|
|
245
|
-
// sthis.env.set("FP_STORAGE_URL", testUrl.toString());
|
|
246
|
-
|
|
247
|
-
let baseDir = dataDir(sthis, my_app()).pathname;
|
|
248
|
-
baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
|
|
249
|
-
|
|
250
|
-
const sysfs = await sysFileSystemFactory(testUrl.URI());
|
|
251
|
-
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
|
252
|
-
/* */
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
const db = fireproof(my_app());
|
|
256
|
-
await db.put({ name: "my-app" });
|
|
257
|
-
expect(db.ledger.name).toBe(my_app());
|
|
258
|
-
const carStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
|
|
259
|
-
expect(carStore?.url().asObj()).toEqual({
|
|
260
|
-
pathname: "./dist/fp-dir-file",
|
|
261
|
-
protocol: "file:",
|
|
262
|
-
style: "path",
|
|
263
|
-
searchParams: {
|
|
264
|
-
// ...isMemFS,
|
|
265
|
-
urlGen: "fromEnv",
|
|
266
|
-
store: "car",
|
|
267
|
-
// runtime: "node",
|
|
268
|
-
suffix: ".car",
|
|
269
|
-
name: my_app(),
|
|
270
|
-
storekey: `@${my_app()}-data@`,
|
|
271
|
-
version: FILESTORE_VERSION,
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
|
276
|
-
const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
|
|
277
|
-
expect(fileStore?.url().asObj()).toEqual({
|
|
278
|
-
pathname: `./dist/fp-dir-file`,
|
|
279
|
-
protocol: "file:",
|
|
280
|
-
style: "path",
|
|
281
|
-
searchParams: {
|
|
282
|
-
// ...isMemFS,
|
|
283
|
-
urlGen: "fromEnv",
|
|
284
|
-
store: "file",
|
|
285
|
-
name: my_app(),
|
|
286
|
-
storekey: `@${my_app()}-data@`,
|
|
287
|
-
version: FILESTORE_VERSION,
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
|
|
292
|
-
expect(metaStore?.url().asObj()).toEqual({
|
|
293
|
-
pathname: `./dist/fp-dir-file`,
|
|
294
|
-
protocol: "file:",
|
|
295
|
-
style: "path",
|
|
296
|
-
searchParams: {
|
|
297
|
-
// ...isMemFS,
|
|
298
|
-
urlGen: "fromEnv",
|
|
299
|
-
store: "meta",
|
|
300
|
-
name: my_app(),
|
|
301
|
-
storekey: `@${my_app()}-meta@`,
|
|
302
|
-
version: FILESTORE_VERSION,
|
|
303
|
-
},
|
|
304
|
-
});
|
|
305
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
|
306
|
-
await db.close();
|
|
307
|
-
sthis.env.set("FP_STORAGE_URL", old);
|
|
308
|
-
});
|
|
309
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { fireproof } from "@fireproof/core";
|
|
2
|
-
import { mockSuperThis } from "../../helpers.js";
|
|
3
|
-
import { describe, beforeAll, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
describe("fireproof config indexeddb", () => {
|
|
6
|
-
const _my_app = "my-app";
|
|
7
|
-
function my_app() {
|
|
8
|
-
return _my_app;
|
|
9
|
-
}
|
|
10
|
-
const sthis = mockSuperThis();
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
await sthis.start();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("indexeddb-loader", async () => {
|
|
16
|
-
const db = fireproof(my_app());
|
|
17
|
-
await db.put({ name: "my-app" });
|
|
18
|
-
expect(db.ledger.name).toBe(my_app());
|
|
19
|
-
|
|
20
|
-
const fileStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.file;
|
|
21
|
-
expect(fileStore?.url().asObj()).toEqual({
|
|
22
|
-
pathname: "fp",
|
|
23
|
-
protocol: "indexeddb:",
|
|
24
|
-
searchParams: {
|
|
25
|
-
name: "my-app",
|
|
26
|
-
store: "file",
|
|
27
|
-
runtime: "browser",
|
|
28
|
-
storekey: "@my-app-data@",
|
|
29
|
-
urlGen: "default",
|
|
30
|
-
version: "v0.19-indexeddb",
|
|
31
|
-
},
|
|
32
|
-
style: "path",
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const dataStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car;
|
|
36
|
-
expect(dataStore?.url().asObj()).toEqual({
|
|
37
|
-
pathname: "fp",
|
|
38
|
-
protocol: "indexeddb:",
|
|
39
|
-
searchParams: {
|
|
40
|
-
name: "my-app",
|
|
41
|
-
store: "car",
|
|
42
|
-
runtime: "browser",
|
|
43
|
-
storekey: "@my-app-data@",
|
|
44
|
-
suffix: ".car",
|
|
45
|
-
urlGen: "default",
|
|
46
|
-
version: "v0.19-indexeddb",
|
|
47
|
-
},
|
|
48
|
-
style: "path",
|
|
49
|
-
});
|
|
50
|
-
const metaStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.meta;
|
|
51
|
-
expect(metaStore?.url().asObj()).toEqual({
|
|
52
|
-
pathname: "fp",
|
|
53
|
-
protocol: "indexeddb:",
|
|
54
|
-
searchParams: {
|
|
55
|
-
name: "my-app",
|
|
56
|
-
store: "meta",
|
|
57
|
-
runtime: "browser",
|
|
58
|
-
storekey: "@my-app-meta@",
|
|
59
|
-
urlGen: "default",
|
|
60
|
-
version: "v0.19-indexeddb",
|
|
61
|
-
},
|
|
62
|
-
style: "path",
|
|
63
|
-
});
|
|
64
|
-
const WALStore = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.wal;
|
|
65
|
-
expect(WALStore?.url().asObj()).toEqual({
|
|
66
|
-
pathname: "fp",
|
|
67
|
-
protocol: "indexeddb:",
|
|
68
|
-
searchParams: {
|
|
69
|
-
name: "my-app",
|
|
70
|
-
store: "wal",
|
|
71
|
-
runtime: "browser",
|
|
72
|
-
storekey: "@my-app-wal@",
|
|
73
|
-
urlGen: "default",
|
|
74
|
-
version: "v0.19-indexeddb",
|
|
75
|
-
},
|
|
76
|
-
style: "path",
|
|
77
|
-
});
|
|
78
|
-
await db.close();
|
|
79
|
-
});
|
|
80
|
-
});
|
package/global-setup.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { cd, $ } from "zx";
|
|
2
|
-
import type { TestProject } from "vitest/node";
|
|
3
|
-
|
|
4
|
-
export async function setup(project: TestProject) {
|
|
5
|
-
const root = project.toJSON().serializedConfig.root;
|
|
6
|
-
$.verbose = true;
|
|
7
|
-
cd(root);
|
|
8
|
-
return () => {
|
|
9
|
-
/* no-op */
|
|
10
|
-
};
|
|
11
|
-
}
|
package/helpers.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { BuildURI, MockLogger, runtimeFn, toCryptoRuntime, URI, utils, LogCollector, Logger, AppContext } from "@adviser/cement";
|
|
2
|
-
import { SuperThis, SuperThisOpts, PARAM, Attachable, Attached, CarTransaction, Falsy, DbMeta } from "@fireproof/core";
|
|
3
|
-
import { CID } from "multiformats";
|
|
4
|
-
import { sha256 } from "multiformats/hashes/sha2";
|
|
5
|
-
import * as json from "multiformats/codecs/json";
|
|
6
|
-
import { CommitQueue, encodeFile, ensureSuperThis, TaskManager } from "@fireproof/core-runtime";
|
|
7
|
-
import { defaultKeyBagOpts, getKeyBag, KeyBag } from "@fireproof/core-keybag";
|
|
8
|
-
import { AttachedRemotesImpl, toStoreRuntime } from "@fireproof/core-blockstore";
|
|
9
|
-
import {
|
|
10
|
-
Loadable,
|
|
11
|
-
BlockstoreRuntime,
|
|
12
|
-
CarLog,
|
|
13
|
-
AttachedStores,
|
|
14
|
-
ActiveStore,
|
|
15
|
-
CarGroup,
|
|
16
|
-
CommitOpts,
|
|
17
|
-
FPBlock,
|
|
18
|
-
CarBlockItem,
|
|
19
|
-
TransactionMeta,
|
|
20
|
-
AnyLink,
|
|
21
|
-
} from "@fireproof/core-types-blockstore";
|
|
22
|
-
|
|
23
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
24
|
-
export function tracer() {}
|
|
25
|
-
|
|
26
|
-
async function toFileWithCid(buffer: Uint8Array, name: string, opts: FilePropertyBag): Promise<FileWithCid> {
|
|
27
|
-
return {
|
|
28
|
-
file: new File([new Blob([buffer])], name, opts),
|
|
29
|
-
cid: (await encodeFile(new File([new Blob([buffer])], name, opts))).cid.toString(),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface FileWithCid {
|
|
34
|
-
file: File;
|
|
35
|
-
cid: string;
|
|
36
|
-
}
|
|
37
|
-
export async function buildBlobFiles(): Promise<FileWithCid[]> {
|
|
38
|
-
const cp = toCryptoRuntime();
|
|
39
|
-
return [
|
|
40
|
-
await toFileWithCid(cp.randomBytes(Math.random() * 51283), `image.jpg`, { type: "image/jpeg" }),
|
|
41
|
-
await toFileWithCid(cp.randomBytes(Math.random() * 51283), `fireproof.png`, { type: "image/png" }),
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function storageURL(sthis: SuperThis): URI {
|
|
46
|
-
const old = sthis.env.get("FP_STORAGE_URL");
|
|
47
|
-
let merged: URI;
|
|
48
|
-
if (runtimeFn().isBrowser) {
|
|
49
|
-
merged = URI.merge(`indexeddb://fp`, old, "indexeddb:");
|
|
50
|
-
} else {
|
|
51
|
-
merged = URI.merge(`./dist/env`, old);
|
|
52
|
-
}
|
|
53
|
-
return merged;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type MockSuperThis = SuperThis & { ctx: { readonly logCollector: LogCollector } };
|
|
57
|
-
export function mockSuperThis(sthis?: Partial<SuperThisOpts>): MockSuperThis {
|
|
58
|
-
const mockLog = MockLogger({
|
|
59
|
-
pass: new utils.ConsoleWriterStreamDefaultWriter(new utils.ConsoleWriterStream()),
|
|
60
|
-
});
|
|
61
|
-
return ensureSuperThis({
|
|
62
|
-
...sthis,
|
|
63
|
-
logger: mockLog.logger,
|
|
64
|
-
ctx: AppContext.merge({
|
|
65
|
-
logCollector: mockLog.logCollector,
|
|
66
|
-
}),
|
|
67
|
-
}) as MockSuperThis;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function noopUrl(name?: string): URI {
|
|
71
|
-
const burl = BuildURI.from("memory://noop");
|
|
72
|
-
burl.setParam(PARAM.NAME, name || "test");
|
|
73
|
-
return burl.URI();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function simpleBlockOpts(sthis: SuperThis, name?: string) {
|
|
77
|
-
const url = noopUrl(name);
|
|
78
|
-
return {
|
|
79
|
-
keyBag: defaultKeyBagOpts(sthis),
|
|
80
|
-
storeRuntime: toStoreRuntime(sthis),
|
|
81
|
-
storeUrls: {
|
|
82
|
-
file: url,
|
|
83
|
-
wal: url,
|
|
84
|
-
meta: url,
|
|
85
|
-
car: url,
|
|
86
|
-
},
|
|
87
|
-
tracer,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function simpleCID(sthis: SuperThis) {
|
|
92
|
-
const bytes = json.encode({ hello: sthis.nextId().str });
|
|
93
|
-
const hash = await sha256.digest(bytes);
|
|
94
|
-
return CID.create(1, json.code, hash);
|
|
95
|
-
}
|
|
96
|
-
class MockLoader implements Loadable {
|
|
97
|
-
readonly sthis: SuperThis;
|
|
98
|
-
readonly logger: Logger;
|
|
99
|
-
readonly ebOpts: BlockstoreRuntime;
|
|
100
|
-
readonly carLog: CarLog;
|
|
101
|
-
readonly attachedStores: AttachedStores;
|
|
102
|
-
readonly taskManager: TaskManager;
|
|
103
|
-
readonly commitQueue: CommitQueue<unknown>;
|
|
104
|
-
|
|
105
|
-
constructor(sthis: SuperThis) {
|
|
106
|
-
this.sthis = sthis;
|
|
107
|
-
this.logger = sthis.logger;
|
|
108
|
-
this.ebOpts = {
|
|
109
|
-
// keyBag: sthis.keyBag,
|
|
110
|
-
// storeRuntime: sthis.storeRuntime,
|
|
111
|
-
storeUrls: {
|
|
112
|
-
file: noopUrl("test"),
|
|
113
|
-
wal: noopUrl("test"),
|
|
114
|
-
meta: noopUrl("test"),
|
|
115
|
-
car: noopUrl("test"),
|
|
116
|
-
},
|
|
117
|
-
} as BlockstoreRuntime;
|
|
118
|
-
this.carLog = new CarLog();
|
|
119
|
-
this.taskManager = new TaskManager(sthis, () => Promise.resolve(), {
|
|
120
|
-
removeAfter: 3,
|
|
121
|
-
retryTimeout: 50,
|
|
122
|
-
});
|
|
123
|
-
this.attachedStores = new AttachedRemotesImpl(this);
|
|
124
|
-
this.commitQueue = new CommitQueue({
|
|
125
|
-
tracer,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
-
attach(attached: Attachable): Promise<Attached> {
|
|
131
|
-
throw new Error("Method not implemented.");
|
|
132
|
-
}
|
|
133
|
-
ready(): Promise<void> {
|
|
134
|
-
throw new Error("Method not implemented.");
|
|
135
|
-
}
|
|
136
|
-
close(): Promise<void> {
|
|
137
|
-
throw new Error("Method not implemented.");
|
|
138
|
-
}
|
|
139
|
-
keyBag(): Promise<KeyBag> {
|
|
140
|
-
return getKeyBag(this.sthis, {});
|
|
141
|
-
}
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
143
|
-
handleDbMetasFromStore(metas: DbMeta[], store: ActiveStore): Promise<CarGroup> {
|
|
144
|
-
// throw new Error("Method not implemented.");
|
|
145
|
-
return Promise.resolve([]);
|
|
146
|
-
}
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
148
|
-
commit<T = unknown>(t: CarTransaction, done: T, opts: CommitOpts): Promise<CarGroup> {
|
|
149
|
-
throw new Error("Method not implemented.");
|
|
150
|
-
}
|
|
151
|
-
destroy(): Promise<void> {
|
|
152
|
-
throw new Error("Method not implemented.");
|
|
153
|
-
}
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
155
|
-
getBlock(cid: AnyLink, store: ActiveStore): Promise<FPBlock | Falsy> {
|
|
156
|
-
throw new Error("Method not implemented.");
|
|
157
|
-
}
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
|
-
loadFileCar(cid: AnyLink, store: ActiveStore): Promise<FPBlock<CarBlockItem>> {
|
|
160
|
-
throw new Error("Method not implemented.");
|
|
161
|
-
}
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
|
-
loadCar(cid: AnyLink, store: ActiveStore): Promise<FPBlock<CarBlockItem>> {
|
|
164
|
-
throw new Error("Method not implemented.");
|
|
165
|
-
}
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
167
|
-
commitFiles(t: CarTransaction, done: TransactionMeta): Promise<CarGroup> {
|
|
168
|
-
throw new Error("Method not implemented.");
|
|
169
|
-
}
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
-
entries(cache?: boolean): AsyncIterableIterator<FPBlock> {
|
|
172
|
-
throw new Error("Method not implemented.");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
export function mockLoader(sthis: SuperThis): Loadable {
|
|
176
|
-
return new MockLoader(sthis);
|
|
177
|
-
}
|