Skip to content

Commit d228a2f

Browse files
committed
API generation
1 parent 5086a19 commit d228a2f

27 files changed

+4222
-1762
lines changed

src/api/api/bulk.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import * as T from '../types'
3737
import * as TB from '../typesWithBodyKey'
3838
interface That { transport: Transport }
3939

40-
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptionsWithOutMeta): Promise<T.BulkResponse>
41-
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.BulkResponse, unknown>>
42-
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptions): Promise<T.BulkResponse>
43-
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptions): Promise<any> {
44-
const acceptedPath: string[] = ['index', 'type']
40+
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithOutMeta): Promise<T.BulkResponse>
41+
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.BulkResponse, unknown>>
42+
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.BulkResponse>
43+
export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument> | TB.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> {
44+
const acceptedPath: string[] = ['index']
4545
const acceptedBody: string[] = ['operations']
4646
const querystring: Record<string, any> = {}
4747
// @ts-expect-error
@@ -61,10 +61,7 @@ export default async function BulkApi<TSource = unknown> (this: That, params: T.
6161

6262
let method = ''
6363
let path = ''
64-
if (params.index != null && params.type != null) {
65-
method = 'POST'
66-
path = `/${encodeURIComponent(params.index.toString())}/${encodeURIComponent(params.type.toString())}/_bulk`
67-
} else if (params.index != null) {
64+
if (params.index != null) {
6865
method = 'POST'
6966
path = `/${encodeURIComponent(params.index.toString())}/_bulk`
7067
} else {

src/api/api/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default async function CreateApi<TDocument = unknown> (this: That, params
4141
export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument> | TB.CreateRequest<TDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CreateResponse, unknown>>
4242
export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument> | TB.CreateRequest<TDocument>, options?: TransportRequestOptions): Promise<T.CreateResponse>
4343
export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument> | TB.CreateRequest<TDocument>, options?: TransportRequestOptions): Promise<any> {
44-
const acceptedPath: string[] = ['id', 'index', 'type']
44+
const acceptedPath: string[] = ['id', 'index']
4545
const acceptedBody: string[] = ['document']
4646
const querystring: Record<string, any> = {}
4747
// @ts-expect-error

src/api/api/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default async function DeleteApi (this: That, params: T.DeleteRequest | T
4141
export default async function DeleteApi (this: That, params: T.DeleteRequest | TB.DeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DeleteResponse, unknown>>
4242
export default async function DeleteApi (this: That, params: T.DeleteRequest | TB.DeleteRequest, options?: TransportRequestOptions): Promise<T.DeleteResponse>
4343
export default async function DeleteApi (this: That, params: T.DeleteRequest | TB.DeleteRequest, options?: TransportRequestOptions): Promise<any> {
44-
const acceptedPath: string[] = ['id', 'index', 'type']
44+
const acceptedPath: string[] = ['id', 'index']
4545
const querystring: Record<string, any> = {}
4646
const body = undefined
4747

src/api/api/eql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default class Eql {
114114
async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest | TB.EqlSearchRequest, options?: TransportRequestOptions): Promise<T.EqlSearchResponse<TEvent>>
115115
async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest | TB.EqlSearchRequest, options?: TransportRequestOptions): Promise<any> {
116116
const acceptedPath: string[] = ['index']
117-
const acceptedBody: string[] = ['query', 'case_sensitive', 'event_category_field', 'tiebreaker_field', 'timestamp_field', 'fetch_size', 'filter', 'keep_alive', 'keep_on_completion', 'wait_for_completion_timeout', 'size', 'fields', 'result_position']
117+
const acceptedBody: string[] = ['query', 'case_sensitive', 'event_category_field', 'tiebreaker_field', 'timestamp_field', 'fetch_size', 'filter', 'keep_alive', 'keep_on_completion', 'wait_for_completion_timeout', 'size', 'fields', 'result_position', 'runtime_mappings']
118118
const querystring: Record<string, any> = {}
119119
// @ts-expect-error
120120
const userBody: any = params?.body

src/api/api/exists_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default async function ExistsSourceApi (this: That, params: T.ExistsSourc
4141
export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest | TB.ExistsSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ExistsSourceResponse, unknown>>
4242
export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest | TB.ExistsSourceRequest, options?: TransportRequestOptions): Promise<T.ExistsSourceResponse>
4343
export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest | TB.ExistsSourceRequest, options?: TransportRequestOptions): Promise<any> {
44-
const acceptedPath: string[] = ['id', 'index', 'type']
44+
const acceptedPath: string[] = ['id', 'index']
4545
const querystring: Record<string, any> = {}
4646
const body = undefined
4747

src/api/api/fleet.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,24 @@ export default class Fleet {
6565
return await this.transport.request({ path, method, querystring, body }, options)
6666
}
6767

68-
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
69-
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
70-
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
71-
async msearch (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
68+
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.FleetMsearchResponse<TDocument>>
69+
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetMsearchResponse<TDocument>, unknown>>
70+
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptions): Promise<T.FleetMsearchResponse<TDocument>>
71+
async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest | TB.FleetMsearchRequest, options?: TransportRequestOptions): Promise<any> {
7272
const acceptedPath: string[] = ['index']
73+
const acceptedBody: string[] = ['searches']
7374
const querystring: Record<string, any> = {}
74-
const body = undefined
75+
// @ts-expect-error
76+
let body: any = params.body ?? undefined
7577

76-
params = params ?? {}
7778
for (const key in params) {
78-
if (acceptedPath.includes(key)) {
79+
if (acceptedBody.includes(key)) {
80+
// @ts-expect-error
81+
body = params[key]
82+
} else if (acceptedPath.includes(key)) {
7983
continue
8084
} else if (key !== 'body') {
85+
// @ts-expect-error
8186
querystring[key] = params[key]
8287
}
8388
}
@@ -94,19 +99,31 @@ export default class Fleet {
9499
return await this.transport.request({ path, method, querystring, bulkBody: body }, options)
95100
}
96101

97-
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
98-
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
99-
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
100-
async search (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
102+
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.FleetSearchResponse<TDocument>>
103+
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetSearchResponse<TDocument>, unknown>>
104+
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptions): Promise<T.FleetSearchResponse<TDocument>>
105+
async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest | TB.FleetSearchRequest, options?: TransportRequestOptions): Promise<any> {
101106
const acceptedPath: string[] = ['index']
107+
const acceptedBody: string[] = ['aggregations', 'aggs', 'collapse', 'explain', 'from', 'highlight', 'track_total_hits', 'indices_boost', 'docvalue_fields', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'script_fields', 'search_after', 'size', 'slice', 'sort', '_source', 'fields', 'suggest', 'terminate_after', 'timeout', 'track_scores', 'version', 'seq_no_primary_term', 'stored_fields', 'pit', 'runtime_mappings', 'stats']
102108
const querystring: Record<string, any> = {}
103-
const body = undefined
109+
// @ts-expect-error
110+
const userBody: any = params?.body
111+
let body: Record<string, any> | string
112+
if (typeof userBody === 'string') {
113+
body = userBody
114+
} else {
115+
body = userBody != null ? { ...userBody } : undefined
116+
}
104117

105-
params = params ?? {}
106118
for (const key in params) {
107-
if (acceptedPath.includes(key)) {
119+
if (acceptedBody.includes(key)) {
120+
body = body ?? {}
121+
// @ts-expect-error
122+
body[key] = params[key]
123+
} else if (acceptedPath.includes(key)) {
108124
continue
109125
} else if (key !== 'body') {
126+
// @ts-expect-error
110127
querystring[key] = params[key]
111128
}
112129
}

src/api/api/ilm.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,32 @@ export default class Ilm {
140140
return await this.transport.request({ path, method, querystring, body }, options)
141141
}
142142

143-
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
144-
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
145-
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
146-
async migrateToDataTiers (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
143+
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.IlmMigrateToDataTiersResponse>
144+
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmMigrateToDataTiersResponse, unknown>>
145+
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions): Promise<T.IlmMigrateToDataTiersResponse>
146+
async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest | TB.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions): Promise<any> {
147147
const acceptedPath: string[] = []
148+
const acceptedBody: string[] = ['legacy_template_to_delete', 'node_attribute']
148149
const querystring: Record<string, any> = {}
149-
const body = undefined
150+
// @ts-expect-error
151+
const userBody: any = params?.body
152+
let body: Record<string, any> | string
153+
if (typeof userBody === 'string') {
154+
body = userBody
155+
} else {
156+
body = userBody != null ? { ...userBody } : undefined
157+
}
150158

151159
params = params ?? {}
152160
for (const key in params) {
153-
if (acceptedPath.includes(key)) {
161+
if (acceptedBody.includes(key)) {
162+
body = body ?? {}
163+
// @ts-expect-error
164+
body[key] = params[key]
165+
} else if (acceptedPath.includes(key)) {
154166
continue
155167
} else if (key !== 'body') {
168+
// @ts-expect-error
156169
querystring[key] = params[key]
157170
}
158171
}

src/api/api/indices.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -513,32 +513,10 @@ export default class Indices {
513513
return await this.transport.request({ path, method, querystring, body }, options)
514514
}
515515

516-
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.IndicesExistsTypeResponse>
517-
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExistsTypeResponse, unknown>>
518-
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptions): Promise<T.IndicesExistsTypeResponse>
519-
async existsType (this: That, params: T.IndicesExistsTypeRequest | TB.IndicesExistsTypeRequest, options?: TransportRequestOptions): Promise<any> {
520-
const acceptedPath: string[] = ['index', 'type']
521-
const querystring: Record<string, any> = {}
522-
const body = undefined
523-
524-
for (const key in params) {
525-
if (acceptedPath.includes(key)) {
526-
continue
527-
} else if (key !== 'body') {
528-
// @ts-expect-error
529-
querystring[key] = params[key]
530-
}
531-
}
532-
533-
const method = 'HEAD'
534-
const path = `/${encodeURIComponent(params.index.toString())}/_mapping/${encodeURIComponent(params.type.toString())}`
535-
return await this.transport.request({ path, method, querystring, body }, options)
536-
}
537-
538-
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithOutMeta): Promise<T.TODO>
539-
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>>
540-
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<T.TODO>
541-
async fieldUsageStats (this: That, params?: T.TODO | TB.TODO, options?: TransportRequestOptions): Promise<any> {
516+
async fieldUsageStats (this: That, params?: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.IndicesFieldUsageStatsResponse>
517+
async fieldUsageStats (this: That, params?: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesFieldUsageStatsResponse, unknown>>
518+
async fieldUsageStats (this: That, params?: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions): Promise<T.IndicesFieldUsageStatsResponse>
519+
async fieldUsageStats (this: That, params?: T.IndicesFieldUsageStatsRequest | TB.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions): Promise<any> {
542520
const acceptedPath: string[] = ['index']
543521
const querystring: Record<string, any> = {}
544522
const body = undefined
@@ -548,6 +526,7 @@ export default class Indices {
548526
if (acceptedPath.includes(key)) {
549527
continue
550528
} else if (key !== 'body') {
529+
// @ts-expect-error
551530
querystring[key] = params[key]
552531
}
553532
}
@@ -1563,7 +1542,7 @@ export default class Indices {
15631542
async validateQuery (this: That, params?: T.IndicesValidateQueryRequest | TB.IndicesValidateQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesValidateQueryResponse, unknown>>
15641543
async validateQuery (this: That, params?: T.IndicesValidateQueryRequest | TB.IndicesValidateQueryRequest, options?: TransportRequestOptions): Promise<T.IndicesValidateQueryResponse>
15651544
async validateQuery (this: That, params?: T.IndicesValidateQueryRequest | TB.IndicesValidateQueryRequest, options?: TransportRequestOptions): Promise<any> {
1566-
const acceptedPath: string[] = ['index', 'type']
1545+
const acceptedPath: string[] = ['index']
15671546
const acceptedBody: string[] = ['query']
15681547
const querystring: Record<string, any> = {}
15691548
// @ts-expect-error

src/api/api/license.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ export default class License {
135135
return await this.transport.request({ path, method, querystring, body }, options)
136136
}
137137

138-
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.LicensePostResponse>
139-
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostResponse, unknown>>
140-
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<T.LicensePostResponse>
141-
async post (this: That, params?: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<any> {
138+
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.LicensePostResponse>
139+
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostResponse, unknown>>
140+
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<T.LicensePostResponse>
141+
async post (this: That, params: T.LicensePostRequest | TB.LicensePostRequest, options?: TransportRequestOptions): Promise<any> {
142142
const acceptedPath: string[] = []
143143
const acceptedBody: string[] = ['license', 'licenses']
144144
const querystring: Record<string, any> = {}
@@ -151,7 +151,6 @@ export default class License {
151151
body = userBody != null ? { ...userBody } : undefined
152152
}
153153

154-
params = params ?? {}
155154
for (const key in params) {
156155
if (acceptedBody.includes(key)) {
157156
body = body ?? {}

0 commit comments

Comments
 (0)