typings refactor - no compilation, renamed package

This commit is contained in:
Jan Prochazka 2020-02-02 12:02:41 +01:00
parent af80a2799f
commit 4fe2912707
20 changed files with 68 additions and 103 deletions

View File

@ -16,7 +16,6 @@
"nedb-promises": "^4.0.1",
"pg": "^7.17.0",
"socket.io": "^2.3.0",
"@dbgate/lib": "file:../lib",
"uuid": "^3.4.0"
},
"scripts": {
@ -26,6 +25,7 @@
"devDependencies": {
"@types/lodash": "^4.14.149",
"nodemon": "^2.0.2",
"typescript": "^3.7.4"
"typescript": "^3.7.4",
"@types/dbgate": "file:../lib"
}
}

View File

@ -6,7 +6,7 @@ const { fork } = require('child_process');
const DatabaseAnalyser = require('../engines/default/DatabaseAnalyser');
module.exports = {
/** @type {import('@dbgate/lib').OpenedDatabaseConnection[]} */
/** @type {import('dbgate').OpenedDatabaseConnection[]} */
opened: [],
requests: {},
@ -48,7 +48,7 @@ module.exports = {
return newOpened;
},
/** @param {import('@dbgate/lib').OpenedDatabaseConnection} conn */
/** @param {import('dbgate').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('@dbgate/lib').EngineDriver} driver
* @param {import('dbgate').EngineDriver} driver
*/
constructor(pool, driver) {
this.pool = pool;
@ -11,7 +11,7 @@ class DatabaseAnalyser {
async runAnalysis() {}
}
/** @returns {import('@dbgate/lib').DatabaseInfo} */
/** @returns {import('dbgate').DatabaseInfo} */
DatabaseAnalyser.createEmptyStructure = () => ({
tables: [],
});

View File

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

1
lib/.gitignore vendored
View File

@ -1 +0,0 @@
lib

View File

@ -1,17 +0,0 @@
{
"version": "0.1.0",
"name": "@dbgate/lib",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"prepare": "yarn build",
"build": "tsc"
},
"files": [
"lib"
],
"devDependencies": {
"@types/node": "^13.7.0",
"typescript": "^3.7.5"
}
}

View File

@ -1,29 +0,0 @@
import { ChildProcess } from "child_process";
export interface NamedObjectInfo {
pureName: string;
schemaName: string;
}
export interface ColumnInfo {
columnName: string;
notNull: boolean;
autoIncrement: boolean;
dataType: string;
precision: number;
scale: number;
length: number;
computedExpression: string;
isPersisted: boolean;
isSparse: boolean;
defaultValue: string;
defaultConstraint: string;
}
export interface TableInfo extends NamedObjectInfo {
columns: ColumnInfo[];
}
export interface DatabaseInfo {
tables: TableInfo[];
}

View File

@ -1,11 +0,0 @@
import { QueryResult } from "./query";
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>;
}

View File

@ -1,5 +0,0 @@
import { ChildProcess } from "child_process";
export interface QueryResult {
rows: any[];
}

View File

@ -1,11 +0,0 @@
{
"compilerOptions": {
"target": "ES2015",
"module": "commonjs",
"declaration": true,
"outDir": "lib"
},
"include": [
"src/**/*"
]
}

View File

@ -1,13 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^13.7.0":
version "13.7.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.0.tgz#b417deda18cf8400f278733499ad5547ed1abec4"
integrity sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ==
typescript@^3.7.5:
version "3.7.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae"
integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==

24
types/dbinfo.d.ts vendored Normal file
View File

@ -0,0 +1,24 @@
export interface NamedObjectInfo {
pureName: string;
schemaName: string;
}
export interface ColumnInfo {
columnName: string;
notNull: boolean;
autoIncrement: boolean;
dataType: string;
precision: number;
scale: number;
length: number;
computedExpression: string;
isPersisted: boolean;
isSparse: boolean;
defaultValue: string;
defaultConstraint: string;
}
export interface TableInfo extends NamedObjectInfo {
columns: ColumnInfo[];
}
export interface DatabaseInfo {
tables: TableInfo[];
}

16
types/engines.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import { QueryResult } from "./query";
export interface EngineDriver {
connect({ server, port, user, password }: {
server: any;
port: any;
user: any;
password: any;
}): any;
query(pool: any, sql: string): Promise<QueryResult>;
getVersion(pool: any): Promise<string>;
listDatabases(pool: any): Promise<{
name: string;
}[]>;
analyseFull(pool: any): Promise<void>;
analyseIncremental(pool: any): Promise<void>;
}

View File

@ -1,13 +1,12 @@
/// <reference types="node" />
import { ChildProcess } from "child_process";
import { DatabaseInfo } from "./dbinfo";
export interface OpenedDatabaseConnection {
conid: string;
database: string;
structure: DatabaseInfo;
subprocess: ChildProcess;
conid: string;
database: string;
structure: DatabaseInfo;
subprocess: ChildProcess;
}
export * from "./engines";
export * from "./dbinfo";
export * from "./query";

7
types/package.json Normal file
View File

@ -0,0 +1,7 @@
{
"version": "0.1.0",
"name": "@types/dbgate",
"types": "index.d.ts",
"main": "",
"typeScriptVersion": "2.8"
}

3
types/query.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export interface QueryResult {
rows: any[];
}

View File

@ -19,7 +19,6 @@
"resize-observer-polyfill": "^1.5.1",
"socket.io-client": "^2.3.0",
"styled-components": "^4.4.1",
"@dbgate/lib": "file:../lib",
"uuid": "^3.4.0"
},
"scripts": {
@ -46,6 +45,7 @@
"@fortawesome/fontawesome-free": "^5.12.0",
"@types/react": "^16.9.17",
"@types/styled-components": "^4.4.2",
"@types/dbgate": "file:../lib",
"typescript": "^3.7.4"
}
}

View File

@ -7,7 +7,7 @@ import axios from '../utility/axios';
import { openNewTab } from '../utility/common';
import { useSetOpenedTabs } from '../utility/globalState';
/** @param columnProps {import('@dbgate/lib').ColumnInfo} */
/** @param columnProps {import('dbgate').ColumnInfo} */
export default function columnAppObject(columnProps, { setOpenedTabs }) {
const title = columnProps.columnName;
const key = title;

View File

@ -15,7 +15,7 @@ const WhitePage = styled.div`
`;
export default function TableStructureTab({ conid, database, schemaName, pureName }) {
/** @type {import('@dbgate/lib').TableInfo} */
/** @type {import('dbgate').TableInfo} */
const tableInfo = useFetch({
url: 'tables/table-info',
params: { conid, database, schemaName, pureName },

View File

@ -21,6 +21,9 @@
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"types": [
"dbgate"
]
},
"include": [
"src"