@decaf-ts/decorator-validation
Version:
simple decorator based validation engine
1 lines • 52.3 kB
JavaScript
import{Metadata as e,apply as t,metadata as r,Decoration as s,propMetadata as n,description as i,DecorationKeys as o,prop as a}from"@decaf-ts/decoration";import{__decorate as c,__metadata as u}from"tslib";import{ObjectAccumulator as l}from"typed-object-accumulator";const d={EQUALS:"equals",DIFF:"different",LESS_THAN:"lessThan",LESS_THAN_OR_EQUAL:"lessThanOrEqual",GREATER_THAN:"greaterThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual"},f={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",...d},g=["January","February","March","April","May","June","July","August","September","October","November","December"],h=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],p={REQUIRED:"This field is required",MIN:"The minimum value is {0}",MAX:"The maximum value is {0}",MIN_LENGTH:"The minimum length is {0}",MAX_LENGTH:"The maximum length is {0}",PATTERN:"The value does not match the pattern",EMAIL:"The value is not a valid email",URL:"The value is not a valid URL",TYPE:"Invalid type. Expected {0}, received {1}",STEP:"Invalid value. Not a step of {0}",DATE:"Invalid value. not a valid Date",DEFAULT:"There is an Error",PASSWORD:"Must be at least 8 characters and contain one of number, lower and upper case letters, and special character (@$!%*?&_-.,)",LIST:"Invalid list of {0}",MODEL_NOT_FOUND:"No model registered under {0}",EQUALS:"This field must be equal to field {0}",DIFF:"This field must be different from field {0}",LESS_THAN:"This field must be less than field {0}",LESS_THAN_OR_EQUAL:"This field must be less than or equal to field {0}",GREATER_THAN:"This field must be greater than field {0}",GREATER_THAN_OR_EQUAL:"This field must be greater than or equal to field {0}",UNIQUE:"Duplicate found, this field must be unique.",ENUM:"Value is not allowed. Must be one of {0}"},y={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 m(e,...t){return e.replace(/{(\d+)}/g,(e,r)=>void 0!==t[r]?t[r].toString():"undefined")}const E=m,b={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"},A=Symbol("_parent"),T=Symbol("isAsync"),N=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,M=e=>void 0===e||e instanceof Date||"bigint"==typeof e||"number"==typeof e&&Number.isFinite(e);function S(e,t){if(M(e)&&M(t))return!0;throw new TypeError(E(b.UNSUPPORTED_TYPES_COMPARISON,N(e),N(t)))}function O(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(b.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(E(b.TYPE_MISMATCH_COMPARISON,r,s))}if("number"===r&&"number"===s||"bigint"===r&&"bigint"===s){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(b.NAN_COMPARISON);return t>e}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(b.INVALID_DATE_COMPARISON);return e.getTime()<t.getTime()}throw new TypeError(E(b.UNSUPPORTED_TYPES_COMPARISON,N(e),N(t)))}function R(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(b.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(E(b.TYPE_MISMATCH_COMPARISON,r,s))}if("number"===r&&"number"===s||"bigint"===r&&"bigint"===s){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(b.NAN_COMPARISON);return e>t}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(b.INVALID_DATE_COMPARISON);return e.getTime()>t.getTime()}throw new TypeError(E(b.UNSUPPORTED_TYPES_COMPARISON,N(e),N(t)))}function v(e,t){return typeof e===t.toLowerCase()||null!=e&&"object"==typeof e&&e instanceof Object&&!!e.constructor&&e.constructor.name.toLowerCase()===t.toLowerCase()}function _(e,t){return!t.every(t=>!v(e,t))}function P(e,t){const r=(e=>"function"!=typeof e||e.name?e:e())(t);if("string"==typeof r)return v(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 w(e,t){return(Array.isArray(t)?t:[t]).some(t=>P(e,t))}function L(e){return e instanceof Set||e instanceof Map?e.size:e.length}class D{constructor(e,t=p.DEFAULT,...r){this.async=e,this.message=t,r.length&&(this.acceptedTypes=r),this.acceptedTypes&&(this.hasErrors=this.checkTypeAndHasErrors(this.hasErrors.bind(this)))}getMessage(e,...t){return E(e,...t)}checkTypeAndHasErrors(e){return function(t,r,s,...n){return void 0!==t&&this.acceptedTypes?_(t,this.acceptedTypes)?e(t,r,s,...n):this.getMessage(p.TYPE,this.acceptedTypes.join(", "),"number"!=typeof t?typeof t:isNaN(t)?"NaN":typeof t):e(t,r,s,...n)}.bind(this)}static isValidator(e){return e.constructor&&!!e.hasErrors}}class I extends D{constructor(e=p.DEFAULT,...t){super(!0,e,...t)}}class H extends D{constructor(e=p.DEFAULT,...t){super(!1,e,...t)}}class j{constructor(...e){this.cache={},this.customKeyCache={},this.register(...e)}getCustomKeys(){return Object.assign({},this.customKeyCache)}getKeys(){return Object.keys(this.cache)}get(e){if(!(e in this.cache))return;const t=this.cache[e];if(H.isValidator(t))return t;const r=new(t.default||t);return this.cache[e]=r,r}register(...e){e.forEach(e=>{if(H.isValidator(e)){if(e.validationKey in this.cache)return;this.cache[e.validationKey]=e}else{const{validationKey:t,validator:r,save:s}=e;if(t in this.cache)return;if(this.cache[t]=r,!s)return;const n={};n[t.toUpperCase()]=t,this.customKeyCache=Object.assign({},this.customKeyCache,n)}})}}var U;(e=>{e.DESCRIPTION="description",e.TYPE="design:type",e.MODEL="model",e.ANCHOR="__model",e.CONSTRUCTION="constructed-by",e.ATTRIBUTE="__attributes",e.HASHING="hashing",e.SERIALIZATION="serialization",e.DECORATORS="decorators",e.CONSTRUCTOR="__original"})(U||(U={}));const x="json";class C{static{this.actingValidatorRegistry=void 0}constructor(){}static setRegistry(e,t){t&&C.actingValidatorRegistry&&C.actingValidatorRegistry.getKeys().forEach(r=>{const s=e.get(r);s&&e.register(t(s))}),C.actingValidatorRegistry=e}static getRegistry(){return C.actingValidatorRegistry||(C.actingValidatorRegistry=new j),C.actingValidatorRegistry}static get(e){return C.getRegistry().get(e)}static register(...e){return C.getRegistry().register(...e)}static key(e){return f.REFLECT+e}static keys(){return this.getRegistry().getKeys()}static registerDecorator(t,r){const s=e.innerGet(Symbol.for(U.DECORATORS),e.key(f.REFLECT,t));s?.[t]||e.set(U.DECORATORS,e.key(f.REFLECT,t),r)}static decoratorFromKey(t){try{return e.innerGet(Symbol.for(U.DECORATORS),e.key(f.REFLECT,t))}catch(e){throw Error(`No decorator registered under ${t}: ${e}`)}}}function z(...e){return t(t=>(e.forEach(e=>{C.register({validator:t,validationKey:e,save:!0})}),t),r(f.VALIDATOR,e))}let F=class extends H{constructor(e=p.DATE){super(e,Number.name,Date.name,String.name)}hasErrors(e,t={}){if(void 0!==e&&("string"==typeof e&&(e=new Date(e)),Number.isNaN(e.getDate()))){const{message:e=""}=t;return this.getMessage(e||this.message)}}};function Y(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(!Y(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,n]of e)if(!t.has(s)||!Y(n,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)),n=Object.keys(t).filter(e=>!r.includes(e));if(s.length!==n.length)return!1;for(const i of s){if(!n.includes(i))return!1;if(!Y(e[i],t[i],...r))return!1}const i=Object.getOwnPropertySymbols(e).filter(e=>!r.includes(e.toString())),o=Object.getOwnPropertySymbols(t).filter(e=>!r.includes(e.toString()));if(i.length!==o.length)return!1;for(const s of i){if(!o.includes(s))return!1;if(!Y(e[s],t[s],...r))return!1}return Object.getPrototypeOf(e)===Object.getPrototypeOf(t)}F=c([z(f.DATE),u("design:paramtypes",[String])],F);let $=class extends H{constructor(e=p.DIFF){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[f.DIFF])}catch(e){return this.getMessage(e.message||this.message)}return Y(e,s)?this.getMessage(t.message||this.message,t.label||t[f.DIFF]):void 0}};$=c([z(f.DIFF),u("design:paramtypes",[String])],$);const G=RegExp("^/(.+)/([gimus]*)$");let Q=class extends H{constructor(e=p.PATTERN){super(e,"string")}getPattern(e){if(!G.test(e))return RegExp(e);const t=e.match(G);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)}};Q=c([z(f.PATTERN),u("design:paramtypes",[String])],Q);let V=class extends Q{constructor(e=p.EMAIL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t?.pattern||y.EMAIL})}};V=c([z(f.EMAIL),u("design:paramtypes",[String])],V);let k=class extends H{constructor(e=p.EQUALS){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[f.EQUALS])}catch(e){return this.getMessage(e.message||this.message)}return Y(e,s)?void 0:this.getMessage(t.message||this.message,t.label||t[f.EQUALS])}};k=c([z(f.EQUALS),u("design:paramtypes",[String])],k);let q=class extends H{constructor(e=p.GREATER_THAN){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[f.GREATER_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!R(e,s))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[f.GREATER_THAN])}}};q=c([z(f.GREATER_THAN),u("design:paramtypes",[String])],q);let B=class extends H{constructor(e=p.GREATER_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[f.GREATER_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(S(e,s)&&Y(e,s)||R(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[f.GREATER_THAN_OR_EQUAL])}}};B=c([z(f.GREATER_THAN_OR_EQUAL),u("design:paramtypes",[String])],B);let X=class extends H{constructor(e=p.LESS_THAN){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[f.LESS_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!O(e,s))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[f.LESS_THAN])}}};X=c([z(f.LESS_THAN),u("design:paramtypes",[String])],X);let K=class extends H{constructor(e=p.LESS_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[f.LESS_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(S(e,s)&&Y(e,s)||O(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[f.LESS_THAN_OR_EQUAL])}}};K=c([z(f.LESS_THAN_OR_EQUAL),u("design:paramtypes",[String])],K);let W=class extends H{constructor(e=p.LIST){super(e,Array.name,Set.name)}hasErrors(e,t){if(!e||(Array.isArray(e)?!e.length:!e.size))return;const r=(Array.isArray(t.clazz)?t.clazz:[t.clazz]).map(e=>"string"==typeof e?e:e?.name||"function"!=typeof e?e?.name:e().name);let s,n=!0;for(let r=0;r<(Array.isArray(e)?e.length:e.size);r++)s=[...e][r],n=(Array.isArray(t.clazz)?t.clazz:[t.clazz]).some(e=>P(s,e));return n?void 0:this.getMessage(t.message||this.message,r)}};W=c([z(f.LIST),u("design:paramtypes",[String])],W);let Z=class extends H{constructor(e=p.MAX_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return L(e)>t.maxlength?this.getMessage(t.message||this.message,t.maxlength):void 0}};Z=c([z(f.MAX_LENGTH),u("design:paramtypes",[String])],Z);let J=class extends H{constructor(e=p.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}};J=c([z(f.MAX),u("design:paramtypes",[String])],J);let ee=class extends H{constructor(e=p.MIN_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return L(e)<t.minlength?this.getMessage(t.message||this.message,t.minlength):void 0}};ee=c([z(f.MIN_LENGTH),u("design:paramtypes",[String])],ee);let te=class extends H{constructor(e=p.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}};te=c([z(f.MIN),u("design:paramtypes",[String])],te);let re=class extends H{constructor(e=p.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))}}}};re=c([z(f.ENUM),u("design:paramtypes",[String])],re);let se=class extends Q{constructor(e=p.PASSWORD){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,[f.PATTERN]:t?.pattern||y.PASSWORD.CHAR8_ONE_OF_EACH})}};se=c([z(f.PASSWORD),u("design:paramtypes",[Object])],se);let ne=class extends H{constructor(e=p.REQUIRED){super(e)}hasErrors(e,t={}){switch(typeof e){case"boolean":case"number":return void 0===e?this.getMessage(t.message||this.message):void 0;default:return e?void 0:this.getMessage(t.message||this.message)}}};ne=c([z(f.REQUIRED),u("design:paramtypes",[String])],ne);let ie=class extends H{constructor(e=p.STEP){super(e,"number","string")}hasErrors(e,t){if(void 0!==e)return Number(e)%Number(t.step)!==0?this.getMessage(t.message||this.message,t.step):void 0}};ie=c([z(f.STEP),u("design:paramtypes",[String])],ie);let oe=class extends H{constructor(e=p.TYPE){super(e)}hasErrors(e,t){if(void 0===e)return;const{type:r,message:s,customTypes:n}=t;let i=n||r;i=Array.isArray(i)?i:[i];const o=i.map(e=>"string"==typeof e?e:"function"!=typeof e||e.name?e?.name||e+"":e().name);return w(e,i)?void 0:this.getMessage(s||this.message,o.join(", "),typeof e)}};oe=c([z(f.TYPE),u("design:paramtypes",[String])],oe),C.register({validator:oe,validationKey:U.TYPE,save:!1});let ae=class extends Q{constructor(e=p.URL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t.pattern||y.URL})}};function ce(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 n=e=>{if(!e)return 0;const t=parseInt(e);return isNaN(t)?0:t},i=n(s.groups.year),o=n(s.groups.day),a=s.groups.ampm;let c=n(s.groups.hour);a&&(c="PM"===a?c+12:c);const u=n(s.groups.minutes),l=n(s.groups.seconds),d=n(s.groups.milis),f=s.groups.monthname,h=s.groups.monthnamesmall;let p=s.groups.month;if(f)p=g.indexOf(f);else if(h){const t=g.find(e=>e.toLowerCase().startsWith(h.toLowerCase()));if(!t)return new Date(e);p=g.indexOf(t)}else p=n(""+p);return new Date(i,p-1,o,c,u,l,d)}function ue(e,t){if(e)return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>fe(r,t)})}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>fe(r,t)})}),e}function le(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function de(e){return 10>e?"0"+e:e.toString()}function fe(e,t="yyyy/MM/dd"){const r=e.getDate(),s=e.getMonth(),n=e.getFullYear(),i=e.getHours(),o=e.getMinutes(),a=e.getSeconds(),c=e.getMilliseconds(),u=i%12,l=de(u),d=de(i),f=de(o),p=de(a),y=12>i?"AM":"PM",m=h[e.getDay()],E=m.substr(0,3),b=de(r),A=s+1,T=de(A),N=g[s],M=N.substr(0,3),S=n+"",O=S.substr(2,2);return(t=t.replace("hh",l).replace("h",u.toString()).replace("HH",d).replace("H",i.toString()).replace("mm",f).replace("m",o.toString()).replace("ss",p).replace("s",a.toString()).replace("S",c.toString()).replace("dd",b).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",N).replace("MMM",M):t.replace("MM",T).replace("M",A.toString())}function ge(e,t){let r;if(t){if(t instanceof Date)try{r=ce(fe(t,e),e)}catch(r){throw Error(E("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=ce(t,e);else if("number"==typeof t)r=ce(fe(new Date(t),e),e);else{if(!le(t))throw Error("Invalid value provided "+t);try{r=ce(fe(new Date(t),e),e)}catch(r){throw Error(E("Could not convert date {0} to format: {1}",t,e))}}return ue(r,e)}}function he(e,r,s){return t(n(r,s))}function pe(e,t,r){return C.registerDecorator(t,e),(e,s)=>he(0,`${f.REFLECT}.${s}.${t}`,r)(e,s)}function ye(){return e=>{Object.prototype.hasOwnProperty.call(e,T)||(e[T]=!0)}}function me(e=p.REQUIRED){const t=f.REQUIRED,r={message:e,description:"defines the attribute as required",async:!1};return s.for(t).define({decorator:pe,args:[me,t,r]}).apply()}function Ee(e,t=p.MIN){const r=f.MIN,n={[f.MIN]:e,message:t,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return s.for(r).define({decorator:pe,args:[Ee,r,n]}).apply()}function be(e,t=p.MAX){const r=f.MAX,n={[f.MAX]:e,message:t,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return s.for(r).define({decorator:pe,args:[be,r,n]}).apply()}function Ae(e,t=p.STEP){const r=f.STEP,n={[f.STEP]:e,message:t,description:"defines the step of the attribute as "+e,async:!1};return s.for(r).define({decorator:pe,args:[Ae,r,n]}).apply()}function Te(e,t=p.MIN_LENGTH){const r=f.MIN_LENGTH,n={[f.MIN_LENGTH]:e,message:t,description:`defines the min length of the attribute as ${e} (applies to strings or lists)`,async:!1};return s.for(r).define({decorator:pe,args:[Te,r,n]}).apply()}function Ne(e,t=p.MAX_LENGTH){const r=f.MAX_LENGTH,n={[f.MAX_LENGTH]:e,message:t,description:`defines the max length of the attribute as ${e} (applies to strings or lists)`,async:!1};return s.for(r).define({decorator:pe,args:[Ne,r,n]}).apply()}function Me(e,t=p.PATTERN){const r=f.PATTERN,n={[f.PATTERN]:"string"==typeof e?e:e.toString(),message:t,description:`assigns the ${"string"===e?e:e.toString()} pattern to the attribute`,async:!1};return s.for(r).define({decorator:pe,args:[Me,r,n]}).apply()}function Se(e=p.EMAIL){const t=f.EMAIL,r={[f.PATTERN]:y.EMAIL.toString(),message:e,description:"marks the attribute as an email",async:!1};return s.for(t).define({decorator:pe,args:[Se,t,r]}).apply()}function Oe(e=p.URL){const t=f.URL,r={[f.PATTERN]:y.URL.toString(),message:e,description:"marks the attribute as an url",async:!1};return s.for(t).define({decorator:pe,args:[Oe,t,r]}).apply()}function Re(e,t=p.TYPE){const r=f.TYPE,n={customTypes:e,message:t,description:"defines the accepted types for the attribute",async:!1};return s.for(r).define({decorator:pe,args:[Re,r,n]}).apply()}function ve(e="dd-MM-yyyy HH:mm:ss:S",t=p.DATE){const r=f.DATE;return s.for(r).define({decorator:function(e,t){const s={[f.FORMAT]:e,message:t,description:"defines the attribute as a date with the format "+e,async:!1};return function(t,n){const i=new WeakMap;return Object.defineProperty(t,n,{configurable:!0,set(t){const r=Object.getOwnPropertyDescriptor(this,n);r&&!r.configurable||Object.defineProperty(this,n,{enumerable:!0,configurable:!1,get:()=>i.get(this),set:t=>{let r;try{r=ge(e,t),i.set(this,r)}catch(e){}}}),this[n]=t},get(){return i.get(this)}}),pe(ve,r,s)(t,n)}},args:[e,t]}).apply()}function _e(e=y.PASSWORD.CHAR8_ONE_OF_EACH,t=p.PASSWORD){const r=f.PASSWORD,n={[f.PATTERN]:e.toString(),message:t,description:"attribute as a password",async:!1};return s.for(r).define({decorator:pe,args:[_e,r,n]}).apply()}function Pe(e,t="Array",r=p.LIST){const n=f.LIST,i={clazz:Array.isArray(e)?e:[e],type:t,message:r,async:!1,description:`defines the attribute as a ${t} of ${e.name}`};return s.for(n).define({decorator:pe,args:[Pe,n,i]}).apply()}function we(e,t=p.LIST){return Pe(e,"Set",t)}function Le(e,t){return pe(Le,f.EQUALS,{label:t?.label||e,message:t?.message||p.EQUALS,[f.EQUALS]:e,description:"defines attribute as equal to "+e,async:!1})}function De(e,t){return pe(De,f.DIFF,{label:t?.label||e,message:t?.message||p.DIFF,[f.DIFF]:e,description:"defines attribute as different to "+e,async:!1})}function Ie(e,t){return pe(Ie,f.LESS_THAN,{label:t?.label||e,message:t?.message||p.LESS_THAN,[f.LESS_THAN]:e,description:"defines attribute as less than to "+e,async:!1})}function He(e,t){return pe(He,f.LESS_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||p.LESS_THAN_OR_EQUAL,[f.LESS_THAN_OR_EQUAL]:e,description:"defines attribute as less or equal to "+e,async:!1})}function je(e,t){return pe(je,f.GREATER_THAN,{label:t?.label||e,message:t?.message||p.GREATER_THAN,[f.GREATER_THAN]:e,description:"defines attribute as greater than "+e,async:!1})}function Ue(e,t){return pe(Ue,f.GREATER_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||p.GREATER_THAN_OR_EQUAL,[f.GREATER_THAN_OR_EQUAL]:e,description:"defines attribute as greater or equal to "+e,async:!1})}function xe(e,t=p.ENUM){const r=f.ENUM,n={[f.ENUM]:e,message:t,description:"defines a list or an object of accepted values for the attribute",async:!1};return s.for(r).define({decorator:pe,args:[xe,r,n]}).apply()}ae=c([z(f.URL),u("design:paramtypes",[String])],ae);class Ce{static{this.current=x}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 ze{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 Fe=e=>e[A],Ye=(e,t)=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw Error(E(b.PROPERTY_NOT_EXIST,t));return e[t]};class $e{static create(e,t){const{getValue:r,getParent:s,ignoreUndefined:n,ignoreNull:i}={getParent:Fe,getValue:Ye,ignoreNull:!1,ignoreUndefined:!1,...t},o=new Proxy({},{get:(t,o)=>"getValueFromPath"===o?t=>{const o=$e.parsePath(t);let a=e;for(let e=0;e<o.length;e++){const c=o[e];if(".."===c){const r=s(a);if(!r||"object"!=typeof r)throw Error(E(b.CONTEXT_NOT_OBJECT_COMPARISON,e+1,t));a=r;continue}if(a=r(a,c),!n&&void 0===a)throw Error(E(b.PROPERTY_INVALID,t,c));if(!i&&null===a)throw Error(E(b.PROPERTY_INVALID,t,c))}return a}:t[o]});return o}static parsePath(e){if("string"!=typeof e||!e.trim())throw Error(E(b.INVALID_PATH,e));return e.match(/(\.\.|[^/.]+)/g)||[]}}function Ge(e,t){return t?Promise.resolve(e):e}var Qe;(e=>{e.STRING="string",e.NUMBER="number",e.BOOLEAN="boolean",e.BIGINT="bigint"})(Qe||(Qe={}));const Ve={STRING:String,OBJECT:Object,NUMBER:Number,BOOLEAN:Boolean,BIGINT:BigInt,DATE:Date},ke=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"];let qe,Be;class Xe{constructor(t=e.isModel){this.cache={},this.testFunction=t}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(t={},r){if(!r&&!this.testFunction(t))throw Error("Provided obj is not a Model object");const s=r||e.modelName(t.constructor);if(!(s in this.cache))throw Error(`Provided class ${s} is not a registered Model object`);return new this.cache[s](t)}static setBuilder(e){qe=e}static getBuilder(){return qe||Xe.fromModel}static fromModel(t,r){let s;r||(r={});const n=e.getAttributes(t),i=Object.getPrototypeOf(t);let o;for(const a of n){try{t[a]=r[a]??t[a]??void 0}catch(e){if(o=Object.getOwnPropertyDescriptor(i,a),!o||o.writable)throw Error(`Unable to write property ${a} to model: ${e}`)}if("object"!=typeof t[a])continue;const n=e.isPropertyModel(t,a);if(n){try{t[a]=Xe.getRegistry().build(t[a],"string"==typeof n?n:void 0)}catch(e){}continue}const c=e.validationFor(t.constructor,a);if(c?.[f.LIST]&&(Array.isArray(t[a])||t[a]instanceof Set)){const e=c[f.LIST].clazz.map(e=>"function"!=typeof e||e.name?e:e()).find(e=>!ke.includes(e.name.toLowerCase()));if(Array.isArray(t[a])&&(t[a]=t[a].map(t=>["object","function"].includes(typeof t)&&e?Xe.getRegistry().build(t,e.name):t)),t[a]instanceof Set){const r=new Set;for(const s of t[a])["object","function"].includes(typeof s)&&e?r.add(Xe.getRegistry().build(s,e.name)):r.add(s);t[a]=r}continue}if(s=e.allowedTypes(t.constructor,a),!s||!s.length)throw Error("failed to find decorators for property "+a);const u=s.map(e=>"function"!=typeof e||e.name?e:e()),l=Object.values(Ve);u.forEach(e=>{if(!l.includes(e))try{e.name,void 0!==t[a]&&Xe.getRegistry().get(e.name)&&(t[a]=Xe.getRegistry().build(t[a],e.name))}catch(e){}})}return t}static getRegistry(){return Be||(Be=new Xe),Be}static setRegistry(e){Be=e}}function Ke(...e){e.forEach(e=>{const t=e.constructor?e.constructor:e;Xe.getRegistry().register(t,e.name)})}function We(e,t,r){Object.hasOwnProperty.call(e,t)||(e[t]=r)}function Ze(e,t){Object.hasOwnProperty.call(e,t)&&delete e[t]}function Je(e,t,r,...s){t&&We(e,A,t),We(e,T,!!r);const n=e.hasErrors(...s);return Ze(e,A),Ze(e,T),n}function et(e,t,r,s,n,...i){let o,a=!1;for(const c of s){const s=Xe.getRegistry().get(c);if(s||(o=new ze({[e]:{[f.TYPE]:"Unable to verify type consistency, missing model registry for "+c}})),t instanceof s){a=!0,o=Je(t,r,n,...i);break}}return a?o:o||new ze({[e]:{[f.TYPE]:"Value must be an instance of one of the expected types: "+s.join(", ")}})}function tt(e,...t){return t?.map(t=>("string"==typeof t&&t?.startsWith(e+".")&&(t=t.replace(e+".","")),t))}function rt(e,t,r,s){const n=C.get(r.key);if(!n)throw Error("Missing validator for "+r.key);if(!s&&r.async)return;const i=r.key===U.TYPE?[r]:r||{},o=$e.create(e,{ignoreUndefined:!0,ignoreNull:!0}),a=r.key===U.TYPE?i[0]:i;return Ge(n.hasErrors(t,a,o),s)}function st(t,r,s,n,i,...o){const a={};for(const c in n){const u={...n[c],key:c};if(!i&&u.async)continue;let l=rt(t,s,u,i);if(c===f.LIST&&(!l||i)){const n=s instanceof Set?[...s]:s;if(n&&n.length>0){let s=u.class||u.clazz||u.customTypes;s=(Array.isArray(s)?s:[s]).map(e=>(e="function"!=typeof e||e.name?e:e()).name?e.name:e);const a=[s].flat().map(e=>(e+"").toLowerCase()),c=n.map(n=>{if(!["string","number","bigint"].includes(typeof n)){if(e.isModel(n)){const e=tt(r,...o);return et(r,n,t,s.flat(),!!i,...e)}return a.includes(typeof n)?void 0:"Value has no validatable type"}});if(i)l=Promise.all(c).then(e=>e.every(e=>!e)?void 0:e);else{const e=c.every(e=>!e);l=c.length>0&&!e?c:void 0}}}const d=c===U.TYPE?f.TYPE:c;l&&(a[d]=l)}if(!i)return Object.keys(a).length>0?a:void 0;const c=Object.keys(a),u=Object.values(a);return Promise.all(u).then(e=>{const t={};for(let r=0;r<e.length;r++){const s=e[r];void 0!==s&&(t[c[r]]=s)}return Object.keys(t).length>0?t:void 0})}function nt(t,r,...s){const n=e.validatableProperties(t.constructor,...s),i={},o={};for(const a of n){const n=a+"",c=t[a],u=e.validationFor(t.constructor,a)||{},{designTypes:l}=e.getPropDesignTypes(t.constructor,a);if(!l)continue;if(l.some(e=>[Array.name,Set.name].includes(e.name))){if(!u||!Object.keys(u).includes(f.LIST)){i[n]={[f.TYPE]:`Array or Set property '${n}' requires a @list decorator`};continue}if(c&&!(Array.isArray(c)||c instanceof Set)){i[n]={[f.TYPE]:`Property '${a+""}' must be either an Array or a Set`};continue}}const d=st(t,n,c,u,r,...s)||{};if(e.isPropertyModel(t,n)&&null!=c){const e=l.map(e=>Xe.getRegistry().get(e.name||e)).find(e=>!!e),i=l.map(e=>"function"==typeof e?e.name?e.name.toLowerCase():e()?.name.toLowerCase():e.toLowerCase());if(e&&c instanceof e){const e=tt(n,...s);o[n]=Je(c,t,r,...e)}else i.includes(typeof c)||(d[f.TYPE]=e?"Value must be an instance of "+e.name:`Unable to verify type consistency, missing model registry for ${l.toString()} on prop ${n}`,delete d[U.TYPE])}(Object.keys(d).length>0||r)&&(i[n]=d),r||Object.entries(o[n]||{}).forEach(([e,t])=>{void 0!==t&&(i[`${n}.${e}`]=t)})}if(!r)return Object.keys(i).length>0?new ze(i):void 0;const a=i,c=Object.keys(a),u=Object.values(a);return Promise.allSettled(u).then(async e=>{const t={};for(const[e,r]of Object.entries(o)){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=c[r],n=e[r];"fulfilled"===n.status&&void 0!==n.value?t[s]=n.value:"rejected"===n.status&&(t[s]=n.reason instanceof Error?n.reason.message:(n.reason||"Validation failed")+"")}return Object.keys(t).length>0?new ze(t):void 0})}function it(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 ot(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=it,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),n=Object.values(e).reduce(t,0);return("number"==typeof n?Math.abs(n):n).toString()}const at="default";class ct{static{this.current=at}static{this.cache={default:ot}}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 ut{constructor(e=void 0){}isAsync(){return!!(this[T]??this?.constructor[T])}hasErrors(...e){return nt(this,this.isAsync(),...e)}equals(e,...t){return Y(this,e,...t)}compare(t,...r){const s=e.properties(this.constructor);if(!s||!s.length)return;const n=s.reduce((e,s)=>{const n=s;if(r.includes(n))return e;if(void 0===this[n]&&void 0!==t[n])return e[n]={other:t[n],current:void 0},e;if(void 0!==this[n]&&void 0===t[n])return e[n]={other:void 0,current:this[n]},e;if(Y(this[n],t[n]))return e;if(ut.isPropertyModel(this,n)){const r=this[n].compare(t[n]);return r&&(e[n]=r),e}if(Array.isArray(this[n])&&Array.isArray(t[n])){if(this[n].length!==t[n].length)return e[n]={current:this[n],other:t[n]},e;const r=this[n].map((e,r)=>Y(e,t[n][r])?null:e instanceof ut&&t[n][r]instanceof ut?e.compare(t[n][r]):{current:e,other:t[n][r]});return r.some(e=>null!==e)&&(e[n]=r),e}return e[n]={other:t[n],current:this[n]},e},{});return Object.keys(n).length>0?n:void 0}serialize(){return ut.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return ut.hash(this)}static deserialize(t){let r;try{r=e.get(this.constructor,U.SERIALIZATION)}catch(e){r=void 0}return r&&r.serializer?Ce.deserialize(t,r.serializer,...r.args||[]):Ce.deserialize(t)}static fromObject(e,t){t||(t={});for(const r of ut.getAttributes(e))e[r]=t[r]??e[r]??void 0;return e}static fromModel(e,t){return Xe.fromModel(e,t)}static setBuilder(e){Xe.setBuilder(e)}static getBuilder(){return Xe.getBuilder()}static getRegistry(){return Xe.getRegistry()}static setRegistry(e){Xe.setRegistry(e)}static register(e,t){return Xe.getRegistry().register(e,t)}static get(e){return Xe.getRegistry().get(e)}static build(e={},t){return ut.getRegistry().build(e,t)}static getAttributes(t){return e.getAttributes(t)}static equals(e,t,...r){return Y(e,t,...r)}static hasErrors(e,t,...r){return nt(e,t,...r)}static serialize(t){let r;try{r=e.get(t.constructor,U.SERIALIZATION)}catch(e){r=void 0}return r&&r.serializer?Ce.serialize(this,r.serializer,...r.args||[]):Ce.serialize(t)}static hash(t){const r=e.get(t.constructor,U.HASHING);return r&&r.algorithm?ct.hash(t,r.algorithm,...r.args||[]):ct.hash(t)}static isModel(t){return e.isModel(t)}static isPropertyModel(t,r){return e.isPropertyModel(t,r)}static describe(t,r){return e.description(t,r)}}function lt(e){return e instanceof ft?e.build():new Date(e)}function dt(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}e.validationFor=((t,r,s)=>{const n=e.get(t);if(!n)return;if(!r)return n.validation;if(!n.validation)return;if(!n.validation[f.TYPE]){const{designTypes:s}=e.getPropDesignTypes(t,r);n.validation[r]&&s?.length&&s[0]!==Ve.OBJECT&&(n.validation[r][f.TYPE]={customTypes:s,message:p.TYPE,description:"defines the accepted types for the attribute",async:!1})}if(!s)return n.validation[r];const i=n.validation[r];return i?i[s]:void 0}).bind(e),e.modelName=(t=>{const r=e.constr(t);return r?r.name:t.name}).bind(e),e.validatableProperties=((t,...r)=>{const s=e.validationFor(t),n=s?Object.keys(s):[];return[...new Set([...ut.getAttributes(t),...n])].filter(e=>!r||!r?.includes(e))}).bind(e),e.allowedTypes=((t,r)=>{const s=e.type(t,r);if(!s)throw Error("No metadata found for property "+r);const n=e.validationFor(t,r);return n&&n[f.TYPE]&&"function"==typeof n[f.TYPE]?.customTypes[Symbol.iterator]?[...n[f.TYPE].customTypes]:[s]}).bind(e),e.getPropDesignTypes=((t,r)=>{const s=e.get(t),n=e.type(t,r),i=s?.[f.REFLECT]?.[r];if(!(n||i&&i[f.TYPE]))return{};const o=i&&i[f.TYPE]?[i[f.TYPE].customTypes]:[n];if(!o?.length)return{};const a=o[0],c=a.class||a.clazz||a.customTypes||a;return{designTypes:(Array.isArray(c)?c:[c]).map(e=>"function"!=typeof e||e.name?e:e()),designType:c}}).bind(e),e.isModel=(t=>{try{if(t instanceof ut)return!0;const r=e.constr(t);return!(!r||r===t||!e.modelName(r))}catch(e){return!1}}).bind(e),e.isPropertyModel=((t,r)=>{if(e.isModel(t[r]))return!0;const s=e.type(t.constructor,r);return s&&Xe.getRegistry().get(s.name)?s.name:void 0}).bind(e),e.getAttributes=(t=>{const r=t instanceof ut?t.constructor:t,s=new Set,n=t=>{if(!t)return[];const r=e.constr(t),i=n(Object.getPrototypeOf(r)),o=e.properties(t)??[];for(const e of o)s.has(e)||(s.add(e),i.push(e));return i};return n(r)}).bind(e);class ft{constructor(){this.years=0,this.months=0,this.days=0,this.hours=0,this.minutes=0,this.seconds=0}static Years(e){return(new ft).Years(e)}static Months(e){return(new ft).Months(e)}static Days(e){return(new ft).Days(e)}static Hours(e){return(new ft).Hours(e)}static Minutes(e){return(new ft).Minutes(e)}static Seconds(e){return(new ft).Seconds(e)}static Now(){return new Date}static Tomorrow(){return ft.Days(1).from(ft.Now())}static Yesterday(){return ft.Days(1).until(ft.Now())}static DaysAgo(e){return ft.Days(e).until(ft.Now())}static NextDays(e){return ft.Days(e).from(ft.Now())}static YearsAgo(e){return ft.Years(e).until(ft.Now())}static NextYears(e){return ft.Years(e).from(ft.Now())}static MonthsAgo(e){return ft.Months(e).until(ft.Now())}static NextMonths(e){return ft.Months(e).from(ft.Now())}static HoursAgo(e){return ft.Hours(e).until(ft.Now())}static NextHours(e){return ft.Hours(e).from(ft.Now())}static MinutesAgo(e){return ft.Minutes(e).until(ft.Now())}static NextMinutes(e){return ft.Minutes(e).from(ft.Now())}static SecondsAgo(e){return ft.Seconds(e).until(ft.Now())}static NextSeconds(e){return ft.Seconds(e).from(ft.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 dt(lt(e),1,this.offsets())}past(e){return this.from(e)}after(e){return this.from(e)}until(e){return dt(lt(e),-1,this.offsets())}before(e){return this.until(e)}ago(e=new Date){return this.until(e)}Now(){return ft.Now()}Tomorrow(){return ft.Tomorrow()}Yesterday(){return ft.Yesterday()}DaysAgo(e){return ft.DaysAgo(e)}NextDays(e){return ft.NextDays(e)}YearsAgo(e){return ft.YearsAgo(e)}NextYears(e){return ft.NextYears(e)}MonthsAgo(e){return ft.MonthsAgo(e)}NextMonths(e){return ft.NextMonths(e)}HoursAgo(e){return ft.HoursAgo(e)}NextHours(e){return ft.NextHours(e)}MinutesAgo(e){return ft.MinutesAgo(e)}NextMinutes(e){return ft.NextMinutes(e)}SecondsAgo(e){return ft.SecondsAgo(e)}NextSeconds(e){return ft.NextSeconds(e)}offsets(){return{years:this.years,months:this.months,days:this.days,hours:this.hours,minutes:this.minutes,seconds:this.seconds}}}const gt=ft,ht=()=>ft.Now(),pt=()=>ft.Tomorrow(),yt=()=>ft.Yesterday(),mt=e=>ft.DaysAgo(e),Et=e=>ft.NextDays(e),bt=e=>ft.YearsAgo(e),At=e=>ft.NextYears(e),Tt=e=>ft.MonthsAgo(e),Nt=e=>ft.NextMonths(e),Mt=e=>ft.HoursAgo(e),St=e=>ft.NextHours(e),Ot=e=>ft.MinutesAgo(e),Rt=e=>ft.NextMinutes(e),vt=e=>ft.SecondsAgo(e),_t=e=>ft.NextSeconds(e);class Pt{constructor(){}preSerialize(t,...r){const s=Object.assign({},t);let n;try{n=e.modelName(t.constructor)}catch(e){n=void 0}return s[U.ANCHOR]=n||t.constructor.name,s}deserialize(e,...t){const r=JSON.parse(e),s=r[U.ANCHOR];if(!s)throw Error("Could not find class reference in serialized model");return ut.build(r,s)}serialize(e,...t){return JSON.stringify(this.preSerialize(e))}}function wt(e,...t){const r=(...t)=>new e(...t);return r.prototype=e.prototype,r(...t)}function Lt(e){let t=Object.getPrototypeOf(e);if(t===Object.prototype)return e;for(;t!==Object.prototype;){if(t=Object.getPrototypeOf(t),t===Object.prototype)return t;if(Object.getPrototypeOf(t)===Object.prototype)return t}throw Error("Could not find proper prototype")}function Dt(e){if(e instanceof ut)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,ut.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,ut.prototype)}throw Error("Could not find proper prototype to bind")}function It(e){const t=(...t)=>{const r=wt(e,...t);Dt(r);const s=ut.getBuilder();return s&&s(r,t.length?t[0]:void 0),r};return t.prototype=e.prototype,Object.setPrototypeOf(t,e),Object.defineProperty(t,"name",{writable:!1,enumerable:!0,configurable:!1,value:e.prototype.constructor.name}),r(U.CONSTRUCTOR,e)(t),ut.register(t,e.name),t}function Ht(){const e=U.MODEL;return s.for(e).define(It).apply()}function jt(e,...t){return r(U.HASHING,{algorithm:e,args:t})}function Ut(e,...t){return r(U.SERIALIZATION,{serializer:e,args:t})}Ce.cache={json:new Pt};class xt{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=xt.asMeta(e),r="string"==typeof e?e:xt.resolveMessage(t);return this.decorate(me(r))}min(e,t){const r=xt.asMeta(e),s=r?.[f.MIN]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${f.MIN} for ${this.attr+""}`);return this.decorate(Ee(s,xt.resolveMessage(r,t)))}max(e,t){const r=xt.asMeta(e),s=r?.[f.MAX]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${f.MAX} for ${this.attr+""}`);return this.decorate(be(s,xt.resolveMessage(r,t)))}step(e,t){const r=xt.asMeta(e),s=r?.[f.STEP]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${f.STEP} for ${this.attr+""}`);return this.decorate(Ae(s,xt.resolveMessage(r,t)))}minlength(e,t){const r=xt.asMeta(e),s=r?.[f.MIN_LENGTH]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${f.MIN_LENGTH} for ${this.attr+""}`);return this.decorate(Te(s,xt.resolveMessage(r,t)))}maxlength(e,t){const r=xt.asMeta(e),s=r?.[f.MAX_LENGTH]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${f.MAX_LENGTH} for ${this.attr+""}`);return this.decorate(Ne(s,xt.resolveMessage(r,t)))}pattern(e,t){const r=xt.asMeta(e),s=r?.[f.PATTERN]??(r?void 0:e),n=xt.patternFromString(s)??/.*/;return this.decorate(Me(n,xt.resolveMessage(r,t)))}email(e){const t=xt.asMeta(e),r="string"==typeof e?e:xt.resolveMessage(t);return this.decorate(Se(r))}url(e){const t=xt.asMeta(e),r="string"==typeof e?e:xt.resolveMessage(t);return this.decorate(Oe(r))}type(e,t){const r=xt.asMeta(e),s=r?.customTypes??r?.type??(r?void 0:e);return this.decorate(Re(s,xt.resolveMessage(r,t)))}date(e,t){const r=xt.asMeta(e),s=r?.[f.FORMAT]??(r?void 0:e);return this.decorate(ve(s,xt.resolveMessage(r,t)))}password(e,t){const r=xt.asMeta(e),s=r?.[f.PATTERN]??(r?void 0:e),n=xt.patternFromString(s);return this.decorate(_e(n,xt.resolveMessage(r,t)))}list(e,t,r){const s=xt.asMeta(e),n=s?.clazz??(s?void 0:e),i=s?.type??t;return this.decorate(Pe(n,i,xt.resolveMessage(s,r)))}set(e,t){return xt.isMetadataPayload(e)?this.list(e):this.list(e,"Set",t)}enum(e,t){const r=xt.asMeta(e),s=r?.[f.ENUM]??(r?void 0:e);return this.decorate(xe(s,xt.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 xt.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=xt.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,f.EQUALS,t);return this.decorate(Le(r,s))}eq(e,t){return this.equals(e,t)}different(e,t){const{target:r,options:s}=this.resolveComparison(e,f.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,f.LESS_THAN,t);return this.decorate(Ie(r,s))}lt(e,t){return this.lessThan(e,t)}lessThanOrEqual(e,t){const{target:r,options:s}=this.resolveComparison(e,f.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,f.GREATER_THAN,t);return this.decorate(je(r,s))}gt(e,t){return this.greaterThan(e,t)}greaterThanOrEqual(e,t){const{target:r,options:s}=this.resolveComparison(e,f.GREATER_THAN_OR_EQUAL,t);return this.decorate(Ue(r,s))}gte(e,t){return this.greaterThanOrEqual(e,t)}description(e){return this.decorate(i(e))}build(e){const t=e.prototype,r=this.attr;Object.getOwnPropertyDescriptor(t,r)||Object.defineProperty(t,r,{configurable:!0,enumerable:!0,writable:!0,value:void 0}),this.declaredType&&Reflect.defineMetadata(o.DESIGN_TYPE,this.declaredType,t,r),a()(t,r),this.decorators.forEach(e=>{try{e(t,r)}catch(e){throw Error(`Failed to apply decorator to property "${this.attr}": ${e}`)}})}}class Ct{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=zt.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 zt extends l{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 xt(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 zt;return t.build=new Proxy(t.build,{apply:(t,r,s)=>{const n=Reflect.apply(t,r,s);return this.instance(n,e)}}),t}listOf(e,t="Array"){const r="Set"===t?Set:Array,s=this.attribute(e,r);return new Ct(this,s,t)}build(){if(!this._name)throw Error("name is required");const e=this._parent??ut;class t extends e{constructor(e){super(e)}}Object.defineProperty(t,"name",{value:this._name,writable:!1});for(const e of this.attributes.values())e.build(t);let r=Ht()(t);for(const e of this._classDecorators){const t=e(r);t&&(r=t)}return this._description&&(r=i(this._description)(r)),r}static builder(){return new zt}static from(e,t){if(!e)throw Error("metadata is required");const r=zt.builder(),s=t??"GeneratedModel"+Date.now();r.setName(s);const n=e.properties||{},i=e.validation||{};for(const[e,t]of Object.entries(n)){const s=r.attribute(e,t||Object),n=i[e];if(n)for(const[e,t]of Object.entries(n)){const r=s[e];if("function"!=typeof r)try{const r=C.decoratorFromKey(e),n="function"==typeof r?r(t):r;s.decorate(n)}catch{}else r.call(s,t)}}return r.build()}}const Ft="##VERSION##",Yt="##COMMIT##",$t="##FULL_VERSION##",Gt="##PACKAGE##";e.registerLibrary(Gt,Ft);export{T as ASYNC_META_KEY,I as AsyncValidator,xt as AttributeBuilder,Yt as COMMIT,b as COMPARISON_ERROR_MESSAGES,d as ComparisonValidationKeys,h as DAYS_OF_WEEK_NAMES,p