@boredland/node-ts-cache 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.mts +109 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -2
- package/.github/workflows/ci.yml +0 -27
- package/biome.json +0 -50
- package/renovate.json +0 -37
- package/src/cacheContainer.ts +0 -90
- package/src/debug.ts +0 -3
- package/src/hash.ts +0 -15
- package/src/index.ts +0 -4
- package/src/lruStorage.test.ts +0 -613
- package/src/lruStorage.ts +0 -32
- package/src/storage.ts +0 -27
- package/src/withCache.ts +0 -110
- package/tsconfig.json +0 -48
- package/tsdown.config.ts +0 -9
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @boredland/node-ts-cache
|
|
2
2
|
|
|
3
|
+
Simple and extensible caching module supporting multiple caching strategies.
|
|
4
|
+
|
|
3
5
|
[](https://github.com/boredland/node-ts-cache/actions/workflows/ci.yml)
|
|
4
6
|
[](http://opensource.org/licenses/MIT)
|
|
5
7
|
|
|
6
|
-
Simple and extensible caching module supporting decorators and multiple caching strategies.
|
|
7
|
-
|
|
8
8
|
## Install
|
|
9
9
|
|
|
10
10
|
```bash
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
|
|
3
|
+
//#region src/storage.d.ts
|
|
4
|
+
interface Storage {
|
|
5
|
+
/**
|
|
6
|
+
* returns a cached item from the storage layer
|
|
7
|
+
* @param key - key to look up
|
|
8
|
+
*/
|
|
9
|
+
getItem(key: string): Promise<CachedItem | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* sets a cached item on the storage layer
|
|
12
|
+
* @param key - key to store
|
|
13
|
+
* @param content - content to store, including some meta data
|
|
14
|
+
*/
|
|
15
|
+
setItem(key: string, content: CachedItem): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* removes item from the storage layer
|
|
18
|
+
* @param key - key to remove
|
|
19
|
+
*/
|
|
20
|
+
removeItem(key: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* remove all keys from the storage layer
|
|
23
|
+
*/
|
|
24
|
+
clear(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/cacheContainer.d.ts
|
|
28
|
+
type CachedItem<T = unknown> = {
|
|
29
|
+
content: T;
|
|
30
|
+
meta: {
|
|
31
|
+
createdAt: number;
|
|
32
|
+
ttl: number | null;
|
|
33
|
+
isLazy: boolean;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type CachingOptions = {
|
|
37
|
+
/** Number of milliseconds to expire the cachte item - defaults to forever */
|
|
38
|
+
ttl: number | null;
|
|
39
|
+
/** (Default: true) If true, expired cache entries will be deleted on touch and returned anyway. If false, entries will be deleted after the given ttl. */
|
|
40
|
+
isLazy: boolean;
|
|
41
|
+
/** (Default: JSON.stringify combination of className, methodName and call args) */
|
|
42
|
+
calculateKey: (data: {
|
|
43
|
+
/** The class name for the method being decorated */
|
|
44
|
+
className: string;
|
|
45
|
+
/** The method name being decorated */
|
|
46
|
+
methodName: string;
|
|
47
|
+
/** The arguments passed to the method when called */
|
|
48
|
+
args: unknown[];
|
|
49
|
+
}) => string;
|
|
50
|
+
};
|
|
51
|
+
declare class CacheContainer {
|
|
52
|
+
private storage;
|
|
53
|
+
constructor(storage: Storage);
|
|
54
|
+
getItem<T>(key: string): Promise<{
|
|
55
|
+
content: T;
|
|
56
|
+
meta: {
|
|
57
|
+
expired: boolean;
|
|
58
|
+
createdAt: number;
|
|
59
|
+
};
|
|
60
|
+
} | undefined>;
|
|
61
|
+
setItem(key: string, content: unknown, options?: Partial<CachingOptions>): Promise<void>;
|
|
62
|
+
clear(): Promise<void>;
|
|
63
|
+
private isItemExpired;
|
|
64
|
+
unsetKey(key: string): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/lruStorage.d.ts
|
|
68
|
+
declare class LRUStorage implements Storage {
|
|
69
|
+
private cache;
|
|
70
|
+
constructor({
|
|
71
|
+
max
|
|
72
|
+
}?: Partial<LRUCache<string, CachedItem, unknown>>);
|
|
73
|
+
clear(): Promise<void>;
|
|
74
|
+
getItem(key: string): Promise<CachedItem | undefined>;
|
|
75
|
+
setItem(key: string, content: CachedItem): Promise<void>;
|
|
76
|
+
removeItem(key: string): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/withCache.d.ts
|
|
80
|
+
type WithCacheOptions<Parameters, Result> = Partial<Omit<CachingOptions, "calculateKey" | "isLazy">> & {
|
|
81
|
+
/** an optional prefix to prepend to the key */
|
|
82
|
+
prefix?: string;
|
|
83
|
+
/** an optional function to calculate a key based on the parameters of the wrapped function */
|
|
84
|
+
calculateKey?: (input: Parameters) => string;
|
|
85
|
+
/** an optional function that is called just before the result is stored to the storage */
|
|
86
|
+
shouldStore?: (result: Awaited<Result>) => boolean;
|
|
87
|
+
/**
|
|
88
|
+
* caching strategy to use
|
|
89
|
+
* - "lazy": cache is populated in the background after returning the result
|
|
90
|
+
* - "swr": stale-while-revalidate, cache is returned if present and updated in the background
|
|
91
|
+
* - "eager": cache is populated before returning the result
|
|
92
|
+
* @default "eager"
|
|
93
|
+
*/
|
|
94
|
+
strategy?: "lazy" | "swr" | "eager";
|
|
95
|
+
/**
|
|
96
|
+
* Concurrency for revalidation queue
|
|
97
|
+
* @default 1
|
|
98
|
+
*/
|
|
99
|
+
revalidationConcurrency?: number;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* wrapped function factory
|
|
103
|
+
* @param container - cache container to create the fn for
|
|
104
|
+
* @returns wrapping function
|
|
105
|
+
*/
|
|
106
|
+
declare const withCacheFactory: (container: CacheContainer) => <Parameters extends Array<unknown>, Result extends Promise<unknown>>(operation: (...parameters: Parameters) => Result, options?: WithCacheOptions<Parameters, Result>) => (...parameters: Parameters) => Promise<Result>;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { CacheContainer, CachedItem, CachingOptions, LRUStorage, Storage, withCacheFactory };
|
|
109
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/storage.ts","../src/cacheContainer.ts","../src/lruStorage.ts","../src/withCache.ts"],"sourcesContent":[],"mappings":";;;UAEiB,OAAA;;AAAjB;;;EAY+B,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAPR,OAOQ,CAPA,UAOA,GAAA,SAAA,CAAA;EAAa;;;;;gCAAb,aAAa;;ACX5C;AASA;AAgBA;EAC8B,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EDTJ,OCSI,CAAA,IAAA,CAAA;EAKjB;;;EAwBD,KAAA,EAAA,EDjCF,OCiCE,CAAA,IAAA,CAAA;;;;KAvDA;WACF;EDFO,IAAA,EAAA;IAKc,SAAA,EAAA,MAAA;IAAR,GAAA,EAAA,MAAA,GAAA,IAAA;IAOQ,MAAA,EAAA,OAAA;EAAa,CAAA;CAMlB;AAKhB,KCbE,cAAA,GDaF;EAAO;;;;ECtBL;EASA,YAAA,EAAA,CAAA,IAAc,EAAA;IAgBb;IACiB,SAAA,EAAA,MAAA;IAKjB;IADT,UAAA,EAAA,MAAA;IAyBgB;IAAR,IAAA,EAAA,OAAA,EAAA;EACR,CAAA,EAAA,GAAA,MAAA;CAgBmB;AAWc,cA1DxB,cAAA,CA0DwB;EAAO,QAAA,OAAA;uBAzDd;2BAI1B;aACS;IC9BA,IAAA,EAAA;MAIX,OAAA,EAAA,OAAA;MAC2B,SAAA,EAAA,MAAA;IAAjB,CAAA;EAAR,CAAA,GAAA,SAAA,CAAA;EAMY,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EAAA,OAAA,EAAA,OAAA,CAAA,ED2CJ,OC3CI,CD2CI,cC3CJ,CAAA,CAAA,ED4CZ,OC5CY,CAAA,IAAA,CAAA;EAIU,KAAA,CAAA,CAAA,EDwDH,OCxDG,CAAA,IAAA,CAAA;EAAA,QAAA,aAAA;EAKW,QAAA,CAAA,GAAA,EAAA,MAAA,CAAA,ED8DA,OC9DA,CAAA,IAAA,CAAA;;;;AFtBpB,cEEJ,UAAA,YAAsB,OFFX,CAAA;EAKO,QAAA,KAAA;EAAR,WAAA,CAAA;IAAA;EAAA,CAAA,CAAA,EEEnB,OFFmB,CEEX,QFFW,CAAA,MAAA,EEEM,UFFN,EAAA,OAAA,CAAA,CAAA;EAOQ,KAAA,CAAA,CAAA,EECf,OFDe,CAAA,IAAA,CAAA;EAAa,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EEKlB,OFLkB,CEKlB,UFLkB,GAAA,SAAA,CAAA;EAMlB,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EEIW,UFJX,CAAA,EEIqB,OFJrB,CAAA,IAAA,CAAA;EAKhB,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EEGmB,OFHnB,CAAA,IAAA,CAAA;;;;KGnBL,uCAAuC,QAC1C,KAAK;;EHLU,MAAA,CAAA,EAAA,MAAO;EAKO;EAAR,YAAA,CAAA,EAAA,CAAA,KAAA,EGKE,UHLF,EAAA,GAAA,MAAA;EAOQ;EAAa,WAAA,CAAA,EAAA,CAAA,MAAA,EGAnB,OHAmB,CGAX,MHAW,CAAA,EAAA,GAAA,OAAA;EAMlB;;;;;;ACjB1B;EASY,QAAA,CAAA,EAAA,MAAc,GAAA,KAAA,GAAA,OAAA;EAgBb;;;;EA8BO,uBAAA,CAAA,EAAA,MAAA;CAAR;;;;;;cEvBC,8BAA+B,uCAQrB,+BACJ,6CAEY,eAAe,kBACjC,iBAAiB,YAAY,4BAET,eAAa,QAAQ"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createRequire as e}from"node:module";import{debug as t}from"node:util";var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=e(import.meta.url);const f=t(`node-ts-cache`);var p=class{constructor(e){this.storage=e}async getItem(e){let t=await this.storage.getItem(e);if(!t)return;let n={content:t.content,meta:{createdAt:t.meta.createdAt,expired:this.isItemExpired(t)}};if(n.meta.expired&&await this.unsetKey(e),!(n.meta.expired&&!t.meta.isLazy))return n}async setItem(e,t,n){let r={ttl:null,isLazy:!0,...n},i={createdAt:Date.now(),isLazy:r.isLazy,ttl:r.ttl};await this.storage.setItem(e,{meta:i,content:t})}async clear(){await this.storage.clear(),f(`Cleared cache`)}isItemExpired(e){return e.meta.ttl===null?!1:Date.now()>e.meta.createdAt+e.meta.ttl}async unsetKey(e){await this.storage.removeItem(e)}};const m=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,h=new Set,g=typeof process==`object`&&process?process:{},_=(e,t,n,r)=>{typeof g.emitWarning==`function`?g.emitWarning(e,t,n,r):console.error(`[${n}] ${t}: ${e}`)};let v=globalThis.AbortController,y=globalThis.AbortSignal;if(v===void 0){y=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(e,t){this._onabort.push(t)}},v=class{constructor(){t()}signal=new y;abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=!0;for(let t of this.signal._onabort)t(e);this.signal.onabort?.(e)}}};let e=g.env?.LRU_CACHE_IGNORE_AC_WARNING!==`1`,t=()=>{e&&(e=!1,_("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.",`NO_ABORT_CONTROLLER`,`ENOTSUP`,t))}}const b=e=>!h.has(e),x=e=>e&&e===Math.floor(e)&&e>0&&isFinite(e),S=e=>x(e)?e<=2**8?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?C:null:null;var C=class extends Array{constructor(e){super(e),this.fill(0)}},w=class e{heap;length;static#e=!1;static create(t){let n=S(t);if(!n)return[];e.#e=!0;let r=new e(t,n);return e.#e=!1,r}constructor(t,n){if(!e.#e)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new n(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},T=class e{#e;#t;#n;#r;#i;#a;#o;#s;get perf(){return this.#s}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#x,sizes:e.#y,keyMap:e.#u,keyList:e.#d,valList:e.#f,next:e.#p,prev:e.#m,get head(){return e.#h},get tail(){return e.#g},free:e.#_,isBackgroundFetch:t=>e.#B(t),backgroundFetch:(t,n,r,i)=>e.#z(t,n,r,i),moveToTail:t=>e.#H(t),indexes:t=>e.#F(t),rindexes:t=>e.#I(t),isStale:t=>e.#A(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#l}get size(){return this.#c}get fetchMethod(){return this.#a}get memoMethod(){return this.#o}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#i}constructor(t){let{max:n=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:s,allowStale:c,dispose:l,onInsert:u,disposeAfter:d,noDisposeOnSet:f,noUpdateTTL:p,maxSize:g=0,maxEntrySize:v=0,sizeCalculation:y,fetchMethod:C,memoMethod:T,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:D,allowStaleOnFetchRejection:O,allowStaleOnFetchAbort:k,ignoreFetchAbort:A,perf:j}=t;if(j!==void 0&&typeof j?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#s=j??m,n!==0&&!x(n))throw TypeError(`max option must be a nonnegative integer`);let M=n?S(n):Array;if(!M)throw Error(`invalid max value: `+n);if(this.#e=n,this.#t=g,this.maxEntrySize=v||this.#t,this.sizeCalculation=y,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(T!==void 0&&typeof T!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#o=T,C!==void 0&&typeof C!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#a=C,this.#C=!!C,this.#u=new Map,this.#d=Array(n).fill(void 0),this.#f=Array(n).fill(void 0),this.#p=new M(n),this.#m=new M(n),this.#h=0,this.#g=0,this.#_=w.create(n),this.#c=0,this.#l=0,typeof l==`function`&&(this.#n=l),typeof u==`function`&&(this.#r=u),typeof d==`function`?(this.#i=d,this.#v=[]):(this.#i=void 0,this.#v=void 0),this.#S=!!this.#n,this.#T=!!this.#r,this.#w=!!this.#i,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!p,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!O,this.allowStaleOnFetchAbort=!!k,this.ignoreFetchAbort=!!A,this.maxEntrySize!==0){if(this.#t!==0&&!x(this.#t))throw TypeError(`maxSize must be a positive integer if specified`);if(!x(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#j()}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!D,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!s,this.ttlResolution=x(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!x(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#E()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t=`LRU_CACHE_UNBOUNDED`;b(t)&&(h.add(t),_(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,t,e))}}getRemainingTTL(e){return this.#u.has(e)?1/0:0}#E(){let e=new C(this.#e),t=new C(this.#e);this.#x=e,this.#b=t,this.#k=(n,r,i=this.#s.now())=>{if(t[n]=r===0?0:i,e[n]=r,r!==0&&this.ttlAutopurge){let e=setTimeout(()=>{this.#A(n)&&this.#U(this.#d[n],`expire`)},r+1);e.unref&&e.unref()}},this.#D=n=>{t[n]=e[n]===0?0:this.#s.now()},this.#O=(i,a)=>{if(e[a]){let o=e[a],s=t[a];if(!o||!s)return;i.ttl=o,i.start=s,i.now=n||r(),i.remainingTTL=o-(i.now-s)}};let n=0,r=()=>{let e=this.#s.now();if(this.ttlResolution>0){n=e;let t=setTimeout(()=>n=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=i=>{let a=this.#u.get(i);if(a===void 0)return 0;let o=e[a],s=t[a];return!o||!s?1/0:o-((n||r())-s)},this.#A=i=>{let a=t[i],o=e[i];return!!o&&!!a&&(n||r())-a>o}}#D=()=>{};#O=()=>{};#k=()=>{};#A=()=>!1;#j(){let e=new C(this.#e);this.#l=0,this.#y=e,this.#M=t=>{this.#l-=e[t],e[t]=0},this.#P=(e,t,n,r)=>{if(this.#B(t))return 0;if(!x(n))if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!x(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`);return n},this.#N=(t,n,r)=>{if(e[t]=n,this.#t){let n=this.#t-e[t];for(;this.#l>n;)this.#R(!0)}this.#l+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#l)}}#M=e=>{};#N=(e,t,n)=>{};#P=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#F({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#g;!(!this.#L(t)||((e||!this.#A(t))&&(yield t),t===this.#h));)t=this.#m[t]}*#I({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#h;!(!this.#L(t)||((e||!this.#A(t))&&(yield t),t===this.#g));)t=this.#p[t]}#L(e){return e!==void 0&&this.#u.get(this.#d[e])===e}*entries(){for(let e of this.#F())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#B(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*rentries(){for(let e of this.#I())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#B(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*keys(){for(let e of this.#F()){let t=this.#d[e];t!==void 0&&!this.#B(this.#f[e])&&(yield t)}}*rkeys(){for(let e of this.#I()){let t=this.#d[e];t!==void 0&&!this.#B(this.#f[e])&&(yield t)}}*values(){for(let e of this.#F())this.#f[e]!==void 0&&!this.#B(this.#f[e])&&(yield this.#f[e])}*rvalues(){for(let e of this.#I())this.#f[e]!==void 0&&!this.#B(this.#f[e])&&(yield this.#f[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#F()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#d[n],this))return this.get(this.#d[n],t)}}forEach(e,t=this){for(let n of this.#F()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}rforEach(e,t=this){for(let n of this.#I()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}purgeStale(){let e=!1;for(let t of this.#I({allowStale:!0}))this.#A(t)&&(this.#U(this.#d[t],`expire`),e=!0);return e}info(e){let t=this.#u.get(e);if(t===void 0)return;let n=this.#f[t],r=this.#B(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#x&&this.#b){let e=this.#x[t],n=this.#b[t];e&&n&&(i.ttl=e-(this.#s.now()-n),i.start=Date.now())}return this.#y&&(i.size=this.#y[t]),i}dump(){let e=[];for(let t of this.#F({allowStale:!0})){let n=this.#d[t],r=this.#f[t],i=this.#B(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#x&&this.#b){a.ttl=this.#x[t];let e=this.#s.now()-this.#b[t];a.start=Math.floor(Date.now()-e)}this.#y&&(a.size=this.#y[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#s.now()-e}this.set(t,n.value,n)}}set(e,t,n={}){if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:i,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:s}=n,{noUpdateTTL:c=this.noUpdateTTL}=n,l=this.#P(e,t,n.size||0,o);if(this.maxEntrySize&&l>this.maxEntrySize)return s&&(s.set=`miss`,s.maxEntrySizeExceeded=!0),this.#U(e,`set`),this;let u=this.#c===0?void 0:this.#u.get(e);if(u===void 0)u=this.#c===0?this.#g:this.#_.length===0?this.#c===this.#e?this.#R(!1):this.#c:this.#_.pop(),this.#d[u]=e,this.#f[u]=t,this.#u.set(e,u),this.#p[this.#g]=u,this.#m[u]=this.#g,this.#g=u,this.#c++,this.#N(u,l,s),s&&(s.set=`add`),c=!1,this.#T&&this.#r?.(t,e,`add`);else{this.#H(u);let n=this.#f[u];if(t!==n){if(this.#C&&this.#B(n)){n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:t}=n;t!==void 0&&!a&&(this.#S&&this.#n?.(t,e,`set`),this.#w&&this.#v?.push([t,e,`set`]))}else a||(this.#S&&this.#n?.(n,e,`set`),this.#w&&this.#v?.push([n,e,`set`]));if(this.#M(u),this.#N(u,l,s),this.#f[u]=t,s){s.set=`replace`;let e=n&&this.#B(n)?n.__staleWhileFetching:n;e!==void 0&&(s.oldValue=e)}}else s&&(s.set=`update`);this.#T&&this.onInsert?.(t,e,t===n?`update`:`replace`)}if(r!==0&&!this.#x&&this.#E(),this.#x&&(c||this.#k(u,r,i),s&&this.#O(s,u)),!a&&this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return this}pop(){try{for(;this.#c;){let e=this.#f[this.#h];if(this.#R(!0),this.#B(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}#R(e){let t=this.#h,n=this.#d[t],r=this.#f[t];return this.#C&&this.#B(r)?r.__abortController.abort(Error(`evicted`)):(this.#S||this.#w)&&(this.#S&&this.#n?.(r,n,`evict`),this.#w&&this.#v?.push([r,n,`evict`])),this.#M(t),e&&(this.#d[t]=void 0,this.#f[t]=void 0,this.#_.push(t)),this.#c===1?(this.#h=this.#g=0,this.#_.length=0):this.#h=this.#p[t],this.#u.delete(n),this.#c--,t}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#u.get(e);if(i!==void 0){let e=this.#f[i];if(this.#B(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#A(i))r&&(r.has=`stale`,this.#O(r,i));else return n&&this.#D(i),r&&(r.has=`hit`,this.#O(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{allowStale:n=this.allowStale}=t,r=this.#u.get(e);if(r===void 0||!n&&this.#A(r))return;let i=this.#f[r];return this.#B(i)?i.__staleWhileFetching:i}#z(e,t,n,r){let i=t===void 0?void 0:this.#f[t];if(this.#B(i))return i;let a=new v,{signal:o}=n;o?.addEventListener(`abort`,()=>a.abort(o.reason),{signal:a.signal});let s={signal:a.signal,options:n,context:r},c=(r,i=!1)=>{let{aborted:o}=a.signal,c=n.ignoreFetchAbort&&r!==void 0;if(n.status&&(o&&!i?(n.status.fetchAborted=!0,n.status.fetchError=a.signal.reason,c&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),o&&!c&&!i)return u(a.signal.reason);let l=f,d=this.#f[t];return(d===f||c&&i&&d===void 0)&&(r===void 0?l.__staleWhileFetching===void 0?this.#U(e,`fetch`):this.#f[t]=l.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.set(e,r,s.options))),r},l=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),u(e)),u=r=>{let{aborted:i}=a.signal,o=i&&n.allowStaleOnFetchAbort,s=o||n.allowStaleOnFetchRejection,c=s||n.noDeleteOnFetchRejection,l=f;if(this.#f[t]===f&&(!c||l.__staleWhileFetching===void 0?this.#U(e,`fetch`):o||(this.#f[t]=l.__staleWhileFetching)),s)return n.status&&l.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),l.__staleWhileFetching;if(l.__returned===l)throw r},d=(t,r)=>{let o=this.#a?.(e,i,s);o&&o instanceof Promise&&o.then(e=>t(e===void 0?void 0:e),r),a.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>c(e,!0)))})};n.status&&(n.status.fetchDispatched=!0);let f=new Promise(d).then(c,l),p=Object.assign(f,{__abortController:a,__staleWhileFetching:i,__returned:void 0});return t===void 0?(this.set(e,p,{...s.options,status:void 0}),t=this.#u.get(e)):this.#f[t]=p,p}#B(e){if(!this.#C)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof v}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(!this.#C)return g&&(g.fetch=`get`),this.get(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#u.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#z(e,y,v,m);return t.__returned=t}else{let t=this.#f[y];if(this.#B(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#A(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#H(y),r&&this.#D(y),g&&this.#O(g,y),t;let a=this.#z(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let n=this.#o;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,forceRefresh:i,...a}=t,o=this.get(e,a);if(!i&&o!==void 0)return o;let s=n(e,o,{options:a,context:r});return this.set(e,s,a),s}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#u.get(e);if(o!==void 0){let t=this.#f[o],s=this.#B(t);return a&&this.#O(a,o),this.#A(o)?(a&&(a.get=`stale`),s?(a&&n&&t.__staleWhileFetching!==void 0&&(a.returnedStale=!0),n?t.__staleWhileFetching:void 0):(i||this.#U(e,`expire`),a&&n&&(a.returnedStale=!0),n?t:void 0)):(a&&(a.get=`hit`),s?t.__staleWhileFetching:(this.#H(o),r&&this.#D(o),t))}else a&&(a.get=`miss`)}#V(e,t){this.#m[t]=e,this.#p[e]=t}#H(e){e!==this.#g&&(e===this.#h?this.#h=this.#p[e]:this.#V(this.#m[e],this.#p[e]),this.#V(this.#g,e),this.#g=e)}delete(e){return this.#U(e,`delete`)}#U(e,t){let n=!1;if(this.#c!==0){let r=this.#u.get(e);if(r!==void 0)if(n=!0,this.#c===1)this.#W(t);else{this.#M(r);let n=this.#f[r];if(this.#B(n)?n.__abortController.abort(Error(`deleted`)):(this.#S||this.#w)&&(this.#S&&this.#n?.(n,e,t),this.#w&&this.#v?.push([n,e,t])),this.#u.delete(e),this.#d[r]=void 0,this.#f[r]=void 0,r===this.#g)this.#g=this.#m[r];else if(r===this.#h)this.#h=this.#p[r];else{let e=this.#m[r];this.#p[e]=this.#p[r];let t=this.#p[r];this.#m[t]=this.#m[r]}this.#c--,this.#_.push(r)}}if(this.#w&&this.#v?.length){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return n}clear(){return this.#W(`delete`)}#W(e){for(let t of this.#I({allowStale:!0})){let n=this.#f[t];if(this.#B(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#d[t];this.#S&&this.#n?.(n,r,e),this.#w&&this.#v?.push([n,r,e])}}if(this.#u.clear(),this.#f.fill(void 0),this.#d.fill(void 0),this.#x&&this.#b&&(this.#x.fill(0),this.#b.fill(0)),this.#y&&this.#y.fill(0),this.#h=0,this.#g=0,this.#_.length=0,this.#l=0,this.#c=0,this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}},E=class{cache;constructor({max:e=1e4}={}){this.cache=new T({max:e})}async clear(){this.cache.clear()}async getItem(e){return this.cache.get(e)}async setItem(e,t){this.cache.set(e,t)}async removeItem(e){this.cache.delete(e)}},D=u(c(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=`~`;function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1));function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,i,o){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var s=new a(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function s(e,t){--e._eventsCount===0?e._events=new i:delete e._events[t]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)n.call(t,i)&&e.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},c.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=Array(a);i<a;i++)o[i]=n[i].fn;return o},c.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},c.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var c=this._events[s],l=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,a),!0;case 6:return c.fn.call(c.context,t,n,i,a,o),!0}for(d=1,u=Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!u)for(p=1,u=Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},c.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&s(this,a);else{for(var c=0,l=[],u=o.length;c<u;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&l.push(o[c]);l.length?this._events[a]=l.length===1?l[0]:l:s(this,a)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t!==void 0&&(t.exports=c)}))(),1),O=class e extends Error{name=`TimeoutError`;constructor(t,n){super(t,n),Error.captureStackTrace?.(this,e)}};const k=e=>e.reason??new DOMException(`This operation was aborted.`,`AbortError`);function A(e,t){let{milliseconds:n,fallback:r,message:i,customTimers:a={setTimeout,clearTimeout},signal:o}=t,s,c,l=new Promise((t,l)=>{if(typeof n!=`number`||Math.sign(n)!==1)throw TypeError(`Expected \`milliseconds\` to be a positive number, got \`${n}\``);if(o?.aborted){l(k(o));return}if(o&&(c=()=>{l(k(o))},o.addEventListener(`abort`,c,{once:!0})),e.then(t,l),n===1/0)return;let u=new O;s=a.setTimeout.call(void 0,()=>{if(r){try{t(r())}catch(e){l(e)}return}typeof e.cancel==`function`&&e.cancel(),i===!1?t():i instanceof Error?l(i):(u.message=i??`Promise timed out after ${n} milliseconds`,l(u))},n)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener(`abort`,c)});return l.clear=()=>{a.clearTimeout.call(void 0,s),s=void 0},l}function j(e,t,n){let r=0,i=e.length;for(;i>0;){let a=Math.trunc(i/2),o=r+a;n(e[o],t)<=0?(r=++o,i-=a+1):i=a}return r}var M=class{#e=[];enqueue(e,t){let{priority:n=0,id:r}=t??{},i={priority:n,id:r,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let a=j(this.#e,i,(e,t)=>t.priority-e.priority);this.#e.splice(a,0,i)}setPriority(e,t){let n=this.#e.findIndex(t=>t.id===e);if(n===-1)throw ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[r]=this.#e.splice(n,1);this.enqueue(r.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(e=>e.run)}get size(){return this.#e.length}},N=class extends D.default{#e;#t;#n=0;#r;#i=!1;#a=!1;#o;#s=0;#c=0;#l;#u;#d;#f;#p=0;#m;#h;#g=1n;#_=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:M,...e},!(typeof e.intervalCap==`number`&&e.intervalCap>=1))throw TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??``}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??``}\` (${typeof e.interval})`);if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===1/0||e.interval===0,this.#r=e.intervalCap,this.#o=e.interval,this.#d=new e.queueClass,this.#f=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#h=e.autoStart===!1,this.#M()}get#v(){return this.#t||this.#n<this.#r}get#y(){return this.#p<this.#m}#b(){this.#p--,this.#p===0&&this.emit(`pendingZero`),this.#E(),this.emit(`next`)}#x(){this.#O(),this.#D(),this.#u=void 0}get#S(){let e=Date.now();if(this.#l===void 0){let t=this.#s-e;if(t<0){if(this.#c>0){let t=e-this.#c;if(t<this.#o)return this.#C(this.#o-t),!0}this.#n=this.#e?this.#p:0}else return this.#C(t),!0}return!1}#C(e){this.#u===void 0&&(this.#u=setTimeout(()=>{this.#x()},e))}#w(){this.#l&&=(clearInterval(this.#l),void 0)}#T(){this.#u&&=(clearTimeout(this.#u),void 0)}#E(){if(this.#d.size===0)return this.#w(),this.emit(`empty`),this.#p===0&&(this.#T(),this.emit(`idle`)),!1;let e=!1;if(!this.#h){let t=!this.#S;if(this.#v&&this.#y){let n=this.#d.dequeue();this.#t||(this.#n++,this.#N()),this.emit(`active`),this.#c=Date.now(),n(),t&&this.#D(),e=!0}}return e}#D(){this.#t||this.#l!==void 0||(this.#l=setInterval(()=>{this.#O()},this.#o),this.#s=Date.now()+this.#o)}#O(){this.#n===0&&this.#p===0&&this.#l&&this.#w(),this.#n=this.#e?this.#p:0,this.#k(),this.#N()}#k(){for(;this.#E(););}get concurrency(){return this.#m}set concurrency(e){if(!(typeof e==`number`&&e>=1))throw TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#m=e,this.#k()}async#A(e){return new Promise((t,n)=>{e.addEventListener(`abort`,()=>{n(e.reason)},{once:!0})})}setPriority(e,t){if(typeof t!=`number`||!Number.isFinite(t))throw TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#d.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#g++).toString(),t={timeout:this.timeout,...t},new Promise((n,r)=>{let i=Symbol(`task-${t.id}`);this.#d.enqueue(async()=>{this.#p++,this.#_.set(i,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});try{try{t.signal?.throwIfAborted()}catch(e){throw this.#t||this.#n--,this.#_.delete(i),e}let r=e({signal:t.signal});t.timeout&&(r=A(Promise.resolve(r),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#p} running, ${this.#d.size} waiting)`})),t.signal&&(r=Promise.race([r,this.#A(t.signal)]));let a=await r;n(a),this.emit(`completed`,a)}catch(e){r(e),this.emit(`error`,e)}finally{this.#_.delete(i),queueMicrotask(()=>{this.#b()})}},t),this.emit(`add`),this.#E()})}async addAll(e,t){return Promise.all(e.map(async e=>this.add(e,t)))}start(){return this.#h?(this.#h=!1,this.#k(),this):this}pause(){this.#h=!0}clear(){this.#d=new this.#f,this.#P()}async onEmpty(){this.#d.size!==0&&await this.#j(`empty`)}async onSizeLessThan(e){this.#d.size<e||await this.#j(`next`,()=>this.#d.size<e)}async onIdle(){this.#p===0&&this.#d.size===0||await this.#j(`idle`)}async onPendingZero(){this.#p!==0&&await this.#j(`pendingZero`)}async onRateLimit(){this.isRateLimited||await this.#j(`rateLimit`)}async onRateLimitCleared(){this.isRateLimited&&await this.#j(`rateLimitCleared`)}async onError(){return new Promise((e,t)=>{let n=e=>{this.off(`error`,n),t(e)};this.on(`error`,n)})}async#j(e,t){return new Promise(n=>{let r=()=>{t&&!t()||(this.off(e,r),n())};this.on(e,r)})}get size(){return this.#d.size}sizeBy(e){return this.#d.filter(e).length}get pending(){return this.#p}get isPaused(){return this.#h}#M(){this.#t||(this.on(`add`,()=>{this.#d.size>0&&this.#N()}),this.on(`next`,()=>{this.#N()}))}#N(){this.#t||this.#a||(this.#a=!0,queueMicrotask(()=>{this.#a=!1,this.#P()}))}#P(){let e=this.#i,t=!this.#t&&this.#n>=this.#r&&this.#d.size>0;t!==e&&(this.#i=t,this.emit(t?`rateLimit`:`rateLimitCleared`))}get isRateLimited(){return this.#i}get isSaturated(){return this.#p===this.#m&&this.#d.size>0||this.isRateLimited&&this.#d.size>0}get runningTasks(){return[...this.#_.values()].map(e=>({...e}))}},P=c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.instanceOfHashable=e.guessType=e.guessObjectType=e.TYPE_MAP=void 0,e.TYPE_MAP={Array:`array`,Int8Array:`typedarray`,Uint8Array:`typedarray`,Uint8ClampedArray:`typedarray`,Int16Array:`typedarray`,Uint16Array:`typedarray`,Int32Array:`typedarray`,Uint32Array:`typedarray`,Float32Array:`typedarray`,Float64Array:`typedarray`,BigUint64Array:`typedarray`,BigInt64Array:`typedarray`,Buffer:`typedarray`,Map:`map`,Set:`set`,Date:`date`,String:`string`,Number:`number`,BigInt:`bigint`,Boolean:`boolean`,Object:`object`},e.guessObjectType=t=>{if(t===null)return`null`;if((0,e.instanceOfHashable)(t))return`hashable`;let n=t?.constructor?.name??`unknown`;return e.TYPE_MAP[n]||`unknown`},e.guessType=t=>{let n=typeof t;return n===`object`?(0,e.guessObjectType)(t):n},e.instanceOfHashable=e=>typeof e.toHashableString==`function`})),F=c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e._mapSort=e._map=e._objectSort=e._object=e._setCoerce=e._set=e._setSort=e._setSortCoerce=e._typedArray=e._typedArraySort=e._array=e._arraySort=e._date=e._dateCoerce=e._functionTrim=e._functionTrimCoerce=e._function=e._functionCoerce=e._null=e._nullCoerce=e._undefined=e._undefinedCoerce=e._symbol=e._symbolCoerce=e._boolean=e._booleanCoerce=e._bigInt=e._bigIntCoerce=e._number=e._numberCoerce=e._stringTrim=e._stringTrimCoerce=e._string=e._stringCoerce=e._hashable=e.PREFIX=void 0;let t=P();e.PREFIX={string:`<:s>`,number:`<:n>`,bigint:`<:bi>`,boolean:`<:b>`,symbol:`<:smbl>`,undefined:`<:undf>`,null:`<:null>`,function:`<:func>`,array:``,date:`<:date>`,set:`<:set>`,map:`<:map>`};function n(e){return e.toHashableString()}e._hashable=n;function r(e){return e}e._stringCoerce=r;function i(t){return e.PREFIX.string+`:`+t}e._string=i;function a(e){return e.replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._stringTrimCoerce=a;function o(t){return e.PREFIX.string+`:`+t.replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._stringTrim=o;function s(e){return e.toString()}e._numberCoerce=s;function c(t){return`${e.PREFIX.number}:${t}`}e._number=c;function l(e){return e.toString()}e._bigIntCoerce=l;function u(t){return`${e.PREFIX.bigint}:${t.toString()}`}e._bigInt=u;function d(e){return e?`1`:`0`}e._booleanCoerce=d;function f(t){return e.PREFIX.boolean+`:`+t.toString()}e._boolean=f;function p(){return e.PREFIX.symbol}e._symbolCoerce=p;function m(t){return e.PREFIX.symbol+`:`+t.toString()}e._symbol=m;function h(){return``}e._undefinedCoerce=h;function g(){return e.PREFIX.undefined}e._undefined=g;function _(){return``}e._nullCoerce=_;function v(){return e.PREFIX.null}e._null=v;function y(e){return e.name+`=>`+e.toString()}e._functionCoerce=y;function b(t){return e.PREFIX.function+`:`+t.name+`=>`+t.toString()}e._function=b;function x(e){return e.name+`=>`+e.toString().replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._functionTrimCoerce=x;function S(t){return e.PREFIX.function+`:`+t.name+`=>`+t.toString().replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._functionTrim=S;function C(e){return e.toISOString()}e._dateCoerce=C;function w(t){return e.PREFIX.date+`:`+t.toISOString()}e._date=w;function T(e){let n=this;return`[`+e.map(e=>n[(0,t.guessType)(e)](e)).sort().toString()+`]`}e._arraySort=T;function E(e){let n=this;return`[`+e.map(e=>n[(0,t.guessType)(e)](e)).toString()+`]`}e._array=E;function D(e){let n=this;return`[`+Array.prototype.slice.call(e).map(e=>n[(0,t.guessType)(e)](e)).sort().toString()+`]`}e._typedArraySort=D;function O(e){let n=this;return`[`+Array.prototype.slice.call(e).map(e=>n[(0,t.guessType)(e)](e)).toString()+`]`}e._typedArray=O;function k(e){return T.call(this,Array.from(e))}e._setSortCoerce=k;function A(t){return`${e.PREFIX.set}:${T.call(this,Array.from(t))}`}e._setSort=A;function j(t){return`${e.PREFIX.set}:${E.call(this,Array.from(t))}`}e._set=j;function M(e){return E.call(this,Array.from(e))}e._setCoerce=M;function N(e){let n=this,r=Object.keys(e),i=[];for(let a of r){let r=e[a],o=(0,t.guessType)(r);i.push(a+`:`+n[o](r))}return`{`+i.toString()+`}`}e._object=N;function F(e){let n=this,r=Object.keys(e).sort(),i=[];for(let a of r){let r=e[a],o=(0,t.guessType)(r);i.push(a+`:`+n[o](r))}return`{`+i.toString()+`}`}e._objectSort=F;function I(e){let n=this,r=Array.from(e),i=[];for(let e of r){let[r,a]=e;i.push([n[(0,t.guessType)(r)](r),n[(0,t.guessType)(a)](a)])}return`[`+i.join(`;`)+`]`}e._map=I;function L(e){let n=this,r=Array.from(e),i=[];for(let e of r){let[r,a]=e;i.push([n[(0,t.guessType)(r)](r),n[(0,t.guessType)(a)](a)])}return`[`+i.sort().join(`;`)+`]`}e._mapSort=L})),I=c((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t}),r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(e,`__esModule`,{value:!0}),e.objectSorter=void 0;let i=r(F()),a=P();e.objectSorter=e=>{let{sort:t,coerce:n,trim:r}={sort:!0,coerce:!0,trim:!1,...e},o={array:typeof t==`boolean`?t:t?.array??!1,typedArray:typeof t==`boolean`?!1:t?.typedArray??!1,object:typeof t==`boolean`?t:t?.object??!1,set:typeof t==`boolean`?t:t?.set??!1,map:typeof t==`boolean`?t:t?.map??!1},s={boolean:typeof n==`boolean`?n:n?.boolean??!1,number:typeof n==`boolean`?n:n?.number??!1,bigint:typeof n==`boolean`?n:n?.bigint??!1,string:typeof n==`boolean`?n:n?.string??!1,undefined:typeof n==`boolean`?n:n?.undefined??!1,null:typeof n==`boolean`?n:n?.null??!1,symbol:typeof n==`boolean`?n:n?.symbol??!1,function:typeof n==`boolean`?n:n?.function??!1,date:typeof n==`boolean`?n:n?.date??!1,set:typeof n==`boolean`?n:n?.set??!1},c={string:typeof r==`boolean`?r:r?.string??!1,function:typeof r==`boolean`?r:r?.function??!1},l={unknown:function(e){let t=e.constructor?.name??`unknonw`,n=`unknown`;return typeof e.toString==`function`?n=e.toString():Object.keys(e).length>0&&(n=JSON.stringify(e)),`<:${t}>:${n}`}};l.hashable=i._hashable.bind(l),c.string?l.string=s.string?i._stringTrimCoerce.bind(l):i._stringTrim.bind(l):l.string=s.string?i._stringCoerce.bind(l):i._string.bind(l),l.number=s.number?i._numberCoerce.bind(l):i._number.bind(l),l.bigint=s.bigint?i._bigIntCoerce.bind(l):i._bigInt.bind(l),l.boolean=s.boolean?i._booleanCoerce.bind(l):i._boolean.bind(l),l.symbol=s.symbol?i._symbolCoerce.bind(l):i._symbol.bind(l),l.undefined=s.undefined?i._undefinedCoerce.bind(l):i._undefined.bind(l),l.null=s.null?i._nullCoerce.bind(l):i._null.bind(l),c.function?l.function=s.function?i._functionTrimCoerce.bind(l):i._functionTrim.bind(l):l.function=s.function?i._functionCoerce.bind(l):i._function.bind(l),l.date=s.date?i._dateCoerce.bind(l):i._date.bind(l),l.array=o.array?i._arraySort.bind(l):i._array.bind(l),l.typedarray=o.typedArray?i._typedArraySort.bind(l):i._typedArray.bind(l),o.set?l.set=s.set?i._setSortCoerce.bind(l):i._setSort.bind(l):l.set=s.set?i._setCoerce.bind(l):i._set.bind(l),l.object=o.object?i._objectSort.bind(l):i._object.bind(l),l.map=o.map?i._mapSort.bind(l):i._map.bind(l);function u(e){return l[(0,a.guessType)(e)](e)}return u}}));const{hash:L}=(0,u(c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.hasher=void 0;let t=d(`crypto`),n=I();e.hasher=e=>{let r=(0,n.objectSorter)(e);return{hash:(n,i)=>{let a=i?.alg||e?.alg||`sha256`,o=i?.enc||e?.enc||`hex`,s=r(n);return(0,t.createHash)(a).update(s).digest(o)},sort:r,sortObject:r}}}))(),1).hasher)({sort:!0,coerce:!0});var R=L;const z={},B=e=>(t,n={})=>async(...r)=>{let{calculateKey:i,strategy:a=`eager`,revalidationConcurrency:o=1,...s}=n,c=n.prefix??`default`,l=`${t.name}:${c}:${i?i(r):R(r)}`,u=`${t.name}:${c}`;z[u]=z[u]??new N({concurrency:o}),z[u].concurrency=o;let d=await e.getItem(l),f=async()=>{let i=await t(...r);return(!n.shouldStore||n.shouldStore(i))&&await e.setItem(l,i,{...s,isLazy:a===`lazy`||a===`swr`}),i};return a===`swr`&&d?.meta.expired&&(z[u].runningTasks.some(e=>e.id===l&&e.startTime)||z[u].add(f,{id:l})),d?d.content:await f()};export{p as CacheContainer,E as LRUStorage,B as withCacheFactory};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|