diff --git a/package.json b/package.json index 499e3f32e..713266513 100644 --- a/package.json +++ b/package.json @@ -17,15 +17,15 @@ "coverage-publish": "aegir-coverage publish" }, "dependencies": { - "async": "^2.0.1", - "babel-runtime": "^6.11.6", + "async": "^2.1.2", + "babel-runtime": "^6.18.0", "bl": "^1.1.2", "bs58": "^3.0.0", "detect-node": "^2.0.3", "flatmap": "0.0.3", - "glob": "^7.0.5", - "ipfs-block": "^0.3.0", - "ipfs-merkle-dag": "^0.7.1", + "glob": "^7.1.1", + "ipfs-block": "^0.4.0", + "ipld-dag-pb": "^0.1.3", "is-ipfs": "^0.2.0", "isstream": "^0.1.2", "multiaddr": "^2.0.2", @@ -34,7 +34,7 @@ "peer-id": "^0.7.0", "peer-info": "^0.7.1", "promisify-es6": "^1.0.1", - "qs": "^6.2.1", + "qs": "^6.3.0", "streamifier": "^0.1.1", "tar-stream": "^1.5.2", "wreck": "^10.0.0" @@ -47,17 +47,17 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^8.0.0", + "aegir": "^8.1.2", "chai": "^3.5.0", "gulp": "^3.9.1", - "hapi": "^15.0.2", - "interface-ipfs-core": "^0.15.0", + "hapi": "^15.2.0", + "interface-ipfs-core": "^0.16.1", "ipfsd-ctl": "^0.16.0", "pre-commit": "^1.1.3", - "socket.io": "^1.4.8", - "socket.io-client": "^1.4.8", + "socket.io": "^1.5.1", + "socket.io-client": "^1.5.1", "stream-equal": "^0.1.8", - "stream-http": "^2.3.1" + "stream-http": "^2.4.0" }, "pre-commit": [ "lint", @@ -103,4 +103,4 @@ "url": "https://github.com/ipfs/js-ipfs-api/issues" }, "homepage": "https://github.com/ipfs/js-ipfs-api" -} \ No newline at end of file +} diff --git a/src/add-to-dagnode-transform.js b/src/add-to-dagnode-transform.js index 32de7f698..5f2e65785 100644 --- a/src/add-to-dagnode-transform.js +++ b/src/add-to-dagnode-transform.js @@ -4,24 +4,29 @@ const map = require('async/map') const getDagNode = require('./get-dagnode') // transform { Hash: '...' } objects into { path: 'string', node: DAGNode } -module.exports = function (err, res, send, done) { +module.exports = (err, res, send, done) => { if (err) { return done(err) } - map(res, function map (entry, next) { - getDagNode(send, entry.Hash, function (err, node) { + map(res, (entry, next) => { + getDagNode(send, entry.Hash, (err, node) => { if (err) { return next(err) } - var obj = { - path: entry.Name, - hash: entry.Hash, - size: node.size() - } - next(null, obj) + node.size((err, size) => { + if (err) { + return next(err) + } + const obj = { + path: entry.Name, + hash: entry.Hash, + size: size + } + next(null, obj) + }) }) - }, function (err, res) { + }, (err, res) => { done(err, res) }) } diff --git a/src/api/block.js b/src/api/block.js index e7458c023..41c880408 100644 --- a/src/api/block.js +++ b/src/api/block.js @@ -3,14 +3,21 @@ const promisify = require('promisify-es6') const bl = require('bl') const Block = require('ipfs-block') +const multihash = require('multihashes') +const CID = require('cids') module.exports = (send) => { return { get: promisify((args, opts, callback) => { + // TODO this needs to be adjusted with the new go-ipfs http-api + if (args && CID.isCID(args)) { + args = multihash.toB58String(args.multihash) + } if (typeof (opts) === 'function') { callback = opts opts = {} } + return send({ path: 'block/get', args: args, @@ -32,6 +39,11 @@ module.exports = (send) => { }) }), stat: promisify((args, opts, callback) => { + // TODO this needs to be adjusted with the new go-ipfs http-api + if (args && CID.isCID(args)) { + args = multihash.toB58String(args.multihash) + } + if (typeof (opts) === 'function') { callback = opts opts = {} @@ -50,7 +62,13 @@ module.exports = (send) => { }) }) }), - put: promisify((block, callback) => { + put: promisify((block, cid, callback) => { + // TODO this needs to be adjusted with the new go-ipfs http-api + if (typeof cid === 'function') { + callback = cid + cid = {} + } + if (Array.isArray(block)) { const err = new Error('block.put() only accepts 1 file') return callback(err) diff --git a/src/api/object.js b/src/api/object.js index 787b36276..4841c8330 100644 --- a/src/api/object.js +++ b/src/api/object.js @@ -1,7 +1,8 @@ 'use strict' -const DAGNode = require('ipfs-merkle-dag').DAGNode -const DAGLink = require('ipfs-merkle-dag').DAGLink +const dagPB = require('ipld-dag-pb') +const DAGNode = dagPB.DAGNode +const DAGLink = dagPB.DAGLink const promisify = require('promisify-es6') const bs58 = require('bs58') const bl = require('bl') @@ -93,21 +94,37 @@ module.exports = (send) => { obj = JSON.parse(obj.toString()) } } + let node + if (obj.multihash) { node = obj } else if (options.enc === 'protobuf') { - node = new DAGNode() - node.unMarshal(obj) + dagPB.util.deserialize(obj, (err, _node) => { + if (err) { + return callback(err) + } + node = _node + next() + }) + return } else { node = new DAGNode(obj.Data, obj.Links) } - - if (node.toJSON().Hash !== result.Hash) { - return callback(new Error('Stored object was different from constructed object')) + next() + + function next () { + node.toJSON((err, nodeJSON) => { + if (err) { + return callback(err) + } + if (nodeJSON.Hash !== result.Hash) { + return callback(new Error('Stored object was different from constructed object')) + } + + callback(null, node) + }) } - - callback(null, node) }) }), data: promisify((multihash, options, callback) => { @@ -200,13 +217,19 @@ module.exports = (send) => { if (err) { return callback(err) } + const node = new DAGNode() + node.toJSON((err, nodeJSON) => { + if (err) { + return callback(err) + } - if (node.toJSON().Hash !== result.Hash) { - return callback(new Error('Stored object was different from constructed object')) - } + if (nodeJSON.Hash !== result.Hash) { + return callback(new Error('Stored object was different from constructed object')) + } - callback(null, node) + callback(null, node) + }) }) }), patch: { diff --git a/src/get-dagnode.js b/src/get-dagnode.js index 2d9e937e2..3c0896ecf 100644 --- a/src/get-dagnode.js +++ b/src/get-dagnode.js @@ -1,6 +1,6 @@ 'use strict' -const DAGNode = require('ipfs-merkle-dag').DAGNode +const DAGNode = require('ipld-dag-pb').DAGNode const bl = require('bl') const parallel = require('async/parallel')