@fireproof/core 0.13.5-dev → 0.14.0

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.
@@ -11600,7 +11600,7 @@ replaceTraps((oldTraps) => ({
11600
11600
  }));
11601
11601
 
11602
11602
  // src/version.ts
11603
- var PACKAGE_VERSION = "0.13.5-dev";
11603
+ var PACKAGE_VERSION = "0.14.0";
11604
11604
 
11605
11605
  // src/store.ts
11606
11606
  var match = PACKAGE_VERSION.match(/^([^.]*\.[^.]*)/);
@@ -12013,9 +12013,6 @@ var Loader = class {
12013
12013
  const header = await encodeCarHeader(fp);
12014
12014
  await t.put(header.cid, header.bytes);
12015
12015
  roots = [header.cid];
12016
- const got = await t.get(header.cid);
12017
- if (!got)
12018
- throw new Error("missing header!!!");
12019
12016
  }
12020
12017
  const theKey = opts.public ? null : await this._getKey();
12021
12018
  const { cid, bytes } = theKey ? await encryptedEncodeCarFile(theKey, roots[0], t) : await encodeCarFile(roots, t);
@@ -12786,6 +12783,9 @@ function makeMapFnFromName(name8) {
12786
12783
  };
12787
12784
  }
12788
12785
 
12786
+ // ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/link.js
12787
+ var parse3 = (source, base3) => CID2.parse(source, base3);
12788
+
12789
12789
  // ../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/hashes/hasher.js
12790
12790
  var from4 = ({ name: name8, code: code8, encode: encode19 }) => new Hasher2(name8, code8, encode19);
