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

feat: REPO spec #207

Merged
merged 6 commits into from
Jan 25, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test.all(common)

## API

In order to be considered "valid", an IPFS core implementation must expose the API described in [/API](/API). You can also use this loose spec as documentation for consuming the core APIs. Here is an outline of the contents of that directory:
In order to be considered "valid", an IPFS core implementation must expose the API described in [/SPEC](/SPEC). You can also use this loose spec as documentation for consuming the core APIs. Here is an outline of the contents of that directory:

- **Files**
- [files](/SPEC/FILES.md)
Expand All @@ -102,6 +102,7 @@ In order to be considered "valid", an IPFS core implementation must expose the
- [Miscellaneous](/SPEC/MISCELLANEOUS.md)
- [config](/SPEC/CONFIG.md)
- [stats](/SPEC/STATS.md)
- [repo](/SPEC/REPO.md)

## Contribute

Expand Down
81 changes: 81 additions & 0 deletions SPEC/REPO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Repo API
=======

#### `gc`

> Perform a garbage collection sweep on the repo.

##### `Go` **WIP**

##### `JavaScript` - ipfs.repo.gc([options, callback])

Where:

- `options` is an object that contains following properties
- `quiet` writes a minimal output.
- `stream-errors` stream errors.

`callback` must follow `function (err, res) {}` signature, where `err` is an Error if the operation was not successful.

If no `callback` is passed, a promise is returned.

**Example:**

```JavaScript
ipfs.repo.gc((err, res) => console.log(res))
```

#### `stat`

> Get stats for the currently used repo.

##### `Go` **WIP**

##### `JavaScript` - ipfs.repo.stat([options, callback])

Where:

- `options` is an object that contains following properties
- `human` a Boolean value to output `repoSize` in MiB.

`callback` must follow `function (err, stats) {}` signature, where `err` is an Error if the operation was not successful and `stats` is an object containing the following keys:

- `numObjects`
- `repoSize`
- `repoPath`
- `version`
- `storageMax`

If no `callback` is passed, a promise is returned.

**Example:**

```JavaScript
ipfs.repo.stat((err, stats) => console.log(stats))

// { numObjects: 15,
// repoSize: 64190,
// repoPath: 'C:\\Users\\henri\\AppData\\Local\\Temp\\ipfs_687c6eb3da07d3b16fe3c63ce17560e9',
// version: 'fs-repo@6',
// storageMax: 10000000000 }
```

#### `version`

> Show the repo version.

##### `Go` **WIP**

##### `JavaScript` - ipfs.repo.version([callback])

`callback` must follow `function (err, version) {}` signature, where `err` is an Error if the operation was not successful and `version` is a String containing the version.

If no `callback` is passed, a promise is returned.

**Example:**

```JavaScript
ipfs.repo.version((err, version) => console.log(version))

// "6"
```
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ exports.dag = require('./dag')
exports.pubsub = require('./pubsub')
exports.key = require('./key')
exports.stats = require('./stats')
exports.repo = require('./repo')
86 changes: 86 additions & 0 deletions src/repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */

'use strict'

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

module.exports = (common) => {
describe('.repo', () => {
let ipfs

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})
})

after((done) => {
common.teardown(done)
})

it('.version', (done) => {
ipfs.repo.version((err, version) => {
expect(err).to.not.exist()
expect(version).to.exist()
done()
})
})

it('.version Promise', () => {
return ipfs.repo.version().then((version) => {
expect(version).to.exist()
})
})

it('.stat', (done) => {
ipfs.repo.stat((err, stat) => {
expect(err).to.not.exist()
expect(stat).to.exist()
expect(stat).to.have.property('numObjects')
expect(stat).to.have.property('repoSize')
expect(stat).to.have.property('repoPath')
expect(stat).to.have.property('version')
expect(stat).to.have.property('storageMax')
done()
})
})

it('.stat Promise', () => {
return ipfs.repo.stat().then((stat) => {
expect(stat).to.exist()
expect(stat).to.have.property('numObjects')
expect(stat).to.have.property('repoSize')
expect(stat).to.have.property('repoPath')
expect(stat).to.have.property('version')
expect(stat).to.have.property('storageMax')
})
})

it('.gc', (done) => {
ipfs.repo.gc((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})

it('.gc Promise', () => {
return ipfs.repo.gc().then((res) => {
expect(res).to.exist()
})
})
})
}