mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
@@ -82,7 +82,7 @@ If you're using `orbitd-db` to develop **browser** or **Node.js** applications,
|
||||
Install dependencies:
|
||||
|
||||
```
|
||||
npm install orbit-db ipfs@0.35.0
|
||||
npm install orbit-db ipfs
|
||||
```
|
||||
|
||||
```javascript
|
||||
|
||||
4284
package-lock.json
generated
4284
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -13,7 +13,7 @@
|
||||
},
|
||||
"main": "src/OrbitDB.js",
|
||||
"dependencies": {
|
||||
"cids": "^0.5.7",
|
||||
"cids": "^0.7.1",
|
||||
"ipfs-pubsub-1on1": "~0.0.4",
|
||||
"localstorage-down": "^0.6.7",
|
||||
"logplease": "^1.2.14",
|
||||
@@ -25,7 +25,7 @@
|
||||
"orbit-db-eventstore": "~1.5.0",
|
||||
"orbit-db-feedstore": "~1.5.0",
|
||||
"orbit-db-identity-provider": "~0.1.0",
|
||||
"orbit-db-io": "~0.0.2",
|
||||
"orbit-db-io": "~0.1.0",
|
||||
"orbit-db-keystore": "^0.2.1",
|
||||
"orbit-db-kvstore": "~1.5.0",
|
||||
"orbit-db-pubsub": "~0.5.5",
|
||||
@@ -37,12 +37,12 @@
|
||||
"babel-plugin-transform-runtime": "^6.23.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"datastore-level": "~0.10.0",
|
||||
"datastore-level": "0.10.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"go-ipfs-dep": "0.4.19",
|
||||
"ipfs": "^0.34.4",
|
||||
"ipfs-repo": "^0.26.2",
|
||||
"ipfsd-ctl": "^0.42.0",
|
||||
"ipfs": "~0.36.3",
|
||||
"ipfs-repo": "~0.26.6",
|
||||
"ipfsd-ctl": "~0.42.3",
|
||||
"localstorage-level-migration": "^0.0.1",
|
||||
"markdown-toc": "^1.2.0",
|
||||
"mocha": "^5.2.0",
|
||||
|
||||
@@ -2,32 +2,17 @@
|
||||
|
||||
const multihashing = require('multihashing-async')
|
||||
const CID = require('cids')
|
||||
const pify = require('pify')
|
||||
|
||||
const createMultihash = pify(multihashing)
|
||||
|
||||
const transformCborLinksIntoCids = (data) => {
|
||||
if (!data) {
|
||||
return data
|
||||
const cidifyString = (str) => {
|
||||
if (!str) {
|
||||
return str
|
||||
}
|
||||
|
||||
if (data['/']) {
|
||||
return new CID(data['/'])
|
||||
if (Array.isArray(str)) {
|
||||
return str.map(cidifyString)
|
||||
}
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
return data.map(transformCborLinksIntoCids)
|
||||
}
|
||||
|
||||
if (typeof data === 'object') {
|
||||
return Object.keys(data).reduce((obj, key) => {
|
||||
obj[key] = transformCborLinksIntoCids(data[key])
|
||||
|
||||
return obj
|
||||
}, {})
|
||||
}
|
||||
|
||||
return data
|
||||
return new CID(str)
|
||||
}
|
||||
|
||||
/* Memory store using an LRU cache */
|
||||
@@ -38,10 +23,9 @@ class MemStore {
|
||||
|
||||
async put (value) {
|
||||
const buffer = Buffer.from(JSON.stringify(value))
|
||||
const multihash = await createMultihash(buffer, 'sha2-256')
|
||||
const multihash = await multihashing(buffer, 'sha2-256')
|
||||
const cid = new CID(1, 'dag-cbor', multihash)
|
||||
const key = cid.toBaseEncodedString()
|
||||
|
||||
const key = cid.toBaseEncodedString('base58btc')
|
||||
this._store.set(key, value)
|
||||
|
||||
return cid
|
||||
@@ -49,13 +33,17 @@ class MemStore {
|
||||
|
||||
async get (cid) {
|
||||
if (CID.isCID(cid)) {
|
||||
cid = cid.toBaseEncodedString()
|
||||
cid = cid.toBaseEncodedString('base58btc')
|
||||
}
|
||||
|
||||
const data = this._store.get(cid)
|
||||
const links = ['next', 'heads']
|
||||
links.forEach((prop) => {
|
||||
if(data[prop])
|
||||
data[prop] = cidifyString(data[prop])
|
||||
})
|
||||
|
||||
return {
|
||||
value: transformCborLinksIntoCids(data)
|
||||
value: data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user