From f56ae1a70d682844e5c1a372bb8928e1b7463ebf Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Fri, 11 Jan 2019 14:08:49 +0100 Subject: [PATCH] Request parameters typings (#748) --- api/requestParams.d.ts | 1895 +++++++++++++++++++++++++ index.d.ts | 850 +++++------ scripts/run.js | 11 +- scripts/utils/genMain.js | 9 +- scripts/utils/generateRequestTypes.js | 71 + scripts/utils/index.js | 3 +- 6 files changed, 2411 insertions(+), 428 deletions(-) create mode 100644 api/requestParams.d.ts create mode 100644 scripts/utils/generateRequestTypes.js diff --git a/api/requestParams.d.ts b/api/requestParams.d.ts new file mode 100644 index 000000000..8277562fe --- /dev/null +++ b/api/requestParams.d.ts @@ -0,0 +1,1895 @@ +export interface Generic { + method?: string; + ignore?: number | number[]; + filter_path?: string | string[]; + pretty?: boolean; + human?: boolean; + error_trace?: boolean; + source?: string; +} + +export interface Bulk extends Generic { + index?: string; + type?: string; + wait_for_active_shards?: string; + refresh?: 'true' | 'false' | 'wait_for'; + routing?: string; + timeout?: string; + fields?: string | string[]; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + pipeline?: string; + body: any; +} + +export interface CatAliases extends Generic { + name?: string | string[]; + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatAllocation extends Generic { + node_id?: string | string[]; + format?: string; + bytes?: 'b' | 'k' | 'kb' | 'm' | 'mb' | 'g' | 'gb' | 't' | 'tb' | 'p' | 'pb'; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatCount extends Generic { + index?: string | string[]; + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatFielddata extends Generic { + fields?: string | string[]; + format?: string; + bytes?: 'b' | 'k' | 'kb' | 'm' | 'mb' | 'g' | 'gb' | 't' | 'tb' | 'p' | 'pb'; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatHealth extends Generic { + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + ts?: boolean; + v?: boolean; +} + +export interface CatHelp extends Generic { + help?: boolean; + s?: string | string[]; +} + +export interface CatIndices extends Generic { + index?: string | string[]; + format?: string; + bytes?: 'b' | 'k' | 'm' | 'g'; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + health?: 'green' | 'yellow' | 'red'; + help?: boolean; + pri?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatMaster extends Generic { + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatNodeattrs extends Generic { + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatNodes extends Generic { + format?: string; + full_id?: boolean; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatPendingTasks extends Generic { + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatPlugins extends Generic { + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatRecovery extends Generic { + index?: string | string[]; + format?: string; + bytes?: 'b' | 'k' | 'kb' | 'm' | 'mb' | 'g' | 'gb' | 't' | 'tb' | 'p' | 'pb'; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatRepositories extends Generic { + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatSegments extends Generic { + index?: string | string[]; + format?: string; + bytes?: 'b' | 'k' | 'kb' | 'm' | 'mb' | 'g' | 'gb' | 't' | 'tb' | 'p' | 'pb'; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatShards extends Generic { + index?: string | string[]; + format?: string; + bytes?: 'b' | 'k' | 'kb' | 'm' | 'mb' | 'g' | 'gb' | 't' | 'tb' | 'p' | 'pb'; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatSnapshots extends Generic { + repository?: string | string[]; + format?: string; + ignore_unavailable?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatTasks extends Generic { + format?: string; + node_id?: string | string[]; + actions?: string | string[]; + detailed?: boolean; + parent_task?: number; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatTemplates extends Generic { + name?: string; + format?: string; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface CatThreadPool extends Generic { + thread_pool_patterns?: string | string[]; + format?: string; + size?: '' | 'k' | 'm' | 'g' | 't' | 'p'; + local?: boolean; + master_timeout?: string; + h?: string | string[]; + help?: boolean; + s?: string | string[]; + v?: boolean; +} + +export interface ClearScroll extends Generic { + scroll_id?: string | string[]; + body?: any; +} + +export interface ClusterAllocationExplain extends Generic { + include_yes_decisions?: boolean; + include_disk_info?: boolean; + body?: any; +} + +export interface ClusterGetSettings extends Generic { + flat_settings?: boolean; + master_timeout?: string; + timeout?: string; + include_defaults?: boolean; +} + +export interface ClusterHealth extends Generic { + index?: string | string[]; + level?: 'cluster' | 'indices' | 'shards'; + local?: boolean; + master_timeout?: string; + timeout?: string; + wait_for_active_shards?: string; + wait_for_nodes?: string; + wait_for_events?: 'immediate' | 'urgent' | 'high' | 'normal' | 'low' | 'languid'; + wait_for_no_relocating_shards?: boolean; + wait_for_no_initializing_shards?: boolean; + wait_for_status?: 'green' | 'yellow' | 'red'; +} + +export interface ClusterPendingTasks extends Generic { + local?: boolean; + master_timeout?: string; +} + +export interface ClusterPutSettings extends Generic { + flat_settings?: boolean; + master_timeout?: string; + timeout?: string; + body: any; +} + +export interface ClusterRemoteInfo extends Generic { +} + +export interface ClusterReroute extends Generic { + dry_run?: boolean; + explain?: boolean; + retry_failed?: boolean; + metric?: string | string[]; + master_timeout?: string; + timeout?: string; + body?: any; +} + +export interface ClusterState extends Generic { + index?: string | string[]; + metric?: string | string[]; + local?: boolean; + master_timeout?: string; + flat_settings?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface ClusterStats extends Generic { + node_id?: string | string[]; + flat_settings?: boolean; + timeout?: string; +} + +export interface Count extends Generic { + index?: string | string[]; + type?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + min_score?: number; + preference?: string; + routing?: string | string[]; + q?: string; + analyzer?: string; + analyze_wildcard?: boolean; + default_operator?: 'AND' | 'OR'; + df?: string; + lenient?: boolean; + terminate_after?: number; + body?: any; +} + +export interface Create extends Generic { + id: string; + index: string; + type: string; + wait_for_active_shards?: string; + parent?: string; + refresh?: 'true' | 'false' | 'wait_for'; + routing?: string; + timeout?: string; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; + pipeline?: string; + body: any; +} + +export interface Delete extends Generic { + id: string; + index: string; + type: string; + wait_for_active_shards?: string; + parent?: string; + refresh?: 'true' | 'false' | 'wait_for'; + routing?: string; + timeout?: string; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; +} + +export interface DeleteByQuery extends Generic { + index: string | string[]; + type?: string | string[]; + analyzer?: string; + analyze_wildcard?: boolean; + default_operator?: 'AND' | 'OR'; + df?: string; + from?: number; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + conflicts?: 'abort' | 'proceed'; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + lenient?: boolean; + preference?: string; + q?: string; + routing?: string | string[]; + scroll?: string; + search_type?: 'query_then_fetch' | 'dfs_query_then_fetch'; + search_timeout?: string; + size?: number; + sort?: string | string[]; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + terminate_after?: number; + stats?: string | string[]; + version?: boolean; + request_cache?: boolean; + refresh?: boolean; + timeout?: string; + wait_for_active_shards?: string; + scroll_size?: number; + wait_for_completion?: boolean; + requests_per_second?: number; + slices?: number; + body: any; +} + +export interface DeleteByQueryRethrottle extends Generic { + task_id: string; + requests_per_second: number; +} + +export interface DeleteScript extends Generic { + id: string; + timeout?: string; + master_timeout?: string; +} + +export interface Exists extends Generic { + id: string; + index: string; + type: string; + stored_fields?: string | string[]; + parent?: string; + preference?: string; + realtime?: boolean; + refresh?: boolean; + routing?: string; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; +} + +export interface ExistsSource extends Generic { + id: string; + index: string; + type: string; + parent?: string; + preference?: string; + realtime?: boolean; + refresh?: boolean; + routing?: string; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; +} + +export interface Explain extends Generic { + id: string; + index: string; + type: string; + analyze_wildcard?: boolean; + analyzer?: string; + default_operator?: 'AND' | 'OR'; + df?: string; + stored_fields?: string | string[]; + lenient?: boolean; + parent?: string; + preference?: string; + q?: string; + routing?: string; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + body?: any; +} + +export interface FieldCaps extends Generic { + index?: string | string[]; + fields?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + body?: any; +} + +export interface Get extends Generic { + id: string; + index: string; + type: string; + stored_fields?: string | string[]; + parent?: string; + preference?: string; + realtime?: boolean; + refresh?: boolean; + routing?: string; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; +} + +export interface GetScript extends Generic { + id: string; + master_timeout?: string; +} + +export interface GetSource extends Generic { + id: string; + index: string; + type: string; + parent?: string; + preference?: string; + realtime?: boolean; + refresh?: boolean; + routing?: string; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; +} + +export interface Index extends Generic { + id?: string; + index: string; + type: string; + wait_for_active_shards?: string; + op_type?: 'index' | 'create'; + parent?: string; + refresh?: 'true' | 'false' | 'wait_for'; + routing?: string; + timeout?: string; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; + pipeline?: string; + body: any; +} + +export interface IndicesAnalyze extends Generic { + index?: string; + body?: any; +} + +export interface IndicesClearCache extends Generic { + index?: string | string[]; + field_data?: boolean; + fielddata?: boolean; + fields?: string | string[]; + query?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + request_cache?: boolean; + request?: boolean; +} + +export interface IndicesClose extends Generic { + index: string | string[]; + timeout?: string; + master_timeout?: string; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface IndicesCreate extends Generic { + index: string; + wait_for_active_shards?: string; + timeout?: string; + master_timeout?: string; + update_all_types?: boolean; + body?: any; +} + +export interface IndicesDelete extends Generic { + index: string | string[]; + timeout?: string; + master_timeout?: string; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface IndicesDeleteAlias extends Generic { + index: string | string[]; + name: string | string[]; + timeout?: string; + master_timeout?: string; +} + +export interface IndicesDeleteTemplate extends Generic { + name: string; + timeout?: string; + master_timeout?: string; +} + +export interface IndicesExists extends Generic { + index: string | string[]; + local?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + flat_settings?: boolean; + include_defaults?: boolean; +} + +export interface IndicesExistsAlias extends Generic { + index?: string | string[]; + name: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + local?: boolean; +} + +export interface IndicesExistsTemplate extends Generic { + name: string | string[]; + flat_settings?: boolean; + master_timeout?: string; + local?: boolean; +} + +export interface IndicesExistsType extends Generic { + index: string | string[]; + type: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + local?: boolean; +} + +export interface IndicesFlush extends Generic { + index?: string | string[]; + force?: boolean; + wait_if_ongoing?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + 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; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + max_num_segments?: number; + only_expunge_deletes?: boolean; +} + +export interface IndicesGet extends Generic { + index: string | string[]; + local?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + flat_settings?: boolean; + include_defaults?: boolean; + master_timeout?: string; +} + +export interface IndicesGetAlias extends Generic { + index?: string | string[]; + name?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + local?: boolean; +} + +export interface IndicesGetFieldMapping extends Generic { + index?: string | string[]; + type?: string | string[]; + fields: string | string[]; + include_defaults?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + local?: boolean; +} + +export interface IndicesGetMapping extends Generic { + index?: string | string[]; + type?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + master_timeout?: string; + local?: boolean; +} + +export interface IndicesGetSettings extends Generic { + index?: string | string[]; + name?: string | string[]; + master_timeout?: string; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + flat_settings?: boolean; + local?: boolean; + include_defaults?: boolean; +} + +export interface IndicesGetTemplate extends Generic { + name?: string | string[]; + flat_settings?: boolean; + master_timeout?: string; + local?: boolean; +} + +export interface IndicesGetUpgrade extends Generic { + index?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface IndicesOpen extends Generic { + index: string | string[]; + timeout?: string; + master_timeout?: string; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + wait_for_active_shards?: string; +} + +export interface IndicesPutAlias extends Generic { + index: string | string[]; + name: string; + timeout?: string; + master_timeout?: string; + body?: any; +} + +export interface IndicesPutMapping extends Generic { + index?: string | string[]; + type: string; + timeout?: string; + master_timeout?: string; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + update_all_types?: boolean; + body: any; +} + +export interface IndicesPutSettings extends Generic { + index?: string | string[]; + master_timeout?: string; + timeout?: string; + preserve_existing?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + flat_settings?: boolean; + body: any; +} + +export interface IndicesPutTemplate extends Generic { + name: string; + order?: number; + create?: boolean; + timeout?: string; + master_timeout?: string; + flat_settings?: boolean; + body: any; +} + +export interface IndicesRecovery extends Generic { + index?: string | string[]; + detailed?: boolean; + active_only?: boolean; +} + +export interface IndicesRefresh extends Generic { + index?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface IndicesRollover extends Generic { + alias: string; + new_index?: string; + timeout?: string; + dry_run?: boolean; + master_timeout?: string; + wait_for_active_shards?: string; + body?: any; +} + +export interface IndicesSegments extends Generic { + index?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + verbose?: boolean; +} + +export interface IndicesShardStores extends Generic { + index?: string | string[]; + status?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface IndicesShrink extends Generic { + index: string; + target: string; + copy_settings?: boolean; + timeout?: string; + master_timeout?: string; + wait_for_active_shards?: string; + body?: any; +} + +export interface IndicesSplit extends Generic { + index: string; + target: string; + copy_settings?: boolean; + timeout?: string; + master_timeout?: string; + wait_for_active_shards?: string; + body?: any; +} + +export interface IndicesStats extends Generic { + index?: string | string[]; + metric?: string | string[]; + completion_fields?: string | string[]; + fielddata_fields?: string | string[]; + fields?: string | string[]; + groups?: string | string[]; + level?: 'cluster' | 'indices' | 'shards'; + types?: string | string[]; + include_segment_file_sizes?: boolean; +} + +export interface IndicesUpdateAliases extends Generic { + timeout?: string; + master_timeout?: string; + body: any; +} + +export interface IndicesUpgrade extends Generic { + index?: string | string[]; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + ignore_unavailable?: boolean; + wait_for_completion?: boolean; + only_ancient_segments?: boolean; +} + +export interface IndicesValidateQuery extends Generic { + index?: string | string[]; + type?: string | string[]; + explain?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + q?: string; + analyzer?: string; + analyze_wildcard?: boolean; + default_operator?: 'AND' | 'OR'; + df?: string; + lenient?: boolean; + rewrite?: boolean; + all_shards?: boolean; + body?: any; +} + +export interface Info extends Generic { +} + +export interface IngestDeletePipeline extends Generic { + id: string; + master_timeout?: string; + timeout?: string; +} + +export interface IngestGetPipeline extends Generic { + id?: string; + master_timeout?: string; +} + +export interface IngestProcessorGrok extends Generic { +} + +export interface IngestPutPipeline extends Generic { + id: string; + master_timeout?: string; + timeout?: string; + body: any; +} + +export interface IngestSimulate extends Generic { + id?: string; + verbose?: boolean; + body: any; +} + +export interface Mget extends Generic { + index?: string; + type?: string; + stored_fields?: string | string[]; + preference?: string; + realtime?: boolean; + refresh?: boolean; + routing?: string; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + body: any; +} + +export interface Msearch extends Generic { + index?: string | string[]; + type?: string | string[]; + search_type?: 'query_then_fetch' | 'query_and_fetch' | 'dfs_query_then_fetch' | 'dfs_query_and_fetch'; + max_concurrent_searches?: number; + typed_keys?: boolean; + pre_filter_shard_size?: number; + max_concurrent_shard_requests?: number; + body: any; +} + +export interface MsearchTemplate extends Generic { + index?: string | string[]; + type?: string | string[]; + search_type?: 'query_then_fetch' | 'query_and_fetch' | 'dfs_query_then_fetch' | 'dfs_query_and_fetch'; + typed_keys?: boolean; + max_concurrent_searches?: number; + body: any; +} + +export interface Mtermvectors extends Generic { + index?: string; + type?: string; + ids?: string | string[]; + term_statistics?: boolean; + field_statistics?: boolean; + fields?: string | string[]; + offsets?: boolean; + positions?: boolean; + payloads?: boolean; + preference?: string; + routing?: string; + parent?: string; + realtime?: boolean; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; + body?: any; +} + +export interface NodesHotThreads extends Generic { + node_id?: string | string[]; + interval?: string; + snapshots?: number; + threads?: number; + ignore_idle_threads?: boolean; + type?: 'cpu' | 'wait' | 'block'; + timeout?: string; +} + +export interface NodesInfo extends Generic { + node_id?: string | string[]; + metric?: string | string[]; + flat_settings?: boolean; + timeout?: string; +} + +export interface NodesReloadSecureSettings extends Generic { + node_id?: string | string[]; + timeout?: string; +} + +export interface NodesStats extends Generic { + metric?: string | string[]; + index_metric?: string | string[]; + node_id?: string | string[]; + completion_fields?: string | string[]; + fielddata_fields?: string | string[]; + fields?: string | string[]; + groups?: boolean; + level?: 'indices' | 'node' | 'shards'; + types?: string | string[]; + timeout?: string; + include_segment_file_sizes?: boolean; +} + +export interface NodesUsage extends Generic { + metric?: string | string[]; + node_id?: string | string[]; + timeout?: string; +} + +export interface Ping extends Generic { +} + +export interface PutScript extends Generic { + id: string; + context?: string; + timeout?: string; + master_timeout?: string; + body: any; +} + +export interface RankEval extends Generic { + index?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + body: any; +} + +export interface Reindex extends Generic { + refresh?: boolean; + timeout?: string; + wait_for_active_shards?: string; + wait_for_completion?: boolean; + requests_per_second?: number; + slices?: number; + body: any; +} + +export interface ReindexRethrottle extends Generic { + task_id: string; + requests_per_second: number; +} + +export interface RenderSearchTemplate extends Generic { + id?: string; + body?: any; +} + +export interface ScriptsPainlessExecute extends Generic { + body?: any; +} + +export interface Scroll extends Generic { + scroll_id?: string; + scroll?: string; + body?: any; +} + +export interface Search extends Generic { + index?: string | string[]; + type?: string | string[]; + analyzer?: string; + analyze_wildcard?: boolean; + default_operator?: 'AND' | 'OR'; + df?: string; + explain?: boolean; + stored_fields?: string | string[]; + docvalue_fields?: string | string[]; + from?: number; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + lenient?: boolean; + preference?: string; + q?: string; + routing?: string | string[]; + scroll?: string; + search_type?: 'query_then_fetch' | 'dfs_query_then_fetch'; + size?: number; + sort?: string | string[]; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + terminate_after?: number; + stats?: string | string[]; + suggest_field?: string; + suggest_mode?: 'missing' | 'popular' | 'always'; + suggest_size?: number; + suggest_text?: string; + timeout?: string; + track_scores?: boolean; + track_total_hits?: boolean; + allow_partial_search_results?: boolean; + typed_keys?: boolean; + version?: boolean; + request_cache?: boolean; + batched_reduce_size?: number; + max_concurrent_shard_requests?: number; + pre_filter_shard_size?: number; + body?: any; +} + +export interface SearchShards extends Generic { + index?: string | string[]; + preference?: string; + routing?: string; + local?: boolean; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; +} + +export interface SearchTemplate extends Generic { + index?: string | string[]; + type?: string | string[]; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + preference?: string; + routing?: string | string[]; + scroll?: string; + search_type?: 'query_then_fetch' | 'query_and_fetch' | 'dfs_query_then_fetch' | 'dfs_query_and_fetch'; + explain?: boolean; + profile?: boolean; + typed_keys?: boolean; + body: any; +} + +export interface SnapshotCreate extends Generic { + repository: string; + snapshot: string; + master_timeout?: string; + wait_for_completion?: boolean; + body?: any; +} + +export interface SnapshotCreateRepository extends Generic { + repository: string; + master_timeout?: string; + timeout?: string; + verify?: boolean; + body: any; +} + +export interface SnapshotDelete extends Generic { + repository: string; + snapshot: string; + master_timeout?: string; +} + +export interface SnapshotDeleteRepository extends Generic { + repository: string | string[]; + master_timeout?: string; + timeout?: string; +} + +export interface SnapshotGet extends Generic { + repository: string; + snapshot: string | string[]; + master_timeout?: string; + ignore_unavailable?: boolean; + verbose?: boolean; +} + +export interface SnapshotGetRepository extends Generic { + repository?: string | string[]; + master_timeout?: string; + local?: boolean; +} + +export interface SnapshotRestore extends Generic { + repository: string; + snapshot: string; + master_timeout?: string; + wait_for_completion?: boolean; + body?: any; +} + +export interface SnapshotStatus extends Generic { + repository?: string; + snapshot?: string | string[]; + master_timeout?: string; + ignore_unavailable?: boolean; +} + +export interface SnapshotVerifyRepository extends Generic { + repository: string; + master_timeout?: string; + timeout?: string; +} + +export interface TasksCancel extends Generic { + task_id?: string; + nodes?: string | string[]; + actions?: string | string[]; + parent_task_id?: string; +} + +export interface TasksGet extends Generic { + task_id: string; + wait_for_completion?: boolean; + timeout?: string; +} + +export interface TasksList extends Generic { + nodes?: string | string[]; + actions?: string | string[]; + detailed?: boolean; + parent_task_id?: string; + wait_for_completion?: boolean; + group_by?: 'nodes' | 'parents' | 'none'; + timeout?: string; +} + +export interface Termvectors extends Generic { + index: string; + type: string; + id?: string; + term_statistics?: boolean; + field_statistics?: boolean; + fields?: string | string[]; + offsets?: boolean; + positions?: boolean; + payloads?: boolean; + preference?: string; + routing?: string; + parent?: string; + realtime?: boolean; + version?: number; + version_type?: 'internal' | 'external' | 'external_gte' | 'force'; + body?: any; +} + +export interface Update extends Generic { + id: string; + index: string; + type: string; + wait_for_active_shards?: string; + fields?: string | string[]; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + lang?: string; + parent?: string; + refresh?: 'true' | 'false' | 'wait_for'; + retry_on_conflict?: number; + routing?: string; + timeout?: string; + version?: number; + version_type?: 'internal' | 'force'; + body: any; +} + +export interface UpdateByQuery extends Generic { + index: string | string[]; + type?: string | string[]; + analyzer?: string; + analyze_wildcard?: boolean; + default_operator?: 'AND' | 'OR'; + df?: string; + from?: number; + ignore_unavailable?: boolean; + allow_no_indices?: boolean; + conflicts?: 'abort' | 'proceed'; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + lenient?: boolean; + pipeline?: string; + preference?: string; + q?: string; + routing?: string | string[]; + scroll?: string; + search_type?: 'query_then_fetch' | 'dfs_query_then_fetch'; + search_timeout?: string; + size?: number; + sort?: string | string[]; + _source?: string | string[]; + _source_exclude?: string | string[]; + _source_include?: string | string[]; + terminate_after?: number; + stats?: string | string[]; + version?: boolean; + version_type?: boolean; + request_cache?: boolean; + refresh?: boolean; + timeout?: string; + wait_for_active_shards?: string; + scroll_size?: number; + wait_for_completion?: boolean; + requests_per_second?: number; + slices?: number; + body?: any; +} + +export interface UpdateByQueryRethrottle extends Generic { + task_id: string; + requests_per_second: number; +} + +export interface CcrDeleteAutoFollowPattern extends Generic { + name: string; +} + +export interface CcrFollow extends Generic { + index: string; + body: any; +} + +export interface CcrFollowStats extends Generic { + index?: string | string[]; +} + +export interface CcrGetAutoFollowPattern extends Generic { + name?: string; +} + +export interface CcrPauseFollow extends Generic { + index: string; +} + +export interface CcrPutAutoFollowPattern extends Generic { + name: string; + body: any; +} + +export interface CcrResumeFollow extends Generic { + index: string; + body: any; +} + +export interface CcrStats extends Generic { +} + +export interface CcrUnfollow extends Generic { + index: string; +} + +export interface XpackGraphExplore extends Generic { + index?: string | string[]; + type?: string | string[]; + routing?: string; + timeout?: string; + body?: any; +} + +export interface XpackInfo extends Generic { + categories?: string | string[]; +} + +export interface XpackLicenseDelete extends Generic { +} + +export interface XpackLicenseGet extends Generic { + local?: boolean; +} + +export interface XpackLicenseGetBasicStatus extends Generic { +} + +export interface XpackLicenseGetTrialStatus extends Generic { +} + +export interface XpackLicensePost extends Generic { + acknowledge?: boolean; + body?: any; +} + +export interface XpackLicensePostStartBasic extends Generic { + acknowledge?: boolean; +} + +export interface XpackLicensePostStartTrial extends Generic { + type?: string; + acknowledge?: boolean; +} + +export interface XpackMigrationDeprecations extends Generic { + index?: string; +} + +export interface XpackMigrationGetAssistance extends Generic { + index?: string | string[]; + allow_no_indices?: boolean; + expand_wildcards?: 'open' | 'closed' | 'none' | 'all'; + ignore_unavailable?: boolean; +} + +export interface XpackMigrationUpgrade extends Generic { + index: string; + wait_for_completion?: boolean; +} + +export interface XpackMlCloseJob extends Generic { + job_id: string; + allow_no_jobs?: boolean; + force?: boolean; + timeout?: string; +} + +export interface XpackMlDeleteCalendar extends Generic { + calendar_id: string; +} + +export interface XpackMlDeleteCalendarEvent extends Generic { + calendar_id: string; + event_id: string; +} + +export interface XpackMlDeleteCalendarJob extends Generic { + calendar_id: string; + job_id: string; +} + +export interface XpackMlDeleteDatafeed extends Generic { + datafeed_id: string; + force?: boolean; +} + +export interface XpackMlDeleteExpiredData extends Generic { +} + +export interface XpackMlDeleteFilter extends Generic { + filter_id: string; +} + +export interface XpackMlDeleteForecast extends Generic { + job_id: string; + forecast_id?: string; + allow_no_forecasts?: boolean; + timeout?: string; +} + +export interface XpackMlDeleteJob extends Generic { + job_id: string; + force?: boolean; + wait_for_completion?: boolean; +} + +export interface XpackMlDeleteModelSnapshot extends Generic { + job_id: string; + snapshot_id: string; +} + +export interface XpackMlFindFileStructure extends Generic { + lines_to_sample?: number; + timeout?: string; + charset?: string; + format?: 'ndjson' | 'xml' | 'delimited' | 'semi_structured_text'; + has_header_row?: boolean; + column_names?: string | string[]; + delimiter?: string; + quote?: string; + should_trim_fields?: boolean; + grok_pattern?: string; + timestamp_field?: string; + timestamp_format?: string; + explain?: boolean; + body: any; +} + +export interface XpackMlFlushJob extends Generic { + job_id: string; + calc_interim?: boolean; + start?: string; + end?: string; + advance_time?: string; + skip_time?: string; + body?: any; +} + +export interface XpackMlForecast extends Generic { + job_id: string; + duration?: string; + expires_in?: string; +} + +export interface XpackMlGetBuckets extends Generic { + job_id: string; + timestamp?: string; + expand?: boolean; + exclude_interim?: boolean; + from?: number; + size?: number; + start?: string; + end?: string; + anomaly_score?: number; + sort?: string; + desc?: boolean; + body?: any; +} + +export interface XpackMlGetCalendarEvents extends Generic { + calendar_id: string; + job_id?: string; + start?: string; + end?: string; + from?: number; + size?: number; +} + +export interface XpackMlGetCalendars extends Generic { + calendar_id?: string; + from?: number; + size?: number; +} + +export interface XpackMlGetCategories extends Generic { + job_id: string; + category_id?: number; + from?: number; + size?: number; + body?: any; +} + +export interface XpackMlGetDatafeedStats extends Generic { + datafeed_id?: string; + allow_no_datafeeds?: boolean; +} + +export interface XpackMlGetDatafeeds extends Generic { + datafeed_id?: string; + allow_no_datafeeds?: boolean; +} + +export interface XpackMlGetFilters extends Generic { + filter_id?: string; + from?: number; + size?: number; +} + +export interface XpackMlGetInfluencers extends Generic { + job_id: string; + exclude_interim?: boolean; + from?: number; + size?: number; + start?: string; + end?: string; + influencer_score?: number; + sort?: string; + desc?: boolean; + body?: any; +} + +export interface XpackMlGetJobStats extends Generic { + job_id?: string; + allow_no_jobs?: boolean; +} + +export interface XpackMlGetJobs extends Generic { + job_id?: string; + allow_no_jobs?: boolean; +} + +export interface XpackMlGetModelSnapshots extends Generic { + job_id: string; + snapshot_id?: string; + from?: number; + size?: number; + start?: string; + end?: string; + sort?: string; + desc?: boolean; + body?: any; +} + +export interface XpackMlGetOverallBuckets extends Generic { + job_id: string; + top_n?: number; + bucket_span?: string; + overall_score?: number; + exclude_interim?: boolean; + start?: string; + end?: string; + allow_no_jobs?: boolean; + body?: any; +} + +export interface XpackMlGetRecords extends Generic { + job_id: string; + exclude_interim?: boolean; + from?: number; + size?: number; + start?: string; + end?: string; + record_score?: number; + sort?: string; + desc?: boolean; + body?: any; +} + +export interface XpackMlInfo extends Generic { +} + +export interface XpackMlOpenJob extends Generic { + job_id: string; + ignore_downtime?: boolean; + timeout?: string; +} + +export interface XpackMlPostCalendarEvents extends Generic { + calendar_id: string; + body: any; +} + +export interface XpackMlPostData extends Generic { + job_id: string; + reset_start?: string; + reset_end?: string; + body: any; +} + +export interface XpackMlPreviewDatafeed extends Generic { + datafeed_id: string; +} + +export interface XpackMlPutCalendar extends Generic { + calendar_id: string; + body?: any; +} + +export interface XpackMlPutCalendarJob extends Generic { + calendar_id: string; + job_id: string; +} + +export interface XpackMlPutDatafeed extends Generic { + datafeed_id: string; + body: any; +} + +export interface XpackMlPutFilter extends Generic { + filter_id: string; + body: any; +} + +export interface XpackMlPutJob extends Generic { + job_id: string; + body: any; +} + +export interface XpackMlRevertModelSnapshot extends Generic { + job_id: string; + snapshot_id: string; + delete_intervening_results?: boolean; + body?: any; +} + +export interface XpackMlStartDatafeed extends Generic { + datafeed_id: string; + start?: string; + end?: string; + timeout?: string; + body?: any; +} + +export interface XpackMlStopDatafeed extends Generic { + datafeed_id: string; + allow_no_datafeeds?: boolean; + force?: boolean; + timeout?: string; +} + +export interface XpackMlUpdateDatafeed extends Generic { + datafeed_id: string; + body: any; +} + +export interface XpackMlUpdateFilter extends Generic { + filter_id: string; + body: any; +} + +export interface XpackMlUpdateJob extends Generic { + job_id: string; + body: any; +} + +export interface XpackMlUpdateModelSnapshot extends Generic { + job_id: string; + snapshot_id: string; + body: any; +} + +export interface XpackMlValidate extends Generic { + body: any; +} + +export interface XpackMlValidateDetector extends Generic { + body: any; +} + +export interface XpackMonitoringBulk extends Generic { + type?: string; + system_id?: string; + system_api_version?: string; + interval?: string; + body: any; +} + +export interface XpackRollupDeleteJob extends Generic { + id: string; +} + +export interface XpackRollupGetJobs extends Generic { + id?: string; +} + +export interface XpackRollupGetRollupCaps extends Generic { + id?: string; +} + +export interface XpackRollupGetRollupIndexCaps extends Generic { + index: string; +} + +export interface XpackRollupPutJob extends Generic { + id: string; + body: any; +} + +export interface XpackRollupRollupSearch extends Generic { + index: string; + type?: string; + body: any; +} + +export interface XpackRollupStartJob extends Generic { + id: string; +} + +export interface XpackRollupStopJob extends Generic { + id: string; +} + +export interface XpackSecurityAuthenticate extends Generic { +} + +export interface XpackSecurityChangePassword extends Generic { + username?: string; + refresh?: 'true' | 'false' | 'wait_for'; + body: any; +} + +export interface XpackSecurityClearCachedRealms extends Generic { + realms: string | string[]; + usernames?: string | string[]; +} + +export interface XpackSecurityClearCachedRoles extends Generic { + name: string | string[]; +} + +export interface XpackSecurityDeletePrivileges extends Generic { + application: string; + name: string; + refresh?: 'true' | 'false' | 'wait_for'; +} + +export interface XpackSecurityDeleteRole extends Generic { + name: string; + refresh?: 'true' | 'false' | 'wait_for'; +} + +export interface XpackSecurityDeleteRoleMapping extends Generic { + name: string; + refresh?: 'true' | 'false' | 'wait_for'; +} + +export interface XpackSecurityDeleteUser extends Generic { + username: string; + refresh?: 'true' | 'false' | 'wait_for'; +} + +export interface XpackSecurityDisableUser extends Generic { + username?: string; + refresh?: 'true' | 'false' | 'wait_for'; +} + +export interface XpackSecurityEnableUser extends Generic { + username?: string; + refresh?: 'true' | 'false' | 'wait_for'; +} + +export interface XpackSecurityGetPrivileges extends Generic { + application?: string; + name?: string; +} + +export interface XpackSecurityGetRole extends Generic { + name?: string; +} + +export interface XpackSecurityGetRoleMapping extends Generic { + name?: string; +} + +export interface XpackSecurityGetToken extends Generic { + body: any; +} + +export interface XpackSecurityGetUser extends Generic { + username?: string | string[]; +} + +export interface XpackSecurityGetUserPrivileges extends Generic { +} + +export interface XpackSecurityHasPrivileges extends Generic { + user?: string; + body: any; +} + +export interface XpackSecurityInvalidateToken extends Generic { + body: any; +} + +export interface XpackSecurityPutPrivileges extends Generic { + refresh?: 'true' | 'false' | 'wait_for'; + body: any; +} + +export interface XpackSecurityPutRole extends Generic { + name: string; + refresh?: 'true' | 'false' | 'wait_for'; + body: any; +} + +export interface XpackSecurityPutRoleMapping extends Generic { + name: string; + refresh?: 'true' | 'false' | 'wait_for'; + body: any; +} + +export interface XpackSecurityPutUser extends Generic { + username: string; + refresh?: 'true' | 'false' | 'wait_for'; + body: any; +} + +export interface XpackSqlClearCursor extends Generic { + body: any; +} + +export interface XpackSqlQuery extends Generic { + format?: string; + body: any; +} + +export interface XpackSqlTranslate extends Generic { + body: any; +} + +export interface XpackSslCertificates extends Generic { +} + +export interface XpackUsage extends Generic { + master_timeout?: string; +} + +export interface XpackWatcherAckWatch extends Generic { + watch_id: string; + action_id?: string | string[]; + master_timeout?: string; +} + +export interface XpackWatcherActivateWatch extends Generic { + watch_id: string; + master_timeout?: string; +} + +export interface XpackWatcherDeactivateWatch extends Generic { + watch_id: string; + master_timeout?: string; +} + +export interface XpackWatcherDeleteWatch extends Generic { + id: string; + master_timeout?: string; +} + +export interface XpackWatcherExecuteWatch extends Generic { + id?: string; + debug?: boolean; + body?: any; +} + +export interface XpackWatcherGetWatch extends Generic { + id: string; +} + +export interface XpackWatcherPutWatch extends Generic { + id: string; + master_timeout?: string; + active?: boolean; + version?: number; + body?: any; +} + +export interface XpackWatcherRestart extends Generic { +} + +export interface XpackWatcherStart extends Generic { +} + +export interface XpackWatcherStats extends Generic { + metric?: '_all' | 'queued_watches' | 'pending_watches'; + emit_stacktraces?: boolean; +} + +export interface XpackWatcherStop extends Generic { +} diff --git a/index.d.ts b/index.d.ts index 2455073e5..76c140c35 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,16 +6,17 @@ import Transport, { ApiResponse, EventMeta, SniffMeta, RequestOptions } from './ import Connection, { AgentOptions } from './lib/Connection'; import ConnectionPool, { nodeSelectorFn, nodeFilterFn, ResurrectMeta } from './lib/ConnectionPool'; import Serializer from './lib/Serializer'; +import * as RequestParams from './api/requestParams' declare type anyObject = { [key: string]: any; }; declare type callbackFn = (err: Error | null, result: ApiResponse) => void; -interface ApiMethod { +interface ApiMethod { (callback?: callbackFn): any; - (params: anyObject, callback?: callbackFn): any; - (params: anyObject, options: RequestOptions, callback?: callbackFn): any; + (params: T, callback?: callbackFn): any; + (params: T, options: RequestOptions, callback?: callbackFn): any; } interface ClientOptions { @@ -45,428 +46,428 @@ declare class Client extends EventEmitter { connectionPool: ConnectionPool; transport: Transport; serializer: Serializer - bulk: ApiMethod - cat: { - aliases: ApiMethod - allocation: ApiMethod - count: ApiMethod - fielddata: ApiMethod - health: ApiMethod - help: ApiMethod - indices: ApiMethod - master: ApiMethod - nodeattrs: ApiMethod - nodes: ApiMethod - pending_tasks: ApiMethod - pendingTasks: ApiMethod - plugins: ApiMethod - recovery: ApiMethod - repositories: ApiMethod - segments: ApiMethod - shards: ApiMethod - snapshots: ApiMethod - tasks: ApiMethod - templates: ApiMethod - thread_pool: ApiMethod - threadPool: ApiMethod - } - ccr: { - delete_auto_follow_pattern: ApiMethod - deleteAutoFollowPattern: ApiMethod - follow: ApiMethod - follow_stats: ApiMethod - followStats: ApiMethod - get_auto_follow_pattern: ApiMethod - getAutoFollowPattern: ApiMethod - pause_follow: ApiMethod - pauseFollow: ApiMethod - put_auto_follow_pattern: ApiMethod - putAutoFollowPattern: ApiMethod - resume_follow: ApiMethod - resumeFollow: ApiMethod - stats: ApiMethod - unfollow: ApiMethod - } - clear_scroll: ApiMethod - clearScroll: ApiMethod - cluster: { - allocation_explain: ApiMethod - allocationExplain: ApiMethod - get_settings: ApiMethod - getSettings: ApiMethod - health: ApiMethod - pending_tasks: ApiMethod - pendingTasks: ApiMethod - put_settings: ApiMethod - putSettings: ApiMethod - remote_info: ApiMethod - remoteInfo: ApiMethod - reroute: ApiMethod - state: ApiMethod - stats: ApiMethod - } - count: ApiMethod - create: ApiMethod - delete: ApiMethod - delete_by_query: ApiMethod - deleteByQuery: ApiMethod - delete_by_query_rethrottle: ApiMethod - deleteByQueryRethrottle: ApiMethod - delete_script: ApiMethod - deleteScript: ApiMethod - exists: ApiMethod - exists_source: ApiMethod - existsSource: ApiMethod - explain: ApiMethod - field_caps: ApiMethod - fieldCaps: ApiMethod - get: ApiMethod - get_script: ApiMethod - getScript: ApiMethod - get_source: ApiMethod - getSource: ApiMethod - index: ApiMethod - indices: { - analyze: ApiMethod - clear_cache: ApiMethod - clearCache: ApiMethod - close: ApiMethod - create: ApiMethod - delete: ApiMethod - delete_alias: ApiMethod - deleteAlias: ApiMethod - delete_template: ApiMethod - deleteTemplate: ApiMethod - exists: ApiMethod - exists_alias: ApiMethod - existsAlias: ApiMethod - exists_template: ApiMethod - existsTemplate: ApiMethod - exists_type: ApiMethod - existsType: ApiMethod - flush: ApiMethod - flush_synced: ApiMethod - flushSynced: ApiMethod - forcemerge: ApiMethod - get: ApiMethod - get_alias: ApiMethod - getAlias: ApiMethod - get_field_mapping: ApiMethod - getFieldMapping: ApiMethod - get_mapping: ApiMethod - getMapping: ApiMethod - get_settings: ApiMethod - getSettings: ApiMethod - get_template: ApiMethod - getTemplate: ApiMethod - get_upgrade: ApiMethod - getUpgrade: ApiMethod - open: ApiMethod - put_alias: ApiMethod - putAlias: ApiMethod - put_mapping: ApiMethod - putMapping: ApiMethod - put_settings: ApiMethod - putSettings: ApiMethod - put_template: ApiMethod - putTemplate: ApiMethod - recovery: ApiMethod - refresh: ApiMethod - rollover: ApiMethod - segments: ApiMethod - shard_stores: ApiMethod - shardStores: ApiMethod - shrink: ApiMethod - split: ApiMethod - stats: ApiMethod - update_aliases: ApiMethod - updateAliases: ApiMethod - upgrade: ApiMethod - validate_query: ApiMethod - validateQuery: ApiMethod - } - info: ApiMethod - ingest: { - delete_pipeline: ApiMethod - deletePipeline: ApiMethod - get_pipeline: ApiMethod - getPipeline: ApiMethod - processor_grok: ApiMethod - processorGrok: ApiMethod - put_pipeline: ApiMethod - putPipeline: ApiMethod - simulate: ApiMethod - } - mget: ApiMethod - msearch: ApiMethod - msearch_template: ApiMethod - msearchTemplate: ApiMethod - mtermvectors: ApiMethod - nodes: { - hot_threads: ApiMethod - hotThreads: ApiMethod - info: ApiMethod - reload_secure_settings: ApiMethod - reloadSecureSettings: ApiMethod - stats: ApiMethod - usage: ApiMethod - } - ping: ApiMethod - put_script: ApiMethod - putScript: ApiMethod - rank_eval: ApiMethod - rankEval: ApiMethod - reindex: ApiMethod - reindex_rethrottle: ApiMethod - reindexRethrottle: ApiMethod - render_search_template: ApiMethod - renderSearchTemplate: ApiMethod - scripts_painless_execute: ApiMethod - scriptsPainlessExecute: ApiMethod - scroll: ApiMethod - search: ApiMethod - search_shards: ApiMethod - searchShards: ApiMethod - search_template: ApiMethod - searchTemplate: ApiMethod - snapshot: { - create: ApiMethod - create_repository: ApiMethod - createRepository: ApiMethod - delete: ApiMethod - delete_repository: ApiMethod - deleteRepository: ApiMethod - get: ApiMethod - get_repository: ApiMethod - getRepository: ApiMethod - restore: ApiMethod - status: ApiMethod - verify_repository: ApiMethod - verifyRepository: ApiMethod - } - tasks: { - cancel: ApiMethod - get: ApiMethod - list: ApiMethod - } - termvectors: ApiMethod - update: ApiMethod - update_by_query: ApiMethod - updateByQuery: ApiMethod - update_by_query_rethrottle: ApiMethod - updateByQueryRethrottle: ApiMethod - xpack: { - graph: { - explore: ApiMethod - } - info: ApiMethod - license: { - delete: ApiMethod - get: ApiMethod - get_basic_status: ApiMethod - getBasicStatus: ApiMethod - get_trial_status: ApiMethod - getTrialStatus: ApiMethod - post: ApiMethod - post_start_basic: ApiMethod - postStartBasic: ApiMethod - post_start_trial: ApiMethod - postStartTrial: ApiMethod - } - migration: { - deprecations: ApiMethod - get_assistance: ApiMethod - getAssistance: ApiMethod - upgrade: ApiMethod - } - ml: { - close_job: ApiMethod - closeJob: ApiMethod - delete_calendar: ApiMethod - deleteCalendar: ApiMethod - delete_calendar_event: ApiMethod - deleteCalendarEvent: ApiMethod - delete_calendar_job: ApiMethod - deleteCalendarJob: ApiMethod - delete_datafeed: ApiMethod - deleteDatafeed: ApiMethod - delete_expired_data: ApiMethod - deleteExpiredData: ApiMethod - delete_filter: ApiMethod - deleteFilter: ApiMethod - delete_forecast: ApiMethod - deleteForecast: ApiMethod - delete_job: ApiMethod - deleteJob: ApiMethod - delete_model_snapshot: ApiMethod - deleteModelSnapshot: ApiMethod - find_file_structure: ApiMethod - findFileStructure: ApiMethod - flush_job: ApiMethod - flushJob: ApiMethod - forecast: ApiMethod - get_buckets: ApiMethod - getBuckets: ApiMethod - get_calendar_events: ApiMethod - getCalendarEvents: ApiMethod - get_calendars: ApiMethod - getCalendars: ApiMethod - get_categories: ApiMethod - getCategories: ApiMethod - get_datafeed_stats: ApiMethod - getDatafeedStats: ApiMethod - get_datafeeds: ApiMethod - getDatafeeds: ApiMethod - get_filters: ApiMethod - getFilters: ApiMethod - get_influencers: ApiMethod - getInfluencers: ApiMethod - get_job_stats: ApiMethod - getJobStats: ApiMethod - get_jobs: ApiMethod - getJobs: ApiMethod - get_model_snapshots: ApiMethod - getModelSnapshots: ApiMethod - get_overall_buckets: ApiMethod - getOverallBuckets: ApiMethod - get_records: ApiMethod - getRecords: ApiMethod - info: ApiMethod - open_job: ApiMethod - openJob: ApiMethod - post_calendar_events: ApiMethod - postCalendarEvents: ApiMethod - post_data: ApiMethod - postData: ApiMethod - preview_datafeed: ApiMethod - previewDatafeed: ApiMethod - put_calendar: ApiMethod - putCalendar: ApiMethod - put_calendar_job: ApiMethod - putCalendarJob: ApiMethod - put_datafeed: ApiMethod - putDatafeed: ApiMethod - put_filter: ApiMethod - putFilter: ApiMethod - put_job: ApiMethod - putJob: ApiMethod - revert_model_snapshot: ApiMethod - revertModelSnapshot: ApiMethod - start_datafeed: ApiMethod - startDatafeed: ApiMethod - stop_datafeed: ApiMethod - stopDatafeed: ApiMethod - update_datafeed: ApiMethod - updateDatafeed: ApiMethod - update_filter: ApiMethod - updateFilter: ApiMethod - update_job: ApiMethod - updateJob: ApiMethod - update_model_snapshot: ApiMethod - updateModelSnapshot: ApiMethod - validate: ApiMethod - validate_detector: ApiMethod - validateDetector: ApiMethod - } - monitoring: { - bulk: ApiMethod - } - rollup: { - delete_job: ApiMethod - deleteJob: ApiMethod - get_jobs: ApiMethod - getJobs: ApiMethod - get_rollup_caps: ApiMethod - getRollupCaps: ApiMethod - get_rollup_index_caps: ApiMethod - getRollupIndexCaps: ApiMethod - put_job: ApiMethod - putJob: ApiMethod - rollup_search: ApiMethod - rollupSearch: ApiMethod - start_job: ApiMethod - startJob: ApiMethod - stop_job: ApiMethod - stopJob: ApiMethod - } - security: { - authenticate: ApiMethod - change_password: ApiMethod - changePassword: ApiMethod - clear_cached_realms: ApiMethod - clearCachedRealms: ApiMethod - clear_cached_roles: ApiMethod - clearCachedRoles: ApiMethod - delete_privileges: ApiMethod - deletePrivileges: ApiMethod - delete_role: ApiMethod - deleteRole: ApiMethod - delete_role_mapping: ApiMethod - deleteRoleMapping: ApiMethod - delete_user: ApiMethod - deleteUser: ApiMethod - disable_user: ApiMethod - disableUser: ApiMethod - enable_user: ApiMethod - enableUser: ApiMethod - get_privileges: ApiMethod - getPrivileges: ApiMethod - get_role: ApiMethod - getRole: ApiMethod - get_role_mapping: ApiMethod - getRoleMapping: ApiMethod - get_token: ApiMethod - getToken: ApiMethod - get_user: ApiMethod - getUser: ApiMethod - get_user_privileges: ApiMethod - getUserPrivileges: ApiMethod - has_privileges: ApiMethod - hasPrivileges: ApiMethod - invalidate_token: ApiMethod - invalidateToken: ApiMethod - put_privileges: ApiMethod - putPrivileges: ApiMethod - put_role: ApiMethod - putRole: ApiMethod - put_role_mapping: ApiMethod - putRoleMapping: ApiMethod - put_user: ApiMethod - putUser: ApiMethod - } - sql: { - clear_cursor: ApiMethod - clearCursor: ApiMethod - query: ApiMethod - translate: ApiMethod - } - ssl: { - certificates: ApiMethod - } - usage: ApiMethod - watcher: { - ack_watch: ApiMethod - ackWatch: ApiMethod - activate_watch: ApiMethod - activateWatch: ApiMethod - deactivate_watch: ApiMethod - deactivateWatch: ApiMethod - delete_watch: ApiMethod - deleteWatch: ApiMethod - execute_watch: ApiMethod - executeWatch: ApiMethod - get_watch: ApiMethod - getWatch: ApiMethod - put_watch: ApiMethod - putWatch: ApiMethod - restart: ApiMethod - start: ApiMethod - stats: ApiMethod - stop: ApiMethod - } - } constructor(opts?: ClientOptions); close(callback?: Function): Promise | void; + bulk: ApiMethod + cat: { + aliases: ApiMethod + allocation: ApiMethod + count: ApiMethod + fielddata: ApiMethod + health: ApiMethod + help: ApiMethod + indices: ApiMethod + master: ApiMethod + nodeattrs: ApiMethod + nodes: ApiMethod + pending_tasks: ApiMethod + pendingTasks: ApiMethod + plugins: ApiMethod + recovery: ApiMethod + repositories: ApiMethod + segments: ApiMethod + shards: ApiMethod + snapshots: ApiMethod + tasks: ApiMethod + templates: ApiMethod + thread_pool: ApiMethod + threadPool: ApiMethod + } + ccr: { + delete_auto_follow_pattern: ApiMethod + deleteAutoFollowPattern: ApiMethod + follow: ApiMethod + follow_stats: ApiMethod + followStats: ApiMethod + get_auto_follow_pattern: ApiMethod + getAutoFollowPattern: ApiMethod + pause_follow: ApiMethod + pauseFollow: ApiMethod + put_auto_follow_pattern: ApiMethod + putAutoFollowPattern: ApiMethod + resume_follow: ApiMethod + resumeFollow: ApiMethod + stats: ApiMethod + unfollow: ApiMethod + } + clear_scroll: ApiMethod + clearScroll: ApiMethod + cluster: { + allocation_explain: ApiMethod + allocationExplain: ApiMethod + get_settings: ApiMethod + getSettings: ApiMethod + health: ApiMethod + pending_tasks: ApiMethod + pendingTasks: ApiMethod + put_settings: ApiMethod + putSettings: ApiMethod + remote_info: ApiMethod + remoteInfo: ApiMethod + reroute: ApiMethod + state: ApiMethod + stats: ApiMethod + } + count: ApiMethod + create: ApiMethod + delete: ApiMethod + delete_by_query: ApiMethod + deleteByQuery: ApiMethod + delete_by_query_rethrottle: ApiMethod + deleteByQueryRethrottle: ApiMethod + delete_script: ApiMethod + deleteScript: ApiMethod + exists: ApiMethod + exists_source: ApiMethod + existsSource: ApiMethod + explain: ApiMethod + field_caps: ApiMethod + fieldCaps: ApiMethod + get: ApiMethod + get_script: ApiMethod + getScript: ApiMethod + get_source: ApiMethod + getSource: ApiMethod + index: ApiMethod + indices: { + analyze: ApiMethod + clear_cache: ApiMethod + clearCache: ApiMethod + close: ApiMethod + create: ApiMethod + delete: ApiMethod + delete_alias: ApiMethod + deleteAlias: ApiMethod + delete_template: ApiMethod + deleteTemplate: ApiMethod + exists: ApiMethod + exists_alias: ApiMethod + existsAlias: ApiMethod + exists_template: ApiMethod + existsTemplate: ApiMethod + exists_type: ApiMethod + existsType: ApiMethod + flush: ApiMethod + flush_synced: ApiMethod + flushSynced: ApiMethod + forcemerge: ApiMethod + get: ApiMethod + get_alias: ApiMethod + getAlias: ApiMethod + get_field_mapping: ApiMethod + getFieldMapping: ApiMethod + get_mapping: ApiMethod + getMapping: ApiMethod + get_settings: ApiMethod + getSettings: ApiMethod + get_template: ApiMethod + getTemplate: ApiMethod + get_upgrade: ApiMethod + getUpgrade: ApiMethod + open: ApiMethod + put_alias: ApiMethod + putAlias: ApiMethod + put_mapping: ApiMethod + putMapping: ApiMethod + put_settings: ApiMethod + putSettings: ApiMethod + put_template: ApiMethod + putTemplate: ApiMethod + recovery: ApiMethod + refresh: ApiMethod + rollover: ApiMethod + segments: ApiMethod + shard_stores: ApiMethod + shardStores: ApiMethod + shrink: ApiMethod + split: ApiMethod + stats: ApiMethod + update_aliases: ApiMethod + updateAliases: ApiMethod + upgrade: ApiMethod + validate_query: ApiMethod + validateQuery: ApiMethod + } + info: ApiMethod + ingest: { + delete_pipeline: ApiMethod + deletePipeline: ApiMethod + get_pipeline: ApiMethod + getPipeline: ApiMethod + processor_grok: ApiMethod + processorGrok: ApiMethod + put_pipeline: ApiMethod + putPipeline: ApiMethod + simulate: ApiMethod + } + mget: ApiMethod + msearch: ApiMethod + msearch_template: ApiMethod + msearchTemplate: ApiMethod + mtermvectors: ApiMethod + nodes: { + hot_threads: ApiMethod + hotThreads: ApiMethod + info: ApiMethod + reload_secure_settings: ApiMethod + reloadSecureSettings: ApiMethod + stats: ApiMethod + usage: ApiMethod + } + ping: ApiMethod + put_script: ApiMethod + putScript: ApiMethod + rank_eval: ApiMethod + rankEval: ApiMethod + reindex: ApiMethod + reindex_rethrottle: ApiMethod + reindexRethrottle: ApiMethod + render_search_template: ApiMethod + renderSearchTemplate: ApiMethod + scripts_painless_execute: ApiMethod + scriptsPainlessExecute: ApiMethod + scroll: ApiMethod + search: ApiMethod + search_shards: ApiMethod + searchShards: ApiMethod + search_template: ApiMethod + searchTemplate: ApiMethod + snapshot: { + create: ApiMethod + create_repository: ApiMethod + createRepository: ApiMethod + delete: ApiMethod + delete_repository: ApiMethod + deleteRepository: ApiMethod + get: ApiMethod + get_repository: ApiMethod + getRepository: ApiMethod + restore: ApiMethod + status: ApiMethod + verify_repository: ApiMethod + verifyRepository: ApiMethod + } + tasks: { + cancel: ApiMethod + get: ApiMethod + list: ApiMethod + } + termvectors: ApiMethod + update: ApiMethod + update_by_query: ApiMethod + updateByQuery: ApiMethod + update_by_query_rethrottle: ApiMethod + updateByQueryRethrottle: ApiMethod + xpack: { + graph: { + explore: ApiMethod + } + info: ApiMethod + license: { + delete: ApiMethod + get: ApiMethod + get_basic_status: ApiMethod + getBasicStatus: ApiMethod + get_trial_status: ApiMethod + getTrialStatus: ApiMethod + post: ApiMethod + post_start_basic: ApiMethod + postStartBasic: ApiMethod + post_start_trial: ApiMethod + postStartTrial: ApiMethod + } + migration: { + deprecations: ApiMethod + get_assistance: ApiMethod + getAssistance: ApiMethod + upgrade: ApiMethod + } + ml: { + close_job: ApiMethod + closeJob: ApiMethod + delete_calendar: ApiMethod + deleteCalendar: ApiMethod + delete_calendar_event: ApiMethod + deleteCalendarEvent: ApiMethod + delete_calendar_job: ApiMethod + deleteCalendarJob: ApiMethod + delete_datafeed: ApiMethod + deleteDatafeed: ApiMethod + delete_expired_data: ApiMethod + deleteExpiredData: ApiMethod + delete_filter: ApiMethod + deleteFilter: ApiMethod + delete_forecast: ApiMethod + deleteForecast: ApiMethod + delete_job: ApiMethod + deleteJob: ApiMethod + delete_model_snapshot: ApiMethod + deleteModelSnapshot: ApiMethod + find_file_structure: ApiMethod + findFileStructure: ApiMethod + flush_job: ApiMethod + flushJob: ApiMethod + forecast: ApiMethod + get_buckets: ApiMethod + getBuckets: ApiMethod + get_calendar_events: ApiMethod + getCalendarEvents: ApiMethod + get_calendars: ApiMethod + getCalendars: ApiMethod + get_categories: ApiMethod + getCategories: ApiMethod + get_datafeed_stats: ApiMethod + getDatafeedStats: ApiMethod + get_datafeeds: ApiMethod + getDatafeeds: ApiMethod + get_filters: ApiMethod + getFilters: ApiMethod + get_influencers: ApiMethod + getInfluencers: ApiMethod + get_job_stats: ApiMethod + getJobStats: ApiMethod + get_jobs: ApiMethod + getJobs: ApiMethod + get_model_snapshots: ApiMethod + getModelSnapshots: ApiMethod + get_overall_buckets: ApiMethod + getOverallBuckets: ApiMethod + get_records: ApiMethod + getRecords: ApiMethod + info: ApiMethod + open_job: ApiMethod + openJob: ApiMethod + post_calendar_events: ApiMethod + postCalendarEvents: ApiMethod + post_data: ApiMethod + postData: ApiMethod + preview_datafeed: ApiMethod + previewDatafeed: ApiMethod + put_calendar: ApiMethod + putCalendar: ApiMethod + put_calendar_job: ApiMethod + putCalendarJob: ApiMethod + put_datafeed: ApiMethod + putDatafeed: ApiMethod + put_filter: ApiMethod + putFilter: ApiMethod + put_job: ApiMethod + putJob: ApiMethod + revert_model_snapshot: ApiMethod + revertModelSnapshot: ApiMethod + start_datafeed: ApiMethod + startDatafeed: ApiMethod + stop_datafeed: ApiMethod + stopDatafeed: ApiMethod + update_datafeed: ApiMethod + updateDatafeed: ApiMethod + update_filter: ApiMethod + updateFilter: ApiMethod + update_job: ApiMethod + updateJob: ApiMethod + update_model_snapshot: ApiMethod + updateModelSnapshot: ApiMethod + validate: ApiMethod + validate_detector: ApiMethod + validateDetector: ApiMethod + } + monitoring: { + bulk: ApiMethod + } + rollup: { + delete_job: ApiMethod + deleteJob: ApiMethod + get_jobs: ApiMethod + getJobs: ApiMethod + get_rollup_caps: ApiMethod + getRollupCaps: ApiMethod + get_rollup_index_caps: ApiMethod + getRollupIndexCaps: ApiMethod + put_job: ApiMethod + putJob: ApiMethod + rollup_search: ApiMethod + rollupSearch: ApiMethod + start_job: ApiMethod + startJob: ApiMethod + stop_job: ApiMethod + stopJob: ApiMethod + } + security: { + authenticate: ApiMethod + change_password: ApiMethod + changePassword: ApiMethod + clear_cached_realms: ApiMethod + clearCachedRealms: ApiMethod + clear_cached_roles: ApiMethod + clearCachedRoles: ApiMethod + delete_privileges: ApiMethod + deletePrivileges: ApiMethod + delete_role: ApiMethod + deleteRole: ApiMethod + delete_role_mapping: ApiMethod + deleteRoleMapping: ApiMethod + delete_user: ApiMethod + deleteUser: ApiMethod + disable_user: ApiMethod + disableUser: ApiMethod + enable_user: ApiMethod + enableUser: ApiMethod + get_privileges: ApiMethod + getPrivileges: ApiMethod + get_role: ApiMethod + getRole: ApiMethod + get_role_mapping: ApiMethod + getRoleMapping: ApiMethod + get_token: ApiMethod + getToken: ApiMethod + get_user: ApiMethod + getUser: ApiMethod + get_user_privileges: ApiMethod + getUserPrivileges: ApiMethod + has_privileges: ApiMethod + hasPrivileges: ApiMethod + invalidate_token: ApiMethod + invalidateToken: ApiMethod + put_privileges: ApiMethod + putPrivileges: ApiMethod + put_role: ApiMethod + putRole: ApiMethod + put_role_mapping: ApiMethod + putRoleMapping: ApiMethod + put_user: ApiMethod + putUser: ApiMethod + } + sql: { + clear_cursor: ApiMethod + clearCursor: ApiMethod + query: ApiMethod + translate: ApiMethod + } + ssl: { + certificates: ApiMethod + } + usage: ApiMethod + watcher: { + ack_watch: ApiMethod + ackWatch: ApiMethod + activate_watch: ApiMethod + activateWatch: ApiMethod + deactivate_watch: ApiMethod + deactivateWatch: ApiMethod + delete_watch: ApiMethod + deleteWatch: ApiMethod + execute_watch: ApiMethod + executeWatch: ApiMethod + get_watch: ApiMethod + getWatch: ApiMethod + put_watch: ApiMethod + putWatch: ApiMethod + restart: ApiMethod + start: ApiMethod + stats: ApiMethod + stop: ApiMethod + } + } } declare const events: { @@ -486,5 +487,6 @@ export { ApiResponse, EventMeta, SniffMeta, - ResurrectMeta + ResurrectMeta, + RequestParams }; diff --git a/scripts/run.js b/scripts/run.js index 7776efba5..92b63fb8b 100644 --- a/scripts/run.js +++ b/scripts/run.js @@ -7,7 +7,7 @@ const semver = require('semver') const ora = require('ora') const rimraf = require('rimraf') const standard = require('standard') -const { generate, cloneAndCheckout, genFactory } = require('./utils') +const { generate, cloneAndCheckout, genFactory, generateRequestTypes } = require('./utils') start(minimist(process.argv.slice(2), { string: ['tag'] @@ -23,6 +23,8 @@ function start (opts) { const apiOutputFolder = join(packageFolder, 'api') const mainOutputFile = join(packageFolder, 'index.js') const typesOutputFile = join(packageFolder, 'generated.d.ts') + const requestParamsOutputFile = join(packageFolder, 'requestParams.d.ts') + const allSpec = [] log.text = 'Cleaning API folder...' rimraf.sync(join(apiOutputFolder, '*.js')) @@ -36,6 +38,12 @@ function start (opts) { readdirSync(apiFolder).forEach(generateApiFile(apiFolder, log)) readdirSync(xPackFolder).forEach(generateApiFile(xPackFolder, log)) + writeFileSync( + requestParamsOutputFile, + generateRequestTypes(allSpec), + { encoding: 'utf8' } + ) + const { fn: factory, types } = genFactory(apiOutputFolder) writeFileSync( mainOutputFile, @@ -61,6 +69,7 @@ function start (opts) { log.text = `Processing ${file}` const spec = require(join(apiFolder, file)) + allSpec.push(spec) const code = generate(spec, common) const filePath = join(apiOutputFolder, `${file.slice(0, file.lastIndexOf('.'))}.js`) diff --git a/scripts/utils/genMain.js b/scripts/utils/genMain.js index ed36ceaa9..f7bc2358b 100644 --- a/scripts/utils/genMain.js +++ b/scripts/utils/genMain.js @@ -9,6 +9,11 @@ function genFactory (folder) { const apiFiles = readdirSync(folder) const types = apiFiles .map(file => { + const name = file + .slice(0, -3) + .replace(/\.([a-z])/g, k => k[1].toUpperCase()) + .replace(/_([a-z])/g, k => k[1].toUpperCase()) + return file .slice(0, -3) // remove `.js` extension .split('.') @@ -16,12 +21,12 @@ function genFactory (folder) { .reduce((acc, val) => { const obj = { [val]: acc === null - ? 'ApiMethod' + ? `ApiMethod` : acc } if (isSnakeCased(val)) { obj[camelify(val)] = acc === null - ? 'ApiMethod' + ? `ApiMethod` : acc } return obj diff --git a/scripts/utils/generateRequestTypes.js b/scripts/utils/generateRequestTypes.js new file mode 100644 index 000000000..092bdf99d --- /dev/null +++ b/scripts/utils/generateRequestTypes.js @@ -0,0 +1,71 @@ +'use strict' + +function generate (api) { + var types = `export interface Generic { + method?: string; + ignore?: number | number[]; + filter_path?: string | string[]; + pretty?: boolean; + human?: boolean; + error_trace?: boolean; + source?: string; +} +` + + api.forEach(generateRequestType) + return types + + function generateRequestType (spec) { + const api = Object.keys(spec)[0] + const name = api + .replace(/\.([a-z])/g, k => k[1].toUpperCase()) + .replace(/_([a-z])/g, k => k[1].toUpperCase()) + + const { parts = {}, params = {} } = spec[api].url + const { body } = spec[api] + + const partsArr = Object.keys(parts) + .map(k => ({ key: k, value: parts[k] })) + const paramsArr = Object.keys(params) + .filter(k => !Object.keys(parts).includes(k)) + .map(k => ({ key: k, value: params[k] })) + + const genLine = e => { + const optional = e.value.required ? '' : '?' + return `${e.key}${optional}: ${getType(e.value.type, e.value.options)};` + } + + const code = ` +export interface ${name[0].toUpperCase() + name.slice(1)} extends Generic { + ${partsArr.map(genLine).join('\n ')} + ${paramsArr.map(genLine).join('\n ')} + ${body ? `body${body.required ? '' : '?'}: any;` : ''} +} +` + + types += '\n' + // remove empty lines + types += code.replace(/^\s*\n/gm, '') + } + + function getType (type, options) { + switch (type) { + case 'list': + return 'string | string[]' + case 'date': + case 'time': + case 'timeout': + return 'string' + case 'enum': + return options.map(k => `'${k}'`).join(' | ') + case 'int': + case 'double': + case 'long': + return 'number' + default: + return type + } + } +} + +module.exports = generate diff --git a/scripts/utils/index.js b/scripts/utils/index.js index 8f781cef7..6993895f7 100644 --- a/scripts/utils/index.js +++ b/scripts/utils/index.js @@ -1,7 +1,8 @@ 'use strict' const generate = require('./generate') +const generateRequestTypes = require('./generateRequestTypes') const cloneAndCheckout = require('./clone-es') const genFactory = require('./genMain') -module.exports = { generate, cloneAndCheckout, genFactory } +module.exports = { generate, cloneAndCheckout, genFactory, generateRequestTypes }