@fireproof/core 0.17.3 → 0.17.4

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.
@@ -9875,8 +9875,7 @@ You can use close({ resize: true }) to resize header`);
9875
9875
  return uint8Array;
9876
9876
  }
9877
9877
  async function encryptedEncodeCarFile(crypto2, key, rootCid, t) {
9878
- const encryptionKeyUint8 = hexStringToUint8Array(key);
9879
- const encryptionKey = encryptionKeyUint8.buffer.slice(0, encryptionKeyUint8.byteLength);
9878
+ const encryptionKey = hexStringToUint8Array(key);
9880
9879
  const encryptedBlocks = new MemoryBlockstore();
9881
9880
  const cidsToEncrypt = [];
9882
9881
  for (const { cid } of t.entries()) {
@@ -9953,7 +9952,7 @@ You can use close({ resize: true }) to resize header`);
9953
9952
  }
9954
9953
  return bytes;
9955
9954
  }
9956
- var PACKAGE_VERSION = "0.16.10";
9955
+ var PACKAGE_VERSION = "0.17.3";
9957
9956
  var match = PACKAGE_VERSION.match(/^([^.]*\.[^.]*)/);
9958
9957
  if (!match)
9959
9958
  throw new Error("invalid version: " + PACKAGE_VERSION);
@@ -10029,11 +10028,11 @@ You can use close({ resize: true }) to resize header`);
10029
10028
  constructor(name7, ebOpts) {
10030
10029
  this.name = name7;
10031
10030
  this.ebOpts = ebOpts;
10032
- this.metaStore = new ebOpts.store.MetaStore(this.name);
10033
- this.carStore = new ebOpts.store.DataStore(this.name);
10034
- this.fileStore = new ebOpts.store.DataStore(this.name);
10035
- this.remoteWAL = new ebOpts.store.RemoteWAL(this);
10031
+ this.carStore = ebOpts.store.makeDataStore(this.name);
10032
+ this.fileStore = ebOpts.store.makeDataStore(this.name);
10033
+ this.remoteWAL = ebOpts.store.makeRemoteWAL(this);
10036
10034
  this.ready = Promise.resolve().then(async () => {
10035
+ this.metaStore = ebOpts.store.makeMetaStore(this);
10037
10036
  if (!this.metaStore || !this.carStore || !this.remoteWAL)
10038
10037
  throw new Error("stores not initialized");
10039
10038
  const metas = this.ebOpts.meta ? [this.ebOpts.meta] : await this.metaStore.load("main");
@@ -10207,19 +10206,30 @@ You can use close({ resize: true }) to resize header`);
10207
10206
  const sCid = cid.toString();
10208
10207
  if (this.getBlockCache.has(sCid))
10209
10208
  return this.getBlockCache.get(sCid);
10210
- const got = await Promise.any(
10211
- // maybe worth taking this in chunks of 5? to allow cache to favor recent files, carLog order is newest first
10212
- this.carLog.map(async (carCid) => {
10213
- const reader = await this.loadCar(carCid);
10214
- if (!reader) {
10215
- throw new Error(`missing car reader ${carCid.toString()}`);
10216
- }
10217
- await this.cacheCarReader(reader);
10218
- if (this.getBlockCache.has(sCid))
10219
- return this.getBlockCache.get(sCid);
10220
- throw new Error(`block not in reader: ${cid.toString()}`);
10221
- })
10222
- ).catch(() => void 0);
10209
+ const getCarCid = async (carCid) => {
10210
+ const reader = await this.loadCar(carCid);
10211
+ if (!reader) {
10212
+ throw new Error(`missing car reader ${carCid.toString()}`);
10213
+ }
10214
+ await this.cacheCarReader(reader);
10215
+ if (this.getBlockCache.has(sCid))
10216
+ return this.getBlockCache.get(sCid);
10217
+ throw new Error(`block not in reader: ${cid.toString()}`);
10218
+ };
10219
+ let got;
10220
+ const batchSize = 5;
10221
+ for (let i = 0; i < this.carLog.length; i += batchSize) {
10222
+ const promises = [];
10223
+ for (let j = i; j < Math.min(i + batchSize, this.carLog.length); j++) {
10224
+ promises.push(getCarCid(this.carLog[j]));
10225
+ }
10226
+ try {
10227
+ got = await Promise.any(promises);
10228
+ } catch {
10229
+ }
10230
+ if (got)
10231
+ break;
10232
+ }
10223
10233
  if (got) {
10224
10234
  this.getBlockCache.set(sCid, got);
10225
10235
  }
@@ -10460,14 +10470,6 @@ You can use close({ resize: true }) to resize header`);
10460
10470
  return bytes;
10461
10471
  }
10462
10472
 
10463
- // ../encrypted-blockstore/dist/lib/store-web.js
10464
- var store_web_exports = {};
10465
- __export(store_web_exports, {
10466
- DataStore: () => DataStore2,
10467
- MetaStore: () => MetaStore2,
10468
- RemoteWAL: () => RemoteWAL2
10469
- });
10470
-
10471
10473
  // ../../node_modules/.pnpm/idb@7.1.1/node_modules/idb/build/wrap-idb-value.js
10472
10474
  var instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
10473
10475
  var idbProxyableTypes;
@@ -10676,7 +10678,7 @@ You can use close({ resize: true }) to resize header`);
10676
10678
  }));
