@fireproof/core 0.5.9 → 0.5.10

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.
@@ -32,9 +32,17 @@ function getAugmentedNamespace(n) {
32
32
  return a;
33
33
  }
34
34
 
35
- var browser$d = {exports: {}};
35
+ var browserExports$1 = {};
36
+ var browser$d = {
37
+ get exports(){ return browserExports$1; },
38
+ set exports(v){ browserExports$1 = v; },
39
+ };
36
40
 
37
- var safeBuffer$1 = {exports: {}};
41
+ var safeBufferExports = {};
42
+ var safeBuffer$1 = {
43
+ get exports(){ return safeBufferExports; },
44
+ set exports(v){ safeBufferExports = v; },
45
+ };
38
46
 
39
47
  var global$1 = (typeof global !== "undefined" ? global :
40
48
  typeof self !== "undefined" ? self :
@@ -2099,10 +2107,8 @@ var require$$6$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_buffer);
2099
2107
  throw new TypeError('Argument must be a number')
2100
2108
  }
2101
2109
  return buffer.SlowBuffer(size)
2102
- };
2103
- } (safeBuffer$1, safeBuffer$1.exports));
2104
-
2105
- var safeBufferExports = safeBuffer$1.exports;
2110
+ };
2111
+ } (safeBuffer$1, safeBufferExports));
2106
2112
 
2107
2113
  // limit of Crypto.getRandomValues()
2108
2114
  // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
@@ -2153,9 +2159,6 @@ function randomBytes$2 (size, cb) {
2153
2159
  return bytes
2154
2160
  }
2155
2161
 
2156
- var browserExports$1 = browser$d.exports;
2157
- var randomBytes$3 = /*@__PURE__*/getDefaultExportFromCjs(browserExports$1);
2158
-
2159
2162
  var encode_1$2 = encode$9;
2160
2163
 
2161
2164
  var MSB$4 = 0x80
@@ -2238,13 +2241,13 @@ var length$2 = function (value) {
2238
2241
  )
2239
2242
  };
2240
2243
 
