and finally, return to standard mo
This commit is contained in:
@ -315,7 +315,7 @@ var client = new elasticsearch.Client({
|
||||
selector: function (hosts) {
|
||||
var myCountry = process.env.COUNTRY;
|
||||
// first try to find a node that is in the same country
|
||||
var selection = _v4.find(nodes, function (node) {
|
||||
var selection = _.find(nodes, function (node) {
|
||||
return node.host.country === myCountry;
|
||||
});
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ var client = new elasticsearch.Client({
|
||||
selector: function (hosts) {
|
||||
var myCountry = process.env.COUNTRY;
|
||||
// first try to find a node that is in the same country
|
||||
var selection = _v4.find(nodes, function (node) {
|
||||
var selection = _.find(nodes, function (node) {
|
||||
return node.host.country === myCountry;
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var utils = require('../utils');
|
||||
var fromRoot = require('path').join.bind(null, __dirname, '..', '..');
|
||||
|
||||
var release = process.env.ES_RELEASE;
|
||||
var ref = process.env.ES_REF;
|
||||
var port = parseFloat(_v4.get(process.env, 'ES_PORT', 9400));
|
||||
var host = _v4.get(process.env, 'ES_HOST', 'localhost');
|
||||
var port = parseFloat(_.get(process.env, 'ES_PORT', 9400));
|
||||
var host = _.get(process.env, 'ES_HOST', 'localhost');
|
||||
|
||||
var Version = require('../../scripts/Version');
|
||||
var versionedOpts = [
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var root = require('find-root')(__dirname);
|
||||
var rel = require('path').resolve.bind(null, root);
|
||||
var rootReq = function (p) { return require(rel(p)); };
|
||||
// var _ = rootReq('src/lib/utils');
|
||||
var _ = rootReq('src/lib/utils');
|
||||
var grunt = require('grunt');
|
||||
|
||||
var JENKINS_REPORTER = rel('test/utils/jenkins-reporter.js');
|
||||
@ -65,7 +65,7 @@ var config = {
|
||||
grunt.registerTask('mocha_integration', function (branch) {
|
||||
grunt.config.set(
|
||||
'mochacov.integration.src',
|
||||
'test/integration/yaml_suite/index_' + _v4.snakeCase(branch) + '.js'
|
||||
'test/integration/yaml_suite/index_' + _.snakeCase(branch) + '.js'
|
||||
);
|
||||
grunt.task.run('mochacov:integration');
|
||||
});
|
||||
@ -73,7 +73,7 @@ grunt.registerTask('mocha_integration', function (branch) {
|
||||
grunt.registerTask('mocha_jenkins_integration', function (branch) {
|
||||
grunt.config.set(
|
||||
'mochacov.jenkins_integration.src',
|
||||
'test/integration/yaml_suite/index_' + _v4.snakeCase(branch) + '.js'
|
||||
'test/integration/yaml_suite/index_' + _.snakeCase(branch) + '.js'
|
||||
);
|
||||
grunt.task.run('mochacov:jenkins_integration');
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('../src/lib/utils');
|
||||
var _ = require('../src/lib/utils');
|
||||
|
||||
var root = require('find-root')(__dirname);
|
||||
var pkg = require(root + '/package.json');
|
||||
@ -8,7 +8,7 @@ var branches = [].concat(stable, unstable);
|
||||
|
||||
var utils = {
|
||||
branchSuffix: function (branch) {
|
||||
return branch === utils.branches._default ? '' : '_' + _v4.snakeCase(branch);
|
||||
return branch === utils.branches._default ? '' : '_' + _.snakeCase(branch);
|
||||
},
|
||||
branches: branches,
|
||||
stableBranches: stable,
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
"dependencies": {
|
||||
"chalk": "^1.0.0",
|
||||
"forever-agent": "^0.6.0",
|
||||
"lodash": "^3.10.0",
|
||||
"lodash": "^4.12.0",
|
||||
"lodash-compat": "^3.0.0",
|
||||
"promise": "^7.1.1"
|
||||
},
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var pkg = require('../package.json');
|
||||
var branches = pkg.config.supported_es_branches;
|
||||
var semver = require('semver');
|
||||
@ -47,10 +47,10 @@ Version.prototype.mergeOpts = function (opts) {
|
||||
return opts.filter(function (rule) {
|
||||
return self.satisfies(rule.version);
|
||||
})
|
||||
.map(_v4.ary(_v4.partialRight(_v4.omit, 'version'), 1))
|
||||
.concat(_v4.tail(arguments))
|
||||
.map(_.ary(_.partialRight(_.omit, 'version'), 1))
|
||||
.concat(_.tail(arguments))
|
||||
.reverse()
|
||||
.reduce(_v4.merge, {});
|
||||
.reduce(_.merge, {});
|
||||
};
|
||||
|
||||
module.exports = Version;
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
*******/
|
||||
|
||||
var Promise = require('bluebird');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var through2 = require('through2');
|
||||
var map = require('through2-map');
|
||||
var split = require('split');
|
||||
@ -30,7 +30,7 @@ var format = require('util').format;
|
||||
var NL_RE = /(\r?\n)/g;
|
||||
var ROOT = join(__dirname, '..');
|
||||
var GRUNT = join(ROOT, 'node_modules', '.bin', 'grunt');
|
||||
var ENV = _v4.clone(process.env);
|
||||
var ENV = _.clone(process.env);
|
||||
var JENKINS = !!ENV.JENKINS_HOME;
|
||||
var TASKS = [];
|
||||
|
||||
@ -80,7 +80,7 @@ task('SAUCE_LABS', false, function () {
|
||||
}));
|
||||
})
|
||||
// ignore server errors
|
||||
.catch(_v4.noop);
|
||||
.catch(_.noop);
|
||||
|
||||
// attempt to run tests on saucelabs and retry if it fails
|
||||
var saucelabsAttempts = 0;
|
||||
@ -116,7 +116,7 @@ task('SAUCE_LABS', false, function () {
|
||||
});
|
||||
})
|
||||
// swallow spawn() errors, custom error handler in place
|
||||
.catch(_v4.noop);
|
||||
.catch(_.noop);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -168,13 +168,13 @@ execTask('SETUP', function () {
|
||||
})
|
||||
.then(function readTasks() {
|
||||
if (!ENV.RUN) {
|
||||
return _v4.filter(TASKS, { default: true });
|
||||
return _.filter(TASKS, { default: true });
|
||||
}
|
||||
|
||||
return ENV.RUN
|
||||
.split(',')
|
||||
.map(function (name) {
|
||||
return _v4.find(TASKS, { name: name.trim() });
|
||||
return _.find(TASKS, { name: name.trim() });
|
||||
})
|
||||
.filter(Boolean);
|
||||
});
|
||||
@ -218,7 +218,7 @@ function logImportant(text) {
|
||||
|
||||
function push(m) {
|
||||
return function () {
|
||||
var args = _v4.toArray(arguments);
|
||||
var args = _.toArray(arguments);
|
||||
var cb = args.pop();
|
||||
this.push(m.apply(this, args));
|
||||
cb();
|
||||
@ -235,7 +235,7 @@ function indent() {
|
||||
}
|
||||
|
||||
function task(name, def, fn) {
|
||||
if (_v4.isFunction(def)) {
|
||||
if (_.isFunction(def)) {
|
||||
fn = def;
|
||||
def = true;
|
||||
}
|
||||
@ -248,7 +248,7 @@ function task(name, def, fn) {
|
||||
}
|
||||
|
||||
function execTask(name, task) {
|
||||
if (_v4.isObject(name)) {
|
||||
if (_.isObject(name)) {
|
||||
task = name.fn;
|
||||
name = name.name;
|
||||
}
|
||||
@ -316,13 +316,13 @@ function spawn(file, args, block) {
|
||||
function node(/* args... */) {
|
||||
return spawn(
|
||||
process.execPath,
|
||||
_v4.toArray(arguments)
|
||||
_.toArray(arguments)
|
||||
);
|
||||
}
|
||||
|
||||
function grunt(/* args... */) {
|
||||
return spawn(
|
||||
GRUNT,
|
||||
_v4.toArray(arguments)
|
||||
_.toArray(arguments)
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
module.exports = function (done) {
|
||||
// var _ = require('../../src/lib/utils');
|
||||
var _ = require('../../src/lib/utils');
|
||||
var utils = require('../../grunt/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _v4.partial(require('path').join, require('find-root')(__dirname));
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
var write = require('fs').writeFileSync;
|
||||
|
||||
var nodeApiIndex = fromRoot('src/lib/apis/index.js');
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
module.exports = function (done) {
|
||||
// var _ = require('../../src/lib/utils');
|
||||
var _ = require('../../src/lib/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _v4.partial(require('path').join, require('find-root')(__dirname));
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
var write = require('fs').writeFile;
|
||||
|
||||
var outputPath = fromRoot('docs/configuration.asciidoc');
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
module.exports = function (done) {
|
||||
// var _ = require('../../src/lib/utils');
|
||||
var _ = require('../../src/lib/utils');
|
||||
var utils = require('../../grunt/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _v4.partial(require('path').join, require('find-root')(__dirname));
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
var write = require('fs').writeFile;
|
||||
|
||||
var outputPath = fromRoot('docs/index.asciidoc');
|
||||
|
||||
@ -30,7 +30,7 @@ var argv = require('optimist')
|
||||
var path = require('path');
|
||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
||||
var utils = require(fromRoot('grunt/utils'));
|
||||
// var _ = require(fromRoot('src/lib/utils'));
|
||||
var _ = require(fromRoot('src/lib/utils'));
|
||||
var esUrl = 'https://github.com/elastic/elasticsearch.git';
|
||||
var branches;
|
||||
|
||||
@ -56,10 +56,10 @@ var paths = {
|
||||
docsIndex: fromRoot('docs/index.asciidoc'),
|
||||
apiSrc: 'src/lib/apis',
|
||||
getArchiveDir: function (branch) {
|
||||
return fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch));
|
||||
return fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||
},
|
||||
getArchiveTarball: function (branch) {
|
||||
return fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch) + '.tar');
|
||||
return fromRoot('src/_elasticsearch_' + _.snakeCase(branch) + '.tar');
|
||||
},
|
||||
getSpecPathInRepo: function (branch) {
|
||||
return /^v?(master|[2-9]\.)/.test(branch) ? 'rest-api-spec/src/main/resources/rest-api-spec' : 'rest-api-spec';
|
||||
@ -93,9 +93,9 @@ function dirRegex(dir, regexp) {
|
||||
}
|
||||
|
||||
function dirOpts(dir, opts) {
|
||||
opts = _v4.isArray(opts) ? opts : [opts];
|
||||
opts = _.isArray(opts) ? opts : [opts];
|
||||
return dirFilter(dir, function (name) {
|
||||
return _v4.includes(opts, name);
|
||||
return _.includes(opts, name);
|
||||
});
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ function fetchBranchesStep() {
|
||||
function findGeneratedApiFiles() {
|
||||
var anyApiMethodDocs = /^(configuration|index|api_methods).*\.asciidoc$/;
|
||||
var anyApiJsFiled = /^.+\.js$/;
|
||||
var allBranches = _v4.isEqual(branches, utils.branches);
|
||||
var allBranches = _.isEqual(branches, utils.branches);
|
||||
|
||||
if (allBranches) {
|
||||
return [
|
||||
@ -140,7 +140,7 @@ function findGeneratedApiFiles() {
|
||||
}
|
||||
|
||||
return branches.reduce(function (files, branch) {
|
||||
var b = _v4.snakeCase(branch);
|
||||
var b = _.snakeCase(branch);
|
||||
|
||||
files.push(dirOpts(paths.docs, 'api_methods_' + b + '.asciidoc'));
|
||||
|
||||
@ -166,7 +166,7 @@ function clearGeneratedFiles() {
|
||||
|
||||
generatedFiles.push(dirRegex(paths.src, esArchives));
|
||||
|
||||
var rmSteps = _v4.chain(generatedFiles)
|
||||
var rmSteps = _.chain(generatedFiles)
|
||||
.flattenDeep()
|
||||
.uniq()
|
||||
.map(function (path) {
|
||||
@ -195,7 +195,7 @@ function createArchive(branch) {
|
||||
var dir = paths.getArchiveDir(branch);
|
||||
var tarball = paths.getArchiveTarball(branch);
|
||||
var specPathInRepo = paths.getSpecPathInRepo(branch);
|
||||
var subDirCount = _v4.countBy(specPathInRepo, _v4.partial(_v4.eq, '/')).true || 0;
|
||||
var subDirCount = _.countBy(specPathInRepo, _.partial(_.eq, '/')).true || 0;
|
||||
|
||||
if (isDirectory(dir)) {
|
||||
console.log(branch + ' archive already exists');
|
||||
@ -227,7 +227,7 @@ var steps = [
|
||||
].filter(Boolean);
|
||||
|
||||
branches.forEach(function (branch) {
|
||||
steps.push(_v4.partial(async.series, [
|
||||
steps.push(_.partial(async.series, [
|
||||
removePrevArchive(branch),
|
||||
createArchive(branch),
|
||||
generateStep(branch)
|
||||
|
||||
@ -3,7 +3,7 @@ module.exports = function (branch, done) {
|
||||
* Read the API actions form the rest-api-spec repo.
|
||||
* @type {[type]}
|
||||
*/
|
||||
// var _ = require('../../src/lib/utils');
|
||||
var _ = require('../../src/lib/utils');
|
||||
var utils = require('../../grunt/utils');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
@ -19,7 +19,7 @@ module.exports = function (branch, done) {
|
||||
var docVars; // slightly modified clone of apiSpec for the docs
|
||||
|
||||
var branchSuffix = utils.branchSuffix(branch);
|
||||
var esDir = fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch));
|
||||
var esDir = fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||
|
||||
var version = Version.fromBranch(branch);
|
||||
var overrides = version.mergeOpts(require('./overrides'), {
|
||||
@ -71,27 +71,27 @@ module.exports = function (branch, done) {
|
||||
});
|
||||
|
||||
// collect the namespaces from the action locations
|
||||
var namespaces = _v4.filter(_v4.map(actions, function (action) {
|
||||
var namespaces = _.filter(_.map(actions, function (action) {
|
||||
if (~action.location.indexOf('.')) {
|
||||
var path = action.location.split('.').slice(0, -1);
|
||||
_v4.pull(path, 'prototype');
|
||||
_.pull(path, 'prototype');
|
||||
return path.join('.');
|
||||
}
|
||||
}));
|
||||
|
||||
// seperate the proxy actions
|
||||
var groups = _v4.groupBy(actions, function (action) {
|
||||
var groups = _.groupBy(actions, function (action) {
|
||||
return action.proxy ? 'proxies' : 'normal';
|
||||
});
|
||||
|
||||
apiSpec = {
|
||||
actions: groups.normal || [],
|
||||
proxies: groups.proxies || [],
|
||||
namespaces: _v4.uniq(namespaces.sort()),
|
||||
namespaces: _.uniq(namespaces.sort()),
|
||||
clientActionModifier: overrides.clientActionModifier
|
||||
};
|
||||
|
||||
var create = _v4.assign({}, _v4.find(apiSpec.actions, { name: 'index' }), {
|
||||
var create = _.assign({}, _.find(apiSpec.actions, { name: 'index' }), {
|
||||
name: 'create',
|
||||
location: 'create',
|
||||
proxy: 'index',
|
||||
@ -119,7 +119,7 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
function writeApiFile(done) {
|
||||
var outputPath = fromRoot('src/lib/apis/' + _v4.snakeCase(branch) + '.js');
|
||||
var outputPath = fromRoot('src/lib/apis/' + _.snakeCase(branch) + '.js');
|
||||
fs.writeFileSync(outputPath, templates.apiFile(apiSpec));
|
||||
console.log(chalk.white.bold('wrote'), apiSpec.actions.length, 'api actions to', outputPath);
|
||||
done();
|
||||
@ -145,8 +145,8 @@ module.exports = function (branch, done) {
|
||||
// merge the actions and proxies to make
|
||||
// itteration easir and keep them in order
|
||||
|
||||
docVars = _v4.omit(apiSpec, 'proxies');
|
||||
docVars.actions = _v4.sortBy(
|
||||
docVars = _.omit(apiSpec, 'proxies');
|
||||
docVars.actions = _.sortBy(
|
||||
[].concat(apiSpec.actions).concat(apiSpec.proxies),
|
||||
'name'
|
||||
);
|
||||
@ -174,9 +174,9 @@ module.exports = function (branch, done) {
|
||||
var actions = [];
|
||||
|
||||
// itterate all of the specs within the file, should only be one
|
||||
_v4.each(spec, function (def, name) {
|
||||
_.each(spec, function (def, name) {
|
||||
// camelcase the name
|
||||
name = _v4.map(name.split('.'), _v4.camelCase).join('.');
|
||||
name = _.map(name.split('.'), _.camelCase).join('.');
|
||||
|
||||
if (name === 'cat.aliases') {
|
||||
def.documentation = 'http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat.html';
|
||||
@ -185,23 +185,23 @@ module.exports = function (branch, done) {
|
||||
var steps = name.split('.');
|
||||
|
||||
function transformParamKeys(note, param, key) {
|
||||
var cmlKey = _v4.camelCase(key);
|
||||
var cmlKey = _.camelCase(key);
|
||||
if (cmlKey !== key) {
|
||||
param.name = key;
|
||||
}
|
||||
note[cmlKey] = param;
|
||||
}
|
||||
|
||||
def.url.params = _v4.transform(def.url.params, transformParamKeys, {});
|
||||
def.url.parts = _v4.transform(def.url.parts, transformParamKeys, {});
|
||||
def.url.params = _.transform(def.url.params, transformParamKeys, {});
|
||||
def.url.parts = _.transform(def.url.parts, transformParamKeys, {});
|
||||
|
||||
var allParams = _v4.extend({}, def.url.params, def.url.parts);
|
||||
var allParams = _.extend({}, def.url.params, def.url.parts);
|
||||
var spec = {
|
||||
name: name,
|
||||
methods: _v4.map(def.methods, function (m) { return m.toUpperCase(); }),
|
||||
methods: _.map(def.methods, function (m) { return m.toUpperCase(); }),
|
||||
params: def.url.params,
|
||||
body: def.body || null,
|
||||
path2lib: _v4.repeat('../', steps.length + 1) + 'lib/'
|
||||
path2lib: _.repeat('../', steps.length + 1) + 'lib/'
|
||||
};
|
||||
|
||||
if (def.body && def.body.required) {
|
||||
@ -216,9 +216,9 @@ module.exports = function (branch, done) {
|
||||
spec.requestTimeout = 3000;
|
||||
}
|
||||
|
||||
var urls = _v4.difference(def.url.paths, overrides.aliases[name]);
|
||||
var urls = _.difference(def.url.paths, overrides.aliases[name]);
|
||||
var urlSignatures = [];
|
||||
urls = _v4.map(urls, function (url) {
|
||||
urls = _.map(urls, function (url) {
|
||||
var optionalVars = {};
|
||||
var requiredVars = {};
|
||||
var param;
|
||||
@ -231,47 +231,47 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
while (match = urlParamRE.exec(url)) {
|
||||
name = _v4.camelCase(match[1]);
|
||||
name = _.camelCase(match[1]);
|
||||
param = def.url.parts[name] || {};
|
||||
target = (param.required || !param.default) ? requiredVars : optionalVars;
|
||||
target[name] = _v4.omit(param, 'required', 'description', 'name');
|
||||
target[name] = _.omit(param, 'required', 'description', 'name');
|
||||
}
|
||||
|
||||
urlSignatures.push(_v4.union(_v4.keys(optionalVars), _v4.keys(requiredVars)).sort().join(':'));
|
||||
urlSignatures.push(_.union(_.keys(optionalVars), _.keys(requiredVars)).sort().join(':'));
|
||||
|
||||
return _v4.omitBy({
|
||||
return _.omitBy({
|
||||
fmt: url.replace(urlParamRE, function (full, match) {
|
||||
return '<%=' + _v4.camelCase(match) + '%>';
|
||||
return '<%=' + _.camelCase(match) + '%>';
|
||||
}),
|
||||
opt: _v4.size(optionalVars) ? optionalVars : null,
|
||||
req: _v4.size(requiredVars) ? requiredVars : null,
|
||||
sortOrder: _v4.size(requiredVars) * -1
|
||||
opt: _.size(optionalVars) ? optionalVars : null,
|
||||
req: _.size(requiredVars) ? requiredVars : null,
|
||||
sortOrder: _.size(requiredVars) * -1
|
||||
}, function (v) {
|
||||
return !v;
|
||||
});
|
||||
});
|
||||
|
||||
if (urlSignatures.length !== _v4.uniq(urlSignatures).length) {
|
||||
if (urlSignatures.length !== _.uniq(urlSignatures).length) {
|
||||
throw new Error(
|
||||
'Multiple URLS with the same signature detected for ' +
|
||||
spec.name +
|
||||
'\n' +
|
||||
_v4.map(urls, 'fmt').join('\n') +
|
||||
_.map(urls, 'fmt').join('\n') +
|
||||
'\n'
|
||||
);
|
||||
}
|
||||
|
||||
if (urls.length > 1) {
|
||||
spec.urls = _v4.map(_v4.sortBy(urls, 'sortOrder'), function (url) {
|
||||
return _v4.omit(url, 'sortOrder');
|
||||
spec.urls = _.map(_.sortBy(urls, 'sortOrder'), function (url) {
|
||||
return _.omit(url, 'sortOrder');
|
||||
});
|
||||
} else {
|
||||
spec.url = _v4.omit(urls[0], 'sortOrder');
|
||||
spec.url = _.omit(urls[0], 'sortOrder');
|
||||
}
|
||||
|
||||
spec.params = _v4.transform(spec.params, function (note, param, name) {
|
||||
spec.params = _.transform(spec.params, function (note, param, name) {
|
||||
// param.name = name;
|
||||
note[name] = _v4.pick(param, [
|
||||
note[name] = _.pick(param, [
|
||||
'type', 'default', 'options', 'required', 'name'
|
||||
]);
|
||||
}, {});
|
||||
@ -280,7 +280,7 @@ module.exports = function (branch, done) {
|
||||
spec.paramAsBody = overrides.paramAsBody[name];
|
||||
}
|
||||
|
||||
if (_v4.size(spec.params) === 0) {
|
||||
if (_.size(spec.params) === 0) {
|
||||
delete spec.params;
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ module.exports = function (branch, done) {
|
||||
|
||||
var action = {
|
||||
_methods: spec.methods,
|
||||
spec: _v4.pick(spec, [
|
||||
spec: _.pick(spec, [
|
||||
'params',
|
||||
'url',
|
||||
'urls',
|
||||
|
||||
@ -9,21 +9,21 @@ var api = module.exports = {};
|
||||
|
||||
api._namespaces = <%= stringify(namespaces) %>;<%
|
||||
|
||||
_v4.each(actions, function (action) {
|
||||
_.each(actions, function (action) {
|
||||
var namespace = action.location.split('.').shift();
|
||||
if (_.includes(namespaces, namespace)) {
|
||||
_v4.pull(namespaces, namespace);
|
||||
_.pull(namespaces, namespace);
|
||||
%>
|
||||
|
||||
api.<%= namespace %> = namespace();<%
|
||||
}%>
|
||||
|
||||
<%= _v4.trimEnd(partials.client_action(action)) %><%
|
||||
<%= _.trimEnd(partials.client_action(action)) %><%
|
||||
|
||||
});
|
||||
|
||||
_v4.each(proxies, function (action) {%>
|
||||
_.each(proxies, function (action) {%>
|
||||
|
||||
<%= _v4.trimEnd(partials.client_action_proxy(action)) %><%
|
||||
<%= _.trimEnd(partials.client_action_proxy(action)) %><%
|
||||
});
|
||||
%>
|
||||
|
||||
@ -2,7 +2,7 @@ module.exports = {
|
||||
<%
|
||||
|
||||
branches.forEach(function (branch, i, list) {
|
||||
var req = "require('./" + _v4.snakeCase(branch) + "')";
|
||||
var req = "require('./" + _.snakeCase(branch) + "')";
|
||||
if (branch === utils.branches._default) {
|
||||
print(" '_default': " + req + ',\n');
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ NOTE: This is currently the default API, but in upcoming versions that will chan
|
||||
NOTE: At this time, you must opt into the <%= branch %> API by setting the `apiVersion` config parameter.
|
||||
<% }
|
||||
|
||||
actions = _v4.sortBy(actions, 'namespace');
|
||||
_v4.each(actions, function (action) {
|
||||
actions = _.sortBy(actions, 'namespace');
|
||||
_.each(actions, function (action) {
|
||||
action.index = 'api-' + action.name.toLowerCase().replace(/[^\w]+/g, '-') + branchSuffix;
|
||||
|
||||
%>
|
||||
@ -27,16 +27,16 @@ The default method is `<%= action.spec.method || 'GET' %>` and the usual <<api-c
|
||||
|
||||
<%= action.examples %>
|
||||
|
||||
<% if (_v4.size(action.allParams)) { %>
|
||||
<% if (_.size(action.allParams)) { %>
|
||||
*Params*
|
||||
|
||||
[horizontal]<%
|
||||
_v4.each(action.allParams, function (param, paramName) { %>
|
||||
_.each(action.allParams, function (param, paramName) { %>
|
||||
`<%= paramWithDefault(paramName, param.default) %>`::
|
||||
`<%= paramType(param.type) %>` -- <%= joinParagraphs(param.description || '', 4) %><%
|
||||
if (param.type === 'enum') {%>
|
||||
Options:::<%
|
||||
_v4.each(param.options, function (opt) {%>
|
||||
_.each(param.options, function (opt) {%>
|
||||
* `"<%= opt %>"`<%
|
||||
});%>
|
||||
<%
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Perform a [<%= name %>](<%= docUrl %>) request
|
||||
*
|
||||
* @param {Object} params - An object with parameters used to carry out this action<%
|
||||
_v4.each(allParams, function(param, paramName) { %>
|
||||
_.each(allParams, function(param, paramName) { %>
|
||||
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><%
|
||||
if (param.description) {
|
||||
%> - <%= param.description %><%
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Perform a [<%= name %>](<%= docUrl %>) request
|
||||
*
|
||||
* @param {Object} params - An object with parameters used to carry out this action<%
|
||||
_v4.each(allParams, function(param, paramName) { %>
|
||||
_.each(allParams, function(param, paramName) { %>
|
||||
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><%
|
||||
if (param.description) {
|
||||
%> - <%= param.description %><%
|
||||
|
||||
@ -303,7 +303,7 @@ var client = new elasticsearch.Client({
|
||||
selector: function (hosts) {
|
||||
var myCountry = process.env.COUNTRY;
|
||||
// first try to find a node that is in the same country
|
||||
var selection = _v4.find(nodes, function (node) {
|
||||
var selection = _.find(nodes, function (node) {
|
||||
return node.host.country === myCountry;
|
||||
});
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var utils = require('../../../grunt/utils');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
@ -41,10 +41,10 @@ var templateGlobals = {
|
||||
|
||||
stringify: stringify,
|
||||
|
||||
_v4: _v4,
|
||||
_: _,
|
||||
|
||||
indent: function (block, spaces) {
|
||||
var indent = _v4.repeat(' ', spaces);
|
||||
var indent = _.repeat(' ', spaces);
|
||||
return block.split('\n').map(function (line) {
|
||||
return indent + line;
|
||||
}).join('\n');
|
||||
@ -77,7 +77,7 @@ var templateGlobals = {
|
||||
case 'list':
|
||||
return 'String, String[], Boolean';
|
||||
default:
|
||||
return _v4.ucfirst(type);
|
||||
return _.ucfirst(type);
|
||||
}
|
||||
},
|
||||
|
||||
@ -97,7 +97,7 @@ var templateGlobals = {
|
||||
fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
||||
var name = filename.replace(/\..+$/, '');
|
||||
if (name !== 'index') {
|
||||
templates[name] = _v4.template(
|
||||
templates[name] = _.template(
|
||||
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
|
||||
{
|
||||
imports: templateGlobals
|
||||
|
||||
@ -8,10 +8,10 @@ module.exports = function (branch, done) {
|
||||
var chalk = require('chalk');
|
||||
var path = require('path');
|
||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
||||
// var _ = require(fromRoot('src/lib/utils'));
|
||||
var _ = require(fromRoot('src/lib/utils'));
|
||||
var tests = {}; // populated in readYamlTests
|
||||
|
||||
var esDir = fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch));
|
||||
var esDir = fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||
|
||||
// generate the yaml tests
|
||||
async.series([
|
||||
@ -43,14 +43,14 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
function writeYamlTests(done) {
|
||||
var testFile = fromRoot('test/integration/yaml_suite/yaml_tests_' + _v4.snakeCase(branch) + '.json');
|
||||
var testFile = fromRoot('test/integration/yaml_suite/yaml_tests_' + _.snakeCase(branch) + '.json');
|
||||
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
|
||||
console.log(chalk.white.bold('wrote') + ' YAML tests as JSON to', testFile);
|
||||
done();
|
||||
}
|
||||
|
||||
function writeTestIndex(done) {
|
||||
var file = fromRoot('test/integration/yaml_suite/index_' + _v4.snakeCase(branch) + '.js');
|
||||
var file = fromRoot('test/integration/yaml_suite/index_' + _.snakeCase(branch) + '.js');
|
||||
fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');\n', 'utf8');
|
||||
console.log(chalk.white.bold('wrote') + ' YAML index to', file);
|
||||
done();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var fs = require('fs');
|
||||
var spawn = require('../_spawn');
|
||||
var async = require('async');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
|
||||
var root = require('path').join(__dirname, '../..');
|
||||
var bowerDir = root + '/src/bower_es_js';
|
||||
@ -21,7 +21,7 @@ fs.writeFileSync(bowerDir + '/bower.json', JSON.stringify(bowerJson, null, ' ')
|
||||
fs.writeFileSync(bowerDir + '/package.json', JSON.stringify(bowerPackageJson, null, ' '));
|
||||
|
||||
function make(cmd, args) {
|
||||
return _v4.bind(spawn, null, cmd, args, {
|
||||
return _.bind(spawn, null, cmd, args, {
|
||||
verbose: true,
|
||||
cwd: bowerDir
|
||||
});
|
||||
@ -36,7 +36,7 @@ async.series([
|
||||
make('npm', ['publish'])
|
||||
], function (err) {
|
||||
if (err) {
|
||||
if (_v4.isNumber(err)) {
|
||||
if (_.isNumber(err)) {
|
||||
console.log('Non-zero exit code: %d', err);
|
||||
} else {
|
||||
console.log('Error: ', err.message ? err.message : err);
|
||||
|
||||
@ -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 = _;
|
||||
|
||||
10
test/fixtures/keepalive.js
vendored
10
test/fixtures/keepalive.js
vendored
@ -1,6 +1,6 @@
|
||||
var clock = require('sinon').useFakeTimers();
|
||||
var Client = require('../../src/elasticsearch').Client;
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var times = require('async').times;
|
||||
|
||||
process.once('message', function (port) {
|
||||
@ -20,9 +20,9 @@ process.once('message', function (port) {
|
||||
clock.tick(10);
|
||||
}, function (err) {
|
||||
var conns = es.transport.connectionPool._conns;
|
||||
var sockets = _v4([].concat(conns.dead, conns.alive))
|
||||
var sockets = _([].concat(conns.dead, conns.alive))
|
||||
.transform(function (sockets, conn) {
|
||||
sockets.push(_v4.values(conn.agent.sockets), _v4.values(conn.agent.freeSockets));
|
||||
sockets.push(_.values(conn.agent.sockets), _.values(conn.agent.freeSockets));
|
||||
}, [])
|
||||
.flattenDeep()
|
||||
.value();
|
||||
@ -31,8 +31,8 @@ process.once('message', function (port) {
|
||||
|
||||
var out = {
|
||||
socketCount: err || sockets.length,
|
||||
remaining: _v4.filter(sockets, { destroyed: true }).length - sockets.length,
|
||||
timeouts: _v4.size(clock.timers) && _v4.map(clock.timers, 'func').map(String)
|
||||
remaining: _.filter(sockets, { destroyed: true }).length - sockets.length,
|
||||
timeouts: _.size(clock.timers) && _.map(clock.timers, 'func').map(String)
|
||||
};
|
||||
|
||||
clock.restore();
|
||||
|
||||
@ -9,10 +9,10 @@ if (BROWSER) {
|
||||
es = require('../../../src/elasticsearch');
|
||||
}
|
||||
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var fromRoot = _v4.bindKey(path, 'join', require('find-root')(__dirname));
|
||||
var fromRoot = _.bindKey(path, 'join', require('find-root')(__dirname));
|
||||
var Bluebird = require('bluebird');
|
||||
|
||||
// current client
|
||||
@ -60,7 +60,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
var logConfig = {};
|
||||
if (_v4.has(options, 'logConfig')) {
|
||||
if (_.has(options, 'logConfig')) {
|
||||
logConfig = options.logConfig;
|
||||
} else {
|
||||
if (BROWSER) {
|
||||
@ -106,14 +106,14 @@ module.exports = {
|
||||
client.snapshot.getRepository({
|
||||
snapshot: '_all'
|
||||
})
|
||||
.then(_v4.keys)
|
||||
.then(_.keys)
|
||||
.map(function (repo) {
|
||||
return client.snapshot.get({
|
||||
repository: repo,
|
||||
snapshot: '_all'
|
||||
})
|
||||
.then(function (resp) {
|
||||
return _v4.map(resp.snapshots, 'snapshot');
|
||||
return _.map(resp.snapshots, 'snapshot');
|
||||
}, function () {
|
||||
return [];
|
||||
})
|
||||
@ -132,7 +132,7 @@ module.exports = {
|
||||
]);
|
||||
};
|
||||
|
||||
_v4.nextTick(cb);
|
||||
_.nextTick(cb);
|
||||
}
|
||||
},
|
||||
get: function () {
|
||||
|
||||
@ -4,7 +4,7 @@ module.exports = function (branch) {
|
||||
var YamlFile = require('./yaml_file');
|
||||
var root = require('find-root')(__dirname);
|
||||
var rootReq = function (loc) { return require(path.join(root, loc)); };
|
||||
// var _ = rootReq('src/lib/utils');
|
||||
var _ = rootReq('src/lib/utils');
|
||||
var utils = rootReq('grunt/utils');
|
||||
var es = rootReq('src/elasticsearch');
|
||||
var clientManager = require('./client_manager');
|
||||
@ -32,7 +32,7 @@ module.exports = function (branch) {
|
||||
return clientManager.get().clearEs();
|
||||
});
|
||||
|
||||
var files = _v4.map(require('./yaml_tests_' + _v4.snakeCase(branch) + '.json'), function (docs, filename) {
|
||||
var files = _.map(require('./yaml_tests_' + _.snakeCase(branch) + '.json'), function (docs, filename) {
|
||||
return new YamlFile(filename, docs);
|
||||
});
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
*/
|
||||
module.exports = YamlDoc;
|
||||
|
||||
// var _ = require('lodash-migrate/lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var clientManager = require('./client_manager');
|
||||
var inspect = require('util').inspect;
|
||||
@ -70,8 +70,8 @@ function versionToComparableString(version, def) {
|
||||
return def;
|
||||
}
|
||||
|
||||
var parts = _v4.map(version.split('.'), function (part) {
|
||||
part = '' + _v4.parseInt(part);
|
||||
var parts = _.map(version.split('.'), function (part) {
|
||||
part = '' + _.parseInt(part);
|
||||
return (new Array(Math.max(4 - part.length, 0))).join('0') + part;
|
||||
});
|
||||
|
||||
@ -109,26 +109,26 @@ function YamlDoc(doc, file) {
|
||||
var self = this;
|
||||
|
||||
self.file = file;
|
||||
self.description = _v4.keys(doc).shift();
|
||||
self.description = _.keys(doc).shift();
|
||||
self._stash = {};
|
||||
self._last_requests_response = null;
|
||||
|
||||
// setup the actions, creating a bound and testable method for each
|
||||
self._actions = _v4.map(self.flattenTestActions(doc[self.description]), function (action) {
|
||||
self._actions = _.map(self.flattenTestActions(doc[self.description]), function (action) {
|
||||
// get the method that will do the action
|
||||
var method = self['do_' + action.name];
|
||||
|
||||
// check that it's a function
|
||||
expect(method || 'YamlDoc#' + action.name).to.be.a('function');
|
||||
|
||||
if (_v4.isPlainObject(action.args)) {
|
||||
if (_.isPlainObject(action.args)) {
|
||||
action.name += '(' + JSON.stringify(action.args) + ')';
|
||||
} else if (action.args) {
|
||||
action.name += '(' + action.args + ')';
|
||||
}
|
||||
|
||||
// wrap in a check for skipping
|
||||
action.bound = _v4.bind(method, self, action.args);
|
||||
action.bound = _.bind(method, self, action.args);
|
||||
|
||||
// create a function that can be passed to mocha or async
|
||||
action.testable = function (_cb) {
|
||||
@ -199,15 +199,15 @@ YamlDoc.prototype = {
|
||||
flattenTestActions: function (config) {
|
||||
// creates [ [ {name:"", args:"" }, ... ], ... ]
|
||||
// from [ {name:args, name:args}, {name:args} ]
|
||||
var actionSets = _v4.map(config, function (set) {
|
||||
return _v4.map(_v4.toPairs(set), function (pair) {
|
||||
var actionSets = _.map(config, function (set) {
|
||||
return _.map(_.toPairs(set), function (pair) {
|
||||
return { name: pair[0], args: pair[1] };
|
||||
});
|
||||
});
|
||||
|
||||
// do a single level flatten, merge=ing the nested arrays from step one
|
||||
// into a master array, creating an array of action objects
|
||||
return _v4.reduce(actionSets, function (note, set) {
|
||||
return _.reduce(actionSets, function (note, set) {
|
||||
return note.concat(set);
|
||||
}, []);
|
||||
},
|
||||
@ -273,7 +273,7 @@ YamlDoc.prototype = {
|
||||
|
||||
log('getting', path, 'from', from);
|
||||
|
||||
var steps = _v4.map(path ? path.replace(/\\\./g, '\uffff').split('.') : [], function (step) {
|
||||
var steps = _.map(path ? path.replace(/\\\./g, '\uffff').split('.') : [], function (step) {
|
||||
return step.replace(/\uffff/g, '.');
|
||||
});
|
||||
var remainingSteps;
|
||||
@ -301,7 +301,7 @@ YamlDoc.prototype = {
|
||||
*/
|
||||
do_skip: function (args, done) {
|
||||
if (args.version) {
|
||||
return rangeMatchesCurrentVersion(args.version, _v4.bind(function (match) {
|
||||
return rangeMatchesCurrentVersion(args.version, _.bind(function (match) {
|
||||
if (match) {
|
||||
if (this.description === 'setup') {
|
||||
this.file.skipping = true;
|
||||
@ -320,7 +320,7 @@ YamlDoc.prototype = {
|
||||
|
||||
if (args.features) {
|
||||
var features = Array.isArray(args.features) ? args.features : [args.features];
|
||||
var notImplemented = _v4.difference(features, implementedFeatures);
|
||||
var notImplemented = _.difference(features, implementedFeatures);
|
||||
|
||||
if (notImplemented.length) {
|
||||
if (this.description === 'setup') {
|
||||
@ -396,25 +396,25 @@ YamlDoc.prototype = {
|
||||
delete args.headers;
|
||||
}
|
||||
|
||||
var otherKeys = _v4.keys(args);
|
||||
var otherKeys = _.keys(args);
|
||||
var action = otherKeys.shift();
|
||||
if (otherKeys.length) {
|
||||
return done(new TypeError('Unexpected top-level args to "do": ' + otherKeys.join(', ')));
|
||||
}
|
||||
|
||||
var client = clientManager.get();
|
||||
var clientActionName = _v4.map(action.split('.'), _v4.camelCase).join('.');
|
||||
var clientActionName = _.map(action.split('.'), _.camelCase).join('.');
|
||||
var clientAction = this.get(clientActionName, client);
|
||||
_v4.assign(inputParams, args[action]);
|
||||
_.assign(inputParams, args[action]);
|
||||
|
||||
var params = _v4.transform(inputParams, _v4.bind(function (params, val, name) {
|
||||
var camelName = _v4.camelCase(name);
|
||||
var params = _.transform(inputParams, _.bind(function (params, val, name) {
|
||||
var camelName = _.camelCase(name);
|
||||
|
||||
// search through the params and url peices to find this param name
|
||||
var paramName = name;
|
||||
var spec = clientAction && clientAction.spec;
|
||||
var knownParam = spec && spec.params && spec.params[camelName];
|
||||
var knownUrlParam = spec && !knownParam && !!_v4.find(spec.url ? [spec.url] : spec.urls, function (url) {
|
||||
var knownUrlParam = spec && !knownParam && !!_.find(spec.url ? [spec.url] : spec.urls, function (url) {
|
||||
if ((url.opt && url.opt[camelName]) || (url.req && url.req[camelName])) {
|
||||
return true;
|
||||
}
|
||||
@ -427,10 +427,10 @@ YamlDoc.prototype = {
|
||||
|
||||
// for ercursively traversing the params to replace '$stashed' vars
|
||||
var transformObject = function (vals, val, i) {
|
||||
if (_v4.isString(val)) {
|
||||
if (_.isString(val)) {
|
||||
val = (val[0] === '$') ? this.get(val) : val;
|
||||
} else if (_v4.isPlainObject(val) || _v4.isArray(val)) {
|
||||
val = _v4.transform(val, transformObject);
|
||||
} else if (_.isPlainObject(val) || _.isArray(val)) {
|
||||
val = _.transform(val, transformObject);
|
||||
}
|
||||
|
||||
vals[i] = val;
|
||||
@ -443,12 +443,12 @@ YamlDoc.prototype = {
|
||||
expect(clientAction || clientActionName).to.be.a('function');
|
||||
|
||||
if (!isNaN(parseFloat(catcher))) {
|
||||
params.ignore = _v4.union(params.ignore || [], [catcher]);
|
||||
params.ignore = _.union(params.ignore || [], [catcher]);
|
||||
catcher = null;
|
||||
}
|
||||
|
||||
var timeoutId;
|
||||
var cb = _v4.bind(function (error, body) {
|
||||
var cb = _.bind(function (error, body) {
|
||||
this._last_requests_response = body;
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
@ -494,7 +494,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_set: function (args) {
|
||||
_v4.forOwn(args, _v4.bind(function (name, path) {
|
||||
_.forOwn(args, _.bind(function (name, path) {
|
||||
this._stash[name] = this.get(path);
|
||||
}, this));
|
||||
},
|
||||
@ -566,25 +566,25 @@ YamlDoc.prototype = {
|
||||
var self = this;
|
||||
|
||||
// recursively replace all $var within args
|
||||
_v4.forOwn(args, function recurse(val, key, lvl) {
|
||||
if (_v4.isObject(val)) {
|
||||
return _v4.each(val, recurse);
|
||||
_.forOwn(args, function recurse(val, key, lvl) {
|
||||
if (_.isObject(val)) {
|
||||
return _.each(val, recurse);
|
||||
}
|
||||
|
||||
if (_v4.isString(val)) {
|
||||
if (_.isString(val)) {
|
||||
lvl[key] = val.replace(/\$[a-zA-Z0-9_]+/g, function (name) {
|
||||
return self.get(name);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
_v4.forOwn(args, _v4.bind(function (match, path) {
|
||||
_.forOwn(args, _.bind(function (match, path) {
|
||||
var origMatch = match;
|
||||
|
||||
var maybeRE = false;
|
||||
var usedRE = false;
|
||||
|
||||
if (_v4.isString(match)) {
|
||||
if (_.isString(match)) {
|
||||
// convert the matcher into a compatible string for building a regexp
|
||||
maybeRE = match
|
||||
// replace comments, but allow the # to be escaped like \#
|
||||
@ -655,7 +655,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_lt: function (args) {
|
||||
_v4.forOwn(args, _v4.bind(function (num, path) {
|
||||
_.forOwn(args, _.bind(function (num, path) {
|
||||
expect(this.get(path)).to.be.below(num, 'path: ' + path);
|
||||
}, this));
|
||||
},
|
||||
@ -667,7 +667,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_lte: function (args) {
|
||||
_v4.forOwn(args, _v4.bind(function (num, path) {
|
||||
_.forOwn(args, _.bind(function (num, path) {
|
||||
expect(this.get(path) <= num).to.be.ok('path: ' + path);
|
||||
}, this));
|
||||
},
|
||||
@ -679,7 +679,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_gt: function (args) {
|
||||
_v4.forOwn(args, _v4.bind(function (num, path) {
|
||||
_.forOwn(args, _.bind(function (num, path) {
|
||||
expect(this.get(path)).to.be.above(num, 'path: ' + path);
|
||||
}, this));
|
||||
},
|
||||
@ -691,7 +691,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_gte: function (args) {
|
||||
_v4.forOwn(args, _v4.bind(function (num, path) {
|
||||
_.forOwn(args, _.bind(function (num, path) {
|
||||
expect(this.get(path) >= num).to.be.ok('path: ' + path);
|
||||
}, this));
|
||||
},
|
||||
@ -704,8 +704,8 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_length: function (args) {
|
||||
_v4.forOwn(args, _v4.bind(function (len, path) {
|
||||
expect(_v4.size(this.get(path))).to.eql(len, 'path: ' + path);
|
||||
_.forOwn(args, _.bind(function (len, path) {
|
||||
expect(_.size(this.get(path))).to.eql(len, 'path: ' + path);
|
||||
}, this));
|
||||
}
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@ module.exports = YamlFile;
|
||||
|
||||
var YamlDoc = require('./yaml_doc');
|
||||
var clientManager = require('./client_manager');
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var async = require('async');
|
||||
|
||||
function YamlFile(filename, docs) {
|
||||
@ -18,7 +18,7 @@ function YamlFile(filename, docs) {
|
||||
file.skipping = false;
|
||||
|
||||
describe(filename, function () {
|
||||
file.docs = _v4.map(docs, function (doc) {
|
||||
file.docs = _.map(docs, function (doc) {
|
||||
doc = new YamlDoc(doc, file);
|
||||
if (doc.description === 'setup') {
|
||||
beforeEach(/* doc */function (done) {
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
module.exports = MockHttpRequest;
|
||||
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
|
||||
function MockHttpRequest() {
|
||||
// These are internal flags and data structures
|
||||
@ -221,7 +221,7 @@ MockHttpRequest.prototype = {
|
||||
|
||||
getAllResponseHeaders: function () {
|
||||
var r = '';
|
||||
_v4.each(this.responseHeaders, function (header) {
|
||||
_.each(this.responseHeaders, function (header) {
|
||||
if ((header === 'set-cookie') || (header === 'set-cookie2')) {
|
||||
return;
|
||||
}
|
||||
@ -353,7 +353,7 @@ MockHttpRequest.prototype = {
|
||||
|
||||
this.responseText = null;
|
||||
this.error = true;
|
||||
_v4.each(this.requestHeaders, function (header) {
|
||||
_.each(this.requestHeaders, function (header) {
|
||||
delete this.requestHeaders[header];
|
||||
}, this);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ var complete = [];
|
||||
var MockHttpRequest = require('./browser_http');
|
||||
var XhrServer = MockHttpRequest.MockHttpServer;
|
||||
var parseUrl = MockHttpRequest.prototype.parseUri;
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
|
||||
var server = new XhrServer(function (request) {
|
||||
var reqDetails = {
|
||||
@ -11,7 +11,7 @@ var server = new XhrServer(function (request) {
|
||||
host: request.urlParts.host,
|
||||
path: request.urlParts.relative
|
||||
};
|
||||
var response = _v4.find(interceptors, reqDetails);
|
||||
var response = _.find(interceptors, reqDetails);
|
||||
|
||||
if (response) {
|
||||
// remove of tick down the times
|
||||
|
||||
6
test/unit/browser_builds/angular.js
vendored
6
test/unit/browser_builds/angular.js
vendored
@ -1,5 +1,5 @@
|
||||
/* global angular */
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var Promise = require('bluebird');
|
||||
var sinon = require('sinon');
|
||||
@ -17,13 +17,13 @@ describe('Angular esFactory', function () {
|
||||
|
||||
function bootstrap(env) {
|
||||
beforeEach(function () {
|
||||
var promiseProvider = _v4.noop;
|
||||
var promiseProvider = _.noop;
|
||||
if (env.bluebirdPromises) {
|
||||
promiseProvider = function ($provide) {
|
||||
$provide.service('$q', function () {
|
||||
return {
|
||||
defer: function () {
|
||||
return _v4.bindAll(Promise.defer(), ['resolve', 'reject']);
|
||||
return _.bindAll(Promise.defer(), ['resolve', 'reject']);
|
||||
},
|
||||
reject: Promise.reject,
|
||||
when: Promise.resolve,
|
||||
|
||||
@ -3,7 +3,7 @@ module.exports = function (makeLogger) {
|
||||
var stub = require('../utils/auto_release_stub').make();
|
||||
var fs = require('fs');
|
||||
var once = require('events').EventEmitter.prototype.once;
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
|
||||
describe('buffer flush', function () {
|
||||
if (require('stream').Writable) {
|
||||
@ -21,7 +21,7 @@ module.exports = function (makeLogger) {
|
||||
var logger = makeLogger();
|
||||
|
||||
// write the line 10 times
|
||||
_v4.times(10, function () {
|
||||
_.times(10, function () {
|
||||
logger.onDebug(line);
|
||||
});
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var ca = require('../../../src/lib/client_action').factory;
|
||||
var proxy = require('../../../src/lib/client_action').proxyFactory;
|
||||
var expect = require('expect.js');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ function makeClientAction(spec) {
|
||||
};
|
||||
}
|
||||
|
||||
return _v4.bind(ca(spec), mockClient());
|
||||
return _.bind(ca(spec), mockClient());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +55,7 @@ function makeClientAction(spec) {
|
||||
* @return {Function} - the clientActionProxy
|
||||
*/
|
||||
function makeClientActionProxy(fn, spec) {
|
||||
return _v4.bind(proxy(fn, spec || {}), mockClient());
|
||||
return _.bind(proxy(fn, spec || {}), mockClient());
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ describe('Client Action runner', function () {
|
||||
afterEach(function () { _stash = {}; });
|
||||
var make = function (params) {
|
||||
_stash.orig = params;
|
||||
_stash.copy = _v4.clone(params);
|
||||
_stash.copy = _.clone(params);
|
||||
return params;
|
||||
};
|
||||
make.check = function () {
|
||||
@ -118,7 +118,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
it('handles passing just the callback', function () {
|
||||
var action = makeClientActionProxy(function (params, cb) {
|
||||
expect(_v4.isObject(params)).to.be.ok();
|
||||
expect(_.isObject(params)).to.be.ok();
|
||||
expect(cb).to.be.a('function');
|
||||
});
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var sinon = require('sinon');
|
||||
var expect = require('expect.js');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
@ -73,10 +73,10 @@ describe('Connection Abstract', function () {
|
||||
|
||||
stub(conn, 'request');
|
||||
|
||||
expect(_v4.size(clock.timers)).to.eql(0);
|
||||
expect(_.size(clock.timers)).to.eql(0);
|
||||
conn.ping();
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
expect(clock.timers[_v4.keys(clock.timers).shift()].delay).to.eql(5000);
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
expect(clock.timers[_.keys(clock.timers).shift()].delay).to.eql(5000);
|
||||
});
|
||||
|
||||
it('calls it\'s own request method', function () {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var ConnectionPool = require('../../../src/lib/connection_pool');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
@ -36,10 +36,10 @@ describe('Connection Pool', function () {
|
||||
});
|
||||
|
||||
it('#addConnection only adds the connection if it doesn\'t already exist', function () {
|
||||
expect(_v4.keys(pool.index).length).to.eql(0);
|
||||
expect(_.keys(pool.index).length).to.eql(0);
|
||||
pool.addConnection(connection);
|
||||
|
||||
expect(_v4.keys(pool.index)).to.eql([host.toString()]);
|
||||
expect(_.keys(pool.index)).to.eql([host.toString()]);
|
||||
|
||||
expect(pool._conns.alive).to.eql([connection]);
|
||||
expect(pool._conns.dead).to.eql([]);
|
||||
@ -52,7 +52,7 @@ describe('Connection Pool', function () {
|
||||
|
||||
expect(pool._conns.alive).to.eql([connection]);
|
||||
expect(pool._conns.dead).to.eql([]);
|
||||
expect(_v4.keys(pool.index).length).to.eql(1);
|
||||
expect(_.keys(pool.index).length).to.eql(1);
|
||||
});
|
||||
|
||||
it('closes the connection when it removes it', function () {
|
||||
@ -175,10 +175,10 @@ describe('Connection Pool', function () {
|
||||
new ConnectionAbstract(new Host('http://localhost:9202')),
|
||||
new ConnectionAbstract(new Host('http://localhost:9203'))
|
||||
];
|
||||
var pingQueue = _v4.shuffle(connections);
|
||||
var pingQueue = _.shuffle(connections);
|
||||
var expectedSelection = pingQueue[pingQueue.length - 1];
|
||||
|
||||
_v4.each(pingQueue, function (conn) {
|
||||
_.each(pingQueue, function (conn) {
|
||||
pool.addConnection(conn);
|
||||
stub(conn, 'ping', function (params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
@ -247,13 +247,13 @@ describe('Connection Pool', function () {
|
||||
stub.autoRelease(clock);
|
||||
|
||||
connection.setStatus('dead');
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
var id = _v4(clock.timers).keys().first();
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
var id = _(clock.timers).keys().first();
|
||||
|
||||
// it re-dies
|
||||
connection.setStatus('dead');
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
expect(_v4(clock.timers).keys().first()).to.not.eql(id);
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
expect(_(clock.timers).keys().first()).to.not.eql(id);
|
||||
});
|
||||
|
||||
it('does nothing when a connection is re-alive', function () {
|
||||
@ -295,7 +295,7 @@ describe('Connection Pool', function () {
|
||||
|
||||
var result = pool.getConnections();
|
||||
expect(result.length).to.be(1000);
|
||||
expect(_v4.reduce(result, function (sum, num) {
|
||||
expect(_.reduce(result, function (sum, num) {
|
||||
sum += num
|
||||
return sum;
|
||||
}, 0)).to.eql(499500);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
var errors = require('../../../src/lib/errors');
|
||||
var expect = require('expect.js');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
|
||||
_v4.each(errors, function (CustomError, name) {
|
||||
_.each(errors, function (CustomError, name) {
|
||||
if (name.charAt(0) !== '_') {
|
||||
describe(name, function () {
|
||||
it('extend the ErrorAbstract and Error classes', function () {
|
||||
|
||||
@ -2,7 +2,7 @@ describe('File Logger', function () {
|
||||
var Log = require('../../../src/lib/log');
|
||||
var FileLogger = require('../../../src/lib/loggers/file');
|
||||
var once = require('events').EventEmitter.prototype.once;
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var parentLog;
|
||||
var logger;
|
||||
var expect = require('expect.js');
|
||||
@ -15,7 +15,7 @@ describe('File Logger', function () {
|
||||
|
||||
afterEach(function () {
|
||||
parentLog.close();
|
||||
logger && _v4.clearWriteStreamBuffer(logger.stream);
|
||||
logger && _.clearWriteStreamBuffer(logger.stream);
|
||||
});
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
@ -49,7 +49,7 @@ describe('File Logger', function () {
|
||||
var logger = makeLogger();
|
||||
|
||||
// write the line 10 times
|
||||
_v4.times(10, function () {
|
||||
_.times(10, function () {
|
||||
logger.onDebug(line);
|
||||
});
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
var Host = require('../../../src/lib/host');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var url = require('url');
|
||||
var expectSubObject = require('../../utils/expect_sub_object');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
describe('Http Connector', function () {
|
||||
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var nock = require('nock');
|
||||
var sinon = require('sinon');
|
||||
@ -67,12 +67,12 @@ describe('Http Connector', function () {
|
||||
|
||||
it('allows defining a custom agent', function () {
|
||||
var football = {};
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _v4.constant(football) });
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _.constant(football) });
|
||||
expect(con.agent).to.be(football);
|
||||
});
|
||||
|
||||
it('allows setting agent to false', function () {
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _v4.constant(false) });
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _.constant(false) });
|
||||
expect(con.agent).to.be(false);
|
||||
});
|
||||
});
|
||||
@ -482,7 +482,7 @@ describe('Http Connector', function () {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
var cp = require('child_process');
|
||||
var path = require('path');
|
||||
var fixture = _v4.partial(path.join, __dirname, '../../fixtures');
|
||||
var fixture = _.partial(path.join, __dirname, '../../fixtures');
|
||||
var timeout; // start the timeout once we hear back from the client
|
||||
|
||||
var server = cp.fork(fixture('keepalive_server.js'))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
var Log = require('../../../src/lib/log');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
|
||||
describe('Log class', function () {
|
||||
@ -129,11 +129,11 @@ describe('Log class', function () {
|
||||
log: [
|
||||
{
|
||||
type: function (log, config) {
|
||||
log.on('error', _v4.noop);
|
||||
log.on('warning', _v4.noop);
|
||||
log.on('info', _v4.noop);
|
||||
log.on('debug', _v4.noop);
|
||||
log.on('trace', _v4.noop);
|
||||
log.on('error', _.noop);
|
||||
log.on('warning', _.noop);
|
||||
log.on('info', _.noop);
|
||||
log.on('debug', _.noop);
|
||||
log.on('trace', _.noop);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
describe('Random Selector', function () {
|
||||
var randomSelector = require('../../../src/lib/selectors/random');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
|
||||
it('chooses a selection by random', function () {
|
||||
var log = { a: 0, b: 0, c: 0 };
|
||||
var choices = _v4.keys(log);
|
||||
var choices = _.keys(log);
|
||||
|
||||
_v4.times(1000, function () {
|
||||
_.times(1000, function () {
|
||||
var choice = randomSelector(choices);
|
||||
log[choice]++;
|
||||
});
|
||||
|
||||
expect(_v4.filter(log, function (count) {
|
||||
expect(_.filter(log, function (count) {
|
||||
return count < 200 || count > 400;
|
||||
})).to.have.length(0);
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
describe('Round Robin Selector', function () {
|
||||
var selector = require('../../../src/lib/selectors/round_robin');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
|
||||
it('chooses options in order', function () {
|
||||
var options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
||||
var expected = _v4.clone(options);
|
||||
var expected = _.clone(options);
|
||||
var selections = [];
|
||||
|
||||
_v4.times(options.length, function () {
|
||||
_.times(options.length, function () {
|
||||
selections.push(selector(options));
|
||||
});
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ describe('Stream Logger', function () {
|
||||
var MockWritableStream = require('../../mocks/writable_stream');
|
||||
var once = require('events').EventEmitter.prototype.once;
|
||||
var stream = new MockWritableStream();
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var expect = require('expect.js');
|
||||
var parentLog;
|
||||
|
||||
@ -19,7 +19,7 @@ describe('Stream Logger', function () {
|
||||
|
||||
afterEach(function () {
|
||||
parentLog.close();
|
||||
_v4.clearWriteStreamBuffer(stream);
|
||||
_.clearWriteStreamBuffer(stream);
|
||||
});
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
@ -41,13 +41,13 @@ describe('Stream Logger', function () {
|
||||
|
||||
// get the last handler for process's "exit" event
|
||||
var exitHandlers = process._events.exit;
|
||||
var exitHandler = _v4.isArray(exitHandlers) ? _v4.last(exitHandlers) : exitHandlers;
|
||||
var exitHandler = _.isArray(exitHandlers) ? _.last(exitHandlers) : exitHandlers;
|
||||
|
||||
// allow the logger to acctually write to the stream
|
||||
stream.write.restore();
|
||||
|
||||
// write the line 10 times
|
||||
_v4.times(10, function () {
|
||||
_.times(10, function () {
|
||||
logger.onDebug(line);
|
||||
});
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ var errors = require('../../../src/lib/errors');
|
||||
|
||||
var sinon = require('sinon');
|
||||
var expect = require('expect.js');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var nodeList = require('../../fixtures/short_node_list.json');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
@ -83,11 +83,11 @@ describe('Transport Class', function () {
|
||||
sniffInterval: 25000
|
||||
});
|
||||
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
var id = _v4.keys(clock.timers).pop();
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
var id = _.keys(clock.timers).pop();
|
||||
clock.tick(25000);
|
||||
expect(trans.sniff.callCount).to.eql(1);
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
expect(clock.timers).to.not.have.key(id);
|
||||
|
||||
});
|
||||
@ -285,25 +285,25 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('randomizeHosts options', function () {
|
||||
it('calls _.shuffle be default', function () {
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
stub(_v4, 'shuffle');
|
||||
stub(_, 'shuffle');
|
||||
var trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
expect(_v4.shuffle.callCount).to.eql(1);
|
||||
expect(_.shuffle.callCount).to.eql(1);
|
||||
});
|
||||
it('skips the call to _.shuffle when false', function () {
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
stub(_v4, 'shuffle');
|
||||
stub(_, 'shuffle');
|
||||
var trans = new Transport({
|
||||
hosts: 'localhost',
|
||||
randomizeHosts: false
|
||||
});
|
||||
|
||||
expect(_v4.shuffle.callCount).to.eql(0);
|
||||
expect(_.shuffle.callCount).to.eql(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -606,7 +606,7 @@ describe('Transport Class', function () {
|
||||
}
|
||||
|
||||
var trans = new Transport({
|
||||
hosts: _v4.map(new Array(retries + 1), function (val, i) {
|
||||
hosts: _.map(new Array(retries + 1), function (val, i) {
|
||||
return 'localhost/' + i;
|
||||
}),
|
||||
maxRetries: retries,
|
||||
@ -617,8 +617,8 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
// trigger a select so that we can harvest the connection list
|
||||
trans.connectionPool.select(_v4.noop);
|
||||
_v4.each(connections, function (conn) {
|
||||
trans.connectionPool.select(_.noop);
|
||||
_.each(connections, function (conn) {
|
||||
stub(conn, 'request', failRequest);
|
||||
});
|
||||
|
||||
@ -632,7 +632,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
};
|
||||
}
|
||||
it('retries when there are retries remaining', testRetries(_v4.random(25, 40)));
|
||||
it('retries when there are retries remaining', testRetries(_.random(25, 40)));
|
||||
it('responds when there are no retries', testRetries(0));
|
||||
});
|
||||
|
||||
@ -641,7 +641,7 @@ describe('Transport Class', function () {
|
||||
it('returns an object with an abort() method when a callback is sent', function () {
|
||||
var tran = new Transport();
|
||||
shortCircuitRequest(tran);
|
||||
var ret = tran.request({}, _v4.noop);
|
||||
var ret = tran.request({}, _.noop);
|
||||
expect(ret).to.be.a('object');
|
||||
expect(ret.abort).to.be.a('function');
|
||||
});
|
||||
@ -651,7 +651,7 @@ describe('Transport Class', function () {
|
||||
var ret = tran.request({});
|
||||
expect(ret.then).to.be.a('function');
|
||||
expect(ret.abort).to.be.a('function');
|
||||
ret.then(_v4.noop, _v4.noop); // prevent complaining from bluebird
|
||||
ret.then(_.noop, _.noop); // prevent complaining from bluebird
|
||||
});
|
||||
it('promise is always pulled from the defer created by this.defer()', function () {
|
||||
var fakePromise = {};
|
||||
@ -659,8 +659,8 @@ describe('Transport Class', function () {
|
||||
var tran = new Transport({
|
||||
defer: function () {
|
||||
return {
|
||||
resolve: _v4.noop,
|
||||
reject: _v4.noop,
|
||||
resolve: _.noop,
|
||||
reject: _.noop,
|
||||
promise: fakePromise
|
||||
};
|
||||
}
|
||||
@ -759,10 +759,10 @@ describe('Transport Class', function () {
|
||||
|
||||
var prom = tran.request({});
|
||||
// disregard promise, prevent bluebird's warnings
|
||||
prom.then(_v4.noop, _v4.noop);
|
||||
prom.then(_.noop, _.noop);
|
||||
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
_v4.each(clock.timers, function (timer, id) {
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
_.each(clock.timers, function (timer, id) {
|
||||
expect(timer.callAt).to.eql(30000);
|
||||
clearTimeout(id);
|
||||
});
|
||||
@ -776,17 +776,17 @@ describe('Transport Class', function () {
|
||||
|
||||
var prom = tran.request({});
|
||||
// disregard promise, prevent bluebird's warnings
|
||||
prom.then(_v4.noop, _v4.noop);
|
||||
prom.then(_.noop, _.noop);
|
||||
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
_v4.each(clock.timers, function (timer, id) {
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
_.each(clock.timers, function (timer, id) {
|
||||
expect(timer.callAt).to.eql(5000);
|
||||
clearTimeout(id);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
_v4.each([false, 0, null], function (falsy) {
|
||||
_.each([false, 0, null], function (falsy) {
|
||||
it('skips the timeout when it is ' + falsy, function () {
|
||||
var clock = sinon.useFakeTimers();
|
||||
stub.autoRelease(clock);
|
||||
@ -797,7 +797,7 @@ describe('Transport Class', function () {
|
||||
requestTimeout: falsy
|
||||
}, function () {});
|
||||
|
||||
expect(_v4.size(clock.timers)).to.eql(0);
|
||||
expect(_.size(clock.timers)).to.eql(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -7,7 +7,7 @@ var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var nock = require('../../mocks/server.js');
|
||||
var through2 = require('through2');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var nodeList = require('../../fixtures/short_node_list.json');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
@ -277,7 +277,7 @@ describe('Transport + Mock server', function () {
|
||||
expect(err).to.be(undefined);
|
||||
expect(resp).to.eql({ i: 'am here' });
|
||||
expect(status).to.eql(200);
|
||||
expect(_v4.keys(clock.timers)).to.have.length(0);
|
||||
expect(_.keys(clock.timers)).to.have.length(0);
|
||||
clock.restore();
|
||||
});
|
||||
});
|
||||
@ -342,9 +342,9 @@ describe('Transport + Mock server', function () {
|
||||
.catch(function (err) {
|
||||
expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1);
|
||||
expect(tran.sniff.callCount).to.eql(0);
|
||||
expect(_v4.size(clock.timers)).to.eql(1);
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
|
||||
var timeout = _v4.values(clock.timers).pop();
|
||||
var timeout = _.values(clock.timers).pop();
|
||||
timeout.func();
|
||||
expect(tran.sniff.callCount).to.eql(1);
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// var _ = require('../../../src/lib/utils');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var expect = require('expect.js');
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
@ -6,7 +6,7 @@ var stub = require('../../utils/auto_release_stub').make();
|
||||
describe('Utils', function () {
|
||||
|
||||
describe('Additional Type Checkers', function () {
|
||||
_v4.forEach({
|
||||
_.forEach({
|
||||
Object: {
|
||||
is: [[], /regexp/]
|
||||
},
|
||||
@ -34,66 +34,66 @@ describe('Utils', function () {
|
||||
function (thing, name) {
|
||||
describe('#isArrayOf' + name, function () {
|
||||
it('likes arrays of ' + name, function () {
|
||||
expect(_v4['isArrayOf' + name + 's'](thing.is)).to.be(true);
|
||||
expect(_['isArrayOf' + name + 's'](thing.is)).to.be(true);
|
||||
});
|
||||
|
||||
it('dislikes when there is even one non ' + name, function () {
|
||||
// notice a string in the array
|
||||
thing.is.push(thing.not || ' not ');
|
||||
expect(_v4['isArrayOf' + name + 's'](thing.is)).to.be(false);
|
||||
expect(_['isArrayOf' + name + 's'](thing.is)).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isNumeric', function () {
|
||||
it('likes integer literals', function () {
|
||||
expect(_v4.isNumeric('-10')).to.be(true);
|
||||
expect(_v4.isNumeric('0')).to.be(true);
|
||||
expect(_v4.isNumeric('5')).to.be(true);
|
||||
expect(_v4.isNumeric(-16)).to.be(true);
|
||||
expect(_v4.isNumeric(0)).to.be(true);
|
||||
expect(_v4.isNumeric(32)).to.be(true);
|
||||
expect(_v4.isNumeric('040')).to.be(true);
|
||||
expect(_v4.isNumeric('0xFF')).to.be(true);
|
||||
expect(_v4.isNumeric(0xFFF)).to.be(true);
|
||||
expect(_.isNumeric('-10')).to.be(true);
|
||||
expect(_.isNumeric('0')).to.be(true);
|
||||
expect(_.isNumeric('5')).to.be(true);
|
||||
expect(_.isNumeric(-16)).to.be(true);
|
||||
expect(_.isNumeric(0)).to.be(true);
|
||||
expect(_.isNumeric(32)).to.be(true);
|
||||
expect(_.isNumeric('040')).to.be(true);
|
||||
expect(_.isNumeric('0xFF')).to.be(true);
|
||||
expect(_.isNumeric(0xFFF)).to.be(true);
|
||||
});
|
||||
|
||||
it('likes float literals', function () {
|
||||
expect(_v4.isNumeric('-1.6')).to.be(true);
|
||||
expect(_v4.isNumeric('4.536')).to.be(true);
|
||||
expect(_v4.isNumeric(-2.6)).to.be(true);
|
||||
expect(_v4.isNumeric(3.1415)).to.be(true);
|
||||
expect(_v4.isNumeric(8e5)).to.be(true);
|
||||
expect(_v4.isNumeric('123e-2')).to.be(true);
|
||||
expect(_.isNumeric('-1.6')).to.be(true);
|
||||
expect(_.isNumeric('4.536')).to.be(true);
|
||||
expect(_.isNumeric(-2.6)).to.be(true);
|
||||
expect(_.isNumeric(3.1415)).to.be(true);
|
||||
expect(_.isNumeric(8e5)).to.be(true);
|
||||
expect(_.isNumeric('123e-2')).to.be(true);
|
||||
});
|
||||
|
||||
it('dislikes non-numeric stuff', function () {
|
||||
expect(_v4.isNumeric('')).to.be(false);
|
||||
expect(_v4.isNumeric(' ')).to.be(false);
|
||||
expect(_v4.isNumeric('\t\t')).to.be(false);
|
||||
expect(_v4.isNumeric('abcdefghijklm1234567890')).to.be(false);
|
||||
expect(_v4.isNumeric('xabcdefx')).to.be(false);
|
||||
expect(_v4.isNumeric(true)).to.be(false);
|
||||
expect(_v4.isNumeric(false)).to.be(false);
|
||||
expect(_v4.isNumeric('bcfed5.2')).to.be(false);
|
||||
expect(_v4.isNumeric('7.2acdgs')).to.be(false);
|
||||
expect(_v4.isNumeric(undefined)).to.be(false);
|
||||
expect(_v4.isNumeric(null)).to.be(false);
|
||||
expect(_v4.isNumeric(NaN)).to.be(false);
|
||||
expect(_v4.isNumeric(Infinity)).to.be(false);
|
||||
expect(_v4.isNumeric(Number.POSITIVE_INFINITY)).to.be(false);
|
||||
expect(_v4.isNumeric(Number.NEGATIVE_INFINITY)).to.be(false);
|
||||
expect(_v4.isNumeric(new Date(2009, 1, 1))).to.be(false);
|
||||
expect(_v4.isNumeric([])).to.be(false);
|
||||
expect(_v4.isNumeric([1, 2, 3, 4])).to.be(false);
|
||||
expect(_v4.isNumeric({})).to.be(false);
|
||||
expect(_v4.isNumeric(function () {})).to.be(false);
|
||||
expect(_.isNumeric('')).to.be(false);
|
||||
expect(_.isNumeric(' ')).to.be(false);
|
||||
expect(_.isNumeric('\t\t')).to.be(false);
|
||||
expect(_.isNumeric('abcdefghijklm1234567890')).to.be(false);
|
||||
expect(_.isNumeric('xabcdefx')).to.be(false);
|
||||
expect(_.isNumeric(true)).to.be(false);
|
||||
expect(_.isNumeric(false)).to.be(false);
|
||||
expect(_.isNumeric('bcfed5.2')).to.be(false);
|
||||
expect(_.isNumeric('7.2acdgs')).to.be(false);
|
||||
expect(_.isNumeric(undefined)).to.be(false);
|
||||
expect(_.isNumeric(null)).to.be(false);
|
||||
expect(_.isNumeric(NaN)).to.be(false);
|
||||
expect(_.isNumeric(Infinity)).to.be(false);
|
||||
expect(_.isNumeric(Number.POSITIVE_INFINITY)).to.be(false);
|
||||
expect(_.isNumeric(Number.NEGATIVE_INFINITY)).to.be(false);
|
||||
expect(_.isNumeric(new Date(2009, 1, 1))).to.be(false);
|
||||
expect(_.isNumeric([])).to.be(false);
|
||||
expect(_.isNumeric([1, 2, 3, 4])).to.be(false);
|
||||
expect(_.isNumeric({})).to.be(false);
|
||||
expect(_.isNumeric(function () {})).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('#isInterval', function () {
|
||||
_v4.forEach({
|
||||
_.forEach({
|
||||
M: 'months',
|
||||
w: 'weeks',
|
||||
d: 'days',
|
||||
@ -104,20 +104,20 @@ describe('Utils', function () {
|
||||
},
|
||||
function (name, unit) {
|
||||
it('likes ' + name, function () {
|
||||
expect(_v4.isInterval('1' + unit)).to.be(true);
|
||||
expect(_.isInterval('1' + unit)).to.be(true);
|
||||
});
|
||||
|
||||
it('likes decimal ' + name, function () {
|
||||
expect(_v4.isInterval('1.5' + unit)).to.be(true);
|
||||
expect(_.isInterval('1.5' + unit)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('dislikes more than one unit', function () {
|
||||
expect(_v4.isInterval('1my')).to.be(false);
|
||||
expect(_.isInterval('1my')).to.be(false);
|
||||
});
|
||||
|
||||
it('dislikes spaces', function () {
|
||||
expect(_v4.isInterval('1 m')).to.be(false);
|
||||
expect(_.isInterval('1 m')).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -127,108 +127,108 @@ describe('Utils', function () {
|
||||
|
||||
describe('#camelCase', function () {
|
||||
it('find spaces, underscores, and other natural word breaks', function () {
|
||||
expect(_v4.camelCase('Neil Patrick.Harris-is_a.dog')).to.eql('neilPatrickHarrisIsADog');
|
||||
expect(_.camelCase('Neil Patrick.Harris-is_a.dog')).to.eql('neilPatrickHarrisIsADog');
|
||||
});
|
||||
|
||||
it('ignores abreviations', function () {
|
||||
expect(_v4.camelCase('Json_parser')).to.eql('jsonParser');
|
||||
expect(_.camelCase('Json_parser')).to.eql('jsonParser');
|
||||
});
|
||||
|
||||
it('handles leading _', function () {
|
||||
expect(_v4.camelCase('_thing_one_')).to.eql('_thingOne');
|
||||
expect(_.camelCase('_thing_one_')).to.eql('_thingOne');
|
||||
});
|
||||
|
||||
it('works on numbers', function () {
|
||||
expect(_v4.camelCase('version 1.0')).to.eql('version10');
|
||||
expect(_.camelCase('version 1.0')).to.eql('version10');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#studlyCase', function () {
|
||||
it('find spaces, underscores, and other natural word breaks', function () {
|
||||
expect(_v4.studlyCase('Neil Patrick.Harris-is_a.dog')).to.eql('NeilPatrickHarrisIsADog');
|
||||
expect(_.studlyCase('Neil Patrick.Harris-is_a.dog')).to.eql('NeilPatrickHarrisIsADog');
|
||||
});
|
||||
|
||||
it('ignores abreviations', function () {
|
||||
expect(_v4.studlyCase('Json_parser')).to.eql('JsonParser');
|
||||
expect(_.studlyCase('Json_parser')).to.eql('JsonParser');
|
||||
});
|
||||
|
||||
it('handles leading _', function () {
|
||||
expect(_v4.studlyCase('_thing_one_')).to.eql('_ThingOne');
|
||||
expect(_.studlyCase('_thing_one_')).to.eql('_ThingOne');
|
||||
});
|
||||
|
||||
it('works on numbers', function () {
|
||||
expect(_v4.studlyCase('version 1.0')).to.eql('Version10');
|
||||
expect(_.studlyCase('version 1.0')).to.eql('Version10');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#snakeCase', function () {
|
||||
it('find spaces, underscores, and other natural word breaks', function () {
|
||||
expect(_v4.snakeCase('Neil Patrick.Harris-is_a.dog')).to.eql('neil_patrick_harris_is_a_dog');
|
||||
expect(_.snakeCase('Neil Patrick.Harris-is_a.dog')).to.eql('neil_patrick_harris_is_a_dog');
|
||||
});
|
||||
|
||||
it('ignores abreviations', function () {
|
||||
expect(_v4.snakeCase('Json_parser')).to.eql('json_parser');
|
||||
expect(_.snakeCase('Json_parser')).to.eql('json_parser');
|
||||
});
|
||||
|
||||
it('handles leading _', function () {
|
||||
expect(_v4.snakeCase('_thing_one_')).to.eql('_thing_one');
|
||||
expect(_.snakeCase('_thing_one_')).to.eql('_thing_one');
|
||||
});
|
||||
|
||||
it('works on numbers', function () {
|
||||
expect(_v4.snakeCase('version 1.0')).to.eql('version_1_0');
|
||||
expect(_.snakeCase('version 1.0')).to.eql('version_1_0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toLowerString', function () {
|
||||
it('transforms normal strings', function () {
|
||||
expect(_v4.toLowerString('PASTA')).to.eql('pasta');
|
||||
expect(_.toLowerString('PASTA')).to.eql('pasta');
|
||||
});
|
||||
|
||||
it('ignores long form empty vals (null, false, undef)', function () {
|
||||
expect(_v4.toLowerString(null)).to.eql('');
|
||||
expect(_v4.toLowerString(false)).to.eql('');
|
||||
expect(_v4.toLowerString(void 0)).to.eql('');
|
||||
expect(_.toLowerString(null)).to.eql('');
|
||||
expect(_.toLowerString(false)).to.eql('');
|
||||
expect(_.toLowerString(void 0)).to.eql('');
|
||||
});
|
||||
|
||||
it('uses the objects own toString', function () {
|
||||
expect(_v4.toLowerString(['A', 'B'])).to.eql('a,b');
|
||||
expect(_.toLowerString(['A', 'B'])).to.eql('a,b');
|
||||
});
|
||||
|
||||
it('sorta kinda works on objects', function () {
|
||||
expect(_v4.toLowerString({ a: 'thing' })).to.eql('[object object]');
|
||||
expect(_.toLowerString({ a: 'thing' })).to.eql('[object object]');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toUpperString', function () {
|
||||
it('transforms normal strings', function () {
|
||||
expect(_v4.toUpperString('PASTA')).to.eql('PASTA');
|
||||
expect(_.toUpperString('PASTA')).to.eql('PASTA');
|
||||
});
|
||||
|
||||
it('ignores long form empty vals (null, false, undef)', function () {
|
||||
expect(_v4.toUpperString(null)).to.eql('');
|
||||
expect(_v4.toUpperString(false)).to.eql('');
|
||||
expect(_v4.toUpperString(void 0)).to.eql('');
|
||||
expect(_.toUpperString(null)).to.eql('');
|
||||
expect(_.toUpperString(false)).to.eql('');
|
||||
expect(_.toUpperString(void 0)).to.eql('');
|
||||
});
|
||||
|
||||
it('uses the objects own toString', function () {
|
||||
expect(_v4.toUpperString(['A', 'B'])).to.eql('A,B');
|
||||
expect(_.toUpperString(['A', 'B'])).to.eql('A,B');
|
||||
});
|
||||
|
||||
it('sorta kinda works on objects', function () {
|
||||
expect(_v4.toUpperString({ a: 'thing' })).to.eql('[OBJECT OBJECT]');
|
||||
expect(_.toUpperString({ a: 'thing' })).to.eql('[OBJECT OBJECT]');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#repeat', function () {
|
||||
it('repeats strings', function () {
|
||||
expect(_v4.repeat(' ', 5)).to.eql(' ');
|
||||
expect(_v4.repeat('foobar', 2)).to.eql('foobarfoobar');
|
||||
expect(_.repeat(' ', 5)).to.eql(' ');
|
||||
expect(_.repeat('foobar', 2)).to.eql('foobarfoobar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ucfirst', function () {
|
||||
it('only capitalized the first letter, lowercases everything else', function () {
|
||||
expect(_v4.ucfirst('ALGER')).to.eql('Alger');
|
||||
expect(_.ucfirst('ALGER')).to.eql('Alger');
|
||||
});
|
||||
});
|
||||
|
||||
@ -241,14 +241,14 @@ describe('Utils', function () {
|
||||
var obj = {
|
||||
foo: 'bar'
|
||||
};
|
||||
expect(_v4.deepMerge(obj, { bar: 'baz' })).to.eql(obj);
|
||||
expect(_.deepMerge(obj, { bar: 'baz' })).to.eql(obj);
|
||||
});
|
||||
|
||||
it('concats arrays', function () {
|
||||
var obj = {
|
||||
foo: ['bax', 'boz']
|
||||
};
|
||||
_v4.deepMerge(obj, { foo: ['boop'] });
|
||||
_.deepMerge(obj, { foo: ['boop'] });
|
||||
expect(obj.foo).to.have.length(3);
|
||||
});
|
||||
|
||||
@ -256,7 +256,7 @@ describe('Utils', function () {
|
||||
var obj = {
|
||||
foo: ['stop', 'foo', 'stahp']
|
||||
};
|
||||
_v4.deepMerge(obj, { foo: 'string' });
|
||||
_.deepMerge(obj, { foo: 'string' });
|
||||
expect(obj.foo).to.have.length(3);
|
||||
});
|
||||
|
||||
@ -267,7 +267,7 @@ describe('Utils', function () {
|
||||
foo: ['bax', 'boz']
|
||||
}
|
||||
};
|
||||
_v4.deepMerge(obj, { bax: { foo: ['poo'] } });
|
||||
_.deepMerge(obj, { bax: { foo: ['poo'] } });
|
||||
expect(obj.bax.foo).to.have.length(3);
|
||||
});
|
||||
|
||||
@ -276,26 +276,26 @@ describe('Utils', function () {
|
||||
describe('#createArray', function () {
|
||||
it('accepts an array of things and simply returns a copy of it', function () {
|
||||
var inp = [{ a: 1 }, 'pizza'];
|
||||
var out = _v4.createArray(inp);
|
||||
var out = _.createArray(inp);
|
||||
expect(out).to.eql(inp);
|
||||
expect(out).to.not.be(inp);
|
||||
});
|
||||
it('accepts a primitive value and calls the the transform function', function (done) {
|
||||
_v4.createArray('str', function (val) {
|
||||
_.createArray('str', function (val) {
|
||||
expect(val).to.be('str');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('wraps any non-array in an array', function () {
|
||||
expect(_v4.createArray({})).to.eql([{}]);
|
||||
expect(_v4.createArray('')).to.eql(['']);
|
||||
expect(_v4.createArray(123)).to.eql([123]);
|
||||
expect(_v4.createArray(/abc/)).to.eql([/abc/]);
|
||||
expect(_v4.createArray(false)).to.eql([false]);
|
||||
expect(_.createArray({})).to.eql([{}]);
|
||||
expect(_.createArray('')).to.eql(['']);
|
||||
expect(_.createArray(123)).to.eql([123]);
|
||||
expect(_.createArray(/abc/)).to.eql([/abc/]);
|
||||
expect(_.createArray(false)).to.eql([false]);
|
||||
});
|
||||
it('returns false when the transform function returns undefined', function () {
|
||||
expect(_v4.createArray(['str', 1], function (val) {
|
||||
if (_v4.isString(val)) {
|
||||
expect(_.createArray(['str', 1], function (val) {
|
||||
if (_.isString(val)) {
|
||||
return {
|
||||
val: val
|
||||
};
|
||||
@ -306,27 +306,27 @@ describe('Utils', function () {
|
||||
|
||||
describe('#funcEnum', function () {
|
||||
/*
|
||||
* _v4.funcEnum(object, key, opts, default);
|
||||
* _.funcEnum(object, key, opts, default);
|
||||
*/
|
||||
it('tests if the value at key in object is a function, returns it if so', function () {
|
||||
var config = {
|
||||
func: function () {}
|
||||
};
|
||||
expect(_v4.funcEnum(config, 'func', {}, 'toString'))
|
||||
expect(_.funcEnum(config, 'func', {}, 'toString'))
|
||||
.to.be(config.func);
|
||||
});
|
||||
it('tests if the value at key in object is undefined, returns the option at key default if so', function () {
|
||||
var config = {
|
||||
func: undefined
|
||||
};
|
||||
expect(_v4.funcEnum(config, 'func', {}, 'toString'))
|
||||
expect(_.funcEnum(config, 'func', {}, 'toString'))
|
||||
.to.be(Object.prototype.toString);
|
||||
});
|
||||
it('tests if the value at key in object is a string, returns the option at that key if so', function () {
|
||||
var config = {
|
||||
'config key name': 'toString'
|
||||
};
|
||||
expect(_v4.funcEnum(config, 'config key name', { toString: 'pizza' }, 'toJSON'))
|
||||
expect(_.funcEnum(config, 'config key name', { toString: 'pizza' }, 'toJSON'))
|
||||
.to.be('pizza');
|
||||
});
|
||||
it('throws an informative error if the selection if invalid', function () {
|
||||
@ -335,21 +335,21 @@ describe('Utils', function () {
|
||||
};
|
||||
|
||||
expect(function () {
|
||||
_v4.funcEnum(config, 'config', {});
|
||||
_.funcEnum(config, 'config', {});
|
||||
}).to.throwError(/expected a function/i);
|
||||
|
||||
expect(function () {
|
||||
_v4.funcEnum(config, 'config', { main: 'default' }, 'main');
|
||||
_.funcEnum(config, 'config', { main: 'default' }, 'main');
|
||||
}).to.throwError(/expected a function or main/i);
|
||||
|
||||
expect(function () {
|
||||
_v4.funcEnum(config, 'config', { main: 'default', other: 'default' }, 'main');
|
||||
_.funcEnum(config, 'config', { main: 'default', other: 'default' }, 'main');
|
||||
}).to.throwError(/expected a function or one of main, other/i);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#applyArgs', function () {
|
||||
_v4.times(10, function (i) {
|
||||
_.times(10, function (i) {
|
||||
var method = i > 5 ? 'apply' : 'call';
|
||||
var argCount = i + 1;
|
||||
var slice = 1;
|
||||
@ -358,8 +358,8 @@ describe('Utils', function () {
|
||||
var func = function () {};
|
||||
stub(func, method);
|
||||
|
||||
var args = _v4.map(new Array(i), function (val, i) { return i; });
|
||||
_v4.applyArgs(func, null, args);
|
||||
var args = _.map(new Array(i), function (val, i) { return i; });
|
||||
_.applyArgs(func, null, args);
|
||||
|
||||
expect(func[method].callCount).to.eql(1);
|
||||
if (method === 'apply') {
|
||||
@ -374,9 +374,9 @@ describe('Utils', function () {
|
||||
var func = function () {};
|
||||
stub(func, method);
|
||||
|
||||
var args = _v4.map(new Array(argCount), function (val, i) { return i; });
|
||||
var args = _.map(new Array(argCount), function (val, i) { return i; });
|
||||
var expected = args.slice(slice);
|
||||
_v4.applyArgs(func, null, args, slice);
|
||||
_.applyArgs(func, null, args, slice);
|
||||
|
||||
expect(func[method].callCount).to.eql(1);
|
||||
if (method === 'apply') {
|
||||
@ -390,24 +390,24 @@ describe('Utils', function () {
|
||||
|
||||
describe('#getUnwrittenFromStream', function () {
|
||||
it('ignores things that do not have writableState', function () {
|
||||
expect(_v4.getUnwrittenFromStream()).to.be(undefined);
|
||||
expect(_v4.getUnwrittenFromStream(false)).to.be(undefined);
|
||||
expect(_v4.getUnwrittenFromStream([])).to.be(undefined);
|
||||
expect(_v4.getUnwrittenFromStream({})).to.be(undefined);
|
||||
expect(_.getUnwrittenFromStream()).to.be(undefined);
|
||||
expect(_.getUnwrittenFromStream(false)).to.be(undefined);
|
||||
expect(_.getUnwrittenFromStream([])).to.be(undefined);
|
||||
expect(_.getUnwrittenFromStream({})).to.be(undefined);
|
||||
});
|
||||
|
||||
if (require('stream').Writable) {
|
||||
var MockWritableStream = require('../../mocks/writable_stream');
|
||||
it('ignores empty stream', function () {
|
||||
var stream = new MockWritableStream();
|
||||
expect(_v4.getUnwrittenFromStream(stream)).to.be('');
|
||||
expect(_.getUnwrittenFromStream(stream)).to.be('');
|
||||
});
|
||||
|
||||
it('returns only what is in the buffer', function () {
|
||||
var stream = new MockWritableStream();
|
||||
stream.write('hot');
|
||||
stream.write('dog');
|
||||
expect(_v4.getUnwrittenFromStream(stream)).to.be('dog');
|
||||
expect(_.getUnwrittenFromStream(stream)).to.be('dog');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
module.exports = function expectSubObject(obj, subObj) {
|
||||
_v4.forOwn(subObj, function (val, prop) {
|
||||
_.forOwn(subObj, function (val, prop) {
|
||||
if (typeof obj[prop] === 'object') {
|
||||
// non-strict equals
|
||||
expect(obj[prop]).to.eql(val, 'Expected property' + prop + ' of object to equal ' + val);
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
module.exports = JenkinsReporter;
|
||||
|
||||
var Base = require('mocha/lib/reporters/base');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
var makeJUnitXml = require('./make_j_unit_xml');
|
||||
var fs = require('fs');
|
||||
@ -15,7 +15,7 @@ var path = require('path');
|
||||
var inspect = require('util').inspect;
|
||||
|
||||
var log = (function () {
|
||||
var locked = _v4.bind(process.stdout.write, process.stdout);
|
||||
var locked = _.bind(process.stdout.write, process.stdout);
|
||||
return function (str) {
|
||||
if (typeof str !== 'string') {
|
||||
str = inspect(str);
|
||||
@ -24,8 +24,8 @@ var log = (function () {
|
||||
};
|
||||
}());
|
||||
|
||||
var integration = _v4.find(process.argv, function (arg) { return arg.indexOf('test/integration') > -1; });
|
||||
var unit = _v4.find(process.argv, function (arg) { return arg.indexOf('test/unit') > -1; });
|
||||
var integration = _.find(process.argv, function (arg) { return arg.indexOf('test/integration') > -1; });
|
||||
var unit = _.find(process.argv, function (arg) { return arg.indexOf('test/unit') > -1; });
|
||||
var output;
|
||||
|
||||
if (unit) {
|
||||
@ -126,7 +126,7 @@ function JenkinsReporter(runner) {
|
||||
errMsg += '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
|
||||
}
|
||||
|
||||
console.error(_v4.map(errMsg.split('\n'), function (line) {
|
||||
console.error(_.map(errMsg.split('\n'), function (line) {
|
||||
return indt() + ' ' + line;
|
||||
}).join('\n'));
|
||||
}
|
||||
@ -146,7 +146,7 @@ function JenkinsReporter(runner) {
|
||||
|
||||
runner.on('hook end', function (hook) {
|
||||
if (hook.title.indexOf('"after each"') > -1 && stack[0] && stack[0].results.length) {
|
||||
var result = _v4.last(stack[0].results);
|
||||
var result = _.last(stack[0].results);
|
||||
result.stdout += stack[0].stdout;
|
||||
result.stderr += stack[0].stderr;
|
||||
stack[0].stdout = stack[0].stderr = '';
|
||||
@ -157,7 +157,7 @@ function JenkinsReporter(runner) {
|
||||
restoreStdio();
|
||||
var xml = makeJUnitXml('node ' + process.version, {
|
||||
stats: stats,
|
||||
suites: _v4.map(rootSuite.suites, function removeElements(suite) {
|
||||
suites: _.map(rootSuite.suites, function removeElements(suite) {
|
||||
var s = {
|
||||
name: suite.name,
|
||||
start: suite.start,
|
||||
@ -168,7 +168,7 @@ function JenkinsReporter(runner) {
|
||||
};
|
||||
|
||||
if (suite.suites) {
|
||||
s.suites = _v4.map(suite.suites, removeElements);
|
||||
s.suites = _.map(suite.suites, removeElements);
|
||||
}
|
||||
return s;
|
||||
})
|
||||
|
||||
@ -28,11 +28,11 @@ var testXml = require('xmlbuilder');
|
||||
var suites = testXml.create('testsuites');
|
||||
var suiteCount = 0;
|
||||
var moment = require('moment');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
|
||||
function makeJUnitXml(runnerName, testDetails) {
|
||||
_v4.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
||||
_.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
||||
|
||||
var suite = suites.ele('testsuite', {
|
||||
package: 'elasticsearch-js',
|
||||
@ -41,12 +41,12 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
timestamp: moment(suiteInfo.start).toJSON(),
|
||||
hostname: 'localhost',
|
||||
tests: (suiteInfo.results && suiteInfo.results.length) || 0,
|
||||
failures: _v4.filter(suiteInfo.results, { pass: false }).length,
|
||||
failures: _.filter(suiteInfo.results, { pass: false }).length,
|
||||
errors: 0,
|
||||
time: suiteInfo.time / 1000
|
||||
});
|
||||
|
||||
_v4.each(suiteInfo.results, function (testInfo) {
|
||||
_.each(suiteInfo.results, function (testInfo) {
|
||||
var section;
|
||||
var integration = false;
|
||||
|
||||
@ -83,7 +83,7 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
});
|
||||
|
||||
if (suiteInfo.suites) {
|
||||
_v4.each(suiteInfo.suites, serializeSuite);
|
||||
_.each(suiteInfo.suites, serializeSuite);
|
||||
}
|
||||
|
||||
giveOutput(suite, suiteInfo);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
var express = require('express');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
// var _ = require('lodash');
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var root = require('path').join(__dirname, '../..');
|
||||
var browserify = require('browserify');
|
||||
@ -12,7 +12,7 @@ var browserBuildsDir = root + '/test/unit/browser_builds';
|
||||
|
||||
var testFiles = {};
|
||||
|
||||
testFiles.unit = _v4(fs.readdirSync(unitSpecDir))
|
||||
testFiles.unit = _(fs.readdirSync(unitSpecDir))
|
||||
.difference([
|
||||
'file_logger.js',
|
||||
'http_connector.js',
|
||||
|
||||
Reference in New Issue
Block a user