From dc73324b018bdf988a643f730679e8a474742545 Mon Sep 17 00:00:00 2001 From: Nuno Nogueira Date: Sun, 18 Jun 2017 19:40:42 +0100 Subject: [PATCH] refactor: modularize name api(#544) --- src/api/name.js | 30 ------------------------------ src/api/name/index.js | 8 ++++++++ src/api/name/publish.js | 20 ++++++++++++++++++++ src/api/name/resolve.js | 20 ++++++++++++++++++++ test/sub-modules.spec.js | 12 ++++++++++++ 5 files changed, 60 insertions(+), 30 deletions(-) delete mode 100644 src/api/name.js create mode 100644 src/api/name/index.js create mode 100644 src/api/name/publish.js create mode 100644 src/api/name/resolve.js diff --git a/src/api/name.js b/src/api/name.js deleted file mode 100644 index 77fd39fe0..000000000 --- a/src/api/name.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict' - -const promisify = require('promisify-es6') - -module.exports = (send) => { - return { - publish: promisify((args, opts, callback) => { - if (typeof (opts) === 'function') { - callback = opts - opts = {} - } - send({ - path: 'name/publish', - args: args, - qs: opts - }, callback) - }), - resolve: promisify((args, opts, callback) => { - if (typeof (opts) === 'function') { - callback = opts - opts = {} - } - send({ - path: 'name/resolve', - args: args, - qs: opts - }, callback) - }) - } -} diff --git a/src/api/name/index.js b/src/api/name/index.js new file mode 100644 index 000000000..8ae02e6f4 --- /dev/null +++ b/src/api/name/index.js @@ -0,0 +1,8 @@ +'use strict' + +module.exports = (arg) => { + return { + publish: require('./publish')(arg), + resolve: require('./resolve')(arg) + } +} diff --git a/src/api/name/publish.js b/src/api/name/publish.js new file mode 100644 index 000000000..a52c2479e --- /dev/null +++ b/src/api/name/publish.js @@ -0,0 +1,20 @@ +'use strict' + +const promisify = require('promisify-es6') +const moduleConfig = require('../../module-config') + +module.exports = (arg) => { + const send = moduleConfig(arg) + + return promisify((args, opts, callback) => { + if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + send({ + path: 'name/publish', + args: args, + qs: opts + }, callback) + }) +} diff --git a/src/api/name/resolve.js b/src/api/name/resolve.js new file mode 100644 index 000000000..686850b7e --- /dev/null +++ b/src/api/name/resolve.js @@ -0,0 +1,20 @@ +'use strict' + +const promisify = require('promisify-es6') +const moduleConfig = require('../../module-config') + +module.exports = (arg) => { + const send = moduleConfig(arg) + + return promisify((args, opts, callback) => { + if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + send({ + path: 'name/resolve', + args: args, + qs: opts + }, callback) + }) +} diff --git a/test/sub-modules.spec.js b/test/sub-modules.spec.js index a84a139fc..c989cdc9a 100644 --- a/test/sub-modules.spec.js +++ b/test/sub-modules.spec.js @@ -156,4 +156,16 @@ describe('submodules', () => { expect(list).to.be.a('function') }) }) + + describe('name', () => { + it('.publish', () => { + const publish = require('../src/api/name/publish') + expect(publish).to.be.a('function') + }) + + it('.resolve', () => { + const resolve = require('../src/api/name/resolve') + expect(resolve).to.be.a('function') + }) + }) })