@minisylar/express-typed-router 1.4.4 → 1.5.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.
@@ -94,7 +94,7 @@ type ZodRequest<Path extends string = string, BodySchema extends AnyZodType | un
94
94
  body: BodySchema extends AnyZodType ? InferOutput<BodySchema> : unknown;
95
95
  query: QuerySchema extends AnyZodType ? InferOutput<QuerySchema> : unknown;
96
96
  } & MiddlewareProps;
97
- type ZodRouteHandler<Path extends string = string, BodySchema extends AnyZodType | unknown = unknown, QuerySchema extends AnyZodType | 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>;
97
+ type ZodRouteHandler<Path extends string = string, BodySchema extends AnyZodType | unknown = unknown, QuerySchema extends AnyZodType | 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 | undefined | Promise<void | undefined> | Response | Promise<Response> | Promise<Response | undefined>;
98
98
  /**
99
99
  * Options for defining a typed route, including schemas and middleware.
100
100
  *
@@ -170,84 +170,158 @@ declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}
170
170
  RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
171
171
  post<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
172
172
  post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
173
- put<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
173
+ put<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
174
174
  bodySchema: BodySchema;
175
175
  querySchema?: QuerySchema;
176
- middleware: Middleware;
177
- }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
178
- put<Path extends string, BodySchema extends AnyZodType, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
176
+ middleware: [...M];
177
+ }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
178
+ // Make it readonly for type inference
179
+ // Make it readonly for type inference
180
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
181
+ put<Path extends string, BodySchema extends AnyZodType, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
179
182
  bodySchema: BodySchema;
180
- middleware: Middleware;
181
- }, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
182
- put<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
183
- middleware: Middleware;
184
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
183
+ middleware: [...M];
184
+ },
185
+ // Using tuple spread pattern
186
+ handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
187
+ // Make it readonly for type inference
188
+ // Make it readonly for type inference
189
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
190
+ put<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
191
+ middleware: [...M];
192
+ },
193
+ // Using tuple spread pattern
194
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
195
+ // Make it readonly for type inference
196
+ // Make it readonly for type inference
197
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
185
198
  put<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
186
199
  put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
187
- patch<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
200
+ patch<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
188
201
  bodySchema: BodySchema;
189
202
  querySchema?: QuerySchema;
190
- middleware: Middleware;
191
- }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
192
- patch<Path extends string, BodySchema extends AnyZodType, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
203
+ middleware: [...M];
204
+ }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
205
+ // Make it readonly for type inference
206
+ // Make it readonly for type inference
207
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
208
+ patch<Path extends string, BodySchema extends AnyZodType, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
193
209
  bodySchema: BodySchema;
194
- middleware: Middleware;
195
- }, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
196
- patch<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
197
- middleware: Middleware;
198
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
210
+ middleware: [...M];
211
+ },
212
+ // Using tuple spread pattern
213
+ handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
214
+ // Make it readonly for type inference
215
+ // Make it readonly for type inference
216
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
217
+ patch<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
218
+ middleware: [...M];
219
+ },
220
+ // Using tuple spread pattern
221
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
222
+ // Make it readonly for type inference
223
+ // Make it readonly for type inference
224
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
199
225
  patch<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
200
226
  patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
201
- delete<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
227
+ delete<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
202
228
  querySchema: QuerySchema;
203
- middleware: Middleware;
204
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
229
+ middleware: [...M];
230
+ },
231
+ // Using tuple spread pattern
232
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
233
+ // Make it readonly for type inference
234
+ // Make it readonly for type inference
235
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
205
236
  delete<Path extends string, QuerySchema extends AnyZodType | unknown>(path: Path, options: {
206
237
  querySchema: QuerySchema;
207
238
  }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
208
- delete<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
209
- middleware: Middleware;
210
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
239
+ delete<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
240
+ middleware: [...M];
241
+ },
242
+ // Using tuple spread pattern
243
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
244
+ // Make it readonly for type inference
245
+ // Make it readonly for type inference
246
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
211
247
  delete<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
212
- options<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
248
+ options<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
213
249
  querySchema: QuerySchema;
214
- middleware: Middleware;
215
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
250
+ middleware: [...M];
251
+ },
252
+ // Using tuple spread pattern
253
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
254
+ // Make it readonly for type inference
255
+ // Make it readonly for type inference
256
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
216
257
  options<Path extends string, QuerySchema extends AnyZodType | unknown>(path: Path, options: {
217
258
  querySchema: QuerySchema;
218
259
  }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
219
- options<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
220
- middleware: Middleware;
221
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
260
+ options<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
261
+ middleware: [...M];
262
+ },
263
+ // Using tuple spread pattern
264
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
265
+ // Make it readonly for type inference
266
+ // Make it readonly for type inference
267
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
222
268
  options<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
223
- head<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
269
+ head<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
224
270
  querySchema: QuerySchema;
225
- middleware: Middleware;
226
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
271
+ middleware: [...M];
272
+ },
273
+ // Using tuple spread pattern
274
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
275
+ // Make it readonly for type inference
276
+ // Make it readonly for type inference
277
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
227
278
  head<Path extends string, QuerySchema extends AnyZodType | unknown>(path: Path, options: {
228
279
  querySchema: QuerySchema;
229
280
  }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
230
- head<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
231
- middleware: Middleware;
232
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
281
+ head<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
282
+ middleware: [...M];
283
+ },
284
+ // Using tuple spread pattern
285
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
286
+ // Make it readonly for type inference
287
+ // Make it readonly for type inference
288
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
233
289
  head<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
234
- all<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
290
+ all<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
235
291
  bodySchema: BodySchema;
236
292
  querySchema?: QuerySchema;
237
- middleware: Middleware;
238
- }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
239
- all<Path extends string, BodySchema extends AnyZodType, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
293
+ middleware: [...M];
294
+ }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
295
+ // Make it readonly for type inference
296
+ // Make it readonly for type inference
297
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
298
+ all<Path extends string, BodySchema extends AnyZodType, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
240
299
  bodySchema: BodySchema;
241
- middleware: Middleware;
242
- }, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
243
- all<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
300
+ middleware: [...M];
301
+ },
302
+ // Using tuple spread pattern
303
+ handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
304
+ // Make it readonly for type inference
305
+ // Make it readonly for type inference
306
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
307
+ all<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
244
308
  querySchema: QuerySchema;
245
- middleware: Middleware;
246
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
309
+ middleware: [...M];
310
+ },
311
+ // Using tuple spread pattern
312
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
313
+ // Make it readonly for type inference
314
+ // Make it readonly for type inference
315
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
247
316
  all<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
248
- all<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
249
- middleware: Middleware;
250
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
317
+ all<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
318
+ middleware: [...M];
319
+ },
320
+ // Using tuple spread pattern
321
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
322
+ // Make it readonly for type inference
323
+ // Make it readonly for type inference
324
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
251
325
  all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
252
326
  private registerRoute;
253
327
  private createBodyValidationMiddleware;
@@ -94,7 +94,7 @@ type ZodRequest<Path extends string = string, BodySchema extends AnyZodType | un
94
94
  body: BodySchema extends AnyZodType ? InferOutput<BodySchema> : unknown;
95
95
  query: QuerySchema extends AnyZodType ? InferOutput<QuerySchema> : unknown;
96
96
  } & MiddlewareProps;
97
- type ZodRouteHandler<Path extends string = string, BodySchema extends AnyZodType | unknown = unknown, QuerySchema extends AnyZodType | 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>;
97
+ type ZodRouteHandler<Path extends string = string, BodySchema extends AnyZodType | unknown = unknown, QuerySchema extends AnyZodType | 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 | undefined | Promise<void | undefined> | Response | Promise<Response> | Promise<Response | undefined>;
98
98
  /**
99
99
  * Options for defining a typed route, including schemas and middleware.
100
100
  *
@@ -170,84 +170,158 @@ declare class TypedRouter<RouterMiddlewareProps extends Record<string, any> = {}
170
170
  RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
171
171
  post<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
172
172
  post<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
173
- put<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
173
+ put<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
174
174
  bodySchema: BodySchema;
175
175
  querySchema?: QuerySchema;
176
- middleware: Middleware;
177
- }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
178
- put<Path extends string, BodySchema extends AnyZodType, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
176
+ middleware: [...M];
177
+ }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
178
+ // Make it readonly for type inference
179
+ // Make it readonly for type inference
180
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
181
+ put<Path extends string, BodySchema extends AnyZodType, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
179
182
  bodySchema: BodySchema;
180
- middleware: Middleware;
181
- }, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
182
- put<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
183
- middleware: Middleware;
184
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
183
+ middleware: [...M];
184
+ },
185
+ // Using tuple spread pattern
186
+ handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
187
+ // Make it readonly for type inference
188
+ // Make it readonly for type inference
189
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
190
+ put<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
191
+ middleware: [...M];
192
+ },
193
+ // Using tuple spread pattern
194
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
195
+ // Make it readonly for type inference
196
+ // Make it readonly for type inference
197
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
185
198
  put<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
186
199
  put<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
187
- patch<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
200
+ patch<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
188
201
  bodySchema: BodySchema;
189
202
  querySchema?: QuerySchema;
190
- middleware: Middleware;
191
- }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
192
- patch<Path extends string, BodySchema extends AnyZodType, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
203
+ middleware: [...M];
204
+ }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
205
+ // Make it readonly for type inference
206
+ // Make it readonly for type inference
207
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
208
+ patch<Path extends string, BodySchema extends AnyZodType, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
193
209
  bodySchema: BodySchema;
194
- middleware: Middleware;
195
- }, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
196
- patch<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
197
- middleware: Middleware;
198
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
210
+ middleware: [...M];
211
+ },
212
+ // Using tuple spread pattern
213
+ handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
214
+ // Make it readonly for type inference
215
+ // Make it readonly for type inference
216
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
217
+ patch<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
218
+ middleware: [...M];
219
+ },
220
+ // Using tuple spread pattern
221
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
222
+ // Make it readonly for type inference
223
+ // Make it readonly for type inference
224
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
199
225
  patch<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
200
226
  patch<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
201
- delete<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
227
+ delete<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
202
228
  querySchema: QuerySchema;
203
- middleware: Middleware;
204
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
229
+ middleware: [...M];
230
+ },
231
+ // Using tuple spread pattern
232
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
233
+ // Make it readonly for type inference
234
+ // Make it readonly for type inference
235
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
205
236
  delete<Path extends string, QuerySchema extends AnyZodType | unknown>(path: Path, options: {
206
237
  querySchema: QuerySchema;
207
238
  }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
208
- delete<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
209
- middleware: Middleware;
210
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
239
+ delete<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
240
+ middleware: [...M];
241
+ },
242
+ // Using tuple spread pattern
243
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
244
+ // Make it readonly for type inference
245
+ // Make it readonly for type inference
246
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
211
247
  delete<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
212
- options<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
248
+ options<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
213
249
  querySchema: QuerySchema;
214
- middleware: Middleware;
215
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
250
+ middleware: [...M];
251
+ },
252
+ // Using tuple spread pattern
253
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
254
+ // Make it readonly for type inference
255
+ // Make it readonly for type inference
256
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
216
257
  options<Path extends string, QuerySchema extends AnyZodType | unknown>(path: Path, options: {
217
258
  querySchema: QuerySchema;
218
259
  }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
219
- options<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
220
- middleware: Middleware;
221
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
260
+ options<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
261
+ middleware: [...M];
262
+ },
263
+ // Using tuple spread pattern
264
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
265
+ // Make it readonly for type inference
266
+ // Make it readonly for type inference
267
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
222
268
  options<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
223
- head<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
269
+ head<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
224
270
  querySchema: QuerySchema;
225
- middleware: Middleware;
226
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
271
+ middleware: [...M];
272
+ },
273
+ // Using tuple spread pattern
274
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
275
+ // Make it readonly for type inference
276
+ // Make it readonly for type inference
277
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
227
278
  head<Path extends string, QuerySchema extends AnyZodType | unknown>(path: Path, options: {
228
279
  querySchema: QuerySchema;
229
280
  }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
230
- head<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
231
- middleware: Middleware;
232
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
281
+ head<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
282
+ middleware: [...M];
283
+ },
284
+ // Using tuple spread pattern
285
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
286
+ // Make it readonly for type inference
287
+ // Make it readonly for type inference
288
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
233
289
  head<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
234
- all<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
290
+ all<Path extends string, BodySchema extends AnyZodType, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
235
291
  bodySchema: BodySchema;
236
292
  querySchema?: QuerySchema;
237
- middleware: Middleware;
238
- }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
239
- all<Path extends string, BodySchema extends AnyZodType, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
293
+ middleware: [...M];
294
+ }, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
295
+ // Make it readonly for type inference
296
+ // Make it readonly for type inference
297
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
298
+ all<Path extends string, BodySchema extends AnyZodType, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
240
299
  bodySchema: BodySchema;
241
- middleware: Middleware;
242
- }, handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
243
- all<Path extends string, QuerySchema extends AnyZodType | unknown, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
300
+ middleware: [...M];
301
+ },
302
+ // Using tuple spread pattern
303
+ handler: ZodRouteHandler<Path, BodySchema, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
304
+ // Make it readonly for type inference
305
+ // Make it readonly for type inference
306
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
307
+ all<Path extends string, QuerySchema extends AnyZodType | unknown, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
244
308
  querySchema: QuerySchema;
245
- middleware: Middleware;
246
- }, handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
309
+ middleware: [...M];
310
+ },
311
+ // Using tuple spread pattern
312
+ handler: ZodRouteHandler<Path, unknown, QuerySchema, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
313
+ // Make it readonly for type inference
314
+ // Make it readonly for type inference
315
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
247
316
  all<Path extends string, BodySchema extends AnyZodType | unknown, QuerySchema extends AnyZodType | unknown>(path: Path, options: RouteOptions<BodySchema, QuerySchema>, handler: ZodRouteHandler<Path, BodySchema, QuerySchema, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
248
- all<Path extends string, Middleware extends readonly TypedMiddleware<any, any>[]>(path: Path, options: {
249
- middleware: Middleware;
250
- }, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<Middleware>, RouterLocals & InferMiddlewareLocals<Middleware>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
317
+ all<Path extends string, M extends TypedMiddleware<any, any>[]>(path: Path, options: {
318
+ middleware: [...M];
319
+ },
320
+ // Using tuple spread pattern
321
+ handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps & InferMiddlewareProps<readonly [...M]>,
322
+ // Make it readonly for type inference
323
+ // Make it readonly for type inference
324
+ RouterLocals & InferMiddlewareLocals<readonly [...M]>>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
251
325
  all<Path extends string>(path: Path, handler: ZodRouteHandler<Path, unknown, unknown, RouterMiddlewareProps, RouterLocals>): TypedRouter<RouterMiddlewareProps, RouterLocals>;
252
326
  private registerRoute;
253
327
  private createBodyValidationMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minisylar/express-typed-router",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "description": "A strongly-typed Express router with Zod validation and automatic type inference for params, body, query, and middleware",
5
5
  "type": "module",
6
6
  "main": "dist/zod-router.cjs",
@@ -63,7 +63,7 @@
63
63
  "conventional-changelog-conventionalcommits": "^9.1.0",
64
64
  "rimraf": "^6.0.1",
65
65
  "semantic-release": "^24.2.7",
66
- "tsdown": "^0.12.9",
66
+ "tsdown": "^0.14.0",
67
67
  "typescript": "^5.8.3",
68
68
  "zod": "^3.25.76"
69
69
  },