@fireproof/core 0.19.101 → 0.19.103
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/{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
@@ -0,0 +1,172 @@
|
|
1
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
2
|
+
import { dataDir, fireproof, rt } from "@fireproof/core";
|
3
|
+
import { runtimeFn, URI } from "@adviser/cement";
|
4
|
+
import { mockSuperThis } from "../helpers";
|
5
|
+
|
6
|
+
describe("runtime", () => {
|
7
|
+
it("runtime", () => {
|
8
|
+
const isNode = !!(typeof process === "object" && process.versions?.node);
|
9
|
+
expect(runtimeFn()).toEqual({
|
10
|
+
isBrowser: !isNode,
|
11
|
+
isDeno: false,
|
12
|
+
isNodeIsh: isNode,
|
13
|
+
isReactNative: false,
|
14
|
+
});
|
15
|
+
});
|
16
|
+
});
|
17
|
+
|
18
|
+
describe("fireproof/config", () => {
|
19
|
+
let _my_app = "my-app";
|
20
|
+
function my_app() {
|
21
|
+
return _my_app;
|
22
|
+
}
|
23
|
+
function params(store: string) {
|
24
|
+
return Object.entries({
|
25
|
+
store,
|
26
|
+
name: my_app(),
|
27
|
+
storekey: `@${my_app()}:${store}@`,
|
28
|
+
version: rt.FILESTORE_VERSION,
|
29
|
+
});
|
30
|
+
}
|
31
|
+
const sthis = mockSuperThis();
|
32
|
+
beforeAll(async () => {
|
33
|
+
await sthis.start();
|
34
|
+
if (runtimeFn().isNodeIsh) {
|
35
|
+
const fpStorageUrl = sthis.env.get("FP_STORAGE_URL");
|
36
|
+
if (fpStorageUrl) {
|
37
|
+
const url = URI.from(fpStorageUrl);
|
38
|
+
_my_app = `my-app-${url.protocol.replace(/:$/, "")}:${url.getParam("fs") || "fs"}`;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
});
|
42
|
+
|
43
|
+
if (!runtimeFn().isNodeIsh) {
|
44
|
+
it("default", async () => {
|
45
|
+
const db = fireproof(my_app());
|
46
|
+
await db.put({ name: "my-app" });
|
47
|
+
expect(db.name).toBe(my_app());
|
48
|
+
|
49
|
+
const fileStore = await db.blockstore.loader?.fileStore();
|
50
|
+
expect(fileStore?.url().toString()).toMatch(
|
51
|
+
new RegExp(`indexdb://fp\\?name=my-app&store=data&storekey=%40my-app%3Adata%40&version=${rt.INDEXDB_VERSION}`),
|
52
|
+
);
|
53
|
+
const metaStore = await db.blockstore.loader?.metaStore();
|
54
|
+
expect(metaStore?.url().toString()).toMatch(
|
55
|
+
new RegExp(`indexdb://fp\\?name=my-app&store=meta&storekey=%40my-app%3Ameta%40&version=${rt.INDEXDB_VERSION}`),
|
56
|
+
);
|
57
|
+
|
58
|
+
const carStore = await db.blockstore.loader?.carStore();
|
59
|
+
expect(carStore?.url().toString()).toMatch(
|
60
|
+
new RegExp(`indexdb://fp\\?name=my-app&store=data&storekey=%40my-app%3Adata%40&version=${rt.INDEXDB_VERSION}`),
|
61
|
+
);
|
62
|
+
|
63
|
+
await db.close();
|
64
|
+
});
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
it("node default", async () => {
|
68
|
+
const old = sthis.env.get("FP_STORAGE_URL");
|
69
|
+
sthis.env.delete("FP_STORAGE_URL");
|
70
|
+
let baseDir = dataDir(sthis, my_app()).pathname;
|
71
|
+
baseDir = sthis.pathOps.join(baseDir, rt.FILESTORE_VERSION, my_app());
|
72
|
+
|
73
|
+
const sysfs = await rt.getFileSystem(URI.from(baseDir));
|
74
|
+
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
75
|
+
/* */
|
76
|
+
});
|
77
|
+
|
78
|
+
expect(baseDir).toMatch(new RegExp(`/\\.fireproof/${rt.FILESTORE_VERSION}/${my_app()}`));
|
79
|
+
|
80
|
+
const db = fireproof(my_app());
|
81
|
+
await db.put({ name: "my-app" });
|
82
|
+
expect(db.name).toBe(my_app());
|
83
|
+
const carStore = await db.blockstore.loader?.carStore();
|
84
|
+
|
85
|
+
for (const [param, value] of Object.entries({
|
86
|
+
store: "data",
|
87
|
+
name: my_app(),
|
88
|
+
storekey: `@${my_app()}:data@`,
|
89
|
+
version: rt.FILESTORE_VERSION,
|
90
|
+
})) {
|
91
|
+
expect(carStore?.url().getParam(param)).toBe(value);
|
92
|
+
}
|
93
|
+
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
94
|
+
|
95
|
+
const fileStore = await db.blockstore.loader?.fileStore();
|
96
|
+
for (const [param, value] of params("data")) {
|
97
|
+
expect(fileStore?.url().getParam(param)).toBe(value);
|
98
|
+
}
|
99
|
+
const metaStore = await db.blockstore.loader?.metaStore();
|
100
|
+
for (const [param, value] of params("meta")) {
|
101
|
+
expect(metaStore?.url().getParam(param)).toBe(value);
|
102
|
+
}
|
103
|
+
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
104
|
+
sthis.env.set("FP_STORAGE_URL", old);
|
105
|
+
await db.close();
|
106
|
+
});
|
107
|
+
|
108
|
+
it("set by env", async () => {
|
109
|
+
const old = sthis.env.get("FP_STORAGE_URL");
|
110
|
+
const testUrl = URI.merge(`./dist/env`, old);
|
111
|
+
sthis.env.set("FP_STORAGE_URL", testUrl.toString());
|
112
|
+
|
113
|
+
let baseDir = dataDir(sthis, my_app()).pathname;
|
114
|
+
baseDir = sthis.pathOps.join(baseDir, rt.FILESTORE_VERSION, my_app());
|
115
|
+
|
116
|
+
const sysfs = await rt.getFileSystem(testUrl);
|
117
|
+
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
118
|
+
/* */
|
119
|
+
});
|
120
|
+
|
121
|
+
const db = fireproof(my_app());
|
122
|
+
await db.put({ name: "my-app" });
|
123
|
+
expect(db.name).toBe(my_app());
|
124
|
+
const carStore = await db.blockstore.loader?.carStore();
|
125
|
+
for (const [param, value] of params("data")) {
|
126
|
+
expect(carStore?.url().getParam(param)).toBe(value);
|
127
|
+
}
|
128
|
+
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
129
|
+
const fileStore = await db.blockstore.loader?.fileStore();
|
130
|
+
for (const [param, value] of params("data")) {
|
131
|
+
expect(fileStore?.url().getParam(param)).toBe(value);
|
132
|
+
}
|
133
|
+
const metaStore = await db.blockstore.loader?.metaStore();
|
134
|
+
for (const [param, value] of params("meta")) {
|
135
|
+
expect(metaStore?.url().getParam(param)).toBe(value);
|
136
|
+
}
|
137
|
+
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
138
|
+
await db.close();
|
139
|
+
sthis.env.set("FP_STORAGE_URL", old);
|
140
|
+
});
|
141
|
+
|
142
|
+
it("file path", async () => {
|
143
|
+
let baseDir = "./dist/data".replace(/\?.*$/, "").replace(/^file:\/\//, "");
|
144
|
+
baseDir = sthis.pathOps.join(baseDir, rt.FILESTORE_VERSION, my_app());
|
145
|
+
|
146
|
+
const base = "./dist/data";
|
147
|
+
const sysfs = await rt.getFileSystem(URI.from(base));
|
148
|
+
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
149
|
+
/* */
|
150
|
+
});
|
151
|
+
|
152
|
+
const db = fireproof(my_app(), { store: { stores: { base } } });
|
153
|
+
// console.log(`>>>>>>>>>>>>>>>file-path`)
|
154
|
+
await db.put({ name: "my-app" });
|
155
|
+
expect(db.name).toBe(my_app());
|
156
|
+
const carStore = await db.blockstore.loader?.carStore();
|
157
|
+
for (const [param, value] of params("data")) {
|
158
|
+
expect(carStore?.url().getParam(param)).toBe(value);
|
159
|
+
}
|
160
|
+
const fileStore = await db.blockstore.loader?.fileStore();
|
161
|
+
for (const [param, value] of params("data")) {
|
162
|
+
expect(fileStore?.url().getParam(param)).toBe(value);
|
163
|
+
}
|
164
|
+
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
165
|
+
const metaStore = await db.blockstore.loader?.metaStore();
|
166
|
+
for (const [param, value] of params("meta")) {
|
167
|
+
expect(metaStore?.url().getParam(param)).toBe(value);
|
168
|
+
}
|
169
|
+
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
170
|
+
await db.close();
|
171
|
+
});
|
172
|
+
});
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import { CRDT
|
1
|
+
import { CRDT } from "@fireproof/core";
|
2
2
|
import { bs } from "@fireproof/core";
|
3
3
|
import { CRDTMeta, DocValue } from "@fireproof/core";
|
4
4
|
import { Index, index } from "@fireproof/core";
|
5
5
|
import { mockSuperThis } from "../helpers";
|
6
|
-
import { defaultKeyBagOpts } from "../../src/runtime/key-bag";
|
7
6
|
|
8
7
|
describe("Fresh crdt", function () {
|
9
8
|
let crdt: CRDT<{ hello: string } | { points: number }>;
|
@@ -14,12 +13,7 @@ describe("Fresh crdt", function () {
|
|
14
13
|
});
|
15
14
|
beforeEach(async function () {
|
16
15
|
await sthis.start();
|
17
|
-
|
18
|
-
keyBag: defaultKeyBagOpts(sthis),
|
19
|
-
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
20
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
21
|
-
};
|
22
|
-
crdt = new CRDT(sthis, dbOpts);
|
16
|
+
crdt = new CRDT(sthis);
|
23
17
|
});
|
24
18
|
it("should have an empty head", async function () {
|
25
19
|
const head = crdt.clock.head;
|
@@ -56,12 +50,7 @@ describe("CRDT with one record", function () {
|
|
56
50
|
|
57
51
|
beforeEach(async function () {
|
58
52
|
await sthis.start();
|
59
|
-
|
60
|
-
keyBag: defaultKeyBagOpts(sthis),
|
61
|
-
storeUrls: toStoreURIRuntime(sthis, `test@${sthis.nextId()}`),
|
62
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
63
|
-
};
|
64
|
-
crdt = new CRDT(sthis, dbOpts);
|
53
|
+
crdt = new CRDT(sthis, `test@${sthis.nextId()}`);
|
65
54
|
firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
|
66
55
|
});
|
67
56
|
it("should have a one-element head", async function () {
|
@@ -111,12 +100,7 @@ describe("CRDT with a multi-write", function () {
|
|
111
100
|
});
|
112
101
|
beforeEach(async function () {
|
113
102
|
await sthis.start();
|
114
|
-
|
115
|
-
keyBag: defaultKeyBagOpts(sthis),
|
116
|
-
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
117
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
118
|
-
};
|
119
|
-
crdt = new CRDT(sthis, dbOpts);
|
103
|
+
crdt = new CRDT(sthis);
|
120
104
|
firstPut = await crdt.bulk([
|
121
105
|
{ id: "ace", value: { points: 11 } },
|
122
106
|
{ id: "king", value: { points: 10 } },
|
@@ -181,12 +165,7 @@ describe("CRDT with two multi-writes", function () {
|
|
181
165
|
});
|
182
166
|
beforeEach(async () => {
|
183
167
|
await sthis.start();
|
184
|
-
|
185
|
-
keyBag: defaultKeyBagOpts(sthis),
|
186
|
-
storeUrls: toStoreURIRuntime(sthis, `test-multiple-writes@${sthis.nextId()}`),
|
187
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
188
|
-
};
|
189
|
-
crdt = new CRDT(sthis, dbOpts);
|
168
|
+
crdt = new CRDT(sthis);
|
190
169
|
firstPut = await crdt.bulk([
|
191
170
|
{ id: "ace", value: { points: 11 } },
|
192
171
|
{ id: "king", value: { points: 10 } },
|
@@ -234,12 +213,7 @@ describe("Compact a named CRDT with writes", function () {
|
|
234
213
|
});
|
235
214
|
beforeEach(async function () {
|
236
215
|
await sthis.start();
|
237
|
-
|
238
|
-
keyBag: defaultKeyBagOpts(sthis),
|
239
|
-
storeUrls: toStoreURIRuntime(sthis, `named-crdt-compaction`),
|
240
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
241
|
-
};
|
242
|
-
crdt = new CRDT(sthis, dbOpts);
|
216
|
+
crdt = new CRDT(sthis, "named-crdt-compaction");
|
243
217
|
for (let i = 0; i < 10; i++) {
|
244
218
|
const bulk = [
|
245
219
|
{ id: "ace", value: { points: 11 } },
|
@@ -295,17 +269,12 @@ describe("CRDT with an index", function () {
|
|
295
269
|
});
|
296
270
|
beforeEach(async function () {
|
297
271
|
await sthis.start();
|
298
|
-
|
299
|
-
keyBag: defaultKeyBagOpts(sthis),
|
300
|
-
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
301
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
302
|
-
};
|
303
|
-
crdt = new CRDT<CRDTTestType>(sthis, dbOpts);
|
272
|
+
crdt = new CRDT<CRDTTestType>(sthis);
|
304
273
|
await crdt.bulk([
|
305
274
|
{ id: "ace", value: { points: 11 } },
|
306
275
|
{ id: "king", value: { points: 10 } },
|
307
276
|
]);
|
308
|
-
idx = await index<number, CRDTTestType>({
|
277
|
+
idx = await index<number, CRDTTestType>(sthis, { _crdt: crdt }, "points");
|
309
278
|
});
|
310
279
|
it("should query the data", async function () {
|
311
280
|
const got = await idx.query({ range: [9, 12] });
|
@@ -314,7 +283,7 @@ describe("CRDT with an index", function () {
|
|
314
283
|
expect(got.rows[0].key).toBe(10);
|
315
284
|
});
|
316
285
|
it("should register the index", async function () {
|
317
|
-
const rIdx = await index<number, CRDTTestType>({
|
286
|
+
const rIdx = await index<number, CRDTTestType>(sthis, { _crdt: crdt }, "points");
|
318
287
|
expect(rIdx).toBeTruthy();
|
319
288
|
expect(rIdx.name).toBe("points");
|
320
289
|
const got = await rIdx.query({ range: [9, 12] });
|
@@ -323,7 +292,7 @@ describe("CRDT with an index", function () {
|
|
323
292
|
expect(got.rows[0].key).toBe(10);
|
324
293
|
});
|
325
294
|
it("creating a different index with same name should not work", async function () {
|
326
|
-
const e = await index({
|
295
|
+
const e = await index(sthis, { _crdt: crdt }, "points", (doc) => doc._id)
|
327
296
|
.query()
|
328
297
|
.catch((err) => err);
|
329
298
|
expect(e.message).toMatch(/cannot apply/);
|
@@ -346,25 +315,15 @@ describe("Loader with a committed transaction", function () {
|
|
346
315
|
});
|
347
316
|
beforeEach(async function () {
|
348
317
|
await sthis.start();
|
349
|
-
|
350
|
-
keyBag: defaultKeyBagOpts(sthis),
|
351
|
-
storeUrls: toStoreURIRuntime(sthis, dbname),
|
352
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
353
|
-
};
|
354
|
-
crdt = new CRDT(sthis, dbOpts);
|
318
|
+
crdt = new CRDT(sthis, dbname);
|
355
319
|
blockstore = crdt.blockstore as bs.EncryptedBlockstore;
|
356
320
|
expect(blockstore.loader).toBeTruthy();
|
357
321
|
loader = blockstore.loader;
|
358
322
|
done = await crdt.bulk([{ id: "foo", value: { foo: "bar" } }]);
|
359
323
|
});
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
// file: "file://./dist/fp-dir-file?name=test-loader&store=data&storekey=%40test-loader-data%40&urlGen=fromEnv",
|
364
|
-
// meta: "file://./dist/fp-dir-file?name=test-loader&store=meta&storekey=%40test-loader-meta%40&urlGen=fromEnv",
|
365
|
-
// wal: "file://./dist/fp-dir-file?name=test-loader&store=wal&storekey=%40test-loader-wal%40&urlGen=fromEnv",
|
366
|
-
// });
|
367
|
-
// });
|
324
|
+
it("should have a name", function () {
|
325
|
+
expect(loader.name).toBe(dbname);
|
326
|
+
});
|
368
327
|
it("should commit a transaction", function () {
|
369
328
|
expect(done.head).toBeTruthy();
|
370
329
|
// expect(done.cars).toBeTruthy();
|
@@ -399,12 +358,7 @@ describe("Loader with two committed transactions", function () {
|
|
399
358
|
});
|
400
359
|
beforeEach(async function () {
|
401
360
|
await sthis.start();
|
402
|
-
|
403
|
-
keyBag: defaultKeyBagOpts(sthis),
|
404
|
-
storeUrls: toStoreURIRuntime(sthis, "test-loader"),
|
405
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
406
|
-
};
|
407
|
-
crdt = new CRDT(sthis, dbOpts);
|
361
|
+
crdt = new CRDT(sthis, "test-loader");
|
408
362
|
blockstore = crdt.blockstore as bs.EncryptedBlockstore;
|
409
363
|
expect(blockstore.loader).toBeTruthy();
|
410
364
|
loader = blockstore.loader;
|
@@ -454,12 +408,7 @@ describe("Loader with many committed transactions", function () {
|
|
454
408
|
});
|
455
409
|
beforeEach(async function () {
|
456
410
|
await sthis.start();
|
457
|
-
|
458
|
-
keyBag: defaultKeyBagOpts(sthis),
|
459
|
-
storeUrls: toStoreURIRuntime(sthis, "test-loader-many"),
|
460
|
-
storeEnDe: bs.ensureStoreEnDeFile({}),
|
461
|
-
};
|
462
|
-
crdt = new CRDT(sthis, dbOpts);
|
411
|
+
crdt = new CRDT(sthis, "test-loader-many");
|
463
412
|
blockstore = crdt.blockstore as bs.EncryptedBlockstore;
|
464
413
|
expect(blockstore.loader).toBeTruthy();
|
465
414
|
loader = blockstore.loader;
|
@@ -1,19 +1,5 @@
|
|
1
|
-
import { URI } from "@adviser/cement";
|
2
1
|
import { buildBlobFiles, FileWithCid, mockSuperThis } from "../helpers.js";
|
3
|
-
import {
|
4
|
-
bs,
|
5
|
-
Database,
|
6
|
-
DocResponse,
|
7
|
-
DocFileMeta,
|
8
|
-
DocWithId,
|
9
|
-
DocFiles,
|
10
|
-
toStoreURIRuntime,
|
11
|
-
keyConfigOpts,
|
12
|
-
DatabaseFactory,
|
13
|
-
DatabaseShell,
|
14
|
-
} from "@fireproof/core";
|
15
|
-
import { fileGatewayFactoryItem } from "../../src/blockstore/register-store-protocol.js";
|
16
|
-
import { FILESTORE_VERSION } from "../../src/runtime/index.js";
|
2
|
+
import { bs, Database, DocResponse, DocFileMeta, DocWithId, DocFiles } from "@fireproof/core";
|
17
3
|
|
18
4
|
describe("basic Database", () => {
|
19
5
|
let db: Database;
|
@@ -24,9 +10,7 @@ describe("basic Database", () => {
|
|
24
10
|
});
|
25
11
|
beforeEach(async () => {
|
26
12
|
await sthis.start();
|
27
|
-
db =
|
28
|
-
logger: sthis.logger,
|
29
|
-
});
|
13
|
+
db = new Database();
|
30
14
|
});
|
31
15
|
it("should put", async () => {
|
32
16
|
/** @type {Doc} */
|
@@ -54,7 +38,7 @@ describe("basic Database with record", function () {
|
|
54
38
|
interface Doc {
|
55
39
|
readonly value: string;
|
56
40
|
}
|
57
|
-
let db:
|
41
|
+
let db: Database;
|
58
42
|
const sthis = mockSuperThis();
|
59
43
|
afterEach(async () => {
|
60
44
|
await db.close();
|
@@ -62,7 +46,7 @@ describe("basic Database with record", function () {
|
|
62
46
|
});
|
63
47
|
beforeEach(async function () {
|
64
48
|
await sthis.start();
|
65
|
-
db =
|
49
|
+
db = new Database();
|
66
50
|
const ok = await db.put<Doc>({ _id: "hello", value: "world" });
|
67
51
|
expect(ok.id).toBe("hello");
|
68
52
|
});
|
@@ -94,13 +78,13 @@ describe("basic Database with record", function () {
|
|
94
78
|
expect(rows[0].value._id).toBe("hello");
|
95
79
|
});
|
96
80
|
it("is not persisted", async function () {
|
97
|
-
const db2 =
|
81
|
+
const db2 = new Database();
|
98
82
|
const { rows } = await db2.changes([]);
|
99
|
-
expect(rows.length).toBe(
|
100
|
-
|
101
|
-
|
102
|
-
expect(doc.value).toBe("world");
|
83
|
+
expect(rows.length).toBe(0);
|
84
|
+
const doc = await db2.get("hello").catch((e) => e);
|
85
|
+
expect(doc.message).toBeTruthy();
|
103
86
|
await db2.close();
|
87
|
+
await db2.destroy();
|
104
88
|
});
|
105
89
|
});
|
106
90
|
|
@@ -116,7 +100,7 @@ describe("named Database with record", function () {
|
|
116
100
|
});
|
117
101
|
beforeEach(async function () {
|
118
102
|
await sthis.start();
|
119
|
-
db =
|
103
|
+
db = new Database("test-db-name");
|
120
104
|
/** @type {Doc} */
|
121
105
|
const doc = { _id: "hello", value: "world" };
|
122
106
|
const ok = await db.put(doc);
|
@@ -152,7 +136,7 @@ describe("named Database with record", function () {
|
|
152
136
|
it("should have a key", async function () {
|
153
137
|
const { rows } = await db.changes([]);
|
154
138
|
expect(rows.length).toBe(1);
|
155
|
-
const blocks = db.
|
139
|
+
const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
|
156
140
|
const loader = blocks.loader;
|
157
141
|
expect(loader).toBeTruthy();
|
158
142
|
await loader.ready();
|
@@ -243,7 +227,7 @@ describe("basic Database parallel writes / public", function () {
|
|
243
227
|
});
|
244
228
|
beforeEach(async function () {
|
245
229
|
await sthis.start();
|
246
|
-
db =
|
230
|
+
db = new Database("test-parallel-writes", { public: true });
|
247
231
|
for (let i = 0; i < 10; i++) {
|
248
232
|
const doc = { _id: `id-${i}`, hello: "world" };
|
249
233
|
writes.push(db.put(doc));
|
@@ -251,7 +235,7 @@ describe("basic Database parallel writes / public", function () {
|
|
251
235
|
await Promise.all(writes);
|
252
236
|
});
|
253
237
|
it("should have one head", function () {
|
254
|
-
const crdt = db.
|
238
|
+
const crdt = db._crdt;
|
255
239
|
expect(crdt.clock.head.length).toBe(1);
|
256
240
|
});
|
257
241
|
it("should write all", async function () {
|
@@ -288,7 +272,7 @@ describe("basic Database parallel writes / public", function () {
|
|
288
272
|
});
|
289
273
|
it("has changes", async function () {
|
290
274
|
const { rows, clock } = await db.changes([]);
|
291
|
-
expect(clock[0]).toBe(db.
|
275
|
+
expect(clock[0]).toBe(db._crdt.clock.head[0]);
|
292
276
|
expect(rows.length).toBe(10);
|
293
277
|
// rows.sort((a, b) => a.key.localeCompare(b.key));
|
294
278
|
for (let i = 0; i < 10; i++) {
|
@@ -299,9 +283,9 @@ describe("basic Database parallel writes / public", function () {
|
|
299
283
|
it("should not have a key", async function () {
|
300
284
|
const { rows } = await db.changes([]);
|
301
285
|
expect(rows.length).toBe(10);
|
302
|
-
|
303
|
-
|
304
|
-
const blocks = db.
|
286
|
+
expect(db.opts.public).toBeTruthy();
|
287
|
+
expect(db._crdt.opts.public).toBeTruthy();
|
288
|
+
const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
|
305
289
|
const loader = blocks.loader;
|
306
290
|
expect(loader).toBeTruthy();
|
307
291
|
await loader.ready();
|
@@ -323,7 +307,7 @@ describe("basic Database with subscription", function () {
|
|
323
307
|
});
|
324
308
|
beforeEach(async function () {
|
325
309
|
await sthis.start();
|
326
|
-
db =
|
310
|
+
db = new Database();
|
327
311
|
didRun = 0;
|
328
312
|
waitForSub = new Promise((resolve) => {
|
329
313
|
unsubscribe = db.subscribe((docs) => {
|
@@ -367,8 +351,9 @@ describe("basic Database with no update subscription", function () {
|
|
367
351
|
});
|
368
352
|
beforeEach(async function () {
|
369
353
|
await sthis.start();
|
370
|
-
db =
|
354
|
+
db = new Database();
|
371
355
|
didRun = 0;
|
356
|
+
|
372
357
|
unsubscribe = db.subscribe(() => {
|
373
358
|
didRun++;
|
374
359
|
});
|
@@ -405,7 +390,7 @@ describe("database with files input", () => {
|
|
405
390
|
beforeEach(async function () {
|
406
391
|
await sthis.start();
|
407
392
|
imagefiles = await buildBlobFiles();
|
408
|
-
db =
|
393
|
+
db = new Database("fireproof-with-images");
|
409
394
|
const doc = {
|
410
395
|
_id: "images-main",
|
411
396
|
type: "files",
|
@@ -487,150 +472,3 @@ describe("database with files input", () => {
|
|
487
472
|
expect(file.size).toBe(imagefiles[0].file.size);
|
488
473
|
});
|
489
474
|
});
|
490
|
-
|
491
|
-
describe("StoreURIRuntime", () => {
|
492
|
-
const sthis = mockSuperThis();
|
493
|
-
let safeEnv: string | undefined;
|
494
|
-
let unreg: () => void;
|
495
|
-
beforeEach(async () => {
|
496
|
-
await sthis.start();
|
497
|
-
safeEnv = sthis.env.get("FP_STORAGE_URL");
|
498
|
-
sthis.env.set("FP_STORAGE_URL", "my://bla/storage");
|
499
|
-
unreg = bs.registerStoreProtocol({
|
500
|
-
protocol: "murks",
|
501
|
-
isDefault: true,
|
502
|
-
defaultURI: function (): URI {
|
503
|
-
return URI.from("murks://fp");
|
504
|
-
},
|
505
|
-
gateway: function (): Promise<bs.Gateway> {
|
506
|
-
throw new Error("Function not implemented.");
|
507
|
-
},
|
508
|
-
test: function (): Promise<bs.TestGateway> {
|
509
|
-
throw new Error("Function not implemented.");
|
510
|
-
},
|
511
|
-
});
|
512
|
-
});
|
513
|
-
afterEach(() => {
|
514
|
-
sthis.env.set("FP_STORAGE_URL", safeEnv);
|
515
|
-
unreg();
|
516
|
-
});
|
517
|
-
it("default toStoreURIRuntime", () => {
|
518
|
-
expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "test")))).toEqual({
|
519
|
-
data: {
|
520
|
-
data: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&suffix=.car&urlGen=fromEnv",
|
521
|
-
file: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&urlGen=fromEnv",
|
522
|
-
meta: "my://bla/storage?name=test&store=meta&storekey=%40test-meta%40&urlGen=fromEnv",
|
523
|
-
wal: "my://bla/storage?name=test&store=wal&storekey=%40test-wal%40&urlGen=fromEnv",
|
524
|
-
},
|
525
|
-
idx: {
|
526
|
-
data: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&suffix=.car&urlGen=fromEnv",
|
527
|
-
file: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&urlGen=fromEnv",
|
528
|
-
meta: "my://bla/storage?index=idx&name=test&store=meta&storekey=%40test-meta-idx%40&urlGen=fromEnv",
|
529
|
-
wal: "my://bla/storage?index=idx&name=test&store=wal&storekey=%40test-wal-idx%40&urlGen=fromEnv",
|
530
|
-
},
|
531
|
-
});
|
532
|
-
// keyConfigOpts(sthis: SuperThis, name: string, opts?: ConfigOpts): string {
|
533
|
-
});
|
534
|
-
it("no name toStoreURIRuntime", () => {
|
535
|
-
expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis)))).toEqual({
|
536
|
-
data: {
|
537
|
-
data: "my://bla/storage?name=storage&store=data&storekey=%40storage-data%40&suffix=.car&urlGen=fromEnv",
|
538
|
-
file: "my://bla/storage?name=storage&store=data&storekey=%40storage-data%40&urlGen=fromEnv",
|
539
|
-
meta: "my://bla/storage?name=storage&store=meta&storekey=%40storage-meta%40&urlGen=fromEnv",
|
540
|
-
wal: "my://bla/storage?name=storage&store=wal&storekey=%40storage-wal%40&urlGen=fromEnv",
|
541
|
-
},
|
542
|
-
idx: {
|
543
|
-
data: "my://bla/storage?index=idx&name=storage&store=data&storekey=%40storage-data-idx%40&suffix=.car&urlGen=fromEnv",
|
544
|
-
file: "my://bla/storage?index=idx&name=storage&store=data&storekey=%40storage-data-idx%40&urlGen=fromEnv",
|
545
|
-
meta: "my://bla/storage?index=idx&name=storage&store=meta&storekey=%40storage-meta-idx%40&urlGen=fromEnv",
|
546
|
-
wal: "my://bla/storage?index=idx&name=storage&store=wal&storekey=%40storage-wal-idx%40&urlGen=fromEnv",
|
547
|
-
},
|
548
|
-
});
|
549
|
-
});
|
550
|
-
|
551
|
-
it("set toStoreURIRuntime", () => {
|
552
|
-
expect(
|
553
|
-
JSON.parse(
|
554
|
-
JSON.stringify(
|
555
|
-
toStoreURIRuntime(sthis, "xxx", {
|
556
|
-
base: "my://storage-base",
|
557
|
-
data: {
|
558
|
-
data: "my://storage-data?name=yyy",
|
559
|
-
meta: "my://storage-meta",
|
560
|
-
},
|
561
|
-
idx: {
|
562
|
-
data: "my://storage-idx-data?name=yyy&index=bla",
|
563
|
-
meta: "my://storage-idx-meta",
|
564
|
-
},
|
565
|
-
}),
|
566
|
-
),
|
567
|
-
),
|
568
|
-
).toEqual({
|
569
|
-
data: {
|
570
|
-
data: "my://storage-data?name=yyy&store=data&storekey=%40yyy-data%40&suffix=.car",
|
571
|
-
file: "my://storage-data?name=yyy&store=data&storekey=%40yyy-data%40",
|
572
|
-
meta: "my://storage-meta?name=storage-meta&store=meta&storekey=%40storage-meta-meta%40",
|
573
|
-
wal: "my://storage-base?name=xxx&store=wal&storekey=%40xxx-wal%40",
|
574
|
-
},
|
575
|
-
idx: {
|
576
|
-
data: "my://storage-idx-data?index=bla&name=yyy&store=data&storekey=%40yyy-data-idx%40&suffix=.car",
|
577
|
-
file: "my://storage-idx-data?index=bla&name=yyy&store=data&storekey=%40yyy-data-idx%40",
|
578
|
-
meta: "my://storage-idx-meta?index=idx&name=storage-idx-meta&store=meta&storekey=%40storage-idx-meta-meta-idx%40",
|
579
|
-
wal: "my://storage-base?index=idx&name=xxx&store=wal&storekey=%40xxx-wal-idx%40",
|
580
|
-
},
|
581
|
-
});
|
582
|
-
});
|
583
|
-
|
584
|
-
it("default-reg toStoreURIRuntime", () => {
|
585
|
-
sthis.env.delete("FP_STORAGE_URL");
|
586
|
-
expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "maxi")))).toEqual({
|
587
|
-
data: {
|
588
|
-
data: "murks://fp?name=maxi&store=data&storekey=%40maxi-data%40&suffix=.car&urlGen=default",
|
589
|
-
file: "murks://fp?name=maxi&store=data&storekey=%40maxi-data%40&urlGen=default",
|
590
|
-
meta: "murks://fp?name=maxi&store=meta&storekey=%40maxi-meta%40&urlGen=default",
|
591
|
-
wal: "murks://fp?name=maxi&store=wal&storekey=%40maxi-wal%40&urlGen=default",
|
592
|
-
},
|
593
|
-
idx: {
|
594
|
-
data: "murks://fp?index=idx&name=maxi&store=data&storekey=%40maxi-data-idx%40&suffix=.car&urlGen=default",
|
595
|
-
file: "murks://fp?index=idx&name=maxi&store=data&storekey=%40maxi-data-idx%40&urlGen=default",
|
596
|
-
meta: "murks://fp?index=idx&name=maxi&store=meta&storekey=%40maxi-meta-idx%40&urlGen=default",
|
597
|
-
wal: "murks://fp?index=idx&name=maxi&store=wal&storekey=%40maxi-wal-idx%40&urlGen=default",
|
598
|
-
},
|
599
|
-
});
|
600
|
-
});
|
601
|
-
|
602
|
-
it("keyConfigOpts", () => {
|
603
|
-
expect(JSON.parse(keyConfigOpts(sthis, "test"))).toEqual([
|
604
|
-
{
|
605
|
-
name: "test",
|
606
|
-
},
|
607
|
-
{
|
608
|
-
stores: [
|
609
|
-
{
|
610
|
-
data: {
|
611
|
-
data: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&suffix=.car&urlGen=fromEnv",
|
612
|
-
file: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&urlGen=fromEnv",
|
613
|
-
meta: "my://bla/storage?name=test&store=meta&storekey=%40test-meta%40&urlGen=fromEnv",
|
614
|
-
wal: "my://bla/storage?name=test&store=wal&storekey=%40test-wal%40&urlGen=fromEnv",
|
615
|
-
},
|
616
|
-
},
|
617
|
-
{
|
618
|
-
idx: {
|
619
|
-
data: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&suffix=.car&urlGen=fromEnv",
|
620
|
-
file: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&urlGen=fromEnv",
|
621
|
-
meta: "my://bla/storage?index=idx&name=test&store=meta&storekey=%40test-meta-idx%40&urlGen=fromEnv",
|
622
|
-
wal: "my://bla/storage?index=idx&name=test&store=wal&storekey=%40test-wal-idx%40&urlGen=fromEnv",
|
623
|
-
},
|
624
|
-
},
|
625
|
-
],
|
626
|
-
},
|
627
|
-
]);
|
628
|
-
});
|
629
|
-
|
630
|
-
it("check file protocol defaultURI", () => {
|
631
|
-
const gw = fileGatewayFactoryItem();
|
632
|
-
expect(gw.defaultURI(sthis).toString()).toBe(
|
633
|
-
`file://${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`,
|
634
|
-
);
|
635
|
-
});
|
636
|
-
});
|