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

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 (103) hide show
  1. package/README.md +13 -12
  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 +3 -4
  7. package/index.cjs +1797 -1431
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +760 -381
  10. package/index.d.ts +760 -381
  11. package/index.js +1976 -913
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/{node-filesystem.cjs → index.cjs} +17 -6
  16. package/node/index.cjs.map +1 -0
  17. package/node/index.d.cts +7 -0
  18. package/node/index.d.ts +7 -0
  19. package/node/{node-filesystem.js → index.js} +25 -5
  20. package/node/index.js.map +1 -0
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +27 -17
  24. package/react/index.cjs +22 -22
  25. package/react/index.cjs.map +1 -1
  26. package/react/index.d.cts +7 -7
  27. package/react/index.d.ts +7 -7
  28. package/react/index.js +22 -22
  29. package/react/index.js.map +1 -1
  30. package/react/metafile-cjs.json +1 -1
  31. package/react/metafile-esm.json +1 -1
  32. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  33. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  34. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  35. package/tests/blockstore/keyed-crypto.test.ts +75 -118
  36. package/tests/blockstore/loader.test.ts +18 -9
  37. package/tests/blockstore/store.test.ts +40 -31
  38. package/tests/blockstore/transaction.test.ts +14 -13
  39. package/tests/fireproof/all-gateway.test.ts +286 -216
  40. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  41. package/tests/fireproof/crdt.test.ts +78 -19
  42. package/tests/fireproof/fireproof.test.ts +111 -92
  43. package/tests/fireproof/hello.test.ts +21 -17
  44. package/tests/fireproof/indexer.test.ts +74 -50
  45. package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
  46. package/tests/fireproof/multiple-ledger.test.ts +2 -2
  47. package/tests/fireproof/utils.test.ts +47 -6
  48. package/tests/gateway/file/loader-config.test.ts +307 -0
  49. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  50. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  51. package/tests/helpers.ts +44 -17
  52. package/tests/react/useFireproof.test.tsx +2 -2
  53. package/tests/www/gallery.html +2 -2
  54. package/tests/www/todo-aws.html +1 -1
  55. package/tests/www/todo-ipfs.html +1 -1
  56. package/tests/www/todo-local.html +1 -1
  57. package/tests/www/todo.html +25 -4
  58. package/web/index.cjs +218 -0
  59. package/web/index.cjs.map +1 -0
  60. package/web/index.d.cts +30 -0
  61. package/web/index.d.ts +30 -0
  62. package/web/index.js +195 -0
  63. package/web/index.js.map +1 -0
  64. package/web/metafile-cjs.json +1 -1
  65. package/web/metafile-esm.json +1 -1
  66. package/chunk-7EWIAXTM.js +0 -7
  67. package/chunk-7EWIAXTM.js.map +0 -1
  68. package/chunk-F4FC6B2T.js +0 -63
  69. package/chunk-F4FC6B2T.js.map +0 -1
  70. package/chunk-PZ5AY32C.js +0 -10
  71. package/chunk-PZ5AY32C.js.map +0 -1
  72. package/chunk-RXC4JGJT.js +0 -301
  73. package/chunk-RXC4JGJT.js.map +0 -1
  74. package/gateway-C62S56GY.js +0 -66
  75. package/gateway-C62S56GY.js.map +0 -1
  76. package/gateway-VVS4QWDA.js +0 -145
  77. package/gateway-VVS4QWDA.js.map +0 -1
  78. package/key-bag-file-PWZ3QE7B.js +0 -55
  79. package/key-bag-file-PWZ3QE7B.js.map +0 -1
  80. package/key-bag-indexdb-SYG3YD4D.js +0 -51
  81. package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
  82. package/node/chunk-4A4RAVNS.js +0 -17
  83. package/node/chunk-4A4RAVNS.js.map +0 -1
  84. package/node/mem-filesystem.cjs +0 -72
  85. package/node/mem-filesystem.cjs.map +0 -1
  86. package/node/mem-filesystem.d.cts +0 -25
  87. package/node/mem-filesystem.d.ts +0 -25
  88. package/node/mem-filesystem.js +0 -40
  89. package/node/mem-filesystem.js.map +0 -1
  90. package/node/node-filesystem.cjs.map +0 -1
  91. package/node/node-filesystem.d.cts +0 -35
  92. package/node/node-filesystem.d.ts +0 -35
  93. package/node/node-filesystem.js.map +0 -1
  94. package/tests/fireproof/config.test.ts +0 -172
  95. package/utils-ZVVGAXFE.js +0 -13
  96. package/utils-ZVVGAXFE.js.map +0 -1
  97. package/web/gateway-impl.cjs +0 -183
  98. package/web/gateway-impl.cjs.map +0 -1
  99. package/web/gateway-impl.d.cts +0 -31
  100. package/web/gateway-impl.d.ts +0 -31
  101. package/web/gateway-impl.js +0 -162
  102. package/web/gateway-impl.js.map +0 -1
  103. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
@@ -1,4 +1,4 @@
1
- import { CRDT, ensureSuperThis } from "@fireproof/core";
1
+ import { CRDT, defaultWriteQueueOpts, ensureSuperThis, LedgerOpts, 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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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: LedgerOpts = {
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" } }]);