Skip to content

Commit

Permalink
# Removed Generic Response
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed Aug 14, 2024
1 parent 3d50050 commit 83d6adb
Show file tree
Hide file tree
Showing 291 changed files with 1,758 additions and 626 deletions.
4 changes: 0 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
* under the License.
*/

/// <reference types="node" />

import Transport, {
ApiError,
ApiResponse,
RequestEvent,
} from './lib/Transport';
import Connection from './lib/Connection';
import {
Expand Down Expand Up @@ -67,7 +64,6 @@ export {
errors,
ApiError,
ApiResponse,
RequestEvent,
ResurrectEvent,
ClientOptions,
NodeOptions,
Expand Down
9 changes: 2 additions & 7 deletions lib/Transport.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ interface TransportOptions {
auth?: BasicAuth | AwsSigv4Auth;
}

export interface RequestEvent<TResponse = Record<string, any>> {
body: TResponse;
export interface ApiResponse {
body: any;
statusCode: number | null;
headers: Record<string, any> | null;
warnings: string[] | null;
Expand All @@ -106,11 +106,6 @@ export interface RequestEvent<TResponse = Record<string, any>> {
};
}

// ApiResponse and RequestEvent are the same thing
// we are doing this for have more clear names
export interface ApiResponse<TResponse = Record<string, any>>
extends RequestEvent<TResponse> {}

export type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream;
export type RequestNDBody<T = Record<string, any>[]> =
| T
Expand Down
8 changes: 4 additions & 4 deletions test/types/client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

import { expectType } from 'tsd';
import { Client, ApiError, ApiResponse, RequestEvent, ResurrectEvent } from '../../';
import { Client, ApiError, ApiResponse, ResurrectEvent } from '../../';
import { TransportRequestCallback, TransportRequestPromise } from '../../lib/Transport';

const client = new Client({
Expand All @@ -37,17 +37,17 @@ const client = new Client({

client.on('request', (err, meta) => {
expectType<ApiError>(err);
expectType<RequestEvent>(meta);
expectType<ApiResponse>(meta);
});

client.on('response', (err, meta) => {
expectType<ApiError>(err);
expectType<RequestEvent>(meta);
expectType<ApiResponse>(meta);
});

client.on('sniff', (err, meta) => {
expectType<ApiError>(err);
expectType<RequestEvent>(meta);
expectType<ApiResponse>(meta);
});

client.on('resurrect', (err, meta) => {
Expand Down
5 changes: 2 additions & 3 deletions test/types/transport.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ import {
TransportRequestOptions,
TransportRequestCallback,
TransportRequestPromise,
RequestEvent,
ApiResponse,
ApiError,
RequestBody,
RequestNDBody,
ApiResponse,
} from '../../lib/Transport';

const params = {
Expand Down Expand Up @@ -84,7 +83,7 @@ const response = {
expectAssignable<TransportRequestParams>(params);
expectAssignable<TransportRequestParams>({ method: 'GET', path: '/' });
expectAssignable<TransportRequestOptions>(options);
expectAssignable<RequestEvent>(response);
expectAssignable<ApiResponse>(response);
expectAssignable<ApiResponse>(response);

// verify that RequestBody, RequestNDBody and ResponseBody works as expected
Expand Down
642 changes: 320 additions & 322 deletions types/Client.d.ts

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion types/functions/bulk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Core_Search from '../components/_core.search'
import * as Common from '../components/_common'
Expand All @@ -33,7 +34,7 @@ export interface Request extends Global.Params {
wait_for_active_shards?: Common.WaitForActiveShards;
}

export interface Response {
export interface ResponseBody {
errors: boolean;
ingest_took?: number;
items: Record<string, Core_Bulk.ResponseItem>[];
Expand All @@ -42,3 +43,6 @@ export interface Response {

export type RequestBody = Core_Bulk.OperationContainer | Core_Bulk.UpdateAction | Record<string, any>[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.aliases.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Aliases from '../components/cat.aliases'
Expand All @@ -28,5 +29,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Aliases.AliasesRecord[]
export type ResponseBody = Cat_Aliases.AliasesRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.all_pit_segments.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Common from '../components/cat._common'
Expand All @@ -26,5 +27,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Common.CatPitSegmentsRecord[]
export type ResponseBody = Cat_Common.CatPitSegmentsRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.allocation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Allocation from '../components/cat.allocation'
Expand All @@ -30,5 +31,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Allocation.AllocationRecord[]
export type ResponseBody = Cat_Allocation.AllocationRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.cluster_manager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_ClusterManager from '../components/cat.cluster_manager'
Expand All @@ -28,5 +29,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_ClusterManager.ClusterManagerRecord[]
export type ResponseBody = Cat_ClusterManager.ClusterManagerRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.count.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Count from '../components/cat.count'
Expand All @@ -26,5 +27,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Count.CountRecord[]
export type ResponseBody = Cat_Count.CountRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.fielddata.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Fielddata from '../components/cat.fielddata'
Expand All @@ -27,5 +28,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Fielddata.FielddataRecord[]
export type ResponseBody = Cat_Fielddata.FielddataRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.health.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Health from '../components/cat.health'
Expand All @@ -27,5 +28,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Health.HealthRecord[]
export type ResponseBody = Cat_Health.HealthRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.help.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'

export type Request = Global.Params & Record<string, any>

export type Response = Record<string, any>
export type ResponseBody = Record<string, any>

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.indices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Indices from '../components/cat.indices'
Expand All @@ -35,5 +36,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Indices.IndicesRecord[]
export type ResponseBody = Cat_Indices.IndicesRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.master.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Master from '../components/cat.master'
Expand All @@ -28,5 +29,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Master.MasterRecord[]
export type ResponseBody = Cat_Master.MasterRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.nodeattrs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Nodeattrs from '../components/cat.nodeattrs'
Expand All @@ -28,5 +29,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Nodeattrs.NodeAttributesRecord[]
export type ResponseBody = Cat_Nodeattrs.NodeAttributesRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Nodes from '../components/cat.nodes'
Expand All @@ -31,5 +32,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Nodes.NodesRecord[]
export type ResponseBody = Cat_Nodes.NodesRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.pending_tasks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_PendingTasks from '../components/cat.pending_tasks'
Expand All @@ -29,5 +30,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_PendingTasks.PendingTasksRecord[]
export type ResponseBody = Cat_PendingTasks.PendingTasksRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.pit_segments.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Common from '../components/cat._common'
Expand All @@ -27,9 +28,12 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Common.CatPitSegmentsRecord[]
export type ResponseBody = Cat_Common.CatPitSegmentsRecord[]

export interface RequestBody {
pit_id: string[];
}

export interface Response extends ApiResponse {
body: ResponseBody
}
6 changes: 5 additions & 1 deletion types/functions/cat.plugins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* the API generator.
*/

import { ApiResponse } from '../../lib/Transport'
import * as Global from '../components/_global'
import * as Common from '../components/_common'
import * as Cat_Plugins from '../components/cat.plugins'
Expand All @@ -28,5 +29,8 @@ export interface Request extends Global.Params {
v?: boolean;
}

export type Response = Cat_Plugins.PluginsRecord[]
export type ResponseBody = Cat_Plugins.PluginsRecord[]

export interface Response extends ApiResponse {
body: ResponseBody
}
Loading

0 comments on commit 83d6adb

Please sign in to comment.