import * as I from "./Interfaces"; export type AnyFunction = (...args:any) => any export type HookFunction = (...args: Parameters) => Promise | ErrorResponse> export type Visibility = "127.0.0.1" | "0.0.0.0" export type ConnectionHandler = (socket:I.Socket) => void export type ErrorHandler = (socket:I.Socket, error:any, rpcName: string, args: any[]) => void export type CloseHandler = (socket:I.Socket) => void export type SesameFunction = (sesame : string) => boolean export type ExceptionHandling = 'local' | 'remote' export type SesameConf = { sesame?: string | SesameFunction } export type FrontEndHandlerType = { 'error' : (e: any) => void 'close' : () => void } export type ServerConf = { connectionHandler?: ConnectionHandler errorHandler?: ErrorHandler closeHandler?: CloseHandler visibility?: Visibility exceptionHandling?: ExceptionHandling } & SesameConf export type SocketConf = { tls:boolean } 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 CallRPC = { name: N call: F } export type HookRPC = { name: N hook: HookFunction onCallback?: AnyFunction onClose?: HookCloseFunction } export type RPC = HookRPC | CallRPC | F export type RPCInterface = { [grp in string] : { [rpc in string] : AnyFunction } } & Impl export type RPCInterfaceArray = { [grp in keyof Itfc]: Array< { [rpc in keyof Itfc[grp]]: RPC }[keyof Itfc[grp]] > } export type BaseInfo = { name: string, owner: string, argNames: string[], } export type HookInfo = BaseInfo & { type: 'Hook', generator: (socket?:I.Socket) => (...args:any[]) => SubresT } export type CallInfo = BaseInfo & { type: 'Call', call: AnyFunction } export type RpcInfo = HookInfo | CallInfo export type ExtendedRpcInfo = RpcInfo & { uniqueName: string } export type OnFunction = (type: T, f: FrontEndHandlerType[T]) => void export type HookCloseFunction = (res:SubscriptionResponse, rpc:HookRPC) => any