import * as R from "./Responses"; import * as I from "./Interfaces"; export type Visibility = "127.0.0.1" | "0.0.0.0" export type Any = any export type Arg = string export type Name = Arg export type Owner = Name export type SocketConf = { connectionHandler: (socket:I.Socket) => void errorHandler: (socket:I.Socket) => (error:any) => void closeHandler: (socket:I.Socket) => () => void visibility: Visibility } export type RPCType = 'Hook' | 'Unhook' | 'Call' export type BaseRPC = { type: RPCType name: Name } export type HookRPC = BaseRPC & { type: 'Hook' clbk: CallbackFunction unhook: UnhookFunction } export type UnhookRPC = BaseRPC & { type: 'Unhook' unhook: UnhookFunction } export type CallRPC = BaseRPC & { type: 'Call' call: AsyncFunction } export type RPC = CallRPC | UnhookRPC | HookRPC export type BaseInfo = { owner: Name, argNames: Name[], } export type HookInfo = BaseRPC & BaseInfo & { type: 'Hook', generator: (socket) => CallbackFunction unhook: UnhookFunction } export type UnhookInfo = BaseRPC & BaseInfo & { type: 'Unhook', unhook: UnhookFunction } export type CallInfo = BaseRPC & BaseInfo & { type: 'Call', call: AsyncFunction } export type RpcInfo = HookInfo | UnhookInfo | CallInfo export type ExtendedRpcInfo = RpcInfo & { uniqueName: string } export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket export type UnhookFunction = (uid:string) => Promise export type CallbackFunction = (...args) => Promise export type AsyncFunction = (...args) => Promise