@@ -35,7 +35,7 @@ beforeEach(() => {
35
35
36
36
describe ( 'cachified' , ( ) => {
37
37
it ( 'caches a value' , async ( ) => {
38
- const cache = new Map < string , CacheEntry < string > > ( ) ;
38
+ const cache = new Map < string , CacheEntry > ( ) ;
39
39
const reporter = createReporter ( ) ;
40
40
const reporter2 = createReporter ( ) ;
41
41
@@ -84,7 +84,7 @@ describe('cachified', () => {
84
84
} ) ;
85
85
86
86
it ( 'immediately refreshes when ttl is 0' , async ( ) => {
87
- const cache = new Map < string , CacheEntry < string > > ( ) ;
87
+ const cache = new Map < string , CacheEntry > ( ) ;
88
88
89
89
const value = await cachified ( {
90
90
cache,
@@ -110,7 +110,7 @@ describe('cachified', () => {
110
110
} ) ;
111
111
112
112
it ( 'caches undefined values' , async ( ) => {
113
- const cache = new Map < string , CacheEntry < undefined > > ( ) ;
113
+ const cache = new Map < string , CacheEntry > ( ) ;
114
114
115
115
const value = await cachified ( {
116
116
cache,
@@ -133,7 +133,7 @@ describe('cachified', () => {
133
133
} ) ;
134
134
135
135
it ( 'caches null values' , async ( ) => {
136
- const cache = new Map < string , CacheEntry < null > > ( ) ;
136
+ const cache = new Map < string , CacheEntry > ( ) ;
137
137
138
138
const value = await cachified ( {
139
139
cache,
@@ -156,7 +156,7 @@ describe('cachified', () => {
156
156
} ) ;
157
157
158
158
it ( 'throws when no fresh value can be received for empty cache' , async ( ) => {
159
- const cache = new Map < string , CacheEntry < string > > ( ) ;
159
+ const cache = new Map < string , CacheEntry > ( ) ;
160
160
const reporter = createReporter ( ) ;
161
161
162
162
const value = cachified ( {
@@ -182,7 +182,7 @@ describe('cachified', () => {
182
182
} ) ;
183
183
184
184
it ( 'throws when no forced fresh value can be received on empty cache' , async ( ) => {
185
- const cache = new Map < string , CacheEntry < string > > ( ) ;
185
+ const cache = new Map < string , CacheEntry > ( ) ;
186
186
187
187
const value = cachified ( {
188
188
cache,
@@ -197,7 +197,7 @@ describe('cachified', () => {
197
197
} ) ;
198
198
199
199
it ( 'throws when fresh value does not meet value check' , async ( ) => {
200
- const cache = new Map < string , CacheEntry < string > > ( ) ;
200
+ const cache = new Map < string , CacheEntry > ( ) ;
201
201
const reporter = createReporter ( ) ;
202
202
const reporter2 = createReporter ( ) ;
203
203
@@ -259,7 +259,7 @@ describe('cachified', () => {
259
259
} ) ;
260
260
261
261
it ( 'supports migrating cached values' , async ( ) => {
262
- const cache = new Map < string , CacheEntry < string > > ( ) ;
262
+ const cache = new Map < string , CacheEntry > ( ) ;
263
263
const reporter = createReporter ( ) ;
264
264
265
265
cache . set ( 'weather' , createCacheEntry ( '☁️' ) ) ;
@@ -292,7 +292,7 @@ describe('cachified', () => {
292
292
} ) ;
293
293
294
294
it ( 'supports async value checkers that throw' , async ( ) => {
295
- const cache = new Map < string , CacheEntry < string > > ( ) ;
295
+ const cache = new Map < string , CacheEntry > ( ) ;
296
296
const reporter = createReporter ( ) ;
297
297
298
298
const value = cachified ( {
@@ -347,7 +347,7 @@ describe('cachified', () => {
347
347
} ) ;
348
348
349
349
it ( 'does not write migrated value to cache in case a new fresh value is already incoming' , async ( ) => {
350
- const cache = new Map < string , CacheEntry < string > > ( ) ;
350
+ const cache = new Map < string , CacheEntry > ( ) ;
351
351
const reporter = createReporter ( ) ;
352
352
353
353
cache . set ( 'weather' , createCacheEntry ( '☁️' ) ) ;
@@ -389,7 +389,7 @@ describe('cachified', () => {
389
389
} ) ;
390
390
391
391
it ( 'gets different values for different keys' , async ( ) => {
392
- const cache = new Map < string , CacheEntry < string > > ( ) ;
392
+ const cache = new Map < string , CacheEntry > ( ) ;
393
393
394
394
const value = await cachified ( {
395
395
cache,
@@ -422,7 +422,7 @@ describe('cachified', () => {
422
422
} ) ;
423
423
424
424
it ( 'gets fresh value when forced to' , async ( ) => {
425
- const cache = new Map < string , CacheEntry < string > > ( ) ;
425
+ const cache = new Map < string , CacheEntry > ( ) ;
426
426
427
427
const value = await cachified ( {
428
428
cache,
@@ -445,7 +445,7 @@ describe('cachified', () => {
445
445
} ) ;
446
446
447
447
it ( 'falls back to cache when forced fresh value fails' , async ( ) => {
448
- const cache = new Map < string , CacheEntry < string > > ( ) ;
448
+ const cache = new Map < string , CacheEntry > ( ) ;
449
449
const reporter = createReporter ( ) ;
450
450
451
451
cache . set ( 'test' , createCacheEntry ( 'ONE' ) ) ;
@@ -477,7 +477,7 @@ describe('cachified', () => {
477
477
} ) ;
478
478
479
479
it ( 'does not fall back to outdated cache' , async ( ) => {
480
- const cache = new Map < string , CacheEntry < string > > ( ) ;
480
+ const cache = new Map < string , CacheEntry > ( ) ;
481
481
const reporter = createReporter ( ) ;
482
482
483
483
cache . set ( 'test' , createCacheEntry ( 'ONE' , { ttl : 5 } ) ) ;
@@ -497,7 +497,7 @@ describe('cachified', () => {
497
497
} ) ;
498
498
499
499
it ( 'it throws when cache fallback is disabled and getting fresh value fails' , async ( ) => {
500
- const cache = new Map < string , CacheEntry < string > > ( ) ;
500
+ const cache = new Map < string , CacheEntry > ( ) ;
501
501
502
502
const value1 = await cachified ( {
503
503
cache,
@@ -519,7 +519,7 @@ describe('cachified', () => {
519
519
} ) ;
520
520
521
521
it ( 'handles cache write fails' , async ( ) => {
522
- const cache = new Map < string , CacheEntry < string > > ( ) ;
522
+ const cache = new Map < string , CacheEntry > ( ) ;
523
523
const setMock = jest . spyOn ( cache , 'set' ) ;
524
524
const reporter = createReporter ( ) ;
525
525
let i = 0 ;
@@ -562,7 +562,7 @@ describe('cachified', () => {
562
562
} ) ;
563
563
564
564
it ( 'gets fresh value when ttl is exceeded' , async ( ) => {
565
- const cache = new Map < string , CacheEntry < string > > ( ) ;
565
+ const cache = new Map < string , CacheEntry > ( ) ;
566
566
const reporter = createReporter ( ) ;
567
567
let i = 0 ;
568
568
const getValue = ( ) =>
@@ -617,7 +617,7 @@ describe('cachified', () => {
617
617
} ) ;
618
618
619
619
it ( 'does not write to cache when ttl is exceeded before value is received' , async ( ) => {
620
- const cache = new Map < string , CacheEntry < string > > ( ) ;
620
+ const cache = new Map < string , CacheEntry > ( ) ;
621
621
const setMock = jest . spyOn ( cache , 'set' ) ;
622
622
const reporter = createReporter ( ) ;
623
623
@@ -649,7 +649,7 @@ describe('cachified', () => {
649
649
} ) ;
650
650
651
651
it ( 'reuses pending fresh value for parallel calls' , async ( ) => {
652
- const cache = new Map < string , CacheEntry < string > > ( ) ;
652
+ const cache = new Map < string , CacheEntry > ( ) ;
653
653
const reporter = createReporter ( ) ;
654
654
const getValue = (
655
655
getFreshValue : CachifiedOptions < string > [ 'getFreshValue' ] ,
@@ -691,7 +691,7 @@ describe('cachified', () => {
691
691
} ) ;
692
692
693
693
it ( 'resolves earlier pending values with faster responses from later calls' , async ( ) => {
694
- const cache = new Map < string , CacheEntry < string > > ( ) ;
694
+ const cache = new Map < string , CacheEntry > ( ) ;
695
695
const getValue = (
696
696
getFreshValue : CachifiedOptions < string > [ 'getFreshValue' ] ,
697
697
) =>
@@ -726,7 +726,7 @@ describe('cachified', () => {
726
726
} ) ;
727
727
728
728
it ( 'uses stale cache while revalidating' , async ( ) => {
729
- const cache = new Map < string , CacheEntry < string > > ( ) ;
729
+ const cache = new Map < string , CacheEntry > ( ) ;
730
730
const reporter = createReporter ( ) ;
731
731
let i = 0 ;
732
732
const getFreshValue = jest . fn ( ( ) => `value-${ i ++ } ` ) ;
@@ -783,7 +783,7 @@ describe('cachified', () => {
783
783
} ) ;
784
784
785
785
it ( 'supports infinite stale while revalidate' , async ( ) => {
786
- const cache = new Map < string , CacheEntry < string > > ( ) ;
786
+ const cache = new Map < string , CacheEntry > ( ) ;
787
787
let i = 0 ;
788
788
const getFreshValue = jest . fn ( ( ) => `value-${ i ++ } ` ) ;
789
789
const getValue = ( ) =>
@@ -811,7 +811,7 @@ describe('cachified', () => {
811
811
} ) ;
812
812
813
813
it ( 'ignores errors when revalidating cache in the background' , async ( ) => {
814
- const cache = new Map < string , CacheEntry < string > > ( ) ;
814
+ const cache = new Map < string , CacheEntry > ( ) ;
815
815
const reporter = createReporter ( ) ;
816
816
let i = 0 ;
817
817
const getFreshValue = jest . fn ( ( ) => `value-${ i ++ } ` ) ;
@@ -867,7 +867,7 @@ describe('cachified', () => {
867
867
} ) ;
868
868
869
869
it ( 'gets fresh value in case cached one does not meet value check' , async ( ) => {
870
- const cache = new Map < string , CacheEntry < string > > ( ) ;
870
+ const cache = new Map < string , CacheEntry > ( ) ;
871
871
const reporter = createReporter ( ) ;
872
872
const reporter2 = createReporter ( ) ;
873
873
@@ -931,7 +931,7 @@ describe('cachified', () => {
931
931
} ) ;
932
932
933
933
it ( 'supports batch-getting fresh values' , async ( ) => {
934
- const cache = new Map < string , CacheEntry < string > > ( ) ;
934
+ const cache = new Map < string , CacheEntry > ( ) ;
935
935
cache . set ( 'test-2' , createCacheEntry ( 'YOLO!' , { swv : null } ) ) ;
936
936
const getValues = jest . fn ( ( indexes : number [ ] ) =>
937
937
indexes . map ( ( i ) => `value-${ i } ` ) ,
@@ -961,7 +961,7 @@ describe('cachified', () => {
961
961
} ) ;
962
962
963
963
it ( 'rejects all values when batch get fails' , async ( ) => {
964
- const cache = new Map < string , CacheEntry < string > > ( ) ;
964
+ const cache = new Map < string , CacheEntry > ( ) ;
965
965
966
966
const batch = createBatch < string , any > ( ( ) => {
967
967
throw new Error ( '🥊' ) ;
@@ -981,7 +981,7 @@ describe('cachified', () => {
981
981
} ) ;
982
982
983
983
it ( 'supports manual submission of batch' , async ( ) => {
984
- const cache = new Map < string , CacheEntry < string > > ( ) ;
984
+ const cache = new Map < string , CacheEntry > ( ) ;
985
985
const getValues = jest . fn ( ( indexes : ( number | string ) [ ] ) =>
986
986
indexes . map ( ( i ) => `value-${ i } ` ) ,
987
987
) ;
@@ -1075,7 +1075,7 @@ describe('cachified', () => {
1075
1075
} ) ;
1076
1076
1077
1077
it ( 'works with LRU cache' , async ( ) => {
1078
- const lru = new LRUCache < string , CacheEntry < string > > ( { max : 5 } ) ;
1078
+ const lru = new LRUCache < string , CacheEntry > ( { max : 5 } ) ;
1079
1079
const cache = lruCacheAdapter ( lru ) ;
1080
1080
1081
1081
const value = await cachified ( {
@@ -1265,7 +1265,7 @@ describe('cachified', () => {
1265
1265
1266
1266
describe ( 'verbose reporter' , ( ) => {
1267
1267
it ( 'logs when cached value is invalid' , async ( ) => {
1268
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1268
+ const cache = new Map < string , CacheEntry > ( ) ;
1269
1269
const logger = createLogger ( ) ;
1270
1270
cache . set ( 'test' , createCacheEntry ( 'One' ) ) ;
1271
1271
@@ -1286,7 +1286,7 @@ describe('verbose reporter', () => {
1286
1286
} ) ;
1287
1287
1288
1288
it ( 'logs when getting a cached value fails' , async ( ) => {
1289
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1289
+ const cache = new Map < string , CacheEntry > ( ) ;
1290
1290
const logger = createLogger ( ) ;
1291
1291
const getMock = jest . spyOn ( cache , 'get' ) ;
1292
1292
getMock . mockImplementationOnce ( ( ) => {
@@ -1309,7 +1309,7 @@ describe('verbose reporter', () => {
1309
1309
} ) ;
1310
1310
1311
1311
it ( 'logs when getting a fresh value fails' , async ( ) => {
1312
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1312
+ const cache = new Map < string , CacheEntry > ( ) ;
1313
1313
const logger = createLogger ( ) ;
1314
1314
1315
1315
await cachified ( {
@@ -1329,7 +1329,7 @@ describe('verbose reporter', () => {
1329
1329
} ) ;
1330
1330
1331
1331
it ( 'logs when fresh value is not written to cache' , async ( ) => {
1332
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1332
+ const cache = new Map < string , CacheEntry > ( ) ;
1333
1333
const logger = createLogger ( ) ;
1334
1334
1335
1335
await cachified ( {
@@ -1350,7 +1350,7 @@ describe('verbose reporter', () => {
1350
1350
} ) ;
1351
1351
1352
1352
it ( 'logs when writing to cache fails (using defaults)' , async ( ) => {
1353
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1353
+ const cache = new Map < string , CacheEntry > ( ) ;
1354
1354
const errorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => {
1355
1355
/* 🤫 */
1356
1356
} ) ;
@@ -1378,7 +1378,7 @@ describe('verbose reporter', () => {
1378
1378
it ( 'falls back to Date when performance is not globally available' , async ( ) => {
1379
1379
const backup = global . performance ;
1380
1380
delete ( global as any ) . performance ;
1381
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1381
+ const cache = new Map < string , CacheEntry > ( ) ;
1382
1382
const logger = createLogger ( ) ;
1383
1383
1384
1384
await cachified ( {
@@ -1393,7 +1393,7 @@ describe('verbose reporter', () => {
1393
1393
} ) ;
1394
1394
1395
1395
it ( 'logs when fresh value does not meet value check' , async ( ) => {
1396
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1396
+ const cache = new Map < string , CacheEntry > ( ) ;
1397
1397
const logger = createLogger ( ) ;
1398
1398
1399
1399
await cachified ( {
@@ -1413,7 +1413,7 @@ describe('verbose reporter', () => {
1413
1413
} ) ;
1414
1414
1415
1415
it ( 'logs when cache is successfully revalidated' , async ( ) => {
1416
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1416
+ const cache = new Map < string , CacheEntry > ( ) ;
1417
1417
const logger = createLogger ( ) ;
1418
1418
cache . set ( 'test' , createCacheEntry ( 'ONE' , { ttl : 5 , swv : 10 } ) ) ;
1419
1419
currentTime = 7 ;
@@ -1435,7 +1435,7 @@ describe('verbose reporter', () => {
1435
1435
} ) ;
1436
1436
1437
1437
it ( 'logs when cache revalidation fails' , async ( ) => {
1438
- const cache = new Map < string , CacheEntry < string > > ( ) ;
1438
+ const cache = new Map < string , CacheEntry > ( ) ;
1439
1439
const logger = createLogger ( ) ;
1440
1440
cache . set ( 'test' , createCacheEntry ( 'ONE' , { ttl : 5 , swv : 10 } ) ) ;
1441
1441
currentTime = 7 ;
0 commit comments