and finally, return to standard mo
This commit is contained in:
@ -28,7 +28,7 @@ module.exports = Client;
|
||||
|
||||
var Transport = require('./transport');
|
||||
var clientAction = require('./client_action');
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
|
||||
function Client(config) {
|
||||
config = config || {};
|
||||
@ -56,7 +56,7 @@ function Client(config) {
|
||||
|
||||
this.transport = new Transport(config);
|
||||
|
||||
_v4.each(EsApiClient.prototype, _v4.bind(function (Fn, prop) {
|
||||
_.each(EsApiClient.prototype, _.bind(function (Fn, prop) {
|
||||
if (Fn.prototype instanceof clientAction.ApiNamespace) {
|
||||
this[prop] = new Fn(this.transport);
|
||||
}
|
||||
@ -66,7 +66,7 @@ function Client(config) {
|
||||
}
|
||||
|
||||
|
||||
EsApiClient.prototype = _v4.funcEnum(config, 'apiVersion', Client.apis, '_default');
|
||||
EsApiClient.prototype = _.funcEnum(config, 'apiVersion', Client.apis, '_default');
|
||||
if (!config.sniffEndpoint && EsApiClient.prototype === Client.apis['0.90']) {
|
||||
config.sniffEndpoint = '/_cluster/nodes';
|
||||
}
|
||||
@ -74,9 +74,9 @@ function Client(config) {
|
||||
var Constructor = EsApiClient;
|
||||
|
||||
if (config.plugins) {
|
||||
Constructor.prototype = _v4.cloneDeep(Constructor.prototype);
|
||||
Constructor.prototype = _.cloneDeep(Constructor.prototype);
|
||||
|
||||
_v4.each(config.plugins, function (setup) {
|
||||
_.each(config.plugins, function (setup) {
|
||||
Constructor = setup(Constructor, config, {
|
||||
apis: require('./apis'),
|
||||
connectors: require('./connectors'),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
|
||||
/**
|
||||
* Constructs a client action factory that uses specific defaults
|
||||
@ -34,12 +34,12 @@ exports.namespaceFactory = function () {
|
||||
};
|
||||
|
||||
function makeFactoryWithModifier(modifier) {
|
||||
modifier = modifier || _v4.identity;
|
||||
modifier = modifier || _.identity;
|
||||
|
||||
var factory = function (spec) {
|
||||
spec = modifier(spec);
|
||||
|
||||
if (!_v4.isPlainObject(spec.params)) {
|
||||
if (!_.isPlainObject(spec.params)) {
|
||||
spec.params = {};
|
||||
}
|
||||
|
||||
@ -57,10 +57,10 @@ function makeFactoryWithModifier(modifier) {
|
||||
}
|
||||
|
||||
try {
|
||||
return exec(this.transport, spec, _v4.clone(params), cb);
|
||||
return exec(this.transport, spec, _.clone(params), cb);
|
||||
} catch (e) {
|
||||
if (typeof cb === 'function') {
|
||||
_v4.nextTick(cb, e);
|
||||
_.nextTick(cb, e);
|
||||
} else {
|
||||
var def = this.transport.defer();
|
||||
def.reject(e);
|
||||
@ -97,11 +97,11 @@ function makeFactoryWithModifier(modifier) {
|
||||
|
||||
var castType = {
|
||||
'enum': function validSelection(param, val, name) {
|
||||
if (_v4.isString(val) && val.indexOf(',') > -1) {
|
||||
if (_.isString(val) && val.indexOf(',') > -1) {
|
||||
val = commaSepList(val);
|
||||
}
|
||||
|
||||
if (_v4.isArray(val)) {
|
||||
if (_.isArray(val)) {
|
||||
return val.map(function (v) {
|
||||
return validSelection(param, v, name);
|
||||
}).join(',');
|
||||
@ -119,7 +119,7 @@ var castType = {
|
||||
));
|
||||
},
|
||||
duration: function (param, val, name) {
|
||||
if (_v4.isNumeric(val) || _v4.isInterval(val)) {
|
||||
if (_.isNumeric(val) || _.isInterval(val)) {
|
||||
return val;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
@ -137,7 +137,7 @@ var castType = {
|
||||
val = commaSepList(val);
|
||||
/* falls through */
|
||||
case 'object':
|
||||
if (_v4.isArray(val)) {
|
||||
if (_.isArray(val)) {
|
||||
return val.join(',');
|
||||
}
|
||||
/* falls through */
|
||||
@ -146,11 +146,11 @@ var castType = {
|
||||
}
|
||||
},
|
||||
'boolean': function (param, val) {
|
||||
val = _v4.isString(val) ? val.toLowerCase() : val;
|
||||
val = _.isString(val) ? val.toLowerCase() : val;
|
||||
return (val === 'no' || val === 'off') ? false : !!val;
|
||||
},
|
||||
number: function (param, val, name) {
|
||||
if (_v4.isNumeric(val)) {
|
||||
if (_.isNumeric(val)) {
|
||||
return val * 1;
|
||||
} else {
|
||||
throw new TypeError('Invalid ' + name + ': expected a number.');
|
||||
@ -169,7 +169,7 @@ var castType = {
|
||||
if (typeof val === 'string') {
|
||||
return val;
|
||||
}
|
||||
else if (_v4.isNumeric(val)) {
|
||||
else if (_.isNumeric(val)) {
|
||||
return '' + val;
|
||||
}
|
||||
else if (val instanceof Date) {
|
||||
@ -188,7 +188,7 @@ function resolveUrl(url, params) {
|
||||
// url has required params
|
||||
if (!url.reqParamKeys) {
|
||||
// create cached key list on demand
|
||||
url.reqParamKeys = _v4.keys(url.req);
|
||||
url.reqParamKeys = _.keys(url.req);
|
||||
}
|
||||
|
||||
for (i = 0; i < url.reqParamKeys.length; i ++) {
|
||||
@ -210,7 +210,7 @@ function resolveUrl(url, params) {
|
||||
if (url.opt) {
|
||||
// url has optional params
|
||||
if (!url.optParamKeys) {
|
||||
url.optParamKeys = _v4.keys(url.opt);
|
||||
url.optParamKeys = _.keys(url.opt);
|
||||
}
|
||||
|
||||
for (i = 0; i < url.optParamKeys.length; i ++) {
|
||||
@ -229,10 +229,10 @@ function resolveUrl(url, params) {
|
||||
|
||||
if (!url.template) {
|
||||
// compile the template on demand
|
||||
url.template = _v4.template(url.fmt);
|
||||
url.template = _.template(url.fmt);
|
||||
}
|
||||
|
||||
return url.template(_v4.transform(vars, function (note, val, name) {
|
||||
return url.template(_.transform(vars, function (note, val, name) {
|
||||
// encode each value
|
||||
note[name] = encodeURIComponent(val);
|
||||
// remove it from the params so that it isn't sent to the final request
|
||||
@ -287,14 +287,14 @@ function exec(transport, spec, params, cb) {
|
||||
if (!request.path) {
|
||||
// there must have been some mimimun requirements that were not met
|
||||
var minUrl = spec.url || spec.urls[spec.urls.length - 1];
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least ' + _v4.keys(minUrl.req).join(', '));
|
||||
throw new TypeError('Unable to build a path with those params. Supply at least ' + _.keys(minUrl.req).join(', '));
|
||||
}
|
||||
|
||||
// build the query string
|
||||
if (!spec.paramKeys) {
|
||||
// build a key list on demand
|
||||
spec.paramKeys = _v4.keys(spec.params);
|
||||
spec.requireParamKeys = _v4.transform(spec.params, function (req, param, key) {
|
||||
spec.paramKeys = _.keys(spec.params);
|
||||
spec.requireParamKeys = _.transform(spec.params, function (req, param, key) {
|
||||
if (param.required) {
|
||||
req.push(key);
|
||||
}
|
||||
@ -311,10 +311,10 @@ function exec(transport, spec, params, cb) {
|
||||
request[key] = params[key];
|
||||
break;
|
||||
case 'ignore':
|
||||
request.ignore = _v4.isArray(params[key]) ? params[key] : [params[key]];
|
||||
request.ignore = _.isArray(params[key]) ? params[key] : [params[key]];
|
||||
break;
|
||||
case 'method':
|
||||
request.method = _v4.toUpperString(params[key]);
|
||||
request.method = _.toUpperString(params[key]);
|
||||
break;
|
||||
default:
|
||||
var paramSpec = spec.params[key];
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
module.exports = ConnectionAbstract;
|
||||
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Log = require('./log');
|
||||
var Host = require('./host');
|
||||
@ -26,9 +26,9 @@ function ConnectionAbstract(host, config) {
|
||||
throw new TypeError('Invalid host');
|
||||
}
|
||||
|
||||
_v4.makeBoundMethods(this);
|
||||
_.makeBoundMethods(this);
|
||||
}
|
||||
_v4.inherits(ConnectionAbstract, EventEmitter);
|
||||
_.inherits(ConnectionAbstract, EventEmitter);
|
||||
|
||||
/**
|
||||
* Make a request using this connection. Must be overridden by Connection classes, which can add whatever keys to
|
||||
@ -61,7 +61,7 @@ ConnectionAbstract.prototype.ping = function (params, cb) {
|
||||
requestTimeout = params.requestTimeout;
|
||||
}
|
||||
|
||||
abort = this.request(_v4.defaults(params || {}, {
|
||||
abort = this.request(_.defaults(params || {}, {
|
||||
path: '/',
|
||||
method: 'HEAD'
|
||||
}), function (err) {
|
||||
|
||||
@ -9,12 +9,12 @@
|
||||
|
||||
module.exports = ConnectionPool;
|
||||
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
var Log = require('./log');
|
||||
|
||||
function ConnectionPool(config) {
|
||||
config = config || {};
|
||||
_v4.makeBoundMethods(this);
|
||||
_.makeBoundMethods(this);
|
||||
|
||||
if (!config.log) {
|
||||
this.log = new Log();
|
||||
@ -27,16 +27,16 @@ function ConnectionPool(config) {
|
||||
this._config = config;
|
||||
|
||||
// get the selector config var
|
||||
this.selector = _v4.funcEnum(config, 'selector', ConnectionPool.selectors, ConnectionPool.defaultSelector);
|
||||
this.selector = _.funcEnum(config, 'selector', ConnectionPool.selectors, ConnectionPool.defaultSelector);
|
||||
|
||||
// get the connection class
|
||||
this.Connection = _v4.funcEnum(config, 'connectionClass', ConnectionPool.connectionClasses,
|
||||
this.Connection = _.funcEnum(config, 'connectionClass', ConnectionPool.connectionClasses,
|
||||
ConnectionPool.defaultConnectionClass);
|
||||
|
||||
// time that connections will wait before being revived
|
||||
this.deadTimeout = config.hasOwnProperty('deadTimeout') ? config.deadTimeout : 60000;
|
||||
this.maxDeadTimeout = config.hasOwnProperty('maxDeadTimeout') ? config.maxDeadTimeout : 18e5;
|
||||
this.calcDeadTimeout = _v4.funcEnum(config, 'calcDeadTimeout', ConnectionPool.calcDeadTimeoutOptions, 'exponential');
|
||||
this.calcDeadTimeout = _.funcEnum(config, 'calcDeadTimeout', ConnectionPool.calcDeadTimeoutOptions, 'exponential');
|
||||
|
||||
// a map of connections to their "id" property, used when sniffing
|
||||
this.index = {};
|
||||
@ -86,7 +86,7 @@ ConnectionPool.prototype.select = function (cb) {
|
||||
this.selector(this._conns.alive, cb);
|
||||
} else {
|
||||
try {
|
||||
_v4.nextTick(cb, void 0, this.selector(this._conns.alive));
|
||||
_.nextTick(cb, void 0, this.selector(this._conns.alive));
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
@ -94,7 +94,7 @@ ConnectionPool.prototype.select = function (cb) {
|
||||
} else if (this._timeouts.length) {
|
||||
this._selectDeadConnection(cb);
|
||||
} else {
|
||||
_v4.nextTick(cb, void 0);
|
||||
_.nextTick(cb, void 0);
|
||||
}
|
||||
};
|
||||
|
||||
@ -106,7 +106,7 @@ ConnectionPool.prototype.select = function (cb) {
|
||||
* @param {String} oldStatus - the connection's old status
|
||||
* @param {ConnectionAbstract} connection - the connection object itself
|
||||
*/
|
||||
ConnectionPool.prototype.onStatusSet = _v4.handler(function (status, oldStatus, connection) {
|
||||
ConnectionPool.prototype.onStatusSet = _.handler(function (status, oldStatus, connection) {
|
||||
var index;
|
||||
|
||||
var died = (status === 'dead');
|
||||
@ -121,14 +121,14 @@ ConnectionPool.prototype.onStatusSet = _v4.handler(function (status, oldStatus,
|
||||
}
|
||||
|
||||
if (from !== to) {
|
||||
if (_v4.isArray(from)) {
|
||||
if (_.isArray(from)) {
|
||||
index = from.indexOf(connection);
|
||||
if (index !== -1) {
|
||||
from.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (_v4.isArray(to)) {
|
||||
if (_.isArray(to)) {
|
||||
index = to.indexOf(connection);
|
||||
if (index === -1) {
|
||||
to.push(connection);
|
||||
@ -200,11 +200,11 @@ ConnectionPool.prototype._onConnectionDied = function (connection, alreadyWasDea
|
||||
|
||||
var ms = this.calcDeadTimeout(timeout.attempt, this.deadTimeout);
|
||||
timeout.id = setTimeout(timeout.revive, ms);
|
||||
timeout.runAt = _v4.now() + ms;
|
||||
timeout.runAt = _.now() + ms;
|
||||
};
|
||||
|
||||
ConnectionPool.prototype._selectDeadConnection = function (cb) {
|
||||
var orderedTimeouts = _v4.sortBy(this._timeouts, 'runAt');
|
||||
var orderedTimeouts = _.sortBy(this._timeouts, 'runAt');
|
||||
var log = this.log;
|
||||
|
||||
process.nextTick(function next() {
|
||||
@ -257,7 +257,7 @@ ConnectionPool.prototype.getConnections = function (status, limit) {
|
||||
if (limit == null) {
|
||||
return list.slice(0);
|
||||
} else {
|
||||
return _v4.shuffle(list).slice(0, limit);
|
||||
return _.shuffle(list).slice(0, limit);
|
||||
}
|
||||
};
|
||||
|
||||
@ -308,7 +308,7 @@ ConnectionPool.prototype.setHosts = function (hosts) {
|
||||
var i;
|
||||
var id;
|
||||
var host;
|
||||
var toRemove = _v4.clone(this.index);
|
||||
var toRemove = _.clone(this.index);
|
||||
|
||||
for (i = 0; i < hosts.length; i++) {
|
||||
host = hosts[i];
|
||||
@ -322,14 +322,14 @@ ConnectionPool.prototype.setHosts = function (hosts) {
|
||||
}
|
||||
}
|
||||
|
||||
var removeIds = _v4.keys(toRemove);
|
||||
var removeIds = _.keys(toRemove);
|
||||
for (i = 0; i < removeIds.length; i++) {
|
||||
this.removeConnection(this.index[removeIds[i]]);
|
||||
}
|
||||
};
|
||||
|
||||
ConnectionPool.prototype.getAllHosts = function () {
|
||||
return _v4.values(this.index).map(function (connection) {
|
||||
return _.values(this.index).map(function (connection) {
|
||||
return connection.host;
|
||||
});
|
||||
};
|
||||
|
||||
4
src/lib/connectors/angular.js
vendored
4
src/lib/connectors/angular.js
vendored
@ -6,7 +6,7 @@
|
||||
*/
|
||||
module.exports = AngularConnector;
|
||||
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var ConnectionAbstract = require('../connection');
|
||||
var ConnectionFault = require('../errors').ConnectionFault;
|
||||
|
||||
@ -20,7 +20,7 @@ function AngularConnector(host, config) {
|
||||
}]);
|
||||
|
||||
}
|
||||
_v4.inherits(AngularConnector, ConnectionAbstract);
|
||||
_.inherits(AngularConnector, ConnectionAbstract);
|
||||
|
||||
AngularConnector.prototype.request = function (params, cb) {
|
||||
var abort = this.$q.defer();
|
||||
|
||||
@ -3,10 +3,10 @@ var opts = {
|
||||
jquery: require('./jquery'),
|
||||
angular: require('./angular')
|
||||
};
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
|
||||
// remove modules that have been ignored by browserify
|
||||
_v4.each(opts, function (conn, name) {
|
||||
_.each(opts, function (conn, name) {
|
||||
if (typeof conn !== 'function') {
|
||||
delete opts[name];
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ var handles = {
|
||||
http: require('http'),
|
||||
https: require('https')
|
||||
};
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var qs = require('querystring');
|
||||
var KeepAliveAgent = require('./_keep_alive_agent');
|
||||
var ConnectionAbstract = require('../connection');
|
||||
@ -31,12 +31,12 @@ function HttpConnector(host, config) {
|
||||
this.hand = handles[this.host.protocol];
|
||||
if (!this.hand) {
|
||||
throw new TypeError('Invalid protocol "' + this.host.protocol +
|
||||
'", expected one of ' + _v4.keys(handles).join(', '));
|
||||
'", expected one of ' + _.keys(handles).join(', '));
|
||||
}
|
||||
|
||||
this.useSsl = this.host.protocol === 'https';
|
||||
|
||||
config = _v4.defaults(config || {}, {
|
||||
config = _.defaults(config || {}, {
|
||||
keepAlive: true,
|
||||
minSockets: 10,
|
||||
// 10 makes sense but 11 actually keeps 10 sockets around
|
||||
@ -46,14 +46,14 @@ function HttpConnector(host, config) {
|
||||
|
||||
this.agent = config.createNodeAgent ? config.createNodeAgent(this, config) : this.createAgent(config);
|
||||
}
|
||||
_v4.inherits(HttpConnector, ConnectionAbstract);
|
||||
_.inherits(HttpConnector, ConnectionAbstract);
|
||||
|
||||
HttpConnector.prototype.onStatusSet = _v4.handler(function (status) {
|
||||
HttpConnector.prototype.onStatusSet = _.handler(function (status) {
|
||||
if (status === 'closed') {
|
||||
var agent = this.agent;
|
||||
var toRemove = [];
|
||||
var collectSockets = function (sockets, host) {
|
||||
_v4.each(sockets, function (s) {
|
||||
_.each(sockets, function (s) {
|
||||
if (s) toRemove.push([host, s]);
|
||||
});
|
||||
};
|
||||
@ -61,9 +61,9 @@ HttpConnector.prototype.onStatusSet = _v4.handler(function (status) {
|
||||
agent.minSockets = agent.maxSockets = 0;
|
||||
agent.requests = {};
|
||||
|
||||
_v4.each(agent.sockets, collectSockets);
|
||||
_v4.each(agent.freeSockets, collectSockets);
|
||||
_v4.each(toRemove, function (args) {
|
||||
_.each(agent.sockets, collectSockets);
|
||||
_.each(agent.freeSockets, collectSockets);
|
||||
_.each(toRemove, function (args) {
|
||||
var host = args[0], socket = args[1];
|
||||
agent.removeSocket(socket, host);
|
||||
socket.destroy();
|
||||
@ -102,7 +102,7 @@ HttpConnector.prototype.makeAgentConfig = function (config) {
|
||||
};
|
||||
|
||||
if (this.useSsl) {
|
||||
_v4.merge(agentConfig, this.host.ssl);
|
||||
_.merge(agentConfig, this.host.ssl);
|
||||
}
|
||||
|
||||
return agentConfig;
|
||||
@ -147,7 +147,7 @@ HttpConnector.prototype.request = function (params, cb) {
|
||||
|
||||
// general clean-up procedure to run after the request
|
||||
// completes, has an error, or is aborted.
|
||||
var cleanUp = _v4.bind(function (err) {
|
||||
var cleanUp = _.bind(function (err) {
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
request && request.removeAllListeners();
|
||||
|
||||
4
src/lib/connectors/jquery.js
vendored
4
src/lib/connectors/jquery.js
vendored
@ -7,14 +7,14 @@
|
||||
*/
|
||||
module.exports = JqueryConnector;
|
||||
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var ConnectionAbstract = require('../connection');
|
||||
var ConnectionFault = require('../errors').ConnectionFault;
|
||||
|
||||
function JqueryConnector(host, config) {
|
||||
ConnectionAbstract.call(this, host, config);
|
||||
}
|
||||
_v4.inherits(JqueryConnector, ConnectionAbstract);
|
||||
_.inherits(JqueryConnector, ConnectionAbstract);
|
||||
|
||||
JqueryConnector.prototype.request = function (params, cb) {
|
||||
var ajax = {
|
||||
|
||||
@ -7,7 +7,7 @@ module.exports = XhrConnector;
|
||||
|
||||
/* jshint browser:true */
|
||||
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var ConnectionAbstract = require('../connection');
|
||||
var ConnectionFault = require('../errors').ConnectionFault;
|
||||
var asyncDefault = !(navigator && /PhantomJS/i.test(navigator.userAgent));
|
||||
@ -15,13 +15,13 @@ var asyncDefault = !(navigator && /PhantomJS/i.test(navigator.userAgent));
|
||||
function XhrConnector(host, config) {
|
||||
ConnectionAbstract.call(this, host, config);
|
||||
}
|
||||
_v4.inherits(XhrConnector, ConnectionAbstract);
|
||||
_.inherits(XhrConnector, ConnectionAbstract);
|
||||
|
||||
/**
|
||||
* Simply returns an XHR object cross browser
|
||||
* @type {Function}
|
||||
*/
|
||||
var getXhr = _v4.noop;
|
||||
var getXhr = _.noop;
|
||||
|
||||
if (typeof XMLHttpRequest !== 'undefined') {
|
||||
// rewrite the getXhr method to always return the native implementation
|
||||
@ -30,7 +30,7 @@ if (typeof XMLHttpRequest !== 'undefined') {
|
||||
};
|
||||
} else {
|
||||
// find the first MS implementation available
|
||||
getXhr = _v4(['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'])
|
||||
getXhr = _(['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'])
|
||||
.map(function (appName) {
|
||||
/* jshint unused: false */
|
||||
try {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
var qs = require('querystring');
|
||||
var errors = module.exports;
|
||||
|
||||
@ -21,21 +21,21 @@ function ErrorAbstract(msg, constructor, metadata) {
|
||||
}
|
||||
|
||||
if (metadata) {
|
||||
_v4.assign(this, metadata);
|
||||
_.assign(this, metadata);
|
||||
|
||||
this.toString = function () {
|
||||
return msg + ' :: ' + JSON.stringify(metadata);
|
||||
};
|
||||
|
||||
this.toJSON = function () {
|
||||
return _v4.assign({
|
||||
return _.assign({
|
||||
msg: msg
|
||||
}, metadata);
|
||||
};
|
||||
}
|
||||
}
|
||||
errors._Abstract = ErrorAbstract;
|
||||
_v4.inherits(ErrorAbstract, Error);
|
||||
_.inherits(ErrorAbstract, Error);
|
||||
|
||||
/**
|
||||
* Connection Error
|
||||
@ -44,7 +44,7 @@ _v4.inherits(ErrorAbstract, Error);
|
||||
errors.ConnectionFault = function ConnectionFault(msg) {
|
||||
ErrorAbstract.call(this, msg || 'Connection Failure', errors.ConnectionFault);
|
||||
};
|
||||
_v4.inherits(errors.ConnectionFault, ErrorAbstract);
|
||||
_.inherits(errors.ConnectionFault, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* No Living Connections
|
||||
@ -53,7 +53,7 @@ _v4.inherits(errors.ConnectionFault, ErrorAbstract);
|
||||
errors.NoConnections = function NoConnections(msg) {
|
||||
ErrorAbstract.call(this, msg || 'No Living connections', errors.NoConnections);
|
||||
};
|
||||
_v4.inherits(errors.NoConnections, ErrorAbstract);
|
||||
_.inherits(errors.NoConnections, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* Generic Error
|
||||
@ -62,7 +62,7 @@ _v4.inherits(errors.NoConnections, ErrorAbstract);
|
||||
errors.Generic = function Generic(msg, metadata) {
|
||||
ErrorAbstract.call(this, msg || 'Generic Error', errors.Generic, metadata);
|
||||
};
|
||||
_v4.inherits(errors.Generic, ErrorAbstract);
|
||||
_.inherits(errors.Generic, ErrorAbstract);
|
||||
|
||||
/**
|
||||
* Request Timeout Error
|
||||
@ -71,7 +71,7 @@ _v4.inherits(errors.Generic, ErrorAbstract);
|
||||
errors.RequestTimeout = function RequestTimeout(msg) {
|
||||
ErrorAbstract.call(this, msg || 'Request Timeout', errors.RequestTimeout);
|
||||
};
|
||||
_v4.inherits(errors.RequestTimeout, ErrorAbstract);
|
||||
_.inherits(errors.RequestTimeout, ErrorAbstract);
|
||||
|
||||
|
||||
/**
|
||||
@ -81,7 +81,7 @@ _v4.inherits(errors.RequestTimeout, ErrorAbstract);
|
||||
errors.Serialization = function Serialization(msg) {
|
||||
ErrorAbstract.call(this, msg || 'Unable to parse/serialize body', errors.Serialization);
|
||||
};
|
||||
_v4.inherits(errors.Serialization, ErrorAbstract);
|
||||
_.inherits(errors.Serialization, ErrorAbstract);
|
||||
|
||||
|
||||
/**
|
||||
@ -90,7 +90,7 @@ _v4.inherits(errors.Serialization, ErrorAbstract);
|
||||
errors.RequestTypeError = function RequestTypeError(feature) {
|
||||
ErrorAbstract.call(this, 'Cross-domain AJAX requests ' + feature + ' are not supported', errors.RequestTypeError);
|
||||
};
|
||||
_v4.inherits(errors.RequestTypeError, ErrorAbstract);
|
||||
_.inherits(errors.RequestTypeError, ErrorAbstract);
|
||||
|
||||
var statusCodes = [
|
||||
[300, 'Multiple Choices'],
|
||||
@ -137,20 +137,20 @@ var statusCodes = [
|
||||
[510, 'Not Extended']
|
||||
];
|
||||
|
||||
_v4.each(statusCodes, function createStatusCodeError(tuple) {
|
||||
_.each(statusCodes, function createStatusCodeError(tuple) {
|
||||
var status = tuple[0];
|
||||
var names = tuple[1];
|
||||
var allNames = [].concat(names, status);
|
||||
var primaryName = allNames[0];
|
||||
var className = _v4.studlyCase(primaryName);
|
||||
allNames = _v4.uniq(allNames.concat(className));
|
||||
var className = _.studlyCase(primaryName);
|
||||
allNames = _.uniq(allNames.concat(className));
|
||||
|
||||
function StatusCodeError(msg, metadata) {
|
||||
this.status = status;
|
||||
this.displayName = className;
|
||||
|
||||
var esErrObject = null;
|
||||
if (_v4.isPlainObject(msg)) {
|
||||
if (_.isPlainObject(msg)) {
|
||||
esErrObject = msg;
|
||||
msg = null;
|
||||
}
|
||||
@ -168,8 +168,8 @@ _v4.each(statusCodes, function createStatusCodeError(tuple) {
|
||||
|
||||
memo += '[' + cause.type + '] ' + cause.reason;
|
||||
|
||||
var extraData = _v4.omit(cause, ['type', 'reason']);
|
||||
if (_v4.size(extraData)) {
|
||||
var extraData = _.omit(cause, ['type', 'reason']);
|
||||
if (_.size(extraData)) {
|
||||
memo += ', with { ' + qs.stringify(extraData, ' ', '=', {
|
||||
encodeURIComponent: function (v) {
|
||||
return String(v).split('\n').join('\\n');
|
||||
@ -188,7 +188,7 @@ _v4.each(statusCodes, function createStatusCodeError(tuple) {
|
||||
ErrorAbstract.call(this, msg || primaryName, StatusCodeError, metadata);
|
||||
return this;
|
||||
}
|
||||
_v4.inherits(StatusCodeError, ErrorAbstract);
|
||||
_.inherits(StatusCodeError, ErrorAbstract);
|
||||
|
||||
allNames.forEach(function (name) {
|
||||
errors[name] = StatusCodeError;
|
||||
|
||||
@ -6,7 +6,7 @@ module.exports = Host;
|
||||
|
||||
var url = require('url');
|
||||
var qs = require('querystring');
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
|
||||
var startsWithProtocolRE = /^([a-z]+:)?\/\//;
|
||||
var defaultProto = 'http:';
|
||||
@ -46,7 +46,7 @@ Host.defaultPorts = {
|
||||
};
|
||||
|
||||
function Host(config, globalConfig) {
|
||||
config = _v4.clone(config || {});
|
||||
config = _.clone(config || {});
|
||||
globalConfig = globalConfig || {};
|
||||
|
||||
// defaults
|
||||
@ -58,7 +58,7 @@ function Host(config, globalConfig) {
|
||||
this.headers = null;
|
||||
this.suggestCompression = !!globalConfig.suggestCompression;
|
||||
|
||||
this.ssl = _v4.defaults({}, config.ssl || {}, globalConfig.ssl || {}, sslDefaults);
|
||||
this.ssl = _.defaults({}, config.ssl || {}, globalConfig.ssl || {}, sslDefaults);
|
||||
|
||||
if (typeof config === 'string') {
|
||||
var firstColon = config.indexOf(':');
|
||||
@ -69,7 +69,7 @@ function Host(config, globalConfig) {
|
||||
if ((noSlash || portNoPath || portWithPath) && !startsWithProtocolRE.test(config)) {
|
||||
config = defaultProto + '//' + config;
|
||||
}
|
||||
config = _v4.pick(url.parse(config, false, true), urlParseFields);
|
||||
config = _.pick(url.parse(config, false, true), urlParseFields);
|
||||
// default logic for the port is to use 9200 for the default. When a string is specified though,
|
||||
// we will use the default from the protocol of the string.
|
||||
if (!config.port) {
|
||||
@ -83,9 +83,9 @@ function Host(config, globalConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
if (_v4.isObject(config)) {
|
||||
if (_.isObject(config)) {
|
||||
// move hostname/portname to host/port semi-intelligently.
|
||||
_v4.each(simplify, function (to) {
|
||||
_.each(simplify, function (to) {
|
||||
var from = to + 'name';
|
||||
if (config[from] && config[to]) {
|
||||
if (config[to].indexOf(config[from]) === 0) {
|
||||
@ -106,20 +106,20 @@ function Host(config, globalConfig) {
|
||||
delete config.auth;
|
||||
}
|
||||
|
||||
_v4.forOwn(config, _v4.bind(function (val, prop) {
|
||||
if (val != null) this[prop] = _v4.clone(val);
|
||||
_.forOwn(config, _.bind(function (val, prop) {
|
||||
if (val != null) this[prop] = _.clone(val);
|
||||
}, this));
|
||||
|
||||
// make sure the query string is parsed
|
||||
if (this.query === null) {
|
||||
// majority case
|
||||
this.query = {};
|
||||
} else if (!_v4.isPlainObject(this.query)) {
|
||||
} else if (!_.isPlainObject(this.query)) {
|
||||
this.query = qs.parse(this.query);
|
||||
}
|
||||
|
||||
// make sure that the port is a number
|
||||
if (_v4.isNumeric(this.port)) {
|
||||
if (_.isNumeric(this.port)) {
|
||||
this.port = parseInt(this.port, 10);
|
||||
} else {
|
||||
this.port = 9200;
|
||||
@ -177,10 +177,10 @@ function objectPropertyGetter(prop, preOverride) {
|
||||
}
|
||||
|
||||
if (overrides) {
|
||||
obj = _v4.assign({}, obj, overrides);
|
||||
obj = _.assign({}, obj, overrides);
|
||||
}
|
||||
|
||||
return _v4.size(obj) ? obj : null;
|
||||
return _.size(obj) ? obj : null;
|
||||
};
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ Host.prototype.getHeaders = objectPropertyGetter('headers', function (overrides)
|
||||
return overrides;
|
||||
}
|
||||
|
||||
return _v4.defaults(overrides || {}, {
|
||||
return _.defaults(overrides || {}, {
|
||||
'Accept-Encoding': 'gzip,deflate'
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
var url = require('url');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
@ -24,13 +24,13 @@ function Log(config) {
|
||||
var i;
|
||||
var outputs;
|
||||
|
||||
if (_v4.isArrayOfStrings(config.log)) {
|
||||
if (_.isArrayOfStrings(config.log)) {
|
||||
outputs = [{
|
||||
levels: config.log
|
||||
}];
|
||||
} else {
|
||||
outputs = _v4.createArray(config.log, function (val) {
|
||||
if (_v4.isPlainObject(val)) {
|
||||
outputs = _.createArray(config.log, function (val) {
|
||||
if (_.isPlainObject(val)) {
|
||||
return val;
|
||||
}
|
||||
if (typeof val === 'string') {
|
||||
@ -50,7 +50,7 @@ function Log(config) {
|
||||
this.addOutput(outputs[i]);
|
||||
}
|
||||
}
|
||||
_v4.inherits(Log, EventEmitter);
|
||||
_.inherits(Log, EventEmitter);
|
||||
|
||||
Log.loggers = require('./loggers');
|
||||
|
||||
@ -151,14 +151,14 @@ Log.levels = [
|
||||
Log.parseLevels = function (input) {
|
||||
switch (typeof input) {
|
||||
case 'string':
|
||||
var i = _v4.indexOf(Log.levels, input);
|
||||
var i = _.indexOf(Log.levels, input);
|
||||
if (i >= 0) {
|
||||
return Log.levels.slice(0, i + 1);
|
||||
}
|
||||
/* fall through */
|
||||
case 'object':
|
||||
if (_v4.isArray(input)) {
|
||||
var valid = _v4.intersection(input, Log.levels);
|
||||
if (_.isArray(input)) {
|
||||
var valid = _.intersection(input, Log.levels);
|
||||
if (valid.length === input.length) {
|
||||
return valid;
|
||||
}
|
||||
@ -176,13 +176,13 @@ Log.parseLevels = function (input) {
|
||||
* @method join
|
||||
* @static
|
||||
* @private
|
||||
* @param {*} arrayish - An array like object that can be itterated by _v4.each
|
||||
* @param {*} arrayish - An array like object that can be itterated by _.each
|
||||
* @return {String} - The final string.
|
||||
*/
|
||||
Log.join = function (arrayish) {
|
||||
return _v4.map(arrayish, function (item) {
|
||||
if (_v4.isPlainObject(item)) {
|
||||
return _v4.inspect(item) + '\n';
|
||||
return _.map(arrayish, function (item) {
|
||||
if (_.isPlainObject(item)) {
|
||||
return _.inspect(item) + '\n';
|
||||
} else {
|
||||
return item.toString();
|
||||
}
|
||||
@ -209,7 +209,7 @@ Log.prototype.addOutput = function (config) {
|
||||
config.levels = Log.parseLevels(config.levels || config.level || 'warning');
|
||||
delete config.level;
|
||||
|
||||
var Logger = _v4.funcEnum(config, 'type', Log.loggers, process.browser ? 'console' : 'stdio');
|
||||
var Logger = _.funcEnum(config, 'type', Log.loggers, process.browser ? 'console' : 'stdio');
|
||||
return new Logger(this, config);
|
||||
};
|
||||
|
||||
@ -289,7 +289,7 @@ Log.normalizeTraceArgs = function (method, requestUrl, body, responseBody, respo
|
||||
if (typeof requestUrl === 'string') {
|
||||
requestUrl = url.parse(requestUrl, true, true);
|
||||
} else {
|
||||
requestUrl = _v4.clone(requestUrl);
|
||||
requestUrl = _.clone(requestUrl);
|
||||
if (requestUrl.path) {
|
||||
requestUrl.query = url.parse(requestUrl.path, true, false).query;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
|
||||
/**
|
||||
* Abstract class providing common functionality to loggers
|
||||
@ -9,7 +9,7 @@ function LoggerAbstract(log, config) {
|
||||
this.log = log;
|
||||
this.listeningLevels = [];
|
||||
|
||||
_v4.makeBoundMethods(this);
|
||||
_.makeBoundMethods(this);
|
||||
|
||||
// when the log closes, remove our event listeners
|
||||
this.log.once('closing', this.bound.cleanUpListeners);
|
||||
@ -37,7 +37,7 @@ LoggerAbstract.prototype.timestamp = function () {
|
||||
};
|
||||
|
||||
function indent(text, spaces) {
|
||||
var space = _v4.repeat(' ', spaces || 2);
|
||||
var space = _.repeat(' ', spaces || 2);
|
||||
return (text || '').split(/\r?\n/).map(function (line) {
|
||||
return space + line;
|
||||
}).join('\n');
|
||||
@ -64,8 +64,8 @@ LoggerAbstract.prototype.setupListeners = function (levels) {
|
||||
|
||||
this.listeningLevels = [];
|
||||
|
||||
_v4.each(levels, _v4.bind(function (level) {
|
||||
var fnName = 'on' + _v4.ucfirst(level);
|
||||
_.each(levels, _.bind(function (level) {
|
||||
var fnName = 'on' + _.ucfirst(level);
|
||||
if (this.bound[fnName]) {
|
||||
this.listeningLevels.push(level);
|
||||
this.log.on(level, this.bound[fnName]);
|
||||
@ -82,9 +82,9 @@ LoggerAbstract.prototype.setupListeners = function (levels) {
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.cleanUpListeners = _v4.handler(function () {
|
||||
_v4.each(this.listeningLevels, _v4.bind(function (level) {
|
||||
this.log.removeListener(level, this.bound['on' + _v4.ucfirst(level)]);
|
||||
LoggerAbstract.prototype.cleanUpListeners = _.handler(function () {
|
||||
_.each(this.listeningLevels, _.bind(function (level) {
|
||||
this.log.removeListener(level, this.bound['on' + _.ucfirst(level)]);
|
||||
}, this));
|
||||
});
|
||||
|
||||
@ -96,7 +96,7 @@ LoggerAbstract.prototype.cleanUpListeners = _v4.handler(function () {
|
||||
* @param {Error} e - The Error object to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onError = _v4.handler(function (e) {
|
||||
LoggerAbstract.prototype.onError = _.handler(function (e) {
|
||||
this.write((e.name === 'Error' ? 'ERROR' : e.name), e.stack);
|
||||
});
|
||||
|
||||
@ -108,7 +108,7 @@ LoggerAbstract.prototype.onError = _v4.handler(function (e) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onWarning = _v4.handler(function (msg) {
|
||||
LoggerAbstract.prototype.onWarning = _.handler(function (msg) {
|
||||
this.write('WARNING', msg);
|
||||
});
|
||||
|
||||
@ -120,7 +120,7 @@ LoggerAbstract.prototype.onWarning = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onInfo = _v4.handler(function (msg) {
|
||||
LoggerAbstract.prototype.onInfo = _.handler(function (msg) {
|
||||
this.write('INFO', msg);
|
||||
});
|
||||
|
||||
@ -132,7 +132,7 @@ LoggerAbstract.prototype.onInfo = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onDebug = _v4.handler(function (msg) {
|
||||
LoggerAbstract.prototype.onDebug = _.handler(function (msg) {
|
||||
this.write('DEBUG', msg);
|
||||
});
|
||||
|
||||
@ -144,7 +144,7 @@ LoggerAbstract.prototype.onDebug = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
LoggerAbstract.prototype.onTrace = _v4.handler(function (requestDetails) {
|
||||
LoggerAbstract.prototype.onTrace = _.handler(function (requestDetails) {
|
||||
this.write('TRACE', this._formatTraceMessage(requestDetails));
|
||||
});
|
||||
|
||||
|
||||
@ -13,15 +13,15 @@
|
||||
module.exports = Console;
|
||||
|
||||
var LoggerAbstract = require('../logger');
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
|
||||
function Console(log, config) {
|
||||
LoggerAbstract.call(this, log, config);
|
||||
|
||||
// config/state
|
||||
this.color = _v4.has(config, 'color') ? !!config.color : true;
|
||||
this.color = _.has(config, 'color') ? !!config.color : true;
|
||||
}
|
||||
_v4.inherits(Console, LoggerAbstract);
|
||||
_.inherits(Console, LoggerAbstract);
|
||||
|
||||
/**
|
||||
* Override the LoggerAbstract's setup listeners to do a little extra setup
|
||||
@ -47,7 +47,7 @@ Console.prototype.write = function (label, message, to) {
|
||||
* @param {Error} e - The Error object to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
Console.prototype.onError = _v4.handler(function (e) {
|
||||
Console.prototype.onError = _.handler(function (e) {
|
||||
var to = console.error ? 'error' : 'log';
|
||||
this.write(e.name === 'Error' ? 'ERROR' : e.name, e.stack || e.message, to);
|
||||
});
|
||||
@ -60,7 +60,7 @@ Console.prototype.onError = _v4.handler(function (e) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Console.prototype.onWarning = _v4.handler(function (msg) {
|
||||
Console.prototype.onWarning = _.handler(function (msg) {
|
||||
this.write('WARNING', msg, console.warn ? 'warn' : 'log');
|
||||
});
|
||||
|
||||
@ -72,7 +72,7 @@ Console.prototype.onWarning = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Console.prototype.onInfo = _v4.handler(function (msg) {
|
||||
Console.prototype.onInfo = _.handler(function (msg) {
|
||||
this.write('INFO', msg, console.info ? 'info' : 'log');
|
||||
});
|
||||
|
||||
@ -84,7 +84,7 @@ Console.prototype.onInfo = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Console.prototype.onDebug = _v4.handler(function (msg) {
|
||||
Console.prototype.onDebug = _.handler(function (msg) {
|
||||
this.write('DEBUG', msg, console.debug ? 'debug' : 'log');
|
||||
});
|
||||
/**
|
||||
@ -94,6 +94,6 @@ Console.prototype.onDebug = _v4.handler(function (msg) {
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
Console.prototype.onTrace = _v4.handler(function (msg) {
|
||||
Console.prototype.onTrace = _.handler(function (msg) {
|
||||
this.write('TRACE', this._formatTraceMessage(msg), 'log');
|
||||
});
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
module.exports = File;
|
||||
|
||||
var StreamLogger = require('./stream');
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var fs = require('fs');
|
||||
|
||||
function File(log, config) {
|
||||
@ -29,10 +29,10 @@ function File(log, config) {
|
||||
|
||||
StreamLogger.call(this, log, config);
|
||||
}
|
||||
_v4.inherits(File, StreamLogger);
|
||||
_.inherits(File, StreamLogger);
|
||||
|
||||
File.prototype.onProcessExit = _v4.handler(function () {
|
||||
var toWrite = _v4.getUnwrittenFromStream(this.stream);
|
||||
File.prototype.onProcessExit = _.handler(function () {
|
||||
var toWrite = _.getUnwrittenFromStream(this.stream);
|
||||
if (toWrite) {
|
||||
fs.appendFileSync(this.path, toWrite);
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ var chalk = require('chalk');
|
||||
chalk.enabled = true;
|
||||
|
||||
var LoggerAbstract = require('../logger');
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
|
||||
var defaultColors = {
|
||||
error: chalk.red.bold,
|
||||
@ -31,12 +31,12 @@ function Stdio(log, config) {
|
||||
LoggerAbstract.call(this, log, config);
|
||||
|
||||
// config/state
|
||||
this.color = !!(_v4.has(config, 'color') ? config.color : chalk.supportsColor);
|
||||
this.color = !!(_.has(config, 'color') ? config.color : chalk.supportsColor);
|
||||
|
||||
this.colors = _v4.defaults(config.colors || {}, defaultColors);
|
||||
this.colors = _.defaults(config.colors || {}, defaultColors);
|
||||
}
|
||||
|
||||
_v4.inherits(Stdio, LoggerAbstract);
|
||||
_.inherits(Stdio, LoggerAbstract);
|
||||
|
||||
/**
|
||||
* Sends output to a stream, does some formatting first
|
||||
@ -65,7 +65,7 @@ Stdio.prototype.write = function (label, message, to, colorize) {
|
||||
* @param {Error} e - The Error object to log
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onError = _v4.handler(function (e) {
|
||||
Stdio.prototype.onError = _.handler(function (e) {
|
||||
this.write(e.name === 'Error' ? 'ERROR' : e.name, e.stack, process.stderr, this.colors.error);
|
||||
});
|
||||
|
||||
@ -77,7 +77,7 @@ Stdio.prototype.onError = _v4.handler(function (e) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onWarning = _v4.handler(function (msg) {
|
||||
Stdio.prototype.onWarning = _.handler(function (msg) {
|
||||
this.write('WARNING', msg, process.stderr, this.colors.warning);
|
||||
});
|
||||
|
||||
@ -89,7 +89,7 @@ Stdio.prototype.onWarning = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onInfo = _v4.handler(function (msg) {
|
||||
Stdio.prototype.onInfo = _.handler(function (msg) {
|
||||
this.write('INFO', msg, process.stdout, this.colors.info);
|
||||
});
|
||||
|
||||
@ -101,7 +101,7 @@ Stdio.prototype.onInfo = _v4.handler(function (msg) {
|
||||
* @param {String} msg - The message to be logged
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onDebug = _v4.handler(function (msg) {
|
||||
Stdio.prototype.onDebug = _.handler(function (msg) {
|
||||
this.write('DEBUG', msg, process.stdout, this.colors.debug);
|
||||
});
|
||||
|
||||
@ -112,6 +112,6 @@ Stdio.prototype.onDebug = _v4.handler(function (msg) {
|
||||
* @private
|
||||
* @return {undefined}
|
||||
*/
|
||||
Stdio.prototype.onTrace = _v4.handler(function (message) {
|
||||
Stdio.prototype.onTrace = _.handler(function (message) {
|
||||
this.write('TRACE', this._formatTraceMessage(message), process.stdout, this.colors.trace);
|
||||
});
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
module.exports = Stream;
|
||||
|
||||
var LoggerAbstract = require('../logger');
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
|
||||
function Stream(log, config) {
|
||||
LoggerAbstract.call(this, log, config);
|
||||
@ -26,17 +26,17 @@ function Stream(log, config) {
|
||||
|
||||
process.once('exit', this.bound.onProcessExit);
|
||||
}
|
||||
_v4.inherits(Stream, LoggerAbstract);
|
||||
_.inherits(Stream, LoggerAbstract);
|
||||
|
||||
Stream.prototype.cleanUpListeners = _v4.handler(function () {
|
||||
Stream.prototype.cleanUpListeners = _.handler(function () {
|
||||
process.removeListener('exit', this.bound.onProcessExit);
|
||||
LoggerAbstract.prototype.cleanUpListeners.call(this);
|
||||
});
|
||||
|
||||
// flush the write buffer to stderr synchronously
|
||||
Stream.prototype.onProcessExit = _v4.handler(function () {
|
||||
Stream.prototype.onProcessExit = _.handler(function () {
|
||||
// process is dying, lets manually flush the buffer synchronously to stderr.
|
||||
var unwritten = _v4.getUnwrittenFromStream(this.stream);
|
||||
var unwritten = _.getUnwrittenFromStream(this.stream);
|
||||
if (unwritten) {
|
||||
console.error('Log stream did not get to finish writing. Flushing to stderr');
|
||||
console.error(unwritten);
|
||||
|
||||
@ -14,7 +14,7 @@ module.exports = Tracer;
|
||||
|
||||
var StreamLogger = require('./stream');
|
||||
var fs = require('fs');
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var url = require('url');
|
||||
|
||||
function Tracer(log, config) {
|
||||
@ -29,18 +29,18 @@ function Tracer(log, config) {
|
||||
|
||||
StreamLogger.call(this, log, config);
|
||||
}
|
||||
_v4.inherits(Tracer, StreamLogger);
|
||||
_.inherits(Tracer, StreamLogger);
|
||||
|
||||
var usefulUrlFields = ['protocol', 'slashes', 'port', 'hostname', 'pathname', 'query'];
|
||||
|
||||
Tracer.prototype._formatTraceMessage = function (req) {
|
||||
var reqUrl = _v4.pick(url.parse(req.url, true, false), usefulUrlFields);
|
||||
var reqUrl = _.pick(url.parse(req.url, true, false), usefulUrlFields);
|
||||
|
||||
var originalHost = url.format(_v4.pick(reqUrl, 'protocol', 'hostname', 'port'));
|
||||
var originalHost = url.format(_.pick(reqUrl, 'protocol', 'hostname', 'port'));
|
||||
|
||||
reqUrl.port = this.curlPort;
|
||||
reqUrl.hostname = this.curlHost;
|
||||
reqUrl.query = _v4.defaults(reqUrl.query || {}, { pretty: true });
|
||||
reqUrl.query = _.defaults(reqUrl.query || {}, { pretty: true });
|
||||
|
||||
/* jshint quotmark: double */
|
||||
var curlCall =
|
||||
@ -56,7 +56,7 @@ Tracer.prototype._formatTraceMessage = function (req) {
|
||||
};
|
||||
|
||||
function comment(str) {
|
||||
return _v4.map(str.split(/\r?\n/g), function (line) {
|
||||
return _.map(str.split(/\r?\n/g), function (line) {
|
||||
return '# ' + line;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
|
||||
var extractHostPartsRE1x = /\[\/*([^:]+):(\d+)\]/;
|
||||
|
||||
function makeNodeParser(hostProp) {
|
||||
return function (nodes) {
|
||||
return _v4.transform(nodes, function (hosts, node, id) {
|
||||
return _.transform(nodes, function (hosts, node, id) {
|
||||
var address = node[hostProp]
|
||||
if (!address) return;
|
||||
|
||||
|
||||
4
src/lib/serializers/angular.js
vendored
4
src/lib/serializers/angular.js
vendored
@ -1,9 +1,9 @@
|
||||
/* global angular */
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
var JsonSerializer = require('../serializers/json');
|
||||
|
||||
function AngularSerializer() {}
|
||||
_v4.inherits(AngularSerializer, JsonSerializer);
|
||||
_.inherits(AngularSerializer, JsonSerializer);
|
||||
|
||||
// mimic the JsonSerializer's encode method, but use angular's toJson instead
|
||||
AngularSerializer.prototype.encode = function (val) {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
module.exports = Json;
|
||||
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
|
||||
function Json() {}
|
||||
|
||||
@ -46,7 +46,7 @@ Json.prototype.deserialize = function (str) {
|
||||
Json.prototype.bulkBody = function (val) {
|
||||
var body = '', i;
|
||||
|
||||
if (_v4.isArray(val)) {
|
||||
if (_.isArray(val)) {
|
||||
for (i = 0; i < val.length; i++) {
|
||||
body += this.serialize(val[i]) + '\n';
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
module.exports = Transport;
|
||||
|
||||
// var _ = require('./utils');
|
||||
var _ = require('./utils');
|
||||
var errors = require('./errors');
|
||||
var Host = require('./host');
|
||||
var Promise = require('promise/lib/es6-extensions');
|
||||
@ -19,15 +19,15 @@ function Transport(config) {
|
||||
config.log = self.log = new LogClass(config);
|
||||
|
||||
// setup the connection pool
|
||||
var ConnectionPool = _v4.funcEnum(config, 'connectionPool', Transport.connectionPools, 'main');
|
||||
var ConnectionPool = _.funcEnum(config, 'connectionPool', Transport.connectionPools, 'main');
|
||||
self.connectionPool = new ConnectionPool(config);
|
||||
|
||||
// setup the serializer
|
||||
var Serializer = _v4.funcEnum(config, 'serializer', Transport.serializers, 'json');
|
||||
var Serializer = _.funcEnum(config, 'serializer', Transport.serializers, 'json');
|
||||
self.serializer = new Serializer(config);
|
||||
|
||||
// setup the nodesToHostCallback
|
||||
self.nodesToHostCallback = _v4.funcEnum(config, 'nodesToHostCallback', Transport.nodesToHostCallbacks, 'main');
|
||||
self.nodesToHostCallback = _.funcEnum(config, 'nodesToHostCallback', Transport.nodesToHostCallbacks, 'main');
|
||||
|
||||
// setup max retries
|
||||
self.maxRetries = config.hasOwnProperty('maxRetries') ? config.maxRetries : 3;
|
||||
@ -50,8 +50,8 @@ function Transport(config) {
|
||||
}
|
||||
|
||||
if (config.hosts) {
|
||||
var hostsConfig = _v4.createArray(config.hosts, function (val) {
|
||||
if (_v4.isPlainObject(val) || _v4.isString(val) || val instanceof Host) {
|
||||
var hostsConfig = _.createArray(config.hosts, function (val) {
|
||||
if (_.isPlainObject(val) || _.isString(val) || val instanceof Host) {
|
||||
return val;
|
||||
}
|
||||
});
|
||||
@ -62,7 +62,7 @@ function Transport(config) {
|
||||
}
|
||||
|
||||
if (randomizeHosts) {
|
||||
hostsConfig = _v4.shuffle(hostsConfig);
|
||||
hostsConfig = _.shuffle(hostsConfig);
|
||||
}
|
||||
|
||||
self.setHosts(hostsConfig);
|
||||
@ -139,7 +139,7 @@ Transport.prototype.request = function (params, cb) {
|
||||
var defer; // the defer object, will be set when we are using promises.
|
||||
|
||||
var body = params.body;
|
||||
var headers = !params.headers ? {} : _v4.transform(params.headers, function (headers, val, name) {
|
||||
var headers = !params.headers ? {} : _.transform(params.headers, function (headers, val, name) {
|
||||
headers[String(name).toLowerCase()] = val;
|
||||
});
|
||||
|
||||
@ -161,7 +161,7 @@ Transport.prototype.request = function (params, cb) {
|
||||
}
|
||||
|
||||
if (body && params.method === 'GET') {
|
||||
_v4.nextTick(respond, new TypeError('Body can not be sent with method "GET"'));
|
||||
_.nextTick(respond, new TypeError('Body can not be sent with method "GET"'));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -274,10 +274,10 @@ Transport.prototype.request = function (params, cb) {
|
||||
if (
|
||||
(!err || err instanceof errors.Serialization)
|
||||
&& (status < 200 || status >= 300)
|
||||
&& (!params.ignore || !_v4.includes(params.ignore, status))
|
||||
&& (!params.ignore || !_.includes(params.ignore, status))
|
||||
) {
|
||||
|
||||
var errorMetadata = _v4.pick(params.req, ['path', 'query', 'body']);
|
||||
var errorMetadata = _.pick(params.req, ['path', 'query', 'body']);
|
||||
errorMetadata.statusCode = status;
|
||||
errorMetadata.response = body;
|
||||
|
||||
@ -361,7 +361,7 @@ Transport.prototype._timeout = function (cb, delay) {
|
||||
if (cb) {
|
||||
// set the timer
|
||||
id = setTimeout(function () {
|
||||
_v4.pull(timers, id);
|
||||
_.pull(timers, id);
|
||||
cb();
|
||||
}, delay);
|
||||
|
||||
@ -392,7 +392,7 @@ Transport.prototype.sniff = function (cb) {
|
||||
var sniffedNodesProtocol = this.sniffedNodesProtocol;
|
||||
|
||||
// make cb a function if it isn't
|
||||
cb = typeof cb === 'function' ? cb : _v4.noop;
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
|
||||
this.request({
|
||||
path: this.sniffEndpoint,
|
||||
@ -409,7 +409,7 @@ Transport.prototype.sniff = function (cb) {
|
||||
return;
|
||||
}
|
||||
|
||||
_v4.forEach(hostsConfigs, function (hostConfig) {
|
||||
_.forEach(hostsConfigs, function (hostConfig) {
|
||||
if (sniffedNodesProtocol) hostConfig.protocol = sniffedNodesProtocol;
|
||||
});
|
||||
|
||||
@ -427,7 +427,7 @@ Transport.prototype.sniff = function (cb) {
|
||||
*/
|
||||
Transport.prototype.setHosts = function (hostsConfigs) {
|
||||
var globalConfig = this._config;
|
||||
this.connectionPool.setHosts(_v4.map(hostsConfigs, function (conf) {
|
||||
this.connectionPool.setHosts(_.map(hostsConfigs, function (conf) {
|
||||
return (conf instanceof Host) ? conf : new Host(conf, globalConfig);
|
||||
}));
|
||||
};
|
||||
@ -439,7 +439,7 @@ Transport.prototype.setHosts = function (hostsConfigs) {
|
||||
Transport.prototype.close = function () {
|
||||
this.log.close();
|
||||
this.closed = true;
|
||||
_v4.each(this._timers, clearTimeout);
|
||||
_.each(this._timers, clearTimeout);
|
||||
this._timers = null;
|
||||
this.connectionPool.close();
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var isEmpty = require('lodash-migrate').isEmpty;
|
||||
var isEmpty = require('lodash').isEmpty;
|
||||
|
||||
module.exports = function (hosts) {
|
||||
if (isEmpty(hosts)) return false;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('../utils');
|
||||
var _ = require('../utils');
|
||||
|
||||
|
||||
/**
|
||||
@ -25,7 +25,7 @@ module.exports = function setupSniffOnConnectionFault(transport) {
|
||||
// create a function that will count down to a
|
||||
// point n milliseconds into the future
|
||||
var countdownTo = function (ms) {
|
||||
var start = _v4.now();
|
||||
var start = _.now();
|
||||
return function () {
|
||||
return start - ms;
|
||||
};
|
||||
|
||||
103
src/lib/utils.js
103
src/lib/utils.js
@ -1,26 +1,23 @@
|
||||
var path = require('path');
|
||||
// var _ = require('lodash');
|
||||
// require('../../stub')
|
||||
var nodeUtils = require('util');
|
||||
|
||||
/**
|
||||
* Custom _v4 library, basically a modified version of [lodash](http://lodash.com/docs) +
|
||||
* [node._v4](http://nodejs.org/api/util.html#util_util) that doesn't use mixins to prevent
|
||||
* Custom _ library, basically a modified version of [lodash](http://lodash.com/docs) +
|
||||
* [node._](http://nodejs.org/api/util.html#util_util) that doesn't use mixins to prevent
|
||||
* confusion when requiring lodash itself.
|
||||
*
|
||||
* @class _v4
|
||||
* @class _
|
||||
* @static
|
||||
*/
|
||||
_v4.assign(_v4, nodeUtils);
|
||||
// _v4 = _v4;
|
||||
var _ = require('lodash').assign({}, require('lodash'), nodeUtils);
|
||||
|
||||
/**
|
||||
* Link to [path.join](http://nodejs.org/api/path.html#path_path_join_path1_path2)
|
||||
*
|
||||
* @method _v4.joinPath
|
||||
* @method _.joinPath
|
||||
* @type {function}
|
||||
*/
|
||||
_v4.joinPath = path.join;
|
||||
_.joinPath = path.join;
|
||||
|
||||
/**
|
||||
* Recursively merge two objects, walking into each object and concating arrays. If both to and from have a value at a
|
||||
@ -32,18 +29,18 @@ _v4.joinPath = path.join;
|
||||
* @param {Object} from - Object to pull changed from
|
||||
* @return {Object} - returns the modified to value
|
||||
*/
|
||||
_v4.deepMerge = function (to, from) {
|
||||
_v4.each(from, function (fromVal, key) {
|
||||
_.deepMerge = function (to, from) {
|
||||
_.each(from, function (fromVal, key) {
|
||||
switch (typeof to[key]) {
|
||||
case 'undefined':
|
||||
to[key] = from[key];
|
||||
break;
|
||||
case 'object':
|
||||
if (_v4.isArray(to[key]) && _v4.isArray(from[key])) {
|
||||
if (_.isArray(to[key]) && _.isArray(from[key])) {
|
||||
to[key] = to[key].concat(from[key]);
|
||||
}
|
||||
else if (_v4.isPlainObject(to[key]) && _v4.isPlainObject(from[key])) {
|
||||
_v4.deepMerge(to[key], from[key]);
|
||||
else if (_.isPlainObject(to[key]) && _.isPlainObject(from[key])) {
|
||||
_.deepMerge(to[key], from[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -57,7 +54,7 @@ _v4.deepMerge = function (to, from) {
|
||||
* @param {Array} arr - An array to check
|
||||
* @return {Boolean}
|
||||
*/
|
||||
_v4.each([
|
||||
_.each([
|
||||
'String',
|
||||
'Object',
|
||||
'PlainObject',
|
||||
@ -66,11 +63,11 @@ _v4.each([
|
||||
'Function',
|
||||
'RegExp'
|
||||
], function (type) {
|
||||
var check = _v4['is' + type];
|
||||
var check = _['is' + type];
|
||||
|
||||
_v4['isArrayOf' + type + 's'] = function (arr) {
|
||||
_['isArrayOf' + type + 's'] = function (arr) {
|
||||
// quick shallow check of arrays
|
||||
return _v4.isArray(arr) && _v4.every(arr.slice(0, 10), check);
|
||||
return _.isArray(arr) && _.every(arr.slice(0, 10), check);
|
||||
};
|
||||
});
|
||||
|
||||
@ -82,7 +79,7 @@ _v4.each([
|
||||
* @param {string} word - The word to transform
|
||||
* @return {string}
|
||||
*/
|
||||
_v4.ucfirst = function (word) {
|
||||
_.ucfirst = function (word) {
|
||||
return word[0].toUpperCase() + word.substring(1).toLowerCase();
|
||||
};
|
||||
|
||||
@ -143,7 +140,7 @@ function adjustWordCase(firstWordCap, otherWordsCap, sep) {
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
_v4.studlyCase = adjustWordCase(true, true, '');
|
||||
_.studlyCase = adjustWordCase(true, true, '');
|
||||
|
||||
/**
|
||||
* Transform a string into camelCase
|
||||
@ -152,7 +149,7 @@ _v4.studlyCase = adjustWordCase(true, true, '');
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
_v4.camelCase = adjustWordCase(false, true, '');
|
||||
_.camelCase = adjustWordCase(false, true, '');
|
||||
|
||||
/**
|
||||
* Transform a string into snakeCase
|
||||
@ -161,7 +158,7 @@ _v4.camelCase = adjustWordCase(false, true, '');
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
_v4.snakeCase = adjustWordCase(false, false, '_');
|
||||
_.snakeCase = adjustWordCase(false, false, '_');
|
||||
|
||||
/**
|
||||
* Lower-case a string, and return an empty string if any is not a string
|
||||
@ -169,7 +166,7 @@ _v4.snakeCase = adjustWordCase(false, false, '_');
|
||||
* @param any {*} - Something or nothing
|
||||
* @returns {string}
|
||||
*/
|
||||
_v4.toLowerString = function (any) {
|
||||
_.toLowerString = function (any) {
|
||||
if (any) {
|
||||
if (typeof any !== 'string') {
|
||||
any = any.toString();
|
||||
@ -186,7 +183,7 @@ _v4.toLowerString = function (any) {
|
||||
* @param any {*} - Something or nothing
|
||||
* @returns {string}
|
||||
*/
|
||||
_v4.toUpperString = function (any) {
|
||||
_.toUpperString = function (any) {
|
||||
if (any) {
|
||||
if (typeof any !== 'string') {
|
||||
any = any.toString();
|
||||
@ -204,7 +201,7 @@ _v4.toUpperString = function (any) {
|
||||
* @param {*} val
|
||||
* @return {Boolean}
|
||||
*/
|
||||
_v4.isNumeric = function (val) {
|
||||
_.isNumeric = function (val) {
|
||||
return typeof val !== 'object' && val - parseFloat(val) >= 0;
|
||||
};
|
||||
|
||||
@ -218,7 +215,7 @@ var intervalRE = /^(\d+(?:\.\d+)?)(M|w|d|h|m|s|y|ms)$/;
|
||||
* @param {String} val
|
||||
* @return {Boolean}
|
||||
*/
|
||||
_v4.isInterval = function (val) {
|
||||
_.isInterval = function (val) {
|
||||
return !!(val.match && val.match(intervalRE));
|
||||
};
|
||||
|
||||
@ -231,7 +228,7 @@ _v4.isInterval = function (val) {
|
||||
* @param {Number} times - Times the string should be repeated
|
||||
* @return {String}
|
||||
*/
|
||||
_v4.repeat = function (what, times) {
|
||||
_.repeat = function (what, times) {
|
||||
return (new Array(times + 1)).join(what);
|
||||
};
|
||||
|
||||
@ -244,7 +241,7 @@ _v4.repeat = function (what, times) {
|
||||
* @param [sliceIndex=0] {Integer} - The index that args should be sliced at, before feeding args to func
|
||||
* @returns {*} - the return value of func
|
||||
*/
|
||||
_v4.applyArgs = function (func, context, args, sliceIndex) {
|
||||
_.applyArgs = function (func, context, args, sliceIndex) {
|
||||
sliceIndex = sliceIndex || 0;
|
||||
switch (args.length - sliceIndex) {
|
||||
case 0:
|
||||
@ -270,9 +267,9 @@ _v4.applyArgs = function (func, context, args, sliceIndex) {
|
||||
* when it is called.
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
_v4.nextTick = function (cb) {
|
||||
_.nextTick = function (cb) {
|
||||
// bind the function and schedule it
|
||||
process.nextTick(_v4.bindKey(_v4, 'applyArgs', cb, null, arguments, 1));
|
||||
process.nextTick(_.bindKey(_, 'applyArgs', cb, null, arguments, 1));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -280,7 +277,7 @@ _v4.nextTick = function (cb) {
|
||||
* flagging it to be bound to the object at object creation when "makeBoundMethods" is called
|
||||
*
|
||||
* ```
|
||||
* ClassName.prototype.methodName = _v4.handler(function () {
|
||||
* ClassName.prototype.methodName = _.handler(function () {
|
||||
* // this will always be bound when called via classInstance.bound.methodName
|
||||
* this === classInstance
|
||||
* });
|
||||
@ -290,11 +287,11 @@ _v4.nextTick = function (cb) {
|
||||
* @param {Function} func - The method that is being defined
|
||||
* @return {Function}
|
||||
*/
|
||||
_v4.handler = function (func) {
|
||||
_.handler = function (func) {
|
||||
func._provideBound = true;
|
||||
return func;
|
||||
};
|
||||
_v4.scheduled = _v4.handler;
|
||||
_.scheduled = _.handler;
|
||||
|
||||
/**
|
||||
* Creates an "bound" property on an object, which all or a subset of methods from
|
||||
@ -305,24 +302,24 @@ _v4.scheduled = _v4.handler;
|
||||
* onEvent: function () {}
|
||||
* };
|
||||
*
|
||||
* _v4.makeBoundMethods(obj);
|
||||
* _.makeBoundMethods(obj);
|
||||
*
|
||||
* obj.bound.onEvent() // is bound to obj, and can safely be used as an event handler.
|
||||
* ```
|
||||
*
|
||||
* @param {Object} obj - The object to bind the methods to
|
||||
*/
|
||||
_v4.makeBoundMethods = function (obj) {
|
||||
_.makeBoundMethods = function (obj) {
|
||||
obj.bound = {};
|
||||
for (var prop in obj) {
|
||||
// dearest maintainer, we want to look through the prototype
|
||||
if (typeof obj[prop] === 'function' && obj[prop]._provideBound === true) {
|
||||
obj.bound[prop] = _v4.bind(obj[prop], obj);
|
||||
obj.bound[prop] = _.bind(obj[prop], obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_v4.noop = function () {};
|
||||
_.noop = function () {};
|
||||
|
||||
/**
|
||||
* Implements the standard "string or constructor" check that I was copy/pasting everywhere
|
||||
@ -330,7 +327,7 @@ _v4.noop = function () {};
|
||||
* @param {Object} opts - a map of the options
|
||||
* @return {Function|undefined} - If a valid option was specified, then the constructor is returned
|
||||
*/
|
||||
_v4.funcEnum = function (config, name, opts, def) {
|
||||
_.funcEnum = function (config, name, opts, def) {
|
||||
var val = config[name];
|
||||
switch (typeof val) {
|
||||
case 'undefined':
|
||||
@ -344,14 +341,14 @@ _v4.funcEnum = function (config, name, opts, def) {
|
||||
/* falls through */
|
||||
default:
|
||||
var err = 'Invalid ' + name + ' "' + val + '", expected a function';
|
||||
switch (_v4.size(opts)) {
|
||||
switch (_.size(opts)) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
err += ' or ' + _v4.keys(opts)[0];
|
||||
err += ' or ' + _.keys(opts)[0];
|
||||
break;
|
||||
default:
|
||||
err += ' or one of ' + _v4.keys(opts).join(', ');
|
||||
err += ' or one of ' + _.keys(opts).join(', ');
|
||||
break;
|
||||
}
|
||||
throw new TypeError(err);
|
||||
@ -368,13 +365,13 @@ _v4.funcEnum = function (config, name, opts, def) {
|
||||
* @param {Function} transform - A function called for each element of the resulting array
|
||||
* @return {Array|false} - an array on success, or false on failure.
|
||||
*/
|
||||
_v4.createArray = function (input, transform) {
|
||||
transform = typeof transform === 'function' ? transform : _v4.identity;
|
||||
_.createArray = function (input, transform) {
|
||||
transform = typeof transform === 'function' ? transform : _.identity;
|
||||
var output = [];
|
||||
var item;
|
||||
var i;
|
||||
|
||||
if (!_v4.isArray(input)) {
|
||||
if (!_.isArray(input)) {
|
||||
input = [input];
|
||||
}
|
||||
|
||||
@ -397,19 +394,19 @@ _v4.createArray = function (input, transform) {
|
||||
* @param {WritableStream} stream - an instance of stream.Writable
|
||||
* @return {string} - the remaining test to be written to the stream
|
||||
*/
|
||||
_v4.getUnwrittenFromStream = function (stream) {
|
||||
var writeBuffer = _v4.getStreamWriteBuffer(stream);
|
||||
_.getUnwrittenFromStream = function (stream) {
|
||||
var writeBuffer = _.getStreamWriteBuffer(stream);
|
||||
if (!writeBuffer) return;
|
||||
|
||||
// flush the write buffer
|
||||
var out = '';
|
||||
if (!writeBuffer.length) return out;
|
||||
|
||||
_v4.each(writeBuffer, function (writeReq) {
|
||||
_.each(writeBuffer, function (writeReq) {
|
||||
if (writeReq.chunk) {
|
||||
// 0.9.12+ uses WriteReq objects with a chunk prop
|
||||
out += '' + writeReq.chunk;
|
||||
} else if (_v4.isArray(writeReq) && (typeof writeReq[0] === 'string' || Buffer.isBuffer(writeReq[0]))) {
|
||||
} else if (_.isArray(writeReq) && (typeof writeReq[0] === 'string' || Buffer.isBuffer(writeReq[0]))) {
|
||||
// 0.9.4 - 0.9.9 buffers are arrays of arrays like [[chunk, cb], [chunk, undef], ...].
|
||||
out += '' + writeReq[0];
|
||||
} else {
|
||||
@ -419,7 +416,7 @@ _v4.getUnwrittenFromStream = function (stream) {
|
||||
return out;
|
||||
};
|
||||
|
||||
_v4.getStreamWriteBuffer = function (stream) {
|
||||
_.getStreamWriteBuffer = function (stream) {
|
||||
if (!stream || !stream._writableState) return;
|
||||
|
||||
var writeState = stream._writableState;
|
||||
@ -431,16 +428,16 @@ _v4.getStreamWriteBuffer = function (stream) {
|
||||
}
|
||||
};
|
||||
|
||||
_v4.clearWriteStreamBuffer = function (stream) {
|
||||
var buffer = _v4.getStreamWriteBuffer(stream);
|
||||
_.clearWriteStreamBuffer = function (stream) {
|
||||
var buffer = _.getStreamWriteBuffer(stream);
|
||||
return buffer && buffer.splice(0);
|
||||
};
|
||||
|
||||
/**
|
||||
* return the current time in milliseconds since epoch
|
||||
*/
|
||||
_v4.now = function () {
|
||||
_.now = function () {
|
||||
return (typeof Date.now === 'function') ? Date.now() : (new Date()).getTime();
|
||||
};
|
||||
|
||||
module.exports = _v4;
|
||||
module.exports = _;
|
||||
|
||||
Reference in New Issue
Block a user