@decaf-ts/decorator-validation
Version:
simple decorator based validation engine
1 lines • 51.7 kB
JavaScript
import{Metadata as e,apply as t,metadata as r,propMetadata as s,Decoration 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";var d;(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"})(d||(d={}));const h="json";class g{static{this.current=h}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 f{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 p={EQUALS:"equals",DIFF:"different",LESS_THAN:"lessThan",LESS_THAN_OR_EQUAL:"lessThanOrEqual",GREATER_THAN:"greaterThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual"},y={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",...p},m=["January","February","March","April","May","June","July","August","September","October","November","December"],E=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],b={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}"},A={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 T(e,...t){return e.replace(/{(\d+)}/g,((e,r)=>void 0!==t[r]?t[r].toString():"undefined"))}const N=T,M={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"},S=Symbol("_parent"),O=Symbol("isAsync"),R=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,v=e=>void 0===e||e instanceof Date||"bigint"==typeof e||"number"==typeof e&&Number.isFinite(e);function P(e,t){if(v(e)&&v(t))return!0;throw new TypeError(N(M.UNSUPPORTED_TYPES_COMPARISON,R(e),R(t)))}function w(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(M.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(N(M.TYPE_MISMATCH_COMPARISON,r,s))}if("number"===r&&"number"===s||"bigint"===r&&"bigint"===s){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(M.NAN_COMPARISON);return t>e}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(M.INVALID_DATE_COMPARISON);return e.getTime()<t.getTime()}throw new TypeError(N(M.UNSUPPORTED_TYPES_COMPARISON,R(e),R(t)))}function _(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(M.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(N(M.TYPE_MISMATCH_COMPARISON,r,s))}if("number"===r&&"number"===s||"bigint"===r&&"bigint"===s){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(M.NAN_COMPARISON);return e>t}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(M.INVALID_DATE_COMPARISON);return e.getTime()>t.getTime()}throw new TypeError(N(M.UNSUPPORTED_TYPES_COMPARISON,R(e),R(t)))}function L(e,t){return typeof e===t.toLowerCase()||void 0!==e&&"object"==typeof e&&e.constructor&&e.constructor.name.toLowerCase()===t.toLowerCase()}function D(e,t){return!t.every((t=>!L(e,t)))}function I(e,t){switch(typeof t){case"string":return L(e,t);case"object":return!Array.isArray(t)||D(e,t);case"function":return!t.name||"Object"===t.name||L(e,t.name);default:return!0}}function H(e){return e instanceof Set||e instanceof Map?e.size:e.length}class j{constructor(e,t=b.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 N(e,...t)}checkTypeAndHasErrors(e){return function(t,r,s,...n){return void 0!==t&&this.acceptedTypes?D(t,this.acceptedTypes)?e(t,r,s,...n):this.getMessage(b.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 U extends j{constructor(e=b.DEFAULT,...t){super(!1,e,...t)}}class x{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(U.isValidator(t))return t;const r=new(t.default||t);return this.cache[e]=r,r}register(...e){e.forEach((e=>{if(U.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)}}))}}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 x),C.actingValidatorRegistry}static get(e){return C.getRegistry().get(e)}static register(...e){return C.getRegistry().register(...e)}static key(e){return y.REFLECT+e}static keys(){return this.getRegistry().getKeys()}static registerDecorator(t,r){const s=e.innerGet(Symbol.for(d.DECORATORS),e.key(y.REFLECT,t));s?.[t]||e.set(d.DECORATORS,e.key(y.REFLECT,t),r)}static decoratorFromKey(t){try{return e.innerGet(Symbol.for(d.DECORATORS),e.key(y.REFLECT,t))}catch(e){throw Error(`No decorator registered under ${t}: ${e}`)}}}const F=e=>e[S],z=(e,t)=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw Error(N(M.PROPERTY_NOT_EXIST,t));return e[t]};class Y{static create(e,t){const{getValue:r,getParent:s,ignoreUndefined:n,ignoreNull:i}={getParent:F,getValue:z,ignoreNull:!1,ignoreUndefined:!1,...t},o=new Proxy({},{get:(t,o)=>"getValueFromPath"===o?t=>{const o=Y.parsePath(t);let a=e;for(let e=0;e<o.length;e++){const c=o[e];if(".."!==c){if(a=r(a,c),!n&&void 0===a)throw Error(N(M.PROPERTY_INVALID,t,c));if(!i&&null===a)throw Error(N(M.PROPERTY_INVALID,t,c))}else{const r=s(a);if(!r||"object"!=typeof r)throw Error(N(M.CONTEXT_NOT_OBJECT_COMPARISON,e+1,t));a=r}}return a}:t[o]});return o}static parsePath(e){if("string"!=typeof e||!e.trim())throw Error(N(M.INVALID_PATH,e));return e.match(/(\.\.|[^/.]+)/g)||[]}}function $(e,t){return t?Promise.resolve(e):e}var G;(e=>{e.STRING="string",e.NUMBER="number",e.BOOLEAN="boolean",e.BIGINT="bigint"})(G||(G={}));const Q={STRING:String,OBJECT:Object,NUMBER:Number,BOOLEAN:Boolean,BIGINT:BigInt,DATE:Date},k=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"];class V extends j{constructor(e=b.DEFAULT,...t){super(!0,e,...t)}}function q(...e){return t((t=>(e.forEach((e=>{C.register({validator:t,validationKey:e,save:!0})})),t)),r(y.VALIDATOR,e))}let B=class extends U{constructor(e=b.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 X(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(!X(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)||!X(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(!X(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(!X(e[s],t[s],...r))return!1}return Object.getPrototypeOf(e)===Object.getPrototypeOf(t)}B=c([q(y.DATE),u("design:paramtypes",[String])],B);let K=class extends U{constructor(e=b.DIFF){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[y.DIFF])}catch(e){return this.getMessage(e.message||this.message)}return X(e,s)?this.getMessage(t.message||this.message,t.label||t[y.DIFF]):void 0}};K=c([q(y.DIFF),u("design:paramtypes",[String])],K);const W=RegExp("^/(.+)/([gimus]*)$");let Z=class extends U{constructor(e=b.PATTERN){super(e,"string")}getPattern(e){if(!W.test(e))return RegExp(e);const t=e.match(W);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)}};Z=c([q(y.PATTERN),u("design:paramtypes",[String])],Z);let J=class extends Z{constructor(e=b.EMAIL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t?.pattern||A.EMAIL})}};J=c([q(y.EMAIL),u("design:paramtypes",[String])],J);let ee=class extends U{constructor(e=b.EQUALS){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[y.EQUALS])}catch(e){return this.getMessage(e.message||this.message)}return X(e,s)?void 0:this.getMessage(t.message||this.message,t.label||t[y.EQUALS])}};ee=c([q(y.EQUALS),u("design:paramtypes",[String])],ee);let te=class extends U{constructor(e=b.GREATER_THAN){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[y.GREATER_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!_(e,s))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[y.GREATER_THAN])}}};te=c([q(y.GREATER_THAN),u("design:paramtypes",[String])],te);let re=class extends U{constructor(e=b.GREATER_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[y.GREATER_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(P(e,s)&&X(e,s)||_(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[y.GREATER_THAN_OR_EQUAL])}}};re=c([q(y.GREATER_THAN_OR_EQUAL),u("design:paramtypes",[String])],re);let se=class extends U{constructor(e=b.LESS_THAN){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[y.LESS_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!w(e,s))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[y.LESS_THAN])}}};se=c([q(y.LESS_THAN),u("design:paramtypes",[String])],se);let ne=class extends U{constructor(e=b.LESS_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let s;try{s=r.getValueFromPath(t[y.LESS_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(P(e,s)&&X(e,s)||w(e,s))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[y.LESS_THAN_OR_EQUAL])}}};ne=c([q(y.LESS_THAN_OR_EQUAL),u("design:paramtypes",[String])],ne);let ie=class extends U{constructor(e=b.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 t=0;t<(Array.isArray(e)?e.length:e.size);t++)switch(s=[...e][t],typeof s){case"object":case"function":n=r.includes((s??{}).constructor?.name);break;default:n=r.some((e=>typeof s===e?.toLowerCase()))}return n?void 0:this.getMessage(t.message||this.message,r)}};ie=c([q(y.LIST),u("design:paramtypes",[String])],ie);let oe=class extends U{constructor(e=b.MAX_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return H(e)>t.maxlength?this.getMessage(t.message||this.message,t.maxlength):void 0}};oe=c([q(y.MAX_LENGTH),u("design:paramtypes",[String])],oe);let ae=class extends U{constructor(e=b.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}};ae=c([q(y.MAX),u("design:paramtypes",[String])],ae);let ce=class extends U{constructor(e=b.MIN_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return H(e)<t.minlength?this.getMessage(t.message||this.message,t.minlength):void 0}};ce=c([q(y.MIN_LENGTH),u("design:paramtypes",[String])],ce);let ue=class extends U{constructor(e=b.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}};ue=c([q(y.MIN),u("design:paramtypes",[String])],ue);let le=class extends U{constructor(e=b.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))}}}};le=c([q(y.ENUM),u("design:paramtypes",[String])],le);let de=class extends Z{constructor(e=b.PASSWORD){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,[y.PATTERN]:t?.pattern||A.PASSWORD.CHAR8_ONE_OF_EACH})}};de=c([q(y.PASSWORD),u("design:paramtypes",[Object])],de);let he=class extends U{constructor(e=b.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)}}};he=c([q(y.REQUIRED),u("design:paramtypes",[String])],he);let ge=class extends U{constructor(e=b.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}};ge=c([q(y.STEP),u("design:paramtypes",[String])],ge);let fe=class extends U{constructor(e=b.TYPE){super(e)}hasErrors(e,t){if(void 0===e)return;const{type:r,message:s,customTypes:n}=t;let i=n||r;return i=(Array.isArray(i)?i:[i]).map((e=>"string"==typeof e?e:("function"!=typeof e||e.name||(e=e()),e.name||e))),I(e,i)?void 0:this.getMessage(s||this.message,"string"==typeof i?i:Array.isArray(i)?i.join(", "):i,typeof e)}};fe=c([q(y.TYPE),u("design:paramtypes",[String])],fe),C.register({validator:fe,validationKey:d.TYPE,save:!1});let pe,ye,me=class extends Z{constructor(e=b.URL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t.pattern||A.URL})}};function Ee(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),h=s.groups.monthname,g=s.groups.monthnamesmall;let f=s.groups.month;if(h)f=m.indexOf(h);else if(g){const t=m.find((e=>e.toLowerCase().startsWith(g.toLowerCase())));if(!t)return new Date(e);f=m.indexOf(t)}else f=n(""+f);return new Date(i,f-1,o,c,u,l,d)}function be(e,t){if(e)return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>Ne(r,t)})}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>Ne(r,t)})}),e}function Ae(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function Te(e){return 10>e?"0"+e:e.toString()}function Ne(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=Te(u),d=Te(i),h=Te(o),g=Te(a),f=12>i?"AM":"PM",p=E[e.getDay()],y=p.substr(0,3),b=Te(r),A=s+1,T=Te(A),N=m[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",h).replace("m",o.toString()).replace("ss",g).replace("s",a.toString()).replace("S",c.toString()).replace("dd",b).replace("d",r.toString()).replace("EEEE",p).replace("EEE",y).replace("yyyy",S).replace("yy",O).replace("aaa",f)).indexOf("MMM")>-1?t.replace("MMMM",N).replace("MMM",M):t.replace("MM",T).replace("M",A.toString())}function Me(e,t){let r;if(t){if(t instanceof Date)try{r=Ee(Ne(t,e),e)}catch(r){throw Error(N("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=Ee(t,e);else if("number"==typeof t)r=Ee(Ne(new Date(t),e),e);else{if(!Ae(t))throw Error("Invalid value provided "+t);try{r=Ee(Ne(new Date(t),e),e)}catch(r){throw Error(N("Could not convert date {0} to format: {1}",t,e))}}return be(r,e)}}function Se(e,r,n){return t(s(r,n))}function Oe(e,t,r){return C.registerDecorator(t,e),(e,s)=>Se(0,`${y.REFLECT}.${s}.${t}`,r)(e,s)}function Re(){return e=>{Object.prototype.hasOwnProperty.call(e,O)||(e[O]=!0)}}function ve(e=b.REQUIRED){const t=y.REQUIRED,r={message:e,description:"defines the attribute as required",async:!1};return n.for(t).define({decorator:Oe,args:[ve,t,r]}).apply()}function Pe(e,t=b.MIN){const r=y.MIN,s={[y.MIN]:e,message:t,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return n.for(r).define({decorator:Oe,args:[Pe,r,s]}).apply()}function we(e,t=b.MAX){const r=y.MAX,s={[y.MAX]:e,message:t,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return n.for(r).define({decorator:Oe,args:[we,r,s]}).apply()}function _e(e,t=b.STEP){const r=y.STEP,s={[y.STEP]:e,message:t,description:"defines the step of the attribute as "+e,async:!1};return n.for(r).define({decorator:Oe,args:[_e,r,s]}).apply()}function Le(e,t=b.MIN_LENGTH){const r=y.MIN_LENGTH,s={[y.MIN_LENGTH]:e,message:t,description:`defines the min length of the attribute as ${e} (applies to strings or lists)`,async:!1};return n.for(r).define({decorator:Oe,args:[Le,r,s]}).apply()}function De(e,t=b.MAX_LENGTH){const r=y.MAX_LENGTH,s={[y.MAX_LENGTH]:e,message:t,description:`defines the max length of the attribute as ${e} (applies to strings or lists)`,async:!1};return n.for(r).define({decorator:Oe,args:[De,r,s]}).apply()}function Ie(e,t=b.PATTERN){const r=y.PATTERN,s={[y.PATTERN]:"string"==typeof e?e:e.toString(),message:t,description:`assigns the ${"string"===e?e:e.toString()} pattern to the attribute`,async:!1};return n.for(r).define({decorator:Oe,args:[Ie,r,s]}).apply()}function He(e=b.EMAIL){const t=y.EMAIL,r={[y.PATTERN]:A.EMAIL.toString(),message:e,description:"marks the attribute as an email",async:!1};return n.for(t).define({decorator:Oe,args:[He,t,r]}).apply()}function je(e=b.URL){const t=y.URL,r={[y.PATTERN]:A.URL.toString(),message:e,description:"marks the attribute as an url",async:!1};return n.for(t).define({decorator:Oe,args:[je,t,r]}).apply()}function Ue(e,t=b.TYPE){const r=y.TYPE,s={customTypes:e,message:t,description:"defines the accepted types for the attribute",async:!1};return n.for(r).define({decorator:Oe,args:[Ue,r,s]}).apply()}function xe(e="dd-MM-yyyy HH:mm:ss:S",t=b.DATE){const r=y.DATE;return n.for(r).define({decorator:function(e,t){const s={[y.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=Me(e,t),i.set(this,r)}catch(e){}}}),this[n]=t},get(){return i.get(this)}}),Oe(xe,r,s)(t,n)}},args:[e,t]}).apply()}function Ce(e=A.PASSWORD.CHAR8_ONE_OF_EACH,t=b.PASSWORD){const r=y.PASSWORD,s={[y.PATTERN]:e.toString(),message:t,description:"attribute as a password",async:!1};return n.for(r).define({decorator:Oe,args:[Ce,r,s]}).apply()}function Fe(e,t="Array",r=b.LIST){const s=y.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 n.for(s).define({decorator:Oe,args:[Fe,s,i]}).apply()}function ze(e,t=b.LIST){return Fe(e,"Set",t)}function Ye(e,t){return Oe(Ye,y.EQUALS,{label:t?.label||e,message:t?.message||b.EQUALS,[y.EQUALS]:e,description:"defines attribute as equal to "+e,async:!1})}function $e(e,t){return Oe($e,y.DIFF,{label:t?.label||e,message:t?.message||b.DIFF,[y.DIFF]:e,description:"defines attribute as different to "+e,async:!1})}function Ge(e,t){return Oe(Ge,y.LESS_THAN,{label:t?.label||e,message:t?.message||b.LESS_THAN,[y.LESS_THAN]:e,description:"defines attribute as less than to "+e,async:!1})}function Qe(e,t){return Oe(Qe,y.LESS_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||b.LESS_THAN_OR_EQUAL,[y.LESS_THAN_OR_EQUAL]:e,description:"defines attribute as less or equal to "+e,async:!1})}function ke(e,t){return Oe(ke,y.GREATER_THAN,{label:t?.label||e,message:t?.message||b.GREATER_THAN,[y.GREATER_THAN]:e,description:"defines attribute as greater than "+e,async:!1})}function Ve(e,t){return Oe(Ve,y.GREATER_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||b.GREATER_THAN_OR_EQUAL,[y.GREATER_THAN_OR_EQUAL]:e,description:"defines attribute as greater or equal to "+e,async:!1})}function qe(e,t=b.ENUM){const r=y.ENUM,s={[y.ENUM]:e,message:t,description:"defines a list or an object of accepted values for the attribute",async:!1};return n.for(r).define({decorator:Oe,args:[qe,r,s]}).apply()}me=c([q(y.URL),u("design:paramtypes",[String])],me);class Be{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){pe=e}static getBuilder(){return pe||Be.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]=Be.getRegistry().build(t[a],"string"==typeof n?n:void 0)}catch(e){}continue}if(s=e.allowedTypes(t.constructor,a),!s||!s.length)throw Error("failed to find decorators for property "+a);const c=s.map((e=>"function"!=typeof e||e.name?e:e())),u=Object.values(Q);c.forEach((r=>{if(!u.includes(r))try{switch(r.name){case"Array":case"Set":{const s=e.validationFor(t.constructor,a);if(!s||!s[y.LIST])break;const n=s[y.LIST].clazz.map((e=>"function"!=typeof e||e.name?e:e())).find((e=>!k.includes(e.name)));if("Array"===r.name&&(t[a]=t[a].map((e=>["object","function"].includes(typeof e)&&n?Be.getRegistry().build(e,n.name):e))),"Set"===r.name){const e=new Set;for(const r of t[a])["object","function"].includes(typeof r)&&n?e.add(Be.getRegistry().build(r,n.name)):e.add(r);t[a]=e}break}default:void 0!==t[a]&&Be.getRegistry().get(r.name)&&(t[a]=Be.getRegistry().build(t[a],r.name))}}catch(e){}}))}return t}static getRegistry(){return ye||(ye=new Be),ye}static setRegistry(e){ye=e}}function Xe(...e){e.forEach((e=>{const t=e.constructor?e.constructor:e;Be.getRegistry().register(t,e.name)}))}function Ke(e,t,r){Object.hasOwnProperty.call(e,t)||(e[t]=r)}function We(e,t){Object.hasOwnProperty.call(e,t)&&delete e[t]}function Ze(e,t,r,...s){t&&Ke(e,S,t),Ke(e,O,!!r);const n=e.hasErrors(...s);return We(e,S),We(e,O),n}function Je(e,t,r,s,n,...i){let o,a=!1;for(const c of s){const s=Be.getRegistry().get(c);if(s||(o=new f({[e]:{[y.TYPE]:"Unable to verify type consistency, missing model registry for "+c}})),t instanceof s){a=!0,o=Ze(t,r,n,...i);break}}return a?o:o||new f({[e]:{[y.TYPE]:"Value must be an instance of one of the expected types: "+s.join(", ")}})}function et(e,...t){return t?.map((t=>("string"==typeof t&&t?.startsWith(e+".")&&(t=t.replace(e+".","")),t)))}function tt(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===d.TYPE?[r]:r||{},o=Y.create(e,{ignoreUndefined:!0,ignoreNull:!0}),a=r.key===d.TYPE?i[0]:i;return $(n.hasErrors(t,a,o),s)}function rt(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=tt(t,s,u,i);if(c===y.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(e.isModel(n)){const e=et(r,...o);return Je(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 h=c===d.TYPE?y.TYPE:c;l&&(a[h]=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 st(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(y.LIST)){i[n]={[y.TYPE]:`Array or Set property '${n}' requires a @list decorator`};continue}if(c&&!(Array.isArray(c)||c instanceof Set)){i[n]={[y.TYPE]:`Property '${a+""}' must be either an Array or a Set`};continue}}const h=rt(t,n,c,u,r,...s)||{};if(e.isPropertyModel(t,n)&&null!=c){const e=l.map((e=>Be.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=et(n,...s);o[n]=Ze(c,t,r,...e)}else i.includes(typeof c)||(h[y.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 h[d.TYPE])}(Object.keys(h).length>0||r)&&(i[n]=h),r||Object.entries(o[n]||{}).forEach((([e,t])=>{void 0!==t&&(i[`${n}.${e}`]=t)}))}if(!r)return Object.keys(i).length>0?new f(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 f(t):void 0}))}function nt(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 it(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=nt,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 ot="default";class at{static{this.current=ot}static{this.cache={default:it}}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 ct{constructor(e=void 0){}isAsync(){return!!(this[O]??this?.constructor[O])}hasErrors(...e){return st(this,this.isAsync(),...e)}equals(e,...t){return X(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(X(this[n],t[n]))return e;if(ct.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)=>X(e,t[n][r])?null:e instanceof ct&&t[n][r]instanceof ct?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 ct.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return ct.hash(this)}static deserialize(t){let r;try{r=e.get(this.constructor,d.SERIALIZATION)}catch(e){r=void 0}return r&&r.serializer?g.deserialize(t,r.serializer,...r.args||[]):g.deserialize(t)}static fromObject(e,t){t||(t={});for(const r of ct.getAttributes(e))e[r]=t[r]??e[r]??void 0;return e}static fromModel(e,t){return Be.fromModel(e,t)}static setBuilder(e){Be.setBuilder(e)}static getBuilder(){return Be.getBuilder()}static getRegistry(){return Be.getRegistry()}static setRegistry(e){Be.setRegistry(e)}static register(e,t){return Be.getRegistry().register(e,t)}static get(e){return Be.getRegistry().get(e)}static build(e={},t){return ct.getRegistry().build(e,t)}static getAttributes(t){return e.getAttributes(t)}static equals(e,t,...r){return X(e,t,...r)}static hasErrors(e,t,...r){return st(e,t,...r)}static serialize(t){let r;try{r=e.get(t.constructor,d.SERIALIZATION)}catch(e){r=void 0}return r&&r.serializer?g.serialize(this,r.serializer,...r.args||[]):g.serialize(t)}static hash(t){const r=e.get(t.constructor,d.HASHING);return r&&r.algorithm?at.hash(t,r.algorithm,...r.args||[]):at.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 ut(e){return e instanceof dt?e.build():new Date(e)}function lt(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[y.TYPE]){const{designTypes:s}=e.getPropDesignTypes(t,r);n.validation[r]&&s?.length&&s[0]!==Q.OBJECT&&(n.validation[r][y.TYPE]={customTypes:s,message:b.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([...ct.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[y.TYPE]&&"function"==typeof n[y.TYPE]?.customTypes[Symbol.iterator]?[...n[y.TYPE].customTypes]:[s]}).bind(e),e.getPropDesignTypes=((t,r)=>{const s=e.get(t),n=e.type(t,r),i=s?.[y.REFLECT]?.[r];if(!(n||i&&i[y.TYPE]))return{};const o=i&&i[y.TYPE]?[i[y.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 ct)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&&Be.getRegistry().get(s.name)?s.name:void 0}).bind(e),e.getAttributes=(t=>{const r=t instanceof ct?t.constructor:t,s=new Set,n=t=>{if(!t)return[];const r=n(Object.getPrototypeOf(t)),i=e.properties(t)??[];for(const e of i)s.has(e)||(s.add(e),r.push(e));return r};return n(r)}).bind(e);class dt{constructor(){this.years=0,this.months=0,this.days=0,this.hours=0,this.minutes=0,this.seconds=0}static Years(e){return(new dt).Years(e)}static Months(e){return(new dt).Months(e)}static Days(e){return(new dt).Days(e)}static Hours(e){return(new dt).Hours(e)}static Minutes(e){return(new dt).Minutes(e)}static Seconds(e){return(new dt).Seconds(e)}static Now(){return new Date}static Tomorrow(){return dt.Days(1).from(dt.Now())}static Yesterday(){return dt.Days(1).until(dt.Now())}static DaysAgo(e){return dt.Days(e).until(dt.Now())}static NextDays(e){return dt.Days(e).from(dt.Now())}static YearsAgo(e){return dt.Years(e).until(dt.Now())}static NextYears(e){return dt.Years(e).from(dt.Now())}static MonthsAgo(e){return dt.Months(e).until(dt.Now())}static NextMonths(e){return dt.Months(e).from(dt.Now())}static HoursAgo(e){return dt.Hours(e).until(dt.Now())}static NextHours(e){return dt.Hours(e).from(dt.Now())}static MinutesAgo(e){return dt.Minutes(e).until(dt.Now())}static NextMinutes(e){return dt.Minutes(e).from(dt.Now())}static SecondsAgo(e){return dt.Seconds(e).until(dt.Now())}static NextSeconds(e){return dt.Seconds(e).from(dt.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 lt(ut(e),1,this.offsets())}past(e){return this.from(e)}after(e){return this.from(e)}until(e){return lt(ut(e),-1,this.offsets())}before(e){return this.until(e)}ago(e=new Date){return this.until(e)}Now(){return dt.Now()}Tomorrow(){return dt.Tomorrow()}Yesterday(){return dt.Yesterday()}DaysAgo(e){return dt.DaysAgo(e)}NextDays(e){return dt.NextDays(e)}YearsAgo(e){return dt.YearsAgo(e)}NextYears(e){return dt.NextYears(e)}MonthsAgo(e){return dt.MonthsAgo(e)}NextMonths(e){return dt.NextMonths(e)}HoursAgo(e){return dt.HoursAgo(e)}NextHours(e){return dt.NextHours(e)}MinutesAgo(e){return dt.MinutesAgo(e)}NextMinutes(e){return dt.NextMinutes(e)}SecondsAgo(e){return dt.SecondsAgo(e)}NextSeconds(e){return dt.NextSeconds(e)}offsets(){return{years:this.years,months:this.months,days:this.days,hours:this.hours,minutes:this.minutes,seconds:this.seconds}}}const ht=dt,gt=()=>dt.Now(),ft=()=>dt.Tomorrow(),pt=()=>dt.Yesterday(),yt=e=>dt.DaysAgo(e),mt=e=>dt.NextDays(e),Et=e=>dt.YearsAgo(e),bt=e=>dt.NextYears(e),At=e=>dt.MonthsAgo(e),Tt=e=>dt.NextMonths(e),Nt=e=>dt.HoursAgo(e),Mt=e=>dt.NextHours(e),St=e=>dt.MinutesAgo(e),Ot=e=>dt.NextMinutes(e),Rt=e=>dt.SecondsAgo(e),vt=e=>dt.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[d.ANCHOR]=n||t.constructor.name,s}deserialize(e,...t){const r=JSON.parse(e),s=r[d.ANCHOR];if(!s)throw Error("Could not find class reference in serialized model");return ct.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 _t(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 Lt(e){if(e instanceof ct)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,ct.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,ct.prototype)}throw Error("Could not find proper prototype to bind")}function Dt(e){const t=(...t)=>{const r=wt(e,...t);Lt(r);const s=ct.getBuilder();return s&&s(r,t.length?t[0]:void 0),r};return t.prototype=e.prototype,Object.defineProperty(t,"name",{writable:!1,enumerable:!0,configurable:!1,value:e.prototype.constructor.name}),r(d.CONSTRUCTOR,e)(t),ct.register(t,e.name),t}function It(){const e=d.MODEL;return n.for(e).define(Dt).apply()}function Ht(e,...t){return r(d.HASHING,{algorithm:e,args:t})}function jt(e,...t){return r(d.SERIALIZATION,{serializer:e,args:t})}g.cache={json:new Pt};class Ut{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=Ut.asMeta(e),r="string"==typeof e?e:Ut.resolveMessage(t);return this.decorate(ve(r))}min(e,t){const r=Ut.asMeta(e),s=r?.[y.MIN]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${y.MIN} for ${this.attr+""}`);return this.decorate(Pe(s,Ut.resolveMessage(r,t)))}max(e,t){const r=Ut.asMeta(e),s=r?.[y.MAX]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${y.MAX} for ${this.attr+""}`);return this.decorate(we(s,Ut.resolveMessage(r,t)))}step(e,t){const r=Ut.asMeta(e),s=r?.[y.STEP]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${y.STEP} for ${this.attr+""}`);return this.decorate(_e(s,Ut.resolveMessage(r,t)))}minlength(e,t){const r=Ut.asMeta(e),s=r?.[y.MIN_LENGTH]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${y.MIN_LENGTH} for ${this.attr+""}`);return this.decorate(Le(s,Ut.resolveMessage(r,t)))}maxlength(e,t){const r=Ut.asMeta(e),s=r?.[y.MAX_LENGTH]??(r?void 0:e);if(void 0===s)throw Error(`Missing ${y.MAX_LENGTH} for ${this.attr+""}`);return this.decorate(De(s,Ut.resolveMessage(r,t)))}pattern(e,t){const r=Ut.asMeta(e),s=r?.[y.PATTERN]??(r?void 0:e),n=Ut.patternFromString(s)??/.*/;return this.decorate(Ie(n,Ut.resolveMessage(r,t)))}email(e){const t=Ut.asMeta(e),r="string"==typeof e?e:Ut.resolveMessage(t);return this.decorate(He(r))}url(e){const t=Ut.asMeta(e),r="string"==typeof e?e:Ut.resolveMessage(t);return this.decorate(je(r))}type(e,t){const r=Ut.asMeta(e),s=r?.customTypes??r?.type??(r?void 0:e);return this.decorate(Ue(s,Ut.resolveMessage(r,t)))}date(e,t){const r=Ut.asMeta(e),s=r?.[y.FORMAT]??(r?void 0:e);return this.decorate(xe(s,Ut.resolveMessage(r,t)))}password(e,t){const r=Ut.asMeta(e),s=r?.[y.PATTERN]??(r?void 0:e),n=Ut.patternFromString(s);return this.decorate(Ce(n,Ut.resolveMessage(r,t)))}list(e,t,r){const s=Ut.asMeta(e),n=s?.clazz??(s?void 0:e),i=s?.type??t;return this.decorate(Fe(n,i,Ut.resolveMessage(s,r)))}set(e,t){return Ut.isMetadataPayload(e)?this.list(e):this.list(e,"Set",t)}enum(e,t){const r=Ut.asMeta(e),s=r?.[y.ENUM]??(r?void 0:e);return this.decorate(qe(s,Ut.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 Ut.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=Ut.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,y.EQUALS,t);return this.decorate(Ye(r,s))}eq(e,t){return this.equals(e,t)}different(e,t){const{target:r,options:s}=this.resolveComparison(e,y.DIFF,t);return this.decorate($e(r,s))}diff(e,t){return this.different(e,t)}lessThan(e,t){const{target:r,options:s}=this.resolveComparison(e,y.LESS_THAN,t);return this.decorate(Ge(r,s))}lt(e,t){return this.lessThan(e,t)}lessThanOrEqual(e,t){const{target:r,options:s}=this.resolveComparison(e,y.LESS_THAN_OR_EQUAL,t);return this.decorate(Qe(r,s))}lte(e,t){return this.lessThanOrEqual(e,t)}greaterThan(e,t){const{target:r,options:s}=this.resolveComparison(e,y.GREATER_THAN,t);return this.decorate(ke(r,s))}gt(e,t){return this.greaterThan(e,t)}greaterThanOrEqual(e,t){const{target:r,options:s}=this.resolveComparison(e,y.GREATER_THAN_OR_EQUAL,t);return this.decorate(Ve(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 xt{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=Ct.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 Ct extends l{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 Ut(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 Ct;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 xt(this,s,t)}build(){if(!this._name)throw Error("name is required");const e=this._parent??ct;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=It()(t);return this._description&&(r=i(this._description)(r)),r}static builder(){return new Ct}static from(e,t){if(!e)throw Error("metadata is required");const r=Ct.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##",zt="##PACKAGE##";e.registerLibrary(zt,Ft);export{O as ASYNC_META_KEY,V as AsyncValidator,Ut as AttributeBuilder,M as COMPARISON_ERROR_MESSAGES,p as ComparisonValidationKeys,E as DAYS_OF_WEEK_NAMES,b as DEFAULT_ERROR_MESSAGES,A as DEFAULT_PATTERNS,dt as DateBuilder,B as DateValidator,ht as Dates,yt as DaysAgo,ot as DefaultHashingMethod,h as DefaultSerializationMethod,K as DiffValidator,J as EmailValidator,ee as EqualsValidator,re as GreaterThanOrEqualValidator,te as GreaterThanValidator,at as Hashing,Nt as HoursAgo,Pt as JSONSerializer,ne as LessThanOrEqualValidator,se as LessThanValidator,ie as ListValidator,m as MONTH_NAMES,oe as MaxLengthValidator,ae as MaxValidator,ce as MinLengthValidator,ue as MinValidator,St as MinutesAg