UNPKG

@decaf-ts/decorator-validation

Version:
1 lines 54 kB
var e,t;e=this,t=function(e,t,r,s){"use strict";const a={EQUALS:"equals",DIFF:"different",LESS_THAN:"lessThan",LESS_THAN_OR_EQUAL:"lessThanOrEqual",GREATER_THAN:"greaterThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual"},n={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",ENUM:"enum",...a},o=["January","February","March","April","May","June","July","August","September","October","November","December"],i=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],c={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.",ENUM:"Value is not allowed. Must be one of {0}"},u={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},asd:"^(?:(?:(?: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\xa1-\uffff][a-z0-9\xa1-\uffff_-]{0,62})?[a-z0-9\xa1-\uffff]\\.)+(?:[a-z\xa1-\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$"};function d(e,...t){return e.replace(/{(\d+)}/g,(e,r)=>void 0!==t[r]?t[r].toString():"undefined")}const l=d,h={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"},g=Symbol("_parent"),f=Symbol("isAsync"),p=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,y=e=>void 0===e||e instanceof Date||"bigint"==typeof e||"number"==typeof e&&Number.isFinite(e);function m(e,t){if(y(e)&&y(t))return!0;throw new TypeError(l(h.UNSUPPORTED_TYPES_COMPARISON,p(e),p(t)))}function E(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(h.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,s=typeof t;if(r!==s){if("bigint"===r&&"number"===s)return t>Number(e);if("number"===r&&"bigint"===s)return Number(t)>e;throw new TypeError(l(h.TYPE_MISMATCH_COMPARISON,r,s))}if("number"===r&&"number"===s||"bigint"===r&&"bigint"===s){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(h.NAN_COMPARISON);return t>e}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(h.INVALID_DATE_COMPARISON);return e.getTime()<t.getTime()}throw new TypeError(l(h.UNSUPPORTED_TYPES_COMPARISON,p(e),p(t)))}function M(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(h.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,s=typeof t;if(r!==s){if("bigint"===r&&"number"===s)return Number(e)>t;if("number"===r&&"bigint"===s)return e>Number(t);throw Error(l(h.TYPE_MISMATCH_COMPARISON,r,s))}if("number"===r&&"number"===s||"bigint"===r&&"bigint"===s){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(h.NAN_COMPARISON);return e>t}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(h.INVALID_DATE_COMPARISON);return e.getTime()>t.getTime()}throw new TypeError(l(h.UNSUPPORTED_TYPES_COMPARISON,p(e),p(t)))}function T(e,t){return typeof e===t.toLowerCase()||null!=e&&"object"==typeof e&&e instanceof Object&&!!e.constructor&&e.constructor.name.toLowerCase()===t.toLowerCase()}function A(e,t){return!t.every(t=>!T(e,t))}function b(e,t){const r=(e=>"function"!=typeof e||e.name?e:e())(t);if("string"==typeof r)return T(e,r);if("function"!=typeof r)return!1;switch(r.name){case"String":return"string"==typeof e;case"Number":return"number"==typeof e;case"Boolean":return"boolean"==typeof e;case"BigInt":return"bigint"==typeof e;case"Symbol":return"symbol"==typeof e;case"Function":return"function"==typeof e;case"Array":return Array.isArray(e);case"Date":return e instanceof Date;case"Object":return"object"==typeof e}return e instanceof r}function N(e,t){return(Array.isArray(t)?t:[t]).some(t=>b(e,t))}function S(e){return e instanceof Set||e instanceof Map?e.size:e.length}class O{constructor(e,t=c.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 l(e,...t)}checkTypeAndHasErrors(e){return function(t,r,s,...a){return void 0!==t&&this.acceptedTypes?A(t,this.acceptedTypes)?e(t,r,s,...a):this.getMessage(c.TYPE,this.acceptedTypes.join(", "),"number"!=typeof t?typeof t:isNaN(t)?"NaN":typeof t):e(t,r,s,...a)}.bind(this)}static isValidator(e){return e.constructor&&!!e.hasErrors}}class _ extends O{constructor(e=c.DEFAULT,...t){super(!1,e,...t)}}class R{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(_.isValidator(t))return t;const r=new(t.default||t);return this.cache[e]=r,r}register(...e){e.forEach(e=>{if(_.isValidator(e)){if(e.validationKey in this.cache)return;this.cache[e.validationKey]=e}else{const{validationKey:t,validator:r,save:s}=e;if(t in this.cache)return;if(this.cache[t]=r,!s)return;const a={};a[t.toUpperCase()]=t,this.customKeyCache=Object.assign({},this.customKeyCache,a)}})}}var v;e.ModelKeys=void 0,(v=e.ModelKeys||(e.ModelKeys={})).DESCRIPTION="description",v.TYPE="design:type",v.MODEL="model",v.ANCHOR="__model",v.CONSTRUCTION="constructed-by",v.ATTRIBUTE="__attributes",v.HASHING="hashing",v.SERIALIZATION="serialization",v.DECORATORS="decorators",v.CONSTRUCTOR="__original";const P="json";class D{static{this.actingValidatorRegistry=void 0}constructor(){}static setRegistry(e,t){t&&D.actingValidatorRegistry&&D.actingValidatorRegistry.getKeys().forEach(r=>{const s=e.get(r);s&&e.register(t(s))}),D.actingValidatorRegistry=e}static getRegistry(){return D.actingValidatorRegistry||(D.actingValidatorRegistry=new R),D.actingValidatorRegistry}static get(e){return D.getRegistry().get(e)}static register(...e){return D.getRegistry().register(...e)}static key(e){return n.REFLECT+e}static keys(){return this.getRegistry().getKeys()}static registerDecorator(r,s){const a=t.Metadata.innerGet(Symbol.for(e.ModelKeys.DECORATORS),t.Metadata.key(n.REFLECT,r));a?.[r]||t.Metadata.set(e.ModelKeys.DECORATORS,t.Metadata.key(n.REFLECT,r),s)}static decoratorFromKey(r){try{return t.Metadata.innerGet(Symbol.for(e.ModelKeys.DECORATORS),t.Metadata.key(n.REFLECT,r))}catch(e){throw Error(`No decorator registered under ${r}: ${e}`)}}}function w(...e){return t.apply(t=>(e.forEach(e=>{D.register({validator:t,validationKey:e,save:!0})}),t),t.metadata(n.VALIDATOR,e))}function L(e,t,...r){if(e===t)return 0!==e||1/e==1/t;if(null==e||null==t)return e===t;if(typeof e!=typeof t)return!1;if(Number.isNaN(e)&&Number.isNaN(t))return!0;if("object"!=typeof e)return e===t;if(e instanceof Date&&t instanceof Date)return!(!isNaN(e.getTime())||!isNaN(t.getTime()))||e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(e instanceof Error&&t instanceof Error)return e.name===t.name&&e.message===t.message;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(!L(e[s],t[s],...r))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[s,a]of e)if(!t.has(s)||!L(a,t.get(s),...r))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(e.byteLength!==t.byteLength)return!1;if(e.byteOffset!==t.byteOffset)return!1;if(e.buffer.byteLength!==t.buffer.byteLength)return!1;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),s=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<r.length;e++)if(r[e]!==s[e])return!1;return!0}const s=Object.keys(e).filter(e=>!r.includes(e)),a=Object.keys(t).filter(e=>!r.includes(e));if(s.length!==a.length)return!1;for(const n of s){if(!a.includes(n))return!1;if(!L(e[n],t[n],...r))return!1}const n=Object.getOwnPropertySymbols(e).filter(e=>!r.includes(e.toString())),o=Object.getOwnPropertySymbols(t).filter(e=>!r.includes(e.toString()));if(n.length!==o.length)return!1;for(const s of n){if(!o.includes(s))return!1;if(!L(e[s],t[s],...r))return!1}return Object.getPrototypeOf(e)===Object.getPrototypeOf(t)}e.DateValidator=class extends _{constructor(e=c.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=r.__decorate([w(n.DATE),r.__metadata("design:paramtypes",[String])],e.DateValidator),e.DiffValidator=class extends _{constructor(e=c.DIFF){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[n.DIFF])}catch(e){return this.getMessage(e.message||this.message)}return L(e,s)?this.getMessage(t.message||this.message,t.label||t[n.DIFF]):void 0}},e.DiffValidator=r.__decorate([w(n.DIFF),r.__metadata("design:paramtypes",[String])],e.DiffValidator);const I=RegExp("^/(.+)/([gimus]*)$");function V(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 s=RegExp(r,"g").exec(e);if(!s||!s.groups)return new Date(e);const a=e=>{if(!e)return 0;const t=parseInt(e);return isNaN(t)?0:t},n=a(s.groups.year),i=a(s.groups.day),c=s.groups.ampm;let u=a(s.groups.hour);c&&(u="PM"===c?u+12:u);const d=a(s.groups.minutes),l=a(s.groups.seconds),h=a(s.groups.milis),g=s.groups.monthname,f=s.groups.monthnamesmall;let p=s.groups.month;if(g)p=o.indexOf(g);else if(f){const t=o.find(e=>e.toLowerCase().startsWith(f.toLowerCase()));if(!t)return new Date(e);p=o.indexOf(t)}else p=a(""+p);return new Date(n,p-1,i,u,d,l,h)}function H(e,t){if(e)return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>U(r,t)})}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>U(r,t)})}),e}function x(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function j(e){return 10>e?"0"+e:e.toString()}function U(e,t="yyyy/MM/dd"){const r=e.getDate(),s=e.getMonth(),a=e.getFullYear(),n=e.getHours(),c=e.getMinutes(),u=e.getSeconds(),d=e.getMilliseconds(),l=n%12,h=j(l),g=j(n),f=j(c),p=j(u),y=12>n?"AM":"PM",m=i[e.getDay()],E=m.substr(0,3),M=j(r),T=s+1,A=j(T),b=o[s],N=b.substr(0,3),S=a+"",O=S.substr(2,2);return(t=t.replace("hh",h).replace("h",l.toString()).replace("HH",g).replace("H",n.toString()).replace("mm",f).replace("m",c.toString()).replace("ss",p).replace("s",u.toString()).replace("S",d.toString()).replace("dd",M).replace("d",r.toString()).replace("EEEE",m).replace("EEE",E).replace("yyyy",S).replace("yy",O).replace("aaa",y)).indexOf("MMM")>-1?t.replace("MMMM",b).replace("MMM",N):t.replace("MM",A).replace("M",T.toString())}function C(e,t){let r;if(t){if(t instanceof Date)try{r=V(U(t,e),e)}catch(r){throw Error(l("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=V(t,e);else if("number"==typeof t)r=V(U(new Date(t),e),e);else{if(!x(t))throw Error("Invalid value provided "+t);try{r=V(U(new Date(t),e),e)}catch(r){throw Error(l("Could not convert date {0} to format: {1}",t,e))}}return H(r,e)}}function F(e,r,s){return t.apply(t.propMetadata(r,s))}function z(e,t,r){return D.registerDecorator(t,e),(e,s)=>F(0,`${n.REFLECT}.${s}.${t}`,r)(e,s)}function Y(e=c.REQUIRED){const r=n.REQUIRED,s={message:e,description:"defines the attribute as required",async:!1};return t.Decoration.for(r).define({decorator:z,args:[Y,r,s]}).apply()}function G(e,r=c.MIN){const s=n.MIN,a={[n.MIN]:e,message:r,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return t.Decoration.for(s).define({decorator:z,args:[G,s,a]}).apply()}function $(e,r=c.MAX){const s=n.MAX,a={[n.MAX]:e,message:r,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return t.Decoration.for(s).define({decorator:z,args:[$,s,a]}).apply()}function q(e,r=c.STEP){const s=n.STEP,a={[n.STEP]:e,message:r,description:"defines the step of the attribute as "+e,async:!1};return t.Decoration.for(s).define({decorator:z,args:[q,s,a]}).apply()}function K(e,r=c.MIN_LENGTH){const s=n.MIN_LENGTH,a={[n.MIN_LENGTH]:e,message:r,description:`defines the min length of the attribute as ${e} (applies to strings or lists)`,async:!1};return t.Decoration.for(s).define({decorator:z,args:[K,s,a]}).apply()}function Q(e,r=c.MAX_LENGTH){const s=n.MAX_LENGTH,a={[n.MAX_LENGTH]:e,message:r,description:`defines the max length of the attribute as ${e} (applies to strings or lists)`,async:!1};return t.Decoration.for(s).define({decorator:z,args:[Q,s,a]}).apply()}function k(e,r=c.PATTERN){const s=n.PATTERN,a={[n.PATTERN]:"string"==typeof e?e:e.toString(),message:r,description:`assigns the ${"string"===e?e:e.toString()} pattern to the attribute`,async:!1};return t.Decoration.for(s).define({decorator:z,args:[k,s,a]}).apply()}function B(e=c.EMAIL){const r=n.EMAIL,s={[n.PATTERN]:u.EMAIL.toString(),message:e,description:"marks the attribute as an email",async:!1};return t.Decoration.for(r).define({decorator:z,args:[B,r,s]}).apply()}function X(e=c.URL){const r=n.URL,s={[n.PATTERN]:u.URL.toString(),message:e,description:"marks the attribute as an url",async:!1};return t.Decoration.for(r).define({decorator:z,args:[X,r,s]}).apply()}function W(e,r=c.TYPE){const s=n.TYPE,a={customTypes:e,message:r,description:"defines the accepted types for the attribute",async:!1};return t.Decoration.for(s).define({decorator:z,args:[W,s,a]}).apply()}function Z(e="dd-MM-yyyy HH:mm:ss:S",r=c.DATE){const s=n.DATE;return t.Decoration.for(s).define({decorator:function(e,t){const r={[n.FORMAT]:e,message:t,description:"defines the attribute as a date with the format "+e,async:!1};return function(t,a){const n=new WeakMap;return Object.defineProperty(t,a,{configurable:!0,set(t){const r=Object.getOwnPropertyDescriptor(this,a);r&&!r.configurable||Object.defineProperty(this,a,{enumerable:!0,configurable:!1,get:()=>n.get(this),set:t=>{let r;try{r=C(e,t),n.set(this,r)}catch(e){}}}),this[a]=t},get(){return n.get(this)}}),z(Z,s,r)(t,a)}},args:[e,r]}).apply()}function J(e=u.PASSWORD.CHAR8_ONE_OF_EACH,r=c.PASSWORD){const s=n.PASSWORD,a={[n.PATTERN]:e.toString(),message:r,description:"attribute as a password",async:!1};return t.Decoration.for(s).define({decorator:z,args:[J,s,a]}).apply()}function ee(e,r="Array",s=c.LIST){const a=n.LIST,o={clazz:Array.isArray(e)?e:[e],type:r,message:s,async:!1,description:`defines the attribute as a ${r} of ${e.name}`};return t.Decoration.for(a).define({decorator:z,args:[ee,a,o]}).apply()}function te(e,t){return z(te,n.EQUALS,{label:t?.label||e,message:t?.message||c.EQUALS,[n.EQUALS]:e,description:"defines attribute as equal to "+e,async:!1})}function re(e,t){return z(re,n.DIFF,{label:t?.label||e,message:t?.message||c.DIFF,[n.DIFF]:e,description:"defines attribute as different to "+e,async:!1})}function se(e,t){return z(se,n.LESS_THAN,{label:t?.label||e,message:t?.message||c.LESS_THAN,[n.LESS_THAN]:e,description:"defines attribute as less than to "+e,async:!1})}function ae(e,t){return z(ae,n.LESS_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||c.LESS_THAN_OR_EQUAL,[n.LESS_THAN_OR_EQUAL]:e,description:"defines attribute as less or equal to "+e,async:!1})}function ne(e,t){return z(ne,n.GREATER_THAN,{label:t?.label||e,message:t?.message||c.GREATER_THAN,[n.GREATER_THAN]:e,description:"defines attribute as greater than "+e,async:!1})}function oe(e,t){return z(oe,n.GREATER_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||c.GREATER_THAN_OR_EQUAL,[n.GREATER_THAN_OR_EQUAL]:e,description:"defines attribute as greater or equal to "+e,async:!1})}function ie(e,r=c.ENUM){const s=n.ENUM,a={[n.ENUM]:e,message:r,description:"defines a list or an object of accepted values for the attribute",async:!1};return t.Decoration.for(s).define({decorator:z,args:[ie,s,a]}).apply()}e.PatternValidator=class extends _{constructor(e=c.PATTERN){super(e,"string")}getPattern(e){if(!I.test(e))return RegExp(e);const t=e.match(I);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=r.__decorate([w(n.PATTERN),r.__metadata("design:paramtypes",[String])],e.PatternValidator),e.EmailValidator=class extends e.PatternValidator{constructor(e=c.EMAIL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t?.pattern||u.EMAIL})}},e.EmailValidator=r.__decorate([w(n.EMAIL),r.__metadata("design:paramtypes",[String])],e.EmailValidator),e.EqualsValidator=class extends _{constructor(e=c.EQUALS){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[n.EQUALS])}catch(e){return this.getMessage(e.message||this.message)}return L(e,s)?void 0:this.getMessage(t.message||this.message,t.label||t[n.EQUALS])}},e.EqualsValidator=r.__decorate([w(n.EQUALS),r.__metadata("design:paramtypes",[String])],e.EqualsValidator),e.GreaterThanValidator=class extends _{constructor(e=c.GREATER_THAN){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[n.GREATER_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!M(e,s))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[n.GREATER_THAN])}}},e.GreaterThanValidator=r.__decorate([w(n.GREATER_THAN),r.__metadata("design:paramtypes",[String])],e.GreaterThanValidator),e.GreaterThanOrEqualValidator=class extends _{constructor(e=c.GREATER_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[n.GREATER_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(m(e,s)&&L(e,s)||M(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[n.GREATER_THAN_OR_EQUAL])}}},e.GreaterThanOrEqualValidator=r.__decorate([w(n.GREATER_THAN_OR_EQUAL),r.__metadata("design:paramtypes",[String])],e.GreaterThanOrEqualValidator),e.LessThanValidator=class extends _{constructor(e=c.LESS_THAN){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[n.LESS_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!E(e,s))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[n.LESS_THAN])}}},e.LessThanValidator=r.__decorate([w(n.LESS_THAN),r.__metadata("design:paramtypes",[String])],e.LessThanValidator),e.LessThanOrEqualValidator=class extends _{constructor(e=c.LESS_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[n.LESS_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(m(e,s)&&L(e,s)||E(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[n.LESS_THAN_OR_EQUAL])}}},e.LessThanOrEqualValidator=r.__decorate([w(n.LESS_THAN_OR_EQUAL),r.__metadata("design:paramtypes",[String])],e.LessThanOrEqualValidator),e.ListValidator=class extends _{constructor(e=c.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||"function"!=typeof e?e?.name:e().name);let s,a=!0;for(let r=0;r<(Array.isArray(e)?e.length:e.size);r++)s=[...e][r],a=(Array.isArray(t.clazz)?t.clazz:[t.clazz]).some(e=>b(s,e));return a?void 0:this.getMessage(t.message||this.message,r)}},e.ListValidator=r.__decorate([w(n.LIST),r.__metadata("design:paramtypes",[String])],e.ListValidator),e.MaxLengthValidator=class extends _{constructor(e=c.MAX_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return S(e)>t.maxlength?this.getMessage(t.message||this.message,t.maxlength):void 0}},e.MaxLengthValidator=r.__decorate([w(n.MAX_LENGTH),r.__metadata("design:paramtypes",[String])],e.MaxLengthValidator),e.MaxValidator=class extends _{constructor(e=c.MAX){super(e,Number.name,Date.name,String.name)}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=r.__decorate([w(n.MAX),r.__metadata("design:paramtypes",[String])],e.MaxValidator),e.MinLengthValidator=class extends _{constructor(e=c.MIN_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return S(e)<t.minlength?this.getMessage(t.message||this.message,t.minlength):void 0}},e.MinLengthValidator=r.__decorate([w(n.MIN_LENGTH),r.__metadata("design:paramtypes",[String])],e.MinLengthValidator),e.MinValidator=class extends _{constructor(e=c.MIN){super(e,Number.name,Date.name,String.name)}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=r.__decorate([w(n.MIN),r.__metadata("design:paramtypes",[String])],e.MinValidator),e.OptionValidator=class extends _{constructor(e=c.ENUM){super(e)}hasErrors(e,t){if(void 0!==e){if(Array.isArray(t.enum))return t.enum.includes(e)?void 0:this.getMessage(t.message||this.message,t.enum);if("object"==typeof t.enum){const r=Object.keys(t.enum);for(const s of r)if(t.enum[s]===e)return;return this.getMessage(t.message||this.message,Object.values(t.enum))}}}},e.OptionValidator=r.__decorate([w(n.ENUM),r.__metadata("design:paramtypes",[String])],e.OptionValidator),e.PasswordValidator=class extends e.PatternValidator{constructor(e=c.PASSWORD){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,[n.PATTERN]:t?.pattern||u.PASSWORD.CHAR8_ONE_OF_EACH})}},e.PasswordValidator=r.__decorate([w(n.PASSWORD),r.__metadata("design:paramtypes",[Object])],e.PasswordValidator),e.RequiredValidator=class extends _{constructor(e=c.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=r.__decorate([w(n.REQUIRED),r.__metadata("design:paramtypes",[String])],e.RequiredValidator),e.StepValidator=class extends _{constructor(e=c.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=r.__decorate([w(n.STEP),r.__metadata("design:paramtypes",[String])],e.StepValidator),e.TypeValidator=class extends _{constructor(e=c.TYPE){super(e)}hasErrors(e,t){if(void 0===e)return;const{type:r,message:s,customTypes:a}=t;let n=a||r;n=Array.isArray(n)?n:[n];const o=n.map(e=>"string"==typeof e?e:"function"!=typeof e||e.name?e?.name||e+"":e().name);return N(e,n)?void 0:this.getMessage(s||this.message,o.join(", "),typeof e)}},e.TypeValidator=r.__decorate([w(n.TYPE),r.__metadata("design:paramtypes",[String])],e.TypeValidator),D.register({validator:e.TypeValidator,validationKey:e.ModelKeys.TYPE,save:!1}),e.URLValidator=class extends e.PatternValidator{constructor(e=c.URL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t.pattern||u.URL})}},e.URLValidator=r.__decorate([w(n.URL),r.__metadata("design:paramtypes",[String])],e.URLValidator);class ce{static{this.current=P}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)}}class ue{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 s=Object.keys(e[r]).reduce((t,s)=>(t?t+="\n"+e[r][s]:t=e[r][s],t),void 0);return s&&(s=`${r} - ${s}`,t?t+="\n"+s:t=s),t},"")}}const de=e=>e[g],le=(e,t)=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw Error(l(h.PROPERTY_NOT_EXIST,t));return e[t]};class he{static create(e,t){const{getValue:r,getParent:s,ignoreUndefined:a,ignoreNull:n}={getParent:de,getValue:le,ignoreNull:!1,ignoreUndefined:!1,...t};return new Proxy({},{get:(t,o)=>"getValueFromPath"===o?t=>{const o=he.parsePath(t);let i=e;for(let e=0;e<o.length;e++){const c=o[e];if(".."===c){const r=s(i);if(!r||"object"!=typeof r)throw Error(l(h.CONTEXT_NOT_OBJECT_COMPARISON,e+1,t));i=r;continue}if(i=r(i,c),!a&&void 0===i)throw Error(l(h.PROPERTY_INVALID,t,c));if(!n&&null===i)throw Error(l(h.PROPERTY_INVALID,t,c))}return i}:t[o]})}static parsePath(e){if("string"!=typeof e||!e.trim())throw Error(l(h.INVALID_PATH,e));return e.match(/(\.\.|[^/.]+)/g)||[]}}function ge(e,t){return t?Promise.resolve(e):e}var fe;e.Primitives=void 0,(fe=e.Primitives||(e.Primitives={})).STRING="string",fe.NUMBER="number",fe.BOOLEAN="boolean",fe.BIGINT="bigint";const pe={STRING:String,OBJECT:Object,NUMBER:Number,BOOLEAN:Boolean,BIGINT:BigInt,DATE:Date},ye=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"];let me,Ee;class Me{constructor(e=t.Metadata.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={},r){if(!r&&!this.testFunction(e))throw Error("Provided obj is not a Model object");const s=r||t.Metadata.modelName(e.constructor);if(!(s in this.cache))throw Error(`Provided class ${s} is not a registered Model object`);return new this.cache[s](e)}static setBuilder(e){me=e}static getBuilder(){return me||Me.fromModel}static fromModel(e,r){let s;r||(r={});const a=t.Metadata.getAttributes(e),o=Object.getPrototypeOf(e);let i;for(const c of a){try{e[c]=r[c]??e[c]??void 0}catch(e){if(i=Object.getOwnPropertyDescriptor(o,c),!i||i.writable)throw Error(`Unable to write property ${c} to model: ${e}`)}if("object"!=typeof e[c])continue;const a=t.Metadata.isPropertyModel(e,c);if(a){try{e[c]=Me.getRegistry().build(e[c],"string"==typeof a?a:void 0)}catch(e){}continue}const u=t.Metadata.validationFor(e.constructor,c);if(u?.[n.LIST]&&(Array.isArray(e[c])||e[c]instanceof Set)){const t=u[n.LIST].clazz.map(e=>"function"!=typeof e||e.name?e:e()).find(e=>!ye.includes(e.name.toLowerCase()));if(Array.isArray(e[c])&&(e[c]=e[c].map(e=>["object","function"].includes(typeof e)&&t?Me.getRegistry().build(e,t.name):e)),e[c]instanceof Set){const r=new Set;for(const s of e[c])["object","function"].includes(typeof s)&&t?r.add(Me.getRegistry().build(s,t.name)):r.add(s);e[c]=r}continue}if(s=t.Metadata.allowedTypes(e.constructor,c),!s||!s.length)throw Error("failed to find decorators for property "+c);const d=s.map(e=>"function"!=typeof e||e.name?e:e()),l=Object.values(pe);d.forEach(t=>{if(!l.includes(t))try{t.name,void 0!==e[c]&&Me.getRegistry().get(t.name)&&(e[c]=Me.getRegistry().build(e[c],t.name))}catch(e){}})}return e}static getRegistry(){return Ee||(Ee=new Me),Ee}static setRegistry(e){Ee=e}}function Te(e,t,r){Object.hasOwnProperty.call(e,t)||(e[t]=r)}function Ae(e,t){Object.hasOwnProperty.call(e,t)&&delete e[t]}function be(e,t,r,...s){t&&Te(e,g,t),Te(e,f,!!r);const a=e.hasErrors(...s);return Ae(e,g),Ae(e,f),a}function Ne(e,t,r,s,a,...o){let i,c=!1;for(const u of s){const s=Me.getRegistry().get(u);if(s||(i=new ue({[e]:{[n.TYPE]:"Unable to verify type consistency, missing model registry for "+u}})),t instanceof s){c=!0,i=be(t,r,a,...o);break}}return c?i:i||new ue({[e]:{[n.TYPE]:"Value must be an instance of one of the expected types: "+s.join(", ")}})}function Se(e,...t){return t?.map(t=>("string"==typeof t&&t?.startsWith(e+".")&&(t=t.replace(e+".","")),t))}function Oe(t,r,s,a){const n=D.get(s.key);if(!n)throw Error("Missing validator for "+s.key);if(!a&&s.async)return;const o=s.key===e.ModelKeys.TYPE?[s]:s||{},i=he.create(t,{ignoreUndefined:!0,ignoreNull:!0}),c=s.key===e.ModelKeys.TYPE?o[0]:o;return ge(n.hasErrors(r,c,i),a)}function _e(r,s,a,o,i,...c){const u={};for(const d in o){const l={...o[d],key:d};if(!i&&l.async)continue;let h=Oe(r,a,l,i);if(d===n.LIST&&(!h||i)){const e=a instanceof Set?[...a]:a;if(e&&e.length>0){let a=l.class||l.clazz||l.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()),o=e.map(e=>{if(!["string","number","bigint"].includes(typeof e)){if(t.Metadata.isModel(e)){const t=Se(s,...c);return Ne(s,e,r,a.flat(),!!i,...t)}return n.includes(typeof e)?void 0:"Value has no validatable type"}});if(i)h=Promise.all(o).then(e=>e.every(e=>!e)?void 0:e);else{const e=o.every(e=>!e);h=o.length>0&&!e?o:void 0}}}const g=d===e.ModelKeys.TYPE?n.TYPE:d;h&&(u[g]=h)}if(!i)return Object.keys(u).length>0?u:void 0;const d=Object.keys(u),l=Object.values(u);return Promise.all(l).then(e=>{const t={};for(let r=0;r<e.length;r++){const s=e[r];void 0!==s&&(t[d[r]]=s)}return Object.keys(t).length>0?t:void 0})}function Re(r,s,...a){const o=t.Metadata.validatableProperties(r.constructor,...a),i={},c={};for(const u of o){const o=u+"",d=r[u],l=t.Metadata.validationFor(r.constructor,u)||{},{designTypes:h}=t.Metadata.getPropDesignTypes(r.constructor,u);if(!h)continue;if(h.some(e=>[Array.name,Set.name].includes(e.name))){if(!l||!Object.keys(l).includes(n.LIST)){i[o]={[n.TYPE]:`Array or Set property '${o}' requires a @list decorator`};continue}if(d&&!(Array.isArray(d)||d instanceof Set)){i[o]={[n.TYPE]:`Property '${u+""}' must be either an Array or a Set`};continue}}const g=_e(r,o,d,l,s,...a)||{};if(t.Metadata.isPropertyModel(r,o)&&null!=d){const t=h.map(e=>Me.getRegistry().get(e.name||e)).find(e=>!!e),i=h.map(e=>"function"==typeof e?e.name?e.name.toLowerCase():e()?.name.toLowerCase():e.toLowerCase());if(t&&d instanceof t){const e=Se(o,...a);c[o]=be(d,r,s,...e)}else i.includes(typeof d)||(g[n.TYPE]=t?"Value must be an instance of "+t.name:`Unable to verify type consistency, missing model registry for ${h.toString()} on prop ${o}`,delete g[e.ModelKeys.TYPE])}(Object.keys(g).length>0||s)&&(i[o]=g),s||Object.entries(c[o]||{}).forEach(([e,t])=>{void 0!==t&&(i[`${o}.${e}`]=t)})}if(!s)return Object.keys(i).length>0?new ue(i):void 0;const u=i,d=Object.keys(u),l=Object.values(u);return Promise.allSettled(l).then(async e=>{const t={};for(const[e,r]of Object.entries(c)){const s=await r;s&&Object.entries(s).forEach(([r,s])=>{void 0!==s&&(t[[e,r].join(".")]=s)})}for(let r=0;r<e.length;r++){const s=d[r],a=e[r];"fulfilled"===a.status&&void 0!==a.value?t[s]=a.value:"rejected"===a.status&&(t[s]=a.reason instanceof Error?a.reason.message:(a.reason||"Validation failed")+"")}return Object.keys(t).length>0?new ue(t):void 0})}function ve(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 Pe(e){const t=(e,t)=>{const r=s(t);return"string"==typeof r?s((e||"")+s(t)):(e=((e=e||0)<<5)-e+r)&e},r=ve,s=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),a=Object.values(e).reduce(t,0);return("number"==typeof a?Math.abs(a):a).toString()}const De="default";class we{static{this.current=De}static{this.cache={default:Pe}}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)}}class Le{constructor(e=void 0){}isAsync(){return!!(this[f]??this?.constructor[f])}hasErrors(...e){return Re(this,this.isAsync(),...e)}equals(e,...t){return L(this,e,...t)}compare(e,...r){const s=t.Metadata.properties(this.constructor);if(!s||!s.length)return;const a=s.reduce((t,s)=>{const a=s;if(r.includes(a))return t;if(void 0===this[a]&&void 0!==e[a])return t[a]={other:e[a],current:void 0},t;if(void 0!==this[a]&&void 0===e[a])return t[a]={other:void 0,current:this[a]},t;if(L(this[a],e[a]))return t;if(Le.isPropertyModel(this,a)){const r=this[a].compare(e[a]);return r&&(t[a]=r),t}if(Array.isArray(this[a])&&Array.isArray(e[a])){if(this[a].length!==e[a].length)return t[a]={current:this[a],other:e[a]},t;const r=this[a].map((t,r)=>L(t,e[a][r])?null:t instanceof Le&&e[a][r]instanceof Le?t.compare(e[a][r]):{current:t,other:e[a][r]});return r.some(e=>null!==e)&&(t[a]=r),t}return t[a]={other:e[a],current:this[a]},t},{});return Object.keys(a).length>0?a:void 0}serialize(){return Le.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return Le.hash(this)}static deserialize(r){let s;try{s=t.Metadata.get(this.constructor,e.ModelKeys.SERIALIZATION)}catch(e){s=void 0}return s&&s.serializer?ce.deserialize(r,s.serializer,...s.args||[]):ce.deserialize(r)}static fromObject(e,t){t||(t={});for(const r of Le.getAttributes(e))e[r]=t[r]??e[r]??void 0;return e}static fromModel(e,t){return Me.fromModel(e,t)}static setBuilder(e){Me.setBuilder(e)}static getBuilder(){return Me.getBuilder()}static getRegistry(){return Me.getRegistry()}static setRegistry(e){Me.setRegistry(e)}static register(e,t){return Me.getRegistry().register(e,t)}static get(e){return Me.getRegistry().get(e)}static build(e={},t){return Le.getRegistry().build(e,t)}static getAttributes(e){return t.Metadata.getAttributes(e)}static equals(e,t,...r){return L(e,t,...r)}static hasErrors(e,t,...r){return Re(e,t,...r)}static serialize(r){let s;try{s=t.Metadata.get(r.constructor,e.ModelKeys.SERIALIZATION)}catch(e){s=void 0}return s&&s.serializer?ce.serialize(this,s.serializer,...s.args||[]):ce.serialize(r)}static hash(r){const s=t.Metadata.get(r.constructor,e.ModelKeys.HASHING);return s&&s.algorithm?we.hash(r,s.algorithm,...s.args||[]):we.hash(r)}static isModel(e){return t.Metadata.isModel(e)}static isPropertyModel(e,r){return t.Metadata.isPropertyModel(e,r)}static describe(e,r){return t.Metadata.description(e,r)}}function Ie(e){return e instanceof He?e.build():new Date(e)}function Ve(e,t,r){const s=new Date(e);return r.years&&s.setFullYear(s.getFullYear()+t*r.years),r.months&&s.setMonth(s.getMonth()+t*r.months),r.days&&s.setDate(s.getDate()+t*r.days),r.hours&&s.setHours(s.getHours()+t*r.hours),r.minutes&&s.setMinutes(s.getMinutes()+t*r.minutes),r.seconds&&s.setSeconds(s.getSeconds()+t*r.seconds),s}t.Metadata.validationFor=((e,r,s)=>{const a=t.Metadata.get(e);if(!a)return;if(!r)return a.validation;if(!a.validation)return;if(!a.validation[n.TYPE]){const{designTypes:s}=t.Metadata.getPropDesignTypes(e,r);a.validation[r]&&s?.length&&s[0]!==pe.OBJECT&&(a.validation[r][n.TYPE]={customTypes:s,message:c.TYPE,description:"defines the accepted types for the attribute",async:!1})}if(!s)return a.validation[r];const o=a.validation[r];return o?o[s]:void 0}).bind(t.Metadata),t.Metadata.modelName=(e=>{const r=t.Metadata.constr(e);return r?r.name:e.name}).bind(t.Metadata),t.Metadata.validatableProperties=((e,...r)=>{const s=t.Metadata.validationFor(e),a=s?Object.keys(s):[];return[...new Set([...Le.getAttributes(e),...a])].filter(e=>!r||!r?.includes(e))}).bind(t.Metadata),t.Metadata.allowedTypes=((e,r)=>{const s=t.Metadata.type(e,r);if(!s)throw Error("No metadata found for property "+r);const a=t.Metadata.validationFor(e,r);return a&&a[n.TYPE]&&"function"==typeof a[n.TYPE]?.customTypes[Symbol.iterator]?[...a[n.TYPE].customTypes]:[s]}).bind(t.Metadata),t.Metadata.getPropDesignTypes=((e,r)=>{const s=t.Metadata.get(e),a=t.Metadata.type(e,r),o=s?.[n.REFLECT]?.[r];if(!(a||o&&o[n.TYPE]))return{};const i=o&&o[n.TYPE]?[o[n.TYPE].customTypes]:[a];if(!i?.length)return{};const c=i[0],u=c.class||c.clazz||c.customTypes||c;return{designTypes:(Array.isArray(u)?u:[u]).map(e=>"function"!=typeof e||e.name?e:e()),designType:u}}).bind(t.Metadata),t.Metadata.isModel=(e=>{try{if(e instanceof Le)return!0;const r=t.Metadata.constr(e);return!(!r||r===e||!t.Metadata.modelName(r))}catch(e){return!1}}).bind(t.Metadata),t.Metadata.isPropertyModel=((e,r)=>{if(t.Metadata.isModel(e[r]))return!0;const s=t.Metadata.type(e.constructor,r);return s&&Me.getRegistry().get(s.name)?s.name:void 0}).bind(t.Metadata),t.Metadata.getAttributes=(e=>{const r=e instanceof Le?e.constructor:e,s=new Set,a=e=>{if(!e)return[];const r=t.Metadata.constr(e),n=a(Object.getPrototypeOf(r)),o=t.Metadata.properties(e)??[];for(const e of o)s.has(e)||(s.add(e),n.push(e));return n};return a(r)}).bind(t.Metadata);class He{constructor(){this.years=0,this.months=0,this.days=0,this.hours=0,this.minutes=0,this.seconds=0}static Years(e){return(new He).Years(e)}static Months(e){return(new He).Months(e)}static Days(e){return(new He).Days(e)}static Hours(e){return(new He).Hours(e)}static Minutes(e){return(new He).Minutes(e)}static Seconds(e){return(new He).Seconds(e)}static Now(){return new Date}static Tomorrow(){return He.Days(1).from(He.Now())}static Yesterday(){return He.Days(1).until(He.Now())}static DaysAgo(e){return He.Days(e).until(He.Now())}static NextDays(e){return He.Days(e).from(He.Now())}static YearsAgo(e){return He.Years(e).until(He.Now())}static NextYears(e){return He.Years(e).from(He.Now())}static MonthsAgo(e){return He.Months(e).until(He.Now())}static NextMonths(e){return He.Months(e).from(He.Now())}static HoursAgo(e){return He.Hours(e).until(He.Now())}static NextHours(e){return He.Hours(e).from(He.Now())}static MinutesAgo(e){return He.Minutes(e).until(He.Now())}static NextMinutes(e){return He.Minutes(e).from(He.Now())}static SecondsAgo(e){return He.Seconds(e).until(He.Now())}static NextSeconds(e){return He.Seconds(e).from(He.Now())}Years(e){return this.years+=e,this}Months(e){return this.months+=e,this}Days(e){return this.days+=e,this}Hours(e){return this.hours+=e,this}Minutes(e){return this.minutes+=e,this}Seconds(e){return this.seconds+=e,this}build(e=new Date){return this.from(e)}from(e){return Ve(Ie(e),1,this.offsets())}past(e){return this.from(e)}after(e){return this.from(e)}until(e){return Ve(Ie(e),-1,this.offsets())}before(e){return this.until(e)}ago(e=new Date){return this.until(e)}Now(){return He.Now()}Tomorrow(){return He.Tomorrow()}Yesterday(){return He.Yesterday()}DaysAgo(e){return He.DaysAgo(e)}NextDays(e){return He.NextDays(e)}YearsAgo(e){return He.YearsAgo(e)}NextYears(e){return He.NextYears(e)}MonthsAgo(e){return He.MonthsAgo(e)}NextMonths(e){return He.NextMonths(e)}HoursAgo(e){return He.HoursAgo(e)}NextHours(e){return He.NextHours(e)}MinutesAgo(e){return He.MinutesAgo(e)}NextMinutes(e){return He.NextMinutes(e)}SecondsAgo(e){return He.SecondsAgo(e)}NextSeconds(e){return He.NextSeconds(e)}offsets(){return{years:this.years,months:this.months,days:this.days,hours:this.hours,minutes:this.minutes,seconds:this.seconds}}}const xe=He;class je{constructor(){}preSerialize(r,...s){const a=Object.assign({},r);let n;try{n=t.Metadata.modelName(r.constructor)}catch(e){n=void 0}return a[e.ModelKeys.ANCHOR]=n||r.constructor.name,a}deserialize(t,...r){const s=JSON.parse(t),a=s[e.ModelKeys.ANCHOR];if(!a)throw Error("Could not find class reference in serialized model");return Le.build(s,a)}serialize(e,...t){return JSON.stringify(this.preSerialize(e))}}function Ue(e,...t){const r=(...t)=>new e(...t);return r.prototype=e.prototype,r(...t)}function Ce(e){if(e instanceof Le)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,Le.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,Le.prototype)}throw Error("Could not find proper prototype to bind")}function Fe(r){const s=(...e)=>{const t=Ue(r,...e);Ce(t);const s=Le.getBuilder();return s&&s(t,e.length?e[0]:void 0),t};return s.prototype=r.prototype,Object.setPrototypeOf(s,r),Object.defineProperty(s,"name",{writable:!1,enumerable:!0,configurable:!1,value:r.prototype.constructor.name}),t.metadata(e.ModelKeys.CONSTRUCTOR,r)(s),Le.register(s,r.name),s}function ze(){const r=e.ModelKeys.MODEL;return t.Decoration.for(r).define(Fe).apply()}ce.cache={json:new je};class Ye{constructor(e,t,r){this.parent=e,this.attr=t,this.declaredType=r,this.decorators=[]}decorate(...e){for(const t of e){if(this.decorators.includes(t))throw Error(`Decorator "${t}" has already been used`);this.decorators.push(t)}return this.parent}undecorate(...e){for(const t of e){const e=this.decorators.indexOf(t);if(0>e)throw Error(`Decorator "${t}" is not applied to ${this.attr}`);this.decorators.splice(e,1)}return this.parent}required(e){const t=Ye.asMeta(e),r="string"==typeof e?e:Ye.resolveMessage(t);return this.decorate(Y(r))}min(e,t){const r=Ye.asMeta(e),s=r?.[n.MIN]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${n.MIN} for ${this.attr+""}`);return this.decorate(G(s,Ye.resolveMessage(r,t)))}max(e,t){const r=Ye.asMeta(e),s=r?.[n.MAX]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${n.MAX} for ${this.attr+""}`);return this.decorate($(s,Ye.resolveMessage(r,t)))}step(e,t){const r=Ye.asMeta(e),s=r?.[n.STEP]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${n.STEP} for ${this.attr+""}`);return this.decorate(q(s,Ye.resolveMessage(r,t)))}minlength(e,t){const r=Ye.asMeta(e),s=r?.[n.MIN_LENGTH]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${n.MIN_LENGTH} for ${this.attr+""}`);return this.decorate(K(s,Ye.resolveMessage(r,t)))}maxlength(e,t){const r=Ye.asMeta(e),s=r?.[n.MAX_LENGTH]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${n.MAX_LENGTH} for ${this.attr+""}`);return this.decorate(Q(s,Ye.resolveMessage(r,t)))}pattern(e,t){const r=Ye.asMeta(e),s=r?.[n.PATTERN]??(r?void 0:e),a=Ye.patternFromString(s)??/.*/;return this.decorate(k(a,Ye.resolveMessage(r,t)))}email(e){const t=Ye.asMeta(e),r="string"==typeof e?e:Ye.resolveMessage(t);return this.decorate(B(r))}url(e){const t=Ye.asMeta(e),r="string"==typeof e?e:Ye.resolveMessage(t);return this.decorate(X(r))}type(e,t){const r=Ye.asMeta(e),s=r?.customTypes??r?.type??(r?void 0:e);return this.decorate(W(s,Ye.resolveMessage(r,t)))}date(e,t){const r=Ye.asMeta(e),s=r?.[n.FORMAT]??(r?void 0:e);return this.decorate(Z(s,Ye.resolveMessage(r,t)))}password(e,t){const r=Ye.asMeta(e),s=r?.[n.PATTERN]??(r?void 0:e),a=Ye.patternFromString(s);return this.decorate(J(a,Ye.resolveMessage(r,t)))}list(e,t,r){const s=Ye.asMeta(e),a=s?.clazz??(s?void 0:e),n=s?.type??t;return this.decorate(ee(a,n,Ye.resolveMessage(s,r)))}set(e,t){return Ye.isMetadataPayload(e)?this.list(e):this.list(e,"Set",t)}enum(e,t){const r=Ye.asMeta(e),s=r?.[n.ENUM]??(r?void 0:e);return this.decorate(ie(s,Ye.resolveMessage(r,t)))}option(e,t){return this.enum(e,t)}static isMetadataPayload(e){return!(!e||e instanceof Date||e instanceof RegExp||Array.isArray(e)||"object"!=typeof e)}static asMeta(e){return Ye.isMetadataPayload(e)?e:void 0}static resolveMessage(e,t){return e?.message??t}static patternFromString(e){if(!e)return;if(e instanceof RegExp)return e;const t=e.match(/^\/(.+)\/([gimsuy]*)$/);return t?RegExp(t[1],t[2]):RegExp(e)}resolveComparison(e,t,r){const s=Ye.asMeta(e);return s?{target:s[t],options:{label:s.label,message:s.message}}:{target:e,options:r}}equals(e,t){const{target:r,options:s}=this.resolveComparison(e,n.EQUALS,t);return this.decorate(te(r,s))}eq(e,t){return this.equals(e,t)}different(e,t){const{target:r,options:s}=this.resolveComparison(e,n.DIFF,t);return this.decorate(re(r,s))}diff(e,t){return this.different(e,t)}lessThan(e,t){const{target:r,options:s}=this.resolveComparison(e,n.LESS_THAN,t);return this.decorate(se(r,s))}lt(e,t){return this.lessThan(e,t)}lessThanOrEqual(e,t){const{target:r,options:s}=this.resolveComparison(e,n.LESS_THAN_OR_EQUAL,t);return this.decorate(ae(r,s))}lte(e,t){return this.lessThanOrEqual(e,t)}greaterThan(e,t){const{target:r,options:s}=this.resolveComparison(e,n.GREATER_THAN,t);return this.decorate(ne(r,s))}gt(e,t){return this.greaterThan(e,t)}greaterThanOrEqual(e,t){const{target:r,options:s}=this.resolveComparison(e,n.GREATER_THAN_OR_EQUAL,t);return this.decorate(oe(r,s))}gte(e,t){return this.greaterThanOrEqual(e,t)}description(e){return this.decorate(t.description(e))}build(e){const r=e.prototype,s=this.attr;Object.getOwnPropertyDescriptor(r,s)||Object.defineProperty(r,s,{configurable:!0,enumerable:!0,writable:!0,value:void 0}),this.declaredType&&Reflect.defineMetadata(t.DecorationKeys.DESIGN_TYPE,this.declaredType,r,s),t.prop()(r,s),this.decorators.forEach(e=>{try{e(r,s)}catch(e){throw Error(`Failed to apply decorator to property "${this.attr}": ${e}`)}})}}class Ge{constructor(e,t,r){this.parent=e,this.attribute=t,this.collection=r}ofPrimitives(e,t){return this.attribute.list(e,this.collection,t),this.parent}ofModel(){const e=$e.builder(),t=e.build;let r;return this.attribute.list(()=>(r||(r=Reflect.apply(t,e,[])),r),this.collection),e.build=new Proxy(t,{apply:(e,t,s)=>(r=Reflect.apply(e,t,s),this.parent)}),e}}class $e extends s.ObjectAccumulator{constructor(){super(...arguments),this.attributes=new Map,this._classDecorators=[]}setName(e){return this._name=e,this}description(e){return this._description=e,this}decorateClass(e){return this._classDecorators.push(e),this}attribute(e,t){const r=this.attributes.get(e);if(r){if(r.declaredType!==t)throw Error(`Attribute "${e+""}" already exists with a different type`);return r}const s=new Ye(this,e,t);return this.attributes.set(e,s),s}string(e){return this.attribute(e,String)}number(e){return this.attribute(e,Number)}date(e){return this.attribute(e,Date)}bigint(e){return this.attribute(e,BigInt)}instance(e,t){return this.attribute(t,e)}model(e){const t=new $e;return t.build=new Proxy(t.build,{apply:(t,r,s)=>{const a=Reflect.apply(t,r,s);return this.instance(a,e)}}),t}listOf(e,t="Array"){const r="Set"===t?Set:Array,s=this.attribute(e,r);return new Ge(this,s,t)}build(){if(!this._name)throw Error("name i