@decaf-ts/db-decorators 0.17.2 → 0.17.3
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/dist/db-decorators.cjs +1 -1
- package/lib/cjs/index.cjs +3 -3
- package/lib/esm/index.js +3 -3
- package/lib/types/index.d.cts +3 -3
- package/lib/types/index.d.mts +3 -3
- package/package.json +1 -1
package/dist/db-decorators.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e,t,r,a,o,n){"use strict";const s={REFLECT:a.ModelKeys.MODEL+".persistence.",REPOSITORY:"repository",CLASS:"_class",ID:"id",INDEX:"index",UNIQUE:"unique",SERIALIZE:"serialize",READONLY:"readonly",TIMESTAMP:"timestamp",TRANSIENT:"transient",HASH:"hash",COMPOSED:"composed",GENERATED:"generated",VERSION:"version",ORIGINAL:"__originalObj"},i="_",c="dd/MM/yyyy HH:mm:ss:S",l={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"}},d={REFLECT:"db.update.validation.",TIMESTAMP:s.TIMESTAMP,READONLY:s.READONLY};e.ReadOnlyValidator=class extends a.Validator{constructor(){super(l.READONLY.INVALID)}hasErrors(e,...t){}updateHasErrors(e,t,r){if(void 0!==e)return a.isEqual(e,t)?void 0:this.getMessage(r||this.message)}},e.ReadOnlyValidator=r.__decorate([a.validator(d.READONLY),r.__metadata("design:paramtypes",[])],e.ReadOnlyValidator),e.TimestampValidator=class extends a.Validator{constructor(){super(l.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?void 0:r}}},e.TimestampValidator=r.__decorate([a.validator(d.TIMESTAMP),r.__metadata("design:paramtypes",[])],e.TimestampValidator);class p extends a.Validator{constructor(e=a.DEFAULT_ERROR_MESSAGES.DEFAULT,...t){super(e,...t)}}var u,f,y;a.Validation.updateKey=e=>d.REFLECT+e,e.OperationKeys=void 0,(u=e.OperationKeys||(e.OperationKeys={})).REFLECT="decaf.model.db.operations.",u.CREATE="create",u.READ="read",u.UPDATE="update",u.DELETE="delete",u.ON="on.",u.AFTER="after.",u.BLOCK="block",e.ModelOperations=void 0,(f=e.ModelOperations||(e.ModelOperations={})).OPERATIONS="operations",f.RELATIONS="relations",e.BulkCrudOperationKeys=void 0,(y=e.BulkCrudOperationKeys||(e.BulkCrudOperationKeys={})).CREATE_ALL="createAll",y.READ_ALL="readAll",y.UPDATE_ALL="updateAll",y.DELETE_ALL="deleteAll",e.BulkOperationBlockTarget=void 0,(e.BulkOperationBlockTarget||(e.BulkOperationBlockTarget={})).ALL="bulkAll";const h={CREATE:[e.OperationKeys.CREATE],READ:[e.OperationKeys.READ],UPDATE:[e.OperationKeys.UPDATE],DELETE:[e.OperationKeys.DELETE],CREATE_UPDATE:[e.OperationKeys.CREATE,e.OperationKeys.UPDATE],READ_CREATE:[e.OperationKeys.READ,e.OperationKeys.CREATE],ALL:[e.OperationKeys.CREATE,e.OperationKeys.READ,e.OperationKeys.UPDATE,e.OperationKeys.DELETE]};class g{constructor(){this.cache={}}get(e,t,r,a){a=a||[];const o=this.resolveOwner(e),n=this.resolveTargetName(e,o);if(n){const e=this.selectHandlers(n,t,r,o);e?.length&&a.unshift(...e)}else if("string"==typeof e||e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return a;let s=Object.getPrototypeOf(e);return s?(s.constructor&&s.constructor.name===n&&(s=Object.getPrototypeOf(s)),s?this.get(s,t,r,a):a):a}register(e,t,r,a){const o=r.constructor.name,n=g.getHandlerName(e),s=this.resolveFlavour(r.constructor);this.cache[o]||(this.cache[o]={}),this.cache[o][a]||(this.cache[o][a]={}),this.cache[o][a][t]||(this.cache[o][a][t]={}),this.cache[o][a][t][s]||(this.cache[o][a][t][s]={}),this.cache[o][a][t][s][n]||(this.cache[o][a][t][s][n]=e)}resolveOwner(e){if(e&&"string"!=typeof e)return"function"==typeof e?e:e.constructor}resolveTargetName(e,t){return"string"==typeof e?e:t?.name}resolveFlavour(e){if(!e)return t.Decoration.defaultFlavour;try{return t.Metadata.flavourOf(e)}catch{return t.Decoration.defaultFlavour}}selectHandlers(e,r,a,o){const n=this.cache[e]?.[r]?.[a];if(!n)return;const s=n[this.resolveFlavour(o)]||n[t.Decoration.defaultFlavour]||this.firstBucket(n);if(!s)return;const i=Object.values(s);return i.length?i:void 0}firstBucket(e){for(const t of Object.values(e))if(t&&Object.keys(t).length)return t}static getHandlerName(e){return e.name?e.name:a.Hashing.hash(e.toString())}}class E{constructor(){}static getHandlerName(e){return g.getHandlerName(e)}static key(t){return e.OperationKeys.REFLECT+t}static get(e,t,r){return E.registry.get(e,t,r)}static getOpRegistry(){return E.registry||(E.registry=new g),E.registry}static register(e,t,r,a){E.getOpRegistry().register(e,t,r,a)}}class O extends Error{constructor(e,t,r){if(t instanceof O)return t;super(`[${e}][${r}] ${t instanceof Error?t.message:t}`),this.code=r,t instanceof Error&&(this.stack=t.stack)}get message(){return`[${this.name}] ${this.code} | ${super.message.replaceAll(/\[.*?Error\]\[\d+\]\s/g,"")}`}toString(){return this.message}}class m extends O{constructor(e,t=m.name,r=999){super(t,e,r)}}class A extends O{constructor(e,t=A.name,r=400){super(t,e,r)}}class T extends A{constructor(e){super(e,T.name,422)}}class M extends O{constructor(e,t=M.name,r=500){super(t,e,r)}}class w extends M{constructor(e){super(e,w.name,500)}}class D extends A{constructor(e){super(e,D.name,404)}}class P extends A{constructor(e){super(e,P.name,409)}}const v={priority:50},R=new Set([e.OperationKeys.CREATE,e.OperationKeys.READ,e.OperationKeys.UPDATE,e.OperationKeys.DELETE]),b=new Set(Object.values(e.BulkCrudOperationKeys));function S(t){return b.has(t)||t===e.BulkOperationBlockTarget.ALL?"bulk":(R.has(t),"crud")}function k(e){return"object"==typeof e&&null!==e&&Object.prototype.hasOwnProperty.call(e,"kind")&&"string"==typeof e.kind}function L(t){const r=Array.isArray(t)?t:[t],a=[];for(const t of r)if(Array.isArray(t))a.push(...L(t));else{if("string"==typeof t){const r=S(t),o=("bulk"===r&&e.BulkOperationBlockTarget.ALL,t);a.push({kind:r,value:o});continue}k(t)&&a.push(t)}return a}const K=(e,t,r,a)=>{const o=r.constructor.name;if(!o)throw new M("Could not determine model class");a=a||{},e.props.handlers[o]&&e.props.handlers[o][t]&&(a={...e.props.handlers[o][t],...a});let n=Object.getPrototypeOf(r);return n===Object.prototype?a:(n.constructor.name===o&&(n=Object.getPrototypeOf(n)),K(e,t,n,a))};function I(e,t,r){const a=[];for(const o in t){const n=t[o];for(const t of n){const{key:n}=t,s=E.get(e,o,r+n);if(!s||!s.length)throw new M(`Could not find registered handler for the operation ${r+n} under property ${o}`);const i=K(t,o,e);if(!i)throw new M("Missing handler arguments for decorators");for(const e of s){const t=E.getHandlerName(e),r=i[t];if(!r)throw new M("Missing handler arguments for handler "+t);const n=r.data;a.push({handler:e,data:[n],prop:[o]})}}}return a}function N(e){const t=e.reduce((e,t)=>{if(!t||!t.data||!t.prop)throw new M("Missing decorator properties or data");if(!t.data[0].group)return e.set(Symbol(),t),e;const r=t.data[0].group;if(e.has(r)){const a=e.get(r);e.set(r,{handler:a.handler,data:[...a.data,...t.data],prop:[...a.prop,...t.prop]})}else e.set(r,{...t});return e},new Map),r=Array.from(t.values());return r.forEach(e=>{const t=e.data.map((t,r)=>({data:t,prop:e.prop[r]}));t.sort((e,t)=>(e.data.groupPriority??50)-(t.data.groupPriority??50)),e.data=t.map(e=>e.data),e.prop=t.map(e=>e.prop)}),r}function C(e){return e.sort((e,t)=>(e.data[0].priority??50)-(t.data[0].priority??50)),e}function x(e,t,r){return V(h.CREATE_UPDATE,e,t,r)}function U(e,t,r){return V(h.UPDATE,e,t,r)}function j(e,t,r){return V(h.CREATE,e,t,r)}function V(t=h.ALL,r,a,o){return H(e.OperationKeys.ON,t,r,a,o)}function F(t=h.ALL,r,a,o){return H(e.OperationKeys.AFTER,t,r,a,o)}function H(r,a=h.ALL,o,n,s=v){return(i,c)=>{const l=i.constructor.name,d=a.reduce((a,d)=>{const p=r+d;let u=t.Metadata.readOperation(i.constructor,c,p);u||(u={operation:d,handlers:{}});const f=E.getHandlerName(o);let y=s;if(n){if(Object.keys(n).filter(e=>e in s).length>0)throw new M("Unable to merge groupSort into dataToAdd due to overlaping keys");y={...s,...n}}return u.handlers[l]&&u.handlers[l][c]&&f in u.handlers[l][c]||(u.handlers[l]=u.handlers[l]||{},u.handlers[l][c]=u.handlers[l][c]||{},u.handlers[l][c][f]={data:y},a.push(((e,t)=>(r,a)=>{E.register(t,e,r,a)})(p,o),t.propMetadata(t.Metadata.key(e.ModelOperations.OPERATIONS,c,p),u))),a},[]);return t.apply(...d)(i,c)}}function _(e,r){return(...a)=>t.metadata(e,{args:a,handler:r})}function B(e){return(r,a)=>t.propMetadata(t.Metadata.key(s.GENERATED,a),e||!0)(r,a)}function $(e,t,r,o,n){if(void 0===o[r])return;const s=a.Hashing.hash(o[r]);n&&o[r]===s||(o[r]=s)}function z(){return t.apply(x($),t.propMetadata(s.HASH,{}))}function G(e,t){const{args:r,type:o,prefix:n,suffix:s,separator:i,filterEmpty:c,hashResult:l}=t;try{const t=r.map(t=>{if("keys"===o)return t;if(void 0===e[t]){if(c){if(!Array.isArray(c))return;if(c.includes(t))return}throw new M(`Property ${r} does not contain a value to compose from`)}return e[t].toString()}).filter(e=>!c||!!e);n&&t.unshift(n),s&&t.push(s);const d=t.map(e=>"object"==typeof e&&"[object Object]"===e.toString()?JSON.stringify(e):e).join(i);return l?a.Hashing.hash(d):d}catch(e){throw new M("Failed to compose value: "+e)}}function Y(e,t,r,a){a[r]=G(a,t)}function q(e,r=!1,a=i,o=!1,n="values",c="",l="",d={priority:55}){return t.Decoration.for(s.COMPOSED).define({decorator:(e,r,a,n,i,c,l)=>(d,p)=>{const u={args:e,hashResult:r,separator:a,type:n,prefix:i,suffix:c,filterEmpty:o},f=[B(s.COMPOSED),x(Y,u,l),t.propMetadata(t.Metadata.key(s.COMPOSED,p),u)];return r&&f.push(z()),t.apply(...f)(d,p)},args:[e,r,a,n,c,l,d]}).apply()}function J(e,t=i,r=!1,a=!1,o="",n="",s={priority:55}){return q(e,a,t,r,"keys",o,n,s)}function Q(e,t=i,r=!1,a=!1,o="",n="",s={priority:55}){return q(e,a,t,r,"values",o,n,s)}function W(t){return(r,o,n,s,i)=>{if(a.Model.shouldGenerate(s,n,r))try{switch(t){case e.OperationKeys.CREATE:s[n]=1;break;case e.OperationKeys.UPDATE:if(r.get("applyUpdateValidation")&&i&&s[n]!==i[n])throw new T(`Version mismatch: ${s[n]} !== ${i[n]}`);s[n]++;break;default:throw new M("Invalid operation: "+t)}}catch(e){throw new M("Failed to update version: "+e)}}}function Z(){const r=s.VERSION;return(o,n)=>t.Decoration.for(r).define(t.propMetadata(t.Metadata.key(r,n),!0),B(s.VERSION),a.type(Number),j(W(e.OperationKeys.CREATE)),U(W(e.OperationKeys.UPDATE))).apply()(o,n)}function X(){return t.Decoration.for(s.TRANSIENT).define((e,r)=>{t.propMetadata(t.Metadata.key(s.TRANSIENT,r),{})(e,r)}).apply()}function ee(e=l.READONLY.INVALID){const r=s.READONLY,o={message:e,description:"defines the attribute as readOnly",async:!1};return t.Decoration.for(r).define({decorator:a.innerValidationDecorator,args:[ee,r,o]}).apply()}async function te(e,t,r,o){a.Model.shouldGenerate(o,r,e)&&(o[r]=e.timestamp)}async function re(e,t,r,a){if(a[r])try{a[r]=t.serializer?(new t.serializer).serialize(a[r]):JSON.stringify(a[r])}catch(e){throw new w(`Failed to serialize ${r.toString()} property of model ${a.constructor.name}: ${e}`)}}async function ae(e,t,r,a){if(a[r]&&"string"==typeof a[r])try{a[r]=t.serializer?(new t.serializer).deserialize(a[r]):JSON.parse(a[r])}catch(e){throw new w(`Failed to deserialize ${r.toString()} property of model ${a.constructor.name}: ${e}`)}}a.Model.prototype.isTransient=function(){return t.Metadata.isTransient(this)},a.Model.prototype.hasErrors=function(e,...t){!e||e instanceof a.Model||(t.unshift(e),e=void 0);const r=this.isAsync(),o=a.validate(this,r,...t);return r?Promise.resolve(o).then(a=>a||!e?a:de(e,this,r,...t)):o||!e?o:de(e,this,r,...t)},a.Model.prototype.segregate=function(){return a.Model.segregate(this)},a.Model.segregate=e=>{if(!t.Metadata.isTransient(e))return{model:e};const r=t.Metadata.validatableProperties(e.constructor),o=t.Metadata.get(e.constructor,s.TRANSIENT),n={model:{},transient:{}};for(const t of r)if(Object.keys(o).includes(t)){n.transient=n.transient||{};try{n.transient[t]=e[t]}catch(e){throw new w(`Failed to serialize transient property ${t}: ${e}`)}}else n.model=n.model||{},n.model[t]=e[t];return n.model=a.Model.build(n.model,e.constructor.name),n},t.Metadata.pk=((e,r=!1)=>{if(!e)throw Error("No model was provided");const o=e instanceof a.Model?e.constructor:e,n=t.Metadata.get(o,s.ID);if(!n)throw Error("No Id property defined for model "+(o?.name||"Unknown Model"));const i=Object.keys(n)[0];if(!r)return i;if(e instanceof a.Model)return e[i];throw Error("Cannot get the value of the pk from the constructor")}).bind(t.Metadata),a.Model.pk=((e,r=!1)=>t.Metadata.pk(e,r)).bind(a.Model),a.Model.pkProps=(e=>t.Metadata.get(e,t.Metadata.key(s.ID,a.Model.pk(e)))).bind(a.Model),a.Model.isTransient=(e=>!!t.Metadata.get("function"!=typeof e?e.constructor:e,s.TRANSIENT)).bind(a.Model),a.Model.composed=((e,r)=>{const o=e instanceof a.Model?e.constructor:e;return r?t.Metadata.get(o,t.Metadata.key(s.COMPOSED,r)):!!t.Metadata.get(o,s.COMPOSED)}).bind(a.Model),a.Model.merge=((e,t,r)=>{const a=e=>Object.entries(e).reduce((e,[t,r])=>(null!=r&&(e[t]=r),e),{});return new(r=r||e.constructor)(Object.assign({},a(e),a(t)))}).bind(a.Model),t.Metadata.saveOperation=((r,a,o,n)=>{a&&t.Metadata.set(r,t.Metadata.key(e.ModelOperations.OPERATIONS,a,o),n)}).bind(t.Metadata),t.Metadata.readOperation=((r,a,o)=>{if(a&&o)return t.Metadata.get(r,t.Metadata.key(e.ModelOperations.OPERATIONS,a,o))}).bind(t.Metadata),t.Metadata.isTransient=(e=>!!t.Metadata.get("function"!=typeof e?e.constructor:e,s.TRANSIENT)).bind(t.Metadata),a.Model.generated=((e,r)=>!!t.Metadata.get("function"!=typeof e?e.constructor:e,t.Metadata.key(s.GENERATED,r))).bind(a.Model),a.Model.shouldGenerate=((e,t,r)=>!r.get("allowGenerationOverride")||void 0===e[t]).bind(a.Model),a.Model.versionProp=(e=>{const r=t.Metadata.get(e.constructor);if(!r||!r[s.VERSION])throw new M("No version found for "+e.constructor.name);return Object.keys(r)[0]}).bind(a.Model),a.Model.versionOf=(e=>{const t=e[a.Model.versionProp(e)];if("number"!=typeof t||1>t)throw new M("Invalid version number: "+t);return t}).bind(a.Model),a.Model.propSerializedBy=((e,r)=>t.Metadata.get("function"!=typeof e?e.constructor:e,t.Metadata.key(s.SERIALIZE,r))).bind(a.Model),a.Model.isPropSerialized=((e,t)=>!!a.Model.propSerializedBy(e,t)).bind(a.Model);const oe=a.ModelBuilder.prototype;oe.decorateClass||(oe.decorateClass=function(e){return this._classDecorators||(this._classDecorators=[]),this._classDecorators.push(e),this});const ne=(e,t,r)=>(((e,t)=>{const r=e.attributes;return r?.has(t)?r.get(t):e.attribute(t,Object)})(e,t).decorate(r),e);function se(e,t,r){if("string"!=typeof r)return r;if(!a.Model.isPropSerialized(e,t))return r;try{const e=JSON.parse(r);if(Array.isArray(e))return e}catch{}return r}function ie(e,r){const a=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o)||r.includes(o))continue;const n=t.Metadata.validationFor(e.constructor,o)||{};a.push({prop:o,decorators:n})}return a}function ce(e,t,r,o,n,s,i){const c=a.Validation.get(o.key);if(!c)throw Error("Missing validator for "+o.key);if(!c.updateHasErrors)return a.toConditionalPromise(void 0,n);if(!n&&o.async)return a.toConditionalPromise(void 0,n);const l=Object.values(o)||{},d=c.updateHasErrors(void 0===s?e[r]:s,void 0===i?t[r]:i,...l);return a.toConditionalPromise(d,n)}function le(e,t,r,o,n,s,i){const c={};for(const l in o){const d={...o[l],key:l};if(!n&&d.async)continue;let p=ce(e,t,r,d,n,s,i);if(d.key===a.ValidationKeys.LIST&&(!p||n)){const e=s instanceof Set?[...s]:s,t=i instanceof Set?[...i]:i;if(e?.length){const r=[d.class||d.clazz||d.customTypes].flat().map(e=>((e=(e="function"!=typeof e||e.name?e:e()).name?e.name:e)+"").toLowerCase()),o=e.map(e=>{if(a.Model.isModel(e)){const r=a.Model.pk(e,!0);if(!r)return"Failed to find model id";const o=t.find(e=>r===a.Model.pk(e,!0));return e.hasErrors(o)}return r.includes(typeof e)?void 0:"Value has no validatable type"});if(n)p=Promise.all(o).then(e=>e.every(e=>!e)?void 0:e);else{const e=o.every(e=>!e);p=o.length>0&&!e?o:void 0}}}p&&(c[d.key]=p)}if(!n)return Object.keys(c).length>0?c:void 0;const l=Object.keys(c),d=Object.values(c);return Promise.all(d).then(e=>{const t={};for(let r=0;r<e.length;r++){const a=e[r];void 0!==a&&(t[l[r]]=a)}return Object.keys(t).length>0?t:void 0})}function de(e,r,o,...n){const s=ie(r,n),i={},c={};for(const{prop:l,decorators:d}of s){const s=l+"",p=se(r,l,r[l]),u=se(e,l,e[l]),{designTypes:f}=t.Metadata.getPropDesignTypes(r.constructor,l);if(!f)continue;if(f.some(e=>[Array.name,Set.name].includes(e))){if(!d||!Object.keys(d).includes(a.ValidationKeys.LIST)){i[s]={[a.ValidationKeys.TYPE]:`Array or Set property '${s}' requires a @list decorator`};continue}if(p&&!(Array.isArray(p)||p instanceof Set)){i[s]={[a.ValidationKeys.TYPE]:`Property '${l+""}' must be either an Array or a Set`};continue}}const y=le(r,e,s,d,o,p,u)||{},h=a.Model.isPropertyModel(r,s);if(null!=p&&h){const t=p,r=f.map(e=>a.Model.get(e.name||e)).find(e=>!!e),o=f.map(e=>"function"==typeof e?e.name?e.name.toLowerCase():e()?.name.toLowerCase():e.toLowerCase());if(r&&p instanceof r){const r=a.getChildNestedPropsToIgnore(s,...n);c[s]=t.hasErrors(e[l],...r)}else o.includes(typeof p)||(y[a.ValidationKeys.TYPE]=r?"Value must be an instance of "+r.name:`Unable to verify type consistency, missing model registry for ${f.toString()} on prop ${s}`,delete y[a.ModelKeys.TYPE])}(Object.keys(y).length>0||o)&&(i[s]=y),o||Object.entries(c[s]||{}).forEach(([e,t])=>{void 0!==t&&(i[`${s}.${e}`]=t)})}if(!o)return Object.keys(i).length>0?new a.ModelErrorDefinition(i):void 0;const l=i,d=Object.keys(l),p=Object.values(l);return Promise.allSettled(p).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=d[r],o=e[r];"fulfilled"===o.status&&void 0!==o.value?t[a]=o.value:"rejected"===o.status&&(t[a]=o.reason instanceof Error?o.reason.message:(o.reason||"Validation failed")+"")}return Object.keys(t).length>0?new a.ModelErrorDefinition(t):void 0})}function pe(e){return e.reduce((e,t,r)=>(t&&(e="string"==typeof e?e+`\n - ${r}: ${t.toString()}`:` - ${r}: ${t.toString()}`),e),void 0)}async function ue(t,r,a,o,n,s){const i=fe(a,o,n);if(!i)return;const c=C(N(I(a,i,n)));for(const n of c){const i=[r,n.data.length>1?n.data:n.data[0],n.prop.length>1?n.prop:n.prop[0],a];if([e.OperationKeys.UPDATE,e.BulkCrudOperationKeys.UPDATE_ALL].includes(o)){if(!s)throw new M("Missing old model for update operation");i.push(s)}try{await n.handler.apply(t,i)}catch(e){if(r.logger.for(ue).error(`Failed to execute handler ${n.handler.name} for ${n.prop} on ${a.constructor.name}`),r.get("breakOnHandlerError"))throw e}}}function fe(r,a,o){const n=o?.replace(/[.]$/,""),s=t.Metadata.get(r.constructor,e.ModelOperations.OPERATIONS);if(s)return Object.keys(s).reduce((e,t)=>{const r=n?s[t][n]||{}:s[t],o=Object.keys(r).filter(e=>e===a),i=[];for(const e of o)i.push({key:e,props:r[e]});return i&&i.length&&(e||(e={}),e[t]=i),e},void 0)}oe.generated=function(e,t){return ne(this,e,B(t))},oe.hash=function(e){return ne(this,e,z())},oe.composedFromKeys=function(e,t,r,a,o,n,s,i){return ne(this,e,J(t,r,a,o,n,s,i))},oe.composed=function(e,t,r,a,o,n,s,i){return ne(this,e,Q(t,r,a,o,n,s,i))},oe.version=function(e){return ne(this,e,Z())},oe.transient=function(e){return ne(this,e,X())};const ye={parentContext:void 0,childContexts:[],ignoredValidationProperties:[],callArgs:[],writeOperation:!1,affectedTables:[],operation:void 0,breakOnHandlerError:!0,rebuildWithTransient:!0,ignoreValidation:!1,ignoreHandlers:!1,ignoreDevSafeGuards:!1,mergeForUpdate:!0,applyUpdateValidation:!0,allowGenerationOverride:!1},he=e=>(new ge).accumulate(Object.assign({},e,{timestamp:new Date,logger:e.logger||n.Logging.get()}));class ge{constructor(e){this.cache=new o.ObjectAccumulator,Object.defineProperty(this,"cache",{value:e?e.cache:new o.ObjectAccumulator,writable:!1,enumerable:!1,configurable:!0})}static{this.factory=he}accumulate(e){return Object.defineProperty(this,"cache",{value:this.cache.accumulate(e),writable:!1,enumerable:!1,configurable:!0}),this}get logger(){return this.cache.logger}get timestamp(){return this.cache.timestamp}get(e){try{return this.cache.get(e)}catch(t){const r=this.cache.parentContext;if(r)return r.get(e);throw t}}static childFrom(e,t){return ge.factory(Object.assign({},e.cache,t||{}))}static async from(e,t,r,...a){return ge.factory(Object.assign({},ye,t,{operation:e,model:r,logger:t.logger||n.Logging.get()}))}static async args(e,t,r,a,o){const n=r.pop();async function s(){return a?a.context(e,o||{},t,...r):ge.from(e,o||{},t,...r)}let i;return n?n instanceof ge?(i=n,r.push(n)):(r.push(n),i=await s(),r.push(i)):(i=await s(),r.push(i)),{context:i,args:r}}}function Ee(e,t,r,a,o){const n=o||r.name;e[n]=new Proxy(e[n],{apply:async(e,r,o)=>{let n=t.call(r,...o);n instanceof Promise&&(n=await n);const s=n[n.length-1];if(!(s instanceof ge))throw new M("Missing a context");let i=e.call(r,...n);return i instanceof Promise&&(i=await i),i=a.call(r,i,s),i instanceof Promise&&(i=await i),i}})}function Oe(e,t,r,o,n){const s=n||r.name;e[s]=new Proxy(e[s],{apply:async(e,r,n)=>{let s=t.call(r,...n);s instanceof Promise&&(s=await s);const i=s.pop(),c=s[s.length-1];if(!(c instanceof ge))throw new M("Missing a context");if(c.get("applyUpdateValidation")&&!c.get("ignoreDevSafeGuards")&&!(i instanceof a.Model)&&(!Array.isArray(i)||!i.every(e=>e instanceof a.Model)))throw new M("No previous versions os models found");let l=e.call(r,...s);return l instanceof Promise&&(l=await l),l=o.call(r,l,i,c),l instanceof Promise&&(l=await l),l}})}const me="##VERSION##",Ae="##PACKAGE##";t.Metadata.registerLibrary(Ae,me),e.BadRequestError=A,e.BaseError=O,e.BlockOperationIf=t=>_(e.OperationKeys.REFLECT+e.OperationKeys.BLOCK,(e,r,a)=>((e,t,r,a)=>e.length>2||"crud"!==r?e(t,r,a):e(t.filter(e=>"crud"===e.kind).map(e=>e.value),a))(t,e,r,a))(),e.BlockOperations=t=>{const r=L(t);return _(e.OperationKeys.REFLECT+e.OperationKeys.BLOCK,(t,r,a)=>t.some(t=>((t,r,a)=>t.kind===r&&("bulk"===t.kind&&t.value===e.BulkOperationBlockTarget.ALL||t.value===a))(t,r,a)))(r)},e.BreakError=m,e.COMMIT="0aed09a",e.ConflictError=P,e.Context=ge,e.DBKeys=s,e.DBOperations=h,e.DEFAULT_ERROR_MESSAGES=l,e.DEFAULT_TIMESTAMP_FORMAT=c,e.DefaultContextFactory=he,e.DefaultRepositoryFlags=ye,e.DefaultSeparator=i,e.FULL_VERSION="0.17.1-0aed09a",e.InternalError=M,e.NotFoundError=D,e.Operations=E,e.OperationsRegistry=g,e.PACKAGE_NAME=Ae,e.Repository=class{get class(){if(!this._class)throw new M("No class definition found for this repository");return this._class}get pk(){return a.Model.pk(this.class)}get pkProps(){return a.Model.pkProps(this.class)}constructor(e){e&&(this._class=e);const t=this;[this.create,this.read,this.delete].forEach(e=>{const r=e.name;Ee(t,t[r+"Prefix"],e,t[r+"Suffix"])}),Oe(t,t[this.update.name+"Prefix"],this.update,t[this.update.name+"Suffix"])}async createAll(e,...t){return Promise.all(e.map(e=>this.create(e,...t)))}async createPrefix(t,...r){const a=await ge.args(e.OperationKeys.CREATE,this.class,r);if(t=new this.class(t),a.context.get("ignoreHandlers")||await ue(this,a.context,t,e.OperationKeys.CREATE,e.OperationKeys.ON),!a.context.get("ignoreValidation")){const e=await Promise.resolve(t.hasErrors());if(e)throw new T(e.toString())}return[t,...a.args]}async createSuffix(t,r){return r.get("ignoreHandlers")||await ue(this,r,t,e.OperationKeys.CREATE,e.OperationKeys.AFTER),t}async createAllPrefix(t,...r){const a=await ge.args(e.OperationKeys.CREATE,this.class,r),o=a.context.get("ignoreHandlers"),n=a.context.get("ignoreValidation");if(t=await Promise.all(t.map(async t=>{const r=new this.class(t);return o||await ue(this,a.context,r,e.OperationKeys.CREATE,e.OperationKeys.ON),r})),!n){const e=pe(await Promise.all(t.map(e=>Promise.resolve(e.hasErrors()))));if(e)throw new T(e)}return[t,...a.args]}async createAllSuffix(t,r){return r.get("ignoreHandlers")||await Promise.all(t.map(t=>ue(this,r,t,e.OperationKeys.CREATE,e.OperationKeys.AFTER))),t}async readAll(e,...t){return await Promise.all(e.map(e=>this.read(e,...t)))}async readSuffix(t,r){return r.get("ignoreHandlers")||await ue(this,r,t,e.OperationKeys.READ,e.OperationKeys.AFTER),t}async readPrefix(t,...r){const a=await ge.args(e.OperationKeys.READ,this.class,r),o=new this.class;return o[this.pk]=t,await ue(this,a.context,o,e.OperationKeys.READ,e.OperationKeys.ON),[t,...a.args]}async readAllPrefix(t,...r){const a=await ge.args(e.OperationKeys.READ,this.class,r);return await Promise.all(t.map(async t=>{const r=new this.class;return r[this.pk]=t,ue(this,a.context,r,e.OperationKeys.READ,e.OperationKeys.ON)})),[t,...a.args]}async readAllSuffix(t,r){return r.get("ignoreHandlers")||await Promise.all(t.map(t=>ue(this,r,t,e.OperationKeys.READ,e.OperationKeys.AFTER))),t}async updateAll(e,...t){return Promise.all(e.map(e=>this.update(e,...t)))}async updateSuffix(t,r,a){return a.get("ignoreHandlers")||await ue(this,a,t,e.OperationKeys.UPDATE,e.OperationKeys.AFTER,r),t}async updatePrefix(t,...r){const o=await ge.args(e.OperationKeys.UPDATE,this.class,r),n=o.context,s=o.context.get("ignoreHandlers"),i=o.context.get("ignoreValidation"),c=t[this.pk];if(!c)throw new M("No value for the Id is defined under the property "+this.pk);let l;if(n.get("applyUpdateValidation")&&(l=await this.read(c),n.get("mergeForUpdate")&&(t=a.Model.merge(l,t,this.class))),s||await ue(this,o.context,t,e.OperationKeys.UPDATE,e.OperationKeys.ON,l),!i){const e=await Promise.resolve(t.hasErrors(l));if(e)throw new T(e.toString())}return[t,...o.args,l]}async updateAllPrefix(t,...r){const o=await ge.args(e.OperationKeys.UPDATE,this.class,r),n=o.context,s=n.get("ignoreHandlers"),i=n.get("ignoreValidation"),c=t.map(e=>{const t=e[this.pk];if(void 0===t)throw new M("No value for the Id is defined under the property "+this.pk);return t});let l;if(n.get("applyUpdateValidation")&&(l=await this.readAll(c,n),n.get("mergeForUpdate")&&(t=t.map((e,t)=>a.Model.merge(l[t],e,this.class)))),s||await Promise.all(t.map((t,r)=>ue(this,o.context,t,e.OperationKeys.UPDATE,e.OperationKeys.ON,l?l[r]:void 0))),!i){let e;e=n.get("applyUpdateValidation")?await Promise.all(t.map((e,t)=>Promise.resolve(e.hasErrors(l[t])))):await Promise.resolve(t.map(e=>e.hasErrors()));const r=pe(e);if(r)throw new T(r)}return[t,...o.args,l]}async updateAllSuffix(t,r,a){if(a.get("applyUpdateValidation")&&!a.get("ignoreDevSafeGuards")&&!r)throw new M("No previous versions of models provided");return a.get("ignoreHandlers")||await Promise.all(t.map((t,o)=>ue(this,a,t,e.OperationKeys.UPDATE,e.OperationKeys.AFTER,r?r[o]:void 0))),t}async deleteAll(e,...t){return Promise.all(e.map(e=>this.delete(e,...t)))}async deleteSuffix(t,r){return r.get("ignoreHandlers")||await ue(this,r,t,e.OperationKeys.DELETE,e.OperationKeys.AFTER),t}async deletePrefix(t,...r){const a=await ge.args(e.OperationKeys.DELETE,this.class,r),o=await this.read(t,...a.args);return await ue(this,a.context,o,e.OperationKeys.DELETE,e.OperationKeys.ON),[t,...a.args]}async deleteAllPrefix(t,...r){const a=await ge.args(e.OperationKeys.DELETE,this.class,r),o=await this.readAll(t,...a.args);return await Promise.all(o.map(async t=>ue(this,a.context,t,e.OperationKeys.DELETE,e.OperationKeys.ON))),[t,...a.args]}async deleteAllSuffix(t,r){return r.get("ignoreHandlers")||await Promise.all(t.map(t=>ue(this,r,t,e.OperationKeys.DELETE,e.OperationKeys.AFTER))),t}toString(){return this.class.name+" Repository"}},e.SerializationError=w,e.UpdateValidationKeys=d,e.UpdateValidator=p,e.VERSION=me,e.ValidationError=T,e.after=F,e.afterAny=(e,t,r)=>F(h.ALL,e,t,r),e.afterCreate=(e,t,r)=>F(h.CREATE,e,t,r),e.afterCreateUpdate=(e,t,r)=>F(h.CREATE_UPDATE,e,t,r),e.afterDelete=(e,t,r)=>F(h.DELETE,e,t,r),e.afterRead=(e,t,r)=>F(h.READ,e,t,r),e.afterUpdate=(e,t,r)=>F(h.UPDATE,e,t,r),e.composeAttributeValue=G,e.composed=Q,e.composedFromCreateUpdate=Y,e.composedFromKeys=J,e.enforceDBDecorators=ue,e.generated=B,e.getDbDecorators=fe,e.getHandlerArgs=K,e.getHandlersDecorators=I,e.getValidatableUpdateProps=ie,e.groupDecorators=N,e.hash=z,e.hashOnCreateUpdate=$,e.id=()=>t.apply(a.required(),ee(),(e,r)=>t.propMetadata(t.Metadata.key(s.ID,r),{})(e,r)),e.on=V,e.onAny=(e,t,r)=>V(h.ALL,e,t,r),e.onCreate=j,e.onCreateUpdate=x,e.onDelete=(e,t,r)=>V(h.DELETE,e,t,r),e.onRead=(e,t,r)=>V(h.READ,e,t,r),e.onUpdate=U,e.operation=H,e.prefixMethod=(e,t,r,a)=>{const o=a||t.name;e[o]=new Proxy(e[o],{apply:async(e,t,a)=>{let o=r.call(t,...a);return o instanceof Promise&&(o=await o),o=e.call(t,...o),o instanceof Promise&&(o=await o),o}})},e.readonly=ee,e.reduceErrorsToPrint=pe,e.serialize=e=>(r,o)=>t.apply(x(re,{serializer:e}),F(h.ALL,ae,{serializer:e}),a.type([String,Object]),t.propMetadata(t.Metadata.key(s.SERIALIZE,o),{serializer:e}))(r,o),e.serializeAfterAll=ae,e.serializeOnCreateUpdate=re,e.sortDecorators=C,e.storeHandlerMetadata=_,e.suffixMethod=(e,t,r,a)=>{const o=a||t.name;e[o]=new Proxy(e[o],{apply:async(e,t,a)=>{let o=e.call(t,...a);return o instanceof Promise&&(o=await o),o=r.call(t,...o),o instanceof Promise&&(o=await o),o}})},e.timestamp=(r=h.CREATE_UPDATE,o=c)=>{const n=s.TIMESTAMP,i=a.Validation.updateKey(s.TIMESTAMP);return t.Decoration.for(n).define({decorator:(r,o)=>{const n=[B(s.TIMESTAMP),a.date(o,l.TIMESTAMP.DATE),a.required(l.TIMESTAMP.REQUIRED),t.propMetadata(a.Validation.key(s.TIMESTAMP),{operation:r,format:o}),V(r,te)];return-1!==r.indexOf(e.OperationKeys.UPDATE)?n.push(t.propMetadata(i,{message:l.TIMESTAMP.INVALID})):n.push(ee()),t.apply(...n)},args:[r,o]}).apply()},e.timestampHandler=te,e.transient=X,e.validateCompare=de,e.validateDecorator=ce,e.validateDecorators=le,e.version=Z,e.versionCreateUpdate=W,e.wrapMethodWithContext=Ee,e.wrapMethodWithContextForUpdate=Oe},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@decaf-ts/decoration"),require("tslib"),require("@decaf-ts/decorator-validation"),require("typed-object-accumulator"),require("@decaf-ts/logging")):"function"==typeof define&&define.amd?define(["exports","@decaf-ts/decoration","tslib","@decaf-ts/decorator-validation","typed-object-accumulator","@decaf-ts/logging"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["db-decorators"]={},e.decafTsDecoration,e.tslib,e.decafTsDecoratorValidation,e.typedObjectAccumulator,e.decafTsLogging);
|
|
1
|
+
var e,t;e=this,t=function(e,t,r,a,o,n){"use strict";const s={REFLECT:a.ModelKeys.MODEL+".persistence.",REPOSITORY:"repository",CLASS:"_class",ID:"id",INDEX:"index",UNIQUE:"unique",SERIALIZE:"serialize",READONLY:"readonly",TIMESTAMP:"timestamp",TRANSIENT:"transient",HASH:"hash",COMPOSED:"composed",GENERATED:"generated",VERSION:"version",ORIGINAL:"__originalObj"},i="_",c="dd/MM/yyyy HH:mm:ss:S",l={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"}},d={REFLECT:"db.update.validation.",TIMESTAMP:s.TIMESTAMP,READONLY:s.READONLY};e.ReadOnlyValidator=class extends a.Validator{constructor(){super(l.READONLY.INVALID)}hasErrors(e,...t){}updateHasErrors(e,t,r){if(void 0!==e)return a.isEqual(e,t)?void 0:this.getMessage(r||this.message)}},e.ReadOnlyValidator=r.__decorate([a.validator(d.READONLY),r.__metadata("design:paramtypes",[])],e.ReadOnlyValidator),e.TimestampValidator=class extends a.Validator{constructor(){super(l.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?void 0:r}}},e.TimestampValidator=r.__decorate([a.validator(d.TIMESTAMP),r.__metadata("design:paramtypes",[])],e.TimestampValidator);class p extends a.Validator{constructor(e=a.DEFAULT_ERROR_MESSAGES.DEFAULT,...t){super(e,...t)}}var u,f,y;a.Validation.updateKey=e=>d.REFLECT+e,e.OperationKeys=void 0,(u=e.OperationKeys||(e.OperationKeys={})).REFLECT="decaf.model.db.operations.",u.CREATE="create",u.READ="read",u.UPDATE="update",u.DELETE="delete",u.ON="on.",u.AFTER="after.",u.BLOCK="block",e.ModelOperations=void 0,(f=e.ModelOperations||(e.ModelOperations={})).OPERATIONS="operations",f.RELATIONS="relations",e.BulkCrudOperationKeys=void 0,(y=e.BulkCrudOperationKeys||(e.BulkCrudOperationKeys={})).CREATE_ALL="createAll",y.READ_ALL="readAll",y.UPDATE_ALL="updateAll",y.DELETE_ALL="deleteAll",e.BulkOperationBlockTarget=void 0,(e.BulkOperationBlockTarget||(e.BulkOperationBlockTarget={})).ALL="bulkAll";const h={CREATE:[e.OperationKeys.CREATE],READ:[e.OperationKeys.READ],UPDATE:[e.OperationKeys.UPDATE],DELETE:[e.OperationKeys.DELETE],CREATE_UPDATE:[e.OperationKeys.CREATE,e.OperationKeys.UPDATE],READ_CREATE:[e.OperationKeys.READ,e.OperationKeys.CREATE],ALL:[e.OperationKeys.CREATE,e.OperationKeys.READ,e.OperationKeys.UPDATE,e.OperationKeys.DELETE]};class g{constructor(){this.cache={}}get(e,t,r,a){a=a||[];const o=this.resolveOwner(e),n=this.resolveTargetName(e,o);if(n){const e=this.selectHandlers(n,t,r,o);e?.length&&a.unshift(...e)}else if("string"==typeof e||e===Object.prototype||Object.getPrototypeOf(e)===Object.prototype)return a;let s=Object.getPrototypeOf(e);return s?(s.constructor&&s.constructor.name===n&&(s=Object.getPrototypeOf(s)),s?this.get(s,t,r,a):a):a}register(e,t,r,a){const o=r.constructor.name,n=g.getHandlerName(e),s=this.resolveFlavour(r.constructor);this.cache[o]||(this.cache[o]={}),this.cache[o][a]||(this.cache[o][a]={}),this.cache[o][a][t]||(this.cache[o][a][t]={}),this.cache[o][a][t][s]||(this.cache[o][a][t][s]={}),this.cache[o][a][t][s][n]||(this.cache[o][a][t][s][n]=e)}resolveOwner(e){if(e&&"string"!=typeof e)return"function"==typeof e?e:e.constructor}resolveTargetName(e,t){return"string"==typeof e?e:t?.name}resolveFlavour(e){if(!e)return t.Decoration.defaultFlavour;try{return t.Metadata.flavourOf(e)}catch{return t.Decoration.defaultFlavour}}selectHandlers(e,r,a,o){const n=this.cache[e]?.[r]?.[a];if(!n)return;const s=n[this.resolveFlavour(o)]||n[t.Decoration.defaultFlavour]||this.firstBucket(n);if(!s)return;const i=Object.values(s);return i.length?i:void 0}firstBucket(e){for(const t of Object.values(e))if(t&&Object.keys(t).length)return t}static getHandlerName(e){return e.name?e.name:a.Hashing.hash(e.toString())}}class E{constructor(){}static getHandlerName(e){return g.getHandlerName(e)}static key(t){return e.OperationKeys.REFLECT+t}static get(e,t,r){return E.registry.get(e,t,r)}static getOpRegistry(){return E.registry||(E.registry=new g),E.registry}static register(e,t,r,a){E.getOpRegistry().register(e,t,r,a)}}class O extends Error{constructor(e,t,r){if(t instanceof O)return t;super(`[${e}][${r}] ${t instanceof Error?t.message:t}`),this.code=r,t instanceof Error&&(this.stack=t.stack)}get message(){return`[${this.name}] ${this.code} | ${super.message.replaceAll(/\[.*?Error\]\[\d+\]\s/g,"")}`}toString(){return this.message}}class m extends O{constructor(e,t=m.name,r=999){super(t,e,r)}}class A extends O{constructor(e,t=A.name,r=400){super(t,e,r)}}class T extends A{constructor(e){super(e,T.name,422)}}class M extends O{constructor(e,t=M.name,r=500){super(t,e,r)}}class w extends M{constructor(e){super(e,w.name,500)}}class D extends A{constructor(e){super(e,D.name,404)}}class P extends A{constructor(e){super(e,P.name,409)}}const v={priority:50},R=new Set([e.OperationKeys.CREATE,e.OperationKeys.READ,e.OperationKeys.UPDATE,e.OperationKeys.DELETE]),b=new Set(Object.values(e.BulkCrudOperationKeys));function S(t){return b.has(t)||t===e.BulkOperationBlockTarget.ALL?"bulk":(R.has(t),"crud")}function k(e){return"object"==typeof e&&null!==e&&Object.prototype.hasOwnProperty.call(e,"kind")&&"string"==typeof e.kind}function L(t){const r=Array.isArray(t)?t:[t],a=[];for(const t of r)if(Array.isArray(t))a.push(...L(t));else{if("string"==typeof t){const r=S(t),o=("bulk"===r&&e.BulkOperationBlockTarget.ALL,t);a.push({kind:r,value:o});continue}k(t)&&a.push(t)}return a}const K=(e,t,r,a)=>{const o=r.constructor.name;if(!o)throw new M("Could not determine model class");a=a||{},e.props.handlers[o]&&e.props.handlers[o][t]&&(a={...e.props.handlers[o][t],...a});let n=Object.getPrototypeOf(r);return n===Object.prototype?a:(n.constructor.name===o&&(n=Object.getPrototypeOf(n)),K(e,t,n,a))};function I(e,t,r){const a=[];for(const o in t){const n=t[o];for(const t of n){const{key:n}=t,s=E.get(e,o,r+n);if(!s||!s.length)throw new M(`Could not find registered handler for the operation ${r+n} under property ${o}`);const i=K(t,o,e);if(!i)throw new M("Missing handler arguments for decorators");for(const e of s){const t=E.getHandlerName(e),r=i[t];if(!r)throw new M("Missing handler arguments for handler "+t);const n=r.data;a.push({handler:e,data:[n],prop:[o]})}}}return a}function N(e){const t=e.reduce((e,t)=>{if(!t||!t.data||!t.prop)throw new M("Missing decorator properties or data");if(!t.data[0].group)return e.set(Symbol(),t),e;const r=t.data[0].group;if(e.has(r)){const a=e.get(r);e.set(r,{handler:a.handler,data:[...a.data,...t.data],prop:[...a.prop,...t.prop]})}else e.set(r,{...t});return e},new Map),r=Array.from(t.values());return r.forEach(e=>{const t=e.data.map((t,r)=>({data:t,prop:e.prop[r]}));t.sort((e,t)=>(e.data.groupPriority??50)-(t.data.groupPriority??50)),e.data=t.map(e=>e.data),e.prop=t.map(e=>e.prop)}),r}function C(e){return e.sort((e,t)=>(e.data[0].priority??50)-(t.data[0].priority??50)),e}function x(e,t,r){return V(h.CREATE_UPDATE,e,t,r)}function U(e,t,r){return V(h.UPDATE,e,t,r)}function j(e,t,r){return V(h.CREATE,e,t,r)}function V(t=h.ALL,r,a,o){return H(e.OperationKeys.ON,t,r,a,o)}function F(t=h.ALL,r,a,o){return H(e.OperationKeys.AFTER,t,r,a,o)}function H(r,a=h.ALL,o,n,s=v){return(i,c)=>{const l=i.constructor.name,d=a.reduce((a,d)=>{const p=r+d;let u=t.Metadata.readOperation(i.constructor,c,p);u||(u={operation:d,handlers:{}});const f=E.getHandlerName(o);let y=s;if(n){if(Object.keys(n).filter(e=>e in s).length>0)throw new M("Unable to merge groupSort into dataToAdd due to overlaping keys");y={...s,...n}}return u.handlers[l]&&u.handlers[l][c]&&f in u.handlers[l][c]||(u.handlers[l]=u.handlers[l]||{},u.handlers[l][c]=u.handlers[l][c]||{},u.handlers[l][c][f]={data:y},a.push(((e,t)=>(r,a)=>{E.register(t,e,r,a)})(p,o),t.propMetadata(t.Metadata.key(e.ModelOperations.OPERATIONS,c,p),u))),a},[]);return t.apply(...d)(i,c)}}function _(e,r){return(...a)=>t.metadata(e,{args:a,handler:r})}function B(e){return(r,a)=>t.propMetadata(t.Metadata.key(s.GENERATED,a),e||!0)(r,a)}function $(e,t,r,o,n){if(void 0===o[r])return;const s=a.Hashing.hash(o[r]);n&&o[r]===s||(o[r]=s)}function z(){return t.apply(x($),t.propMetadata(s.HASH,{}))}function G(e,t){const{args:r,type:o,prefix:n,suffix:s,separator:i,filterEmpty:c,hashResult:l}=t;try{const t=r.map(t=>{if("keys"===o)return t;if(void 0===e[t]){if(c){if(!Array.isArray(c))return;if(c.includes(t))return}throw new M(`Property ${r} does not contain a value to compose from`)}return e[t].toString()}).filter(e=>!c||!!e);n&&t.unshift(n),s&&t.push(s);const d=t.map(e=>"object"==typeof e&&"[object Object]"===e.toString()?JSON.stringify(e):e).join(i);return l?a.Hashing.hash(d):d}catch(e){throw new M("Failed to compose value: "+e)}}function Y(e,t,r,a){a[r]=G(a,t)}function q(e,r=!1,a=i,o=!1,n="values",c="",l="",d={priority:55}){return t.Decoration.for(s.COMPOSED).define({decorator:(e,r,a,n,i,c,l)=>(d,p)=>{const u={args:e,hashResult:r,separator:a,type:n,prefix:i,suffix:c,filterEmpty:o},f=[B(s.COMPOSED),x(Y,u,l),t.propMetadata(t.Metadata.key(s.COMPOSED,p),u)];return r&&f.push(z()),t.apply(...f)(d,p)},args:[e,r,a,n,c,l,d]}).apply()}function J(e,t=i,r=!1,a=!1,o="",n="",s={priority:55}){return q(e,a,t,r,"keys",o,n,s)}function Q(e,t=i,r=!1,a=!1,o="",n="",s={priority:55}){return q(e,a,t,r,"values",o,n,s)}function W(t){return(r,o,n,s,i)=>{if(a.Model.shouldGenerate(s,n,r))try{switch(t){case e.OperationKeys.CREATE:s[n]=1;break;case e.OperationKeys.UPDATE:if(r.get("applyUpdateValidation")&&i&&s[n]!==i[n])throw new T(`Version mismatch: ${s[n]} !== ${i[n]}`);s[n]++;break;default:throw new M("Invalid operation: "+t)}}catch(e){throw new M("Failed to update version: "+e)}}}function Z(){const r=s.VERSION;return(o,n)=>t.Decoration.for(r).define(t.propMetadata(t.Metadata.key(r,n),!0),B(s.VERSION),a.type(Number),j(W(e.OperationKeys.CREATE)),U(W(e.OperationKeys.UPDATE))).apply()(o,n)}function X(){return t.Decoration.for(s.TRANSIENT).define((e,r)=>{t.propMetadata(t.Metadata.key(s.TRANSIENT,r),{})(e,r)}).apply()}function ee(e=l.READONLY.INVALID){const r=s.READONLY,o={message:e,description:"defines the attribute as readOnly",async:!1};return t.Decoration.for(r).define({decorator:a.innerValidationDecorator,args:[ee,r,o]}).apply()}async function te(e,t,r,o){a.Model.shouldGenerate(o,r,e)&&(o[r]=e.timestamp)}async function re(e,t,r,a){if(a[r])try{a[r]=t.serializer?(new t.serializer).serialize(a[r]):JSON.stringify(a[r])}catch(e){throw new w(`Failed to serialize ${r.toString()} property of model ${a.constructor.name}: ${e}`)}}async function ae(e,t,r,a){if(a[r]&&"string"==typeof a[r])try{a[r]=t.serializer?(new t.serializer).deserialize(a[r]):JSON.parse(a[r])}catch(e){throw new w(`Failed to deserialize ${r.toString()} property of model ${a.constructor.name}: ${e}`)}}a.Model.prototype.isTransient=function(){return t.Metadata.isTransient(this)},a.Model.prototype.hasErrors=function(e,...t){!e||e instanceof a.Model||(t.unshift(e),e=void 0);const r=this.isAsync(),o=a.validate(this,r,...t);return r?Promise.resolve(o).then(a=>a||!e?a:de(e,this,r,...t)):o||!e?o:de(e,this,r,...t)},a.Model.prototype.segregate=function(){return a.Model.segregate(this)},a.Model.segregate=e=>{if(!t.Metadata.isTransient(e))return{model:e};const r=t.Metadata.validatableProperties(e.constructor),o=t.Metadata.get(e.constructor,s.TRANSIENT),n={model:{},transient:{}};for(const t of r)if(Object.keys(o).includes(t)){n.transient=n.transient||{};try{n.transient[t]=e[t]}catch(e){throw new w(`Failed to serialize transient property ${t}: ${e}`)}}else n.model=n.model||{},n.model[t]=e[t];return n.model=a.Model.build(n.model,e.constructor.name),n},t.Metadata.pk=((e,r=!1)=>{if(!e)throw Error("No model was provided");const o=e instanceof a.Model?e.constructor:e,n=t.Metadata.get(o,s.ID);if(!n)throw Error("No Id property defined for model "+(o?.name||"Unknown Model"));const i=Object.keys(n)[0];if(!r)return i;if(e instanceof a.Model)return e[i];throw Error("Cannot get the value of the pk from the constructor")}).bind(t.Metadata),a.Model.pk=((e,r=!1)=>t.Metadata.pk(e,r)).bind(a.Model),a.Model.pkProps=(e=>t.Metadata.get(e,t.Metadata.key(s.ID,a.Model.pk(e)))).bind(a.Model),a.Model.isTransient=(e=>!!t.Metadata.get("function"!=typeof e?e.constructor:e,s.TRANSIENT)).bind(a.Model),a.Model.composed=((e,r)=>{const o=e instanceof a.Model?e.constructor:e;return r?t.Metadata.get(o,t.Metadata.key(s.COMPOSED,r)):!!t.Metadata.get(o,s.COMPOSED)}).bind(a.Model),a.Model.merge=((e,t,r)=>{const a=e=>Object.entries(e).reduce((e,[t,r])=>(null!=r&&(e[t]=r),e),{});return new(r=r||e.constructor)(Object.assign({},a(e),a(t)))}).bind(a.Model),t.Metadata.saveOperation=((r,a,o,n)=>{a&&t.Metadata.set(r,t.Metadata.key(e.ModelOperations.OPERATIONS,a,o),n)}).bind(t.Metadata),t.Metadata.readOperation=((r,a,o)=>{if(a&&o)return t.Metadata.get(r,t.Metadata.key(e.ModelOperations.OPERATIONS,a,o))}).bind(t.Metadata),t.Metadata.isTransient=(e=>!!t.Metadata.get("function"!=typeof e?e.constructor:e,s.TRANSIENT)).bind(t.Metadata),a.Model.generated=((e,r)=>!!t.Metadata.get("function"!=typeof e?e.constructor:e,t.Metadata.key(s.GENERATED,r))).bind(a.Model),a.Model.shouldGenerate=((e,t,r)=>!r.get("allowGenerationOverride")||void 0===e[t]).bind(a.Model),a.Model.versionProp=(e=>{const r=t.Metadata.get(e.constructor);if(!r||!r[s.VERSION])throw new M("No version found for "+e.constructor.name);return Object.keys(r)[0]}).bind(a.Model),a.Model.versionOf=(e=>{const t=e[a.Model.versionProp(e)];if("number"!=typeof t||1>t)throw new M("Invalid version number: "+t);return t}).bind(a.Model),a.Model.propSerializedBy=((e,r)=>t.Metadata.get("function"!=typeof e?e.constructor:e,t.Metadata.key(s.SERIALIZE,r))).bind(a.Model),a.Model.isPropSerialized=((e,t)=>!!a.Model.propSerializedBy(e,t)).bind(a.Model);const oe=a.ModelBuilder.prototype;oe.decorateClass||(oe.decorateClass=function(e){return this._classDecorators||(this._classDecorators=[]),this._classDecorators.push(e),this});const ne=(e,t,r)=>(((e,t)=>{const r=e.attributes;return r?.has(t)?r.get(t):e.attribute(t,Object)})(e,t).decorate(r),e);function se(e,t,r){if("string"!=typeof r)return r;if(!a.Model.isPropSerialized(e,t))return r;try{const e=JSON.parse(r);if(Array.isArray(e))return e}catch{}return r}function ie(e,r){const a=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o)||r.includes(o))continue;const n=t.Metadata.validationFor(e.constructor,o)||{};a.push({prop:o,decorators:n})}return a}function ce(e,t,r,o,n,s,i){const c=a.Validation.get(o.key);if(!c)throw Error("Missing validator for "+o.key);if(!c.updateHasErrors)return a.toConditionalPromise(void 0,n);if(!n&&o.async)return a.toConditionalPromise(void 0,n);const l=Object.values(o)||{},d=c.updateHasErrors(void 0===s?e[r]:s,void 0===i?t[r]:i,...l);return a.toConditionalPromise(d,n)}function le(e,t,r,o,n,s,i){const c={};for(const l in o){const d={...o[l],key:l};if(!n&&d.async)continue;let p=ce(e,t,r,d,n,s,i);if(d.key===a.ValidationKeys.LIST&&(!p||n)){const e=s instanceof Set?[...s]:s,t=i instanceof Set?[...i]:i;if(e?.length){const r=[d.class||d.clazz||d.customTypes].flat().map(e=>((e=(e="function"!=typeof e||e.name?e:e()).name?e.name:e)+"").toLowerCase()),o=e.map(e=>{if(a.Model.isModel(e)){const r=a.Model.pk(e,!0);if(!r)return"Failed to find model id";const o=t.find(e=>r===a.Model.pk(e,!0));return e.hasErrors(o)}return r.includes(typeof e)?void 0:"Value has no validatable type"});if(n)p=Promise.all(o).then(e=>e.every(e=>!e)?void 0:e);else{const e=o.every(e=>!e);p=o.length>0&&!e?o:void 0}}}p&&(c[d.key]=p)}if(!n)return Object.keys(c).length>0?c:void 0;const l=Object.keys(c),d=Object.values(c);return Promise.all(d).then(e=>{const t={};for(let r=0;r<e.length;r++){const a=e[r];void 0!==a&&(t[l[r]]=a)}return Object.keys(t).length>0?t:void 0})}function de(e,r,o,...n){const s=ie(r,n),i={},c={};for(const{prop:l,decorators:d}of s){const s=l+"",p=se(r,l,r[l]),u=se(e,l,e[l]),{designTypes:f}=t.Metadata.getPropDesignTypes(r.constructor,l);if(!f)continue;if(f.some(e=>[Array.name,Set.name].includes(e))){if(!d||!Object.keys(d).includes(a.ValidationKeys.LIST)){i[s]={[a.ValidationKeys.TYPE]:`Array or Set property '${s}' requires a @list decorator`};continue}if(p&&!(Array.isArray(p)||p instanceof Set)){i[s]={[a.ValidationKeys.TYPE]:`Property '${l+""}' must be either an Array or a Set`};continue}}const y=le(r,e,s,d,o,p,u)||{},h=a.Model.isPropertyModel(r,s);if(null!=p&&h){const t=p,r=f.map(e=>a.Model.get(e.name||e)).find(e=>!!e),o=f.map(e=>"function"==typeof e?e.name?e.name.toLowerCase():e()?.name.toLowerCase():e.toLowerCase());if(r&&p instanceof r){const r=a.getChildNestedPropsToIgnore(s,...n);c[s]=t.hasErrors(e[l],...r)}else o.includes(typeof p)||(y[a.ValidationKeys.TYPE]=r?"Value must be an instance of "+r.name:`Unable to verify type consistency, missing model registry for ${f.toString()} on prop ${s}`,delete y[a.ModelKeys.TYPE])}(Object.keys(y).length>0||o)&&(i[s]=y),o||Object.entries(c[s]||{}).forEach(([e,t])=>{void 0!==t&&(i[`${s}.${e}`]=t)})}if(!o)return Object.keys(i).length>0?new a.ModelErrorDefinition(i):void 0;const l=i,d=Object.keys(l),p=Object.values(l);return Promise.allSettled(p).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=d[r],o=e[r];"fulfilled"===o.status&&void 0!==o.value?t[a]=o.value:"rejected"===o.status&&(t[a]=o.reason instanceof Error?o.reason.message:(o.reason||"Validation failed")+"")}return Object.keys(t).length>0?new a.ModelErrorDefinition(t):void 0})}function pe(e){return e.reduce((e,t,r)=>(t&&(e="string"==typeof e?e+`\n - ${r}: ${t.toString()}`:` - ${r}: ${t.toString()}`),e),void 0)}async function ue(t,r,a,o,n,s){const i=fe(a,o,n);if(!i)return;const c=C(N(I(a,i,n)));for(const n of c){const i=[r,n.data.length>1?n.data:n.data[0],n.prop.length>1?n.prop:n.prop[0],a];if([e.OperationKeys.UPDATE,e.BulkCrudOperationKeys.UPDATE_ALL].includes(o)){if(!s)throw new M("Missing old model for update operation");i.push(s)}try{await n.handler.apply(t,i)}catch(e){if(r.logger.for(ue).error(`Failed to execute handler ${n.handler.name} for ${n.prop} on ${a.constructor.name}`),r.get("breakOnHandlerError"))throw e}}}function fe(r,a,o){const n=o?.replace(/[.]$/,""),s=t.Metadata.get(r.constructor,e.ModelOperations.OPERATIONS);if(s)return Object.keys(s).reduce((e,t)=>{const r=n?s[t][n]||{}:s[t],o=Object.keys(r).filter(e=>e===a),i=[];for(const e of o)i.push({key:e,props:r[e]});return i&&i.length&&(e||(e={}),e[t]=i),e},void 0)}oe.generated=function(e,t){return ne(this,e,B(t))},oe.hash=function(e){return ne(this,e,z())},oe.composedFromKeys=function(e,t,r,a,o,n,s,i){return ne(this,e,J(t,r,a,o,n,s,i))},oe.composed=function(e,t,r,a,o,n,s,i){return ne(this,e,Q(t,r,a,o,n,s,i))},oe.version=function(e){return ne(this,e,Z())},oe.transient=function(e){return ne(this,e,X())};const ye={parentContext:void 0,childContexts:[],ignoredValidationProperties:[],callArgs:[],writeOperation:!1,affectedTables:[],operation:void 0,breakOnHandlerError:!0,rebuildWithTransient:!0,ignoreValidation:!1,ignoreHandlers:!1,ignoreDevSafeGuards:!1,mergeForUpdate:!0,applyUpdateValidation:!0,allowGenerationOverride:!1},he=e=>(new ge).accumulate(Object.assign({},e,{timestamp:new Date,logger:e.logger||n.Logging.get()}));class ge{constructor(e){this.cache=new o.ObjectAccumulator,Object.defineProperty(this,"cache",{value:e?e.cache:new o.ObjectAccumulator,writable:!1,enumerable:!1,configurable:!0})}static{this.factory=he}accumulate(e){return Object.defineProperty(this,"cache",{value:this.cache.accumulate(e),writable:!1,enumerable:!1,configurable:!0}),this}get logger(){return this.cache.logger}get timestamp(){return this.cache.timestamp}get(e){try{return this.cache.get(e)}catch(t){const r=this.cache.parentContext;if(r)return r.get(e);throw t}}static childFrom(e,t){return ge.factory(Object.assign({},e.cache,t||{}))}static async from(e,t,r,...a){return ge.factory(Object.assign({},ye,t,{operation:e,model:r,logger:t.logger||n.Logging.get()}))}static async args(e,t,r,a,o){const n=r.pop();async function s(){return a?a.context(e,o||{},t,...r):ge.from(e,o||{},t,...r)}let i;return n?n instanceof ge?(i=n,r.push(n)):(r.push(n),i=await s(),r.push(i)):(i=await s(),r.push(i)),{context:i,args:r}}}function Ee(e,t,r,a,o){const n=o||r.name;e[n]=new Proxy(e[n],{apply:async(e,r,o)=>{let n=t.call(r,...o);n instanceof Promise&&(n=await n);const s=n[n.length-1];if(!(s instanceof ge))throw new M("Missing a context");let i=e.call(r,...n);return i instanceof Promise&&(i=await i),i=a.call(r,i,s),i instanceof Promise&&(i=await i),i}})}function Oe(e,t,r,o,n){const s=n||r.name;e[s]=new Proxy(e[s],{apply:async(e,r,n)=>{let s=t.call(r,...n);s instanceof Promise&&(s=await s);const i=s.pop(),c=s[s.length-1];if(!(c instanceof ge))throw new M("Missing a context");if(c.get("applyUpdateValidation")&&!c.get("ignoreDevSafeGuards")&&!(i instanceof a.Model)&&(!Array.isArray(i)||!i.every(e=>e instanceof a.Model)))throw new M("No previous versions os models found");let l=e.call(r,...s);return l instanceof Promise&&(l=await l),l=o.call(r,l,i,c),l instanceof Promise&&(l=await l),l}})}const me="##VERSION##",Ae="##PACKAGE##";t.Metadata.registerLibrary(Ae,me),e.BadRequestError=A,e.BaseError=O,e.BlockOperationIf=t=>_(e.OperationKeys.REFLECT+e.OperationKeys.BLOCK,(e,r,a)=>((e,t,r,a)=>e.length>2||"crud"!==r?e(t,r,a):e(t.filter(e=>"crud"===e.kind).map(e=>e.value),a))(t,e,r,a))(),e.BlockOperations=t=>{const r=L(t);return _(e.OperationKeys.REFLECT+e.OperationKeys.BLOCK,(t,r,a)=>t.some(t=>((t,r,a)=>t.kind===r&&("bulk"===t.kind&&t.value===e.BulkOperationBlockTarget.ALL||t.value===a))(t,r,a)))(r)},e.BreakError=m,e.COMMIT="f86b26a",e.ConflictError=P,e.Context=ge,e.DBKeys=s,e.DBOperations=h,e.DEFAULT_ERROR_MESSAGES=l,e.DEFAULT_TIMESTAMP_FORMAT=c,e.DefaultContextFactory=he,e.DefaultRepositoryFlags=ye,e.DefaultSeparator=i,e.FULL_VERSION="0.17.2-f86b26a",e.InternalError=M,e.NotFoundError=D,e.Operations=E,e.OperationsRegistry=g,e.PACKAGE_NAME=Ae,e.Repository=class{get class(){if(!this._class)throw new M("No class definition found for this repository");return this._class}get pk(){return a.Model.pk(this.class)}get pkProps(){return a.Model.pkProps(this.class)}constructor(e){e&&(this._class=e);const t=this;[this.create,this.read,this.delete].forEach(e=>{const r=e.name;Ee(t,t[r+"Prefix"],e,t[r+"Suffix"])}),Oe(t,t[this.update.name+"Prefix"],this.update,t[this.update.name+"Suffix"])}async createAll(e,...t){return Promise.all(e.map(e=>this.create(e,...t)))}async createPrefix(t,...r){const a=await ge.args(e.OperationKeys.CREATE,this.class,r);if(t=new this.class(t),a.context.get("ignoreHandlers")||await ue(this,a.context,t,e.OperationKeys.CREATE,e.OperationKeys.ON),!a.context.get("ignoreValidation")){const e=await Promise.resolve(t.hasErrors());if(e)throw new T(e.toString())}return[t,...a.args]}async createSuffix(t,r){return r.get("ignoreHandlers")||await ue(this,r,t,e.OperationKeys.CREATE,e.OperationKeys.AFTER),t}async createAllPrefix(t,...r){const a=await ge.args(e.OperationKeys.CREATE,this.class,r),o=a.context.get("ignoreHandlers"),n=a.context.get("ignoreValidation");if(t=await Promise.all(t.map(async t=>{const r=new this.class(t);return o||await ue(this,a.context,r,e.OperationKeys.CREATE,e.OperationKeys.ON),r})),!n){const e=pe(await Promise.all(t.map(e=>Promise.resolve(e.hasErrors()))));if(e)throw new T(e)}return[t,...a.args]}async createAllSuffix(t,r){return r.get("ignoreHandlers")||await Promise.all(t.map(t=>ue(this,r,t,e.OperationKeys.CREATE,e.OperationKeys.AFTER))),t}async readAll(e,...t){return await Promise.all(e.map(e=>this.read(e,...t)))}async readSuffix(t,r){return r.get("ignoreHandlers")||await ue(this,r,t,e.OperationKeys.READ,e.OperationKeys.AFTER),t}async readPrefix(t,...r){const a=await ge.args(e.OperationKeys.READ,this.class,r),o=new this.class;return o[this.pk]=t,await ue(this,a.context,o,e.OperationKeys.READ,e.OperationKeys.ON),[t,...a.args]}async readAllPrefix(t,...r){const a=await ge.args(e.OperationKeys.READ,this.class,r);return await Promise.all(t.map(async t=>{const r=new this.class;return r[this.pk]=t,ue(this,a.context,r,e.OperationKeys.READ,e.OperationKeys.ON)})),[t,...a.args]}async readAllSuffix(t,r){return r.get("ignoreHandlers")||await Promise.all(t.map(t=>ue(this,r,t,e.OperationKeys.READ,e.OperationKeys.AFTER))),t}async updateAll(e,...t){return Promise.all(e.map(e=>this.update(e,...t)))}async updateSuffix(t,r,a){return a.get("ignoreHandlers")||await ue(this,a,t,e.OperationKeys.UPDATE,e.OperationKeys.AFTER,r),t}async updatePrefix(t,...r){const o=await ge.args(e.OperationKeys.UPDATE,this.class,r),n=o.context,s=o.context.get("ignoreHandlers"),i=o.context.get("ignoreValidation"),c=t[this.pk];if(!c)throw new M("No value for the Id is defined under the property "+this.pk);let l;if(n.get("applyUpdateValidation")&&(l=await this.read(c),n.get("mergeForUpdate")&&(t=a.Model.merge(l,t,this.class))),s||await ue(this,o.context,t,e.OperationKeys.UPDATE,e.OperationKeys.ON,l),!i){const e=await Promise.resolve(t.hasErrors(l));if(e)throw new T(e.toString())}return[t,...o.args,l]}async updateAllPrefix(t,...r){const o=await ge.args(e.OperationKeys.UPDATE,this.class,r),n=o.context,s=n.get("ignoreHandlers"),i=n.get("ignoreValidation"),c=t.map(e=>{const t=e[this.pk];if(void 0===t)throw new M("No value for the Id is defined under the property "+this.pk);return t});let l;if(n.get("applyUpdateValidation")&&(l=await this.readAll(c,n),n.get("mergeForUpdate")&&(t=t.map((e,t)=>a.Model.merge(l[t],e,this.class)))),s||await Promise.all(t.map((t,r)=>ue(this,o.context,t,e.OperationKeys.UPDATE,e.OperationKeys.ON,l?l[r]:void 0))),!i){let e;e=n.get("applyUpdateValidation")?await Promise.all(t.map((e,t)=>Promise.resolve(e.hasErrors(l[t])))):await Promise.resolve(t.map(e=>e.hasErrors()));const r=pe(e);if(r)throw new T(r)}return[t,...o.args,l]}async updateAllSuffix(t,r,a){if(a.get("applyUpdateValidation")&&!a.get("ignoreDevSafeGuards")&&!r)throw new M("No previous versions of models provided");return a.get("ignoreHandlers")||await Promise.all(t.map((t,o)=>ue(this,a,t,e.OperationKeys.UPDATE,e.OperationKeys.AFTER,r?r[o]:void 0))),t}async deleteAll(e,...t){return Promise.all(e.map(e=>this.delete(e,...t)))}async deleteSuffix(t,r){return r.get("ignoreHandlers")||await ue(this,r,t,e.OperationKeys.DELETE,e.OperationKeys.AFTER),t}async deletePrefix(t,...r){const a=await ge.args(e.OperationKeys.DELETE,this.class,r),o=await this.read(t,...a.args);return await ue(this,a.context,o,e.OperationKeys.DELETE,e.OperationKeys.ON),[t,...a.args]}async deleteAllPrefix(t,...r){const a=await ge.args(e.OperationKeys.DELETE,this.class,r),o=await this.readAll(t,...a.args);return await Promise.all(o.map(async t=>ue(this,a.context,t,e.OperationKeys.DELETE,e.OperationKeys.ON))),[t,...a.args]}async deleteAllSuffix(t,r){return r.get("ignoreHandlers")||await Promise.all(t.map(t=>ue(this,r,t,e.OperationKeys.DELETE,e.OperationKeys.AFTER))),t}toString(){return this.class.name+" Repository"}},e.SerializationError=w,e.UpdateValidationKeys=d,e.UpdateValidator=p,e.VERSION=me,e.ValidationError=T,e.after=F,e.afterAny=(e,t,r)=>F(h.ALL,e,t,r),e.afterCreate=(e,t,r)=>F(h.CREATE,e,t,r),e.afterCreateUpdate=(e,t,r)=>F(h.CREATE_UPDATE,e,t,r),e.afterDelete=(e,t,r)=>F(h.DELETE,e,t,r),e.afterRead=(e,t,r)=>F(h.READ,e,t,r),e.afterUpdate=(e,t,r)=>F(h.UPDATE,e,t,r),e.composeAttributeValue=G,e.composed=Q,e.composedFromCreateUpdate=Y,e.composedFromKeys=J,e.enforceDBDecorators=ue,e.generated=B,e.getDbDecorators=fe,e.getHandlerArgs=K,e.getHandlersDecorators=I,e.getValidatableUpdateProps=ie,e.groupDecorators=N,e.hash=z,e.hashOnCreateUpdate=$,e.id=()=>t.apply(a.required(),ee(),(e,r)=>t.propMetadata(t.Metadata.key(s.ID,r),{})(e,r)),e.on=V,e.onAny=(e,t,r)=>V(h.ALL,e,t,r),e.onCreate=j,e.onCreateUpdate=x,e.onDelete=(e,t,r)=>V(h.DELETE,e,t,r),e.onRead=(e,t,r)=>V(h.READ,e,t,r),e.onUpdate=U,e.operation=H,e.prefixMethod=(e,t,r,a)=>{const o=a||t.name;e[o]=new Proxy(e[o],{apply:async(e,t,a)=>{let o=r.call(t,...a);return o instanceof Promise&&(o=await o),o=e.call(t,...o),o instanceof Promise&&(o=await o),o}})},e.readonly=ee,e.reduceErrorsToPrint=pe,e.serialize=e=>(r,o)=>t.apply(x(re,{serializer:e}),F(h.ALL,ae,{serializer:e}),a.type([String,Object]),t.propMetadata(t.Metadata.key(s.SERIALIZE,o),{serializer:e}))(r,o),e.serializeAfterAll=ae,e.serializeOnCreateUpdate=re,e.sortDecorators=C,e.storeHandlerMetadata=_,e.suffixMethod=(e,t,r,a)=>{const o=a||t.name;e[o]=new Proxy(e[o],{apply:async(e,t,a)=>{let o=e.call(t,...a);return o instanceof Promise&&(o=await o),o=r.call(t,...o),o instanceof Promise&&(o=await o),o}})},e.timestamp=(r=h.CREATE_UPDATE,o=c)=>{const n=s.TIMESTAMP,i=a.Validation.updateKey(s.TIMESTAMP);return t.Decoration.for(n).define({decorator:(r,o)=>{const n=[B(s.TIMESTAMP),a.date(o,l.TIMESTAMP.DATE),a.required(l.TIMESTAMP.REQUIRED),t.propMetadata(a.Validation.key(s.TIMESTAMP),{operation:r,format:o}),V(r,te)];return-1!==r.indexOf(e.OperationKeys.UPDATE)?n.push(t.propMetadata(i,{message:l.TIMESTAMP.INVALID})):n.push(ee()),t.apply(...n)},args:[r,o]}).apply()},e.timestampHandler=te,e.transient=X,e.validateCompare=de,e.validateDecorator=ce,e.validateDecorators=le,e.version=Z,e.versionCreateUpdate=W,e.wrapMethodWithContext=Ee,e.wrapMethodWithContextForUpdate=Oe},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@decaf-ts/decoration"),require("tslib"),require("@decaf-ts/decorator-validation"),require("typed-object-accumulator"),require("@decaf-ts/logging")):"function"==typeof define&&define.amd?define(["exports","@decaf-ts/decoration","tslib","@decaf-ts/decorator-validation","typed-object-accumulator","@decaf-ts/logging"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["db-decorators"]={},e.decafTsDecoration,e.tslib,e.decafTsDecoratorValidation,e.typedObjectAccumulator,e.decafTsLogging);
|
|
2
2
|
//# sourceMappingURL=db-decorators.cjs.map
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -35,21 +35,21 @@ __exportStar(require("./validation/index.cjs"), exports);
|
|
|
35
35
|
* @const VERSION
|
|
36
36
|
* @memberOf module:db-decorators
|
|
37
37
|
*/
|
|
38
|
-
exports.VERSION = "0.17.
|
|
38
|
+
exports.VERSION = "0.17.2";
|
|
39
39
|
/**
|
|
40
40
|
* @description Represents the current commit hash of the module build.
|
|
41
41
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
42
42
|
* the placeholder with the actual commit hash at publish time.
|
|
43
43
|
* @const COMMIT
|
|
44
44
|
*/
|
|
45
|
-
exports.COMMIT = "
|
|
45
|
+
exports.COMMIT = "f86b26a";
|
|
46
46
|
/**
|
|
47
47
|
* @description Represents the full version string of the module.
|
|
48
48
|
* @summary Stores the semver version and commit hash for the package.
|
|
49
49
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
50
50
|
* @const FULL_VERSION
|
|
51
51
|
*/
|
|
52
|
-
exports.FULL_VERSION = "0.17.
|
|
52
|
+
exports.FULL_VERSION = "0.17.2-f86b26a";
|
|
53
53
|
exports.PACKAGE_NAME = "@decaf-ts/db-decorators";
|
|
54
54
|
decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
|
|
55
55
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js
CHANGED
|
@@ -18,21 +18,21 @@ export * from "./validation/index.js";
|
|
|
18
18
|
* @const VERSION
|
|
19
19
|
* @memberOf module:db-decorators
|
|
20
20
|
*/
|
|
21
|
-
export const VERSION = "0.17.
|
|
21
|
+
export const VERSION = "0.17.2";
|
|
22
22
|
/**
|
|
23
23
|
* @description Represents the current commit hash of the module build.
|
|
24
24
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
25
25
|
* the placeholder with the actual commit hash at publish time.
|
|
26
26
|
* @const COMMIT
|
|
27
27
|
*/
|
|
28
|
-
export const COMMIT = "
|
|
28
|
+
export const COMMIT = "f86b26a";
|
|
29
29
|
/**
|
|
30
30
|
* @description Represents the full version string of the module.
|
|
31
31
|
* @summary Stores the semver version and commit hash for the package.
|
|
32
32
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
33
33
|
* @const FULL_VERSION
|
|
34
34
|
*/
|
|
35
|
-
export const FULL_VERSION = "0.17.
|
|
35
|
+
export const FULL_VERSION = "0.17.2-f86b26a";
|
|
36
36
|
export const PACKAGE_NAME = "@decaf-ts/db-decorators";
|
|
37
37
|
Metadata.registerLibrary(PACKAGE_NAME, VERSION);
|
|
38
38
|
//# sourceMappingURL=index.js.map
|
package/lib/types/index.d.cts
CHANGED
|
@@ -12,19 +12,19 @@ export * from "./validation/index.d.cts";
|
|
|
12
12
|
* @const VERSION
|
|
13
13
|
* @memberOf module:db-decorators
|
|
14
14
|
*/
|
|
15
|
-
export declare const VERSION = "0.17.
|
|
15
|
+
export declare const VERSION = "0.17.2";
|
|
16
16
|
/**
|
|
17
17
|
* @description Represents the current commit hash of the module build.
|
|
18
18
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
19
19
|
* the placeholder with the actual commit hash at publish time.
|
|
20
20
|
* @const COMMIT
|
|
21
21
|
*/
|
|
22
|
-
export declare const COMMIT = "
|
|
22
|
+
export declare const COMMIT = "f86b26a";
|
|
23
23
|
/**
|
|
24
24
|
* @description Represents the full version string of the module.
|
|
25
25
|
* @summary Stores the semver version and commit hash for the package.
|
|
26
26
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
27
27
|
* @const FULL_VERSION
|
|
28
28
|
*/
|
|
29
|
-
export declare const FULL_VERSION = "0.17.
|
|
29
|
+
export declare const FULL_VERSION = "0.17.2-f86b26a";
|
|
30
30
|
export declare const PACKAGE_NAME = "@decaf-ts/db-decorators";
|
package/lib/types/index.d.mts
CHANGED
|
@@ -12,19 +12,19 @@ export * from "./validation/index.d.mts";
|
|
|
12
12
|
* @const VERSION
|
|
13
13
|
* @memberOf module:db-decorators
|
|
14
14
|
*/
|
|
15
|
-
export declare const VERSION = "0.17.
|
|
15
|
+
export declare const VERSION = "0.17.2";
|
|
16
16
|
/**
|
|
17
17
|
* @description Represents the current commit hash of the module build.
|
|
18
18
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
19
19
|
* the placeholder with the actual commit hash at publish time.
|
|
20
20
|
* @const COMMIT
|
|
21
21
|
*/
|
|
22
|
-
export declare const COMMIT = "
|
|
22
|
+
export declare const COMMIT = "f86b26a";
|
|
23
23
|
/**
|
|
24
24
|
* @description Represents the full version string of the module.
|
|
25
25
|
* @summary Stores the semver version and commit hash for the package.
|
|
26
26
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
27
27
|
* @const FULL_VERSION
|
|
28
28
|
*/
|
|
29
|
-
export declare const FULL_VERSION = "0.17.
|
|
29
|
+
export declare const FULL_VERSION = "0.17.2-f86b26a";
|
|
30
30
|
export declare const PACKAGE_NAME = "@decaf-ts/db-decorators";
|