and finally, return to standard mo
This commit is contained in:
@ -315,7 +315,7 @@ var client = new elasticsearch.Client({
|
|||||||
selector: function (hosts) {
|
selector: function (hosts) {
|
||||||
var myCountry = process.env.COUNTRY;
|
var myCountry = process.env.COUNTRY;
|
||||||
// first try to find a node that is in the same 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;
|
return node.host.country === myCountry;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ var client = new elasticsearch.Client({
|
|||||||
selector: function (hosts) {
|
selector: function (hosts) {
|
||||||
var myCountry = process.env.COUNTRY;
|
var myCountry = process.env.COUNTRY;
|
||||||
// first try to find a node that is in the same 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;
|
return node.host.country === myCountry;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var fromRoot = require('path').join.bind(null, __dirname, '..', '..');
|
var fromRoot = require('path').join.bind(null, __dirname, '..', '..');
|
||||||
|
|
||||||
var release = process.env.ES_RELEASE;
|
var release = process.env.ES_RELEASE;
|
||||||
var ref = process.env.ES_REF;
|
var ref = process.env.ES_REF;
|
||||||
var port = parseFloat(_v4.get(process.env, 'ES_PORT', 9400));
|
var port = parseFloat(_.get(process.env, 'ES_PORT', 9400));
|
||||||
var host = _v4.get(process.env, 'ES_HOST', 'localhost');
|
var host = _.get(process.env, 'ES_HOST', 'localhost');
|
||||||
|
|
||||||
var Version = require('../../scripts/Version');
|
var Version = require('../../scripts/Version');
|
||||||
var versionedOpts = [
|
var versionedOpts = [
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var root = require('find-root')(__dirname);
|
var root = require('find-root')(__dirname);
|
||||||
var rel = require('path').resolve.bind(null, root);
|
var rel = require('path').resolve.bind(null, root);
|
||||||
var rootReq = function (p) { return require(rel(p)); };
|
var rootReq = function (p) { return require(rel(p)); };
|
||||||
// var _ = rootReq('src/lib/utils');
|
var _ = rootReq('src/lib/utils');
|
||||||
var grunt = require('grunt');
|
var grunt = require('grunt');
|
||||||
|
|
||||||
var JENKINS_REPORTER = rel('test/utils/jenkins-reporter.js');
|
var JENKINS_REPORTER = rel('test/utils/jenkins-reporter.js');
|
||||||
@ -65,7 +65,7 @@ var config = {
|
|||||||
grunt.registerTask('mocha_integration', function (branch) {
|
grunt.registerTask('mocha_integration', function (branch) {
|
||||||
grunt.config.set(
|
grunt.config.set(
|
||||||
'mochacov.integration.src',
|
'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');
|
grunt.task.run('mochacov:integration');
|
||||||
});
|
});
|
||||||
@ -73,7 +73,7 @@ grunt.registerTask('mocha_integration', function (branch) {
|
|||||||
grunt.registerTask('mocha_jenkins_integration', function (branch) {
|
grunt.registerTask('mocha_jenkins_integration', function (branch) {
|
||||||
grunt.config.set(
|
grunt.config.set(
|
||||||
'mochacov.jenkins_integration.src',
|
'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');
|
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 root = require('find-root')(__dirname);
|
||||||
var pkg = require(root + '/package.json');
|
var pkg = require(root + '/package.json');
|
||||||
@ -8,7 +8,7 @@ var branches = [].concat(stable, unstable);
|
|||||||
|
|
||||||
var utils = {
|
var utils = {
|
||||||
branchSuffix: function (branch) {
|
branchSuffix: function (branch) {
|
||||||
return branch === utils.branches._default ? '' : '_' + _v4.snakeCase(branch);
|
return branch === utils.branches._default ? '' : '_' + _.snakeCase(branch);
|
||||||
},
|
},
|
||||||
branches: branches,
|
branches: branches,
|
||||||
stableBranches: stable,
|
stableBranches: stable,
|
||||||
|
|||||||
@ -96,7 +96,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^1.0.0",
|
"chalk": "^1.0.0",
|
||||||
"forever-agent": "^0.6.0",
|
"forever-agent": "^0.6.0",
|
||||||
"lodash": "^3.10.0",
|
"lodash": "^4.12.0",
|
||||||
"lodash-compat": "^3.0.0",
|
"lodash-compat": "^3.0.0",
|
||||||
"promise": "^7.1.1"
|
"promise": "^7.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var pkg = require('../package.json');
|
var pkg = require('../package.json');
|
||||||
var branches = pkg.config.supported_es_branches;
|
var branches = pkg.config.supported_es_branches;
|
||||||
var semver = require('semver');
|
var semver = require('semver');
|
||||||
@ -47,10 +47,10 @@ Version.prototype.mergeOpts = function (opts) {
|
|||||||
return opts.filter(function (rule) {
|
return opts.filter(function (rule) {
|
||||||
return self.satisfies(rule.version);
|
return self.satisfies(rule.version);
|
||||||
})
|
})
|
||||||
.map(_v4.ary(_v4.partialRight(_v4.omit, 'version'), 1))
|
.map(_.ary(_.partialRight(_.omit, 'version'), 1))
|
||||||
.concat(_v4.tail(arguments))
|
.concat(_.tail(arguments))
|
||||||
.reverse()
|
.reverse()
|
||||||
.reduce(_v4.merge, {});
|
.reduce(_.merge, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Version;
|
module.exports = Version;
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
*******/
|
*******/
|
||||||
|
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var through2 = require('through2');
|
var through2 = require('through2');
|
||||||
var map = require('through2-map');
|
var map = require('through2-map');
|
||||||
var split = require('split');
|
var split = require('split');
|
||||||
@ -30,7 +30,7 @@ var format = require('util').format;
|
|||||||
var NL_RE = /(\r?\n)/g;
|
var NL_RE = /(\r?\n)/g;
|
||||||
var ROOT = join(__dirname, '..');
|
var ROOT = join(__dirname, '..');
|
||||||
var GRUNT = join(ROOT, 'node_modules', '.bin', 'grunt');
|
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 JENKINS = !!ENV.JENKINS_HOME;
|
||||||
var TASKS = [];
|
var TASKS = [];
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ task('SAUCE_LABS', false, function () {
|
|||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
// ignore server errors
|
// ignore server errors
|
||||||
.catch(_v4.noop);
|
.catch(_.noop);
|
||||||
|
|
||||||
// attempt to run tests on saucelabs and retry if it fails
|
// attempt to run tests on saucelabs and retry if it fails
|
||||||
var saucelabsAttempts = 0;
|
var saucelabsAttempts = 0;
|
||||||
@ -116,7 +116,7 @@ task('SAUCE_LABS', false, function () {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
// swallow spawn() errors, custom error handler in place
|
// swallow spawn() errors, custom error handler in place
|
||||||
.catch(_v4.noop);
|
.catch(_.noop);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -168,13 +168,13 @@ execTask('SETUP', function () {
|
|||||||
})
|
})
|
||||||
.then(function readTasks() {
|
.then(function readTasks() {
|
||||||
if (!ENV.RUN) {
|
if (!ENV.RUN) {
|
||||||
return _v4.filter(TASKS, { default: true });
|
return _.filter(TASKS, { default: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
return ENV.RUN
|
return ENV.RUN
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(function (name) {
|
.map(function (name) {
|
||||||
return _v4.find(TASKS, { name: name.trim() });
|
return _.find(TASKS, { name: name.trim() });
|
||||||
})
|
})
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
});
|
});
|
||||||
@ -218,7 +218,7 @@ function logImportant(text) {
|
|||||||
|
|
||||||
function push(m) {
|
function push(m) {
|
||||||
return function () {
|
return function () {
|
||||||
var args = _v4.toArray(arguments);
|
var args = _.toArray(arguments);
|
||||||
var cb = args.pop();
|
var cb = args.pop();
|
||||||
this.push(m.apply(this, args));
|
this.push(m.apply(this, args));
|
||||||
cb();
|
cb();
|
||||||
@ -235,7 +235,7 @@ function indent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function task(name, def, fn) {
|
function task(name, def, fn) {
|
||||||
if (_v4.isFunction(def)) {
|
if (_.isFunction(def)) {
|
||||||
fn = def;
|
fn = def;
|
||||||
def = true;
|
def = true;
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ function task(name, def, fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function execTask(name, task) {
|
function execTask(name, task) {
|
||||||
if (_v4.isObject(name)) {
|
if (_.isObject(name)) {
|
||||||
task = name.fn;
|
task = name.fn;
|
||||||
name = name.name;
|
name = name.name;
|
||||||
}
|
}
|
||||||
@ -316,13 +316,13 @@ function spawn(file, args, block) {
|
|||||||
function node(/* args... */) {
|
function node(/* args... */) {
|
||||||
return spawn(
|
return spawn(
|
||||||
process.execPath,
|
process.execPath,
|
||||||
_v4.toArray(arguments)
|
_.toArray(arguments)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function grunt(/* args... */) {
|
function grunt(/* args... */) {
|
||||||
return spawn(
|
return spawn(
|
||||||
GRUNT,
|
GRUNT,
|
||||||
_v4.toArray(arguments)
|
_.toArray(arguments)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
module.exports = function (done) {
|
module.exports = function (done) {
|
||||||
// var _ = require('../../src/lib/utils');
|
var _ = require('../../src/lib/utils');
|
||||||
var utils = require('../../grunt/utils');
|
var utils = require('../../grunt/utils');
|
||||||
|
|
||||||
var chalk = require('chalk');
|
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 write = require('fs').writeFileSync;
|
||||||
|
|
||||||
var nodeApiIndex = fromRoot('src/lib/apis/index.js');
|
var nodeApiIndex = fromRoot('src/lib/apis/index.js');
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
module.exports = function (done) {
|
module.exports = function (done) {
|
||||||
// var _ = require('../../src/lib/utils');
|
var _ = require('../../src/lib/utils');
|
||||||
|
|
||||||
var chalk = require('chalk');
|
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 write = require('fs').writeFile;
|
||||||
|
|
||||||
var outputPath = fromRoot('docs/configuration.asciidoc');
|
var outputPath = fromRoot('docs/configuration.asciidoc');
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
module.exports = function (done) {
|
module.exports = function (done) {
|
||||||
// var _ = require('../../src/lib/utils');
|
var _ = require('../../src/lib/utils');
|
||||||
var utils = require('../../grunt/utils');
|
var utils = require('../../grunt/utils');
|
||||||
|
|
||||||
var chalk = require('chalk');
|
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 write = require('fs').writeFile;
|
||||||
|
|
||||||
var outputPath = fromRoot('docs/index.asciidoc');
|
var outputPath = fromRoot('docs/index.asciidoc');
|
||||||
|
|||||||
@ -30,7 +30,7 @@ var argv = require('optimist')
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
||||||
var utils = require(fromRoot('grunt/utils'));
|
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 esUrl = 'https://github.com/elastic/elasticsearch.git';
|
||||||
var branches;
|
var branches;
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ var paths = {
|
|||||||
docsIndex: fromRoot('docs/index.asciidoc'),
|
docsIndex: fromRoot('docs/index.asciidoc'),
|
||||||
apiSrc: 'src/lib/apis',
|
apiSrc: 'src/lib/apis',
|
||||||
getArchiveDir: function (branch) {
|
getArchiveDir: function (branch) {
|
||||||
return fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch));
|
return fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||||
},
|
},
|
||||||
getArchiveTarball: function (branch) {
|
getArchiveTarball: function (branch) {
|
||||||
return fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch) + '.tar');
|
return fromRoot('src/_elasticsearch_' + _.snakeCase(branch) + '.tar');
|
||||||
},
|
},
|
||||||
getSpecPathInRepo: function (branch) {
|
getSpecPathInRepo: function (branch) {
|
||||||
return /^v?(master|[2-9]\.)/.test(branch) ? 'rest-api-spec/src/main/resources/rest-api-spec' : 'rest-api-spec';
|
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) {
|
function dirOpts(dir, opts) {
|
||||||
opts = _v4.isArray(opts) ? opts : [opts];
|
opts = _.isArray(opts) ? opts : [opts];
|
||||||
return dirFilter(dir, function (name) {
|
return dirFilter(dir, function (name) {
|
||||||
return _v4.includes(opts, name);
|
return _.includes(opts, name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ function fetchBranchesStep() {
|
|||||||
function findGeneratedApiFiles() {
|
function findGeneratedApiFiles() {
|
||||||
var anyApiMethodDocs = /^(configuration|index|api_methods).*\.asciidoc$/;
|
var anyApiMethodDocs = /^(configuration|index|api_methods).*\.asciidoc$/;
|
||||||
var anyApiJsFiled = /^.+\.js$/;
|
var anyApiJsFiled = /^.+\.js$/;
|
||||||
var allBranches = _v4.isEqual(branches, utils.branches);
|
var allBranches = _.isEqual(branches, utils.branches);
|
||||||
|
|
||||||
if (allBranches) {
|
if (allBranches) {
|
||||||
return [
|
return [
|
||||||
@ -140,7 +140,7 @@ function findGeneratedApiFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return branches.reduce(function (files, branch) {
|
return branches.reduce(function (files, branch) {
|
||||||
var b = _v4.snakeCase(branch);
|
var b = _.snakeCase(branch);
|
||||||
|
|
||||||
files.push(dirOpts(paths.docs, 'api_methods_' + b + '.asciidoc'));
|
files.push(dirOpts(paths.docs, 'api_methods_' + b + '.asciidoc'));
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ function clearGeneratedFiles() {
|
|||||||
|
|
||||||
generatedFiles.push(dirRegex(paths.src, esArchives));
|
generatedFiles.push(dirRegex(paths.src, esArchives));
|
||||||
|
|
||||||
var rmSteps = _v4.chain(generatedFiles)
|
var rmSteps = _.chain(generatedFiles)
|
||||||
.flattenDeep()
|
.flattenDeep()
|
||||||
.uniq()
|
.uniq()
|
||||||
.map(function (path) {
|
.map(function (path) {
|
||||||
@ -195,7 +195,7 @@ function createArchive(branch) {
|
|||||||
var dir = paths.getArchiveDir(branch);
|
var dir = paths.getArchiveDir(branch);
|
||||||
var tarball = paths.getArchiveTarball(branch);
|
var tarball = paths.getArchiveTarball(branch);
|
||||||
var specPathInRepo = paths.getSpecPathInRepo(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)) {
|
if (isDirectory(dir)) {
|
||||||
console.log(branch + ' archive already exists');
|
console.log(branch + ' archive already exists');
|
||||||
@ -227,7 +227,7 @@ var steps = [
|
|||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
branches.forEach(function (branch) {
|
branches.forEach(function (branch) {
|
||||||
steps.push(_v4.partial(async.series, [
|
steps.push(_.partial(async.series, [
|
||||||
removePrevArchive(branch),
|
removePrevArchive(branch),
|
||||||
createArchive(branch),
|
createArchive(branch),
|
||||||
generateStep(branch)
|
generateStep(branch)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module.exports = function (branch, done) {
|
|||||||
* Read the API actions form the rest-api-spec repo.
|
* Read the API actions form the rest-api-spec repo.
|
||||||
* @type {[type]}
|
* @type {[type]}
|
||||||
*/
|
*/
|
||||||
// var _ = require('../../src/lib/utils');
|
var _ = require('../../src/lib/utils');
|
||||||
var utils = require('../../grunt/utils');
|
var utils = require('../../grunt/utils');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
@ -19,7 +19,7 @@ module.exports = function (branch, done) {
|
|||||||
var docVars; // slightly modified clone of apiSpec for the docs
|
var docVars; // slightly modified clone of apiSpec for the docs
|
||||||
|
|
||||||
var branchSuffix = utils.branchSuffix(branch);
|
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 version = Version.fromBranch(branch);
|
||||||
var overrides = version.mergeOpts(require('./overrides'), {
|
var overrides = version.mergeOpts(require('./overrides'), {
|
||||||
@ -71,27 +71,27 @@ module.exports = function (branch, done) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// collect the namespaces from the action locations
|
// 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('.')) {
|
if (~action.location.indexOf('.')) {
|
||||||
var path = action.location.split('.').slice(0, -1);
|
var path = action.location.split('.').slice(0, -1);
|
||||||
_v4.pull(path, 'prototype');
|
_.pull(path, 'prototype');
|
||||||
return path.join('.');
|
return path.join('.');
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// seperate the proxy actions
|
// seperate the proxy actions
|
||||||
var groups = _v4.groupBy(actions, function (action) {
|
var groups = _.groupBy(actions, function (action) {
|
||||||
return action.proxy ? 'proxies' : 'normal';
|
return action.proxy ? 'proxies' : 'normal';
|
||||||
});
|
});
|
||||||
|
|
||||||
apiSpec = {
|
apiSpec = {
|
||||||
actions: groups.normal || [],
|
actions: groups.normal || [],
|
||||||
proxies: groups.proxies || [],
|
proxies: groups.proxies || [],
|
||||||
namespaces: _v4.uniq(namespaces.sort()),
|
namespaces: _.uniq(namespaces.sort()),
|
||||||
clientActionModifier: overrides.clientActionModifier
|
clientActionModifier: overrides.clientActionModifier
|
||||||
};
|
};
|
||||||
|
|
||||||
var create = _v4.assign({}, _v4.find(apiSpec.actions, { name: 'index' }), {
|
var create = _.assign({}, _.find(apiSpec.actions, { name: 'index' }), {
|
||||||
name: 'create',
|
name: 'create',
|
||||||
location: 'create',
|
location: 'create',
|
||||||
proxy: 'index',
|
proxy: 'index',
|
||||||
@ -119,7 +119,7 @@ module.exports = function (branch, done) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeApiFile(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));
|
fs.writeFileSync(outputPath, templates.apiFile(apiSpec));
|
||||||
console.log(chalk.white.bold('wrote'), apiSpec.actions.length, 'api actions to', outputPath);
|
console.log(chalk.white.bold('wrote'), apiSpec.actions.length, 'api actions to', outputPath);
|
||||||
done();
|
done();
|
||||||
@ -145,8 +145,8 @@ module.exports = function (branch, done) {
|
|||||||
// merge the actions and proxies to make
|
// merge the actions and proxies to make
|
||||||
// itteration easir and keep them in order
|
// itteration easir and keep them in order
|
||||||
|
|
||||||
docVars = _v4.omit(apiSpec, 'proxies');
|
docVars = _.omit(apiSpec, 'proxies');
|
||||||
docVars.actions = _v4.sortBy(
|
docVars.actions = _.sortBy(
|
||||||
[].concat(apiSpec.actions).concat(apiSpec.proxies),
|
[].concat(apiSpec.actions).concat(apiSpec.proxies),
|
||||||
'name'
|
'name'
|
||||||
);
|
);
|
||||||
@ -174,9 +174,9 @@ module.exports = function (branch, done) {
|
|||||||
var actions = [];
|
var actions = [];
|
||||||
|
|
||||||
// itterate all of the specs within the file, should only be one
|
// 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
|
// camelcase the name
|
||||||
name = _v4.map(name.split('.'), _v4.camelCase).join('.');
|
name = _.map(name.split('.'), _.camelCase).join('.');
|
||||||
|
|
||||||
if (name === 'cat.aliases') {
|
if (name === 'cat.aliases') {
|
||||||
def.documentation = 'http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat.html';
|
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('.');
|
var steps = name.split('.');
|
||||||
|
|
||||||
function transformParamKeys(note, param, key) {
|
function transformParamKeys(note, param, key) {
|
||||||
var cmlKey = _v4.camelCase(key);
|
var cmlKey = _.camelCase(key);
|
||||||
if (cmlKey !== key) {
|
if (cmlKey !== key) {
|
||||||
param.name = key;
|
param.name = key;
|
||||||
}
|
}
|
||||||
note[cmlKey] = param;
|
note[cmlKey] = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
def.url.params = _v4.transform(def.url.params, transformParamKeys, {});
|
def.url.params = _.transform(def.url.params, transformParamKeys, {});
|
||||||
def.url.parts = _v4.transform(def.url.parts, 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 = {
|
var spec = {
|
||||||
name: name,
|
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,
|
params: def.url.params,
|
||||||
body: def.body || null,
|
body: def.body || null,
|
||||||
path2lib: _v4.repeat('../', steps.length + 1) + 'lib/'
|
path2lib: _.repeat('../', steps.length + 1) + 'lib/'
|
||||||
};
|
};
|
||||||
|
|
||||||
if (def.body && def.body.required) {
|
if (def.body && def.body.required) {
|
||||||
@ -216,9 +216,9 @@ module.exports = function (branch, done) {
|
|||||||
spec.requestTimeout = 3000;
|
spec.requestTimeout = 3000;
|
||||||
}
|
}
|
||||||
|
|
||||||
var urls = _v4.difference(def.url.paths, overrides.aliases[name]);
|
var urls = _.difference(def.url.paths, overrides.aliases[name]);
|
||||||
var urlSignatures = [];
|
var urlSignatures = [];
|
||||||
urls = _v4.map(urls, function (url) {
|
urls = _.map(urls, function (url) {
|
||||||
var optionalVars = {};
|
var optionalVars = {};
|
||||||
var requiredVars = {};
|
var requiredVars = {};
|
||||||
var param;
|
var param;
|
||||||
@ -231,47 +231,47 @@ module.exports = function (branch, done) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (match = urlParamRE.exec(url)) {
|
while (match = urlParamRE.exec(url)) {
|
||||||
name = _v4.camelCase(match[1]);
|
name = _.camelCase(match[1]);
|
||||||
param = def.url.parts[name] || {};
|
param = def.url.parts[name] || {};
|
||||||
target = (param.required || !param.default) ? requiredVars : optionalVars;
|
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) {
|
fmt: url.replace(urlParamRE, function (full, match) {
|
||||||
return '<%=' + _v4.camelCase(match) + '%>';
|
return '<%=' + _.camelCase(match) + '%>';
|
||||||
}),
|
}),
|
||||||
opt: _v4.size(optionalVars) ? optionalVars : null,
|
opt: _.size(optionalVars) ? optionalVars : null,
|
||||||
req: _v4.size(requiredVars) ? requiredVars : null,
|
req: _.size(requiredVars) ? requiredVars : null,
|
||||||
sortOrder: _v4.size(requiredVars) * -1
|
sortOrder: _.size(requiredVars) * -1
|
||||||
}, function (v) {
|
}, function (v) {
|
||||||
return !v;
|
return !v;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (urlSignatures.length !== _v4.uniq(urlSignatures).length) {
|
if (urlSignatures.length !== _.uniq(urlSignatures).length) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Multiple URLS with the same signature detected for ' +
|
'Multiple URLS with the same signature detected for ' +
|
||||||
spec.name +
|
spec.name +
|
||||||
'\n' +
|
'\n' +
|
||||||
_v4.map(urls, 'fmt').join('\n') +
|
_.map(urls, 'fmt').join('\n') +
|
||||||
'\n'
|
'\n'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urls.length > 1) {
|
if (urls.length > 1) {
|
||||||
spec.urls = _v4.map(_v4.sortBy(urls, 'sortOrder'), function (url) {
|
spec.urls = _.map(_.sortBy(urls, 'sortOrder'), function (url) {
|
||||||
return _v4.omit(url, 'sortOrder');
|
return _.omit(url, 'sortOrder');
|
||||||
});
|
});
|
||||||
} else {
|
} 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;
|
// param.name = name;
|
||||||
note[name] = _v4.pick(param, [
|
note[name] = _.pick(param, [
|
||||||
'type', 'default', 'options', 'required', 'name'
|
'type', 'default', 'options', 'required', 'name'
|
||||||
]);
|
]);
|
||||||
}, {});
|
}, {});
|
||||||
@ -280,7 +280,7 @@ module.exports = function (branch, done) {
|
|||||||
spec.paramAsBody = overrides.paramAsBody[name];
|
spec.paramAsBody = overrides.paramAsBody[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_v4.size(spec.params) === 0) {
|
if (_.size(spec.params) === 0) {
|
||||||
delete spec.params;
|
delete spec.params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ module.exports = function (branch, done) {
|
|||||||
|
|
||||||
var action = {
|
var action = {
|
||||||
_methods: spec.methods,
|
_methods: spec.methods,
|
||||||
spec: _v4.pick(spec, [
|
spec: _.pick(spec, [
|
||||||
'params',
|
'params',
|
||||||
'url',
|
'url',
|
||||||
'urls',
|
'urls',
|
||||||
|
|||||||
@ -9,21 +9,21 @@ var api = module.exports = {};
|
|||||||
|
|
||||||
api._namespaces = <%= stringify(namespaces) %>;<%
|
api._namespaces = <%= stringify(namespaces) %>;<%
|
||||||
|
|
||||||
_v4.each(actions, function (action) {
|
_.each(actions, function (action) {
|
||||||
var namespace = action.location.split('.').shift();
|
var namespace = action.location.split('.').shift();
|
||||||
if (_.includes(namespaces, namespace)) {
|
if (_.includes(namespaces, namespace)) {
|
||||||
_v4.pull(namespaces, namespace);
|
_.pull(namespaces, namespace);
|
||||||
%>
|
%>
|
||||||
|
|
||||||
api.<%= namespace %> = 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) {
|
branches.forEach(function (branch, i, list) {
|
||||||
var req = "require('./" + _v4.snakeCase(branch) + "')";
|
var req = "require('./" + _.snakeCase(branch) + "')";
|
||||||
if (branch === utils.branches._default) {
|
if (branch === utils.branches._default) {
|
||||||
print(" '_default': " + req + ',\n');
|
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.
|
NOTE: At this time, you must opt into the <%= branch %> API by setting the `apiVersion` config parameter.
|
||||||
<% }
|
<% }
|
||||||
|
|
||||||
actions = _v4.sortBy(actions, 'namespace');
|
actions = _.sortBy(actions, 'namespace');
|
||||||
_v4.each(actions, function (action) {
|
_.each(actions, function (action) {
|
||||||
action.index = 'api-' + action.name.toLowerCase().replace(/[^\w]+/g, '-') + branchSuffix;
|
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 %>
|
<%= action.examples %>
|
||||||
|
|
||||||
<% if (_v4.size(action.allParams)) { %>
|
<% if (_.size(action.allParams)) { %>
|
||||||
*Params*
|
*Params*
|
||||||
|
|
||||||
[horizontal]<%
|
[horizontal]<%
|
||||||
_v4.each(action.allParams, function (param, paramName) { %>
|
_.each(action.allParams, function (param, paramName) { %>
|
||||||
`<%= paramWithDefault(paramName, param.default) %>`::
|
`<%= paramWithDefault(paramName, param.default) %>`::
|
||||||
`<%= paramType(param.type) %>` -- <%= joinParagraphs(param.description || '', 4) %><%
|
`<%= paramType(param.type) %>` -- <%= joinParagraphs(param.description || '', 4) %><%
|
||||||
if (param.type === 'enum') {%>
|
if (param.type === 'enum') {%>
|
||||||
Options:::<%
|
Options:::<%
|
||||||
_v4.each(param.options, function (opt) {%>
|
_.each(param.options, function (opt) {%>
|
||||||
* `"<%= opt %>"`<%
|
* `"<%= opt %>"`<%
|
||||||
});%>
|
});%>
|
||||||
<%
|
<%
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
* Perform a [<%= name %>](<%= docUrl %>) request
|
* Perform a [<%= name %>](<%= docUrl %>) request
|
||||||
*
|
*
|
||||||
* @param {Object} params - An object with parameters used to carry out this action<%
|
* @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) %><%
|
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><%
|
||||||
if (param.description) {
|
if (param.description) {
|
||||||
%> - <%= param.description %><%
|
%> - <%= param.description %><%
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
* Perform a [<%= name %>](<%= docUrl %>) request
|
* Perform a [<%= name %>](<%= docUrl %>) request
|
||||||
*
|
*
|
||||||
* @param {Object} params - An object with parameters used to carry out this action<%
|
* @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) %><%
|
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><%
|
||||||
if (param.description) {
|
if (param.description) {
|
||||||
%> - <%= param.description %><%
|
%> - <%= param.description %><%
|
||||||
|
|||||||
@ -303,7 +303,7 @@ var client = new elasticsearch.Client({
|
|||||||
selector: function (hosts) {
|
selector: function (hosts) {
|
||||||
var myCountry = process.env.COUNTRY;
|
var myCountry = process.env.COUNTRY;
|
||||||
// first try to find a node that is in the same 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;
|
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 utils = require('../../../grunt/utils');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
@ -41,10 +41,10 @@ var templateGlobals = {
|
|||||||
|
|
||||||
stringify: stringify,
|
stringify: stringify,
|
||||||
|
|
||||||
_v4: _v4,
|
_: _,
|
||||||
|
|
||||||
indent: function (block, spaces) {
|
indent: function (block, spaces) {
|
||||||
var indent = _v4.repeat(' ', spaces);
|
var indent = _.repeat(' ', spaces);
|
||||||
return block.split('\n').map(function (line) {
|
return block.split('\n').map(function (line) {
|
||||||
return indent + line;
|
return indent + line;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
@ -77,7 +77,7 @@ var templateGlobals = {
|
|||||||
case 'list':
|
case 'list':
|
||||||
return 'String, String[], Boolean';
|
return 'String, String[], Boolean';
|
||||||
default:
|
default:
|
||||||
return _v4.ucfirst(type);
|
return _.ucfirst(type);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ var templateGlobals = {
|
|||||||
fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
||||||
var name = filename.replace(/\..+$/, '');
|
var name = filename.replace(/\..+$/, '');
|
||||||
if (name !== 'index') {
|
if (name !== 'index') {
|
||||||
templates[name] = _v4.template(
|
templates[name] = _.template(
|
||||||
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
|
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
|
||||||
{
|
{
|
||||||
imports: templateGlobals
|
imports: templateGlobals
|
||||||
|
|||||||
@ -8,10 +8,10 @@ module.exports = function (branch, done) {
|
|||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
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 tests = {}; // populated in readYamlTests
|
||||||
|
|
||||||
var esDir = fromRoot('src/_elasticsearch_' + _v4.snakeCase(branch));
|
var esDir = fromRoot('src/_elasticsearch_' + _.snakeCase(branch));
|
||||||
|
|
||||||
// generate the yaml tests
|
// generate the yaml tests
|
||||||
async.series([
|
async.series([
|
||||||
@ -43,14 +43,14 @@ module.exports = function (branch, done) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeYamlTests(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');
|
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
|
||||||
console.log(chalk.white.bold('wrote') + ' YAML tests as JSON to', testFile);
|
console.log(chalk.white.bold('wrote') + ' YAML tests as JSON to', testFile);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeTestIndex(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');
|
fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');\n', 'utf8');
|
||||||
console.log(chalk.white.bold('wrote') + ' YAML index to', file);
|
console.log(chalk.white.bold('wrote') + ' YAML index to', file);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var spawn = require('../_spawn');
|
var spawn = require('../_spawn');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
|
||||||
var root = require('path').join(__dirname, '../..');
|
var root = require('path').join(__dirname, '../..');
|
||||||
var bowerDir = root + '/src/bower_es_js';
|
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, ' '));
|
fs.writeFileSync(bowerDir + '/package.json', JSON.stringify(bowerPackageJson, null, ' '));
|
||||||
|
|
||||||
function make(cmd, args) {
|
function make(cmd, args) {
|
||||||
return _v4.bind(spawn, null, cmd, args, {
|
return _.bind(spawn, null, cmd, args, {
|
||||||
verbose: true,
|
verbose: true,
|
||||||
cwd: bowerDir
|
cwd: bowerDir
|
||||||
});
|
});
|
||||||
@ -36,7 +36,7 @@ async.series([
|
|||||||
make('npm', ['publish'])
|
make('npm', ['publish'])
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (_v4.isNumber(err)) {
|
if (_.isNumber(err)) {
|
||||||
console.log('Non-zero exit code: %d', err);
|
console.log('Non-zero exit code: %d', err);
|
||||||
} else {
|
} else {
|
||||||
console.log('Error: ', err.message ? err.message : err);
|
console.log('Error: ', err.message ? err.message : err);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ module.exports = Client;
|
|||||||
|
|
||||||
var Transport = require('./transport');
|
var Transport = require('./transport');
|
||||||
var clientAction = require('./client_action');
|
var clientAction = require('./client_action');
|
||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
|
|
||||||
function Client(config) {
|
function Client(config) {
|
||||||
config = config || {};
|
config = config || {};
|
||||||
@ -56,7 +56,7 @@ function Client(config) {
|
|||||||
|
|
||||||
this.transport = new Transport(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) {
|
if (Fn.prototype instanceof clientAction.ApiNamespace) {
|
||||||
this[prop] = new Fn(this.transport);
|
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']) {
|
if (!config.sniffEndpoint && EsApiClient.prototype === Client.apis['0.90']) {
|
||||||
config.sniffEndpoint = '/_cluster/nodes';
|
config.sniffEndpoint = '/_cluster/nodes';
|
||||||
}
|
}
|
||||||
@ -74,9 +74,9 @@ function Client(config) {
|
|||||||
var Constructor = EsApiClient;
|
var Constructor = EsApiClient;
|
||||||
|
|
||||||
if (config.plugins) {
|
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, {
|
Constructor = setup(Constructor, config, {
|
||||||
apis: require('./apis'),
|
apis: require('./apis'),
|
||||||
connectors: require('./connectors'),
|
connectors: require('./connectors'),
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a client action factory that uses specific defaults
|
* Constructs a client action factory that uses specific defaults
|
||||||
@ -34,12 +34,12 @@ exports.namespaceFactory = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function makeFactoryWithModifier(modifier) {
|
function makeFactoryWithModifier(modifier) {
|
||||||
modifier = modifier || _v4.identity;
|
modifier = modifier || _.identity;
|
||||||
|
|
||||||
var factory = function (spec) {
|
var factory = function (spec) {
|
||||||
spec = modifier(spec);
|
spec = modifier(spec);
|
||||||
|
|
||||||
if (!_v4.isPlainObject(spec.params)) {
|
if (!_.isPlainObject(spec.params)) {
|
||||||
spec.params = {};
|
spec.params = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +57,10 @@ function makeFactoryWithModifier(modifier) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return exec(this.transport, spec, _v4.clone(params), cb);
|
return exec(this.transport, spec, _.clone(params), cb);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
_v4.nextTick(cb, e);
|
_.nextTick(cb, e);
|
||||||
} else {
|
} else {
|
||||||
var def = this.transport.defer();
|
var def = this.transport.defer();
|
||||||
def.reject(e);
|
def.reject(e);
|
||||||
@ -97,11 +97,11 @@ function makeFactoryWithModifier(modifier) {
|
|||||||
|
|
||||||
var castType = {
|
var castType = {
|
||||||
'enum': function validSelection(param, val, name) {
|
'enum': function validSelection(param, val, name) {
|
||||||
if (_v4.isString(val) && val.indexOf(',') > -1) {
|
if (_.isString(val) && val.indexOf(',') > -1) {
|
||||||
val = commaSepList(val);
|
val = commaSepList(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_v4.isArray(val)) {
|
if (_.isArray(val)) {
|
||||||
return val.map(function (v) {
|
return val.map(function (v) {
|
||||||
return validSelection(param, v, name);
|
return validSelection(param, v, name);
|
||||||
}).join(',');
|
}).join(',');
|
||||||
@ -119,7 +119,7 @@ var castType = {
|
|||||||
));
|
));
|
||||||
},
|
},
|
||||||
duration: function (param, val, name) {
|
duration: function (param, val, name) {
|
||||||
if (_v4.isNumeric(val) || _v4.isInterval(val)) {
|
if (_.isNumeric(val) || _.isInterval(val)) {
|
||||||
return val;
|
return val;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
@ -137,7 +137,7 @@ var castType = {
|
|||||||
val = commaSepList(val);
|
val = commaSepList(val);
|
||||||
/* falls through */
|
/* falls through */
|
||||||
case 'object':
|
case 'object':
|
||||||
if (_v4.isArray(val)) {
|
if (_.isArray(val)) {
|
||||||
return val.join(',');
|
return val.join(',');
|
||||||
}
|
}
|
||||||
/* falls through */
|
/* falls through */
|
||||||
@ -146,11 +146,11 @@ var castType = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
'boolean': function (param, val) {
|
'boolean': function (param, val) {
|
||||||
val = _v4.isString(val) ? val.toLowerCase() : val;
|
val = _.isString(val) ? val.toLowerCase() : val;
|
||||||
return (val === 'no' || val === 'off') ? false : !!val;
|
return (val === 'no' || val === 'off') ? false : !!val;
|
||||||
},
|
},
|
||||||
number: function (param, val, name) {
|
number: function (param, val, name) {
|
||||||
if (_v4.isNumeric(val)) {
|
if (_.isNumeric(val)) {
|
||||||
return val * 1;
|
return val * 1;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError('Invalid ' + name + ': expected a number.');
|
throw new TypeError('Invalid ' + name + ': expected a number.');
|
||||||
@ -169,7 +169,7 @@ var castType = {
|
|||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
else if (_v4.isNumeric(val)) {
|
else if (_.isNumeric(val)) {
|
||||||
return '' + val;
|
return '' + val;
|
||||||
}
|
}
|
||||||
else if (val instanceof Date) {
|
else if (val instanceof Date) {
|
||||||
@ -188,7 +188,7 @@ function resolveUrl(url, params) {
|
|||||||
// url has required params
|
// url has required params
|
||||||
if (!url.reqParamKeys) {
|
if (!url.reqParamKeys) {
|
||||||
// create cached key list on demand
|
// 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 ++) {
|
for (i = 0; i < url.reqParamKeys.length; i ++) {
|
||||||
@ -210,7 +210,7 @@ function resolveUrl(url, params) {
|
|||||||
if (url.opt) {
|
if (url.opt) {
|
||||||
// url has optional params
|
// url has optional params
|
||||||
if (!url.optParamKeys) {
|
if (!url.optParamKeys) {
|
||||||
url.optParamKeys = _v4.keys(url.opt);
|
url.optParamKeys = _.keys(url.opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < url.optParamKeys.length; i ++) {
|
for (i = 0; i < url.optParamKeys.length; i ++) {
|
||||||
@ -229,10 +229,10 @@ function resolveUrl(url, params) {
|
|||||||
|
|
||||||
if (!url.template) {
|
if (!url.template) {
|
||||||
// compile the template on demand
|
// 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
|
// encode each value
|
||||||
note[name] = encodeURIComponent(val);
|
note[name] = encodeURIComponent(val);
|
||||||
// remove it from the params so that it isn't sent to the final request
|
// 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) {
|
if (!request.path) {
|
||||||
// there must have been some mimimun requirements that were not met
|
// there must have been some mimimun requirements that were not met
|
||||||
var minUrl = spec.url || spec.urls[spec.urls.length - 1];
|
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
|
// build the query string
|
||||||
if (!spec.paramKeys) {
|
if (!spec.paramKeys) {
|
||||||
// build a key list on demand
|
// build a key list on demand
|
||||||
spec.paramKeys = _v4.keys(spec.params);
|
spec.paramKeys = _.keys(spec.params);
|
||||||
spec.requireParamKeys = _v4.transform(spec.params, function (req, param, key) {
|
spec.requireParamKeys = _.transform(spec.params, function (req, param, key) {
|
||||||
if (param.required) {
|
if (param.required) {
|
||||||
req.push(key);
|
req.push(key);
|
||||||
}
|
}
|
||||||
@ -311,10 +311,10 @@ function exec(transport, spec, params, cb) {
|
|||||||
request[key] = params[key];
|
request[key] = params[key];
|
||||||
break;
|
break;
|
||||||
case 'ignore':
|
case 'ignore':
|
||||||
request.ignore = _v4.isArray(params[key]) ? params[key] : [params[key]];
|
request.ignore = _.isArray(params[key]) ? params[key] : [params[key]];
|
||||||
break;
|
break;
|
||||||
case 'method':
|
case 'method':
|
||||||
request.method = _v4.toUpperString(params[key]);
|
request.method = _.toUpperString(params[key]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
var paramSpec = spec.params[key];
|
var paramSpec = spec.params[key];
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
module.exports = ConnectionAbstract;
|
module.exports = ConnectionAbstract;
|
||||||
|
|
||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var Log = require('./log');
|
var Log = require('./log');
|
||||||
var Host = require('./host');
|
var Host = require('./host');
|
||||||
@ -26,9 +26,9 @@ function ConnectionAbstract(host, config) {
|
|||||||
throw new TypeError('Invalid host');
|
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
|
* 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;
|
requestTimeout = params.requestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
abort = this.request(_v4.defaults(params || {}, {
|
abort = this.request(_.defaults(params || {}, {
|
||||||
path: '/',
|
path: '/',
|
||||||
method: 'HEAD'
|
method: 'HEAD'
|
||||||
}), function (err) {
|
}), function (err) {
|
||||||
|
|||||||
@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
module.exports = ConnectionPool;
|
module.exports = ConnectionPool;
|
||||||
|
|
||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
var Log = require('./log');
|
var Log = require('./log');
|
||||||
|
|
||||||
function ConnectionPool(config) {
|
function ConnectionPool(config) {
|
||||||
config = config || {};
|
config = config || {};
|
||||||
_v4.makeBoundMethods(this);
|
_.makeBoundMethods(this);
|
||||||
|
|
||||||
if (!config.log) {
|
if (!config.log) {
|
||||||
this.log = new Log();
|
this.log = new Log();
|
||||||
@ -27,16 +27,16 @@ function ConnectionPool(config) {
|
|||||||
this._config = config;
|
this._config = config;
|
||||||
|
|
||||||
// get the selector config var
|
// 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
|
// get the connection class
|
||||||
this.Connection = _v4.funcEnum(config, 'connectionClass', ConnectionPool.connectionClasses,
|
this.Connection = _.funcEnum(config, 'connectionClass', ConnectionPool.connectionClasses,
|
||||||
ConnectionPool.defaultConnectionClass);
|
ConnectionPool.defaultConnectionClass);
|
||||||
|
|
||||||
// time that connections will wait before being revived
|
// time that connections will wait before being revived
|
||||||
this.deadTimeout = config.hasOwnProperty('deadTimeout') ? config.deadTimeout : 60000;
|
this.deadTimeout = config.hasOwnProperty('deadTimeout') ? config.deadTimeout : 60000;
|
||||||
this.maxDeadTimeout = config.hasOwnProperty('maxDeadTimeout') ? config.maxDeadTimeout : 18e5;
|
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
|
// a map of connections to their "id" property, used when sniffing
|
||||||
this.index = {};
|
this.index = {};
|
||||||
@ -86,7 +86,7 @@ ConnectionPool.prototype.select = function (cb) {
|
|||||||
this.selector(this._conns.alive, cb);
|
this.selector(this._conns.alive, cb);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
_v4.nextTick(cb, void 0, this.selector(this._conns.alive));
|
_.nextTick(cb, void 0, this.selector(this._conns.alive));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
cb(e);
|
cb(e);
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ ConnectionPool.prototype.select = function (cb) {
|
|||||||
} else if (this._timeouts.length) {
|
} else if (this._timeouts.length) {
|
||||||
this._selectDeadConnection(cb);
|
this._selectDeadConnection(cb);
|
||||||
} else {
|
} 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 {String} oldStatus - the connection's old status
|
||||||
* @param {ConnectionAbstract} connection - the connection object itself
|
* @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 index;
|
||||||
|
|
||||||
var died = (status === 'dead');
|
var died = (status === 'dead');
|
||||||
@ -121,14 +121,14 @@ ConnectionPool.prototype.onStatusSet = _v4.handler(function (status, oldStatus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (from !== to) {
|
if (from !== to) {
|
||||||
if (_v4.isArray(from)) {
|
if (_.isArray(from)) {
|
||||||
index = from.indexOf(connection);
|
index = from.indexOf(connection);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
from.splice(index, 1);
|
from.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_v4.isArray(to)) {
|
if (_.isArray(to)) {
|
||||||
index = to.indexOf(connection);
|
index = to.indexOf(connection);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
to.push(connection);
|
to.push(connection);
|
||||||
@ -200,11 +200,11 @@ ConnectionPool.prototype._onConnectionDied = function (connection, alreadyWasDea
|
|||||||
|
|
||||||
var ms = this.calcDeadTimeout(timeout.attempt, this.deadTimeout);
|
var ms = this.calcDeadTimeout(timeout.attempt, this.deadTimeout);
|
||||||
timeout.id = setTimeout(timeout.revive, ms);
|
timeout.id = setTimeout(timeout.revive, ms);
|
||||||
timeout.runAt = _v4.now() + ms;
|
timeout.runAt = _.now() + ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
ConnectionPool.prototype._selectDeadConnection = function (cb) {
|
ConnectionPool.prototype._selectDeadConnection = function (cb) {
|
||||||
var orderedTimeouts = _v4.sortBy(this._timeouts, 'runAt');
|
var orderedTimeouts = _.sortBy(this._timeouts, 'runAt');
|
||||||
var log = this.log;
|
var log = this.log;
|
||||||
|
|
||||||
process.nextTick(function next() {
|
process.nextTick(function next() {
|
||||||
@ -257,7 +257,7 @@ ConnectionPool.prototype.getConnections = function (status, limit) {
|
|||||||
if (limit == null) {
|
if (limit == null) {
|
||||||
return list.slice(0);
|
return list.slice(0);
|
||||||
} else {
|
} 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 i;
|
||||||
var id;
|
var id;
|
||||||
var host;
|
var host;
|
||||||
var toRemove = _v4.clone(this.index);
|
var toRemove = _.clone(this.index);
|
||||||
|
|
||||||
for (i = 0; i < hosts.length; i++) {
|
for (i = 0; i < hosts.length; i++) {
|
||||||
host = hosts[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++) {
|
for (i = 0; i < removeIds.length; i++) {
|
||||||
this.removeConnection(this.index[removeIds[i]]);
|
this.removeConnection(this.index[removeIds[i]]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ConnectionPool.prototype.getAllHosts = function () {
|
ConnectionPool.prototype.getAllHosts = function () {
|
||||||
return _v4.values(this.index).map(function (connection) {
|
return _.values(this.index).map(function (connection) {
|
||||||
return connection.host;
|
return connection.host;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
4
src/lib/connectors/angular.js
vendored
4
src/lib/connectors/angular.js
vendored
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = AngularConnector;
|
module.exports = AngularConnector;
|
||||||
|
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var ConnectionAbstract = require('../connection');
|
var ConnectionAbstract = require('../connection');
|
||||||
var ConnectionFault = require('../errors').ConnectionFault;
|
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) {
|
AngularConnector.prototype.request = function (params, cb) {
|
||||||
var abort = this.$q.defer();
|
var abort = this.$q.defer();
|
||||||
|
|||||||
@ -3,10 +3,10 @@ var opts = {
|
|||||||
jquery: require('./jquery'),
|
jquery: require('./jquery'),
|
||||||
angular: require('./angular')
|
angular: require('./angular')
|
||||||
};
|
};
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
|
|
||||||
// remove modules that have been ignored by browserify
|
// remove modules that have been ignored by browserify
|
||||||
_v4.each(opts, function (conn, name) {
|
_.each(opts, function (conn, name) {
|
||||||
if (typeof conn !== 'function') {
|
if (typeof conn !== 'function') {
|
||||||
delete opts[name];
|
delete opts[name];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ var handles = {
|
|||||||
http: require('http'),
|
http: require('http'),
|
||||||
https: require('https')
|
https: require('https')
|
||||||
};
|
};
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var qs = require('querystring');
|
var qs = require('querystring');
|
||||||
var KeepAliveAgent = require('./_keep_alive_agent');
|
var KeepAliveAgent = require('./_keep_alive_agent');
|
||||||
var ConnectionAbstract = require('../connection');
|
var ConnectionAbstract = require('../connection');
|
||||||
@ -31,12 +31,12 @@ function HttpConnector(host, config) {
|
|||||||
this.hand = handles[this.host.protocol];
|
this.hand = handles[this.host.protocol];
|
||||||
if (!this.hand) {
|
if (!this.hand) {
|
||||||
throw new TypeError('Invalid protocol "' + this.host.protocol +
|
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';
|
this.useSsl = this.host.protocol === 'https';
|
||||||
|
|
||||||
config = _v4.defaults(config || {}, {
|
config = _.defaults(config || {}, {
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
minSockets: 10,
|
minSockets: 10,
|
||||||
// 10 makes sense but 11 actually keeps 10 sockets around
|
// 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);
|
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') {
|
if (status === 'closed') {
|
||||||
var agent = this.agent;
|
var agent = this.agent;
|
||||||
var toRemove = [];
|
var toRemove = [];
|
||||||
var collectSockets = function (sockets, host) {
|
var collectSockets = function (sockets, host) {
|
||||||
_v4.each(sockets, function (s) {
|
_.each(sockets, function (s) {
|
||||||
if (s) toRemove.push([host, s]);
|
if (s) toRemove.push([host, s]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -61,9 +61,9 @@ HttpConnector.prototype.onStatusSet = _v4.handler(function (status) {
|
|||||||
agent.minSockets = agent.maxSockets = 0;
|
agent.minSockets = agent.maxSockets = 0;
|
||||||
agent.requests = {};
|
agent.requests = {};
|
||||||
|
|
||||||
_v4.each(agent.sockets, collectSockets);
|
_.each(agent.sockets, collectSockets);
|
||||||
_v4.each(agent.freeSockets, collectSockets);
|
_.each(agent.freeSockets, collectSockets);
|
||||||
_v4.each(toRemove, function (args) {
|
_.each(toRemove, function (args) {
|
||||||
var host = args[0], socket = args[1];
|
var host = args[0], socket = args[1];
|
||||||
agent.removeSocket(socket, host);
|
agent.removeSocket(socket, host);
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
@ -102,7 +102,7 @@ HttpConnector.prototype.makeAgentConfig = function (config) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (this.useSsl) {
|
if (this.useSsl) {
|
||||||
_v4.merge(agentConfig, this.host.ssl);
|
_.merge(agentConfig, this.host.ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return agentConfig;
|
return agentConfig;
|
||||||
@ -147,7 +147,7 @@ HttpConnector.prototype.request = function (params, cb) {
|
|||||||
|
|
||||||
// general clean-up procedure to run after the request
|
// general clean-up procedure to run after the request
|
||||||
// completes, has an error, or is aborted.
|
// completes, has an error, or is aborted.
|
||||||
var cleanUp = _v4.bind(function (err) {
|
var cleanUp = _.bind(function (err) {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
request && request.removeAllListeners();
|
request && request.removeAllListeners();
|
||||||
|
|||||||
4
src/lib/connectors/jquery.js
vendored
4
src/lib/connectors/jquery.js
vendored
@ -7,14 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = JqueryConnector;
|
module.exports = JqueryConnector;
|
||||||
|
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var ConnectionAbstract = require('../connection');
|
var ConnectionAbstract = require('../connection');
|
||||||
var ConnectionFault = require('../errors').ConnectionFault;
|
var ConnectionFault = require('../errors').ConnectionFault;
|
||||||
|
|
||||||
function JqueryConnector(host, config) {
|
function JqueryConnector(host, config) {
|
||||||
ConnectionAbstract.call(this, host, config);
|
ConnectionAbstract.call(this, host, config);
|
||||||
}
|
}
|
||||||
_v4.inherits(JqueryConnector, ConnectionAbstract);
|
_.inherits(JqueryConnector, ConnectionAbstract);
|
||||||
|
|
||||||
JqueryConnector.prototype.request = function (params, cb) {
|
JqueryConnector.prototype.request = function (params, cb) {
|
||||||
var ajax = {
|
var ajax = {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ module.exports = XhrConnector;
|
|||||||
|
|
||||||
/* jshint browser:true */
|
/* jshint browser:true */
|
||||||
|
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var ConnectionAbstract = require('../connection');
|
var ConnectionAbstract = require('../connection');
|
||||||
var ConnectionFault = require('../errors').ConnectionFault;
|
var ConnectionFault = require('../errors').ConnectionFault;
|
||||||
var asyncDefault = !(navigator && /PhantomJS/i.test(navigator.userAgent));
|
var asyncDefault = !(navigator && /PhantomJS/i.test(navigator.userAgent));
|
||||||
@ -15,13 +15,13 @@ var asyncDefault = !(navigator && /PhantomJS/i.test(navigator.userAgent));
|
|||||||
function XhrConnector(host, config) {
|
function XhrConnector(host, config) {
|
||||||
ConnectionAbstract.call(this, host, config);
|
ConnectionAbstract.call(this, host, config);
|
||||||
}
|
}
|
||||||
_v4.inherits(XhrConnector, ConnectionAbstract);
|
_.inherits(XhrConnector, ConnectionAbstract);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply returns an XHR object cross browser
|
* Simply returns an XHR object cross browser
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
*/
|
*/
|
||||||
var getXhr = _v4.noop;
|
var getXhr = _.noop;
|
||||||
|
|
||||||
if (typeof XMLHttpRequest !== 'undefined') {
|
if (typeof XMLHttpRequest !== 'undefined') {
|
||||||
// rewrite the getXhr method to always return the native implementation
|
// rewrite the getXhr method to always return the native implementation
|
||||||
@ -30,7 +30,7 @@ if (typeof XMLHttpRequest !== 'undefined') {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// find the first MS implementation available
|
// 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) {
|
.map(function (appName) {
|
||||||
/* jshint unused: false */
|
/* jshint unused: false */
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
var qs = require('querystring');
|
var qs = require('querystring');
|
||||||
var errors = module.exports;
|
var errors = module.exports;
|
||||||
|
|
||||||
@ -21,21 +21,21 @@ function ErrorAbstract(msg, constructor, metadata) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
_v4.assign(this, metadata);
|
_.assign(this, metadata);
|
||||||
|
|
||||||
this.toString = function () {
|
this.toString = function () {
|
||||||
return msg + ' :: ' + JSON.stringify(metadata);
|
return msg + ' :: ' + JSON.stringify(metadata);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toJSON = function () {
|
this.toJSON = function () {
|
||||||
return _v4.assign({
|
return _.assign({
|
||||||
msg: msg
|
msg: msg
|
||||||
}, metadata);
|
}, metadata);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errors._Abstract = ErrorAbstract;
|
errors._Abstract = ErrorAbstract;
|
||||||
_v4.inherits(ErrorAbstract, Error);
|
_.inherits(ErrorAbstract, Error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection Error
|
* Connection Error
|
||||||
@ -44,7 +44,7 @@ _v4.inherits(ErrorAbstract, Error);
|
|||||||
errors.ConnectionFault = function ConnectionFault(msg) {
|
errors.ConnectionFault = function ConnectionFault(msg) {
|
||||||
ErrorAbstract.call(this, msg || 'Connection Failure', errors.ConnectionFault);
|
ErrorAbstract.call(this, msg || 'Connection Failure', errors.ConnectionFault);
|
||||||
};
|
};
|
||||||
_v4.inherits(errors.ConnectionFault, ErrorAbstract);
|
_.inherits(errors.ConnectionFault, ErrorAbstract);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No Living Connections
|
* No Living Connections
|
||||||
@ -53,7 +53,7 @@ _v4.inherits(errors.ConnectionFault, ErrorAbstract);
|
|||||||
errors.NoConnections = function NoConnections(msg) {
|
errors.NoConnections = function NoConnections(msg) {
|
||||||
ErrorAbstract.call(this, msg || 'No Living connections', errors.NoConnections);
|
ErrorAbstract.call(this, msg || 'No Living connections', errors.NoConnections);
|
||||||
};
|
};
|
||||||
_v4.inherits(errors.NoConnections, ErrorAbstract);
|
_.inherits(errors.NoConnections, ErrorAbstract);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic Error
|
* Generic Error
|
||||||
@ -62,7 +62,7 @@ _v4.inherits(errors.NoConnections, ErrorAbstract);
|
|||||||
errors.Generic = function Generic(msg, metadata) {
|
errors.Generic = function Generic(msg, metadata) {
|
||||||
ErrorAbstract.call(this, msg || 'Generic Error', errors.Generic, metadata);
|
ErrorAbstract.call(this, msg || 'Generic Error', errors.Generic, metadata);
|
||||||
};
|
};
|
||||||
_v4.inherits(errors.Generic, ErrorAbstract);
|
_.inherits(errors.Generic, ErrorAbstract);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request Timeout Error
|
* Request Timeout Error
|
||||||
@ -71,7 +71,7 @@ _v4.inherits(errors.Generic, ErrorAbstract);
|
|||||||
errors.RequestTimeout = function RequestTimeout(msg) {
|
errors.RequestTimeout = function RequestTimeout(msg) {
|
||||||
ErrorAbstract.call(this, msg || 'Request Timeout', errors.RequestTimeout);
|
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) {
|
errors.Serialization = function Serialization(msg) {
|
||||||
ErrorAbstract.call(this, msg || 'Unable to parse/serialize body', errors.Serialization);
|
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) {
|
errors.RequestTypeError = function RequestTypeError(feature) {
|
||||||
ErrorAbstract.call(this, 'Cross-domain AJAX requests ' + feature + ' are not supported', errors.RequestTypeError);
|
ErrorAbstract.call(this, 'Cross-domain AJAX requests ' + feature + ' are not supported', errors.RequestTypeError);
|
||||||
};
|
};
|
||||||
_v4.inherits(errors.RequestTypeError, ErrorAbstract);
|
_.inherits(errors.RequestTypeError, ErrorAbstract);
|
||||||
|
|
||||||
var statusCodes = [
|
var statusCodes = [
|
||||||
[300, 'Multiple Choices'],
|
[300, 'Multiple Choices'],
|
||||||
@ -137,20 +137,20 @@ var statusCodes = [
|
|||||||
[510, 'Not Extended']
|
[510, 'Not Extended']
|
||||||
];
|
];
|
||||||
|
|
||||||
_v4.each(statusCodes, function createStatusCodeError(tuple) {
|
_.each(statusCodes, function createStatusCodeError(tuple) {
|
||||||
var status = tuple[0];
|
var status = tuple[0];
|
||||||
var names = tuple[1];
|
var names = tuple[1];
|
||||||
var allNames = [].concat(names, status);
|
var allNames = [].concat(names, status);
|
||||||
var primaryName = allNames[0];
|
var primaryName = allNames[0];
|
||||||
var className = _v4.studlyCase(primaryName);
|
var className = _.studlyCase(primaryName);
|
||||||
allNames = _v4.uniq(allNames.concat(className));
|
allNames = _.uniq(allNames.concat(className));
|
||||||
|
|
||||||
function StatusCodeError(msg, metadata) {
|
function StatusCodeError(msg, metadata) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.displayName = className;
|
this.displayName = className;
|
||||||
|
|
||||||
var esErrObject = null;
|
var esErrObject = null;
|
||||||
if (_v4.isPlainObject(msg)) {
|
if (_.isPlainObject(msg)) {
|
||||||
esErrObject = msg;
|
esErrObject = msg;
|
||||||
msg = null;
|
msg = null;
|
||||||
}
|
}
|
||||||
@ -168,8 +168,8 @@ _v4.each(statusCodes, function createStatusCodeError(tuple) {
|
|||||||
|
|
||||||
memo += '[' + cause.type + '] ' + cause.reason;
|
memo += '[' + cause.type + '] ' + cause.reason;
|
||||||
|
|
||||||
var extraData = _v4.omit(cause, ['type', 'reason']);
|
var extraData = _.omit(cause, ['type', 'reason']);
|
||||||
if (_v4.size(extraData)) {
|
if (_.size(extraData)) {
|
||||||
memo += ', with { ' + qs.stringify(extraData, ' ', '=', {
|
memo += ', with { ' + qs.stringify(extraData, ' ', '=', {
|
||||||
encodeURIComponent: function (v) {
|
encodeURIComponent: function (v) {
|
||||||
return String(v).split('\n').join('\\n');
|
return String(v).split('\n').join('\\n');
|
||||||
@ -188,7 +188,7 @@ _v4.each(statusCodes, function createStatusCodeError(tuple) {
|
|||||||
ErrorAbstract.call(this, msg || primaryName, StatusCodeError, metadata);
|
ErrorAbstract.call(this, msg || primaryName, StatusCodeError, metadata);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
_v4.inherits(StatusCodeError, ErrorAbstract);
|
_.inherits(StatusCodeError, ErrorAbstract);
|
||||||
|
|
||||||
allNames.forEach(function (name) {
|
allNames.forEach(function (name) {
|
||||||
errors[name] = StatusCodeError;
|
errors[name] = StatusCodeError;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ module.exports = Host;
|
|||||||
|
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var qs = require('querystring');
|
var qs = require('querystring');
|
||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
|
|
||||||
var startsWithProtocolRE = /^([a-z]+:)?\/\//;
|
var startsWithProtocolRE = /^([a-z]+:)?\/\//;
|
||||||
var defaultProto = 'http:';
|
var defaultProto = 'http:';
|
||||||
@ -46,7 +46,7 @@ Host.defaultPorts = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Host(config, globalConfig) {
|
function Host(config, globalConfig) {
|
||||||
config = _v4.clone(config || {});
|
config = _.clone(config || {});
|
||||||
globalConfig = globalConfig || {};
|
globalConfig = globalConfig || {};
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
@ -58,7 +58,7 @@ function Host(config, globalConfig) {
|
|||||||
this.headers = null;
|
this.headers = null;
|
||||||
this.suggestCompression = !!globalConfig.suggestCompression;
|
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') {
|
if (typeof config === 'string') {
|
||||||
var firstColon = config.indexOf(':');
|
var firstColon = config.indexOf(':');
|
||||||
@ -69,7 +69,7 @@ function Host(config, globalConfig) {
|
|||||||
if ((noSlash || portNoPath || portWithPath) && !startsWithProtocolRE.test(config)) {
|
if ((noSlash || portNoPath || portWithPath) && !startsWithProtocolRE.test(config)) {
|
||||||
config = defaultProto + '//' + 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,
|
// 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.
|
// we will use the default from the protocol of the string.
|
||||||
if (!config.port) {
|
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.
|
// move hostname/portname to host/port semi-intelligently.
|
||||||
_v4.each(simplify, function (to) {
|
_.each(simplify, function (to) {
|
||||||
var from = to + 'name';
|
var from = to + 'name';
|
||||||
if (config[from] && config[to]) {
|
if (config[from] && config[to]) {
|
||||||
if (config[to].indexOf(config[from]) === 0) {
|
if (config[to].indexOf(config[from]) === 0) {
|
||||||
@ -106,20 +106,20 @@ function Host(config, globalConfig) {
|
|||||||
delete config.auth;
|
delete config.auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
_v4.forOwn(config, _v4.bind(function (val, prop) {
|
_.forOwn(config, _.bind(function (val, prop) {
|
||||||
if (val != null) this[prop] = _v4.clone(val);
|
if (val != null) this[prop] = _.clone(val);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
// make sure the query string is parsed
|
// make sure the query string is parsed
|
||||||
if (this.query === null) {
|
if (this.query === null) {
|
||||||
// majority case
|
// majority case
|
||||||
this.query = {};
|
this.query = {};
|
||||||
} else if (!_v4.isPlainObject(this.query)) {
|
} else if (!_.isPlainObject(this.query)) {
|
||||||
this.query = qs.parse(this.query);
|
this.query = qs.parse(this.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that the port is a number
|
// make sure that the port is a number
|
||||||
if (_v4.isNumeric(this.port)) {
|
if (_.isNumeric(this.port)) {
|
||||||
this.port = parseInt(this.port, 10);
|
this.port = parseInt(this.port, 10);
|
||||||
} else {
|
} else {
|
||||||
this.port = 9200;
|
this.port = 9200;
|
||||||
@ -177,10 +177,10 @@ function objectPropertyGetter(prop, preOverride) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (overrides) {
|
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 overrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _v4.defaults(overrides || {}, {
|
return _.defaults(overrides || {}, {
|
||||||
'Accept-Encoding': 'gzip,deflate'
|
'Accept-Encoding': 'gzip,deflate'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
@ -24,13 +24,13 @@ function Log(config) {
|
|||||||
var i;
|
var i;
|
||||||
var outputs;
|
var outputs;
|
||||||
|
|
||||||
if (_v4.isArrayOfStrings(config.log)) {
|
if (_.isArrayOfStrings(config.log)) {
|
||||||
outputs = [{
|
outputs = [{
|
||||||
levels: config.log
|
levels: config.log
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
outputs = _v4.createArray(config.log, function (val) {
|
outputs = _.createArray(config.log, function (val) {
|
||||||
if (_v4.isPlainObject(val)) {
|
if (_.isPlainObject(val)) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
@ -50,7 +50,7 @@ function Log(config) {
|
|||||||
this.addOutput(outputs[i]);
|
this.addOutput(outputs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_v4.inherits(Log, EventEmitter);
|
_.inherits(Log, EventEmitter);
|
||||||
|
|
||||||
Log.loggers = require('./loggers');
|
Log.loggers = require('./loggers');
|
||||||
|
|
||||||
@ -151,14 +151,14 @@ Log.levels = [
|
|||||||
Log.parseLevels = function (input) {
|
Log.parseLevels = function (input) {
|
||||||
switch (typeof input) {
|
switch (typeof input) {
|
||||||
case 'string':
|
case 'string':
|
||||||
var i = _v4.indexOf(Log.levels, input);
|
var i = _.indexOf(Log.levels, input);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
return Log.levels.slice(0, i + 1);
|
return Log.levels.slice(0, i + 1);
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'object':
|
case 'object':
|
||||||
if (_v4.isArray(input)) {
|
if (_.isArray(input)) {
|
||||||
var valid = _v4.intersection(input, Log.levels);
|
var valid = _.intersection(input, Log.levels);
|
||||||
if (valid.length === input.length) {
|
if (valid.length === input.length) {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
@ -176,13 +176,13 @@ Log.parseLevels = function (input) {
|
|||||||
* @method join
|
* @method join
|
||||||
* @static
|
* @static
|
||||||
* @private
|
* @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.
|
* @return {String} - The final string.
|
||||||
*/
|
*/
|
||||||
Log.join = function (arrayish) {
|
Log.join = function (arrayish) {
|
||||||
return _v4.map(arrayish, function (item) {
|
return _.map(arrayish, function (item) {
|
||||||
if (_v4.isPlainObject(item)) {
|
if (_.isPlainObject(item)) {
|
||||||
return _v4.inspect(item) + '\n';
|
return _.inspect(item) + '\n';
|
||||||
} else {
|
} else {
|
||||||
return item.toString();
|
return item.toString();
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ Log.prototype.addOutput = function (config) {
|
|||||||
config.levels = Log.parseLevels(config.levels || config.level || 'warning');
|
config.levels = Log.parseLevels(config.levels || config.level || 'warning');
|
||||||
delete config.level;
|
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);
|
return new Logger(this, config);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ Log.normalizeTraceArgs = function (method, requestUrl, body, responseBody, respo
|
|||||||
if (typeof requestUrl === 'string') {
|
if (typeof requestUrl === 'string') {
|
||||||
requestUrl = url.parse(requestUrl, true, true);
|
requestUrl = url.parse(requestUrl, true, true);
|
||||||
} else {
|
} else {
|
||||||
requestUrl = _v4.clone(requestUrl);
|
requestUrl = _.clone(requestUrl);
|
||||||
if (requestUrl.path) {
|
if (requestUrl.path) {
|
||||||
requestUrl.query = url.parse(requestUrl.path, true, false).query;
|
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
|
* Abstract class providing common functionality to loggers
|
||||||
@ -9,7 +9,7 @@ function LoggerAbstract(log, config) {
|
|||||||
this.log = log;
|
this.log = log;
|
||||||
this.listeningLevels = [];
|
this.listeningLevels = [];
|
||||||
|
|
||||||
_v4.makeBoundMethods(this);
|
_.makeBoundMethods(this);
|
||||||
|
|
||||||
// when the log closes, remove our event listeners
|
// when the log closes, remove our event listeners
|
||||||
this.log.once('closing', this.bound.cleanUpListeners);
|
this.log.once('closing', this.bound.cleanUpListeners);
|
||||||
@ -37,7 +37,7 @@ LoggerAbstract.prototype.timestamp = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function indent(text, spaces) {
|
function indent(text, spaces) {
|
||||||
var space = _v4.repeat(' ', spaces || 2);
|
var space = _.repeat(' ', spaces || 2);
|
||||||
return (text || '').split(/\r?\n/).map(function (line) {
|
return (text || '').split(/\r?\n/).map(function (line) {
|
||||||
return space + line;
|
return space + line;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
@ -64,8 +64,8 @@ LoggerAbstract.prototype.setupListeners = function (levels) {
|
|||||||
|
|
||||||
this.listeningLevels = [];
|
this.listeningLevels = [];
|
||||||
|
|
||||||
_v4.each(levels, _v4.bind(function (level) {
|
_.each(levels, _.bind(function (level) {
|
||||||
var fnName = 'on' + _v4.ucfirst(level);
|
var fnName = 'on' + _.ucfirst(level);
|
||||||
if (this.bound[fnName]) {
|
if (this.bound[fnName]) {
|
||||||
this.listeningLevels.push(level);
|
this.listeningLevels.push(level);
|
||||||
this.log.on(level, this.bound[fnName]);
|
this.log.on(level, this.bound[fnName]);
|
||||||
@ -82,9 +82,9 @@ LoggerAbstract.prototype.setupListeners = function (levels) {
|
|||||||
* @private
|
* @private
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
LoggerAbstract.prototype.cleanUpListeners = _v4.handler(function () {
|
LoggerAbstract.prototype.cleanUpListeners = _.handler(function () {
|
||||||
_v4.each(this.listeningLevels, _v4.bind(function (level) {
|
_.each(this.listeningLevels, _.bind(function (level) {
|
||||||
this.log.removeListener(level, this.bound['on' + _v4.ucfirst(level)]);
|
this.log.removeListener(level, this.bound['on' + _.ucfirst(level)]);
|
||||||
}, this));
|
}, this));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ LoggerAbstract.prototype.cleanUpListeners = _v4.handler(function () {
|
|||||||
* @param {Error} e - The Error object to log
|
* @param {Error} e - The Error object to log
|
||||||
* @return {undefined}
|
* @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);
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
LoggerAbstract.prototype.onWarning = _v4.handler(function (msg) {
|
LoggerAbstract.prototype.onWarning = _.handler(function (msg) {
|
||||||
this.write('WARNING', msg);
|
this.write('WARNING', msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ LoggerAbstract.prototype.onWarning = _v4.handler(function (msg) {
|
|||||||
* @param {String} msg - The message to be logged
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
LoggerAbstract.prototype.onInfo = _v4.handler(function (msg) {
|
LoggerAbstract.prototype.onInfo = _.handler(function (msg) {
|
||||||
this.write('INFO', msg);
|
this.write('INFO', msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ LoggerAbstract.prototype.onInfo = _v4.handler(function (msg) {
|
|||||||
* @param {String} msg - The message to be logged
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
LoggerAbstract.prototype.onDebug = _v4.handler(function (msg) {
|
LoggerAbstract.prototype.onDebug = _.handler(function (msg) {
|
||||||
this.write('DEBUG', msg);
|
this.write('DEBUG', msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ LoggerAbstract.prototype.onDebug = _v4.handler(function (msg) {
|
|||||||
* @param {String} msg - The message to be logged
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
LoggerAbstract.prototype.onTrace = _v4.handler(function (requestDetails) {
|
LoggerAbstract.prototype.onTrace = _.handler(function (requestDetails) {
|
||||||
this.write('TRACE', this._formatTraceMessage(requestDetails));
|
this.write('TRACE', this._formatTraceMessage(requestDetails));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -13,15 +13,15 @@
|
|||||||
module.exports = Console;
|
module.exports = Console;
|
||||||
|
|
||||||
var LoggerAbstract = require('../logger');
|
var LoggerAbstract = require('../logger');
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
|
|
||||||
function Console(log, config) {
|
function Console(log, config) {
|
||||||
LoggerAbstract.call(this, log, config);
|
LoggerAbstract.call(this, log, config);
|
||||||
|
|
||||||
// config/state
|
// 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
|
* 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
|
* @param {Error} e - The Error object to log
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Console.prototype.onError = _v4.handler(function (e) {
|
Console.prototype.onError = _.handler(function (e) {
|
||||||
var to = console.error ? 'error' : 'log';
|
var to = console.error ? 'error' : 'log';
|
||||||
this.write(e.name === 'Error' ? 'ERROR' : e.name, e.stack || e.message, to);
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Console.prototype.onWarning = _v4.handler(function (msg) {
|
Console.prototype.onWarning = _.handler(function (msg) {
|
||||||
this.write('WARNING', msg, console.warn ? 'warn' : 'log');
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Console.prototype.onInfo = _v4.handler(function (msg) {
|
Console.prototype.onInfo = _.handler(function (msg) {
|
||||||
this.write('INFO', msg, console.info ? 'info' : 'log');
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Console.prototype.onDebug = _v4.handler(function (msg) {
|
Console.prototype.onDebug = _.handler(function (msg) {
|
||||||
this.write('DEBUG', msg, console.debug ? 'debug' : 'log');
|
this.write('DEBUG', msg, console.debug ? 'debug' : 'log');
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
@ -94,6 +94,6 @@ Console.prototype.onDebug = _v4.handler(function (msg) {
|
|||||||
* @private
|
* @private
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Console.prototype.onTrace = _v4.handler(function (msg) {
|
Console.prototype.onTrace = _.handler(function (msg) {
|
||||||
this.write('TRACE', this._formatTraceMessage(msg), 'log');
|
this.write('TRACE', this._formatTraceMessage(msg), 'log');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
module.exports = File;
|
module.exports = File;
|
||||||
|
|
||||||
var StreamLogger = require('./stream');
|
var StreamLogger = require('./stream');
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
function File(log, config) {
|
function File(log, config) {
|
||||||
@ -29,10 +29,10 @@ function File(log, config) {
|
|||||||
|
|
||||||
StreamLogger.call(this, log, config);
|
StreamLogger.call(this, log, config);
|
||||||
}
|
}
|
||||||
_v4.inherits(File, StreamLogger);
|
_.inherits(File, StreamLogger);
|
||||||
|
|
||||||
File.prototype.onProcessExit = _v4.handler(function () {
|
File.prototype.onProcessExit = _.handler(function () {
|
||||||
var toWrite = _v4.getUnwrittenFromStream(this.stream);
|
var toWrite = _.getUnwrittenFromStream(this.stream);
|
||||||
if (toWrite) {
|
if (toWrite) {
|
||||||
fs.appendFileSync(this.path, toWrite);
|
fs.appendFileSync(this.path, toWrite);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ var chalk = require('chalk');
|
|||||||
chalk.enabled = true;
|
chalk.enabled = true;
|
||||||
|
|
||||||
var LoggerAbstract = require('../logger');
|
var LoggerAbstract = require('../logger');
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
|
|
||||||
var defaultColors = {
|
var defaultColors = {
|
||||||
error: chalk.red.bold,
|
error: chalk.red.bold,
|
||||||
@ -31,12 +31,12 @@ function Stdio(log, config) {
|
|||||||
LoggerAbstract.call(this, log, config);
|
LoggerAbstract.call(this, log, config);
|
||||||
|
|
||||||
// config/state
|
// 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
|
* 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
|
* @param {Error} e - The Error object to log
|
||||||
* @return {undefined}
|
* @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);
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Stdio.prototype.onWarning = _v4.handler(function (msg) {
|
Stdio.prototype.onWarning = _.handler(function (msg) {
|
||||||
this.write('WARNING', msg, process.stderr, this.colors.warning);
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Stdio.prototype.onInfo = _v4.handler(function (msg) {
|
Stdio.prototype.onInfo = _.handler(function (msg) {
|
||||||
this.write('INFO', msg, process.stdout, this.colors.info);
|
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
|
* @param {String} msg - The message to be logged
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Stdio.prototype.onDebug = _v4.handler(function (msg) {
|
Stdio.prototype.onDebug = _.handler(function (msg) {
|
||||||
this.write('DEBUG', msg, process.stdout, this.colors.debug);
|
this.write('DEBUG', msg, process.stdout, this.colors.debug);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,6 +112,6 @@ Stdio.prototype.onDebug = _v4.handler(function (msg) {
|
|||||||
* @private
|
* @private
|
||||||
* @return {undefined}
|
* @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);
|
this.write('TRACE', this._formatTraceMessage(message), process.stdout, this.colors.trace);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
module.exports = Stream;
|
module.exports = Stream;
|
||||||
|
|
||||||
var LoggerAbstract = require('../logger');
|
var LoggerAbstract = require('../logger');
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
|
|
||||||
function Stream(log, config) {
|
function Stream(log, config) {
|
||||||
LoggerAbstract.call(this, log, config);
|
LoggerAbstract.call(this, log, config);
|
||||||
@ -26,17 +26,17 @@ function Stream(log, config) {
|
|||||||
|
|
||||||
process.once('exit', this.bound.onProcessExit);
|
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);
|
process.removeListener('exit', this.bound.onProcessExit);
|
||||||
LoggerAbstract.prototype.cleanUpListeners.call(this);
|
LoggerAbstract.prototype.cleanUpListeners.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// flush the write buffer to stderr synchronously
|
// 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.
|
// process is dying, lets manually flush the buffer synchronously to stderr.
|
||||||
var unwritten = _v4.getUnwrittenFromStream(this.stream);
|
var unwritten = _.getUnwrittenFromStream(this.stream);
|
||||||
if (unwritten) {
|
if (unwritten) {
|
||||||
console.error('Log stream did not get to finish writing. Flushing to stderr');
|
console.error('Log stream did not get to finish writing. Flushing to stderr');
|
||||||
console.error(unwritten);
|
console.error(unwritten);
|
||||||
|
|||||||
@ -14,7 +14,7 @@ module.exports = Tracer;
|
|||||||
|
|
||||||
var StreamLogger = require('./stream');
|
var StreamLogger = require('./stream');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
|
|
||||||
function Tracer(log, config) {
|
function Tracer(log, config) {
|
||||||
@ -29,18 +29,18 @@ function Tracer(log, config) {
|
|||||||
|
|
||||||
StreamLogger.call(this, log, config);
|
StreamLogger.call(this, log, config);
|
||||||
}
|
}
|
||||||
_v4.inherits(Tracer, StreamLogger);
|
_.inherits(Tracer, StreamLogger);
|
||||||
|
|
||||||
var usefulUrlFields = ['protocol', 'slashes', 'port', 'hostname', 'pathname', 'query'];
|
var usefulUrlFields = ['protocol', 'slashes', 'port', 'hostname', 'pathname', 'query'];
|
||||||
|
|
||||||
Tracer.prototype._formatTraceMessage = function (req) {
|
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.port = this.curlPort;
|
||||||
reqUrl.hostname = this.curlHost;
|
reqUrl.hostname = this.curlHost;
|
||||||
reqUrl.query = _v4.defaults(reqUrl.query || {}, { pretty: true });
|
reqUrl.query = _.defaults(reqUrl.query || {}, { pretty: true });
|
||||||
|
|
||||||
/* jshint quotmark: double */
|
/* jshint quotmark: double */
|
||||||
var curlCall =
|
var curlCall =
|
||||||
@ -56,7 +56,7 @@ Tracer.prototype._formatTraceMessage = function (req) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function comment(str) {
|
function comment(str) {
|
||||||
return _v4.map(str.split(/\r?\n/g), function (line) {
|
return _.map(str.split(/\r?\n/g), function (line) {
|
||||||
return '# ' + line;
|
return '# ' + line;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
|
|
||||||
var extractHostPartsRE1x = /\[\/*([^:]+):(\d+)\]/;
|
var extractHostPartsRE1x = /\[\/*([^:]+):(\d+)\]/;
|
||||||
|
|
||||||
function makeNodeParser(hostProp) {
|
function makeNodeParser(hostProp) {
|
||||||
return function (nodes) {
|
return function (nodes) {
|
||||||
return _v4.transform(nodes, function (hosts, node, id) {
|
return _.transform(nodes, function (hosts, node, id) {
|
||||||
var address = node[hostProp]
|
var address = node[hostProp]
|
||||||
if (!address) return;
|
if (!address) return;
|
||||||
|
|
||||||
|
|||||||
4
src/lib/serializers/angular.js
vendored
4
src/lib/serializers/angular.js
vendored
@ -1,9 +1,9 @@
|
|||||||
/* global angular */
|
/* global angular */
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
var JsonSerializer = require('../serializers/json');
|
var JsonSerializer = require('../serializers/json');
|
||||||
|
|
||||||
function AngularSerializer() {}
|
function AngularSerializer() {}
|
||||||
_v4.inherits(AngularSerializer, JsonSerializer);
|
_.inherits(AngularSerializer, JsonSerializer);
|
||||||
|
|
||||||
// mimic the JsonSerializer's encode method, but use angular's toJson instead
|
// mimic the JsonSerializer's encode method, but use angular's toJson instead
|
||||||
AngularSerializer.prototype.encode = function (val) {
|
AngularSerializer.prototype.encode = function (val) {
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = Json;
|
module.exports = Json;
|
||||||
|
|
||||||
// var _ = require('../utils');
|
var _ = require('../utils');
|
||||||
|
|
||||||
function Json() {}
|
function Json() {}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ Json.prototype.deserialize = function (str) {
|
|||||||
Json.prototype.bulkBody = function (val) {
|
Json.prototype.bulkBody = function (val) {
|
||||||
var body = '', i;
|
var body = '', i;
|
||||||
|
|
||||||
if (_v4.isArray(val)) {
|
if (_.isArray(val)) {
|
||||||
for (i = 0; i < val.length; i++) {
|
for (i = 0; i < val.length; i++) {
|
||||||
body += this.serialize(val[i]) + '\n';
|
body += this.serialize(val[i]) + '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = Transport;
|
module.exports = Transport;
|
||||||
|
|
||||||
// var _ = require('./utils');
|
var _ = require('./utils');
|
||||||
var errors = require('./errors');
|
var errors = require('./errors');
|
||||||
var Host = require('./host');
|
var Host = require('./host');
|
||||||
var Promise = require('promise/lib/es6-extensions');
|
var Promise = require('promise/lib/es6-extensions');
|
||||||
@ -19,15 +19,15 @@ function Transport(config) {
|
|||||||
config.log = self.log = new LogClass(config);
|
config.log = self.log = new LogClass(config);
|
||||||
|
|
||||||
// setup the connection pool
|
// 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);
|
self.connectionPool = new ConnectionPool(config);
|
||||||
|
|
||||||
// setup the serializer
|
// 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);
|
self.serializer = new Serializer(config);
|
||||||
|
|
||||||
// setup the nodesToHostCallback
|
// setup the nodesToHostCallback
|
||||||
self.nodesToHostCallback = _v4.funcEnum(config, 'nodesToHostCallback', Transport.nodesToHostCallbacks, 'main');
|
self.nodesToHostCallback = _.funcEnum(config, 'nodesToHostCallback', Transport.nodesToHostCallbacks, 'main');
|
||||||
|
|
||||||
// setup max retries
|
// setup max retries
|
||||||
self.maxRetries = config.hasOwnProperty('maxRetries') ? config.maxRetries : 3;
|
self.maxRetries = config.hasOwnProperty('maxRetries') ? config.maxRetries : 3;
|
||||||
@ -50,8 +50,8 @@ function Transport(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.hosts) {
|
if (config.hosts) {
|
||||||
var hostsConfig = _v4.createArray(config.hosts, function (val) {
|
var hostsConfig = _.createArray(config.hosts, function (val) {
|
||||||
if (_v4.isPlainObject(val) || _v4.isString(val) || val instanceof Host) {
|
if (_.isPlainObject(val) || _.isString(val) || val instanceof Host) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -62,7 +62,7 @@ function Transport(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (randomizeHosts) {
|
if (randomizeHosts) {
|
||||||
hostsConfig = _v4.shuffle(hostsConfig);
|
hostsConfig = _.shuffle(hostsConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setHosts(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 defer; // the defer object, will be set when we are using promises.
|
||||||
|
|
||||||
var body = params.body;
|
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;
|
headers[String(name).toLowerCase()] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ Transport.prototype.request = function (params, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (body && params.method === 'GET') {
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,10 +274,10 @@ Transport.prototype.request = function (params, cb) {
|
|||||||
if (
|
if (
|
||||||
(!err || err instanceof errors.Serialization)
|
(!err || err instanceof errors.Serialization)
|
||||||
&& (status < 200 || status >= 300)
|
&& (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.statusCode = status;
|
||||||
errorMetadata.response = body;
|
errorMetadata.response = body;
|
||||||
|
|
||||||
@ -361,7 +361,7 @@ Transport.prototype._timeout = function (cb, delay) {
|
|||||||
if (cb) {
|
if (cb) {
|
||||||
// set the timer
|
// set the timer
|
||||||
id = setTimeout(function () {
|
id = setTimeout(function () {
|
||||||
_v4.pull(timers, id);
|
_.pull(timers, id);
|
||||||
cb();
|
cb();
|
||||||
}, delay);
|
}, delay);
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ Transport.prototype.sniff = function (cb) {
|
|||||||
var sniffedNodesProtocol = this.sniffedNodesProtocol;
|
var sniffedNodesProtocol = this.sniffedNodesProtocol;
|
||||||
|
|
||||||
// make cb a function if it isn't
|
// make cb a function if it isn't
|
||||||
cb = typeof cb === 'function' ? cb : _v4.noop;
|
cb = typeof cb === 'function' ? cb : _.noop;
|
||||||
|
|
||||||
this.request({
|
this.request({
|
||||||
path: this.sniffEndpoint,
|
path: this.sniffEndpoint,
|
||||||
@ -409,7 +409,7 @@ Transport.prototype.sniff = function (cb) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_v4.forEach(hostsConfigs, function (hostConfig) {
|
_.forEach(hostsConfigs, function (hostConfig) {
|
||||||
if (sniffedNodesProtocol) hostConfig.protocol = sniffedNodesProtocol;
|
if (sniffedNodesProtocol) hostConfig.protocol = sniffedNodesProtocol;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -427,7 +427,7 @@ Transport.prototype.sniff = function (cb) {
|
|||||||
*/
|
*/
|
||||||
Transport.prototype.setHosts = function (hostsConfigs) {
|
Transport.prototype.setHosts = function (hostsConfigs) {
|
||||||
var globalConfig = this._config;
|
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);
|
return (conf instanceof Host) ? conf : new Host(conf, globalConfig);
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
@ -439,7 +439,7 @@ Transport.prototype.setHosts = function (hostsConfigs) {
|
|||||||
Transport.prototype.close = function () {
|
Transport.prototype.close = function () {
|
||||||
this.log.close();
|
this.log.close();
|
||||||
this.closed = true;
|
this.closed = true;
|
||||||
_v4.each(this._timers, clearTimeout);
|
_.each(this._timers, clearTimeout);
|
||||||
this._timers = null;
|
this._timers = null;
|
||||||
this.connectionPool.close();
|
this.connectionPool.close();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var isEmpty = require('lodash-migrate').isEmpty;
|
var isEmpty = require('lodash').isEmpty;
|
||||||
|
|
||||||
module.exports = function (hosts) {
|
module.exports = function (hosts) {
|
||||||
if (isEmpty(hosts)) return false;
|
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
|
// create a function that will count down to a
|
||||||
// point n milliseconds into the future
|
// point n milliseconds into the future
|
||||||
var countdownTo = function (ms) {
|
var countdownTo = function (ms) {
|
||||||
var start = _v4.now();
|
var start = _.now();
|
||||||
return function () {
|
return function () {
|
||||||
return start - ms;
|
return start - ms;
|
||||||
};
|
};
|
||||||
|
|||||||
103
src/lib/utils.js
103
src/lib/utils.js
@ -1,26 +1,23 @@
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
// var _ = require('lodash');
|
|
||||||
// require('../../stub')
|
|
||||||
var nodeUtils = require('util');
|
var nodeUtils = require('util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom _v4 library, basically a modified version of [lodash](http://lodash.com/docs) +
|
* Custom _ 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
|
* [node._](http://nodejs.org/api/util.html#util_util) that doesn't use mixins to prevent
|
||||||
* confusion when requiring lodash itself.
|
* confusion when requiring lodash itself.
|
||||||
*
|
*
|
||||||
* @class _v4
|
* @class _
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
_v4.assign(_v4, nodeUtils);
|
var _ = require('lodash').assign({}, require('lodash'), nodeUtils);
|
||||||
// _v4 = _v4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link to [path.join](http://nodejs.org/api/path.html#path_path_join_path1_path2)
|
* Link to [path.join](http://nodejs.org/api/path.html#path_path_join_path1_path2)
|
||||||
*
|
*
|
||||||
* @method _v4.joinPath
|
* @method _.joinPath
|
||||||
* @type {function}
|
* @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
|
* 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
|
* @param {Object} from - Object to pull changed from
|
||||||
* @return {Object} - returns the modified to value
|
* @return {Object} - returns the modified to value
|
||||||
*/
|
*/
|
||||||
_v4.deepMerge = function (to, from) {
|
_.deepMerge = function (to, from) {
|
||||||
_v4.each(from, function (fromVal, key) {
|
_.each(from, function (fromVal, key) {
|
||||||
switch (typeof to[key]) {
|
switch (typeof to[key]) {
|
||||||
case 'undefined':
|
case 'undefined':
|
||||||
to[key] = from[key];
|
to[key] = from[key];
|
||||||
break;
|
break;
|
||||||
case 'object':
|
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]);
|
to[key] = to[key].concat(from[key]);
|
||||||
}
|
}
|
||||||
else if (_v4.isPlainObject(to[key]) && _v4.isPlainObject(from[key])) {
|
else if (_.isPlainObject(to[key]) && _.isPlainObject(from[key])) {
|
||||||
_v4.deepMerge(to[key], from[key]);
|
_.deepMerge(to[key], from[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -57,7 +54,7 @@ _v4.deepMerge = function (to, from) {
|
|||||||
* @param {Array} arr - An array to check
|
* @param {Array} arr - An array to check
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
_v4.each([
|
_.each([
|
||||||
'String',
|
'String',
|
||||||
'Object',
|
'Object',
|
||||||
'PlainObject',
|
'PlainObject',
|
||||||
@ -66,11 +63,11 @@ _v4.each([
|
|||||||
'Function',
|
'Function',
|
||||||
'RegExp'
|
'RegExp'
|
||||||
], function (type) {
|
], 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
|
// 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
|
* @param {string} word - The word to transform
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
_v4.ucfirst = function (word) {
|
_.ucfirst = function (word) {
|
||||||
return word[0].toUpperCase() + word.substring(1).toLowerCase();
|
return word[0].toUpperCase() + word.substring(1).toLowerCase();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,7 +140,7 @@ function adjustWordCase(firstWordCap, otherWordsCap, sep) {
|
|||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
_v4.studlyCase = adjustWordCase(true, true, '');
|
_.studlyCase = adjustWordCase(true, true, '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a string into camelCase
|
* Transform a string into camelCase
|
||||||
@ -152,7 +149,7 @@ _v4.studlyCase = adjustWordCase(true, true, '');
|
|||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
_v4.camelCase = adjustWordCase(false, true, '');
|
_.camelCase = adjustWordCase(false, true, '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a string into snakeCase
|
* Transform a string into snakeCase
|
||||||
@ -161,7 +158,7 @@ _v4.camelCase = adjustWordCase(false, true, '');
|
|||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @return {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
|
* 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
|
* @param any {*} - Something or nothing
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_v4.toLowerString = function (any) {
|
_.toLowerString = function (any) {
|
||||||
if (any) {
|
if (any) {
|
||||||
if (typeof any !== 'string') {
|
if (typeof any !== 'string') {
|
||||||
any = any.toString();
|
any = any.toString();
|
||||||
@ -186,7 +183,7 @@ _v4.toLowerString = function (any) {
|
|||||||
* @param any {*} - Something or nothing
|
* @param any {*} - Something or nothing
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_v4.toUpperString = function (any) {
|
_.toUpperString = function (any) {
|
||||||
if (any) {
|
if (any) {
|
||||||
if (typeof any !== 'string') {
|
if (typeof any !== 'string') {
|
||||||
any = any.toString();
|
any = any.toString();
|
||||||
@ -204,7 +201,7 @@ _v4.toUpperString = function (any) {
|
|||||||
* @param {*} val
|
* @param {*} val
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
_v4.isNumeric = function (val) {
|
_.isNumeric = function (val) {
|
||||||
return typeof val !== 'object' && val - parseFloat(val) >= 0;
|
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
|
* @param {String} val
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
_v4.isInterval = function (val) {
|
_.isInterval = function (val) {
|
||||||
return !!(val.match && val.match(intervalRE));
|
return !!(val.match && val.match(intervalRE));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -231,7 +228,7 @@ _v4.isInterval = function (val) {
|
|||||||
* @param {Number} times - Times the string should be repeated
|
* @param {Number} times - Times the string should be repeated
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
_v4.repeat = function (what, times) {
|
_.repeat = function (what, times) {
|
||||||
return (new Array(times + 1)).join(what);
|
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
|
* @param [sliceIndex=0] {Integer} - The index that args should be sliced at, before feeding args to func
|
||||||
* @returns {*} - the return value of func
|
* @returns {*} - the return value of func
|
||||||
*/
|
*/
|
||||||
_v4.applyArgs = function (func, context, args, sliceIndex) {
|
_.applyArgs = function (func, context, args, sliceIndex) {
|
||||||
sliceIndex = sliceIndex || 0;
|
sliceIndex = sliceIndex || 0;
|
||||||
switch (args.length - sliceIndex) {
|
switch (args.length - sliceIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -270,9 +267,9 @@ _v4.applyArgs = function (func, context, args, sliceIndex) {
|
|||||||
* when it is called.
|
* when it is called.
|
||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
_v4.nextTick = function (cb) {
|
_.nextTick = function (cb) {
|
||||||
// bind the function and schedule it
|
// 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
|
* 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 will always be bound when called via classInstance.bound.methodName
|
||||||
* this === classInstance
|
* this === classInstance
|
||||||
* });
|
* });
|
||||||
@ -290,11 +287,11 @@ _v4.nextTick = function (cb) {
|
|||||||
* @param {Function} func - The method that is being defined
|
* @param {Function} func - The method that is being defined
|
||||||
* @return {Function}
|
* @return {Function}
|
||||||
*/
|
*/
|
||||||
_v4.handler = function (func) {
|
_.handler = function (func) {
|
||||||
func._provideBound = true;
|
func._provideBound = true;
|
||||||
return func;
|
return func;
|
||||||
};
|
};
|
||||||
_v4.scheduled = _v4.handler;
|
_.scheduled = _.handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an "bound" property on an object, which all or a subset of methods from
|
* 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 () {}
|
* onEvent: function () {}
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* _v4.makeBoundMethods(obj);
|
* _.makeBoundMethods(obj);
|
||||||
*
|
*
|
||||||
* obj.bound.onEvent() // is bound to obj, and can safely be used as an event handler.
|
* 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
|
* @param {Object} obj - The object to bind the methods to
|
||||||
*/
|
*/
|
||||||
_v4.makeBoundMethods = function (obj) {
|
_.makeBoundMethods = function (obj) {
|
||||||
obj.bound = {};
|
obj.bound = {};
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
// dearest maintainer, we want to look through the prototype
|
// dearest maintainer, we want to look through the prototype
|
||||||
if (typeof obj[prop] === 'function' && obj[prop]._provideBound === true) {
|
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
|
* 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
|
* @param {Object} opts - a map of the options
|
||||||
* @return {Function|undefined} - If a valid option was specified, then the constructor is returned
|
* @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];
|
var val = config[name];
|
||||||
switch (typeof val) {
|
switch (typeof val) {
|
||||||
case 'undefined':
|
case 'undefined':
|
||||||
@ -344,14 +341,14 @@ _v4.funcEnum = function (config, name, opts, def) {
|
|||||||
/* falls through */
|
/* falls through */
|
||||||
default:
|
default:
|
||||||
var err = 'Invalid ' + name + ' "' + val + '", expected a function';
|
var err = 'Invalid ' + name + ' "' + val + '", expected a function';
|
||||||
switch (_v4.size(opts)) {
|
switch (_.size(opts)) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
err += ' or ' + _v4.keys(opts)[0];
|
err += ' or ' + _.keys(opts)[0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err += ' or one of ' + _v4.keys(opts).join(', ');
|
err += ' or one of ' + _.keys(opts).join(', ');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new TypeError(err);
|
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
|
* @param {Function} transform - A function called for each element of the resulting array
|
||||||
* @return {Array|false} - an array on success, or false on failure.
|
* @return {Array|false} - an array on success, or false on failure.
|
||||||
*/
|
*/
|
||||||
_v4.createArray = function (input, transform) {
|
_.createArray = function (input, transform) {
|
||||||
transform = typeof transform === 'function' ? transform : _v4.identity;
|
transform = typeof transform === 'function' ? transform : _.identity;
|
||||||
var output = [];
|
var output = [];
|
||||||
var item;
|
var item;
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
if (!_v4.isArray(input)) {
|
if (!_.isArray(input)) {
|
||||||
input = [input];
|
input = [input];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,19 +394,19 @@ _v4.createArray = function (input, transform) {
|
|||||||
* @param {WritableStream} stream - an instance of stream.Writable
|
* @param {WritableStream} stream - an instance of stream.Writable
|
||||||
* @return {string} - the remaining test to be written to the stream
|
* @return {string} - the remaining test to be written to the stream
|
||||||
*/
|
*/
|
||||||
_v4.getUnwrittenFromStream = function (stream) {
|
_.getUnwrittenFromStream = function (stream) {
|
||||||
var writeBuffer = _v4.getStreamWriteBuffer(stream);
|
var writeBuffer = _.getStreamWriteBuffer(stream);
|
||||||
if (!writeBuffer) return;
|
if (!writeBuffer) return;
|
||||||
|
|
||||||
// flush the write buffer
|
// flush the write buffer
|
||||||
var out = '';
|
var out = '';
|
||||||
if (!writeBuffer.length) return out;
|
if (!writeBuffer.length) return out;
|
||||||
|
|
||||||
_v4.each(writeBuffer, function (writeReq) {
|
_.each(writeBuffer, function (writeReq) {
|
||||||
if (writeReq.chunk) {
|
if (writeReq.chunk) {
|
||||||
// 0.9.12+ uses WriteReq objects with a chunk prop
|
// 0.9.12+ uses WriteReq objects with a chunk prop
|
||||||
out += '' + writeReq.chunk;
|
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], ...].
|
// 0.9.4 - 0.9.9 buffers are arrays of arrays like [[chunk, cb], [chunk, undef], ...].
|
||||||
out += '' + writeReq[0];
|
out += '' + writeReq[0];
|
||||||
} else {
|
} else {
|
||||||
@ -419,7 +416,7 @@ _v4.getUnwrittenFromStream = function (stream) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
_v4.getStreamWriteBuffer = function (stream) {
|
_.getStreamWriteBuffer = function (stream) {
|
||||||
if (!stream || !stream._writableState) return;
|
if (!stream || !stream._writableState) return;
|
||||||
|
|
||||||
var writeState = stream._writableState;
|
var writeState = stream._writableState;
|
||||||
@ -431,16 +428,16 @@ _v4.getStreamWriteBuffer = function (stream) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_v4.clearWriteStreamBuffer = function (stream) {
|
_.clearWriteStreamBuffer = function (stream) {
|
||||||
var buffer = _v4.getStreamWriteBuffer(stream);
|
var buffer = _.getStreamWriteBuffer(stream);
|
||||||
return buffer && buffer.splice(0);
|
return buffer && buffer.splice(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the current time in milliseconds since epoch
|
* return the current time in milliseconds since epoch
|
||||||
*/
|
*/
|
||||||
_v4.now = function () {
|
_.now = function () {
|
||||||
return (typeof Date.now === 'function') ? Date.now() : (new Date()).getTime();
|
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 clock = require('sinon').useFakeTimers();
|
||||||
var Client = require('../../src/elasticsearch').Client;
|
var Client = require('../../src/elasticsearch').Client;
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var times = require('async').times;
|
var times = require('async').times;
|
||||||
|
|
||||||
process.once('message', function (port) {
|
process.once('message', function (port) {
|
||||||
@ -20,9 +20,9 @@ process.once('message', function (port) {
|
|||||||
clock.tick(10);
|
clock.tick(10);
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
var conns = es.transport.connectionPool._conns;
|
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) {
|
.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()
|
.flattenDeep()
|
||||||
.value();
|
.value();
|
||||||
@ -31,8 +31,8 @@ process.once('message', function (port) {
|
|||||||
|
|
||||||
var out = {
|
var out = {
|
||||||
socketCount: err || sockets.length,
|
socketCount: err || sockets.length,
|
||||||
remaining: _v4.filter(sockets, { destroyed: true }).length - sockets.length,
|
remaining: _.filter(sockets, { destroyed: true }).length - sockets.length,
|
||||||
timeouts: _v4.size(clock.timers) && _v4.map(clock.timers, 'func').map(String)
|
timeouts: _.size(clock.timers) && _.map(clock.timers, 'func').map(String)
|
||||||
};
|
};
|
||||||
|
|
||||||
clock.restore();
|
clock.restore();
|
||||||
|
|||||||
@ -9,10 +9,10 @@ if (BROWSER) {
|
|||||||
es = require('../../../src/elasticsearch');
|
es = require('../../../src/elasticsearch');
|
||||||
}
|
}
|
||||||
|
|
||||||
// var _ = require('../../../src/lib/utils');
|
var _ = require('../../../src/lib/utils');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
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');
|
var Bluebird = require('bluebird');
|
||||||
|
|
||||||
// current client
|
// current client
|
||||||
@ -60,7 +60,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var logConfig = {};
|
var logConfig = {};
|
||||||
if (_v4.has(options, 'logConfig')) {
|
if (_.has(options, 'logConfig')) {
|
||||||
logConfig = options.logConfig;
|
logConfig = options.logConfig;
|
||||||
} else {
|
} else {
|
||||||
if (BROWSER) {
|
if (BROWSER) {
|
||||||
@ -106,14 +106,14 @@ module.exports = {
|
|||||||
client.snapshot.getRepository({
|
client.snapshot.getRepository({
|
||||||
snapshot: '_all'
|
snapshot: '_all'
|
||||||
})
|
})
|
||||||
.then(_v4.keys)
|
.then(_.keys)
|
||||||
.map(function (repo) {
|
.map(function (repo) {
|
||||||
return client.snapshot.get({
|
return client.snapshot.get({
|
||||||
repository: repo,
|
repository: repo,
|
||||||
snapshot: '_all'
|
snapshot: '_all'
|
||||||
})
|
})
|
||||||
.then(function (resp) {
|
.then(function (resp) {
|
||||||
return _v4.map(resp.snapshots, 'snapshot');
|
return _.map(resp.snapshots, 'snapshot');
|
||||||
}, function () {
|
}, function () {
|
||||||
return [];
|
return [];
|
||||||
})
|
})
|
||||||
@ -132,7 +132,7 @@ module.exports = {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
_v4.nextTick(cb);
|
_.nextTick(cb);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ module.exports = function (branch) {
|
|||||||
var YamlFile = require('./yaml_file');
|
var YamlFile = require('./yaml_file');
|
||||||
var root = require('find-root')(__dirname);
|
var root = require('find-root')(__dirname);
|
||||||
var rootReq = function (loc) { return require(path.join(root, loc)); };
|
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 utils = rootReq('grunt/utils');
|
||||||
var es = rootReq('src/elasticsearch');
|
var es = rootReq('src/elasticsearch');
|
||||||
var clientManager = require('./client_manager');
|
var clientManager = require('./client_manager');
|
||||||
@ -32,7 +32,7 @@ module.exports = function (branch) {
|
|||||||
return clientManager.get().clearEs();
|
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);
|
return new YamlFile(filename, docs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = YamlDoc;
|
module.exports = YamlDoc;
|
||||||
|
|
||||||
// var _ = require('lodash-migrate/lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
var clientManager = require('./client_manager');
|
var clientManager = require('./client_manager');
|
||||||
var inspect = require('util').inspect;
|
var inspect = require('util').inspect;
|
||||||
@ -70,8 +70,8 @@ function versionToComparableString(version, def) {
|
|||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parts = _v4.map(version.split('.'), function (part) {
|
var parts = _.map(version.split('.'), function (part) {
|
||||||
part = '' + _v4.parseInt(part);
|
part = '' + _.parseInt(part);
|
||||||
return (new Array(Math.max(4 - part.length, 0))).join('0') + part;
|
return (new Array(Math.max(4 - part.length, 0))).join('0') + part;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -109,26 +109,26 @@ function YamlDoc(doc, file) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.file = file;
|
self.file = file;
|
||||||
self.description = _v4.keys(doc).shift();
|
self.description = _.keys(doc).shift();
|
||||||
self._stash = {};
|
self._stash = {};
|
||||||
self._last_requests_response = null;
|
self._last_requests_response = null;
|
||||||
|
|
||||||
// setup the actions, creating a bound and testable method for each
|
// 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
|
// get the method that will do the action
|
||||||
var method = self['do_' + action.name];
|
var method = self['do_' + action.name];
|
||||||
|
|
||||||
// check that it's a function
|
// check that it's a function
|
||||||
expect(method || 'YamlDoc#' + action.name).to.be.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) + ')';
|
action.name += '(' + JSON.stringify(action.args) + ')';
|
||||||
} else if (action.args) {
|
} else if (action.args) {
|
||||||
action.name += '(' + action.args + ')';
|
action.name += '(' + action.args + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap in a check for skipping
|
// 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
|
// create a function that can be passed to mocha or async
|
||||||
action.testable = function (_cb) {
|
action.testable = function (_cb) {
|
||||||
@ -199,15 +199,15 @@ YamlDoc.prototype = {
|
|||||||
flattenTestActions: function (config) {
|
flattenTestActions: function (config) {
|
||||||
// creates [ [ {name:"", args:"" }, ... ], ... ]
|
// creates [ [ {name:"", args:"" }, ... ], ... ]
|
||||||
// from [ {name:args, name:args}, {name:args} ]
|
// from [ {name:args, name:args}, {name:args} ]
|
||||||
var actionSets = _v4.map(config, function (set) {
|
var actionSets = _.map(config, function (set) {
|
||||||
return _v4.map(_v4.toPairs(set), function (pair) {
|
return _.map(_.toPairs(set), function (pair) {
|
||||||
return { name: pair[0], args: pair[1] };
|
return { name: pair[0], args: pair[1] };
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// do a single level flatten, merge=ing the nested arrays from step one
|
// do a single level flatten, merge=ing the nested arrays from step one
|
||||||
// into a master array, creating an array of action objects
|
// 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);
|
return note.concat(set);
|
||||||
}, []);
|
}, []);
|
||||||
},
|
},
|
||||||
@ -273,7 +273,7 @@ YamlDoc.prototype = {
|
|||||||
|
|
||||||
log('getting', path, 'from', from);
|
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, '.');
|
return step.replace(/\uffff/g, '.');
|
||||||
});
|
});
|
||||||
var remainingSteps;
|
var remainingSteps;
|
||||||
@ -301,7 +301,7 @@ YamlDoc.prototype = {
|
|||||||
*/
|
*/
|
||||||
do_skip: function (args, done) {
|
do_skip: function (args, done) {
|
||||||
if (args.version) {
|
if (args.version) {
|
||||||
return rangeMatchesCurrentVersion(args.version, _v4.bind(function (match) {
|
return rangeMatchesCurrentVersion(args.version, _.bind(function (match) {
|
||||||
if (match) {
|
if (match) {
|
||||||
if (this.description === 'setup') {
|
if (this.description === 'setup') {
|
||||||
this.file.skipping = true;
|
this.file.skipping = true;
|
||||||
@ -320,7 +320,7 @@ YamlDoc.prototype = {
|
|||||||
|
|
||||||
if (args.features) {
|
if (args.features) {
|
||||||
var features = Array.isArray(args.features) ? args.features : [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 (notImplemented.length) {
|
||||||
if (this.description === 'setup') {
|
if (this.description === 'setup') {
|
||||||
@ -396,25 +396,25 @@ YamlDoc.prototype = {
|
|||||||
delete args.headers;
|
delete args.headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
var otherKeys = _v4.keys(args);
|
var otherKeys = _.keys(args);
|
||||||
var action = otherKeys.shift();
|
var action = otherKeys.shift();
|
||||||
if (otherKeys.length) {
|
if (otherKeys.length) {
|
||||||
return done(new TypeError('Unexpected top-level args to "do": ' + otherKeys.join(', ')));
|
return done(new TypeError('Unexpected top-level args to "do": ' + otherKeys.join(', ')));
|
||||||
}
|
}
|
||||||
|
|
||||||
var client = clientManager.get();
|
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);
|
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 params = _.transform(inputParams, _.bind(function (params, val, name) {
|
||||||
var camelName = _v4.camelCase(name);
|
var camelName = _.camelCase(name);
|
||||||
|
|
||||||
// search through the params and url peices to find this param name
|
// search through the params and url peices to find this param name
|
||||||
var paramName = name;
|
var paramName = name;
|
||||||
var spec = clientAction && clientAction.spec;
|
var spec = clientAction && clientAction.spec;
|
||||||
var knownParam = spec && spec.params && spec.params[camelName];
|
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])) {
|
if ((url.opt && url.opt[camelName]) || (url.req && url.req[camelName])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -427,10 +427,10 @@ YamlDoc.prototype = {
|
|||||||
|
|
||||||
// for ercursively traversing the params to replace '$stashed' vars
|
// for ercursively traversing the params to replace '$stashed' vars
|
||||||
var transformObject = function (vals, val, i) {
|
var transformObject = function (vals, val, i) {
|
||||||
if (_v4.isString(val)) {
|
if (_.isString(val)) {
|
||||||
val = (val[0] === '$') ? this.get(val) : val;
|
val = (val[0] === '$') ? this.get(val) : val;
|
||||||
} else if (_v4.isPlainObject(val) || _v4.isArray(val)) {
|
} else if (_.isPlainObject(val) || _.isArray(val)) {
|
||||||
val = _v4.transform(val, transformObject);
|
val = _.transform(val, transformObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
vals[i] = val;
|
vals[i] = val;
|
||||||
@ -443,12 +443,12 @@ YamlDoc.prototype = {
|
|||||||
expect(clientAction || clientActionName).to.be.a('function');
|
expect(clientAction || clientActionName).to.be.a('function');
|
||||||
|
|
||||||
if (!isNaN(parseFloat(catcher))) {
|
if (!isNaN(parseFloat(catcher))) {
|
||||||
params.ignore = _v4.union(params.ignore || [], [catcher]);
|
params.ignore = _.union(params.ignore || [], [catcher]);
|
||||||
catcher = null;
|
catcher = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeoutId;
|
var timeoutId;
|
||||||
var cb = _v4.bind(function (error, body) {
|
var cb = _.bind(function (error, body) {
|
||||||
this._last_requests_response = body;
|
this._last_requests_response = body;
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ YamlDoc.prototype = {
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
do_set: function (args) {
|
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._stash[name] = this.get(path);
|
||||||
}, this));
|
}, this));
|
||||||
},
|
},
|
||||||
@ -566,25 +566,25 @@ YamlDoc.prototype = {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// recursively replace all $var within args
|
// recursively replace all $var within args
|
||||||
_v4.forOwn(args, function recurse(val, key, lvl) {
|
_.forOwn(args, function recurse(val, key, lvl) {
|
||||||
if (_v4.isObject(val)) {
|
if (_.isObject(val)) {
|
||||||
return _v4.each(val, recurse);
|
return _.each(val, recurse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_v4.isString(val)) {
|
if (_.isString(val)) {
|
||||||
lvl[key] = val.replace(/\$[a-zA-Z0-9_]+/g, function (name) {
|
lvl[key] = val.replace(/\$[a-zA-Z0-9_]+/g, function (name) {
|
||||||
return self.get(name);
|
return self.get(name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_v4.forOwn(args, _v4.bind(function (match, path) {
|
_.forOwn(args, _.bind(function (match, path) {
|
||||||
var origMatch = match;
|
var origMatch = match;
|
||||||
|
|
||||||
var maybeRE = false;
|
var maybeRE = false;
|
||||||
var usedRE = false;
|
var usedRE = false;
|
||||||
|
|
||||||
if (_v4.isString(match)) {
|
if (_.isString(match)) {
|
||||||
// convert the matcher into a compatible string for building a regexp
|
// convert the matcher into a compatible string for building a regexp
|
||||||
maybeRE = match
|
maybeRE = match
|
||||||
// replace comments, but allow the # to be escaped like \#
|
// replace comments, but allow the # to be escaped like \#
|
||||||
@ -655,7 +655,7 @@ YamlDoc.prototype = {
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
do_lt: function (args) {
|
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);
|
expect(this.get(path)).to.be.below(num, 'path: ' + path);
|
||||||
}, this));
|
}, this));
|
||||||
},
|
},
|
||||||
@ -667,7 +667,7 @@ YamlDoc.prototype = {
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
do_lte: function (args) {
|
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);
|
expect(this.get(path) <= num).to.be.ok('path: ' + path);
|
||||||
}, this));
|
}, this));
|
||||||
},
|
},
|
||||||
@ -679,7 +679,7 @@ YamlDoc.prototype = {
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
do_gt: function (args) {
|
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);
|
expect(this.get(path)).to.be.above(num, 'path: ' + path);
|
||||||
}, this));
|
}, this));
|
||||||
},
|
},
|
||||||
@ -691,7 +691,7 @@ YamlDoc.prototype = {
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
do_gte: function (args) {
|
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);
|
expect(this.get(path) >= num).to.be.ok('path: ' + path);
|
||||||
}, this));
|
}, this));
|
||||||
},
|
},
|
||||||
@ -704,8 +704,8 @@ YamlDoc.prototype = {
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
do_length: function (args) {
|
do_length: function (args) {
|
||||||
_v4.forOwn(args, _v4.bind(function (len, path) {
|
_.forOwn(args, _.bind(function (len, path) {
|
||||||
expect(_v4.size(this.get(path))).to.eql(len, 'path: ' + path);
|
expect(_.size(this.get(path))).to.eql(len, 'path: ' + path);
|
||||||
}, this));
|
}, this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@ module.exports = YamlFile;
|
|||||||
|
|
||||||
var YamlDoc = require('./yaml_doc');
|
var YamlDoc = require('./yaml_doc');
|
||||||
var clientManager = require('./client_manager');
|
var clientManager = require('./client_manager');
|
||||||
// var _ = require('../../../src/lib/utils');
|
var _ = require('../../../src/lib/utils');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
function YamlFile(filename, docs) {
|
function YamlFile(filename, docs) {
|
||||||
@ -18,7 +18,7 @@ function YamlFile(filename, docs) {
|
|||||||
file.skipping = false;
|
file.skipping = false;
|
||||||
|
|
||||||
describe(filename, function () {
|
describe(filename, function () {
|
||||||
file.docs = _v4.map(docs, function (doc) {
|
file.docs = _.map(docs, function (doc) {
|
||||||
doc = new YamlDoc(doc, file);
|
doc = new YamlDoc(doc, file);
|
||||||
if (doc.description === 'setup') {
|
if (doc.description === 'setup') {
|
||||||
beforeEach(/* doc */function (done) {
|
beforeEach(/* doc */function (done) {
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
module.exports = MockHttpRequest;
|
module.exports = MockHttpRequest;
|
||||||
|
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
|
||||||
function MockHttpRequest() {
|
function MockHttpRequest() {
|
||||||
// These are internal flags and data structures
|
// These are internal flags and data structures
|
||||||
@ -221,7 +221,7 @@ MockHttpRequest.prototype = {
|
|||||||
|
|
||||||
getAllResponseHeaders: function () {
|
getAllResponseHeaders: function () {
|
||||||
var r = '';
|
var r = '';
|
||||||
_v4.each(this.responseHeaders, function (header) {
|
_.each(this.responseHeaders, function (header) {
|
||||||
if ((header === 'set-cookie') || (header === 'set-cookie2')) {
|
if ((header === 'set-cookie') || (header === 'set-cookie2')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -353,7 +353,7 @@ MockHttpRequest.prototype = {
|
|||||||
|
|
||||||
this.responseText = null;
|
this.responseText = null;
|
||||||
this.error = true;
|
this.error = true;
|
||||||
_v4.each(this.requestHeaders, function (header) {
|
_.each(this.requestHeaders, function (header) {
|
||||||
delete this.requestHeaders[header];
|
delete this.requestHeaders[header];
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ var complete = [];
|
|||||||
var MockHttpRequest = require('./browser_http');
|
var MockHttpRequest = require('./browser_http');
|
||||||
var XhrServer = MockHttpRequest.MockHttpServer;
|
var XhrServer = MockHttpRequest.MockHttpServer;
|
||||||
var parseUrl = MockHttpRequest.prototype.parseUri;
|
var parseUrl = MockHttpRequest.prototype.parseUri;
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
|
||||||
var server = new XhrServer(function (request) {
|
var server = new XhrServer(function (request) {
|
||||||
var reqDetails = {
|
var reqDetails = {
|
||||||
@ -11,7 +11,7 @@ var server = new XhrServer(function (request) {
|
|||||||
host: request.urlParts.host,
|
host: request.urlParts.host,
|
||||||
path: request.urlParts.relative
|
path: request.urlParts.relative
|
||||||
};
|
};
|
||||||
var response = _v4.find(interceptors, reqDetails);
|
var response = _.find(interceptors, reqDetails);
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
// remove of tick down the times
|
// 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 */
|
/* global angular */
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
@ -17,13 +17,13 @@ describe('Angular esFactory', function () {
|
|||||||
|
|
||||||
function bootstrap(env) {
|
function bootstrap(env) {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
var promiseProvider = _v4.noop;
|
var promiseProvider = _.noop;
|
||||||
if (env.bluebirdPromises) {
|
if (env.bluebirdPromises) {
|
||||||
promiseProvider = function ($provide) {
|
promiseProvider = function ($provide) {
|
||||||
$provide.service('$q', function () {
|
$provide.service('$q', function () {
|
||||||
return {
|
return {
|
||||||
defer: function () {
|
defer: function () {
|
||||||
return _v4.bindAll(Promise.defer(), ['resolve', 'reject']);
|
return _.bindAll(Promise.defer(), ['resolve', 'reject']);
|
||||||
},
|
},
|
||||||
reject: Promise.reject,
|
reject: Promise.reject,
|
||||||
when: Promise.resolve,
|
when: Promise.resolve,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module.exports = function (makeLogger) {
|
|||||||
var stub = require('../utils/auto_release_stub').make();
|
var stub = require('../utils/auto_release_stub').make();
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var once = require('events').EventEmitter.prototype.once;
|
var once = require('events').EventEmitter.prototype.once;
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
|
||||||
describe('buffer flush', function () {
|
describe('buffer flush', function () {
|
||||||
if (require('stream').Writable) {
|
if (require('stream').Writable) {
|
||||||
@ -21,7 +21,7 @@ module.exports = function (makeLogger) {
|
|||||||
var logger = makeLogger();
|
var logger = makeLogger();
|
||||||
|
|
||||||
// write the line 10 times
|
// write the line 10 times
|
||||||
_v4.times(10, function () {
|
_.times(10, function () {
|
||||||
logger.onDebug(line);
|
logger.onDebug(line);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var ca = require('../../../src/lib/client_action').factory;
|
var ca = require('../../../src/lib/client_action').factory;
|
||||||
var proxy = require('../../../src/lib/client_action').proxyFactory;
|
var proxy = require('../../../src/lib/client_action').proxyFactory;
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var Promise = require('bluebird');
|
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
|
* @return {Function} - the clientActionProxy
|
||||||
*/
|
*/
|
||||||
function makeClientActionProxy(fn, spec) {
|
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 = {}; });
|
afterEach(function () { _stash = {}; });
|
||||||
var make = function (params) {
|
var make = function (params) {
|
||||||
_stash.orig = params;
|
_stash.orig = params;
|
||||||
_stash.copy = _v4.clone(params);
|
_stash.copy = _.clone(params);
|
||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
make.check = function () {
|
make.check = function () {
|
||||||
@ -118,7 +118,7 @@ describe('Client Action runner', function () {
|
|||||||
|
|
||||||
it('handles passing just the callback', function () {
|
it('handles passing just the callback', function () {
|
||||||
var action = makeClientActionProxy(function (params, cb) {
|
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');
|
expect(cb).to.be.a('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var ConnectionAbstract = require('../../../src/lib/connection');
|
|||||||
var Host = require('../../../src/lib/host');
|
var Host = require('../../../src/lib/host');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var errors = require('../../../src/lib/errors');
|
var errors = require('../../../src/lib/errors');
|
||||||
|
|
||||||
var stub = require('../../utils/auto_release_stub').make();
|
var stub = require('../../utils/auto_release_stub').make();
|
||||||
@ -73,10 +73,10 @@ describe('Connection Abstract', function () {
|
|||||||
|
|
||||||
stub(conn, 'request');
|
stub(conn, 'request');
|
||||||
|
|
||||||
expect(_v4.size(clock.timers)).to.eql(0);
|
expect(_.size(clock.timers)).to.eql(0);
|
||||||
conn.ping();
|
conn.ping();
|
||||||
expect(_v4.size(clock.timers)).to.eql(1);
|
expect(_.size(clock.timers)).to.eql(1);
|
||||||
expect(clock.timers[_v4.keys(clock.timers).shift()].delay).to.eql(5000);
|
expect(clock.timers[_.keys(clock.timers).shift()].delay).to.eql(5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls it\'s own request method', function () {
|
it('calls it\'s own request method', function () {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var ConnectionPool = require('../../../src/lib/connection_pool');
|
var ConnectionPool = require('../../../src/lib/connection_pool');
|
||||||
var Host = require('../../../src/lib/host');
|
var Host = require('../../../src/lib/host');
|
||||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
var sinon = require('sinon');
|
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 () {
|
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);
|
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.alive).to.eql([connection]);
|
||||||
expect(pool._conns.dead).to.eql([]);
|
expect(pool._conns.dead).to.eql([]);
|
||||||
@ -52,7 +52,7 @@ describe('Connection Pool', function () {
|
|||||||
|
|
||||||
expect(pool._conns.alive).to.eql([connection]);
|
expect(pool._conns.alive).to.eql([connection]);
|
||||||
expect(pool._conns.dead).to.eql([]);
|
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 () {
|
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:9202')),
|
||||||
new ConnectionAbstract(new Host('http://localhost:9203'))
|
new ConnectionAbstract(new Host('http://localhost:9203'))
|
||||||
];
|
];
|
||||||
var pingQueue = _v4.shuffle(connections);
|
var pingQueue = _.shuffle(connections);
|
||||||
var expectedSelection = pingQueue[pingQueue.length - 1];
|
var expectedSelection = pingQueue[pingQueue.length - 1];
|
||||||
|
|
||||||
_v4.each(pingQueue, function (conn) {
|
_.each(pingQueue, function (conn) {
|
||||||
pool.addConnection(conn);
|
pool.addConnection(conn);
|
||||||
stub(conn, 'ping', function (params, cb) {
|
stub(conn, 'ping', function (params, cb) {
|
||||||
if (typeof params === 'function') {
|
if (typeof params === 'function') {
|
||||||
@ -247,13 +247,13 @@ describe('Connection Pool', function () {
|
|||||||
stub.autoRelease(clock);
|
stub.autoRelease(clock);
|
||||||
|
|
||||||
connection.setStatus('dead');
|
connection.setStatus('dead');
|
||||||
expect(_v4.size(clock.timers)).to.eql(1);
|
expect(_.size(clock.timers)).to.eql(1);
|
||||||
var id = _v4(clock.timers).keys().first();
|
var id = _(clock.timers).keys().first();
|
||||||
|
|
||||||
// it re-dies
|
// it re-dies
|
||||||
connection.setStatus('dead');
|
connection.setStatus('dead');
|
||||||
expect(_v4.size(clock.timers)).to.eql(1);
|
expect(_.size(clock.timers)).to.eql(1);
|
||||||
expect(_v4(clock.timers).keys().first()).to.not.eql(id);
|
expect(_(clock.timers).keys().first()).to.not.eql(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does nothing when a connection is re-alive', function () {
|
it('does nothing when a connection is re-alive', function () {
|
||||||
@ -295,7 +295,7 @@ describe('Connection Pool', function () {
|
|||||||
|
|
||||||
var result = pool.getConnections();
|
var result = pool.getConnections();
|
||||||
expect(result.length).to.be(1000);
|
expect(result.length).to.be(1000);
|
||||||
expect(_v4.reduce(result, function (sum, num) {
|
expect(_.reduce(result, function (sum, num) {
|
||||||
sum += num
|
sum += num
|
||||||
return sum;
|
return sum;
|
||||||
}, 0)).to.eql(499500);
|
}, 0)).to.eql(499500);
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
var errors = require('../../../src/lib/errors');
|
var errors = require('../../../src/lib/errors');
|
||||||
var expect = require('expect.js');
|
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) !== '_') {
|
if (name.charAt(0) !== '_') {
|
||||||
describe(name, function () {
|
describe(name, function () {
|
||||||
it('extend the ErrorAbstract and Error classes', function () {
|
it('extend the ErrorAbstract and Error classes', function () {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ describe('File Logger', function () {
|
|||||||
var Log = require('../../../src/lib/log');
|
var Log = require('../../../src/lib/log');
|
||||||
var FileLogger = require('../../../src/lib/loggers/file');
|
var FileLogger = require('../../../src/lib/loggers/file');
|
||||||
var once = require('events').EventEmitter.prototype.once;
|
var once = require('events').EventEmitter.prototype.once;
|
||||||
// var _ = require('../../../src/lib/utils');
|
var _ = require('../../../src/lib/utils');
|
||||||
var parentLog;
|
var parentLog;
|
||||||
var logger;
|
var logger;
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
@ -15,7 +15,7 @@ describe('File Logger', function () {
|
|||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
parentLog.close();
|
parentLog.close();
|
||||||
logger && _v4.clearWriteStreamBuffer(logger.stream);
|
logger && _.clearWriteStreamBuffer(logger.stream);
|
||||||
});
|
});
|
||||||
|
|
||||||
function makeLogger(parent, levels) {
|
function makeLogger(parent, levels) {
|
||||||
@ -49,7 +49,7 @@ describe('File Logger', function () {
|
|||||||
var logger = makeLogger();
|
var logger = makeLogger();
|
||||||
|
|
||||||
// write the line 10 times
|
// write the line 10 times
|
||||||
_v4.times(10, function () {
|
_.times(10, function () {
|
||||||
logger.onDebug(line);
|
logger.onDebug(line);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var Host = require('../../../src/lib/host');
|
var Host = require('../../../src/lib/host');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var expectSubObject = require('../../utils/expect_sub_object');
|
var expectSubObject = require('../../utils/expect_sub_object');
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
describe('Http Connector', function () {
|
describe('Http Connector', function () {
|
||||||
|
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
var nock = require('nock');
|
var nock = require('nock');
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
@ -67,12 +67,12 @@ describe('Http Connector', function () {
|
|||||||
|
|
||||||
it('allows defining a custom agent', function () {
|
it('allows defining a custom agent', function () {
|
||||||
var football = {};
|
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);
|
expect(con.agent).to.be(football);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows setting agent to false', function () {
|
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);
|
expect(con.agent).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -482,7 +482,7 @@ describe('Http Connector', function () {
|
|||||||
this.timeout(5 * 60 * 1000);
|
this.timeout(5 * 60 * 1000);
|
||||||
var cp = require('child_process');
|
var cp = require('child_process');
|
||||||
var path = require('path');
|
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 timeout; // start the timeout once we hear back from the client
|
||||||
|
|
||||||
var server = cp.fork(fixture('keepalive_server.js'))
|
var server = cp.fork(fixture('keepalive_server.js'))
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var Log = require('../../../src/lib/log');
|
var Log = require('../../../src/lib/log');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
|
|
||||||
describe('Log class', function () {
|
describe('Log class', function () {
|
||||||
@ -129,11 +129,11 @@ describe('Log class', function () {
|
|||||||
log: [
|
log: [
|
||||||
{
|
{
|
||||||
type: function (log, config) {
|
type: function (log, config) {
|
||||||
log.on('error', _v4.noop);
|
log.on('error', _.noop);
|
||||||
log.on('warning', _v4.noop);
|
log.on('warning', _.noop);
|
||||||
log.on('info', _v4.noop);
|
log.on('info', _.noop);
|
||||||
log.on('debug', _v4.noop);
|
log.on('debug', _.noop);
|
||||||
log.on('trace', _v4.noop);
|
log.on('trace', _.noop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
describe('Random Selector', function () {
|
describe('Random Selector', function () {
|
||||||
var randomSelector = require('../../../src/lib/selectors/random');
|
var randomSelector = require('../../../src/lib/selectors/random');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
|
|
||||||
it('chooses a selection by random', function () {
|
it('chooses a selection by random', function () {
|
||||||
var log = { a: 0, b: 0, c: 0 };
|
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);
|
var choice = randomSelector(choices);
|
||||||
log[choice]++;
|
log[choice]++;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(_v4.filter(log, function (count) {
|
expect(_.filter(log, function (count) {
|
||||||
return count < 200 || count > 400;
|
return count < 200 || count > 400;
|
||||||
})).to.have.length(0);
|
})).to.have.length(0);
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
describe('Round Robin Selector', function () {
|
describe('Round Robin Selector', function () {
|
||||||
var selector = require('../../../src/lib/selectors/round_robin');
|
var selector = require('../../../src/lib/selectors/round_robin');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
|
|
||||||
it('chooses options in order', function () {
|
it('chooses options in order', function () {
|
||||||
var options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
var options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
||||||
var expected = _v4.clone(options);
|
var expected = _.clone(options);
|
||||||
var selections = [];
|
var selections = [];
|
||||||
|
|
||||||
_v4.times(options.length, function () {
|
_.times(options.length, function () {
|
||||||
selections.push(selector(options));
|
selections.push(selector(options));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ describe('Stream Logger', function () {
|
|||||||
var MockWritableStream = require('../../mocks/writable_stream');
|
var MockWritableStream = require('../../mocks/writable_stream');
|
||||||
var once = require('events').EventEmitter.prototype.once;
|
var once = require('events').EventEmitter.prototype.once;
|
||||||
var stream = new MockWritableStream();
|
var stream = new MockWritableStream();
|
||||||
// var _ = require('../../../src/lib/utils');
|
var _ = require('../../../src/lib/utils');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
var parentLog;
|
var parentLog;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ describe('Stream Logger', function () {
|
|||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
parentLog.close();
|
parentLog.close();
|
||||||
_v4.clearWriteStreamBuffer(stream);
|
_.clearWriteStreamBuffer(stream);
|
||||||
});
|
});
|
||||||
|
|
||||||
function makeLogger(parent, levels) {
|
function makeLogger(parent, levels) {
|
||||||
@ -41,13 +41,13 @@ describe('Stream Logger', function () {
|
|||||||
|
|
||||||
// get the last handler for process's "exit" event
|
// get the last handler for process's "exit" event
|
||||||
var exitHandlers = process._events.exit;
|
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
|
// allow the logger to acctually write to the stream
|
||||||
stream.write.restore();
|
stream.write.restore();
|
||||||
|
|
||||||
// write the line 10 times
|
// write the line 10 times
|
||||||
_v4.times(10, function () {
|
_.times(10, function () {
|
||||||
logger.onDebug(line);
|
logger.onDebug(line);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ var errors = require('../../../src/lib/errors');
|
|||||||
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var expect = require('expect.js');
|
var expect = require('expect.js');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var nodeList = require('../../fixtures/short_node_list.json');
|
var nodeList = require('../../fixtures/short_node_list.json');
|
||||||
var stub = require('../../utils/auto_release_stub').make();
|
var stub = require('../../utils/auto_release_stub').make();
|
||||||
|
|
||||||
@ -83,11 +83,11 @@ describe('Transport Class', function () {
|
|||||||
sniffInterval: 25000
|
sniffInterval: 25000
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(_v4.size(clock.timers)).to.eql(1);
|
expect(_.size(clock.timers)).to.eql(1);
|
||||||
var id = _v4.keys(clock.timers).pop();
|
var id = _.keys(clock.timers).pop();
|
||||||
clock.tick(25000);
|
clock.tick(25000);
|
||||||
expect(trans.sniff.callCount).to.eql(1);
|
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);
|
expect(clock.timers).to.not.have.key(id);
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -285,25 +285,25 @@ describe('Transport Class', function () {
|
|||||||
|
|
||||||
describe('randomizeHosts options', function () {
|
describe('randomizeHosts options', function () {
|
||||||
it('calls _.shuffle be default', function () {
|
it('calls _.shuffle be default', function () {
|
||||||
// var _ = require('../../../src/lib/utils');
|
var _ = require('../../../src/lib/utils');
|
||||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||||
stub(_v4, 'shuffle');
|
stub(_, 'shuffle');
|
||||||
var trans = new Transport({
|
var trans = new Transport({
|
||||||
hosts: 'localhost'
|
hosts: 'localhost'
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(_v4.shuffle.callCount).to.eql(1);
|
expect(_.shuffle.callCount).to.eql(1);
|
||||||
});
|
});
|
||||||
it('skips the call to _.shuffle when false', function () {
|
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(Transport.connectionPools.main.prototype, 'setHosts');
|
||||||
stub(_v4, 'shuffle');
|
stub(_, 'shuffle');
|
||||||
var trans = new Transport({
|
var trans = new Transport({
|
||||||
hosts: 'localhost',
|
hosts: 'localhost',
|
||||||
randomizeHosts: false
|
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({
|
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;
|
return 'localhost/' + i;
|
||||||
}),
|
}),
|
||||||
maxRetries: retries,
|
maxRetries: retries,
|
||||||
@ -617,8 +617,8 @@ describe('Transport Class', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// trigger a select so that we can harvest the connection list
|
// trigger a select so that we can harvest the connection list
|
||||||
trans.connectionPool.select(_v4.noop);
|
trans.connectionPool.select(_.noop);
|
||||||
_v4.each(connections, function (conn) {
|
_.each(connections, function (conn) {
|
||||||
stub(conn, 'request', failRequest);
|
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));
|
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 () {
|
it('returns an object with an abort() method when a callback is sent', function () {
|
||||||
var tran = new Transport();
|
var tran = new Transport();
|
||||||
shortCircuitRequest(tran);
|
shortCircuitRequest(tran);
|
||||||
var ret = tran.request({}, _v4.noop);
|
var ret = tran.request({}, _.noop);
|
||||||
expect(ret).to.be.a('object');
|
expect(ret).to.be.a('object');
|
||||||
expect(ret.abort).to.be.a('function');
|
expect(ret.abort).to.be.a('function');
|
||||||
});
|
});
|
||||||
@ -651,7 +651,7 @@ describe('Transport Class', function () {
|
|||||||
var ret = tran.request({});
|
var ret = tran.request({});
|
||||||
expect(ret.then).to.be.a('function');
|
expect(ret.then).to.be.a('function');
|
||||||
expect(ret.abort).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 () {
|
it('promise is always pulled from the defer created by this.defer()', function () {
|
||||||
var fakePromise = {};
|
var fakePromise = {};
|
||||||
@ -659,8 +659,8 @@ describe('Transport Class', function () {
|
|||||||
var tran = new Transport({
|
var tran = new Transport({
|
||||||
defer: function () {
|
defer: function () {
|
||||||
return {
|
return {
|
||||||
resolve: _v4.noop,
|
resolve: _.noop,
|
||||||
reject: _v4.noop,
|
reject: _.noop,
|
||||||
promise: fakePromise
|
promise: fakePromise
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -759,10 +759,10 @@ describe('Transport Class', function () {
|
|||||||
|
|
||||||
var prom = tran.request({});
|
var prom = tran.request({});
|
||||||
// disregard promise, prevent bluebird's warnings
|
// disregard promise, prevent bluebird's warnings
|
||||||
prom.then(_v4.noop, _v4.noop);
|
prom.then(_.noop, _.noop);
|
||||||
|
|
||||||
expect(_v4.size(clock.timers)).to.eql(1);
|
expect(_.size(clock.timers)).to.eql(1);
|
||||||
_v4.each(clock.timers, function (timer, id) {
|
_.each(clock.timers, function (timer, id) {
|
||||||
expect(timer.callAt).to.eql(30000);
|
expect(timer.callAt).to.eql(30000);
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
});
|
});
|
||||||
@ -776,17 +776,17 @@ describe('Transport Class', function () {
|
|||||||
|
|
||||||
var prom = tran.request({});
|
var prom = tran.request({});
|
||||||
// disregard promise, prevent bluebird's warnings
|
// disregard promise, prevent bluebird's warnings
|
||||||
prom.then(_v4.noop, _v4.noop);
|
prom.then(_.noop, _.noop);
|
||||||
|
|
||||||
expect(_v4.size(clock.timers)).to.eql(1);
|
expect(_.size(clock.timers)).to.eql(1);
|
||||||
_v4.each(clock.timers, function (timer, id) {
|
_.each(clock.timers, function (timer, id) {
|
||||||
expect(timer.callAt).to.eql(5000);
|
expect(timer.callAt).to.eql(5000);
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
_v4.each([false, 0, null], function (falsy) {
|
_.each([false, 0, null], function (falsy) {
|
||||||
it('skips the timeout when it is ' + falsy, function () {
|
it('skips the timeout when it is ' + falsy, function () {
|
||||||
var clock = sinon.useFakeTimers();
|
var clock = sinon.useFakeTimers();
|
||||||
stub.autoRelease(clock);
|
stub.autoRelease(clock);
|
||||||
@ -797,7 +797,7 @@ describe('Transport Class', function () {
|
|||||||
requestTimeout: falsy
|
requestTimeout: falsy
|
||||||
}, function () {});
|
}, 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 sinon = require('sinon');
|
||||||
var nock = require('../../mocks/server.js');
|
var nock = require('../../mocks/server.js');
|
||||||
var through2 = require('through2');
|
var through2 = require('through2');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var nodeList = require('../../fixtures/short_node_list.json');
|
var nodeList = require('../../fixtures/short_node_list.json');
|
||||||
var stub = require('../../utils/auto_release_stub').make();
|
var stub = require('../../utils/auto_release_stub').make();
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ describe('Transport + Mock server', function () {
|
|||||||
expect(err).to.be(undefined);
|
expect(err).to.be(undefined);
|
||||||
expect(resp).to.eql({ i: 'am here' });
|
expect(resp).to.eql({ i: 'am here' });
|
||||||
expect(status).to.eql(200);
|
expect(status).to.eql(200);
|
||||||
expect(_v4.keys(clock.timers)).to.have.length(0);
|
expect(_.keys(clock.timers)).to.have.length(0);
|
||||||
clock.restore();
|
clock.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -342,9 +342,9 @@ describe('Transport + Mock server', function () {
|
|||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1);
|
expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1);
|
||||||
expect(tran.sniff.callCount).to.eql(0);
|
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();
|
timeout.func();
|
||||||
expect(tran.sniff.callCount).to.eql(1);
|
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 expect = require('expect.js');
|
||||||
|
|
||||||
var stub = require('../../utils/auto_release_stub').make();
|
var stub = require('../../utils/auto_release_stub').make();
|
||||||
@ -6,7 +6,7 @@ var stub = require('../../utils/auto_release_stub').make();
|
|||||||
describe('Utils', function () {
|
describe('Utils', function () {
|
||||||
|
|
||||||
describe('Additional Type Checkers', function () {
|
describe('Additional Type Checkers', function () {
|
||||||
_v4.forEach({
|
_.forEach({
|
||||||
Object: {
|
Object: {
|
||||||
is: [[], /regexp/]
|
is: [[], /regexp/]
|
||||||
},
|
},
|
||||||
@ -34,66 +34,66 @@ describe('Utils', function () {
|
|||||||
function (thing, name) {
|
function (thing, name) {
|
||||||
describe('#isArrayOf' + name, function () {
|
describe('#isArrayOf' + name, function () {
|
||||||
it('likes arrays of ' + 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 () {
|
it('dislikes when there is even one non ' + name, function () {
|
||||||
// notice a string in the array
|
// notice a string in the array
|
||||||
thing.is.push(thing.not || ' not ');
|
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 () {
|
describe('#isNumeric', function () {
|
||||||
it('likes integer literals', function () {
|
it('likes integer literals', function () {
|
||||||
expect(_v4.isNumeric('-10')).to.be(true);
|
expect(_.isNumeric('-10')).to.be(true);
|
||||||
expect(_v4.isNumeric('0')).to.be(true);
|
expect(_.isNumeric('0')).to.be(true);
|
||||||
expect(_v4.isNumeric('5')).to.be(true);
|
expect(_.isNumeric('5')).to.be(true);
|
||||||
expect(_v4.isNumeric(-16)).to.be(true);
|
expect(_.isNumeric(-16)).to.be(true);
|
||||||
expect(_v4.isNumeric(0)).to.be(true);
|
expect(_.isNumeric(0)).to.be(true);
|
||||||
expect(_v4.isNumeric(32)).to.be(true);
|
expect(_.isNumeric(32)).to.be(true);
|
||||||
expect(_v4.isNumeric('040')).to.be(true);
|
expect(_.isNumeric('040')).to.be(true);
|
||||||
expect(_v4.isNumeric('0xFF')).to.be(true);
|
expect(_.isNumeric('0xFF')).to.be(true);
|
||||||
expect(_v4.isNumeric(0xFFF)).to.be(true);
|
expect(_.isNumeric(0xFFF)).to.be(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('likes float literals', function () {
|
it('likes float literals', function () {
|
||||||
expect(_v4.isNumeric('-1.6')).to.be(true);
|
expect(_.isNumeric('-1.6')).to.be(true);
|
||||||
expect(_v4.isNumeric('4.536')).to.be(true);
|
expect(_.isNumeric('4.536')).to.be(true);
|
||||||
expect(_v4.isNumeric(-2.6)).to.be(true);
|
expect(_.isNumeric(-2.6)).to.be(true);
|
||||||
expect(_v4.isNumeric(3.1415)).to.be(true);
|
expect(_.isNumeric(3.1415)).to.be(true);
|
||||||
expect(_v4.isNumeric(8e5)).to.be(true);
|
expect(_.isNumeric(8e5)).to.be(true);
|
||||||
expect(_v4.isNumeric('123e-2')).to.be(true);
|
expect(_.isNumeric('123e-2')).to.be(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dislikes non-numeric stuff', function () {
|
it('dislikes non-numeric stuff', function () {
|
||||||
expect(_v4.isNumeric('')).to.be(false);
|
expect(_.isNumeric('')).to.be(false);
|
||||||
expect(_v4.isNumeric(' ')).to.be(false);
|
expect(_.isNumeric(' ')).to.be(false);
|
||||||
expect(_v4.isNumeric('\t\t')).to.be(false);
|
expect(_.isNumeric('\t\t')).to.be(false);
|
||||||
expect(_v4.isNumeric('abcdefghijklm1234567890')).to.be(false);
|
expect(_.isNumeric('abcdefghijklm1234567890')).to.be(false);
|
||||||
expect(_v4.isNumeric('xabcdefx')).to.be(false);
|
expect(_.isNumeric('xabcdefx')).to.be(false);
|
||||||
expect(_v4.isNumeric(true)).to.be(false);
|
expect(_.isNumeric(true)).to.be(false);
|
||||||
expect(_v4.isNumeric(false)).to.be(false);
|
expect(_.isNumeric(false)).to.be(false);
|
||||||
expect(_v4.isNumeric('bcfed5.2')).to.be(false);
|
expect(_.isNumeric('bcfed5.2')).to.be(false);
|
||||||
expect(_v4.isNumeric('7.2acdgs')).to.be(false);
|
expect(_.isNumeric('7.2acdgs')).to.be(false);
|
||||||
expect(_v4.isNumeric(undefined)).to.be(false);
|
expect(_.isNumeric(undefined)).to.be(false);
|
||||||
expect(_v4.isNumeric(null)).to.be(false);
|
expect(_.isNumeric(null)).to.be(false);
|
||||||
expect(_v4.isNumeric(NaN)).to.be(false);
|
expect(_.isNumeric(NaN)).to.be(false);
|
||||||
expect(_v4.isNumeric(Infinity)).to.be(false);
|
expect(_.isNumeric(Infinity)).to.be(false);
|
||||||
expect(_v4.isNumeric(Number.POSITIVE_INFINITY)).to.be(false);
|
expect(_.isNumeric(Number.POSITIVE_INFINITY)).to.be(false);
|
||||||
expect(_v4.isNumeric(Number.NEGATIVE_INFINITY)).to.be(false);
|
expect(_.isNumeric(Number.NEGATIVE_INFINITY)).to.be(false);
|
||||||
expect(_v4.isNumeric(new Date(2009, 1, 1))).to.be(false);
|
expect(_.isNumeric(new Date(2009, 1, 1))).to.be(false);
|
||||||
expect(_v4.isNumeric([])).to.be(false);
|
expect(_.isNumeric([])).to.be(false);
|
||||||
expect(_v4.isNumeric([1, 2, 3, 4])).to.be(false);
|
expect(_.isNumeric([1, 2, 3, 4])).to.be(false);
|
||||||
expect(_v4.isNumeric({})).to.be(false);
|
expect(_.isNumeric({})).to.be(false);
|
||||||
expect(_v4.isNumeric(function () {})).to.be(false);
|
expect(_.isNumeric(function () {})).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('#isInterval', function () {
|
describe('#isInterval', function () {
|
||||||
_v4.forEach({
|
_.forEach({
|
||||||
M: 'months',
|
M: 'months',
|
||||||
w: 'weeks',
|
w: 'weeks',
|
||||||
d: 'days',
|
d: 'days',
|
||||||
@ -104,20 +104,20 @@ describe('Utils', function () {
|
|||||||
},
|
},
|
||||||
function (name, unit) {
|
function (name, unit) {
|
||||||
it('likes ' + name, function () {
|
it('likes ' + name, function () {
|
||||||
expect(_v4.isInterval('1' + unit)).to.be(true);
|
expect(_.isInterval('1' + unit)).to.be(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('likes decimal ' + name, function () {
|
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 () {
|
it('dislikes more than one unit', function () {
|
||||||
expect(_v4.isInterval('1my')).to.be(false);
|
expect(_.isInterval('1my')).to.be(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dislikes spaces', function () {
|
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 () {
|
describe('#camelCase', function () {
|
||||||
it('find spaces, underscores, and other natural word breaks', 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 () {
|
it('ignores abreviations', function () {
|
||||||
expect(_v4.camelCase('Json_parser')).to.eql('jsonParser');
|
expect(_.camelCase('Json_parser')).to.eql('jsonParser');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles leading _', function () {
|
it('handles leading _', function () {
|
||||||
expect(_v4.camelCase('_thing_one_')).to.eql('_thingOne');
|
expect(_.camelCase('_thing_one_')).to.eql('_thingOne');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works on numbers', function () {
|
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 () {
|
describe('#studlyCase', function () {
|
||||||
it('find spaces, underscores, and other natural word breaks', 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 () {
|
it('ignores abreviations', function () {
|
||||||
expect(_v4.studlyCase('Json_parser')).to.eql('JsonParser');
|
expect(_.studlyCase('Json_parser')).to.eql('JsonParser');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles leading _', function () {
|
it('handles leading _', function () {
|
||||||
expect(_v4.studlyCase('_thing_one_')).to.eql('_ThingOne');
|
expect(_.studlyCase('_thing_one_')).to.eql('_ThingOne');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works on numbers', function () {
|
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 () {
|
describe('#snakeCase', function () {
|
||||||
it('find spaces, underscores, and other natural word breaks', 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 () {
|
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 () {
|
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 () {
|
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 () {
|
describe('#toLowerString', function () {
|
||||||
it('transforms normal strings', 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 () {
|
it('ignores long form empty vals (null, false, undef)', function () {
|
||||||
expect(_v4.toLowerString(null)).to.eql('');
|
expect(_.toLowerString(null)).to.eql('');
|
||||||
expect(_v4.toLowerString(false)).to.eql('');
|
expect(_.toLowerString(false)).to.eql('');
|
||||||
expect(_v4.toLowerString(void 0)).to.eql('');
|
expect(_.toLowerString(void 0)).to.eql('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the objects own toString', function () {
|
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 () {
|
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 () {
|
describe('#toUpperString', function () {
|
||||||
it('transforms normal strings', 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 () {
|
it('ignores long form empty vals (null, false, undef)', function () {
|
||||||
expect(_v4.toUpperString(null)).to.eql('');
|
expect(_.toUpperString(null)).to.eql('');
|
||||||
expect(_v4.toUpperString(false)).to.eql('');
|
expect(_.toUpperString(false)).to.eql('');
|
||||||
expect(_v4.toUpperString(void 0)).to.eql('');
|
expect(_.toUpperString(void 0)).to.eql('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the objects own toString', function () {
|
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 () {
|
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 () {
|
describe('#repeat', function () {
|
||||||
it('repeats strings', function () {
|
it('repeats strings', function () {
|
||||||
expect(_v4.repeat(' ', 5)).to.eql(' ');
|
expect(_.repeat(' ', 5)).to.eql(' ');
|
||||||
expect(_v4.repeat('foobar', 2)).to.eql('foobarfoobar');
|
expect(_.repeat('foobar', 2)).to.eql('foobarfoobar');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#ucfirst', function () {
|
describe('#ucfirst', function () {
|
||||||
it('only capitalized the first letter, lowercases everything else', 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 = {
|
var obj = {
|
||||||
foo: 'bar'
|
foo: 'bar'
|
||||||
};
|
};
|
||||||
expect(_v4.deepMerge(obj, { bar: 'baz' })).to.eql(obj);
|
expect(_.deepMerge(obj, { bar: 'baz' })).to.eql(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('concats arrays', function () {
|
it('concats arrays', function () {
|
||||||
var obj = {
|
var obj = {
|
||||||
foo: ['bax', 'boz']
|
foo: ['bax', 'boz']
|
||||||
};
|
};
|
||||||
_v4.deepMerge(obj, { foo: ['boop'] });
|
_.deepMerge(obj, { foo: ['boop'] });
|
||||||
expect(obj.foo).to.have.length(3);
|
expect(obj.foo).to.have.length(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ describe('Utils', function () {
|
|||||||
var obj = {
|
var obj = {
|
||||||
foo: ['stop', 'foo', 'stahp']
|
foo: ['stop', 'foo', 'stahp']
|
||||||
};
|
};
|
||||||
_v4.deepMerge(obj, { foo: 'string' });
|
_.deepMerge(obj, { foo: 'string' });
|
||||||
expect(obj.foo).to.have.length(3);
|
expect(obj.foo).to.have.length(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ describe('Utils', function () {
|
|||||||
foo: ['bax', 'boz']
|
foo: ['bax', 'boz']
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_v4.deepMerge(obj, { bax: { foo: ['poo'] } });
|
_.deepMerge(obj, { bax: { foo: ['poo'] } });
|
||||||
expect(obj.bax.foo).to.have.length(3);
|
expect(obj.bax.foo).to.have.length(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -276,26 +276,26 @@ describe('Utils', function () {
|
|||||||
describe('#createArray', function () {
|
describe('#createArray', function () {
|
||||||
it('accepts an array of things and simply returns a copy of it', function () {
|
it('accepts an array of things and simply returns a copy of it', function () {
|
||||||
var inp = [{ a: 1 }, 'pizza'];
|
var inp = [{ a: 1 }, 'pizza'];
|
||||||
var out = _v4.createArray(inp);
|
var out = _.createArray(inp);
|
||||||
expect(out).to.eql(inp);
|
expect(out).to.eql(inp);
|
||||||
expect(out).to.not.be(inp);
|
expect(out).to.not.be(inp);
|
||||||
});
|
});
|
||||||
it('accepts a primitive value and calls the the transform function', function (done) {
|
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');
|
expect(val).to.be('str');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('wraps any non-array in an array', function () {
|
it('wraps any non-array in an array', function () {
|
||||||
expect(_v4.createArray({})).to.eql([{}]);
|
expect(_.createArray({})).to.eql([{}]);
|
||||||
expect(_v4.createArray('')).to.eql(['']);
|
expect(_.createArray('')).to.eql(['']);
|
||||||
expect(_v4.createArray(123)).to.eql([123]);
|
expect(_.createArray(123)).to.eql([123]);
|
||||||
expect(_v4.createArray(/abc/)).to.eql([/abc/]);
|
expect(_.createArray(/abc/)).to.eql([/abc/]);
|
||||||
expect(_v4.createArray(false)).to.eql([false]);
|
expect(_.createArray(false)).to.eql([false]);
|
||||||
});
|
});
|
||||||
it('returns false when the transform function returns undefined', function () {
|
it('returns false when the transform function returns undefined', function () {
|
||||||
expect(_v4.createArray(['str', 1], function (val) {
|
expect(_.createArray(['str', 1], function (val) {
|
||||||
if (_v4.isString(val)) {
|
if (_.isString(val)) {
|
||||||
return {
|
return {
|
||||||
val: val
|
val: val
|
||||||
};
|
};
|
||||||
@ -306,27 +306,27 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
describe('#funcEnum', 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 () {
|
it('tests if the value at key in object is a function, returns it if so', function () {
|
||||||
var config = {
|
var config = {
|
||||||
func: function () {}
|
func: function () {}
|
||||||
};
|
};
|
||||||
expect(_v4.funcEnum(config, 'func', {}, 'toString'))
|
expect(_.funcEnum(config, 'func', {}, 'toString'))
|
||||||
.to.be(config.func);
|
.to.be(config.func);
|
||||||
});
|
});
|
||||||
it('tests if the value at key in object is undefined, returns the option at key default if so', function () {
|
it('tests if the value at key in object is undefined, returns the option at key default if so', function () {
|
||||||
var config = {
|
var config = {
|
||||||
func: undefined
|
func: undefined
|
||||||
};
|
};
|
||||||
expect(_v4.funcEnum(config, 'func', {}, 'toString'))
|
expect(_.funcEnum(config, 'func', {}, 'toString'))
|
||||||
.to.be(Object.prototype.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 () {
|
it('tests if the value at key in object is a string, returns the option at that key if so', function () {
|
||||||
var config = {
|
var config = {
|
||||||
'config key name': 'toString'
|
'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');
|
.to.be('pizza');
|
||||||
});
|
});
|
||||||
it('throws an informative error if the selection if invalid', function () {
|
it('throws an informative error if the selection if invalid', function () {
|
||||||
@ -335,21 +335,21 @@ describe('Utils', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
expect(function () {
|
expect(function () {
|
||||||
_v4.funcEnum(config, 'config', {});
|
_.funcEnum(config, 'config', {});
|
||||||
}).to.throwError(/expected a function/i);
|
}).to.throwError(/expected a function/i);
|
||||||
|
|
||||||
expect(function () {
|
expect(function () {
|
||||||
_v4.funcEnum(config, 'config', { main: 'default' }, 'main');
|
_.funcEnum(config, 'config', { main: 'default' }, 'main');
|
||||||
}).to.throwError(/expected a function or main/i);
|
}).to.throwError(/expected a function or main/i);
|
||||||
|
|
||||||
expect(function () {
|
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);
|
}).to.throwError(/expected a function or one of main, other/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#applyArgs', function () {
|
describe('#applyArgs', function () {
|
||||||
_v4.times(10, function (i) {
|
_.times(10, function (i) {
|
||||||
var method = i > 5 ? 'apply' : 'call';
|
var method = i > 5 ? 'apply' : 'call';
|
||||||
var argCount = i + 1;
|
var argCount = i + 1;
|
||||||
var slice = 1;
|
var slice = 1;
|
||||||
@ -358,8 +358,8 @@ describe('Utils', function () {
|
|||||||
var func = function () {};
|
var func = function () {};
|
||||||
stub(func, method);
|
stub(func, method);
|
||||||
|
|
||||||
var args = _v4.map(new Array(i), function (val, i) { return i; });
|
var args = _.map(new Array(i), function (val, i) { return i; });
|
||||||
_v4.applyArgs(func, null, args);
|
_.applyArgs(func, null, args);
|
||||||
|
|
||||||
expect(func[method].callCount).to.eql(1);
|
expect(func[method].callCount).to.eql(1);
|
||||||
if (method === 'apply') {
|
if (method === 'apply') {
|
||||||
@ -374,9 +374,9 @@ describe('Utils', function () {
|
|||||||
var func = function () {};
|
var func = function () {};
|
||||||
stub(func, method);
|
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);
|
var expected = args.slice(slice);
|
||||||
_v4.applyArgs(func, null, args, slice);
|
_.applyArgs(func, null, args, slice);
|
||||||
|
|
||||||
expect(func[method].callCount).to.eql(1);
|
expect(func[method].callCount).to.eql(1);
|
||||||
if (method === 'apply') {
|
if (method === 'apply') {
|
||||||
@ -390,24 +390,24 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
describe('#getUnwrittenFromStream', function () {
|
describe('#getUnwrittenFromStream', function () {
|
||||||
it('ignores things that do not have writableState', function () {
|
it('ignores things that do not have writableState', function () {
|
||||||
expect(_v4.getUnwrittenFromStream()).to.be(undefined);
|
expect(_.getUnwrittenFromStream()).to.be(undefined);
|
||||||
expect(_v4.getUnwrittenFromStream(false)).to.be(undefined);
|
expect(_.getUnwrittenFromStream(false)).to.be(undefined);
|
||||||
expect(_v4.getUnwrittenFromStream([])).to.be(undefined);
|
expect(_.getUnwrittenFromStream([])).to.be(undefined);
|
||||||
expect(_v4.getUnwrittenFromStream({})).to.be(undefined);
|
expect(_.getUnwrittenFromStream({})).to.be(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (require('stream').Writable) {
|
if (require('stream').Writable) {
|
||||||
var MockWritableStream = require('../../mocks/writable_stream');
|
var MockWritableStream = require('../../mocks/writable_stream');
|
||||||
it('ignores empty stream', function () {
|
it('ignores empty stream', function () {
|
||||||
var stream = new MockWritableStream();
|
var stream = new MockWritableStream();
|
||||||
expect(_v4.getUnwrittenFromStream(stream)).to.be('');
|
expect(_.getUnwrittenFromStream(stream)).to.be('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns only what is in the buffer', function () {
|
it('returns only what is in the buffer', function () {
|
||||||
var stream = new MockWritableStream();
|
var stream = new MockWritableStream();
|
||||||
stream.write('hot');
|
stream.write('hot');
|
||||||
stream.write('dog');
|
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');
|
var expect = require('expect.js');
|
||||||
module.exports = function expectSubObject(obj, subObj) {
|
module.exports = function expectSubObject(obj, subObj) {
|
||||||
_v4.forOwn(subObj, function (val, prop) {
|
_.forOwn(subObj, function (val, prop) {
|
||||||
if (typeof obj[prop] === 'object') {
|
if (typeof obj[prop] === 'object') {
|
||||||
// non-strict equals
|
// non-strict equals
|
||||||
expect(obj[prop]).to.eql(val, 'Expected property' + prop + ' of object to equal ' + val);
|
expect(obj[prop]).to.eql(val, 'Expected property' + prop + ' of object to equal ' + val);
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
module.exports = JenkinsReporter;
|
module.exports = JenkinsReporter;
|
||||||
|
|
||||||
var Base = require('mocha/lib/reporters/base');
|
var Base = require('mocha/lib/reporters/base');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
var makeJUnitXml = require('./make_j_unit_xml');
|
var makeJUnitXml = require('./make_j_unit_xml');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@ -15,7 +15,7 @@ var path = require('path');
|
|||||||
var inspect = require('util').inspect;
|
var inspect = require('util').inspect;
|
||||||
|
|
||||||
var log = (function () {
|
var log = (function () {
|
||||||
var locked = _v4.bind(process.stdout.write, process.stdout);
|
var locked = _.bind(process.stdout.write, process.stdout);
|
||||||
return function (str) {
|
return function (str) {
|
||||||
if (typeof str !== 'string') {
|
if (typeof str !== 'string') {
|
||||||
str = inspect(str);
|
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 integration = _.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 unit = _.find(process.argv, function (arg) { return arg.indexOf('test/unit') > -1; });
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
if (unit) {
|
if (unit) {
|
||||||
@ -126,7 +126,7 @@ function JenkinsReporter(runner) {
|
|||||||
errMsg += '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
|
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;
|
return indt() + ' ' + line;
|
||||||
}).join('\n'));
|
}).join('\n'));
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ function JenkinsReporter(runner) {
|
|||||||
|
|
||||||
runner.on('hook end', function (hook) {
|
runner.on('hook end', function (hook) {
|
||||||
if (hook.title.indexOf('"after each"') > -1 && stack[0] && stack[0].results.length) {
|
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.stdout += stack[0].stdout;
|
||||||
result.stderr += stack[0].stderr;
|
result.stderr += stack[0].stderr;
|
||||||
stack[0].stdout = stack[0].stderr = '';
|
stack[0].stdout = stack[0].stderr = '';
|
||||||
@ -157,7 +157,7 @@ function JenkinsReporter(runner) {
|
|||||||
restoreStdio();
|
restoreStdio();
|
||||||
var xml = makeJUnitXml('node ' + process.version, {
|
var xml = makeJUnitXml('node ' + process.version, {
|
||||||
stats: stats,
|
stats: stats,
|
||||||
suites: _v4.map(rootSuite.suites, function removeElements(suite) {
|
suites: _.map(rootSuite.suites, function removeElements(suite) {
|
||||||
var s = {
|
var s = {
|
||||||
name: suite.name,
|
name: suite.name,
|
||||||
start: suite.start,
|
start: suite.start,
|
||||||
@ -168,7 +168,7 @@ function JenkinsReporter(runner) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (suite.suites) {
|
if (suite.suites) {
|
||||||
s.suites = _v4.map(suite.suites, removeElements);
|
s.suites = _.map(suite.suites, removeElements);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
})
|
})
|
||||||
|
|||||||
@ -28,11 +28,11 @@ var testXml = require('xmlbuilder');
|
|||||||
var suites = testXml.create('testsuites');
|
var suites = testXml.create('testsuites');
|
||||||
var suiteCount = 0;
|
var suiteCount = 0;
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
|
|
||||||
function makeJUnitXml(runnerName, testDetails) {
|
function makeJUnitXml(runnerName, testDetails) {
|
||||||
_v4.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
_.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
||||||
|
|
||||||
var suite = suites.ele('testsuite', {
|
var suite = suites.ele('testsuite', {
|
||||||
package: 'elasticsearch-js',
|
package: 'elasticsearch-js',
|
||||||
@ -41,12 +41,12 @@ function makeJUnitXml(runnerName, testDetails) {
|
|||||||
timestamp: moment(suiteInfo.start).toJSON(),
|
timestamp: moment(suiteInfo.start).toJSON(),
|
||||||
hostname: 'localhost',
|
hostname: 'localhost',
|
||||||
tests: (suiteInfo.results && suiteInfo.results.length) || 0,
|
tests: (suiteInfo.results && suiteInfo.results.length) || 0,
|
||||||
failures: _v4.filter(suiteInfo.results, { pass: false }).length,
|
failures: _.filter(suiteInfo.results, { pass: false }).length,
|
||||||
errors: 0,
|
errors: 0,
|
||||||
time: suiteInfo.time / 1000
|
time: suiteInfo.time / 1000
|
||||||
});
|
});
|
||||||
|
|
||||||
_v4.each(suiteInfo.results, function (testInfo) {
|
_.each(suiteInfo.results, function (testInfo) {
|
||||||
var section;
|
var section;
|
||||||
var integration = false;
|
var integration = false;
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ function makeJUnitXml(runnerName, testDetails) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (suiteInfo.suites) {
|
if (suiteInfo.suites) {
|
||||||
_v4.each(suiteInfo.suites, serializeSuite);
|
_.each(suiteInfo.suites, serializeSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
giveOutput(suite, suiteInfo);
|
giveOutput(suite, suiteInfo);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
// var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var root = require('path').join(__dirname, '../..');
|
var root = require('path').join(__dirname, '../..');
|
||||||
var browserify = require('browserify');
|
var browserify = require('browserify');
|
||||||
@ -12,7 +12,7 @@ var browserBuildsDir = root + '/test/unit/browser_builds';
|
|||||||
|
|
||||||
var testFiles = {};
|
var testFiles = {};
|
||||||
|
|
||||||
testFiles.unit = _v4(fs.readdirSync(unitSpecDir))
|
testFiles.unit = _(fs.readdirSync(unitSpecDir))
|
||||||
.difference([
|
.difference([
|
||||||
'file_logger.js',
|
'file_logger.js',
|
||||||
'http_connector.js',
|
'http_connector.js',
|
||||||
|
|||||||
Reference in New Issue
Block a user