1
1
import { storageSettings } from "../index.js" ;
2
- import { StorageKeys , type SessionManager } from "../types.js" ;
2
+ import { SessionBase , StorageKeys , type SessionManager } from "../types.js" ;
3
3
import { splitString } from "../utils.js" ;
4
4
5
5
/**
6
6
* Provides a localStorage based session manager implementation for the browser.
7
7
* @class LocalStorage
8
8
*/
9
- export class LocalStorage < V = StorageKeys > implements SessionManager < V > {
9
+ export class LocalStorage < V extends string = StorageKeys > extends SessionBase < V > implements SessionManager < V > {
10
10
constructor ( ) {
11
+ super ( ) ;
11
12
console . warn ( "LocalStorage store should not be used in production" ) ;
12
13
}
13
14
14
- setItems : Set < V | StorageKeys > = new Set < V > ( ) ;
15
+ private internalItems : Set < V | StorageKeys > = new Set < V > ( ) ;
15
16
16
17
/**
17
18
* Clears all items from session store.
18
19
* @returns {void }
19
20
*/
20
21
async destroySession ( ) : Promise < void > {
21
- this . setItems . forEach ( ( key ) => {
22
+ this . internalItems . forEach ( ( key ) => {
22
23
this . removeSessionItem ( key ) ;
23
24
} ) ;
24
25
}
@@ -35,7 +36,7 @@ export class LocalStorage<V = StorageKeys> implements SessionManager<V> {
35
36
) : Promise < void > {
36
37
// clear items first
37
38
await this . removeSessionItem ( itemKey ) ;
38
- this . setItems . add ( itemKey ) ;
39
+ this . internalItems . add ( itemKey ) ;
39
40
40
41
if ( typeof itemValue === "string" ) {
41
42
splitString ( itemValue , storageSettings . maxLength ) . forEach (
@@ -97,6 +98,6 @@ export class LocalStorage<V = StorageKeys> implements SessionManager<V> {
97
98
98
99
index ++ ;
99
100
}
100
- this . setItems . delete ( itemKey ) ;
101
+ this . internalItems . delete ( itemKey ) ;
101
102
}
102
103
}
0 commit comments