@@ -29,9 +29,12 @@ export class LocalStorageWithSchema<T> {
2929 }
3030
3131 public get ( ) : T {
32+ console . debug ( `LS ${ this . key } Getting value from localStorage` ) ;
33+
3234 const value = window . localStorage . getItem ( this . key ) ;
3335
3436 if ( value === null ) {
37+ console . debug ( `LS ${ this . key } No value found, returning fallback` ) ;
3538 return this . fallback ;
3639 }
3740
@@ -40,31 +43,45 @@ export class LocalStorageWithSchema<T> {
4043 parseJsonWithSchema ( value , this . schema , {
4144 fallback : this . fallback ,
4245 migrate : ( oldData , zodIssues ) => {
46+ console . debug ( `LS ${ this . key } Schema validation failed` ) ;
4347 migrated = true ;
4448 if ( this . migrate ) {
49+ console . debug (
50+ `LS ${ this . key } Migrating from old format to new format`
51+ ) ;
4552 return this . migrate ( oldData , zodIssues ) ;
4653 } else {
54+ console . debug (
55+ `LS ${ this . key } No migration function provided, returning fallback`
56+ ) ;
4757 return this . fallback ;
4858 }
4959 } ,
5060 } )
5161 ) ;
5262
5363 if ( error ) {
64+ console . error (
65+ `LS ${ this . key } Failed to parse from localStorage: ${ error . message } `
66+ ) ;
5467 window . localStorage . setItem ( this . key , JSON . stringify ( this . fallback ) ) ;
5568 return this . fallback ;
5669 }
5770
5871 if ( migrated || parsed === this . fallback ) {
72+ console . debug ( `LS ${ this . key } Setting in localStorage` ) ;
5973 window . localStorage . setItem ( this . key , JSON . stringify ( parsed ) ) ;
6074 }
6175
76+ console . debug ( `LS ${ this . key } Got value:` , parsed ) ;
6277 return parsed ;
6378 }
6479
6580 public set ( data : T ) : boolean {
6681 try {
82+ console . debug ( `LS ${ this . key } Parsing to set in localStorage` ) ;
6783 const parsed = this . schema . parse ( data ) ;
84+ console . debug ( `LS ${ this . key } Setting in localStorage` ) ;
6885 window . localStorage . setItem ( this . key , JSON . stringify ( parsed ) ) ;
6986 return true ;
7087 } catch ( e ) {
0 commit comments