@fireproof/core 0.5.9 → 0.5.11

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.
@@ -34,9 +34,17 @@ function getAugmentedNamespace(n) {
34
34
  return a;
35
35
  }
36
36
 
37
- var browser$d = {exports: {}};
37
+ var browserExports$1 = {};
38
+ var browser$d = {
39
+ get exports(){ return browserExports$1; },
40
+ set exports(v){ browserExports$1 = v; },
41
+ };
38
42
 
39
- var safeBuffer$1 = {exports: {}};
43
+ var safeBufferExports = {};
44
+ var safeBuffer$1 = {
45
+ get exports(){ return safeBufferExports; },
46
+ set exports(v){ safeBufferExports = v; },
47
+ };
40
48
 
41
49
  var global$1 = (typeof global !== "undefined" ? global :
42
50
  typeof self !== "undefined" ? self :
@@ -2101,10 +2109,8 @@ var require$$6$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_buffer);
2101
2109
  throw new TypeError('Argument must be a number')
2102
2110
  }
2103
2111
  return buffer.SlowBuffer(size)
2104
- };
2105
- } (safeBuffer$1, safeBuffer$1.exports));
2106
-
2107
- var safeBufferExports = safeBuffer$1.exports;
2112
+ };
2113
+ } (safeBuffer$1, safeBufferExports));
2108
2114
 
2109
2115
  // limit of Crypto.getRandomValues()
2110
2116
  // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
@@ -2155,9 +2161,6 @@ function randomBytes$2 (size, cb) {
2155
2161
  return bytes
2156
2162
  }
2157
2163
 
2158
- var browserExports$1 = browser$d.exports;
2159
- var randomBytes$3 = /*@__PURE__*/getDefaultExportFromCjs(browserExports$1);
2160
-
2161
2164
  var encode_1$2 = encode$9;
2162
2165
 
2163
2166
  var MSB$4 = 0x80
@@ -2240,13 +2243,13 @@ var length$2 = function (value) {
2240
2243
  )
2241
2244
  };
2242
2245
 
