@@ -4,22 +4,25 @@ import * as os from 'os'
4
4
import * as fs from 'fs-extra'
5
5
import EventEmitter from 'events' ;
6
6
import type { KeyvStoreAdapter , StoredData } from 'keyv' ;
7
+ import { defaultDeserialize , defaultSerialize } from '@keyv/serialize' ;
7
8
8
9
export interface Options {
9
- deserialize : ( val : any ) => any ;
10
+ deserialize : ( val : string ) => any ;
10
11
dialect : string
11
- expiredCheckDelay : number ; // milliseconds
12
+ /** milliseconds */
13
+ expiredCheckDelay : number ;
12
14
filename : string ;
13
- serialize : ( val : any ) => any ;
14
- writeDelay : number ; // milliseconds
15
+ serialize : ( val : any ) => string ;
16
+ /** milliseconds */
17
+ writeDelay : number ;
15
18
}
16
19
17
20
export const defaultOpts : Options = {
18
- deserialize : JSON . parse as any as ( val : any ) => any ,
21
+ deserialize : defaultDeserialize ,
19
22
dialect : 'redis' ,
20
23
expiredCheckDelay : 24 * 3600 * 1000 , // ms
21
24
filename : `${ os . tmpdir ( ) } /keyv-file/default.json` ,
22
- serialize : JSON . stringify as any as ( val : any ) => any ,
25
+ serialize : defaultSerialize ,
23
26
writeDelay : 100 , // ms
24
27
}
25
28
@@ -185,15 +188,14 @@ export class KeyvFile extends EventEmitter implements KeyvStoreAdapter {
185
188
return Promise . resolve ( ) ;
186
189
}
187
190
188
- // @ts -ignore
189
- public * iterator ( namespace ?: string ) : AsyncGenerator < Array < string | Awaited < Value > | undefined > > {
191
+ public async * iterator ( namespace ?: string ) {
190
192
for ( const [ key , data ] of this . _cache . entries ( ) ) {
191
193
if ( key === undefined ) {
192
194
continue ;
193
195
}
194
196
// Filter by namespace if provided
195
197
if ( ! namespace || key . includes ( namespace ) ) {
196
- yield [ key , await Promise . resolve ( data . value ) ] ;
198
+ yield [ key , data . value ] ;
197
199
}
198
200
}
199
201
}
0 commit comments