Skip to content

Commit

Permalink
Update unknown parameter handling. (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor authored Oct 18, 2021
1 parent 070b9d7 commit 4492532
Show file tree
Hide file tree
Showing 84 changed files with 1,884 additions and 3,177 deletions.
52 changes: 26 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
'use strict'

const {
Diagnostic,
Transport,
WeightedConnectionPool,
ClusterConnectionPool,
BaseConnectionPool,
CloudConnectionPool,
BaseConnection,
HttpConnection,
UndiciConnection,
Serializer,
errors,
events
Diagnostic,
Transport,
WeightedConnectionPool,
ClusterConnectionPool,
BaseConnectionPool,
CloudConnectionPool,
BaseConnection,
HttpConnection,
UndiciConnection,
Serializer,
errors,
events
} = require('@elastic/transport')

const { default: Client } = require('./lib/client')

module.exports = {
Client,
Diagnostic,
Transport,
WeightedConnectionPool,
ClusterConnectionPool,
BaseConnectionPool,
CloudConnectionPool,
BaseConnection,
HttpConnection,
UndiciConnection,
Serializer,
errors,
events
module.exports = {
Client,
Diagnostic,
Transport,
WeightedConnectionPool,
ClusterConnectionPool,
BaseConnectionPool,
CloudConnectionPool,
BaseConnection,
HttpConnection,
UndiciConnection,
Serializer,
errors,
events
}
46 changes: 14 additions & 32 deletions src/api/api/async_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,15 @@ export default class AsyncSearch {
async delete (this: That, params: T.AsyncSearchDeleteRequest | TB.AsyncSearchDeleteRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchDeleteResponse>
async delete (this: That, params: T.AsyncSearchDeleteRequest | TB.AsyncSearchDeleteRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['id']
const acceptedQuery: string[] = ['error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params.body ?? undefined
const body = undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
} else if (acceptedPath.includes(key)) {
if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand All @@ -76,21 +70,15 @@ export default class AsyncSearch {
async get<TDocument = unknown> (this: That, params: T.AsyncSearchGetRequest | TB.AsyncSearchGetRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchGetResponse<TDocument>>
async get<TDocument = unknown> (this: That, params: T.AsyncSearchGetRequest | TB.AsyncSearchGetRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['id']
const acceptedQuery: string[] = ['keep_alive', 'typed_keys', 'wait_for_completion_timeout', 'error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params.body ?? undefined
const body = undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
} else if (acceptedPath.includes(key)) {
if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand All @@ -104,21 +92,15 @@ export default class AsyncSearch {
async status<TDocument = unknown> (this: That, params: T.AsyncSearchStatusRequest | TB.AsyncSearchStatusRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchStatusResponse<TDocument>>
async status<TDocument = unknown> (this: That, params: T.AsyncSearchStatusRequest | TB.AsyncSearchStatusRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['id']
const acceptedQuery: string[] = ['error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params.body ?? undefined
const body = undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
} else if (acceptedPath.includes(key)) {
if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand All @@ -132,22 +114,22 @@ export default class AsyncSearch {
async submit<TDocument = unknown> (this: That, params?: T.AsyncSearchSubmitRequest | TB.AsyncSearchSubmitRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchSubmitResponse<TDocument>>
async submit<TDocument = unknown> (this: That, params?: T.AsyncSearchSubmitRequest | TB.AsyncSearchSubmitRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['index']
const acceptedQuery: string[] = ['batched_reduce_size', 'wait_for_completion_timeout', 'keep_on_completion', 'typed_keys', 'error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const acceptedBody: string[] = ['aggs', 'aggregations', 'collapse', 'highlight', 'indices_boost', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'script_fields', 'search_after', 'slice', 'fields', 'suggest', 'pit', 'runtime_mappings']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params?.body ?? undefined

params = params ?? {}
for (const key in params) {
if (acceptedQuery.includes(key)) {
if (acceptedBody.includes(key)) {
body = body ?? {}
// @ts-expect-error
querystring[key] = params[key]
body[key] = params[key]
} else if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand Down
44 changes: 13 additions & 31 deletions src/api/api/autoscaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,15 @@ export default class Autoscaling {
async deleteAutoscalingPolicy (this: That, params: T.AutoscalingDeleteAutoscalingPolicyRequest | TB.AutoscalingDeleteAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<T.AutoscalingDeleteAutoscalingPolicyResponse>
async deleteAutoscalingPolicy (this: That, params: T.AutoscalingDeleteAutoscalingPolicyRequest | TB.AutoscalingDeleteAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['name']
const acceptedQuery: string[] = ['error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params.body ?? undefined
const body = undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
} else if (acceptedPath.includes(key)) {
if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand All @@ -76,22 +70,16 @@ export default class Autoscaling {
async getAutoscalingCapacity (this: That, params?: T.AutoscalingGetAutoscalingCapacityRequest | TB.AutoscalingGetAutoscalingCapacityRequest, options?: TransportRequestOptions): Promise<T.AutoscalingGetAutoscalingCapacityResponse>
async getAutoscalingCapacity (this: That, params?: T.AutoscalingGetAutoscalingCapacityRequest | TB.AutoscalingGetAutoscalingCapacityRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = []
const acceptedQuery: string[] = ['error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params?.body ?? undefined
const body = undefined

params = params ?? {}
for (const key in params) {
if (acceptedQuery.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
} else if (acceptedPath.includes(key)) {
if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand All @@ -105,21 +93,15 @@ export default class Autoscaling {
async getAutoscalingPolicy (this: That, params: T.AutoscalingGetAutoscalingPolicyRequest | TB.AutoscalingGetAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<T.AutoscalingGetAutoscalingPolicyResponse>
async getAutoscalingPolicy (this: That, params: T.AutoscalingGetAutoscalingPolicyRequest | TB.AutoscalingGetAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['name']
const acceptedQuery: string[] = ['error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: Record<string, any> = params.body ?? undefined
const body = undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
} else if (acceptedPath.includes(key)) {
if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
body = body ?? {}
// @ts-expect-error
body[key] = params[key]
querystring[key] = params[key]
}
}

Expand All @@ -133,20 +115,20 @@ export default class Autoscaling {
async putAutoscalingPolicy (this: That, params: T.AutoscalingPutAutoscalingPolicyRequest | TB.AutoscalingPutAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<T.AutoscalingPutAutoscalingPolicyResponse>
async putAutoscalingPolicy (this: That, params: T.AutoscalingPutAutoscalingPolicyRequest | TB.AutoscalingPutAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['name']
const acceptedQuery: string[] = ['error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const acceptedBody: string[] = ['policy']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: any = params.body ?? undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
if (acceptedBody.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
body = params[key]
} else if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
// @ts-expect-error
body = params[key]
querystring[key] = params[key]
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/api/api/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ export default async function BulkApi<TSource = unknown> (this: That, params: T.
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptions): Promise<T.BulkResponse>
export default async function BulkApi<TSource = unknown> (this: That, params: T.BulkRequest<TSource> | TB.BulkRequest<TSource>, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = ['index', 'type']
const acceptedQuery: string[] = ['pipeline', 'refresh', 'routing', '_source', '_source_excludes', '_source_includes', 'timeout', 'type', 'wait_for_active_shards', 'require_alias', 'error_trace', 'filter_path', 'human', 'pretty', 'source_query_string']
const acceptedBody: string[] = ['operations']
const querystring: Record<string, any> = {}
// @ts-expect-error
let body: any = params.body ?? undefined

for (const key in params) {
if (acceptedQuery.includes(key)) {
if (acceptedBody.includes(key)) {
// @ts-expect-error
querystring[key] = params[key]
body = params[key]
} else if (acceptedPath.includes(key)) {
continue
} else if (key !== 'body') {
// @ts-expect-error
body = params[key]
querystring[key] = params[key]
}
}

Expand Down
Loading

0 comments on commit 4492532

Please sign in to comment.