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