@fireproof/core 0.5.11 → 0.5.12
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 +12 -11
- package/dist/src/fireproof.js +222 -234
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +222 -234
- package/dist/src/fireproof.mjs.map +1 -1
- package/package.json +1 -1
- package/src/blockstore.js +2 -2
- package/src/sync.js +40 -18
package/dist/src/fireproof.mjs
CHANGED
@@ -9571,15 +9571,7 @@ var _polyfillNode_events = /*#__PURE__*/Object.freeze({
|
|
9571
9571
|
|
9572
9572
|
var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_events);
|
9573
9573
|
|
9574
|
-
var streamBrowser;
|
9575
|
-
var hasRequiredStreamBrowser;
|
9576
|
-
|
9577
|
-
function requireStreamBrowser () {
|
9578
|
-
if (hasRequiredStreamBrowser) return streamBrowser;
|
9579
|
-
hasRequiredStreamBrowser = 1;
|
9580
|
-
streamBrowser = require$$0$1.EventEmitter;
|
9581
|
-
return streamBrowser;
|
9582
|
-
}
|
9574
|
+
var streamBrowser = require$$0$1.EventEmitter;
|
9583
9575
|
|
9584
9576
|
// shim for using process in browser
|
9585
9577
|
// based off https://github.com/defunctzombie/node-process/blob/master/browser.js
|
@@ -9722,7 +9714,7 @@ var argv = [];
|
|
9722
9714
|
var version$2 = ''; // empty string to avoid regexp issues
|
9723
9715
|
var versions = {};
|
9724
9716
|
var release = {};
|
9725
|
-
var config = {};
|
9717
|
+
var config$1 = {};
|
9726
9718
|
|
9727
9719
|
function noop$2() {}
|
9728
9720
|
|
@@ -9799,7 +9791,7 @@ var browser$1$1 = {
|
|
9799
9791
|
hrtime: hrtime,
|
9800
9792
|
platform: platform,
|
9801
9793
|
release: release,
|
9802
|
-
config: config,
|
9794
|
+
config: config$1,
|
9803
9795
|
uptime: uptime
|
9804
9796
|
};
|
9805
9797
|
|
@@ -9880,11 +9872,11 @@ function format(f) {
|
|
9880
9872
|
// Mark that a method should not be used.
|
9881
9873
|
// Returns a modified function which warns once by default.
|
9882
9874
|
// If --no-deprecation is set, then it is a no-op.
|
9883
|
-
function deprecate$
|
9875
|
+
function deprecate$2(fn, msg) {
|
9884
9876
|
// Allow for deprecating things in the process of starting up.
|
9885
9877
|
if (isUndefined(global$1.process)) {
|
9886
9878
|
return function() {
|
9887
|
-
return deprecate$
|
9879
|
+
return deprecate$2(fn, msg).apply(this, arguments);
|
9888
9880
|
};
|
9889
9881
|
}
|
9890
9882
|
|
@@ -10493,7 +10485,7 @@ var _polyfillNode_util = {
|
|
10493
10485
|
isBoolean: isBoolean,
|
10494
10486
|
isArray: isArray,
|
10495
10487
|
inspect: inspect,
|
10496
|
-
deprecate: deprecate$
|
10488
|
+
deprecate: deprecate$2,
|
10497
10489
|
format: format,
|
10498
10490
|
debuglog: debuglog,
|
10499
10491
|
promisify: promisify,
|
@@ -10506,7 +10498,7 @@ var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
|
|
10506
10498
|
callbackify: callbackify,
|
10507
10499
|
debuglog: debuglog,
|
10508
10500
|
default: _polyfillNode_util,
|
10509
|
-
deprecate: deprecate$
|
10501
|
+
deprecate: deprecate$2,
|
10510
10502
|
format: format,
|
10511
10503
|
inherits: inherits$w,
|
10512
10504
|
inspect: inspect,
|
@@ -10694,108 +10686,99 @@ function requireBuffer_list () {
|
|
10694
10686
|
return buffer_list;
|
10695
10687
|
}
|
10696
10688
|
|
10697
|
-
|
10698
|
-
|
10699
|
-
|
10700
|
-
|
10701
|
-
|
10702
|
-
|
10703
|
-
|
10704
|
-
|
10705
|
-
|
10706
|
-
|
10707
|
-
|
10708
|
-
|
10709
|
-
|
10710
|
-
|
10711
|
-
|
10712
|
-
|
10713
|
-
|
10714
|
-
} else if (!this._writableState.errorEmitted) {
|
10715
|
-
this._writableState.errorEmitted = true;
|
10716
|
-
process.nextTick(emitErrorNT, this, err);
|
10717
|
-
}
|
10718
|
-
}
|
10719
|
-
return this;
|
10720
|
-
}
|
10689
|
+
// undocumented cb() API, needed for core, not for public API
|
10690
|
+
function destroy(err, cb) {
|
10691
|
+
const readableDestroyed = this._readableState && this._readableState.destroyed;
|
10692
|
+
const writableDestroyed = this._writableState && this._writableState.destroyed;
|
10693
|
+
if (readableDestroyed || writableDestroyed) {
|
10694
|
+
if (cb) {
|
10695
|
+
cb(err);
|
10696
|
+
} else if (err) {
|
10697
|
+
if (!this._writableState) {
|
10698
|
+
process.nextTick(emitErrorNT, this, err);
|
10699
|
+
} else if (!this._writableState.errorEmitted) {
|
10700
|
+
this._writableState.errorEmitted = true;
|
10701
|
+
process.nextTick(emitErrorNT, this, err);
|
10702
|
+
}
|
10703
|
+
}
|
10704
|
+
return this;
|
10705
|
+
}
|
10721
10706
|
|
10722
|
-
|
10723
|
-
|
10707
|
+
// we set destroyed to true before firing error callbacks in order
|
10708
|
+
// to make it re-entrance safe in case destroy() is called within callbacks
|
10724
10709
|
|
10725
|
-
|
10726
|
-
|
10727
|
-
|
10710
|
+
if (this._readableState) {
|
10711
|
+
this._readableState.destroyed = true;
|
10712
|
+
}
|
10728
10713
|
|
10729
|
-
|
10730
|
-
|
10731
|
-
|
10732
|
-
|
10733
|
-
|
10734
|
-
|
10735
|
-
|
10736
|
-
|
10737
|
-
|
10738
|
-
|
10739
|
-
|
10740
|
-
|
10741
|
-
|
10742
|
-
|
10743
|
-
|
10744
|
-
|
10745
|
-
|
10746
|
-
|
10747
|
-
|
10748
|
-
|
10749
|
-
|
10750
|
-
|
10751
|
-
|
10752
|
-
|
10753
|
-
|
10754
|
-
|
10755
|
-
|
10756
|
-
|
10757
|
-
|
10758
|
-
|
10759
|
-
|
10760
|
-
|
10761
|
-
|
10762
|
-
|
10763
|
-
|
10764
|
-
|
10765
|
-
|
10766
|
-
|
10767
|
-
|
10768
|
-
|
10769
|
-
|
10770
|
-
|
10771
|
-
|
10772
|
-
|
10773
|
-
|
10774
|
-
|
10775
|
-
|
10776
|
-
|
10777
|
-
|
10778
|
-
|
10779
|
-
|
10780
|
-
|
10781
|
-
|
10782
|
-
|
10783
|
-
|
10784
|
-
|
10785
|
-
|
10786
|
-
|
10787
|
-
|
10788
|
-
|
10789
|
-
|
10790
|
-
|
10791
|
-
}
|
10792
|
-
destroy_1 = {
|
10793
|
-
destroy,
|
10794
|
-
undestroy,
|
10795
|
-
errorOrDestroy
|
10796
|
-
};
|
10797
|
-
return destroy_1;
|
10714
|
+
// if this is a duplex stream mark the writable part as destroyed as well
|
10715
|
+
if (this._writableState) {
|
10716
|
+
this._writableState.destroyed = true;
|
10717
|
+
}
|
10718
|
+
this._destroy(err || null, err => {
|
10719
|
+
if (!cb && err) {
|
10720
|
+
if (!this._writableState) {
|
10721
|
+
process.nextTick(emitErrorAndCloseNT, this, err);
|
10722
|
+
} else if (!this._writableState.errorEmitted) {
|
10723
|
+
this._writableState.errorEmitted = true;
|
10724
|
+
process.nextTick(emitErrorAndCloseNT, this, err);
|
10725
|
+
} else {
|
10726
|
+
process.nextTick(emitCloseNT, this);
|
10727
|
+
}
|
10728
|
+
} else if (cb) {
|
10729
|
+
process.nextTick(emitCloseNT, this);
|
10730
|
+
cb(err);
|
10731
|
+
} else {
|
10732
|
+
process.nextTick(emitCloseNT, this);
|
10733
|
+
}
|
10734
|
+
});
|
10735
|
+
return this;
|
10736
|
+
}
|
10737
|
+
function emitErrorAndCloseNT(self, err) {
|
10738
|
+
emitErrorNT(self, err);
|
10739
|
+
emitCloseNT(self);
|
10740
|
+
}
|
10741
|
+
function emitCloseNT(self) {
|
10742
|
+
if (self._writableState && !self._writableState.emitClose) return;
|
10743
|
+
if (self._readableState && !self._readableState.emitClose) return;
|
10744
|
+
self.emit('close');
|
10745
|
+
}
|
10746
|
+
function undestroy() {
|
10747
|
+
if (this._readableState) {
|
10748
|
+
this._readableState.destroyed = false;
|
10749
|
+
this._readableState.reading = false;
|
10750
|
+
this._readableState.ended = false;
|
10751
|
+
this._readableState.endEmitted = false;
|
10752
|
+
}
|
10753
|
+
if (this._writableState) {
|
10754
|
+
this._writableState.destroyed = false;
|
10755
|
+
this._writableState.ended = false;
|
10756
|
+
this._writableState.ending = false;
|
10757
|
+
this._writableState.finalCalled = false;
|
10758
|
+
this._writableState.prefinished = false;
|
10759
|
+
this._writableState.finished = false;
|
10760
|
+
this._writableState.errorEmitted = false;
|
10761
|
+
}
|
10762
|
+
}
|
10763
|
+
function emitErrorNT(self, err) {
|
10764
|
+
self.emit('error', err);
|
10765
|
+
}
|
10766
|
+
function errorOrDestroy(stream, err) {
|
10767
|
+
// We have tests that rely on errors being emitted
|
10768
|
+
// in the same tick, so changing this is semver major.
|
10769
|
+
// For now when you opt-in to autoDestroy we allow
|
10770
|
+
// the error to be emitted nextTick. In a future
|
10771
|
+
// semver major update we should change the default to this.
|
10772
|
+
|
10773
|
+
const rState = stream._readableState;
|
10774
|
+
const wState = stream._writableState;
|
10775
|
+
if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
|
10798
10776
|
}
|
10777
|
+
var destroy_1 = {
|
10778
|
+
destroy,
|
10779
|
+
undestroy,
|
10780
|
+
errorOrDestroy
|
10781
|
+
};
|
10799
10782
|
|
10800
10783
|
var errorsBrowser = {};
|
10801
10784
|
|
@@ -10925,109 +10908,92 @@ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
|
|
10925
10908
|
createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
|
10926
10909
|
errorsBrowser.codes = codes;
|
10927
10910
|
|
10928
|
-
|
10929
|
-
|
10930
|
-
|
10931
|
-
function requireState () {
|
10932
|
-
if (hasRequiredState) return state;
|
10933
|
-
hasRequiredState = 1;
|
10934
|
-
|
10935
|
-
const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
|
10936
|
-
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
10937
|
-
return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
|
10938
|
-
}
|
10939
|
-
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
10940
|
-
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
10941
|
-
if (hwm != null) {
|
10942
|
-
if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
|
10943
|
-
const name = isDuplex ? duplexKey : 'highWaterMark';
|
10944
|
-
throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
10945
|
-
}
|
10946
|
-
return Math.floor(hwm);
|
10947
|
-
}
|
10948
|
-
|
10949
|
-
// Default value
|
10950
|
-
return state.objectMode ? 16 : 16 * 1024;
|
10951
|
-
}
|
10952
|
-
state = {
|
10953
|
-
getHighWaterMark
|
10954
|
-
};
|
10955
|
-
return state;
|
10911
|
+
const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
|
10912
|
+
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
10913
|
+
return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
|
10956
10914
|
}
|
10915
|
+
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
10916
|
+
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
10917
|
+
if (hwm != null) {
|
10918
|
+
if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
|
10919
|
+
const name = isDuplex ? duplexKey : 'highWaterMark';
|
10920
|
+
throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
10921
|
+
}
|
10922
|
+
return Math.floor(hwm);
|
10923
|
+
}
|
10957
10924
|
|
10958
|
-
|
10959
|
-
|
10925
|
+
// Default value
|
10926
|
+
return state.objectMode ? 16 : 16 * 1024;
|
10927
|
+
}
|
10928
|
+
var state = {
|
10929
|
+
getHighWaterMark
|
10930
|
+
};
|
10960
10931
|
|
10961
|
-
|
10962
|
-
|
10963
|
-
|
10964
|
-
/**
|
10965
|
-
* Module exports.
|
10966
|
-
*/
|
10932
|
+
/**
|
10933
|
+
* Module exports.
|
10934
|
+
*/
|
10967
10935
|
|
10968
|
-
|
10936
|
+
var browser$b = deprecate$1;
|
10969
10937
|
|
10970
|
-
|
10971
|
-
|
10972
|
-
|
10973
|
-
|
10974
|
-
|
10975
|
-
|
10976
|
-
|
10977
|
-
|
10978
|
-
|
10979
|
-
|
10980
|
-
|
10981
|
-
|
10982
|
-
|
10983
|
-
|
10984
|
-
|
10985
|
-
|
10986
|
-
|
10938
|
+
/**
|
10939
|
+
* Mark that a method should not be used.
|
10940
|
+
* Returns a modified function which warns once by default.
|
10941
|
+
*
|
10942
|
+
* If `localStorage.noDeprecation = true` is set, then it is a no-op.
|
10943
|
+
*
|
10944
|
+
* If `localStorage.throwDeprecation = true` is set, then deprecated functions
|
10945
|
+
* will throw an Error when invoked.
|
10946
|
+
*
|
10947
|
+
* If `localStorage.traceDeprecation = true` is set, then deprecated functions
|
10948
|
+
* will invoke `console.trace()` instead of `console.error()`.
|
10949
|
+
*
|
10950
|
+
* @param {Function} fn - the function to deprecate
|
10951
|
+
* @param {String} msg - the string to print to the console when `fn` is invoked
|
10952
|
+
* @returns {Function} a new "deprecated" version of `fn`
|
10953
|
+
* @api public
|
10954
|
+
*/
|
10987
10955
|
|
10988
|
-
|
10989
|
-
|
10990
|
-
|
10991
|
-
|
10956
|
+
function deprecate$1 (fn, msg) {
|
10957
|
+
if (config('noDeprecation')) {
|
10958
|
+
return fn;
|
10959
|
+
}
|
10992
10960
|
|
10993
|
-
|
10994
|
-
|
10995
|
-
|
10996
|
-
|
10997
|
-
|
10998
|
-
|
10999
|
-
|
11000
|
-
|
11001
|
-
|
11002
|
-
|
11003
|
-
|
11004
|
-
|
11005
|
-
|
11006
|
-
|
10961
|
+
var warned = false;
|
10962
|
+
function deprecated() {
|
10963
|
+
if (!warned) {
|
10964
|
+
if (config('throwDeprecation')) {
|
10965
|
+
throw new Error(msg);
|
10966
|
+
} else if (config('traceDeprecation')) {
|
10967
|
+
console.trace(msg);
|
10968
|
+
} else {
|
10969
|
+
console.warn(msg);
|
10970
|
+
}
|
10971
|
+
warned = true;
|
10972
|
+
}
|
10973
|
+
return fn.apply(this, arguments);
|
10974
|
+
}
|
11007
10975
|
|
11008
|
-
|
11009
|
-
|
10976
|
+
return deprecated;
|
10977
|
+
}
|
11010
10978
|
|
11011
|
-
|
11012
|
-
|
11013
|
-
|
11014
|
-
|
11015
|
-
|
11016
|
-
|
11017
|
-
|
10979
|
+
/**
|
10980
|
+
* Checks `localStorage` for boolean values for the given `name`.
|
10981
|
+
*
|
10982
|
+
* @param {String} name
|
10983
|
+
* @returns {Boolean}
|
10984
|
+
* @api private
|
10985
|
+
*/
|
11018
10986
|
|
11019
|
-
|
11020
|
-
|
11021
|
-
|
11022
|
-
|
11023
|
-
|
11024
|
-
|
11025
|
-
|
11026
|
-
|
11027
|
-
|
11028
|
-
|
11029
|
-
}
|
11030
|
-
return browser$b;
|
10987
|
+
function config (name) {
|
10988
|
+
// accessing global.localStorage can trigger a DOMException in sandboxed iframes
|
10989
|
+
try {
|
10990
|
+
if (!commonjsGlobal.localStorage) return false;
|
10991
|
+
} catch (_) {
|
10992
|
+
return false;
|
10993
|
+
}
|
10994
|
+
var val = commonjsGlobal.localStorage[name];
|
10995
|
+
if (null == val) return false;
|
10996
|
+
return String(val).toLowerCase() === 'true';
|
11031
10997
|
}
|
11032
10998
|
|
11033
10999
|
var _stream_writable;
|
@@ -11058,12 +11024,12 @@ function require_stream_writable () {
|
|
11058
11024
|
|
11059
11025
|
/*<replacement>*/
|
11060
11026
|
const internalUtil = {
|
11061
|
-
deprecate:
|
11027
|
+
deprecate: browser$b
|
11062
11028
|
};
|
11063
11029
|
/*</replacement>*/
|
11064
11030
|
|
11065
11031
|
/*<replacement>*/
|
11066
|
-
var Stream =
|
11032
|
+
var Stream = streamBrowser;
|
11067
11033
|
/*</replacement>*/
|
11068
11034
|
|
11069
11035
|
const Buffer = require$$6$1.Buffer;
|
@@ -11074,8 +11040,8 @@ function require_stream_writable () {
|
|
11074
11040
|
function _isUint8Array(obj) {
|
11075
11041
|
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
11076
11042
|
}
|
11077
|
-
const destroyImpl =
|
11078
|
-
const _require =
|
11043
|
+
const destroyImpl = destroy_1;
|
11044
|
+
const _require = state,
|
11079
11045
|
getHighWaterMark = _require.getHighWaterMark;
|
11080
11046
|
const _require$codes = errorsBrowser.codes,
|
11081
11047
|
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
@@ -12269,7 +12235,7 @@ function require_stream_readable () {
|
|
12269
12235
|
/*</replacement>*/
|
12270
12236
|
|
12271
12237
|
/*<replacement>*/
|
12272
|
-
var Stream =
|
12238
|
+
var Stream = streamBrowser;
|
12273
12239
|
/*</replacement>*/
|
12274
12240
|
|
12275
12241
|
const Buffer = require$$6$1.Buffer;
|
@@ -12292,8 +12258,8 @@ function require_stream_readable () {
|
|
12292
12258
|
/*</replacement>*/
|
12293
12259
|
|
12294
12260
|
const BufferList = requireBuffer_list();
|
12295
|
-
const destroyImpl =
|
12296
|
-
const _require =
|
12261
|
+
const destroyImpl = destroy_1;
|
12262
|
+
const _require = state,
|
12297
12263
|
getHighWaterMark = _require.getHighWaterMark;
|
12298
12264
|
const _require$codes = errorsBrowser.codes,
|
12299
12265
|
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
@@ -15659,7 +15625,7 @@ function WriteReq(chunk, encoding, cb) {
|
|
15659
15625
|
|
15660
15626
|
function WritableState(options, stream) {
|
15661
15627
|
Object.defineProperty(this, 'buffer', {
|
15662
|
-
get: deprecate$
|
15628
|
+
get: deprecate$2(function () {
|
15663
15629
|
return this.getBuffer();
|
15664
15630
|
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
|
15665
15631
|
});
|
@@ -37408,8 +37374,8 @@ class TransactionBlockstore {
|
|
37408
37374
|
if (doSync) {
|
37409
37375
|
// const all =
|
37410
37376
|
await Promise.all([...this.syncs].map(async sync => sync.sendUpdate(innerBlockstore).catch(e => {
|
37411
|
-
console.error('sync error', e);
|
37412
|
-
|
37377
|
+
console.error('sync error, cancelling', e);
|
37378
|
+
sync.destroy();
|
37413
37379
|
})));
|
37414
37380
|
}
|
37415
37381
|
}
|
@@ -41046,6 +41012,7 @@ class Sync {
|
|
41046
41012
|
* @memberof Sync
|
41047
41013
|
* @static
|
41048
41014
|
*/
|
41015
|
+
status = 'new'
|
41049
41016
|
constructor (database, PeerClass = simplePeer) {
|
41050
41017
|
this.database = database;
|
41051
41018
|
this.database.blocks.syncs.add(this); // should this happen during setup?
|
@@ -41061,6 +41028,7 @@ class Sync {
|
|
41061
41028
|
}
|
41062
41029
|
|
41063
41030
|
async offer () {
|
41031
|
+
this.status = 'offering';
|
41064
41032
|
return this.setupPeer(true)
|
41065
41033
|
}
|
41066
41034
|
|
@@ -41068,11 +41036,13 @@ class Sync {
|
|
41068
41036
|
const offer = JSON.parse(atob(base64offer));
|
41069
41037
|
const p = this.setupPeer(false);
|
41070
41038
|
this.peer.signal(offer);
|
41039
|
+
this.status = 'accepting';
|
41071
41040
|
return p
|
41072
41041
|
}
|
41073
41042
|
|
41074
41043
|
connect (base64accept) {
|
41075
41044
|
const accept = JSON.parse(atob(base64accept));
|
41045
|
+
this.status = 'connecting';
|
41076
41046
|
this.peer.signal(accept);
|
41077
41047
|
}
|
41078
41048
|
|
@@ -41103,6 +41073,7 @@ class Sync {
|
|
41103
41073
|
// console.log('not a car', data.toString())
|
41104
41074
|
}
|
41105
41075
|
if (reader) {
|
41076
|
+
this.status = 'parking car';
|
41106
41077
|
const blz = new Set();
|
41107
41078
|
for await (const block of reader.blocks()) {
|
41108
41079
|
blz.add(block);
|
@@ -41119,23 +41090,28 @@ class Sync {
|
|
41119
41090
|
// )
|
41120
41091
|
// @ts-ignore
|
41121
41092
|
reader.entries = reader.blocks;
|
41122
|
-
await this.database.blocks.commit(
|
41123
|
-
|
41124
|
-
|
41125
|
-
|
41126
|
-
|
41127
|
-
|
41093
|
+
await this.database.blocks.commit(
|
41094
|
+
{
|
41095
|
+
label: 'sync',
|
41096
|
+
entries: () => [...blz],
|
41097
|
+
get: async cid => await reader.get(cid),
|
41098
|
+
lastCid: [...blz][0].cid // doesn't matter
|
41099
|
+
},
|
41100
|
+
false
|
41101
|
+
);
|
41128
41102
|
// first arg could be the roots parents?
|
41129
41103
|
// get the roots parents
|
41130
|
-
const parents = await Promise.all(
|
41131
|
-
|
41132
|
-
|
41133
|
-
|
41134
|
-
|
41135
|
-
|
41136
|
-
|
41137
|
-
|
41138
|
-
|
41104
|
+
const parents = await Promise.all(
|
41105
|
+
roots.map(async cid => {
|
41106
|
+
const rbl = await reader.get(cid);
|
41107
|
+
if (!rbl) {
|
41108
|
+
console.log('missing root block', cid.toString(), reader);
|
41109
|
+
throw new Error('missing root block')
|
41110
|
+
}
|
41111
|
+
const block = await decodeEventBlock(rbl.bytes);
|
41112
|
+
return block.value.parents
|
41113
|
+
})
|
41114
|
+
);
|
41139
41115
|
this.database.applyClock(parents.flat(), roots);
|
41140
41116
|
this.database.notifyReset();
|
41141
41117
|
// console.log('after', this.database.clockToJSON())
|
@@ -41145,6 +41121,7 @@ class Sync {
|
|
41145
41121
|
const message = JSON.parse(data.toString());
|
41146
41122
|
// console.log('got message', message)
|
41147
41123
|
if (message.ok) {
|
41124
|
+
this.status = 'ok';
|
41148
41125
|
this.pushBacklogResolve({ ok: true });
|
41149
41126
|
} else if (message.clock) {
|
41150
41127
|
const reqCidDiff = message;
|
@@ -41152,12 +41129,14 @@ class Sync {
|
|
41152
41129
|
console.log('got diff', reqCidDiff);
|
41153
41130
|
const carBlock = await Sync.makeCar(this.database, null, reqCidDiff.cids);
|
41154
41131
|
if (!carBlock) {
|
41155
|
-
|
41156
|
-
|
41132
|
+
// we are full synced
|
41133
|
+
// console.log('we are full synced')
|
41134
|
+
this.status = 'full synced';
|
41157
41135
|
this.peer.send(JSON.stringify({ ok: true }));
|
41158
41136
|
// this.pushBacklogResolve({ ok: true })
|
41159
41137
|
} else {
|
41160
|
-
|
41138
|
+
// console.log('do send', carBlock.bytes.length)
|
41139
|
+
this.status = 'sending diff car';
|
41161
41140
|
this.peer.send(carBlock.bytes);
|
41162
41141
|
// this.pushBacklogResolve({ ok: true })
|
41163
41142
|
}
|
@@ -41165,10 +41144,18 @@ class Sync {
|
|
41165
41144
|
}
|
41166
41145
|
}
|
41167
41146
|
|
41147
|
+
destroy () {
|
41148
|
+
this.database.blocks.syncs.delete(this);
|
41149
|
+
this.status = 'destroyed';
|
41150
|
+
this.peer.destroy();
|
41151
|
+
}
|
41152
|
+
|
41168
41153
|
async sendUpdate (blockstore) {
|
41154
|
+
if (!this.peer) return
|
41169
41155
|
// console.log('send update from', this.database.instanceId)
|
41170
41156
|
// todo should send updates since last sync
|
41171
41157
|
const newCar = await blocksToCarBlock(blockstore.lastCid, blockstore);
|
41158
|
+
this.status = 'sending update car';
|
41172
41159
|
this.peer.send(newCar.bytes);
|
41173
41160
|
}
|
41174
41161
|
|
@@ -41181,6 +41168,7 @@ class Sync {
|
|
41181
41168
|
cids: allCIDs.map(cid => cid.toString())
|
41182
41169
|
};
|
41183
41170
|
// console.log('send diff', reqCidDiff)
|
41171
|
+
this.status = 'sending cid diff';
|
41184
41172
|
this.peer.send(JSON.stringify(reqCidDiff));
|
41185
41173
|
}
|
41186
41174
|
|