"use strict";var J=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var n=(t,e)=>J(t,"name",{value:e,configurable:!0});var Xe=(t,e)=>{for(var r in e)J(t,r,{get:e[r],enumerable:!0})},Ze=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qe(e))!Je.call(t,o)&&o!==r&&J(t,o,{get:()=>e[o],enumerable:!(s=Qe(e,o))||s.enumerable});return t};var $e=t=>Ze(J({},"__esModule",{value:!0}),t);var nr={};Xe(nr,{Cache:()=>Ge,SourceCleanupPolicies:()=>A,async:()=>U,cache:()=>F,cacheWith:()=>je,clean:()=>Be,compose:()=>fe,createCache:()=>q,effects:()=>G,lifeCycle:()=>me,lru:()=>H,memo:()=>O,once:()=>D,remote:()=>Q,source:()=>ce});module.exports=$e(nr);var i=Symbol.for("cache"),I=Symbol.for("cache-promise-getter"),g=Symbol.for("cache-promise-setter"),P=Symbol.for("cache-promise-has"),E=Symbol.for("cache-values-delete"),l=Symbol.for("event-emitter"),ir=Symbol.for("set-observable"),cr=Symbol.for("delete-observable"),ur=Symbol.for("clean-observable");var L=Symbol.for("remote-cache-remote-cache"),K=Symbol.for("remote-cache-options"),A=function(t){return t.ALL="all",t.NONE="none",t.KEYS="only-known-keys",t}({});var ke=n((t,e,r)=>(t.on(e,r),()=>{t.off(e,r)}),"subscribe"),w=ke;var et=class{static{n(this,"EventEmitter")}listeners;constructor(){this.listeners={}}on(e,r){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(r)}off(e,r){if(e in this.listeners){let s=this.listeners[e].indexOf(r);s>-1&&this.listeners[e].splice(s,1)}}emit(e,...r){this.listeners[e]?.forEach(s=>{s(...r)})}},pe=et;var tt=n(()=>new pe,"createEventEmitter"),R=tt;var rt=class{static{n(this,"Cache")}[i];[l];constructor(e){this[i]=e||new Map,this[l]=R()}set(e,r){let s=this[i].set(e,r);return this[l].emit("set",e,r),s}get(e){let r=this[i].get(e);return this[l].emit("get",e),r}has(e){return this[i].has(e)}delete(e){let r=this[i].delete(e);return this[l].emit("delete",e),r}keys(){return this[i].keys()}values(){return this[i].values()}entries(){return this[i].entries()}on(e,r){return w(this[l],e,r)}[Symbol.iterator](){return this[i][Symbol.iterator]()}clean(){if(typeof this[i].clean=="function"){let e=this[i].clean();return this[l].emit("clean"),e}else{for(let e of this.keys())this[i].delete(e);this[l].emit("clean")}}},C=rt;var st=n(()=>new C,"createCache"),F=st;var oe=Symbol.for("source-cache-options");var nt=n(t=>typeof t=="object"&&!!t&&typeof t.then=="function","isThentable"),d=nt;var ot=n(t=>d(t)?t:Promise.resolve(t),"promisify"),_=ot;var ie=Symbol.for("async-iterable-iterator-wrapper-key"),it=class{static{n(this,"AsyncIterableIteratorWrapper")}[ie];constructor(e){this[ie]=e}next(){let e=this[ie].next();return d(e)?e:Promise.resolve(e)}[Symbol.asyncIterator](){return this}},ct=n(t=>new it(t),"getAsyncIterator"),x=ct;function ut(t){let e,r=!1,s=!1,o,c=n(function(...a){if(o)return o;if(s)return r?(o=Promise.resolve(e).then(u=>(o=void 0,u)),o):e;let f=t.apply(this,a);return d(f)?(r=!0,o=Promise.resolve(f.then(u=>(s=!0,e=u,o=void 0,e))).catch(u=>(o=void 0,Promise.reject(u))),o):(s=!0,e=f,f)},"fnOnce"),m=n(function(){e=void 0,s=!1,o=void 0},"clean");return c.clean=m,c}n(ut,"once");var D=ut;var lt=n(()=>new C,"createCache"),mt=n(t=>{let e=D(lt),r=n(h=>e().has(h)?_(e().get(h)):_(t.get(h)).then(y=>(y&&!e().has(h)&&e().set(h,y),y)),"get"),s=t.set?(h,y)=>(e().set(h,y),_(t.set(h,y))):(h,y)=>(e().set(h,y),Promise.resolve()),o=t.has?h=>_(t.has(h)):h=>Promise.resolve(e().has(h)),c=t.delete?h=>(e().delete(h),_(t.delete(h))):h=>(e().delete(h),Promise.resolve()),m=t.clean?()=>(e().clean(),_(t.clean())):()=>(e().clean(),Promise.resolve()),a=t.keys?()=>x(t.keys()):()=>x(e().keys()),f=t.values?()=>x(t.values()):()=>x(e().values()),u=t.entries?()=>x(t.entries()):()=>x(e().entries());return{get:r,set:s,has:o,delete:c,clean:m,keys:a,values:f,entries:u}},"compile"),de=mt;var b=Symbol(),at=class{static{n(this,"SourceAsyncCache")}[oe];[i];[b];[l];constructor(e){this[oe]=e,this[i]=new C,this[b]=de(e),this[l]=R()}get(e){return this[b].get(e).then(r=>(this[l].emit("get",e),r))}set(e,r){return this[b].set(e,r).then(s=>(this[l].emit("set",e,r),s))}has(e){return this[b].has(e)}delete(e){return this[b].delete(e).then(r=>(this[l].emit("delete",e),r))}keys(){return this[b].keys()}values(){return this[b].values()}entries(){return this[b].entries()}[Symbol.asyncIterator](){return this.entries()}clean(){return this[b].clean().then(e=>(this[l].emit("clean"),e))}on(e,r){return w(this[l],e,r)}},Ee=at;var ht=n(t=>new Ee(t),"createSource"),ce=ht;var ft=n((t,e)=>d(t)?t.then(e):e(t),"evaluate"),p=ft;var S=Symbol.for("keys-cache"),pt=500,dt=n(()=>1,"defaultItemSizeGetter"),Et={maxSize:pt,getItemSize:dt},St=n((t,e)=>t[S].has(e)?t[S].get(e)||1:0,"getKeySize"),Ce=n((t,e)=>{if(t[S].has(e)){let r=t[S].get(e);t[S].delete(e),t[S].set(e,r)}},"refreshKey"),ye=n((t,e,r)=>{if(r<1)throw new Error("LruCacheError: Size cannot be smaller than 1");if(r>t.maxCacheSize)throw new Error("LruCacheError: Item is bigger than the whole cache size");let s=St(t,e),o=r-s;if(s===r)Ce(t,e);else{let c=t.usedSize+o;for(;c>t.maxCacheSize;)t.delete(t[S].keys().next().value),c=t.usedSize+o;t[S].set(e,r===1?void 0:r),t.usedSize=t.usedSize+o}},"setKey"),Se=n((t,e)=>{let r=t[S].has(e)?t[S].get(e)||1:0;t[S].delete(e),t.usedSize=t.usedSize-r},"removeKey"),Ct=n((t,e,r)=>{r!==void 0&&!t[S].has(e)?ye(t,e,t.getItemSize(e,r)):Ce(t,e)},"introduce"),yt=class{static{n(this,"LruCache")}[i];[S];maxCacheSize;usedSize;getItemSize;constructor(e,r){this[i]=e||new C,this[S]=new Map,this.usedSize=0;let s={...Et,...r};this.maxCacheSize=s.maxSize,this.getItemSize=s.getItemSize,this.on("delete",o=>{this[S].has(o)&&Se(this,o)}),this.on("clean",()=>{this[S].size>0&&(this[S]=new Map)})}get(...e){let r=e[0];return p(this[i].get.apply(this[i],e),s=>(Ct(this,r,s),s))}set(...e){let[r,s]=e;return p(this[i].set.apply(this[i],e),o=>(ye(this,r,this.getItemSize(r,s)),o))}has(...e){return this[i].has.apply(this[i],e)}delete(...e){return Se(this,e[0]),p(this[i].delete.apply(this[i],e),r=>r)}keys(){return this[i].keys()}values(){return this[i].values()}entries(){return this[i].entries()}[Symbol.iterator](){return this.entries()}[Symbol.asyncIterator](){return x(this.entries())}clean(){return p(this[i].clean(),()=>{this[S]=new Map,this.usedSize=0})}on(e,r){return this[i].on(e,r)}},xe=yt;var xt=n(t=>e=>new xe(e,t),"lru"),H=xt;var ge=n((t,e)=>new Promise((r,s)=>{let o=t[i].get(e);return Promise.resolve(o).then(c=>(t[l].emit("get",e),t[I].delete(e),c)).then(r).catch(c=>{t[I].delete(e),s(c)})}),"getValuePromise"),gt=class{static{n(this,"AsyncCache")}[i];[I];[g];[P];[E];[l];constructor(e){this[i]=e||new C,this[I]=new Map,this[g]=new Map,this[P]=new Map,this[E]=new Map,this[l]=R()}get(e){let r=this[I].get(e);if(r)return r;let s=this[g].get(e);if(s){let c=new Promise((m,a)=>{s.finally(()=>{ge(this,e).then(m,a)})});return this[I].set(e,c),c}let o=ge(this,e);return this[I].set(e,o),o}set(e,r){let s=this[g].get(e);if(s){let c=new Promise((m,a)=>{s.finally(()=>{Promise.resolve(this[i].set(e,r)).then(f=>{this[l].emit("set",e,r),m(f)}).catch(a)})}).then(()=>{this[g].delete(e)}).catch(m=>(this[g].delete(e),Promise.reject(m)));return this[g].set(e,c),Promise.resolve(c)}let o=Promise.resolve(this[i].set(e,r)).then(()=>{this[l].emit("set",e,r),this[g].delete(e)}).catch(c=>(this[g].delete(e),Promise.reject(c)));return this[g].set(e,o),o}has(e){let r=this[P].get(e);if(r)return r;let s=this[g].get(e);if(s){let c=new Promise((m,a)=>{s.finally(()=>{let f=this[i].has(e);Promise.resolve(f).then(u=>(this[P].delete(e),u)).then(m).catch(u=>{this[P].delete(e),a(u)})})});return this[P].set(e,c),c}let o=new Promise((c,m)=>{Promise.resolve(this[i].has(e)).then(a=>{this[P].delete(e),c(a)}).catch(a=>{this[P].delete(e),m(a)})});return this[P].set(e,o),o}delete(e){let r=this[E].get(e);if(r)return r;let s=Promise.resolve(Promise.resolve(this[i].delete(e)).then(()=>{this[l].emit("delete",e),this[E].delete(e)},o=>(this[E].delete(e),Promise.reject(o))));return this[E].set(e,s),s}keys(){return x(this[i].keys())}values(){return x(this[i].values())}entries(){return x(this[i].entries())}[Symbol.asyncIterator](){return this.entries()}on(e,r){return w(this[l],e,r)}clean(){if(typeof this[i].clean=="function")return _(this[i].clean()).then(()=>{this[l].emit("clean")});let e=this.keys();return new Promise((r,s)=>{let o=[],c=n((m,a)=>e.next().then(({value:f,done:u})=>{let h=this[E].get(f);if(a.push(h||this.delete(f)),!u)return c(m,a)}).catch(s),"enrichDeletePromises");return c(e,o).then(()=>Promise.all(o).then(()=>{r(void 0),this[l].emit("clean")}).catch(s))})}},_e=gt;var _t=n(()=>t=>new _e(t),"async"),U=_t;var v=Symbol.for("cache-cleanup-queue"),W=Symbol.for("cache-delete-queue"),T=Symbol.for("cache-effects"),X=Symbol.for("lifecycle-cache-remote-ref"),Z=Symbol.for("lifecycle-cache-remote-read"),V=Symbol.for("lifecycle-cache-remote-clean");var Pt=class{static{n(this,"LifeCycleItem")}isCleaned;remoteApi;cleanupCalls;constructor(e,r){this.isCleaned=!1,this.remoteApi=r,this.cleanupCalls=[],this.cleanupCalls=e.reduce((s,o)=>{let c=o(this.remoteApi);return typeof c=="function"&&s.push(c),s},[])}read(e){this.remoteApi[Z](e)}clean(){if(!this.isCleaned){let e=this.cleanupCalls.reduce((r,s)=>{let o=s();return d(o)&&r.push(o),r},[]);if(e.length)return Promise.all(e).then(()=>{}).then(()=>{this.remoteApi[V](),this.isCleaned=!0});this.remoteApi[V](),this.isCleaned=!0}}},Pe=Pt;var bt=n(t=>{if(!t)return!1;let e=typeof t;return e==="object"||e==="function"},"isComplexType"),be=bt;var ue=Symbol("key-ref"),$=Symbol("last-value"),le=Symbol("last-value-ref"),B=Symbol("listeners"),Te=n((t,e)=>{let r=be(e);t[$]=r?void 0:e,t[le]=r?new WeakRef(e):void 0},"setValue"),Tt=class{static{n(this,"RemoteApi")}[X];[ue];[$];[le];[B];constructor(e,r,s){this[X]=e,this[ue]=r,this[B]=[],Te(this,s)}getSelf(){return this[$]?this[$]:this[le]?.deref()}deleteSelf(){return this[X].delete(this[ue])}onRead(e){this[B].push(e)}[Z](e){Te(this,e),this[B].forEach(r=>r())}[V](){this[B]=[]}},Ae=Tt;var Ie=[],Re=n((t,e)=>{let r=Promise.resolve(e).then(()=>{t[v].delete(r)});return t[v].add(r),r},"clean"),Le=n((t,e)=>{let r=t[T].get(e);if(r){let s=r.clean();return t[T].delete(e),s}},"cleanByKey"),j=n((t,e)=>{let r=Le(t,e);r&&Re(t,r)},"deleteKey"),we=n((t,e,r,s)=>{let o=Le(t,e);o&&Re(t,o);let c=new Pe(s,new Ae(t,e,r));t[T].set(e,c)},"setLifeCycleItem"),At=class{static{n(this,"LifeCycleCache")}[i];[v];[W];[T];[E];constructor(e){this[i]=e||new C,this[T]=new Map,this[v]=new Set,this[W]=new Set,this[E]=new Map,this.on("delete",r=>{this[E].get(r)||j(this,r)}),this.on("clean",()=>{Array.from(this[T].keys()).forEach(r=>j(this,r))})}get(...e){let r=this[T].get.apply(this[T],e),s=this[i].get.apply(this[i],e);return d(s)?s.then(o=>(r&&o&&r.read(o),o)):(r&&s&&r.read(s),s)}set(e,r,s){let o=this[i].set(e,r);return d(o)?o.then(c=>(we(this,e,r,s||Ie),this[E].delete(e),c)):(we(this,e,r,s||Ie),this[E].delete(e),o)}has(...e){return this[i].has.apply(this[i],e)}delete(e){let r=this[E].get(e);if(r)return r;let s=this[i].delete(e);if(d(s)){let o=s.then(c=>(j(this,e),this[W].delete(o),this[E].get(e)===o&&this[E].delete(e),c));return this[W].add(o),this[E].set(e,o),o}return j(this,e),s}keys(){return this[i].keys()}values(){return this[i].values()}entries(){return this[i].entries()}[Symbol.iterator](){return this.entries()}[Symbol.asyncIterator](){return this.entries()}clean(){return Array.from(this[T].keys()).forEach(e=>j(this,e)),p(this[i].clean(),()=>{if(this[v].size>0)return Promise.all(this[v]).then(()=>{})})}on(e,r){return this[i].on(e,r)}},k=At;var It=n(()=>t=>new k(t),"lifeCycle"),me=It;var ae=Symbol("effects-cache-effects"),wt=[],Rt=class{static{n(this,"EffectsCache")}[i];[ae];constructor(e,r){this[i]=new k(e),this[ae]=r||wt}get(...e){return this[i].get.apply(this[i],e)}set(e,r){return this[i].set.apply(this[i],[e,r,this[ae]])}has(...e){return this[i].has.apply(this[i],e)}delete(...e){return this[i].delete.apply(this[i],e)}keys(){return this[i].keys()}values(){return this[i].values()}entries(){return this[i].entries()}[Symbol.iterator](){return this[i][Symbol.iterator]()}[Symbol.asyncIterator](){return this[i][Symbol.asyncIterator]()}clean(){return this[i].clean()}on(e,r){return this[i].on(e,r)}},Ke=Rt;var Lt=n(t=>e=>new Ke(e,t),"effects"),G=Lt;var ve=n((t,e,r)=>p(t.next(),s=>{if(!s.done){let o=r(s.value,e);return p(o,()=>ve(t,e+1,r))}}),"innerForEach"),Kt=n((t,e)=>ve(t,0,e),"forEach"),ee=Kt;var vt={deleteFromSource:!0,cleanupPolicy:A.ALL},M=n(t=>t[i],"getFrontCache"),Y=n(t=>t[L],"getRemoteCache"),Ot=n((t,e,r)=>t[i].set(e,r),"introduce"),Oe=n((t,e)=>ee(e,r=>t.delete(r)),"cleanKeys"),Me=n(t=>typeof t.clean=="function"?t.clean():Oe(t,t.keys()),"clean"),Mt=n(t=>{if(t[K].deleteFromSource){if(t[K].cleanupPolicy===A.ALL)return Me(Y(t));if(t[K].cleanupPolicy===A.KEYS)return Oe(Y(t),M(t).keys())}},"cleanRemoteCache"),Yt=class{static{n(this,"RemoteCache")}[i];[L];[K];[l];constructor(e,r,s){this[i]=e,this[L]=r,this[K]={...vt,...s},this[l]=R()}get(e){return p(M(this).get(e),r=>r===void 0?p(Y(this).get(e),s=>p(Ot(this,e,s),()=>(this[l].emit("get",e),s))):(this[l].emit("get",e),r))}set(e,r){return p(M(this).set(e,r),()=>p(Y(this).set(e,r),s=>(this[l].emit("set",e,r),s)))}has(e){return p(M(this).has(e),r=>r||Y(this).has(e))}delete(e){return p(M(this).delete(e),r=>p(this[K].deleteFromSource?Y(this).delete(e):r,s=>(this[l].emit("delete",e),s)))}keys(){return this[L].keys()}values(){return this[L].values()}entries(){return this[L].entries()}[Symbol.iterator](){return this.entries()}[Symbol.asyncIterator](){return this.entries()}clean(){return p(Mt(this),()=>p(Me(M(this)),()=>{this[l].emit("clean")}))}on(e,r){return w(this[l],e,r)}},Ye=Yt;var Nt={cleanupPolicy:A.NONE},zt=n((t,e)=>r=>new Ye(r,t,{...Nt,...e}),"remote"),Q=zt;var Ft=n((...t)=>{if(t.length===0)return"";if(t.length===1){let e=typeof t[0];if(e==="string"||e==="number")return String(t[0])}return JSON.stringify(t)},"getSignatureKey"),te=Ft;var Ne=n((t,e,r)=>{let s=Promise.resolve(r).then(o=>(t.delete(e),o)).catch(o=>(t.delete(e),Promise.reject(o)));return t.set(e,s),s},"registerPromise");function Dt(t,e,r){let s=e||te,o=r||new C,c=new C,m=!1,a=n(function(...f){let u=s.apply(this,f);if(c.has(u))return c.get(u);let h=p(o.has(u),y=>{if(y){let z=o.get(u);return m?Ne(c,u,_(z)):z}let N=t(...f);return m=m||d(N),p(N,z=>p(o.set(u,z),()=>z))});return d(h)?Ne(c,u,h):h},"memoized");return a.cache=o,a.clean=o.clean.bind(o),a}n(Dt,"memo");var O=Dt;var ze=n((t,e,r,s)=>{let o=t.next();return o.done?s:ze(t,e,r+1,e(s,o.value,r))},"reduceInner"),Ht=n((t,e,r)=>ze(t,e,0,r),"reduce"),re=Ht;var Ut=n(t=>{ee(t.values(),e=>{e.deref()||t.delete(e)})},"cleanRefKeys"),he=Ut;var Wt=n((t,e,r,s,o)=>{let c=o.get(r);if(c)return c;let m=O(t,e,r);return he(s),o.set(r,m),s.add(new WeakRef(r)),m},"getMemoizedInstance");function Vt(t,e){let{by:r,from:s}={by:te,...e},o=new WeakMap,c=new Set,m=n(()=>Promise.all(re(c.values(),(f,u)=>{let h=u.deref();if(h){let y=o.get(h);if(y){let N=y.clean();d(N)&&f.push(N)}}return f},[])).then(()=>{he(c)}),"clean"),a=n(function(...f){let u=s.apply(this,f);return Wt(t,r,u,c,o).apply(this,f)},"memoized");return a.clean=m,a}n(Vt,"cacheWith");var se=Vt;var Bt=n(({timeout:t})=>e=>{let r=setTimeout(()=>e.deleteSelf(),t);return r.unref&&r.unref(),e.onRead(()=>{clearTimeout(r),r=setTimeout(()=>e.deleteSelf(),t),r.unref&&r.unref()}),()=>{clearTimeout(r),r=void 0}},"ttl"),Fe=Bt;var jt={async:!1,ttl:1/0,lru:1e3},Gt=n(t=>typeof t=="number"?{maxSize:t}:t,"getLruOptions"),Qt=n(t=>e=>()=>t(e.getSelf()),"createDisposeEffect");function qt(t){let{async:e,ttl:r,lru:s,source:o,dispose:c,effects:m}={...jt,...t},a=Gt(s),f=[...m||[],...c?[Qt(c)]:[],...r!==1/0?[Fe({timeout:r})]:[]],u=F();return u=H(a)(u),u=f.length?G(f)(u):u,u=o?Q(o)(u):u,u=e||o?U()(u):u,u}n(qt,"createCache");var q=qt;var Jt=n(t=>"from"in t,"isCacheWithOptions");function Xt(t,e){if(Jt(e))return se(t,{by:e.cacheBy,from:e.from});let{cacheBy:r,...s}=e;return O(t,r,q(s))}n(Xt,"cacheFn");function Zt(t){return function(e,r,s){if(s.value)s.value=Xt(s.value,t);else throw new Error("Cache decorator can only be applied to methods");return s}}n(Zt,"Cache");var De=Zt;function $t(t,...e){return e.reduce((r,s)=>o=>r(s(o)),t)}n($t,"compose");var fe=$t;var kt=n(t=>{let e;return function(...r){return e||(e=Promise.resolve(t.apply(this,r)).then(s=>(e=void 0,s)).catch(s=>(e=void 0,Promise.reject(s))),e)}},"singlify"),He=kt;var er=n(()=>{let t=new Set;return{register:n(e=>{t.add(e)},"register"),clean:He(()=>Promise.all(re(t.values(),(e,r)=>{let s=r.clean();return d(s)&&e.push(s),e},[])).then(()=>{}))}},"createCacheManager"),Ue=er;var tr=Ue(),ne=tr;var rr=n((t,e)=>n(function(...s){let o=t.apply(this,s);return e.register(o),o},"wrap"),"wrapUtil"),We=rr;function sr(t,e){return n(function(...s){let o=t(...s);return function(c,m,a){let f=o(c,m,a);return e.register(a.value),f}},"wrappedDecorator")}n(sr,"wrapDecorator");var Ve=sr;var{clean:Be}=ne,je=We(se,ne),Ge=Ve(De,ne);0&&(module.exports={Cache,SourceCleanupPolicies,async,cache,cacheWith,clean,compose,createCache,effects,lifeCycle,lru,memo,once,remote,source});