@fireproof/core 0.19.121 → 0.20.0-dev-preview-06

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/README.md +3 -2
  2. package/deno/index.d.ts +7 -0
  3. package/deno/index.js +66 -0
  4. package/deno/index.js.map +1 -0
  5. package/deno/metafile-esm.json +1 -0
  6. package/deno.json +2 -3
  7. package/index.cjs +1819 -1051
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +746 -333
  10. package/index.d.ts +746 -333
  11. package/index.js +1792 -1026
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/index.cjs +16 -293
  16. package/node/index.cjs.map +1 -1
  17. package/node/index.d.cts +4 -40
  18. package/node/index.d.ts +4 -40
  19. package/node/index.js +22 -237
  20. package/node/index.js.map +1 -1
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +12 -4
  24. package/react/index.cjs.map +1 -1
  25. package/react/index.js.map +1 -1
  26. package/react/metafile-cjs.json +1 -1
  27. package/react/metafile-esm.json +1 -1
  28. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  29. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  30. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  31. package/tests/blockstore/keyed-crypto.test.ts +73 -118
  32. package/tests/blockstore/loader.test.ts +18 -9
  33. package/tests/blockstore/store.test.ts +40 -31
  34. package/tests/blockstore/transaction.test.ts +14 -13
  35. package/tests/fireproof/all-gateway.test.ts +283 -213
  36. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  37. package/tests/fireproof/crdt.test.ts +78 -19
  38. package/tests/fireproof/database.test.ts +225 -29
  39. package/tests/fireproof/fireproof.test.ts +92 -73
  40. package/tests/fireproof/hello.test.ts +17 -13
  41. package/tests/fireproof/indexer.test.ts +67 -43
  42. package/tests/fireproof/utils.test.ts +47 -6
  43. package/tests/gateway/file/loader-config.test.ts +307 -0
  44. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  45. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  46. package/tests/helpers.ts +44 -17
  47. package/tests/react/useFireproof.test.tsx +1 -1
  48. package/tests/www/todo.html +24 -3
  49. package/web/index.cjs +102 -116
  50. package/web/index.cjs.map +1 -1
  51. package/web/index.d.cts +15 -29
  52. package/web/index.d.ts +15 -29
  53. package/web/index.js +91 -105
  54. package/web/index.js.map +1 -1
  55. package/web/metafile-cjs.json +1 -1
  56. package/web/metafile-esm.json +1 -1
  57. package/node/chunk-4A4RAVNS.js +0 -17
  58. package/node/chunk-4A4RAVNS.js.map +0 -1
  59. package/node/mem-filesystem-LPPT7QV5.js +0 -40
  60. package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
  61. package/tests/fireproof/config.test.ts +0 -163
  62. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
  63. /package/tests/fireproof/{multiple-ledger.test.ts → multiple-database.test.ts} +0 -0
@@ -1,4 +1,17 @@
1
- import { Index, index, Database, CRDT, IndexRows, ensureSuperThis } from "@fireproof/core";
1
+ import {
2
+ Index,
3
+ index,
4
+ Database,
5
+ CRDT,
6
+ IndexRows,
7
+ toStoreURIRuntime,
8
+ bs,
9
+ rt,
10
+ DatabaseFactory,
11
+ defaultWriteQueueOpts,
12
+ ensureSuperThis,
13
+ DatabaseOpts,
14
+ } from "@fireproof/core";
2
15
 
