@fireproof/core 0.14.1 → 0.14.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11605,7 +11605,7 @@ replaceTraps((oldTraps) => ({
11605
11605
  }));
11606
11606
 
11607
11607
  // src/version.ts
11608
- var PACKAGE_VERSION = "0.14.1";
11608
+ var PACKAGE_VERSION = "0.14.3";
11609
11609
 
11610
11610
  // src/store.ts
11611
11611
  var match = PACKAGE_VERSION.match(/^([^.]*\.[^.]*)/);
@@ -20808,11 +20808,9 @@ async function processFileset(blocks, files, publicFiles = false) {
20808
20808
  const dbBlockstore = blocks.parent;
20809
20809
  const t = new Transaction(dbBlockstore);
20810
20810
  const didPut = [];
20811
- let totalSize = 0;
20812
20811
  for (const filename in files) {
20813
20812
  if (File === files[filename].constructor) {
20814
20813
  const file = files[filename];
20815
- totalSize += file.size;
20816
20814
  const { cid, blocks: fileBlocks } = await encodeFile2(file);
20817
20815
  didPut.push(filename);
20818
20816
  for (const block of fileBlocks) {
@@ -20821,8 +20819,6 @@ async function processFileset(blocks, files, publicFiles = false) {
20821
20819
  files[filename] = { cid, type: file.type, size: file.size };
20822
20820
  }
20823
20821
  }
20824
- if (totalSize > 1024 * 1024 * 1)
20825
- throw new Error("Sync limit for files in a single update is 1MB");
20826
20822
  if (didPut.length) {
20827
20823
  const car = await dbBlockstore.loader?.commit(t, { files }, { public: publicFiles });
20828
20824
  if (car) {
@@ -21048,7 +21044,7 @@ var _DbLoader = class _DbLoader extends Loader {
21048
21044
  this.isCompacting = true;
21049
21045
  const compactHead = this.clock.head;
21050
21046
  const compactingResult = await doCompact(blocks, this.clock.head);
21051
- await this.clock.applyHead(null, compactHead, compactHead, null);
21047
+ await this.clock.applyHead(compactHead, compactHead, null);
21052
21048
  return compactingResult;
21053
21049
  };
21054
21050
  this.compacting = this._setWaitForWrite(compactingFn);
@@ -21063,9 +21059,9 @@ var _DbLoader = class _DbLoader extends Loader {
21063
21059
  }
21064
21060
  async _applyCarHeader(carHeader, snap = false) {
21065
21061
  if (snap) {
21066
- await this.clock.applyHead(null, carHeader.head, this.clock.head);
21062
+ await this.clock.applyHead(carHeader.head, this.clock.head);
21067
21063
  } else {
21068
- await this.clock.applyHead(null, carHeader.head, []);
21064
+ await this.clock.applyHead(carHeader.head, []);
21069
21065
  }
21070
21066
  }
21071
21067
  makeCarHeader(result, cars, compact = false) {
@@ -21224,7 +21220,7 @@ function applyHeadQueue(worker) {
21224
21220
  const task = queue.shift();
21225
21221
  if (!task)
21226
21222
  continue;
21227
- await worker(task.id, task.tblocks, task.newHead, task.prevHead, task.updates);
21223
+ await worker(task.id, task.newHead, task.prevHead, task.updates);
21228
21224
  if (task.updates) {
21229
21225
  allUpdates.push(...task.updates);
21230
21226
  }
@@ -21268,18 +21264,18 @@ var CRDTClock = class {
21268
21264
  setHead(head) {
21269
21265
  this.head = head;
21270
21266
  }
21271
- async applyHead(tblocks, newHead, prevHead, updates = null) {
21267
+ async applyHead(newHead, prevHead, updates = null) {
21272
21268
  const taskId = Math.random().toString().slice(2, 8);
21273
21269
  for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
21274
21270
  id: taskId,
21275
- tblocks,
21271
+ // tblocks,
21276
21272
  newHead,
21277
21273
  prevHead,
21278
21274
  updates
21279
21275
  })) {
21280
21276
  ;
21281
- (async (updatesAcc2, all2) => {
21282
- Promise.resolve().then(async () => {
21277
+ ((updatesAcc2, all2) => {
21278
+ void Promise.resolve().then(async () => {
21283
21279
  let intUpdates = updatesAcc2;
21284
21280
  if (this.watchers.size && !all2) {
21285
21281
  const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
@@ -21291,11 +21287,11 @@ var CRDTClock = class {
21291
21287
  })([...updatesAcc], all);
21292
21288
  }
21293
21289
  }
21294
- async int_applyHead(taskId, tblocks, newHead, prevHead, updates = null) {
21290
+ async int_applyHead(taskId, newHead, prevHead) {
21295
21291
  const ogHead = this.head.sort((a, b) => a.toString().localeCompare(b.toString()));
21296
21292
  newHead = newHead.sort((a, b) => a.toString().localeCompare(b.toString()));
21297
- newHead.map((cid) => {
21298
- const got = this.blocks.get(cid);
21293
+ newHead.map(async (cid) => {
21294
+ const got = await this.blocks.get(cid);
21299
21295
  if (!got) {
21300
21296
  throw new Error("int_applyHead missing block: " + cid.toString());
21301
21297
  }
@@ -21310,23 +21306,23 @@ var CRDTClock = class {
21310
21306
  }
21311
21307
  let head = this.head;
21312
21308
  const noLoader = false;
21313
- const withBlocks = async (tblocks2, fn) => {
21309
+ const withBlocks = async (fn) => {
21314
21310
  if (!this.blocks)
21315
21311
  throw new Error("missing blocks");
21316
21312
  return await this.blocks.transaction(fn, void 0, { noLoader });
21317
21313
  };
21318
- await withBlocks(tblocks, async (tblocks2) => {
21314
+ await withBlocks(async (tblocks) => {
21319
21315
  for (const cid of newHead) {
21320
21316
  try {
21321
- head = await advance(tblocks2, head, cid);
21317
+ head = await advance(tblocks, head, cid);
21322
21318
  } catch (e) {
21323
21319
  console.error("failed to advance", cid.toString(), e);
21324
21320
  continue;
21325
21321
  }
21326
21322
  }
21327
- const result = await root(tblocks2, head);
21323
+ const result = await root(tblocks, head);
21328
21324
  for (const { cid, bytes } of [...result.additions, ...result.removals]) {
21329
- tblocks2.putSync(cid, bytes);
21325
+ tblocks.putSync(cid, bytes);
21330
21326
  }
21331
21327
  return { head };
21332
21328
  });
@@ -21405,7 +21401,7 @@ var CRDT = class {
21405
21401
  }
21406
21402
  return { head };
21407
21403
  });
21408
- await this.clock.applyHead(null, got.head, prevHead, updates);
21404
+ await this.clock.applyHead(got.head, prevHead, updates);
21409
21405
  return got;
21410
21406
  })();
21411
21407
  if (loader) {
@@ -21440,7 +21436,7 @@ var CRDT = class {
21440
21436
  return await getBlock(this.blocks, cidString);
21441
21437
  }
21442
21438
  async getThatBlock() {
21443
- const blockJson = { "cid": "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", "bytes": "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
21439
+ const blockJson = { cid: "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", bytes: "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
21444
21440
  return await getThatBlock(blockJson);
21445
21441
  }
21446
21442
  async get(key) {