2241
- var varint$3 = {
2244
+ var varint$2 = {
2242
2245
  encode: encode_1$2
2243
2246
  , decode: decode$d
2244
2247
  , encodingLength: length$2
2245
2248
  };
2246
2249
 
2247
- var _brrp_varint$1 = varint$3;
2250
+ var _brrp_varint$1 = varint$2;
2248
2251
 
2249
2252
  /**
2250
2253
  * @param {Uint8Array} data
@@ -7073,8 +7076,6 @@ var varint$1 = {
7073
7076
  , encodingLength: length$1
7074
7077
  };
7075
7078
 
7076
- var varint$2 = /*@__PURE__*/getDefaultExportFromCjs(varint$1);
7077
-
7078
7079
  const CIDV0_BYTES = {
7079
7080
  SHA2_256: 0x12,
7080
7081
  LENGTH: 0x20,
@@ -7099,8 +7100,8 @@ function decodeVarint (bytes, seeker) {
7099
7100
  if (!bytes.length) {
7100
7101
  throw new Error('Unexpected end of data')
7101
7102
  }
7102
- const i = varint$2.decode(bytes);
7103
- seeker.seek(/** @type {number} */(varint$2.decode.bytes));
7103
+ const i = varint$1.decode(bytes);
7104
+ seeker.seek(/** @type {number} */(varint$1.decode.bytes));
7104
7105
  return i
7105
7106
  /* c8 ignore next 2 */
7106
7107
  // Node.js 12 c8 bug
@@ -7151,10 +7152,10 @@ function getMultihashLength (bytes) {
7151
7152
  // where both code and length are varints, so we have to decode
7152
7153
  // them first before we can know total length
7153
7154
 
7154
- varint$2.decode(bytes); // code
7155
- const codeLength = /** @type {number} */(varint$2.decode.bytes);
7156
- const length = varint$2.decode(bytes.subarray(varint$2.decode.bytes));
7157
- const lengthLength = /** @type {number} */(varint$2.decode.bytes);
7155
+ varint$1.decode(bytes); // code
7156
+ const codeLength = /** @type {number} */(varint$1.decode.bytes);
7157
+ const length = varint$1.decode(bytes.subarray(varint$1.decode.bytes));
7158
+ const lengthLength = /** @type {number} */(varint$1.decode.bytes);
7158
7159
  const mhLength = codeLength + lengthLength + length;
7159
7160
 
7160
7161
  return mhLength
@@ -7862,7 +7863,7 @@ const addRoot = (writer, root, options = {}) => {
7862
7863
  */
7863
7864
  const blockLength = ({ cid, bytes }) => {
7864
7865
  const size = cid.bytes.byteLength + bytes.byteLength;
7865
- return varint$2.encodingLength(size) + size
7866
+ return varint$1.encodingLength(size) + size
7866
7867
  };
7867
7868
 
7868
7869
  /**
@@ -7871,7 +7872,7 @@ const blockLength = ({ cid, bytes }) => {
7871
7872
  */
7872
7873
  const addBlock = (writer, { cid, bytes }) => {
7873
7874
  const byteLength = cid.bytes.byteLength + bytes.byteLength;
7874
- const size = varint$2.encode(byteLength);
7875
+ const size = varint$1.encode(byteLength);
7875
7876
  if (writer.byteOffset + size.length + byteLength > writer.bytes.byteLength) {
7876
7877
  throw new RangeError('Buffer has no capacity for this block')
7877
7878
  } else {
@@ -7891,7 +7892,7 @@ const close = (writer, options = {}) => {
7891
7892
  const { roots, bytes, byteOffset, headerSize } = writer;
7892
7893
 
7893
7894
  const headerBytes = encode$5({ version: 1, roots });
7894
- const varintBytes = varint$2.encode(headerBytes.length);
7895
+ const varintBytes = varint$1.encode(headerBytes.length);
7895
7896
 
7896
7897
  const size = varintBytes.length + headerBytes.byteLength;
7897
7898
  const offset = headerSize - size;
@@ -7968,7 +7969,7 @@ const calculateHeaderLength = (rootLengths) => {
7968
7969
  tokens.push(new Token(Type.bytes, { length: rootLength + 1 }));
7969
7970
  }
7970
7971
  const length = tokensToLength(tokens); // no options needed here because we have simple tokens
7971
- return varint$2.encodingLength(length) + length
7972
+ return varint$1.encodingLength(length) + length
7972
7973
  };
7973
7974
 
7974
7975
  /**
@@ -8311,11 +8312,23 @@ replaceTraps((oldTraps) => ({
8311
8312
  has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
8312
8313
  }));
8313
8314
 
8314
- var cargoQueue$1 = {exports: {}};
8315
+ var cargoQueueExports = {};
8316
+ var cargoQueue$1 = {
8317
+ get exports(){ return cargoQueueExports; },
8318
+ set exports(v){ cargoQueueExports = v; },
8319
+ };
8315
8320
 
8316
- var queue$1 = {exports: {}};
8321
+ var queueExports = {};
8322
+ var queue$1 = {
8323
+ get exports(){ return queueExports; },
8324
+ set exports(v){ queueExports = v; },
8325
+ };
8317
8326
 
8318
- var onlyOnce = {exports: {}};
8327
+ var onlyOnceExports = {};
8328
+ var onlyOnce = {
8329
+ get exports(){ return onlyOnceExports; },
8330
+ set exports(v){ onlyOnceExports = v; },
8331
+ };
8319
8332
 
8320
8333
  (function (module, exports) {
8321
8334
 
@@ -8331,10 +8344,8 @@ var onlyOnce = {exports: {}};
8331
8344
  callFn.apply(this, args);
8332
8345
  };
8333
8346
  }
8334
- module.exports = exports["default"];
8335
- } (onlyOnce, onlyOnce.exports));
8336
-
8337
- var onlyOnceExports = onlyOnce.exports;
8347
+ module.exports = exports["default"];
8348
+ } (onlyOnce, onlyOnceExports));
8338
8349
 
8339
8350
  var setImmediate$1 = {};
8340
8351
 
@@ -8371,7 +8382,11 @@ if (hasQueueMicrotask) {
8371
8382
 
8372
8383
  setImmediate$1.default = wrap(_defer);
8373
8384
 
8374
- var DoublyLinkedList = {exports: {}};
8385
+ var DoublyLinkedListExports = {};
8386
+ var DoublyLinkedList = {
8387
+ get exports(){ return DoublyLinkedListExports; },
8388
+ set exports(v){ DoublyLinkedListExports = v; },
8389
+ };
8375
8390
 
8376
8391
  (function (module, exports) {
8377
8392
 
@@ -8464,16 +8479,22 @@ var DoublyLinkedList = {exports: {}};
8464
8479
  dll.length = 1;
8465
8480
  dll.head = dll.tail = node;
8466
8481
  }
8467
- module.exports = exports["default"];
8468
- } (DoublyLinkedList, DoublyLinkedList.exports));
8469
-
8470
- var DoublyLinkedListExports = DoublyLinkedList.exports;
8482
+ module.exports = exports["default"];
8483
+ } (DoublyLinkedList, DoublyLinkedListExports));
8471
8484
 
8472
8485
  var wrapAsync = {};
8473
8486
 
8474
- var asyncify = {exports: {}};
8487
+ var asyncifyExports = {};
8488
+ var asyncify = {
8489
+ get exports(){ return asyncifyExports; },
8490
+ set exports(v){ asyncifyExports = v; },
8491
+ };
8475
8492
 
8476
- var initialParams = {exports: {}};
8493
+ var initialParamsExports = {};
8494
+ var initialParams = {
8495
+ get exports(){ return initialParamsExports; },
8496
+ set exports(v){ initialParamsExports = v; },
8497
+ };
8477
8498
 
8478
8499
  (function (module, exports) {
8479
8500
 
@@ -8488,15 +8509,13 @@ var initialParams = {exports: {}};
8488
8509
  };
8489
8510
  };
8490
8511
 
8491
- module.exports = exports["default"];
8492
- } (initialParams, initialParams.exports));
8493
-
8494
- var initialParamsExports = initialParams.exports;
8512
+ module.exports = exports["default"];
8513
+ } (initialParams, initialParamsExports));
8495
8514
 
8496
8515
  var hasRequiredAsyncify;
8497
8516
 
8498
8517
  function requireAsyncify () {
8499
- if (hasRequiredAsyncify) return asyncify.exports;
8518
+ if (hasRequiredAsyncify) return asyncifyExports;
8500
8519
  hasRequiredAsyncify = 1;
8501
8520
  (function (module, exports) {
8502
8521
 
@@ -8615,9 +8634,9 @@ function requireAsyncify () {
8615
8634
  }, err);
8616
8635
  }
8617
8636
  }
8618
- module.exports = exports['default'];
8619
- } (asyncify, asyncify.exports));
8620
- return asyncify.exports;
8637
+ module.exports = exports['default'];
8638
+ } (asyncify, asyncifyExports));
8639
+ return asyncifyExports;
8621
8640
  }
8622
8641
 
8623
8642
  var hasRequiredWrapAsync;
@@ -8954,10 +8973,8 @@ function requireWrapAsync () {
8954
8973
  });
8955
8974
  return q;
8956
8975
  }
8957
- module.exports = exports['default'];
8958
- } (queue$1, queue$1.exports));
8959
-
8960
- var queueExports = queue$1.exports;
8976
+ module.exports = exports['default'];
8977
+ } (queue$1, queueExports));
8961
8978
 
8962
8979
  (function (module, exports) {
8963
8980
 
@@ -9029,10 +9046,9 @@ var queueExports = queue$1.exports;
9029
9046
  function cargo(worker, concurrency, payload) {
9030
9047
  return (0, _queue2.default)(worker, concurrency, payload);
9031
9048
  }
9032
- module.exports = exports['default'];
9033
- } (cargoQueue$1, cargoQueue$1.exports));
9049
+ module.exports = exports['default'];
9050
+ } (cargoQueue$1, cargoQueueExports));
9034
9051
 
9035
- var cargoQueueExports = cargoQueue$1.exports;
9036
9052
  var cargoQueue = /*@__PURE__*/getDefaultExportFromCjs(cargoQueueExports);
9037
9053
 
9038
9054
  var cryptoBrowserify = {};
@@ -9069,7 +9085,11 @@ var _polyfillNode_inherits = /*#__PURE__*/Object.freeze({
9069
9085
 
9070
9086
  var require$$3$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_inherits);
9071
9087
 
9072
- var readableBrowser = {exports: {}};
9088
+ var readableBrowserExports = {};
9089
+ var readableBrowser = {
9090
+ get exports(){ return readableBrowserExports; },
9091
+ set exports(v){ readableBrowserExports = v; },
9092
+ };
9073
9093
 
9074
9094
  var domain;
9075
9095
 
@@ -13466,10 +13486,8 @@ var pipeline_1 = pipeline;
13466
13486
  exports.Transform = _stream_transform;
13467
13487
  exports.PassThrough = _stream_passthrough;
13468
13488
  exports.finished = endOfStream;
13469
- exports.pipeline = pipeline_1;
13470
- } (readableBrowser, readableBrowser.exports));
13471
-
13472
- var readableBrowserExports = readableBrowser.exports;
13489
+ exports.pipeline = pipeline_1;
13490
+ } (readableBrowser, readableBrowserExports));
13473
13491
 
13474
13492
  var Buffer$E = safeBufferExports.Buffer;
13475
13493
  var Transform$6 = readableBrowserExports.Transform;
@@ -13875,7 +13893,11 @@ function fn5 (a, b, c, d, e, m, k, s) {
13875
13893
 
13876
13894
  var ripemd160 = RIPEMD160$4;
13877
13895
 
13878
- var sha_js = {exports: {}};
13896
+ var sha_jsExports = {};
13897
+ var sha_js = {
13898
+ get exports(){ return sha_jsExports; },
13899
+ set exports(v){ sha_jsExports = v; },
13900
+ };
13879
13901
 
13880
13902
  var Buffer$B = safeBufferExports.Buffer;
13881
13903
 
@@ -14679,8 +14701,6 @@ exports.sha256 = sha256$1;
14679
14701
  exports.sha384 = sha384$1;
14680
14702
  exports.sha512 = sha512$1;
14681
14703
 
14682
- var sha_jsExports = sha_js.exports;
14683
-
14684
14704
  function BufferList() {
14685
14705
  this.head = null;
14686
14706
  this.tail = null;
@@ -16631,6 +16651,12 @@ var browser$9 = function createHmac (alg, key) {
16631
16651
  return new Hmac$2(alg, key)
16632
16652
  };
16633
16653
 
16654
+ var algosExports = {};
16655
+ var algos = {
16656
+ get exports(){ return algosExports; },
16657
+ set exports(v){ algosExports = v; },
16658
+ };
16659
+
16634
16660
  var sha224WithRSAEncryption = {
16635
16661
  sign: "rsa",
16636
16662
  hash: "sha224",
@@ -16795,7 +16821,9 @@ var require$$6 = {
16795
16821
  }
16796
16822
  };
16797
16823
 
16798
- var algos = require$$6;
16824
+ (function (module) {
16825
+ module.exports = require$$6;
16826
+ } (algos));
16799
16827
 
16800
16828
  var browser$8 = {};
16801
16829
 
@@ -19035,7 +19063,7 @@ var modes = {};
19035
19063
  exports['des-ede'] = {
19036
19064
  key: 16,
19037
19065
  iv: 0
19038
- };
19066
+ };
19039
19067
  } (modes));
19040
19068
 
19041
19069
  var DES = browserifyDes;
@@ -19108,9 +19136,11 @@ browser$7.listCiphers = browser$7.getCiphers = getCiphers;
19108
19136
 
19109
19137
  var browser$5 = {};
19110
19138
 
19111
- var bn$1 = {exports: {}};
19112
-
19113
- bn$1.exports;
19139
+ var bnExports$1 = {};
19140
+ var bn$1 = {
19141
+ get exports(){ return bnExports$1; },
19142
+ set exports(v){ bnExports$1 = v; },
19143
+ };
19114
19144
 
19115
19145
  (function (module) {
19116
19146
  (function (module, exports) {
@@ -22555,17 +22585,19 @@ bn$1.exports;
22555
22585
  var res = this.imod(a._invmp(this.m).mul(this.r2));
22556
22586
  return res._forceRed(this);
22557
22587
  };
22558
- })(module, commonjsGlobal);
22588
+ })(module, commonjsGlobal);
22559
22589
  } (bn$1));
