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 ConnectionHandler = (socket:I.Socket) => void export type ErrorHandler = (socket:I.Socket, error:any) => void export type CloseHandler = (socket:I.Socket) => void export type SocketConf = { connectionHandler?: ConnectionHandler errorHandler?: ErrorHandler closeHandler?: CloseHandler visibility?: Visibility } export type ResponseType = "Subscribe" | "Success" | "Error" export type Outcome = "Success" | "Error" export type Respose = T & { result: Outcome } export type SuccessResponse = Respose & { result: "Success" } export type ErrorResponse = Respose & { result: "Error", message?:string } export type SubscriptionResponse = Respose & { result: "Success"; uuid: string } export type RPCType = 'Hook' | 'Unhook' | 'Call' export type HookRPC = { name: Name hook: HookFunction onCallback?: CallbackFunction, onClose?: HookCloseFunction } export type CallRPC = { name: Name call: AsyncFunction } | Function export type RPC = CallRPC | HookRPC export type BaseInfo = { name: Name, owner: Name, argNames: Name[], } export type HookInfo = BaseInfo & { type: 'Hook', generator: (socket?:I.Socket) => HookFunction } export type CallInfo = BaseInfo & { type: 'Call', call: AsyncFunction } export type RpcInfo = HookInfo | CallInfo export type ExtendedRpcInfo = RpcInfo & { uniqueName: string } export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket export type HookCloseFunction = (res:SubscriptionResponse, rpc:HookRPC) => any export type HookFunction = (...args:any) => Promise | ErrorResponse> export type AsyncFunction = (...args:any) => Promise export type CallbackFunction = (...args:any) => void