API generation
This commit is contained in:
@ -20,15 +20,21 @@ function buildSearchTemplate (opts) {
|
||||
* @param {boolean} typed_keys - Specify whether aggregation and suggester names should be prefixed by their respective types in the response
|
||||
* @param {object} body - The search definition template and its params
|
||||
*/
|
||||
return function searchTemplate (params, callback) {
|
||||
return function searchTemplate (params, options, callback) {
|
||||
options = options || {}
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
if (typeof params === 'function' || params == null) {
|
||||
callback = params
|
||||
params = {}
|
||||
options = {}
|
||||
}
|
||||
// promises support
|
||||
if (callback == null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
searchTemplate(params, (err, body) => {
|
||||
searchTemplate(params, options, (err, body) => {
|
||||
err ? reject(err) : resolve(body)
|
||||
})
|
||||
})
|
||||
@ -114,7 +120,7 @@ function buildSearchTemplate (opts) {
|
||||
)
|
||||
}
|
||||
|
||||
var ignore = params.ignore || null
|
||||
var ignore = options.ignore || null
|
||||
if (typeof ignore === 'number') {
|
||||
ignore = [ignore]
|
||||
}
|
||||
@ -126,12 +132,17 @@ function buildSearchTemplate (opts) {
|
||||
path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'),
|
||||
querystring,
|
||||
body: params.body || '',
|
||||
headers: params.headers || null,
|
||||
ignore,
|
||||
requestTimeout: params.requestTimeout || null
|
||||
headers: params.headers || null
|
||||
}
|
||||
|
||||
return makeRequest(request, callback)
|
||||
const requestOptions = {
|
||||
ignore,
|
||||
requestTimeout: options.requestTimeout || null,
|
||||
maxRetries: options.maxRetries || null,
|
||||
asStream: options.asStream || false
|
||||
}
|
||||
|
||||
return makeRequest(request, requestOptions, callback)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user