@fireproof/core 0.21.0-dev-preview-6 → 0.21.0-dev-preview-7

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 (137) hide show
  1. package/blockstore/attachable-store.d.ts.map +1 -1
  2. package/blockstore/attachable-store.js +4 -5
  3. package/blockstore/attachable-store.js.map +1 -1
  4. package/blockstore/index.d.ts +2 -1
  5. package/blockstore/index.d.ts.map +1 -1
  6. package/blockstore/index.js +2 -1
  7. package/blockstore/index.js.map +1 -1
  8. package/blockstore/loader.d.ts +2 -1
  9. package/blockstore/loader.d.ts.map +1 -1
  10. package/blockstore/loader.js +41 -11
  11. package/blockstore/loader.js.map +1 -1
  12. package/blockstore/store.js +1 -1
  13. package/blockstore/store.js.map +1 -1
  14. package/blockstore/types.d.ts +0 -2
  15. package/blockstore/types.d.ts.map +1 -1
  16. package/blockstore/types.js.map +1 -1
  17. package/cli/main.js +112 -80
  18. package/database.d.ts +0 -1
  19. package/database.d.ts.map +1 -1
  20. package/database.js +0 -1
  21. package/database.js.map +1 -1
  22. package/deno.json +2 -2
  23. package/ledger.d.ts +3 -2
  24. package/ledger.d.ts.map +1 -1
  25. package/ledger.js +16 -19
  26. package/ledger.js.map +1 -1
  27. package/package.json +3 -4
  28. package/protocols/cloud/http-connection.d.ts +2 -1
  29. package/protocols/cloud/http-connection.d.ts.map +1 -1
  30. package/protocols/cloud/http-connection.js +1 -0
  31. package/protocols/cloud/http-connection.js.map +1 -1
  32. package/protocols/cloud/msg-types-data.d.ts +4 -4
  33. package/protocols/cloud/msg-types-data.d.ts.map +1 -1
  34. package/protocols/cloud/msg-types-data.js.map +1 -1
  35. package/protocols/cloud/msg-types-meta.d.ts +13 -13
  36. package/protocols/cloud/msg-types-meta.d.ts.map +1 -1
  37. package/protocols/cloud/msg-types-meta.js.map +1 -1
  38. package/protocols/cloud/msg-types-wal.d.ts +4 -4
  39. package/protocols/cloud/msg-types-wal.d.ts.map +1 -1
  40. package/protocols/cloud/msg-types-wal.js.map +1 -1
  41. package/protocols/cloud/msg-types.d.ts +33 -19
  42. package/protocols/cloud/msg-types.d.ts.map +1 -1
  43. package/protocols/cloud/msg-types.js +4 -1
  44. package/protocols/cloud/msg-types.js.map +1 -1
  45. package/protocols/cloud/msger.d.ts +54 -39
  46. package/protocols/cloud/msger.d.ts.map +1 -1
  47. package/protocols/cloud/msger.js +228 -107
  48. package/protocols/cloud/msger.js.map +1 -1
  49. package/protocols/cloud/ws-connection.d.ts +14 -3
  50. package/protocols/cloud/ws-connection.d.ts.map +1 -1
  51. package/protocols/cloud/ws-connection.js +73 -34
  52. package/protocols/cloud/ws-connection.js.map +1 -1
  53. package/protocols/dashboard/index.d.ts +4 -0
  54. package/protocols/dashboard/index.d.ts.map +1 -0
  55. package/protocols/dashboard/index.js +4 -0
  56. package/protocols/dashboard/index.js.map +1 -0
  57. package/protocols/dashboard/msg-api.d.ts +11 -0
  58. package/protocols/dashboard/msg-api.d.ts.map +1 -0
  59. package/protocols/dashboard/msg-api.js +55 -0
  60. package/protocols/dashboard/msg-api.js.map +1 -0
  61. package/protocols/dashboard/msg-is.d.ts +45 -0
  62. package/protocols/dashboard/msg-is.d.ts.map +1 -0
  63. package/protocols/dashboard/msg-is.js +63 -0
  64. package/protocols/dashboard/msg-is.js.map +1 -0
  65. package/protocols/dashboard/msg-types.d.ts +397 -0
  66. package/protocols/dashboard/msg-types.d.ts.map +1 -0
  67. package/protocols/dashboard/msg-types.js +4 -0
  68. package/protocols/dashboard/msg-types.js.map +1 -0
  69. package/protocols/index.d.ts +1 -0
  70. package/protocols/index.d.ts.map +1 -1
  71. package/protocols/index.js +1 -0
  72. package/protocols/index.js.map +1 -1
  73. package/react/types.d.ts +28 -8
  74. package/react/types.d.ts.map +1 -1
  75. package/react/use-attach.d.ts +9 -4
  76. package/react/use-attach.d.ts.map +1 -1
  77. package/react/use-attach.js +137 -43
  78. package/react/use-attach.js.map +1 -1
  79. package/react/use-fireproof.js +2 -2
  80. package/react/use-fireproof.js.map +1 -1
  81. package/runtime/gateways/cloud/gateway.d.ts +8 -8
  82. package/runtime/gateways/cloud/gateway.d.ts.map +1 -1
  83. package/runtime/gateways/cloud/gateway.js +17 -15
  84. package/runtime/gateways/cloud/gateway.js.map +1 -1
  85. package/runtime/gateways/cloud/to-cloud.d.ts +22 -9
  86. package/runtime/gateways/cloud/to-cloud.d.ts.map +1 -1
  87. package/runtime/gateways/cloud/to-cloud.js +75 -59
  88. package/runtime/gateways/cloud/to-cloud.js.map +1 -1
  89. package/runtime/gateways/file/key-bag-file.d.ts +1 -0
  90. package/runtime/gateways/file/key-bag-file.d.ts.map +1 -1
  91. package/runtime/gateways/file/key-bag-file.js +12 -0
  92. package/runtime/gateways/file/key-bag-file.js.map +1 -1
  93. package/runtime/gateways/indexeddb/gateway-impl.d.ts.map +1 -1
  94. package/runtime/gateways/indexeddb/gateway-impl.js.map +1 -1
  95. package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts +1 -0
  96. package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +1 -1
  97. package/runtime/gateways/indexeddb/key-bag-indexeddb.js +6 -0
  98. package/runtime/gateways/indexeddb/key-bag-indexeddb.js.map +1 -1
  99. package/runtime/key-bag-memory.d.ts +1 -0
  100. package/runtime/key-bag-memory.d.ts.map +1 -1
  101. package/runtime/key-bag-memory.js +7 -0
  102. package/runtime/key-bag-memory.js.map +1 -1
  103. package/runtime/key-bag.d.ts +3 -0
  104. package/runtime/key-bag.d.ts.map +1 -1
  105. package/runtime/key-bag.js +6 -0
  106. package/runtime/key-bag.js.map +1 -1
  107. package/runtime/keyed-crypto.d.ts.map +1 -1
  108. package/runtime/keyed-crypto.js +5 -5
  109. package/runtime/keyed-crypto.js.map +1 -1
  110. package/tests/blockstore/keyed-crypto.test.ts +0 -150
  111. package/tests/blockstore/loader.test.ts +3 -2
  112. package/tests/blockstore/standalone.test.ts +1 -1
  113. package/tests/blockstore/transaction.test.ts +3 -3
  114. package/tests/fireproof/attachable.test.ts +1 -1
  115. package/tests/helpers.ts +7 -9
  116. package/tests/protocols/cloud/msger.test.ts +548 -0
  117. package/tests/react/use-all-docs.test.tsx +1 -2
  118. package/tests/react/use-fireproof-stability.test.tsx +1 -1
  119. package/types.d.ts +1 -2
  120. package/types.d.ts.map +1 -1
  121. package/use-fireproof/iframe-strategy.d.ts +5 -4
  122. package/use-fireproof/iframe-strategy.d.ts.map +1 -1
  123. package/use-fireproof/iframe-strategy.js +7 -11
  124. package/use-fireproof/iframe-strategy.js.map +1 -1
  125. package/use-fireproof/index.d.ts +6 -2
  126. package/use-fireproof/index.d.ts.map +1 -1
  127. package/use-fireproof/index.js +23 -3
  128. package/use-fireproof/index.js.map +1 -1
  129. package/use-fireproof/redirect-strategy.d.ts +11 -4
  130. package/use-fireproof/redirect-strategy.d.ts.map +1 -1
  131. package/use-fireproof/redirect-strategy.js +142 -20
  132. package/use-fireproof/redirect-strategy.js.map +1 -1
  133. package/utils.d.ts +5 -6
  134. package/utils.d.ts.map +1 -1
  135. package/utils.js +19 -67
  136. package/utils.js.map +1 -1
  137. package/tests/utils.test.ts +0 -192
