"use strict";exports.id=1006,exports.ids=[1006],exports.modules={41006:(a,b,c)=>{c.d(b,{memoryAdapter:()=>h});var d=c(9965),e=c(61510);function f(a,b){return"string"==typeof a&&"string"==typeof b?a.toLowerCase()===b.toLowerCase():a===b}function g(a,b){return"string"!=typeof a?b.includes(a):b.some(b=>"string"==typeof b&&a.toLowerCase()===b.toLowerCase())}let h=(a,b)=>{let c=null,h=(0,d.I)({config:{adapterId:"memory",adapterName:"Memory Adapter",usePlural:!1,debugLogs:b?.debugLogs||!1,supportsArrays:!0,customTransformInput:b=>b.options.advanced?.database?.generateId==="serial"&&"id"===b.field&&"create"===b.action?a[b.model].length+1:b.data,transaction:async b=>{let d=structuredClone(a);try{return await b(h(c))}catch(b){throw Object.keys(a).forEach(b=>{a[b]=d[b]}),b}}},adapter:({getFieldName:b,getDefaultFieldName:c,options:d,getModelName:h})=>{let i=(a,c,d)=>c?a.sort((a,e)=>{let f=b({model:d,field:c.field}),g=a[f],h=e[f],i=0;return i=null==g&&null==h?0:null==g?-1:null==h?1:"string"==typeof g&&"string"==typeof h?g.localeCompare(h):g instanceof Date&&h instanceof Date?g.getTime()-h.getTime():"number"==typeof g&&"number"==typeof h?g-h:"boolean"==typeof g&&"boolean"==typeof h?g===h?0:g?1:-1:String(g).localeCompare(String(h)),"asc"===c.direction?i:-i}):a;function j(b,d,i,j){let k=(()=>{let h=a[d];if(!h)throw e.vF.error(`[MemoryAdapter] Model ${d} not found in the DB`,Object.keys(a)),Error(`Model ${d} not found`);let i=(a,b)=>{var c,d,e;let{field:h,value:i,operator:j,mode:k="sensitive"}=b,l="insensitive"===k&&("string"==typeof i||Array.isArray(i)&&i.every(a=>"string"==typeof a));switch(j){case"in":if(!Array.isArray(i))throw Error("Value must be an array");if(l)return g(a[h],i);return i.includes(a[h]);case"not_in":if(!Array.isArray(i))throw Error("Value must be an array");if(l)return!g(a[h],i);return!i.includes(a[h]);case"contains":if(l)return c=a[h],"string"==typeof c&&"string"==typeof i&&c.toLowerCase().includes(i.toLowerCase());return a[h]?.includes(i);case"starts_with":if(l)return d=a[h],"string"==typeof d&&"string"==typeof i&&d.toLowerCase().startsWith(i.toLowerCase());return a[h].startsWith(i);case"ends_with":if(l)return e=a[h],"string"==typeof e&&"string"==typeof i&&e.toLowerCase().endsWith(i.toLowerCase());return a[h].endsWith(i);case"ne":return l?!f(a[h],i):a[h]!==i;case"gt":return null!=i&&a[h]>i;case"gte":return null!=i&&a[h]>=i;case"lt":return null!=i&&a[h]<i;case"lte":return null!=i&&a[h]<=i;default:return l?f(a[h],i):a[h]===i}},k=h.filter(a=>{if(!b.length||0===b.length)return!0;let c=i(a,b[0]);for(let d of b){let b=i(a,d);c="OR"===d.connector?c||b:c&&b}return c});return j?.length&&j.length>0&&(k=k.map(a=>Object.fromEntries(Object.entries(a).filter(([a])=>j.includes(c({model:d,field:a})))))),k})();if(!i)return k;let l=new Map,m=new Map;for(let b of k){let c=String(b.id);if(!l.has(c)){let a={...b};for(let[b,d]of Object.entries(i)){let e=h(b);"one-to-one"===d.relation?a[e]=null:(a[e]=[],m.set(`${c}-${b}`,new Set))}l.set(c,a)}let d=l.get(c);for(let[f,g]of Object.entries(i)){let i=h(f),j=a[i];if(!j)throw e.vF.error(`[MemoryAdapter] JoinOption model ${i} not found in the DB`,Object.keys(a)),Error(`JoinOption model ${i} not found`);let k=j.filter(a=>a[g.on.to]===b[g.on.from]);if("one-to-one"===g.relation)d[i]=k[0]||null;else{let a=m.get(`${c}-${f}`),b=g.limit??100,e=0;for(let c of k){if(e>=b)break;!a.has(c.id)&&(d[i].push(c),a.add(c.id),e++)}}}}return Array.from(l.values())}return{create:async({model:b,data:c})=>(d.advanced?.database?.generateId==="serial"&&(c.id=a[h(b)].length+1),a[b]||(a[b]=[]),a[b].push(c),c),findOne:async({model:a,where:b,select:c,join:d})=>{let e=j(b,a,d,c);return d?e.length?e[0]:null:e[0]||null},findMany:async({model:a,where:b,sortBy:c,limit:d,select:e,offset:f,join:g})=>{let h=j(b||[],a,g,e);if(g){if(!h.length)return[];i(h,c,a);let b=h;return void 0!==f&&(b=b.slice(f)),void 0!==d&&(b=b.slice(0,d)),b}let k=i(h,c,a);return void 0!==f&&(k=k.slice(f)),void 0!==d&&(k=k.slice(0,d)),k||[]},count:async({model:b,where:c})=>c?j(c,b).length:a[b].length,update:async({model:a,where:b,update:c})=>{let d=j(b,a);return d.forEach(a=>{Object.assign(a,c)}),d[0]||null},delete:async({model:b,where:c})=>{let d=a[b],e=j(c,b);a[b]=d.filter(a=>!e.includes(a))},deleteMany:async({model:b,where:c})=>{let d=a[b],e=j(c,b),f=0;return a[b]=d.filter(a=>e.includes(a)?(f++,!1):!e.includes(a)),f},updateMany({model:a,where:b,update:c}){let d=j(b,a);return d.forEach(a=>{Object.assign(a,c)}),d[0]||null}}}});return a=>(c=a,h(a))}}};