22560
22590
 
22561
- var bnExports$1 = bn$1.exports;
22562
-
22563
- var brorand = {exports: {}};
22591
+ var brorandExports = {};
22592
+ var brorand = {
22593
+ get exports(){ return brorandExports; },
22594
+ set exports(v){ brorandExports = v; },
22595
+ };
22564
22596
 
22565
22597
  var hasRequiredBrorand;
22566
22598
 
22567
22599
  function requireBrorand () {
22568
- if (hasRequiredBrorand) return brorand.exports;
22600
+ if (hasRequiredBrorand) return brorandExports;
22569
22601
  hasRequiredBrorand = 1;
22570
22602
  var r;
22571
22603
 
@@ -22579,7 +22611,7 @@ function requireBrorand () {
22579
22611
  function Rand(rand) {
22580
22612
  this.rand = rand;
22581
22613
  }
22582
- brorand.exports.Rand = Rand;
22614
+ brorandExports.Rand = Rand;
22583
22615
 
22584
22616
  Rand.prototype.generate = function generate(len) {
22585
22617
  return this._rand(len);
@@ -22632,7 +22664,7 @@ function requireBrorand () {
22632
22664
  } catch (e) {
22633
22665
  }
22634
22666
  }
22635
- return brorand.exports;
22667
+ return brorandExports;
22636
22668
  }
22637
22669
 
22638
22670
  var mr;
@@ -23139,11 +23171,17 @@ function requireBrowser$2 () {
23139
23171
  return browser$5;
23140
23172
  }
23141
23173
 
23142
- var sign = {exports: {}};
23143
-
23144
- var bn = {exports: {}};
23174
+ var signExports = {};
23175
+ var sign = {
23176
+ get exports(){ return signExports; },
23177
+ set exports(v){ signExports = v; },
23178
+ };
23145
23179
 
23146
- bn.exports;
23180
+ var bnExports = {};
23181
+ var bn = {
23182
+ get exports(){ return bnExports; },
23183
+ set exports(v){ bnExports = v; },
23184
+ };
23147
23185
 
23148
23186
  (function (module) {
23149
23187
  (function (module, exports) {
@@ -26493,11 +26531,9 @@ bn.exports;
26493
26531
  var res = this.imod(a._invmp(this.m).mul(this.r2));
26494
26532
  return res._forceRed(this);
26495
26533
  };
26496
- })(module, commonjsGlobal);
26534
+ })(module, commonjsGlobal);
26497
26535
  } (bn));
