This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(request-api): mov away from arg flags, use option object ins…
…tead, migrate every call to it
- Loading branch information
Showing
31 changed files
with
712 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
'use strict' | ||
|
||
const argCommand = require('../cmd-helpers').argCommand | ||
|
||
module.exports = (send) => { | ||
return { | ||
wantlist (cb) { | ||
return send('bitswap/wantlist', {}, null, null, cb) | ||
wantlist (callback) { | ||
return send({ | ||
path: 'bitswap/wantlist' | ||
}, callback) | ||
}, | ||
stat (cb) { | ||
return send('bitswap/stat', {}, null, null, cb) | ||
stat (callback) { | ||
return send({ | ||
path: 'bitswap/stat' | ||
}, callback) | ||
}, | ||
unwant: argCommand(send, 'bitswap/unwant') | ||
unwant (args, opts, callback) { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
return send({ | ||
path: 'bitswap/unwant', | ||
args: args, | ||
qs: opts | ||
}, callback) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
'use strict' | ||
|
||
const argCommand = require('../cmd-helpers').argCommand | ||
|
||
module.exports = (send) => { | ||
return { | ||
get: argCommand(send, 'block/get'), | ||
stat: argCommand(send, 'block/stat'), | ||
put (file, cb) { | ||
get (args, opts, callback) { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
return send({ | ||
path: 'block/get', | ||
args: args, | ||
qs: opts | ||
}, callback) | ||
}, | ||
stat (args, opts, callback) { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
return send({ | ||
path: 'block/stat', | ||
args: args, | ||
qs: opts | ||
}, callback) | ||
}, | ||
put (file, callback) { | ||
if (Array.isArray(file)) { | ||
let err = new Error('block.put() only accepts 1 file') | ||
if (typeof cb !== 'function' && typeof Promise !== 'undefined') { | ||
const err = new Error('block.put() only accepts 1 file') | ||
if (typeof callback !== 'function' && | ||
typeof Promise !== 'undefined') { | ||
return new Promise((resolve, reject) => reject(err)) | ||
} | ||
return cb(err) | ||
return callback(err) | ||
} | ||
return send('block/put', null, null, file, cb) | ||
|
||
return send({ | ||
path: 'block/put', | ||
files: file | ||
}, callback) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
'use strict' | ||
|
||
const command = require('../cmd-helpers').command | ||
|
||
module.exports = (send) => { | ||
return { | ||
add: (arg, opts, cb) => { | ||
if (typeof opts === 'function' && cb === undefined) { | ||
cb = opts | ||
add (args, opts, callback) { | ||
if (typeof opts === 'function' && | ||
callback === undefined) { | ||
callback = opts | ||
opts = {} | ||
} | ||
return send('bootstrap/add', arg, opts, null, cb) | ||
return send({ | ||
path: 'bootstrap/add', | ||
args: args, | ||
qs: opts | ||
}, callback) | ||
}, | ||
rm: (arg, opts, cb) => { | ||
if (typeof opts === 'function' && cb === undefined) { | ||
cb = opts | ||
rm (args, opts, callback) { | ||
if (typeof opts === 'function' && | ||
callback === undefined) { | ||
callback = opts | ||
opts = {} | ||
} | ||
return send('bootstrap/rm', arg, opts, null, cb) | ||
return send({ | ||
path: 'bootstrap/rm', | ||
args: args, | ||
qs: opts | ||
}, callback) | ||
}, | ||
list: command(send, 'bootstrap/list') | ||
list (opts, callback) { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
return send({ | ||
path: 'bootstrap/list', | ||
qs: opts | ||
}, callback) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
'use strict' | ||
|
||
const command = require('../cmd-helpers').command | ||
|
||
module.exports = (send) => { | ||
return command(send, 'commands') | ||
return (callback) => { | ||
return send({ | ||
path: 'commands' | ||
}, callback) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.