Skip to content

Commit

Permalink
feat: remove options object from stat method (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Santos authored and jacobheun committed Nov 27, 2019
1 parent 9a13115 commit 0fb521c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 41 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,10 @@ Sets the API address.

* `value` should be a [Multiaddr](https://github.com/multiformats/js-multiaddr) or a String representing a valid one.

### `Promise<Object> repo.stat ([options])`
### `Promise<Object> repo.stat ()`

Gets the repo status.

`options` is an object which might contain the key `human`, which is a boolean indicating whether or not the `repoSize` should be displayed in MiB or not.

Returned promise resolves to an `Object` with the following keys:

- `numObjects`
Expand Down Expand Up @@ -322,7 +320,7 @@ Returned promise resolves to a `boolean` indicating the existence of the lock.

### Migrations

When there is a new repo migration and the version of repo is increased, don't
When there is a new repo migration and the version of repo is increased, don't
forget to propagate the changes into the test repo (`test/test-repo`).

**For tools that run mainly in the browser environment, be aware that disabling automatic
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"just-safe-set": "^2.1.0",
"lodash.has": "^4.5.2",
"p-queue": "^6.0.0",
"pretty-bytes": "^5.3.0",
"proper-lockfile": "^4.0.0",
"sort-keys": "^3.0.0"
},
Expand Down
20 changes: 5 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const debug = require('debug')
const Big = require('bignumber.js')
const errcode = require('err-code')
const migrator = require('ipfs-repo-migrations')
const prettyBytes = require('pretty-bytes')
const bytes = require('bytes')

const constants = require('./constants')
Expand Down Expand Up @@ -247,12 +246,9 @@ class IpfsRepo {
/**
* Get repo status.
*
* @param {Object} options
* @param {Boolean} options.human
* @return {Object}
* @returns {Object}
*/
async stat (options) {
options = Object.assign({}, { human: false }, options)
async stat () {
const [storageMax, blocks, version, datastore, keys] = await Promise.all([
this._storageMaxStat(),
this._blockStat(),
Expand All @@ -266,16 +262,10 @@ class IpfsRepo {

return {
repoPath: this.path,
storageMax: options.human
? prettyBytes(storageMax.toNumber()).toUpperCase()
: storageMax,
storageMax,
version: version,
numObjects: options.human
? blocks.count.toNumber()
: blocks.count,
repoSize: options.human
? prettyBytes(size.toNumber()).toUpperCase()
: size
numObjects: blocks.count,
repoSize: size
}
}

Expand Down
21 changes: 0 additions & 21 deletions test/stat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const Block = require('ipfs-block')
const CID = require('cids')
const prettyBytes = require('pretty-bytes')

module.exports = (repo) => {
describe('stat', () => {
Expand All @@ -32,25 +31,5 @@ module.exports = (repo) => {
expect(stats.repoSize > '0').to.eql(true)
expect(stats.storageMax > '0').to.eql(true)
})

it('get human stats', async () => {
const { repoSize, storageMax } = await repo.stat()

const humanizedRepoSize = prettyBytes(repoSize.toNumber()).toUpperCase()
const humanizedStorageMax = prettyBytes(storageMax.toNumber()).toUpperCase()

const humanizedStats = await repo.stat({ human: true })

expect(humanizedStats).to.exist()
expect(humanizedStats).to.have.property('numObjects')
expect(humanizedStats).to.have.property('version').and.be.above(0)
expect(humanizedStats).to.have.property('repoPath')
expect(humanizedStats).to.have.property('repoSize').that.equals(humanizedRepoSize)
expect(humanizedStats).to.have.property('storageMax').that.equals(humanizedStorageMax)

expect(humanizedStats.numObjects > '0').to.eql(true)
expect(humanizedStats.repoSize > '0').to.eql(true)
expect(humanizedStats.storageMax > '0').to.eql(true)
})
})
}

0 comments on commit 0fb521c

Please sign in to comment.