You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Types.ts 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import * as I from "./Interfaces";
  2. export type Visibility = "127.0.0.1" | "0.0.0.0"
  3. export type Any = any
  4. export type Arg = string
  5. export type Name = Arg
  6. export type Owner = Name
  7. export type ConnectionHandler = (socket:I.Socket) => void
  8. export type ErrorHandler = (socket:I.Socket, error:any) => void
  9. export type CloseHandler = (socket:I.Socket) => void
  10. export type SocketConf = {
  11. connectionHandler?: ConnectionHandler
  12. errorHandler?: ErrorHandler
  13. closeHandler?: CloseHandler
  14. visibility?: Visibility
  15. }
  16. export type ResponseType = "Subscribe" | "Success" | "Error"
  17. export type Outcome = "Success" | "Error"
  18. export type Respose<T> = T & { result: Outcome }
  19. export type SuccessResponse<T = {}> = Respose<T> & { result: "Success" }
  20. export type ErrorResponse<T = {}> = Respose<T> & { result: "Error", message?:string }
  21. export type SubscriptionResponse<T = {}> = Respose<T> & { result: "Success"; uuid: string }
  22. export type RPCType = 'Hook' | 'Unhook' | 'Call'
  23. export type HookRPC<T = {}> = {
  24. name: Name
  25. hook: HookFunction<T>
  26. onCallback?: CallbackFunction,
  27. onClose?: HookCloseFunction<T>
  28. }
  29. export type CallRPC = {
  30. name: Name
  31. call: AsyncFunction
  32. } | Function
  33. export type RPC<T = {}> = CallRPC | HookRPC<T>
  34. export type BaseInfo = {
  35. name: Name,
  36. owner: Name,
  37. argNames: Name[],
  38. }
  39. export type HookInfo<T = {}> = BaseInfo & {
  40. type: 'Hook',
  41. generator: (socket?:I.Socket) => HookFunction<T>
  42. }
  43. export type CallInfo = BaseInfo & {
  44. type: 'Call',
  45. call: AsyncFunction
  46. }
  47. export type RpcInfo = HookInfo | CallInfo
  48. export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
  49. export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
  50. export type HookCloseFunction<T = {}> = (res:SubscriptionResponse<T>, rpc:HookRPC<T>) => any
  51. export type HookFunction<T = {}> = (...args:any) => Promise<SubscriptionResponse<T> | ErrorResponse>
  52. export type AsyncFunction = (...args:any) => Promise<any>
  53. export type CallbackFunction = (...args:any) => void