@fireproof/core 0.7.2 → 0.7.3-dev.1

Sign up to get free protection for your applications and to get access to all the features.
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
  };
@@ -39376,7 +39376,7 @@ const blocksFromEncryptedCarBlock = async (cid, get, keyMaterial) => {
39376
39376
  }
39377
39377
  };
39378
39378
 
39379
- const defaultConfig$1 = {
39379
+ const defaultConfig$2 = {
39380
39380
  headerKeyPrefix: 'fp.'
39381
39381
  };
39382
39382
 
@@ -39384,7 +39384,7 @@ const defaultConfig$1 = {
39384
39384
 
39385
39385
  class Browser extends Base {
39386
39386
  constructor (name, config = {}) {
39387
- super(name, Object.assign({}, defaultConfig$1, config));
39387
+ super(name, Object.assign({}, defaultConfig$2, config));
39388
39388
  }
39389
39389
 
39390
39390
  withDB = async dbWorkFun => {
@@ -40006,13 +40006,13 @@ var browserPonyfill = {
40006
40006
 
40007
40007
  var fetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfillExports);
40008
40008
 
40009
- const defaultConfig = {
40009
+ const defaultConfig$1 = {
40010
40010
  url: 'http://localhost:4000'
40011
40011
  };
40012
40012
 
40013
40013
  class Rest extends Base {
40014
40014
  constructor (name, config = {}) {
40015
- super(name, Object.assign({}, defaultConfig, config));
40015
+ super(name, Object.assign({}, defaultConfig$1, config));
40016
40016
  // console.log('Rest', name, config)
40017
40017
  }
40018
40018
 
@@ -40064,6 +40064,48 @@ class Rest extends Base {
40064
40064
  }
40065
40065
  }
40066
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
+
40067
40109
  const Loader = {
40068
40110
  appropriate: (name, config = {}) => {
40069
40111
  if (config.StorageClass) {
@@ -40074,6 +40116,10 @@ const Loader = {
40074
40116
  return new Rest(name, config)
40075
40117
  }
40076
40118
 
40119
+ if (config.type === 'ucan') {
40120
+ return new UCAN(name, config)
40121
+ }
40122
+
40077
40123
  return new Browser(name, config)
40078
40124
  }
40079
40125
  };