express-zod-api 10.0.0-beta2 → 10.0.0-beta5

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 CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  ## Version 10
4
4
 
5
+ ### v10.0.0-beta5
6
+
7
+ - Fixed DTS path for ESM in package.json.
8
+
9
+ ### v10.0.0-beta4
10
+
11
+ - No changes.
12
+
13
+ ### v10.0.0-beta3
14
+
15
+ - This release contains features from versions 9.3.0 (incl. hotfix 9.3.1) and 9.4.0.
16
+ - **BREAKING** changes:
17
+ - `Client::constructor()` now requires an object argument having `routing` property.
18
+
19
+ ```ts
20
+ // before
21
+ new Client(routing).print();
22
+ // after
23
+ new Client({ routing }).print();
24
+ ```
25
+
5
26
  ### v10.0.0-beta2
6
27
 
7
28
  - **BREAKING** changes to the behavior of a public method.
@@ -29,6 +50,7 @@ const schemaB = withMeta(originalSchema).example("B");
29
50
 
30
51
  ### v10.0.0-beta1
31
52
 
53
+ - This release is based on the features of version 9.2.1.
32
54
  - **BREAKING** changes to the concept of dependencies.
33
55
  - `zod` becomes a peer dependency, fixes issue #822.
34
56
  - You need to install it manually and adjust your imports accordingly.
@@ -40,6 +62,7 @@ const schemaB = withMeta(originalSchema).example("B");
40
62
  - Proprietary schemas are now exported under the namespace `ez`.
41
63
  - Imports and utilization should be adjusted accordingly.
42
64
  - Affected schemas: `file`, `dateIn`, `dateOut`, `upload`.
65
+ - If facing Typescript errors `TS4023` or `TS4094`, ensure disabling `declaration` option in your `tsconfig.json`.
43
66
  - **BREAKING** changes to the engines.
44
67
  - The minimal Node version is now 14.18.0.
45
68
  - Due to switching to `tsup` builder, the file structure has changed:
@@ -64,6 +87,67 @@ const uploadSchema = ez.upload(); // namespace changed
64
87
 
65
88
  ## Version 9
66
89
 
90
+ ### v9.4.0
91
+
92
+ - Feature #875, proposed by [@VideoSystemsTech](https://github.com/VideoSystemsTech).
93
+ - Ability to document the API specification keeping the schemas organized within named components.
94
+ - `OpenAPI::constructor()` is equipped with a new optional property `composition` that can be:
95
+ - `inline` (default) — schemas are depicted directly in a place of their usage;
96
+ - `components` (feature) — schemas are depicted within the `components` section and have references by their names.
97
+
98
+ ```ts
99
+ // example usage
100
+ new OpenAPI({
101
+ routing,
102
+ config,
103
+ version: "1.2.3",
104
+ title: "My API",
105
+ serverUrl: "https://example.com",
106
+ composition: "components", // <——
107
+ }).getSpecAsYaml();
108
+ ```
109
+
110
+ ### v9.3.1
111
+
112
+ - Hotfix for the feature #856
113
+ - `$ref` is equipped with the required prefix: `#/components/schemas/`.
114
+
115
+ ```yaml
116
+ before:
117
+ $ref: 2048581c137c5b2130eb860e3ae37da196dfc25b
118
+ after:
119
+ $ref: "#/components/schemas/2048581c137c5b2130eb860e3ae37da196dfc25b"
120
+ ```
121
+
122
+ ### v9.3.0
123
+
124
+ - Feature #856, proposed by [@TheWisestOne](https://github.com/TheWisestOne) in discussion #801.
125
+ - Supporting `z.lazy()` in the documentation generator (OpenAPI), including circular schemas.
126
+ - The feature is only available for the OpenAPI generator, it's not available for the client generator yet.
127
+ - OpenAPI references are utilized in order to limit the possible recursion.
128
+ - A new optional property added to the constructor of the OpenAPI class:
129
+ - `serializer` is the function that accepts a schema and returns its unique identifier in order to compare them.
130
+ - When omitted, the default one used, which is `JSON.stringify()` + `SHA1` hash as a `hex` digest.
131
+ - If/when it's not enough precise, consider specifying your own implementation.
132
+
133
+ ```yaml
134
+ # having z.lazy() within your IO schema
135
+ before:
136
+ error: Zod type ZodLazy is unsupported
137
+ after:
138
+ schema:
139
+ type: object
140
+ properties:
141
+ lazyProperty:
142
+ $ref: 2048581c137c5b2130eb860e3ae37da196dfc25b # sample reference
143
+ components:
144
+ schemas:
145
+ 2048581c137c5b2130eb860e3ae37da196dfc25b:
146
+ type: array
147
+ items:
148
+ $ref: 2048581c137c5b2130eb860e3ae37da196dfc25b # circular reference
149
+ ```
150
+
67
151
  ### v9.2.1
68
152
 
69
153
  - `zod` version is 3.21.4.
package/README.md CHANGED
@@ -811,7 +811,11 @@ Consuming the generated client requires Typescript version 4.1 or higher.
811
811
  import fs from "fs";
812
812
  import { Client } from "express-zod-api";
813
813
 
814
- fs.writeFileSync("./frontend/client.ts", new Client(routing).print(), "utf-8");
814
+ fs.writeFileSync(
815
+ "./frontend/client.ts",
816
+ new Client({ routing }).print(),
817
+ "utf-8"
818
+ );
815
819
  ```
816
820
 
817
821
  ```typescript
@@ -847,6 +851,7 @@ const yamlString = new OpenAPI({
847
851
  version: "1.2.3",
848
852
  title: "Example API",
849
853
  serverUrl: "https://example.com",
854
+ composition: "inline", // optional, or "components" for keeping schemas in a separate dedicated section using refs
850
855
  }).getSpecAsYaml();
