@types/lru-cache
Advanced tools
Comparing version 7.5.0 to 7.6.0
@@ -1,2 +0,2 @@ | ||
// Type definitions for lru-cache 7.5 | ||
// Type definitions for lru-cache 7.6 | ||
// Project: https://github.com/isaacs/node-lru-cache | ||
@@ -6,4 +6,5 @@ // Definitions by: Bart van der Schoor <https://github.com/Bartvds> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.3 | ||
/// <reference lib="DOM" /> | ||
// tslint:disable:member-access | ||
declare class LRUCache<K, V> implements Iterable<[K, V]> { | ||
@@ -15,19 +16,22 @@ constructor(options: LRUCache.Options<K, V>); | ||
* | ||
* @deprecated use `cache.size` instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use `cache.size` instead | ||
*/ | ||
readonly length: number; | ||
public readonly length: number; | ||
// values populated from the constructor options | ||
readonly max: number; | ||
readonly maxSize: number; | ||
readonly sizeCalculation: LRUCache.SizeCalculator<K, V> | undefined; | ||
readonly dispose: LRUCache.Disposer<K, V>; | ||
readonly disposeAfter: LRUCache.Disposer<K, V> | null; | ||
readonly noDisposeOnSet: boolean; | ||
readonly ttl: number; | ||
readonly ttlResolution: number; | ||
readonly ttlAutopurge: boolean; | ||
readonly allowStale: boolean; | ||
readonly updateAgeOnGet: boolean; | ||
public readonly max: number; | ||
public readonly maxSize: number; | ||
public readonly sizeCalculation: LRUCache.SizeCalculator<K, V> | undefined; | ||
public readonly dispose: LRUCache.Disposer<K, V>; | ||
/** | ||
* @since 7.4.0 | ||
*/ | ||
public readonly disposeAfter: LRUCache.Disposer<K, V> | null; | ||
public readonly noDisposeOnSet: boolean; | ||
public readonly ttl: number; | ||
public readonly ttlResolution: number; | ||
public readonly ttlAutopurge: boolean; | ||
public readonly allowStale: boolean; | ||
public readonly updateAgeOnGet: boolean; | ||
public readonly fetchMethod: LRUCache.Fetcher<K, V> | null; | ||
@@ -37,3 +41,3 @@ /** | ||
*/ | ||
readonly size: number; | ||
public readonly size: number; | ||
@@ -43,3 +47,3 @@ /** | ||
*/ | ||
readonly calculatedSize: number; | ||
public readonly calculatedSize: number; | ||
@@ -49,3 +53,3 @@ /** | ||
*/ | ||
set(key: K, value: V, options?: LRUCache.SetOptions<K, V>): this; | ||
public set(key: K, value: V, options?: LRUCache.SetOptions<K, V>): this; | ||
@@ -60,3 +64,4 @@ /** | ||
*/ | ||
get(key: K, options?: LRUCache.GetOptions): V | undefined; | ||
// tslint:disable-next-line:no-unnecessary-generics | ||
public get<T = V>(key: K, options?: LRUCache.GetOptions): T | undefined; | ||
@@ -67,3 +72,4 @@ /** | ||
*/ | ||
peek(key: K, options?: LRUCache.PeekOptions): V | undefined; | ||
// tslint:disable-next-line:no-unnecessary-generics | ||
public peek<T = V>(key: K, options?: LRUCache.PeekOptions): T | undefined; | ||
@@ -74,3 +80,3 @@ /** | ||
*/ | ||
has(key: K): boolean; | ||
public has(key: K): boolean; | ||
@@ -81,3 +87,3 @@ /** | ||
*/ | ||
delete(key: K): boolean; | ||
public delete(key: K): boolean; | ||
@@ -87,3 +93,3 @@ /** | ||
*/ | ||
clear(): void; | ||
public clear(): void; | ||
@@ -93,3 +99,3 @@ /** | ||
*/ | ||
purgeStale(): boolean; | ||
public purgeStale(): boolean; | ||
@@ -100,3 +106,4 @@ /** | ||
*/ | ||
find(callbackFn: (value: V, key: K, cache: this) => boolean, options?: LRUCache.GetOptions): V; | ||
// tslint:disable-next-line:no-unnecessary-generics | ||
public find<T = V>(callbackFn: (value: V, key: K, cache: this) => boolean | undefined | void, options?: LRUCache.GetOptions): T; | ||
@@ -106,3 +113,3 @@ /** | ||
*/ | ||
forEach<T = this>(callbackFn: (this: T, value: V, key: K, cache: this) => void, thisArg?: T): void; | ||
public forEach<T = this>(callbackFn: (this: T, value: V, key: K, cache: this) => void, thisArg?: T): void; | ||
@@ -113,3 +120,3 @@ /** | ||
*/ | ||
rforEach<T = this>(callbackFn: (this: T, value: V, key: K, cache: this) => void, thisArg?: T): void; | ||
public rforEach<T = this>(callbackFn: (this: T, value: V, key: K, cache: this) => void, thisArg?: T): void; | ||
@@ -120,3 +127,3 @@ /** | ||
*/ | ||
keys(): Generator<K>; | ||
public keys(): Generator<K>; | ||
@@ -127,3 +134,3 @@ /** | ||
*/ | ||
rkeys(): Generator<K>; | ||
public rkeys(): Generator<K>; | ||
@@ -134,3 +141,3 @@ /** | ||
*/ | ||
values(): Generator<V>; | ||
public values(): Generator<V>; | ||
@@ -141,3 +148,3 @@ /** | ||
*/ | ||
rvalues(): Generator<V>; | ||
public rvalues(): Generator<V>; | ||
@@ -148,3 +155,3 @@ /** | ||
*/ | ||
entries(): Generator<[K, V]>; | ||
public entries(): Generator<[K, V]>; | ||
@@ -155,5 +162,5 @@ /** | ||
*/ | ||
rentries(): Generator<[K, V]>; | ||
public rentries(): Generator<[K, V]>; | ||
[Symbol.iterator](): Iterator<[K, V]>; | ||
public [Symbol.iterator](): Iterator<[K, V]>; | ||
@@ -163,3 +170,3 @@ /** | ||
*/ | ||
dump(): Array<[K, LRUCache.Entry<V>]>; | ||
public dump(): Array<[K, LRUCache.Entry<V>]>; | ||
@@ -171,3 +178,3 @@ /** | ||
*/ | ||
load(cacheEntries: ReadonlyArray<[K, LRUCache.Entry<V>]>): void; | ||
public load(cacheEntries: ReadonlyArray<[K, LRUCache.Entry<V>]>): void; | ||
@@ -177,3 +184,3 @@ /** | ||
*/ | ||
pop(): V | undefined; | ||
public pop(): V | undefined; | ||
@@ -185,6 +192,5 @@ // ========================= Deprecated | ||
* | ||
* @deprecated use delete() instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use delete() instead | ||
*/ | ||
del(key: K): boolean; | ||
public del(key: K): boolean; | ||
@@ -194,6 +200,5 @@ /** | ||
* | ||
* @deprecated use clear() instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use clear() instead | ||
*/ | ||
reset(): void; | ||
public reset(): void; | ||
@@ -203,10 +208,19 @@ /** | ||
* | ||
* @deprecated use purgeStale() instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use purgeStale() instead | ||
*/ | ||
prune(): boolean; | ||
public prune(): boolean; | ||
/** | ||
* since: 7.6.0 | ||
*/ | ||
// tslint:disable-next-line:no-unnecessary-generics | ||
public fetch<ExpectedValue = V>(key: K, options?: LRUCache.FetchOptions): Promise<ExpectedValue | undefined>; | ||
/** | ||
* since: 7.6.0 | ||
*/ | ||
public getRemainingTTL(key: K): number; | ||
} | ||
declare namespace LRUCache { | ||
type DisposeReason = "evict" | "set" | "delete"; | ||
type DisposeReason = 'evict' | 'set' | 'delete'; | ||
@@ -216,2 +230,3 @@ type SizeCalculator<K, V> = (value: V, key: K) => number; | ||
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void; | ||
type Fetcher<K, V> = (key: K, staleKey?: K, options?: FetcherOptions<K, V>) => Promise<V>; | ||
@@ -224,4 +239,3 @@ interface DeprecatedOptions<K, V> { | ||
* | ||
* @deprecated use options.ttl instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use options.ttl instead | ||
*/ | ||
@@ -238,4 +252,3 @@ maxAge?: number; | ||
* | ||
* @deprecated use options.sizeCalculation instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use options.sizeCalculation instead | ||
*/ | ||
@@ -252,4 +265,3 @@ length?(value: V, key?: K): number; | ||
* | ||
* @deprecated use options.allowStale instead | ||
* @since 7.0.0 | ||
* @deprecated since 7.0 use options.allowStale instead | ||
*/ | ||
@@ -259,3 +271,3 @@ stale?: boolean; | ||
interface Options<K, V> extends DeprecatedOptions<K, V> { | ||
interface LimitedByCount { | ||
/** | ||
@@ -266,3 +278,5 @@ * The number of most recently used items to keep. | ||
max: number; | ||
} | ||
interface LimitedBySize<K, V> { | ||
/** | ||
@@ -277,3 +291,3 @@ * If you wish to track item size, you must provide a maxSize | ||
*/ | ||
maxSize?: number; | ||
maxSize: number; | ||
@@ -287,30 +301,18 @@ /** | ||
sizeCalculation?: SizeCalculator<K, V>; | ||
} | ||
interface LimitedByTTL { | ||
/** | ||
* Function that is called on items when they are dropped from the cache. | ||
* This can be handy if you want to close file descriptors or do other | ||
* cleanup tasks when items are no longer accessible. Called with `key, value`. | ||
* It's called before actually removing the item from the internal cache, | ||
* so if you want to immediately put it back in, you'll have to do that in | ||
* a `nextTick` or `setTimeout` callback or it won't do anything. | ||
*/ | ||
dispose?: Disposer<K, V>; | ||
/** | ||
* The same as dispose, but called *after* the entry is completely removed | ||
* and the cache is once again in a clean state | ||
* It is safe to add an item right back into the cache at this point. | ||
* However, note that it is *very* easy to inadvertently create infinite | ||
* recursion this way. | ||
*/ | ||
disposeAfter?: Disposer<K, V>; | ||
/** | ||
* Set to true to suppress calling the dispose() function if the entry | ||
* key is still accessible within the cache. | ||
* This may be overridden by passing an options object to cache.set(). | ||
* Max time to live for items before they are considered stale. | ||
* Note that stale items are NOT preemptively removed by default, | ||
* and MAY live in the cache, contributing to its LRU max, long after | ||
* they have expired. | ||
* | ||
* @default false | ||
* Also, as this cache is optimized for LRU/MRU operations, some of | ||
* the staleness/TTL checks will reduce performance, as they will incur | ||
* overhead by deleting items. | ||
* | ||
* Must be a positive integer in ms, defaults to 0, which means "no TTL" | ||
*/ | ||
noDisposeOnSet?: boolean; | ||
ttl: number; | ||
@@ -324,2 +326,3 @@ /** | ||
* @default false | ||
* @since 7.4.0 | ||
*/ | ||
@@ -329,16 +332,2 @@ noUpdateTTL?: boolean; | ||
/** | ||
* Max time to live for items before they are considered stale. | ||
* Note that stale items are NOT preemptively removed by default, | ||
* and MAY live in the cache, contributing to its LRU max, long after | ||
* they have expired. | ||
* | ||
* Also, as this cache is optimized for LRU/MRU operations, some of | ||
* the staleness/TTL checks will reduce performance, as they will incur | ||
* overhead by deleting items. | ||
* | ||
* Must be a positive integer in ms, defaults to 0, which means "no TTL" | ||
*/ | ||
ttl?: number; | ||
/** | ||
* Minimum amount of time in ms in which to check for staleness. | ||
@@ -355,2 +344,3 @@ * Defaults to 1, which means that the current time is checked | ||
* @default 1 | ||
* @since 7.1.0 | ||
*/ | ||
@@ -372,2 +362,3 @@ ttlResolution?: number; | ||
* @default false | ||
* @since 7.1.0 | ||
*/ | ||
@@ -390,3 +381,48 @@ ttlAutopurge?: boolean; | ||
} | ||
type SafetyBounds<K, V> = LimitedByCount | LimitedBySize<K, V> | LimitedByTTL; | ||
interface SharedOptions<K, V> { | ||
/** | ||
* Function that is called on items when they are dropped from the cache. | ||
* This can be handy if you want to close file descriptors or do other | ||
* cleanup tasks when items are no longer accessible. Called with `key, value`. | ||
* It's called before actually removing the item from the internal cache, | ||
* so if you want to immediately put it back in, you'll have to do that in | ||
* a `nextTick` or `setTimeout` callback or it won't do anything. | ||
*/ | ||
dispose?: Disposer<K, V>; | ||
/** | ||
* The same as dispose, but called *after* the entry is completely removed | ||
* and the cache is once again in a clean state | ||
* It is safe to add an item right back into the cache at this point. | ||
* However, note that it is *very* easy to inadvertently create infinite | ||
* recursion this way. | ||
* @since 7.3.0 | ||
*/ | ||
disposeAfter?: Disposer<K, V>; | ||
/** | ||
* Set to true to suppress calling the dispose() function if the entry | ||
* key is still accessible within the cache. | ||
* This may be overridden by passing an options object to cache.set(). | ||
* | ||
* @default false | ||
*/ | ||
noDisposeOnSet?: boolean; | ||
/** | ||
* Since 7.6.0 | ||
* `fetchMethod` Function that is used to make background asynchronous | ||
* fetches. Called with `fetchMethod(key, staleValue)`. May return a | ||
* Promise. | ||
* | ||
* If `fetchMethod` is not provided, then `cache.fetch(key)` is equivalent | ||
* to `Promise.resolve(cache.get(key))`. | ||
*/ | ||
fetchMethod?: Fetcher<K, V> | null; | ||
} | ||
type Options<K, V> = SharedOptions<K, V> & DeprecatedOptions<K, V> & SafetyBounds<K, V>; | ||
interface SetOptions<K, V> { | ||
@@ -411,3 +447,12 @@ /** | ||
} | ||
interface FetchOptions { | ||
allowStale?: boolean; | ||
updateAgeOnGet?: boolean; | ||
} | ||
interface FetcherOptions<K, V> { | ||
signal?: AbortSignal; | ||
options?: SetOptions<K, V> & GetOptions; | ||
} | ||
interface Entry<V> { | ||
@@ -414,0 +459,0 @@ value: V; |
{ | ||
"name": "@types/lru-cache", | ||
"version": "7.5.0", | ||
"version": "7.6.0", | ||
"description": "TypeScript definitions for lru-cache", | ||
@@ -28,4 +28,4 @@ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lru-cache", | ||
"dependencies": {}, | ||
"typesPublisherContentHash": "fa37136c1ffa5c8ed262e0ddd15faf5f262606e7d3b1f9a7920d32f9c0ba15e9", | ||
"typesPublisherContentHash": "8a0568cca1d7c002536ce32370c56a9dc740e0d5c53aa2f3324eed598520a689", | ||
"typeScriptVersion": "3.9" | ||
} |
@@ -11,3 +11,3 @@ # Installation | ||
### Additional Details | ||
* Last updated: Thu, 17 Mar 2022 20:31:47 GMT | ||
* Last updated: Fri, 25 Mar 2022 23:31:44 GMT | ||
* Dependencies: none | ||
@@ -14,0 +14,0 @@ * Global values: none |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17647
369