| 1 |
- "use strict";(self.webpackChunk_e22m4u_node_repository=self.webpackChunk_e22m4u_node_repository||[]).push([[225],{225:(e,t,r)=>{r.r(t),r.d(t,{MemoryAdapter:()=>h});var s=r(895),a=r(390),o=r(286),i=r(606),n=r(202),l=r(524);class h extends s.L{_tables=new Map;_lastIds=new Map;_getTableOrCreate(e){const t=this.getService(i.r0).getTableNameByModelName(e);let r=this._tables.get(t);return r||(r=new Map,this._tables.set(t,r),r)}_genNextIdValue(e,t){const r=this.getService(i.r0).getDataTypeByPropertyName(e,t);if(r!==i.g.ANY&&r!==i.g.NUMBER)throw new l.R("The memory adapter able to generate only Number identifiers, but the primary key %v of the model %v is defined as %s. Do provide your own value for the %v property, or change the type in the primary key definition to a Number that will be generated automatically.",t,e,(0,o.k)(r),t);const s=this.getService(i.r0).getTableNameByModelName(e),a=(this._lastIds.get(s)??0)+1;this._lastIds.set(s,a);const n=this._getTableOrCreate(e);return Array.from(n.keys()).includes(a)?this._genNextIdValue(e,t):a}async create(e,t,r=void 0){const s=this.getService(i.r0).getPrimaryKeyAsPropertyName(e);let o=t[s];null==o&&(o=this._genNextIdValue(e,s));const n=this._getTableOrCreate(e);if(n.has(o))throw new l.R("The value %v of the primary key %v already exists in the model %v.",o,s,e);(t=(0,a.X)(t))[s]=o;const h=this.getService(i.r0).convertPropertyNamesToColumnNames(e,t);return n.set(o,h),this.getService(i.r0).convertColumnNamesToPropertyNames(e,h)}async replaceById(e,t,r,s=void 0){const o=this._getTableOrCreate(e),n=o.has(t),h=this.getService(i.r0).getPrimaryKeyAsPropertyName(e);if(!n)throw new l.R("The value %v of the primary key %v does not exist in the model %v.",t,h,e);(r=(0,a.X)(r))[h]=t;const c=this.getService(i.r0).convertPropertyNamesToColumnNames(e,r);return o.set(t,c),this.getService(i.r0).convertColumnNamesToPropertyNames(e,c)}async patchById(e,t,r,s=void 0){const o=this._getTableOrCreate(e),n=o.get(t),h=this.getService(i.r0).getPrimaryKeyAsPropertyName(e);if(null==n)throw new l.R("The value %v of the primary key %v does not exist in the model %v.",t,h,e);delete(r=(0,a.X)(r))[h];const c=this.getService(i.r0).convertColumnNamesToPropertyNames(e,n),m=Object.assign({},c,r),y=this.getService(i.r0).convertPropertyNamesToColumnNames(e,m);return o.set(t,y),this.getService(i.r0).convertColumnNamesToPropertyNames(e,y)}async find(e,t=void 0){const r=this._getTableOrCreate(e);let s=Array.from(r.values()).map((t=>this.getService(i.r0).convertColumnNamesToPropertyNames(e,t)));return t&&"object"==typeof t&&(t.where&&(s=this.getService(n.d4).filter(s,t.where)),(t.skip||t.limit)&&(s=this.getService(n.hH).slice(s,t.skip,t.limit)),t.order&&this.getService(n.$Z).sort(s,t.order)),s}async findById(e,t,r=void 0){const s=this._getTableOrCreate(e).get(t),a=this.getService(i.r0).getPrimaryKeyAsPropertyName(e);if(!s)throw new l.R("The value %v of the primary key %v does not exist in the model %v.",t,a,e);return this.getService(i.r0).convertColumnNamesToPropertyNames(e,s)}async delete(e,t=void 0){const r=this._getTableOrCreate(e),s=Array.from(r.values());if(!s.length)return 0;let a=s.map((t=>this.getService(i.r0).convertColumnNamesToPropertyNames(e,t)));t&&"object"==typeof t&&(a=this.getService(n.d4).filter(a,t));const o=a.length,l=this.getService(i.r0).getPrimaryKeyAsPropertyName(e);return a.forEach((e=>{const t=e[l];r.delete(t)})),o}async deleteById(e,t){const r=this._getTableOrCreate(e),s=r.has(t);return r.delete(t),s}async exists(e,t){return this._getTableOrCreate(e).has(t)}async count(e,t=void 0){const r=this._getTableOrCreate(e);let s=Array.from(r.values()).map((t=>this.getService(i.r0).convertColumnNamesToPropertyNames(e,t)));return t&&"object"==typeof t&&(s=this.getService(n.d4).filter(s,t)),s.length}}}}]);
|