Skip to content

Updated typings #819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -604,5 +611,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