All tests are passing. Removed the HTML docs

This commit is contained in:
Spencer Alger
2013-10-03 10:05:58 -07:00
parent 462444c20b
commit 9e608226e1
229 changed files with 11719 additions and 45504 deletions

View File

@ -1,5 +1,5 @@
module.exports = {
'cluster.nodeHotThreads': [
'cluster.node_hot_threads': [
'/_cluster/nodes/hotthreads',
'/_cluster/nodes/hot_threads',
'/_nodes/hot_threads',
@ -7,7 +7,7 @@ module.exports = {
'/_cluster/nodes/{node_id}/hot_threads',
'/_nodes/{node_id}/hot_threads'
],
'cluster.nodeInfo': [
'cluster.node_info': [
'/_cluster/nodes',
'/_nodes/settings',
'/_nodes/os',
@ -29,10 +29,10 @@ module.exports = {
'/_nodes/{node_id}/http',
'/_nodes/{node_id}/plugin'
],
'cluster.nodeShutdown': [
'cluster.node_shutdown': [
'/_cluster/nodes/_shutdown'
],
'cluster.nodeStats': [
'cluster.node_stats': [
'/_cluster/nodes/stats',
'/_nodes/stats/{metric_family}',
'/_nodes/stats/indices/{metric}/{fields}',
@ -43,7 +43,7 @@ module.exports = {
'get': [
'/{index}/{type}/{id}/_source'
],
'indices.deleteMapping': [
'indices.delete_mapping': [
'/{index}/{type}/_mapping'
],
'indices.stats': [
@ -56,5 +56,8 @@ module.exports = {
'/{index}/_stats/indexing',
'/{index}/_stats/search/{search_groups}',
'/{index}/_stats/fielddata/{fields}'
],
'search': [
'/_search'
]
};
};

View File

@ -1,4 +1,4 @@
var _ = require('../../src/lib/utils')
var _ = require('../../src/lib/toolbelt')
, asset = require('assert')
, path = require('path')
, fs = require('fs')
@ -29,18 +29,13 @@ _.each(docs, function (doc) {
// and each definition within each doc (should only be one)
_.each(doc, function (def, name) {
name = _.map(name.split('.'), function (name) {
return _.camelCase(name);
}).join('.');
var steps = name.split('.')
, fileName = steps.pop() + '.js'
, dirName = _.joinPath(outputDir, steps.join('/') || './');
var spec = {
name: name,
methods: def.methods,
methods: _.map(def.methods, function (m) { return m.toLowerCase(); }),
docUrl: def.documentation,
urlParts: def.url.parts,
params: def.url.params,
@ -57,14 +52,8 @@ _.each(docs, function (doc) {
}
})));
// turn a url string into an object describing the url, then sort them in decending order by how many args they have
spec.urls = _.sortBy(spec.urls, function (url) {
var vars = url.match(templates.urlParamRE);
return vars ? vars.length * -1 : 0;
});
mkdirp.sync(dirName);
fs.writeFileSync(_.joinPath(dirName, fileName), templates.action(spec));
});
});
});

View File

@ -1,4 +1,5 @@
var _ = require('<%= path2lib %>utils');<%
var _ = require('<%= path2lib %>toolbelt')
, paramHelper = require('<%= path2lib %>param_helper');<%
if (_.keys(enumOptions).length) {
@ -23,29 +24,42 @@ var <%= name %>Options = <%= stringify(options) %>;<%
})
%>
*/
function do<%= _.studlyCase(name) %>(params) {
var request = {}
function do<%= _.studlyCase(name) %>(params, callback) {
params = params || {};
var request = {<%
if (~name.indexOf('exists')) {%>
ignore: _.union([404], params.ignore)<%
} else {%>
ignore: params.ignore<%
}
if (body) { if (_.contains(['bulk', 'msearch'], name)) {%>,
body: paramHelper.bulkBody(params.body, this.client.serializer) || null<%
} else { %>,
body: params.body || null<%
} }%>
}
, url = {}
, query = {};
, query = {}
, responseOpts = {};
<%
params = params || {};<%
if (body) { %>
request.body = params.body || null;<%
}
%>
<%
if (methods.length > 1) { %>
if (params.method) {
if (params.method = _.toLowerString(params.method)) {
if (<%= _.map(methods, function (method) { return 'params.method === ' + stringify(method) }).join(' || ') %>) {
request.method = params.method;
} else {
throw new TypeError('Invalid method: should be one of <%= methods.join(', ') %>');
}
} else {
request.method = <%= stringify(methods[0]) %>;
} else {<%
if (_.contains(methods, 'get')) {
var nonGet = _.find(methods, function (m) {return m !== 'get'; });%>
request.method = params.body ? <%= stringify(nonGet) %> : 'get';<%
} else {%>
request.method = <%= stringify(methods[0]) %>;<%
}%>
}<%
} else { %>
} else {%>
request.method = <%= stringify(methods[0]) %>;<%
}
%>
@ -54,13 +68,17 @@ if (methods.length > 1) { %>
<%= writeParams(2, urlParts, 'url.') %>
// build the url
<%= writeUrls(2, urls) %>
<%= writeUrls(2, urls, urlParts, params) %>
// build the query string
<%= writeParams(2, params, 'query.') %>
request.url = request.url + _.makeQueryString(query);
return this.client.request(request);
var reqPromise = this.client.request(request);
if (callback) {
reqPromise.then(_.bind(callback, null, null), callback);
}
return reqPromise;
}
module.exports = do<%= _.studlyCase(name) %>;
module.exports = do<%= _.studlyCase(name) %>;

View File

@ -4,4 +4,4 @@ if (<%= get %>.toLowerCase && (<%= get %> = <%= get %>.toLowerCase())
<%= set %> = false;
} else {
<%= set %> = !!<%= get %>;
}
}

View File

@ -1,5 +1,5 @@
if (_.isInterval(<%= get %>)) {
if (_.isNumeric(<%= get %>) || _.isInterval(<%= get %>)) {
<%= set %> = <%= get %>;
} else {
throw new TypeError('Invalid <%= name %>: ' + <%= get %> + ' should be in interval notation (an integer followed by one of Mwdhmsy).');
}
throw new TypeError('Invalid <%= name %>: ' + <%= get %> + ' should be a number or in interval notation (an integer followed by one of Mwdhmsy).');
}

View File

@ -1,5 +1,5 @@
var _ = require('../../../src/lib/utils')
var _ = require('../../../src/lib/toolbelt')
, fs = require('fs')
, path = require('path')
, urlParamRE = /\{(\w+)\}/g;
@ -89,25 +89,56 @@ var templateGlobals = {
return l.toString();
},
writeUrls: function (indent, urls) {
writeUrls: function (indent, urls, urlParams, queryStringParams) {
var l = lines(indent);
function urlVarIsRequired(varDetails) {
varDetails = typeof varDetails === 'string' ? urlParams[varDetails] : varDetails;
return varDetails && (varDetails.required || !varDetails.default);
}
// turn a url string into an object describing the url, then sort them in decending order by how many args they have
urls = _.sortBy(urls, function (url) {
var requiredVars = _.filter(_.collectMatches(url, urlParamRE), function (match) {
return urlVarIsRequired(urlParams[match[1]]);
});
return requiredVars ? requiredVars.length * -1 : 0;
});
_.each(urls, function (url, urlIndex) {
// collect the vars from the url and replace them to form the js that will build the url
var makeL = lines(), vars = [];
makeL('request.url = \'' + url.replace(urlParamRE, function (match, varName) {
vars.push(varName);
return '\' + url.' + varName + ' + \'';
var varDetails = urlParams[varName];
varDetails.name = varName;
vars.push(varDetails);
if (urlVarIsRequired(varDetails)) {
return '\' + encodeURIComponent(url.' + varName + ') + \'';
} else {
return '\' + encodeURIComponent(url.' + varName + ' || ' + stringify(varDetails.default) + ') + \'';
}
}) + '\';');
makeL(_.filter(_.map(vars, function (v, i) {
if (_.has(queryStringParams, v.name)) {
// delete the param so that it's not used later on in the queryString
return 'delete params.' + v.name + ';';
}
})).join(' '));
if (vars.length || urlIndex) {
var condition = _.map(vars, function (v) { return 'url.hasOwnProperty(\'' + v + '\')'; }).join(' && ');
l((urlIndex > 0 ? 'else ' : '') + (condition ? 'if (' + condition + ') ' : ' ') + '{').in();
var requiredVars = _.filter(vars, urlVarIsRequired);
var condition = _.map(requiredVars, function (v) {
return 'url.hasOwnProperty(\'' + v.name + '\')';
}).join(' && ');
l((urlIndex > 0 ? 'else ' : '') + (condition ? 'if (' + condition + ') ' : '') + '{').in();
l.split(makeL.toString()).out();
l('}');
if (urlIndex === urls.length - 1 && vars.length) {
if (urlIndex === urls.length - 1 && condition) {
l('else {').in();
l('throw new TypeError(\'Unable to build a url with those params. Supply at least ' + vars.join(', ') + '\');').out();
l('}');
@ -141,6 +172,8 @@ var templateGlobals = {
return '*';
case 'enum':
return 'String';
case 'list':
return 'String|ArrayOfStrings|Boolean';
default:
return type;
}
@ -174,4 +207,4 @@ templates.text = templates.string;
module.exports = {
action: templates.action,
urlParamRE: urlParamRE
};
};

View File

@ -1,7 +1,14 @@
if (typeof <%= get %> === 'string') {
switch (typeof <%= get %>) {
case 'string':
<%= set %> = <%= get %>;
} else if (_.isArray(<%= get %>)) {
<%= set %> = <%= get %>.join(',');
} else {
throw new TypeError('Invalid <%= name %>: ' + <%= get %> + ' should be a comma seperated list or array.');
}
break;
case 'object':
if (_.isArray(<%= get %>)) {
<%= set %> = <%= get %>.join(',');
} else {
throw new TypeError('Invalid <%= name %>: ' + <%= get %> + ' should be a comma seperated list, array, or boolean.');
}
break;
default:
<%= set %> = !!<%= get %>;
}

View File

@ -1,5 +1,5 @@
if (typeof <%= get %> !== 'object' && typeof <%= get %> !== 'undefined') {
if (typeof <%= get %> !== 'object' && <%= get %>) {
<%= set %> = '' + <%= get %>;
} else {
throw new TypeError('Invalid <%= name %>: ' + <%= get %> + ' should be a string.');
}
}