Upload folder using huggingface_hub (part 9)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/loupe/lib/promise.d.ts.map +1 -0
- node_modules/loupe/lib/promise.js +2 -0
- node_modules/loupe/lib/regexp.d.ts +3 -0
- node_modules/loupe/lib/regexp.d.ts.map +1 -0
- node_modules/loupe/lib/regexp.js +7 -0
- node_modules/loupe/lib/set.d.ts +3 -0
- node_modules/loupe/lib/set.d.ts.map +1 -0
- node_modules/loupe/lib/set.js +15 -0
- node_modules/loupe/lib/string.d.ts +3 -0
- node_modules/loupe/lib/string.d.ts.map +1 -0
- node_modules/loupe/lib/string.js +24 -0
- node_modules/loupe/lib/symbol.d.ts +2 -0
- node_modules/loupe/lib/symbol.d.ts.map +1 -0
- node_modules/loupe/lib/symbol.js +6 -0
- node_modules/loupe/lib/typedarray.d.ts +5 -0
- node_modules/loupe/lib/typedarray.d.ts.map +1 -0
- node_modules/loupe/lib/typedarray.js +38 -0
- node_modules/loupe/lib/types.d.ts +15 -0
- node_modules/loupe/lib/types.d.ts.map +1 -0
- node_modules/loupe/lib/types.js +1 -0
- node_modules/loupe/loupe.js +622 -0
- node_modules/loupe/package.json +73 -0
- node_modules/lru-cache/LICENSE.md +55 -0
- node_modules/lru-cache/README.md +469 -0
- node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.d.ts.map +1 -0
- node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.js.map +1 -0
- node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.d.ts +5 -0
- node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- node_modules/lru-cache/dist/commonjs/browser/index.d.ts +1400 -0
- node_modules/lru-cache/dist/commonjs/browser/index.d.ts.map +1 -0
- node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- node_modules/lru-cache/dist/commonjs/browser/index.js.map +0 -0
- node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- node_modules/lru-cache/dist/commonjs/browser/index.min.js.map +0 -0
- node_modules/lru-cache/dist/commonjs/browser/perf.d.ts +12 -0
- node_modules/lru-cache/dist/commonjs/browser/perf.d.ts.map +1 -0
- node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- node_modules/lru-cache/dist/commonjs/browser/perf.js.map +1 -0
- node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.cjs.map +1 -0
- node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
- node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- node_modules/lru-cache/dist/commonjs/index.d.ts +1400 -0
- node_modules/lru-cache/dist/commonjs/index.d.ts.map +1 -0
- node_modules/lru-cache/dist/commonjs/index.js +1726 -0
- node_modules/lru-cache/dist/commonjs/index.js.map +0 -0
- node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
- node_modules/lru-cache/dist/commonjs/index.min.js.map +0 -0
- node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.d.ts.map +1 -0
- node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.js.map +1 -0
node_modules/loupe/lib/promise.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,KAAK,eAAe,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAA;AAC5E,QAAA,MAAM,eAAe,EAAE,eAAoC,CAAA;AAC3D,eAAe,eAAe,CAAA"}
|
node_modules/loupe/lib/promise.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const getPromiseValue = () => 'Promise{…}';
|
| 2 |
+
export default getPromiseValue;
|
node_modules/loupe/lib/regexp.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Options } from './types.js';
|
| 2 |
+
export default function inspectRegExp(value: RegExp, options: Options): string;
|
| 3 |
+
//# sourceMappingURL=regexp.d.ts.map
|
node_modules/loupe/lib/regexp.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../src/regexp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAK7E"}
|
node_modules/loupe/lib/regexp.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { truncate } from './helpers.js';
|
| 2 |
+
export default function inspectRegExp(value, options) {
|
| 3 |
+
const flags = value.toString().split('/')[2];
|
| 4 |
+
const sourceLength = options.truncate - (2 + flags.length);
|
| 5 |
+
const source = value.source;
|
| 6 |
+
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, 'regexp');
|
| 7 |
+
}
|
node_modules/loupe/lib/set.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Options } from './types.js';
|
| 2 |
+
export default function inspectSet(set: Set<unknown>, options: Options): string;
|
| 3 |
+
//# sourceMappingURL=set.d.ts.map
|
node_modules/loupe/lib/set.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAWzC,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAI9E"}
|
node_modules/loupe/lib/set.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { inspectList } from './helpers.js';
|
| 2 |
+
// IE11 doesn't support `Array.from(set)`
|
| 3 |
+
function arrayFromSet(set) {
|
| 4 |
+
const values = [];
|
| 5 |
+
set.forEach(value => {
|
| 6 |
+
values.push(value);
|
| 7 |
+
});
|
| 8 |
+
return values;
|
| 9 |
+
}
|
| 10 |
+
export default function inspectSet(set, options) {
|
| 11 |
+
if (set.size === 0)
|
| 12 |
+
return 'Set{}';
|
| 13 |
+
options.truncate -= 7;
|
| 14 |
+
return `Set{ ${inspectList(arrayFromSet(set), options)} }`;
|
| 15 |
+
}
|
node_modules/loupe/lib/string.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Options } from './types.js';
|
| 2 |
+
export default function inspectString(string: string, options: Options): string;
|
| 3 |
+
//# sourceMappingURL=string.d.ts.map
|
node_modules/loupe/lib/string.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AA2BzC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAK9E"}
|
node_modules/loupe/lib/string.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { truncate } from './helpers.js';
|
| 2 |
+
const stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5" +
|
| 3 |
+
'\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]', 'g');
|
| 4 |
+
const escapeCharacters = {
|
| 5 |
+
'\b': '\\b',
|
| 6 |
+
'\t': '\\t',
|
| 7 |
+
'\n': '\\n',
|
| 8 |
+
'\f': '\\f',
|
| 9 |
+
'\r': '\\r',
|
| 10 |
+
"'": "\\'",
|
| 11 |
+
'\\': '\\\\',
|
| 12 |
+
};
|
| 13 |
+
const hex = 16;
|
| 14 |
+
const unicodeLength = 4;
|
| 15 |
+
function escape(char) {
|
| 16 |
+
return (escapeCharacters[char] ||
|
| 17 |
+
`\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}`);
|
| 18 |
+
}
|
| 19 |
+
export default function inspectString(string, options) {
|
| 20 |
+
if (stringEscapeChars.test(string)) {
|
| 21 |
+
string = string.replace(stringEscapeChars, escape);
|
| 22 |
+
}
|
| 23 |
+
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, 'string');
|
| 24 |
+
}
|
node_modules/loupe/lib/symbol.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function inspectSymbol(value: Symbol): string;
|
| 2 |
+
//# sourceMappingURL=symbol.d.ts.map
|
node_modules/loupe/lib/symbol.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"symbol.d.ts","sourceRoot":"","sources":["../src/symbol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3D"}
|
node_modules/loupe/lib/symbol.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function inspectSymbol(value) {
|
| 2 |
+
if ('description' in Symbol.prototype) {
|
| 3 |
+
return value.description ? `Symbol(${value.description})` : 'Symbol()';
|
| 4 |
+
}
|
| 5 |
+
return value.toString();
|
| 6 |
+
}
|
node_modules/loupe/lib/typedarray.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Options } from './types.js';
|
| 2 |
+
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
| 3 |
+
export default function inspectTypedArray(array: TypedArray, options: Options): string;
|
| 4 |
+
export {};
|
| 5 |
+
//# sourceMappingURL=typedarray.d.ts.map
|
node_modules/loupe/lib/typedarray.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"typedarray.d.ts","sourceRoot":"","sources":["../src/typedarray.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,YAAY,CAAA;AAElD,KAAK,UAAU,GACX,SAAS,GACT,UAAU,GACV,iBAAiB,GACjB,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,YAAY,GACZ,YAAY,CAAA;AAchB,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CA8BrF"}
|
node_modules/loupe/lib/typedarray.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { inspectList, inspectProperty, truncate, truncator } from './helpers.js';
|
| 2 |
+
const getArrayName = (array) => {
|
| 3 |
+
// We need to special case Node.js' Buffers, which report to be Uint8Array
|
| 4 |
+
// @ts-ignore
|
| 5 |
+
if (typeof Buffer === 'function' && array instanceof Buffer) {
|
| 6 |
+
return 'Buffer';
|
| 7 |
+
}
|
| 8 |
+
if (array[Symbol.toStringTag]) {
|
| 9 |
+
return array[Symbol.toStringTag];
|
| 10 |
+
}
|
| 11 |
+
return array.constructor.name;
|
| 12 |
+
};
|
| 13 |
+
export default function inspectTypedArray(array, options) {
|
| 14 |
+
const name = getArrayName(array);
|
| 15 |
+
options.truncate -= name.length + 4;
|
| 16 |
+
// Object.keys will always output the Array indices first, so we can slice by
|
| 17 |
+
// `array.length` to get non-index properties
|
| 18 |
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
| 19 |
+
if (!array.length && !nonIndexProperties.length)
|
| 20 |
+
return `${name}[]`;
|
| 21 |
+
// As we know TypedArrays only contain Unsigned Integers, we can skip inspecting each one and simply
|
| 22 |
+
// stylise the toString() value of them
|
| 23 |
+
let output = '';
|
| 24 |
+
for (let i = 0; i < array.length; i++) {
|
| 25 |
+
const string = `${options.stylize(truncate(array[i], options.truncate), 'number')}${i === array.length - 1 ? '' : ', '}`;
|
| 26 |
+
options.truncate -= string.length;
|
| 27 |
+
if (array[i] !== array.length && options.truncate <= 3) {
|
| 28 |
+
output += `${truncator}(${array.length - array[i] + 1})`;
|
| 29 |
+
break;
|
| 30 |
+
}
|
| 31 |
+
output += string;
|
| 32 |
+
}
|
| 33 |
+
let propertyContents = '';
|
| 34 |
+
if (nonIndexProperties.length) {
|
| 35 |
+
propertyContents = inspectList(nonIndexProperties.map(key => [key, array[key]]), options, inspectProperty);
|
| 36 |
+
}
|
| 37 |
+
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ''} ]`;
|
| 38 |
+
}
|
node_modules/loupe/lib/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type Inspect = (value: unknown, options: Options) => string;
|
| 2 |
+
export interface Options {
|
| 3 |
+
showHidden: boolean;
|
| 4 |
+
depth: number;
|
| 5 |
+
colors: boolean;
|
| 6 |
+
customInspect: boolean;
|
| 7 |
+
showProxy: boolean;
|
| 8 |
+
maxArrayLength: number;
|
| 9 |
+
breakLength: number;
|
| 10 |
+
truncate: number;
|
| 11 |
+
seen: unknown[];
|
| 12 |
+
inspect: Inspect;
|
| 13 |
+
stylize: (value: string, styleType: string) => string;
|
| 14 |
+
}
|
| 15 |
+
//# sourceMappingURL=types.d.ts.map
|
node_modules/loupe/lib/types.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAA;AAElE,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;IACf,aAAa,EAAE,OAAO,CAAA;IACtB,SAAS,EAAE,OAAO,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,OAAO,EAAE,CAAA;IACf,OAAO,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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __defProp = Object.defineProperty;
|
| 3 |
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
| 4 |
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
| 5 |
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
| 6 |
+
var __export = (target, all) => {
|
| 7 |
+
for (var name in all)
|
| 8 |
+
__defProp(target, name, { get: all[name], enumerable: true });
|
| 9 |
+
};
|
| 10 |
+
var __copyProps = (to, from, except, desc) => {
|
| 11 |
+
if (from && typeof from === "object" || typeof from === "function") {
|
| 12 |
+
for (let key of __getOwnPropNames(from))
|
| 13 |
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
| 14 |
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
| 15 |
+
}
|
| 16 |
+
return to;
|
| 17 |
+
};
|
| 18 |
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
| 19 |
+
|
| 20 |
+
// src/index.ts
|
| 21 |
+
var index_exports = {};
|
| 22 |
+
__export(index_exports, {
|
| 23 |
+
custom: () => custom,
|
| 24 |
+
default: () => index_default,
|
| 25 |
+
inspect: () => inspect,
|
| 26 |
+
registerConstructor: () => registerConstructor,
|
| 27 |
+
registerStringTag: () => registerStringTag
|
| 28 |
+
});
|
| 29 |
+
module.exports = __toCommonJS(index_exports);
|
| 30 |
+
|
| 31 |
+
// src/helpers.ts
|
| 32 |
+
var ansiColors = {
|
| 33 |
+
bold: ["1", "22"],
|
| 34 |
+
dim: ["2", "22"],
|
| 35 |
+
italic: ["3", "23"],
|
| 36 |
+
underline: ["4", "24"],
|
| 37 |
+
// 5 & 6 are blinking
|
| 38 |
+
inverse: ["7", "27"],
|
| 39 |
+
hidden: ["8", "28"],
|
| 40 |
+
strike: ["9", "29"],
|
| 41 |
+
// 10-20 are fonts
|
| 42 |
+
// 21-29 are resets for 1-9
|
| 43 |
+
black: ["30", "39"],
|
| 44 |
+
red: ["31", "39"],
|
| 45 |
+
green: ["32", "39"],
|
| 46 |
+
yellow: ["33", "39"],
|
| 47 |
+
blue: ["34", "39"],
|
| 48 |
+
magenta: ["35", "39"],
|
| 49 |
+
cyan: ["36", "39"],
|
| 50 |
+
white: ["37", "39"],
|
| 51 |
+
brightblack: ["30;1", "39"],
|
| 52 |
+
brightred: ["31;1", "39"],
|
| 53 |
+
brightgreen: ["32;1", "39"],
|
| 54 |
+
brightyellow: ["33;1", "39"],
|
| 55 |
+
brightblue: ["34;1", "39"],
|
| 56 |
+
brightmagenta: ["35;1", "39"],
|
| 57 |
+
brightcyan: ["36;1", "39"],
|
| 58 |
+
brightwhite: ["37;1", "39"],
|
| 59 |
+
grey: ["90", "39"]
|
| 60 |
+
};
|
| 61 |
+
var styles = {
|
| 62 |
+
special: "cyan",
|
| 63 |
+
number: "yellow",
|
| 64 |
+
bigint: "yellow",
|
| 65 |
+
boolean: "yellow",
|
| 66 |
+
undefined: "grey",
|
| 67 |
+
null: "bold",
|
| 68 |
+
string: "green",
|
| 69 |
+
symbol: "green",
|
| 70 |
+
date: "magenta",
|
| 71 |
+
regexp: "red"
|
| 72 |
+
};
|
| 73 |
+
var truncator = "\u2026";
|
| 74 |
+
function colorise(value, styleType) {
|
| 75 |
+
const color = ansiColors[styles[styleType]] || ansiColors[styleType] || "";
|
| 76 |
+
if (!color) {
|
| 77 |
+
return String(value);
|
| 78 |
+
}
|
| 79 |
+
return `\x1B[${color[0]}m${String(value)}\x1B[${color[1]}m`;
|
| 80 |
+
}
|
| 81 |
+
function normaliseOptions({
|
| 82 |
+
showHidden = false,
|
| 83 |
+
depth = 2,
|
| 84 |
+
colors = false,
|
| 85 |
+
customInspect = true,
|
| 86 |
+
showProxy = false,
|
| 87 |
+
maxArrayLength = Infinity,
|
| 88 |
+
breakLength = Infinity,
|
| 89 |
+
seen = [],
|
| 90 |
+
// eslint-disable-next-line no-shadow
|
| 91 |
+
truncate: truncate2 = Infinity,
|
| 92 |
+
stylize = String
|
| 93 |
+
} = {}, inspect2) {
|
| 94 |
+
const options = {
|
| 95 |
+
showHidden: Boolean(showHidden),
|
| 96 |
+
depth: Number(depth),
|
| 97 |
+
colors: Boolean(colors),
|
| 98 |
+
customInspect: Boolean(customInspect),
|
| 99 |
+
showProxy: Boolean(showProxy),
|
| 100 |
+
maxArrayLength: Number(maxArrayLength),
|
| 101 |
+
breakLength: Number(breakLength),
|
| 102 |
+
truncate: Number(truncate2),
|
| 103 |
+
seen,
|
| 104 |
+
inspect: inspect2,
|
| 105 |
+
stylize
|
| 106 |
+
};
|
| 107 |
+
if (options.colors) {
|
| 108 |
+
options.stylize = colorise;
|
| 109 |
+
}
|
| 110 |
+
return options;
|
| 111 |
+
}
|
| 112 |
+
function isHighSurrogate(char) {
|
| 113 |
+
return char >= "\uD800" && char <= "\uDBFF";
|
| 114 |
+
}
|
| 115 |
+
function truncate(string, length, tail = truncator) {
|
| 116 |
+
string = String(string);
|
| 117 |
+
const tailLength = tail.length;
|
| 118 |
+
const stringLength = string.length;
|
| 119 |
+
if (tailLength > length && stringLength > tailLength) {
|
| 120 |
+
return tail;
|
| 121 |
+
}
|
| 122 |
+
if (stringLength > length && stringLength > tailLength) {
|
| 123 |
+
let end = length - tailLength;
|
| 124 |
+
if (end > 0 && isHighSurrogate(string[end - 1])) {
|
| 125 |
+
end = end - 1;
|
| 126 |
+
}
|
| 127 |
+
return `${string.slice(0, end)}${tail}`;
|
| 128 |
+
}
|
| 129 |
+
return string;
|
| 130 |
+
}
|
| 131 |
+
function inspectList(list, options, inspectItem, separator = ", ") {
|
| 132 |
+
inspectItem = inspectItem || options.inspect;
|
| 133 |
+
const size = list.length;
|
| 134 |
+
if (size === 0) return "";
|
| 135 |
+
const originalLength = options.truncate;
|
| 136 |
+
let output = "";
|
| 137 |
+
let peek = "";
|
| 138 |
+
let truncated = "";
|
| 139 |
+
for (let i = 0; i < size; i += 1) {
|
| 140 |
+
const last = i + 1 === list.length;
|
| 141 |
+
const secondToLast = i + 2 === list.length;
|
| 142 |
+
truncated = `${truncator}(${list.length - i})`;
|
| 143 |
+
const value = list[i];
|
| 144 |
+
options.truncate = originalLength - output.length - (last ? 0 : separator.length);
|
| 145 |
+
const string = peek || inspectItem(value, options) + (last ? "" : separator);
|
| 146 |
+
const nextLength = output.length + string.length;
|
| 147 |
+
const truncatedLength = nextLength + truncated.length;
|
| 148 |
+
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
|
| 149 |
+
break;
|
| 150 |
+
}
|
| 151 |
+
if (!last && !secondToLast && truncatedLength > originalLength) {
|
| 152 |
+
break;
|
| 153 |
+
}
|
| 154 |
+
peek = last ? "" : inspectItem(list[i + 1], options) + (secondToLast ? "" : separator);
|
| 155 |
+
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
|
| 156 |
+
break;
|
| 157 |
+
}
|
| 158 |
+
output += string;
|
| 159 |
+
if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
|
| 160 |
+
truncated = `${truncator}(${list.length - i - 1})`;
|
| 161 |
+
break;
|
| 162 |
+
}
|
| 163 |
+
truncated = "";
|
| 164 |
+
}
|
| 165 |
+
return `${output}${truncated}`;
|
| 166 |
+
}
|
| 167 |
+
function quoteComplexKey(key) {
|
| 168 |
+
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) {
|
| 169 |
+
return key;
|
| 170 |
+
}
|
| 171 |
+
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
|
| 172 |
+
}
|
| 173 |
+
function inspectProperty([key, value], options) {
|
| 174 |
+
options.truncate -= 2;
|
| 175 |
+
if (typeof key === "string") {
|
| 176 |
+
key = quoteComplexKey(key);
|
| 177 |
+
} else if (typeof key !== "number") {
|
| 178 |
+
key = `[${options.inspect(key, options)}]`;
|
| 179 |
+
}
|
| 180 |
+
options.truncate -= key.length;
|
| 181 |
+
value = options.inspect(value, options);
|
| 182 |
+
return `${key}: ${value}`;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// src/array.ts
|
| 186 |
+
function inspectArray(array, options) {
|
| 187 |
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
| 188 |
+
if (!array.length && !nonIndexProperties.length) return "[]";
|
| 189 |
+
options.truncate -= 4;
|
| 190 |
+
const listContents = inspectList(array, options);
|
| 191 |
+
options.truncate -= listContents.length;
|
| 192 |
+
let propertyContents = "";
|
| 193 |
+
if (nonIndexProperties.length) {
|
| 194 |
+
propertyContents = inspectList(
|
| 195 |
+
nonIndexProperties.map((key) => [key, array[key]]),
|
| 196 |
+
options,
|
| 197 |
+
inspectProperty
|
| 198 |
+
);
|
| 199 |
+
}
|
| 200 |
+
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ""} ]`;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
// src/typedarray.ts
|
| 204 |
+
var getArrayName = (array) => {
|
| 205 |
+
if (typeof Buffer === "function" && array instanceof Buffer) {
|
| 206 |
+
return "Buffer";
|
| 207 |
+
}
|
| 208 |
+
if (array[Symbol.toStringTag]) {
|
| 209 |
+
return array[Symbol.toStringTag];
|
| 210 |
+
}
|
| 211 |
+
return array.constructor.name;
|
| 212 |
+
};
|
| 213 |
+
function inspectTypedArray(array, options) {
|
| 214 |
+
const name = getArrayName(array);
|
| 215 |
+
options.truncate -= name.length + 4;
|
| 216 |
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
| 217 |
+
if (!array.length && !nonIndexProperties.length) return `${name}[]`;
|
| 218 |
+
let output = "";
|
| 219 |
+
for (let i = 0; i < array.length; i++) {
|
| 220 |
+
const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`;
|
| 221 |
+
options.truncate -= string.length;
|
| 222 |
+
if (array[i] !== array.length && options.truncate <= 3) {
|
| 223 |
+
output += `${truncator}(${array.length - array[i] + 1})`;
|
| 224 |
+
break;
|
| 225 |
+
}
|
| 226 |
+
output += string;
|
| 227 |
+
}
|
| 228 |
+
let propertyContents = "";
|
| 229 |
+
if (nonIndexProperties.length) {
|
| 230 |
+
propertyContents = inspectList(
|
| 231 |
+
nonIndexProperties.map((key) => [key, array[key]]),
|
| 232 |
+
options,
|
| 233 |
+
inspectProperty
|
| 234 |
+
);
|
| 235 |
+
}
|
| 236 |
+
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// src/date.ts
|
| 240 |
+
function inspectDate(dateObject, options) {
|
| 241 |
+
const stringRepresentation = dateObject.toJSON();
|
| 242 |
+
if (stringRepresentation === null) {
|
| 243 |
+
return "Invalid Date";
|
| 244 |
+
}
|
| 245 |
+
const split = stringRepresentation.split("T");
|
| 246 |
+
const date = split[0];
|
| 247 |
+
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date");
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
// src/function.ts
|
| 251 |
+
function inspectFunction(func, options) {
|
| 252 |
+
const functionType = func[Symbol.toStringTag] || "Function";
|
| 253 |
+
const name = func.name;
|
| 254 |
+
if (!name) {
|
| 255 |
+
return options.stylize(`[${functionType}]`, "special");
|
| 256 |
+
}
|
| 257 |
+
return options.stylize(`[${functionType} ${truncate(name, options.truncate - 11)}]`, "special");
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// src/map.ts
|
| 261 |
+
function inspectMapEntry([key, value], options) {
|
| 262 |
+
options.truncate -= 4;
|
| 263 |
+
key = options.inspect(key, options);
|
| 264 |
+
options.truncate -= key.length;
|
| 265 |
+
value = options.inspect(value, options);
|
| 266 |
+
return `${key} => ${value}`;
|
| 267 |
+
}
|
| 268 |
+
function mapToEntries(map) {
|
| 269 |
+
const entries = [];
|
| 270 |
+
map.forEach((value, key) => {
|
| 271 |
+
entries.push([key, value]);
|
| 272 |
+
});
|
| 273 |
+
return entries;
|
| 274 |
+
}
|
| 275 |
+
function inspectMap(map, options) {
|
| 276 |
+
if (map.size === 0) return "Map{}";
|
| 277 |
+
options.truncate -= 7;
|
| 278 |
+
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
// src/number.ts
|
| 282 |
+
var isNaN = Number.isNaN || ((i) => i !== i);
|
| 283 |
+
function inspectNumber(number, options) {
|
| 284 |
+
if (isNaN(number)) {
|
| 285 |
+
return options.stylize("NaN", "number");
|
| 286 |
+
}
|
| 287 |
+
if (number === Infinity) {
|
| 288 |
+
return options.stylize("Infinity", "number");
|
| 289 |
+
}
|
| 290 |
+
if (number === -Infinity) {
|
| 291 |
+
return options.stylize("-Infinity", "number");
|
| 292 |
+
}
|
| 293 |
+
if (number === 0) {
|
| 294 |
+
return options.stylize(1 / number === Infinity ? "+0" : "-0", "number");
|
| 295 |
+
}
|
| 296 |
+
return options.stylize(truncate(String(number), options.truncate), "number");
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// src/bigint.ts
|
| 300 |
+
function inspectBigInt(number, options) {
|
| 301 |
+
let nums = truncate(number.toString(), options.truncate - 1);
|
| 302 |
+
if (nums !== truncator) nums += "n";
|
| 303 |
+
return options.stylize(nums, "bigint");
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
// src/regexp.ts
|
| 307 |
+
function inspectRegExp(value, options) {
|
| 308 |
+
const flags = value.toString().split("/")[2];
|
| 309 |
+
const sourceLength = options.truncate - (2 + flags.length);
|
| 310 |
+
const source = value.source;
|
| 311 |
+
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, "regexp");
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
// src/set.ts
|
| 315 |
+
function arrayFromSet(set) {
|
| 316 |
+
const values = [];
|
| 317 |
+
set.forEach((value) => {
|
| 318 |
+
values.push(value);
|
| 319 |
+
});
|
| 320 |
+
return values;
|
| 321 |
+
}
|
| 322 |
+
function inspectSet(set, options) {
|
| 323 |
+
if (set.size === 0) return "Set{}";
|
| 324 |
+
options.truncate -= 7;
|
| 325 |
+
return `Set{ ${inspectList(arrayFromSet(set), options)} }`;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// src/string.ts
|
| 329 |
+
var stringEscapeChars = new RegExp(
|
| 330 |
+
"['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]",
|
| 331 |
+
"g"
|
| 332 |
+
);
|
| 333 |
+
var escapeCharacters = {
|
| 334 |
+
"\b": "\\b",
|
| 335 |
+
" ": "\\t",
|
| 336 |
+
"\n": "\\n",
|
| 337 |
+
"\f": "\\f",
|
| 338 |
+
"\r": "\\r",
|
| 339 |
+
"'": "\\'",
|
| 340 |
+
"\\": "\\\\"
|
| 341 |
+
};
|
| 342 |
+
var hex = 16;
|
| 343 |
+
var unicodeLength = 4;
|
| 344 |
+
function escape(char) {
|
| 345 |
+
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}`;
|
| 346 |
+
}
|
| 347 |
+
function inspectString(string, options) {
|
| 348 |
+
if (stringEscapeChars.test(string)) {
|
| 349 |
+
string = string.replace(stringEscapeChars, escape);
|
| 350 |
+
}
|
| 351 |
+
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, "string");
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
// src/symbol.ts
|
| 355 |
+
function inspectSymbol(value) {
|
| 356 |
+
if ("description" in Symbol.prototype) {
|
| 357 |
+
return value.description ? `Symbol(${value.description})` : "Symbol()";
|
| 358 |
+
}
|
| 359 |
+
return value.toString();
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
// src/promise.ts
|
| 363 |
+
var getPromiseValue = () => "Promise{\u2026}";
|
| 364 |
+
var promise_default = getPromiseValue;
|
| 365 |
+
|
| 366 |
+
// src/object.ts
|
| 367 |
+
function inspectObject(object, options) {
|
| 368 |
+
const properties = Object.getOwnPropertyNames(object);
|
| 369 |
+
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
|
| 370 |
+
if (properties.length === 0 && symbols.length === 0) {
|
| 371 |
+
return "{}";
|
| 372 |
+
}
|
| 373 |
+
options.truncate -= 4;
|
| 374 |
+
options.seen = options.seen || [];
|
| 375 |
+
if (options.seen.includes(object)) {
|
| 376 |
+
return "[Circular]";
|
| 377 |
+
}
|
| 378 |
+
options.seen.push(object);
|
| 379 |
+
const propertyContents = inspectList(
|
| 380 |
+
properties.map((key) => [key, object[key]]),
|
| 381 |
+
options,
|
| 382 |
+
inspectProperty
|
| 383 |
+
);
|
| 384 |
+
const symbolContents = inspectList(
|
| 385 |
+
symbols.map((key) => [key, object[key]]),
|
| 386 |
+
options,
|
| 387 |
+
inspectProperty
|
| 388 |
+
);
|
| 389 |
+
options.seen.pop();
|
| 390 |
+
let sep = "";
|
| 391 |
+
if (propertyContents && symbolContents) {
|
| 392 |
+
sep = ", ";
|
| 393 |
+
}
|
| 394 |
+
return `{ ${propertyContents}${sep}${symbolContents} }`;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
// src/class.ts
|
| 398 |
+
var toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag ? Symbol.toStringTag : false;
|
| 399 |
+
function inspectClass(value, options) {
|
| 400 |
+
let name = "";
|
| 401 |
+
if (toStringTag && toStringTag in value) {
|
| 402 |
+
name = value[toStringTag];
|
| 403 |
+
}
|
| 404 |
+
name = name || value.constructor.name;
|
| 405 |
+
if (!name || name === "_class") {
|
| 406 |
+
name = "<Anonymous Class>";
|
| 407 |
+
}
|
| 408 |
+
options.truncate -= name.length;
|
| 409 |
+
return `${name}${inspectObject(value, options)}`;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// src/arguments.ts
|
| 413 |
+
function inspectArguments(args, options) {
|
| 414 |
+
if (args.length === 0) return "Arguments[]";
|
| 415 |
+
options.truncate -= 13;
|
| 416 |
+
return `Arguments[ ${inspectList(args, options)} ]`;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// src/error.ts
|
| 420 |
+
var errorKeys = [
|
| 421 |
+
"stack",
|
| 422 |
+
"line",
|
| 423 |
+
"column",
|
| 424 |
+
"name",
|
| 425 |
+
"message",
|
| 426 |
+
"fileName",
|
| 427 |
+
"lineNumber",
|
| 428 |
+
"columnNumber",
|
| 429 |
+
"number",
|
| 430 |
+
"description",
|
| 431 |
+
"cause"
|
| 432 |
+
];
|
| 433 |
+
function inspectObject2(error, options) {
|
| 434 |
+
const properties = Object.getOwnPropertyNames(error).filter((key) => errorKeys.indexOf(key) === -1);
|
| 435 |
+
const name = error.name;
|
| 436 |
+
options.truncate -= name.length;
|
| 437 |
+
let message = "";
|
| 438 |
+
if (typeof error.message === "string") {
|
| 439 |
+
message = truncate(error.message, options.truncate);
|
| 440 |
+
} else {
|
| 441 |
+
properties.unshift("message");
|
| 442 |
+
}
|
| 443 |
+
message = message ? `: ${message}` : "";
|
| 444 |
+
options.truncate -= message.length + 5;
|
| 445 |
+
options.seen = options.seen || [];
|
| 446 |
+
if (options.seen.includes(error)) {
|
| 447 |
+
return "[Circular]";
|
| 448 |
+
}
|
| 449 |
+
options.seen.push(error);
|
| 450 |
+
const propertyContents = inspectList(
|
| 451 |
+
properties.map((key) => [key, error[key]]),
|
| 452 |
+
options,
|
| 453 |
+
inspectProperty
|
| 454 |
+
);
|
| 455 |
+
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
// src/html.ts
|
| 459 |
+
function inspectAttribute([key, value], options) {
|
| 460 |
+
options.truncate -= 3;
|
| 461 |
+
if (!value) {
|
| 462 |
+
return `${options.stylize(String(key), "yellow")}`;
|
| 463 |
+
}
|
| 464 |
+
return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`;
|
| 465 |
+
}
|
| 466 |
+
function inspectNodeCollection(collection, options) {
|
| 467 |
+
return inspectList(collection, options, inspectNode, "\n");
|
| 468 |
+
}
|
| 469 |
+
function inspectNode(node, options) {
|
| 470 |
+
switch (node.nodeType) {
|
| 471 |
+
case 1:
|
| 472 |
+
return inspectHTML(node, options);
|
| 473 |
+
case 3:
|
| 474 |
+
return options.inspect(node.data, options);
|
| 475 |
+
default:
|
| 476 |
+
return options.inspect(node, options);
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
function inspectHTML(element, options) {
|
| 480 |
+
const properties = element.getAttributeNames();
|
| 481 |
+
const name = element.tagName.toLowerCase();
|
| 482 |
+
const head = options.stylize(`<${name}`, "special");
|
| 483 |
+
const headClose = options.stylize(`>`, "special");
|
| 484 |
+
const tail = options.stylize(`</${name}>`, "special");
|
| 485 |
+
options.truncate -= name.length * 2 + 5;
|
| 486 |
+
let propertyContents = "";
|
| 487 |
+
if (properties.length > 0) {
|
| 488 |
+
propertyContents += " ";
|
| 489 |
+
propertyContents += inspectList(
|
| 490 |
+
properties.map((key) => [key, element.getAttribute(key)]),
|
| 491 |
+
options,
|
| 492 |
+
inspectAttribute,
|
| 493 |
+
" "
|
| 494 |
+
);
|
| 495 |
+
}
|
| 496 |
+
options.truncate -= propertyContents.length;
|
| 497 |
+
const truncate2 = options.truncate;
|
| 498 |
+
let children = inspectNodeCollection(element.children, options);
|
| 499 |
+
if (children && children.length > truncate2) {
|
| 500 |
+
children = `${truncator}(${element.children.length})`;
|
| 501 |
+
}
|
| 502 |
+
return `${head}${propertyContents}${headClose}${children}${tail}`;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
// src/index.ts
|
| 506 |
+
var symbolsSupported = typeof Symbol === "function" && typeof Symbol.for === "function";
|
| 507 |
+
var chaiInspect = symbolsSupported ? Symbol.for("chai/inspect") : "@@chai/inspect";
|
| 508 |
+
var nodeInspect = Symbol.for("nodejs.util.inspect.custom");
|
| 509 |
+
var constructorMap = /* @__PURE__ */ new WeakMap();
|
| 510 |
+
var stringTagMap = {};
|
| 511 |
+
var baseTypesMap = {
|
| 512 |
+
undefined: (value, options) => options.stylize("undefined", "undefined"),
|
| 513 |
+
null: (value, options) => options.stylize("null", "null"),
|
| 514 |
+
boolean: (value, options) => options.stylize(String(value), "boolean"),
|
| 515 |
+
Boolean: (value, options) => options.stylize(String(value), "boolean"),
|
| 516 |
+
number: inspectNumber,
|
| 517 |
+
Number: inspectNumber,
|
| 518 |
+
bigint: inspectBigInt,
|
| 519 |
+
BigInt: inspectBigInt,
|
| 520 |
+
string: inspectString,
|
| 521 |
+
String: inspectString,
|
| 522 |
+
function: inspectFunction,
|
| 523 |
+
Function: inspectFunction,
|
| 524 |
+
symbol: inspectSymbol,
|
| 525 |
+
// A Symbol polyfill will return `Symbol` not `symbol` from typedetect
|
| 526 |
+
Symbol: inspectSymbol,
|
| 527 |
+
Array: inspectArray,
|
| 528 |
+
Date: inspectDate,
|
| 529 |
+
Map: inspectMap,
|
| 530 |
+
Set: inspectSet,
|
| 531 |
+
RegExp: inspectRegExp,
|
| 532 |
+
Promise: promise_default,
|
| 533 |
+
// WeakSet, WeakMap are totally opaque to us
|
| 534 |
+
WeakSet: (value, options) => options.stylize("WeakSet{\u2026}", "special"),
|
| 535 |
+
WeakMap: (value, options) => options.stylize("WeakMap{\u2026}", "special"),
|
| 536 |
+
Arguments: inspectArguments,
|
| 537 |
+
Int8Array: inspectTypedArray,
|
| 538 |
+
Uint8Array: inspectTypedArray,
|
| 539 |
+
Uint8ClampedArray: inspectTypedArray,
|
| 540 |
+
Int16Array: inspectTypedArray,
|
| 541 |
+
Uint16Array: inspectTypedArray,
|
| 542 |
+
Int32Array: inspectTypedArray,
|
| 543 |
+
Uint32Array: inspectTypedArray,
|
| 544 |
+
Float32Array: inspectTypedArray,
|
| 545 |
+
Float64Array: inspectTypedArray,
|
| 546 |
+
Generator: () => "",
|
| 547 |
+
DataView: () => "",
|
| 548 |
+
ArrayBuffer: () => "",
|
| 549 |
+
Error: inspectObject2,
|
| 550 |
+
HTMLCollection: inspectNodeCollection,
|
| 551 |
+
NodeList: inspectNodeCollection
|
| 552 |
+
};
|
| 553 |
+
var inspectCustom = (value, options, type, inspectFn) => {
|
| 554 |
+
if (chaiInspect in value && typeof value[chaiInspect] === "function") {
|
| 555 |
+
return value[chaiInspect](options);
|
| 556 |
+
}
|
| 557 |
+
if (nodeInspect in value && typeof value[nodeInspect] === "function") {
|
| 558 |
+
return value[nodeInspect](options.depth, options, inspectFn);
|
| 559 |
+
}
|
| 560 |
+
if ("inspect" in value && typeof value.inspect === "function") {
|
| 561 |
+
return value.inspect(options.depth, options);
|
| 562 |
+
}
|
| 563 |
+
if ("constructor" in value && constructorMap.has(value.constructor)) {
|
| 564 |
+
return constructorMap.get(value.constructor)(value, options);
|
| 565 |
+
}
|
| 566 |
+
if (stringTagMap[type]) {
|
| 567 |
+
return stringTagMap[type](value, options);
|
| 568 |
+
}
|
| 569 |
+
return "";
|
| 570 |
+
};
|
| 571 |
+
var toString = Object.prototype.toString;
|
| 572 |
+
function inspect(value, opts = {}) {
|
| 573 |
+
const options = normaliseOptions(opts, inspect);
|
| 574 |
+
const { customInspect } = options;
|
| 575 |
+
let type = value === null ? "null" : typeof value;
|
| 576 |
+
if (type === "object") {
|
| 577 |
+
type = toString.call(value).slice(8, -1);
|
| 578 |
+
}
|
| 579 |
+
if (type in baseTypesMap) {
|
| 580 |
+
return baseTypesMap[type](value, options);
|
| 581 |
+
}
|
| 582 |
+
if (customInspect && value) {
|
| 583 |
+
const output = inspectCustom(value, options, type, inspect);
|
| 584 |
+
if (output) {
|
| 585 |
+
if (typeof output === "string") return output;
|
| 586 |
+
return inspect(output, options);
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
const proto = value ? Object.getPrototypeOf(value) : false;
|
| 590 |
+
if (proto === Object.prototype || proto === null) {
|
| 591 |
+
return inspectObject(value, options);
|
| 592 |
+
}
|
| 593 |
+
if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) {
|
| 594 |
+
return inspectHTML(value, options);
|
| 595 |
+
}
|
| 596 |
+
if ("constructor" in value) {
|
| 597 |
+
if (value.constructor !== Object) {
|
| 598 |
+
return inspectClass(value, options);
|
| 599 |
+
}
|
| 600 |
+
return inspectObject(value, options);
|
| 601 |
+
}
|
| 602 |
+
if (value === Object(value)) {
|
| 603 |
+
return inspectObject(value, options);
|
| 604 |
+
}
|
| 605 |
+
return options.stylize(String(value), type);
|
| 606 |
+
}
|
| 607 |
+
function registerConstructor(constructor, inspector) {
|
| 608 |
+
if (constructorMap.has(constructor)) {
|
| 609 |
+
return false;
|
| 610 |
+
}
|
| 611 |
+
constructorMap.set(constructor, inspector);
|
| 612 |
+
return true;
|
| 613 |
+
}
|
| 614 |
+
function registerStringTag(stringTag, inspector) {
|
| 615 |
+
if (stringTag in stringTagMap) {
|
| 616 |
+
return false;
|
| 617 |
+
}
|
| 618 |
+
stringTagMap[stringTag] = inspector;
|
| 619 |
+
return true;
|
| 620 |
+
}
|
| 621 |
+
var custom = chaiInspect;
|
| 622 |
+
var index_default = inspect;
|
node_modules/loupe/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "loupe",
|
| 3 |
+
"version": "3.2.1",
|
| 4 |
+
"description": "Inspect utility for Node.js and browsers",
|
| 5 |
+
"homepage": "https://github.com/chaijs/loupe",
|
| 6 |
+
"license": "MIT",
|
| 7 |
+
"author": "Veselin Todorov <hi@vesln.com>",
|
| 8 |
+
"contributors": [
|
| 9 |
+
"Keith Cirkel (https://github.com/keithamus)"
|
| 10 |
+
],
|
| 11 |
+
"type": "module",
|
| 12 |
+
"main": "./lib/index.js",
|
| 13 |
+
"module": "./lib/index.js",
|
| 14 |
+
"browser": {
|
| 15 |
+
"./index.js": "./loupe.js",
|
| 16 |
+
"util": false
|
| 17 |
+
},
|
| 18 |
+
"repository": {
|
| 19 |
+
"type": "git",
|
| 20 |
+
"url": "https://github.com/chaijs/loupe"
|
| 21 |
+
},
|
| 22 |
+
"files": [
|
| 23 |
+
"loupe.js",
|
| 24 |
+
"lib/*"
|
| 25 |
+
],
|
| 26 |
+
"scripts": {
|
| 27 |
+
"bench": "node bench",
|
| 28 |
+
"lint": "eslint .",
|
| 29 |
+
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
|
| 30 |
+
"test": "npm run test:node && npm run test:browser",
|
| 31 |
+
"pretest:browser": "npx playwright install-deps && npx playwright install && npm run build",
|
| 32 |
+
"test:browser": "wtr",
|
| 33 |
+
"pretest:node": "npm run build",
|
| 34 |
+
"test:node": "mocha",
|
| 35 |
+
"build": "npm run build:lib && npm run build:esm-bundle && npm run build:cjs-bundle",
|
| 36 |
+
"build:lib": "tsc",
|
| 37 |
+
"build:esm-bundle": "esbuild --bundle src/index.ts --outfile=loupe.js --format=esm",
|
| 38 |
+
"build:cjs-bundle": "esbuild --bundle src/index.ts --outfile=loupe.js --format=cjs",
|
| 39 |
+
"upload-coverage": "codecov"
|
| 40 |
+
},
|
| 41 |
+
"prettier": {
|
| 42 |
+
"printWidth": 120,
|
| 43 |
+
"tabWidth": 2,
|
| 44 |
+
"useTabs": false,
|
| 45 |
+
"semi": false,
|
| 46 |
+
"singleQuote": true,
|
| 47 |
+
"trailingComma": "es5",
|
| 48 |
+
"arrowParens": "avoid",
|
| 49 |
+
"bracketSpacing": true
|
| 50 |
+
},
|
| 51 |
+
"devDependencies": {
|
| 52 |
+
"@web/dev-server-esbuild": "^1.0.3",
|
| 53 |
+
"@web/test-runner": "^0.19.0",
|
| 54 |
+
"@web/test-runner-playwright": "^0.11.0",
|
| 55 |
+
"benchmark": "^2.1.4",
|
| 56 |
+
"chai": "^5.0.0-alpha.0",
|
| 57 |
+
"codecov": "^3.8.3",
|
| 58 |
+
"core-js": "^3.8.3",
|
| 59 |
+
"cross-env": "^7.0.3",
|
| 60 |
+
"esbuild": "^0.24.2",
|
| 61 |
+
"eslint": "^9.19.0",
|
| 62 |
+
"eslint-config-prettier": "^10.0.1",
|
| 63 |
+
"eslint-config-strict": "^14.0.1",
|
| 64 |
+
"eslint-plugin-filenames": "^1.3.2",
|
| 65 |
+
"eslint-plugin-prettier": "^5.2.3",
|
| 66 |
+
"husky": "^9.1.7",
|
| 67 |
+
"mocha": "^11.1.0",
|
| 68 |
+
"nyc": "^17.1.0",
|
| 69 |
+
"prettier": "^3.0.0",
|
| 70 |
+
"simple-assert": "^2.0.0",
|
| 71 |
+
"typescript": "^5.0.0-beta"
|
| 72 |
+
}
|
| 73 |
+
}
|
node_modules/lru-cache/LICENSE.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Blue Oak Model License
|
| 2 |
+
|
| 3 |
+
Version 1.0.0
|
| 4 |
+
|
| 5 |
+
## Purpose
|
| 6 |
+
|
| 7 |
+
This license gives everyone as much permission to work with
|
| 8 |
+
this software as possible, while protecting contributors
|
| 9 |
+
from liability.
|
| 10 |
+
|
| 11 |
+
## Acceptance
|
| 12 |
+
|
| 13 |
+
In order to receive this license, you must agree to its
|
| 14 |
+
rules. The rules of this license are both obligations
|
| 15 |
+
under that agreement and conditions to your license.
|
| 16 |
+
You must not do anything with this software that triggers
|
| 17 |
+
a rule that you cannot or will not follow.
|
| 18 |
+
|
| 19 |
+
## Copyright
|
| 20 |
+
|
| 21 |
+
Each contributor licenses you to do everything with this
|
| 22 |
+
software that would otherwise infringe that contributor's
|
| 23 |
+
copyright in it.
|
| 24 |
+
|
| 25 |
+
## Notices
|
| 26 |
+
|
| 27 |
+
You must ensure that everyone who gets a copy of
|
| 28 |
+
any part of this software from you, with or without
|
| 29 |
+
changes, also gets the text of this license or a link to
|
| 30 |
+
<https://blueoakcouncil.org/license/1.0.0>.
|
| 31 |
+
|
| 32 |
+
## Excuse
|
| 33 |
+
|
| 34 |
+
If anyone notifies you in writing that you have not
|
| 35 |
+
complied with [Notices](#notices), you can keep your
|
| 36 |
+
license by taking all practical steps to comply within 30
|
| 37 |
+
days after the notice. If you do not do so, your license
|
| 38 |
+
ends immediately.
|
| 39 |
+
|
| 40 |
+
## Patent
|
| 41 |
+
|
| 42 |
+
Each contributor licenses you to do everything with this
|
| 43 |
+
software that would otherwise infringe any patent claims
|
| 44 |
+
they can license or become able to license.
|
| 45 |
+
|
| 46 |
+
## Reliability
|
| 47 |
+
|
| 48 |
+
No contributor can revoke this license.
|
| 49 |
+
|
| 50 |
+
## No Liability
|
| 51 |
+
|
| 52 |
+
***As far as the law allows, this software comes as is,
|
| 53 |
+
without any warranty or condition, and no contributor
|
| 54 |
+
will be liable to anyone for any damages related to this
|
| 55 |
+
software or this license, under any kind of legal claim.***
|
node_modules/lru-cache/README.md
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# lru-cache
|
| 2 |
+
|
| 3 |
+
A cache object that deletes the least-recently-used items.
|
| 4 |
+
|
| 5 |
+
Specify a max number of the most recently used items that you
|
| 6 |
+
want to keep, and this cache will keep that many of the most
|
| 7 |
+
recently accessed items.
|
| 8 |
+
|
| 9 |
+
This is not primarily a TTL cache, and does not make strong TTL
|
| 10 |
+
guarantees. There is no preemptive pruning of expired items by
|
| 11 |
+
default, but you _may_ set a TTL on the cache or on a single
|
| 12 |
+
`set`. If you do so, it will treat expired items as missing, and
|
| 13 |
+
delete them when fetched. If you are more interested in TTL
|
| 14 |
+
caching than LRU caching, check out
|
| 15 |
+
[@isaacs/ttlcache](http://npm.im/@isaacs/ttlcache).
|
| 16 |
+
|
| 17 |
+
As of version 7, this is one of the most performant LRU
|
| 18 |
+
implementations available in JavaScript, and supports a wide
|
| 19 |
+
diversity of use cases. However, note that using some of the
|
| 20 |
+
features will necessarily impact performance, by causing the
|
| 21 |
+
cache to have to do more work. See the "Performance" section
|
| 22 |
+
below.
|
| 23 |
+
|
| 24 |
+
## Installation
|
| 25 |
+
|
| 26 |
+
```bash
|
| 27 |
+
npm install lru-cache --save
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## Usage
|
| 31 |
+
|
| 32 |
+
```js
|
| 33 |
+
// hybrid module, either works
|
| 34 |
+
import { LRUCache } from 'lru-cache'
|
| 35 |
+
// or:
|
| 36 |
+
const { LRUCache } = require('lru-cache')
|
| 37 |
+
// or in minified form for web browsers:
|
| 38 |
+
import { LRUCache } from 'http://unpkg.com/lru-cache@9/dist/mjs/index.min.mjs'
|
| 39 |
+
|
| 40 |
+
// At least one of 'max', 'ttl', or 'maxSize' is required, to prevent
|
| 41 |
+
// unsafe unbounded storage.
|
| 42 |
+
//
|
| 43 |
+
// In most cases, it's best to specify a max for performance, so all
|
| 44 |
+
// the required memory allocation is done up-front.
|
| 45 |
+
//
|
| 46 |
+
// All the other options are optional, see the sections below for
|
| 47 |
+
// documentation on what each one does. Most of them can be
|
| 48 |
+
// overridden for specific items in get()/set()
|
| 49 |
+
const options = {
|
| 50 |
+
max: 500,
|
| 51 |
+
|
| 52 |
+
// for use with tracking overall storage size
|
| 53 |
+
maxSize: 5000,
|
| 54 |
+
sizeCalculation: (value, key) => {
|
| 55 |
+
return 1
|
| 56 |
+
},
|
| 57 |
+
|
| 58 |
+
// for use when you need to clean up something when objects
|
| 59 |
+
// are evicted from the cache
|
| 60 |
+
dispose: (value, key, reason) => {
|
| 61 |
+
freeFromMemoryOrWhatever(value)
|
| 62 |
+
},
|
| 63 |
+
|
| 64 |
+
// for use when you need to know that an item is being inserted
|
| 65 |
+
// note that this does NOT allow you to prevent the insertion,
|
| 66 |
+
// it just allows you to know about it.
|
| 67 |
+
onInsert: (value, key, reason) => {
|
| 68 |
+
logInsertionOrWhatever(key, value)
|
| 69 |
+
},
|
| 70 |
+
|
| 71 |
+
// how long to live in ms
|
| 72 |
+
ttl: 1000 * 60 * 5,
|
| 73 |
+
|
| 74 |
+
// return stale items before removing from cache?
|
| 75 |
+
allowStale: false,
|
| 76 |
+
|
| 77 |
+
updateAgeOnGet: false,
|
| 78 |
+
updateAgeOnHas: false,
|
| 79 |
+
|
| 80 |
+
// async method to use for cache.fetch(), for
|
| 81 |
+
// stale-while-revalidate type of behavior
|
| 82 |
+
fetchMethod: async (key, staleValue, { options, signal, context }) => {},
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
const cache = new LRUCache(options)
|
| 86 |
+
|
| 87 |
+
cache.set('key', 'value')
|
| 88 |
+
cache.get('key') // "value"
|
| 89 |
+
|
| 90 |
+
// non-string keys ARE fully supported
|
| 91 |
+
// but note that it must be THE SAME object, not
|
| 92 |
+
// just a JSON-equivalent object.
|
| 93 |
+
var someObject = { a: 1 }
|
| 94 |
+
cache.set(someObject, 'a value')
|
| 95 |
+
// Object keys are not toString()-ed
|
| 96 |
+
cache.set('[object Object]', 'a different value')
|
| 97 |
+
assert.equal(cache.get(someObject), 'a value')
|
| 98 |
+
// A similar object with same keys/values won't work,
|
| 99 |
+
// because it's a different object identity
|
| 100 |
+
assert.equal(cache.get({ a: 1 }), undefined)
|
| 101 |
+
|
| 102 |
+
cache.clear() // empty the cache
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
If you put more stuff in the cache, then less recently used items
|
| 106 |
+
will fall out. That's what an LRU cache is.
|
| 107 |
+
|
| 108 |
+
For full description of the API and all options, please see [the
|
| 109 |
+
LRUCache typedocs](https://isaacs.github.io/node-lru-cache/)
|
| 110 |
+
|
| 111 |
+
## Storage Bounds Safety
|
| 112 |
+
|
| 113 |
+
This implementation aims to be as flexible as possible, within
|
| 114 |
+
the limits of safe memory consumption and optimal performance.
|
| 115 |
+
|
| 116 |
+
At initial object creation, storage is allocated for `max` items.
|
| 117 |
+
If `max` is set to zero, then some performance is lost, and item
|
| 118 |
+
count is unbounded. Either `maxSize` or `ttl` _must_ be set if
|
| 119 |
+
`max` is not specified.
|
| 120 |
+
|
| 121 |
+
If `maxSize` is set, then this creates a safe limit on the
|
| 122 |
+
maximum storage consumed, but without the performance benefits of
|
| 123 |
+
pre-allocation. When `maxSize` is set, every item _must_ provide
|
| 124 |
+
a size, either via the `sizeCalculation` method provided to the
|
| 125 |
+
constructor, or via a `size` or `sizeCalculation` option provided
|
| 126 |
+
to `cache.set()`. The size of every item _must_ be a positive
|
| 127 |
+
integer.
|
| 128 |
+
|
| 129 |
+
If neither `max` nor `maxSize` are set, then `ttl` tracking must
|
| 130 |
+
be enabled. Note that, even when tracking item `ttl`, items are
|
| 131 |
+
_not_ preemptively deleted when they become stale, unless
|
| 132 |
+
`ttlAutopurge` is enabled. Instead, they are only purged the
|
| 133 |
+
next time the key is requested. Thus, if `ttlAutopurge`, `max`,
|
| 134 |
+
and `maxSize` are all not set, then the cache will potentially
|
| 135 |
+
grow unbounded.
|
| 136 |
+
|
| 137 |
+
In this case, a warning is printed to standard error. Future
|
| 138 |
+
versions may require the use of `ttlAutopurge` if `max` and
|
| 139 |
+
`maxSize` are not specified.
|
| 140 |
+
|
| 141 |
+
If you truly wish to use a cache that is bound _only_ by TTL
|
| 142 |
+
expiration, consider using a `Map` object, and calling
|
| 143 |
+
`setTimeout` to delete entries when they expire. It will perform
|
| 144 |
+
much better than an LRU cache.
|
| 145 |
+
|
| 146 |
+
Here is an implementation you may use, under the same
|
| 147 |
+
[license](./LICENSE) as this package:
|
| 148 |
+
|
| 149 |
+
```js
|
| 150 |
+
// a storage-unbounded ttl cache that is not an lru-cache
|
| 151 |
+
const cache = {
|
| 152 |
+
data: new Map(),
|
| 153 |
+
timers: new Map(),
|
| 154 |
+
set: (k, v, ttl) => {
|
| 155 |
+
if (cache.timers.has(k)) {
|
| 156 |
+
clearTimeout(cache.timers.get(k))
|
| 157 |
+
}
|
| 158 |
+
cache.timers.set(
|
| 159 |
+
k,
|
| 160 |
+
setTimeout(() => cache.delete(k), ttl),
|
| 161 |
+
)
|
| 162 |
+
cache.data.set(k, v)
|
| 163 |
+
},
|
| 164 |
+
get: k => cache.data.get(k),
|
| 165 |
+
has: k => cache.data.has(k),
|
| 166 |
+
delete: k => {
|
| 167 |
+
if (cache.timers.has(k)) {
|
| 168 |
+
clearTimeout(cache.timers.get(k))
|
| 169 |
+
}
|
| 170 |
+
cache.timers.delete(k)
|
| 171 |
+
return cache.data.delete(k)
|
| 172 |
+
},
|
| 173 |
+
clear: () => {
|
| 174 |
+
cache.data.clear()
|
| 175 |
+
for (const v of cache.timers.values()) {
|
| 176 |
+
clearTimeout(v)
|
| 177 |
+
}
|
| 178 |
+
cache.timers.clear()
|
| 179 |
+
},
|
| 180 |
+
}
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
If that isn't to your liking, check out
|
| 184 |
+
[@isaacs/ttlcache](http://npm.im/@isaacs/ttlcache).
|
| 185 |
+
|
| 186 |
+
## Storing Undefined Values
|
| 187 |
+
|
| 188 |
+
This cache never stores undefined values, as `undefined` is used
|
| 189 |
+
internally in a few places to indicate that a key is not in the
|
| 190 |
+
cache.
|
| 191 |
+
|
| 192 |
+
You may call `cache.set(key, undefined)`, but this is just
|
| 193 |
+
an alias for `cache.delete(key)`. Note that this has the effect
|
| 194 |
+
that `cache.has(key)` will return _false_ after setting it to
|
| 195 |
+
undefined.
|
| 196 |
+
|
| 197 |
+
```js
|
| 198 |
+
cache.set(myKey, undefined)
|
| 199 |
+
cache.has(myKey) // false!
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
If you need to track `undefined` values, and still note that the
|
| 203 |
+
key is in the cache, an easy workaround is to use a sigil object
|
| 204 |
+
of your own.
|
| 205 |
+
|
| 206 |
+
```js
|
| 207 |
+
import { LRUCache } from 'lru-cache'
|
| 208 |
+
const undefinedValue = Symbol('undefined')
|
| 209 |
+
const cache = new LRUCache(...)
|
| 210 |
+
const mySet = (key, value) =>
|
| 211 |
+
cache.set(key, value === undefined ? undefinedValue : value)
|
| 212 |
+
const myGet = (key, value) => {
|
| 213 |
+
const v = cache.get(key)
|
| 214 |
+
return v === undefinedValue ? undefined : v
|
| 215 |
+
}
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
## Tracing and Observability
|
| 219 |
+
|
| 220 |
+
Most methods can accept a `status` option, which is an
|
| 221 |
+
[`LRUCache.Status`](https://isaacs.github.io/node-lru-cache/interfaces/LRUCache.LRUCache.Status.html)
|
| 222 |
+
object that will be decorated along the operation with
|
| 223 |
+
indications about what was done and why.
|
| 224 |
+
|
| 225 |
+
Additionally, this library is instrumented using the
|
| 226 |
+
[`node:diagnostics_channel`](https://nodejs.org/api/diagnostics_channel.html)
|
| 227 |
+
module on Node and other platforms that support it. In order to
|
| 228 |
+
get diagnostics metrics, listen on the
|
| 229 |
+
`channel('lru-cache:metrics')`. To get Tracing Channel traces,
|
| 230 |
+
subscribe to the `tracingChannel('lru-cache')`. The
|
| 231 |
+
[`LRUCache.Status`](https://isaacs.github.io/node-lru-cache/interfaces/LRUCache.LRUCache.Status.html)
|
| 232 |
+
objects will be provided as the message context to those channel
|
| 233 |
+
listeners.
|
| 234 |
+
|
| 235 |
+
For example, you could do the following to get comprehensive
|
| 236 |
+
information about every LRUCache instance in your application:
|
| 237 |
+
|
| 238 |
+
```ts
|
| 239 |
+
import { tracingChannel, subscribe } from 'node:diagnostics_channel'
|
| 240 |
+
|
| 241 |
+
subscribe('lru-cache:metrics', (message, name) => {
|
| 242 |
+
// name will always be 'lru-cache:metrics'
|
| 243 |
+
// message will be the LRUCache.Status object for whatever
|
| 244 |
+
// synchronous operation was performed.
|
| 245 |
+
console.error('LRUCache Metrics', message)
|
| 246 |
+
})
|
| 247 |
+
|
| 248 |
+
tracingChannel('lru-cache').subscribe({
|
| 249 |
+
start: status => {
|
| 250 |
+
// a traced operation is starting
|
| 251 |
+
},
|
| 252 |
+
asyncStart: status => {
|
| 253 |
+
// an async traced operation is starting
|
| 254 |
+
},
|
| 255 |
+
asyncEnd: status => {
|
| 256 |
+
// an async traced operation is ending
|
| 257 |
+
}
|
| 258 |
+
error: status => {
|
| 259 |
+
// a traced operation failed
|
| 260 |
+
},
|
| 261 |
+
end: status => {
|
| 262 |
+
// a traced operation is complete
|
| 263 |
+
},
|
| 264 |
+
})
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
The async `cache.fetch()` and `cache.forceFetch` methods are
|
| 268 |
+
covered by `tracingChannels`. All the other operations are
|
| 269 |
+
covered by the `lru-cache:metrics` channel, because they are
|
| 270 |
+
strictly synchronous, and thus don't have an asynchronous
|
| 271 |
+
lifecycle to track.
|
| 272 |
+
|
| 273 |
+
Note that using `status` objects or using
|
| 274 |
+
`node:diagnostics_channel` listeners _will_ impose a modest
|
| 275 |
+
performance penalty. Creating data objects is not ever free; do
|
| 276 |
+
not believe anyone who tells you otherwise. But it is as small as
|
| 277 |
+
possible.
|
| 278 |
+
|
| 279 |
+
### Platform Compatibility Caveat
|
| 280 |
+
|
| 281 |
+
Not all platforms support the `node:diagnostics_channel` module.
|
| 282 |
+
Currently, this is only available in Node, Bun, and Deno, and
|
| 283 |
+
some edge computing platforms that provide a Node compatibility
|
| 284 |
+
layer.
|
| 285 |
+
|
| 286 |
+
To work around this, if you are loading in a non-Node
|
| 287 |
+
environment, the package.json exports will direct your module
|
| 288 |
+
loader to pull in a version that starts out with a dummy
|
| 289 |
+
implementation, then does a conditional dynamic `import` of the
|
| 290 |
+
`node:diagnostics_channel` module, and then swaps out those
|
| 291 |
+
dummy objects with the real thing if it succeeds. This means that
|
| 292 |
+
cache metrics and tracing channels started in the first load-time
|
| 293 |
+
tick of your application will _not_ be covered, except in
|
| 294 |
+
environments that load using the `require` import
|
| 295 |
+
condition, or both the `node` and `esm` import conditions
|
| 296 |
+
together.
|
| 297 |
+
|
| 298 |
+
Top-level await _could_ be used to remove this caveat, but that
|
| 299 |
+
feature is dead on arrival, unfortunately. See
|
| 300 |
+
[#397](https://github.com/isaacs/node-lru-cache/issues/397) and
|
| 301 |
+
[#398](https://github.com/isaacs/node-lru-cache/issues/398) for
|
| 302 |
+
more details.
|
| 303 |
+
|
| 304 |
+
## Performance
|
| 305 |
+
|
| 306 |
+
As of April 2026, version 11 of this library is one of the most
|
| 307 |
+
performant LRU cache implementations in JavaScript.
|
| 308 |
+
|
| 309 |
+
Benchmarks can be extremely difficult to get right. In
|
| 310 |
+
particular, the performance of set/get/delete operations on
|
| 311 |
+
objects will vary _wildly_ depending on the type of key used. V8
|
| 312 |
+
is highly optimized for objects with keys that are short strings,
|
| 313 |
+
especially integer numeric strings. Thus any benchmark which
|
| 314 |
+
tests _solely_ using numbers as keys will tend to find that an
|
| 315 |
+
object-based approach performs the best.
|
| 316 |
+
|
| 317 |
+
Note that coercing _anything_ to strings to use as object keys is
|
| 318 |
+
unsafe, unless you can be 100% certain that no other type of
|
| 319 |
+
value will be used. For example:
|
| 320 |
+
|
| 321 |
+
```js
|
| 322 |
+
const myCache = {}
|
| 323 |
+
const set = (k, v) => (myCache[k] = v)
|
| 324 |
+
const get = k => myCache[k]
|
| 325 |
+
|
| 326 |
+
set({}, 'please hang onto this for me')
|
| 327 |
+
set('[object Object]', 'oopsie')
|
| 328 |
+
```
|
| 329 |
+
|
| 330 |
+
Also beware of "Just So" stories regarding performance. Garbage
|
| 331 |
+
collection of large (especially: deep) object graphs can be
|
| 332 |
+
incredibly costly, with several "tipping points" where it
|
| 333 |
+
increases exponentially. As a result, putting that off until
|
| 334 |
+
later can make it much worse, and less predictable. If a library
|
| 335 |
+
performs well, but only in a scenario where the object graph is
|
| 336 |
+
kept shallow, then that won't help you if you are using large
|
| 337 |
+
objects as keys.
|
| 338 |
+
|
| 339 |
+
In general, when attempting to use a library to improve
|
| 340 |
+
performance (such as a cache like this one), it's best to choose
|
| 341 |
+
an option that will perform well in the sorts of scenarios where
|
| 342 |
+
you'll actually use it.
|
| 343 |
+
|
| 344 |
+
This library is optimized for repeated gets and minimizing
|
| 345 |
+
eviction time, since that is the expected need of a LRU. Set
|
| 346 |
+
operations are somewhat slower on average than a few other
|
| 347 |
+
options, in part because of that optimization. It is assumed
|
| 348 |
+
that you'll be caching some costly operation, ideally as rarely
|
| 349 |
+
as possible, so optimizing set over get would be unwise.
|
| 350 |
+
|
| 351 |
+
If performance matters to you:
|
| 352 |
+
|
| 353 |
+
1. If it's at all possible to use small integer values as keys,
|
| 354 |
+
and you can guarantee that no other types of values will be
|
| 355 |
+
used as keys, then do that, and use a cache such as
|
| 356 |
+
[lru-fast](https://npmjs.com/package/lru-fast), or
|
| 357 |
+
[mnemonist's
|
| 358 |
+
LRUCache](https://yomguithereal.github.io/mnemonist/lru-cache)
|
| 359 |
+
which uses an Object as its data store.
|
| 360 |
+
|
| 361 |
+
2. Failing that, if you can use short non-numeric strings (ie,
|
| 362 |
+
less than 256 characters) as your keys, and you do not need
|
| 363 |
+
any of the other features of this library, use [mnemonist's
|
| 364 |
+
LRUCache](https://yomguithereal.github.io/mnemonist/lru-cache).
|
| 365 |
+
|
| 366 |
+
3. If the types of your keys will be anything else, especially
|
| 367 |
+
long strings, strings that look like floats, objects, or some
|
| 368 |
+
mix of types, or if you aren't sure, then this library will
|
| 369 |
+
work well for you.
|
| 370 |
+
|
| 371 |
+
If you do not need the features that this library provides
|
| 372 |
+
(like asynchronous fetching, a variety of TTL staleness
|
| 373 |
+
options, and so on), then [mnemonist's
|
| 374 |
+
LRUMap](https://yomguithereal.github.io/mnemonist/lru-map) is
|
| 375 |
+
also a very good option, and just slightly faster than this
|
| 376 |
+
module (since it does considerably less).
|
| 377 |
+
|
| 378 |
+
4. Do not use a `dispose` function, size tracking, or especially
|
| 379 |
+
ttl behavior or observability features, unless absolutely
|
| 380 |
+
needed. These features are convenient, and necessary in some
|
| 381 |
+
use cases, and every attempt has been made to make the
|
| 382 |
+
performance impact minimal, but it isn't nothing.
|
| 383 |
+
|
| 384 |
+
## Testing
|
| 385 |
+
|
| 386 |
+
When writing tests that involve TTL-related functionality, note
|
| 387 |
+
that this module creates an internal reference to the global
|
| 388 |
+
`performance` or `Date` objects at import time. If you import it
|
| 389 |
+
statically at the top level, those references cannot be mocked or
|
| 390 |
+
overridden in your test environment.
|
| 391 |
+
|
| 392 |
+
To avoid this, dynamically import the package within your tests
|
| 393 |
+
so that the references are captured after your mocks are applied.
|
| 394 |
+
For example:
|
| 395 |
+
|
| 396 |
+
```ts
|
| 397 |
+
// ❌ Not recommended
|
| 398 |
+
import { LRUCache } from 'lru-cache'
|
| 399 |
+
// mocking timers, e.g. jest.useFakeTimers()
|
| 400 |
+
|
| 401 |
+
// ✅ Recommended for TTL tests
|
| 402 |
+
// mocking timers, e.g. jest.useFakeTimers()
|
| 403 |
+
const { LRUCache } = await import('lru-cache')
|
| 404 |
+
```
|
| 405 |
+
|
| 406 |
+
This ensures that your mocked timers or time sources are
|
| 407 |
+
respected when testing TTL behavior.
|
| 408 |
+
|
| 409 |
+
Additionally, you can pass in a `perf` option when creating your
|
| 410 |
+
LRUCache instance. This option accepts any object with a `now`
|
| 411 |
+
method that returns a number.
|
| 412 |
+
|
| 413 |
+
For example, this would be a very bare-bones time-mocking system
|
| 414 |
+
you could use in your tests, without any particular test
|
| 415 |
+
framework:
|
| 416 |
+
|
| 417 |
+
```ts
|
| 418 |
+
import { LRUCache } from 'lru-cache'
|
| 419 |
+
|
| 420 |
+
let myClockTime = 0
|
| 421 |
+
|
| 422 |
+
const cache = new LRUCache<string>({
|
| 423 |
+
max: 10,
|
| 424 |
+
ttl: 1000,
|
| 425 |
+
perf: {
|
| 426 |
+
now: () => myClockTime,
|
| 427 |
+
},
|
| 428 |
+
})
|
| 429 |
+
|
| 430 |
+
// run tests, updating myClockTime as needed
|
| 431 |
+
```
|
| 432 |
+
|
| 433 |
+
## Breaking Changes in Version 7
|
| 434 |
+
|
| 435 |
+
This library changed to a different algorithm and internal data
|
| 436 |
+
structure in version 7, yielding significantly better
|
| 437 |
+
performance, albeit with some subtle changes as a result.
|
| 438 |
+
|
| 439 |
+
If you were relying on the internals of LRUCache in version 6 or
|
| 440 |
+
before, it probably will not work in version 7 and above.
|
| 441 |
+
|
| 442 |
+
## Breaking Changes in Version 8
|
| 443 |
+
|
| 444 |
+
- The `fetchContext` option was renamed to `context`, and may no
|
| 445 |
+
longer be set on the cache instance itself.
|
| 446 |
+
- Rewritten in TypeScript, so pretty much all the types moved
|
| 447 |
+
around a lot.
|
| 448 |
+
- The AbortController/AbortSignal polyfill was removed. For this
|
| 449 |
+
reason, **Node version 16.14.0 or higher is now required**.
|
| 450 |
+
- Internal properties were moved to actual private class
|
| 451 |
+
properties.
|
| 452 |
+
- Keys and values must not be `null` or `undefined`.
|
| 453 |
+
- Minified export available at `'lru-cache/min'`, for both CJS
|
| 454 |
+
and MJS builds.
|
| 455 |
+
|
| 456 |
+
## Breaking Changes in Version 9
|
| 457 |
+
|
| 458 |
+
- Named export only, no default export.
|
| 459 |
+
- AbortController polyfill returned, albeit with a warning when
|
| 460 |
+
used.
|
| 461 |
+
|
| 462 |
+
## Breaking Changes in Version 10
|
| 463 |
+
|
| 464 |
+
- `cache.fetch()` return type is now `Promise<V | undefined>`
|
| 465 |
+
instead of `Promise<V | void>`. This is an irrelevant change
|
| 466 |
+
practically speaking, but can require changes for TypeScript
|
| 467 |
+
users.
|
| 468 |
+
|
| 469 |
+
For more info, see the [change log](CHANGELOG.md).
|
node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"diagnostics-channel-browser.d.ts","sourceRoot":"","sources":["../../../src/diagnostics-channel-browser.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,CAAA;AAGvC,eAAO,MAAM,OAAO,EAAY,OAAO,CAAC,OAAO,CAAC,CAAA;AAChD,eAAO,MAAM,OAAO,EAAY,cAAc,CAAC,OAAO,CAAC,CAAA"}
|
node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"diagnostics-channel-browser.js","sourceRoot":"","sources":["../../../src/diagnostics-channel-browser.ts"],"names":[],"mappings":";;;AAQA,MAAM,KAAK,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,CAAA;AAC1B,QAAA,OAAO,GAAG,KAAyB,CAAA;AACnC,QAAA,OAAO,GAAG,KAAgC,CAAA","sourcesContent":["// this is used in ESM environments that follow the 'browser' import\n// condition, to avoid even trying to load node:diagnostics_channel\nimport {\n type Channel,\n type TracingChannel,\n} from 'node:diagnostics_channel'\nexport type { TracingChannel, Channel }\n\nconst dummy = { hasSubscribers: false }\nexport const metrics = dummy as Channel<unknown>\nexport const tracing = dummy as TracingChannel<unknown>\n"]}
|
node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { type Channel, type TracingChannel } from 'node:diagnostics_channel';
|
| 2 |
+
export type { TracingChannel, Channel };
|
| 3 |
+
export declare const metrics: Channel<unknown>;
|
| 4 |
+
export declare const tracing: TracingChannel<unknown>;
|
| 5 |
+
//# sourceMappingURL=diagnostics-channel-browser.d.ts.map
|
node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.tracing = exports.metrics = void 0;
|
| 4 |
+
const dummy = { hasSubscribers: false };
|
| 5 |
+
exports.metrics = dummy;
|
| 6 |
+
exports.tracing = dummy;
|
| 7 |
+
//# sourceMappingURL=diagnostics-channel-browser.js.map
|
node_modules/lru-cache/dist/commonjs/browser/index.d.ts
ADDED
|
@@ -0,0 +1,1400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @module LRUCache
|
| 3 |
+
*/
|
| 4 |
+
import type { Perf } from './perf.js';
|
| 5 |
+
export type { Perf } from './perf.js';
|
| 6 |
+
declare const TYPE: unique symbol;
|
| 7 |
+
export type PosInt = number & {
|
| 8 |
+
[TYPE]: 'Positive Integer';
|
| 9 |
+
};
|
| 10 |
+
export type Index = number & {
|
| 11 |
+
[TYPE]: 'LRUCache Index';
|
| 12 |
+
};
|
| 13 |
+
export type UintArray = Uint8Array | Uint16Array | Uint32Array;
|
| 14 |
+
export type NumberArray = UintArray | number[];
|
| 15 |
+
declare class ZeroArray extends Array<number> {
|
| 16 |
+
constructor(size: number);
|
| 17 |
+
}
|
| 18 |
+
export type { ZeroArray };
|
| 19 |
+
export type { Stack };
|
| 20 |
+
export type StackLike = Stack | Index[];
|
| 21 |
+
declare class Stack {
|
| 22 |
+
#private;
|
| 23 |
+
heap: NumberArray;
|
| 24 |
+
length: number;
|
| 25 |
+
static create(max: number): StackLike;
|
| 26 |
+
constructor(max: number, HeapCls: {
|
| 27 |
+
new (n: number): NumberArray;
|
| 28 |
+
});
|
| 29 |
+
push(n: Index): void;
|
| 30 |
+
pop(): Index;
|
| 31 |
+
}
|
| 32 |
+
/**
|
| 33 |
+
* Promise representing an in-progress {@link LRUCache#fetch} call
|
| 34 |
+
*/
|
| 35 |
+
export type BackgroundFetch<V> = Promise<V | undefined> & {
|
| 36 |
+
__returned: BackgroundFetch<V> | undefined;
|
| 37 |
+
__abortController: AbortController;
|
| 38 |
+
__staleWhileFetching: V | undefined;
|
| 39 |
+
};
|
| 40 |
+
export type DisposeTask<K, V> = [
|
| 41 |
+
value: V,
|
| 42 |
+
key: K,
|
| 43 |
+
reason: LRUCache.DisposeReason
|
| 44 |
+
];
|
| 45 |
+
export declare namespace LRUCache {
|
| 46 |
+
/**
|
| 47 |
+
* An integer greater than 0, reflecting the calculated size of items
|
| 48 |
+
*/
|
| 49 |
+
type Size = number;
|
| 50 |
+
/**
|
| 51 |
+
* Integer greater than 0, representing some number of milliseconds, or the
|
| 52 |
+
* time at which a TTL started counting from.
|
| 53 |
+
*/
|
| 54 |
+
type Milliseconds = number;
|
| 55 |
+
/**
|
| 56 |
+
* An integer greater than 0, reflecting a number of items
|
| 57 |
+
*/
|
| 58 |
+
type Count = number;
|
| 59 |
+
/**
|
| 60 |
+
* The reason why an item was removed from the cache, passed
|
| 61 |
+
* to the {@link Disposer} methods.
|
| 62 |
+
*
|
| 63 |
+
* - `evict`: The item was evicted because it is the least recently used,
|
| 64 |
+
* and the cache is full.
|
| 65 |
+
* - `set`: A new value was set, overwriting the old value being disposed.
|
| 66 |
+
* - `delete`: The item was explicitly deleted, either by calling
|
| 67 |
+
* {@link LRUCache#delete}, {@link LRUCache#clear}, or
|
| 68 |
+
* {@link LRUCache#set} with an undefined value.
|
| 69 |
+
* - `expire`: The item was removed due to exceeding its TTL.
|
| 70 |
+
* - `fetch`: A {@link OptionsBase#fetchMethod} operation returned
|
| 71 |
+
* `undefined` or was aborted, causing the item to be deleted.
|
| 72 |
+
*/
|
| 73 |
+
type DisposeReason = 'evict' | 'set' | 'delete' | 'expire' | 'fetch';
|
| 74 |
+
/**
|
| 75 |
+
* A method called upon item removal, passed as the
|
| 76 |
+
* {@link OptionsBase.dispose} and/or
|
| 77 |
+
* {@link OptionsBase.disposeAfter} options.
|
| 78 |
+
*/
|
| 79 |
+
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
|
| 80 |
+
/**
|
| 81 |
+
* The reason why an item was added to the cache, passed
|
| 82 |
+
* to the {@link Inserter} methods.
|
| 83 |
+
*
|
| 84 |
+
* - `add`: the item was not found in the cache, and was added
|
| 85 |
+
* - `update`: the item was in the cache, with the same value provided
|
| 86 |
+
* - `replace`: the item was in the cache, and replaced
|
| 87 |
+
*/
|
| 88 |
+
type InsertReason = 'add' | 'update' | 'replace';
|
| 89 |
+
/**
|
| 90 |
+
* A method called upon item insertion, passed as the
|
| 91 |
+
* {@link OptionsBase.insert}
|
| 92 |
+
*/
|
| 93 |
+
type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
|
| 94 |
+
/**
|
| 95 |
+
* A function that returns the effective calculated size
|
| 96 |
+
* of an entry in the cache.
|
| 97 |
+
*/
|
| 98 |
+
type SizeCalculator<K, V> = (value: V, key: K) => Size;
|
| 99 |
+
/**
|
| 100 |
+
* Options provided to the
|
| 101 |
+
* {@link OptionsBase.fetchMethod} function.
|
| 102 |
+
*/
|
| 103 |
+
interface FetcherOptions<K, V, FC = unknown> {
|
| 104 |
+
signal: AbortSignal;
|
| 105 |
+
options: FetcherFetchOptions<K, V, FC>;
|
| 106 |
+
/**
|
| 107 |
+
* Object provided in the {@link FetchOptions.context} option to
|
| 108 |
+
* {@link LRUCache#fetch}
|
| 109 |
+
*/
|
| 110 |
+
context: FC;
|
| 111 |
+
}
|
| 112 |
+
/**
|
| 113 |
+
* Occasionally, it may be useful to track the internal behavior of the
|
| 114 |
+
* cache, particularly for logging, debugging, or for behavior within the
|
| 115 |
+
* `fetchMethod`. To do this, you can pass a `status` object to the
|
| 116 |
+
* {@link LRUCache#fetch}, {@link LRUCache#get}, {@link LRUCache#set},
|
| 117 |
+
* {@link LRUCache#memo}, and {@link LRUCache#has} methods.
|
| 118 |
+
*
|
| 119 |
+
* The `status` option should be a plain JavaScript object. The following
|
| 120 |
+
* fields will be set on it appropriately, depending on the situation.
|
| 121 |
+
*
|
| 122 |
+
* These objects are also the context objects passed to listeners on the
|
| 123 |
+
* `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
|
| 124 |
+
* channels, in platforms that support them.
|
| 125 |
+
*/
|
| 126 |
+
interface Status<K, V, FC = unknown> {
|
| 127 |
+
/**
|
| 128 |
+
* The operation being performed
|
| 129 |
+
*/
|
| 130 |
+
op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek';
|
| 131 |
+
/**
|
| 132 |
+
* The status of a set() operation.
|
| 133 |
+
*
|
| 134 |
+
* - add: the item was not found in the cache, and was added
|
| 135 |
+
* - update: the item was in the cache, with the same value provided
|
| 136 |
+
* - replace: the item was in the cache, and replaced
|
| 137 |
+
* - miss: the item was not added to the cache for some reason
|
| 138 |
+
*/
|
| 139 |
+
set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted';
|
| 140 |
+
/**
|
| 141 |
+
* The status of a delete() operation.
|
| 142 |
+
*/
|
| 143 |
+
delete?: LRUCache.DisposeReason;
|
| 144 |
+
/**
|
| 145 |
+
* The result of a peek() operation
|
| 146 |
+
*
|
| 147 |
+
* - hit: the item was found and returned
|
| 148 |
+
* - stale: the item is in the cache, but past its ttl and not returned
|
| 149 |
+
* - miss: item not in the cache
|
| 150 |
+
*/
|
| 151 |
+
peek?: 'hit' | 'miss' | 'stale';
|
| 152 |
+
/**
|
| 153 |
+
* The status of a memo() operation.
|
| 154 |
+
*
|
| 155 |
+
* - 'hit': the item was found in the cache and returned
|
| 156 |
+
* - 'miss': the `memoMethod` function was called
|
| 157 |
+
*/
|
| 158 |
+
memo?: 'hit' | 'miss';
|
| 159 |
+
/**
|
| 160 |
+
* The `context` option provided to a memo or fetch operation
|
| 161 |
+
*
|
| 162 |
+
* In practice, of course, this will be the same type as the `FC`
|
| 163 |
+
* fetch context param used to instantiate the LRUCache, but the
|
| 164 |
+
* convolutions of threading that through would get quite complicated,
|
| 165 |
+
* and preclude forcing/forbidding the passing of a `context` param
|
| 166 |
+
* where it is/isn't expected, which is more valuable for error
|
| 167 |
+
* prevention.
|
| 168 |
+
*/
|
| 169 |
+
context?: unknown;
|
| 170 |
+
/**
|
| 171 |
+
* the ttl stored for the item, or undefined if ttls are not used.
|
| 172 |
+
*/
|
| 173 |
+
ttl?: Milliseconds;
|
| 174 |
+
/**
|
| 175 |
+
* the start time for the item, or undefined if ttls are not used.
|
| 176 |
+
*/
|
| 177 |
+
start?: Milliseconds;
|
| 178 |
+
/**
|
| 179 |
+
* The timestamp used for TTL calculation
|
| 180 |
+
*/
|
| 181 |
+
now?: Milliseconds;
|
| 182 |
+
/**
|
| 183 |
+
* the remaining ttl for the item, or undefined if ttls are not used.
|
| 184 |
+
*/
|
| 185 |
+
remainingTTL?: Milliseconds;
|
| 186 |
+
/**
|
| 187 |
+
* The calculated size for the item, if sizes are used.
|
| 188 |
+
*/
|
| 189 |
+
entrySize?: Size;
|
| 190 |
+
/**
|
| 191 |
+
* The total calculated size of the cache, if sizes are used.
|
| 192 |
+
*/
|
| 193 |
+
totalCalculatedSize?: Size;
|
| 194 |
+
/**
|
| 195 |
+
* A flag indicating that the item was not stored, due to exceeding the
|
| 196 |
+
* {@link OptionsBase.maxEntrySize}
|
| 197 |
+
*/
|
| 198 |
+
maxEntrySizeExceeded?: true;
|
| 199 |
+
/**
|
| 200 |
+
* The key that was set or retrieved
|
| 201 |
+
*/
|
| 202 |
+
key?: K;
|
| 203 |
+
/**
|
| 204 |
+
* The value that was set
|
| 205 |
+
*/
|
| 206 |
+
value?: V;
|
| 207 |
+
/**
|
| 208 |
+
* The old value, specified in the case of `set:'replace'`
|
| 209 |
+
*/
|
| 210 |
+
oldValue?: V;
|
| 211 |
+
/**
|
| 212 |
+
* The results of a {@link LRUCache#has} operation
|
| 213 |
+
*
|
| 214 |
+
* - hit: the item was found in the cache
|
| 215 |
+
* - stale: the item was found in the cache, but is stale
|
| 216 |
+
* - miss: the item was not found in the cache
|
| 217 |
+
*/
|
| 218 |
+
has?: 'hit' | 'stale' | 'miss';
|
| 219 |
+
/**
|
| 220 |
+
* The status of a {@link LRUCache#fetch} operation.
|
| 221 |
+
* Note that this can change as the underlying fetch() moves through
|
| 222 |
+
* various states.
|
| 223 |
+
*
|
| 224 |
+
* - inflight: there is another fetch() for this key which is in process
|
| 225 |
+
* - get: there is no {@link OptionsBase.fetchMethod}, so
|
| 226 |
+
* {@link LRUCache#get} was called.
|
| 227 |
+
* - miss: the item is not in cache, and will be fetched.
|
| 228 |
+
* - hit: the item is in the cache, and was resolved immediately.
|
| 229 |
+
* - stale: the item is in the cache, but stale.
|
| 230 |
+
* - refresh: the item is in the cache, and not stale, but
|
| 231 |
+
* {@link FetchOptions.forceRefresh} was specified.
|
| 232 |
+
*/
|
| 233 |
+
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh';
|
| 234 |
+
/**
|
| 235 |
+
* `forceRefresh` option was used for either a fetch or memo operation
|
| 236 |
+
*/
|
| 237 |
+
forceRefresh?: boolean;
|
| 238 |
+
/**
|
| 239 |
+
* The {@link OptionsBase.fetchMethod} was called
|
| 240 |
+
*/
|
| 241 |
+
fetchDispatched?: true;
|
| 242 |
+
/**
|
| 243 |
+
* The cached value was updated after a successful call to
|
| 244 |
+
* {@link OptionsBase.fetchMethod}
|
| 245 |
+
*/
|
| 246 |
+
fetchUpdated?: true;
|
| 247 |
+
/**
|
| 248 |
+
* The reason for a fetch() rejection. Either the error raised by the
|
| 249 |
+
* {@link OptionsBase.fetchMethod}, or the reason for an
|
| 250 |
+
* AbortSignal.
|
| 251 |
+
*/
|
| 252 |
+
fetchError?: Error;
|
| 253 |
+
/**
|
| 254 |
+
* The fetch received an abort signal
|
| 255 |
+
*/
|
| 256 |
+
fetchAborted?: true;
|
| 257 |
+
/**
|
| 258 |
+
* The abort signal received was ignored, and the fetch was allowed to
|
| 259 |
+
* continue in the background.
|
| 260 |
+
*/
|
| 261 |
+
fetchAbortIgnored?: true;
|
| 262 |
+
/**
|
| 263 |
+
* The fetchMethod promise resolved successfully
|
| 264 |
+
*/
|
| 265 |
+
fetchResolved?: true;
|
| 266 |
+
/**
|
| 267 |
+
* The fetchMethod promise was rejected
|
| 268 |
+
*/
|
| 269 |
+
fetchRejected?: true;
|
| 270 |
+
/**
|
| 271 |
+
* The status of a {@link LRUCache#get} operation.
|
| 272 |
+
*
|
| 273 |
+
* - fetching: The item is currently being fetched. If a previous value
|
| 274 |
+
* is present and allowed, that will be returned.
|
| 275 |
+
* - stale: The item is in the cache, and is stale. If it was returned,
|
| 276 |
+
* then the `returnedStale` flag will be set.
|
| 277 |
+
* - stale-fetching: The value is being fetched in the background, but is
|
| 278 |
+
* currently stale. If the stale value was returned, then the
|
| 279 |
+
* `returnedStale` flag will be set.
|
| 280 |
+
* - hit: the item is in the cache
|
| 281 |
+
* - miss: the item is not in the cache
|
| 282 |
+
*/
|
| 283 |
+
get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching';
|
| 284 |
+
/**
|
| 285 |
+
* A fetch or get operation returned a stale value.
|
| 286 |
+
*/
|
| 287 |
+
returnedStale?: true;
|
| 288 |
+
/**
|
| 289 |
+
* A tracingChannel trace was started for this operation
|
| 290 |
+
*/
|
| 291 |
+
trace?: boolean;
|
| 292 |
+
/**
|
| 293 |
+
* A reference to the cache instance associated with this operation
|
| 294 |
+
*/
|
| 295 |
+
cache?: LRUCache<K & {}, V & {}, FC>;
|
| 296 |
+
}
|
| 297 |
+
/**
|
| 298 |
+
* options which override the options set in the LRUCache constructor
|
| 299 |
+
* when calling {@link LRUCache#fetch}.
|
| 300 |
+
*
|
| 301 |
+
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
| 302 |
+
* {@link OptionsBase.noDeleteOnFetchRejection},
|
| 303 |
+
* {@link OptionsBase.allowStaleOnFetchRejection},
|
| 304 |
+
* {@link FetchOptions.forceRefresh}, and
|
| 305 |
+
* {@link FetcherOptions.context}
|
| 306 |
+
*
|
| 307 |
+
* Any of these may be modified in the {@link OptionsBase.fetchMethod}
|
| 308 |
+
* function, but the {@link GetOptions} fields will of course have no
|
| 309 |
+
* effect, as the {@link LRUCache#get} call already happened by the time
|
| 310 |
+
* the fetchMethod is called.
|
| 311 |
+
*/
|
| 312 |
+
interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
| 313 |
+
status?: Status<K, V, FC>;
|
| 314 |
+
size?: Size;
|
| 315 |
+
}
|
| 316 |
+
/**
|
| 317 |
+
* Options that may be passed to the {@link LRUCache#fetch} method.
|
| 318 |
+
*/
|
| 319 |
+
interface FetchOptions<K, V, FC> extends FetcherFetchOptions<K, V, FC> {
|
| 320 |
+
/**
|
| 321 |
+
* Set to true to force a re-load of the existing data, even if it
|
| 322 |
+
* is not yet stale.
|
| 323 |
+
*/
|
| 324 |
+
forceRefresh?: boolean;
|
| 325 |
+
/**
|
| 326 |
+
* Context provided to the {@link OptionsBase.fetchMethod} as
|
| 327 |
+
* the {@link FetcherOptions.context} param.
|
| 328 |
+
*
|
| 329 |
+
* If the FC type is specified as unknown (the default),
|
| 330 |
+
* undefined or void, then this is optional. Otherwise, it will
|
| 331 |
+
* be required.
|
| 332 |
+
*/
|
| 333 |
+
context?: FC;
|
| 334 |
+
signal?: AbortSignal;
|
| 335 |
+
status?: Status<K, V, FC>;
|
| 336 |
+
}
|
| 337 |
+
/**
|
| 338 |
+
* Options provided to {@link LRUCache#fetch} when the FC type is something
|
| 339 |
+
* other than `unknown`, `undefined`, or `void`
|
| 340 |
+
*/
|
| 341 |
+
interface FetchOptionsWithContext<K, V, FC> extends FetchOptions<K, V, FC> {
|
| 342 |
+
context: FC;
|
| 343 |
+
}
|
| 344 |
+
/**
|
| 345 |
+
* Options provided to {@link LRUCache#fetch} when the FC type is
|
| 346 |
+
* `undefined` or `void`
|
| 347 |
+
*/
|
| 348 |
+
interface FetchOptionsNoContext<K, V, FC extends undefined | void = undefined> extends FetchOptions<K, V, FC> {
|
| 349 |
+
context?: FC;
|
| 350 |
+
}
|
| 351 |
+
interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
| 352 |
+
/**
|
| 353 |
+
* Set to true to force a re-load of the existing data, even if it
|
| 354 |
+
* is not yet stale.
|
| 355 |
+
*/
|
| 356 |
+
forceRefresh?: boolean;
|
| 357 |
+
/**
|
| 358 |
+
* Context provided to the {@link OptionsBase.memoMethod} as
|
| 359 |
+
* the {@link MemoizerOptions.context} param.
|
| 360 |
+
*
|
| 361 |
+
* If the FC type is specified as unknown (the default),
|
| 362 |
+
* undefined or void, then this is optional. Otherwise, it will
|
| 363 |
+
* be required.
|
| 364 |
+
*/
|
| 365 |
+
context?: FC;
|
| 366 |
+
status?: Status<K, V, FC>;
|
| 367 |
+
}
|
| 368 |
+
/**
|
| 369 |
+
* Options provided to {@link LRUCache#memo} when the FC type is something
|
| 370 |
+
* other than `unknown`, `undefined`, or `void`
|
| 371 |
+
*/
|
| 372 |
+
interface MemoOptionsWithContext<K, V, FC> extends MemoOptions<K, V, FC> {
|
| 373 |
+
context: FC;
|
| 374 |
+
}
|
| 375 |
+
/**
|
| 376 |
+
* Options provided to {@link LRUCache#memo} when the FC type is
|
| 377 |
+
* `undefined` or `void`
|
| 378 |
+
*/
|
| 379 |
+
interface MemoOptionsNoContext<K, V, FC extends undefined | void = undefined> extends MemoOptions<K, V, FC> {
|
| 380 |
+
context?: FC;
|
| 381 |
+
}
|
| 382 |
+
/**
|
| 383 |
+
* Options provided to the
|
| 384 |
+
* {@link OptionsBase.memoMethod} function.
|
| 385 |
+
*/
|
| 386 |
+
interface MemoizerOptions<K, V, FC = unknown> {
|
| 387 |
+
options: MemoizerMemoOptions<K, V, FC>;
|
| 388 |
+
/**
|
| 389 |
+
* Object provided in the {@link MemoOptions.context} option to
|
| 390 |
+
* {@link LRUCache#memo}
|
| 391 |
+
*/
|
| 392 |
+
context: FC;
|
| 393 |
+
}
|
| 394 |
+
/**
|
| 395 |
+
* options which override the options set in the LRUCache constructor
|
| 396 |
+
* when calling {@link LRUCache#memo}.
|
| 397 |
+
*
|
| 398 |
+
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
| 399 |
+
* {@link MemoOptions.forceRefresh}, and
|
| 400 |
+
* {@link MemoOptions.context}
|
| 401 |
+
*
|
| 402 |
+
* Any of these may be modified in the {@link OptionsBase.memoMethod}
|
| 403 |
+
* function, but the {@link GetOptions} fields will of course have no
|
| 404 |
+
* effect, as the {@link LRUCache#get} call already happened by the time
|
| 405 |
+
* the memoMethod is called.
|
| 406 |
+
*/
|
| 407 |
+
interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
| 408 |
+
status?: Status<K, V, FC>;
|
| 409 |
+
size?: Size;
|
| 410 |
+
start?: Milliseconds;
|
| 411 |
+
}
|
| 412 |
+
/**
|
| 413 |
+
* Options that may be passed to the {@link LRUCache#has} method.
|
| 414 |
+
*/
|
| 415 |
+
interface HasOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'updateAgeOnHas'> {
|
| 416 |
+
status?: Status<K, V, FC>;
|
| 417 |
+
}
|
| 418 |
+
/**
|
| 419 |
+
* Options that may be passed to the {@link LRUCache#get} method.
|
| 420 |
+
*/
|
| 421 |
+
interface GetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'> {
|
| 422 |
+
status?: Status<K, V, FC>;
|
| 423 |
+
}
|
| 424 |
+
/**
|
| 425 |
+
* Options that may be passed to the {@link LRUCache#peek} method.
|
| 426 |
+
*/
|
| 427 |
+
interface PeekOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale'> {
|
| 428 |
+
status?: Status<K, V, FC>;
|
| 429 |
+
}
|
| 430 |
+
/**
|
| 431 |
+
* Options that may be passed to the {@link LRUCache#set} method.
|
| 432 |
+
*/
|
| 433 |
+
interface SetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
| 434 |
+
/**
|
| 435 |
+
* If size tracking is enabled, then setting an explicit size
|
| 436 |
+
* in the {@link LRUCache#set} call will prevent calling the
|
| 437 |
+
* {@link OptionsBase.sizeCalculation} function.
|
| 438 |
+
*/
|
| 439 |
+
size?: Size;
|
| 440 |
+
/**
|
| 441 |
+
* If TTL tracking is enabled, then setting an explicit start
|
| 442 |
+
* time in the {@link LRUCache#set} call will override the
|
| 443 |
+
* default time from `performance.now()` or `Date.now()`.
|
| 444 |
+
*
|
| 445 |
+
* Note that it must be a valid value for whichever time-tracking
|
| 446 |
+
* method is in use.
|
| 447 |
+
*/
|
| 448 |
+
start?: Milliseconds;
|
| 449 |
+
status?: Status<K, V, FC>;
|
| 450 |
+
}
|
| 451 |
+
/**
|
| 452 |
+
* The type signature for the {@link OptionsBase.fetchMethod} option.
|
| 453 |
+
*/
|
| 454 |
+
type Fetcher<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: FetcherOptions<K, V, FC>) => Promise<V | undefined | void> | V | undefined | void;
|
| 455 |
+
/**
|
| 456 |
+
* the type signature for the {@link OptionsBase.memoMethod} option.
|
| 457 |
+
*/
|
| 458 |
+
type Memoizer<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: MemoizerOptions<K, V, FC>) => V;
|
| 459 |
+
/**
|
| 460 |
+
* Options which may be passed to the {@link LRUCache} constructor.
|
| 461 |
+
*
|
| 462 |
+
* Most of these may be overridden in the various options that use
|
| 463 |
+
* them.
|
| 464 |
+
*
|
| 465 |
+
* Despite all being technically optional, the constructor requires that
|
| 466 |
+
* a cache is at minimum limited by one or more of {@link OptionsBase.max},
|
| 467 |
+
* {@link OptionsBase.ttl}, or {@link OptionsBase.maxSize}.
|
| 468 |
+
*
|
| 469 |
+
* If {@link OptionsBase.ttl} is used alone, then it is strongly advised
|
| 470 |
+
* (and in fact required by the type definitions here) that the cache
|
| 471 |
+
* also set {@link OptionsBase.ttlAutopurge}, to prevent potentially
|
| 472 |
+
* unbounded storage.
|
| 473 |
+
*
|
| 474 |
+
* All options are also available on the {@link LRUCache} instance, making
|
| 475 |
+
* it safe to pass an LRUCache instance as the options argumemnt to
|
| 476 |
+
* make another empty cache of the same type.
|
| 477 |
+
*
|
| 478 |
+
* Some options are marked as read-only, because changing them after
|
| 479 |
+
* instantiation is not safe. Changing any of the other options will of
|
| 480 |
+
* course only have an effect on subsequent method calls.
|
| 481 |
+
*/
|
| 482 |
+
interface OptionsBase<K, V, FC> {
|
| 483 |
+
/**
|
| 484 |
+
* The maximum number of items to store in the cache before evicting
|
| 485 |
+
* old entries. This is read-only on the {@link LRUCache} instance,
|
| 486 |
+
* and may not be overridden.
|
| 487 |
+
*
|
| 488 |
+
* If set, then storage space will be pre-allocated at construction
|
| 489 |
+
* time, and the cache will perform significantly faster.
|
| 490 |
+
*
|
| 491 |
+
* Note that significantly fewer items may be stored, if
|
| 492 |
+
* {@link OptionsBase.maxSize} and/or {@link OptionsBase.ttl} are also
|
| 493 |
+
* set.
|
| 494 |
+
*
|
| 495 |
+
* **It is strongly recommended to set a `max` to prevent unbounded growth
|
| 496 |
+
* of the cache.**
|
| 497 |
+
*/
|
| 498 |
+
max?: Count;
|
| 499 |
+
/**
|
| 500 |
+
* Max time in milliseconds for items to live in cache before they are
|
| 501 |
+
* considered stale. Note that stale items are NOT preemptively removed by
|
| 502 |
+
* default, and MAY live in the cache, contributing to its LRU max, long
|
| 503 |
+
* after they have expired, unless {@link OptionsBase.ttlAutopurge} is
|
| 504 |
+
* set.
|
| 505 |
+
*
|
| 506 |
+
* If set to `0` (the default value), then that means "do not track
|
| 507 |
+
* TTL", not "expire immediately".
|
| 508 |
+
*
|
| 509 |
+
* Also, as this cache is optimized for LRU/MRU operations, some of
|
| 510 |
+
* the staleness/TTL checks will reduce performance, as they will incur
|
| 511 |
+
* overhead by deleting items.
|
| 512 |
+
*
|
| 513 |
+
* This is not primarily a TTL cache, and does not make strong TTL
|
| 514 |
+
* guarantees. There is no pre-emptive pruning of expired items, but you
|
| 515 |
+
* _may_ set a TTL on the cache, and it will treat expired items as missing
|
| 516 |
+
* when they are fetched, and delete them.
|
| 517 |
+
*
|
| 518 |
+
* Optional, but must be a non-negative integer in ms if specified.
|
| 519 |
+
*
|
| 520 |
+
* This may be overridden by passing an options object to `cache.set()`.
|
| 521 |
+
*
|
| 522 |
+
* At least one of `max`, `maxSize`, or `TTL` is required. This must be a
|
| 523 |
+
* positive integer if set.
|
| 524 |
+
*
|
| 525 |
+
* Even if ttl tracking is enabled, **it is strongly recommended to set a
|
| 526 |
+
* `max` to prevent unbounded growth of the cache.**
|
| 527 |
+
*
|
| 528 |
+
* If ttl tracking is enabled, and `max` and `maxSize` are not set,
|
| 529 |
+
* and `ttlAutopurge` is not set, then a warning will be emitted
|
| 530 |
+
* cautioning about the potential for unbounded memory consumption.
|
| 531 |
+
* (The TypeScript definitions will also discourage this.)
|
| 532 |
+
*/
|
| 533 |
+
ttl?: Milliseconds;
|
| 534 |
+
/**
|
| 535 |
+
* Minimum amount of time in ms in which to check for staleness.
|
| 536 |
+
* Defaults to 1, which means that the current time is checked
|
| 537 |
+
* at most once per millisecond.
|
| 538 |
+
*
|
| 539 |
+
* Set to 0 to check the current time every time staleness is tested.
|
| 540 |
+
* (This reduces performance, and is theoretically unnecessary.)
|
| 541 |
+
*
|
| 542 |
+
* Setting this to a higher value will improve performance somewhat
|
| 543 |
+
* while using ttl tracking, albeit at the expense of keeping stale
|
| 544 |
+
* items around a bit longer than their TTLs would indicate.
|
| 545 |
+
*
|
| 546 |
+
* @default 1
|
| 547 |
+
*/
|
| 548 |
+
ttlResolution?: Milliseconds;
|
| 549 |
+
/**
|
| 550 |
+
* Preemptively remove stale items from the cache.
|
| 551 |
+
*
|
| 552 |
+
* Note that this may *significantly* degrade performance, especially if
|
| 553 |
+
* the cache is storing a large number of items. It is almost always best
|
| 554 |
+
* to just leave the stale items in the cache, and let them fall out as new
|
| 555 |
+
* items are added.
|
| 556 |
+
*
|
| 557 |
+
* Note that this means that {@link OptionsBase.allowStale} is a bit
|
| 558 |
+
* pointless, as stale items will be deleted almost as soon as they
|
| 559 |
+
* expire.
|
| 560 |
+
*
|
| 561 |
+
* Use with caution!
|
| 562 |
+
*/
|
| 563 |
+
ttlAutopurge?: boolean;
|
| 564 |
+
/**
|
| 565 |
+
* When using time-expiring entries with `ttl`, setting this to `true` will
|
| 566 |
+
* make each item's age reset to 0 whenever it is retrieved from cache with
|
| 567 |
+
* {@link LRUCache#get}, causing it to not expire. (It can still fall out
|
| 568 |
+
* of cache based on recency of use, of course.)
|
| 569 |
+
*
|
| 570 |
+
* Has no effect if {@link OptionsBase.ttl} is not set.
|
| 571 |
+
*
|
| 572 |
+
* This may be overridden by passing an options object to `cache.get()`.
|
| 573 |
+
*/
|
| 574 |
+
updateAgeOnGet?: boolean;
|
| 575 |
+
/**
|
| 576 |
+
* When using time-expiring entries with `ttl`, setting this to `true` will
|
| 577 |
+
* make each item's age reset to 0 whenever its presence in the cache is
|
| 578 |
+
* checked with {@link LRUCache#has}, causing it to not expire. (It can
|
| 579 |
+
* still fall out of cache based on recency of use, of course.)
|
| 580 |
+
*
|
| 581 |
+
* Has no effect if {@link OptionsBase.ttl} is not set.
|
| 582 |
+
*/
|
| 583 |
+
updateAgeOnHas?: boolean;
|
| 584 |
+
/**
|
| 585 |
+
* Allow {@link LRUCache#get} and {@link LRUCache#fetch} calls to return
|
| 586 |
+
* stale data, if available.
|
| 587 |
+
*
|
| 588 |
+
* By default, if you set `ttl`, stale items will only be deleted from the
|
| 589 |
+
* cache when you `get(key)`. That is, it's not preemptively pruning items,
|
| 590 |
+
* unless {@link OptionsBase.ttlAutopurge} is set.
|
| 591 |
+
*
|
| 592 |
+
* If you set `allowStale:true`, it'll return the stale value *as well as*
|
| 593 |
+
* deleting it. If you don't set this, then it'll return `undefined` when
|
| 594 |
+
* you try to get a stale entry.
|
| 595 |
+
*
|
| 596 |
+
* Note that when a stale entry is fetched, _even if it is returned due to
|
| 597 |
+
* `allowStale` being set_, it is removed from the cache immediately. You
|
| 598 |
+
* can suppress this behavior by setting
|
| 599 |
+
* {@link OptionsBase.noDeleteOnStaleGet}, either in the constructor, or in
|
| 600 |
+
* the options provided to {@link LRUCache#get}.
|
| 601 |
+
*
|
| 602 |
+
* This may be overridden by passing an options object to `cache.get()`.
|
| 603 |
+
* The `cache.has()` method will always return `false` for stale items.
|
| 604 |
+
*
|
| 605 |
+
* Only relevant if a ttl is set.
|
| 606 |
+
*/
|
| 607 |
+
allowStale?: boolean;
|
| 608 |
+
/**
|
| 609 |
+
* Function that is called on items when they are dropped from the
|
| 610 |
+
* cache, as `dispose(value, key, reason)`.
|
| 611 |
+
*
|
| 612 |
+
* This can be handy if you want to close file descriptors or do
|
| 613 |
+
* other cleanup tasks when items are no longer stored in the cache.
|
| 614 |
+
*
|
| 615 |
+
* **NOTE**: It is called _before_ the item has been fully removed
|
| 616 |
+
* from the cache, so if you want to put it right back in, you need
|
| 617 |
+
* to wait until the next tick. If you try to add it back in during
|
| 618 |
+
* the `dispose()` function call, it will break things in subtle and
|
| 619 |
+
* weird ways.
|
| 620 |
+
*
|
| 621 |
+
* Unlike several other options, this may _not_ be overridden by
|
| 622 |
+
* passing an option to `set()`, for performance reasons.
|
| 623 |
+
*
|
| 624 |
+
* The `reason` will be one of the following strings, corresponding
|
| 625 |
+
* to the reason for the item's deletion:
|
| 626 |
+
*
|
| 627 |
+
* - `evict` Item was evicted to make space for a new addition
|
| 628 |
+
* - `set` Item was overwritten by a new value
|
| 629 |
+
* - `expire` Item expired its TTL
|
| 630 |
+
* - `fetch` Item was deleted due to a failed or aborted fetch, or a
|
| 631 |
+
* fetchMethod returning `undefined.
|
| 632 |
+
* - `delete` Item was removed by explicit `cache.delete(key)`,
|
| 633 |
+
* `cache.clear()`, or `cache.set(key, undefined)`.
|
| 634 |
+
*/
|
| 635 |
+
dispose?: Disposer<K, V>;
|
| 636 |
+
/**
|
| 637 |
+
* Function that is called when new items are inserted into the cache,
|
| 638 |
+
* as `onInsert(value, key, reason)`.
|
| 639 |
+
*
|
| 640 |
+
* This can be useful if you need to perform actions when an item is
|
| 641 |
+
* added, such as logging or tracking insertions.
|
| 642 |
+
*
|
| 643 |
+
* Unlike some other options, this may _not_ be overridden by passing
|
| 644 |
+
* an option to `set()`, for performance and consistency reasons.
|
| 645 |
+
*/
|
| 646 |
+
onInsert?: Inserter<K, V>;
|
| 647 |
+
/**
|
| 648 |
+
* The same as {@link OptionsBase.dispose}, but called *after* the entry
|
| 649 |
+
* is completely removed and the cache is once again in a clean state.
|
| 650 |
+
*
|
| 651 |
+
* It is safe to add an item right back into the cache at this point.
|
| 652 |
+
* However, note that it is *very* easy to inadvertently create infinite
|
| 653 |
+
* recursion this way.
|
| 654 |
+
*/
|
| 655 |
+
disposeAfter?: Disposer<K, V>;
|
| 656 |
+
/**
|
| 657 |
+
* Set to true to suppress calling the
|
| 658 |
+
* {@link OptionsBase.dispose} function if the entry key is
|
| 659 |
+
* still accessible within the cache.
|
| 660 |
+
*
|
| 661 |
+
* This may be overridden by passing an options object to
|
| 662 |
+
* {@link LRUCache#set}.
|
| 663 |
+
*
|
| 664 |
+
* Only relevant if `dispose` or `disposeAfter` are set.
|
| 665 |
+
*/
|
| 666 |
+
noDisposeOnSet?: boolean;
|
| 667 |
+
/**
|
| 668 |
+
* Boolean flag to tell the cache to not update the TTL when setting a new
|
| 669 |
+
* value for an existing key (ie, when updating a value rather than
|
| 670 |
+
* inserting a new value). Note that the TTL value is _always_ set (if
|
| 671 |
+
* provided) when adding a new entry into the cache.
|
| 672 |
+
*
|
| 673 |
+
* Has no effect if a {@link OptionsBase.ttl} is not set.
|
| 674 |
+
*
|
| 675 |
+
* May be passed as an option to {@link LRUCache#set}.
|
| 676 |
+
*/
|
| 677 |
+
noUpdateTTL?: boolean;
|
| 678 |
+
/**
|
| 679 |
+
* Set to a positive integer to track the sizes of items added to the
|
| 680 |
+
* cache, and automatically evict items in order to stay below this size.
|
| 681 |
+
* Note that this may result in fewer than `max` items being stored.
|
| 682 |
+
*
|
| 683 |
+
* Attempting to add an item to the cache whose calculated size is greater
|
| 684 |
+
* that this amount will be a no-op. The item will not be cached, and no
|
| 685 |
+
* other items will be evicted.
|
| 686 |
+
*
|
| 687 |
+
* Optional, must be a positive integer if provided.
|
| 688 |
+
*
|
| 689 |
+
* Sets `maxEntrySize` to the same value, unless a different value is
|
| 690 |
+
* provided for `maxEntrySize`.
|
| 691 |
+
*
|
| 692 |
+
* At least one of `max`, `maxSize`, or `TTL` is required. This must be a
|
| 693 |
+
* positive integer if set.
|
| 694 |
+
*
|
| 695 |
+
* Even if size tracking is enabled, **it is strongly recommended to set a
|
| 696 |
+
* `max` to prevent unbounded growth of the cache.**
|
| 697 |
+
*
|
| 698 |
+
* Note also that size tracking can negatively impact performance,
|
| 699 |
+
* though for most cases, only minimally.
|
| 700 |
+
*/
|
| 701 |
+
maxSize?: Size;
|
| 702 |
+
/**
|
| 703 |
+
* The effective size for background fetch promises.
|
| 704 |
+
*
|
| 705 |
+
* This has no effect unless `maxSize` and `sizeCalculation` are used,
|
| 706 |
+
* and a {@link LRUCache.OptionsBase.fetchMethod} is provided to
|
| 707 |
+
* support {@link LRUCache#fetch}.
|
| 708 |
+
*
|
| 709 |
+
* If a stale value is present in the cache, then the effective size of
|
| 710 |
+
* the background fetch is the size of the stale item it will eventually
|
| 711 |
+
* replace. If not, then this value is used as its effective size.
|
| 712 |
+
*
|
| 713 |
+
* @default 1
|
| 714 |
+
*/
|
| 715 |
+
backgroundFetchSize?: number;
|
| 716 |
+
/**
|
| 717 |
+
* The maximum allowed size for any single item in the cache.
|
| 718 |
+
*
|
| 719 |
+
* If a larger item is passed to {@link LRUCache#set} or returned by a
|
| 720 |
+
* {@link OptionsBase.fetchMethod} or {@link OptionsBase.memoMethod}, then
|
| 721 |
+
* it will not be stored in the cache.
|
| 722 |
+
*
|
| 723 |
+
* Attempting to add an item whose calculated size is greater than
|
| 724 |
+
* this amount will not cache the item or evict any old items, but
|
| 725 |
+
* WILL delete an existing value if one is already present.
|
| 726 |
+
*
|
| 727 |
+
* Optional, must be a positive integer if provided. Defaults to
|
| 728 |
+
* the value of `maxSize` if provided.
|
| 729 |
+
*/
|
| 730 |
+
maxEntrySize?: Size;
|
| 731 |
+
/**
|
| 732 |
+
* A function that returns a number indicating the item's size.
|
| 733 |
+
*
|
| 734 |
+
* Requires {@link OptionsBase.maxSize} to be set.
|
| 735 |
+
*
|
| 736 |
+
* If not provided, and {@link OptionsBase.maxSize} or
|
| 737 |
+
* {@link OptionsBase.maxEntrySize} are set, then all
|
| 738 |
+
* {@link LRUCache#set} calls **must** provide an explicit
|
| 739 |
+
* {@link SetOptions.size} or sizeCalculation param.
|
| 740 |
+
*/
|
| 741 |
+
sizeCalculation?: SizeCalculator<K, V>;
|
| 742 |
+
/**
|
| 743 |
+
* Method that provides the implementation for {@link LRUCache#fetch}
|
| 744 |
+
*
|
| 745 |
+
* ```ts
|
| 746 |
+
* fetchMethod(key, staleValue, { signal, options, context })
|
| 747 |
+
* ```
|
| 748 |
+
*
|
| 749 |
+
* If `fetchMethod` is not provided, then `cache.fetch(key)` is equivalent
|
| 750 |
+
* to `Promise.resolve(cache.get(key))`.
|
| 751 |
+
*
|
| 752 |
+
* If at any time, `signal.aborted` is set to `true`, or if the
|
| 753 |
+
* `signal.onabort` method is called, or if it emits an `'abort'` event
|
| 754 |
+
* which you can listen to with `addEventListener`, then that means that
|
| 755 |
+
* the fetch should be abandoned. This may be passed along to async
|
| 756 |
+
* functions aware of AbortController/AbortSignal behavior.
|
| 757 |
+
*
|
| 758 |
+
* The `fetchMethod` should **only** return `undefined` or a Promise
|
| 759 |
+
* resolving to `undefined` if the AbortController signaled an `abort`
|
| 760 |
+
* event. In all other cases, it should return or resolve to a value
|
| 761 |
+
* suitable for adding to the cache.
|
| 762 |
+
*
|
| 763 |
+
* The `options` object is a union of the options that may be provided to
|
| 764 |
+
* `set()` and `get()`. If they are modified, then that will result in
|
| 765 |
+
* modifying the settings to `cache.set()` when the value is resolved, and
|
| 766 |
+
* in the case of
|
| 767 |
+
* {@link OptionsBase.noDeleteOnFetchRejection} and
|
| 768 |
+
* {@link OptionsBase.allowStaleOnFetchRejection}, the handling of
|
| 769 |
+
* `fetchMethod` failures.
|
| 770 |
+
*
|
| 771 |
+
* For example, a DNS cache may update the TTL based on the value returned
|
| 772 |
+
* from a remote DNS server by changing `options.ttl` in the `fetchMethod`.
|
| 773 |
+
*/
|
| 774 |
+
fetchMethod?: Fetcher<K, V, FC>;
|
| 775 |
+
/**
|
| 776 |
+
* Method that provides the implementation for {@link LRUCache#memo}
|
| 777 |
+
*/
|
| 778 |
+
memoMethod?: Memoizer<K, V, FC>;
|
| 779 |
+
/**
|
| 780 |
+
* Set to true to suppress the deletion of stale data when a
|
| 781 |
+
* {@link OptionsBase.fetchMethod} returns a rejected promise.
|
| 782 |
+
*/
|
| 783 |
+
noDeleteOnFetchRejection?: boolean;
|
| 784 |
+
/**
|
| 785 |
+
* Do not delete stale items when they are retrieved with
|
| 786 |
+
* {@link LRUCache#get}.
|
| 787 |
+
*
|
| 788 |
+
* Note that the `get` return value will still be `undefined`
|
| 789 |
+
* unless {@link OptionsBase.allowStale} is true.
|
| 790 |
+
*
|
| 791 |
+
* When using time-expiring entries with `ttl`, by default stale
|
| 792 |
+
* items will be removed from the cache when the key is accessed
|
| 793 |
+
* with `cache.get()`.
|
| 794 |
+
*
|
| 795 |
+
* Setting this option will cause stale items to remain in the cache, until
|
| 796 |
+
* they are explicitly deleted with `cache.delete(key)`, or retrieved with
|
| 797 |
+
* `noDeleteOnStaleGet` set to `false`.
|
| 798 |
+
*
|
| 799 |
+
* This may be overridden by passing an options object to `cache.get()`.
|
| 800 |
+
*
|
| 801 |
+
* Only relevant if a ttl is used.
|
| 802 |
+
*/
|
| 803 |
+
noDeleteOnStaleGet?: boolean;
|
| 804 |
+
/**
|
| 805 |
+
* Set to true to allow returning stale data when a
|
| 806 |
+
* {@link OptionsBase.fetchMethod} throws an error or returns a rejected
|
| 807 |
+
* promise.
|
| 808 |
+
*
|
| 809 |
+
* This differs from using {@link OptionsBase.allowStale} in that stale
|
| 810 |
+
* data will ONLY be returned in the case that the {@link LRUCache#fetch}
|
| 811 |
+
* fails, not any other times.
|
| 812 |
+
*
|
| 813 |
+
* If a `fetchMethod` fails, and there is no stale value available, the
|
| 814 |
+
* `fetch()` will resolve to `undefined`. Ie, all `fetchMethod` errors are
|
| 815 |
+
* suppressed.
|
| 816 |
+
*
|
| 817 |
+
* Implies `noDeleteOnFetchRejection`.
|
| 818 |
+
*
|
| 819 |
+
* This may be set in calls to `fetch()`, or defaulted on the constructor,
|
| 820 |
+
* or overridden by modifying the options object in the `fetchMethod`.
|
| 821 |
+
*/
|
| 822 |
+
allowStaleOnFetchRejection?: boolean;
|
| 823 |
+
/**
|
| 824 |
+
* Set to true to return a stale value from the cache when the
|
| 825 |
+
* `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches
|
| 826 |
+
* an `'abort'` event, whether user-triggered, or due to internal cache
|
| 827 |
+
* behavior.
|
| 828 |
+
*
|
| 829 |
+
* Unless {@link OptionsBase.ignoreFetchAbort} is also set, the underlying
|
| 830 |
+
* {@link OptionsBase.fetchMethod} will still be considered canceled, and
|
| 831 |
+
* any value it returns will be ignored and not cached.
|
| 832 |
+
*
|
| 833 |
+
* Caveat: since fetches are aborted when a new value is explicitly
|
| 834 |
+
* set in the cache, this can lead to fetch returning a stale value,
|
| 835 |
+
* since that was the fallback value _at the moment the `fetch()` was
|
| 836 |
+
* initiated_, even though the new updated value is now present in
|
| 837 |
+
* the cache.
|
| 838 |
+
*
|
| 839 |
+
* For example:
|
| 840 |
+
*
|
| 841 |
+
* ```ts
|
| 842 |
+
* const cache = new LRUCache<string, any>({
|
| 843 |
+
* ttl: 100,
|
| 844 |
+
* fetchMethod: async (url, oldValue, { signal }) => {
|
| 845 |
+
* const res = await fetch(url, { signal })
|
| 846 |
+
* return await res.json()
|
| 847 |
+
* }
|
| 848 |
+
* })
|
| 849 |
+
* cache.set('https://example.com/', { some: 'data' })
|
| 850 |
+
* // 100ms go by...
|
| 851 |
+
* const result = cache.fetch('https://example.com/')
|
| 852 |
+
* cache.set('https://example.com/', { other: 'thing' })
|
| 853 |
+
* console.log(await result) // { some: 'data' }
|
| 854 |
+
* console.log(cache.get('https://example.com/')) // { other: 'thing' }
|
| 855 |
+
* ```
|
| 856 |
+
*/
|
| 857 |
+
allowStaleOnFetchAbort?: boolean;
|
| 858 |
+
/**
|
| 859 |
+
* Set to true to ignore the `abort` event emitted by the `AbortSignal`
|
| 860 |
+
* object passed to {@link OptionsBase.fetchMethod}, and still cache the
|
| 861 |
+
* resulting resolution value, as long as it is not `undefined`.
|
| 862 |
+
*
|
| 863 |
+
* When used on its own, this means aborted {@link LRUCache#fetch} calls
|
| 864 |
+
* are not immediately resolved or rejected when they are aborted, and
|
| 865 |
+
* instead take the full time to await.
|
| 866 |
+
*
|
| 867 |
+
* When used with {@link OptionsBase.allowStaleOnFetchAbort}, aborted
|
| 868 |
+
* {@link LRUCache#fetch} calls will resolve immediately to their stale
|
| 869 |
+
* cached value or `undefined`, and will continue to process and eventually
|
| 870 |
+
* update the cache when they resolve, as long as the resulting value is
|
| 871 |
+
* not `undefined`, thus supporting a "return stale on timeout while
|
| 872 |
+
* refreshing" mechanism by passing `AbortSignal.timeout(n)` as the signal.
|
| 873 |
+
*
|
| 874 |
+
* For example:
|
| 875 |
+
*
|
| 876 |
+
* ```ts
|
| 877 |
+
* const c = new LRUCache({
|
| 878 |
+
* ttl: 100,
|
| 879 |
+
* ignoreFetchAbort: true,
|
| 880 |
+
* allowStaleOnFetchAbort: true,
|
| 881 |
+
* fetchMethod: async (key, oldValue, { signal }) => {
|
| 882 |
+
* // note: do NOT pass the signal to fetch()!
|
| 883 |
+
* // let's say this fetch can take a long time.
|
| 884 |
+
* const res = await fetch(`https://slow-backend-server/${key}`)
|
| 885 |
+
* return await res.json()
|
| 886 |
+
* },
|
| 887 |
+
* })
|
| 888 |
+
*
|
| 889 |
+
* // this will return the stale value after 100ms, while still
|
| 890 |
+
* // updating in the background for next time.
|
| 891 |
+
* const val = await c.fetch('key', { signal: AbortSignal.timeout(100) })
|
| 892 |
+
* ```
|
| 893 |
+
*
|
| 894 |
+
* **Note**: regardless of this setting, an `abort` event _is still
|
| 895 |
+
* emitted on the `AbortSignal` object_, so may result in invalid results
|
| 896 |
+
* when passed to other underlying APIs that use AbortSignals.
|
| 897 |
+
*
|
| 898 |
+
* This may be overridden in the {@link OptionsBase.fetchMethod} or the
|
| 899 |
+
* call to {@link LRUCache#fetch}.
|
| 900 |
+
*/
|
| 901 |
+
ignoreFetchAbort?: boolean;
|
| 902 |
+
/**
|
| 903 |
+
* In some cases, you may want to swap out the performance/Date object
|
| 904 |
+
* used for TTL tracking. This should almost certainly NOT be done in
|
| 905 |
+
* production environments!
|
| 906 |
+
*
|
| 907 |
+
* This value defaults to `global.performance` if it has a `now()` method,
|
| 908 |
+
* or the `global.Date` object otherwise.
|
| 909 |
+
*/
|
| 910 |
+
perf?: Perf;
|
| 911 |
+
}
|
| 912 |
+
interface OptionsMaxLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
| 913 |
+
max: Count;
|
| 914 |
+
}
|
| 915 |
+
interface OptionsTTLLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
| 916 |
+
ttl: Milliseconds;
|
| 917 |
+
ttlAutopurge: boolean;
|
| 918 |
+
}
|
| 919 |
+
interface OptionsSizeLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
| 920 |
+
maxSize: Size;
|
| 921 |
+
}
|
| 922 |
+
/**
|
| 923 |
+
* The valid safe options for the {@link LRUCache} constructor
|
| 924 |
+
*/
|
| 925 |
+
type Options<K, V, FC> = OptionsMaxLimit<K, V, FC> | OptionsSizeLimit<K, V, FC> | OptionsTTLLimit<K, V, FC>;
|
| 926 |
+
/**
|
| 927 |
+
* Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump},
|
| 928 |
+
* and returned by {@link LRUCache#info}.
|
| 929 |
+
*/
|
| 930 |
+
interface Entry<V> {
|
| 931 |
+
value: V;
|
| 932 |
+
ttl?: Milliseconds;
|
| 933 |
+
size?: Size;
|
| 934 |
+
start?: Milliseconds;
|
| 935 |
+
}
|
| 936 |
+
}
|
| 937 |
+
/**
|
| 938 |
+
* Default export, the thing you're using this module to get.
|
| 939 |
+
*
|
| 940 |
+
* The `K` and `V` types define the key and value types, respectively. The
|
| 941 |
+
* optional `FC` type defines the type of the `context` object passed to
|
| 942 |
+
* `cache.fetch()` and `cache.memo()`.
|
| 943 |
+
*
|
| 944 |
+
* Keys and values **must not** be `null` or `undefined`.
|
| 945 |
+
*
|
| 946 |
+
* All properties from the options object (with the exception of `max`,
|
| 947 |
+
* `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
|
| 948 |
+
* added as normal public members. (The listed options are read-only getters.)
|
| 949 |
+
*
|
| 950 |
+
* Changing any of these will alter the defaults for subsequent method calls.
|
| 951 |
+
*/
|
| 952 |
+
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
| 953 |
+
#private;
|
| 954 |
+
/**
|
| 955 |
+
* {@link LRUCache.OptionsBase.perf}
|
| 956 |
+
*/
|
| 957 |
+
get perf(): Perf;
|
| 958 |
+
/**
|
| 959 |
+
* {@link LRUCache.OptionsBase.ttl}
|
| 960 |
+
*/
|
| 961 |
+
ttl: LRUCache.Milliseconds;
|
| 962 |
+
/**
|
| 963 |
+
* {@link LRUCache.OptionsBase.ttlResolution}
|
| 964 |
+
*/
|
| 965 |
+
ttlResolution: LRUCache.Milliseconds;
|
| 966 |
+
/**
|
| 967 |
+
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
| 968 |
+
*/
|
| 969 |
+
ttlAutopurge: boolean;
|
| 970 |
+
/**
|
| 971 |
+
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
| 972 |
+
*/
|
| 973 |
+
updateAgeOnGet: boolean;
|
| 974 |
+
/**
|
| 975 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
| 976 |
+
*/
|
| 977 |
+
updateAgeOnHas: boolean;
|
| 978 |
+
/**
|
| 979 |
+
* {@link LRUCache.OptionsBase.allowStale}
|
| 980 |
+
*/
|
| 981 |
+
allowStale: boolean;
|
| 982 |
+
/**
|
| 983 |
+
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
| 984 |
+
*/
|
| 985 |
+
noDisposeOnSet: boolean;
|
| 986 |
+
/**
|
| 987 |
+
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
| 988 |
+
*/
|
| 989 |
+
noUpdateTTL: boolean;
|
| 990 |
+
/**
|
| 991 |
+
* {@link LRUCache.OptionsBase.maxEntrySize}
|
| 992 |
+
*/
|
| 993 |
+
maxEntrySize: LRUCache.Size;
|
| 994 |
+
/**
|
| 995 |
+
* {@link LRUCache.OptionsBase.sizeCalculation}
|
| 996 |
+
*/
|
| 997 |
+
sizeCalculation?: LRUCache.SizeCalculator<K, V>;
|
| 998 |
+
/**
|
| 999 |
+
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
| 1000 |
+
*/
|
| 1001 |
+
noDeleteOnFetchRejection: boolean;
|
| 1002 |
+
/**
|
| 1003 |
+
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
| 1004 |
+
*/
|
| 1005 |
+
noDeleteOnStaleGet: boolean;
|
| 1006 |
+
/**
|
| 1007 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
| 1008 |
+
*/
|
| 1009 |
+
allowStaleOnFetchAbort: boolean;
|
| 1010 |
+
/**
|
| 1011 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
| 1012 |
+
*/
|
| 1013 |
+
allowStaleOnFetchRejection: boolean;
|
| 1014 |
+
/**
|
| 1015 |
+
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
| 1016 |
+
*/
|
| 1017 |
+
ignoreFetchAbort: boolean;
|
| 1018 |
+
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
| 1019 |
+
backgroundFetchSize: number;
|
| 1020 |
+
/**
|
| 1021 |
+
* Do not call this method unless you need to inspect the
|
| 1022 |
+
* inner workings of the cache. If anything returned by this
|
| 1023 |
+
* object is modified in any way, strange breakage may occur.
|
| 1024 |
+
*
|
| 1025 |
+
* These fields are private for a reason!
|
| 1026 |
+
*
|
| 1027 |
+
* @internal
|
| 1028 |
+
*/
|
| 1029 |
+
static unsafeExposeInternals<K extends {}, V extends {}, FC extends unknown = unknown>(c: LRUCache<K, V, FC>): {
|
| 1030 |
+
starts: ZeroArray | undefined;
|
| 1031 |
+
ttls: ZeroArray | undefined;
|
| 1032 |
+
autopurgeTimers: (NodeJS.Timeout | undefined)[] | undefined;
|
| 1033 |
+
sizes: ZeroArray | undefined;
|
| 1034 |
+
keyMap: Map<K, number>;
|
| 1035 |
+
keyList: (K | undefined)[];
|
| 1036 |
+
valList: (V | BackgroundFetch<V> | undefined)[];
|
| 1037 |
+
next: NumberArray;
|
| 1038 |
+
prev: NumberArray;
|
| 1039 |
+
readonly head: Index;
|
| 1040 |
+
readonly tail: Index;
|
| 1041 |
+
free: StackLike;
|
| 1042 |
+
isBackgroundFetch: (p: unknown) => p is BackgroundFetch<V>;
|
| 1043 |
+
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: unknown) => BackgroundFetch<V>;
|
| 1044 |
+
moveToTail: (index: number) => void;
|
| 1045 |
+
indexes: (options?: {
|
| 1046 |
+
allowStale: boolean;
|
| 1047 |
+
}) => Generator<Index, void, unknown>;
|
| 1048 |
+
rindexes: (options?: {
|
| 1049 |
+
allowStale: boolean;
|
| 1050 |
+
}) => Generator<Index, void, unknown>;
|
| 1051 |
+
isStale: (index: number | undefined) => boolean;
|
| 1052 |
+
};
|
| 1053 |
+
/**
|
| 1054 |
+
* {@link LRUCache.OptionsBase.max} (read-only)
|
| 1055 |
+
*/
|
| 1056 |
+
get max(): LRUCache.Count;
|
| 1057 |
+
/**
|
| 1058 |
+
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
| 1059 |
+
*/
|
| 1060 |
+
get maxSize(): LRUCache.Count;
|
| 1061 |
+
/**
|
| 1062 |
+
* The total computed size of items in the cache (read-only)
|
| 1063 |
+
*/
|
| 1064 |
+
get calculatedSize(): LRUCache.Size;
|
| 1065 |
+
/**
|
| 1066 |
+
* The number of items stored in the cache (read-only)
|
| 1067 |
+
*/
|
| 1068 |
+
get size(): LRUCache.Count;
|
| 1069 |
+
/**
|
| 1070 |
+
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
| 1071 |
+
*/
|
| 1072 |
+
get fetchMethod(): LRUCache.Fetcher<K, V, FC> | undefined;
|
| 1073 |
+
get memoMethod(): LRUCache.Memoizer<K, V, FC> | undefined;
|
| 1074 |
+
/**
|
| 1075 |
+
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
| 1076 |
+
*/
|
| 1077 |
+
get dispose(): LRUCache.Disposer<K, V> | undefined;
|
| 1078 |
+
/**
|
| 1079 |
+
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
| 1080 |
+
*/
|
| 1081 |
+
get onInsert(): LRUCache.Inserter<K, V> | undefined;
|
| 1082 |
+
/**
|
| 1083 |
+
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
| 1084 |
+
*/
|
| 1085 |
+
get disposeAfter(): LRUCache.Disposer<K, V> | undefined;
|
| 1086 |
+
constructor(options: LRUCache.Options<K, V, FC> | LRUCache<K, V, FC>);
|
| 1087 |
+
/**
|
| 1088 |
+
* Return the number of ms left in the item's TTL. If item is not in cache,
|
| 1089 |
+
* returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
|
| 1090 |
+
*/
|
| 1091 |
+
getRemainingTTL(key: K): number;
|
| 1092 |
+
/**
|
| 1093 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 1094 |
+
* in order from most recently used to least recently used.
|
| 1095 |
+
*/
|
| 1096 |
+
entries(): Generator<[K, V], void, unknown>;
|
| 1097 |
+
/**
|
| 1098 |
+
* Inverse order version of {@link LRUCache.entries}
|
| 1099 |
+
*
|
| 1100 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 1101 |
+
* in order from least recently used to most recently used.
|
| 1102 |
+
*/
|
| 1103 |
+
rentries(): Generator<(K | V)[], void, unknown>;
|
| 1104 |
+
/**
|
| 1105 |
+
* Return a generator yielding the keys in the cache,
|
| 1106 |
+
* in order from most recently used to least recently used.
|
| 1107 |
+
*/
|
| 1108 |
+
keys(): Generator<K, void, unknown>;
|
| 1109 |
+
/**
|
| 1110 |
+
* Inverse order version of {@link LRUCache.keys}
|
| 1111 |
+
*
|
| 1112 |
+
* Return a generator yielding the keys in the cache,
|
| 1113 |
+
* in order from least recently used to most recently used.
|
| 1114 |
+
*/
|
| 1115 |
+
rkeys(): Generator<K, void, unknown>;
|
| 1116 |
+
/**
|
| 1117 |
+
* Return a generator yielding the values in the cache,
|
| 1118 |
+
* in order from most recently used to least recently used.
|
| 1119 |
+
*/
|
| 1120 |
+
values(): Generator<V, void, unknown>;
|
| 1121 |
+
/**
|
| 1122 |
+
* Inverse order version of {@link LRUCache.values}
|
| 1123 |
+
*
|
| 1124 |
+
* Return a generator yielding the values in the cache,
|
| 1125 |
+
* in order from least recently used to most recently used.
|
| 1126 |
+
*/
|
| 1127 |
+
rvalues(): Generator<V | undefined, void, unknown>;
|
| 1128 |
+
/**
|
| 1129 |
+
* Iterating over the cache itself yields the same results as
|
| 1130 |
+
* {@link LRUCache.entries}
|
| 1131 |
+
*/
|
| 1132 |
+
[Symbol.iterator](): Generator<[K, V], void, unknown>;
|
| 1133 |
+
/**
|
| 1134 |
+
* A String value that is used in the creation of the default string
|
| 1135 |
+
* description of an object. Called by the built-in method
|
| 1136 |
+
* `Object.prototype.toString`.
|
| 1137 |
+
*/
|
| 1138 |
+
[Symbol.toStringTag]: string;
|
| 1139 |
+
/**
|
| 1140 |
+
* Find a value for which the supplied fn method returns a truthy value,
|
| 1141 |
+
* similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
|
| 1142 |
+
*/
|
| 1143 |
+
find(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => boolean, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
|
| 1144 |
+
/**
|
| 1145 |
+
* Call the supplied function on each item in the cache, in order from most
|
| 1146 |
+
* recently used to least recently used.
|
| 1147 |
+
*
|
| 1148 |
+
* `fn` is called as `fn(value, key, cache)`.
|
| 1149 |
+
*
|
| 1150 |
+
* If `thisp` is provided, function will be called in the `this`-context of
|
| 1151 |
+
* the provided object, or the cache if no `thisp` object is provided.
|
| 1152 |
+
*
|
| 1153 |
+
* Does not update age or recenty of use, or iterate over stale values.
|
| 1154 |
+
*/
|
| 1155 |
+
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
| 1156 |
+
/**
|
| 1157 |
+
* The same as {@link LRUCache.forEach} but items are iterated over in
|
| 1158 |
+
* reverse order. (ie, less recently used items are iterated over first.)
|
| 1159 |
+
*/
|
| 1160 |
+
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
| 1161 |
+
/**
|
| 1162 |
+
* Delete any stale entries. Returns true if anything was removed,
|
| 1163 |
+
* false otherwise.
|
| 1164 |
+
*/
|
| 1165 |
+
purgeStale(): boolean;
|
| 1166 |
+
/**
|
| 1167 |
+
* Get the extended info about a given entry, to get its value, size, and
|
| 1168 |
+
* TTL info simultaneously. Returns `undefined` if the key is not present.
|
| 1169 |
+
*
|
| 1170 |
+
* Unlike {@link LRUCache#dump}, which is designed to be portable and survive
|
| 1171 |
+
* serialization, the `start` value is always the current timestamp, and the
|
| 1172 |
+
* `ttl` is a calculated remaining time to live (negative if expired).
|
| 1173 |
+
*
|
| 1174 |
+
* Always returns stale values, if their info is found in the cache, so be
|
| 1175 |
+
* sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
|
| 1176 |
+
* if relevant.
|
| 1177 |
+
*/
|
| 1178 |
+
info(key: K): LRUCache.Entry<V> | undefined;
|
| 1179 |
+
/**
|
| 1180 |
+
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
| 1181 |
+
* passed to {@link LRUCache#load}.
|
| 1182 |
+
*
|
| 1183 |
+
* The `start` fields are calculated relative to a portable `Date.now()`
|
| 1184 |
+
* timestamp, even if `performance.now()` is available.
|
| 1185 |
+
*
|
| 1186 |
+
* Stale entries are always included in the `dump`, even if
|
| 1187 |
+
* {@link LRUCache.OptionsBase.allowStale} is false.
|
| 1188 |
+
*
|
| 1189 |
+
* Note: this returns an actual array, not a generator, so it can be more
|
| 1190 |
+
* easily passed around.
|
| 1191 |
+
*/
|
| 1192 |
+
dump(): [K, LRUCache.Entry<V>][];
|
| 1193 |
+
/**
|
| 1194 |
+
* Reset the cache and load in the items in entries in the order listed.
|
| 1195 |
+
*
|
| 1196 |
+
* The shape of the resulting cache may be different if the same options are
|
| 1197 |
+
* not used in both caches.
|
| 1198 |
+
*
|
| 1199 |
+
* The `start` fields are assumed to be calculated relative to a portable
|
| 1200 |
+
* `Date.now()` timestamp, even if `performance.now()` is available.
|
| 1201 |
+
*/
|
| 1202 |
+
load(arr: [K, LRUCache.Entry<V>][]): void;
|
| 1203 |
+
/**
|
| 1204 |
+
* Add a value to the cache.
|
| 1205 |
+
*
|
| 1206 |
+
* Note: if `undefined` is specified as a value, this is an alias for
|
| 1207 |
+
* {@link LRUCache#delete}
|
| 1208 |
+
*
|
| 1209 |
+
* Fields on the {@link LRUCache.SetOptions} options param will override
|
| 1210 |
+
* their corresponding values in the constructor options for the scope
|
| 1211 |
+
* of this single `set()` operation.
|
| 1212 |
+
*
|
| 1213 |
+
* If `start` is provided, then that will set the effective start
|
| 1214 |
+
* time for the TTL calculation. Note that this must be a previous
|
| 1215 |
+
* value of `performance.now()` if supported, or a previous value of
|
| 1216 |
+
* `Date.now()` if not.
|
| 1217 |
+
*
|
| 1218 |
+
* Options object may also include `size`, which will prevent
|
| 1219 |
+
* calling the `sizeCalculation` function and just use the specified
|
| 1220 |
+
* number if it is a positive integer, and `noDisposeOnSet` which
|
| 1221 |
+
* will prevent calling a `dispose` function in the case of
|
| 1222 |
+
* overwrites.
|
| 1223 |
+
*
|
| 1224 |
+
* If the `size` (or return value of `sizeCalculation`) for a given
|
| 1225 |
+
* entry is greater than `maxEntrySize`, then the item will not be
|
| 1226 |
+
* added to the cache.
|
| 1227 |
+
*
|
| 1228 |
+
* Will update the recency of the entry.
|
| 1229 |
+
*
|
| 1230 |
+
* If the value is `undefined`, then this is an alias for
|
| 1231 |
+
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
| 1232 |
+
*/
|
| 1233 |
+
set(k: K, v: V | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
| 1234 |
+
/**
|
| 1235 |
+
* Evict the least recently used item, returning its value or
|
| 1236 |
+
* `undefined` if cache is empty.
|
| 1237 |
+
*/
|
| 1238 |
+
pop(): V | undefined;
|
| 1239 |
+
/**
|
| 1240 |
+
* Check if a key is in the cache, without updating the recency of use.
|
| 1241 |
+
* Will return false if the item is stale, even though it is technically
|
| 1242 |
+
* in the cache.
|
| 1243 |
+
*
|
| 1244 |
+
* Check if a key is in the cache, without updating the recency of
|
| 1245 |
+
* use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
|
| 1246 |
+
* to `true` in either the options or the constructor.
|
| 1247 |
+
*
|
| 1248 |
+
* Will return `false` if the item is stale, even though it is technically in
|
| 1249 |
+
* the cache. The difference can be determined (if it matters) by using a
|
| 1250 |
+
* `status` argument, and inspecting the `has` field.
|
| 1251 |
+
*
|
| 1252 |
+
* Will not update item age unless
|
| 1253 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
| 1254 |
+
*/
|
| 1255 |
+
has(k: K, hasOptions?: LRUCache.HasOptions<K, V, FC>): boolean;
|
| 1256 |
+
/**
|
| 1257 |
+
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
| 1258 |
+
* items.
|
| 1259 |
+
*
|
| 1260 |
+
* Returns `undefined` if the item is stale, unless
|
| 1261 |
+
* {@link LRUCache.OptionsBase.allowStale} is set.
|
| 1262 |
+
*/
|
| 1263 |
+
peek(k: K, peekOptions?: LRUCache.PeekOptions<K, V, FC>): V | undefined;
|
| 1264 |
+
/**
|
| 1265 |
+
* Make an asynchronous cached fetch using the
|
| 1266 |
+
* {@link LRUCache.OptionsBase.fetchMethod} function.
|
| 1267 |
+
*
|
| 1268 |
+
* If the value is in the cache and not stale, then the returned
|
| 1269 |
+
* Promise resolves to the value.
|
| 1270 |
+
*
|
| 1271 |
+
* If not in the cache, or beyond its TTL staleness, then
|
| 1272 |
+
* `fetchMethod(key, staleValue, { options, signal, context })` is
|
| 1273 |
+
* called, and the value returned will be added to the cache once
|
| 1274 |
+
* resolved.
|
| 1275 |
+
*
|
| 1276 |
+
* If called with `allowStale`, and an asynchronous fetch is
|
| 1277 |
+
* currently in progress to reload a stale value, then the former
|
| 1278 |
+
* stale value will be returned.
|
| 1279 |
+
*
|
| 1280 |
+
* If called with `forceRefresh`, then the cached item will be
|
| 1281 |
+
* re-fetched, even if it is not stale. However, if `allowStale` is also
|
| 1282 |
+
* set, then the old value will still be returned. This is useful
|
| 1283 |
+
* in cases where you want to force a reload of a cached value. If
|
| 1284 |
+
* a background fetch is already in progress, then `forceRefresh`
|
| 1285 |
+
* has no effect.
|
| 1286 |
+
*
|
| 1287 |
+
* If multiple fetches for the same key are issued, then they will all be
|
| 1288 |
+
* coalesced into a single call to fetchMethod.
|
| 1289 |
+
*
|
| 1290 |
+
* Note that this means that handling options such as
|
| 1291 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort},
|
| 1292 |
+
* {@link LRUCache.FetchOptions.signal},
|
| 1293 |
+
* and {@link LRUCache.OptionsBase.allowStaleOnFetchRejection} will be
|
| 1294 |
+
* determined by the FIRST fetch() call for a given key.
|
| 1295 |
+
*
|
| 1296 |
+
* This is a known (fixable) shortcoming which will be addresed on when
|
| 1297 |
+
* someone complains about it, as the fix would involve added complexity and
|
| 1298 |
+
* may not be worth the costs for this edge case.
|
| 1299 |
+
*
|
| 1300 |
+
* If {@link LRUCache.OptionsBase.fetchMethod} is not specified, then this is
|
| 1301 |
+
* effectively an alias for `Promise.resolve(cache.get(key))`.
|
| 1302 |
+
*
|
| 1303 |
+
* When the fetch method resolves to a value, if the fetch has not
|
| 1304 |
+
* been aborted due to deletion, eviction, or being overwritten,
|
| 1305 |
+
* then it is added to the cache using the options provided.
|
| 1306 |
+
*
|
| 1307 |
+
* If the key is evicted or deleted before the `fetchMethod`
|
| 1308 |
+
* resolves, then the AbortSignal passed to the `fetchMethod` will
|
| 1309 |
+
* receive an `abort` event, and the promise returned by `fetch()`
|
| 1310 |
+
* will reject with the reason for the abort.
|
| 1311 |
+
*
|
| 1312 |
+
* If a `signal` is passed to the `fetch()` call, then aborting the
|
| 1313 |
+
* signal will abort the fetch and cause the `fetch()` promise to
|
| 1314 |
+
* reject with the reason provided.
|
| 1315 |
+
*
|
| 1316 |
+
* **Setting `context`**
|
| 1317 |
+
*
|
| 1318 |
+
* If an `FC` type is set to a type other than `unknown`, `void`, or
|
| 1319 |
+
* `undefined` in the {@link LRUCache} constructor, then all
|
| 1320 |
+
* calls to `cache.fetch()` _must_ provide a `context` option. If
|
| 1321 |
+
* set to `undefined` or `void`, then calls to fetch _must not_
|
| 1322 |
+
* provide a `context` option.
|
| 1323 |
+
*
|
| 1324 |
+
* The `context` param allows you to provide arbitrary data that
|
| 1325 |
+
* might be relevant in the course of fetching the data. It is only
|
| 1326 |
+
* relevant for the course of a single `fetch()` operation, and
|
| 1327 |
+
* discarded afterwards.
|
| 1328 |
+
*
|
| 1329 |
+
* **Note: `fetch()` calls are inflight-unique**
|
| 1330 |
+
*
|
| 1331 |
+
* If you call `fetch()` multiple times with the same key value,
|
| 1332 |
+
* then every call after the first will resolve on the same
|
| 1333 |
+
* promise<sup>1</sup>,
|
| 1334 |
+
* _even if they have different settings that would otherwise change
|
| 1335 |
+
* the behavior of the fetch_, such as `noDeleteOnFetchRejection`
|
| 1336 |
+
* or `ignoreFetchAbort`.
|
| 1337 |
+
*
|
| 1338 |
+
* In most cases, this is not a problem (in fact, only fetching
|
| 1339 |
+
* something once is what you probably want, if you're caching in
|
| 1340 |
+
* the first place). If you are changing the fetch() options
|
| 1341 |
+
* dramatically between runs, there's a good chance that you might
|
| 1342 |
+
* be trying to fit divergent semantics into a single object, and
|
| 1343 |
+
* would be better off with multiple cache instances.
|
| 1344 |
+
*
|
| 1345 |
+
* **1**: Ie, they're not the "same Promise", but they resolve at
|
| 1346 |
+
* the same time, because they're both waiting on the same
|
| 1347 |
+
* underlying fetchMethod response.
|
| 1348 |
+
*/
|
| 1349 |
+
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
| 1350 |
+
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<undefined | V>;
|
| 1351 |
+
/**
|
| 1352 |
+
* In some cases, `cache.fetch()` may resolve to `undefined`, either because
|
| 1353 |
+
* a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
|
| 1354 |
+
* `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
|
| 1355 |
+
* because `ignoreFetchAbort` was specified (either to the constructor or
|
| 1356 |
+
* in the {@link LRUCache.FetchOptions}). Also, the
|
| 1357 |
+
* {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
| 1358 |
+
* the test even more complicated.
|
| 1359 |
+
*
|
| 1360 |
+
* Because inferring the cases where `undefined` might be returned are so
|
| 1361 |
+
* cumbersome, but testing for `undefined` can also be annoying, this method
|
| 1362 |
+
* can be used, which will reject if `this.fetch()` resolves to undefined.
|
| 1363 |
+
*/
|
| 1364 |
+
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
| 1365 |
+
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<V>;
|
| 1366 |
+
/**
|
| 1367 |
+
* If the key is found in the cache, then this is equivalent to
|
| 1368 |
+
* {@link LRUCache#get}. If not, in the cache, then calculate the value using
|
| 1369 |
+
* the {@link LRUCache.OptionsBase.memoMethod}, and add it to the cache.
|
| 1370 |
+
*
|
| 1371 |
+
* If an `FC` type is set to a type other than `unknown`, `void`, or
|
| 1372 |
+
* `undefined` in the LRUCache constructor, then all calls to `cache.memo()`
|
| 1373 |
+
* _must_ provide a `context` option. If set to `undefined` or `void`, then
|
| 1374 |
+
* calls to memo _must not_ provide a `context` option.
|
| 1375 |
+
*
|
| 1376 |
+
* The `context` param allows you to provide arbitrary data that might be
|
| 1377 |
+
* relevant in the course of fetching the data. It is only relevant for the
|
| 1378 |
+
* course of a single `memo()` operation, and discarded afterwards.
|
| 1379 |
+
*/
|
| 1380 |
+
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
| 1381 |
+
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : never): V;
|
| 1382 |
+
/**
|
| 1383 |
+
* Return a value from the cache. Will update the recency of the cache
|
| 1384 |
+
* entry found.
|
| 1385 |
+
*
|
| 1386 |
+
* If the key is not found, get() will return `undefined`.
|
| 1387 |
+
*/
|
| 1388 |
+
get(k: K, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
|
| 1389 |
+
/**
|
| 1390 |
+
* Deletes a key out of the cache.
|
| 1391 |
+
*
|
| 1392 |
+
* Returns true if the key was deleted, false otherwise.
|
| 1393 |
+
*/
|
| 1394 |
+
delete(k: K): boolean;
|
| 1395 |
+
/**
|
| 1396 |
+
* Clear the cache entirely, throwing away all values.
|
| 1397 |
+
*/
|
| 1398 |
+
clear(): void;
|
| 1399 |
+
}
|
| 1400 |
+
//# sourceMappingURL=index.d.ts.map
|
node_modules/lru-cache/dist/commonjs/browser/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index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", { value: true });
|
| 6 |
+
exports.LRUCache = void 0;
|
| 7 |
+
const diagnostics_channel_js_1 = require("./diagnostics-channel.js");
|
| 8 |
+
const perf_js_1 = require("./perf.js");
|
| 9 |
+
const hasSubscribers = () => diagnostics_channel_js_1.metrics.hasSubscribers || diagnostics_channel_js_1.tracing.hasSubscribers;
|
| 10 |
+
const warned = new Set();
|
| 11 |
+
/* c8 ignore start */
|
| 12 |
+
const PROCESS = (typeof process === 'object' && !!process ?
|
| 13 |
+
process
|
| 14 |
+
: {});
|
| 15 |
+
/* c8 ignore stop */
|
| 16 |
+
const emitWarning = (msg, type, code, fn) => {
|
| 17 |
+
if (typeof PROCESS.emitWarning === 'function') {
|
| 18 |
+
PROCESS.emitWarning(msg, type, code, fn);
|
| 19 |
+
}
|
| 20 |
+
else {
|
| 21 |
+
//oxlint-disable-next-line no-console
|
| 22 |
+
console.error(`[${code}] ${type}: ${msg}`);
|
| 23 |
+
}
|
| 24 |
+
};
|
| 25 |
+
const shouldWarn = (code) => !warned.has(code);
|
| 26 |
+
const TYPE = Symbol('type');
|
| 27 |
+
const isPosInt = (n) => !!n && n === Math.floor(n) && n > 0 && isFinite(n);
|
| 28 |
+
// This is a little bit ridiculous, tbh.
|
| 29 |
+
// The maximum array length is 2^32-1 or thereabouts on most JS impls.
|
| 30 |
+
// And well before that point, you're caching the entire world, I mean,
|
| 31 |
+
// that's ~32GB of just integers for the next/prev links, plus whatever
|
| 32 |
+
// else to hold that many keys and values. Just filling the memory with
|
| 33 |
+
// zeroes at init time is brutal when you get that big.
|
| 34 |
+
// But why not be complete?
|
| 35 |
+
// Maybe in the future, these limits will have expanded.
|
| 36 |
+
/* c8 ignore start */
|
| 37 |
+
const getUintArray = (max) => !isPosInt(max) ? null
|
| 38 |
+
: max <= Math.pow(2, 8) ? Uint8Array
|
| 39 |
+
: max <= Math.pow(2, 16) ? Uint16Array
|
| 40 |
+
: max <= Math.pow(2, 32) ? Uint32Array
|
| 41 |
+
: max <= Number.MAX_SAFE_INTEGER ? ZeroArray
|
| 42 |
+
: null;
|
| 43 |
+
/* c8 ignore stop */
|
| 44 |
+
class ZeroArray extends Array {
|
| 45 |
+
constructor(size) {
|
| 46 |
+
super(size);
|
| 47 |
+
this.fill(0);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
class Stack {
|
| 51 |
+
/* c8 ignore start - not sure why this is showing up uncovered?? */
|
| 52 |
+
heap;
|
| 53 |
+
/* c8 ignore stop */
|
| 54 |
+
length;
|
| 55 |
+
// private constructor
|
| 56 |
+
static #constructing = false;
|
| 57 |
+
static create(max) {
|
| 58 |
+
const HeapCls = getUintArray(max);
|
| 59 |
+
if (!HeapCls)
|
| 60 |
+
return [];
|
| 61 |
+
Stack.#constructing = true;
|
| 62 |
+
const s = new Stack(max, HeapCls);
|
| 63 |
+
Stack.#constructing = false;
|
| 64 |
+
return s;
|
| 65 |
+
}
|
| 66 |
+
constructor(max, HeapCls) {
|
| 67 |
+
/* c8 ignore start */
|
| 68 |
+
if (!Stack.#constructing) {
|
| 69 |
+
throw new TypeError('instantiate Stack using Stack.create(n)');
|
| 70 |
+
}
|
| 71 |
+
/* c8 ignore stop */
|
| 72 |
+
this.heap = new HeapCls(max);
|
| 73 |
+
this.length = 0;
|
| 74 |
+
}
|
| 75 |
+
push(n) {
|
| 76 |
+
this.heap[this.length++] = n;
|
| 77 |
+
}
|
| 78 |
+
pop() {
|
| 79 |
+
return this.heap[--this.length];
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
/**
|
| 83 |
+
* Default export, the thing you're using this module to get.
|
| 84 |
+
*
|
| 85 |
+
* The `K` and `V` types define the key and value types, respectively. The
|
| 86 |
+
* optional `FC` type defines the type of the `context` object passed to
|
| 87 |
+
* `cache.fetch()` and `cache.memo()`.
|
| 88 |
+
*
|
| 89 |
+
* Keys and values **must not** be `null` or `undefined`.
|
| 90 |
+
*
|
| 91 |
+
* All properties from the options object (with the exception of `max`,
|
| 92 |
+
* `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
|
| 93 |
+
* added as normal public members. (The listed options are read-only getters.)
|
| 94 |
+
*
|
| 95 |
+
* Changing any of these will alter the defaults for subsequent method calls.
|
| 96 |
+
*/
|
| 97 |
+
class LRUCache {
|
| 98 |
+
// options that cannot be changed without disaster
|
| 99 |
+
#max;
|
| 100 |
+
#maxSize;
|
| 101 |
+
#dispose;
|
| 102 |
+
#onInsert;
|
| 103 |
+
#disposeAfter;
|
| 104 |
+
#fetchMethod;
|
| 105 |
+
#memoMethod;
|
| 106 |
+
#perf;
|
| 107 |
+
/**
|
| 108 |
+
* {@link LRUCache.OptionsBase.perf}
|
| 109 |
+
*/
|
| 110 |
+
get perf() {
|
| 111 |
+
return this.#perf;
|
| 112 |
+
}
|
| 113 |
+
/**
|
| 114 |
+
* {@link LRUCache.OptionsBase.ttl}
|
| 115 |
+
*/
|
| 116 |
+
ttl;
|
| 117 |
+
/**
|
| 118 |
+
* {@link LRUCache.OptionsBase.ttlResolution}
|
| 119 |
+
*/
|
| 120 |
+
ttlResolution;
|
| 121 |
+
/**
|
| 122 |
+
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
| 123 |
+
*/
|
| 124 |
+
ttlAutopurge;
|
| 125 |
+
/**
|
| 126 |
+
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
| 127 |
+
*/
|
| 128 |
+
updateAgeOnGet;
|
| 129 |
+
/**
|
| 130 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
| 131 |
+
*/
|
| 132 |
+
updateAgeOnHas;
|
| 133 |
+
/**
|
| 134 |
+
* {@link LRUCache.OptionsBase.allowStale}
|
| 135 |
+
*/
|
| 136 |
+
allowStale;
|
| 137 |
+
/**
|
| 138 |
+
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
| 139 |
+
*/
|
| 140 |
+
noDisposeOnSet;
|
| 141 |
+
/**
|
| 142 |
+
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
| 143 |
+
*/
|
| 144 |
+
noUpdateTTL;
|
| 145 |
+
/**
|
| 146 |
+
* {@link LRUCache.OptionsBase.maxEntrySize}
|
| 147 |
+
*/
|
| 148 |
+
maxEntrySize;
|
| 149 |
+
/**
|
| 150 |
+
* {@link LRUCache.OptionsBase.sizeCalculation}
|
| 151 |
+
*/
|
| 152 |
+
sizeCalculation;
|
| 153 |
+
/**
|
| 154 |
+
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
| 155 |
+
*/
|
| 156 |
+
noDeleteOnFetchRejection;
|
| 157 |
+
/**
|
| 158 |
+
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
| 159 |
+
*/
|
| 160 |
+
noDeleteOnStaleGet;
|
| 161 |
+
/**
|
| 162 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
| 163 |
+
*/
|
| 164 |
+
allowStaleOnFetchAbort;
|
| 165 |
+
/**
|
| 166 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
| 167 |
+
*/
|
| 168 |
+
allowStaleOnFetchRejection;
|
| 169 |
+
/**
|
| 170 |
+
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
| 171 |
+
*/
|
| 172 |
+
ignoreFetchAbort;
|
| 173 |
+
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
| 174 |
+
backgroundFetchSize;
|
| 175 |
+
// computed properties
|
| 176 |
+
#size;
|
| 177 |
+
#calculatedSize;
|
| 178 |
+
#keyMap;
|
| 179 |
+
#keyList;
|
| 180 |
+
#valList;
|
| 181 |
+
#next;
|
| 182 |
+
#prev;
|
| 183 |
+
#head;
|
| 184 |
+
#tail;
|
| 185 |
+
#free;
|
| 186 |
+
#disposed;
|
| 187 |
+
#sizes;
|
| 188 |
+
#starts;
|
| 189 |
+
#ttls;
|
| 190 |
+
#autopurgeTimers;
|
| 191 |
+
#hasDispose;
|
| 192 |
+
#hasFetchMethod;
|
| 193 |
+
#hasDisposeAfter;
|
| 194 |
+
#hasOnInsert;
|
| 195 |
+
/**
|
| 196 |
+
* Do not call this method unless you need to inspect the
|
| 197 |
+
* inner workings of the cache. If anything returned by this
|
| 198 |
+
* object is modified in any way, strange breakage may occur.
|
| 199 |
+
*
|
| 200 |
+
* These fields are private for a reason!
|
| 201 |
+
*
|
| 202 |
+
* @internal
|
| 203 |
+
*/
|
| 204 |
+
static unsafeExposeInternals(c) {
|
| 205 |
+
return {
|
| 206 |
+
// properties
|
| 207 |
+
starts: c.#starts,
|
| 208 |
+
ttls: c.#ttls,
|
| 209 |
+
autopurgeTimers: c.#autopurgeTimers,
|
| 210 |
+
sizes: c.#sizes,
|
| 211 |
+
keyMap: c.#keyMap,
|
| 212 |
+
keyList: c.#keyList,
|
| 213 |
+
valList: c.#valList,
|
| 214 |
+
next: c.#next,
|
| 215 |
+
prev: c.#prev,
|
| 216 |
+
get head() {
|
| 217 |
+
return c.#head;
|
| 218 |
+
},
|
| 219 |
+
get tail() {
|
| 220 |
+
return c.#tail;
|
| 221 |
+
},
|
| 222 |
+
free: c.#free,
|
| 223 |
+
// methods
|
| 224 |
+
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
| 225 |
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
| 226 |
+
moveToTail: (index) => c.#moveToTail(index),
|
| 227 |
+
indexes: (options) => c.#indexes(options),
|
| 228 |
+
rindexes: (options) => c.#rindexes(options),
|
| 229 |
+
isStale: (index) => c.#isStale(index),
|
| 230 |
+
};
|
| 231 |
+
}
|
| 232 |
+
// Protected read-only members
|
| 233 |
+
/**
|
| 234 |
+
* {@link LRUCache.OptionsBase.max} (read-only)
|
| 235 |
+
*/
|
| 236 |
+
get max() {
|
| 237 |
+
return this.#max;
|
| 238 |
+
}
|
| 239 |
+
/**
|
| 240 |
+
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
| 241 |
+
*/
|
| 242 |
+
get maxSize() {
|
| 243 |
+
return this.#maxSize;
|
| 244 |
+
}
|
| 245 |
+
/**
|
| 246 |
+
* The total computed size of items in the cache (read-only)
|
| 247 |
+
*/
|
| 248 |
+
get calculatedSize() {
|
| 249 |
+
return this.#calculatedSize;
|
| 250 |
+
}
|
| 251 |
+
/**
|
| 252 |
+
* The number of items stored in the cache (read-only)
|
| 253 |
+
*/
|
| 254 |
+
get size() {
|
| 255 |
+
return this.#size;
|
| 256 |
+
}
|
| 257 |
+
/**
|
| 258 |
+
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
| 259 |
+
*/
|
| 260 |
+
get fetchMethod() {
|
| 261 |
+
return this.#fetchMethod;
|
| 262 |
+
}
|
| 263 |
+
get memoMethod() {
|
| 264 |
+
return this.#memoMethod;
|
| 265 |
+
}
|
| 266 |
+
/**
|
| 267 |
+
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
| 268 |
+
*/
|
| 269 |
+
get dispose() {
|
| 270 |
+
return this.#dispose;
|
| 271 |
+
}
|
| 272 |
+
/**
|
| 273 |
+
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
| 274 |
+
*/
|
| 275 |
+
get onInsert() {
|
| 276 |
+
return this.#onInsert;
|
| 277 |
+
}
|
| 278 |
+
/**
|
| 279 |
+
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
| 280 |
+
*/
|
| 281 |
+
get disposeAfter() {
|
| 282 |
+
return this.#disposeAfter;
|
| 283 |
+
}
|
| 284 |
+
constructor(options) {
|
| 285 |
+
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, backgroundFetchSize = 1, perf, } = options;
|
| 286 |
+
this.backgroundFetchSize = backgroundFetchSize;
|
| 287 |
+
if (perf !== undefined) {
|
| 288 |
+
if (typeof perf?.now !== 'function') {
|
| 289 |
+
throw new TypeError('perf option must have a now() method if specified');
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
this.#perf = perf ?? perf_js_1.defaultPerf;
|
| 293 |
+
if (max !== 0 && !isPosInt(max)) {
|
| 294 |
+
throw new TypeError('max option must be a nonnegative integer');
|
| 295 |
+
}
|
| 296 |
+
const UintArray = max ? getUintArray(max) : Array;
|
| 297 |
+
if (!UintArray) {
|
| 298 |
+
throw new Error('invalid max value: ' + max);
|
| 299 |
+
}
|
| 300 |
+
this.#max = max;
|
| 301 |
+
this.#maxSize = maxSize;
|
| 302 |
+
this.maxEntrySize = maxEntrySize || this.#maxSize;
|
| 303 |
+
this.sizeCalculation = sizeCalculation;
|
| 304 |
+
if (this.sizeCalculation) {
|
| 305 |
+
if (!this.#maxSize && !this.maxEntrySize) {
|
| 306 |
+
throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
|
| 307 |
+
}
|
| 308 |
+
if (typeof this.sizeCalculation !== 'function') {
|
| 309 |
+
throw new TypeError('sizeCalculation set to non-function');
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
if (memoMethod !== undefined && typeof memoMethod !== 'function') {
|
| 313 |
+
throw new TypeError('memoMethod must be a function if defined');
|
| 314 |
+
}
|
| 315 |
+
this.#memoMethod = memoMethod;
|
| 316 |
+
if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
|
| 317 |
+
throw new TypeError('fetchMethod must be a function if specified');
|
| 318 |
+
}
|
| 319 |
+
this.#fetchMethod = fetchMethod;
|
| 320 |
+
this.#hasFetchMethod = !!fetchMethod;
|
| 321 |
+
this.#keyMap = new Map();
|
| 322 |
+
this.#keyList = Array.from({ length: max }).fill(undefined);
|
| 323 |
+
this.#valList = Array.from({ length: max }).fill(undefined);
|
| 324 |
+
this.#next = new UintArray(max);
|
| 325 |
+
this.#prev = new UintArray(max);
|
| 326 |
+
this.#head = 0;
|
| 327 |
+
this.#tail = 0;
|
| 328 |
+
this.#free = Stack.create(max);
|
| 329 |
+
this.#size = 0;
|
| 330 |
+
this.#calculatedSize = 0;
|
| 331 |
+
if (typeof dispose === 'function') {
|
| 332 |
+
this.#dispose = dispose;
|
| 333 |
+
}
|
| 334 |
+
if (typeof onInsert === 'function') {
|
| 335 |
+
this.#onInsert = onInsert;
|
| 336 |
+
}
|
| 337 |
+
if (typeof disposeAfter === 'function') {
|
| 338 |
+
this.#disposeAfter = disposeAfter;
|
| 339 |
+
this.#disposed = [];
|
| 340 |
+
}
|
| 341 |
+
else {
|
| 342 |
+
this.#disposeAfter = undefined;
|
| 343 |
+
this.#disposed = undefined;
|
| 344 |
+
}
|
| 345 |
+
this.#hasDispose = !!this.#dispose;
|
| 346 |
+
this.#hasOnInsert = !!this.#onInsert;
|
| 347 |
+
this.#hasDisposeAfter = !!this.#disposeAfter;
|
| 348 |
+
this.noDisposeOnSet = !!noDisposeOnSet;
|
| 349 |
+
this.noUpdateTTL = !!noUpdateTTL;
|
| 350 |
+
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
| 351 |
+
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
| 352 |
+
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
| 353 |
+
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
| 354 |
+
// NB: maxEntrySize is set to maxSize if it's set
|
| 355 |
+
if (this.maxEntrySize !== 0) {
|
| 356 |
+
if (this.#maxSize !== 0) {
|
| 357 |
+
if (!isPosInt(this.#maxSize)) {
|
| 358 |
+
throw new TypeError('maxSize must be a positive integer if specified');
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
if (!isPosInt(this.maxEntrySize)) {
|
| 362 |
+
throw new TypeError('maxEntrySize must be a positive integer if specified');
|
| 363 |
+
}
|
| 364 |
+
this.#initializeSizeTracking();
|
| 365 |
+
}
|
| 366 |
+
this.allowStale = !!allowStale;
|
| 367 |
+
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
| 368 |
+
this.updateAgeOnGet = !!updateAgeOnGet;
|
| 369 |
+
this.updateAgeOnHas = !!updateAgeOnHas;
|
| 370 |
+
this.ttlResolution =
|
| 371 |
+
isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
|
| 372 |
+
this.ttlAutopurge = !!ttlAutopurge;
|
| 373 |
+
this.ttl = ttl || 0;
|
| 374 |
+
if (this.ttl) {
|
| 375 |
+
if (!isPosInt(this.ttl)) {
|
| 376 |
+
throw new TypeError('ttl must be a positive integer if specified');
|
| 377 |
+
}
|
| 378 |
+
this.#initializeTTLTracking();
|
| 379 |
+
}
|
| 380 |
+
// do not allow completely unbounded caches
|
| 381 |
+
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
|
| 382 |
+
throw new TypeError('At least one of max, maxSize, or ttl is required');
|
| 383 |
+
}
|
| 384 |
+
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
| 385 |
+
const code = 'LRU_CACHE_UNBOUNDED';
|
| 386 |
+
if (shouldWarn(code)) {
|
| 387 |
+
warned.add(code);
|
| 388 |
+
const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
|
| 389 |
+
'result in unbounded memory consumption.';
|
| 390 |
+
emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
/**
|
| 395 |
+
* Return the number of ms left in the item's TTL. If item is not in cache,
|
| 396 |
+
* returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
|
| 397 |
+
*/
|
| 398 |
+
getRemainingTTL(key) {
|
| 399 |
+
return this.#keyMap.has(key) ? Infinity : 0;
|
| 400 |
+
}
|
| 401 |
+
#initializeTTLTracking() {
|
| 402 |
+
const ttls = new ZeroArray(this.#max);
|
| 403 |
+
const starts = new ZeroArray(this.#max);
|
| 404 |
+
this.#ttls = ttls;
|
| 405 |
+
this.#starts = starts;
|
| 406 |
+
const purgeTimers = this.ttlAutopurge ?
|
| 407 |
+
Array.from({
|
| 408 |
+
length: this.#max,
|
| 409 |
+
})
|
| 410 |
+
: undefined;
|
| 411 |
+
this.#autopurgeTimers = purgeTimers;
|
| 412 |
+
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
|
| 413 |
+
starts[index] = ttl !== 0 ? start : 0;
|
| 414 |
+
ttls[index] = ttl;
|
| 415 |
+
setPurgetTimer(index, ttl);
|
| 416 |
+
};
|
| 417 |
+
this.#updateItemAge = index => {
|
| 418 |
+
starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
|
| 419 |
+
setPurgetTimer(index, ttls[index]);
|
| 420 |
+
};
|
| 421 |
+
// clear out the purge timer if we're setting TTL to 0, and
|
| 422 |
+
// previously had a ttl purge timer running, so it doesn't
|
| 423 |
+
// fire unnecessarily. Don't need to do this if we're not doing
|
| 424 |
+
// autopurge.
|
| 425 |
+
const setPurgetTimer = !this.ttlAutopurge ?
|
| 426 |
+
() => { }
|
| 427 |
+
: (index, ttl) => {
|
| 428 |
+
if (purgeTimers?.[index]) {
|
| 429 |
+
clearTimeout(purgeTimers[index]);
|
| 430 |
+
purgeTimers[index] = undefined;
|
| 431 |
+
}
|
| 432 |
+
if (ttl && ttl !== 0 && purgeTimers) {
|
| 433 |
+
const t = setTimeout(() => {
|
| 434 |
+
if (this.#isStale(index)) {
|
| 435 |
+
this.#delete(this.#keyList[index], 'expire');
|
| 436 |
+
}
|
| 437 |
+
}, ttl + 1);
|
| 438 |
+
// unref() not supported on all platforms
|
| 439 |
+
/* c8 ignore start */
|
| 440 |
+
if (t.unref) {
|
| 441 |
+
t.unref();
|
| 442 |
+
}
|
| 443 |
+
/* c8 ignore stop */
|
| 444 |
+
purgeTimers[index] = t;
|
| 445 |
+
}
|
| 446 |
+
};
|
| 447 |
+
this.#statusTTL = (status, index) => {
|
| 448 |
+
if (ttls[index]) {
|
| 449 |
+
const ttl = ttls[index];
|
| 450 |
+
const start = starts[index];
|
| 451 |
+
/* c8 ignore start */
|
| 452 |
+
if (!ttl || !start) {
|
| 453 |
+
return;
|
| 454 |
+
}
|
| 455 |
+
/* c8 ignore stop */
|
| 456 |
+
status.ttl = ttl;
|
| 457 |
+
status.start = start;
|
| 458 |
+
status.now = cachedNow || getNow();
|
| 459 |
+
const age = status.now - start;
|
| 460 |
+
status.remainingTTL = ttl - age;
|
| 461 |
+
}
|
| 462 |
+
};
|
| 463 |
+
// debounce calls to perf.now() to 1s so we're not hitting
|
| 464 |
+
// that costly call repeatedly.
|
| 465 |
+
let cachedNow = 0;
|
| 466 |
+
const getNow = () => {
|
| 467 |
+
const n = this.#perf.now();
|
| 468 |
+
if (this.ttlResolution > 0) {
|
| 469 |
+
cachedNow = n;
|
| 470 |
+
const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
|
| 471 |
+
// not available on all platforms
|
| 472 |
+
/* c8 ignore start */
|
| 473 |
+
if (t.unref) {
|
| 474 |
+
t.unref();
|
| 475 |
+
}
|
| 476 |
+
/* c8 ignore stop */
|
| 477 |
+
}
|
| 478 |
+
return n;
|
| 479 |
+
};
|
| 480 |
+
this.getRemainingTTL = key => {
|
| 481 |
+
const index = this.#keyMap.get(key);
|
| 482 |
+
if (index === undefined) {
|
| 483 |
+
return 0;
|
| 484 |
+
}
|
| 485 |
+
const ttl = ttls[index];
|
| 486 |
+
const start = starts[index];
|
| 487 |
+
if (!ttl || !start) {
|
| 488 |
+
return Infinity;
|
| 489 |
+
}
|
| 490 |
+
const age = (cachedNow || getNow()) - start;
|
| 491 |
+
return ttl - age;
|
| 492 |
+
};
|
| 493 |
+
this.#isStale = index => {
|
| 494 |
+
const s = starts[index];
|
| 495 |
+
const t = ttls[index];
|
| 496 |
+
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
| 497 |
+
};
|
| 498 |
+
}
|
| 499 |
+
// conditionally set private methods related to TTL
|
| 500 |
+
#updateItemAge = () => { };
|
| 501 |
+
#statusTTL = () => { };
|
| 502 |
+
#setItemTTL = () => { };
|
| 503 |
+
/* c8 ignore stop */
|
| 504 |
+
#isStale = () => false;
|
| 505 |
+
#initializeSizeTracking() {
|
| 506 |
+
const sizes = new ZeroArray(this.#max);
|
| 507 |
+
this.#calculatedSize = 0;
|
| 508 |
+
this.#sizes = sizes;
|
| 509 |
+
this.#removeItemSize = index => {
|
| 510 |
+
this.#calculatedSize -= sizes[index];
|
| 511 |
+
sizes[index] = 0;
|
| 512 |
+
};
|
| 513 |
+
this.#requireSize = (k, v, size, sizeCalculation) => {
|
| 514 |
+
if (!isPosInt(size)) {
|
| 515 |
+
// provisionally accept background fetches.
|
| 516 |
+
// actual value size will be checked when they return.
|
| 517 |
+
if (this.#isBackgroundFetch(v)) {
|
| 518 |
+
// NB: this cannot occur if v.__staleWhileFetching is set,
|
| 519 |
+
// because in that case, it would take on the size of the
|
| 520 |
+
// existing entry that it temporarily replaces.
|
| 521 |
+
return this.backgroundFetchSize;
|
| 522 |
+
}
|
| 523 |
+
if (sizeCalculation) {
|
| 524 |
+
if (typeof sizeCalculation !== 'function') {
|
| 525 |
+
throw new TypeError('sizeCalculation must be a function');
|
| 526 |
+
}
|
| 527 |
+
size = sizeCalculation(v, k);
|
| 528 |
+
if (!isPosInt(size)) {
|
| 529 |
+
throw new TypeError('sizeCalculation return invalid (expect positive integer)');
|
| 530 |
+
}
|
| 531 |
+
}
|
| 532 |
+
else {
|
| 533 |
+
throw new TypeError('invalid size value (must be positive integer). ' +
|
| 534 |
+
'When maxSize or maxEntrySize is used, sizeCalculation ' +
|
| 535 |
+
'or size must be set.');
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
return size;
|
| 539 |
+
};
|
| 540 |
+
this.#addItemSize = (index, size, status) => {
|
| 541 |
+
sizes[index] = size;
|
| 542 |
+
if (this.#maxSize) {
|
| 543 |
+
const maxSize = this.#maxSize - sizes[index];
|
| 544 |
+
while (this.#calculatedSize > maxSize) {
|
| 545 |
+
this.#evict(true);
|
| 546 |
+
}
|
| 547 |
+
}
|
| 548 |
+
this.#calculatedSize += sizes[index];
|
| 549 |
+
if (status) {
|
| 550 |
+
status.entrySize = size;
|
| 551 |
+
status.totalCalculatedSize = this.#calculatedSize;
|
| 552 |
+
}
|
| 553 |
+
};
|
| 554 |
+
}
|
| 555 |
+
#removeItemSize = _i => { };
|
| 556 |
+
#addItemSize = (_i, _s, _st) => { };
|
| 557 |
+
#requireSize = (_k, _v, size, sizeCalculation) => {
|
| 558 |
+
if (size || sizeCalculation) {
|
| 559 |
+
throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
|
| 560 |
+
}
|
| 561 |
+
return 0;
|
| 562 |
+
};
|
| 563 |
+
*#indexes({ allowStale = this.allowStale } = {}) {
|
| 564 |
+
if (this.#size) {
|
| 565 |
+
for (let i = this.#tail; this.#isValidIndex(i);) {
|
| 566 |
+
if (allowStale || !this.#isStale(i)) {
|
| 567 |
+
yield i;
|
| 568 |
+
}
|
| 569 |
+
if (i === this.#head) {
|
| 570 |
+
break;
|
| 571 |
+
}
|
| 572 |
+
else {
|
| 573 |
+
i = this.#prev[i];
|
| 574 |
+
}
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
}
|
| 578 |
+
*#rindexes({ allowStale = this.allowStale } = {}) {
|
| 579 |
+
if (this.#size) {
|
| 580 |
+
for (let i = this.#head; this.#isValidIndex(i);) {
|
| 581 |
+
if (allowStale || !this.#isStale(i)) {
|
| 582 |
+
yield i;
|
| 583 |
+
}
|
| 584 |
+
if (i === this.#tail) {
|
| 585 |
+
break;
|
| 586 |
+
}
|
| 587 |
+
else {
|
| 588 |
+
i = this.#next[i];
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
#isValidIndex(index) {
|
| 594 |
+
return (index !== undefined &&
|
| 595 |
+
this.#keyMap.get(this.#keyList[index]) === index);
|
| 596 |
+
}
|
| 597 |
+
/**
|
| 598 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 599 |
+
* in order from most recently used to least recently used.
|
| 600 |
+
*/
|
| 601 |
+
*entries() {
|
| 602 |
+
for (const i of this.#indexes()) {
|
| 603 |
+
if (this.#valList[i] !== undefined &&
|
| 604 |
+
this.#keyList[i] !== undefined &&
|
| 605 |
+
!this.#isBackgroundFetch(this.#valList[i])) {
|
| 606 |
+
yield [this.#keyList[i], this.#valList[i]];
|
| 607 |
+
}
|
| 608 |
+
}
|
| 609 |
+
}
|
| 610 |
+
/**
|
| 611 |
+
* Inverse order version of {@link LRUCache.entries}
|
| 612 |
+
*
|
| 613 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 614 |
+
* in order from least recently used to most recently used.
|
| 615 |
+
*/
|
| 616 |
+
*rentries() {
|
| 617 |
+
for (const i of this.#rindexes()) {
|
| 618 |
+
if (this.#valList[i] !== undefined &&
|
| 619 |
+
this.#keyList[i] !== undefined &&
|
| 620 |
+
!this.#isBackgroundFetch(this.#valList[i])) {
|
| 621 |
+
yield [this.#keyList[i], this.#valList[i]];
|
| 622 |
+
}
|
| 623 |
+
}
|
| 624 |
+
}
|
| 625 |
+
/**
|
| 626 |
+
* Return a generator yielding the keys in the cache,
|
| 627 |
+
* in order from most recently used to least recently used.
|
| 628 |
+
*/
|
| 629 |
+
*keys() {
|
| 630 |
+
for (const i of this.#indexes()) {
|
| 631 |
+
const k = this.#keyList[i];
|
| 632 |
+
if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 633 |
+
yield k;
|
| 634 |
+
}
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
/**
|
| 638 |
+
* Inverse order version of {@link LRUCache.keys}
|
| 639 |
+
*
|
| 640 |
+
* Return a generator yielding the keys in the cache,
|
| 641 |
+
* in order from least recently used to most recently used.
|
| 642 |
+
*/
|
| 643 |
+
*rkeys() {
|
| 644 |
+
for (const i of this.#rindexes()) {
|
| 645 |
+
const k = this.#keyList[i];
|
| 646 |
+
if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 647 |
+
yield k;
|
| 648 |
+
}
|
| 649 |
+
}
|
| 650 |
+
}
|
| 651 |
+
/**
|
| 652 |
+
* Return a generator yielding the values in the cache,
|
| 653 |
+
* in order from most recently used to least recently used.
|
| 654 |
+
*/
|
| 655 |
+
*values() {
|
| 656 |
+
for (const i of this.#indexes()) {
|
| 657 |
+
const v = this.#valList[i];
|
| 658 |
+
if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 659 |
+
yield this.#valList[i];
|
| 660 |
+
}
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
/**
|
| 664 |
+
* Inverse order version of {@link LRUCache.values}
|
| 665 |
+
*
|
| 666 |
+
* Return a generator yielding the values in the cache,
|
| 667 |
+
* in order from least recently used to most recently used.
|
| 668 |
+
*/
|
| 669 |
+
*rvalues() {
|
| 670 |
+
for (const i of this.#rindexes()) {
|
| 671 |
+
const v = this.#valList[i];
|
| 672 |
+
if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 673 |
+
yield this.#valList[i];
|
| 674 |
+
}
|
| 675 |
+
}
|
| 676 |
+
}
|
| 677 |
+
/**
|
| 678 |
+
* Iterating over the cache itself yields the same results as
|
| 679 |
+
* {@link LRUCache.entries}
|
| 680 |
+
*/
|
| 681 |
+
[Symbol.iterator]() {
|
| 682 |
+
return this.entries();
|
| 683 |
+
}
|
| 684 |
+
/**
|
| 685 |
+
* A String value that is used in the creation of the default string
|
| 686 |
+
* description of an object. Called by the built-in method
|
| 687 |
+
* `Object.prototype.toString`.
|
| 688 |
+
*/
|
| 689 |
+
[Symbol.toStringTag] = 'LRUCache';
|
| 690 |
+
/**
|
| 691 |
+
* Find a value for which the supplied fn method returns a truthy value,
|
| 692 |
+
* similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
|
| 693 |
+
*/
|
| 694 |
+
find(fn, getOptions = {}) {
|
| 695 |
+
for (const i of this.#indexes()) {
|
| 696 |
+
const v = this.#valList[i];
|
| 697 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 698 |
+
if (value === undefined)
|
| 699 |
+
continue;
|
| 700 |
+
if (fn(value, this.#keyList[i], this)) {
|
| 701 |
+
return this.#get(this.#keyList[i], getOptions);
|
| 702 |
+
}
|
| 703 |
+
}
|
| 704 |
+
}
|
| 705 |
+
/**
|
| 706 |
+
* Call the supplied function on each item in the cache, in order from most
|
| 707 |
+
* recently used to least recently used.
|
| 708 |
+
*
|
| 709 |
+
* `fn` is called as `fn(value, key, cache)`.
|
| 710 |
+
*
|
| 711 |
+
* If `thisp` is provided, function will be called in the `this`-context of
|
| 712 |
+
* the provided object, or the cache if no `thisp` object is provided.
|
| 713 |
+
*
|
| 714 |
+
* Does not update age or recenty of use, or iterate over stale values.
|
| 715 |
+
*/
|
| 716 |
+
forEach(fn, thisp = this) {
|
| 717 |
+
for (const i of this.#indexes()) {
|
| 718 |
+
const v = this.#valList[i];
|
| 719 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 720 |
+
if (value === undefined)
|
| 721 |
+
continue;
|
| 722 |
+
fn.call(thisp, value, this.#keyList[i], this);
|
| 723 |
+
}
|
| 724 |
+
}
|
| 725 |
+
/**
|
| 726 |
+
* The same as {@link LRUCache.forEach} but items are iterated over in
|
| 727 |
+
* reverse order. (ie, less recently used items are iterated over first.)
|
| 728 |
+
*/
|
| 729 |
+
rforEach(fn, thisp = this) {
|
| 730 |
+
for (const i of this.#rindexes()) {
|
| 731 |
+
const v = this.#valList[i];
|
| 732 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 733 |
+
if (value === undefined)
|
| 734 |
+
continue;
|
| 735 |
+
fn.call(thisp, value, this.#keyList[i], this);
|
| 736 |
+
}
|
| 737 |
+
}
|
| 738 |
+
/**
|
| 739 |
+
* Delete any stale entries. Returns true if anything was removed,
|
| 740 |
+
* false otherwise.
|
| 741 |
+
*/
|
| 742 |
+
purgeStale() {
|
| 743 |
+
let deleted = false;
|
| 744 |
+
for (const i of this.#rindexes({ allowStale: true })) {
|
| 745 |
+
if (this.#isStale(i)) {
|
| 746 |
+
this.#delete(this.#keyList[i], 'expire');
|
| 747 |
+
deleted = true;
|
| 748 |
+
}
|
| 749 |
+
}
|
| 750 |
+
return deleted;
|
| 751 |
+
}
|
| 752 |
+
/**
|
| 753 |
+
* Get the extended info about a given entry, to get its value, size, and
|
| 754 |
+
* TTL info simultaneously. Returns `undefined` if the key is not present.
|
| 755 |
+
*
|
| 756 |
+
* Unlike {@link LRUCache#dump}, which is designed to be portable and survive
|
| 757 |
+
* serialization, the `start` value is always the current timestamp, and the
|
| 758 |
+
* `ttl` is a calculated remaining time to live (negative if expired).
|
| 759 |
+
*
|
| 760 |
+
* Always returns stale values, if their info is found in the cache, so be
|
| 761 |
+
* sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
|
| 762 |
+
* if relevant.
|
| 763 |
+
*/
|
| 764 |
+
info(key) {
|
| 765 |
+
const i = this.#keyMap.get(key);
|
| 766 |
+
if (i === undefined)
|
| 767 |
+
return undefined;
|
| 768 |
+
const v = this.#valList[i];
|
| 769 |
+
/* c8 ignore start - this isn't tested for the info function,
|
| 770 |
+
* but it's the same logic as found in other places. */
|
| 771 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 772 |
+
if (value === undefined)
|
| 773 |
+
return undefined;
|
| 774 |
+
/* c8 ignore stop */
|
| 775 |
+
const entry = { value };
|
| 776 |
+
if (this.#ttls && this.#starts) {
|
| 777 |
+
const ttl = this.#ttls[i];
|
| 778 |
+
const start = this.#starts[i];
|
| 779 |
+
if (ttl && start) {
|
| 780 |
+
const remain = ttl - (this.#perf.now() - start);
|
| 781 |
+
entry.ttl = remain;
|
| 782 |
+
entry.start = Date.now();
|
| 783 |
+
}
|
| 784 |
+
}
|
| 785 |
+
if (this.#sizes) {
|
| 786 |
+
entry.size = this.#sizes[i];
|
| 787 |
+
}
|
| 788 |
+
return entry;
|
| 789 |
+
}
|
| 790 |
+
/**
|
| 791 |
+
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
| 792 |
+
* passed to {@link LRUCache#load}.
|
| 793 |
+
*
|
| 794 |
+
* The `start` fields are calculated relative to a portable `Date.now()`
|
| 795 |
+
* timestamp, even if `performance.now()` is available.
|
| 796 |
+
*
|
| 797 |
+
* Stale entries are always included in the `dump`, even if
|
| 798 |
+
* {@link LRUCache.OptionsBase.allowStale} is false.
|
| 799 |
+
*
|
| 800 |
+
* Note: this returns an actual array, not a generator, so it can be more
|
| 801 |
+
* easily passed around.
|
| 802 |
+
*/
|
| 803 |
+
dump() {
|
| 804 |
+
const arr = [];
|
| 805 |
+
for (const i of this.#indexes({ allowStale: true })) {
|
| 806 |
+
const key = this.#keyList[i];
|
| 807 |
+
const v = this.#valList[i];
|
| 808 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 809 |
+
if (value === undefined || key === undefined)
|
| 810 |
+
continue;
|
| 811 |
+
const entry = { value };
|
| 812 |
+
if (this.#ttls && this.#starts) {
|
| 813 |
+
entry.ttl = this.#ttls[i];
|
| 814 |
+
// always dump the start relative to a portable timestamp
|
| 815 |
+
// it's ok for this to be a bit slow, it's a rare operation.
|
| 816 |
+
const age = this.#perf.now() - this.#starts[i];
|
| 817 |
+
entry.start = Math.floor(Date.now() - age);
|
| 818 |
+
}
|
| 819 |
+
if (this.#sizes) {
|
| 820 |
+
entry.size = this.#sizes[i];
|
| 821 |
+
}
|
| 822 |
+
arr.unshift([key, entry]);
|
| 823 |
+
}
|
| 824 |
+
return arr;
|
| 825 |
+
}
|
| 826 |
+
/**
|
| 827 |
+
* Reset the cache and load in the items in entries in the order listed.
|
| 828 |
+
*
|
| 829 |
+
* The shape of the resulting cache may be different if the same options are
|
| 830 |
+
* not used in both caches.
|
| 831 |
+
*
|
| 832 |
+
* The `start` fields are assumed to be calculated relative to a portable
|
| 833 |
+
* `Date.now()` timestamp, even if `performance.now()` is available.
|
| 834 |
+
*/
|
| 835 |
+
load(arr) {
|
| 836 |
+
this.clear();
|
| 837 |
+
for (const [key, entry] of arr) {
|
| 838 |
+
if (entry.start) {
|
| 839 |
+
// entry.start is a portable timestamp, but we may be using
|
| 840 |
+
// node's performance.now(), so calculate the offset, so that
|
| 841 |
+
// we get the intended remaining TTL, no matter how long it's
|
| 842 |
+
// been on ice.
|
| 843 |
+
//
|
| 844 |
+
// it's ok for this to be a bit slow, it's a rare operation.
|
| 845 |
+
const age = Date.now() - entry.start;
|
| 846 |
+
entry.start = this.#perf.now() - age;
|
| 847 |
+
}
|
| 848 |
+
this.#set(key, entry.value, entry);
|
| 849 |
+
}
|
| 850 |
+
}
|
| 851 |
+
/**
|
| 852 |
+
* Add a value to the cache.
|
| 853 |
+
*
|
| 854 |
+
* Note: if `undefined` is specified as a value, this is an alias for
|
| 855 |
+
* {@link LRUCache#delete}
|
| 856 |
+
*
|
| 857 |
+
* Fields on the {@link LRUCache.SetOptions} options param will override
|
| 858 |
+
* their corresponding values in the constructor options for the scope
|
| 859 |
+
* of this single `set()` operation.
|
| 860 |
+
*
|
| 861 |
+
* If `start` is provided, then that will set the effective start
|
| 862 |
+
* time for the TTL calculation. Note that this must be a previous
|
| 863 |
+
* value of `performance.now()` if supported, or a previous value of
|
| 864 |
+
* `Date.now()` if not.
|
| 865 |
+
*
|
| 866 |
+
* Options object may also include `size`, which will prevent
|
| 867 |
+
* calling the `sizeCalculation` function and just use the specified
|
| 868 |
+
* number if it is a positive integer, and `noDisposeOnSet` which
|
| 869 |
+
* will prevent calling a `dispose` function in the case of
|
| 870 |
+
* overwrites.
|
| 871 |
+
*
|
| 872 |
+
* If the `size` (or return value of `sizeCalculation`) for a given
|
| 873 |
+
* entry is greater than `maxEntrySize`, then the item will not be
|
| 874 |
+
* added to the cache.
|
| 875 |
+
*
|
| 876 |
+
* Will update the recency of the entry.
|
| 877 |
+
*
|
| 878 |
+
* If the value is `undefined`, then this is an alias for
|
| 879 |
+
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
| 880 |
+
*/
|
| 881 |
+
set(k, v, setOptions = {}) {
|
| 882 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = setOptions;
|
| 883 |
+
setOptions.status = status;
|
| 884 |
+
if (status) {
|
| 885 |
+
status.op = 'set';
|
| 886 |
+
status.key = k;
|
| 887 |
+
if (v !== undefined)
|
| 888 |
+
status.value = v;
|
| 889 |
+
status.cache = this;
|
| 890 |
+
}
|
| 891 |
+
const result = this.#set(k, v, setOptions);
|
| 892 |
+
if (status && diagnostics_channel_js_1.metrics.hasSubscribers) {
|
| 893 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 894 |
+
}
|
| 895 |
+
return result;
|
| 896 |
+
}
|
| 897 |
+
#set(k, v, setOptions, bf) {
|
| 898 |
+
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
|
| 899 |
+
const isBF = this.#isBackgroundFetch(v);
|
| 900 |
+
if (v === undefined) {
|
| 901 |
+
if (status)
|
| 902 |
+
status.set = 'deleted';
|
| 903 |
+
this.delete(k);
|
| 904 |
+
return this;
|
| 905 |
+
}
|
| 906 |
+
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
| 907 |
+
if (status && !isBF)
|
| 908 |
+
status.value = v;
|
| 909 |
+
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation, status);
|
| 910 |
+
// if the item doesn't fit, don't do anything
|
| 911 |
+
// NB: maxEntrySize set to maxSize by default
|
| 912 |
+
if (this.maxEntrySize && size > this.maxEntrySize) {
|
| 913 |
+
// have to delete, in case something is there already.
|
| 914 |
+
this.#delete(k, 'set');
|
| 915 |
+
if (status) {
|
| 916 |
+
status.set = 'miss';
|
| 917 |
+
status.maxEntrySizeExceeded = true;
|
| 918 |
+
}
|
| 919 |
+
return this;
|
| 920 |
+
}
|
| 921 |
+
let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
|
| 922 |
+
if (index === undefined) {
|
| 923 |
+
// addition
|
| 924 |
+
index = (this.#size === 0 ? this.#tail
|
| 925 |
+
: this.#free.length !== 0 ? this.#free.pop()
|
| 926 |
+
: this.#size === this.#max ? this.#evict(false)
|
| 927 |
+
: this.#size);
|
| 928 |
+
this.#keyList[index] = k;
|
| 929 |
+
this.#valList[index] = v;
|
| 930 |
+
this.#keyMap.set(k, index);
|
| 931 |
+
this.#next[this.#tail] = index;
|
| 932 |
+
this.#prev[index] = this.#tail;
|
| 933 |
+
this.#tail = index;
|
| 934 |
+
this.#size++;
|
| 935 |
+
this.#addItemSize(index, size, status);
|
| 936 |
+
if (status)
|
| 937 |
+
status.set = 'add';
|
| 938 |
+
noUpdateTTL = false;
|
| 939 |
+
if (this.#hasOnInsert && !isBF) {
|
| 940 |
+
this.#onInsert?.(v, k, 'add');
|
| 941 |
+
}
|
| 942 |
+
}
|
| 943 |
+
else {
|
| 944 |
+
// update
|
| 945 |
+
// might be updating a background fetch!
|
| 946 |
+
this.#moveToTail(index);
|
| 947 |
+
const oldVal = this.#valList[index];
|
| 948 |
+
if (v !== oldVal) {
|
| 949 |
+
if (!noDisposeOnSet) {
|
| 950 |
+
if (this.#isBackgroundFetch(oldVal)) {
|
| 951 |
+
if (oldVal !== bf) {
|
| 952 |
+
// setting over a background fetch, not merely resolving it.
|
| 953 |
+
oldVal.__abortController.abort(new Error('replaced'));
|
| 954 |
+
}
|
| 955 |
+
const { __staleWhileFetching: s } = oldVal;
|
| 956 |
+
if (s !== undefined && s !== v) {
|
| 957 |
+
if (this.#hasDispose) {
|
| 958 |
+
this.#dispose?.(s, k, 'set');
|
| 959 |
+
}
|
| 960 |
+
if (this.#hasDisposeAfter) {
|
| 961 |
+
this.#disposed?.push([s, k, 'set']);
|
| 962 |
+
}
|
| 963 |
+
}
|
| 964 |
+
}
|
| 965 |
+
else {
|
| 966 |
+
if (this.#hasDispose) {
|
| 967 |
+
this.#dispose?.(oldVal, k, 'set');
|
| 968 |
+
}
|
| 969 |
+
if (this.#hasDisposeAfter) {
|
| 970 |
+
this.#disposed?.push([oldVal, k, 'set']);
|
| 971 |
+
}
|
| 972 |
+
}
|
| 973 |
+
}
|
| 974 |
+
this.#removeItemSize(index);
|
| 975 |
+
this.#addItemSize(index, size, status);
|
| 976 |
+
this.#valList[index] = v;
|
| 977 |
+
if (!isBF) {
|
| 978 |
+
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ?
|
| 979 |
+
oldVal.__staleWhileFetching
|
| 980 |
+
: oldVal;
|
| 981 |
+
const setType = oldValue === undefined ? 'add'
|
| 982 |
+
: v !== oldValue ? 'replace'
|
| 983 |
+
: 'update';
|
| 984 |
+
if (status) {
|
| 985 |
+
status.set = setType;
|
| 986 |
+
if (oldValue !== undefined)
|
| 987 |
+
status.oldValue = oldValue;
|
| 988 |
+
}
|
| 989 |
+
if (this.#hasOnInsert) {
|
| 990 |
+
this.onInsert?.(v, k, setType);
|
| 991 |
+
}
|
| 992 |
+
}
|
| 993 |
+
}
|
| 994 |
+
else if (!isBF) {
|
| 995 |
+
if (status) {
|
| 996 |
+
status.set = 'update';
|
| 997 |
+
}
|
| 998 |
+
if (this.#hasOnInsert) {
|
| 999 |
+
this.onInsert?.(v, k, 'update');
|
| 1000 |
+
}
|
| 1001 |
+
}
|
| 1002 |
+
}
|
| 1003 |
+
if (ttl !== 0 && !this.#ttls) {
|
| 1004 |
+
this.#initializeTTLTracking();
|
| 1005 |
+
}
|
| 1006 |
+
if (this.#ttls) {
|
| 1007 |
+
if (!noUpdateTTL) {
|
| 1008 |
+
this.#setItemTTL(index, ttl, start);
|
| 1009 |
+
}
|
| 1010 |
+
if (status)
|
| 1011 |
+
this.#statusTTL(status, index);
|
| 1012 |
+
}
|
| 1013 |
+
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
| 1014 |
+
const dt = this.#disposed;
|
| 1015 |
+
let task;
|
| 1016 |
+
while ((task = dt?.shift())) {
|
| 1017 |
+
this.#disposeAfter?.(...task);
|
| 1018 |
+
}
|
| 1019 |
+
}
|
| 1020 |
+
return this;
|
| 1021 |
+
}
|
| 1022 |
+
/**
|
| 1023 |
+
* Evict the least recently used item, returning its value or
|
| 1024 |
+
* `undefined` if cache is empty.
|
| 1025 |
+
*/
|
| 1026 |
+
pop() {
|
| 1027 |
+
try {
|
| 1028 |
+
while (this.#size) {
|
| 1029 |
+
const val = this.#valList[this.#head];
|
| 1030 |
+
this.#evict(true);
|
| 1031 |
+
if (this.#isBackgroundFetch(val)) {
|
| 1032 |
+
if (val.__staleWhileFetching) {
|
| 1033 |
+
return val.__staleWhileFetching;
|
| 1034 |
+
}
|
| 1035 |
+
}
|
| 1036 |
+
else if (val !== undefined) {
|
| 1037 |
+
return val;
|
| 1038 |
+
}
|
| 1039 |
+
}
|
| 1040 |
+
}
|
| 1041 |
+
finally {
|
| 1042 |
+
if (this.#hasDisposeAfter && this.#disposed) {
|
| 1043 |
+
const dt = this.#disposed;
|
| 1044 |
+
let task;
|
| 1045 |
+
while ((task = dt?.shift())) {
|
| 1046 |
+
this.#disposeAfter?.(...task);
|
| 1047 |
+
}
|
| 1048 |
+
}
|
| 1049 |
+
}
|
| 1050 |
+
}
|
| 1051 |
+
#evict(free) {
|
| 1052 |
+
const head = this.#head;
|
| 1053 |
+
const k = this.#keyList[head];
|
| 1054 |
+
const v = this.#valList[head];
|
| 1055 |
+
const isBF = this.#isBackgroundFetch(v);
|
| 1056 |
+
if (isBF) {
|
| 1057 |
+
v.__abortController.abort(new Error('evicted'));
|
| 1058 |
+
}
|
| 1059 |
+
const oldValue = isBF ? v.__staleWhileFetching : v;
|
| 1060 |
+
if ((this.#hasDispose || this.#hasDisposeAfter) &&
|
| 1061 |
+
oldValue !== undefined) {
|
| 1062 |
+
if (this.#hasDispose) {
|
| 1063 |
+
this.#dispose?.(oldValue, k, 'evict');
|
| 1064 |
+
}
|
| 1065 |
+
if (this.#hasDisposeAfter) {
|
| 1066 |
+
this.#disposed?.push([oldValue, k, 'evict']);
|
| 1067 |
+
}
|
| 1068 |
+
}
|
| 1069 |
+
this.#removeItemSize(head);
|
| 1070 |
+
if (this.#autopurgeTimers?.[head]) {
|
| 1071 |
+
clearTimeout(this.#autopurgeTimers[head]);
|
| 1072 |
+
this.#autopurgeTimers[head] = undefined;
|
| 1073 |
+
}
|
| 1074 |
+
// if we aren't about to use the index, then null these out
|
| 1075 |
+
if (free) {
|
| 1076 |
+
this.#keyList[head] = undefined;
|
| 1077 |
+
this.#valList[head] = undefined;
|
| 1078 |
+
this.#free.push(head);
|
| 1079 |
+
}
|
| 1080 |
+
if (this.#size === 1) {
|
| 1081 |
+
this.#head = this.#tail = 0;
|
| 1082 |
+
this.#free.length = 0;
|
| 1083 |
+
}
|
| 1084 |
+
else {
|
| 1085 |
+
this.#head = this.#next[head];
|
| 1086 |
+
}
|
| 1087 |
+
this.#keyMap.delete(k);
|
| 1088 |
+
this.#size--;
|
| 1089 |
+
return head;
|
| 1090 |
+
}
|
| 1091 |
+
/**
|
| 1092 |
+
* Check if a key is in the cache, without updating the recency of use.
|
| 1093 |
+
* Will return false if the item is stale, even though it is technically
|
| 1094 |
+
* in the cache.
|
| 1095 |
+
*
|
| 1096 |
+
* Check if a key is in the cache, without updating the recency of
|
| 1097 |
+
* use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
|
| 1098 |
+
* to `true` in either the options or the constructor.
|
| 1099 |
+
*
|
| 1100 |
+
* Will return `false` if the item is stale, even though it is technically in
|
| 1101 |
+
* the cache. The difference can be determined (if it matters) by using a
|
| 1102 |
+
* `status` argument, and inspecting the `has` field.
|
| 1103 |
+
*
|
| 1104 |
+
* Will not update item age unless
|
| 1105 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
| 1106 |
+
*/
|
| 1107 |
+
has(k, hasOptions = {}) {
|
| 1108 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = hasOptions;
|
| 1109 |
+
hasOptions.status = status;
|
| 1110 |
+
if (status) {
|
| 1111 |
+
status.op = 'has';
|
| 1112 |
+
status.key = k;
|
| 1113 |
+
status.cache = this;
|
| 1114 |
+
}
|
| 1115 |
+
const result = this.#has(k, hasOptions);
|
| 1116 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers)
|
| 1117 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1118 |
+
return result;
|
| 1119 |
+
}
|
| 1120 |
+
#has(k, hasOptions = {}) {
|
| 1121 |
+
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
| 1122 |
+
const index = this.#keyMap.get(k);
|
| 1123 |
+
if (index !== undefined) {
|
| 1124 |
+
const v = this.#valList[index];
|
| 1125 |
+
if (this.#isBackgroundFetch(v) &&
|
| 1126 |
+
v.__staleWhileFetching === undefined) {
|
| 1127 |
+
return false;
|
| 1128 |
+
}
|
| 1129 |
+
if (!this.#isStale(index)) {
|
| 1130 |
+
if (updateAgeOnHas) {
|
| 1131 |
+
this.#updateItemAge(index);
|
| 1132 |
+
}
|
| 1133 |
+
if (status) {
|
| 1134 |
+
status.has = 'hit';
|
| 1135 |
+
this.#statusTTL(status, index);
|
| 1136 |
+
}
|
| 1137 |
+
return true;
|
| 1138 |
+
}
|
| 1139 |
+
else if (status) {
|
| 1140 |
+
status.has = 'stale';
|
| 1141 |
+
this.#statusTTL(status, index);
|
| 1142 |
+
}
|
| 1143 |
+
}
|
| 1144 |
+
else if (status) {
|
| 1145 |
+
status.has = 'miss';
|
| 1146 |
+
}
|
| 1147 |
+
return false;
|
| 1148 |
+
}
|
| 1149 |
+
/**
|
| 1150 |
+
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
| 1151 |
+
* items.
|
| 1152 |
+
*
|
| 1153 |
+
* Returns `undefined` if the item is stale, unless
|
| 1154 |
+
* {@link LRUCache.OptionsBase.allowStale} is set.
|
| 1155 |
+
*/
|
| 1156 |
+
peek(k, peekOptions = {}) {
|
| 1157 |
+
const { status = hasSubscribers() ? {} : undefined } = peekOptions;
|
| 1158 |
+
if (status) {
|
| 1159 |
+
status.op = 'peek';
|
| 1160 |
+
status.key = k;
|
| 1161 |
+
status.cache = this;
|
| 1162 |
+
}
|
| 1163 |
+
peekOptions.status = status;
|
| 1164 |
+
const result = this.#peek(k, peekOptions);
|
| 1165 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers) {
|
| 1166 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1167 |
+
}
|
| 1168 |
+
return result;
|
| 1169 |
+
}
|
| 1170 |
+
#peek(k, peekOptions) {
|
| 1171 |
+
const { status, allowStale = this.allowStale } = peekOptions;
|
| 1172 |
+
const index = this.#keyMap.get(k);
|
| 1173 |
+
if (index === undefined || (!allowStale && this.#isStale(index))) {
|
| 1174 |
+
if (status)
|
| 1175 |
+
status.peek = index === undefined ? 'miss' : 'stale';
|
| 1176 |
+
return undefined;
|
| 1177 |
+
}
|
| 1178 |
+
const v = this.#valList[index];
|
| 1179 |
+
const val = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 1180 |
+
if (status) {
|
| 1181 |
+
if (val !== undefined) {
|
| 1182 |
+
status.peek = 'hit';
|
| 1183 |
+
status.value = val;
|
| 1184 |
+
}
|
| 1185 |
+
else {
|
| 1186 |
+
status.peek = 'miss';
|
| 1187 |
+
}
|
| 1188 |
+
}
|
| 1189 |
+
return val;
|
| 1190 |
+
}
|
| 1191 |
+
#backgroundFetch(k, index, options, context) {
|
| 1192 |
+
const v = index === undefined ? undefined : this.#valList[index];
|
| 1193 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1194 |
+
return v;
|
| 1195 |
+
}
|
| 1196 |
+
const ac = new AbortController();
|
| 1197 |
+
const { signal } = options;
|
| 1198 |
+
// when/if our AC signals, then stop listening to theirs.
|
| 1199 |
+
signal?.addEventListener('abort', () => ac.abort(signal.reason), {
|
| 1200 |
+
signal: ac.signal,
|
| 1201 |
+
});
|
| 1202 |
+
const fetchOpts = {
|
| 1203 |
+
signal: ac.signal,
|
| 1204 |
+
options,
|
| 1205 |
+
context,
|
| 1206 |
+
};
|
| 1207 |
+
const cb = (v, updateCache = false) => {
|
| 1208 |
+
const { aborted } = ac.signal;
|
| 1209 |
+
const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
|
| 1210 |
+
const proceed = options.ignoreFetchAbort ||
|
| 1211 |
+
!!(options.allowStaleOnFetchAbort && v !== undefined);
|
| 1212 |
+
if (options.status) {
|
| 1213 |
+
if (aborted && !updateCache) {
|
| 1214 |
+
options.status.fetchAborted = true;
|
| 1215 |
+
options.status.fetchError = ac.signal.reason;
|
| 1216 |
+
if (ignoreAbort)
|
| 1217 |
+
options.status.fetchAbortIgnored = true;
|
| 1218 |
+
}
|
| 1219 |
+
else {
|
| 1220 |
+
options.status.fetchResolved = true;
|
| 1221 |
+
}
|
| 1222 |
+
}
|
| 1223 |
+
if (aborted && !ignoreAbort && !updateCache) {
|
| 1224 |
+
return fetchFail(ac.signal.reason, proceed);
|
| 1225 |
+
}
|
| 1226 |
+
// either we didn't abort, and are still here, or we did, and ignored
|
| 1227 |
+
const bf = p;
|
| 1228 |
+
// if nothing else has been written there but we're set to update the
|
| 1229 |
+
// cache and ignore the abort, or if it's still pending on this specific
|
| 1230 |
+
// background request, then write it to the cache.
|
| 1231 |
+
const vl = this.#valList[index];
|
| 1232 |
+
if (vl === p || (vl === undefined && ignoreAbort && updateCache)) {
|
| 1233 |
+
if (v === undefined) {
|
| 1234 |
+
if (bf.__staleWhileFetching !== undefined) {
|
| 1235 |
+
this.#valList[index] = bf.__staleWhileFetching;
|
| 1236 |
+
}
|
| 1237 |
+
else {
|
| 1238 |
+
this.#delete(k, 'fetch');
|
| 1239 |
+
}
|
| 1240 |
+
}
|
| 1241 |
+
else {
|
| 1242 |
+
if (options.status)
|
| 1243 |
+
options.status.fetchUpdated = true;
|
| 1244 |
+
this.#set(k, v, fetchOpts.options, bf);
|
| 1245 |
+
}
|
| 1246 |
+
}
|
| 1247 |
+
return v;
|
| 1248 |
+
};
|
| 1249 |
+
const eb = (er) => {
|
| 1250 |
+
if (options.status) {
|
| 1251 |
+
options.status.fetchRejected = true;
|
| 1252 |
+
options.status.fetchError = er;
|
| 1253 |
+
}
|
| 1254 |
+
// do not pass go, do not collect $200
|
| 1255 |
+
return fetchFail(er, false);
|
| 1256 |
+
};
|
| 1257 |
+
const fetchFail = (er, proceed) => {
|
| 1258 |
+
const { aborted } = ac.signal;
|
| 1259 |
+
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
| 1260 |
+
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
| 1261 |
+
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
| 1262 |
+
const bf = p;
|
| 1263 |
+
if (this.#valList[index] === p) {
|
| 1264 |
+
// if we allow stale on fetch rejections, then we need to ensure that
|
| 1265 |
+
// the stale value is not removed from the cache when the fetch fails.
|
| 1266 |
+
const del = !noDelete || (!proceed && bf.__staleWhileFetching === undefined);
|
| 1267 |
+
if (del) {
|
| 1268 |
+
this.#delete(k, 'fetch');
|
| 1269 |
+
}
|
| 1270 |
+
else if (!allowStaleAborted) {
|
| 1271 |
+
// still replace the *promise* with the stale value,
|
| 1272 |
+
// since we are done with the promise at this point.
|
| 1273 |
+
// leave it untouched if we're still waiting for an
|
| 1274 |
+
// aborted background fetch that hasn't yet returned.
|
| 1275 |
+
this.#valList[index] = bf.__staleWhileFetching;
|
| 1276 |
+
}
|
| 1277 |
+
}
|
| 1278 |
+
if (allowStale) {
|
| 1279 |
+
if (options.status && bf.__staleWhileFetching !== undefined) {
|
| 1280 |
+
options.status.returnedStale = true;
|
| 1281 |
+
}
|
| 1282 |
+
return bf.__staleWhileFetching;
|
| 1283 |
+
}
|
| 1284 |
+
else if (bf.__returned === bf) {
|
| 1285 |
+
throw er;
|
| 1286 |
+
}
|
| 1287 |
+
};
|
| 1288 |
+
const pcall = (res, rej) => {
|
| 1289 |
+
const fmp = this.#fetchMethod?.(k, v, fetchOpts);
|
| 1290 |
+
// ignored, we go until we finish, regardless.
|
| 1291 |
+
// defer check until we are actually aborting,
|
| 1292 |
+
// so fetchMethod can override.
|
| 1293 |
+
ac.signal.addEventListener('abort', () => {
|
| 1294 |
+
if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
|
| 1295 |
+
res(undefined);
|
| 1296 |
+
// when it eventually resolves, update the cache.
|
| 1297 |
+
if (options.allowStaleOnFetchAbort) {
|
| 1298 |
+
res = v => cb(v, true);
|
| 1299 |
+
}
|
| 1300 |
+
}
|
| 1301 |
+
});
|
| 1302 |
+
if (fmp && fmp instanceof Promise) {
|
| 1303 |
+
fmp.then(v => res(v === undefined ? undefined : v), rej);
|
| 1304 |
+
}
|
| 1305 |
+
else if (fmp !== undefined) {
|
| 1306 |
+
res(fmp);
|
| 1307 |
+
}
|
| 1308 |
+
};
|
| 1309 |
+
if (options.status)
|
| 1310 |
+
options.status.fetchDispatched = true;
|
| 1311 |
+
const p = new Promise(pcall).then(cb, eb);
|
| 1312 |
+
const bf = Object.assign(p, {
|
| 1313 |
+
__abortController: ac,
|
| 1314 |
+
__staleWhileFetching: v,
|
| 1315 |
+
__returned: undefined,
|
| 1316 |
+
});
|
| 1317 |
+
if (index === undefined) {
|
| 1318 |
+
// internal, don't expose status.
|
| 1319 |
+
this.#set(k, bf, { ...fetchOpts.options, status: undefined });
|
| 1320 |
+
index = this.#keyMap.get(k);
|
| 1321 |
+
}
|
| 1322 |
+
else {
|
| 1323 |
+
// do not call #set, because we do not want to adjust its place
|
| 1324 |
+
// in the lru queue, as it has not yet been "used". Also, we don't
|
| 1325 |
+
// need to worry about evicting for size, because a background fetch
|
| 1326 |
+
// over a stale value is treated as the same size as its stale value.
|
| 1327 |
+
this.#valList[index] = bf;
|
| 1328 |
+
}
|
| 1329 |
+
return bf;
|
| 1330 |
+
}
|
| 1331 |
+
#isBackgroundFetch(p) {
|
| 1332 |
+
if (!this.#hasFetchMethod)
|
| 1333 |
+
return false;
|
| 1334 |
+
const b = p;
|
| 1335 |
+
return (!!b &&
|
| 1336 |
+
b instanceof Promise &&
|
| 1337 |
+
b.hasOwnProperty('__staleWhileFetching') &&
|
| 1338 |
+
b.__abortController instanceof AbortController);
|
| 1339 |
+
}
|
| 1340 |
+
fetch(k, fetchOptions = {}) {
|
| 1341 |
+
const ths = diagnostics_channel_js_1.tracing.hasSubscribers;
|
| 1342 |
+
const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
|
| 1343 |
+
fetchOptions.status = status;
|
| 1344 |
+
if (status && fetchOptions.context) {
|
| 1345 |
+
status.context = fetchOptions.context;
|
| 1346 |
+
}
|
| 1347 |
+
const p = this.#fetch(k, fetchOptions);
|
| 1348 |
+
if (status && ths) {
|
| 1349 |
+
status.trace = true;
|
| 1350 |
+
diagnostics_channel_js_1.tracing.tracePromise(() => p, status).catch(() => { });
|
| 1351 |
+
}
|
| 1352 |
+
return p;
|
| 1353 |
+
}
|
| 1354 |
+
async #fetch(k, fetchOptions = {}) {
|
| 1355 |
+
const {
|
| 1356 |
+
// get options
|
| 1357 |
+
allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
| 1358 |
+
// set options
|
| 1359 |
+
ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
|
| 1360 |
+
// fetch exclusive options
|
| 1361 |
+
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
|
| 1362 |
+
if (status) {
|
| 1363 |
+
status.op = 'fetch';
|
| 1364 |
+
status.key = k;
|
| 1365 |
+
if (forceRefresh)
|
| 1366 |
+
status.forceRefresh = true;
|
| 1367 |
+
status.cache = this;
|
| 1368 |
+
}
|
| 1369 |
+
if (!this.#hasFetchMethod) {
|
| 1370 |
+
if (status)
|
| 1371 |
+
status.fetch = 'get';
|
| 1372 |
+
return this.#get(k, {
|
| 1373 |
+
allowStale,
|
| 1374 |
+
updateAgeOnGet,
|
| 1375 |
+
noDeleteOnStaleGet,
|
| 1376 |
+
status,
|
| 1377 |
+
});
|
| 1378 |
+
}
|
| 1379 |
+
const options = {
|
| 1380 |
+
allowStale,
|
| 1381 |
+
updateAgeOnGet,
|
| 1382 |
+
noDeleteOnStaleGet,
|
| 1383 |
+
ttl,
|
| 1384 |
+
noDisposeOnSet,
|
| 1385 |
+
size,
|
| 1386 |
+
sizeCalculation,
|
| 1387 |
+
noUpdateTTL,
|
| 1388 |
+
noDeleteOnFetchRejection,
|
| 1389 |
+
allowStaleOnFetchRejection,
|
| 1390 |
+
allowStaleOnFetchAbort,
|
| 1391 |
+
ignoreFetchAbort,
|
| 1392 |
+
status,
|
| 1393 |
+
signal,
|
| 1394 |
+
};
|
| 1395 |
+
let index = this.#keyMap.get(k);
|
| 1396 |
+
if (index === undefined) {
|
| 1397 |
+
if (status)
|
| 1398 |
+
status.fetch = 'miss';
|
| 1399 |
+
const p = this.#backgroundFetch(k, index, options, context);
|
| 1400 |
+
return (p.__returned = p);
|
| 1401 |
+
}
|
| 1402 |
+
else {
|
| 1403 |
+
// in cache, maybe already fetching
|
| 1404 |
+
const v = this.#valList[index];
|
| 1405 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1406 |
+
const stale = allowStale && v.__staleWhileFetching !== undefined;
|
| 1407 |
+
if (status) {
|
| 1408 |
+
status.fetch = 'inflight';
|
| 1409 |
+
if (stale)
|
| 1410 |
+
status.returnedStale = true;
|
| 1411 |
+
}
|
| 1412 |
+
return stale ? v.__staleWhileFetching : (v.__returned = v);
|
| 1413 |
+
}
|
| 1414 |
+
// if we force a refresh, that means do NOT serve the cached value,
|
| 1415 |
+
// unless we are already in the process of refreshing the cache.
|
| 1416 |
+
const isStale = this.#isStale(index);
|
| 1417 |
+
if (!forceRefresh && !isStale) {
|
| 1418 |
+
if (status)
|
| 1419 |
+
status.fetch = 'hit';
|
| 1420 |
+
this.#moveToTail(index);
|
| 1421 |
+
if (updateAgeOnGet) {
|
| 1422 |
+
this.#updateItemAge(index);
|
| 1423 |
+
}
|
| 1424 |
+
if (status)
|
| 1425 |
+
this.#statusTTL(status, index);
|
| 1426 |
+
return v;
|
| 1427 |
+
}
|
| 1428 |
+
// ok, it is stale or a forced refresh, and not already fetching.
|
| 1429 |
+
// refresh the cache.
|
| 1430 |
+
const p = this.#backgroundFetch(k, index, options, context);
|
| 1431 |
+
const hasStale = p.__staleWhileFetching !== undefined;
|
| 1432 |
+
const staleVal = hasStale && allowStale;
|
| 1433 |
+
if (status) {
|
| 1434 |
+
status.fetch = isStale ? 'stale' : 'refresh';
|
| 1435 |
+
if (staleVal && isStale)
|
| 1436 |
+
status.returnedStale = true;
|
| 1437 |
+
}
|
| 1438 |
+
return staleVal ? p.__staleWhileFetching : (p.__returned = p);
|
| 1439 |
+
}
|
| 1440 |
+
}
|
| 1441 |
+
forceFetch(k, fetchOptions = {}) {
|
| 1442 |
+
const ths = diagnostics_channel_js_1.tracing.hasSubscribers;
|
| 1443 |
+
const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
|
| 1444 |
+
fetchOptions.status = status;
|
| 1445 |
+
if (status && fetchOptions.context) {
|
| 1446 |
+
status.context = fetchOptions.context;
|
| 1447 |
+
}
|
| 1448 |
+
const p = this.#forceFetch(k, fetchOptions);
|
| 1449 |
+
if (status && ths) {
|
| 1450 |
+
status.trace = true;
|
| 1451 |
+
diagnostics_channel_js_1.tracing.tracePromise(() => p, status).catch(() => { });
|
| 1452 |
+
}
|
| 1453 |
+
return p;
|
| 1454 |
+
}
|
| 1455 |
+
async #forceFetch(k, fetchOptions = {}) {
|
| 1456 |
+
const v = await this.#fetch(k, fetchOptions);
|
| 1457 |
+
if (v === undefined)
|
| 1458 |
+
throw new Error('fetch() returned undefined');
|
| 1459 |
+
return v;
|
| 1460 |
+
}
|
| 1461 |
+
memo(k, memoOptions = {}) {
|
| 1462 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = memoOptions;
|
| 1463 |
+
memoOptions.status = status;
|
| 1464 |
+
if (status) {
|
| 1465 |
+
status.op = 'memo';
|
| 1466 |
+
status.key = k;
|
| 1467 |
+
if (memoOptions.context) {
|
| 1468 |
+
status.context = memoOptions.context;
|
| 1469 |
+
}
|
| 1470 |
+
status.cache = this;
|
| 1471 |
+
}
|
| 1472 |
+
const result = this.#memo(k, memoOptions);
|
| 1473 |
+
if (status)
|
| 1474 |
+
status.value = result;
|
| 1475 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers)
|
| 1476 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1477 |
+
return result;
|
| 1478 |
+
}
|
| 1479 |
+
#memo(k, memoOptions = {}) {
|
| 1480 |
+
const memoMethod = this.#memoMethod;
|
| 1481 |
+
if (!memoMethod) {
|
| 1482 |
+
throw new Error('no memoMethod provided to constructor');
|
| 1483 |
+
}
|
| 1484 |
+
const { context, status, forceRefresh, ...options } = memoOptions;
|
| 1485 |
+
if (status && forceRefresh)
|
| 1486 |
+
status.forceRefresh = true;
|
| 1487 |
+
const v = this.#get(k, options);
|
| 1488 |
+
const refresh = forceRefresh || v === undefined;
|
| 1489 |
+
if (status) {
|
| 1490 |
+
status.memo = refresh ? 'miss' : 'hit';
|
| 1491 |
+
if (!refresh)
|
| 1492 |
+
status.value = v;
|
| 1493 |
+
}
|
| 1494 |
+
if (!refresh)
|
| 1495 |
+
return v;
|
| 1496 |
+
const vv = memoMethod(k, v, {
|
| 1497 |
+
options,
|
| 1498 |
+
context,
|
| 1499 |
+
});
|
| 1500 |
+
if (status)
|
| 1501 |
+
status.value = vv;
|
| 1502 |
+
this.#set(k, vv, options);
|
| 1503 |
+
return vv;
|
| 1504 |
+
}
|
| 1505 |
+
/**
|
| 1506 |
+
* Return a value from the cache. Will update the recency of the cache
|
| 1507 |
+
* entry found.
|
| 1508 |
+
*
|
| 1509 |
+
* If the key is not found, get() will return `undefined`.
|
| 1510 |
+
*/
|
| 1511 |
+
get(k, getOptions = {}) {
|
| 1512 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = getOptions;
|
| 1513 |
+
getOptions.status = status;
|
| 1514 |
+
if (status) {
|
| 1515 |
+
status.op = 'get';
|
| 1516 |
+
status.key = k;
|
| 1517 |
+
status.cache = this;
|
| 1518 |
+
}
|
| 1519 |
+
const result = this.#get(k, getOptions);
|
| 1520 |
+
if (status) {
|
| 1521 |
+
if (result !== undefined)
|
| 1522 |
+
status.value = result;
|
| 1523 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers)
|
| 1524 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1525 |
+
}
|
| 1526 |
+
return result;
|
| 1527 |
+
}
|
| 1528 |
+
#get(k, getOptions = {}) {
|
| 1529 |
+
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
|
| 1530 |
+
const index = this.#keyMap.get(k);
|
| 1531 |
+
if (index === undefined) {
|
| 1532 |
+
if (status)
|
| 1533 |
+
status.get = 'miss';
|
| 1534 |
+
return undefined;
|
| 1535 |
+
}
|
| 1536 |
+
const value = this.#valList[index];
|
| 1537 |
+
const fetching = this.#isBackgroundFetch(value);
|
| 1538 |
+
if (status)
|
| 1539 |
+
this.#statusTTL(status, index);
|
| 1540 |
+
if (this.#isStale(index)) {
|
| 1541 |
+
// delete only if not an in-flight background fetch
|
| 1542 |
+
if (!fetching) {
|
| 1543 |
+
if (!noDeleteOnStaleGet) {
|
| 1544 |
+
this.#delete(k, 'expire');
|
| 1545 |
+
}
|
| 1546 |
+
if (status)
|
| 1547 |
+
status.get = 'stale';
|
| 1548 |
+
if (allowStale) {
|
| 1549 |
+
if (status)
|
| 1550 |
+
status.returnedStale = true;
|
| 1551 |
+
return value;
|
| 1552 |
+
}
|
| 1553 |
+
return undefined;
|
| 1554 |
+
}
|
| 1555 |
+
if (status)
|
| 1556 |
+
status.get = 'stale-fetching';
|
| 1557 |
+
if (allowStale && value.__staleWhileFetching !== undefined) {
|
| 1558 |
+
if (status)
|
| 1559 |
+
status.returnedStale = true;
|
| 1560 |
+
return value.__staleWhileFetching;
|
| 1561 |
+
}
|
| 1562 |
+
return undefined;
|
| 1563 |
+
}
|
| 1564 |
+
// not stale
|
| 1565 |
+
if (status)
|
| 1566 |
+
status.get = fetching ? 'fetching' : 'hit';
|
| 1567 |
+
// if we're currently fetching it, we don't actually have it yet
|
| 1568 |
+
// it's not stale, which means this isn't a staleWhileRefetching.
|
| 1569 |
+
// If it's not stale, and fetching, AND has a __staleWhileFetching
|
| 1570 |
+
// value, then that means the user fetched with {forceRefresh:true},
|
| 1571 |
+
// so it's safe to return that value.
|
| 1572 |
+
this.#moveToTail(index);
|
| 1573 |
+
if (updateAgeOnGet) {
|
| 1574 |
+
this.#updateItemAge(index);
|
| 1575 |
+
}
|
| 1576 |
+
return fetching ? value.__staleWhileFetching : value;
|
| 1577 |
+
}
|
| 1578 |
+
#connect(p, n) {
|
| 1579 |
+
this.#prev[n] = p;
|
| 1580 |
+
this.#next[p] = n;
|
| 1581 |
+
}
|
| 1582 |
+
#moveToTail(index) {
|
| 1583 |
+
// if tail already, nothing to do
|
| 1584 |
+
// if head, move head to next[index]
|
| 1585 |
+
// else
|
| 1586 |
+
// move next[prev[index]] to next[index] (head has no prev)
|
| 1587 |
+
// move prev[next[index]] to prev[index]
|
| 1588 |
+
// prev[index] = tail
|
| 1589 |
+
// next[tail] = index
|
| 1590 |
+
// tail = index
|
| 1591 |
+
if (index !== this.#tail) {
|
| 1592 |
+
if (index === this.#head) {
|
| 1593 |
+
this.#head = this.#next[index];
|
| 1594 |
+
}
|
| 1595 |
+
else {
|
| 1596 |
+
this.#connect(this.#prev[index], this.#next[index]);
|
| 1597 |
+
}
|
| 1598 |
+
this.#connect(this.#tail, index);
|
| 1599 |
+
this.#tail = index;
|
| 1600 |
+
}
|
| 1601 |
+
}
|
| 1602 |
+
/**
|
| 1603 |
+
* Deletes a key out of the cache.
|
| 1604 |
+
*
|
| 1605 |
+
* Returns true if the key was deleted, false otherwise.
|
| 1606 |
+
*/
|
| 1607 |
+
delete(k) {
|
| 1608 |
+
return this.#delete(k, 'delete');
|
| 1609 |
+
}
|
| 1610 |
+
#delete(k, reason) {
|
| 1611 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers) {
|
| 1612 |
+
diagnostics_channel_js_1.metrics.publish({
|
| 1613 |
+
op: 'delete',
|
| 1614 |
+
delete: reason,
|
| 1615 |
+
key: k,
|
| 1616 |
+
cache: this,
|
| 1617 |
+
});
|
| 1618 |
+
}
|
| 1619 |
+
let deleted = false;
|
| 1620 |
+
if (this.#size !== 0) {
|
| 1621 |
+
const index = this.#keyMap.get(k);
|
| 1622 |
+
if (index !== undefined) {
|
| 1623 |
+
if (this.#autopurgeTimers?.[index]) {
|
| 1624 |
+
clearTimeout(this.#autopurgeTimers?.[index]);
|
| 1625 |
+
this.#autopurgeTimers[index] = undefined;
|
| 1626 |
+
}
|
| 1627 |
+
deleted = true;
|
| 1628 |
+
if (this.#size === 1) {
|
| 1629 |
+
this.#clear(reason);
|
| 1630 |
+
}
|
| 1631 |
+
else {
|
| 1632 |
+
this.#removeItemSize(index);
|
| 1633 |
+
const v = this.#valList[index];
|
| 1634 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1635 |
+
v.__abortController.abort(new Error('deleted'));
|
| 1636 |
+
}
|
| 1637 |
+
else if (this.#hasDispose || this.#hasDisposeAfter) {
|
| 1638 |
+
if (this.#hasDispose) {
|
| 1639 |
+
this.#dispose?.(v, k, reason);
|
| 1640 |
+
}
|
| 1641 |
+
if (this.#hasDisposeAfter) {
|
| 1642 |
+
this.#disposed?.push([v, k, reason]);
|
| 1643 |
+
}
|
| 1644 |
+
}
|
| 1645 |
+
this.#keyMap.delete(k);
|
| 1646 |
+
this.#keyList[index] = undefined;
|
| 1647 |
+
this.#valList[index] = undefined;
|
| 1648 |
+
if (index === this.#tail) {
|
| 1649 |
+
this.#tail = this.#prev[index];
|
| 1650 |
+
}
|
| 1651 |
+
else if (index === this.#head) {
|
| 1652 |
+
this.#head = this.#next[index];
|
| 1653 |
+
}
|
| 1654 |
+
else {
|
| 1655 |
+
const pi = this.#prev[index];
|
| 1656 |
+
this.#next[pi] = this.#next[index];
|
| 1657 |
+
const ni = this.#next[index];
|
| 1658 |
+
this.#prev[ni] = this.#prev[index];
|
| 1659 |
+
}
|
| 1660 |
+
this.#size--;
|
| 1661 |
+
this.#free.push(index);
|
| 1662 |
+
}
|
| 1663 |
+
}
|
| 1664 |
+
}
|
| 1665 |
+
if (this.#hasDisposeAfter && this.#disposed?.length) {
|
| 1666 |
+
const dt = this.#disposed;
|
| 1667 |
+
let task;
|
| 1668 |
+
while ((task = dt?.shift())) {
|
| 1669 |
+
this.#disposeAfter?.(...task);
|
| 1670 |
+
}
|
| 1671 |
+
}
|
| 1672 |
+
return deleted;
|
| 1673 |
+
}
|
| 1674 |
+
/**
|
| 1675 |
+
* Clear the cache entirely, throwing away all values.
|
| 1676 |
+
*/
|
| 1677 |
+
clear() {
|
| 1678 |
+
return this.#clear('delete');
|
| 1679 |
+
}
|
| 1680 |
+
#clear(reason) {
|
| 1681 |
+
for (const index of this.#rindexes({ allowStale: true })) {
|
| 1682 |
+
const v = this.#valList[index];
|
| 1683 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1684 |
+
v.__abortController.abort(new Error('deleted'));
|
| 1685 |
+
}
|
| 1686 |
+
else {
|
| 1687 |
+
const k = this.#keyList[index];
|
| 1688 |
+
if (this.#hasDispose) {
|
| 1689 |
+
this.#dispose?.(v, k, reason);
|
| 1690 |
+
}
|
| 1691 |
+
if (this.#hasDisposeAfter) {
|
| 1692 |
+
this.#disposed?.push([v, k, reason]);
|
| 1693 |
+
}
|
| 1694 |
+
}
|
| 1695 |
+
}
|
| 1696 |
+
this.#keyMap.clear();
|
| 1697 |
+
void this.#valList.fill(undefined);
|
| 1698 |
+
this.#keyList.fill(undefined);
|
| 1699 |
+
if (this.#ttls && this.#starts) {
|
| 1700 |
+
this.#ttls.fill(0);
|
| 1701 |
+
this.#starts.fill(0);
|
| 1702 |
+
for (const t of this.#autopurgeTimers ?? []) {
|
| 1703 |
+
if (t !== undefined)
|
| 1704 |
+
clearTimeout(t);
|
| 1705 |
+
}
|
| 1706 |
+
this.#autopurgeTimers?.fill(undefined);
|
| 1707 |
+
}
|
| 1708 |
+
if (this.#sizes) {
|
| 1709 |
+
this.#sizes.fill(0);
|
| 1710 |
+
}
|
| 1711 |
+
this.#head = 0;
|
| 1712 |
+
this.#tail = 0;
|
| 1713 |
+
this.#free.length = 0;
|
| 1714 |
+
this.#calculatedSize = 0;
|
| 1715 |
+
this.#size = 0;
|
| 1716 |
+
if (this.#hasDisposeAfter && this.#disposed) {
|
| 1717 |
+
const dt = this.#disposed;
|
| 1718 |
+
let task;
|
| 1719 |
+
while ((task = dt?.shift())) {
|
| 1720 |
+
this.#disposeAfter?.(...task);
|
| 1721 |
+
}
|
| 1722 |
+
}
|
| 1723 |
+
}
|
| 1724 |
+
}
|
| 1725 |
+
exports.LRUCache = LRUCache;
|
| 1726 |
+
//# sourceMappingURL=index.js.map
|
node_modules/lru-cache/dist/commonjs/browser/index.js.map
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/lru-cache/dist/commonjs/browser/index.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";var j=(c,t)=>()=>(t||c((t={exports:{}}).exports,t),t.exports);var I=j(O=>{"use strict";Object.defineProperty(O,"__esModule",{value:!0});O.tracing=O.metrics=void 0;var U={hasSubscribers:!1};O.metrics=U;O.tracing=U});var P=j(D=>{"use strict";Object.defineProperty(D,"__esModule",{value:!0});D.defaultPerf=void 0;D.defaultPerf=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date});Object.defineProperty(exports,"__esModule",{value:!0});exports.LRUCache=void 0;var g=I(),N=P(),x=()=>g.metrics.hasSubscribers||g.tracing.hasSubscribers,k=new Set,G=typeof process=="object"&&process?process:{},V=(c,t,e,i)=>{typeof G.emitWarning=="function"?G.emitWarning(c,t,e,i):console.error(`[${e}] ${t}: ${c}`)},B=c=>!k.has(c);var T=c=>!!c&&c===Math.floor(c)&&c>0&&isFinite(c),H=c=>T(c)?c<=Math.pow(2,8)?Uint8Array:c<=Math.pow(2,16)?Uint16Array:c<=Math.pow(2,32)?Uint32Array:c<=Number.MAX_SAFE_INTEGER?W:null:null,W=class extends Array{constructor(t){super(t),this.fill(0)}},C=class c{heap;length;static#o=!1;static create(t){let e=H(t);if(!e)return[];c.#o=!0;let i=new c(t,e);return c.#o=!1,i}constructor(t,e){if(!c.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},L=class c{#o;#c;#m;#W;#S;#M;#j;#w;get perf(){return this.#w}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;backgroundFetchSize;#n;#b;#s;#i;#t;#l;#u;#a;#h;#y;#r;#_;#F;#d;#g;#T;#U;#f;#D;static unsafeExposeInternals(t){return{starts:t.#F,ttls:t.#d,autopurgeTimers:t.#g,sizes:t.#_,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#l,prev:t.#u,get head(){return t.#a},get tail(){return t.#h},free:t.#y,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,n)=>t.#G(e,i,s,n),moveToTail:e=>t.#L(e),indexes:e=>t.#A(e),rindexes:e=>t.#z(e),isStale:e=>t.#p(e)}}get max(){return this.#o}get maxSize(){return this.#c}get calculatedSize(){return this.#b}get size(){return this.#n}get fetchMethod(){return this.#M}get memoMethod(){return this.#j}get dispose(){return this.#m}get onInsert(){return this.#W}get disposeAfter(){return this.#S}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:r,updateAgeOnHas:h,allowStale:a,dispose:o,onInsert:d,disposeAfter:y,noDisposeOnSet:_,noUpdateTTL:u,maxSize:p=0,maxEntrySize:f=0,sizeCalculation:b,fetchMethod:l,memoMethod:S,noDeleteOnFetchRejection:F,noDeleteOnStaleGet:w,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:A,ignoreFetchAbort:z,backgroundFetchSize:M=1,perf:v}=t;if(this.backgroundFetchSize=M,v!==void 0&&typeof v?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#w=v??N.defaultPerf,e!==0&&!T(e))throw new TypeError("max option must be a nonnegative integer");let E=e?H(e):Array;if(!E)throw new Error("invalid max value: "+e);if(this.#o=e,this.#c=p,this.maxEntrySize=f||this.#c,this.sizeCalculation=b,this.sizeCalculation){if(!this.#c&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(S!==void 0&&typeof S!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#j=S,l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#M=l,this.#U=!!l,this.#s=new Map,this.#i=Array.from({length:e}).fill(void 0),this.#t=Array.from({length:e}).fill(void 0),this.#l=new E(e),this.#u=new E(e),this.#a=0,this.#h=0,this.#y=C.create(e),this.#n=0,this.#b=0,typeof o=="function"&&(this.#m=o),typeof d=="function"&&(this.#W=d),typeof y=="function"?(this.#S=y,this.#r=[]):(this.#S=void 0,this.#r=void 0),this.#T=!!this.#m,this.#D=!!this.#W,this.#f=!!this.#S,this.noDisposeOnSet=!!_,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!F,this.allowStaleOnFetchRejection=!!m,this.allowStaleOnFetchAbort=!!A,this.ignoreFetchAbort=!!z,this.maxEntrySize!==0){if(this.#c!==0&&!T(this.#c))throw new TypeError("maxSize must be a positive integer if specified");if(!T(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#X()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!w,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!h,this.ttlResolution=T(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!T(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#k()}if(this.#o===0&&this.ttl===0&&this.#c===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#c){let R="LRU_CACHE_UNBOUNDED";B(R)&&(k.add(R),V("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",R,c))}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#k(){let t=new W(this.#o),e=new W(this.#o);this.#d=t,this.#F=e;let i=this.ttlAutopurge?Array.from({length:this.#o}):void 0;this.#g=i,this.#H=(h,a,o=this.#w.now())=>{e[h]=a!==0?o:0,t[h]=a,s(h,a)},this.#R=h=>{e[h]=t[h]!==0?this.#w.now():0,s(h,t[h])};let s=this.ttlAutopurge?(h,a)=>{if(i?.[h]&&(clearTimeout(i[h]),i[h]=void 0),a&&a!==0&&i){let o=setTimeout(()=>{this.#p(h)&&this.#v(this.#i[h],"expire")},a+1);o.unref&&o.unref(),i[h]=o}}:()=>{};this.#E=(h,a)=>{if(t[a]){let o=t[a],d=e[a];if(!o||!d)return;h.ttl=o,h.start=d,h.now=n||r();let y=h.now-d;h.remainingTTL=o-y}};let n=0,r=()=>{let h=this.#w.now();if(this.ttlResolution>0){n=h;let a=setTimeout(()=>n=0,this.ttlResolution);a.unref&&a.unref()}return h};this.getRemainingTTL=h=>{let a=this.#s.get(h);if(a===void 0)return 0;let o=t[a],d=e[a];if(!o||!d)return 1/0;let y=(n||r())-d;return o-y},this.#p=h=>{let a=e[h],o=t[h];return!!o&&!!a&&(n||r())-a>o}}#R=()=>{};#E=()=>{};#H=()=>{};#p=()=>!1;#X(){let t=new W(this.#o);this.#b=0,this.#_=t,this.#x=e=>{this.#b-=t[e],t[e]=0},this.#N=(e,i,s,n)=>{if(!T(s)){if(this.#e(i))return this.backgroundFetchSize;if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,e),!T(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.")}return s},this.#I=(e,i,s)=>{if(t[e]=i,this.#c){let n=this.#c-t[e];for(;this.#b>n;)this.#P(!0)}this.#b+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#b)}}#x=t=>{};#I=(t,e,i)=>{};#N=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;this.#V(e)&&((t||!this.#p(e))&&(yield e),e!==this.#a);)e=this.#u[e]}*#z({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#a;this.#V(e)&&((t||!this.#p(e))&&(yield e),e!==this.#h);)e=this.#l[e]}#V(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#A())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*rentries(){for(let t of this.#z())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*keys(){for(let t of this.#A()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*rkeys(){for(let t of this.#z()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*values(){for(let t of this.#A())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}*rvalues(){for(let t of this.#z())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&t(n,this.#i[i],this))return this.#C(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}rforEach(t,e=this){for(let i of this.#z()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}purgeStale(){let t=!1;for(let e of this.#z({allowStale:!0}))this.#p(e)&&(this.#v(this.#i[e],"expire"),t=!0);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#d&&this.#F){let r=this.#d[e],h=this.#F[e];if(r&&h){let a=r-(this.#w.now()-h);n.ttl=a,n.start=Date.now()}}return this.#_&&(n.size=this.#_[e]),n}dump(){let t=[];for(let e of this.#A({allowStale:!0})){let i=this.#i[e],s=this.#t[e],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let r={value:n};if(this.#d&&this.#F){r.ttl=this.#d[e];let h=this.#w.now()-this.#F[e];r.start=Math.floor(Date.now()-h)}this.#_&&(r.size=this.#_[e]),t.unshift([i,r])}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=this.#w.now()-s}this.#O(e,i.value,i)}}set(t,e,i={}){let{status:s=g.metrics.hasSubscribers?{}:void 0}=i;i.status=s,s&&(s.op="set",s.key=t,e!==void 0&&(s.value=e),s.cache=this);let n=this.#O(t,e,i);return s&&g.metrics.hasSubscribers&&g.metrics.publish(s),n}#O(t,e,i,s){let{ttl:n=this.ttl,start:r,noDisposeOnSet:h=this.noDisposeOnSet,sizeCalculation:a=this.sizeCalculation,status:o}=i,d=this.#e(e);if(e===void 0)return o&&(o.set="deleted"),this.delete(t),this;let{noUpdateTTL:y=this.noUpdateTTL}=i;o&&!d&&(o.value=e);let _=this.#N(t,e,i.size||0,a,o);if(this.maxEntrySize&&_>this.maxEntrySize)return this.#v(t,"set"),o&&(o.set="miss",o.maxEntrySizeExceeded=!0),this;let u=this.#n===0?void 0:this.#s.get(t);if(u===void 0)u=this.#n===0?this.#h:this.#y.length!==0?this.#y.pop():this.#n===this.#o?this.#P(!1):this.#n,this.#i[u]=t,this.#t[u]=e,this.#s.set(t,u),this.#l[this.#h]=u,this.#u[u]=this.#h,this.#h=u,this.#n++,this.#I(u,_,o),o&&(o.set="add"),y=!1,this.#D&&!d&&this.#W?.(e,t,"add");else{this.#L(u);let p=this.#t[u];if(e!==p){if(!h)if(this.#e(p)){p!==s&&p.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:f}=p;f!==void 0&&f!==e&&(this.#T&&this.#m?.(f,t,"set"),this.#f&&this.#r?.push([f,t,"set"]))}else this.#T&&this.#m?.(p,t,"set"),this.#f&&this.#r?.push([p,t,"set"]);if(this.#x(u),this.#I(u,_,o),this.#t[u]=e,!d){let f=p&&this.#e(p)?p.__staleWhileFetching:p,b=f===void 0?"add":e!==f?"replace":"update";o&&(o.set=b,f!==void 0&&(o.oldValue=f)),this.#D&&this.onInsert?.(e,t,b)}}else d||(o&&(o.set="update"),this.#D&&this.onInsert?.(e,t,"update"))}if(n!==0&&!this.#d&&this.#k(),this.#d&&(y||this.#H(u,n,r),o&&this.#E(o,u)),!h&&this.#f&&this.#r){let p=this.#r,f;for(;f=p?.shift();)this.#S?.(...f)}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#a];if(this.#P(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#f&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#S?.(...e)}}}#P(t){let e=this.#a,i=this.#i[e],s=this.#t[e],n=this.#e(s);n&&s.__abortController.abort(new Error("evicted"));let r=n?s.__staleWhileFetching:s;return(this.#T||this.#f)&&r!==void 0&&(this.#T&&this.#m?.(r,i,"evict"),this.#f&&this.#r?.push([r,i,"evict"])),this.#x(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.#y.push(e)),this.#n===1?(this.#a=this.#h=0,this.#y.length=0):this.#a=this.#l[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{status:i=g.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="has",i.key=t,i.cache=this);let s=this.#Y(t,e);return g.metrics.hasSubscribers&&g.metrics.publish(i),s}#Y(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#s.get(t);if(n!==void 0){let r=this.#t[n];if(this.#e(r)&&r.__staleWhileFetching===void 0)return!1;if(this.#p(n))s&&(s.has="stale",this.#E(s,n));else return i&&this.#R(n),s&&(s.has="hit",this.#E(s,n)),!0}else s&&(s.has="miss");return!1}peek(t,e={}){let{status:i=x()?{}:void 0}=e;i&&(i.op="peek",i.key=t,i.cache=this),e.status=i;let s=this.#J(t,e);return g.metrics.hasSubscribers&&g.metrics.publish(i),s}#J(t,e){let{status:i,allowStale:s=this.allowStale}=e,n=this.#s.get(t);if(n===void 0||!s&&this.#p(n)){i&&(i.peek=n===void 0?"miss":"stale");return}let r=this.#t[n],h=this.#e(r)?r.__staleWhileFetching:r;return i&&(h!==void 0?(i.peek="hit",i.value=h):i.peek="miss"),h}#G(t,e,i,s){let n=e===void 0?void 0:this.#t[e];if(this.#e(n))return n;let r=new AbortController,{signal:h}=i;h?.addEventListener("abort",()=>r.abort(h.reason),{signal:r.signal});let a={signal:r.signal,options:i,context:s},o=(f,b=!1)=>{let{aborted:l}=r.signal,S=i.ignoreFetchAbort&&f!==void 0,F=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&f!==void 0);if(i.status&&(l&&!b?(i.status.fetchAborted=!0,i.status.fetchError=r.signal.reason,S&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),l&&!S&&!b)return y(r.signal.reason,F);let w=u,m=this.#t[e];return(m===u||m===void 0&&S&&b)&&(f===void 0?w.__staleWhileFetching!==void 0?this.#t[e]=w.__staleWhileFetching:this.#v(t,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.#O(t,f,a.options,w))),f},d=f=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=f),y(f,!1)),y=(f,b)=>{let{aborted:l}=r.signal,S=l&&i.allowStaleOnFetchAbort,F=S||i.allowStaleOnFetchRejection,w=F||i.noDeleteOnFetchRejection,m=u;if(this.#t[e]===u&&(!w||!b&&m.__staleWhileFetching===void 0?this.#v(t,"fetch"):S||(this.#t[e]=m.__staleWhileFetching)),F)return i.status&&m.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),m.__staleWhileFetching;if(m.__returned===m)throw f},_=(f,b)=>{let l=this.#M?.(t,n,a);r.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(f(void 0),i.allowStaleOnFetchAbort&&(f=S=>o(S,!0)))}),l&&l instanceof Promise?l.then(S=>f(S===void 0?void 0:S),b):l!==void 0&&f(l)};i.status&&(i.status.fetchDispatched=!0);let u=new Promise(_).then(o,d),p=Object.assign(u,{__abortController:r,__staleWhileFetching:n,__returned:void 0});return e===void 0?(this.#O(t,p,{...a.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=p,p}#e(t){if(!this.#U)return!1;let e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof AbortController}fetch(t,e={}){let i=g.tracing.hasSubscribers,{status:s=x()?{}:void 0}=e;e.status=s,s&&e.context&&(s.context=e.context);let n=this.#B(t,e);return s&&i&&(s.trace=!0,g.tracing.tracePromise(()=>n,s).catch(()=>{})),n}async#B(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:r=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:a=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:d=this.noUpdateTTL,noDeleteOnFetchRejection:y=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:_=this.allowStaleOnFetchRejection,ignoreFetchAbort:u=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:f,forceRefresh:b=!1,status:l,signal:S}=e;if(l&&(l.op="fetch",l.key=t,b&&(l.forceRefresh=!0),l.cache=this),!this.#U)return l&&(l.fetch="get"),this.#C(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:l});let F={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:r,noDisposeOnSet:h,size:a,sizeCalculation:o,noUpdateTTL:d,noDeleteOnFetchRejection:y,allowStaleOnFetchRejection:_,allowStaleOnFetchAbort:p,ignoreFetchAbort:u,status:l,signal:S},w=this.#s.get(t);if(w===void 0){l&&(l.fetch="miss");let m=this.#G(t,w,F,f);return m.__returned=m}else{let m=this.#t[w];if(this.#e(m)){let E=i&&m.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",E&&(l.returnedStale=!0)),E?m.__staleWhileFetching:m.__returned=m}let A=this.#p(w);if(!b&&!A)return l&&(l.fetch="hit"),this.#L(w),s&&this.#R(w),l&&this.#E(l,w),m;let z=this.#G(t,w,F,f),v=z.__staleWhileFetching!==void 0&&i;return l&&(l.fetch=A?"stale":"refresh",v&&A&&(l.returnedStale=!0)),v?z.__staleWhileFetching:z.__returned=z}}forceFetch(t,e={}){let i=g.tracing.hasSubscribers,{status:s=x()?{}:void 0}=e;e.status=s,s&&e.context&&(s.context=e.context);let n=this.#K(t,e);return s&&i&&(s.trace=!0,g.tracing.tracePromise(()=>n,s).catch(()=>{})),n}async#K(t,e={}){let i=await this.#B(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let{status:i=g.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="memo",i.key=t,e.context&&(i.context=e.context),i.cache=this);let s=this.#Q(t,e);return i&&(i.value=s),g.metrics.hasSubscribers&&g.metrics.publish(i),s}#Q(t,e={}){let i=this.#j;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,status:n,forceRefresh:r,...h}=e;n&&r&&(n.forceRefresh=!0);let a=this.#C(t,h),o=r||a===void 0;if(n&&(n.memo=o?"miss":"hit",o||(n.value=a)),!o)return a;let d=i(t,a,{options:h,context:s});return n&&(n.value=d),this.#O(t,d,h),d}get(t,e={}){let{status:i=g.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="get",i.key=t,i.cache=this);let s=this.#C(t,e);return i&&(s!==void 0&&(i.value=s),g.metrics.hasSubscribers&&g.metrics.publish(i)),s}#C(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:r}=e,h=this.#s.get(t);if(h===void 0){r&&(r.get="miss");return}let a=this.#t[h],o=this.#e(a);return r&&this.#E(r,h),this.#p(h)?o?(r&&(r.get="stale-fetching"),i&&a.__staleWhileFetching!==void 0?(r&&(r.returnedStale=!0),a.__staleWhileFetching):void 0):(n||this.#v(t,"expire"),r&&(r.get="stale"),i?(r&&(r.returnedStale=!0),a):void 0):(r&&(r.get=o?"fetching":"hit"),this.#L(h),s&&this.#R(h),o?a.__staleWhileFetching:a)}#q(t,e){this.#u[e]=t,this.#l[t]=e}#L(t){t!==this.#h&&(t===this.#a?this.#a=this.#l[t]:this.#q(this.#u[t],this.#l[t]),this.#q(this.#h,t),this.#h=t)}delete(t){return this.#v(t,"delete")}#v(t,e){g.metrics.hasSubscribers&&g.metrics.publish({op:"delete",delete:e,key:t,cache:this});let i=!1;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=!0,this.#n===1)this.#$(e);else{this.#x(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#m?.(n,t,e),this.#f&&this.#r?.push([n,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#u[s];else if(s===this.#a)this.#a=this.#l[s];else{let r=this.#u[s];this.#l[r]=this.#l[s];let h=this.#l[s];this.#u[h]=this.#u[s]}this.#n--,this.#y.push(s)}}if(this.#f&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#S?.(...n)}return i}clear(){return this.#$("delete")}#$(t){for(let e of this.#z({allowStale:!0})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[e];this.#T&&this.#m?.(i,s,t),this.#f&&this.#r?.push([i,s,t])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#F){this.#d.fill(0),this.#F.fill(0);for(let e of this.#g??[])e!==void 0&&clearTimeout(e);this.#g?.fill(void 0)}if(this.#_&&this.#_.fill(0),this.#a=0,this.#h=0,this.#y.length=0,this.#b=0,this.#n=0,this.#f&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#S?.(...i)}}};exports.LRUCache=L;
|
| 2 |
+
//# sourceMappingURL=index.min.js.map
|
node_modules/lru-cache/dist/commonjs/browser/index.min.js.map
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/lru-cache/dist/commonjs/browser/perf.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* this provides the default Perf object source, either the
|
| 3 |
+
* `performance` global, or the `Date` constructor.
|
| 4 |
+
*
|
| 5 |
+
* it can be passed in via configuration to override it
|
| 6 |
+
* for a single LRU object.
|
| 7 |
+
*/
|
| 8 |
+
export type Perf = {
|
| 9 |
+
now: () => number;
|
| 10 |
+
};
|
| 11 |
+
export declare const defaultPerf: Perf;
|
| 12 |
+
//# sourceMappingURL=perf.d.ts.map
|
node_modules/lru-cache/dist/commonjs/browser/perf.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../../../src/perf.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,IAAI,GAAG;IAAE,GAAG,EAAE,MAAM,MAAM,CAAA;CAAE,CAAA;AACxC,eAAO,MAAM,WAAW,EAAE,IAQG,CAAA"}
|
node_modules/lru-cache/dist/commonjs/browser/perf.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.defaultPerf = void 0;
|
| 4 |
+
exports.defaultPerf = (typeof performance === 'object' &&
|
| 5 |
+
performance &&
|
| 6 |
+
typeof performance.now === 'function') ?
|
| 7 |
+
/* c8 ignore start - this gets covered, but c8 gets confused */
|
| 8 |
+
performance
|
| 9 |
+
: /* c8 ignore stop */ Date;
|
| 10 |
+
//# sourceMappingURL=perf.js.map
|
node_modules/lru-cache/dist/commonjs/browser/perf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"perf.js","sourceRoot":"","sources":["../../../src/perf.ts"],"names":[],"mappings":";;;AAQa,QAAA,WAAW,GACtB,CACE,OAAO,WAAW,KAAK,QAAQ;IAC/B,WAAW;IACX,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU,CACtC,CAAC,CAAC;IACD,+DAA+D;IAC/D,WAAW;IACb,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAA","sourcesContent":["/**\n * this provides the default Perf object source, either the\n * `performance` global, or the `Date` constructor.\n *\n * it can be passed in via configuration to override it\n * for a single LRU object.\n */\nexport type Perf = { now: () => number }\nexport const defaultPerf: Perf =\n (\n typeof performance === 'object' &&\n performance &&\n typeof performance.now === 'function'\n ) ?\n /* c8 ignore start - this gets covered, but c8 gets confused */\n performance\n : /* c8 ignore stop */ Date\n"]}
|
node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"diagnostics-channel-cjs.cjs","sourceRoot":"","sources":["../../src/diagnostics-channel-cjs.cts"],"names":[],"mappings":";;;AAQA,MAAM,KAAK,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,CAAA;AAC1B,QAAA,OAAO,GAAG,KAAyB,CAAA;AACnC,QAAA,OAAO,GAAG,KAAgC,CAAA","sourcesContent":["// this is used in CJS environments that do NOT follow the 'node' import\n// condition, to avoid even trying to load node:diagnostics_channel\nimport {\n type Channel,\n type TracingChannel,\n} from 'node:diagnostics_channel'\nexport type { TracingChannel, Channel }\n\nconst dummy = { hasSubscribers: false }\nexport const metrics = dummy as Channel<unknown>\nexport const tracing = dummy as TracingChannel<unknown>\n"]}
|
node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"diagnostics-channel-cjs.d.cts","sourceRoot":"","sources":["../../src/diagnostics-channel-cjs.cts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,CAAA;AAGvC,eAAO,MAAM,OAAO,EAAY,OAAO,CAAC,OAAO,CAAC,CAAA;AAChD,eAAO,MAAM,OAAO,EAAY,cAAc,CAAC,OAAO,CAAC,CAAA"}
|
node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { type Channel, type TracingChannel } from 'node:diagnostics_channel';
|
| 2 |
+
export type { TracingChannel, Channel };
|
| 3 |
+
export declare const metrics: Channel<unknown>;
|
| 4 |
+
export declare const tracing: TracingChannel<unknown>;
|
| 5 |
+
//# sourceMappingURL=diagnostics-channel-cjs.d.cts.map
|
node_modules/lru-cache/dist/commonjs/diagnostics-channel.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.tracing = exports.metrics = void 0;
|
| 4 |
+
const dummy = { hasSubscribers: false };
|
| 5 |
+
exports.metrics = dummy;
|
| 6 |
+
exports.tracing = dummy;
|
| 7 |
+
//# sourceMappingURL=diagnostics-channel-cjs.cjs.map
|
node_modules/lru-cache/dist/commonjs/index.d.ts
ADDED
|
@@ -0,0 +1,1400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
* @module LRUCache
|
| 3 |
+
*/
|
| 4 |
+
import type { Perf } from './perf.js';
|
| 5 |
+
export type { Perf } from './perf.js';
|
| 6 |
+
declare const TYPE: unique symbol;
|
| 7 |
+
export type PosInt = number & {
|
| 8 |
+
[TYPE]: 'Positive Integer';
|
| 9 |
+
};
|
| 10 |
+
export type Index = number & {
|
| 11 |
+
[TYPE]: 'LRUCache Index';
|
| 12 |
+
};
|
| 13 |
+
export type UintArray = Uint8Array | Uint16Array | Uint32Array;
|
| 14 |
+
export type NumberArray = UintArray | number[];
|
| 15 |
+
declare class ZeroArray extends Array<number> {
|
| 16 |
+
constructor(size: number);
|
| 17 |
+
}
|
| 18 |
+
export type { ZeroArray };
|
| 19 |
+
export type { Stack };
|
| 20 |
+
export type StackLike = Stack | Index[];
|
| 21 |
+
declare class Stack {
|
| 22 |
+
#private;
|
| 23 |
+
heap: NumberArray;
|
| 24 |
+
length: number;
|
| 25 |
+
static create(max: number): StackLike;
|
| 26 |
+
constructor(max: number, HeapCls: {
|
| 27 |
+
new (n: number): NumberArray;
|
| 28 |
+
});
|
| 29 |
+
push(n: Index): void;
|
| 30 |
+
pop(): Index;
|
| 31 |
+
}
|
| 32 |
+
/**
|
| 33 |
+
* Promise representing an in-progress {@link LRUCache#fetch} call
|
| 34 |
+
*/
|
| 35 |
+
export type BackgroundFetch<V> = Promise<V | undefined> & {
|
| 36 |
+
__returned: BackgroundFetch<V> | undefined;
|
| 37 |
+
__abortController: AbortController;
|
| 38 |
+
__staleWhileFetching: V | undefined;
|
| 39 |
+
};
|
| 40 |
+
export type DisposeTask<K, V> = [
|
| 41 |
+
value: V,
|
| 42 |
+
key: K,
|
| 43 |
+
reason: LRUCache.DisposeReason
|
| 44 |
+
];
|
| 45 |
+
export declare namespace LRUCache {
|
| 46 |
+
/**
|
| 47 |
+
* An integer greater than 0, reflecting the calculated size of items
|
| 48 |
+
*/
|
| 49 |
+
type Size = number;
|
| 50 |
+
/**
|
| 51 |
+
* Integer greater than 0, representing some number of milliseconds, or the
|
| 52 |
+
* time at which a TTL started counting from.
|
| 53 |
+
*/
|
| 54 |
+
type Milliseconds = number;
|
| 55 |
+
/**
|
| 56 |
+
* An integer greater than 0, reflecting a number of items
|
| 57 |
+
*/
|
| 58 |
+
type Count = number;
|
| 59 |
+
/**
|
| 60 |
+
* The reason why an item was removed from the cache, passed
|
| 61 |
+
* to the {@link Disposer} methods.
|
| 62 |
+
*
|
| 63 |
+
* - `evict`: The item was evicted because it is the least recently used,
|
| 64 |
+
* and the cache is full.
|
| 65 |
+
* - `set`: A new value was set, overwriting the old value being disposed.
|
| 66 |
+
* - `delete`: The item was explicitly deleted, either by calling
|
| 67 |
+
* {@link LRUCache#delete}, {@link LRUCache#clear}, or
|
| 68 |
+
* {@link LRUCache#set} with an undefined value.
|
| 69 |
+
* - `expire`: The item was removed due to exceeding its TTL.
|
| 70 |
+
* - `fetch`: A {@link OptionsBase#fetchMethod} operation returned
|
| 71 |
+
* `undefined` or was aborted, causing the item to be deleted.
|
| 72 |
+
*/
|
| 73 |
+
type DisposeReason = 'evict' | 'set' | 'delete' | 'expire' | 'fetch';
|
| 74 |
+
/**
|
| 75 |
+
* A method called upon item removal, passed as the
|
| 76 |
+
* {@link OptionsBase.dispose} and/or
|
| 77 |
+
* {@link OptionsBase.disposeAfter} options.
|
| 78 |
+
*/
|
| 79 |
+
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
|
| 80 |
+
/**
|
| 81 |
+
* The reason why an item was added to the cache, passed
|
| 82 |
+
* to the {@link Inserter} methods.
|
| 83 |
+
*
|
| 84 |
+
* - `add`: the item was not found in the cache, and was added
|
| 85 |
+
* - `update`: the item was in the cache, with the same value provided
|
| 86 |
+
* - `replace`: the item was in the cache, and replaced
|
| 87 |
+
*/
|
| 88 |
+
type InsertReason = 'add' | 'update' | 'replace';
|
| 89 |
+
/**
|
| 90 |
+
* A method called upon item insertion, passed as the
|
| 91 |
+
* {@link OptionsBase.insert}
|
| 92 |
+
*/
|
| 93 |
+
type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
|
| 94 |
+
/**
|
| 95 |
+
* A function that returns the effective calculated size
|
| 96 |
+
* of an entry in the cache.
|
| 97 |
+
*/
|
| 98 |
+
type SizeCalculator<K, V> = (value: V, key: K) => Size;
|
| 99 |
+
/**
|
| 100 |
+
* Options provided to the
|
| 101 |
+
* {@link OptionsBase.fetchMethod} function.
|
| 102 |
+
*/
|
| 103 |
+
interface FetcherOptions<K, V, FC = unknown> {
|
| 104 |
+
signal: AbortSignal;
|
| 105 |
+
options: FetcherFetchOptions<K, V, FC>;
|
| 106 |
+
/**
|
| 107 |
+
* Object provided in the {@link FetchOptions.context} option to
|
| 108 |
+
* {@link LRUCache#fetch}
|
| 109 |
+
*/
|
| 110 |
+
context: FC;
|
| 111 |
+
}
|
| 112 |
+
/**
|
| 113 |
+
* Occasionally, it may be useful to track the internal behavior of the
|
| 114 |
+
* cache, particularly for logging, debugging, or for behavior within the
|
| 115 |
+
* `fetchMethod`. To do this, you can pass a `status` object to the
|
| 116 |
+
* {@link LRUCache#fetch}, {@link LRUCache#get}, {@link LRUCache#set},
|
| 117 |
+
* {@link LRUCache#memo}, and {@link LRUCache#has} methods.
|
| 118 |
+
*
|
| 119 |
+
* The `status` option should be a plain JavaScript object. The following
|
| 120 |
+
* fields will be set on it appropriately, depending on the situation.
|
| 121 |
+
*
|
| 122 |
+
* These objects are also the context objects passed to listeners on the
|
| 123 |
+
* `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
|
| 124 |
+
* channels, in platforms that support them.
|
| 125 |
+
*/
|
| 126 |
+
interface Status<K, V, FC = unknown> {
|
| 127 |
+
/**
|
| 128 |
+
* The operation being performed
|
| 129 |
+
*/
|
| 130 |
+
op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek';
|
| 131 |
+
/**
|
| 132 |
+
* The status of a set() operation.
|
| 133 |
+
*
|
| 134 |
+
* - add: the item was not found in the cache, and was added
|
| 135 |
+
* - update: the item was in the cache, with the same value provided
|
| 136 |
+
* - replace: the item was in the cache, and replaced
|
| 137 |
+
* - miss: the item was not added to the cache for some reason
|
| 138 |
+
*/
|
| 139 |
+
set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted';
|
| 140 |
+
/**
|
| 141 |
+
* The status of a delete() operation.
|
| 142 |
+
*/
|
| 143 |
+
delete?: LRUCache.DisposeReason;
|
| 144 |
+
/**
|
| 145 |
+
* The result of a peek() operation
|
| 146 |
+
*
|
| 147 |
+
* - hit: the item was found and returned
|
| 148 |
+
* - stale: the item is in the cache, but past its ttl and not returned
|
| 149 |
+
* - miss: item not in the cache
|
| 150 |
+
*/
|
| 151 |
+
peek?: 'hit' | 'miss' | 'stale';
|
| 152 |
+
/**
|
| 153 |
+
* The status of a memo() operation.
|
| 154 |
+
*
|
| 155 |
+
* - 'hit': the item was found in the cache and returned
|
| 156 |
+
* - 'miss': the `memoMethod` function was called
|
| 157 |
+
*/
|
| 158 |
+
memo?: 'hit' | 'miss';
|
| 159 |
+
/**
|
| 160 |
+
* The `context` option provided to a memo or fetch operation
|
| 161 |
+
*
|
| 162 |
+
* In practice, of course, this will be the same type as the `FC`
|
| 163 |
+
* fetch context param used to instantiate the LRUCache, but the
|
| 164 |
+
* convolutions of threading that through would get quite complicated,
|
| 165 |
+
* and preclude forcing/forbidding the passing of a `context` param
|
| 166 |
+
* where it is/isn't expected, which is more valuable for error
|
| 167 |
+
* prevention.
|
| 168 |
+
*/
|
| 169 |
+
context?: unknown;
|
| 170 |
+
/**
|
| 171 |
+
* the ttl stored for the item, or undefined if ttls are not used.
|
| 172 |
+
*/
|
| 173 |
+
ttl?: Milliseconds;
|
| 174 |
+
/**
|
| 175 |
+
* the start time for the item, or undefined if ttls are not used.
|
| 176 |
+
*/
|
| 177 |
+
start?: Milliseconds;
|
| 178 |
+
/**
|
| 179 |
+
* The timestamp used for TTL calculation
|
| 180 |
+
*/
|
| 181 |
+
now?: Milliseconds;
|
| 182 |
+
/**
|
| 183 |
+
* the remaining ttl for the item, or undefined if ttls are not used.
|
| 184 |
+
*/
|
| 185 |
+
remainingTTL?: Milliseconds;
|
| 186 |
+
/**
|
| 187 |
+
* The calculated size for the item, if sizes are used.
|
| 188 |
+
*/
|
| 189 |
+
entrySize?: Size;
|
| 190 |
+
/**
|
| 191 |
+
* The total calculated size of the cache, if sizes are used.
|
| 192 |
+
*/
|
| 193 |
+
totalCalculatedSize?: Size;
|
| 194 |
+
/**
|
| 195 |
+
* A flag indicating that the item was not stored, due to exceeding the
|
| 196 |
+
* {@link OptionsBase.maxEntrySize}
|
| 197 |
+
*/
|
| 198 |
+
maxEntrySizeExceeded?: true;
|
| 199 |
+
/**
|
| 200 |
+
* The key that was set or retrieved
|
| 201 |
+
*/
|
| 202 |
+
key?: K;
|
| 203 |
+
/**
|
| 204 |
+
* The value that was set
|
| 205 |
+
*/
|
| 206 |
+
value?: V;
|
| 207 |
+
/**
|
| 208 |
+
* The old value, specified in the case of `set:'replace'`
|
| 209 |
+
*/
|
| 210 |
+
oldValue?: V;
|
| 211 |
+
/**
|
| 212 |
+
* The results of a {@link LRUCache#has} operation
|
| 213 |
+
*
|
| 214 |
+
* - hit: the item was found in the cache
|
| 215 |
+
* - stale: the item was found in the cache, but is stale
|
| 216 |
+
* - miss: the item was not found in the cache
|
| 217 |
+
*/
|
| 218 |
+
has?: 'hit' | 'stale' | 'miss';
|
| 219 |
+
/**
|
| 220 |
+
* The status of a {@link LRUCache#fetch} operation.
|
| 221 |
+
* Note that this can change as the underlying fetch() moves through
|
| 222 |
+
* various states.
|
| 223 |
+
*
|
| 224 |
+
* - inflight: there is another fetch() for this key which is in process
|
| 225 |
+
* - get: there is no {@link OptionsBase.fetchMethod}, so
|
| 226 |
+
* {@link LRUCache#get} was called.
|
| 227 |
+
* - miss: the item is not in cache, and will be fetched.
|
| 228 |
+
* - hit: the item is in the cache, and was resolved immediately.
|
| 229 |
+
* - stale: the item is in the cache, but stale.
|
| 230 |
+
* - refresh: the item is in the cache, and not stale, but
|
| 231 |
+
* {@link FetchOptions.forceRefresh} was specified.
|
| 232 |
+
*/
|
| 233 |
+
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh';
|
| 234 |
+
/**
|
| 235 |
+
* `forceRefresh` option was used for either a fetch or memo operation
|
| 236 |
+
*/
|
| 237 |
+
forceRefresh?: boolean;
|
| 238 |
+
/**
|
| 239 |
+
* The {@link OptionsBase.fetchMethod} was called
|
| 240 |
+
*/
|
| 241 |
+
fetchDispatched?: true;
|
| 242 |
+
/**
|
| 243 |
+
* The cached value was updated after a successful call to
|
| 244 |
+
* {@link OptionsBase.fetchMethod}
|
| 245 |
+
*/
|
| 246 |
+
fetchUpdated?: true;
|
| 247 |
+
/**
|
| 248 |
+
* The reason for a fetch() rejection. Either the error raised by the
|
| 249 |
+
* {@link OptionsBase.fetchMethod}, or the reason for an
|
| 250 |
+
* AbortSignal.
|
| 251 |
+
*/
|
| 252 |
+
fetchError?: Error;
|
| 253 |
+
/**
|
| 254 |
+
* The fetch received an abort signal
|
| 255 |
+
*/
|
| 256 |
+
fetchAborted?: true;
|
| 257 |
+
/**
|
| 258 |
+
* The abort signal received was ignored, and the fetch was allowed to
|
| 259 |
+
* continue in the background.
|
| 260 |
+
*/
|
| 261 |
+
fetchAbortIgnored?: true;
|
| 262 |
+
/**
|
| 263 |
+
* The fetchMethod promise resolved successfully
|
| 264 |
+
*/
|
| 265 |
+
fetchResolved?: true;
|
| 266 |
+
/**
|
| 267 |
+
* The fetchMethod promise was rejected
|
| 268 |
+
*/
|
| 269 |
+
fetchRejected?: true;
|
| 270 |
+
/**
|
| 271 |
+
* The status of a {@link LRUCache#get} operation.
|
| 272 |
+
*
|
| 273 |
+
* - fetching: The item is currently being fetched. If a previous value
|
| 274 |
+
* is present and allowed, that will be returned.
|
| 275 |
+
* - stale: The item is in the cache, and is stale. If it was returned,
|
| 276 |
+
* then the `returnedStale` flag will be set.
|
| 277 |
+
* - stale-fetching: The value is being fetched in the background, but is
|
| 278 |
+
* currently stale. If the stale value was returned, then the
|
| 279 |
+
* `returnedStale` flag will be set.
|
| 280 |
+
* - hit: the item is in the cache
|
| 281 |
+
* - miss: the item is not in the cache
|
| 282 |
+
*/
|
| 283 |
+
get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching';
|
| 284 |
+
/**
|
| 285 |
+
* A fetch or get operation returned a stale value.
|
| 286 |
+
*/
|
| 287 |
+
returnedStale?: true;
|
| 288 |
+
/**
|
| 289 |
+
* A tracingChannel trace was started for this operation
|
| 290 |
+
*/
|
| 291 |
+
trace?: boolean;
|
| 292 |
+
/**
|
| 293 |
+
* A reference to the cache instance associated with this operation
|
| 294 |
+
*/
|
| 295 |
+
cache?: LRUCache<K & {}, V & {}, FC>;
|
| 296 |
+
}
|
| 297 |
+
/**
|
| 298 |
+
* options which override the options set in the LRUCache constructor
|
| 299 |
+
* when calling {@link LRUCache#fetch}.
|
| 300 |
+
*
|
| 301 |
+
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
| 302 |
+
* {@link OptionsBase.noDeleteOnFetchRejection},
|
| 303 |
+
* {@link OptionsBase.allowStaleOnFetchRejection},
|
| 304 |
+
* {@link FetchOptions.forceRefresh}, and
|
| 305 |
+
* {@link FetcherOptions.context}
|
| 306 |
+
*
|
| 307 |
+
* Any of these may be modified in the {@link OptionsBase.fetchMethod}
|
| 308 |
+
* function, but the {@link GetOptions} fields will of course have no
|
| 309 |
+
* effect, as the {@link LRUCache#get} call already happened by the time
|
| 310 |
+
* the fetchMethod is called.
|
| 311 |
+
*/
|
| 312 |
+
interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
| 313 |
+
status?: Status<K, V, FC>;
|
| 314 |
+
size?: Size;
|
| 315 |
+
}
|
| 316 |
+
/**
|
| 317 |
+
* Options that may be passed to the {@link LRUCache#fetch} method.
|
| 318 |
+
*/
|
| 319 |
+
interface FetchOptions<K, V, FC> extends FetcherFetchOptions<K, V, FC> {
|
| 320 |
+
/**
|
| 321 |
+
* Set to true to force a re-load of the existing data, even if it
|
| 322 |
+
* is not yet stale.
|
| 323 |
+
*/
|
| 324 |
+
forceRefresh?: boolean;
|
| 325 |
+
/**
|
| 326 |
+
* Context provided to the {@link OptionsBase.fetchMethod} as
|
| 327 |
+
* the {@link FetcherOptions.context} param.
|
| 328 |
+
*
|
| 329 |
+
* If the FC type is specified as unknown (the default),
|
| 330 |
+
* undefined or void, then this is optional. Otherwise, it will
|
| 331 |
+
* be required.
|
| 332 |
+
*/
|
| 333 |
+
context?: FC;
|
| 334 |
+
signal?: AbortSignal;
|
| 335 |
+
status?: Status<K, V, FC>;
|
| 336 |
+
}
|
| 337 |
+
/**
|
| 338 |
+
* Options provided to {@link LRUCache#fetch} when the FC type is something
|
| 339 |
+
* other than `unknown`, `undefined`, or `void`
|
| 340 |
+
*/
|
| 341 |
+
interface FetchOptionsWithContext<K, V, FC> extends FetchOptions<K, V, FC> {
|
| 342 |
+
context: FC;
|
| 343 |
+
}
|
| 344 |
+
/**
|
| 345 |
+
* Options provided to {@link LRUCache#fetch} when the FC type is
|
| 346 |
+
* `undefined` or `void`
|
| 347 |
+
*/
|
| 348 |
+
interface FetchOptionsNoContext<K, V, FC extends undefined | void = undefined> extends FetchOptions<K, V, FC> {
|
| 349 |
+
context?: FC;
|
| 350 |
+
}
|
| 351 |
+
interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
| 352 |
+
/**
|
| 353 |
+
* Set to true to force a re-load of the existing data, even if it
|
| 354 |
+
* is not yet stale.
|
| 355 |
+
*/
|
| 356 |
+
forceRefresh?: boolean;
|
| 357 |
+
/**
|
| 358 |
+
* Context provided to the {@link OptionsBase.memoMethod} as
|
| 359 |
+
* the {@link MemoizerOptions.context} param.
|
| 360 |
+
*
|
| 361 |
+
* If the FC type is specified as unknown (the default),
|
| 362 |
+
* undefined or void, then this is optional. Otherwise, it will
|
| 363 |
+
* be required.
|
| 364 |
+
*/
|
| 365 |
+
context?: FC;
|
| 366 |
+
status?: Status<K, V, FC>;
|
| 367 |
+
}
|
| 368 |
+
/**
|
| 369 |
+
* Options provided to {@link LRUCache#memo} when the FC type is something
|
| 370 |
+
* other than `unknown`, `undefined`, or `void`
|
| 371 |
+
*/
|
| 372 |
+
interface MemoOptionsWithContext<K, V, FC> extends MemoOptions<K, V, FC> {
|
| 373 |
+
context: FC;
|
| 374 |
+
}
|
| 375 |
+
/**
|
| 376 |
+
* Options provided to {@link LRUCache#memo} when the FC type is
|
| 377 |
+
* `undefined` or `void`
|
| 378 |
+
*/
|
| 379 |
+
interface MemoOptionsNoContext<K, V, FC extends undefined | void = undefined> extends MemoOptions<K, V, FC> {
|
| 380 |
+
context?: FC;
|
| 381 |
+
}
|
| 382 |
+
/**
|
| 383 |
+
* Options provided to the
|
| 384 |
+
* {@link OptionsBase.memoMethod} function.
|
| 385 |
+
*/
|
| 386 |
+
interface MemoizerOptions<K, V, FC = unknown> {
|
| 387 |
+
options: MemoizerMemoOptions<K, V, FC>;
|
| 388 |
+
/**
|
| 389 |
+
* Object provided in the {@link MemoOptions.context} option to
|
| 390 |
+
* {@link LRUCache#memo}
|
| 391 |
+
*/
|
| 392 |
+
context: FC;
|
| 393 |
+
}
|
| 394 |
+
/**
|
| 395 |
+
* options which override the options set in the LRUCache constructor
|
| 396 |
+
* when calling {@link LRUCache#memo}.
|
| 397 |
+
*
|
| 398 |
+
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
| 399 |
+
* {@link MemoOptions.forceRefresh}, and
|
| 400 |
+
* {@link MemoOptions.context}
|
| 401 |
+
*
|
| 402 |
+
* Any of these may be modified in the {@link OptionsBase.memoMethod}
|
| 403 |
+
* function, but the {@link GetOptions} fields will of course have no
|
| 404 |
+
* effect, as the {@link LRUCache#get} call already happened by the time
|
| 405 |
+
* the memoMethod is called.
|
| 406 |
+
*/
|
| 407 |
+
interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
| 408 |
+
status?: Status<K, V, FC>;
|
| 409 |
+
size?: Size;
|
| 410 |
+
start?: Milliseconds;
|
| 411 |
+
}
|
| 412 |
+
/**
|
| 413 |
+
* Options that may be passed to the {@link LRUCache#has} method.
|
| 414 |
+
*/
|
| 415 |
+
interface HasOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'updateAgeOnHas'> {
|
| 416 |
+
status?: Status<K, V, FC>;
|
| 417 |
+
}
|
| 418 |
+
/**
|
| 419 |
+
* Options that may be passed to the {@link LRUCache#get} method.
|
| 420 |
+
*/
|
| 421 |
+
interface GetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'> {
|
| 422 |
+
status?: Status<K, V, FC>;
|
| 423 |
+
}
|
| 424 |
+
/**
|
| 425 |
+
* Options that may be passed to the {@link LRUCache#peek} method.
|
| 426 |
+
*/
|
| 427 |
+
interface PeekOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale'> {
|
| 428 |
+
status?: Status<K, V, FC>;
|
| 429 |
+
}
|
| 430 |
+
/**
|
| 431 |
+
* Options that may be passed to the {@link LRUCache#set} method.
|
| 432 |
+
*/
|
| 433 |
+
interface SetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
| 434 |
+
/**
|
| 435 |
+
* If size tracking is enabled, then setting an explicit size
|
| 436 |
+
* in the {@link LRUCache#set} call will prevent calling the
|
| 437 |
+
* {@link OptionsBase.sizeCalculation} function.
|
| 438 |
+
*/
|
| 439 |
+
size?: Size;
|
| 440 |
+
/**
|
| 441 |
+
* If TTL tracking is enabled, then setting an explicit start
|
| 442 |
+
* time in the {@link LRUCache#set} call will override the
|
| 443 |
+
* default time from `performance.now()` or `Date.now()`.
|
| 444 |
+
*
|
| 445 |
+
* Note that it must be a valid value for whichever time-tracking
|
| 446 |
+
* method is in use.
|
| 447 |
+
*/
|
| 448 |
+
start?: Milliseconds;
|
| 449 |
+
status?: Status<K, V, FC>;
|
| 450 |
+
}
|
| 451 |
+
/**
|
| 452 |
+
* The type signature for the {@link OptionsBase.fetchMethod} option.
|
| 453 |
+
*/
|
| 454 |
+
type Fetcher<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: FetcherOptions<K, V, FC>) => Promise<V | undefined | void> | V | undefined | void;
|
| 455 |
+
/**
|
| 456 |
+
* the type signature for the {@link OptionsBase.memoMethod} option.
|
| 457 |
+
*/
|
| 458 |
+
type Memoizer<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: MemoizerOptions<K, V, FC>) => V;
|
| 459 |
+
/**
|
| 460 |
+
* Options which may be passed to the {@link LRUCache} constructor.
|
| 461 |
+
*
|
| 462 |
+
* Most of these may be overridden in the various options that use
|
| 463 |
+
* them.
|
| 464 |
+
*
|
| 465 |
+
* Despite all being technically optional, the constructor requires that
|
| 466 |
+
* a cache is at minimum limited by one or more of {@link OptionsBase.max},
|
| 467 |
+
* {@link OptionsBase.ttl}, or {@link OptionsBase.maxSize}.
|
| 468 |
+
*
|
| 469 |
+
* If {@link OptionsBase.ttl} is used alone, then it is strongly advised
|
| 470 |
+
* (and in fact required by the type definitions here) that the cache
|
| 471 |
+
* also set {@link OptionsBase.ttlAutopurge}, to prevent potentially
|
| 472 |
+
* unbounded storage.
|
| 473 |
+
*
|
| 474 |
+
* All options are also available on the {@link LRUCache} instance, making
|
| 475 |
+
* it safe to pass an LRUCache instance as the options argumemnt to
|
| 476 |
+
* make another empty cache of the same type.
|
| 477 |
+
*
|
| 478 |
+
* Some options are marked as read-only, because changing them after
|
| 479 |
+
* instantiation is not safe. Changing any of the other options will of
|
| 480 |
+
* course only have an effect on subsequent method calls.
|
| 481 |
+
*/
|
| 482 |
+
interface OptionsBase<K, V, FC> {
|
| 483 |
+
/**
|
| 484 |
+
* The maximum number of items to store in the cache before evicting
|
| 485 |
+
* old entries. This is read-only on the {@link LRUCache} instance,
|
| 486 |
+
* and may not be overridden.
|
| 487 |
+
*
|
| 488 |
+
* If set, then storage space will be pre-allocated at construction
|
| 489 |
+
* time, and the cache will perform significantly faster.
|
| 490 |
+
*
|
| 491 |
+
* Note that significantly fewer items may be stored, if
|
| 492 |
+
* {@link OptionsBase.maxSize} and/or {@link OptionsBase.ttl} are also
|
| 493 |
+
* set.
|
| 494 |
+
*
|
| 495 |
+
* **It is strongly recommended to set a `max` to prevent unbounded growth
|
| 496 |
+
* of the cache.**
|
| 497 |
+
*/
|
| 498 |
+
max?: Count;
|
| 499 |
+
/**
|
| 500 |
+
* Max time in milliseconds for items to live in cache before they are
|
| 501 |
+
* considered stale. Note that stale items are NOT preemptively removed by
|
| 502 |
+
* default, and MAY live in the cache, contributing to its LRU max, long
|
| 503 |
+
* after they have expired, unless {@link OptionsBase.ttlAutopurge} is
|
| 504 |
+
* set.
|
| 505 |
+
*
|
| 506 |
+
* If set to `0` (the default value), then that means "do not track
|
| 507 |
+
* TTL", not "expire immediately".
|
| 508 |
+
*
|
| 509 |
+
* Also, as this cache is optimized for LRU/MRU operations, some of
|
| 510 |
+
* the staleness/TTL checks will reduce performance, as they will incur
|
| 511 |
+
* overhead by deleting items.
|
| 512 |
+
*
|
| 513 |
+
* This is not primarily a TTL cache, and does not make strong TTL
|
| 514 |
+
* guarantees. There is no pre-emptive pruning of expired items, but you
|
| 515 |
+
* _may_ set a TTL on the cache, and it will treat expired items as missing
|
| 516 |
+
* when they are fetched, and delete them.
|
| 517 |
+
*
|
| 518 |
+
* Optional, but must be a non-negative integer in ms if specified.
|
| 519 |
+
*
|
| 520 |
+
* This may be overridden by passing an options object to `cache.set()`.
|
| 521 |
+
*
|
| 522 |
+
* At least one of `max`, `maxSize`, or `TTL` is required. This must be a
|
| 523 |
+
* positive integer if set.
|
| 524 |
+
*
|
| 525 |
+
* Even if ttl tracking is enabled, **it is strongly recommended to set a
|
| 526 |
+
* `max` to prevent unbounded growth of the cache.**
|
| 527 |
+
*
|
| 528 |
+
* If ttl tracking is enabled, and `max` and `maxSize` are not set,
|
| 529 |
+
* and `ttlAutopurge` is not set, then a warning will be emitted
|
| 530 |
+
* cautioning about the potential for unbounded memory consumption.
|
| 531 |
+
* (The TypeScript definitions will also discourage this.)
|
| 532 |
+
*/
|
| 533 |
+
ttl?: Milliseconds;
|
| 534 |
+
/**
|
| 535 |
+
* Minimum amount of time in ms in which to check for staleness.
|
| 536 |
+
* Defaults to 1, which means that the current time is checked
|
| 537 |
+
* at most once per millisecond.
|
| 538 |
+
*
|
| 539 |
+
* Set to 0 to check the current time every time staleness is tested.
|
| 540 |
+
* (This reduces performance, and is theoretically unnecessary.)
|
| 541 |
+
*
|
| 542 |
+
* Setting this to a higher value will improve performance somewhat
|
| 543 |
+
* while using ttl tracking, albeit at the expense of keeping stale
|
| 544 |
+
* items around a bit longer than their TTLs would indicate.
|
| 545 |
+
*
|
| 546 |
+
* @default 1
|
| 547 |
+
*/
|
| 548 |
+
ttlResolution?: Milliseconds;
|
| 549 |
+
/**
|
| 550 |
+
* Preemptively remove stale items from the cache.
|
| 551 |
+
*
|
| 552 |
+
* Note that this may *significantly* degrade performance, especially if
|
| 553 |
+
* the cache is storing a large number of items. It is almost always best
|
| 554 |
+
* to just leave the stale items in the cache, and let them fall out as new
|
| 555 |
+
* items are added.
|
| 556 |
+
*
|
| 557 |
+
* Note that this means that {@link OptionsBase.allowStale} is a bit
|
| 558 |
+
* pointless, as stale items will be deleted almost as soon as they
|
| 559 |
+
* expire.
|
| 560 |
+
*
|
| 561 |
+
* Use with caution!
|
| 562 |
+
*/
|
| 563 |
+
ttlAutopurge?: boolean;
|
| 564 |
+
/**
|
| 565 |
+
* When using time-expiring entries with `ttl`, setting this to `true` will
|
| 566 |
+
* make each item's age reset to 0 whenever it is retrieved from cache with
|
| 567 |
+
* {@link LRUCache#get}, causing it to not expire. (It can still fall out
|
| 568 |
+
* of cache based on recency of use, of course.)
|
| 569 |
+
*
|
| 570 |
+
* Has no effect if {@link OptionsBase.ttl} is not set.
|
| 571 |
+
*
|
| 572 |
+
* This may be overridden by passing an options object to `cache.get()`.
|
| 573 |
+
*/
|
| 574 |
+
updateAgeOnGet?: boolean;
|
| 575 |
+
/**
|
| 576 |
+
* When using time-expiring entries with `ttl`, setting this to `true` will
|
| 577 |
+
* make each item's age reset to 0 whenever its presence in the cache is
|
| 578 |
+
* checked with {@link LRUCache#has}, causing it to not expire. (It can
|
| 579 |
+
* still fall out of cache based on recency of use, of course.)
|
| 580 |
+
*
|
| 581 |
+
* Has no effect if {@link OptionsBase.ttl} is not set.
|
| 582 |
+
*/
|
| 583 |
+
updateAgeOnHas?: boolean;
|
| 584 |
+
/**
|
| 585 |
+
* Allow {@link LRUCache#get} and {@link LRUCache#fetch} calls to return
|
| 586 |
+
* stale data, if available.
|
| 587 |
+
*
|
| 588 |
+
* By default, if you set `ttl`, stale items will only be deleted from the
|
| 589 |
+
* cache when you `get(key)`. That is, it's not preemptively pruning items,
|
| 590 |
+
* unless {@link OptionsBase.ttlAutopurge} is set.
|
| 591 |
+
*
|
| 592 |
+
* If you set `allowStale:true`, it'll return the stale value *as well as*
|
| 593 |
+
* deleting it. If you don't set this, then it'll return `undefined` when
|
| 594 |
+
* you try to get a stale entry.
|
| 595 |
+
*
|
| 596 |
+
* Note that when a stale entry is fetched, _even if it is returned due to
|
| 597 |
+
* `allowStale` being set_, it is removed from the cache immediately. You
|
| 598 |
+
* can suppress this behavior by setting
|
| 599 |
+
* {@link OptionsBase.noDeleteOnStaleGet}, either in the constructor, or in
|
| 600 |
+
* the options provided to {@link LRUCache#get}.
|
| 601 |
+
*
|
| 602 |
+
* This may be overridden by passing an options object to `cache.get()`.
|
| 603 |
+
* The `cache.has()` method will always return `false` for stale items.
|
| 604 |
+
*
|
| 605 |
+
* Only relevant if a ttl is set.
|
| 606 |
+
*/
|
| 607 |
+
allowStale?: boolean;
|
| 608 |
+
/**
|
| 609 |
+
* Function that is called on items when they are dropped from the
|
| 610 |
+
* cache, as `dispose(value, key, reason)`.
|
| 611 |
+
*
|
| 612 |
+
* This can be handy if you want to close file descriptors or do
|
| 613 |
+
* other cleanup tasks when items are no longer stored in the cache.
|
| 614 |
+
*
|
| 615 |
+
* **NOTE**: It is called _before_ the item has been fully removed
|
| 616 |
+
* from the cache, so if you want to put it right back in, you need
|
| 617 |
+
* to wait until the next tick. If you try to add it back in during
|
| 618 |
+
* the `dispose()` function call, it will break things in subtle and
|
| 619 |
+
* weird ways.
|
| 620 |
+
*
|
| 621 |
+
* Unlike several other options, this may _not_ be overridden by
|
| 622 |
+
* passing an option to `set()`, for performance reasons.
|
| 623 |
+
*
|
| 624 |
+
* The `reason` will be one of the following strings, corresponding
|
| 625 |
+
* to the reason for the item's deletion:
|
| 626 |
+
*
|
| 627 |
+
* - `evict` Item was evicted to make space for a new addition
|
| 628 |
+
* - `set` Item was overwritten by a new value
|
| 629 |
+
* - `expire` Item expired its TTL
|
| 630 |
+
* - `fetch` Item was deleted due to a failed or aborted fetch, or a
|
| 631 |
+
* fetchMethod returning `undefined.
|
| 632 |
+
* - `delete` Item was removed by explicit `cache.delete(key)`,
|
| 633 |
+
* `cache.clear()`, or `cache.set(key, undefined)`.
|
| 634 |
+
*/
|
| 635 |
+
dispose?: Disposer<K, V>;
|
| 636 |
+
/**
|
| 637 |
+
* Function that is called when new items are inserted into the cache,
|
| 638 |
+
* as `onInsert(value, key, reason)`.
|
| 639 |
+
*
|
| 640 |
+
* This can be useful if you need to perform actions when an item is
|
| 641 |
+
* added, such as logging or tracking insertions.
|
| 642 |
+
*
|
| 643 |
+
* Unlike some other options, this may _not_ be overridden by passing
|
| 644 |
+
* an option to `set()`, for performance and consistency reasons.
|
| 645 |
+
*/
|
| 646 |
+
onInsert?: Inserter<K, V>;
|
| 647 |
+
/**
|
| 648 |
+
* The same as {@link OptionsBase.dispose}, but called *after* the entry
|
| 649 |
+
* is completely removed and the cache is once again in a clean state.
|
| 650 |
+
*
|
| 651 |
+
* It is safe to add an item right back into the cache at this point.
|
| 652 |
+
* However, note that it is *very* easy to inadvertently create infinite
|
| 653 |
+
* recursion this way.
|
| 654 |
+
*/
|
| 655 |
+
disposeAfter?: Disposer<K, V>;
|
| 656 |
+
/**
|
| 657 |
+
* Set to true to suppress calling the
|
| 658 |
+
* {@link OptionsBase.dispose} function if the entry key is
|
| 659 |
+
* still accessible within the cache.
|
| 660 |
+
*
|
| 661 |
+
* This may be overridden by passing an options object to
|
| 662 |
+
* {@link LRUCache#set}.
|
| 663 |
+
*
|
| 664 |
+
* Only relevant if `dispose` or `disposeAfter` are set.
|
| 665 |
+
*/
|
| 666 |
+
noDisposeOnSet?: boolean;
|
| 667 |
+
/**
|
| 668 |
+
* Boolean flag to tell the cache to not update the TTL when setting a new
|
| 669 |
+
* value for an existing key (ie, when updating a value rather than
|
| 670 |
+
* inserting a new value). Note that the TTL value is _always_ set (if
|
| 671 |
+
* provided) when adding a new entry into the cache.
|
| 672 |
+
*
|
| 673 |
+
* Has no effect if a {@link OptionsBase.ttl} is not set.
|
| 674 |
+
*
|
| 675 |
+
* May be passed as an option to {@link LRUCache#set}.
|
| 676 |
+
*/
|
| 677 |
+
noUpdateTTL?: boolean;
|
| 678 |
+
/**
|
| 679 |
+
* Set to a positive integer to track the sizes of items added to the
|
| 680 |
+
* cache, and automatically evict items in order to stay below this size.
|
| 681 |
+
* Note that this may result in fewer than `max` items being stored.
|
| 682 |
+
*
|
| 683 |
+
* Attempting to add an item to the cache whose calculated size is greater
|
| 684 |
+
* that this amount will be a no-op. The item will not be cached, and no
|
| 685 |
+
* other items will be evicted.
|
| 686 |
+
*
|
| 687 |
+
* Optional, must be a positive integer if provided.
|
| 688 |
+
*
|
| 689 |
+
* Sets `maxEntrySize` to the same value, unless a different value is
|
| 690 |
+
* provided for `maxEntrySize`.
|
| 691 |
+
*
|
| 692 |
+
* At least one of `max`, `maxSize`, or `TTL` is required. This must be a
|
| 693 |
+
* positive integer if set.
|
| 694 |
+
*
|
| 695 |
+
* Even if size tracking is enabled, **it is strongly recommended to set a
|
| 696 |
+
* `max` to prevent unbounded growth of the cache.**
|
| 697 |
+
*
|
| 698 |
+
* Note also that size tracking can negatively impact performance,
|
| 699 |
+
* though for most cases, only minimally.
|
| 700 |
+
*/
|
| 701 |
+
maxSize?: Size;
|
| 702 |
+
/**
|
| 703 |
+
* The effective size for background fetch promises.
|
| 704 |
+
*
|
| 705 |
+
* This has no effect unless `maxSize` and `sizeCalculation` are used,
|
| 706 |
+
* and a {@link LRUCache.OptionsBase.fetchMethod} is provided to
|
| 707 |
+
* support {@link LRUCache#fetch}.
|
| 708 |
+
*
|
| 709 |
+
* If a stale value is present in the cache, then the effective size of
|
| 710 |
+
* the background fetch is the size of the stale item it will eventually
|
| 711 |
+
* replace. If not, then this value is used as its effective size.
|
| 712 |
+
*
|
| 713 |
+
* @default 1
|
| 714 |
+
*/
|
| 715 |
+
backgroundFetchSize?: number;
|
| 716 |
+
/**
|
| 717 |
+
* The maximum allowed size for any single item in the cache.
|
| 718 |
+
*
|
| 719 |
+
* If a larger item is passed to {@link LRUCache#set} or returned by a
|
| 720 |
+
* {@link OptionsBase.fetchMethod} or {@link OptionsBase.memoMethod}, then
|
| 721 |
+
* it will not be stored in the cache.
|
| 722 |
+
*
|
| 723 |
+
* Attempting to add an item whose calculated size is greater than
|
| 724 |
+
* this amount will not cache the item or evict any old items, but
|
| 725 |
+
* WILL delete an existing value if one is already present.
|
| 726 |
+
*
|
| 727 |
+
* Optional, must be a positive integer if provided. Defaults to
|
| 728 |
+
* the value of `maxSize` if provided.
|
| 729 |
+
*/
|
| 730 |
+
maxEntrySize?: Size;
|
| 731 |
+
/**
|
| 732 |
+
* A function that returns a number indicating the item's size.
|
| 733 |
+
*
|
| 734 |
+
* Requires {@link OptionsBase.maxSize} to be set.
|
| 735 |
+
*
|
| 736 |
+
* If not provided, and {@link OptionsBase.maxSize} or
|
| 737 |
+
* {@link OptionsBase.maxEntrySize} are set, then all
|
| 738 |
+
* {@link LRUCache#set} calls **must** provide an explicit
|
| 739 |
+
* {@link SetOptions.size} or sizeCalculation param.
|
| 740 |
+
*/
|
| 741 |
+
sizeCalculation?: SizeCalculator<K, V>;
|
| 742 |
+
/**
|
| 743 |
+
* Method that provides the implementation for {@link LRUCache#fetch}
|
| 744 |
+
*
|
| 745 |
+
* ```ts
|
| 746 |
+
* fetchMethod(key, staleValue, { signal, options, context })
|
| 747 |
+
* ```
|
| 748 |
+
*
|
| 749 |
+
* If `fetchMethod` is not provided, then `cache.fetch(key)` is equivalent
|
| 750 |
+
* to `Promise.resolve(cache.get(key))`.
|
| 751 |
+
*
|
| 752 |
+
* If at any time, `signal.aborted` is set to `true`, or if the
|
| 753 |
+
* `signal.onabort` method is called, or if it emits an `'abort'` event
|
| 754 |
+
* which you can listen to with `addEventListener`, then that means that
|
| 755 |
+
* the fetch should be abandoned. This may be passed along to async
|
| 756 |
+
* functions aware of AbortController/AbortSignal behavior.
|
| 757 |
+
*
|
| 758 |
+
* The `fetchMethod` should **only** return `undefined` or a Promise
|
| 759 |
+
* resolving to `undefined` if the AbortController signaled an `abort`
|
| 760 |
+
* event. In all other cases, it should return or resolve to a value
|
| 761 |
+
* suitable for adding to the cache.
|
| 762 |
+
*
|
| 763 |
+
* The `options` object is a union of the options that may be provided to
|
| 764 |
+
* `set()` and `get()`. If they are modified, then that will result in
|
| 765 |
+
* modifying the settings to `cache.set()` when the value is resolved, and
|
| 766 |
+
* in the case of
|
| 767 |
+
* {@link OptionsBase.noDeleteOnFetchRejection} and
|
| 768 |
+
* {@link OptionsBase.allowStaleOnFetchRejection}, the handling of
|
| 769 |
+
* `fetchMethod` failures.
|
| 770 |
+
*
|
| 771 |
+
* For example, a DNS cache may update the TTL based on the value returned
|
| 772 |
+
* from a remote DNS server by changing `options.ttl` in the `fetchMethod`.
|
| 773 |
+
*/
|
| 774 |
+
fetchMethod?: Fetcher<K, V, FC>;
|
| 775 |
+
/**
|
| 776 |
+
* Method that provides the implementation for {@link LRUCache#memo}
|
| 777 |
+
*/
|
| 778 |
+
memoMethod?: Memoizer<K, V, FC>;
|
| 779 |
+
/**
|
| 780 |
+
* Set to true to suppress the deletion of stale data when a
|
| 781 |
+
* {@link OptionsBase.fetchMethod} returns a rejected promise.
|
| 782 |
+
*/
|
| 783 |
+
noDeleteOnFetchRejection?: boolean;
|
| 784 |
+
/**
|
| 785 |
+
* Do not delete stale items when they are retrieved with
|
| 786 |
+
* {@link LRUCache#get}.
|
| 787 |
+
*
|
| 788 |
+
* Note that the `get` return value will still be `undefined`
|
| 789 |
+
* unless {@link OptionsBase.allowStale} is true.
|
| 790 |
+
*
|
| 791 |
+
* When using time-expiring entries with `ttl`, by default stale
|
| 792 |
+
* items will be removed from the cache when the key is accessed
|
| 793 |
+
* with `cache.get()`.
|
| 794 |
+
*
|
| 795 |
+
* Setting this option will cause stale items to remain in the cache, until
|
| 796 |
+
* they are explicitly deleted with `cache.delete(key)`, or retrieved with
|
| 797 |
+
* `noDeleteOnStaleGet` set to `false`.
|
| 798 |
+
*
|
| 799 |
+
* This may be overridden by passing an options object to `cache.get()`.
|
| 800 |
+
*
|
| 801 |
+
* Only relevant if a ttl is used.
|
| 802 |
+
*/
|
| 803 |
+
noDeleteOnStaleGet?: boolean;
|
| 804 |
+
/**
|
| 805 |
+
* Set to true to allow returning stale data when a
|
| 806 |
+
* {@link OptionsBase.fetchMethod} throws an error or returns a rejected
|
| 807 |
+
* promise.
|
| 808 |
+
*
|
| 809 |
+
* This differs from using {@link OptionsBase.allowStale} in that stale
|
| 810 |
+
* data will ONLY be returned in the case that the {@link LRUCache#fetch}
|
| 811 |
+
* fails, not any other times.
|
| 812 |
+
*
|
| 813 |
+
* If a `fetchMethod` fails, and there is no stale value available, the
|
| 814 |
+
* `fetch()` will resolve to `undefined`. Ie, all `fetchMethod` errors are
|
| 815 |
+
* suppressed.
|
| 816 |
+
*
|
| 817 |
+
* Implies `noDeleteOnFetchRejection`.
|
| 818 |
+
*
|
| 819 |
+
* This may be set in calls to `fetch()`, or defaulted on the constructor,
|
| 820 |
+
* or overridden by modifying the options object in the `fetchMethod`.
|
| 821 |
+
*/
|
| 822 |
+
allowStaleOnFetchRejection?: boolean;
|
| 823 |
+
/**
|
| 824 |
+
* Set to true to return a stale value from the cache when the
|
| 825 |
+
* `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches
|
| 826 |
+
* an `'abort'` event, whether user-triggered, or due to internal cache
|
| 827 |
+
* behavior.
|
| 828 |
+
*
|
| 829 |
+
* Unless {@link OptionsBase.ignoreFetchAbort} is also set, the underlying
|
| 830 |
+
* {@link OptionsBase.fetchMethod} will still be considered canceled, and
|
| 831 |
+
* any value it returns will be ignored and not cached.
|
| 832 |
+
*
|
| 833 |
+
* Caveat: since fetches are aborted when a new value is explicitly
|
| 834 |
+
* set in the cache, this can lead to fetch returning a stale value,
|
| 835 |
+
* since that was the fallback value _at the moment the `fetch()` was
|
| 836 |
+
* initiated_, even though the new updated value is now present in
|
| 837 |
+
* the cache.
|
| 838 |
+
*
|
| 839 |
+
* For example:
|
| 840 |
+
*
|
| 841 |
+
* ```ts
|
| 842 |
+
* const cache = new LRUCache<string, any>({
|
| 843 |
+
* ttl: 100,
|
| 844 |
+
* fetchMethod: async (url, oldValue, { signal }) => {
|
| 845 |
+
* const res = await fetch(url, { signal })
|
| 846 |
+
* return await res.json()
|
| 847 |
+
* }
|
| 848 |
+
* })
|
| 849 |
+
* cache.set('https://example.com/', { some: 'data' })
|
| 850 |
+
* // 100ms go by...
|
| 851 |
+
* const result = cache.fetch('https://example.com/')
|
| 852 |
+
* cache.set('https://example.com/', { other: 'thing' })
|
| 853 |
+
* console.log(await result) // { some: 'data' }
|
| 854 |
+
* console.log(cache.get('https://example.com/')) // { other: 'thing' }
|
| 855 |
+
* ```
|
| 856 |
+
*/
|
| 857 |
+
allowStaleOnFetchAbort?: boolean;
|
| 858 |
+
/**
|
| 859 |
+
* Set to true to ignore the `abort` event emitted by the `AbortSignal`
|
| 860 |
+
* object passed to {@link OptionsBase.fetchMethod}, and still cache the
|
| 861 |
+
* resulting resolution value, as long as it is not `undefined`.
|
| 862 |
+
*
|
| 863 |
+
* When used on its own, this means aborted {@link LRUCache#fetch} calls
|
| 864 |
+
* are not immediately resolved or rejected when they are aborted, and
|
| 865 |
+
* instead take the full time to await.
|
| 866 |
+
*
|
| 867 |
+
* When used with {@link OptionsBase.allowStaleOnFetchAbort}, aborted
|
| 868 |
+
* {@link LRUCache#fetch} calls will resolve immediately to their stale
|
| 869 |
+
* cached value or `undefined`, and will continue to process and eventually
|
| 870 |
+
* update the cache when they resolve, as long as the resulting value is
|
| 871 |
+
* not `undefined`, thus supporting a "return stale on timeout while
|
| 872 |
+
* refreshing" mechanism by passing `AbortSignal.timeout(n)` as the signal.
|
| 873 |
+
*
|
| 874 |
+
* For example:
|
| 875 |
+
*
|
| 876 |
+
* ```ts
|
| 877 |
+
* const c = new LRUCache({
|
| 878 |
+
* ttl: 100,
|
| 879 |
+
* ignoreFetchAbort: true,
|
| 880 |
+
* allowStaleOnFetchAbort: true,
|
| 881 |
+
* fetchMethod: async (key, oldValue, { signal }) => {
|
| 882 |
+
* // note: do NOT pass the signal to fetch()!
|
| 883 |
+
* // let's say this fetch can take a long time.
|
| 884 |
+
* const res = await fetch(`https://slow-backend-server/${key}`)
|
| 885 |
+
* return await res.json()
|
| 886 |
+
* },
|
| 887 |
+
* })
|
| 888 |
+
*
|
| 889 |
+
* // this will return the stale value after 100ms, while still
|
| 890 |
+
* // updating in the background for next time.
|
| 891 |
+
* const val = await c.fetch('key', { signal: AbortSignal.timeout(100) })
|
| 892 |
+
* ```
|
| 893 |
+
*
|
| 894 |
+
* **Note**: regardless of this setting, an `abort` event _is still
|
| 895 |
+
* emitted on the `AbortSignal` object_, so may result in invalid results
|
| 896 |
+
* when passed to other underlying APIs that use AbortSignals.
|
| 897 |
+
*
|
| 898 |
+
* This may be overridden in the {@link OptionsBase.fetchMethod} or the
|
| 899 |
+
* call to {@link LRUCache#fetch}.
|
| 900 |
+
*/
|
| 901 |
+
ignoreFetchAbort?: boolean;
|
| 902 |
+
/**
|
| 903 |
+
* In some cases, you may want to swap out the performance/Date object
|
| 904 |
+
* used for TTL tracking. This should almost certainly NOT be done in
|
| 905 |
+
* production environments!
|
| 906 |
+
*
|
| 907 |
+
* This value defaults to `global.performance` if it has a `now()` method,
|
| 908 |
+
* or the `global.Date` object otherwise.
|
| 909 |
+
*/
|
| 910 |
+
perf?: Perf;
|
| 911 |
+
}
|
| 912 |
+
interface OptionsMaxLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
| 913 |
+
max: Count;
|
| 914 |
+
}
|
| 915 |
+
interface OptionsTTLLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
| 916 |
+
ttl: Milliseconds;
|
| 917 |
+
ttlAutopurge: boolean;
|
| 918 |
+
}
|
| 919 |
+
interface OptionsSizeLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
| 920 |
+
maxSize: Size;
|
| 921 |
+
}
|
| 922 |
+
/**
|
| 923 |
+
* The valid safe options for the {@link LRUCache} constructor
|
| 924 |
+
*/
|
| 925 |
+
type Options<K, V, FC> = OptionsMaxLimit<K, V, FC> | OptionsSizeLimit<K, V, FC> | OptionsTTLLimit<K, V, FC>;
|
| 926 |
+
/**
|
| 927 |
+
* Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump},
|
| 928 |
+
* and returned by {@link LRUCache#info}.
|
| 929 |
+
*/
|
| 930 |
+
interface Entry<V> {
|
| 931 |
+
value: V;
|
| 932 |
+
ttl?: Milliseconds;
|
| 933 |
+
size?: Size;
|
| 934 |
+
start?: Milliseconds;
|
| 935 |
+
}
|
| 936 |
+
}
|
| 937 |
+
/**
|
| 938 |
+
* Default export, the thing you're using this module to get.
|
| 939 |
+
*
|
| 940 |
+
* The `K` and `V` types define the key and value types, respectively. The
|
| 941 |
+
* optional `FC` type defines the type of the `context` object passed to
|
| 942 |
+
* `cache.fetch()` and `cache.memo()`.
|
| 943 |
+
*
|
| 944 |
+
* Keys and values **must not** be `null` or `undefined`.
|
| 945 |
+
*
|
| 946 |
+
* All properties from the options object (with the exception of `max`,
|
| 947 |
+
* `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
|
| 948 |
+
* added as normal public members. (The listed options are read-only getters.)
|
| 949 |
+
*
|
| 950 |
+
* Changing any of these will alter the defaults for subsequent method calls.
|
| 951 |
+
*/
|
| 952 |
+
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
| 953 |
+
#private;
|
| 954 |
+
/**
|
| 955 |
+
* {@link LRUCache.OptionsBase.perf}
|
| 956 |
+
*/
|
| 957 |
+
get perf(): Perf;
|
| 958 |
+
/**
|
| 959 |
+
* {@link LRUCache.OptionsBase.ttl}
|
| 960 |
+
*/
|
| 961 |
+
ttl: LRUCache.Milliseconds;
|
| 962 |
+
/**
|
| 963 |
+
* {@link LRUCache.OptionsBase.ttlResolution}
|
| 964 |
+
*/
|
| 965 |
+
ttlResolution: LRUCache.Milliseconds;
|
| 966 |
+
/**
|
| 967 |
+
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
| 968 |
+
*/
|
| 969 |
+
ttlAutopurge: boolean;
|
| 970 |
+
/**
|
| 971 |
+
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
| 972 |
+
*/
|
| 973 |
+
updateAgeOnGet: boolean;
|
| 974 |
+
/**
|
| 975 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
| 976 |
+
*/
|
| 977 |
+
updateAgeOnHas: boolean;
|
| 978 |
+
/**
|
| 979 |
+
* {@link LRUCache.OptionsBase.allowStale}
|
| 980 |
+
*/
|
| 981 |
+
allowStale: boolean;
|
| 982 |
+
/**
|
| 983 |
+
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
| 984 |
+
*/
|
| 985 |
+
noDisposeOnSet: boolean;
|
| 986 |
+
/**
|
| 987 |
+
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
| 988 |
+
*/
|
| 989 |
+
noUpdateTTL: boolean;
|
| 990 |
+
/**
|
| 991 |
+
* {@link LRUCache.OptionsBase.maxEntrySize}
|
| 992 |
+
*/
|
| 993 |
+
maxEntrySize: LRUCache.Size;
|
| 994 |
+
/**
|
| 995 |
+
* {@link LRUCache.OptionsBase.sizeCalculation}
|
| 996 |
+
*/
|
| 997 |
+
sizeCalculation?: LRUCache.SizeCalculator<K, V>;
|
| 998 |
+
/**
|
| 999 |
+
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
| 1000 |
+
*/
|
| 1001 |
+
noDeleteOnFetchRejection: boolean;
|
| 1002 |
+
/**
|
| 1003 |
+
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
| 1004 |
+
*/
|
| 1005 |
+
noDeleteOnStaleGet: boolean;
|
| 1006 |
+
/**
|
| 1007 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
| 1008 |
+
*/
|
| 1009 |
+
allowStaleOnFetchAbort: boolean;
|
| 1010 |
+
/**
|
| 1011 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
| 1012 |
+
*/
|
| 1013 |
+
allowStaleOnFetchRejection: boolean;
|
| 1014 |
+
/**
|
| 1015 |
+
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
| 1016 |
+
*/
|
| 1017 |
+
ignoreFetchAbort: boolean;
|
| 1018 |
+
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
| 1019 |
+
backgroundFetchSize: number;
|
| 1020 |
+
/**
|
| 1021 |
+
* Do not call this method unless you need to inspect the
|
| 1022 |
+
* inner workings of the cache. If anything returned by this
|
| 1023 |
+
* object is modified in any way, strange breakage may occur.
|
| 1024 |
+
*
|
| 1025 |
+
* These fields are private for a reason!
|
| 1026 |
+
*
|
| 1027 |
+
* @internal
|
| 1028 |
+
*/
|
| 1029 |
+
static unsafeExposeInternals<K extends {}, V extends {}, FC extends unknown = unknown>(c: LRUCache<K, V, FC>): {
|
| 1030 |
+
starts: ZeroArray | undefined;
|
| 1031 |
+
ttls: ZeroArray | undefined;
|
| 1032 |
+
autopurgeTimers: (NodeJS.Timeout | undefined)[] | undefined;
|
| 1033 |
+
sizes: ZeroArray | undefined;
|
| 1034 |
+
keyMap: Map<K, number>;
|
| 1035 |
+
keyList: (K | undefined)[];
|
| 1036 |
+
valList: (V | BackgroundFetch<V> | undefined)[];
|
| 1037 |
+
next: NumberArray;
|
| 1038 |
+
prev: NumberArray;
|
| 1039 |
+
readonly head: Index;
|
| 1040 |
+
readonly tail: Index;
|
| 1041 |
+
free: StackLike;
|
| 1042 |
+
isBackgroundFetch: (p: unknown) => p is BackgroundFetch<V>;
|
| 1043 |
+
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: unknown) => BackgroundFetch<V>;
|
| 1044 |
+
moveToTail: (index: number) => void;
|
| 1045 |
+
indexes: (options?: {
|
| 1046 |
+
allowStale: boolean;
|
| 1047 |
+
}) => Generator<Index, void, unknown>;
|
| 1048 |
+
rindexes: (options?: {
|
| 1049 |
+
allowStale: boolean;
|
| 1050 |
+
}) => Generator<Index, void, unknown>;
|
| 1051 |
+
isStale: (index: number | undefined) => boolean;
|
| 1052 |
+
};
|
| 1053 |
+
/**
|
| 1054 |
+
* {@link LRUCache.OptionsBase.max} (read-only)
|
| 1055 |
+
*/
|
| 1056 |
+
get max(): LRUCache.Count;
|
| 1057 |
+
/**
|
| 1058 |
+
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
| 1059 |
+
*/
|
| 1060 |
+
get maxSize(): LRUCache.Count;
|
| 1061 |
+
/**
|
| 1062 |
+
* The total computed size of items in the cache (read-only)
|
| 1063 |
+
*/
|
| 1064 |
+
get calculatedSize(): LRUCache.Size;
|
| 1065 |
+
/**
|
| 1066 |
+
* The number of items stored in the cache (read-only)
|
| 1067 |
+
*/
|
| 1068 |
+
get size(): LRUCache.Count;
|
| 1069 |
+
/**
|
| 1070 |
+
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
| 1071 |
+
*/
|
| 1072 |
+
get fetchMethod(): LRUCache.Fetcher<K, V, FC> | undefined;
|
| 1073 |
+
get memoMethod(): LRUCache.Memoizer<K, V, FC> | undefined;
|
| 1074 |
+
/**
|
| 1075 |
+
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
| 1076 |
+
*/
|
| 1077 |
+
get dispose(): LRUCache.Disposer<K, V> | undefined;
|
| 1078 |
+
/**
|
| 1079 |
+
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
| 1080 |
+
*/
|
| 1081 |
+
get onInsert(): LRUCache.Inserter<K, V> | undefined;
|
| 1082 |
+
/**
|
| 1083 |
+
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
| 1084 |
+
*/
|
| 1085 |
+
get disposeAfter(): LRUCache.Disposer<K, V> | undefined;
|
| 1086 |
+
constructor(options: LRUCache.Options<K, V, FC> | LRUCache<K, V, FC>);
|
| 1087 |
+
/**
|
| 1088 |
+
* Return the number of ms left in the item's TTL. If item is not in cache,
|
| 1089 |
+
* returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
|
| 1090 |
+
*/
|
| 1091 |
+
getRemainingTTL(key: K): number;
|
| 1092 |
+
/**
|
| 1093 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 1094 |
+
* in order from most recently used to least recently used.
|
| 1095 |
+
*/
|
| 1096 |
+
entries(): Generator<[K, V], void, unknown>;
|
| 1097 |
+
/**
|
| 1098 |
+
* Inverse order version of {@link LRUCache.entries}
|
| 1099 |
+
*
|
| 1100 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 1101 |
+
* in order from least recently used to most recently used.
|
| 1102 |
+
*/
|
| 1103 |
+
rentries(): Generator<(K | V)[], void, unknown>;
|
| 1104 |
+
/**
|
| 1105 |
+
* Return a generator yielding the keys in the cache,
|
| 1106 |
+
* in order from most recently used to least recently used.
|
| 1107 |
+
*/
|
| 1108 |
+
keys(): Generator<K, void, unknown>;
|
| 1109 |
+
/**
|
| 1110 |
+
* Inverse order version of {@link LRUCache.keys}
|
| 1111 |
+
*
|
| 1112 |
+
* Return a generator yielding the keys in the cache,
|
| 1113 |
+
* in order from least recently used to most recently used.
|
| 1114 |
+
*/
|
| 1115 |
+
rkeys(): Generator<K, void, unknown>;
|
| 1116 |
+
/**
|
| 1117 |
+
* Return a generator yielding the values in the cache,
|
| 1118 |
+
* in order from most recently used to least recently used.
|
| 1119 |
+
*/
|
| 1120 |
+
values(): Generator<V, void, unknown>;
|
| 1121 |
+
/**
|
| 1122 |
+
* Inverse order version of {@link LRUCache.values}
|
| 1123 |
+
*
|
| 1124 |
+
* Return a generator yielding the values in the cache,
|
| 1125 |
+
* in order from least recently used to most recently used.
|
| 1126 |
+
*/
|
| 1127 |
+
rvalues(): Generator<V | undefined, void, unknown>;
|
| 1128 |
+
/**
|
| 1129 |
+
* Iterating over the cache itself yields the same results as
|
| 1130 |
+
* {@link LRUCache.entries}
|
| 1131 |
+
*/
|
| 1132 |
+
[Symbol.iterator](): Generator<[K, V], void, unknown>;
|
| 1133 |
+
/**
|
| 1134 |
+
* A String value that is used in the creation of the default string
|
| 1135 |
+
* description of an object. Called by the built-in method
|
| 1136 |
+
* `Object.prototype.toString`.
|
| 1137 |
+
*/
|
| 1138 |
+
[Symbol.toStringTag]: string;
|
| 1139 |
+
/**
|
| 1140 |
+
* Find a value for which the supplied fn method returns a truthy value,
|
| 1141 |
+
* similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
|
| 1142 |
+
*/
|
| 1143 |
+
find(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => boolean, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
|
| 1144 |
+
/**
|
| 1145 |
+
* Call the supplied function on each item in the cache, in order from most
|
| 1146 |
+
* recently used to least recently used.
|
| 1147 |
+
*
|
| 1148 |
+
* `fn` is called as `fn(value, key, cache)`.
|
| 1149 |
+
*
|
| 1150 |
+
* If `thisp` is provided, function will be called in the `this`-context of
|
| 1151 |
+
* the provided object, or the cache if no `thisp` object is provided.
|
| 1152 |
+
*
|
| 1153 |
+
* Does not update age or recenty of use, or iterate over stale values.
|
| 1154 |
+
*/
|
| 1155 |
+
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
| 1156 |
+
/**
|
| 1157 |
+
* The same as {@link LRUCache.forEach} but items are iterated over in
|
| 1158 |
+
* reverse order. (ie, less recently used items are iterated over first.)
|
| 1159 |
+
*/
|
| 1160 |
+
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
| 1161 |
+
/**
|
| 1162 |
+
* Delete any stale entries. Returns true if anything was removed,
|
| 1163 |
+
* false otherwise.
|
| 1164 |
+
*/
|
| 1165 |
+
purgeStale(): boolean;
|
| 1166 |
+
/**
|
| 1167 |
+
* Get the extended info about a given entry, to get its value, size, and
|
| 1168 |
+
* TTL info simultaneously. Returns `undefined` if the key is not present.
|
| 1169 |
+
*
|
| 1170 |
+
* Unlike {@link LRUCache#dump}, which is designed to be portable and survive
|
| 1171 |
+
* serialization, the `start` value is always the current timestamp, and the
|
| 1172 |
+
* `ttl` is a calculated remaining time to live (negative if expired).
|
| 1173 |
+
*
|
| 1174 |
+
* Always returns stale values, if their info is found in the cache, so be
|
| 1175 |
+
* sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
|
| 1176 |
+
* if relevant.
|
| 1177 |
+
*/
|
| 1178 |
+
info(key: K): LRUCache.Entry<V> | undefined;
|
| 1179 |
+
/**
|
| 1180 |
+
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
| 1181 |
+
* passed to {@link LRUCache#load}.
|
| 1182 |
+
*
|
| 1183 |
+
* The `start` fields are calculated relative to a portable `Date.now()`
|
| 1184 |
+
* timestamp, even if `performance.now()` is available.
|
| 1185 |
+
*
|
| 1186 |
+
* Stale entries are always included in the `dump`, even if
|
| 1187 |
+
* {@link LRUCache.OptionsBase.allowStale} is false.
|
| 1188 |
+
*
|
| 1189 |
+
* Note: this returns an actual array, not a generator, so it can be more
|
| 1190 |
+
* easily passed around.
|
| 1191 |
+
*/
|
| 1192 |
+
dump(): [K, LRUCache.Entry<V>][];
|
| 1193 |
+
/**
|
| 1194 |
+
* Reset the cache and load in the items in entries in the order listed.
|
| 1195 |
+
*
|
| 1196 |
+
* The shape of the resulting cache may be different if the same options are
|
| 1197 |
+
* not used in both caches.
|
| 1198 |
+
*
|
| 1199 |
+
* The `start` fields are assumed to be calculated relative to a portable
|
| 1200 |
+
* `Date.now()` timestamp, even if `performance.now()` is available.
|
| 1201 |
+
*/
|
| 1202 |
+
load(arr: [K, LRUCache.Entry<V>][]): void;
|
| 1203 |
+
/**
|
| 1204 |
+
* Add a value to the cache.
|
| 1205 |
+
*
|
| 1206 |
+
* Note: if `undefined` is specified as a value, this is an alias for
|
| 1207 |
+
* {@link LRUCache#delete}
|
| 1208 |
+
*
|
| 1209 |
+
* Fields on the {@link LRUCache.SetOptions} options param will override
|
| 1210 |
+
* their corresponding values in the constructor options for the scope
|
| 1211 |
+
* of this single `set()` operation.
|
| 1212 |
+
*
|
| 1213 |
+
* If `start` is provided, then that will set the effective start
|
| 1214 |
+
* time for the TTL calculation. Note that this must be a previous
|
| 1215 |
+
* value of `performance.now()` if supported, or a previous value of
|
| 1216 |
+
* `Date.now()` if not.
|
| 1217 |
+
*
|
| 1218 |
+
* Options object may also include `size`, which will prevent
|
| 1219 |
+
* calling the `sizeCalculation` function and just use the specified
|
| 1220 |
+
* number if it is a positive integer, and `noDisposeOnSet` which
|
| 1221 |
+
* will prevent calling a `dispose` function in the case of
|
| 1222 |
+
* overwrites.
|
| 1223 |
+
*
|
| 1224 |
+
* If the `size` (or return value of `sizeCalculation`) for a given
|
| 1225 |
+
* entry is greater than `maxEntrySize`, then the item will not be
|
| 1226 |
+
* added to the cache.
|
| 1227 |
+
*
|
| 1228 |
+
* Will update the recency of the entry.
|
| 1229 |
+
*
|
| 1230 |
+
* If the value is `undefined`, then this is an alias for
|
| 1231 |
+
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
| 1232 |
+
*/
|
| 1233 |
+
set(k: K, v: V | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
| 1234 |
+
/**
|
| 1235 |
+
* Evict the least recently used item, returning its value or
|
| 1236 |
+
* `undefined` if cache is empty.
|
| 1237 |
+
*/
|
| 1238 |
+
pop(): V | undefined;
|
| 1239 |
+
/**
|
| 1240 |
+
* Check if a key is in the cache, without updating the recency of use.
|
| 1241 |
+
* Will return false if the item is stale, even though it is technically
|
| 1242 |
+
* in the cache.
|
| 1243 |
+
*
|
| 1244 |
+
* Check if a key is in the cache, without updating the recency of
|
| 1245 |
+
* use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
|
| 1246 |
+
* to `true` in either the options or the constructor.
|
| 1247 |
+
*
|
| 1248 |
+
* Will return `false` if the item is stale, even though it is technically in
|
| 1249 |
+
* the cache. The difference can be determined (if it matters) by using a
|
| 1250 |
+
* `status` argument, and inspecting the `has` field.
|
| 1251 |
+
*
|
| 1252 |
+
* Will not update item age unless
|
| 1253 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
| 1254 |
+
*/
|
| 1255 |
+
has(k: K, hasOptions?: LRUCache.HasOptions<K, V, FC>): boolean;
|
| 1256 |
+
/**
|
| 1257 |
+
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
| 1258 |
+
* items.
|
| 1259 |
+
*
|
| 1260 |
+
* Returns `undefined` if the item is stale, unless
|
| 1261 |
+
* {@link LRUCache.OptionsBase.allowStale} is set.
|
| 1262 |
+
*/
|
| 1263 |
+
peek(k: K, peekOptions?: LRUCache.PeekOptions<K, V, FC>): V | undefined;
|
| 1264 |
+
/**
|
| 1265 |
+
* Make an asynchronous cached fetch using the
|
| 1266 |
+
* {@link LRUCache.OptionsBase.fetchMethod} function.
|
| 1267 |
+
*
|
| 1268 |
+
* If the value is in the cache and not stale, then the returned
|
| 1269 |
+
* Promise resolves to the value.
|
| 1270 |
+
*
|
| 1271 |
+
* If not in the cache, or beyond its TTL staleness, then
|
| 1272 |
+
* `fetchMethod(key, staleValue, { options, signal, context })` is
|
| 1273 |
+
* called, and the value returned will be added to the cache once
|
| 1274 |
+
* resolved.
|
| 1275 |
+
*
|
| 1276 |
+
* If called with `allowStale`, and an asynchronous fetch is
|
| 1277 |
+
* currently in progress to reload a stale value, then the former
|
| 1278 |
+
* stale value will be returned.
|
| 1279 |
+
*
|
| 1280 |
+
* If called with `forceRefresh`, then the cached item will be
|
| 1281 |
+
* re-fetched, even if it is not stale. However, if `allowStale` is also
|
| 1282 |
+
* set, then the old value will still be returned. This is useful
|
| 1283 |
+
* in cases where you want to force a reload of a cached value. If
|
| 1284 |
+
* a background fetch is already in progress, then `forceRefresh`
|
| 1285 |
+
* has no effect.
|
| 1286 |
+
*
|
| 1287 |
+
* If multiple fetches for the same key are issued, then they will all be
|
| 1288 |
+
* coalesced into a single call to fetchMethod.
|
| 1289 |
+
*
|
| 1290 |
+
* Note that this means that handling options such as
|
| 1291 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort},
|
| 1292 |
+
* {@link LRUCache.FetchOptions.signal},
|
| 1293 |
+
* and {@link LRUCache.OptionsBase.allowStaleOnFetchRejection} will be
|
| 1294 |
+
* determined by the FIRST fetch() call for a given key.
|
| 1295 |
+
*
|
| 1296 |
+
* This is a known (fixable) shortcoming which will be addresed on when
|
| 1297 |
+
* someone complains about it, as the fix would involve added complexity and
|
| 1298 |
+
* may not be worth the costs for this edge case.
|
| 1299 |
+
*
|
| 1300 |
+
* If {@link LRUCache.OptionsBase.fetchMethod} is not specified, then this is
|
| 1301 |
+
* effectively an alias for `Promise.resolve(cache.get(key))`.
|
| 1302 |
+
*
|
| 1303 |
+
* When the fetch method resolves to a value, if the fetch has not
|
| 1304 |
+
* been aborted due to deletion, eviction, or being overwritten,
|
| 1305 |
+
* then it is added to the cache using the options provided.
|
| 1306 |
+
*
|
| 1307 |
+
* If the key is evicted or deleted before the `fetchMethod`
|
| 1308 |
+
* resolves, then the AbortSignal passed to the `fetchMethod` will
|
| 1309 |
+
* receive an `abort` event, and the promise returned by `fetch()`
|
| 1310 |
+
* will reject with the reason for the abort.
|
| 1311 |
+
*
|
| 1312 |
+
* If a `signal` is passed to the `fetch()` call, then aborting the
|
| 1313 |
+
* signal will abort the fetch and cause the `fetch()` promise to
|
| 1314 |
+
* reject with the reason provided.
|
| 1315 |
+
*
|
| 1316 |
+
* **Setting `context`**
|
| 1317 |
+
*
|
| 1318 |
+
* If an `FC` type is set to a type other than `unknown`, `void`, or
|
| 1319 |
+
* `undefined` in the {@link LRUCache} constructor, then all
|
| 1320 |
+
* calls to `cache.fetch()` _must_ provide a `context` option. If
|
| 1321 |
+
* set to `undefined` or `void`, then calls to fetch _must not_
|
| 1322 |
+
* provide a `context` option.
|
| 1323 |
+
*
|
| 1324 |
+
* The `context` param allows you to provide arbitrary data that
|
| 1325 |
+
* might be relevant in the course of fetching the data. It is only
|
| 1326 |
+
* relevant for the course of a single `fetch()` operation, and
|
| 1327 |
+
* discarded afterwards.
|
| 1328 |
+
*
|
| 1329 |
+
* **Note: `fetch()` calls are inflight-unique**
|
| 1330 |
+
*
|
| 1331 |
+
* If you call `fetch()` multiple times with the same key value,
|
| 1332 |
+
* then every call after the first will resolve on the same
|
| 1333 |
+
* promise<sup>1</sup>,
|
| 1334 |
+
* _even if they have different settings that would otherwise change
|
| 1335 |
+
* the behavior of the fetch_, such as `noDeleteOnFetchRejection`
|
| 1336 |
+
* or `ignoreFetchAbort`.
|
| 1337 |
+
*
|
| 1338 |
+
* In most cases, this is not a problem (in fact, only fetching
|
| 1339 |
+
* something once is what you probably want, if you're caching in
|
| 1340 |
+
* the first place). If you are changing the fetch() options
|
| 1341 |
+
* dramatically between runs, there's a good chance that you might
|
| 1342 |
+
* be trying to fit divergent semantics into a single object, and
|
| 1343 |
+
* would be better off with multiple cache instances.
|
| 1344 |
+
*
|
| 1345 |
+
* **1**: Ie, they're not the "same Promise", but they resolve at
|
| 1346 |
+
* the same time, because they're both waiting on the same
|
| 1347 |
+
* underlying fetchMethod response.
|
| 1348 |
+
*/
|
| 1349 |
+
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
| 1350 |
+
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<undefined | V>;
|
| 1351 |
+
/**
|
| 1352 |
+
* In some cases, `cache.fetch()` may resolve to `undefined`, either because
|
| 1353 |
+
* a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
|
| 1354 |
+
* `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
|
| 1355 |
+
* because `ignoreFetchAbort` was specified (either to the constructor or
|
| 1356 |
+
* in the {@link LRUCache.FetchOptions}). Also, the
|
| 1357 |
+
* {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
| 1358 |
+
* the test even more complicated.
|
| 1359 |
+
*
|
| 1360 |
+
* Because inferring the cases where `undefined` might be returned are so
|
| 1361 |
+
* cumbersome, but testing for `undefined` can also be annoying, this method
|
| 1362 |
+
* can be used, which will reject if `this.fetch()` resolves to undefined.
|
| 1363 |
+
*/
|
| 1364 |
+
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
| 1365 |
+
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<V>;
|
| 1366 |
+
/**
|
| 1367 |
+
* If the key is found in the cache, then this is equivalent to
|
| 1368 |
+
* {@link LRUCache#get}. If not, in the cache, then calculate the value using
|
| 1369 |
+
* the {@link LRUCache.OptionsBase.memoMethod}, and add it to the cache.
|
| 1370 |
+
*
|
| 1371 |
+
* If an `FC` type is set to a type other than `unknown`, `void`, or
|
| 1372 |
+
* `undefined` in the LRUCache constructor, then all calls to `cache.memo()`
|
| 1373 |
+
* _must_ provide a `context` option. If set to `undefined` or `void`, then
|
| 1374 |
+
* calls to memo _must not_ provide a `context` option.
|
| 1375 |
+
*
|
| 1376 |
+
* The `context` param allows you to provide arbitrary data that might be
|
| 1377 |
+
* relevant in the course of fetching the data. It is only relevant for the
|
| 1378 |
+
* course of a single `memo()` operation, and discarded afterwards.
|
| 1379 |
+
*/
|
| 1380 |
+
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
| 1381 |
+
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : never): V;
|
| 1382 |
+
/**
|
| 1383 |
+
* Return a value from the cache. Will update the recency of the cache
|
| 1384 |
+
* entry found.
|
| 1385 |
+
*
|
| 1386 |
+
* If the key is not found, get() will return `undefined`.
|
| 1387 |
+
*/
|
| 1388 |
+
get(k: K, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
|
| 1389 |
+
/**
|
| 1390 |
+
* Deletes a key out of the cache.
|
| 1391 |
+
*
|
| 1392 |
+
* Returns true if the key was deleted, false otherwise.
|
| 1393 |
+
*/
|
| 1394 |
+
delete(k: K): boolean;
|
| 1395 |
+
/**
|
| 1396 |
+
* Clear the cache entirely, throwing away all values.
|
| 1397 |
+
*/
|
| 1398 |
+
clear(): void;
|
| 1399 |
+
}
|
| 1400 |
+
//# sourceMappingURL=index.d.ts.map
|
node_modules/lru-cache/dist/commonjs/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAiCrC,QAAA,MAAM,IAAI,eAAiB,CAAA;AAC3B,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAA;AAC5D,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAKzD,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAA;AAC9D,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,EAAE,CAAA;AAoB9C,cAAM,SAAU,SAAQ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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* @module LRUCache
|
| 4 |
+
*/
|
| 5 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 6 |
+
exports.LRUCache = void 0;
|
| 7 |
+
const diagnostics_channel_js_1 = require("./diagnostics-channel.js");
|
| 8 |
+
const perf_js_1 = require("./perf.js");
|
| 9 |
+
const hasSubscribers = () => diagnostics_channel_js_1.metrics.hasSubscribers || diagnostics_channel_js_1.tracing.hasSubscribers;
|
| 10 |
+
const warned = new Set();
|
| 11 |
+
/* c8 ignore start */
|
| 12 |
+
const PROCESS = (typeof process === 'object' && !!process ?
|
| 13 |
+
process
|
| 14 |
+
: {});
|
| 15 |
+
/* c8 ignore stop */
|
| 16 |
+
const emitWarning = (msg, type, code, fn) => {
|
| 17 |
+
if (typeof PROCESS.emitWarning === 'function') {
|
| 18 |
+
PROCESS.emitWarning(msg, type, code, fn);
|
| 19 |
+
}
|
| 20 |
+
else {
|
| 21 |
+
//oxlint-disable-next-line no-console
|
| 22 |
+
console.error(`[${code}] ${type}: ${msg}`);
|
| 23 |
+
}
|
| 24 |
+
};
|
| 25 |
+
const shouldWarn = (code) => !warned.has(code);
|
| 26 |
+
const TYPE = Symbol('type');
|
| 27 |
+
const isPosInt = (n) => !!n && n === Math.floor(n) && n > 0 && isFinite(n);
|
| 28 |
+
// This is a little bit ridiculous, tbh.
|
| 29 |
+
// The maximum array length is 2^32-1 or thereabouts on most JS impls.
|
| 30 |
+
// And well before that point, you're caching the entire world, I mean,
|
| 31 |
+
// that's ~32GB of just integers for the next/prev links, plus whatever
|
| 32 |
+
// else to hold that many keys and values. Just filling the memory with
|
| 33 |
+
// zeroes at init time is brutal when you get that big.
|
| 34 |
+
// But why not be complete?
|
| 35 |
+
// Maybe in the future, these limits will have expanded.
|
| 36 |
+
/* c8 ignore start */
|
| 37 |
+
const getUintArray = (max) => !isPosInt(max) ? null
|
| 38 |
+
: max <= Math.pow(2, 8) ? Uint8Array
|
| 39 |
+
: max <= Math.pow(2, 16) ? Uint16Array
|
| 40 |
+
: max <= Math.pow(2, 32) ? Uint32Array
|
| 41 |
+
: max <= Number.MAX_SAFE_INTEGER ? ZeroArray
|
| 42 |
+
: null;
|
| 43 |
+
/* c8 ignore stop */
|
| 44 |
+
class ZeroArray extends Array {
|
| 45 |
+
constructor(size) {
|
| 46 |
+
super(size);
|
| 47 |
+
this.fill(0);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
class Stack {
|
| 51 |
+
/* c8 ignore start - not sure why this is showing up uncovered?? */
|
| 52 |
+
heap;
|
| 53 |
+
/* c8 ignore stop */
|
| 54 |
+
length;
|
| 55 |
+
// private constructor
|
| 56 |
+
static #constructing = false;
|
| 57 |
+
static create(max) {
|
| 58 |
+
const HeapCls = getUintArray(max);
|
| 59 |
+
if (!HeapCls)
|
| 60 |
+
return [];
|
| 61 |
+
Stack.#constructing = true;
|
| 62 |
+
const s = new Stack(max, HeapCls);
|
| 63 |
+
Stack.#constructing = false;
|
| 64 |
+
return s;
|
| 65 |
+
}
|
| 66 |
+
constructor(max, HeapCls) {
|
| 67 |
+
/* c8 ignore start */
|
| 68 |
+
if (!Stack.#constructing) {
|
| 69 |
+
throw new TypeError('instantiate Stack using Stack.create(n)');
|
| 70 |
+
}
|
| 71 |
+
/* c8 ignore stop */
|
| 72 |
+
this.heap = new HeapCls(max);
|
| 73 |
+
this.length = 0;
|
| 74 |
+
}
|
| 75 |
+
push(n) {
|
| 76 |
+
this.heap[this.length++] = n;
|
| 77 |
+
}
|
| 78 |
+
pop() {
|
| 79 |
+
return this.heap[--this.length];
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
/**
|
| 83 |
+
* Default export, the thing you're using this module to get.
|
| 84 |
+
*
|
| 85 |
+
* The `K` and `V` types define the key and value types, respectively. The
|
| 86 |
+
* optional `FC` type defines the type of the `context` object passed to
|
| 87 |
+
* `cache.fetch()` and `cache.memo()`.
|
| 88 |
+
*
|
| 89 |
+
* Keys and values **must not** be `null` or `undefined`.
|
| 90 |
+
*
|
| 91 |
+
* All properties from the options object (with the exception of `max`,
|
| 92 |
+
* `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
|
| 93 |
+
* added as normal public members. (The listed options are read-only getters.)
|
| 94 |
+
*
|
| 95 |
+
* Changing any of these will alter the defaults for subsequent method calls.
|
| 96 |
+
*/
|
| 97 |
+
class LRUCache {
|
| 98 |
+
// options that cannot be changed without disaster
|
| 99 |
+
#max;
|
| 100 |
+
#maxSize;
|
| 101 |
+
#dispose;
|
| 102 |
+
#onInsert;
|
| 103 |
+
#disposeAfter;
|
| 104 |
+
#fetchMethod;
|
| 105 |
+
#memoMethod;
|
| 106 |
+
#perf;
|
| 107 |
+
/**
|
| 108 |
+
* {@link LRUCache.OptionsBase.perf}
|
| 109 |
+
*/
|
| 110 |
+
get perf() {
|
| 111 |
+
return this.#perf;
|
| 112 |
+
}
|
| 113 |
+
/**
|
| 114 |
+
* {@link LRUCache.OptionsBase.ttl}
|
| 115 |
+
*/
|
| 116 |
+
ttl;
|
| 117 |
+
/**
|
| 118 |
+
* {@link LRUCache.OptionsBase.ttlResolution}
|
| 119 |
+
*/
|
| 120 |
+
ttlResolution;
|
| 121 |
+
/**
|
| 122 |
+
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
| 123 |
+
*/
|
| 124 |
+
ttlAutopurge;
|
| 125 |
+
/**
|
| 126 |
+
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
| 127 |
+
*/
|
| 128 |
+
updateAgeOnGet;
|
| 129 |
+
/**
|
| 130 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
| 131 |
+
*/
|
| 132 |
+
updateAgeOnHas;
|
| 133 |
+
/**
|
| 134 |
+
* {@link LRUCache.OptionsBase.allowStale}
|
| 135 |
+
*/
|
| 136 |
+
allowStale;
|
| 137 |
+
/**
|
| 138 |
+
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
| 139 |
+
*/
|
| 140 |
+
noDisposeOnSet;
|
| 141 |
+
/**
|
| 142 |
+
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
| 143 |
+
*/
|
| 144 |
+
noUpdateTTL;
|
| 145 |
+
/**
|
| 146 |
+
* {@link LRUCache.OptionsBase.maxEntrySize}
|
| 147 |
+
*/
|
| 148 |
+
maxEntrySize;
|
| 149 |
+
/**
|
| 150 |
+
* {@link LRUCache.OptionsBase.sizeCalculation}
|
| 151 |
+
*/
|
| 152 |
+
sizeCalculation;
|
| 153 |
+
/**
|
| 154 |
+
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
| 155 |
+
*/
|
| 156 |
+
noDeleteOnFetchRejection;
|
| 157 |
+
/**
|
| 158 |
+
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
| 159 |
+
*/
|
| 160 |
+
noDeleteOnStaleGet;
|
| 161 |
+
/**
|
| 162 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
| 163 |
+
*/
|
| 164 |
+
allowStaleOnFetchAbort;
|
| 165 |
+
/**
|
| 166 |
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
| 167 |
+
*/
|
| 168 |
+
allowStaleOnFetchRejection;
|
| 169 |
+
/**
|
| 170 |
+
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
| 171 |
+
*/
|
| 172 |
+
ignoreFetchAbort;
|
| 173 |
+
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
| 174 |
+
backgroundFetchSize;
|
| 175 |
+
// computed properties
|
| 176 |
+
#size;
|
| 177 |
+
#calculatedSize;
|
| 178 |
+
#keyMap;
|
| 179 |
+
#keyList;
|
| 180 |
+
#valList;
|
| 181 |
+
#next;
|
| 182 |
+
#prev;
|
| 183 |
+
#head;
|
| 184 |
+
#tail;
|
| 185 |
+
#free;
|
| 186 |
+
#disposed;
|
| 187 |
+
#sizes;
|
| 188 |
+
#starts;
|
| 189 |
+
#ttls;
|
| 190 |
+
#autopurgeTimers;
|
| 191 |
+
#hasDispose;
|
| 192 |
+
#hasFetchMethod;
|
| 193 |
+
#hasDisposeAfter;
|
| 194 |
+
#hasOnInsert;
|
| 195 |
+
/**
|
| 196 |
+
* Do not call this method unless you need to inspect the
|
| 197 |
+
* inner workings of the cache. If anything returned by this
|
| 198 |
+
* object is modified in any way, strange breakage may occur.
|
| 199 |
+
*
|
| 200 |
+
* These fields are private for a reason!
|
| 201 |
+
*
|
| 202 |
+
* @internal
|
| 203 |
+
*/
|
| 204 |
+
static unsafeExposeInternals(c) {
|
| 205 |
+
return {
|
| 206 |
+
// properties
|
| 207 |
+
starts: c.#starts,
|
| 208 |
+
ttls: c.#ttls,
|
| 209 |
+
autopurgeTimers: c.#autopurgeTimers,
|
| 210 |
+
sizes: c.#sizes,
|
| 211 |
+
keyMap: c.#keyMap,
|
| 212 |
+
keyList: c.#keyList,
|
| 213 |
+
valList: c.#valList,
|
| 214 |
+
next: c.#next,
|
| 215 |
+
prev: c.#prev,
|
| 216 |
+
get head() {
|
| 217 |
+
return c.#head;
|
| 218 |
+
},
|
| 219 |
+
get tail() {
|
| 220 |
+
return c.#tail;
|
| 221 |
+
},
|
| 222 |
+
free: c.#free,
|
| 223 |
+
// methods
|
| 224 |
+
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
| 225 |
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
| 226 |
+
moveToTail: (index) => c.#moveToTail(index),
|
| 227 |
+
indexes: (options) => c.#indexes(options),
|
| 228 |
+
rindexes: (options) => c.#rindexes(options),
|
| 229 |
+
isStale: (index) => c.#isStale(index),
|
| 230 |
+
};
|
| 231 |
+
}
|
| 232 |
+
// Protected read-only members
|
| 233 |
+
/**
|
| 234 |
+
* {@link LRUCache.OptionsBase.max} (read-only)
|
| 235 |
+
*/
|
| 236 |
+
get max() {
|
| 237 |
+
return this.#max;
|
| 238 |
+
}
|
| 239 |
+
/**
|
| 240 |
+
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
| 241 |
+
*/
|
| 242 |
+
get maxSize() {
|
| 243 |
+
return this.#maxSize;
|
| 244 |
+
}
|
| 245 |
+
/**
|
| 246 |
+
* The total computed size of items in the cache (read-only)
|
| 247 |
+
*/
|
| 248 |
+
get calculatedSize() {
|
| 249 |
+
return this.#calculatedSize;
|
| 250 |
+
}
|
| 251 |
+
/**
|
| 252 |
+
* The number of items stored in the cache (read-only)
|
| 253 |
+
*/
|
| 254 |
+
get size() {
|
| 255 |
+
return this.#size;
|
| 256 |
+
}
|
| 257 |
+
/**
|
| 258 |
+
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
| 259 |
+
*/
|
| 260 |
+
get fetchMethod() {
|
| 261 |
+
return this.#fetchMethod;
|
| 262 |
+
}
|
| 263 |
+
get memoMethod() {
|
| 264 |
+
return this.#memoMethod;
|
| 265 |
+
}
|
| 266 |
+
/**
|
| 267 |
+
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
| 268 |
+
*/
|
| 269 |
+
get dispose() {
|
| 270 |
+
return this.#dispose;
|
| 271 |
+
}
|
| 272 |
+
/**
|
| 273 |
+
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
| 274 |
+
*/
|
| 275 |
+
get onInsert() {
|
| 276 |
+
return this.#onInsert;
|
| 277 |
+
}
|
| 278 |
+
/**
|
| 279 |
+
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
| 280 |
+
*/
|
| 281 |
+
get disposeAfter() {
|
| 282 |
+
return this.#disposeAfter;
|
| 283 |
+
}
|
| 284 |
+
constructor(options) {
|
| 285 |
+
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, backgroundFetchSize = 1, perf, } = options;
|
| 286 |
+
this.backgroundFetchSize = backgroundFetchSize;
|
| 287 |
+
if (perf !== undefined) {
|
| 288 |
+
if (typeof perf?.now !== 'function') {
|
| 289 |
+
throw new TypeError('perf option must have a now() method if specified');
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
this.#perf = perf ?? perf_js_1.defaultPerf;
|
| 293 |
+
if (max !== 0 && !isPosInt(max)) {
|
| 294 |
+
throw new TypeError('max option must be a nonnegative integer');
|
| 295 |
+
}
|
| 296 |
+
const UintArray = max ? getUintArray(max) : Array;
|
| 297 |
+
if (!UintArray) {
|
| 298 |
+
throw new Error('invalid max value: ' + max);
|
| 299 |
+
}
|
| 300 |
+
this.#max = max;
|
| 301 |
+
this.#maxSize = maxSize;
|
| 302 |
+
this.maxEntrySize = maxEntrySize || this.#maxSize;
|
| 303 |
+
this.sizeCalculation = sizeCalculation;
|
| 304 |
+
if (this.sizeCalculation) {
|
| 305 |
+
if (!this.#maxSize && !this.maxEntrySize) {
|
| 306 |
+
throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
|
| 307 |
+
}
|
| 308 |
+
if (typeof this.sizeCalculation !== 'function') {
|
| 309 |
+
throw new TypeError('sizeCalculation set to non-function');
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
if (memoMethod !== undefined && typeof memoMethod !== 'function') {
|
| 313 |
+
throw new TypeError('memoMethod must be a function if defined');
|
| 314 |
+
}
|
| 315 |
+
this.#memoMethod = memoMethod;
|
| 316 |
+
if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
|
| 317 |
+
throw new TypeError('fetchMethod must be a function if specified');
|
| 318 |
+
}
|
| 319 |
+
this.#fetchMethod = fetchMethod;
|
| 320 |
+
this.#hasFetchMethod = !!fetchMethod;
|
| 321 |
+
this.#keyMap = new Map();
|
| 322 |
+
this.#keyList = Array.from({ length: max }).fill(undefined);
|
| 323 |
+
this.#valList = Array.from({ length: max }).fill(undefined);
|
| 324 |
+
this.#next = new UintArray(max);
|
| 325 |
+
this.#prev = new UintArray(max);
|
| 326 |
+
this.#head = 0;
|
| 327 |
+
this.#tail = 0;
|
| 328 |
+
this.#free = Stack.create(max);
|
| 329 |
+
this.#size = 0;
|
| 330 |
+
this.#calculatedSize = 0;
|
| 331 |
+
if (typeof dispose === 'function') {
|
| 332 |
+
this.#dispose = dispose;
|
| 333 |
+
}
|
| 334 |
+
if (typeof onInsert === 'function') {
|
| 335 |
+
this.#onInsert = onInsert;
|
| 336 |
+
}
|
| 337 |
+
if (typeof disposeAfter === 'function') {
|
| 338 |
+
this.#disposeAfter = disposeAfter;
|
| 339 |
+
this.#disposed = [];
|
| 340 |
+
}
|
| 341 |
+
else {
|
| 342 |
+
this.#disposeAfter = undefined;
|
| 343 |
+
this.#disposed = undefined;
|
| 344 |
+
}
|
| 345 |
+
this.#hasDispose = !!this.#dispose;
|
| 346 |
+
this.#hasOnInsert = !!this.#onInsert;
|
| 347 |
+
this.#hasDisposeAfter = !!this.#disposeAfter;
|
| 348 |
+
this.noDisposeOnSet = !!noDisposeOnSet;
|
| 349 |
+
this.noUpdateTTL = !!noUpdateTTL;
|
| 350 |
+
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
| 351 |
+
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
| 352 |
+
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
| 353 |
+
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
| 354 |
+
// NB: maxEntrySize is set to maxSize if it's set
|
| 355 |
+
if (this.maxEntrySize !== 0) {
|
| 356 |
+
if (this.#maxSize !== 0) {
|
| 357 |
+
if (!isPosInt(this.#maxSize)) {
|
| 358 |
+
throw new TypeError('maxSize must be a positive integer if specified');
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
if (!isPosInt(this.maxEntrySize)) {
|
| 362 |
+
throw new TypeError('maxEntrySize must be a positive integer if specified');
|
| 363 |
+
}
|
| 364 |
+
this.#initializeSizeTracking();
|
| 365 |
+
}
|
| 366 |
+
this.allowStale = !!allowStale;
|
| 367 |
+
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
| 368 |
+
this.updateAgeOnGet = !!updateAgeOnGet;
|
| 369 |
+
this.updateAgeOnHas = !!updateAgeOnHas;
|
| 370 |
+
this.ttlResolution =
|
| 371 |
+
isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
|
| 372 |
+
this.ttlAutopurge = !!ttlAutopurge;
|
| 373 |
+
this.ttl = ttl || 0;
|
| 374 |
+
if (this.ttl) {
|
| 375 |
+
if (!isPosInt(this.ttl)) {
|
| 376 |
+
throw new TypeError('ttl must be a positive integer if specified');
|
| 377 |
+
}
|
| 378 |
+
this.#initializeTTLTracking();
|
| 379 |
+
}
|
| 380 |
+
// do not allow completely unbounded caches
|
| 381 |
+
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
|
| 382 |
+
throw new TypeError('At least one of max, maxSize, or ttl is required');
|
| 383 |
+
}
|
| 384 |
+
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
| 385 |
+
const code = 'LRU_CACHE_UNBOUNDED';
|
| 386 |
+
if (shouldWarn(code)) {
|
| 387 |
+
warned.add(code);
|
| 388 |
+
const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
|
| 389 |
+
'result in unbounded memory consumption.';
|
| 390 |
+
emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
/**
|
| 395 |
+
* Return the number of ms left in the item's TTL. If item is not in cache,
|
| 396 |
+
* returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
|
| 397 |
+
*/
|
| 398 |
+
getRemainingTTL(key) {
|
| 399 |
+
return this.#keyMap.has(key) ? Infinity : 0;
|
| 400 |
+
}
|
| 401 |
+
#initializeTTLTracking() {
|
| 402 |
+
const ttls = new ZeroArray(this.#max);
|
| 403 |
+
const starts = new ZeroArray(this.#max);
|
| 404 |
+
this.#ttls = ttls;
|
| 405 |
+
this.#starts = starts;
|
| 406 |
+
const purgeTimers = this.ttlAutopurge ?
|
| 407 |
+
Array.from({
|
| 408 |
+
length: this.#max,
|
| 409 |
+
})
|
| 410 |
+
: undefined;
|
| 411 |
+
this.#autopurgeTimers = purgeTimers;
|
| 412 |
+
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
|
| 413 |
+
starts[index] = ttl !== 0 ? start : 0;
|
| 414 |
+
ttls[index] = ttl;
|
| 415 |
+
setPurgetTimer(index, ttl);
|
| 416 |
+
};
|
| 417 |
+
this.#updateItemAge = index => {
|
| 418 |
+
starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
|
| 419 |
+
setPurgetTimer(index, ttls[index]);
|
| 420 |
+
};
|
| 421 |
+
// clear out the purge timer if we're setting TTL to 0, and
|
| 422 |
+
// previously had a ttl purge timer running, so it doesn't
|
| 423 |
+
// fire unnecessarily. Don't need to do this if we're not doing
|
| 424 |
+
// autopurge.
|
| 425 |
+
const setPurgetTimer = !this.ttlAutopurge ?
|
| 426 |
+
() => { }
|
| 427 |
+
: (index, ttl) => {
|
| 428 |
+
if (purgeTimers?.[index]) {
|
| 429 |
+
clearTimeout(purgeTimers[index]);
|
| 430 |
+
purgeTimers[index] = undefined;
|
| 431 |
+
}
|
| 432 |
+
if (ttl && ttl !== 0 && purgeTimers) {
|
| 433 |
+
const t = setTimeout(() => {
|
| 434 |
+
if (this.#isStale(index)) {
|
| 435 |
+
this.#delete(this.#keyList[index], 'expire');
|
| 436 |
+
}
|
| 437 |
+
}, ttl + 1);
|
| 438 |
+
// unref() not supported on all platforms
|
| 439 |
+
/* c8 ignore start */
|
| 440 |
+
if (t.unref) {
|
| 441 |
+
t.unref();
|
| 442 |
+
}
|
| 443 |
+
/* c8 ignore stop */
|
| 444 |
+
purgeTimers[index] = t;
|
| 445 |
+
}
|
| 446 |
+
};
|
| 447 |
+
this.#statusTTL = (status, index) => {
|
| 448 |
+
if (ttls[index]) {
|
| 449 |
+
const ttl = ttls[index];
|
| 450 |
+
const start = starts[index];
|
| 451 |
+
/* c8 ignore start */
|
| 452 |
+
if (!ttl || !start) {
|
| 453 |
+
return;
|
| 454 |
+
}
|
| 455 |
+
/* c8 ignore stop */
|
| 456 |
+
status.ttl = ttl;
|
| 457 |
+
status.start = start;
|
| 458 |
+
status.now = cachedNow || getNow();
|
| 459 |
+
const age = status.now - start;
|
| 460 |
+
status.remainingTTL = ttl - age;
|
| 461 |
+
}
|
| 462 |
+
};
|
| 463 |
+
// debounce calls to perf.now() to 1s so we're not hitting
|
| 464 |
+
// that costly call repeatedly.
|
| 465 |
+
let cachedNow = 0;
|
| 466 |
+
const getNow = () => {
|
| 467 |
+
const n = this.#perf.now();
|
| 468 |
+
if (this.ttlResolution > 0) {
|
| 469 |
+
cachedNow = n;
|
| 470 |
+
const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
|
| 471 |
+
// not available on all platforms
|
| 472 |
+
/* c8 ignore start */
|
| 473 |
+
if (t.unref) {
|
| 474 |
+
t.unref();
|
| 475 |
+
}
|
| 476 |
+
/* c8 ignore stop */
|
| 477 |
+
}
|
| 478 |
+
return n;
|
| 479 |
+
};
|
| 480 |
+
this.getRemainingTTL = key => {
|
| 481 |
+
const index = this.#keyMap.get(key);
|
| 482 |
+
if (index === undefined) {
|
| 483 |
+
return 0;
|
| 484 |
+
}
|
| 485 |
+
const ttl = ttls[index];
|
| 486 |
+
const start = starts[index];
|
| 487 |
+
if (!ttl || !start) {
|
| 488 |
+
return Infinity;
|
| 489 |
+
}
|
| 490 |
+
const age = (cachedNow || getNow()) - start;
|
| 491 |
+
return ttl - age;
|
| 492 |
+
};
|
| 493 |
+
this.#isStale = index => {
|
| 494 |
+
const s = starts[index];
|
| 495 |
+
const t = ttls[index];
|
| 496 |
+
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
| 497 |
+
};
|
| 498 |
+
}
|
| 499 |
+
// conditionally set private methods related to TTL
|
| 500 |
+
#updateItemAge = () => { };
|
| 501 |
+
#statusTTL = () => { };
|
| 502 |
+
#setItemTTL = () => { };
|
| 503 |
+
/* c8 ignore stop */
|
| 504 |
+
#isStale = () => false;
|
| 505 |
+
#initializeSizeTracking() {
|
| 506 |
+
const sizes = new ZeroArray(this.#max);
|
| 507 |
+
this.#calculatedSize = 0;
|
| 508 |
+
this.#sizes = sizes;
|
| 509 |
+
this.#removeItemSize = index => {
|
| 510 |
+
this.#calculatedSize -= sizes[index];
|
| 511 |
+
sizes[index] = 0;
|
| 512 |
+
};
|
| 513 |
+
this.#requireSize = (k, v, size, sizeCalculation) => {
|
| 514 |
+
if (!isPosInt(size)) {
|
| 515 |
+
// provisionally accept background fetches.
|
| 516 |
+
// actual value size will be checked when they return.
|
| 517 |
+
if (this.#isBackgroundFetch(v)) {
|
| 518 |
+
// NB: this cannot occur if v.__staleWhileFetching is set,
|
| 519 |
+
// because in that case, it would take on the size of the
|
| 520 |
+
// existing entry that it temporarily replaces.
|
| 521 |
+
return this.backgroundFetchSize;
|
| 522 |
+
}
|
| 523 |
+
if (sizeCalculation) {
|
| 524 |
+
if (typeof sizeCalculation !== 'function') {
|
| 525 |
+
throw new TypeError('sizeCalculation must be a function');
|
| 526 |
+
}
|
| 527 |
+
size = sizeCalculation(v, k);
|
| 528 |
+
if (!isPosInt(size)) {
|
| 529 |
+
throw new TypeError('sizeCalculation return invalid (expect positive integer)');
|
| 530 |
+
}
|
| 531 |
+
}
|
| 532 |
+
else {
|
| 533 |
+
throw new TypeError('invalid size value (must be positive integer). ' +
|
| 534 |
+
'When maxSize or maxEntrySize is used, sizeCalculation ' +
|
| 535 |
+
'or size must be set.');
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
return size;
|
| 539 |
+
};
|
| 540 |
+
this.#addItemSize = (index, size, status) => {
|
| 541 |
+
sizes[index] = size;
|
| 542 |
+
if (this.#maxSize) {
|
| 543 |
+
const maxSize = this.#maxSize - sizes[index];
|
| 544 |
+
while (this.#calculatedSize > maxSize) {
|
| 545 |
+
this.#evict(true);
|
| 546 |
+
}
|
| 547 |
+
}
|
| 548 |
+
this.#calculatedSize += sizes[index];
|
| 549 |
+
if (status) {
|
| 550 |
+
status.entrySize = size;
|
| 551 |
+
status.totalCalculatedSize = this.#calculatedSize;
|
| 552 |
+
}
|
| 553 |
+
};
|
| 554 |
+
}
|
| 555 |
+
#removeItemSize = _i => { };
|
| 556 |
+
#addItemSize = (_i, _s, _st) => { };
|
| 557 |
+
#requireSize = (_k, _v, size, sizeCalculation) => {
|
| 558 |
+
if (size || sizeCalculation) {
|
| 559 |
+
throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
|
| 560 |
+
}
|
| 561 |
+
return 0;
|
| 562 |
+
};
|
| 563 |
+
*#indexes({ allowStale = this.allowStale } = {}) {
|
| 564 |
+
if (this.#size) {
|
| 565 |
+
for (let i = this.#tail; this.#isValidIndex(i);) {
|
| 566 |
+
if (allowStale || !this.#isStale(i)) {
|
| 567 |
+
yield i;
|
| 568 |
+
}
|
| 569 |
+
if (i === this.#head) {
|
| 570 |
+
break;
|
| 571 |
+
}
|
| 572 |
+
else {
|
| 573 |
+
i = this.#prev[i];
|
| 574 |
+
}
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
}
|
| 578 |
+
*#rindexes({ allowStale = this.allowStale } = {}) {
|
| 579 |
+
if (this.#size) {
|
| 580 |
+
for (let i = this.#head; this.#isValidIndex(i);) {
|
| 581 |
+
if (allowStale || !this.#isStale(i)) {
|
| 582 |
+
yield i;
|
| 583 |
+
}
|
| 584 |
+
if (i === this.#tail) {
|
| 585 |
+
break;
|
| 586 |
+
}
|
| 587 |
+
else {
|
| 588 |
+
i = this.#next[i];
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
#isValidIndex(index) {
|
| 594 |
+
return (index !== undefined &&
|
| 595 |
+
this.#keyMap.get(this.#keyList[index]) === index);
|
| 596 |
+
}
|
| 597 |
+
/**
|
| 598 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 599 |
+
* in order from most recently used to least recently used.
|
| 600 |
+
*/
|
| 601 |
+
*entries() {
|
| 602 |
+
for (const i of this.#indexes()) {
|
| 603 |
+
if (this.#valList[i] !== undefined &&
|
| 604 |
+
this.#keyList[i] !== undefined &&
|
| 605 |
+
!this.#isBackgroundFetch(this.#valList[i])) {
|
| 606 |
+
yield [this.#keyList[i], this.#valList[i]];
|
| 607 |
+
}
|
| 608 |
+
}
|
| 609 |
+
}
|
| 610 |
+
/**
|
| 611 |
+
* Inverse order version of {@link LRUCache.entries}
|
| 612 |
+
*
|
| 613 |
+
* Return a generator yielding `[key, value]` pairs,
|
| 614 |
+
* in order from least recently used to most recently used.
|
| 615 |
+
*/
|
| 616 |
+
*rentries() {
|
| 617 |
+
for (const i of this.#rindexes()) {
|
| 618 |
+
if (this.#valList[i] !== undefined &&
|
| 619 |
+
this.#keyList[i] !== undefined &&
|
| 620 |
+
!this.#isBackgroundFetch(this.#valList[i])) {
|
| 621 |
+
yield [this.#keyList[i], this.#valList[i]];
|
| 622 |
+
}
|
| 623 |
+
}
|
| 624 |
+
}
|
| 625 |
+
/**
|
| 626 |
+
* Return a generator yielding the keys in the cache,
|
| 627 |
+
* in order from most recently used to least recently used.
|
| 628 |
+
*/
|
| 629 |
+
*keys() {
|
| 630 |
+
for (const i of this.#indexes()) {
|
| 631 |
+
const k = this.#keyList[i];
|
| 632 |
+
if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 633 |
+
yield k;
|
| 634 |
+
}
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
/**
|
| 638 |
+
* Inverse order version of {@link LRUCache.keys}
|
| 639 |
+
*
|
| 640 |
+
* Return a generator yielding the keys in the cache,
|
| 641 |
+
* in order from least recently used to most recently used.
|
| 642 |
+
*/
|
| 643 |
+
*rkeys() {
|
| 644 |
+
for (const i of this.#rindexes()) {
|
| 645 |
+
const k = this.#keyList[i];
|
| 646 |
+
if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 647 |
+
yield k;
|
| 648 |
+
}
|
| 649 |
+
}
|
| 650 |
+
}
|
| 651 |
+
/**
|
| 652 |
+
* Return a generator yielding the values in the cache,
|
| 653 |
+
* in order from most recently used to least recently used.
|
| 654 |
+
*/
|
| 655 |
+
*values() {
|
| 656 |
+
for (const i of this.#indexes()) {
|
| 657 |
+
const v = this.#valList[i];
|
| 658 |
+
if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 659 |
+
yield this.#valList[i];
|
| 660 |
+
}
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
/**
|
| 664 |
+
* Inverse order version of {@link LRUCache.values}
|
| 665 |
+
*
|
| 666 |
+
* Return a generator yielding the values in the cache,
|
| 667 |
+
* in order from least recently used to most recently used.
|
| 668 |
+
*/
|
| 669 |
+
*rvalues() {
|
| 670 |
+
for (const i of this.#rindexes()) {
|
| 671 |
+
const v = this.#valList[i];
|
| 672 |
+
if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
| 673 |
+
yield this.#valList[i];
|
| 674 |
+
}
|
| 675 |
+
}
|
| 676 |
+
}
|
| 677 |
+
/**
|
| 678 |
+
* Iterating over the cache itself yields the same results as
|
| 679 |
+
* {@link LRUCache.entries}
|
| 680 |
+
*/
|
| 681 |
+
[Symbol.iterator]() {
|
| 682 |
+
return this.entries();
|
| 683 |
+
}
|
| 684 |
+
/**
|
| 685 |
+
* A String value that is used in the creation of the default string
|
| 686 |
+
* description of an object. Called by the built-in method
|
| 687 |
+
* `Object.prototype.toString`.
|
| 688 |
+
*/
|
| 689 |
+
[Symbol.toStringTag] = 'LRUCache';
|
| 690 |
+
/**
|
| 691 |
+
* Find a value for which the supplied fn method returns a truthy value,
|
| 692 |
+
* similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
|
| 693 |
+
*/
|
| 694 |
+
find(fn, getOptions = {}) {
|
| 695 |
+
for (const i of this.#indexes()) {
|
| 696 |
+
const v = this.#valList[i];
|
| 697 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 698 |
+
if (value === undefined)
|
| 699 |
+
continue;
|
| 700 |
+
if (fn(value, this.#keyList[i], this)) {
|
| 701 |
+
return this.#get(this.#keyList[i], getOptions);
|
| 702 |
+
}
|
| 703 |
+
}
|
| 704 |
+
}
|
| 705 |
+
/**
|
| 706 |
+
* Call the supplied function on each item in the cache, in order from most
|
| 707 |
+
* recently used to least recently used.
|
| 708 |
+
*
|
| 709 |
+
* `fn` is called as `fn(value, key, cache)`.
|
| 710 |
+
*
|
| 711 |
+
* If `thisp` is provided, function will be called in the `this`-context of
|
| 712 |
+
* the provided object, or the cache if no `thisp` object is provided.
|
| 713 |
+
*
|
| 714 |
+
* Does not update age or recenty of use, or iterate over stale values.
|
| 715 |
+
*/
|
| 716 |
+
forEach(fn, thisp = this) {
|
| 717 |
+
for (const i of this.#indexes()) {
|
| 718 |
+
const v = this.#valList[i];
|
| 719 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 720 |
+
if (value === undefined)
|
| 721 |
+
continue;
|
| 722 |
+
fn.call(thisp, value, this.#keyList[i], this);
|
| 723 |
+
}
|
| 724 |
+
}
|
| 725 |
+
/**
|
| 726 |
+
* The same as {@link LRUCache.forEach} but items are iterated over in
|
| 727 |
+
* reverse order. (ie, less recently used items are iterated over first.)
|
| 728 |
+
*/
|
| 729 |
+
rforEach(fn, thisp = this) {
|
| 730 |
+
for (const i of this.#rindexes()) {
|
| 731 |
+
const v = this.#valList[i];
|
| 732 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 733 |
+
if (value === undefined)
|
| 734 |
+
continue;
|
| 735 |
+
fn.call(thisp, value, this.#keyList[i], this);
|
| 736 |
+
}
|
| 737 |
+
}
|
| 738 |
+
/**
|
| 739 |
+
* Delete any stale entries. Returns true if anything was removed,
|
| 740 |
+
* false otherwise.
|
| 741 |
+
*/
|
| 742 |
+
purgeStale() {
|
| 743 |
+
let deleted = false;
|
| 744 |
+
for (const i of this.#rindexes({ allowStale: true })) {
|
| 745 |
+
if (this.#isStale(i)) {
|
| 746 |
+
this.#delete(this.#keyList[i], 'expire');
|
| 747 |
+
deleted = true;
|
| 748 |
+
}
|
| 749 |
+
}
|
| 750 |
+
return deleted;
|
| 751 |
+
}
|
| 752 |
+
/**
|
| 753 |
+
* Get the extended info about a given entry, to get its value, size, and
|
| 754 |
+
* TTL info simultaneously. Returns `undefined` if the key is not present.
|
| 755 |
+
*
|
| 756 |
+
* Unlike {@link LRUCache#dump}, which is designed to be portable and survive
|
| 757 |
+
* serialization, the `start` value is always the current timestamp, and the
|
| 758 |
+
* `ttl` is a calculated remaining time to live (negative if expired).
|
| 759 |
+
*
|
| 760 |
+
* Always returns stale values, if their info is found in the cache, so be
|
| 761 |
+
* sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
|
| 762 |
+
* if relevant.
|
| 763 |
+
*/
|
| 764 |
+
info(key) {
|
| 765 |
+
const i = this.#keyMap.get(key);
|
| 766 |
+
if (i === undefined)
|
| 767 |
+
return undefined;
|
| 768 |
+
const v = this.#valList[i];
|
| 769 |
+
/* c8 ignore start - this isn't tested for the info function,
|
| 770 |
+
* but it's the same logic as found in other places. */
|
| 771 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 772 |
+
if (value === undefined)
|
| 773 |
+
return undefined;
|
| 774 |
+
/* c8 ignore stop */
|
| 775 |
+
const entry = { value };
|
| 776 |
+
if (this.#ttls && this.#starts) {
|
| 777 |
+
const ttl = this.#ttls[i];
|
| 778 |
+
const start = this.#starts[i];
|
| 779 |
+
if (ttl && start) {
|
| 780 |
+
const remain = ttl - (this.#perf.now() - start);
|
| 781 |
+
entry.ttl = remain;
|
| 782 |
+
entry.start = Date.now();
|
| 783 |
+
}
|
| 784 |
+
}
|
| 785 |
+
if (this.#sizes) {
|
| 786 |
+
entry.size = this.#sizes[i];
|
| 787 |
+
}
|
| 788 |
+
return entry;
|
| 789 |
+
}
|
| 790 |
+
/**
|
| 791 |
+
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
| 792 |
+
* passed to {@link LRUCache#load}.
|
| 793 |
+
*
|
| 794 |
+
* The `start` fields are calculated relative to a portable `Date.now()`
|
| 795 |
+
* timestamp, even if `performance.now()` is available.
|
| 796 |
+
*
|
| 797 |
+
* Stale entries are always included in the `dump`, even if
|
| 798 |
+
* {@link LRUCache.OptionsBase.allowStale} is false.
|
| 799 |
+
*
|
| 800 |
+
* Note: this returns an actual array, not a generator, so it can be more
|
| 801 |
+
* easily passed around.
|
| 802 |
+
*/
|
| 803 |
+
dump() {
|
| 804 |
+
const arr = [];
|
| 805 |
+
for (const i of this.#indexes({ allowStale: true })) {
|
| 806 |
+
const key = this.#keyList[i];
|
| 807 |
+
const v = this.#valList[i];
|
| 808 |
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 809 |
+
if (value === undefined || key === undefined)
|
| 810 |
+
continue;
|
| 811 |
+
const entry = { value };
|
| 812 |
+
if (this.#ttls && this.#starts) {
|
| 813 |
+
entry.ttl = this.#ttls[i];
|
| 814 |
+
// always dump the start relative to a portable timestamp
|
| 815 |
+
// it's ok for this to be a bit slow, it's a rare operation.
|
| 816 |
+
const age = this.#perf.now() - this.#starts[i];
|
| 817 |
+
entry.start = Math.floor(Date.now() - age);
|
| 818 |
+
}
|
| 819 |
+
if (this.#sizes) {
|
| 820 |
+
entry.size = this.#sizes[i];
|
| 821 |
+
}
|
| 822 |
+
arr.unshift([key, entry]);
|
| 823 |
+
}
|
| 824 |
+
return arr;
|
| 825 |
+
}
|
| 826 |
+
/**
|
| 827 |
+
* Reset the cache and load in the items in entries in the order listed.
|
| 828 |
+
*
|
| 829 |
+
* The shape of the resulting cache may be different if the same options are
|
| 830 |
+
* not used in both caches.
|
| 831 |
+
*
|
| 832 |
+
* The `start` fields are assumed to be calculated relative to a portable
|
| 833 |
+
* `Date.now()` timestamp, even if `performance.now()` is available.
|
| 834 |
+
*/
|
| 835 |
+
load(arr) {
|
| 836 |
+
this.clear();
|
| 837 |
+
for (const [key, entry] of arr) {
|
| 838 |
+
if (entry.start) {
|
| 839 |
+
// entry.start is a portable timestamp, but we may be using
|
| 840 |
+
// node's performance.now(), so calculate the offset, so that
|
| 841 |
+
// we get the intended remaining TTL, no matter how long it's
|
| 842 |
+
// been on ice.
|
| 843 |
+
//
|
| 844 |
+
// it's ok for this to be a bit slow, it's a rare operation.
|
| 845 |
+
const age = Date.now() - entry.start;
|
| 846 |
+
entry.start = this.#perf.now() - age;
|
| 847 |
+
}
|
| 848 |
+
this.#set(key, entry.value, entry);
|
| 849 |
+
}
|
| 850 |
+
}
|
| 851 |
+
/**
|
| 852 |
+
* Add a value to the cache.
|
| 853 |
+
*
|
| 854 |
+
* Note: if `undefined` is specified as a value, this is an alias for
|
| 855 |
+
* {@link LRUCache#delete}
|
| 856 |
+
*
|
| 857 |
+
* Fields on the {@link LRUCache.SetOptions} options param will override
|
| 858 |
+
* their corresponding values in the constructor options for the scope
|
| 859 |
+
* of this single `set()` operation.
|
| 860 |
+
*
|
| 861 |
+
* If `start` is provided, then that will set the effective start
|
| 862 |
+
* time for the TTL calculation. Note that this must be a previous
|
| 863 |
+
* value of `performance.now()` if supported, or a previous value of
|
| 864 |
+
* `Date.now()` if not.
|
| 865 |
+
*
|
| 866 |
+
* Options object may also include `size`, which will prevent
|
| 867 |
+
* calling the `sizeCalculation` function and just use the specified
|
| 868 |
+
* number if it is a positive integer, and `noDisposeOnSet` which
|
| 869 |
+
* will prevent calling a `dispose` function in the case of
|
| 870 |
+
* overwrites.
|
| 871 |
+
*
|
| 872 |
+
* If the `size` (or return value of `sizeCalculation`) for a given
|
| 873 |
+
* entry is greater than `maxEntrySize`, then the item will not be
|
| 874 |
+
* added to the cache.
|
| 875 |
+
*
|
| 876 |
+
* Will update the recency of the entry.
|
| 877 |
+
*
|
| 878 |
+
* If the value is `undefined`, then this is an alias for
|
| 879 |
+
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
| 880 |
+
*/
|
| 881 |
+
set(k, v, setOptions = {}) {
|
| 882 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = setOptions;
|
| 883 |
+
setOptions.status = status;
|
| 884 |
+
if (status) {
|
| 885 |
+
status.op = 'set';
|
| 886 |
+
status.key = k;
|
| 887 |
+
if (v !== undefined)
|
| 888 |
+
status.value = v;
|
| 889 |
+
status.cache = this;
|
| 890 |
+
}
|
| 891 |
+
const result = this.#set(k, v, setOptions);
|
| 892 |
+
if (status && diagnostics_channel_js_1.metrics.hasSubscribers) {
|
| 893 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 894 |
+
}
|
| 895 |
+
return result;
|
| 896 |
+
}
|
| 897 |
+
#set(k, v, setOptions, bf) {
|
| 898 |
+
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
|
| 899 |
+
const isBF = this.#isBackgroundFetch(v);
|
| 900 |
+
if (v === undefined) {
|
| 901 |
+
if (status)
|
| 902 |
+
status.set = 'deleted';
|
| 903 |
+
this.delete(k);
|
| 904 |
+
return this;
|
| 905 |
+
}
|
| 906 |
+
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
| 907 |
+
if (status && !isBF)
|
| 908 |
+
status.value = v;
|
| 909 |
+
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation, status);
|
| 910 |
+
// if the item doesn't fit, don't do anything
|
| 911 |
+
// NB: maxEntrySize set to maxSize by default
|
| 912 |
+
if (this.maxEntrySize && size > this.maxEntrySize) {
|
| 913 |
+
// have to delete, in case something is there already.
|
| 914 |
+
this.#delete(k, 'set');
|
| 915 |
+
if (status) {
|
| 916 |
+
status.set = 'miss';
|
| 917 |
+
status.maxEntrySizeExceeded = true;
|
| 918 |
+
}
|
| 919 |
+
return this;
|
| 920 |
+
}
|
| 921 |
+
let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
|
| 922 |
+
if (index === undefined) {
|
| 923 |
+
// addition
|
| 924 |
+
index = (this.#size === 0 ? this.#tail
|
| 925 |
+
: this.#free.length !== 0 ? this.#free.pop()
|
| 926 |
+
: this.#size === this.#max ? this.#evict(false)
|
| 927 |
+
: this.#size);
|
| 928 |
+
this.#keyList[index] = k;
|
| 929 |
+
this.#valList[index] = v;
|
| 930 |
+
this.#keyMap.set(k, index);
|
| 931 |
+
this.#next[this.#tail] = index;
|
| 932 |
+
this.#prev[index] = this.#tail;
|
| 933 |
+
this.#tail = index;
|
| 934 |
+
this.#size++;
|
| 935 |
+
this.#addItemSize(index, size, status);
|
| 936 |
+
if (status)
|
| 937 |
+
status.set = 'add';
|
| 938 |
+
noUpdateTTL = false;
|
| 939 |
+
if (this.#hasOnInsert && !isBF) {
|
| 940 |
+
this.#onInsert?.(v, k, 'add');
|
| 941 |
+
}
|
| 942 |
+
}
|
| 943 |
+
else {
|
| 944 |
+
// update
|
| 945 |
+
// might be updating a background fetch!
|
| 946 |
+
this.#moveToTail(index);
|
| 947 |
+
const oldVal = this.#valList[index];
|
| 948 |
+
if (v !== oldVal) {
|
| 949 |
+
if (!noDisposeOnSet) {
|
| 950 |
+
if (this.#isBackgroundFetch(oldVal)) {
|
| 951 |
+
if (oldVal !== bf) {
|
| 952 |
+
// setting over a background fetch, not merely resolving it.
|
| 953 |
+
oldVal.__abortController.abort(new Error('replaced'));
|
| 954 |
+
}
|
| 955 |
+
const { __staleWhileFetching: s } = oldVal;
|
| 956 |
+
if (s !== undefined && s !== v) {
|
| 957 |
+
if (this.#hasDispose) {
|
| 958 |
+
this.#dispose?.(s, k, 'set');
|
| 959 |
+
}
|
| 960 |
+
if (this.#hasDisposeAfter) {
|
| 961 |
+
this.#disposed?.push([s, k, 'set']);
|
| 962 |
+
}
|
| 963 |
+
}
|
| 964 |
+
}
|
| 965 |
+
else {
|
| 966 |
+
if (this.#hasDispose) {
|
| 967 |
+
this.#dispose?.(oldVal, k, 'set');
|
| 968 |
+
}
|
| 969 |
+
if (this.#hasDisposeAfter) {
|
| 970 |
+
this.#disposed?.push([oldVal, k, 'set']);
|
| 971 |
+
}
|
| 972 |
+
}
|
| 973 |
+
}
|
| 974 |
+
this.#removeItemSize(index);
|
| 975 |
+
this.#addItemSize(index, size, status);
|
| 976 |
+
this.#valList[index] = v;
|
| 977 |
+
if (!isBF) {
|
| 978 |
+
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ?
|
| 979 |
+
oldVal.__staleWhileFetching
|
| 980 |
+
: oldVal;
|
| 981 |
+
const setType = oldValue === undefined ? 'add'
|
| 982 |
+
: v !== oldValue ? 'replace'
|
| 983 |
+
: 'update';
|
| 984 |
+
if (status) {
|
| 985 |
+
status.set = setType;
|
| 986 |
+
if (oldValue !== undefined)
|
| 987 |
+
status.oldValue = oldValue;
|
| 988 |
+
}
|
| 989 |
+
if (this.#hasOnInsert) {
|
| 990 |
+
this.onInsert?.(v, k, setType);
|
| 991 |
+
}
|
| 992 |
+
}
|
| 993 |
+
}
|
| 994 |
+
else if (!isBF) {
|
| 995 |
+
if (status) {
|
| 996 |
+
status.set = 'update';
|
| 997 |
+
}
|
| 998 |
+
if (this.#hasOnInsert) {
|
| 999 |
+
this.onInsert?.(v, k, 'update');
|
| 1000 |
+
}
|
| 1001 |
+
}
|
| 1002 |
+
}
|
| 1003 |
+
if (ttl !== 0 && !this.#ttls) {
|
| 1004 |
+
this.#initializeTTLTracking();
|
| 1005 |
+
}
|
| 1006 |
+
if (this.#ttls) {
|
| 1007 |
+
if (!noUpdateTTL) {
|
| 1008 |
+
this.#setItemTTL(index, ttl, start);
|
| 1009 |
+
}
|
| 1010 |
+
if (status)
|
| 1011 |
+
this.#statusTTL(status, index);
|
| 1012 |
+
}
|
| 1013 |
+
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
| 1014 |
+
const dt = this.#disposed;
|
| 1015 |
+
let task;
|
| 1016 |
+
while ((task = dt?.shift())) {
|
| 1017 |
+
this.#disposeAfter?.(...task);
|
| 1018 |
+
}
|
| 1019 |
+
}
|
| 1020 |
+
return this;
|
| 1021 |
+
}
|
| 1022 |
+
/**
|
| 1023 |
+
* Evict the least recently used item, returning its value or
|
| 1024 |
+
* `undefined` if cache is empty.
|
| 1025 |
+
*/
|
| 1026 |
+
pop() {
|
| 1027 |
+
try {
|
| 1028 |
+
while (this.#size) {
|
| 1029 |
+
const val = this.#valList[this.#head];
|
| 1030 |
+
this.#evict(true);
|
| 1031 |
+
if (this.#isBackgroundFetch(val)) {
|
| 1032 |
+
if (val.__staleWhileFetching) {
|
| 1033 |
+
return val.__staleWhileFetching;
|
| 1034 |
+
}
|
| 1035 |
+
}
|
| 1036 |
+
else if (val !== undefined) {
|
| 1037 |
+
return val;
|
| 1038 |
+
}
|
| 1039 |
+
}
|
| 1040 |
+
}
|
| 1041 |
+
finally {
|
| 1042 |
+
if (this.#hasDisposeAfter && this.#disposed) {
|
| 1043 |
+
const dt = this.#disposed;
|
| 1044 |
+
let task;
|
| 1045 |
+
while ((task = dt?.shift())) {
|
| 1046 |
+
this.#disposeAfter?.(...task);
|
| 1047 |
+
}
|
| 1048 |
+
}
|
| 1049 |
+
}
|
| 1050 |
+
}
|
| 1051 |
+
#evict(free) {
|
| 1052 |
+
const head = this.#head;
|
| 1053 |
+
const k = this.#keyList[head];
|
| 1054 |
+
const v = this.#valList[head];
|
| 1055 |
+
const isBF = this.#isBackgroundFetch(v);
|
| 1056 |
+
if (isBF) {
|
| 1057 |
+
v.__abortController.abort(new Error('evicted'));
|
| 1058 |
+
}
|
| 1059 |
+
const oldValue = isBF ? v.__staleWhileFetching : v;
|
| 1060 |
+
if ((this.#hasDispose || this.#hasDisposeAfter) &&
|
| 1061 |
+
oldValue !== undefined) {
|
| 1062 |
+
if (this.#hasDispose) {
|
| 1063 |
+
this.#dispose?.(oldValue, k, 'evict');
|
| 1064 |
+
}
|
| 1065 |
+
if (this.#hasDisposeAfter) {
|
| 1066 |
+
this.#disposed?.push([oldValue, k, 'evict']);
|
| 1067 |
+
}
|
| 1068 |
+
}
|
| 1069 |
+
this.#removeItemSize(head);
|
| 1070 |
+
if (this.#autopurgeTimers?.[head]) {
|
| 1071 |
+
clearTimeout(this.#autopurgeTimers[head]);
|
| 1072 |
+
this.#autopurgeTimers[head] = undefined;
|
| 1073 |
+
}
|
| 1074 |
+
// if we aren't about to use the index, then null these out
|
| 1075 |
+
if (free) {
|
| 1076 |
+
this.#keyList[head] = undefined;
|
| 1077 |
+
this.#valList[head] = undefined;
|
| 1078 |
+
this.#free.push(head);
|
| 1079 |
+
}
|
| 1080 |
+
if (this.#size === 1) {
|
| 1081 |
+
this.#head = this.#tail = 0;
|
| 1082 |
+
this.#free.length = 0;
|
| 1083 |
+
}
|
| 1084 |
+
else {
|
| 1085 |
+
this.#head = this.#next[head];
|
| 1086 |
+
}
|
| 1087 |
+
this.#keyMap.delete(k);
|
| 1088 |
+
this.#size--;
|
| 1089 |
+
return head;
|
| 1090 |
+
}
|
| 1091 |
+
/**
|
| 1092 |
+
* Check if a key is in the cache, without updating the recency of use.
|
| 1093 |
+
* Will return false if the item is stale, even though it is technically
|
| 1094 |
+
* in the cache.
|
| 1095 |
+
*
|
| 1096 |
+
* Check if a key is in the cache, without updating the recency of
|
| 1097 |
+
* use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
|
| 1098 |
+
* to `true` in either the options or the constructor.
|
| 1099 |
+
*
|
| 1100 |
+
* Will return `false` if the item is stale, even though it is technically in
|
| 1101 |
+
* the cache. The difference can be determined (if it matters) by using a
|
| 1102 |
+
* `status` argument, and inspecting the `has` field.
|
| 1103 |
+
*
|
| 1104 |
+
* Will not update item age unless
|
| 1105 |
+
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
| 1106 |
+
*/
|
| 1107 |
+
has(k, hasOptions = {}) {
|
| 1108 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = hasOptions;
|
| 1109 |
+
hasOptions.status = status;
|
| 1110 |
+
if (status) {
|
| 1111 |
+
status.op = 'has';
|
| 1112 |
+
status.key = k;
|
| 1113 |
+
status.cache = this;
|
| 1114 |
+
}
|
| 1115 |
+
const result = this.#has(k, hasOptions);
|
| 1116 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers)
|
| 1117 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1118 |
+
return result;
|
| 1119 |
+
}
|
| 1120 |
+
#has(k, hasOptions = {}) {
|
| 1121 |
+
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
| 1122 |
+
const index = this.#keyMap.get(k);
|
| 1123 |
+
if (index !== undefined) {
|
| 1124 |
+
const v = this.#valList[index];
|
| 1125 |
+
if (this.#isBackgroundFetch(v) &&
|
| 1126 |
+
v.__staleWhileFetching === undefined) {
|
| 1127 |
+
return false;
|
| 1128 |
+
}
|
| 1129 |
+
if (!this.#isStale(index)) {
|
| 1130 |
+
if (updateAgeOnHas) {
|
| 1131 |
+
this.#updateItemAge(index);
|
| 1132 |
+
}
|
| 1133 |
+
if (status) {
|
| 1134 |
+
status.has = 'hit';
|
| 1135 |
+
this.#statusTTL(status, index);
|
| 1136 |
+
}
|
| 1137 |
+
return true;
|
| 1138 |
+
}
|
| 1139 |
+
else if (status) {
|
| 1140 |
+
status.has = 'stale';
|
| 1141 |
+
this.#statusTTL(status, index);
|
| 1142 |
+
}
|
| 1143 |
+
}
|
| 1144 |
+
else if (status) {
|
| 1145 |
+
status.has = 'miss';
|
| 1146 |
+
}
|
| 1147 |
+
return false;
|
| 1148 |
+
}
|
| 1149 |
+
/**
|
| 1150 |
+
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
| 1151 |
+
* items.
|
| 1152 |
+
*
|
| 1153 |
+
* Returns `undefined` if the item is stale, unless
|
| 1154 |
+
* {@link LRUCache.OptionsBase.allowStale} is set.
|
| 1155 |
+
*/
|
| 1156 |
+
peek(k, peekOptions = {}) {
|
| 1157 |
+
const { status = hasSubscribers() ? {} : undefined } = peekOptions;
|
| 1158 |
+
if (status) {
|
| 1159 |
+
status.op = 'peek';
|
| 1160 |
+
status.key = k;
|
| 1161 |
+
status.cache = this;
|
| 1162 |
+
}
|
| 1163 |
+
peekOptions.status = status;
|
| 1164 |
+
const result = this.#peek(k, peekOptions);
|
| 1165 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers) {
|
| 1166 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1167 |
+
}
|
| 1168 |
+
return result;
|
| 1169 |
+
}
|
| 1170 |
+
#peek(k, peekOptions) {
|
| 1171 |
+
const { status, allowStale = this.allowStale } = peekOptions;
|
| 1172 |
+
const index = this.#keyMap.get(k);
|
| 1173 |
+
if (index === undefined || (!allowStale && this.#isStale(index))) {
|
| 1174 |
+
if (status)
|
| 1175 |
+
status.peek = index === undefined ? 'miss' : 'stale';
|
| 1176 |
+
return undefined;
|
| 1177 |
+
}
|
| 1178 |
+
const v = this.#valList[index];
|
| 1179 |
+
const val = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
| 1180 |
+
if (status) {
|
| 1181 |
+
if (val !== undefined) {
|
| 1182 |
+
status.peek = 'hit';
|
| 1183 |
+
status.value = val;
|
| 1184 |
+
}
|
| 1185 |
+
else {
|
| 1186 |
+
status.peek = 'miss';
|
| 1187 |
+
}
|
| 1188 |
+
}
|
| 1189 |
+
return val;
|
| 1190 |
+
}
|
| 1191 |
+
#backgroundFetch(k, index, options, context) {
|
| 1192 |
+
const v = index === undefined ? undefined : this.#valList[index];
|
| 1193 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1194 |
+
return v;
|
| 1195 |
+
}
|
| 1196 |
+
const ac = new AbortController();
|
| 1197 |
+
const { signal } = options;
|
| 1198 |
+
// when/if our AC signals, then stop listening to theirs.
|
| 1199 |
+
signal?.addEventListener('abort', () => ac.abort(signal.reason), {
|
| 1200 |
+
signal: ac.signal,
|
| 1201 |
+
});
|
| 1202 |
+
const fetchOpts = {
|
| 1203 |
+
signal: ac.signal,
|
| 1204 |
+
options,
|
| 1205 |
+
context,
|
| 1206 |
+
};
|
| 1207 |
+
const cb = (v, updateCache = false) => {
|
| 1208 |
+
const { aborted } = ac.signal;
|
| 1209 |
+
const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
|
| 1210 |
+
const proceed = options.ignoreFetchAbort ||
|
| 1211 |
+
!!(options.allowStaleOnFetchAbort && v !== undefined);
|
| 1212 |
+
if (options.status) {
|
| 1213 |
+
if (aborted && !updateCache) {
|
| 1214 |
+
options.status.fetchAborted = true;
|
| 1215 |
+
options.status.fetchError = ac.signal.reason;
|
| 1216 |
+
if (ignoreAbort)
|
| 1217 |
+
options.status.fetchAbortIgnored = true;
|
| 1218 |
+
}
|
| 1219 |
+
else {
|
| 1220 |
+
options.status.fetchResolved = true;
|
| 1221 |
+
}
|
| 1222 |
+
}
|
| 1223 |
+
if (aborted && !ignoreAbort && !updateCache) {
|
| 1224 |
+
return fetchFail(ac.signal.reason, proceed);
|
| 1225 |
+
}
|
| 1226 |
+
// either we didn't abort, and are still here, or we did, and ignored
|
| 1227 |
+
const bf = p;
|
| 1228 |
+
// if nothing else has been written there but we're set to update the
|
| 1229 |
+
// cache and ignore the abort, or if it's still pending on this specific
|
| 1230 |
+
// background request, then write it to the cache.
|
| 1231 |
+
const vl = this.#valList[index];
|
| 1232 |
+
if (vl === p || (vl === undefined && ignoreAbort && updateCache)) {
|
| 1233 |
+
if (v === undefined) {
|
| 1234 |
+
if (bf.__staleWhileFetching !== undefined) {
|
| 1235 |
+
this.#valList[index] = bf.__staleWhileFetching;
|
| 1236 |
+
}
|
| 1237 |
+
else {
|
| 1238 |
+
this.#delete(k, 'fetch');
|
| 1239 |
+
}
|
| 1240 |
+
}
|
| 1241 |
+
else {
|
| 1242 |
+
if (options.status)
|
| 1243 |
+
options.status.fetchUpdated = true;
|
| 1244 |
+
this.#set(k, v, fetchOpts.options, bf);
|
| 1245 |
+
}
|
| 1246 |
+
}
|
| 1247 |
+
return v;
|
| 1248 |
+
};
|
| 1249 |
+
const eb = (er) => {
|
| 1250 |
+
if (options.status) {
|
| 1251 |
+
options.status.fetchRejected = true;
|
| 1252 |
+
options.status.fetchError = er;
|
| 1253 |
+
}
|
| 1254 |
+
// do not pass go, do not collect $200
|
| 1255 |
+
return fetchFail(er, false);
|
| 1256 |
+
};
|
| 1257 |
+
const fetchFail = (er, proceed) => {
|
| 1258 |
+
const { aborted } = ac.signal;
|
| 1259 |
+
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
| 1260 |
+
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
| 1261 |
+
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
| 1262 |
+
const bf = p;
|
| 1263 |
+
if (this.#valList[index] === p) {
|
| 1264 |
+
// if we allow stale on fetch rejections, then we need to ensure that
|
| 1265 |
+
// the stale value is not removed from the cache when the fetch fails.
|
| 1266 |
+
const del = !noDelete || (!proceed && bf.__staleWhileFetching === undefined);
|
| 1267 |
+
if (del) {
|
| 1268 |
+
this.#delete(k, 'fetch');
|
| 1269 |
+
}
|
| 1270 |
+
else if (!allowStaleAborted) {
|
| 1271 |
+
// still replace the *promise* with the stale value,
|
| 1272 |
+
// since we are done with the promise at this point.
|
| 1273 |
+
// leave it untouched if we're still waiting for an
|
| 1274 |
+
// aborted background fetch that hasn't yet returned.
|
| 1275 |
+
this.#valList[index] = bf.__staleWhileFetching;
|
| 1276 |
+
}
|
| 1277 |
+
}
|
| 1278 |
+
if (allowStale) {
|
| 1279 |
+
if (options.status && bf.__staleWhileFetching !== undefined) {
|
| 1280 |
+
options.status.returnedStale = true;
|
| 1281 |
+
}
|
| 1282 |
+
return bf.__staleWhileFetching;
|
| 1283 |
+
}
|
| 1284 |
+
else if (bf.__returned === bf) {
|
| 1285 |
+
throw er;
|
| 1286 |
+
}
|
| 1287 |
+
};
|
| 1288 |
+
const pcall = (res, rej) => {
|
| 1289 |
+
const fmp = this.#fetchMethod?.(k, v, fetchOpts);
|
| 1290 |
+
// ignored, we go until we finish, regardless.
|
| 1291 |
+
// defer check until we are actually aborting,
|
| 1292 |
+
// so fetchMethod can override.
|
| 1293 |
+
ac.signal.addEventListener('abort', () => {
|
| 1294 |
+
if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
|
| 1295 |
+
res(undefined);
|
| 1296 |
+
// when it eventually resolves, update the cache.
|
| 1297 |
+
if (options.allowStaleOnFetchAbort) {
|
| 1298 |
+
res = v => cb(v, true);
|
| 1299 |
+
}
|
| 1300 |
+
}
|
| 1301 |
+
});
|
| 1302 |
+
if (fmp && fmp instanceof Promise) {
|
| 1303 |
+
fmp.then(v => res(v === undefined ? undefined : v), rej);
|
| 1304 |
+
}
|
| 1305 |
+
else if (fmp !== undefined) {
|
| 1306 |
+
res(fmp);
|
| 1307 |
+
}
|
| 1308 |
+
};
|
| 1309 |
+
if (options.status)
|
| 1310 |
+
options.status.fetchDispatched = true;
|
| 1311 |
+
const p = new Promise(pcall).then(cb, eb);
|
| 1312 |
+
const bf = Object.assign(p, {
|
| 1313 |
+
__abortController: ac,
|
| 1314 |
+
__staleWhileFetching: v,
|
| 1315 |
+
__returned: undefined,
|
| 1316 |
+
});
|
| 1317 |
+
if (index === undefined) {
|
| 1318 |
+
// internal, don't expose status.
|
| 1319 |
+
this.#set(k, bf, { ...fetchOpts.options, status: undefined });
|
| 1320 |
+
index = this.#keyMap.get(k);
|
| 1321 |
+
}
|
| 1322 |
+
else {
|
| 1323 |
+
// do not call #set, because we do not want to adjust its place
|
| 1324 |
+
// in the lru queue, as it has not yet been "used". Also, we don't
|
| 1325 |
+
// need to worry about evicting for size, because a background fetch
|
| 1326 |
+
// over a stale value is treated as the same size as its stale value.
|
| 1327 |
+
this.#valList[index] = bf;
|
| 1328 |
+
}
|
| 1329 |
+
return bf;
|
| 1330 |
+
}
|
| 1331 |
+
#isBackgroundFetch(p) {
|
| 1332 |
+
if (!this.#hasFetchMethod)
|
| 1333 |
+
return false;
|
| 1334 |
+
const b = p;
|
| 1335 |
+
return (!!b &&
|
| 1336 |
+
b instanceof Promise &&
|
| 1337 |
+
b.hasOwnProperty('__staleWhileFetching') &&
|
| 1338 |
+
b.__abortController instanceof AbortController);
|
| 1339 |
+
}
|
| 1340 |
+
fetch(k, fetchOptions = {}) {
|
| 1341 |
+
const ths = diagnostics_channel_js_1.tracing.hasSubscribers;
|
| 1342 |
+
const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
|
| 1343 |
+
fetchOptions.status = status;
|
| 1344 |
+
if (status && fetchOptions.context) {
|
| 1345 |
+
status.context = fetchOptions.context;
|
| 1346 |
+
}
|
| 1347 |
+
const p = this.#fetch(k, fetchOptions);
|
| 1348 |
+
if (status && ths) {
|
| 1349 |
+
status.trace = true;
|
| 1350 |
+
diagnostics_channel_js_1.tracing.tracePromise(() => p, status).catch(() => { });
|
| 1351 |
+
}
|
| 1352 |
+
return p;
|
| 1353 |
+
}
|
| 1354 |
+
async #fetch(k, fetchOptions = {}) {
|
| 1355 |
+
const {
|
| 1356 |
+
// get options
|
| 1357 |
+
allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
| 1358 |
+
// set options
|
| 1359 |
+
ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
|
| 1360 |
+
// fetch exclusive options
|
| 1361 |
+
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
|
| 1362 |
+
if (status) {
|
| 1363 |
+
status.op = 'fetch';
|
| 1364 |
+
status.key = k;
|
| 1365 |
+
if (forceRefresh)
|
| 1366 |
+
status.forceRefresh = true;
|
| 1367 |
+
status.cache = this;
|
| 1368 |
+
}
|
| 1369 |
+
if (!this.#hasFetchMethod) {
|
| 1370 |
+
if (status)
|
| 1371 |
+
status.fetch = 'get';
|
| 1372 |
+
return this.#get(k, {
|
| 1373 |
+
allowStale,
|
| 1374 |
+
updateAgeOnGet,
|
| 1375 |
+
noDeleteOnStaleGet,
|
| 1376 |
+
status,
|
| 1377 |
+
});
|
| 1378 |
+
}
|
| 1379 |
+
const options = {
|
| 1380 |
+
allowStale,
|
| 1381 |
+
updateAgeOnGet,
|
| 1382 |
+
noDeleteOnStaleGet,
|
| 1383 |
+
ttl,
|
| 1384 |
+
noDisposeOnSet,
|
| 1385 |
+
size,
|
| 1386 |
+
sizeCalculation,
|
| 1387 |
+
noUpdateTTL,
|
| 1388 |
+
noDeleteOnFetchRejection,
|
| 1389 |
+
allowStaleOnFetchRejection,
|
| 1390 |
+
allowStaleOnFetchAbort,
|
| 1391 |
+
ignoreFetchAbort,
|
| 1392 |
+
status,
|
| 1393 |
+
signal,
|
| 1394 |
+
};
|
| 1395 |
+
let index = this.#keyMap.get(k);
|
| 1396 |
+
if (index === undefined) {
|
| 1397 |
+
if (status)
|
| 1398 |
+
status.fetch = 'miss';
|
| 1399 |
+
const p = this.#backgroundFetch(k, index, options, context);
|
| 1400 |
+
return (p.__returned = p);
|
| 1401 |
+
}
|
| 1402 |
+
else {
|
| 1403 |
+
// in cache, maybe already fetching
|
| 1404 |
+
const v = this.#valList[index];
|
| 1405 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1406 |
+
const stale = allowStale && v.__staleWhileFetching !== undefined;
|
| 1407 |
+
if (status) {
|
| 1408 |
+
status.fetch = 'inflight';
|
| 1409 |
+
if (stale)
|
| 1410 |
+
status.returnedStale = true;
|
| 1411 |
+
}
|
| 1412 |
+
return stale ? v.__staleWhileFetching : (v.__returned = v);
|
| 1413 |
+
}
|
| 1414 |
+
// if we force a refresh, that means do NOT serve the cached value,
|
| 1415 |
+
// unless we are already in the process of refreshing the cache.
|
| 1416 |
+
const isStale = this.#isStale(index);
|
| 1417 |
+
if (!forceRefresh && !isStale) {
|
| 1418 |
+
if (status)
|
| 1419 |
+
status.fetch = 'hit';
|
| 1420 |
+
this.#moveToTail(index);
|
| 1421 |
+
if (updateAgeOnGet) {
|
| 1422 |
+
this.#updateItemAge(index);
|
| 1423 |
+
}
|
| 1424 |
+
if (status)
|
| 1425 |
+
this.#statusTTL(status, index);
|
| 1426 |
+
return v;
|
| 1427 |
+
}
|
| 1428 |
+
// ok, it is stale or a forced refresh, and not already fetching.
|
| 1429 |
+
// refresh the cache.
|
| 1430 |
+
const p = this.#backgroundFetch(k, index, options, context);
|
| 1431 |
+
const hasStale = p.__staleWhileFetching !== undefined;
|
| 1432 |
+
const staleVal = hasStale && allowStale;
|
| 1433 |
+
if (status) {
|
| 1434 |
+
status.fetch = isStale ? 'stale' : 'refresh';
|
| 1435 |
+
if (staleVal && isStale)
|
| 1436 |
+
status.returnedStale = true;
|
| 1437 |
+
}
|
| 1438 |
+
return staleVal ? p.__staleWhileFetching : (p.__returned = p);
|
| 1439 |
+
}
|
| 1440 |
+
}
|
| 1441 |
+
forceFetch(k, fetchOptions = {}) {
|
| 1442 |
+
const ths = diagnostics_channel_js_1.tracing.hasSubscribers;
|
| 1443 |
+
const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
|
| 1444 |
+
fetchOptions.status = status;
|
| 1445 |
+
if (status && fetchOptions.context) {
|
| 1446 |
+
status.context = fetchOptions.context;
|
| 1447 |
+
}
|
| 1448 |
+
const p = this.#forceFetch(k, fetchOptions);
|
| 1449 |
+
if (status && ths) {
|
| 1450 |
+
status.trace = true;
|
| 1451 |
+
diagnostics_channel_js_1.tracing.tracePromise(() => p, status).catch(() => { });
|
| 1452 |
+
}
|
| 1453 |
+
return p;
|
| 1454 |
+
}
|
| 1455 |
+
async #forceFetch(k, fetchOptions = {}) {
|
| 1456 |
+
const v = await this.#fetch(k, fetchOptions);
|
| 1457 |
+
if (v === undefined)
|
| 1458 |
+
throw new Error('fetch() returned undefined');
|
| 1459 |
+
return v;
|
| 1460 |
+
}
|
| 1461 |
+
memo(k, memoOptions = {}) {
|
| 1462 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = memoOptions;
|
| 1463 |
+
memoOptions.status = status;
|
| 1464 |
+
if (status) {
|
| 1465 |
+
status.op = 'memo';
|
| 1466 |
+
status.key = k;
|
| 1467 |
+
if (memoOptions.context) {
|
| 1468 |
+
status.context = memoOptions.context;
|
| 1469 |
+
}
|
| 1470 |
+
status.cache = this;
|
| 1471 |
+
}
|
| 1472 |
+
const result = this.#memo(k, memoOptions);
|
| 1473 |
+
if (status)
|
| 1474 |
+
status.value = result;
|
| 1475 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers)
|
| 1476 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1477 |
+
return result;
|
| 1478 |
+
}
|
| 1479 |
+
#memo(k, memoOptions = {}) {
|
| 1480 |
+
const memoMethod = this.#memoMethod;
|
| 1481 |
+
if (!memoMethod) {
|
| 1482 |
+
throw new Error('no memoMethod provided to constructor');
|
| 1483 |
+
}
|
| 1484 |
+
const { context, status, forceRefresh, ...options } = memoOptions;
|
| 1485 |
+
if (status && forceRefresh)
|
| 1486 |
+
status.forceRefresh = true;
|
| 1487 |
+
const v = this.#get(k, options);
|
| 1488 |
+
const refresh = forceRefresh || v === undefined;
|
| 1489 |
+
if (status) {
|
| 1490 |
+
status.memo = refresh ? 'miss' : 'hit';
|
| 1491 |
+
if (!refresh)
|
| 1492 |
+
status.value = v;
|
| 1493 |
+
}
|
| 1494 |
+
if (!refresh)
|
| 1495 |
+
return v;
|
| 1496 |
+
const vv = memoMethod(k, v, {
|
| 1497 |
+
options,
|
| 1498 |
+
context,
|
| 1499 |
+
});
|
| 1500 |
+
if (status)
|
| 1501 |
+
status.value = vv;
|
| 1502 |
+
this.#set(k, vv, options);
|
| 1503 |
+
return vv;
|
| 1504 |
+
}
|
| 1505 |
+
/**
|
| 1506 |
+
* Return a value from the cache. Will update the recency of the cache
|
| 1507 |
+
* entry found.
|
| 1508 |
+
*
|
| 1509 |
+
* If the key is not found, get() will return `undefined`.
|
| 1510 |
+
*/
|
| 1511 |
+
get(k, getOptions = {}) {
|
| 1512 |
+
const { status = diagnostics_channel_js_1.metrics.hasSubscribers ? {} : undefined } = getOptions;
|
| 1513 |
+
getOptions.status = status;
|
| 1514 |
+
if (status) {
|
| 1515 |
+
status.op = 'get';
|
| 1516 |
+
status.key = k;
|
| 1517 |
+
status.cache = this;
|
| 1518 |
+
}
|
| 1519 |
+
const result = this.#get(k, getOptions);
|
| 1520 |
+
if (status) {
|
| 1521 |
+
if (result !== undefined)
|
| 1522 |
+
status.value = result;
|
| 1523 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers)
|
| 1524 |
+
diagnostics_channel_js_1.metrics.publish(status);
|
| 1525 |
+
}
|
| 1526 |
+
return result;
|
| 1527 |
+
}
|
| 1528 |
+
#get(k, getOptions = {}) {
|
| 1529 |
+
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
|
| 1530 |
+
const index = this.#keyMap.get(k);
|
| 1531 |
+
if (index === undefined) {
|
| 1532 |
+
if (status)
|
| 1533 |
+
status.get = 'miss';
|
| 1534 |
+
return undefined;
|
| 1535 |
+
}
|
| 1536 |
+
const value = this.#valList[index];
|
| 1537 |
+
const fetching = this.#isBackgroundFetch(value);
|
| 1538 |
+
if (status)
|
| 1539 |
+
this.#statusTTL(status, index);
|
| 1540 |
+
if (this.#isStale(index)) {
|
| 1541 |
+
// delete only if not an in-flight background fetch
|
| 1542 |
+
if (!fetching) {
|
| 1543 |
+
if (!noDeleteOnStaleGet) {
|
| 1544 |
+
this.#delete(k, 'expire');
|
| 1545 |
+
}
|
| 1546 |
+
if (status)
|
| 1547 |
+
status.get = 'stale';
|
| 1548 |
+
if (allowStale) {
|
| 1549 |
+
if (status)
|
| 1550 |
+
status.returnedStale = true;
|
| 1551 |
+
return value;
|
| 1552 |
+
}
|
| 1553 |
+
return undefined;
|
| 1554 |
+
}
|
| 1555 |
+
if (status)
|
| 1556 |
+
status.get = 'stale-fetching';
|
| 1557 |
+
if (allowStale && value.__staleWhileFetching !== undefined) {
|
| 1558 |
+
if (status)
|
| 1559 |
+
status.returnedStale = true;
|
| 1560 |
+
return value.__staleWhileFetching;
|
| 1561 |
+
}
|
| 1562 |
+
return undefined;
|
| 1563 |
+
}
|
| 1564 |
+
// not stale
|
| 1565 |
+
if (status)
|
| 1566 |
+
status.get = fetching ? 'fetching' : 'hit';
|
| 1567 |
+
// if we're currently fetching it, we don't actually have it yet
|
| 1568 |
+
// it's not stale, which means this isn't a staleWhileRefetching.
|
| 1569 |
+
// If it's not stale, and fetching, AND has a __staleWhileFetching
|
| 1570 |
+
// value, then that means the user fetched with {forceRefresh:true},
|
| 1571 |
+
// so it's safe to return that value.
|
| 1572 |
+
this.#moveToTail(index);
|
| 1573 |
+
if (updateAgeOnGet) {
|
| 1574 |
+
this.#updateItemAge(index);
|
| 1575 |
+
}
|
| 1576 |
+
return fetching ? value.__staleWhileFetching : value;
|
| 1577 |
+
}
|
| 1578 |
+
#connect(p, n) {
|
| 1579 |
+
this.#prev[n] = p;
|
| 1580 |
+
this.#next[p] = n;
|
| 1581 |
+
}
|
| 1582 |
+
#moveToTail(index) {
|
| 1583 |
+
// if tail already, nothing to do
|
| 1584 |
+
// if head, move head to next[index]
|
| 1585 |
+
// else
|
| 1586 |
+
// move next[prev[index]] to next[index] (head has no prev)
|
| 1587 |
+
// move prev[next[index]] to prev[index]
|
| 1588 |
+
// prev[index] = tail
|
| 1589 |
+
// next[tail] = index
|
| 1590 |
+
// tail = index
|
| 1591 |
+
if (index !== this.#tail) {
|
| 1592 |
+
if (index === this.#head) {
|
| 1593 |
+
this.#head = this.#next[index];
|
| 1594 |
+
}
|
| 1595 |
+
else {
|
| 1596 |
+
this.#connect(this.#prev[index], this.#next[index]);
|
| 1597 |
+
}
|
| 1598 |
+
this.#connect(this.#tail, index);
|
| 1599 |
+
this.#tail = index;
|
| 1600 |
+
}
|
| 1601 |
+
}
|
| 1602 |
+
/**
|
| 1603 |
+
* Deletes a key out of the cache.
|
| 1604 |
+
*
|
| 1605 |
+
* Returns true if the key was deleted, false otherwise.
|
| 1606 |
+
*/
|
| 1607 |
+
delete(k) {
|
| 1608 |
+
return this.#delete(k, 'delete');
|
| 1609 |
+
}
|
| 1610 |
+
#delete(k, reason) {
|
| 1611 |
+
if (diagnostics_channel_js_1.metrics.hasSubscribers) {
|
| 1612 |
+
diagnostics_channel_js_1.metrics.publish({
|
| 1613 |
+
op: 'delete',
|
| 1614 |
+
delete: reason,
|
| 1615 |
+
key: k,
|
| 1616 |
+
cache: this,
|
| 1617 |
+
});
|
| 1618 |
+
}
|
| 1619 |
+
let deleted = false;
|
| 1620 |
+
if (this.#size !== 0) {
|
| 1621 |
+
const index = this.#keyMap.get(k);
|
| 1622 |
+
if (index !== undefined) {
|
| 1623 |
+
if (this.#autopurgeTimers?.[index]) {
|
| 1624 |
+
clearTimeout(this.#autopurgeTimers?.[index]);
|
| 1625 |
+
this.#autopurgeTimers[index] = undefined;
|
| 1626 |
+
}
|
| 1627 |
+
deleted = true;
|
| 1628 |
+
if (this.#size === 1) {
|
| 1629 |
+
this.#clear(reason);
|
| 1630 |
+
}
|
| 1631 |
+
else {
|
| 1632 |
+
this.#removeItemSize(index);
|
| 1633 |
+
const v = this.#valList[index];
|
| 1634 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1635 |
+
v.__abortController.abort(new Error('deleted'));
|
| 1636 |
+
}
|
| 1637 |
+
else if (this.#hasDispose || this.#hasDisposeAfter) {
|
| 1638 |
+
if (this.#hasDispose) {
|
| 1639 |
+
this.#dispose?.(v, k, reason);
|
| 1640 |
+
}
|
| 1641 |
+
if (this.#hasDisposeAfter) {
|
| 1642 |
+
this.#disposed?.push([v, k, reason]);
|
| 1643 |
+
}
|
| 1644 |
+
}
|
| 1645 |
+
this.#keyMap.delete(k);
|
| 1646 |
+
this.#keyList[index] = undefined;
|
| 1647 |
+
this.#valList[index] = undefined;
|
| 1648 |
+
if (index === this.#tail) {
|
| 1649 |
+
this.#tail = this.#prev[index];
|
| 1650 |
+
}
|
| 1651 |
+
else if (index === this.#head) {
|
| 1652 |
+
this.#head = this.#next[index];
|
| 1653 |
+
}
|
| 1654 |
+
else {
|
| 1655 |
+
const pi = this.#prev[index];
|
| 1656 |
+
this.#next[pi] = this.#next[index];
|
| 1657 |
+
const ni = this.#next[index];
|
| 1658 |
+
this.#prev[ni] = this.#prev[index];
|
| 1659 |
+
}
|
| 1660 |
+
this.#size--;
|
| 1661 |
+
this.#free.push(index);
|
| 1662 |
+
}
|
| 1663 |
+
}
|
| 1664 |
+
}
|
| 1665 |
+
if (this.#hasDisposeAfter && this.#disposed?.length) {
|
| 1666 |
+
const dt = this.#disposed;
|
| 1667 |
+
let task;
|
| 1668 |
+
while ((task = dt?.shift())) {
|
| 1669 |
+
this.#disposeAfter?.(...task);
|
| 1670 |
+
}
|
| 1671 |
+
}
|
| 1672 |
+
return deleted;
|
| 1673 |
+
}
|
| 1674 |
+
/**
|
| 1675 |
+
* Clear the cache entirely, throwing away all values.
|
| 1676 |
+
*/
|
| 1677 |
+
clear() {
|
| 1678 |
+
return this.#clear('delete');
|
| 1679 |
+
}
|
| 1680 |
+
#clear(reason) {
|
| 1681 |
+
for (const index of this.#rindexes({ allowStale: true })) {
|
| 1682 |
+
const v = this.#valList[index];
|
| 1683 |
+
if (this.#isBackgroundFetch(v)) {
|
| 1684 |
+
v.__abortController.abort(new Error('deleted'));
|
| 1685 |
+
}
|
| 1686 |
+
else {
|
| 1687 |
+
const k = this.#keyList[index];
|
| 1688 |
+
if (this.#hasDispose) {
|
| 1689 |
+
this.#dispose?.(v, k, reason);
|
| 1690 |
+
}
|
| 1691 |
+
if (this.#hasDisposeAfter) {
|
| 1692 |
+
this.#disposed?.push([v, k, reason]);
|
| 1693 |
+
}
|
| 1694 |
+
}
|
| 1695 |
+
}
|
| 1696 |
+
this.#keyMap.clear();
|
| 1697 |
+
void this.#valList.fill(undefined);
|
| 1698 |
+
this.#keyList.fill(undefined);
|
| 1699 |
+
if (this.#ttls && this.#starts) {
|
| 1700 |
+
this.#ttls.fill(0);
|
| 1701 |
+
this.#starts.fill(0);
|
| 1702 |
+
for (const t of this.#autopurgeTimers ?? []) {
|
| 1703 |
+
if (t !== undefined)
|
| 1704 |
+
clearTimeout(t);
|
| 1705 |
+
}
|
| 1706 |
+
this.#autopurgeTimers?.fill(undefined);
|
| 1707 |
+
}
|
| 1708 |
+
if (this.#sizes) {
|
| 1709 |
+
this.#sizes.fill(0);
|
| 1710 |
+
}
|
| 1711 |
+
this.#head = 0;
|
| 1712 |
+
this.#tail = 0;
|
| 1713 |
+
this.#free.length = 0;
|
| 1714 |
+
this.#calculatedSize = 0;
|
| 1715 |
+
this.#size = 0;
|
| 1716 |
+
if (this.#hasDisposeAfter && this.#disposed) {
|
| 1717 |
+
const dt = this.#disposed;
|
| 1718 |
+
let task;
|
| 1719 |
+
while ((task = dt?.shift())) {
|
| 1720 |
+
this.#disposeAfter?.(...task);
|
| 1721 |
+
}
|
| 1722 |
+
}
|
| 1723 |
+
}
|
| 1724 |
+
}
|
| 1725 |
+
exports.LRUCache = LRUCache;
|
| 1726 |
+
//# sourceMappingURL=index.js.map
|
node_modules/lru-cache/dist/commonjs/index.js.map
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/lru-cache/dist/commonjs/index.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";var j=(c,t)=>()=>(t||c((t={exports:{}}).exports,t),t.exports);var I=j(O=>{"use strict";Object.defineProperty(O,"__esModule",{value:!0});O.tracing=O.metrics=void 0;var U={hasSubscribers:!1};O.metrics=U;O.tracing=U});var P=j(D=>{"use strict";Object.defineProperty(D,"__esModule",{value:!0});D.defaultPerf=void 0;D.defaultPerf=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date});Object.defineProperty(exports,"__esModule",{value:!0});exports.LRUCache=void 0;var g=I(),N=P(),x=()=>g.metrics.hasSubscribers||g.tracing.hasSubscribers,k=new Set,G=typeof process=="object"&&process?process:{},V=(c,t,e,i)=>{typeof G.emitWarning=="function"?G.emitWarning(c,t,e,i):console.error(`[${e}] ${t}: ${c}`)},B=c=>!k.has(c);var T=c=>!!c&&c===Math.floor(c)&&c>0&&isFinite(c),H=c=>T(c)?c<=Math.pow(2,8)?Uint8Array:c<=Math.pow(2,16)?Uint16Array:c<=Math.pow(2,32)?Uint32Array:c<=Number.MAX_SAFE_INTEGER?W:null:null,W=class extends Array{constructor(t){super(t),this.fill(0)}},C=class c{heap;length;static#o=!1;static create(t){let e=H(t);if(!e)return[];c.#o=!0;let i=new c(t,e);return c.#o=!1,i}constructor(t,e){if(!c.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},L=class c{#o;#c;#m;#W;#S;#M;#j;#w;get perf(){return this.#w}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;backgroundFetchSize;#n;#b;#s;#i;#t;#l;#u;#a;#h;#y;#r;#_;#F;#d;#g;#T;#U;#f;#D;static unsafeExposeInternals(t){return{starts:t.#F,ttls:t.#d,autopurgeTimers:t.#g,sizes:t.#_,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#l,prev:t.#u,get head(){return t.#a},get tail(){return t.#h},free:t.#y,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,n)=>t.#G(e,i,s,n),moveToTail:e=>t.#L(e),indexes:e=>t.#A(e),rindexes:e=>t.#z(e),isStale:e=>t.#p(e)}}get max(){return this.#o}get maxSize(){return this.#c}get calculatedSize(){return this.#b}get size(){return this.#n}get fetchMethod(){return this.#M}get memoMethod(){return this.#j}get dispose(){return this.#m}get onInsert(){return this.#W}get disposeAfter(){return this.#S}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:r,updateAgeOnHas:h,allowStale:a,dispose:o,onInsert:d,disposeAfter:y,noDisposeOnSet:_,noUpdateTTL:u,maxSize:p=0,maxEntrySize:f=0,sizeCalculation:b,fetchMethod:l,memoMethod:S,noDeleteOnFetchRejection:F,noDeleteOnStaleGet:w,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:A,ignoreFetchAbort:z,backgroundFetchSize:M=1,perf:v}=t;if(this.backgroundFetchSize=M,v!==void 0&&typeof v?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#w=v??N.defaultPerf,e!==0&&!T(e))throw new TypeError("max option must be a nonnegative integer");let E=e?H(e):Array;if(!E)throw new Error("invalid max value: "+e);if(this.#o=e,this.#c=p,this.maxEntrySize=f||this.#c,this.sizeCalculation=b,this.sizeCalculation){if(!this.#c&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(S!==void 0&&typeof S!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#j=S,l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#M=l,this.#U=!!l,this.#s=new Map,this.#i=Array.from({length:e}).fill(void 0),this.#t=Array.from({length:e}).fill(void 0),this.#l=new E(e),this.#u=new E(e),this.#a=0,this.#h=0,this.#y=C.create(e),this.#n=0,this.#b=0,typeof o=="function"&&(this.#m=o),typeof d=="function"&&(this.#W=d),typeof y=="function"?(this.#S=y,this.#r=[]):(this.#S=void 0,this.#r=void 0),this.#T=!!this.#m,this.#D=!!this.#W,this.#f=!!this.#S,this.noDisposeOnSet=!!_,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!F,this.allowStaleOnFetchRejection=!!m,this.allowStaleOnFetchAbort=!!A,this.ignoreFetchAbort=!!z,this.maxEntrySize!==0){if(this.#c!==0&&!T(this.#c))throw new TypeError("maxSize must be a positive integer if specified");if(!T(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#X()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!w,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!h,this.ttlResolution=T(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!T(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#k()}if(this.#o===0&&this.ttl===0&&this.#c===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#c){let R="LRU_CACHE_UNBOUNDED";B(R)&&(k.add(R),V("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",R,c))}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#k(){let t=new W(this.#o),e=new W(this.#o);this.#d=t,this.#F=e;let i=this.ttlAutopurge?Array.from({length:this.#o}):void 0;this.#g=i,this.#H=(h,a,o=this.#w.now())=>{e[h]=a!==0?o:0,t[h]=a,s(h,a)},this.#R=h=>{e[h]=t[h]!==0?this.#w.now():0,s(h,t[h])};let s=this.ttlAutopurge?(h,a)=>{if(i?.[h]&&(clearTimeout(i[h]),i[h]=void 0),a&&a!==0&&i){let o=setTimeout(()=>{this.#p(h)&&this.#v(this.#i[h],"expire")},a+1);o.unref&&o.unref(),i[h]=o}}:()=>{};this.#E=(h,a)=>{if(t[a]){let o=t[a],d=e[a];if(!o||!d)return;h.ttl=o,h.start=d,h.now=n||r();let y=h.now-d;h.remainingTTL=o-y}};let n=0,r=()=>{let h=this.#w.now();if(this.ttlResolution>0){n=h;let a=setTimeout(()=>n=0,this.ttlResolution);a.unref&&a.unref()}return h};this.getRemainingTTL=h=>{let a=this.#s.get(h);if(a===void 0)return 0;let o=t[a],d=e[a];if(!o||!d)return 1/0;let y=(n||r())-d;return o-y},this.#p=h=>{let a=e[h],o=t[h];return!!o&&!!a&&(n||r())-a>o}}#R=()=>{};#E=()=>{};#H=()=>{};#p=()=>!1;#X(){let t=new W(this.#o);this.#b=0,this.#_=t,this.#x=e=>{this.#b-=t[e],t[e]=0},this.#N=(e,i,s,n)=>{if(!T(s)){if(this.#e(i))return this.backgroundFetchSize;if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,e),!T(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.")}return s},this.#I=(e,i,s)=>{if(t[e]=i,this.#c){let n=this.#c-t[e];for(;this.#b>n;)this.#P(!0)}this.#b+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#b)}}#x=t=>{};#I=(t,e,i)=>{};#N=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;this.#V(e)&&((t||!this.#p(e))&&(yield e),e!==this.#a);)e=this.#u[e]}*#z({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#a;this.#V(e)&&((t||!this.#p(e))&&(yield e),e!==this.#h);)e=this.#l[e]}#V(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#A())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*rentries(){for(let t of this.#z())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*keys(){for(let t of this.#A()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*rkeys(){for(let t of this.#z()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*values(){for(let t of this.#A())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}*rvalues(){for(let t of this.#z())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&t(n,this.#i[i],this))return this.#C(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}rforEach(t,e=this){for(let i of this.#z()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}purgeStale(){let t=!1;for(let e of this.#z({allowStale:!0}))this.#p(e)&&(this.#v(this.#i[e],"expire"),t=!0);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#d&&this.#F){let r=this.#d[e],h=this.#F[e];if(r&&h){let a=r-(this.#w.now()-h);n.ttl=a,n.start=Date.now()}}return this.#_&&(n.size=this.#_[e]),n}dump(){let t=[];for(let e of this.#A({allowStale:!0})){let i=this.#i[e],s=this.#t[e],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let r={value:n};if(this.#d&&this.#F){r.ttl=this.#d[e];let h=this.#w.now()-this.#F[e];r.start=Math.floor(Date.now()-h)}this.#_&&(r.size=this.#_[e]),t.unshift([i,r])}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=this.#w.now()-s}this.#O(e,i.value,i)}}set(t,e,i={}){let{status:s=g.metrics.hasSubscribers?{}:void 0}=i;i.status=s,s&&(s.op="set",s.key=t,e!==void 0&&(s.value=e),s.cache=this);let n=this.#O(t,e,i);return s&&g.metrics.hasSubscribers&&g.metrics.publish(s),n}#O(t,e,i,s){let{ttl:n=this.ttl,start:r,noDisposeOnSet:h=this.noDisposeOnSet,sizeCalculation:a=this.sizeCalculation,status:o}=i,d=this.#e(e);if(e===void 0)return o&&(o.set="deleted"),this.delete(t),this;let{noUpdateTTL:y=this.noUpdateTTL}=i;o&&!d&&(o.value=e);let _=this.#N(t,e,i.size||0,a,o);if(this.maxEntrySize&&_>this.maxEntrySize)return this.#v(t,"set"),o&&(o.set="miss",o.maxEntrySizeExceeded=!0),this;let u=this.#n===0?void 0:this.#s.get(t);if(u===void 0)u=this.#n===0?this.#h:this.#y.length!==0?this.#y.pop():this.#n===this.#o?this.#P(!1):this.#n,this.#i[u]=t,this.#t[u]=e,this.#s.set(t,u),this.#l[this.#h]=u,this.#u[u]=this.#h,this.#h=u,this.#n++,this.#I(u,_,o),o&&(o.set="add"),y=!1,this.#D&&!d&&this.#W?.(e,t,"add");else{this.#L(u);let p=this.#t[u];if(e!==p){if(!h)if(this.#e(p)){p!==s&&p.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:f}=p;f!==void 0&&f!==e&&(this.#T&&this.#m?.(f,t,"set"),this.#f&&this.#r?.push([f,t,"set"]))}else this.#T&&this.#m?.(p,t,"set"),this.#f&&this.#r?.push([p,t,"set"]);if(this.#x(u),this.#I(u,_,o),this.#t[u]=e,!d){let f=p&&this.#e(p)?p.__staleWhileFetching:p,b=f===void 0?"add":e!==f?"replace":"update";o&&(o.set=b,f!==void 0&&(o.oldValue=f)),this.#D&&this.onInsert?.(e,t,b)}}else d||(o&&(o.set="update"),this.#D&&this.onInsert?.(e,t,"update"))}if(n!==0&&!this.#d&&this.#k(),this.#d&&(y||this.#H(u,n,r),o&&this.#E(o,u)),!h&&this.#f&&this.#r){let p=this.#r,f;for(;f=p?.shift();)this.#S?.(...f)}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#a];if(this.#P(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#f&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#S?.(...e)}}}#P(t){let e=this.#a,i=this.#i[e],s=this.#t[e],n=this.#e(s);n&&s.__abortController.abort(new Error("evicted"));let r=n?s.__staleWhileFetching:s;return(this.#T||this.#f)&&r!==void 0&&(this.#T&&this.#m?.(r,i,"evict"),this.#f&&this.#r?.push([r,i,"evict"])),this.#x(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.#y.push(e)),this.#n===1?(this.#a=this.#h=0,this.#y.length=0):this.#a=this.#l[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{status:i=g.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="has",i.key=t,i.cache=this);let s=this.#Y(t,e);return g.metrics.hasSubscribers&&g.metrics.publish(i),s}#Y(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#s.get(t);if(n!==void 0){let r=this.#t[n];if(this.#e(r)&&r.__staleWhileFetching===void 0)return!1;if(this.#p(n))s&&(s.has="stale",this.#E(s,n));else return i&&this.#R(n),s&&(s.has="hit",this.#E(s,n)),!0}else s&&(s.has="miss");return!1}peek(t,e={}){let{status:i=x()?{}:void 0}=e;i&&(i.op="peek",i.key=t,i.cache=this),e.status=i;let s=this.#J(t,e);return g.metrics.hasSubscribers&&g.metrics.publish(i),s}#J(t,e){let{status:i,allowStale:s=this.allowStale}=e,n=this.#s.get(t);if(n===void 0||!s&&this.#p(n)){i&&(i.peek=n===void 0?"miss":"stale");return}let r=this.#t[n],h=this.#e(r)?r.__staleWhileFetching:r;return i&&(h!==void 0?(i.peek="hit",i.value=h):i.peek="miss"),h}#G(t,e,i,s){let n=e===void 0?void 0:this.#t[e];if(this.#e(n))return n;let r=new AbortController,{signal:h}=i;h?.addEventListener("abort",()=>r.abort(h.reason),{signal:r.signal});let a={signal:r.signal,options:i,context:s},o=(f,b=!1)=>{let{aborted:l}=r.signal,S=i.ignoreFetchAbort&&f!==void 0,F=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&f!==void 0);if(i.status&&(l&&!b?(i.status.fetchAborted=!0,i.status.fetchError=r.signal.reason,S&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),l&&!S&&!b)return y(r.signal.reason,F);let w=u,m=this.#t[e];return(m===u||m===void 0&&S&&b)&&(f===void 0?w.__staleWhileFetching!==void 0?this.#t[e]=w.__staleWhileFetching:this.#v(t,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.#O(t,f,a.options,w))),f},d=f=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=f),y(f,!1)),y=(f,b)=>{let{aborted:l}=r.signal,S=l&&i.allowStaleOnFetchAbort,F=S||i.allowStaleOnFetchRejection,w=F||i.noDeleteOnFetchRejection,m=u;if(this.#t[e]===u&&(!w||!b&&m.__staleWhileFetching===void 0?this.#v(t,"fetch"):S||(this.#t[e]=m.__staleWhileFetching)),F)return i.status&&m.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),m.__staleWhileFetching;if(m.__returned===m)throw f},_=(f,b)=>{let l=this.#M?.(t,n,a);r.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(f(void 0),i.allowStaleOnFetchAbort&&(f=S=>o(S,!0)))}),l&&l instanceof Promise?l.then(S=>f(S===void 0?void 0:S),b):l!==void 0&&f(l)};i.status&&(i.status.fetchDispatched=!0);let u=new Promise(_).then(o,d),p=Object.assign(u,{__abortController:r,__staleWhileFetching:n,__returned:void 0});return e===void 0?(this.#O(t,p,{...a.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=p,p}#e(t){if(!this.#U)return!1;let e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof AbortController}fetch(t,e={}){let i=g.tracing.hasSubscribers,{status:s=x()?{}:void 0}=e;e.status=s,s&&e.context&&(s.context=e.context);let n=this.#B(t,e);return s&&i&&(s.trace=!0,g.tracing.tracePromise(()=>n,s).catch(()=>{})),n}async#B(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:r=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:a=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:d=this.noUpdateTTL,noDeleteOnFetchRejection:y=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:_=this.allowStaleOnFetchRejection,ignoreFetchAbort:u=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:f,forceRefresh:b=!1,status:l,signal:S}=e;if(l&&(l.op="fetch",l.key=t,b&&(l.forceRefresh=!0),l.cache=this),!this.#U)return l&&(l.fetch="get"),this.#C(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:l});let F={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:r,noDisposeOnSet:h,size:a,sizeCalculation:o,noUpdateTTL:d,noDeleteOnFetchRejection:y,allowStaleOnFetchRejection:_,allowStaleOnFetchAbort:p,ignoreFetchAbort:u,status:l,signal:S},w=this.#s.get(t);if(w===void 0){l&&(l.fetch="miss");let m=this.#G(t,w,F,f);return m.__returned=m}else{let m=this.#t[w];if(this.#e(m)){let E=i&&m.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",E&&(l.returnedStale=!0)),E?m.__staleWhileFetching:m.__returned=m}let A=this.#p(w);if(!b&&!A)return l&&(l.fetch="hit"),this.#L(w),s&&this.#R(w),l&&this.#E(l,w),m;let z=this.#G(t,w,F,f),v=z.__staleWhileFetching!==void 0&&i;return l&&(l.fetch=A?"stale":"refresh",v&&A&&(l.returnedStale=!0)),v?z.__staleWhileFetching:z.__returned=z}}forceFetch(t,e={}){let i=g.tracing.hasSubscribers,{status:s=x()?{}:void 0}=e;e.status=s,s&&e.context&&(s.context=e.context);let n=this.#K(t,e);return s&&i&&(s.trace=!0,g.tracing.tracePromise(()=>n,s).catch(()=>{})),n}async#K(t,e={}){let i=await this.#B(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let{status:i=g.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="memo",i.key=t,e.context&&(i.context=e.context),i.cache=this);let s=this.#Q(t,e);return i&&(i.value=s),g.metrics.hasSubscribers&&g.metrics.publish(i),s}#Q(t,e={}){let i=this.#j;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,status:n,forceRefresh:r,...h}=e;n&&r&&(n.forceRefresh=!0);let a=this.#C(t,h),o=r||a===void 0;if(n&&(n.memo=o?"miss":"hit",o||(n.value=a)),!o)return a;let d=i(t,a,{options:h,context:s});return n&&(n.value=d),this.#O(t,d,h),d}get(t,e={}){let{status:i=g.metrics.hasSubscribers?{}:void 0}=e;e.status=i,i&&(i.op="get",i.key=t,i.cache=this);let s=this.#C(t,e);return i&&(s!==void 0&&(i.value=s),g.metrics.hasSubscribers&&g.metrics.publish(i)),s}#C(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:r}=e,h=this.#s.get(t);if(h===void 0){r&&(r.get="miss");return}let a=this.#t[h],o=this.#e(a);return r&&this.#E(r,h),this.#p(h)?o?(r&&(r.get="stale-fetching"),i&&a.__staleWhileFetching!==void 0?(r&&(r.returnedStale=!0),a.__staleWhileFetching):void 0):(n||this.#v(t,"expire"),r&&(r.get="stale"),i?(r&&(r.returnedStale=!0),a):void 0):(r&&(r.get=o?"fetching":"hit"),this.#L(h),s&&this.#R(h),o?a.__staleWhileFetching:a)}#q(t,e){this.#u[e]=t,this.#l[t]=e}#L(t){t!==this.#h&&(t===this.#a?this.#a=this.#l[t]:this.#q(this.#u[t],this.#l[t]),this.#q(this.#h,t),this.#h=t)}delete(t){return this.#v(t,"delete")}#v(t,e){g.metrics.hasSubscribers&&g.metrics.publish({op:"delete",delete:e,key:t,cache:this});let i=!1;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=!0,this.#n===1)this.#$(e);else{this.#x(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#m?.(n,t,e),this.#f&&this.#r?.push([n,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#u[s];else if(s===this.#a)this.#a=this.#l[s];else{let r=this.#u[s];this.#l[r]=this.#l[s];let h=this.#l[s];this.#u[h]=this.#u[s]}this.#n--,this.#y.push(s)}}if(this.#f&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#S?.(...n)}return i}clear(){return this.#$("delete")}#$(t){for(let e of this.#z({allowStale:!0})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[e];this.#T&&this.#m?.(i,s,t),this.#f&&this.#r?.push([i,s,t])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#F){this.#d.fill(0),this.#F.fill(0);for(let e of this.#g??[])e!==void 0&&clearTimeout(e);this.#g?.fill(void 0)}if(this.#_&&this.#_.fill(0),this.#a=0,this.#h=0,this.#y.length=0,this.#b=0,this.#n=0,this.#f&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#S?.(...i)}}};exports.LRUCache=L;
|
| 2 |
+
//# sourceMappingURL=index.min.js.map
|
node_modules/lru-cache/dist/commonjs/index.min.js.map
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"diagnostics-channel-node.d.ts","sourceRoot":"","sources":["../../../src/diagnostics-channel-node.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,CAAA;AACvC,eAAO,MAAM,OAAO,EAAE,OAAO,CAAC,OAAO,CAAgC,CAAA;AACrE,eAAO,MAAM,OAAO,EAAE,cAAc,CAAC,OAAO,CAA+B,CAAA"}
|
node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"diagnostics-channel-node.js","sourceRoot":"","sources":["../../../src/diagnostics-channel-node.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACrD,mEAAmE;AACnE,uEAAkE;AAGrD,QAAA,OAAO,GAAqB,IAAA,kCAAO,EAAC,mBAAmB,CAAC,CAAA;AACxD,QAAA,OAAO,GAA4B,IAAA,yCAAc,EAAC,WAAW,CAAC,CAAA","sourcesContent":["// simple node version that imports from node builtin\n// this is built to both ESM and CommonJS on the 'node' import path\nimport { tracingChannel, channel } from 'node:diagnostics_channel'\nimport type { TracingChannel, Channel } from 'node:diagnostics_channel'\nexport type { TracingChannel, Channel }\nexport const metrics: Channel<unknown> = channel('lru-cache:metrics')\nexport const tracing: TracingChannel<unknown> = tracingChannel('lru-cache')\n"]}
|