11import { storageSettings } from "../index.js" ;
2- import { StorageKeys , type SessionManager } from "../types.js" ;
2+ import { SessionBase , StorageKeys , type SessionManager } from "../types.js" ;
33import { splitString } from "../utils.js" ;
44
55/**
66 * Provides a localStorage based session manager implementation for the browser.
77 * @class LocalStorage
88 */
9- export class LocalStorage < V = StorageKeys > implements SessionManager < V > {
9+ export class LocalStorage < V extends string = StorageKeys >
10+ extends SessionBase < V >
11+ implements SessionManager < V >
12+ {
1013 constructor ( ) {
14+ super ( ) ;
1115 console . warn ( "LocalStorage store should not be used in production" ) ;
1216 }
1317
14- setItems : Set < V | StorageKeys > = new Set < V > ( ) ;
18+ private internalItems : Set < V | StorageKeys > = new Set < V > ( ) ;
1519
1620 /**
1721 * Clears all items from session store.
1822 * @returns {void }
1923 */
2024 async destroySession ( ) : Promise < void > {
21- this . setItems . forEach ( ( key ) => {
25+ this . internalItems . forEach ( ( key ) => {
2226 this . removeSessionItem ( key ) ;
2327 } ) ;
2428 }
@@ -35,7 +39,7 @@ export class LocalStorage<V = StorageKeys> implements SessionManager<V> {
3539 ) : Promise < void > {
3640 // clear items first
3741 await this . removeSessionItem ( itemKey ) ;
38- this . setItems . add ( itemKey ) ;
42+ this . internalItems . add ( itemKey ) ;
3943
4044 if ( typeof itemValue === "string" ) {
4145 splitString ( itemValue , storageSettings . maxLength ) . forEach (
@@ -97,6 +101,6 @@ export class LocalStorage<V = StorageKeys> implements SessionManager<V> {
97101
98102 index ++ ;
99103 }
100- this . setItems . delete ( itemKey ) ;
104+ this . internalItems . delete ( itemKey ) ;
101105 }
102106}
0 commit comments