@fireproof/core 0.7.2-dev.8 → 0.7.3-dev.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8198,7 +8198,15 @@ var _polyfillNode_events = /*#__PURE__*/Object.freeze({
8198
8198
 
8199
8199
  var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_events);
8200
8200
 
8201
- var streamBrowser = require$$0$1.EventEmitter;
8201
+ var streamBrowser;
8202
+ var hasRequiredStreamBrowser;
8203
+
8204
+ function requireStreamBrowser () {
8205
+ if (hasRequiredStreamBrowser) return streamBrowser;
8206
+ hasRequiredStreamBrowser = 1;
8207
+ streamBrowser = require$$0$1.EventEmitter;
8208
+ return streamBrowser;
8209
+ }
8202
8210
 
8203
8211
  // shim for using process in browser
8204
8212
  // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
@@ -8341,7 +8349,7 @@ var argv = [];
8341
8349
  var version$1 = ''; // empty string to avoid regexp issues
8342
8350
  var versions = {};
8343
8351
  var release = {};
8344
- var config$1 = {};
8352
+ var config = {};
8345
8353
 
8346
8354
  function noop$3() {}
8347
8355
 
@@ -8418,7 +8426,7 @@ var browser$1$1 = {
8418
8426
  hrtime: hrtime,
8419
8427
  platform: platform,
8420
8428
  release: release,
8421
- config: config$1,
8429
+ config: config,
8422
8430
  uptime: uptime
8423
8431
  };
8424
8432
 
@@ -8499,11 +8507,11 @@ function format(f) {
8499
8507
  // Mark that a method should not be used.
8500
8508
  // Returns a modified function which warns once by default.
8501
8509
  // If --no-deprecation is set, then it is a no-op.
8502
- function deprecate$1(fn, msg) {
8510
+ function deprecate(fn, msg) {
8503
8511
  // Allow for deprecating things in the process of starting up.
8504
8512
  if (isUndefined(global$1.process)) {
8505
8513
  return function() {
8506
- return deprecate$1(fn, msg).apply(this, arguments);
8514
+ return deprecate(fn, msg).apply(this, arguments);
8507
8515
  };
8508
8516
  }
8509
8517
 
@@ -9112,7 +9120,7 @@ var _polyfillNode_util = {
9112
9120
  isBoolean: isBoolean,
9113
9121
  isArray: isArray,
9114
9122
  inspect: inspect,
9115
- deprecate: deprecate$1,
9123
+ deprecate: deprecate,
9116
9124
  format: format,
9117
9125
  debuglog: debuglog,
9118
9126
  promisify: promisify,
@@ -9125,7 +9133,7 @@ var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
9125
9133
  callbackify: callbackify,
9126
9134
  debuglog: debuglog,
9127
9135
  default: _polyfillNode_util,
9128
- deprecate: deprecate$1,
9136
+ deprecate: deprecate,
9129
9137
  format: format,
9130
9138
  inherits: inherits$1,
9131
9139
  inspect: inspect,
@@ -9313,99 +9321,108 @@ function requireBuffer_list () {
9313
9321
  return buffer_list;
9314
9322
  }
9315
9323
 
9316
- // undocumented cb() API, needed for core, not for public API
9317
- function destroy(err, cb) {
9318
- const readableDestroyed = this._readableState && this._readableState.destroyed;
9319
- const writableDestroyed = this._writableState && this._writableState.destroyed;
9320
- if (readableDestroyed || writableDestroyed) {
9321
- if (cb) {
9322
- cb(err);
9323
- } else if (err) {
9324
- if (!this._writableState) {
9325
- process.nextTick(emitErrorNT, this, err);
9326
- } else if (!this._writableState.errorEmitted) {
9327
- this._writableState.errorEmitted = true;
9328
- process.nextTick(emitErrorNT, this, err);
9329
- }
9330
- }
9331
- return this;
9332
- }
9324
+ var destroy_1;
9325
+ var hasRequiredDestroy;
9333
9326
 
9334
- // we set destroyed to true before firing error callbacks in order
9335
- // to make it re-entrance safe in case destroy() is called within callbacks
9327
+ function requireDestroy () {
9328
+ if (hasRequiredDestroy) return destroy_1;
9329
+ hasRequiredDestroy = 1;
9336
9330
 
9337
- if (this._readableState) {
9338
- this._readableState.destroyed = true;
9339
- }
9331
+ // undocumented cb() API, needed for core, not for public API
9332
+ function destroy(err, cb) {
9333
+ const readableDestroyed = this._readableState && this._readableState.destroyed;
9334
+ const writableDestroyed = this._writableState && this._writableState.destroyed;
9335
+ if (readableDestroyed || writableDestroyed) {
9336
+ if (cb) {
9337
+ cb(err);
9338
+ } else if (err) {
9339
+ if (!this._writableState) {
9340
+ process.nextTick(emitErrorNT, this, err);
9341
+ } else if (!this._writableState.errorEmitted) {
9342
+ this._writableState.errorEmitted = true;
9343
+ process.nextTick(emitErrorNT, this, err);
9344
+ }
9345
+ }
9346
+ return this;
9347
+ }
9340
9348
 
9341
- // if this is a duplex stream mark the writable part as destroyed as well
9342
- if (this._writableState) {
9343
- this._writableState.destroyed = true;
9344
- }
9345
- this._destroy(err || null, err => {
9346
- if (!cb && err) {
9347
- if (!this._writableState) {
9348
- process.nextTick(emitErrorAndCloseNT, this, err);
9349
- } else if (!this._writableState.errorEmitted) {
9350
- this._writableState.errorEmitted = true;
9351
- process.nextTick(emitErrorAndCloseNT, this, err);
9352
- } else {
9353
- process.nextTick(emitCloseNT, this);
9354
- }
9355
- } else if (cb) {
9356
- process.nextTick(emitCloseNT, this);
9357
- cb(err);
9358
- } else {
9359
- process.nextTick(emitCloseNT, this);
9360
- }
9361
- });
9362
- return this;
9363
- }
9364
- function emitErrorAndCloseNT(self, err) {
9365
- emitErrorNT(self, err);
9366
- emitCloseNT(self);
9367
- }
9368
- function emitCloseNT(self) {
9369
- if (self._writableState && !self._writableState.emitClose) return;
9370
- if (self._readableState && !self._readableState.emitClose) return;
9371
- self.emit('close');
9372
- }
9373
- function undestroy() {
9374
- if (this._readableState) {
9375
- this._readableState.destroyed = false;
9376
- this._readableState.reading = false;
9377
- this._readableState.ended = false;
9378
- this._readableState.endEmitted = false;
9379
- }
9380
- if (this._writableState) {
9381
- this._writableState.destroyed = false;
9382
- this._writableState.ended = false;
9383
- this._writableState.ending = false;
9384
- this._writableState.finalCalled = false;
9385
- this._writableState.prefinished = false;
9386
- this._writableState.finished = false;
9387
- this._writableState.errorEmitted = false;
9388
- }
9389
- }
9390
- function emitErrorNT(self, err) {
9391
- self.emit('error', err);
9392
- }
9393
- function errorOrDestroy(stream, err) {
9394
- // We have tests that rely on errors being emitted
9395
- // in the same tick, so changing this is semver major.
9396
- // For now when you opt-in to autoDestroy we allow
9397
- // the error to be emitted nextTick. In a future
9398
- // semver major update we should change the default to this.
9349
+ // we set destroyed to true before firing error callbacks in order
9350
+ // to make it re-entrance safe in case destroy() is called within callbacks
9351
+
9352
+ if (this._readableState) {
9353
+ this._readableState.destroyed = true;
9354
+ }
9355
+
9356
+ // if this is a duplex stream mark the writable part as destroyed as well
9357
+ if (this._writableState) {
9358
+ this._writableState.destroyed = true;
9359
+ }
9360
+ this._destroy(err || null, err => {
9361
+ if (!cb && err) {
9362
+ if (!this._writableState) {
9363
+ process.nextTick(emitErrorAndCloseNT, this, err);
9364
+ } else if (!this._writableState.errorEmitted) {
9365
+ this._writableState.errorEmitted = true;
9366
+ process.nextTick(emitErrorAndCloseNT, this, err);
9367
+ } else {
9368
+ process.nextTick(emitCloseNT, this);
9369
+ }
9370
+ } else if (cb) {
9371
+ process.nextTick(emitCloseNT, this);
9372
+ cb(err);
9373
+ } else {
9374
+ process.nextTick(emitCloseNT, this);
9375
+ }
9376
+ });
9377
+ return this;
9378
+ }
9379
+ function emitErrorAndCloseNT(self, err) {
9380
+ emitErrorNT(self, err);
9381
+ emitCloseNT(self);
9382
+ }
9383
+ function emitCloseNT(self) {
9384
+ if (self._writableState && !self._writableState.emitClose) return;
9385
+ if (self._readableState && !self._readableState.emitClose) return;
9386
+ self.emit('close');
9387
+ }
9388
+ function undestroy() {
9389
+ if (this._readableState) {
9390
+ this._readableState.destroyed = false;
9391
+ this._readableState.reading = false;
9392
+ this._readableState.ended = false;
9393
+ this._readableState.endEmitted = false;
9394
+ }
9395
+ if (this._writableState) {
9396
+ this._writableState.destroyed = false;
9397
+ this._writableState.ended = false;
9398
+ this._writableState.ending = false;
9399
+ this._writableState.finalCalled = false;
9400
+ this._writableState.prefinished = false;
9401
+ this._writableState.finished = false;
9402
+ this._writableState.errorEmitted = false;
9403
+ }
9404
+ }
9405
+ function emitErrorNT(self, err) {
9406
+ self.emit('error', err);
9407
+ }
9408
+ function errorOrDestroy(stream, err) {
9409
+ // We have tests that rely on errors being emitted
9410
+ // in the same tick, so changing this is semver major.
9411
+ // For now when you opt-in to autoDestroy we allow
9412
+ // the error to be emitted nextTick. In a future
9413
+ // semver major update we should change the default to this.
9399
9414
 
9400
- const rState = stream._readableState;
9401
- const wState = stream._writableState;
9402
- if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
9415
+ const rState = stream._readableState;
9416
+ const wState = stream._writableState;
9417
+ if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
9418
+ }
9419
+ destroy_1 = {
9420
+ destroy,
9421
+ undestroy,
9422
+ errorOrDestroy
9423
+ };
9424
+ return destroy_1;
9403
9425
  }
9404
- var destroy_1 = {
9405
- destroy,
9406
- undestroy,
9407
- errorOrDestroy
9408
- };
9409
9426
 
9410
9427
  var errorsBrowser = {};
9411
9428
 
@@ -9535,92 +9552,109 @@ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
9535
9552
  createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
9536
9553
  errorsBrowser.codes = codes;
9537
9554
 
9538
- const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
9539
- function highWaterMarkFrom(options, isDuplex, duplexKey) {
9540
- return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
9541
- }
9542
- function getHighWaterMark(state, options, duplexKey, isDuplex) {
9543
- const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
9544
- if (hwm != null) {
9545
- if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
9546
- const name = isDuplex ? duplexKey : 'highWaterMark';
9547
- throw new ERR_INVALID_OPT_VALUE(name, hwm);
9548
- }
9549
- return Math.floor(hwm);
9550
- }
9555
+ var state;
9556
+ var hasRequiredState;
9551
9557
 
9552
- // Default value
9553
- return state.objectMode ? 16 : 16 * 1024;
9558
+ function requireState () {
9559
+ if (hasRequiredState) return state;
9560
+ hasRequiredState = 1;
9561
+
9562
+ const ERR_INVALID_OPT_VALUE = errorsBrowser.codes.ERR_INVALID_OPT_VALUE;
9563
+ function highWaterMarkFrom(options, isDuplex, duplexKey) {
9564
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
9565
+ }
9566
+ function getHighWaterMark(state, options, duplexKey, isDuplex) {
9567
+ const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
9568
+ if (hwm != null) {
9569
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
9570
+ const name = isDuplex ? duplexKey : 'highWaterMark';
9571
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
9572
+ }
9573
+ return Math.floor(hwm);
9574
+ }
9575
+
9576
+ // Default value
9577
+ return state.objectMode ? 16 : 16 * 1024;
9578
+ }
9579
+ state = {
9580
+ getHighWaterMark
9581
+ };
9582
+ return state;
9554
9583
  }
9555
- var state = {
9556
- getHighWaterMark
9557
- };
9558
9584
 
9559
- /**
9560
- * Module exports.
9561
- */
9585
+ var browser$b;
9586
+ var hasRequiredBrowser$a;
9562
9587
 
9563
- var browser$b = deprecate;
9588
+ function requireBrowser$a () {
9589
+ if (hasRequiredBrowser$a) return browser$b;
9590
+ hasRequiredBrowser$a = 1;
9591
+ /**
9592
+ * Module exports.
9593
+ */
9564
9594
 
9565
- /**
9566
- * Mark that a method should not be used.
9567
- * Returns a modified function which warns once by default.
9568
- *
9569
- * If `localStorage.noDeprecation = true` is set, then it is a no-op.
9570
- *
9571
- * If `localStorage.throwDeprecation = true` is set, then deprecated functions
9572
- * will throw an Error when invoked.
9573
- *
9574
- * If `localStorage.traceDeprecation = true` is set, then deprecated functions
9575
- * will invoke `console.trace()` instead of `console.error()`.
9576
- *
9577
- * @param {Function} fn - the function to deprecate
9578
- * @param {String} msg - the string to print to the console when `fn` is invoked
9579
- * @returns {Function} a new "deprecated" version of `fn`
9580
- * @api public
9581
- */
9595
+ browser$b = deprecate;
9582
9596
 
9583
- function deprecate (fn, msg) {
9584
- if (config('noDeprecation')) {
9585
- return fn;
9586
- }
9597
+ /**
9598
+ * Mark that a method should not be used.
9599
+ * Returns a modified function which warns once by default.
9600
+ *
9601
+ * If `localStorage.noDeprecation = true` is set, then it is a no-op.
9602
+ *
9603
+ * If `localStorage.throwDeprecation = true` is set, then deprecated functions
9604
+ * will throw an Error when invoked.
9605
+ *
9606
+ * If `localStorage.traceDeprecation = true` is set, then deprecated functions
9607
+ * will invoke `console.trace()` instead of `console.error()`.
9608
+ *
9609
+ * @param {Function} fn - the function to deprecate
9610
+ * @param {String} msg - the string to print to the console when `fn` is invoked
9611
+ * @returns {Function} a new "deprecated" version of `fn`
9612
+ * @api public
9613
+ */
9587
9614
 
9588
- var warned = false;
9589
- function deprecated() {
9590
- if (!warned) {
9591
- if (config('throwDeprecation')) {
9592
- throw new Error(msg);
9593
- } else if (config('traceDeprecation')) {
9594
- console.trace(msg);
9595
- } else {
9596
- console.warn(msg);
9597
- }
9598
- warned = true;
9599
- }
9600
- return fn.apply(this, arguments);
9601
- }
9615
+ function deprecate (fn, msg) {
9616
+ if (config('noDeprecation')) {
9617
+ return fn;
9618
+ }
9602
9619
 
9603
- return deprecated;
9604
- }
9620
+ var warned = false;
9621
+ function deprecated() {
9622
+ if (!warned) {
9623
+ if (config('throwDeprecation')) {
9624
+ throw new Error(msg);
9625
+ } else if (config('traceDeprecation')) {
9626
+ console.trace(msg);
9627
+ } else {
9628
+ console.warn(msg);
9629
+ }
9630
+ warned = true;
9631
+ }
9632
+ return fn.apply(this, arguments);
9633
+ }
9605
9634
 
9606
- /**
9607
- * Checks `localStorage` for boolean values for the given `name`.
9608
- *
9609
- * @param {String} name
9610
- * @returns {Boolean}
9611
- * @api private
9612
- */
9635
+ return deprecated;
9636
+ }
9613
9637
 
9614
- function config (name) {
9615
- // accessing global.localStorage can trigger a DOMException in sandboxed iframes
9616
- try {
9617
- if (!commonjsGlobal.localStorage) return false;
9618
- } catch (_) {
9619
- return false;
9620
- }
9621
- var val = commonjsGlobal.localStorage[name];
9622
- if (null == val) return false;
9623
- return String(val).toLowerCase() === 'true';
9638
+ /**
9639
+ * Checks `localStorage` for boolean values for the given `name`.
9640
+ *
9641
+ * @param {String} name
9642
+ * @returns {Boolean}
9643
+ * @api private
9644
+ */
9645
+
9646
+ function config (name) {
9647
+ // accessing global.localStorage can trigger a DOMException in sandboxed iframes
9648
+ try {
9649
+ if (!commonjsGlobal.localStorage) return false;
9650
+ } catch (_) {
9651
+ return false;
9652
+ }
9653
+ var val = commonjsGlobal.localStorage[name];
9654
+ if (null == val) return false;
9655
+ return String(val).toLowerCase() === 'true';
9656
+ }
9657
+ return browser$b;
9624
9658
  }
9625
9659
 
9626
9660
  var _stream_writable;
@@ -9651,12 +9685,12 @@ function require_stream_writable () {
9651
9685
 
9652
9686
  /*<replacement>*/
9653
9687
  const internalUtil = {
9654
- deprecate: browser$b
9688
+ deprecate: requireBrowser$a()
9655
9689
  };
9656
9690
  /*</replacement>*/
9657
9691
 
9658
9692
  /*<replacement>*/
9659
- var Stream = streamBrowser;
9693
+ var Stream = requireStreamBrowser();
9660
9694
  /*</replacement>*/
9661
9695
 
9662
9696
  const Buffer = require$$6$1.Buffer;
@@ -9667,8 +9701,8 @@ function require_stream_writable () {
9667
9701
  function _isUint8Array(obj) {
9668
9702
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
9669
9703
  }
9670
- const destroyImpl = destroy_1;
9671
- const _require = state,
9704
+ const destroyImpl = requireDestroy();
9705
+ const _require = requireState(),
9672
9706
  getHighWaterMark = _require.getHighWaterMark;
9673
9707
  const _require$codes = errorsBrowser.codes,
9674
9708
  ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
@@ -10862,7 +10896,7 @@ function require_stream_readable () {
10862
10896
  /*</replacement>*/
10863
10897
 
10864
10898
  /*<replacement>*/
10865
- var Stream = streamBrowser;
10899
+ var Stream = requireStreamBrowser();
10866
10900
  /*</replacement>*/
10867
10901
 
10868
10902
  const Buffer = require$$6$1.Buffer;
@@ -10885,8 +10919,8 @@ function require_stream_readable () {
10885
10919
  /*</replacement>*/
10886
10920
 
10887
10921
  const BufferList = requireBuffer_list();
10888
- const destroyImpl = destroy_1;
10889
- const _require = state,
10922
+ const destroyImpl = requireDestroy();
10923
+ const _require = requireState(),
10890
10924
  getHighWaterMark = _require.getHighWaterMark;
10891
10925
  const _require$codes = errorsBrowser.codes,
10892
10926
  ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
@@ -14339,7 +14373,7 @@ function WriteReq(chunk, encoding, cb) {
14339
14373
 
14340
14374
  function WritableState(options, stream) {
14341
14375
  Object.defineProperty(this, 'buffer', {
14342
- get: deprecate$1(function () {
14376
+ get: deprecate(function () {
14343
14377
  return this.getBuffer();
14344
14378
  }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
14345
14379
  });
@@ -39340,7 +39374,7 @@ const blocksFromEncryptedCarBlock = async (cid, get, keyMaterial) => {
39340
39374
  }
39341
39375
  };
39342
39376
 
39343
- const defaultConfig$1 = {
39377
+ const defaultConfig$2 = {
39344
39378
  headerKeyPrefix: 'fp.'
39345
39379
  };
39346
39380
 
@@ -39348,7 +39382,7 @@ const defaultConfig$1 = {
39348
39382
 
39349
39383
  class Browser extends Base {
39350
39384
  constructor (name, config = {}) {
39351
- super(name, Object.assign({}, defaultConfig$1, config));
39385
+ super(name, Object.assign({}, defaultConfig$2, config));
39352
39386
  }
39353
39387
 
39354
39388
  withDB = async dbWorkFun => {
@@ -39970,13 +40004,13 @@ var browserPonyfill = {
39970
40004
 
39971
40005
  var fetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfillExports);
39972
40006
 
39973
- const defaultConfig = {
40007
+ const defaultConfig$1 = {
39974
40008
  url: 'http://localhost:4000'
39975
40009
  };
39976
40010
 
39977
40011
  class Rest extends Base {
39978
40012
  constructor (name, config = {}) {
39979
- super(name, Object.assign({}, defaultConfig, config));
40013
+ super(name, Object.assign({}, defaultConfig$1, config));
39980
40014
  // console.log('Rest', name, config)
39981
40015
  }
39982
40016
 
@@ -40028,6 +40062,48 @@ class Rest extends Base {
40028
40062
  }
40029
40063
  }
40030
40064
 
40065
+ const defaultConfig = {
40066
+ upload: () => {},
40067
+ url: (cid) => `https://${cid}.ipfs.w3s.link/`
40068
+ };
40069
+
40070
+ class UCAN extends Base {
40071
+ constructor (name, config = {}) {
40072
+ super(name, Object.assign({}, defaultConfig, config));
40073
+ }
40074
+
40075
+ async writeCars (cars) {
40076
+ if (this.config.readonly) return
40077
+ for (const { cid, bytes } of cars) {
40078
+ const upCid = await this.config.upload(bytes);
40079
+ console.log('writeCar UCAN', cid, upCid);
40080
+ // if (!response.ok) throw new Error(`An error occurred: ${response.statusText}`)
40081
+ }
40082
+ }
40083
+
40084
+ async readCar (carCid) {
40085
+ const carURL = this.config.url(carCid);
40086
+ const response = await fetch(carURL);
40087
+ if (!response.ok) throw new Error(`An error occurred: ${response.statusText}`)
40088
+ const got = await response.arrayBuffer();
40089
+ return new Uint8Array(got)
40090
+ }
40091
+
40092
+ async loadHeader (branch = 'main') {
40093
+ return headerMock.get(branch)
40094
+ }
40095
+
40096
+ async writeHeader (branch, header) {
40097
+ if (this.config.readonly) return
40098
+ const pHeader = this.prepareHeader(header);
40099
+ // console.log('writeHeader rt', branch, pHeader)
40100
+
40101
+ headerMock.set(branch, pHeader);
40102
+ }
40103
+ }
40104
+
40105
+ const headerMock = new Map();
40106
+
40031
40107
  const Loader = {
40032
40108
  appropriate: (name, config = {}) => {
40033
40109
  if (config.StorageClass) {
@@ -40038,6 +40114,10 @@ const Loader = {
40038
40114
  return new Rest(name, config)
40039
40115
  }
40040
40116
 
40117
+ if (config.type === 'ucan') {
40118
+ return new UCAN(name, config)
40119
+ }
40120
+
40041
40121
  return new Browser(name, config)
40042
40122
  }
40043
40123
  };