Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: add support for js-ipfs dag api and also some tests #957

Merged
merged 4 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"ipfs-utils": "~0.0.3",
"ipld-dag-cbor": "~0.15.0",
"ipld-dag-pb": "~0.17.3",
"ipld-raw": "^4.0.0",
"is-ipfs": "~0.6.1",
"is-pull-stream": "0.0.0",
"is-stream": "^2.0.0",
Expand Down Expand Up @@ -85,7 +86,7 @@
"cross-env": "^5.2.0",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "~0.4.21",
"interface-ipfs-core": "~0.107.0",
"interface-ipfs-core": "^0.107.1",
"ipfsd-ctl": "~0.43.0",
"nock": "^10.0.2",
"stream-equal": "^1.1.1"
Expand Down
7 changes: 5 additions & 2 deletions src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

const dagPB = require('ipld-dag-pb')
const dagCBOR = require('ipld-dag-cbor')
const raw = require('ipld-raw')
const promisify = require('promisify-es6')
const CID = require('cids')
const waterfall = require('async/waterfall')
const block = require('../block')

const resolvers = {
'dag-cbor': dagCBOR.resolver,
'dag-pb': dagPB.resolver
'dag-pb': dagPB.resolver,
raw: raw.resolver
}

module.exports = (send) => {
Expand Down Expand Up @@ -48,7 +50,7 @@ module.exports = (send) => {
const dagResolver = resolvers[ipfsBlock.cid.codec]

if (!dagResolver) {
const error = new Error('ipfs-http-client is missing DAG resolver for "' + ipfsBlock.cid.codec + '" multicodec')
const error = new Error(`Missing IPLD format "${ipfsBlock.cid.codec}"`)
error.missingMulticodec = ipfsBlock.cid.codec
return cb(error)
}
Expand All @@ -59,6 +61,7 @@ module.exports = (send) => {
} catch (err) {
return cb(err)
}

cb(null, res)
}
], callback)
Expand Down
13 changes: 6 additions & 7 deletions test/dag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,15 @@ describe('.dag', function () {
})
})

it('should callback with error when missing DAG resolver for raw multicodec', (done) => {
ipfs.dag.put(Buffer.from([0, 1, 2, 3]), {
// CIDv1 with multicodec = raw
cid: new CID('bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy')
}, (err, cid) => {
it('should callback with error when missing DAG resolver for multicodec from requested CID', (done) => {
ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr')
}, (err, block) => {
expect(err).to.not.exist()

ipfs.dag.get(cid, (err, result) => {
ipfs.dag.get(block.cid, (err, result) => {
expect(result).to.not.exist()
expect(err.message).to.equal('ipfs-http-client is missing DAG resolver for "raw" multicodec')
expect(err.message).to.equal('Missing IPLD format "git-raw"')
done()
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be moved (and deduped) into interface-ipfs-core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. This comes up a lot - what's the criteria on deciding where to put them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this - I mostly view it as a place where we put core tests that are shared between js-ipfs and js-ipfs-http-client.

Expand Down