UNPKG

@decaf-ts/decorator-validation

Version:
3 lines (2 loc) 41.8 kB
var e,t;e=this,t=function(e,t,r,a,s){"use strict";const o={INVALID_PATH:"Invalid path argument. Expected non-empty string but received: '{0}'",CONTEXT_NOT_OBJECT_COMPARISON:"Unable to access parent at level {0} for path '{1}': current context is not an object",PROPERTY_INVALID:"Failed to resolve path {0}: property '{1}' is invalid or does not exist.",PROPERTY_NOT_EXIST:"Failed to resolve path: property '{0}' does not exist.",UNSUPPORTED_TYPES_COMPARISON:"Unsupported types for comparison: '{0}' and '{1}'",NULL_OR_UNDEFINED_COMPARISON:"Comparison failed due to null or undefined value",INVALID_DATE_COMPARISON:"Invalid Date objects are not comparable",TYPE_MISMATCH_COMPARISON:"Cannot compare values of different types: {0} and {1}.",NAN_COMPARISON:"Comparison not supported for NaN values"},i=Symbol("_parent"),n=Symbol("isAsync");var c;e.ModelKeys=void 0,(c=e.ModelKeys||(e.ModelKeys={})).REFLECT="decaf.model.",c.DESCRIPTION="decaf.description.",c.TYPE="design:type",c.PARAMS="design:paramtypes",c.RETURN="design:returntype",c.MODEL="model",c.ANCHOR="__model",c.CONSTRUCTION="constructed-by",c.ATTRIBUTE="__attributes",c.HASHING="hashing",c.SERIALIZATION="serialization";const d="decaf",l={EQUALS:"equals",DIFF:"different",LESS_THAN:"lessThan",LESS_THAN_OR_EQUAL:"lessThanOrEqual",GREATER_THAN:"greaterThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual"},u={REFLECT:e.ModelKeys.REFLECT+"validation.",DATE:"date",EMAIL:"email",FORMAT:"format",LIST:"list",MAX:"max",MAX_LENGTH:"maxlength",MIN:"min",MIN_LENGTH:"minlength",PASSWORD:"password",PATTERN:"pattern",REQUIRED:"required",STEP:"step",TYPE:"type",UNIQUE:"unique",URL:"url",VALIDATOR:"validator",...l},f=["January","February","March","April","May","June","July","August","September","October","November","December"],g=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],p={REQUIRED:"This field is required",MIN:"The minimum value is {0}",MAX:"The maximum value is {0}",MIN_LENGTH:"The minimum length is {0}",MAX_LENGTH:"The maximum length is {0}",PATTERN:"The value does not match the pattern",EMAIL:"The value is not a valid email",URL:"The value is not a valid URL",TYPE:"Invalid type. Expected {0}, received {1}",STEP:"Invalid value. Not a step of {0}",DATE:"Invalid value. not a valid Date",DEFAULT:"There is an Error",PASSWORD:"Must be at least 8 characters and contain one of number, lower and upper case letters, and special character (@$!%*?&_-.,)",LIST:"Invalid list of {0}",MODEL_NOT_FOUND:"No model registered under {0}",EQUALS:"This field must be equal to field {0}",DIFF:"This field must be different from field {0}",LESS_THAN:"This field must be less than field {0}",LESS_THAN_OR_EQUAL:"This field must be less than or equal to field {0}",GREATER_THAN:"This field must be greater than field {0}",GREATER_THAN_OR_EQUAL:"This field must be greater than or equal to field {0}",UNIQUE:"Duplicate found, this field must be unique."},h={EMAIL:/[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/,URL:/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,PASSWORD:{CHAR8_ONE_OF_EACH:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&_\-.,])[A-Za-z\d@$!%*?&_\-.,]{8,}$/g}};function y(e,...t){return e.replace(/{(\d+)}/g,(e,r)=>void 0!==t[r]?t[r].toString():"undefined")}const m=y;function E(e,t){let r=t;r.match(/hh/)?r=r.replace("hh","(?<hour>\\d{2})"):r.match(/h/)?r=r.replace("h","(?<hour>\\d{1,2})"):r.match(/HH/)?r=r.replace("HH","(?<hour>\\d{2})"):r.match(/H/)&&(r=r.replace("H","(?<hour>\\d{1,2})")),r.match(/mm/)?r=r.replace("mm","(?<minutes>\\d{2})"):r.match(/m/)&&(r=r.replace("m","(?<minutes>\\d{1,2})")),r.match(/ss/)?r=r.replace("ss","(?<seconds>\\d{2})"):r.match(/s/)&&(r=r.replace("s","(?<seconds>\\d{1,2})")),r.match(/dd/)?r=r.replace("dd","(?<day>\\d{2})"):r.match(/d/)&&(r=r.replace("d","(?<day>\\d{1,2})")),r.match(/EEEE/)?r=r.replace("EEEE","(?<dayofweek>\\w+)"):r.match(/EEEE/)&&(r=r.replace("EEE","(?<dayofweek>\\w+)")),r.match(/yyyy/)?r=r.replace("yyyy","(?<year>\\d{4})"):r.match(/yy/)&&(r=r.replace("yy","(?<year>\\d{2})")),r.match(/MMMM/)?r=r.replace("MMMM","(?<monthname>\\w+)"):r.match(/MMM/)&&(r=r.replace("MMM","(?<monthnamesmall>\\w+)")),r.match(/MM/)?r=r.replace("MM","(?<month>\\d{2})"):r.match(/M/)&&(r=r.replace("M","(?<month>\\d{1,2})")),r=r.replace("S","(?<milis>\\d{1,3})").replace("aaa","(?<ampm>\\w{2})");const a=RegExp(r,"g").exec(e);if(!a||!a.groups)return new Date(e);const s=e=>{if(!e)return 0;const t=parseInt(e);return isNaN(t)?0:t},o=s(a.groups.year),i=s(a.groups.day),n=a.groups.ampm;let c=s(a.groups.hour);n&&(c="PM"===n?c+12:c);const d=s(a.groups.minutes),l=s(a.groups.seconds),u=s(a.groups.milis),g=a.groups.monthname,p=a.groups.monthnamesmall;let h=a.groups.month;if(g)h=f.indexOf(g);else if(p){const t=f.find(e=>e.toLowerCase().startsWith(p.toLowerCase()));if(!t)return new Date(e);h=f.indexOf(t)}else h=s(""+h);return new Date(o,h-1,i,c,d,l,u)}function T(e,t){if(e)return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>M(r,t)})}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>M(r,t)})}),e}function A(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function b(e){return 10>e?"0"+e:e.toString()}function M(e,t="yyyy/MM/dd"){const r=e.getDate(),a=e.getMonth(),s=e.getFullYear(),o=e.getHours(),i=e.getMinutes(),n=e.getSeconds(),c=e.getMilliseconds(),d=o%12,l=b(d),u=b(o),p=b(i),h=b(n),y=12>o?"AM":"PM",m=g[e.getDay()],E=m.substr(0,3),T=b(r),A=a+1,M=b(A),_=f[a],S=_.substr(0,3),N=s+"",O=N.substr(2,2);return(t=t.replace("hh",l).replace("h",d.toString()).replace("HH",u).replace("H",o.toString()).replace("mm",p).replace("m",i.toString()).replace("ss",h).replace("s",n.toString()).replace("S",c.toString()).replace("dd",T).replace("d",r.toString()).replace("EEEE",m).replace("EEE",E).replace("yyyy",N).replace("yy",O).replace("aaa",y)).indexOf("MMM")>-1?t.replace("MMMM",_).replace("MMM",S):t.replace("MM",M).replace("M",A.toString())}function _(e,t){let r;if(t){if(t instanceof Date)try{r=E(M(t,e),e)}catch(r){throw Error(m("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=E(t,e);else if("number"==typeof t)r=E(M(new Date(t),e),e);else{if(!A(t))throw Error("Invalid value provided "+t);try{r=E(M(new Date(t),e),e)}catch(r){throw Error(m("Could not convert date {0} to format: {1}",t,e))}}return T(r,e)}}function S(e){return d}class N{static{this.decorators={}}static{this.flavourResolver=S}constructor(e=d){this.flavour=e}for(e){return this.key=e,this}decorate(e=!1,...t){if(!this.key)throw Error("key must be provided before decorators can be added");if(!(t&&t.length||e||this.flavour===d))throw Error("Must provide overrides or addons to override or extend decaf's decorators");if(this.flavour===d&&e)throw Error("Default flavour cannot be extended");return this[e?"extras":"decorators"]=new Set([...(this[e?"extras":"decorators"]||new Set).values(),...t]),this}define(...e){return this.decorate(!1,...e)}extend(...e){return this.decorate(!0,...e)}decoratorFactory(e,t=d){const r=(t,r,a)=>{const s=N.flavourResolver(t),o=N.decorators[e];let i;const n=o[s]?o[s].extras:o[d].extras,c=[...o[d].extras?o[d].extras.values():[]].reduce((e,t,r)=>(t.args&&(e[r]=t.args),e),{});i=o&&o[s]&&o[s].decorators&&o[s].decorators.size?o[s].decorators:o[d].decorators;const l=[...o[d].decorators.values()].reduce((e,t,r)=>(t.args&&(e[r]=t.args),e),{});return[...i?i.values():[],...n?n.values():[]].reduce((e,s,o)=>{switch(typeof s){case"object":{const{decorator:e,args:n,transform:d}=s,u=n||o<(i?i.size:0)?l[o]:c[o-(i?i.size:0)]||(i?l[o-i.size]:[]);return e(...d?d(u||[]):u||[])(t,r,a)}case"function":return s(t,r,a);default:throw Error("Unexpected decorator type: "+typeof s)}},{target:t,propertyKey:r,descriptor:a})};return Object.defineProperty(r,"name",{value:[t,e].join("_decorator_for_"),writable:!1}),r}apply(){if(!this.key)throw Error("No key provided for the decoration builder");return N.register(this.key,this.flavour,this.decorators||new Set,this.extras),this.decoratorFactory(this.key,this.flavour)}static register(e,t,r,a){if(!e)throw Error("No key provided for the decoration builder");if(!r)throw Error("No decorators provided for the decoration builder");if(!t)throw Error("No flavour provided for the decoration builder");N.decorators[e]||(N.decorators[e]={}),N.decorators[e][t]||(N.decorators[e][t]={}),r&&(N.decorators[e][t].decorators=r),a&&(N.decorators[e][t].extras=a)}static setFlavourResolver(e){N.flavourResolver=e}static for(e){return(new N).for(e)}static flavouredAs(e){return new N(e)}}function O(t=e.ModelKeys.ATTRIBUTE){return N.for(t).define((e,r)=>{let a;Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!1,configurable:!1,writable:!1,value:[]}),a=e[t],a.includes(r)||a.push(r)}).apply()}function R(e,t){return a.apply(O(),a.metadata(e,t))}function P(e){e+="";let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return t.toString()}function v(e){const t=(e,t)=>{const r=a(t);return"string"==typeof r?a((e||"")+a(t)):(e=((e=e||0)<<5)-e+r)&e},r=P,a=e=>void 0===e?"":-1!==["string","number","symbol"].indexOf(typeof e)?r(e.toString()):e instanceof Date?r(e.getTime()):Array.isArray(e)?e.reduce(t,void 0):Object.values(e).reduce(t,void 0),s=Object.values(e).reduce(t,0);return("number"==typeof s?Math.abs(s):s).toString()}const L="default";class D{static{this.current=L}static{this.cache={default:v}}constructor(){}static get(e){if(e in this.cache)return this.cache[e];throw Error("No hashing method registered under "+e)}static register(e,t,r=!1){if(e in this.cache)throw Error(`Hashing method ${e} already registered`);this.cache[e]=t,r&&(this.current=e)}static hash(e,t,...r){return t?this.get(t)(e,...r):this.get(this.current)(e,...r)}static setDefault(e){this.current=this.get(e)}}const I=e=>e[i],w=(e,t)=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw Error(m(o.PROPERTY_NOT_EXIST,t));return e[t]};class V{static create(e,t){const{getValue:r,getParent:a,ignoreUndefined:s,ignoreNull:i}={getParent:I,getValue:w,ignoreNull:!1,ignoreUndefined:!1,...t},n=new Proxy({},{get:(t,n)=>"getValueFromPath"===n?t=>{const n=V.parsePath(t);let c=e;for(let e=0;e<n.length;e++){const d=n[e];if(".."===d){const r=a(c);if(!r||"object"!=typeof r)throw Error(m(o.CONTEXT_NOT_OBJECT_COMPARISON,e+1,t));c=r;continue}if(c=r(c,d),!s&&void 0===c)throw Error(m(o.PROPERTY_INVALID,t,d));if(!i&&null===c)throw Error(m(o.PROPERTY_INVALID,t,d))}return c}:t[n]});return n}static parsePath(e){if("string"!=typeof e||!e.trim())throw Error(m(o.INVALID_PATH,e));return e.match(/(\.\.|[^/.]+)/g)||[]}}class j{constructor(e){for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&Object.defineProperty(this,t,{enumerable:!0,configurable:!1,value:e[t],writable:!1})}toString(){const e=this;return Object.keys(e).filter(t=>Object.prototype.hasOwnProperty.call(e,t)&&"function"!=typeof e[t]).reduce((t,r)=>{let a=Object.keys(e[r]).reduce((t,a)=>(t?t+="\n"+e[r][a]:t=e[r][a],t),void 0);return a&&(a=`${r} - ${a}`,t?t+="\n"+a:t=a),t},"")}}class U{constructor(e,t=p.DEFAULT,...r){this.async=e,this.message=t,r.length&&(this.acceptedTypes=r),this.acceptedTypes&&(this.hasErrors=this.checkTypeAndHasErrors(this.hasErrors.bind(this)))}getMessage(e,...t){return m(e,...t)}checkTypeAndHasErrors(e){return function(t,r,s,...o){return void 0!==t&&this.acceptedTypes?a.Reflection.checkTypes(t,this.acceptedTypes)?e(t,r,s,...o):this.getMessage(p.TYPE,this.acceptedTypes.join(", "),typeof t):e(t,r,s,...o)}.bind(this)}static isValidator(e){return e.constructor&&!!e.hasErrors}}class H extends U{constructor(e=p.DEFAULT,...t){super(!1,e,...t)}}class C{constructor(...e){this.cache={},this.customKeyCache={},this.register(...e)}getCustomKeys(){return Object.assign({},this.customKeyCache)}getKeys(){return Object.keys(this.cache)}get(e){if(!(e in this.cache))return;const t=this.cache[e];if(H.isValidator(t))return t;const r=new(t.default||t);return this.cache[e]=r,r}register(...e){e.forEach(e=>{if(H.isValidator(e)){if(e.validationKey in this.cache)return;this.cache[e.validationKey]=e}else{const{validationKey:t,validator:r,save:a}=e;if(t in this.cache)return;if(this.cache[t]=r,!a)return;const s={};s[t.toUpperCase()]=t,this.customKeyCache=Object.assign({},this.customKeyCache,s)}})}}class k{static{this.actingValidatorRegistry=void 0}static{this.loadedDecorators={}}constructor(){}static setRegistry(e,t){t&&k.actingValidatorRegistry&&k.actingValidatorRegistry.getKeys().forEach(r=>{const a=e.get(r);a&&e.register(t(a))}),k.actingValidatorRegistry=e}static getRegistry(){return k.actingValidatorRegistry||(k.actingValidatorRegistry=new C),k.actingValidatorRegistry}static get(e){return k.getRegistry().get(e)}static register(...e){return k.getRegistry().register(...e)}static key(e){return u.REFLECT+e}static keys(){return this.getRegistry().getKeys()}static registerDecorator(e,t){e in this.loadedDecorators||(this.loadedDecorators[e]=t)}static decoratorFromKey(e){if(!(e in this.loadedDecorators))throw Error("No decorator registered under "+e);return this.loadedDecorators[e]}}function x(t){return e.ModelKeys.REFLECT+t}function z(t){const r=Reflect.getMetadata(x(e.ModelKeys.MODEL),t.constructor);if(!r)throw Error("could not find metadata for provided "+t.constructor.name);return r}function F(e,t){return t?Promise.resolve(e):e}function K(e,t,r=u.REFLECT){return a.Reflection.getPropertyDecorators(r,e,t)}function G(e,t){const r=[];for(const a in e)if(Object.prototype.hasOwnProperty.call(e,a)&&!t.includes(a)){const t=K(e,a);t&&r.push(t)}return r}function Y(e,t,r){Object.hasOwnProperty.call(e,t)||(e[t]=r)}function q(e,t){Object.hasOwnProperty.call(e,t)&&delete e[t]}function Q(e,t,r,...a){t&&Y(e,i,t),Y(e,n,!!r);const s=e.hasErrors(...a);return q(e,i),q(e,n),s}function $(e,t,r,a,s,...o){let i,n=!1;for(const c of a){const a=se.get(c);if(a||(i=new j({[e]:{[u.TYPE]:"Unable to verify type consistency, missing model registry for "+c}})),t instanceof a){n=!0,i=Q(t,r,s,...o);break}}return n?i:i||new j({[e]:{[u.TYPE]:"Value must be an instance of one of the expected types: "+a.join(", ")}})}function B(t,r,a,s){const o=k.get(a.key);if(!o)throw Error("Missing validator for "+a.key);if(!s&&a.props.async)return;const i=a.key===e.ModelKeys.TYPE?[a.props]:a.props||{},n=V.create(t,{ignoreUndefined:!0,ignoreNull:!0}),c=a.key===e.ModelKeys.TYPE?{type:i[0].name}:i;return F(o.hasErrors(r,c,n),s)}function X(t,r,a,s,o,...i){const n={};for(const c of s){if(!o&&c.props.async)continue;let s=B(t,a,c,o);if(c.key===u.LIST&&(!s||o)){const e=a instanceof Set?[...a]:a;if(e&&e.length>0){let a=c.props.class||c.props.clazz||c.props.customTypes;a=(Array.isArray(a)?a:[a]).map(e=>(e="function"!=typeof e||e.name?e:e()).name?e.name:e);const n=[a].flat().map(e=>(e+"").toLowerCase()),d=e.map(e=>se.isModel(e)?$(r,e,t,a.flat(),!!o,...i):n.includes(typeof e)?void 0:"Value has no validatable type");if(o)s=Promise.all(d).then(e=>e.every(e=>!e)?void 0:e);else{const e=d.every(e=>!e);s=d.length>0&&!e?d:void 0}}}const d=c.key===e.ModelKeys.TYPE?u.TYPE:c.key;s&&(n[d]=s)}if(!o)return Object.keys(n).length>0?n:void 0;const c=Object.keys(n),d=Object.values(n);return Promise.all(d).then(e=>{const t={};for(let r=0;r<e.length;r++){const a=e[r];void 0!==a&&(t[c[r]]=a)}return Object.keys(t).length>0?t:void 0})}function W(t,r,...a){const s=G(t,a),o={},i={};for(const{prop:n,decorators:c}of s){const s=n+"";let d=t[n];if(!c?.length)continue;const l=[u.TYPE,e.ModelKeys.TYPE].map(e=>c.find(t=>t.key===e)).find(Boolean);if(l?.key===u.TYPE&&c.splice(0,c.length,...c.filter(t=>t.key!==e.ModelKeys.TYPE)),!l)continue;const f=l.props.class||l.props.clazz||l.props.customTypes||l.props.name;l.key===e.ModelKeys.TYPE&&"Object"===f&&c.shift();const g=(Array.isArray(f)?f:[f]).map(e=>(e="function"!=typeof e||e.name?e:e()).name?e.name:e);if(g.some(e=>[Array.name,Set.name].includes(e))){if(!c.some(e=>e.key===u.LIST)){o[s]={[u.TYPE]:`Array or Set property '${s}' requires a @list decorator`};continue}if(d&&!(Array.isArray(d)||d instanceof Set)){o[s]={[u.TYPE]:`Property '${n+""}' must be either an Array or a Set`};continue}for(let t=c.length-1;t>=0;t--)c[t].key===e.ModelKeys.TYPE&&c.splice(t,1);d=d instanceof Set?[...d]:d}const p=X(t,s,d,c,r,...a)||{};if(se.isPropertyModel(t,s)&&null!=d){const o=d;if("object"!=typeof o||"function"!=typeof o.hasErrors);else{const n=(Array.isArray(f)?f:[f]).map(e=>("function"!=typeof e||e.name||(e=e()),se.get(e.name||e))).find(e=>!!e);n&&o instanceof n?i[s]=Q(o,t,r,...a):(p[u.TYPE]=n?"Value must be an instance of "+n.name:`Unable to verify type consistency, missing model registry for ${g.toString()} on prop ${s}`,delete p[e.ModelKeys.TYPE])}}(Object.keys(p).length>0||r)&&(o[s]=p),r||Object.entries(i[s]||{}).forEach(([e,t])=>{void 0!==t&&(o[`${s}.${e}`]=t)})}if(!r)return Object.keys(o).length>0?new j(o):void 0;const n=o,c=Object.keys(n),d=Object.values(n);return Promise.allSettled(d).then(async e=>{const t={};for(const[e,r]of Object.entries(i)){const a=await r;a&&Object.entries(a).forEach(([r,a])=>{void 0!==a&&(t[[e,r].join(".")]=a)})}for(let r=0;r<e.length;r++){const a=c[r],s=e[r];"fulfilled"===s.status&&void 0!==s.value?t[a]=s.value:"rejected"===s.status&&(t[a]=s.reason instanceof Error?s.reason.message:(s.reason||"Validation failed")+"")}return Object.keys(t).length>0?new j(t):void 0})}var Z,J;e.Primitives=void 0,(Z=e.Primitives||(e.Primitives={})).STRING="string",Z.NUMBER="number",Z.BOOLEAN="boolean",Z.BIGINT="bigint",e.ReservedModels=void 0,(J=e.ReservedModels||(e.ReservedModels={})).STRING="string",J.OBJECT="object",J.NUMBER="number",J.BOOLEAN="boolean",J.BIGINT="bigint",J.DATE="date";const ee=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"];let te,re;class ae{constructor(e=se.isModel){this.cache={},this.testFunction=e}register(e,t){if("function"!=typeof e)throw Error("Model registering failed. Missing Class name or constructor");t=t||e.name,this.cache[t]=e}get(e){try{return this.cache[e]}catch(e){return}}build(e={},t){if(!t&&!this.testFunction(e))throw Error("Provided obj is not a Model object");const r=t||se.getMetadata(e);if(!(r in this.cache))throw Error(`Provided class ${r} is not a registered Model object`);return new this.cache[r](e)}}class se{constructor(e=void 0){}isAsync(){return!!(this[n]??this?.constructor[n])}hasErrors(...e){return W(this,this.isAsync(),...e)}equals(e,...t){return a.isEqual(this,e,...t)}serialize(){return se.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return se.hash(this)}static deserialize(t){const r=Reflect.getMetadata(se.key(e.ModelKeys.SERIALIZATION),this.constructor);return r&&r.serializer?ne.deserialize(t,r.serializer,...r.args||[]):ne.deserialize(t)}static fromObject(e,t){t||(t={});for(const r of se.getAttributes(e))e[r]=t[r]??e[r]??void 0;return e}static fromModel(t,r){let s,o;r||(r={});const i=se.getAttributes(t),n=Object.getPrototypeOf(t);let c;for(const d of i){try{t[d]=r[d]??t[d]??void 0}catch(e){if(c=Object.getOwnPropertyDescriptor(n,d),!c||c.writable)throw Error(`Unable to write property ${d} to model: ${e}`)}if("object"!=typeof t[d])continue;const i=se.isPropertyModel(t,d);if(i){try{t[d]=se.build(t[d],"string"==typeof i?i:void 0)}catch(e){}continue}const l=a.Reflection.getPropertyDecorators(u.REFLECT,t,d).decorators;if(s=l.filter(t=>-1!==[e.ModelKeys.TYPE,u.TYPE].indexOf(t.key)),!s||!s.length)throw Error("failed to find decorators for property "+d);o=s.pop();const f=o.props.name?[o.props.name]:(Array.isArray(o.props.customTypes)?o.props.customTypes:[o.props.customTypes]).map(e=>"function"==typeof e?e():e),g=Object.values(e.ReservedModels).map(e=>e.toLowerCase());f.forEach(e=>{if("function"==typeof e&&(e=e.name?e.name:e()),-1===g.indexOf(e.toLowerCase()))try{switch(e){case"Array":case"Set":if(l.length){const r=l.find(e=>e.key===u.LIST);if(r){let a=r.props.clazz.find(e=>(e=(e="function"==typeof e?e():e).name?e.name:e,!ee.includes(e)));if(a="string"==typeof a?a:a(),a="string"==typeof a?a:a.name,"Array"===e&&(t[d]=t[d].map(e=>["object","function"].includes(typeof e)&&a?se.build(e,a):e)),"Set"===e){const e=new Set;for(const r of t[d])["object","function"].includes(typeof r)&&a?e.add(se.build(r,a)):e.add(r);t[d]=e}}}break;default:void 0!==t[d]&&se.get(e)&&(t[d]=se.build(t[d],e))}}catch(e){}})}return t}static setBuilder(e){te=e}static getBuilder(){return te||se.fromModel}static getRegistry(){return re||(re=new ae),re}static setRegistry(e){re=e}static register(e,t){return se.getRegistry().register(e,t)}static get(e){return se.getRegistry().get(e)}static build(e={},t){return se.getRegistry().build(e,t)}static getMetadata(e){return z(e)}static getAttributes(t){const r=[];let a=t instanceof se?Object.getPrototypeOf(t):t.prototype;for(;null!=a;){const t=a[e.ModelKeys.ATTRIBUTE];t&&r.push(...t),a=Object.getPrototypeOf(a)}return r}static equals(e,t,...r){return a.isEqual(e,t,...r)}static hasErrors(e,t,...r){return W(e,t,...r)}static serialize(t){const r=Reflect.getMetadata(se.key(e.ModelKeys.SERIALIZATION),t.constructor);return r&&r.serializer?ne.serialize(this,r.serializer,...r.args||[]):ne.serialize(t)}static hash(t){const r=Reflect.getMetadata(se.key(e.ModelKeys.HASHING),t.constructor);return r&&r.algorithm?D.hash(t,r.algorithm,...r.args||[]):D.hash(t)}static key(e){return x(e)}static isModel(e){try{return e instanceof se||!!se.getMetadata(e)}catch(e){return!1}}static isPropertyModel(t,r){if(se.isModel(t[r]))return!0;const a=Reflect.getMetadata(e.ModelKeys.TYPE,t,r);return se.get(a.name)?a.name:void 0}static describe(t,r){const a=se.key(e.ModelKeys.DESCRIPTION);return r?(t=t instanceof se?t:new t,Reflect.getMetadataKeys(t.constructor,r.toString()).find(e=>e===a)?.toString()||t.toString()):Reflect.getMetadata(se.key(e.ModelKeys.DESCRIPTION),t instanceof se?t.constructor:t)||t.toString()}}const oe="json";class ie{constructor(){}preSerialize(t){const r=Object.assign({},t),a=z(t);return r[e.ModelKeys.ANCHOR]=a||t.constructor.name,r}deserialize(t){const r=JSON.parse(t),a=r[e.ModelKeys.ANCHOR];if(!a)throw Error("Could not find class reference in serialized model");return se.build(r,a)}serialize(e){return JSON.stringify(this.preSerialize(e))}}class ne{static{this.current=oe}static{this.cache={json:new ie}}constructor(){}static get(e){if(e in this.cache)return this.cache[e];throw Error("No serialization method registered under "+e)}static register(e,t,r=!1){if(e in this.cache)throw Error(`Serialization method ${e} already registered`);this.cache[e]=new t,r&&(this.current=e)}static serialize(e,t,...r){return t?this.get(t).serialize(e,...r):this.get(this.current).serialize(e,...r)}static deserialize(e,t,...r){return t?this.get(t).deserialize(e,...r):this.get(this.current).deserialize(e,...r)}static setDefault(e){this.current=this.get(e)}}function ce(...e){return a.apply(t=>(e.forEach(e=>{k.register({validator:t,validationKey:e,save:!0})}),t),a.metadata(k.key(u.VALIDATOR),e))}e.DateValidator=class extends H{constructor(e=p.DATE){super(e,Number.name,Date.name,String.name)}hasErrors(e,t={}){if(void 0!==e&&("string"==typeof e&&(e=new Date(e)),Number.isNaN(e.getDate()))){const{message:e=""}=t;return this.getMessage(e||this.message)}}},e.DateValidator=s.__decorate([ce(u.DATE),s.__metadata("design:paramtypes",[String])],e.DateValidator),e.DiffValidator=class extends H{constructor(e=p.DIFF){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[u.DIFF])}catch(e){return this.getMessage(e.message||this.message)}return a.isEqual(e,s)?this.getMessage(t.message||this.message,t.label||t[u.DIFF]):void 0}},e.DiffValidator=s.__decorate([ce(u.DIFF),s.__metadata("design:paramtypes",[String])],e.DiffValidator);const de=RegExp("^/(.+)/([gimus]*)$");e.PatternValidator=class extends H{constructor(e=p.PATTERN){super(e,"string")}getPattern(e){if(!de.test(e))return RegExp(e);const t=e.match(de);return RegExp(t[1],t[2])}hasErrors(e,t){if(!e)return;let{pattern:r}=t;if(!r)throw Error("Missing Pattern");return r="string"==typeof r?this.getPattern(r):r,r.lastIndex=0,r.test(e)?void 0:this.getMessage(t.message||this.message)}},e.PatternValidator=s.__decorate([ce(u.PATTERN),s.__metadata("design:paramtypes",[String])],e.PatternValidator),e.EmailValidator=class extends e.PatternValidator{constructor(e=p.EMAIL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t?.pattern||h.EMAIL})}},e.EmailValidator=s.__decorate([ce(u.EMAIL),s.__metadata("design:paramtypes",[String])],e.EmailValidator),e.EqualsValidator=class extends H{constructor(e=p.EQUALS){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[u.EQUALS])}catch(e){return this.getMessage(e.message||this.message)}return a.isEqual(e,s)?void 0:this.getMessage(t.message||this.message,t.label||t[u.EQUALS])}},e.EqualsValidator=s.__decorate([ce(u.EQUALS),s.__metadata("design:paramtypes",[String])],e.EqualsValidator);const le=e=>null===e?"null":e instanceof Date?"Date":Number.isNaN(e)?"NaN":e===1/0?"Infinity":e===-1/0?"-Infinity":Array.isArray(e)?"array":typeof e,ue=e=>void 0===e||e instanceof Date||"bigint"==typeof e||"number"==typeof e&&Number.isFinite(e);function fe(e,t){if(ue(e)&&ue(t))return!0;throw new TypeError(m(o.UNSUPPORTED_TYPES_COMPARISON,le(e),le(t)))}function ge(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(o.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,a=typeof t;if(r!==a){if("bigint"===r&&"number"===a)return t>Number(e);if("number"===r&&"bigint"===a)return Number(t)>e;throw new TypeError(m(o.TYPE_MISMATCH_COMPARISON,r,a))}if("number"===r&&"number"===a||"bigint"===r&&"bigint"===a){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(o.NAN_COMPARISON);return t>e}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(o.INVALID_DATE_COMPARISON);return e.getTime()<t.getTime()}throw new TypeError(m(o.UNSUPPORTED_TYPES_COMPARISON,le(e),le(t)))}function pe(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(o.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,a=typeof t;if(r!==a){if("bigint"===r&&"number"===a)return Number(e)>t;if("number"===r&&"bigint"===a)return e>Number(t);throw Error(m(o.TYPE_MISMATCH_COMPARISON,r,a))}if("number"===r&&"number"===a||"bigint"===r&&"bigint"===a){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(o.NAN_COMPARISON);return e>t}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(o.INVALID_DATE_COMPARISON);return e.getTime()>t.getTime()}throw new TypeError(m(o.UNSUPPORTED_TYPES_COMPARISON,le(e),le(t)))}function he(e,t,r){return k.registerDecorator(t,e),a.apply(R(t,r))}function ye(e,t="Array",r=p.LIST){const a=k.key(u.LIST),s={clazz:Array.isArray(e)?e.map(e=>e.name?e.name:e):[e.name?e.name:e],type:t,message:r,async:!1,description:`defines the attribute as a ${t} of ${e.name}`};return N.for(a).define({decorator:he,args:[ye,a,s]}).apply()}function me(e,...t){const r=(...t)=>new e(...t);return r.prototype=e.prototype,r(...t)}function Ee(e){if(e instanceof se)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,se.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,se.prototype)}throw Error("Could not find proper prototype to bind")}function Te(r){const s=(...t)=>{const s=me(r,...t);Ee(s);const o=se.getBuilder();return o&&o(s,t.length?t[0]:void 0),a.metadata(se.key(e.ModelKeys.MODEL),r.name)(s.constructor),s};return s.prototype=r.prototype,a.metadata(se.key(e.ModelKeys.MODEL),r.name)(r),Reflect.getMetadataKeys(r).forEach(e=>{Reflect.defineMetadata(e,Reflect.getMetadata(e,r),s)}),Object.defineProperty(s,"name",{writable:!1,enumerable:!0,configurable:!1,value:r.prototype.constructor.name}),Object.defineProperty(s,e.ModelKeys.ANCHOR,{writable:!1,enumerable:!1,configurable:!1,value:r}),t.Metadata.set(s,t.DecorationKeys.CONSTRUCTOR,r),se.register(s,r.name),s}e.GreaterThanValidator=class extends H{constructor(e=p.GREATER_THAN){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.GREATER_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!pe(e,a))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.GREATER_THAN])}}},e.GreaterThanValidator=s.__decorate([ce(u.GREATER_THAN),s.__metadata("design:paramtypes",[String])],e.GreaterThanValidator),e.GreaterThanOrEqualValidator=class extends H{constructor(e=p.GREATER_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[u.GREATER_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(fe(e,s)&&a.isEqual(e,s)||pe(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.GREATER_THAN_OR_EQUAL])}}},e.GreaterThanOrEqualValidator=s.__decorate([ce(u.GREATER_THAN_OR_EQUAL),s.__metadata("design:paramtypes",[String])],e.GreaterThanOrEqualValidator),e.LessThanValidator=class extends H{constructor(e=p.LESS_THAN){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.LESS_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!ge(e,a))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.LESS_THAN])}}},e.LessThanValidator=s.__decorate([ce(u.LESS_THAN),s.__metadata("design:paramtypes",[String])],e.LessThanValidator),e.LessThanOrEqualValidator=class extends H{constructor(e=p.LESS_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[u.LESS_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(fe(e,s)&&a.isEqual(e,s)||ge(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.LESS_THAN_OR_EQUAL])}}},e.LessThanOrEqualValidator=s.__decorate([ce(u.LESS_THAN_OR_EQUAL),s.__metadata("design:paramtypes",[String])],e.LessThanOrEqualValidator),e.ListValidator=class extends H{constructor(e=p.LIST){super(e,Array.name,Set.name)}hasErrors(e,t){if(!e||(Array.isArray(e)?!e.length:!e.size))return;const r=(Array.isArray(t.clazz)?t.clazz:[t.clazz]).map(e=>"string"==typeof e?e:e.name?e.name:e().name);let a,s=!0;for(let t=0;t<(Array.isArray(e)?e.length:e.size);t++)switch(a=e[t],typeof a){case"object":case"function":s=r.includes((a??{}).constructor?.name);break;default:s=r.some(e=>typeof a===e.toLowerCase())}return s?void 0:this.getMessage(t.message||this.message,r)}},e.ListValidator=s.__decorate([ce(u.LIST),s.__metadata("design:paramtypes",[String])],e.ListValidator),e.MaxLengthValidator=class extends H{constructor(e=p.MAX_LENGTH){super(e,String.name,Array.name)}hasErrors(e,t){if(void 0!==e)return e.length>t.maxlength?this.getMessage(t.message||this.message,t.maxlength):void 0}},e.MaxLengthValidator=s.__decorate([ce(u.MAX_LENGTH),s.__metadata("design:paramtypes",[String])],e.MaxLengthValidator),e.MaxValidator=class extends H{constructor(e=p.MAX){super(e,"number","Date","string")}hasErrors(e,t){if(void 0===e)return;let{max:r}=t;if(e instanceof Date&&!(r instanceof Date)&&(r=new Date(r),Number.isNaN(r.getDate())))throw Error("Invalid Max param defined");return e>r?this.getMessage(t.message||this.message,r):void 0}},e.MaxValidator=s.__decorate([ce(u.MAX),s.__metadata("design:paramtypes",[String])],e.MaxValidator),e.MinLengthValidator=class extends H{constructor(e=p.MIN_LENGTH){super(e,String.name,Array.name)}hasErrors(e,t){if(void 0!==e)return e.length<t.minlength?this.getMessage(t.message||this.message,t.minlength):void 0}},e.MinLengthValidator=s.__decorate([ce(u.MIN_LENGTH),s.__metadata("design:paramtypes",[String])],e.MinLengthValidator),e.MinValidator=class extends H{constructor(e=p.MIN){super(e,"number","Date","string")}hasErrors(e,t){if(void 0===e)return;let{min:r}=t;if(e instanceof Date&&!(r instanceof Date)&&(r=new Date(r),Number.isNaN(r.getDate())))throw Error("Invalid Min param defined");return r>e?this.getMessage(t.message||this.message,r):void 0}},e.MinValidator=s.__decorate([ce(u.MIN),s.__metadata("design:paramtypes",[String])],e.MinValidator),e.PasswordValidator=class extends e.PatternValidator{constructor(e=p.PASSWORD){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,[u.PATTERN]:t?.pattern||h.PASSWORD.CHAR8_ONE_OF_EACH})}},e.PasswordValidator=s.__decorate([ce(u.PASSWORD),s.__metadata("design:paramtypes",[Object])],e.PasswordValidator),e.RequiredValidator=class extends H{constructor(e=p.REQUIRED){super(e)}hasErrors(e,t={}){switch(typeof e){case"boolean":case"number":return void 0===e?this.getMessage(t.message||this.message):void 0;default:return e?void 0:this.getMessage(t.message||this.message)}}},e.RequiredValidator=s.__decorate([ce(u.REQUIRED),s.__metadata("design:paramtypes",[String])],e.RequiredValidator),e.StepValidator=class extends H{constructor(e=p.STEP){super(e,"number","string")}hasErrors(e,t){if(void 0!==e)return Number(e)%Number(t.step)!==0?this.getMessage(t.message||this.message,t.step):void 0}},e.StepValidator=s.__decorate([ce(u.STEP),s.__metadata("design:paramtypes",[String])],e.StepValidator),e.TypeValidator=class extends H{constructor(e=p.TYPE){super(e)}hasErrors(e,t){if(void 0===e)return;const{type:r,message:s,customTypes:o}=t;let i=o||r;return i=(Array.isArray(i)?i:[i]).map(e=>"string"==typeof e?e:("function"!=typeof e||e.name||(e=e()),e.name||e)),a.Reflection.evaluateDesignTypes(e,i)?void 0:this.getMessage(s||this.message,"string"==typeof i?i:Array.isArray(i)?i.join(", "):i,typeof e)}},e.TypeValidator=s.__decorate([ce(u.TYPE),s.__metadata("design:paramtypes",[String])],e.TypeValidator),k.register({validator:e.TypeValidator,validationKey:e.ModelKeys.TYPE,save:!1}),e.URLValidator=class extends e.PatternValidator{constructor(e=p.URL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t.pattern||h.URL})}},e.URLValidator=s.__decorate([ce(u.URL),s.__metadata("design:paramtypes",[String])],e.URLValidator);const Ae="##VERSION##",be="##PACKAGE##";t.Metadata.registerLibrary(be,Ae),e.ASYNC_META_KEY=n,e.AsyncValidator=class extends U{constructor(e=p.DEFAULT,...t){super(!0,e,...t)}},e.COMPARISON_ERROR_MESSAGES=o,e.ComparisonValidationKeys=l,e.DAYS_OF_WEEK_NAMES=g,e.DEFAULT_ERROR_MESSAGES=p,e.DEFAULT_PATTERNS=h,e.Decoration=N,e.DefaultFlavour=d,e.DefaultHashingMethod=L,e.DefaultSerializationMethod=oe,e.Hashing=D,e.JSONSerializer=ie,e.MONTH_NAMES=f,e.Model=se,e.ModelErrorDefinition=j,e.ModelRegistryManager=ae,e.PACKAGE_NAME=be,e.PathProxyEngine=V,e.Serialization=ne,e.VALIDATION_PARENT_KEY=i,e.VERSION=Ae,e.Validation=k,e.ValidationKeys=u,e.Validator=H,e.ValidatorRegistry=C,e.async=()=>e=>{Object.prototype.hasOwnProperty.call(e,n)||(e[n]=!0)},e.bindDateToString=T,e.bindModelPrototype=Ee,e.bulkModelRegister=(...e)=>{e.forEach(e=>{const t=e.constructor?e.constructor:e;se.register(t,e.name)})},e.construct=me,e.date=function e(t="dd/MM/yyyy",r=p.DATE){const a=k.key(u.DATE);return N.for(a).define({decorator:function(t,r){const s={[u.FORMAT]:t,message:r,types:[Date.name],description:"defines the attribute as a date with the format "+t,async:!1};return function(r,o){const i=new WeakMap;return Object.defineProperty(r,o,{configurable:!1,set(e){const r=Object.getOwnPropertyDescriptor(this,o);r&&!r.configurable||Object.defineProperty(this,o,{enumerable:!0,configurable:!1,get:()=>i.get(this),set:e=>{let r;try{r=_(t,e),i.set(this,r)}catch(e){}}}),this[o]=e},get(){return i.get(this)}}),he(e,a,s)(r,o)}},args:[t,r]}).apply()},e.dateFromFormat=E,e.description=t=>a.metadata(se.key(e.ModelKeys.DESCRIPTION),t),e.diff=function e(t,r){const a={label:r?.label||t,message:r?.message||p.DIFF,[u.DIFF]:t,description:"defines attribute as different to "+t};return he(e,k.key(u.DIFF),{...a,async:!1})},e.email=function e(t=p.EMAIL){const r=k.key(u.EMAIL),a={[u.PATTERN]:h.EMAIL.toString(),message:t,types:[String.name],description:"marks the attribute as an email",async:!1};return N.for(r).define({decorator:he,args:[e,r,a]}).apply()},e.eq=function e(t,r){const a={label:r?.label||t,message:r?.message||p.EQUALS,[u.EQUALS]:t,description:"defines attribute as equal to "+t};return he(e,k.key(u.EQUALS),{...a,async:!1})},e.findLastProtoBeforeObject=e=>{let t=Object.getPrototypeOf(e);if(t===Object.prototype)return e;for(;t!==Object.prototype;){if(t=Object.getPrototypeOf(t),t===Object.prototype)return t;if(Object.getPrototypeOf(t)===Object.prototype)return t}throw Error("Could not find proper prototype")},e.formatDate=M,e.getMetadata=z,e.getModelKey=x,e.getValidatableProperties=G,e.getValidationDecorators=K,e.gt=function e(t,r){const a={label:r?.label||t,message:r?.message||p.GREATER_THAN,[u.GREATER_THAN]:t,description:"defines attribute as greater than "+t};return he(e,k.key(u.GREATER_THAN),{...a,async:!1})},e.gte=function e(t,r){const a={label:r?.label||t,message:r?.message||p.GREATER_THAN_OR_EQUAL,[u.GREATER_THAN_OR_EQUAL]:t,description:"defines attribute as greater or equal to "+t};return he(e,k.key(u.GREATER_THAN_OR_EQUAL),{...a,async:!1})},e.hashCode=P,e.hashObj=v,e.hashedBy=(t,...r)=>a.metadata(se.key(e.ModelKeys.HASHING),{algorithm:t,args:r}),e.isGreaterThan=pe,e.isLessThan=ge,e.isValidDate=A,e.isValidForGteOrLteComparison=fe,e.jsTypes=ee,e.list=ye,e.lt=function e(t,r){const a={label:r?.label||t,message:r?.message||p.LESS_THAN,[u.LESS_THAN]:t,description:"defines attribute as less than to "+t};return he(e,k.key(u.LESS_THAN),{...a,async:!1})},e.lte=function e(t,r){const a={label:r?.label||t,message:r?.message||p.LESS_THAN_OR_EQUAL,[u.LESS_THAN_OR_EQUAL]:t,description:"defines attribute as less or equal to "+t};return he(e,k.key(u.LESS_THAN_OR_EQUAL),{...a,async:!1})},e.max=function e(t,r=p.MAX){const a=k.key(u.MAX),s={[u.MAX]:t,message:r,types:[Number.name,Date.name],description:`defines the max value of the attribute as ${t} (applies to numbers or Dates)`,async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.maxlength=function e(t,r=p.MAX_LENGTH){const a=k.key(u.MAX_LENGTH),s={[u.MAX_LENGTH]:t,message:r,types:[String.name,Array.name,Set.name],description:`defines the max length of the attribute as ${t} (applies to strings or lists)`,async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.min=function e(t,r=p.MIN){const a=k.key(u.MIN),s={[u.MIN]:t,message:r,types:[Number.name,Date.name],description:`defines the max value of the attribute as ${t} (applies to numbers or Dates)`,async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.minlength=function e(t,r=p.MIN_LENGTH){const a=k.key(u.MIN_LENGTH),s={[u.MIN_LENGTH]:t,message:r,types:[String.name,Array.name,Set.name],description:`defines the min length of the attribute as ${t} (applies to strings or lists)`,async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.model=()=>{const r=se.key(e.ModelKeys.MODEL);return t.Decoration.for(r).define(Te).apply()},e.modelBaseDecorator=Te,e.parseDate=_,e.password=function e(t=h.PASSWORD.CHAR8_ONE_OF_EACH,r=p.PASSWORD){const a=k.key(u.PASSWORD),s={[u.PATTERN]:t.toString(),message:r,types:[String.name],description:"attribute as a password",async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.pattern=function e(t,r=p.PATTERN){const a=k.key(u.PATTERN),s={[u.PATTERN]:"string"==typeof t?t:t.toString(),message:r,types:[String.name],description:`assigns the ${"string"===t?t:t.toString()} pattern to the attribute`,async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.prop=O,e.propMetadata=R,e.regexpParser=de,e.required=function e(t=p.REQUIRED){const r=k.key(u.REQUIRED),a={message:t,description:"defines the attribute as required",async:!1};return N.for(r).define({decorator:he,args:[e,r,a]}).apply()},e.serializedBy=(t,...r)=>a.metadata(se.key(e.ModelKeys.SERIALIZATION),{serializer:t,args:r}),e.set=(e,t=p.LIST)=>ye(e,"Set",t),e.sf=m,e.step=function e(t,r=p.STEP){const a=k.key(u.STEP),s={[u.STEP]:t,message:r,types:[Number.name],description:"defines the step of the attribute as "+t,async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.stringFormat=y,e.toConditionalPromise=F,e.twoDigitPad=b,e.type=function e(t,r=p.TYPE){const a=k.key(u.TYPE),s={customTypes:t,message:r,description:"defines the accepted types for the attribute",async:!1};return N.for(a).define({decorator:he,args:[e,a,s]}).apply()},e.url=function e(t=p.URL){const r=k.key(u.URL),a={[u.PATTERN]:h.URL.toString(),message:t,types:[String.name],description:"marks the attribute as an url",async:!1};return N.for(r).define({decorator:he,args:[e,r,a]}).apply()},e.validate=W,e.validateChildValue=$,e.validateDecorator=B,e.validateDecorators=X,e.validationMetadata=he,e.validator=ce},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@decaf-ts/decoration"),require("reflect-metadata"),require("@decaf-ts/reflection"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","@decaf-ts/decoration","reflect-metadata","@decaf-ts/reflection","tslib"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["decorator-validation"]={},e.decafTsDecoration,e.reflectMetadata,e.decafTsReflection,e.tslib); //# sourceMappingURL=decorator-validation.cjs.map