@fireproof/core 0.7.0-alpha.1 → 0.7.0-alpha.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,7 +39,7 @@ export class Base {
39
39
  // currently we don't do that, because we only use
40
40
  // the config for first run, and then we use the headers
41
41
  // once they exist
42
- this.ready = this.getHeaders().then((blocksReady) => {
42
+ this.ready = this.getHeaders().then(blocksReady => {
43
43
  // console.log('blocksReady base', this.name, blocksReady)
44
44
  return blocksReady;
45
45
  });
@@ -243,8 +243,10 @@ export class Base {
243
243
  };
244
244
  const { blocks } = await blocksFromEncryptedCarBlock(roots[0], readerGetWithCodec, this.keyMaterial);
245
245
  const rootBlock = blocks[blocks.length - 1];
246
- const blocksIterable = function* () { for (const block of blocks)
247
- yield block; };
246
+ const blocksIterable = function* () {
247
+ for (const block of blocks)
248
+ yield block;
249
+ };
248
250
  const gat = async (dataCID) => {
249
251
  dataCID = dataCID.toString();
250
252
  return blocks.find(b => b.cid.toString() === dataCID);
@@ -1,8 +1,11 @@
1
- import { readFileSync } from 'node:fs';
2
- import { mkdir, writeFile } from 'node:fs/promises';
1
+ // import { mkdir, writeFile } from 'fs/promises'
3
2
  import { join, dirname } from 'path';
4
3
  import { homedir } from 'os';
5
4
  import { Base } from './base.js';
5
+ // import { readFileSync } from 'node:fs'
6
+ // const { readFileSync } = require('fs')
7
+ import fs from 'fs';
8
+ const readFileSync = fs.readFileSync;
6
9
  export const defaultConfig = {
7
10
  dataDir: join(homedir(), '.fireproof')
8
11
  };
@@ -59,7 +62,7 @@ function loadSync(filename) {
59
62
  }
60
63
  }
61
64
  async function writeSync(fullpath, stringValue) {
62
- await mkdir(dirname(fullpath), { recursive: true });
65
+ await fs.promises.mkdir(dirname(fullpath), { recursive: true });
63
66
  // writeFileSync(fullpath, stringValue)
64
- await writeFile(fullpath, stringValue);
67
+ await fs.promises.writeFile(fullpath, stringValue);
65
68
  }
@@ -1,4 +1,4 @@
1
- import fetch from 'node-fetch';
1
+ import fetch from 'cross-fetch';
2
2
  import { Base } from './base.js';
3
3
  const defaultConfig = {
4
4
  url: 'http://localhost:4000'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core",
3
- "version": "0.7.0-alpha.1",
3
+ "version": "0.7.0-alpha.10",
4
4
  "description": "Live data for React, accelerated by proofs, powered by IPFS",
5
5
  "main": "dist/src/fireproof.js",
6
6
  "module": "dist/src/fireproof.mjs",
@@ -41,27 +41,21 @@
41
41
  "@ipld/car": "^5.1.0",
42
42
  "@ipld/dag-cbor": "^9.0.0",
43
43
  "@jsonlines/core": "^1.0.2",
44
- "@rollup/plugin-commonjs": "^24.0.1",
45
- "archy": "^1.0.0",
46
44
  "async": "^3.2.4",
47
- "car-transaction": "^1.0.1",
48
45
  "charwise": "^3.0.1",
49
- "cli-color": "^2.0.3",
46
+ "cross-fetch": "^3.1.6",
50
47
  "crypto-browserify": "^3.12.0",
51
- "encrypted-block": "^0.0.3",
48
+ "encrypted-block": "jchris/encrypted-block#update",
52
49
  "idb": "^7.1.1",
53
50
  "ipld-hashmap": "^2.1.18",
54
51
  "multiformats": "^11.0.1",
55
- "node-fetch": "^3.3.1",
56
- "node-polyfill-webpack-plugin": "^2.0.1",
57
52
  "prolly-trees": "1.0.4",
58
53
  "randombytes": "^2.1.0",
59
- "rollup-plugin-commonjs": "^10.1.0",
60
- "sade": "^1.8.1",
61
54
  "simple-peer": "^9.11.1"
62
55
  },
63
56
  "devDependencies": {
64
57
  "@rollup/plugin-alias": "^5.0.0",
58
+ "@rollup/plugin-commonjs": "^24.0.1",
65
59
  "@rollup/plugin-json": "^6.0.0",
66
60
  "@rollup/plugin-node-resolve": "^15.0.2",
67
61
  "c8": "^7.12.0",
@@ -70,11 +64,11 @@
70
64
  "flexsearch": "^0.7.31",
71
65
  "mocha": "^10.2.0",
72
66
  "nanoid": "^4.0.0",
67
+ "node-polyfill-webpack-plugin": "^2.0.1",
73
68
  "rollup": "^3.20.2",
74
69
  "rollup-plugin-auto-external": "^2.0.0",
75
70
  "rollup-plugin-dts": "^5.3.0",
76
71
  "rollup-plugin-esbuild": "^5.0.0",
77
- "rollup-plugin-node-builtins": "^2.1.2",
78
72
  "rollup-plugin-polyfill-node": "^0.12.0",
79
73
  "rollup-plugin-visualizer": "^5.9.0",
80
74
  "standard": "^17.0.0",
@@ -117,7 +111,6 @@
117
111
  "files": [
118
112
  "src",
119
113
  "dist",
120
- "hooks",
121
114
  "README.md"
122
115
  ]
123
116
  }
package/src/fireproof.js CHANGED
@@ -50,7 +50,7 @@ export class Fireproof {
50
50
  clock: {
51
51
  byId: byId ? parseCID(byId) : null,
52
52
  byKey: byKey ? parseCID(byKey) : null,
53
- db: (db && db.length > 0) ? db.map(c => parseCID(c)) : null
53
+ db: db && db.length > 0 ? db.map(c => parseCID(c)) : null
54
54
  },
55
55
  code,
56
56
  name
@@ -73,7 +73,9 @@ export class Fireproof {
73
73
 
74
74
  const withBlocks = new Database(database.name)
75
75
  withBlocks.blocks = database.blocks
76
- withBlocks.clock = definition.clock
76
+ withBlocks.ready.then(() => {
77
+ withBlocks.clock = definition.clock.map(c => parseCID(c))
78
+ })
77
79
 
78
80
  const snappedDb = Fireproof.fromJSON(definition, null, withBlocks)
79
81
  ;[...database.indexes.values()].forEach(index => {
package/src/loader.js CHANGED
@@ -1,26 +1,16 @@
1
1
  import { Browser } from './storage/browser.js'
2
- import { Filesystem } from './storage/filesystem.js'
3
2
  import { Rest } from './storage/rest.js'
4
3
 
5
- const FORCE_IDB = typeof process !== 'undefined' && !!process.env?.FORCE_IDB
6
-
7
- /* global window */
8
-
9
4
  export const Loader = {
10
5
  appropriate: (name, config = {}) => {
11
- let isBrowser = false
12
- try {
13
- isBrowser = window.localStorage && true
14
- } catch (e) {}
6
+ if (config.StorageClass) {
7
+ return new config.StorageClass(name, config)
8
+ }
15
9
 
16
10
  if (config.type === 'rest') {
17
11
  return new Rest(name, config)
18
12
  }
19
13
 
20
- if (FORCE_IDB || isBrowser) {
21
- return new Browser(name, config)
22
- } else {
23
- return new Filesystem(name, config)
24
- }
14
+ return new Browser(name, config)
25
15
  }
26
16
  }
@@ -45,7 +45,7 @@ export class Base {
45
45
  // currently we don't do that, because we only use
46
46
  // the config for first run, and then we use the headers
47
47
  // once they exist
48
- this.ready = this.getHeaders().then((blocksReady) => {
48
+ this.ready = this.getHeaders().then(blocksReady => {
49
49
  // console.log('blocksReady base', this.name, blocksReady)
50
50
  return blocksReady
51
51
  })
@@ -258,7 +258,9 @@ export class Base {
258
258
  }
259
259
  const { blocks } = await blocksFromEncryptedCarBlock(roots[0], readerGetWithCodec, this.keyMaterial)
260
260
  const rootBlock = blocks[blocks.length - 1]
261
- const blocksIterable = function * () { for (const block of blocks) yield block }
261
+ const blocksIterable = function * () {
262
+ for (const block of blocks) yield block
263
+ }
262
264
 
263
265
  const gat = async dataCID => {
264
266
  dataCID = dataCID.toString()
@@ -295,7 +297,7 @@ export class Base {
295
297
  }
296
298
  }
297
299
 
298
- writeCars (cars) { }
300
+ writeCars (cars) {}
299
301
 
300
302
  async updateCarCidMap (carCid, cids) {
301
303
  // this hydrates the map if it has not been hydrated
@@ -1,8 +1,12 @@
1
- import { readFileSync } from 'node:fs'
2
- import { mkdir, writeFile } from 'node:fs/promises'
1
+
2
+ // import { mkdir, writeFile } from 'fs/promises'
3
3
  import { join, dirname } from 'path'
4
4
  import { homedir } from 'os'
5
5
  import { Base } from './base.js'
6
+ // import { readFileSync } from 'node:fs'
7
+ // const { readFileSync } = require('fs')
8
+ import fs from 'fs'
9
+ const readFileSync = fs.readFileSync
6
10
 
7
11
  export const defaultConfig = {
8
12
  dataDir: join(homedir(), '.fireproof')
@@ -64,7 +68,7 @@ function loadSync (filename) {
64
68
  }
65
69
 
66
70
  async function writeSync (fullpath, stringValue) {
67
- await mkdir(dirname(fullpath), { recursive: true })
71
+ await fs.promises.mkdir(dirname(fullpath), { recursive: true })
68
72
  // writeFileSync(fullpath, stringValue)
69
- await writeFile(fullpath, stringValue)
73
+ await fs.promises.writeFile(fullpath, stringValue)
70
74
  }
@@ -1,4 +1,4 @@
1
- import fetch from 'node-fetch'
1
+ import fetch from 'cross-fetch'
2
2
  import { Base } from './base.js'
3
3
 
4
4
  const defaultConfig = {