@fireproof/core 0.7.2-dev.2 → 0.7.2-dev.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/database.js CHANGED
@@ -78,6 +78,7 @@ export class Database {
78
78
  * @instance
79
79
  */
80
80
  toJSON() {
81
+ // todo this prepareHeader ignores secondary storage, need both
81
82
  return this.blocks.valet ? this.blocks.valet.primary.prepareHeader(this.toHeader(), false) : this.toHeader(); // omg
82
83
  }
83
84
  toHeader() {
@@ -11480,15 +11480,7 @@ var _polyfillNode_events = /*#__PURE__*/Object.freeze({
11480
11480
 
11481
11481
  var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_events);
11482
11482
 
11483
- var streamBrowser;
11484
- var hasRequiredStreamBrowser;
11485
-
11486
- function requireStreamBrowser () {
11487
- if (hasRequiredStreamBrowser) return streamBrowser;
11488
- hasRequiredStreamBrowser = 1;
11489
- streamBrowser = require$$0$1.EventEmitter;
11490
- return streamBrowser;
11491
- }
11483
+ var streamBrowser = require$$0$1.EventEmitter;
11492
11484
 
11493
11485
  // shim for using process in browser
11494
11486
  // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
@@ -11631,7 +11623,7 @@ var argv = [];
11631
11623
  var version$1 = ''; // empty string to avoid regexp issues
11632
11624
  var versions = {};
11633
11625
  var release = {};
11634
- var config = {};
11626
+ var config$1 = {};
11635
11627
 
11636
11628
  function noop$2() {}
11637
11629
 
@@ -11708,7 +11700,7 @@ var browser$1$1 = {
11708
11700
  hrtime: hrtime,
11709
11701
  platform: platform,
11710
11702
  release: release,
11711
- config: config,
11703
+ config: config$1,
11712
11704
  uptime: uptime
11713
11705
  };
11714
11706
 
@@ -11789,11 +11781,11 @@ function format(f) {
11789
11781
  // Mark that a method should not be used.
11790
11782
  // Returns a modified function which warns once by default.
11791
11783
  // If --no-deprecation is set, then it is a no-op.
11792
- function deprecate(fn, msg) {
11784
+ function deprecate$1(fn, msg) {
11793
11785
  // Allow for deprecating things in the process of starting up.
11794
11786
  if (isUndefined(global$1.process)) {
11795
11787
  return function() {
11796
- return deprecate(fn, msg).apply(this, arguments);
11788
+ return deprecate$1(fn, msg).apply(this, arguments);
11797
11789
  };
11798
11790
  }
11799
11791
 
@@ -12402,7 +12394,7 @@ var _polyfillNode_util = {
12402
12394
  isBoolean: isBoolean,
12403
12395
  isArray: isArray,
12404
12396
  inspect: inspect,
12405
- deprecate: deprecate,
12397
+ deprecate: deprecate$1,
12406
12398
  format: format,
12407
12399
  debuglog: debuglog,
12408
12400
  promisify: promisify,
@@ -12415,7 +12407,7 @@ var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
12415
12407
  callbackify: callbackify,
12416
12408
  debuglog: debuglog,
12417
12409
  default: _polyfillNode_util,
12418
- deprecate: deprecate,
12410
+ deprecate: deprecate$1,
12419
12411
  format: format,
12420
12412
  inherits: inherits$1,
12421
12413
  inspect: inspect,
@@ -12603,108 +12595,99 @@ function requireBuffer_list () {
12603
12595
  return buffer_list;
12604
12596
  }
12605
12597
 
12606
- var destroy_1;
12607
- var hasRequiredDestroy;
12608
-
12609
- function requireDestroy () {
12610
- if (hasRequiredDestroy) return destroy_1;
12611
- hasRequiredDestroy = 1;
12612
-
12613
- // undocumented cb() API, needed for core, not for public API
12614
- function destroy(err, cb) {
12615
- const readableDestroyed = this._readableState && this._readableState.destroyed;
12616
- const writableDestroyed = this._writableState && this._writableState.destroyed;
12617
- if (readableDestroyed || writableDestroyed) {
12618
- if (cb) {
12619
- cb(err);
12620
- } else if (err) {
12621
- if (!this._writableState) {
12622
- process.nextTick(emitErrorNT, this, err);
12623
- } else if (!this._writableState.errorEmitted) {
12624
- this._writableState.errorEmitted = true;
12625
- process.nextTick(emitErrorNT, this, err);
12626
- }
12627
- }
12628
- return this;
12629
- }
12598
+ // undocumented cb() API, needed for core, not for public API
12599
+ function destroy(err, cb) {
12600
+ const readableDestroyed = this._readableState && this._readableState.destroyed;
12601
+ const writableDestroyed = this._writableState && this._writableState.destroyed;
12602
+ if (readableDestroyed || writableDestroyed) {
12603
+ if (cb) {
12604
+ cb(err);
12605
+ } else if (err) {
12606
+ if (!this._writableState) {
12607
+ process.nextTick(emitErrorNT, this, err);
12608
+ } else if (!this._writableState.errorEmitted) {
12609
+ this._writableState.errorEmitted = true;
12610
+ process.nextTick(emitErrorNT, this, err);
12611
+ }
12612
+ }
12613
+ return this;
12614
+ }
12630
12615
 
12631
- // we set destroyed to true before firing error callbacks in order
12632
- // to make it re-entrance safe in case destroy() is called within callbacks
12616
+ // we set destroyed to true before firing error callbacks in order
12617
+ // to make it re-entrance safe in case destroy() is called within callbacks
12633
12618
 
12634
- if (this._readableState) {
12635
- this._readableState.destroyed = true;
12636
- }
12619
+ if (this._readableState) {
12620
+ this._readableState.destroyed = true;
12621
+ }
12637
12622
 
12638
- // if this is a duplex stream mark the writable part as destroyed as well
12639
- if (this._writableState) {
12640
- this._writableState.destroyed = true;
12641
- }
12642
- this._destroy(err || null, err => {
12643
- if (!cb && err) {
12644
- if (!this._writableState) {
12645
- process.nextTick(emitErrorAndCloseNT, this, err);
12646
- } else if (!this._writableState.errorEmitted) {
12647
- this._writableState.errorEmitted = true;
12648
- process.nextTick(emitErrorAndCloseNT, this, err);
12649
- } else {
12650
- process.nextTick(emitCloseNT, this);
12651
- }
12652
- } else if (cb) {
12653
- process.nextTick(emitCloseNT, this);
12654
- cb(err);
12655
- } else {
12656
- process.nextTick(emitCloseNT, this);
12657
- }
12658
- });
12659
- return this;
12660
- }
12661
- function emitErrorAndCloseNT(self, err) {
12662
- emitErrorNT(self, err);
12663
- emitCloseNT(self);
12664
- }
12665
- function emitCloseNT(self) {
12666
- if (self._writableState && !self._writableState.emitClose) return;
12667
- if (self._readableState && !self._readableState.emitClose) return;
12668
- self.emit('close');
12669
- }
12670
- function undestroy() {
12671
- if (this._readableState) {
12672
- this._readableState.destroyed = false;
12673
- this._readableState.reading = false;
12674
- this._readableState.ended = false;
12675
- this._readableState.endEmitted = false;
12676
- }
12677
- if (this._writableState) {
12678
- this._writableState.destroyed = false;
12679
- this._writableState.ended = false;
12680
- this._writableState.ending = false;
12681
- this._writableState.finalCalled = false;
12682
- this._writableState.prefinished = false;
12683
- this._writableState.finished = false;
12684
- this._writableState.errorEmitted = false;
12685
- }
12686
- }
12687
- function emitErrorNT(self, err) {
12688
- self.emit('error', err);
12689
- }
12690
- function errorOrDestroy(stream, err) {
12691
- // We have tests that rely on errors being emitted
12692
- // in the same tick, so changing this is semver major.
12693
- // For now when you opt-in to autoDestroy we allow
12694
- // the error to be emitted nextTick. In a future
12695
- // semver major update we should change the default to this.
12623
+ // if this is a duplex stream mark the writable part as destroyed as well
12624
+ if (this._writableState) {
12625
+ this._writableState.destroyed = true;
12626
+ }
12627
+ this._destroy(err || null, err => {
12628
+ if (!cb && err) {
12629
+ if (!this._writableState) {
12630
+ process.nextTick(emitErrorAndCloseNT, this, err);
12631
+ } else if (!this._writableState.errorEmitted) {
12632
+ this._writableState.errorEmitted = true;
12633
+ process.nextTick(emitErrorAndCloseNT, this, err);
12634
+ } else {
12635
+ process.nextTick(emitCloseNT, this);
12636
+ }
12637
+ } else if (cb) {
12638
+ process.nextTick(emitCloseNT, this);
12639
+ cb(err);
12640
+ } else {
12641
+ process.nextTick(emitCloseNT, this);
12642
+ }
12643
+ });
12644
+ return this;
12645
+ }
12646
+ function emitErrorAndCloseNT(self, err) {
12647
+ emitErrorNT(self, err);
12648
+ emitCloseNT(self);
12649
+ }
12650
+ function emitCloseNT(self) {
12651
+ if (self._writableState && !self._writableState.emitClose) return;
12652
+ if (self._readableState && !self._readableState.emitClose) return;
12653
+ self.emit('close');
12654
+ }
12655
+ function undestroy() {
12656
+ if (this._readableState) {
12657
+ this._readableState.destroyed = false;
12658
+ this._readableState.reading = false;
12659
+ this._readableState.ended = false;
12660
+ this._readableState.endEmitted = false;
12661
+ }
12662
+ if (this._writableState) {
12663
+ this._writableState.destroyed = false;
12664
+ this._writableState.ended = false;
12665
+ this._writableState.ending = false;
12666
+ this._writableState.finalCalled = false;
12667
+ this._writableState.prefinished = false;
12668
+ this._writableState.finished = false;
12669
+ this._writableState.errorEmitted = false;
12670
+ }
12671
+ }
12672
+ function emitErrorNT(self, err) {
12673
+ self.emit('error', err);
12674
+ }
12675
+ function errorOrDestroy(stream, err) {
12676
+ // We have tests that rely on errors being emitted
12677
+ // in the same tick, so changing this is semver major.
12678
+ // For now when you opt-in to autoDestroy we allow
12679
+ // the error to be emitted nextTick. In a future
12680
+ // semver major update we should change the default to this.
12696
12681
 
12697
- const rState = stream._readableState;
12698
- const wState = stream._writableState;
12699
- if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
12700
- }
12701
- destroy_1 = {
12702
- destroy,
12703
- undestroy,
12704
- errorOrDestroy
12705
- };
12706
- return destroy_1;
12682
+ const rState = stream._readableState;
12683
+ const wState = stream._writableState;
12684
+ if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
12707
12685
  }
12686
+ var destroy_1 = {
12687
+ destroy,
12688
+ undestroy,
12689
+ errorOrDestroy
12690
+ };
12708
12691
 
12709
12692
  var errorsBrowser = {};
12710
12693
 
@@ -12834,109 +12817,92 @@ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
12834
12817
  createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
12835
12818
  errorsBrowser.codes = codes;
12836
12819
 
12837
- var state;
12838
- var hasRequiredState;
12839
-
12840
- function requireState () {
12841
- if (hasRequiredState) return state;
12842
- hasRequiredState = 1;
12843
-
12844
- const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
12845
- function highWaterMarkFrom(options, isDuplex, duplexKey) {
12846
- return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
12847
- }
12848
- function getHighWaterMark(state, options, duplexKey, isDuplex) {
12849
- const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
12850
- if (hwm != null) {
12851
- if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
12852
- const name = isDuplex ? duplexKey : 'highWaterMark';
12853
- throw new ERR_INVALID_OPT_VALUE(name, hwm);
12854
- }
12855
- return Math.floor(hwm);
12856
- }
12857
-
12858
- // Default value
12859
- return state.objectMode ? 16 : 16 * 1024;
12860
- }
12861
- state = {
12862
- getHighWaterMark
12863
- };
12864
- return state;
12820
+ const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
12821
+ function highWaterMarkFrom(options, isDuplex, duplexKey) {
12822
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
12865
12823
  }
12824
+ function getHighWaterMark(state, options, duplexKey, isDuplex) {
12825
+ const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
12826
+ if (hwm != null) {
12827
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
12828
+ const name = isDuplex ? duplexKey : 'highWaterMark';
12829
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
12830
+ }
12831
+ return Math.floor(hwm);
12832
+ }
12866
12833
 
12867
- var browser$b;
12868
- var hasRequiredBrowser$a;
12834
+ // Default value
12835
+ return state.objectMode ? 16 : 16 * 1024;
12836
+ }
12837
+ var state = {
12838
+ getHighWaterMark
12839
+ };
12869
12840
 
12870
- function requireBrowser$a () {
12871
- if (hasRequiredBrowser$a) return browser$b;
12872
- hasRequiredBrowser$a = 1;
12873
- /**
12874
- * Module exports.
12875
- */
12841
+ /**
12842
+ * Module exports.
12843
+ */
12876
12844
 
12877
- browser$b = deprecate;
12845
+ var browser$b = deprecate;
12878
12846
 
12879
- /**
12880
- * Mark that a method should not be used.
12881
- * Returns a modified function which warns once by default.
12882
- *
12883
- * If `localStorage.noDeprecation = true` is set, then it is a no-op.
12884
- *
12885
- * If `localStorage.throwDeprecation = true` is set, then deprecated functions
12886
- * will throw an Error when invoked.
12887
- *
12888
- * If `localStorage.traceDeprecation = true` is set, then deprecated functions
12889
- * will invoke `console.trace()` instead of `console.error()`.
12890
- *
12891
- * @param {Function} fn - the function to deprecate
12892
- * @param {String} msg - the string to print to the console when `fn` is invoked
12893
- * @returns {Function} a new "deprecated" version of `fn`
12894
- * @api public
12895
- */
12847
+ /**
12848
+ * Mark that a method should not be used.
12849
+ * Returns a modified function which warns once by default.
12850
+ *
12851
+ * If `localStorage.noDeprecation = true` is set, then it is a no-op.
12852
+ *
12853
+ * If `localStorage.throwDeprecation = true` is set, then deprecated functions
12854
+ * will throw an Error when invoked.
12855
+ *
12856
+ * If `localStorage.traceDeprecation = true` is set, then deprecated functions
12857
+ * will invoke `console.trace()` instead of `console.error()`.
12858
+ *
12859
+ * @param {Function} fn - the function to deprecate
12860
+ * @param {String} msg - the string to print to the console when `fn` is invoked
12861
+ * @returns {Function} a new "deprecated" version of `fn`
12862
+ * @api public
12863
+ */
12896
12864
 
12897
- function deprecate (fn, msg) {
12898
- if (config('noDeprecation')) {
12899
- return fn;
12900
- }
12865
+ function deprecate (fn, msg) {
12866
+ if (config('noDeprecation')) {
12867
+ return fn;
12868
+ }
12901
12869
 
12902
- var warned = false;
12903
- function deprecated() {
12904
- if (!warned) {
12905
- if (config('throwDeprecation')) {
12906
- throw new Error(msg);
12907
- } else if (config('traceDeprecation')) {
12908
- console.trace(msg);
12909
- } else {
12910
- console.warn(msg);
12911
- }
12912
- warned = true;
12913
- }
12914
- return fn.apply(this, arguments);
12915
- }
12870
+ var warned = false;
12871
+ function deprecated() {
12872
+ if (!warned) {
12873
+ if (config('throwDeprecation')) {
12874
+ throw new Error(msg);
12875
+ } else if (config('traceDeprecation')) {
12876
+ console.trace(msg);
12877
+ } else {
12878
+ console.warn(msg);
12879
+ }
12880
+ warned = true;
12881
+ }
12882
+ return fn.apply(this, arguments);
12883
+ }
12916
12884
 
12917
- return deprecated;
12918
- }
12885
+ return deprecated;
12886
+ }
12919
12887
 
12920
- /**
12921
- * Checks `localStorage` for boolean values for the given `name`.
12922
- *
12923
- * @param {String} name
12924
- * @returns {Boolean}
12925
- * @api private
12926
- */
12888
+ /**
12889
+ * Checks `localStorage` for boolean values for the given `name`.
12890
+ *
12891
+ * @param {String} name
12892
+ * @returns {Boolean}
12893
+ * @api private
12894
+ */
12927
12895
 
12928
- function config (name) {
12929
- // accessing global.localStorage can trigger a DOMException in sandboxed iframes
12930
- try {
12931
- if (!commonjsGlobal.localStorage) return false;
12932
- } catch (_) {
12933
- return false;
12934
- }
12935
- var val = commonjsGlobal.localStorage[name];
12936
- if (null == val) return false;
12937
- return String(val).toLowerCase() === 'true';
12938
- }
12939
- return browser$b;
12896
+ function config (name) {
12897
+ // accessing global.localStorage can trigger a DOMException in sandboxed iframes
12898
+ try {
12899
+ if (!commonjsGlobal.localStorage) return false;
12900
+ } catch (_) {
12901
+ return false;
12902
+ }
12903
+ var val = commonjsGlobal.localStorage[name];
12904
+ if (null == val) return false;
12905
+ return String(val).toLowerCase() === 'true';
12940
12906
  }
12941
12907
 
12942
12908
  var _stream_writable;
@@ -12967,12 +12933,12 @@ function require_stream_writable () {
12967
12933
 
12968
12934
  /*<replacement>*/
12969
12935
  const internalUtil = {
12970
- deprecate: requireBrowser$a()
12936
+ deprecate: browser$b
12971
12937
  };
12972
12938
  /*</replacement>*/
12973
12939
 
12974
12940
  /*<replacement>*/
12975
- var Stream = requireStreamBrowser();
12941
+ var Stream = streamBrowser;
12976
12942
  /*</replacement>*/
12977
12943
 
12978
12944
  const Buffer = require$$6$1.Buffer;
@@ -12983,8 +12949,8 @@ function require_stream_writable () {
12983
12949
  function _isUint8Array(obj) {
12984
12950
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
12985
12951
  }
12986
- const destroyImpl = requireDestroy();
12987
- const _require = requireState(),
12952
+ const destroyImpl = destroy_1;
12953
+ const _require = state,
12988
12954
  getHighWaterMark = _require.getHighWaterMark;
12989
12955
  const _require$codes = errorsBrowser.codes,
12990
12956
  ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
@@ -14178,7 +14144,7 @@ function require_stream_readable () {
14178
14144
  /*</replacement>*/
14179
14145
 
14180
14146
  /*<replacement>*/
14181
- var Stream = requireStreamBrowser();
14147
+ var Stream = streamBrowser;
14182
14148
  /*</replacement>*/
14183
14149
 
14184
14150
  const Buffer = require$$6$1.Buffer;
@@ -14201,8 +14167,8 @@ function require_stream_readable () {
14201
14167
  /*</replacement>*/
14202
14168
 
14203
14169
  const BufferList = requireBuffer_list();
14204
- const destroyImpl = requireDestroy();
14205
- const _require = requireState(),
14170
+ const destroyImpl = destroy_1;
14171
+ const _require = state,
14206
14172
  getHighWaterMark = _require.getHighWaterMark;
14207
14173
  const _require$codes = errorsBrowser.codes,
14208
14174
  ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
@@ -17655,7 +17621,7 @@ function WriteReq(chunk, encoding, cb) {
17655
17621
 
17656
17622
  function WritableState(options, stream) {
17657
17623
  Object.defineProperty(this, 'buffer', {
17658
- get: deprecate(function () {
17624
+ get: deprecate$1(function () {
17659
17625
  return this.getBuffer();
17660
17626
  }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
17661
17627
  });
@@ -39076,10 +39042,6 @@ const defaultConfig$1 = {
39076
39042
  class Browser extends Base {
39077
39043
  constructor (name, config = {}) {
39078
39044
  super(name, Object.assign({}, defaultConfig$1, config));
39079
- this.isBrowser = false;
39080
- try {
39081
- this.isBrowser = window.localStorage && true;
39082
- } catch (e) {}
39083
39045
  }
39084
39046
 
39085
39047
  withDB = async dbWorkFun => {
@@ -39119,12 +39081,16 @@ class Browser extends Base {
39119
39081
  }
39120
39082
 
39121
39083
  loadHeader (branch = 'main') {
39122
- return this.isBrowser && localStorage.getItem(this.headerKey(branch))
39084
+ try {
39085
+ return JSON.parse(localStorage.getItem(this.headerKey(branch)))
39086
+ } catch (e) {}
39123
39087
  }
39124
39088
 
39125
39089
  async writeHeader (branch, header) {
39126
39090
  if (this.config.readonly) return
39127
- return this.isBrowser && localStorage.setItem(this.headerKey(branch), this.prepareHeader(header))
39091
+ try {
39092
+ return localStorage.setItem(this.headerKey(branch), this.prepareHeader(header))
39093
+ } catch (e) {}
39128
39094
  }
39129
39095
 
39130
39096
  headerKey (branch = 'main') {
@@ -41642,6 +41608,7 @@ class Database {
41642
41608
  * @instance
41643
41609
  */
41644
41610
  toJSON () {
41611
+ // todo this prepareHeader ignores secondary storage, need both
41645
41612
  return this.blocks.valet ? this.blocks.valet.primary.prepareHeader(this.toHeader(), false) : this.toHeader() // omg
41646
41613
  }
41647
41614