typescript common lib

This commit is contained in:
Jan Prochazka
2020-02-01 19:57:07 +01:00
parent 8291885d56
commit d22058382f
15 changed files with 3434 additions and 94 deletions

3373
api/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@
"nedb-promises": "^4.0.1",
"pg": "^7.17.0",
"socket.io": "^2.3.0",
"@dbgate/lib": "file:../lib",
"uuid": "^3.4.0"
},
"scripts": {

View File

@@ -6,7 +6,7 @@ const { fork } = require('child_process');
const DatabaseAnalyser = require('../engines/default/DatabaseAnalyser');
module.exports = {
/** @type {import('../types').OpenedDatabaseConnection[]} */
/** @type {import('@dbgate/lib').OpenedDatabaseConnection[]} */
opened: [],
requests: {},
@@ -48,7 +48,7 @@ module.exports = {
return newOpened;
},
/** @param {import('../types').OpenedDatabaseConnection} conn */
/** @param {import('@dbgate/lib').OpenedDatabaseConnection} conn */
async sendRequest(conn, message) {
const msgid = uuidv1();
const promise = new Promise((resolve, reject) => {

View File

@@ -1,7 +1,7 @@
class DatabaseAnalyser {
/**
*
* @param {import('../../types').EngineDriver} driver
* @param {import('@dbgate/lib').EngineDriver} driver
*/
constructor(pool, driver) {
this.pool = pool;
@@ -11,7 +11,7 @@ class DatabaseAnalyser {
async runAnalysis() {}
}
/** @returns {import('../../types').DatabaseInfo} */
/** @returns {import('@dbgate/lib').DatabaseInfo} */
DatabaseAnalyser.createEmptyStructure = () => ({
tables: [],
});

View File

@@ -1,8 +1,7 @@
/** @return {import('../types').EngineDriver} */
/** @return {import('@dbgate/lib').EngineDriver} */
function getDriver(connection) {
const { engine } = connection;
return require(`./${engine}`);
}
module.exports = getDriver;

View File

@@ -1,33 +0,0 @@
import { ChildProcess } from 'child_process';
export interface QueryResult {
rows: any[];
}
export interface EngineDriver {
connect({ server, port, user, password });
query(pool, sql: string): Promise<QueryResult>;
getVersion(pool): Promise<string>;
listDatabases(pool): Promise<{ name: string }[]>;
analyseFull(pool): Promise<void>;
analyseIncremental(pool): Promise<void>;
}
export interface NamedObjectInfo {
pureName: string;
schemaName: string;
}
export interface TableInfo extends NamedObjectInfo {
}
export interface DatabaseInfo {
tables: TableInfo[];
}
export interface OpenedDatabaseConnection {
conid: string;
database: string;
structure: DatabaseInfo;
subprocess: ChildProcess;
}

View File

@@ -3,7 +3,8 @@
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"noEmit": true
"noEmit": true,
"moduleResolution": "node",
},
"include": [
"src"

View File

@@ -46,6 +46,9 @@
esutils "^2.0.2"
js-tokens "^4.0.0"
"@dbgate/lib@file:../lib":
version "0.1.0"
"@types/lodash@^4.14.149":
version "4.14.149"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"