Skip to content

Commit 682f3f6

Browse files
committed
refactor: modularize key api(ipfs-inactive#544)
1 parent 5ca09af commit 682f3f6

File tree

5 files changed

+59
-29
lines changed

5 files changed

+59
-29
lines changed

src/api/key.js

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

src/api/key/gen.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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((args, opts, callback) => {
10+
if (typeof (opts) === 'function') {
11+
callback = opts
12+
opts = {}
13+
}
14+
send({
15+
path: 'key/gen',
16+
args: args,
17+
qs: opts
18+
}, callback)
19+
})
20+
}

src/api/key/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+
gen: require('./gen')(arg),
6+
list: require('./list')(arg)
7+
}
8+
}

src/api/key/list.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: 'key/list',
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
@@ -144,4 +144,16 @@ describe('submodules', () => {
144144
expect(level).to.be.a('function')
145145
})
146146
})
147+
148+
describe('key', () => {
149+
it('.gen', () => {
150+
const gen = require('../src/api/key/gen')
151+
expect(gen).to.be.a('function')
152+
})
153+
154+
it('.list', () => {
155+
const list = require('../src/api/key/list')
156+
expect(list).to.be.a('function')
157+
})
158+
})
147159
})

0 commit comments

Comments
 (0)