UNPKG

@decaf-ts/db-decorators

Version:

Agnostic database decorators and repository

2 lines 90.5 kB
/*! For license information please see db-decorators.bundle.min.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("db-decorators",[],t):"object"==typeof exports?exports["db-decorators"]=t():e["db-decorators"]=t()}(this,(()=>(()=>{var e={5580:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.id=function(){return(0,o.apply)((0,n.required)(),(0,a.readonly)(),(0,n.propMetadata)(s.Repository.key(i.DBKeys.ID),{}))};const n=r(2302),o=r(32),a=r(965),i=r(2402),s=r(5666)},2912:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(5580),t),o(r(861),t)},861:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.findPrimaryKey=s,t.findModelId=function(e,t=!1){const r=s(e).id,n=e[r];if(!n&&!t)throw new i.InternalError((0,a.sf)("No value for the Id is defined under the property {0}",r));return n};const n=r(2402),o=r(8311),a=r(2302),i=r(879);function s(e){const t=(0,o.getAllPropertyDecoratorsRecursive)(e,void 0,n.DBKeys.REFLECT+n.DBKeys.ID),r=Object.entries(t).reduce(((e,[t,r])=>{const n=r.filter((e=>e.key!==a.ModelKeys.TYPE));return n&&n.length&&(e[t]=e[t]||[],e[t].push(...n)),e}),{});if(!r||!Object.keys(r).length)throw new i.InternalError("Could not find ID decorated Property");if(Object.keys(r).length>1)throw new i.InternalError((0,a.sf)(Object.keys(r).join(", ")));const s=Object.keys(r)[0];if(!s)throw new i.InternalError("Could not find ID decorated Property");return{id:s,props:r[s][0].props}}},7729:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(2912),t),o(r(1206),t),o(r(3847),t),o(r(5804),t),o(r(5666),t),o(r(965),t)},5996:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},2395:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},2564:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},885:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},1206:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(5996),t),o(r(2395),t),o(r(2564),t),o(r(885),t)},2402:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_TIMESTAMP_FORMAT=t.DefaultSeparator=t.DBKeys=void 0;const n=r(2302);t.DBKeys={REFLECT:`${n.ModelKeys.REFLECT}persistence.`,REPOSITORY:"repository",CLASS:"_class",ID:"id",INDEX:"index",UNIQUE:"unique",SERIALIZE:"serialize",READONLY:"readonly",TIMESTAMP:"timestamp",HASH:"hash",COMPOSED:"composed",VERSION:"version",ORIGINAL:"__originalObj"},t.DefaultSeparator="_",t.DEFAULT_TIMESTAMP_FORMAT="dd/MM/yyyy HH:mm:ss:S"},5893:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hashOnCreateUpdate=l,t.hash=f,t.composedFromCreateUpdate=d,t.composedFromKeys=function(e,t=n.DefaultSeparator,r=!1,o="",a=""){return p(e,r,t,"keys",o,a)},t.composed=function(e,t=n.DefaultSeparator,r=!1,o="",a=""){return p(e,r,t,"values",o,a)},t.versionCreateUpdate=y,t.version=function(){return(0,o.apply)((0,a.type)(Number.name),(0,i.onCreate)(y(u.OperationKeys.CREATE)),(0,i.onUpdate)(y(u.OperationKeys.UPDATE)),(0,a.propMetadata)(c.Repository.key(n.DBKeys.VERSION),!0))};const n=r(2402),o=r(32),a=r(2302),i=r(6208),s=r(879),c=r(3932),u=r(5804);function l(e,t,r,n){if(!r[t])return;const o=a.Hashing.hash(r[t]);n&&r[t]===o||(r[t]=o)}function f(){return(0,o.apply)((0,i.onCreateUpdate)(l),(0,a.propMetadata)(c.Repository.key(n.DBKeys.HASH),{}))}function d(e,t,r,n){try{const{args:e,type:o,prefix:i,suffix:c,separator:u}=t,l=e.map((e=>{if(!(e in n))throw new s.InternalError((0,a.sf)("Property {0} not found to compose from",e));if("keys"===o)return e;if(void 0===n[e])throw new s.InternalError((0,a.sf)("Property {0} does not contain a value to compose from",e));return n[e].toString()}));i&&l.unshift(i),c&&l.push(c),n[r]=l.join(u)}catch(e){throw new s.InternalError(`Failed to compose value: ${e}`)}}function p(e,t=!1,r=n.DefaultSeparator,s="values",u="",l=""){const p={args:e,hashResult:t,separator:r,type:s,prefix:u,suffix:l},y=[(0,i.onCreateUpdate)(d,p),(0,a.propMetadata)(c.Repository.key(n.DBKeys.COMPOSED),p)];return t&&y.push(f()),(0,o.apply)(...y)}function y(e){return function(t,r,n,o){try{switch(e){case u.OperationKeys.CREATE:o[n]=1;break;case u.OperationKeys.UPDATE:o[n]++;break;default:throw new s.InternalError(`Invalid operation: ${e}`)}}catch(e){throw new s.InternalError(`Failed to update version: ${e}`)}}}},3847:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(192),t),o(r(2402),t),o(r(5893),t),o(r(2366),t)},2366:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2302),o=r(192);n.Model.prototype.hasErrors=function(e,...t){!e||e instanceof n.Model||(t.unshift(e),e=void 0);const r=(0,n.validate)(this,...t);return r||!e?r:(0,o.validateCompare)(e,this,...t)}},192:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.validateCompare=function(e,t,...r){const s=[];for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&-1===r.indexOf(e)&&s.push(o.Reflection.getPropertyDecorators(a.UpdateValidationKeys.REFLECT,t,e));let c;for(const r of s){const{prop:o,decorators:a}=r;if(a.shift(),!a||!a.length)continue;let i;for(const s of a){const a=n.Validation.get(s.key);if(!a){console.error(`Could not find Matching validator for ${s.key} for property ${String(r.prop)}`);continue}const c=a.updateHasErrors(t[o.toString()],e[o.toString()],...Object.values(s.props));c&&(i=i||{},i[s.key]=c)}i&&(c=c||{},c[r.prop.toString()]=i)}for(const a of Object.keys(t).filter((e=>!(r.includes(e)||c&&c[e])))){let r;const s=o.Reflection.getPropertyDecorators(n.ValidationKeys.REFLECT,t,a).decorators,u=o.Reflection.getPropertyDecorators(n.ValidationKeys.REFLECT,t,a).decorators.filter((e=>-1!==[n.ModelKeys.TYPE,n.ValidationKeys.TYPE].indexOf(e.key)));if(!u||!u.length)continue;const l=u.pop(),f=l.props.name?[l.props.name]:Array.isArray(l.props.customTypes)?l.props.customTypes:[l.props.customTypes],d=Object.values(n.ReservedModels).map((e=>e.toLowerCase()));for(const o of f){if(-1===d.indexOf(o.toLowerCase()))switch(o){case Array.name:case Set.name:if(s.length&&s.find((e=>e.key===n.ValidationKeys.LIST))){let n,s;switch(o){case Array.name:n=t[a],s=e[a];break;case Set.name:n=t[a].values(),s=e[a].values();break;default:throw new Error(`Invalid attribute type ${o}`)}r=n.map((e=>{const t=(0,i.findModelId)(e,!0);if(!t)return"Failed to find model id";const r=s.find((e=>t===(0,i.findModelId)(e,!0)));return r?e.hasErrors(r):void 0})).filter((e=>!!e)),r?.length||(r=void 0)}break;default:try{t[a]&&e[a]&&(r=t[a].hasErrors(e[a]))}catch(e){console.warn((0,n.sf)("Model should be validatable but its not"))}}r&&(c=c||{},c[a]=r)}}return c?new n.ModelErrorDefinition(c):void 0};const n=r(2302),o=r(32),a=r(965),i=r(2912)},9668:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Operations=void 0;const n=r(2302),o=r(4143),a=r(7625);class i{constructor(){}static getHandlerName(e){return e.name?e.name:(console.warn("Handler name not defined. A name will be generated, but this is not desirable. please avoid using anonymous functions"),n.Hashing.hash(e.toString()))}static key(e){return a.OperationKeys.REFLECT+e}static get(e,t,r){return i.registry.get(e,t,r)}static getOpRegistry(){return i.registry||(i.registry=new o.OperationsRegistry),i.registry}static register(e,t,r,n){i.getOpRegistry().register(e,t,r,n)}}t.Operations=i},4143:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.OperationsRegistry=void 0;const n=r(9668);t.OperationsRegistry=class{constructor(){this.cache={}}get(e,t,r,n){let o;n=n||[];try{o="string"==typeof e?e:e.constructor.name,n.unshift(...Object.values(this.cache[o][t][r]||[]))}catch(t){if("string"==typeof e||e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return n}let a=Object.getPrototypeOf(e);return a.constructor.name===o&&(a=Object.getPrototypeOf(a)),this.get(a,t,r,n)}register(e,t,r,o){const a=r.constructor.name,i=n.Operations.getHandlerName(e);this.cache[a]||(this.cache[a]={}),this.cache[a][o]||(this.cache[a][o]={}),this.cache[a][o][t]||(this.cache[a][o][t]={}),this.cache[a][o][t][i]||(this.cache[a][o][t][i]=e)}}},7625:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.DBOperations=t.OperationKeys=void 0,function(e){e.REFLECT="decaf.model.db.operations.",e.CREATE="create",e.READ="read",e.UPDATE="update",e.DELETE="delete",e.ON="on.",e.AFTER="after."}(r||(t.OperationKeys=r={})),t.DBOperations={CREATE:[r.CREATE],READ:[r.READ],UPDATE:[r.UPDATE],DELETE:[r.DELETE],CREATE_UPDATE:[r.CREATE,r.UPDATE],READ_CREATE:[r.READ,r.CREATE],ALL:[r.CREATE,r.READ,r.UPDATE,r.DELETE]}},6208:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.onCreateUpdate=function(e,t){return s(n.DBOperations.CREATE_UPDATE,e,t)},t.onUpdate=function(e,t){return s(n.DBOperations.UPDATE,e,t)},t.onCreate=function(e,t){return s(n.DBOperations.CREATE,e,t)},t.onRead=function(e,t){return s(n.DBOperations.READ,e,t)},t.onDelete=function(e,t){return s(n.DBOperations.DELETE,e,t)},t.onAny=function(e,t){return s(n.DBOperations.ALL,e,t)},t.on=s,t.afterCreateUpdate=function(e,t){return c(n.DBOperations.CREATE_UPDATE,e,t)},t.afterUpdate=function(e,t){return c(n.DBOperations.UPDATE,e,t)},t.afterCreate=function(e,t){return c(n.DBOperations.CREATE,e,t)},t.afterRead=function(e,t){return c(n.DBOperations.READ,e,t)},t.afterDelete=function(e,t){return c(n.DBOperations.DELETE,e,t)},t.afterAny=function(e,t){return c(n.DBOperations.ALL,e,t)},t.after=c,t.operation=u;const n=r(7625),o=r(9668),a=r(32),i=r(2302);function s(e=n.DBOperations.ALL,t,r){return u(n.OperationKeys.ON,e,t,r)}function c(e=n.DBOperations.ALL,t,r){return u(n.OperationKeys.AFTER,e,t,r)}function u(e,t=n.DBOperations.ALL,r,s){return(n,c)=>{const u=n.constructor.name,l=t.reduce(((t,a)=>{const l=e+a;let f=Reflect.getMetadata(o.Operations.key(l),n,c);f||(f={operation:a,handlers:{}});const d=o.Operations.getHandlerName(r);return f.handlers[u]&&f.handlers[u][c]&&d in f.handlers[u][c]||(f.handlers[u]=f.handlers[u]||{},f.handlers[u][c]=f.handlers[u][c]||{},f.handlers[u][c][d]={data:s},t.push(function(e,t){return(r,n)=>{o.Operations.register(t,e,r,n)}}(l,r),(0,i.propMetadata)(o.Operations.key(l),f))),t}),[]);return(0,a.apply)(...l)(n,c)}}},5804:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(7625),t),o(r(6208),t),o(r(9668),t),o(r(4143),t),o(r(5981),t)},5981:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},8269:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BaseRepository=void 0;const n=r(2302),o=r(8311),a=r(7625),i=r(879),s=r(3420),c=r(861),u=r(4605);t.BaseRepository=class{get class(){if(!this._class)throw new i.InternalError("No class definition found for this repository");return this._class}get pk(){return this._pk||(this._pk=(0,c.findPrimaryKey)(new this.class).id),this._pk}constructor(e){e&&(this._class=e);const t=this;[this.create,this.read,this.update,this.delete].forEach((e=>{const r=e.name;(0,s.wrapMethodWithContext)(t,t[r+"Prefix"],e,t[r+"Suffix"])}))}async createAll(e,...t){return Promise.all(e.map((e=>this.create(e,...t))))}async createPrefix(e,...t){const r=await u.Context.args(a.OperationKeys.CREATE,this.class,t);return e=new this.class(e),await(0,o.enforceDBDecorators)(this,r.context,e,a.OperationKeys.CREATE,a.OperationKeys.ON),[e,...r.args]}async createSuffix(e,t){return await(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.CREATE,a.OperationKeys.AFTER),e}async createAllPrefix(e,...t){const r=await u.Context.args(a.OperationKeys.CREATE,this.class,t);return await Promise.all(e.map((async e=>(e=new this.class(e),await(0,o.enforceDBDecorators)(this,r.context,e,a.OperationKeys.CREATE,a.OperationKeys.ON),e)))),[e,...r.args]}async createAllSuffix(e,t){return await Promise.all(e.map((e=>(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.CREATE,a.OperationKeys.AFTER)))),e}async readAll(e,...t){return await Promise.all(e.map((e=>this.read(e,...t))))}async readSuffix(e,t){return await(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.READ,a.OperationKeys.AFTER),e}async readPrefix(e,...t){const r=await u.Context.args(a.OperationKeys.READ,this.class,t),n=new this.class;return n[this.pk]=e,await(0,o.enforceDBDecorators)(this,r.context,n,a.OperationKeys.READ,a.OperationKeys.ON),[e,...r.args]}async readAllPrefix(e,...t){const r=await u.Context.args(a.OperationKeys.READ,this.class,t);return await Promise.all(e.map((async e=>{const t=new this.class;return t[this.pk]=e,(0,o.enforceDBDecorators)(this,r.context,t,a.OperationKeys.READ,a.OperationKeys.ON)}))),[e,...r.args]}async readAllSuffix(e,t){return await Promise.all(e.map((e=>(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.READ,a.OperationKeys.AFTER)))),e}async updateAll(e,...t){return Promise.all(e.map((e=>this.update(e,...t))))}async updateSuffix(e,t){return await(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.UPDATE,a.OperationKeys.AFTER),e}async updatePrefix(e,...t){const r=await u.Context.args(a.OperationKeys.UPDATE,this.class,t),n=e[this.pk];if(!n)throw new i.InternalError(`No value for the Id is defined under the property ${this.pk}`);const s=await this.read(n);return await(0,o.enforceDBDecorators)(this,r.context,e,a.OperationKeys.UPDATE,a.OperationKeys.ON,s),[e,...r.args]}async updateAllPrefix(e,...t){const r=await u.Context.args(a.OperationKeys.UPDATE,this.class,t);return await Promise.all(e.map((e=>(e=new this.class(e),(0,o.enforceDBDecorators)(this,r.context,e,a.OperationKeys.UPDATE,a.OperationKeys.ON),e)))),[e,...r.args]}async updateAllSuffix(e,t){return await Promise.all(e.map((e=>(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.UPDATE,a.OperationKeys.AFTER)))),e}async deleteAll(e,...t){return Promise.all(e.map((e=>this.delete(e,...t))))}async deleteSuffix(e,t){return await(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.DELETE,a.OperationKeys.AFTER),e}async deletePrefix(e,...t){const r=await u.Context.args(a.OperationKeys.DELETE,this.class,t),n=await this.read(e,...r.args);return await(0,o.enforceDBDecorators)(this,r.context,n,a.OperationKeys.DELETE,a.OperationKeys.ON),[e,...r.args]}async deleteAllPrefix(e,...t){const r=await u.Context.args(a.OperationKeys.DELETE,this.class,t),n=await this.readAll(e,...r.args);return await Promise.all(n.map((async e=>(0,o.enforceDBDecorators)(this,r.context,e,a.OperationKeys.DELETE,a.OperationKeys.ON)))),[e,...r.args]}async deleteAllSuffix(e,t){return await Promise.all(e.map((e=>(0,o.enforceDBDecorators)(this,t,e,a.OperationKeys.DELETE,a.OperationKeys.AFTER)))),e}merge(e,t){const r=e=>Object.entries(e).reduce(((e,[t,r])=>(void 0!==r&&(e[t]=r),e)),{});return new this.class(Object.assign({},r(e),r(t)))}toString(){return(0,n.sf)("[{0}] - Repository for {1}",this.constructor.name,this.class.name)}}},4605:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Context=void 0;const n=r(6124),o=r(879);class a extends n.DataCache{constructor(e,t,r){super(),this.operation=e,this.model=t,this.parent=r}get timestamp(){return new Date}async get(e){try{return super.get(e)}catch(t){if(this.parent)return this.parent.get(e);throw t}}async pop(e){if(e in this.cache)return super.pop(e);if(!this.parent)throw new o.NotFoundError(`Key ${e} not in dataStore`);return this.parent.pop(e)}child(e,t){return this.constructor(e,t,this)}static async from(e,t,...r){return new a(e,t)}static async args(e,t,r,n){const o=r.pop();async function i(){return n?n.context(e,t,...r):new a(e,t)}let s;return o?o instanceof a?(s=o,r.push(o)):(s=await i(),r.push(o,s)):(s=await i(),r.push(s)),{context:s,args:r}}}t.Context=a},6124:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.DataCache=void 0;const n=r(879);t.DataCache=class{constructor(){this.cache={}}async get(e){if(!(e in this.cache))throw new n.NotFoundError(`Key ${e} not in dataStore`);return this.cache[e]}async push(e,t){if(e in this.cache)throw new n.ConflictError(`Key ${e} already in dataStore`);this.cache[e]=t}async put(e,t){this.cache[e]=t}async pop(e){const t=this.get(e);return delete this.cache[e],t}async filter(e){return"string"==typeof e&&(e=new RegExp(e)),Object.keys(this.cache).filter((t=>!!e.exec(t))).map((e=>this.cache[e]))}async purge(e){e?await this.pop(e):this.cache={}}}},3932:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Repository=void 0;const n=r(8311),o=r(7625),a=r(879),i=r(8269),s=r(2402),c=r(4605);class u extends i.BaseRepository{constructor(e){super(e)}async createPrefix(e,...t){const r=await c.Context.args(o.OperationKeys.CREATE,this.class,t);e=new this.class(e),await(0,n.enforceDBDecorators)(this,r.context,e,o.OperationKeys.CREATE,o.OperationKeys.ON);const i=e.hasErrors();if(i)throw new a.ValidationError(i.toString());return[e,...r.args]}async createAllPrefix(e,...t){const r=await c.Context.args(o.OperationKeys.CREATE,this.class,t);await Promise.all(e.map((async e=>(e=new this.class(e),await(0,n.enforceDBDecorators)(this,r.context,e,o.OperationKeys.CREATE,o.OperationKeys.ON),e))));const i=e.map((e=>e.hasErrors())).reduce(((e,t,r)=>(t&&(e="string"==typeof e?e+`\n - ${r}: ${t.toString()}`:` - ${r}: ${t.toString()}`),e)),void 0);if(i)throw new a.ValidationError(i);return[e,...r.args]}async updatePrefix(e,...t){const r=await c.Context.args(o.OperationKeys.UPDATE,this.class,t),i=e[this.pk];if(!i)throw new a.InternalError(`No value for the Id is defined under the property ${this.pk}`);const s=await this.read(i);e=this.merge(s,e),await(0,n.enforceDBDecorators)(this,r.context,e,o.OperationKeys.UPDATE,o.OperationKeys.ON,s);const u=e.hasErrors(s);if(u)throw new a.ValidationError(u.toString());return[e,...r.args]}async updateAllPrefix(e,...t){const r=await c.Context.args(o.OperationKeys.UPDATE,this.class,t),i=e.map((e=>{const t=e[this.pk];if(!t)throw new a.InternalError(`No value for the Id is defined under the property ${this.pk}`);return t})),s=await this.readAll(i,...r.args);e=e.map(((e,t)=>this.merge(s[t],e))),await Promise.all(e.map(((e,t)=>(0,n.enforceDBDecorators)(this,r.context,e,o.OperationKeys.UPDATE,o.OperationKeys.ON,s[t]))));const u=e.map(((e,t)=>e.hasErrors(s[t],e))).reduce(((e,t,r)=>(t&&(e="string"==typeof e?e+`\n - ${r}: ${t.toString()}`:` - ${r}: ${t.toString()}`),e)),void 0);if(u)throw new a.ValidationError(u);return[e,...r.args]}static key(e){return s.DBKeys.REFLECT+e}}t.Repository=u},879:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ConflictError=t.NotFoundError=t.SerializationError=t.InternalError=t.ValidationError=t.BaseError=void 0;class r extends Error{constructor(e,t){if(t instanceof r)return t;super(`[${e}] ${t instanceof Error?t.message:t}`),t instanceof Error&&(this.stack=t.stack)}}t.BaseError=r;class n extends r{constructor(e){super(n.name,e)}}t.ValidationError=n;class o extends r{constructor(e){super(o.name,e)}}t.InternalError=o;class a extends r{constructor(e){super(a.name,e)}}t.SerializationError=a;class i extends r{constructor(e){super(i.name,e)}}t.NotFoundError=i;class s extends r{constructor(e){super(s.name,e)}}t.ConflictError=s},5666:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(8269),t),o(r(4605),t),o(r(6124),t),o(r(879),t),o(r(3932),t),o(r(8311),t),o(r(3420),t)},8311:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getAllPropertyDecoratorsRecursive=t.getHandlerArgs=void 0,t.enforceDBDecorators=async function(e,r,a,u,l,f){const d=c(a,u,l);if(d)for(const c in d){const p=d[c];for(const d of p){const{key:p}=d,y=n.Operations.get(a,c,l+p);if(!y||!y.length)throw new i.InternalError(`Could not find registered handler for the operation ${l+p} under property ${c}`);const h=(0,t.getHandlerArgs)(d,c,a);if(!h||Object.values(h).length!==y.length)throw new i.InternalError((0,s.sf)("Args and handlers length do not match"));let g,E;for(let t=0;t<y.length;t++){g=y[t],E=Object.values(h)[t];const n=[r,E.data,c,a];if(u===o.OperationKeys.UPDATE&&l===o.OperationKeys.ON){if(!f)throw new i.InternalError("Missing old model for update operation");n.push(f)}await g.apply(e,n)}}}},t.getDbDecorators=c;const n=r(9668),o=r(7625),a=r(32),i=r(879),s=r(2302);function c(e,t,r){const n=a.Reflection.getAllPropertyDecorators(e,o.OperationKeys.REFLECT+(r||""));if(n)return Object.keys(n).reduce(((e,r)=>{const o=n[r].filter((e=>e.key===t));return o&&o.length&&(e||(e={}),e[r]=o),e}),void 0)}t.getHandlerArgs=function(e,r,n,o){const a=n.constructor.name;if(!a)throw new i.InternalError("Could not determine model class");o=o||{},e.props.handlers[a]&&e.props.handlers[a][r]&&(o={...e.props.handlers[a][r],...o});let s=Object.getPrototypeOf(n);return s===Object.prototype?o:(s.constructor.name===a&&(s=Object.getPrototypeOf(s)),(0,t.getHandlerArgs)(e,r,s,o))},t.getAllPropertyDecoratorsRecursive=function(e,r,...n){const i=r||{},c=a.Reflection.getAllPropertyDecorators(e,...n);if(c&&function(e){Object.entries(e).forEach((([e,t])=>{i[e]=i[e]||[],((e,...t)=>{t.forEach((t=>{let r;if(!(r=i[e].find((e=>e.key===t.key)))||r.props.operation!==t.props.operation)return void i[e].push(t);if(t.key===s.ModelKeys.TYPE)return;const{handlers:n,operation:a}=t.props;if(!a||!a.match(new RegExp(`^(:?${o.OperationKeys.ON}|${o.OperationKeys.AFTER})(:?${o.OperationKeys.CREATE}|${o.OperationKeys.READ}|${o.OperationKeys.UPDATE}|${o.OperationKeys.DELETE})$`)))return void i[e].push(t);const c=r.props.handlers;Object.entries(n).forEach((([e,t])=>{e in c?Object.entries(t).forEach((([t,r])=>{t in c[e]?Object.entries(r).forEach((([r,n])=>{r in c[e][t]?console.warn((0,s.sf)("Skipping handler registration for {0} under prop {0} because handler is the same",e,t)):c[e][t][r]=n})):c[e][t]=r})):c[e]=t}))}))})(e,...t)}))}(c),Object.getPrototypeOf(e)===Object.prototype)return i;const u=Object.getPrototypeOf(e);return u?(0,t.getAllPropertyDecoratorsRecursive)(u,i,...n):i}},3420:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prefixMethod=function(e,t,r,n){const o=async function(...e){const n=await Promise.resolve(r.call(this,...e));return Promise.resolve(t.apply(this,n))}.bind(e),a=n||t.name;Object.defineProperty(o,"name",{enumerable:!0,configurable:!0,writable:!1,value:a}),e[a]=o},t.suffixMethod=function(e,t,r,n){const o=async function(...e){const n=await Promise.resolve(t.call(this,...e));return r.call(this,...n)}.bind(e),a=n||t.name;Object.defineProperty(o,"name",{enumerable:!0,configurable:!0,writable:!1,value:a}),e[a]=o},t.wrapMethodWithContext=function(e,t,r,a,i){const s=async function(...i){let s=t.call(e,...i);s instanceof Promise&&(s=await s);const c=s[s.length-1];if(!(c instanceof n.Context))throw new o.InternalError("Missing a context");let u=await r.call(e,...s);return u instanceof Promise&&(u=await u),u=a.call(this,u,c),u instanceof Promise&&(u=await u),u}.bind(e),c=i||r.name;Object.defineProperty(s,"name",{enumerable:!0,configurable:!0,writable:!1,value:c}),e[c]=s};const n=r(4605),o=r(879)},2628:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UpdateValidationKeys=t.DEFAULT_ERROR_MESSAGES=void 0;const n=r(2402);t.DEFAULT_ERROR_MESSAGES={ID:{INVALID:"This Id is invalid",REQUIRED:"The Id is mandatory"},READONLY:{INVALID:"This cannot be updated"},TIMESTAMP:{REQUIRED:"Timestamp is Mandatory",DATE:"The Timestamp must the a valid date",INVALID:"This value must always increase"}},t.UpdateValidationKeys={REFLECT:"db.update.validation.",TIMESTAMP:n.DBKeys.TIMESTAMP,READONLY:n.DBKeys.READONLY}},3475:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.readonly=function(e=a.DEFAULT_ERROR_MESSAGES.READONLY.INVALID){return(0,n.propMetadata)(n.Validation.updateKey(o.DBKeys.READONLY),{message:e})},t.timestampHandler=f,t.timestamp=function(e=i.DBOperations.CREATE_UPDATE,t=o.DEFAULT_TIMESTAMP_FORMAT){const r=[(0,n.date)(t,a.DEFAULT_ERROR_MESSAGES.TIMESTAMP.DATE),(0,n.required)(a.DEFAULT_ERROR_MESSAGES.TIMESTAMP.REQUIRED),(0,s.on)(e,f)];return-1!==e.indexOf(i.OperationKeys.UPDATE)&&r.push((0,n.propMetadata)(n.Validation.updateKey(o.DBKeys.TIMESTAMP),{message:a.DEFAULT_ERROR_MESSAGES.TIMESTAMP.INVALID})),(0,u.apply)(...r)},t.serializeOnCreateUpdate=d,t.serializeAfterAll=p,t.serialize=function(){return(0,u.apply)((0,s.onCreateUpdate)(d),(0,s.after)(i.DBOperations.ALL,p),(0,n.type)([String.name,Object.name]),(0,u.metadata)(l.Repository.key(o.DBKeys.SERIALIZE),{}))};const n=r(2302),o=r(2402),a=r(2628),i=r(7625),s=r(6208),c=r(879),u=r(32),l=r(5666);async function f(e,t,r,n){n[r]=e.timestamp}async function d(e,t,r,o){if(r[t])try{r[t]=JSON.stringify(r[t])}catch(e){throw new c.SerializationError((0,n.sf)("Failed to serialize {0} property on {1} model: {2}",t,r.constructor.name,e.message))}}async function p(e,t,r){if(r[t]&&"string"==typeof r[t])try{r[t]=JSON.parse(r[t])}catch(e){throw new c.SerializationError((0,n.sf)("Failed to deserialize {0} property on {1} model: {2}",t,r.constructor.name,e.message))}}},965:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(973),t),o(r(2628),t),o(r(3475),t),o(r(5634),t)},5634:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2302),o=r(2628);n.Validation.updateKey=function(e){return o.UpdateValidationKeys.REFLECT+e}},4837:function(e,t,r){"use strict";var n=this&&this.__decorate||function(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i},o=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ReadOnlyValidator=void 0;const a=r(2302),i=r(2628),s=r(32);let c=class extends a.Validator{constructor(){super(i.DEFAULT_ERROR_MESSAGES.READONLY.INVALID)}hasErrors(e,...t){}updateHasErrors(e,t,r){if(void 0!==e)return(0,s.isEqual)(e,t)?void 0:this.getMessage(r||this.message)}};t.ReadOnlyValidator=c,t.ReadOnlyValidator=c=n([(0,a.validator)(i.UpdateValidationKeys.READONLY),o("design:paramtypes",[])],c)},3927:function(e,t,r){"use strict";var n=this&&this.__decorate||function(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i},o=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.TimestampValidator=void 0;const a=r(2302),i=r(2628);let s=class extends a.Validator{constructor(){super(i.DEFAULT_ERROR_MESSAGES.TIMESTAMP.INVALID)}hasErrors(e,...t){}updateHasErrors(e,t,r){if(void 0!==e){r=r||this.getMessage(r||this.message);try{e=new Date(e),t=new Date(t)}catch(e){return r}return e<=t?r:void 0}}};t.TimestampValidator=s,t.TimestampValidator=s=n([(0,a.validator)(i.UpdateValidationKeys.TIMESTAMP),o("design:paramtypes",[])],s)},372:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UpdateValidator=void 0;const n=r(2302);class o extends n.Validator{constructor(e=n.DEFAULT_ERROR_MESSAGES.DEFAULT,...t){super(e,...t)}}t.UpdateValidator=o},973:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(4837),t),o(r(3927),t),o(r(372),t)},2302:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.VERSION=void 0,o(r(4072),t),o(r(5030),t),o(r(5643),t),t.VERSION="1.4.17"},3:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Model=void 0;const n=r(4744),o=r(1825),a=r(32),i=r(2709),s=r(2252),c=r(9683),u=r(7675),l=r(5021),f=r(1318),d=r(8539);let p,y;class h{constructor(e){}hasErrors(...e){return(0,i.validate)(this,...e)}equals(e,...t){return(0,a.isEqual)(this,e,...t)}serialize(){return h.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}hash(){return h.hash(this)}static deserialize(e){const t=Reflect.getMetadata(h.key(u.ModelKeys.SERIALIZATION),this.constructor);return t&&t.serializer?n.Serialization.deserialize(e,t.serializer,...t.args||[]):n.Serialization.deserialize(e)}static fromObject(e,t){t||(t={});for(const r of h.getAttributes(e))e[r]=t[r]||void 0;return e}static fromModel(e,t){let r,n;t||(t={});const o=h.getAttributes(e);for(const i of o){if(e[i]=t[i]||void 0,"object"!=typeof e[i])continue;const o=(0,c.isPropertyModel)(e,i);if(o){try{e[i]=h.build(e[i],"string"==typeof o?o:void 0)}catch(e){console.log(e)}continue}const s=a.Reflection.getPropertyDecorators(l.ValidationKeys.REFLECT,e,i).decorators;if(r=s.filter((e=>-1!==[u.ModelKeys.TYPE,l.ValidationKeys.TYPE].indexOf(e.key))),!r||!r.length)throw new Error((0,f.sf)("failed to find decorators for property {0}",i));n=r.pop();const p=n.props.name?[n.props.name]:Array.isArray(n.props.customTypes)?n.props.customTypes:[n.props.customTypes],y=Object.values(d.ReservedModels).map((e=>e.toLowerCase()));p.forEach((t=>{if(-1===y.indexOf(t.toLowerCase()))try{switch(t){case"Array":case"Set":if(s.length){const r=s.find((e=>e.key===l.ValidationKeys.LIST));if(r){const n=r.props.class.find((e=>!d.jsTypes.includes(e.toLowerCase())));if("Array"===t&&(e[i]=e[i].map((e=>["object","function"].includes(typeof e)&&n?h.build(e,n):e))),"Set"===t){const t=new Set;for(const r of e[i])["object","function"].includes(typeof r)&&n?t.add(h.build(r,n)):t.add(r);e[i]=t}}}break;default:e[i]&&(e[i]=h.build(e[i],t))}}catch(e){console.log(e)}}))}return e}static setBuilder(e){p=e}static getBuilder(){return p}static getRegistry(){return y||(y=new o.ModelRegistryManager),y}static setRegistry(e){y=e}static register(e,t){return h.getRegistry().register(e,t)}static get(e){return h.getRegistry().get(e)}static build(e={},t){return h.getRegistry().build(e,t)}static getMetadata(e){const t=Reflect.getMetadata(h.key(u.ModelKeys.MODEL),e.constructor);if(!t)throw new Error("could not find metadata for provided "+e.constructor.name);return t}static getAttributes(e){const t=[];let r=e instanceof h?Object.getPrototypeOf(e):e.prototype;for(;null!=r;){const e=r[u.ModelKeys.ATTRIBUTE];e&&t.push(...e),r=Object.getPrototypeOf(r)}return t}static equals(e,t,...r){return(0,a.isEqual)(e,t,...r)}static hasErrors(e,...t){return(0,i.validate)(e,...t)}static serialize(e){const t=Reflect.getMetadata(h.key(u.ModelKeys.SERIALIZATION),e.constructor);return t&&t.serializer?n.Serialization.serialize(this,t.serializer,...t.args||[]):n.Serialization.serialize(e)}static hash(e){const t=Reflect.getMetadata(h.key(u.ModelKeys.HASHING),e.constructor);return t&&t.algorithm?s.Hashing.hash(e,t.algorithm,...t.args||[]):s.Hashing.hash(e)}static key(e){return u.ModelKeys.REFLECT+e}}t.Model=h},3368:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ModelErrorDefinition=void 0,t.ModelErrorDefinition=class{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 n=Object.keys(e[r]).reduce(((t,n)=>(t?t+=`\n${e[r][n]}`:t=e[r][n],t)),void 0);return n&&(n=`${r} - ${n}`,t?t+=`\n${n}`:t=n),t}),"")}}},1825:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ModelRegistryManager=void 0,t.bulkModelRegister=function(...e){e.forEach((e=>{const t=e.constructor?e.constructor:e;n.Model.register(t,e.name)}))};const n=r(3),o=r(1318),a=r(9683);t.ModelRegistryManager=class{constructor(e=a.isModel){this.cache={},this.testFunction=e}register(e,t){if("function"!=typeof e)throw new 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={},t){if(!t&&!this.testFunction(e))throw new Error("Provided obj is not a Model object");const r=t||n.Model.getMetadata(e);if(!(r in this.cache))throw new Error((0,o.sf)("Provided class {0} is not a registered Model object",r));return new this.cache[r](e)}}},8539:(e,t)=>{"use strict";var r,n;Object.defineProperty(t,"__esModule",{value:!0}),t.jsTypes=t.ReservedModels=t.Primitives=void 0,function(e){e.STRING="string",e.NUMBER="number",e.BOOLEAN="boolean",e.BIGINT="bigint"}(r||(t.Primitives=r={})),function(e){e.STRING="string",e.OBJECT="object",e.NUMBER="number",e.BOOLEAN="boolean",e.BIGINT="bigint",e.DATE="date"}(n||(t.ReservedModels=n={})),t.jsTypes=["string","array","number","boolean","symbol","function","object","undefined","null","bigint"]},4939:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.construct=function(e,...t){const r=(...t)=>new e(...t);return r.prototype=e.prototype,r(...t)},t.findLastProtoBeforeObject=function(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 new Error("Could not find proper prototype")},t.bindModelPrototype=function(e){if(e instanceof n.Model)return;function t(e,t){Object.setPrototypeOf(e,t)}const r=Object.getPrototypeOf(e);if(r===Object.prototype)return t(e,n.Model.prototype);for(;r!==Object.prototype;){const e=Object.getPrototypeOf(r);if(e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return t(r,n.Model.prototype)}throw new Error("Could not find proper prototype to bind")};const n=r(3)},754:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.model=function(e){return t=>{const r=function(...r){const s=(0,n.construct)(t,...r);(0,n.bindModelPrototype)(s);const c=a.Model.getBuilder();return c&&c(s,r.length?r[0]:void 0),(0,i.metadata)(a.Model.key(o.ModelKeys.MODEL),t.name)(s.constructor),e&&e(s,...r),s};return r.prototype=t.prototype,Object.defineProperty(r,"name",{writable:!1,enumerable:!0,configurable:!1,value:t.prototype.constructor.name}),(0,i.metadata)(a.Model.key(o.ModelKeys.MODEL),t.name)(t),a.Model.register(r,t.name),r}},t.hashedBy=function(e,...t){return(0,i.metadata)(a.Model.key(o.ModelKeys.HASHING),{algorithm:e,args:t})},t.serializedBy=function(e,...t){return(0,i.metadata)(a.Model.key(o.ModelKeys.SERIALIZATION),{serializer:e,args:t})};const n=r(4939),o=r(7675),a=r(3),i=r(32)},5643:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(8539),t),o(r(4939),t),o(r(754),t),o(r(3),t),o(r(3368),t),o(r(1825),t),o(r(1967),t),o(r(9683),t),o(r(2709),t)},1967:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},9683:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isPropertyModel=function(e,t){if(a(e[t]))return!0;const r=Reflect.getMetadata(n.ModelKeys.TYPE,e,t);return o.Model.get(r.name)?r.name:void 0},t.isModel=a;const n=r(7675),o=r(3);function a(e){try{return e instanceof o.Model||!!o.Model.getMetadata(e)}catch(e){return!1}}},2709:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.validate=function(e,...t){const r=[];for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&-1===t.indexOf(n)&&r.push(o.Reflection.getPropertyDecorators(u.ValidationKeys.REFLECT,e,n));let f;for(const t of r){const{prop:r,decorators:n}=t;if(!n||!n.length)continue;const o=n[0];let i;n.find((e=>e.key===u.ValidationKeys.TYPE||!!e.props.types?.find((e=>e===o.props.name))))&&n.shift();for(const t of n){const n=c.Validation.get(t.key);if(!n)throw new Error(`Missing validator for ${t.key}`);const o=n.hasErrors(e[r.toString()],...t.key===a.ModelKeys.TYPE?[t.props]:Object.values(t.props));o&&(i=i||{},i[t.key]=o)}i&&(f=f||{},f[t.prop.toString()]=i)}for(const t of Object.keys(e).filter((e=>!f||!f[e]))){let r;const n=o.Reflection.getPropertyDecorators(u.ValidationKeys.REFLECT,e,t).decorators,c=o.Reflection.getPropertyDecorators(u.ValidationKeys.REFLECT,e,t).decorators.filter((e=>-1!==[a.ModelKeys.TYPE,u.ValidationKeys.TYPE].indexOf(e.key)));if(!c||!c.length)continue;const d=c.pop(),p=d.props.name?[d.props.name]:Array.isArray(d.props.customTypes)?d.props.customTypes:[d.props.customTypes],y=Object.values(s.ReservedModels).map((e=>e.toLowerCase()));for(const o of p){if(-1===y.indexOf(o.toLowerCase())){const a=Array.isArray(e[t])?u.ValidationKeys.LIST:u.ValidationKeys.TYPE,s=n.find((e=>e.key===a))||{};let c=[];if(s&&s.props){const r=Array.isArray(e[t])?s.props.class:s.props.customTypes;r&&(c=Array.isArray(r)?r.map((e=>`${e}`.toLowerCase())):[r.toLowerCase()])}const f=(e,t)=>{if("object"==typeof t||"function"==typeof t)return(0,l.isModel)(t)?t.hasErrors():c.includes(typeof t)?void 0:"Value has no validatable type"};switch(o){case Array.name:case Set.name:n.length&&n.find((e=>e.key===u.ValidationKeys.LIST))&&(r=(o===Array.name?e[t]:e[t].values()).map((e=>f(t,e))).filter((e=>!!e)),r?.length||(r=void 0));break;default:try{e[t]&&(r=f(t,e[t]))}catch(e){console.warn((0,i.sf)("Model should be validatable but its not: "+e))}}}r&&(f=f||{},f[t]=r)}}return f?new n.ModelErrorDefinition(f):void 0};const n=r(3368),o=r(32),a=r(7675),i=r(1318),s=r(8539),c=r(1375),u=r(5021),l=r(9683)},7675:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.ModelKeys=void 0,function(e){e.REFLECT="decaf.model.",e.TYPE="design:type",e.PARAMS="design:paramtypes",e.RETURN="design:returntype",e.MODEL="model",e.ANCHOR="__model",e.CONSTRUCTION="constructed-by",e.ATTRIBUTE="__attributes",e.HASHING="hashing",e.SERIALIZATION="serialization"}(r||(t.ModelKeys=r={}))},5243:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.dateFromFormat=a,t.bindDateToString=i,t.isValidDate=s,t.twoDigitPad=c,t.formatDate=u,t.parseDate=function(e,t){let r;if(t){if(t instanceof Date)try{r=a(u(t,e),e)}catch(r){throw new Error((0,o.sf)("Could not convert date {0} to format: {1}",t.toString(),e))}else if("string"==typeof t)r=a(t,e);else if("number"==typeof t)r=a(u(new Date(t),e),e);else{if(!s(t))throw new Error(`Invalid value provided ${t}`);try{r=a(u(new Date(t),e),e)}catch(r){throw new Error((0,o.sf)("Could not convert date {0} to format: {1}",t,e))}}return i(r,e)}},r(8630);const n=r(5021),o=r(1318);function a(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 o=new RegExp(r,"g").exec(e);if(!o||!o.groups)return new Date(e);const a=function(e){if(!e)return 0;const t=parseInt(e);return isNaN(t)?0:t},i=a(o.groups.year),s=a(o.groups.day),c=o.groups.ampm;let u=a(o.groups.hour);c&&(u="PM"===c?u+12:u);const l=a(o.groups.minutes),f=a(o.groups.seconds),d=a(o.groups.milis),p=o.groups.monthname,y=o.groups.monthnamesmall;let h=o.groups.month;if(p)h=n.MONTH_NAMES.indexOf(p);else if(y){const t=n.MONTH_NAMES.find((e=>e.toLowerCase().startsWith(y.toLowerCase())));if(!t)return new Date(e);h=n.MONTH_NAMES.indexOf(t)}else h=a(`${h}`);return new Date(i,h-1,s,u,l,f,d)}function i(e,t){if(!e)return;const r=()=>u(e,t);return Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:r}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:r}),e}function s(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!Number.isNaN(e)}function c(e){return e<10?"0"+e:e.toString()}function u(e,t="yyyy/MM/dd"){const r=e.getDate(),o=e.getMonth(),a=e.getFullYear(),i=e.getHours(),s=e.getMinutes(),u=e.getSeconds(),l=e.getMilliseconds(),f=i%12,d=c(f),p=c(i),y=c(s),h=c(u),g=i<12?"AM":"PM",E=n.DAYS_OF_WEEK_NAMES[e.getDay()],O=E.substr(0,3),v=c(r),_=o+1,b=c(_),m=n.MONTH_NAMES[o],R=m.substr(0,3),M=a+"",w=M.substr(2,2);return(t=t.replace("hh",d).replace("h",f.toString()).replace("HH",p).replace("H",i.toString()).replace("mm",y).replace("m",s.toString()).replace("ss",h).replace("s",u.toString()).replace("S",l.toString()).replace("dd",v).replace("d",r.toString()).replace("EEEE",E).replace("EEE",O).replace("yyyy",M).replace("yy",w).replace("aaa",g)).indexOf("MMM")>-1?t.replace("MMMM",m).replace("MMM",R):t.replace("MM",b).replace("M",_.toString())}},3042:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.prop=a,t.propMetadata=function(e,t){return(0,n.apply)(a(),(0,n.metadata)(e,t))};const n=r(32),o=r(7675);function a(e=o.ModelKeys.ATTRIBUTE){return(t,r)=>{let n;n=Object.prototype.hasOwnProperty.call(t,e)?t[e]:t[e]=[],n.includes(r)||n.push(r)}}},2252:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Hashing=t.DefaultHashingMethod=void 0,t.hashCode=o,t.hashSerialization=function(e){return o(n.Serialization.serialize(e))},t.hashObj=a;const n=r(4744);function o(e){e=String(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 a(e){const t=function(e,t){const r=n(t);return"string"==typeof r?n((e||"")+n(t)):0|(e=((e=e||0)<<5)-e+r)},r=o,n=function(e){return void 0===e?"":-1!==["string","number","symbol"].indexOf(typeof e)?r(e.toString()):e instanceof Date?r(e.getTime()):Array.isArray(e)?e.reduce(t,void 0):Object.values(e).reduce(t,void 0)},a=Object.values(e).reduce(t,0);return("number"==typeof a?Math.abs(a):a).toString()}t.DefaultHashingMethod="default";class i{static{this.current=t.DefaultHashingMethod}static{this.cache={default:a}}constructor(){}static get(e){if(e in this.cache)return this.cache[e];throw new Error(`No hashing method registered under ${e}`)}static register(e,t,r=!1){if(e in this.cache)throw new 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)}}t.Hashing=i},4072:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(7675),t),o(r(5243),t),o(r(3042),t),o(r(2252),t),o(r(2417),t),o(r(4744),t),o(r(1318),t)},2417:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},4744:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Serialization=t.DefaultSerializationMethod=t.JSONSerializer=void 0;const n=r(3),o=r(7675);class a{preSerialize(e){const t=Object.assign({},e),r=n.Model.getMetadata(e);return t[o.ModelKeys.ANCHOR]=r||e.constructor.name,t}deserialize(e){const t=JSON.parse(e),r=t[o.ModelKeys.ANCHOR];if(!r)throw new Error("Could not find class reference in serialized model");return n.Model.build(t,r)}serialize(e){return JSON.stringify(this.preSerialize(e))}}t.JSONSerializer=a,t.DefaultSerializationMethod="json";class i{static{this.current=t.DefaultSerializationMethod}static{this.cache={json:new a}}constructor(){}static get(e){if(e in this.cache)return this.cache[e];throw new Error(`No serialization method registered under ${e}`)}static register(e,t,r=!1){if(e in this.cache)throw new 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)}}t.Serialization=i},1318:(e,t)=>{"use strict";function r(e,...t){return e.replace(/{(\d+)}/g,(function(e,r){return void 0!==t[r]?t[r].toString():"undefined"}))}Object.defineProperty(t,"__esModule",{value:!0}),t.sf=void 0,t.stringFormat=r,t.sf=r},1375:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Validation=void 0;const n=r(3201),o=r(5021);class a{static{this.actingValidatorRegistry=void 0}constructor(){}static setRegistry(e,t){t&&a.actingValidatorRegistry&&a.actingValidatorRegistry.getKeys().forEach((r=>{const n=e.get(r);n&&e.register(t(n))})),a.actingValidatorRegistry=e}static getRegistry(){return a.actingValidatorRegistry||(a.actingValidatorRegistry=new n.ValidatorRegistry),a.actingValidatorRegistry}static get(e){return a.getRegistry().get(e)}static register(...e){return a.getRegistry().register(...e)}static key(e){return o.ValidationKey