Add support for local dbs in config (#1751)
This commit is contained in:
@@ -99,7 +99,11 @@ export class DbConfigStore extends DisposableObject {
|
||||
repositoryLists: [],
|
||||
owners: [],
|
||||
repositories: [],
|
||||
}
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
export interface DbConfig {
|
||||
remote: RemoteDbConfig;
|
||||
local: LocalDbConfig;
|
||||
}
|
||||
|
||||
export interface RemoteDbConfig {
|
||||
@@ -15,6 +16,23 @@ export interface RemoteRepositoryList {
|
||||
repositories: string[];
|
||||
}
|
||||
|
||||
export interface LocalDbConfig {
|
||||
lists: LocalList[];
|
||||
databases: LocalDatabase[];
|
||||
}
|
||||
|
||||
export interface LocalList {
|
||||
name: string;
|
||||
databases: LocalDatabase[];
|
||||
}
|
||||
|
||||
export interface LocalDatabase {
|
||||
name: string;
|
||||
dateAdded: number;
|
||||
language: string;
|
||||
storagePath: string;
|
||||
}
|
||||
|
||||
export function cloneDbConfig(config: DbConfig): DbConfig {
|
||||
return {
|
||||
remote: {
|
||||
@@ -24,6 +42,13 @@ export function cloneDbConfig(config: DbConfig): DbConfig {
|
||||
})),
|
||||
owners: [...config.remote.owners],
|
||||
repositories: [...config.remote.repositories],
|
||||
}
|
||||
},
|
||||
local: {
|
||||
lists: config.local.lists.map((list) => ({
|
||||
name: list.name,
|
||||
databases: list.databases.map((db) => ({ ...db })),
|
||||
})),
|
||||
databases: config.local.databases.map((db) => ({ ...db })),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ describe('db panel', async () => {
|
||||
owners: [],
|
||||
repositories: []
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
},
|
||||
};
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
@@ -116,6 +120,10 @@ describe('db panel', async () => {
|
||||
owners: [],
|
||||
repositories: []
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
},
|
||||
};
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
@@ -148,6 +156,10 @@ describe('db panel', async () => {
|
||||
owners: ['owner1', 'owner2'],
|
||||
repositories: []
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
},
|
||||
};
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
@@ -177,6 +189,10 @@ describe('db panel', async () => {
|
||||
owners: [],
|
||||
repositories: ['owner1/repo1', 'owner1/repo2']
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
},
|
||||
};
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
|
||||
@@ -8,5 +8,39 @@
|
||||
],
|
||||
"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/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ describe('db config store', async () => {
|
||||
expect(config.remote.repositoryLists).to.be.empty;
|
||||
expect(config.remote.owners).to.be.empty;
|
||||
expect(config.remote.repositories).to.be.empty;
|
||||
expect(config.local.lists).to.be.empty;
|
||||
expect(config.local.databases).to.be.empty;
|
||||
});
|
||||
|
||||
it('should load an existing config', async () => {
|
||||
@@ -36,12 +38,35 @@ describe('db config store', async () => {
|
||||
const config = configStore.getConfig().value;
|
||||
expect(config.remote.repositoryLists).to.have.length(1);
|
||||
expect(config.remote.repositoryLists[0]).to.deep.equal({
|
||||
'name': 'repoList1',
|
||||
'repositories': ['foo/bar', 'foo/baz']
|
||||
name: 'repoList1',
|
||||
repositories: ['foo/bar', 'foo/baz']
|
||||
});
|
||||
expect(config.remote.owners).to.be.empty;
|
||||
expect(config.remote.repositories).to.have.length(3);
|
||||
expect(config.remote.repositories).to.deep.equal(['owner/repo1', 'owner/repo2', 'owner/repo3']);
|
||||
expect(config.remote.repositories).to.deep.equal([
|
||||
'owner/repo1',
|
||||
'owner/repo2',
|
||||
'owner/repo3',
|
||||
]);
|
||||
expect(config.local.lists).to.have.length(2);
|
||||
expect(config.local.lists[0]).to.deep.equal({
|
||||
name: 'localList1',
|
||||
databases: [
|
||||
{
|
||||
name: 'foo/bar',
|
||||
dateAdded: 1668096745193,
|
||||
language: 'go',
|
||||
storagePath: '/path/to/database/',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(config.local.databases).to.have.length(1);
|
||||
expect(config.local.databases[0]).to.deep.equal({
|
||||
name: 'example-db',
|
||||
dateAdded: 1668096927267,
|
||||
language: 'ruby',
|
||||
storagePath: '/path/to/database/',
|
||||
});
|
||||
});
|
||||
|
||||
it('should not allow modification of the config', async () => {
|
||||
|
||||
@@ -25,9 +25,10 @@ describe('db config validation', async () => {
|
||||
|
||||
const validationOutput = configValidator.validate(dbConfig);
|
||||
|
||||
expect(validationOutput).to.have.length(2);
|
||||
expect(validationOutput).to.have.length(3);
|
||||
|
||||
expect(validationOutput[0]).to.deep.equal('/remote must have required property \'owners\'');
|
||||
expect(validationOutput[1]).to.deep.equal('/remote must NOT have additional properties');
|
||||
expect(validationOutput[0]).to.deep.equal(' must have required property \'local\'');
|
||||
expect(validationOutput[1]).to.deep.equal('/remote must have required property \'owners\'');
|
||||
expect(validationOutput[2]).to.deep.equal('/remote must NOT have additional properties');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,10 @@ describe('db tree creator', () => {
|
||||
repositoryLists: [],
|
||||
owners: [],
|
||||
repositories: []
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,6 +67,10 @@ describe('db tree creator', () => {
|
||||
],
|
||||
owners: [],
|
||||
repositories: []
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -102,6 +110,10 @@ describe('db tree creator', () => {
|
||||
'owner2'
|
||||
],
|
||||
repositories: []
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -134,6 +146,10 @@ describe('db tree creator', () => {
|
||||
'owner1/repo2',
|
||||
'owner2/repo1'
|
||||
]
|
||||
},
|
||||
local: {
|
||||
lists: [],
|
||||
databases: []
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -44,6 +44,72 @@
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"dateAdded": {
|
||||
"type": "number"
|
||||
},
|
||||
"language": {
|
||||
"type": "string"
|
||||
},
|
||||
"storagePath": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "dateAdded", "language", "storagePath"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name", "databases"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"databases": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"dateAdded": {
|
||||
"type": "number"
|
||||
},
|
||||
"language": {
|
||||
"type": "string"
|
||||
},
|
||||
"storagePath": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "dateAdded", "language", "storagePath"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["lists", "databases"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["remote", "local"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user