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

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.
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,4 @@
1
- import { CRDT, ensureSuperThis } from "@fireproof/core";
1
+ import { CRDT, defaultWriteQueueOpts, ensureSuperThis, DatabaseOpts, toStoreURIRuntime, rt } 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";
@@ -12,7 +12,13 @@ describe("Fresh crdt", function () {
12
12
  });
13
13
  beforeEach(async function () {
14
14
  await sthis.start();
15
- crdt = new CRDT(sthis);
15
+ const dbOpts: DatabaseOpts = {
16
+ writeQueue: defaultWriteQueueOpts({}),
17
+ keyBag: rt.defaultKeyBagOpts(sthis),
18
+ storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
19
+ storeEnDe: bs.ensureStoreEnDeFile({}),
20
+ };
21
+ crdt = new CRDT(sthis, dbOpts);
16
22
  });
17
23
  it("should have an empty head", async function () {
18
24
  const head = crdt.clock.head;
@@ -49,7 +55,13 @@ describe("CRDT with one record", function () {
49
55
 
50
56
  beforeEach(async function () {
51
57
  await sthis.start();
52
- crdt = new CRDT(sthis, `test@${sthis.nextId()}`);
58
+ const dbOpts: DatabaseOpts = {
59
+ writeQueue: defaultWriteQueueOpts({}),
60
+ keyBag: rt.defaultKeyBagOpts(sthis),
61
+ storeUrls: toStoreURIRuntime(sthis, `test@${sthis.nextId().str}`),
62
+ storeEnDe: bs.ensureStoreEnDeFile({}),
63
+ };
64
+ crdt = new CRDT(sthis, dbOpts);
53
65
  firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
54
66
  });
55
67
  it("should have a one-element head", async function () {
@@ -99,7 +111,13 @@ describe("CRDT with a multi-write", function () {
99
111
  });
100
112
  beforeEach(async function () {
101
113
  await sthis.start();
102
- crdt = new CRDT(sthis);
114
+ const dbOpts: DatabaseOpts = {
115
+ writeQueue: defaultWriteQueueOpts({}),
116
+ keyBag: rt.defaultKeyBagOpts(sthis),
117
+ storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
118
+ storeEnDe: bs.ensureStoreEnDeFile({}),
119
+ };
120
+ crdt = new CRDT(sthis, dbOpts);
103
121
  firstPut = await crdt.bulk([
104
122
  { id: "ace", value: { points: 11 } },
105
123
  { id: "king", value: { points: 10 } },
@@ -164,7 +182,13 @@ describe("CRDT with two multi-writes", function () {
164
182
  });
165
183
  beforeEach(async () => {
166
184
  await sthis.start();
167
- crdt = new CRDT(sthis);
185
+ const dbOpts: DatabaseOpts = {
186
+ writeQueue: defaultWriteQueueOpts({}),
187
+ keyBag: rt.defaultKeyBagOpts(sthis),
188
+ storeUrls: toStoreURIRuntime(sthis, `test-multiple-writes@${sthis.nextId().str}`),
189
+ storeEnDe: bs.ensureStoreEnDeFile({}),
190
+ };
191
+ crdt = new CRDT(sthis, dbOpts);
168
192
  firstPut = await crdt.bulk([
169
193
  { id: "ace", value: { points: 11 } },
170
194
  { id: "king", value: { points: 10 } },
@@ -212,7 +236,13 @@ describe("Compact a named CRDT with writes", function () {
212
236
  });
213
237
  beforeEach(async function () {
214
238
  await sthis.start();
215
- crdt = new CRDT(sthis, "named-crdt-compaction");
239
+ const dbOpts: DatabaseOpts = {
240
+ writeQueue: defaultWriteQueueOpts({}),
241
+ keyBag: rt.defaultKeyBagOpts(sthis),
242
+ storeUrls: toStoreURIRuntime(sthis, `named-crdt-compaction`),
243
+ storeEnDe: bs.ensureStoreEnDeFile({}),
244
+ };
245
+ crdt = new CRDT(sthis, dbOpts);
216
246
  for (let i = 0; i < 10; i++) {
217
247
  const bulk = [
218
248
  { id: "ace", value: { points: 11 } },
@@ -268,12 +298,18 @@ describe("CRDT with an index", function () {
268
298
  });
269
299
  beforeEach(async function () {
270
300
  await sthis.start();
271
- crdt = new CRDT<CRDTTestType>(sthis);
301
+ const dbOpts: DatabaseOpts = {
302
+ writeQueue: defaultWriteQueueOpts({}),
303
+ keyBag: rt.defaultKeyBagOpts(sthis),
304
+ storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
305
+ storeEnDe: bs.ensureStoreEnDeFile({}),
306
+ };
307
+ crdt = new CRDT<CRDTTestType>(sthis, dbOpts);
272
308
  await crdt.bulk([
273
309
  { id: "ace", value: { points: 11 } },
274
310
  { id: "king", value: { points: 10 } },
275
311
  ]);
276
- idx = await index<number, CRDTTestType>(sthis, { _crdt: crdt }, "points");
312
+ idx = await index<number, CRDTTestType>({ crdt: crdt }, "points");
277
313
  });
278
314
  it("should query the data", async function () {
279
315
  const got = await idx.query({ range: [9, 12] });
@@ -282,7 +318,7 @@ describe("CRDT with an index", function () {
282
318
  expect(got.rows[0].key).toBe(10);
283
319
  });
284
320
  it("should register the index", async function () {
285
- const rIdx = await index<number, CRDTTestType>(sthis, { _crdt: crdt }, "points");
321
+ const rIdx = await index<number, CRDTTestType>({ crdt: crdt }, "points");
286
322
  expect(rIdx).toBeTruthy();
287
323
  expect(rIdx.name).toBe("points");
288
324
  const got = await rIdx.query({ range: [9, 12] });
@@ -291,7 +327,7 @@ describe("CRDT with an index", function () {
291
327
  expect(got.rows[0].key).toBe(10);
292
328
  });
293
329
  it("creating a different index with same name should not work", async function () {
294
- const e = await index(sthis, { _crdt: crdt }, "points", (doc) => doc._id)
330
+ const e = await index({ crdt: crdt }, "points", (doc) => doc._id)
295
331
  .query()
296
332
  .catch((err) => err);
297
333
  expect(e.message).toMatch(/cannot apply/);
@@ -314,15 +350,26 @@ describe("Loader with a committed transaction", function () {
314
350
  });
315
351
  beforeEach(async function () {
316
352
  await sthis.start();
317
- crdt = new CRDT(sthis, dbname);
353
+ const dbOpts: DatabaseOpts = {
354
+ writeQueue: defaultWriteQueueOpts({}),
355
+ keyBag: rt.defaultKeyBagOpts(sthis),
356
+ storeUrls: toStoreURIRuntime(sthis, dbname),
357
+ storeEnDe: bs.ensureStoreEnDeFile({}),
358
+ };
359
+ crdt = new CRDT(sthis, dbOpts);
318
360
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
319
361
  expect(blockstore.loader).toBeTruthy();
320
- loader = blockstore.loader;
362
+ loader = blockstore.loader as bs.Loader;
321
363
  done = await crdt.bulk([{ id: "foo", value: { foo: "bar" } }]);
322
364
  });
323
- it("should have a name", function () {
324
- expect(loader.name).toBe(dbname);
325
- });
365
+ // it("should have a name", function () {
366
+ // expect(loader.ebOpts.storeUrls).toEqual({
367
+ // data: "file://./dist/fp-dir-file?name=test-loader&store=data&storekey=%40test-loader-data%40&suffix=.car&urlGen=fromEnv",
368
+ // file: "file://./dist/fp-dir-file?name=test-loader&store=data&storekey=%40test-loader-data%40&urlGen=fromEnv",
369
+ // meta: "file://./dist/fp-dir-file?name=test-loader&store=meta&storekey=%40test-loader-meta%40&urlGen=fromEnv",
370
+ // wal: "file://./dist/fp-dir-file?name=test-loader&store=wal&storekey=%40test-loader-wal%40&urlGen=fromEnv",
371
+ // });
372
+ // });
326
373
  it("should commit a transaction", function () {
327
374
  expect(done.head).toBeTruthy();
328
375
  // expect(done.cars).toBeTruthy();
@@ -357,10 +404,16 @@ describe("Loader with two committed transactions", function () {
357
404
  });
358
405
  beforeEach(async function () {
359
406
  await sthis.start();
360
- crdt = new CRDT(sthis, "test-loader");
407
+ const dbOpts: DatabaseOpts = {
408
+ writeQueue: defaultWriteQueueOpts({}),
409
+ keyBag: rt.defaultKeyBagOpts(sthis),
410
+ storeUrls: toStoreURIRuntime(sthis, "test-loader"),
411
+ storeEnDe: bs.ensureStoreEnDeFile({}),
412
+ };
413
+ crdt = new CRDT(sthis, dbOpts);
361
414
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
362
415
  expect(blockstore.loader).toBeTruthy();
363
- loader = blockstore.loader;
416
+ loader = blockstore.loader as bs.Loader;
364
417
  done1 = await crdt.bulk([{ id: "apple", value: { foo: "bar" } }]);
365
418
  done2 = await crdt.bulk([{ id: "orange", value: { foo: "bar" } }]);
366
419
  });
@@ -407,10 +460,16 @@ describe("Loader with many committed transactions", function () {
407
460
  });
408
461
  beforeEach(async function () {
409
462
  await sthis.start();
410
- crdt = new CRDT(sthis, "test-loader-many");
463
+ const dbOpts: DatabaseOpts = {
464
+ writeQueue: defaultWriteQueueOpts({}),
465
+ keyBag: rt.defaultKeyBagOpts(sthis),
466
+ storeUrls: toStoreURIRuntime(sthis, "test-loader-many"),
467
+ storeEnDe: bs.ensureStoreEnDeFile({}),
468
+ };
469
+ crdt = new CRDT(sthis, dbOpts);
411
470
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
412
471
  expect(blockstore.loader).toBeTruthy();
413
- loader = blockstore.loader;
472
+ loader = blockstore.loader as bs.Loader;
414
473
  dones = [];
415
474
  for (let i = 0; i < count; i++) {
416
475
  const did = await crdt.bulk([{ id: `apple${i}`, value: { foo: "bar" } }]);
@@ -1,16 +1,31 @@
1
- import { buildBlobFiles, FileWithCid } from "../helpers.js";
2
- import { bs, Database, DocResponse, DocFileMeta, DocWithId, DocFiles, ensureSuperThis } from "@fireproof/core";
1
+ import { URI } from "@adviser/cement";
2
+ 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
+ ensureSuperThis,
15
+ } from "@fireproof/core";
3
16
 
4
17
  describe("basic Database", () => {
5
18
  let db: Database;
6
- const sthis = ensureSuperThis();
19
+ const sthis = mockSuperThis();
7
20
  afterEach(async () => {
8
21
  await db.close();
9
22
  await db.destroy();
10
23
  });
11
24
  beforeEach(async () => {
12
25
  await sthis.start();
13
- db = new Database();
26
+ db = DatabaseFactory(undefined, {
27
+ logger: sthis.logger,
28
+ });
14
29
  });
15
30
  it("should put", async () => {
16
31
  /** @type {Doc} */
@@ -38,7 +53,7 @@ describe("basic Database with record", function () {
38
53
  interface Doc {
39
54
  readonly value: string;
40
55
  }
41
- let db: Database;
56
+ let db: DatabaseShell;
42
57
  const sthis = ensureSuperThis();
43
58
  afterEach(async () => {
44
59
  await db.close();
@@ -46,7 +61,7 @@ describe("basic Database with record", function () {
46
61
  });
47
62
  beforeEach(async function () {
48
63
  await sthis.start();
49
- db = new Database();
64
+ db = DatabaseFactory("factory-name") as DatabaseShell;
50
65
  const ok = await db.put<Doc>({ _id: "hello", value: "world" });
51
66
  expect(ok.id).toBe("hello");
52
67
  });
@@ -78,13 +93,13 @@ describe("basic Database with record", function () {
78
93
  expect(rows[0].value._id).toBe("hello");
79
94
  });
80
95
  it("is not persisted", async function () {
81
- const db2 = new Database();
96
+ const db2 = DatabaseFactory("factory-name") as DatabaseShell;
82
97
  const { rows } = await db2.changes([]);
83
- expect(rows.length).toBe(0);
84
- const doc = await db2.get("hello").catch((e) => e);
85
- expect(doc.message).toBeTruthy();
98
+ expect(rows.length).toBe(1);
99
+ expect(db2.ref).toBe(db.ref);
100
+ const doc = await db2.get<Doc>("hello").catch((e) => e);
101
+ expect(doc.value).toBe("world");
86
102
  await db2.close();
87
- await db2.destroy();
88
103
  });
89
104
  });
90
105
 
@@ -100,7 +115,7 @@ describe("named Database with record", function () {
100
115
  });
101
116
  beforeEach(async function () {
102
117
  await sthis.start();
103
- db = new Database("test-db-name");
118
+ db = DatabaseFactory("test-db-name");
104
119
  /** @type {Doc} */
105
120
  const doc = { _id: "hello", value: "world" };
106
121
  const ok = await db.put(doc);
@@ -136,7 +151,7 @@ describe("named Database with record", function () {
136
151
  it("should have a key", async function () {
137
152
  const { rows } = await db.changes([]);
138
153
  expect(rows.length).toBe(1);
139
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
154
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
140
155
  const loader = blocks.loader;
141
156
  expect(loader).toBeTruthy();
142
157
  await loader.ready();
@@ -217,7 +232,41 @@ describe("named Database with record", function () {
217
232
  // await Promise.all(writes)
218
233
  // })
219
234
 
220
- describe("basic Database parallel writes / public", function () {
235
+ describe("basic Database parallel writes / public ordered", () => {
236
+ let db: Database;
237
+ const writes: Promise<DocResponse>[] = [];
238
+ const sthis = mockSuperThis();
239
+ afterEach(async () => {
240
+ await db.close();
241
+ await db.destroy();
242
+ });
243
+ beforeEach(async () => {
244
+ await sthis.start();
245
+ db = DatabaseFactory("test-parallel-writes-ordered", { writeQueue: { chunkSize: 1 } });
246
+ for (let i = 0; i < 10; i++) {
247
+ const doc = { _id: `id-${i}`, hello: "world" };
248
+ writes.push(db.put(doc));
249
+ }
250
+ await Promise.all(writes);
251
+ });
252
+
253
+ it("should have one head", () => {
254
+ const crdt = db.crdt;
255
+ expect(crdt.clock.head.length).toBe(1);
256
+ });
257
+
258
+ it("has changes ordered", async function () {
259
+ const { rows, clock } = await db.changes([]);
260
+ expect(clock[0]).toBe(db.crdt.clock.head[0]);
261
+ expect(rows.length).toBe(10);
262
+ for (let i = 0; i < 10; i++) {
263
+ expect(rows[i].key).toBe("id-" + i);
264
+ expect(rows[i].clock).toBeTruthy();
265
+ }
266
+ });
267
+ });
268
+
269
+ describe("basic Database parallel writes / public", () => {
221
270
  let db: Database;
222
271
  const writes: Promise<DocResponse>[] = [];
223
272
  const sthis = ensureSuperThis();
@@ -225,20 +274,22 @@ describe("basic Database parallel writes / public", function () {
225
274
  await db.close();
226
275
  await db.destroy();
227
276
  });
228
- beforeEach(async function () {
277
+ beforeEach(async () => {
229
278
  await sthis.start();
230
- db = new Database("test-parallel-writes", { public: true });
279
+ db = DatabaseFactory("test-parallel-writes", { writeQueue: { chunkSize: 32 } });
231
280
  for (let i = 0; i < 10; i++) {
232
281
  const doc = { _id: `id-${i}`, hello: "world" };
233
282
  writes.push(db.put(doc));
234
283
  }
235
284
  await Promise.all(writes);
236
285
  });
237
- it("should have one head", function () {
238
- const crdt = db._crdt;
286
+ it("should resolve to one head", async () => {
287
+ const crdt = db.crdt;
288
+ expect(crdt.clock.head.length).toBe(9);
289
+ await db.put({ _id: "id-10", hello: "world" });
239
290
  expect(crdt.clock.head.length).toBe(1);
240
291
  });
241
- it("should write all", async function () {
292
+ it("should write all", async () => {
242
293
  for (let i = 0; i < 10; i++) {
243
294
  const id = `id-${i}`;
244
295
  const doc = await db.get<{ hello: string }>(id);
@@ -270,11 +321,12 @@ describe("basic Database parallel writes / public", function () {
270
321
  expect(e.message).toMatch(/Not found/);
271
322
  }
272
323
  });
273
- it("has changes", async function () {
324
+ it("has changes not ordered", async function () {
274
325
  const { rows, clock } = await db.changes([]);
275
- expect(clock[0]).toBe(db._crdt.clock.head[0]);
326
+ expect(clock[0]).toBe(db.crdt.clock.head[0]);
276
327
  expect(rows.length).toBe(10);
277
- // rows.sort((a, b) => a.key.localeCompare(b.key));
328
+ rows.sort((a, b) => a.key.localeCompare(b.key));
329
+ // console.log(rows);
278
330
  for (let i = 0; i < 10; i++) {
279
331
  expect(rows[i].key).toBe("id-" + i);
280
332
  expect(rows[i].clock).toBeTruthy();
@@ -283,9 +335,9 @@ describe("basic Database parallel writes / public", function () {
283
335
  it("should not have a key", async function () {
284
336
  const { rows } = await db.changes([]);
285
337
  expect(rows.length).toBe(10);
286
- expect(db.opts.public).toBeTruthy();
287
- expect(db._crdt.opts.public).toBeTruthy();
288
- const blocks = db._crdt.blockstore as bs.EncryptedBlockstore;
338
+ // expect(db.opts.public).toBeTruthy();
339
+ // expect(db._crdt.opts.public).toBeTruthy();
340
+ const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
289
341
  const loader = blocks.loader;
290
342
  expect(loader).toBeTruthy();
291
343
  await loader.ready();
@@ -307,7 +359,7 @@ describe("basic Database with subscription", function () {
307
359
  });
308
360
  beforeEach(async function () {
309
361
  await sthis.start();
310
- db = new Database();
362
+ db = DatabaseFactory("factory-name");
311
363
  didRun = 0;
312
364
  waitForSub = new Promise((resolve) => {
313
365
  unsubscribe = db.subscribe((docs) => {
@@ -351,9 +403,8 @@ describe("basic Database with no update subscription", function () {
351
403
  });
352
404
  beforeEach(async function () {
353
405
  await sthis.start();
354
- db = new Database();
406
+ db = DatabaseFactory("factory-name");
355
407
  didRun = 0;
356
-
357
408
  unsubscribe = db.subscribe(() => {
358
409
  didRun++;
359
410
  });
@@ -390,7 +441,7 @@ describe("database with files input", () => {
390
441
  beforeEach(async function () {
391
442
  await sthis.start();
392
443
  imagefiles = await buildBlobFiles();
393
- db = new Database("fireproof-with-images");
444
+ db = DatabaseFactory("fireproof-with-images");
394
445
  const doc = {
395
446
  _id: "images-main",
396
447
  type: "files",
@@ -472,3 +523,148 @@ describe("database with files input", () => {
472
523
  expect(file.size).toBe(imagefiles[0].file.size);
473
524
  });
474
525
  });
526
+
527
+ describe("StoreURIRuntime", () => {
528
+ const sthis = mockSuperThis();
529
+ let safeEnv: string | undefined;
530
+ let unreg: () => void;
531
+ beforeEach(async () => {
532
+ await sthis.start();
533
+ safeEnv = sthis.env.get("FP_STORAGE_URL");
534
+ sthis.env.set("FP_STORAGE_URL", "my://bla/storage");
535
+ unreg = bs.registerStoreProtocol({
536
+ protocol: "murks",
537
+ isDefault: true,
538
+ defaultURI: function (): URI {
539
+ return URI.from("murks://fp");
540
+ },
541
+ gateway: function (): Promise<bs.Gateway> {
542
+ throw new Error("Function not implemented.");
543
+ },
544
+ });
545
+ });
546
+ afterEach(() => {
547
+ sthis.env.set("FP_STORAGE_URL", safeEnv);
548
+ unreg();
549
+ });
550
+ it("default toStoreURIRuntime", () => {
551
+ expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "test")))).toEqual({
552
+ data: {
553
+ data: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&suffix=.car&urlGen=fromEnv",
554
+ file: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&urlGen=fromEnv",
555
+ meta: "my://bla/storage?name=test&store=meta&storekey=%40test-meta%40&urlGen=fromEnv",
556
+ wal: "my://bla/storage?name=test&store=wal&storekey=%40test-wal%40&urlGen=fromEnv",
557
+ },
558
+ idx: {
559
+ data: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&suffix=.car&urlGen=fromEnv",
560
+ file: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&urlGen=fromEnv",
561
+ meta: "my://bla/storage?index=idx&name=test&store=meta&storekey=%40test-meta-idx%40&urlGen=fromEnv",
562
+ wal: "my://bla/storage?index=idx&name=test&store=wal&storekey=%40test-wal-idx%40&urlGen=fromEnv",
563
+ },
564
+ });
565
+ // keyConfigOpts(sthis: SuperThis, name: string, opts?: ConfigOpts): string {
566
+ });
567
+ it("no name toStoreURIRuntime", () => {
568
+ expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis)))).toEqual({
569
+ data: {
570
+ data: "my://bla/storage?name=storage&store=data&storekey=%40storage-data%40&suffix=.car&urlGen=fromEnv",
571
+ file: "my://bla/storage?name=storage&store=data&storekey=%40storage-data%40&urlGen=fromEnv",
572
+ meta: "my://bla/storage?name=storage&store=meta&storekey=%40storage-meta%40&urlGen=fromEnv",
573
+ wal: "my://bla/storage?name=storage&store=wal&storekey=%40storage-wal%40&urlGen=fromEnv",
574
+ },
575
+ idx: {
576
+ data: "my://bla/storage?index=idx&name=storage&store=data&storekey=%40storage-data-idx%40&suffix=.car&urlGen=fromEnv",
577
+ file: "my://bla/storage?index=idx&name=storage&store=data&storekey=%40storage-data-idx%40&urlGen=fromEnv",
578
+ meta: "my://bla/storage?index=idx&name=storage&store=meta&storekey=%40storage-meta-idx%40&urlGen=fromEnv",
579
+ wal: "my://bla/storage?index=idx&name=storage&store=wal&storekey=%40storage-wal-idx%40&urlGen=fromEnv",
580
+ },
581
+ });
582
+ });
583
+
584
+ it("set toStoreURIRuntime", () => {
585
+ expect(
586
+ JSON.parse(
587
+ JSON.stringify(
588
+ toStoreURIRuntime(sthis, "xxx", {
589
+ base: "my://storage-base",
590
+ data: {
591
+ data: "my://storage-data?name=yyy",
592
+ meta: "my://storage-meta",
593
+ },
594
+ idx: {
595
+ data: "my://storage-idx-data?name=yyy&index=bla",
596
+ meta: "my://storage-idx-meta",
597
+ },
598
+ }),
599
+ ),
600
+ ),
601
+ ).toEqual({
602
+ data: {
603
+ data: "my://storage-data?name=yyy&store=data&storekey=%40yyy-data%40&suffix=.car",
604
+ file: "my://storage-data?name=yyy&store=data&storekey=%40yyy-data%40",
605
+ meta: "my://storage-meta?name=storage-meta&store=meta&storekey=%40storage-meta-meta%40",
606
+ wal: "my://storage-base?name=xxx&store=wal&storekey=%40xxx-wal%40",
607
+ },
608
+ idx: {
609
+ data: "my://storage-idx-data?index=bla&name=yyy&store=data&storekey=%40yyy-data-idx%40&suffix=.car",
610
+ file: "my://storage-idx-data?index=bla&name=yyy&store=data&storekey=%40yyy-data-idx%40",
611
+ meta: "my://storage-idx-meta?index=idx&name=storage-idx-meta&store=meta&storekey=%40storage-idx-meta-meta-idx%40",
612
+ wal: "my://storage-base?index=idx&name=xxx&store=wal&storekey=%40xxx-wal-idx%40",
613
+ },
614
+ });
615
+ });
616
+
617
+ it("default-reg toStoreURIRuntime", () => {
618
+ sthis.env.delete("FP_STORAGE_URL");
619
+ expect(JSON.parse(JSON.stringify(toStoreURIRuntime(sthis, "maxi")))).toEqual({
620
+ data: {
621
+ data: "murks://fp?name=maxi&store=data&storekey=%40maxi-data%40&suffix=.car&urlGen=default",
622
+ file: "murks://fp?name=maxi&store=data&storekey=%40maxi-data%40&urlGen=default",
623
+ meta: "murks://fp?name=maxi&store=meta&storekey=%40maxi-meta%40&urlGen=default",
624
+ wal: "murks://fp?name=maxi&store=wal&storekey=%40maxi-wal%40&urlGen=default",
625
+ },
626
+ idx: {
627
+ data: "murks://fp?index=idx&name=maxi&store=data&storekey=%40maxi-data-idx%40&suffix=.car&urlGen=default",
628
+ file: "murks://fp?index=idx&name=maxi&store=data&storekey=%40maxi-data-idx%40&urlGen=default",
629
+ meta: "murks://fp?index=idx&name=maxi&store=meta&storekey=%40maxi-meta-idx%40&urlGen=default",
630
+ wal: "murks://fp?index=idx&name=maxi&store=wal&storekey=%40maxi-wal-idx%40&urlGen=default",
631
+ },
632
+ });
633
+ });
634
+
635
+ it("keyConfigOpts", () => {
636
+ expect(JSON.parse(keyConfigOpts(sthis, "test"))).toEqual([
637
+ {
638
+ name: "test",
639
+ },
640
+ {
641
+ stores: [
642
+ {
643
+ data: {
644
+ data: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&suffix=.car&urlGen=fromEnv",
645
+ file: "my://bla/storage?name=test&store=data&storekey=%40test-data%40&urlGen=fromEnv",
646
+ meta: "my://bla/storage?name=test&store=meta&storekey=%40test-meta%40&urlGen=fromEnv",
647
+ wal: "my://bla/storage?name=test&store=wal&storekey=%40test-wal%40&urlGen=fromEnv",
648
+ },
649
+ },
650
+ {
651
+ idx: {
652
+ data: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&suffix=.car&urlGen=fromEnv",
653
+ file: "my://bla/storage?index=idx&name=test&store=data&storekey=%40test-data-idx%40&urlGen=fromEnv",
654
+ meta: "my://bla/storage?index=idx&name=test&store=meta&storekey=%40test-meta-idx%40&urlGen=fromEnv",
655
+ wal: "my://bla/storage?index=idx&name=test&store=wal&storekey=%40test-wal-idx%40&urlGen=fromEnv",
656
+ },
657
+ },
658
+ ],
659
+ },
660
+ ]);
661
+ });
662
+
663
+ it("check file protocol defaultURI", () => {
664
+ const gw = bs.defaultGatewayFactoryItem();
665
+ expect(gw.defaultURI(sthis).toString()).toBe(
666
+ "murks://fp",
667
+ // `file://${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`,
668
+ );
669
+ });
670
+ });