@fireproof/core 0.5.2 → 0.5.4

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.
@@ -9539,15 +9539,7 @@ var _polyfillNode_events = /*#__PURE__*/Object.freeze({
9539
9539
 
9540
9540
  var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_events);
9541
9541
 
9542
- var streamBrowser;
9543
- var hasRequiredStreamBrowser;
9544
-
9545
- function requireStreamBrowser () {
9546
- if (hasRequiredStreamBrowser) return streamBrowser;
9547
- hasRequiredStreamBrowser = 1;
9548
- streamBrowser = require$$0$1.EventEmitter;
9549
- return streamBrowser;
9550
- }
9542
+ var streamBrowser = require$$0$1.EventEmitter;
9551
9543
 
9552
9544
  // shim for using process in browser
9553
9545
  // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
@@ -9690,7 +9682,7 @@ var argv = [];
9690
9682
  var version$2 = ''; // empty string to avoid regexp issues
9691
9683
  var versions = {};
9692
9684
  var release = {};
9693
- var config = {};
9685
+ var config$1 = {};
9694
9686
 
9695
9687
  function noop$2() {}
9696
9688
 
@@ -9767,7 +9759,7 @@ var browser$1$1 = {
9767
9759
  hrtime: hrtime,
9768
9760
  platform: platform,
9769
9761
  release: release,
9770
- config: config,
9762
+ config: config$1,
9771
9763
  uptime: uptime
9772
9764
  };
9773
9765
 
@@ -9848,11 +9840,11 @@ function format(f) {
9848
9840
  // Mark that a method should not be used.
9849
9841
  // Returns a modified function which warns once by default.
9850
9842
  // If --no-deprecation is set, then it is a no-op.
9851
- function deprecate$1(fn, msg) {
9843
+ function deprecate$2(fn, msg) {
9852
9844
  // Allow for deprecating things in the process of starting up.
9853
9845
  if (isUndefined(global$1.process)) {
9854
9846
  return function() {
9855
- return deprecate$1(fn, msg).apply(this, arguments);
9847
+ return deprecate$2(fn, msg).apply(this, arguments);
9856
9848
  };
9857
9849
  }
9858
9850
 
@@ -10461,7 +10453,7 @@ var _polyfillNode_util = {
10461
10453
  isBoolean: isBoolean,
10462
10454
  isArray: isArray,
10463
10455
  inspect: inspect,
10464
- deprecate: deprecate$1,
10456
+ deprecate: deprecate$2,
10465
10457
  format: format,
10466
10458
  debuglog: debuglog,
10467
10459
  promisify: promisify,
@@ -10474,7 +10466,7 @@ var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
10474
10466
  callbackify: callbackify,
10475
10467
  debuglog: debuglog,
10476
10468
  default: _polyfillNode_util,
10477
- deprecate: deprecate$1,
10469
+ deprecate: deprecate$2,
10478
10470
  format: format,
10479
10471
  inherits: inherits$w,
10480
10472
  inspect: inspect,
@@ -10662,108 +10654,99 @@ function requireBuffer_list () {
10662
10654
  return buffer_list;
10663
10655
  }
10664
10656
 
10665
- var destroy_1;
10666
- var hasRequiredDestroy;
10667
-
10668
- function requireDestroy () {
10669
- if (hasRequiredDestroy) return destroy_1;
10670
- hasRequiredDestroy = 1;
10671
-
10672
- // undocumented cb() API, needed for core, not for public API
10673
- function destroy(err, cb) {
10674
- const readableDestroyed = this._readableState && this._readableState.destroyed;
10675
- const writableDestroyed = this._writableState && this._writableState.destroyed;
10676
- if (readableDestroyed || writableDestroyed) {
10677
- if (cb) {
10678
- cb(err);
10679
- } else if (err) {
10680
- if (!this._writableState) {
10681
- process.nextTick(emitErrorNT, this, err);
10682
- } else if (!this._writableState.errorEmitted) {
10683
- this._writableState.errorEmitted = true;
10684
- process.nextTick(emitErrorNT, this, err);
10685
- }
10686
- }
10687
- return this;
10688
- }
10657
+ // undocumented cb() API, needed for core, not for public API
10658
+ function destroy(err, cb) {
10659
+ const readableDestroyed = this._readableState && this._readableState.destroyed;
10660
+ const writableDestroyed = this._writableState && this._writableState.destroyed;
10661
+ if (readableDestroyed || writableDestroyed) {
10662
+ if (cb) {
10663
+ cb(err);
10664
+ } else if (err) {
10665
+ if (!this._writableState) {
10666
+ process.nextTick(emitErrorNT, this, err);
10667
+ } else if (!this._writableState.errorEmitted) {
10668
+ this._writableState.errorEmitted = true;
10669
+ process.nextTick(emitErrorNT, this, err);
10670
+ }
10671
+ }
10672
+ return this;
10673
+ }
10689
10674
 
10690
- // we set destroyed to true before firing error callbacks in order
10691
- // to make it re-entrance safe in case destroy() is called within callbacks
10675
+ // we set destroyed to true before firing error callbacks in order
10676
+ // to make it re-entrance safe in case destroy() is called within callbacks
10692
10677
 
10693
- if (this._readableState) {
10694
- this._readableState.destroyed = true;
10695
- }
10678
+ if (this._readableState) {
10679
+ this._readableState.destroyed = true;
10680
+ }
10696
10681
 
10697
- // if this is a duplex stream mark the writable part as destroyed as well
10698
- if (this._writableState) {
10699
- this._writableState.destroyed = true;
10700
- }
10701
- this._destroy(err || null, err => {
10702
- if (!cb && err) {
10703
- if (!this._writableState) {
10704
- process.nextTick(emitErrorAndCloseNT, this, err);
10705
- } else if (!this._writableState.errorEmitted) {
10706
- this._writableState.errorEmitted = true;
10707
- process.nextTick(emitErrorAndCloseNT, this, err);
10708
- } else {
10709
- process.nextTick(emitCloseNT, this);
10710
- }
10711
- } else if (cb) {
10712
- process.nextTick(emitCloseNT, this);
10713
- cb(err);
10714
- } else {
10715
- process.nextTick(emitCloseNT, this);
10716
- }
10717
- });
10718
- return this;
10719
- }
10720
- function emitErrorAndCloseNT(self, err) {
10721
- emitErrorNT(self, err);
10722
- emitCloseNT(self);
10723
- }
10724
- function emitCloseNT(self) {
10725
- if (self._writableState && !self._writableState.emitClose) return;
10726
- if (self._readableState && !self._readableState.emitClose) return;
10727
- self.emit('close');
10728
- }
10729
- function undestroy() {
10730
- if (this._readableState) {
10731
- this._readableState.destroyed = false;
10732
- this._readableState.reading = false;
10733
- this._readableState.ended = false;
10734
- this._readableState.endEmitted = false;
10735
- }
10736
- if (this._writableState) {
10737
- this._writableState.destroyed = false;
10738
- this._writableState.ended = false;
10739
- this._writableState.ending = false;
10740
- this._writableState.finalCalled = false;
10741
- this._writableState.prefinished = false;
10742
- this._writableState.finished = false;
10743
- this._writableState.errorEmitted = false;
10744
- }
10745
- }
10746
- function emitErrorNT(self, err) {
10747
- self.emit('error', err);
10748
- }
10749
- function errorOrDestroy(stream, err) {
10750
- // We have tests that rely on errors being emitted
10751
- // in the same tick, so changing this is semver major.
10752
- // For now when you opt-in to autoDestroy we allow
10753
- // the error to be emitted nextTick. In a future
10754
- // semver major update we should change the default to this.
10755
-
10756
- const rState = stream._readableState;
10757
- const wState = stream._writableState;
10758
- if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
10759
- }
10760
- destroy_1 = {
10761
- destroy,
10762
- undestroy,
10763
- errorOrDestroy
10764
- };
10765
- return destroy_1;
10682
+ // if this is a duplex stream mark the writable part as destroyed as well
10683
+ if (this._writableState) {
10684
+ this._writableState.destroyed = true;
10685
+ }
10686
+ this._destroy(err || null, err => {
10687
+ if (!cb && err) {
10688
+ if (!this._writableState) {
10689
+ process.nextTick(emitErrorAndCloseNT, this, err);
10690
+ } else if (!this._writableState.errorEmitted) {
10691
+ this._writableState.errorEmitted = true;
10692
+ process.nextTick(emitErrorAndCloseNT, this, err);
10693
+ } else {
10694
+ process.nextTick(emitCloseNT, this);
10695
+ }
10696
+ } else if (cb) {
10697
+ process.nextTick(emitCloseNT, this);
10698
+ cb(err);
10699
+ } else {
10700
+ process.nextTick(emitCloseNT, this);
10701
+ }
10702
+ });
10703
+ return this;
10704
+ }
10705
+ function emitErrorAndCloseNT(self, err) {
10706
+ emitErrorNT(self, err);
10707
+ emitCloseNT(self);
10708
+ }
10709
+ function emitCloseNT(self) {
10710
+ if (self._writableState && !self._writableState.emitClose) return;
10711
+ if (self._readableState && !self._readableState.emitClose) return;
10712
+ self.emit('close');
10713
+ }
10714
+ function undestroy() {
10715
+ if (this._readableState) {
10716
+ this._readableState.destroyed = false;
10717
+ this._readableState.reading = false;
10718
+ this._readableState.ended = false;
10719
+ this._readableState.endEmitted = false;
10720
+ }
10721
+ if (this._writableState) {
10722
+ this._writableState.destroyed = false;
10723
+ this._writableState.ended = false;
10724
+ this._writableState.ending = false;
10725
+ this._writableState.finalCalled = false;
10726
+ this._writableState.prefinished = false;
10727
+ this._writableState.finished = false;
10728
+ this._writableState.errorEmitted = false;
10729
+ }
10730
+ }
10731
+ function emitErrorNT(self, err) {
10732
+ self.emit('error', err);
10766
10733
  }
10734
+ function errorOrDestroy(stream, err) {
10735
+ // We have tests that rely on errors being emitted
10736
+ // in the same tick, so changing this is semver major.
10737
+ // For now when you opt-in to autoDestroy we allow
10738
+ // the error to be emitted nextTick. In a future
10739
+ // semver major update we should change the default to this.
10740
+
10741
+ const rState = stream._readableState;
10742
+ const wState = stream._writableState;
10743
+ if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
10744
+ }
10745
+ var destroy_1 = {
10746
+ destroy,
10747
+ undestroy,
10748
+ errorOrDestroy
10749
+ };
10767
10750
 
10768
10751
  var errorsBrowser = {};
10769
10752
 
@@ -10893,109 +10876,92 @@ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
10893
10876
  createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
10894
10877
  errorsBrowser.codes = codes;
10895
10878
 
10896
- var state;
10897
- var hasRequiredState;
10898
-
10899
- function requireState () {
10900
- if (hasRequiredState) return state;
10901
- hasRequiredState = 1;
10902
-
10903
- const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
10904
- function highWaterMarkFrom(options, isDuplex, duplexKey) {
10905
- return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
10906
- }
10907
- function getHighWaterMark(state, options, duplexKey, isDuplex) {
10908
- const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
10909
- if (hwm != null) {
10910
- if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
10911
- const name = isDuplex ? duplexKey : 'highWaterMark';
10912
- throw new ERR_INVALID_OPT_VALUE(name, hwm);
10913
- }
10914
- return Math.floor(hwm);
10915
- }
10916
-
10917
- // Default value
10918
- return state.objectMode ? 16 : 16 * 1024;
10919
- }
10920
- state = {
10921
- getHighWaterMark
10922
- };
10923
- return state;
10879
+ const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
10880
+ function highWaterMarkFrom(options, isDuplex, duplexKey) {
10881
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
10924
10882
  }
10883
+ function getHighWaterMark(state, options, duplexKey, isDuplex) {
10884
+ const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
10885
+ if (hwm != null) {
10886
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
10887
+ const name = isDuplex ? duplexKey : 'highWaterMark';
10888
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
10889
+ }
10890
+ return Math.floor(hwm);
10891
+ }
10925
10892
 
10926
- var browser$a;
10927
- var hasRequiredBrowser$3;
10893
+ // Default value
10894
+ return state.objectMode ? 16 : 16 * 1024;
10895
+ }
10896
+ var state = {
10897
+ getHighWaterMark
10898
+ };
10928
10899
 
10929
- function requireBrowser$3 () {
10930
- if (hasRequiredBrowser$3) return browser$a;
10931
- hasRequiredBrowser$3 = 1;
10932
- /**
10933
- * Module exports.
10934
- */
10900
+ /**
10901
+ * Module exports.
10902
+ */
10935
10903
 
10936
- browser$a = deprecate;
10904
+ var browser$a = deprecate$1;
10937
10905
 
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
- */
10906
+ /**
10907
+ * Mark that a method should not be used.
10908
+ * Returns a modified function which warns once by default.
10909
+ *
10910
+ * If `localStorage.noDeprecation = true` is set, then it is a no-op.
10911
+ *
10912
+ * If `localStorage.throwDeprecation = true` is set, then deprecated functions
10913
+ * will throw an Error when invoked.
10914
+ *
10915
+ * If `localStorage.traceDeprecation = true` is set, then deprecated functions
10916
+ * will invoke `console.trace()` instead of `console.error()`.
10917
+ *
10918
+ * @param {Function} fn - the function to deprecate
10919
+ * @param {String} msg - the string to print to the console when `fn` is invoked
10920
+ * @returns {Function} a new "deprecated" version of `fn`
10921
+ * @api public
10922
+ */
10955
10923
 
10956
- function deprecate (fn, msg) {
10957
- if (config('noDeprecation')) {
10958
- return fn;
10959
- }
10924
+ function deprecate$1 (fn, msg) {
10925
+ if (config('noDeprecation')) {
10926
+ return fn;
10927
+ }
10960
10928
 
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
- }
10929
+ var warned = false;
10930
+ function deprecated() {
10931
+ if (!warned) {
10932
+ if (config('throwDeprecation')) {
10933
+ throw new Error(msg);
10934
+ } else if (config('traceDeprecation')) {
10935
+ console.trace(msg);
10936
+ } else {
10937
+ console.warn(msg);
10938
+ }
10939
+ warned = true;
10940
+ }
10941
+ return fn.apply(this, arguments);
10942
+ }
10975
10943
 
10976
- return deprecated;
10977
- }
10944
+ return deprecated;
10945
+ }
10978
10946
 
10979
- /**
10980
- * Checks `localStorage` for boolean values for the given `name`.
10981
- *
10982
- * @param {String} name
10983
- * @returns {Boolean}
10984
- * @api private
10985
- */
10947
+ /**
10948
+ * Checks `localStorage` for boolean values for the given `name`.
10949
+ *
10950
+ * @param {String} name
10951
+ * @returns {Boolean}
10952
+ * @api private
10953
+ */
10986
10954
 
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';
10997
- }
10998
- return browser$a;
10955
+ function config (name) {
10956
+ // accessing global.localStorage can trigger a DOMException in sandboxed iframes
10957
+ try {
10958
+ if (!commonjsGlobal.localStorage) return false;
10959
+ } catch (_) {
10960
+ return false;
10961
+ }
10962
+ var val = commonjsGlobal.localStorage[name];
10963
+ if (null == val) return false;
10964
+ return String(val).toLowerCase() === 'true';
10999
10965
  }
11000
10966
 
11001
10967
  var _stream_writable;
@@ -11026,12 +10992,12 @@ function require_stream_writable () {
11026
10992
 
11027
10993
  /*<replacement>*/
11028
10994
  const internalUtil = {
11029
- deprecate: requireBrowser$3()
10995
+ deprecate: browser$a
11030
10996
  };
11031
10997
  /*</replacement>*/
11032
10998
 
11033
10999
  /*<replacement>*/
11034
- var Stream = requireStreamBrowser();
11000
+ var Stream = streamBrowser;
11035
11001
  /*</replacement>*/
11036
11002
 
11037
11003
  const Buffer = require$$0$2.Buffer;
@@ -11042,8 +11008,8 @@ function require_stream_writable () {
11042
11008
  function _isUint8Array(obj) {
11043
11009
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
11044
11010
  }
11045
- const destroyImpl = requireDestroy();
11046
- const _require = requireState(),
11011
+ const destroyImpl = destroy_1;
11012
+ const _require = state,
11047
11013
  getHighWaterMark = _require.getHighWaterMark;
11048
11014
  const _require$codes = errorsBrowser.codes,
11049
11015
  ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
@@ -12237,7 +12203,7 @@ function require_stream_readable () {
12237
12203
  /*</replacement>*/
12238
12204
 
12239
12205
  /*<replacement>*/
12240
- var Stream = requireStreamBrowser();
12206
+ var Stream = streamBrowser;
12241
12207
  /*</replacement>*/
12242
12208
 
12243
12209
  const Buffer = require$$0$2.Buffer;
@@ -12260,8 +12226,8 @@ function require_stream_readable () {
12260
12226
  /*</replacement>*/
12261
12227
 
12262
12228
  const BufferList = requireBuffer_list();
12263
- const destroyImpl = requireDestroy();
12264
- const _require = requireState(),
12229
+ const destroyImpl = destroy_1;
12230
+ const _require = state,
12265
12231
  getHighWaterMark = _require.getHighWaterMark;
12266
12232
  const _require$codes = errorsBrowser.codes,
12267
12233
  ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
@@ -15627,7 +15593,7 @@ function WriteReq(chunk, encoding, cb) {
15627
15593
 
15628
15594
  function WritableState(options, stream) {
15629
15595
  Object.defineProperty(this, 'buffer', {
15630
- get: deprecate$1(function () {
15596
+ get: deprecate$2(function () {
15631
15597
  return this.getBuffer();
15632
15598
  }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
15633
15599
  });
@@ -38416,9 +38382,9 @@ class Listener {
38416
38382
  * @returns {Function} A function to unsubscribe from the topic.
38417
38383
  * @memberof Listener
38418
38384
  * @instance
38419
- * @param {any} since
38385
+ * @param {any} [since] - clock to flush from on launch
38420
38386
  */
38421
- on (topic, subscriber, since) {
38387
+ on (topic, subscriber, since = undefined) {
38422
38388
  const listOfTopicSubscribers = getTopicList(this.subcribers, topic);
38423
38389
  listOfTopicSubscribers.push(subscriber);
38424
38390
  if (typeof since !== 'undefined') {
@@ -38833,7 +38799,8 @@ class DbIndex {
38833
38799
  let removeByIdIndexEntries = [];
38834
38800
  await loadIndex(blocks, this.indexById, idIndexOpts);
38835
38801
  await loadIndex(blocks, this.indexByKey, dbIndexOpts);
38836
- if (this.dbHead) {
38802
+ // console.log('head', this.dbHead, this.indexById)
38803
+ if (this.indexById.root) {
38837
38804
  const oldChangeEntries = await this.indexById.root.getMany(result.rows.map(({ key }) => key));
38838
38805
  oldIndexEntries = oldChangeEntries.result.map((key) => ({ key, del: true }));
38839
38806
  removeByIdIndexEntries = oldIndexEntries.map(({ key }) => ({ key: key[1], del: true }));
@@ -38881,13 +38848,18 @@ async function bulkIndex (blocks, inIndex, indexEntries, opts) {
38881
38848
  inIndex.root = await load({ cid, get: getBlock, ...dbIndexOpts });
38882
38849
  }
38883
38850
  const { root, blocks: newBlocks } = await inIndex.root.bulk(indexEntries);
38884
- returnRootBlock = await root.block;
38885
- returnNode = root;
38886
- for await (const block of newBlocks) {
38887
- await putBlock(block.cid, block.bytes);
38851
+ if (root) {
38852
+ returnRootBlock = await root.block;
38853
+ returnNode = root;
38854
+ for await (const block of newBlocks) {
38855
+ await putBlock(block.cid, block.bytes);
38856
+ }
38857
+ await putBlock(returnRootBlock.cid, returnRootBlock.bytes);
38858
+ return { root: returnNode, cid: returnRootBlock.cid }
38859
+ } else {
38860
+ // throw new Error('test for index after delete')
38861
+ return { root: null, cid: null }
38888
38862
  }
38889
- await putBlock(returnRootBlock.cid, returnRootBlock.bytes);
38890
- return { root: returnNode, cid: returnRootBlock.cid }
38891
38863
  }
38892
38864
 
38893
38865
  async function loadIndex (blocks, index, indexOpts) {