@fireproof/core 0.13.5-dev → 0.13.7-dev

Sign up to get free protection for your applications and to get access to all the features.
@@ -11618,7 +11618,7 @@ replaceTraps((oldTraps) => ({
11618
11618
  }));
11619
11619
 
11620
11620
  // src/version.ts
11621
- var PACKAGE_VERSION = "0.13.5-dev";
11621
+ var PACKAGE_VERSION = "0.13.7-dev";
11622
11622
 
11623
11623
  // src/store.ts
11624
11624
  var match = PACKAGE_VERSION.match(/^([^.]*\.[^.]*)/);
@@ -12031,9 +12031,6 @@ var Loader = class {
12031
12031
  const header = await encodeCarHeader(fp);
12032
12032
  await t.put(header.cid, header.bytes);
12033
12033
  roots = [header.cid];
12034
- const got = await t.get(header.cid);
12035
- if (!got)
12036
- throw new Error("missing header!!!");
12037
12034
  }
12038
12035
  const theKey = opts.public ? null : await this._getKey();
12039
12036
  const { cid, bytes } = theKey ? await encryptedEncodeCarFile(theKey, roots[0], t) : await encodeCarFile(roots, t);
@@ -12804,6 +12801,9 @@ function makeMapFnFromName(name8) {
12804
12801
  };
12805
12802
  }
12806
12803
 
12804
+ // ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/link.js
12805
+ var parse3 = (source, base3) => CID2.parse(source, base3);
12806
+
12807
12807
  // ../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/hashes/hasher.js
12808
12808
  var from4 = ({ name: name8, code: code8, encode: encode19 }) => new Hasher2(name8, code8, encode19);