2243
- var varint$3 = {
2246
+ var varint$2 = {
2244
2247
  encode: encode_1$2
2245
2248
  , decode: decode$d
2246
2249
  , encodingLength: length$2
2247
2250
  };
2248
2251
 
2249
- var _brrp_varint$1 = varint$3;
2252
+ var _brrp_varint$1 = varint$2;
2250
2253
 
2251
2254
  /**
2252
2255
  * @param {Uint8Array} data
@@ -7075,8 +7078,6 @@ var varint$1 = {
7075
7078
  , encodingLength: length$1
7076
7079
  };
7077
7080
 
7078
- var varint$2 = /*@__PURE__*/getDefaultExportFromCjs(varint$1);
7079
-
7080
7081
  const CIDV0_BYTES = {
7081
7082
  SHA2_256: 0x12,
7082
7083
  LENGTH: 0x20,
@@ -7101,8 +7102,8 @@ function decodeVarint (bytes, seeker) {
7101
7102
  if (!bytes.length) {
7102
7103
  throw new Error('Unexpected end of data')
7103
7104
  }
7104
- const i = varint$2.decode(bytes);
7105
- seeker.seek(/** @type {number} */(varint$2.decode.bytes));
7105
+ const i = varint$1.decode(bytes);
7106
+ seeker.seek(/** @type {number} */(varint$1.decode.bytes));
7106
7107
  return i
7107
7108
  /* c8 ignore next 2 */
7108
7109
  // Node.js 12 c8 bug
@@ -7153,10 +7154,10 @@ function getMultihashLength (bytes) {
7153
7154
  // where both code and length are varints, so we have to decode
7154
7155
  // them first before we can know total length
7155
7156
 
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);
7157
+ varint$1.decode(bytes); // code
7158
+ const codeLength = /** @type {number} */(varint$1.decode.bytes);
7159
+ const length = varint$1.decode(bytes.subarray(varint$1.decode.bytes));
7160
+ const lengthLength = /** @type {number} */(varint$1.decode.bytes);
7160
7161
  const mhLength = codeLength + lengthLength + length;
7161
7162
 
7162
7163
  return mhLength
@@ -7864,7 +7865,7 @@ const addRoot = (writer, root, options = {}) => {
7864
7865
  */
7865
7866
  const blockLength = ({ cid, bytes }) => {
7866
7867
  const size = cid.bytes.byteLength + bytes.byteLength;
7867
- return varint$2.encodingLength(size) + size
7868
+ return varint$1.encodingLength(size) + size
7868
7869
  };
7869
7870
 
7870
7871
  /**
@@ -7873,7 +7874,7 @@ const blockLength = ({ cid, bytes }) => {
7873
7874
  */
7874
7875
  const addBlock = (writer, { cid, bytes }) => {
7875
7876
  const byteLength = cid.bytes.byteLength + bytes.byteLength;
7876
- const size = varint$2.encode(byteLength);
7877
+ const size = varint$1.encode(byteLength);
7877
7878
  if (writer.byteOffset + size.length + byteLength > writer.bytes.byteLength) {
7878
7879
  throw new RangeError('Buffer has no capacity for this block')
7879
7880
  } else {
@@ -7893,7 +7894,7 @@ const close = (writer, options = {}) => {
7893
7894
  const { roots, bytes, byteOffset, headerSize } = writer;
7894
7895
 
7895
7896
  const headerBytes = encode$5({ version: 1, roots });
7896
- const varintBytes = varint$2.encode(headerBytes.length);
7897
+ const varintBytes = varint$1.encode(headerBytes.length);
7897
7898
 
7898
7899
  const size = varintBytes.length + headerBytes.byteLength;
7899
7900
  const offset = headerSize - size;
@@ -7970,7 +7971,7 @@ const calculateHeaderLength = (rootLengths) => {
7970
7971
  tokens.push(new Token(Type.bytes, { length: rootLength + 1 }));
7971
7972
  }
7972
7973
  const length = tokensToLength(tokens); // no options needed here because we have simple tokens
7973
- return varint$2.encodingLength(length) + length
7974
+ return varint$1.encodingLength(length) + length
7974
7975
  };
7975
7976
 
7976
7977
  /**
@@ -8313,11 +8314,23 @@ replaceTraps((oldTraps) => ({
8313
8314
  has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
8314
8315
  }));
8315
8316
 
8316
- var cargoQueue$1 = {exports: {}};
8317
+ var cargoQueueExports = {};
8318
+ var cargoQueue$1 = {
8319
+ get exports(){ return cargoQueueExports; },
8320
+ set exports(v){ cargoQueueExports = v; },
8321
+ };
8317
8322
 
8318
- var queue$1 = {exports: {}};
8323
+ var queueExports = {};
8324
+ var queue$1 = {
8325
+ get exports(){ return queueExports; },
8326
+ set exports(v){ queueExports = v; },
8327
+ };
8319
8328
 
8320
- var onlyOnce = {exports: {}};
8329
+ var onlyOnceExports = {};
8330
+ var onlyOnce = {
8331
+ get exports(){ return onlyOnceExports; },
8332
+ set exports(v){ onlyOnceExports = v; },
8333
+ };
8321
8334
 
8322
8335
  (function (module, exports) {
8323
8336
 
@@ -8333,10 +8346,8 @@ var onlyOnce = {exports: {}};
8333
8346
  callFn.apply(this, args);
8334
8347
  };
8335
8348
  }
8336
- module.exports = exports["default"];
8337
- } (onlyOnce, onlyOnce.exports));
8338
-
8339
- var onlyOnceExports = onlyOnce.exports;
8349
+ module.exports = exports["default"];
8350
+ } (onlyOnce, onlyOnceExports));
8340
8351
 
8341
8352
  var setImmediate$1 = {};
8342
8353
 
@@ -8373,7 +8384,11 @@ if (hasQueueMicrotask) {
8373
8384
 
8374
8385
  setImmediate$1.default = wrap(_defer);
8375
8386
 
8376
- var DoublyLinkedList = {exports: {}};
8387
+ var DoublyLinkedListExports = {};
8388
+ var DoublyLinkedList = {
8389
+ get exports(){ return DoublyLinkedListExports; },
8390
+ set exports(v){ DoublyLinkedListExports = v; },
8391
+ };
8377
8392
 
8378
8393
  (function (module, exports) {
8379
8394
 
@@ -8466,16 +8481,22 @@ var DoublyLinkedList = {exports: {}};
8466
8481
  dll.length = 1;
8467
8482
  dll.head = dll.tail = node;
8468
8483
  }
8469
- module.exports = exports["default"];
8470
- } (DoublyLinkedList, DoublyLinkedList.exports));
8471
-
8472
- var DoublyLinkedListExports = DoublyLinkedList.exports;
8484
+ module.exports = exports["default"];
8485
+ } (DoublyLinkedList, DoublyLinkedListExports));
8473
8486
 
8474
8487
  var wrapAsync = {};
8475
8488
 
8476
- var asyncify = {exports: {}};
8489
+ var asyncifyExports = {};
8490
+ var asyncify = {
8491
+ get exports(){ return asyncifyExports; },
8492
+ set exports(v){ asyncifyExports = v; },
8493
+ };
8477
8494
 
8478
- var initialParams = {exports: {}};
8495
+ var initialParamsExports = {};
8496
+ var initialParams = {
8497
+ get exports(){ return initialParamsExports; },
8498
+ set exports(v){ initialParamsExports = v; },
8499
+ };
8479
8500
 
8480
8501
  (function (module, exports) {
8481
8502
 
@@ -8490,15 +8511,13 @@ var initialParams = {exports: {}};
8490
8511
  };
8491
8512
  };
8492
8513
 
8493
- module.exports = exports["default"];
8494
- } (initialParams, initialParams.exports));
8495
-
8496
- var initialParamsExports = initialParams.exports;
8514
+ module.exports = exports["default"];
8515
+ } (initialParams, initialParamsExports));
8497
8516
 
8498
8517
  var hasRequiredAsyncify;
8499
8518
 
8500
8519
  function requireAsyncify () {
8501
- if (hasRequiredAsyncify) return asyncify.exports;
8520
+ if (hasRequiredAsyncify) return asyncifyExports;
8502
8521
  hasRequiredAsyncify = 1;
8503
8522
  (function (module, exports) {
8504
8523
 
@@ -8617,9 +8636,9 @@ function requireAsyncify () {
8617
8636
  }, err);
8618
8637
  }
8619
8638
  }
8620
- module.exports = exports['default'];
8621
- } (asyncify, asyncify.exports));
8622
- return asyncify.exports;
8639
+ module.exports = exports['default'];
8640
+ } (asyncify, asyncifyExports));
8641
+ return asyncifyExports;
8623
8642
  }
8624
8643
 
8625
8644
  var hasRequiredWrapAsync;
@@ -8956,10 +8975,8 @@ function requireWrapAsync () {
8956
8975
  });
8957
8976
  return q;
8958
8977
  }
8959
- module.exports = exports['default'];
8960
- } (queue$1, queue$1.exports));
8961
-
8962
- var queueExports = queue$1.exports;
8978
+ module.exports = exports['default'];
8979
+ } (queue$1, queueExports));
8963
8980
 
8964
8981
  (function (module, exports) {
8965
8982
 
@@ -9031,10 +9048,9 @@ var queueExports = queue$1.exports;
9031
9048
  function cargo(worker, concurrency, payload) {
9032
9049
  return (0, _queue2.default)(worker, concurrency, payload);
9033
9050
  }
9034
- module.exports = exports['default'];
9035
- } (cargoQueue$1, cargoQueue$1.exports));
9051
+ module.exports = exports['default'];
9052
+ } (cargoQueue$1, cargoQueueExports));
9036
9053
 
9037
- var cargoQueueExports = cargoQueue$1.exports;
9038
9054
  var cargoQueue = /*@__PURE__*/getDefaultExportFromCjs(cargoQueueExports);
9039
9055
 
9040
9056
  var cryptoBrowserify = {};
@@ -9071,7 +9087,11 @@ var _polyfillNode_inherits = /*#__PURE__*/Object.freeze({
9071
9087
 
9072
9088
  var require$$3$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_inherits);
9073
9089
 
9074
- var readableBrowser = {exports: {}};
9090
+ var readableBrowserExports = {};
9091
+ var readableBrowser = {
9092
+ get exports(){ return readableBrowserExports; },
9093
+ set exports(v){ readableBrowserExports = v; },
9094
+ };
9075
9095
 
9076
9096
  var domain;
9077
9097
 
@@ -13468,10 +13488,8 @@ var pipeline_1 = pipeline;
13468
13488
  exports.Transform = _stream_transform;
13469
13489
  exports.PassThrough = _stream_passthrough;
13470
13490
  exports.finished = endOfStream;
13471
- exports.pipeline = pipeline_1;
13472
- } (readableBrowser, readableBrowser.exports));
13473
-
13474
- var readableBrowserExports = readableBrowser.exports;
13491
+ exports.pipeline = pipeline_1;
13492
+ } (readableBrowser, readableBrowserExports));
13475
13493
 
13476
13494
  var Buffer$E = safeBufferExports.Buffer;
13477
13495
  var Transform$6 = readableBrowserExports.Transform;
@@ -13877,7 +13895,11 @@ function fn5 (a, b, c, d, e, m, k, s) {
13877
13895
 
13878
13896
  var ripemd160 = RIPEMD160$4;
13879
13897
 
13880
- var sha_js = {exports: {}};
13898
+ var sha_jsExports = {};
13899
+ var sha_js = {
13900
+ get exports(){ return sha_jsExports; },
13901
+ set exports(v){ sha_jsExports = v; },
13902
+ };
13881
13903
 
13882
13904
  var Buffer$B = safeBufferExports.Buffer;
13883
13905
 
@@ -14681,8 +14703,6 @@ exports$1.sha256 = sha256$1;
14681
14703
  exports$1.sha384 = sha384$1;
14682
14704
  exports$1.sha512 = sha512$1;
14683
14705
 
14684
- var sha_jsExports = sha_js.exports;
14685
-
14686
14706
  function BufferList() {
14687
14707
  this.head = null;
14688
14708
  this.tail = null;
@@ -16633,6 +16653,12 @@ var browser$9 = function createHmac (alg, key) {
16633
16653
  return new Hmac$2(alg, key)
16634
16654
  };
16635
16655
 
16656
+ var algosExports = {};
16657
+ var algos = {
16658
+ get exports(){ return algosExports; },
16659
+ set exports(v){ algosExports = v; },
16660
+ };
16661
+
16636
16662
  var sha224WithRSAEncryption = {
16637
16663
  sign: "rsa",
16638
16664
  hash: "sha224",
@@ -16797,7 +16823,9 @@ var require$$6 = {
16797
16823
  }
16798
16824
  };
16799
16825
 
16800
- var algos = require$$6;
16826
+ (function (module) {
16827
+ module.exports = require$$6;
16828
+ } (algos));
16801
16829
 
16802
16830
  var browser$8 = {};
16803
16831
 
@@ -19037,7 +19065,7 @@ var modes = {};
19037
19065
  exports['des-ede'] = {
19038
19066
  key: 16,
19039
19067
  iv: 0
19040
- };
19068
+ };
19041
19069
  } (modes));
19042
19070
 
19043
19071
  var DES = browserifyDes;
@@ -19110,9 +19138,11 @@ browser$7.listCiphers = browser$7.getCiphers = getCiphers;
19110
19138
 
19111
19139
  var browser$5 = {};
19112
19140
 
19113
- var bn$1 = {exports: {}};
19114
-
19115
- bn$1.exports;
19141
+ var bnExports$1 = {};
19142
+ var bn$1 = {
19143
+ get exports(){ return bnExports$1; },
19144
+ set exports(v){ bnExports$1 = v; },
19145
+ };
19116
19146
 
19117
19147
  (function (module) {
19118
19148
  (function (module, exports) {
@@ -22557,17 +22587,19 @@ bn$1.exports;
22557
22587
  var res = this.imod(a._invmp(this.m).mul(this.r2));
22558
22588
  return res._forceRed(this);
22559
22589
  };
22560
- })(module, commonjsGlobal);
22590
+ })(module, commonjsGlobal);
22561
22591
  } (bn$1));
