@@ -14,13 +14,15 @@ import type {
1414 $ZodPipe ,
1515 $ZodReadonly ,
1616 $ZodRecord ,
17+ $ZodString ,
18+ $ZodTransform ,
1719 $ZodTuple ,
1820 $ZodUnion ,
1921} from "@zod/core" ;
2022import * as R from "ramda" ;
2123import ts from "typescript" ;
2224import { globalRegistry , z } from "zod" ;
23- import { getTransformedType } from "./common-helpers" ;
25+ import { doesAccept , getTransformedType , isSchema } from "./common-helpers" ;
2426import { ezDateInBrand } from "./date-in-schema" ;
2527import { ezDateOutBrand } from "./date-out-schema" ;
2628import { ezFileBrand , FileSchema } from "./file-schema" ;
@@ -92,10 +94,8 @@ const onObject: Producer = (
9294 const members = Object . entries ( def . shape ) . map < ts . TypeElement > (
9395 ( [ key , value ] ) => {
9496 const isOptional = isResponse
95- ? value . _zod . def . type === "optional"
96- : value . _zod . def . type !== "promise" &&
97- value instanceof z . ZodType &&
98- value . isOptional ( ) ;
97+ ? isSchema < $ZodOptional > ( value , "optional" )
98+ : doesAccept ( value , undefined ) ;
9999 const { description : comment , deprecated : isDeprecated } =
100100 globalRegistry . get ( value ) || { } ;
101101 return makeInterfaceProp ( key , next ( value ) , {
@@ -184,24 +184,22 @@ const onPipeline: Producer = (
184184) => {
185185 const target = def [ isResponse ? "out" : "in" ] ;
186186 const opposite = def [ isResponse ? "in" : "out" ] ;
187- if ( target instanceof z . ZodTransform ) {
188- const opposingType = next ( opposite ) ;
189- const targetType = getTransformedType ( target , makeSample ( opposingType ) ) ;
190- const resolutions : Partial <
191- Record < NonNullable < typeof targetType > , ts . KeywordTypeSyntaxKind >
192- > = {
193- number : ts . SyntaxKind . NumberKeyword ,
194- bigint : ts . SyntaxKind . BigIntKeyword ,
195- boolean : ts . SyntaxKind . BooleanKeyword ,
196- string : ts . SyntaxKind . StringKeyword ,
197- undefined : ts . SyntaxKind . UndefinedKeyword ,
198- object : ts . SyntaxKind . ObjectKeyword ,
199- } ;
200- return ensureTypeNode (
201- ( targetType && resolutions [ targetType ] ) || ts . SyntaxKind . AnyKeyword ,
202- ) ;
203- }
204- return next ( target ) ;
187+ if ( ! isSchema < $ZodTransform > ( target , "transform" ) ) return next ( target ) ;
188+ const opposingType = next ( opposite ) ;
189+ const targetType = getTransformedType ( target , makeSample ( opposingType ) ) ;
190+ const resolutions : Partial <
191+ Record < NonNullable < typeof targetType > , ts . KeywordTypeSyntaxKind >
192+ > = {
193+ number : ts . SyntaxKind . NumberKeyword ,
194+ bigint : ts . SyntaxKind . BigIntKeyword ,
195+ boolean : ts . SyntaxKind . BooleanKeyword ,
196+ string : ts . SyntaxKind . StringKeyword ,
197+ undefined : ts . SyntaxKind . UndefinedKeyword ,
198+ object : ts . SyntaxKind . ObjectKeyword ,
199+ } ;
200+ return ensureTypeNode (
201+ ( targetType && resolutions [ targetType ] ) || ts . SyntaxKind . AnyKeyword ,
202+ ) ;
205203} ;
206204
207205const onNull : Producer = ( ) => makeLiteralType ( null ) ;
@@ -213,9 +211,9 @@ const onFile: Producer = (schema: FileSchema) => {
213211 const stringType = ensureTypeNode ( ts . SyntaxKind . StringKeyword ) ;
214212 const bufferType = ensureTypeNode ( "Buffer" ) ;
215213 const unionType = f . createUnionTypeNode ( [ stringType , bufferType ] ) ;
216- return schema . _zod . def . type === "string"
214+ return isSchema < $ZodString > ( schema , "string" )
217215 ? stringType
218- : schema . _zod . def . type === "union"
216+ : isSchema < $ZodUnion > ( schema , "union" )
219217 ? unionType
220218 : bufferType ;
221219} ;
0 commit comments