|
| 1 | +// Vendored and simplified from @types/hapi__hapi and @types/boom |
| 2 | +export interface Boom<Data = unknown> extends Error { |
| 3 | + isBoom: boolean; |
| 4 | + isServer: boolean; |
| 5 | + message: string; |
| 6 | + reformat: () => string; |
| 7 | + isMissing?: boolean | undefined; |
| 8 | + data: Data; |
| 9 | +} |
| 10 | + |
| 11 | +export interface RequestEvent { |
| 12 | + timestamp: string; |
| 13 | + tags: string[]; |
| 14 | + channel: 'internal' | 'app' | 'error'; |
| 15 | + data: object | string; |
| 16 | + error: object; |
| 17 | +} |
| 18 | + |
| 19 | +export interface Server<A = ServerApplicationState> { |
| 20 | + app: A; |
| 21 | + events: ServerEvents; |
| 22 | + ext(event: ServerExtType, method: LifecycleMethod, options?: unknown | undefined): void; |
| 23 | + initialize(): Promise<void>; |
| 24 | + register<T, D>(plugins: Plugin<T>, options?: unknown | undefined): Promise<this & D>; |
| 25 | + start(): Promise<void>; |
| 26 | +} |
| 27 | + |
| 28 | +export interface ResponseObject { |
| 29 | + statusCode: number; |
| 30 | + header: (key: string, value: string) => void; |
| 31 | +} |
| 32 | + |
| 33 | +type RequestEventHandler = (request: Request, event: RequestEvent, tags: { [key: string]: true }) => void; |
| 34 | +type LifecycleMethod = (request: Request, h: ResponseToolkit, err?: Error | undefined) => unknown; |
| 35 | +type Plugin<T> = PluginBase<T> & (PluginNameVersion | PluginPackage); |
| 36 | +type ServerExtType = |
| 37 | + | 'onPreStart' |
| 38 | + | 'onPostStart' |
| 39 | + | 'onPreStop' |
| 40 | + | 'onPostStop' |
| 41 | + | 'onPreAuth' |
| 42 | + | 'onCredentials' |
| 43 | + | 'onPostAuth' |
| 44 | + | 'onPreHandler' |
| 45 | + | 'onPostHandler' |
| 46 | + | 'onPreResponse' |
| 47 | + | 'onPostResponse'; |
| 48 | + |
| 49 | +// eslint-disable-next-line @typescript-eslint/no-empty-interface |
| 50 | +interface ServerApplicationState {} |
| 51 | +// eslint-disable-next-line @typescript-eslint/no-empty-interface |
| 52 | +interface RequestEvents {} |
| 53 | + |
| 54 | +interface ServerEvents { |
| 55 | + on(criteria: 'request', listener: RequestEventHandler): this; |
| 56 | +} |
| 57 | + |
| 58 | +interface PluginBase<T> { |
| 59 | + register: (server: Server, options: T) => void | Promise<void>; |
| 60 | +} |
| 61 | + |
| 62 | +interface PluginPackage { |
| 63 | + pkg: PluginNameVersion; |
| 64 | +} |
| 65 | + |
| 66 | +interface ResponseToolkit { |
| 67 | + readonly continue: symbol; |
| 68 | +} |
| 69 | + |
| 70 | +interface PluginNameVersion { |
| 71 | + name: string; |
| 72 | + version?: string | undefined; |
| 73 | +} |
| 74 | + |
| 75 | +interface Request { |
| 76 | + events: RequestEvents; |
| 77 | + response: ResponseObject | Boom; |
| 78 | + headers: Record<string, string>; |
| 79 | + path: string; |
| 80 | + route: { |
| 81 | + path: string; |
| 82 | + }; |
| 83 | +} |
0 commit comments