@fireproof/core 0.7.2 → 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.
@@ -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,48 @@ 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
+ 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
+
40065
40107
  const Loader = {
40066
40108
  appropriate: (name, config = {}) => {
40067
40109
  if (config.StorageClass) {
@@ -40072,6 +40114,10 @@ const Loader = {
40072
40114
  return new Rest(name, config)
40073
40115
  }
40074
40116
 
40117
+ if (config.type === 'ucan') {
40118
+ return new UCAN(name, config)
40119
+ }
40120
+
40075
40121
  return new Browser(name, config)
40076
40122
  }
40077
40123
  };