UNPKG

next-validations

Version:

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

2 lines 1.08 kB
"use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of c(e))!f.call(t,a)&&a!==r&&p(t,a,{get:()=>e[a],enumerable:!(i=y(e,a))||i.enumerable});return t};var l=t=>x(p({},"__esModule",{value:!0}),t);var R={};h(R,{withValidation:()=>N,withValidations:()=>u});module.exports=l(R);var d=require("@typeschema/main");function m(t){return{async validate(e){return(0,d.assert)(t,e)}}}function N({schema:t,mode:e="query"}){return u([{schema:t,mode:e}])}function u(t){return e=>async(r,i,a)=>{try{if(await Promise.all(t.map(async s=>{let o=m(s.schema),n=s.mode??"query";n==="query"?await o.validate(r.query):n==="body"?await o.validate(r.body):n==="headers"&&await o.validate(r.headers)})),a){a();return}if(e)return e(r,i);i.status(404).end()}catch(s){i.status(400).send(s)}}}0&&(module.exports={withValidation,withValidations}); //# sourceMappingURL=index.js.map