@jujulego/jill 3.0.8 → 3.0.9

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/main.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"jill@3.0.8"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0ababa30-bd28-44f9-ab35-b37a3474aa90",e._sentryDebugIdIdentifier="sentry-dbid-0ababa30-bd28-44f9-ab35-b37a3474aa90");}catch(e){}}();import { startSpan, startInactiveSpan, getActiveSpan, updateSpanName, getRootSpan, captureException, flush } from '@sentry/node';
1
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"jill@3.0.9"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="bfa80f19-f695-4bc1-b1d8-5744e3e8229e",e._sentryDebugIdIdentifier="sentry-dbid-bfa80f19-f695-4bc1-b1d8-5744e3e8229e");}catch(e){}}();import { startSpan, startInactiveSpan, getActiveSpan, updateSpanName, getRootSpan, captureException, flush } from '@sentry/node';
2
2
  import process$1 from 'node:process';
3
3
  import { hideBin } from 'yargs/helpers';
4
4
  import path, { win32, posix } from 'node:path';
@@ -1539,31 +1539,35 @@ const QUICK_CONDITION_INJECTOR = Symbol.for('jujulego/quick-tag:condition-inject
1539
1539
  };
1540
1540
  }
1541
1541
 
1542
- function safeStringifyReplacer(seen) {
1543
- const replacer = function(key, value) {
1544
- // Handle objects with a custom `.toJSON()` method.
1545
- if (typeof value?.toJSON === 'function') {
1546
- value = value.toJSON();
1547
- }
1548
- if (!(value !== null && typeof value === 'object')) {
1549
- return value;
1550
- }
1551
- if (seen.has(value)) {
1542
+ function serializeValue(value, seen, trace, currentPath) {
1543
+ // Handle objects with a custom `.toJSON()` method.
1544
+ if (typeof value?.toJSON === 'function') {
1545
+ value = value.toJSON();
1546
+ }
1547
+ if (!(value !== null && typeof value === 'object')) {
1548
+ return value;
1549
+ }
1550
+ if (seen.has(value)) {
1551
+ if (!trace) {
1552
1552
  return '[Circular]';
1553
1553
  }
1554
- seen.add(value);
1555
- const newValue = Array.isArray(value) ? [] : {};
1556
- for (const [key2, value2] of Object.entries(value)){
1557
- newValue[key2] = replacer(key2, value2);
1558
- }
1559
- seen.delete(value);
1560
- return newValue;
1561
- };
1562
- return replacer;
1554
+ const existingPath = seen.get(value);
1555
+ const circularPath = existingPath === '' ? '*' : `*${existingPath}`;
1556
+ return `[Circular ${circularPath}]`;
1557
+ }
1558
+ seen.set(value, currentPath);
1559
+ const newValue = Array.isArray(value) ? [] : {};
1560
+ for (const [propertyKey, propertyValue] of Object.entries(value)){
1561
+ const nextPath = currentPath === '' ? propertyKey : `${currentPath}.${propertyKey}`;
1562
+ newValue[propertyKey] = serializeValue(propertyValue, seen, trace, nextPath);
1563
+ }
1564
+ seen.delete(value);
1565
+ return newValue;
1563
1566
  }
1564
- function safeStringify(object, { indentation } = {}) {
1565
- const seen = new WeakSet();
1566
- return JSON.stringify(object, safeStringifyReplacer(seen), indentation);
1567
+ function safeStringify(value, { indentation, trace } = {}) {
1568
+ const seen = new WeakMap();
1569
+ const serializedValue = serializeValue(value, seen, trace, '');
1570
+ return JSON.stringify(serializedValue, undefined, indentation);
1567
1571
  }
1568
1572
 
1569
1573
  /**
@@ -2037,1435 +2041,631 @@ function logger$(...fns) {
2037
2041
  }
2038
2042
 
2039
2043
  var _computedKey$3, _computedKey1$3;
2040
- /**
2041
- * @module LRUCache
2042
- */ const defaultPerf = typeof performance === 'object' && performance && typeof performance.now === 'function' ? performance : Date;
2043
- const warned = new Set();
2044
- /* c8 ignore start */ const PROCESS = typeof process === 'object' && !!process ? process : {};
2045
- /* c8 ignore start */ const emitWarning = (msg, type, code, fn)=>{
2046
- typeof PROCESS.emitWarning === 'function' ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
2047
- };
2048
- let AC = globalThis.AbortController;
2049
- let AS = globalThis.AbortSignal;
2050
- /* c8 ignore start */ if (typeof AC === 'undefined') {
2051
- //@ts-ignore
2052
- AS = class AbortSignal {
2044
+ var x$1 = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, I$1 = new Set, R$1 = typeof process == "object" && process ? process : {}, U$1 = (c, t, e, i)=>{
2045
+ typeof R$1.emitWarning == "function" ? R$1.emitWarning(c, t, e, i) : console.error(`[${e}] ${t}: ${c}`);
2046
+ }, C$1 = globalThis.AbortController, D$1 = globalThis.AbortSignal;
2047
+ if (typeof C$1 > "u") {
2048
+ D$1 = class {
2053
2049
  onabort;
2054
2050
  _onabort = [];
2055
2051
  reason;
2056
2052
  aborted = false;
2057
- addEventListener(_, fn) {
2058
- this._onabort.push(fn);
2053
+ addEventListener(i, s) {
2054
+ this._onabort.push(s);
2059
2055
  }
2060
- };
2061
- //@ts-ignore
2062
- AC = class AbortController {
2056
+ }, C$1 = class {
2063
2057
  constructor(){
2064
- warnACPolyfill();
2058
+ t();
2065
2059
  }
2066
- signal = new AS();
2067
- abort(reason) {
2068
- if (this.signal.aborted) return;
2069
- //@ts-ignore
2070
- this.signal.reason = reason;
2071
- //@ts-ignore
2072
- this.signal.aborted = true;
2073
- //@ts-ignore
2074
- for (const fn of this.signal._onabort){
2075
- fn(reason);
2060
+ signal = new D$1;
2061
+ abort(i) {
2062
+ if (!this.signal.aborted) {
2063
+ this.signal.reason = i, this.signal.aborted = true;
2064
+ for (let s of this.signal._onabort)s(i);
2065
+ this.signal.onabort?.(i);
2076
2066
  }
2077
- this.signal.onabort?.(reason);
2078
2067
  }
2079
2068
  };
2080
- let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
2081
- const warnACPolyfill = ()=>{
2082
- if (!printACPolyfillWarning) return;
2083
- printACPolyfillWarning = false;
2084
- emitWarning('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', warnACPolyfill);
2069
+ let c = R$1.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1", t = ()=>{
2070
+ c && (c = false, U$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));
2085
2071
  };
2086
2072
  }
2087
- /* c8 ignore stop */ const shouldWarn = (code)=>!warned.has(code);
2088
- const isPosInt = (n)=>n && n === Math.floor(n) && n > 0 && isFinite(n);
2089
- /* c8 ignore start */ // This is a little bit ridiculous, tbh.
2090
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
2091
- // And well before that point, you're caching the entire world, I mean,
2092
- // that's ~32GB of just integers for the next/prev links, plus whatever
2093
- // else to hold that many keys and values. Just filling the memory with
2094
- // zeroes at init time is brutal when you get that big.
2095
- // But why not be complete?
2096
- // Maybe in the future, these limits will have expanded.
2097
- const getUintArray = (max)=>!isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
2098
- /* c8 ignore stop */ class ZeroArray extends Array {
2099
- constructor(size){
2100
- super(size);
2101
- this.fill(0);
2102
- }
2103
- }
2104
- class Stack {
2073
+ _computedKey$3 = Symbol.iterator, _computedKey1$3 = Symbol.toStringTag;
2074
+ var G$1 = (c)=>!I$1.has(c), y = (c)=>c && c === Math.floor(c) && c > 0 && isFinite(c), M$1 = (c)=>y(c) ? c <= Math.pow(2, 8) ? Uint8Array : c <= Math.pow(2, 16) ? Uint16Array : c <= Math.pow(2, 32) ? Uint32Array : c <= Number.MAX_SAFE_INTEGER ? z : null : null, z = class extends Array {
2075
+ constructor(t){
2076
+ super(t), this.fill(0);
2077
+ }
2078
+ }, W$1 = class c {
2105
2079
  heap;
2106
2080
  length;
2107
- // private constructor
2108
- static #constructing = false;
2109
- static create(max) {
2110
- const HeapCls = getUintArray(max);
2111
- if (!HeapCls) return [];
2112
- Stack.#constructing = true;
2113
- const s = new Stack(max, HeapCls);
2114
- Stack.#constructing = false;
2115
- return s;
2081
+ static #o = false;
2082
+ static create(t) {
2083
+ let e = M$1(t);
2084
+ if (!e) return [];
2085
+ c.#o = true;
2086
+ let i = new c(t, e);
2087
+ return c.#o = false, i;
2116
2088
  }
2117
- constructor(max, HeapCls){
2118
- /* c8 ignore start */ if (!Stack.#constructing) {
2119
- throw new TypeError('instantiate Stack using Stack.create(n)');
2120
- }
2121
- /* c8 ignore stop */ this.heap = new HeapCls(max);
2122
- this.length = 0;
2089
+ constructor(t, e){
2090
+ if (!c.#o) throw new TypeError("instantiate Stack using Stack.create(n)");
2091
+ this.heap = new e(t), this.length = 0;
2123
2092
  }
2124
- push(n) {
2125
- this.heap[this.length++] = n;
2093
+ push(t) {
2094
+ this.heap[this.length++] = t;
2126
2095
  }
2127
2096
  pop() {
2128
2097
  return this.heap[--this.length];
2129
2098
  }
2130
- }
2131
- _computedKey$3 = Symbol.iterator, _computedKey1$3 = Symbol.toStringTag;
2132
- /**
2133
- * Default export, the thing you're using this module to get.
2134
- *
2135
- * The `K` and `V` types define the key and value types, respectively. The
2136
- * optional `FC` type defines the type of the `context` object passed to
2137
- * `cache.fetch()` and `cache.memo()`.
2138
- *
2139
- * Keys and values **must not** be `null` or `undefined`.
2140
- *
2141
- * All properties from the options object (with the exception of `max`,
2142
- * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
2143
- * added as normal public members. (The listed options are read-only getters.)
2144
- *
2145
- * Changing any of these will alter the defaults for subsequent method calls.
2146
- */ class LRUCache {
2147
- // options that cannot be changed without disaster
2148
- #max;
2149
- #maxSize;
2150
- #dispose;
2151
- #onInsert;
2152
- #disposeAfter;
2153
- #fetchMethod;
2154
- #memoMethod;
2155
- #perf;
2156
- /**
2157
- * {@link LRUCache.OptionsBase.perf}
2158
- */ get perf() {
2159
- return this.#perf;
2099
+ }, L$1 = class c {
2100
+ #o;
2101
+ #c;
2102
+ #w;
2103
+ #C;
2104
+ #S;
2105
+ #L;
2106
+ #I;
2107
+ #m;
2108
+ get perf() {
2109
+ return this.#m;
2160
2110
  }
2161
- /**
2162
- * {@link LRUCache.OptionsBase.ttl}
2163
- */ ttl;
2164
- /**
2165
- * {@link LRUCache.OptionsBase.ttlResolution}
2166
- */ ttlResolution;
2167
- /**
2168
- * {@link LRUCache.OptionsBase.ttlAutopurge}
2169
- */ ttlAutopurge;
2170
- /**
2171
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
2172
- */ updateAgeOnGet;
2173
- /**
2174
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
2175
- */ updateAgeOnHas;
2176
- /**
2177
- * {@link LRUCache.OptionsBase.allowStale}
2178
- */ allowStale;
2179
- /**
2180
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
2181
- */ noDisposeOnSet;
2182
- /**
2183
- * {@link LRUCache.OptionsBase.noUpdateTTL}
2184
- */ noUpdateTTL;
2185
- /**
2186
- * {@link LRUCache.OptionsBase.maxEntrySize}
2187
- */ maxEntrySize;
2188
- /**
2189
- * {@link LRUCache.OptionsBase.sizeCalculation}
2190
- */ sizeCalculation;
2191
- /**
2192
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
2193
- */ noDeleteOnFetchRejection;
2194
- /**
2195
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
2196
- */ noDeleteOnStaleGet;
2197
- /**
2198
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
2199
- */ allowStaleOnFetchAbort;
2200
- /**
2201
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
2202
- */ allowStaleOnFetchRejection;
2203
- /**
2204
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
2205
- */ ignoreFetchAbort;
2206
- // computed properties
2207
- #size;
2208
- #calculatedSize;
2209
- #keyMap;
2210
- #keyList;
2211
- #valList;
2212
- #next;
2213
- #prev;
2214
- #head;
2215
- #tail;
2216
- #free;
2217
- #disposed;
2218
- #sizes;
2219
- #starts;
2220
- #ttls;
2221
- #hasDispose;
2222
- #hasFetchMethod;
2223
- #hasDisposeAfter;
2224
- #hasOnInsert;
2225
- /**
2226
- * Do not call this method unless you need to inspect the
2227
- * inner workings of the cache. If anything returned by this
2228
- * object is modified in any way, strange breakage may occur.
2229
- *
2230
- * These fields are private for a reason!
2231
- *
2232
- * @internal
2233
- */ static unsafeExposeInternals(c) {
2111
+ ttl;
2112
+ ttlResolution;
2113
+ ttlAutopurge;
2114
+ updateAgeOnGet;
2115
+ updateAgeOnHas;
2116
+ allowStale;
2117
+ noDisposeOnSet;
2118
+ noUpdateTTL;
2119
+ maxEntrySize;
2120
+ sizeCalculation;
2121
+ noDeleteOnFetchRejection;
2122
+ noDeleteOnStaleGet;
2123
+ allowStaleOnFetchAbort;
2124
+ allowStaleOnFetchRejection;
2125
+ ignoreFetchAbort;
2126
+ #n;
2127
+ #_;
2128
+ #s;
2129
+ #i;
2130
+ #t;
2131
+ #a;
2132
+ #u;
2133
+ #l;
2134
+ #h;
2135
+ #b;
2136
+ #r;
2137
+ #y;
2138
+ #A;
2139
+ #d;
2140
+ #g;
2141
+ #T;
2142
+ #v;
2143
+ #f;
2144
+ #U;
2145
+ static unsafeExposeInternals(t) {
2234
2146
  return {
2235
- // properties
2236
- starts: c.#starts,
2237
- ttls: c.#ttls,
2238
- sizes: c.#sizes,
2239
- keyMap: c.#keyMap,
2240
- keyList: c.#keyList,
2241
- valList: c.#valList,
2242
- next: c.#next,
2243
- prev: c.#prev,
2147
+ starts: t.#A,
2148
+ ttls: t.#d,
2149
+ autopurgeTimers: t.#g,
2150
+ sizes: t.#y,
2151
+ keyMap: t.#s,
2152
+ keyList: t.#i,
2153
+ valList: t.#t,
2154
+ next: t.#a,
2155
+ prev: t.#u,
2244
2156
  get head () {
2245
- return c.#head;
2157
+ return t.#l;
2246
2158
  },
2247
2159
  get tail () {
2248
- return c.#tail;
2160
+ return t.#h;
2249
2161
  },
2250
- free: c.#free,
2251
- // methods
2252
- isBackgroundFetch: (p)=>c.#isBackgroundFetch(p),
2253
- backgroundFetch: (k, index, options, context)=>c.#backgroundFetch(k, index, options, context),
2254
- moveToTail: (index)=>c.#moveToTail(index),
2255
- indexes: (options)=>c.#indexes(options),
2256
- rindexes: (options)=>c.#rindexes(options),
2257
- isStale: (index)=>c.#isStale(index)
2162
+ free: t.#b,
2163
+ isBackgroundFetch: (e)=>t.#e(e),
2164
+ backgroundFetch: (e, i, s, n)=>t.#G(e, i, s, n),
2165
+ moveToTail: (e)=>t.#D(e),
2166
+ indexes: (e)=>t.#F(e),
2167
+ rindexes: (e)=>t.#O(e),
2168
+ isStale: (e)=>t.#p(e)
2258
2169
  };
2259
2170
  }
2260
- // Protected read-only members
2261
- /**
2262
- * {@link LRUCache.OptionsBase.max} (read-only)
2263
- */ get max() {
2264
- return this.#max;
2171
+ get max() {
2172
+ return this.#o;
2265
2173
  }
2266
- /**
2267
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
2268
- */ get maxSize() {
2269
- return this.#maxSize;
2174
+ get maxSize() {
2175
+ return this.#c;
2270
2176
  }
2271
- /**
2272
- * The total computed size of items in the cache (read-only)
2273
- */ get calculatedSize() {
2274
- return this.#calculatedSize;
2177
+ get calculatedSize() {
2178
+ return this.#_;
2275
2179
  }
2276
- /**
2277
- * The number of items stored in the cache (read-only)
2278
- */ get size() {
2279
- return this.#size;
2180
+ get size() {
2181
+ return this.#n;
2280
2182
  }
2281
- /**
2282
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
2283
- */ get fetchMethod() {
2284
- return this.#fetchMethod;
2183
+ get fetchMethod() {
2184
+ return this.#L;
2285
2185
  }
2286
2186
  get memoMethod() {
2287
- return this.#memoMethod;
2187
+ return this.#I;
2288
2188
  }
2289
- /**
2290
- * {@link LRUCache.OptionsBase.dispose} (read-only)
2291
- */ get dispose() {
2292
- return this.#dispose;
2189
+ get dispose() {
2190
+ return this.#w;
2293
2191
  }
2294
- /**
2295
- * {@link LRUCache.OptionsBase.onInsert} (read-only)
2296
- */ get onInsert() {
2297
- return this.#onInsert;
2192
+ get onInsert() {
2193
+ return this.#C;
2298
2194
  }
2299
- /**
2300
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
2301
- */ get disposeAfter() {
2302
- return this.#disposeAfter;
2303
- }
2304
- constructor(options){
2305
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
2306
- if (perf !== undefined) {
2307
- if (typeof perf?.now !== 'function') {
2308
- throw new TypeError('perf option must have a now() method if specified');
2309
- }
2310
- }
2311
- this.#perf = perf ?? defaultPerf;
2312
- if (max !== 0 && !isPosInt(max)) {
2313
- throw new TypeError('max option must be a nonnegative integer');
2314
- }
2315
- const UintArray = max ? getUintArray(max) : Array;
2316
- if (!UintArray) {
2317
- throw new Error('invalid max value: ' + max);
2318
- }
2319
- this.#max = max;
2320
- this.#maxSize = maxSize;
2321
- this.maxEntrySize = maxEntrySize || this.#maxSize;
2322
- this.sizeCalculation = sizeCalculation;
2323
- if (this.sizeCalculation) {
2324
- if (!this.#maxSize && !this.maxEntrySize) {
2325
- throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
2326
- }
2327
- if (typeof this.sizeCalculation !== 'function') {
2328
- throw new TypeError('sizeCalculation set to non-function');
2329
- }
2330
- }
2331
- if (memoMethod !== undefined && typeof memoMethod !== 'function') {
2332
- throw new TypeError('memoMethod must be a function if defined');
2333
- }
2334
- this.#memoMethod = memoMethod;
2335
- if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
2336
- throw new TypeError('fetchMethod must be a function if specified');
2337
- }
2338
- this.#fetchMethod = fetchMethod;
2339
- this.#hasFetchMethod = !!fetchMethod;
2340
- this.#keyMap = new Map();
2341
- this.#keyList = new Array(max).fill(undefined);
2342
- this.#valList = new Array(max).fill(undefined);
2343
- this.#next = new UintArray(max);
2344
- this.#prev = new UintArray(max);
2345
- this.#head = 0;
2346
- this.#tail = 0;
2347
- this.#free = Stack.create(max);
2348
- this.#size = 0;
2349
- this.#calculatedSize = 0;
2350
- if (typeof dispose === 'function') {
2351
- this.#dispose = dispose;
2352
- }
2353
- if (typeof onInsert === 'function') {
2354
- this.#onInsert = onInsert;
2355
- }
2356
- if (typeof disposeAfter === 'function') {
2357
- this.#disposeAfter = disposeAfter;
2358
- this.#disposed = [];
2359
- } else {
2360
- this.#disposeAfter = undefined;
2361
- this.#disposed = undefined;
2362
- }
2363
- this.#hasDispose = !!this.#dispose;
2364
- this.#hasOnInsert = !!this.#onInsert;
2365
- this.#hasDisposeAfter = !!this.#disposeAfter;
2366
- this.noDisposeOnSet = !!noDisposeOnSet;
2367
- this.noUpdateTTL = !!noUpdateTTL;
2368
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
2369
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
2370
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
2371
- this.ignoreFetchAbort = !!ignoreFetchAbort;
2372
- // NB: maxEntrySize is set to maxSize if it's set
2373
- if (this.maxEntrySize !== 0) {
2374
- if (this.#maxSize !== 0) {
2375
- if (!isPosInt(this.#maxSize)) {
2376
- throw new TypeError('maxSize must be a positive integer if specified');
2377
- }
2378
- }
2379
- if (!isPosInt(this.maxEntrySize)) {
2380
- throw new TypeError('maxEntrySize must be a positive integer if specified');
2381
- }
2382
- this.#initializeSizeTracking();
2383
- }
2384
- this.allowStale = !!allowStale;
2385
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
2386
- this.updateAgeOnGet = !!updateAgeOnGet;
2387
- this.updateAgeOnHas = !!updateAgeOnHas;
2388
- this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
2389
- this.ttlAutopurge = !!ttlAutopurge;
2390
- this.ttl = ttl || 0;
2391
- if (this.ttl) {
2392
- if (!isPosInt(this.ttl)) {
2393
- throw new TypeError('ttl must be a positive integer if specified');
2394
- }
2395
- this.#initializeTTLTracking();
2396
- }
2397
- // do not allow completely unbounded caches
2398
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
2399
- throw new TypeError('At least one of max, maxSize, or ttl is required');
2400
- }
2401
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
2402
- const code = 'LRU_CACHE_UNBOUNDED';
2403
- if (shouldWarn(code)) {
2404
- warned.add(code);
2405
- const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' + 'result in unbounded memory consumption.';
2406
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
2407
- }
2195
+ get disposeAfter() {
2196
+ return this.#S;
2197
+ }
2198
+ constructor(t){
2199
+ let { max: e = 0, ttl: i, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: o, updateAgeOnHas: h, allowStale: r, dispose: a, onInsert: w, disposeAfter: f, noDisposeOnSet: d, noUpdateTTL: g, maxSize: A = 0, maxEntrySize: p = 0, sizeCalculation: _, fetchMethod: l, memoMethod: S, noDeleteOnFetchRejection: b, noDeleteOnStaleGet: m, allowStaleOnFetchRejection: u, allowStaleOnFetchAbort: T, ignoreFetchAbort: F, perf: v } = t;
2200
+ if (v !== void 0 && typeof v?.now != "function") throw new TypeError("perf option must have a now() method if specified");
2201
+ if (this.#m = v ?? x$1, e !== 0 && !y(e)) throw new TypeError("max option must be a nonnegative integer");
2202
+ let O = e ? M$1(e) : Array;
2203
+ if (!O) throw new Error("invalid max value: " + e);
2204
+ if (this.#o = e, this.#c = A, this.maxEntrySize = p || this.#c, this.sizeCalculation = _, this.sizeCalculation) {
2205
+ if (!this.#c && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
2206
+ if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
2207
+ }
2208
+ if (S !== void 0 && typeof S != "function") throw new TypeError("memoMethod must be a function if defined");
2209
+ if (this.#I = S, l !== void 0 && typeof l != "function") throw new TypeError("fetchMethod must be a function if specified");
2210
+ if (this.#L = l, this.#v = !!l, this.#s = new Map, this.#i = new Array(e).fill(void 0), this.#t = new Array(e).fill(void 0), this.#a = new O(e), this.#u = new O(e), this.#l = 0, this.#h = 0, this.#b = W$1.create(e), this.#n = 0, this.#_ = 0, typeof a == "function" && (this.#w = a), typeof w == "function" && (this.#C = w), typeof f == "function" ? (this.#S = f, this.#r = []) : (this.#S = void 0, this.#r = void 0), this.#T = !!this.#w, this.#U = !!this.#C, this.#f = !!this.#S, this.noDisposeOnSet = !!d, this.noUpdateTTL = !!g, this.noDeleteOnFetchRejection = !!b, this.allowStaleOnFetchRejection = !!u, this.allowStaleOnFetchAbort = !!T, this.ignoreFetchAbort = !!F, this.maxEntrySize !== 0) {
2211
+ if (this.#c !== 0 && !y(this.#c)) throw new TypeError("maxSize must be a positive integer if specified");
2212
+ if (!y(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
2213
+ this.#B();
2214
+ }
2215
+ if (this.allowStale = !!r, this.noDeleteOnStaleGet = !!m, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!h, this.ttlResolution = y(s) || s === 0 ? s : 1, this.ttlAutopurge = !!n, this.ttl = i || 0, this.ttl) {
2216
+ if (!y(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
2217
+ this.#j();
2218
+ }
2219
+ if (this.#o === 0 && this.ttl === 0 && this.#c === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
2220
+ if (!this.ttlAutopurge && !this.#o && !this.#c) {
2221
+ let E = "LRU_CACHE_UNBOUNDED";
2222
+ G$1(E) && (I$1.add(E), U$1("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", E, c));
2408
2223
  }
2409
2224
  }
2410
- /**
2411
- * Return the number of ms left in the item's TTL. If item is not in cache,
2412
- * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
2413
- */ getRemainingTTL(key) {
2414
- return this.#keyMap.has(key) ? Infinity : 0;
2415
- }
2416
- #initializeTTLTracking() {
2417
- const ttls = new ZeroArray(this.#max);
2418
- const starts = new ZeroArray(this.#max);
2419
- this.#ttls = ttls;
2420
- this.#starts = starts;
2421
- this.#setItemTTL = (index, ttl, start = this.#perf.now())=>{
2422
- starts[index] = ttl !== 0 ? start : 0;
2423
- ttls[index] = ttl;
2424
- if (ttl !== 0 && this.ttlAutopurge) {
2425
- const t = setTimeout(()=>{
2426
- if (this.#isStale(index)) {
2427
- this.#delete(this.#keyList[index], 'expire');
2428
- }
2429
- }, ttl + 1);
2430
- // unref() not supported on all platforms
2431
- /* c8 ignore start */ if (t.unref) {
2432
- t.unref();
2433
- }
2434
- /* c8 ignore stop */ }
2435
- };
2436
- this.#updateItemAge = (index)=>{
2437
- starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
2225
+ getRemainingTTL(t) {
2226
+ return this.#s.has(t) ? 1 / 0 : 0;
2227
+ }
2228
+ #j() {
2229
+ let t = new z(this.#o), e = new z(this.#o);
2230
+ this.#d = t, this.#A = e;
2231
+ let i = this.ttlAutopurge ? new Array(this.#o) : void 0;
2232
+ this.#g = i, this.#N = (h, r, a = this.#m.now())=>{
2233
+ e[h] = r !== 0 ? a : 0, t[h] = r, s(h, r);
2234
+ }, this.#R = (h)=>{
2235
+ e[h] = t[h] !== 0 ? this.#m.now() : 0, s(h, t[h]);
2438
2236
  };
2439
- this.#statusTTL = (status, index)=>{
2440
- if (ttls[index]) {
2441
- const ttl = ttls[index];
2442
- const start = starts[index];
2443
- /* c8 ignore next */ if (!ttl || !start) return;
2444
- status.ttl = ttl;
2445
- status.start = start;
2446
- status.now = cachedNow || getNow();
2447
- const age = status.now - start;
2448
- status.remainingTTL = ttl - age;
2237
+ let s = this.ttlAutopurge ? (h, r)=>{
2238
+ if (i?.[h] && (clearTimeout(i[h]), i[h] = void 0), r && r !== 0 && i) {
2239
+ let a = setTimeout(()=>{
2240
+ this.#p(h) && this.#E(this.#i[h], "expire");
2241
+ }, r + 1);
2242
+ a.unref && a.unref(), i[h] = a;
2243
+ }
2244
+ } : ()=>{};
2245
+ this.#z = (h, r)=>{
2246
+ if (t[r]) {
2247
+ let a = t[r], w = e[r];
2248
+ if (!a || !w) return;
2249
+ h.ttl = a, h.start = w, h.now = n || o();
2250
+ let f = h.now - w;
2251
+ h.remainingTTL = a - f;
2449
2252
  }
2450
2253
  };
2451
- // debounce calls to perf.now() to 1s so we're not hitting
2452
- // that costly call repeatedly.
2453
- let cachedNow = 0;
2454
- const getNow = ()=>{
2455
- const n = this.#perf.now();
2254
+ let n = 0, o = ()=>{
2255
+ let h = this.#m.now();
2456
2256
  if (this.ttlResolution > 0) {
2457
- cachedNow = n;
2458
- const t = setTimeout(()=>cachedNow = 0, this.ttlResolution);
2459
- // not available on all platforms
2460
- /* c8 ignore start */ if (t.unref) {
2461
- t.unref();
2462
- }
2463
- /* c8 ignore stop */ }
2464
- return n;
2465
- };
2466
- this.getRemainingTTL = (key)=>{
2467
- const index = this.#keyMap.get(key);
2468
- if (index === undefined) {
2469
- return 0;
2257
+ n = h;
2258
+ let r = setTimeout(()=>n = 0, this.ttlResolution);
2259
+ r.unref && r.unref();
2470
2260
  }
2471
- const ttl = ttls[index];
2472
- const start = starts[index];
2473
- if (!ttl || !start) {
2474
- return Infinity;
2475
- }
2476
- const age = (cachedNow || getNow()) - start;
2477
- return ttl - age;
2261
+ return h;
2478
2262
  };
2479
- this.#isStale = (index)=>{
2480
- const s = starts[index];
2481
- const t = ttls[index];
2482
- return !!t && !!s && (cachedNow || getNow()) - s > t;
2263
+ this.getRemainingTTL = (h)=>{
2264
+ let r = this.#s.get(h);
2265
+ if (r === void 0) return 0;
2266
+ let a = t[r], w = e[r];
2267
+ if (!a || !w) return 1 / 0;
2268
+ let f = (n || o()) - w;
2269
+ return a - f;
2270
+ }, this.#p = (h)=>{
2271
+ let r = e[h], a = t[h];
2272
+ return !!a && !!r && (n || o()) - r > a;
2483
2273
  };
2484
2274
  }
2485
- // conditionally set private methods related to TTL
2486
- #updateItemAge = ()=>{};
2487
- #statusTTL = ()=>{};
2488
- #setItemTTL = ()=>{};
2489
- /* c8 ignore stop */ #isStale = ()=>false;
2490
- #initializeSizeTracking() {
2491
- const sizes = new ZeroArray(this.#max);
2492
- this.#calculatedSize = 0;
2493
- this.#sizes = sizes;
2494
- this.#removeItemSize = (index)=>{
2495
- this.#calculatedSize -= sizes[index];
2496
- sizes[index] = 0;
2497
- };
2498
- this.#requireSize = (k, v, size, sizeCalculation)=>{
2499
- // provisionally accept background fetches.
2500
- // actual value size will be checked when they return.
2501
- if (this.#isBackgroundFetch(v)) {
2502
- return 0;
2503
- }
2504
- if (!isPosInt(size)) {
2505
- if (sizeCalculation) {
2506
- if (typeof sizeCalculation !== 'function') {
2507
- throw new TypeError('sizeCalculation must be a function');
2508
- }
2509
- size = sizeCalculation(v, k);
2510
- if (!isPosInt(size)) {
2511
- throw new TypeError('sizeCalculation return invalid (expect positive integer)');
2512
- }
2513
- } else {
2514
- throw new TypeError('invalid size value (must be positive integer). ' + 'When maxSize or maxEntrySize is used, sizeCalculation ' + 'or size must be set.');
2515
- }
2516
- }
2517
- return size;
2518
- };
2519
- this.#addItemSize = (index, size, status)=>{
2520
- sizes[index] = size;
2521
- if (this.#maxSize) {
2522
- const maxSize = this.#maxSize - sizes[index];
2523
- while(this.#calculatedSize > maxSize){
2524
- this.#evict(true);
2525
- }
2526
- }
2527
- this.#calculatedSize += sizes[index];
2528
- if (status) {
2529
- status.entrySize = size;
2530
- status.totalCalculatedSize = this.#calculatedSize;
2275
+ #R = ()=>{};
2276
+ #z = ()=>{};
2277
+ #N = ()=>{};
2278
+ #p = ()=>false;
2279
+ #B() {
2280
+ let t = new z(this.#o);
2281
+ this.#_ = 0, this.#y = t, this.#W = (e)=>{
2282
+ this.#_ -= t[e], t[e] = 0;
2283
+ }, this.#P = (e, i, s, n)=>{
2284
+ if (this.#e(i)) return 0;
2285
+ if (!y(s)) if (n) {
2286
+ if (typeof n != "function") throw new TypeError("sizeCalculation must be a function");
2287
+ if (s = n(i, e), !y(s)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
2288
+ } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
2289
+ return s;
2290
+ }, this.#M = (e, i, s)=>{
2291
+ if (t[e] = i, this.#c) {
2292
+ let n = this.#c - t[e];
2293
+ for(; this.#_ > n;)this.#x(true);
2531
2294
  }
2295
+ this.#_ += t[e], s && (s.entrySize = i, s.totalCalculatedSize = this.#_);
2532
2296
  };
2533
2297
  }
2534
- #removeItemSize = (_i)=>{};
2535
- #addItemSize = (_i, _s, _st)=>{};
2536
- #requireSize = (_k, _v, size, sizeCalculation)=>{
2537
- if (size || sizeCalculation) {
2538
- throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
2539
- }
2298
+ #W = (t)=>{};
2299
+ #M = (t, e, i)=>{};
2300
+ #P = (t, e, i, s)=>{
2301
+ if (i || s) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
2540
2302
  return 0;
2541
2303
  };
2542
- *#indexes({ allowStale = this.allowStale } = {}) {
2543
- if (this.#size) {
2544
- for(let i = this.#tail; true;){
2545
- if (!this.#isValidIndex(i)) {
2546
- break;
2547
- }
2548
- if (allowStale || !this.#isStale(i)) {
2549
- yield i;
2550
- }
2551
- if (i === this.#head) {
2552
- break;
2553
- } else {
2554
- i = this.#prev[i];
2555
- }
2556
- }
2557
- }
2304
+ *#F({ allowStale: t = this.allowStale } = {}) {
2305
+ if (this.#n) for(let e = this.#h; !(!this.#H(e) || ((t || !this.#p(e)) && (yield e), e === this.#l));)e = this.#u[e];
2558
2306
  }
2559
- *#rindexes({ allowStale = this.allowStale } = {}) {
2560
- if (this.#size) {
2561
- for(let i = this.#head; true;){
2562
- if (!this.#isValidIndex(i)) {
2563
- break;
2564
- }
2565
- if (allowStale || !this.#isStale(i)) {
2566
- yield i;
2567
- }
2568
- if (i === this.#tail) {
2569
- break;
2570
- } else {
2571
- i = this.#next[i];
2572
- }
2573
- }
2574
- }
2307
+ *#O({ allowStale: t = this.allowStale } = {}) {
2308
+ if (this.#n) for(let e = this.#l; !(!this.#H(e) || ((t || !this.#p(e)) && (yield e), e === this.#h));)e = this.#a[e];
2575
2309
  }
2576
- #isValidIndex(index) {
2577
- return index !== undefined && this.#keyMap.get(this.#keyList[index]) === index;
2310
+ #H(t) {
2311
+ return t !== void 0 && this.#s.get(this.#i[t]) === t;
2578
2312
  }
2579
- /**
2580
- * Return a generator yielding `[key, value]` pairs,
2581
- * in order from most recently used to least recently used.
2582
- */ *entries() {
2583
- for (const i of this.#indexes()){
2584
- if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
2585
- yield [
2586
- this.#keyList[i],
2587
- this.#valList[i]
2588
- ];
2589
- }
2590
- }
2313
+ *entries() {
2314
+ for (let t of this.#F())this.#t[t] !== void 0 && this.#i[t] !== void 0 && !this.#e(this.#t[t]) && (yield [
2315
+ this.#i[t],
2316
+ this.#t[t]
2317
+ ]);
2591
2318
  }
2592
- /**
2593
- * Inverse order version of {@link LRUCache.entries}
2594
- *
2595
- * Return a generator yielding `[key, value]` pairs,
2596
- * in order from least recently used to most recently used.
2597
- */ *rentries() {
2598
- for (const i of this.#rindexes()){
2599
- if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
2600
- yield [
2601
- this.#keyList[i],
2602
- this.#valList[i]
2603
- ];
2604
- }
2605
- }
2319
+ *rentries() {
2320
+ for (let t of this.#O())this.#t[t] !== void 0 && this.#i[t] !== void 0 && !this.#e(this.#t[t]) && (yield [
2321
+ this.#i[t],
2322
+ this.#t[t]
2323
+ ]);
2606
2324
  }
2607
- /**
2608
- * Return a generator yielding the keys in the cache,
2609
- * in order from most recently used to least recently used.
2610
- */ *keys() {
2611
- for (const i of this.#indexes()){
2612
- const k = this.#keyList[i];
2613
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
2614
- yield k;
2615
- }
2325
+ *keys() {
2326
+ for (let t of this.#F()){
2327
+ let e = this.#i[t];
2328
+ e !== void 0 && !this.#e(this.#t[t]) && (yield e);
2616
2329
  }
2617
2330
  }
2618
- /**
2619
- * Inverse order version of {@link LRUCache.keys}
2620
- *
2621
- * Return a generator yielding the keys in the cache,
2622
- * in order from least recently used to most recently used.
2623
- */ *rkeys() {
2624
- for (const i of this.#rindexes()){
2625
- const k = this.#keyList[i];
2626
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
2627
- yield k;
2628
- }
2331
+ *rkeys() {
2332
+ for (let t of this.#O()){
2333
+ let e = this.#i[t];
2334
+ e !== void 0 && !this.#e(this.#t[t]) && (yield e);
2629
2335
  }
2630
2336
  }
2631
- /**
2632
- * Return a generator yielding the values in the cache,
2633
- * in order from most recently used to least recently used.
2634
- */ *values() {
2635
- for (const i of this.#indexes()){
2636
- const v = this.#valList[i];
2637
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
2638
- yield this.#valList[i];
2639
- }
2640
- }
2337
+ *values() {
2338
+ for (let t of this.#F())this.#t[t] !== void 0 && !this.#e(this.#t[t]) && (yield this.#t[t]);
2641
2339
  }
2642
- /**
2643
- * Inverse order version of {@link LRUCache.values}
2644
- *
2645
- * Return a generator yielding the values in the cache,
2646
- * in order from least recently used to most recently used.
2647
- */ *rvalues() {
2648
- for (const i of this.#rindexes()){
2649
- const v = this.#valList[i];
2650
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
2651
- yield this.#valList[i];
2652
- }
2653
- }
2340
+ *rvalues() {
2341
+ for (let t of this.#O())this.#t[t] !== void 0 && !this.#e(this.#t[t]) && (yield this.#t[t]);
2654
2342
  }
2655
- /**
2656
- * Iterating over the cache itself yields the same results as
2657
- * {@link LRUCache.entries}
2658
- */ [_computedKey$3]() {
2343
+ [_computedKey$3]() {
2659
2344
  return this.entries();
2660
2345
  }
2661
- /**
2662
- * A String value that is used in the creation of the default string
2663
- * description of an object. Called by the built-in method
2664
- * `Object.prototype.toString`.
2665
- */ [_computedKey1$3] = 'LRUCache';
2666
- /**
2667
- * Find a value for which the supplied fn method returns a truthy value,
2668
- * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
2669
- */ find(fn, getOptions = {}) {
2670
- for (const i of this.#indexes()){
2671
- const v = this.#valList[i];
2672
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
2673
- if (value === undefined) continue;
2674
- if (fn(value, this.#keyList[i], this)) {
2675
- return this.get(this.#keyList[i], getOptions);
2676
- }
2346
+ [_computedKey1$3] = "LRUCache";
2347
+ find(t, e = {}) {
2348
+ for (let i of this.#F()){
2349
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
2350
+ if (n !== void 0 && t(n, this.#i[i], this)) return this.get(this.#i[i], e);
2677
2351
  }
2678
2352
  }
2679
- /**
2680
- * Call the supplied function on each item in the cache, in order from most
2681
- * recently used to least recently used.
2682
- *
2683
- * `fn` is called as `fn(value, key, cache)`.
2684
- *
2685
- * If `thisp` is provided, function will be called in the `this`-context of
2686
- * the provided object, or the cache if no `thisp` object is provided.
2687
- *
2688
- * Does not update age or recenty of use, or iterate over stale values.
2689
- */ forEach(fn, thisp = this) {
2690
- for (const i of this.#indexes()){
2691
- const v = this.#valList[i];
2692
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
2693
- if (value === undefined) continue;
2694
- fn.call(thisp, value, this.#keyList[i], this);
2353
+ forEach(t, e = this) {
2354
+ for (let i of this.#F()){
2355
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
2356
+ n !== void 0 && t.call(e, n, this.#i[i], this);
2695
2357
  }
2696
2358
  }
2697
- /**
2698
- * The same as {@link LRUCache.forEach} but items are iterated over in
2699
- * reverse order. (ie, less recently used items are iterated over first.)
2700
- */ rforEach(fn, thisp = this) {
2701
- for (const i of this.#rindexes()){
2702
- const v = this.#valList[i];
2703
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
2704
- if (value === undefined) continue;
2705
- fn.call(thisp, value, this.#keyList[i], this);
2359
+ rforEach(t, e = this) {
2360
+ for (let i of this.#O()){
2361
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
2362
+ n !== void 0 && t.call(e, n, this.#i[i], this);
2706
2363
  }
2707
2364
  }
2708
- /**
2709
- * Delete any stale entries. Returns true if anything was removed,
2710
- * false otherwise.
2711
- */ purgeStale() {
2712
- let deleted = false;
2713
- for (const i of this.#rindexes({
2365
+ purgeStale() {
2366
+ let t = false;
2367
+ for (let e of this.#O({
2714
2368
  allowStale: true
2715
- })){
2716
- if (this.#isStale(i)) {
2717
- this.#delete(this.#keyList[i], 'expire');
2718
- deleted = true;
2719
- }
2720
- }
2721
- return deleted;
2369
+ }))this.#p(e) && (this.#E(this.#i[e], "expire"), t = true);
2370
+ return t;
2722
2371
  }
2723
- /**
2724
- * Get the extended info about a given entry, to get its value, size, and
2725
- * TTL info simultaneously. Returns `undefined` if the key is not present.
2726
- *
2727
- * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
2728
- * serialization, the `start` value is always the current timestamp, and the
2729
- * `ttl` is a calculated remaining time to live (negative if expired).
2730
- *
2731
- * Always returns stale values, if their info is found in the cache, so be
2732
- * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
2733
- * if relevant.
2734
- */ info(key) {
2735
- const i = this.#keyMap.get(key);
2736
- if (i === undefined) return undefined;
2737
- const v = this.#valList[i];
2738
- /* c8 ignore start - this isn't tested for the info function,
2739
- * but it's the same logic as found in other places. */ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
2740
- if (value === undefined) return undefined;
2741
- /* c8 ignore end */ const entry = {
2742
- value
2372
+ info(t) {
2373
+ let e = this.#s.get(t);
2374
+ if (e === void 0) return;
2375
+ let i = this.#t[e], s = this.#e(i) ? i.__staleWhileFetching : i;
2376
+ if (s === void 0) return;
2377
+ let n = {
2378
+ value: s
2743
2379
  };
2744
- if (this.#ttls && this.#starts) {
2745
- const ttl = this.#ttls[i];
2746
- const start = this.#starts[i];
2747
- if (ttl && start) {
2748
- const remain = ttl - (this.#perf.now() - start);
2749
- entry.ttl = remain;
2750
- entry.start = Date.now();
2380
+ if (this.#d && this.#A) {
2381
+ let o = this.#d[e], h = this.#A[e];
2382
+ if (o && h) {
2383
+ let r = o - (this.#m.now() - h);
2384
+ n.ttl = r, n.start = Date.now();
2751
2385
  }
2752
2386
  }
2753
- if (this.#sizes) {
2754
- entry.size = this.#sizes[i];
2755
- }
2756
- return entry;
2387
+ return this.#y && (n.size = this.#y[e]), n;
2757
2388
  }
2758
- /**
2759
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
2760
- * passed to {@link LRUCache#load}.
2761
- *
2762
- * The `start` fields are calculated relative to a portable `Date.now()`
2763
- * timestamp, even if `performance.now()` is available.
2764
- *
2765
- * Stale entries are always included in the `dump`, even if
2766
- * {@link LRUCache.OptionsBase.allowStale} is false.
2767
- *
2768
- * Note: this returns an actual array, not a generator, so it can be more
2769
- * easily passed around.
2770
- */ dump() {
2771
- const arr = [];
2772
- for (const i of this.#indexes({
2389
+ dump() {
2390
+ let t = [];
2391
+ for (let e of this.#F({
2773
2392
  allowStale: true
2774
2393
  })){
2775
- const key = this.#keyList[i];
2776
- const v = this.#valList[i];
2777
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
2778
- if (value === undefined || key === undefined) continue;
2779
- const entry = {
2780
- value
2394
+ let i = this.#i[e], s = this.#t[e], n = this.#e(s) ? s.__staleWhileFetching : s;
2395
+ if (n === void 0 || i === void 0) continue;
2396
+ let o = {
2397
+ value: n
2781
2398
  };
2782
- if (this.#ttls && this.#starts) {
2783
- entry.ttl = this.#ttls[i];
2784
- // always dump the start relative to a portable timestamp
2785
- // it's ok for this to be a bit slow, it's a rare operation.
2786
- const age = this.#perf.now() - this.#starts[i];
2787
- entry.start = Math.floor(Date.now() - age);
2788
- }
2789
- if (this.#sizes) {
2790
- entry.size = this.#sizes[i];
2791
- }
2792
- arr.unshift([
2793
- key,
2794
- entry
2399
+ if (this.#d && this.#A) {
2400
+ o.ttl = this.#d[e];
2401
+ let h = this.#m.now() - this.#A[e];
2402
+ o.start = Math.floor(Date.now() - h);
2403
+ }
2404
+ this.#y && (o.size = this.#y[e]), t.unshift([
2405
+ i,
2406
+ o
2795
2407
  ]);
2796
2408
  }
2797
- return arr;
2409
+ return t;
2798
2410
  }
2799
- /**
2800
- * Reset the cache and load in the items in entries in the order listed.
2801
- *
2802
- * The shape of the resulting cache may be different if the same options are
2803
- * not used in both caches.
2804
- *
2805
- * The `start` fields are assumed to be calculated relative to a portable
2806
- * `Date.now()` timestamp, even if `performance.now()` is available.
2807
- */ load(arr) {
2411
+ load(t) {
2808
2412
  this.clear();
2809
- for (const [key, entry] of arr){
2810
- if (entry.start) {
2811
- // entry.start is a portable timestamp, but we may be using
2812
- // node's performance.now(), so calculate the offset, so that
2813
- // we get the intended remaining TTL, no matter how long it's
2814
- // been on ice.
2815
- //
2816
- // it's ok for this to be a bit slow, it's a rare operation.
2817
- const age = Date.now() - entry.start;
2818
- entry.start = this.#perf.now() - age;
2413
+ for (let [e, i] of t){
2414
+ if (i.start) {
2415
+ let s = Date.now() - i.start;
2416
+ i.start = this.#m.now() - s;
2819
2417
  }
2820
- this.set(key, entry.value, entry);
2418
+ this.set(e, i.value, i);
2821
2419
  }
2822
2420
  }
2823
- /**
2824
- * Add a value to the cache.
2825
- *
2826
- * Note: if `undefined` is specified as a value, this is an alias for
2827
- * {@link LRUCache#delete}
2828
- *
2829
- * Fields on the {@link LRUCache.SetOptions} options param will override
2830
- * their corresponding values in the constructor options for the scope
2831
- * of this single `set()` operation.
2832
- *
2833
- * If `start` is provided, then that will set the effective start
2834
- * time for the TTL calculation. Note that this must be a previous
2835
- * value of `performance.now()` if supported, or a previous value of
2836
- * `Date.now()` if not.
2837
- *
2838
- * Options object may also include `size`, which will prevent
2839
- * calling the `sizeCalculation` function and just use the specified
2840
- * number if it is a positive integer, and `noDisposeOnSet` which
2841
- * will prevent calling a `dispose` function in the case of
2842
- * overwrites.
2843
- *
2844
- * If the `size` (or return value of `sizeCalculation`) for a given
2845
- * entry is greater than `maxEntrySize`, then the item will not be
2846
- * added to the cache.
2847
- *
2848
- * Will update the recency of the entry.
2849
- *
2850
- * If the value is `undefined`, then this is an alias for
2851
- * `cache.delete(key)`. `undefined` is never stored in the cache.
2852
- */ set(k, v, setOptions = {}) {
2853
- if (v === undefined) {
2854
- this.delete(k);
2855
- return this;
2856
- }
2857
- const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
2858
- let { noUpdateTTL = this.noUpdateTTL } = setOptions;
2859
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
2860
- // if the item doesn't fit, don't do anything
2861
- // NB: maxEntrySize set to maxSize by default
2862
- if (this.maxEntrySize && size > this.maxEntrySize) {
2863
- if (status) {
2864
- status.set = 'miss';
2865
- status.maxEntrySizeExceeded = true;
2866
- }
2867
- // have to delete, in case something is there already.
2868
- this.#delete(k, 'set');
2869
- return this;
2870
- }
2871
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
2872
- if (index === undefined) {
2873
- // addition
2874
- index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
2875
- this.#keyList[index] = k;
2876
- this.#valList[index] = v;
2877
- this.#keyMap.set(k, index);
2878
- this.#next[this.#tail] = index;
2879
- this.#prev[index] = this.#tail;
2880
- this.#tail = index;
2881
- this.#size++;
2882
- this.#addItemSize(index, size, status);
2883
- if (status) status.set = 'add';
2884
- noUpdateTTL = false;
2885
- if (this.#hasOnInsert) {
2886
- this.#onInsert?.(v, k, 'add');
2887
- }
2888
- } else {
2889
- // update
2890
- this.#moveToTail(index);
2891
- const oldVal = this.#valList[index];
2892
- if (v !== oldVal) {
2893
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
2894
- oldVal.__abortController.abort(new Error('replaced'));
2895
- const { __staleWhileFetching: s } = oldVal;
2896
- if (s !== undefined && !noDisposeOnSet) {
2897
- if (this.#hasDispose) {
2898
- this.#dispose?.(s, k, 'set');
2899
- }
2900
- if (this.#hasDisposeAfter) {
2901
- this.#disposed?.push([
2902
- s,
2903
- k,
2904
- 'set'
2905
- ]);
2906
- }
2907
- }
2908
- } else if (!noDisposeOnSet) {
2909
- if (this.#hasDispose) {
2910
- this.#dispose?.(oldVal, k, 'set');
2911
- }
2912
- if (this.#hasDisposeAfter) {
2913
- this.#disposed?.push([
2914
- oldVal,
2915
- k,
2916
- 'set'
2917
- ]);
2918
- }
2919
- }
2920
- this.#removeItemSize(index);
2921
- this.#addItemSize(index, size, status);
2922
- this.#valList[index] = v;
2923
- if (status) {
2924
- status.set = 'replace';
2925
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
2926
- if (oldValue !== undefined) status.oldValue = oldValue;
2421
+ set(t, e, i = {}) {
2422
+ if (e === void 0) return this.delete(t), this;
2423
+ let { ttl: s = this.ttl, start: n, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: h = this.sizeCalculation, status: r } = i, { noUpdateTTL: a = this.noUpdateTTL } = i, w = this.#P(t, e, i.size || 0, h);
2424
+ if (this.maxEntrySize && w > this.maxEntrySize) return r && (r.set = "miss", r.maxEntrySizeExceeded = true), this.#E(t, "set"), this;
2425
+ let f = this.#n === 0 ? void 0 : this.#s.get(t);
2426
+ if (f === void 0) f = this.#n === 0 ? this.#h : this.#b.length !== 0 ? this.#b.pop() : this.#n === this.#o ? this.#x(false) : this.#n, this.#i[f] = t, this.#t[f] = e, this.#s.set(t, f), this.#a[this.#h] = f, this.#u[f] = this.#h, this.#h = f, this.#n++, this.#M(f, w, r), r && (r.set = "add"), a = false, this.#U && this.#C?.(e, t, "add");
2427
+ else {
2428
+ this.#D(f);
2429
+ let d = this.#t[f];
2430
+ if (e !== d) {
2431
+ if (this.#v && this.#e(d)) {
2432
+ d.__abortController.abort(new Error("replaced"));
2433
+ let { __staleWhileFetching: g } = d;
2434
+ g !== void 0 && !o && (this.#T && this.#w?.(g, t, "set"), this.#f && this.#r?.push([
2435
+ g,
2436
+ t,
2437
+ "set"
2438
+ ]));
2439
+ } else o || (this.#T && this.#w?.(d, t, "set"), this.#f && this.#r?.push([
2440
+ d,
2441
+ t,
2442
+ "set"
2443
+ ]));
2444
+ if (this.#W(f), this.#M(f, w, r), this.#t[f] = e, r) {
2445
+ r.set = "replace";
2446
+ let g = d && this.#e(d) ? d.__staleWhileFetching : d;
2447
+ g !== void 0 && (r.oldValue = g);
2927
2448
  }
2928
- } else if (status) {
2929
- status.set = 'update';
2930
- }
2931
- if (this.#hasOnInsert) {
2932
- this.onInsert?.(v, k, v === oldVal ? 'update' : 'replace');
2933
- }
2449
+ } else r && (r.set = "update");
2450
+ this.#U && this.onInsert?.(e, t, e === d ? "update" : "replace");
2934
2451
  }
2935
- if (ttl !== 0 && !this.#ttls) {
2936
- this.#initializeTTLTracking();
2937
- }
2938
- if (this.#ttls) {
2939
- if (!noUpdateTTL) {
2940
- this.#setItemTTL(index, ttl, start);
2941
- }
2942
- if (status) this.#statusTTL(status, index);
2943
- }
2944
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
2945
- const dt = this.#disposed;
2946
- let task;
2947
- while(task = dt?.shift()){
2948
- this.#disposeAfter?.(...task);
2949
- }
2452
+ if (s !== 0 && !this.#d && this.#j(), this.#d && (a || this.#N(f, s, n), r && this.#z(r, f)), !o && this.#f && this.#r) {
2453
+ let d = this.#r, g;
2454
+ for(; g = d?.shift();)this.#S?.(...g);
2950
2455
  }
2951
2456
  return this;
2952
2457
  }
2953
- /**
2954
- * Evict the least recently used item, returning its value or
2955
- * `undefined` if cache is empty.
2956
- */ pop() {
2458
+ pop() {
2957
2459
  try {
2958
- while(this.#size){
2959
- const val = this.#valList[this.#head];
2960
- this.#evict(true);
2961
- if (this.#isBackgroundFetch(val)) {
2962
- if (val.__staleWhileFetching) {
2963
- return val.__staleWhileFetching;
2964
- }
2965
- } else if (val !== undefined) {
2966
- return val;
2967
- }
2460
+ for(; this.#n;){
2461
+ let t = this.#t[this.#l];
2462
+ if (this.#x(!0), this.#e(t)) {
2463
+ if (t.__staleWhileFetching) return t.__staleWhileFetching;
2464
+ } else if (t !== void 0) return t;
2968
2465
  }
2969
2466
  } finally{
2970
- if (this.#hasDisposeAfter && this.#disposed) {
2971
- const dt = this.#disposed;
2972
- let task;
2973
- while(task = dt?.shift()){
2974
- this.#disposeAfter?.(...task);
2975
- }
2976
- }
2977
- }
2978
- }
2979
- #evict(free) {
2980
- const head = this.#head;
2981
- const k = this.#keyList[head];
2982
- const v = this.#valList[head];
2983
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
2984
- v.__abortController.abort(new Error('evicted'));
2985
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
2986
- if (this.#hasDispose) {
2987
- this.#dispose?.(v, k, 'evict');
2988
- }
2989
- if (this.#hasDisposeAfter) {
2990
- this.#disposed?.push([
2991
- v,
2992
- k,
2993
- 'evict'
2994
- ]);
2467
+ if (this.#f && this.#r) {
2468
+ let t = this.#r, e;
2469
+ for(; e = t?.shift();)this.#S?.(...e);
2995
2470
  }
2996
2471
  }
2997
- this.#removeItemSize(head);
2998
- // if we aren't about to use the index, then null these out
2999
- if (free) {
3000
- this.#keyList[head] = undefined;
3001
- this.#valList[head] = undefined;
3002
- this.#free.push(head);
3003
- }
3004
- if (this.#size === 1) {
3005
- this.#head = this.#tail = 0;
3006
- this.#free.length = 0;
3007
- } else {
3008
- this.#head = this.#next[head];
3009
- }
3010
- this.#keyMap.delete(k);
3011
- this.#size--;
3012
- return head;
3013
2472
  }
3014
- /**
3015
- * Check if a key is in the cache, without updating the recency of use.
3016
- * Will return false if the item is stale, even though it is technically
3017
- * in the cache.
3018
- *
3019
- * Check if a key is in the cache, without updating the recency of
3020
- * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
3021
- * to `true` in either the options or the constructor.
3022
- *
3023
- * Will return `false` if the item is stale, even though it is technically in
3024
- * the cache. The difference can be determined (if it matters) by using a
3025
- * `status` argument, and inspecting the `has` field.
3026
- *
3027
- * Will not update item age unless
3028
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
3029
- */ has(k, hasOptions = {}) {
3030
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
3031
- const index = this.#keyMap.get(k);
3032
- if (index !== undefined) {
3033
- const v = this.#valList[index];
3034
- if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === undefined) {
3035
- return false;
3036
- }
3037
- if (!this.#isStale(index)) {
3038
- if (updateAgeOnHas) {
3039
- this.#updateItemAge(index);
3040
- }
3041
- if (status) {
3042
- status.has = 'hit';
3043
- this.#statusTTL(status, index);
3044
- }
3045
- return true;
3046
- } else if (status) {
3047
- status.has = 'stale';
3048
- this.#statusTTL(status, index);
3049
- }
3050
- } else if (status) {
3051
- status.has = 'miss';
3052
- }
3053
- return false;
2473
+ #x(t) {
2474
+ let e = this.#l, i = this.#i[e], s = this.#t[e];
2475
+ return this.#v && this.#e(s) ? s.__abortController.abort(new Error("evicted")) : (this.#T || this.#f) && (this.#T && this.#w?.(s, i, "evict"), this.#f && this.#r?.push([
2476
+ s,
2477
+ i,
2478
+ "evict"
2479
+ ])), this.#W(e), this.#g?.[e] && (clearTimeout(this.#g[e]), this.#g[e] = void 0), t && (this.#i[e] = void 0, this.#t[e] = void 0, this.#b.push(e)), this.#n === 1 ? (this.#l = this.#h = 0, this.#b.length = 0) : this.#l = this.#a[e], this.#s.delete(i), this.#n--, e;
3054
2480
  }
3055
- /**
3056
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
3057
- * items.
3058
- *
3059
- * Returns `undefined` if the item is stale, unless
3060
- * {@link LRUCache.OptionsBase.allowStale} is set.
3061
- */ peek(k, peekOptions = {}) {
3062
- const { allowStale = this.allowStale } = peekOptions;
3063
- const index = this.#keyMap.get(k);
3064
- if (index === undefined || !allowStale && this.#isStale(index)) {
3065
- return;
3066
- }
3067
- const v = this.#valList[index];
3068
- // either stale and allowed, or forcing a refresh of non-stale value
3069
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
2481
+ has(t, e = {}) {
2482
+ let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = e, n = this.#s.get(t);
2483
+ if (n !== void 0) {
2484
+ let o = this.#t[n];
2485
+ if (this.#e(o) && o.__staleWhileFetching === void 0) return false;
2486
+ if (this.#p(n)) s && (s.has = "stale", this.#z(s, n));
2487
+ else return i && this.#R(n), s && (s.has = "hit", this.#z(s, n)), true;
2488
+ } else s && (s.has = "miss");
2489
+ return false;
3070
2490
  }
3071
- #backgroundFetch(k, index, options, context) {
3072
- const v = index === undefined ? undefined : this.#valList[index];
3073
- if (this.#isBackgroundFetch(v)) {
3074
- return v;
3075
- }
3076
- const ac = new AC();
3077
- const { signal } = options;
3078
- // when/if our AC signals, then stop listening to theirs.
3079
- signal?.addEventListener('abort', ()=>ac.abort(signal.reason), {
3080
- signal: ac.signal
2491
+ peek(t, e = {}) {
2492
+ let { allowStale: i = this.allowStale } = e, s = this.#s.get(t);
2493
+ if (s === void 0 || !i && this.#p(s)) return;
2494
+ let n = this.#t[s];
2495
+ return this.#e(n) ? n.__staleWhileFetching : n;
2496
+ }
2497
+ #G(t, e, i, s) {
2498
+ let n = e === void 0 ? void 0 : this.#t[e];
2499
+ if (this.#e(n)) return n;
2500
+ let o = new C$1, { signal: h } = i;
2501
+ h?.addEventListener("abort", ()=>o.abort(h.reason), {
2502
+ signal: o.signal
3081
2503
  });
3082
- const fetchOpts = {
3083
- signal: ac.signal,
3084
- options,
3085
- context
3086
- };
3087
- const cb = (v, updateCache = false)=>{
3088
- const { aborted } = ac.signal;
3089
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
3090
- if (options.status) {
3091
- if (aborted && !updateCache) {
3092
- options.status.fetchAborted = true;
3093
- options.status.fetchError = ac.signal.reason;
3094
- if (ignoreAbort) options.status.fetchAbortIgnored = true;
3095
- } else {
3096
- options.status.fetchResolved = true;
3097
- }
3098
- }
3099
- if (aborted && !ignoreAbort && !updateCache) {
3100
- return fetchFail(ac.signal.reason);
3101
- }
3102
- // either we didn't abort, and are still here, or we did, and ignored
3103
- const bf = p;
3104
- // if nothing else has been written there but we're set to update the
3105
- // cache and ignore the abort, or if it's still pending on this specific
3106
- // background request, then write it to the cache.
3107
- const vl = this.#valList[index];
3108
- if (vl === p || ignoreAbort && updateCache && vl === undefined) {
3109
- if (v === undefined) {
3110
- if (bf.__staleWhileFetching !== undefined) {
3111
- this.#valList[index] = bf.__staleWhileFetching;
3112
- } else {
3113
- this.#delete(k, 'fetch');
3114
- }
3115
- } else {
3116
- if (options.status) options.status.fetchUpdated = true;
3117
- this.set(k, v, fetchOpts.options);
3118
- }
3119
- }
3120
- return v;
3121
- };
3122
- const eb = (er)=>{
3123
- if (options.status) {
3124
- options.status.fetchRejected = true;
3125
- options.status.fetchError = er;
3126
- }
3127
- return fetchFail(er);
3128
- };
3129
- const fetchFail = (er)=>{
3130
- const { aborted } = ac.signal;
3131
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
3132
- const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
3133
- const noDelete = allowStale || options.noDeleteOnFetchRejection;
3134
- const bf = p;
3135
- if (this.#valList[index] === p) {
3136
- // if we allow stale on fetch rejections, then we need to ensure that
3137
- // the stale value is not removed from the cache when the fetch fails.
3138
- const del = !noDelete || bf.__staleWhileFetching === undefined;
3139
- if (del) {
3140
- this.#delete(k, 'fetch');
3141
- } else if (!allowStaleAborted) {
3142
- // still replace the *promise* with the stale value,
3143
- // since we are done with the promise at this point.
3144
- // leave it untouched if we're still waiting for an
3145
- // aborted background fetch that hasn't yet returned.
3146
- this.#valList[index] = bf.__staleWhileFetching;
3147
- }
3148
- }
3149
- if (allowStale) {
3150
- if (options.status && bf.__staleWhileFetching !== undefined) {
3151
- options.status.returnedStale = true;
3152
- }
3153
- return bf.__staleWhileFetching;
3154
- } else if (bf.__returned === bf) {
3155
- throw er;
3156
- }
3157
- };
3158
- const pcall = (res, rej)=>{
3159
- const fmp = this.#fetchMethod?.(k, v, fetchOpts);
3160
- if (fmp && fmp instanceof Promise) {
3161
- fmp.then((v)=>res(v === undefined ? undefined : v), rej);
3162
- }
3163
- // ignored, we go until we finish, regardless.
3164
- // defer check until we are actually aborting,
3165
- // so fetchMethod can override.
3166
- ac.signal.addEventListener('abort', ()=>{
3167
- if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
3168
- res(undefined);
3169
- // when it eventually resolves, update the cache.
3170
- if (options.allowStaleOnFetchAbort) {
3171
- res = (v)=>cb(v, true);
3172
- }
3173
- }
2504
+ let r = {
2505
+ signal: o.signal,
2506
+ options: i,
2507
+ context: s
2508
+ }, a = (p, _ = false)=>{
2509
+ let { aborted: l } = o.signal, S = i.ignoreFetchAbort && p !== void 0, b = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && p !== void 0);
2510
+ if (i.status && (l && !_ ? (i.status.fetchAborted = true, i.status.fetchError = o.signal.reason, S && (i.status.fetchAbortIgnored = true)) : i.status.fetchResolved = true), l && !S && !_) return f(o.signal.reason, b);
2511
+ let m = g, u = this.#t[e];
2512
+ return (u === g || S && _ && u === void 0) && (p === void 0 ? m.__staleWhileFetching !== void 0 ? this.#t[e] = m.__staleWhileFetching : this.#E(t, "fetch") : (i.status && (i.status.fetchUpdated = true), this.set(t, p, r.options))), p;
2513
+ }, w = (p)=>(i.status && (i.status.fetchRejected = true, i.status.fetchError = p), f(p, false)), f = (p, _)=>{
2514
+ let { aborted: l } = o.signal, S = l && i.allowStaleOnFetchAbort, b = S || i.allowStaleOnFetchRejection, m = b || i.noDeleteOnFetchRejection, u = g;
2515
+ if (this.#t[e] === g && (!m || !_ && u.__staleWhileFetching === void 0 ? this.#E(t, "fetch") : S || (this.#t[e] = u.__staleWhileFetching)), b) return i.status && u.__staleWhileFetching !== void 0 && (i.status.returnedStale = true), u.__staleWhileFetching;
2516
+ if (u.__returned === u) throw p;
2517
+ }, d = (p, _)=>{
2518
+ let l = this.#L?.(t, n, r);
2519
+ l && l instanceof Promise && l.then((S)=>p(S === void 0 ? void 0 : S), _), o.signal.addEventListener("abort", ()=>{
2520
+ (!i.ignoreFetchAbort || i.allowStaleOnFetchAbort) && (p(void 0), i.allowStaleOnFetchAbort && (p = (S)=>a(S, true)));
3174
2521
  });
3175
2522
  };
3176
- if (options.status) options.status.fetchDispatched = true;
3177
- const p = new Promise(pcall).then(cb, eb);
3178
- const bf = Object.assign(p, {
3179
- __abortController: ac,
3180
- __staleWhileFetching: v,
3181
- __returned: undefined
2523
+ i.status && (i.status.fetchDispatched = true);
2524
+ let g = new Promise(d).then(a, w), A = Object.assign(g, {
2525
+ __abortController: o,
2526
+ __staleWhileFetching: n,
2527
+ __returned: void 0
3182
2528
  });
3183
- if (index === undefined) {
3184
- // internal, don't expose status.
3185
- this.set(k, bf, {
3186
- ...fetchOpts.options,
3187
- status: undefined
3188
- });
3189
- index = this.#keyMap.get(k);
2529
+ return e === void 0 ? (this.set(t, A, {
2530
+ ...r.options,
2531
+ status: void 0
2532
+ }), e = this.#s.get(t)) : this.#t[e] = A, A;
2533
+ }
2534
+ #e(t) {
2535
+ if (!this.#v) return false;
2536
+ let e = t;
2537
+ return !!e && e instanceof Promise && e.hasOwnProperty("__staleWhileFetching") && e.__abortController instanceof C$1;
2538
+ }
2539
+ async fetch(t, e = {}) {
2540
+ let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: r = 0, sizeCalculation: a = this.sizeCalculation, noUpdateTTL: w = this.noUpdateTTL, noDeleteOnFetchRejection: f = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: g = this.ignoreFetchAbort, allowStaleOnFetchAbort: A = this.allowStaleOnFetchAbort, context: p, forceRefresh: _ = false, status: l, signal: S } = e;
2541
+ if (!this.#v) return l && (l.fetch = "get"), this.get(t, {
2542
+ allowStale: i,
2543
+ updateAgeOnGet: s,
2544
+ noDeleteOnStaleGet: n,
2545
+ status: l
2546
+ });
2547
+ let b = {
2548
+ allowStale: i,
2549
+ updateAgeOnGet: s,
2550
+ noDeleteOnStaleGet: n,
2551
+ ttl: o,
2552
+ noDisposeOnSet: h,
2553
+ size: r,
2554
+ sizeCalculation: a,
2555
+ noUpdateTTL: w,
2556
+ noDeleteOnFetchRejection: f,
2557
+ allowStaleOnFetchRejection: d,
2558
+ allowStaleOnFetchAbort: A,
2559
+ ignoreFetchAbort: g,
2560
+ status: l,
2561
+ signal: S
2562
+ }, m = this.#s.get(t);
2563
+ if (m === void 0) {
2564
+ l && (l.fetch = "miss");
2565
+ let u = this.#G(t, m, b, p);
2566
+ return u.__returned = u;
3190
2567
  } else {
3191
- this.#valList[index] = bf;
3192
- }
3193
- return bf;
3194
- }
3195
- #isBackgroundFetch(p) {
3196
- if (!this.#hasFetchMethod) return false;
3197
- const b = p;
3198
- return !!b && b instanceof Promise && b.hasOwnProperty('__staleWhileFetching') && b.__abortController instanceof AC;
3199
- }
3200
- async fetch(k, fetchOptions = {}) {
3201
- const { // get options
3202
- allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, // set options
3203
- ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, // fetch exclusive options
3204
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal } = fetchOptions;
3205
- if (!this.#hasFetchMethod) {
3206
- if (status) status.fetch = 'get';
3207
- return this.get(k, {
3208
- allowStale,
3209
- updateAgeOnGet,
3210
- noDeleteOnStaleGet,
3211
- status
3212
- });
2568
+ let u = this.#t[m];
2569
+ if (this.#e(u)) {
2570
+ let E = i && u.__staleWhileFetching !== void 0;
2571
+ return l && (l.fetch = "inflight", E && (l.returnedStale = true)), E ? u.__staleWhileFetching : u.__returned = u;
2572
+ }
2573
+ let T = this.#p(m);
2574
+ if (!_ && !T) return l && (l.fetch = "hit"), this.#D(m), s && this.#R(m), l && this.#z(l, m), u;
2575
+ let F = this.#G(t, m, b, p), O = F.__staleWhileFetching !== void 0 && i;
2576
+ return l && (l.fetch = T ? "stale" : "refresh", O && T && (l.returnedStale = true)), O ? F.__staleWhileFetching : F.__returned = F;
3213
2577
  }
3214
- const options = {
3215
- allowStale,
3216
- updateAgeOnGet,
3217
- noDeleteOnStaleGet,
3218
- ttl,
3219
- noDisposeOnSet,
3220
- size,
3221
- sizeCalculation,
3222
- noUpdateTTL,
3223
- noDeleteOnFetchRejection,
3224
- allowStaleOnFetchRejection,
3225
- allowStaleOnFetchAbort,
3226
- ignoreFetchAbort,
3227
- status,
3228
- signal
3229
- };
3230
- let index = this.#keyMap.get(k);
3231
- if (index === undefined) {
3232
- if (status) status.fetch = 'miss';
3233
- const p = this.#backgroundFetch(k, index, options, context);
3234
- return p.__returned = p;
3235
- } else {
3236
- // in cache, maybe already fetching
3237
- const v = this.#valList[index];
3238
- if (this.#isBackgroundFetch(v)) {
3239
- const stale = allowStale && v.__staleWhileFetching !== undefined;
3240
- if (status) {
3241
- status.fetch = 'inflight';
3242
- if (stale) status.returnedStale = true;
3243
- }
3244
- return stale ? v.__staleWhileFetching : v.__returned = v;
3245
- }
3246
- // if we force a refresh, that means do NOT serve the cached value,
3247
- // unless we are already in the process of refreshing the cache.
3248
- const isStale = this.#isStale(index);
3249
- if (!forceRefresh && !isStale) {
3250
- if (status) status.fetch = 'hit';
3251
- this.#moveToTail(index);
3252
- if (updateAgeOnGet) {
3253
- this.#updateItemAge(index);
3254
- }
3255
- if (status) this.#statusTTL(status, index);
3256
- return v;
3257
- }
3258
- // ok, it is stale or a forced refresh, and not already fetching.
3259
- // refresh the cache.
3260
- const p = this.#backgroundFetch(k, index, options, context);
3261
- const hasStale = p.__staleWhileFetching !== undefined;
3262
- const staleVal = hasStale && allowStale;
3263
- if (status) {
3264
- status.fetch = isStale ? 'stale' : 'refresh';
3265
- if (staleVal && isStale) status.returnedStale = true;
3266
- }
3267
- return staleVal ? p.__staleWhileFetching : p.__returned = p;
3268
- }
3269
- }
3270
- async forceFetch(k, fetchOptions = {}) {
3271
- const v = await this.fetch(k, fetchOptions);
3272
- if (v === undefined) throw new Error('fetch() returned undefined');
3273
- return v;
3274
- }
3275
- memo(k, memoOptions = {}) {
3276
- const memoMethod = this.#memoMethod;
3277
- if (!memoMethod) {
3278
- throw new Error('no memoMethod provided to constructor');
3279
- }
3280
- const { context, forceRefresh, ...options } = memoOptions;
3281
- const v = this.get(k, options);
3282
- if (!forceRefresh && v !== undefined) return v;
3283
- const vv = memoMethod(k, v, {
3284
- options,
3285
- context
2578
+ }
2579
+ async forceFetch(t, e = {}) {
2580
+ let i = await this.fetch(t, e);
2581
+ if (i === void 0) throw new Error("fetch() returned undefined");
2582
+ return i;
2583
+ }
2584
+ memo(t, e = {}) {
2585
+ let i = this.#I;
2586
+ if (!i) throw new Error("no memoMethod provided to constructor");
2587
+ let { context: s, forceRefresh: n, ...o } = e, h = this.get(t, o);
2588
+ if (!n && h !== void 0) return h;
2589
+ let r = i(t, h, {
2590
+ options: o,
2591
+ context: s
3286
2592
  });
3287
- this.set(k, vv, options);
3288
- return vv;
2593
+ return this.set(t, r, o), r;
3289
2594
  }
3290
- /**
3291
- * Return a value from the cache. Will update the recency of the cache
3292
- * entry found.
3293
- *
3294
- * If the key is not found, get() will return `undefined`.
3295
- */ get(k, getOptions = {}) {
3296
- const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
3297
- const index = this.#keyMap.get(k);
3298
- if (index !== undefined) {
3299
- const value = this.#valList[index];
3300
- const fetching = this.#isBackgroundFetch(value);
3301
- if (status) this.#statusTTL(status, index);
3302
- if (this.#isStale(index)) {
3303
- if (status) status.get = 'stale';
3304
- // delete only if not an in-flight background fetch
3305
- if (!fetching) {
3306
- if (!noDeleteOnStaleGet) {
3307
- this.#delete(k, 'expire');
3308
- }
3309
- if (status && allowStale) status.returnedStale = true;
3310
- return allowStale ? value : undefined;
3311
- } else {
3312
- if (status && allowStale && value.__staleWhileFetching !== undefined) {
3313
- status.returnedStale = true;
3314
- }
3315
- return allowStale ? value.__staleWhileFetching : undefined;
3316
- }
3317
- } else {
3318
- if (status) status.get = 'hit';
3319
- // if we're currently fetching it, we don't actually have it yet
3320
- // it's not stale, which means this isn't a staleWhileRefetching.
3321
- // If it's not stale, and fetching, AND has a __staleWhileFetching
3322
- // value, then that means the user fetched with {forceRefresh:true},
3323
- // so it's safe to return that value.
3324
- if (fetching) {
3325
- return value.__staleWhileFetching;
3326
- }
3327
- this.#moveToTail(index);
3328
- if (updateAgeOnGet) {
3329
- this.#updateItemAge(index);
3330
- }
3331
- return value;
3332
- }
3333
- } else if (status) {
3334
- status.get = 'miss';
3335
- }
3336
- }
3337
- #connect(p, n) {
3338
- this.#prev[n] = p;
3339
- this.#next[p] = n;
3340
- }
3341
- #moveToTail(index) {
3342
- // if tail already, nothing to do
3343
- // if head, move head to next[index]
3344
- // else
3345
- // move next[prev[index]] to next[index] (head has no prev)
3346
- // move prev[next[index]] to prev[index]
3347
- // prev[index] = tail
3348
- // next[tail] = index
3349
- // tail = index
3350
- if (index !== this.#tail) {
3351
- if (index === this.#head) {
3352
- this.#head = this.#next[index];
3353
- } else {
3354
- this.#connect(this.#prev[index], this.#next[index]);
3355
- }
3356
- this.#connect(this.#tail, index);
3357
- this.#tail = index;
3358
- }
2595
+ get(t, e = {}) {
2596
+ let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = e, h = this.#s.get(t);
2597
+ if (h !== void 0) {
2598
+ let r = this.#t[h], a = this.#e(r);
2599
+ return o && this.#z(o, h), this.#p(h) ? (o && (o.get = "stale"), a ? (o && i && r.__staleWhileFetching !== void 0 && (o.returnedStale = true), i ? r.__staleWhileFetching : void 0) : (n || this.#E(t, "expire"), o && i && (o.returnedStale = true), i ? r : void 0)) : (o && (o.get = "hit"), a ? r.__staleWhileFetching : (this.#D(h), s && this.#R(h), r));
2600
+ } else o && (o.get = "miss");
3359
2601
  }
3360
- /**
3361
- * Deletes a key out of the cache.
3362
- *
3363
- * Returns true if the key was deleted, false otherwise.
3364
- */ delete(k) {
3365
- return this.#delete(k, 'delete');
3366
- }
3367
- #delete(k, reason) {
3368
- let deleted = false;
3369
- if (this.#size !== 0) {
3370
- const index = this.#keyMap.get(k);
3371
- if (index !== undefined) {
3372
- deleted = true;
3373
- if (this.#size === 1) {
3374
- this.#clear(reason);
3375
- } else {
3376
- this.#removeItemSize(index);
3377
- const v = this.#valList[index];
3378
- if (this.#isBackgroundFetch(v)) {
3379
- v.__abortController.abort(new Error('deleted'));
3380
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
3381
- if (this.#hasDispose) {
3382
- this.#dispose?.(v, k, reason);
3383
- }
3384
- if (this.#hasDisposeAfter) {
3385
- this.#disposed?.push([
3386
- v,
3387
- k,
3388
- reason
3389
- ]);
3390
- }
3391
- }
3392
- this.#keyMap.delete(k);
3393
- this.#keyList[index] = undefined;
3394
- this.#valList[index] = undefined;
3395
- if (index === this.#tail) {
3396
- this.#tail = this.#prev[index];
3397
- } else if (index === this.#head) {
3398
- this.#head = this.#next[index];
3399
- } else {
3400
- const pi = this.#prev[index];
3401
- this.#next[pi] = this.#next[index];
3402
- const ni = this.#next[index];
3403
- this.#prev[ni] = this.#prev[index];
3404
- }
3405
- this.#size--;
3406
- this.#free.push(index);
2602
+ #k(t, e) {
2603
+ this.#u[e] = t, this.#a[t] = e;
2604
+ }
2605
+ #D(t) {
2606
+ t !== this.#h && (t === this.#l ? this.#l = this.#a[t] : this.#k(this.#u[t], this.#a[t]), this.#k(this.#h, t), this.#h = t);
2607
+ }
2608
+ delete(t) {
2609
+ return this.#E(t, "delete");
2610
+ }
2611
+ #E(t, e) {
2612
+ let i = false;
2613
+ if (this.#n !== 0) {
2614
+ let s = this.#s.get(t);
2615
+ if (s !== void 0) if (this.#g?.[s] && (clearTimeout(this.#g?.[s]), this.#g[s] = void 0), i = true, this.#n === 1) this.#V(e);
2616
+ else {
2617
+ this.#W(s);
2618
+ let n = this.#t[s];
2619
+ if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, t, e), this.#f && this.#r?.push([
2620
+ n,
2621
+ t,
2622
+ e
2623
+ ])), this.#s.delete(t), this.#i[s] = void 0, this.#t[s] = void 0, s === this.#h) this.#h = this.#u[s];
2624
+ else if (s === this.#l) this.#l = this.#a[s];
2625
+ else {
2626
+ let o = this.#u[s];
2627
+ this.#a[o] = this.#a[s];
2628
+ let h = this.#a[s];
2629
+ this.#u[h] = this.#u[s];
3407
2630
  }
2631
+ this.#n--, this.#b.push(s);
3408
2632
  }
3409
2633
  }
3410
- if (this.#hasDisposeAfter && this.#disposed?.length) {
3411
- const dt = this.#disposed;
3412
- let task;
3413
- while(task = dt?.shift()){
3414
- this.#disposeAfter?.(...task);
3415
- }
2634
+ if (this.#f && this.#r?.length) {
2635
+ let s = this.#r, n;
2636
+ for(; n = s?.shift();)this.#S?.(...n);
3416
2637
  }
3417
- return deleted;
2638
+ return i;
3418
2639
  }
3419
- /**
3420
- * Clear the cache entirely, throwing away all values.
3421
- */ clear() {
3422
- return this.#clear('delete');
2640
+ clear() {
2641
+ return this.#V("delete");
3423
2642
  }
3424
- #clear(reason) {
3425
- for (const index of this.#rindexes({
2643
+ #V(t) {
2644
+ for (let e of this.#O({
3426
2645
  allowStale: true
3427
2646
  })){
3428
- const v = this.#valList[index];
3429
- if (this.#isBackgroundFetch(v)) {
3430
- v.__abortController.abort(new Error('deleted'));
3431
- } else {
3432
- const k = this.#keyList[index];
3433
- if (this.#hasDispose) {
3434
- this.#dispose?.(v, k, reason);
3435
- }
3436
- if (this.#hasDisposeAfter) {
3437
- this.#disposed?.push([
3438
- v,
3439
- k,
3440
- reason
3441
- ]);
3442
- }
2647
+ let i = this.#t[e];
2648
+ if (this.#e(i)) i.__abortController.abort(new Error("deleted"));
2649
+ else {
2650
+ let s = this.#i[e];
2651
+ this.#T && this.#w?.(i, s, t), this.#f && this.#r?.push([
2652
+ i,
2653
+ s,
2654
+ t
2655
+ ]);
3443
2656
  }
3444
2657
  }
3445
- this.#keyMap.clear();
3446
- this.#valList.fill(undefined);
3447
- this.#keyList.fill(undefined);
3448
- if (this.#ttls && this.#starts) {
3449
- this.#ttls.fill(0);
3450
- this.#starts.fill(0);
2658
+ if (this.#s.clear(), this.#t.fill(void 0), this.#i.fill(void 0), this.#d && this.#A) {
2659
+ this.#d.fill(0), this.#A.fill(0);
2660
+ for (let e of this.#g ?? [])e !== void 0 && clearTimeout(e);
2661
+ this.#g?.fill(void 0);
3451
2662
  }
3452
- if (this.#sizes) {
3453
- this.#sizes.fill(0);
3454
- }
3455
- this.#head = 0;
3456
- this.#tail = 0;
3457
- this.#free.length = 0;
3458
- this.#calculatedSize = 0;
3459
- this.#size = 0;
3460
- if (this.#hasDisposeAfter && this.#disposed) {
3461
- const dt = this.#disposed;
3462
- let task;
3463
- while(task = dt?.shift()){
3464
- this.#disposeAfter?.(...task);
3465
- }
2663
+ if (this.#y && this.#y.fill(0), this.#l = 0, this.#h = 0, this.#b.length = 0, this.#_ = 0, this.#n = 0, this.#f && this.#r) {
2664
+ let e = this.#r, i;
2665
+ for(; i = e?.shift();)this.#S?.(...i);
3466
2666
  }
3467
2667
  }
3468
- }
2668
+ };
3469
2669
 
3470
2670
  var _computedKey$2, _computedKey1$2, _computedKey2$1, _computedKey3$1;
3471
2671
  const proc = typeof process === 'object' && process ? process : {
@@ -4397,7 +3597,7 @@ const ENOCHILD = ENOTDIR | ENOENT | ENOREALPATH;
4397
3597
  const TYPEMASK = 1023;
4398
3598
  const entToType = (s)=>s.isFile() ? IFREG : s.isDirectory() ? IFDIR : s.isSymbolicLink() ? IFLNK : s.isCharacterDevice() ? IFCHR : s.isBlockDevice() ? IFBLK : s.isSocket() ? IFSOCK : s.isFIFO() ? IFIFO : UNKNOWN;
4399
3599
  // normalize unicode path names
4400
- const normalizeCache = new LRUCache({
3600
+ const normalizeCache = new L$1({
4401
3601
  max: 2 ** 12
4402
3602
  });
4403
3603
  const normalize$1 = (s)=>{
@@ -4407,7 +3607,7 @@ const normalize$1 = (s)=>{
4407
3607
  normalizeCache.set(s, n);
4408
3608
  return n;
4409
3609
  };
4410
- const normalizeNocaseCache = new LRUCache({
3610
+ const normalizeNocaseCache = new L$1({
4411
3611
  max: 2 ** 12
4412
3612
  });
4413
3613
  const normalizeNocase = (s)=>{
@@ -4420,7 +3620,7 @@ const normalizeNocase = (s)=>{
4420
3620
  /**
4421
3621
  * An LRUCache for storing resolved path strings or Path objects.
4422
3622
  * @internal
4423
- */ class ResolveCache extends LRUCache {
3623
+ */ class ResolveCache extends L$1 {
4424
3624
  constructor(){
4425
3625
  super({
4426
3626
  max: 256
@@ -4441,7 +3641,7 @@ const normalizeNocase = (s)=>{
4441
3641
  /**
4442
3642
  * an LRUCache for storing child entries.
4443
3643
  * @internal
4444
- */ class ChildrenCache extends LRUCache {
3644
+ */ class ChildrenCache extends L$1 {
4445
3645
  constructor(maxSize = 16 * 1024){
4446
3646
  super({
4447
3647
  maxSize,
@@ -10212,6 +9412,7 @@ var require$$1$2 = [
10212
9412
  "AGPL-1.0-or-later",
10213
9413
  "AGPL-3.0-only",
10214
9414
  "AGPL-3.0-or-later",
9415
+ "ALGLIB-Documentation",
10215
9416
  "AMD-newlib",
10216
9417
  "AMDPLPA",
10217
9418
  "AML",
@@ -10233,6 +9434,7 @@ var require$$1$2 = [
10233
9434
  "Adobe-Display-PostScript",
10234
9435
  "Adobe-Glyph",
10235
9436
  "Adobe-Utopia",
9437
+ "Advanced-Cryptics-Dictionary",
10236
9438
  "Afmparse",
10237
9439
  "Aladdin",
10238
9440
  "Apache-1.0",
@@ -10246,6 +9448,7 @@ var require$$1$2 = [
10246
9448
  "Artistic-2.0",
10247
9449
  "Artistic-dist",
10248
9450
  "Aspell-RU",
9451
+ "BOLA-1.1",
10249
9452
  "BSD-1-Clause",
10250
9453
  "BSD-2-Clause",
10251
9454
  "BSD-2-Clause-Darwin",
@@ -10265,6 +9468,7 @@ var require$$1$2 = [
10265
9468
  "BSD-3-Clause-No-Nuclear-Warranty",
10266
9469
  "BSD-3-Clause-Open-MPI",
10267
9470
  "BSD-3-Clause-Sun",
9471
+ "BSD-3-Clause-Tso",
10268
9472
  "BSD-3-Clause-acpica",
10269
9473
  "BSD-3-Clause-flex",
10270
9474
  "BSD-4-Clause",
@@ -10275,6 +9479,7 @@ var require$$1$2 = [
10275
9479
  "BSD-Advertising-Acknowledgement",
10276
9480
  "BSD-Attribution-HPND-disclaimer",
10277
9481
  "BSD-Inferno-Nettverk",
9482
+ "BSD-Mark-Modifications",
10278
9483
  "BSD-Protection",
10279
9484
  "BSD-Source-Code",
10280
9485
  "BSD-Source-beginning-file",
@@ -10296,9 +9501,11 @@ var require$$1$2 = [
10296
9501
  "Borceux",
10297
9502
  "Brian-Gladman-2-Clause",
10298
9503
  "Brian-Gladman-3-Clause",
9504
+ "Buddy",
10299
9505
  "C-UDA-1.0",
10300
9506
  "CAL-1.0",
10301
9507
  "CAL-1.0-Combined-Work-Exception",
9508
+ "CAPEC-tou",
10302
9509
  "CATOSL-1.1",
10303
9510
  "CC-BY-1.0",
10304
9511
  "CC-BY-2.0",
@@ -10416,6 +9623,9 @@ var require$$1$2 = [
10416
9623
  "EPICS",
10417
9624
  "EPL-1.0",
10418
9625
  "EPL-2.0",
9626
+ "ESA-PL-permissive-2.4",
9627
+ "ESA-PL-strong-copyleft-2.4",
9628
+ "ESA-PL-weak-copyleft-2.4",
10419
9629
  "EUDatagrid",
10420
9630
  "EUPL-1.0",
10421
9631
  "EUPL-1.1",
@@ -10489,6 +9699,7 @@ var require$$1$2 = [
10489
9699
  "HPND-Markus-Kuhn",
10490
9700
  "HPND-Netrek",
10491
9701
  "HPND-Pbmplus",
9702
+ "HPND-SMC",
10492
9703
  "HPND-UC",
10493
9704
  "HPND-UC-export-US",
10494
9705
  "HPND-doc",
@@ -10503,6 +9714,7 @@ var require$$1$2 = [
10503
9714
  "HPND-sell-variant",
10504
9715
  "HPND-sell-variant-MIT-disclaimer",
10505
9716
  "HPND-sell-variant-MIT-disclaimer-rev",
9717
+ "HPND-sell-variant-critical-systems",
10506
9718
  "HTMLTIDY",
10507
9719
  "HaskellReport",
10508
9720
  "Hippocratic-2.1",
@@ -10515,6 +9727,7 @@ var require$$1$2 = [
10515
9727
  "IPL-1.0",
10516
9728
  "ISC",
10517
9729
  "ISC-Veillard",
9730
+ "ISO-permission",
10518
9731
  "ImageMagick",
10519
9732
  "Imlib2",
10520
9733
  "Info-ZIP",
@@ -10572,6 +9785,7 @@ var require$$1$2 = [
10572
9785
  "MIT-Festival",
10573
9786
  "MIT-Khronos-old",
10574
9787
  "MIT-Modern-Variant",
9788
+ "MIT-STK",
10575
9789
  "MIT-Wu",
10576
9790
  "MIT-advertising",
10577
9791
  "MIT-enna",
@@ -10580,6 +9794,7 @@ var require$$1$2 = [
10580
9794
  "MIT-testregex",
10581
9795
  "MITNFA",
10582
9796
  "MMIXware",
9797
+ "MMPL-1.0.1",
10583
9798
  "MPEG-SSG",
10584
9799
  "MPL-1.0",
10585
9800
  "MPL-1.1",
@@ -10611,6 +9826,7 @@ var require$$1$2 = [
10611
9826
  "NGPL",
10612
9827
  "NICTA-1.0",
10613
9828
  "NIST-PD",
9829
+ "NIST-PD-TNT",
10614
9830
  "NIST-PD-fallback",
10615
9831
  "NIST-Software",
10616
9832
  "NLOD-1.0",
@@ -10670,12 +9886,15 @@ var require$$1$2 = [
10670
9886
  "OPL-1.0",
10671
9887
  "OPL-UK-3.0",
10672
9888
  "OPUBL-1.0",
9889
+ "OSC-1.0",
10673
9890
  "OSET-PL-2.1",
10674
9891
  "OSL-1.0",
10675
9892
  "OSL-1.1",
10676
9893
  "OSL-2.0",
10677
9894
  "OSL-2.1",
10678
9895
  "OSL-3.0",
9896
+ "OSSP",
9897
+ "OpenMDW-1.0",
10679
9898
  "OpenPBS-2.3",
10680
9899
  "OpenSSL",
10681
9900
  "OpenSSL-standalone",
@@ -10686,6 +9905,7 @@ var require$$1$2 = [
10686
9905
  "PHP-3.01",
10687
9906
  "PPL",
10688
9907
  "PSF-2.0",
9908
+ "ParaType-Free-Font-1.3",
10689
9909
  "Parity-6.0.0",
10690
9910
  "Parity-7.0.0",
10691
9911
  "Pixar",
@@ -10714,6 +9934,7 @@ var require$$1$2 = [
10714
9934
  "SGI-B-1.1",
10715
9935
  "SGI-B-2.0",
10716
9936
  "SGI-OpenGL",
9937
+ "SGMLUG-PM",
10717
9938
  "SGP4",
10718
9939
  "SHL-0.5",
10719
9940
  "SHL-0.51",
@@ -10761,6 +9982,7 @@ var require$$1$2 = [
10761
9982
  "TTYP0",
10762
9983
  "TU-Berlin-1.0",
10763
9984
  "TU-Berlin-2.0",
9985
+ "TekHVC",
10764
9986
  "TermReadKey",
10765
9987
  "ThirdEye",
10766
9988
  "TrustedQSL",
@@ -10770,6 +9992,7 @@ var require$$1$2 = [
10770
9992
  "UPL-1.0",
10771
9993
  "URT-RLE",
10772
9994
  "Ubuntu-font-1.0",
9995
+ "UnRAR",
10773
9996
  "Unicode-3.0",
10774
9997
  "Unicode-DFS-2015",
10775
9998
  "Unicode-DFS-2016",
@@ -10781,15 +10004,19 @@ var require$$1$2 = [
10781
10004
  "VOSTROM",
10782
10005
  "VSL-1.0",
10783
10006
  "Vim",
10007
+ "Vixie-Cron",
10784
10008
  "W3C",
10785
10009
  "W3C-19980720",
10786
10010
  "W3C-20150513",
10011
+ "WTFNMFPL",
10787
10012
  "WTFPL",
10788
10013
  "Watcom-1.0",
10789
10014
  "Widget-Workshop",
10015
+ "WordNet",
10790
10016
  "Wsuipa",
10791
10017
  "X11",
10792
10018
  "X11-distribute-modifications-variant",
10019
+ "X11-no-permit-persons",
10793
10020
  "X11-swapped",
10794
10021
  "XFree86-1.1",
10795
10022
  "XSkat",
@@ -10830,6 +10057,7 @@ var require$$1$2 = [
10830
10057
  "gnuplot",
10831
10058
  "gtkbook",
10832
10059
  "hdparm",
10060
+ "hyphen-bulgarian",
10833
10061
  "iMatix",
10834
10062
  "jove",
10835
10063
  "libpng-1.6.35",
@@ -11853,1449 +11081,645 @@ function requireValidateNpmPackageLicense() {
11853
11081
  return validateNpmPackageLicense;
11854
11082
  }
11855
11083
 
11856
- var commonjs = {};
11084
+ var index_min = {};
11857
11085
 
11858
- var hasRequiredCommonjs;
11859
- function requireCommonjs() {
11086
+ var hasRequiredIndex_min;
11087
+ function requireIndex_min() {
11860
11088
  var _computedKey, _computedKey1;
11861
- if (hasRequiredCommonjs) return commonjs;
11862
- hasRequiredCommonjs = 1;
11863
- /**
11864
- * @module LRUCache
11865
- */ Object.defineProperty(commonjs, "__esModule", {
11089
+ if (hasRequiredIndex_min) return index_min;
11090
+ hasRequiredIndex_min = 1;
11091
+ Object.defineProperty(index_min, "__esModule", {
11866
11092
  value: true
11867
11093
  });
11868
- commonjs.LRUCache = void 0;
11869
- const defaultPerf = typeof performance === 'object' && performance && typeof performance.now === 'function' ? performance : Date;
11870
- const warned = new Set();
11871
- /* c8 ignore start */ const PROCESS = typeof process === 'object' && !!process ? process : {};
11872
- /* c8 ignore start */ const emitWarning = (msg, type, code, fn)=>{
11873
- typeof PROCESS.emitWarning === 'function' ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
11874
- };
11875
- let AC = globalThis.AbortController;
11876
- let AS = globalThis.AbortSignal;
11877
- /* c8 ignore start */ if (typeof AC === 'undefined') {
11878
- //@ts-ignore
11879
- AS = class AbortSignal {
11094
+ index_min.LRUCache = void 0;
11095
+ var G = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, U = new Set, R = typeof process == "object" && process ? process : {}, I = (c, t, e, i)=>{
11096
+ typeof R.emitWarning == "function" ? R.emitWarning(c, t, e, i) : console.error(`[${e}] ${t}: ${c}`);
11097
+ }, C = globalThis.AbortController, L = globalThis.AbortSignal;
11098
+ if (typeof C > "u") {
11099
+ L = class {
11880
11100
  onabort;
11881
11101
  _onabort = [];
11882
11102
  reason;
11883
11103
  aborted = false;
11884
- addEventListener(_, fn) {
11885
- this._onabort.push(fn);
11104
+ addEventListener(i, s) {
11105
+ this._onabort.push(s);
11886
11106
  }
11887
- };
11888
- //@ts-ignore
11889
- AC = class AbortController {
11107
+ }, C = class {
11890
11108
  constructor(){
11891
- warnACPolyfill();
11109
+ t();
11892
11110
  }
11893
- signal = new AS();
11894
- abort(reason) {
11895
- if (this.signal.aborted) return;
11896
- //@ts-ignore
11897
- this.signal.reason = reason;
11898
- //@ts-ignore
11899
- this.signal.aborted = true;
11900
- //@ts-ignore
11901
- for (const fn of this.signal._onabort){
11902
- fn(reason);
11111
+ signal = new L;
11112
+ abort(i) {
11113
+ if (!this.signal.aborted) {
11114
+ this.signal.reason = i, this.signal.aborted = true;
11115
+ for (let s of this.signal._onabort)s(i);
11116
+ this.signal.onabort?.(i);
11903
11117
  }
11904
- this.signal.onabort?.(reason);
11905
11118
  }
11906
11119
  };
11907
- let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
11908
- const warnACPolyfill = ()=>{
11909
- if (!printACPolyfillWarning) return;
11910
- printACPolyfillWarning = false;
11911
- emitWarning('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', warnACPolyfill);
11120
+ let c = R.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1", t = ()=>{
11121
+ c && (c = false, I("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));
11912
11122
  };
11913
11123
  }
11914
- /* c8 ignore stop */ const shouldWarn = (code)=>!warned.has(code);
11915
- const isPosInt = (n)=>n && n === Math.floor(n) && n > 0 && isFinite(n);
11916
- /* c8 ignore start */ // This is a little bit ridiculous, tbh.
11917
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
11918
- // And well before that point, you're caching the entire world, I mean,
11919
- // that's ~32GB of just integers for the next/prev links, plus whatever
11920
- // else to hold that many keys and values. Just filling the memory with
11921
- // zeroes at init time is brutal when you get that big.
11922
- // But why not be complete?
11923
- // Maybe in the future, these limits will have expanded.
11924
- const getUintArray = (max)=>!isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
11925
- /* c8 ignore stop */ class ZeroArray extends Array {
11926
- constructor(size){
11927
- super(size);
11928
- this.fill(0);
11929
- }
11930
- }
11931
- class Stack {
11124
+ _computedKey = Symbol.iterator, _computedKey1 = Symbol.toStringTag;
11125
+ var x = (c)=>!U.has(c), y = (c)=>c && c === Math.floor(c) && c > 0 && isFinite(c), M = (c)=>y(c) ? c <= Math.pow(2, 8) ? Uint8Array : c <= Math.pow(2, 16) ? Uint16Array : c <= Math.pow(2, 32) ? Uint32Array : c <= Number.MAX_SAFE_INTEGER ? z : null : null, z = class extends Array {
11126
+ constructor(t){
11127
+ super(t), this.fill(0);
11128
+ }
11129
+ }, W = class c {
11932
11130
  heap;
11933
11131
  length;
11934
- // private constructor
11935
- static #constructing = false;
11936
- static create(max) {
11937
- const HeapCls = getUintArray(max);
11938
- if (!HeapCls) return [];
11939
- Stack.#constructing = true;
11940
- const s = new Stack(max, HeapCls);
11941
- Stack.#constructing = false;
11942
- return s;
11943
- }
11944
- constructor(max, HeapCls){
11945
- /* c8 ignore start */ if (!Stack.#constructing) {
11946
- throw new TypeError('instantiate Stack using Stack.create(n)');
11947
- }
11948
- /* c8 ignore stop */ this.heap = new HeapCls(max);
11949
- this.length = 0;
11950
- }
11951
- push(n) {
11952
- this.heap[this.length++] = n;
11132
+ static #o = false;
11133
+ static create(t) {
11134
+ let e = M(t);
11135
+ if (!e) return [];
11136
+ c.#o = true;
11137
+ let i = new c(t, e);
11138
+ return c.#o = false, i;
11953
11139
  }
11954
- pop() {
11955
- return this.heap[--this.length];
11956
- }
11957
- }
11958
- _computedKey = Symbol.iterator, _computedKey1 = Symbol.toStringTag;
11959
- /**
11960
- * Default export, the thing you're using this module to get.
11961
- *
11962
- * The `K` and `V` types define the key and value types, respectively. The
11963
- * optional `FC` type defines the type of the `context` object passed to
11964
- * `cache.fetch()` and `cache.memo()`.
11965
- *
11966
- * Keys and values **must not** be `null` or `undefined`.
11967
- *
11968
- * All properties from the options object (with the exception of `max`,
11969
- * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
11970
- * added as normal public members. (The listed options are read-only getters.)
11971
- *
11972
- * Changing any of these will alter the defaults for subsequent method calls.
11973
- */ class LRUCache {
11974
- // options that cannot be changed without disaster
11975
- #max;
11976
- #maxSize;
11977
- #dispose;
11978
- #onInsert;
11979
- #disposeAfter;
11980
- #fetchMethod;
11981
- #memoMethod;
11982
- #perf;
11983
- /**
11984
- * {@link LRUCache.OptionsBase.perf}
11985
- */ get perf() {
11986
- return this.#perf;
11140
+ constructor(t, e){
11141
+ if (!c.#o) throw new TypeError("instantiate Stack using Stack.create(n)");
11142
+ this.heap = new e(t), this.length = 0;
11987
11143
  }
11988
- /**
11989
- * {@link LRUCache.OptionsBase.ttl}
11990
- */ ttl;
11991
- /**
11992
- * {@link LRUCache.OptionsBase.ttlResolution}
11993
- */ ttlResolution;
11994
- /**
11995
- * {@link LRUCache.OptionsBase.ttlAutopurge}
11996
- */ ttlAutopurge;
11997
- /**
11998
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
11999
- */ updateAgeOnGet;
12000
- /**
12001
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
12002
- */ updateAgeOnHas;
12003
- /**
12004
- * {@link LRUCache.OptionsBase.allowStale}
12005
- */ allowStale;
12006
- /**
12007
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
12008
- */ noDisposeOnSet;
12009
- /**
12010
- * {@link LRUCache.OptionsBase.noUpdateTTL}
12011
- */ noUpdateTTL;
12012
- /**
12013
- * {@link LRUCache.OptionsBase.maxEntrySize}
12014
- */ maxEntrySize;
12015
- /**
12016
- * {@link LRUCache.OptionsBase.sizeCalculation}
12017
- */ sizeCalculation;
12018
- /**
12019
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
12020
- */ noDeleteOnFetchRejection;
12021
- /**
12022
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
12023
- */ noDeleteOnStaleGet;
12024
- /**
12025
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
12026
- */ allowStaleOnFetchAbort;
12027
- /**
12028
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
12029
- */ allowStaleOnFetchRejection;
12030
- /**
12031
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
12032
- */ ignoreFetchAbort;
12033
- // computed properties
12034
- #size;
12035
- #calculatedSize;
12036
- #keyMap;
12037
- #keyList;
12038
- #valList;
12039
- #next;
12040
- #prev;
12041
- #head;
12042
- #tail;
12043
- #free;
12044
- #disposed;
12045
- #sizes;
12046
- #starts;
12047
- #ttls;
12048
- #hasDispose;
12049
- #hasFetchMethod;
12050
- #hasDisposeAfter;
12051
- #hasOnInsert;
12052
- /**
12053
- * Do not call this method unless you need to inspect the
12054
- * inner workings of the cache. If anything returned by this
12055
- * object is modified in any way, strange breakage may occur.
12056
- *
12057
- * These fields are private for a reason!
12058
- *
12059
- * @internal
12060
- */ static unsafeExposeInternals(c) {
11144
+ push(t) {
11145
+ this.heap[this.length++] = t;
11146
+ }
11147
+ pop() {
11148
+ return this.heap[--this.length];
11149
+ }
11150
+ }, D = class c {
11151
+ #o;
11152
+ #c;
11153
+ #w;
11154
+ #C;
11155
+ #S;
11156
+ #L;
11157
+ #U;
11158
+ #m;
11159
+ get perf() {
11160
+ return this.#m;
11161
+ }
11162
+ ttl;
11163
+ ttlResolution;
11164
+ ttlAutopurge;
11165
+ updateAgeOnGet;
11166
+ updateAgeOnHas;
11167
+ allowStale;
11168
+ noDisposeOnSet;
11169
+ noUpdateTTL;
11170
+ maxEntrySize;
11171
+ sizeCalculation;
11172
+ noDeleteOnFetchRejection;
11173
+ noDeleteOnStaleGet;
11174
+ allowStaleOnFetchAbort;
11175
+ allowStaleOnFetchRejection;
11176
+ ignoreFetchAbort;
11177
+ #n;
11178
+ #_;
11179
+ #s;
11180
+ #i;
11181
+ #t;
11182
+ #a;
11183
+ #u;
11184
+ #l;
11185
+ #h;
11186
+ #b;
11187
+ #r;
11188
+ #y;
11189
+ #A;
11190
+ #d;
11191
+ #g;
11192
+ #T;
11193
+ #v;
11194
+ #f;
11195
+ #I;
11196
+ static unsafeExposeInternals(t) {
12061
11197
  return {
12062
- // properties
12063
- starts: c.#starts,
12064
- ttls: c.#ttls,
12065
- sizes: c.#sizes,
12066
- keyMap: c.#keyMap,
12067
- keyList: c.#keyList,
12068
- valList: c.#valList,
12069
- next: c.#next,
12070
- prev: c.#prev,
11198
+ starts: t.#A,
11199
+ ttls: t.#d,
11200
+ autopurgeTimers: t.#g,
11201
+ sizes: t.#y,
11202
+ keyMap: t.#s,
11203
+ keyList: t.#i,
11204
+ valList: t.#t,
11205
+ next: t.#a,
11206
+ prev: t.#u,
12071
11207
  get head () {
12072
- return c.#head;
11208
+ return t.#l;
12073
11209
  },
12074
11210
  get tail () {
12075
- return c.#tail;
11211
+ return t.#h;
12076
11212
  },
12077
- free: c.#free,
12078
- // methods
12079
- isBackgroundFetch: (p)=>c.#isBackgroundFetch(p),
12080
- backgroundFetch: (k, index, options, context)=>c.#backgroundFetch(k, index, options, context),
12081
- moveToTail: (index)=>c.#moveToTail(index),
12082
- indexes: (options)=>c.#indexes(options),
12083
- rindexes: (options)=>c.#rindexes(options),
12084
- isStale: (index)=>c.#isStale(index)
11213
+ free: t.#b,
11214
+ isBackgroundFetch: (e)=>t.#e(e),
11215
+ backgroundFetch: (e, i, s, n)=>t.#x(e, i, s, n),
11216
+ moveToTail: (e)=>t.#D(e),
11217
+ indexes: (e)=>t.#F(e),
11218
+ rindexes: (e)=>t.#O(e),
11219
+ isStale: (e)=>t.#p(e)
12085
11220
  };
12086
11221
  }
12087
- // Protected read-only members
12088
- /**
12089
- * {@link LRUCache.OptionsBase.max} (read-only)
12090
- */ get max() {
12091
- return this.#max;
11222
+ get max() {
11223
+ return this.#o;
12092
11224
  }
12093
- /**
12094
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
12095
- */ get maxSize() {
12096
- return this.#maxSize;
11225
+ get maxSize() {
11226
+ return this.#c;
12097
11227
  }
12098
- /**
12099
- * The total computed size of items in the cache (read-only)
12100
- */ get calculatedSize() {
12101
- return this.#calculatedSize;
11228
+ get calculatedSize() {
11229
+ return this.#_;
12102
11230
  }
12103
- /**
12104
- * The number of items stored in the cache (read-only)
12105
- */ get size() {
12106
- return this.#size;
11231
+ get size() {
11232
+ return this.#n;
12107
11233
  }
12108
- /**
12109
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
12110
- */ get fetchMethod() {
12111
- return this.#fetchMethod;
11234
+ get fetchMethod() {
11235
+ return this.#L;
12112
11236
  }
12113
11237
  get memoMethod() {
12114
- return this.#memoMethod;
12115
- }
12116
- /**
12117
- * {@link LRUCache.OptionsBase.dispose} (read-only)
12118
- */ get dispose() {
12119
- return this.#dispose;
12120
- }
12121
- /**
12122
- * {@link LRUCache.OptionsBase.onInsert} (read-only)
12123
- */ get onInsert() {
12124
- return this.#onInsert;
12125
- }
12126
- /**
12127
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
12128
- */ get disposeAfter() {
12129
- return this.#disposeAfter;
12130
- }
12131
- constructor(options){
12132
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
12133
- if (perf !== undefined) {
12134
- if (typeof perf?.now !== 'function') {
12135
- throw new TypeError('perf option must have a now() method if specified');
12136
- }
12137
- }
12138
- this.#perf = perf ?? defaultPerf;
12139
- if (max !== 0 && !isPosInt(max)) {
12140
- throw new TypeError('max option must be a nonnegative integer');
12141
- }
12142
- const UintArray = max ? getUintArray(max) : Array;
12143
- if (!UintArray) {
12144
- throw new Error('invalid max value: ' + max);
12145
- }
12146
- this.#max = max;
12147
- this.#maxSize = maxSize;
12148
- this.maxEntrySize = maxEntrySize || this.#maxSize;
12149
- this.sizeCalculation = sizeCalculation;
12150
- if (this.sizeCalculation) {
12151
- if (!this.#maxSize && !this.maxEntrySize) {
12152
- throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
12153
- }
12154
- if (typeof this.sizeCalculation !== 'function') {
12155
- throw new TypeError('sizeCalculation set to non-function');
12156
- }
12157
- }
12158
- if (memoMethod !== undefined && typeof memoMethod !== 'function') {
12159
- throw new TypeError('memoMethod must be a function if defined');
12160
- }
12161
- this.#memoMethod = memoMethod;
12162
- if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
12163
- throw new TypeError('fetchMethod must be a function if specified');
12164
- }
12165
- this.#fetchMethod = fetchMethod;
12166
- this.#hasFetchMethod = !!fetchMethod;
12167
- this.#keyMap = new Map();
12168
- this.#keyList = new Array(max).fill(undefined);
12169
- this.#valList = new Array(max).fill(undefined);
12170
- this.#next = new UintArray(max);
12171
- this.#prev = new UintArray(max);
12172
- this.#head = 0;
12173
- this.#tail = 0;
12174
- this.#free = Stack.create(max);
12175
- this.#size = 0;
12176
- this.#calculatedSize = 0;
12177
- if (typeof dispose === 'function') {
12178
- this.#dispose = dispose;
12179
- }
12180
- if (typeof onInsert === 'function') {
12181
- this.#onInsert = onInsert;
12182
- }
12183
- if (typeof disposeAfter === 'function') {
12184
- this.#disposeAfter = disposeAfter;
12185
- this.#disposed = [];
12186
- } else {
12187
- this.#disposeAfter = undefined;
12188
- this.#disposed = undefined;
12189
- }
12190
- this.#hasDispose = !!this.#dispose;
12191
- this.#hasOnInsert = !!this.#onInsert;
12192
- this.#hasDisposeAfter = !!this.#disposeAfter;
12193
- this.noDisposeOnSet = !!noDisposeOnSet;
12194
- this.noUpdateTTL = !!noUpdateTTL;
12195
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
12196
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
12197
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
12198
- this.ignoreFetchAbort = !!ignoreFetchAbort;
12199
- // NB: maxEntrySize is set to maxSize if it's set
12200
- if (this.maxEntrySize !== 0) {
12201
- if (this.#maxSize !== 0) {
12202
- if (!isPosInt(this.#maxSize)) {
12203
- throw new TypeError('maxSize must be a positive integer if specified');
12204
- }
12205
- }
12206
- if (!isPosInt(this.maxEntrySize)) {
12207
- throw new TypeError('maxEntrySize must be a positive integer if specified');
12208
- }
12209
- this.#initializeSizeTracking();
12210
- }
12211
- this.allowStale = !!allowStale;
12212
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
12213
- this.updateAgeOnGet = !!updateAgeOnGet;
12214
- this.updateAgeOnHas = !!updateAgeOnHas;
12215
- this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
12216
- this.ttlAutopurge = !!ttlAutopurge;
12217
- this.ttl = ttl || 0;
12218
- if (this.ttl) {
12219
- if (!isPosInt(this.ttl)) {
12220
- throw new TypeError('ttl must be a positive integer if specified');
12221
- }
12222
- this.#initializeTTLTracking();
12223
- }
12224
- // do not allow completely unbounded caches
12225
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
12226
- throw new TypeError('At least one of max, maxSize, or ttl is required');
12227
- }
12228
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
12229
- const code = 'LRU_CACHE_UNBOUNDED';
12230
- if (shouldWarn(code)) {
12231
- warned.add(code);
12232
- const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' + 'result in unbounded memory consumption.';
12233
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
12234
- }
12235
- }
12236
- }
12237
- /**
12238
- * Return the number of ms left in the item's TTL. If item is not in cache,
12239
- * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
12240
- */ getRemainingTTL(key) {
12241
- return this.#keyMap.has(key) ? Infinity : 0;
12242
- }
12243
- #initializeTTLTracking() {
12244
- const ttls = new ZeroArray(this.#max);
12245
- const starts = new ZeroArray(this.#max);
12246
- this.#ttls = ttls;
12247
- this.#starts = starts;
12248
- this.#setItemTTL = (index, ttl, start = this.#perf.now())=>{
12249
- starts[index] = ttl !== 0 ? start : 0;
12250
- ttls[index] = ttl;
12251
- if (ttl !== 0 && this.ttlAutopurge) {
12252
- const t = setTimeout(()=>{
12253
- if (this.#isStale(index)) {
12254
- this.#delete(this.#keyList[index], 'expire');
12255
- }
12256
- }, ttl + 1);
12257
- // unref() not supported on all platforms
12258
- /* c8 ignore start */ if (t.unref) {
12259
- t.unref();
12260
- }
12261
- /* c8 ignore stop */ }
12262
- };
12263
- this.#updateItemAge = (index)=>{
12264
- starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
11238
+ return this.#U;
11239
+ }
11240
+ get dispose() {
11241
+ return this.#w;
11242
+ }
11243
+ get onInsert() {
11244
+ return this.#C;
11245
+ }
11246
+ get disposeAfter() {
11247
+ return this.#S;
11248
+ }
11249
+ constructor(t){
11250
+ let { max: e = 0, ttl: i, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: o, updateAgeOnHas: h, allowStale: r, dispose: a, onInsert: w, disposeAfter: f, noDisposeOnSet: d, noUpdateTTL: g, maxSize: A = 0, maxEntrySize: p = 0, sizeCalculation: _, fetchMethod: l, memoMethod: S, noDeleteOnFetchRejection: b, noDeleteOnStaleGet: m, allowStaleOnFetchRejection: u, allowStaleOnFetchAbort: T, ignoreFetchAbort: F, perf: v } = t;
11251
+ if (v !== void 0 && typeof v?.now != "function") throw new TypeError("perf option must have a now() method if specified");
11252
+ if (this.#m = v ?? G, e !== 0 && !y(e)) throw new TypeError("max option must be a nonnegative integer");
11253
+ let O = e ? M(e) : Array;
11254
+ if (!O) throw new Error("invalid max value: " + e);
11255
+ if (this.#o = e, this.#c = A, this.maxEntrySize = p || this.#c, this.sizeCalculation = _, this.sizeCalculation) {
11256
+ if (!this.#c && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
11257
+ if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
11258
+ }
11259
+ if (S !== void 0 && typeof S != "function") throw new TypeError("memoMethod must be a function if defined");
11260
+ if (this.#U = S, l !== void 0 && typeof l != "function") throw new TypeError("fetchMethod must be a function if specified");
11261
+ if (this.#L = l, this.#v = !!l, this.#s = new Map, this.#i = new Array(e).fill(void 0), this.#t = new Array(e).fill(void 0), this.#a = new O(e), this.#u = new O(e), this.#l = 0, this.#h = 0, this.#b = W.create(e), this.#n = 0, this.#_ = 0, typeof a == "function" && (this.#w = a), typeof w == "function" && (this.#C = w), typeof f == "function" ? (this.#S = f, this.#r = []) : (this.#S = void 0, this.#r = void 0), this.#T = !!this.#w, this.#I = !!this.#C, this.#f = !!this.#S, this.noDisposeOnSet = !!d, this.noUpdateTTL = !!g, this.noDeleteOnFetchRejection = !!b, this.allowStaleOnFetchRejection = !!u, this.allowStaleOnFetchAbort = !!T, this.ignoreFetchAbort = !!F, this.maxEntrySize !== 0) {
11262
+ if (this.#c !== 0 && !y(this.#c)) throw new TypeError("maxSize must be a positive integer if specified");
11263
+ if (!y(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
11264
+ this.#B();
11265
+ }
11266
+ if (this.allowStale = !!r, this.noDeleteOnStaleGet = !!m, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!h, this.ttlResolution = y(s) || s === 0 ? s : 1, this.ttlAutopurge = !!n, this.ttl = i || 0, this.ttl) {
11267
+ if (!y(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
11268
+ this.#j();
11269
+ }
11270
+ if (this.#o === 0 && this.ttl === 0 && this.#c === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
11271
+ if (!this.ttlAutopurge && !this.#o && !this.#c) {
11272
+ let E = "LRU_CACHE_UNBOUNDED";
11273
+ x(E) && (U.add(E), I("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", E, c));
11274
+ }
11275
+ }
11276
+ getRemainingTTL(t) {
11277
+ return this.#s.has(t) ? 1 / 0 : 0;
11278
+ }
11279
+ #j() {
11280
+ let t = new z(this.#o), e = new z(this.#o);
11281
+ this.#d = t, this.#A = e;
11282
+ let i = this.ttlAutopurge ? new Array(this.#o) : void 0;
11283
+ this.#g = i, this.#N = (h, r, a = this.#m.now())=>{
11284
+ e[h] = r !== 0 ? a : 0, t[h] = r, s(h, r);
11285
+ }, this.#R = (h)=>{
11286
+ e[h] = t[h] !== 0 ? this.#m.now() : 0, s(h, t[h]);
12265
11287
  };
12266
- this.#statusTTL = (status, index)=>{
12267
- if (ttls[index]) {
12268
- const ttl = ttls[index];
12269
- const start = starts[index];
12270
- /* c8 ignore next */ if (!ttl || !start) return;
12271
- status.ttl = ttl;
12272
- status.start = start;
12273
- status.now = cachedNow || getNow();
12274
- const age = status.now - start;
12275
- status.remainingTTL = ttl - age;
11288
+ let s = this.ttlAutopurge ? (h, r)=>{
11289
+ if (i?.[h] && (clearTimeout(i[h]), i[h] = void 0), r && r !== 0 && i) {
11290
+ let a = setTimeout(()=>{
11291
+ this.#p(h) && this.#E(this.#i[h], "expire");
11292
+ }, r + 1);
11293
+ a.unref && a.unref(), i[h] = a;
11294
+ }
11295
+ } : ()=>{};
11296
+ this.#z = (h, r)=>{
11297
+ if (t[r]) {
11298
+ let a = t[r], w = e[r];
11299
+ if (!a || !w) return;
11300
+ h.ttl = a, h.start = w, h.now = n || o();
11301
+ let f = h.now - w;
11302
+ h.remainingTTL = a - f;
12276
11303
  }
12277
11304
  };
12278
- // debounce calls to perf.now() to 1s so we're not hitting
12279
- // that costly call repeatedly.
12280
- let cachedNow = 0;
12281
- const getNow = ()=>{
12282
- const n = this.#perf.now();
11305
+ let n = 0, o = ()=>{
11306
+ let h = this.#m.now();
12283
11307
  if (this.ttlResolution > 0) {
12284
- cachedNow = n;
12285
- const t = setTimeout(()=>cachedNow = 0, this.ttlResolution);
12286
- // not available on all platforms
12287
- /* c8 ignore start */ if (t.unref) {
12288
- t.unref();
12289
- }
12290
- /* c8 ignore stop */ }
12291
- return n;
12292
- };
12293
- this.getRemainingTTL = (key)=>{
12294
- const index = this.#keyMap.get(key);
12295
- if (index === undefined) {
12296
- return 0;
12297
- }
12298
- const ttl = ttls[index];
12299
- const start = starts[index];
12300
- if (!ttl || !start) {
12301
- return Infinity;
11308
+ n = h;
11309
+ let r = setTimeout(()=>n = 0, this.ttlResolution);
11310
+ r.unref && r.unref();
12302
11311
  }
12303
- const age = (cachedNow || getNow()) - start;
12304
- return ttl - age;
11312
+ return h;
12305
11313
  };
12306
- this.#isStale = (index)=>{
12307
- const s = starts[index];
12308
- const t = ttls[index];
12309
- return !!t && !!s && (cachedNow || getNow()) - s > t;
11314
+ this.getRemainingTTL = (h)=>{
11315
+ let r = this.#s.get(h);
11316
+ if (r === void 0) return 0;
11317
+ let a = t[r], w = e[r];
11318
+ if (!a || !w) return 1 / 0;
11319
+ let f = (n || o()) - w;
11320
+ return a - f;
11321
+ }, this.#p = (h)=>{
11322
+ let r = e[h], a = t[h];
11323
+ return !!a && !!r && (n || o()) - r > a;
12310
11324
  };
12311
11325
  }
12312
- // conditionally set private methods related to TTL
12313
- #updateItemAge = ()=>{};
12314
- #statusTTL = ()=>{};
12315
- #setItemTTL = ()=>{};
12316
- /* c8 ignore stop */ #isStale = ()=>false;
12317
- #initializeSizeTracking() {
12318
- const sizes = new ZeroArray(this.#max);
12319
- this.#calculatedSize = 0;
12320
- this.#sizes = sizes;
12321
- this.#removeItemSize = (index)=>{
12322
- this.#calculatedSize -= sizes[index];
12323
- sizes[index] = 0;
12324
- };
12325
- this.#requireSize = (k, v, size, sizeCalculation)=>{
12326
- // provisionally accept background fetches.
12327
- // actual value size will be checked when they return.
12328
- if (this.#isBackgroundFetch(v)) {
12329
- return 0;
12330
- }
12331
- if (!isPosInt(size)) {
12332
- if (sizeCalculation) {
12333
- if (typeof sizeCalculation !== 'function') {
12334
- throw new TypeError('sizeCalculation must be a function');
12335
- }
12336
- size = sizeCalculation(v, k);
12337
- if (!isPosInt(size)) {
12338
- throw new TypeError('sizeCalculation return invalid (expect positive integer)');
12339
- }
12340
- } else {
12341
- throw new TypeError('invalid size value (must be positive integer). ' + 'When maxSize or maxEntrySize is used, sizeCalculation ' + 'or size must be set.');
12342
- }
12343
- }
12344
- return size;
12345
- };
12346
- this.#addItemSize = (index, size, status)=>{
12347
- sizes[index] = size;
12348
- if (this.#maxSize) {
12349
- const maxSize = this.#maxSize - sizes[index];
12350
- while(this.#calculatedSize > maxSize){
12351
- this.#evict(true);
12352
- }
12353
- }
12354
- this.#calculatedSize += sizes[index];
12355
- if (status) {
12356
- status.entrySize = size;
12357
- status.totalCalculatedSize = this.#calculatedSize;
12358
- }
11326
+ #R = ()=>{};
11327
+ #z = ()=>{};
11328
+ #N = ()=>{};
11329
+ #p = ()=>false;
11330
+ #B() {
11331
+ let t = new z(this.#o);
11332
+ this.#_ = 0, this.#y = t, this.#W = (e)=>{
11333
+ this.#_ -= t[e], t[e] = 0;
11334
+ }, this.#P = (e, i, s, n)=>{
11335
+ if (this.#e(i)) return 0;
11336
+ if (!y(s)) if (n) {
11337
+ if (typeof n != "function") throw new TypeError("sizeCalculation must be a function");
11338
+ if (s = n(i, e), !y(s)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
11339
+ } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
11340
+ return s;
11341
+ }, this.#M = (e, i, s)=>{
11342
+ if (t[e] = i, this.#c) {
11343
+ let n = this.#c - t[e];
11344
+ for(; this.#_ > n;)this.#G(true);
11345
+ }
11346
+ this.#_ += t[e], s && (s.entrySize = i, s.totalCalculatedSize = this.#_);
12359
11347
  };
12360
11348
  }
12361
- #removeItemSize = (_i)=>{};
12362
- #addItemSize = (_i, _s, _st)=>{};
12363
- #requireSize = (_k, _v, size, sizeCalculation)=>{
12364
- if (size || sizeCalculation) {
12365
- throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
12366
- }
11349
+ #W = (t)=>{};
11350
+ #M = (t, e, i)=>{};
11351
+ #P = (t, e, i, s)=>{
11352
+ if (i || s) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
12367
11353
  return 0;
12368
11354
  };
12369
- *#indexes({ allowStale = this.allowStale } = {}) {
12370
- if (this.#size) {
12371
- for(let i = this.#tail; true;){
12372
- if (!this.#isValidIndex(i)) {
12373
- break;
12374
- }
12375
- if (allowStale || !this.#isStale(i)) {
12376
- yield i;
12377
- }
12378
- if (i === this.#head) {
12379
- break;
12380
- } else {
12381
- i = this.#prev[i];
12382
- }
12383
- }
12384
- }
11355
+ *#F({ allowStale: t = this.allowStale } = {}) {
11356
+ if (this.#n) for(let e = this.#h; !(!this.#H(e) || ((t || !this.#p(e)) && (yield e), e === this.#l));)e = this.#u[e];
12385
11357
  }
12386
- *#rindexes({ allowStale = this.allowStale } = {}) {
12387
- if (this.#size) {
12388
- for(let i = this.#head; true;){
12389
- if (!this.#isValidIndex(i)) {
12390
- break;
12391
- }
12392
- if (allowStale || !this.#isStale(i)) {
12393
- yield i;
12394
- }
12395
- if (i === this.#tail) {
12396
- break;
12397
- } else {
12398
- i = this.#next[i];
12399
- }
12400
- }
12401
- }
11358
+ *#O({ allowStale: t = this.allowStale } = {}) {
11359
+ if (this.#n) for(let e = this.#l; !(!this.#H(e) || ((t || !this.#p(e)) && (yield e), e === this.#h));)e = this.#a[e];
12402
11360
  }
12403
- #isValidIndex(index) {
12404
- return index !== undefined && this.#keyMap.get(this.#keyList[index]) === index;
11361
+ #H(t) {
11362
+ return t !== void 0 && this.#s.get(this.#i[t]) === t;
12405
11363
  }
12406
- /**
12407
- * Return a generator yielding `[key, value]` pairs,
12408
- * in order from most recently used to least recently used.
12409
- */ *entries() {
12410
- for (const i of this.#indexes()){
12411
- if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
12412
- yield [
12413
- this.#keyList[i],
12414
- this.#valList[i]
12415
- ];
12416
- }
12417
- }
11364
+ *entries() {
11365
+ for (let t of this.#F())this.#t[t] !== void 0 && this.#i[t] !== void 0 && !this.#e(this.#t[t]) && (yield [
11366
+ this.#i[t],
11367
+ this.#t[t]
11368
+ ]);
12418
11369
  }
12419
- /**
12420
- * Inverse order version of {@link LRUCache.entries}
12421
- *
12422
- * Return a generator yielding `[key, value]` pairs,
12423
- * in order from least recently used to most recently used.
12424
- */ *rentries() {
12425
- for (const i of this.#rindexes()){
12426
- if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
12427
- yield [
12428
- this.#keyList[i],
12429
- this.#valList[i]
12430
- ];
12431
- }
12432
- }
11370
+ *rentries() {
11371
+ for (let t of this.#O())this.#t[t] !== void 0 && this.#i[t] !== void 0 && !this.#e(this.#t[t]) && (yield [
11372
+ this.#i[t],
11373
+ this.#t[t]
11374
+ ]);
12433
11375
  }
12434
- /**
12435
- * Return a generator yielding the keys in the cache,
12436
- * in order from most recently used to least recently used.
12437
- */ *keys() {
12438
- for (const i of this.#indexes()){
12439
- const k = this.#keyList[i];
12440
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
12441
- yield k;
12442
- }
11376
+ *keys() {
11377
+ for (let t of this.#F()){
11378
+ let e = this.#i[t];
11379
+ e !== void 0 && !this.#e(this.#t[t]) && (yield e);
12443
11380
  }
12444
11381
  }
12445
- /**
12446
- * Inverse order version of {@link LRUCache.keys}
12447
- *
12448
- * Return a generator yielding the keys in the cache,
12449
- * in order from least recently used to most recently used.
12450
- */ *rkeys() {
12451
- for (const i of this.#rindexes()){
12452
- const k = this.#keyList[i];
12453
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
12454
- yield k;
12455
- }
11382
+ *rkeys() {
11383
+ for (let t of this.#O()){
11384
+ let e = this.#i[t];
11385
+ e !== void 0 && !this.#e(this.#t[t]) && (yield e);
12456
11386
  }
12457
11387
  }
12458
- /**
12459
- * Return a generator yielding the values in the cache,
12460
- * in order from most recently used to least recently used.
12461
- */ *values() {
12462
- for (const i of this.#indexes()){
12463
- const v = this.#valList[i];
12464
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
12465
- yield this.#valList[i];
12466
- }
12467
- }
11388
+ *values() {
11389
+ for (let t of this.#F())this.#t[t] !== void 0 && !this.#e(this.#t[t]) && (yield this.#t[t]);
12468
11390
  }
12469
- /**
12470
- * Inverse order version of {@link LRUCache.values}
12471
- *
12472
- * Return a generator yielding the values in the cache,
12473
- * in order from least recently used to most recently used.
12474
- */ *rvalues() {
12475
- for (const i of this.#rindexes()){
12476
- const v = this.#valList[i];
12477
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
12478
- yield this.#valList[i];
12479
- }
12480
- }
11391
+ *rvalues() {
11392
+ for (let t of this.#O())this.#t[t] !== void 0 && !this.#e(this.#t[t]) && (yield this.#t[t]);
12481
11393
  }
12482
- /**
12483
- * Iterating over the cache itself yields the same results as
12484
- * {@link LRUCache.entries}
12485
- */ [_computedKey]() {
11394
+ [_computedKey]() {
12486
11395
  return this.entries();
12487
11396
  }
12488
- /**
12489
- * A String value that is used in the creation of the default string
12490
- * description of an object. Called by the built-in method
12491
- * `Object.prototype.toString`.
12492
- */ [_computedKey1] = 'LRUCache';
12493
- /**
12494
- * Find a value for which the supplied fn method returns a truthy value,
12495
- * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
12496
- */ find(fn, getOptions = {}) {
12497
- for (const i of this.#indexes()){
12498
- const v = this.#valList[i];
12499
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
12500
- if (value === undefined) continue;
12501
- if (fn(value, this.#keyList[i], this)) {
12502
- return this.get(this.#keyList[i], getOptions);
12503
- }
11397
+ [_computedKey1] = "LRUCache";
11398
+ find(t, e = {}) {
11399
+ for (let i of this.#F()){
11400
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
11401
+ if (n !== void 0 && t(n, this.#i[i], this)) return this.get(this.#i[i], e);
12504
11402
  }
12505
11403
  }
12506
- /**
12507
- * Call the supplied function on each item in the cache, in order from most
12508
- * recently used to least recently used.
12509
- *
12510
- * `fn` is called as `fn(value, key, cache)`.
12511
- *
12512
- * If `thisp` is provided, function will be called in the `this`-context of
12513
- * the provided object, or the cache if no `thisp` object is provided.
12514
- *
12515
- * Does not update age or recenty of use, or iterate over stale values.
12516
- */ forEach(fn, thisp = this) {
12517
- for (const i of this.#indexes()){
12518
- const v = this.#valList[i];
12519
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
12520
- if (value === undefined) continue;
12521
- fn.call(thisp, value, this.#keyList[i], this);
11404
+ forEach(t, e = this) {
11405
+ for (let i of this.#F()){
11406
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
11407
+ n !== void 0 && t.call(e, n, this.#i[i], this);
12522
11408
  }
12523
11409
  }
12524
- /**
12525
- * The same as {@link LRUCache.forEach} but items are iterated over in
12526
- * reverse order. (ie, less recently used items are iterated over first.)
12527
- */ rforEach(fn, thisp = this) {
12528
- for (const i of this.#rindexes()){
12529
- const v = this.#valList[i];
12530
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
12531
- if (value === undefined) continue;
12532
- fn.call(thisp, value, this.#keyList[i], this);
11410
+ rforEach(t, e = this) {
11411
+ for (let i of this.#O()){
11412
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
11413
+ n !== void 0 && t.call(e, n, this.#i[i], this);
12533
11414
  }
12534
11415
  }
12535
- /**
12536
- * Delete any stale entries. Returns true if anything was removed,
12537
- * false otherwise.
12538
- */ purgeStale() {
12539
- let deleted = false;
12540
- for (const i of this.#rindexes({
11416
+ purgeStale() {
11417
+ let t = false;
11418
+ for (let e of this.#O({
12541
11419
  allowStale: true
12542
- })){
12543
- if (this.#isStale(i)) {
12544
- this.#delete(this.#keyList[i], 'expire');
12545
- deleted = true;
12546
- }
12547
- }
12548
- return deleted;
12549
- }
12550
- /**
12551
- * Get the extended info about a given entry, to get its value, size, and
12552
- * TTL info simultaneously. Returns `undefined` if the key is not present.
12553
- *
12554
- * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
12555
- * serialization, the `start` value is always the current timestamp, and the
12556
- * `ttl` is a calculated remaining time to live (negative if expired).
12557
- *
12558
- * Always returns stale values, if their info is found in the cache, so be
12559
- * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
12560
- * if relevant.
12561
- */ info(key) {
12562
- const i = this.#keyMap.get(key);
12563
- if (i === undefined) return undefined;
12564
- const v = this.#valList[i];
12565
- /* c8 ignore start - this isn't tested for the info function,
12566
- * but it's the same logic as found in other places. */ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
12567
- if (value === undefined) return undefined;
12568
- /* c8 ignore end */ const entry = {
12569
- value
11420
+ }))this.#p(e) && (this.#E(this.#i[e], "expire"), t = true);
11421
+ return t;
11422
+ }
11423
+ info(t) {
11424
+ let e = this.#s.get(t);
11425
+ if (e === void 0) return;
11426
+ let i = this.#t[e], s = this.#e(i) ? i.__staleWhileFetching : i;
11427
+ if (s === void 0) return;
11428
+ let n = {
11429
+ value: s
12570
11430
  };
12571
- if (this.#ttls && this.#starts) {
12572
- const ttl = this.#ttls[i];
12573
- const start = this.#starts[i];
12574
- if (ttl && start) {
12575
- const remain = ttl - (this.#perf.now() - start);
12576
- entry.ttl = remain;
12577
- entry.start = Date.now();
11431
+ if (this.#d && this.#A) {
11432
+ let o = this.#d[e], h = this.#A[e];
11433
+ if (o && h) {
11434
+ let r = o - (this.#m.now() - h);
11435
+ n.ttl = r, n.start = Date.now();
12578
11436
  }
12579
11437
  }
12580
- if (this.#sizes) {
12581
- entry.size = this.#sizes[i];
12582
- }
12583
- return entry;
11438
+ return this.#y && (n.size = this.#y[e]), n;
12584
11439
  }
12585
- /**
12586
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
12587
- * passed to {@link LRUCache#load}.
12588
- *
12589
- * The `start` fields are calculated relative to a portable `Date.now()`
12590
- * timestamp, even if `performance.now()` is available.
12591
- *
12592
- * Stale entries are always included in the `dump`, even if
12593
- * {@link LRUCache.OptionsBase.allowStale} is false.
12594
- *
12595
- * Note: this returns an actual array, not a generator, so it can be more
12596
- * easily passed around.
12597
- */ dump() {
12598
- const arr = [];
12599
- for (const i of this.#indexes({
11440
+ dump() {
11441
+ let t = [];
11442
+ for (let e of this.#F({
12600
11443
  allowStale: true
12601
11444
  })){
12602
- const key = this.#keyList[i];
12603
- const v = this.#valList[i];
12604
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
12605
- if (value === undefined || key === undefined) continue;
12606
- const entry = {
12607
- value
11445
+ let i = this.#i[e], s = this.#t[e], n = this.#e(s) ? s.__staleWhileFetching : s;
11446
+ if (n === void 0 || i === void 0) continue;
11447
+ let o = {
11448
+ value: n
12608
11449
  };
12609
- if (this.#ttls && this.#starts) {
12610
- entry.ttl = this.#ttls[i];
12611
- // always dump the start relative to a portable timestamp
12612
- // it's ok for this to be a bit slow, it's a rare operation.
12613
- const age = this.#perf.now() - this.#starts[i];
12614
- entry.start = Math.floor(Date.now() - age);
12615
- }
12616
- if (this.#sizes) {
12617
- entry.size = this.#sizes[i];
12618
- }
12619
- arr.unshift([
12620
- key,
12621
- entry
11450
+ if (this.#d && this.#A) {
11451
+ o.ttl = this.#d[e];
11452
+ let h = this.#m.now() - this.#A[e];
11453
+ o.start = Math.floor(Date.now() - h);
11454
+ }
11455
+ this.#y && (o.size = this.#y[e]), t.unshift([
11456
+ i,
11457
+ o
12622
11458
  ]);
12623
11459
  }
12624
- return arr;
11460
+ return t;
12625
11461
  }
12626
- /**
12627
- * Reset the cache and load in the items in entries in the order listed.
12628
- *
12629
- * The shape of the resulting cache may be different if the same options are
12630
- * not used in both caches.
12631
- *
12632
- * The `start` fields are assumed to be calculated relative to a portable
12633
- * `Date.now()` timestamp, even if `performance.now()` is available.
12634
- */ load(arr) {
11462
+ load(t) {
12635
11463
  this.clear();
12636
- for (const [key, entry] of arr){
12637
- if (entry.start) {
12638
- // entry.start is a portable timestamp, but we may be using
12639
- // node's performance.now(), so calculate the offset, so that
12640
- // we get the intended remaining TTL, no matter how long it's
12641
- // been on ice.
12642
- //
12643
- // it's ok for this to be a bit slow, it's a rare operation.
12644
- const age = Date.now() - entry.start;
12645
- entry.start = this.#perf.now() - age;
11464
+ for (let [e, i] of t){
11465
+ if (i.start) {
11466
+ let s = Date.now() - i.start;
11467
+ i.start = this.#m.now() - s;
12646
11468
  }
12647
- this.set(key, entry.value, entry);
11469
+ this.set(e, i.value, i);
12648
11470
  }
12649
11471
  }
12650
- /**
12651
- * Add a value to the cache.
12652
- *
12653
- * Note: if `undefined` is specified as a value, this is an alias for
12654
- * {@link LRUCache#delete}
12655
- *
12656
- * Fields on the {@link LRUCache.SetOptions} options param will override
12657
- * their corresponding values in the constructor options for the scope
12658
- * of this single `set()` operation.
12659
- *
12660
- * If `start` is provided, then that will set the effective start
12661
- * time for the TTL calculation. Note that this must be a previous
12662
- * value of `performance.now()` if supported, or a previous value of
12663
- * `Date.now()` if not.
12664
- *
12665
- * Options object may also include `size`, which will prevent
12666
- * calling the `sizeCalculation` function and just use the specified
12667
- * number if it is a positive integer, and `noDisposeOnSet` which
12668
- * will prevent calling a `dispose` function in the case of
12669
- * overwrites.
12670
- *
12671
- * If the `size` (or return value of `sizeCalculation`) for a given
12672
- * entry is greater than `maxEntrySize`, then the item will not be
12673
- * added to the cache.
12674
- *
12675
- * Will update the recency of the entry.
12676
- *
12677
- * If the value is `undefined`, then this is an alias for
12678
- * `cache.delete(key)`. `undefined` is never stored in the cache.
12679
- */ set(k, v, setOptions = {}) {
12680
- if (v === undefined) {
12681
- this.delete(k);
12682
- return this;
12683
- }
12684
- const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
12685
- let { noUpdateTTL = this.noUpdateTTL } = setOptions;
12686
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
12687
- // if the item doesn't fit, don't do anything
12688
- // NB: maxEntrySize set to maxSize by default
12689
- if (this.maxEntrySize && size > this.maxEntrySize) {
12690
- if (status) {
12691
- status.set = 'miss';
12692
- status.maxEntrySizeExceeded = true;
12693
- }
12694
- // have to delete, in case something is there already.
12695
- this.#delete(k, 'set');
12696
- return this;
12697
- }
12698
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
12699
- if (index === undefined) {
12700
- // addition
12701
- index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
12702
- this.#keyList[index] = k;
12703
- this.#valList[index] = v;
12704
- this.#keyMap.set(k, index);
12705
- this.#next[this.#tail] = index;
12706
- this.#prev[index] = this.#tail;
12707
- this.#tail = index;
12708
- this.#size++;
12709
- this.#addItemSize(index, size, status);
12710
- if (status) status.set = 'add';
12711
- noUpdateTTL = false;
12712
- if (this.#hasOnInsert) {
12713
- this.#onInsert?.(v, k, 'add');
12714
- }
12715
- } else {
12716
- // update
12717
- this.#moveToTail(index);
12718
- const oldVal = this.#valList[index];
12719
- if (v !== oldVal) {
12720
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
12721
- oldVal.__abortController.abort(new Error('replaced'));
12722
- const { __staleWhileFetching: s } = oldVal;
12723
- if (s !== undefined && !noDisposeOnSet) {
12724
- if (this.#hasDispose) {
12725
- this.#dispose?.(s, k, 'set');
12726
- }
12727
- if (this.#hasDisposeAfter) {
12728
- this.#disposed?.push([
12729
- s,
12730
- k,
12731
- 'set'
12732
- ]);
12733
- }
12734
- }
12735
- } else if (!noDisposeOnSet) {
12736
- if (this.#hasDispose) {
12737
- this.#dispose?.(oldVal, k, 'set');
12738
- }
12739
- if (this.#hasDisposeAfter) {
12740
- this.#disposed?.push([
12741
- oldVal,
12742
- k,
12743
- 'set'
12744
- ]);
12745
- }
12746
- }
12747
- this.#removeItemSize(index);
12748
- this.#addItemSize(index, size, status);
12749
- this.#valList[index] = v;
12750
- if (status) {
12751
- status.set = 'replace';
12752
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
12753
- if (oldValue !== undefined) status.oldValue = oldValue;
11472
+ set(t, e, i = {}) {
11473
+ if (e === void 0) return this.delete(t), this;
11474
+ let { ttl: s = this.ttl, start: n, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: h = this.sizeCalculation, status: r } = i, { noUpdateTTL: a = this.noUpdateTTL } = i, w = this.#P(t, e, i.size || 0, h);
11475
+ if (this.maxEntrySize && w > this.maxEntrySize) return r && (r.set = "miss", r.maxEntrySizeExceeded = true), this.#E(t, "set"), this;
11476
+ let f = this.#n === 0 ? void 0 : this.#s.get(t);
11477
+ if (f === void 0) f = this.#n === 0 ? this.#h : this.#b.length !== 0 ? this.#b.pop() : this.#n === this.#o ? this.#G(false) : this.#n, this.#i[f] = t, this.#t[f] = e, this.#s.set(t, f), this.#a[this.#h] = f, this.#u[f] = this.#h, this.#h = f, this.#n++, this.#M(f, w, r), r && (r.set = "add"), a = false, this.#I && this.#C?.(e, t, "add");
11478
+ else {
11479
+ this.#D(f);
11480
+ let d = this.#t[f];
11481
+ if (e !== d) {
11482
+ if (this.#v && this.#e(d)) {
11483
+ d.__abortController.abort(new Error("replaced"));
11484
+ let { __staleWhileFetching: g } = d;
11485
+ g !== void 0 && !o && (this.#T && this.#w?.(g, t, "set"), this.#f && this.#r?.push([
11486
+ g,
11487
+ t,
11488
+ "set"
11489
+ ]));
11490
+ } else o || (this.#T && this.#w?.(d, t, "set"), this.#f && this.#r?.push([
11491
+ d,
11492
+ t,
11493
+ "set"
11494
+ ]));
11495
+ if (this.#W(f), this.#M(f, w, r), this.#t[f] = e, r) {
11496
+ r.set = "replace";
11497
+ let g = d && this.#e(d) ? d.__staleWhileFetching : d;
11498
+ g !== void 0 && (r.oldValue = g);
12754
11499
  }
12755
- } else if (status) {
12756
- status.set = 'update';
12757
- }
12758
- if (this.#hasOnInsert) {
12759
- this.onInsert?.(v, k, v === oldVal ? 'update' : 'replace');
12760
- }
12761
- }
12762
- if (ttl !== 0 && !this.#ttls) {
12763
- this.#initializeTTLTracking();
11500
+ } else r && (r.set = "update");
11501
+ this.#I && this.onInsert?.(e, t, e === d ? "update" : "replace");
12764
11502
  }
12765
- if (this.#ttls) {
12766
- if (!noUpdateTTL) {
12767
- this.#setItemTTL(index, ttl, start);
12768
- }
12769
- if (status) this.#statusTTL(status, index);
12770
- }
12771
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
12772
- const dt = this.#disposed;
12773
- let task;
12774
- while(task = dt?.shift()){
12775
- this.#disposeAfter?.(...task);
12776
- }
11503
+ if (s !== 0 && !this.#d && this.#j(), this.#d && (a || this.#N(f, s, n), r && this.#z(r, f)), !o && this.#f && this.#r) {
11504
+ let d = this.#r, g;
11505
+ for(; g = d?.shift();)this.#S?.(...g);
12777
11506
  }
12778
11507
  return this;
12779
11508
  }
12780
- /**
12781
- * Evict the least recently used item, returning its value or
12782
- * `undefined` if cache is empty.
12783
- */ pop() {
11509
+ pop() {
12784
11510
  try {
12785
- while(this.#size){
12786
- const val = this.#valList[this.#head];
12787
- this.#evict(true);
12788
- if (this.#isBackgroundFetch(val)) {
12789
- if (val.__staleWhileFetching) {
12790
- return val.__staleWhileFetching;
12791
- }
12792
- } else if (val !== undefined) {
12793
- return val;
12794
- }
11511
+ for(; this.#n;){
11512
+ let t = this.#t[this.#l];
11513
+ if (this.#G(!0), this.#e(t)) {
11514
+ if (t.__staleWhileFetching) return t.__staleWhileFetching;
11515
+ } else if (t !== void 0) return t;
12795
11516
  }
12796
11517
  } finally{
12797
- if (this.#hasDisposeAfter && this.#disposed) {
12798
- const dt = this.#disposed;
12799
- let task;
12800
- while(task = dt?.shift()){
12801
- this.#disposeAfter?.(...task);
12802
- }
12803
- }
12804
- }
12805
- }
12806
- #evict(free) {
12807
- const head = this.#head;
12808
- const k = this.#keyList[head];
12809
- const v = this.#valList[head];
12810
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
12811
- v.__abortController.abort(new Error('evicted'));
12812
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
12813
- if (this.#hasDispose) {
12814
- this.#dispose?.(v, k, 'evict');
12815
- }
12816
- if (this.#hasDisposeAfter) {
12817
- this.#disposed?.push([
12818
- v,
12819
- k,
12820
- 'evict'
12821
- ]);
11518
+ if (this.#f && this.#r) {
11519
+ let t = this.#r, e;
11520
+ for(; e = t?.shift();)this.#S?.(...e);
12822
11521
  }
12823
11522
  }
12824
- this.#removeItemSize(head);
12825
- // if we aren't about to use the index, then null these out
12826
- if (free) {
12827
- this.#keyList[head] = undefined;
12828
- this.#valList[head] = undefined;
12829
- this.#free.push(head);
12830
- }
12831
- if (this.#size === 1) {
12832
- this.#head = this.#tail = 0;
12833
- this.#free.length = 0;
12834
- } else {
12835
- this.#head = this.#next[head];
12836
- }
12837
- this.#keyMap.delete(k);
12838
- this.#size--;
12839
- return head;
12840
11523
  }
12841
- /**
12842
- * Check if a key is in the cache, without updating the recency of use.
12843
- * Will return false if the item is stale, even though it is technically
12844
- * in the cache.
12845
- *
12846
- * Check if a key is in the cache, without updating the recency of
12847
- * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
12848
- * to `true` in either the options or the constructor.
12849
- *
12850
- * Will return `false` if the item is stale, even though it is technically in
12851
- * the cache. The difference can be determined (if it matters) by using a
12852
- * `status` argument, and inspecting the `has` field.
12853
- *
12854
- * Will not update item age unless
12855
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
12856
- */ has(k, hasOptions = {}) {
12857
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
12858
- const index = this.#keyMap.get(k);
12859
- if (index !== undefined) {
12860
- const v = this.#valList[index];
12861
- if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === undefined) {
12862
- return false;
12863
- }
12864
- if (!this.#isStale(index)) {
12865
- if (updateAgeOnHas) {
12866
- this.#updateItemAge(index);
12867
- }
12868
- if (status) {
12869
- status.has = 'hit';
12870
- this.#statusTTL(status, index);
12871
- }
12872
- return true;
12873
- } else if (status) {
12874
- status.has = 'stale';
12875
- this.#statusTTL(status, index);
12876
- }
12877
- } else if (status) {
12878
- status.has = 'miss';
12879
- }
11524
+ #G(t) {
11525
+ let e = this.#l, i = this.#i[e], s = this.#t[e];
11526
+ return this.#v && this.#e(s) ? s.__abortController.abort(new Error("evicted")) : (this.#T || this.#f) && (this.#T && this.#w?.(s, i, "evict"), this.#f && this.#r?.push([
11527
+ s,
11528
+ i,
11529
+ "evict"
11530
+ ])), this.#W(e), this.#g?.[e] && (clearTimeout(this.#g[e]), this.#g[e] = void 0), t && (this.#i[e] = void 0, this.#t[e] = void 0, this.#b.push(e)), this.#n === 1 ? (this.#l = this.#h = 0, this.#b.length = 0) : this.#l = this.#a[e], this.#s.delete(i), this.#n--, e;
11531
+ }
11532
+ has(t, e = {}) {
11533
+ let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = e, n = this.#s.get(t);
11534
+ if (n !== void 0) {
11535
+ let o = this.#t[n];
11536
+ if (this.#e(o) && o.__staleWhileFetching === void 0) return false;
11537
+ if (this.#p(n)) s && (s.has = "stale", this.#z(s, n));
11538
+ else return i && this.#R(n), s && (s.has = "hit", this.#z(s, n)), true;
11539
+ } else s && (s.has = "miss");
12880
11540
  return false;
12881
11541
  }
12882
- /**
12883
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
12884
- * items.
12885
- *
12886
- * Returns `undefined` if the item is stale, unless
12887
- * {@link LRUCache.OptionsBase.allowStale} is set.
12888
- */ peek(k, peekOptions = {}) {
12889
- const { allowStale = this.allowStale } = peekOptions;
12890
- const index = this.#keyMap.get(k);
12891
- if (index === undefined || !allowStale && this.#isStale(index)) {
12892
- return;
12893
- }
12894
- const v = this.#valList[index];
12895
- // either stale and allowed, or forcing a refresh of non-stale value
12896
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
12897
- }
12898
- #backgroundFetch(k, index, options, context) {
12899
- const v = index === undefined ? undefined : this.#valList[index];
12900
- if (this.#isBackgroundFetch(v)) {
12901
- return v;
12902
- }
12903
- const ac = new AC();
12904
- const { signal } = options;
12905
- // when/if our AC signals, then stop listening to theirs.
12906
- signal?.addEventListener('abort', ()=>ac.abort(signal.reason), {
12907
- signal: ac.signal
11542
+ peek(t, e = {}) {
11543
+ let { allowStale: i = this.allowStale } = e, s = this.#s.get(t);
11544
+ if (s === void 0 || !i && this.#p(s)) return;
11545
+ let n = this.#t[s];
11546
+ return this.#e(n) ? n.__staleWhileFetching : n;
11547
+ }
11548
+ #x(t, e, i, s) {
11549
+ let n = e === void 0 ? void 0 : this.#t[e];
11550
+ if (this.#e(n)) return n;
11551
+ let o = new C, { signal: h } = i;
11552
+ h?.addEventListener("abort", ()=>o.abort(h.reason), {
11553
+ signal: o.signal
12908
11554
  });
12909
- const fetchOpts = {
12910
- signal: ac.signal,
12911
- options,
12912
- context
12913
- };
12914
- const cb = (v, updateCache = false)=>{
12915
- const { aborted } = ac.signal;
12916
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
12917
- if (options.status) {
12918
- if (aborted && !updateCache) {
12919
- options.status.fetchAborted = true;
12920
- options.status.fetchError = ac.signal.reason;
12921
- if (ignoreAbort) options.status.fetchAbortIgnored = true;
12922
- } else {
12923
- options.status.fetchResolved = true;
12924
- }
12925
- }
12926
- if (aborted && !ignoreAbort && !updateCache) {
12927
- return fetchFail(ac.signal.reason);
12928
- }
12929
- // either we didn't abort, and are still here, or we did, and ignored
12930
- const bf = p;
12931
- // if nothing else has been written there but we're set to update the
12932
- // cache and ignore the abort, or if it's still pending on this specific
12933
- // background request, then write it to the cache.
12934
- const vl = this.#valList[index];
12935
- if (vl === p || ignoreAbort && updateCache && vl === undefined) {
12936
- if (v === undefined) {
12937
- if (bf.__staleWhileFetching !== undefined) {
12938
- this.#valList[index] = bf.__staleWhileFetching;
12939
- } else {
12940
- this.#delete(k, 'fetch');
12941
- }
12942
- } else {
12943
- if (options.status) options.status.fetchUpdated = true;
12944
- this.set(k, v, fetchOpts.options);
12945
- }
12946
- }
12947
- return v;
12948
- };
12949
- const eb = (er)=>{
12950
- if (options.status) {
12951
- options.status.fetchRejected = true;
12952
- options.status.fetchError = er;
12953
- }
12954
- return fetchFail(er);
12955
- };
12956
- const fetchFail = (er)=>{
12957
- const { aborted } = ac.signal;
12958
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
12959
- const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
12960
- const noDelete = allowStale || options.noDeleteOnFetchRejection;
12961
- const bf = p;
12962
- if (this.#valList[index] === p) {
12963
- // if we allow stale on fetch rejections, then we need to ensure that
12964
- // the stale value is not removed from the cache when the fetch fails.
12965
- const del = !noDelete || bf.__staleWhileFetching === undefined;
12966
- if (del) {
12967
- this.#delete(k, 'fetch');
12968
- } else if (!allowStaleAborted) {
12969
- // still replace the *promise* with the stale value,
12970
- // since we are done with the promise at this point.
12971
- // leave it untouched if we're still waiting for an
12972
- // aborted background fetch that hasn't yet returned.
12973
- this.#valList[index] = bf.__staleWhileFetching;
12974
- }
12975
- }
12976
- if (allowStale) {
12977
- if (options.status && bf.__staleWhileFetching !== undefined) {
12978
- options.status.returnedStale = true;
12979
- }
12980
- return bf.__staleWhileFetching;
12981
- } else if (bf.__returned === bf) {
12982
- throw er;
12983
- }
12984
- };
12985
- const pcall = (res, rej)=>{
12986
- const fmp = this.#fetchMethod?.(k, v, fetchOpts);
12987
- if (fmp && fmp instanceof Promise) {
12988
- fmp.then((v)=>res(v === undefined ? undefined : v), rej);
12989
- }
12990
- // ignored, we go until we finish, regardless.
12991
- // defer check until we are actually aborting,
12992
- // so fetchMethod can override.
12993
- ac.signal.addEventListener('abort', ()=>{
12994
- if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
12995
- res(undefined);
12996
- // when it eventually resolves, update the cache.
12997
- if (options.allowStaleOnFetchAbort) {
12998
- res = (v)=>cb(v, true);
12999
- }
13000
- }
11555
+ let r = {
11556
+ signal: o.signal,
11557
+ options: i,
11558
+ context: s
11559
+ }, a = (p, _ = false)=>{
11560
+ let { aborted: l } = o.signal, S = i.ignoreFetchAbort && p !== void 0, b = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && p !== void 0);
11561
+ if (i.status && (l && !_ ? (i.status.fetchAborted = true, i.status.fetchError = o.signal.reason, S && (i.status.fetchAbortIgnored = true)) : i.status.fetchResolved = true), l && !S && !_) return f(o.signal.reason, b);
11562
+ let m = g, u = this.#t[e];
11563
+ return (u === g || S && _ && u === void 0) && (p === void 0 ? m.__staleWhileFetching !== void 0 ? this.#t[e] = m.__staleWhileFetching : this.#E(t, "fetch") : (i.status && (i.status.fetchUpdated = true), this.set(t, p, r.options))), p;
11564
+ }, w = (p)=>(i.status && (i.status.fetchRejected = true, i.status.fetchError = p), f(p, false)), f = (p, _)=>{
11565
+ let { aborted: l } = o.signal, S = l && i.allowStaleOnFetchAbort, b = S || i.allowStaleOnFetchRejection, m = b || i.noDeleteOnFetchRejection, u = g;
11566
+ if (this.#t[e] === g && (!m || !_ && u.__staleWhileFetching === void 0 ? this.#E(t, "fetch") : S || (this.#t[e] = u.__staleWhileFetching)), b) return i.status && u.__staleWhileFetching !== void 0 && (i.status.returnedStale = true), u.__staleWhileFetching;
11567
+ if (u.__returned === u) throw p;
11568
+ }, d = (p, _)=>{
11569
+ let l = this.#L?.(t, n, r);
11570
+ l && l instanceof Promise && l.then((S)=>p(S === void 0 ? void 0 : S), _), o.signal.addEventListener("abort", ()=>{
11571
+ (!i.ignoreFetchAbort || i.allowStaleOnFetchAbort) && (p(void 0), i.allowStaleOnFetchAbort && (p = (S)=>a(S, true)));
13001
11572
  });
13002
11573
  };
13003
- if (options.status) options.status.fetchDispatched = true;
13004
- const p = new Promise(pcall).then(cb, eb);
13005
- const bf = Object.assign(p, {
13006
- __abortController: ac,
13007
- __staleWhileFetching: v,
13008
- __returned: undefined
11574
+ i.status && (i.status.fetchDispatched = true);
11575
+ let g = new Promise(d).then(a, w), A = Object.assign(g, {
11576
+ __abortController: o,
11577
+ __staleWhileFetching: n,
11578
+ __returned: void 0
13009
11579
  });
13010
- if (index === undefined) {
13011
- // internal, don't expose status.
13012
- this.set(k, bf, {
13013
- ...fetchOpts.options,
13014
- status: undefined
13015
- });
13016
- index = this.#keyMap.get(k);
11580
+ return e === void 0 ? (this.set(t, A, {
11581
+ ...r.options,
11582
+ status: void 0
11583
+ }), e = this.#s.get(t)) : this.#t[e] = A, A;
11584
+ }
11585
+ #e(t) {
11586
+ if (!this.#v) return false;
11587
+ let e = t;
11588
+ return !!e && e instanceof Promise && e.hasOwnProperty("__staleWhileFetching") && e.__abortController instanceof C;
11589
+ }
11590
+ async fetch(t, e = {}) {
11591
+ let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: r = 0, sizeCalculation: a = this.sizeCalculation, noUpdateTTL: w = this.noUpdateTTL, noDeleteOnFetchRejection: f = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: g = this.ignoreFetchAbort, allowStaleOnFetchAbort: A = this.allowStaleOnFetchAbort, context: p, forceRefresh: _ = false, status: l, signal: S } = e;
11592
+ if (!this.#v) return l && (l.fetch = "get"), this.get(t, {
11593
+ allowStale: i,
11594
+ updateAgeOnGet: s,
11595
+ noDeleteOnStaleGet: n,
11596
+ status: l
11597
+ });
11598
+ let b = {
11599
+ allowStale: i,
11600
+ updateAgeOnGet: s,
11601
+ noDeleteOnStaleGet: n,
11602
+ ttl: o,
11603
+ noDisposeOnSet: h,
11604
+ size: r,
11605
+ sizeCalculation: a,
11606
+ noUpdateTTL: w,
11607
+ noDeleteOnFetchRejection: f,
11608
+ allowStaleOnFetchRejection: d,
11609
+ allowStaleOnFetchAbort: A,
11610
+ ignoreFetchAbort: g,
11611
+ status: l,
11612
+ signal: S
11613
+ }, m = this.#s.get(t);
11614
+ if (m === void 0) {
11615
+ l && (l.fetch = "miss");
11616
+ let u = this.#x(t, m, b, p);
11617
+ return u.__returned = u;
13017
11618
  } else {
13018
- this.#valList[index] = bf;
13019
- }
13020
- return bf;
13021
- }
13022
- #isBackgroundFetch(p) {
13023
- if (!this.#hasFetchMethod) return false;
13024
- const b = p;
13025
- return !!b && b instanceof Promise && b.hasOwnProperty('__staleWhileFetching') && b.__abortController instanceof AC;
13026
- }
13027
- async fetch(k, fetchOptions = {}) {
13028
- const { // get options
13029
- allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, // set options
13030
- ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, // fetch exclusive options
13031
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal } = fetchOptions;
13032
- if (!this.#hasFetchMethod) {
13033
- if (status) status.fetch = 'get';
13034
- return this.get(k, {
13035
- allowStale,
13036
- updateAgeOnGet,
13037
- noDeleteOnStaleGet,
13038
- status
13039
- });
11619
+ let u = this.#t[m];
11620
+ if (this.#e(u)) {
11621
+ let E = i && u.__staleWhileFetching !== void 0;
11622
+ return l && (l.fetch = "inflight", E && (l.returnedStale = true)), E ? u.__staleWhileFetching : u.__returned = u;
11623
+ }
11624
+ let T = this.#p(m);
11625
+ if (!_ && !T) return l && (l.fetch = "hit"), this.#D(m), s && this.#R(m), l && this.#z(l, m), u;
11626
+ let F = this.#x(t, m, b, p), O = F.__staleWhileFetching !== void 0 && i;
11627
+ return l && (l.fetch = T ? "stale" : "refresh", O && T && (l.returnedStale = true)), O ? F.__staleWhileFetching : F.__returned = F;
13040
11628
  }
13041
- const options = {
13042
- allowStale,
13043
- updateAgeOnGet,
13044
- noDeleteOnStaleGet,
13045
- ttl,
13046
- noDisposeOnSet,
13047
- size,
13048
- sizeCalculation,
13049
- noUpdateTTL,
13050
- noDeleteOnFetchRejection,
13051
- allowStaleOnFetchRejection,
13052
- allowStaleOnFetchAbort,
13053
- ignoreFetchAbort,
13054
- status,
13055
- signal
13056
- };
13057
- let index = this.#keyMap.get(k);
13058
- if (index === undefined) {
13059
- if (status) status.fetch = 'miss';
13060
- const p = this.#backgroundFetch(k, index, options, context);
13061
- return p.__returned = p;
13062
- } else {
13063
- // in cache, maybe already fetching
13064
- const v = this.#valList[index];
13065
- if (this.#isBackgroundFetch(v)) {
13066
- const stale = allowStale && v.__staleWhileFetching !== undefined;
13067
- if (status) {
13068
- status.fetch = 'inflight';
13069
- if (stale) status.returnedStale = true;
13070
- }
13071
- return stale ? v.__staleWhileFetching : v.__returned = v;
13072
- }
13073
- // if we force a refresh, that means do NOT serve the cached value,
13074
- // unless we are already in the process of refreshing the cache.
13075
- const isStale = this.#isStale(index);
13076
- if (!forceRefresh && !isStale) {
13077
- if (status) status.fetch = 'hit';
13078
- this.#moveToTail(index);
13079
- if (updateAgeOnGet) {
13080
- this.#updateItemAge(index);
13081
- }
13082
- if (status) this.#statusTTL(status, index);
13083
- return v;
13084
- }
13085
- // ok, it is stale or a forced refresh, and not already fetching.
13086
- // refresh the cache.
13087
- const p = this.#backgroundFetch(k, index, options, context);
13088
- const hasStale = p.__staleWhileFetching !== undefined;
13089
- const staleVal = hasStale && allowStale;
13090
- if (status) {
13091
- status.fetch = isStale ? 'stale' : 'refresh';
13092
- if (staleVal && isStale) status.returnedStale = true;
13093
- }
13094
- return staleVal ? p.__staleWhileFetching : p.__returned = p;
13095
- }
13096
- }
13097
- async forceFetch(k, fetchOptions = {}) {
13098
- const v = await this.fetch(k, fetchOptions);
13099
- if (v === undefined) throw new Error('fetch() returned undefined');
13100
- return v;
13101
- }
13102
- memo(k, memoOptions = {}) {
13103
- const memoMethod = this.#memoMethod;
13104
- if (!memoMethod) {
13105
- throw new Error('no memoMethod provided to constructor');
13106
- }
13107
- const { context, forceRefresh, ...options } = memoOptions;
13108
- const v = this.get(k, options);
13109
- if (!forceRefresh && v !== undefined) return v;
13110
- const vv = memoMethod(k, v, {
13111
- options,
13112
- context
11629
+ }
11630
+ async forceFetch(t, e = {}) {
11631
+ let i = await this.fetch(t, e);
11632
+ if (i === void 0) throw new Error("fetch() returned undefined");
11633
+ return i;
11634
+ }
11635
+ memo(t, e = {}) {
11636
+ let i = this.#U;
11637
+ if (!i) throw new Error("no memoMethod provided to constructor");
11638
+ let { context: s, forceRefresh: n, ...o } = e, h = this.get(t, o);
11639
+ if (!n && h !== void 0) return h;
11640
+ let r = i(t, h, {
11641
+ options: o,
11642
+ context: s
13113
11643
  });
13114
- this.set(k, vv, options);
13115
- return vv;
11644
+ return this.set(t, r, o), r;
13116
11645
  }
13117
- /**
13118
- * Return a value from the cache. Will update the recency of the cache
13119
- * entry found.
13120
- *
13121
- * If the key is not found, get() will return `undefined`.
13122
- */ get(k, getOptions = {}) {
13123
- const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
13124
- const index = this.#keyMap.get(k);
13125
- if (index !== undefined) {
13126
- const value = this.#valList[index];
13127
- const fetching = this.#isBackgroundFetch(value);
13128
- if (status) this.#statusTTL(status, index);
13129
- if (this.#isStale(index)) {
13130
- if (status) status.get = 'stale';
13131
- // delete only if not an in-flight background fetch
13132
- if (!fetching) {
13133
- if (!noDeleteOnStaleGet) {
13134
- this.#delete(k, 'expire');
13135
- }
13136
- if (status && allowStale) status.returnedStale = true;
13137
- return allowStale ? value : undefined;
13138
- } else {
13139
- if (status && allowStale && value.__staleWhileFetching !== undefined) {
13140
- status.returnedStale = true;
13141
- }
13142
- return allowStale ? value.__staleWhileFetching : undefined;
13143
- }
13144
- } else {
13145
- if (status) status.get = 'hit';
13146
- // if we're currently fetching it, we don't actually have it yet
13147
- // it's not stale, which means this isn't a staleWhileRefetching.
13148
- // If it's not stale, and fetching, AND has a __staleWhileFetching
13149
- // value, then that means the user fetched with {forceRefresh:true},
13150
- // so it's safe to return that value.
13151
- if (fetching) {
13152
- return value.__staleWhileFetching;
13153
- }
13154
- this.#moveToTail(index);
13155
- if (updateAgeOnGet) {
13156
- this.#updateItemAge(index);
13157
- }
13158
- return value;
13159
- }
13160
- } else if (status) {
13161
- status.get = 'miss';
13162
- }
13163
- }
13164
- #connect(p, n) {
13165
- this.#prev[n] = p;
13166
- this.#next[p] = n;
13167
- }
13168
- #moveToTail(index) {
13169
- // if tail already, nothing to do
13170
- // if head, move head to next[index]
13171
- // else
13172
- // move next[prev[index]] to next[index] (head has no prev)
13173
- // move prev[next[index]] to prev[index]
13174
- // prev[index] = tail
13175
- // next[tail] = index
13176
- // tail = index
13177
- if (index !== this.#tail) {
13178
- if (index === this.#head) {
13179
- this.#head = this.#next[index];
13180
- } else {
13181
- this.#connect(this.#prev[index], this.#next[index]);
13182
- }
13183
- this.#connect(this.#tail, index);
13184
- this.#tail = index;
13185
- }
11646
+ get(t, e = {}) {
11647
+ let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = e, h = this.#s.get(t);
11648
+ if (h !== void 0) {
11649
+ let r = this.#t[h], a = this.#e(r);
11650
+ return o && this.#z(o, h), this.#p(h) ? (o && (o.get = "stale"), a ? (o && i && r.__staleWhileFetching !== void 0 && (o.returnedStale = true), i ? r.__staleWhileFetching : void 0) : (n || this.#E(t, "expire"), o && i && (o.returnedStale = true), i ? r : void 0)) : (o && (o.get = "hit"), a ? r.__staleWhileFetching : (this.#D(h), s && this.#R(h), r));
11651
+ } else o && (o.get = "miss");
13186
11652
  }
13187
- /**
13188
- * Deletes a key out of the cache.
13189
- *
13190
- * Returns true if the key was deleted, false otherwise.
13191
- */ delete(k) {
13192
- return this.#delete(k, 'delete');
13193
- }
13194
- #delete(k, reason) {
13195
- let deleted = false;
13196
- if (this.#size !== 0) {
13197
- const index = this.#keyMap.get(k);
13198
- if (index !== undefined) {
13199
- deleted = true;
13200
- if (this.#size === 1) {
13201
- this.#clear(reason);
13202
- } else {
13203
- this.#removeItemSize(index);
13204
- const v = this.#valList[index];
13205
- if (this.#isBackgroundFetch(v)) {
13206
- v.__abortController.abort(new Error('deleted'));
13207
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
13208
- if (this.#hasDispose) {
13209
- this.#dispose?.(v, k, reason);
13210
- }
13211
- if (this.#hasDisposeAfter) {
13212
- this.#disposed?.push([
13213
- v,
13214
- k,
13215
- reason
13216
- ]);
13217
- }
13218
- }
13219
- this.#keyMap.delete(k);
13220
- this.#keyList[index] = undefined;
13221
- this.#valList[index] = undefined;
13222
- if (index === this.#tail) {
13223
- this.#tail = this.#prev[index];
13224
- } else if (index === this.#head) {
13225
- this.#head = this.#next[index];
13226
- } else {
13227
- const pi = this.#prev[index];
13228
- this.#next[pi] = this.#next[index];
13229
- const ni = this.#next[index];
13230
- this.#prev[ni] = this.#prev[index];
13231
- }
13232
- this.#size--;
13233
- this.#free.push(index);
11653
+ #k(t, e) {
11654
+ this.#u[e] = t, this.#a[t] = e;
11655
+ }
11656
+ #D(t) {
11657
+ t !== this.#h && (t === this.#l ? this.#l = this.#a[t] : this.#k(this.#u[t], this.#a[t]), this.#k(this.#h, t), this.#h = t);
11658
+ }
11659
+ delete(t) {
11660
+ return this.#E(t, "delete");
11661
+ }
11662
+ #E(t, e) {
11663
+ let i = false;
11664
+ if (this.#n !== 0) {
11665
+ let s = this.#s.get(t);
11666
+ if (s !== void 0) if (this.#g?.[s] && (clearTimeout(this.#g?.[s]), this.#g[s] = void 0), i = true, this.#n === 1) this.#V(e);
11667
+ else {
11668
+ this.#W(s);
11669
+ let n = this.#t[s];
11670
+ if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, t, e), this.#f && this.#r?.push([
11671
+ n,
11672
+ t,
11673
+ e
11674
+ ])), this.#s.delete(t), this.#i[s] = void 0, this.#t[s] = void 0, s === this.#h) this.#h = this.#u[s];
11675
+ else if (s === this.#l) this.#l = this.#a[s];
11676
+ else {
11677
+ let o = this.#u[s];
11678
+ this.#a[o] = this.#a[s];
11679
+ let h = this.#a[s];
11680
+ this.#u[h] = this.#u[s];
13234
11681
  }
11682
+ this.#n--, this.#b.push(s);
13235
11683
  }
13236
11684
  }
13237
- if (this.#hasDisposeAfter && this.#disposed?.length) {
13238
- const dt = this.#disposed;
13239
- let task;
13240
- while(task = dt?.shift()){
13241
- this.#disposeAfter?.(...task);
13242
- }
11685
+ if (this.#f && this.#r?.length) {
11686
+ let s = this.#r, n;
11687
+ for(; n = s?.shift();)this.#S?.(...n);
13243
11688
  }
13244
- return deleted;
11689
+ return i;
13245
11690
  }
13246
- /**
13247
- * Clear the cache entirely, throwing away all values.
13248
- */ clear() {
13249
- return this.#clear('delete');
11691
+ clear() {
11692
+ return this.#V("delete");
13250
11693
  }
13251
- #clear(reason) {
13252
- for (const index of this.#rindexes({
11694
+ #V(t) {
11695
+ for (let e of this.#O({
13253
11696
  allowStale: true
13254
11697
  })){
13255
- const v = this.#valList[index];
13256
- if (this.#isBackgroundFetch(v)) {
13257
- v.__abortController.abort(new Error('deleted'));
13258
- } else {
13259
- const k = this.#keyList[index];
13260
- if (this.#hasDispose) {
13261
- this.#dispose?.(v, k, reason);
13262
- }
13263
- if (this.#hasDisposeAfter) {
13264
- this.#disposed?.push([
13265
- v,
13266
- k,
13267
- reason
13268
- ]);
13269
- }
11698
+ let i = this.#t[e];
11699
+ if (this.#e(i)) i.__abortController.abort(new Error("deleted"));
11700
+ else {
11701
+ let s = this.#i[e];
11702
+ this.#T && this.#w?.(i, s, t), this.#f && this.#r?.push([
11703
+ i,
11704
+ s,
11705
+ t
11706
+ ]);
13270
11707
  }
13271
11708
  }
13272
- this.#keyMap.clear();
13273
- this.#valList.fill(undefined);
13274
- this.#keyList.fill(undefined);
13275
- if (this.#ttls && this.#starts) {
13276
- this.#ttls.fill(0);
13277
- this.#starts.fill(0);
13278
- }
13279
- if (this.#sizes) {
13280
- this.#sizes.fill(0);
11709
+ if (this.#s.clear(), this.#t.fill(void 0), this.#i.fill(void 0), this.#d && this.#A) {
11710
+ this.#d.fill(0), this.#A.fill(0);
11711
+ for (let e of this.#g ?? [])e !== void 0 && clearTimeout(e);
11712
+ this.#g?.fill(void 0);
13281
11713
  }
13282
- this.#head = 0;
13283
- this.#tail = 0;
13284
- this.#free.length = 0;
13285
- this.#calculatedSize = 0;
13286
- this.#size = 0;
13287
- if (this.#hasDisposeAfter && this.#disposed) {
13288
- const dt = this.#disposed;
13289
- let task;
13290
- while(task = dt?.shift()){
13291
- this.#disposeAfter?.(...task);
13292
- }
11714
+ if (this.#y && this.#y.fill(0), this.#l = 0, this.#h = 0, this.#b.length = 0, this.#_ = 0, this.#n = 0, this.#f && this.#r) {
11715
+ let e = this.#r, i;
11716
+ for(; i = e?.shift();)this.#S?.(...i);
13293
11717
  }
13294
11718
  }
13295
- }
13296
- commonjs.LRUCache = LRUCache;
11719
+ };
11720
+ index_min.LRUCache = D;
13297
11721
 
13298
- return commonjs;
11722
+ return index_min;
13299
11723
  }
13300
11724
 
13301
11725
  /* eslint-disable max-len */ var hosts_1;
@@ -13718,7 +12142,7 @@ var hasRequiredLib$2;
13718
12142
  function requireLib$2() {
13719
12143
  if (hasRequiredLib$2) return lib$2;
13720
12144
  hasRequiredLib$2 = 1;
13721
- const { LRUCache } = /*@__PURE__*/ requireCommonjs();
12145
+ const { LRUCache } = /*@__PURE__*/ requireIndex_min();
13722
12146
  const hosts = requireHosts();
13723
12147
  const fromUrl = requireFromUrl();
13724
12148
  const parseUrl = requireParseUrl();
@@ -19099,7 +17523,7 @@ const command$1 = {
19099
17523
  }
19100
17524
  };
19101
17525
 
19102
- var version = "3.0.8";
17526
+ var version = "3.0.9";
19103
17527
 
19104
17528
  var ajv = {exports: {}};
19105
17529
 
@@ -28108,39 +26532,39 @@ function requireLib() {
28108
26532
  const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/;
28109
26533
  const BRACKET = /^[()[\]{}]$/;
28110
26534
  let tokenize;
28111
- {
28112
- const JSX_TAG = /^[a-z][\w-]*$/i;
28113
- const getTokenType = function(token, offset, text) {
28114
- if (token.type === "name") {
28115
- if (helperValidatorIdentifier.isKeyword(token.value) || helperValidatorIdentifier.isStrictReservedWord(token.value, true) || sometimesKeywords.has(token.value)) {
28116
- return "keyword";
28117
- }
28118
- if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) {
28119
- return "jsxIdentifier";
28120
- }
28121
- if (token.value[0] !== token.value[0].toLowerCase()) {
28122
- return "capitalized";
28123
- }
26535
+ const JSX_TAG = /^[a-z][\w-]*$/i;
26536
+ const getTokenType = function(token, offset, text) {
26537
+ if (token.type === "name") {
26538
+ const tokenValue = token.value;
26539
+ if (helperValidatorIdentifier.isKeyword(tokenValue) || helperValidatorIdentifier.isStrictReservedWord(tokenValue, true) || sometimesKeywords.has(tokenValue)) {
26540
+ return "keyword";
28124
26541
  }
28125
- if (token.type === "punctuator" && BRACKET.test(token.value)) {
28126
- return "bracket";
26542
+ if (JSX_TAG.test(tokenValue) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) {
26543
+ return "jsxIdentifier";
28127
26544
  }
28128
- if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
28129
- return "punctuator";
28130
- }
28131
- return token.type;
28132
- };
28133
- tokenize = function*(text) {
28134
- let match;
28135
- while(match = jsTokens.default.exec(text)){
28136
- const token = jsTokens.matchToToken(match);
28137
- yield {
28138
- type: getTokenType(token, match.index, text),
28139
- value: token.value
28140
- };
26545
+ const firstChar = String.fromCodePoint(tokenValue.codePointAt(0));
26546
+ if (firstChar !== firstChar.toLowerCase()) {
26547
+ return "capitalized";
28141
26548
  }
28142
- };
28143
- }
26549
+ }
26550
+ if (token.type === "punctuator" && BRACKET.test(token.value)) {
26551
+ return "bracket";
26552
+ }
26553
+ if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
26554
+ return "punctuator";
26555
+ }
26556
+ return token.type;
26557
+ };
26558
+ tokenize = function*(text) {
26559
+ let match;
26560
+ while(match = jsTokens.default.exec(text)){
26561
+ const token = jsTokens.matchToToken(match);
26562
+ yield {
26563
+ type: getTokenType(token, match.index, text),
26564
+ value: token.value
26565
+ };
26566
+ }
26567
+ };
28144
26568
  function highlight(text) {
28145
26569
  if (text === "") return "";
28146
26570
  const defs = getDefs(true);
@@ -28156,16 +26580,16 @@ function requireLib() {
28156
26580
  }
28157
26581
  let deprecationWarningShown = false;
28158
26582
  const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
28159
- function getMarkerLines(loc, source, opts) {
26583
+ function getMarkerLines(loc, source, opts, startLineBaseZero) {
28160
26584
  const startLoc = Object.assign({
28161
26585
  column: 0,
28162
26586
  line: -1
28163
26587
  }, loc.start);
28164
26588
  const endLoc = Object.assign({}, startLoc, loc.end);
28165
26589
  const { linesAbove = 2, linesBelow = 3 } = opts || {};
28166
- const startLine = startLoc.line;
26590
+ const startLine = startLoc.line - startLineBaseZero;
28167
26591
  const startColumn = startLoc.column;
28168
- const endLine = endLoc.line;
26592
+ const endLine = endLoc.line - startLineBaseZero;
28169
26593
  const endColumn = endLoc.column;
28170
26594
  let start = Math.max(startLine - (linesAbove + 1), 0);
28171
26595
  let end = Math.min(source.length, endLine + linesBelow);
@@ -28226,15 +26650,16 @@ function requireLib() {
28226
26650
  }
28227
26651
  function codeFrameColumns(rawLines, loc, opts = {}) {
28228
26652
  const shouldHighlight = opts.forceColor || isColorSupported() && opts.highlightCode;
26653
+ const startLineBaseZero = (opts.startLine || 1) - 1;
28229
26654
  const defs = getDefs(shouldHighlight);
28230
26655
  const lines = rawLines.split(NEWLINE);
28231
- const { start, end, markerLines } = getMarkerLines(loc, lines, opts);
26656
+ const { start, end, markerLines } = getMarkerLines(loc, lines, opts, startLineBaseZero);
28232
26657
  const hasColumns = loc.start && typeof loc.start.column === "number";
28233
- const numberMaxWidth = String(end).length;
26658
+ const numberMaxWidth = String(end + startLineBaseZero).length;
28234
26659
  const highlightedLines = shouldHighlight ? highlight(rawLines) : rawLines;
28235
26660
  let frame = highlightedLines.split(NEWLINE, end).slice(start, end).map((line, index)=>{
28236
26661
  const number = start + 1 + index;
28237
- const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
26662
+ const paddedNumber = ` ${number + startLineBaseZero}`.slice(-numberMaxWidth);
28238
26663
  const gutter = ` ${paddedNumber} |`;
28239
26664
  const hasMarker = markerLines[number];
28240
26665
  const lastMarkerLine = !markerLines[number + 1];