11import { NextFunction , Request , Response } from "express" ;
22import { z } from "zod/v4" ;
3- import { FlatObject } from "./common-helpers" ;
3+ import { emptySchema , FlatObject } from "./common-helpers" ;
44import { InputValidationError } from "./errors" ;
55import { IOSchema } from "./io-schema" ;
66import { LogicalContainer } from "./logical-container" ;
@@ -47,11 +47,7 @@ export class Middleware<
4747 readonly #security?: LogicalContainer <
4848 Security < Extract < keyof z . input < IN > , string > , SCO >
4949 > ;
50- readonly #handler: Handler <
51- IN extends IOSchema ? z . output < IN > : undefined ,
52- OPT ,
53- OUT
54- > ;
50+ readonly #handler: Handler < z . output < IN > , OPT , OUT > ;
5551
5652 constructor ( {
5753 input,
@@ -69,7 +65,7 @@ export class Middleware<
6965 Security < Extract < keyof z . input < IN > , string > , SCO >
7066 > ;
7167 /** @desc The handler returning options available to Endpoints */
72- handler : Handler < IN extends IOSchema ? z . output < IN > : undefined , OPT , OUT > ;
68+ handler : Handler < z . output < IN > , OPT , OUT > ;
7369 } ) {
7470 super ( ) ;
7571 this . #schema = input as IN ;
@@ -99,9 +95,9 @@ export class Middleware<
9995 logger : ActualLogger ;
10096 } ) {
10197 try {
102- const validInput = (
103- this . #schema ? await this . #schema . parseAsync ( input ) : undefined
104- ) as IN extends IOSchema ? z . output < IN > : undefined ;
98+ const validInput = ( await ( this . #schema || emptySchema ) . parseAsync (
99+ input ,
100+ ) ) as z . output < IN > ;
105101 return this . #handler( { ...rest , input : validInput } ) ;
106102 } catch ( e ) {
107103 throw e instanceof z . ZodError ? new InputValidationError ( e ) : e ;
0 commit comments