sdg-rpc
Version:
pomelo ts rpc
57 lines (56 loc) • 1.61 kB
TypeScript
import SocketClient from '../client/mailboxes/sio';
import { IRpcMsg } from './common';
export declare type IRpcServerId = string;
export interface IRpcServerInfo {
id: IRpcServerId;
host: string;
port: number;
type: string;
weight?: number;
}
export interface IRpcServerMap {
[serverType: string]: string[];
}
export interface IRpcServerInfos {
[key: string]: IRpcServerInfo;
}
export interface IStatus {
[key: string]: boolean;
}
export interface ISocketClientOpts {
bufferMsg?: boolean;
keepalive?: number;
interval?: number;
timeout?: number;
context?: any;
}
export interface IClientFactory {
create: Function;
}
export interface IMailStationOpts extends ISocketClientOpts {
mailboxFactory?: IClientFactory;
}
export interface IRpcClientOpts extends IMailStationOpts {
context?: any;
routerContext?: any;
router?: IRouter;
routerType?: string;
}
export declare type IMailbox = SocketClient;
export interface IMailboxes {
[key: string]: IMailbox;
}
export interface ITargetRouterFunction {
(serverType: string, msg: IRpcMsg, routeParam: object): Promise<string>;
}
export declare type IRouteServers = IRpcServerInfo[];
export interface IRouteContextClass {
getServersByType?: (serverType: string) => IRouteServers;
}
export declare type IRouteContext = IRouteServers | IRouteContextClass;
export declare type IRouterFunction = (session: {
[key: string]: any;
}, msg: IRpcMsg, context: IRouteContext) => Promise<string> | string;
export declare type IRouter = IRouterFunction | {
route: IRouterFunction;
};