22562
22592
 
22563
- var bnExports$1 = bn$1.exports;
22564
-
22565
- var brorand = {exports: {}};
22593
+ var brorandExports = {};
22594
+ var brorand = {
22595
+ get exports(){ return brorandExports; },
22596
+ set exports(v){ brorandExports = v; },
22597
+ };
22566
22598
 
22567
22599
  var hasRequiredBrorand;
22568
22600
 
22569
22601
  function requireBrorand () {
22570
- if (hasRequiredBrorand) return brorand.exports;
22602
+ if (hasRequiredBrorand) return brorandExports;
22571
22603
  hasRequiredBrorand = 1;
22572
22604
  var r;
22573
22605
 
@@ -22581,7 +22613,7 @@ function requireBrorand () {
22581
22613
  function Rand(rand) {
22582
22614
  this.rand = rand;
22583
22615
  }
22584
- brorand.exports.Rand = Rand;
22616
+ brorandExports.Rand = Rand;
22585
22617
 
22586
22618
  Rand.prototype.generate = function generate(len) {
22587
22619
  return this._rand(len);
@@ -22634,7 +22666,7 @@ function requireBrorand () {
22634
22666
  } catch (e) {
22635
22667
  }
22636
22668
  }
22637
- return brorand.exports;
22669
+ return brorandExports;
22638
22670
  }
22639
22671
 
22640
22672
  var mr;
@@ -23141,11 +23173,17 @@ function requireBrowser$2 () {
23141
23173
  return browser$5;
23142
23174
  }
23143
23175
 
23144
- var sign = {exports: {}};
23145
-
23146
- var bn = {exports: {}};
23176
+ var signExports = {};
23177
+ var sign = {
23178
+ get exports(){ return signExports; },
23179
+ set exports(v){ signExports = v; },
23180
+ };
23147
23181
 
23148
- bn.exports;
23182
+ var bnExports = {};
23183
+ var bn = {
23184
+ get exports(){ return bnExports; },
23185
+ set exports(v){ bnExports = v; },
23186
+ };
23149
23187
 
23150
23188
  (function (module) {
23151
23189
  (function (module, exports) {
@@ -26495,11 +26533,9 @@ bn.exports;
26495
26533
  var res = this.imod(a._invmp(this.m).mul(this.r2));
26496
26534
  return res._forceRed(this);
26497
26535
  };
26498
- })(module, commonjsGlobal);
26536
+ })(module, commonjsGlobal);
26499
26537
  } (bn));