10677
10679
 
10678
10680
  // ../encrypted-blockstore/dist/lib/store-web.js
10679
- var PACKAGE_VERSION2 = "0.16.10";
10681
+ var PACKAGE_VERSION2 = "0.17.3";
10680
10682
  var match2 = PACKAGE_VERSION2.match(/^([^.]*\.[^.]*)/);
10681
10683
  if (!match2)
10682
10684
  throw new Error("invalid version: " + PACKAGE_VERSION2);
@@ -10764,14 +10766,14 @@ You can use close({ resize: true }) to resize header`);
10764
10766
  processQueue = new CommitQueue2();
10765
10767
  constructor(loader) {
10766
10768
  this.loader = loader;
10767
- this.ready = (async () => {
10769
+ this.ready = Promise.resolve().then(async () => {
10768
10770
  const walState = await this.load().catch((e) => {
10769
10771
  console.error("error loading wal", e);
10770
10772
  return null;
10771
10773
  });
10772
10774
  this.walState.operations = walState?.operations || [];
10773
10775
  this.walState.fileOperations = walState?.fileOperations || [];
10774
- })();
10776
+ });
10775
10777
  }
10776
10778
  async enqueue(dbMeta, opts) {
10777
10779
  await this.ready;
@@ -10870,6 +10872,9 @@ You can use close({ resize: true }) to resize header`);
10870
10872
  await rmlp;
10871
10873
  }
10872
10874
  };
10875
+ var makeDataStore = (name7) => new DataStore2(name7);
10876
+ var makeMetaStore = (loader) => new MetaStore2(loader.name);
10877
+ var makeRemoteWAL = (loader) => new RemoteWAL2(loader);
10873
10878
  var DataStore2 = class extends DataStore {
10874
10879
  tag = "car-web-idb";
10875
10880
  idb = null;
@@ -10964,6 +10969,13 @@ You can use close({ resize: true }) to resize header`);
10964
10969
  }
10965
10970
  };
10966
10971
 
10972
+ // src/eb-web.ts
10973
+ var store = {
10974
+ makeDataStore,
10975
+ makeMetaStore,
10976
+ makeRemoteWAL
10977
+ };
10978
+
10967
10979
  // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/clock/index.js
10968
10980
  var advance = async (blocks, head, event) => {
10969
10981
  const events = new EventFetcher(blocks);
@@ -11038,6 +11050,7 @@ You can use close({ resize: true }) to resize header`);
11038
11050
  return true;
11039
11051
  const [{ value: aevent }, { value: bevent }] = await Promise.all([events.get(a), events.get(b)]);
11040
11052
  const links3 = [...aevent.parents];
11053
+ const seen = /* @__PURE__ */ new Set();
11041
11054
  while (links3.length) {
11042
11055
  const link2 = links3.shift();
11043
11056
  if (!link2)
@@ -11046,6 +11059,9 @@ You can use close({ resize: true }) to resize header`);
11046
11059
  return true;
11047
11060
  if (bevent.parents.some((p) => link2.toString() === p.toString()))
11048
11061
  continue;
11062
+ if (seen.has(link2.toString()))
11063
+ continue;
11064
+ seen.add(link2.toString());
11049
11065
  const { value: event } = await events.get(link2);
11050
11066
  links3.push(...event.parents);
11051
11067
  }
@@ -20611,6 +20627,7 @@ You can use close({ resize: true }) to resize header`);
20611
20627
  if (!block)
20612
20628
  throw new Error(`Missing linked block ${link2.toString()}`);
20613
20629
  const { value } = await decode11({ bytes: block.bytes, hasher: sha256, codec: src_exports });
20630
+ value.cid = link2;
20614
20631
  readFiles(blocks, value);
20615
20632
  return value;
20616
20633
  }
@@ -21562,8 +21579,8 @@ You can use close({ resize: true }) to resize header`);
21562
21579
  return { head: this.clock.head };
21563
21580
  },
21564
21581
  autoCompact: this.opts.autoCompact || 100,
21565
- crypto: crypto_web_exports,
21566
- store: store_web_exports,
21582
+ crypto: this.opts.crypto || crypto_web_exports,
21583
+ store: this.opts.store || store,
21567
21584
  public: this.opts.public,
21568
21585
  meta: this.opts.meta
21569
21586
  });
@@ -21578,7 +21595,7 @@ You can use close({ resize: true }) to resize header`);
21578
21595
  },
21579
21596
  crypto: crypto_web_exports,
21580
21597
  public: this.opts.public,
21581
- store: store_web_exports
21598
+ store
21582
21599
  });
21583
21600
  this.ready = Promise.all([this.blockstore.ready, this.indexBlockstore.ready]).then(() => {
21584
21601
  });