@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.
- package/dist/browser/fireproof.cjs +68 -34
- package/dist/browser/fireproof.cjs.map +4 -4
- package/dist/browser/fireproof.esm.js +68 -34
- package/dist/browser/fireproof.esm.js.map +4 -4
- package/dist/browser/fireproof.iife.js +68 -34
- package/dist/browser/fireproof.iife.js.map +4 -4
- package/dist/node/fireproof.cjs +68 -34
- package/dist/node/fireproof.cjs.map +4 -4
- package/dist/node/fireproof.esm.js +68 -34
- package/dist/node/fireproof.esm.js.map +4 -4
- package/dist/types/apply-head-queue.d.ts +2 -2
- package/dist/types/crdt-clock.d.ts +3 -3
- package/dist/types/crdt-helpers.d.ts +8 -2
- package/dist/types/crdt.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
@@ -11583,7 +11583,7 @@ replaceTraps((oldTraps) => ({
|
|
11583
11583
|
}));
|
11584
11584
|
|
11585
11585
|
// src/version.ts
|
11586
|
-
var PACKAGE_VERSION = "0.
|
11586
|
+
var PACKAGE_VERSION = "0.14.0";
|
11587
11587
|
|
11588
11588
|
// src/store.ts
|
11589
11589
|
var match = PACKAGE_VERSION.match(/^([^.]*\.[^.]*)/);
|
@@ -12009,9 +12009,6 @@ var Loader = class {
|
|
12009
12009
|
const header = await encodeCarHeader(fp);
|
12010
12010
|
await t.put(header.cid, header.bytes);
|
12011
12011
|
roots = [header.cid];
|
12012
|
-
const got = await t.get(header.cid);
|
12013
|
-
if (!got)
|
12014
|
-
throw new Error("missing header!!!");
|
12015
12012
|
}
|
12016
12013
|
const theKey = opts.public ? null : await this._getKey();
|
12017
12014
|
const { cid, bytes } = theKey ? await encryptedEncodeCarFile(theKey, roots[0], t) : await encodeCarFile(roots, t);
|
@@ -12785,6 +12782,9 @@ function makeMapFnFromName(name8) {
|
|
12785
12782
|
};
|
12786
12783
|
}
|
12787
12784
|
|
12785
|
+
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/link.js
|
12786
|
+
var parse3 = (source, base3) => CID2.parse(source, base3);
|
12787
|
+
|
12788
12788
|
// ../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/hashes/hasher.js
|
12789
12789
|
var from4 = ({ name: name8, code: code8, encode: encode19 }) => new Hasher2(name8, code8, encode19);
|
12790
12790
|
var Hasher2 = class {
|
@@ -14621,7 +14621,7 @@ var Data = $root.Data = (() => {
|
|
14621
14621
|
}
|
14622
14622
|
return d;
|
14623
14623
|
};
|
14624
|
-
Data3.prototype.toJSON = function
|
14624
|
+
Data3.prototype.toJSON = function toJSON3() {
|
14625
14625
|
return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
|
14626
14626
|
};
|
14627
14627
|
Data3.DataType = function() {
|
@@ -14718,7 +14718,7 @@ var UnixTime = $root.UnixTime = (() => {
|
|
14718
14718
|
}
|
14719
14719
|
return d;
|
14720
14720
|
};
|
14721
|
-
UnixTime3.prototype.toJSON = function
|
14721
|
+
UnixTime3.prototype.toJSON = function toJSON3() {
|
14722
14722
|
return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
|
14723
14723
|
};
|
14724
14724
|
return UnixTime3;
|
@@ -14777,7 +14777,7 @@ var Metadata = $root.Metadata = (() => {
|
|
14777
14777
|
}
|
14778
14778
|
return d;
|
14779
14779
|
};
|
14780
|
-
Metadata3.prototype.toJSON = function
|
14780
|
+
Metadata3.prototype.toJSON = function toJSON3() {
|
14781
14781
|
return this.constructor.toObject(this, import_minimal.default.util.toJSONOptions);
|
14782
14782
|
};
|
14783
14783
|
return Metadata3;
|
@@ -20932,6 +20932,8 @@ async function doCompact(blocks, head) {
|
|
20932
20932
|
if (!bl)
|
20933
20933
|
throw new Error("Missing head block: " + cid.toString());
|
20934
20934
|
}
|
20935
|
+
for await (const entry of getAllEntries(blockLog, head)) {
|
20936
|
+
}
|
20935
20937
|
for await (const [, link2] of entries2(blockLog, head)) {
|
20936
20938
|
const bl = await blockLog.get(link2);
|
20937
20939
|
if (!bl)
|
@@ -20948,6 +20950,18 @@ async function doCompact(blocks, head) {
|
|
20948
20950
|
isCompacting = false;
|
20949
20951
|
return done;
|
20950
20952
|
}
|
20953
|
+
async function getThatBlock({ bytes }) {
|
20954
|
+
const realBytes = Uint8Array.from(atob(bytes), (c) => c.charCodeAt(0));
|
20955
|
+
const { cid, value } = await decode12({ bytes: realBytes, codec: src_exports, hasher: sha256 });
|
20956
|
+
return new Block({ cid, value, bytes: realBytes });
|
20957
|
+
}
|
20958
|
+
async function getBlock(blocks, cidString) {
|
20959
|
+
const block = await blocks.get(parse3(cidString));
|
20960
|
+
if (!block)
|
20961
|
+
throw new Error(`Missing block ${cidString}`);
|
20962
|
+
const { cid, value } = await decode12({ bytes: block.bytes, codec: src_exports, hasher: sha256 });
|
20963
|
+
return new Block({ cid, value, bytes: block.bytes });
|
20964
|
+
}
|
20951
20965
|
|
20952
20966
|
// src/loaders.ts
|
20953
20967
|
var _IdxLoader = class _IdxLoader extends Loader {
|
@@ -21010,18 +21024,17 @@ var _DbLoader = class _DbLoader extends Loader {
|
|
21010
21024
|
return;
|
21011
21025
|
}
|
21012
21026
|
this.isCompacting = true;
|
21013
|
-
|
21014
|
-
|
21015
|
-
|
21016
|
-
|
21017
|
-
return compactingResult;
|
21018
|
-
} finally {
|
21019
|
-
this.isCompacting = false;
|
21020
|
-
}
|
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;
|
21021
21031
|
};
|
21022
21032
|
this.compacting = this._setWaitForWrite(compactingFn);
|
21033
|
+
this.compacting.finally(() => {
|
21034
|
+
this.isCompacting = false;
|
21035
|
+
this.awaitingCompact = false;
|
21036
|
+
});
|
21023
21037
|
await this.compacting;
|
21024
|
-
this.awaitingCompact = false;
|
21025
21038
|
}
|
21026
21039
|
async loadFileCar(cid, isPublic = false) {
|
21027
21040
|
return await this.storesLoadCar(cid, this.fileStore, this.remoteFileStore, isPublic);
|
@@ -21235,17 +21248,25 @@ var CRDTClock = class {
|
|
21235
21248
|
}
|
21236
21249
|
async applyHead(tblocks, newHead, prevHead, updates = null) {
|
21237
21250
|
const taskId = Math.random().toString().slice(2, 8);
|
21238
|
-
for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
|
21239
|
-
|
21240
|
-
|
21241
|
-
|
21242
|
-
|
21243
|
-
|
21244
|
-
|
21245
|
-
|
21246
|
-
|
21247
|
-
|
21248
|
-
|
21251
|
+
for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
|
21252
|
+
id: taskId,
|
21253
|
+
tblocks,
|
21254
|
+
newHead,
|
21255
|
+
prevHead,
|
21256
|
+
updates
|
21257
|
+
})) {
|
21258
|
+
;
|
21259
|
+
(async (updatesAcc2, all2) => {
|
21260
|
+
Promise.resolve().then(async () => {
|
21261
|
+
let intUpdates = updatesAcc2;
|
21262
|
+
if (this.watchers.size && !all2) {
|
21263
|
+
const changes = await clockChangesSince(this.blocks, this.head, prevHead, {});
|
21264
|
+
intUpdates = changes.result;
|
21265
|
+
}
|
21266
|
+
this.zoomers.forEach((fn) => fn());
|
21267
|
+
this.notifyWatchers(intUpdates || []);
|
21268
|
+
});
|
21269
|
+
})([...updatesAcc], all);
|
21249
21270
|
}
|
21250
21271
|
}
|
21251
21272
|
async int_applyHead(taskId, tblocks, newHead, prevHead, updates = null) {
|
@@ -21258,13 +21279,11 @@ var CRDTClock = class {
|
|
21258
21279
|
}
|
21259
21280
|
});
|
21260
21281
|
if (ogHead.toString() === newHead.toString()) {
|
21261
|
-
this.notifyWatchers(updates || []);
|
21262
21282
|
return;
|
21263
21283
|
}
|
21264
21284
|
const ogPrev = prevHead.sort((a, b) => a.toString().localeCompare(b.toString()));
|
21265
21285
|
if (ogHead.toString() === ogPrev.toString()) {
|
21266
21286
|
this.setHead(newHead);
|
21267
|
-
this.notifyWatchers(updates || []);
|
21268
21287
|
return;
|
21269
21288
|
}
|
21270
21289
|
let head = this.head;
|
@@ -21279,6 +21298,7 @@ var CRDTClock = class {
|
|
21279
21298
|
try {
|
21280
21299
|
head = await advance(tblocks2, head, cid);
|
21281
21300
|
} catch (e) {
|
21301
|
+
console.error("failed to advance", cid.toString(), e);
|
21282
21302
|
continue;
|
21283
21303
|
}
|
21284
21304
|
}
|
@@ -21349,16 +21369,22 @@ var CRDT = class {
|
|
21349
21369
|
if (loader?.isCompacting) {
|
21350
21370
|
throw new Error("cant bulk while compacting");
|
21351
21371
|
}
|
21352
|
-
const
|
21353
|
-
const { head
|
21372
|
+
const got = await this.blocks.transaction(async (tblocks) => {
|
21373
|
+
const { head } = await applyBulkUpdateToCrdt(tblocks, this.clock.head, updates, options);
|
21354
21374
|
updates = updates.map(({ key, value, del: del2 }) => {
|
21355
21375
|
readFiles(this.blocks, { doc: value });
|
21356
21376
|
return { key, value, del: del2 };
|
21357
21377
|
});
|
21358
|
-
|
21378
|
+
if (loader?.awaitingCompact) {
|
21379
|
+
console.log("missing?", head.toString());
|
21380
|
+
}
|
21381
|
+
if (loader?.isCompacting) {
|
21382
|
+
console.log("compacting?", head.toString());
|
21383
|
+
}
|
21384
|
+
return { head };
|
21359
21385
|
});
|
21360
|
-
await this.clock.applyHead(null, head, prevHead, updates);
|
21361
|
-
return
|
21386
|
+
await this.clock.applyHead(null, got.head, prevHead, updates);
|
21387
|
+
return got;
|
21362
21388
|
})();
|
21363
21389
|
if (loader) {
|
21364
21390
|
const wr = loader.writing;
|
@@ -21387,6 +21413,14 @@ var CRDT = class {
|
|
21387
21413
|
}
|
21388
21414
|
return txt.join("\n");
|
21389
21415
|
}
|
21416
|
+
async getBlock(cidString) {
|
21417
|
+
await this.ready;
|
21418
|
+
return await getBlock(this.blocks, cidString);
|
21419
|
+
}
|
21420
|
+
async getThatBlock() {
|
21421
|
+
const blockJson = { "cid": "bafyreib7ee4pscqpuioxobmh3ac5xbbslypmaqqbkugalhw67hnco6dvoa", "bytes": "omRkYXRhpGNrZXl4JDAxOGFmNzdiLWZmMTUtNzI5Ny04ODZiLTYwMjViM2MxODI2ZWRyb2902CpYJQABcRIgKVLI53HO1TFDbPUoSaybd0mop2oX/CRFm1RrpiY4ne9kdHlwZWNwdXRldmFsdWXYKlglAAFxEiAGw53MVtPzeeGT/itfdLBfCVu6MTj96AHU6v9a3K/wYGdwYXJlbnRzgdgqWCUAAXESIJiL5qjdpgghUfbQLpKJeCgMX+ubhoTpYBoZHYdzbQJ/" };
|
21422
|
+
return await getThatBlock(blockJson);
|
21423
|
+
}
|
21390
21424
|
async get(key) {
|
21391
21425
|
await this.ready;
|
21392
21426
|
const result = await getValueFromCrdt(this.blocks, this.clock.head, key);
|