1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import * as R from "./Responses";
- 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 RPCType = 'Hook' | 'Unhook' | 'Call'
-
- export type BaseRPC = {
- type: RPCType
- name: Name
- }
-
- export type HookRPC = BaseRPC & {
- type: 'Hook'
- hook: HookFunction
- onCallback?: CallbackFunction,
- onClose?: HookCloseFunction
- }
-
- export type CallRPC = (BaseRPC & {
- type: 'Call'
- call: AsyncFunction
- } ) | Function
-
- export type RPC = CallRPC | HookRPC
-
- export type BaseInfo = {
- owner: Name,
- argNames: Name[],
- }
-
- export type HookInfo = BaseRPC & BaseInfo & {
- type: 'Hook',
- generator: (socket) => HookFunction
- }
-
- export type CallInfo = BaseRPC & 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 = (res:R.SubscriptionResponse) => any
- export type HookFunction = (...args:any[]) => Promise<R.SubscriptionResponse | R.ErrorResponse>
- export type AsyncFunction = (...args:any[]) => Promise<any>
- export type CallbackFunction = (arg: any) => void
|