123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import * as I from "./Interfaces";
-
- export type Visibility = "127.0.0.1" | "0.0.0.0"
- export type Any = any
- export type Arg = string
- export type Name = Arg
- export type Owner = Name
- export type ConnectionHandler = (socket:I.Socket) => void
- export type ErrorHandler = (socket:I.Socket, error:any) => void
- export type CloseHandler = (socket:I.Socket) => void
- export type SocketConf = {
- connectionHandler?: ConnectionHandler
- errorHandler?: ErrorHandler
- closeHandler?: CloseHandler
- visibility?: Visibility
- }
-
- 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 HookRPC<T = {}> = {
- name: Name
- hook: HookFunction<T>
- onCallback?: CallbackFunction,
- onClose?: HookCloseFunction<T>
- }
-
- export type CallRPC = {
- name: Name
- call: AsyncFunction
- } | Function
-
- export type RPC<T = {}> = CallRPC | HookRPC<T>
-
- export type BaseInfo = {
- name: Name,
- owner: Name,
- argNames: Name[],
- }
-
- export type HookInfo<T = {}> = BaseInfo & {
- type: 'Hook',
- generator: (socket?:I.Socket) => HookFunction<T>
- }
-
- export type CallInfo = BaseInfo & {
- type: 'Call',
- call: AsyncFunction
- }
-
- export type RpcInfo = HookInfo | CallInfo
- export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
-
- export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
- export type HookCloseFunction<T = {}> = (res:SubscriptionResponse<T>, rpc:HookRPC<T>) => any
- export type HookFunction<T = {}> = (...args:any) => Promise<SubscriptionResponse<T> | ErrorResponse>
- export type AsyncFunction = (...args:any) => Promise<any>
- export type CallbackFunction = (...args:any) => void
|