"use strict";var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var O=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!f.call(t,n)&&n!==r&&p(t,n,{get:()=>e[n],enumerable:!(a=h(e,n))||a.enumerable});return t};var b=t=>x(p({},"__esModule",{value:!0}),t);var v={};O(v,{createWrapKey:()=>u,getOrSet:()=>g,wrap:()=>K,wrapSync:()=>m});module.exports=b(v);var y=require("@cacheable/utils");function m(t,e){let{ttl:r,keyPrefix:a,cache:n,serialize:c}=e;return(...s)=>{let i=u(t,s,{keyPrefix:a,serialize:c});e.createKey&&(i=e.createKey(t,s,e));let o=n.get(i);if(o===void 0)try{o=t(...s),n.set(i,o,r)}catch(l){n.emit("error",l),e.cacheErrors&&n.set(i,l,r)}return o}}async function g(t,e,r){let a=typeof t=="function"?t(r):t,n=await r.cache.get(a);if(n===void 0){let s=`${r.cacheId??"default"}::${a}`;n=await(0,y.coalesceAsync)(s,async()=>{try{let i=await e();return await r.cache.set(a,i,r.ttl),i}catch(i){if(r.cache.emit("error",i),r.cacheErrors&&await r.cache.set(a,i,r.ttl),r.throwErrors)throw i}})}return n}function K(t,e){let{keyPrefix:r,serialize:a}=e;return async(...n)=>{let c=u(t,n,{keyPrefix:r,serialize:a});return e.createKey&&(c=e.createKey(t,n,e)),g(c,async()=>t(...n),e)}}function u(t,e,r){let{keyPrefix:a,serialize:n}=r||{};return a?`${a}::${t.name}::${(0,y.hash)(e,{serialize:n})}`:`${t.name}::${(0,y.hash)(e,{serialize:n})}`}0&&(module.exports={createWrapKey,getOrSet,wrap,wrapSync});
