next-validations
Version:
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
2 lines • 570 B
JavaScript
import{assert as d}from"@typeschema/main";function p(t){return{async validate(e){return d(t,e)}}}function f({schema:t,mode:e="query"}){return m([{schema:t,mode:e}])}function m(t){return e=>async(r,i,n)=>{try{if(await Promise.all(t.map(async a=>{let s=p(a.schema),o=a.mode??"query";o==="query"?await s.validate(r.query):o==="body"?await s.validate(r.body):o==="headers"&&await s.validate(r.headers)})),n){n();return}if(e)return e(r,i);i.status(404).end()}catch(a){i.status(400).send(a)}}}export{f as withValidation,m as withValidations};
//# sourceMappingURL=index.js.map