Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 1 addition & 107 deletions extensions/ql-vscode/databases-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,120 +48,14 @@
},
"required": ["repositoryLists", "owners", "repositories"],
"additionalProperties": false
},
"local": {
"type": "object",
"properties": {
"lists": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"databases": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"dateAdded": {
"type": "number"
},
"language": {
"type": "string",
"minLength": 1
},
"storagePath": {
"type": "string",
"minLength": 1
}
},
"required": [
"name",
"dateAdded",
"language",
"storagePath"
],
"additionalProperties": false
}
}
},
"required": ["name", "databases"],
"additionalProperties": false
}
},
"databases": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"dateAdded": {
"type": "number"
},
"language": {
"type": "string",
"minLength": 1
},
"storagePath": {
"type": "string",
"minLength": 1
}
},
"required": ["name", "dateAdded", "language", "storagePath"],
"additionalProperties": false
}
}
},
"required": ["lists", "databases"],
"additionalProperties": false
}
},
"required": ["variantAnalysis", "local"],
"required": ["variantAnalysis"],
"additionalProperties": false
},
"selected": {
"type": "object",
"oneOf": [
{
"properties": {
"kind": {
"type": "string",
"enum": ["localUserDefinedList"]
},
"listName": {
"type": "string",
"minLength": 1
}
},
"required": ["kind", "listName"],
"additionalProperties": false
},
{
"properties": {
"kind": {
"type": "string",
"enum": ["localDatabase"]
},
"databaseName": {
"type": "string"
},
"listName": {
"type": "string",
"minLength": 1
}
},
"required": ["kind", "databaseName"],
"additionalProperties": false
},
{
"properties": {
"kind": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { pathExists, outputJSON, readJSON, readJSONSync } from "fs-extra";
import { join } from "path";
import {
clearLocalDbConfig,
cloneDbConfig,
DbConfig,
initializeLocalDbConfig,
removeLocalDb,
removeLocalList,
removeRemoteList,
Expand Down Expand Up @@ -349,6 +351,7 @@ export class DbConfigStore extends DisposableObject {
}

private async writeConfig(config: DbConfig): Promise<void> {
clearLocalDbConfig(config);
await outputJSON(this.configPath, config, {
spaces: 2,
});
Expand Down Expand Up @@ -380,6 +383,7 @@ export class DbConfigStore extends DisposableObject {
}

if (newConfig) {
initializeLocalDbConfig(newConfig);
this.configErrors = this.configValidator.validate(newConfig);
}

Expand Down Expand Up @@ -414,6 +418,7 @@ export class DbConfigStore extends DisposableObject {
}

if (newConfig) {
initializeLocalDbConfig(newConfig);
this.configErrors = this.configValidator.validate(newConfig);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readJsonSync } from "fs-extra";
import { resolve } from "path";
import Ajv from "ajv";
import { DbConfig } from "./db-config";
import { clearLocalDbConfig, DbConfig } from "./db-config";
import { findDuplicateStrings } from "../../text-utils";
import {
DbConfigValidationError,
Expand All @@ -18,6 +18,9 @@ export class DbConfigValidator {

public validate(dbConfig: DbConfig): DbConfigValidationError[] {
const ajv = new Ajv({ allErrors: true });

const localDbs = clearLocalDbConfig(dbConfig);

ajv.validate(this.schema, dbConfig);

if (ajv.errors) {
Expand All @@ -27,6 +30,13 @@ 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),
Expand Down
32 changes: 32 additions & 0 deletions extensions/ql-vscode/src/databases/config/db-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,38 @@ 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:
Expand Down
8 changes: 3 additions & 5 deletions extensions/ql-vscode/src/databases/db-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getSelectedDbItem,
mapDbItemToSelectedDbItem,
} from "./db-item-selection";
import { createLocalTree, createRemoteTree } from "./db-tree-creator";
import { createRemoteTree } from "./db-tree-creator";
import { DbConfigValidationError } from "./db-validation-errors";

export class DbManager {
Expand Down Expand Up @@ -58,10 +58,8 @@ export class DbManager {

const expandedItems = this.getExpandedItems();

return ValueResult.ok([
createRemoteTree(configResult.value, expandedItems),
createLocalTree(configResult.value, expandedItems),
]);
const remoteTree = createRemoteTree(configResult.value, expandedItems);
return ValueResult.ok(remoteTree.children);
}

public getConfigPath(): string {
Expand Down
44 changes: 1 addition & 43 deletions extensions/ql-vscode/src/databases/ui/db-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
DbListKind,
LocalDatabaseDbItem,
LocalListDbItem,
remoteDbKinds,
RemoteUserDefinedListDbItem,
} from "../db-item";
import { getDbItemName } from "../db-item-naming";
Expand Down Expand Up @@ -219,7 +218,7 @@ export class DbPanel extends DisposableObject {
}

private async addNewList(): Promise<void> {
const listKind = await this.getAddNewListKind();
const listKind = DbListKind.Remote;

const listName = await window.showInputBox({
prompt: "Enter a name for the new list",
Expand All @@ -237,47 +236,6 @@ export class DbPanel extends DisposableObject {
await this.dbManager.addNewList(listKind, listName);
}

private async getAddNewListKind(): Promise<DbListKind> {
const highlightedItem = await this.getHighlightedDbItem();
if (highlightedItem) {
return remoteDbKinds.includes(highlightedItem.kind)
? DbListKind.Remote
: DbListKind.Local;
} else {
const quickPickItems = [
{
label: "$(cloud) Variant Analysis",
detail: "Add a repository from GitHub",
alwaysShow: true,
kind: DbListKind.Remote,
},
{
label: "$(database) Local",
detail: "Import a database from the cloud or a local file",
alwaysShow: true,
kind: DbListKind.Local,
},
];
const selectedOption = await window.showQuickPick<AddListQuickPickItem>(
quickPickItems,
{
title: "Add a new database",
ignoreFocusOut: true,
},
);
if (!selectedOption) {
// We don't need to display a warning pop-up in this case, since the user just escaped out of the operation.
// We set 'true' to make this a silent exception.
throw new UserCancellationException(
"No database list kind selected",
true,
);
}

return selectedOption.kind;
}
}

private async setSelectedItem(treeViewItem: DbTreeViewItem): Promise<void> {
if (treeViewItem.dbItem === undefined) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,6 @@
],
"owners": [],
"repositories": ["owner/repo1", "owner/repo2", "owner/repo3"]
},
"local": {
"lists": [
{
"name": "localList1",
"databases": [
{
"name": "foo/bar",
"dateAdded": 1668096745193,
"language": "go",
"storagePath": "/path/to/database/"
}
]
},
{
"name": "localList2",
"databases": [
{
"name": "foo/baz",
"dateAdded": 1668096760848,
"language": "javascript",
"storagePath": "/path/to/database/"
}
]
}
],
"databases": [
{
"name": "example-db",
"dateAdded": 1668096927267,
"language": "ruby",
"storagePath": "/path/to/database/"
}
]
}
},
"selected": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"repositoryLists": [],
"owners": [],
"repositories": []
},
"local": {
"lists": [],
"databases": []
}
}
}
Loading