From 363455b71f75fc2e402c5a25b71ec00b30b74f10 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 11:01:25 +0000 Subject: [PATCH 1/6] docs: repo spec --- SPEC/REPO.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 SPEC/REPO.md diff --git a/SPEC/REPO.md b/SPEC/REPO.md new file mode 100644 index 000000000..eff9ab956 --- /dev/null +++ b/SPEC/REPO.md @@ -0,0 +1,75 @@ +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.stats((err, stats) => console.log(stats)) +``` + +#### `version` + +> Show the repo version. + +##### `Go` **WIP** + +##### `JavaScript` - ipfs.repo.stat([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" +``` From 3fb610b13d92fba75b70985bd9f636780ba8c6cd Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 11:18:31 +0000 Subject: [PATCH 2/6] Update REPO.md --- SPEC/REPO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SPEC/REPO.md b/SPEC/REPO.md index eff9ab956..b76eeba47 100644 --- a/SPEC/REPO.md +++ b/SPEC/REPO.md @@ -60,7 +60,7 @@ ipfs.repo.stats((err, stats) => console.log(stats)) ##### `Go` **WIP** -##### `JavaScript` - ipfs.repo.stat([callback]) +##### `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. From 569ca8e5ddda98ded83f4015dcb26ec3200131fc Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 11:19:10 +0000 Subject: [PATCH 3/6] Update REPO.md --- SPEC/REPO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SPEC/REPO.md b/SPEC/REPO.md index b76eeba47..0af7beaf2 100644 --- a/SPEC/REPO.md +++ b/SPEC/REPO.md @@ -51,7 +51,7 @@ If no `callback` is passed, a promise is returned. **Example:** ```JavaScript -ipfs.repo.stats((err, stats) => console.log(stats)) +ipfs.repo.stat((err, stats) => console.log(stats)) ``` #### `version` From 822c07c9ee7ec671b5876668e12f50fcded3a430 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 11:36:44 +0000 Subject: [PATCH 4/6] add repo tests --- SPEC/REPO.md | 6 ++++ src/index.js | 1 + src/repo.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/repo.js diff --git a/SPEC/REPO.md b/SPEC/REPO.md index 0af7beaf2..a90cf0b12 100644 --- a/SPEC/REPO.md +++ b/SPEC/REPO.md @@ -52,6 +52,12 @@ If no `callback` is passed, a promise is returned. ```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` diff --git a/src/index.js b/src/index.js index fe35236ac..808aca3ca 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 000000000..e4973212f --- /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() + }) + }) + }) +} From cd5be93fec7d10907d995a6a50e74e6cc068a5f2 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 11:57:02 +0000 Subject: [PATCH 5/6] fix: linting --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 808aca3ca..39cdfbff1 100644 --- a/src/index.js +++ b/src/index.js @@ -12,5 +12,8 @@ exports.dht = require('./dht') exports.dag = require('./dag') exports.pubsub = require('./pubsub') exports.key = require('./key') +<<<<<<< HEAD exports.stats = require('./stats') +======= +>>>>>>> fix: linting exports.repo = require('./repo') From b4dc43fb8c0074e3a7fa829a336c5adf8697cb19 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 18:01:47 +0000 Subject: [PATCH 6/6] docs: add REPO to readme --- README.md | 3 ++- src/index.js | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e943f1821..3ad84c998 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/src/index.js b/src/index.js index 39cdfbff1..808aca3ca 100644 --- a/src/index.js +++ b/src/index.js @@ -12,8 +12,5 @@ exports.dht = require('./dht') exports.dag = require('./dag') exports.pubsub = require('./pubsub') exports.key = require('./key') -<<<<<<< HEAD exports.stats = require('./stats') -======= ->>>>>>> fix: linting exports.repo = require('./repo')