@fireproof/core 0.7.2 → 0.7.3-dev.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -39374,7 +39374,7 @@ const blocksFromEncryptedCarBlock = async (cid, get, keyMaterial) => {
39374
39374
  }
39375
39375
  };
39376
39376
 
39377
- const defaultConfig$1 = {
39377
+ const defaultConfig$2 = {
39378
39378
  headerKeyPrefix: 'fp.'
39379
39379
  };
39380
39380
 
@@ -39382,7 +39382,7 @@ const defaultConfig$1 = {
39382
39382
 
39383
39383
  class Browser extends Base {
39384
39384
  constructor (name, config = {}) {
39385
- super(name, Object.assign({}, defaultConfig$1, config));
39385
+ super(name, Object.assign({}, defaultConfig$2, config));
39386
39386
  }
39387
39387
 
39388
39388
  withDB = async dbWorkFun => {
@@ -40004,13 +40004,13 @@ var browserPonyfill = {
40004
40004
 
40005
40005
  var fetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfillExports);
40006
40006
 
40007
- const defaultConfig = {
40007
+ const defaultConfig$1 = {
40008
40008
  url: 'http://localhost:4000'
40009
40009
  };
40010
40010
 
40011
40011
  class Rest extends Base {
40012
40012
  constructor (name, config = {}) {
40013
- super(name, Object.assign({}, defaultConfig, config));
40013
+ super(name, Object.assign({}, defaultConfig$1, config));
40014
40014
  // console.log('Rest', name, config)
40015
40015
  }
40016
40016
 
@@ -40062,6 +40062,49 @@ class Rest extends Base {
40062
40062
  }
40063
40063
  }
40064
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
+ console.log(`write UCAN ${cid}, ${bytes.length} bytes`);
40079
+ const upCid = await this.config.upload(bytes);
40080
+ console.log(`wrote UCAN ${cid}, ${upCid}`);
40081
+ // if (!response.ok) throw new Error(`An error occurred: ${response.statusText}`)
40082
+ }
40083
+ }
40084
+
40085
+ async readCar (carCid) {
40086
+ const carURL = this.config.url(carCid);
40087
+ const response = await fetch(carURL);
40088
+ if (!response.ok) throw new Error(`An error occurred: ${response.statusText}`)
40089
+ const got = await response.arrayBuffer();
40090
+ return new Uint8Array(got)
40091
+ }
40092
+
40093
+ async loadHeader (branch = 'main') {
40094
+ return headerMock.get(branch)
40095
+ }
40096
+
40097
+ async writeHeader (branch, header) {
40098
+ if (this.config.readonly) return
40099
+ const pHeader = this.prepareHeader(header);
40100
+ // console.log('writeHeader rt', branch, pHeader)
40101
+
40102
+ headerMock.set(branch, pHeader);
40103
+ }
40104
+ }
40105
+
40106
+ const headerMock = new Map();
40107
+
40065
40108
  const Loader = {
40066
40109
  appropriate: (name, config = {}) => {
40067
40110
  if (config.StorageClass) {
@@ -40072,6 +40115,10 @@ const Loader = {
40072
40115
  return new Rest(name, config)
40073
40116
  }
40074
40117
 
40118
+ if (config.type === 'ucan') {
40119
+ return new UCAN(name, config)
40120
+ }
40121
+
40075
40122
  return new Browser(name, config)
40076
40123
  }
40077
40124
  };