@fireproof/core 0.14.1 → 0.14.3

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.
@@ -20987,7 +20987,7 @@ var import_os = require("os");
20987
20987
  var import_promises = require("fs/promises");
20988
20988
 
20989
20989
  // src/version.ts
20990
- var PACKAGE_VERSION = "0.14.1";
20990
+ var PACKAGE_VERSION = "0.14.3";
20991
20991
 
20992
20992
  // src/store.ts
20993
20993
  var match = PACKAGE_VERSION.match(/^([^.]*\.[^.]*)/);
@@ -30142,11 +30142,9 @@ async function processFileset(blocks, files, publicFiles = false) {
30142
30142
  const dbBlockstore = blocks.parent;
30143
30143
  const t = new Transaction(dbBlockstore);
30144
30144
  const didPut = [];
30145
- let totalSize = 0;
30146
30145
  for (const filename in files) {
30147
30146
  if (File === files[filename].constructor) {
30148
30147
  const file = files[filename];
30149
- totalSize += file.size;
30150
30148
  const { cid, blocks: fileBlocks } = await encodeFile2(file);
30151
30149
  didPut.push(filename);
30152
30150
  for (const block of fileBlocks) {
@@ -30155,8 +30153,6 @@ async function processFileset(blocks, files, publicFiles = false) {
30155
30153
  files[filename] = { cid, type: file.type, size: file.size };
30156
30154
  }
30157
30155
  }
30158
- if (totalSize > 1024 * 1024 * 1)
30159
- throw new Error("Sync limit for files in a single update is 1MB");
30160
30156
  if (didPut.length) {
30161
30157
  const car = await dbBlockstore.loader?.commit(t, { files }, { public: publicFiles });
30162
30158
  if (car) {
@@ -30383,7 +30379,7 @@ var DbLoader = class _DbLoader extends Loader {
30383
30379
  this.isCompacting = true;
30384
30380
  const compactHead = this.clock.head;
30385
30381
  const compactingResult = await doCompact(blocks, this.clock.head);
30386
- await this.clock.applyHead(null, compactHead, compactHead, null);
30382
+ await this.clock.applyHead(compactHead, compactHead, null);
30387
30383
  return compactingResult;
30388
30384
  };
30389
30385
  this.compacting = this._setWaitForWrite(compactingFn);
@@ -30398,9 +30394,9 @@ var DbLoader = class _DbLoader extends Loader {
30398
30394
  }
30399
30395
  async _applyCarHeader(carHeader, snap = false) {
30400
30396
  if (snap) {
30401
- await this.clock.applyHead(null, carHeader.head, this.clock.head);
30397
+ await this.clock.applyHead(carHeader.head, this.clock.head);
30402
30398
  } else {
30403
- await this.clock.applyHead(null, carHeader.head, []);
30399
+ await this.clock.applyHead(carHeader.head, []);
30404
30400
  }
30405
30401
  }
30406
30402
  makeCarHeader(result, cars, compact = false) {
@@ -30556,7 +30552,7 @@ function applyHeadQueue(worker) {
30556
30552
  const task = queue.shift();
30557
30553
  if (!task)
30558
30554
  continue;
30559
- await worker(task.id, task.tblocks, task.newHead, task.prevHead, task.updates);
30555
+ await worker(task.id, task.newHead, task.prevHead, task.updates);
30560
30556
  if (task.updates) {
30561
30557
  allUpdates.push(...task.updates);
30562
30558
  }
@@ -30600,18 +30596,18 @@ var CRDTClock = class {
30600
30596
  setHead(head) {
30601
30597
  this.head = head;
30602
30598
  }
30603
- async applyHead(tblocks, newHead, prevHead, updates = null) {
30599
+ async applyHead(newHead, prevHead, updates = null) {
30604
30600
  const taskId = Math.random().toString().slice(2, 8);
30605
30601
  for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
30606
30602
  id: taskId,
30607
- tblocks,
30603
+ // tblocks,
30608
30604
  newHead,
30609
30605
  prevHead,
30610
30606
  updates
30611
30607
  })) {
30612
30608
  ;
30613
- (async (updatesAcc2, all2) => {
30614
- Promise.resolve().then(async () => {
30609
+ ((updatesAcc2, all2) => {
30610
+ void Promise.resolve().then(async () => {
30615
30611
  let intUpdates = updatesAcc2;
30616
30612
  if (this.watchers.size && !all2) {
30617
30613
  const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
@@ -30623,11 +30619,11 @@ var CRDTClock = class {
30623
30619
  })([...updatesAcc], all);
30624
30620
  }
30625
30621
  }
30626
- async int_applyHead(taskId, tblocks, newHead, prevHead, updates = null) {
30622
+ async int_applyHead(taskId, newHead, prevHead) {
30627
30623
  const ogHead = this.head.sort((a, b) => a.toString().localeCompare(b.toString()));
30628
30624
  newHead = newHead.sort((a, b) => a.toString().localeCompare(b.toString()));
30629
- newHead.map((cid) => {
30630
- const got = this.blocks.get(cid);
30625
+ newHead.map(async (cid) => {
30626
+ const got = await this.blocks.get(cid);
30631
30627
  if (!got) {
30632
30628
  throw new Error("int_applyHead missing block: " + cid.toString());
30633
30629
  }
@@ -30642,23 +30638,23 @@ var CRDTClock = class {
30642
30638
  }
30643
30639
  let head = this.head;
30644
30640
  const noLoader = false;
30645
- const withBlocks = async (tblocks2, fn) => {
30641
+ const withBlocks = async (fn) => {
30646
30642
  if (!this.blocks)
30647
30643
  throw new Error("missing blocks");
30648
30644
  return await this.blocks.transaction(fn, void 0, { noLoader });
30649
30645
  };
30650
- await withBlocks(tblocks, async (tblocks2) => {
30646
+ await withBlocks(async (tblocks) => {
30651
30647
  for (const cid of newHead) {
30652
30648
  try {
30653
- head = await advance(tblocks2, head, cid);
30649
+ head = await advance(tblocks, head, cid);
30654
30650
  } catch (e) {
30655
30651
  console.error("failed to advance", cid.toString(), e);
30656
30652
  continue;
30657
30653
  }
30658
30654
  }
30659
- const result = await root(tblocks2, head);
30655
+ const result = await root(tblocks, head);
30660
30656
  for (const { cid, bytes } of [...result.additions, ...result.removals]) {
30661
- tblocks2.putSync(cid, bytes);
30657
+ tblocks.putSync(cid, bytes);
30662
30658
  }
30663
30659
  return { head };
30664
30660
  });
@@ -30737,7 +30733,7 @@ var CRDT = class {
30737
30733
  }
30738
30734
  return { head };
30739
30735
  });
30740
- await this.clock.applyHead(null, got.head, prevHead, updates);
30736
+ await this.clock.applyHead(got.head, prevHead, updates);
30741
30737
  return got;
30742
30738
  })();
30743
30739
  if (loader) {
@@ -30772,7 +30768,7 @@ var CRDT = class {
30772
30768
  return await getBlock(this.blocks, cidString);
30773
30769
  }
30774
30770
  async getThatBlock() {
30775
- const blockJson = { "cid": "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", "bytes": "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
30771
+ const blockJson = { cid: "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", bytes: "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
30776
30772
  return await getThatBlock(blockJson);
30777
30773
  }
30778
30774
  async get(key) {