WIP: initial prototype

- Added sniff reason
- Improved types
This commit is contained in:
delvedor
2018-12-04 14:29:40 +01:00
parent bf4adf0546
commit b60a716e00
3 changed files with 80 additions and 41 deletions

79
lib/Transport.d.ts vendored
View File

@ -6,42 +6,61 @@ declare type noopFn = (...args: any[]) => void;
declare type emitFn = (event: string | symbol, ...args: any[]) => boolean;
interface TransportOptions {
emit: emitFn & noopFn;
connectionPool: ConnectionPool;
serializer: Serializer;
maxRetries: number;
requestTimeout: number | string;
suggestCompression: boolean;
sniffInterval: number;
sniffOnConnectionFault: boolean;
sniffEndpoint: string;
sniffOnStart: boolean;
emit: emitFn & noopFn;
connectionPool: ConnectionPool;
serializer: Serializer;
maxRetries: number;
requestTimeout: number | string;
suggestCompression: boolean;
sniffInterval: number;
sniffOnConnectionFault: boolean;
sniffEndpoint: string;
sniffOnStart: boolean;
}
export interface ApiResponse {
body: any;
statusCode: number | null;
headers: any;
warnings: any[] | null;
body: any;
statusCode: number | null;
headers: any;
warnings: any[] | null;
}
export interface EventMeta {
connection: Connection;
request: any;
response: ApiResponse;
attempts: number;
aborted: boolean;
}
export interface SniffMeta {
hosts: any[];
reason: string;
}
export default class Transport {
emit: emitFn & noopFn;
connectionPool: ConnectionPool;
serializer: Serializer;
maxRetries: number;
requestTimeout: number;
suggestCompression: boolean;
sniffInterval: number;
sniffOnConnectionFault: boolean;
sniffEndpoint: string;
_sniffEnabled: boolean;
_nextSniff: number;
_isSniffing: boolean;
constructor(opts: TransportOptions);
request(params: any, callback: (err: Error | null, result: ApiResponse) => void): any;
getConnection(): Connection | null;
sniff(callback?: (...args: any[]) => void): void;
static sniffReasons: {
SNIFF_ON_START: string;
SNIFF_INTERVAL: string;
SNIFF_ON_CONNECTION_FAULT: string;
DEFAULT: string;
};
emit: emitFn & noopFn;
connectionPool: ConnectionPool;
serializer: Serializer;
maxRetries: number;
requestTimeout: number;
suggestCompression: boolean;
sniffInterval: number;
sniffOnConnectionFault: boolean;
sniffEndpoint: string;
_sniffEnabled: boolean;
_nextSniff: number;
_isSniffing: boolean;
constructor(opts: TransportOptions);
request(params: any, callback: (err: Error | null, result: ApiResponse) => void): any;
getConnection(): Connection | null;
sniff(callback?: (...args: any[]) => void): void;
}
export {};