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

Commit 689afcc

Browse files
Alan Shawvmx
Alan Shaw
authored andcommitted
refactor: remove inMemory util
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 <[email protected]>
1 parent f7494ec commit 689afcc

File tree

4 files changed

+5
-38
lines changed

4 files changed

+5
-38
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"ipld-bitcoin": "~0.1.8",
4242
"ipld-ethereum": "^2.0.1",
4343
"ipld-git": "~0.2.2",
44+
"ipld-in-memory": "^2.0.0",
4445
"ipld-zcash": "~0.1.6",
4546
"merkle-patricia-tree": "^2.3.2",
4647
"multihashes": "~0.4.14",
@@ -52,10 +53,7 @@
5253
"dependencies": {
5354
"async": "^2.6.1",
5455
"cids": "~0.5.5",
55-
"interface-datastore": "~0.6.0",
5656
"ipfs-block": "~0.8.0",
57-
"ipfs-block-service": "~0.15.0",
58-
"ipfs-repo": "~0.26.0",
5957
"ipld-dag-cbor": "~0.13.0",
6058
"ipld-dag-pb": "~0.15.2",
6159
"ipld-raw": "^2.0.1",

src/index.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ const Block = require('ipfs-block')
44
const pull = require('pull-stream')
55
const CID = require('cids')
66
const doUntil = require('async/doUntil')
7-
const IPFSRepo = require('ipfs-repo')
8-
const BlockService = require('ipfs-block-service')
97
const joinPath = require('path').join
108
const osPathSep = require('path').sep
119
const pullDeferSource = require('pull-defer').source
1210
const pullTraverse = require('pull-traverse')
1311
const map = require('async/map')
14-
const series = require('async/series')
1512
const waterfall = require('async/waterfall')
16-
const MemoryStore = require('interface-datastore').MemoryDatastore
1713
const mergeOptions = require('merge-options')
1814
const ipldDagCbor = require('ipld-dag-cbor')
1915
const ipldDagPb = require('ipld-dag-pb')
@@ -425,33 +421,4 @@ IPLDResolver.defaultOptions = {
425421
formats: [ipldDagCbor, ipldDagPb, ipldRaw]
426422
}
427423

428-
/**
429-
* Create an IPLD resolver with an in memory blockservice and
430-
* repo.
431-
*
432-
* @param {function(Error, IPLDResolver)} callback
433-
* @returns {void}
434-
*/
435-
IPLDResolver.inMemory = function (callback) {
436-
const repo = new IPFSRepo('in-memory', {
437-
storageBackends: {
438-
root: MemoryStore,
439-
blocks: MemoryStore,
440-
datastore: MemoryStore
441-
},
442-
lock: 'memory'
443-
})
444-
const blockService = new BlockService(repo)
445-
446-
series([
447-
(cb) => repo.init({}, cb),
448-
(cb) => repo.open(cb)
449-
], (err) => {
450-
if (err) {
451-
return callback(err)
452-
}
453-
callback(null, new IPLDResolver({ blockService }))
454-
})
455-
}
456-
457424
module.exports = IPLDResolver

test/basics.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const BlockService = require('ipfs-block-service')
99
const CID = require('cids')
1010
const multihash = require('multihashes')
1111
const pull = require('pull-stream')
12+
const inMemory = require('ipld-in-memory')
1213

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

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

2324
it('creates an in memory repo if no blockService is passed', () => {
24-
IPLDResolver.inMemory((err, r) => {
25+
inMemory(IPLDResolver, (err, r) => {
2526
expect(err).to.not.exist()
2627
expect(r.bs).to.exist()
2728
})

test/ipld-all.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const dagCBOR = require('ipld-dag-cbor')
1616
const each = require('async/each')
1717
const waterfall = require('async/waterfall')
1818
const CID = require('cids')
19+
const inMemory = require('ipld-in-memory')
1920

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

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

3031
before((done) => {
3132
waterfall([
32-
(cb) => IPLDResolver.inMemory(cb),
33+
(cb) => inMemory(IPLDResolver, cb),
3334
(res, cb) => {
3435
resolver = res
3536
dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'), cb)

0 commit comments

Comments
 (0)