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 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import * as R from "./Responses";
  2. import * as I from "./Interfaces";
  3. export type Visibility = "127.0.0.1" | "0.0.0.0"
  4. export type Any = any
  5. export type Arg = string
  6. export type Name = Arg
  7. export type Owner = Name
  8. export type SocketConf = {
  9. connectionHandler: (socket:I.Socket) => void
  10. errorHandler: (socket:I.Socket) => (error:any) => void
  11. closeHandler: (socket:I.Socket) => () => void
  12. visibility: Visibility
  13. }
  14. export type RPCType = 'Hook' | 'Unhook' | 'Call'
  15. export type BaseRPC = {
  16. type: RPCType
  17. name: Name
  18. }
  19. export type HookRPC = BaseRPC & {
  20. type: 'Hook'
  21. clbk: CallbackFunction
  22. unhook: UnhookFunction
  23. }
  24. export type UnhookRPC = BaseRPC & {
  25. type: 'Unhook'
  26. unhook: UnhookFunction
  27. }
  28. export type CallRPC = BaseRPC & {
  29. type: 'Call'
  30. call: AsyncFunction
  31. }
  32. export type RPC = CallRPC | UnhookRPC | HookRPC
  33. export type BaseInfo = {
  34. owner: Name,
  35. argNames: Name[],
  36. }
  37. export type HookInfo = BaseRPC & BaseInfo & {
  38. type: 'Hook',
  39. generator: (socket) => CallbackFunction
  40. unhook: UnhookFunction
  41. }
  42. export type UnhookInfo = BaseRPC & BaseInfo & {
  43. type: 'Unhook',
  44. unhook: UnhookFunction
  45. }
  46. export type CallInfo = BaseRPC & BaseInfo & {
  47. type: 'Call',
  48. call: AsyncFunction
  49. }
  50. export type RpcInfo = HookInfo | UnhookInfo | CallInfo
  51. export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
  52. export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
  53. export type UnhookFunction = (uid:string) => Promise<R.SuccessResponse | R.ErrorResponse>
  54. export type CallbackFunction = (...args) => Promise<R.SubscriptionResponse | R.ErrorResponse>
  55. export type AsyncFunction = (...args) => Promise<any>