2019-09-29 12:34:59 +00:00
|
|
|
'use strict'
|
2012-04-27 03:23:43 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const logger = require('../logger')
|
|
|
|
const Client = require('./client')
|
2012-04-27 03:23:43 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2015-10-28 02:52:43 +00:00
|
|
|
Client: Client,
|
2019-08-27 21:11:49 +00:00
|
|
|
createClient: function createClient (options) {
|
2019-09-29 12:34:59 +00:00
|
|
|
if (isObject(options) === false) throw TypeError('options (object) required')
|
|
|
|
if (options.url && typeof options.url !== 'string') throw TypeError('options.url (string) required')
|
|
|
|
if (options.socketPath && typeof options.socketPath !== 'string') throw TypeError('options.socketPath must be a string')
|
|
|
|
if ((options.url && options.socketPath) || !(options.url || options.socketPath)) throw TypeError('options.url ^ options.socketPath (String) required')
|
|
|
|
if (!options.log) options.log = logger
|
|
|
|
if (isObject(options.log) !== true) throw TypeError('options.log must be an object')
|
|
|
|
if (!options.log.child) options.log.child = function () { return options.log }
|
2019-08-27 21:11:49 +00:00
|
|
|
|
|
|
|
return new Client(options)
|
2012-04-27 03:23:43 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
}
|
2019-09-29 12:34:59 +00:00
|
|
|
|
|
|
|
function isObject (input) {
|
|
|
|
return Object.prototype.toString.apply(input) === '[object Object]'
|
|
|
|
}
|