From 803a3efcfe3f6e46c979abdae2849529637789d9 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 18:22:33 +0000 Subject: [PATCH] feat: REPO spec (#207) --- README.md | 3 +- SPEC/REPO.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 1 + src/repo.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 SPEC/REPO.md create mode 100644 src/repo.js diff --git a/README.md b/README.md index e943f182..3ad84c99 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/SPEC/REPO.md b/SPEC/REPO.md new file mode 100644 index 00000000..a90cf0b1 --- /dev/null +++ b/SPEC/REPO.md @@ -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" +``` diff --git a/src/index.js b/src/index.js index fe35236a..808aca3c 100644 --- a/src/index.js +++ b/src/index.js @@ -13,3 +13,4 @@ exports.dag = require('./dag') exports.pubsub = require('./pubsub') exports.key = require('./key') exports.stats = require('./stats') +exports.repo = require('./repo') diff --git a/src/repo.js b/src/repo.js new file mode 100644 index 00000000..e4973212 --- /dev/null +++ b/src/repo.js @@ -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() + }) + }) + }) +}