@fireproof/core 0.5.7 → 0.5.9
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/src/fireproof.d.ts +109 -104
- package/dist/src/fireproof.js +309 -235
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +309 -235
- package/dist/src/fireproof.mjs.map +1 -1
- package/package.json +1 -1
- package/src/blockstore.js +4 -1
- package/src/clock.js +41 -9
- package/src/database.js +33 -12
- package/src/db-index.js +14 -3
- package/src/fireproof.js +2 -2
- package/src/prolly.js +82 -48
- package/src/sync.js +23 -12
- package/src/valet.js +1 -1
package/dist/src/fireproof.js
CHANGED
@@ -34,17 +34,9 @@ function getAugmentedNamespace(n) {
|
|
34
34
|
return a;
|
35
35
|
}
|
36
36
|
|
37
|
-
var
|
38
|
-
var browser$d = {
|
39
|
-
get exports(){ return browserExports$1; },
|
40
|
-
set exports(v){ browserExports$1 = v; },
|
41
|
-
};
|
37
|
+
var browser$d = {exports: {}};
|
42
38
|
|
43
|
-
var
|
44
|
-
var safeBuffer$1 = {
|
45
|
-
get exports(){ return safeBufferExports; },
|
46
|
-
set exports(v){ safeBufferExports = v; },
|
47
|
-
};
|
39
|
+
var safeBuffer$1 = {exports: {}};
|
48
40
|
|
49
41
|
var global$1 = (typeof global !== "undefined" ? global :
|
50
42
|
typeof self !== "undefined" ? self :
|
@@ -2109,8 +2101,10 @@ var require$$6$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_buffer);
|
|
2109
2101
|
throw new TypeError('Argument must be a number')
|
2110
2102
|
}
|
2111
2103
|
return buffer.SlowBuffer(size)
|
2112
|
-
};
|
2113
|
-
} (safeBuffer$1,
|
2104
|
+
};
|
2105
|
+
} (safeBuffer$1, safeBuffer$1.exports));
|
2106
|
+
|
2107
|
+
var safeBufferExports = safeBuffer$1.exports;
|
2114
2108
|
|
2115
2109
|
// limit of Crypto.getRandomValues()
|
2116
2110
|
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
@@ -2161,6 +2155,9 @@ function randomBytes$2 (size, cb) {
|
|
2161
2155
|
return bytes
|
2162
2156
|
}
|
2163
2157
|
|
2158
|
+
var browserExports$1 = browser$d.exports;
|
2159
|
+
var randomBytes$3 = /*@__PURE__*/getDefaultExportFromCjs(browserExports$1);
|
2160
|
+
|
2164
2161
|
var encode_1$2 = encode$9;
|
2165
2162
|
|
2166
2163
|
var MSB$4 = 0x80
|
@@ -2243,13 +2240,13 @@ var length$2 = function (value) {
|
|
2243
2240
|
)
|
2244
2241
|
};
|
2245
2242
|
|
2246
|
-
var varint$
|
2243
|
+
var varint$3 = {
|
2247
2244
|
encode: encode_1$2
|
2248
2245
|
, decode: decode$d
|
2249
2246
|
, encodingLength: length$2
|
2250
2247
|
};
|
2251
2248
|
|
2252
|
-
var _brrp_varint$1 = varint$
|
2249
|
+
var _brrp_varint$1 = varint$3;
|
2253
2250
|
|
2254
2251
|
/**
|
2255
2252
|
* @param {Uint8Array} data
|
@@ -5668,7 +5665,11 @@ async function contains (events, a, b) {
|
|
5668
5665
|
*/
|
5669
5666
|
async function * vis$1 (blocks, head, options = {}) {
|
5670
5667
|
// @ts-ignore
|
5671
|
-
const renderNodeLabel = options.renderNodeLabel ?? ((b) =>
|
5668
|
+
const renderNodeLabel = options.renderNodeLabel ?? ((b) => {
|
5669
|
+
// @ts-ignore
|
5670
|
+
const { key, root, type } = b.value.data;
|
5671
|
+
return b.cid.toString() + '\n' + JSON.stringify({ key, root: root.cid.toString(), type }, null, 2).replace(/"/g, '\'')
|
5672
|
+
});
|
5672
5673
|
const events = new EventFetcher(blocks);
|
5673
5674
|
yield 'digraph clock {';
|
5674
5675
|
yield ' node [shape=point fontname="Courier"]; head;';
|
@@ -5709,6 +5710,7 @@ async function findEventsToSync (blocks, head) {
|
|
5709
5710
|
// console.time(callTag + '.contains')
|
5710
5711
|
const toSync = await asyncFilter(sorted, async (uks) => !(await contains(events, ancestor, uks.cid)));
|
5711
5712
|
// console.timeEnd(callTag + '.contains')
|
5713
|
+
// console.log('toSync.contains', toSync.length)
|
5712
5714
|
|
5713
5715
|
return { cids: events, events: toSync }
|
5714
5716
|
}
|
@@ -5716,17 +5718,21 @@ async function findEventsToSync (blocks, head) {
|
|
5716
5718
|
const asyncFilter = async (arr, predicate) =>
|
5717
5719
|
Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));
|
5718
5720
|
|
5719
|
-
async function findCommonAncestorWithSortedEvents (events, children) {
|
5721
|
+
async function findCommonAncestorWithSortedEvents (events, children, doFull = false) {
|
5722
|
+
// console.trace('findCommonAncestorWithSortedEvents')
|
5720
5723
|
// const callTag = Math.random().toString(36).substring(7)
|
5724
|
+
// console.log(callTag + '.children', children.map((c) => c.toString()))
|
5721
5725
|
// console.time(callTag + '.findCommonAncestor')
|
5722
5726
|
const ancestor = await findCommonAncestor(events, children);
|
5723
5727
|
// console.timeEnd(callTag + '.findCommonAncestor')
|
5728
|
+
// console.log('ancestor', ancestor.toString())
|
5724
5729
|
if (!ancestor) {
|
5725
5730
|
throw new Error('failed to find common ancestor event')
|
5726
5731
|
}
|
5727
5732
|
// console.time(callTag + '.findSortedEvents')
|
5728
|
-
const sorted = await findSortedEvents(events, children, ancestor);
|
5733
|
+
const sorted = await findSortedEvents(events, children, ancestor, doFull);
|
5729
5734
|
// console.timeEnd(callTag + '.findSortedEvents')
|
5735
|
+
// console.log('sorted', sorted.length)
|
5730
5736
|
return { ancestor, sorted }
|
5731
5737
|
}
|
5732
5738
|
|
@@ -5739,6 +5745,7 @@ async function findCommonAncestorWithSortedEvents (events, children) {
|
|
5739
5745
|
*/
|
5740
5746
|
async function findCommonAncestor (events, children) {
|
5741
5747
|
if (!children.length) return
|
5748
|
+
if (children.length === 1) return children[0]
|
5742
5749
|
const candidates = children.map((c) => [c]);
|
5743
5750
|
while (true) {
|
5744
5751
|
let changed = false;
|
@@ -5759,7 +5766,7 @@ async function findCommonAncestor (events, children) {
|
|
5759
5766
|
* @param {import('./clock').EventLink<EventData>} root
|
5760
5767
|
*/
|
5761
5768
|
async function findAncestorCandidate (events, root) {
|
5762
|
-
const { value: event } = await events.get(root)
|
5769
|
+
const { value: event } = await events.get(root);// .catch(() => ({ value: { parents: [] } }))
|
5763
5770
|
if (!event.parents.length) return root
|
5764
5771
|
return event.parents.length === 1 ? event.parents[0] : findCommonAncestor(events, event.parents)
|
5765
5772
|
}
|
@@ -5769,6 +5776,7 @@ async function findAncestorCandidate (events, root) {
|
|
5769
5776
|
* @param {Array<T[]>} arrays
|
5770
5777
|
*/
|
5771
5778
|
function findCommonString (arrays) {
|
5779
|
+
// console.log('findCommonString', arrays.map((a) => a.map((i) => String(i))))
|
5772
5780
|
arrays = arrays.map((a) => [...a]);
|
5773
5781
|
for (const arr of arrays) {
|
5774
5782
|
for (const item of arr) {
|
@@ -5786,15 +5794,33 @@ function findCommonString (arrays) {
|
|
5786
5794
|
/**
|
5787
5795
|
* Find and sort events between the head(s) and the tail.
|
5788
5796
|
* @param {import('./clock').EventFetcher} events
|
5789
|
-
* @param {
|
5797
|
+
* @param {any[]} head
|
5790
5798
|
* @param {import('./clock').EventLink<EventData>} tail
|
5791
5799
|
*/
|
5792
|
-
async function findSortedEvents (events, head, tail) {
|
5800
|
+
async function findSortedEvents (events, head, tail, doFull) {
|
5793
5801
|
// const callTag = Math.random().toString(36).substring(7)
|
5794
5802
|
// get weighted events - heavier events happened first
|
5803
|
+
// const callTag = Math.random().toString(36).substring(7)
|
5804
|
+
|
5795
5805
|
/** @type {Map<string, { event: import('./clock').EventBlockView<EventData>, weight: number }>} */
|
5796
5806
|
const weights = new Map();
|
5807
|
+
head = [...new Set([...head.map((h) => h.toString())])];
|
5808
|
+
// console.log(callTag + '.head', head.length)
|
5809
|
+
|
5810
|
+
const allEvents = new Set([tail.toString(), ...head]);
|
5811
|
+
if (!doFull && allEvents.size === 1) {
|
5812
|
+
// console.log('head contains tail', tail.toString())
|
5813
|
+
return []
|
5814
|
+
// const event = await events.get(tail)
|
5815
|
+
// return [event]
|
5816
|
+
}
|
5817
|
+
|
5818
|
+
// console.log('finding events')
|
5819
|
+
// console.log(callTag + '.head', head.length, [...head.map((h) => h.toString())], tail.toString())
|
5820
|
+
|
5821
|
+
// console.time(callTag + '.findEvents')
|
5797
5822
|
const all = await Promise.all(head.map((h) => findEvents(events, h, tail)));
|
5823
|
+
// console.timeEnd(callTag + '.findEvents')
|
5798
5824
|
for (const arr of all) {
|
5799
5825
|
for (const { event, depth } of arr) {
|
5800
5826
|
// console.log('event value', event.value.data.value)
|
@@ -5823,7 +5849,7 @@ async function findSortedEvents (events, head, tail) {
|
|
5823
5849
|
const sorted = Array.from(buckets)
|
5824
5850
|
.sort((a, b) => b[0] - a[0])
|
5825
5851
|
.flatMap(([, es]) => es.sort((a, b) => (String(a.cid) < String(b.cid) ? -1 : 1)));
|
5826
|
-
// console.log('sorted', sorted.map(s => s.
|
5852
|
+
// console.log('sorted', sorted.map(s => s.cid))
|
5827
5853
|
|
5828
5854
|
return sorted
|
5829
5855
|
}
|
@@ -5835,11 +5861,14 @@ async function findSortedEvents (events, head, tail) {
|
|
5835
5861
|
* @returns {Promise<Array<{ event: EventBlockView<EventData>, depth: number }>>}
|
5836
5862
|
*/
|
5837
5863
|
async function findEvents (events, start, end, depth = 0) {
|
5838
|
-
// console.log('findEvents', start)
|
5864
|
+
// console.log('findEvents', start.toString(), end.toString(), depth)
|
5839
5865
|
const event = await events.get(start);
|
5866
|
+
const send = String(end);
|
5840
5867
|
const acc = [{ event, depth }];
|
5841
5868
|
const { parents } = event.value;
|
5842
|
-
if (parents.length === 1 && String(parents[0]) ===
|
5869
|
+
// if (parents.length === 1 && String(parents[0]) === send) return acc
|
5870
|
+
if (parents.findIndex((p) => String(p) === send) !== -1) return acc
|
5871
|
+
// if (parents.length === 1) return acc
|
5843
5872
|
const rest = await Promise.all(parents.map((p) => findEvents(events, p, end, depth + 1)));
|
5844
5873
|
return acc.concat(...rest)
|
5845
5874
|
}
|
@@ -7046,6 +7075,8 @@ var varint$1 = {
|
|
7046
7075
|
, encodingLength: length$1
|
7047
7076
|
};
|
7048
7077
|
|
7078
|
+
var varint$2 = /*@__PURE__*/getDefaultExportFromCjs(varint$1);
|
7079
|
+
|
7049
7080
|
const CIDV0_BYTES = {
|
7050
7081
|
SHA2_256: 0x12,
|
7051
7082
|
LENGTH: 0x20,
|
@@ -7070,8 +7101,8 @@ function decodeVarint (bytes, seeker) {
|
|
7070
7101
|
if (!bytes.length) {
|
7071
7102
|
throw new Error('Unexpected end of data')
|
7072
7103
|
}
|
7073
|
-
const i = varint$
|
7074
|
-
seeker.seek(/** @type {number} */(varint$
|
7104
|
+
const i = varint$2.decode(bytes);
|
7105
|
+
seeker.seek(/** @type {number} */(varint$2.decode.bytes));
|
7075
7106
|
return i
|
7076
7107
|
/* c8 ignore next 2 */
|
7077
7108
|
// Node.js 12 c8 bug
|
@@ -7122,10 +7153,10 @@ function getMultihashLength (bytes) {
|
|
7122
7153
|
// where both code and length are varints, so we have to decode
|
7123
7154
|
// them first before we can know total length
|
7124
7155
|
|
7125
|
-
varint$
|
7126
|
-
const codeLength = /** @type {number} */(varint$
|
7127
|
-
const length = varint$
|
7128
|
-
const lengthLength = /** @type {number} */(varint$
|
7156
|
+
varint$2.decode(bytes); // code
|
7157
|
+
const codeLength = /** @type {number} */(varint$2.decode.bytes);
|
7158
|
+
const length = varint$2.decode(bytes.subarray(varint$2.decode.bytes));
|
7159
|
+
const lengthLength = /** @type {number} */(varint$2.decode.bytes);
|
7129
7160
|
const mhLength = codeLength + lengthLength + length;
|
7130
7161
|
|
7131
7162
|
return mhLength
|
@@ -7833,7 +7864,7 @@ const addRoot = (writer, root, options = {}) => {
|
|
7833
7864
|
*/
|
7834
7865
|
const blockLength = ({ cid, bytes }) => {
|
7835
7866
|
const size = cid.bytes.byteLength + bytes.byteLength;
|
7836
|
-
return varint$
|
7867
|
+
return varint$2.encodingLength(size) + size
|
7837
7868
|
};
|
7838
7869
|
|
7839
7870
|
/**
|
@@ -7842,7 +7873,7 @@ const blockLength = ({ cid, bytes }) => {
|
|
7842
7873
|
*/
|
7843
7874
|
const addBlock = (writer, { cid, bytes }) => {
|
7844
7875
|
const byteLength = cid.bytes.byteLength + bytes.byteLength;
|
7845
|
-
const size = varint$
|
7876
|
+
const size = varint$2.encode(byteLength);
|
7846
7877
|
if (writer.byteOffset + size.length + byteLength > writer.bytes.byteLength) {
|
7847
7878
|
throw new RangeError('Buffer has no capacity for this block')
|
7848
7879
|
} else {
|
@@ -7862,7 +7893,7 @@ const close = (writer, options = {}) => {
|
|
7862
7893
|
const { roots, bytes, byteOffset, headerSize } = writer;
|
7863
7894
|
|
7864
7895
|
const headerBytes = encode$5({ version: 1, roots });
|
7865
|
-
const varintBytes = varint$
|
7896
|
+
const varintBytes = varint$2.encode(headerBytes.length);
|
7866
7897
|
|
7867
7898
|
const size = varintBytes.length + headerBytes.byteLength;
|
7868
7899
|
const offset = headerSize - size;
|
@@ -7939,7 +7970,7 @@ const calculateHeaderLength = (rootLengths) => {
|
|
7939
7970
|
tokens.push(new Token(Type.bytes, { length: rootLength + 1 }));
|
7940
7971
|
}
|
7941
7972
|
const length = tokensToLength(tokens); // no options needed here because we have simple tokens
|
7942
|
-
return varint$
|
7973
|
+
return varint$2.encodingLength(length) + length
|
7943
7974
|
};
|
7944
7975
|
|
7945
7976
|
/**
|
@@ -8282,23 +8313,11 @@ replaceTraps((oldTraps) => ({
|
|
8282
8313
|
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
|
8283
8314
|
}));
|
8284
8315
|
|
8285
|
-
var
|
8286
|
-
var cargoQueue$1 = {
|
8287
|
-
get exports(){ return cargoQueueExports; },
|
8288
|
-
set exports(v){ cargoQueueExports = v; },
|
8289
|
-
};
|
8316
|
+
var cargoQueue$1 = {exports: {}};
|
8290
8317
|
|
8291
|
-
var
|
8292
|
-
var queue$1 = {
|
8293
|
-
get exports(){ return queueExports; },
|
8294
|
-
set exports(v){ queueExports = v; },
|
8295
|
-
};
|
8318
|
+
var queue$1 = {exports: {}};
|
8296
8319
|
|
8297
|
-
var
|
8298
|
-
var onlyOnce = {
|
8299
|
-
get exports(){ return onlyOnceExports; },
|
8300
|
-
set exports(v){ onlyOnceExports = v; },
|
8301
|
-
};
|
8320
|
+
var onlyOnce = {exports: {}};
|
8302
8321
|
|
8303
8322
|
(function (module, exports) {
|
8304
8323
|
|
@@ -8314,8 +8333,10 @@ var onlyOnce = {
|
|
8314
8333
|
callFn.apply(this, args);
|
8315
8334
|
};
|
8316
8335
|
}
|
8317
|
-
module.exports = exports["default"];
|
8318
|
-
} (onlyOnce,
|
8336
|
+
module.exports = exports["default"];
|
8337
|
+
} (onlyOnce, onlyOnce.exports));
|
8338
|
+
|
8339
|
+
var onlyOnceExports = onlyOnce.exports;
|
8319
8340
|
|
8320
8341
|
var setImmediate$1 = {};
|
8321
8342
|
|
@@ -8352,11 +8373,7 @@ if (hasQueueMicrotask) {
|
|
8352
8373
|
|
8353
8374
|
setImmediate$1.default = wrap(_defer);
|
8354
8375
|
|
8355
|
-
var
|
8356
|
-
var DoublyLinkedList = {
|
8357
|
-
get exports(){ return DoublyLinkedListExports; },
|
8358
|
-
set exports(v){ DoublyLinkedListExports = v; },
|
8359
|
-
};
|
8376
|
+
var DoublyLinkedList = {exports: {}};
|
8360
8377
|
|
8361
8378
|
(function (module, exports) {
|
8362
8379
|
|
@@ -8449,22 +8466,16 @@ var DoublyLinkedList = {
|
|
8449
8466
|
dll.length = 1;
|
8450
8467
|
dll.head = dll.tail = node;
|
8451
8468
|
}
|
8452
|
-
module.exports = exports["default"];
|
8453
|
-
} (DoublyLinkedList,
|
8469
|
+
module.exports = exports["default"];
|
8470
|
+
} (DoublyLinkedList, DoublyLinkedList.exports));
|
8471
|
+
|
8472
|
+
var DoublyLinkedListExports = DoublyLinkedList.exports;
|
8454
8473
|
|
8455
8474
|
var wrapAsync = {};
|
8456
8475
|
|
8457
|
-
var
|
8458
|
-
var asyncify = {
|
8459
|
-
get exports(){ return asyncifyExports; },
|
8460
|
-
set exports(v){ asyncifyExports = v; },
|
8461
|
-
};
|
8476
|
+
var asyncify = {exports: {}};
|
8462
8477
|
|
8463
|
-
var
|
8464
|
-
var initialParams = {
|
8465
|
-
get exports(){ return initialParamsExports; },
|
8466
|
-
set exports(v){ initialParamsExports = v; },
|
8467
|
-
};
|
8478
|
+
var initialParams = {exports: {}};
|
8468
8479
|
|
8469
8480
|
(function (module, exports) {
|
8470
8481
|
|
@@ -8479,13 +8490,15 @@ var initialParams = {
|
|
8479
8490
|
};
|
8480
8491
|
};
|
8481
8492
|
|
8482
|
-
module.exports = exports["default"];
|
8483
|
-
} (initialParams,
|
8493
|
+
module.exports = exports["default"];
|
8494
|
+
} (initialParams, initialParams.exports));
|
8495
|
+
|
8496
|
+
var initialParamsExports = initialParams.exports;
|
8484
8497
|
|
8485
8498
|
var hasRequiredAsyncify;
|
8486
8499
|
|
8487
8500
|
function requireAsyncify () {
|
8488
|
-
if (hasRequiredAsyncify) return
|
8501
|
+
if (hasRequiredAsyncify) return asyncify.exports;
|
8489
8502
|
hasRequiredAsyncify = 1;
|
8490
8503
|
(function (module, exports) {
|
8491
8504
|
|
@@ -8604,9 +8617,9 @@ function requireAsyncify () {
|
|
8604
8617
|
}, err);
|
8605
8618
|
}
|
8606
8619
|
}
|
8607
|
-
module.exports = exports['default'];
|
8608
|
-
} (asyncify,
|
8609
|
-
return
|
8620
|
+
module.exports = exports['default'];
|
8621
|
+
} (asyncify, asyncify.exports));
|
8622
|
+
return asyncify.exports;
|
8610
8623
|
}
|
8611
8624
|
|
8612
8625
|
var hasRequiredWrapAsync;
|
@@ -8943,8 +8956,10 @@ function requireWrapAsync () {
|
|
8943
8956
|
});
|
8944
8957
|
return q;
|
8945
8958
|
}
|
8946
|
-
module.exports = exports['default'];
|
8947
|
-
} (queue$1,
|
8959
|
+
module.exports = exports['default'];
|
8960
|
+
} (queue$1, queue$1.exports));
|
8961
|
+
|
8962
|
+
var queueExports = queue$1.exports;
|
8948
8963
|
|
8949
8964
|
(function (module, exports) {
|
8950
8965
|
|
@@ -9016,9 +9031,10 @@ function requireWrapAsync () {
|
|
9016
9031
|
function cargo(worker, concurrency, payload) {
|
9017
9032
|
return (0, _queue2.default)(worker, concurrency, payload);
|
9018
9033
|
}
|
9019
|
-
module.exports = exports['default'];
|
9020
|
-
} (cargoQueue$1,
|
9034
|
+
module.exports = exports['default'];
|
9035
|
+
} (cargoQueue$1, cargoQueue$1.exports));
|
9021
9036
|
|
9037
|
+
var cargoQueueExports = cargoQueue$1.exports;
|
9022
9038
|
var cargoQueue = /*@__PURE__*/getDefaultExportFromCjs(cargoQueueExports);
|
9023
9039
|
|
9024
9040
|
var cryptoBrowserify = {};
|
@@ -9055,11 +9071,7 @@ var _polyfillNode_inherits = /*#__PURE__*/Object.freeze({
|
|
9055
9071
|
|
9056
9072
|
var require$$3$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_inherits);
|
9057
9073
|
|
9058
|
-
var
|
9059
|
-
var readableBrowser = {
|
9060
|
-
get exports(){ return readableBrowserExports; },
|
9061
|
-
set exports(v){ readableBrowserExports = v; },
|
9062
|
-
};
|
9074
|
+
var readableBrowser = {exports: {}};
|
9063
9075
|
|
9064
9076
|
var domain;
|
9065
9077
|
|
@@ -13456,8 +13468,10 @@ var pipeline_1 = pipeline;
|
|
13456
13468
|
exports.Transform = _stream_transform;
|
13457
13469
|
exports.PassThrough = _stream_passthrough;
|
13458
13470
|
exports.finished = endOfStream;
|
13459
|
-
exports.pipeline = pipeline_1;
|
13460
|
-
} (readableBrowser,
|
13471
|
+
exports.pipeline = pipeline_1;
|
13472
|
+
} (readableBrowser, readableBrowser.exports));
|
13473
|
+
|
13474
|
+
var readableBrowserExports = readableBrowser.exports;
|
13461
13475
|
|
13462
13476
|
var Buffer$E = safeBufferExports.Buffer;
|
13463
13477
|
var Transform$6 = readableBrowserExports.Transform;
|
@@ -13863,11 +13877,7 @@ function fn5 (a, b, c, d, e, m, k, s) {
|
|
13863
13877
|
|
13864
13878
|
var ripemd160 = RIPEMD160$4;
|
13865
13879
|
|
13866
|
-
var
|
13867
|
-
var sha_js = {
|
13868
|
-
get exports(){ return sha_jsExports; },
|
13869
|
-
set exports(v){ sha_jsExports = v; },
|
13870
|
-
};
|
13880
|
+
var sha_js = {exports: {}};
|
13871
13881
|
|
13872
13882
|
var Buffer$B = safeBufferExports.Buffer;
|
13873
13883
|
|
@@ -14671,6 +14681,8 @@ exports$1.sha256 = sha256$1;
|
|
14671
14681
|
exports$1.sha384 = sha384$1;
|
14672
14682
|
exports$1.sha512 = sha512$1;
|
14673
14683
|
|
14684
|
+
var sha_jsExports = sha_js.exports;
|
14685
|
+
|
14674
14686
|
function BufferList() {
|
14675
14687
|
this.head = null;
|
14676
14688
|
this.tail = null;
|
@@ -16621,12 +16633,6 @@ var browser$9 = function createHmac (alg, key) {
|
|
16621
16633
|
return new Hmac$2(alg, key)
|
16622
16634
|
};
|
16623
16635
|
|
16624
|
-
var algosExports = {};
|
16625
|
-
var algos = {
|
16626
|
-
get exports(){ return algosExports; },
|
16627
|
-
set exports(v){ algosExports = v; },
|
16628
|
-
};
|
16629
|
-
|
16630
16636
|
var sha224WithRSAEncryption = {
|
16631
16637
|
sign: "rsa",
|
16632
16638
|
hash: "sha224",
|
@@ -16791,9 +16797,7 @@ var require$$6 = {
|
|
16791
16797
|
}
|
16792
16798
|
};
|
16793
16799
|
|
16794
|
-
|
16795
|
-
module.exports = require$$6;
|
16796
|
-
} (algos));
|
16800
|
+
var algos = require$$6;
|
16797
16801
|
|
16798
16802
|
var browser$8 = {};
|
16799
16803
|
|
@@ -19033,7 +19037,7 @@ var modes = {};
|
|
19033
19037
|
exports['des-ede'] = {
|
19034
19038
|
key: 16,
|
19035
19039
|
iv: 0
|
19036
|
-
};
|
19040
|
+
};
|
19037
19041
|
} (modes));
|
19038
19042
|
|
19039
19043
|
var DES = browserifyDes;
|
@@ -19106,11 +19110,9 @@ browser$7.listCiphers = browser$7.getCiphers = getCiphers;
|
|
19106
19110
|
|
19107
19111
|
var browser$5 = {};
|
19108
19112
|
|
19109
|
-
var
|
19110
|
-
|
19111
|
-
|
19112
|
-
set exports(v){ bnExports$1 = v; },
|
19113
|
-
};
|
19113
|
+
var bn$1 = {exports: {}};
|
19114
|
+
|
19115
|
+
bn$1.exports;
|
19114
19116
|
|
19115
19117
|
(function (module) {
|
19116
19118
|
(function (module, exports) {
|
@@ -22555,19 +22557,17 @@ var bn$1 = {
|
|
22555
22557
|
var res = this.imod(a._invmp(this.m).mul(this.r2));
|
22556
22558
|
return res._forceRed(this);
|
22557
22559
|
};
|
22558
|
-
})(module, commonjsGlobal);
|
22560
|
+
})(module, commonjsGlobal);
|
22559
22561
|
} (bn$1));
|
22560
22562
|
|
22561
|
-
var
|
22562
|
-
|
22563
|
-
|
22564
|
-
set exports(v){ brorandExports = v; },
|
22565
|
-
};
|
22563
|
+
var bnExports$1 = bn$1.exports;
|
22564
|
+
|
22565
|
+
var brorand = {exports: {}};
|
22566
22566
|
|
22567
22567
|
var hasRequiredBrorand;
|
22568
22568
|
|
22569
22569
|
function requireBrorand () {
|
22570
|
-
if (hasRequiredBrorand) return
|
22570
|
+
if (hasRequiredBrorand) return brorand.exports;
|
22571
22571
|
hasRequiredBrorand = 1;
|
22572
22572
|
var r;
|
22573
22573
|
|
@@ -22581,7 +22581,7 @@ function requireBrorand () {
|
|
22581
22581
|
function Rand(rand) {
|
22582
22582
|
this.rand = rand;
|
22583
22583
|
}
|
22584
|
-
|
22584
|
+
brorand.exports.Rand = Rand;
|
22585
22585
|
|
22586
22586
|
Rand.prototype.generate = function generate(len) {
|
22587
22587
|
return this._rand(len);
|
@@ -22634,7 +22634,7 @@ function requireBrorand () {
|
|
22634
22634
|
} catch (e) {
|
22635
22635
|
}
|
22636
22636
|
}
|
22637
|
-
return
|
22637
|
+
return brorand.exports;
|
22638
22638
|
}
|
22639
22639
|
|
22640
22640
|
var mr;
|
@@ -23141,17 +23141,11 @@ function requireBrowser$2 () {
|
|
23141
23141
|
return browser$5;
|
23142
23142
|
}
|
23143
23143
|
|
23144
|
-
var
|
23145
|
-
var sign = {
|
23146
|
-
get exports(){ return signExports; },
|
23147
|
-
set exports(v){ signExports = v; },
|
23148
|
-
};
|
23144
|
+
var sign = {exports: {}};
|
23149
23145
|
|
23150
|
-
var
|
23151
|
-
|
23152
|
-
|
23153
|
-
set exports(v){ bnExports = v; },
|
23154
|
-
};
|
23146
|
+
var bn = {exports: {}};
|
23147
|
+
|
23148
|
+
bn.exports;
|
23155
23149
|
|
23156
23150
|
(function (module) {
|
23157
23151
|
(function (module, exports) {
|
@@ -26501,9 +26495,11 @@ var bn = {
|
|
26501
26495
|
var res = this.imod(a._invmp(this.m).mul(this.r2));
|
26502
26496
|
return res._forceRed(this);
|
26503
26497
|
};
|
26504
|
-
})(module, commonjsGlobal);
|
26498
|
+
})(module, commonjsGlobal);
|
26505
26499
|
} (bn));
|
26506
26500
|
|
26501
|
+
var bnExports = bn.exports;
|
26502
|
+
|
26507
26503
|
var BN$a = bnExports;
|
26508
26504
|
var randomBytes$1 = browserExports$1;
|
26509
26505
|
|
@@ -26674,7 +26670,7 @@ var utils$k = {};
|
|
26674
26670
|
return toHex(arr);
|
26675
26671
|
else
|
26676
26672
|
return arr;
|
26677
|
-
};
|
26673
|
+
};
|
26678
26674
|
} (utils$k));
|
26679
26675
|
|
26680
26676
|
(function (exports) {
|
@@ -26794,7 +26790,7 @@ var utils$k = {};
|
|
26794
26790
|
function intFromLE(bytes) {
|
26795
26791
|
return new BN(bytes, 'hex', 'le');
|
26796
26792
|
}
|
26797
|
-
utils.intFromLE = intFromLE;
|
26793
|
+
utils.intFromLE = intFromLE;
|
26798
26794
|
} (utils$l));
|
26799
26795
|
|
26800
26796
|
var curve = {};
|
@@ -28733,7 +28729,7 @@ Point.prototype.mixedAdd = Point.prototype.add;
|
|
28733
28729
|
curve.base = base$2;
|
28734
28730
|
curve.short = short;
|
28735
28731
|
curve.mont = mont;
|
28736
|
-
curve.edwards = edwards;
|
28732
|
+
curve.edwards = edwards;
|
28737
28733
|
} (curve));
|
28738
28734
|
|
28739
28735
|
var curves$1 = {};
|
@@ -29946,7 +29942,7 @@ Hmac.prototype.digest = function digest(enc) {
|
|
29946
29942
|
hash.sha224 = hash.sha.sha224;
|
29947
29943
|
hash.sha384 = hash.sha.sha384;
|
29948
29944
|
hash.sha512 = hash.sha.sha512;
|
29949
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
29945
|
+
hash.ripemd160 = hash.ripemd.ripemd160;
|
29950
29946
|
} (hash$2));
|
29951
29947
|
|
29952
29948
|
var secp256k1;
|
@@ -30943,7 +30939,7 @@ function requireSecp256k1 () {
|
|
30943
30939
|
'483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
|
30944
30940
|
pre,
|
30945
30941
|
],
|
30946
|
-
});
|
30942
|
+
});
|
30947
30943
|
} (curves$1));
|
30948
30944
|
|
30949
30945
|
var hash$1 = hash$2;
|
@@ -31886,8 +31882,8 @@ function requireElliptic () {
|
|
31886
31882
|
|
31887
31883
|
// Protocols
|
31888
31884
|
elliptic.ec = requireEc();
|
31889
|
-
elliptic.eddsa = eddsa;
|
31890
|
-
} (elliptic));
|
31885
|
+
elliptic.eddsa = eddsa;
|
31886
|
+
} (elliptic));
|
31891
31887
|
return elliptic;
|
31892
31888
|
}
|
31893
31889
|
|
@@ -32947,7 +32943,7 @@ var der$2 = {};
|
|
32947
32943
|
0x1d: 'charstr',
|
32948
32944
|
0x1e: 'bmpstr'
|
32949
32945
|
};
|
32950
|
-
exports.tagByName = reverse(exports.tag);
|
32946
|
+
exports.tagByName = reverse(exports.tag);
|
32951
32947
|
} (der$2));
|
32952
32948
|
|
32953
32949
|
const inherits$3 = require$$3$1;
|
@@ -33271,7 +33267,7 @@ PEMEncoder.prototype.encode = function encode(data, options) {
|
|
33271
33267
|
const encoders = exports;
|
33272
33268
|
|
33273
33269
|
encoders.der = der_1$1;
|
33274
|
-
encoders.pem = pem$1;
|
33270
|
+
encoders.pem = pem$1;
|
33275
33271
|
} (encoders));
|
33276
33272
|
|
33277
33273
|
var decoders = {};
|
@@ -33665,7 +33661,7 @@ PEMDecoder.prototype.decode = function decode(data, options) {
|
|
33665
33661
|
const decoders = exports;
|
33666
33662
|
|
33667
33663
|
decoders.der = der_1;
|
33668
|
-
decoders.pem = pem;
|
33664
|
+
decoders.pem = pem;
|
33669
33665
|
} (decoders));
|
33670
33666
|
|
33671
33667
|
(function (exports) {
|
@@ -33724,7 +33720,7 @@ PEMDecoder.prototype.decode = function decode(data, options) {
|
|
33724
33720
|
|
33725
33721
|
Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
|
33726
33722
|
return this._getEncoder(enc).encode(data, reporter);
|
33727
|
-
};
|
33723
|
+
};
|
33728
33724
|
} (api));
|
33729
33725
|
|
33730
33726
|
var base$1 = {};
|
@@ -33736,7 +33732,7 @@ var base$1 = {};
|
|
33736
33732
|
base.Reporter = reporter.Reporter;
|
33737
33733
|
base.DecoderBuffer = buffer.DecoderBuffer;
|
33738
33734
|
base.EncoderBuffer = buffer.EncoderBuffer;
|
33739
|
-
base.Node = node;
|
33735
|
+
base.Node = node;
|
33740
33736
|
} (base$1));
|
33741
33737
|
|
33742
33738
|
var constants = {};
|
@@ -33761,7 +33757,7 @@ var constants = {};
|
|
33761
33757
|
return res;
|
33762
33758
|
};
|
33763
33759
|
|
33764
|
-
constants.der = der$2;
|
33760
|
+
constants.der = der$2;
|
33765
33761
|
} (constants));
|
33766
33762
|
|
33767
33763
|
(function (exports) {
|
@@ -33774,7 +33770,7 @@ var constants = {};
|
|
33774
33770
|
asn1.base = base$1;
|
33775
33771
|
asn1.constants = constants;
|
33776
33772
|
asn1.decoders = decoders;
|
33777
|
-
asn1.encoders = encoders;
|
33773
|
+
asn1.encoders = encoders;
|
33778
33774
|
} (asn1$2));
|
33779
33775
|
|
33780
33776
|
var asn = asn1$2;
|
@@ -34148,7 +34144,7 @@ var require$$4 = {
|
|
34148
34144
|
var hasRequiredSign;
|
34149
34145
|
|
34150
34146
|
function requireSign () {
|
34151
|
-
if (hasRequiredSign) return
|
34147
|
+
if (hasRequiredSign) return sign.exports;
|
34152
34148
|
hasRequiredSign = 1;
|
34153
34149
|
// much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
|
34154
34150
|
var Buffer = safeBufferExports.Buffer;
|
@@ -34291,9 +34287,9 @@ function requireSign () {
|
|
34291
34287
|
}
|
34292
34288
|
|
34293
34289
|
sign.exports = sign$1;
|
34294
|
-
|
34295
|
-
|
34296
|
-
return
|
34290
|
+
sign.exports.getKey = getKey;
|
34291
|
+
sign.exports.makeKey = makeKey;
|
34292
|
+
return sign.exports;
|
34297
34293
|
}
|
34298
34294
|
|
34299
34295
|
var verify_1;
|
@@ -34872,7 +34868,7 @@ function compare$3 (a, b) {
|
|
34872
34868
|
|
34873
34869
|
exports.publicDecrypt = function publicDecrypt (key, buf) {
|
34874
34870
|
return exports.privateDecrypt(key, buf, true)
|
34875
|
-
};
|
34871
|
+
};
|
34876
34872
|
} (browser$2));
|
34877
34873
|
|
34878
34874
|
var browser$1 = {};
|
@@ -34994,8 +34990,8 @@ function requireCryptoBrowserify () {
|
|
34994
34990
|
cryptoBrowserify.createHash = cryptoBrowserify.Hash = browser$a;
|
34995
34991
|
cryptoBrowserify.createHmac = cryptoBrowserify.Hmac = browser$9;
|
34996
34992
|
|
34997
|
-
var algos =
|
34998
|
-
var algoKeys = Object.keys(algos);
|
34993
|
+
var algos$1 = algos;
|
34994
|
+
var algoKeys = Object.keys(algos$1);
|
34999
34995
|
var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
|
35000
34996
|
cryptoBrowserify.getHashes = function () {
|
35001
34997
|
return hashes
|
@@ -36928,7 +36924,7 @@ function rawSha1 (b) {
|
|
36928
36924
|
return new Uint8Array(H.buffer, H.byteOffset, H.byteLength)
|
36929
36925
|
}
|
36930
36926
|
|
36931
|
-
const chunker = bf(
|
36927
|
+
const chunker = bf(30);
|
36932
36928
|
|
36933
36929
|
const NO_ENCRYPT = typeof process !== 'undefined' && !!process.env?.NO_ENCRYPT;
|
36934
36930
|
// ? process.env.NO_ENCRYPT : import.meta && import.meta.env.VITE_NO_ENCRYPT
|
@@ -37377,7 +37373,10 @@ class TransactionBlockstore {
|
|
37377
37373
|
await this.doCommit(innerBlockstore);
|
37378
37374
|
if (doSync) {
|
37379
37375
|
// const all =
|
37380
|
-
await Promise.all([...this.syncs].map(async sync => sync.sendUpdate(innerBlockstore)
|
37376
|
+
await Promise.all([...this.syncs].map(async sync => sync.sendUpdate(innerBlockstore).catch(e => {
|
37377
|
+
console.error('sync error', e);
|
37378
|
+
this.syncs.delete(sync);
|
37379
|
+
})));
|
37381
37380
|
}
|
37382
37381
|
}
|
37383
37382
|
|
@@ -37484,23 +37483,24 @@ class InnerBlockstore {
|
|
37484
37483
|
}
|
37485
37484
|
}
|
37486
37485
|
|
37487
|
-
const blockOpts = { cache: nocache, chunker: bf(
|
37486
|
+
const blockOpts = { cache: nocache, chunker: bf(30), codec: codec$1, hasher: sha256$2, compare: simpleCompare };
|
37488
37487
|
|
37489
37488
|
/**
|
37490
37489
|
* @typedef {import('./blockstore.js').TransactionBlockstore} TransactionBlockstore
|
37491
37490
|
*/
|
37492
37491
|
|
37493
|
-
const withLog = async (label, fn) => {
|
37494
|
-
|
37495
|
-
|
37496
|
-
|
37497
|
-
}
|
37492
|
+
// const withLog = async (label, fn) => {
|
37493
|
+
// const resp = await fn()
|
37494
|
+
// // console.log('withLog', label, !!resp)
|
37495
|
+
// return resp
|
37496
|
+
// }
|
37498
37497
|
|
37499
37498
|
// should also return a CIDCounter
|
37500
|
-
const makeGetBlock =
|
37499
|
+
const makeGetBlock = blocks => {
|
37501
37500
|
// const cids = new CIDCounter() // this could be used for proofs of mutations
|
37502
|
-
const getBlockFn = async
|
37503
|
-
const { cid, bytes } = await withLog(address, () => blocks.get(address))
|
37501
|
+
const getBlockFn = async address => {
|
37502
|
+
// const { cid, bytes } = await withLog(address, () => blocks.get(address))
|
37503
|
+
const { cid, bytes } = await blocks.get(address);
|
37504
37504
|
// cids.add({ address: cid })
|
37505
37505
|
return create$5({ cid, bytes, hasher: sha256$2, codec: codec$1 })
|
37506
37506
|
};
|
@@ -37515,25 +37515,17 @@ const makeGetBlock = (blocks) => {
|
|
37515
37515
|
* @param {*} param0
|
37516
37516
|
* @returns
|
37517
37517
|
*/
|
37518
|
-
async function createAndSaveNewEvent ({
|
37519
|
-
inBlocks,
|
37520
|
-
bigPut,
|
37521
|
-
root,
|
37522
|
-
event: inEvent,
|
37523
|
-
head,
|
37524
|
-
additions,
|
37525
|
-
removals = []
|
37526
|
-
}) {
|
37518
|
+
async function createAndSaveNewEvent ({ inBlocks, bigPut, root, event: inEvent, head, additions, removals = [] }) {
|
37527
37519
|
let cids;
|
37528
37520
|
const { key, value, del } = inEvent;
|
37529
37521
|
const data = {
|
37530
|
-
root:
|
37522
|
+
root: root
|
37531
37523
|
? {
|
37532
37524
|
cid: root.cid,
|
37533
37525
|
bytes: root.bytes, // can we remove this?
|
37534
37526
|
value: root.value // can we remove this?
|
37535
37527
|
}
|
37536
|
-
: null
|
37528
|
+
: null,
|
37537
37529
|
key
|
37538
37530
|
};
|
37539
37531
|
// import('./clock').EventLink<import('./clock').EventData>
|
@@ -37561,7 +37553,7 @@ async function createAndSaveNewEvent ({
|
|
37561
37553
|
}
|
37562
37554
|
}
|
37563
37555
|
|
37564
|
-
const makeGetAndPutBlock =
|
37556
|
+
const makeGetAndPutBlock = inBlocks => {
|
37565
37557
|
// const mblocks = new MemoryBlockstore()
|
37566
37558
|
// const blocks = new MultiBlockFetcher(mblocks, inBlocks)
|
37567
37559
|
const { getBlock, cids } = makeGetBlock(inBlocks);
|
@@ -37620,20 +37612,24 @@ const prollyRootFromAncestor = async (events, ancestor, getBlock) => {
|
|
37620
37612
|
}
|
37621
37613
|
};
|
37622
37614
|
|
37623
|
-
const doProllyBulk = async (inBlocks, head, event) => {
|
37615
|
+
const doProllyBulk = async (inBlocks, head, event, doFull = false) => {
|
37624
37616
|
const { getBlock, blocks } = makeGetAndPutBlock(inBlocks);
|
37625
37617
|
let bulkSorted = [];
|
37626
37618
|
let prollyRootNode = null;
|
37627
37619
|
const events = new EventFetcher(blocks);
|
37628
37620
|
if (head.length) {
|
37629
|
-
|
37621
|
+
if (!doFull && head.length === 1) {
|
37622
|
+
prollyRootNode = await prollyRootFromAncestor(events, head[0], getBlock);
|
37623
|
+
} else {
|
37624
|
+
// Otherwise, we find the common ancestor and update the root and other blocks
|
37630
37625
|
// todo this is returning more events than necessary, lets define the desired semantics from the top down
|
37631
37626
|
// good semantics mean we can cache the results of this call
|
37632
|
-
|
37633
|
-
|
37634
|
-
|
37635
|
-
|
37627
|
+
const { ancestor, sorted } = await findCommonAncestorWithSortedEvents(events, head, doFull);
|
37628
|
+
bulkSorted = sorted;
|
37629
|
+
// console.log('sorted', JSON.stringify(sorted.map(({ value: { data: { key, value } } }) => ({ key, value }))))
|
37630
|
+
prollyRootNode = await prollyRootFromAncestor(events, ancestor, getBlock);
|
37636
37631
|
// console.log('event', event)
|
37632
|
+
}
|
37637
37633
|
}
|
37638
37634
|
|
37639
37635
|
const bulkOperations = bulkFromEvents(bulkSorted, event);
|
@@ -37643,7 +37639,7 @@ const doProllyBulk = async (inBlocks, head, event) => {
|
|
37643
37639
|
let root;
|
37644
37640
|
const newBlocks = [];
|
37645
37641
|
// if all operations are deletes, we can just return an empty root
|
37646
|
-
if (bulkOperations.every(
|
37642
|
+
if (bulkOperations.every(op => op.del)) {
|
37647
37643
|
return { root: null, blocks: [], clockCIDs: await events.all() }
|
37648
37644
|
}
|
37649
37645
|
for await (const node of create$3({ get: getBlock, list: bulkOperations, ...blockOpts })) {
|
@@ -37663,7 +37659,7 @@ const doProllyBulk = async (inBlocks, head, event) => {
|
|
37663
37659
|
*
|
37664
37660
|
* @param {import('./blockstore.js').Blockstore} inBlocks Bucket block storage.
|
37665
37661
|
* @param {import('./clock').EventLink<import('./clock').EventData>[]} head Merkle clock head.
|
37666
|
-
* @param {{key: string, value: import('./clock').EventLink<import('./clock').EventData>}} event The key of the value to put.
|
37662
|
+
* @param {{key: string, value: import('./clock').EventLink<import('./clock').EventData>}} event The key of the value to put.
|
37667
37663
|
* @param {object} [options]
|
37668
37664
|
* @returns {Promise<any>}
|
37669
37665
|
*/
|
@@ -37715,18 +37711,24 @@ async function put (inBlocks, head, event, options) {
|
|
37715
37711
|
* @param {TransactionBlockstore} inBlocks Bucket block storage.
|
37716
37712
|
* @param {import('./clock').EventLink<import('./clock').EventData>[]} head Merkle clock head.
|
37717
37713
|
*/
|
37718
|
-
async function root (inBlocks, head) {
|
37714
|
+
async function root (inBlocks, head, doFull = false) {
|
37719
37715
|
if (!head.length) {
|
37720
37716
|
throw new Error('no head')
|
37721
37717
|
}
|
37722
|
-
|
37718
|
+
// console.log('root', head.map(h => h.toString()))
|
37719
|
+
const { root: newProllyRootNode, blocks: newBlocks, clockCIDs } = await doProllyBulk(inBlocks, head, null, doFull);
|
37723
37720
|
// todo maybe these should go to a temp blockstore?
|
37724
|
-
await doTransaction(
|
37725
|
-
|
37726
|
-
|
37727
|
-
|
37728
|
-
|
37729
|
-
|
37721
|
+
await doTransaction(
|
37722
|
+
'root',
|
37723
|
+
inBlocks,
|
37724
|
+
async transactionBlocks => {
|
37725
|
+
const { bigPut } = makeGetAndPutBlock(transactionBlocks);
|
37726
|
+
for (const nb of newBlocks) {
|
37727
|
+
bigPut(nb);
|
37728
|
+
}
|
37729
|
+
},
|
37730
|
+
false
|
37731
|
+
);
|
37730
37732
|
return { clockCIDs, node: newProllyRootNode }
|
37731
37733
|
}
|
37732
37734
|
|
@@ -37753,22 +37755,37 @@ async function eventsSince (blocks, head, since) {
|
|
37753
37755
|
* @param {TransactionBlockstore} blocks Bucket block storage.
|
37754
37756
|
* @param {import('./clock').EventLink<import('./clock').EventData>[]} head Merkle clock head.
|
37755
37757
|
*
|
37756
|
-
* @returns {Promise<{cids: CIDCounter, clockCIDs: CIDCounter, result: import('./clock').EventData[]}>}
|
37758
|
+
* @returns {Promise<{root: any, cids: CIDCounter, clockCIDs: CIDCounter, result: import('./clock').EventData[]}>}
|
37757
37759
|
*
|
37758
37760
|
*/
|
37759
|
-
async function getAll (blocks, head) {
|
37761
|
+
async function getAll (blocks, head, rootCache = null, doFull = false) {
|
37760
37762
|
// todo use the root node left around from put, etc
|
37761
37763
|
// move load to a central place
|
37762
37764
|
if (!head.length) {
|
37763
|
-
return { clockCIDs: new CIDCounter(), cids: new CIDCounter(), result: [] }
|
37765
|
+
return { root: null, clockCIDs: new CIDCounter(), cids: new CIDCounter(), result: [] }
|
37764
37766
|
}
|
37765
|
-
const { node: prollyRootNode, clockCIDs } = await
|
37767
|
+
const { node: prollyRootNode, clockCIDs } = await rootOrCache(blocks, head, rootCache, doFull);
|
37766
37768
|
|
37767
37769
|
if (!prollyRootNode) {
|
37768
|
-
return { clockCIDs, cids: new CIDCounter(), result: [] }
|
37770
|
+
return { root: null, clockCIDs, cids: new CIDCounter(), result: [] }
|
37769
37771
|
}
|
37770
37772
|
const { result, cids } = await prollyRootNode.getAllEntries(); // todo params
|
37771
|
-
return { clockCIDs, cids, result: result.map(({ key, value }) => ({ key, value })) }
|
37773
|
+
return { root: prollyRootNode, clockCIDs, cids, result: result.map(({ key, value }) => ({ key, value })) }
|
37774
|
+
}
|
37775
|
+
|
37776
|
+
async function rootOrCache (blocks, head, rootCache, doFull = false) {
|
37777
|
+
let node;
|
37778
|
+
let clockCIDs;
|
37779
|
+
if (!doFull && rootCache && rootCache.root) {
|
37780
|
+
// console.log('get root from cache', rootCache)
|
37781
|
+
node = rootCache.root;
|
37782
|
+
clockCIDs = rootCache.clockCIDs;
|
37783
|
+
} else {
|
37784
|
+
({ node, clockCIDs } = await root(blocks, head, doFull));
|
37785
|
+
// console.timeEnd(callTag + '.root')
|
37786
|
+
// console.log('found root')
|
37787
|
+
}
|
37788
|
+
return { node, clockCIDs }
|
37772
37789
|
}
|
37773
37790
|
|
37774
37791
|
/**
|
@@ -37776,17 +37793,19 @@ async function getAll (blocks, head) {
|
|
37776
37793
|
* @param {import('./clock').EventLink<import('./clock').EventData>[]} head Merkle clock head.
|
37777
37794
|
* @param {string} key The key of the value to retrieve.
|
37778
37795
|
*/
|
37779
|
-
async function get (blocks, head, key) {
|
37796
|
+
async function get (blocks, head, key, rootCache = null) {
|
37780
37797
|
// instead pass root from db? and always update on change
|
37781
37798
|
if (!head.length) {
|
37782
37799
|
return { cids: new CIDCounter(), result: null }
|
37783
37800
|
}
|
37784
|
-
|
37801
|
+
|
37802
|
+
const { node: prollyRootNode, clockCIDs } = await rootOrCache(blocks, head, rootCache);
|
37803
|
+
|
37785
37804
|
if (!prollyRootNode) {
|
37786
37805
|
return { clockCIDs, cids: new CIDCounter(), result: null }
|
37787
37806
|
}
|
37788
37807
|
const { result, cids } = await prollyRootNode.get(key);
|
37789
|
-
return { result, cids, clockCIDs }
|
37808
|
+
return { result, cids, clockCIDs, root: prollyRootNode }
|
37790
37809
|
}
|
37791
37810
|
|
37792
37811
|
async function * vis (blocks, head) {
|
@@ -37803,8 +37822,19 @@ async function * vis (blocks, head) {
|
|
37803
37822
|
}
|
37804
37823
|
|
37805
37824
|
async function visMerkleTree (blocks, head) {
|
37806
|
-
if (!head
|
37807
|
-
|
37825
|
+
// if (!head) return
|
37826
|
+
if (head && !Array.isArray(head)) {
|
37827
|
+
const getBl = makeGetBlock(blocks);
|
37828
|
+
const prollyRootNode = await load$2({
|
37829
|
+
cid: head,
|
37830
|
+
get: getBl.getBlock,
|
37831
|
+
...blockOpts
|
37832
|
+
});
|
37833
|
+
const lines = [];
|
37834
|
+
for await (const line of prollyRootNode.vis()) {
|
37835
|
+
lines.push(line);
|
37836
|
+
}
|
37837
|
+
return { vis: lines.join('\n'), cids: new CIDCounter() }
|
37808
37838
|
}
|
37809
37839
|
const { node: prollyRootNode, cids } = await root(blocks, head);
|
37810
37840
|
const lines = [];
|
@@ -37823,7 +37853,7 @@ async function visMerkleClock (blocks, head) {
|
|
37823
37853
|
return { vis: lines.join('\n') }
|
37824
37854
|
}
|
37825
37855
|
|
37826
|
-
var charwise = {};
|
37856
|
+
var charwise$1 = {};
|
37827
37857
|
|
37828
37858
|
var number = {};
|
37829
37859
|
|
@@ -38051,8 +38081,10 @@ object.factory = function (codec) {
|
|
38051
38081
|
|
38052
38082
|
//for leveldb, request strings
|
38053
38083
|
exports.buffer = false;
|
38054
|
-
exports.type = 'charwise';
|
38055
|
-
} (charwise));
|
38084
|
+
exports.type = 'charwise';
|
38085
|
+
} (charwise$1));
|
38086
|
+
|
38087
|
+
var charwise = /*@__PURE__*/getDefaultExportFromCjs(charwise$1);
|
38056
38088
|
|
38057
38089
|
/* global localStorage */
|
38058
38090
|
let storageSupported = false;
|
@@ -38087,15 +38119,16 @@ const parseCID = cid => (typeof cid === 'string' ? CID$1.parse(cid) : cid);
|
|
38087
38119
|
*/
|
38088
38120
|
class Database {
|
38089
38121
|
listeners = new Set()
|
38122
|
+
indexes = new Map()
|
38123
|
+
rootCache = null
|
38124
|
+
eventsCache = new Map()
|
38090
38125
|
|
38091
|
-
// todo refactor this for the next version
|
38092
38126
|
constructor (blocks, clock, config = {}) {
|
38093
38127
|
this.name = config.name;
|
38094
38128
|
this.instanceId = `fp.${this.name}.${Math.random().toString(36).substring(2, 7)}`;
|
38095
38129
|
this.blocks = blocks;
|
38096
38130
|
this.clock = clock;
|
38097
38131
|
this.config = config;
|
38098
|
-
this.indexes = new Map();
|
38099
38132
|
}
|
38100
38133
|
|
38101
38134
|
/**
|
@@ -38162,11 +38195,22 @@ class Database {
|
|
38162
38195
|
* @instance
|
38163
38196
|
*/
|
38164
38197
|
async changesSince (event) {
|
38198
|
+
// console.log('events for', this.instanceId, event.constructor.name)
|
38165
38199
|
// console.log('changesSince', this.instanceId, event, this.clock)
|
38166
38200
|
let rows, dataCIDs, clockCIDs;
|
38167
38201
|
// if (!event) event = []
|
38168
38202
|
if (event) {
|
38169
|
-
|
38203
|
+
event = event.map((cid) => cid.toString());
|
38204
|
+
const eventKey = JSON.stringify([...event, ...this.clockToJSON()]);
|
38205
|
+
|
38206
|
+
let resp;
|
38207
|
+
if (this.eventsCache.has(eventKey)) {
|
38208
|
+
console.log('events from cache');
|
38209
|
+
resp = this.eventsCache.get(eventKey);
|
38210
|
+
} else {
|
38211
|
+
resp = await eventsSince(this.blocks, this.clock, event);
|
38212
|
+
this.eventsCache.set(eventKey, resp);
|
38213
|
+
}
|
38170
38214
|
const docsMap = new Map();
|
38171
38215
|
for (const { key, type, value } of resp.result.map(decodeEvent)) {
|
38172
38216
|
if (type === 'del') {
|
@@ -38179,7 +38223,9 @@ class Database {
|
|
38179
38223
|
clockCIDs = resp.clockCIDs;
|
38180
38224
|
// console.log('change rows', this.instanceId, rows)
|
38181
38225
|
} else {
|
38182
|
-
const allResp = await getAll(this.blocks, this.clock);
|
38226
|
+
const allResp = await getAll(this.blocks, this.clock, this.rootCache);
|
38227
|
+
this.rootCache = { root: allResp.root, clockCIDs: allResp.clockCIDs };
|
38228
|
+
|
38183
38229
|
rows = allResp.result.map(({ key, value }) => decodeEvent({ key, value }));
|
38184
38230
|
dataCIDs = allResp.cids;
|
38185
38231
|
// console.log('dbdoc rows', this.instanceId, rows)
|
@@ -38192,7 +38238,9 @@ class Database {
|
|
38192
38238
|
}
|
38193
38239
|
|
38194
38240
|
async allDocuments () {
|
38195
|
-
const allResp = await getAll(this.blocks, this.clock);
|
38241
|
+
const allResp = await getAll(this.blocks, this.clock, this.rootCache);
|
38242
|
+
this.rootCache = { root: allResp.root, clockCIDs: allResp.clockCIDs };
|
38243
|
+
|
38196
38244
|
const rows = allResp.result
|
38197
38245
|
.map(({ key, value }) => decodeEvent({ key, value }))
|
38198
38246
|
.map(({ key, value }) => ({ key, value: { _id: key, ...value } }));
|
@@ -38204,7 +38252,8 @@ class Database {
|
|
38204
38252
|
}
|
38205
38253
|
|
38206
38254
|
async allCIDs () {
|
38207
|
-
const allResp = await getAll(this.blocks, this.clock);
|
38255
|
+
const allResp = await getAll(this.blocks, this.clock, this.rootCache, true);
|
38256
|
+
this.rootCache = { root: allResp.root, clockCIDs: allResp.clockCIDs };
|
38208
38257
|
// console.log('allcids', allResp.cids, allResp.clockCIDs)
|
38209
38258
|
const cids = await cidsToProof(allResp.cids);
|
38210
38259
|
const clockCids = await cidsToProof(allResp.clockCIDs);
|
@@ -38250,13 +38299,13 @@ class Database {
|
|
38250
38299
|
*/
|
38251
38300
|
async get (key, opts = {}) {
|
38252
38301
|
const clock = opts.clock || this.clock;
|
38253
|
-
const resp = await get(this.blocks, clock, charwise.encode(key));
|
38254
|
-
|
38302
|
+
const resp = await get(this.blocks, clock, charwise.encode(key), this.rootCache);
|
38303
|
+
this.rootCache = { root: resp.root, clockCIDs: resp.clockCIDs };
|
38255
38304
|
// this tombstone is temporary until we can get the prolly tree to delete
|
38256
38305
|
if (!resp || resp.result === null) {
|
38257
38306
|
throw new Error('Not found')
|
38258
38307
|
}
|
38259
|
-
const doc = resp.result;
|
38308
|
+
const doc = { ...resp.result };
|
38260
38309
|
if (opts.mvcc === true) {
|
38261
38310
|
doc._clock = this.clockToJSON();
|
38262
38311
|
}
|
@@ -38350,7 +38399,9 @@ class Database {
|
|
38350
38399
|
}
|
38351
38400
|
|
38352
38401
|
applyClock (prevClock, newClock) {
|
38353
|
-
// console.log('
|
38402
|
+
// console.log('prevClock', prevClock.length, prevClock.map((cid) => cid.toString()))
|
38403
|
+
// console.log('newClock', newClock.length, newClock.map((cid) => cid.toString()))
|
38404
|
+
// console.log('this.clock', this.clock.length, this.clockToJSON())
|
38354
38405
|
const stPrev = prevClock.map(cid => cid.toString());
|
38355
38406
|
const keptPrevClock = this.clock.filter(cid => stPrev.indexOf(cid.toString()) === -1);
|
38356
38407
|
const merged = keptPrevClock.concat(newClock);
|
@@ -38358,8 +38409,10 @@ class Database {
|
|
38358
38409
|
for (const cid of merged) {
|
38359
38410
|
uniquebyCid.set(cid.toString(), cid);
|
38360
38411
|
}
|
38361
|
-
this.clock = Array.from(uniquebyCid.values());
|
38362
|
-
|
38412
|
+
this.clock = Array.from(uniquebyCid.values()).sort((a, b) => a.toString().localeCompare(b.toString()));
|
38413
|
+
this.rootCache = null;
|
38414
|
+
this.eventsCache.clear();
|
38415
|
+
// console.log('afterClock', this.clock.length, this.clockToJSON())
|
38363
38416
|
}
|
38364
38417
|
|
38365
38418
|
// /**
|
@@ -38695,8 +38748,8 @@ const refCompare = (aRef, bRef) => {
|
|
38695
38748
|
return simpleCompare(aRef, bRef)
|
38696
38749
|
};
|
38697
38750
|
|
38698
|
-
const dbIndexOpts = { cache: nocache, chunker: bf(
|
38699
|
-
const idIndexOpts = { cache: nocache, chunker: bf(
|
38751
|
+
const dbIndexOpts = { cache: nocache, chunker: bf(30), codec: codec$1, hasher: sha256$2, compare };
|
38752
|
+
const idIndexOpts = { cache: nocache, chunker: bf(30), codec: codec$1, hasher: sha256$2, compare: simpleCompare };
|
38700
38753
|
|
38701
38754
|
const makeDoc = ({ key, value }) => ({ _id: key, ...value });
|
38702
38755
|
|
@@ -38753,6 +38806,9 @@ const indexEntriesForChanges = (changes, mapFn) => {
|
|
38753
38806
|
*
|
38754
38807
|
*/
|
38755
38808
|
class DbIndex {
|
38809
|
+
/**
|
38810
|
+
* @param {Database} database
|
38811
|
+
*/
|
38756
38812
|
constructor (database, name, mapFn, clock = null, opts = {}) {
|
38757
38813
|
this.database = database;
|
38758
38814
|
if (!database.indexBlocks) {
|
@@ -38824,6 +38880,14 @@ class DbIndex {
|
|
38824
38880
|
return new DbIndex(database, name, code, clock)
|
38825
38881
|
}
|
38826
38882
|
|
38883
|
+
async visKeyTree () {
|
38884
|
+
return await visMerkleTree(this.database.indexBlocks, this.indexById.cid)
|
38885
|
+
}
|
38886
|
+
|
38887
|
+
async visIdTree () {
|
38888
|
+
return await visMerkleTree(this.database.indexBlocks, this.indexByKey.cid)
|
38889
|
+
}
|
38890
|
+
|
38827
38891
|
/**
|
38828
38892
|
* JSDoc for Query type.
|
38829
38893
|
* @typedef {Object} DbQuery
|
@@ -38993,11 +39057,7 @@ async function doIndexQuery (blocks, indexByKey, query = {}) {
|
|
38993
39057
|
}
|
38994
39058
|
}
|
38995
39059
|
|
38996
|
-
var
|
38997
|
-
var browser = {
|
38998
|
-
get exports(){ return browserExports; },
|
38999
|
-
set exports(v){ browserExports = v; },
|
39000
|
-
};
|
39060
|
+
var browser = {exports: {}};
|
39001
39061
|
|
39002
39062
|
/**
|
39003
39063
|
* Helpers.
|
@@ -39713,8 +39773,10 @@ var common = setup;
|
|
39713
39773
|
} catch (error) {
|
39714
39774
|
return '[UnexpectedJSONParseError]: ' + error.message;
|
39715
39775
|
}
|
39716
|
-
};
|
39717
|
-
} (browser,
|
39776
|
+
};
|
39777
|
+
} (browser, browser.exports));
|
39778
|
+
|
39779
|
+
var browserExports = browser.exports;
|
39718
39780
|
|
39719
39781
|
// originally pulled out of simple-peer
|
39720
39782
|
|
@@ -40865,6 +40927,8 @@ Peer.channelConfig = {};
|
|
40865
40927
|
|
40866
40928
|
var simplePeer = Peer;
|
40867
40929
|
|
40930
|
+
var SimplePeer = /*@__PURE__*/getDefaultExportFromCjs(simplePeer);
|
40931
|
+
|
40868
40932
|
/**
|
40869
40933
|
* @typedef {import('./database.js').Database} Database
|
40870
40934
|
*/
|
@@ -40875,9 +40939,9 @@ class Sync {
|
|
40875
40939
|
* @memberof Sync
|
40876
40940
|
* @static
|
40877
40941
|
*/
|
40878
|
-
constructor (database, PeerClass =
|
40942
|
+
constructor (database, PeerClass = SimplePeer) {
|
40879
40943
|
this.database = database;
|
40880
|
-
this.database.blocks.syncs.add(this);
|
40944
|
+
this.database.blocks.syncs.add(this); // should this happen during setup?
|
40881
40945
|
this.PeerClass = PeerClass;
|
40882
40946
|
this.pushBacklog = new Promise((resolve, reject) => {
|
40883
40947
|
this.pushBacklogResolve = resolve;
|
@@ -40925,8 +40989,13 @@ class Sync {
|
|
40925
40989
|
|
40926
40990
|
async gotData (data) {
|
40927
40991
|
// console.log('got data', data.toString())
|
40992
|
+
let reader = null;
|
40928
40993
|
try {
|
40929
|
-
|
40994
|
+
reader = await CarReader.fromBytes(data);
|
40995
|
+
} catch (e) {
|
40996
|
+
// console.log('not a car', data.toString())
|
40997
|
+
}
|
40998
|
+
if (reader) {
|
40930
40999
|
const blz = new Set();
|
40931
41000
|
for await (const block of reader.blocks()) {
|
40932
41001
|
blz.add(block);
|
@@ -40949,17 +41018,22 @@ class Sync {
|
|
40949
41018
|
get: async cid => await reader.get(cid),
|
40950
41019
|
lastCid: [...blz][0].cid // doesn't matter
|
40951
41020
|
}, false);
|
40952
|
-
|
41021
|
+
// first arg could be the roots parents?
|
41022
|
+
// get the roots parents
|
41023
|
+
const parents = await Promise.all(roots.map(async (cid) => {
|
41024
|
+
const rbl = await reader.get(cid);
|
41025
|
+
if (!rbl) {
|
41026
|
+
console.log('missing root block', cid.toString(), reader);
|
41027
|
+
throw new Error('missing root block')
|
41028
|
+
}
|
41029
|
+
const block = await decodeEventBlock(rbl.bytes);
|
41030
|
+
return block.value.parents
|
41031
|
+
}));
|
41032
|
+
this.database.applyClock(parents.flat(), roots);
|
40953
41033
|
this.database.notifyReset();
|
40954
41034
|
// console.log('after', this.database.clockToJSON())
|
40955
41035
|
this.pushBacklogResolve({ ok: true });
|
40956
|
-
}
|
40957
|
-
// console.error(e)
|
40958
|
-
// if e.message matche 'CBOR' we can ignore it
|
40959
|
-
if (!e.message.match(/CBOR|fromBytes/)) {
|
40960
|
-
throw e
|
40961
|
-
}
|
40962
|
-
|
41036
|
+
} else {
|
40963
41037
|
// data is a json string, parse it
|
40964
41038
|
const message = JSON.parse(data.toString());
|
40965
41039
|
// console.log('got message', message)
|
@@ -40968,7 +41042,7 @@ class Sync {
|
|
40968
41042
|
} else if (message.clock) {
|
40969
41043
|
const reqCidDiff = message;
|
40970
41044
|
// this might be a CID diff
|
40971
|
-
|
41045
|
+
console.log('got diff', reqCidDiff);
|
40972
41046
|
const carBlock = await Sync.makeCar(this.database, null, reqCidDiff.cids);
|
40973
41047
|
if (!carBlock) {
|
40974
41048
|
// we are full synced
|
@@ -40985,7 +41059,7 @@ class Sync {
|
|
40985
41059
|
}
|
40986
41060
|
|
40987
41061
|
async sendUpdate (blockstore) {
|
40988
|
-
console.log('send update from', this.database.instanceId)
|
41062
|
+
// console.log('send update from', this.database.instanceId)
|
40989
41063
|
// todo should send updates since last sync
|
40990
41064
|
const newCar = await blocksToCarBlock(blockstore.lastCid, blockstore);
|
40991
41065
|
this.peer.send(newCar.bytes);
|
@@ -41071,9 +41145,9 @@ class Fireproof {
|
|
41071
41145
|
if (existing) {
|
41072
41146
|
const existingConfig = JSON.parse(existing);
|
41073
41147
|
const fp = new Database(new TransactionBlockstore(name, existingConfig.key), [], opts);
|
41074
|
-
return
|
41148
|
+
return Fireproof.fromJSON(existingConfig, fp)
|
41075
41149
|
} else {
|
41076
|
-
const instanceKey =
|
41150
|
+
const instanceKey = randomBytes$3(32).toString('hex'); // pass null to disable encryption
|
41077
41151
|
return new Database(new TransactionBlockstore(name, instanceKey), [], opts)
|
41078
41152
|
}
|
41079
41153
|
} else {
|
@@ -41114,7 +41188,7 @@ class Fireproof {
|
|
41114
41188
|
index.clock.db = null;
|
41115
41189
|
});
|
41116
41190
|
}
|
41117
|
-
const snappedDb =
|
41191
|
+
const snappedDb = Fireproof.fromJSON(definition, withBlocks)
|
41118
41192
|
;[...database.indexes.values()].forEach(index => {
|
41119
41193
|
snappedDb.indexes.get(index.mapFnString).mapFn = index.mapFn;
|
41120
41194
|
});
|