2012-04-27 03:23:43 +00:00
|
|
|
// Copyright 2012 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const logger = require('../logger')
|
|
|
|
const Client = require('./client')
|
2012-04-27 03:23:43 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Functions
|
2012-04-27 03:23:43 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function xor () {
|
|
|
|
var b = false
|
2012-04-27 03:23:43 +00:00
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
if (arguments[i] && !b) {
|
2019-08-27 21:11:49 +00:00
|
|
|
b = true
|
2012-04-27 03:23:43 +00:00
|
|
|
} else if (arguments[i] && b) {
|
2019-08-27 21:11:49 +00:00
|
|
|
return false
|
2012-04-27 03:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
return b
|
2012-04-27 03:23:43 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Exports
|
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) {
|
|
|
|
if (typeof (options) !== 'object') { throw new TypeError('options (object) required') }
|
|
|
|
if (options.url && typeof (options.url) !== 'string') { throw new TypeError('options.url (string) required') }
|
|
|
|
if (options.socketPath && typeof (options.socketPath) !== 'string') { throw new TypeError('options.socketPath must be a string') }
|
|
|
|
if (!xor(options.url, options.socketPath)) { throw new TypeError('options.url ^ options.socketPath (String) required') }
|
|
|
|
if (!options.log) { options.log = logger }
|
|
|
|
if (!options.log.child) { options.log.child = function () { return options.log } }
|
|
|
|
if (typeof (options.log) !== 'object') { throw new TypeError('options.log must be an object') }
|
|
|
|
|
|
|
|
return new Client(options)
|
2012-04-27 03:23:43 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
}
|