UNPKG

decoval

Version:

DecoVal is a decorator-driven validation pattern that allows you to add validation rules directly to the properties of TypeScript classes, simplifying data control and increasing code readability and reusability.

21 lines (17 loc) 29.1 kB
var nt=Object.create;var Ve=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var ft=(o,n)=>()=>(n||o((n={exports:{}}).exports,n),n.exports);var ut=(o,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let f of it(n))!st.call(o,f)&&f!==r&&Ve(o,f,{get:()=>n[f],enumerable:!(i=at(n,f))||i.enumerable});return o};var lt=(o,n,r)=>(r=o!=null?nt(ot(o)):{},ut(n||!o||!o.__esModule?Ve(r,"default",{value:o,enumerable:!0}):r,o));var _e=ft(()=>{var xe;(function(o){(function(n){var r=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:b(),i=f(o);typeof r.Reflect<"u"&&(i=f(r.Reflect,i)),n(i,r),typeof r.Reflect>"u"&&(r.Reflect=o);function f(T,_){return function(O,x){Object.defineProperty(T,O,{configurable:!0,writable:!0,value:x}),_&&_(O,x)}}function m(){try{return Function("return this;")()}catch{}}function h(){try{return(0,eval)("(function() { return this; })()")}catch{}}function b(){return m()||h()}})(function(n,r){var i=Object.prototype.hasOwnProperty,f=typeof Symbol=="function",m=f&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",h=f&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",b=typeof Object.create=="function",T={__proto__:[]}instanceof Array,_=!b&&!T,O={create:b?function(){return de(Object.create(null))}:T?function(){return de({__proto__:null})}:function(){return de({})},has:_?function(e,t){return i.call(e,t)}:function(e,t){return t in e},get:_?function(e,t){return i.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},x=Object.getPrototypeOf(Function),$=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Ye(),F=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Ke(),I=typeof WeakMap=="function"?WeakMap:et(),j=f?Symbol.for("@reflect-metadata:registry"):void 0,v=Je(),z=Qe(v);function B(e,t,a,s){if(y(a)){if(!we(e))throw new TypeError;if(!ge(t))throw new TypeError;return R(e,t)}else{if(!we(e))throw new TypeError;if(!D(t))throw new TypeError;if(!D(s)&&!y(s)&&!X(s))throw new TypeError;return X(s)&&(s=void 0),a=H(a),C(e,t,a,s)}}n("decorate",B);function Z(e,t){function a(s,g){if(!D(s))throw new TypeError;if(!y(g)&&!ze(g))throw new TypeError;ne(e,t,s,g)}return a}n("metadata",Z);function J(e,t,a,s){if(!D(a))throw new TypeError;return y(s)||(s=H(s)),ne(e,t,a,s)}n("defineMetadata",J);function te(e,t,a){if(!D(t))throw new TypeError;return y(a)||(a=H(a)),fe(e,t,a)}n("hasMetadata",te);function q(e,t,a){if(!D(t))throw new TypeError;return y(a)||(a=H(a)),G(e,t,a)}n("hasOwnMetadata",q);function V(e,t,a){if(!D(t))throw new TypeError;return y(a)||(a=H(a)),re(e,t,a)}n("getMetadata",V);function N(e,t,a){if(!D(t))throw new TypeError;return y(a)||(a=H(a)),oe(e,t,a)}n("getOwnMetadata",N);function U(e,t){if(!D(e))throw new TypeError;return y(t)||(t=H(t)),ce(e,t)}n("getMetadataKeys",U);function L(e,t){if(!D(e))throw new TypeError;return y(t)||(t=H(t)),me(e,t)}n("getOwnMetadataKeys",L);function Q(e,t,a){if(!D(t))throw new TypeError;if(y(a)||(a=H(a)),!D(t))throw new TypeError;y(a)||(a=H(a));var s=ae(t,a,!1);return y(s)?!1:s.OrdinaryDeleteMetadata(e,t,a)}n("deleteMetadata",Q);function R(e,t){for(var a=e.length-1;a>=0;--a){var s=e[a],g=s(t);if(!y(g)&&!X(g)){if(!ge(g))throw new TypeError;t=g}}return t}function C(e,t,a,s){for(var g=e.length-1;g>=0;--g){var k=e[g],S=k(t,a,s);if(!y(S)&&!X(S)){if(!D(S))throw new TypeError;s=S}}return s}function fe(e,t,a){var s=G(e,t,a);if(s)return!0;var g=le(t);return X(g)?!1:fe(e,g,a)}function G(e,t,a){var s=ae(t,a,!1);return y(s)?!1:he(s.OrdinaryHasOwnMetadata(e,t,a))}function re(e,t,a){var s=G(e,t,a);if(s)return oe(e,t,a);var g=le(t);if(!X(g))return re(e,g,a)}function oe(e,t,a){var s=ae(t,a,!1);if(!y(s))return s.OrdinaryGetOwnMetadata(e,t,a)}function ne(e,t,a,s){var g=ae(a,s,!0);g.OrdinaryDefineOwnMetadata(e,t,a,s)}function ce(e,t){var a=me(e,t),s=le(e);if(s===null)return a;var g=ce(s,t);if(g.length<=0)return a;if(a.length<=0)return g;for(var k=new F,S=[],M=0,u=a;M<u.length;M++){var d=u[M],c=k.has(d);c||(k.add(d),S.push(d))}for(var p=0,E=g;p<E.length;p++){var d=E[p],c=k.has(d);c||(k.add(d),S.push(d))}return S}function me(e,t){var a=ae(e,t,!1);return a?a.OrdinaryOwnMetadataKeys(e,t):[]}function pe(e){if(e===null)return 1;switch(typeof e){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return e===null?1:6;default:return 6}}function y(e){return e===void 0}function X(e){return e===null}function Ge(e){return typeof e=="symbol"}function D(e){return typeof e=="object"?e!==null:typeof e=="function"}function We(e,t){switch(pe(e)){case 0:return e;case 1:return e;case 2:return e;case 3:return e;case 4:return e;case 5:return e}var a=t===3?"string":t===5?"number":"default",s=ve(e,m);if(s!==void 0){var g=s.call(e,a);if(D(g))throw new TypeError;return g}return Be(e,a==="default"?"number":a)}function Be(e,t){if(t==="string"){var a=e.toString;if(Y(a)){var s=a.call(e);if(!D(s))return s}var g=e.valueOf;if(Y(g)){var s=g.call(e);if(!D(s))return s}}else{var g=e.valueOf;if(Y(g)){var s=g.call(e);if(!D(s))return s}var k=e.toString;if(Y(k)){var s=k.call(e);if(!D(s))return s}}throw new TypeError}function he(e){return!!e}function He(e){return""+e}function H(e){var t=We(e,3);return Ge(t)?t:He(t)}function we(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:Object.prototype.toString.call(e)==="[object Array]"}function Y(e){return typeof e=="function"}function ge(e){return typeof e=="function"}function ze(e){switch(pe(e)){case 3:return!0;case 4:return!0;default:return!1}}function ue(e,t){return e===t||e!==e&&t!==t}function ve(e,t){var a=e[t];if(a!=null){if(!Y(a))throw new TypeError;return a}}function ye(e){var t=ve(e,h);if(!Y(t))throw new TypeError;var a=t.call(e);if(!D(a))throw new TypeError;return a}function be(e){return e.value}function Me(e){var t=e.next();return t.done?!1:t}function Ee(e){var t=e.return;t&&t.call(e)}function le(e){var t=Object.getPrototypeOf(e);if(typeof e!="function"||e===x||t!==x)return t;var a=e.prototype,s=a&&Object.getPrototypeOf(a);if(s==null||s===Object.prototype)return t;var g=s.constructor;return typeof g!="function"||g===e?t:g}function Ze(){var e;!y(j)&&typeof r.Reflect<"u"&&!(j in r.Reflect)&&typeof r.Reflect.defineMetadata=="function"&&(e=Xe(r.Reflect));var t,a,s,g=new I,k={registerProvider:S,getProvider:u,setProvider:c};return k;function S(p){if(!Object.isExtensible(k))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===p:break;case y(t):t=p;break;case t===p:break;case y(a):a=p;break;case a===p:break;default:s===void 0&&(s=new F),s.add(p);break}}function M(p,E){if(!y(t)){if(t.isProviderFor(p,E))return t;if(!y(a)){if(a.isProviderFor(p,E))return t;if(!y(s))for(var A=ye(s);;){var P=Me(A);if(!P)return;var W=be(P);if(W.isProviderFor(p,E))return Ee(A),W}}}if(!y(e)&&e.isProviderFor(p,E))return e}function u(p,E){var A=g.get(p),P;return y(A)||(P=A.get(E)),y(P)&&(P=M(p,E),y(P)||(y(A)&&(A=new $,g.set(p,A)),A.set(E,P))),P}function d(p){if(y(p))throw new TypeError;return t===p||a===p||!y(s)&&s.has(p)}function c(p,E,A){if(!d(A))throw new Error("Metadata provider not registered.");var P=u(p,E);if(P!==A){if(!y(P))return!1;var W=g.get(p);y(W)&&(W=new $,g.set(p,W)),W.set(E,A)}return!0}}function Je(){var e;return!y(j)&&D(r.Reflect)&&Object.isExtensible(r.Reflect)&&(e=r.Reflect[j]),y(e)&&(e=Ze()),!y(j)&&D(r.Reflect)&&Object.isExtensible(r.Reflect)&&Object.defineProperty(r.Reflect,j,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function Qe(e){var t=new I,a={isProviderFor:function(d,c){var p=t.get(d);return y(p)?!1:p.has(c)},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:g,OrdinaryGetOwnMetadata:k,OrdinaryOwnMetadataKeys:M,OrdinaryDeleteMetadata:u};return v.registerProvider(a),a;function s(d,c,p){var E=t.get(d),A=!1;if(y(E)){if(!p)return;E=new $,t.set(d,E),A=!0}var P=E.get(c);if(y(P)){if(!p)return;if(P=new $,E.set(c,P),!e.setProvider(d,c,a))throw E.delete(c),A&&t.delete(d),new Error("Wrong provider for target.")}return P}function g(d,c,p){var E=s(c,p,!1);return y(E)?!1:he(E.has(d))}function k(d,c,p){var E=s(c,p,!1);if(!y(E))return E.get(d)}function S(d,c,p,E){var A=s(p,E,!0);A.set(d,c)}function M(d,c){var p=[],E=s(d,c,!1);if(y(E))return p;for(var A=E.keys(),P=ye(A),W=0;;){var Te=Me(P);if(!Te)return p.length=W,p;var tt=be(Te);try{p[W]=tt}catch(rt){try{Ee(P)}finally{throw rt}}W++}}function u(d,c,p){var E=s(c,p,!1);if(y(E)||!E.delete(d))return!1;if(E.size===0){var A=t.get(c);y(A)||(A.delete(p),A.size===0&&t.delete(A))}return!0}}function Xe(e){var t=e.defineMetadata,a=e.hasOwnMetadata,s=e.getOwnMetadata,g=e.getOwnMetadataKeys,k=e.deleteMetadata,S=new I,M={isProviderFor:function(u,d){var c=S.get(u);return!y(c)&&c.has(d)?!0:g(u,d).length?(y(c)&&(c=new F,S.set(u,c)),c.add(d),!0):!1},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:a,OrdinaryGetOwnMetadata:s,OrdinaryOwnMetadataKeys:g,OrdinaryDeleteMetadata:k};return M}function ae(e,t,a){var s=v.getProvider(e,t);if(!y(s))return s;if(a){if(v.setProvider(e,t,z))return z;throw new Error("Illegal state.")}}function Ye(){var e={},t=[],a=function(){function M(u,d,c){this._index=0,this._keys=u,this._values=d,this._selector=c}return M.prototype["@@iterator"]=function(){return this},M.prototype[h]=function(){return this},M.prototype.next=function(){var u=this._index;if(u>=0&&u<this._keys.length){var d=this._selector(this._keys[u],this._values[u]);return u+1>=this._keys.length?(this._index=-1,this._keys=t,this._values=t):this._index++,{value:d,done:!1}}return{value:void 0,done:!0}},M.prototype.throw=function(u){throw this._index>=0&&(this._index=-1,this._keys=t,this._values=t),u},M.prototype.return=function(u){return this._index>=0&&(this._index=-1,this._keys=t,this._values=t),{value:u,done:!0}},M}(),s=function(){function M(){this._keys=[],this._values=[],this._cacheKey=e,this._cacheIndex=-2}return Object.defineProperty(M.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),M.prototype.has=function(u){return this._find(u,!1)>=0},M.prototype.get=function(u){var d=this._find(u,!1);return d>=0?this._values[d]:void 0},M.prototype.set=function(u,d){var c=this._find(u,!0);return this._values[c]=d,this},M.prototype.delete=function(u){var d=this._find(u,!1);if(d>=0){for(var c=this._keys.length,p=d+1;p<c;p++)this._keys[p-1]=this._keys[p],this._values[p-1]=this._values[p];return this._keys.length--,this._values.length--,ue(u,this._cacheKey)&&(this._cacheKey=e,this._cacheIndex=-2),!0}return!1},M.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=e,this._cacheIndex=-2},M.prototype.keys=function(){return new a(this._keys,this._values,g)},M.prototype.values=function(){return new a(this._keys,this._values,k)},M.prototype.entries=function(){return new a(this._keys,this._values,S)},M.prototype["@@iterator"]=function(){return this.entries()},M.prototype[h]=function(){return this.entries()},M.prototype._find=function(u,d){if(!ue(this._cacheKey,u)){this._cacheIndex=-1;for(var c=0;c<this._keys.length;c++)if(ue(this._keys[c],u)){this._cacheIndex=c;break}}return this._cacheIndex<0&&d&&(this._cacheIndex=this._keys.length,this._keys.push(u),this._values.push(void 0)),this._cacheIndex},M}();return s;function g(M,u){return M}function k(M,u){return u}function S(M,u){return[M,u]}}function Ke(){var e=function(){function t(){this._map=new $}return Object.defineProperty(t.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),t.prototype.has=function(a){return this._map.has(a)},t.prototype.add=function(a){return this._map.set(a,a),this},t.prototype.delete=function(a){return this._map.delete(a)},t.prototype.clear=function(){this._map.clear()},t.prototype.keys=function(){return this._map.keys()},t.prototype.values=function(){return this._map.keys()},t.prototype.entries=function(){return this._map.entries()},t.prototype["@@iterator"]=function(){return this.keys()},t.prototype[h]=function(){return this.keys()},t}();return e}function et(){var e=16,t=O.create(),a=s();return function(){function u(){this._key=s()}return u.prototype.has=function(d){var c=g(d,!1);return c!==void 0?O.has(c,this._key):!1},u.prototype.get=function(d){var c=g(d,!1);return c!==void 0?O.get(c,this._key):void 0},u.prototype.set=function(d,c){var p=g(d,!0);return p[this._key]=c,this},u.prototype.delete=function(d){var c=g(d,!1);return c!==void 0?delete c[this._key]:!1},u.prototype.clear=function(){this._key=s()},u}();function s(){var u;do u="@@WeakMap@@"+M();while(O.has(t,u));return t[u]=!0,u}function g(u,d){if(!i.call(u,a)){if(!d)return;Object.defineProperty(u,a,{value:O.create()})}return u[a]}function k(u,d){for(var c=0;c<d;++c)u[c]=Math.random()*255|0;return u}function S(u){if(typeof Uint8Array=="function"){var d=new Uint8Array(u);return typeof crypto<"u"?crypto.getRandomValues(d):typeof msCrypto<"u"?msCrypto.getRandomValues(d):k(d,u),d}return k(new Array(u),u)}function M(){var u=S(e);u[6]=u[6]&79|64,u[8]=u[8]&191|128;for(var d="",c=0;c<e;++c){var p=u[c];(c===4||c===6||c===8)&&(d+="-"),p<16&&(d+="0"),d+=p.toString(16).toLowerCase()}return d}}function de(e){return e.__=void 0,delete e.__,e}})})(xe||(xe={}))});var On=lt(_e());var l=class extends Error{constructor(n){super(n),this.name="ValidationError"}};var ie=new Map;function dt(o,n){return`${typeof o=="function"?o.name:o.constructor.name}.${n}`}function w(o,n,r){let i=dt(o,n);ie.has(i)||ie.set(i,[]);let f=ie.get(i);f.includes(r)||f.push(r)}function yt(o={}){let{minLength:n={value:0,message:"The array must contain at least {minLength.value} elements."},maxLength:r={value:1/0,message:"The array must contain at most {maxLength.value} elements."},elementsType:i={value:"any",message:"The array elements must be of type {elementsType.value}."},allowedValues:f={value:[],message:"The array elements must be one of the allowed values: {allowedValues.value.join(', ')}."},message:m="The array contains invalid elements."}=o,h=(b,T)=>b.replace(/{([^}]+)}/g,(_,O)=>T[O]||"");return function(b,T){if(Reflect.getMetadata("valarray:applied",b,T))throw new Error(`The @ValArray decorator has already been applied to the field "${T}"`);Reflect.defineMetadata("valarray:applied",!0,b,T),w(b,T,O=>{if(!Array.isArray(O))throw new l(h(`The field "${T}" must be an array.`,{}));if(O.length<n.value)throw new l(h(n.message,{minLength:n}));if(O.length>r.value)throw new l(h(r.message,{maxLength:r}));if(i.value!=="any"){for(let x of O)if(typeof x!==i.value)throw new l(h(i.message,{elementsType:i}))}if(f.value.length>0){for(let x of O)if(!f.value.includes(x))throw new l(h(f.message||m,{allowedValues:f}))}})}}function Tt(o){if(!o||Array.isArray(o)&&o.length===0)throw new Error("The 'rules' parameter of the @DvCustom decorator cannot be empty or undefined.");let n=Array.isArray(o)?o:[o];for(let r of n){if(typeof r!="object"||r===null)throw new Error("Each custom rule must be a valid object.");if(typeof r.validate!="function")throw new Error("The 'validate' property of each rule must be a function.");if(typeof r.message!="string"||r.message.trim()==="")throw new Error("The 'message' property of each rule must be a non-empty string.")}return function(r,i){let f=Reflect.getMetadata("valtcustom:applied",r,i)??new Set;if(f.has("DvCustom"))throw new Error(`The @DvCustom decorator has already been applied in the field "${i}".`);f.add("DvCustom"),Reflect.defineMetadata("valcustom:applied",f,r,i),w(r,i,m=>{for(let h of n)if(!h.validate(m))throw new l(`[${i}] ${h.message}`)})}}function Oe(o){return(n,r)=>{w(n,r,i=>{if(!(i instanceof Date)||isNaN(i.getTime()))throw new l(o||`Property "${r}" must be a valid date.`)})}}function Rt(o={}){let{minDate:n,maxDate:r,past:i,future:f}=o,m=n instanceof Date?n:n?.value,h=r instanceof Date?r:r?.value,b=typeof n=="object"&&"message"in n?n.message:`The date must be after ${m?.toLocaleDateString()}`,T=typeof r=="object"&&"message"in r?r.message:`The date must be before ${h?.toLocaleDateString()}`,_=typeof i=="object"?i.value:i,O=typeof f=="object"?f.value:f,x=typeof i=="object"&&"message"in i?i.message:"The date must be in the past",$=typeof f=="object"&&"message"in f?f.message:"A data deve estar no futuro";return function(F,I){if(Reflect.getMetadata("valdate:applied",F,I))throw new Error(`The @ValDate decorator has already been applied to the field"${I}"`);Reflect.defineMetadata("valdate:applied",!0,F,I),Oe("Field must be a valid date")(F,I),w(F,I,v=>{if(!(v instanceof Date)||isNaN(v.getTime()))throw new l(`The "${I}" field must be a valid date.`);if(m&&v<m)throw new l(b);if(h&&v>h)throw new l(T);let z=new Date;if(_&&v>=z)throw new l(x);if(O&&v<=z)throw new l($)})}}function It(o){let{values:n,in:r}=o,i=Array.isArray(n)?n:Object.values(n).filter(m=>typeof m!="number"||!Object.values(n).includes(m.toString())),f=r?.message||`The field must be one of the following values: ${i.join(", ")}.`;return function(m,h){if(Reflect.getMetadata("valenum:applied",m,h))throw new Error(`The @ValEnum decorator has already been applied to the field "${h}"`);Reflect.defineMetadata("valenum:applied",!0,m,h),w(m,h,T=>{if(!i.includes(T))throw new l(f.replace("{property}",h))})}}var K=class extends Error{constructor(){super("Skip further validations for this optional field."),this.name="ValidationSkipError"}};function se(){return(o,n)=>{w(o,n,r=>{if(r==null||r==="")throw new K})}}var $e={uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,mongo:/^[0-9a-fA-F]{24}$/,number:/^[0-9]+$/};function ee(o,n){let r=typeof o>"u",i=o===null,f=o==="";return!!(n.optional&&r||n.null&&i||n.empty&&f)}function Jt(o={}){let{type:n,optional:r=!1,empty:i=!1,null:f=!1,regex:m}=o;if(r&&f)throw new Error("The 'optional' and 'null' options cannot be used simultaneously.");if(i&&n)throw new Error("The 'empty' option cannot be used with the defined ID type.");if(m&&n)throw new Error("It is not recommended to use 'regex' and 'type' at the same time. Choose only one.");return function(h,b){if(Reflect.getMetadata("dvid:applied",h,b))throw new Error(`The @DvId decorator has already been applied to the field "${b}".`);Reflect.defineMetadata("dvid:applied",!0,h,b),w(h,b,_=>{if(ee(_,{optional:r,null:f,empty:i}))return;if(typeof _!="string"&&typeof _!="number")throw new l(`The "${b}" field must be a valid ID (string or number).`);let O=String(_);if(n){let x=$e[n];if(!x)throw new Error(`ID type "${n}" is not supported.`);if(!x.test(O))throw new l(`The field "${b}" is not a valid ${n}.`)}if(m){let x,$=`The field "${b}" does not match the required pattern.`;if(typeof m=="string"||m instanceof RegExp?x=new RegExp(m):(x=new RegExp(m.value),m.message&&($=m.message)),!x.test(O))throw new l($)}}),r&&se()(h,b)}}function Kt(o){return function(n,r){if(Reflect.getMetadata("valip:applied",n,r))throw new Error(`The @ValIP decorator has already been applied to the field "${r}"`);Reflect.defineMetadata("valip:applied",!0,n,r);let f=o?.message||`The "${r}" field must be a valid IP`,m=o?.version||"v4",h=/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,b=/([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|([0-9a-fA-F]{1,4}:){1}(:[0-9a-fA-F]{1,4}){1,6}|::([0-9a-fA-F]{1,4}:){1,7}([0-9a-fA-F]{1,4})$/;w(n,r,T=>{if(typeof T!="string")throw new l(f);let _=!1;if((m==="v4"||m==="any")&&(_=h.test(T)),(m==="v6"||m==="any")&&(_=_||b.test(T)),!_)throw new l(f)})}}function ar(o){return function(n,r){let i=o?.message||`The "${r}" field must be a valid URL`,f=/^(https?:\/\/)?([\w\d\-]+\.)+[a-z]{2,6}(:\d+)?(\/[\w\d\-._~:/?#[\]@!$&'()*+,;%=]*)?$/i;w(n,r,m=>{let h={optional:!0,null:o?.allowNull??!0,empty:!0};if(!ee(m,h)){if(typeof m!="string")throw new l(i);if(!f.test(m))throw new l(i)}})}}function fr(o={}){let{message:n,optional:r=!1,empty:i=!1,null:f=!1}=o;if(r&&f)throw new Error("The 'optional' and 'null' options cannot be used together.");return function(m,h){if(Reflect.getMetadata("valboolean:applied",m,h))throw new Error(`The @DvBoolean decorator has already been applied to the field"${h}"`);Reflect.defineMetadata("valboolean:applied",!0,m,h),w(m,h,T=>{if(!(T===void 0&&r)&&!(T===null&&f)&&!(T===""&&i)&&typeof T!="boolean")throw new l(typeof n=="string"?n:`The "${h}" field must be a boolean value.`)})}}function Ae(o,n){return(r,i)=>{w(r,i,f=>{if(f!==o)throw new l(n||`Property "${i}" must be equal to ${o}.`)})}}function je(o){return(n,r)=>{w(n,r,i=>{if(!Number.isFinite(i))throw new l(o||`Property "${r}" must be a finite number.`)})}}function Re(o){return(n,r)=>{w(n,r,i=>{if(!Number.isInteger(i))throw new l(o||`Property "${r}" must be an integer.`)})}}function De(o,n){return(r,i)=>{w(r,i,f=>{if(typeof f!="number"||f>o)throw new l(n||`Property "${i}" must be at most ${o}.`)})}}function ke(o,n){return(r,i)=>{w(r,i,f=>{if(typeof f!="number"||f<o)throw new l(n||`Property "${i}" must be at least ${o}.`)})}}function Pe(o,n){return(r,i)=>{w(r,i,f=>{if(typeof f!="number"||f%o!==0)throw new l(n||`Property "${i}" must be a multiple of ${o}.`)})}}function Ie(o){return(n,r)=>{w(n,r,i=>{if(typeof i!="number"||i>=0)throw new l(o||`Property "${r}" must be a negative number.`)})}}function Se(o,n){return(r,i)=>{w(r,i,f=>{if(f===o)throw new l(n||`Property "${i}" must not be equal to ${o}.`)})}}function Ce(o){return(n,r)=>{w(n,r,i=>{if(typeof i!="number"||i<=0)throw new l(o||`Property "${r}" must be a positive number.`)})}}function Ne(o){return(n,r)=>{w(n,r,i=>{if(!Number.isSafeInteger(i))throw new l(o||`Property "${r}" must be a safe integer.`)})}}function Yr(o={}){let{min:n,max:r,positive:i,negative:f,multipleOf:m,equals:h,notEquals:b,finite:T,safe:_,integer:O,optional:x=!1,empty:$=!1,null:F=!1}=o,I=typeof n=="object"?n.value:n,j=typeof n=="object"?n.message:`Number must be greater than or equal to ${I}`,v=typeof r=="object"?r.value:r,z=typeof r=="object"?r.message:`Number must be less than or equal to ${v}`,B=typeof i=="object"?i.value:i,Z=typeof i=="object"?i.message:"The number must be positive",J=typeof f=="object"?f.value:f,te=typeof f=="object"?f.message:"The number must be negative",q=typeof m=="object"?m.value:m,V=typeof m=="object"?m.message:`Number must be a multiple of ${q}`,N=typeof h=="object"?h.value:h,U=typeof h=="object"?h.message:`Number must be equal to ${N}`,L=typeof b=="object"?b.value:b,Q=typeof b=="object"?b.message:`Number cannot be equal to ${L}`;if(x&&$)throw new Error("The 'optional' and 'empty' options cannot be used together.");if(x&&F)throw new Error("The 'optional' and 'null' options cannot be used together.");if($&&F)throw new Error("The 'empty' and 'null' options cannot be used together.");if(i&&f)throw new Error("The options 'positive' and 'negative' cannot be used together.");if(h!==void 0&&b!==void 0)throw new Error("The 'equals' and 'notEquals' options cannot be used together.");if(I!==void 0&&v!==void 0&&I>v)throw new Error("The minimum value cannot be greater than the maximum value.");if(q&&I!==void 0&&I%q!==0&&v!==void 0&&v%q!==0)throw new Error(`Number must be a multiple of ${q}, but the minimum or maximum value conflicts.`);return function(R,C){if(Reflect.getMetadata("valnumber:applied",R,C))throw new Error(`The @ValNumber decorator has already been applied to the field "${C}"`);if(Reflect.defineMetadata("valnumber:applied",!0,R,C),w(R,C,G=>{let re=G===null,oe=G===void 0,ne=G==="";if(!(x&&(oe||ne||re)||$&&ne||F&&re)&&(typeof G!="number"||isNaN(G)))throw new l(`The "${C}" field must be a number`)}),O){let G=typeof O=="string"?O:`The "${C}" field must be an integer`;Re(G)(R,C)}n!==void 0&&ke(I,j)(R,C),r!==void 0&&De(v,z)(R,C),B&&Ce(Z)(R,C),J&&Ie(te)(R,C),q&&Pe(q,V)(R,C),N!==void 0&&Ae(N,U)(R,C),L!==void 0&&Se(L,Q)(R,C),T&&je("The number must be finite")(R,C),_&&Ne("The number must be safe integer")(R,C)}}function Fe(o){return(n,r)=>{w(n,r,i=>{if(typeof i=="string"&&!/\d/.test(i))throw new l(o||`O campo "${r}" deve conter pelo menos um n\xFAmero.`)})}}function Le(o){return(n,r)=>{w(n,r,i=>{if(typeof i!="string"||i!==i.toLowerCase())throw new l(o||`A propriedade "${r}" deve estar em letras menusculas.`)})}}function qe(o){return(n,r)=>{w(n,r,i=>{if(typeof i!="string"||!/[^\w\s]/.test(i))throw new l(o||`Property "${r}" must contain at least one special character.`)})}}function Ue(o){return(n,r)=>{w(n,r,i=>{if(typeof i!="string"||i!==i.toUpperCase())throw new l(o||`A propriedade "${r}" deve estar em letras mai\xFAsculas.`)})}}function Mn(o={}){let{empty:n=!1,null:r=!1,optional:i=!1,lowercase:f=!1,maxLength:m=40,minLength:h=3,number:b=!1,specialChar:T=!1,uppercase:_=!1,noSpaces:O=!1,emailProviders:x=!1,regex:$=!1}=o;if(f&&_)throw new Error("The options 'lowercase' and 'uppercase' cannot be used together.");if(i&&n)throw new Error("The options 'optional' and 'empty' cannot be used together. 'optional' allows empty values, but 'empty' requires a non-empty value.");let F=typeof h=="object"?h.value:h,I=typeof m=="object"?m.value:m;if(F>I)throw new Error("The value of 'minLength' cannot be greater than 'maxLength'.");return function(j,v){if(Reflect.getMetadata("valtext:applied",j,v))throw new Error(`The @ValText decorator has already been applied to the field "${v}".`);Reflect.defineMetadata("valtext:applied",!0,j,v);let B=V=>ee(V,{optional:typeof i=="object"?i.value:i,null:typeof r=="object"?r.value:r,empty:typeof n=="object"?n.value:n});w(j,v,V=>{if(!B(V)){if(typeof V!="string")throw new l(`The "${v}" field must be a string.`);if(!n&&V==="")throw new l(`The "${v}" field is required.`)}}),i&&se()(j,v);let Z=typeof h=="object"?h.value:h,J=typeof m=="object"?m.value:m,te=typeof h=="object"?h.message:`The "${v}" field must have at least ${Z} characters.`,q=typeof m=="object"?m.message:`The "${v}" field must be at most ${J} characters long.`;if(w(j,v,V=>{if(!B(V)&&typeof V=="string"&&V.length<Z)throw new l(te)}),w(j,v,V=>{if(!B(V)&&typeof V=="string"&&V.length>J)throw new l(q)}),_&&Ue(`The "${v}" field must contain only uppercase letters.`)(j,v),f&&Le(`The "${v}" field must contain only lowercase letters.`)(j,v),b&&Fe(`The "${v}" field must contain at least one number`)(j,v),O&&w(j,v,V=>{if(!B(V)&&typeof V=="string"&&/\s/.test(V))throw new l(`The "${v}" field must not contain spaces.`)}),T&&qe(`The "${v}" field must contain at least one special character`)(j,v),x){let V=[],N="";typeof x=="string"?(V=[x],N=`The email must be from the provider ${V[0]}`):Array.isArray(x)?(V=x,N=`The email must be from one of the following providers: ${V.join(", ")}`):typeof x=="object"&&(V=Array.isArray(x.value)?x.value:[x.value],N=x.message||`The email must be from one of the following providers: ${V.join(", ")}`),w(j,v,U=>{if(B(U)||typeof U!="string")return;let L=/^[^\s@]+@([^\s@]+\.[^\s@]+)$/i.exec(U);if(!L||!L[1])throw new l(`The "${v}" field must be a valid email.`);let Q=L[1].toLowerCase();if(!V.some(R=>Q===R.toLowerCase()))throw new l(N)})}if($){let V=[],N="";typeof $=="string"||$ instanceof RegExp?(V=[$],N=`${v} does not match the required pattern.`):Array.isArray($)?(V=$,N=`${v} does not match any of the required patterns.`):typeof $=="object"&&(V=Array.isArray($.value)?$.value:[$.value],N=$.message||`${v} does not match any of the required patterns.`),w(j,v,U=>{if(B(U)||typeof U!="string")return;let L=U.replace(/\s+/g,"");if(!V.some(R=>typeof R=="string"?L.startsWith(R):R.test(L)))throw new l(N)})}}}function xn(o){return new Promise((n,r)=>{let i={},f=o.constructor.name;for(let m of Object.keys(o)){let h=`${f}.${m}`,b=o[m],T=ie.get(h);if(T)try{for(let _ of T)_(b)}catch(_){if(_ instanceof K)continue;let O=_ instanceof Error?_.message:String(_);i[m]||(i[m]=[]),i[m].push(O)}}Object.keys(i).length>0?r(i):n(o)})}export{yt as DvArray,fr as DvBoolean,Tt as DvCustom,Rt as DvDate,It as DvEnum,Kt as DvIP,Jt as DvId,Yr as DvNumber,Mn as DvText,ar as DvURL,xn as decoValidation}; /*! Bundled license information: reflect-metadata/Reflect.js: (*! ***************************************************************************** Copyright (C) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** *) */ //# sourceMappingURL=index.js.map