/* Socket Lib - Built with esbuild */
var b=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var D=(a,t)=>{for(var r in t)y(a,r,{get:t[r],enumerable:!0})},E=(a,t,r,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of $(t))!S.call(a,c)&&c!==r&&y(a,c,{get:()=>t[c],enumerable:!(u=M(t,c))||u.enumerable});return a};var g=(a,t,r)=>(r=a!=null?b(z(a)):{},E(t||!a||!a.__esModule?y(r,"default",{value:a,enumerable:!0}):r,a)),K=a=>E(y({},"__esModule",{value:!0}),a);var W={};D(W,{createTtlCache:()=>U});module.exports=K(W);var l=g(require("./cacache"));const A=300*1e3,F="ttl-cache";function U(a){const t={__proto__:null,memoize:!0,prefix:F,ttl:A,...a};if(t.prefix?.includes("*"))throw new TypeError('Cache prefix cannot contain wildcards (*). Use clear({ prefix: "pattern*" }) for wildcard matching.');const r=new Map,u=t.ttl??A;function c(e){return`${t.prefix}:${e}`}function p(e){return Date.now()>e.expiresAt}function w(e){const n=c(e);if(!e.includes("*"))return o=>o.startsWith(n);const f=n.replaceAll(/[.+?^${}()|[\]\\]/g,"\\$&").replaceAll("*",".*"),T=new RegExp(`^${f}`);return o=>T.test(o)}async function x(e){if(e.includes("*"))throw new TypeError("Cache key cannot contain wildcards (*). Use getAll(pattern) to retrieve multiple entries.");const n=c(e);if(t.memoize){const i=r.get(n);if(i&&!p(i))return i.data;i&&r.delete(n)}const s=await l.safeGet(n);if(s){const i=JSON.parse(s.data.toString("utf8"));if(!p(i))return t.memoize&&r.set(n,i),i.data;await l.remove(n)}}async function k(e){const n=new Map,s=w(e);if(t.memoize)for(const[o,d]of r.entries()){if(!s(o))continue;if(p(d)){r.delete(o);continue}const m=o.slice((t.prefix?.length??0)+1);n.set(m,d.data)}const i=(await import("./paths")).getSocketCacacheDir(),T=(await import("./cacache")).getCacache().ls.stream(i);for await(const o of T){if(!o.key.startsWith(`${t.prefix}:`)||!s(o.key))continue;const d=o.key.slice((t.prefix?.length??0)+1);if(!n.has(d))try{const m=await l.safeGet(o.key);if(!m)continue;const h=JSON.parse(m.data.toString("utf8"));if(p(h)){await l.remove(o.key);continue}n.set(d,h.data),t.memoize&&r.set(o.key,h)}catch{}}return n}async function C(e,n){if(e.includes("*"))throw new TypeError('Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).');const s=c(e),i={data:n,expiresAt:Date.now()+u};t.memoize&&r.set(s,i),await l.put(s,JSON.stringify(i),{metadata:{expiresAt:i.expiresAt}})}async function O(e,n){const s=await x(e);if(s!==void 0)return s;const i=await n();return await C(e,i),i}async function v(e){if(e.includes("*"))throw new TypeError("Cache key cannot contain wildcards (*). Use deleteAll(pattern) to remove multiple entries.");const n=c(e);r.delete(n),await l.remove(n)}async function P(e){const n=e?`${t.prefix}:${e}`:t.prefix;if(!e)r.clear();else{const i=w(e);for(const f of r.keys())i(f)&&r.delete(f)}return await l.clear({prefix:n})??0}async function _(e){const n={__proto__:null,...e};r.clear(),!n.memoOnly&&await P()}return{clear:_,delete:v,deleteAll:P,get:x,getAll:k,getOrFetch:O,set:C}}0&&(module.exports={createTtlCache});
//# sourceMappingURL=cache-with-ttl.js.map