26500
26538
 
26501
- var bnExports = bn.exports;
26502
-
26503
26539
  var BN$a = bnExports;
26504
26540
  var randomBytes$1 = browserExports$1;
26505
26541
 
@@ -26670,7 +26706,7 @@ var utils$k = {};
26670
26706
  return toHex(arr);
26671
26707
  else
26672
26708
  return arr;
26673
- };
26709
+ };
26674
26710
  } (utils$k));
26675
26711
 
26676
26712
  (function (exports) {
@@ -26790,7 +26826,7 @@ var utils$k = {};
26790
26826
  function intFromLE(bytes) {
26791
26827
  return new BN(bytes, 'hex', 'le');
26792
26828
  }
26793
- utils.intFromLE = intFromLE;
26829
+ utils.intFromLE = intFromLE;
26794
26830
  } (utils$l));
26795
26831
 
26796
26832
  var curve = {};
@@ -28729,7 +28765,7 @@ Point.prototype.mixedAdd = Point.prototype.add;
28729
28765
  curve.base = base$2;
28730
28766
  curve.short = short;
28731
28767
  curve.mont = mont;
28732
- curve.edwards = edwards;
28768
+ curve.edwards = edwards;
28733
28769
  } (curve));
28734
28770
 
28735
28771
  var curves$1 = {};
@@ -29942,7 +29978,7 @@ Hmac.prototype.digest = function digest(enc) {
29942
29978
  hash.sha224 = hash.sha.sha224;
29943
29979
  hash.sha384 = hash.sha.sha384;
29944
29980
  hash.sha512 = hash.sha.sha512;
29945
- hash.ripemd160 = hash.ripemd.ripemd160;
29981
+ hash.ripemd160 = hash.ripemd.ripemd160;
29946
29982
  } (hash$2));
29947
29983
 
29948
29984
  var secp256k1;
@@ -30939,7 +30975,7 @@ function requireSecp256k1 () {
30939
30975
  '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
30940
30976
  pre,
30941
30977
  ],
30942
- });
30978
+ });
30943
30979
  } (curves$1));
30944
30980
 
30945
30981
  var hash$1 = hash$2;
@@ -31882,8 +31918,8 @@ function requireElliptic () {
31882
31918
 
31883
31919
  // Protocols
31884
31920
  elliptic.ec = requireEc();
31885
- elliptic.eddsa = eddsa;
31886
- } (elliptic));
31921
+ elliptic.eddsa = eddsa;
31922
+ } (elliptic));
31887
31923
  return elliptic;
31888
31924
  }
31889
31925
 
@@ -32943,7 +32979,7 @@ var der$2 = {};
32943
32979
  0x1d: 'charstr',
32944
32980
  0x1e: 'bmpstr'
32945
32981
  };
32946
- exports.tagByName = reverse(exports.tag);
32982
+ exports.tagByName = reverse(exports.tag);
32947
32983
  } (der$2));
32948
32984
 
32949
32985
  const inherits$3 = require$$3$1;
@@ -33267,7 +33303,7 @@ PEMEncoder.prototype.encode = function encode(data, options) {
33267
33303
  const encoders = exports;
33268
33304
 
33269
33305
  encoders.der = der_1$1;
33270
- encoders.pem = pem$1;
33306
+ encoders.pem = pem$1;
33271
33307
  } (encoders));
