選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Types.ts 2.5KB

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