Skip to content

Commit

Permalink
Updated typings (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Apr 17, 2019
1 parent cfd4e70 commit d4f4b47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
20 changes: 14 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import Transport, {
TransportRequestParams,
TransportRequestOptions,
nodeFilterFn,
nodeSelectorFn
nodeSelectorFn,
TransportRequestCallback
} from './lib/Transport';
import Connection, { AgentOptions, agentFn } from './lib/Connection';
import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool';
Expand All @@ -38,12 +39,18 @@ import * as errors from './lib/errors';
declare type anyObject = {
[key: string]: any;
};
declare type callbackFn = (err: Error | null, result: ApiResponse) => void;

interface ApiMethod<T> {
(callback?: callbackFn): any;
(params: T, callback?: callbackFn): any;
(params: T, options: TransportRequestOptions, callback?: callbackFn): any;
declare type callbackFn<T> = (err: Error | null, result: ApiResponse<T>) => void;

interface ApiMethod<TParams, TBody = any> {
// Promise API
(): Promise<ApiResponse<TBody>>;
(params: TParams): Promise<ApiResponse<TBody>>;
(params: TParams, options: TransportRequestOptions): Promise<ApiResponse<TBody>>;
// Callback API
(callback: callbackFn<TBody>): TransportRequestCallback;
(params: TParams, callback: callbackFn<TBody>): TransportRequestCallback;
(params: TParams, options: TransportRequestOptions, callback: callbackFn<TBody>): TransportRequestCallback;
}

// Extend API
Expand Down Expand Up @@ -570,5 +577,6 @@ export {
RequestEvent,
ResurrectEvent,
RequestParams,
ClientOptions,
ClientExtendsCallbackOptions
};
7 changes: 6 additions & 1 deletion lib/Transport.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export interface TransportRequestOptions {
warnings?: [string];
}

export interface TransportRequestCallback {
abort: () => void;
}

export default class Transport {
static sniffReasons: {
SNIFF_ON_START: string;
Expand All @@ -117,7 +121,8 @@ export default class Transport {
_nextSniff: number;
_isSniffing: boolean;
constructor(opts: TransportOptions);
request(params: TransportRequestParams, options: TransportRequestOptions, callback: (err: Error | null, result: ApiResponse) => void): any;
request(params: TransportRequestParams, options?: TransportRequestOptions): Promise<ApiResponse>;
request(params: TransportRequestParams, options?: TransportRequestOptions, callback?: (err: Error | null, result: ApiResponse) => void): TransportRequestCallback;
getConnection(): Connection | null;
sniff(callback?: (...args: any[]) => void): void;
}
Expand Down

0 comments on commit d4f4b47

Please sign in to comment.