@@ -7,6 +7,7 @@ import { ipcRenderer } from 'electron';
77import FsHelper from '../../helpers/FsHelper' ;
88import PromiseQueue from '../../helpers/PromiseQueueHelper' ;
99import { SchemaMigration } from '../../types/SchemaMigration' ;
10+ import MigrationRunner from '../MigrationRunner' ;
1011
1112const APP_DIR =
1213 process . env . NODE_ENV === 'development'
@@ -15,19 +16,24 @@ const APP_DIR =
1516
1617let _appDataPath : string = '' ;
1718
18- export default abstract class AbstractFileRepository < T = any > {
19+ export default abstract class AbstractFileRepository < T = unknown > {
1920 dirWithProfileData : string = 'profile1' ;
2021 fileName : string = 'defaultFileName.json' ;
2122 saveInRoot : boolean = false ;
2223 schemaMigrations : SchemaMigration [ ] = [ ] ;
2324
2425 private writeFileQueue = new PromiseQueue ( ) ;
26+ private migrationRunner : MigrationRunner < T > ;
2527
2628 private get logPrefix ( ) {
2729 const filePath = ! this . saveInRoot ? this . dirWithProfileData : '' ;
2830 return `FileRepository [${ filePath } /${ this . fileName } ]:` ;
2931 }
3032
33+ constructor ( ) {
34+ this . migrationRunner = new MigrationRunner ( this . schemaMigrations ) ;
35+ }
36+
3137 static get appDataFolder ( ) {
3238 if ( _appDataPath ) {
3339 return _appDataPath ;
@@ -58,6 +64,7 @@ export default abstract class AbstractFileRepository<T = any> {
5864 const data = fs . readFileSync ( this . filePath , { encoding : 'utf-8' } ) ;
5965 // TODO handle parse error. Backup file with issues and return defaultValue
6066 const parsedData = JSON . parse ( data ) ;
67+ return this . migrationRunner . runMigration ( parsedData ) ;
6168 }
6269 return defaultValue ;
6370 }
0 commit comments