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