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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 ConnectionHandler = (socket:I.Socket) => void
  9. export type ErrorHandler = (socket:I.Socket) => (error:any) => void
  10. export type CloseHandler = (socket:I.Socket) => () => void
  11. export type SocketConf = {
  12. connectionHandler?: ConnectionHandler
  13. errorHandler?: ErrorHandler
  14. closeHandler?: CloseHandler
  15. visibility?: Visibility
  16. }
  17. export type RPCType = 'Hook' | 'Unhook' | 'Call'
  18. export type BaseRPC = {
  19. type: RPCType
  20. name: Name
  21. }
  22. export type HookRPC = BaseRPC & {
  23. type: 'Hook'
  24. hook: CallbackFunction
  25. unhook: UnhookFunction
  26. }
  27. export type UnhookRPC = BaseRPC & {
  28. type: 'Unhook'
  29. unhook: UnhookFunction
  30. }
  31. export type CallRPC = (BaseRPC & {
  32. type: 'Call'
  33. call: AsyncFunction
  34. } ) | Function
  35. export type RPC = CallRPC | UnhookRPC | HookRPC
  36. export type BaseInfo = {
  37. owner: Name,
  38. argNames: Name[],
  39. }
  40. export type HookInfo = BaseRPC & BaseInfo & {
  41. type: 'Hook',
  42. generator: (socket) => CallbackFunction
  43. unhook: UnhookFunction
  44. }
  45. export type UnhookInfo = BaseRPC & BaseInfo & {
  46. type: 'Unhook',
  47. unhook: UnhookFunction
  48. }
  49. export type CallInfo = BaseRPC & BaseInfo & {
  50. type: 'Call',
  51. call: AsyncFunction
  52. }
  53. export type RpcInfo = HookInfo | UnhookInfo | CallInfo
  54. export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
  55. export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
  56. export type UnhookFunction = (uid:string) => Promise<R.SuccessResponse | R.ErrorResponse>
  57. export type CallbackFunction = (...args) => Promise<R.SubscriptionResponse | R.ErrorResponse>
  58. export type AsyncFunction = (...args) => Promise<any>