| 1 | /** |
| 2 | * Generic HTTP request interface that abstracts Express and Fastify request objects |
| 3 | */ |
| 4 | export interface HttpRequest { |
| 5 | url?: string |
| 6 | method?: string |
| 7 | headers: Record<string, string | string[] | undefined> |
| 8 | query: Record<string, any> |
| 9 | body?: any |
| 10 | params?: Record<string, string> |
| 11 | /** |
| 12 | * Get a header value by name (case-insensitive) |
| 13 | */ |
| 14 | get?: (name: string) => string | undefined |
| 15 | /** |
| 16 | * Access to the raw framework-specific request object |
| 17 | */ |
| 18 | raw?: any |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Generic HTTP response interface that abstracts Express and Fastify response objects |
| 23 | */ |
| 24 | export interface HttpResponse { |
| 25 | /** |
| 26 | * Set the response status code |
| 27 | */ |
| 28 | status: (code: number) => this |
| 29 | |
| 30 | /** |
| 31 | * Send a JSON response |
| 32 | */ |
| 33 | json: (body: any) => this | void |
| 34 | |
| 35 | /** |
| 36 | * Send a text response |
| 37 | */ |
| 38 | send: (body: string) => this | void |
| 39 | |
| 40 | /** |
| 41 | * Write data to the response stream |
| 42 | */ |
| 43 | write: (chunk: any) => boolean | void |
| 44 | |
| 45 | /** |
| 46 | * Set a response header |
| 47 | */ |
| 48 | setHeader?: (name: string, value: string | string[]) => void |
| 49 | |
| 50 | /** |
| 51 | * Check if headers have been sent |
| 52 | */ |
| 53 | readonly headersSent?: boolean |
| 54 | |
| 55 | /** |
| 56 | * Check if the response is writable |
| 57 | */ |
| 58 | readonly writable?: boolean |
| 59 | |
| 60 | /** |
| 61 | * Check if the response is closed |
| 62 | */ |
| 63 | readonly closed?: boolean |
| 64 | |
| 65 | /** |
| 66 | * Listen for events |
| 67 | */ |
| 68 | on?: (event: string, listener: (...args: any[]) => void) => void |
| 69 | |
| 70 | /** |
| 71 | * Access to the raw framework-specific response object |
| 72 | */ |
| 73 | raw?: any |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * HTTP adapter interface for framework-specific implementations |
| 78 | */ |
| 79 | export interface HttpAdapter { |
| 80 | /** |
| 81 | * Adapt a framework-specific request to the generic HttpRequest interface |
| 82 | */ |
| 83 | adaptRequest: (req: any) => HttpRequest |
| 84 | |
| 85 | /** |
| 86 | * Adapt a framework-specific response to the generic HttpResponse interface |
| 87 | */ |
| 88 | adaptResponse: (res: any) => HttpResponse |
| 89 | } |
| 90 |