11import { pathExists , outputJSON , readJSON , readJSONSync } from "fs-extra" ;
22import { join } from "path" ;
33import {
4- clearLocalDbConfig ,
54 cloneDbConfig ,
65 DbConfig ,
7- initializeLocalDbConfig ,
8- removeLocalDb ,
9- removeLocalList ,
106 removeRemoteList ,
117 removeRemoteOwner ,
128 removeRemoteRepo ,
13- renameLocalDb ,
14- renameLocalList ,
159 renameRemoteList ,
1610 SelectedDbItem ,
1711 DB_CONFIG_VERSION ,
@@ -30,13 +24,7 @@ import {
3024 DbConfigValidationErrorKind ,
3125} from "../db-validation-errors" ;
3226import { ValueResult } from "../../common/value-result" ;
33- import {
34- LocalDatabaseDbItem ,
35- LocalListDbItem ,
36- RemoteUserDefinedListDbItem ,
37- DbItem ,
38- DbItemKind ,
39- } from "../db-item" ;
27+ import { RemoteUserDefinedListDbItem , DbItem , DbItemKind } from "../db-item" ;
4028
4129export class DbConfigStore extends DisposableObject {
4230 public static readonly databaseConfigFileName = "databases.json" ;
@@ -119,20 +107,9 @@ export class DbConfigStore extends DisposableObject {
119107 let config : DbConfig ;
120108
121109 switch ( dbItem . kind ) {
122- case DbItemKind . LocalList :
123- config = removeLocalList ( this . config , dbItem . listName ) ;
124- break ;
125110 case DbItemKind . RemoteUserDefinedList :
126111 config = removeRemoteList ( this . config , dbItem . listName ) ;
127112 break ;
128- case DbItemKind . LocalDatabase :
129- // When we start using local databases these need to be removed from disk as well.
130- config = removeLocalDb (
131- this . config ,
132- dbItem . databaseName ,
133- dbItem . parentListName ,
134- ) ;
135- break ;
136113 case DbItemKind . RemoteRepo :
137114 config = removeRemoteRepo (
138115 this . config ,
@@ -229,22 +206,6 @@ export class DbConfigStore extends DisposableObject {
229206 await this . writeConfig ( config ) ;
230207 }
231208
232- public async addLocalList ( listName : string ) : Promise < void > {
233- if ( ! this . config ) {
234- throw Error ( "Cannot add local list if config is not loaded" ) ;
235- }
236-
237- this . validateLocalListName ( listName ) ;
238-
239- const config = cloneDbConfig ( this . config ) ;
240- config . databases . local . lists . push ( {
241- name : listName ,
242- databases : [ ] ,
243- } ) ;
244-
245- await this . writeConfig ( config ) ;
246- }
247-
248209 public async addRemoteList ( listName : string ) : Promise < void > {
249210 if ( ! this . config ) {
250211 throw Error ( "Cannot add variant analysis list if config is not loaded" ) ;
@@ -261,25 +222,6 @@ export class DbConfigStore extends DisposableObject {
261222 await this . writeConfig ( config ) ;
262223 }
263224
264- public async renameLocalList (
265- currentDbItem : LocalListDbItem ,
266- newName : string ,
267- ) {
268- if ( ! this . config ) {
269- throw Error ( "Cannot rename local list if config is not loaded" ) ;
270- }
271-
272- this . validateLocalListName ( newName ) ;
273-
274- const updatedConfig = renameLocalList (
275- this . config ,
276- currentDbItem . listName ,
277- newName ,
278- ) ;
279-
280- await this . writeConfig ( updatedConfig ) ;
281- }
282-
283225 public async renameRemoteList (
284226 currentDbItem : RemoteUserDefinedListDbItem ,
285227 newName : string ,
@@ -301,27 +243,6 @@ export class DbConfigStore extends DisposableObject {
301243 await this . writeConfig ( updatedConfig ) ;
302244 }
303245
304- public async renameLocalDb (
305- currentDbItem : LocalDatabaseDbItem ,
306- newName : string ,
307- parentListName ?: string ,
308- ) : Promise < void > {
309- if ( ! this . config ) {
310- throw Error ( "Cannot rename local db if config is not loaded" ) ;
311- }
312-
313- this . validateLocalDbName ( newName ) ;
314-
315- const updatedConfig = renameLocalDb (
316- this . config ,
317- currentDbItem . databaseName ,
318- newName ,
319- parentListName ,
320- ) ;
321-
322- await this . writeConfig ( updatedConfig ) ;
323- }
324-
325246 public doesRemoteListExist ( listName : string ) : boolean {
326247 if ( ! this . config ) {
327248 throw Error (
@@ -334,31 +255,6 @@ export class DbConfigStore extends DisposableObject {
334255 ) ;
335256 }
336257
337- public doesLocalListExist ( listName : string ) : boolean {
338- if ( ! this . config ) {
339- throw Error ( "Cannot check local list existence if config is not loaded" ) ;
340- }
341-
342- return this . config . databases . local . lists . some ( ( l ) => l . name === listName ) ;
343- }
344-
345- public doesLocalDbExist ( dbName : string , listName ?: string ) : boolean {
346- if ( ! this . config ) {
347- throw Error (
348- "Cannot check variant analysis repository existence if config is not loaded" ,
349- ) ;
350- }
351-
352- if ( listName ) {
353- return this . config . databases . local . lists . some (
354- ( l ) =>
355- l . name === listName && l . databases . some ( ( d ) => d . name === dbName ) ,
356- ) ;
357- }
358-
359- return this . config . databases . local . databases . some ( ( d ) => d . name === dbName ) ;
360- }
361-
362258 public doesRemoteDbExist ( dbName : string , listName ?: string ) : boolean {
363259 if ( ! this . config ) {
364260 throw Error (
@@ -384,7 +280,6 @@ export class DbConfigStore extends DisposableObject {
384280 }
385281
386282 private async writeConfig ( config : DbConfig ) : Promise < void > {
387- clearLocalDbConfig ( config ) ;
388283 await outputJSON ( this . configPath , config , {
389284 spaces : 2 ,
390285 } ) ;
@@ -416,7 +311,6 @@ export class DbConfigStore extends DisposableObject {
416311 }
417312
418313 if ( newConfig ) {
419- initializeLocalDbConfig ( newConfig ) ;
420314 this . configErrors = this . configValidator . validate ( newConfig ) ;
421315 }
422316
@@ -451,7 +345,6 @@ export class DbConfigStore extends DisposableObject {
451345 }
452346
453347 if ( newConfig ) {
454- initializeLocalDbConfig ( newConfig ) ;
455348 this . configErrors = this . configValidator . validate ( newConfig ) ;
456349 }
457350
@@ -499,10 +392,6 @@ export class DbConfigStore extends DisposableObject {
499392 owners : [ ] ,
500393 repositories : [ ] ,
501394 } ,
502- local : {
503- lists : [ ] ,
504- databases : [ ] ,
505- } ,
506395 } ,
507396 selected : {
508397 kind : SelectedDbItemKind . VariantAnalysisSystemDefinedList ,
@@ -511,16 +400,6 @@ export class DbConfigStore extends DisposableObject {
511400 } ;
512401 }
513402
514- private validateLocalListName ( listName : string ) : void {
515- if ( listName === "" ) {
516- throw Error ( "List name cannot be empty" ) ;
517- }
518-
519- if ( this . doesLocalListExist ( listName ) ) {
520- throw Error ( `A local list with the name '${ listName } ' already exists` ) ;
521- }
522- }
523-
524403 private validateRemoteListName ( listName : string ) : void {
525404 if ( listName === "" ) {
526405 throw Error ( "List name cannot be empty" ) ;
@@ -532,14 +411,4 @@ export class DbConfigStore extends DisposableObject {
532411 ) ;
533412 }
534413 }
535-
536- private validateLocalDbName ( dbName : string ) : void {
537- if ( dbName === "" ) {
538- throw Error ( "Database name cannot be empty" ) ;
539- }
540-
541- if ( this . doesLocalDbExist ( dbName ) ) {
542- throw Error ( `A local database with the name '${ dbName } ' already exists` ) ;
543- }
544- }
545414}
0 commit comments