26498
26536
 
26499
- var bnExports = bn.exports;
26500
-
26501
26537
  var BN$a = bnExports;
26502
26538
  var randomBytes$1 = browserExports$1;
26503
26539
 
@@ -26668,7 +26704,7 @@ var utils$k = {};
26668
26704
  return toHex(arr);
26669
26705
  else
26670
26706
  return arr;
26671
- };
26707
+ };
26672
26708
  } (utils$k));
26673
26709
 
26674
26710
  (function (exports) {
@@ -26788,7 +26824,7 @@ var utils$k = {};
26788
26824
  function intFromLE(bytes) {
26789
26825
  return new BN(bytes, 'hex', 'le');
26790
26826
  }
26791
- utils.intFromLE = intFromLE;
26827
+ utils.intFromLE = intFromLE;
26792
26828
  } (utils$l));
26793
26829
 
26794
26830
  var curve = {};
@@ -28727,7 +28763,7 @@ Point.prototype.mixedAdd = Point.prototype.add;
28727
28763
  curve.base = base$2;
28728
28764
  curve.short = short;
28729
28765
  curve.mont = mont;
28730
- curve.edwards = edwards;
28766
+ curve.edwards = edwards;
28731
28767
  } (curve));
28732
28768
 
28733
28769
  var curves$1 = {};
@@ -29940,7 +29976,7 @@ Hmac.prototype.digest = function digest(enc) {
29940
29976
  hash.sha224 = hash.sha.sha224;
29941
29977
  hash.sha384 = hash.sha.sha384;
29942
29978
  hash.sha512 = hash.sha.sha512;
29943
- hash.ripemd160 = hash.ripemd.ripemd160;
29979
+ hash.ripemd160 = hash.ripemd.ripemd160;
29944
29980
  } (hash$2));
29945
29981
 
29946
29982
  var secp256k1;
@@ -30937,7 +30973,7 @@ function requireSecp256k1 () {
30937
30973
  '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
30938
30974
  pre,
30939
30975
  ],
30940
- });
30976
+ });
30941
30977
  } (curves$1));
30942
30978
 
30943
30979
  var hash$1 = hash$2;
@@ -31880,8 +31916,8 @@ function requireElliptic () {
31880
31916
 
31881
31917
  // Protocols
31882
31918
  elliptic.ec = requireEc();
31883
- elliptic.eddsa = eddsa;
31884
- } (elliptic));
31919
+ elliptic.eddsa = eddsa;
31920
+ } (elliptic));
31885
31921
  return elliptic;
31886
31922
  }
31887
31923
 
@@ -32941,7 +32977,7 @@ var der$2 = {};
32941
32977
  0x1d: 'charstr',
32942
32978
  0x1e: 'bmpstr'
32943
32979
  };
32944
- exports.tagByName = reverse(exports.tag);
32980
+ exports.tagByName = reverse(exports.tag);
32945
32981
  } (der$2));
32946
32982
 
32947
32983
  const inherits$3 = require$$3$1;
