import * as I from "./Interfaces"; import { RPCSocket } from "./Frontend"; import { ManagerOptions, SocketOptions } from 'socket.io-client' export type PioBindListener = (...args: any) => void export type PioHookListener = GenericFunction export type GenericFunction = {(...args: Parameters): Result} export type BackendHook = GenericFunction< [ GenericFunction< Parameters< AsFunction< Parameters[0] > >, void >, ...Tail> ], ReturnType > 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, 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 ClientConfig = Partial & { protocol?: 'http' | 'https', callTimeoutMs?: number } export type SomeOf = { [key in keyof T]?: T[key] } export type ExporterArray = I.RPCExporter, keyof InterfaceT>[] export type ConnectedSocket = RPCSocket & AsyncIfc export type ServerConf = { accessFilter?: AccessFilter connectionHandler?: ConnectionHandler errorHandler?: ErrorHandler closeHandler?: CloseHandler throwOnUnknownRPC?: boolean } & SesameConf 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: BackendHook onCallback?: GenericFunction onDestroy?: HookCloseFunction extends Promise ? T : ReturnType> } export type RPC = HookRPC | CallRPC | Func export type RPCInterface = { [grp in string]: { [rpc in string]: GenericFunction } } & Impl export type exportT = { [group in string]: {} } 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: GenericFunction } 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]]: AsyncGenericFunction } } export type AsyncGenericFunction = F extends (...args: Parameters) => infer R ? ((...args: Parameters) => R extends Promise ? R : Promise) : Promise type Destroyable = { destroy: () => void } export type Callback = (this: Destroyable, ...args: Params) => void type AsFunction = F extends GenericFunction ? F : GenericFunction type Last = Tuple[ Subtract, 1> ] type Tail = T extends [any, ...infer R] ? R : any[] type Length = T extends { length: infer L } ? L : never; type BuildTuple = T extends { length: L } ? T : BuildTuple; type Subtract = BuildTuple extends [...(infer U), ...BuildTuple] ? Length : never;