44 */
55Object . defineProperty ( exports , "__esModule" , { value :true } ) ;
66exports . LRUCache = void 0 ;
7- const defaultPerf = ( typeof performance === 'object' &&
7+ const perf = typeof performance === 'object' &&
88performance &&
9- typeof performance . now === 'function' ) ?
10- performance
9+ typeof performance . now === 'function'
10+ ? performance
1111 :Date ;
1212const warned = new Set ( ) ;
1313/* c8 ignore start */
14- const PROCESS = ( typeof process === 'object' && ! ! process ?
15- process
16- :{ } ) ;
14+ const PROCESS = ( typeof process === 'object' && ! ! process ?process :{ } ) ;
1715/* c8 ignore start */
1816const emitWarning = ( msg , type , code , fn ) => {
19- typeof PROCESS . emitWarning === 'function' ?
20- PROCESS . emitWarning ( msg , type , code , fn )
17+ typeof PROCESS . emitWarning === 'function'
18+ ? PROCESS . emitWarning ( msg , type , code , fn )
2119 :console . error ( `[${ code } ]${ type } :${ msg } ` ) ;
2220} ;
2321let AC = globalThis . AbortController ;
@@ -81,11 +79,16 @@ const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
8179// zeroes at init time is brutal when you get that big.
8280// But why not be complete?
8381// Maybe in the future, these limits will have expanded.
84- const getUintArray = ( max ) => ! isPosInt ( max ) ?null
85- :max <= Math . pow ( 2 , 8 ) ?Uint8Array
86- :max <= Math . pow ( 2 , 16 ) ?Uint16Array
87- :max <= Math . pow ( 2 , 32 ) ?Uint32Array
88- :max <= Number . MAX_SAFE_INTEGER ?ZeroArray
82+ const getUintArray = ( max ) => ! isPosInt ( max )
83+ ?null
84+ :max <= Math . pow ( 2 , 8 )
85+ ?Uint8Array
86+ :max <= Math . pow ( 2 , 16 )
87+ ?Uint16Array
88+ :max <= Math . pow ( 2 , 32 )
89+ ?Uint32Array
90+ :max <= Number . MAX_SAFE_INTEGER
91+ ?ZeroArray
8992 :null ;
9093/* c8 ignore stop */
9194class ZeroArray extends Array {
@@ -144,17 +147,9 @@ class LRUCache {
144147 #max;
145148 #maxSize;
146149 #dispose;
147- #onInsert;
148150 #disposeAfter;
149151 #fetchMethod;
150152 #memoMethod;
151- #perf;
152- /**
153- * {@link LRUCache.OptionsBase.perf }
154- */
155- get perf ( ) {
156- return this . #perf;
157- }
158153/**
159154 * {@link LRUCache.OptionsBase.ttl }
160155 */
@@ -233,7 +228,6 @@ class LRUCache {
233228 #hasDispose;
234229 #hasFetchMethod;
235230 #hasDisposeAfter;
236- #hasOnInsert;
237231/**
238232 * Do not call this method unless you need to inspect the
239233 * inner workings of the cache. If anything returned by this
@@ -310,26 +304,14 @@ class LRUCache {
310304get dispose ( ) {
311305return this . #dispose;
312306}
313- /**
314- * {@link LRUCache.OptionsBase.onInsert } (read-only)
315- */
316- get onInsert ( ) {
317- return this . #onInsert;
318- }
319307/**
320308 * {@link LRUCache.OptionsBase.disposeAfter } (read-only)
321309 */
322310get disposeAfter ( ) {
323311return this . #disposeAfter;
324312}
325313constructor ( options ) {
326- const { max= 0 , ttl, ttlResolution= 1 , ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize= 0 , maxEntrySize= 0 , sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf, } = options ;
327- if ( perf !== undefined ) {
328- if ( typeof perf ?. now !== 'function' ) {
329- throw new TypeError ( 'perf option must have a now() method if specified' ) ;
330- }
331- }
332- this . #perf= perf ?? defaultPerf ;
314+ const { max= 0 , ttl, ttlResolution= 1 , ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize= 0 , maxEntrySize= 0 , sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, } = options ;
333315if ( max !== 0 && ! isPosInt ( max ) ) {
334316throw new TypeError ( 'max option must be a nonnegative integer' ) ;
335317}
@@ -373,9 +355,6 @@ class LRUCache {
373355if ( typeof dispose === 'function' ) {
374356this . #dispose= dispose ;
375357}
376- if ( typeof onInsert === 'function' ) {
377- this . #onInsert= onInsert ;
378- }
379358if ( typeof disposeAfter === 'function' ) {
380359this . #disposeAfter= disposeAfter ;
381360this . #disposed= [ ] ;
@@ -385,7 +364,6 @@ class LRUCache {
385364this . #disposed= undefined ;
386365}
387366this . #hasDispose= ! ! this . #dispose;
388- this . #hasOnInsert= ! ! this . #onInsert;
389367this . #hasDisposeAfter= ! ! this . #disposeAfter;
390368this . noDisposeOnSet = ! ! noDisposeOnSet ;
391369this . noUpdateTTL = ! ! noUpdateTTL ;
@@ -410,8 +388,8 @@ class LRUCache {
410388this . updateAgeOnGet = ! ! updateAgeOnGet ;
411389this . updateAgeOnHas = ! ! updateAgeOnHas ;
412390this . ttlResolution =
413- isPosInt ( ttlResolution ) || ttlResolution === 0 ?
414- ttlResolution
391+ isPosInt ( ttlResolution ) || ttlResolution === 0
392+ ? ttlResolution
415393 :1 ;
416394this . ttlAutopurge = ! ! ttlAutopurge ;
417395this . ttl = ttl || 0 ;
@@ -447,7 +425,7 @@ class LRUCache {
447425const starts = new ZeroArray ( this . #max) ;
448426this . #ttls= ttls ;
449427this . #starts= starts ;
450- this . #setItemTTL= ( index , ttl , start = this . # perf. now ( ) ) => {
428+ this . #setItemTTL= ( index , ttl , start = perf . now ( ) ) => {
451429starts [ index ] = ttl !== 0 ?start :0 ;
452430ttls [ index ] = ttl ;
453431if ( ttl !== 0 && this . ttlAutopurge ) {
@@ -465,7 +443,7 @@ class LRUCache {
465443}
466444} ;
467445this . #updateItemAge= index => {
468- starts [ index ] = ttls [ index ] !== 0 ?this . # perf. now ( ) :0 ;
446+ starts [ index ] = ttls [ index ] !== 0 ?perf . now ( ) :0 ;
469447} ;
470448this . #statusTTL= ( status , index ) => {
471449if ( ttls [ index ] ) {
@@ -485,7 +463,7 @@ class LRUCache {
485463// that costly call repeatedly.
486464let cachedNow = 0 ;
487465const getNow = ( ) => {
488- const n = this . # perf. now ( ) ;
466+ const n = perf . now ( ) ;
489467if ( this . ttlResolution > 0 ) {
490468cachedNow = n ;
491469const t = setTimeout ( ( ) => ( cachedNow = 0 ) , this . ttlResolution ) ;
@@ -722,7 +700,9 @@ class LRUCache {
722700find ( fn , getOptions = { } ) {
723701for ( const i of this . #indexes( ) ) {
724702const v = this . #valList[ i ] ;
725- const value = this . #isBackgroundFetch( v ) ?v . __staleWhileFetching :v ;
703+ const value = this . #isBackgroundFetch( v )
704+ ?v . __staleWhileFetching
705+ :v ;
726706if ( value === undefined )
727707continue ;
728708if ( fn ( value , this . #keyList[ i ] , this ) ) {
@@ -744,7 +724,9 @@ class LRUCache {
744724forEach ( fn , thisp = this ) {
745725for ( const i of this . #indexes( ) ) {
746726const v = this . #valList[ i ] ;
747- const value = this . #isBackgroundFetch( v ) ?v . __staleWhileFetching :v ;
727+ const value = this . #isBackgroundFetch( v )
728+ ?v . __staleWhileFetching
729+ :v ;
748730if ( value === undefined )
749731continue ;
750732fn . call ( thisp , value , this . #keyList[ i ] , this ) ;
@@ -757,7 +739,9 @@ class LRUCache {
757739rforEach ( fn , thisp = this ) {
758740for ( const i of this . #rindexes( ) ) {
759741const v = this . #valList[ i ] ;
760- const value = this . #isBackgroundFetch( v ) ?v . __staleWhileFetching :v ;
742+ const value = this . #isBackgroundFetch( v )
743+ ?v . __staleWhileFetching
744+ :v ;
761745if ( value === undefined )
762746continue ;
763747fn . call ( thisp , value , this . #keyList[ i ] , this ) ;
@@ -794,18 +778,17 @@ class LRUCache {
794778if ( i === undefined )
795779return undefined ;
796780const v = this . #valList[ i ] ;
797- /* c8 ignore start - this isn't tested for the info function,
798- * but it's the same logic as found in other places. */
799- const value = this . #isBackgroundFetch ( v ) ? v . __staleWhileFetching :v ;
781+ const value = this . #isBackgroundFetch ( v )
782+ ? v . __staleWhileFetching
783+ :v ;
800784if ( value === undefined )
801785return undefined ;
802- /* c8 ignore end */
803786const entry = { value} ;
804787if ( this . #ttls&& this . #starts) {
805788const ttl = this . #ttls[ i ] ;
806789const start = this . #starts[ i ] ;
807790if ( ttl && start ) {
808- const remain = ttl - ( this . # perf. now ( ) - start ) ;
791+ const remain = ttl - ( perf . now ( ) - start ) ;
809792entry . ttl = remain ;
810793entry . start = Date . now ( ) ;
811794}
@@ -817,7 +800,7 @@ class LRUCache {
817800}
818801/**
819802 * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
820- * passed to {@link LRUCache #load}.
803+ * passed to {@link LRLUCache #load}.
821804 *
822805 * The `start` fields are calculated relative to a portable `Date.now()`
823806 * timestamp, even if `performance.now()` is available.
@@ -833,15 +816,17 @@ class LRUCache {
833816for ( const i of this . #indexes( { allowStale :true } ) ) {
834817const key = this . #keyList[ i ] ;
835818const v = this . #valList[ i ] ;
836- const value = this . #isBackgroundFetch( v ) ?v . __staleWhileFetching :v ;
819+ const value = this . #isBackgroundFetch( v )
820+ ?v . __staleWhileFetching
821+ :v ;
837822if ( value === undefined || key === undefined )
838823continue ;
839824const entry = { value} ;
840825if ( this . #ttls&& this . #starts) {
841826entry . ttl = this . #ttls[ i ] ;
842827// always dump the start relative to a portable timestamp
843828// it's ok for this to be a bit slow, it's a rare operation.
844- const age = this . # perf. now ( ) - this . #starts[ i ] ;
829+ const age = perf . now ( ) - this . #starts[ i ] ;
845830entry . start = Math . floor ( Date . now ( ) - age ) ;
846831}
847832if ( this . #sizes) {
@@ -871,7 +856,7 @@ class LRUCache {
871856//
872857// it's ok for this to be a bit slow, it's a rare operation.
873858const age = Date . now ( ) - entry . start ;
874- entry . start = this . # perf. now ( ) - age ;
859+ entry . start = perf . now ( ) - age ;
875860}
876861this . set ( key , entry . value , entry ) ;
877862}
@@ -928,9 +913,12 @@ class LRUCache {
928913let index = this . #size=== 0 ?undefined :this . #keyMap. get ( k ) ;
929914if ( index === undefined ) {
930915// addition
931- index = ( this . #size=== 0 ?this . #tail
932- :this . #free. length !== 0 ?this . #free. pop ( )
933- :this . #size=== this . #max ?this . #evict( false )
916+ index = ( this . #size=== 0
917+ ?this . #tail
918+ :this . #free. length !== 0
919+ ?this . #free. pop ( )
920+ :this . #size=== this . #max
921+ ?this . #evict( false )
934922 :this . #size) ;
935923this . #keyList[ index ] = k ;
936924this . #valList[ index ] = v ;
@@ -943,9 +931,6 @@ class LRUCache {
943931if ( status )
944932status . set = 'add' ;
945933noUpdateTTL = false ;
946- if ( this . #hasOnInsert) {
947- this . #onInsert?. ( v , k , 'add' ) ;
948- }
949934}
950935else {
951936// update
@@ -977,8 +962,8 @@ class LRUCache {
977962this . #valList[ index ] = v ;
978963if ( status ) {
979964status . set = 'replace' ;
980- const oldValue = oldVal && this . #isBackgroundFetch( oldVal ) ?
981- oldVal . __staleWhileFetching
965+ const oldValue = oldVal && this . #isBackgroundFetch( oldVal )
966+ ? oldVal . __staleWhileFetching
982967 :oldVal ;
983968if ( oldValue !== undefined )
984969status . oldValue = oldValue ;
@@ -987,9 +972,6 @@ class LRUCache {
987972else if ( status ) {
988973status . set = 'update' ;
989974}
990- if ( this . #hasOnInsert) {
991- this . onInsert ?. ( v , k , v === oldVal ?'update' :'replace' ) ;
992- }
993975}
994976if ( ttl !== 0 && ! this . #ttls) {
995977this . #initializeTTLTracking( ) ;
@@ -1172,7 +1154,7 @@ class LRUCache {
11721154const bf = p ;
11731155if ( this . #valList[ index ] === p ) {
11741156if ( v === undefined ) {
1175- if ( bf . __staleWhileFetching !== undefined ) {
1157+ if ( bf . __staleWhileFetching ) {
11761158this . #valList[ index ] = bf . __staleWhileFetching ;
11771159}
11781160else {