@@ -1,7 +1,6 @@
1
1
  import { bs, ensureSuperThis, PARAM, rt, StoreType, storeType2DataMetaWal } from "@fireproof/core";
2
2
  import { BuildURI, LogCollector, runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
3
3
  import { base58btc } from "multiformats/bases/base58";
4
- import { CID } from "multiformats/cid";
5
4
  // import { sha256 as hasher } from "multiformats/hashes/sha2";
6
5
  // import * as dagCodec from "@ipld/dag-cbor";
7
6
  import * as cborg from "cborg";
@@ -325,155 +324,6 @@ describe("KeyedCryptoStore", () => {
325
324
  expect(dec).toEqual(testData);
326
325
  }
327
326
  });
328
-
329
- it("public: true results in insecure STORE_KEY and noCrypto", async () => {
330
- if (!baseUrl) {
331
- throw new Error("baseUrl not initialized. Check test setup.");
332
- }
333
- if (!kb) {
334
- throw new Error("kb not initialized. Check test setup.");
335
- }
336
-
337
- const testDbName = "testDbPublic";
338
- const mockStethis = mockSuperThis();
339
- await mockStethis.start();
340
-
341
- // DbMeta only has 'cars' property. A CarGroup is Car[], so an empty array is a valid empty CarGroup.
342
- const dbMeta: bs.DbMeta = { cars: [] };
343
-
344
- // Constructing storeUrls with 'insecure' for public: true
345
- const metaUri = baseUrl
346
- .build()
347
- .setParam(PARAM.NAME, `${testDbName}-meta`)
348
- .setParam(PARAM.STORE, "meta" as StoreType)
349
- .setParam(PARAM.STORE_KEY, "insecure")
350
- .URI();
351
- const carUri = baseUrl
352
- .build()
353
- .setParam(PARAM.NAME, `${testDbName}-car`)
354
- .setParam(PARAM.STORE, "car" as StoreType)
355
- .setParam(PARAM.STORE_KEY, "insecure")
356
- .URI();
357
- const fileUri = baseUrl
358
- .build()
359
- .setParam(PARAM.NAME, `${testDbName}-file`)
360
- .setParam(PARAM.STORE, "file" as StoreType)
361
- .setParam(PARAM.STORE_KEY, "insecure")
362
- .URI();
363
- const walUri = baseUrl
364
- .build()
365
- .setParam(PARAM.NAME, `${testDbName}-wal`)
366
- .setParam(PARAM.STORE, "wal" as StoreType)
367
- .setParam(PARAM.STORE_KEY, "insecure")
368
- .URI();
369
-
370
- const insecureStoreUrls: bs.StoreURIs = {
371
- meta: metaUri,
372
- car: carUri,
373
- file: fileUri,
374
- wal: walUri,
375
- };
376
-
377
- const bsOpts: bs.BlockstoreOpts = {
378
- public: true,
379
- storeUrls: insecureStoreUrls, // Use the correctly configured insecure URLs
380
- keyBag: kb.rt,
381
- meta: dbMeta,
382
- compact: async () => ({
383
- car: CID.parse("bafyreibv2h6gs6lgjpmwj2k2qflgsemg32ufoq2t3r24g7myr5gc5a2vta"),
384
- blocks: [],
385
- size: 0,
386
- meta: CID.parse("bafyreibv2h6gs6lgjpmwj2k2qflgsemg32ufoq2t3r24g7myr5gc5a2vta"),
387
- }),
388
- autoCompact: 0,
389
- crypto: toCryptoRuntime(),
390
- threshold: 10,
391
- taskManager: { removeAfter: 3, retryTimeout: 50 },
392
- storeRuntime: bs.toStoreRuntime(mockStethis, {}),
393
- tracer: () => {
394
- /* noop */
395
- },
396
- logger: mockStethis.logger,
397
- applyMeta: async () => Promise.resolve(),
398
- };
399
-
400
- const encBlockstore = new bs.EncryptedBlockstore(mockStethis, bsOpts);
401
-
402
- expect(encBlockstore.loader.ebOpts.storeUrls.meta.getParam(PARAM.STORE_KEY), "Meta store URL's STORE_KEY in loader opts").toBe(
403
- "insecure",
404
- );
405
- expect(encBlockstore.loader.ebOpts.storeUrls.car.getParam(PARAM.STORE_KEY), "Car store URL's STORE_KEY in loader opts").toBe(
406
- "insecure",
407
- );
408
- expect(encBlockstore.loader.ebOpts.storeUrls.file.getParam(PARAM.STORE_KEY), "File store URL's STORE_KEY in loader opts").toBe(
409
- "insecure",
410
- );
411
- expect(encBlockstore.loader.ebOpts.storeUrls.wal.getParam(PARAM.STORE_KEY), "Wal store URL's STORE_KEY in loader opts").toBe(
412
- "insecure",
413
- );
414
-
415
- const storeFactoryItem: bs.StoreFactoryItem = {
416
- loader: encBlockstore.loader,
417
- byStore: {
418
- meta: { url: encBlockstore.loader.ebOpts.storeUrls.meta },
419
- car: { url: encBlockstore.loader.ebOpts.storeUrls.car },
420
- file: { url: encBlockstore.loader.ebOpts.storeUrls.file },
421
- wal: { url: encBlockstore.loader.ebOpts.storeUrls.wal },
422
- },
423
- };
424
- const stores = await encBlockstore.loader.ebOpts.storeRuntime.makeStores(storeFactoryItem);
425
-
426
- const resolvedMetaStore = stores.meta;
427
- expect(resolvedMetaStore.url().getParam(PARAM.STORE_KEY), "Resolved meta store's STORE_KEY").toBe("insecure");
428
- let kc = await resolvedMetaStore.keyedCrypto();
429
- expect(kc.constructor.name).toBe("noCrypto");
430
-
431
- const resolvedCarStore = stores.car;
432
- expect(resolvedCarStore.url().getParam(PARAM.STORE_KEY), "Resolved car store's STORE_KEY").toBe("insecure");
433
- kc = await resolvedCarStore.keyedCrypto();
434
- expect(kc.constructor.name).toBe("noCrypto");
435
-
436
- const resolvedFileStore = stores.file;
437
- expect(resolvedFileStore).toBeDefined();
438
- if (resolvedFileStore) {
439
- expect(resolvedFileStore.url().getParam(PARAM.STORE_KEY), "Resolved file store's STORE_KEY").toBe("insecure");
440
- kc = await resolvedFileStore.keyedCrypto();
441
- expect(kc.constructor.name).toBe("noCrypto");
442
- }
443
-
444
- const resolvedWalStore = stores.wal;
445
- expect(resolvedWalStore).toBeDefined();
446
- if (resolvedWalStore) {
447
- expect(resolvedWalStore.url().getParam(PARAM.STORE_KEY), "Resolved wal store's STORE_KEY").toBe("insecure");
448
- kc = await resolvedWalStore.keyedCrypto(); // kc is now from WAL store if it exists
449
- expect(kc.constructor.name).toBe("noCrypto");
450
- }
451
-
452
- // Test noCrypto's _encrypt and _decrypt behavior (currently throws)
453
- // Use the latest 'kc' which would be from WAL store if present, or File, or Car, or Meta.
454
- // All should be noCrypto instances in this test case.
455
- const testData = kb.rt.crypto.randomBytes(1024);
456
- const iv = kb.rt.crypto.randomBytes(12);
457
- // Test noCrypto's key.get() behavior (currently throws)
458
- await expect(kc.key.get()).resolves.toBeUndefined();
459
-
460
- // Test noCrypto's _encrypt behavior (currently throws)
461
- // Since key.get() throws, we can't get a real key. _encrypt in noCrypto also throws and doesn't use the key.
462
- // The key parameter in _encrypt is optional, so we can pass undefined or a dummy.
463
- const dummyCryptoKey: CryptoKey = {
464
- algorithm: { name: "NONE" }, // Or simply {} if that's too specific
465
- extractable: false,
466
- type: "secret",
467
- usages: [], // CryptoKeyUsage[]
468
- };
469
- // For public databases, noCrypto now returns the bytes unchanged instead of throwing
470
- const encryptedData = await kc._encrypt({ bytes: testData, key: dummyCryptoKey, iv });
471
- expect(encryptedData).toEqual(testData); // Expect the same bytes to be returned
472
-
473
- // Test decrypt also returns the original bytes
474
- const decryptedData = await kc._decrypt({ bytes: testData, key: dummyCryptoKey, iv });
475
- expect(decryptedData).toEqual(testData);
476
- });
477
327
  });