@@ -33265,7 +33301,7 @@ PEMEncoder.prototype.encode = function encode(data, options) {
33265
33301
  const encoders = exports;
33266
33302
 
33267
33303
  encoders.der = der_1$1;
33268
- encoders.pem = pem$1;
33304
+ encoders.pem = pem$1;
33269
33305
  } (encoders));
33270
33306
 
33271
33307
  var decoders = {};
@@ -33659,7 +33695,7 @@ PEMDecoder.prototype.decode = function decode(data, options) {
33659
33695
  const decoders = exports;
33660
33696
 
33661
33697
  decoders.der = der_1;
33662
- decoders.pem = pem;
33698
+ decoders.pem = pem;
33663
33699
  } (decoders));
33664
33700
 
33665
33701
  (function (exports) {
@@ -33718,7 +33754,7 @@ PEMDecoder.prototype.decode = function decode(data, options) {
33718
33754
 
33719
33755
  Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
33720
33756
  return this._getEncoder(enc).encode(data, reporter);
33721
- };
33757
+ };
33722
33758
  } (api));
33723
33759
 
33724
33760
  var base$1 = {};
@@ -33730,7 +33766,7 @@ var base$1 = {};
33730
33766
  base.Reporter = reporter.Reporter;
33731
33767
  base.DecoderBuffer = buffer.DecoderBuffer;
33732
33768
  base.EncoderBuffer = buffer.EncoderBuffer;
33733
- base.Node = node;
33769
+ base.Node = node;
33734
33770
  } (base$1));
33735
33771
 
33736
33772
  var constants = {};
@@ -33755,7 +33791,7 @@ var constants = {};
33755
33791
  return res;
33756
33792
  };
33757
33793
 
33758
- constants.der = der$2;
33794
+ constants.der = der$2;
33759
33795
  } (constants));
33760
33796
 
33761
33797
  (function (exports) {
@@ -33768,7 +33804,7 @@ var constants = {};
33768
33804
  asn1.base = base$1;
33769
33805
  asn1.constants = constants;
33770
33806
  asn1.decoders = decoders;
33771
- asn1.encoders = encoders;
33807
+ asn1.encoders = encoders;
33772
33808
  } (asn1$2));
33773
33809
 
33774
33810
  var asn = asn1$2;
@@ -34142,7 +34178,7 @@ var require$$4 = {
34142
34178
  var hasRequiredSign;
34143
34179
 
34144
34180
  function requireSign () {
34145
- if (hasRequiredSign) return sign.exports;
34181
+ if (hasRequiredSign) return signExports;
34146
34182
  hasRequiredSign = 1;
34147
34183
  // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
34148
34184
  var Buffer = safeBufferExports.Buffer;
@@ -34285,9 +34321,9 @@ function requireSign () {
34285
34321
  }
34286
34322
 
34287
34323
  sign.exports = sign$1;
34288
- sign.exports.getKey = getKey;
34289
- sign.exports.makeKey = makeKey;
34290
- return sign.exports;
34324
+ signExports.getKey = getKey;
34325
+ signExports.makeKey = makeKey;
34326
+ return signExports;
34291
34327
  }
34292
34328
 
34293
34329
  var verify_1;
@@ -34866,7 +34902,7 @@ function compare$3 (a, b) {
34866
34902
 
34867
34903
  exports.publicDecrypt = function publicDecrypt (key, buf) {
34868
34904
  return exports.privateDecrypt(key, buf, true)
34869
- };
34905
+ };
34870
34906
  } (browser$2));
34871
34907
 
34872
34908
  var browser$1 = {};
@@ -34988,8 +35024,8 @@ function requireCryptoBrowserify () {
34988
35024
  cryptoBrowserify.createHash = cryptoBrowserify.Hash = browser$a;
34989
35025
  cryptoBrowserify.createHmac = cryptoBrowserify.Hmac = browser$9;
34990
35026
 
34991
- var algos$1 = algos;
34992
- var algoKeys = Object.keys(algos$1);
35027
+ var algos = algosExports;
35028
+ var algoKeys = Object.keys(algos);
34993
35029
  var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
34994
35030
  cryptoBrowserify.getHashes = function () {
34995
35031
  return hashes
@@ -37851,7 +37887,7 @@ async function visMerkleClock (blocks, head) {
37851
37887
  return { vis: lines.join('\n') }
37852
37888
  }
37853
37889
 
37854
- var charwise$1 = {};
37890
+ var charwise = {};
37855
37891
 
37856
37892
  var number = {};
37857
37893
 
@@ -38079,10 +38115,8 @@ object.factory = function (codec) {
38079
38115
 
38080
38116
  //for leveldb, request strings
38081
38117
  exports.buffer = false;
38082
- exports.type = 'charwise';
38083
- } (charwise$1));
38084
-
38085
- var charwise = /*@__PURE__*/getDefaultExportFromCjs(charwise$1);
38118
+ exports.type = 'charwise';
38119
+ } (charwise));
38086
38120
 
38087
38121
  /* global localStorage */
38088
38122
  let storageSupported = false;
@@ -38180,9 +38214,9 @@ class Database {
38180
38214
  }
38181
38215
 
38182
38216
  // used be indexes etc to notify database listeners of new availability
38183
- async notifyExternal (source = 'unknown') {
38184
- await this.notifyListeners({ _external: source, _clock: this.clockToJSON() });
38185
- }
38217
+ // async notifyExternal (source = 'unknown') {
38218
+ // // await this.notifyListeners({ _external: source, _clock: this.clockToJSON() })
38219
+ // }
38186
38220
 
