@boredland/node-ts-cache 2.0.0 → 2.0.2
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/dist/index.d.mts +21 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +42 -41
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LRUCache } from "lru-cache";
|
|
2
|
-
|
|
3
1
|
//#region src/storage.d.ts
|
|
4
2
|
interface Storage {
|
|
5
3
|
/**
|
|
@@ -66,12 +64,31 @@ declare class CacheContainer {
|
|
|
66
64
|
unsetKey(key: string): Promise<void>;
|
|
67
65
|
}
|
|
68
66
|
//#endregion
|
|
67
|
+
//#region src/fallbackStorage.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Fallback Cache Provider that tries multiple storages in order.
|
|
70
|
+
*
|
|
71
|
+
* On getItem, it tries each storage in order until it finds a hit.
|
|
72
|
+
* If a hit is found in a lower-priority storage, it writes it back to all higher-priority storages.
|
|
73
|
+
* **It only guarantees writing to the highest priority storage on setItem.**
|
|
74
|
+
*/
|
|
75
|
+
declare class FallbackStorage implements Storage {
|
|
76
|
+
private storages;
|
|
77
|
+
constructor(storages: [Storage, ...Storage[]]);
|
|
78
|
+
clear(): Promise<void>;
|
|
79
|
+
getItem(key: string): Promise<CachedItem | undefined>;
|
|
80
|
+
setItem(key: string, content: CachedItem): Promise<void>;
|
|
81
|
+
removeItem(key: string): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
69
84
|
//#region src/lruStorage.d.ts
|
|
70
85
|
declare class LRUStorage implements Storage {
|
|
71
86
|
private cache;
|
|
72
87
|
constructor({
|
|
73
88
|
max
|
|
74
|
-
}?:
|
|
89
|
+
}?: {
|
|
90
|
+
max?: number;
|
|
91
|
+
});
|
|
75
92
|
clear(): Promise<void>;
|
|
76
93
|
getItem(key: string): Promise<CachedItem | undefined>;
|
|
77
94
|
setItem(key: string, content: CachedItem): Promise<void>;
|
|
@@ -126,5 +143,5 @@ declare const withCacheFactory: (container: CacheContainer) => <Parameters exten
|
|
|
126
143
|
shouldStore
|
|
127
144
|
}?: WithCacheOptions<Parameters, Result>) => (...parameters: Parameters) => Promise<Result>;
|
|
128
145
|
//#endregion
|
|
129
|
-
export { CacheContainer, CachedItem, CachingOptions, LRUStorage, Storage, withCacheFactory };
|
|
146
|
+
export { CacheContainer, CachedItem, CachingOptions, FallbackStorage, LRUStorage, Storage, withCacheFactory };
|
|
130
147
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/storage.ts","../src/cacheContainer.ts","../src/lruStorage.ts","../src/withCache.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/storage.ts","../src/cacheContainer.ts","../src/fallbackStorage.ts","../src/lruStorage.ts","../src/withCache.ts"],"sourcesContent":[],"mappings":";AAEiB,UAAA,OAAA,CAAO;EAKO;;;;EAaL,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAbH,OAaG,CAbK,UAaL,GAAA,SAAA,CAAA;EAKhB;;;;;ECtBE,OAAA,CAAA,GAAA,EAAU,MAAA,EAAA,OACX,EDUoB,UCVpB,CAAA,EDUiC,OCVjC,CAAA,IAAA,CAAA;EAQC;AAgBZ;;;EAGuC,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EDXb,OCWa,CAAA,IAAA,CAAA;EA+BnB;;;EAiBG,KAAA,EAAA,EDtDb,OCsDa,CAAA,IAAA,CAAA;;;;AD7EN,KCCL,UDDY,CAAA,IAAA,OAAA,CAAA,GAAA;EAKO,OAAA,ECHrB,CDGqB;EAAR,IAAA,EAAA;IAOQ,SAAA,EAAA,MAAA;IAAa,GAAA,EAAA,MAAA,GAAA,IAAA;IAMlB,QAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAKhB,CAAA;CAAO;KCbL,cAAA;;;EATA;EASA,QAAA,EAAA,MAAA,GAAc,IAAA;EAgBb;EACiB,YAAA,EAAA,CAAA,IAAA,EAAA;IAIjB;IAF0B,SAAA,EAAA,MAAA;IA+BnB;IAAR,UAAA,EAAA,MAAA;IACR;IAgBmB,IAAA,EAAA,OAAA,EAAA;EAiBc,CAAA,EAAA,GAAA,MAAA;CAAO;cApE/B,cAAA;;uBACiB;ECnBjB,OAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAgB,CAAA,EDqBU,OCrBV,CAAA;IAGL,OAAA,EDoBX,CCpBW;IAAY,IAAA,EAAA;MAIpB,OAAA,EAAA,OAAA;MAIqB,KAAA,EAAA,OAAA;MAAR,SAAA,EAAA,MAAA;IAmBQ,CAAA;EAAa,CAAA,GAAA,SAAA,CAAA;EAQlB,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EAAA,OAAA,EAAA,OAAA,CAAA,EDcpB,OCdoB,CDcZ,cCdY,CAAA,CAAA,EDe5B,OCf4B,CAAA,IAAA,CAAA;EAtCQ,KAAA,CAAA,CAAA,EDqEjB,OCrEiB,CAAA,IAAA,CAAA;EAAO,QAAA,aAAA;;yBDsFV;;;;;;;;;;;cCtFxB,eAAA,YAA2B;;yBAGhB,YAAY;EDVxB,KAAA,CAAA,CAAA,ECcI,ODdM,CAAA,IAAA,CAAA;EASV,OAAA,CAAA,GAAA,EAAA,MAAc,CAAA,ECSG,ODTH,CCSW,UDTX,GAAA,SAAA,CAAA;EAgBb,OAAA,CAAA,GAAA,EAAA,MAAc,EAAA,OAAA,ECYU,UDZV,CAAA,ECYuB,ODZvB,CAAA,IAAA,CAAA;EACG,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,ECmBE,ODnBF,CAAA,IAAA,CAAA;;;;ADtBC,cGHlB,UAAA,YAAsB,OHGJ,CAAA;EAAR,QAAA,KAAA;EAOQ,WAAA,CAAA;IAAA;EAML,CAAA,CANK,EAAA;IAAa,GAAA,CAAA,EAAA,MAAA;EAMlB,CAAA;EAKhB,KAAA,CAAA,CAAA,EGdM,OHcN,CAAA,IAAA,CAAA;EAAO,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EGVS,OHUT,CGVS,UHUT,GAAA,SAAA,CAAA;gCGLoB,aAAU;2BAIlB;;;;AHtB7B,KIIK,gBJJmB,CAAA,UAAA,EAAA,MAAA,CAAA,GAAA;EAKO;EAAR,MAAA,CAAA,EAAA,MAAA;EAOQ;EAAa,YAAA,CAAA,EAAA,CAAA,KAAA,EIJpB,UJIoB,EAAA,GAAA,MAAA;EAMlB;EAKhB,WAAA,CAAA,EAAA,CAAA,MAAA,EIbc,OJad,CIbsB,MJatB,CAAA,EAAA,GAAA,OAAA;EAAO;;;;ECtBL,uBAAU,CAAA,EACZ,MAAC;EAQC;AAgBZ;;;;;EAkCY,WAAA,CAAA,EAAA,MAAA;EACR;;;;;;;ACrDJ,CAAA;;;;;;;;;;;;cEmCa,8BAA+B,uCAUvB,+BACJ,6CAEY,eAAe;;;;2BAAM;;;IAQ7C,iBAAiB,YAAY,4BAEH,eAAa,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +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),stale:this.isStaleItem(t)}};if(n.meta.expired&&!n.meta.stale){await this.unsetKey(e);return}return n}async setItem(e,t,n){let r={ttl:null,staleTtl:null,...n},i={createdAt:Date.now(),staleTtl:r.staleTtl,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}isStaleItem(e){let t=e.meta.staleTtl??e.meta.ttl;return t===null?!1:Date.now()>e.meta.createdAt+t}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,{cacheTimeMs:n=0,staleTimeMs:r=0,calculateKey:i=R,revalidationConcurrency:a=1,prefix:o=`default`,shouldStore:s=()=>!0}={})=>async(...c)=>{let l=`${t.name}:${o}:${i?i(c):R(c)}`,u=`${t.name}:${o}`;z[u]=z[u]??new N({concurrency:a}),z[u].concurrency=a;let d=await e.getItem(l),f=async()=>{let i=await t(...c);return s(i)&&await e.setItem(l,i,{ttl:n,staleTtl:r}),i};return n===0&&r===0?f():d&&!d.meta.expired?d.content:d?.meta.expired&&d?.meta.stale?(z[u].runningTasks.some(e=>e.id===l&&e.startTime)||z[u].add(f,{id:l}),d.content):await f()};export{p as CacheContainer,E as LRUStorage,B as withCacheFactory};
|
|
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),stale:this.isStaleItem(t)}};if(n.meta.expired&&!n.meta.stale){await this.unsetKey(e);return}return n}async setItem(e,t,n){let r={ttl:null,staleTtl:null,...n},i={createdAt:Date.now(),ttl:r.ttl,staleTtl:r.staleTtl};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}isStaleItem(e){let t=e.meta.staleTtl??e.meta.ttl;return t===null?!1:Date.now()>e.meta.createdAt+t}async unsetKey(e){await this.storage.removeItem(e)}},m=class{storages;constructor(e){this.storages=e}async clear(){await Promise.all([...this.storages.map(e=>e.clear())])}async getItem(e){for(let t=0;t<this.storages.length;t++){let n=await this.storages[t]?.getItem(e);if(n!==void 0)return t!==0&&await Promise.all(this.storages.slice(0,t).map(t=>t.setItem(e,n))),n}}async setItem(e,t){let[n,...r]=this.storages;await n.setItem(e,t),Promise.all(r.map(n=>n.setItem(e,t)))}async removeItem(e){await Promise.all(this.storages.map(t=>t.removeItem(e)))}},h=c((e=>{var t=function(e,t){return e<t?-1:e>t?1:0},n=function(e,t){return e<t?1:e>t?-1:0};function r(e){return function(t,n){return e(n,t)}}function i(e){return e===2?function(e,t){return e[0]<t[0]?-1:e[0]>t[0]?1:e[1]<t[1]?-1:e[1]>t[1]?1:0}:function(t,n){for(var r=0;r<e;){if(t[r]<n[r])return-1;if(t[r]>n[r])return 1;r++}return 0}}e.DEFAULT_COMPARATOR=t,e.DEFAULT_REVERSE_COMPARATOR=n,e.reverseComparator=r,e.createTupleComparator=i})),g=c((e=>{e.ARRAY_BUFFER_SUPPORT=typeof ArrayBuffer<`u`,e.SYMBOL_SUPPORT=typeof Symbol<`u`})),_=c(((e,t)=>{var n=g(),r=n.ARRAY_BUFFER_SUPPORT,i=n.SYMBOL_SUPPORT;t.exports=function(e,t){var n,a,o,s,c;if(!e)throw Error(`obliterator/forEach: invalid iterable.`);if(typeof t!=`function`)throw Error(`obliterator/forEach: expecting a callback.`);if(Array.isArray(e)||r&&ArrayBuffer.isView(e)||typeof e==`string`||e.toString()===`[object Arguments]`){for(o=0,s=e.length;o<s;o++)t(e[o],o);return}if(typeof e.forEach==`function`){e.forEach(t);return}if(i&&Symbol.iterator in e&&typeof e.next!=`function`&&(e=e[Symbol.iterator]()),typeof e.next==`function`){for(n=e,o=0;c=n.next(),c.done!==!0;)t(c.value,o),o++;return}for(a in e)e.hasOwnProperty(a)&&t(e[a],a)}})),v=c(((e,t)=>{var n=h(),r=_(),i=n.DEFAULT_COMPARATOR,a=n.reverseComparator;function o(e){if(this.clear(),this.comparator=e||i,typeof this.comparator!=`function`)throw Error(`mnemonist/FibonacciHeap.constructor: given comparator should be a function.`)}o.prototype.clear=function(){this.root=null,this.min=null,this.size=0};function s(e){return{item:e,degree:0}}function c(e,t){e.root?(t.right=e.root.right,t.left=e.root,e.root.right.left=t,e.root.right=t):e.root=t}o.prototype.push=function(e){var t=s(e);return t.left=t,t.right=t,c(this,t),(!this.min||this.comparator(t.item,this.min.item)<=0)&&(this.min=t),++this.size},o.prototype.peek=function(){return this.min?this.min.item:void 0};function l(e){for(var t=[],n=e,r=!1;!(n===e&&r);)n===e&&(r=!0),t.push(n),n=n.right;return t}function u(e,t){e.root===t&&(e.root=t.right),t.left.right=t.right,t.right.left=t.left}function d(e,t){e.child?(t.right=e.child.right,t.left=e.child,e.child.right.left=t,e.child.right=t):e.child=t}function f(e,t,n){u(e,t),t.left=t,t.right=t,d(n,t),n.degree++,t.parent=n}function p(e){var t=Array(e.size),n=l(e.root),r,i,a,o,s,c;for(r=0,i=n.length;r<i;r++){for(a=n[r],s=a.degree;t[s];)o=t[s],e.comparator(a.item,o.item)>0&&(c=a,a=o,o=c),f(e,o,a),t[s]=null,s++;t[s]=a}for(r=0;r<e.size;r++)t[r]&&e.comparator(t[r].item,e.min.item)<=0&&(e.min=t[r])}o.prototype.pop=function(){if(this.size){var e=this.min;if(e.child){var t=l(e.child),n,r,i;for(r=0,i=t.length;r<i;r++)n=t[r],c(this,n),delete n.parent}return u(this,e),e===e.right?(this.min=null,this.root=null):(this.min=e.right,p(this)),this.size--,e.item}},o.prototype.inspect=function(){var e={size:this.size};return this.min&&`item`in this.min&&(e.top=this.min.item),Object.defineProperty(e,`constructor`,{value:o,enumerable:!1}),e},typeof Symbol<`u`&&(o.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=o.prototype.inspect);function m(e){if(this.clear(),this.comparator=e||i,typeof this.comparator!=`function`)throw Error(`mnemonist/FibonacciHeap.constructor: given comparator should be a function.`);this.comparator=a(this.comparator)}m.prototype=o.prototype,o.from=function(e,t){var n=new o(t);return r(e,function(e){n.push(e)}),n},m.from=function(e,t){var n=new m(t);return r(e,function(e){n.push(e)}),n},o.MinFibonacciHeap=o,o.MaxFibonacciHeap=m,t.exports=o})),y=c((e=>{var t=2**8-1,n=2**16-1,r=2**32-1,i=2**7-1,a=2**15-1,o=2**31-1;e.getPointerArray=function(e){var i=e-1;if(i<=t)return Uint8Array;if(i<=n)return Uint16Array;if(i<=r)return Uint32Array;throw Error(`mnemonist: Pointer Array of size > 4294967295 is not supported.`)},e.getSignedPointerArray=function(e){var t=e-1;return t<=i?Int8Array:t<=a?Int16Array:t<=o?Int32Array:Float64Array},e.getNumberType=function(e){return e===(e|0)?Math.sign(e)===-1?e<=127&&e>=-128?Int8Array:e<=32767&&e>=-32768?Int16Array:Int32Array:e<=255?Uint8Array:e<=65535?Uint16Array:Uint32Array:Float64Array};var s={Uint8Array:1,Int8Array:2,Uint16Array:3,Int16Array:4,Uint32Array:5,Int32Array:6,Float32Array:7,Float64Array:8};e.getMinimalRepresentation=function(t,n){var r=null,i=0,a,o,c,l,u;for(l=0,u=t.length;l<u;l++)c=n?n(t[l]):t[l],o=e.getNumberType(c),a=s[o.name],a>i&&(i=a,r=o);return r},e.isTypedArray=function(e){return typeof ArrayBuffer<`u`&&ArrayBuffer.isView(e)},e.concat=function(){var e=0,t,n,r;for(t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var i=new arguments[0].constructor(e);for(t=0,n=0;t<r;t++)i.set(arguments[t],n),n+=arguments[t].length;return i},e.indices=function(t){for(var n=new(e.getPointerArray(t))(t),r=0;r<t;r++)n[r]=r;return n}})),b=c((e=>{var t=_(),n=y();function r(e){return Array.isArray(e)||n.isTypedArray(e)}function i(e){if(typeof e.length==`number`)return e.length;if(typeof e.size==`number`)return e.size}function a(e){var n=i(e),r=typeof n==`number`?Array(n):[],a=0;return t(e,function(e){r[a++]=e}),r}function o(e){var r=i(e),a=typeof r==`number`?n.getPointerArray(r):Array,o=typeof r==`number`?Array(r):[],s=typeof r==`number`?new a(r):[],c=0;return t(e,function(e){o[c]=e,s[c]=c++}),[o,s]}e.isArrayLike=r,e.guessLength=i,e.toArray=a,e.toArrayWithIndices=o})),x=c(((e,t)=>{var n=_(),r=h(),i=b(),a=r.DEFAULT_COMPARATOR,o=r.reverseComparator;function s(e,t,n,r){for(var i=t[r],a,o;r>n;){if(a=r-1>>1,o=t[a],e(i,o)<0){t[r]=o,r=a;continue}break}t[r]=i}function c(e,t,n){for(var r=t.length,i=n,a=t[n],o=2*n+1,c;o<r;)c=o+1,c<r&&e(t[o],t[c])>=0&&(o=c),t[n]=t[o],n=o,o=2*n+1;t[n]=a,s(e,t,i,n)}function l(e,t,n){t.push(n),s(e,t,0,t.length-1)}function u(e,t){var n=t.pop();if(t.length!==0){var r=t[0];return t[0]=n,c(e,t,0),r}return n}function d(e,t,n){if(t.length===0)throw Error(`mnemonist/heap.replace: cannot pop an empty heap.`);var r=t[0];return t[0]=n,c(e,t,0),r}function f(e,t,n){var r;return t.length!==0&&e(t[0],n)<0&&(r=t[0],t[0]=n,n=r,c(e,t,0)),n}function p(e,t){for(var n=t.length>>1;--n>=0;)c(e,t,n)}function m(e,t){for(var n=t.length,r=0,i=Array(n);r<n;)i[r++]=u(e,t);return i}function g(e,t,r){arguments.length===2&&(r=t,t=e,e=a);var s=o(e),c,l,u,f=1/0,m;if(t===1){if(i.isArrayLike(r)){for(c=0,l=r.length;c<l;c++)u=r[c],(f===1/0||e(u,f)<0)&&(f=u);return m=new r.constructor(1),m[0]=f,m}return n(r,function(t){(f===1/0||e(t,f)<0)&&(f=t)}),[f]}if(i.isArrayLike(r)){if(t>=r.length)return r.slice().sort(e);for(m=r.slice(0,t),p(s,m),c=t,l=r.length;c<l;c++)s(r[c],m[0])>0&&d(s,m,r[c]);return m.sort(e)}var h=i.guessLength(r);return h!==null&&h<t&&(t=h),m=Array(t),c=0,n(r,function(e){c<t?m[c]=e:(c===t&&p(s,m),s(e,m[0])>0&&d(s,m,e)),c++}),m.length>c&&(m.length=c),m.sort(e)}function v(e,t,r){arguments.length===2&&(r=t,t=e,e=a);var s=o(e),c,l,u,f=-1/0,m;if(t===1){if(i.isArrayLike(r)){for(c=0,l=r.length;c<l;c++)u=r[c],(f===-1/0||e(u,f)>0)&&(f=u);return m=new r.constructor(1),m[0]=f,m}return n(r,function(t){(f===-1/0||e(t,f)>0)&&(f=t)}),[f]}if(i.isArrayLike(r)){if(t>=r.length)return r.slice().sort(s);for(m=r.slice(0,t),p(e,m),c=t,l=r.length;c<l;c++)e(r[c],m[0])>0&&d(e,m,r[c]);return m.sort(s)}var h=i.guessLength(r);return h!==null&&h<t&&(t=h),m=Array(t),c=0,n(r,function(n){c<t?m[c]=n:(c===t&&p(e,m),e(n,m[0])>0&&d(e,m,n)),c++}),m.length>c&&(m.length=c),m.sort(s)}function y(e){if(this.clear(),this.comparator=e||a,typeof this.comparator!=`function`)throw Error(`mnemonist/Heap.constructor: given comparator should be a function.`)}y.prototype.clear=function(){this.items=[],this.size=0},y.prototype.push=function(e){return l(this.comparator,this.items,e),++this.size},y.prototype.peek=function(){return this.items[0]},y.prototype.pop=function(){return this.size!==0&&this.size--,u(this.comparator,this.items)},y.prototype.replace=function(e){return d(this.comparator,this.items,e)},y.prototype.pushpop=function(e){return f(this.comparator,this.items,e)},y.prototype.consume=function(){return this.size=0,m(this.comparator,this.items)},y.prototype.toArray=function(){return m(this.comparator,this.items.slice())},y.prototype.inspect=function(){var e=this.toArray();return Object.defineProperty(e,`constructor`,{value:y,enumerable:!1}),e},typeof Symbol<`u`&&(y.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=y.prototype.inspect);function x(e){if(this.clear(),this.comparator=e||a,typeof this.comparator!=`function`)throw Error(`mnemonist/MaxHeap.constructor: given comparator should be a function.`);this.comparator=o(this.comparator)}x.prototype=y.prototype,y.from=function(e,t){var n=new y(t),r=i.isArrayLike(e)?e.slice():i.toArray(e);return p(n.comparator,r),n.items=r,n.size=r.length,n},x.from=function(e,t){var n=new x(t),r=i.isArrayLike(e)?e.slice():i.toArray(e);return p(n.comparator,r),n.items=r,n.size=r.length,n},y.siftUp=c,y.siftDown=s,y.push=l,y.pop=u,y.replace=d,y.pushpop=f,y.heapify=p,y.consume=m,y.nsmallest=g,y.nlargest=v,y.MinHeap=y,y.MaxHeap=x,t.exports=y})),S=c(((e,t)=>{var n=``;function r(e,t,n){for(var r=t.length,i=[],a=r,o=-1,s,c=0,l;a--;)o=Math.max(e[t[a]+n],o);for(l=o>>24&&32||o>>16&&24||o>>8&&16||8;c<l;c+=4){for(a=16;a--;)i[a]=[];for(a=r;a--;)i[e[t[a]+n]>>c&15].push(t[a]);for(s=0;s<16;s++)for(o=i[s].length;o--;)t[++a]=i[s][o]}}function i(e,t,n,r){return e[n]-e[r]||(n%3==2?e[n+1]-e[r+1]||t[n+2]-t[r+2]:t[n+1]-t[r+1])}function a(e,t){var n=[],o=[],s=2*t/3|0,c=t-s,l=s+1>>1,u=s,d=0,f,p=[],m=[];if(t===1)return[0];for(;u--;)n[u]=(u*3>>1)+1;for(u=3;u--;)r(e,n,u);for(d=o[(n[0]/3|0)+(n[0]%3==1?0:l)]=1,u=1;u<s;u++)(e[n[u]]!==e[n[u-1]]||e[n[u]+1]!==e[n[u-1]+1]||e[n[u]+2]!==e[n[u-1]+2])&&d++,o[(n[u]/3|0)+(n[u]%3==1?0:l)]=d;if(d<s)for(o=a(o,s),u=s;u--;)n[u]=o[u]<l?o[u]*3+1:(o[u]-l)*3+2;for(u=s;u--;)p[n[u]]=u;for(p[t]=-1,p[t+1]=-2,o=t%3==1?[t-1]:[],u=0;u<s;u++)n[u]%3==1&&o.push(n[u]-1);for(r(e,o,0),u=0,d=0,f=0;u<s&&d<c;)m[f++]=i(e,p,n[u],o[d])<0?n[u++]:o[d++];for(;u<s;)m[f++]=n[u++];for(;d<c;)m[f++]=o[d++];return m}function o(e){var t=e.length,n=t%3,r=Array(t+n),i,a;if(typeof e!=`string`){var o=Object.create(null);for(a=0;a<t;a++)o[e[a]]||(o[e[a]]=!0);var s=Object.create(null),c=Object.keys(o).sort();for(a=0,i=c.length;a<i;a++)s[c[a]]=a+1;for(a=0;a<t;a++)r[a]=s[e[a]]}else for(a=0;a<t;a++)r[a]=e.charCodeAt(a);for(a=t;a<t+n;a++)r[a]=0;return r}function s(e){this.hasArbitrarySequence=typeof e!=`string`,this.string=e,this.length=e.length,this.array=a(o(e),this.length)}s.prototype.toString=function(){return this.array.join(`,`)},s.prototype.toJSON=function(){return this.array},s.prototype.inspect=function(){for(var e=Array(this.length),t=0;t<this.length;t++)e[t]=this.string.slice(this.array[t]);return Object.defineProperty(e,`constructor`,{value:s,enumerable:!1}),e},typeof Symbol<`u`&&(s.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=s.prototype.inspect);function c(e){if(this.hasArbitrarySequence=typeof e[0]!=`string`,this.size=e.length,this.hasArbitrarySequence){this.text=[];for(var t=0,r=this.size;t<r;t++)this.text.push.apply(this.text,e[t]),t<r-1&&this.text.push(n)}else this.text=e.join(n);this.firstLength=e[0].length,this.length=this.text.length,this.array=a(o(this.text),this.length)}c.prototype.longestCommonSubsequence=function(){var e=this.hasArbitrarySequence?[]:``,t,n,r,i,a;for(n=1;n<this.length;n++)if(i=this.array[n],a=this.array[n-1],!(i<this.firstLength&&a<this.firstLength)&&!(i>this.firstLength&&a>this.firstLength)){for(t=Math.min(this.length-i,this.length-a),r=0;r<t;r++)if(this.text[i+r]!==this.text[a+r]){t=r;break}t>e.length&&(e=this.text.slice(i,i+t))}return e},c.prototype.toString=function(){return this.array.join(`,`)},c.prototype.toJSON=function(){return this.array},c.prototype.inspect=function(){for(var e=Array(this.length),t=0;t<this.length;t++)e[t]=this.text.slice(this.array[t]);return Object.defineProperty(e,`constructor`,{value:c,enumerable:!1}),e},typeof Symbol<`u`&&(c.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=c.prototype.inspect),s.GeneralizedSuffixArray=c,t.exports=s})),C=c(((e,t)=>{function n(e){if(typeof e!=`function`)throw Error(`obliterator/iterator: expecting a function!`);this.next=e}typeof Symbol<`u`&&(n.prototype[Symbol.iterator]=function(){return this}),n.of=function(){var e=arguments,t=e.length,r=0;return new n(function(){return r>=t?{done:!0}:{done:!1,value:e[r++]}})},n.empty=function(){return new n(function(){return{done:!0}})},n.fromSequence=function(e){var t=0,r=e.length;return new n(function(){return t>=r?{done:!0}:{done:!1,value:e[t++]}})},n.is=function(e){return e instanceof n?!0:typeof e==`object`&&!!e&&typeof e.next==`function`},t.exports=n})),w=c(((e,t)=>{var n=C(),r=_(),i=b(),a=y(),o=function(e){return Math.max(1,Math.ceil(e*1.5))},s=function(e){return new(a.getPointerArray(e))(e)};function c(e,t){if(arguments.length<1)throw Error(`mnemonist/vector: expecting at least a byte array constructor.`);var n=t||0,r=o,i=0,a=!1;typeof t==`object`&&(n=t.initialCapacity||0,i=t.initialLength||0,r=t.policy||r,a=t.factory===!0),this.factory=a?e:null,this.ArrayClass=e,this.length=i,this.capacity=Math.max(i,n),this.policy=r,this.array=new e(this.capacity)}c.prototype.set=function(e,t){if(this.length<e)throw Error(`Vector(`+this.ArrayClass.name+`).set: index out of bounds.`);return this.array[e]=t,this},c.prototype.get=function(e){if(!(this.length<e))return this.array[e]},c.prototype.applyPolicy=function(e){var t=this.policy(e||this.capacity);if(typeof t!=`number`||t<0)throw Error(`mnemonist/vector.applyPolicy: policy returned an invalid value (expecting a positive integer).`);if(t<=this.capacity)throw Error(`mnemonist/vector.applyPolicy: policy returned a less or equal capacity to allocate.`);return t},c.prototype.reallocate=function(e){if(e===this.capacity)return this;var t=this.array;if(e<this.length&&(this.length=e),e>this.capacity)if(this.factory===null?this.array=new this.ArrayClass(e):this.array=this.factory(e),a.isTypedArray(this.array))this.array.set(t,0);else for(var n=0,r=this.length;n<r;n++)this.array[n]=t[n];else this.array=t.slice(0,e);return this.capacity=e,this},c.prototype.grow=function(e){var t;if(typeof e==`number`){if(this.capacity>=e)return this;for(t=this.capacity;t<e;)t=this.applyPolicy(t);return this.reallocate(t),this}return t=this.applyPolicy(),this.reallocate(t),this},c.prototype.resize=function(e){return e===this.length?this:e<this.length?(this.length=e,this):(this.length=e,this.reallocate(e),this)},c.prototype.push=function(e){return this.capacity===this.length&&this.grow(),this.array[this.length++]=e,this.length},c.prototype.pop=function(){if(this.length!==0)return this.array[--this.length]},c.prototype.values=function(){var e=this.array,t=this.length,r=0;return new n(function(){if(r>=t)return{done:!0};var n=e[r];return r++,{value:n,done:!1}})},c.prototype.entries=function(){var e=this.array,t=this.length,r=0;return new n(function(){if(r>=t)return{done:!0};var n=e[r];return{value:[r++,n],done:!1}})},typeof Symbol<`u`&&(c.prototype[Symbol.iterator]=c.prototype.values),c.prototype.inspect=function(){var e=this.array.slice(0,this.length);return e.type=this.array.constructor.name,e.items=this.length,e.capacity=this.capacity,Object.defineProperty(e,`constructor`,{value:c,enumerable:!1}),e},typeof Symbol<`u`&&(c.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=c.prototype.inspect),c.from=function(e,t,n){if(arguments.length<3&&(n=i.guessLength(e),typeof n!=`number`))throw Error(`mnemonist/vector.from: could not guess iterable length. Please provide desired capacity as last argument.`);var a=new c(t,n);return r(e,function(e){a.push(e)}),a};function l(e){var t=function(t){c.call(this,e,t)};for(var n in c.prototype)c.prototype.hasOwnProperty(n)&&(t.prototype[n]=c.prototype[n]);return t.from=function(t,n){return c.from(t,e,n)},typeof Symbol<`u`&&(t.prototype[Symbol.iterator]=t.prototype.values),t}c.Int8Vector=l(Int8Array),c.Uint8Vector=l(Uint8Array),c.Uint8ClampedVector=l(Uint8ClampedArray),c.Int16Vector=l(Int16Array),c.Uint16Vector=l(Uint16Array),c.Int32Vector=l(Int32Array),c.Uint32Vector=l(Uint32Array),c.Float32Vector=l(Float32Array),c.Float64Vector=l(Float64Array),c.PointerVector=l(s),t.exports=c})),T=c(((e,t)=>{var n=C(),r=_(),i=y(),a=b();function o(e,t,n){if(arguments.length<2&&(n=e,e=null,t=null),this.capacity=n,typeof this.capacity!=`number`||this.capacity<=0)throw Error(`mnemonist/lru-cache: capacity should be positive number.`);if(!isFinite(this.capacity)||Math.floor(this.capacity)!==this.capacity)throw Error(`mnemonist/lru-cache: capacity should be a finite positive integer.`);var r=i.getPointerArray(n);this.forward=new r(n),this.backward=new r(n),this.K=typeof e==`function`?new e(n):Array(n),this.V=typeof t==`function`?new t(n):Array(n),this.size=0,this.head=0,this.tail=0,this.items={}}o.prototype.clear=function(){this.size=0,this.head=0,this.tail=0,this.items={}},o.prototype.splayOnTop=function(e){var t=this.head;if(this.head===e)return this;var n=this.backward[e],r=this.forward[e];return this.tail===e?this.tail=n:this.backward[r]=n,this.forward[n]=r,this.backward[t]=e,this.head=e,this.forward[e]=t,this},o.prototype.set=function(e,t){var n=this.items[e];if(n!==void 0){this.splayOnTop(n),this.V[n]=t;return}this.size<this.capacity?n=this.size++:(n=this.tail,this.tail=this.backward[n],delete this.items[this.K[n]]),this.items[e]=n,this.K[n]=e,this.V[n]=t,this.forward[n]=this.head,this.backward[this.head]=n,this.head=n},o.prototype.setpop=function(e,t){var n=null,r=null,i=this.items[e];return i===void 0?(this.size<this.capacity?i=this.size++:(i=this.tail,this.tail=this.backward[i],n=this.V[i],r=this.K[i],delete this.items[r]),this.items[e]=i,this.K[i]=e,this.V[i]=t,this.forward[i]=this.head,this.backward[this.head]=i,this.head=i,r?{evicted:!0,key:r,value:n}:null):(this.splayOnTop(i),n=this.V[i],this.V[i]=t,{evicted:!1,key:e,value:n})},o.prototype.has=function(e){return e in this.items},o.prototype.get=function(e){var t=this.items[e];if(t!==void 0)return this.splayOnTop(t),this.V[t]},o.prototype.peek=function(e){var t=this.items[e];if(t!==void 0)return this.V[t]},o.prototype.forEach=function(e,t){t=arguments.length>1?t:this;for(var n=0,r=this.size,i=this.head,a=this.K,o=this.V,s=this.forward;n<r;)e.call(t,o[i],a[i],this),i=s[i],n++},o.prototype.keys=function(){var e=0,t=this.size,r=this.head,i=this.K,a=this.forward;return new n(function(){if(e>=t)return{done:!0};var n=i[r];return e++,e<t&&(r=a[r]),{done:!1,value:n}})},o.prototype.values=function(){var e=0,t=this.size,r=this.head,i=this.V,a=this.forward;return new n(function(){if(e>=t)return{done:!0};var n=i[r];return e++,e<t&&(r=a[r]),{done:!1,value:n}})},o.prototype.entries=function(){var e=0,t=this.size,r=this.head,i=this.K,a=this.V,o=this.forward;return new n(function(){if(e>=t)return{done:!0};var n=i[r],s=a[r];return e++,e<t&&(r=o[r]),{done:!1,value:[n,s]}})},typeof Symbol<`u`&&(o.prototype[Symbol.iterator]=o.prototype.entries),o.prototype.inspect=function(){for(var e=new Map,t=this.entries(),n;n=t.next(),!n.done;)e.set(n.value[0],n.value[1]);return Object.defineProperty(e,`constructor`,{value:o,enumerable:!1}),e},typeof Symbol<`u`&&(o.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=o.prototype.inspect),o.from=function(e,t,n,i){if(arguments.length<2){if(i=a.guessLength(e),typeof i!=`number`)throw Error(`mnemonist/lru-cache.from: could not guess iterable length. Please provide desired capacity as last argument.`)}else arguments.length===2&&(i=t,t=null,n=null);var s=new o(t,n,i);return r(e,function(e,t){s.set(t,e)}),s},t.exports=o})),E=c(((e,t)=>{var n=T(),r=_(),i=y(),a=b();function o(e,t,n){if(arguments.length<2&&(n=e,e=null,t=null),this.capacity=n,typeof this.capacity!=`number`||this.capacity<=0)throw Error(`mnemonist/lru-map: capacity should be positive number.`);if(!isFinite(this.capacity)||Math.floor(this.capacity)!==this.capacity)throw Error(`mnemonist/lru-map: capacity should be a finite positive integer.`);var r=i.getPointerArray(n);this.forward=new r(n),this.backward=new r(n),this.K=typeof e==`function`?new e(n):Array(n),this.V=typeof t==`function`?new t(n):Array(n),this.size=0,this.head=0,this.tail=0,this.items=new Map}o.prototype.clear=function(){this.size=0,this.head=0,this.tail=0,this.items.clear()},o.prototype.set=function(e,t){var n=this.items.get(e);if(n!==void 0){this.splayOnTop(n),this.V[n]=t;return}this.size<this.capacity?n=this.size++:(n=this.tail,this.tail=this.backward[n],this.items.delete(this.K[n])),this.items.set(e,n),this.K[n]=e,this.V[n]=t,this.forward[n]=this.head,this.backward[this.head]=n,this.head=n},o.prototype.setpop=function(e,t){var n=null,r=null,i=this.items.get(e);return i===void 0?(this.size<this.capacity?i=this.size++:(i=this.tail,this.tail=this.backward[i],n=this.V[i],r=this.K[i],this.items.delete(r)),this.items.set(e,i),this.K[i]=e,this.V[i]=t,this.forward[i]=this.head,this.backward[this.head]=i,this.head=i,r?{evicted:!0,key:r,value:n}:null):(this.splayOnTop(i),n=this.V[i],this.V[i]=t,{evicted:!1,key:e,value:n})},o.prototype.has=function(e){return this.items.has(e)},o.prototype.get=function(e){var t=this.items.get(e);if(t!==void 0)return this.splayOnTop(t),this.V[t]},o.prototype.peek=function(e){var t=this.items.get(e);if(t!==void 0)return this.V[t]},o.prototype.splayOnTop=n.prototype.splayOnTop,o.prototype.forEach=n.prototype.forEach,o.prototype.keys=n.prototype.keys,o.prototype.values=n.prototype.values,o.prototype.entries=n.prototype.entries,typeof Symbol<`u`&&(o.prototype[Symbol.iterator]=o.prototype.entries),o.prototype.inspect=n.prototype.inspect,o.from=function(e,t,n,i){if(arguments.length<2){if(i=a.guessLength(e),typeof i!=`number`)throw Error(`mnemonist/lru-cache.from: could not guess iterable length. Please provide desired capacity as last argument.`)}else arguments.length===2&&(i=t,t=null,n=null);var s=new o(t,n,i);return r(e,function(e,t){s.set(t,e)}),s},t.exports=o})),D=c(((e,t)=>{var n=E(),r=_(),i=y(),a=b();function o(e,t,r){arguments.length<2?n.call(this,e):n.call(this,e,t,r),this.deleted=new(i.getPointerArray(this.capacity))(this.capacity),this.deletedSize=0}for(var s in n.prototype)o.prototype[s]=n.prototype[s];typeof Symbol<`u`&&(o.prototype[Symbol.iterator]=n.prototype[Symbol.iterator]),o.prototype.clear=function(){n.prototype.clear.call(this),this.deletedSize=0},o.prototype.set=function(e,t){var n=this.items.get(e);if(n!==void 0){this.splayOnTop(n),this.V[n]=t;return}this.size<this.capacity?(n=this.deletedSize>0?this.deleted[--this.deletedSize]:this.size,this.size++):(n=this.tail,this.tail=this.backward[n],this.items.delete(this.K[n])),this.items.set(e,n),this.K[n]=e,this.V[n]=t,this.forward[n]=this.head,this.backward[this.head]=n,this.head=n},o.prototype.setpop=function(e,t){var n=null,r=null,i=this.items.get(e);return i===void 0?(this.size<this.capacity?(i=this.deletedSize>0?this.deleted[--this.deletedSize]:this.size,this.size++):(i=this.tail,this.tail=this.backward[i],n=this.V[i],r=this.K[i],this.items.delete(r)),this.items.set(e,i),this.K[i]=e,this.V[i]=t,this.forward[i]=this.head,this.backward[this.head]=i,this.head=i,r?{evicted:!0,key:r,value:n}:null):(this.splayOnTop(i),n=this.V[i],this.V[i]=t,{evicted:!1,key:e,value:n})},o.prototype.delete=function(e){var t=this.items.get(e);if(t===void 0)return!1;if(this.items.delete(e),this.size===1)return this.size=0,this.head=0,this.tail=0,this.deletedSize=0,!0;var n=this.backward[t],r=this.forward[t];return this.head===t&&(this.head=r),this.tail===t&&(this.tail=n),this.forward[n]=r,this.backward[r]=n,this.size--,this.deleted[this.deletedSize++]=t,!0},o.prototype.remove=function(e,t=void 0){var n=this.items.get(e);if(n===void 0)return t;var r=this.V[n];if(this.items.delete(e),this.size===1)return this.size=0,this.head=0,this.tail=0,this.deletedSize=0,r;var i=this.backward[n],a=this.forward[n];return this.head===n&&(this.head=a),this.tail===n&&(this.tail=i),this.forward[i]=a,this.backward[a]=i,this.size--,this.deleted[this.deletedSize++]=n,r},o.from=function(e,t,n,i){if(arguments.length<2){if(i=a.guessLength(e),typeof i!=`number`)throw Error(`mnemonist/lru-map.from: could not guess iterable length. Please provide desired capacity as last argument.`)}else arguments.length===2&&(i=t,t=null,n=null);var s=new o(t,n,i);return r(e,function(e,t){s.set(t,e)}),s},t.exports=o})),O=u(v(),1),k=u(x(),1),A=u(S(),1),j=u(w(),1),M=u(D(),1);O.default.MinFibonacciHeap,O.default.MaxFibonacciHeap,k.default.MinHeap,k.default.MaxHeap,A.default.GeneralizedSuffixArray,j.default.Uint8Vector,j.default.Uint8ClampedVector,j.default.Int8Vector,j.default.Uint16Vector,j.default.Int16Vector,j.default.Uint32Vector,j.default.Int32Vector,j.default.Float32Vector,j.default.Float64Vector,j.default.PointerVector;var N=class{cache;constructor({max:e=1e4}={}){this.cache=new M.default(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)}},P=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),F=class e extends Error{name=`TimeoutError`;constructor(t,n){super(t,n),Error.captureStackTrace?.(this,e)}};const I=e=>e.reason??new DOMException(`This operation was aborted.`,`AbortError`);function L(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(I(o));return}if(o&&(c=()=>{l(I(o))},o.addEventListener(`abort`,c,{once:!0})),e.then(t,l),n===1/0)return;let u=new F;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 R(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 z=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=R(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}},B=class extends P.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:z,...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=L(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}))}},V=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`})),H=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=V();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 P(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=P;function F(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=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.sort().join(`;`)+`]`}e._mapSort=I})),U=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(H()),a=V();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:W}=(0,u(c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.hasher=void 0;let t=d(`crypto`),n=U();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 G=W;const K={},q=e=>(t,{cacheTimeMs:n=0,staleTimeMs:r=0,calculateKey:i=G,revalidationConcurrency:a=1,prefix:o=`default`,shouldStore:s=()=>!0}={})=>async(...c)=>{let l=`${t.name}:${o}:${i?i(c):G(c)}`,u=`${t.name}:${o}`;K[u]=K[u]??new B({concurrency:a}),K[u].concurrency=a;let d=await e.getItem(l),f=async()=>{let i=await t(...c);return s(i)&&await e.setItem(l,i,{ttl:n,staleTtl:r}),i};return n===0&&r===0?t(...c):d&&!d.meta.expired?d.content:d?.meta.expired&&d?.meta.stale?(K[u].runningTasks.some(e=>e.id===l&&e.startTime)||K[u].add(f,{id:l}),d.content):await f()};export{p as CacheContainer,m as FallbackStorage,N as LRUStorage,q as withCacheFactory};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|