1 | 'use strict'
|
2 |
|
3 | const logger = require('../logger')
|
4 | const Client = require('./client')
|
5 |
|
6 | module.exports = {
|
7 | Client: Client,
|
8 | createClient: function createClient (options) {
|
9 | if (isObject(options) === false) throw TypeError('options (object) required')
|
10 | if (options.url && typeof options.url !== 'string' && !Array.isArray(options.url)) throw TypeError('options.url (string|array) required')
|
11 | if (options.socketPath && typeof options.socketPath !== 'string') throw TypeError('options.socketPath must be a string')
|
12 | if ((options.url && options.socketPath) || !(options.url || options.socketPath)) throw TypeError('options.url ^ options.socketPath (String) required')
|
13 | if (!options.log) options.log = logger
|
14 | if (isObject(options.log) !== true) throw TypeError('options.log must be an object')
|
15 | if (!options.log.child) options.log.child = function () { return options.log }
|
16 |
|
17 | return new Client(options)
|
18 | }
|
19 | }
|
20 |
|
21 | function isObject (input) {
|
22 | return Object.prototype.toString.apply(input) === '[object Object]'
|
23 | }
|