UNPKG

@hpcc-js/comms

Version:
43 lines (42 loc) 2.32 kB
export type RequestType = "post" | "get" | "jsonp"; export type ResponseType = "json" | "text"; export type IOptionsSend = (options: IOptions, action: string, request: any, responseType: ResponseType, defaultSend: SendFunc, header?: any) => Promise<any>; export interface IOptions { baseUrl: string; type?: RequestType; userID?: string; password?: string; rejectUnauthorized?: boolean; timeoutSecs?: number; hookSend?: IOptionsSend; encodeRequest?: boolean; } export declare function instanceOfIOptions(object: any): object is IOptions; export interface IConnection { opts(_: Partial<IOptions>): this; opts(): IOptions; baseUrl: string; send(action: string, request: any, responseType?: ResponseType): Promise<any>; clone(): IConnection; } export declare function instanceOfIConnection(object: any): object is IConnection; export declare function serializeRequest(obj: any, encodeRequest?: boolean, prefix?: string): string; export declare function deserializeResponse(body: string): any; export declare function jsonp(opts: IOptions, action: string, request?: any, responseType?: ResponseType, header?: any): Promise<any>; export declare function post(opts: IOptions, action: string, request: any, responseType?: ResponseType, header?: any): Promise<any>; export declare function get(opts: IOptions, action: string, request: any, responseType?: ResponseType, header?: any): Promise<any>; export type SendFunc = (opts: IOptions, action: string, request: any, responseType: ResponseType, header?: any) => Promise<any>; export declare function send(opts: IOptions, action: string, request: any, responseType?: ResponseType, header?: any): Promise<any>; export declare function hookSend(newSend?: SendFunc): SendFunc; export declare class Connection implements IConnection { protected _opts: IOptions; get baseUrl(): string; constructor(opts: IOptions); opts(_: Partial<IOptions>): this; opts(): IOptions; send(action: string, request: any, responseType?: ResponseType, header?: any): Promise<any>; clone(): Connection; } export type IConnectionFactory = (opts: IOptions) => IConnection; export declare let createConnection: IConnectionFactory; export declare function setTransportFactory(newFunc: IConnectionFactory): IConnectionFactory;