import * as I from "./Interfaces"; import { RPCSocket } from "./Frontend"; import { PromiseIO } from "./PromiseIO/Server"; export type PioBindListener = (...args: any) => void export type PioHookListener = AnyFunction export type AnyFunction = (...args:any) => any export type HookFunction = AnyFunction export type AccessFilter = (sesame:string|undefined, exporter: I.RPCExporter) => Promise | boolean export type Visibility = "127.0.0.1" | "0.0.0.0" export type ConnectionHandler = (socket:I.Socket) => void export type ErrorHandler = (socket:I.Socket | PromiseIO, error:any, rpcName: string, args: any[]) => void export type CloseHandler = (socket:I.Socket) => void export type SesameFunction = (sesame : string) => boolean export type SesameConf = { sesame?: string | SesameFunction } export type FrontEndHandlerType = { 'error' : (e: any) => void 'close' : () => void } export type ExporterArray = I.RPCExporter, keyof InterfaceT>[] export type ConnectedSocket = RPCSocket & AsyncIfc export type ServerConf = { accessFilter?: AccessFilter connectionHandler?: ConnectionHandler errorHandler?: ErrorHandler closeHandler?: CloseHandler } & 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 RPCType = 'Hook' | 'Unhook' | 'Call' export type CallRPC = { name: Name call: Func } export type HookRPC = { name: Name hook: Func onCallback?: AnyFunction onClose?: HookCloseFunction extends Promise ? T : ReturnType> } export type RPC = HookRPC | CallRPC | Func export type RPCInterface = { [grp in string] : { [rpc in string] : AnyFunction } } & Impl export type exportT = { [group in string]: {} } //This probably has lots of issues export type RPCDefinitions = { [grp in keyof Ifc]:( { [rpc in keyof Ifc[grp]]: RPC }[keyof Ifc[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: T, rpc:HookRPC) => any export type AsyncIfc = { [grp in keyof Ifc]: {[rpcname in keyof Ifc[grp]] : AsyncAnyFunction } } export type AsyncAnyFunction = F extends (...args: Parameters) => infer R ? ((...args: Parameters) => R extends Promise ? R : Promise ) : Promise