express-zod-api 10.0.0-beta6 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Version 10
4
4
 
5
+ ### v10.0.0
6
+
7
+ - This release contains the fix from version 9.4.2.
8
+ - Read the release notes on beta versions for migration strategy from v9.
9
+
5
10
  ### v10.0.0-beta6
6
11
 
7
12
  - This release contains the fix from version 9.4.1.
@@ -91,6 +96,11 @@ const uploadSchema = ez.upload(); // namespace changed
91
96
 
92
97
  ## Version 9
93
98
 
99
+ ### v9.4.2
100
+
101
+ - Fixed issue #892, found and reported by [@McMerph](https://github.com/McMerph).
102
+ - Several examples for Array-Like schemas (`z.array()` and `z.tuple()`) used to be merged in the generated documentation due to the bug in `getExamples()` method.
103
+
94
104
  ### v9.4.1
95
105
 
96
106
  - Fixing the example implementation for the generated client in case of `DELETE` method.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
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
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=[],o=Oe(e,"examples");for(let n of o||[]){let s=e.safeParse(n);s.success&&t.push(r?s.data:n)}return t},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
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
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.