Skip to content

Commit

Permalink
API generation
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Jan 31, 2020
1 parent 5f1edbb commit ebb96e9
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 71 deletions.
84 changes: 84 additions & 0 deletions api/api/cat.ml.jobs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

'use strict'

/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */

function buildCatMlJobs (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts

const acceptedQuerystring = [
'allow_no_jobs',
'bytes',
'format',
'h',
'help',
's',
'time',
'v'
]

const snakeCase = {
allowNoJobs: 'allow_no_jobs'

}

/**
* Perform a cat.ml.jobs request
* http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html
*/
return function catMlJobs (params, options, callback) {
options = options || {}
if (typeof options === 'function') {
callback = options
options = {}
}
if (typeof params === 'function' || params == null) {
callback = params
params = {}
options = {}
}

// validate headers object
if (options.headers != null && typeof options.headers !== 'object') {
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
return handleError(err, callback)
}

var warnings = []
var { method, body, jobId, job_id, ...querystring } = params
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings)

var ignore = options.ignore
if (typeof ignore === 'number') {
options.ignore = [ignore]
}

var path = ''

if ((job_id || jobId) != null) {
if (method == null) method = 'GET'
path = '/' + '_cat' + '/' + 'ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId)
} else {
if (method == null) method = 'GET'
path = '/' + '_cat' + '/' + 'ml' + '/' + 'anomaly_detectors'
}

// build request object
const request = {
method,
path,
body: null,
querystring
}

options.warnings = warnings.length === 0 ? null : warnings
return makeRequest(request, options, callback)
}
}

module.exports = buildCatMlJobs
45 changes: 19 additions & 26 deletions api/api/indices.flush_synced.js → api/api/eql.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,23 @@
/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */

