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

fix(breaking change): spec repo #678

Merged
merged 3 commits into from
Jan 26, 2018
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"P
- [`ipfs.block.put(block, cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#put)
- [`ipfs.block.stat(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#stat)

- repo
- `ipfs.repo.stat()`
- `ipfs.repo.gc()`
- [repo](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/REPO.md)
- [`ipfs.repo.gc([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/REPO.md#gc)
- [`ipfs.repo.stat([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/REPO.md#stat)
- [`ipfs.repo.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/REPO.md#version)

#### `Graph`

Expand Down
15 changes: 13 additions & 2 deletions src/repo/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
numObjects: res.NumObjects,
repoSize: res.RepoSize,
repoPath: res.RepoPath,
version: res.Version,
storageMax: res.StorageMax
})
}

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({

send.andTransform({
path: 'repo/stat',
qs: opts
}, callback)
}, transform, callback)
})
}
9 changes: 7 additions & 2 deletions src/repo/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, res.Version)
}

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({

send.andTransform({
path: 'repo/version',
qs: opts
}, callback)
}, transform, callback)
})
}
1 change: 0 additions & 1 deletion src/stats/repo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict'

const promisify = require('promisify-es6')
Expand Down
34 changes: 34 additions & 0 deletions test/interface/repo.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const test = require('interface-ipfs-core')
const parallel = require('async/parallel')

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

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create()

const nodes = []
const common = {
setup: function (callback) {
callback(null, {
spawnNode: (cb) => {
df.spawn((err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, IPFSApi(_ipfsd.apiAddr))
})
}
})
},
teardown: function (callback) {
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
}
}

test.repo(common)
10 changes: 4 additions & 6 deletions test/repo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('.repo', function () {
ipfs.repo.stat((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.have.a.property('NumObjects')
expect(res).to.have.a.property('RepoSize')
expect(res).to.have.a.property('numObjects')
expect(res).to.have.a.property('repoSize')
done()
})
})
Expand All @@ -51,7 +51,6 @@ describe('.repo', function () {
ipfs.repo.version((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.have.a.property('Version')
done()
})
})
Expand All @@ -66,16 +65,15 @@ describe('.repo', function () {
return ipfs.repo.stat()
.then((res) => {
expect(res).to.exist()
expect(res).to.have.a.property('NumObjects')
expect(res).to.have.a.property('RepoSize')
expect(res).to.have.a.property('numObjects')
expect(res).to.have.a.property('repoSize')
})
})

it('.repo.version', () => {
return ipfs.repo.version()
.then(res => {
expect(res).to.exist()
expect(res).to.have.a.property('Version')
})
})
})
Expand Down