851
856
  ```
852
857
 
package/SECURITY.md CHANGED
@@ -21,6 +21,6 @@
21
21
  Found a vulnerability or other security issue?
22
22
 
23
23
  Please urgently inform me privately by
24
- [email](https://github.com/RobinTail/express-zod-api/blob/master/package.json#L121).
24
+ [email](https://github.com/RobinTail/express-zod-api/blob/master/package.json#L122).
25
25
 
26
26
  I will try to fix it as soon as possible.
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var Or=(e,r,t)=>{if(!r.has(e))throw TypeError("Cannot "+t)};var A=(e,r,t)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,t)};var E=(e,r,t)=>(Or(e,r,"access private method"),t);var Rt={silent:!0,warn:!0,debug:!0},br=e=>e;import{z as N}from"zod";import{HttpError as zr}from"http-errors";import{z as T}from"zod";import{clone as Pr,mergeDeepRight as Er}from"ramda";var O="expressZodApiMeta",Zr=e=>{let r=e.constructor,t=Pr(e._def);return t[O]=t[O]||{examples:[]},new r(t)},$=e=>{let r=Zr(e);return Object.defineProperties(r,{example:{get:()=>t=>{let o=$(r);return o._def[O].examples.push(t),o}}}),r},At=e=>O in e._def?typeof e._def[O]=="object"&&e._def[O]!==null:!1;function Se(e,r){if(!At(e))return;let t=e._def;return r in t[O]?t[O][r]:void 0}var Oe=(e,r)=>{if(!At(e))return r;let t=$(r),o=te(t._def[O].examples,e._def[O].examples);if(t._def[O].examples=[],o.type==="single")t._def[O].examples=o.value;else for(let[n,i]of o.value)t._def[O].examples.push(Er({...n},{...i}));return t};import Rr from"mime";var j=Rr.getType("json")||"application/json",re="multipart/form-data";import{INVALID as Ar,OK as Ir,ZodIssueCode as Cr,ZodParsedType as Mr,ZodType as Nr,addIssueToContext as wr}from"zod";var Dr="ZodUpload",vr=e=>typeof e=="object"&&e!==null&&"name"in e&&"encoding"in e&&"mimetype"in e&&"data"in e&&"tempFilePath"in e&&"truncated"in e&&"size"in e&&"md5"in e&&"mv"in e&&typeof e.name=="string"&&typeof e.mimetype=="string"&&typeof e.data=="object"&&typeof e.tempFilePath=="string"&&typeof e.truncated=="boolean"&&typeof e.size=="number"&&typeof e.md5=="string"&&typeof e.mv=="function",Ge=class extends Nr{_parse(r){let{ctx:t}=this._processInputParams(r);return t.parsedType!==Mr.object||!vr(t.data)?(wr(t,{code:Cr.custom,message:`Expected file upload, received ${t.parsedType}`}),Ar):Ir(t.data)}},L=Ge;L.create=()=>new Ge({typeName:Dr});var qe=/:([A-Za-z0-9_]+)/g;function jr(e){let t=(e.header("content-type")||"").slice(0,re.length).toLowerCase()===re;return"files"in e&&t}var be={get:["query","params"],post:["body","params","files"],put:["body","params"],patch:["body","params"],delete:["query","params"]},Lr=["body","query","params"],Ve=e=>e.method.toLowerCase();function It(e,r){let t=Ve(e);if(t==="options")return{};let o=Lr;return t in be&&(o=be[t]),r&&t in r&&(o=r[t]||o),o.filter(n=>n==="files"?jr(e):!0).reduce((n,i)=>({...n,...e[i]}),{})}function Be(e){return typeof e=="object"&&"level"in e&&"color"in e&&Object.keys(Rt).includes(e.level)&&typeof e.color=="boolean"}function Pe(e){return!isNaN(e.getTime())}function ne(e){return e instanceof Error?e:new Error(typeof e=="symbol"?e.toString():`${e}`)}function k(e){return e instanceof T.ZodError?e.issues.map(({path:r,message:t})=>(r.length?[r.join("/")]:[]).concat(t).join(": ")).join("; "):e instanceof U?`output${e.originalError.issues[0]?.path.length>0?"/":": "}${e.message}`:e.message}function Ye(e){return e instanceof zr?e.statusCode:e instanceof C?400:500}var Ee=(e,r)=>{let t=Se(e,"examples");return t===void 0?[]:t.reduce((o,n)=>{let i=e.safeParse(n);return o.concat(i.success?r?i.data:n:[])},[])},te=(e,r)=>{if(e.length===0)return{type:"single",value:r};if(r.length===0)return{type:"single",value:e};let t=[];for(let o of e)for(let n of r)t.push([o,n]);return{type:"tuple",value:t}};function Je(e){let r=e.match(qe);return r?r.map(t=>t.slice(1)):[]}var oe=e=>e.reduce((r,t)=>r||t,!1);function I(e){return e instanceof T.ZodEffects&&e._def.effect.type!=="refinement"?!0:e instanceof T.ZodUnion?oe(e.options.map(I)):e instanceof T.ZodIntersection?oe([e._def.left,e._def.right].map(I)):!1}function Z(e){return e instanceof L?!0:e instanceof T.ZodObject?oe(Object.values(e.shape).map(Z)):e instanceof T.ZodUnion?oe(e.options.map(Z)):e instanceof T.ZodIntersection?oe([e._def.left,e._def.right].map(Z)):e instanceof T.ZodOptional||e instanceof T.ZodNullable?Z(e.unwrap()):e instanceof T.ZodEffects||e instanceof T.ZodTransformer?Z(e._def.schema):e instanceof T.ZodRecord?Z(e._def.valueType):e instanceof T.ZodArray?Z(e._def.type):e instanceof T.ZodDefault?Z(e._def.innerType):!1}var ie=e=>"coerce"in e._def&&typeof e._def.coerce=="boolean"?e._def.coerce:!1,se=(e,r,t)=>[r].concat(e.split("/")).concat(t||[]).flatMap(o=>o.split(/[^A-Z0-9]/gi)).map(o=>o.slice(0,1).toUpperCase()+o.slice(1).toLowerCase()).join(""),Ze=({effect:e,sample:r})=>{try{return typeof e.transform(r,{addIssue:()=>{},path:[]})}catch{return}},We=e=>typeof e=="string"?{message:e}:e||{};var G=class extends Error{constructor(){super(...arguments);this.name="RoutingError"}},ae=class extends G{constructor(){super(...arguments);this.name="DependsOnMethodError"}},b=class extends Error{constructor(){super(...arguments);this.name="OpenAPIError"}},M=class extends Error{constructor(){super(...arguments);this.name="IOSchemaError"}},U=class extends M{constructor(t){super(k(t));this.name="OutputValidationError";this.originalError=t}},C=class extends M{constructor(t){super(k(t));this.name="InputValidationError";this.originalError=t}},q=class extends Error{constructor(t,o){super(t);this.name="ResultHandlerError";this.originalError=o||void 0}};var R=e=>typeof e=="object"&&e!==null,Re=e=>({and:e.reduce((r,t)=>r.concat(R(t)&&"and"in t?t.and:t),[])}),Ae=(e,r)=>{if(R(e)){if("and"in e)return{and:e.and.map(t=>R(t)&&"or"in t?{or:t.or.map(r)}:r(t))};if("or"in e)return{or:e.or.map(t=>R(t)&&"and"in t?{and:t.and.map(r)}:r(t))}}return r(e)},Qe=e=>e.and.reduce((r,t)=>{let o=te(r.or,R(t)&&"or"in t?t.or:[t]);return o.type==="single"?r.or.push(...o.value):r.or=o.value.map(Re),r},{or:[]}),V=(e,r)=>{if(R(e)){if("and"in e){if(R(r)){if("and"in r)return Re([e,r]);if("or"in r)return V(Qe(e),r)}return Re([e,r])}if("or"in e){if(R(r)){if("and"in r)return V(r,e);if("or"in r){let t=te(e.or,r.or);return{or:t.type==="single"?t.value:t.value.map(Re)}}}return V(e,{and:[r]})}}return R(r)&&("and"in r||"or"in r)?V(r,e):{and:[e,r]}};import{z as B}from"zod";var Y={positive:200,negative:400},Ct=e=>e,J=Ct({getPositiveResponse:e=>{let r=Se(e,"examples")||[],t=$(B.object({status:B.literal("success"),data:e}));return r.reduce((o,n)=>o.example({status:"success",data:n}),t)},getNegativeResponse:()=>$(B.object({status:B.literal("error"),error:B.object({message:B.string()})})).example({status:"error",error:{message:k(new Error("Sample error message"))}}),handler:({error:e,input:r,output:t,request:o,response:n,logger:i})=>{if(!e){n.status(Y.positive).json({status:"success",data:t});return}let a=Ye(e);a===500&&i.error(`Internal server error
1
+ var Zr=(e,r,t)=>{if(!r.has(e))throw TypeError("Cannot "+t)};var M=(e,r,t)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,t)};var R=(e,r,t)=>(Zr(e,r,"access private method"),t);var Ct={silent:!0,warn:!0,debug:!0},Er=e=>e;import{z as v}from"zod";import{HttpError as Ur}from"http-errors";import{z as S}from"zod";import{clone as Ar,mergeDeepRight as Ir}from"ramda";var O="expressZodApiMeta",Cr=e=>{let r=e.constructor,t=Ar(e._def);return t[O]=t[O]||{examples:[]},new r(t)},G=e=>{let r=Cr(e);return Object.defineProperties(r,{example:{get:()=>t=>{let o=G(r);return o._def[O].examples.push(t),o}}}),r},Mt=e=>O in e._def?typeof e._def[O]=="object"&&e._def[O]!==null:!1;function Oe(e,r){if(!Mt(e))return;let t=e._def;return r in t[O]?t[O][r]:void 0}var be=(e,r)=>{if(!Mt(e))return r;let t=G(r),o=ne(t._def[O].examples,e._def[O].examples);if(t._def[O].examples=[],o.type==="single")t._def[O].examples=o.value;else for(let[n,s]of o.value)t._def[O].examples.push(Ir({...n},{...s}));return t};import Mr from"mime";var U=Mr.getType("json")||"application/json",se="multipart/form-data";import{INVALID as Nr,OK as wr,ZodIssueCode as Dr,ZodParsedType as vr,ZodType as zr,addIssueToContext as jr}from"zod";var Lr="ZodUpload",kr=e=>typeof e=="object"&&e!==null&&"name"in e&&"encoding"in e&&"mimetype"in e&&"data"in e&&"tempFilePath"in e&&"truncated"in e&&"size"in e&&"md5"in e&&"mv"in e&&typeof e.name=="string"&&typeof e.mimetype=="string"&&typeof e.data=="object"&&typeof e.tempFilePath=="string"&&typeof e.truncated=="boolean"&&typeof e.size=="number"&&typeof e.md5=="string"&&typeof e.mv=="function",Ve=class extends zr{_parse(r){let{ctx:t}=this._processInputParams(r);return t.parsedType!==vr.object||!kr(t.data)?(jr(t,{code:Dr.custom,message:`Expected file upload, received ${t.parsedType}`}),Nr):wr(t.data)}},H=Ve;H.create=()=>new Ve({typeName:Lr});var Be=/:([A-Za-z0-9_]+)/g;function Hr(e){let t=(e.header("content-type")||"").slice(0,se.length).toLowerCase()===se;return"files"in e&&t}var Pe={get:["query","params"],post:["body","params","files"],put:["body","params"],patch:["body","params"],delete:["query","params"]},Kr=["body","query","params"],Ye=e=>e.method.toLowerCase();function Nt(e,r){let t=Ye(e);if(t==="options")return{};let o=Kr;return t in Pe&&(o=Pe[t]),r&&t in r&&(o=r[t]||o),o.filter(n=>n==="files"?Hr(e):!0).reduce((n,s)=>({...n,...e[s]}),{})}function Je(e){return typeof e=="object"&&"level"in e&&"color"in e&&Object.keys(Ct).includes(e.level)&&typeof e.color=="boolean"}function Re(e){return!isNaN(e.getTime())}function ae(e){return e instanceof Error?e:new Error(typeof e=="symbol"?e.toString():`${e}`)}function K(e){return e instanceof S.ZodError?e.issues.map(({path:r,message:t})=>(r.length?[r.join("/")]:[]).concat(t).join(": ")).join("; "):e instanceof F?`output${e.originalError.issues[0]?.path.length>0?"/":": "}${e.message}`:e.message}function We(e){return e instanceof Ur?e.statusCode:e instanceof w?400:500}var Ze=(e,r)=>{let t=Oe(e,"examples");return t===void 0?[]:t.reduce((o,n)=>{let s=e.safeParse(n);return o.concat(s.success?r?s.data:n:[])},[])},ne=(e,r)=>{if(e.length===0)return{type:"single",value:r};if(r.length===0)return{type:"single",value:e};let t=[];for(let o of e)for(let n of r)t.push([o,n]);return{type:"tuple",value:t}};function Qe(e){let r=e.match(Be);return r?r.map(t=>t.slice(1)):[]}var ie=e=>e.reduce((r,t)=>r||t,!1);function N(e){return e instanceof S.ZodEffects&&e._def.effect.type!=="refinement"?!0:e instanceof S.ZodUnion?ie(e.options.map(N)):e instanceof S.ZodIntersection?ie([e._def.left,e._def.right].map(N)):!1}function Z(e){return e instanceof H?!0:e instanceof S.ZodObject?ie(Object.values(e.shape).map(Z)):e instanceof S.ZodUnion?ie(e.options.map(Z)):e instanceof S.ZodIntersection?ie([e._def.left,e._def.right].map(Z)):e instanceof S.ZodOptional||e instanceof S.ZodNullable?Z(e.unwrap()):e instanceof S.ZodEffects||e instanceof S.ZodTransformer?Z(e._def.schema):e instanceof S.ZodRecord?Z(e._def.valueType):e instanceof S.ZodArray?Z(e._def.type):e instanceof S.ZodDefault?Z(e._def.innerType):!1}var de=e=>"coerce"in e._def&&typeof e._def.coerce=="boolean"?e._def.coerce:!1,A=(e,r,t)=>[r].concat(e.split("/")).concat(t||[]).flatMap(o=>o.split(/[^A-Z0-9]/gi)).map(o=>o.slice(0,1).toUpperCase()+o.slice(1).toLowerCase()).join(""),Ee=({effect:e,sample:r})=>{try{return typeof e.transform(r,{addIssue:()=>{},path:[]})}catch{return}},Xe=e=>typeof e=="string"?{message:e}:e||{};var q=class extends Error{constructor(){super(...arguments);this.name="RoutingError"}},pe=class extends q{constructor(){super(...arguments);this.name="DependsOnMethodError"}},P=class extends Error{constructor(){super(...arguments);this.name="OpenAPIError"}},D=class extends Error{constructor(){super(...arguments);this.name="IOSchemaError"}},F=class extends D{constructor(t){super(K(t));this.name="OutputValidationError";this.originalError=t}},w=class extends D{constructor(t){super(K(t));this.name="InputValidationError";this.originalError=t}},V=class extends Error{constructor(t,o){super(t);this.name="ResultHandlerError";this.originalError=o||void 0}};var I=e=>typeof e=="object"&&e!==null,Ae=e=>({and:e.reduce((r,t)=>r.concat(I(t)&&"and"in t?t.and:t),[])}),Ie=(e,r)=>{if(I(e)){if("and"in e)return{and:e.and.map(t=>I(t)&&"or"in t?{or:t.or.map(r)}:r(t))};if("or"in e)return{or:e.or.map(t=>I(t)&&"and"in t?{and:t.and.map(r)}:r(t))}}return r(e)},et=e=>e.and.reduce((r,t)=>{let o=ne(r.or,I(t)&&"or"in t?t.or:[t]);return o.type==="single"?r.or.push(...o.value):r.or=o.value.map(Ae),r},{or:[]}),B=(e,r)=>{if(I(e)){if("and"in e){if(I(r)){if("and"in r)return Ae([e,r]);if("or"in r)return B(et(e),r)}return Ae([e,r])}if("or"in e){if(I(r)){if("and"in r)return B(r,e);if("or"in r){let t=ne(e.or,r.or);return{or:t.type==="single"?t.value:t.value.map(Ae)}}}return B(e,{and:[r]})}}return I(r)&&("and"in r||"or"in r)?B(r,e):{and:[e,r]}};import{z as Y}from"zod";var J={positive:200,negative:400},wt=e=>e,W=wt({getPositiveResponse:e=>{let r=Oe(e,"examples")||[],t=G(Y.object({status:Y.literal("success"),data:e}));return r.reduce((o,n)=>o.example({status:"success",data:n}),t)},getNegativeResponse:()=>G(Y.object({status:Y.literal("error"),error:Y.object({message:Y.string()})})).example({status:"error",error:{message:K(new Error("Sample error message"))}}),handler:({error:e,input:r,output:t,request:o,response:n,logger:s})=>{if(!e){n.status(J.positive).json({status:"success",data:t});return}let a=We(e);a===500&&s.error(`Internal server error
2
2
  ${e.stack}
3
- `,{url:o.url,payload:r}),n.status(a).json({status:"error",error:{message:k(e)}})}}),Ie=({error:e,logger:r,response:t})=>{r.error(`Result handler failure: ${e.message}.`),t.status(500).end(`An error occurred while serving the result: ${e.message}.`+(e.originalError?`
4
- Original error: ${e.originalError.message}.`:""))};var Mt=(e,r=[j])=>{if(e instanceof N.ZodType)return r;let{mimeTypes:t,mimeType:o}=e;return o?[o]:t||r},W=class{},Me,Nt,Ne,wt,we,Dt,De,vt,ve,zt,Ce=class extends W{constructor({middlewares:t,inputSchema:o,outputSchema:n,handler:i,resultHandler:a,description:d,shortDescription:l,...c}){super();A(this,Me);A(this,Ne);A(this,we);A(this,De);A(this,ve);this.methods=[];this.siblingMethods=[];this.middlewares=[];this.scopes=[];this.tags=[];[{name:"input schema",schema:o},{name:"output schema",schema:n}].forEach(({name:u,schema:g})=>{if(I(g))throw new M(`Using transformations on the top level of endpoint ${u} is not allowed.`)}),this.middlewares=t;let p={positive:a.getPositiveResponse(n),negative:a.getNegativeResponse()};this.mimeTypes={input:Z(o)?[re]:[j],positive:Mt(p.positive),negative:Mt(p.negative)},this.schemas={input:o,output:n,positive:p.positive instanceof N.ZodType?p.positive:p.positive.schema,negative:p.negative instanceof N.ZodType?p.negative:p.negative.schema},this.statusCodes={positive:p.positive instanceof N.ZodType?Y.positive:p.positive.statusCode||Y.positive,negative:p.negative instanceof N.ZodType?Y.negative:p.negative.statusCode||Y.negative},this.handler=i,this.resultHandler=a,this.descriptions={long:d,short:l},"scopes"in c&&c.scopes&&this.scopes.push(...c.scopes),"scope"in c&&c.scope&&this.scopes.push(c.scope),"tags"in c&&c.tags&&this.tags.push(...c.tags),"tag"in c&&c.tag&&this.tags.push(c.tag),"methods"in c?this.methods=c.methods:this.methods=[c.method]}_setSiblingMethods(t){this.siblingMethods=t}getDescription(t){return this.descriptions[t]}getMethods(){return this.methods}getSchema(t){return this.schemas[t]}getMimeTypes(t){return this.mimeTypes[t]}getStatusCode(t){return this.statusCodes[t]}getSecurity(){return this.middlewares.reduce((t,o)=>o.security?V(t,o.security):t,{and:[]})}getScopes(){return this.scopes}getTags(){return this.tags}async execute({request:t,response:o,logger:n,config:i}){let a=Ve(t),d,l=null;if(i.cors){let p=E(this,Me,Nt).call(this);typeof i.cors=="function"&&(p=await i.cors({request:t,logger:n,endpoint:this,defaultHeaders:p}));for(let u in p)o.set(u,p[u])}let c=It(t,i.inputSources);try{let{options:p,isStreamClosed:u}=await E(this,we,Dt).call(this,{method:a,input:c,request:t,response:o,logger:n});if(u)return;if(a==="options"){o.status(200).end();return}d=await E(this,Ne,wt).call(this,await E(this,De,vt).call(this,{input:c,options:p,logger:n}))}catch(p){l=ne(p)}await E(this,ve,zt).call(this,{input:c,output:d,request:t,response:o,error:l,logger:n})}};Me=new WeakSet,Nt=function(){return{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":this.methods.concat(this.siblingMethods).concat("options").join(", ").toUpperCase(),"Access-Control-Allow-Headers":"content-type"}},Ne=new WeakSet,wt=async function(t){try{return await this.schemas.output.parseAsync(t)}catch(o){throw o instanceof N.ZodError?new U(o):o}},we=new WeakSet,Dt=async function({method:t,input:o,request:n,response:i,logger:a}){let d={},l=!1;for(let c of this.middlewares){if(t==="options"&&c.type==="proprietary")continue;let p;try{p=await c.input.parseAsync(o)}catch(u){throw u instanceof N.ZodError?new C(u):u}if(Object.assign(d,await c.middleware({input:p,options:d,request:n,response:i,logger:a})),l="writableEnded"in i&&i.writableEnded,l){a.warn(`The middleware ${c.middleware.name} has closed the stream. Accumulated options:`,d);break}}return{options:d,isStreamClosed:l}},De=new WeakSet,vt=async function({input:t,options:o,logger:n}){let i;try{i=await this.schemas.input.parseAsync(t)}catch(a){throw a instanceof N.ZodError?new C(a):a}return this.handler({input:i,options:o,logger:n})},ve=new WeakSet,zt=async function({error:t,request:o,response:n,logger:i,input:a,output:d}){try{await this.resultHandler.handler({error:t,output:d,request:o,response:n,logger:i,input:a})}catch(l){Ie({logger:i,response:n,error:new q(ne(l).message,t)})}};var jt=["get","post","put","delete","patch"];import{z as kt}from"zod";var Lt=(e,r)=>{let t=e.map(({input:n})=>n).concat(r),o=t.reduce((n,i)=>n.and(i));return t.reduce((n,i)=>Oe(i,n),o)};var Xe=e=>{if(I(e.input))throw new M("Using transformations on the top level of middleware input schema is not allowed.");return{...e,type:"proprietary"}};var X,ze,Q=class{constructor(r){this.middlewares=[];this.use=this.addExpressMiddleware;this.resultHandler="resultHandler"in r?r.resultHandler:r}addMiddleware(r){var t;return E(t=Q,X,ze).call(t,this.middlewares.concat(r),this.resultHandler)}addExpressMiddleware(r,t){var a;let o=t?.transformer||(d=>d),n=t?.provider||(()=>({})),i={type:"express",input:kt.object({}),middleware:async({request:d,response:l})=>new Promise((c,p)=>{r(d,l,g=>{if(g&&g instanceof Error)return p(o(g));c(n(d,l))})})};return E(a=Q,X,ze).call(a,this.middlewares.concat(i),this.resultHandler)}addOptions(r){var t;return E(t=Q,X,ze).call(t,this.middlewares.concat(Xe({input:kt.object({}),middleware:async()=>r})),this.resultHandler)}build({input:r,handler:t,output:o,...n}){let{middlewares:i,resultHandler:a}=this;return new Ce({handler:t,middlewares:i,outputSchema:o,resultHandler:a,inputSchema:Lt(i,r),...n})}},de=Q;X=new WeakSet,ze=function(r,t){let o=new Q(t);return o.middlewares=r,o},A(de,X);var kr=new de(J);import{inspect as Ur}from"util";import{LEVEL as Hr,MESSAGE as Kr,SPLAT as Fr}from"triple-beam";import je from"winston";var{combine:_r,colorize:$r,timestamp:Gr,printf:qr}=je.format;function Le(e){let r=i=>{let{[Hr]:a,[Kr]:d,[Fr]:l,...c}=i;return Ur(c,!1,1,e.color)},t=i=>qr(({timestamp:a,message:d,level:l,durationMs:c,...p})=>(typeof d=="object"&&(p={...p,...d},d="[No message]"),`${a} ${l}: ${d}`+(c===void 0?"":` duration: ${c}ms`)+(Object.keys(p).length===0?"":" "+(i?r(p):JSON.stringify(p))))),o=[Gr()],n={handleExceptions:!0};switch(e.color&&o.push($r()),e.level){case"debug":n.level="debug",o.push(t(!0));break;case"silent":case"warn":default:n.level="warn",o.push(t())}return n.format=_r(...o),je.createLogger({silent:e.level==="silent",levels:je.config.npm.levels,transports:[new je.transports.Console(n)],exitOnError:!1})}var pe=class{constructor(r){this.methods=r;Object.keys(r).forEach(t=>{if(t in r&&!(r[t]?.getMethods()||[]).includes(t))throw new ae(`The endpoint assigned to the '${t}' parameter must have at least this method in its specification.
3
+ `,{url:o.url,payload:r}),n.status(a).json({status:"error",error:{message:K(e)}})}}),Ce=({error:e,logger:r,response:t})=>{r.error(`Result handler failure: ${e.message}.`),t.status(500).end(`An error occurred while serving the result: ${e.message}.`+(e.originalError?`
4
+ Original error: ${e.originalError.message}.`:""))};var Dt=(e,r=[U])=>{if(e instanceof v.ZodType)return r;let{mimeTypes:t,mimeType:o}=e;return o?[o]:t||r},Q=class{},Ne,vt,we,zt,De,jt,ve,Lt,ze,kt,Me=class extends Q{constructor({middlewares:t,inputSchema:o,outputSchema:n,handler:s,resultHandler:a,description:d,shortDescription:l,...p}){super();M(this,Ne);M(this,we);M(this,De);M(this,ve);M(this,ze);this.methods=[];this.siblingMethods=[];this.middlewares=[];this.scopes=[];this.tags=[];[{name:"input schema",schema:o},{name:"output schema",schema:n}].forEach(({name:f,schema:h})=>{if(N(h))throw new D(`Using transformations on the top level of endpoint ${f} is not allowed.`)}),this.middlewares=t;let c={positive:a.getPositiveResponse(n),negative:a.getNegativeResponse()};this.mimeTypes={input:Z(o)?[se]:[U],positive:Dt(c.positive),negative:Dt(c.negative)},this.schemas={input:o,output:n,positive:c.positive instanceof v.ZodType?c.positive:c.positive.schema,negative:c.negative instanceof v.ZodType?c.negative:c.negative.schema},this.statusCodes={positive:c.positive instanceof v.ZodType?J.positive:c.positive.statusCode||J.positive,negative:c.negative instanceof v.ZodType?J.negative:c.negative.statusCode||J.negative},this.handler=s,this.resultHandler=a,this.descriptions={long:d,short:l},"scopes"in p&&p.scopes&&this.scopes.push(...p.scopes),"scope"in p&&p.scope&&this.scopes.push(p.scope),"tags"in p&&p.tags&&this.tags.push(...p.tags),"tag"in p&&p.tag&&this.tags.push(p.tag),"methods"in p?this.methods=p.methods:this.methods=[p.method]}_setSiblingMethods(t){this.siblingMethods=t}getDescription(t){return this.descriptions[t]}getMethods(){return this.methods}getSchema(t){return this.schemas[t]}getMimeTypes(t){return this.mimeTypes[t]}getStatusCode(t){return this.statusCodes[t]}getSecurity(){return this.middlewares.reduce((t,o)=>o.security?B(t,o.security):t,{and:[]})}getScopes(){return this.scopes}getTags(){return this.tags}async execute({request:t,response:o,logger:n,config:s}){let a=Ye(t),d,l=null;if(s.cors){let c=R(this,Ne,vt).call(this);typeof s.cors=="function"&&(c=await s.cors({request:t,logger:n,endpoint:this,defaultHeaders:c}));for(let f in c)o.set(f,c[f])}let p=Nt(t,s.inputSources);try{let{options:c,isStreamClosed:f}=await R(this,De,jt).call(this,{method:a,input:p,request:t,response:o,logger:n});if(f)return;if(a==="options"){o.status(200).end();return}d=await R(this,we,zt).call(this,await R(this,ve,Lt).call(this,{input:p,options:c,logger:n}))}catch(c){l=ae(c)}await R(this,ze,kt).call(this,{input:p,output:d,request:t,response:o,error:l,logger:n})}};Ne=new WeakSet,vt=function(){return{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":this.methods.concat(this.siblingMethods).concat("options").join(", ").toUpperCase(),"Access-Control-Allow-Headers":"content-type"}},we=new WeakSet,zt=async function(t){try{return await this.schemas.output.parseAsync(t)}catch(o){throw o instanceof v.ZodError?new F(o):o}},De=new WeakSet,jt=async function({method:t,input:o,request:n,response:s,logger:a}){let d={},l=!1;for(let p of this.middlewares){if(t==="options"&&p.type==="proprietary")continue;let c;try{c=await p.input.parseAsync(o)}catch(f){throw f instanceof v.ZodError?new w(f):f}if(Object.assign(d,await p.middleware({input:c,options:d,request:n,response:s,logger:a})),l="writableEnded"in s&&s.writableEnded,l){a.warn(`The middleware ${p.middleware.name} has closed the stream. Accumulated options:`,d);break}}return{options:d,isStreamClosed:l}},ve=new WeakSet,Lt=async function({input:t,options:o,logger:n}){let s;try{s=await this.schemas.input.parseAsync(t)}catch(a){throw a instanceof v.ZodError?new w(a):a}return this.handler({input:s,options:o,logger:n})},ze=new WeakSet,kt=async function({error:t,request:o,response:n,logger:s,input:a,output:d}){try{await this.resultHandler.handler({error:t,output:d,request:o,response:n,logger:s,input:a})}catch(l){Ce({logger:s,response:n,error:new V(ae(l).message,t)})}};var Ut=["get","post","put","delete","patch"];import{z as Kt}from"zod";var Ht=(e,r)=>{let t=e.map(({input:n})=>n).concat(r),o=t.reduce((n,s)=>n.and(s));return t.reduce((n,s)=>be(s,n),o)};var tt=e=>{if(N(e.input))throw new D("Using transformations on the top level of middleware input schema is not allowed.");return{...e,type:"proprietary"}};var ee,je,X=class{constructor(r){this.middlewares=[];this.use=this.addExpressMiddleware;this.resultHandler="resultHandler"in r?r.resultHandler:r}addMiddleware(r){var t;return R(t=X,ee,je).call(t,this.middlewares.concat(r),this.resultHandler)}addExpressMiddleware(r,t){var a;let o=t?.transformer||(d=>d),n=t?.provider||(()=>({})),s={type:"express",input:Kt.object({}),middleware:async({request:d,response:l})=>new Promise((p,c)=>{r(d,l,h=>{if(h&&h instanceof Error)return c(o(h));p(n(d,l))})})};return R(a=X,ee,je).call(a,this.middlewares.concat(s),this.resultHandler)}addOptions(r){var t;return R(t=X,ee,je).call(t,this.middlewares.concat(tt({input:Kt.object({}),middleware:async()=>r})),this.resultHandler)}build({input:r,handler:t,output:o,...n}){let{middlewares:s,resultHandler:a}=this;return new Me({handler:t,middlewares:s,outputSchema:o,resultHandler:a,inputSchema:Ht(s,r),...n})}},ce=X;ee=new WeakSet,je=function(r,t){let o=new X(t);return o.middlewares=r,o},M(ce,ee);var Fr=new ce(W);import{inspect as $r}from"util";import{LEVEL as _r,MESSAGE as Gr,SPLAT as qr}from"triple-beam";import Le from"winston";var{combine:Vr,colorize:Br,timestamp:Yr,printf:Jr}=Le.format;function ke(e){let r=s=>{let{[_r]:a,[Gr]:d,[qr]:l,...p}=s;return $r(p,!1,1,e.color)},t=s=>Jr(({timestamp:a,message:d,level:l,durationMs:p,...c})=>(typeof d=="object"&&(c={...c,...d},d="[No message]"),`${a} ${l}: ${d}`+(p===void 0?"":` duration: ${p}ms`)+(Object.keys(c).length===0?"":" "+(s?r(c):JSON.stringify(c))))),o=[Yr()],n={handleExceptions:!0};switch(e.color&&o.push(Br()),e.level){case"debug":n.level="debug",o.push(t(!0));break;case"silent":case"warn":default:n.level="warn",o.push(t())}return n.format=Vr(...o),Le.createLogger({silent:e.level==="silent",levels:Le.config.npm.levels,transports:[new Le.transports.Console(n)],exitOnError:!1})}var le=class{constructor(r){this.methods=r;Object.keys(r).forEach(t=>{if(t in r&&!(r[t]?.getMethods()||[]).includes(t))throw new pe(`The endpoint assigned to the '${t}' parameter must have at least this method in its specification.
5
5
  This error should prevent mistakes during the development process.
6
6
  Example:
7
7
 
@@ -12,8 +12,8 @@ new ${this.constructor.name}({
12
12
  ...
13
13
  })
14
14
  });
