express-zod-api 16.2.2 → 16.3.0-beta1
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/CHANGELOG.md +11 -0
- package/README.md +3 -3
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +170 -75
- package/dist/index.d.ts +170 -75
- package/dist/index.js +8 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## Version 16
|
|
4
4
|
|
|
5
|
+
### 16.3.0
|
|
6
|
+
|
|
7
|
+
- Switching to using native `zod` methods for proprietary schemas instead of custom classes (`ez` namespace):
|
|
8
|
+
- Each proprietary schema now relies on internal Metadata;
|
|
9
|
+
- Validation errors for `ez.file()` are changed slightly;
|
|
10
|
+
- The following refinements of `ez.file()` are deprecated and will be removed later:
|
|
11
|
+
- ~~`ez.file().string()`~~ — use `ez.file("string")` instead,
|
|
12
|
+
- ~~`ez.file().buffer()`~~ — use `ez.file("buffer")` instead,
|
|
13
|
+
- ~~`ez.file().base64()`~~ — use `ez.file("base64")` instead,
|
|
14
|
+
- ~~`ez.file().binary()`~~ — use `ez.file("binary")` instead.
|
|
15
|
+
|
|
5
16
|
### 16.2.2
|
|
6
17
|
|
|
7
18
|
- Fixed issue #1458 reported by [@elee1766](https://github.com/elee1766):
|
package/README.md
CHANGED
|
@@ -708,14 +708,14 @@ You can find two approaches to `EndpointsFactory` and `ResultHandler` implementa
|
|
|
708
708
|
[in this example](https://github.com/RobinTail/express-zod-api/blob/master/example/factories.ts).
|
|
709
709
|
One of them implements file streaming, in this case the endpoint just has to provide the filename.
|
|
710
710
|
The response schema generally may be just `z.string()`, but I made more specific `ez.file()` that also supports
|
|
711
|
-
|
|
711
|
+
`ez.file("binary")` and `ez.file("base64")` variants which are reflected in the
|
|
712
712
|
[generated documentation](#creating-a-documentation).
|
|
713
713
|
|
|
714
714
|
```typescript
|
|
715
715
|
const fileStreamingEndpointsFactory = new EndpointsFactory(
|
|
716
716
|
createResultHandler({
|
|
717
717
|
getPositiveResponse: () => ({
|
|
718
|
-
schema: ez.file(
|
|
718
|
+
schema: ez.file("buffer"),
|
|
719
719
|
mimeType: "image/*",
|
|
720
720
|
}),
|
|
721
721
|
getNegativeResponse: () => ({ schema: z.string(), mimeType: "text/plain" }),
|
|
@@ -899,7 +899,7 @@ Some APIs may require an endpoint to be able to accept and process raw data, suc
|
|
|
899
899
|
file as an entire body of request. In order to enable this feature you need to set the `rawParser` config feature to
|
|
900
900
|
`express.raw()`. See also its options [in Express.js documentation](https://expressjs.com/en/4x/api.html#express.raw).
|
|
901
901
|
The raw data is placed into `request.body.raw` property, having type `Buffer`. Then use the proprietary `ez.raw()`
|
|
902
|
-
schema (which is an alias for `z.object({ raw: ez.file(
|
|
902
|
+
schema (which is an alias for `z.object({ raw: ez.file("buffer") })`) as the input schema of your endpoint.
|
|
903
903
|
|
|
904
904
|
```typescript
|
|
905
905
|
import express from "express";
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
Caused by ${
|
|
1
|
+
"use strict";var lo=Object.create;var Ke=Object.defineProperty;var uo=Object.getOwnPropertyDescriptor;var fo=Object.getOwnPropertyNames;var yo=Object.getPrototypeOf,go=Object.prototype.hasOwnProperty;var ho=(e,t)=>{for(var r in t)Ke(e,r,{get:t[r],enumerable:!0})},Qt=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of fo(t))!go.call(e,i)&&i!==r&&Ke(e,i,{get:()=>t[i],enumerable:!(o=uo(t,i))||o.enumerable});return e};var R=(e,t,r)=>(r=e!=null?lo(yo(e)):{},Qt(t||!e||!e.__esModule?Ke(r,"default",{value:e,enumerable:!0}):r,e)),xo=e=>Qt(Ke({},"__esModule",{value:!0}),e);var Un={};ho(Un,{AbstractEndpoint:()=>ae,DependsOnMethod:()=>Te,Documentation:()=>at,DocumentationError:()=>C,EndpointsFactory:()=>xe,InputValidationError:()=>H,Integration:()=>lt,MissingPeerError:()=>oe,OutputValidationError:()=>G,RoutingError:()=>te,ServeStatic:()=>be,arrayEndpointsFactory:()=>Tr,arrayResultHandler:()=>ot,attachRouting:()=>Er,createConfig:()=>Xt,createLogger:()=>nt,createMiddleware:()=>tt,createResultHandler:()=>rt,createServer:()=>wr,defaultEndpointsFactory:()=>xr,defaultResultHandler:()=>he,ez:()=>po,getExamples:()=>q,getMessageFromError:()=>U,getStatusCodeFromError:()=>ve,testEndpoint:()=>Wr,withMeta:()=>N});module.exports=xo(Un);function Xt(e){return e}var Ot=R(require("assert/strict"),1),Xe=require("zod");var er=require("zod"),fe={positive:200,negative:400},ft=(e,t)=>e instanceof er.z.ZodType?[{...t,schema:e}]:(Array.isArray(e)?e:[e]).map(({schema:r,statusCodes:o,statusCode:i,mimeTypes:s,mimeType:a})=>({schema:r,statusCodes:i?[i]:o||t.statusCodes,mimeTypes:a?[a]:s||t.mimeTypes}));var dr=require("http-errors"),cr=require("crypto"),mr=require("ramda"),A=require("zod");var te=class extends Error{name="RoutingError"},C=class extends Error{name="DocumentationError";constructor({message:t,method:r,path:o,isResponse:i}){let s=`${t}
|
|
2
|
+
Caused by ${i?"response":"input"} schema of an Endpoint assigned to ${r.toUpperCase()} method of ${o} path.`;super(s)}},_=class extends Error{name="IOSchemaError"},G=class extends _{name="OutputValidationError";originalError;constructor(t){super(U(t)),this.originalError=t}},H=class extends _{name="InputValidationError";originalError;constructor(t){super(U(t)),this.originalError=t}},re=class extends Error{name="ResultHandlerError";originalError;constructor(t,r){super(t),this.originalError=r||void 0}},oe=class extends Error{name="MissingPeerError";constructor(t){let r=Array.isArray(t);super(`Missing ${r?"one of the following peer dependencies":"peer dependency"}: ${r?t.join(" | "):t}. Please install it to use the feature.`)}};var yt=require("zod"),He=require("ramda"),F="expressZodApiMeta",To=e=>e.describe(e.description),N=e=>{let t=To(e);return t._def[F]=(0,He.clone)(t._def[F])||{examples:[]},Object.defineProperties(t,{example:{get:()=>r=>{let o=N(t);return o._def[F].examples.push(r),o}}})},tr=e=>yt.z.object({[F]:yt.z.object({})}).safeParse(e._def).success,Ce=(e,t)=>tr(e)?e._def[F][t]:void 0,Ue=(e,t)=>{if(!tr(e))return t;let r=N(t);return r._def[F].examples=Ee(r._def[F].examples,e._def[F].examples,([o,i])=>typeof o=="object"&&typeof i=="object"?(0,He.mergeDeepRight)({...o},{...i}):i),r},j=(e,t)=>{let r=N(t);return r._def[F].proprietaryKind=e,r},gt=(e,t)=>Ce(e,"proprietaryKind")===t;var B="application/json",we="multipart/form-data",rr="application/octet-stream";var sr=require("zod");var Ve=require("zod");var or=require("zod"),Fe=e=>!isNaN(e.getTime()),Ze=or.z.custom(e=>Buffer.isBuffer(e),{message:"Expected Buffer"}),nr=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Be=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?)?Z?$/;var ze="File",qe=e=>Object.entries(ir).reduce((t,[r,o])=>Object.defineProperty(t,r,{get:()=>o}),j(ze,e)),ir={buffer:()=>qe(Ze),string:()=>qe(Ve.z.string()),binary:()=>qe(Ze.or(Ve.z.string())),base64:()=>qe(Ve.z.string().regex(nr,"Does not match base64 encoding"))};function $e(e){return ir[e||"string"]()}var ne="Raw",ar=()=>j(ne,sr.z.object({raw:$e("buffer")}));var z=require("zod");var Me="Upload",pr=()=>j(Me,z.z.custom(e=>z.z.object({name:z.z.string(),encoding:z.z.string(),mimetype:z.z.string(),data:Ze,tempFilePath:z.z.string(),truncated:z.z.boolean(),size:z.z.number(),md5:z.z.string(),mv:z.z.function()}).safeParse(e).success,e=>({message:`Expected file upload, received ${typeof e}`})));var bo=e=>{let r=(e.header("content-type")||"").slice(0,we.length).toLowerCase()===we;return"files"in e&&r},_e={get:["query","params"],post:["body","params","files"],put:["body","params"],patch:["body","params"],delete:["query","params"]},So=["body","query","params"],ht=e=>e.method.toLowerCase(),xt=e=>e.startsWith("x-"),Oo=e=>Object.entries(e.headers).reduce((t,[r,o])=>xt(r)?{...t,[r]:o}:t,{}),lr=(e,t)=>{let r=ht(e);if(r==="options")return{};let o=So;return r in _e&&(o=_e[r]),t&&r in t&&(o=t[r]||o),o.filter(i=>i==="files"?bo(e):!0).reduce((i,s)=>({...i,...s==="headers"?Oo(e):e[s]}),{})},ye=e=>e instanceof Error?e:new Error(typeof e=="symbol"?e.toString():`${e}`),U=e=>e instanceof A.z.ZodError?e.issues.map(({path:t,message:r})=>(t.length?[t.join("/")]:[]).concat(r).join(": ")).join("; "):e instanceof G?`output${e.originalError.issues[0]?.path.length>0?"/":": "}${e.message}`:e.message,ve=e=>(0,dr.isHttpError)(e)?e.statusCode:e instanceof H?400:500,Tt=({logger:e,request:t,input:r,error:o,statusCode:i})=>{i===500&&e.error(`Internal server error
|
|
3
3
|
${o.stack}
|
|
4
|
-
`,{url:t.url,payload:r})},
|
|
5
|
-
Original error: ${e.originalError.message}.`:""))};var
|
|
4
|
+
`,{url:t.url,payload:r})},q=({schema:e,variant:t="original",validate:r=t==="parsed"})=>{let o=Ce(e,"examples")||[];if(!r&&t==="original")return o;let i=[];for(let s of o){let a=e.safeParse(s);a.success&&i.push(t==="parsed"?a.data:s)}return i},Ee=(e,t,r)=>e.length&&t.length?(0,mr.xprod)(e,t).map(r):e.concat(t),W=e=>e instanceof A.z.ZodEffects&&e._def.effect.type!=="refinement"?!0:e instanceof A.z.ZodUnion?e.options.some(W):e instanceof A.z.ZodIntersection?[e._def.left,e._def.right].some(W):!1,D=({subject:e,condition:t,maxDepth:r,depth:o=1})=>{if(t(e))return!0;if(r!==void 0&&o>=r)return!1;let i={condition:t,maxDepth:r,depth:o+1};return e instanceof A.z.ZodObject?Object.values(e.shape).some(s=>D({subject:s,...i})):e instanceof A.z.ZodUnion?e.options.some(s=>D({subject:s,...i})):e instanceof A.z.ZodIntersection?[e._def.left,e._def.right].some(s=>D({subject:s,...i})):e instanceof A.z.ZodOptional||e instanceof A.z.ZodNullable?D({subject:e.unwrap(),...i}):e instanceof A.z.ZodEffects||e instanceof A.z.ZodTransformer?D({subject:e.innerType(),...i}):e instanceof A.z.ZodRecord?D({subject:e.valueSchema,...i}):e instanceof A.z.ZodArray?D({subject:e.element,...i}):e instanceof A.z.ZodDefault?D({subject:e._def.innerType,...i}):!1},ur=e=>D({subject:e,condition:t=>gt(t,Me)}),fr=e=>D({subject:e,condition:t=>gt(t,ne),maxDepth:3}),Ne=e=>"coerce"in e._def&&typeof e._def.coerce=="boolean"?e._def.coerce:!1,bt=e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),M=(...e)=>e.flatMap(t=>t.split(/[^A-Z0-9]/gi)).flatMap(t=>t.replaceAll(/[A-Z]+/g,r=>`/${r}`).split("/")).map(bt).join(""),Ge=e=>(0,cr.createHash)("sha1").update(JSON.stringify(e),"utf8").digest("hex"),We=(e,t)=>{try{return typeof e.parse(t)}catch{return}};var Ye=({error:e,logger:t,response:r})=>{t.error(`Result handler failure: ${e.message}.`),r.status(500).end(`An error occurred while serving the result: ${e.message}.`+(e.originalError?`
|
|
5
|
+
Original error: ${e.originalError.message}.`:""))};var yr=e=>typeof e=="object"&&e!==null,ie=e=>yr(e)&&"or"in e,se=e=>yr(e)&&"and"in e,Je=e=>({and:e.reduce((t,r)=>t.concat(se(r)?r.and:r),[])}),Qe=(e,t)=>se(e)?{and:e.and.map(r=>ie(r)?{or:r.or.map(t)}:t(r))}:ie(e)?{or:e.or.map(r=>se(r)?{and:r.and.map(t)}:t(r))}:t(e),St=e=>e.and.reduce((t,r)=>({or:Ee(t.or,ie(r)?r.or:[r],Je)}),{or:[]}),ge=(e,t)=>se(e)?se(t)?Je([e,t]):ie(t)?ge(St(e),t):Je([e,t]):ie(e)?se(t)?ge(t,e):ie(t)?{or:Ee(e.or,t.or,Je)}:ge(e,{and:[t]}):se(t)||ie(t)?ge(t,e):{and:[e,t]};var ae=class{},et=class extends ae{#e;#o;#n;#i;#t;#s;#a;#r;#p;#d;#c;#m=[];constructor({methods:t,inputSchema:r,outputSchema:o,handler:i,resultHandler:s,getOperationId:a=()=>{},scopes:p=[],middlewares:d=[],tags:c=[],description:l,shortDescription:m}){super(),this.#s=i,this.#a=s,this.#n=d,this.#c=a,this.#o=t,this.#p=p,this.#d=c,this.#e={long:l,short:m},this.#r={input:r,output:o};for(let[f,T]of Object.entries(this.#r))(0,Ot.default)(!W(T),new _(`Using transformations on the top level of endpoint ${f} schema is not allowed.`));this.#t={positive:ft(s.getPositiveResponse(o),{mimeTypes:[B],statusCodes:[fe.positive]}),negative:ft(s.getNegativeResponse(),{mimeTypes:[B],statusCodes:[fe.negative]})};for(let[f,T]of Object.entries(this.#t))(0,Ot.default)(T.length,new re(`ResultHandler must have at least one ${f} response schema specified.`));this.#i={input:ur(r)?[we]:fr(r)?[rr]:[B],positive:this.#t.positive.flatMap(({mimeTypes:f})=>f),negative:this.#t.negative.flatMap(({mimeTypes:f})=>f)}}_setSiblingMethods(t){this.#m=t}getDescription(t){return this.#e[t]}getMethods(){return this.#o}getSchema(t){return t==="input"||t==="output"?this.#r[t]:this.getResponses(t).map(({schema:r})=>r).reduce((r,o)=>r.or(o))}getMimeTypes(t){return this.#i[t]}getResponses(t){return this.#t[t]}getSecurity(){return this.#n.reduce((t,r)=>r.security?ge(t,r.security):t,{and:[]})}getScopes(){return this.#p}getTags(){return this.#d}getOperationId(t){return this.#c(t)}#l(){return{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":this.#o.concat(this.#m).concat("options").join(", ").toUpperCase(),"Access-Control-Allow-Headers":"content-type"}}async#u(t){try{return await this.#r.output.parseAsync(t)}catch(r){throw r instanceof Xe.z.ZodError?new G(r):r}}async#f({method:t,input:r,request:o,response:i,logger:s}){let a={},p=!1;for(let d of this.#n){if(t==="options"&&d.type==="proprietary")continue;let c;try{c=await d.input.parseAsync(r)}catch(l){throw l instanceof Xe.z.ZodError?new H(l):l}if(Object.assign(a,await d.middleware({input:c,options:a,request:o,response:i,logger:s})),p="writableEnded"in i&&i.writableEnded,p){s.warn(`The middleware ${d.middleware.name} has closed the stream. Accumulated options:`,a);break}}return{options:a,isStreamClosed:p}}async#y({input:t,options:r,logger:o}){let i;try{i=await this.#r.input.parseAsync(t)}catch(s){throw s instanceof Xe.z.ZodError?new H(s):s}return this.#s({input:i,options:r,logger:o})}async#g({error:t,request:r,response:o,logger:i,input:s,output:a}){try{await this.#a.handler({error:t,output:a,request:r,response:o,logger:i,input:s})}catch(p){Ye({logger:i,response:o,error:new re(ye(p).message,t)})}}async execute({request:t,response:r,logger:o,config:i}){let s=ht(t),a=null,p=null;if(i.cors){let c=this.#l();typeof i.cors=="function"&&(c=await i.cors({request:t,logger:o,endpoint:this,defaultHeaders:c}));for(let l in c)r.set(l,c[l])}let d=lr(t,i.inputSources);try{let{options:c,isStreamClosed:l}=await this.#f({method:s,input:d,request:t,response:r,logger:o});if(l)return;if(s==="options"){r.status(200).end();return}a=await this.#u(await this.#y({input:d,options:c,logger:o}))}catch(c){p=ye(c)}await this.#g({input:d,output:a,request:t,response:r,error:p,logger:o})}};var Rt=require("zod");var gr=(e,t)=>{let r=e.map(({input:i})=>i).concat(t),o=r.reduce((i,s)=>i.and(s));return r.reduce((i,s)=>Ue(s,i),o)};var hr=R(require("assert/strict"),1),tt=e=>((0,hr.default)(!W(e.input),new _("Using transformations on the top level of middleware input schema is not allowed.")),{...e,type:"proprietary"});var v=require("zod");var rt=e=>e,he=rt({getPositiveResponse:e=>{let t=q({schema:e}),r=N(v.z.object({status:v.z.literal("success"),data:e}));return t.reduce((o,i)=>o.example({status:"success",data:i}),r)},getNegativeResponse:()=>N(v.z.object({status:v.z.literal("error"),error:v.z.object({message:v.z.string()})})).example({status:"error",error:{message:U(new Error("Sample error message"))}}),handler:({error:e,input:t,output:r,request:o,response:i,logger:s})=>{if(!e){i.status(fe.positive).json({status:"success",data:r});return}let a=ve(e);Tt({logger:s,statusCode:a,request:o,error:e,input:t}),i.status(a).json({status:"error",error:{message:U(e)}})}}),ot=rt({getPositiveResponse:e=>{let t=q({schema:e}),r=N("shape"in e&&"items"in e.shape&&e.shape.items instanceof v.z.ZodArray?e.shape.items:v.z.array(v.z.any()));return t.reduce((o,i)=>typeof i=="object"&&i!==null&&"items"in i&&Array.isArray(i.items)?o.example(i.items):o,r)},getNegativeResponse:()=>N(v.z.string()).example(U(new Error("Sample error message"))),handler:({response:e,output:t,error:r,logger:o,request:i,input:s})=>{if(r){let a=ve(r);Tt({logger:o,statusCode:a,request:i,error:r,input:s}),e.status(a).send(r.message);return}t&&"items"in t&&Array.isArray(t.items)?e.status(fe.positive).json(t.items):e.status(500).send("Property 'items' is missing in the endpoint output")}});var xe=class e{resultHandler;middlewares=[];constructor(t){this.resultHandler="resultHandler"in t?t.resultHandler:t}static#e(t,r){let o=new e(r);return o.middlewares=t,o}addMiddleware(t){return e.#e(this.middlewares.concat(t),this.resultHandler)}use=this.addExpressMiddleware;addExpressMiddleware(t,r){let o=r?.transformer||(a=>a),i=r?.provider||(()=>({})),s={type:"express",input:Rt.z.object({}),middleware:async({request:a,response:p})=>new Promise((d,c)=>{t(a,p,m=>{if(m&&m instanceof Error)return c(o(m));d(i(a,p))})})};return e.#e(this.middlewares.concat(s),this.resultHandler)}addOptions(t){return e.#e(this.middlewares.concat(tt({input:Rt.z.object({}),middleware:async()=>t})),this.resultHandler)}build({input:t,handler:r,output:o,description:i,shortDescription:s,operationId:a,...p}){let{middlewares:d,resultHandler:c}=this,l="methods"in p?p.methods:[p.method],m=typeof a=="function"?a:()=>a,f="scopes"in p?p.scopes:"scope"in p&&p.scope?[p.scope]:[],T="tags"in p?p.tags:"tag"in p&&p.tag?[p.tag]:[];return new et({handler:r,middlewares:d,outputSchema:o,resultHandler:c,scopes:f,tags:T,methods:l,getOperationId:m,description:i,shortDescription:s,inputSchema:gr(d,t)})}},xr=new xe(he),Tr=new xe(ot);var br=require("util"),Sr=e=>typeof e=="object"&&e!==null&&"level"in e&&("color"in e?typeof e.color=="boolean":!0)&&typeof e.level=="string"&&["silent","warn","debug"].includes(e.level),nt=({winston:{createLogger:e,transports:t,format:{printf:r,timestamp:o,colorize:i,combine:s},config:{npm:a}},...p})=>{let d=f=>{let{[Symbol.for("level")]:T,[Symbol.for("message")]:g,[Symbol.for("splat")]:S,...y}=f;return(0,br.inspect)(y,!1,1,p.color)},c=f=>r(({timestamp:T,message:g,level:S,durationMs:y,...x})=>{typeof g=="object"&&(x={...x,...g},g="[No message]");let L=Object.keys(x).length>0,w=[];y&&w.push("duration:",`${y}ms`);let Q=f?d:JSON.stringify;if(L)w.push(Q(x));else{let P=x?.[Symbol.for("splat")];Array.isArray(P)&&w.push(...P.map($=>typeof $=="object"?Q($):$))}return[T,`${S}:`,g,...w].join(" ")}),l=[o()],m={handleExceptions:!0};switch(p.color&&l.push(i()),p.level){case"debug":m.level="debug",l.push(c(!0));break;case"silent":case"warn":default:m.level="warn",l.push(c())}return m.format=s(...l),e({silent:p.level==="silent",levels:a.levels,transports:[new t.Console(m)],exitOnError:!1})};var Te=class{constructor(t){this.endpoints=t}};var Or=R(require("express"),1),be=class{params;constructor(...t){this.params=t}apply(t,r){return r(t,Or.default.static(...this.params))}};var It=R(require("express"),1),Pr=R(require("http"),1),Ir=R(require("https"),1);var pe=async(e,t="default")=>{try{return(await import(e))[t]}catch{}try{return await Promise.resolve().then(()=>require(e)[t])}catch{}throw new oe(e)},Rr=async e=>{for(let{moduleName:t,moduleExport:r}of e)try{return await pe(t,r)}catch{}throw new oe(e.map(({moduleName:t})=>t))};var At=R(require("assert/strict"),1);var de=({routing:e,onEndpoint:t,onStatic:r,parentPath:o,hasCors:i})=>{Object.entries(e).forEach(([s,a])=>{s=s.trim(),At.default.doesNotMatch(s,/\//,new te(`The entry '${s}' must avoid having slashes \u2014 use nesting instead.`));let p=`${o||""}${s?`/${s}`:""}`;if(a instanceof ae){let d=a.getMethods().slice();i&&d.push("options"),d.forEach(c=>{t(a,p,c)})}else if(a instanceof be)r&&a.apply(p,r);else if(a instanceof Te){if(Object.entries(a.endpoints).forEach(([d,c])=>{(0,At.default)(c.getMethods().includes(d),new te(`Endpoint assigned to ${d} method of ${p} must support ${d} method.`)),t(c,p,d)}),i&&Object.keys(a.endpoints).length>0){let[d,...c]=Object.keys(a.endpoints),l=a.endpoints[d];l._setSiblingMethods(c),t(l,p,"options")}}else de({onEndpoint:t,onStatic:r,hasCors:i,routing:a,parentPath:p})})};var Ar=()=>`
|
|
6
6
|
\x1B[94m8888888888 8888888888P 888 d8888 8888888b. 8888888 \x1B[39m
|
|
7
7
|
\x1B[94m888 d88P 888 d88888 888 Y88b 888\x1B[39m
|
|
8
8
|
\x1B[95m888 d88P 888 d88P888 888 888 888\x1B[39m
|
|
@@ -15,8 +15,8 @@ Original error: ${e.originalError.message}.`:""))};var pr=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 St=({app:e,logger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(xr()),t.debug("Running","v16.2.2 (CJS)"),me({routing:o,hasCors:!!r.cors,onEndpoint:(s,i,a)=>{e[a](i,async(d,p)=>{t.info(`${d.method}: ${i}`),await s.execute({request:d,response:p,logger:t,config:r})})},onStatic:(s,i)=>{e.use(s,i)}})};var At=I(require("http-errors"),1),xo=(e,t)=>(r,o,s,i)=>{if(!r)return i();e.handler({error:(0,At.default)(400,xe(r).message),request:o,response:s,logger:t,input:null,output:null})},To=(e,t)=>(r,o)=>{let s=(0,At.default)(404,`Can not ${r.method} ${r.path}`);try{e.handler({request:r,response:o,logger:t,error:s,input:null,output:null})}catch(i){$e({response:o,logger:t,error:new se(xe(i).message,s)})}},Sr=async e=>{let t=yr(e.logger)?Xe({...e.logger,winston:await ce("winston")}):e.logger,r=e.errorHandler||Se,o=To(r,t);return{logger:t,errorHandler:r,notFoundHandler:o}},Or=async(e,t)=>{let{logger:r,notFoundHandler:o}=await Sr(e);return St({app:e.app,routing:t,logger:r,config:e}),{notFoundHandler:o,logger:r}},Ar=async(e,t)=>{let r=(0,Ot.default)().disable("x-powered-by");if(e.server.compression){let p=await ce("compression");r.use(p(typeof e.server.compression=="object"?e.server.compression:void 0))}if(r.use(e.server.jsonParser||Ot.default.json()),e.server.upload){let p=await ce("express-fileupload");r.use(p({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}))}e.server.rawParser&&(r.use(e.server.rawParser),r.use((p,{},c)=>{Buffer.isBuffer(p.body)&&(p.body={raw:p.body}),c()}));let{logger:o,errorHandler:s,notFoundHandler:i}=await Sr(e);r.use(xo(s,o)),St({app:r,routing:t,logger:o,config:e}),r.use(i);let a=(p,c)=>p.listen(c,()=>{o.info("Listening",c)}),d={httpServer:a(Tr.default.createServer(r),e.server.listen),httpsServer:e.https?a(br.default.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...d,logger:o}};var kr=I(require("assert/strict"),1),Ur=require("openapi3-ts/oas31");var fe=I(require("assert/strict"),1),ue=require("openapi3-ts/oas31"),Pe=require("ramda"),R=require("zod");var P=require("zod");var Rt=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?)?Z?$/,bo="ZodDateIn",et=class e extends P.ZodType{_parse(t){let{status:r,ctx:o}=this._processInputParams(t);if(o.parsedType!==P.ZodParsedType.string)return(0,P.addIssueToContext)(o,{code:P.ZodIssueCode.invalid_type,expected:P.ZodParsedType.string,received:o.parsedType}),P.INVALID;Rt.test(o.data)||((0,P.addIssueToContext)(o,{code:P.ZodIssueCode.invalid_string,validation:"regex"}),r.dirty());let s=new Date(o.data);return Ue(s)?{status:r.value,value:s}:((0,P.addIssueToContext)(o,{code:P.ZodIssueCode.invalid_date}),P.INVALID)}static create=()=>new e({typeName:bo})};var le=({schema:e,onEach:t,rules:r,onMissing:o,...s})=>{let i="typeName"in e._def?r[e._def.typeName]:void 0,a=s,p=i?i({schema:e,...a,next:l=>le({...l,...a,onEach:t,rules:r,onMissing:o})}):o({schema:e,...a}),c=t&&t({schema:e,prev:p,...a});return c?{...p,...c}:p};var Rr=50,Ir="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",So={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},Cr=/:([A-Za-z0-9_]+)/g,Zr=e=>{let t=e.match(Cr);return t?t.map(r=>r.slice(1)):[]},Er=e=>e.replace(Cr,t=>`{${t.slice(1)}}`),Oo=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),Ao=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),Ro=()=>({format:"any"}),Po=e=>((0,fe.default)(!e.isResponse,new D({message:"Please use ez.upload() only for input.",...e})),{type:"string",format:"binary"}),Io=({schema:{isBinary:e,isBase64:t,isBuffer:r}})=>({type:"string",format:r||e?"binary":t?"byte":"file"}),Co=({schema:{options:e},next:t})=>({oneOf:e.map(r=>t({schema:r}))}),Zo=({schema:{options:e,discriminator:t},next:r})=>({discriminator:{propertyName:t},oneOf:Array.from(e.values()).map(o=>r({schema:o}))}),Eo=({schema:{_def:{left:e,right:t}},next:r})=>({allOf:[e,t].map(o=>r({schema:o}))}),wo=({schema:e,next:t})=>t({schema:e.unwrap()}),Do=({schema:e,next:t})=>t({schema:e._def.innerType}),No=({schema:e,next:t})=>{let r=t({schema:e.unwrap()});return(0,ue.isReferenceObject)(r)||(r.type=wr(r)),r},Pr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),vo=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Mo=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(i=>{let a=e.shape[i];return!(t&&ze(a)?a instanceof R.z.ZodOptional:a.isOptional())}),s={type:"object",properties:tt({schema:e,isResponse:t,...r})};return o.length&&(s.required=o),s},zo=()=>({type:"null"}),jo=e=>((0,fe.default)(!e.isResponse,new D({message:"Please use ez.dateOut() for output.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:Rt.source,externalDocs:{url:Ir}}),Lo=e=>((0,fe.default)(e.isResponse,new D({message:"Please use ez.dateIn() for input.",...e})),{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:Ir}}),ko=e=>fe.default.fail(new D({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})),Uo=()=>({type:"boolean"}),Ho=()=>({type:"integer",format:"bigint"}),Fo=e=>e.reduce((t,r)=>t&&r instanceof R.z.ZodLiteral,!0),Ko=({schema:{keySchema:e,valueSchema:t},...r})=>{if(e instanceof R.z.ZodEnum||e instanceof R.z.ZodNativeEnum){let o=Object.values(e.enum),s=o.reduce((a,d)=>({...a,[d]:t}),{}),i={type:"object",properties:tt({schema:R.z.object(s),...r})};return o.length&&(i.required=o),i}if(e instanceof R.z.ZodLiteral)return{type:"object",properties:tt({schema:R.z.object({[e.value]:t}),...r}),required:[e.value]};if(e instanceof R.z.ZodUnion&&Fo(e.options)){let o=e.options.reduce((s,i)=>({...s,[`${i.value}`]:t}),{});return{type:"object",properties:tt({schema:R.z.object(o),...r}),required:e.options.map(s=>s.value)}}return{type:"object",additionalProperties:r.next({schema:t})}},Bo=({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},qo=({schema:{items:e},next:t})=>({type:"array",prefixItems:e.map(o=>t({schema:o}))}),$o=({schema:{isEmail:e,isURL:t,minLength:r,maxLength:o,isUUID:s,isCUID:i,isCUID2:a,isULID:d,isIP:p,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,O={type:"string"},y={"date-time":l,email:e,url:t,uuid:s,cuid:i,cuid2:a,ulid:d,ip:p,emoji:c};for(let x in y)if(y[x]){O.format=x;break}return r!==null&&(O.minLength=r),o!==null&&(O.maxLength=o),g&&(O.pattern=g.source),O},Vo=({schema:e})=>{let t=e._def.checks.find(({kind:p})=>p==="min"),r=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,o=t?t.inclusive:!0,s=e._def.checks.find(({kind:p})=>p==="max"),i=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,a=s?s.inclusive:!0,d={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return o?d.minimum=r:d.exclusiveMinimum=r,a?d.maximum=i:d.exclusiveMaximum=i,d},tt=({schema:{shape:e},next:t})=>Object.keys(e).reduce((r,o)=>({...r,[o]:t({schema:e[o]})}),{}),_o=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return So?.[t]},wr=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Go=({schema:e,isResponse:t,next:r})=>{let o=r({schema:e.innerType()}),{effect:s}=e._def;if(t&&s.type==="transform"&&!(0,ue.isReferenceObject)(o)){let i=qe(e,_o(o));return i&&["number","string","boolean"].includes(i)?{type:i}:r({schema:R.z.any()})}if(!t&&s.type==="preprocess"&&!(0,ue.isReferenceObject)(o)){let{type:i,...a}=o;return{...a,format:`${a.format||i} (preprocessed)`}}return o},Wo=({schema:e,isResponse:t,next:r})=>r({schema:e._def[t?"out":"in"]}),Yo=({schema:e,next:t})=>t({schema:e.unwrap()}),Jo=({next:e,schema:t,serializer:r,getRef:o,makeRef:s})=>{let i=r(t.schema);return o(i)||(s(i,{}),s(i,e({schema:t.schema})))},Dr=(e,t,r=[])=>{let o=V({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((s,i,a)=>({...s,[`example${a+1}`]:{value:typeof i=="object"&&!Array.isArray(i)?(0,Pe.omit)(r,i):i}}),{})},Qo=(e,t,r)=>{let o=V({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((s,i,a)=>r in i?{...s,[`example${a+1}`]:{value:i[r]}}:s,{})},je=(e,t)=>{if(e instanceof R.z.ZodObject)return e;let r;return e instanceof R.z.ZodUnion||e instanceof R.z.ZodDiscriminatedUnion?r=Array.from(e.options.values()).map(o=>je(o,t)).reduce((o,s)=>o.merge(s.partial()),R.z.object({})):e instanceof R.z.ZodEffects?((0,fe.default)(!Q(e),new D({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=je(e._def.schema,t)):r=je(e._def.left,t).merge(je(e._def.right,t)),Fe(e,r)},Nr=({path:e,method:t,schema:r,inputSources:o,serializer:s,getRef:i,makeRef:a,composition:d,description:p=`${t.toUpperCase()} ${e} Parameter`})=>{let c=je(r,{path:e,method:t,isResponse:!1}).shape,l=Zr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),O=y=>T&&ft(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=le({schema:c[y],isResponse:!1,rules:It,onEach:Ct,onMissing:Zt,serializer:s,getRef:i,makeRef:a,path:e,method:t}),H=d==="components"?a(j(p,y),x):x;return{name:y,in:g(y)?"path":O(y)?"header":"query",required:!c[y].isOptional(),description:x.description||p,schema:H,examples:Qo(r,!1,y)}})},It={ZodString:$o,ZodNumber:Vo,ZodBigInt:Ho,ZodBoolean:Uo,ZodDateIn:jo,ZodDateOut:Lo,ZodNull:zo,ZodArray:Bo,ZodTuple:qo,ZodRecord:Ko,ZodObject:Mo,ZodLiteral:vo,ZodIntersection:Eo,ZodUnion:Co,ZodFile:Io,ZodUpload:Po,ZodAny:Ro,ZodDefault:Oo,ZodEnum:Pr,ZodNativeEnum:Pr,ZodEffects:Go,ZodOptional:wo,ZodNullable:No,ZodDiscriminatedUnion:Zo,ZodBranded:Yo,ZodDate:ko,ZodCatch:Ao,ZodPipeline:Wo,ZodLazy:Jo,ZodReadonly:Do},Ct=({schema:e,isResponse:t,prev:r})=>{if((0,ue.isReferenceObject)(r))return{};let{description:o}=e,s=e instanceof R.z.ZodLazy,i=r.type!==void 0,a=t&&ze(e),d=!s&&i&&!a&&e.isNullable(),p=s?[]:V({schema:e,variant:t?"parsed":"original",validate:!0}),c={};return o&&(c.description=o),d&&(c.type=wr(r)),p.length&&(c.examples=Array.from(p)),c},Zt=({schema:e,...t})=>fe.default.fail(new D({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),Pt=(e,t)=>{if((0,ue.isReferenceObject)(e))return e;let r=e.properties?(0,Pe.omit)(t,e.properties):void 0,o=e.examples?e.examples.map(d=>(0,Pe.omit)(t,d)):void 0,s=e.required?e.required.filter(d=>!t.includes(d)):void 0,i=e.allOf?e.allOf.map(d=>Pt(d,t)):void 0,a=e.oneOf?e.oneOf.map(d=>Pt(d,t)):void 0;return(0,Pe.omit)(Object.entries({properties:r,required:s,examples:o,allOf:i,oneOf:a}).filter(([{},d])=>d===void 0).map(([d])=>d),{...e,properties:r,required:s,examples:o,allOf:i,oneOf:a})},vr=e=>(0,ue.isReferenceObject)(e)?e:(0,Pe.omit)(["examples"],e),Mr=({method:e,path:t,schema:r,mimeTypes:o,variant:s,serializer:i,getRef:a,makeRef:d,composition:p,hasMultipleStatusCodes:c,statusCode:l,description:m=`${e.toUpperCase()} ${t} ${gt(s)} response ${c?l:""}`.trim()})=>{let f=vr(le({schema:r,isResponse:!0,rules:It,onEach:Ct,onMissing:Zt,serializer:i,getRef:a,makeRef:d,path:t,method:e})),T=Dr(r,!0),g=p==="components"?d(j(m),f):f;return{description:m,content:o.reduce((O,y)=>({...O,[y]:{schema:g,examples:T}}),{})}},Xo=()=>({type:"http",scheme:"basic"}),en=({format:e})=>{let t={type:"http",scheme:"bearer"};return e&&(t.bearerFormat=e),t},tn=({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},rn=({name:e})=>({type:"apiKey",in:"header",name:e}),on=({name:e})=>({type:"apiKey",in:"cookie",name:e}),nn=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),sn=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((t,r)=>{let o=e[r];if(!o)return t;let{scopes:s={},...i}=o;return{...t,[r]:{...i,scopes:s}}},{})}),zr=(e,t)=>{let r={basic:Xo,bearer:en,input:tn,header:rn,cookie:on,openid:nn,oauth2:sn};return _e(e,o=>r[o.type](o,t))},rt=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:s})=>({...r,[o]:s}),{}));if("and"in e)return rt(ht(e))}return rt({or:[e]})},jr=({method:e,path:t,schema:r,mimeTypes:o,serializer:s,getRef:i,makeRef:a,composition:d,description:p=`${e.toUpperCase()} ${t} Request body`})=>{let c=Zr(t),l=vr(Pt(le({schema:Te(r)?z.create().buffer():r,isResponse:!1,rules:It,onEach:Ct,onMissing:Zt,serializer:s,getRef:i,makeRef:a,path:t,method:e}),c)),m=Dr(r,!1,c),f=d==="components"?a(j(p),l):l;return{description:p,content:o.reduce((T,g)=>({...T,[g]:{schema:f,examples:m}}),{})}},Lr=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}),Et=e=>e.length<=Rr?e:e.slice(0,Rr-1)+"\u2026";var ot=class extends Ur.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,kr.default)(!(o in this.lastOperationIdSuffixes),new D({message:`Duplicated operationId: "${o}"`,method:r,isResponse:!1,path:t})),this.lastOperationIdSuffixes[o]=1,o;let s=j(r,t);return s in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[s]++,`${s}${this.lastOperationIdSuffixes[s]}`):(this.lastOperationIdSuffixes[s]=1,s)}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:s,serverUrl:i,descriptions:a,hasSummaryFromDescription:d=!0,composition:p="inline",serializer:c=Be}){super(),this.addInfo({title:o,version:s});for(let m of typeof i=="string"?[i]:i)this.addServer({url:m});me({routing:t,onEndpoint:(m,f,T)=>{let g=T,O={path:f,method:g,endpoint:m,composition:p,serializer:c,getRef:this.getRef.bind(this),makeRef:this.makeRef.bind(this)},[y,x]=["short","long"].map(m.getDescription.bind(m)),H=r.inputSources?.[g]||Ke[g],v=this.ensureUniqOperationId(f,g,m.getOperationId(g)),te=Nr({...O,inputSources:H,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:v})}),Z={operationId:v,responses:{}};for(let F of["positive","negative"]){let re=m.getResponses(F);for(let{mimeTypes:Ze,schema:ct,statusCodes:S}of re)for(let E of S)Z.responses[E]=Mr({...O,variant:F,schema:ct,mimeTypes:Ze,statusCode:E,hasMultipleStatusCodes:re.length>1||S.length>1,description:a?.[`${F}Response`]?.call(null,{method:g,path:f,operationId:v,statusCode:E})})}x&&(Z.description=x,d&&y===void 0&&(Z.summary=Et(x))),y&&(Z.summary=Et(y)),m.getTags().length>0&&(Z.tags=m.getTags()),te.length>0&&(Z.parameters=te),H.includes("body")&&(Z.requestBody=jr({...O,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:v})}));let G=rt(_e(zr(m.getSecurity(),H),F=>{let re=this.ensureUniqSecuritySchemaName(F),Ze=["oauth2","openIdConnect"].includes(F.type)?m.getScopes():[];return this.addSecurityScheme(re,F),{name:re,scopes:Ze}}));G.length>0&&(Z.security=G),this.addPath(Er(f),{[g]:Z})}}),this.rootDoc.tags=r.tags?Lr(r.tags):[]}};var wt=I(require("http"),1);var an=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>$),...t}),dn=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:wt.default.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=wt.default.STATUS_CODES[o],r)),json:e(()=>r),send:e(()=>r),end:e(()=>(r.writableEnded=!0,r)),...t};return r},pn=({fnMethod:e,loggerProps:t})=>({info:e(),warn:e(),error:e(),debug:e(),...t}),Hr=async({endpoint:e,requestProps:t,responseProps:r,configProps:o,loggerProps:s,fnMethod:i})=>{let a=i||(await hr([{moduleName:"vitest",moduleExport:"vi"},{moduleName:"@jest/globals",moduleExport:"jest"}])).fn,d=an({fnMethod:a,requestProps:t}),p=dn({fnMethod:a,responseProps:r}),c=pn({fnMethod:a,loggerProps:s}),l={cors:!1,logger:c,...o};return await e.execute({request:d,response:p,config:l,logger:c}),{requestMock:d,responseMock:p,loggerMock:c}};var N=I(require("typescript"),1);var U=I(require("typescript"),1),n=U.default.factory,X=[n.createModifier(U.default.SyntaxKind.ExportKeyword)],cn=[n.createModifier(U.default.SyntaxKind.AsyncKeyword)],mn=[n.createModifier(U.default.SyntaxKind.PublicKeyword),n.createModifier(U.default.SyntaxKind.ReadonlyKeyword)],Fr=[n.createModifier(U.default.SyntaxKind.ProtectedKeyword),n.createModifier(U.default.SyntaxKind.ReadonlyKeyword)],Dt=n.createTemplateHead(""),Ie=n.createTemplateTail(""),Nt=n.createTemplateMiddle(" "),vt=e=>n.createTemplateLiteralType(Dt,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?Ie:Nt))),Mt=vt(["M","P"]),nt=(e,t,r)=>n.createParameterDeclaration(r,void 0,e,void 0,t,void 0),st=(e,t)=>Object.keys(e).reduce((r,o)=>r.concat(nt(n.createIdentifier(o),e[o],t)),[]),zt=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Kr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),Br=(e,t)=>n.createPropertySignature(void 0,`"${e}"`,void 0,n.createTypeReferenceNode(t)),ee=(e,t,r)=>n.createVariableDeclarationList([n.createVariableDeclaration(e,void 0,r,t)],U.default.NodeFlags.Const),jt=(e,t)=>n.createTypeAliasDeclaration(X,e,void 0,n.createUnionTypeNode(t.map(r=>n.createLiteralTypeNode(n.createStringLiteral(r))))),it=(e,t)=>n.createTypeAliasDeclaration(X,e,void 0,t),qr=(e,t,r)=>n.createPropertyDeclaration(mn,e,void 0,t,r),$r=(e,t,r=[])=>n.createClassDeclaration(X,e,void 0,void 0,[t,...r]),Vr=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),_r=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(U.default.SyntaxKind.AnyKeyword)]),Gr=(e,t,r)=>n.createInterfaceDeclaration(X,e,void 0,t,r),Wr=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),Lt=(e,t,r)=>n.createArrowFunction(r?cn:void 0,void 0,e.map(o=>nt(o)),void 0,void 0,t),kt=(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,st({acc:void 0,key:void 0}),void 0,void 0,t),r]);var Yr=["get","post","put","delete","patch"];var h=I(require("typescript"),1),Xr=require("zod");var _=I(require("typescript"),1),{factory:at}=_.default,Ut=(e,t)=>{_.default.addSyntheticLeadingComment(e,_.default.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},Ce=(e,t,r)=>{let o=at.createTypeAliasDeclaration(void 0,at.createIdentifier(t),void 0,e);return r&&Ut(o,r),o},Ht=(e,t)=>{let r=_.default.createSourceFile("print.ts","",_.default.ScriptTarget.Latest,!1,_.default.ScriptKind.TS);return _.default.createPrinter(t).printNode(_.default.EmitHint.Unspecified,e,r)},ln=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Jr=e=>ln.test(e)?at.createIdentifier(e):at.createStringLiteral(e);var{factory:u}=h.default,un={[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},fn=({schema:{value:e}})=>u.createLiteralTypeNode(typeof e=="number"?u.createNumericLiteral(e):typeof e=="boolean"?e?u.createTrue():u.createFalse():u.createStringLiteral(e)),yn=({schema:{shape:e},isResponse:t,next:r,optionalPropStyle:{withQuestionMark:o}})=>{let s=Object.entries(e).map(([i,a])=>{let d=t&&ze(a)?a instanceof Xr.z.ZodOptional:a.isOptional(),p=u.createPropertySignature(void 0,Jr(i),d&&o?u.createToken(h.default.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&Ut(p,a.description),p});return u.createTypeLiteralNode(s)},gn=({schema:{element:e},next:t})=>u.createArrayTypeNode(t({schema:e})),hn=({schema:{options:e}})=>u.createUnionTypeNode(e.map(t=>u.createLiteralTypeNode(u.createStringLiteral(t)))),Qr=({schema:{options:e},next:t})=>u.createUnionTypeNode(e.map(r=>t({schema:r}))),xn=e=>un?.[e.kind],Tn=({schema:e,next:t,isResponse:r})=>{let o=t({schema:e.innerType()}),s=e._def.effect;if(r&&s.type==="transform"){let i=qe(e,xn(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(i&&a[i]||h.default.SyntaxKind.AnyKeyword)}return o},bn=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(t=>u.createLiteralTypeNode(typeof t=="number"?u.createNumericLiteral(t):u.createStringLiteral(t)))),Sn=({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},On=({next:e,schema:t})=>u.createUnionTypeNode([e({schema:t.unwrap()}),u.createLiteralTypeNode(u.createNull())]),An=({next:e,schema:{items:t}})=>u.createTupleTypeNode(t.map(r=>e({schema:r}))),Rn=({next:e,schema:{keySchema:t,valueSchema:r}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:t}),e({schema:r})]),Pn=({next:e,schema:t})=>u.createIntersectionTypeNode([t._def.left,t._def.right].map(r=>e({schema:r}))),In=({next:e,schema:t})=>e({schema:t._def.innerType}),ye=e=>()=>u.createKeywordTypeNode(e),Cn=({next:e,schema:t})=>e({schema:t.unwrap()}),Zn=({next:e,schema:t})=>e({schema:t._def.innerType}),En=({next:e,schema:t})=>e({schema:t._def.innerType}),wn=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),Dn=()=>u.createLiteralTypeNode(u.createNull()),Nn=({getAlias:e,makeAlias:t,next:r,serializer:o,schema:s})=>{let i=`Type${o(s.schema)}`;return e(i)||(t(i,u.createLiteralTypeNode(u.createNull())),t(i,r({schema:s.schema})))},vn=({schema:{isBuffer:e}})=>e?u.createTypeReferenceNode("Buffer"):u.createKeywordTypeNode(h.default.SyntaxKind.StringKeyword),Mn={ZodString:ye(h.default.SyntaxKind.StringKeyword),ZodNumber:ye(h.default.SyntaxKind.NumberKeyword),ZodBigInt:ye(h.default.SyntaxKind.BigIntKeyword),ZodBoolean:ye(h.default.SyntaxKind.BooleanKeyword),ZodDateIn:ye(h.default.SyntaxKind.StringKeyword),ZodDateOut:ye(h.default.SyntaxKind.StringKeyword),ZodNull:Dn,ZodArray:gn,ZodTuple:An,ZodRecord:Rn,ZodObject:yn,ZodLiteral:fn,ZodIntersection:Pn,ZodUnion:Qr,ZodFile:vn,ZodAny:ye(h.default.SyntaxKind.AnyKeyword),ZodDefault:In,ZodEnum:hn,ZodNativeEnum:bn,ZodEffects:Tn,ZodOptional:Sn,ZodNullable:On,ZodDiscriminatedUnion:Qr,ZodBranded:Cn,ZodCatch:En,ZodPipeline:wn,ZodLazy:Nn,ZodReadonly:Zn},Le=({schema:e,...t})=>le({schema:e,rules:Mn,onMissing:()=>u.createKeywordTypeNode(h.default.SyntaxKind.AnyKeyword),...t});var dt=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]=Ce(r,t),this.getAlias(t)}constructor({routing:t,variant:r="client",serializer:o=Be,splitResponse:s=!1,optionalPropStyle:i={withQuestionMark:!0,withUndefined:!0}}){me({routing:t,onEndpoint:(S,E,M)=>{let oe={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:i},Kt=S.getSchema("input"),Bt=j(M,E,"input"),to=Le({...oe,schema:Te(Kt)?z.create().buffer():Kt,isResponse:!1}),Ee=s?j(M,E,"positive.response"):void 0,qt=S.getSchema("positive"),$t=s?Le({...oe,isResponse:!0,schema:qt}):void 0,we=s?j(M,E,"negative.response"):void 0,Vt=S.getSchema("negative"),_t=s?Le({...oe,isResponse:!0,schema:Vt}):void 0,Gt=j(M,E,"response"),ro=Ee&&we?n.createUnionTypeNode([n.createTypeReferenceNode(Ee),n.createTypeReferenceNode(we)]):Le({...oe,isResponse:!0,schema:qt.or(Vt)});this.program.push(Ce(to,Bt)),$t&&Ee&&this.program.push(Ce($t,Ee)),_t&&we&&this.program.push(Ce(_t,we)),this.program.push(Ce(ro,Gt)),M!=="options"&&(this.paths.push(E),this.registry[`${M} ${E}`]={input:Bt,positive:Ee,negative:we,response:Gt,isJson:S.getMimeTypes("positive").includes($),tags:S.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(jt(this.ids.pathType,this.paths)),this.program.push(jt(this.ids.methodType,Yr)),this.program.push(it(this.ids.methodPathType,vt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(N.default.SyntaxKind.ExtendsKeyword,[zt(this.ids.methodPathType,N.default.SyntaxKind.AnyKeyword)])];this.interfaces.push({id:this.ids.inputInterface,kind:"input"}),s&&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:S,kind:E}of this.interfaces)this.program.push(Gr(S,a,Object.keys(this.registry).map(M=>{let oe=this.registry[M][E];return oe?Br(M,oe):void 0}).filter(M=>M!==void 0)));if(r==="types")return;let d=n.createVariableStatement(X,ee(this.ids.jsonEndpointsConst,n.createObjectLiteralExpression(Object.keys(this.registry).filter(S=>this.registry[S].isJson).map(S=>n.createPropertyAssignment(`"${S}"`,n.createTrue()))))),p=n.createVariableStatement(X,ee(this.ids.endpointTagsConst,n.createObjectLiteralExpression(Object.keys(this.registry).map(S=>n.createPropertyAssignment(`"${S}"`,n.createArrayLiteralExpression(this.registry[S].tags.map(E=>n.createStringLiteral(E)))))))),c=it(this.ids.providerType,n.createFunctionTypeNode(Wr({M:this.ids.methodType,P:this.ids.pathType}),st({method:n.createTypeReferenceNode("M"),path:n.createTypeReferenceNode("P"),params:n.createIndexedAccessTypeNode(n.createTypeReferenceNode(this.ids.inputInterface),Mt)}),Vr(this.ids.responseInterface,Mt))),l=it(this.ids.implementationType,n.createFunctionTypeNode(void 0,st({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(N.default.SyntaxKind.StringKeyword),params:zt(N.default.SyntaxKind.StringKeyword,N.default.SyntaxKind.AnyKeyword)}),_r())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,Ie)]),f=kt(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=kt(this.ids.paramsArgument,n.createConditionalExpression(n.createBinaryExpression(n.createCallExpression(n.createPropertyAccessExpression(this.ids.pathParameter,"indexOf"),void 0,[m]),N.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=$r(this.ids.clientClass,Kr([nt(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),Fr)]),[qr(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),Lt([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(d,p,c,l,g);let O=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($))]),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)),H=n.createVariableStatement(void 0,ee(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,Ie)]),n.createObjectLiteralExpression([O,y,x])])))),v=n.createVariableStatement(void 0,ee(this.ids.hasBodyConst,n.createLogicalNot(n.createCallExpression(n.createPropertyAccessExpression(n.createArrayLiteralExpression([n.createStringLiteral("get"),n.createStringLiteral("delete")]),"includes"),void 0,[this.ids.methodParameter])))),te=n.createVariableStatement(void 0,ee(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]),Ie)])))),[Z,G]=["json","text"].map(S=>n.createReturnStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.responseConst,S),void 0,void 0))),F=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(Dt,[n.createTemplateSpan(this.ids.methodParameter,Nt),n.createTemplateSpan(this.ids.pathParameter,Ie)]),N.default.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([Z])),re=n.createVariableStatement(X,ee(this.ids.exampleImplementationConst,Lt([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([v,te,H,F,G]),!0),n.createTypeReferenceNode(this.ids.implementationType))),Ze=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"))])])),ct=n.createVariableStatement(void 0,ee(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(re,ct,Ze)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:Ht(r,t)).join(`
|
|
19
|
-
`):void 0}print(t){let r=this.printUsage(t),o=r&&
|
|
20
|
-
${r}`);return this.program.concat(o||[]).map((s
|
|
18
|
+
`;var Pt=({app:e,logger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(Ar()),t.debug("Running","v16.3.0-beta1 (CJS)"),de({routing:o,hasCors:!!r.cors,onEndpoint:(i,s,a)=>{e[a](s,async(p,d)=>{t.info(`${p.method}: ${s}`),await i.execute({request:p,response:d,logger:t,config:r})})},onStatic:(i,s)=>{e.use(i,s)}})};var Ct=R(require("http-errors"),1),Ro=(e,t)=>(r,o,i,s)=>{if(!r)return s();e.handler({error:(0,Ct.default)(400,ye(r).message),request:o,response:i,logger:t,input:null,output:null})},Ao=(e,t)=>(r,o)=>{let i=(0,Ct.default)(404,`Can not ${r.method} ${r.path}`);try{e.handler({request:r,response:o,logger:t,error:i,input:null,output:null})}catch(s){Ye({response:o,logger:t,error:new re(ye(s).message,i)})}},Cr=async e=>{let t=Sr(e.logger)?nt({...e.logger,winston:await pe("winston")}):e.logger,r=e.errorHandler||he,o=Ao(r,t);return{logger:t,errorHandler:r,notFoundHandler:o}},Er=async(e,t)=>{let{logger:r,notFoundHandler:o}=await Cr(e);return Pt({app:e.app,routing:t,logger:r,config:e}),{notFoundHandler:o,logger:r}},wr=async(e,t)=>{let r=(0,It.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||It.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{logger:o,errorHandler:i,notFoundHandler:s}=await Cr(e);r.use(Ro(i,o)),Pt({app:r,routing:t,logger:o,config:e}),r.use(s);let a=(d,c)=>d.listen(c,()=>{o.info("Listening",c)}),p={httpServer:a(Pr.default.createServer(r),e.server.listen),httpsServer:e.https?a(Ir.default.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...p,logger:o}};var _r=R(require("assert/strict"),1),Gr=require("openapi3-ts/oas31");var le=R(require("assert/strict"),1),me=require("openapi3-ts/oas31"),Se=require("ramda"),O=require("zod");var Et=require("zod");var je="DateIn",Zr=()=>j(je,Et.z.string().regex(Be).transform(e=>new Date(e)).pipe(Et.z.date().refine(Fe)));var zr=require("zod");var De="DateOut",Mr=()=>j(De,zr.z.date().refine(Fe).transform(e=>e.toISOString()));var ce=({schema:e,onEach:t,rules:r,onMissing:o,...i})=>{let s=Ce(e,"proprietaryKind")||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 vr=50,jr="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:[]},Dr=/:([A-Za-z0-9_]+)/g,kr=e=>{let t=e.match(Dr);return t?t.map(r=>r.slice(1)):[]},Lr=e=>e.replace(Dr,t=>`{${t.slice(1)}}`),Io=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),Co=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),Eo=()=>({format:"any"}),wo=e=>((0,le.default)(!e.isResponse,new C({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},Nr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),ko=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Lo=({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},Ko=()=>({type:"null"}),Ho=e=>((0,le.default)(!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:Be.source,externalDocs:{url:jr}}),Uo=e=>((0,le.default)(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:jr}}),Fo=e=>le.default.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})),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}),Hr=(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,{})},ke=(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=>ke(o,t)).reduce((o,i)=>o.merge(i.partial()),O.z.object({})):e instanceof O.z.ZodEffects?((0,le.default)(!W(e),new C({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=ke(e._def.schema,t)):r=ke(e._def.left,t).merge(ke(e._def.right,t)),Ue(e,r)},Ur=({path:e,method:t,schema:r,inputSources:o,serializer:i,getRef:s,makeRef:a,composition:p,description:d=`${t.toUpperCase()} ${e} Parameter`})=>{let c=ke(r,{path:e,method:t,isResponse:!1}).shape,l=kr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),S=y=>T&&xt(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=ce({schema:c[y],isResponse:!1,rules:Zt,onEach:zt,onMissing:Mt,serializer:i,getRef:s,makeRef:a,path:e,method:t}),L=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:L,examples:on(r,!1,y)}})},Zt={ZodString:Wo,ZodNumber:Yo,ZodBigInt:qo,ZodBoolean:Bo,ZodNull:Ko,ZodArray:_o,ZodTuple:Go,ZodRecord:$o,ZodObject:Lo,ZodLiteral:ko,ZodIntersection:vo,ZodUnion:zo,ZodAny:Eo,ZodDefault:Io,ZodEnum:Nr,ZodNativeEnum:Nr,ZodEffects:Qo,ZodOptional:No,ZodNullable:Do,ZodDiscriminatedUnion:Mo,ZodBranded:en,ZodDate:Fo,ZodCatch:Co,ZodPipeline:Xo,ZodLazy:tn,ZodReadonly:jo,[ze]:Zo,[Me]:wo,[De]:Uo,[je]:Ho,[ne]:rn},zt=({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},Mt=({schema:e,...t})=>le.default.fail(new C({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),wt=(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=>wt(p,t)):void 0,a=e.oneOf?e.oneOf.map(p=>wt(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})},Fr=e=>(0,me.isReferenceObject)(e)?e:(0,Se.omit)(["examples"],e),Br=({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} ${bt(i)} response ${c?l:""}`.trim()})=>{let f=Fr(ce({schema:r,isResponse:!0,rules:Zt,onEach:zt,onMissing:Mt,serializer:s,getRef:a,makeRef:p,path:t,method:e})),T=Hr(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}}},{})}),qr=(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(St(e))}return st({or:[e]})},Vr=({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=kr(t),l=Fr(wt(ce({schema:r,isResponse:!1,rules:Zt,onEach:zt,onMissing:Mt,serializer:i,getRef:s,makeRef:a,path:t,method:e}),c)),m=Hr(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}}),{})}},$r=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}),vt=e=>e.length<=vr?e:e.slice(0,vr-1)+"\u2026";var at=class extends Gr.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,_r.default)(!(o in this.lastOperationIdSuffixes),new C({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)),L=r.inputSources?.[g]||_e[g],w=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Q=Ur({...S,inputSources:L,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:w})}),P={operationId:w,responses:{}};for(let K of["positive","negative"]){let X=m.getResponses(K);for(let{mimeTypes:Ae,schema:ut,statusCodes:b}of X)for(let I of b)P.responses[I]=Br({...S,variant:K,schema:ut,mimeTypes:Ae,statusCode:I,hasMultipleStatusCodes:X.length>1||b.length>1,description:a?.[`${K}Response`]?.call(null,{method:g,path:f,operationId:w,statusCode:I})})}x&&(P.description=x,p&&y===void 0&&(P.summary=vt(x))),y&&(P.summary=vt(y)),m.getTags().length>0&&(P.tags=m.getTags()),Q.length>0&&(P.parameters=Q),L.includes("body")&&(P.requestBody=Vr({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:w})}));let $=st(Qe(qr(m.getSecurity(),L),K=>{let X=this.ensureUniqSecuritySchemaName(K),Ae=["oauth2","openIdConnect"].includes(K.type)?m.getScopes():[];return this.addSecurityScheme(X,K),{name:X,scopes:Ae}}));$.length>0&&(P.security=$),this.addPath(Lr(f),{[g]:P})}}),this.rootDoc.tags=r.tags?$r(r.tags):[]}};var Nt=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:Nt.default.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=Nt.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}),Wr=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 k=R(require("typescript"),1),n=k.default.factory,Y=[n.createModifier(k.default.SyntaxKind.ExportKeyword)],yn=[n.createModifier(k.default.SyntaxKind.AsyncKeyword)],gn=[n.createModifier(k.default.SyntaxKind.PublicKeyword),n.createModifier(k.default.SyntaxKind.ReadonlyKeyword)],Yr=[n.createModifier(k.default.SyntaxKind.ProtectedKeyword),n.createModifier(k.default.SyntaxKind.ReadonlyKeyword)],jt=n.createTemplateHead(""),Oe=n.createTemplateTail(""),Dt=n.createTemplateMiddle(" "),kt=e=>n.createTemplateLiteralType(jt,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?Oe:Dt))),Lt=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)),[]),Kt=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Jr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),Qr=(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)],k.default.NodeFlags.Const),Ht=(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),Xr=(e,t,r)=>n.createPropertyDeclaration(gn,e,void 0,t,r),eo=(e,t,r=[])=>n.createClassDeclaration(Y,e,void 0,void 0,[t,...r]),to=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),ro=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(k.default.SyntaxKind.AnyKeyword)]),oo=(e,t,r)=>n.createInterfaceDeclaration(Y,e,void 0,t,r),no=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),Ut=(e,t,r)=>n.createArrowFunction(r?yn:void 0,void 0,e.map(o=>pt(o)),void 0,void 0,t),Ft=(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 io=["get","post","put","delete","patch"];var h=R(require("typescript"),1),Vt=require("zod");var V=R(require("typescript"),1),{factory:mt}=V.default,Bt=(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&&Bt(o,r),o},qt=(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_$]*$/,so=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 Vt.z.ZodOptional:a.isOptional(),d=u.createPropertySignature(void 0,so(s),p&&o?u.createToken(h.default.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&Bt(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)))),ao=({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)))),In=({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},Cn=({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()),kn=({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})))},Ln=({schema:e})=>e instanceof Vt.z.ZodString?u.createKeywordTypeNode(h.default.SyntaxKind.StringKeyword):u.createTypeReferenceNode("Buffer"),Kn=({next:e,schema:t})=>e({schema:t.shape.raw}),Hn={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:ao,ZodDefault:zn,ZodEnum:On,ZodNativeEnum:Pn,ZodEffects:An,ZodOptional:In,ZodNullable:Cn,ZodDiscriminatedUnion:ao,ZodBranded:Mn,ZodCatch:Nn,ZodPipeline:jn,ZodLazy:kn,ZodReadonly:vn,[ze]:Ln,[ne]:Kn},Le=({schema:e,...t})=>ce({schema:e,rules:Hn,onMissing:()=>u.createKeywordTypeNode(h.default.SyntaxKind.AnyKeyword),...t});var lt=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,I,Z)=>{let ee={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:s},$t=M(Z,I,"input"),co=Le({...ee,schema:b.getSchema("input"),isResponse:!1}),Pe=i?M(Z,I,"positive.response"):void 0,_t=b.getSchema("positive"),Gt=i?Le({...ee,isResponse:!0,schema:_t}):void 0,Ie=i?M(Z,I,"negative.response"):void 0,Wt=b.getSchema("negative"),Yt=i?Le({...ee,isResponse:!0,schema:Wt}):void 0,Jt=M(Z,I,"response"),mo=Pe&&Ie?n.createUnionTypeNode([n.createTypeReferenceNode(Pe),n.createTypeReferenceNode(Ie)]):Le({...ee,isResponse:!0,schema:_t.or(Wt)});this.program.push(Re(co,$t)),Gt&&Pe&&this.program.push(Re(Gt,Pe)),Yt&&Ie&&this.program.push(Re(Yt,Ie)),this.program.push(Re(mo,Jt)),Z!=="options"&&(this.paths.push(I),this.registry[`${Z} ${I}`]={input:$t,positive:Pe,negative:Ie,response:Jt,isJson:b.getMimeTypes("positive").includes(B),tags:b.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(Ht(this.ids.pathType,this.paths)),this.program.push(Ht(this.ids.methodType,io)),this.program.push(ct(this.ids.methodPathType,kt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(E.default.SyntaxKind.ExtendsKeyword,[Kt(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:I}of this.interfaces)this.program.push(oo(b,a,Object.keys(this.registry).map(Z=>{let ee=this.registry[Z][I];return ee?Qr(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(I=>n.createStringLiteral(I)))))))),c=ct(this.ids.providerType,n.createFunctionTypeNode(no({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),Lt)}),to(this.ids.responseInterface,Lt))),l=ct(this.ids.implementationType,n.createFunctionTypeNode(void 0,dt({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(E.default.SyntaxKind.StringKeyword),params:Kt(E.default.SyntaxKind.StringKeyword,E.default.SyntaxKind.AnyKeyword)}),ro())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,Oe)]),f=Ft(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=Ft(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=eo(this.ids.clientClass,Jr([pt(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),Yr)]),[Xr(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),Ut([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)),L=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))),K=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(jt,[n.createTemplateSpan(this.ids.methodParameter,Dt),n.createTemplateSpan(this.ids.pathParameter,Oe)]),E.default.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([P])),X=n.createVariableStatement(Y,J(this.ids.exampleImplementationConst,Ut([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([w,Q,L,K,$]),!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"))])])),ut=n.createVariableStatement(void 0,J(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(X,ut,Ae)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:qt(r,t)).join(`
|
|
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
|
+
${r}`);return this.program.concat(o||[]).map((i,s)=>qt(i,s<this.program.length?t:{...t,omitTrailingSemicolon:!0})).join(`
|
|
21
21
|
|
|
22
|
-
`)}async printFormatted({printerOptions:t,format:r}={}){let o=r;if(!o)try{let a=(await
|
|
22
|
+
`)}async printFormatted({printerOptions:t,format:r}={}){let o=r;if(!o)try{let a=(await pe("prettier")).format;o=p=>a(p,{filepath:"client.ts"})}catch{}let i=this.printUsage(t);this.usage=i&&o?[await o(i)]:this.usage;let s=this.print(t);return o?o(s):s}};var po={dateIn:Zr,dateOut:Mr,file:$e,upload:pr,raw:ar};0&&(module.exports={AbstractEndpoint,DependsOnMethod,Documentation,DocumentationError,EndpointsFactory,InputValidationError,Integration,MissingPeerError,OutputValidationError,RoutingError,ServeStatic,arrayEndpointsFactory,arrayResultHandler,attachRouting,createConfig,createLogger,createMiddleware,createResultHandler,createServer,defaultEndpointsFactory,defaultResultHandler,ez,getExamples,getMessageFromError,getStatusCodeFromError,testEndpoint,withMeta});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import compression from 'compression';
|
|
2
2
|
import express, { Request, Response, NextFunction, RequestHandler, IRouter } from 'express';
|
|
3
|
-
import
|
|
3
|
+
import * as express_fileupload from 'express-fileupload';
|
|
4
|
+
import express_fileupload__default from 'express-fileupload';
|
|
4
5
|
import https, { ServerOptions } from 'node:https';
|
|
5
|
-
import
|
|
6
|
+
import * as zod from 'zod';
|
|
7
|
+
import { z, ZodError } from 'zod';
|
|
6
8
|
import Winston from 'winston';
|
|
7
9
|
import { HttpError } from 'http-errors';
|
|
8
10
|
import { ListenOptions } from 'node:net';
|
|
@@ -192,7 +194,171 @@ declare const getExamples: <T extends z.ZodTypeAny, V extends "original" | "pars
|
|
|
192
194
|
validate?: boolean | undefined;
|
|
193
195
|
}) => readonly (V extends "parsed" ? z.output<T> : z.input<T>)[];
|
|
194
196
|
|
|
197
|
+
declare const ezDateInKind = "DateIn";
|
|
198
|
+
|
|
199
|
+
declare const ezDateOutKind = "DateOut";
|
|
200
|
+
|
|
201
|
+
declare const ezFileKind = "File";
|
|
202
|
+
declare const variants: {
|
|
203
|
+
/** @deprecated use ez.file("buffer") instead */
|
|
204
|
+
buffer: () => z.ZodType<Buffer, z.ZodTypeDef, Buffer> & {
|
|
205
|
+
_def: z.ZodTypeDef & Record<"expressZodApiMeta", Metadata<z.ZodType<Buffer, z.ZodTypeDef, Buffer>>>;
|
|
206
|
+
example: (example: Buffer) => z.ZodType<Buffer, z.ZodTypeDef, Buffer> & any;
|
|
207
|
+
} & any;
|
|
208
|
+
/** @deprecated use ez.file("string") instead */
|
|
209
|
+
string: () => z.ZodString & {
|
|
210
|
+
_def: z.ZodStringDef & Record<"expressZodApiMeta", Metadata<z.ZodString>>;
|
|
211
|
+
example: (example: string) => z.ZodString & any;
|
|
212
|
+
} & any;
|
|
213
|
+
/** @deprecated use ez.file("binary") instead */
|
|
214
|
+
binary: () => z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]> & {
|
|
215
|
+
_def: z.ZodUnionDef<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]> & Record<"expressZodApiMeta", Metadata<z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]>>>;
|
|
216
|
+
example: (example: string | Buffer) => z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]> & any;
|
|
217
|
+
} & any;
|
|
218
|
+
/** @deprecated use ez.file("base64") instead */
|
|
219
|
+
base64: () => z.ZodString & {
|
|
220
|
+
_def: z.ZodStringDef & Record<"expressZodApiMeta", Metadata<z.ZodString>>;
|
|
221
|
+
example: (example: string) => z.ZodString & any;
|
|
222
|
+
} & any;
|
|
223
|
+
};
|
|
224
|
+
type Variants = typeof variants;
|
|
225
|
+
type Variant = keyof Variants;
|
|
226
|
+
declare function file(): ReturnType<Variants["string"]>;
|
|
227
|
+
declare function file<K extends Variant>(variant: K): ReturnType<Variants[K]>;
|
|
228
|
+
|
|
229
|
+
declare const ezRawKind = "Raw";
|
|
230
|
+
|
|
231
|
+
declare const ezUploadKind = "Upload";
|
|
232
|
+
|
|
233
|
+
declare const ez: {
|
|
234
|
+
dateIn: () => zod.ZodPipeline<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>> & {
|
|
235
|
+
_def: zod.ZodPipelineDef<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>> & Record<"expressZodApiMeta", Metadata<zod.ZodPipeline<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>>>>;
|
|
236
|
+
example: (example: string) => zod.ZodPipeline<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>> & any;
|
|
237
|
+
};
|
|
238
|
+
dateOut: () => zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date> & {
|
|
239
|
+
_def: zod.ZodEffectsDef<zod.ZodEffects<zod.ZodDate, Date, Date>> & Record<"expressZodApiMeta", Metadata<zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date>>>;
|
|
240
|
+
example: (example: Date) => zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date> & any;
|
|
241
|
+
};
|
|
242
|
+
file: typeof file;
|
|
243
|
+
upload: () => zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile> & {
|
|
244
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile>>>;
|
|
245
|
+
example: (example: express_fileupload.UploadedFile) => zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile> & any;
|
|
246
|
+
};
|
|
247
|
+
raw: () => zod.ZodObject<{
|
|
248
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
249
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
250
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
251
|
+
} & {
|
|
252
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
253
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
254
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
255
|
+
} & any;
|
|
256
|
+
string: () => zod.ZodString & {
|
|
257
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
258
|
+
example: (example: string) => zod.ZodString & any;
|
|
259
|
+
} & any;
|
|
260
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
261
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
262
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
263
|
+
} & any;
|
|
264
|
+
base64: () => zod.ZodString & {
|
|
265
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
266
|
+
example: (example: string) => zod.ZodString & any;
|
|
267
|
+
} & any;
|
|
268
|
+
};
|
|
269
|
+
}, "strip", zod.ZodTypeAny, {
|
|
270
|
+
raw: Buffer;
|
|
271
|
+
}, {
|
|
272
|
+
raw: Buffer;
|
|
273
|
+
}> & {
|
|
274
|
+
_def: zod.ZodObjectDef<{
|
|
275
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
276
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
277
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
278
|
+
} & {
|
|
279
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
280
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
281
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
282
|
+
} & any;
|
|
283
|
+
string: () => zod.ZodString & {
|
|
284
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
285
|
+
example: (example: string) => zod.ZodString & any;
|
|
286
|
+
} & any;
|
|
287
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
288
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
289
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
290
|
+
} & any;
|
|
291
|
+
base64: () => zod.ZodString & {
|
|
292
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
293
|
+
example: (example: string) => zod.ZodString & any;
|
|
294
|
+
} & any;
|
|
295
|
+
};
|
|
296
|
+
}, "strip", zod.ZodTypeAny> & Record<"expressZodApiMeta", Metadata<zod.ZodObject<{
|
|
297
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
298
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
299
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
300
|
+
} & {
|
|
301
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
302
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
303
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
304
|
+
} & any;
|
|
305
|
+
string: () => zod.ZodString & {
|
|
306
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
307
|
+
example: (example: string) => zod.ZodString & any;
|
|
308
|
+
} & any;
|
|
309
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
310
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
311
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
312
|
+
} & any;
|
|
313
|
+
base64: () => zod.ZodString & {
|
|
314
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
315
|
+
example: (example: string) => zod.ZodString & any;
|
|
316
|
+
} & any;
|
|
317
|
+
};
|
|
318
|
+
}, "strip", zod.ZodTypeAny, {
|
|
319
|
+
raw: Buffer;
|
|
320
|
+
}, {
|
|
321
|
+
raw: Buffer;
|
|
322
|
+
}>>>;
|
|
323
|
+
example: (example: {
|
|
324
|
+
raw: Buffer;
|
|
325
|
+
}) => zod.ZodObject<{
|
|
326
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
327
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
328
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
329
|
+
} & {
|
|
330
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
331
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
332
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
333
|
+
} & any;
|
|
334
|
+
string: () => zod.ZodString & {
|
|
335
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
336
|
+
example: (example: string) => zod.ZodString & any;
|
|
337
|
+
} & any;
|
|
338
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
339
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
340
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
341
|
+
} & any;
|
|
342
|
+
base64: () => zod.ZodString & {
|
|
343
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
344
|
+
example: (example: string) => zod.ZodString & any;
|
|
345
|
+
} & any;
|
|
346
|
+
};
|
|
347
|
+
}, "strip", zod.ZodTypeAny, {
|
|
348
|
+
raw: Buffer;
|
|
349
|
+
}, {
|
|
350
|
+
raw: Buffer;
|
|
351
|
+
}> & any;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
type ProprietaryKind = typeof ezFileKind | typeof ezDateInKind | typeof ezDateOutKind | typeof ezUploadKind | typeof ezRawKind;
|
|
355
|
+
|
|
195
356
|
interface Metadata<T extends z.ZodTypeAny> {
|
|
357
|
+
/**
|
|
358
|
+
* @todo if the following PR merged, use native branding instead:
|
|
359
|
+
* @link https://github.com/colinhacks/zod/pull/2860
|
|
360
|
+
* */
|
|
361
|
+
proprietaryKind?: ProprietaryKind;
|
|
196
362
|
examples: z.input<T>[];
|
|
197
363
|
}
|
|
198
364
|
declare const metaProp = "expressZodApiMeta";
|
|
@@ -463,7 +629,7 @@ interface CommonConfig<TAG extends string = string> {
|
|
|
463
629
|
*/
|
|
464
630
|
tags?: TagsConfig<TAG>;
|
|
465
631
|
}
|
|
466
|
-
type UploadOptions = Pick<
|
|
632
|
+
type UploadOptions = Pick<express_fileupload__default.Options, "createParentPath" | "uriDecodeFileNames" | "safeFileNames" | "preserveExtension" | "useTempFiles" | "tempFileDir" | "debug" | "uploadTimeout">;
|
|
467
633
|
type CompressionOptions = Pick<compression.CompressionOptions, "threshold" | "level" | "strategy" | "chunkSize" | "memLevel">;
|
|
468
634
|
interface ServerConfig<TAG extends string = string> extends CommonConfig<TAG> {
|
|
469
635
|
/** @desc Server configuration. */
|
|
@@ -621,55 +787,6 @@ declare class Documentation extends OpenApiBuilder {
|
|
|
621
787
|
constructor({ routing, config, title, version, serverUrl, descriptions, hasSummaryFromDescription, composition, serializer, }: DocumentationParams);
|
|
622
788
|
}
|
|
623
789
|
|
|
624
|
-
declare const zodDateInKind = "ZodDateIn";
|
|
625
|
-
interface ZodDateInDef extends ZodTypeDef {
|
|
626
|
-
typeName: typeof zodDateInKind;
|
|
627
|
-
}
|
|
628
|
-
declare class ZodDateIn extends ZodType<Date, ZodDateInDef, string> {
|
|
629
|
-
_parse(input: ParseInput): ParseReturnType<Date>;
|
|
630
|
-
static create: () => ZodDateIn;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
declare const zodDateOutKind = "ZodDateOut";
|
|
634
|
-
interface ZodDateOutDef extends ZodTypeDef {
|
|
635
|
-
typeName: typeof zodDateOutKind;
|
|
636
|
-
}
|
|
637
|
-
declare class ZodDateOut extends ZodType<string, ZodDateOutDef, Date> {
|
|
638
|
-
_parse(input: ParseInput): ParseReturnType<string>;
|
|
639
|
-
static create: () => ZodDateOut;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
type ErrMessage = Exclude<Parameters<typeof z.ZodString.prototype.email>[0], undefined>;
|
|
643
|
-
|
|
644
|
-
declare const zodFileKind = "ZodFile";
|
|
645
|
-
interface ZodFileDef<T extends string | Buffer = string | Buffer> extends ZodTypeDef {
|
|
646
|
-
typeName: typeof zodFileKind;
|
|
647
|
-
type: T;
|
|
648
|
-
encoding?: "binary" | "base64";
|
|
649
|
-
message?: string;
|
|
650
|
-
}
|
|
651
|
-
declare class ZodFile<T extends string | Buffer = string | Buffer> extends ZodType<T, ZodFileDef<T>, T> {
|
|
652
|
-
_parse(input: ParseInput): ParseReturnType<T>;
|
|
653
|
-
string: (message?: ErrMessage) => ZodFile<string>;
|
|
654
|
-
buffer: (message?: ErrMessage) => ZodFile<Buffer>;
|
|
655
|
-
binary: (message?: ErrMessage) => ZodFile<T>;
|
|
656
|
-
base64: (message?: ErrMessage) => ZodFile<T>;
|
|
657
|
-
get isBinary(): boolean;
|
|
658
|
-
get isBase64(): boolean;
|
|
659
|
-
get isString(): boolean;
|
|
660
|
-
get isBuffer(): boolean;
|
|
661
|
-
static create: () => ZodFile<string>;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
declare const zodUploadKind = "ZodUpload";
|
|
665
|
-
interface ZodUploadDef extends ZodTypeDef {
|
|
666
|
-
typeName: typeof zodUploadKind;
|
|
667
|
-
}
|
|
668
|
-
declare class ZodUpload extends ZodType<UploadedFile, ZodUploadDef> {
|
|
669
|
-
_parse(input: ParseInput): ParseReturnType<UploadedFile>;
|
|
670
|
-
static create: () => ZodUpload;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
790
|
interface OpenAPIContext extends FlatObject {
|
|
674
791
|
isResponse: boolean;
|
|
675
792
|
serializer: (schema: z.ZodTypeAny) => string;
|
|
@@ -864,26 +981,4 @@ declare class Integration {
|
|
|
864
981
|
printFormatted({ printerOptions, format: userDefined, }?: FormattedPrintingOptions): Promise<string>;
|
|
865
982
|
}
|
|
866
983
|
|
|
867
|
-
|
|
868
|
-
declare const upload: () => ZodUpload;
|
|
869
|
-
declare const dateIn: () => ZodDateIn;
|
|
870
|
-
declare const dateOut: () => ZodDateOut;
|
|
871
|
-
/** Shorthand for z.object({ raw: ez.file().buffer() }) */
|
|
872
|
-
declare const raw: () => z.ZodObject<{
|
|
873
|
-
raw: ZodFile<Buffer>;
|
|
874
|
-
}, "strip", z.ZodTypeAny, {
|
|
875
|
-
raw: Buffer;
|
|
876
|
-
}, {
|
|
877
|
-
raw: Buffer;
|
|
878
|
-
}>;
|
|
879
|
-
|
|
880
|
-
declare const proprietarySchemas_dateIn: typeof dateIn;
|
|
881
|
-
declare const proprietarySchemas_dateOut: typeof dateOut;
|
|
882
|
-
declare const proprietarySchemas_file: typeof file;
|
|
883
|
-
declare const proprietarySchemas_raw: typeof raw;
|
|
884
|
-
declare const proprietarySchemas_upload: typeof upload;
|
|
885
|
-
declare namespace proprietarySchemas {
|
|
886
|
-
export { proprietarySchemas_dateIn as dateIn, proprietarySchemas_dateOut as dateOut, proprietarySchemas_file as file, proprietarySchemas_raw as raw, proprietarySchemas_upload as upload };
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
export { AbstractEndpoint, type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, Documentation, DocumentationError, EndpointsFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Metadata, type Method, type MiddlewareDefinition, MissingPeerError, type MockOverrides, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type ResultHandlerDefinition, type Routing, RoutingError, ServeStatic, type ServerConfig, type ZodDateInDef, type ZodDateOutDef, type ZodFileDef, type ZodUploadDef, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, proprietarySchemas as ez, getExamples, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|
|
984
|
+
export { AbstractEndpoint, type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, Documentation, DocumentationError, EndpointsFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Metadata, type Method, type MiddlewareDefinition, MissingPeerError, type MockOverrides, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type ResultHandlerDefinition, type Routing, RoutingError, ServeStatic, type ServerConfig, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, ez, getExamples, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import compression from 'compression';
|
|
2
2
|
import express, { Request, Response, NextFunction, RequestHandler, IRouter } from 'express';
|
|
3
|
-
import
|
|
3
|
+
import * as express_fileupload from 'express-fileupload';
|
|
4
|
+
import express_fileupload__default from 'express-fileupload';
|
|
4
5
|
import https, { ServerOptions } from 'node:https';
|
|
5
|
-
import
|
|
6
|
+
import * as zod from 'zod';
|
|
7
|
+
import { z, ZodError } from 'zod';
|
|
6
8
|
import Winston from 'winston';
|
|
7
9
|
import { HttpError } from 'http-errors';
|
|
8
10
|
import { ListenOptions } from 'node:net';
|
|
@@ -192,7 +194,171 @@ declare const getExamples: <T extends z.ZodTypeAny, V extends "original" | "pars
|
|
|
192
194
|
validate?: boolean | undefined;
|
|
193
195
|
}) => readonly (V extends "parsed" ? z.output<T> : z.input<T>)[];
|
|
194
196
|
|
|
197
|
+
declare const ezDateInKind = "DateIn";
|
|
198
|
+
|
|
199
|
+
declare const ezDateOutKind = "DateOut";
|
|
200
|
+
|
|
201
|
+
declare const ezFileKind = "File";
|
|
202
|
+
declare const variants: {
|
|
203
|
+
/** @deprecated use ez.file("buffer") instead */
|
|
204
|
+
buffer: () => z.ZodType<Buffer, z.ZodTypeDef, Buffer> & {
|
|
205
|
+
_def: z.ZodTypeDef & Record<"expressZodApiMeta", Metadata<z.ZodType<Buffer, z.ZodTypeDef, Buffer>>>;
|
|
206
|
+
example: (example: Buffer) => z.ZodType<Buffer, z.ZodTypeDef, Buffer> & any;
|
|
207
|
+
} & any;
|
|
208
|
+
/** @deprecated use ez.file("string") instead */
|
|
209
|
+
string: () => z.ZodString & {
|
|
210
|
+
_def: z.ZodStringDef & Record<"expressZodApiMeta", Metadata<z.ZodString>>;
|
|
211
|
+
example: (example: string) => z.ZodString & any;
|
|
212
|
+
} & any;
|
|
213
|
+
/** @deprecated use ez.file("binary") instead */
|
|
214
|
+
binary: () => z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]> & {
|
|
215
|
+
_def: z.ZodUnionDef<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]> & Record<"expressZodApiMeta", Metadata<z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]>>>;
|
|
216
|
+
example: (example: string | Buffer) => z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodString]> & any;
|
|
217
|
+
} & any;
|
|
218
|
+
/** @deprecated use ez.file("base64") instead */
|
|
219
|
+
base64: () => z.ZodString & {
|
|
220
|
+
_def: z.ZodStringDef & Record<"expressZodApiMeta", Metadata<z.ZodString>>;
|
|
221
|
+
example: (example: string) => z.ZodString & any;
|
|
222
|
+
} & any;
|
|
223
|
+
};
|
|
224
|
+
type Variants = typeof variants;
|
|
225
|
+
type Variant = keyof Variants;
|
|
226
|
+
declare function file(): ReturnType<Variants["string"]>;
|
|
227
|
+
declare function file<K extends Variant>(variant: K): ReturnType<Variants[K]>;
|
|
228
|
+
|
|
229
|
+
declare const ezRawKind = "Raw";
|
|
230
|
+
|
|
231
|
+
declare const ezUploadKind = "Upload";
|
|
232
|
+
|
|
233
|
+
declare const ez: {
|
|
234
|
+
dateIn: () => zod.ZodPipeline<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>> & {
|
|
235
|
+
_def: zod.ZodPipelineDef<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>> & Record<"expressZodApiMeta", Metadata<zod.ZodPipeline<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>>>>;
|
|
236
|
+
example: (example: string) => zod.ZodPipeline<zod.ZodEffects<zod.ZodString, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>> & any;
|
|
237
|
+
};
|
|
238
|
+
dateOut: () => zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date> & {
|
|
239
|
+
_def: zod.ZodEffectsDef<zod.ZodEffects<zod.ZodDate, Date, Date>> & Record<"expressZodApiMeta", Metadata<zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date>>>;
|
|
240
|
+
example: (example: Date) => zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date> & any;
|
|
241
|
+
};
|
|
242
|
+
file: typeof file;
|
|
243
|
+
upload: () => zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile> & {
|
|
244
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile>>>;
|
|
245
|
+
example: (example: express_fileupload.UploadedFile) => zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile> & any;
|
|
246
|
+
};
|
|
247
|
+
raw: () => zod.ZodObject<{
|
|
248
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
249
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
250
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
251
|
+
} & {
|
|
252
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
253
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
254
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
255
|
+
} & any;
|
|
256
|
+
string: () => zod.ZodString & {
|
|
257
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
258
|
+
example: (example: string) => zod.ZodString & any;
|
|
259
|
+
} & any;
|
|
260
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
261
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
262
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
263
|
+
} & any;
|
|
264
|
+
base64: () => zod.ZodString & {
|
|
265
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
266
|
+
example: (example: string) => zod.ZodString & any;
|
|
267
|
+
} & any;
|
|
268
|
+
};
|
|
269
|
+
}, "strip", zod.ZodTypeAny, {
|
|
270
|
+
raw: Buffer;
|
|
271
|
+
}, {
|
|
272
|
+
raw: Buffer;
|
|
273
|
+
}> & {
|
|
274
|
+
_def: zod.ZodObjectDef<{
|
|
275
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
276
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
277
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
278
|
+
} & {
|
|
279
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
280
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
281
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
282
|
+
} & any;
|
|
283
|
+
string: () => zod.ZodString & {
|
|
284
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
285
|
+
example: (example: string) => zod.ZodString & any;
|
|
286
|
+
} & any;
|
|
287
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
288
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
289
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
290
|
+
} & any;
|
|
291
|
+
base64: () => zod.ZodString & {
|
|
292
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
293
|
+
example: (example: string) => zod.ZodString & any;
|
|
294
|
+
} & any;
|
|
295
|
+
};
|
|
296
|
+
}, "strip", zod.ZodTypeAny> & Record<"expressZodApiMeta", Metadata<zod.ZodObject<{
|
|
297
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
298
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
299
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
300
|
+
} & {
|
|
301
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
302
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
303
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
304
|
+
} & any;
|
|
305
|
+
string: () => zod.ZodString & {
|
|
306
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
307
|
+
example: (example: string) => zod.ZodString & any;
|
|
308
|
+
} & any;
|
|
309
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
310
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
311
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
312
|
+
} & any;
|
|
313
|
+
base64: () => zod.ZodString & {
|
|
314
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
315
|
+
example: (example: string) => zod.ZodString & any;
|
|
316
|
+
} & any;
|
|
317
|
+
};
|
|
318
|
+
}, "strip", zod.ZodTypeAny, {
|
|
319
|
+
raw: Buffer;
|
|
320
|
+
}, {
|
|
321
|
+
raw: Buffer;
|
|
322
|
+
}>>>;
|
|
323
|
+
example: (example: {
|
|
324
|
+
raw: Buffer;
|
|
325
|
+
}) => zod.ZodObject<{
|
|
326
|
+
raw: zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
327
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
328
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
329
|
+
} & {
|
|
330
|
+
buffer: () => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & {
|
|
331
|
+
_def: zod.ZodTypeDef & Record<"expressZodApiMeta", Metadata<zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>>>;
|
|
332
|
+
example: (example: Buffer) => zod.ZodType<Buffer, zod.ZodTypeDef, Buffer> & any;
|
|
333
|
+
} & any;
|
|
334
|
+
string: () => zod.ZodString & {
|
|
335
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
336
|
+
example: (example: string) => zod.ZodString & any;
|
|
337
|
+
} & any;
|
|
338
|
+
binary: () => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & {
|
|
339
|
+
_def: zod.ZodUnionDef<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & Record<"expressZodApiMeta", Metadata<zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]>>>;
|
|
340
|
+
example: (example: string | Buffer) => zod.ZodUnion<[zod.ZodType<Buffer, zod.ZodTypeDef, Buffer>, zod.ZodString]> & any;
|
|
341
|
+
} & any;
|
|
342
|
+
base64: () => zod.ZodString & {
|
|
343
|
+
_def: zod.ZodStringDef & Record<"expressZodApiMeta", Metadata<zod.ZodString>>;
|
|
344
|
+
example: (example: string) => zod.ZodString & any;
|
|
345
|
+
} & any;
|
|
346
|
+
};
|
|
347
|
+
}, "strip", zod.ZodTypeAny, {
|
|
348
|
+
raw: Buffer;
|
|
349
|
+
}, {
|
|
350
|
+
raw: Buffer;
|
|
351
|
+
}> & any;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
type ProprietaryKind = typeof ezFileKind | typeof ezDateInKind | typeof ezDateOutKind | typeof ezUploadKind | typeof ezRawKind;
|
|
355
|
+
|
|
195
356
|
interface Metadata<T extends z.ZodTypeAny> {
|
|
357
|
+
/**
|
|
358
|
+
* @todo if the following PR merged, use native branding instead:
|
|
359
|
+
* @link https://github.com/colinhacks/zod/pull/2860
|
|
360
|
+
* */
|
|
361
|
+
proprietaryKind?: ProprietaryKind;
|
|
196
362
|
examples: z.input<T>[];
|
|
197
363
|
}
|
|
198
364
|
declare const metaProp = "expressZodApiMeta";
|
|
@@ -463,7 +629,7 @@ interface CommonConfig<TAG extends string = string> {
|
|
|
463
629
|
*/
|
|
464
630
|
tags?: TagsConfig<TAG>;
|
|
465
631
|
}
|
|
466
|
-
type UploadOptions = Pick<
|
|
632
|
+
type UploadOptions = Pick<express_fileupload__default.Options, "createParentPath" | "uriDecodeFileNames" | "safeFileNames" | "preserveExtension" | "useTempFiles" | "tempFileDir" | "debug" | "uploadTimeout">;
|
|
467
633
|
type CompressionOptions = Pick<compression.CompressionOptions, "threshold" | "level" | "strategy" | "chunkSize" | "memLevel">;
|
|
468
634
|
interface ServerConfig<TAG extends string = string> extends CommonConfig<TAG> {
|
|
469
635
|
/** @desc Server configuration. */
|
|
@@ -621,55 +787,6 @@ declare class Documentation extends OpenApiBuilder {
|
|
|
621
787
|
constructor({ routing, config, title, version, serverUrl, descriptions, hasSummaryFromDescription, composition, serializer, }: DocumentationParams);
|
|
622
788
|
}
|
|
623
789
|
|
|
624
|
-
declare const zodDateInKind = "ZodDateIn";
|
|
625
|
-
interface ZodDateInDef extends ZodTypeDef {
|
|
626
|
-
typeName: typeof zodDateInKind;
|
|
627
|
-
}
|
|
628
|
-
declare class ZodDateIn extends ZodType<Date, ZodDateInDef, string> {
|
|
629
|
-
_parse(input: ParseInput): ParseReturnType<Date>;
|
|
630
|
-
static create: () => ZodDateIn;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
declare const zodDateOutKind = "ZodDateOut";
|
|
634
|
-
interface ZodDateOutDef extends ZodTypeDef {
|
|
635
|
-
typeName: typeof zodDateOutKind;
|
|
636
|
-
}
|
|
637
|
-
declare class ZodDateOut extends ZodType<string, ZodDateOutDef, Date> {
|
|
638
|
-
_parse(input: ParseInput): ParseReturnType<string>;
|
|
639
|
-
static create: () => ZodDateOut;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
type ErrMessage = Exclude<Parameters<typeof z.ZodString.prototype.email>[0], undefined>;
|
|
643
|
-
|
|
644
|
-
declare const zodFileKind = "ZodFile";
|
|
645
|
-
interface ZodFileDef<T extends string | Buffer = string | Buffer> extends ZodTypeDef {
|
|
646
|
-
typeName: typeof zodFileKind;
|
|
647
|
-
type: T;
|
|
648
|
-
encoding?: "binary" | "base64";
|
|
649
|
-
message?: string;
|
|
650
|
-
}
|
|
651
|
-
declare class ZodFile<T extends string | Buffer = string | Buffer> extends ZodType<T, ZodFileDef<T>, T> {
|
|
652
|
-
_parse(input: ParseInput): ParseReturnType<T>;
|
|
653
|
-
string: (message?: ErrMessage) => ZodFile<string>;
|
|
654
|
-
buffer: (message?: ErrMessage) => ZodFile<Buffer>;
|
|
655
|
-
binary: (message?: ErrMessage) => ZodFile<T>;
|
|
656
|
-
base64: (message?: ErrMessage) => ZodFile<T>;
|
|
657
|
-
get isBinary(): boolean;
|
|
658
|
-
get isBase64(): boolean;
|
|
659
|
-
get isString(): boolean;
|
|
660
|
-
get isBuffer(): boolean;
|
|
661
|
-
static create: () => ZodFile<string>;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
declare const zodUploadKind = "ZodUpload";
|
|
665
|
-
interface ZodUploadDef extends ZodTypeDef {
|
|
666
|
-
typeName: typeof zodUploadKind;
|
|
667
|
-
}
|
|
668
|
-
declare class ZodUpload extends ZodType<UploadedFile, ZodUploadDef> {
|
|
669
|
-
_parse(input: ParseInput): ParseReturnType<UploadedFile>;
|
|
670
|
-
static create: () => ZodUpload;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
790
|
interface OpenAPIContext extends FlatObject {
|
|
674
791
|
isResponse: boolean;
|
|
675
792
|
serializer: (schema: z.ZodTypeAny) => string;
|
|
@@ -864,26 +981,4 @@ declare class Integration {
|
|
|
864
981
|
printFormatted({ printerOptions, format: userDefined, }?: FormattedPrintingOptions): Promise<string>;
|
|
865
982
|
}
|
|
866
983
|
|
|
867
|
-
|
|
868
|
-
declare const upload: () => ZodUpload;
|
|
869
|
-
declare const dateIn: () => ZodDateIn;
|
|
870
|
-
declare const dateOut: () => ZodDateOut;
|
|
871
|
-
/** Shorthand for z.object({ raw: ez.file().buffer() }) */
|
|
872
|
-
declare const raw: () => z.ZodObject<{
|
|
873
|
-
raw: ZodFile<Buffer>;
|
|
874
|
-
}, "strip", z.ZodTypeAny, {
|
|
875
|
-
raw: Buffer;
|
|
876
|
-
}, {
|
|
877
|
-
raw: Buffer;
|
|
878
|
-
}>;
|
|
879
|
-
|
|
880
|
-
declare const proprietarySchemas_dateIn: typeof dateIn;
|
|
881
|
-
declare const proprietarySchemas_dateOut: typeof dateOut;
|
|
882
|
-
declare const proprietarySchemas_file: typeof file;
|
|
883
|
-
declare const proprietarySchemas_raw: typeof raw;
|
|
884
|
-
declare const proprietarySchemas_upload: typeof upload;
|
|
885
|
-
declare namespace proprietarySchemas {
|
|
886
|
-
export { proprietarySchemas_dateIn as dateIn, proprietarySchemas_dateOut as dateOut, proprietarySchemas_file as file, proprietarySchemas_raw as raw, proprietarySchemas_upload as upload };
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
export { AbstractEndpoint, type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, Documentation, DocumentationError, EndpointsFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Metadata, type Method, type MiddlewareDefinition, MissingPeerError, type MockOverrides, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type ResultHandlerDefinition, type Routing, RoutingError, ServeStatic, type ServerConfig, type ZodDateInDef, type ZodDateOutDef, type ZodFileDef, type ZodUploadDef, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, proprietarySchemas as ez, getExamples, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|
|
984
|
+
export { AbstractEndpoint, type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, Documentation, DocumentationError, EndpointsFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Metadata, type Method, type MiddlewareDefinition, MissingPeerError, type MockOverrides, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type ResultHandlerDefinition, type Routing, RoutingError, ServeStatic, type ServerConfig, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, ez, getExamples, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
Caused by ${
|
|
1
|
+
var Ht=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});function Ur(e){return e}import Qt from"assert/strict";import{z as mt}from"zod";import{z as Fr}from"zod";var pe={positive:200,negative:400},ot=(e,t)=>e instanceof Fr.ZodType?[{...t,schema:e}]:(Array.isArray(e)?e:[e]).map(({schema:r,statusCodes:o,statusCode:i,mimeTypes:s,mimeType:a})=>({schema:r,statusCodes:i?[i]:o||t.statusCodes,mimeTypes:a?[a]:s||t.mimeTypes}));import{isHttpError as Gr}from"http-errors";import{createHash as Wr}from"crypto";import{xprod as Yr}from"ramda";import{z as P}from"zod";var de=class extends Error{name="RoutingError"},I=class extends Error{name="DocumentationError";constructor({message:t,method:r,path:o,isResponse:i}){let s=`${t}
|
|
2
|
+
Caused by ${i?"response":"input"} schema of an Endpoint assigned to ${r.toUpperCase()} method of ${o} path.`;super(s)}},F=class extends Error{name="IOSchemaError"},X=class extends F{name="OutputValidationError";originalError;constructor(t){super(q(t)),this.originalError=t}},B=class extends F{name="InputValidationError";originalError;constructor(t){super(q(t)),this.originalError=t}},ee=class extends Error{name="ResultHandlerError";originalError;constructor(t,r){super(t),this.originalError=r||void 0}},ce=class extends Error{name="MissingPeerError";constructor(t){let r=Array.isArray(t);super(`Missing ${r?"one of the following peer dependencies":"peer dependency"}: ${r?t.join(" | "):t}. Please install it to use the feature.`)}};import{z as Ut}from"zod";import{clone as Br,mergeDeepRight as qr}from"ramda";var k="expressZodApiMeta",Vr=e=>e.describe(e.description),L=e=>{let t=Vr(e);return t._def[k]=Br(t._def[k])||{examples:[]},Object.defineProperties(t,{example:{get:()=>r=>{let o=L(t);return o._def[k].examples.push(r),o}}})},Ft=e=>Ut.object({[k]:Ut.object({})}).safeParse(e._def).success,Se=(e,t)=>Ft(e)?e._def[k][t]:void 0,ke=(e,t)=>{if(!Ft(e))return t;let r=L(t);return r._def[k].examples=Oe(r._def[k].examples,e._def[k].examples,([o,i])=>typeof o=="object"&&typeof i=="object"?qr({...o},{...i}):i),r},z=(e,t)=>{let r=L(t);return r._def[k].proprietaryKind=e,r},nt=(e,t)=>Se(e,"proprietaryKind")===t;var K="application/json",Re="multipart/form-data",Bt="application/octet-stream";import{z as _r}from"zod";import{z as it}from"zod";import{z as $r}from"zod";var Le=e=>!isNaN(e.getTime()),Ae=$r.custom(e=>Buffer.isBuffer(e),{message:"Expected Buffer"}),qt=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Ke=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?)?Z?$/;var Pe="File",He=e=>Object.entries(Vt).reduce((t,[r,o])=>Object.defineProperty(t,r,{get:()=>o}),z(Pe,e)),Vt={buffer:()=>He(Ae),string:()=>He(it.string()),binary:()=>He(Ae.or(it.string())),base64:()=>He(it.string().regex(qt,"Does not match base64 encoding"))};function Ue(e){return Vt[e||"string"]()}var te="Raw",$t=()=>z(te,_r.object({raw:Ue("buffer")}));import{z as M}from"zod";var Ie="Upload",_t=()=>z(Ie,M.custom(e=>M.object({name:M.string(),encoding:M.string(),mimetype:M.string(),data:Ae,tempFilePath:M.string(),truncated:M.boolean(),size:M.number(),md5:M.string(),mv:M.function()}).safeParse(e).success,e=>({message:`Expected file upload, received ${typeof e}`})));var Jr=e=>{let r=(e.header("content-type")||"").slice(0,Re.length).toLowerCase()===Re;return"files"in e&&r},Fe={get:["query","params"],post:["body","params","files"],put:["body","params"],patch:["body","params"],delete:["query","params"]},Qr=["body","query","params"],st=e=>e.method.toLowerCase(),at=e=>e.startsWith("x-"),Xr=e=>Object.entries(e.headers).reduce((t,[r,o])=>at(r)?{...t,[r]:o}:t,{}),Gt=(e,t)=>{let r=st(e);if(r==="options")return{};let o=Qr;return r in Fe&&(o=Fe[r]),t&&r in t&&(o=t[r]||o),o.filter(i=>i==="files"?Jr(e):!0).reduce((i,s)=>({...i,...s==="headers"?Xr(e):e[s]}),{})},me=e=>e instanceof Error?e:new Error(typeof e=="symbol"?e.toString():`${e}`),q=e=>e instanceof P.ZodError?e.issues.map(({path:t,message:r})=>(t.length?[t.join("/")]:[]).concat(r).join(": ")).join("; "):e instanceof X?`output${e.originalError.issues[0]?.path.length>0?"/":": "}${e.message}`:e.message,Be=e=>Gr(e)?e.statusCode:e instanceof B?400:500,pt=({logger:e,request:t,input:r,error:o,statusCode:i})=>{i===500&&e.error(`Internal server error
|
|
3
3
|
${o.stack}
|
|
4
|
-
`,{url:t.url,payload:r})}
|
|
5
|
-
Original error: ${e.originalError.message}.`:""))};var
|
|
4
|
+
`,{url:t.url,payload:r})},$=({schema:e,variant:t="original",validate:r=t==="parsed"})=>{let o=Se(e,"examples")||[];if(!r&&t==="original")return o;let i=[];for(let s of o){let a=e.safeParse(s);a.success&&i.push(t==="parsed"?a.data:s)}return i},Oe=(e,t,r)=>e.length&&t.length?Yr(e,t).map(r):e.concat(t),V=e=>e instanceof P.ZodEffects&&e._def.effect.type!=="refinement"?!0:e instanceof P.ZodUnion?e.options.some(V):e instanceof P.ZodIntersection?[e._def.left,e._def.right].some(V):!1,v=({subject:e,condition:t,maxDepth:r,depth:o=1})=>{if(t(e))return!0;if(r!==void 0&&o>=r)return!1;let i={condition:t,maxDepth:r,depth:o+1};return e instanceof P.ZodObject?Object.values(e.shape).some(s=>v({subject:s,...i})):e instanceof P.ZodUnion?e.options.some(s=>v({subject:s,...i})):e instanceof P.ZodIntersection?[e._def.left,e._def.right].some(s=>v({subject:s,...i})):e instanceof P.ZodOptional||e instanceof P.ZodNullable?v({subject:e.unwrap(),...i}):e instanceof P.ZodEffects||e instanceof P.ZodTransformer?v({subject:e.innerType(),...i}):e instanceof P.ZodRecord?v({subject:e.valueSchema,...i}):e instanceof P.ZodArray?v({subject:e.element,...i}):e instanceof P.ZodDefault?v({subject:e._def.innerType,...i}):!1},Wt=e=>v({subject:e,condition:t=>nt(t,Ie)}),Yt=e=>v({subject:e,condition:t=>nt(t,te),maxDepth:3}),Ce=e=>"coerce"in e._def&&typeof e._def.coerce=="boolean"?e._def.coerce:!1,dt=e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),w=(...e)=>e.flatMap(t=>t.split(/[^A-Z0-9]/gi)).flatMap(t=>t.replaceAll(/[A-Z]+/g,r=>`/${r}`).split("/")).map(dt).join(""),qe=e=>Wr("sha1").update(JSON.stringify(e),"utf8").digest("hex"),Ve=(e,t)=>{try{return typeof e.parse(t)}catch{return}};var $e=({error:e,logger:t,response:r})=>{t.error(`Result handler failure: ${e.message}.`),r.status(500).end(`An error occurred while serving the result: ${e.message}.`+(e.originalError?`
|
|
5
|
+
Original error: ${e.originalError.message}.`:""))};var Jt=e=>typeof e=="object"&&e!==null,re=e=>Jt(e)&&"or"in e,oe=e=>Jt(e)&&"and"in e,_e=e=>({and:e.reduce((t,r)=>t.concat(oe(r)?r.and:r),[])}),Ge=(e,t)=>oe(e)?{and:e.and.map(r=>re(r)?{or:r.or.map(t)}:t(r))}:re(e)?{or:e.or.map(r=>oe(r)?{and:r.and.map(t)}:t(r))}:t(e),ct=e=>e.and.reduce((t,r)=>({or:Oe(t.or,re(r)?r.or:[r],_e)}),{or:[]}),le=(e,t)=>oe(e)?oe(t)?_e([e,t]):re(t)?le(ct(e),t):_e([e,t]):re(e)?oe(t)?le(t,e):re(t)?{or:Oe(e.or,t.or,_e)}:le(e,{and:[t]}):oe(t)||re(t)?le(t,e):{and:[e,t]};var ue=class{},We=class extends ue{#e;#o;#n;#i;#t;#s;#a;#r;#p;#d;#c;#m=[];constructor({methods:t,inputSchema:r,outputSchema:o,handler:i,resultHandler:s,getOperationId:a=()=>{},scopes:p=[],middlewares:d=[],tags:c=[],description:l,shortDescription:m}){super(),this.#s=i,this.#a=s,this.#n=d,this.#c=a,this.#o=t,this.#p=p,this.#d=c,this.#e={long:l,short:m},this.#r={input:r,output:o};for(let[f,T]of Object.entries(this.#r))Qt(!V(T),new F(`Using transformations on the top level of endpoint ${f} schema is not allowed.`));this.#t={positive:ot(s.getPositiveResponse(o),{mimeTypes:[K],statusCodes:[pe.positive]}),negative:ot(s.getNegativeResponse(),{mimeTypes:[K],statusCodes:[pe.negative]})};for(let[f,T]of Object.entries(this.#t))Qt(T.length,new ee(`ResultHandler must have at least one ${f} response schema specified.`));this.#i={input:Wt(r)?[Re]:Yt(r)?[Bt]:[K],positive:this.#t.positive.flatMap(({mimeTypes:f})=>f),negative:this.#t.negative.flatMap(({mimeTypes:f})=>f)}}_setSiblingMethods(t){this.#m=t}getDescription(t){return this.#e[t]}getMethods(){return this.#o}getSchema(t){return t==="input"||t==="output"?this.#r[t]:this.getResponses(t).map(({schema:r})=>r).reduce((r,o)=>r.or(o))}getMimeTypes(t){return this.#i[t]}getResponses(t){return this.#t[t]}getSecurity(){return this.#n.reduce((t,r)=>r.security?le(t,r.security):t,{and:[]})}getScopes(){return this.#p}getTags(){return this.#d}getOperationId(t){return this.#c(t)}#l(){return{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":this.#o.concat(this.#m).concat("options").join(", ").toUpperCase(),"Access-Control-Allow-Headers":"content-type"}}async#u(t){try{return await this.#r.output.parseAsync(t)}catch(r){throw r instanceof mt.ZodError?new X(r):r}}async#f({method:t,input:r,request:o,response:i,logger:s}){let a={},p=!1;for(let d of this.#n){if(t==="options"&&d.type==="proprietary")continue;let c;try{c=await d.input.parseAsync(r)}catch(l){throw l instanceof mt.ZodError?new B(l):l}if(Object.assign(a,await d.middleware({input:c,options:a,request:o,response:i,logger:s})),p="writableEnded"in i&&i.writableEnded,p){s.warn(`The middleware ${d.middleware.name} has closed the stream. Accumulated options:`,a);break}}return{options:a,isStreamClosed:p}}async#y({input:t,options:r,logger:o}){let i;try{i=await this.#r.input.parseAsync(t)}catch(s){throw s instanceof mt.ZodError?new B(s):s}return this.#s({input:i,options:r,logger:o})}async#g({error:t,request:r,response:o,logger:i,input:s,output:a}){try{await this.#a.handler({error:t,output:a,request:r,response:o,logger:i,input:s})}catch(p){$e({logger:i,response:o,error:new ee(me(p).message,t)})}}async execute({request:t,response:r,logger:o,config:i}){let s=st(t),a=null,p=null;if(i.cors){let c=this.#l();typeof i.cors=="function"&&(c=await i.cors({request:t,logger:o,endpoint:this,defaultHeaders:c}));for(let l in c)r.set(l,c[l])}let d=Gt(t,i.inputSources);try{let{options:c,isStreamClosed:l}=await this.#f({method:s,input:d,request:t,response:r,logger:o});if(l)return;if(s==="options"){r.status(200).end();return}a=await this.#u(await this.#y({input:d,options:c,logger:o}))}catch(c){p=me(c)}await this.#g({input:d,output:a,request:t,response:r,error:p,logger:o})}};import{z as er}from"zod";var Xt=(e,t)=>{let r=e.map(({input:i})=>i).concat(t),o=r.reduce((i,s)=>i.and(s));return r.reduce((i,s)=>ke(s,i),o)};import eo from"assert/strict";var lt=e=>(eo(!V(e.input),new F("Using transformations on the top level of middleware input schema is not allowed.")),{...e,type:"proprietary"});import{z as N}from"zod";var ut=e=>e,Ee=ut({getPositiveResponse:e=>{let t=$({schema:e}),r=L(N.object({status:N.literal("success"),data:e}));return t.reduce((o,i)=>o.example({status:"success",data:i}),r)},getNegativeResponse:()=>L(N.object({status:N.literal("error"),error:N.object({message:N.string()})})).example({status:"error",error:{message:q(new Error("Sample error message"))}}),handler:({error:e,input:t,output:r,request:o,response:i,logger:s})=>{if(!e){i.status(pe.positive).json({status:"success",data:r});return}let a=Be(e);pt({logger:s,statusCode:a,request:o,error:e,input:t}),i.status(a).json({status:"error",error:{message:q(e)}})}}),ft=ut({getPositiveResponse:e=>{let t=$({schema:e}),r=L("shape"in e&&"items"in e.shape&&e.shape.items instanceof N.ZodArray?e.shape.items:N.array(N.any()));return t.reduce((o,i)=>typeof i=="object"&&i!==null&&"items"in i&&Array.isArray(i.items)?o.example(i.items):o,r)},getNegativeResponse:()=>L(N.string()).example(q(new Error("Sample error message"))),handler:({response:e,output:t,error:r,logger:o,request:i,input:s})=>{if(r){let a=Be(r);pt({logger:o,statusCode:a,request:i,error:r,input:s}),e.status(a).send(r.message);return}t&&"items"in t&&Array.isArray(t.items)?e.status(pe.positive).json(t.items):e.status(500).send("Property 'items' is missing in the endpoint output")}});var we=class e{resultHandler;middlewares=[];constructor(t){this.resultHandler="resultHandler"in t?t.resultHandler:t}static#e(t,r){let o=new e(r);return o.middlewares=t,o}addMiddleware(t){return e.#e(this.middlewares.concat(t),this.resultHandler)}use=this.addExpressMiddleware;addExpressMiddleware(t,r){let o=r?.transformer||(a=>a),i=r?.provider||(()=>({})),s={type:"express",input:er.object({}),middleware:async({request:a,response:p})=>new Promise((d,c)=>{t(a,p,m=>{if(m&&m instanceof Error)return c(o(m));d(i(a,p))})})};return e.#e(this.middlewares.concat(s),this.resultHandler)}addOptions(t){return e.#e(this.middlewares.concat(lt({input:er.object({}),middleware:async()=>t})),this.resultHandler)}build({input:t,handler:r,output:o,description:i,shortDescription:s,operationId:a,...p}){let{middlewares:d,resultHandler:c}=this,l="methods"in p?p.methods:[p.method],m=typeof a=="function"?a:()=>a,f="scopes"in p?p.scopes:"scope"in p&&p.scope?[p.scope]:[],T="tags"in p?p.tags:"tag"in p&&p.tag?[p.tag]:[];return new We({handler:r,middlewares:d,outputSchema:o,resultHandler:c,scopes:f,tags:T,methods:l,getOperationId:m,description:i,shortDescription:s,inputSchema:Xt(d,t)})}},to=new we(Ee),ro=new we(ft);import{inspect as oo}from"util";var tr=e=>typeof e=="object"&&e!==null&&"level"in e&&("color"in e?typeof e.color=="boolean":!0)&&typeof e.level=="string"&&["silent","warn","debug"].includes(e.level),yt=({winston:{createLogger:e,transports:t,format:{printf:r,timestamp:o,colorize:i,combine:s},config:{npm:a}},...p})=>{let d=f=>{let{[Symbol.for("level")]:T,[Symbol.for("message")]:g,[Symbol.for("splat")]:S,...y}=f;return oo(y,!1,1,p.color)},c=f=>r(({timestamp:T,message:g,level:S,durationMs:y,...x})=>{typeof g=="object"&&(x={...x,...g},g="[No message]");let j=Object.keys(x).length>0,C=[];y&&C.push("duration:",`${y}ms`);let Y=f?d:JSON.stringify;if(j)C.push(Y(x));else{let R=x?.[Symbol.for("splat")];Array.isArray(R)&&C.push(...R.map(U=>typeof U=="object"?Y(U):U))}return[T,`${S}:`,g,...C].join(" ")}),l=[o()],m={handleExceptions:!0};switch(p.color&&l.push(i()),p.level){case"debug":m.level="debug",l.push(c(!0));break;case"silent":case"warn":default:m.level="warn",l.push(c())}return m.format=s(...l),e({silent:p.level==="silent",levels:a.levels,transports:[new t.Console(m)],exitOnError:!1})};var Ze=class{constructor(t){this.endpoints=t}};import no from"express";var ze=class{params;constructor(...t){this.params=t}apply(t,r){return r(t,no.static(...this.params))}};import ir from"express";import io from"http";import so from"https";var ne=async(e,t="default")=>{try{return(await import(e))[t]}catch{}try{return await Promise.resolve().then(()=>Ht(e)[t])}catch{}throw new ce(e)},rr=async e=>{for(let{moduleName:t,moduleExport:r}of e)try{return await ne(t,r)}catch{}throw new ce(e.map(({moduleName:t})=>t))};import or from"assert/strict";var ie=({routing:e,onEndpoint:t,onStatic:r,parentPath:o,hasCors:i})=>{Object.entries(e).forEach(([s,a])=>{s=s.trim(),or.doesNotMatch(s,/\//,new de(`The entry '${s}' must avoid having slashes \u2014 use nesting instead.`));let p=`${o||""}${s?`/${s}`:""}`;if(a instanceof ue){let d=a.getMethods().slice();i&&d.push("options"),d.forEach(c=>{t(a,p,c)})}else if(a instanceof ze)r&&a.apply(p,r);else if(a instanceof Ze){if(Object.entries(a.endpoints).forEach(([d,c])=>{or(c.getMethods().includes(d),new de(`Endpoint assigned to ${d} method of ${p} must support ${d} method.`)),t(c,p,d)}),i&&Object.keys(a.endpoints).length>0){let[d,...c]=Object.keys(a.endpoints),l=a.endpoints[d];l._setSiblingMethods(c),t(l,p,"options")}}else ie({onEndpoint:t,onStatic:r,hasCors:i,routing:a,parentPath:p})})};var nr=()=>`
|
|
6
6
|
\x1B[94m8888888888 8888888888P 888 d8888 8888888b. 8888888 \x1B[39m
|
|
7
7
|
\x1B[94m888 d88P 888 d88888 888 Y88b 888\x1B[39m
|
|
8
8
|
\x1B[95m888 d88P 888 d88P888 888 888 888\x1B[39m
|
|
@@ -15,8 +15,8 @@ Original error: ${e.originalError.message}.`:""))};var Wt=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 lt=({app:e,logger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(rr()),t.debug("Running","v16.2.2 (ESM)"),ne({routing:o,hasCors:!!r.cors,onEndpoint:(s,i,a)=>{e[a](i,async(d,p)=>{t.info(`${d.method}: ${i}`),await s.execute({request:d,response:p,logger:t,config:r})})},onStatic:(s,i)=>{e.use(s,i)}})};import nr from"http-errors";var bo=(e,t)=>(r,o,s,i)=>{if(!r)return i();e.handler({error:nr(400,me(r).message),request:o,response:s,logger:t,input:null,output:null})},So=(e,t)=>(r,o)=>{let s=nr(404,`Can not ${r.method} ${r.path}`);try{e.handler({request:r,response:o,logger:t,error:s,input:null,output:null})}catch(i){He({response:o,logger:t,error:new ee(me(i).message,s)})}},sr=async e=>{let t=Xt(e.logger)?mt({...e.logger,winston:await oe("winston")}):e.logger,r=e.errorHandler||Ie,o=So(r,t);return{logger:t,errorHandler:r,notFoundHandler:o}},Oo=async(e,t)=>{let{logger:r,notFoundHandler:o}=await sr(e);return lt({app:e.app,routing:t,logger:r,config:e}),{notFoundHandler:o,logger:r}},Ao=async(e,t)=>{let r=or().disable("x-powered-by");if(e.server.compression){let p=await oe("compression");r.use(p(typeof e.server.compression=="object"?e.server.compression:void 0))}if(r.use(e.server.jsonParser||or.json()),e.server.upload){let p=await oe("express-fileupload");r.use(p({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}))}e.server.rawParser&&(r.use(e.server.rawParser),r.use((p,{},c)=>{Buffer.isBuffer(p.body)&&(p.body={raw:p.body}),c()}));let{logger:o,errorHandler:s,notFoundHandler:i}=await sr(e);r.use(bo(s,o)),lt({app:r,routing:t,logger:o,config:e}),r.use(i);let a=(p,c)=>p.listen(c,()=>{o.info("Listening",c)}),d={httpServer:a(xo.createServer(r),e.server.listen),httpsServer:e.https?a(To.createServer(e.https.options,r),e.https.listen):void 0};return{app:r,...d,logger:o}};import ln from"assert/strict";import{OpenApiBuilder as un}from"openapi3-ts/oas31";import ge from"assert/strict";import{isReferenceObject as ye}from"openapi3-ts/oas31";import{omit as De}from"ramda";import{z as O}from"zod";import{INVALID as ir,ZodIssueCode as ut,ZodParsedType as ar,ZodType as Ro,addIssueToContext as ft}from"zod";var yt=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?)?Z?$/,Po="ZodDateIn",qe=class e extends Ro{_parse(t){let{status:r,ctx:o}=this._processInputParams(t);if(o.parsedType!==ar.string)return ft(o,{code:ut.invalid_type,expected:ar.string,received:o.parsedType}),ir;yt.test(o.data)||(ft(o,{code:ut.invalid_string,validation:"regex"}),r.dirty());let s=new Date(o.data);return ve(s)?{status:r.value,value:s}:(ft(o,{code:ut.invalid_date}),ir)}static create=()=>new e({typeName:Po})};var se=({schema:e,onEach:t,rules:r,onMissing:o,...s})=>{let i="typeName"in e._def?r[e._def.typeName]:void 0,a=s,p=i?i({schema:e,...a,next:l=>se({...l,...a,onEach:t,rules:r,onMissing:o})}):o({schema:e,...a}),c=t&&t({schema:e,prev:p,...a});return c?{...p,...c}:p};var dr=50,cr="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",Io={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},mr=/:([A-Za-z0-9_]+)/g,lr=e=>{let t=e.match(mr);return t?t.map(r=>r.slice(1)):[]},ur=e=>e.replace(mr,t=>`{${t.slice(1)}}`),Co=({schema:{_def:{innerType:e,defaultValue:t}},next:r})=>({...r({schema:e}),default:t()}),Zo=({schema:{_def:{innerType:e}},next:t})=>t({schema:e}),Eo=()=>({format:"any"}),wo=e=>(ge(!e.isResponse,new I({message:"Please use ez.upload() only for input.",...e})),{type:"string",format:"binary"}),Do=({schema:{isBinary:e,isBase64:t,isBuffer:r}})=>({type:"string",format:r||e?"binary":t?"byte":"file"}),No=({schema:{options:e},next:t})=>({oneOf:e.map(r=>t({schema:r}))}),vo=({schema:{options:e,discriminator:t},next:r})=>({discriminator:{propertyName:t},oneOf:Array.from(e.values()).map(o=>r({schema:o}))}),Mo=({schema:{_def:{left:e,right:t}},next:r})=>({allOf:[e,t].map(o=>r({schema:o}))}),zo=({schema:e,next:t})=>t({schema:e.unwrap()}),jo=({schema:e,next:t})=>t({schema:e._def.innerType}),Lo=({schema:e,next:t})=>{let r=t({schema:e.unwrap()});return ye(r)||(r.type=fr(r)),r},pr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),ko=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Uo=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(i=>{let a=e.shape[i];return!(t&&Pe(a)?a instanceof O.ZodOptional:a.isOptional())}),s={type:"object",properties:$e({schema:e,isResponse:t,...r})};return o.length&&(s.required=o),s},Ho=()=>({type:"null"}),Fo=e=>(ge(!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:yt.source,externalDocs:{url:cr}}),Ko=e=>(ge(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:cr}}),Bo=e=>ge.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})),qo=()=>({type:"boolean"}),$o=()=>({type:"integer",format:"bigint"}),Vo=e=>e.reduce((t,r)=>t&&r instanceof O.ZodLiteral,!0),_o=({schema:{keySchema:e,valueSchema:t},...r})=>{if(e instanceof O.ZodEnum||e instanceof O.ZodNativeEnum){let o=Object.values(e.enum),s=o.reduce((a,d)=>({...a,[d]:t}),{}),i={type:"object",properties:$e({schema:O.object(s),...r})};return o.length&&(i.required=o),i}if(e instanceof O.ZodLiteral)return{type:"object",properties:$e({schema:O.object({[e.value]:t}),...r}),required:[e.value]};if(e instanceof O.ZodUnion&&Vo(e.options)){let o=e.options.reduce((s,i)=>({...s,[`${i.value}`]:t}),{});return{type:"object",properties:$e({schema:O.object(o),...r}),required:e.options.map(s=>s.value)}}return{type:"object",additionalProperties:r.next({schema:t})}},Go=({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},Wo=({schema:{items:e},next:t})=>({type:"array",prefixItems:e.map(o=>t({schema:o}))}),Yo=({schema:{isEmail:e,isURL:t,minLength:r,maxLength:o,isUUID:s,isCUID:i,isCUID2:a,isULID:d,isIP:p,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:s,cuid:i,cuid2:a,ulid:d,ip:p,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},Jo=({schema:e})=>{let t=e._def.checks.find(({kind:p})=>p==="min"),r=e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,o=t?t.inclusive:!0,s=e._def.checks.find(({kind:p})=>p==="max"),i=e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,a=s?s.inclusive:!0,d={type:e.isInt?"integer":"number",format:e.isInt?"int64":"double"};return o?d.minimum=r:d.exclusiveMinimum=r,a?d.maximum=i:d.exclusiveMaximum=i,d},$e=({schema:{shape:e},next:t})=>Object.keys(e).reduce((r,o)=>({...r,[o]:t({schema:e[o]})}),{}),Qo=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return Io?.[t]},fr=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Xo=({schema:e,isResponse:t,next:r})=>{let o=r({schema:e.innerType()}),{effect:s}=e._def;if(t&&s.type==="transform"&&!ye(o)){let i=Ue(e,Qo(o));return i&&["number","string","boolean"].includes(i)?{type:i}:r({schema:O.any()})}if(!t&&s.type==="preprocess"&&!ye(o)){let{type:i,...a}=o;return{...a,format:`${a.format||i} (preprocessed)`}}return o},en=({schema:e,isResponse:t,next:r})=>r({schema:e._def[t?"out":"in"]}),tn=({schema:e,next:t})=>t({schema:e.unwrap()}),rn=({next:e,schema:t,serializer:r,getRef:o,makeRef:s})=>{let i=r(t.schema);return o(i)||(s(i,{}),s(i,e({schema:t.schema})))},yr=(e,t,r=[])=>{let o=V({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((s,i,a)=>({...s,[`example${a+1}`]:{value:typeof i=="object"&&!Array.isArray(i)?De(r,i):i}}),{})},on=(e,t,r)=>{let o=V({schema:e,variant:t?"parsed":"original",validate:!0});if(o.length!==0)return o.reduce((s,i,a)=>r in i?{...s,[`example${a+1}`]:{value:i[r]}}:s,{})},we=(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=>we(o,t)).reduce((o,s)=>o.merge(s.partial()),O.object({})):e instanceof O.ZodEffects?(ge(!$(e),new I({message:`Using transformations on the top level of ${t.isResponse?"response":"input"} schema is not allowed.`,...t})),r=we(e._def.schema,t)):r=we(e._def.left,t).merge(we(e._def.right,t)),ze(e,r)},gr=({path:e,method:t,schema:r,inputSources:o,serializer:s,getRef:i,makeRef:a,composition:d,description:p=`${t.toUpperCase()} ${e} Parameter`})=>{let c=we(r,{path:e,method:t,isResponse:!1}).shape,l=lr(e),m=o.includes("query"),f=o.includes("params"),T=o.includes("headers"),g=y=>f&&l.includes(y),S=y=>T&&ot(y);return Object.keys(c).filter(y=>m||g(y)).map(y=>{let x=se({schema:c[y],isResponse:!1,rules:ht,onEach:xt,onMissing:Tt,serializer:s,getRef:i,makeRef:a,path:e,method:t}),M=d==="components"?a(w(p,y),x):x;return{name:y,in:g(y)?"path":S(y)?"header":"query",required:!c[y].isOptional(),description:x.description||p,schema:M,examples:on(r,!1,y)}})},ht={ZodString:Yo,ZodNumber:Jo,ZodBigInt:$o,ZodBoolean:qo,ZodDateIn:Fo,ZodDateOut:Ko,ZodNull:Ho,ZodArray:Go,ZodTuple:Wo,ZodRecord:_o,ZodObject:Uo,ZodLiteral:ko,ZodIntersection:Mo,ZodUnion:No,ZodFile:Do,ZodUpload:wo,ZodAny:Eo,ZodDefault:Co,ZodEnum:pr,ZodNativeEnum:pr,ZodEffects:Xo,ZodOptional:zo,ZodNullable:Lo,ZodDiscriminatedUnion:vo,ZodBranded:tn,ZodDate:Bo,ZodCatch:Zo,ZodPipeline:en,ZodLazy:rn,ZodReadonly:jo},xt=({schema:e,isResponse:t,prev:r})=>{if(ye(r))return{};let{description:o}=e,s=e instanceof O.ZodLazy,i=r.type!==void 0,a=t&&Pe(e),d=!s&&i&&!a&&e.isNullable(),p=s?[]:V({schema:e,variant:t?"parsed":"original",validate:!0}),c={};return o&&(c.description=o),d&&(c.type=fr(r)),p.length&&(c.examples=Array.from(p)),c},Tt=({schema:e,...t})=>ge.fail(new I({message:`Zod type ${e.constructor.name} is unsupported.`,...t})),gt=(e,t)=>{if(ye(e))return e;let r=e.properties?De(t,e.properties):void 0,o=e.examples?e.examples.map(d=>De(t,d)):void 0,s=e.required?e.required.filter(d=>!t.includes(d)):void 0,i=e.allOf?e.allOf.map(d=>gt(d,t)):void 0,a=e.oneOf?e.oneOf.map(d=>gt(d,t)):void 0;return De(Object.entries({properties:r,required:s,examples:o,allOf:i,oneOf:a}).filter(([{},d])=>d===void 0).map(([d])=>d),{...e,properties:r,required:s,examples:o,allOf:i,oneOf:a})},hr=e=>ye(e)?e:De(["examples"],e),xr=({method:e,path:t,schema:r,mimeTypes:o,variant:s,serializer:i,getRef:a,makeRef:d,composition:p,hasMultipleStatusCodes:c,statusCode:l,description:m=`${e.toUpperCase()} ${t} ${st(s)} response ${c?l:""}`.trim()})=>{let f=hr(se({schema:r,isResponse:!0,rules:ht,onEach:xt,onMissing:Tt,serializer:i,getRef:a,makeRef:d,path:t,method:e})),T=yr(r,!0),g=p==="components"?d(w(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},dn=({name:e})=>({type:"apiKey",in:"header",name:e}),pn=({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:s={},...i}=o;return{...t,[r]:{...i,scopes:s}}},{})}),Tr=(e,t)=>{let r={basic:nn,bearer:sn,input:an,header:dn,cookie:pn,openid:cn,oauth2:mn};return Ke(e,o=>r[o.type](o,t))},Ve=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:s})=>({...r,[o]:s}),{}));if("and"in e)return Ve(it(e))}return Ve({or:[e]})},br=({method:e,path:t,schema:r,mimeTypes:o,serializer:s,getRef:i,makeRef:a,composition:d,description:p=`${e.toUpperCase()} ${t} Request body`})=>{let c=lr(t),l=hr(gt(se({schema:le(r)?E.create().buffer():r,isResponse:!1,rules:ht,onEach:xt,onMissing:Tt,serializer:s,getRef:i,makeRef:a,path:t,method:e}),c)),m=yr(r,!1,c),f=d==="components"?a(w(p),l):l;return{description:p,content:o.reduce((T,g)=>({...T,[g]:{schema:f,examples:m}}),{})}},Sr=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}),bt=e=>e.length<=dr?e:e.slice(0,dr-1)+"\u2026";var St=class extends un{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 ln(!(o in this.lastOperationIdSuffixes),new I({message:`Duplicated operationId: "${o}"`,method:r,isResponse:!1,path:t})),this.lastOperationIdSuffixes[o]=1,o;let s=w(r,t);return s in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[s]++,`${s}${this.lastOperationIdSuffixes[s]}`):(this.lastOperationIdSuffixes[s]=1,s)}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:s,serverUrl:i,descriptions:a,hasSummaryFromDescription:d=!0,composition:p="inline",serializer:c=ke}){super(),this.addInfo({title:o,version:s});for(let m of typeof i=="string"?[i]:i)this.addServer({url:m});ne({routing:t,onEndpoint:(m,f,T)=>{let g=T,S={path:f,method:g,endpoint:m,composition:p,serializer:c,getRef:this.getRef.bind(this),makeRef:this.makeRef.bind(this)},[y,x]=["short","long"].map(m.getDescription.bind(m)),M=r.inputSources?.[g]||je[g],C=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Y=gr({...S,inputSources:M,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:C})}),A={operationId:C,responses:{}};for(let z of["positive","negative"]){let J=m.getResponses(z);for(let{mimeTypes:Te,schema:Qe,statusCodes:b}of J)for(let R of b)A.responses[R]=xr({...S,variant:z,schema:Qe,mimeTypes:Te,statusCode:R,hasMultipleStatusCodes:J.length>1||b.length>1,description:a?.[`${z}Response`]?.call(null,{method:g,path:f,operationId:C,statusCode:R})})}x&&(A.description=x,d&&y===void 0&&(A.summary=bt(x))),y&&(A.summary=bt(y)),m.getTags().length>0&&(A.tags=m.getTags()),Y.length>0&&(A.parameters=Y),M.includes("body")&&(A.requestBody=br({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:C})}));let U=Ve(Ke(Tr(m.getSecurity(),M),z=>{let J=this.ensureUniqSecuritySchemaName(z),Te=["oauth2","openIdConnect"].includes(z.type)?m.getScopes():[];return this.addSecurityScheme(J,z),{name:J,scopes:Te}}));U.length>0&&(A.security=U),this.addPath(ur(f),{[g]:A})}}),this.rootDoc.tags=r.tags?Sr(r.tags):[]}};import Or from"http";var fn=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>j),...t}),yn=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:Or.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=Or.STATUS_CODES[o],r)),json:e(()=>r),send:e(()=>r),end:e(()=>(r.writableEnded=!0,r)),...t};return r},gn=({fnMethod:e,loggerProps:t})=>({info:e(),warn:e(),error:e(),debug:e(),...t}),hn=async({endpoint:e,requestProps:t,responseProps:r,configProps:o,loggerProps:s,fnMethod:i})=>{let a=i||(await er([{moduleName:"vitest",moduleExport:"vi"},{moduleName:"@jest/globals",moduleExport:"jest"}])).fn,d=fn({fnMethod:a,requestProps:t}),p=yn({fnMethod:a,responseProps:r}),c=gn({fnMethod:a,loggerProps:s}),l={cors:!1,logger:c,...o};return await e.execute({request:d,response:p,config:l,logger:c}),{requestMock:d,responseMock:p,loggerMock:c}};import D from"typescript";import k from"typescript";var n=k.factory,_=[n.createModifier(k.SyntaxKind.ExportKeyword)],xn=[n.createModifier(k.SyntaxKind.AsyncKeyword)],Tn=[n.createModifier(k.SyntaxKind.PublicKeyword),n.createModifier(k.SyntaxKind.ReadonlyKeyword)],Ar=[n.createModifier(k.SyntaxKind.ProtectedKeyword),n.createModifier(k.SyntaxKind.ReadonlyKeyword)],Ot=n.createTemplateHead(""),he=n.createTemplateTail(""),At=n.createTemplateMiddle(" "),Rt=e=>n.createTemplateLiteralType(Ot,e.map((t,r)=>n.createTemplateLiteralTypeSpan(n.createTypeReferenceNode(t),r===e.length-1?he:At))),Pt=Rt(["M","P"]),_e=(e,t,r)=>n.createParameterDeclaration(r,void 0,e,void 0,t,void 0),Ge=(e,t)=>Object.keys(e).reduce((r,o)=>r.concat(_e(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)]),Rr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),Pr=(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)],k.NodeFlags.Const),Ct=(e,t)=>n.createTypeAliasDeclaration(_,e,void 0,n.createUnionTypeNode(t.map(r=>n.createLiteralTypeNode(n.createStringLiteral(r))))),We=(e,t)=>n.createTypeAliasDeclaration(_,e,void 0,t),Ir=(e,t,r)=>n.createPropertyDeclaration(Tn,e,void 0,t,r),Cr=(e,t,r=[])=>n.createClassDeclaration(_,e,void 0,void 0,[t,...r]),Zr=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),Er=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(k.SyntaxKind.AnyKeyword)]),wr=(e,t,r)=>n.createInterfaceDeclaration(_,e,void 0,t,r),Dr=e=>Object.keys(e).reduce((t,r)=>t.concat(n.createTypeParameterDeclaration([],r,n.createTypeReferenceNode(e[r]))),[]),Zt=(e,t,r)=>n.createArrowFunction(r?xn:void 0,void 0,e.map(o=>_e(o)),void 0,void 0,t),Et=(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,Ge({acc:void 0,key:void 0}),void 0,void 0,t),r]);var Nr=["get","post","put","delete","patch"];import h from"typescript";import{z as Sn}from"zod";import W from"typescript";var{factory:Ye}=W,wt=(e,t)=>{W.addSyntheticLeadingComment(e,W.SyntaxKind.MultiLineCommentTrivia,`* ${t} `,!0)},xe=(e,t,r)=>{let o=Ye.createTypeAliasDeclaration(void 0,Ye.createIdentifier(t),void 0,e);return r&&wt(o,r),o},Dt=(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)},bn=/^[A-Za-z_$][A-Za-z0-9_$]*$/,vr=e=>bn.test(e)?Ye.createIdentifier(e):Ye.createStringLiteral(e);var{factory:u}=h,On={[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},An=({schema:{value:e}})=>u.createLiteralTypeNode(typeof e=="number"?u.createNumericLiteral(e):typeof e=="boolean"?e?u.createTrue():u.createFalse():u.createStringLiteral(e)),Rn=({schema:{shape:e},isResponse:t,next:r,optionalPropStyle:{withQuestionMark:o}})=>{let s=Object.entries(e).map(([i,a])=>{let d=t&&Pe(a)?a instanceof Sn.ZodOptional:a.isOptional(),p=u.createPropertySignature(void 0,vr(i),d&&o?u.createToken(h.SyntaxKind.QuestionToken):void 0,r({schema:a}));return a.description&&wt(p,a.description),p});return u.createTypeLiteralNode(s)},Pn=({schema:{element:e},next:t})=>u.createArrayTypeNode(t({schema:e})),In=({schema:{options:e}})=>u.createUnionTypeNode(e.map(t=>u.createLiteralTypeNode(u.createStringLiteral(t)))),Mr=({schema:{options:e},next:t})=>u.createUnionTypeNode(e.map(r=>t({schema:r}))),Cn=e=>On?.[e.kind],Zn=({schema:e,next:t,isResponse:r})=>{let o=t({schema:e.innerType()}),s=e._def.effect;if(r&&s.type==="transform"){let i=Ue(e,Cn(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(i&&a[i]||h.SyntaxKind.AnyKeyword)}return o},En=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(t=>u.createLiteralTypeNode(typeof t=="number"?u.createNumericLiteral(t):u.createStringLiteral(t)))),wn=({next:e,schema:t,optionalPropStyle:{withUndefined:r}})=>{let o=e({schema:t.unwrap()});return r?u.createUnionTypeNode([o,u.createKeywordTypeNode(h.SyntaxKind.UndefinedKeyword)]):o},Dn=({next:e,schema:t})=>u.createUnionTypeNode([e({schema:t.unwrap()}),u.createLiteralTypeNode(u.createNull())]),Nn=({next:e,schema:{items:t}})=>u.createTupleTypeNode(t.map(r=>e({schema:r}))),vn=({next:e,schema:{keySchema:t,valueSchema:r}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:t}),e({schema:r})]),Mn=({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}),ie=e=>()=>u.createKeywordTypeNode(e),jn=({next:e,schema:t})=>e({schema:t.unwrap()}),Ln=({next:e,schema:t})=>e({schema:t._def.innerType}),kn=({next:e,schema:t})=>e({schema:t._def.innerType}),Un=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),Hn=()=>u.createLiteralTypeNode(u.createNull()),Fn=({getAlias:e,makeAlias:t,next:r,serializer:o,schema:s})=>{let i=`Type${o(s.schema)}`;return e(i)||(t(i,u.createLiteralTypeNode(u.createNull())),t(i,r({schema:s.schema})))},Kn=({schema:{isBuffer:e}})=>e?u.createTypeReferenceNode("Buffer"):u.createKeywordTypeNode(h.SyntaxKind.StringKeyword),Bn={ZodString:ie(h.SyntaxKind.StringKeyword),ZodNumber:ie(h.SyntaxKind.NumberKeyword),ZodBigInt:ie(h.SyntaxKind.BigIntKeyword),ZodBoolean:ie(h.SyntaxKind.BooleanKeyword),ZodDateIn:ie(h.SyntaxKind.StringKeyword),ZodDateOut:ie(h.SyntaxKind.StringKeyword),ZodNull:Hn,ZodArray:Pn,ZodTuple:Nn,ZodRecord:vn,ZodObject:Rn,ZodLiteral:An,ZodIntersection:Mn,ZodUnion:Mr,ZodFile:Kn,ZodAny:ie(h.SyntaxKind.AnyKeyword),ZodDefault:zn,ZodEnum:In,ZodNativeEnum:En,ZodEffects:Zn,ZodOptional:wn,ZodNullable:Dn,ZodDiscriminatedUnion:Mr,ZodBranded:jn,ZodCatch:kn,ZodPipeline:Un,ZodLazy:Fn,ZodReadonly:Ln},Ne=({schema:e,...t})=>se({schema:e,rules:Bn,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]=xe(r,t),this.getAlias(t)}constructor({routing:t,variant:r="client",serializer:o=ke,splitResponse:s=!1,optionalPropStyle:i={withQuestionMark:!0,withUndefined:!0}}){ne({routing:t,onEndpoint:(b,R,Z)=>{let Q={serializer:o,getAlias:this.getAlias.bind(this),makeAlias:this.makeAlias.bind(this),optionalPropStyle:i},vt=b.getSchema("input"),Mt=w(Z,R,"input"),Hr=Ne({...Q,schema:le(vt)?E.create().buffer():vt,isResponse:!1}),be=s?w(Z,R,"positive.response"):void 0,zt=b.getSchema("positive"),jt=s?Ne({...Q,isResponse:!0,schema:zt}):void 0,Se=s?w(Z,R,"negative.response"):void 0,Lt=b.getSchema("negative"),kt=s?Ne({...Q,isResponse:!0,schema:Lt}):void 0,Ut=w(Z,R,"response"),Fr=be&&Se?n.createUnionTypeNode([n.createTypeReferenceNode(be),n.createTypeReferenceNode(Se)]):Ne({...Q,isResponse:!0,schema:zt.or(Lt)});this.program.push(xe(Hr,Mt)),jt&&be&&this.program.push(xe(jt,be)),kt&&Se&&this.program.push(xe(kt,Se)),this.program.push(xe(Fr,Ut)),Z!=="options"&&(this.paths.push(R),this.registry[`${Z} ${R}`]={input:Mt,positive:be,negative:Se,response:Ut,isJson:b.getMimeTypes("positive").includes(j),tags:b.getTags()})}}),this.program.unshift(...Object.values(this.aliases)),this.program.push(Ct(this.ids.pathType,this.paths)),this.program.push(Ct(this.ids.methodType,Nr)),this.program.push(We(this.ids.methodPathType,Rt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(D.SyntaxKind.ExtendsKeyword,[It(this.ids.methodPathType,D.SyntaxKind.AnyKeyword)])];this.interfaces.push({id:this.ids.inputInterface,kind:"input"}),s&&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:R}of this.interfaces)this.program.push(wr(b,a,Object.keys(this.registry).map(Z=>{let Q=this.registry[Z][R];return Q?Pr(Z,Q):void 0}).filter(Z=>Z!==void 0)));if(r==="types")return;let d=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()))))),p=n.createVariableStatement(_,G(this.ids.endpointTagsConst,n.createObjectLiteralExpression(Object.keys(this.registry).map(b=>n.createPropertyAssignment(`"${b}"`,n.createArrayLiteralExpression(this.registry[b].tags.map(R=>n.createStringLiteral(R)))))))),c=We(this.ids.providerType,n.createFunctionTypeNode(Dr({M:this.ids.methodType,P:this.ids.pathType}),Ge({method:n.createTypeReferenceNode("M"),path:n.createTypeReferenceNode("P"),params:n.createIndexedAccessTypeNode(n.createTypeReferenceNode(this.ids.inputInterface),Pt)}),Zr(this.ids.responseInterface,Pt))),l=We(this.ids.implementationType,n.createFunctionTypeNode(void 0,Ge({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(D.SyntaxKind.StringKeyword),params:It(D.SyntaxKind.StringKeyword,D.SyntaxKind.AnyKeyword)}),Er())),m=n.createTemplateExpression(n.createTemplateHead(":"),[n.createTemplateSpan(this.ids.keyParameter,he)]),f=Et(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=Et(this.ids.paramsArgument,n.createConditionalExpression(n.createBinaryExpression(n.createCallExpression(n.createPropertyAccessExpression(this.ids.pathParameter,"indexOf"),void 0,[m]),D.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=Cr(this.ids.clientClass,Rr([_e(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),Ar)]),[Ir(this.ids.provideMethod,n.createTypeReferenceNode(this.ids.providerType),Zt([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(d,p,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(j))]),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)),M=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,he)]),n.createObjectLiteralExpression([S,y,x])])))),C=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]),he)])))),[A,U]=["json","text"].map(b=>n.createReturnStatement(n.createCallExpression(n.createPropertyAccessExpression(this.ids.responseConst,b),void 0,void 0))),z=n.createIfStatement(n.createBinaryExpression(n.createTemplateExpression(Ot,[n.createTemplateSpan(this.ids.methodParameter,At),n.createTemplateSpan(this.ids.pathParameter,he)]),D.SyntaxKind.InKeyword,this.ids.jsonEndpointsConst),n.createBlock([A])),J=n.createVariableStatement(_,G(this.ids.exampleImplementationConst,Zt([this.ids.methodParameter,this.ids.pathParameter,this.ids.paramsArgument],n.createBlock([C,Y,M,z,U]),!0),n.createTypeReferenceNode(this.ids.implementationType))),Te=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"))])])),Qe=n.createVariableStatement(void 0,G(this.ids.clientConst,n.createNewExpression(this.ids.clientClass,void 0,[this.ids.exampleImplementationConst])));this.usage.push(J,Qe,Te)}printUsage(t){return this.usage.length?this.usage.map(r=>typeof r=="string"?r:Dt(r,t)).join(`
|
|
19
|
-
`):void 0}print(t){let r=this.printUsage(t),o=r&&
|
|
20
|
-
${r}`);return this.program.concat(o||[]).map((s
|
|
18
|
+
`;var gt=({app:e,logger:t,config:r,routing:o})=>{r.startupLogo!==!1&&console.log(nr()),t.debug("Running","v16.3.0-beta1 (ESM)"),ie({routing:o,hasCors:!!r.cors,onEndpoint:(i,s,a)=>{e[a](s,async(p,d)=>{t.info(`${p.method}: ${s}`),await i.execute({request:p,response:d,logger:t,config:r})})},onStatic:(i,s)=>{e.use(i,s)}})};import sr from"http-errors";var ao=(e,t)=>(r,o,i,s)=>{if(!r)return s();e.handler({error:sr(400,me(r).message),request:o,response:i,logger:t,input:null,output:null})},po=(e,t)=>(r,o)=>{let i=sr(404,`Can not ${r.method} ${r.path}`);try{e.handler({request:r,response:o,logger:t,error:i,input:null,output:null})}catch(s){$e({response:o,logger:t,error:new ee(me(s).message,i)})}},ar=async e=>{let t=tr(e.logger)?yt({...e.logger,winston:await ne("winston")}):e.logger,r=e.errorHandler||Ee,o=po(r,t);return{logger:t,errorHandler:r,notFoundHandler:o}},co=async(e,t)=>{let{logger:r,notFoundHandler:o}=await ar(e);return gt({app:e.app,routing:t,logger:r,config:e}),{notFoundHandler:o,logger:r}},mo=async(e,t)=>{let r=ir().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||ir.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{logger:o,errorHandler:i,notFoundHandler:s}=await ar(e);r.use(ao(i,o)),gt({app:r,routing:t,logger:o,config:e}),r.use(s);let a=(d,c)=>d.listen(c,()=>{o.info("Listening",c)}),p={httpServer:a(io.createServer(r),e.server.listen),httpsServer:e.https?a(so.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 pr}from"zod";var Me="DateIn",dr=()=>z(Me,pr.string().regex(Ke).transform(e=>new Date(e)).pipe(pr.date().refine(Le)));import{z as lo}from"zod";var ve="DateOut",cr=()=>z(ve,lo.date().refine(Le).transform(e=>e.toISOString()));var se=({schema:e,onEach:t,rules:r,onMissing:o,...i})=>{let s=Se(e,"proprietaryKind")||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 mr=50,ur="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:[]},fr=/:([A-Za-z0-9_]+)/g,yr=e=>{let t=e.match(fr);return t?t.map(r=>r.slice(1)):[]},gr=e=>e.replace(fr,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 I({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=hr(r)),r},lr=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),Po=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Io=({schema:e,isResponse:t,...r})=>{let o=Object.keys(e.shape).filter(s=>{let a=e.shape[s];return!(t&&Ce(a)?a instanceof O.ZodOptional:a.isOptional())}),i={type:"object",properties:Ye({schema:e,isResponse:t,...r})};return o.length&&(i.required=o),i},Co=()=>({type:"null"}),Eo=e=>(ye(!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:Ke.source,externalDocs:{url:ur}}),wo=e=>(ye(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:ur}}),Zo=e=>ye.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})),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}))}),ko=({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},Lo=({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]})}),{}),Ko=e=>{let t=Array.isArray(e.type)?e.type[0]:e.type;return uo?.[t]},hr=e=>{let t=typeof e.type=="string"?[e.type]:e.type||[];return t.includes("null")?t:t.concat("null")},Ho=({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,Ko(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},Uo=({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}),xr=(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 I({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)),ke(e,r)},Tr=({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=yr(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:ko,ZodNumber:Lo,ZodBigInt:Mo,ZodBoolean:zo,ZodNull:Co,ZodArray:jo,ZodTuple:Do,ZodRecord:No,ZodObject:Io,ZodLiteral:Po,ZodIntersection:So,ZodUnion:To,ZodAny:go,ZodDefault:fo,ZodEnum:lr,ZodNativeEnum:lr,ZodEffects:Ho,ZodOptional:Oo,ZodNullable:Ao,ZodDiscriminatedUnion:bo,ZodBranded:Fo,ZodDate:Zo,ZodCatch:yo,ZodPipeline:Uo,ZodLazy:Bo,ZodReadonly:Ro,[Pe]:xo,[Ie]: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&&Ce(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=hr(r)),d.length&&(c.examples=Array.from(d)),c},bt=({schema:e,...t})=>ye.fail(new I({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})},br=e=>fe(e)?e:je(["examples"],e),Sr=({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=br(se({schema:r,isResponse:!0,rules:xt,onEach:Tt,onMissing:bt,serializer:s,getRef:a,makeRef:p,path:t,method:e})),T=xr(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}}},{})}),Or=(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]})},Rr=({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=yr(t),l=br(ht(se({schema:r,isResponse:!1,rules:xt,onEach:Tt,onMissing:bt,serializer:i,getRef:s,makeRef:a,path:t,method:e}),c)),m=xr(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}}),{})}},Ar=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<=mr?e:e.slice(0,mr-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 I({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],C=this.ensureUniqOperationId(f,g,m.getOperationId(g)),Y=Tr({...S,inputSources:j,schema:m.getSchema("input"),description:a?.requestParameter?.call(null,{method:g,path:f,operationId:C})}),R={operationId:C,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]=Sr({...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:C,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=Rr({...S,schema:m.getSchema("input"),mimeTypes:m.getMimeTypes("input"),description:a?.requestBody?.call(null,{method:g,path:f,operationId:C})}));let U=Je(Ge(Or(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}}));U.length>0&&(R.security=U),this.addPath(gr(f),{[g]:R})}}),this.rootDoc.tags=r.tags?Ar(r.tags):[]}};import Pr from"http";var tn=({fnMethod:e,requestProps:t})=>({method:"GET",header:e(()=>K),...t}),rn=({fnMethod:e,responseProps:t})=>{let r={writableEnded:!1,statusCode:200,statusMessage:Pr.STATUS_CODES[200],set:e(()=>r),setHeader:e(()=>r),header:e(()=>r),status:e(o=>(r.statusCode=o,r.statusMessage=Pr.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 rr([{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 H from"typescript";var n=H.factory,_=[n.createModifier(H.SyntaxKind.ExportKeyword)],sn=[n.createModifier(H.SyntaxKind.AsyncKeyword)],an=[n.createModifier(H.SyntaxKind.PublicKeyword),n.createModifier(H.SyntaxKind.ReadonlyKeyword)],Ir=[n.createModifier(H.SyntaxKind.ProtectedKeyword),n.createModifier(H.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))),It=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)),[]),Ct=(e,t)=>n.createExpressionWithTypeArguments(n.createIdentifier("Record"),[typeof e=="number"?n.createKeywordTypeNode(e):n.createTypeReferenceNode(e),n.createKeywordTypeNode(t)]),Cr=e=>n.createConstructorDeclaration(void 0,e,n.createBlock([])),Er=(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)],H.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),wr=(e,t,r)=>n.createPropertyDeclaration(an,e,void 0,t,r),Zr=(e,t,r=[])=>n.createClassDeclaration(_,e,void 0,void 0,[t,...r]),zr=(e,t)=>n.createTypeReferenceNode("Promise",[n.createIndexedAccessTypeNode(n.createTypeReferenceNode(e),t)]),Mr=()=>n.createTypeReferenceNode("Promise",[n.createKeywordTypeNode(H.SyntaxKind.AnyKeyword)]),vr=(e,t,r)=>n.createInterfaceDeclaration(_,e,void 0,t,r),Nr=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 jr=["get","post","put","delete","patch"];import h from"typescript";import{z as Lr}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_$]*$/,Dr=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&&Ce(a)?a instanceof Lr.ZodOptional:a.isOptional(),d=u.createPropertySignature(void 0,Dr(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)))),kr=({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}),In=({schema:e,next:t,isResponse:r})=>t({schema:e._def[r?"out":"in"]}),Cn=()=>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})=>e instanceof Lr.ZodString?u.createKeywordTypeNode(h.SyntaxKind.StringKeyword):u.createTypeReferenceNode("Buffer"),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:Cn,ZodArray:ln,ZodTuple:Tn,ZodRecord:bn,ZodObject:mn,ZodLiteral:cn,ZodIntersection:Sn,ZodUnion:kr,ZodDefault:On,ZodEnum:un,ZodNativeEnum:gn,ZodEffects:yn,ZodOptional:hn,ZodNullable:xn,ZodDiscriminatedUnion:kr,ZodBranded:Rn,ZodCatch:Pn,ZodPipeline:In,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 vt=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},Nt=w(E,A,"input"),Kr=De({...Q,schema:b.getSchema("input"),isResponse:!1}),Te=i?w(E,A,"positive.response"):void 0,jt=b.getSchema("positive"),Dt=i?De({...Q,isResponse:!0,schema:jt}):void 0,be=i?w(E,A,"negative.response"):void 0,kt=b.getSchema("negative"),Lt=i?De({...Q,isResponse:!0,schema:kt}):void 0,Kt=w(E,A,"response"),Hr=Te&&be?n.createUnionTypeNode([n.createTypeReferenceNode(Te),n.createTypeReferenceNode(be)]):De({...Q,isResponse:!0,schema:jt.or(kt)});this.program.push(he(Kr,Nt)),Dt&&Te&&this.program.push(he(Dt,Te)),Lt&&be&&this.program.push(he(Lt,be)),this.program.push(he(Hr,Kt)),E!=="options"&&(this.paths.push(A),this.registry[`${E} ${A}`]={input:Nt,positive:Te,negative:be,response:Kt,isJson:b.getMimeTypes("positive").includes(K),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,jr)),this.program.push(et(this.ids.methodPathType,Pt([this.ids.methodType,this.ids.pathType])));let a=[n.createHeritageClause(Z.SyntaxKind.ExtendsKeyword,[Ct(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(vr(b,a,Object.keys(this.registry).map(E=>{let Q=this.registry[E][A];return Q?Er(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(Nr({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),It)}),zr(this.ids.responseInterface,It))),l=et(this.ids.implementationType,n.createFunctionTypeNode(void 0,Xe({method:n.createTypeReferenceNode(this.ids.methodType),path:n.createKeywordTypeNode(Z.SyntaxKind.StringKeyword),params:Ct(Z.SyntaxKind.StringKeyword,Z.SyntaxKind.AnyKeyword)}),Mr())),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=Zr(this.ids.clientClass,Cr([Qe(this.ids.implementationArgument,n.createTypeReferenceNode(this.ids.implementationType),Ir)]),[wr(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(K))]),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])])))),C=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,U]=["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([C,Y,j,D,U]),!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
|
+
`):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
|
+
${r}`);return this.program.concat(o||[]).map((i,s)=>Mt(i,s<this.program.length?t:{...t,omitTrailingSemicolon:!0})).join(`
|
|
21
21
|
|
|
22
|
-
`)}async printFormatted({printerOptions:t,format:r}={}){let o=r;if(!o)try{let a=(await
|
|
22
|
+
`)}async printFormatted({printerOptions:t,format:r}={}){let o=r;if(!o)try{let a=(await ne("prettier")).format;o=p=>a(p,{filepath:"client.ts"})}catch{}let i=this.printUsage(t);this.usage=i&&o?[await o(i)]:this.usage;let s=this.print(t);return o?o(s):s}};var Mn={dateIn:dr,dateOut:cr,file:Ue,upload:_t,raw:$t};export{ue as AbstractEndpoint,Ze as DependsOnMethod,Ot as Documentation,I as DocumentationError,we as EndpointsFactory,B as InputValidationError,vt as Integration,ce as MissingPeerError,X as OutputValidationError,de as RoutingError,ze as ServeStatic,ro as arrayEndpointsFactory,ft as arrayResultHandler,co as attachRouting,Ur as createConfig,yt as createLogger,lt as createMiddleware,ut as createResultHandler,mo as createServer,to as defaultEndpointsFactory,Ee as defaultResultHandler,Mn as ez,$ as getExamples,q as getMessageFromError,Be as getStatusCodeFromError,nn as testEndpoint,L as withMeta};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-zod-api",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.3.0-beta1",
|
|
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": {
|