1- import { addBreadcrumb , Severity } from '@sentry/node' ;
1+ import { addBreadcrumb } from '@sentry/node' ;
22import { EventEmitter } from 'events' ;
33
44import { castArray } from './castArray.js' ;
@@ -136,14 +136,14 @@ const DEFAULT_OPTIONS: CacheOptions = {
136136 * @template Value
137137 * @template Key
138138 */
139- export class Cache < Value = any , Key = any > extends EventEmitter {
139+ export class Cache < Value = unknown , Key = unknown > extends EventEmitter {
140140 #data: Map < Key , WrappedValue < Value > > ;
141141
142- options : CacheOptions ;
142+ public options : CacheOptions ;
143143
144- checkTimeout : NodeJS . Timeout ;
144+ public checkTimeout : NodeJS . Timeout ;
145145
146- constructor ( options : CacheOptions ) {
146+ public constructor ( options : CacheOptions ) {
147147 super ( ) ;
148148 this . options = {
149149 ...DEFAULT_OPTIONS ,
@@ -160,11 +160,11 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
160160 * @param key cache key
161161 * @returns The value stored in the key
162162 */
163- get < T extends Value = Value > ( key : Key ) : T | undefined {
163+ public get < T extends Value = Value > ( key : Key ) : T | undefined {
164164 const data = this . #data. get ( key ) ;
165165
166166 addBreadcrumb ( {
167- level : Severity . Debug ,
167+ level : 'debug' ,
168168 message : `Cache [Get]: ${ String ( key ) } ` ,
169169 } ) ;
170170
@@ -180,11 +180,11 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
180180 * @param keys an array of keys
181181 * @returns an object containing the values stored in the matching keys
182182 */
183- mget < T extends Value = Value > ( keys : Key [ ] ) : Map < Key , T > {
183+ public mget < T extends Value = Value > ( keys : Key [ ] ) : Map < Key , T > {
184184 const output : Map < Key , T > = new Map ( ) ;
185185
186186 addBreadcrumb ( {
187- level : Severity . Debug ,
187+ level : 'debug' ,
188188 message : `Cache [MGet]: keys: ${ keys . slice ( 0 , 10 ) } (${
189189 keys . length
190190 } items)`,
@@ -209,11 +209,11 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
209209 * it to a serialized JSON
210210 * @param ttl The time to live in seconds.
211211 */
212- set < T extends Value = Value > ( key : Key , value : T , ttl ?: number ) : boolean {
212+ public set < T extends Value = Value > ( key : Key , value : T , ttl ?: number ) : boolean {
213213 const usedTtl = ttl ?? this . options . stdTTL ;
214214
215215 addBreadcrumb ( {
216- level : Severity . Debug ,
216+ level : 'debug' ,
217217 message : `Cache [Set]: ${ String ( key ) } : ${ String (
218218 value
219219 ) } | TTL: ${ ttl } /${ usedTtl } `,
@@ -231,10 +231,10 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
231231 *
232232 * @param keyValueSet an array of object which includes key,value and ttl
233233 */
234- mset < T extends Value = Value > ( keyValueSet : ValueSetItem < Key , T > [ ] ) : boolean {
234+ public mset < T extends Value = Value > ( keyValueSet : ValueSetItem < Key , T > [ ] ) : boolean {
235235 const len = keyValueSet . length ;
236236 addBreadcrumb ( {
237- level : Severity . Debug ,
237+ level : 'debug' ,
238238 message : `Cache [MSet]: ${ keyValueSet . length } Items` ,
239239 } ) ;
240240 for ( let i = 0 ; i < len ; i ++ ) {
@@ -250,13 +250,13 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
250250 * @param cb Callback function
251251 * @returns Number of deleted keys
252252 */
253- del ( keys : Key | Key [ ] ) : number {
253+ public del ( keys : Key | Key [ ] ) : number {
254254 let deleted = 0 ;
255255 const keyArr = castArray ( keys ) ;
256256 const data = this . #data;
257257
258258 addBreadcrumb ( {
259- level : Severity . Debug ,
259+ level : 'debug' ,
260260 message : `Cache [Del]: ${ String ( keyArr . slice ( 0 , 10 ) ) } (${
261261 keyArr . length
262262 } items)`,
@@ -282,7 +282,7 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
282282 * @param key cache key
283283 * @returns The value stored in the key
284284 */
285- take < T extends Value = Value > ( key : Key ) : T | undefined {
285+ public take < T extends Value = Value > ( key : Key ) : T | undefined {
286286 const output = this . get ( key ) ;
287287
288288 if ( this . #data. has ( key ) ) {
@@ -295,7 +295,7 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
295295 /**
296296 * reset or redefine the ttl of a key. If `ttl` is not passed or set to 0 it's similar to `.del()`
297297 */
298- ttl ( key : Key , ttl : number = this . options . stdTTL ) : boolean {
298+ public ttl ( key : Key , ttl : number = this . options . stdTTL ) : boolean {
299299 if ( ! key ) {
300300 return false ;
301301 }
@@ -308,29 +308,29 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
308308 this . del ( key ) ;
309309 }
310310 return true ;
311- }
311+ }
312312 return false ;
313-
313+
314314 }
315315
316- getTtl ( key : Key ) : number | undefined {
316+ public getTtl ( key : Key ) : number | undefined {
317317 if ( ! key ) {
318318 return void 0 ;
319319 }
320320
321321 const value = this . #data. get ( key ) ;
322322 if ( this . #data. has ( key ) && this . _check ( key , value ) ) {
323323 return value . t ;
324- }
324+ }
325325 return void 0 ;
326-
326+
327327 }
328328
329329 /**
330330 * list all keys within this cache
331331 * @returns An array of all keys
332332 */
333- keys ( ) : IterableIterator < Key > {
333+ public keys ( ) : IterableIterator < Key > {
334334 return this . #data. keys ( ) ;
335335 }
336336
@@ -348,14 +348,14 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
348348 * @param key cache key to check
349349 * @returns Boolean indicating if the key is cached or not
350350 */
351- has ( key : Key ) : boolean {
351+ public has ( key : Key ) : boolean {
352352 return this . has ( key ) && this . _check ( key , this . #data. get ( key ) ) ;
353353 }
354354
355355 /**
356356 * flush the whole data and reset the stats
357357 */
358- flushAll ( _startPeriod = true ) : void {
358+ public flushAll ( _startPeriod = true ) : void {
359359 this . #data. clear ( ) ;
360360 this . _killCheckPeriod ( ) ;
361361 this . _checkData ( _startPeriod ) ;
@@ -365,14 +365,14 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
365365 /**
366366 * This will clear the interval timeout which is set on checkperiod option.
367367 */
368- close ( ) : void {
368+ public close ( ) : void {
369369 this . _killCheckPeriod ( ) ;
370370 }
371371
372372 /**
373373 * flush the stats and reset all counters to 0
374374 */
375- flushStats ( ) : void { }
375+ public flushStats ( ) : void { }
376376
377377 private _check ( key : Key , data ) {
378378 let ret = true ;
@@ -390,7 +390,7 @@ export class Cache<Value = any, Key = any> extends EventEmitter {
390390 if ( this . checkTimeout != null ) {
391391 const { checkTimeout} = this ;
392392 this . checkTimeout = null ;
393- clearTimeout ( checkTimeout ) ;
393+ clearTimeout ( checkTimeout ) ;
394394 }
395395 }
396396
0 commit comments