3
16
  interface TestType {
4
17
  readonly title: string;
@@ -13,24 +26,24 @@ describe("basic Index", () => {
13
26
  afterEach(async function () {
14
27
  await db.close();
15
28
  await db.destroy();
16
- await indexer.close();
17
- await indexer.destroy();
29
+ // await indexer.close();
30
+ // await indexer.destroy();
18
31
  });
19
32
  beforeEach(async function () {
20
33
  await sthis.start();
21
- db = new Database("test-indexer");
34
+ db = DatabaseFactory("test-indexer");
22
35
  await db.put({ title: "amazing" });
23
36
  await db.put({ title: "creative" });
24
37
  await db.put({ title: "bazillas" });
25
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
38
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
26
39
  didMap = true;
27
40
  return doc.title;
28
41
  });
29
42
  await indexer.ready();
30
43
  });
31
44
  it("should have properties", function () {
32
- expect(indexer.crdt).toBe(db._crdt);
33
- expect(indexer.crdt.name).toBe("test-indexer");
45
+ expect(indexer.crdt).toBe(db.crdt);
46
+ // expect(indexer.crdt.name).toBe("test-indexer");
34
47
  expect(indexer.name).toBe("hello");
35
48
  expect(indexer.mapFn).toBeTruthy();
36
49
  });
@@ -100,17 +113,17 @@ describe("Index query with compound key", function () {
100
113
  afterEach(async function () {
101
114
  await db.close();
102
115
  await db.destroy();
103
- await indexer.close();
104
- await indexer.destroy();
116
+ // await indexer.close();
117
+ // await indexer.destroy();
105
118
  });
106
119
  beforeEach(async function () {
107
120
  await sthis.start();
108
- db = new Database("test-indexer");
121
+ db = DatabaseFactory("test-indexer");
109
122
  await db.put({ title: "amazing", score: 1 });
110
123
  await db.put({ title: "creative", score: 2 });
111
124
  await db.put({ title: "creative", score: 20 });
112
125
  await db.put({ title: "bazillas", score: 3 });
113
- indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc) => {
126
+ indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc) => {
114
127
  return [doc.title, doc.score];
115
128
  });
116
129
  await indexer.ready();
@@ -130,16 +143,16 @@ describe("basic Index with map fun", function () {
130
143
  afterEach(async function () {
131
144
  await db.close();
132
145
  await db.destroy();
133
- await indexer.close();
134
- await indexer.destroy();
146
+ // await indexer.close();
147
+ // await indexer.destroy();
135
148
  });
136
149
  beforeEach(async function () {
137
150
  await sthis.start();
138
- db = new Database("test-indexer");
151
+ db = DatabaseFactory("test-indexer");
139
152
  await db.put({ title: "amazing" });
140
153
  await db.put({ title: "creative" });
141
154
  await db.put({ title: "bazillas" });
142
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc, map) => {
155
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc, map) => {
143
156
  map(doc.title);
144
157
  });
145
158
  await indexer.ready();
@@ -163,11 +176,11 @@ describe("basic Index with map fun with value", function () {
163
176
  });
164
177
  beforeEach(async function () {
165
178
  await sthis.start();
166
- db = new Database("test-indexer");
179
+ db = DatabaseFactory("test-indexer");
167
180
  await db.put({ title: "amazing" });
168
181
  await db.put({ title: "creative" });
169
182
  await db.put({ title: "bazillas" });
170
- indexer = new Index<string, TestType, number>(sthis, db._crdt, "hello", (doc, map) => {
183
+ indexer = new Index<string, TestType, number>(sthis, db.crdt, "hello", (doc, map) => {
171
184
  map(doc.title, doc.title.length);
172
185
  });
173
186
  });
@@ -198,17 +211,17 @@ describe("Index query with map and compound key", function () {
198
211
  afterEach(async function () {
199
212
  await db.close();
200
213
  await db.destroy();
201
- await indexer.close();
202
- await indexer.destroy();
214
+ // await indexer.close();
215
+ // await indexer.destroy();
203
216
  });
204
217
  beforeEach(async function () {
205
218
  await sthis.start();
206
- db = new Database("test-indexer");
219
+ db = DatabaseFactory("test-indexer");
207
220
  await db.put({ title: "amazing", score: 1 });
208
221
  await db.put({ title: "creative", score: 2 });
209
222
  await db.put({ title: "creative", score: 20 });
210
223
  await db.put({ title: "bazillas", score: 3 });
211
- indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc, emit) => {
224
+ indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc, emit) => {
212
225
  emit([doc.title, doc.score]);
213
226
  });
214
227
  await indexer.ready();
@@ -228,16 +241,16 @@ describe("basic Index with string fun", function () {
228
241
  afterEach(async function () {
229
242
  await db.close();
230
243
  await db.destroy();
231
- await indexer.close();
232
- await indexer.destroy();
244
+ // await indexer.close();
245
+ // await indexer.destroy();
233
246
  });
234
247
  beforeEach(async function () {
235
248
  await sthis.start();
236
- db = new Database("test-indexer");
249
+ db = DatabaseFactory("test-indexer");
237
250
  await db.put({ title: "amazing" });
238
251
  await db.put({ title: "creative" });
239
252
  await db.put({ title: "bazillas" });
240
- indexer = new Index(sthis, db._crdt, "title");
253
+ indexer = new Index(sthis, db.crdt, "title");
241
254
  await indexer.ready();
242
255
  });
243
256
  it("should get results", async function () {
@@ -264,31 +277,44 @@ describe("basic Index upon cold start", function () {
264
277
  let mapFn: (doc: TestType) => string;
265
278
  let result: IndexRows<string, TestType>;
266
279
  const sthis = ensureSuperThis();
280
+ let dbOpts: DatabaseOpts;
267
281
  // result, mapFn;
268
282
  afterEach(async function () {
269
283
  await crdt.close();
270
284
  await crdt.destroy();
271
- await indexer.close();
272
- await indexer.destroy();
285
+ // await indexer.close();
286
+ // await indexer.destroy();
273
287
  });
274
288
  beforeEach(async function () {
275
289
  await sthis.start();
276
- // db = database()
277
- crdt = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
290
+ const logger = sthis.logger.With().Module("IndexerTest").Logger();
291
+ logger.Debug().Msg("enter beforeEach");
292
+ dbOpts = {
293
+ writeQueue: defaultWriteQueueOpts({}),
294
+ keyBag: rt.kb.defaultKeyBagOpts(sthis),
295
+ storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"),
296
+ storeEnDe: bs.ensureStoreEnDeFile({}),
297
+ };
298
+ crdt = new CRDT<TestType>(sthis, dbOpts);
278
299
  await crdt.bulk([
279
300
  { id: "abc1", value: { title: "amazing" } },
280
301
  { id: "abc2", value: { title: "creative" } },
281
302
  { id: "abc3", value: { title: "bazillas" } },
282
303
  ]);
304
+ logger.Debug().Msg("post bulk beforeEach");
283
305
  didMap = 0;
284
306
  mapFn = (doc) => {
285
307
  didMap++;
286
308
  return doc.title;
287
309
  };
288
- indexer = await index<string, TestType>(sthis, { _crdt: crdt }, "hello", mapFn);
310
+ indexer = await index<string, TestType>({ crdt: crdt }, "hello", mapFn);
311
+ logger.Debug().Msg("post index beforeEach");
289
312
  await indexer.ready();
313
+ logger.Debug().Msg("post indexer.ready beforeEach");
290
314
  // new Index(db._crdt.indexBlockstore, db._crdt, 'hello', mapFn)
291
315
  result = await indexer.query();
316
+
317
+ logger.Debug().Msg("post indexer.query beforeEach");
292
318
  expect(indexer.indexHead).toEqual(crdt.clock.head);
293
319
  });
294
320
  it("should call map on first query", function () {
@@ -301,12 +327,12 @@ describe("basic Index upon cold start", function () {
301
327
  expect(result.rows.length).toEqual(3);
302
328
  });
303
329
  it("should work on cold load", async function () {
304
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
330
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
305
331
  await crdt2.ready();
306
332
  const { result, head } = await crdt2.changes();
307
333
  expect(result).toBeTruthy();
308
334
  await crdt2.ready();
309
- const indexer2 = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", mapFn);
335
+ const indexer2 = await index<string, TestType>({ crdt: crdt2 }, "hello", mapFn);
310
336
  await indexer2.ready();
311
337
  const result2 = await indexer2.query();
312
338
  expect(indexer2.indexHead).toEqual(head);
@@ -316,8 +342,8 @@ describe("basic Index upon cold start", function () {
316
342
  });
317
343
  it.skip("should not rerun the map function on seen changes", async function () {
318
344
  didMap = 0;
319
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
320
- const indexer2 = await index(sthis, { _crdt: crdt2 }, "hello", mapFn);
345
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
346
+ const indexer2 = await index({ crdt: crdt2 }, "hello", mapFn);
321
347
  const { result, head } = await crdt2.changes([]);
322
348
  expect(result.length).toEqual(3);
323
349
  expect(head.length).toEqual(1);
@@ -341,10 +367,8 @@ describe("basic Index upon cold start", function () {
341
367
  expect(didMap).toEqual(1);
342
368
  });
343
369
  it("should ignore meta when map function definiton changes", async function () {
344
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold");
345
- const result = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", (doc) =>
346
- doc.title.split("").reverse().join(""),
347
- ).query();
370
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
371
+ const result = await index<string, TestType>({ crdt: crdt2 }, "hello", (doc) => doc.title.split("").reverse().join("")).query();
348
372
  expect(result.rows.length).toEqual(3);
349
373
  expect(result.rows[0].key).toEqual("evitaerc"); // creative
350
374
  });
@@ -358,20 +382,20 @@ describe("basic Index with no data", function () {
358
382
  afterEach(async function () {
359
383
  await db.close();
360
384
  await db.destroy();
361
- await indexer.close();
362
- await indexer.destroy();
385
+ // await indexer.close();
386
+ // await indexer.destroy();
363
387
  });
364
388
  beforeEach(async function () {
365
389
  await sthis.start();
366
- db = new Database("test-indexer");
367
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
390
+ db = DatabaseFactory("test-indexer");
391
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
368
392
  didMap = true;
369
393
  return doc.title;
370
394
  });
371
395
  await indexer.ready();
372
396
  });
373
397
  it("should have properties", function () {
374
- expect(indexer.crdt).toEqual(db._crdt);
398
+ expect(indexer.crdt).toEqual(db.crdt);
375
399
  expect(indexer.name).toEqual("hello");
376
400
  expect(indexer.mapFn).toBeTruthy();
377
401
  });
@@ -1,7 +1,5 @@
1
- import { URI } from "@adviser/cement";
2
- import { rt, getStore, ensureSuperLog, ensureSuperThis } from "@fireproof/core";
3
-
4
- // only for test
1
+ import { runtimeFn, URI } from "@adviser/cement";
2
+ import { rt, getStore, inplaceFilter, ensureSuperThis, ensureSuperLog } from "@fireproof/core";
5
3
  import { UUID } from "uuidv7";
6
4
 
7
5
  describe("utils", () => {
@@ -33,14 +31,16 @@ describe("utils", () => {
33
31
  ];
34
32
  it("getfilename plain", () => {
35
33
  for (const store of storeOpts) {
36
- const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
34
+ const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version&suffix=${store.suffix}`);
37
35
  expect(rt.getFileName(url, logger)).toEqual(`${store.type}/key${store.suffix}`);
38
36
  }
39
37
  });
40
38
 
41
39
  it("getfilename index", () => {
42
40
  for (const store of storeOpts) {
43
- const url = URI.from(`file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version`);
41
+ const url = URI.from(
42
+ `file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version&suffix=${store.suffix}`,
43
+ );
44
44
  expect(rt.getFileName(url, logger)).toEqual(`idx-${store.type}/key${store.suffix}`);
45
45
  }
46
46
  });
@@ -80,4 +80,45 @@ describe("utils", () => {
80
80
  const id = sthis.timeOrderedNextId(0xcafebabebeef).str;
81
81
  expect(id.slice(0, 15)).toBe("cafebabe-beef-7");
82
82
  });
83
+
84
+ it("inplaceFilter empty", () => {
85
+ const s: string[] = [];
86
+ expect(inplaceFilter(s, () => false)).toEqual([]);
87
+ expect(inplaceFilter(s, () => true)).toEqual([]);
88
+ });
89
+
90
+ it("inplaceFilter sized filtered", () => {
91
+ const s = new Array(100).fill("a").map((a, i) => `${a}${i.toString()}`);
92
+ expect(inplaceFilter(s, () => false)).toEqual([]);
93
+ });
94
+ it("inplaceFilter sized unfiltered", () => {
95
+ const s = new Array(100).fill("a").map((a, i) => `${a}${i.toString()}`);
96
+ const ref = [...s];
97
+ expect(inplaceFilter(s, () => true)).toEqual(ref);
98
+ });
99
+
100
+ it("inplaceFilter sized mod 7", () => {
101
+ const s = new Array(100).fill("a").map((a, i) => `${a}${i.toString()}`);
102
+ const ref = [...s];
103
+ for (let i = 99; i >= 0; i--) {
104
+ if (!(i % 7)) {
105
+ ref.splice(i, 1);
106
+ }
107
+ }
108
+ expect(inplaceFilter(s, (_, j) => !!(j % 7))).toEqual(ref);
109
+ expect(s.length).toBe(85);
110
+ });
111
+ });
112
+
113
+ describe("runtime", () => {
114
+ it("runtime", () => {
115
+ const isNode = !!(typeof process === "object" && process.versions?.node);
116
+ expect(runtimeFn()).toEqual({
117
+ isBrowser: !isNode,
118
+ isCFWorker: false,
119
+ isDeno: false,
120
+ isNodeIsh: isNode,
121
+ isReactNative: false,
122
+ });
123
+ });
83
124
  });
@@ -0,0 +1,307 @@
1
+ import { BuildURI, CoerceURI, URI } from "@adviser/cement";
2
+ import { fireproof, PARAM, rt, SuperThis } from "@fireproof/core";
3
+ import { mockSuperThis } from "../../helpers.js";
4
+
5
+ function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI {
6
+ if (!base) {
7
+ const home = sthis.env.get("HOME") || "./";
8
+ base =
9
+ sthis.env.get("FP_STORAGE_URL") ||
10
+ `file://${sthis.pathOps.join(home, ".fireproof", rt.FILESTORE_VERSION.replace(/-.*$/, ""))}?${PARAM.URL_GEN}=default`;
11
+ }
12
+ return URI.from(base.toString())
13
+ .build()
14
+ .setParam(PARAM.NAME, name || "")
15
+ .URI();
16
+ }
17
+
18
+ const _my_app = "my-app";
19
+ function my_app() {
20
+ return _my_app;
21
+ }
22
+
23
+ describe("config file gateway", () => {
24
+ const sthis = mockSuperThis();
25
+ // const isMemFS: { fs?: string } = {};
26
+
27
+ beforeAll(async () => {
28
+ await sthis.start();
29
+ // const url = URI.from(sthis.env.get("FP_STORAGE_URL"));
30
+ // if (url.getParam("fs") === "mem") {
31
+ // isMemFS.fs = "mem";
32
+ // }
33
+ });
34
+
35
+ it("loader", async () => {
36
+ const db = fireproof(my_app());
37
+ await db.put({ name: "my-app" });
38
+ expect(db.name).toBe(my_app());
39
+
40
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
41
+ expect(fileStore?.url().asObj()).toEqual({
42
+ pathname: "./dist/fp-dir-file",
43
+ protocol: "file:",
44
+ searchParams: {
45
+ // ...isMemFS,
46
+ name: "my-app",
47
+ store: "data",
48
+ storekey: "@my-app-data@",
49
+ urlGen: "fromEnv",
50
+ version: "v0.19-file",
51
+ },
52
+ style: "path",
53
+ });
54
+
55
+ const dataStore = await db.crdt.blockstore.loader?.carStore();
56
+ expect(dataStore?.url().asObj()).toEqual({
57
+ pathname: "./dist/fp-dir-file",
58
+ protocol: "file:",
59
+ searchParams: {
60
+ // ...isMemFS,
61
+ name: "my-app",
62
+ store: "data",
63
+ suffix: ".car",
64
+ storekey: "@my-app-data@",
65
+ urlGen: "fromEnv",
66
+ version: "v0.19-file",
67
+ },
68
+ style: "path",
69
+ });
70
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
71
+ expect(metaStore?.url().asObj()).toEqual({
72
+ pathname: "./dist/fp-dir-file",
73
+ protocol: "file:",
74
+ searchParams: {
75
+ // ...isMemFS,
76
+ name: "my-app",
77
+ store: "meta",
78
+ storekey: "@my-app-meta@",
79
+ urlGen: "fromEnv",
80
+ version: "v0.19-file",
81
+ },
82
+ style: "path",
83
+ });
84
+ const WALStore = await db.crdt.blockstore.loader?.WALStore();
85
+ expect(WALStore?.url().asObj()).toEqual({
86
+ pathname: "./dist/fp-dir-file",
87
+ protocol: "file:",
88
+ searchParams: {
89
+ // ...isMemFS,
90
+ name: "my-app",
91
+ store: "wal",
92
+ storekey: "@my-app-wal@",
93
+ urlGen: "fromEnv",
94
+ version: "v0.19-file",
95
+ },
96
+ style: "path",
97
+ });
98
+ await db.close();
99
+ });
100
+
101
+ it("file path", async () => {
102
+ let baseDir = "./dist/data".replace(/\?.*$/, "").replace(/^file:\/\//, "");
103
+ baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
104
+ const base = BuildURI.from("./dist/data");
105
+ // if (isMemFS.fs) {
106
+ // base.setParam("fs", isMemFS.fs);
107
+ // }
108
+ const sysfs = await rt.gw.file.sysFileSystemFactory(base.URI());
109
+ await sysfs.rm(baseDir, { recursive: true }).catch(() => {
110
+ /* */
111
+ });
112
+
113
+ const db = fireproof(my_app(), { storeUrls: { base } });
114
+ // console.log(`>>>>>>>>>>>>>>>file-path`)
115
+ await db.put({ name: "my-app" });
116
+ expect(db.name).toBe(my_app());
117
+ const carStore = await db.crdt.blockstore.loader?.carStore();
118
+ expect(carStore?.url().asObj()).toEqual({
119
+ pathname: "./dist/data",
120
+ protocol: "file:",
121
+ searchParams: {
122
+ // ...isMemFS,
123
+ name: "my-app",
124
+ store: "data",
125
+ storekey: "@my-app-data@",
126
+ suffix: ".car",
127
+ version: "v0.19-file",
128
+ },
129
+ style: "path",
130
+ });
131
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
132
+ expect(fileStore?.url().asObj()).toEqual({
133
+ pathname: "./dist/data",
134
+ protocol: "file:",
135
+ searchParams: {
136
+ // ...isMemFS,
137
+ name: "my-app",
138
+ store: "data",
139
+ storekey: "@my-app-data@",
140
+ version: "v0.19-file",
141
+ },
142
+ style: "path",
143
+ });
144
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
145
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
146
+ expect(metaStore?.url().asObj()).toEqual({
147
+ pathname: "./dist/data",
148
+ protocol: "file:",
149
+ searchParams: {
150
+ // ...isMemFS,
151
+ name: "my-app",
152
+ store: "meta",
153
+ storekey: "@my-app-meta@",
154
+ version: "v0.19-file",
155
+ },
156
+ style: "path",
157
+ });
158
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
159
+ await db.close();
160
+ });
161
+
162
+ it("homedir default", async () => {
163
+ const old = sthis.env.get("FP_STORAGE_URL");
164
+ sthis.env.delete("FP_STORAGE_URL");
165
+ // this switches file: protocol not memory:
166
+ let baseDir = dataDir(sthis, my_app()).pathname;
167
+ baseDir = sthis.pathOps.join(baseDir, my_app());
168
+
169
+ const base = BuildURI.from(baseDir);
170
+ // if (isMemFS.fs) {
171
+ // base.setParam("fs", isMemFS.fs);
172
+ // }
173
+ const sysfs = await rt.gw.file.sysFileSystemFactory(base.URI());
174
+ await sysfs.rm(baseDir, { recursive: true }).catch(() => {
175
+ /* */
176
+ });
177
+
178
+ expect(baseDir).toMatch(new RegExp(`/\\.fireproof/${rt.FILESTORE_VERSION.replace(/-file/, "")}/${my_app()}`));
179
+
180
+ const db = fireproof(my_app());
181
+ await db.put({ name: "my-app" });
182
+ expect(db.name).toBe(my_app());
183
+ const carStore = await db.crdt.blockstore.loader?.carStore();
184
+
185
+ expect(carStore?.url().asObj()).toEqual({
186
+ pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
187
+ protocol: "file:",
188
+ style: "path",
189
+ searchParams: {
190
+ // ...isMemFS,
191
+ suffix: ".car",
192
+ runtime: "node",
193
+ urlGen: "default",
194
+ store: "data",
195
+ name: my_app(),
196
+ storekey: `@${my_app()}-data@`,
197
+ version: rt.FILESTORE_VERSION,
198
+ },
199
+ });
200
+
201
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
202
+
203
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
204
+ expect(fileStore?.url().asObj()).toEqual({
205
+ pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
206
+ protocol: "file:",
207
+ style: "path",
208
+ searchParams: {
209
+ // ...isMemFS,
210
+ runtime: "node",
211
+ urlGen: "default",
212
+ store: "data",
213
+ name: my_app(),
214
+ storekey: `@${my_app()}-data@`,
215
+ version: rt.FILESTORE_VERSION,
216
+ },
217
+ });
218
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
219
+ expect(metaStore?.url().asObj()).toEqual({
220
+ pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
221
+ protocol: "file:",
222
+ style: "path",
223
+ searchParams: {
224
+ // ...isMemFS,
225
+ runtime: "node",
226
+ urlGen: "default",
227
+ store: "meta",
228
+ name: my_app(),
229
+ storekey: `@${my_app()}-meta@`,
230
+ version: rt.FILESTORE_VERSION,
231
+ },
232
+ });
233
+
234
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
235
+ sthis.env.set("FP_STORAGE_URL", old);
236
+ await db.close();
237
+ });
238
+
239
+ it("set by env", async () => {
240
+ const old = sthis.env.get("FP_STORAGE_URL");
241
+ // assert(!old, "FP_STORAGE_URL must set")
242
+ const testUrl = BuildURI.from(old);
243
+ // sthis.env.set("FP_STORAGE_URL", testUrl.toString());
244
+
245
+ let baseDir = dataDir(sthis, my_app()).pathname;
246
+ baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
247
+
248
+ const sysfs = await rt.gw.file.sysFileSystemFactory(testUrl.URI());
249
+ await sysfs.rm(baseDir, { recursive: true }).catch(() => {
250
+ /* */
251
+ });
252
+
253
+ const db = fireproof(my_app());
254
+ await db.put({ name: "my-app" });
255
+ expect(db.name).toBe(my_app());
256
+ const carStore = await db.crdt.blockstore.loader.carStore();
257
+ expect(carStore?.url().asObj()).toEqual({
258
+ pathname: "./dist/fp-dir-file",
259
+ protocol: "file:",
260
+ style: "path",
261
+ searchParams: {
262
+ // ...isMemFS,
263
+ urlGen: "fromEnv",
264
+ store: "data",
265
+ // runtime: "node",
266
+ suffix: ".car",
267
+ name: my_app(),
268
+ storekey: `@${my_app()}-data@`,
269
+ version: rt.FILESTORE_VERSION,
270
+ },
271
+ });
272
+
273
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
274
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
275
+ expect(fileStore?.url().asObj()).toEqual({
276
+ pathname: `./dist/fp-dir-file`,
277
+ protocol: "file:",
278
+ style: "path",
279
+ searchParams: {
280
+ // ...isMemFS,
281
+ urlGen: "fromEnv",
282
+ store: "data",
283
+ name: my_app(),
284
+ storekey: `@${my_app()}-data@`,
285
+ version: rt.FILESTORE_VERSION,
286
+ },
287
+ });
288
+
289
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
290
+ expect(metaStore?.url().asObj()).toEqual({
291
+ pathname: `./dist/fp-dir-file`,
292
+ protocol: "file:",
293
+ style: "path",
294
+ searchParams: {
295
+ // ...isMemFS,
296
+ urlGen: "fromEnv",
297
+ store: "meta",
298
+ name: my_app(),
299
+ storekey: `@${my_app()}-meta@`,
300
+ version: rt.FILESTORE_VERSION,
301
+ },
302
+ });
303
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
304
+ await db.close();
305
+ sthis.env.set("FP_STORAGE_URL", old);
306
+ });
307
+ });