Remove from other files
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import { pathExists, outputJSON, readJSON, readJSONSync } from "fs-extra";
|
||||
import { join } from "path";
|
||||
import {
|
||||
clearLocalDbConfig,
|
||||
cloneDbConfig,
|
||||
DbConfig,
|
||||
initializeLocalDbConfig,
|
||||
removeLocalDb,
|
||||
removeLocalList,
|
||||
removeRemoteList,
|
||||
removeRemoteOwner,
|
||||
removeRemoteRepo,
|
||||
renameLocalDb,
|
||||
renameLocalList,
|
||||
renameRemoteList,
|
||||
SelectedDbItem,
|
||||
DB_CONFIG_VERSION,
|
||||
@@ -30,13 +24,7 @@ import {
|
||||
DbConfigValidationErrorKind,
|
||||
} from "../db-validation-errors";
|
||||
import { ValueResult } from "../../common/value-result";
|
||||
import {
|
||||
LocalDatabaseDbItem,
|
||||
LocalListDbItem,
|
||||
RemoteUserDefinedListDbItem,
|
||||
DbItem,
|
||||
DbItemKind,
|
||||
} from "../db-item";
|
||||
import { RemoteUserDefinedListDbItem, DbItem, DbItemKind } from "../db-item";
|
||||
|
||||
export class DbConfigStore extends DisposableObject {
|
||||
public static readonly databaseConfigFileName = "databases.json";
|
||||
@@ -119,20 +107,9 @@ export class DbConfigStore extends DisposableObject {
|
||||
let config: DbConfig;
|
||||
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.LocalList:
|
||||
config = removeLocalList(this.config, dbItem.listName);
|
||||
break;
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
config = removeRemoteList(this.config, dbItem.listName);
|
||||
break;
|
||||
case DbItemKind.LocalDatabase:
|
||||
// When we start using local databases these need to be removed from disk as well.
|
||||
config = removeLocalDb(
|
||||
this.config,
|
||||
dbItem.databaseName,
|
||||
dbItem.parentListName,
|
||||
);
|
||||
break;
|
||||
case DbItemKind.RemoteRepo:
|
||||
config = removeRemoteRepo(
|
||||
this.config,
|
||||
@@ -229,22 +206,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
public async addLocalList(listName: string): Promise<void> {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot add local list if config is not loaded");
|
||||
}
|
||||
|
||||
this.validateLocalListName(listName);
|
||||
|
||||
const config = cloneDbConfig(this.config);
|
||||
config.databases.local.lists.push({
|
||||
name: listName,
|
||||
databases: [],
|
||||
});
|
||||
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
public async addRemoteList(listName: string): Promise<void> {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot add variant analysis list if config is not loaded");
|
||||
@@ -261,25 +222,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
await this.writeConfig(config);
|
||||
}
|
||||
|
||||
public async renameLocalList(
|
||||
currentDbItem: LocalListDbItem,
|
||||
newName: string,
|
||||
) {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot rename local list if config is not loaded");
|
||||
}
|
||||
|
||||
this.validateLocalListName(newName);
|
||||
|
||||
const updatedConfig = renameLocalList(
|
||||
this.config,
|
||||
currentDbItem.listName,
|
||||
newName,
|
||||
);
|
||||
|
||||
await this.writeConfig(updatedConfig);
|
||||
}
|
||||
|
||||
public async renameRemoteList(
|
||||
currentDbItem: RemoteUserDefinedListDbItem,
|
||||
newName: string,
|
||||
@@ -301,27 +243,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
await this.writeConfig(updatedConfig);
|
||||
}
|
||||
|
||||
public async renameLocalDb(
|
||||
currentDbItem: LocalDatabaseDbItem,
|
||||
newName: string,
|
||||
parentListName?: string,
|
||||
): Promise<void> {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot rename local db if config is not loaded");
|
||||
}
|
||||
|
||||
this.validateLocalDbName(newName);
|
||||
|
||||
const updatedConfig = renameLocalDb(
|
||||
this.config,
|
||||
currentDbItem.databaseName,
|
||||
newName,
|
||||
parentListName,
|
||||
);
|
||||
|
||||
await this.writeConfig(updatedConfig);
|
||||
}
|
||||
|
||||
public doesRemoteListExist(listName: string): boolean {
|
||||
if (!this.config) {
|
||||
throw Error(
|
||||
@@ -334,31 +255,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
);
|
||||
}
|
||||
|
||||
public doesLocalListExist(listName: string): boolean {
|
||||
if (!this.config) {
|
||||
throw Error("Cannot check local list existence if config is not loaded");
|
||||
}
|
||||
|
||||
return this.config.databases.local.lists.some((l) => l.name === listName);
|
||||
}
|
||||
|
||||
public doesLocalDbExist(dbName: string, listName?: string): boolean {
|
||||
if (!this.config) {
|
||||
throw Error(
|
||||
"Cannot check variant analysis repository existence if config is not loaded",
|
||||
);
|
||||
}
|
||||
|
||||
if (listName) {
|
||||
return this.config.databases.local.lists.some(
|
||||
(l) =>
|
||||
l.name === listName && l.databases.some((d) => d.name === dbName),
|
||||
);
|
||||
}
|
||||
|
||||
return this.config.databases.local.databases.some((d) => d.name === dbName);
|
||||
}
|
||||
|
||||
public doesRemoteDbExist(dbName: string, listName?: string): boolean {
|
||||
if (!this.config) {
|
||||
throw Error(
|
||||
@@ -384,7 +280,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
}
|
||||
|
||||
private async writeConfig(config: DbConfig): Promise<void> {
|
||||
clearLocalDbConfig(config);
|
||||
await outputJSON(this.configPath, config, {
|
||||
spaces: 2,
|
||||
});
|
||||
@@ -416,7 +311,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
}
|
||||
|
||||
if (newConfig) {
|
||||
initializeLocalDbConfig(newConfig);
|
||||
this.configErrors = this.configValidator.validate(newConfig);
|
||||
}
|
||||
|
||||
@@ -451,7 +345,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
}
|
||||
|
||||
if (newConfig) {
|
||||
initializeLocalDbConfig(newConfig);
|
||||
this.configErrors = this.configValidator.validate(newConfig);
|
||||
}
|
||||
|
||||
@@ -499,10 +392,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
owners: [],
|
||||
repositories: [],
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: [],
|
||||
},
|
||||
},
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.VariantAnalysisSystemDefinedList,
|
||||
@@ -511,16 +400,6 @@ export class DbConfigStore extends DisposableObject {
|
||||
};
|
||||
}
|
||||
|
||||
private validateLocalListName(listName: string): void {
|
||||
if (listName === "") {
|
||||
throw Error("List name cannot be empty");
|
||||
}
|
||||
|
||||
if (this.doesLocalListExist(listName)) {
|
||||
throw Error(`A local list with the name '${listName}' already exists`);
|
||||
}
|
||||
}
|
||||
|
||||
private validateRemoteListName(listName: string): void {
|
||||
if (listName === "") {
|
||||
throw Error("List name cannot be empty");
|
||||
@@ -532,14 +411,4 @@ export class DbConfigStore extends DisposableObject {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private validateLocalDbName(dbName: string): void {
|
||||
if (dbName === "") {
|
||||
throw Error("Database name cannot be empty");
|
||||
}
|
||||
|
||||
if (this.doesLocalDbExist(dbName)) {
|
||||
throw Error(`A local database with the name '${dbName}' already exists`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { readJsonSync } from "fs-extra";
|
||||
import { resolve } from "path";
|
||||
import Ajv, { ValidateFunction } from "ajv";
|
||||
import { clearLocalDbConfig, DbConfig } from "./db-config";
|
||||
import { DbConfig } from "./db-config";
|
||||
import { findDuplicateStrings } from "../../common/text-utils";
|
||||
import {
|
||||
DbConfigValidationError,
|
||||
@@ -19,8 +19,6 @@ export class DbConfigValidator {
|
||||
}
|
||||
|
||||
public validate(dbConfig: DbConfig): DbConfigValidationError[] {
|
||||
const localDbs = clearLocalDbConfig(dbConfig);
|
||||
|
||||
this.validateSchemaFn(dbConfig);
|
||||
|
||||
if (this.validateSchemaFn.errors) {
|
||||
@@ -30,13 +28,6 @@ export class DbConfigValidator {
|
||||
}));
|
||||
}
|
||||
|
||||
// Add any local db config back so that we have a config
|
||||
// object that respects its type and validation can happen
|
||||
// as normal.
|
||||
if (localDbs) {
|
||||
dbConfig.databases.local = localDbs;
|
||||
}
|
||||
|
||||
return [
|
||||
...this.validateDbListNames(dbConfig),
|
||||
...this.validateDbNames(dbConfig),
|
||||
@@ -55,14 +46,6 @@ export class DbConfigValidator {
|
||||
)}`,
|
||||
});
|
||||
|
||||
const duplicateLocalDbLists = findDuplicateStrings(
|
||||
dbConfig.databases.local.lists.map((n) => n.name),
|
||||
);
|
||||
|
||||
if (duplicateLocalDbLists.length > 0) {
|
||||
errors.push(buildError(duplicateLocalDbLists));
|
||||
}
|
||||
|
||||
const duplicateRemoteDbLists = findDuplicateStrings(
|
||||
dbConfig.databases.variantAnalysis.repositoryLists.map((n) => n.name),
|
||||
);
|
||||
@@ -81,14 +64,6 @@ export class DbConfigValidator {
|
||||
message: `There are databases with the same name: ${dups.join(", ")}`,
|
||||
});
|
||||
|
||||
const duplicateLocalDbs = findDuplicateStrings(
|
||||
dbConfig.databases.local.databases.map((d) => d.name),
|
||||
);
|
||||
|
||||
if (duplicateLocalDbs.length > 0) {
|
||||
errors.push(buildError(duplicateLocalDbs));
|
||||
}
|
||||
|
||||
const duplicateRemoteDbs = findDuplicateStrings(
|
||||
dbConfig.databases.variantAnalysis.repositories,
|
||||
);
|
||||
@@ -111,13 +86,6 @@ export class DbConfigValidator {
|
||||
)}`,
|
||||
});
|
||||
|
||||
for (const list of dbConfig.databases.local.lists) {
|
||||
const dups = findDuplicateStrings(list.databases.map((d) => d.name));
|
||||
if (dups.length > 0) {
|
||||
errors.push(buildError(list.name, dups));
|
||||
}
|
||||
}
|
||||
|
||||
for (const list of dbConfig.databases.variantAnalysis.repositoryLists) {
|
||||
const dups = findDuplicateStrings(list.repositories);
|
||||
if (dups.length > 0) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Contains models and consts for the data we want to store in the database config.
|
||||
// Changes to these models should be done carefully and account for backwards compatibility of data.
|
||||
|
||||
import { DatabaseOrigin } from "../local-databases/database-origin";
|
||||
|
||||
export const DB_CONFIG_VERSION = 1;
|
||||
|
||||
export interface DbConfig {
|
||||
@@ -13,37 +11,21 @@ export interface DbConfig {
|
||||
|
||||
interface DbConfigDatabases {
|
||||
variantAnalysis: RemoteDbConfig;
|
||||
local: LocalDbConfig;
|
||||
}
|
||||
|
||||
export type SelectedDbItem =
|
||||
| SelectedLocalUserDefinedList
|
||||
| SelectedLocalDatabase
|
||||
| SelectedRemoteSystemDefinedList
|
||||
| SelectedVariantAnalysisUserDefinedList
|
||||
| SelectedRemoteOwner
|
||||
| SelectedRemoteRepository;
|
||||
|
||||
export enum SelectedDbItemKind {
|
||||
LocalUserDefinedList = "localUserDefinedList",
|
||||
LocalDatabase = "localDatabase",
|
||||
VariantAnalysisSystemDefinedList = "variantAnalysisSystemDefinedList",
|
||||
VariantAnalysisUserDefinedList = "variantAnalysisUserDefinedList",
|
||||
VariantAnalysisOwner = "variantAnalysisOwner",
|
||||
VariantAnalysisRepository = "variantAnalysisRepository",
|
||||
}
|
||||
|
||||
interface SelectedLocalUserDefinedList {
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList;
|
||||
listName: string;
|
||||
}
|
||||
|
||||
interface SelectedLocalDatabase {
|
||||
kind: SelectedDbItemKind.LocalDatabase;
|
||||
databaseName: string;
|
||||
listName?: string;
|
||||
}
|
||||
|
||||
interface SelectedRemoteSystemDefinedList {
|
||||
kind: SelectedDbItemKind.VariantAnalysisSystemDefinedList;
|
||||
listName: string;
|
||||
@@ -76,24 +58,6 @@ export interface RemoteRepositoryList {
|
||||
repositories: string[];
|
||||
}
|
||||
|
||||
interface LocalDbConfig {
|
||||
lists: LocalList[];
|
||||
databases: LocalDatabase[];
|
||||
}
|
||||
|
||||
export interface LocalList {
|
||||
name: string;
|
||||
databases: LocalDatabase[];
|
||||
}
|
||||
|
||||
export interface LocalDatabase {
|
||||
name: string;
|
||||
dateAdded: number;
|
||||
language: string;
|
||||
origin: DatabaseOrigin;
|
||||
storagePath: string;
|
||||
}
|
||||
|
||||
export function cloneDbConfig(config: DbConfig): DbConfig {
|
||||
return {
|
||||
version: config.version,
|
||||
@@ -108,13 +72,6 @@ export function cloneDbConfig(config: DbConfig): DbConfig {
|
||||
owners: [...config.databases.variantAnalysis.owners],
|
||||
repositories: [...config.databases.variantAnalysis.repositories],
|
||||
},
|
||||
local: {
|
||||
lists: config.databases.local.lists.map((list) => ({
|
||||
name: list.name,
|
||||
databases: list.databases.map((db) => ({ ...db })),
|
||||
})),
|
||||
databases: config.databases.local.databases.map((db) => ({ ...db })),
|
||||
},
|
||||
},
|
||||
selected: config.selected
|
||||
? cloneDbConfigSelectedItem(config.selected)
|
||||
@@ -122,28 +79,6 @@ export function cloneDbConfig(config: DbConfig): DbConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export function renameLocalList(
|
||||
originalConfig: DbConfig,
|
||||
currentListName: string,
|
||||
newListName: string,
|
||||
): DbConfig {
|
||||
const config = cloneDbConfig(originalConfig);
|
||||
|
||||
const list = getLocalList(config, currentListName);
|
||||
list.name = newListName;
|
||||
|
||||
if (
|
||||
config.selected?.kind === SelectedDbItemKind.LocalUserDefinedList ||
|
||||
config.selected?.kind === SelectedDbItemKind.LocalDatabase
|
||||
) {
|
||||
if (config.selected.listName === currentListName) {
|
||||
config.selected.listName = newListName;
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function renameRemoteList(
|
||||
originalConfig: DbConfig,
|
||||
currentListName: string,
|
||||
@@ -167,67 +102,6 @@ export function renameRemoteList(
|
||||
return config;
|
||||
}
|
||||
|
||||
export function renameLocalDb(
|
||||
originalConfig: DbConfig,
|
||||
currentDbName: string,
|
||||
newDbName: string,
|
||||
parentListName?: string,
|
||||
): DbConfig {
|
||||
const config = cloneDbConfig(originalConfig);
|
||||
|
||||
if (parentListName) {
|
||||
const list = getLocalList(config, parentListName);
|
||||
const dbIndex = list.databases.findIndex((db) => db.name === currentDbName);
|
||||
if (dbIndex === -1) {
|
||||
throw Error(
|
||||
`Cannot find database '${currentDbName}' in list '${parentListName}'`,
|
||||
);
|
||||
}
|
||||
list.databases[dbIndex].name = newDbName;
|
||||
} else {
|
||||
const dbIndex = config.databases.local.databases.findIndex(
|
||||
(db) => db.name === currentDbName,
|
||||
);
|
||||
if (dbIndex === -1) {
|
||||
throw Error(`Cannot find database '${currentDbName}' in local databases`);
|
||||
}
|
||||
config.databases.local.databases[dbIndex].name = newDbName;
|
||||
}
|
||||
|
||||
if (
|
||||
config.selected?.kind === SelectedDbItemKind.LocalDatabase &&
|
||||
config.selected.databaseName === currentDbName
|
||||
) {
|
||||
config.selected.databaseName = newDbName;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function removeLocalList(
|
||||
originalConfig: DbConfig,
|
||||
listName: string,
|
||||
): DbConfig {
|
||||
const config = cloneDbConfig(originalConfig);
|
||||
|
||||
config.databases.local.lists = config.databases.local.lists.filter(
|
||||
(list) => list.name !== listName,
|
||||
);
|
||||
|
||||
if (config.selected?.kind === SelectedDbItemKind.LocalUserDefinedList) {
|
||||
config.selected = undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
config.selected?.kind === SelectedDbItemKind.LocalDatabase &&
|
||||
config.selected?.listName === listName
|
||||
) {
|
||||
config.selected = undefined;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function removeRemoteList(
|
||||
originalConfig: DbConfig,
|
||||
listName: string,
|
||||
@@ -255,35 +129,6 @@ export function removeRemoteList(
|
||||
return config;
|
||||
}
|
||||
|
||||
export function removeLocalDb(
|
||||
originalConfig: DbConfig,
|
||||
databaseName: string,
|
||||
parentListName?: string,
|
||||
): DbConfig {
|
||||
const config = cloneDbConfig(originalConfig);
|
||||
|
||||
if (parentListName) {
|
||||
const parentList = getLocalList(config, parentListName);
|
||||
parentList.databases = parentList.databases.filter(
|
||||
(db) => db.name !== databaseName,
|
||||
);
|
||||
} else {
|
||||
config.databases.local.databases = config.databases.local.databases.filter(
|
||||
(db) => db.name !== databaseName,
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
config.selected?.kind === SelectedDbItemKind.LocalDatabase &&
|
||||
config.selected?.databaseName === databaseName &&
|
||||
config.selected?.listName === parentListName
|
||||
) {
|
||||
config.selected = undefined;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function removeRemoteRepo(
|
||||
originalConfig: DbConfig,
|
||||
repoFullName: string,
|
||||
@@ -333,51 +178,8 @@ export function removeRemoteOwner(
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes local db config from a db config object, if one is set.
|
||||
* We do this because we don't want to expose this feature to users
|
||||
* yet (since it's only partially implemented), but we also don't want
|
||||
* to remove all the code we've already implemented.
|
||||
* @param config The config object to change.
|
||||
* @returns Any removed local db config.
|
||||
*/
|
||||
export function clearLocalDbConfig(
|
||||
config: DbConfig,
|
||||
): LocalDbConfig | undefined {
|
||||
let localDbs = undefined;
|
||||
|
||||
if (config && config.databases && config.databases.local) {
|
||||
localDbs = config.databases.local;
|
||||
delete (config.databases as any).local;
|
||||
}
|
||||
|
||||
return localDbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the local db config, if the config object contains
|
||||
* database configuration.
|
||||
* @param config The config object to change.
|
||||
*/
|
||||
export function initializeLocalDbConfig(config: DbConfig): void {
|
||||
if (config.databases) {
|
||||
config.databases.local = { lists: [], databases: [] };
|
||||
}
|
||||
}
|
||||
|
||||
function cloneDbConfigSelectedItem(selected: SelectedDbItem): SelectedDbItem {
|
||||
switch (selected.kind) {
|
||||
case SelectedDbItemKind.LocalUserDefinedList:
|
||||
return {
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: selected.listName,
|
||||
};
|
||||
case SelectedDbItemKind.LocalDatabase:
|
||||
return {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: selected.databaseName,
|
||||
listName: selected.listName,
|
||||
};
|
||||
case SelectedDbItemKind.VariantAnalysisSystemDefinedList:
|
||||
return {
|
||||
kind: SelectedDbItemKind.VariantAnalysisSystemDefinedList,
|
||||
@@ -402,16 +204,6 @@ function cloneDbConfigSelectedItem(selected: SelectedDbItem): SelectedDbItem {
|
||||
}
|
||||
}
|
||||
|
||||
function getLocalList(config: DbConfig, listName: string): LocalList {
|
||||
const list = config.databases.local.lists.find((l) => l.name === listName);
|
||||
|
||||
if (!list) {
|
||||
throw Error(`Cannot find local list '${listName}'`);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
function getRemoteList(
|
||||
config: DbConfig,
|
||||
listName: string,
|
||||
|
||||
@@ -1,27 +1,14 @@
|
||||
import { DbItem, DbItemKind, flattenDbItems } from "./db-item";
|
||||
|
||||
export type ExpandedDbItem =
|
||||
| RootLocalExpandedDbItem
|
||||
| LocalUserDefinedListExpandedDbItem
|
||||
| RootRemoteExpandedDbItem
|
||||
| RemoteUserDefinedListExpandedDbItem;
|
||||
|
||||
export enum ExpandedDbItemKind {
|
||||
RootLocal = "rootLocal",
|
||||
LocalUserDefinedList = "localUserDefinedList",
|
||||
RootRemote = "rootRemote",
|
||||
RemoteUserDefinedList = "remoteUserDefinedList",
|
||||
}
|
||||
|
||||
interface RootLocalExpandedDbItem {
|
||||
kind: ExpandedDbItemKind.RootLocal;
|
||||
}
|
||||
|
||||
interface LocalUserDefinedListExpandedDbItem {
|
||||
kind: ExpandedDbItemKind.LocalUserDefinedList;
|
||||
listName: string;
|
||||
}
|
||||
|
||||
interface RootRemoteExpandedDbItem {
|
||||
kind: ExpandedDbItemKind.RootRemote;
|
||||
}
|
||||
@@ -80,13 +67,6 @@ export function cleanNonExistentExpandedItems(
|
||||
|
||||
function mapDbItemToExpandedDbItem(dbItem: DbItem): ExpandedDbItem {
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.RootLocal:
|
||||
return { kind: ExpandedDbItemKind.RootLocal };
|
||||
case DbItemKind.LocalList:
|
||||
return {
|
||||
kind: ExpandedDbItemKind.LocalUserDefinedList,
|
||||
listName: dbItem.listName,
|
||||
};
|
||||
case DbItemKind.RootRemote:
|
||||
return { kind: ExpandedDbItemKind.RootRemote };
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
@@ -104,13 +84,6 @@ function isDbItemEqualToExpandedDbItem(
|
||||
expandedDbItem: ExpandedDbItem,
|
||||
) {
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.RootLocal:
|
||||
return expandedDbItem.kind === ExpandedDbItemKind.RootLocal;
|
||||
case DbItemKind.LocalList:
|
||||
return (
|
||||
expandedDbItem.kind === ExpandedDbItemKind.LocalUserDefinedList &&
|
||||
expandedDbItem.listName === dbItem.listName
|
||||
);
|
||||
case DbItemKind.RootRemote:
|
||||
return expandedDbItem.kind === ExpandedDbItemKind.RootRemote;
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
@@ -118,7 +91,6 @@ function isDbItemEqualToExpandedDbItem(
|
||||
expandedDbItem.kind === ExpandedDbItemKind.RemoteUserDefinedList &&
|
||||
expandedDbItem.listName === dbItem.listName
|
||||
);
|
||||
case DbItemKind.LocalDatabase:
|
||||
case DbItemKind.RemoteSystemDefinedList:
|
||||
case DbItemKind.RemoteOwner:
|
||||
case DbItemKind.RemoteRepo:
|
||||
|
||||
@@ -2,17 +2,13 @@ import { DbItem, DbItemKind } from "./db-item";
|
||||
|
||||
export function getDbItemName(dbItem: DbItem): string | undefined {
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.RootLocal:
|
||||
case DbItemKind.RootRemote:
|
||||
return undefined;
|
||||
case DbItemKind.LocalList:
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
case DbItemKind.RemoteSystemDefinedList:
|
||||
return dbItem.listName;
|
||||
case DbItemKind.RemoteOwner:
|
||||
return dbItem.ownerName;
|
||||
case DbItemKind.LocalDatabase:
|
||||
return dbItem.databaseName;
|
||||
case DbItemKind.RemoteRepo:
|
||||
return dbItem.repoFullName;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { DbItem, DbItemKind, LocalDbItem, RemoteDbItem } from "./db-item";
|
||||
import { DbItem, DbItemKind, RemoteDbItem } from "./db-item";
|
||||
import { SelectedDbItem, SelectedDbItemKind } from "./config/db-config";
|
||||
|
||||
export function getSelectedDbItem(dbItems: DbItem[]): DbItem | undefined {
|
||||
for (const dbItem of dbItems) {
|
||||
if (
|
||||
dbItem.kind === DbItemKind.RootRemote ||
|
||||
dbItem.kind === DbItemKind.RootLocal
|
||||
) {
|
||||
if (dbItem.kind === DbItemKind.RootRemote) {
|
||||
for (const child of dbItem.children) {
|
||||
const selectedItem = extractSelected(child);
|
||||
if (selectedItem) {
|
||||
@@ -23,20 +20,11 @@ export function getSelectedDbItem(dbItems: DbItem[]): DbItem | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function extractSelected(
|
||||
dbItem: RemoteDbItem | LocalDbItem,
|
||||
): DbItem | undefined {
|
||||
function extractSelected(dbItem: RemoteDbItem): DbItem | undefined {
|
||||
if (dbItem.selected) {
|
||||
return dbItem;
|
||||
}
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.LocalList:
|
||||
for (const database of dbItem.databases) {
|
||||
if (database.selected) {
|
||||
return database;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
for (const repo of dbItem.repos) {
|
||||
if (repo.selected) {
|
||||
@@ -52,17 +40,10 @@ export function mapDbItemToSelectedDbItem(
|
||||
dbItem: DbItem,
|
||||
): SelectedDbItem | undefined {
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.RootLocal:
|
||||
case DbItemKind.RootRemote:
|
||||
// Root items are not selectable.
|
||||
return undefined;
|
||||
|
||||
case DbItemKind.LocalList:
|
||||
return {
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: dbItem.listName,
|
||||
};
|
||||
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
return {
|
||||
kind: SelectedDbItemKind.VariantAnalysisUserDefinedList,
|
||||
@@ -81,13 +62,6 @@ export function mapDbItemToSelectedDbItem(
|
||||
ownerName: dbItem.ownerName,
|
||||
};
|
||||
|
||||
case DbItemKind.LocalDatabase:
|
||||
return {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: dbItem.databaseName,
|
||||
listName: dbItem?.parentListName,
|
||||
};
|
||||
|
||||
case DbItemKind.RemoteRepo:
|
||||
return {
|
||||
kind: SelectedDbItemKind.VariantAnalysisRepository,
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
// This file contains models that are used to represent the databases.
|
||||
|
||||
import { DatabaseOrigin } from "./local-databases/database-origin";
|
||||
|
||||
export enum DbItemKind {
|
||||
RootLocal = "RootLocal",
|
||||
LocalList = "LocalList",
|
||||
LocalDatabase = "LocalDatabase",
|
||||
RootRemote = "RootRemote",
|
||||
RemoteSystemDefinedList = "RemoteSystemDefinedList",
|
||||
RemoteUserDefinedList = "RemoteUserDefinedList",
|
||||
@@ -13,44 +8,13 @@ export enum DbItemKind {
|
||||
RemoteRepo = "RemoteRepo",
|
||||
}
|
||||
|
||||
export interface RootLocalDbItem {
|
||||
kind: DbItemKind.RootLocal;
|
||||
expanded: boolean;
|
||||
children: LocalDbItem[];
|
||||
}
|
||||
|
||||
export type LocalDbItem = LocalListDbItem | LocalDatabaseDbItem;
|
||||
|
||||
export interface LocalListDbItem {
|
||||
kind: DbItemKind.LocalList;
|
||||
expanded: boolean;
|
||||
selected: boolean;
|
||||
listName: string;
|
||||
databases: LocalDatabaseDbItem[];
|
||||
}
|
||||
|
||||
export interface LocalDatabaseDbItem {
|
||||
kind: DbItemKind.LocalDatabase;
|
||||
selected: boolean;
|
||||
databaseName: string;
|
||||
dateAdded: number;
|
||||
language: string;
|
||||
origin: DatabaseOrigin;
|
||||
storagePath: string;
|
||||
parentListName?: string;
|
||||
}
|
||||
|
||||
export interface RootRemoteDbItem {
|
||||
kind: DbItemKind.RootRemote;
|
||||
expanded: boolean;
|
||||
children: RemoteDbItem[];
|
||||
}
|
||||
|
||||
export type DbItem =
|
||||
| RootLocalDbItem
|
||||
| RootRemoteDbItem
|
||||
| RemoteDbItem
|
||||
| LocalDbItem;
|
||||
export type DbItem = RootRemoteDbItem | RemoteDbItem;
|
||||
|
||||
export type RemoteDbItem =
|
||||
| RemoteSystemDefinedListDbItem
|
||||
@@ -103,15 +67,13 @@ export function isRemoteRepoDbItem(dbItem: DbItem): dbItem is RemoteRepoDbItem {
|
||||
return dbItem.kind === DbItemKind.RemoteRepo;
|
||||
}
|
||||
|
||||
type SelectableDbItem = RemoteDbItem | LocalDbItem;
|
||||
type SelectableDbItem = RemoteDbItem;
|
||||
|
||||
export function isSelectableDbItem(dbItem: DbItem): dbItem is SelectableDbItem {
|
||||
return SelectableDbItemKinds.includes(dbItem.kind);
|
||||
}
|
||||
|
||||
const SelectableDbItemKinds = [
|
||||
DbItemKind.LocalList,
|
||||
DbItemKind.LocalDatabase,
|
||||
DbItemKind.RemoteSystemDefinedList,
|
||||
DbItemKind.RemoteUserDefinedList,
|
||||
DbItemKind.RemoteOwner,
|
||||
@@ -124,19 +86,12 @@ export function flattenDbItems(dbItems: DbItem[]): DbItem[] {
|
||||
for (const dbItem of dbItems) {
|
||||
allItems.push(dbItem);
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.RootLocal:
|
||||
allItems.push(...flattenDbItems(dbItem.children));
|
||||
break;
|
||||
case DbItemKind.LocalList:
|
||||
allItems.push(...flattenDbItems(dbItem.databases));
|
||||
break;
|
||||
case DbItemKind.RootRemote:
|
||||
allItems.push(...flattenDbItems(dbItem.children));
|
||||
break;
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
allItems.push(...dbItem.repos);
|
||||
break;
|
||||
case DbItemKind.LocalDatabase:
|
||||
case DbItemKind.RemoteSystemDefinedList:
|
||||
case DbItemKind.RemoteOwner:
|
||||
case DbItemKind.RemoteRepo:
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
import {
|
||||
DbConfig,
|
||||
LocalDatabase,
|
||||
LocalList,
|
||||
RemoteRepositoryList,
|
||||
SelectedDbItemKind,
|
||||
} from "./config/db-config";
|
||||
import {
|
||||
DbItemKind,
|
||||
LocalDatabaseDbItem,
|
||||
LocalListDbItem,
|
||||
RemoteOwnerDbItem,
|
||||
RemoteRepoDbItem,
|
||||
RemoteSystemDefinedListDbItem,
|
||||
RemoteUserDefinedListDbItem,
|
||||
RootLocalDbItem,
|
||||
RootRemoteDbItem,
|
||||
} from "./db-item";
|
||||
import { ExpandedDbItem, ExpandedDbItemKind } from "./db-item-expansion";
|
||||
@@ -55,28 +50,6 @@ export function createRemoteTree(
|
||||
};
|
||||
}
|
||||
|
||||
export function createLocalTree(
|
||||
dbConfig: DbConfig,
|
||||
expandedItems: ExpandedDbItem[],
|
||||
): RootLocalDbItem {
|
||||
const localLists = dbConfig.databases.local.lists.map((l) =>
|
||||
createLocalList(l, dbConfig, expandedItems),
|
||||
);
|
||||
const localDbs = dbConfig.databases.local.databases.map((l) =>
|
||||
createLocalDb(l, dbConfig),
|
||||
);
|
||||
|
||||
const expanded = expandedItems.some(
|
||||
(e) => e.kind === ExpandedDbItemKind.RootLocal,
|
||||
);
|
||||
|
||||
return {
|
||||
kind: DbItemKind.RootLocal,
|
||||
children: [...localLists, ...localDbs],
|
||||
expanded: !!expanded,
|
||||
};
|
||||
}
|
||||
|
||||
function createSystemDefinedList(
|
||||
n: number,
|
||||
dbConfig: DbConfig,
|
||||
@@ -155,51 +128,3 @@ function createRepoItem(
|
||||
parentListName: listName,
|
||||
};
|
||||
}
|
||||
|
||||
function createLocalList(
|
||||
list: LocalList,
|
||||
dbConfig: DbConfig,
|
||||
expandedItems: ExpandedDbItem[],
|
||||
): LocalListDbItem {
|
||||
const selected =
|
||||
dbConfig.selected &&
|
||||
dbConfig.selected.kind === SelectedDbItemKind.LocalUserDefinedList &&
|
||||
dbConfig.selected.listName === list.name;
|
||||
|
||||
const expanded = expandedItems.some(
|
||||
(e) =>
|
||||
e.kind === ExpandedDbItemKind.LocalUserDefinedList &&
|
||||
e.listName === list.name,
|
||||
);
|
||||
|
||||
return {
|
||||
kind: DbItemKind.LocalList,
|
||||
listName: list.name,
|
||||
databases: list.databases.map((d) => createLocalDb(d, dbConfig, list.name)),
|
||||
selected: !!selected,
|
||||
expanded: !!expanded,
|
||||
};
|
||||
}
|
||||
|
||||
function createLocalDb(
|
||||
db: LocalDatabase,
|
||||
dbConfig: DbConfig,
|
||||
listName?: string,
|
||||
): LocalDatabaseDbItem {
|
||||
const selected =
|
||||
dbConfig.selected &&
|
||||
dbConfig.selected.kind === SelectedDbItemKind.LocalDatabase &&
|
||||
dbConfig.selected.databaseName === db.name &&
|
||||
dbConfig.selected.listName === listName;
|
||||
|
||||
return {
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
databaseName: db.name,
|
||||
dateAdded: db.dateAdded,
|
||||
language: db.language,
|
||||
origin: db.origin,
|
||||
storagePath: db.storagePath,
|
||||
selected: !!selected,
|
||||
parentListName: listName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { DbItem, DbItemKind } from "../db-item";
|
||||
import {
|
||||
createDbTreeViewItemLocalDatabase,
|
||||
createDbTreeViewItemOwner,
|
||||
createDbTreeViewItemRepo,
|
||||
createDbTreeViewItemRoot,
|
||||
@@ -11,14 +10,6 @@ import {
|
||||
|
||||
export function mapDbItemToTreeViewItem(dbItem: DbItem): DbTreeViewItem {
|
||||
switch (dbItem.kind) {
|
||||
case DbItemKind.RootLocal:
|
||||
return createDbTreeViewItemRoot(
|
||||
dbItem,
|
||||
"local",
|
||||
"Local databases",
|
||||
dbItem.children.map((c) => mapDbItemToTreeViewItem(c)),
|
||||
);
|
||||
|
||||
case DbItemKind.RootRemote:
|
||||
return createDbTreeViewItemRoot(
|
||||
dbItem,
|
||||
@@ -46,19 +37,5 @@ export function mapDbItemToTreeViewItem(dbItem: DbItem): DbTreeViewItem {
|
||||
|
||||
case DbItemKind.RemoteRepo:
|
||||
return createDbTreeViewItemRepo(dbItem, dbItem.repoFullName);
|
||||
|
||||
case DbItemKind.LocalList:
|
||||
return createDbTreeViewItemUserDefinedList(
|
||||
dbItem,
|
||||
dbItem.listName,
|
||||
dbItem.databases.map(mapDbItemToTreeViewItem),
|
||||
);
|
||||
|
||||
case DbItemKind.LocalDatabase:
|
||||
return createDbTreeViewItemLocalDatabase(
|
||||
dbItem,
|
||||
dbItem.databaseName,
|
||||
dbItem.language,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,18 +29,12 @@ export function getDbItemActions(dbItem: DbItem): DbTreeViewItemAction[] {
|
||||
}
|
||||
|
||||
const dbItemKindsThatCanBeRemoved = [
|
||||
DbItemKind.LocalList,
|
||||
DbItemKind.RemoteUserDefinedList,
|
||||
DbItemKind.LocalDatabase,
|
||||
DbItemKind.RemoteRepo,
|
||||
DbItemKind.RemoteOwner,
|
||||
];
|
||||
|
||||
const dbItemKindsThatCanBeRenamed = [
|
||||
DbItemKind.LocalList,
|
||||
DbItemKind.RemoteUserDefinedList,
|
||||
DbItemKind.LocalDatabase,
|
||||
];
|
||||
const dbItemKindsThatCanBeRenamed = [DbItemKind.RemoteUserDefinedList];
|
||||
|
||||
const dbItemKindsThatCanBeOpenedOnGitHub = [
|
||||
DbItemKind.RemoteOwner,
|
||||
|
||||
@@ -2,13 +2,10 @@ import * as vscode from "vscode";
|
||||
import {
|
||||
DbItem,
|
||||
isSelectableDbItem,
|
||||
LocalDatabaseDbItem,
|
||||
LocalListDbItem,
|
||||
RemoteOwnerDbItem,
|
||||
RemoteRepoDbItem,
|
||||
RemoteSystemDefinedListDbItem,
|
||||
RemoteUserDefinedListDbItem,
|
||||
RootLocalDbItem,
|
||||
RootRemoteDbItem,
|
||||
} from "../db-item";
|
||||
import { getDbItemActions } from "./db-tree-view-item-action";
|
||||
@@ -74,7 +71,7 @@ export function createDbTreeViewItemError(
|
||||
}
|
||||
|
||||
export function createDbTreeViewItemRoot(
|
||||
dbItem: RootLocalDbItem | RootRemoteDbItem,
|
||||
dbItem: RootRemoteDbItem,
|
||||
label: string,
|
||||
tooltip: string,
|
||||
children: DbTreeViewItem[],
|
||||
@@ -105,7 +102,7 @@ export function createDbTreeViewItemSystemDefinedList(
|
||||
}
|
||||
|
||||
export function createDbTreeViewItemUserDefinedList(
|
||||
dbItem: LocalListDbItem | RemoteUserDefinedListDbItem,
|
||||
dbItem: RemoteUserDefinedListDbItem,
|
||||
listName: string,
|
||||
children: DbTreeViewItem[],
|
||||
): DbTreeViewItem {
|
||||
@@ -147,21 +144,6 @@ export function createDbTreeViewItemRepo(
|
||||
);
|
||||
}
|
||||
|
||||
export function createDbTreeViewItemLocalDatabase(
|
||||
dbItem: LocalDatabaseDbItem,
|
||||
databaseName: string,
|
||||
language: string,
|
||||
): DbTreeViewItem {
|
||||
return new DbTreeViewItem(
|
||||
dbItem,
|
||||
new vscode.ThemeIcon("database"),
|
||||
databaseName,
|
||||
`Language: ${language}`,
|
||||
vscode.TreeItemCollapsibleState.None,
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
function getCollapsibleState(
|
||||
expanded: boolean,
|
||||
): vscode.TreeItemCollapsibleState {
|
||||
|
||||
@@ -18,10 +18,6 @@ export async function getRepositorySelection(
|
||||
const selectedDbItem = dbManager.getSelectedDbItem();
|
||||
if (selectedDbItem) {
|
||||
switch (selectedDbItem.kind) {
|
||||
case DbItemKind.LocalDatabase || DbItemKind.LocalList:
|
||||
throw new UserCancellationException(
|
||||
"Local databases and lists are not supported yet.",
|
||||
);
|
||||
case DbItemKind.RemoteSystemDefinedList:
|
||||
return { repositoryLists: [selectedDbItem.listName] };
|
||||
case DbItemKind.RemoteUserDefinedList:
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import {
|
||||
DbConfig,
|
||||
LocalDatabase,
|
||||
LocalList,
|
||||
RemoteRepositoryList,
|
||||
SelectedDbItem,
|
||||
DB_CONFIG_VERSION,
|
||||
} from "../../src/databases/config/db-config";
|
||||
import { DatabaseOrigin } from "../../src/databases/local-databases/database-origin";
|
||||
|
||||
export function createDbConfig({
|
||||
remoteLists = [],
|
||||
remoteOwners = [],
|
||||
remoteRepos = [],
|
||||
localLists = [],
|
||||
localDbs = [],
|
||||
selected = undefined,
|
||||
}: {
|
||||
remoteLists?: RemoteRepositoryList[];
|
||||
remoteOwners?: string[];
|
||||
remoteRepos?: string[];
|
||||
localLists?: LocalList[];
|
||||
localDbs?: LocalDatabase[];
|
||||
selected?: SelectedDbItem;
|
||||
} = {}): DbConfig {
|
||||
return {
|
||||
@@ -32,35 +24,7 @@ export function createDbConfig({
|
||||
owners: remoteOwners,
|
||||
repositories: remoteRepos,
|
||||
},
|
||||
local: {
|
||||
lists: localLists,
|
||||
databases: localDbs,
|
||||
},
|
||||
},
|
||||
selected,
|
||||
};
|
||||
}
|
||||
|
||||
export function createLocalDbConfigItem({
|
||||
name = `database${faker.number.int()}`,
|
||||
dateAdded = faker.date.past().getTime(),
|
||||
language = `language${faker.number.int()}`,
|
||||
storagePath = `storagePath${faker.number.int()}`,
|
||||
origin = {
|
||||
type: "folder",
|
||||
},
|
||||
}: {
|
||||
name?: string;
|
||||
dateAdded?: number;
|
||||
language?: string;
|
||||
storagePath?: string;
|
||||
origin?: DatabaseOrigin;
|
||||
} = {}): LocalDatabase {
|
||||
return {
|
||||
name,
|
||||
dateAdded,
|
||||
language,
|
||||
storagePath,
|
||||
origin,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import {
|
||||
DbItemKind,
|
||||
LocalDatabaseDbItem,
|
||||
LocalDbItem,
|
||||
LocalListDbItem,
|
||||
RemoteDbItem,
|
||||
RemoteOwnerDbItem,
|
||||
RemoteRepoDbItem,
|
||||
RemoteSystemDefinedListDbItem,
|
||||
RemoteUserDefinedListDbItem,
|
||||
RootLocalDbItem,
|
||||
RootRemoteDbItem,
|
||||
} from "../../src/databases/db-item";
|
||||
import { DatabaseOrigin } from "../../src/databases/local-databases/database-origin";
|
||||
|
||||
// Root Remote Db Items
|
||||
export function createRootRemoteDbItem({
|
||||
@@ -103,66 +98,3 @@ export function createRemoteUserDefinedListDbItem({
|
||||
repos,
|
||||
};
|
||||
}
|
||||
|
||||
// Root Local Db Items
|
||||
export function createRootLocalDbItem({
|
||||
children = [],
|
||||
expanded = false,
|
||||
}: {
|
||||
children?: LocalDbItem[];
|
||||
expanded?: boolean;
|
||||
} = {}): RootLocalDbItem {
|
||||
return {
|
||||
kind: DbItemKind.RootLocal,
|
||||
children,
|
||||
expanded,
|
||||
};
|
||||
}
|
||||
|
||||
export function createLocalDatabaseDbItem({
|
||||
databaseName = `database${faker.number.int()}`,
|
||||
dateAdded = faker.date.past().getTime(),
|
||||
language = `language${faker.number.int()}`,
|
||||
storagePath = `storagePath${faker.number.int()}`,
|
||||
selected = false,
|
||||
origin = {
|
||||
type: "folder",
|
||||
},
|
||||
}: {
|
||||
databaseName?: string;
|
||||
dateAdded?: number;
|
||||
language?: string;
|
||||
storagePath?: string;
|
||||
selected?: boolean;
|
||||
origin?: DatabaseOrigin;
|
||||
} = {}): LocalDatabaseDbItem {
|
||||
return {
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
selected,
|
||||
databaseName,
|
||||
dateAdded,
|
||||
language,
|
||||
storagePath,
|
||||
origin,
|
||||
};
|
||||
}
|
||||
|
||||
export function createLocalListDbItem({
|
||||
listName = `top_${faker.number.int()}`,
|
||||
selected = false,
|
||||
expanded = false,
|
||||
databases = [],
|
||||
}: {
|
||||
listName?: string;
|
||||
databases?: LocalDatabaseDbItem[];
|
||||
selected?: boolean;
|
||||
expanded?: boolean;
|
||||
} = {}): LocalListDbItem {
|
||||
return {
|
||||
kind: DbItemKind.LocalList,
|
||||
selected,
|
||||
expanded,
|
||||
databases,
|
||||
listName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,13 +7,8 @@ import {
|
||||
SelectedDbItemKind,
|
||||
} from "../../../../src/databases/config/db-config";
|
||||
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
|
||||
import { createDbConfig } from "../../../factories/db-config-factories";
|
||||
import {
|
||||
createDbConfig,
|
||||
createLocalDbConfigItem,
|
||||
} from "../../../factories/db-config-factories";
|
||||
import {
|
||||
createLocalDatabaseDbItem,
|
||||
createLocalListDbItem,
|
||||
createRemoteOwnerDbItem,
|
||||
createRemoteRepoDbItem,
|
||||
createRemoteUserDefinedListDbItem,
|
||||
@@ -55,8 +50,6 @@ describe("db config store", () => {
|
||||
expect(config.databases.variantAnalysis.repositoryLists).toHaveLength(0);
|
||||
expect(config.databases.variantAnalysis.owners).toHaveLength(0);
|
||||
expect(config.databases.variantAnalysis.repositories).toHaveLength(0);
|
||||
expect(config.databases.local.lists).toHaveLength(0);
|
||||
expect(config.databases.local.databases).toHaveLength(0);
|
||||
expect(config.selected).toEqual({
|
||||
kind: SelectedDbItemKind.VariantAnalysisSystemDefinedList,
|
||||
listName: "top_10",
|
||||
@@ -302,26 +295,6 @@ describe("db config store", () => {
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it.skip("should add a local list", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig();
|
||||
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
|
||||
// Add
|
||||
await configStore.addLocalList("list1");
|
||||
|
||||
// Read the config file
|
||||
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
|
||||
|
||||
// Check that the config file has been updated
|
||||
const updatedLocalDbs = updatedDbConfig.databases.local;
|
||||
expect(updatedLocalDbs.lists).toHaveLength(1);
|
||||
expect(updatedLocalDbs.lists[0].name).toEqual("list1");
|
||||
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it("should add a remote list", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig();
|
||||
@@ -400,95 +373,6 @@ describe("db config store", () => {
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it.skip("should allow renaming a local list", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem(),
|
||||
createLocalDbConfigItem(),
|
||||
createLocalDbConfigItem(),
|
||||
],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
});
|
||||
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
|
||||
// Rename
|
||||
const currentDbItem = createLocalListDbItem({
|
||||
listName: "list1",
|
||||
});
|
||||
await configStore.renameLocalList(currentDbItem, "listRenamed");
|
||||
|
||||
// Read the config file
|
||||
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
|
||||
|
||||
// Check that the config file has been updated
|
||||
const updatedLocalDbs = updatedDbConfig.databases.local;
|
||||
expect(updatedLocalDbs.lists).toHaveLength(1);
|
||||
expect(updatedLocalDbs.lists[0].name).toEqual("listRenamed");
|
||||
|
||||
expect(updatedDbConfig.selected).toEqual({
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: "listRenamed",
|
||||
});
|
||||
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it.skip("should allow renaming of a local db", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
createLocalDbConfigItem({ name: "db3" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: "db1",
|
||||
listName: "list1",
|
||||
},
|
||||
});
|
||||
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
|
||||
// Rename
|
||||
const currentDbItem = createLocalDatabaseDbItem({
|
||||
databaseName: "db1",
|
||||
});
|
||||
await configStore.renameLocalDb(currentDbItem, "dbRenamed", "list1");
|
||||
|
||||
// Read the config file
|
||||
const updatedDbConfig = (await readJSON(configPath)) as DbConfig;
|
||||
|
||||
// Check that the config file has been updated
|
||||
const updatedLocalDbs = updatedDbConfig.databases.local;
|
||||
expect(updatedLocalDbs.lists).toHaveLength(1);
|
||||
expect(updatedLocalDbs.lists[0].name).toEqual("list1");
|
||||
expect(updatedLocalDbs.lists[0].databases.length).toEqual(3);
|
||||
expect(updatedLocalDbs.lists[0].databases[0].name).toEqual("dbRenamed");
|
||||
expect(updatedDbConfig.selected).toEqual({
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: "dbRenamed",
|
||||
listName: "list1",
|
||||
});
|
||||
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it("should throw if the name of a list is taken", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({
|
||||
@@ -753,28 +637,6 @@ describe("db config store", () => {
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it.skip("should return true if a local db and local list exists", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [createLocalDbConfigItem({ name: "db1" })],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
|
||||
// Check
|
||||
const doesDbExist = configStore.doesLocalDbExist("db1", "list1");
|
||||
expect(doesDbExist).toEqual(true);
|
||||
const doesListExist = configStore.doesLocalListExist("list1");
|
||||
expect(doesListExist).toEqual(true);
|
||||
|
||||
configStore.dispose();
|
||||
});
|
||||
|
||||
it("should return false if items do not exist", async () => {
|
||||
// Initial set up
|
||||
const dbConfig = createDbConfig({});
|
||||
@@ -782,10 +644,6 @@ describe("db config store", () => {
|
||||
const configStore = await initializeConfig(dbConfig, configPath, app);
|
||||
|
||||
// Check
|
||||
const doesLocalDbExist = configStore.doesLocalDbExist("db1", "list1");
|
||||
expect(doesLocalDbExist).toEqual(false);
|
||||
const doesLocalListExist = configStore.doesLocalListExist("list1");
|
||||
expect(doesLocalListExist).toEqual(false);
|
||||
const doesRemoteDbExist = configStore.doesRemoteDbExist("db1", "list1");
|
||||
expect(doesRemoteDbExist).toEqual(false);
|
||||
const doesRemoteListExist = configStore.doesRemoteListExist("list1");
|
||||
@@ -802,10 +660,6 @@ describe("db config store", () => {
|
||||
configPath: string,
|
||||
app: App,
|
||||
): Promise<DbConfigStore> {
|
||||
if (dbConfig && dbConfig.databases && dbConfig.databases.local) {
|
||||
delete (dbConfig.databases as any).local;
|
||||
}
|
||||
// const config = clearLocalDbs(dbConfig);
|
||||
await writeJSON(configPath, dbConfig);
|
||||
const configStore = new DbConfigStore(app, false);
|
||||
await configStore.initialize();
|
||||
|
||||
@@ -5,10 +5,7 @@ import {
|
||||
} from "../../../../src/databases/config/db-config";
|
||||
import { DbConfigValidator } from "../../../../src/databases/config/db-config-validator";
|
||||
import { DbConfigValidationErrorKind } from "../../../../src/databases/db-validation-errors";
|
||||
import {
|
||||
createDbConfig,
|
||||
createLocalDbConfigItem,
|
||||
} from "../../../factories/db-config-factories";
|
||||
import { createDbConfig } from "../../../factories/db-config-factories";
|
||||
|
||||
describe("db config validation", () => {
|
||||
const extensionPath = join(__dirname, "../../../..");
|
||||
@@ -104,69 +101,4 @@ describe("db config validation", () => {
|
||||
"There are databases with the same name in the repoList1 list: owner1/repo2",
|
||||
});
|
||||
});
|
||||
|
||||
it("should return error when there are multiple local db lists with the same name", async () => {
|
||||
const dbConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "dbList1",
|
||||
databases: [createLocalDbConfigItem()],
|
||||
},
|
||||
{
|
||||
name: "dbList1",
|
||||
databases: [createLocalDbConfigItem()],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const validationOutput = configValidator.validate(dbConfig);
|
||||
|
||||
expect(validationOutput).toHaveLength(1);
|
||||
expect(validationOutput[0]).toEqual({
|
||||
kind: DbConfigValidationErrorKind.DuplicateNames,
|
||||
message: "There are database lists with the same name: dbList1",
|
||||
});
|
||||
});
|
||||
|
||||
it("should return error when there are multiple local dbs with the same name", async () => {
|
||||
const dbConfig = createDbConfig({
|
||||
localDbs: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
],
|
||||
});
|
||||
|
||||
const validationOutput = configValidator.validate(dbConfig);
|
||||
|
||||
expect(validationOutput).toHaveLength(1);
|
||||
expect(validationOutput[0]).toEqual({
|
||||
kind: DbConfigValidationErrorKind.DuplicateNames,
|
||||
message: "There are databases with the same name: db1",
|
||||
});
|
||||
});
|
||||
|
||||
it("should return error when there are multiple local dbs with the same name in the same list", async () => {
|
||||
const dbConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "dbList1",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const validationOutput = configValidator.validate(dbConfig);
|
||||
|
||||
expect(validationOutput).toHaveLength(1);
|
||||
expect(validationOutput[0]).toEqual({
|
||||
kind: DbConfigValidationErrorKind.DuplicateNames,
|
||||
message:
|
||||
"There are databases with the same name in the dbList1 list: db1",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,141 +1,14 @@
|
||||
import {
|
||||
LocalList,
|
||||
RemoteRepositoryList,
|
||||
removeLocalDb,
|
||||
removeLocalList,
|
||||
removeRemoteList,
|
||||
removeRemoteOwner,
|
||||
removeRemoteRepo,
|
||||
renameLocalDb,
|
||||
renameLocalList,
|
||||
renameRemoteList,
|
||||
SelectedDbItemKind,
|
||||
} from "../../../../src/databases/config/db-config";
|
||||
import {
|
||||
createDbConfig,
|
||||
createLocalDbConfigItem,
|
||||
} from "../../../factories/db-config-factories";
|
||||
import { createDbConfig } from "../../../factories/db-config-factories";
|
||||
|
||||
describe("db config", () => {
|
||||
describe("renameLocalList", () => {
|
||||
it("should rename a local list", () => {
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalList(
|
||||
originalConfig,
|
||||
"list1",
|
||||
"listRenamed",
|
||||
);
|
||||
|
||||
expect(updatedConfig.databases.local.lists).toEqual([
|
||||
{
|
||||
name: "listRenamed",
|
||||
databases: [],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should rename a selected local list", () => {
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalList(
|
||||
originalConfig,
|
||||
"list1",
|
||||
"listRenamed",
|
||||
);
|
||||
|
||||
expect(updatedConfig.databases.local.lists).toEqual([
|
||||
{
|
||||
name: "listRenamed",
|
||||
databases: [],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
]);
|
||||
|
||||
expect(updatedConfig.selected).toEqual({
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: "listRenamed",
|
||||
});
|
||||
});
|
||||
|
||||
it("should rename a local list with a db that is selected", () => {
|
||||
const selectedLocalDb = createLocalDbConfigItem();
|
||||
const list1: LocalList = {
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem(),
|
||||
selectedLocalDb,
|
||||
createLocalDbConfigItem(),
|
||||
],
|
||||
};
|
||||
const list2: LocalList = {
|
||||
name: "list2",
|
||||
databases: [],
|
||||
};
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [list1, list2],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: selectedLocalDb.name,
|
||||
listName: list1.name,
|
||||
},
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalList(
|
||||
originalConfig,
|
||||
list1.name,
|
||||
"listRenamed",
|
||||
);
|
||||
|
||||
expect(updatedConfig.databases.local.lists.length).toEqual(2);
|
||||
expect(updatedConfig.databases.local.lists[0]).toEqual({
|
||||
...list1,
|
||||
name: "listRenamed",
|
||||
});
|
||||
expect(updatedConfig.databases.local.lists[1]).toEqual(list2);
|
||||
|
||||
expect(updatedConfig.selected).toEqual({
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: selectedLocalDb.name,
|
||||
listName: "listRenamed",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("renameRemoteList", () => {
|
||||
it("should rename a remote list", () => {
|
||||
const originalConfig = createDbConfig({
|
||||
@@ -255,205 +128,6 @@ describe("db config", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("renameLocalDb", () => {
|
||||
it("should rename a local db", () => {
|
||||
const db1 = createLocalDbConfigItem({ name: "db1" });
|
||||
const db2 = createLocalDbConfigItem({ name: "db2" });
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
localDbs: [db1, db2],
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalDb(originalConfig, "db1", "dbRenamed");
|
||||
|
||||
const updatedLocalDbs = updatedConfig.databases.local;
|
||||
const originalLocalDbs = originalConfig.databases.local;
|
||||
|
||||
expect(updatedLocalDbs.lists).toEqual(originalLocalDbs.lists);
|
||||
expect(updatedLocalDbs.databases.length).toEqual(2);
|
||||
expect(updatedLocalDbs.databases[0]).toEqual({
|
||||
...db1,
|
||||
name: "dbRenamed",
|
||||
});
|
||||
expect(updatedLocalDbs.databases[1]).toEqual(db2);
|
||||
});
|
||||
|
||||
it("should rename a local db inside a list", () => {
|
||||
const db1List1 = createLocalDbConfigItem({ name: "db1" });
|
||||
const db2List1 = createLocalDbConfigItem({ name: "db2" });
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [db1List1, db2List1],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
localDbs: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalDb(
|
||||
originalConfig,
|
||||
db1List1.name,
|
||||
"dbRenamed",
|
||||
"list1",
|
||||
);
|
||||
|
||||
const updatedLocalDbs = updatedConfig.databases.local;
|
||||
const originalLocalDbs = originalConfig.databases.local;
|
||||
expect(updatedLocalDbs.databases).toEqual(originalLocalDbs.databases);
|
||||
expect(updatedLocalDbs.lists.length).toEqual(2);
|
||||
expect(updatedLocalDbs.lists[0].databases.length).toEqual(2);
|
||||
expect(updatedLocalDbs.lists[0].databases[0]).toEqual({
|
||||
...db1List1,
|
||||
name: "dbRenamed",
|
||||
});
|
||||
expect(updatedLocalDbs.lists[0].databases[1]).toEqual(db2List1);
|
||||
expect(updatedLocalDbs.lists[1]).toEqual(originalLocalDbs.lists[1]);
|
||||
});
|
||||
|
||||
it("should rename a local db that is selected", () => {
|
||||
const db1 = createLocalDbConfigItem({ name: "db1" });
|
||||
const db2 = createLocalDbConfigItem({ name: "db2" });
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
localDbs: [db1, db2],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: "db1",
|
||||
},
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalDb(originalConfig, "db1", "dbRenamed");
|
||||
|
||||
const updatedLocalDbs = updatedConfig.databases.local;
|
||||
const originalLocalDbs = originalConfig.databases.local;
|
||||
|
||||
expect(updatedLocalDbs.lists).toEqual(originalLocalDbs.lists);
|
||||
expect(updatedLocalDbs.databases.length).toEqual(2);
|
||||
expect(updatedLocalDbs.databases[0]).toEqual({
|
||||
...db1,
|
||||
name: "dbRenamed",
|
||||
});
|
||||
expect(updatedLocalDbs.databases[1]).toEqual(db2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeLocalList", () => {
|
||||
it("should remove a local list", () => {
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const updatedConfig = removeLocalList(originalConfig, "list1");
|
||||
|
||||
expect(updatedConfig.databases.local.lists).toEqual([
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should remove a selected local list", () => {
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
});
|
||||
|
||||
const updatedConfig = removeLocalList(originalConfig, "list1");
|
||||
|
||||
expect(updatedConfig.databases.local.lists).toEqual([
|
||||
{
|
||||
name: "list2",
|
||||
databases: [],
|
||||
},
|
||||
]);
|
||||
|
||||
expect(updatedConfig.selected).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should remove a local list with a db that is selected", () => {
|
||||
const selectedLocalDb = createLocalDbConfigItem();
|
||||
const list1: LocalList = {
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem(),
|
||||
selectedLocalDb,
|
||||
createLocalDbConfigItem(),
|
||||
],
|
||||
};
|
||||
const list2: LocalList = {
|
||||
name: "list2",
|
||||
databases: [],
|
||||
};
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [list1, list2],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: selectedLocalDb.name,
|
||||
listName: list1.name,
|
||||
},
|
||||
});
|
||||
|
||||
const updatedConfig = removeLocalList(originalConfig, list1.name);
|
||||
|
||||
expect(updatedConfig.databases.local.lists.length).toEqual(1);
|
||||
expect(updatedConfig.databases.local.lists[0]).toEqual(list2);
|
||||
expect(updatedConfig.selected).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeRemoteList", () => {
|
||||
it("should remove a remote list", () => {
|
||||
const originalConfig = createDbConfig({
|
||||
@@ -541,109 +215,6 @@ describe("db config", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeLocalDb", () => {
|
||||
it("should remove a local db", () => {
|
||||
const db1 = createLocalDbConfigItem({ name: "db1" });
|
||||
const db2 = createLocalDbConfigItem({ name: "db2" });
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
localDbs: [db1, db2],
|
||||
});
|
||||
|
||||
const updatedConfig = renameLocalDb(originalConfig, "db1", "dbRenamed");
|
||||
|
||||
const updatedLocalDbs = updatedConfig.databases.local;
|
||||
const originalLocalDbs = originalConfig.databases.local;
|
||||
|
||||
expect(updatedLocalDbs.lists).toEqual(originalLocalDbs.lists);
|
||||
expect(updatedLocalDbs.databases.length).toEqual(2);
|
||||
expect(updatedLocalDbs.databases[0]).toEqual({
|
||||
...db1,
|
||||
name: "dbRenamed",
|
||||
});
|
||||
expect(updatedLocalDbs.databases[1]).toEqual(db2);
|
||||
});
|
||||
|
||||
it("should remove a local db inside a list", () => {
|
||||
const db1List1 = createLocalDbConfigItem({ name: "db1" });
|
||||
const db2List1 = createLocalDbConfigItem({ name: "db2" });
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [db1List1, db2List1],
|
||||
},
|
||||
{
|
||||
name: "list2",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
localDbs: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
});
|
||||
|
||||
const updatedConfig = removeLocalDb(
|
||||
originalConfig,
|
||||
db1List1.name,
|
||||
"list1",
|
||||
);
|
||||
|
||||
const updatedLocalDbs = updatedConfig.databases.local;
|
||||
const originalLocalDbs = originalConfig.databases.local;
|
||||
expect(updatedLocalDbs.databases).toEqual(originalLocalDbs.databases);
|
||||
expect(updatedLocalDbs.lists.length).toEqual(2);
|
||||
expect(updatedLocalDbs.lists[0].databases.length).toEqual(1);
|
||||
expect(updatedLocalDbs.lists[0].databases[0]).toEqual(db2List1);
|
||||
expect(updatedLocalDbs.lists[1]).toEqual(originalLocalDbs.lists[1]);
|
||||
});
|
||||
|
||||
it("should remove a local db that is selected", () => {
|
||||
const db1 = createLocalDbConfigItem({ name: "db1" });
|
||||
const db2 = createLocalDbConfigItem({ name: "db2" });
|
||||
|
||||
const originalConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "list1",
|
||||
databases: [
|
||||
createLocalDbConfigItem({ name: "db1" }),
|
||||
createLocalDbConfigItem({ name: "db2" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
localDbs: [db1, db2],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.LocalDatabase,
|
||||
databaseName: "db1",
|
||||
},
|
||||
});
|
||||
|
||||
const updatedConfig = removeLocalDb(originalConfig, "db1");
|
||||
|
||||
const updatedLocalDbs = updatedConfig.databases.local;
|
||||
const originalLocalDbs = originalConfig.databases.local;
|
||||
|
||||
expect(updatedLocalDbs.lists).toEqual(originalLocalDbs.lists);
|
||||
expect(updatedLocalDbs.databases.length).toEqual(1);
|
||||
expect(updatedLocalDbs.databases[0]).toEqual(db2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeRemoteRepo", () => {
|
||||
it("should remove a remote repo", () => {
|
||||
const repo1 = "owner1/repo1";
|
||||
|
||||
@@ -6,9 +6,7 @@ import {
|
||||
cleanNonExistentExpandedItems,
|
||||
} from "../../../src/databases/db-item-expansion";
|
||||
import {
|
||||
createLocalListDbItem,
|
||||
createRemoteUserDefinedListDbItem,
|
||||
createRootLocalDbItem,
|
||||
createRootRemoteDbItem,
|
||||
} from "../../factories/db-item-factories";
|
||||
|
||||
@@ -120,10 +118,6 @@ describe("db item expansion", () => {
|
||||
kind: ExpandedDbItemKind.RemoteUserDefinedList,
|
||||
listName: "list2",
|
||||
},
|
||||
{
|
||||
kind: ExpandedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
];
|
||||
|
||||
const currentDbItem = createRemoteUserDefinedListDbItem({
|
||||
@@ -153,10 +147,6 @@ describe("db item expansion", () => {
|
||||
kind: ExpandedDbItemKind.RemoteUserDefinedList,
|
||||
listName: "list2",
|
||||
},
|
||||
{
|
||||
kind: ExpandedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -175,10 +165,6 @@ describe("db item expansion", () => {
|
||||
kind: ExpandedDbItemKind.RemoteUserDefinedList,
|
||||
listName: "list2",
|
||||
},
|
||||
{
|
||||
kind: ExpandedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
];
|
||||
|
||||
const dbItems = [
|
||||
@@ -189,13 +175,6 @@ describe("db item expansion", () => {
|
||||
}),
|
||||
],
|
||||
}),
|
||||
createRootLocalDbItem({
|
||||
children: [
|
||||
createLocalListDbItem({
|
||||
listName: "list1",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
];
|
||||
|
||||
const newExpandedItems = cleanNonExistentExpandedItems(
|
||||
@@ -211,10 +190,6 @@ describe("db item expansion", () => {
|
||||
kind: ExpandedDbItemKind.RemoteUserDefinedList,
|
||||
listName: "list2",
|
||||
},
|
||||
{
|
||||
kind: ExpandedDbItemKind.LocalUserDefinedList,
|
||||
listName: "list1",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
import { getDbItemName } from "../../../src/databases/db-item-naming";
|
||||
import {
|
||||
createLocalDatabaseDbItem,
|
||||
createLocalListDbItem,
|
||||
createRemoteOwnerDbItem,
|
||||
createRemoteRepoDbItem,
|
||||
createRemoteSystemDefinedListDbItem,
|
||||
createRemoteUserDefinedListDbItem,
|
||||
createRootLocalDbItem,
|
||||
createRootRemoteDbItem,
|
||||
} from "../../factories/db-item-factories";
|
||||
|
||||
describe("db item naming", () => {
|
||||
describe("getDbItemName", () => {
|
||||
it("return undefined for root local db item", () => {
|
||||
const dbItem = createRootLocalDbItem();
|
||||
|
||||
const name = getDbItemName(dbItem);
|
||||
|
||||
expect(name).toBeUndefined();
|
||||
});
|
||||
|
||||
it("return undefined for root remote db item", () => {
|
||||
const dbItem = createRootRemoteDbItem();
|
||||
|
||||
@@ -28,14 +17,6 @@ describe("db item naming", () => {
|
||||
expect(name).toBeUndefined();
|
||||
});
|
||||
|
||||
it("return list name for local list db item", () => {
|
||||
const dbItem = createLocalListDbItem();
|
||||
|
||||
const name = getDbItemName(dbItem);
|
||||
|
||||
expect(name).toEqual(dbItem.listName);
|
||||
});
|
||||
|
||||
it("return list name for remote user defined list db item", () => {
|
||||
const dbItem = createRemoteUserDefinedListDbItem();
|
||||
|
||||
@@ -60,14 +41,6 @@ describe("db item naming", () => {
|
||||
expect(name).toEqual(dbItem.ownerName);
|
||||
});
|
||||
|
||||
it("return database name for local db item", () => {
|
||||
const dbItem = createLocalDatabaseDbItem();
|
||||
|
||||
const name = getDbItemName(dbItem);
|
||||
|
||||
expect(name).toEqual(dbItem.databaseName);
|
||||
});
|
||||
|
||||
it("return repo name for remote repo db item", () => {
|
||||
const dbItem = createRemoteRepoDbItem();
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { DbItem, DbItemKind } from "../../../src/databases/db-item";
|
||||
import { getSelectedDbItem } from "../../../src/databases/db-item-selection";
|
||||
import {
|
||||
createLocalDatabaseDbItem,
|
||||
createLocalListDbItem,
|
||||
createRemoteOwnerDbItem,
|
||||
createRemoteRepoDbItem,
|
||||
createRemoteSystemDefinedListDbItem,
|
||||
createRemoteUserDefinedListDbItem,
|
||||
createRootLocalDbItem,
|
||||
createRootRemoteDbItem,
|
||||
} from "../../factories/db-item-factories";
|
||||
|
||||
@@ -21,49 +18,11 @@ describe("db item selection", () => {
|
||||
createRemoteUserDefinedListDbItem(),
|
||||
],
|
||||
}),
|
||||
createRootLocalDbItem({
|
||||
children: [createLocalListDbItem(), createLocalDatabaseDbItem()],
|
||||
}),
|
||||
];
|
||||
|
||||
expect(getSelectedDbItem(dbItems)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return correct local database item from DbItem list", () => {
|
||||
const dbItems: DbItem[] = [
|
||||
createRootLocalDbItem({
|
||||
children: [
|
||||
createLocalDatabaseDbItem({
|
||||
databaseName: "db2",
|
||||
dateAdded: 1234,
|
||||
language: "javascript",
|
||||
storagePath: "/foo/bar",
|
||||
selected: true,
|
||||
}),
|
||||
createLocalListDbItem({
|
||||
databases: [
|
||||
createLocalDatabaseDbItem(),
|
||||
createLocalDatabaseDbItem(),
|
||||
],
|
||||
}),
|
||||
],
|
||||
expanded: false,
|
||||
}),
|
||||
];
|
||||
|
||||
expect(getSelectedDbItem(dbItems)).toEqual({
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
databaseName: "db2",
|
||||
dateAdded: 1234,
|
||||
language: "javascript",
|
||||
storagePath: "/foo/bar",
|
||||
origin: {
|
||||
type: "folder",
|
||||
},
|
||||
selected: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("should return correct remote database list item from DbItem list", () => {
|
||||
const dbItems: DbItem[] = [
|
||||
createRootRemoteDbItem({
|
||||
|
||||
@@ -4,13 +4,10 @@ import {
|
||||
flattenDbItems,
|
||||
} from "../../../src/databases/db-item";
|
||||
import {
|
||||
createLocalDatabaseDbItem,
|
||||
createLocalListDbItem,
|
||||
createRemoteOwnerDbItem,
|
||||
createRemoteRepoDbItem,
|
||||
createRemoteSystemDefinedListDbItem,
|
||||
createRemoteUserDefinedListDbItem,
|
||||
createRootLocalDbItem,
|
||||
createRootRemoteDbItem,
|
||||
} from "../../factories/db-item-factories";
|
||||
|
||||
@@ -40,22 +37,11 @@ describe("DbItem", () => {
|
||||
createRemoteRepoDbItem({ repoFullName: "owner3/repo3" }),
|
||||
],
|
||||
}),
|
||||
createRootLocalDbItem({
|
||||
children: [
|
||||
createLocalListDbItem({
|
||||
listName: "local-list1",
|
||||
databases: [
|
||||
createLocalDatabaseDbItem({ databaseName: "local-db1" }),
|
||||
],
|
||||
}),
|
||||
createLocalDatabaseDbItem({ databaseName: "local-db2" }),
|
||||
],
|
||||
}),
|
||||
];
|
||||
|
||||
const flattenedItems = flattenDbItems(dbItems);
|
||||
|
||||
expect(flattenedItems.length).toEqual(15);
|
||||
expect(flattenedItems.length).toEqual(11);
|
||||
checkRootRemoteExists(flattenedItems);
|
||||
checkSystemDefinedListExists(flattenedItems, "top10");
|
||||
checkSystemDefinedListExists(flattenedItems, "top100");
|
||||
@@ -66,10 +52,6 @@ describe("DbItem", () => {
|
||||
checkRemoteRepoExists(flattenedItems, "owner2/repo2");
|
||||
checkRemoteOwnerExists(flattenedItems, "owner1");
|
||||
checkRemoteRepoExists(flattenedItems, "owner3/repo3");
|
||||
checkRootLocalExists(flattenedItems);
|
||||
checkLocalListExists(flattenedItems, "local-list1");
|
||||
checkLocalDbExists(flattenedItems, "local-db1");
|
||||
checkLocalDbExists(flattenedItems, "local-db2");
|
||||
});
|
||||
|
||||
function checkRootRemoteExists(items: DbItem[]): void {
|
||||
@@ -115,30 +97,5 @@ describe("DbItem", () => {
|
||||
),
|
||||
).toBeDefined();
|
||||
}
|
||||
|
||||
function checkRootLocalExists(items: DbItem[]): void {
|
||||
expect(
|
||||
items.find((item) => item.kind === DbItemKind.RootLocal),
|
||||
).toBeDefined();
|
||||
}
|
||||
|
||||
function checkLocalListExists(items: DbItem[], name: string): void {
|
||||
expect(
|
||||
items.find(
|
||||
(item) =>
|
||||
item.kind === DbItemKind.LocalList && item.listName === name,
|
||||
),
|
||||
).toBeDefined();
|
||||
}
|
||||
|
||||
function checkLocalDbExists(items: DbItem[], name: string): void {
|
||||
expect(
|
||||
items.find(
|
||||
(item) =>
|
||||
item.kind === DbItemKind.LocalDatabase &&
|
||||
item.databaseName === name,
|
||||
),
|
||||
).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,11 +12,7 @@ import {
|
||||
ExpandedDbItem,
|
||||
ExpandedDbItemKind,
|
||||
} from "../../../src/databases/db-item-expansion";
|
||||
import {
|
||||
createLocalTree,
|
||||
createRemoteTree,
|
||||
} from "../../../src/databases/db-tree-creator";
|
||||
import { QueryLanguage } from "../../../src/common/query-language";
|
||||
import { createRemoteTree } from "../../../src/databases/db-tree-creator";
|
||||
import { createDbConfig } from "../../factories/db-config-factories";
|
||||
|
||||
describe("db tree creator", () => {
|
||||
@@ -313,156 +309,4 @@ describe("db tree creator", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("createLocalTree", () => {
|
||||
it("should build root node", () => {
|
||||
const dbConfig = createDbConfig();
|
||||
|
||||
const dbTreeRoot = createLocalTree(dbConfig, []);
|
||||
|
||||
expect(dbTreeRoot).toBeTruthy();
|
||||
expect(dbTreeRoot.kind).toBe(DbItemKind.RootLocal);
|
||||
expect(dbTreeRoot.expanded).toBe(false);
|
||||
expect(dbTreeRoot.children.length).toBe(0);
|
||||
});
|
||||
|
||||
it("should create local list nodes", () => {
|
||||
const dbConfig = createDbConfig({
|
||||
localLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
databases: [
|
||||
{
|
||||
name: "db1",
|
||||
dateAdded: 1668428293677,
|
||||
language: QueryLanguage.Cpp,
|
||||
storagePath: "/path/to/db1/",
|
||||
origin: {
|
||||
type: "folder",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "db2",
|
||||
dateAdded: 1668428472731,
|
||||
language: "cpp",
|
||||
storagePath: "/path/to/db2/",
|
||||
origin: {
|
||||
type: "folder",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "my-list-2",
|
||||
databases: [
|
||||
{
|
||||
name: "db3",
|
||||
dateAdded: 1668428472731,
|
||||
language: "ruby",
|
||||
storagePath: "/path/to/db3/",
|
||||
origin: {
|
||||
type: "folder",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const dbTreeRoot = createLocalTree(dbConfig, []);
|
||||
|
||||
expect(dbTreeRoot).toBeTruthy();
|
||||
expect(dbTreeRoot.kind).toBe(DbItemKind.RootLocal);
|
||||
const localListNodes = dbTreeRoot.children.filter(
|
||||
(child) => child.kind === DbItemKind.LocalList,
|
||||
);
|
||||
|
||||
expect(localListNodes.length).toBe(2);
|
||||
expect(localListNodes[0]).toEqual({
|
||||
kind: DbItemKind.LocalList,
|
||||
expanded: false,
|
||||
selected: false,
|
||||
listName: dbConfig.databases.local.lists[0].name,
|
||||
databases: dbConfig.databases.local.lists[0].databases.map((db) => ({
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
selected: false,
|
||||
databaseName: db.name,
|
||||
dateAdded: db.dateAdded,
|
||||
language: db.language,
|
||||
origin: db.origin,
|
||||
storagePath: db.storagePath,
|
||||
parentListName: dbConfig.databases.local.lists[0].name,
|
||||
})),
|
||||
});
|
||||
expect(localListNodes[1]).toEqual({
|
||||
kind: DbItemKind.LocalList,
|
||||
expanded: false,
|
||||
selected: false,
|
||||
listName: dbConfig.databases.local.lists[1].name,
|
||||
databases: dbConfig.databases.local.lists[1].databases.map((db) => ({
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
selected: false,
|
||||
databaseName: db.name,
|
||||
dateAdded: db.dateAdded,
|
||||
language: db.language,
|
||||
origin: db.origin,
|
||||
storagePath: db.storagePath,
|
||||
parentListName: dbConfig.databases.local.lists[1].name,
|
||||
})),
|
||||
});
|
||||
});
|
||||
|
||||
it("should create local database nodes", () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
localDbs: [
|
||||
{
|
||||
name: "db1",
|
||||
dateAdded: 1668428293677,
|
||||
language: "csharp",
|
||||
storagePath: "/path/to/db1/",
|
||||
origin: {
|
||||
type: "folder",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "db2",
|
||||
dateAdded: 1668428472731,
|
||||
language: "go",
|
||||
storagePath: "/path/to/db2/",
|
||||
origin: {
|
||||
type: "folder",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const dbTreeRoot = createLocalTree(dbConfig, []);
|
||||
|
||||
expect(dbTreeRoot).toBeTruthy();
|
||||
expect(dbTreeRoot.kind).toBe(DbItemKind.RootLocal);
|
||||
const localDatabaseNodes = dbTreeRoot.children.filter(
|
||||
(child) => child.kind === DbItemKind.LocalDatabase,
|
||||
);
|
||||
|
||||
expect(localDatabaseNodes.length).toBe(2);
|
||||
expect(localDatabaseNodes[0]).toEqual({
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
selected: false,
|
||||
databaseName: dbConfig.databases.local.databases[0].name,
|
||||
dateAdded: dbConfig.databases.local.databases[0].dateAdded,
|
||||
language: dbConfig.databases.local.databases[0].language,
|
||||
origin: dbConfig.databases.local.databases[0].origin,
|
||||
storagePath: dbConfig.databases.local.databases[0].storagePath,
|
||||
});
|
||||
expect(localDatabaseNodes[1]).toEqual({
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
selected: false,
|
||||
databaseName: dbConfig.databases.local.databases[1].name,
|
||||
dateAdded: dbConfig.databases.local.databases[1].dateAdded,
|
||||
language: dbConfig.databases.local.databases[1].language,
|
||||
origin: dbConfig.databases.local.databases[1].origin,
|
||||
storagePath: dbConfig.databases.local.databases[1].storagePath,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,13 +3,10 @@ import {
|
||||
getGitHubUrl,
|
||||
} from "../../../../src/databases/ui/db-tree-view-item-action";
|
||||
import {
|
||||
createLocalDatabaseDbItem,
|
||||
createLocalListDbItem,
|
||||
createRemoteOwnerDbItem,
|
||||
createRemoteRepoDbItem,
|
||||
createRemoteSystemDefinedListDbItem,
|
||||
createRemoteUserDefinedListDbItem,
|
||||
createRootLocalDbItem,
|
||||
createRootRemoteDbItem,
|
||||
} from "../../../factories/db-item-factories";
|
||||
|
||||
@@ -22,30 +19,6 @@ describe("getDbItemActions", () => {
|
||||
expect(actions).toEqual([]);
|
||||
});
|
||||
|
||||
it("should return an empty array for root local node", () => {
|
||||
const dbItem = createRootLocalDbItem();
|
||||
|
||||
const actions = getDbItemActions(dbItem);
|
||||
|
||||
expect(actions).toEqual([]);
|
||||
});
|
||||
|
||||
it("should set canBeSelected, canBeRemoved and canBeRenamed for local user defined db list", () => {
|
||||
const dbItem = createLocalListDbItem();
|
||||
|
||||
const actions = getDbItemActions(dbItem);
|
||||
|
||||
expect(actions).toEqual(["canBeSelected", "canBeRemoved", "canBeRenamed"]);
|
||||
});
|
||||
|
||||
it("should set canBeSelected, canBeRemoved and canBeRenamed for local db", () => {
|
||||
const dbItem = createLocalDatabaseDbItem();
|
||||
|
||||
const actions = getDbItemActions(dbItem);
|
||||
|
||||
expect(actions).toEqual(["canBeSelected", "canBeRemoved", "canBeRenamed"]);
|
||||
});
|
||||
|
||||
it("should set canBeSelected for remote system defined db list", () => {
|
||||
const dbItem = createRemoteSystemDefinedListDbItem();
|
||||
|
||||
@@ -150,18 +123,4 @@ describe("getGitHubUrl", () => {
|
||||
expect(actualUrl1).toBeUndefined();
|
||||
expect(actualUrl2).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return undefined for local db items", () => {
|
||||
const dbItem0 = createRootLocalDbItem();
|
||||
const dbItem1 = createLocalDatabaseDbItem();
|
||||
const dbItem2 = createLocalListDbItem();
|
||||
|
||||
const actualUrl0 = getGitHubUrl(dbItem0);
|
||||
const actualUrl1 = getGitHubUrl(dbItem1);
|
||||
const actualUrl2 = getGitHubUrl(dbItem2);
|
||||
|
||||
expect(actualUrl0).toBeUndefined();
|
||||
expect(actualUrl1).toBeUndefined();
|
||||
expect(actualUrl2).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,16 +15,6 @@ describe("repository selection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should log error when local database item is selected", async () => {
|
||||
const dbManager = setUpDbManager({
|
||||
kind: DbItemKind.LocalDatabase,
|
||||
} as DbItem);
|
||||
|
||||
await expect(getRepositorySelection(dbManager)).rejects.toThrow(
|
||||
"Local databases and lists are not supported yet.",
|
||||
);
|
||||
});
|
||||
|
||||
it("should log an error when an empty remote user defined list is selected", async () => {
|
||||
const dbManager = setUpDbManager({
|
||||
kind: DbItemKind.RemoteUserDefinedList,
|
||||
|
||||
Reference in New Issue
Block a user