|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +'use strict' |
| 6 | + |
| 7 | +/* eslint camelcase: 0 */ |
| 8 | +/* eslint no-unused-vars: 0 */ |
| 9 | + |
| 10 | +function buildMlGetTrainedModels (opts) { |
| 11 | + // eslint-disable-next-line no-unused-vars |
| 12 | + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts |
| 13 | + |
| 14 | + const acceptedQuerystring = [ |
| 15 | + 'allow_no_match', |
| 16 | + 'include_model_definition', |
| 17 | + 'from', |
| 18 | + 'size' |
| 19 | + ] |
| 20 | + |
| 21 | + const snakeCase = { |
| 22 | + allowNoMatch: 'allow_no_match', |
| 23 | + includeModelDefinition: 'include_model_definition' |
| 24 | + |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Perform a ml.get_trained_models request |
| 29 | + * TODO |
| 30 | + */ |
| 31 | + return function mlGetTrainedModels (params, options, callback) { |
| 32 | + options = options || {} |
| 33 | + if (typeof options === 'function') { |
| 34 | + callback = options |
| 35 | + options = {} |
| 36 | + } |
| 37 | + if (typeof params === 'function' || params == null) { |
| 38 | + callback = params |
| 39 | + params = {} |
| 40 | + options = {} |
| 41 | + } |
| 42 | + |
| 43 | + // validate headers object |
| 44 | + if (options.headers != null && typeof options.headers !== 'object') { |
| 45 | + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) |
| 46 | + return handleError(err, callback) |
| 47 | + } |
| 48 | + |
| 49 | + var warnings = [] |
| 50 | + var { method, body, modelId, model_id, ...querystring } = params |
| 51 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) |
| 52 | + |
| 53 | + var ignore = options.ignore |
| 54 | + if (typeof ignore === 'number') { |
| 55 | + options.ignore = [ignore] |
| 56 | + } |
| 57 | + |
| 58 | + var path = '' |
| 59 | + |
| 60 | + if ((model_id || modelId) != null) { |
| 61 | + if (method == null) method = 'GET' |
| 62 | + path = '/' + '_ml' + '/' + 'inference' + '/' + encodeURIComponent(model_id || modelId) |
| 63 | + } else { |
| 64 | + if (method == null) method = 'GET' |
| 65 | + path = '/' + '_ml' + '/' + 'inference' |
| 66 | + } |
| 67 | + |
| 68 | + // build request object |
| 69 | + const request = { |
| 70 | + method, |
| 71 | + path, |
| 72 | + body: null, |
| 73 | + querystring |
| 74 | + } |
| 75 | + |
| 76 | + options.warnings = warnings.length === 0 ? null : warnings |
| 77 | + return makeRequest(request, options, callback) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +module.exports = buildMlGetTrainedModels |
0 commit comments