UNPKG

@decaf-ts/decorator-validation

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