38187
38221
  /**
38188
38222
  * Returns the changes made to the Fireproof instance since the specified event.
@@ -38442,13 +38476,23 @@ class Database {
38442
38476
  * @returns {Function} - A function that can be called to unregister the listener.
38443
38477
  * @memberof Fireproof
38444
38478
  */
38445
- registerListener (listener) {
38479
+ subscribe (listener) {
38446
38480
  this.listeners.add(listener);
38447
38481
  return () => {
38448
38482
  this.listeners.delete(listener);
38449
38483
  }
38450
38484
  }
38451
38485
 
38486
+ /**
38487
+ * @deprecated 0.7.0 - renamed subscribe(listener)
38488
+ * @param {Function} listener - The listener to be called when the clock is updated.
38489
+ * @returns {Function} - A function that can be called to unregister the listener.
38490
+ * @memberof Fireproof
38491
+ */
38492
+ registerListener (listener) {
38493
+ return this.subscribe(listener)
38494
+ }
38495
+
38452
38496
  async notifyListeners (changes) {
38453
38497
  // await sleep(10)
38454
38498
  await this.maybeSaveClock();
@@ -38497,7 +38541,9 @@ function encodeEvent (event) {
38497
38541
  * @param {Function} routingFn - The routing function to apply to each entry in the database.
38498
38542
  */
38499
38543
  // import { ChangeEvent } from './db-index'
38500
-
38544
+ /**
38545
+ * @deprecated since version 0.7.0
38546
+ */
38501
38547
  class Listener {
38502
38548
  subcribers = new Map()
38503
38549
  doStopListening = null
@@ -38781,14 +38827,23 @@ const makeDoc = ({ key, value }) => ({ _id: key, ...value });
38781
38827
  const indexEntriesForChanges = (changes, mapFn) => {
38782
38828
  const indexEntries = [];
38783
38829
  changes.forEach(({ key, value, del }) => {
38830
+ // key is _id, value is the document
38784
38831
  if (del || !value) return
38785
- mapFn(makeDoc({ key, value }), (k, v) => {
38832
+ let mapCalled = false;
38833
+ const mapReturn = mapFn(makeDoc({ key, value }), (k, v) => {
38834
+ mapCalled = true;
38786
38835
  if (typeof k === 'undefined') return
38787
38836
  indexEntries.push({
38788
38837
  key: [charwise.encode(k), key],
38789
38838
  value: v || null
38790
38839
  });
38791
38840
  });
38841
+ if (!mapCalled && mapReturn) {
38842
+ indexEntries.push({
38843
+ key: [charwise.encode(mapReturn), key],
38844
+ value: null
38845
+ });
38846
+ }
38792
38847
  });
38793
38848
  return indexEntries
38794
38849
  };
@@ -38810,7 +38865,10 @@ class DbIndex {
38810
38865
  constructor (database, name, mapFn, clock = null, opts = {}) {
38811
38866
  this.database = database;
38812
38867
  if (!database.indexBlocks) {
38813
- database.indexBlocks = new TransactionBlockstore(database?.name + '.indexes', database.blocks.valet?.getKeyMaterial());
38868
+ database.indexBlocks = new TransactionBlockstore(
38869
+ database?.name + '.indexes',
38870
+ database.blocks.valet?.getKeyMaterial()
38871
+ );
38814
38872
  }
38815
38873
  if (typeof name === 'function') {
38816
38874
  // app is using deprecated API, remove in 0.7
@@ -38819,13 +38877,8 @@ class DbIndex {
38819
38877
  mapFn = name;
38820
38878
  name = null;
38821
38879
  }
38822
- if (typeof mapFn === 'string') {
38823
- this.mapFnString = mapFn;
38824
- } else {
38825
- this.mapFn = mapFn;
38826
- this.mapFnString = mapFn.toString();
38827
- }
38828
- this.name = name || this.makeName();
38880
+ this.applyMapFn(mapFn, name);
38881
+
38829
38882
  this.indexById = { root: null, cid: null };
38830
38883
  this.indexByKey = { root: null, cid: null };
38831
38884
  this.dbHead = null;
@@ -38836,13 +38889,34 @@ class DbIndex {
38836
38889
  }
38837
38890
  this.instanceId = this.database.instanceId + `.DbIndex.${Math.random().toString(36).substring(2, 7)}`;
38838
38891
  this.updateIndexPromise = null;
38839
- if (!opts.temporary) { DbIndex.registerWithDatabase(this, this.database); }
38892
+ if (!opts.temporary) {
38893
+ DbIndex.registerWithDatabase(this, this.database);
38894
+ }
38895
+ }
38896
+
38897
+ applyMapFn (mapFn, name) {
38898
+ if (typeof mapFn === 'string') {
38899
+ this.mapFnString = mapFn;
38900
+ } else {
38901
+ this.mapFn = mapFn;
38902
+ this.mapFnString = mapFn.toString();
38903
+ }
38904
+ this.name = name || this.makeName();
38840
38905
  }
38841
38906
 
38842
38907
  makeName () {
38843
38908
  const regex = /\(([^,()]+,\s*[^,()]+|\[[^\]]+\],\s*[^,()]+)\)/g;
38844
- const matches = Array.from(this.mapFnString.matchAll(regex), match => match[1].trim());
38845
- return matches[1]
38909
+ let matches = Array.from(this.mapFnString.matchAll(regex), match => match[1].trim());
38910
+ if (matches.length === 0) {
38911
+ matches = /=>\s*(.*)/.exec(this.mapFnString);
38912
+ }
38913
+ if (matches.length === 0) {
38914
+ return this.mapFnString
38915
+ } else {
38916
+ // it's a consise arrow function, match everythign after the arrow
38917
+ this.includeDocsDefault = true;
38918
+ return matches[1]
38919
+ }
38846
38920
  }
38847
38921
 
38848
38922
  static registerWithDatabase (inIndex, database) {
@@ -38852,7 +38926,8 @@ class DbIndex {
38852
38926
  // merge our inIndex code with the inIndex clock or vice versa
38853
38927
  const existingIndex = database.indexes.get(inIndex.mapFnString);
38854
38928
  // keep the code instance, discard the clock instance
38855
- if (existingIndex.mapFn) { // this one also has other config
38929
+ if (existingIndex.mapFn) {
38930
+ // this one also has other config
38856
38931
  existingIndex.dbHead = inIndex.dbHead;
38857
38932
  existingIndex.indexById.cid = inIndex.indexById.cid;
38858
38933
  existingIndex.indexByKey.cid = inIndex.indexByKey.cid;
@@ -38896,7 +38971,7 @@ class DbIndex {
38896
38971
  /**
38897
38972
  * Query object can have {range}
38898
38973
  * @param {DbQuery} query - the query range to use
38899
- * @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
38974
+ * @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any, doc?: any}>}>}
38900
38975
  * @memberof DbIndex
38901
38976
  * @instance
38902
38977
  */
@@ -38904,20 +38979,63 @@ class DbIndex {
38904
38979
  // const callId = Math.random().toString(36).substring(2, 7)
38905
38980
  // todo pass a root to query a snapshot
38906
38981
  // console.time(callId + '.updateIndex')
38907
- update && await this.updateIndex(this.database.indexBlocks);
38982
+ update && (await this.updateIndex(this.database.indexBlocks));
38908
38983
  // console.timeEnd(callId + '.updateIndex')
38909
38984
  // console.time(callId + '.doIndexQuery')
38910
38985
  // console.log('query', query)
38911
- const response = await doIndexQuery(this.database.indexBlocks, this.indexByKey, query);
38986
+ const response = await this.doIndexQuery(query);
38912
38987
  // console.timeEnd(callId + '.doIndexQuery')
38913
38988
  return {
38914
38989
  proof: { index: await cidsToProof(response.cids) },
38915
- rows: response.result.map(({ id, key, row }) => {
38916
- return ({ id, key: charwise.decode(key), value: row })
38990
+ rows: response.result.map(({ id, key, row, doc }) => {
38991
+ return { id, key: charwise.decode(key), value: row, doc }
38917
38992
  })
38918
38993
  }
38919
38994
  }
38920
38995
 
38996
+ /**
38997
+ *
38998
+ * @param {any} resp
38999
+ * @param {any} query
39000
+ * @returns
39001
+ */
39002
+ async applyQuery (resp, query) {
39003
+ if (query.descending) {
39004
+ resp.result = resp.result.reverse();
39005
+ }
39006
+ if (query.limit) {
39007
+ resp.result = resp.result.slice(0, query.limit);
39008
+ }
39009
+ if (query.includeDocs) {
39010
+ resp.result = await Promise.all(
39011
+ resp.result.map(async row => {
39012
+ const doc = await this.database.get(row.id);
39013
+ return { ...row, doc }
39014
+ })
39015
+ );
39016
+ }
39017
+ return resp
39018
+ }
39019
+
39020
+ async doIndexQuery (query = {}) {
39021
+ await loadIndex(this.database.indexBlocks, this.indexByKey, dbIndexOpts);
39022
+ if (!this.indexByKey.root) return { result: [] }
39023
+ if (query.includeDocs === undefined) query.includeDocs = this.includeDocsDefault;
39024
+ if (query.range) {
39025
+ const encodedRange = query.range.map(key => charwise.encode(key));
39026
+ return await this.applyQuery(await this.indexByKey.root.range(...encodedRange), query)
39027
+ } else if (query.key) {
39028
+ const encodedKey = charwise.encode(query.key);
39029
+ return await this.applyQuery(this.indexByKey.root.get(encodedKey), query)
39030
+ } else {
39031
+ const { result, ...all } = await this.indexByKey.root.getAllEntries();
39032
+ return await this.applyQuery(
39033
+ { result: result.map(({ key: [k, id], value }) => ({ key: k, id, row: value })), ...all },
39034
+ query
39035
+ )
39036
+ }
39037
+ }
39038
+
38921
39039
  /**
38922
39040
  * Update the DbIndex with the latest changes
38923
39041
  * @private
@@ -38934,7 +39052,9 @@ class DbIndex {
38934
39052
  })
38935
39053
  }
38936
39054
  this.updateIndexPromise = this.innerUpdateIndex(blocks);
38937
- this.updateIndexPromise.finally(() => { this.updateIndexPromise = null; });
39055
+ this.updateIndexPromise.finally(() => {
39056
+ this.updateIndexPromise = null;
39057
+ });
38938
39058
  return this.updateIndexPromise
38939
39059
  }
38940
39060
 
@@ -38953,7 +39073,7 @@ class DbIndex {
38953
39073
  this.dbHead = result.clock;
38954
39074
  return
38955
39075
  }
38956
- const didT = await doTransaction('updateIndex', inBlocks, async (blocks) => {
39076
+ const didT = await doTransaction('updateIndex', inBlocks, async blocks => {
38957
39077
  let oldIndexEntries = [];
38958
39078
  let removeByIdIndexEntries = [];
38959
39079
  await loadIndex(blocks, this.indexById, idIndexOpts);
@@ -38961,19 +39081,28 @@ class DbIndex {
38961
39081
  // console.log('head', this.dbHead, this.indexById)
38962
39082
  if (this.indexById.root) {
38963
39083
  const oldChangeEntries = await this.indexById.root.getMany(result.rows.map(({ key }) => key));
38964
- oldIndexEntries = oldChangeEntries.result.map((key) => ({ key, del: true }));
39084
+ oldIndexEntries = oldChangeEntries.result.map(key => ({ key, del: true }));
38965
39085
  removeByIdIndexEntries = oldIndexEntries.map(({ key }) => ({ key: key[1], del: true }));
38966
39086
  }
38967
39087
  if (!this.mapFn) {
38968
- 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 : ''))
39088
+ throw new Error(
39089
+ 'No live map function installed for index, cannot update. Make sure your index definition runs before any queries.' +
39090
+ (this.mapFnString ? ' Your code should match the stored map function source:\n' + this.mapFnString : '')
39091
+ )
38969
39092
  }
38970
39093
  const indexEntries = indexEntriesForChanges(result.rows, this.mapFn);
38971
39094
  const byIdIndexEntries = indexEntries.map(({ key }) => ({ key: key[1], value: key }));
38972
- this.indexById = await bulkIndex(blocks, this.indexById, removeByIdIndexEntries.concat(byIdIndexEntries), idIndexOpts);
39095
+ this.indexById = await bulkIndex(
39096
+ blocks,
39097
+ this.indexById,
39098
+ removeByIdIndexEntries.concat(byIdIndexEntries),
39099
+ idIndexOpts
39100
+ );
38973
39101
  this.indexByKey = await bulkIndex(blocks, this.indexByKey, oldIndexEntries.concat(indexEntries), dbIndexOpts);
38974
39102
  this.dbHead = result.clock;
38975
39103
  });
38976
- this.database.notifyExternal('dbIndex');
39104
+ // todo index subscriptions
39105
+ // this.database.notifyExternal('dbIndex')
38977
39106
  // console.timeEnd(callTag + '.doTransactionupdateIndex')
38978
39107
  // console.log(`updateIndex ${callTag} <`, this.instanceId, this.dbHead?.toString(), this.indexByKey.cid?.toString(), this.indexById.cid?.toString())
38979
39108
  return didT
@@ -39035,27 +39164,11 @@ async function loadIndex (blocks, index, indexOpts) {
39035
39164
  return index.root
39036
39165
  }
39037
39166
 
39038
- async function applyLimit (results, limit) {
39039
- results.result = results.result.slice(0, limit);
39040
- return results
39041
- }
39042
-
39043
- async function doIndexQuery (blocks, indexByKey, query = {}) {
39044
- await loadIndex(blocks, indexByKey, dbIndexOpts);
39045
- if (!indexByKey.root) return { result: [] }
39046
- if (query.range) {
39047
- const encodedRange = query.range.map((key) => charwise.encode(key));
39048
- return applyLimit(await indexByKey.root.range(...encodedRange), query.limit)
39049
- } else if (query.key) {
39050
- const encodedKey = charwise.encode(query.key);
39051
- return indexByKey.root.get(encodedKey)
39052
- } else {
39053
- const { result, ...all } = await indexByKey.root.getAllEntries();
39054
- return applyLimit({ result: result.map(({ key: [k, id], value }) => ({ key: k, id, row: value })), ...all }, query.limit)
39055
- }
39056
- }
39057
-
39058
- var browser = {exports: {}};
39167
+ var browserExports = {};
39168
+ var browser = {
39169
+ get exports(){ return browserExports; },
39170
+ set exports(v){ browserExports = v; },
39171
+ };
39059
39172
 
39060
39173
  /**
39061
39174
  * Helpers.
@@ -39771,10 +39884,8 @@ var common = setup;
39771
39884
  } catch (error) {
39772
39885
  return '[UnexpectedJSONParseError]: ' + error.message;
39773
39886
  }
39774
- };
39775
- } (browser, browser.exports));
39776
-
39777
- var browserExports = browser.exports;
39887
+ };
39888
+ } (browser, browserExports));
39778
39889
 
39779
39890
  // originally pulled out of simple-peer
39780
39891
 
@@ -40925,8 +41036,6 @@ Peer.channelConfig = {};
40925
41036
 
40926
41037
  var simplePeer = Peer;
40927
41038
 
40928
- var SimplePeer = /*@__PURE__*/getDefaultExportFromCjs(simplePeer);
40929
-
40930
41039
  /**
40931
41040
  * @typedef {import('./database.js').Database} Database
40932
41041
  */
@@ -40937,7 +41046,7 @@ class Sync {
40937
41046
  * @memberof Sync
40938
41047
  * @static
40939
41048
  */
40940
- constructor (database, PeerClass = SimplePeer) {
41049
+ constructor (database, PeerClass = simplePeer) {
40941
41050
  this.database = database;
40942
41051
  this.database.blocks.syncs.add(this); // should this happen during setup?
40943
41052
  this.PeerClass = PeerClass;
@@ -41145,7 +41254,7 @@ class Fireproof {
41145
41254
  const fp = new Database(new TransactionBlockstore(name, existingConfig.key), [], opts);
41146
41255
  return Fireproof.fromJSON(existingConfig, fp)
41147
41256
  } else {
41148
- const instanceKey = randomBytes$3(32).toString('hex'); // pass null to disable encryption
41257
+ const instanceKey = browserExports$1(32).toString('hex'); // pass null to disable encryption
41149
41258
  return new Database(new TransactionBlockstore(name, instanceKey), [], opts)
41150
41259
  }
41151
41260
  } else {