express-zod-api 16.4.0-beta2 → 16.4.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/dist/index.cjs CHANGED
@@ -15,7 +15,7 @@ Original error: ${e.originalError.message}.`:""))};var yr=e=>typeof e=="object"&
15
15
  \x1B[94m 888\x1B[3m Proudly supports transgender community.\x1B[23m\x1B[39m
16
16
  \x1B[94m\x1B[3mfor Nina \x1B[23m888\x1B[3m Start your API server with I/O schema validation and custom middlewares in minutes.\x1B[23m\x1B[39m
17
17
  \x1B[90m\x1B[3m Thank you for choosing Express Zod API for your project.\x1B[23m\x1B[39m
18
- `;var Ct=({app:e,rootLogger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(Ar()),t.debug("Running","v16.4.0-beta2 (CJS)"),de({routing:o,hasCors:!!r.cors,onEndpoint:(i,s,a)=>{e[a](s,async(p,d)=>{let c=r.childLoggerProvider?await r.childLoggerProvider({request:p,parent:t}):t;c.info(`${p.method}: ${s}`),await i.execute({request:p,response:d,logger:c,config:r})})},onStatic:(i,s)=>{e.use(i,s)}})};var It=R(require("http-errors"),1);var Pr=({errorHandler:e,rootLogger:t,getChildLogger:r})=>async(o,i,s,a)=>{if(!o)return a();e.handler({error:(0,It.default)(400,ye(o).message),request:i,response:s,input:null,output:null,logger:r?await r({request:i,parent:t}):t})},Cr=({errorHandler:e,getChildLogger:t,rootLogger:r})=>async(o,i)=>{let s=(0,It.default)(404,`Can not ${o.method} ${o.path}`),a=t?await t({request:o,parent:r}):r;try{e.handler({request:o,response:i,logger:a,error:s,input:null,output:null})}catch(p){Ye({response:i,logger:a,error:new re(ye(p).message,s)})}};var wr=async e=>{let t=Sr(e.logger)?nt({...e.logger,winston:await pe("winston")}):e.logger,r=e.errorHandler||he,{childLoggerProvider:o}=e,i={errorHandler:r,rootLogger:t,getChildLogger:o},s=Cr(i),a=Pr(i);return{rootLogger:t,errorHandler:r,notFoundHandler:s,parserFailureHandler:a}},Zr=async(e,t)=>{let{rootLogger:r,notFoundHandler:o}=await wr(e);return Ct({app:e.app,routing:t,rootLogger:r,config:e}),{notFoundHandler:o,logger:r}},zr=async(e,t)=>{let r=(0,Et.default)().disable("x-powered-by");if(e.server.compression){let d=await pe("compression");r.use(d(typeof e.server.compression=="object"?e.server.compression:void 0))}if(r.use(e.server.jsonParser||Et.default.json()),e.server.upload){let d=await pe("express-fileupload");r.use(d({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}))}e.server.rawParser&&(r.use(e.server.rawParser),r.use((d,{},c)=>{Buffer.isBuffer(d.body)&&(d.body={raw:d.body}),c()}));let{rootLogger:o,notFoundHandler:i,parserFailureHandler:s}=await wr(e);r.use(s),Ct({app:r,routing:t,rootLogger:o,config:e}),r.use(i);let a=(d,c)=>d.listen(c,()=>{o.info("Listening",c)}),p={httpServer:a(Ir.default.createServer(r),e.server.listen),httpsServer:e.https?a(Er.default.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...p,logger:o}};var Wr=R(require("assert/strict"),1),Yr=require("openapi3-ts/oas31");var le=R(require("assert/strict"),1),me=require("openapi3-ts/oas31"),Se=require("ramda"),O=require("zod");var wt=require("zod");var je="DateIn",Mr=()=>j(je,wt.z.string().regex(Be).transform(e=>new Date(e)).pipe(wt.z.date().refine(Fe)));var vr=require("zod");var De="DateOut",Nr=()=>j(De,vr.z.date().refine(Fe).transform(e=>e.toISOString()));var ce=({schema:e,onEach:t,rules:r,onMissing:o,...i})=>{let s=Ie(e,"kind")||e._def.typeName,a=s?r[s]:void 0,p=i,c=a?a({schema:e,...p,next:m=>ce({...m,...p,onEach:t,rules:r,onMissing:o})}):o({schema:e,...p}),l=t&&t({schema:e,prev:c,...p});return l?{...c,...l}:c};var jr=50,Lr="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",Po={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},kr=/:([A-Za-z0-9_]+)/g,Hr=e=>{let t=e.match(kr);return t?t.map(r=>r.slice(1)):[]},Ur=e=>e.replace(kr,t=>`{${t.slice(1)}}`),Co=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),Io=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),Eo=()=>({format:"any"}),wo=e=>((0,le.default)(!e.isResponse,new I({message:"Please use ez.upload() only for input.",...e})),{type:"string",format:"binary"}),Zo=({schema:e})=>({type:"string",format:e instanceof O.z.ZodString?e._def.checks.find(t=>t.kind==="regex")?"byte":"file":"binary"}),zo=({schema:{options:e},next:t})=>({oneOf:e.map(r=>t({schema:r}))}),Mo=({schema:{options:e,discriminator:t},next:r})=>({discriminator:{propertyName:t},oneOf:Array.from(e.values()).map(o=>r({schema:o}))}),vo=({schema:{_def:{left:e,right:t}},next:r})=>({allOf:[e,t].map(o=>r({schema:o}))}),No=({schema:e,next:t})=>t({schema:e.unwrap()}),jo=({schema:e,next:t})=>t({schema:e._def.innerType}),Do=({schema:e,next:t})=>{let r=t({schema:e.unwrap()});return(0,me.isReferenceObject)(r)||(r.type=Kr(r)),r},Dr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),Lo=({schema:{value:e}})=>({type:typeof e,enum:[e]}),ko=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(s=>{let a=e.shape[s];return!(t&&Ne(a)?a instanceof O.z.ZodOptional:a.isOptional())}),i={type:"object",properties:it({schema:e,isResponse:t,...r})};return o.length&&(i.required=o),i},Ho=()=>({type:"null"}),Uo=e=>((0,le.default)(!e.isResponse,new I({message:"Please use ez.dateOut() for output.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:Be.source,externalDocs:{url:Lr}}),Ko=e=>((0,le.default)(e.isResponse,new I({message:"Please use ez.dateIn() for input.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:Lr}}),Fo=e=>le.default.fail(new I({message:`Using z.date() within ${e.isResponse?"output":"input"} schema is forbidden. Please use ez.date${e.isResponse?"Out":"In"}() instead. Check out the documentation for details.`,...e})),Bo=()=>({type:"boolean"}),qo=()=>({type:"integer",format:"bigint"}),Vo=e=>e.reduce((t,r)=>t&&r instanceof O.z.ZodLiteral,!0),$o=({schema:{keySchema:e,valueSchema:t},...r})=>{if(e instanceof O.z.ZodEnum||e instanceof O.z.ZodNativeEnum){let o=Object.values(e.enum),i=o.reduce((a,p)=>({...a,[p]:t}),{}),s={type:"object",properties:it({schema:O.z.object(i),...r})};return o.length&&(s.required=o),s}if(e instanceof O.z.ZodLiteral)return{type:"object",properties:it({schema:O.z.object({[e.value]:t}),...r}),required:[e.value]};if(e instanceof O.z.ZodUnion&&Vo(e.options)){let o=e.options.reduce((i,s)=>({...i,[`${s.value}`]:t}),{});return{type:"object",properties:it({schema:O.z.object(o),...r}),required:e.options.map(i=>i.value)}}return{type:"object",additionalProperties:r.next({schema:t})}},_o=({schema:{_def:e,element:t},next:r})=>{let o={type:"array",items:r({schema:t})};return e.minLength&&(o.minItems=e.minLength.value),e.maxLength&&(o.maxItems=e.maxLength.value),o},Go=({schema:{items:e},next:t})=>({type:"array",prefixItems:e.map(o=>t({schema:o}))}),Wo=({schema:{isEmail:e,isURL:t,minLength:r,maxLength:o,isUUID:i,isCUID:s,isCUID2:a,isULID:p,isIP:d,isEmoji:c,isDatetime:l,_def:{checks:m}}})=>{let f=m.find(x=>x.kind==="regex"),T=m.find(x=>x.kind==="datetime"),g=f?f.regex:T?T.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"):void 0,S={type:"string"},y={"date-time":l,email:e,url:t,uuid:i,cuid:s,cuid2:a,ulid:p,ip:d,emoji:c};for(let x in y)if(y[x]){S.format=x;break}return r!==null&&(S.minLength=r),o!==null&&(S.maxLength=o),g&&(S.pattern=g.source),S},Yo=({schema:e})=>{let t=e._def.checks.find(({kind:d})=>d==="min"),r=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,o=t?t.inclusive:!0,i=e._def.checks.find(({kind:d})=>d==="max"),s=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,a=i?i.inclusive:!0,p={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return o?p.minimum=r:p.exclusiveMinimum=r,a?p.maximum=s:p.exclusiveMaximum=s,p},it=({schema:{shape:e},next:t})=>Object.keys(e).reduce((r,o)=>({...r,[o]:t({schema:e[o]})}),{}),Jo=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return Po?.[t]},Kr=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Qo=({schema:e,isResponse:t,next:r})=>{let o=r({schema:e.innerType()}),{effect:i}=e._def;if(t&&i.type==="transform"&&!(0,me.isReferenceObject)(o)){let s=We(e,Jo(o));return s&&["number","string","boolean"].includes(s)?{type:s}:r({schema:O.z.any()})}if(!t&&i.type==="preprocess"&&!(0,me.isReferenceObject)(o)){let{type:s,...a}=o;return{...a,format:`${a.format||s} (preprocessed)`}}return o},Xo=({schema:e,isResponse:t,next:r})=>r({schema:e._def[t?"out":"in"]}),en=({schema:e,next:t})=>t({schema:e.unwrap()}),tn=({next:e,schema:t,serializer:r,getRef:o,makeRef:i})=>{let s=r(t.schema);return o(s)||(i(s,{}),i(s,e({schema:t.schema})))},rn=({next:e,schema:t})=>e({schema:t.shape.raw}),Fr=(e,t,r=[])=>{let o=q({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>({...i,[`example${a+1}`]:{value:typeof s=="object"&&!Array.isArray(s)?(0,Se.omit)(r,s):s}}),{})},on=(e,t,r)=>{let o=q({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>r in s?{...i,[`example${a+1}`]:{value:s[r]}}:i,{})},Le=(e,t)=>{if(e instanceof O.z.ZodObject)return e;let r;return e instanceof O.z.ZodUnion||e instanceof O.z.ZodDiscriminatedUnion?r=Array.from(e.options.values()).map(o=>Le(o,t)).reduce((o,i)=>o.merge(i.partial()),O.z.object({})):e instanceof O.z.ZodEffects?((0,le.default)(!W(e),new I({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=Le(e._def.schema,t)):r=Le(e._def.left,t).merge(Le(e._def.right,t)),Ke(e,r)},Br=({path:e,method:t,schema:r,inputSources:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${t.toUpperCase()} ${e} Parameter`})=>{let c=Le(r,{path:e,method:t,isResponse:!1}).shape,l=Hr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),S=y=>T&&Tt(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=ce({schema:c[y],isResponse:!1,rules:zt,onEach:Mt,onMissing:vt,serializer:i,getRef:s,makeRef:a,path:e,method:t}),k=p==="components"?a(M(d,y),x):x;return{name:y,in:g(y)?"path":S(y)?"header":"query",required:!c[y].isOptional(),description:x.description||d,schema:k,examples:on(r,!1,y)}})},zt={ZodString:Wo,ZodNumber:Yo,ZodBigInt:qo,ZodBoolean:Bo,ZodNull:Ho,ZodArray:_o,ZodTuple:Go,ZodRecord:$o,ZodObject:ko,ZodLiteral:Lo,ZodIntersection:vo,ZodUnion:zo,ZodAny:Eo,ZodDefault:Co,ZodEnum:Dr,ZodNativeEnum:Dr,ZodEffects:Qo,ZodOptional:No,ZodNullable:Do,ZodDiscriminatedUnion:Mo,ZodBranded:en,ZodDate:Fo,ZodCatch:Io,ZodPipeline:Xo,ZodLazy:tn,ZodReadonly:jo,[ze]:Zo,[Me]:wo,[De]:Ko,[je]:Uo,[ne]:rn},Mt=({schema:e,isResponse:t,prev:r})=>{if((0,me.isReferenceObject)(r))return{};let{description:o}=e,i=e instanceof O.z.ZodLazy,s=r.type!==void 0,a=t&&Ne(e),p=!i&&s&&!a&&e.isNullable(),d=i?[]:q({schema:e,variant:t?"parsed":"original",validate:!0}),c={};return o&&(c.description=o),p&&(c.type=Kr(r)),d.length&&(c.examples=Array.from(d)),c},vt=({schema:e,...t})=>le.default.fail(new I({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),Zt=(e,t)=>{if((0,me.isReferenceObject)(e))return e;let r=e.properties?(0,Se.omit)(t,e.properties):void 0,o=e.examples?e.examples.map(p=>(0,Se.omit)(t,p)):void 0,i=e.required?e.required.filter(p=>!t.includes(p)):void 0,s=e.allOf?e.allOf.map(p=>Zt(p,t)):void 0,a=e.oneOf?e.oneOf.map(p=>Zt(p,t)):void 0;return(0,Se.omit)(Object.entries({properties:r,required:i,examples:o,allOf:s,oneOf:a}).filter(([{},p])=>p===void 0).map(([p])=>p),{...e,properties:r,required:i,examples:o,allOf:s,oneOf:a})},qr=e=>(0,me.isReferenceObject)(e)?e:(0,Se.omit)(["examples"],e),Vr=({method:e,path:t,schema:r,mimeTypes:o,variant:i,serializer:s,getRef:a,makeRef:p,composition:d,hasMultipleStatusCodes:c,statusCode:l,description:m=`${e.toUpperCase()} ${t} ${St(i)} response ${c?l:""}`.trim()})=>{let f=qr(ce({schema:r,isResponse:!0,rules:zt,onEach:Mt,onMissing:vt,serializer:s,getRef:a,makeRef:p,path:t,method:e})),T=Fr(r,!0),g=d==="components"?p(M(m),f):f;return{description:m,content:o.reduce((S,y)=>({...S,[y]:{schema:g,examples:T}}),{})}},nn=()=>({type:"http",scheme:"basic"}),sn=({format:e})=>{let t={type:"http",scheme:"bearer"};return e&&(t.bearerFormat=e),t},an=({name:e},t)=>{let r={type:"apiKey",in:"query",name:e};return t?.includes("body")&&(t?.includes("query")?(r["x-in-alternative"]="body",r.description=`${e} CAN also be supplied within the request body`):(r["x-in-actual"]="body",r.description=`${e} MUST be supplied within the request body instead of query`)),r},pn=({name:e})=>({type:"apiKey",in:"header",name:e}),dn=({name:e})=>({type:"apiKey",in:"cookie",name:e}),cn=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),mn=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((t,r)=>{let o=e[r];if(!o)return t;let{scopes:i={},...s}=o;return{...t,[r]:{...s,scopes:i}}},{})}),$r=(e,t)=>{let r={basic:nn,bearer:sn,input:an,header:pn,cookie:dn,openid:cn,oauth2:mn};return Qe(e,o=>r[o.type](o,t))},st=e=>{if(typeof e=="object"){if("or"in e)return e.or.map(t=>("and"in t?t.and:[t]).reduce((r,{name:o,scopes:i})=>({...r,[o]:i}),{}));if("and"in e)return st(Ot(e))}return st({or:[e]})},_r=({method:e,path:t,schema:r,mimeTypes:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${e.toUpperCase()} ${t} Request body`})=>{let c=Hr(t),l=qr(Zt(ce({schema:r,isResponse:!1,rules:zt,onEach:Mt,onMissing:vt,serializer:i,getRef:s,makeRef:a,path:t,method:e}),c)),m=Fr(r,!1,c),f=p==="components"?a(M(d),l):l;return{description:d,content:o.reduce((T,g)=>({...T,[g]:{schema:f,examples:m}}),{})}},Gr=e=>Object.keys(e).map(t=>{let r=e[t],o={name:t,description:typeof r=="string"?r:r.description};return typeof r=="object"&&r.url&&(o.externalDocs={url:r.url}),o}),Nt=e=>e.length<=jr?e:e.slice(0,jr-1)+"\u2026";var at=class extends Yr.OpenApiBuilder{lastSecuritySchemaIds={};lastOperationIdSuffixes={};makeRef(t,r){return this.addSchema(t,r),this.getRef(t)}getRef(t){return t in(this.rootDoc.components?.schemas||{})?{$ref:`#/components/schemas/${t}`}:void 0}ensureUniqOperationId(t,r,o){if(o)return(0,Wr.default)(!(o in this.lastOperationIdSuffixes),new I({message:`Duplicated operationId: "${o}"`,method:r,isResponse:!1,path:t})),this.lastOperationIdSuffixes[o]=1,o;let i=M(r,t);return i in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[i]++,`${i}${this.lastOperationIdSuffixes[i]}`):(this.lastOperationIdSuffixes[i]=1,i)}ensureUniqSecuritySchemaName(t){let r=JSON.stringify(t);for(let o in this.rootDoc.components?.securitySchemes||{})if(r===JSON.stringify(this.rootDoc.components?.securitySchemes?.[o]))return o;return this.lastSecuritySchemaIds[t.type]=(this.lastSecuritySchemaIds?.[t.type]||0)+1,`${t.type.toUpperCase()}_${this.lastSecuritySchemaIds[t.type]}`}constructor({routing:t,config:r,title:o,version:i,serverUrl:s,descriptions:a,hasSummaryFromDescription:p=!0,composition:d="inline",serializer:c=Ge}){super(),this.addInfo({title:o,version:i});for(let m of typeof s=="string"?[s]:s)this.addServer({url:m});de({routing:t,onEndpoint:(m,f,T)=>{let g=T,S={path:f,method:g,endpoint:m,composition:d,serializer:c,getRef:this.getRef.bind(this),makeRef:this.makeRef.bind(this)},[y,x]=["short","long"].map(m.getDescription.bind(m)),k=r.inputSources?.[g]||_e[g],w=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Q=Br({...S,inputSources:k,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:w})}),P={operationId:w,responses:{}};for(let H of["positive","negative"]){let X=m.getResponses(H);for(let{mimeTypes:Ae,schema:ft,statusCodes:b}of X)for(let C of b)P.responses[C]=Vr({...S,variant:H,schema:ft,mimeTypes:Ae,statusCode:C,hasMultipleStatusCodes:X.length>1||b.length>1,description:a?.[`${H}Response`]?.call(null,{method:g,path:f,operationId:w,statusCode:C})})}x&&(P.description=x,p&&y===void 0&&(P.summary=Nt(x))),y&&(P.summary=Nt(y)),m.getTags().length>0&&(P.tags=m.getTags()),Q.length>0&&(P.parameters=Q),k.includes("body")&&(P.requestBody=_r({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:w})}));let $=st(Qe($r(m.getSecurity(),k),H=>{let X=this.ensureUniqSecuritySchemaName(H),Ae=["oauth2","openIdConnect"].includes(H.type)?m.getScopes():[];return this.addSecurityScheme(X,H),{name:X,scopes:Ae}}));$.length>0&&(P.security=$),this.addPath(Ur(f),{[g]:P})}}),this.rootDoc.tags=r.tags?Gr(r.tags):[]}};var jt=R(require("http"),1);var ln=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>B),...t}),un=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:jt.default.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=jt.default.STATUS_CODES[o],r)),json:e(()=>r),send:e(()=>r),end:e(()=>(r.writableEnded=!0,r)),...t};return r},fn=({fnMethod:e,loggerProps:t})=>({info:e(),warn:e(),error:e(),debug:e(),...t}),Jr=async({endpoint:e,requestProps:t,responseProps:r,configProps:o,loggerProps:i,fnMethod:s})=>{let a=s||(await Rr([{moduleName:"vitest",moduleExport:"vi"},{moduleName:"@jest/globals",moduleExport:"jest"}])).fn,p=ln({fnMethod:a,requestProps:t}),d=un({fnMethod:a,responseProps:r}),c=fn({fnMethod:a,loggerProps:i}),l={cors:!1,logger:c,...o};return await e.execute({request:p,response:d,config:l,logger:c}),{requestMock:p,responseMock:d,loggerMock:c}};var E=R(require("typescript"),1);var L=R(require("typescript"),1),n=L.default.factory,Y=[n.createModifier(L.default.SyntaxKind.ExportKeyword)],yn=[n.createModifier(L.default.SyntaxKind.AsyncKeyword)],gn=[n.createModifier(L.default.SyntaxKind.PublicKeyword),n.createModifier(L.default.SyntaxKind.ReadonlyKeyword)],Qr=[n.createModifier(L.default.SyntaxKind.ProtectedKeyword),n.createModifier(L.default.SyntaxKind.ReadonlyKeyword)],Dt=n.createTemplateHead(""),Oe=n.createTemplateTail(""),Lt=n.createTemplateMiddle(" "),kt=e=>n.createTemplateLiteralType(Dt,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?Oe:Lt))),Ht=kt(["M","P"]),pt=(e,t,r)=>n.createParameterDeclaration(r,void 0,e,void 0,t,void 0),dt=(e,t)=>Object.keys(e).reduce((r,o)=>r.concat(pt(n.createIdentifier(o),e[o],t)),[]),Ut=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Xr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),eo=(e,t)=>n.createPropertySignature(void 0,`"${e}"`,void 0,n.createTypeReferenceNode(t)),J=(e,t,r)=>n.createVariableDeclarationList([n.createVariableDeclaration(e,void 0,r,t)],L.default.NodeFlags.Const),Kt=(e,t)=>n.createTypeAliasDeclaration(Y,e,void 0,n.createUnionTypeNode(t.map(r=>n.createLiteralTypeNode(n.createStringLiteral(r))))),ct=(e,t)=>n.createTypeAliasDeclaration(Y,e,void 0,t),to=(e,t,r)=>n.createPropertyDeclaration(gn,e,void 0,t,r),ro=(e,t,r=[])=>n.createClassDeclaration(Y,e,void 0,void 0,[t,...r]),oo=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),no=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(L.default.SyntaxKind.AnyKeyword)]),io=(e,t,r)=>n.createInterfaceDeclaration(Y,e,void 0,t,r),so=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),Ft=(e,t,r)=>n.createArrowFunction(r?yn:void 0,void 0,e.map(o=>pt(o)),void 0,void 0,t),Bt=(e,t,r)=>n.createCallExpression(n.createPropertyAccessExpression(n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("Object"),"keys"),void 0,[e]),"reduce"),void 0,[n.createArrowFunction(void 0,void 0,dt({acc:void 0,key:void 0}),void 0,void 0,t),r]);var ao=["get","post","put","delete","patch"];var h=R(require("typescript"),1),lt=require("zod");var V=R(require("typescript"),1),{factory:mt}=V.default,qt=(e,t)=>{V.default.addSyntheticLeadingComment(e,V.default.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},Re=(e,t,r)=>{let o=mt.createTypeAliasDeclaration(void 0,mt.createIdentifier(t),void 0,e);return r&&qt(o,r),o},Vt=(e,t)=>{let r=V.default.createSourceFile("print.ts","",V.default.ScriptTarget.Latest,!1,V.default.ScriptKind.TS);return V.default.createPrinter(t).printNode(V.default.EmitHint.Unspecified,e,r)},hn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,po=e=>hn.test(e)?mt.createIdentifier(e):mt.createStringLiteral(e);var{factory:u}=h.default,xn={[h.default.SyntaxKind.AnyKeyword]:"",[h.default.SyntaxKind.BigIntKeyword]:BigInt(0),[h.default.SyntaxKind.BooleanKeyword]:!1,[h.default.SyntaxKind.NumberKeyword]:0,[h.default.SyntaxKind.ObjectKeyword]:{},[h.default.SyntaxKind.StringKeyword]:"",[h.default.SyntaxKind.UndefinedKeyword]:void 0},Tn=({schema:{value:e}})=>u.createLiteralTypeNode(typeof e=="number"?u.createNumericLiteral(e):typeof e=="boolean"?e?u.createTrue():u.createFalse():u.createStringLiteral(e)),bn=({schema:{shape:e},isResponse:t,next:r,optionalPropStyle:{withQuestionMark:o}})=>{let i=Object.entries(e).map(([s,a])=>{let p=t&&Ne(a)?a instanceof lt.z.ZodOptional:a.isOptional(),d=u.createPropertySignature(void 0,po(s),p&&o?u.createToken(h.default.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&qt(d,a.description),d});return u.createTypeLiteralNode(i)},Sn=({schema:{element:e},next:t})=>u.createArrayTypeNode(t({schema:e})),On=({schema:{options:e}})=>u.createUnionTypeNode(e.map(t=>u.createLiteralTypeNode(u.createStringLiteral(t)))),co=({schema:{options:e},next:t})=>u.createUnionTypeNode(e.map(r=>t({schema:r}))),Rn=e=>xn?.[e.kind],An=({schema:e,next:t,isResponse:r})=>{let o=t({schema:e.innerType()}),i=e._def.effect;if(r&&i.type==="transform"){let s=We(e,Rn(o)),a={number:h.default.SyntaxKind.NumberKeyword,bigint:h.default.SyntaxKind.BigIntKeyword,boolean:h.default.SyntaxKind.BooleanKeyword,string:h.default.SyntaxKind.StringKeyword,undefined:h.default.SyntaxKind.UndefinedKeyword,object:h.default.SyntaxKind.ObjectKeyword};return u.createKeywordTypeNode(s&&a[s]||h.default.SyntaxKind.AnyKeyword)}return o},Pn=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(t=>u.createLiteralTypeNode(typeof t=="number"?u.createNumericLiteral(t):u.createStringLiteral(t)))),Cn=({next:e,schema:t,optionalPropStyle:{withUndefined:r}})=>{let o=e({schema:t.unwrap()});return r?u.createUnionTypeNode([o,u.createKeywordTypeNode(h.default.SyntaxKind.UndefinedKeyword)]):o},In=({next:e,schema:t})=>u.createUnionTypeNode([e({schema:t.unwrap()}),u.createLiteralTypeNode(u.createNull())]),En=({next:e,schema:{items:t}})=>u.createTupleTypeNode(t.map(r=>e({schema:r}))),wn=({next:e,schema:{keySchema:t,valueSchema:r}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:t}),e({schema:r})]),Zn=({next:e,schema:t})=>u.createIntersectionTypeNode([t._def.left,t._def.right].map(r=>e({schema:r}))),zn=({next:e,schema:t})=>e({schema:t._def.innerType}),ue=e=>()=>u.createKeywordTypeNode(e),Mn=({next:e,schema:t})=>e({schema:t.unwrap()}),vn=({next:e,schema:t})=>e({schema:t._def.innerType}),Nn=({next:e,schema:t})=>e({schema:t._def.innerType}),jn=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),Dn=()=>u.createLiteralTypeNode(u.createNull()),Ln=({getAlias:e,makeAlias:t,next:r,serializer:o,schema:i})=>{let s=`Type${o(i.schema)}`;return e(s)||(t(s,u.createLiteralTypeNode(u.createNull())),t(s,r({schema:i.schema})))},kn=({schema:e})=>{let t=u.createKeywordTypeNode(h.default.SyntaxKind.StringKeyword),r=u.createTypeReferenceNode("Buffer"),o=u.createUnionTypeNode([t,r]);return e instanceof lt.z.ZodString?t:e instanceof lt.z.ZodUnion?o:r},Hn=({next:e,schema:t})=>e({schema:t.shape.raw}),Un={ZodString:ue(h.default.SyntaxKind.StringKeyword),ZodNumber:ue(h.default.SyntaxKind.NumberKeyword),ZodBigInt:ue(h.default.SyntaxKind.BigIntKeyword),ZodBoolean:ue(h.default.SyntaxKind.BooleanKeyword),ZodAny:ue(h.default.SyntaxKind.AnyKeyword),[je]:ue(h.default.SyntaxKind.StringKeyword),[De]:ue(h.default.SyntaxKind.StringKeyword),ZodNull:Dn,ZodArray:Sn,ZodTuple:En,ZodRecord:wn,ZodObject:bn,ZodLiteral:Tn,ZodIntersection:Zn,ZodUnion:co,ZodDefault:zn,ZodEnum:On,ZodNativeEnum:Pn,ZodEffects:An,ZodOptional:Cn,ZodNullable:In,ZodDiscriminatedUnion:co,ZodBranded:Mn,ZodCatch:Nn,ZodPipeline:jn,ZodLazy:Ln,ZodReadonly:vn,[ze]:kn,[ne]:Hn},ke=({schema:e,...t})=>ce({schema:e,rules:Un,onMissing:()=>u.createKeywordTypeNode(h.default.SyntaxKind.AnyKeyword),...t});var ut=class{program=[];usage=[];registry={};paths=[];aliases={};ids={pathType:n.createIdentifier("Path"),methodType:n.createIdentifier("Method"),methodPathType:n.createIdentifier("MethodPath"),inputInterface:n.createIdentifier("Input"),posResponseInterface:n.createIdentifier("PositiveResponse"),negResponseInterface:n.createIdentifier("NegativeResponse"),responseInterface:n.createIdentifier("Response"),jsonEndpointsConst:n.createIdentifier("jsonEndpoints"),endpointTagsConst:n.createIdentifier("endpointTags"),providerType:n.createIdentifier("Provider"),implementationType:n.createIdentifier("Implementation"),clientClass:n.createIdentifier("ExpressZodAPIClient"),keyParameter:n.createIdentifier("key"),pathParameter:n.createIdentifier("path"),paramsArgument:n.createIdentifier("params"),methodParameter:n.createIdentifier("method"),accumulator:n.createIdentifier("acc"),provideMethod:n.createIdentifier("provide"),implementationArgument:n.createIdentifier("implementation"),headersProperty:n.createIdentifier("headers"),hasBodyConst:n.createIdentifier("hasBody"),undefinedValue:n.createIdentifier("undefined"),bodyProperty:n.createIdentifier("body"),responseConst:n.createIdentifier("response"),searchParamsConst:n.createIdentifier("searchParams"),exampleImplementationConst:n.createIdentifier("exampleImplementation"),clientConst:n.createIdentifier("client")};interfaces=[];getAlias(t){return t in this.aliases?n.createTypeReferenceNode(t):void 0}makeAlias(t,r){return this.aliases[t]=Re(r,t),this.getAlias(t)}constructor({routing:t,variant:r="client",serializer:o=Ge,splitResponse:i=!1,optionalPropStyle:s={withQuestionMark:!0,withUndefined:!0}}){de({routing:t,onEndpoint:(b,C,Z)=>{let ee={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:s},$t=M(Z,C,"input"),lo=ke({...ee,schema:b.getSchema("input"),isResponse:!1}),Pe=i?M(Z,C,"positive.response"):void 0,_t=b.getSchema("positive"),Gt=i?ke({...ee,isResponse:!0,schema:_t}):void 0,Ce=i?M(Z,C,"negative.response"):void 0,Wt=b.getSchema("negative"),Yt=i?ke({...ee,isResponse:!0,schema:Wt}):void 0,Jt=M(Z,C,"response"),uo=Pe&&Ce?n.createUnionTypeNode([n.createTypeReferenceNode(Pe),n.createTypeReferenceNode(Ce)]):ke({...ee,isResponse:!0,schema:_t.or(Wt)});this.program.push(Re(lo,$t)),Gt&&Pe&&this.program.push(Re(Gt,Pe)),Yt&&Ce&&this.program.push(Re(Yt,Ce)),this.program.push(Re(uo,Jt)),Z!=="options"&&(this.paths.push(C),this.registry[`${Z} ${C}`]={input:$t,positive:Pe,negative:Ce,response:Jt,isJson:b.getMimeTypes("positive").includes(B),tags:b.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(Kt(this.ids.pathType,this.paths)),this.program.push(Kt(this.ids.methodType,ao)),this.program.push(ct(this.ids.methodPathType,kt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(E.default.SyntaxKind.ExtendsKeyword,[Ut(this.ids.methodPathType,E.default.SyntaxKind.AnyKeyword)])];this.interfaces.push({id:this.ids.inputInterface,kind:"input"}),i&&this.interfaces.push({id:this.ids.posResponseInterface,kind:"positive"},{id:this.ids.negResponseInterface,kind:"negative"}),this.interfaces.push({id:this.ids.responseInterface,kind:"response"});for(let{id:b,kind:C}of this.interfaces)this.program.push(io(b,a,Object.keys(this.registry).map(Z=>{let ee=this.registry[Z][C];return ee?eo(Z,ee):void 0}).filter(Z=>Z!==void 0)));if(r==="types")return;let p=n.createVariableStatement(Y,J(this.ids.jsonEndpointsConst,n.createObjectLiteralExpression(Object.keys(this.registry).filter(b=>this.registry[b].isJson).map(b=>n.createPropertyAssignment(`"${b}"`,n.createTrue()))))),d=n.createVariableStatement(Y,J(this.ids.endpointTagsConst,n.createObjectLiteralExpression(Object.keys(this.registry).map(b=>n.createPropertyAssignment(`"${b}"`,n.createArrayLiteralExpression(this.registry[b].tags.map(C=>n.createStringLiteral(C)))))))),c=ct(this.ids.providerType,n.createFunctionTypeNode(so({M:this.ids.methodType,P:this.ids.pathType}),dt({method:n.createTypeReferenceNode("M"),path:n.createTypeReferenceNode("P"),params:n.createIndexedAccessTypeNode(n.createTypeReferenceNode(this.ids.inputInterface),Ht)}),oo(this.ids.responseInterface,Ht))),l=ct(this.ids.implementationType,n.createFunctionTypeNode(void 0,dt({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(E.default.SyntaxKind.StringKeyword),params:Ut(E.default.SyntaxKind.StringKeyword,E.default.SyntaxKind.AnyKeyword)}),no())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,Oe)]),f=Bt(this.ids.paramsArgument,n.createCallExpression(n.createPropertyAccessExpression(this.ids.accumulator,"replace"),void 0,[m,n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter)]),this.ids.pathParameter),T=Bt(this.ids.paramsArgument,n.createConditionalExpression(n.createBinaryExpression(n.createCallExpression(n.createPropertyAccessExpression(this.ids.pathParameter,"indexOf"),void 0,[m]),E.default.SyntaxKind.GreaterThanEqualsToken,n.createNumericLiteral(0)),void 0,this.ids.accumulator,void 0,n.createObjectLiteralExpression([n.createSpreadAssignment(this.ids.accumulator),n.createPropertyAssignment(n.createComputedPropertyName(this.ids.keyParameter),n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter))])),n.createObjectLiteralExpression()),g=ro(this.ids.clientClass,Xr([pt(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),Qr)]),[to(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),Ft([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createCallExpression(n.createPropertyAccessExpression(n.createThis(),this.ids.implementationArgument),void 0,[this.ids.methodParameter,f,T]),!0))]);this.program.push(p,d,c,l,g);let S=n.createPropertyAssignment(this.ids.methodParameter,n.createCallExpression(n.createPropertyAccessExpression(this.ids.methodParameter,"toUpperCase"),void 0,void 0)),y=n.createPropertyAssignment(this.ids.headersProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createObjectLiteralExpression([n.createPropertyAssignment(n.createStringLiteral("Content-Type"),n.createStringLiteral(B))]),void 0,this.ids.undefinedValue)),x=n.createPropertyAssignment(this.ids.bodyProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("JSON"),"stringify"),void 0,[this.ids.paramsArgument]),void 0,this.ids.undefinedValue)),k=n.createVariableStatement(void 0,J(this.ids.responseConst,n.createAwaitExpression(n.createCallExpression(n.createIdentifier("fetch"),void 0,[n.createTemplateExpression(n.createTemplateHead("https://example.com"),[n.createTemplateSpan(this.ids.pathParameter,n.createTemplateMiddle("")),n.createTemplateSpan(this.ids.searchParamsConst,Oe)]),n.createObjectLiteralExpression([S,y,x])])))),w=n.createVariableStatement(void 0,J(this.ids.hasBodyConst,n.createLogicalNot(n.createCallExpression(n.createPropertyAccessExpression(n.createArrayLiteralExpression([n.createStringLiteral("get"),n.createStringLiteral("delete")]),"includes"),void 0,[this.ids.methodParameter])))),Q=n.createVariableStatement(void 0,J(this.ids.searchParamsConst,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createStringLiteral(""),void 0,n.createTemplateExpression(n.createTemplateHead("?"),[n.createTemplateSpan(n.createNewExpression(n.createIdentifier("URLSearchParams"),void 0,[this.ids.paramsArgument]),Oe)])))),[P,$]=["json","text"].map(b=>n.createReturnStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.responseConst,b),void 0,void 0))),H=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(Dt,[n.createTemplateSpan(this.ids.methodParameter,Lt),n.createTemplateSpan(this.ids.pathParameter,Oe)]),E.default.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([P])),X=n.createVariableStatement(Y,J(this.ids.exampleImplementationConst,Ft([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([w,Q,k,H,$]),!0),n.createTypeReferenceNode(this.ids.implementationType))),Ae=n.createExpressionStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.clientConst,this.ids.provideMethod),void 0,[n.createStringLiteral("get"),n.createStringLiteral("/v1/user/retrieve"),n.createObjectLiteralExpression([n.createPropertyAssignment("id",n.createStringLiteral("10"))])])),ft=n.createVariableStatement(void 0,J(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(X,ft,Ae)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:Vt(r,t)).join(`
18
+ `;var Ct=({app:e,rootLogger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(Ar()),t.debug("Running","v16.4.0 (CJS)"),de({routing:o,hasCors:!!r.cors,onEndpoint:(i,s,a)=>{e[a](s,async(p,d)=>{let c=r.childLoggerProvider?await r.childLoggerProvider({request:p,parent:t}):t;c.info(`${p.method}: ${s}`),await i.execute({request:p,response:d,logger:c,config:r})})},onStatic:(i,s)=>{e.use(i,s)}})};var It=R(require("http-errors"),1);var Pr=({errorHandler:e,rootLogger:t,getChildLogger:r})=>async(o,i,s,a)=>{if(!o)return a();e.handler({error:(0,It.default)(400,ye(o).message),request:i,response:s,input:null,output:null,logger:r?await r({request:i,parent:t}):t})},Cr=({errorHandler:e,getChildLogger:t,rootLogger:r})=>async(o,i)=>{let s=(0,It.default)(404,`Can not ${o.method} ${o.path}`),a=t?await t({request:o,parent:r}):r;try{e.handler({request:o,response:i,logger:a,error:s,input:null,output:null})}catch(p){Ye({response:i,logger:a,error:new re(ye(p).message,s)})}};var wr=async e=>{let t=Sr(e.logger)?nt({...e.logger,winston:await pe("winston")}):e.logger,r=e.errorHandler||he,{childLoggerProvider:o}=e,i={errorHandler:r,rootLogger:t,getChildLogger:o},s=Cr(i),a=Pr(i);return{rootLogger:t,errorHandler:r,notFoundHandler:s,parserFailureHandler:a}},Zr=async(e,t)=>{let{rootLogger:r,notFoundHandler:o}=await wr(e);return Ct({app:e.app,routing:t,rootLogger:r,config:e}),{notFoundHandler:o,logger:r}},zr=async(e,t)=>{let r=(0,Et.default)().disable("x-powered-by");if(e.server.compression){let d=await pe("compression");r.use(d(typeof e.server.compression=="object"?e.server.compression:void 0))}if(r.use(e.server.jsonParser||Et.default.json()),e.server.upload){let d=await pe("express-fileupload");r.use(d({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}))}e.server.rawParser&&(r.use(e.server.rawParser),r.use((d,{},c)=>{Buffer.isBuffer(d.body)&&(d.body={raw:d.body}),c()}));let{rootLogger:o,notFoundHandler:i,parserFailureHandler:s}=await wr(e);r.use(s),Ct({app:r,routing:t,rootLogger:o,config:e}),r.use(i);let a=(d,c)=>d.listen(c,()=>{o.info("Listening",c)}),p={httpServer:a(Ir.default.createServer(r),e.server.listen),httpsServer:e.https?a(Er.default.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...p,logger:o}};var Wr=R(require("assert/strict"),1),Yr=require("openapi3-ts/oas31");var le=R(require("assert/strict"),1),me=require("openapi3-ts/oas31"),Se=require("ramda"),O=require("zod");var wt=require("zod");var je="DateIn",Mr=()=>j(je,wt.z.string().regex(Be).transform(e=>new Date(e)).pipe(wt.z.date().refine(Fe)));var vr=require("zod");var De="DateOut",Nr=()=>j(De,vr.z.date().refine(Fe).transform(e=>e.toISOString()));var ce=({schema:e,onEach:t,rules:r,onMissing:o,...i})=>{let s=Ie(e,"kind")||e._def.typeName,a=s?r[s]:void 0,p=i,c=a?a({schema:e,...p,next:m=>ce({...m,...p,onEach:t,rules:r,onMissing:o})}):o({schema:e,...p}),l=t&&t({schema:e,prev:c,...p});return l?{...c,...l}:c};var jr=50,Lr="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",Po={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},kr=/:([A-Za-z0-9_]+)/g,Hr=e=>{let t=e.match(kr);return t?t.map(r=>r.slice(1)):[]},Ur=e=>e.replace(kr,t=>`{${t.slice(1)}}`),Co=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),Io=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),Eo=()=>({format:"any"}),wo=e=>((0,le.default)(!e.isResponse,new I({message:"Please use ez.upload() only for input.",...e})),{type:"string",format:"binary"}),Zo=({schema:e})=>({type:"string",format:e instanceof O.z.ZodString?e._def.checks.find(t=>t.kind==="regex")?"byte":"file":"binary"}),zo=({schema:{options:e},next:t})=>({oneOf:e.map(r=>t({schema:r}))}),Mo=({schema:{options:e,discriminator:t},next:r})=>({discriminator:{propertyName:t},oneOf:Array.from(e.values()).map(o=>r({schema:o}))}),vo=({schema:{_def:{left:e,right:t}},next:r})=>({allOf:[e,t].map(o=>r({schema:o}))}),No=({schema:e,next:t})=>t({schema:e.unwrap()}),jo=({schema:e,next:t})=>t({schema:e._def.innerType}),Do=({schema:e,next:t})=>{let r=t({schema:e.unwrap()});return(0,me.isReferenceObject)(r)||(r.type=Kr(r)),r},Dr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),Lo=({schema:{value:e}})=>({type:typeof e,enum:[e]}),ko=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(s=>{let a=e.shape[s];return!(t&&Ne(a)?a instanceof O.z.ZodOptional:a.isOptional())}),i={type:"object",properties:it({schema:e,isResponse:t,...r})};return o.length&&(i.required=o),i},Ho=()=>({type:"null"}),Uo=e=>((0,le.default)(!e.isResponse,new I({message:"Please use ez.dateOut() for output.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:Be.source,externalDocs:{url:Lr}}),Ko=e=>((0,le.default)(e.isResponse,new I({message:"Please use ez.dateIn() for input.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:Lr}}),Fo=e=>le.default.fail(new I({message:`Using z.date() within ${e.isResponse?"output":"input"} schema is forbidden. Please use ez.date${e.isResponse?"Out":"In"}() instead. Check out the documentation for details.`,...e})),Bo=()=>({type:"boolean"}),qo=()=>({type:"integer",format:"bigint"}),Vo=e=>e.reduce((t,r)=>t&&r instanceof O.z.ZodLiteral,!0),$o=({schema:{keySchema:e,valueSchema:t},...r})=>{if(e instanceof O.z.ZodEnum||e instanceof O.z.ZodNativeEnum){let o=Object.values(e.enum),i=o.reduce((a,p)=>({...a,[p]:t}),{}),s={type:"object",properties:it({schema:O.z.object(i),...r})};return o.length&&(s.required=o),s}if(e instanceof O.z.ZodLiteral)return{type:"object",properties:it({schema:O.z.object({[e.value]:t}),...r}),required:[e.value]};if(e instanceof O.z.ZodUnion&&Vo(e.options)){let o=e.options.reduce((i,s)=>({...i,[`${s.value}`]:t}),{});return{type:"object",properties:it({schema:O.z.object(o),...r}),required:e.options.map(i=>i.value)}}return{type:"object",additionalProperties:r.next({schema:t})}},_o=({schema:{_def:e,element:t},next:r})=>{let o={type:"array",items:r({schema:t})};return e.minLength&&(o.minItems=e.minLength.value),e.maxLength&&(o.maxItems=e.maxLength.value),o},Go=({schema:{items:e},next:t})=>({type:"array",prefixItems:e.map(o=>t({schema:o}))}),Wo=({schema:{isEmail:e,isURL:t,minLength:r,maxLength:o,isUUID:i,isCUID:s,isCUID2:a,isULID:p,isIP:d,isEmoji:c,isDatetime:l,_def:{checks:m}}})=>{let f=m.find(x=>x.kind==="regex"),T=m.find(x=>x.kind==="datetime"),g=f?f.regex:T?T.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"):void 0,S={type:"string"},y={"date-time":l,email:e,url:t,uuid:i,cuid:s,cuid2:a,ulid:p,ip:d,emoji:c};for(let x in y)if(y[x]){S.format=x;break}return r!==null&&(S.minLength=r),o!==null&&(S.maxLength=o),g&&(S.pattern=g.source),S},Yo=({schema:e})=>{let t=e._def.checks.find(({kind:d})=>d==="min"),r=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,o=t?t.inclusive:!0,i=e._def.checks.find(({kind:d})=>d==="max"),s=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,a=i?i.inclusive:!0,p={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return o?p.minimum=r:p.exclusiveMinimum=r,a?p.maximum=s:p.exclusiveMaximum=s,p},it=({schema:{shape:e},next:t})=>Object.keys(e).reduce((r,o)=>({...r,[o]:t({schema:e[o]})}),{}),Jo=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return Po?.[t]},Kr=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Qo=({schema:e,isResponse:t,next:r})=>{let o=r({schema:e.innerType()}),{effect:i}=e._def;if(t&&i.type==="transform"&&!(0,me.isReferenceObject)(o)){let s=We(e,Jo(o));return s&&["number","string","boolean"].includes(s)?{type:s}:r({schema:O.z.any()})}if(!t&&i.type==="preprocess"&&!(0,me.isReferenceObject)(o)){let{type:s,...a}=o;return{...a,format:`${a.format||s} (preprocessed)`}}return o},Xo=({schema:e,isResponse:t,next:r})=>r({schema:e._def[t?"out":"in"]}),en=({schema:e,next:t})=>t({schema:e.unwrap()}),tn=({next:e,schema:t,serializer:r,getRef:o,makeRef:i})=>{let s=r(t.schema);return o(s)||(i(s,{}),i(s,e({schema:t.schema})))},rn=({next:e,schema:t})=>e({schema:t.shape.raw}),Fr=(e,t,r=[])=>{let o=q({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>({...i,[`example${a+1}`]:{value:typeof s=="object"&&!Array.isArray(s)?(0,Se.omit)(r,s):s}}),{})},on=(e,t,r)=>{let o=q({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>r in s?{...i,[`example${a+1}`]:{value:s[r]}}:i,{})},Le=(e,t)=>{if(e instanceof O.z.ZodObject)return e;let r;return e instanceof O.z.ZodUnion||e instanceof O.z.ZodDiscriminatedUnion?r=Array.from(e.options.values()).map(o=>Le(o,t)).reduce((o,i)=>o.merge(i.partial()),O.z.object({})):e instanceof O.z.ZodEffects?((0,le.default)(!W(e),new I({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=Le(e._def.schema,t)):r=Le(e._def.left,t).merge(Le(e._def.right,t)),Ke(e,r)},Br=({path:e,method:t,schema:r,inputSources:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${t.toUpperCase()} ${e} Parameter`})=>{let c=Le(r,{path:e,method:t,isResponse:!1}).shape,l=Hr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),S=y=>T&&Tt(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=ce({schema:c[y],isResponse:!1,rules:zt,onEach:Mt,onMissing:vt,serializer:i,getRef:s,makeRef:a,path:e,method:t}),k=p==="components"?a(M(d,y),x):x;return{name:y,in:g(y)?"path":S(y)?"header":"query",required:!c[y].isOptional(),description:x.description||d,schema:k,examples:on(r,!1,y)}})},zt={ZodString:Wo,ZodNumber:Yo,ZodBigInt:qo,ZodBoolean:Bo,ZodNull:Ho,ZodArray:_o,ZodTuple:Go,ZodRecord:$o,ZodObject:ko,ZodLiteral:Lo,ZodIntersection:vo,ZodUnion:zo,ZodAny:Eo,ZodDefault:Co,ZodEnum:Dr,ZodNativeEnum:Dr,ZodEffects:Qo,ZodOptional:No,ZodNullable:Do,ZodDiscriminatedUnion:Mo,ZodBranded:en,ZodDate:Fo,ZodCatch:Io,ZodPipeline:Xo,ZodLazy:tn,ZodReadonly:jo,[ze]:Zo,[Me]:wo,[De]:Ko,[je]:Uo,[ne]:rn},Mt=({schema:e,isResponse:t,prev:r})=>{if((0,me.isReferenceObject)(r))return{};let{description:o}=e,i=e instanceof O.z.ZodLazy,s=r.type!==void 0,a=t&&Ne(e),p=!i&&s&&!a&&e.isNullable(),d=i?[]:q({schema:e,variant:t?"parsed":"original",validate:!0}),c={};return o&&(c.description=o),p&&(c.type=Kr(r)),d.length&&(c.examples=Array.from(d)),c},vt=({schema:e,...t})=>le.default.fail(new I({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),Zt=(e,t)=>{if((0,me.isReferenceObject)(e))return e;let r=e.properties?(0,Se.omit)(t,e.properties):void 0,o=e.examples?e.examples.map(p=>(0,Se.omit)(t,p)):void 0,i=e.required?e.required.filter(p=>!t.includes(p)):void 0,s=e.allOf?e.allOf.map(p=>Zt(p,t)):void 0,a=e.oneOf?e.oneOf.map(p=>Zt(p,t)):void 0;return(0,Se.omit)(Object.entries({properties:r,required:i,examples:o,allOf:s,oneOf:a}).filter(([{},p])=>p===void 0).map(([p])=>p),{...e,properties:r,required:i,examples:o,allOf:s,oneOf:a})},qr=e=>(0,me.isReferenceObject)(e)?e:(0,Se.omit)(["examples"],e),Vr=({method:e,path:t,schema:r,mimeTypes:o,variant:i,serializer:s,getRef:a,makeRef:p,composition:d,hasMultipleStatusCodes:c,statusCode:l,description:m=`${e.toUpperCase()} ${t} ${St(i)} response ${c?l:""}`.trim()})=>{let f=qr(ce({schema:r,isResponse:!0,rules:zt,onEach:Mt,onMissing:vt,serializer:s,getRef:a,makeRef:p,path:t,method:e})),T=Fr(r,!0),g=d==="components"?p(M(m),f):f;return{description:m,content:o.reduce((S,y)=>({...S,[y]:{schema:g,examples:T}}),{})}},nn=()=>({type:"http",scheme:"basic"}),sn=({format:e})=>{let t={type:"http",scheme:"bearer"};return e&&(t.bearerFormat=e),t},an=({name:e},t)=>{let r={type:"apiKey",in:"query",name:e};return t?.includes("body")&&(t?.includes("query")?(r["x-in-alternative"]="body",r.description=`${e} CAN also be supplied within the request body`):(r["x-in-actual"]="body",r.description=`${e} MUST be supplied within the request body instead of query`)),r},pn=({name:e})=>({type:"apiKey",in:"header",name:e}),dn=({name:e})=>({type:"apiKey",in:"cookie",name:e}),cn=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),mn=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((t,r)=>{let o=e[r];if(!o)return t;let{scopes:i={},...s}=o;return{...t,[r]:{...s,scopes:i}}},{})}),$r=(e,t)=>{let r={basic:nn,bearer:sn,input:an,header:pn,cookie:dn,openid:cn,oauth2:mn};return Qe(e,o=>r[o.type](o,t))},st=e=>{if(typeof e=="object"){if("or"in e)return e.or.map(t=>("and"in t?t.and:[t]).reduce((r,{name:o,scopes:i})=>({...r,[o]:i}),{}));if("and"in e)return st(Ot(e))}return st({or:[e]})},_r=({method:e,path:t,schema:r,mimeTypes:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${e.toUpperCase()} ${t} Request body`})=>{let c=Hr(t),l=qr(Zt(ce({schema:r,isResponse:!1,rules:zt,onEach:Mt,onMissing:vt,serializer:i,getRef:s,makeRef:a,path:t,method:e}),c)),m=Fr(r,!1,c),f=p==="components"?a(M(d),l):l;return{description:d,content:o.reduce((T,g)=>({...T,[g]:{schema:f,examples:m}}),{})}},Gr=e=>Object.keys(e).map(t=>{let r=e[t],o={name:t,description:typeof r=="string"?r:r.description};return typeof r=="object"&&r.url&&(o.externalDocs={url:r.url}),o}),Nt=e=>e.length<=jr?e:e.slice(0,jr-1)+"\u2026";var at=class extends Yr.OpenApiBuilder{lastSecuritySchemaIds={};lastOperationIdSuffixes={};makeRef(t,r){return this.addSchema(t,r),this.getRef(t)}getRef(t){return t in(this.rootDoc.components?.schemas||{})?{$ref:`#/components/schemas/${t}`}:void 0}ensureUniqOperationId(t,r,o){if(o)return(0,Wr.default)(!(o in this.lastOperationIdSuffixes),new I({message:`Duplicated operationId: "${o}"`,method:r,isResponse:!1,path:t})),this.lastOperationIdSuffixes[o]=1,o;let i=M(r,t);return i in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[i]++,`${i}${this.lastOperationIdSuffixes[i]}`):(this.lastOperationIdSuffixes[i]=1,i)}ensureUniqSecuritySchemaName(t){let r=JSON.stringify(t);for(let o in this.rootDoc.components?.securitySchemes||{})if(r===JSON.stringify(this.rootDoc.components?.securitySchemes?.[o]))return o;return this.lastSecuritySchemaIds[t.type]=(this.lastSecuritySchemaIds?.[t.type]||0)+1,`${t.type.toUpperCase()}_${this.lastSecuritySchemaIds[t.type]}`}constructor({routing:t,config:r,title:o,version:i,serverUrl:s,descriptions:a,hasSummaryFromDescription:p=!0,composition:d="inline",serializer:c=Ge}){super(),this.addInfo({title:o,version:i});for(let m of typeof s=="string"?[s]:s)this.addServer({url:m});de({routing:t,onEndpoint:(m,f,T)=>{let g=T,S={path:f,method:g,endpoint:m,composition:d,serializer:c,getRef:this.getRef.bind(this),makeRef:this.makeRef.bind(this)},[y,x]=["short","long"].map(m.getDescription.bind(m)),k=r.inputSources?.[g]||_e[g],w=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Q=Br({...S,inputSources:k,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:w})}),P={operationId:w,responses:{}};for(let H of["positive","negative"]){let X=m.getResponses(H);for(let{mimeTypes:Ae,schema:ft,statusCodes:b}of X)for(let C of b)P.responses[C]=Vr({...S,variant:H,schema:ft,mimeTypes:Ae,statusCode:C,hasMultipleStatusCodes:X.length>1||b.length>1,description:a?.[`${H}Response`]?.call(null,{method:g,path:f,operationId:w,statusCode:C})})}x&&(P.description=x,p&&y===void 0&&(P.summary=Nt(x))),y&&(P.summary=Nt(y)),m.getTags().length>0&&(P.tags=m.getTags()),Q.length>0&&(P.parameters=Q),k.includes("body")&&(P.requestBody=_r({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:w})}));let $=st(Qe($r(m.getSecurity(),k),H=>{let X=this.ensureUniqSecuritySchemaName(H),Ae=["oauth2","openIdConnect"].includes(H.type)?m.getScopes():[];return this.addSecurityScheme(X,H),{name:X,scopes:Ae}}));$.length>0&&(P.security=$),this.addPath(Ur(f),{[g]:P})}}),this.rootDoc.tags=r.tags?Gr(r.tags):[]}};var jt=R(require("http"),1);var ln=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>B),...t}),un=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:jt.default.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=jt.default.STATUS_CODES[o],r)),json:e(()=>r),send:e(()=>r),end:e(()=>(r.writableEnded=!0,r)),...t};return r},fn=({fnMethod:e,loggerProps:t})=>({info:e(),warn:e(),error:e(),debug:e(),...t}),Jr=async({endpoint:e,requestProps:t,responseProps:r,configProps:o,loggerProps:i,fnMethod:s})=>{let a=s||(await Rr([{moduleName:"vitest",moduleExport:"vi"},{moduleName:"@jest/globals",moduleExport:"jest"}])).fn,p=ln({fnMethod:a,requestProps:t}),d=un({fnMethod:a,responseProps:r}),c=fn({fnMethod:a,loggerProps:i}),l={cors:!1,logger:c,...o};return await e.execute({request:p,response:d,config:l,logger:c}),{requestMock:p,responseMock:d,loggerMock:c}};var E=R(require("typescript"),1);var L=R(require("typescript"),1),n=L.default.factory,Y=[n.createModifier(L.default.SyntaxKind.ExportKeyword)],yn=[n.createModifier(L.default.SyntaxKind.AsyncKeyword)],gn=[n.createModifier(L.default.SyntaxKind.PublicKeyword),n.createModifier(L.default.SyntaxKind.ReadonlyKeyword)],Qr=[n.createModifier(L.default.SyntaxKind.ProtectedKeyword),n.createModifier(L.default.SyntaxKind.ReadonlyKeyword)],Dt=n.createTemplateHead(""),Oe=n.createTemplateTail(""),Lt=n.createTemplateMiddle(" "),kt=e=>n.createTemplateLiteralType(Dt,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?Oe:Lt))),Ht=kt(["M","P"]),pt=(e,t,r)=>n.createParameterDeclaration(r,void 0,e,void 0,t,void 0),dt=(e,t)=>Object.keys(e).reduce((r,o)=>r.concat(pt(n.createIdentifier(o),e[o],t)),[]),Ut=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Xr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),eo=(e,t)=>n.createPropertySignature(void 0,`"${e}"`,void 0,n.createTypeReferenceNode(t)),J=(e,t,r)=>n.createVariableDeclarationList([n.createVariableDeclaration(e,void 0,r,t)],L.default.NodeFlags.Const),Kt=(e,t)=>n.createTypeAliasDeclaration(Y,e,void 0,n.createUnionTypeNode(t.map(r=>n.createLiteralTypeNode(n.createStringLiteral(r))))),ct=(e,t)=>n.createTypeAliasDeclaration(Y,e,void 0,t),to=(e,t,r)=>n.createPropertyDeclaration(gn,e,void 0,t,r),ro=(e,t,r=[])=>n.createClassDeclaration(Y,e,void 0,void 0,[t,...r]),oo=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),no=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(L.default.SyntaxKind.AnyKeyword)]),io=(e,t,r)=>n.createInterfaceDeclaration(Y,e,void 0,t,r),so=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),Ft=(e,t,r)=>n.createArrowFunction(r?yn:void 0,void 0,e.map(o=>pt(o)),void 0,void 0,t),Bt=(e,t,r)=>n.createCallExpression(n.createPropertyAccessExpression(n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("Object"),"keys"),void 0,[e]),"reduce"),void 0,[n.createArrowFunction(void 0,void 0,dt({acc:void 0,key:void 0}),void 0,void 0,t),r]);var ao=["get","post","put","delete","patch"];var h=R(require("typescript"),1),lt=require("zod");var V=R(require("typescript"),1),{factory:mt}=V.default,qt=(e,t)=>{V.default.addSyntheticLeadingComment(e,V.default.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},Re=(e,t,r)=>{let o=mt.createTypeAliasDeclaration(void 0,mt.createIdentifier(t),void 0,e);return r&&qt(o,r),o},Vt=(e,t)=>{let r=V.default.createSourceFile("print.ts","",V.default.ScriptTarget.Latest,!1,V.default.ScriptKind.TS);return V.default.createPrinter(t).printNode(V.default.EmitHint.Unspecified,e,r)},hn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,po=e=>hn.test(e)?mt.createIdentifier(e):mt.createStringLiteral(e);var{factory:u}=h.default,xn={[h.default.SyntaxKind.AnyKeyword]:"",[h.default.SyntaxKind.BigIntKeyword]:BigInt(0),[h.default.SyntaxKind.BooleanKeyword]:!1,[h.default.SyntaxKind.NumberKeyword]:0,[h.default.SyntaxKind.ObjectKeyword]:{},[h.default.SyntaxKind.StringKeyword]:"",[h.default.SyntaxKind.UndefinedKeyword]:void 0},Tn=({schema:{value:e}})=>u.createLiteralTypeNode(typeof e=="number"?u.createNumericLiteral(e):typeof e=="boolean"?e?u.createTrue():u.createFalse():u.createStringLiteral(e)),bn=({schema:{shape:e},isResponse:t,next:r,optionalPropStyle:{withQuestionMark:o}})=>{let i=Object.entries(e).map(([s,a])=>{let p=t&&Ne(a)?a instanceof lt.z.ZodOptional:a.isOptional(),d=u.createPropertySignature(void 0,po(s),p&&o?u.createToken(h.default.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&qt(d,a.description),d});return u.createTypeLiteralNode(i)},Sn=({schema:{element:e},next:t})=>u.createArrayTypeNode(t({schema:e})),On=({schema:{options:e}})=>u.createUnionTypeNode(e.map(t=>u.createLiteralTypeNode(u.createStringLiteral(t)))),co=({schema:{options:e},next:t})=>u.createUnionTypeNode(e.map(r=>t({schema:r}))),Rn=e=>xn?.[e.kind],An=({schema:e,next:t,isResponse:r})=>{let o=t({schema:e.innerType()}),i=e._def.effect;if(r&&i.type==="transform"){let s=We(e,Rn(o)),a={number:h.default.SyntaxKind.NumberKeyword,bigint:h.default.SyntaxKind.BigIntKeyword,boolean:h.default.SyntaxKind.BooleanKeyword,string:h.default.SyntaxKind.StringKeyword,undefined:h.default.SyntaxKind.UndefinedKeyword,object:h.default.SyntaxKind.ObjectKeyword};return u.createKeywordTypeNode(s&&a[s]||h.default.SyntaxKind.AnyKeyword)}return o},Pn=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(t=>u.createLiteralTypeNode(typeof t=="number"?u.createNumericLiteral(t):u.createStringLiteral(t)))),Cn=({next:e,schema:t,optionalPropStyle:{withUndefined:r}})=>{let o=e({schema:t.unwrap()});return r?u.createUnionTypeNode([o,u.createKeywordTypeNode(h.default.SyntaxKind.UndefinedKeyword)]):o},In=({next:e,schema:t})=>u.createUnionTypeNode([e({schema:t.unwrap()}),u.createLiteralTypeNode(u.createNull())]),En=({next:e,schema:{items:t}})=>u.createTupleTypeNode(t.map(r=>e({schema:r}))),wn=({next:e,schema:{keySchema:t,valueSchema:r}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:t}),e({schema:r})]),Zn=({next:e,schema:t})=>u.createIntersectionTypeNode([t._def.left,t._def.right].map(r=>e({schema:r}))),zn=({next:e,schema:t})=>e({schema:t._def.innerType}),ue=e=>()=>u.createKeywordTypeNode(e),Mn=({next:e,schema:t})=>e({schema:t.unwrap()}),vn=({next:e,schema:t})=>e({schema:t._def.innerType}),Nn=({next:e,schema:t})=>e({schema:t._def.innerType}),jn=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),Dn=()=>u.createLiteralTypeNode(u.createNull()),Ln=({getAlias:e,makeAlias:t,next:r,serializer:o,schema:i})=>{let s=`Type${o(i.schema)}`;return e(s)||(t(s,u.createLiteralTypeNode(u.createNull())),t(s,r({schema:i.schema})))},kn=({schema:e})=>{let t=u.createKeywordTypeNode(h.default.SyntaxKind.StringKeyword),r=u.createTypeReferenceNode("Buffer"),o=u.createUnionTypeNode([t,r]);return e instanceof lt.z.ZodString?t:e instanceof lt.z.ZodUnion?o:r},Hn=({next:e,schema:t})=>e({schema:t.shape.raw}),Un={ZodString:ue(h.default.SyntaxKind.StringKeyword),ZodNumber:ue(h.default.SyntaxKind.NumberKeyword),ZodBigInt:ue(h.default.SyntaxKind.BigIntKeyword),ZodBoolean:ue(h.default.SyntaxKind.BooleanKeyword),ZodAny:ue(h.default.SyntaxKind.AnyKeyword),[je]:ue(h.default.SyntaxKind.StringKeyword),[De]:ue(h.default.SyntaxKind.StringKeyword),ZodNull:Dn,ZodArray:Sn,ZodTuple:En,ZodRecord:wn,ZodObject:bn,ZodLiteral:Tn,ZodIntersection:Zn,ZodUnion:co,ZodDefault:zn,ZodEnum:On,ZodNativeEnum:Pn,ZodEffects:An,ZodOptional:Cn,ZodNullable:In,ZodDiscriminatedUnion:co,ZodBranded:Mn,ZodCatch:Nn,ZodPipeline:jn,ZodLazy:Ln,ZodReadonly:vn,[ze]:kn,[ne]:Hn},ke=({schema:e,...t})=>ce({schema:e,rules:Un,onMissing:()=>u.createKeywordTypeNode(h.default.SyntaxKind.AnyKeyword),...t});var ut=class{program=[];usage=[];registry={};paths=[];aliases={};ids={pathType:n.createIdentifier("Path"),methodType:n.createIdentifier("Method"),methodPathType:n.createIdentifier("MethodPath"),inputInterface:n.createIdentifier("Input"),posResponseInterface:n.createIdentifier("PositiveResponse"),negResponseInterface:n.createIdentifier("NegativeResponse"),responseInterface:n.createIdentifier("Response"),jsonEndpointsConst:n.createIdentifier("jsonEndpoints"),endpointTagsConst:n.createIdentifier("endpointTags"),providerType:n.createIdentifier("Provider"),implementationType:n.createIdentifier("Implementation"),clientClass:n.createIdentifier("ExpressZodAPIClient"),keyParameter:n.createIdentifier("key"),pathParameter:n.createIdentifier("path"),paramsArgument:n.createIdentifier("params"),methodParameter:n.createIdentifier("method"),accumulator:n.createIdentifier("acc"),provideMethod:n.createIdentifier("provide"),implementationArgument:n.createIdentifier("implementation"),headersProperty:n.createIdentifier("headers"),hasBodyConst:n.createIdentifier("hasBody"),undefinedValue:n.createIdentifier("undefined"),bodyProperty:n.createIdentifier("body"),responseConst:n.createIdentifier("response"),searchParamsConst:n.createIdentifier("searchParams"),exampleImplementationConst:n.createIdentifier("exampleImplementation"),clientConst:n.createIdentifier("client")};interfaces=[];getAlias(t){return t in this.aliases?n.createTypeReferenceNode(t):void 0}makeAlias(t,r){return this.aliases[t]=Re(r,t),this.getAlias(t)}constructor({routing:t,variant:r="client",serializer:o=Ge,splitResponse:i=!1,optionalPropStyle:s={withQuestionMark:!0,withUndefined:!0}}){de({routing:t,onEndpoint:(b,C,Z)=>{let ee={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:s},$t=M(Z,C,"input"),lo=ke({...ee,schema:b.getSchema("input"),isResponse:!1}),Pe=i?M(Z,C,"positive.response"):void 0,_t=b.getSchema("positive"),Gt=i?ke({...ee,isResponse:!0,schema:_t}):void 0,Ce=i?M(Z,C,"negative.response"):void 0,Wt=b.getSchema("negative"),Yt=i?ke({...ee,isResponse:!0,schema:Wt}):void 0,Jt=M(Z,C,"response"),uo=Pe&&Ce?n.createUnionTypeNode([n.createTypeReferenceNode(Pe),n.createTypeReferenceNode(Ce)]):ke({...ee,isResponse:!0,schema:_t.or(Wt)});this.program.push(Re(lo,$t)),Gt&&Pe&&this.program.push(Re(Gt,Pe)),Yt&&Ce&&this.program.push(Re(Yt,Ce)),this.program.push(Re(uo,Jt)),Z!=="options"&&(this.paths.push(C),this.registry[`${Z} ${C}`]={input:$t,positive:Pe,negative:Ce,response:Jt,isJson:b.getMimeTypes("positive").includes(B),tags:b.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(Kt(this.ids.pathType,this.paths)),this.program.push(Kt(this.ids.methodType,ao)),this.program.push(ct(this.ids.methodPathType,kt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(E.default.SyntaxKind.ExtendsKeyword,[Ut(this.ids.methodPathType,E.default.SyntaxKind.AnyKeyword)])];this.interfaces.push({id:this.ids.inputInterface,kind:"input"}),i&&this.interfaces.push({id:this.ids.posResponseInterface,kind:"positive"},{id:this.ids.negResponseInterface,kind:"negative"}),this.interfaces.push({id:this.ids.responseInterface,kind:"response"});for(let{id:b,kind:C}of this.interfaces)this.program.push(io(b,a,Object.keys(this.registry).map(Z=>{let ee=this.registry[Z][C];return ee?eo(Z,ee):void 0}).filter(Z=>Z!==void 0)));if(r==="types")return;let p=n.createVariableStatement(Y,J(this.ids.jsonEndpointsConst,n.createObjectLiteralExpression(Object.keys(this.registry).filter(b=>this.registry[b].isJson).map(b=>n.createPropertyAssignment(`"${b}"`,n.createTrue()))))),d=n.createVariableStatement(Y,J(this.ids.endpointTagsConst,n.createObjectLiteralExpression(Object.keys(this.registry).map(b=>n.createPropertyAssignment(`"${b}"`,n.createArrayLiteralExpression(this.registry[b].tags.map(C=>n.createStringLiteral(C)))))))),c=ct(this.ids.providerType,n.createFunctionTypeNode(so({M:this.ids.methodType,P:this.ids.pathType}),dt({method:n.createTypeReferenceNode("M"),path:n.createTypeReferenceNode("P"),params:n.createIndexedAccessTypeNode(n.createTypeReferenceNode(this.ids.inputInterface),Ht)}),oo(this.ids.responseInterface,Ht))),l=ct(this.ids.implementationType,n.createFunctionTypeNode(void 0,dt({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(E.default.SyntaxKind.StringKeyword),params:Ut(E.default.SyntaxKind.StringKeyword,E.default.SyntaxKind.AnyKeyword)}),no())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,Oe)]),f=Bt(this.ids.paramsArgument,n.createCallExpression(n.createPropertyAccessExpression(this.ids.accumulator,"replace"),void 0,[m,n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter)]),this.ids.pathParameter),T=Bt(this.ids.paramsArgument,n.createConditionalExpression(n.createBinaryExpression(n.createCallExpression(n.createPropertyAccessExpression(this.ids.pathParameter,"indexOf"),void 0,[m]),E.default.SyntaxKind.GreaterThanEqualsToken,n.createNumericLiteral(0)),void 0,this.ids.accumulator,void 0,n.createObjectLiteralExpression([n.createSpreadAssignment(this.ids.accumulator),n.createPropertyAssignment(n.createComputedPropertyName(this.ids.keyParameter),n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter))])),n.createObjectLiteralExpression()),g=ro(this.ids.clientClass,Xr([pt(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),Qr)]),[to(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),Ft([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createCallExpression(n.createPropertyAccessExpression(n.createThis(),this.ids.implementationArgument),void 0,[this.ids.methodParameter,f,T]),!0))]);this.program.push(p,d,c,l,g);let S=n.createPropertyAssignment(this.ids.methodParameter,n.createCallExpression(n.createPropertyAccessExpression(this.ids.methodParameter,"toUpperCase"),void 0,void 0)),y=n.createPropertyAssignment(this.ids.headersProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createObjectLiteralExpression([n.createPropertyAssignment(n.createStringLiteral("Content-Type"),n.createStringLiteral(B))]),void 0,this.ids.undefinedValue)),x=n.createPropertyAssignment(this.ids.bodyProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("JSON"),"stringify"),void 0,[this.ids.paramsArgument]),void 0,this.ids.undefinedValue)),k=n.createVariableStatement(void 0,J(this.ids.responseConst,n.createAwaitExpression(n.createCallExpression(n.createIdentifier("fetch"),void 0,[n.createTemplateExpression(n.createTemplateHead("https://example.com"),[n.createTemplateSpan(this.ids.pathParameter,n.createTemplateMiddle("")),n.createTemplateSpan(this.ids.searchParamsConst,Oe)]),n.createObjectLiteralExpression([S,y,x])])))),w=n.createVariableStatement(void 0,J(this.ids.hasBodyConst,n.createLogicalNot(n.createCallExpression(n.createPropertyAccessExpression(n.createArrayLiteralExpression([n.createStringLiteral("get"),n.createStringLiteral("delete")]),"includes"),void 0,[this.ids.methodParameter])))),Q=n.createVariableStatement(void 0,J(this.ids.searchParamsConst,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createStringLiteral(""),void 0,n.createTemplateExpression(n.createTemplateHead("?"),[n.createTemplateSpan(n.createNewExpression(n.createIdentifier("URLSearchParams"),void 0,[this.ids.paramsArgument]),Oe)])))),[P,$]=["json","text"].map(b=>n.createReturnStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.responseConst,b),void 0,void 0))),H=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(Dt,[n.createTemplateSpan(this.ids.methodParameter,Lt),n.createTemplateSpan(this.ids.pathParameter,Oe)]),E.default.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([P])),X=n.createVariableStatement(Y,J(this.ids.exampleImplementationConst,Ft([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([w,Q,k,H,$]),!0),n.createTypeReferenceNode(this.ids.implementationType))),Ae=n.createExpressionStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.clientConst,this.ids.provideMethod),void 0,[n.createStringLiteral("get"),n.createStringLiteral("/v1/user/retrieve"),n.createObjectLiteralExpression([n.createPropertyAssignment("id",n.createStringLiteral("10"))])])),ft=n.createVariableStatement(void 0,J(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(X,ft,Ae)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:Vt(r,t)).join(`
19
19
  `):void 0}print(t){let r=this.printUsage(t),o=r&&E.default.addSyntheticLeadingComment(E.default.addSyntheticLeadingComment(n.createEmptyStatement(),E.default.SyntaxKind.SingleLineCommentTrivia," Usage example:"),E.default.SyntaxKind.MultiLineCommentTrivia,`
20
20
  ${r}`);return this.program.concat(o||[]).map((i,s)=>Vt(i,s<this.program.length?t:{...t,omitTrailingSemicolon:!0})).join(`
21
21
 
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ Original error: ${e.originalError.message}.`:""))};var Qt=e=>typeof e=="object"&
15
15
  \x1B[94m 888\x1B[3m Proudly supports transgender community.\x1B[23m\x1B[39m
16
16
  \x1B[94m\x1B[3mfor Nina \x1B[23m888\x1B[3m Start your API server with I/O schema validation and custom middlewares in minutes.\x1B[23m\x1B[39m
17
17
  \x1B[90m\x1B[3m Thank you for choosing Express Zod API for your project.\x1B[23m\x1B[39m
18
- `;var gt=({app:e,rootLogger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(ir()),t.debug("Running","v16.4.0-beta2 (ESM)"),ie({routing:o,hasCors:!!r.cors,onEndpoint:(i,s,a)=>{e[a](s,async(p,d)=>{let c=r.childLoggerProvider?await r.childLoggerProvider({request:p,parent:t}):t;c.info(`${p.method}: ${s}`),await i.execute({request:p,response:d,logger:c,config:r})})},onStatic:(i,s)=>{e.use(i,s)}})};import sr from"http-errors";var ar=({errorHandler:e,rootLogger:t,getChildLogger:r})=>async(o,i,s,a)=>{if(!o)return a();e.handler({error:sr(400,me(o).message),request:i,response:s,input:null,output:null,logger:r?await r({request:i,parent:t}):t})},pr=({errorHandler:e,getChildLogger:t,rootLogger:r})=>async(o,i)=>{let s=sr(404,`Can not ${o.method} ${o.path}`),a=t?await t({request:o,parent:r}):r;try{e.handler({request:o,response:i,logger:a,error:s,input:null,output:null})}catch(p){$e({response:i,logger:a,error:new ee(me(p).message,s)})}};var cr=async e=>{let t=rr(e.logger)?yt({...e.logger,winston:await ne("winston")}):e.logger,r=e.errorHandler||Ee,{childLoggerProvider:o}=e,i={errorHandler:r,rootLogger:t,getChildLogger:o},s=pr(i),a=ar(i);return{rootLogger:t,errorHandler:r,notFoundHandler:s,parserFailureHandler:a}},co=async(e,t)=>{let{rootLogger:r,notFoundHandler:o}=await cr(e);return gt({app:e.app,routing:t,rootLogger:r,config:e}),{notFoundHandler:o,logger:r}},mo=async(e,t)=>{let r=dr().disable("x-powered-by");if(e.server.compression){let d=await ne("compression");r.use(d(typeof e.server.compression=="object"?e.server.compression:void 0))}if(r.use(e.server.jsonParser||dr.json()),e.server.upload){let d=await ne("express-fileupload");r.use(d({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}))}e.server.rawParser&&(r.use(e.server.rawParser),r.use((d,{},c)=>{Buffer.isBuffer(d.body)&&(d.body={raw:d.body}),c()}));let{rootLogger:o,notFoundHandler:i,parserFailureHandler:s}=await cr(e);r.use(s),gt({app:r,routing:t,rootLogger:o,config:e}),r.use(i);let a=(d,c)=>d.listen(c,()=>{o.info("Listening",c)}),p={httpServer:a(ao.createServer(r),e.server.listen),httpsServer:e.https?a(po.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...p,logger:o}};import Xo from"assert/strict";import{OpenApiBuilder as en}from"openapi3-ts/oas31";import ye from"assert/strict";import{isReferenceObject as fe}from"openapi3-ts/oas31";import{omit as je}from"ramda";import{z as O}from"zod";import{z as mr}from"zod";var Me="DateIn",lr=()=>z(Me,mr.string().regex(He).transform(e=>new Date(e)).pipe(mr.date().refine(ke)));import{z as lo}from"zod";var ve="DateOut",ur=()=>z(ve,lo.date().refine(ke).transform(e=>e.toISOString()));var se=({schema:e,onEach:t,rules:r,onMissing:o,...i})=>{let s=Se(e,"kind")||e._def.typeName,a=s?r[s]:void 0,p=i,c=a?a({schema:e,...p,next:m=>se({...m,...p,onEach:t,rules:r,onMissing:o})}):o({schema:e,...p}),l=t&&t({schema:e,prev:c,...p});return l?{...c,...l}:c};var fr=50,gr="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",uo={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},hr=/:([A-Za-z0-9_]+)/g,xr=e=>{let t=e.match(hr);return t?t.map(r=>r.slice(1)):[]},Tr=e=>e.replace(hr,t=>`{${t.slice(1)}}`),fo=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),yo=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),go=()=>({format:"any"}),ho=e=>(ye(!e.isResponse,new C({message:"Please use ez.upload() only for input.",...e})),{type:"string",format:"binary"}),xo=({schema:e})=>({type:"string",format:e instanceof O.ZodString?e._def.checks.find(t=>t.kind==="regex")?"byte":"file":"binary"}),To=({schema:{options:e},next:t})=>({oneOf:e.map(r=>t({schema:r}))}),bo=({schema:{options:e,discriminator:t},next:r})=>({discriminator:{propertyName:t},oneOf:Array.from(e.values()).map(o=>r({schema:o}))}),So=({schema:{_def:{left:e,right:t}},next:r})=>({allOf:[e,t].map(o=>r({schema:o}))}),Oo=({schema:e,next:t})=>t({schema:e.unwrap()}),Ro=({schema:e,next:t})=>t({schema:e._def.innerType}),Ao=({schema:e,next:t})=>{let r=t({schema:e.unwrap()});return fe(r)||(r.type=br(r)),r},yr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),Po=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Co=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(s=>{let a=e.shape[s];return!(t&&Ie(a)?a instanceof O.ZodOptional:a.isOptional())}),i={type:"object",properties:Ye({schema:e,isResponse:t,...r})};return o.length&&(i.required=o),i},Io=()=>({type:"null"}),Eo=e=>(ye(!e.isResponse,new C({message:"Please use ez.dateOut() for output.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:He.source,externalDocs:{url:gr}}),wo=e=>(ye(e.isResponse,new C({message:"Please use ez.dateIn() for input.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:gr}}),Zo=e=>ye.fail(new C({message:`Using z.date() within ${e.isResponse?"output":"input"} schema is forbidden. Please use ez.date${e.isResponse?"Out":"In"}() instead. Check out the documentation for details.`,...e})),zo=()=>({type:"boolean"}),Mo=()=>({type:"integer",format:"bigint"}),vo=e=>e.reduce((t,r)=>t&&r instanceof O.ZodLiteral,!0),No=({schema:{keySchema:e,valueSchema:t},...r})=>{if(e instanceof O.ZodEnum||e instanceof O.ZodNativeEnum){let o=Object.values(e.enum),i=o.reduce((a,p)=>({...a,[p]:t}),{}),s={type:"object",properties:Ye({schema:O.object(i),...r})};return o.length&&(s.required=o),s}if(e instanceof O.ZodLiteral)return{type:"object",properties:Ye({schema:O.object({[e.value]:t}),...r}),required:[e.value]};if(e instanceof O.ZodUnion&&vo(e.options)){let o=e.options.reduce((i,s)=>({...i,[`${s.value}`]:t}),{});return{type:"object",properties:Ye({schema:O.object(o),...r}),required:e.options.map(i=>i.value)}}return{type:"object",additionalProperties:r.next({schema:t})}},jo=({schema:{_def:e,element:t},next:r})=>{let o={type:"array",items:r({schema:t})};return e.minLength&&(o.minItems=e.minLength.value),e.maxLength&&(o.maxItems=e.maxLength.value),o},Do=({schema:{items:e},next:t})=>({type:"array",prefixItems:e.map(o=>t({schema:o}))}),Lo=({schema:{isEmail:e,isURL:t,minLength:r,maxLength:o,isUUID:i,isCUID:s,isCUID2:a,isULID:p,isIP:d,isEmoji:c,isDatetime:l,_def:{checks:m}}})=>{let f=m.find(x=>x.kind==="regex"),T=m.find(x=>x.kind==="datetime"),g=f?f.regex:T?T.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"):void 0,S={type:"string"},y={"date-time":l,email:e,url:t,uuid:i,cuid:s,cuid2:a,ulid:p,ip:d,emoji:c};for(let x in y)if(y[x]){S.format=x;break}return r!==null&&(S.minLength=r),o!==null&&(S.maxLength=o),g&&(S.pattern=g.source),S},ko=({schema:e})=>{let t=e._def.checks.find(({kind:d})=>d==="min"),r=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,o=t?t.inclusive:!0,i=e._def.checks.find(({kind:d})=>d==="max"),s=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,a=i?i.inclusive:!0,p={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return o?p.minimum=r:p.exclusiveMinimum=r,a?p.maximum=s:p.exclusiveMaximum=s,p},Ye=({schema:{shape:e},next:t})=>Object.keys(e).reduce((r,o)=>({...r,[o]:t({schema:e[o]})}),{}),Ho=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return uo?.[t]},br=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Uo=({schema:e,isResponse:t,next:r})=>{let o=r({schema:e.innerType()}),{effect:i}=e._def;if(t&&i.type==="transform"&&!fe(o)){let s=Ve(e,Ho(o));return s&&["number","string","boolean"].includes(s)?{type:s}:r({schema:O.any()})}if(!t&&i.type==="preprocess"&&!fe(o)){let{type:s,...a}=o;return{...a,format:`${a.format||s} (preprocessed)`}}return o},Ko=({schema:e,isResponse:t,next:r})=>r({schema:e._def[t?"out":"in"]}),Fo=({schema:e,next:t})=>t({schema:e.unwrap()}),Bo=({next:e,schema:t,serializer:r,getRef:o,makeRef:i})=>{let s=r(t.schema);return o(s)||(i(s,{}),i(s,e({schema:t.schema})))},qo=({next:e,schema:t})=>e({schema:t.shape.raw}),Sr=(e,t,r=[])=>{let o=$({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>({...i,[`example${a+1}`]:{value:typeof s=="object"&&!Array.isArray(s)?je(r,s):s}}),{})},Vo=(e,t,r)=>{let o=$({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>r in s?{...i,[`example${a+1}`]:{value:s[r]}}:i,{})},Ne=(e,t)=>{if(e instanceof O.ZodObject)return e;let r;return e instanceof O.ZodUnion||e instanceof O.ZodDiscriminatedUnion?r=Array.from(e.options.values()).map(o=>Ne(o,t)).reduce((o,i)=>o.merge(i.partial()),O.object({})):e instanceof O.ZodEffects?(ye(!V(e),new C({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=Ne(e._def.schema,t)):r=Ne(e._def.left,t).merge(Ne(e._def.right,t)),Le(e,r)},Or=({path:e,method:t,schema:r,inputSources:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${t.toUpperCase()} ${e} Parameter`})=>{let c=Ne(r,{path:e,method:t,isResponse:!1}).shape,l=xr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),S=y=>T&&at(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=se({schema:c[y],isResponse:!1,rules:xt,onEach:Tt,onMissing:bt,serializer:i,getRef:s,makeRef:a,path:e,method:t}),j=p==="components"?a(w(d,y),x):x;return{name:y,in:g(y)?"path":S(y)?"header":"query",required:!c[y].isOptional(),description:x.description||d,schema:j,examples:Vo(r,!1,y)}})},xt={ZodString:Lo,ZodNumber:ko,ZodBigInt:Mo,ZodBoolean:zo,ZodNull:Io,ZodArray:jo,ZodTuple:Do,ZodRecord:No,ZodObject:Co,ZodLiteral:Po,ZodIntersection:So,ZodUnion:To,ZodAny:go,ZodDefault:fo,ZodEnum:yr,ZodNativeEnum:yr,ZodEffects:Uo,ZodOptional:Oo,ZodNullable:Ao,ZodDiscriminatedUnion:bo,ZodBranded:Fo,ZodDate:Zo,ZodCatch:yo,ZodPipeline:Ko,ZodLazy:Bo,ZodReadonly:Ro,[Pe]:xo,[Ce]:ho,[ve]:wo,[Me]:Eo,[te]:qo},Tt=({schema:e,isResponse:t,prev:r})=>{if(fe(r))return{};let{description:o}=e,i=e instanceof O.ZodLazy,s=r.type!==void 0,a=t&&Ie(e),p=!i&&s&&!a&&e.isNullable(),d=i?[]:$({schema:e,variant:t?"parsed":"original",validate:!0}),c={};return o&&(c.description=o),p&&(c.type=br(r)),d.length&&(c.examples=Array.from(d)),c},bt=({schema:e,...t})=>ye.fail(new C({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),ht=(e,t)=>{if(fe(e))return e;let r=e.properties?je(t,e.properties):void 0,o=e.examples?e.examples.map(p=>je(t,p)):void 0,i=e.required?e.required.filter(p=>!t.includes(p)):void 0,s=e.allOf?e.allOf.map(p=>ht(p,t)):void 0,a=e.oneOf?e.oneOf.map(p=>ht(p,t)):void 0;return je(Object.entries({properties:r,required:i,examples:o,allOf:s,oneOf:a}).filter(([{},p])=>p===void 0).map(([p])=>p),{...e,properties:r,required:i,examples:o,allOf:s,oneOf:a})},Rr=e=>fe(e)?e:je(["examples"],e),Ar=({method:e,path:t,schema:r,mimeTypes:o,variant:i,serializer:s,getRef:a,makeRef:p,composition:d,hasMultipleStatusCodes:c,statusCode:l,description:m=`${e.toUpperCase()} ${t} ${dt(i)} response ${c?l:""}`.trim()})=>{let f=Rr(se({schema:r,isResponse:!0,rules:xt,onEach:Tt,onMissing:bt,serializer:s,getRef:a,makeRef:p,path:t,method:e})),T=Sr(r,!0),g=d==="components"?p(w(m),f):f;return{description:m,content:o.reduce((S,y)=>({...S,[y]:{schema:g,examples:T}}),{})}},$o=()=>({type:"http",scheme:"basic"}),_o=({format:e})=>{let t={type:"http",scheme:"bearer"};return e&&(t.bearerFormat=e),t},Go=({name:e},t)=>{let r={type:"apiKey",in:"query",name:e};return t?.includes("body")&&(t?.includes("query")?(r["x-in-alternative"]="body",r.description=`${e} CAN also be supplied within the request body`):(r["x-in-actual"]="body",r.description=`${e} MUST be supplied within the request body instead of query`)),r},Wo=({name:e})=>({type:"apiKey",in:"header",name:e}),Yo=({name:e})=>({type:"apiKey",in:"cookie",name:e}),Jo=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),Qo=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((t,r)=>{let o=e[r];if(!o)return t;let{scopes:i={},...s}=o;return{...t,[r]:{...s,scopes:i}}},{})}),Pr=(e,t)=>{let r={basic:$o,bearer:_o,input:Go,header:Wo,cookie:Yo,openid:Jo,oauth2:Qo};return Ge(e,o=>r[o.type](o,t))},Je=e=>{if(typeof e=="object"){if("or"in e)return e.or.map(t=>("and"in t?t.and:[t]).reduce((r,{name:o,scopes:i})=>({...r,[o]:i}),{}));if("and"in e)return Je(ct(e))}return Je({or:[e]})},Cr=({method:e,path:t,schema:r,mimeTypes:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${e.toUpperCase()} ${t} Request body`})=>{let c=xr(t),l=Rr(ht(se({schema:r,isResponse:!1,rules:xt,onEach:Tt,onMissing:bt,serializer:i,getRef:s,makeRef:a,path:t,method:e}),c)),m=Sr(r,!1,c),f=p==="components"?a(w(d),l):l;return{description:d,content:o.reduce((T,g)=>({...T,[g]:{schema:f,examples:m}}),{})}},Ir=e=>Object.keys(e).map(t=>{let r=e[t],o={name:t,description:typeof r=="string"?r:r.description};return typeof r=="object"&&r.url&&(o.externalDocs={url:r.url}),o}),St=e=>e.length<=fr?e:e.slice(0,fr-1)+"\u2026";var Ot=class extends en{lastSecuritySchemaIds={};lastOperationIdSuffixes={};makeRef(t,r){return this.addSchema(t,r),this.getRef(t)}getRef(t){return t in(this.rootDoc.components?.schemas||{})?{$ref:`#/components/schemas/${t}`}:void 0}ensureUniqOperationId(t,r,o){if(o)return Xo(!(o in this.lastOperationIdSuffixes),new C({message:`Duplicated operationId: "${o}"`,method:r,isResponse:!1,path:t})),this.lastOperationIdSuffixes[o]=1,o;let i=w(r,t);return i in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[i]++,`${i}${this.lastOperationIdSuffixes[i]}`):(this.lastOperationIdSuffixes[i]=1,i)}ensureUniqSecuritySchemaName(t){let r=JSON.stringify(t);for(let o in this.rootDoc.components?.securitySchemes||{})if(r===JSON.stringify(this.rootDoc.components?.securitySchemes?.[o]))return o;return this.lastSecuritySchemaIds[t.type]=(this.lastSecuritySchemaIds?.[t.type]||0)+1,`${t.type.toUpperCase()}_${this.lastSecuritySchemaIds[t.type]}`}constructor({routing:t,config:r,title:o,version:i,serverUrl:s,descriptions:a,hasSummaryFromDescription:p=!0,composition:d="inline",serializer:c=qe}){super(),this.addInfo({title:o,version:i});for(let m of typeof s=="string"?[s]:s)this.addServer({url:m});ie({routing:t,onEndpoint:(m,f,T)=>{let g=T,S={path:f,method:g,endpoint:m,composition:d,serializer:c,getRef:this.getRef.bind(this),makeRef:this.makeRef.bind(this)},[y,x]=["short","long"].map(m.getDescription.bind(m)),j=r.inputSources?.[g]||Fe[g],I=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Y=Or({...S,inputSources:j,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:I})}),R={operationId:I,responses:{}};for(let D of["positive","negative"]){let J=m.getResponses(D);for(let{mimeTypes:xe,schema:rt,statusCodes:b}of J)for(let A of b)R.responses[A]=Ar({...S,variant:D,schema:rt,mimeTypes:xe,statusCode:A,hasMultipleStatusCodes:J.length>1||b.length>1,description:a?.[`${D}Response`]?.call(null,{method:g,path:f,operationId:I,statusCode:A})})}x&&(R.description=x,p&&y===void 0&&(R.summary=St(x))),y&&(R.summary=St(y)),m.getTags().length>0&&(R.tags=m.getTags()),Y.length>0&&(R.parameters=Y),j.includes("body")&&(R.requestBody=Cr({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:I})}));let K=Je(Ge(Pr(m.getSecurity(),j),D=>{let J=this.ensureUniqSecuritySchemaName(D),xe=["oauth2","openIdConnect"].includes(D.type)?m.getScopes():[];return this.addSecurityScheme(J,D),{name:J,scopes:xe}}));K.length>0&&(R.security=K),this.addPath(Tr(f),{[g]:R})}}),this.rootDoc.tags=r.tags?Ir(r.tags):[]}};import Er from"http";var tn=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>H),...t}),rn=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:Er.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=Er.STATUS_CODES[o],r)),json:e(()=>r),send:e(()=>r),end:e(()=>(r.writableEnded=!0,r)),...t};return r},on=({fnMethod:e,loggerProps:t})=>({info:e(),warn:e(),error:e(),debug:e(),...t}),nn=async({endpoint:e,requestProps:t,responseProps:r,configProps:o,loggerProps:i,fnMethod:s})=>{let a=s||(await or([{moduleName:"vitest",moduleExport:"vi"},{moduleName:"@jest/globals",moduleExport:"jest"}])).fn,p=tn({fnMethod:a,requestProps:t}),d=rn({fnMethod:a,responseProps:r}),c=on({fnMethod:a,loggerProps:i}),l={cors:!1,logger:c,...o};return await e.execute({request:p,response:d,config:l,logger:c}),{requestMock:p,responseMock:d,loggerMock:c}};import Z from"typescript";import U from"typescript";var n=U.factory,_=[n.createModifier(U.SyntaxKind.ExportKeyword)],sn=[n.createModifier(U.SyntaxKind.AsyncKeyword)],an=[n.createModifier(U.SyntaxKind.PublicKeyword),n.createModifier(U.SyntaxKind.ReadonlyKeyword)],wr=[n.createModifier(U.SyntaxKind.ProtectedKeyword),n.createModifier(U.SyntaxKind.ReadonlyKeyword)],Rt=n.createTemplateHead(""),ge=n.createTemplateTail(""),At=n.createTemplateMiddle(" "),Pt=e=>n.createTemplateLiteralType(Rt,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?ge:At))),Ct=Pt(["M","P"]),Qe=(e,t,r)=>n.createParameterDeclaration(r,void 0,e,void 0,t,void 0),Xe=(e,t)=>Object.keys(e).reduce((r,o)=>r.concat(Qe(n.createIdentifier(o),e[o],t)),[]),It=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Zr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),zr=(e,t)=>n.createPropertySignature(void 0,`"${e}"`,void 0,n.createTypeReferenceNode(t)),G=(e,t,r)=>n.createVariableDeclarationList([n.createVariableDeclaration(e,void 0,r,t)],U.NodeFlags.Const),Et=(e,t)=>n.createTypeAliasDeclaration(_,e,void 0,n.createUnionTypeNode(t.map(r=>n.createLiteralTypeNode(n.createStringLiteral(r))))),et=(e,t)=>n.createTypeAliasDeclaration(_,e,void 0,t),Mr=(e,t,r)=>n.createPropertyDeclaration(an,e,void 0,t,r),vr=(e,t,r=[])=>n.createClassDeclaration(_,e,void 0,void 0,[t,...r]),Nr=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),jr=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(U.SyntaxKind.AnyKeyword)]),Dr=(e,t,r)=>n.createInterfaceDeclaration(_,e,void 0,t,r),Lr=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),wt=(e,t,r)=>n.createArrowFunction(r?sn:void 0,void 0,e.map(o=>Qe(o)),void 0,void 0,t),Zt=(e,t,r)=>n.createCallExpression(n.createPropertyAccessExpression(n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("Object"),"keys"),void 0,[e]),"reduce"),void 0,[n.createArrowFunction(void 0,void 0,Xe({acc:void 0,key:void 0}),void 0,void 0,t),r]);var kr=["get","post","put","delete","patch"];import h from"typescript";import{z as vt}from"zod";import W from"typescript";var{factory:tt}=W,zt=(e,t)=>{W.addSyntheticLeadingComment(e,W.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},he=(e,t,r)=>{let o=tt.createTypeAliasDeclaration(void 0,tt.createIdentifier(t),void 0,e);return r&&zt(o,r),o},Mt=(e,t)=>{let r=W.createSourceFile("print.ts","",W.ScriptTarget.Latest,!1,W.ScriptKind.TS);return W.createPrinter(t).printNode(W.EmitHint.Unspecified,e,r)},pn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Hr=e=>pn.test(e)?tt.createIdentifier(e):tt.createStringLiteral(e);var{factory:u}=h,dn={[h.SyntaxKind.AnyKeyword]:"",[h.SyntaxKind.BigIntKeyword]:BigInt(0),[h.SyntaxKind.BooleanKeyword]:!1,[h.SyntaxKind.NumberKeyword]:0,[h.SyntaxKind.ObjectKeyword]:{},[h.SyntaxKind.StringKeyword]:"",[h.SyntaxKind.UndefinedKeyword]:void 0},cn=({schema:{value:e}})=>u.createLiteralTypeNode(typeof e=="number"?u.createNumericLiteral(e):typeof e=="boolean"?e?u.createTrue():u.createFalse():u.createStringLiteral(e)),mn=({schema:{shape:e},isResponse:t,next:r,optionalPropStyle:{withQuestionMark:o}})=>{let i=Object.entries(e).map(([s,a])=>{let p=t&&Ie(a)?a instanceof vt.ZodOptional:a.isOptional(),d=u.createPropertySignature(void 0,Hr(s),p&&o?u.createToken(h.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&zt(d,a.description),d});return u.createTypeLiteralNode(i)},ln=({schema:{element:e},next:t})=>u.createArrayTypeNode(t({schema:e})),un=({schema:{options:e}})=>u.createUnionTypeNode(e.map(t=>u.createLiteralTypeNode(u.createStringLiteral(t)))),Ur=({schema:{options:e},next:t})=>u.createUnionTypeNode(e.map(r=>t({schema:r}))),fn=e=>dn?.[e.kind],yn=({schema:e,next:t,isResponse:r})=>{let o=t({schema:e.innerType()}),i=e._def.effect;if(r&&i.type==="transform"){let s=Ve(e,fn(o)),a={number:h.SyntaxKind.NumberKeyword,bigint:h.SyntaxKind.BigIntKeyword,boolean:h.SyntaxKind.BooleanKeyword,string:h.SyntaxKind.StringKeyword,undefined:h.SyntaxKind.UndefinedKeyword,object:h.SyntaxKind.ObjectKeyword};return u.createKeywordTypeNode(s&&a[s]||h.SyntaxKind.AnyKeyword)}return o},gn=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(t=>u.createLiteralTypeNode(typeof t=="number"?u.createNumericLiteral(t):u.createStringLiteral(t)))),hn=({next:e,schema:t,optionalPropStyle:{withUndefined:r}})=>{let o=e({schema:t.unwrap()});return r?u.createUnionTypeNode([o,u.createKeywordTypeNode(h.SyntaxKind.UndefinedKeyword)]):o},xn=({next:e,schema:t})=>u.createUnionTypeNode([e({schema:t.unwrap()}),u.createLiteralTypeNode(u.createNull())]),Tn=({next:e,schema:{items:t}})=>u.createTupleTypeNode(t.map(r=>e({schema:r}))),bn=({next:e,schema:{keySchema:t,valueSchema:r}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:t}),e({schema:r})]),Sn=({next:e,schema:t})=>u.createIntersectionTypeNode([t._def.left,t._def.right].map(r=>e({schema:r}))),On=({next:e,schema:t})=>e({schema:t._def.innerType}),ae=e=>()=>u.createKeywordTypeNode(e),Rn=({next:e,schema:t})=>e({schema:t.unwrap()}),An=({next:e,schema:t})=>e({schema:t._def.innerType}),Pn=({next:e,schema:t})=>e({schema:t._def.innerType}),Cn=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),In=()=>u.createLiteralTypeNode(u.createNull()),En=({getAlias:e,makeAlias:t,next:r,serializer:o,schema:i})=>{let s=`Type${o(i.schema)}`;return e(s)||(t(s,u.createLiteralTypeNode(u.createNull())),t(s,r({schema:i.schema})))},wn=({schema:e})=>{let t=u.createKeywordTypeNode(h.SyntaxKind.StringKeyword),r=u.createTypeReferenceNode("Buffer"),o=u.createUnionTypeNode([t,r]);return e instanceof vt.ZodString?t:e instanceof vt.ZodUnion?o:r},Zn=({next:e,schema:t})=>e({schema:t.shape.raw}),zn={ZodString:ae(h.SyntaxKind.StringKeyword),ZodNumber:ae(h.SyntaxKind.NumberKeyword),ZodBigInt:ae(h.SyntaxKind.BigIntKeyword),ZodBoolean:ae(h.SyntaxKind.BooleanKeyword),ZodAny:ae(h.SyntaxKind.AnyKeyword),[Me]:ae(h.SyntaxKind.StringKeyword),[ve]:ae(h.SyntaxKind.StringKeyword),ZodNull:In,ZodArray:ln,ZodTuple:Tn,ZodRecord:bn,ZodObject:mn,ZodLiteral:cn,ZodIntersection:Sn,ZodUnion:Ur,ZodDefault:On,ZodEnum:un,ZodNativeEnum:gn,ZodEffects:yn,ZodOptional:hn,ZodNullable:xn,ZodDiscriminatedUnion:Ur,ZodBranded:Rn,ZodCatch:Pn,ZodPipeline:Cn,ZodLazy:En,ZodReadonly:An,[Pe]:wn,[te]:Zn},De=({schema:e,...t})=>se({schema:e,rules:zn,onMissing:()=>u.createKeywordTypeNode(h.SyntaxKind.AnyKeyword),...t});var Nt=class{program=[];usage=[];registry={};paths=[];aliases={};ids={pathType:n.createIdentifier("Path"),methodType:n.createIdentifier("Method"),methodPathType:n.createIdentifier("MethodPath"),inputInterface:n.createIdentifier("Input"),posResponseInterface:n.createIdentifier("PositiveResponse"),negResponseInterface:n.createIdentifier("NegativeResponse"),responseInterface:n.createIdentifier("Response"),jsonEndpointsConst:n.createIdentifier("jsonEndpoints"),endpointTagsConst:n.createIdentifier("endpointTags"),providerType:n.createIdentifier("Provider"),implementationType:n.createIdentifier("Implementation"),clientClass:n.createIdentifier("ExpressZodAPIClient"),keyParameter:n.createIdentifier("key"),pathParameter:n.createIdentifier("path"),paramsArgument:n.createIdentifier("params"),methodParameter:n.createIdentifier("method"),accumulator:n.createIdentifier("acc"),provideMethod:n.createIdentifier("provide"),implementationArgument:n.createIdentifier("implementation"),headersProperty:n.createIdentifier("headers"),hasBodyConst:n.createIdentifier("hasBody"),undefinedValue:n.createIdentifier("undefined"),bodyProperty:n.createIdentifier("body"),responseConst:n.createIdentifier("response"),searchParamsConst:n.createIdentifier("searchParams"),exampleImplementationConst:n.createIdentifier("exampleImplementation"),clientConst:n.createIdentifier("client")};interfaces=[];getAlias(t){return t in this.aliases?n.createTypeReferenceNode(t):void 0}makeAlias(t,r){return this.aliases[t]=he(r,t),this.getAlias(t)}constructor({routing:t,variant:r="client",serializer:o=qe,splitResponse:i=!1,optionalPropStyle:s={withQuestionMark:!0,withUndefined:!0}}){ie({routing:t,onEndpoint:(b,A,E)=>{let Q={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:s},jt=w(E,A,"input"),Kr=De({...Q,schema:b.getSchema("input"),isResponse:!1}),Te=i?w(E,A,"positive.response"):void 0,Dt=b.getSchema("positive"),Lt=i?De({...Q,isResponse:!0,schema:Dt}):void 0,be=i?w(E,A,"negative.response"):void 0,kt=b.getSchema("negative"),Ht=i?De({...Q,isResponse:!0,schema:kt}):void 0,Ut=w(E,A,"response"),Fr=Te&&be?n.createUnionTypeNode([n.createTypeReferenceNode(Te),n.createTypeReferenceNode(be)]):De({...Q,isResponse:!0,schema:Dt.or(kt)});this.program.push(he(Kr,jt)),Lt&&Te&&this.program.push(he(Lt,Te)),Ht&&be&&this.program.push(he(Ht,be)),this.program.push(he(Fr,Ut)),E!=="options"&&(this.paths.push(A),this.registry[`${E} ${A}`]={input:jt,positive:Te,negative:be,response:Ut,isJson:b.getMimeTypes("positive").includes(H),tags:b.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(Et(this.ids.pathType,this.paths)),this.program.push(Et(this.ids.methodType,kr)),this.program.push(et(this.ids.methodPathType,Pt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(Z.SyntaxKind.ExtendsKeyword,[It(this.ids.methodPathType,Z.SyntaxKind.AnyKeyword)])];this.interfaces.push({id:this.ids.inputInterface,kind:"input"}),i&&this.interfaces.push({id:this.ids.posResponseInterface,kind:"positive"},{id:this.ids.negResponseInterface,kind:"negative"}),this.interfaces.push({id:this.ids.responseInterface,kind:"response"});for(let{id:b,kind:A}of this.interfaces)this.program.push(Dr(b,a,Object.keys(this.registry).map(E=>{let Q=this.registry[E][A];return Q?zr(E,Q):void 0}).filter(E=>E!==void 0)));if(r==="types")return;let p=n.createVariableStatement(_,G(this.ids.jsonEndpointsConst,n.createObjectLiteralExpression(Object.keys(this.registry).filter(b=>this.registry[b].isJson).map(b=>n.createPropertyAssignment(`"${b}"`,n.createTrue()))))),d=n.createVariableStatement(_,G(this.ids.endpointTagsConst,n.createObjectLiteralExpression(Object.keys(this.registry).map(b=>n.createPropertyAssignment(`"${b}"`,n.createArrayLiteralExpression(this.registry[b].tags.map(A=>n.createStringLiteral(A)))))))),c=et(this.ids.providerType,n.createFunctionTypeNode(Lr({M:this.ids.methodType,P:this.ids.pathType}),Xe({method:n.createTypeReferenceNode("M"),path:n.createTypeReferenceNode("P"),params:n.createIndexedAccessTypeNode(n.createTypeReferenceNode(this.ids.inputInterface),Ct)}),Nr(this.ids.responseInterface,Ct))),l=et(this.ids.implementationType,n.createFunctionTypeNode(void 0,Xe({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(Z.SyntaxKind.StringKeyword),params:It(Z.SyntaxKind.StringKeyword,Z.SyntaxKind.AnyKeyword)}),jr())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,ge)]),f=Zt(this.ids.paramsArgument,n.createCallExpression(n.createPropertyAccessExpression(this.ids.accumulator,"replace"),void 0,[m,n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter)]),this.ids.pathParameter),T=Zt(this.ids.paramsArgument,n.createConditionalExpression(n.createBinaryExpression(n.createCallExpression(n.createPropertyAccessExpression(this.ids.pathParameter,"indexOf"),void 0,[m]),Z.SyntaxKind.GreaterThanEqualsToken,n.createNumericLiteral(0)),void 0,this.ids.accumulator,void 0,n.createObjectLiteralExpression([n.createSpreadAssignment(this.ids.accumulator),n.createPropertyAssignment(n.createComputedPropertyName(this.ids.keyParameter),n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter))])),n.createObjectLiteralExpression()),g=vr(this.ids.clientClass,Zr([Qe(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),wr)]),[Mr(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),wt([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createCallExpression(n.createPropertyAccessExpression(n.createThis(),this.ids.implementationArgument),void 0,[this.ids.methodParameter,f,T]),!0))]);this.program.push(p,d,c,l,g);let S=n.createPropertyAssignment(this.ids.methodParameter,n.createCallExpression(n.createPropertyAccessExpression(this.ids.methodParameter,"toUpperCase"),void 0,void 0)),y=n.createPropertyAssignment(this.ids.headersProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createObjectLiteralExpression([n.createPropertyAssignment(n.createStringLiteral("Content-Type"),n.createStringLiteral(H))]),void 0,this.ids.undefinedValue)),x=n.createPropertyAssignment(this.ids.bodyProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("JSON"),"stringify"),void 0,[this.ids.paramsArgument]),void 0,this.ids.undefinedValue)),j=n.createVariableStatement(void 0,G(this.ids.responseConst,n.createAwaitExpression(n.createCallExpression(n.createIdentifier("fetch"),void 0,[n.createTemplateExpression(n.createTemplateHead("https://example.com"),[n.createTemplateSpan(this.ids.pathParameter,n.createTemplateMiddle("")),n.createTemplateSpan(this.ids.searchParamsConst,ge)]),n.createObjectLiteralExpression([S,y,x])])))),I=n.createVariableStatement(void 0,G(this.ids.hasBodyConst,n.createLogicalNot(n.createCallExpression(n.createPropertyAccessExpression(n.createArrayLiteralExpression([n.createStringLiteral("get"),n.createStringLiteral("delete")]),"includes"),void 0,[this.ids.methodParameter])))),Y=n.createVariableStatement(void 0,G(this.ids.searchParamsConst,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createStringLiteral(""),void 0,n.createTemplateExpression(n.createTemplateHead("?"),[n.createTemplateSpan(n.createNewExpression(n.createIdentifier("URLSearchParams"),void 0,[this.ids.paramsArgument]),ge)])))),[R,K]=["json","text"].map(b=>n.createReturnStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.responseConst,b),void 0,void 0))),D=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(Rt,[n.createTemplateSpan(this.ids.methodParameter,At),n.createTemplateSpan(this.ids.pathParameter,ge)]),Z.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([R])),J=n.createVariableStatement(_,G(this.ids.exampleImplementationConst,wt([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([I,Y,j,D,K]),!0),n.createTypeReferenceNode(this.ids.implementationType))),xe=n.createExpressionStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.clientConst,this.ids.provideMethod),void 0,[n.createStringLiteral("get"),n.createStringLiteral("/v1/user/retrieve"),n.createObjectLiteralExpression([n.createPropertyAssignment("id",n.createStringLiteral("10"))])])),rt=n.createVariableStatement(void 0,G(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(J,rt,xe)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:Mt(r,t)).join(`
18
+ `;var gt=({app:e,rootLogger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(ir()),t.debug("Running","v16.4.0 (ESM)"),ie({routing:o,hasCors:!!r.cors,onEndpoint:(i,s,a)=>{e[a](s,async(p,d)=>{let c=r.childLoggerProvider?await r.childLoggerProvider({request:p,parent:t}):t;c.info(`${p.method}: ${s}`),await i.execute({request:p,response:d,logger:c,config:r})})},onStatic:(i,s)=>{e.use(i,s)}})};import sr from"http-errors";var ar=({errorHandler:e,rootLogger:t,getChildLogger:r})=>async(o,i,s,a)=>{if(!o)return a();e.handler({error:sr(400,me(o).message),request:i,response:s,input:null,output:null,logger:r?await r({request:i,parent:t}):t})},pr=({errorHandler:e,getChildLogger:t,rootLogger:r})=>async(o,i)=>{let s=sr(404,`Can not ${o.method} ${o.path}`),a=t?await t({request:o,parent:r}):r;try{e.handler({request:o,response:i,logger:a,error:s,input:null,output:null})}catch(p){$e({response:i,logger:a,error:new ee(me(p).message,s)})}};var cr=async e=>{let t=rr(e.logger)?yt({...e.logger,winston:await ne("winston")}):e.logger,r=e.errorHandler||Ee,{childLoggerProvider:o}=e,i={errorHandler:r,rootLogger:t,getChildLogger:o},s=pr(i),a=ar(i);return{rootLogger:t,errorHandler:r,notFoundHandler:s,parserFailureHandler:a}},co=async(e,t)=>{let{rootLogger:r,notFoundHandler:o}=await cr(e);return gt({app:e.app,routing:t,rootLogger:r,config:e}),{notFoundHandler:o,logger:r}},mo=async(e,t)=>{let r=dr().disable("x-powered-by");if(e.server.compression){let d=await ne("compression");r.use(d(typeof e.server.compression=="object"?e.server.compression:void 0))}if(r.use(e.server.jsonParser||dr.json()),e.server.upload){let d=await ne("express-fileupload");r.use(d({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}))}e.server.rawParser&&(r.use(e.server.rawParser),r.use((d,{},c)=>{Buffer.isBuffer(d.body)&&(d.body={raw:d.body}),c()}));let{rootLogger:o,notFoundHandler:i,parserFailureHandler:s}=await cr(e);r.use(s),gt({app:r,routing:t,rootLogger:o,config:e}),r.use(i);let a=(d,c)=>d.listen(c,()=>{o.info("Listening",c)}),p={httpServer:a(ao.createServer(r),e.server.listen),httpsServer:e.https?a(po.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...p,logger:o}};import Xo from"assert/strict";import{OpenApiBuilder as en}from"openapi3-ts/oas31";import ye from"assert/strict";import{isReferenceObject as fe}from"openapi3-ts/oas31";import{omit as je}from"ramda";import{z as O}from"zod";import{z as mr}from"zod";var Me="DateIn",lr=()=>z(Me,mr.string().regex(He).transform(e=>new Date(e)).pipe(mr.date().refine(ke)));import{z as lo}from"zod";var ve="DateOut",ur=()=>z(ve,lo.date().refine(ke).transform(e=>e.toISOString()));var se=({schema:e,onEach:t,rules:r,onMissing:o,...i})=>{let s=Se(e,"kind")||e._def.typeName,a=s?r[s]:void 0,p=i,c=a?a({schema:e,...p,next:m=>se({...m,...p,onEach:t,rules:r,onMissing:o})}):o({schema:e,...p}),l=t&&t({schema:e,prev:c,...p});return l?{...c,...l}:c};var fr=50,gr="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",uo={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},hr=/:([A-Za-z0-9_]+)/g,xr=e=>{let t=e.match(hr);return t?t.map(r=>r.slice(1)):[]},Tr=e=>e.replace(hr,t=>`{${t.slice(1)}}`),fo=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),yo=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),go=()=>({format:"any"}),ho=e=>(ye(!e.isResponse,new C({message:"Please use ez.upload() only for input.",...e})),{type:"string",format:"binary"}),xo=({schema:e})=>({type:"string",format:e instanceof O.ZodString?e._def.checks.find(t=>t.kind==="regex")?"byte":"file":"binary"}),To=({schema:{options:e},next:t})=>({oneOf:e.map(r=>t({schema:r}))}),bo=({schema:{options:e,discriminator:t},next:r})=>({discriminator:{propertyName:t},oneOf:Array.from(e.values()).map(o=>r({schema:o}))}),So=({schema:{_def:{left:e,right:t}},next:r})=>({allOf:[e,t].map(o=>r({schema:o}))}),Oo=({schema:e,next:t})=>t({schema:e.unwrap()}),Ro=({schema:e,next:t})=>t({schema:e._def.innerType}),Ao=({schema:e,next:t})=>{let r=t({schema:e.unwrap()});return fe(r)||(r.type=br(r)),r},yr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),Po=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Co=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(s=>{let a=e.shape[s];return!(t&&Ie(a)?a instanceof O.ZodOptional:a.isOptional())}),i={type:"object",properties:Ye({schema:e,isResponse:t,...r})};return o.length&&(i.required=o),i},Io=()=>({type:"null"}),Eo=e=>(ye(!e.isResponse,new C({message:"Please use ez.dateOut() for output.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:He.source,externalDocs:{url:gr}}),wo=e=>(ye(e.isResponse,new C({message:"Please use ez.dateIn() for input.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:gr}}),Zo=e=>ye.fail(new C({message:`Using z.date() within ${e.isResponse?"output":"input"} schema is forbidden. Please use ez.date${e.isResponse?"Out":"In"}() instead. Check out the documentation for details.`,...e})),zo=()=>({type:"boolean"}),Mo=()=>({type:"integer",format:"bigint"}),vo=e=>e.reduce((t,r)=>t&&r instanceof O.ZodLiteral,!0),No=({schema:{keySchema:e,valueSchema:t},...r})=>{if(e instanceof O.ZodEnum||e instanceof O.ZodNativeEnum){let o=Object.values(e.enum),i=o.reduce((a,p)=>({...a,[p]:t}),{}),s={type:"object",properties:Ye({schema:O.object(i),...r})};return o.length&&(s.required=o),s}if(e instanceof O.ZodLiteral)return{type:"object",properties:Ye({schema:O.object({[e.value]:t}),...r}),required:[e.value]};if(e instanceof O.ZodUnion&&vo(e.options)){let o=e.options.reduce((i,s)=>({...i,[`${s.value}`]:t}),{});return{type:"object",properties:Ye({schema:O.object(o),...r}),required:e.options.map(i=>i.value)}}return{type:"object",additionalProperties:r.next({schema:t})}},jo=({schema:{_def:e,element:t},next:r})=>{let o={type:"array",items:r({schema:t})};return e.minLength&&(o.minItems=e.minLength.value),e.maxLength&&(o.maxItems=e.maxLength.value),o},Do=({schema:{items:e},next:t})=>({type:"array",prefixItems:e.map(o=>t({schema:o}))}),Lo=({schema:{isEmail:e,isURL:t,minLength:r,maxLength:o,isUUID:i,isCUID:s,isCUID2:a,isULID:p,isIP:d,isEmoji:c,isDatetime:l,_def:{checks:m}}})=>{let f=m.find(x=>x.kind==="regex"),T=m.find(x=>x.kind==="datetime"),g=f?f.regex:T?T.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"):void 0,S={type:"string"},y={"date-time":l,email:e,url:t,uuid:i,cuid:s,cuid2:a,ulid:p,ip:d,emoji:c};for(let x in y)if(y[x]){S.format=x;break}return r!==null&&(S.minLength=r),o!==null&&(S.maxLength=o),g&&(S.pattern=g.source),S},ko=({schema:e})=>{let t=e._def.checks.find(({kind:d})=>d==="min"),r=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,o=t?t.inclusive:!0,i=e._def.checks.find(({kind:d})=>d==="max"),s=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,a=i?i.inclusive:!0,p={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return o?p.minimum=r:p.exclusiveMinimum=r,a?p.maximum=s:p.exclusiveMaximum=s,p},Ye=({schema:{shape:e},next:t})=>Object.keys(e).reduce((r,o)=>({...r,[o]:t({schema:e[o]})}),{}),Ho=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return uo?.[t]},br=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Uo=({schema:e,isResponse:t,next:r})=>{let o=r({schema:e.innerType()}),{effect:i}=e._def;if(t&&i.type==="transform"&&!fe(o)){let s=Ve(e,Ho(o));return s&&["number","string","boolean"].includes(s)?{type:s}:r({schema:O.any()})}if(!t&&i.type==="preprocess"&&!fe(o)){let{type:s,...a}=o;return{...a,format:`${a.format||s} (preprocessed)`}}return o},Ko=({schema:e,isResponse:t,next:r})=>r({schema:e._def[t?"out":"in"]}),Fo=({schema:e,next:t})=>t({schema:e.unwrap()}),Bo=({next:e,schema:t,serializer:r,getRef:o,makeRef:i})=>{let s=r(t.schema);return o(s)||(i(s,{}),i(s,e({schema:t.schema})))},qo=({next:e,schema:t})=>e({schema:t.shape.raw}),Sr=(e,t,r=[])=>{let o=$({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>({...i,[`example${a+1}`]:{value:typeof s=="object"&&!Array.isArray(s)?je(r,s):s}}),{})},Vo=(e,t,r)=>{let o=$({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((i,s,a)=>r in s?{...i,[`example${a+1}`]:{value:s[r]}}:i,{})},Ne=(e,t)=>{if(e instanceof O.ZodObject)return e;let r;return e instanceof O.ZodUnion||e instanceof O.ZodDiscriminatedUnion?r=Array.from(e.options.values()).map(o=>Ne(o,t)).reduce((o,i)=>o.merge(i.partial()),O.object({})):e instanceof O.ZodEffects?(ye(!V(e),new C({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=Ne(e._def.schema,t)):r=Ne(e._def.left,t).merge(Ne(e._def.right,t)),Le(e,r)},Or=({path:e,method:t,schema:r,inputSources:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${t.toUpperCase()} ${e} Parameter`})=>{let c=Ne(r,{path:e,method:t,isResponse:!1}).shape,l=xr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),S=y=>T&&at(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=se({schema:c[y],isResponse:!1,rules:xt,onEach:Tt,onMissing:bt,serializer:i,getRef:s,makeRef:a,path:e,method:t}),j=p==="components"?a(w(d,y),x):x;return{name:y,in:g(y)?"path":S(y)?"header":"query",required:!c[y].isOptional(),description:x.description||d,schema:j,examples:Vo(r,!1,y)}})},xt={ZodString:Lo,ZodNumber:ko,ZodBigInt:Mo,ZodBoolean:zo,ZodNull:Io,ZodArray:jo,ZodTuple:Do,ZodRecord:No,ZodObject:Co,ZodLiteral:Po,ZodIntersection:So,ZodUnion:To,ZodAny:go,ZodDefault:fo,ZodEnum:yr,ZodNativeEnum:yr,ZodEffects:Uo,ZodOptional:Oo,ZodNullable:Ao,ZodDiscriminatedUnion:bo,ZodBranded:Fo,ZodDate:Zo,ZodCatch:yo,ZodPipeline:Ko,ZodLazy:Bo,ZodReadonly:Ro,[Pe]:xo,[Ce]:ho,[ve]:wo,[Me]:Eo,[te]:qo},Tt=({schema:e,isResponse:t,prev:r})=>{if(fe(r))return{};let{description:o}=e,i=e instanceof O.ZodLazy,s=r.type!==void 0,a=t&&Ie(e),p=!i&&s&&!a&&e.isNullable(),d=i?[]:$({schema:e,variant:t?"parsed":"original",validate:!0}),c={};return o&&(c.description=o),p&&(c.type=br(r)),d.length&&(c.examples=Array.from(d)),c},bt=({schema:e,...t})=>ye.fail(new C({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),ht=(e,t)=>{if(fe(e))return e;let r=e.properties?je(t,e.properties):void 0,o=e.examples?e.examples.map(p=>je(t,p)):void 0,i=e.required?e.required.filter(p=>!t.includes(p)):void 0,s=e.allOf?e.allOf.map(p=>ht(p,t)):void 0,a=e.oneOf?e.oneOf.map(p=>ht(p,t)):void 0;return je(Object.entries({properties:r,required:i,examples:o,allOf:s,oneOf:a}).filter(([{},p])=>p===void 0).map(([p])=>p),{...e,properties:r,required:i,examples:o,allOf:s,oneOf:a})},Rr=e=>fe(e)?e:je(["examples"],e),Ar=({method:e,path:t,schema:r,mimeTypes:o,variant:i,serializer:s,getRef:a,makeRef:p,composition:d,hasMultipleStatusCodes:c,statusCode:l,description:m=`${e.toUpperCase()} ${t} ${dt(i)} response ${c?l:""}`.trim()})=>{let f=Rr(se({schema:r,isResponse:!0,rules:xt,onEach:Tt,onMissing:bt,serializer:s,getRef:a,makeRef:p,path:t,method:e})),T=Sr(r,!0),g=d==="components"?p(w(m),f):f;return{description:m,content:o.reduce((S,y)=>({...S,[y]:{schema:g,examples:T}}),{})}},$o=()=>({type:"http",scheme:"basic"}),_o=({format:e})=>{let t={type:"http",scheme:"bearer"};return e&&(t.bearerFormat=e),t},Go=({name:e},t)=>{let r={type:"apiKey",in:"query",name:e};return t?.includes("body")&&(t?.includes("query")?(r["x-in-alternative"]="body",r.description=`${e} CAN also be supplied within the request body`):(r["x-in-actual"]="body",r.description=`${e} MUST be supplied within the request body instead of query`)),r},Wo=({name:e})=>({type:"apiKey",in:"header",name:e}),Yo=({name:e})=>({type:"apiKey",in:"cookie",name:e}),Jo=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),Qo=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((t,r)=>{let o=e[r];if(!o)return t;let{scopes:i={},...s}=o;return{...t,[r]:{...s,scopes:i}}},{})}),Pr=(e,t)=>{let r={basic:$o,bearer:_o,input:Go,header:Wo,cookie:Yo,openid:Jo,oauth2:Qo};return Ge(e,o=>r[o.type](o,t))},Je=e=>{if(typeof e=="object"){if("or"in e)return e.or.map(t=>("and"in t?t.and:[t]).reduce((r,{name:o,scopes:i})=>({...r,[o]:i}),{}));if("and"in e)return Je(ct(e))}return Je({or:[e]})},Cr=({method:e,path:t,schema:r,mimeTypes:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${e.toUpperCase()} ${t} Request body`})=>{let c=xr(t),l=Rr(ht(se({schema:r,isResponse:!1,rules:xt,onEach:Tt,onMissing:bt,serializer:i,getRef:s,makeRef:a,path:t,method:e}),c)),m=Sr(r,!1,c),f=p==="components"?a(w(d),l):l;return{description:d,content:o.reduce((T,g)=>({...T,[g]:{schema:f,examples:m}}),{})}},Ir=e=>Object.keys(e).map(t=>{let r=e[t],o={name:t,description:typeof r=="string"?r:r.description};return typeof r=="object"&&r.url&&(o.externalDocs={url:r.url}),o}),St=e=>e.length<=fr?e:e.slice(0,fr-1)+"\u2026";var Ot=class extends en{lastSecuritySchemaIds={};lastOperationIdSuffixes={};makeRef(t,r){return this.addSchema(t,r),this.getRef(t)}getRef(t){return t in(this.rootDoc.components?.schemas||{})?{$ref:`#/components/schemas/${t}`}:void 0}ensureUniqOperationId(t,r,o){if(o)return Xo(!(o in this.lastOperationIdSuffixes),new C({message:`Duplicated operationId: "${o}"`,method:r,isResponse:!1,path:t})),this.lastOperationIdSuffixes[o]=1,o;let i=w(r,t);return i in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[i]++,`${i}${this.lastOperationIdSuffixes[i]}`):(this.lastOperationIdSuffixes[i]=1,i)}ensureUniqSecuritySchemaName(t){let r=JSON.stringify(t);for(let o in this.rootDoc.components?.securitySchemes||{})if(r===JSON.stringify(this.rootDoc.components?.securitySchemes?.[o]))return o;return this.lastSecuritySchemaIds[t.type]=(this.lastSecuritySchemaIds?.[t.type]||0)+1,`${t.type.toUpperCase()}_${this.lastSecuritySchemaIds[t.type]}`}constructor({routing:t,config:r,title:o,version:i,serverUrl:s,descriptions:a,hasSummaryFromDescription:p=!0,composition:d="inline",serializer:c=qe}){super(),this.addInfo({title:o,version:i});for(let m of typeof s=="string"?[s]:s)this.addServer({url:m});ie({routing:t,onEndpoint:(m,f,T)=>{let g=T,S={path:f,method:g,endpoint:m,composition:d,serializer:c,getRef:this.getRef.bind(this),makeRef:this.makeRef.bind(this)},[y,x]=["short","long"].map(m.getDescription.bind(m)),j=r.inputSources?.[g]||Fe[g],I=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Y=Or({...S,inputSources:j,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:I})}),R={operationId:I,responses:{}};for(let D of["positive","negative"]){let J=m.getResponses(D);for(let{mimeTypes:xe,schema:rt,statusCodes:b}of J)for(let A of b)R.responses[A]=Ar({...S,variant:D,schema:rt,mimeTypes:xe,statusCode:A,hasMultipleStatusCodes:J.length>1||b.length>1,description:a?.[`${D}Response`]?.call(null,{method:g,path:f,operationId:I,statusCode:A})})}x&&(R.description=x,p&&y===void 0&&(R.summary=St(x))),y&&(R.summary=St(y)),m.getTags().length>0&&(R.tags=m.getTags()),Y.length>0&&(R.parameters=Y),j.includes("body")&&(R.requestBody=Cr({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:I})}));let K=Je(Ge(Pr(m.getSecurity(),j),D=>{let J=this.ensureUniqSecuritySchemaName(D),xe=["oauth2","openIdConnect"].includes(D.type)?m.getScopes():[];return this.addSecurityScheme(J,D),{name:J,scopes:xe}}));K.length>0&&(R.security=K),this.addPath(Tr(f),{[g]:R})}}),this.rootDoc.tags=r.tags?Ir(r.tags):[]}};import Er from"http";var tn=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>H),...t}),rn=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:Er.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=Er.STATUS_CODES[o],r)),json:e(()=>r),send:e(()=>r),end:e(()=>(r.writableEnded=!0,r)),...t};return r},on=({fnMethod:e,loggerProps:t})=>({info:e(),warn:e(),error:e(),debug:e(),...t}),nn=async({endpoint:e,requestProps:t,responseProps:r,configProps:o,loggerProps:i,fnMethod:s})=>{let a=s||(await or([{moduleName:"vitest",moduleExport:"vi"},{moduleName:"@jest/globals",moduleExport:"jest"}])).fn,p=tn({fnMethod:a,requestProps:t}),d=rn({fnMethod:a,responseProps:r}),c=on({fnMethod:a,loggerProps:i}),l={cors:!1,logger:c,...o};return await e.execute({request:p,response:d,config:l,logger:c}),{requestMock:p,responseMock:d,loggerMock:c}};import Z from"typescript";import U from"typescript";var n=U.factory,_=[n.createModifier(U.SyntaxKind.ExportKeyword)],sn=[n.createModifier(U.SyntaxKind.AsyncKeyword)],an=[n.createModifier(U.SyntaxKind.PublicKeyword),n.createModifier(U.SyntaxKind.ReadonlyKeyword)],wr=[n.createModifier(U.SyntaxKind.ProtectedKeyword),n.createModifier(U.SyntaxKind.ReadonlyKeyword)],Rt=n.createTemplateHead(""),ge=n.createTemplateTail(""),At=n.createTemplateMiddle(" "),Pt=e=>n.createTemplateLiteralType(Rt,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?ge:At))),Ct=Pt(["M","P"]),Qe=(e,t,r)=>n.createParameterDeclaration(r,void 0,e,void 0,t,void 0),Xe=(e,t)=>Object.keys(e).reduce((r,o)=>r.concat(Qe(n.createIdentifier(o),e[o],t)),[]),It=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Zr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),zr=(e,t)=>n.createPropertySignature(void 0,`"${e}"`,void 0,n.createTypeReferenceNode(t)),G=(e,t,r)=>n.createVariableDeclarationList([n.createVariableDeclaration(e,void 0,r,t)],U.NodeFlags.Const),Et=(e,t)=>n.createTypeAliasDeclaration(_,e,void 0,n.createUnionTypeNode(t.map(r=>n.createLiteralTypeNode(n.createStringLiteral(r))))),et=(e,t)=>n.createTypeAliasDeclaration(_,e,void 0,t),Mr=(e,t,r)=>n.createPropertyDeclaration(an,e,void 0,t,r),vr=(e,t,r=[])=>n.createClassDeclaration(_,e,void 0,void 0,[t,...r]),Nr=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),jr=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(U.SyntaxKind.AnyKeyword)]),Dr=(e,t,r)=>n.createInterfaceDeclaration(_,e,void 0,t,r),Lr=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),wt=(e,t,r)=>n.createArrowFunction(r?sn:void 0,void 0,e.map(o=>Qe(o)),void 0,void 0,t),Zt=(e,t,r)=>n.createCallExpression(n.createPropertyAccessExpression(n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("Object"),"keys"),void 0,[e]),"reduce"),void 0,[n.createArrowFunction(void 0,void 0,Xe({acc:void 0,key:void 0}),void 0,void 0,t),r]);var kr=["get","post","put","delete","patch"];import h from"typescript";import{z as vt}from"zod";import W from"typescript";var{factory:tt}=W,zt=(e,t)=>{W.addSyntheticLeadingComment(e,W.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},he=(e,t,r)=>{let o=tt.createTypeAliasDeclaration(void 0,tt.createIdentifier(t),void 0,e);return r&&zt(o,r),o},Mt=(e,t)=>{let r=W.createSourceFile("print.ts","",W.ScriptTarget.Latest,!1,W.ScriptKind.TS);return W.createPrinter(t).printNode(W.EmitHint.Unspecified,e,r)},pn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Hr=e=>pn.test(e)?tt.createIdentifier(e):tt.createStringLiteral(e);var{factory:u}=h,dn={[h.SyntaxKind.AnyKeyword]:"",[h.SyntaxKind.BigIntKeyword]:BigInt(0),[h.SyntaxKind.BooleanKeyword]:!1,[h.SyntaxKind.NumberKeyword]:0,[h.SyntaxKind.ObjectKeyword]:{},[h.SyntaxKind.StringKeyword]:"",[h.SyntaxKind.UndefinedKeyword]:void 0},cn=({schema:{value:e}})=>u.createLiteralTypeNode(typeof e=="number"?u.createNumericLiteral(e):typeof e=="boolean"?e?u.createTrue():u.createFalse():u.createStringLiteral(e)),mn=({schema:{shape:e},isResponse:t,next:r,optionalPropStyle:{withQuestionMark:o}})=>{let i=Object.entries(e).map(([s,a])=>{let p=t&&Ie(a)?a instanceof vt.ZodOptional:a.isOptional(),d=u.createPropertySignature(void 0,Hr(s),p&&o?u.createToken(h.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&zt(d,a.description),d});return u.createTypeLiteralNode(i)},ln=({schema:{element:e},next:t})=>u.createArrayTypeNode(t({schema:e})),un=({schema:{options:e}})=>u.createUnionTypeNode(e.map(t=>u.createLiteralTypeNode(u.createStringLiteral(t)))),Ur=({schema:{options:e},next:t})=>u.createUnionTypeNode(e.map(r=>t({schema:r}))),fn=e=>dn?.[e.kind],yn=({schema:e,next:t,isResponse:r})=>{let o=t({schema:e.innerType()}),i=e._def.effect;if(r&&i.type==="transform"){let s=Ve(e,fn(o)),a={number:h.SyntaxKind.NumberKeyword,bigint:h.SyntaxKind.BigIntKeyword,boolean:h.SyntaxKind.BooleanKeyword,string:h.SyntaxKind.StringKeyword,undefined:h.SyntaxKind.UndefinedKeyword,object:h.SyntaxKind.ObjectKeyword};return u.createKeywordTypeNode(s&&a[s]||h.SyntaxKind.AnyKeyword)}return o},gn=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(t=>u.createLiteralTypeNode(typeof t=="number"?u.createNumericLiteral(t):u.createStringLiteral(t)))),hn=({next:e,schema:t,optionalPropStyle:{withUndefined:r}})=>{let o=e({schema:t.unwrap()});return r?u.createUnionTypeNode([o,u.createKeywordTypeNode(h.SyntaxKind.UndefinedKeyword)]):o},xn=({next:e,schema:t})=>u.createUnionTypeNode([e({schema:t.unwrap()}),u.createLiteralTypeNode(u.createNull())]),Tn=({next:e,schema:{items:t}})=>u.createTupleTypeNode(t.map(r=>e({schema:r}))),bn=({next:e,schema:{keySchema:t,valueSchema:r}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:t}),e({schema:r})]),Sn=({next:e,schema:t})=>u.createIntersectionTypeNode([t._def.left,t._def.right].map(r=>e({schema:r}))),On=({next:e,schema:t})=>e({schema:t._def.innerType}),ae=e=>()=>u.createKeywordTypeNode(e),Rn=({next:e,schema:t})=>e({schema:t.unwrap()}),An=({next:e,schema:t})=>e({schema:t._def.innerType}),Pn=({next:e,schema:t})=>e({schema:t._def.innerType}),Cn=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),In=()=>u.createLiteralTypeNode(u.createNull()),En=({getAlias:e,makeAlias:t,next:r,serializer:o,schema:i})=>{let s=`Type${o(i.schema)}`;return e(s)||(t(s,u.createLiteralTypeNode(u.createNull())),t(s,r({schema:i.schema})))},wn=({schema:e})=>{let t=u.createKeywordTypeNode(h.SyntaxKind.StringKeyword),r=u.createTypeReferenceNode("Buffer"),o=u.createUnionTypeNode([t,r]);return e instanceof vt.ZodString?t:e instanceof vt.ZodUnion?o:r},Zn=({next:e,schema:t})=>e({schema:t.shape.raw}),zn={ZodString:ae(h.SyntaxKind.StringKeyword),ZodNumber:ae(h.SyntaxKind.NumberKeyword),ZodBigInt:ae(h.SyntaxKind.BigIntKeyword),ZodBoolean:ae(h.SyntaxKind.BooleanKeyword),ZodAny:ae(h.SyntaxKind.AnyKeyword),[Me]:ae(h.SyntaxKind.StringKeyword),[ve]:ae(h.SyntaxKind.StringKeyword),ZodNull:In,ZodArray:ln,ZodTuple:Tn,ZodRecord:bn,ZodObject:mn,ZodLiteral:cn,ZodIntersection:Sn,ZodUnion:Ur,ZodDefault:On,ZodEnum:un,ZodNativeEnum:gn,ZodEffects:yn,ZodOptional:hn,ZodNullable:xn,ZodDiscriminatedUnion:Ur,ZodBranded:Rn,ZodCatch:Pn,ZodPipeline:Cn,ZodLazy:En,ZodReadonly:An,[Pe]:wn,[te]:Zn},De=({schema:e,...t})=>se({schema:e,rules:zn,onMissing:()=>u.createKeywordTypeNode(h.SyntaxKind.AnyKeyword),...t});var Nt=class{program=[];usage=[];registry={};paths=[];aliases={};ids={pathType:n.createIdentifier("Path"),methodType:n.createIdentifier("Method"),methodPathType:n.createIdentifier("MethodPath"),inputInterface:n.createIdentifier("Input"),posResponseInterface:n.createIdentifier("PositiveResponse"),negResponseInterface:n.createIdentifier("NegativeResponse"),responseInterface:n.createIdentifier("Response"),jsonEndpointsConst:n.createIdentifier("jsonEndpoints"),endpointTagsConst:n.createIdentifier("endpointTags"),providerType:n.createIdentifier("Provider"),implementationType:n.createIdentifier("Implementation"),clientClass:n.createIdentifier("ExpressZodAPIClient"),keyParameter:n.createIdentifier("key"),pathParameter:n.createIdentifier("path"),paramsArgument:n.createIdentifier("params"),methodParameter:n.createIdentifier("method"),accumulator:n.createIdentifier("acc"),provideMethod:n.createIdentifier("provide"),implementationArgument:n.createIdentifier("implementation"),headersProperty:n.createIdentifier("headers"),hasBodyConst:n.createIdentifier("hasBody"),undefinedValue:n.createIdentifier("undefined"),bodyProperty:n.createIdentifier("body"),responseConst:n.createIdentifier("response"),searchParamsConst:n.createIdentifier("searchParams"),exampleImplementationConst:n.createIdentifier("exampleImplementation"),clientConst:n.createIdentifier("client")};interfaces=[];getAlias(t){return t in this.aliases?n.createTypeReferenceNode(t):void 0}makeAlias(t,r){return this.aliases[t]=he(r,t),this.getAlias(t)}constructor({routing:t,variant:r="client",serializer:o=qe,splitResponse:i=!1,optionalPropStyle:s={withQuestionMark:!0,withUndefined:!0}}){ie({routing:t,onEndpoint:(b,A,E)=>{let Q={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:s},jt=w(E,A,"input"),Kr=De({...Q,schema:b.getSchema("input"),isResponse:!1}),Te=i?w(E,A,"positive.response"):void 0,Dt=b.getSchema("positive"),Lt=i?De({...Q,isResponse:!0,schema:Dt}):void 0,be=i?w(E,A,"negative.response"):void 0,kt=b.getSchema("negative"),Ht=i?De({...Q,isResponse:!0,schema:kt}):void 0,Ut=w(E,A,"response"),Fr=Te&&be?n.createUnionTypeNode([n.createTypeReferenceNode(Te),n.createTypeReferenceNode(be)]):De({...Q,isResponse:!0,schema:Dt.or(kt)});this.program.push(he(Kr,jt)),Lt&&Te&&this.program.push(he(Lt,Te)),Ht&&be&&this.program.push(he(Ht,be)),this.program.push(he(Fr,Ut)),E!=="options"&&(this.paths.push(A),this.registry[`${E} ${A}`]={input:jt,positive:Te,negative:be,response:Ut,isJson:b.getMimeTypes("positive").includes(H),tags:b.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(Et(this.ids.pathType,this.paths)),this.program.push(Et(this.ids.methodType,kr)),this.program.push(et(this.ids.methodPathType,Pt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(Z.SyntaxKind.ExtendsKeyword,[It(this.ids.methodPathType,Z.SyntaxKind.AnyKeyword)])];this.interfaces.push({id:this.ids.inputInterface,kind:"input"}),i&&this.interfaces.push({id:this.ids.posResponseInterface,kind:"positive"},{id:this.ids.negResponseInterface,kind:"negative"}),this.interfaces.push({id:this.ids.responseInterface,kind:"response"});for(let{id:b,kind:A}of this.interfaces)this.program.push(Dr(b,a,Object.keys(this.registry).map(E=>{let Q=this.registry[E][A];return Q?zr(E,Q):void 0}).filter(E=>E!==void 0)));if(r==="types")return;let p=n.createVariableStatement(_,G(this.ids.jsonEndpointsConst,n.createObjectLiteralExpression(Object.keys(this.registry).filter(b=>this.registry[b].isJson).map(b=>n.createPropertyAssignment(`"${b}"`,n.createTrue()))))),d=n.createVariableStatement(_,G(this.ids.endpointTagsConst,n.createObjectLiteralExpression(Object.keys(this.registry).map(b=>n.createPropertyAssignment(`"${b}"`,n.createArrayLiteralExpression(this.registry[b].tags.map(A=>n.createStringLiteral(A)))))))),c=et(this.ids.providerType,n.createFunctionTypeNode(Lr({M:this.ids.methodType,P:this.ids.pathType}),Xe({method:n.createTypeReferenceNode("M"),path:n.createTypeReferenceNode("P"),params:n.createIndexedAccessTypeNode(n.createTypeReferenceNode(this.ids.inputInterface),Ct)}),Nr(this.ids.responseInterface,Ct))),l=et(this.ids.implementationType,n.createFunctionTypeNode(void 0,Xe({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(Z.SyntaxKind.StringKeyword),params:It(Z.SyntaxKind.StringKeyword,Z.SyntaxKind.AnyKeyword)}),jr())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,ge)]),f=Zt(this.ids.paramsArgument,n.createCallExpression(n.createPropertyAccessExpression(this.ids.accumulator,"replace"),void 0,[m,n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter)]),this.ids.pathParameter),T=Zt(this.ids.paramsArgument,n.createConditionalExpression(n.createBinaryExpression(n.createCallExpression(n.createPropertyAccessExpression(this.ids.pathParameter,"indexOf"),void 0,[m]),Z.SyntaxKind.GreaterThanEqualsToken,n.createNumericLiteral(0)),void 0,this.ids.accumulator,void 0,n.createObjectLiteralExpression([n.createSpreadAssignment(this.ids.accumulator),n.createPropertyAssignment(n.createComputedPropertyName(this.ids.keyParameter),n.createElementAccessExpression(this.ids.paramsArgument,this.ids.keyParameter))])),n.createObjectLiteralExpression()),g=vr(this.ids.clientClass,Zr([Qe(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),wr)]),[Mr(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),wt([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createCallExpression(n.createPropertyAccessExpression(n.createThis(),this.ids.implementationArgument),void 0,[this.ids.methodParameter,f,T]),!0))]);this.program.push(p,d,c,l,g);let S=n.createPropertyAssignment(this.ids.methodParameter,n.createCallExpression(n.createPropertyAccessExpression(this.ids.methodParameter,"toUpperCase"),void 0,void 0)),y=n.createPropertyAssignment(this.ids.headersProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createObjectLiteralExpression([n.createPropertyAssignment(n.createStringLiteral("Content-Type"),n.createStringLiteral(H))]),void 0,this.ids.undefinedValue)),x=n.createPropertyAssignment(this.ids.bodyProperty,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createCallExpression(n.createPropertyAccessExpression(n.createIdentifier("JSON"),"stringify"),void 0,[this.ids.paramsArgument]),void 0,this.ids.undefinedValue)),j=n.createVariableStatement(void 0,G(this.ids.responseConst,n.createAwaitExpression(n.createCallExpression(n.createIdentifier("fetch"),void 0,[n.createTemplateExpression(n.createTemplateHead("https://example.com"),[n.createTemplateSpan(this.ids.pathParameter,n.createTemplateMiddle("")),n.createTemplateSpan(this.ids.searchParamsConst,ge)]),n.createObjectLiteralExpression([S,y,x])])))),I=n.createVariableStatement(void 0,G(this.ids.hasBodyConst,n.createLogicalNot(n.createCallExpression(n.createPropertyAccessExpression(n.createArrayLiteralExpression([n.createStringLiteral("get"),n.createStringLiteral("delete")]),"includes"),void 0,[this.ids.methodParameter])))),Y=n.createVariableStatement(void 0,G(this.ids.searchParamsConst,n.createConditionalExpression(this.ids.hasBodyConst,void 0,n.createStringLiteral(""),void 0,n.createTemplateExpression(n.createTemplateHead("?"),[n.createTemplateSpan(n.createNewExpression(n.createIdentifier("URLSearchParams"),void 0,[this.ids.paramsArgument]),ge)])))),[R,K]=["json","text"].map(b=>n.createReturnStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.responseConst,b),void 0,void 0))),D=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(Rt,[n.createTemplateSpan(this.ids.methodParameter,At),n.createTemplateSpan(this.ids.pathParameter,ge)]),Z.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([R])),J=n.createVariableStatement(_,G(this.ids.exampleImplementationConst,wt([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([I,Y,j,D,K]),!0),n.createTypeReferenceNode(this.ids.implementationType))),xe=n.createExpressionStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.clientConst,this.ids.provideMethod),void 0,[n.createStringLiteral("get"),n.createStringLiteral("/v1/user/retrieve"),n.createObjectLiteralExpression([n.createPropertyAssignment("id",n.createStringLiteral("10"))])])),rt=n.createVariableStatement(void 0,G(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(J,rt,xe)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:Mt(r,t)).join(`
19
19
  `):void 0}print(t){let r=this.printUsage(t),o=r&&Z.addSyntheticLeadingComment(Z.addSyntheticLeadingComment(n.createEmptyStatement(),Z.SyntaxKind.SingleLineCommentTrivia," Usage example:"),Z.SyntaxKind.MultiLineCommentTrivia,`
20
20
  ${r}`);return this.program.concat(o||[]).map((i,s)=>Mt(i,s<this.program.length?t:{...t,omitTrailingSemicolon:!0})).join(`
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-zod-api",
3
- "version": "16.4.0-beta2",
3
+ "version": "16.4.0",
4
4
  "description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
5
5
  "license": "MIT",
6
6
  "repository": {