/* Socket Lib - Built with esbuild */
var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var k=(e,n)=>{for(var r in n)p(e,r,{get:n[r],enumerable:!0})},w=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of A(n))!x.call(e,t)&&t!==r&&p(e,t,{get:()=>n[t],enumerable:!(i=y(n,t))||i.enumerable});return e};var N=e=>w(p({},"__esModule",{value:!0}),e);var $={};k($,{Memoize:()=>O,clearAllMemoizationCaches:()=>T,memoize:()=>R,memoizeAsync:()=>b,memoizeDebounced:()=>P,memoizeWeak:()=>S,once:()=>E});module.exports=N($);var c=require("./debug");function R(e,n={}){const{keyGen:r=(...o)=>JSON.stringify(o),maxSize:i=Number.POSITIVE_INFINITY,name:t=e.name||"anonymous",ttl:l=Number.POSITIVE_INFINITY}=n,u=new Map,m=[];function f(){if(u.size>=i&&m.length>0){const o=m.shift();o&&(u.delete(o),(0,c.debugLog)(`[memoize:${t}] clear`,{key:o,reason:"LRU"}))}}function z(o){return l===Number.POSITIVE_INFINITY?!1:Date.now()-o.timestamp>l}return function(...g){const s=r(...g),a=u.get(s);if(a&&!z(a)){a.hits++;const d=m.indexOf(s);return d!==-1&&m.splice(d,1),m.push(s),(0,c.debugLog)(`[memoize:${t}] hit`,{key:s,hits:a.hits}),a.value}(0,c.debugLog)(`[memoize:${t}] miss`,{key:s});const h=e(...g);return f(),u.set(s,{value:h,timestamp:Date.now(),hits:0}),m.push(s),(0,c.debugLog)(`[memoize:${t}] set`,{key:s,cacheSize:u.size}),h}}function b(e,n={}){const{keyGen:r=(...o)=>JSON.stringify(o),maxSize:i=Number.POSITIVE_INFINITY,name:t=e.name||"anonymous",ttl:l=Number.POSITIVE_INFINITY}=n,u=new Map,m=[];function f(){if(u.size>=i&&m.length>0){const o=m.shift();o&&(u.delete(o),(0,c.debugLog)(`[memoizeAsync:${t}] clear`,{key:o,reason:"LRU"}))}}function z(o){return l===Number.POSITIVE_INFINITY?!1:Date.now()-o.timestamp>l}return async function(...g){const s=r(...g),a=u.get(s);if(a&&!z(a)){a.hits++;const d=m.indexOf(s);return d!==-1&&m.splice(d,1),m.push(s),(0,c.debugLog)(`[memoizeAsync:${t}] hit`,{key:s,hits:a.hits}),await a.value}(0,c.debugLog)(`[memoizeAsync:${t}] miss`,{key:s});const h=e(...g);f(),u.set(s,{value:h,timestamp:Date.now(),hits:0}),m.push(s),(0,c.debugLog)(`[memoizeAsync:${t}] set`,{key:s,cacheSize:u.size});try{return await h}catch(d){u.delete(s);const I=m.indexOf(s);throw I!==-1&&m.splice(I,1),(0,c.debugLog)(`[memoizeAsync:${t}] clear`,{key:s,reason:"error"}),d}}}function O(e={}){return(n,r,i)=>{const t=i.value;return i.value=R(t,{...e,name:e.name||r}),i}}function T(){(0,c.debugLog)("[memoize:all] clear",{action:"clear-all-caches"})}function S(e){const n=new WeakMap;return function(i){const t=n.get(i);if(t!==void 0)return(0,c.debugLog)(`[memoizeWeak:${e.name}] hit`),t;(0,c.debugLog)(`[memoizeWeak:${e.name}] miss`);const l=e(i);return n.set(i,l),l}}function E(e){let n=!1,r;return function(){return n?(0,c.debugLog)(`[once:${e.name}] hit`):(r=e(),n=!0,(0,c.debugLog)(`[once:${e.name}] set`)),r}}function P(e,n,r={}){const i=R(e,r);let t;return function(...u){return t&&clearTimeout(t),t=setTimeout(()=>{i(...u)},n),i(...u)}}0&&(module.exports={Memoize,clearAllMemoizationCaches,memoize,memoizeAsync,memoizeDebounced,memoizeWeak,once});
//# sourceMappingURL=memoization.js.map