function buildIndicesFlushSynced (opts) {
function buildEqlSearch (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts

const acceptedQuerystring = [
'ignore_unavailable',
'allow_no_indices',
'expand_wildcards',
'pretty',
'human',
'error_trace',
'source',
'filter_path'

]

const snakeCase = {
ignoreUnavailable: 'ignore_unavailable',
allowNoIndices: 'allow_no_indices',
expandWildcards: 'expand_wildcards',
errorTrace: 'error_trace',
filterPath: 'filter_path'

}

/**
* Perform a indices.flush_synced request
* Performs a synced flush operation on one or more indices.
* https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush-api.html
* Perform a eql.search request
* https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search.html
*/
return function indicesFlushSynced (params, options, callback) {
return function eqlSearch (params, options, callback) {
options = options || {}
if (typeof options === 'function') {
callback = options
Expand All @@ -47,6 +35,16 @@ function buildIndicesFlushSynced (opts) {
options = {}
}

// check required parameters
if (params['index'] == null) {
const err = new ConfigurationError('Missing required parameter: index')
return handleError(err, callback)
}
if (params['body'] == null) {
const err = new ConfigurationError('Missing required parameter: body')
return handleError(err, callback)
}

// validate headers object
if (options.headers != null && typeof options.headers !== 'object') {
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
Expand All @@ -64,13 +62,8 @@ function buildIndicesFlushSynced (opts) {

var path = ''

if ((index) != null) {
if (method == null) method = body == null ? 'GET' : 'POST'
path = '/' + encodeURIComponent(index) + '/' + '_flush' + '/' + 'synced'
} else {
if (method == null) method = body == null ? 'GET' : 'POST'
path = '/' + '_flush' + '/' + 'synced'
}
if (method == null) method = body == null ? 'GET' : 'POST'
path = '/' + encodeURIComponent(index) + '/' + '_eql' + '/' + 'search'

// build request object
const request = {
Expand All @@ -85,4 +78,4 @@ function buildIndicesFlushSynced (opts) {
}
}

module.exports = buildIndicesFlushSynced
module.exports = buildEqlSearch
11 changes: 3 additions & 8 deletions api/api/indices.get_upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function buildIndicesGetUpgrade (opts) {

/**
* Perform a indices.get_upgrade request
* The _upgrade API is no longer useful and will be removed.
* DEPRECATED Returns a progress status of current upgrade.
* https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html
*/
return function indicesGetUpgrade (params, options, callback) {
Expand Down Expand Up @@ -64,13 +64,8 @@ function buildIndicesGetUpgrade (opts) {

var path = ''

if ((index) != null) {
if (method == null) method = 'GET'
path = '/' + encodeURIComponent(index) + '/' + '_upgrade'
} else {
if (method == null) method = 'GET'
path = '/' + '_upgrade'
}
if (method == null) method = 'GET'
path = '/' + encodeURIComponent(index) + '/' + '_upgrade'

// build request object
const request = {
Expand Down
11 changes: 3 additions & 8 deletions api/api/indices.upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function buildIndicesUpgrade (opts) {

/**
* Perform a indices.upgrade request
* The _upgrade API is no longer useful and will be removed.
* DEPRECATED Upgrades to the current version of Lucene.
* https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html
*/
return function indicesUpgrade (params, options, callback) {
Expand Down Expand Up @@ -68,13 +68,8 @@ function buildIndicesUpgrade (opts) {

var path = ''

if ((index) != null) {
if (method == null) method = 'POST'
path = '/' + encodeURIComponent(index) + '/' + '_upgrade'
} else {
if (method == null) method = 'POST'
path = '/' + '_upgrade'
}
if (method == null) method = 'POST'
path = '/' + encodeURIComponent(index) + '/' + '_upgrade'

// build request object
const request = {
Expand Down
3 changes: 2 additions & 1 deletion api/api/ml.get_trained_models.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function buildMlGetTrainedModels (opts) {
'include_model_definition',
'decompress_definition',
'from',
'size'
'size',
'tags'
]

const snakeCase = {
Expand Down
2 changes: 1 addition & 1 deletion api/api/slm.delete_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function buildSlmDeleteLifecycle (opts) {

/**
* Perform a slm.delete_lifecycle request
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete.html
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete-policy.html
*/
return function slmDeleteLifecycle (params, options, callback) {
options = options || {}
Expand Down
2 changes: 1 addition & 1 deletion api/api/slm.execute_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function buildSlmExecuteLifecycle (opts) {

/**
* Perform a slm.execute_lifecycle request
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute.html
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute-policy.html
*/
return function slmExecuteLifecycle (params, options, callback) {
options = options || {}
Expand Down
2 changes: 1 addition & 1 deletion api/api/slm.get_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function buildSlmGetLifecycle (opts) {

/**
* Perform a slm.get_lifecycle request
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get-policy.html
*/
return function slmGetLifecycle (params, options, callback) {
options = options || {}
Expand Down
2 changes: 1 addition & 1 deletion api/api/slm.get_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function buildSlmGetStats (opts) {

/**
* Perform a slm.get_stats request
* https://www.elastic.co/guide/en/elasticsearch/reference/master/slm-get-stats.html
* https://www.elastic.co/guide/en/elasticsearch/reference/master/slm-api-get-stats.html
*/
return function slmGetStats (params, options, callback) {
options = options || {}
Expand Down
2 changes: 1 addition & 1 deletion api/api/slm.put_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function buildSlmPutLifecycle (opts) {

/**
* Perform a slm.put_lifecycle request
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put.html
* https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put-policy.html
*/
return function slmPutLifecycle (params, options, callback) {
options = options || {}
Expand Down
8 changes: 6 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function ESAPI (opts) {
help: lazyLoad('cat.help', opts),
indices: lazyLoad('cat.indices', opts),
master: lazyLoad('cat.master', opts),
ml: {
jobs: lazyLoad('cat.ml.jobs', opts)
},
nodeattrs: lazyLoad('cat.nodeattrs', opts),
nodes: lazyLoad('cat.nodes', opts),
pending_tasks: lazyLoad('cat.pending_tasks', opts),
Expand Down Expand Up @@ -140,6 +143,9 @@ function ESAPI (opts) {
putPolicy: lazyLoad('enrich.put_policy', opts),
stats: lazyLoad('enrich.stats', opts)
},
eql: {
search: lazyLoad('eql.search', opts)
},
exists: lazyLoad('exists', opts),
exists_source: lazyLoad('exists_source', opts),
existsSource: lazyLoad('exists_source', opts),
Expand Down Expand Up @@ -198,8 +204,6 @@ function ESAPI (opts) {
exists_type: lazyLoad('indices.exists_type', opts),
existsType: lazyLoad('indices.exists_type', opts),
flush: lazyLoad('indices.flush', opts),
flush_synced: lazyLoad('indices.flush_synced', opts),
flushSynced: lazyLoad('indices.flush_synced', opts),
forcemerge: lazyLoad('indices.forcemerge', opts),
freeze: lazyLoad('indices.freeze', opts),
get: lazyLoad('indices.get', opts),
Expand Down
25 changes: 18 additions & 7 deletions api/requestParams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,6 @@ export interface IndicesFlush extends Generic {
expand_wildcards?: 'open' | 'closed' | 'none' | 'all';
}

export interface IndicesFlushSynced extends Generic {
index?: string | string[];
ignore_unavailable?: boolean;
allow_no_indices?: boolean;
expand_wildcards?: 'open' | 'closed' | 'none' | 'all';
}

export interface IndicesForcemerge extends Generic {
index?: string | string[];
flush?: boolean;
Expand Down Expand Up @@ -1322,6 +1315,18 @@ export interface UpdateByQueryRethrottle extends Generic {
requests_per_second: number;
}

export interface CatMlJobs extends Generic {
job_id?: string;
allow_no_jobs?: boolean;
bytes?: 'b' | 'k' | 'kb' | 'm' | 'mb' | 'g' | 'gb' | 't' | 'tb' | 'p' | 'pb';
format?: string;
h?: string | string[];
help?: boolean;
s?: string | string[];
time?: 'd (Days)' | 'h (Hours)' | 'm (Minutes)' | 's (Seconds)' | 'ms (Milliseconds)' | 'micros (Microseconds)' | 'nanos (Nanoseconds)';
v?: boolean;
}

export interface CcrDeleteAutoFollowPattern extends Generic {
name: string;
}
Expand Down Expand Up @@ -1446,6 +1451,11 @@ export interface EnrichPutPolicy<T = any> extends Generic {
export interface EnrichStats extends Generic {
}

export interface EqlSearch<T = any> extends Generic {
index: string;
body: T;
}

export interface GraphExplore<T = any> extends Generic {
index: string | string[];
routing?: string;
Expand Down Expand Up @@ -1793,6 +1803,7 @@ export interface MlGetTrainedModels extends Generic {
decompress_definition?: boolean;
from?: number;
size?: number;
tags?: string | string[];
}

export interface MlGetTrainedModelsStats extends Generic {
Expand Down
Loading

0 comments on commit ebb96e9

Please sign in to comment.