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

Commit c6d930f

Browse files
committed
refactor: move send instance creation to sub-modules index.(#544)
1 parent 934e314 commit c6d930f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+283
-539
lines changed

src/api/bitswap/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
'use strict'
22

3+
const moduleConfig = require('../../module-config')
4+
35
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
48
return {
5-
wantlist: require('./wantlist')(arg),
6-
stat: require('./stat')(arg),
7-
unwant: require('./unwant')(arg)
9+
wantlist: require('./wantlist')(send),
10+
stat: require('./stat')(send),
11+
unwant: require('./unwant')(send)
812
}
913
}

src/api/bitswap/stat.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((callback) => {
107
send({
118
path: 'bitswap/stat'

src/api/bitswap/unwant.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((args, opts, callback) => {
107
if (typeof (opts) === 'function') {
118
callback = opts

src/api/bitswap/wantlist.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((callback) => {
107
send({
118
path: 'bitswap/wantlist'

src/api/block/get.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ const promisify = require('promisify-es6')
44
const Block = require('ipfs-block')
55
const CID = require('cids')
66
const streamToValue = require('../../stream-to-value')
7-
const moduleConfig = require('../../module-config')
8-
9-
module.exports = (arg) => {
10-
const send = moduleConfig(arg)
117

8+
module.exports = (send) => {
129
return promisify((args, opts, callback) => {
1310
if (typeof opts === 'function') {
1411
callback = opts

src/api/block/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
'use strict'
22

3+
const moduleConfig = require('../../module-config')
4+
35
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
48
return {
5-
get: require('./get')(arg),
6-
stat: require('./stat')(arg),
7-
put: require('./put')(arg)
9+
get: require('./get')(send),
10+
stat: require('./stat')(send),
11+
put: require('./put')(send)
812
}
913
}

src/api/block/put.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
const promisify = require('promisify-es6')
44
const Block = require('ipfs-block')
55
const CID = require('cids')
6-
const moduleConfig = require('../../module-config')
7-
8-
module.exports = (arg) => {
9-
const send = moduleConfig(arg)
106

7+
module.exports = (send) => {
118
return promisify((block, cid, callback) => {
129
// TODO this needs to be adjusted with the new go-ipfs http-api
1310
if (typeof cid === 'function') {

src/api/block/stat.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
const promisify = require('promisify-es6')
44
const CID = require('cids')
55
const multihash = require('multihashes')
6-
const moduleConfig = require('../../module-config')
7-
8-
module.exports = (arg) => {
9-
const send = moduleConfig(arg)
106

7+
module.exports = (send) => {
118
return promisify((args, opts, callback) => {
129
// TODO this needs to be adjusted with the new go-ipfs http-api
1310
if (args && CID.isCID(args)) {

src/api/bootstrap/add.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((args, opts, callback) => {
107
if (typeof opts === 'function' &&
118
!callback) {

src/api/bootstrap/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
'use strict'
22

3+
const moduleConfig = require('../../module-config')
4+
35
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
48
return {
5-
add: require('./add')(arg),
6-
rm: require('./rm')(arg),
7-
list: require('./list')(arg)
9+
add: require('./add')(send),
10+
rm: require('./rm')(send),
11+
list: require('./list')(send)
812
}
913
}

src/api/bootstrap/list.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((opts, callback) => {
107
if (typeof (opts) === 'function') {
118
callback = opts

src/api/bootstrap/rm.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((args, opts, callback) => {
107
if (typeof opts === 'function' &&
118
!callback) {

src/api/config/get.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((key, callback) => {
107
if (typeof key === 'function') {
118
callback = key

src/api/config/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
'use strict'
22

3+
const moduleConfig = require('../../module-config')
4+
35
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
48
return {
5-
get: require('./get')(arg),
6-
set: require('./set')(arg),
7-
replace: require('./replace')(arg)
9+
get: require('./get')(send),
10+
set: require('./set')(send),
11+
replace: require('./replace')(send)
812
}
913
}

src/api/config/replace.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
const streamifier = require('streamifier')
44
const promisify = require('promisify-es6')
5-
const moduleConfig = require('../../module-config')
6-
7-
module.exports = (arg) => {
8-
const send = moduleConfig(arg)
95

6+
module.exports = (send) => {
107
return promisify((config, callback) => {
118
if (typeof config === 'object') {
129
config = streamifier.createReadStream(new Buffer(JSON.stringify(config)))

src/api/config/set.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((key, value, opts, callback) => {
107
if (typeof opts === 'function') {
118
callback = opts

src/api/dht/findpeer.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
const promisify = require('promisify-es6')
44
const streamToValue = require('../../stream-to-value')
5-
const moduleConfig = require('../../module-config')
6-
7-
module.exports = (arg) => {
8-
const send = moduleConfig(arg)
95

6+
module.exports = (send) => {
107
return promisify((peerId, opts, callback) => {
118
if (typeof opts === 'function' && !callback) {
129
callback = opts

src/api/dht/findprovs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
const promisify = require('promisify-es6')
44
const streamToValue = require('../../stream-to-value')
5-
const moduleConfig = require('../../module-config')
6-
7-
module.exports = (arg) => {
8-
const send = moduleConfig(arg)
95

6+
module.exports = (send) => {
107
return promisify((cid, opts, callback) => {
118
if (typeof opts === 'function' && !callback) {
129
callback = opts

src/api/dht/get.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((key, opts, callback) => {
107
if (typeof opts === 'function' && !callback) {
118
callback = opts

src/api/dht/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
'use strict'
22

3+
const moduleConfig = require('../../module-config')
4+
35
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
48
return {
5-
get: require('./get')(arg),
6-
put: require('./put')(arg),
7-
findprovs: require('./findprovs')(arg),
8-
findpeer: require('./findpeer')(arg),
9-
provide: require('./provide')(arg),
9+
get: require('./get')(send),
10+
put: require('./put')(send),
11+
findprovs: require('./findprovs')(send),
12+
findpeer: require('./findpeer')(send),
13+
provide: require('./provide')(send),
1014
// find closest peerId to given peerId
11-
query: require('./query')(arg)
15+
query: require('./query')(send)
1216
}
1317
}

src/api/dht/provide.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((cids, opts, callback) => {
107
if (typeof opts === 'function' && !callback) {
118
callback = opts

src/api/dht/put.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((key, value, opts, callback) => {
107
if (typeof opts === 'function' && !callback) {
118
callback = opts

src/api/dht/query.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
const promisify = require('promisify-es6')
44
const streamToValue = require('../../stream-to-value')
5-
const moduleConfig = require('../../module-config')
6-
7-
module.exports = (arg) => {
8-
const send = moduleConfig(arg)
95

6+
module.exports = (send) => {
107
return promisify((peerId, opts, callback) => {
118
if (typeof opts === 'function' && !callback) {
129
callback = opts

src/api/diag/cmds.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((opts, callback) => {
107
if (typeof (opts) === 'function') {
118
callback = opts

src/api/diag/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
'use strict'
22

3+
const moduleConfig = require('../../module-config')
4+
35
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
48
return {
5-
net: require('./net')(arg),
6-
sys: require('./sys')(arg),
7-
cmds: require('./cmds')(arg)
9+
net: require('./net')(send),
10+
sys: require('./sys')(send),
11+
cmds: require('./cmds')(send)
812
}
913
}

src/api/diag/net.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((opts, callback) => {
107
if (typeof (opts) === 'function') {
118
callback = opts

src/api/diag/sys.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((opts, callback) => {
107
if (typeof (opts) === 'function') {
118
callback = opts

src/api/key/gen.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const moduleConfig = require('../../module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
84

5+
module.exports = (send) => {
96
return promisify((args, opts, callback) => {
107
if (typeof (opts) === 'function') {
118
callback = opts

0 commit comments

Comments
 (0)