15
- `)})}};import Vr from"express";var ce=class{constructor(...r){this.params=r}apply(r,t){return t(r,Vr.static(...this.params))}};var H=({routing:e,onEndpoint:r,onStatic:t,parentPath:o,hasCors:n})=>{Object.entries(e).forEach(([i,a])=>{if(i=i.trim(),i.match(/\//))throw new G(`Routing elements should not contain '/' character.
16
- The error caused by ${o?`'${o}' route that has a '${i}'`:`'${i}'`} entry.`);let d=`${o||""}${i?`/${i}`:""}`;if(a instanceof W){let l=a.getMethods().slice();n&&l.push("options"),l.forEach(c=>{r(a,d,c)})}else if(a instanceof ce)t&&a.apply(d,t);else if(a instanceof pe){if(Object.entries(a.methods).forEach(([l,c])=>{r(c,d,l)}),n&&Object.keys(a.methods).length>0){let[l,...c]=Object.keys(a.methods),p=a.methods[l];p._setSiblingMethods(c),r(p,d,"options")}}else H({onEndpoint:r,onStatic:t,hasCors:n,routing:a,parentPath:d})})};var Ut=()=>`
15
+ `)})}};import Wr from"express";var me=class{constructor(...r){this.params=r}apply(r,t){return t(r,Wr.static(...this.params))}};var $=({routing:e,onEndpoint:r,onStatic:t,parentPath:o,hasCors:n})=>{Object.entries(e).forEach(([s,a])=>{if(s=s.trim(),s.match(/\//))throw new q(`Routing elements should not contain '/' character.
16
+ The error caused by ${o?`'${o}' route that has a '${s}'`:`'${s}'`} entry.`);let d=`${o||""}${s?`/${s}`:""}`;if(a instanceof Q){let l=a.getMethods().slice();n&&l.push("options"),l.forEach(p=>{r(a,d,p)})}else if(a instanceof me)t&&a.apply(d,t);else if(a instanceof le){if(Object.entries(a.methods).forEach(([l,p])=>{r(p,d,l)}),n&&Object.keys(a.methods).length>0){let[l,...p]=Object.keys(a.methods),c=a.methods[l];c._setSiblingMethods(p),r(c,d,"options")}}else $({onEndpoint:r,onStatic:t,hasCors:n,routing:a,parentPath:d})})};var Ft=()=>`
17
17
  \x1B[94m\x1B[39m
18
18
  \x1B[94m\x1B[39m
19
19
  \x1B[94m8888888888 8888888888P 888 d8888 8888888b. 8888888 \x1B[39m
@@ -30,7 +30,7 @@ The error caused by ${o?`'${o}' route that has a '${i}'`:`'${i}'`} entry.`);let
30
30
  \x1B[90m\x1B[3m Thank you for choosing Express Zod API for your project.\x1B[23m\x1B[39m\x1B[0m\x1B[0m
31
31
  \x1B[0m\x1B[0m
32
32
  \x1B[0m\x1B[0m
33
- `.trim();var et=({app:e,logger:r,config:t,routing:o})=>{t.startupLogo!==!1&&console.log(Ut()),H({routing:o,hasCors:!!t.cors,onEndpoint:(n,i,a)=>{e[a](i,async(d,l)=>{r.info(`${d.method}: ${i}`),await n.execute({request:d,response:l,logger:r,config:t})})},onStatic:(n,i)=>{e.use(n,i)}})};import Br,{json as Yr}from"express";import Jr from"compression";import Wr from"express-fileupload";import Qr from"https";import Xr from"http-errors";var eo=(e,r)=>(t,o,n,i)=>{if(!t)return i();e.handler({error:t,request:o,response:n,logger:r,input:o.body,output:null})},Ht=(e,r)=>(t,o)=>{let n=Xr(404,`Can not ${t.method} ${t.path}`);try{e.handler({request:t,response:o,logger:r,error:n,input:null,output:null})}catch(i){Ie({response:o,logger:r,error:new q(ne(i).message,n)})}};function to(e,r){let t=Be(e.logger)?Le(e.logger):e.logger;et({app:e.app,routing:r,logger:t,config:e});let o=e.errorHandler||J;return{notFoundHandler:Ht(o,t),logger:t}}function ro(e,r){let t=Be(e.logger)?Le(e.logger):e.logger,o=Br();o.disable("x-powered-by");let n=e.errorHandler||J,i=e.server.compression?Jr({...typeof e.server.compression=="object"?e.server.compression:{}}):void 0,a=e.server.jsonParser||Yr(),d=e.server.upload?Wr({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}):void 0,l=[].concat(i||[]).concat(a).concat(d||[]);o.use(l),o.use(eo(n,t)),et({app:o,routing:r,logger:t,config:e}),o.use(Ht(n,t));let c=o.listen(e.server.listen,()=>{t.info(`Listening ${e.server.listen}`)}),p;return e.https&&(p=Qr.createServer(e.https.options,o).listen(e.https.listen,()=>{t.info(`Listening ${e.https.listen}`)})),{app:o,httpServer:c,httpsServer:p,logger:t}}import{OpenApiBuilder as Fo}from"openapi3-ts";import{omit as ue}from"ramda";import{z as x}from"zod";import{INVALID as Kt,ZodIssueCode as tt,ZodParsedType as Ft,ZodType as oo,addIssueToContext as rt}from"zod";var ot=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?)?Z?$/,no="ZodDateIn",nt=class extends oo{_parse(r){let{status:t,ctx:o}=this._processInputParams(r);if(o.parsedType!==Ft.string)return rt(o,{code:tt.invalid_type,expected:Ft.string,received:o.parsedType}),Kt;ot.test(o.data)||(rt(o,{code:tt.invalid_string,validation:"regex"}),t.dirty());let n=new Date(o.data);return Pe(n)?{status:t.value,value:n}:(rt(o,{code:tt.invalid_date}),Kt)}},le=nt;le.create=()=>new nt({typeName:no});var K=({schema:e,onEach:r,rules:t,onMissing:o,...n})=>{let i=r&&r({schema:e,...n}),a="typeName"in e._def?t[e._def.typeName]:void 0,l=a?a({schema:e,...n,next:c=>K({...c,...n,onEach:r,rules:t,onMissing:o})}):o(e);return i?{...l,...i}:l};var _t=50,Gt="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:[]},qt=e=>e.replace(qe,r=>`{${r.slice(1)}}`),so=({schema:{_def:{innerType:e,defaultValue:r}},next:t})=>({...t({schema:e}),default:r()}),ao=({schema:{_def:{innerType:e}},next:r})=>r({schema:e}),po=()=>({format:"any"}),co=({isResponse:e})=>{if(e)throw new b("Please use z.upload() only for input.");return{type:"string",format:"binary"}},lo=({schema:{isBinary:e,isBase64:r},isResponse:t})=>{if(!t)throw new b("Please use z.file() only within ResultHandler.");return{type:"string",format:e?"binary":r?"byte":"file"}},mo=({schema:{options:e},next:r})=>({oneOf:e.map(t=>r({schema:t}))}),uo=({schema:{options:e,discriminator:r},next:t})=>({discriminator:{propertyName:r},oneOf:Array.from(e.values()).map(o=>t({schema:o}))}),fo=({schema:{_def:{left:e,right:r}},next:t})=>({allOf:[e,r].map(o=>t({schema:o}))}),yo=({schema:e,next:r})=>r({schema:e.unwrap()}),go=({schema:e,next:r})=>({nullable:!0,...r({schema:e.unwrap()})}),$t=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),xo=({schema:{value:e}})=>({type:typeof e,enum:[e]}),ho=({schema:e,isResponse:r,next:t})=>{let o=Object.keys(e.shape).filter(n=>{let i=e.shape[n];return!(r&&ie(i)?i instanceof x.ZodOptional:i.isOptional())});return{type:"object",properties:ke({schema:e,isResponse:r,next:t}),...o.length?{required:o}:{}}},To=()=>({type:"string",nullable:!0,format:"null"}),So=({isResponse:e})=>{if(e)throw new b("Please use z.dateOut() for output.");return{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:ot.source,externalDocs:{url:Gt}}},Oo=({isResponse:e})=>{if(!e)throw new b("Please use z.dateIn() for input.");return{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:Gt}}},bo=({isResponse:e})=>{throw new b(`Using z.date() within ${e?"output":"input"} schema is forbidden. Please use z.date${e?"Out":"In"}() instead. Check out the documentation for details.`)},Po=()=>({type:"boolean"}),Eo=()=>({type:"integer",format:"bigint"}),Zo=({schema:{keySchema:e,valueSchema:r},isResponse:t,next:o})=>{if(e instanceof x.ZodEnum||e instanceof x.ZodNativeEnum){let n=Object.values(e.enum),i=n.reduce((a,d)=>({...a,[d]:r}),{});return{type:"object",properties:ke({schema:x.object(i),isResponse:t,next:o}),...n.length?{required:n}:{}}}if(e instanceof x.ZodLiteral)return{type:"object",properties:ke({schema:x.object({[e.value]:r}),isResponse:t,next:o}),required:[e.value]};if(e instanceof x.ZodUnion&&e.options.reduce((i,a)=>i&&a instanceof x.ZodLiteral,!0)){let i=e.options.reduce((a,d)=>({...a,[d.value]:r}),{});return{type:"object",properties:ke({schema:x.object(i),isResponse:t,next:o}),required:e.options.map(a=>a.value)}}return{type:"object",additionalProperties:o({schema:r})}},Ro=({schema:{_def:e,element:r},next:t})=>({type:"array",items:t({schema:r}),...e.minLength!==null&&{minItems:e.minLength.value},...e.maxLength!==null&&{maxItems:e.maxLength.value}}),Ao=({schema:{items:e},next:r})=>{let t=e.map(o=>r({schema:o}));return{type:"array",minItems:t.length,maxItems:t.length,items:{oneOf:t,format:"tuple",...t.length>0&&{description:t.map((o,n)=>`${n}: ${o.type}`).join(", ")}}}},Io=({schema:{isEmail:e,isURL:r,minLength:t,maxLength:o,isUUID:n,isCUID:i,isCUID2:a,isULID:d,isIP:l,isEmoji:c,isDatetime:p,_def:{checks:u}}})=>{let g=u.find(S=>S.kind==="regex"),y=u.find(S=>S.kind==="datetime"),h=g?g.regex:y?y.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;return{type:"string",...p&&{format:"date-time"},...e&&{format:"email"},...r&&{format:"url"},...n&&{format:"uuid"},...i&&{format:"cuid"},...a&&{format:"cuid2"},...d&&{format:"ulid"},...l&&{format:"ip"},...c&&{format:"emoji"},...t!==null&&{minLength:t},...o!==null&&{maxLength:o},...h&&{pattern:`/${h.source}/${h.flags}`}}},Co=({schema:e})=>{let r=e._def.checks.find(({kind:i})=>i==="min"),t=r?r.inclusive:!0,o=e._def.checks.find(({kind:i})=>i==="max"),n=o?o.inclusive:!0;return{type:e.isInt?"integer":"number",format:e.isInt?"int64":"double",minimum:e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,exclusiveMinimum:!t,maximum:e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,exclusiveMaximum:!n}},ke=({schema:{shape:e},next:r})=>Object.keys(e).reduce((t,o)=>({...t,[o]:r({schema:e[o]})}),{}),Mo=e=>{let r=Array.isArray(e.type)?e.type[0]:e.type;return io?.[r]},No=({schema:e,isResponse:r,next:t})=>{let o=t({schema:e.innerType()}),{effect:n}=e._def;if(r&&n.type==="transform"){let i=Ze({effect:n,sample:Mo(o)});return i&&["number","string","boolean"].includes(i)?{type:i}:t({schema:x.any()})}if(!r&&n.type==="preprocess"){let{type:i,...a}=o;return{...a,format:`${a.format||i} (preprocessed)`}}return o},wo=({schema:e,isResponse:r,next:t})=>t({schema:e._def[r?"out":"in"]}),Do=({schema:e,next:r})=>r({schema:e.unwrap()}),Vt=(e,r,t=[])=>{let o=Ee(e,r);return o.length===0?{}:{examples:o.reduce((n,i,a)=>({...n,[`example${a+1}`]:{value:ue(t,i)}}),{})}},vo=(e,r,t)=>{let o=Ee(e,r);return o.length===0?{}:{examples:o.reduce((n,i,a)=>t in i?{...n,[`example${a+1}`]:{value:i[t]}}:n,{})}};function me(e){if(e instanceof x.ZodObject)return e;let r;if(e instanceof x.ZodUnion||e instanceof x.ZodDiscriminatedUnion)r=Array.from(e.options.values()).map(t=>me(t)).reduce((t,o)=>t.merge(o.partial()),x.object({}));else if(e instanceof x.ZodEffects){if(I(e))throw new b("Using transformations on the top level of input schema is not allowed.");r=me(e._def.schema)}else r=me(e._def.left).merge(me(e._def.right));return Oe(e,r)}var Bt=({path:e,method:r,endpoint:t,inputSources:o})=>{let n=t.getSchema("input"),i=me(n).shape,a=Je(e),d=o.includes("query"),l=o.includes("params"),c=p=>l&&a.includes(p);return Object.keys(i).filter(p=>d||c(p)).map(p=>({name:p,in:c(p)?"path":"query",required:!i[p].isOptional(),schema:{description:`${r.toUpperCase()} ${e} parameter`,...K({schema:i[p],isResponse:!1,rules:st,onEach:at,onMissing:dt})},...vo(n,!1,p)}))},st={ZodString:Io,ZodNumber:Co,ZodBigInt:Eo,ZodBoolean:Po,ZodDateIn:So,ZodDateOut:Oo,ZodNull:To,ZodArray:Ro,ZodTuple:Ao,ZodRecord:Zo,ZodObject:ho,ZodLiteral:xo,ZodIntersection:fo,ZodUnion:mo,ZodFile:lo,ZodUpload:co,ZodAny:po,ZodDefault:so,ZodEnum:$t,ZodNativeEnum:$t,ZodEffects:No,ZodOptional:yo,ZodNullable:go,ZodDiscriminatedUnion:uo,ZodBranded:Do,ZodDate:bo,ZodCatch:ao,ZodPipeline:wo},at=({schema:e,isResponse:r})=>{let{description:t}=e,o=Ee(e,r);return{...t&&{description:t},...e.isNullable()&&!(r&&ie(e))&&{nullable:!0},...o.length>0&&{example:o[0]}}},dt=e=>{throw new b(`Zod type ${e.constructor.name} is unsupported`)},it=(e,r)=>{let t=e.properties?ue(r,e.properties):void 0,o=e.example?ue(r,e.example):void 0,n=e.required?e.required.filter(d=>!r.includes(d)):void 0,i=e.allOf?e.allOf.map(d=>it(d,r)):void 0,a=e.oneOf?e.oneOf.map(d=>it(d,r)):void 0;return ue(Object.entries({properties:t,required:n,example:o,allOf:i,oneOf:a}).filter(([{},d])=>d===void 0).map(([d])=>d),{...e,properties:t,required:n,example:o,allOf:i,oneOf:a})},Yt=e=>ue(["example"],e),pt=({method:e,path:r,description:t,endpoint:o,isPositive:n})=>{let i=n?o.getSchema("positive"):o.getSchema("negative"),a=n?o.getMimeTypes("positive"):o.getMimeTypes("negative"),d=Yt(K({schema:i,isResponse:!0,rules:st,onEach:at,onMissing:dt})),l=Vt(i,!0);return{description:`${e.toUpperCase()} ${r} ${t}`,content:a.reduce((c,p)=>({...c,[p]:{schema:d,...l}}),{})}},zo=()=>({type:"http",scheme:"basic"}),jo=({format:e})=>({type:"http",scheme:"bearer",...e&&{bearerFormat:e}}),Lo=({name:e})=>({type:"apiKey",in:"query",name:e}),ko=({name:e})=>({type:"apiKey",in:"header",name:e}),Uo=({name:e})=>({type:"apiKey",in:"cookie",name:e}),Ho=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),Ko=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((r,t)=>{let o=e[t];if(!o)return r;let{scopes:n={},...i}=o;return{...r,[t]:{...i,scopes:n}}},{})}),Jt=e=>{let r={basic:zo,bearer:jo,input:Lo,header:ko,cookie:Uo,openid:Ho,oauth2:Ko};return Ae(e,t=>r[t.type](t))},Ue=e=>{if(typeof e=="object"){if("or"in e)return e.or.map(r=>("and"in r?r.and:[r]).reduce((t,{name:o,scopes:n})=>({...t,[o]:n}),{}));if("and"in e)return Ue(Qe(e))}return Ue({or:[e]})},Wt=({method:e,path:r,endpoint:t})=>{let o=Je(r),n=Yt(it(K({schema:t.getSchema("input"),isResponse:!1,rules:st,onEach:at,onMissing:dt}),o)),i=Vt(t.getSchema("input"),!1,o);return{content:t.getMimeTypes("input").reduce((a,d)=>({...a,[d]:{schema:{description:`${e.toUpperCase()} ${r} request body`,...n},...i}}),{})}},Qt=e=>Object.keys(e).map(r=>{let t=e[r];return{name:r,description:typeof t=="string"?t:t.description,...typeof t=="object"&&t.url&&{externalDocs:{url:t.url}}}}),ct=e=>e.length<=_t?e:e.slice(0,_t-1)+"\u2026";var lt=class extends Fo{constructor({routing:t,config:o,title:n,version:i,serverUrl:a,successfulResponseDescription:d="Successful response",errorResponseDescription:l="Error response",hasSummaryFromDescription:c=!0}){super();this.lastSecuritySchemaIds={};this.lastOperationIdSuffixes={};this.addInfo({title:n,version:i}).addServer({url:a}),H({routing:t,onEndpoint:(u,g,y)=>{let h=y,S={path:g,method:h,endpoint:u},[F,_]=["short","long"].map(u.getDescription.bind(u)),xe=o.inputSources?.[h]||be[h],he=Bt({...S,inputSources:xe}),P={operationId:this.ensureUniqOperationId(g,h),responses:{[u.getStatusCode("positive")]:pt({...S,description:d,isPositive:!0}),[u.getStatusCode("negative")]:pt({...S,description:l,isPositive:!1})}};_&&(P.description=_,c&&F===void 0&&(P.summary=ct(_))),F&&(P.summary=ct(F)),u.getTags().length>0&&(P.tags=u.getTags()),he.length>0&&(P.parameters=he),xe.includes("body")&&(P.requestBody=Wt(S));let Te=Ue(Ae(Jt(u.getSecurity()),$e=>{let Zt=this.ensureUniqSecuritySchemaName($e),Sr=["oauth2","openIdConnect"].includes($e.type)?u.getScopes():[];return this.addSecurityScheme(Zt,$e),{name:Zt,scopes:Sr}}));Te.length>0&&(P.security=Te);let Tr=qt(g);this.addPath(Tr,{[h]:P})}}),this.rootDoc.tags=o.tags?Qt(o.tags):[]}ensureUniqOperationId(t,o){let n=se(t,o);return n in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[n]++,`${n}${this.lastOperationIdSuffixes[n]}`):(this.lastOperationIdSuffixes[n]=1,n)}ensureUniqSecuritySchemaName(t){for(let o in this.rootDoc.components?.securitySchemes||{})if(JSON.stringify(t)===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]}`}};import Xt from"http";var _o=e=>({method:"GET",header:jest.fn(()=>j),...e}),$o=e=>{let r={writableEnded:!1,statusCode:200,statusMessage:Xt.STATUS_CODES[200],set:jest.fn(()=>r),status:jest.fn(t=>(r.statusCode=t,r.statusMessage=Xt.STATUS_CODES[t],r)),json:jest.fn(()=>r),end:jest.fn(()=>(r.writableEnded=!0,r)),...e};return r},Go=async({endpoint:e,requestProps:r,responseProps:t,configProps:o,loggerProps:n,__noJest:i})=>{if(!jest||i)throw new Error("You need to install Jest in order to use testEndpoint().");let a=_o(r),d=$o(t),l={info:jest.fn(),warn:jest.fn(),error:jest.fn(),debug:jest.fn(),...n},c={cors:!1,logger:l,...o};return await e.execute({request:a,response:d,config:c,logger:l}),{requestMock:a,responseMock:d,loggerMock:l}};import z from"typescript";import w from"typescript";var s=w.factory,ee=[s.createModifier(w.SyntaxKind.ExportKeyword)],qo=[s.createModifier(w.SyntaxKind.PublicKeyword),s.createModifier(w.SyntaxKind.ReadonlyKeyword)],er=[s.createModifier(w.SyntaxKind.ProtectedKeyword),s.createModifier(w.SyntaxKind.ReadonlyKeyword)],Vo=s.createTemplateHead(""),Bo=s.createTemplateTail(""),Yo=s.createTemplateMiddle(" "),mt=e=>s.createTemplateLiteralType(Vo,e.map((r,t)=>s.createTemplateLiteralTypeSpan(s.createTypeReferenceNode(r),t===e.length-1?Bo:Yo))),ut=mt(["M","P"]),He=(e,r,t)=>s.createParameterDeclaration(t,void 0,e,void 0,r),Ke=(e,r)=>Object.keys(e).reduce((t,o)=>t.concat(He(o,e[o],r)),[]),ft=(e,r)=>s.createExpressionWithTypeArguments(s.createIdentifier("Record"),[typeof e=="number"?s.createKeywordTypeNode(e):s.createTypeReferenceNode(e),s.createKeywordTypeNode(r)]),tr=e=>s.createConstructorDeclaration(void 0,e,s.createBlock([])),yt=(e,r)=>s.createPropertySignature(void 0,`"${e}"`,void 0,s.createTypeReferenceNode(r)),rr=(e,r)=>s.createVariableDeclarationList([s.createVariableDeclaration(e,void 0,void 0,r)],w.NodeFlags.Const),gt=(e,r)=>s.createTypeAliasDeclaration(ee,e,void 0,s.createUnionTypeNode(r.map(t=>s.createLiteralTypeNode(s.createStringLiteral(t))))),Fe=(e,r)=>s.createTypeAliasDeclaration(ee,e,void 0,r),or=(e,r,t)=>s.createPropertyDeclaration(qo,e,void 0,r,t),nr=(e,r,t=[])=>s.createClassDeclaration(ee,e,void 0,void 0,[r,...t]),ir=(e,r)=>s.createTypeReferenceNode("Promise",[s.createIndexedAccessTypeNode(s.createTypeReferenceNode(e),r)]),sr=()=>s.createTypeReferenceNode("Promise",[s.createKeywordTypeNode(w.SyntaxKind.AnyKeyword)]),xt=(e,r,t)=>s.createInterfaceDeclaration(ee,e,void 0,r,t),ar=e=>Object.keys(e).reduce((r,t)=>r.concat(s.createTypeParameterDeclaration([],t,s.createTypeReferenceNode(e[t]))),[]),dr=(e,r)=>s.createArrowFunction(void 0,void 0,e.map(t=>He(t)),void 0,void 0,s.createCallExpression(s.createPropertyAccessExpression(s.createThis(),"implementation"),void 0,r)),ht=(e,r,t)=>s.createCallExpression(s.createPropertyAccessExpression(s.createCallExpression(s.createPropertyAccessExpression(s.createIdentifier("Object"),"keys"),void 0,[s.createIdentifier(e)]),"reduce"),void 0,[s.createArrowFunction(void 0,void 0,Ke({acc:void 0,key:void 0}),void 0,void 0,r),t]);import f from"typescript";import{z as Wo}from"zod";import D from"typescript";var{factory:_e}=D,Tt=(e,r)=>{D.addSyntheticLeadingComment(e,D.SyntaxKind.MultiLineCommentTrivia,`* ${r} `,!0)},St=(e,r,t)=>{let o=_e.createTypeAliasDeclaration(void 0,_e.createIdentifier(r),void 0,e);return t&&Tt(o,t),o},pr=(e,r)=>{let t=D.createSourceFile("print.ts","",D.ScriptTarget.Latest,!1,D.ScriptKind.TS);return D.createPrinter(r).printNode(D.EmitHint.Unspecified,e,t)},Jo=/^[A-Za-z_$][A-Za-z0-9_$]*$/,cr=e=>Jo.test(e)?_e.createIdentifier(e):_e.createStringLiteral(e);var{factory:m}=f,Qo={[f.SyntaxKind.AnyKeyword]:"",[f.SyntaxKind.BigIntKeyword]:BigInt(0),[f.SyntaxKind.BooleanKeyword]:!1,[f.SyntaxKind.NumberKeyword]:0,[f.SyntaxKind.ObjectKeyword]:{},[f.SyntaxKind.StringKeyword]:"",[f.SyntaxKind.UndefinedKeyword]:void 0},Xo=({schema:{value:e}})=>m.createLiteralTypeNode(typeof e=="number"?m.createNumericLiteral(e):typeof e=="boolean"?e?m.createTrue():m.createFalse():m.createStringLiteral(e)),en=({schema:{shape:e},isResponse:r,next:t})=>{let o=Object.entries(e).map(([n,i])=>{let a=r&&ie(i)?i instanceof Wo.ZodOptional:i.isOptional(),d=m.createPropertySignature(void 0,cr(n),a?m.createToken(f.SyntaxKind.QuestionToken):void 0,t({schema:i}));return i.description&&Tt(d,i.description),d});return m.createTypeLiteralNode(o)},tn=({schema:{element:e},next:r})=>m.createArrayTypeNode(r({schema:e})),rn=({schema:{options:e}})=>m.createUnionTypeNode(e.map(r=>m.createLiteralTypeNode(m.createStringLiteral(r)))),lr=({schema:{options:e},next:r})=>m.createUnionTypeNode(e.map(t=>r({schema:t}))),on=e=>Qo?.[e.kind],nn=({schema:e,next:r,isResponse:t})=>{let o=r({schema:e.innerType()}),n=e._def.effect;if(t&&n.type==="transform"){let i=Ze({effect:n,sample:on(o)}),a={number:f.SyntaxKind.NumberKeyword,bigint:f.SyntaxKind.BigIntKeyword,boolean:f.SyntaxKind.BooleanKeyword,string:f.SyntaxKind.StringKeyword,undefined:f.SyntaxKind.UndefinedKeyword,object:f.SyntaxKind.ObjectKeyword};return m.createKeywordTypeNode(i&&a[i]||f.SyntaxKind.AnyKeyword)}return o},sn=({schema:e})=>m.createUnionTypeNode(Object.values(e.enum).map(r=>m.createLiteralTypeNode(typeof r=="number"?m.createNumericLiteral(r):m.createStringLiteral(r)))),an=({next:e,schema:r})=>m.createUnionTypeNode([e({schema:r.unwrap()}),m.createKeywordTypeNode(f.SyntaxKind.UndefinedKeyword)]),dn=({next:e,schema:r})=>m.createUnionTypeNode([e({schema:r.unwrap()}),m.createLiteralTypeNode(m.createNull())]),pn=({next:e,schema:{items:r}})=>m.createTupleTypeNode(r.map(t=>e({schema:t}))),cn=({next:e,schema:{keySchema:r,valueSchema:t}})=>m.createExpressionWithTypeArguments(m.createIdentifier("Record"),[e({schema:r}),e({schema:t})]),ln=({next:e,schema:r})=>m.createIntersectionTypeNode([r._def.left,r._def.right].map(t=>e({schema:t}))),mn=({next:e,schema:r})=>e({schema:r._def.innerType}),v=e=>()=>m.createKeywordTypeNode(e),un=({next:e,schema:r})=>e({schema:r.unwrap()}),fn=({next:e,schema:r})=>e({schema:r._def.innerType}),yn=({schema:e,next:r,isResponse:t})=>r({schema:e._def[t?"out":"in"]}),gn=()=>m.createLiteralTypeNode(m.createNull()),xn={ZodString:v(f.SyntaxKind.StringKeyword),ZodNumber:v(f.SyntaxKind.NumberKeyword),ZodBigInt:v(f.SyntaxKind.BigIntKeyword),ZodBoolean:v(f.SyntaxKind.BooleanKeyword),ZodDateIn:v(f.SyntaxKind.StringKeyword),ZodDateOut:v(f.SyntaxKind.StringKeyword),ZodNull:gn,ZodArray:tn,ZodTuple:pn,ZodRecord:cn,ZodObject:en,ZodLiteral:Xo,ZodIntersection:ln,ZodUnion:lr,ZodFile:v(f.SyntaxKind.StringKeyword),ZodAny:v(f.SyntaxKind.AnyKeyword),ZodDefault:mn,ZodEnum:rn,ZodNativeEnum:sn,ZodEffects:nn,ZodOptional:an,ZodNullable:dn,ZodDiscriminatedUnion:lr,ZodBranded:un,ZodCatch:fn,ZodPipeline:yn},Ot=({schema:e,...r})=>K({schema:e,rules:xn,onMissing:()=>m.createKeywordTypeNode(f.SyntaxKind.AnyKeyword),...r});var bt=class{constructor(r){this.agg=[];this.registry={};this.paths=[];H({routing:r,onEndpoint:(y,h,S)=>{let F=se(h,S,"input"),_=se(h,S,"response"),xe=Ot({schema:y.getSchema("input"),isResponse:!1}),he=Ot({isResponse:!0,schema:y.getSchema("positive").or(y.getSchema("negative"))}),P=St(xe,F),Te=St(he,_);this.agg.push(P),this.agg.push(Te),S!=="options"&&(this.paths.push(h),this.registry[`${S} ${h}`]={in:F,out:_,isJson:y.getMimeTypes("positive").includes(j)})}});let t=gt("Path",this.paths),o=gt("Method",jt),n=Fe("MethodPath",mt([o.name,t.name])),i=[s.createHeritageClause(z.SyntaxKind.ExtendsKeyword,[ft(n.name,z.SyntaxKind.AnyKeyword)])],a=xt("Input",i,Object.keys(this.registry).map(y=>yt(y,this.registry[y].in))),d=xt("Response",i,Object.keys(this.registry).map(y=>yt(y,this.registry[y].out))),l=s.createVariableStatement(ee,rr("jsonEndpoints",s.createObjectLiteralExpression(Object.keys(this.registry).filter(y=>this.registry[y].isJson).map(y=>s.createPropertyAssignment(`"${y}"`,s.createTrue()))))),c=Fe("Provider",s.createFunctionTypeNode(ar({M:o.name,P:t.name}),Ke({method:s.createTypeReferenceNode("M"),path:s.createTypeReferenceNode("P"),params:s.createIndexedAccessTypeNode(s.createTypeReferenceNode(a.name),ut)}),ir(d.name,ut))),p=Fe("Implementation",s.createFunctionTypeNode(void 0,Ke({method:s.createTypeReferenceNode(o.name),path:s.createKeywordTypeNode(z.SyntaxKind.StringKeyword),params:ft(z.SyntaxKind.StringKeyword,z.SyntaxKind.AnyKeyword)}),sr())),u=s.createTemplateExpression(s.createTemplateHead(":"),[s.createTemplateSpan(s.createIdentifier("key"),s.createTemplateTail(""))]),g=nr("ExpressZodAPIClient",tr([He("implementation",s.createTypeReferenceNode(p.name),er)]),[or("provide",s.createTypeReferenceNode(c.name),dr(["method","path","params"],[s.createIdentifier("method"),ht("params",s.createCallExpression(s.createPropertyAccessExpression(s.createIdentifier("acc"),"replace"),void 0,[u,s.createElementAccessExpression(s.createIdentifier("params"),s.createIdentifier("key"))]),s.createIdentifier("path")),ht("params",s.createConditionalExpression(s.createBinaryExpression(s.createCallExpression(s.createPropertyAccessExpression(s.createIdentifier("path"),"indexOf"),void 0,[u]),z.SyntaxKind.GreaterThanEqualsToken,s.createNumericLiteral(0)),void 0,s.createIdentifier("acc"),void 0,s.createObjectLiteralExpression([s.createSpreadAssignment(s.createIdentifier("acc")),s.createPropertyAssignment("[key]",s.createElementAccessExpression(s.createIdentifier("params"),s.createIdentifier("key")))])),s.createObjectLiteralExpression())]))]);z.addSyntheticLeadingComment(g,z.SyntaxKind.MultiLineCommentTrivia,`
33
+ `.trim();var rt=({app:e,logger:r,config:t,routing:o})=>{t.startupLogo!==!1&&console.log(Ft()),$({routing:o,hasCors:!!t.cors,onEndpoint:(n,s,a)=>{e[a](s,async(d,l)=>{r.info(`${d.method}: ${s}`),await n.execute({request:d,response:l,logger:r,config:t})})},onStatic:(n,s)=>{e.use(n,s)}})};import Qr,{json as Xr}from"express";import eo from"compression";import to from"express-fileupload";import ro from"https";import oo from"http-errors";var no=(e,r)=>(t,o,n,s)=>{if(!t)return s();e.handler({error:t,request:o,response:n,logger:r,input:o.body,output:null})},$t=(e,r)=>(t,o)=>{let n=oo(404,`Can not ${t.method} ${t.path}`);try{e.handler({request:t,response:o,logger:r,error:n,input:null,output:null})}catch(s){Ce({response:o,logger:r,error:new V(ae(s).message,n)})}};function so(e,r){let t=Je(e.logger)?ke(e.logger):e.logger;rt({app:e.app,routing:r,logger:t,config:e});let o=e.errorHandler||W;return{notFoundHandler:$t(o,t),logger:t}}function io(e,r){let t=Je(e.logger)?ke(e.logger):e.logger,o=Qr();o.disable("x-powered-by");let n=e.errorHandler||W,s=e.server.compression?eo({...typeof e.server.compression=="object"?e.server.compression:{}}):void 0,a=e.server.jsonParser||Xr(),d=e.server.upload?to({...typeof e.server.upload=="object"?e.server.upload:{},abortOnLimit:!1,parseNested:!0}):void 0,l=[].concat(s||[]).concat(a).concat(d||[]);o.use(l),o.use(no(n,t)),rt({app:o,routing:r,logger:t,config:e}),o.use($t(n,t));let p=o.listen(e.server.listen,()=>{t.info(`Listening ${e.server.listen}`)}),c;return e.https&&(c=ro.createServer(e.https.options,o).listen(e.https.listen,()=>{t.info(`Listening ${e.https.listen}`)})),{app:o,httpServer:p,httpsServer:c,logger:t}}import{OpenApiBuilder as Yo}from"openapi3-ts";import{createHash as co}from"crypto";import{isReferenceObject as lo,isSchemaObject as He}from"openapi3-ts";import{omit as ye}from"ramda";import{z as T}from"zod";import{INVALID as _t,ZodIssueCode as ot,ZodParsedType as Gt,ZodType as ao,addIssueToContext as nt}from"zod";var st=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?)?Z?$/,po="ZodDateIn",it=class extends ao{_parse(r){let{status:t,ctx:o}=this._processInputParams(r);if(o.parsedType!==Gt.string)return nt(o,{code:ot.invalid_type,expected:Gt.string,received:o.parsedType}),_t;st.test(o.data)||(nt(o,{code:ot.invalid_string,validation:"regex"}),t.dirty());let n=new Date(o.data);return Re(n)?{status:t.value,value:n}:(nt(o,{code:ot.invalid_date}),_t)}},ue=it;ue.create=()=>new it({typeName:po});var _=({schema:e,onEach:r,rules:t,onMissing:o,...n})=>{let s=r&&r({schema:e,...n}),a="typeName"in e._def?t[e._def.typeName]:void 0,l=a?a({schema:e,...n,next:p=>_({...p,...n,onEach:r,rules:t,onMissing:o})}):o(e);return s?{...l,...s}:l};var qt=50,Bt="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",mo={integer:0,number:0,string:"",boolean:!1,object:{},null:null,array:[]},Yt=e=>e.replace(Be,r=>`{${r.slice(1)}}`),uo=({schema:{_def:{innerType:e,defaultValue:r}},next:t})=>({...t({schema:e}),default:r()}),fo=({schema:{_def:{innerType:e}},next:r})=>r({schema:e}),yo=()=>({format:"any"}),go=({isResponse:e})=>{if(e)throw new P("Please use z.upload() only for input.");return{type:"string",format:"binary"}},ho=({schema:{isBinary:e,isBase64:r},isResponse:t})=>{if(!t)throw new P("Please use z.file() only within ResultHandler.");return{type:"string",format:e?"binary":r?"byte":"file"}},xo=({schema:{options:e},next:r})=>({oneOf:e.map(t=>r({schema:t}))}),To=({schema:{options:e,discriminator:r},next:t})=>({discriminator:{propertyName:r},oneOf:Array.from(e.values()).map(o=>t({schema:o}))}),So=({schema:{_def:{left:e,right:r}},next:t})=>({allOf:[e,r].map(o=>t({schema:o}))}),Oo=({schema:e,next:r})=>r({schema:e.unwrap()}),bo=({schema:e,next:r})=>({nullable:!0,...r({schema:e.unwrap()})}),Vt=({schema:e})=>({type:typeof Object.values(e.enum)[0],enum:Object.values(e.enum)}),Po=({schema:{value:e}})=>({type:typeof e,enum:[e]}),Ro=({schema:e,isResponse:r,...t})=>{let o=Object.keys(e.shape).filter(n=>{let s=e.shape[n];return!(r&&de(s)?s instanceof T.ZodOptional:s.isOptional())});return{type:"object",properties:Ue({schema:e,isResponse:r,...t}),...o.length?{required:o}:{}}},Zo=()=>({type:"string",nullable:!0,format:"null"}),Eo=({isResponse:e})=>{if(e)throw new P("Please use z.dateOut() for output.");return{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",pattern:st.source,externalDocs:{url:Bt}}},Ao=({isResponse:e})=>{if(!e)throw new P("Please use z.dateIn() for input.");return{description:"YYYY-MM-DDTHH:mm:ss.sssZ",type:"string",format:"date-time",externalDocs:{url:Bt}}},Io=({isResponse:e})=>{throw new P(`Using z.date() within ${e?"output":"input"} schema is forbidden. Please use z.date${e?"Out":"In"}() instead. Check out the documentation for details.`)},Co=()=>({type:"boolean"}),Mo=()=>({type:"integer",format:"bigint"}),No=({schema:{keySchema:e,valueSchema:r},...t})=>{if(e instanceof T.ZodEnum||e instanceof T.ZodNativeEnum){let o=Object.values(e.enum),n=o.reduce((s,a)=>({...s,[a]:r}),{});return{type:"object",properties:Ue({schema:T.object(n),...t}),...o.length?{required:o}:{}}}if(e instanceof T.ZodLiteral)return{type:"object",properties:Ue({schema:T.object({[e.value]:r}),...t}),required:[e.value]};if(e instanceof T.ZodUnion&&e.options.reduce((n,s)=>n&&s instanceof T.ZodLiteral,!0)){let n=e.options.reduce((s,a)=>({...s,[a.value]:r}),{});return{type:"object",properties:Ue({schema:T.object(n),...t}),required:e.options.map(s=>s.value)}}return{type:"object",additionalProperties:t.next({schema:r})}},wo=({schema:{_def:e,element:r},next:t})=>({type:"array",items:t({schema:r}),...e.minLength!==null&&{minItems:e.minLength.value},...e.maxLength!==null&&{maxItems:e.maxLength.value}}),Do=({schema:{items:e},next:r})=>{let t=e.map(o=>r({schema:o}));return{type:"array",minItems:t.length,maxItems:t.length,items:{oneOf:t,format:"tuple",...t.length>0&&{description:t.map((o,n)=>`${n}: ${He(o)?o.type:o.$ref}`).join(", ")}}}},vo=({schema:{isEmail:e,isURL:r,minLength:t,maxLength:o,isUUID:n,isCUID:s,isCUID2:a,isULID:d,isIP:l,isEmoji:p,isDatetime:c,_def:{checks:f}}})=>{let h=f.find(g=>g.kind==="regex"),m=f.find(g=>g.kind==="datetime"),x=h?h.regex:m?m.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;return{type:"string",...c&&{format:"date-time"},...e&&{format:"email"},...r&&{format:"url"},...n&&{format:"uuid"},...s&&{format:"cuid"},...a&&{format:"cuid2"},...d&&{format:"ulid"},...l&&{format:"ip"},...p&&{format:"emoji"},...t!==null&&{minLength:t},...o!==null&&{maxLength:o},...x&&{pattern:`/${x.source}/${x.flags}`}}},zo=({schema:e})=>{let r=e._def.checks.find(({kind:s})=>s==="min"),t=r?r.inclusive:!0,o=e._def.checks.find(({kind:s})=>s==="max"),n=o?o.inclusive:!0;return{type:e.isInt?"integer":"number",format:e.isInt?"int64":"double",minimum:e.minValue===null?e.isInt?Number.MIN_SAFE_INTEGER:Number.MIN_VALUE:e.minValue,exclusiveMinimum:!t,maximum:e.maxValue===null?e.isInt?Number.MAX_SAFE_INTEGER:Number.MAX_VALUE:e.maxValue,exclusiveMaximum:!n}},Ue=({schema:{shape:e},next:r})=>Object.keys(e).reduce((t,o)=>({...t,[o]:r({schema:e[o]})}),{}),jo=e=>{let r=Array.isArray(e.type)?e.type[0]:e.type;return mo?.[r]},Lo=({schema:e,isResponse:r,next:t})=>{let o=t({schema:e.innerType()}),{effect:n}=e._def;if(r&&n.type==="transform"&&He(o)){let s=Ee({effect:n,sample:jo(o)});return s&&["number","string","boolean"].includes(s)?{type:s}:t({schema:T.any()})}if(!r&&n.type==="preprocess"&&He(o)){let{type:s,...a}=o;return{...a,format:`${a.format||s} (preprocessed)`}}return o},ko=({schema:e,isResponse:r,next:t})=>t({schema:e._def[r?"out":"in"]}),Uo=({schema:e,next:r})=>r({schema:e.unwrap()}),Jt=e=>co("sha1").update(JSON.stringify(e),"utf8").digest("hex"),Ho=({next:e,schema:r,serializer:t,hasRef:o,makeRef:n})=>{let s=t(r.schema);if(o(s))return{$ref:`#/components/schemas/${s}`};let a=n(s,{});return n(s,e({schema:r.schema})),a},Wt=(e,r,t=[])=>{let o=Ze(e,r);return o.length===0?{}:{examples:o.reduce((n,s,a)=>({...n,[`example${a+1}`]:{value:ye(t,s)}}),{})}},Ko=(e,r,t)=>{let o=Ze(e,r);return o.length===0?{}:{examples:o.reduce((n,s,a)=>t in s?{...n,[`example${a+1}`]:{value:s[t]}}:n,{})}};function fe(e){if(e instanceof T.ZodObject)return e;let r;if(e instanceof T.ZodUnion||e instanceof T.ZodDiscriminatedUnion)r=Array.from(e.options.values()).map(t=>fe(t)).reduce((t,o)=>t.merge(o.partial()),T.object({}));else if(e instanceof T.ZodEffects){if(N(e))throw new P("Using transformations on the top level of input schema is not allowed.");r=fe(e._def.schema)}else r=fe(e._def.left).merge(fe(e._def.right));return be(e,r)}var Qt=({path:e,method:r,endpoint:t,inputSources:o,serializer:n,hasRef:s,makeRef:a,composition:d,clue:l="parameter"})=>{let p=t.getSchema("input"),c=fe(p).shape,f=Qe(e),h=o.includes("query"),m=o.includes("params"),x=g=>m&&f.includes(g);return Object.keys(c).filter(g=>h||x(g)).map(g=>{let b=_({schema:c[g],isResponse:!1,rules:dt,onEach:pt,onMissing:ct,serializer:n,hasRef:s,makeRef:a}),E=d==="components"?a(A(e,r,`${l} ${g}`),b):b;return{name:g,in:x(g)?"path":"query",required:!c[g].isOptional(),description:`${r.toUpperCase()} ${e} ${l}`,schema:E,...Ko(p,!1,g)}})},dt={ZodString:vo,ZodNumber:zo,ZodBigInt:Mo,ZodBoolean:Co,ZodDateIn:Eo,ZodDateOut:Ao,ZodNull:Zo,ZodArray:wo,ZodTuple:Do,ZodRecord:No,ZodObject:Ro,ZodLiteral:Po,ZodIntersection:So,ZodUnion:xo,ZodFile:ho,ZodUpload:go,ZodAny:yo,ZodDefault:uo,ZodEnum:Vt,ZodNativeEnum:Vt,ZodEffects:Lo,ZodOptional:Oo,ZodNullable:bo,ZodDiscriminatedUnion:To,ZodBranded:Uo,ZodDate:Io,ZodCatch:fo,ZodPipeline:ko,ZodLazy:Ho},pt=({schema:e,isResponse:r})=>{let{description:t}=e,o=e instanceof T.ZodLazy,n=o?[]:Ze(e,r);return{...t&&{description:t},...!o&&e.isNullable()&&!(r&&de(e))&&{nullable:!0},...n.length>0&&{example:n[0]}}},ct=e=>{throw new P(`Zod type ${e.constructor.name} is unsupported`)},at=(e,r)=>{if(lo(e))return e;let t=e.properties?ye(r,e.properties):void 0,o=e.example?ye(r,e.example):void 0,n=e.required?e.required.filter(d=>!r.includes(d)):void 0,s=e.allOf?e.allOf.map(d=>at(d,r)):void 0,a=e.oneOf?e.oneOf.map(d=>at(d,r)):void 0;return ye(Object.entries({properties:t,required:n,example:o,allOf:s,oneOf:a}).filter(([{},d])=>d===void 0).map(([d])=>d),{...e,properties:t,required:n,example:o,allOf:s,oneOf:a})},Xt=e=>He(e)?ye(["example"],e):e,lt=({method:e,path:r,endpoint:t,isPositive:o,serializer:n,hasRef:s,makeRef:a,composition:d,clue:l="response"})=>{let p=t.getSchema(o?"positive":"negative"),c=t.getMimeTypes(o?"positive":"negative"),f=Xt(_({schema:p,isResponse:!0,rules:dt,onEach:pt,onMissing:ct,serializer:n,hasRef:s,makeRef:a})),h=Wt(p,!0),m=d==="components"?a(A(r,e,l),f):f;return{description:`${e.toUpperCase()} ${r} ${l}`,content:c.reduce((x,g)=>({...x,[g]:{schema:m,...h}}),{})}},Fo=()=>({type:"http",scheme:"basic"}),$o=({format:e})=>({type:"http",scheme:"bearer",...e&&{bearerFormat:e}}),_o=({name:e})=>({type:"apiKey",in:"query",name:e}),Go=({name:e})=>({type:"apiKey",in:"header",name:e}),qo=({name:e})=>({type:"apiKey",in:"cookie",name:e}),Vo=({url:e})=>({type:"openIdConnect",openIdConnectUrl:e}),Bo=({flows:e={}})=>({type:"oauth2",flows:Object.keys(e).reduce((r,t)=>{let o=e[t];if(!o)return r;let{scopes:n={},...s}=o;return{...r,[t]:{...s,scopes:n}}},{})}),er=e=>{let r={basic:Fo,bearer:$o,input:_o,header:Go,cookie:qo,openid:Vo,oauth2:Bo};return Ie(e,t=>r[t.type](t))},Ke=e=>{if(typeof e=="object"){if("or"in e)return e.or.map(r=>("and"in r?r.and:[r]).reduce((t,{name:o,scopes:n})=>({...t,[o]:n}),{}));if("and"in e)return Ke(et(e))}return Ke({or:[e]})},tr=({method:e,path:r,endpoint:t,serializer:o,hasRef:n,makeRef:s,composition:a,clue:d="request body"})=>{let l=Qe(r),p=Xt(at(_({schema:t.getSchema("input"),isResponse:!1,rules:dt,onEach:pt,onMissing:ct,serializer:o,hasRef:n,makeRef:s}),l)),c=Wt(t.getSchema("input"),!1,l),f=a==="components"?s(A(r,e,d),p):p;return{description:`${e.toUpperCase()} ${r} ${d}`,content:t.getMimeTypes("input").reduce((h,m)=>({...h,[m]:{schema:f,...c}}),{})}},rr=e=>Object.keys(e).map(r=>{let t=e[r];return{name:r,description:typeof t=="string"?t:t.description,...typeof t=="object"&&t.url&&{externalDocs:{url:t.url}}}}),mt=e=>e.length<=qt?e:e.slice(0,qt-1)+"\u2026";var ut=class extends Yo{constructor({routing:t,config:o,title:n,version:s,serverUrl:a,successfulResponseDescription:d="Successful response",errorResponseDescription:l="Error response",hasSummaryFromDescription:p=!0,composition:c="inline",serializer:f=Jt}){super();this.lastSecuritySchemaIds={};this.lastOperationIdSuffixes={};this.addInfo({title:n,version:s}).addServer({url:a}),$({routing:t,onEndpoint:(m,x,g)=>{let b=g,E={path:x,method:b,endpoint:m,composition:c,serializer:f,hasRef:this.hasRef.bind(this),makeRef:this.makeRef.bind(this)},[re,oe]=["short","long"].map(m.getDescription.bind(m)),Te=o.inputSources?.[b]||Pe[b],Se=Qt({...E,inputSources:Te}),C={operationId:this.ensureUniqOperationId(x,b),responses:{[m.getStatusCode("positive")]:lt({...E,clue:d,isPositive:!0}),[m.getStatusCode("negative")]:lt({...E,clue:l,isPositive:!1})}};oe&&(C.description=oe,p&&re===void 0&&(C.summary=mt(oe))),re&&(C.summary=mt(re)),m.getTags().length>0&&(C.tags=m.getTags()),Se.length>0&&(C.parameters=Se),Te.includes("body")&&(C.requestBody=tr(E));let At=Ke(Ie(er(m.getSecurity()),qe=>{let It=this.ensureUniqSecuritySchemaName(qe),Rr=["oauth2","openIdConnect"].includes(qe.type)?m.getScopes():[];return this.addSecurityScheme(It,qe),{name:It,scopes:Rr}}));At.length>0&&(C.security=At);let Pr=Yt(x);this.addPath(Pr,{[b]:C})}}),this.rootDoc.tags=o.tags?rr(o.tags):[]}makeRef(t,o){return this.addSchema(t,o),{$ref:`#/components/schemas/${t}`}}hasRef(t){return t in(this.rootDoc.components?.schemas||{})}ensureUniqOperationId(t,o){let n=A(t,o);return n in this.lastOperationIdSuffixes?(this.lastOperationIdSuffixes[n]++,`${n}${this.lastOperationIdSuffixes[n]}`):(this.lastOperationIdSuffixes[n]=1,n)}ensureUniqSecuritySchemaName(t){let o=JSON.stringify(t);for(let n in this.rootDoc.components?.securitySchemes||{})if(o===JSON.stringify(this.rootDoc.components?.securitySchemes?.[n]))return n;return this.lastSecuritySchemaIds[t.type]=(this.lastSecuritySchemaIds?.[t.type]||0)+1,`${t.type.toUpperCase()}_${this.lastSecuritySchemaIds[t.type]}`}};import or from"http";var Jo=e=>({method:"GET",header:jest.fn(()=>U),...e}),Wo=e=>{let r={writableEnded:!1,statusCode:200,statusMessage:or.STATUS_CODES[200],set:jest.fn(()=>r),status:jest.fn(t=>(r.statusCode=t,r.statusMessage=or.STATUS_CODES[t],r)),json:jest.fn(()=>r),end:jest.fn(()=>(r.writableEnded=!0,r)),...e};return r},Qo=async({endpoint:e,requestProps:r,responseProps:t,configProps:o,loggerProps:n,__noJest:s})=>{if(!jest||s)throw new Error("You need to install Jest in order to use testEndpoint().");let a=Jo(r),d=Wo(t),l={info:jest.fn(),warn:jest.fn(),error:jest.fn(),debug:jest.fn(),...n},p={cors:!1,logger:l,...o};return await e.execute({request:a,response:d,config:p,logger:l}),{requestMock:a,responseMock:d,loggerMock:l}};import k from"typescript";import z from"typescript";var i=z.factory,te=[i.createModifier(z.SyntaxKind.ExportKeyword)],Xo=[i.createModifier(z.SyntaxKind.PublicKeyword),i.createModifier(z.SyntaxKind.ReadonlyKeyword)],nr=[i.createModifier(z.SyntaxKind.ProtectedKeyword),i.createModifier(z.SyntaxKind.ReadonlyKeyword)],en=i.createTemplateHead(""),tn=i.createTemplateTail(""),rn=i.createTemplateMiddle(" "),ft=e=>i.createTemplateLiteralType(en,e.map((r,t)=>i.createTemplateLiteralTypeSpan(i.createTypeReferenceNode(r),t===e.length-1?tn:rn))),yt=ft(["M","P"]),Fe=(e,r,t)=>i.createParameterDeclaration(t,void 0,e,void 0,r),$e=(e,r)=>Object.keys(e).reduce((t,o)=>t.concat(Fe(o,e[o],r)),[]),gt=(e,r)=>i.createExpressionWithTypeArguments(i.createIdentifier("Record"),[typeof e=="number"?i.createKeywordTypeNode(e):i.createTypeReferenceNode(e),i.createKeywordTypeNode(r)]),sr=e=>i.createConstructorDeclaration(void 0,e,i.createBlock([])),ht=(e,r)=>i.createPropertySignature(void 0,`"${e}"`,void 0,i.createTypeReferenceNode(r)),ir=(e,r)=>i.createVariableDeclarationList([i.createVariableDeclaration(e,void 0,void 0,r)],z.NodeFlags.Const),xt=(e,r)=>i.createTypeAliasDeclaration(te,e,void 0,i.createUnionTypeNode(r.map(t=>i.createLiteralTypeNode(i.createStringLiteral(t))))),_e=(e,r)=>i.createTypeAliasDeclaration(te,e,void 0,r),ar=(e,r,t)=>i.createPropertyDeclaration(Xo,e,void 0,r,t),dr=(e,r,t=[])=>i.createClassDeclaration(te,e,void 0,void 0,[r,...t]),pr=(e,r)=>i.createTypeReferenceNode("Promise",[i.createIndexedAccessTypeNode(i.createTypeReferenceNode(e),r)]),cr=()=>i.createTypeReferenceNode("Promise",[i.createKeywordTypeNode(z.SyntaxKind.AnyKeyword)]),Tt=(e,r,t)=>i.createInterfaceDeclaration(te,e,void 0,r,t),lr=e=>Object.keys(e).reduce((r,t)=>r.concat(i.createTypeParameterDeclaration([],t,i.createTypeReferenceNode(e[t]))),[]),mr=(e,r)=>i.createArrowFunction(void 0,void 0,e.map(t=>Fe(t)),void 0,void 0,i.createCallExpression(i.createPropertyAccessExpression(i.createThis(),"implementation"),void 0,r)),St=(e,r,t)=>i.createCallExpression(i.createPropertyAccessExpression(i.createCallExpression(i.createPropertyAccessExpression(i.createIdentifier("Object"),"keys"),void 0,[i.createIdentifier(e)]),"reduce"),void 0,[i.createArrowFunction(void 0,void 0,$e({acc:void 0,key:void 0}),void 0,void 0,r),t]);import y from"typescript";import{z as nn}from"zod";import j from"typescript";var{factory:Ge}=j,Ot=(e,r)=>{j.addSyntheticLeadingComment(e,j.SyntaxKind.MultiLineCommentTrivia,`* ${r} `,!0)},bt=(e,r,t)=>{let o=Ge.createTypeAliasDeclaration(void 0,Ge.createIdentifier(r),void 0,e);return t&&Ot(o,t),o},ur=(e,r)=>{let t=j.createSourceFile("print.ts","",j.ScriptTarget.Latest,!1,j.ScriptKind.TS);return j.createPrinter(r).printNode(j.EmitHint.Unspecified,e,t)},on=/^[A-Za-z_$][A-Za-z0-9_$]*$/,fr=e=>on.test(e)?Ge.createIdentifier(e):Ge.createStringLiteral(e);var{factory:u}=y,sn={[y.SyntaxKind.AnyKeyword]:"",[y.SyntaxKind.BigIntKeyword]:BigInt(0),[y.SyntaxKind.BooleanKeyword]:!1,[y.SyntaxKind.NumberKeyword]:0,[y.SyntaxKind.ObjectKeyword]:{},[y.SyntaxKind.StringKeyword]:"",[y.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)),dn=({schema:{shape:e},isResponse:r,next:t})=>{let o=Object.entries(e).map(([n,s])=>{let a=r&&de(s)?s instanceof nn.ZodOptional:s.isOptional(),d=u.createPropertySignature(void 0,fr(n),a?u.createToken(y.SyntaxKind.QuestionToken):void 0,t({schema:s}));return s.description&&Ot(d,s.description),d});return u.createTypeLiteralNode(o)},pn=({schema:{element:e},next:r})=>u.createArrayTypeNode(r({schema:e})),cn=({schema:{options:e}})=>u.createUnionTypeNode(e.map(r=>u.createLiteralTypeNode(u.createStringLiteral(r)))),yr=({schema:{options:e},next:r})=>u.createUnionTypeNode(e.map(t=>r({schema:t}))),ln=e=>sn?.[e.kind],mn=({schema:e,next:r,isResponse:t})=>{let o=r({schema:e.innerType()}),n=e._def.effect;if(t&&n.type==="transform"){let s=Ee({effect:n,sample:ln(o)}),a={number:y.SyntaxKind.NumberKeyword,bigint:y.SyntaxKind.BigIntKeyword,boolean:y.SyntaxKind.BooleanKeyword,string:y.SyntaxKind.StringKeyword,undefined:y.SyntaxKind.UndefinedKeyword,object:y.SyntaxKind.ObjectKeyword};return u.createKeywordTypeNode(s&&a[s]||y.SyntaxKind.AnyKeyword)}return o},un=({schema:e})=>u.createUnionTypeNode(Object.values(e.enum).map(r=>u.createLiteralTypeNode(typeof r=="number"?u.createNumericLiteral(r):u.createStringLiteral(r)))),fn=({next:e,schema:r})=>u.createUnionTypeNode([e({schema:r.unwrap()}),u.createKeywordTypeNode(y.SyntaxKind.UndefinedKeyword)]),yn=({next:e,schema:r})=>u.createUnionTypeNode([e({schema:r.unwrap()}),u.createLiteralTypeNode(u.createNull())]),gn=({next:e,schema:{items:r}})=>u.createTupleTypeNode(r.map(t=>e({schema:t}))),hn=({next:e,schema:{keySchema:r,valueSchema:t}})=>u.createExpressionWithTypeArguments(u.createIdentifier("Record"),[e({schema:r}),e({schema:t})]),xn=({next:e,schema:r})=>u.createIntersectionTypeNode([r._def.left,r._def.right].map(t=>e({schema:t}))),Tn=({next:e,schema:r})=>e({schema:r._def.innerType}),L=e=>()=>u.createKeywordTypeNode(e),Sn=({next:e,schema:r})=>e({schema:r.unwrap()}),On=({next:e,schema:r})=>e({schema:r._def.innerType}),bn=({schema:e,next:r,isResponse:t})=>r({schema:e._def[t?"out":"in"]}),Pn=()=>u.createLiteralTypeNode(u.createNull()),Rn={ZodString:L(y.SyntaxKind.StringKeyword),ZodNumber:L(y.SyntaxKind.NumberKeyword),ZodBigInt:L(y.SyntaxKind.BigIntKeyword),ZodBoolean:L(y.SyntaxKind.BooleanKeyword),ZodDateIn:L(y.SyntaxKind.StringKeyword),ZodDateOut:L(y.SyntaxKind.StringKeyword),ZodNull:Pn,ZodArray:pn,ZodTuple:gn,ZodRecord:hn,ZodObject:dn,ZodLiteral:an,ZodIntersection:xn,ZodUnion:yr,ZodFile:L(y.SyntaxKind.StringKeyword),ZodAny:L(y.SyntaxKind.AnyKeyword),ZodDefault:Tn,ZodEnum:cn,ZodNativeEnum:un,ZodEffects:mn,ZodOptional:fn,ZodNullable:yn,ZodDiscriminatedUnion:yr,ZodBranded:Sn,ZodCatch:On,ZodPipeline:bn},Pt=({schema:e,...r})=>_({schema:e,rules:Rn,onMissing:()=>u.createKeywordTypeNode(y.SyntaxKind.AnyKeyword),...r});var Rt=class{constructor({routing:r}){this.agg=[];this.registry={};this.paths=[];$({routing:r,onEndpoint:(m,x,g)=>{let b=A(x,g,"input"),E=A(x,g,"response"),re=Pt({schema:m.getSchema("input"),isResponse:!1}),oe=Pt({isResponse:!0,schema:m.getSchema("positive").or(m.getSchema("negative"))}),Te=bt(re,b),Se=bt(oe,E);this.agg.push(Te),this.agg.push(Se),g!=="options"&&(this.paths.push(x),this.registry[`${g} ${x}`]={in:b,out:E,isJson:m.getMimeTypes("positive").includes(U)})}});let t=xt("Path",this.paths),o=xt("Method",Ut),n=_e("MethodPath",ft([o.name,t.name])),s=[i.createHeritageClause(k.SyntaxKind.ExtendsKeyword,[gt(n.name,k.SyntaxKind.AnyKeyword)])],a=Tt("Input",s,Object.keys(this.registry).map(m=>ht(m,this.registry[m].in))),d=Tt("Response",s,Object.keys(this.registry).map(m=>ht(m,this.registry[m].out))),l=i.createVariableStatement(te,ir("jsonEndpoints",i.createObjectLiteralExpression(Object.keys(this.registry).filter(m=>this.registry[m].isJson).map(m=>i.createPropertyAssignment(`"${m}"`,i.createTrue()))))),p=_e("Provider",i.createFunctionTypeNode(lr({M:o.name,P:t.name}),$e({method:i.createTypeReferenceNode("M"),path:i.createTypeReferenceNode("P"),params:i.createIndexedAccessTypeNode(i.createTypeReferenceNode(a.name),yt)}),pr(d.name,yt))),c=_e("Implementation",i.createFunctionTypeNode(void 0,$e({method:i.createTypeReferenceNode(o.name),path:i.createKeywordTypeNode(k.SyntaxKind.StringKeyword),params:gt(k.SyntaxKind.StringKeyword,k.SyntaxKind.AnyKeyword)}),cr())),f=i.createTemplateExpression(i.createTemplateHead(":"),[i.createTemplateSpan(i.createIdentifier("key"),i.createTemplateTail(""))]),h=dr("ExpressZodAPIClient",sr([Fe("implementation",i.createTypeReferenceNode(c.name),nr)]),[ar("provide",i.createTypeReferenceNode(p.name),mr(["method","path","params"],[i.createIdentifier("method"),St("params",i.createCallExpression(i.createPropertyAccessExpression(i.createIdentifier("acc"),"replace"),void 0,[f,i.createElementAccessExpression(i.createIdentifier("params"),i.createIdentifier("key"))]),i.createIdentifier("path")),St("params",i.createConditionalExpression(i.createBinaryExpression(i.createCallExpression(i.createPropertyAccessExpression(i.createIdentifier("path"),"indexOf"),void 0,[f]),k.SyntaxKind.GreaterThanEqualsToken,i.createNumericLiteral(0)),void 0,i.createIdentifier("acc"),void 0,i.createObjectLiteralExpression([i.createSpreadAssignment(i.createIdentifier("acc")),i.createPropertyAssignment("[key]",i.createElementAccessExpression(i.createIdentifier("params"),i.createIdentifier("key")))])),i.createObjectLiteralExpression())]))]);k.addSyntheticLeadingComment(h,k.SyntaxKind.MultiLineCommentTrivia,`
34
34
  export const exampleImplementation: Implementation = async (
35
35
  method,
36
36
  path,
@@ -52,7 +52,7 @@ export const exampleImplementation: Implementation = async (
52
52
 
53
53
  const client = new ExpressZodAPIClient(exampleImplementation);
54
54
  client.provide("get", "/v1/user/retrieve", { id: "10" });
55
- `,!0),this.agg.push(t,o,n,a,d,l,c,p,g)}print(r){return this.agg.map(t=>pr(t,r)).join(`
55
+ `,!0),this.agg.push(t,o,n,a,d,l,p,c,h)}print(r){return this.agg.map(t=>ur(t,r)).join(`
56
56
 
57
- `)}};import{INVALID as mr,ZodIssueCode as ur,ZodParsedType as fr,ZodType as hn,addIssueToContext as yr}from"zod";var Tn="ZodDateOut",Pt=class extends hn{_parse(r){let{status:t,ctx:o}=this._processInputParams(r);return o.parsedType!==fr.date?(yr(o,{code:ur.invalid_type,expected:fr.date,received:o.parsedType}),mr):Pe(o.data)?{status:t.value,value:o.data.toISOString()}:(yr(o,{code:ur.invalid_date}),mr)}},fe=Pt;fe.create=()=>new Pt({typeName:Tn});import{INVALID as Sn,ZodIssueCode as gr,ZodParsedType as xr,ZodType as On,addIssueToContext as hr}from"zod";var bn="ZodFile",Pn=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ge=class extends On{constructor(){super(...arguments);this.binary=t=>new ge({...this._def,checks:[...this._def.checks,{kind:"binary",...We(t)}]});this.base64=t=>new ge({...this._def,checks:[...this._def.checks,{kind:"base64",...We(t)}]})}_parse(t){let{status:o,ctx:n}=this._processInputParams(t);if(n.parsedType!==xr.string)return hr(n,{code:gr.invalid_type,expected:xr.string,received:n.parsedType}),Sn;for(let i of this._def.checks)i.kind==="base64"&&(Pn.test(n.data)||(hr(n,{code:gr.custom,message:i.message}),o.dirty()));return{status:o.value,value:n.data}}get isBinary(){return!!this._def.checks.find(t=>t.kind==="binary")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}},ye=ge;ye.create=()=>new ge({checks:[],typeName:bn});var Et;(n=>(n.file=ye.create,n.upload=L.create,n.dateIn=le.create,n.dateOut=fe.create))(Et||(Et={}));import Ua from"http-errors";export{W as AbstractEndpoint,bt as Client,pe as DependsOnMethod,ae as DependsOnMethodError,de as EndpointsFactory,C as InputValidationError,lt as OpenAPI,b as OpenAPIError,U as OutputValidationError,G as RoutingError,ce as ServeStatic,to as attachRouting,br as createConfig,Ua as createHttpError,Le as createLogger,Xe as createMiddleware,Ct as createResultHandler,ro as createServer,kr as defaultEndpointsFactory,J as defaultResultHandler,Et as ez,k as getMessageFromError,Ye as getStatusCodeFromError,Go as testEndpoint,$ as withMeta};
57
+ `)}};import{INVALID as gr,ZodIssueCode as hr,ZodParsedType as xr,ZodType as Zn,addIssueToContext as Tr}from"zod";var En="ZodDateOut",Zt=class extends Zn{_parse(r){let{status:t,ctx:o}=this._processInputParams(r);return o.parsedType!==xr.date?(Tr(o,{code:hr.invalid_type,expected:xr.date,received:o.parsedType}),gr):Re(o.data)?{status:t.value,value:o.data.toISOString()}:(Tr(o,{code:hr.invalid_date}),gr)}},ge=Zt;ge.create=()=>new Zt({typeName:En});import{INVALID as An,ZodIssueCode as Sr,ZodParsedType as Or,ZodType as In,addIssueToContext as br}from"zod";var Cn="ZodFile",Mn=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,xe=class extends In{constructor(){super(...arguments);this.binary=t=>new xe({...this._def,checks:[...this._def.checks,{kind:"binary",...Xe(t)}]});this.base64=t=>new xe({...this._def,checks:[...this._def.checks,{kind:"base64",...Xe(t)}]})}_parse(t){let{status:o,ctx:n}=this._processInputParams(t);if(n.parsedType!==Or.string)return br(n,{code:Sr.invalid_type,expected:Or.string,received:n.parsedType}),An;for(let s of this._def.checks)s.kind==="base64"&&(Mn.test(n.data)||(br(n,{code:Sr.custom,message:s.message}),o.dirty()));return{status:o.value,value:n.data}}get isBinary(){return!!this._def.checks.find(t=>t.kind==="binary")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}},he=xe;he.create=()=>new xe({checks:[],typeName:Cn});var Et;(n=>(n.file=he.create,n.upload=H.create,n.dateIn=ue.create,n.dateOut=ge.create))(Et||(Et={}));import cd from"http-errors";export{Q as AbstractEndpoint,Rt as Client,le as DependsOnMethod,pe as DependsOnMethodError,ce as EndpointsFactory,w as InputValidationError,ut as OpenAPI,P as OpenAPIError,F as OutputValidationError,q as RoutingError,me as ServeStatic,so as attachRouting,Er as createConfig,cd as createHttpError,ke as createLogger,tt as createMiddleware,wt as createResultHandler,io as createServer,Fr as defaultEndpointsFactory,W as defaultResultHandler,Et as ez,K as getMessageFromError,We as getStatusCodeFromError,Qo as testEndpoint,G as withMeta};
58
58
  //# sourceMappingURL=index.js.map