@minisylar/express-typed-router 1.0.0 → 1.1.0
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/README.md +702 -164
- package/dist/zod-router.cjs +4 -56
- package/dist/zod-router.cjs.map +1 -1
- package/dist/zod-router.d.cts +90 -68
- package/dist/zod-router.d.ts +90 -68
- package/dist/zod-router.js +2 -52
- package/dist/zod-router.js.map +1 -1
- package/package.json +6 -5
- package/dist/zod-router.d.cts.map +0 -1
- package/dist/zod-router.d.ts.map +0 -1
package/dist/zod-router.d.cts
CHANGED
|
@@ -66,21 +66,31 @@ type CountWildcards<Path extends string, Count extends string = "0"> = Path exte
|
|
|
66
66
|
*/
|
|
67
67
|
type IncrementWildcard<T extends string> = T extends "0" ? "1" : T extends "1" ? "2" : T extends "2" ? "3" : T extends "3" ? "4" : T extends "4" ? "5" : T extends "5" ? "6" : T extends "6" ? "7" : T extends "7" ? "8" : T extends "8" ? "9" : "10";
|
|
68
68
|
/**
|
|
69
|
-
* Express middleware that adds custom properties to the request object.
|
|
69
|
+
* Express middleware that adds custom properties to the request object and/or response locals.
|
|
70
70
|
*
|
|
71
|
-
* @template
|
|
72
|
-
* @
|
|
73
|
-
* @param
|
|
71
|
+
* @template TReq - The shape of the properties added to the request object.
|
|
72
|
+
* @template TLocals - The shape of the properties added to response.locals.
|
|
73
|
+
* @param req - The Express request object, extended with TReq.
|
|
74
|
+
* @param res - The Express response object with typed locals.
|
|
74
75
|
* @param next - The next middleware function.
|
|
75
76
|
*/
|
|
76
|
-
type TypedMiddleware<
|
|
77
|
-
|
|
77
|
+
type TypedMiddleware<TReq extends Record<string, any> = {}, TLocals extends Record<string, any> = {}> = (req: Request & TReq, res: Response<any, TLocals>, next: NextFunction) => void | Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Simplified TypedMiddleware for request-only extensions (backward compatibility)
|
|
80
|
+
*/
|
|
81
|
+
type RequestOnlyMiddleware<TReq extends Record<string, any>> = TypedMiddleware<TReq, {}>;
|
|
82
|
+
/**
|
|
83
|
+
* Simplified TypedMiddleware for response locals-only extensions
|
|
84
|
+
*/
|
|
85
|
+
type LocalsOnlyMiddleware<TLocals extends Record<string, any>> = TypedMiddleware<{}, TLocals>;
|
|
86
|
+
type InferMiddlewareProps<T extends readonly TypedMiddleware<any, any>[]> = T extends readonly [infer First, ...infer Rest] ? First extends TypedMiddleware<infer FirstReq, any> ? Rest extends readonly TypedMiddleware<any, any>[] ? FirstReq & InferMiddlewareProps<Rest> : FirstReq : {} : {};
|
|
87
|
+
type InferMiddlewareLocals<T extends readonly TypedMiddleware<any, any>[]> = T extends readonly [infer First, ...infer Rest] ? First extends TypedMiddleware<any, infer FirstLocals> ? Rest extends readonly TypedMiddleware<any, any>[] ? FirstLocals & InferMiddlewareLocals<Rest> : FirstLocals : {} : {};
|
|
78
88
|
type ZodRequest<Path extends string = string, BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown, MiddlewareProps extends Record<string, any> = {}> = Omit<Request, "params" | "query" | "body"> & {
|
|
79
89
|
params: ExtractRouteParams<Path>;
|
|
80
90
|
body: BodySchema extends ZodType<any, any, any> ? z.infer<BodySchema> : unknown;
|
|
81
91
|
query: QuerySchema extends ZodType<any, any, any> ? z.infer<QuerySchema> : unknown;
|
|
82
92
|
} & MiddlewareProps;
|
|
83
|
-
type ZodRouteHandler<Path extends string = string, BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown, MiddlewareProps extends Record<string, any> = {}> = (req: ZodRequest<Path, BodySchema, QuerySchema, MiddlewareProps>, res: Response, next?: NextFunction) => void | Promise<void> | Response | Promise<Response>;
|
|
93
|
+
type ZodRouteHandler<Path extends string = string, BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown, MiddlewareProps extends Record<string, any> = {}, ResponseLocals extends Record<string, any> = {}> = (req: ZodRequest<Path, BodySchema, QuerySchema, MiddlewareProps>, res: Response<any, ResponseLocals>, next?: NextFunction) => void | Promise<void> | Response | Promise<Response>;
|
|
84
94
|
/**
|
|
85
95
|
* Options for defining a typed route, including schemas and middleware.
|
|
86
96
|
*
|
|
@@ -93,110 +103,122 @@ type ZodRouteHandler<Path extends string = string, BodySchema extends ZodType<an
|
|
|
93
103
|
interface RouteOptions<BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown> {
|
|
94
104
|
bodySchema?: BodySchema extends ZodType<any, any, any> ? BodySchema : never;
|
|
95
105
|
querySchema?: QuerySchema extends ZodType<any, any, any> ? QuerySchema : never;
|
|
96
|
-
middleware?: readonly TypedMiddleware<any>[];
|
|
106
|
+
middleware?: readonly TypedMiddleware<any, any>[];
|
|
97
107
|
}
|
|
98
108
|
type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "all";
|
|
99
|
-
declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}> {
|
|
109
|
+
declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}> {
|
|
100
110
|
private router;
|
|
101
111
|
constructor();
|
|
102
112
|
/**
|
|
103
113
|
* Add typed middleware that extends the request with additional properties
|
|
114
|
+
* and/or adds properties to response.locals
|
|
104
115
|
*/
|
|
105
|
-
useTypedMiddleware<
|
|
116
|
+
useTypedMiddleware<TReq extends Record<string, any> = {}, TLocals extends Record<string, any> = {}>(middleware: TypedMiddleware<TReq, TLocals>): TypedRouter<RouterMiddlewareProps & TReq, RouterLocals & TLocals>;
|
|
106
117
|
/**
|
|
107
118
|
* Get the underlying Express router
|
|
108
119
|
*/
|
|
109
120
|
getRouter(): express.Router;
|
|
110
|
-
get<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
111
|
-
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
112
|
-
get<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
121
|
+
get<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
122
|
+
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
123
|
+
get<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
113
124
|
middleware: Middleware;
|
|
114
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
115
|
-
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: RouteOptions<BodySchema, QuerySchema> & {
|
|
125
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
126
|
+
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: RouteOptions<BodySchema, QuerySchema> & {
|
|
116
127
|
middleware: Middleware;
|
|
117
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
118
|
-
post<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
128
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
129
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
119
130
|
bodySchema: BodySchema;
|
|
120
131
|
querySchema?: QuerySchema;
|
|
121
132
|
middleware: Middleware;
|
|
122
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
123
|
-
post<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
133
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
134
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
124
135
|
bodySchema: BodySchema;
|
|
125
136
|
middleware: Middleware;
|
|
126
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
127
|
-
post<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
137
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
138
|
+
post<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
128
139
|
middleware: Middleware;
|
|
129
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
130
|
-
post<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
131
|
-
post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
132
|
-
put<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
140
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
141
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
142
|
+
post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
143
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
133
144
|
bodySchema: BodySchema;
|
|
134
145
|
querySchema?: QuerySchema;
|
|
135
146
|
middleware: Middleware;
|
|
136
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
137
|
-
put<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
147
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
148
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
138
149
|
bodySchema: BodySchema;
|
|
139
150
|
middleware: Middleware;
|
|
140
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
141
|
-
put<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
151
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
152
|
+
put<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
142
153
|
middleware: Middleware;
|
|
143
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
144
|
-
put<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
145
|
-
put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
146
|
-
patch<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
154
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
155
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
156
|
+
put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
157
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
147
158
|
bodySchema: BodySchema;
|
|
148
159
|
querySchema?: QuerySchema;
|
|
149
160
|
middleware: Middleware;
|
|
150
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
151
|
-
patch<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
161
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
162
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
152
163
|
bodySchema: BodySchema;
|
|
153
164
|
middleware: Middleware;
|
|
154
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
155
|
-
patch<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
156
|
-
middleware: Middleware;
|
|
157
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
158
|
-
patch<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
159
|
-
patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
160
|
-
delete<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
165
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
166
|
+
patch<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
161
167
|
middleware: Middleware;
|
|
162
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
163
|
-
|
|
168
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
169
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
170
|
+
patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
171
|
+
delete<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
164
172
|
querySchema: QuerySchema;
|
|
165
173
|
middleware: Middleware;
|
|
166
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
174
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
167
175
|
delete<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
168
176
|
querySchema: QuerySchema;
|
|
169
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
170
|
-
delete<Path extends string
|
|
171
|
-
options<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
177
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
178
|
+
delete<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
172
179
|
middleware: Middleware;
|
|
173
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
181
|
+
delete<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
182
|
+
options<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
183
|
+
querySchema: QuerySchema;
|
|
176
184
|
middleware: Middleware;
|
|
177
|
-
}, handler: ZodRouteHandler<Path, unknown,
|
|
178
|
-
|
|
185
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
186
|
+
options<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
179
187
|
querySchema: QuerySchema;
|
|
188
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
189
|
+
options<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
180
190
|
middleware: Middleware;
|
|
181
|
-
}, handler: ZodRouteHandler<Path, unknown,
|
|
191
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
192
|
+
options<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
193
|
+
head<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
194
|
+
querySchema: QuerySchema;
|
|
195
|
+
middleware: Middleware;
|
|
196
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
182
197
|
head<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
183
198
|
querySchema: QuerySchema;
|
|
184
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
185
|
-
head<Path extends string
|
|
186
|
-
|
|
199
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
200
|
+
head<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
201
|
+
middleware: Middleware;
|
|
202
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
203
|
+
head<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
204
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
187
205
|
bodySchema: BodySchema;
|
|
188
206
|
querySchema?: QuerySchema;
|
|
189
207
|
middleware: Middleware;
|
|
190
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
191
|
-
all<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
208
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
209
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
192
210
|
bodySchema: BodySchema;
|
|
193
211
|
middleware: Middleware;
|
|
194
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
195
|
-
all<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
212
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
213
|
+
all<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
214
|
+
querySchema: QuerySchema;
|
|
215
|
+
middleware: Middleware;
|
|
216
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
217
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
218
|
+
all<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
196
219
|
middleware: Middleware;
|
|
197
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
198
|
-
all<Path extends string
|
|
199
|
-
all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
220
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
221
|
+
all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
200
222
|
private registerRoute;
|
|
201
223
|
private createBodyValidationMiddleware;
|
|
202
224
|
private createQueryValidationMiddleware;
|
|
@@ -221,7 +243,7 @@ declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}
|
|
|
221
243
|
* const app = express();
|
|
222
244
|
* app.use('/api', router.getRouter());
|
|
223
245
|
*/
|
|
224
|
-
declare function createTypedRouter<RouterMiddlewareProps extends Record<string, any> = {}>(): TypedRouter<RouterMiddlewareProps>;
|
|
246
|
+
declare function createTypedRouter<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}>(): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
225
247
|
/**
|
|
226
248
|
* Configuration options for createTypedRouterWithConfig.
|
|
227
249
|
*
|
|
@@ -249,7 +271,7 @@ interface RouterConfig {
|
|
|
249
271
|
* }
|
|
250
272
|
* });
|
|
251
273
|
*/
|
|
252
|
-
declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Record<string, any> = {}>(config?: RouterConfig): TypedRouter<RouterMiddlewareProps>;
|
|
274
|
+
declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}>(config?: RouterConfig): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
253
275
|
/**
|
|
254
276
|
* Create a new typed router with pre-configured middleware.
|
|
255
277
|
*
|
|
@@ -263,8 +285,8 @@ declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Recor
|
|
|
263
285
|
*
|
|
264
286
|
* const router = createTypedRouterWithMiddleware(authMiddleware, loggingMiddleware);
|
|
265
287
|
*/
|
|
266
|
-
declare function createTypedRouterWithMiddleware<T extends Record<string, any>>(...middleware: TypedMiddleware<any>[]): TypedRouter<T>;
|
|
288
|
+
declare function createTypedRouterWithMiddleware<T extends Record<string, any>>(...middleware: TypedMiddleware<any, any>[]): TypedRouter<T>;
|
|
267
289
|
|
|
268
290
|
//#endregion
|
|
269
|
-
export { ExtractRouteParams, HttpMethod, RouteOptions, RouterConfig, TypedMiddleware,
|
|
291
|
+
export { ExtractRouteParams, HttpMethod, LocalsOnlyMiddleware, RequestOnlyMiddleware, RouteOptions, RouterConfig, TypedMiddleware, ZodRequest, ZodRouteHandler, createTypedRouter, createTypedRouterWithConfig, createTypedRouterWithMiddleware };
|
|
270
292
|
//# sourceMappingURL=zod-router.d.cts.map
|
package/dist/zod-router.d.ts
CHANGED
|
@@ -66,21 +66,31 @@ type CountWildcards<Path extends string, Count extends string = "0"> = Path exte
|
|
|
66
66
|
*/
|
|
67
67
|
type IncrementWildcard<T extends string> = T extends "0" ? "1" : T extends "1" ? "2" : T extends "2" ? "3" : T extends "3" ? "4" : T extends "4" ? "5" : T extends "5" ? "6" : T extends "6" ? "7" : T extends "7" ? "8" : T extends "8" ? "9" : "10";
|
|
68
68
|
/**
|
|
69
|
-
* Express middleware that adds custom properties to the request object.
|
|
69
|
+
* Express middleware that adds custom properties to the request object and/or response locals.
|
|
70
70
|
*
|
|
71
|
-
* @template
|
|
72
|
-
* @
|
|
73
|
-
* @param
|
|
71
|
+
* @template TReq - The shape of the properties added to the request object.
|
|
72
|
+
* @template TLocals - The shape of the properties added to response.locals.
|
|
73
|
+
* @param req - The Express request object, extended with TReq.
|
|
74
|
+
* @param res - The Express response object with typed locals.
|
|
74
75
|
* @param next - The next middleware function.
|
|
75
76
|
*/
|
|
76
|
-
type TypedMiddleware<
|
|
77
|
-
|
|
77
|
+
type TypedMiddleware<TReq extends Record<string, any> = {}, TLocals extends Record<string, any> = {}> = (req: Request & TReq, res: Response<any, TLocals>, next: NextFunction) => void | Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Simplified TypedMiddleware for request-only extensions (backward compatibility)
|
|
80
|
+
*/
|
|
81
|
+
type RequestOnlyMiddleware<TReq extends Record<string, any>> = TypedMiddleware<TReq, {}>;
|
|
82
|
+
/**
|
|
83
|
+
* Simplified TypedMiddleware for response locals-only extensions
|
|
84
|
+
*/
|
|
85
|
+
type LocalsOnlyMiddleware<TLocals extends Record<string, any>> = TypedMiddleware<{}, TLocals>;
|
|
86
|
+
type InferMiddlewareProps<T extends readonly TypedMiddleware<any, any>[]> = T extends readonly [infer First, ...infer Rest] ? First extends TypedMiddleware<infer FirstReq, any> ? Rest extends readonly TypedMiddleware<any, any>[] ? FirstReq & InferMiddlewareProps<Rest> : FirstReq : {} : {};
|
|
87
|
+
type InferMiddlewareLocals<T extends readonly TypedMiddleware<any, any>[]> = T extends readonly [infer First, ...infer Rest] ? First extends TypedMiddleware<any, infer FirstLocals> ? Rest extends readonly TypedMiddleware<any, any>[] ? FirstLocals & InferMiddlewareLocals<Rest> : FirstLocals : {} : {};
|
|
78
88
|
type ZodRequest<Path extends string = string, BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown, MiddlewareProps extends Record<string, any> = {}> = Omit<Request, "params" | "query" | "body"> & {
|
|
79
89
|
params: ExtractRouteParams<Path>;
|
|
80
90
|
body: BodySchema extends ZodType<any, any, any> ? z.infer<BodySchema> : unknown;
|
|
81
91
|
query: QuerySchema extends ZodType<any, any, any> ? z.infer<QuerySchema> : unknown;
|
|
82
92
|
} & MiddlewareProps;
|
|
83
|
-
type ZodRouteHandler<Path extends string = string, BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown, MiddlewareProps extends Record<string, any> = {}> = (req: ZodRequest<Path, BodySchema, QuerySchema, MiddlewareProps>, res: Response, next?: NextFunction) => void | Promise<void> | Response | Promise<Response>;
|
|
93
|
+
type ZodRouteHandler<Path extends string = string, BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown, MiddlewareProps extends Record<string, any> = {}, ResponseLocals extends Record<string, any> = {}> = (req: ZodRequest<Path, BodySchema, QuerySchema, MiddlewareProps>, res: Response<any, ResponseLocals>, next?: NextFunction) => void | Promise<void> | Response | Promise<Response>;
|
|
84
94
|
/**
|
|
85
95
|
* Options for defining a typed route, including schemas and middleware.
|
|
86
96
|
*
|
|
@@ -93,110 +103,122 @@ type ZodRouteHandler<Path extends string = string, BodySchema extends ZodType<an
|
|
|
93
103
|
interface RouteOptions<BodySchema extends ZodType<any, any, any> | unknown = unknown, QuerySchema extends ZodType<any, any, any> | unknown = unknown> {
|
|
94
104
|
bodySchema?: BodySchema extends ZodType<any, any, any> ? BodySchema : never;
|
|
95
105
|
querySchema?: QuerySchema extends ZodType<any, any, any> ? QuerySchema : never;
|
|
96
|
-
middleware?: readonly TypedMiddleware<any>[];
|
|
106
|
+
middleware?: readonly TypedMiddleware<any, any>[];
|
|
97
107
|
}
|
|
98
108
|
type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "all";
|
|
99
|
-
declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}> {
|
|
109
|
+
declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}> {
|
|
100
110
|
private router;
|
|
101
111
|
constructor();
|
|
102
112
|
/**
|
|
103
113
|
* Add typed middleware that extends the request with additional properties
|
|
114
|
+
* and/or adds properties to response.locals
|
|
104
115
|
*/
|
|
105
|
-
useTypedMiddleware<
|
|
116
|
+
useTypedMiddleware<TReq extends Record<string, any> = {}, TLocals extends Record<string, any> = {}>(middleware: TypedMiddleware<TReq, TLocals>): TypedRouter<RouterMiddlewareProps & TReq, RouterLocals & TLocals>;
|
|
106
117
|
/**
|
|
107
118
|
* Get the underlying Express router
|
|
108
119
|
*/
|
|
109
120
|
getRouter(): express.Router;
|
|
110
|
-
get<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
111
|
-
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
112
|
-
get<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
121
|
+
get<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
122
|
+
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
123
|
+
get<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
113
124
|
middleware: Middleware;
|
|
114
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
115
|
-
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: RouteOptions<BodySchema, QuerySchema> & {
|
|
125
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
126
|
+
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: RouteOptions<BodySchema, QuerySchema> & {
|
|
116
127
|
middleware: Middleware;
|
|
117
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
118
|
-
post<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
128
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
129
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
119
130
|
bodySchema: BodySchema;
|
|
120
131
|
querySchema?: QuerySchema;
|
|
121
132
|
middleware: Middleware;
|
|
122
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
123
|
-
post<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
133
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
134
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
124
135
|
bodySchema: BodySchema;
|
|
125
136
|
middleware: Middleware;
|
|
126
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
127
|
-
post<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
137
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
138
|
+
post<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
128
139
|
middleware: Middleware;
|
|
129
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
130
|
-
post<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
131
|
-
post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
132
|
-
put<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
140
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
141
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
142
|
+
post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
143
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
133
144
|
bodySchema: BodySchema;
|
|
134
145
|
querySchema?: QuerySchema;
|
|
135
146
|
middleware: Middleware;
|
|
136
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
137
|
-
put<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
147
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
148
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
138
149
|
bodySchema: BodySchema;
|
|
139
150
|
middleware: Middleware;
|
|
140
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
141
|
-
put<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
151
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
152
|
+
put<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
142
153
|
middleware: Middleware;
|
|
143
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
144
|
-
put<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
145
|
-
put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
146
|
-
patch<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
154
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
155
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
156
|
+
put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
157
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
147
158
|
bodySchema: BodySchema;
|
|
148
159
|
querySchema?: QuerySchema;
|
|
149
160
|
middleware: Middleware;
|
|
150
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
151
|
-
patch<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
161
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
162
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
152
163
|
bodySchema: BodySchema;
|
|
153
164
|
middleware: Middleware;
|
|
154
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
155
|
-
patch<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
156
|
-
middleware: Middleware;
|
|
157
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
158
|
-
patch<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
159
|
-
patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
160
|
-
delete<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
165
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
166
|
+
patch<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
161
167
|
middleware: Middleware;
|
|
162
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
163
|
-
|
|
168
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
169
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
170
|
+
patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
171
|
+
delete<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
164
172
|
querySchema: QuerySchema;
|
|
165
173
|
middleware: Middleware;
|
|
166
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
174
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
167
175
|
delete<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
168
176
|
querySchema: QuerySchema;
|
|
169
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
170
|
-
delete<Path extends string
|
|
171
|
-
options<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
177
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
178
|
+
delete<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
172
179
|
middleware: Middleware;
|
|
173
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
181
|
+
delete<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
182
|
+
options<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
183
|
+
querySchema: QuerySchema;
|
|
176
184
|
middleware: Middleware;
|
|
177
|
-
}, handler: ZodRouteHandler<Path, unknown,
|
|
178
|
-
|
|
185
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
186
|
+
options<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
179
187
|
querySchema: QuerySchema;
|
|
188
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
189
|
+
options<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
180
190
|
middleware: Middleware;
|
|
181
|
-
}, handler: ZodRouteHandler<Path, unknown,
|
|
191
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
192
|
+
options<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
193
|
+
head<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
194
|
+
querySchema: QuerySchema;
|
|
195
|
+
middleware: Middleware;
|
|
196
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
182
197
|
head<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
183
198
|
querySchema: QuerySchema;
|
|
184
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
185
|
-
head<Path extends string
|
|
186
|
-
|
|
199
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
200
|
+
head<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
201
|
+
middleware: Middleware;
|
|
202
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
203
|
+
head<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
204
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
187
205
|
bodySchema: BodySchema;
|
|
188
206
|
querySchema?: QuerySchema;
|
|
189
207
|
middleware: Middleware;
|
|
190
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
191
|
-
all<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
208
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
209
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
192
210
|
bodySchema: BodySchema;
|
|
193
211
|
middleware: Middleware;
|
|
194
|
-
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
195
|
-
all<Path extends string, Middleware extends readonly TypedMiddleware<any>[]>(path: Path, options: {
|
|
212
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
213
|
+
all<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
214
|
+
querySchema: QuerySchema;
|
|
215
|
+
middleware: Middleware;
|
|
216
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
217
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
218
|
+
all<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
196
219
|
middleware: Middleware;
|
|
197
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
198
|
-
all<Path extends string
|
|
199
|
-
all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
220
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
221
|
+
all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
200
222
|
private registerRoute;
|
|
201
223
|
private createBodyValidationMiddleware;
|
|
202
224
|
private createQueryValidationMiddleware;
|
|
@@ -221,7 +243,7 @@ declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}
|
|
|
221
243
|
* const app = express();
|
|
222
244
|
* app.use('/api', router.getRouter());
|
|
223
245
|
*/
|
|
224
|
-
declare function createTypedRouter<RouterMiddlewareProps extends Record<string, any> = {}>(): TypedRouter<RouterMiddlewareProps>;
|
|
246
|
+
declare function createTypedRouter<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}>(): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
225
247
|
/**
|
|
226
248
|
* Configuration options for createTypedRouterWithConfig.
|
|
227
249
|
*
|
|
@@ -249,7 +271,7 @@ interface RouterConfig {
|
|
|
249
271
|
* }
|
|
250
272
|
* });
|
|
251
273
|
*/
|
|
252
|
-
declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Record<string, any> = {}>(config?: RouterConfig): TypedRouter<RouterMiddlewareProps>;
|
|
274
|
+
declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}>(config?: RouterConfig): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
253
275
|
/**
|
|
254
276
|
* Create a new typed router with pre-configured middleware.
|
|
255
277
|
*
|
|
@@ -263,8 +285,8 @@ declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Recor
|
|
|
263
285
|
*
|
|
264
286
|
* const router = createTypedRouterWithMiddleware(authMiddleware, loggingMiddleware);
|
|
265
287
|
*/
|
|
266
|
-
declare function createTypedRouterWithMiddleware<T extends Record<string, any>>(...middleware: TypedMiddleware<any>[]): TypedRouter<T>;
|
|
288
|
+
declare function createTypedRouterWithMiddleware<T extends Record<string, any>>(...middleware: TypedMiddleware<any, any>[]): TypedRouter<T>;
|
|
267
289
|
|
|
268
290
|
//#endregion
|
|
269
|
-
export { ExtractRouteParams, HttpMethod, RouteOptions, RouterConfig, TypedMiddleware,
|
|
291
|
+
export { ExtractRouteParams, HttpMethod, LocalsOnlyMiddleware, RequestOnlyMiddleware, RouteOptions, RouterConfig, TypedMiddleware, ZodRequest, ZodRouteHandler, createTypedRouter, createTypedRouterWithConfig, createTypedRouterWithMiddleware };
|
|
270
292
|
//# sourceMappingURL=zod-router.d.ts.map
|