|
3 | 3 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
4 | 4 | import { Schema } from 'zod'; |
5 | 5 |
|
| 6 | +/** |
| 7 | + * Function that is called when the route handler is executed and all the middleware has been executed |
| 8 | + * @param request - The request object |
| 9 | + * @param context - The context object |
| 10 | + * @returns The response from the route handler |
| 11 | + */ |
6 | 12 | export type HandlerFunction<TParams, TQuery, TBody, TContext, TMetadata = unknown> = ( |
7 | 13 | request: Request, |
8 | 14 | context: { params: TParams; query: TQuery; body: TBody; ctx: TContext; metadata?: TMetadata }, |
@@ -54,12 +60,27 @@ export type MiddlewareFunction< |
54 | 60 | // This context is not really used and not really needed |
55 | 61 | export type MiddlewareResult<TContext> = Response & { ctx?: TContext }; |
56 | 62 |
|
| 63 | +/** |
| 64 | + * Configuration object for the RouteHandlerBuilder |
| 65 | + * @param paramsSchema - Schema for the route parameters |
| 66 | + * @param querySchema - Schema for the route query parameters |
| 67 | + * @param bodySchema - Schema for the route body |
| 68 | + */ |
57 | 69 | export interface RouteHandlerBuilderConfig { |
58 | 70 | paramsSchema: Schema; |
59 | 71 | querySchema: Schema; |
60 | 72 | bodySchema: Schema; |
61 | 73 | } |
62 | 74 |
|
| 75 | +/** |
| 76 | + * Original Next.js route handler type for reference |
| 77 | + * This is the type that Next.js uses internally before our library wraps it |
| 78 | + */ |
63 | 79 | export type OriginalRouteHandler = (request: Request, context: { params: Promise<Record<string, unknown>> }) => any; |
64 | 80 |
|
| 81 | +/** |
| 82 | + * Function that handles server errors in route handlers |
| 83 | + * @param error - The error that was thrown |
| 84 | + * @returns Response object with appropriate error details and status code |
| 85 | + */ |
65 | 86 | export type HandlerServerErrorFn = (error: Error) => Response; |
0 commit comments