@decaf-ts/decorator-validation 1.11.12 → 1.11.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/decorator-validation.cjs +1 -1
- package/dist/decorator-validation.cjs.map +1 -1
- package/dist/decorator-validation.js +1 -1
- package/dist/decorator-validation.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/utils/DateBuilder.d.ts +57 -0
- package/lib/esm/utils/DateBuilder.js +121 -0
- package/lib/esm/utils/DateBuilder.js.map +1 -0
- package/lib/esm/utils/index.d.ts +1 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/index.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/utils/DateBuilder.cjs +141 -0
- package/lib/utils/DateBuilder.d.ts +57 -0
- package/lib/utils/DateBuilder.js.map +1 -0
- package/lib/utils/index.cjs +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ A TypeScript decorator-driven validation and model framework. It lets you:
|
|
|
33
33
|
|
|
34
34
|
Documentation available [here](https://decaf-ts.github.io/decorator-validation/)
|
|
35
35
|
|
|
36
|
-
Minimal size:
|
|
36
|
+
Minimal size: 14.2 KB kb gzipped
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
# Decorator Validation – Detailed Description
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e,t,r,a){"use strict";var s;e.ModelKeys=void 0,(s=e.ModelKeys||(e.ModelKeys={})).DESCRIPTION="description",s.TYPE="design:type",s.MODEL="model",s.ANCHOR="__model",s.CONSTRUCTION="constructed-by",s.ATTRIBUTE="__attributes",s.HASHING="hashing",s.SERIALIZATION="serialization",s.DECORATORS="decorators",s.CONSTRUCTOR="__original";const i="json";class n{static{this.current=i}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 o{constructor(e){for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&Object.defineProperty(this,t,{enumerable:!0,configurable:!1,value:e[t],writable:!1})}toString(){const e=this;return Object.keys(e).filter((t=>Object.prototype.hasOwnProperty.call(e,t)&&"function"!=typeof e[t])).reduce(((t,r)=>{let a=Object.keys(e[r]).reduce(((t,a)=>(t?t+="\n"+e[r][a]:t=e[r][a],t)),void 0);return a&&(a=`${r} - ${a}`,t?t+="\n"+a:t=a),t}),"")}}const c={EQUALS:"equals",DIFF:"different",LESS_THAN:"lessThan",LESS_THAN_OR_EQUAL:"lessThanOrEqual",GREATER_THAN:"greaterThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual"},d={REFLECT:"validation",DATE:"date",EMAIL:"email",FORMAT:"format",LIST:"list",MAX:"max",MAX_LENGTH:"maxlength",MIN:"min",MIN_LENGTH:"minlength",PASSWORD:"password",PATTERN:"pattern",REQUIRED:"required",STEP:"step",TYPE:"type",UNIQUE:"unique",URL:"url",VALIDATOR:"validator",ENUM:"enum",...c},u=["January","February","March","April","May","June","July","August","September","October","November","December"],l=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],g={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}"},f={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 h(e,...t){return e.replace(/{(\d+)}/g,((e,r)=>void 0!==t[r]?t[r].toString():"undefined"))}const p=h,y={INVALID_PATH:"Invalid path argument. Expected non-empty string but received: '{0}'",CONTEXT_NOT_OBJECT_COMPARISON:"Unable to access parent at level {0} for path '{1}': current context is not an object",PROPERTY_INVALID:"Failed to resolve path {0}: property '{1}' is invalid or does not exist.",PROPERTY_NOT_EXIST:"Failed to resolve path: property '{0}' does not exist.",UNSUPPORTED_TYPES_COMPARISON:"Unsupported types for comparison: '{0}' and '{1}'",NULL_OR_UNDEFINED_COMPARISON:"Comparison failed due to null or undefined value",INVALID_DATE_COMPARISON:"Invalid Date objects are not comparable",TYPE_MISMATCH_COMPARISON:"Cannot compare values of different types: {0} and {1}.",NAN_COMPARISON:"Comparison not supported for NaN values"},m=Symbol("_parent"),E=Symbol("isAsync"),T=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 b(e,t){if(M(e)&&M(t))return!0;throw new TypeError(p(y.UNSUPPORTED_TYPES_COMPARISON,T(e),T(t)))}function A(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(y.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,a=typeof t;if(r!==a){if("bigint"===r&&"number"===a)return t>Number(e);if("number"===r&&"bigint"===a)return Number(t)>e;throw new TypeError(p(y.TYPE_MISMATCH_COMPARISON,r,a))}if("number"===r&&"number"===a||"bigint"===r&&"bigint"===a){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(y.NAN_COMPARISON);return t>e}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(y.INVALID_DATE_COMPARISON);return e.getTime()<t.getTime()}throw new TypeError(p(y.UNSUPPORTED_TYPES_COMPARISON,T(e),T(t)))}function N(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(y.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,a=typeof t;if(r!==a){if("bigint"===r&&"number"===a)return Number(e)>t;if("number"===r&&"bigint"===a)return e>Number(t);throw Error(p(y.TYPE_MISMATCH_COMPARISON,r,a))}if("number"===r&&"number"===a||"bigint"===r&&"bigint"===a){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(y.NAN_COMPARISON);return e>t}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(y.INVALID_DATE_COMPARISON);return e.getTime()>t.getTime()}throw new TypeError(p(y.UNSUPPORTED_TYPES_COMPARISON,T(e),T(t)))}function O(e,t){return typeof e===t.toLowerCase()||void 0!==e&&"object"==typeof e&&e.constructor&&e.constructor.name.toLowerCase()===t.toLowerCase()}function _(e,t){return!t.every((t=>!O(e,t)))}function S(e,t){switch(typeof t){case"string":return O(e,t);case"object":return!Array.isArray(t)||_(e,t);case"function":return!t.name||"Object"===t.name||O(e,t.name);default:return!0}}function R(e){return e instanceof Set||e instanceof Map?e.size:e.length}class v{constructor(e,t=g.DEFAULT,...r){this.async=e,this.message=t,r.length&&(this.acceptedTypes=r),this.acceptedTypes&&(this.hasErrors=this.checkTypeAndHasErrors(this.hasErrors.bind(this)))}getMessage(e,...t){return p(e,...t)}checkTypeAndHasErrors(e){return function(t,r,a,...s){return void 0!==t&&this.acceptedTypes?_(t,this.acceptedTypes)?e(t,r,a,...s):this.getMessage(g.TYPE,this.acceptedTypes.join(", "),"number"!=typeof t?typeof t:isNaN(t)?"NaN":typeof t):e(t,r,a,...s)}.bind(this)}static isValidator(e){return e.constructor&&!!e.hasErrors}}class P extends v{constructor(e=g.DEFAULT,...t){super(!1,e,...t)}}class L{constructor(...e){this.cache={},this.customKeyCache={},this.register(...e)}getCustomKeys(){return Object.assign({},this.customKeyCache)}getKeys(){return Object.keys(this.cache)}get(e){if(!(e in this.cache))return;const t=this.cache[e];if(P.isValidator(t))return t;const r=new(t.default||t);return this.cache[e]=r,r}register(...e){e.forEach((e=>{if(P.isValidator(e)){if(e.validationKey in this.cache)return;this.cache[e.validationKey]=e}else{const{validationKey:t,validator:r,save:a}=e;if(t in this.cache)return;if(this.cache[t]=r,!a)return;const s={};s[t.toUpperCase()]=t,this.customKeyCache=Object.assign({},this.customKeyCache,s)}}))}}class D{static{this.actingValidatorRegistry=void 0}constructor(){}static setRegistry(e,t){t&&D.actingValidatorRegistry&&D.actingValidatorRegistry.getKeys().forEach((r=>{const a=e.get(r);a&&e.register(t(a))})),D.actingValidatorRegistry=e}static getRegistry(){return D.actingValidatorRegistry||(D.actingValidatorRegistry=new L),D.actingValidatorRegistry}static get(e){return D.getRegistry().get(e)}static register(...e){return D.getRegistry().register(...e)}static key(e){return d.REFLECT+e}static keys(){return this.getRegistry().getKeys()}static registerDecorator(r,a){const s=t.Metadata.innerGet(Symbol.for(e.ModelKeys.DECORATORS),t.Metadata.key(d.REFLECT,r));s?.[r]||t.Metadata.set(e.ModelKeys.DECORATORS,t.Metadata.key(d.REFLECT,r),a)}static decoratorFromKey(r){try{return t.Metadata.innerGet(Symbol.for(e.ModelKeys.DECORATORS),t.Metadata.key(d.REFLECT,r))}catch(e){throw Error(`No decorator registered under ${r}: ${e}`)}}}const w=e=>e[m],I=(e,t)=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw Error(p(y.PROPERTY_NOT_EXIST,t));return e[t]};class V{static create(e,t){const{getValue:r,getParent:a,ignoreUndefined:s,ignoreNull:i}={getParent:w,getValue:I,ignoreNull:!1,ignoreUndefined:!1,...t};return new Proxy({},{get:(t,n)=>"getValueFromPath"===n?t=>{const n=V.parsePath(t);let o=e;for(let e=0;e<n.length;e++){const c=n[e];if(".."!==c){if(o=r(o,c),!s&&void 0===o)throw Error(p(y.PROPERTY_INVALID,t,c));if(!i&&null===o)throw Error(p(y.PROPERTY_INVALID,t,c))}else{const r=a(o);if(!r||"object"!=typeof r)throw Error(p(y.CONTEXT_NOT_OBJECT_COMPARISON,e+1,t));o=r}}return o}:t[n]})}static parsePath(e){if("string"!=typeof e||!e.trim())throw Error(p(y.INVALID_PATH,e));return e.match(/(\.\.|[^/.]+)/g)||[]}}function j(e,t){return t?Promise.resolve(e):e}var U;e.Primitives=void 0,(U=e.Primitives||(e.Primitives={})).STRING="string",U.NUMBER="number",U.BOOLEAN="boolean",U.BIGINT="bigint";const C={STRING:String,OBJECT:Object,NUMBER:Number,BOOLEAN:Boolean,BIGINT:BigInt,DATE:Date},H=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"];function x(...e){return t.apply((t=>(e.forEach((e=>{D.register({validator:t,validationKey:e,save:!0})})),t)),t.metadata(d.VALIDATOR,e))}function F(e,t,...r){if(e===t)return 0!==e||1/e==1/t;if(null==e||null==t)return e===t;if(typeof e!=typeof t)return!1;if(Number.isNaN(e)&&Number.isNaN(t))return!0;if("object"!=typeof e)return e===t;if(e instanceof Date&&t instanceof Date)return!(!isNaN(e.getTime())||!isNaN(t.getTime()))||e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(e instanceof Error&&t instanceof Error)return e.name===t.name&&e.message===t.message;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(!F(e[a],t[a],...r))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[a,s]of e)if(!t.has(a)||!F(s,t.get(a),...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),a=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<r.length;e++)if(r[e]!==a[e])return!1;return!0}const a=Object.keys(e).filter((e=>!r.includes(e))),s=Object.keys(t).filter((e=>!r.includes(e)));if(a.length!==s.length)return!1;for(const i of a){if(!s.includes(i))return!1;if(!F(e[i],t[i],...r))return!1}const i=Object.getOwnPropertySymbols(e).filter((e=>!r.includes(e.toString()))),n=Object.getOwnPropertySymbols(t).filter((e=>!r.includes(e.toString())));if(i.length!==n.length)return!1;for(const a of i){if(!n.includes(a))return!1;if(!F(e[a],t[a],...r))return!1}return Object.getPrototypeOf(e)===Object.getPrototypeOf(t)}e.DateValidator=class extends P{constructor(e=g.DATE){super(e,Number.name,Date.name,String.name)}hasErrors(e,t={}){if(void 0!==e&&("string"==typeof e&&(e=new Date(e)),Number.isNaN(e.getDate()))){const{message:e=""}=t;return this.getMessage(e||this.message)}}},e.DateValidator=r.__decorate([x(d.DATE),r.__metadata("design:paramtypes",[String])],e.DateValidator),e.DiffValidator=class extends P{constructor(e=g.DIFF){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[d.DIFF])}catch(e){return this.getMessage(e.message||this.message)}return F(e,a)?this.getMessage(t.message||this.message,t.label||t[d.DIFF]):void 0}},e.DiffValidator=r.__decorate([x(d.DIFF),r.__metadata("design:paramtypes",[String])],e.DiffValidator);const z=RegExp("^/(.+)/([gimus]*)$");function G(e,t){let r=t;r.match(/hh/)?r=r.replace("hh","(?<hour>\\d{2})"):r.match(/h/)?r=r.replace("h","(?<hour>\\d{1,2})"):r.match(/HH/)?r=r.replace("HH","(?<hour>\\d{2})"):r.match(/H/)&&(r=r.replace("H","(?<hour>\\d{1,2})")),r.match(/mm/)?r=r.replace("mm","(?<minutes>\\d{2})"):r.match(/m/)&&(r=r.replace("m","(?<minutes>\\d{1,2})")),r.match(/ss/)?r=r.replace("ss","(?<seconds>\\d{2})"):r.match(/s/)&&(r=r.replace("s","(?<seconds>\\d{1,2})")),r.match(/dd/)?r=r.replace("dd","(?<day>\\d{2})"):r.match(/d/)&&(r=r.replace("d","(?<day>\\d{1,2})")),r.match(/EEEE/)?r=r.replace("EEEE","(?<dayofweek>\\w+)"):r.match(/EEEE/)&&(r=r.replace("EEE","(?<dayofweek>\\w+)")),r.match(/yyyy/)?r=r.replace("yyyy","(?<year>\\d{4})"):r.match(/yy/)&&(r=r.replace("yy","(?<year>\\d{2})")),r.match(/MMMM/)?r=r.replace("MMMM","(?<monthname>\\w+)"):r.match(/MMM/)&&(r=r.replace("MMM","(?<monthnamesmall>\\w+)")),r.match(/MM/)?r=r.replace("MM","(?<month>\\d{2})"):r.match(/M/)&&(r=r.replace("M","(?<month>\\d{1,2})")),r=r.replace("S","(?<milis>\\d{1,3})").replace("aaa","(?<ampm>\\w{2})");const a=RegExp(r,"g").exec(e);if(!a||!a.groups)return new Date(e);const s=e=>{if(!e)return 0;const t=parseInt(e);return isNaN(t)?0:t},i=s(a.groups.year),n=s(a.groups.day),o=a.groups.ampm;let c=s(a.groups.hour);o&&(c="PM"===o?c+12:c);const d=s(a.groups.minutes),l=s(a.groups.seconds),g=s(a.groups.milis),f=a.groups.monthname,h=a.groups.monthnamesmall;let p=a.groups.month;if(f)p=u.indexOf(f);else if(h){const t=u.find((e=>e.toLowerCase().startsWith(h.toLowerCase())));if(!t)return new Date(e);p=u.indexOf(t)}else p=s(""+p);return new Date(i,p-1,n,c,d,l,g)}function $(e,t){if(e)return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>K(r,t)})}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>K(r,t)})}),e}function Y(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function q(e){return 10>e?"0"+e:e.toString()}function K(e,t="yyyy/MM/dd"){const r=e.getDate(),a=e.getMonth(),s=e.getFullYear(),i=e.getHours(),n=e.getMinutes(),o=e.getSeconds(),c=e.getMilliseconds(),d=i%12,g=q(d),f=q(i),h=q(n),p=q(o),y=12>i?"AM":"PM",m=l[e.getDay()],E=m.substr(0,3),T=q(r),M=a+1,b=q(M),A=u[a],N=A.substr(0,3),O=s+"",_=O.substr(2,2);return(t=t.replace("hh",g).replace("h",d.toString()).replace("HH",f).replace("H",i.toString()).replace("mm",h).replace("m",n.toString()).replace("ss",p).replace("s",o.toString()).replace("S",c.toString()).replace("dd",T).replace("d",r.toString()).replace("EEEE",m).replace("EEE",E).replace("yyyy",O).replace("yy",_).replace("aaa",y)).indexOf("MMM")>-1?t.replace("MMMM",A).replace("MMM",N):t.replace("MM",b).replace("M",M.toString())}function k(e,t){let r;if(t){if(t instanceof Date)try{r=G(K(t,e),e)}catch(r){throw Error(p("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=G(t,e);else if("number"==typeof t)r=G(K(new Date(t),e),e);else{if(!Y(t))throw Error("Invalid value provided "+t);try{r=G(K(new Date(t),e),e)}catch(r){throw Error(p("Could not convert date {0} to format: {1}",t,e))}}return $(r,e)}}function Q(e,r,a){return t.apply(t.propMetadata(r,a))}function B(e,t,r){return D.registerDecorator(t,e),(e,a)=>Q(0,`${d.REFLECT}.${a}.${t}`,r)(e,a)}function X(e=g.REQUIRED){const r=d.REQUIRED,a={message:e,description:"defines the attribute as required",async:!1};return t.Decoration.for(r).define({decorator:B,args:[X,r,a]}).apply()}function W(e,r=g.MIN){const a=d.MIN,s={[d.MIN]:e,message:r,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[W,a,s]}).apply()}function Z(e,r=g.MAX){const a=d.MAX,s={[d.MAX]:e,message:r,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[Z,a,s]}).apply()}function J(e,r=g.STEP){const a=d.STEP,s={[d.STEP]:e,message:r,description:"defines the step of the attribute as "+e,async:!1};return t.Decoration.for(a).define({decorator:B,args:[J,a,s]}).apply()}function ee(e,r=g.MIN_LENGTH){const a=d.MIN_LENGTH,s={[d.MIN_LENGTH]:e,message:r,description:`defines the min length of the attribute as ${e} (applies to strings or lists)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[ee,a,s]}).apply()}function te(e,r=g.MAX_LENGTH){const a=d.MAX_LENGTH,s={[d.MAX_LENGTH]:e,message:r,description:`defines the max length of the attribute as ${e} (applies to strings or lists)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[te,a,s]}).apply()}function re(e,r=g.PATTERN){const a=d.PATTERN,s={[d.PATTERN]:"string"==typeof e?e:e.toString(),message:r,description:`assigns the ${"string"===e?e:e.toString()} pattern to the attribute`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[re,a,s]}).apply()}function ae(e=g.EMAIL){const r=d.EMAIL,a={[d.PATTERN]:f.EMAIL.toString(),message:e,description:"marks the attribute as an email",async:!1};return t.Decoration.for(r).define({decorator:B,args:[ae,r,a]}).apply()}function se(e=g.URL){const r=d.URL,a={[d.PATTERN]:f.URL.toString(),message:e,description:"marks the attribute as an url",async:!1};return t.Decoration.for(r).define({decorator:B,args:[se,r,a]}).apply()}function ie(e,r=g.TYPE){const a=d.TYPE,s={customTypes:e,message:r,description:"defines the accepted types for the attribute",async:!1};return t.Decoration.for(a).define({decorator:B,args:[ie,a,s]}).apply()}function ne(e="dd/MM/yyyy",r=g.DATE){const a=d.DATE;return t.Decoration.for(a).define({decorator:function(e,t){const r={[d.FORMAT]:e,message:t,description:"defines the attribute as a date with the format "+e,async:!1};return function(t,s){const i=new WeakMap;return Object.defineProperty(t,s,{configurable:!0,set(t){const r=Object.getOwnPropertyDescriptor(this,s);r&&!r.configurable||Object.defineProperty(this,s,{enumerable:!0,configurable:!1,get:()=>i.get(this),set:t=>{let r;try{r=k(e,t),i.set(this,r)}catch(e){}}}),this[s]=t},get(){return i.get(this)}}),B(ne,a,r)(t,s)}},args:[e,r]}).apply()}function oe(e=f.PASSWORD.CHAR8_ONE_OF_EACH,r=g.PASSWORD){const a=d.PASSWORD,s={[d.PATTERN]:e.toString(),message:r,description:"attribute as a password",async:!1};return t.Decoration.for(a).define({decorator:B,args:[oe,a,s]}).apply()}function ce(e,r="Array",a=g.LIST){const s=d.LIST,i={clazz:Array.isArray(e)?e:[e],type:r,message:a,async:!1,description:`defines the attribute as a ${r} of ${e.name}`};return t.Decoration.for(s).define({decorator:B,args:[ce,s,i]}).apply()}function de(e,t){return B(de,d.EQUALS,{label:t?.label||e,message:t?.message||g.EQUALS,[d.EQUALS]:e,description:"defines attribute as equal to "+e,async:!1})}function ue(e,t){return B(ue,d.DIFF,{label:t?.label||e,message:t?.message||g.DIFF,[d.DIFF]:e,description:"defines attribute as different to "+e,async:!1})}function le(e,t){return B(le,d.LESS_THAN,{label:t?.label||e,message:t?.message||g.LESS_THAN,[d.LESS_THAN]:e,description:"defines attribute as less than to "+e,async:!1})}function ge(e,t){return B(ge,d.LESS_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||g.LESS_THAN_OR_EQUAL,[d.LESS_THAN_OR_EQUAL]:e,description:"defines attribute as less or equal to "+e,async:!1})}function fe(e,t){return B(fe,d.GREATER_THAN,{label:t?.label||e,message:t?.message||g.GREATER_THAN,[d.GREATER_THAN]:e,description:"defines attribute as greater than "+e,async:!1})}function he(e,t){return B(he,d.GREATER_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||g.GREATER_THAN_OR_EQUAL,[d.GREATER_THAN_OR_EQUAL]:e,description:"defines attribute as greater or equal to "+e,async:!1})}function pe(e,r=g.ENUM){const a=d.ENUM,s={[d.ENUM]:e,message:r,description:"defines a list or an object of accepted values for the attribute",async:!1};return t.Decoration.for(a).define({decorator:B,args:[pe,a,s]}).apply()}let ye,me;e.PatternValidator=class extends P{constructor(e=g.PATTERN){super(e,"string")}getPattern(e){if(!z.test(e))return RegExp(e);const t=e.match(z);return RegExp(t[1],t[2])}hasErrors(e,t){if(!e)return;let{pattern:r}=t;if(!r)throw Error("Missing Pattern");return r="string"==typeof r?this.getPattern(r):r,r.lastIndex=0,r.test(e)?void 0:this.getMessage(t.message||this.message)}},e.PatternValidator=r.__decorate([x(d.PATTERN),r.__metadata("design:paramtypes",[String])],e.PatternValidator),e.EmailValidator=class extends e.PatternValidator{constructor(e=g.EMAIL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t?.pattern||f.EMAIL})}},e.EmailValidator=r.__decorate([x(d.EMAIL),r.__metadata("design:paramtypes",[String])],e.EmailValidator),e.EqualsValidator=class extends P{constructor(e=g.EQUALS){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[d.EQUALS])}catch(e){return this.getMessage(e.message||this.message)}return F(e,a)?void 0:this.getMessage(t.message||this.message,t.label||t[d.EQUALS])}},e.EqualsValidator=r.__decorate([x(d.EQUALS),r.__metadata("design:paramtypes",[String])],e.EqualsValidator),e.GreaterThanValidator=class extends P{constructor(e=g.GREATER_THAN){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[d.GREATER_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!N(e,a))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[d.GREATER_THAN])}}},e.GreaterThanValidator=r.__decorate([x(d.GREATER_THAN),r.__metadata("design:paramtypes",[String])],e.GreaterThanValidator),e.GreaterThanOrEqualValidator=class extends P{constructor(e=g.GREATER_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[d.GREATER_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(b(e,a)&&F(e,a)||N(e,a))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[d.GREATER_THAN_OR_EQUAL])}}},e.GreaterThanOrEqualValidator=r.__decorate([x(d.GREATER_THAN_OR_EQUAL),r.__metadata("design:paramtypes",[String])],e.GreaterThanOrEqualValidator),e.LessThanValidator=class extends P{constructor(e=g.LESS_THAN){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[d.LESS_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!A(e,a))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[d.LESS_THAN])}}},e.LessThanValidator=r.__decorate([x(d.LESS_THAN),r.__metadata("design:paramtypes",[String])],e.LessThanValidator),e.LessThanOrEqualValidator=class extends P{constructor(e=g.LESS_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[d.LESS_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(b(e,a)&&F(e,a)||A(e,a))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[d.LESS_THAN_OR_EQUAL])}}},e.LessThanOrEqualValidator=r.__decorate([x(d.LESS_THAN_OR_EQUAL),r.__metadata("design:paramtypes",[String])],e.LessThanOrEqualValidator),e.ListValidator=class extends P{constructor(e=g.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 a,s=!0;for(let t=0;t<(Array.isArray(e)?e.length:e.size);t++)switch(a=[...e][t],typeof a){case"object":case"function":s=r.includes((a??{}).constructor?.name);break;default:s=r.some((e=>typeof a===e?.toLowerCase()))}return s?void 0:this.getMessage(t.message||this.message,r)}},e.ListValidator=r.__decorate([x(d.LIST),r.__metadata("design:paramtypes",[String])],e.ListValidator),e.MaxLengthValidator=class extends P{constructor(e=g.MAX_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return R(e)>t.maxlength?this.getMessage(t.message||this.message,t.maxlength):void 0}},e.MaxLengthValidator=r.__decorate([x(d.MAX_LENGTH),r.__metadata("design:paramtypes",[String])],e.MaxLengthValidator),e.MaxValidator=class extends P{constructor(e=g.MAX){super(e,Number.name,Date.name,String.name)}hasErrors(e,t){if(void 0===e)return;let{max:r}=t;if(e instanceof Date&&!(r instanceof Date)&&(r=new Date(r),Number.isNaN(r.getDate())))throw Error("Invalid Max param defined");return e>r?this.getMessage(t.message||this.message,r):void 0}},e.MaxValidator=r.__decorate([x(d.MAX),r.__metadata("design:paramtypes",[String])],e.MaxValidator),e.MinLengthValidator=class extends P{constructor(e=g.MIN_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return R(e)<t.minlength?this.getMessage(t.message||this.message,t.minlength):void 0}},e.MinLengthValidator=r.__decorate([x(d.MIN_LENGTH),r.__metadata("design:paramtypes",[String])],e.MinLengthValidator),e.MinValidator=class extends P{constructor(e=g.MIN){super(e,Number.name,Date.name,String.name)}hasErrors(e,t){if(void 0===e)return;let{min:r}=t;if(e instanceof Date&&!(r instanceof Date)&&(r=new Date(r),Number.isNaN(r.getDate())))throw Error("Invalid Min param defined");return r>e?this.getMessage(t.message||this.message,r):void 0}},e.MinValidator=r.__decorate([x(d.MIN),r.__metadata("design:paramtypes",[String])],e.MinValidator),e.OptionValidator=class extends P{constructor(e=g.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 a of r)if(t.enum[a]===e)return;return this.getMessage(t.message||this.message,Object.values(t.enum))}}}},e.OptionValidator=r.__decorate([x(d.ENUM),r.__metadata("design:paramtypes",[String])],e.OptionValidator),e.PasswordValidator=class extends e.PatternValidator{constructor(e=g.PASSWORD){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,[d.PATTERN]:t?.pattern||f.PASSWORD.CHAR8_ONE_OF_EACH})}},e.PasswordValidator=r.__decorate([x(d.PASSWORD),r.__metadata("design:paramtypes",[Object])],e.PasswordValidator),e.RequiredValidator=class extends P{constructor(e=g.REQUIRED){super(e)}hasErrors(e,t={}){switch(typeof e){case"boolean":case"number":return void 0===e?this.getMessage(t.message||this.message):void 0;default:return e?void 0:this.getMessage(t.message||this.message)}}},e.RequiredValidator=r.__decorate([x(d.REQUIRED),r.__metadata("design:paramtypes",[String])],e.RequiredValidator),e.StepValidator=class extends P{constructor(e=g.STEP){super(e,"number","string")}hasErrors(e,t){if(void 0!==e)return Number(e)%Number(t.step)!=0?this.getMessage(t.message||this.message,t.step):void 0}},e.StepValidator=r.__decorate([x(d.STEP),r.__metadata("design:paramtypes",[String])],e.StepValidator),e.TypeValidator=class extends P{constructor(e=g.TYPE){super(e)}hasErrors(e,t){if(void 0===e)return;const{type:r,message:a,customTypes:s}=t;let i=s||r;return i=(Array.isArray(i)?i:[i]).map((e=>"string"==typeof e?e:("function"!=typeof e||e.name||(e=e()),e.name||e))),S(e,i)?void 0:this.getMessage(a||this.message,"string"==typeof i?i:Array.isArray(i)?i.join(", "):i,typeof e)}},e.TypeValidator=r.__decorate([x(d.TYPE),r.__metadata("design:paramtypes",[String])],e.TypeValidator),D.register({validator:e.TypeValidator,validationKey:e.ModelKeys.TYPE,save:!1}),e.URLValidator=class extends e.PatternValidator{constructor(e=g.URL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t.pattern||f.URL})}},e.URLValidator=r.__decorate([x(d.URL),r.__metadata("design:paramtypes",[String])],e.URLValidator);class Ee{constructor(e=t.Metadata.isModel){this.cache={},this.testFunction=e}register(e,t){if("function"!=typeof e)throw Error("Model registering failed. Missing Class name or constructor");t=t||e.name,this.cache[t]=e}get(e){try{return this.cache[e]}catch(e){return}}build(e={},r){if(!r&&!this.testFunction(e))throw Error("Provided obj is not a Model object");const a=r||t.Metadata.modelName(e.constructor);if(!(a in this.cache))throw Error(`Provided class ${a} is not a registered Model object`);return new this.cache[a](e)}static setBuilder(e){ye=e}static getBuilder(){return ye||Ee.fromModel}static fromModel(e,r){let a;r||(r={});const s=t.Metadata.getAttributes(e),i=Object.getPrototypeOf(e);let n;for(const o of s){try{e[o]=r[o]??e[o]??void 0}catch(e){if(n=Object.getOwnPropertyDescriptor(i,o),!n||n.writable)throw Error(`Unable to write property ${o} to model: ${e}`)}if("object"!=typeof e[o])continue;const s=t.Metadata.isPropertyModel(e,o);if(s){try{e[o]=Ee.getRegistry().build(e[o],"string"==typeof s?s:void 0)}catch(e){}continue}if(a=t.Metadata.allowedTypes(e.constructor,o),!a||!a.length)throw Error("failed to find decorators for property "+o);const c=a.map((e=>"function"!=typeof e||e.name?e:e())),u=Object.values(C);c.forEach((r=>{if(!u.includes(r))try{switch(r.name){case"Array":case"Set":{const a=t.Metadata.validationFor(e.constructor,o);if(!a||!a[d.LIST])break;const s=a[d.LIST].clazz.map((e=>"function"!=typeof e||e.name?e:e())).find((e=>!H.includes(e.name)));if("Array"===r.name&&(e[o]=e[o].map((e=>["object","function"].includes(typeof e)&&s?Ee.getRegistry().build(e,s.name):e))),"Set"===r.name){const t=new Set;for(const r of e[o])["object","function"].includes(typeof r)&&s?t.add(Ee.getRegistry().build(r,s.name)):t.add(r);e[o]=t}break}default:void 0!==e[o]&&Ee.getRegistry().get(r.name)&&(e[o]=Ee.getRegistry().build(e[o],r.name))}}catch(e){}}))}return e}static getRegistry(){return me||(me=new Ee),me}static setRegistry(e){me=e}}function Te(e,t,r){Object.hasOwnProperty.call(e,t)||(e[t]=r)}function Me(e,t){Object.hasOwnProperty.call(e,t)&&delete e[t]}function be(e,t,r,...a){t&&Te(e,m,t),Te(e,E,!!r);const s=e.hasErrors(...a);return Me(e,m),Me(e,E),s}function Ae(e,t,r,a,s,...i){let n,c=!1;for(const u of a){const a=Ee.getRegistry().get(u);if(a||(n=new o({[e]:{[d.TYPE]:"Unable to verify type consistency, missing model registry for "+u}})),t instanceof a){c=!0,n=be(t,r,s,...i);break}}return c?n:n||new o({[e]:{[d.TYPE]:"Value must be an instance of one of the expected types: "+a.join(", ")}})}function Ne(e,...t){return t?.map((t=>("string"==typeof t&&t?.startsWith(e+".")&&(t=t.replace(e+".","")),t)))}function Oe(t,r,a,s){const i=D.get(a.key);if(!i)throw Error("Missing validator for "+a.key);if(!s&&a.async)return;const n=a.key===e.ModelKeys.TYPE?[a]:a||{},o=V.create(t,{ignoreUndefined:!0,ignoreNull:!0}),c=a.key===e.ModelKeys.TYPE?n[0]:n;return j(i.hasErrors(r,c,o),s)}function _e(r,a,s,i,n,...o){const c={};for(const u in i){const l={...i[u],key:u};if(!n&&l.async)continue;let g=Oe(r,s,l,n);if(u===d.LIST&&(!g||n)){const e=s instanceof Set?[...s]:s;if(e&&e.length>0){let s=l.class||l.clazz||l.customTypes;s=(Array.isArray(s)?s:[s]).map((e=>(e="function"!=typeof e||e.name?e:e()).name?e.name:e));const i=[s].flat().map((e=>(e+"").toLowerCase())),c=e.map((e=>{if(t.Metadata.isModel(e)){const t=Ne(a,...o);return Ae(a,e,r,s.flat(),!!n,...t)}return i.includes(typeof e)?void 0:"Value has no validatable type"}));if(n)g=Promise.all(c).then((e=>e.every((e=>!e))?void 0:e));else{const e=c.every((e=>!e));g=c.length>0&&!e?c:void 0}}}const f=u===e.ModelKeys.TYPE?d.TYPE:u;g&&(c[f]=g)}if(!n)return Object.keys(c).length>0?c:void 0;const u=Object.keys(c),l=Object.values(c);return Promise.all(l).then((e=>{const t={};for(let r=0;r<e.length;r++){const a=e[r];void 0!==a&&(t[u[r]]=a)}return Object.keys(t).length>0?t:void 0}))}function Se(r,a,...s){const i=t.Metadata.validatableProperties(r.constructor,...s),n={},c={};for(const o of i){const i=o+"",u=r[o],l=t.Metadata.validationFor(r.constructor,o)||{},{designTypes:g}=t.Metadata.getPropDesignTypes(r.constructor,o);if(!g)continue;if(g.some((e=>[Array.name,Set.name].includes(e.name)))){if(!l||!Object.keys(l).includes(d.LIST)){n[i]={[d.TYPE]:`Array or Set property '${i}' requires a @list decorator`};continue}if(u&&!(Array.isArray(u)||u instanceof Set)){n[i]={[d.TYPE]:`Property '${o+""}' must be either an Array or a Set`};continue}}const f=_e(r,i,u,l,a,...s)||{};if(t.Metadata.isPropertyModel(r,i)&&null!=u){const t=g.map((e=>Ee.getRegistry().get(e.name||e))).find((e=>!!e)),n=g.map((e=>"function"==typeof e?e.name?e.name.toLowerCase():e()?.name.toLowerCase():e.toLowerCase()));if(t&&u instanceof t){const e=Ne(i,...s);c[i]=be(u,r,a,...e)}else n.includes(typeof u)||(f[d.TYPE]=t?"Value must be an instance of "+t.name:`Unable to verify type consistency, missing model registry for ${g.toString()} on prop ${i}`,delete f[e.ModelKeys.TYPE])}(Object.keys(f).length>0||a)&&(n[i]=f),a||Object.entries(c[i]||{}).forEach((([e,t])=>{void 0!==t&&(n[`${i}.${e}`]=t)}))}if(!a)return Object.keys(n).length>0?new o(n):void 0;const u=n,l=Object.keys(u),g=Object.values(u);return Promise.allSettled(g).then((async e=>{const t={};for(const[e,r]of Object.entries(c)){const a=await r;a&&Object.entries(a).forEach((([r,a])=>{void 0!==a&&(t[[e,r].join(".")]=a)}))}for(let r=0;r<e.length;r++){const a=l[r],s=e[r];"fulfilled"===s.status&&void 0!==s.value?t[a]=s.value:"rejected"===s.status&&(t[a]=s.reason instanceof Error?s.reason.message:(s.reason||"Validation failed")+"")}return Object.keys(t).length>0?new o(t):void 0}))}function Re(e){e+="";let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t.toString()}function ve(e){const t=(e,t)=>{const r=a(t);return"string"==typeof r?a((e||"")+a(t)):0|(e=((e=e||0)<<5)-e+r)},r=Re,a=e=>void 0===e?"":-1!==["string","number","symbol"].indexOf(typeof e)?r(e.toString()):e instanceof Date?r(e.getTime()):Array.isArray(e)?e.reduce(t,void 0):Object.values(e).reduce(t,void 0),s=Object.values(e).reduce(t,0);return("number"==typeof s?Math.abs(s):s).toString()}const Pe="default";class Le{static{this.current=Pe}static{this.cache={default:ve}}constructor(){}static get(e){if(e in this.cache)return this.cache[e];throw Error("No hashing method registered under "+e)}static register(e,t,r=!1){if(e in this.cache)throw Error(`Hashing method ${e} already registered`);this.cache[e]=t,r&&(this.current=e)}static hash(e,t,...r){return t?this.get(t)(e,...r):this.get(this.current)(e,...r)}static setDefault(e){this.current=this.get(e)}}class De{constructor(e=void 0){}isAsync(){return!!(this[E]??this?.constructor[E])}hasErrors(...e){return Se(this,this.isAsync(),...e)}equals(e,...t){return F(this,e,...t)}compare(e,...r){const a=t.Metadata.properties(this.constructor);if(!a||!a.length)return;const s=a.reduce(((t,a)=>{const s=a;if(r.includes(s))return t;if(void 0===this[s]&&void 0!==e[s])return t[s]={other:e[s],current:void 0},t;if(void 0!==this[s]&&void 0===e[s])return t[s]={other:void 0,current:this[s]},t;if(F(this[s],e[s]))return t;if(De.isPropertyModel(this,s)){const r=this[s].compare(e[s]);return r&&(t[s]=r),t}if(Array.isArray(this[s])&&Array.isArray(e[s])){if(this[s].length!==e[s].length)return t[s]={current:this[s],other:e[s]},t;const r=this[s].map(((t,r)=>F(t,e[s][r])?null:t instanceof De&&e[s][r]instanceof De?t.compare(e[s][r]):{current:t,other:e[s][r]}));return r.some((e=>null!==e))&&(t[s]=r),t}return t[s]={other:e[s],current:this[s]},t}),{});return Object.keys(s).length>0?s:void 0}serialize(){return De.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return De.hash(this)}static deserialize(r){let a;try{a=t.Metadata.get(this.constructor,e.ModelKeys.SERIALIZATION)}catch(e){a=void 0}return a&&a.serializer?n.deserialize(r,a.serializer,...a.args||[]):n.deserialize(r)}static fromObject(e,t){t||(t={});for(const r of De.getAttributes(e))e[r]=t[r]??e[r]??void 0;return e}static fromModel(e,t){return Ee.fromModel(e,t)}static setBuilder(e){Ee.setBuilder(e)}static getBuilder(){return Ee.getBuilder()}static getRegistry(){return Ee.getRegistry()}static setRegistry(e){Ee.setRegistry(e)}static register(e,t){return Ee.getRegistry().register(e,t)}static get(e){return Ee.getRegistry().get(e)}static build(e={},t){return De.getRegistry().build(e,t)}static getAttributes(e){return t.Metadata.getAttributes(e)}static equals(e,t,...r){return F(e,t,...r)}static hasErrors(e,t,...r){return Se(e,t,...r)}static serialize(r){let a;try{a=t.Metadata.get(r.constructor,e.ModelKeys.SERIALIZATION)}catch(e){a=void 0}return a&&a.serializer?n.serialize(this,a.serializer,...a.args||[]):n.serialize(r)}static hash(r){const a=t.Metadata.get(r.constructor,e.ModelKeys.HASHING);return a&&a.algorithm?Le.hash(r,a.algorithm,...a.args||[]):Le.hash(r)}static isModel(e){return t.Metadata.isModel(e)}static isPropertyModel(e,r){return t.Metadata.isPropertyModel(e,r)}static describe(e,r){return t.Metadata.description(e,r)}}t.Metadata.validationFor=((e,r,a)=>{const s=t.Metadata.get(e);if(!s)return;if(!r)return s.validation;if(!s.validation)return;if(!s.validation[d.TYPE]){const{designTypes:a}=t.Metadata.getPropDesignTypes(e,r);s.validation[r]&&a?.length&&a[0]!==C.OBJECT&&(s.validation[r][d.TYPE]={customTypes:a,message:g.TYPE,description:"defines the accepted types for the attribute",async:!1})}if(!a)return s.validation[r];const i=s.validation[r];return i?i[a]:void 0}).bind(t.Metadata),t.Metadata.modelName=(e=>{const r=t.Metadata.constr(e);return r?r.name:e.name}).bind(t.Metadata),t.Metadata.validatableProperties=((e,...r)=>{const a=t.Metadata.validationFor(e),s=a?Object.keys(a):[];return[...new Set([...De.getAttributes(e),...s])].filter((e=>!r||!r?.includes(e)))}).bind(t.Metadata),t.Metadata.allowedTypes=((e,r)=>{const a=t.Metadata.type(e,r);if(!a)throw Error("No metadata found for property "+r);const s=t.Metadata.validationFor(e,r);return s&&s[d.TYPE]&&"function"==typeof s[d.TYPE]?.customTypes[Symbol.iterator]?[...s[d.TYPE].customTypes]:[a]}).bind(t.Metadata),t.Metadata.getPropDesignTypes=((e,r)=>{const a=t.Metadata.get(e),s=t.Metadata.type(e,r),i=a?.[d.REFLECT]?.[r];if(!(s||i&&i[d.TYPE]))return{};const n=i&&i[d.TYPE]?[i[d.TYPE].customTypes]:[s];if(!n?.length)return{};const o=n[0],c=o.class||o.clazz||o.customTypes||o;return{designTypes:(Array.isArray(c)?c:[c]).map((e=>"function"!=typeof e||e.name?e:e())),designType:c}}).bind(t.Metadata),t.Metadata.isModel=(e=>{try{if(e instanceof De)return!0;const r=t.Metadata.constr(e);return!(!r||r===e||!t.Metadata.modelName(r))}catch(e){return!1}}).bind(t.Metadata),t.Metadata.isPropertyModel=((e,r)=>{if(t.Metadata.isModel(e[r]))return!0;const a=t.Metadata.type(e.constructor,r);return a&&Ee.getRegistry().get(a.name)?a.name:void 0}).bind(t.Metadata),t.Metadata.getAttributes=(e=>{const r=e instanceof De?e.constructor:e,a=new Set,s=e=>{if(!e)return[];const r=s(Object.getPrototypeOf(e)),i=t.Metadata.properties(e)??[];for(const e of i)a.has(e)||(a.add(e),r.push(e));return r};return s(r)}).bind(t.Metadata);class we{constructor(){}preSerialize(r,...a){const s=Object.assign({},r);let i;try{i=t.Metadata.modelName(r.constructor)}catch(e){i=void 0}return s[e.ModelKeys.ANCHOR]=i||r.constructor.name,s}deserialize(t,...r){const a=JSON.parse(t),s=a[e.ModelKeys.ANCHOR];if(!s)throw Error("Could not find class reference in serialized model");return De.build(a,s)}serialize(e,...t){return JSON.stringify(this.preSerialize(e))}}function Ie(e,...t){const r=(...t)=>new e(...t);return r.prototype=e.prototype,r(...t)}function Ve(e){if(e instanceof De)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,De.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,De.prototype)}throw Error("Could not find proper prototype to bind")}function je(r){const a=(...e)=>{const t=Ie(r,...e);Ve(t);const a=De.getBuilder();return a&&a(t,e.length?e[0]:void 0),t};return a.prototype=r.prototype,Object.defineProperty(a,"name",{writable:!1,enumerable:!0,configurable:!1,value:r.prototype.constructor.name}),t.metadata(e.ModelKeys.CONSTRUCTOR,r)(a),De.register(a,r.name),a}function Ue(){const r=e.ModelKeys.MODEL;return t.Decoration.for(r).define(je).apply()}n.cache={json:new we};class Ce{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=Ce.asMeta(e),r="string"==typeof e?e:Ce.resolveMessage(t);return this.decorate(X(r))}min(e,t){const r=Ce.asMeta(e),a=r?.[d.MIN]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${d.MIN} for ${this.attr+""}`);return this.decorate(W(a,Ce.resolveMessage(r,t)))}max(e,t){const r=Ce.asMeta(e),a=r?.[d.MAX]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${d.MAX} for ${this.attr+""}`);return this.decorate(Z(a,Ce.resolveMessage(r,t)))}step(e,t){const r=Ce.asMeta(e),a=r?.[d.STEP]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${d.STEP} for ${this.attr+""}`);return this.decorate(J(a,Ce.resolveMessage(r,t)))}minlength(e,t){const r=Ce.asMeta(e),a=r?.[d.MIN_LENGTH]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${d.MIN_LENGTH} for ${this.attr+""}`);return this.decorate(ee(a,Ce.resolveMessage(r,t)))}maxlength(e,t){const r=Ce.asMeta(e),a=r?.[d.MAX_LENGTH]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${d.MAX_LENGTH} for ${this.attr+""}`);return this.decorate(te(a,Ce.resolveMessage(r,t)))}pattern(e,t){const r=Ce.asMeta(e),a=r?.[d.PATTERN]??(r?void 0:e),s=Ce.patternFromString(a)??/.*/;return this.decorate(re(s,Ce.resolveMessage(r,t)))}email(e){const t=Ce.asMeta(e),r="string"==typeof e?e:Ce.resolveMessage(t);return this.decorate(ae(r))}url(e){const t=Ce.asMeta(e),r="string"==typeof e?e:Ce.resolveMessage(t);return this.decorate(se(r))}type(e,t){const r=Ce.asMeta(e),a=r?.customTypes??r?.type??(r?void 0:e);return this.decorate(ie(a,Ce.resolveMessage(r,t)))}date(e,t){const r=Ce.asMeta(e),a=r?.[d.FORMAT]??(r?void 0:e);return this.decorate(ne(a,Ce.resolveMessage(r,t)))}password(e,t){const r=Ce.asMeta(e),a=r?.[d.PATTERN]??(r?void 0:e),s=Ce.patternFromString(a);return this.decorate(oe(s,Ce.resolveMessage(r,t)))}list(e,t,r){const a=Ce.asMeta(e),s=a?.clazz??(a?void 0:e),i=a?.type??t;return this.decorate(ce(s,i,Ce.resolveMessage(a,r)))}set(e,t){return Ce.isMetadataPayload(e)?this.list(e):this.list(e,"Set",t)}enum(e,t){const r=Ce.asMeta(e),a=r?.[d.ENUM]??(r?void 0:e);return this.decorate(pe(a,Ce.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 Ce.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 a=Ce.asMeta(e);return a?{target:a[t],options:{label:a.label,message:a.message}}:{target:e,options:r}}equals(e,t){const{target:r,options:a}=this.resolveComparison(e,d.EQUALS,t);return this.decorate(de(r,a))}eq(e,t){return this.equals(e,t)}different(e,t){const{target:r,options:a}=this.resolveComparison(e,d.DIFF,t);return this.decorate(ue(r,a))}diff(e,t){return this.different(e,t)}lessThan(e,t){const{target:r,options:a}=this.resolveComparison(e,d.LESS_THAN,t);return this.decorate(le(r,a))}lt(e,t){return this.lessThan(e,t)}lessThanOrEqual(e,t){const{target:r,options:a}=this.resolveComparison(e,d.LESS_THAN_OR_EQUAL,t);return this.decorate(ge(r,a))}lte(e,t){return this.lessThanOrEqual(e,t)}greaterThan(e,t){const{target:r,options:a}=this.resolveComparison(e,d.GREATER_THAN,t);return this.decorate(fe(r,a))}gt(e,t){return this.greaterThan(e,t)}greaterThanOrEqual(e,t){const{target:r,options:a}=this.resolveComparison(e,d.GREATER_THAN_OR_EQUAL,t);return this.decorate(he(r,a))}gte(e,t){return this.greaterThanOrEqual(e,t)}description(e){return this.decorate(t.description(e))}build(e){const r=e.prototype,a=this.attr;Object.getOwnPropertyDescriptor(r,a)||Object.defineProperty(r,a,{configurable:!0,enumerable:!0,writable:!0,value:void 0}),this.declaredType&&Reflect.defineMetadata(t.DecorationKeys.DESIGN_TYPE,this.declaredType,r,a),t.prop()(r,a),this.decorators.forEach((e=>{try{e(r,a)}catch(e){throw Error(`Failed to apply decorator to property "${this.attr}": ${e}`)}}))}}class He{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=xe.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,a)=>(r=Reflect.apply(e,t,a),this.parent)}),e}}class xe extends a.ObjectAccumulator{constructor(){super(...arguments),this.attributes=new Map}setName(e){return this._name=e,this}description(e){return this._description=e,this}attribute(e,t){const r=this.attributes.get(e);if(r){if(r.declaredType!==t)throw Error(`Attribute "${e+""}" already exists with a different type`);return r}const a=new Ce(this,e,t);return this.attributes.set(e,a),a}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 xe;return t.build=new Proxy(t.build,{apply:(t,r,a)=>{const s=Reflect.apply(t,r,a);return this.instance(s,e)}}),t}listOf(e,t="Array"){const r="Set"===t?Set:Array,a=this.attribute(e,r);return new He(this,a,t)}build(){if(!this._name)throw Error("name is required");const e=this._parent??De;class r extends e{constructor(e){super(e)}}Object.defineProperty(r,"name",{value:this._name,writable:!1});for(const e of this.attributes.values())e.build(r);let a=Ue()(r);return this._description&&(a=t.description(this._description)(a)),a}static builder(){return new xe}static from(e,t){if(!e)throw Error("metadata is required");const r=xe.builder(),a=t??"GeneratedModel"+Date.now();r.setName(a);const s=e.properties||{},i=e.validation||{};for(const[e,t]of Object.entries(s)){const a=r.attribute(e,t||Object),s=i[e];if(s)for(const[e,t]of Object.entries(s)){const r=a[e];if("function"!=typeof r)try{const r=D.decoratorFromKey(e),s="function"==typeof r?r(t):r;a.decorate(s)}catch{}else r.call(a,t)}}return r.build()}}const Fe="##VERSION##",ze="##PACKAGE##";t.Metadata.registerLibrary(ze,Fe),e.ASYNC_META_KEY=E,e.AsyncValidator=class extends v{constructor(e=g.DEFAULT,...t){super(!0,e,...t)}},e.AttributeBuilder=Ce,e.COMPARISON_ERROR_MESSAGES=y,e.ComparisonValidationKeys=c,e.DAYS_OF_WEEK_NAMES=l,e.DEFAULT_ERROR_MESSAGES=g,e.DEFAULT_PATTERNS=f,e.DefaultHashingMethod=Pe,e.DefaultSerializationMethod=i,e.Hashing=Le,e.JSONSerializer=we,e.MONTH_NAMES=u,e.Model=De,e.ModelBuilder=xe,e.ModelErrorDefinition=o,e.ModelRegistryManager=Ee,e.PACKAGE_NAME=ze,e.PathProxyEngine=V,e.ReservedModels=C,e.Serialization=n,e.VALIDATION_PARENT_KEY=m,e.VERSION=Fe,e.Validation=D,e.ValidationKeys=d,e.Validator=P,e.ValidatorRegistry=L,e.async=()=>e=>{Object.prototype.hasOwnProperty.call(e,E)||(e[E]=!0)},e.bindDateToString=$,e.bindModelPrototype=Ve,e.bulkModelRegister=(...e)=>{e.forEach((e=>{const t=e.constructor?e.constructor:e;Ee.getRegistry().register(t,e.name)}))},e.checkType=O,e.checkTypes=_,e.construct=Ie,e.date=ne,e.dateFromFormat=G,e.diff=ue,e.email=ae,e.eq=de,e.evaluateDesignTypes=S,e.findLastProtoBeforeObject=e=>{let t=Object.getPrototypeOf(e);if(t===Object.prototype)return e;for(;t!==Object.prototype;){if(t=Object.getPrototypeOf(t),t===Object.prototype)return t;if(Object.getPrototypeOf(t)===Object.prototype)return t}throw Error("Could not find proper prototype")},e.formatDate=K,e.getChildNestedPropsToIgnore=Ne,e.gt=fe,e.gte=he,e.hashCode=Re,e.hashObj=ve,e.hashedBy=(r,...a)=>t.metadata(e.ModelKeys.HASHING,{algorithm:r,args:a}),e.innerValidationDecorator=B,e.isEqual=F,e.isGreaterThan=N,e.isLessThan=A,e.isValidDate=Y,e.isValidForGteOrLteComparison=b,e.jsTypes=H,e.list=ce,e.lt=le,e.lte=ge,e.max=Z,e.maxlength=te,e.min=W,e.minlength=ee,e.model=Ue,e.modelBaseDecorator=je,e.option=pe,e.parseDate=k,e.password=oe,e.pattern=re,e.regexpParser=z,e.required=X,e.serializedBy=(r,...a)=>t.metadata(e.ModelKeys.SERIALIZATION,{serializer:r,args:a}),e.set=(e,t=g.LIST)=>ce(e,"Set",t),e.sf=p,e.step=J,e.stringFormat=h,e.toConditionalPromise=j,e.twoDigitPad=q,e.type=ie,e.url=se,e.validate=Se,e.validateChildValue=Ae,e.validateDecorator=Oe,e.validateDecorators=_e,e.validationMetadata=Q,e.validator=x,e.valueLength=R},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@decaf-ts/decoration"),require("tslib"),require("typed-object-accumulator")):"function"==typeof define&&define.amd?define(["exports","@decaf-ts/decoration","tslib","typed-object-accumulator"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["decorator-validation"]={},e.decafTsDecoration,e.tslib,e.typedObjectAccumulator);
|
|
1
|
+
var e,t;e=this,t=function(e,t,r,a){"use strict";var s;e.ModelKeys=void 0,(s=e.ModelKeys||(e.ModelKeys={})).DESCRIPTION="description",s.TYPE="design:type",s.MODEL="model",s.ANCHOR="__model",s.CONSTRUCTION="constructed-by",s.ATTRIBUTE="__attributes",s.HASHING="hashing",s.SERIALIZATION="serialization",s.DECORATORS="decorators",s.CONSTRUCTOR="__original";const i="json";class n{static{this.current=i}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 o{constructor(e){for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&Object.defineProperty(this,t,{enumerable:!0,configurable:!1,value:e[t],writable:!1})}toString(){const e=this;return Object.keys(e).filter((t=>Object.prototype.hasOwnProperty.call(e,t)&&"function"!=typeof e[t])).reduce(((t,r)=>{let a=Object.keys(e[r]).reduce(((t,a)=>(t?t+="\n"+e[r][a]:t=e[r][a],t)),void 0);return a&&(a=`${r} - ${a}`,t?t+="\n"+a:t=a),t}),"")}}const c={EQUALS:"equals",DIFF:"different",LESS_THAN:"lessThan",LESS_THAN_OR_EQUAL:"lessThanOrEqual",GREATER_THAN:"greaterThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual"},u={REFLECT:"validation",DATE:"date",EMAIL:"email",FORMAT:"format",LIST:"list",MAX:"max",MAX_LENGTH:"maxlength",MIN:"min",MIN_LENGTH:"minlength",PASSWORD:"password",PATTERN:"pattern",REQUIRED:"required",STEP:"step",TYPE:"type",UNIQUE:"unique",URL:"url",VALIDATOR:"validator",ENUM:"enum",...c},d=["January","February","March","April","May","June","July","August","September","October","November","December"],l=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],h={REQUIRED:"This field is required",MIN:"The minimum value is {0}",MAX:"The maximum value is {0}",MIN_LENGTH:"The minimum length is {0}",MAX_LENGTH:"The maximum length is {0}",PATTERN:"The value does not match the pattern",EMAIL:"The value is not a valid email",URL:"The value is not a valid URL",TYPE:"Invalid type. Expected {0}, received {1}",STEP:"Invalid value. Not a step of {0}",DATE:"Invalid value. not a valid Date",DEFAULT:"There is an Error",PASSWORD:"Must be at least 8 characters and contain one of number, lower and upper case letters, and special character (@$!%*?&_-.,)",LIST:"Invalid list of {0}",MODEL_NOT_FOUND:"No model registered under {0}",EQUALS:"This field must be equal to field {0}",DIFF:"This field must be different from field {0}",LESS_THAN:"This field must be less than field {0}",LESS_THAN_OR_EQUAL:"This field must be less than or equal to field {0}",GREATER_THAN:"This field must be greater than field {0}",GREATER_THAN_OR_EQUAL:"This field must be greater than or equal to field {0}",UNIQUE:"Duplicate found, this field must be unique.",ENUM:"Value is not allowed. Must be one of {0}"},f={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 g(e,...t){return e.replace(/{(\d+)}/g,((e,r)=>void 0!==t[r]?t[r].toString():"undefined"))}const p=g,y={INVALID_PATH:"Invalid path argument. Expected non-empty string but received: '{0}'",CONTEXT_NOT_OBJECT_COMPARISON:"Unable to access parent at level {0} for path '{1}': current context is not an object",PROPERTY_INVALID:"Failed to resolve path {0}: property '{1}' is invalid or does not exist.",PROPERTY_NOT_EXIST:"Failed to resolve path: property '{0}' does not exist.",UNSUPPORTED_TYPES_COMPARISON:"Unsupported types for comparison: '{0}' and '{1}'",NULL_OR_UNDEFINED_COMPARISON:"Comparison failed due to null or undefined value",INVALID_DATE_COMPARISON:"Invalid Date objects are not comparable",TYPE_MISMATCH_COMPARISON:"Cannot compare values of different types: {0} and {1}.",NAN_COMPARISON:"Comparison not supported for NaN values"},m=Symbol("_parent"),E=Symbol("isAsync"),M=e=>null===e?"null":e instanceof Date?"Date":Number.isNaN(e)?"NaN":e===1/0?"Infinity":e===-1/0?"-Infinity":Array.isArray(e)?"array":typeof e,T=e=>void 0===e||e instanceof Date||"bigint"==typeof e||"number"==typeof e&&Number.isFinite(e);function b(e,t){if(T(e)&&T(t))return!0;throw new TypeError(p(y.UNSUPPORTED_TYPES_COMPARISON,M(e),M(t)))}function A(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(y.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,a=typeof t;if(r!==a){if("bigint"===r&&"number"===a)return t>Number(e);if("number"===r&&"bigint"===a)return Number(t)>e;throw new TypeError(p(y.TYPE_MISMATCH_COMPARISON,r,a))}if("number"===r&&"number"===a||"bigint"===r&&"bigint"===a){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(y.NAN_COMPARISON);return t>e}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(y.INVALID_DATE_COMPARISON);return e.getTime()<t.getTime()}throw new TypeError(p(y.UNSUPPORTED_TYPES_COMPARISON,M(e),M(t)))}function N(e,t){if([null,void 0].includes(e)||[null,void 0].includes(t))throw Error(y.NULL_OR_UNDEFINED_COMPARISON);const r=typeof e,a=typeof t;if(r!==a){if("bigint"===r&&"number"===a)return Number(e)>t;if("number"===r&&"bigint"===a)return e>Number(t);throw Error(p(y.TYPE_MISMATCH_COMPARISON,r,a))}if("number"===r&&"number"===a||"bigint"===r&&"bigint"===a){if(Number.isNaN(e)||Number.isNaN(t))throw new TypeError(y.NAN_COMPARISON);return e>t}if(e instanceof Date&&t instanceof Date){if(isNaN(e.getTime())||isNaN(t.getTime()))throw new TypeError(y.INVALID_DATE_COMPARISON);return e.getTime()>t.getTime()}throw new TypeError(p(y.UNSUPPORTED_TYPES_COMPARISON,M(e),M(t)))}function S(e,t){return typeof e===t.toLowerCase()||void 0!==e&&"object"==typeof e&&e.constructor&&e.constructor.name.toLowerCase()===t.toLowerCase()}function O(e,t){return!t.every((t=>!S(e,t)))}function _(e,t){switch(typeof t){case"string":return S(e,t);case"object":return!Array.isArray(t)||O(e,t);case"function":return!t.name||"Object"===t.name||S(e,t.name);default:return!0}}function R(e){return e instanceof Set||e instanceof Map?e.size:e.length}class v{constructor(e,t=h.DEFAULT,...r){this.async=e,this.message=t,r.length&&(this.acceptedTypes=r),this.acceptedTypes&&(this.hasErrors=this.checkTypeAndHasErrors(this.hasErrors.bind(this)))}getMessage(e,...t){return p(e,...t)}checkTypeAndHasErrors(e){return function(t,r,a,...s){return void 0!==t&&this.acceptedTypes?O(t,this.acceptedTypes)?e(t,r,a,...s):this.getMessage(h.TYPE,this.acceptedTypes.join(", "),"number"!=typeof t?typeof t:isNaN(t)?"NaN":typeof t):e(t,r,a,...s)}.bind(this)}static isValidator(e){return e.constructor&&!!e.hasErrors}}class P extends v{constructor(e=h.DEFAULT,...t){super(!1,e,...t)}}class D{constructor(...e){this.cache={},this.customKeyCache={},this.register(...e)}getCustomKeys(){return Object.assign({},this.customKeyCache)}getKeys(){return Object.keys(this.cache)}get(e){if(!(e in this.cache))return;const t=this.cache[e];if(P.isValidator(t))return t;const r=new(t.default||t);return this.cache[e]=r,r}register(...e){e.forEach((e=>{if(P.isValidator(e)){if(e.validationKey in this.cache)return;this.cache[e.validationKey]=e}else{const{validationKey:t,validator:r,save:a}=e;if(t in this.cache)return;if(this.cache[t]=r,!a)return;const s={};s[t.toUpperCase()]=t,this.customKeyCache=Object.assign({},this.customKeyCache,s)}}))}}class L{static{this.actingValidatorRegistry=void 0}constructor(){}static setRegistry(e,t){t&&L.actingValidatorRegistry&&L.actingValidatorRegistry.getKeys().forEach((r=>{const a=e.get(r);a&&e.register(t(a))})),L.actingValidatorRegistry=e}static getRegistry(){return L.actingValidatorRegistry||(L.actingValidatorRegistry=new D),L.actingValidatorRegistry}static get(e){return L.getRegistry().get(e)}static register(...e){return L.getRegistry().register(...e)}static key(e){return u.REFLECT+e}static keys(){return this.getRegistry().getKeys()}static registerDecorator(r,a){const s=t.Metadata.innerGet(Symbol.for(e.ModelKeys.DECORATORS),t.Metadata.key(u.REFLECT,r));s?.[r]||t.Metadata.set(e.ModelKeys.DECORATORS,t.Metadata.key(u.REFLECT,r),a)}static decoratorFromKey(r){try{return t.Metadata.innerGet(Symbol.for(e.ModelKeys.DECORATORS),t.Metadata.key(u.REFLECT,r))}catch(e){throw Error(`No decorator registered under ${r}: ${e}`)}}}const w=e=>e[m],I=(e,t)=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw Error(p(y.PROPERTY_NOT_EXIST,t));return e[t]};class V{static create(e,t){const{getValue:r,getParent:a,ignoreUndefined:s,ignoreNull:i}={getParent:w,getValue:I,ignoreNull:!1,ignoreUndefined:!1,...t};return new Proxy({},{get:(t,n)=>"getValueFromPath"===n?t=>{const n=V.parsePath(t);let o=e;for(let e=0;e<n.length;e++){const c=n[e];if(".."!==c){if(o=r(o,c),!s&&void 0===o)throw Error(p(y.PROPERTY_INVALID,t,c));if(!i&&null===o)throw Error(p(y.PROPERTY_INVALID,t,c))}else{const r=a(o);if(!r||"object"!=typeof r)throw Error(p(y.CONTEXT_NOT_OBJECT_COMPARISON,e+1,t));o=r}}return o}:t[n]})}static parsePath(e){if("string"!=typeof e||!e.trim())throw Error(p(y.INVALID_PATH,e));return e.match(/(\.\.|[^/.]+)/g)||[]}}function j(e,t){return t?Promise.resolve(e):e}var H;e.Primitives=void 0,(H=e.Primitives||(e.Primitives={})).STRING="string",H.NUMBER="number",H.BOOLEAN="boolean",H.BIGINT="bigint";const U={STRING:String,OBJECT:Object,NUMBER:Number,BOOLEAN:Boolean,BIGINT:BigInt,DATE:Date},C=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"];function x(...e){return t.apply((t=>(e.forEach((e=>{L.register({validator:t,validationKey:e,save:!0})})),t)),t.metadata(u.VALIDATOR,e))}function F(e,t,...r){if(e===t)return 0!==e||1/e==1/t;if(null==e||null==t)return e===t;if(typeof e!=typeof t)return!1;if(Number.isNaN(e)&&Number.isNaN(t))return!0;if("object"!=typeof e)return e===t;if(e instanceof Date&&t instanceof Date)return!(!isNaN(e.getTime())||!isNaN(t.getTime()))||e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(e instanceof Error&&t instanceof Error)return e.name===t.name&&e.message===t.message;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(!F(e[a],t[a],...r))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[a,s]of e)if(!t.has(a)||!F(s,t.get(a),...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),a=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<r.length;e++)if(r[e]!==a[e])return!1;return!0}const a=Object.keys(e).filter((e=>!r.includes(e))),s=Object.keys(t).filter((e=>!r.includes(e)));if(a.length!==s.length)return!1;for(const i of a){if(!s.includes(i))return!1;if(!F(e[i],t[i],...r))return!1}const i=Object.getOwnPropertySymbols(e).filter((e=>!r.includes(e.toString()))),n=Object.getOwnPropertySymbols(t).filter((e=>!r.includes(e.toString())));if(i.length!==n.length)return!1;for(const a of i){if(!n.includes(a))return!1;if(!F(e[a],t[a],...r))return!1}return Object.getPrototypeOf(e)===Object.getPrototypeOf(t)}e.DateValidator=class extends P{constructor(e=h.DATE){super(e,Number.name,Date.name,String.name)}hasErrors(e,t={}){if(void 0!==e&&("string"==typeof e&&(e=new Date(e)),Number.isNaN(e.getDate()))){const{message:e=""}=t;return this.getMessage(e||this.message)}}},e.DateValidator=r.__decorate([x(u.DATE),r.__metadata("design:paramtypes",[String])],e.DateValidator),e.DiffValidator=class extends P{constructor(e=h.DIFF){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.DIFF])}catch(e){return this.getMessage(e.message||this.message)}return F(e,a)?this.getMessage(t.message||this.message,t.label||t[u.DIFF]):void 0}},e.DiffValidator=r.__decorate([x(u.DIFF),r.__metadata("design:paramtypes",[String])],e.DiffValidator);const z=RegExp("^/(.+)/([gimus]*)$");function G(e,t){let r=t;r.match(/hh/)?r=r.replace("hh","(?<hour>\\d{2})"):r.match(/h/)?r=r.replace("h","(?<hour>\\d{1,2})"):r.match(/HH/)?r=r.replace("HH","(?<hour>\\d{2})"):r.match(/H/)&&(r=r.replace("H","(?<hour>\\d{1,2})")),r.match(/mm/)?r=r.replace("mm","(?<minutes>\\d{2})"):r.match(/m/)&&(r=r.replace("m","(?<minutes>\\d{1,2})")),r.match(/ss/)?r=r.replace("ss","(?<seconds>\\d{2})"):r.match(/s/)&&(r=r.replace("s","(?<seconds>\\d{1,2})")),r.match(/dd/)?r=r.replace("dd","(?<day>\\d{2})"):r.match(/d/)&&(r=r.replace("d","(?<day>\\d{1,2})")),r.match(/EEEE/)?r=r.replace("EEEE","(?<dayofweek>\\w+)"):r.match(/EEEE/)&&(r=r.replace("EEE","(?<dayofweek>\\w+)")),r.match(/yyyy/)?r=r.replace("yyyy","(?<year>\\d{4})"):r.match(/yy/)&&(r=r.replace("yy","(?<year>\\d{2})")),r.match(/MMMM/)?r=r.replace("MMMM","(?<monthname>\\w+)"):r.match(/MMM/)&&(r=r.replace("MMM","(?<monthnamesmall>\\w+)")),r.match(/MM/)?r=r.replace("MM","(?<month>\\d{2})"):r.match(/M/)&&(r=r.replace("M","(?<month>\\d{1,2})")),r=r.replace("S","(?<milis>\\d{1,3})").replace("aaa","(?<ampm>\\w{2})");const a=RegExp(r,"g").exec(e);if(!a||!a.groups)return new Date(e);const s=e=>{if(!e)return 0;const t=parseInt(e);return isNaN(t)?0:t},i=s(a.groups.year),n=s(a.groups.day),o=a.groups.ampm;let c=s(a.groups.hour);o&&(c="PM"===o?c+12:c);const u=s(a.groups.minutes),l=s(a.groups.seconds),h=s(a.groups.milis),f=a.groups.monthname,g=a.groups.monthnamesmall;let p=a.groups.month;if(f)p=d.indexOf(f);else if(g){const t=d.find((e=>e.toLowerCase().startsWith(g.toLowerCase())));if(!t)return new Date(e);p=d.indexOf(t)}else p=s(""+p);return new Date(i,p-1,n,c,u,l,h)}function Y(e,t){if(e)return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>K(r,t)})}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:new Proxy(e.toISOString,{apply:(e,r)=>K(r,t)})}),e}function $(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function q(e){return 10>e?"0"+e:e.toString()}function K(e,t="yyyy/MM/dd"){const r=e.getDate(),a=e.getMonth(),s=e.getFullYear(),i=e.getHours(),n=e.getMinutes(),o=e.getSeconds(),c=e.getMilliseconds(),u=i%12,h=q(u),f=q(i),g=q(n),p=q(o),y=12>i?"AM":"PM",m=l[e.getDay()],E=m.substr(0,3),M=q(r),T=a+1,b=q(T),A=d[a],N=A.substr(0,3),S=s+"",O=S.substr(2,2);return(t=t.replace("hh",h).replace("h",u.toString()).replace("HH",f).replace("H",i.toString()).replace("mm",g).replace("m",n.toString()).replace("ss",p).replace("s",o.toString()).replace("S",c.toString()).replace("dd",M).replace("d",r.toString()).replace("EEEE",m).replace("EEE",E).replace("yyyy",S).replace("yy",O).replace("aaa",y)).indexOf("MMM")>-1?t.replace("MMMM",A).replace("MMM",N):t.replace("MM",b).replace("M",T.toString())}function k(e,t){let r;if(t){if(t instanceof Date)try{r=G(K(t,e),e)}catch(r){throw Error(p("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=G(t,e);else if("number"==typeof t)r=G(K(new Date(t),e),e);else{if(!$(t))throw Error("Invalid value provided "+t);try{r=G(K(new Date(t),e),e)}catch(r){throw Error(p("Could not convert date {0} to format: {1}",t,e))}}return Y(r,e)}}function Q(e,r,a){return t.apply(t.propMetadata(r,a))}function B(e,t,r){return L.registerDecorator(t,e),(e,a)=>Q(0,`${u.REFLECT}.${a}.${t}`,r)(e,a)}function X(e=h.REQUIRED){const r=u.REQUIRED,a={message:e,description:"defines the attribute as required",async:!1};return t.Decoration.for(r).define({decorator:B,args:[X,r,a]}).apply()}function W(e,r=h.MIN){const a=u.MIN,s={[u.MIN]:e,message:r,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[W,a,s]}).apply()}function Z(e,r=h.MAX){const a=u.MAX,s={[u.MAX]:e,message:r,description:`defines the max value of the attribute as ${e} (applies to numbers or Dates)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[Z,a,s]}).apply()}function J(e,r=h.STEP){const a=u.STEP,s={[u.STEP]:e,message:r,description:"defines the step of the attribute as "+e,async:!1};return t.Decoration.for(a).define({decorator:B,args:[J,a,s]}).apply()}function ee(e,r=h.MIN_LENGTH){const a=u.MIN_LENGTH,s={[u.MIN_LENGTH]:e,message:r,description:`defines the min length of the attribute as ${e} (applies to strings or lists)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[ee,a,s]}).apply()}function te(e,r=h.MAX_LENGTH){const a=u.MAX_LENGTH,s={[u.MAX_LENGTH]:e,message:r,description:`defines the max length of the attribute as ${e} (applies to strings or lists)`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[te,a,s]}).apply()}function re(e,r=h.PATTERN){const a=u.PATTERN,s={[u.PATTERN]:"string"==typeof e?e:e.toString(),message:r,description:`assigns the ${"string"===e?e:e.toString()} pattern to the attribute`,async:!1};return t.Decoration.for(a).define({decorator:B,args:[re,a,s]}).apply()}function ae(e=h.EMAIL){const r=u.EMAIL,a={[u.PATTERN]:f.EMAIL.toString(),message:e,description:"marks the attribute as an email",async:!1};return t.Decoration.for(r).define({decorator:B,args:[ae,r,a]}).apply()}function se(e=h.URL){const r=u.URL,a={[u.PATTERN]:f.URL.toString(),message:e,description:"marks the attribute as an url",async:!1};return t.Decoration.for(r).define({decorator:B,args:[se,r,a]}).apply()}function ie(e,r=h.TYPE){const a=u.TYPE,s={customTypes:e,message:r,description:"defines the accepted types for the attribute",async:!1};return t.Decoration.for(a).define({decorator:B,args:[ie,a,s]}).apply()}function ne(e="dd/MM/yyyy",r=h.DATE){const a=u.DATE;return t.Decoration.for(a).define({decorator:function(e,t){const r={[u.FORMAT]:e,message:t,description:"defines the attribute as a date with the format "+e,async:!1};return function(t,s){const i=new WeakMap;return Object.defineProperty(t,s,{configurable:!0,set(t){const r=Object.getOwnPropertyDescriptor(this,s);r&&!r.configurable||Object.defineProperty(this,s,{enumerable:!0,configurable:!1,get:()=>i.get(this),set:t=>{let r;try{r=k(e,t),i.set(this,r)}catch(e){}}}),this[s]=t},get(){return i.get(this)}}),B(ne,a,r)(t,s)}},args:[e,r]}).apply()}function oe(e=f.PASSWORD.CHAR8_ONE_OF_EACH,r=h.PASSWORD){const a=u.PASSWORD,s={[u.PATTERN]:e.toString(),message:r,description:"attribute as a password",async:!1};return t.Decoration.for(a).define({decorator:B,args:[oe,a,s]}).apply()}function ce(e,r="Array",a=h.LIST){const s=u.LIST,i={clazz:Array.isArray(e)?e:[e],type:r,message:a,async:!1,description:`defines the attribute as a ${r} of ${e.name}`};return t.Decoration.for(s).define({decorator:B,args:[ce,s,i]}).apply()}function ue(e,t){return B(ue,u.EQUALS,{label:t?.label||e,message:t?.message||h.EQUALS,[u.EQUALS]:e,description:"defines attribute as equal to "+e,async:!1})}function de(e,t){return B(de,u.DIFF,{label:t?.label||e,message:t?.message||h.DIFF,[u.DIFF]:e,description:"defines attribute as different to "+e,async:!1})}function le(e,t){return B(le,u.LESS_THAN,{label:t?.label||e,message:t?.message||h.LESS_THAN,[u.LESS_THAN]:e,description:"defines attribute as less than to "+e,async:!1})}function he(e,t){return B(he,u.LESS_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||h.LESS_THAN_OR_EQUAL,[u.LESS_THAN_OR_EQUAL]:e,description:"defines attribute as less or equal to "+e,async:!1})}function fe(e,t){return B(fe,u.GREATER_THAN,{label:t?.label||e,message:t?.message||h.GREATER_THAN,[u.GREATER_THAN]:e,description:"defines attribute as greater than "+e,async:!1})}function ge(e,t){return B(ge,u.GREATER_THAN_OR_EQUAL,{label:t?.label||e,message:t?.message||h.GREATER_THAN_OR_EQUAL,[u.GREATER_THAN_OR_EQUAL]:e,description:"defines attribute as greater or equal to "+e,async:!1})}function pe(e,r=h.ENUM){const a=u.ENUM,s={[u.ENUM]:e,message:r,description:"defines a list or an object of accepted values for the attribute",async:!1};return t.Decoration.for(a).define({decorator:B,args:[pe,a,s]}).apply()}let ye,me;e.PatternValidator=class extends P{constructor(e=h.PATTERN){super(e,"string")}getPattern(e){if(!z.test(e))return RegExp(e);const t=e.match(z);return RegExp(t[1],t[2])}hasErrors(e,t){if(!e)return;let{pattern:r}=t;if(!r)throw Error("Missing Pattern");return r="string"==typeof r?this.getPattern(r):r,r.lastIndex=0,r.test(e)?void 0:this.getMessage(t.message||this.message)}},e.PatternValidator=r.__decorate([x(u.PATTERN),r.__metadata("design:paramtypes",[String])],e.PatternValidator),e.EmailValidator=class extends e.PatternValidator{constructor(e=h.EMAIL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t?.pattern||f.EMAIL})}},e.EmailValidator=r.__decorate([x(u.EMAIL),r.__metadata("design:paramtypes",[String])],e.EmailValidator),e.EqualsValidator=class extends P{constructor(e=h.EQUALS){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.EQUALS])}catch(e){return this.getMessage(e.message||this.message)}return F(e,a)?void 0:this.getMessage(t.message||this.message,t.label||t[u.EQUALS])}},e.EqualsValidator=r.__decorate([x(u.EQUALS),r.__metadata("design:paramtypes",[String])],e.EqualsValidator),e.GreaterThanValidator=class extends P{constructor(e=h.GREATER_THAN){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.GREATER_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!N(e,a))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.GREATER_THAN])}}},e.GreaterThanValidator=r.__decorate([x(u.GREATER_THAN),r.__metadata("design:paramtypes",[String])],e.GreaterThanValidator),e.GreaterThanOrEqualValidator=class extends P{constructor(e=h.GREATER_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.GREATER_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(b(e,a)&&F(e,a)||N(e,a))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.GREATER_THAN_OR_EQUAL])}}},e.GreaterThanOrEqualValidator=r.__decorate([x(u.GREATER_THAN_OR_EQUAL),r.__metadata("design:paramtypes",[String])],e.GreaterThanOrEqualValidator),e.LessThanValidator=class extends P{constructor(e=h.LESS_THAN){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.LESS_THAN])}catch(e){return this.getMessage(e.message||this.message)}try{if(!A(e,a))throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.LESS_THAN])}}},e.LessThanValidator=r.__decorate([x(u.LESS_THAN),r.__metadata("design:paramtypes",[String])],e.LessThanValidator),e.LessThanOrEqualValidator=class extends P{constructor(e=h.LESS_THAN_OR_EQUAL){super(e)}hasErrors(e,t,r){let a;try{a=r.getValueFromPath(t[u.LESS_THAN_OR_EQUAL])}catch(e){return this.getMessage(e.message||this.message)}try{if(b(e,a)&&F(e,a)||A(e,a))return;throw Error(t.message||this.message)}catch(e){return this.getMessage(e.message,t.label||t[u.LESS_THAN_OR_EQUAL])}}},e.LessThanOrEqualValidator=r.__decorate([x(u.LESS_THAN_OR_EQUAL),r.__metadata("design:paramtypes",[String])],e.LessThanOrEqualValidator),e.ListValidator=class extends P{constructor(e=h.LIST){super(e,Array.name,Set.name)}hasErrors(e,t){if(!e||(Array.isArray(e)?!e.length:!e.size))return;const r=(Array.isArray(t.clazz)?t.clazz:[t.clazz]).map((e=>"string"==typeof e?e:e?.name||"function"!=typeof e?e?.name:e().name));let a,s=!0;for(let t=0;t<(Array.isArray(e)?e.length:e.size);t++)switch(a=[...e][t],typeof a){case"object":case"function":s=r.includes((a??{}).constructor?.name);break;default:s=r.some((e=>typeof a===e?.toLowerCase()))}return s?void 0:this.getMessage(t.message||this.message,r)}},e.ListValidator=r.__decorate([x(u.LIST),r.__metadata("design:paramtypes",[String])],e.ListValidator),e.MaxLengthValidator=class extends P{constructor(e=h.MAX_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return R(e)>t.maxlength?this.getMessage(t.message||this.message,t.maxlength):void 0}},e.MaxLengthValidator=r.__decorate([x(u.MAX_LENGTH),r.__metadata("design:paramtypes",[String])],e.MaxLengthValidator),e.MaxValidator=class extends P{constructor(e=h.MAX){super(e,Number.name,Date.name,String.name)}hasErrors(e,t){if(void 0===e)return;let{max:r}=t;if(e instanceof Date&&!(r instanceof Date)&&(r=new Date(r),Number.isNaN(r.getDate())))throw Error("Invalid Max param defined");return e>r?this.getMessage(t.message||this.message,r):void 0}},e.MaxValidator=r.__decorate([x(u.MAX),r.__metadata("design:paramtypes",[String])],e.MaxValidator),e.MinLengthValidator=class extends P{constructor(e=h.MIN_LENGTH){super(e,String.name,Array.name,Set.name,Map.name)}hasErrors(e,t){if(void 0!==e)return R(e)<t.minlength?this.getMessage(t.message||this.message,t.minlength):void 0}},e.MinLengthValidator=r.__decorate([x(u.MIN_LENGTH),r.__metadata("design:paramtypes",[String])],e.MinLengthValidator),e.MinValidator=class extends P{constructor(e=h.MIN){super(e,Number.name,Date.name,String.name)}hasErrors(e,t){if(void 0===e)return;let{min:r}=t;if(e instanceof Date&&!(r instanceof Date)&&(r=new Date(r),Number.isNaN(r.getDate())))throw Error("Invalid Min param defined");return r>e?this.getMessage(t.message||this.message,r):void 0}},e.MinValidator=r.__decorate([x(u.MIN),r.__metadata("design:paramtypes",[String])],e.MinValidator),e.OptionValidator=class extends P{constructor(e=h.ENUM){super(e)}hasErrors(e,t){if(void 0!==e){if(Array.isArray(t.enum))return t.enum.includes(e)?void 0:this.getMessage(t.message||this.message,t.enum);if("object"==typeof t.enum){const r=Object.keys(t.enum);for(const a of r)if(t.enum[a]===e)return;return this.getMessage(t.message||this.message,Object.values(t.enum))}}}},e.OptionValidator=r.__decorate([x(u.ENUM),r.__metadata("design:paramtypes",[String])],e.OptionValidator),e.PasswordValidator=class extends e.PatternValidator{constructor(e=h.PASSWORD){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,[u.PATTERN]:t?.pattern||f.PASSWORD.CHAR8_ONE_OF_EACH})}},e.PasswordValidator=r.__decorate([x(u.PASSWORD),r.__metadata("design:paramtypes",[Object])],e.PasswordValidator),e.RequiredValidator=class extends P{constructor(e=h.REQUIRED){super(e)}hasErrors(e,t={}){switch(typeof e){case"boolean":case"number":return void 0===e?this.getMessage(t.message||this.message):void 0;default:return e?void 0:this.getMessage(t.message||this.message)}}},e.RequiredValidator=r.__decorate([x(u.REQUIRED),r.__metadata("design:paramtypes",[String])],e.RequiredValidator),e.StepValidator=class extends P{constructor(e=h.STEP){super(e,"number","string")}hasErrors(e,t){if(void 0!==e)return Number(e)%Number(t.step)!=0?this.getMessage(t.message||this.message,t.step):void 0}},e.StepValidator=r.__decorate([x(u.STEP),r.__metadata("design:paramtypes",[String])],e.StepValidator),e.TypeValidator=class extends P{constructor(e=h.TYPE){super(e)}hasErrors(e,t){if(void 0===e)return;const{type:r,message:a,customTypes:s}=t;let i=s||r;return i=(Array.isArray(i)?i:[i]).map((e=>"string"==typeof e?e:("function"!=typeof e||e.name||(e=e()),e.name||e))),_(e,i)?void 0:this.getMessage(a||this.message,"string"==typeof i?i:Array.isArray(i)?i.join(", "):i,typeof e)}},e.TypeValidator=r.__decorate([x(u.TYPE),r.__metadata("design:paramtypes",[String])],e.TypeValidator),L.register({validator:e.TypeValidator,validationKey:e.ModelKeys.TYPE,save:!1}),e.URLValidator=class extends e.PatternValidator{constructor(e=h.URL){super(e)}hasErrors(e,t={}){return super.hasErrors(e,{...t,message:t.message||this.message,pattern:t.pattern||f.URL})}},e.URLValidator=r.__decorate([x(u.URL),r.__metadata("design:paramtypes",[String])],e.URLValidator);class Ee{constructor(e=t.Metadata.isModel){this.cache={},this.testFunction=e}register(e,t){if("function"!=typeof e)throw Error("Model registering failed. Missing Class name or constructor");t=t||e.name,this.cache[t]=e}get(e){try{return this.cache[e]}catch(e){return}}build(e={},r){if(!r&&!this.testFunction(e))throw Error("Provided obj is not a Model object");const a=r||t.Metadata.modelName(e.constructor);if(!(a in this.cache))throw Error(`Provided class ${a} is not a registered Model object`);return new this.cache[a](e)}static setBuilder(e){ye=e}static getBuilder(){return ye||Ee.fromModel}static fromModel(e,r){let a;r||(r={});const s=t.Metadata.getAttributes(e),i=Object.getPrototypeOf(e);let n;for(const o of s){try{e[o]=r[o]??e[o]??void 0}catch(e){if(n=Object.getOwnPropertyDescriptor(i,o),!n||n.writable)throw Error(`Unable to write property ${o} to model: ${e}`)}if("object"!=typeof e[o])continue;const s=t.Metadata.isPropertyModel(e,o);if(s){try{e[o]=Ee.getRegistry().build(e[o],"string"==typeof s?s:void 0)}catch(e){}continue}if(a=t.Metadata.allowedTypes(e.constructor,o),!a||!a.length)throw Error("failed to find decorators for property "+o);const c=a.map((e=>"function"!=typeof e||e.name?e:e())),d=Object.values(U);c.forEach((r=>{if(!d.includes(r))try{switch(r.name){case"Array":case"Set":{const a=t.Metadata.validationFor(e.constructor,o);if(!a||!a[u.LIST])break;const s=a[u.LIST].clazz.map((e=>"function"!=typeof e||e.name?e:e())).find((e=>!C.includes(e.name)));if("Array"===r.name&&(e[o]=e[o].map((e=>["object","function"].includes(typeof e)&&s?Ee.getRegistry().build(e,s.name):e))),"Set"===r.name){const t=new Set;for(const r of e[o])["object","function"].includes(typeof r)&&s?t.add(Ee.getRegistry().build(r,s.name)):t.add(r);e[o]=t}break}default:void 0!==e[o]&&Ee.getRegistry().get(r.name)&&(e[o]=Ee.getRegistry().build(e[o],r.name))}}catch(e){}}))}return e}static getRegistry(){return me||(me=new Ee),me}static setRegistry(e){me=e}}function Me(e,t,r){Object.hasOwnProperty.call(e,t)||(e[t]=r)}function Te(e,t){Object.hasOwnProperty.call(e,t)&&delete e[t]}function be(e,t,r,...a){t&&Me(e,m,t),Me(e,E,!!r);const s=e.hasErrors(...a);return Te(e,m),Te(e,E),s}function Ae(e,t,r,a,s,...i){let n,c=!1;for(const d of a){const a=Ee.getRegistry().get(d);if(a||(n=new o({[e]:{[u.TYPE]:"Unable to verify type consistency, missing model registry for "+d}})),t instanceof a){c=!0,n=be(t,r,s,...i);break}}return c?n:n||new o({[e]:{[u.TYPE]:"Value must be an instance of one of the expected types: "+a.join(", ")}})}function Ne(e,...t){return t?.map((t=>("string"==typeof t&&t?.startsWith(e+".")&&(t=t.replace(e+".","")),t)))}function Se(t,r,a,s){const i=L.get(a.key);if(!i)throw Error("Missing validator for "+a.key);if(!s&&a.async)return;const n=a.key===e.ModelKeys.TYPE?[a]:a||{},o=V.create(t,{ignoreUndefined:!0,ignoreNull:!0}),c=a.key===e.ModelKeys.TYPE?n[0]:n;return j(i.hasErrors(r,c,o),s)}function Oe(r,a,s,i,n,...o){const c={};for(const d in i){const l={...i[d],key:d};if(!n&&l.async)continue;let h=Se(r,s,l,n);if(d===u.LIST&&(!h||n)){const e=s instanceof Set?[...s]:s;if(e&&e.length>0){let s=l.class||l.clazz||l.customTypes;s=(Array.isArray(s)?s:[s]).map((e=>(e="function"!=typeof e||e.name?e:e()).name?e.name:e));const i=[s].flat().map((e=>(e+"").toLowerCase())),c=e.map((e=>{if(t.Metadata.isModel(e)){const t=Ne(a,...o);return Ae(a,e,r,s.flat(),!!n,...t)}return i.includes(typeof e)?void 0:"Value has no validatable type"}));if(n)h=Promise.all(c).then((e=>e.every((e=>!e))?void 0:e));else{const e=c.every((e=>!e));h=c.length>0&&!e?c:void 0}}}const f=d===e.ModelKeys.TYPE?u.TYPE:d;h&&(c[f]=h)}if(!n)return Object.keys(c).length>0?c:void 0;const d=Object.keys(c),l=Object.values(c);return Promise.all(l).then((e=>{const t={};for(let r=0;r<e.length;r++){const a=e[r];void 0!==a&&(t[d[r]]=a)}return Object.keys(t).length>0?t:void 0}))}function _e(r,a,...s){const i=t.Metadata.validatableProperties(r.constructor,...s),n={},c={};for(const o of i){const i=o+"",d=r[o],l=t.Metadata.validationFor(r.constructor,o)||{},{designTypes:h}=t.Metadata.getPropDesignTypes(r.constructor,o);if(!h)continue;if(h.some((e=>[Array.name,Set.name].includes(e.name)))){if(!l||!Object.keys(l).includes(u.LIST)){n[i]={[u.TYPE]:`Array or Set property '${i}' requires a @list decorator`};continue}if(d&&!(Array.isArray(d)||d instanceof Set)){n[i]={[u.TYPE]:`Property '${o+""}' must be either an Array or a Set`};continue}}const f=Oe(r,i,d,l,a,...s)||{};if(t.Metadata.isPropertyModel(r,i)&&null!=d){const t=h.map((e=>Ee.getRegistry().get(e.name||e))).find((e=>!!e)),n=h.map((e=>"function"==typeof e?e.name?e.name.toLowerCase():e()?.name.toLowerCase():e.toLowerCase()));if(t&&d instanceof t){const e=Ne(i,...s);c[i]=be(d,r,a,...e)}else n.includes(typeof d)||(f[u.TYPE]=t?"Value must be an instance of "+t.name:`Unable to verify type consistency, missing model registry for ${h.toString()} on prop ${i}`,delete f[e.ModelKeys.TYPE])}(Object.keys(f).length>0||a)&&(n[i]=f),a||Object.entries(c[i]||{}).forEach((([e,t])=>{void 0!==t&&(n[`${i}.${e}`]=t)}))}if(!a)return Object.keys(n).length>0?new o(n):void 0;const d=n,l=Object.keys(d),h=Object.values(d);return Promise.allSettled(h).then((async e=>{const t={};for(const[e,r]of Object.entries(c)){const a=await r;a&&Object.entries(a).forEach((([r,a])=>{void 0!==a&&(t[[e,r].join(".")]=a)}))}for(let r=0;r<e.length;r++){const a=l[r],s=e[r];"fulfilled"===s.status&&void 0!==s.value?t[a]=s.value:"rejected"===s.status&&(t[a]=s.reason instanceof Error?s.reason.message:(s.reason||"Validation failed")+"")}return Object.keys(t).length>0?new o(t):void 0}))}function Re(e){e+="";let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t.toString()}function ve(e){const t=(e,t)=>{const r=a(t);return"string"==typeof r?a((e||"")+a(t)):0|(e=((e=e||0)<<5)-e+r)},r=Re,a=e=>void 0===e?"":-1!==["string","number","symbol"].indexOf(typeof e)?r(e.toString()):e instanceof Date?r(e.getTime()):Array.isArray(e)?e.reduce(t,void 0):Object.values(e).reduce(t,void 0),s=Object.values(e).reduce(t,0);return("number"==typeof s?Math.abs(s):s).toString()}const Pe="default";class De{static{this.current=Pe}static{this.cache={default:ve}}constructor(){}static get(e){if(e in this.cache)return this.cache[e];throw Error("No hashing method registered under "+e)}static register(e,t,r=!1){if(e in this.cache)throw Error(`Hashing method ${e} already registered`);this.cache[e]=t,r&&(this.current=e)}static hash(e,t,...r){return t?this.get(t)(e,...r):this.get(this.current)(e,...r)}static setDefault(e){this.current=this.get(e)}}class Le{constructor(e=void 0){}isAsync(){return!!(this[E]??this?.constructor[E])}hasErrors(...e){return _e(this,this.isAsync(),...e)}equals(e,...t){return F(this,e,...t)}compare(e,...r){const a=t.Metadata.properties(this.constructor);if(!a||!a.length)return;const s=a.reduce(((t,a)=>{const s=a;if(r.includes(s))return t;if(void 0===this[s]&&void 0!==e[s])return t[s]={other:e[s],current:void 0},t;if(void 0!==this[s]&&void 0===e[s])return t[s]={other:void 0,current:this[s]},t;if(F(this[s],e[s]))return t;if(Le.isPropertyModel(this,s)){const r=this[s].compare(e[s]);return r&&(t[s]=r),t}if(Array.isArray(this[s])&&Array.isArray(e[s])){if(this[s].length!==e[s].length)return t[s]={current:this[s],other:e[s]},t;const r=this[s].map(((t,r)=>F(t,e[s][r])?null:t instanceof Le&&e[s][r]instanceof Le?t.compare(e[s][r]):{current:t,other:e[s][r]}));return r.some((e=>null!==e))&&(t[s]=r),t}return t[s]={other:e[s],current:this[s]},t}),{});return Object.keys(s).length>0?s:void 0}serialize(){return Le.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return Le.hash(this)}static deserialize(r){let a;try{a=t.Metadata.get(this.constructor,e.ModelKeys.SERIALIZATION)}catch(e){a=void 0}return a&&a.serializer?n.deserialize(r,a.serializer,...a.args||[]):n.deserialize(r)}static fromObject(e,t){t||(t={});for(const r of Le.getAttributes(e))e[r]=t[r]??e[r]??void 0;return e}static fromModel(e,t){return Ee.fromModel(e,t)}static setBuilder(e){Ee.setBuilder(e)}static getBuilder(){return Ee.getBuilder()}static getRegistry(){return Ee.getRegistry()}static setRegistry(e){Ee.setRegistry(e)}static register(e,t){return Ee.getRegistry().register(e,t)}static get(e){return Ee.getRegistry().get(e)}static build(e={},t){return Le.getRegistry().build(e,t)}static getAttributes(e){return t.Metadata.getAttributes(e)}static equals(e,t,...r){return F(e,t,...r)}static hasErrors(e,t,...r){return _e(e,t,...r)}static serialize(r){let a;try{a=t.Metadata.get(r.constructor,e.ModelKeys.SERIALIZATION)}catch(e){a=void 0}return a&&a.serializer?n.serialize(this,a.serializer,...a.args||[]):n.serialize(r)}static hash(r){const a=t.Metadata.get(r.constructor,e.ModelKeys.HASHING);return a&&a.algorithm?De.hash(r,a.algorithm,...a.args||[]):De.hash(r)}static isModel(e){return t.Metadata.isModel(e)}static isPropertyModel(e,r){return t.Metadata.isPropertyModel(e,r)}static describe(e,r){return t.Metadata.description(e,r)}}function we(e){return e instanceof Ve?e.build():new Date(e)}function Ie(e,t,r){const a=new Date(e);return r.years&&a.setFullYear(a.getFullYear()+t*r.years),r.months&&a.setMonth(a.getMonth()+t*r.months),r.days&&a.setDate(a.getDate()+t*r.days),r.hours&&a.setHours(a.getHours()+t*r.hours),r.minutes&&a.setMinutes(a.getMinutes()+t*r.minutes),r.seconds&&a.setSeconds(a.getSeconds()+t*r.seconds),a}t.Metadata.validationFor=((e,r,a)=>{const s=t.Metadata.get(e);if(!s)return;if(!r)return s.validation;if(!s.validation)return;if(!s.validation[u.TYPE]){const{designTypes:a}=t.Metadata.getPropDesignTypes(e,r);s.validation[r]&&a?.length&&a[0]!==U.OBJECT&&(s.validation[r][u.TYPE]={customTypes:a,message:h.TYPE,description:"defines the accepted types for the attribute",async:!1})}if(!a)return s.validation[r];const i=s.validation[r];return i?i[a]:void 0}).bind(t.Metadata),t.Metadata.modelName=(e=>{const r=t.Metadata.constr(e);return r?r.name:e.name}).bind(t.Metadata),t.Metadata.validatableProperties=((e,...r)=>{const a=t.Metadata.validationFor(e),s=a?Object.keys(a):[];return[...new Set([...Le.getAttributes(e),...s])].filter((e=>!r||!r?.includes(e)))}).bind(t.Metadata),t.Metadata.allowedTypes=((e,r)=>{const a=t.Metadata.type(e,r);if(!a)throw Error("No metadata found for property "+r);const s=t.Metadata.validationFor(e,r);return s&&s[u.TYPE]&&"function"==typeof s[u.TYPE]?.customTypes[Symbol.iterator]?[...s[u.TYPE].customTypes]:[a]}).bind(t.Metadata),t.Metadata.getPropDesignTypes=((e,r)=>{const a=t.Metadata.get(e),s=t.Metadata.type(e,r),i=a?.[u.REFLECT]?.[r];if(!(s||i&&i[u.TYPE]))return{};const n=i&&i[u.TYPE]?[i[u.TYPE].customTypes]:[s];if(!n?.length)return{};const o=n[0],c=o.class||o.clazz||o.customTypes||o;return{designTypes:(Array.isArray(c)?c:[c]).map((e=>"function"!=typeof e||e.name?e:e())),designType:c}}).bind(t.Metadata),t.Metadata.isModel=(e=>{try{if(e instanceof Le)return!0;const r=t.Metadata.constr(e);return!(!r||r===e||!t.Metadata.modelName(r))}catch(e){return!1}}).bind(t.Metadata),t.Metadata.isPropertyModel=((e,r)=>{if(t.Metadata.isModel(e[r]))return!0;const a=t.Metadata.type(e.constructor,r);return a&&Ee.getRegistry().get(a.name)?a.name:void 0}).bind(t.Metadata),t.Metadata.getAttributes=(e=>{const r=e instanceof Le?e.constructor:e,a=new Set,s=e=>{if(!e)return[];const r=s(Object.getPrototypeOf(e)),i=t.Metadata.properties(e)??[];for(const e of i)a.has(e)||(a.add(e),r.push(e));return r};return s(r)}).bind(t.Metadata);class Ve{constructor(){this.years=0,this.months=0,this.days=0,this.hours=0,this.minutes=0,this.seconds=0}static Years(e){return(new Ve).Years(e)}static Months(e){return(new Ve).Months(e)}static Days(e){return(new Ve).Days(e)}static Hours(e){return(new Ve).Hours(e)}static Minutes(e){return(new Ve).Minutes(e)}static Seconds(e){return(new Ve).Seconds(e)}Years(e){return this.years+=e,this}Months(e){return this.months+=e,this}Days(e){return this.days+=e,this}Hours(e){return this.hours+=e,this}Minutes(e){return this.minutes+=e,this}Seconds(e){return this.seconds+=e,this}build(e=new Date){return this.from(e)}from(e){return Ie(we(e),1,this.offsets())}past(e){return this.from(e)}after(e){return this.from(e)}until(e){return Ie(we(e),-1,this.offsets())}before(e){return this.until(e)}offsets(){return{years:this.years,months:this.months,days:this.days,hours:this.hours,minutes:this.minutes,seconds:this.seconds}}}const je=Ve,He=()=>new Date;class Ue{constructor(){}preSerialize(r,...a){const s=Object.assign({},r);let i;try{i=t.Metadata.modelName(r.constructor)}catch(e){i=void 0}return s[e.ModelKeys.ANCHOR]=i||r.constructor.name,s}deserialize(t,...r){const a=JSON.parse(t),s=a[e.ModelKeys.ANCHOR];if(!s)throw Error("Could not find class reference in serialized model");return Le.build(a,s)}serialize(e,...t){return JSON.stringify(this.preSerialize(e))}}function Ce(e,...t){const r=(...t)=>new e(...t);return r.prototype=e.prototype,r(...t)}function xe(e){if(e instanceof Le)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,Le.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,Le.prototype)}throw Error("Could not find proper prototype to bind")}function Fe(r){const a=(...e)=>{const t=Ce(r,...e);xe(t);const a=Le.getBuilder();return a&&a(t,e.length?e[0]:void 0),t};return a.prototype=r.prototype,Object.defineProperty(a,"name",{writable:!1,enumerable:!0,configurable:!1,value:r.prototype.constructor.name}),t.metadata(e.ModelKeys.CONSTRUCTOR,r)(a),Le.register(a,r.name),a}function ze(){const r=e.ModelKeys.MODEL;return t.Decoration.for(r).define(Fe).apply()}n.cache={json:new Ue};class Ge{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=Ge.asMeta(e),r="string"==typeof e?e:Ge.resolveMessage(t);return this.decorate(X(r))}min(e,t){const r=Ge.asMeta(e),a=r?.[u.MIN]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${u.MIN} for ${this.attr+""}`);return this.decorate(W(a,Ge.resolveMessage(r,t)))}max(e,t){const r=Ge.asMeta(e),a=r?.[u.MAX]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${u.MAX} for ${this.attr+""}`);return this.decorate(Z(a,Ge.resolveMessage(r,t)))}step(e,t){const r=Ge.asMeta(e),a=r?.[u.STEP]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${u.STEP} for ${this.attr+""}`);return this.decorate(J(a,Ge.resolveMessage(r,t)))}minlength(e,t){const r=Ge.asMeta(e),a=r?.[u.MIN_LENGTH]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${u.MIN_LENGTH} for ${this.attr+""}`);return this.decorate(ee(a,Ge.resolveMessage(r,t)))}maxlength(e,t){const r=Ge.asMeta(e),a=r?.[u.MAX_LENGTH]??(r?void 0:e);if(void 0===a)throw Error(`Missing ${u.MAX_LENGTH} for ${this.attr+""}`);return this.decorate(te(a,Ge.resolveMessage(r,t)))}pattern(e,t){const r=Ge.asMeta(e),a=r?.[u.PATTERN]??(r?void 0:e),s=Ge.patternFromString(a)??/.*/;return this.decorate(re(s,Ge.resolveMessage(r,t)))}email(e){const t=Ge.asMeta(e),r="string"==typeof e?e:Ge.resolveMessage(t);return this.decorate(ae(r))}url(e){const t=Ge.asMeta(e),r="string"==typeof e?e:Ge.resolveMessage(t);return this.decorate(se(r))}type(e,t){const r=Ge.asMeta(e),a=r?.customTypes??r?.type??(r?void 0:e);return this.decorate(ie(a,Ge.resolveMessage(r,t)))}date(e,t){const r=Ge.asMeta(e),a=r?.[u.FORMAT]??(r?void 0:e);return this.decorate(ne(a,Ge.resolveMessage(r,t)))}password(e,t){const r=Ge.asMeta(e),a=r?.[u.PATTERN]??(r?void 0:e),s=Ge.patternFromString(a);return this.decorate(oe(s,Ge.resolveMessage(r,t)))}list(e,t,r){const a=Ge.asMeta(e),s=a?.clazz??(a?void 0:e),i=a?.type??t;return this.decorate(ce(s,i,Ge.resolveMessage(a,r)))}set(e,t){return Ge.isMetadataPayload(e)?this.list(e):this.list(e,"Set",t)}enum(e,t){const r=Ge.asMeta(e),a=r?.[u.ENUM]??(r?void 0:e);return this.decorate(pe(a,Ge.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 Ge.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 a=Ge.asMeta(e);return a?{target:a[t],options:{label:a.label,message:a.message}}:{target:e,options:r}}equals(e,t){const{target:r,options:a}=this.resolveComparison(e,u.EQUALS,t);return this.decorate(ue(r,a))}eq(e,t){return this.equals(e,t)}different(e,t){const{target:r,options:a}=this.resolveComparison(e,u.DIFF,t);return this.decorate(de(r,a))}diff(e,t){return this.different(e,t)}lessThan(e,t){const{target:r,options:a}=this.resolveComparison(e,u.LESS_THAN,t);return this.decorate(le(r,a))}lt(e,t){return this.lessThan(e,t)}lessThanOrEqual(e,t){const{target:r,options:a}=this.resolveComparison(e,u.LESS_THAN_OR_EQUAL,t);return this.decorate(he(r,a))}lte(e,t){return this.lessThanOrEqual(e,t)}greaterThan(e,t){const{target:r,options:a}=this.resolveComparison(e,u.GREATER_THAN,t);return this.decorate(fe(r,a))}gt(e,t){return this.greaterThan(e,t)}greaterThanOrEqual(e,t){const{target:r,options:a}=this.resolveComparison(e,u.GREATER_THAN_OR_EQUAL,t);return this.decorate(ge(r,a))}gte(e,t){return this.greaterThanOrEqual(e,t)}description(e){return this.decorate(t.description(e))}build(e){const r=e.prototype,a=this.attr;Object.getOwnPropertyDescriptor(r,a)||Object.defineProperty(r,a,{configurable:!0,enumerable:!0,writable:!0,value:void 0}),this.declaredType&&Reflect.defineMetadata(t.DecorationKeys.DESIGN_TYPE,this.declaredType,r,a),t.prop()(r,a),this.decorators.forEach((e=>{try{e(r,a)}catch(e){throw Error(`Failed to apply decorator to property "${this.attr}": ${e}`)}}))}}class Ye{constructor(e,t,r){this.parent=e,this.attribute=t,this.collection=r}ofPrimitives(e,t){return this.attribute.list(e,this.collection,t),this.parent}ofModel(){const e=$e.builder(),t=e.build;let r;return this.attribute.list((()=>(r||(r=Reflect.apply(t,e,[])),r)),this.collection),e.build=new Proxy(t,{apply:(e,t,a)=>(r=Reflect.apply(e,t,a),this.parent)}),e}}class $e extends a.ObjectAccumulator{constructor(){super(...arguments),this.attributes=new Map}setName(e){return this._name=e,this}description(e){return this._description=e,this}attribute(e,t){const r=this.attributes.get(e);if(r){if(r.declaredType!==t)throw Error(`Attribute "${e+""}" already exists with a different type`);return r}const a=new Ge(this,e,t);return this.attributes.set(e,a),a}string(e){return this.attribute(e,String)}number(e){return this.attribute(e,Number)}date(e){return this.attribute(e,Date)}bigint(e){return this.attribute(e,BigInt)}instance(e,t){return this.attribute(t,e)}model(e){const t=new $e;return t.build=new Proxy(t.build,{apply:(t,r,a)=>{const s=Reflect.apply(t,r,a);return this.instance(s,e)}}),t}listOf(e,t="Array"){const r="Set"===t?Set:Array,a=this.attribute(e,r);return new Ye(this,a,t)}build(){if(!this._name)throw Error("name is required");const e=this._parent??Le;class r extends e{constructor(e){super(e)}}Object.defineProperty(r,"name",{value:this._name,writable:!1});for(const e of this.attributes.values())e.build(r);let a=ze()(r);return this._description&&(a=t.description(this._description)(a)),a}static builder(){return new $e}static from(e,t){if(!e)throw Error("metadata is required");const r=$e.builder(),a=t??"GeneratedModel"+Date.now();r.setName(a);const s=e.properties||{},i=e.validation||{};for(const[e,t]of Object.entries(s)){const a=r.attribute(e,t||Object),s=i[e];if(s)for(const[e,t]of Object.entries(s)){const r=a[e];if("function"!=typeof r)try{const r=L.decoratorFromKey(e),s="function"==typeof r?r(t):r;a.decorate(s)}catch{}else r.call(a,t)}}return r.build()}}const qe="##VERSION##",Ke="##PACKAGE##";t.Metadata.registerLibrary(Ke,qe),e.ASYNC_META_KEY=E,e.AsyncValidator=class extends v{constructor(e=h.DEFAULT,...t){super(!0,e,...t)}},e.AttributeBuilder=Ge,e.COMPARISON_ERROR_MESSAGES=y,e.ComparisonValidationKeys=c,e.DAYS_OF_WEEK_NAMES=l,e.DEFAULT_ERROR_MESSAGES=h,e.DEFAULT_PATTERNS=f,e.DateBuilder=Ve,e.Dates=je,e.DaysAgo=e=>Ve.Days(e).until(He()),e.DefaultHashingMethod=Pe,e.DefaultSerializationMethod=i,e.Hashing=De,e.HoursAgo=e=>Ve.Hours(e).until(He()),e.JSONSerializer=Ue,e.MONTH_NAMES=d,e.MinutesAgo=e=>Ve.Minutes(e).until(He()),e.Model=Le,e.ModelBuilder=$e,e.ModelErrorDefinition=o,e.ModelRegistryManager=Ee,e.MonthsAgo=e=>Ve.Months(e).until(He()),e.NextDays=e=>Ve.Days(e).from(He()),e.NextHours=e=>Ve.Hours(e).from(He()),e.NextMinutes=e=>Ve.Minutes(e).from(He()),e.NextMonths=e=>Ve.Months(e).from(He()),e.NextSeconds=e=>Ve.Seconds(e).from(He()),e.NextYears=e=>Ve.Years(e).from(He()),e.Now=He,e.PACKAGE_NAME=Ke,e.PathProxyEngine=V,e.ReservedModels=U,e.SecondsAgo=e=>Ve.Seconds(e).until(He()),e.Serialization=n,e.Tomorrow=()=>Ve.Days(1).from(He()),e.VALIDATION_PARENT_KEY=m,e.VERSION=qe,e.Validation=L,e.ValidationKeys=u,e.Validator=P,e.ValidatorRegistry=D,e.YearsAgo=e=>Ve.Years(e).until(He()),e.Yesterday=()=>Ve.Days(1).until(He()),e.async=()=>e=>{Object.prototype.hasOwnProperty.call(e,E)||(e[E]=!0)},e.bindDateToString=Y,e.bindModelPrototype=xe,e.bulkModelRegister=(...e)=>{e.forEach((e=>{const t=e.constructor?e.constructor:e;Ee.getRegistry().register(t,e.name)}))},e.checkType=S,e.checkTypes=O,e.construct=Ce,e.date=ne,e.dateFromFormat=G,e.diff=de,e.email=ae,e.eq=ue,e.evaluateDesignTypes=_,e.findLastProtoBeforeObject=e=>{let t=Object.getPrototypeOf(e);if(t===Object.prototype)return e;for(;t!==Object.prototype;){if(t=Object.getPrototypeOf(t),t===Object.prototype)return t;if(Object.getPrototypeOf(t)===Object.prototype)return t}throw Error("Could not find proper prototype")},e.formatDate=K,e.getChildNestedPropsToIgnore=Ne,e.gt=fe,e.gte=ge,e.hashCode=Re,e.hashObj=ve,e.hashedBy=(r,...a)=>t.metadata(e.ModelKeys.HASHING,{algorithm:r,args:a}),e.innerValidationDecorator=B,e.isEqual=F,e.isGreaterThan=N,e.isLessThan=A,e.isValidDate=$,e.isValidForGteOrLteComparison=b,e.jsTypes=C,e.list=ce,e.lt=le,e.lte=he,e.max=Z,e.maxlength=te,e.min=W,e.minlength=ee,e.model=ze,e.modelBaseDecorator=Fe,e.offsetDate=Ie,e.option=pe,e.parseDate=k,e.password=oe,e.pattern=re,e.regexpParser=z,e.required=X,e.serializedBy=(r,...a)=>t.metadata(e.ModelKeys.SERIALIZATION,{serializer:r,args:a}),e.set=(e,t=h.LIST)=>ce(e,"Set",t),e.sf=p,e.step=J,e.stringFormat=g,e.toConditionalPromise=j,e.twoDigitPad=q,e.type=ie,e.url=se,e.validate=_e,e.validateChildValue=Ae,e.validateDecorator=Se,e.validateDecorators=Oe,e.validationMetadata=Q,e.validator=x,e.valueLength=R},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@decaf-ts/decoration"),require("tslib"),require("typed-object-accumulator")):"function"==typeof define&&define.amd?define(["exports","@decaf-ts/decoration","tslib","typed-object-accumulator"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["decorator-validation"]={},e.decafTsDecoration,e.tslib,e.typedObjectAccumulator);
|
|
2
2
|
//# sourceMappingURL=decorator-validation.cjs.map
|