@minisylar/express-typed-router 1.0.1 → 1.2.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 +207 -22
- package/dist/zod-router.cjs +12 -3
- package/dist/zod-router.cjs.map +1 -1
- package/dist/zod-router.d.cts +121 -73
- package/dist/zod-router.d.ts +121 -73
- package/dist/zod-router.js +13 -3
- package/dist/zod-router.js.map +1 -1
- package/package.json +1 -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,148 @@ 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?:
|
|
106
|
+
middleware?: 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
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
* and/or adds properties to response.locals
|
|
115
|
+
*/ /**
|
|
116
|
+
* Add typed middleware to the router.
|
|
117
|
+
* This middleware will apply to all routes defined after this call.
|
|
118
|
+
*
|
|
119
|
+
* @template TReq - Type extensions for the request object
|
|
120
|
+
* @template TLocals - Type extensions for response.locals
|
|
121
|
+
* @param middleware - The typed middleware function
|
|
122
|
+
* @returns A new router instance with updated types
|
|
123
|
+
*/
|
|
124
|
+
useMiddleware<TReq extends Record<string, any> = {}, TLocals extends Record<string, any> = {}>(middleware: TypedMiddleware<TReq, TLocals>): TypedRouter<RouterMiddlewareProps & TReq, RouterLocals & TLocals>;
|
|
106
125
|
/**
|
|
107
126
|
* Get the underlying Express router
|
|
108
127
|
*/
|
|
109
128
|
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: {
|
|
113
|
-
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> & {
|
|
129
|
+
get<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
130
|
+
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>;
|
|
131
|
+
get<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
116
132
|
middleware: Middleware;
|
|
117
|
-
}, handler: ZodRouteHandler<Path,
|
|
118
|
-
|
|
133
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
134
|
+
get<Path extends string, BodySchema extends ZodType<any, any, any> | unknown, QuerySchema extends ZodType<any, any, any> | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: RouteOptions<BodySchema, QuerySchema> & {
|
|
135
|
+
middleware: [...M];
|
|
136
|
+
},
|
|
137
|
+
// Using tuple spread pattern
|
|
138
|
+
handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
|
|
139
|
+
// Make it readonly for type inference
|
|
140
|
+
// Make it readonly for type inference
|
|
141
|
+
RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
142
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any>, QuerySchema extends ZodType<any, any, any> | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
119
143
|
bodySchema: BodySchema;
|
|
120
144
|
querySchema?: QuerySchema;
|
|
121
|
-
middleware:
|
|
122
|
-
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<
|
|
123
|
-
|
|
145
|
+
middleware: [...M];
|
|
146
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
|
|
147
|
+
// Make it readonly for type inference
|
|
148
|
+
// Make it readonly for type inference
|
|
149
|
+
RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
150
|
+
post<Path extends string, BodySchema extends ZodType<any, any, any>, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
124
151
|
bodySchema: BodySchema;
|
|
125
|
-
middleware:
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
152
|
+
middleware: [...M];
|
|
153
|
+
},
|
|
154
|
+
// Using tuple spread pattern
|
|
155
|
+
handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
|
|
156
|
+
// Make it readonly for type inference
|
|
157
|
+
// Make it readonly for type inference
|
|
158
|
+
RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
159
|
+
post<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
160
|
+
middleware: [...M];
|
|
161
|
+
},
|
|
162
|
+
// Using tuple spread pattern
|
|
163
|
+
handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
|
|
164
|
+
// Make it readonly for type inference
|
|
165
|
+
// Make it readonly for type inference
|
|
166
|
+
RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
167
|
+
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>;
|
|
168
|
+
post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
169
|
+
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
170
|
bodySchema: BodySchema;
|
|
134
171
|
querySchema?: QuerySchema;
|
|
135
172
|
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: {
|
|
173
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
174
|
+
put<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
138
175
|
bodySchema: BodySchema;
|
|
139
176
|
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: {
|
|
177
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
178
|
+
put<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
142
179
|
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: {
|
|
180
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
181
|
+
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>;
|
|
182
|
+
put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
183
|
+
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
184
|
bodySchema: BodySchema;
|
|
148
185
|
querySchema?: QuerySchema;
|
|
149
186
|
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: {
|
|
187
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
188
|
+
patch<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
152
189
|
bodySchema: BodySchema;
|
|
153
190
|
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: {
|
|
191
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
192
|
+
patch<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
161
193
|
middleware: Middleware;
|
|
162
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
163
|
-
|
|
194
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
195
|
+
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>;
|
|
196
|
+
patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
197
|
+
delete<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
164
198
|
querySchema: QuerySchema;
|
|
165
199
|
middleware: Middleware;
|
|
166
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
200
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
167
201
|
delete<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
168
202
|
querySchema: QuerySchema;
|
|
169
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
170
|
-
delete<Path extends string
|
|
171
|
-
|
|
203
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
204
|
+
delete<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
205
|
+
middleware: Middleware;
|
|
206
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
207
|
+
delete<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
208
|
+
options<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
209
|
+
querySchema: QuerySchema;
|
|
172
210
|
middleware: Middleware;
|
|
173
|
-
}, handler: ZodRouteHandler<Path, unknown,
|
|
174
|
-
options<Path extends string
|
|
175
|
-
|
|
211
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
212
|
+
options<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
213
|
+
querySchema: QuerySchema;
|
|
214
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
215
|
+
options<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
176
216
|
middleware: Middleware;
|
|
177
|
-
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
178
|
-
|
|
217
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
218
|
+
options<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
219
|
+
head<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
179
220
|
querySchema: QuerySchema;
|
|
180
221
|
middleware: Middleware;
|
|
181
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>>): TypedRouter<RouterMiddlewareProps>;
|
|
222
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
182
223
|
head<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown>(path: Path, options: {
|
|
183
224
|
querySchema: QuerySchema;
|
|
184
|
-
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps>): TypedRouter<RouterMiddlewareProps>;
|
|
185
|
-
head<Path extends string
|
|
186
|
-
|
|
225
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
226
|
+
head<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
227
|
+
middleware: Middleware;
|
|
228
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
229
|
+
head<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
230
|
+
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
231
|
bodySchema: BodySchema;
|
|
188
232
|
querySchema?: QuerySchema;
|
|
189
233
|
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: {
|
|
234
|
+
}, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
235
|
+
all<Path extends string, BodySchema extends ZodType<any, any, any>, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
192
236
|
bodySchema: BodySchema;
|
|
193
237
|
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: {
|
|
238
|
+
}, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
239
|
+
all<Path extends string, QuerySchema extends ZodType<any, any, any> | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
240
|
+
querySchema: QuerySchema;
|
|
241
|
+
middleware: Middleware;
|
|
242
|
+
}, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
243
|
+
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>;
|
|
244
|
+
all<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
|
|
196
245
|
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>;
|
|
246
|
+
}, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
247
|
+
all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
200
248
|
private registerRoute;
|
|
201
249
|
private createBodyValidationMiddleware;
|
|
202
250
|
private createQueryValidationMiddleware;
|
|
@@ -221,7 +269,7 @@ declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}
|
|
|
221
269
|
* const app = express();
|
|
222
270
|
* app.use('/api', router.getRouter());
|
|
223
271
|
*/
|
|
224
|
-
declare function createTypedRouter<RouterMiddlewareProps extends Record<string, any> = {}>(): TypedRouter<RouterMiddlewareProps>;
|
|
272
|
+
declare function createTypedRouter<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}>(): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
225
273
|
/**
|
|
226
274
|
* Configuration options for createTypedRouterWithConfig.
|
|
227
275
|
*
|
|
@@ -249,7 +297,7 @@ interface RouterConfig {
|
|
|
249
297
|
* }
|
|
250
298
|
* });
|
|
251
299
|
*/
|
|
252
|
-
declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Record<string, any> = {}>(config?: RouterConfig): TypedRouter<RouterMiddlewareProps>;
|
|
300
|
+
declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Record<string, any> = {}, RouterLocals extends Record<string, any> = {}>(config?: RouterConfig): TypedRouter<RouterMiddlewareProps, RouterLocals>;
|
|
253
301
|
/**
|
|
254
302
|
* Create a new typed router with pre-configured middleware.
|
|
255
303
|
*
|
|
@@ -263,8 +311,8 @@ declare function createTypedRouterWithConfig<RouterMiddlewareProps extends Recor
|
|
|
263
311
|
*
|
|
264
312
|
* const router = createTypedRouterWithMiddleware(authMiddleware, loggingMiddleware);
|
|
265
313
|
*/
|
|
266
|
-
declare function createTypedRouterWithMiddleware<T extends Record<string, any>>(...middleware: TypedMiddleware<any>[]): TypedRouter<T>;
|
|
314
|
+
declare function createTypedRouterWithMiddleware<T extends Record<string, any>>(...middleware: TypedMiddleware<any, any>[]): TypedRouter<T>;
|
|
267
315
|
|
|
268
316
|
//#endregion
|
|
269
|
-
export { ExtractRouteParams, HttpMethod, RouteOptions, RouterConfig, TypedMiddleware,
|
|
317
|
+
export { ExtractRouteParams, HttpMethod, LocalsOnlyMiddleware, RequestOnlyMiddleware, RouteOptions, RouterConfig, TypedMiddleware, ZodRequest, ZodRouteHandler, createTypedRouter, createTypedRouterWithConfig, createTypedRouterWithMiddleware };
|
|
270
318
|
//# sourceMappingURL=zod-router.d.cts.map
|