478
328
 
479
329
  describe("KeyedCrypto", () => {
@@ -3,8 +3,9 @@ import { sha256 as hasher } from "multiformats/hashes/sha2";
3
3
  import { CID } from "multiformats/cid";
4
4
  import { CRDTMeta, CarTransaction, IndexTransactionMeta, SuperThis, bs, ensureSuperThis, rt } from "@fireproof/core";
5
5
  import { simpleBlockOpts } from "../helpers.js";
6
- import { FPBlock, isCarBlockItemReady, isCarBlockItemStale } from "../../src/blockstore/index.js";
7
- import { anyBlock2FPBlock } from "../../src/blockstore/loader-helpers.js";
6
+
7
+ const { isCarBlockItemReady, isCarBlockItemStale, anyBlock2FPBlock } = bs;
8
+ type FPBlock = bs.FPBlock;
8
9
 
9
10
  class MyMemoryBlockStore extends bs.EncryptedBlockstore {
10
11
  readonly memblock = new Map<string, FPBlock>();
@@ -2,7 +2,7 @@ import { BuildURI, runtimeFn, URI } from "@adviser/cement";
2
2
  import { ensureSuperThis, PARAM, CRDTImpl, CRDT, LedgerOpts, fireproof, bs, sleep } from "@fireproof/core";
3
3
  import { Link } from "multiformats";
4
4
  import { stripper } from "@adviser/cement/utils";
5
- import pLimit from "p-limit";
5
+ import pLimit from "@fireproof/vendor/p-limit";
6
6
 
7
7
  describe("standalone", () => {
8
8
  const sthis = ensureSuperThis();
@@ -1,10 +1,10 @@
1
1
  import { CID } from "multiformats";
2
2
  import { BaseBlockstore, bs, CarTransaction, ensureSuperThis } from "@fireproof/core";
3
3
  import { simpleBlockOpts } from "../helpers.js";
4
- import { anyBlock2FPBlock } from "../../src/blockstore/loader-helpers.js";
5
- import { AnyLink } from "../../src/blockstore/index.js";
6
4
  import { to_uint8 } from "@adviser/cement";
7
5
 
6
+ const { anyBlock2FPBlock } = bs;
7
+
8
8
  describe("Fresh TransactionBlockstore", function () {
9
9
  let blocks: BaseBlockstore;
10
10
  const sthis = ensureSuperThis();
@@ -20,7 +20,7 @@ describe("Fresh TransactionBlockstore", function () {
20
20
  // });
21
21
  it("should not put", async () => {
22
22
  const value = sthis.txt.encode("value");
23
- const e = await blocks.put(await anyBlock2FPBlock({ cid: "key" as unknown as AnyLink, bytes: value })).catch((e) => e);
23
+ const e = await blocks.put(await anyBlock2FPBlock({ cid: "key" as unknown as bs.AnyLink, bytes: value })).catch((e) => e);
24
24
  expect(e.message).toMatch(/transaction/g);
25
25
  });
26
26
  it("should yield a transaction", async () => {
@@ -530,7 +530,7 @@ describe("sync", () => {
530
530
  );
531
531
 
532
532
  // await waitIdle.wait(dbs);
533
- await sleep(500);
533
+ await sleep(1000);
534
534
  await Promise.all(
535
535
  dbs.map(async (tdb) => {
536
536
  const rows = await tdb.db.allDocs();
package/tests/helpers.ts CHANGED
@@ -14,8 +14,6 @@ import {
14
14
  import { CID } from "multiformats";
15
15
  import { sha256 } from "multiformats/hashes/sha2";
16
16
  import * as json from "multiformats/codecs/json";
17
- import { CarBlockItem, CarGroup, FPBlock } from "../src/blockstore/index.js";
18
- import { CommitQueue } from "../src/blockstore/commit-queue.js";
19
17
 
20
18
  /* eslint-disable @typescript-eslint/no-empty-function */
21
19
  export function tracer() {}
@@ -97,7 +95,7 @@ class MockLoader implements bs.Loadable {
97
95
  readonly carLog: bs.CarLog;
98
96
  readonly attachedStores: bs.AttachedStores;
99
97
  readonly taskManager: bs.TaskManager;
100
- readonly commitQueue: CommitQueue<unknown>;
98
+ readonly commitQueue: bs.CommitQueue<unknown>;
101
99
 
102
100
  constructor(sthis: SuperThis) {
103
101
  this.sthis = sthis;
@@ -118,7 +116,7 @@ class MockLoader implements bs.Loadable {
118
116
  retryTimeout: 50,
119
117
  });
120
118
  this.attachedStores = new bs.AttachedRemotesImpl(this);
121
- this.commitQueue = new CommitQueue({
119
+ this.commitQueue = new bs.CommitQueue({
122
120
  tracer,
123
121
  });
124
122
  }
@@ -137,7 +135,7 @@ class MockLoader implements bs.Loadable {
137
135
  return rt.kb.getKeyBag(this.sthis, {});
138
136
  }
139
137
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
140
- handleDbMetasFromStore(metas: bs.DbMeta[], store: bs.ActiveStore): Promise<CarGroup> {
138
+ handleDbMetasFromStore(metas: bs.DbMeta[], store: bs.ActiveStore): Promise<bs.CarGroup> {
141
139
  // throw new Error("Method not implemented.");
142
140
  return Promise.resolve([]);
143
141
  }
@@ -149,15 +147,15 @@ class MockLoader implements bs.Loadable {
149
147
  throw new Error("Method not implemented.");
150
148
  }
151
149
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
152
- getBlock(cid: bs.AnyLink, store: bs.ActiveStore): Promise<FPBlock | Falsy> {
150
+ getBlock(cid: bs.AnyLink, store: bs.ActiveStore): Promise<bs.FPBlock | Falsy> {
153
151
  throw new Error("Method not implemented.");
154
152
  }
155
153
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
156
- loadFileCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<FPBlock<CarBlockItem>> {
154
+ loadFileCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<bs.FPBlock<bs.CarBlockItem>> {
157
155
  throw new Error("Method not implemented.");
158
156
  }
159
157
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
160
- loadCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<FPBlock<CarBlockItem>> {
158
+ loadCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<bs.FPBlock<bs.CarBlockItem>> {
161
159
  throw new Error("Method not implemented.");
162
160
  }
163
161
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -165,7 +163,7 @@ class MockLoader implements bs.Loadable {
165
163
  throw new Error("Method not implemented.");
166
164
  }
167
165
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
168
- entries(cache?: boolean): AsyncIterableIterator<FPBlock> {
166
+ entries(cache?: boolean): AsyncIterableIterator<bs.FPBlock> {
169
167
  throw new Error("Method not implemented.");
170
168
  }
171
169
  }