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

//# sourceMappingURL=0hi7_%40better-auth_memory-adapter_dist_index_mjs_0.w32jf._.js.map