save point durring huge unorganized refactor
This commit is contained in:
@ -1,73 +0,0 @@
|
||||
var _ = require('<%= path2lib %>utils');
|
||||
var errors = require('<%= path2lib %>errors');<%
|
||||
|
||||
|
||||
if (_.keys(enumOptions).length) {
|
||||
%>
|
||||
<% _.each(enumOptions, function(options, name) {
|
||||
%>
|
||||
var <%= name %>Options = <%= stringify(options) %>;<%
|
||||
});
|
||||
}
|
||||
%>
|
||||
|
||||
/**
|
||||
* Perform an elasticsearch [<%= name %>](<%= docUrl %>) request
|
||||
*
|
||||
* @for Client
|
||||
* @method <%= name %>
|
||||
* @param {Object} params - An object with parameters used to carry out this action<% _.each(params, function(param, paramName) { %>
|
||||
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><% if (param.description) { %> - <%= param.description %><% } %><%
|
||||
})
|
||||
%>
|
||||
*/
|
||||
function do<%= _.studlyCase(name) %>(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = {};
|
||||
} else {
|
||||
params = params || {};
|
||||
cb = typeof cb === 'function' ? cb : _.noop;
|
||||
}
|
||||
|
||||
var request = {
|
||||
<%= writeRequestObjectBody(4, name, body, methods) %>
|
||||
};
|
||||
var parts = {};
|
||||
var query = {};
|
||||
var responseOpts = {};
|
||||
<%
|
||||
|
||||
if (methods.length > 1) { %>
|
||||
// figure out the method
|
||||
if (params.method = _.toUpperString(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 {<%
|
||||
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]) %>;<%
|
||||
}%>
|
||||
}<%
|
||||
}
|
||||
%>
|
||||
|
||||
// find the paths's params
|
||||
<%= writeParams(2, urlParts, 'parts.') %>
|
||||
|
||||
// build the path
|
||||
<%= writeUrls(2, urls, urlParts, params) %>
|
||||
|
||||
// build the query string
|
||||
<%= writeParams(2, params, 'query.') %>
|
||||
request.path = request.path + _.makeQueryString(query);
|
||||
|
||||
<%= returnStatement(2, name) %>
|
||||
}
|
||||
|
||||
module.exports = do<%= _.studlyCase(name) %>;
|
||||
@ -12,16 +12,16 @@ _.each(actions, function (action) {
|
||||
var className = _.studlyCase(namespace) + 'NS';
|
||||
%>
|
||||
|
||||
api.<%= namespace %> = function <%= className %>(client) {
|
||||
if (this instanceof <%= className %>) {
|
||||
this.client = client;
|
||||
} else {
|
||||
return new <%= className %>(client);
|
||||
}
|
||||
api.<%= namespace %> = function <%= className %>(transport) {
|
||||
this.transport = transport;
|
||||
};<%
|
||||
}
|
||||
%>
|
||||
}%>
|
||||
|
||||
<%= partials.client_action(action) %><%
|
||||
|
||||
}); %>
|
||||
});
|
||||
|
||||
_.each(proxies, function (action) {%>
|
||||
<%= partials.client_action_proxy(action) %><%
|
||||
});
|
||||
%>
|
||||
|
||||
19
scripts/generate/js_api/templates/client_action_proxy.tmpl
Normal file
19
scripts/generate/js_api/templates/client_action_proxy.tmpl
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Perform a [<%= name %>](<%= docUrl %>) request
|
||||
*
|
||||
* @param {Object} params - An object with parameters used to carry out this action<%
|
||||
_.each(allParams, function(param, paramName) { %>
|
||||
* @param {<%= paramType(param.type) %>} <%= paramWithDefault('params.' + paramName, param.default) %><%
|
||||
if (param.description) {
|
||||
%> - <%= param.description %><%
|
||||
}
|
||||
%><% }) %>
|
||||
*/
|
||||
api<%= (location[0] === '[' ? '' : '.') + location %> = ca.proxy(<%= 'api' + (proxy[0] === '[' ? '' : '.') + proxy %><%
|
||||
if (typeof transformBody === 'string') { %>, {
|
||||
transform: function (params) {
|
||||
<%= indent(transformBody, 4) %>
|
||||
}
|
||||
}<%
|
||||
}
|
||||
%>);
|
||||
@ -42,6 +42,13 @@ var templateGlobals = {
|
||||
|
||||
_: _,
|
||||
|
||||
indent: function (block, spaces) {
|
||||
var indent = _.repeat(' ', spaces);
|
||||
return block.split('\n').map(function (line) {
|
||||
return indent + line;
|
||||
}).join('\n');
|
||||
},
|
||||
|
||||
paramType: function (type) {
|
||||
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
|
||||
case 'time':
|
||||
|
||||
Reference in New Issue
Block a user