12791
12791
  var Hasher2 = class {
@@ -14617,7 +14617,7 @@ var Data = $root.Data = (() => {
14617
14617
  }
14618
14618
  return d;
14619
14619
  };
14620
- Data3.prototype.toJSON = function toJSON2() {
14620
+ Data3.prototype.toJSON = function toJSON3() {
14621
14621
  return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
14622
14622
  };
14623
14623
  Data3.DataType = function() {
@@ -14714,7 +14714,7 @@ var UnixTime = $root.UnixTime = (() => {
14714
14714
  }
14715
14715
  return d;
14716
14716
  };
14717
- UnixTime3.prototype.toJSON = function toJSON2() {
14717
+ UnixTime3.prototype.toJSON = function toJSON3() {
14718
14718
  return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
14719
14719
  };
14720
14720
  return UnixTime3;
@@ -14773,7 +14773,7 @@ var Metadata = $root.Metadata = (() => {
14773
14773
  }
14774
14774
  return d;
14775
14775
  };
14776
- Metadata3.prototype.toJSON = function toJSON2() {
14776
+ Metadata3.prototype.toJSON = function toJSON3() {
14777
14777
  return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
14778
14778
  };
14779
14779
  return Metadata3;
@@ -20926,6 +20926,8 @@ async function doCompact(blocks, head) {
20926
20926
  if (!bl)
20927
20927
  throw new Error("Missing head block: " + cid.toString());
20928
20928
  }
20929
+ for await (const entry of getAllEntries(blockLog, head)) {
20930
+ }
20929
20931
  for await (const [, link2] of entries2(blockLog, head)) {
20930
20932
  const bl = await blockLog.get(link2);
20931
20933
  if (!bl)
@@ -20942,6 +20944,18 @@ async function doCompact(blocks, head) {
20942
20944
  isCompacting = false;
20943
20945
  return done;
20944
20946
  }
20947
+ async function getThatBlock({ bytes }) {
20948
+ const realBytes = Uint8Array.from(atob(bytes), (c) => c.charCodeAt(0));
20949
+ const { cid, value } = await decode12({ bytes: realBytes, codec: src_exports, hasher: sha256 });
20950
+ return new Block({ cid, value, bytes: realBytes });
20951
+ }
20952
+ async function getBlock(blocks, cidString) {
20953
+ const block = await blocks.get(parse3(cidString));
20954
+ if (!block)
20955
+ throw new Error(`Missing block ${cidString}`);
20956
+ const { cid, value } = await decode12({ bytes: block.bytes, codec: src_exports, hasher: sha256 });
20957
+ return new Block({ cid, value, bytes: block.bytes });
20958
+ }
20945
20959
 
20946
20960
  // src/loaders.ts
20947
20961
  var IdxLoader = class _IdxLoader extends Loader {
@@ -21005,18 +21019,17 @@ var DbLoader = class _DbLoader extends Loader {
21005
21019
  return;
21006
21020
  }
21007
21021
  this.isCompacting = true;
21008
- try {
21009
- const compactHead = this.clock.head;
21010
- const compactingResult = await doCompact(blocks, this.clock.head);
21011
- await this.clock.applyHead(null, compactHead, compactHead, null);
21012
- return compactingResult;
21013
- } finally {
21014
- this.isCompacting = false;
21015
- }
21022
+ const compactHead = this.clock.head;
21023
+ const compactingResult = await doCompact(blocks, this.clock.head);
21024
+ await this.clock.applyHead(null, compactHead, compactHead, null);
21025
+ return compactingResult;
21016
21026
  };
21017
21027
  this.compacting = this._setWaitForWrite(compactingFn);
21028
+ this.compacting.finally(() => {
21029
+ this.isCompacting = false;
21030
+ this.awaitingCompact = false;
21031
+ });
21018
21032
  await this.compacting;
21019
- this.awaitingCompact = false;
21020
21033
  }
21021
21034
  async loadFileCar(cid, isPublic = false) {
21022
21035
  return await this.storesLoadCar(cid, this.fileStore, this.remoteFileStore, isPublic);
@@ -21227,17 +21240,25 @@ var CRDTClock = class {
21227
21240
  }
21228
21241
  async applyHead(tblocks, newHead, prevHead, updates = null) {
21229
21242
  const taskId = Math.random().toString().slice(2, 8);
21230
- for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({ id: taskId, tblocks, newHead, prevHead, updates })) {
21231
- Promise.resolve().then(async () => {
21232
- if (this.watchers.size && !all) {
21233
- const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
21234
- updates = changes.result;
21235
- } else {
21236
- updates = updatesAcc;
21237
- }
21238
- this.zoomers.forEach((fn) => fn());
21239
- this.notifyWatchers(updates || []);
21240
- });
21243
+ for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
21244
+ id: taskId,
21245
+ tblocks,
21246
+ newHead,
21247
+ prevHead,
21248
+ updates
21249
+ })) {
21250
+ ;
21251
+ (async (updatesAcc2, all2) => {
21252
+ Promise.resolve().then(async () => {
21253
+ let intUpdates = updatesAcc2;
21254
+ if (this.watchers.size && !all2) {
21255
+ const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
21256
+ intUpdates = changes.result;
21257
+ }
21258
+ this.zoomers.forEach((fn) => fn());
21259
+ this.notifyWatchers(intUpdates || []);
21260
+ });
21261
+ })([...updatesAcc], all);
21241
21262
  }
21242
21263
  }
21243
21264
  async int_applyHead(taskId, tblocks, newHead, prevHead, updates = null) {
@@ -21250,13 +21271,11 @@ var CRDTClock = class {
21250
21271
  }
21251
21272
  });
21252
21273
  if (ogHead.toString() === newHead.toString()) {
21253
- this.notifyWatchers(updates || []);
21254
21274
  return;
21255
21275
  }
21256
21276
  const ogPrev = prevHead.sort((a, b) => a.toString().localeCompare(b.toString()));
21257
21277
  if (ogHead.toString() === ogPrev.toString()) {
21258
21278
  this.setHead(newHead);
21259
- this.notifyWatchers(updates || []);
21260
21279
  return;
21261
21280
  }
21262
21281
  let head = this.head;
@@ -21271,6 +21290,7 @@ var CRDTClock = class {
21271
21290
  try {
21272
21291
  head = await advance(tblocks2, head, cid);
21273
21292
  } catch (e) {
21293
+ console.error("failed to advance", cid.toString(), e);
21274
21294
  continue;
21275
21295
  }
21276
21296
  }
@@ -21341,16 +21361,22 @@ var CRDT = class {
21341
21361
  if (loader?.isCompacting) {
21342
21362
  throw new Error("cant bulk while compacting");
21343
21363
  }
21344
- const { head } = await this.blocks.transaction(async (tblocks) => {
21345
- const { head: head2 } = await applyBulkUpdateToCrdt(tblocks, this.clock.head, updates, options);
21364
+ const got = await this.blocks.transaction(async (tblocks) => {
21365
+ const { head } = await applyBulkUpdateToCrdt(tblocks, this.clock.head, updates, options);
21346
21366
  updates = updates.map(({ key, value, del: del2 }) => {
21347
21367
  readFiles(this.blocks, { doc: value });
21348
21368
  return { key, value, del: del2 };
21349
21369
  });
21350
- return { head: head2 };
21370
+ if (loader?.awaitingCompact) {
21371
+ console.log("missing?", head.toString());
21372
+ }
21373
+ if (loader?.isCompacting) {
21374
+ console.log("compacting?", head.toString());
21375
+ }
21376
+ return { head };
21351
21377
  });
21352
- await this.clock.applyHead(null, head, prevHead, updates);
21353
- return { head };
21378
+ await this.clock.applyHead(null, got.head, prevHead, updates);
21379
+ return got;
21354
21380
  })();
21355
21381
  if (loader) {
21356
21382
  const wr = loader.writing;
@@ -21379,6 +21405,14 @@ var CRDT = class {
21379
21405
  }
21380
21406
  return txt.join("\n");
21381
21407
  }
21408
+ async getBlock(cidString) {
21409
+ await this.ready;
21410
+ return await getBlock(this.blocks, cidString);
21411
+ }
21412
+ async getThatBlock() {
21413
+ const blockJson = { "cid": "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", "bytes": "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
21414
+ return await getThatBlock(blockJson);
21415
+ }
21382
21416
  async get(key) {
21383
21417
  await this.ready;
21384
21418
  const result = await getValueFromCrdt(this.blocks, this.clock.head, key);