@fireproof/core 0.19.99 → 0.19.101

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/{chunk-OFGPKRCM.js → chunk-3EB3ENHT.js} +54 -25
  2. package/chunk-3EB3ENHT.js.map +1 -0
  3. package/chunk-HQ7D3PEU.js +61 -0
  4. package/chunk-HQ7D3PEU.js.map +1 -0
  5. package/chunk-PZ5AY32C.js +10 -0
  6. package/deno-filesystem-Q2IJ7YDR.js +57 -0
  7. package/deno-filesystem-Q2IJ7YDR.js.map +1 -0
  8. package/deno.json +3 -1
  9. package/{gateway-5FCWPX5W.js → gateway-GK5QZ6KP.js} +13 -12
  10. package/gateway-GK5QZ6KP.js.map +1 -0
  11. package/{gateway-H7UD6TNB.js → gateway-TQTGDRCN.js} +9 -8
  12. package/gateway-TQTGDRCN.js.map +1 -0
  13. package/index.cjs +2232 -1781
  14. package/index.cjs.map +1 -1
  15. package/index.d.cts +261 -117
  16. package/index.d.ts +261 -117
  17. package/index.global.js +12776 -11829
  18. package/index.global.js.map +1 -1
  19. package/index.js +1936 -1579
  20. package/index.js.map +1 -1
  21. package/{key-bag-file-WADZBHYG.js → key-bag-file-VOSSK46F.js} +4 -3
  22. package/{key-bag-file-WADZBHYG.js.map → key-bag-file-VOSSK46F.js.map} +1 -1
  23. package/{key-bag-indexdb-PGVAI3FJ.js → key-bag-indexdb-AXTQOSMC.js} +4 -3
  24. package/{key-bag-indexdb-PGVAI3FJ.js.map → key-bag-indexdb-AXTQOSMC.js.map} +1 -1
  25. package/key-bag-memory-LWE6ARPX.js +29 -0
  26. package/key-bag-memory-LWE6ARPX.js.map +1 -0
  27. package/metafile-cjs.json +1 -1
  28. package/metafile-esm.json +1 -1
  29. package/metafile-iife.json +1 -1
  30. package/{node-filesystem-INX4ZTHE.js → node-filesystem-CFRXFSO7.js} +6 -9
  31. package/node-filesystem-CFRXFSO7.js.map +1 -0
  32. package/package.json +4 -2
  33. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +129 -0
  34. package/tests/blockstore/keyed-crypto.test.ts +63 -227
  35. package/tests/blockstore/loader.test.ts +19 -11
  36. package/tests/blockstore/store.test.ts +23 -19
  37. package/tests/blockstore/transaction.test.ts +12 -12
  38. package/tests/fireproof/all-gateway.test.ts +201 -193
  39. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  40. package/tests/fireproof/crdt.test.ts +67 -16
  41. package/tests/fireproof/database.test.ts +183 -21
  42. package/tests/fireproof/fireproof.test.ts +83 -74
  43. package/tests/fireproof/hello.test.ts +18 -14
  44. package/tests/fireproof/indexer.test.ts +53 -43
  45. package/tests/fireproof/utils.test.ts +18 -6
  46. package/tests/gateway/file/loader-config.test.ts +303 -0
  47. package/tests/gateway/indexdb/loader-config.test.ts +75 -0
  48. package/tests/helpers.ts +27 -9
  49. package/tests/react/useFireproof.test.tsx +1 -1
  50. package/{utils-QO2HIWGI.js → utils-STA2C35G.js} +4 -3
  51. package/utils-STA2C35G.js.map +1 -0
  52. package/chunk-OFGPKRCM.js.map +0 -1
  53. package/chunk-WS3YRPIA.js +0 -75
  54. package/chunk-WS3YRPIA.js.map +0 -1
  55. package/gateway-5FCWPX5W.js.map +0 -1
  56. package/gateway-H7UD6TNB.js.map +0 -1
  57. package/mem-filesystem-YPPJV7Q2.js +0 -41
  58. package/mem-filesystem-YPPJV7Q2.js.map +0 -1
  59. package/node-filesystem-INX4ZTHE.js.map +0 -1
  60. package/tests/fireproof/config.test.ts +0 -172
  61. /package/{utils-QO2HIWGI.js.map → chunk-PZ5AY32C.js.map} +0 -0
  62. /package/tests/fireproof/{fireproof.test.fixture.ts → fireproof.fixture.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { Index, index, Database, CRDT, IndexRows } from "@fireproof/core";
1
+ import { Index, index, Database, CRDT, IndexRows, DatabaseOpts, toStoreURIRuntime, bs, rt, DatabaseFactory } from "@fireproof/core";
2
2
  import { mockSuperThis } from "../helpers";
3
3
 
4
4
  interface TestType {
@@ -14,24 +14,24 @@ describe("basic Index", () => {
14
14
  afterEach(async function () {
15
15
  await db.close();
16
16
  await db.destroy();
17
- await indexer.close();
18
- await indexer.destroy();
17
+ // await indexer.close();
18
+ // await indexer.destroy();
19
19
  });
20
20
  beforeEach(async function () {
21
21
  await sthis.start();
22
- db = new Database("test-indexer");
22
+ db = DatabaseFactory("test-indexer");
23
23
  await db.put({ title: "amazing" });
24
24
  await db.put({ title: "creative" });
25
25
  await db.put({ title: "bazillas" });
26
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
26
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
27
27
  didMap = true;
28
28
  return doc.title;
29
29
  });
30
30
  await indexer.ready();
31
31
  });
32
32
  it("should have properties", function () {
33
- expect(indexer.crdt).toBe(db._crdt);
34
- expect(indexer.crdt.name).toBe("test-indexer");
33
+ expect(indexer.crdt).toBe(db.crdt);
34
+ // expect(indexer.crdt.name).toBe("test-indexer");
35
35
  expect(indexer.name).toBe("hello");
36
36
  expect(indexer.mapFn).toBeTruthy();
37
37
  });
@@ -101,17 +101,17 @@ describe("Index query with compound key", function () {
101
101
  afterEach(async function () {
102
102
  await db.close();
103
103
  await db.destroy();
104
- await indexer.close();
105
- await indexer.destroy();
104
+ // await indexer.close();
105
+ // await indexer.destroy();
106
106
  });
107
107
  beforeEach(async function () {
108
108
  await sthis.start();
109
- db = new Database("test-indexer");
109
+ db = DatabaseFactory("test-indexer");
110
110
  await db.put({ title: "amazing", score: 1 });
111
111
  await db.put({ title: "creative", score: 2 });
112
112
  await db.put({ title: "creative", score: 20 });
113
113
  await db.put({ title: "bazillas", score: 3 });
114
- indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc) => {
114
+ indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc) => {
115
115
  return [doc.title, doc.score];
116
116
  });
117
117
  await indexer.ready();
@@ -131,16 +131,16 @@ describe("basic Index with map fun", function () {
131
131
  afterEach(async function () {
132
132
  await db.close();
133
133
  await db.destroy();
134
- await indexer.close();
135
- await indexer.destroy();
134
+ // await indexer.close();
135
+ // await indexer.destroy();
136
136
  });
137
137
  beforeEach(async function () {
138
138
  await sthis.start();
139
- db = new Database("test-indexer");
139
+ db = DatabaseFactory("test-indexer");
140
140
  await db.put({ title: "amazing" });
141
141
  await db.put({ title: "creative" });
142
142
  await db.put({ title: "bazillas" });
143
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc, map) => {
143
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc, map) => {
144
144
  map(doc.title);
145
145
  });
146
146
  await indexer.ready();
@@ -164,11 +164,11 @@ describe("basic Index with map fun with value", function () {
164
164
  });
165
165
  beforeEach(async function () {
166
166
  await sthis.start();
167
- db = new Database("test-indexer");
167
+ db = DatabaseFactory("test-indexer");
168
168
  await db.put({ title: "amazing" });
169
169
  await db.put({ title: "creative" });
170
170
  await db.put({ title: "bazillas" });
171
- indexer = new Index<string, TestType, number>(sthis, db._crdt, "hello", (doc, map) => {
171
+ indexer = new Index<string, TestType, number>(sthis, db.crdt, "hello", (doc, map) => {
172
172
  map(doc.title, doc.title.length);
173
173
  });
174
174
  });
@@ -199,17 +199,17 @@ describe("Index query with map and compound key", function () {
199
199
  afterEach(async function () {
200
200
  await db.close();
201
201
  await db.destroy();
202
- await indexer.close();
203
- await indexer.destroy();
202
+ // await indexer.close();
203
+ // await indexer.destroy();
204
204
  });
205
205
  beforeEach(async function () {
206
206
  await sthis.start();
207
- db = new Database("test-indexer");
207
+ db = DatabaseFactory("test-indexer");
208
208
  await db.put({ title: "amazing", score: 1 });
209
209
  await db.put({ title: "creative", score: 2 });
210
210
  await db.put({ title: "creative", score: 20 });
211
211
  await db.put({ title: "bazillas", score: 3 });
212
- indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc, emit) => {
212
+ indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc, emit) => {
213
213
  emit([doc.title, doc.score]);
214
214
  });
215
215
  await indexer.ready();
@@ -229,16 +229,16 @@ describe("basic Index with string fun", function () {
229
229
  afterEach(async function () {
230
230
  await db.close();
231
231
  await db.destroy();
232
- await indexer.close();
233
- await indexer.destroy();
232
+ // await indexer.close();
233
+ // await indexer.destroy();
234
234
  });
235
235
  beforeEach(async function () {
236
236
  await sthis.start();
237
- db = new Database("test-indexer");
237
+ db = DatabaseFactory("test-indexer");
238
238
  await db.put({ title: "amazing" });
239
239
  await db.put({ title: "creative" });
240
240
  await db.put({ title: "bazillas" });
241
- indexer = new Index(sthis, db._crdt, "title");
241
+ indexer = new Index(sthis, db.crdt, "title");
242
242
  await indexer.ready();
243
243
  });
244
244
  it("should get results", async function () {
@@ -265,31 +265,43 @@ describe("basic Index upon cold start", function () {
265
265
  let mapFn: (doc: TestType) => string;
266
266
  let result: IndexRows<string, TestType>;
267
267
  const sthis = mockSuperThis();
268
+ let dbOpts: DatabaseOpts;
268
269
  // result, mapFn;
269
270
  afterEach(async function () {
270
271
  await crdt.close();
271
272
  await crdt.destroy();
272
- await indexer.close();
273
- await indexer.destroy();
273
+ // await indexer.close();
274
+ // await indexer.destroy();
274
275
  });
275
276
  beforeEach(async function () {
276
277
  await sthis.start();
277
- // db = database()
278
- crdt = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
278
+ const logger = sthis.logger.With().Module("IndexerTest").Logger();
279
+ logger.Debug().Msg("enter beforeEach");
280
+ dbOpts = {
281
+ keyBag: rt.kb.defaultKeyBagOpts(sthis),
282
+ storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"),
283
+ storeEnDe: bs.ensureStoreEnDeFile({}),
284
+ };
285
+ crdt = new CRDT<TestType>(sthis, dbOpts);
279
286
  await crdt.bulk([
280
287
  { id: "abc1", value: { title: "amazing" } },
281
288
  { id: "abc2", value: { title: "creative" } },
282
289
  { id: "abc3", value: { title: "bazillas" } },
283
290
  ]);
291
+ logger.Debug().Msg("post bulk beforeEach");
284
292
  didMap = 0;
285
293
  mapFn = (doc) => {
286
294
  didMap++;
287
295
  return doc.title;
288
296
  };
289
- indexer = await index<string, TestType>(sthis, { _crdt: crdt }, "hello", mapFn);
297
+ indexer = await index<string, TestType>({ crdt: crdt }, "hello", mapFn);
298
+ logger.Debug().Msg("post index beforeEach");
290
299
  await indexer.ready();
300
+ logger.Debug().Msg("post indexer.ready beforeEach");
291
301
  // new Index(db._crdt.indexBlockstore, db._crdt, 'hello', mapFn)
292
302
  result = await indexer.query();
303
+
304
+ logger.Debug().Msg("post indexer.query beforeEach");
293
305
  expect(indexer.indexHead).toEqual(crdt.clock.head);
294
306
  });
295
307
  it("should call map on first query", function () {
@@ -302,12 +314,12 @@ describe("basic Index upon cold start", function () {
302
314
  expect(result.rows.length).toEqual(3);
303
315
  });
304
316
  it("should work on cold load", async function () {
305
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
317
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
306
318
  await crdt2.ready();
307
319
  const { result, head } = await crdt2.changes();
308
320
  expect(result).toBeTruthy();
309
321
  await crdt2.ready();
310
- const indexer2 = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", mapFn);
322
+ const indexer2 = await index<string, TestType>({ crdt: crdt2 }, "hello", mapFn);
311
323
  await indexer2.ready();
312
324
  const result2 = await indexer2.query();
313
325
  expect(indexer2.indexHead).toEqual(head);
@@ -317,8 +329,8 @@ describe("basic Index upon cold start", function () {
317
329
  });
318
330
  it.skip("should not rerun the map function on seen changes", async function () {
319
331
  didMap = 0;
320
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
321
- const indexer2 = await index(sthis, { _crdt: crdt2 }, "hello", mapFn);
332
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
333
+ const indexer2 = await index({ crdt: crdt2 }, "hello", mapFn);
322
334
  const { result, head } = await crdt2.changes([]);
323
335
  expect(result.length).toEqual(3);
324
336
  expect(head.length).toEqual(1);
@@ -342,10 +354,8 @@ describe("basic Index upon cold start", function () {
342
354
  expect(didMap).toEqual(1);
343
355
  });
344
356
  it("should ignore meta when map function definiton changes", async function () {
345
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold");
346
- const result = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", (doc) =>
347
- doc.title.split("").reverse().join(""),
348
- ).query();
357
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
358
+ const result = await index<string, TestType>({ crdt: crdt2 }, "hello", (doc) => doc.title.split("").reverse().join("")).query();
349
359
  expect(result.rows.length).toEqual(3);
350
360
  expect(result.rows[0].key).toEqual("evitaerc"); // creative
351
361
  });
@@ -359,20 +369,20 @@ describe("basic Index with no data", function () {
359
369
  afterEach(async function () {
360
370
  await db.close();
361
371
  await db.destroy();
362
- await indexer.close();
363
- await indexer.destroy();
372
+ // await indexer.close();
373
+ // await indexer.destroy();
364
374
  });
365
375
  beforeEach(async function () {
366
376
  await sthis.start();
367
- db = new Database("test-indexer");
368
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
377
+ db = DatabaseFactory("test-indexer");
378
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
369
379
  didMap = true;
370
380
  return doc.title;
371
381
  });
372
382
  await indexer.ready();
373
383
  });
374
384
  it("should have properties", function () {
375
- expect(indexer.crdt).toEqual(db._crdt);
385
+ expect(indexer.crdt).toEqual(db.crdt);
376
386
  expect(indexer.name).toEqual("hello");
377
387
  expect(indexer.mapFn).toBeTruthy();
378
388
  });
@@ -1,8 +1,6 @@
1
- import { URI } from "@adviser/cement";
1
+ import { runtimeFn, URI } from "@adviser/cement";
2
2
  import { rt, getStore, ensureSuperLog } from "@fireproof/core";
3
3
  import { mockSuperThis } from "../helpers";
4
-
5
- // only for test
6
4
  import { UUID } from "uuidv7";
7
5
 
8
6
  describe("utils", () => {
@@ -21,7 +19,7 @@ describe("utils", () => {
21
19
  const storeOpts = [
22
20
  {
23
21
  type: "data",
24
- suffix: ".car",
22
+ suffix: ".tar",
25
23
  },
26
24
  {
27
25
  type: "wal",
@@ -34,14 +32,16 @@ describe("utils", () => {
34
32
  ];
35
33
  it("getfilename plain", () => {
36
34
  for (const store of storeOpts) {
37
- const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
35
+ const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version&suffix=${store.suffix}`);
38
36
  expect(rt.getFileName(url, logger)).toEqual(`${store.type}/key${store.suffix}`);
39
37
  }
40
38
  });
41
39
 
42
40
  it("getfilename index", () => {
43
41
  for (const store of storeOpts) {
44
- const url = URI.from(`file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version`);
42
+ const url = URI.from(
43
+ `file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version&suffix=${store.suffix}`,
44
+ );
45
45
  expect(rt.getFileName(url, logger)).toEqual(`idx-${store.type}/key${store.suffix}`);
46
46
  }
47
47
  });
@@ -82,3 +82,15 @@ describe("utils", () => {
82
82
  expect(id.slice(0, 15)).toBe("cafebabe-beef-7");
83
83
  });
84
84
  });
85
+
86
+ describe("runtime", () => {
87
+ it("runtime", () => {
88
+ const isNode = !!(typeof process === "object" && process.versions?.node);
89
+ expect(runtimeFn()).toEqual({
90
+ isBrowser: !isNode,
91
+ isDeno: false,
92
+ isNodeIsh: isNode,
93
+ isReactNative: false,
94
+ });
95
+ });
96
+ });
@@ -0,0 +1,303 @@
1
+ import { BuildURI, CoerceURI, URI } from "@adviser/cement";
2
+ import { fireproof, PARAM, rt, SuperThis } from "@fireproof/core";
3
+ import { mockSuperThis } from "../../helpers";
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.getFileSystem(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.getFileSystem(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
+ urlGen: "default",
193
+ store: "data",
194
+ name: my_app(),
195
+ storekey: `@${my_app()}-data@`,
196
+ version: rt.FILESTORE_VERSION,
197
+ },
198
+ });
199
+
200
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
201
+
202
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
203
+ expect(fileStore?.url().asObj()).toEqual({
204
+ pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
205
+ protocol: "file:",
206
+ style: "path",
207
+ searchParams: {
208
+ ...isMemFS,
209
+ urlGen: "default",
210
+ store: "data",
211
+ name: my_app(),
212
+ storekey: `@${my_app()}-data@`,
213
+ version: rt.FILESTORE_VERSION,
214
+ },
215
+ });
216
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
217
+ expect(metaStore?.url().asObj()).toEqual({
218
+ pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
219
+ protocol: "file:",
220
+ style: "path",
221
+ searchParams: {
222
+ ...isMemFS,
223
+ urlGen: "default",
224
+ store: "meta",
225
+ name: my_app(),
226
+ storekey: `@${my_app()}-meta@`,
227
+ version: rt.FILESTORE_VERSION,
228
+ },
229
+ });
230
+
231
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
232
+ sthis.env.set("FP_STORAGE_URL", old);
233
+ await db.close();
234
+ });
235
+
236
+ it("set by env", async () => {
237
+ const old = sthis.env.get("FP_STORAGE_URL");
238
+ // assert(!old, "FP_STORAGE_URL must set")
239
+ const testUrl = BuildURI.from(old);
240
+ // sthis.env.set("FP_STORAGE_URL", testUrl.toString());
241
+
242
+ let baseDir = dataDir(sthis, my_app()).pathname;
243
+ baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
244
+
245
+ const sysfs = await rt.getFileSystem(testUrl.URI());
246
+ await sysfs.rm(baseDir, { recursive: true }).catch(() => {
247
+ /* */
248
+ });
249
+
250
+ const db = fireproof(my_app());
251
+ await db.put({ name: "my-app" });
252
+ expect(db.name()).toBe(my_app());
253
+ const carStore = await db.crdt.blockstore.loader?.carStore();
254
+ expect(carStore?.url().asObj()).toEqual({
255
+ pathname: "./dist/fp-dir-file",
256
+ protocol: "file:",
257
+ style: "path",
258
+ searchParams: {
259
+ ...isMemFS,
260
+ urlGen: "fromEnv",
261
+ store: "data",
262
+ suffix: ".car",
263
+ name: my_app(),
264
+ storekey: `@${my_app()}-data@`,
265
+ version: rt.FILESTORE_VERSION,
266
+ },
267
+ });
268
+
269
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
270
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
271
+ expect(fileStore?.url().asObj()).toEqual({
272
+ pathname: `./dist/fp-dir-file`,
273
+ protocol: "file:",
274
+ style: "path",
275
+ searchParams: {
276
+ ...isMemFS,
277
+ urlGen: "fromEnv",
278
+ store: "data",
279
+ name: my_app(),
280
+ storekey: `@${my_app()}-data@`,
281
+ version: rt.FILESTORE_VERSION,
282
+ },
283
+ });
284
+
285
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
286
+ expect(metaStore?.url().asObj()).toEqual({
287
+ pathname: `./dist/fp-dir-file`,
288
+ protocol: "file:",
289
+ style: "path",
290
+ searchParams: {
291
+ ...isMemFS,
292
+ urlGen: "fromEnv",
293
+ store: "meta",
294
+ name: my_app(),
295
+ storekey: `@${my_app()}-meta@`,
296
+ version: rt.FILESTORE_VERSION,
297
+ },
298
+ });
299
+ expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
300
+ await db.close();
301
+ sthis.env.set("FP_STORAGE_URL", old);
302
+ });
303
+ });
@@ -0,0 +1,75 @@
1
+ import { fireproof } from "@fireproof/core";
2
+ import { mockSuperThis } from "../../helpers";
3
+
4
+ describe("fireproof config indexdb", () => {
5
+ const _my_app = "my-app";
6
+ function my_app() {
7
+ return _my_app;
8
+ }
9
+ const sthis = mockSuperThis();
10
+ beforeAll(async () => {
11
+ await sthis.start();
12
+ });
13
+
14
+ it("indexdb-loader", async () => {
15
+ const db = fireproof(my_app());
16
+ await db.put({ name: "my-app" });
17
+ expect(db.name()).toBe(my_app());
18
+
19
+ const fileStore = await db.crdt.blockstore.loader?.fileStore();
20
+ expect(fileStore?.url().asObj()).toEqual({
21
+ pathname: "fp",
22
+ protocol: "indexdb:",
23
+ searchParams: {
24
+ name: "my-app",
25
+ store: "data",
26
+ storekey: "@my-app-data@",
27
+ urlGen: "default",
28
+ version: "v0.19-indexdb",
29
+ },
30
+ style: "path",
31
+ });
32
+
33
+ const dataStore = await db.crdt.blockstore.loader?.carStore();
34
+ expect(dataStore?.url().asObj()).toEqual({
35
+ pathname: "fp",
36
+ protocol: "indexdb:",
37
+ searchParams: {
38
+ name: "my-app",
39
+ store: "data",
40
+ storekey: "@my-app-data@",
41
+ suffix: ".car",
42
+ urlGen: "default",
43
+ version: "v0.19-indexdb",
44
+ },
45
+ style: "path",
46
+ });
47
+ const metaStore = await db.crdt.blockstore.loader?.metaStore();
48
+ expect(metaStore?.url().asObj()).toEqual({
49
+ pathname: "fp",
50
+ protocol: "indexdb:",
51
+ searchParams: {
52
+ name: "my-app",
53
+ store: "meta",
54
+ storekey: "@my-app-meta@",
55
+ urlGen: "default",
56
+ version: "v0.19-indexdb",
57
+ },
58
+ style: "path",
59
+ });
60
+ const WALStore = await db.crdt.blockstore.loader?.WALStore();
61
+ expect(WALStore?.url().asObj()).toEqual({
62
+ pathname: "fp",
63
+ protocol: "indexdb:",
64
+ searchParams: {
65
+ name: "my-app",
66
+ store: "wal",
67
+ storekey: "@my-app-wal@",
68
+ urlGen: "default",
69
+ version: "v0.19-indexdb",
70
+ },
71
+ style: "path",
72
+ });
73
+ await db.close();
74
+ });
75
+ });