12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import * as I from "./Interfaces";
- import { RPCSocket } from "./Frontend";
-
- export type AnyFunction = (...args:any) => any
- export type HookFunction = AnyFunction
- export type AccessFilter<InterfaceT extends RPCInterface = RPCInterface> = (sesame:string|undefined, exporter: I.RPCExporter<InterfaceT, keyof InterfaceT>) => 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 ExceptionHandling = 'local' | 'remote'
- export type SesameConf = {
- sesame?: string | SesameFunction
- }
- export type FrontEndHandlerType = {
- 'error' : (e: any) => void
- 'close' : () => void
- }
-
- export type ExporterArray<InterfaceT extends RPCInterface = RPCInterface> = I.RPCExporter<RPCInterface<InterfaceT>, keyof InterfaceT>[]
-
- export type ConnectedSocket<T extends RPCInterface = RPCInterface> = RPCSocket & T
-
- export type ServerConf<InterfaceT extends RPCInterface> = {
- accessFilter?: AccessFilter<InterfaceT>
- 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> = T & { result: Outcome }
- export type SuccessResponse<T = {}> = Respose<T> & { result: "Success" }
- export type ErrorResponse<T = {}> = Respose<T> & { result: "Error", message?:string }
-
- export type RPCType = 'Hook' | 'Unhook' | 'Call'
-
- export type CallRPC<Name, Func extends AnyFunction> = {
- name: Name
- call: Func
- }
-
-
- export type HookRPC<Name, Func extends AnyFunction> = {
- name: Name
- hook: Func
- onCallback?: AnyFunction
- onClose?: HookCloseFunction<ReturnType<Func> extends Promise<infer T> ? T : ReturnType<Func>>
- }
-
- export type RPC<Name, Func extends AnyFunction> = HookRPC<Name, Func> | CallRPC<Name,Func> | Func
-
- export type RPCInterface<Impl extends RPCInterface = {}> = {
- [grp in string] : {
- [rpc in string] : AnyFunction
- }
- } & Impl
-
- export type exportT = {
- [group in string]: {}
- }
-
- //This probably has lots of issues
- export type RPCDefinitions<Ifc extends RPCInterface> = {
- [grp in keyof Ifc]:( { [rpc in keyof Ifc[grp]]: RPC<rpc, Ifc[grp][rpc]> }[keyof Ifc[grp]] )[]
- }
-
- export type BaseInfo = {
- name: string,
- owner: string,
- argNames: string[],
- }
-
- export type HookInfo<SubresT = {}> = 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 = <T extends "error" | "close">(type: T, f: FrontEndHandlerType[T]) => void
- export type HookCloseFunction<T> = (res: T, rpc:HookRPC<any, any>) => any
|