33272
33308
 
33273
33309
  var decoders = {};
@@ -33661,7 +33697,7 @@ PEMDecoder.prototype.decode = function decode(data, options) {
33661
33697
  const decoders = exports;
33662
33698
 
33663
33699
  decoders.der = der_1;
33664
- decoders.pem = pem;
33700
+ decoders.pem = pem;
33665
33701
  } (decoders));
33666
33702
 
33667
33703
  (function (exports) {
@@ -33720,7 +33756,7 @@ PEMDecoder.prototype.decode = function decode(data, options) {
33720
33756
 
33721
33757
  Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
33722
33758
  return this._getEncoder(enc).encode(data, reporter);
33723
- };
33759
+ };
33724
33760
  } (api));
33725
33761
 
33726
33762
  var base$1 = {};
@@ -33732,7 +33768,7 @@ var base$1 = {};
33732
33768
  base.Reporter = reporter.Reporter;
33733
33769
  base.DecoderBuffer = buffer.DecoderBuffer;
33734
33770
  base.EncoderBuffer = buffer.EncoderBuffer;
33735
- base.Node = node;
33771
+ base.Node = node;
33736
33772
  } (base$1));
33737
33773
 
33738
33774
  var constants = {};
@@ -33757,7 +33793,7 @@ var constants = {};
33757
33793
  return res;
33758
33794
  };
33759
33795
 
33760
- constants.der = der$2;
33796
+ constants.der = der$2;
33761
33797
  } (constants));
33762
33798
 
33763
33799
  (function (exports) {
@@ -33770,7 +33806,7 @@ var constants = {};
33770
33806
  asn1.base = base$1;
33771
33807
  asn1.constants = constants;
33772
33808
  asn1.decoders = decoders;
33773
- asn1.encoders = encoders;
33809
+ asn1.encoders = encoders;
33774
33810
  } (asn1$2));
33775
33811
 
33776
33812
  var asn = asn1$2;
@@ -34144,7 +34180,7 @@ var require$$4 = {
34144
34180
  var hasRequiredSign;
34145
34181
 
34146
34182
  function requireSign () {
34147
- if (hasRequiredSign) return sign.exports;
34183
+ if (hasRequiredSign) return signExports;
34148
34184
  hasRequiredSign = 1;
34149
34185
  // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
34150
34186
  var Buffer = safeBufferExports.Buffer;
@@ -34287,9 +34323,9 @@ function requireSign () {
34287
34323
  }
34288
34324
 
34289
34325
  sign.exports = sign$1;
34290
- sign.exports.getKey = getKey;
34291
- sign.exports.makeKey = makeKey;
34292
- return sign.exports;
34326
+ signExports.getKey = getKey;
34327
+ signExports.makeKey = makeKey;
34328
+ return signExports;
34293
34329
  }
34294
34330
 
34295
34331
  var verify_1;
@@ -34868,7 +34904,7 @@ function compare$3 (a, b) {
34868
34904
 
34869
34905
  exports.publicDecrypt = function publicDecrypt (key, buf) {
34870
34906
  return exports.privateDecrypt(key, buf, true)
34871
- };
34907
+ };
34872
34908
  } (browser$2));
34873
34909
 
34874
34910
  var browser$1 = {};
@@ -34990,8 +35026,8 @@ function requireCryptoBrowserify () {
34990
35026
  cryptoBrowserify.createHash = cryptoBrowserify.Hash = browser$a;
34991
35027
  cryptoBrowserify.createHmac = cryptoBrowserify.Hmac = browser$9;
34992
35028
 
34993
- var algos$1 = algos;
34994
- var algoKeys = Object.keys(algos$1);
35029
+ var algos = algosExports;
35030
+ var algoKeys = Object.keys(algos);
34995
35031
  var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
34996
35032
  cryptoBrowserify.getHashes = function () {
34997
35033
  return hashes
@@ -37853,7 +37889,7 @@ async function visMerkleClock (blocks, head) {
37853
37889
  return { vis: lines.join('\n') }
37854
37890
  }
37855
37891
 
37856
- var charwise$1 = {};
37892
+ var charwise = {};
37857
37893
 
37858
37894
  var number = {};
37859
37895
 
@@ -38081,10 +38117,8 @@ object.factory = function (codec) {
38081
38117
 
38082
38118
  //for leveldb, request strings
38083
38119
  exports.buffer = false;
38084
- exports.type = 'charwise';
38085
- } (charwise$1));
38086
-
38087
- var charwise = /*@__PURE__*/getDefaultExportFromCjs(charwise$1);
38120
+ exports.type = 'charwise';
38121
+ } (charwise));
38088
38122
 
38089
38123
  /* global localStorage */
38090
38124
  let storageSupported = false;
@@ -38182,9 +38216,9 @@ class Database {
38182
38216
  }
38183
38217
 
38184
38218
  // used be indexes etc to notify database listeners of new availability
38185
- async notifyExternal (source = 'unknown') {
38186
- await this.notifyListeners({ _external: source, _clock: this.clockToJSON() });
38187
- }
38219
+ // async notifyExternal (source = 'unknown') {
38220
+ // // await this.notifyListeners({ _external: source, _clock: this.clockToJSON() })
38221
+ // }
38188
38222
 
38189
38223
  /**
38190
38224
  * Returns the changes made to the Fireproof instance since the specified event.
@@ -38444,13 +38478,23 @@ class Database {
38444
38478
  * @returns {Function} - A function that can be called to unregister the listener.
38445
38479
  * @memberof Fireproof
38446
38480
  */