12809
12809
  var Hasher2 = class {
@@ -14635,7 +14635,7 @@ var Data = $root.Data = (() => {
14635
14635
  }
14636
14636
  return d;
14637
14637
  };
14638
- Data3.prototype.toJSON = function toJSON2() {
14638
+ Data3.prototype.toJSON = function toJSON3() {
14639
14639
  return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
14640
14640
  };
14641
14641
  Data3.DataType = function() {
@@ -14732,7 +14732,7 @@ var UnixTime = $root.UnixTime = (() => {
14732
14732
  }
14733
14733
  return d;
14734
14734
  };
14735
- UnixTime3.prototype.toJSON = function toJSON2() {
14735
+ UnixTime3.prototype.toJSON = function toJSON3() {
14736
14736
  return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
14737
14737
  };
14738
14738
  return UnixTime3;
@@ -14791,7 +14791,7 @@ var Metadata = $root.Metadata = (() => {
14791
14791
  }
14792
14792
  return d;
14793
14793
  };
14794
- Metadata3.prototype.toJSON = function toJSON2() {
14794
+ Metadata3.prototype.toJSON = function toJSON3() {
14795
14795
  return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
14796
14796
  };
14797
14797
  return Metadata3;
@@ -20944,6 +20944,8 @@ async function doCompact(blocks, head) {
20944
20944
  if (!bl)
20945
20945
  throw new Error("Missing head block: " + cid.toString());
20946
20946
  }
20947
+ for await (const entry of getAllEntries(blockLog, head)) {
20948
+ }
20947
20949
  for await (const [, link2] of entries2(blockLog, head)) {
20948
20950
  const bl = await blockLog.get(link2);
20949
20951
  if (!bl)
@@ -20960,6 +20962,18 @@ async function doCompact(blocks, head) {
20960
20962
  isCompacting = false;
20961
20963
  return done;
20962
20964
  }
20965
+ async function getThatBlock({ bytes }) {
20966
+ const realBytes = Uint8Array.from(atob(bytes), (c) => c.charCodeAt(0));
20967
+ const { cid, value } = await decode12({ bytes: realBytes, codec: src_exports, hasher: sha256 });
20968
+ return new Block({ cid, value, bytes: realBytes });
20969
+ }
20970
+ async function getBlock(blocks, cidString) {
20971
+ const block = await blocks.get(parse3(cidString));
20972
+ if (!block)
20973
+ throw new Error(`Missing block ${cidString}`);
20974
+ const { cid, value } = await decode12({ bytes: block.bytes, codec: src_exports, hasher: sha256 });
20975
+ return new Block({ cid, value, bytes: block.bytes });
20976
+ }
20963
20977
 
20964
20978
  // src/loaders.ts
20965
20979
  var IdxLoader = class _IdxLoader extends Loader {
@@ -21023,18 +21037,17 @@ var DbLoader = class _DbLoader extends Loader {
21023
21037
  return;
21024
21038
  }
21025
21039
  this.isCompacting = true;
21026
- try {
21027
- const compactHead = this.clock.head;
21028
- const compactingResult = await doCompact(blocks, this.clock.head);
21029
- await this.clock.applyHead(null, compactHead, compactHead, null);
21030
- return compactingResult;
21031
- } finally {
21032
- this.isCompacting = false;
21033
- }
21040
+ const compactHead = this.clock.head;
21041
+ const compactingResult = await doCompact(blocks, this.clock.head);
21042
+ await this.clock.applyHead(null, compactHead, compactHead, null);
21043
+ return compactingResult;
21034
21044
  };
21035
21045
  this.compacting = this._setWaitForWrite(compactingFn);
21046
+ this.compacting.finally(() => {
21047
+ this.isCompacting = false;
21048
+ this.awaitingCompact = false;
21049
+ });
21036
21050
  await this.compacting;
21037
- this.awaitingCompact = false;
21038
21051
  }
21039
21052
  async loadFileCar(cid, isPublic = false) {
21040
21053
  return await this.storesLoadCar(cid, this.fileStore, this.remoteFileStore, isPublic);
@@ -21245,17 +21258,25 @@ var CRDTClock = class {
21245
21258
  }
21246
21259
  async applyHead(tblocks, newHead, prevHead, updates = null) {
21247
21260
  const taskId = Math.random().toString().slice(2, 8);
21248
- for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({ id: taskId, tblocks, newHead, prevHead, updates })) {
21249
- Promise.resolve().then(async () => {
21250
- if (this.watchers.size && !all) {
21251
- const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
21252
- updates = changes.result;
21253
- } else {
21254
- updates = updatesAcc;
21255
- }
21256
- this.zoomers.forEach((fn) => fn());
21257
- this.notifyWatchers(updates || []);
21258
- });
21261
+ for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
21262
+ id: taskId,
21263
+ tblocks,
21264
+ newHead,
21265
+ prevHead,
21266
+ updates
21267
+ })) {
21268
+ ;
21269
+ (async (updatesAcc2, all2) => {
21270
+ Promise.resolve().then(async () => {
21271
+ let intUpdates = updatesAcc2;
21272
+ if (this.watchers.size && !all2) {
21273
+ const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
21274
+ intUpdates = changes.result;
21275
+ }
21276
+ this.zoomers.forEach((fn) => fn());
21277
+ this.notifyWatchers(intUpdates || []);
21278
+ });
21279
+ })([...updatesAcc], all);
21259
21280
  }
21260
21281
  }
21261
21282
  async int_applyHead(taskId, tblocks, newHead, prevHead, updates = null) {
@@ -21268,13 +21289,11 @@ var CRDTClock = class {
21268
21289
  }
21269
21290
  });
21270
21291
  if (ogHead.toString() === newHead.toString()) {
21271
- this.notifyWatchers(updates || []);
21272
21292
  return;
21273
21293
  }
21274
21294
  const ogPrev = prevHead.sort((a, b) => a.toString().localeCompare(b.toString()));
21275
21295
  if (ogHead.toString() === ogPrev.toString()) {
21276
21296
  this.setHead(newHead);
21277
- this.notifyWatchers(updates || []);
21278
21297
  return;
21279
21298
  }
21280
21299
  let head = this.head;
@@ -21289,6 +21308,7 @@ var CRDTClock = class {
21289
21308
  try {
21290
21309
  head = await advance(tblocks2, head, cid);
21291
21310
  } catch (e) {
21311
+ console.error("failed to advance", cid.toString(), e);
21292
21312
  continue;
21293
21313
  }
21294
21314
  }
@@ -21359,16 +21379,22 @@ var CRDT = class {
21359
21379
  if (loader?.isCompacting) {
21360
21380
  throw new Error("cant bulk while compacting");
21361
21381
  }
21362
- const { head } = await this.blocks.transaction(async (tblocks) => {
21363
- const { head: head2 } = await applyBulkUpdateToCrdt(tblocks, this.clock.head, updates, options);
21382
+ const got = await this.blocks.transaction(async (tblocks) => {
21383
+ const { head } = await applyBulkUpdateToCrdt(tblocks, this.clock.head, updates, options);
21364
21384
  updates = updates.map(({ key, value, del: del2 }) => {
21365
21385
  readFiles(this.blocks, { doc: value });
21366
21386
  return { key, value, del: del2 };
21367
21387
  });
21368
- return { head: head2 };
21388
+ if (loader?.awaitingCompact) {
21389
+ console.log("missing?", head.toString());
21390
+ }
21391
+ if (loader?.isCompacting) {
21392
+ console.log("compacting?", head.toString());
21393
+ }
21394
+ return { head };
21369
21395
  });
21370
- await this.clock.applyHead(null, head, prevHead, updates);
21371
- return { head };
21396
+ await this.clock.applyHead(null, got.head, prevHead, updates);
21397
+ return got;
21372
21398
  })();
21373
21399
  if (loader) {
21374
21400
  const wr = loader.writing;
@@ -21397,6 +21423,14 @@ var CRDT = class {
21397
21423
  }
21398
21424
  return txt.join("\n");
21399
21425
  }
21426
+ async getBlock(cidString) {
21427
+ await this.ready;
21428
+ return await getBlock(this.blocks, cidString);
21429
+ }
21430
+ async getThatBlock() {
21431
+ const blockJson = { "cid": "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", "bytes": "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
21432
+ return await getThatBlock(blockJson);
21433
+ }
21400
21434
  async get(key) {
21401
21435
  await this.ready;
21402
21436
  const result = await getValueFromCrdt(this.blocks, this.clock.head, key);