balda 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.cts CHANGED
@@ -54,6 +54,10 @@ interface ValidationOptions {
54
54
  * The schema to validate the query parameters against (Zod, TypeBox, or plain JSON schema)
55
55
  */
56
56
  query?: RequestSchema;
57
+ /**
58
+ * The schema to validate the request headers against (Zod, TypeBox, or plain JSON schema)
59
+ */
60
+ headers?: RequestSchema;
57
61
  /**
58
62
  * The schema to validate both body and query against (Zod, TypeBox, or plain JSON schema)
59
63
  */
@@ -93,6 +97,12 @@ type InferBodyType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
93
97
  * Infers the typed query from a schema. Returns `Record<string, string>` if no schema is provided.
94
98
  */
95
99
  type InferQueryType<T> = T extends RequestSchema ? ValidatedData<T> : Record<string, string>;
100
+ /**
101
+ * Infers the typed headers from a schema.
102
+ * Returns `Record<string, string | string[]>` if no schema is provided
103
+ * (supporting multi-value headers).
104
+ */
105
+ type InferHeadersType<T> = T extends RequestSchema ? ValidatedData<T> : Record<string, string | string[]>;
96
106
  /**
97
107
  * Extracts the body type for a specific HTTP status code from a response map.
98
108
  * When the status code has a schema defined, enforces type matching with widened
@@ -180,8 +190,9 @@ type FilePluginOptions = {
180
190
  * @template Params - The path parameters type (automatically extracted from route)
181
191
  * @template TBody - The typed body (inferred from body schema when provided)
182
192
  * @template TQuery - The typed query (inferred from query schema when provided)
193
+ * @template THeaders - The typed headers (inferred from headers schema when provided)
183
194
  */
184
- declare class Request<Params extends Record<string, string> = any, TBody = unknown, TQuery extends Record<string, any> = Record<string, string>> {
195
+ declare class Request<Params extends Record<string, string> = Record<string, string>, TBody = unknown, TQuery extends Record<string, any> = Record<string, string>, THeaders extends Record<string, any> = Record<string, string | string[]>> {
185
196
  #private;
186
197
  /**
187
198
  * Creates a new request object from a Web API Request object.
@@ -228,10 +239,17 @@ declare class Request<Params extends Record<string, string> = any, TBody = unkno
228
239
  */
229
240
  method: string;
230
241
  /**
231
- * The headers of the request lazily constructed from raw Node.js headers.
242
+ * Raw Headers API object for low-level access.
243
+ * Use this for case-insensitive lookups, iteration, etc.
232
244
  */
233
- get headers(): globalThis.Headers;
234
- set headers(value: globalThis.Headers);
245
+ get rawHeaders(): globalThis.Headers;
246
+ /**
247
+ * The typed headers of the request.
248
+ * After validation with a headers schema, this contains the validated/typed header values.
249
+ * For raw Headers API access, use `rawHeaders`.
250
+ */
251
+ get headers(): THeaders;
252
+ set headers(value: THeaders);
235
253
  /**
236
254
  * The signal for aborting the request
237
255
  */
@@ -449,6 +467,12 @@ declare class Request<Params extends Record<string, string> = any, TBody = unkno
449
467
  * @param throwErrorOnValidationFail - If true, throws ValidationError on validation failure. If false, returns the original data.
450
468
  */
451
469
  validateAll<T extends RequestSchema>(inputSchema: T, throwErrorOnValidationFail?: boolean): ValidatedData<T>;
470
+ /**
471
+ * Validates the headers of the request.
472
+ * @param inputSchema - The schema to validate the headers against (Zod schema, TypeBox, or JSON Schema).
473
+ * @param throwErrorOnValidationFail - If true, throws ValidationError on validation failure. If false, returns the original headers.
474
+ */
475
+ validateHeaders<T extends RequestSchema>(inputSchema: T, throwErrorOnValidationFail?: boolean): ValidatedData<T>;
452
476
  /**
453
477
  * Sets a lazy IP extractor function.
454
478
  * IP will only be extracted when `.ip` is first accessed.
@@ -850,9 +874,11 @@ type HTMLString = string;
850
874
  */
851
875
  type CustomUIGenerator = (specUrl: string, globalOptions: SwaggerGlobalOptions) => HTMLString;
852
876
  /**
853
- * Type of request body for a route
877
+ * Type of request body for a route.
878
+ * Common MIME types are provided as literals withintellisense,
879
+ * custom MIME types can be specified as strings.
854
880
  */
855
- type SwaggerBodyType = "json" | "form-data" | "urlencoded";
881
+ type SwaggerBodyType = "json" | "form-data" | "urlencoded" | "binary" | "text" | "event-stream" | (string & {});
856
882
  /**
857
883
  * JSONSchema type for OpenAPI/AJV-compatible schemas
858
884
  */
@@ -939,17 +965,24 @@ type SwaggerGlobalOptions = (SwaggerGlobalOptionsBase & {
939
965
  customUIGenerator: CustomUIGenerator;
940
966
  });
941
967
  /**
942
- * Route-specific documentation options (for individual endpoints)
968
+ * Route-specific documentation options for OpenAPI/Swagger generation.
969
+ *
970
+ * These options are for DOCUMENTATION PURPOSES ONLY and are NOT validated or enforced at runtime.
971
+ * For validated schemas, use the route-level `body`, `query`, and `responses` options.
972
+ *
973
+ * @example
974
+ * // Document route with custom body type
975
+ * router.get("/download", { swagger: { bodyType: "binary" } }, handler);
976
+ *
977
+ * @example
978
+ * // Document authentication requirements
979
+ * router.get("/protected", { swagger: { security: { type: "bearer" } } }, handler);
943
980
  */
944
981
  type SwaggerRouteOptions = {
945
982
  /** Service category where the route belongs to */
946
983
  service?: string;
947
984
  /** Name of the route */
948
985
  name?: string;
949
- /** Responses for this route (used by decorators) */
950
- responses?: Record<number, RequestSchema>;
951
- /** Errors for this route */
952
- errors?: Record<number, RequestSchema>;
953
986
  /** Security requirements for this route */
954
987
  security?: Security[] | Security;
955
988
  /** Description of the route */
@@ -959,7 +992,10 @@ type SwaggerRouteOptions = {
959
992
  /** Exclude from swagger */
960
993
  excludeFromSwagger?: boolean;
961
994
  /**
962
- * The request body type for this route. Allowed values: 'json', 'form-data', 'urlencoded'. Defaults to 'json'.
995
+ * The request body type for documentation purposes.
996
+ * Common types: 'json', 'form-data', 'urlencoded', 'binary', 'text', 'event-stream'.
997
+ * Custom MIME types can be specified as strings (e.g., 'application/vnd.api+json').
998
+ * Defaults to 'json'.
963
999
  */
964
1000
  bodyType?: SwaggerBodyType;
965
1001
  };
@@ -1021,6 +1057,7 @@ type OpenIdConnectOptions = {
1021
1057
  /**
1022
1058
  * Decorator to mark a class as a controller, routes defined in the controller will be registered at import time when calling the `listen` method.
1023
1059
  * You can customize the path pattern for controller imports in the server options `controllerPatterns`
1060
+ * @deprecated This decorator is deprecated and class based controllers won't be supported in the future. Please use the `router` directly to define your routes in a functional way for better type-safety.
1024
1061
  * @param path - The path pattern for the controller.
1025
1062
  * @param swaggerOptions - The swagger options for the controller that will be applied to all routes defined in the controller. Controller options will override route options.
1026
1063
  * @swagger If swagger is enabled, the default service name for all routes defined in the controller will be the controller name.
@@ -1672,20 +1709,20 @@ type InferMiddlewareExtensions<T extends readonly any[]> = T extends readonly [i
1672
1709
  * ```
1673
1710
  */
1674
1711
  interface GroupRouter<TGroupExt extends Record<string, any> = Record<string, never>> {
1675
- get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1676
- get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1677
- post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1678
- post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1679
- patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1680
- patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1681
- put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1682
- put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1683
- delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1684
- delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1685
- options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1686
- options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1687
- head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1688
- head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1712
+ get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1713
+ get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1714
+ post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1715
+ post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1716
+ patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1717
+ patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1718
+ put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1719
+ put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1720
+ delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1721
+ delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1722
+ options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1723
+ options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1724
+ head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1725
+ head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1689
1726
  group<const TMiddlewares extends readonly (ServerRouteMiddleware | TypedMiddleware<any>)[] = readonly (ServerRouteMiddleware | TypedMiddleware<any>)[]>(path: string, middleware: TMiddlewares, cb: (router: GroupRouter<TGroupExt & InferMiddlewareExtensions<TMiddlewares>>) => void): void;
1690
1727
  group(path: string, cb: (router: GroupRouter<TGroupExt>) => void): void;
1691
1728
  }
@@ -1717,6 +1754,7 @@ declare class Router {
1717
1754
  addOrUpdate(method: HttpMethod, path: string, middleware: (ServerRouteMiddleware | TypedMiddleware<any>)[], handler: ServerRouteHandler, validationSchemas?: {
1718
1755
  body?: RequestSchema;
1719
1756
  query?: RequestSchema;
1757
+ headers?: RequestSchema;
1720
1758
  all?: RequestSchema;
1721
1759
  }, swaggerOptions?: SwaggerRouteOptions, responses?: Record<number, RequestSchema>, allowUpdate?: boolean): void;
1722
1760
  /**
@@ -1740,37 +1778,37 @@ declare class Router {
1740
1778
  * Register a GET route under this router's base path with type-safe path parameters.
1741
1779
  */
1742
1780
  get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1743
- get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1781
+ get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1744
1782
  /**
1745
1783
  * Register a POST route under this router's base path with type-safe path parameters.
1746
1784
  */
1747
1785
  post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1748
- post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1786
+ post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1749
1787
  /**
1750
1788
  * Register a PATCH route under this router's base path with type-safe path parameters.
1751
1789
  */
1752
1790
  patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1753
- patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1791
+ patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1754
1792
  /**
1755
1793
  * Register a PUT route under this router's base path with type-safe path parameters.
1756
1794
  */
1757
1795
  put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1758
- put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1796
+ put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1759
1797
  /**
1760
1798
  * Register a DELETE route under this router's base path with type-safe path parameters.
1761
1799
  */
1762
1800
  delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1763
- delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1801
+ delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1764
1802
  /**
1765
1803
  * Register an OPTIONS route under this router's base path with type-safe path parameters.
1766
1804
  */
1767
1805
  options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1768
- options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1806
+ options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1769
1807
  /**
1770
1808
  * Register an HEAD route under this router's base path with type-safe path parameters.
1771
1809
  */
1772
1810
  head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1773
- head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1811
+ head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1774
1812
  /**
1775
1813
  * Create a grouped router that shares a base path and middlewares.
1776
1814
  * The callback receives a typed child router where routes are defined; routes
@@ -1817,12 +1855,13 @@ interface Route {
1817
1855
  */
1818
1856
  responseSchemas?: RouteResponseSchemas;
1819
1857
  /**
1820
- * Validation schemas for request body, query parameters, or both.
1858
+ * Validation schemas for request body, query parameters, headers, or all.
1821
1859
  * When provided, the handler will receive validated data as additional parameters.
1822
1860
  */
1823
1861
  validationSchemas?: {
1824
1862
  body?: RequestSchema;
1825
1863
  query?: RequestSchema;
1864
+ headers?: RequestSchema;
1826
1865
  all?: RequestSchema;
1827
1866
  };
1828
1867
  }
@@ -2779,10 +2818,11 @@ interface ServerInterface {
2779
2818
  */
2780
2819
  exit: (code?: number) => void;
2781
2820
  }
2782
- type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TPath extends string = string, TAll extends RequestSchema | unknown = unknown, TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]> = {
2821
+ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, THeaders extends RequestSchema | unknown = unknown, TPath extends string = string, TAll extends RequestSchema | unknown = unknown, TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]> = {
2783
2822
  middlewares?: TMiddlewares | TypedMiddleware<any>;
2784
2823
  body?: TBody;
2785
2824
  query?: TQuery;
2825
+ headers?: THeaders;
2786
2826
  all?: TAll;
2787
2827
  responses?: TResponses;
2788
2828
  swagger?: SwaggerRouteOptions;
@@ -2793,7 +2833,7 @@ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Re
2793
2833
  };
2794
2834
  type ServerHook = () => SyncOrAsync;
2795
2835
  type SignalEvent = Deno.Signal | NodeJS.Signals;
2796
- type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown, TMiddlewareExt extends Record<string, any> = Record<string, never>> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown>> & TMiddlewareExt, res: Response$1<InferResponseMap<TResponses>>) => ServerHandlerReturnType<InferResponseMap<TResponses>>;
2836
+ type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, THeaders extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown, TMiddlewareExt extends Record<string, any> = Record<string, never>> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown>, THeaders extends RequestSchema ? InferHeadersType<THeaders> : Record<string, string | string[]>> & TMiddlewareExt, res: Response$1<InferResponseMap<TResponses>>) => ServerHandlerReturnType<InferResponseMap<TResponses>>;
2797
2837
 
2798
2838
  type RunTimeType = "bun" | "node" | "deno";
2799
2839
 
package/lib/index.d.ts CHANGED
@@ -54,6 +54,10 @@ interface ValidationOptions {
54
54
  * The schema to validate the query parameters against (Zod, TypeBox, or plain JSON schema)
55
55
  */
56
56
  query?: RequestSchema;
57
+ /**
58
+ * The schema to validate the request headers against (Zod, TypeBox, or plain JSON schema)
59
+ */
60
+ headers?: RequestSchema;
57
61
  /**
58
62
  * The schema to validate both body and query against (Zod, TypeBox, or plain JSON schema)
59
63
  */
@@ -93,6 +97,12 @@ type InferBodyType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
93
97
  * Infers the typed query from a schema. Returns `Record<string, string>` if no schema is provided.
94
98
  */
95
99
  type InferQueryType<T> = T extends RequestSchema ? ValidatedData<T> : Record<string, string>;
100
+ /**
101
+ * Infers the typed headers from a schema.
102
+ * Returns `Record<string, string | string[]>` if no schema is provided
103
+ * (supporting multi-value headers).
104
+ */
105
+ type InferHeadersType<T> = T extends RequestSchema ? ValidatedData<T> : Record<string, string | string[]>;
96
106
  /**
97
107
  * Extracts the body type for a specific HTTP status code from a response map.
98
108
  * When the status code has a schema defined, enforces type matching with widened
@@ -180,8 +190,9 @@ type FilePluginOptions = {
180
190
  * @template Params - The path parameters type (automatically extracted from route)
181
191
  * @template TBody - The typed body (inferred from body schema when provided)
182
192
  * @template TQuery - The typed query (inferred from query schema when provided)
193
+ * @template THeaders - The typed headers (inferred from headers schema when provided)
183
194
  */
184
- declare class Request<Params extends Record<string, string> = any, TBody = unknown, TQuery extends Record<string, any> = Record<string, string>> {
195
+ declare class Request<Params extends Record<string, string> = Record<string, string>, TBody = unknown, TQuery extends Record<string, any> = Record<string, string>, THeaders extends Record<string, any> = Record<string, string | string[]>> {
185
196
  #private;
186
197
  /**
187
198
  * Creates a new request object from a Web API Request object.
@@ -228,10 +239,17 @@ declare class Request<Params extends Record<string, string> = any, TBody = unkno
228
239
  */
229
240
  method: string;
230
241
  /**
231
- * The headers of the request lazily constructed from raw Node.js headers.
242
+ * Raw Headers API object for low-level access.
243
+ * Use this for case-insensitive lookups, iteration, etc.
232
244
  */
233
- get headers(): globalThis.Headers;
234
- set headers(value: globalThis.Headers);
245
+ get rawHeaders(): globalThis.Headers;
246
+ /**
247
+ * The typed headers of the request.
248
+ * After validation with a headers schema, this contains the validated/typed header values.
249
+ * For raw Headers API access, use `rawHeaders`.
250
+ */
251
+ get headers(): THeaders;
252
+ set headers(value: THeaders);
235
253
  /**
236
254
  * The signal for aborting the request
237
255
  */
@@ -449,6 +467,12 @@ declare class Request<Params extends Record<string, string> = any, TBody = unkno
449
467
  * @param throwErrorOnValidationFail - If true, throws ValidationError on validation failure. If false, returns the original data.
450
468
  */
451
469
  validateAll<T extends RequestSchema>(inputSchema: T, throwErrorOnValidationFail?: boolean): ValidatedData<T>;
470
+ /**
471
+ * Validates the headers of the request.
472
+ * @param inputSchema - The schema to validate the headers against (Zod schema, TypeBox, or JSON Schema).
473
+ * @param throwErrorOnValidationFail - If true, throws ValidationError on validation failure. If false, returns the original headers.
474
+ */
475
+ validateHeaders<T extends RequestSchema>(inputSchema: T, throwErrorOnValidationFail?: boolean): ValidatedData<T>;
452
476
  /**
453
477
  * Sets a lazy IP extractor function.
454
478
  * IP will only be extracted when `.ip` is first accessed.
@@ -850,9 +874,11 @@ type HTMLString = string;
850
874
  */
851
875
  type CustomUIGenerator = (specUrl: string, globalOptions: SwaggerGlobalOptions) => HTMLString;
852
876
  /**
853
- * Type of request body for a route
877
+ * Type of request body for a route.
878
+ * Common MIME types are provided as literals withintellisense,
879
+ * custom MIME types can be specified as strings.
854
880
  */
855
- type SwaggerBodyType = "json" | "form-data" | "urlencoded";
881
+ type SwaggerBodyType = "json" | "form-data" | "urlencoded" | "binary" | "text" | "event-stream" | (string & {});
856
882
  /**
857
883
  * JSONSchema type for OpenAPI/AJV-compatible schemas
858
884
  */
@@ -939,17 +965,24 @@ type SwaggerGlobalOptions = (SwaggerGlobalOptionsBase & {
939
965
  customUIGenerator: CustomUIGenerator;
940
966
  });
941
967
  /**
942
- * Route-specific documentation options (for individual endpoints)
968
+ * Route-specific documentation options for OpenAPI/Swagger generation.
969
+ *
970
+ * These options are for DOCUMENTATION PURPOSES ONLY and are NOT validated or enforced at runtime.
971
+ * For validated schemas, use the route-level `body`, `query`, and `responses` options.
972
+ *
973
+ * @example
974
+ * // Document route with custom body type
975
+ * router.get("/download", { swagger: { bodyType: "binary" } }, handler);
976
+ *
977
+ * @example
978
+ * // Document authentication requirements
979
+ * router.get("/protected", { swagger: { security: { type: "bearer" } } }, handler);
943
980
  */
944
981
  type SwaggerRouteOptions = {
945
982
  /** Service category where the route belongs to */
946
983
  service?: string;
947
984
  /** Name of the route */
948
985
  name?: string;
949
- /** Responses for this route (used by decorators) */
950
- responses?: Record<number, RequestSchema>;
951
- /** Errors for this route */
952
- errors?: Record<number, RequestSchema>;
953
986
  /** Security requirements for this route */
954
987
  security?: Security[] | Security;
955
988
  /** Description of the route */
@@ -959,7 +992,10 @@ type SwaggerRouteOptions = {
959
992
  /** Exclude from swagger */
960
993
  excludeFromSwagger?: boolean;
961
994
  /**
962
- * The request body type for this route. Allowed values: 'json', 'form-data', 'urlencoded'. Defaults to 'json'.
995
+ * The request body type for documentation purposes.
996
+ * Common types: 'json', 'form-data', 'urlencoded', 'binary', 'text', 'event-stream'.
997
+ * Custom MIME types can be specified as strings (e.g., 'application/vnd.api+json').
998
+ * Defaults to 'json'.
963
999
  */
964
1000
  bodyType?: SwaggerBodyType;
965
1001
  };
@@ -1021,6 +1057,7 @@ type OpenIdConnectOptions = {
1021
1057
  /**
1022
1058
  * Decorator to mark a class as a controller, routes defined in the controller will be registered at import time when calling the `listen` method.
1023
1059
  * You can customize the path pattern for controller imports in the server options `controllerPatterns`
1060
+ * @deprecated This decorator is deprecated and class based controllers won't be supported in the future. Please use the `router` directly to define your routes in a functional way for better type-safety.
1024
1061
  * @param path - The path pattern for the controller.
1025
1062
  * @param swaggerOptions - The swagger options for the controller that will be applied to all routes defined in the controller. Controller options will override route options.
1026
1063
  * @swagger If swagger is enabled, the default service name for all routes defined in the controller will be the controller name.
@@ -1672,20 +1709,20 @@ type InferMiddlewareExtensions<T extends readonly any[]> = T extends readonly [i
1672
1709
  * ```
1673
1710
  */
1674
1711
  interface GroupRouter<TGroupExt extends Record<string, any> = Record<string, never>> {
1675
- get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1676
- get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1677
- post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1678
- post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1679
- patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1680
- patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1681
- put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1682
- put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1683
- delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1684
- delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1685
- options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1686
- options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1687
- head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, TGroupExt>): void;
1688
- head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1712
+ get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1713
+ get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1714
+ post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1715
+ post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1716
+ patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1717
+ patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1718
+ put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1719
+ put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1720
+ delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1721
+ delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1722
+ options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1723
+ options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1724
+ head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
1725
+ head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
1689
1726
  group<const TMiddlewares extends readonly (ServerRouteMiddleware | TypedMiddleware<any>)[] = readonly (ServerRouteMiddleware | TypedMiddleware<any>)[]>(path: string, middleware: TMiddlewares, cb: (router: GroupRouter<TGroupExt & InferMiddlewareExtensions<TMiddlewares>>) => void): void;
1690
1727
  group(path: string, cb: (router: GroupRouter<TGroupExt>) => void): void;
1691
1728
  }
@@ -1717,6 +1754,7 @@ declare class Router {
1717
1754
  addOrUpdate(method: HttpMethod, path: string, middleware: (ServerRouteMiddleware | TypedMiddleware<any>)[], handler: ServerRouteHandler, validationSchemas?: {
1718
1755
  body?: RequestSchema;
1719
1756
  query?: RequestSchema;
1757
+ headers?: RequestSchema;
1720
1758
  all?: RequestSchema;
1721
1759
  }, swaggerOptions?: SwaggerRouteOptions, responses?: Record<number, RequestSchema>, allowUpdate?: boolean): void;
1722
1760
  /**
@@ -1740,37 +1778,37 @@ declare class Router {
1740
1778
  * Register a GET route under this router's base path with type-safe path parameters.
1741
1779
  */
1742
1780
  get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1743
- get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1781
+ get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1744
1782
  /**
1745
1783
  * Register a POST route under this router's base path with type-safe path parameters.
1746
1784
  */
1747
1785
  post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1748
- post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1786
+ post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1749
1787
  /**
1750
1788
  * Register a PATCH route under this router's base path with type-safe path parameters.
1751
1789
  */
1752
1790
  patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1753
- patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1791
+ patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1754
1792
  /**
1755
1793
  * Register a PUT route under this router's base path with type-safe path parameters.
1756
1794
  */
1757
1795
  put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1758
- put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1796
+ put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1759
1797
  /**
1760
1798
  * Register a DELETE route under this router's base path with type-safe path parameters.
1761
1799
  */
1762
1800
  delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1763
- delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1801
+ delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1764
1802
  /**
1765
1803
  * Register an OPTIONS route under this router's base path with type-safe path parameters.
1766
1804
  */
1767
1805
  options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1768
- options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1806
+ options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1769
1807
  /**
1770
1808
  * Register an HEAD route under this router's base path with type-safe path parameters.
1771
1809
  */
1772
1810
  head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
1773
- head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1811
+ head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
1774
1812
  /**
1775
1813
  * Create a grouped router that shares a base path and middlewares.
1776
1814
  * The callback receives a typed child router where routes are defined; routes
@@ -1817,12 +1855,13 @@ interface Route {
1817
1855
  */
1818
1856
  responseSchemas?: RouteResponseSchemas;
1819
1857
  /**
1820
- * Validation schemas for request body, query parameters, or both.
1858
+ * Validation schemas for request body, query parameters, headers, or all.
1821
1859
  * When provided, the handler will receive validated data as additional parameters.
1822
1860
  */
1823
1861
  validationSchemas?: {
1824
1862
  body?: RequestSchema;
1825
1863
  query?: RequestSchema;
1864
+ headers?: RequestSchema;
1826
1865
  all?: RequestSchema;
1827
1866
  };
1828
1867
  }
@@ -2779,10 +2818,11 @@ interface ServerInterface {
2779
2818
  */
2780
2819
  exit: (code?: number) => void;
2781
2820
  }
2782
- type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TPath extends string = string, TAll extends RequestSchema | unknown = unknown, TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]> = {
2821
+ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, THeaders extends RequestSchema | unknown = unknown, TPath extends string = string, TAll extends RequestSchema | unknown = unknown, TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]> = {
2783
2822
  middlewares?: TMiddlewares | TypedMiddleware<any>;
2784
2823
  body?: TBody;
2785
2824
  query?: TQuery;
2825
+ headers?: THeaders;
2786
2826
  all?: TAll;
2787
2827
  responses?: TResponses;
2788
2828
  swagger?: SwaggerRouteOptions;
@@ -2793,7 +2833,7 @@ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Re
2793
2833
  };
2794
2834
  type ServerHook = () => SyncOrAsync;
2795
2835
  type SignalEvent = Deno.Signal | NodeJS.Signals;
2796
- type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown, TMiddlewareExt extends Record<string, any> = Record<string, never>> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown>> & TMiddlewareExt, res: Response$1<InferResponseMap<TResponses>>) => ServerHandlerReturnType<InferResponseMap<TResponses>>;
2836
+ type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, THeaders extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown, TMiddlewareExt extends Record<string, any> = Record<string, never>> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown>, THeaders extends RequestSchema ? InferHeadersType<THeaders> : Record<string, string | string[]>> & TMiddlewareExt, res: Response$1<InferResponseMap<TResponses>>) => ServerHandlerReturnType<InferResponseMap<TResponses>>;
2797
2837
 
2798
2838
  type RunTimeType = "bun" | "node" | "deno";
2799
2839