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

Update for new block interface #538

Merged
merged 4 commits into from
Mar 22, 2017
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
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"flatmap": "0.0.3",
"glob": "^7.1.1",
"glob-escape": "0.0.2",
"ipfs-block": "~0.5.5",
"ipfs-block": "~0.6.0",
"ipfs-unixfs": "~0.1.11",
"ipld-dag-pb": "~0.10.1",
"ipld-dag-pb": "~0.11.0",
"is-ipfs": "~0.3.0",
"isstream": "^0.1.2",
"lru-cache": "^4.0.2",
Expand Down Expand Up @@ -60,12 +60,13 @@
"url": "https://github.com/ipfs/js-ipfs-api"
},
"devDependencies": {
"aegir": "^10.0.0",
"aegir": "^11.0.1",
"chai": "^3.5.0",
"eslint-plugin-react": "^6.10.2",
"dirty-chai": "^1.2.2",
"eslint-plugin-react": "^6.10.3",
"gulp": "^3.9.1",
"hapi": "^16.1.0",
"interface-ipfs-core": "~0.25.1",
"interface-ipfs-core": "~0.26.0",
"ipfsd-ctl": "~0.20.0",
"pre-commit": "^1.2.2",
"socket.io": "^1.7.3",
Expand Down
33 changes: 23 additions & 10 deletions src/api/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,39 @@ const streamToValue = require('../stream-to-value')
module.exports = (send) => {
return {
get: promisify((args, opts, callback) => {
// TODO this needs to be adjusted with the new go-ipfs http-api
if (CID.isCID(args)) {
args = multihash.toB58String(args.multihash)
}
if (Buffer.isBuffer(args)) {
args = multihash.toB58String(args)
}
if (typeof opts === 'function') {
callback = opts
opts = {}
}

// TODO this needs to be adjusted with the new go-ipfs http-api
let cid
try {
if (CID.isCID(args)) {
cid = args
args = multihash.toB58String(args.multihash)
} else if (Buffer.isBuffer(args)) {
cid = new CID(args)
args = multihash.toB58String(args)
} else if (typeof args === 'string') {
cid = new CID(args)
} else {
return callback(new Error('invalid argument'))
}
} catch (err) {
return callback(err)
}

// Transform the response from Buffer or a Stream to a Block
const transform = (res, callback) => {
if (Buffer.isBuffer(res)) {
callback(null, new Block(res))
callback(null, new Block(res, cid))
} else {
streamToValue(res, (err, data) => {
if (err) {
return callback(err)
}
callback(null, new Block(data))
callback(null, new Block(data, cid))
})
}
}
Expand Down Expand Up @@ -92,7 +103,9 @@ module.exports = (send) => {
}

// Transform the response to a Block
const transform = (blockInfo, callback) => callback(null, new Block(block))
const transform = (info, callback) => {
callback(null, new Block(block, new CID(info.Key)))
}

send.andTransform(request, transform, callback)
})
Expand Down
1 change: 0 additions & 1 deletion src/clean-multihash.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ module.exports = function (multihash) {
}
return multihash
}

4 changes: 1 addition & 3 deletions src/get-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function loadPaths (opts, file) {

if (stats.isDirectory() && opts.recursive) {
const globEscapedDir = escape(file) + (file.endsWith('/') ? '' : '/')
const mg = new glob.sync.GlobSync(`${globEscapedDir}**/*`, {
const mg = new glob.sync.GlobSync(`${globEscapedDir}` + '**/*', {
follow: followSymlinks,
dot: opts.hidden,
ignore: (opts.ignore || []).map(function (ignoreGlob) {
Expand Down Expand Up @@ -84,9 +84,7 @@ function loadPaths (opts, file) {
dir: true
}
}

// files inside symlinks and others
return
})
// filter out null files
.filter(Boolean)
Expand Down
1 change: 1 addition & 0 deletions src/request-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function parseError (res, cb) {
if (err) {
return cb(err)
}

if (payload) {
error.code = payload.Code
error.message = payload.Message || payload.toString()
Expand Down
9 changes: 6 additions & 3 deletions test/add.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const path = require('path')

Expand All @@ -18,7 +21,7 @@ describe('.add (extra tests)', () => {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
expect(err).to.not.exist()
ipfs = node
done()
})
Expand All @@ -30,7 +33,7 @@ describe('.add (extra tests)', () => {
const validPath = path.join(process.cwd() + '/package.json')

ipfs.files.add(validPath, (err, res) => {
expect(err).to.exist
expect(err).to.exist()
done()
})
})
Expand Down
13 changes: 8 additions & 5 deletions test/bitswap.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const FactoryClient = require('./ipfs-factory/client')

describe('.bitswap', () => {
Expand All @@ -12,7 +15,7 @@ describe('.bitswap', () => {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
expect(err).to.not.exist()
ipfs = node
done()
})
Expand All @@ -25,7 +28,7 @@ describe('.bitswap', () => {
describe('Callback API', () => {
it('.wantlist', (done) => {
ipfs.bitswap.wantlist((err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(res).to.have.to.be.eql({
Keys: null
})
Expand All @@ -35,7 +38,7 @@ describe('.bitswap', () => {

it('.stat', (done) => {
ipfs.bitswap.stat((err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(res).to.have.property('BlocksReceived')
expect(res).to.have.property('DupBlksReceived')
expect(res).to.have.property('DupDataReceived')
Expand All @@ -50,7 +53,7 @@ describe('.bitswap', () => {
it('.unwant', (done) => {
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
ipfs.bitswap.unwant(key, (err) => {
expect(err).to.not.exist
expect(err).to.not.exist()
done()
})
})
Expand Down
43 changes: 23 additions & 20 deletions test/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const FactoryClient = require('./ipfs-factory/client')

const invalidArg = 'this/Is/So/Invalid/'
Expand All @@ -16,7 +19,7 @@ describe('.bootstrap', () => {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
expect(err).to.not.exist()
ipfs = node
done()
})
Expand All @@ -39,20 +42,20 @@ describe('.bootstrap', () => {

it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
ipfs.bootstrap.add(validIp4, (err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.eql(1)
done()
})
})

it('returns a list of bootstrap peers when called with the default option', (done) => {
ipfs.bootstrap.add({ default: true }, (err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.above(1)
done()
})
Expand All @@ -62,9 +65,9 @@ describe('.bootstrap', () => {
describe('.list', () => {
it('returns a list of peers', (done) => {
ipfs.bootstrap.list((err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
done()
})
})
Expand All @@ -80,29 +83,29 @@ describe('.bootstrap', () => {

it('returns empty list because no peers removed when called without an arg or options', (done) => {
ipfs.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.eql(0)
done()
})
})

it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
ipfs.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.eql(0)
done()
})
})

it('returns list of all peers removed when all option is passed', (done) => {
ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
expect(err).to.not.exist
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
done()
})
})
Expand Down Expand Up @@ -130,7 +133,7 @@ describe('.bootstrap', () => {
.then((res) => {
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.eql(1)
})
})
Expand All @@ -139,7 +142,7 @@ describe('.bootstrap', () => {
return ipfs.bootstrap.add(null, { default: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.above(1)
})
})
Expand All @@ -150,7 +153,7 @@ describe('.bootstrap', () => {
return ipfs.bootstrap.list()
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
})
})
})
Expand All @@ -167,7 +170,7 @@ describe('.bootstrap', () => {
return ipfs.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.eql(0)
})
})
Expand All @@ -176,7 +179,7 @@ describe('.bootstrap', () => {
return ipfs.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
expect(peers.length).to.eql(0)
})
})
Expand All @@ -185,7 +188,7 @@ describe('.bootstrap', () => {
return ipfs.bootstrap.rm(null, { all: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers).to.exist()
})
})
})
Expand Down
14 changes: 9 additions & 5 deletions test/commands.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const FactoryClient = require('./ipfs-factory/client')

describe('.commands', () => {
Expand All @@ -12,7 +16,7 @@ describe('.commands', () => {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist
expect(err).to.not.exist()
ipfs = node
done()
})
Expand All @@ -24,8 +28,8 @@ describe('.commands', () => {

it('lists commands', (done) => {
ipfs.commands((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})
Expand All @@ -34,7 +38,7 @@ describe('.commands', () => {
it('lists commands', () => {
return ipfs.commands()
.then((res) => {
expect(res).to.exist
expect(res).to.exist()
})
})
})
Expand Down
Loading