38447
- registerListener (listener) {
38481
+ subscribe (listener) {
38448
38482
  this.listeners.add(listener);
38449
38483
  return () => {
38450
38484
  this.listeners.delete(listener);
38451
38485
  }
38452
38486
  }
38453
38487
 
38488
+ /**
38489
+ * @deprecated 0.7.0 - renamed subscribe(listener)
38490
+ * @param {Function} listener - The listener to be called when the clock is updated.
38491
+ * @returns {Function} - A function that can be called to unregister the listener.
38492
+ * @memberof Fireproof
38493
+ */
38494
+ registerListener (listener) {
38495
+ return this.subscribe(listener)
38496
+ }
38497
+
38454
38498
  async notifyListeners (changes) {
38455
38499
  // await sleep(10)
38456
38500
  await this.maybeSaveClock();
@@ -38499,7 +38543,9 @@ function encodeEvent (event) {
38499
38543
  * @param {Function} routingFn - The routing function to apply to each entry in the database.
38500
38544
  */
38501
38545
  // import { ChangeEvent } from './db-index'
38502
-
38546
+ /**
38547
+ * @deprecated since version 0.7.0
38548
+ */
38503
38549
  class Listener {
38504
38550
  subcribers = new Map()
38505
38551
  doStopListening = null
@@ -38783,14 +38829,23 @@ const makeDoc = ({ key, value }) => ({ _id: key, ...value });
38783
38829
  const indexEntriesForChanges = (changes, mapFn) => {
38784
38830
  const indexEntries = [];
38785
38831
  changes.forEach(({ key, value, del }) => {
38832
+ // key is _id, value is the document
38786
38833
  if (del || !value) return
38787
- mapFn(makeDoc({ key, value }), (k, v) => {
38834
+ let mapCalled = false;
38835
+ const mapReturn = mapFn(makeDoc({ key, value }), (k, v) => {
38836
+ mapCalled = true;
38788
38837
  if (typeof k === 'undefined') return
38789
38838
  indexEntries.push({
38790
38839
  key: [charwise.encode(k), key],
38791
38840
  value: v || null
38792
38841
  });
38793
38842
  });
38843
+ if (!mapCalled && mapReturn) {
38844
+ indexEntries.push({
38845
+ key: [charwise.encode(mapReturn), key],
38846
+ value: null
38847
+ });
38848
+ }
38794
38849
  });
38795
38850
  return indexEntries
38796
38851
  };
@@ -38812,7 +38867,10 @@ class DbIndex {
38812
38867
  constructor (database, name, mapFn, clock = null, opts = {}) {
38813
38868
  this.database = database;
38814
38869
  if (!database.indexBlocks) {
38815
- database.indexBlocks = new TransactionBlockstore(database?.name + '.indexes', database.blocks.valet?.getKeyMaterial());
38870
+ database.indexBlocks = new TransactionBlockstore(
38871
+ database?.name + '.indexes',
38872
+ database.blocks.valet?.getKeyMaterial()
38873
+ );
38816
38874
  }
38817
38875
  if (typeof name === 'function') {
38818
38876
  // app is using deprecated API, remove in 0.7
@@ -38821,13 +38879,8 @@ class DbIndex {
38821
38879
  mapFn = name;
38822
38880
  name = null;
38823
38881
  }
38824
- if (typeof mapFn === 'string') {
38825
- this.mapFnString = mapFn;
38826
- } else {
38827
- this.mapFn = mapFn;
38828
- this.mapFnString = mapFn.toString();
38829
- }
38830
- this.name = name || this.makeName();
38882
+ this.applyMapFn(mapFn, name);
38883
+
38831
38884
  this.indexById = { root: null, cid: null };
38832
38885
  this.indexByKey = { root: null, cid: null };
38833
38886
  this.dbHead = null;
@@ -38838,13 +38891,34 @@ class DbIndex {
38838
38891
  }
38839
38892
  this.instanceId = this.database.instanceId + `.DbIndex.${Math.random().toString(36).substring(2, 7)}`;
38840
38893
  this.updateIndexPromise = null;
38841
- if (!opts.temporary) { DbIndex.registerWithDatabase(this, this.database); }
38894
+ if (!opts.temporary) {
38895
+ DbIndex.registerWithDatabase(this, this.database);
38896
+ }
38897
+ }
38898
+
38899
+ applyMapFn (mapFn, name) {
38900
+ if (typeof mapFn === 'string') {
38901
+ this.mapFnString = mapFn;
38902
+ } else {
38903
+ this.mapFn = mapFn;
38904
+ this.mapFnString = mapFn.toString();
38905
+ }
38906
+ this.name = name || this.makeName();
38842
38907
  }
38843
38908
 
38844
38909
  makeName () {
38845
38910
  const regex = /\(([^,()]+,\s*[^,()]+|\[[^\]]+\],\s*[^,()]+)\)/g;
38846
- const matches = Array.from(this.mapFnString.matchAll(regex), match => match[1].trim());
38847
- return matches[1]
38911
+ let matches = Array.from(this.mapFnString.matchAll(regex), match => match[1].trim());
38912
+ if (matches.length === 0) {
38913
+ matches = /=>\s*(.*)/.exec(this.mapFnString);
38914
+ }
38915
+ if (matches === null) {
38916
+ return this.mapFnString
38917
+ } else {
38918
+ // it's a consise arrow function, match everythign after the arrow
38919
+ this.includeDocsDefault = true;
38920
+ return matches[1]
38921
+ }
38848
38922
  }
38849
38923
 
38850
38924
  static registerWithDatabase (inIndex, database) {
@@ -38854,7 +38928,8 @@ class DbIndex {
38854
38928
  // merge our inIndex code with the inIndex clock or vice versa
38855
38929
  const existingIndex = database.indexes.get(inIndex.mapFnString);
38856
38930
  // keep the code instance, discard the clock instance
38857
- if (existingIndex.mapFn) { // this one also has other config
38931
+ if (existingIndex.mapFn) {
38932
+ // this one also has other config
38858
38933
  existingIndex.dbHead = inIndex.dbHead;
38859
38934
  existingIndex.indexById.cid = inIndex.indexById.cid;
38860
38935
  existingIndex.indexByKey.cid = inIndex.indexByKey.cid;
@@ -38898,7 +38973,7 @@ class DbIndex {
38898
38973
  /**
38899
38974
  * Query object can have {range}
38900
38975
  * @param {DbQuery} query - the query range to use
38901
- * @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
38976
+ * @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any, doc?: any}>}>}
38902
38977
  * @memberof DbIndex
38903
38978
  * @instance
38904
38979
  */
@@ -38906,20 +38981,63 @@ class DbIndex {
38906
38981
  // const callId = Math.random().toString(36).substring(2, 7)
38907
38982
  // todo pass a root to query a snapshot
38908
38983
  // console.time(callId + '.updateIndex')
38909
- update && await this.updateIndex(this.database.indexBlocks);
38984
+ update && (await this.updateIndex(this.database.indexBlocks));
38910
38985
  // console.timeEnd(callId + '.updateIndex')
38911
38986
  // console.time(callId + '.doIndexQuery')
38912
38987
  // console.log('query', query)
38913
- const response = await doIndexQuery(this.database.indexBlocks, this.indexByKey, query);
38988
+ const response = await this.doIndexQuery(query);
38914
38989
  // console.timeEnd(callId + '.doIndexQuery')
38915
38990
  return {
38916
38991
  proof: { index: await cidsToProof(response.cids) },
38917
- rows: response.result.map(({ id, key, row }) => {
38918
- return ({ id, key: charwise.decode(key), value: row })
38992
+ rows: response.result.map(({ id, key, row, doc }) => {
38993
+ return { id, key: charwise.decode(key), value: row, doc }
38919
38994
  })
38920
38995
  }
38921
38996
  }
38922
38997
 
38998
+ /**
38999
+ *
39000
+ * @param {any} resp
39001
+ * @param {any} query
39002
+ * @returns
39003
+ */
39004
+ async applyQuery (resp, query) {
39005
+ if (query.descending) {
39006
+ resp.result = resp.result.reverse();
39007
+ }
39008
+ if (query.limit) {
39009
+ resp.result = resp.result.slice(0, query.limit);
39010
+ }
39011
+ if (query.includeDocs) {
39012
+ resp.result = await Promise.all(
39013
+ resp.result.map(async row => {
39014
+ const doc = await this.database.get(row.id);
39015
+ return { ...row, doc }
39016
+ })
39017
+ );
39018
+ }
39019
+ return resp
39020
+ }
39021
+
39022
+ async doIndexQuery (query = {}) {
39023
+ await loadIndex(this.database.indexBlocks, this.indexByKey, dbIndexOpts);
39024
+ if (!this.indexByKey.root) return { result: [] }
39025
+ if (query.includeDocs === undefined) query.includeDocs = this.includeDocsDefault;
39026
+ if (query.range) {
39027
+ const encodedRange = query.range.map(key => charwise.encode(key));
39028
+ return await this.applyQuery(await this.indexByKey.root.range(...encodedRange), query)
39029
+ } else if (query.key) {
39030
+ const encodedKey = charwise.encode(query.key);
39031
+ return await this.applyQuery(this.indexByKey.root.get(encodedKey), query)
39032
+ } else {
39033
+ const { result, ...all } = await this.indexByKey.root.getAllEntries();
39034
+ return await this.applyQuery(
39035
+ { result: result.map(({ key: [k, id], value }) => ({ key: k, id, row: value })), ...all },
39036
+ query
39037
+ )
39038
+ }
39039
+ }
39040
+
38923
39041
  /**
38924
39042
  * Update the DbIndex with the latest changes
38925
39043
  * @private
@@ -38936,7 +39054,9 @@ class DbIndex {
38936
39054
  })
38937
39055
  }
38938
39056
  this.updateIndexPromise = this.innerUpdateIndex(blocks);
38939
- this.updateIndexPromise.finally(() => { this.updateIndexPromise = null; });
39057
+ this.updateIndexPromise.finally(() => {
39058
+ this.updateIndexPromise = null;
39059
+ });
38940
39060
  return this.updateIndexPromise
38941
39061
  }
38942
39062
 
@@ -38955,7 +39075,7 @@ class DbIndex {
38955
39075
  this.dbHead = result.clock;
38956
39076
  return
38957
39077
  }
38958
- const didT = await doTransaction('updateIndex', inBlocks, async (blocks) => {
39078
+ const didT = await doTransaction('updateIndex', inBlocks, async blocks => {
38959
39079
  let oldIndexEntries = [];
38960
39080
  let removeByIdIndexEntries = [];
38961
39081
  await loadIndex(blocks, this.indexById, idIndexOpts);
@@ -38963,19 +39083,28 @@ class DbIndex {
38963
39083
  // console.log('head', this.dbHead, this.indexById)
38964
39084
  if (this.indexById.root) {
38965
39085
  const oldChangeEntries = await this.indexById.root.getMany(result.rows.map(({ key }) => key));
38966
- oldIndexEntries = oldChangeEntries.result.map((key) => ({ key, del: true }));
39086
+ oldIndexEntries = oldChangeEntries.result.map(key => ({ key, del: true }));
38967
39087
  removeByIdIndexEntries = oldIndexEntries.map(({ key }) => ({ key: key[1], del: true }));
38968
39088
  }
38969
39089
  if (!this.mapFn) {
38970
- throw new Error('No live map function installed for index, cannot update. Make sure your index definition runs before any queries.' + (this.mapFnString ? ' Your code should match the stored map function source:\n' + this.mapFnString : ''))
39090
+ throw new Error(
39091
+ 'No live map function installed for index, cannot update. Make sure your index definition runs before any queries.' +
39092
+ (this.mapFnString ? ' Your code should match the stored map function source:\n' + this.mapFnString : '')
39093
+ )
38971
39094
  }
38972
39095
  const indexEntries = indexEntriesForChanges(result.rows, this.mapFn);
38973
39096
  const byIdIndexEntries = indexEntries.map(({ key }) => ({ key: key[1], value: key }));
38974
- this.indexById = await bulkIndex(blocks, this.indexById, removeByIdIndexEntries.concat(byIdIndexEntries), idIndexOpts);
39097
+ this.indexById = await bulkIndex(
39098
+ blocks,
39099
+ this.indexById,
39100
+ removeByIdIndexEntries.concat(byIdIndexEntries),
39101
+ idIndexOpts
39102
+ );
38975
39103
  this.indexByKey = await bulkIndex(blocks, this.indexByKey, oldIndexEntries.concat(indexEntries), dbIndexOpts);
38976
39104
  this.dbHead = result.clock;
38977
39105
  });
38978
- this.database.notifyExternal('dbIndex');
39106
+ // todo index subscriptions
39107
+ // this.database.notifyExternal('dbIndex')
38979
39108
  // console.timeEnd(callTag + '.doTransactionupdateIndex')
38980
39109
  // console.log(`updateIndex ${callTag} <`, this.instanceId, this.dbHead?.toString(), this.indexByKey.cid?.toString(), this.indexById.cid?.toString())
38981
39110
  return didT
@@ -39037,27 +39166,11 @@ async function loadIndex (blocks, index, indexOpts) {
39037
39166
  return index.root
39038
39167
  }
39039
39168
 
39040
- async function applyLimit (results, limit) {
39041
- results.result = results.result.slice(0, limit);
39042
- return results
39043
- }
39044
-
39045
- async function doIndexQuery (blocks, indexByKey, query = {}) {
39046
- await loadIndex(blocks, indexByKey, dbIndexOpts);
39047
- if (!indexByKey.root) return { result: [] }
39048
- if (query.range) {
39049
- const encodedRange = query.range.map((key) => charwise.encode(key));
39050
- return applyLimit(await indexByKey.root.range(...encodedRange), query.limit)
39051
- } else if (query.key) {
39052
- const encodedKey = charwise.encode(query.key);
39053
- return indexByKey.root.get(encodedKey)
39054
- } else {
39055
- const { result, ...all } = await indexByKey.root.getAllEntries();
39056
- return applyLimit({ result: result.map(({ key: [k, id], value }) => ({ key: k, id, row: value })), ...all }, query.limit)
39057
- }
39058
- }
39059
-
39060
- var browser = {exports: {}};
39169
+ var browserExports = {};
39170
+ var browser = {
39171
+ get exports(){ return browserExports; },
39172
+ set exports(v){ browserExports = v; },
39173
+ };
39061
39174
 
39062
39175
  /**
39063
39176
  * Helpers.
@@ -39773,10 +39886,8 @@ var common = setup;
39773
39886
  } catch (error) {
39774
39887
  return '[UnexpectedJSONParseError]: ' + error.message;
39775
39888
  }
39776
- };
39777
- } (browser, browser.exports));
39778
-
39779
- var browserExports = browser.exports;
39889
+ };
39890
+ } (browser, browserExports));
39780
39891
 
39781
39892
  // originally pulled out of simple-peer
39782
39893
 
@@ -40927,8 +41038,6 @@ Peer.channelConfig = {};
40927
41038
 
40928
41039
  var simplePeer = Peer;
40929
41040
 
40930
- var SimplePeer = /*@__PURE__*/getDefaultExportFromCjs(simplePeer);
40931
-
40932
41041
  /**
40933
41042
  * @typedef {import('./database.js').Database} Database
40934
41043
  */
@@ -40939,7 +41048,7 @@ class Sync {
40939
41048
  * @memberof Sync
40940
41049
  * @static
40941
41050
  */
40942
- constructor (database, PeerClass = SimplePeer) {
41051
+ constructor (database, PeerClass = simplePeer) {
40943
41052
  this.database = database;
40944
41053
  this.database.blocks.syncs.add(this); // should this happen during setup?
40945
41054
  this.PeerClass = PeerClass;
@@ -41147,7 +41256,7 @@ class Fireproof {
41147
41256
  const fp = new Database(new TransactionBlockstore(name, existingConfig.key), [], opts);
41148
41257
  return Fireproof.fromJSON(existingConfig, fp)
41149
41258
  } else {
41150
- const instanceKey = randomBytes$3(32).toString('hex'); // pass null to disable encryption
41259
+ const instanceKey = browserExports$1(32).toString('hex'); // pass null to disable encryption
41151
41260
  return new Database(new TransactionBlockstore(name, instanceKey), [], opts)
41152
41261
  }
41153
41262
  } else {