import type { Context } from 'cordis'; import type { ApiHandler } from './api'; import type { ConnectionHandler, Handler, NotFoundHandler } from './server'; export interface KnownHandlers { NotFound: NotFoundHandler; } type MapHandlerEvents> = Record<`handler/${HookType}/${N}`, (thisArg: H) => VoidReturn> & Record<`handler/${HookWithMethod}/${N}/${Methods}`, (thisArg: H) => VoidReturn>; type KnownHandlerEvents = { [key in keyof KnownHandlers]: MapHandlerEvents }[keyof KnownHandlers]; type HandlerEvents = Record<`handler/${HookType}`, (thisArg: Handler) => VoidReturn> & Record<`connection/${'create' | 'active' | 'close'}`, (thisArg: any) => VoidReturn>; export type VoidReturn = Promise | any; export type HookType = 'before-prepare' | 'before' | 'before-operation' | 'after' | 'finish'; export type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch'; export type HookWithMethod = Exclude; export interface ServerEvents extends KnownHandlerEvents, HandlerEvents { 'handler/create': (thisArg: Handler | ConnectionHandler, type: 'ws' | 'http') => VoidReturn; 'handler/create/http': (thisArg: Handler) => VoidReturn; 'handler/create/ws': (thisArg: ConnectionHandler) => VoidReturn; 'handler/init': (thisArg: Handler) => VoidReturn; 'handler/error': (thisArg: Handler | ConnectionHandler, e: Error) => VoidReturn; 'handler/api/before': (thisArg: ApiHandler) => VoidReturn; 'api/before': (args: any) => VoidReturn; [k: `handler/${HookType}/${string}`]: (thisArg: any) => VoidReturn; [k: `handler/${HookWithMethod}/${string}/${Methods}`]: (thisArg: any) => VoidReturn; [k: `handler/register/${string}`]: (HandlerClass: new (...args: any[]) => any) => VoidReturn; [k: `handler/error/${string}`]: (thisArg: Handler, e: Error) => VoidReturn; [k: `handler/api/before/${string}`]: (thisArg: ApiHandler) => VoidReturn; [k: `api/before/${string}`]: (args: any) => VoidReturn; } declare module 'cordis' { interface Events extends ServerEvents { } }