Skip to content

Commit 163e175

Browse files
committed
refactor: modularize repo api(ipfs-inactive#544)
1 parent d06a951 commit 163e175

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

src/api/repo.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/api/repo/gc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
const moduleConfig = require('../../module-config')
5+
6+
module.exports = (arg) => {
7+
const send = moduleConfig(arg)
8+
9+
return promisify((opts, callback) => {
10+
if (typeof (opts) === 'function') {
11+
callback = opts
12+
opts = {}
13+
}
14+
send({
15+
path: 'repo/gc',
16+
qs: opts
17+
}, callback)
18+
})
19+
}

src/api/repo/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict'
2+
3+
module.exports = (arg) => {
4+
return {
5+
gc: require('./gc')(arg),
6+
stat: require('./stat')(arg)
7+
}
8+
}

src/api/repo/stat.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
const moduleConfig = require('../../module-config')
5+
6+
module.exports = (arg) => {
7+
const send = moduleConfig(arg)
8+
9+
return promisify((opts, callback) => {
10+
if (typeof (opts) === 'function') {
11+
callback = opts
12+
opts = {}
13+
}
14+
send({
15+
path: 'repo/stat',
16+
qs: opts
17+
}, callback)
18+
})
19+
}

test/sub-modules.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ describe('submodules', () => {
185185
expect(ls).to.be.a('function')
186186
})
187187
})
188+
189+
describe('repo', () => {
190+
it('.gc', () => {
191+
const gc = require('../src/api/repo/gc')
192+
expect(gc).to.be.a('function')
193+
})
194+
195+
it('.stat', () => {
196+
const stat = require('../src/api/repo/stat')
197+
expect(stat).to.be.a('function')
198+
})
199+
})
188200
})

0 commit comments

Comments
 (0)