Skip to content

Commit 8fce7c1

Browse files
committed
docs: Enhance type definitions with detailed JSDoc comments
- Added JSDoc comments for `HandlerFunction`, `RouteHandlerBuilderConfig`, and `HandlerServerErrorFn` to improve code documentation and clarity.
1 parent 7133df1 commit 8fce7c1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
/* eslint-disable @typescript-eslint/no-explicit-any */
44
import { Schema } from 'zod';
55

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+
*/
612
export type HandlerFunction<TParams, TQuery, TBody, TContext, TMetadata = unknown> = (
713
request: Request,
814
context: { params: TParams; query: TQuery; body: TBody; ctx: TContext; metadata?: TMetadata },
@@ -54,12 +60,27 @@ export type MiddlewareFunction<
5460
// This context is not really used and not really needed
5561
export type MiddlewareResult<TContext> = Response & { ctx?: TContext };
5662

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+
*/
5769
export interface RouteHandlerBuilderConfig {
5870
paramsSchema: Schema;
5971
querySchema: Schema;
6072
bodySchema: Schema;
6173
}
6274

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+
*/
6379
export type OriginalRouteHandler = (request: Request, context: { params: Promise<Record<string, unknown>> }) => any;
6480

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+
*/
6586
export type HandlerServerErrorFn = (error: Error) => Response;

0 commit comments

Comments
 (0)