Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Types.ts 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import * as I from "./Interfaces";
  2. export type AnyFunction = (...args:any) => any
  3. export type HookFunction<F extends AnyFunction = AnyFunction, SubresT = {}> = (...args: Parameters<F>) => Promise<SubscriptionResponse<SubresT> | ErrorResponse>
  4. export type Visibility = "127.0.0.1" | "0.0.0.0"
  5. export type ConnectionHandler = (socket:I.Socket) => void
  6. export type ErrorHandler = (socket:I.Socket, error:any) => void
  7. export type CloseHandler = (socket:I.Socket) => void
  8. export type SesameConf = {
  9. sesame?: string
  10. }
  11. export type ServerConf = {
  12. connectionHandler?: ConnectionHandler
  13. errorHandler?: ErrorHandler
  14. closeHandler?: CloseHandler
  15. visibility?: Visibility
  16. } & SesameConf
  17. export type SocketConf = {
  18. tls:boolean
  19. }
  20. export type ResponseType = "Subscribe" | "Success" | "Error"
  21. export type Outcome = "Success" | "Error"
  22. export type Respose<T> = T & { result: Outcome }
  23. export type SuccessResponse<T = {}> = Respose<T> & { result: "Success" }
  24. export type ErrorResponse<T = {}> = Respose<T> & { result: "Error", message?:string }
  25. export type SubscriptionResponse<T = {}> = Respose<T> & { result: "Success"; uuid: string }
  26. export type RPCType = 'Hook' | 'Unhook' | 'Call'
  27. export type CallRPC<N, F> = {
  28. name: N
  29. call: F
  30. }
  31. export type HookRPC<N, F extends AnyFunction, SubresT = {}> = {
  32. name: N
  33. hook: HookFunction<F, SubresT>
  34. onCallback?: AnyFunction
  35. onClose?: HookCloseFunction<SubresT>
  36. }
  37. export type RPC<N, F extends AnyFunction, SubresT = {}> = HookRPC<N, F, SubresT> | CallRPC<N,F> | F
  38. export type RPCInterface<Impl extends RPCInterface = {}> = {
  39. [grp in string] : {
  40. [rpc in string] : AnyFunction
  41. }
  42. } & Impl
  43. export type RPCInterfaceArray<Itfc extends RPCInterface, SubresT = {}> = {
  44. [grp in keyof Itfc]: Array<
  45. { [rpc in keyof Itfc[grp]]: RPC<rpc, Itfc[grp][rpc], SubresT> }[keyof Itfc[grp]]
  46. >
  47. }
  48. export type BaseInfo = {
  49. name: string,
  50. owner: string,
  51. argNames: string[],
  52. }
  53. export type HookInfo<SubresT = {}> = BaseInfo & {
  54. type: 'Hook',
  55. generator: (socket?:I.Socket) => (...args:any) => SubresT
  56. }
  57. export type CallInfo = BaseInfo & {
  58. type: 'Call',
  59. call: AnyFunction
  60. }
  61. export type RpcInfo = HookInfo | CallInfo
  62. export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
  63. export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
  64. export type HookCloseFunction<T = {}> = (res:SubscriptionResponse<T>, rpc:HookRPC<any, any, T>) => any