Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
refactor: remove inMemory util
Browse files Browse the repository at this point in the history
This removes the dependency on `ipfs-repo`, `ipfs-block-service` and `interface-datastore` and resolves #151.

BREAKING CHANGE: This module no longer exports an `inMemory` utility to create an IPLD instance that uses a block service that stores data in memory. Please use the [`ipld-in-memory`](https://www.npmjs.com/package/ipld-in-memory) module instead.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw authored and vmx committed Jan 16, 2019
1 parent f7494ec commit 689afcc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 38 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"ipld-bitcoin": "~0.1.8",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.2.2",
"ipld-in-memory": "^2.0.0",
"ipld-zcash": "~0.1.6",
"merkle-patricia-tree": "^2.3.2",
"multihashes": "~0.4.14",
Expand All @@ -52,10 +53,7 @@
"dependencies": {
"async": "^2.6.1",
"cids": "~0.5.5",
"interface-datastore": "~0.6.0",
"ipfs-block": "~0.8.0",
"ipfs-block-service": "~0.15.0",
"ipfs-repo": "~0.26.0",
"ipld-dag-cbor": "~0.13.0",
"ipld-dag-pb": "~0.15.2",
"ipld-raw": "^2.0.1",
Expand Down
33 changes: 0 additions & 33 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ const Block = require('ipfs-block')
const pull = require('pull-stream')
const CID = require('cids')
const doUntil = require('async/doUntil')
const IPFSRepo = require('ipfs-repo')
const BlockService = require('ipfs-block-service')
const joinPath = require('path').join
const osPathSep = require('path').sep
const pullDeferSource = require('pull-defer').source
const pullTraverse = require('pull-traverse')
const map = require('async/map')
const series = require('async/series')
const waterfall = require('async/waterfall')
const MemoryStore = require('interface-datastore').MemoryDatastore
const mergeOptions = require('merge-options')
const ipldDagCbor = require('ipld-dag-cbor')
const ipldDagPb = require('ipld-dag-pb')
Expand Down Expand Up @@ -425,33 +421,4 @@ IPLDResolver.defaultOptions = {
formats: [ipldDagCbor, ipldDagPb, ipldRaw]
}

/**
* Create an IPLD resolver with an in memory blockservice and
* repo.
*
* @param {function(Error, IPLDResolver)} callback
* @returns {void}
*/
IPLDResolver.inMemory = function (callback) {
const repo = new IPFSRepo('in-memory', {
storageBackends: {
root: MemoryStore,
blocks: MemoryStore,
datastore: MemoryStore
},
lock: 'memory'
})
const blockService = new BlockService(repo)

series([
(cb) => repo.init({}, cb),
(cb) => repo.open(cb)
], (err) => {
if (err) {
return callback(err)
}
callback(null, new IPLDResolver({ blockService }))
})
}

module.exports = IPLDResolver
3 changes: 2 additions & 1 deletion test/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const BlockService = require('ipfs-block-service')
const CID = require('cids')
const multihash = require('multihashes')
const pull = require('pull-stream')
const inMemory = require('ipld-in-memory')

const IPLDResolver = require('../src')

Expand All @@ -21,7 +22,7 @@ module.exports = (repo) => {
})

it('creates an in memory repo if no blockService is passed', () => {
IPLDResolver.inMemory((err, r) => {
inMemory(IPLDResolver, (err, r) => {
expect(err).to.not.exist()
expect(r.bs).to.exist()
})
Expand Down
3 changes: 2 additions & 1 deletion test/ipld-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const dagCBOR = require('ipld-dag-cbor')
const each = require('async/each')
const waterfall = require('async/waterfall')
const CID = require('cids')
const inMemory = require('ipld-in-memory')

const IPLDResolver = require('../src')

Expand All @@ -29,7 +30,7 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {

before((done) => {
waterfall([
(cb) => IPLDResolver.inMemory(cb),
(cb) => inMemory(IPLDResolver, cb),
(res, cb) => {
resolver = res
dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'), cb)
Expand Down

0 comments on commit 689afcc

Please sign in to comment.