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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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: HookFunction
  25. onCallback?: CallbackFunction,
  26. onClose?: HookCloseFunction
  27. }
  28. export type CallRPC = (BaseRPC & {
  29. type: 'Call'
  30. call: AsyncFunction
  31. } ) | Function
  32. export type RPC = CallRPC | HookRPC
  33. export type BaseInfo = {
  34. owner: Name,
  35. argNames: Name[],
  36. }
  37. export type HookInfo = BaseRPC & BaseInfo & {
  38. type: 'Hook',
  39. generator: (socket) => HookFunction
  40. }
  41. export type CallInfo = BaseRPC & BaseInfo & {
  42. type: 'Call',
  43. call: AsyncFunction
  44. }
  45. export type RpcInfo = HookInfo | CallInfo
  46. export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
  47. export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
  48. export type HookCloseFunction = (res:R.SubscriptionResponse) => any
  49. export type HookFunction = (...args:any[]) => Promise<R.SubscriptionResponse | R.ErrorResponse>
  50. export type AsyncFunction = (...args:any[]) => Promise<any>
  51. export type CallbackFunction = (arg: any) => void