12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import * as I from "./Interfaces";
-
- export type AnyFunction = (...args:any) => any
- export type HookFunction<F extends AnyFunction = AnyFunction, SubresT = {}> = (...args: Parameters<F>) => Promise<SubscriptionResponse<SubresT> | 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> = T & { result: Outcome }
- export type SuccessResponse<T = {}> = Respose<T> & { result: "Success" }
- export type ErrorResponse<T = {}> = Respose<T> & { result: "Error", message?:string }
- export type SubscriptionResponse<T = {}> = Respose<T> & { result: "Success"; uuid: string }
-
- export type RPCType = 'Hook' | 'Unhook' | 'Call'
-
- export type CallRPC<N, F> = {
- name: N
- call: F
- }
-
- export type HookRPC<N, F extends AnyFunction, SubresT = {}> = {
- name: N
- hook: HookFunction<F, SubresT>
- onCallback?: AnyFunction
- onClose?: HookCloseFunction<SubresT>
- }
-
- export type RPC<N, F extends AnyFunction, SubresT = {}> = HookRPC<N, F, SubresT> | CallRPC<N,F> | F
-
- export type RPCInterface<Impl extends RPCInterface = {}> = {
- [grp in string] : {
- [rpc in string] : AnyFunction
- }
- } & Impl
-
- export type RPCInterfaceArray<Itfc extends RPCInterface, SubresT = {}> = {
- [grp in keyof Itfc]: Array<
- { [rpc in keyof Itfc[grp]]: RPC<rpc, Itfc[grp][rpc], SubresT> }[keyof Itfc[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:SubscriptionResponse<T>, rpc:HookRPC<any, any, T>) => any
|