diff --git a/package.json b/package.json index 44c9eb55..890c9bb9 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "@babel/preset-typescript": "~7.16.7", "@playwright/test": "~1.21.1", "@types/better-sqlite3": "~7.5.0", + "@types/leaflet": "~1.7.9", "@types/node": "~17.0.23", "@types/pg": "~8.6.5", "@typescript-eslint/eslint-plugin": "~5.18.0", diff --git a/src/common/FakerMethods.js b/src/common/FakerMethods.ts similarity index 100% rename from src/common/FakerMethods.js rename to src/common/FakerMethods.ts diff --git a/src/common/customizations/defaults.js b/src/common/customizations/defaults.ts similarity index 88% rename from src/common/customizations/defaults.js rename to src/common/customizations/defaults.ts index 40b949e2..794a72d4 100644 --- a/src/common/customizations/defaults.js +++ b/src/common/customizations/defaults.ts @@ -1,4 +1,6 @@ -module.exports = { +import { Customizations } from '../interfaces/customizations'; + +export const defaults: Customizations = { // Defaults defaultPort: null, defaultUser: null, @@ -68,24 +70,24 @@ module.exports = { viewUpdateOption: false, procedureDeterministic: false, procedureDataAccess: false, - procedureSql: false, + procedureSql: null, procedureContext: false, procedureLanguage: false, functionDeterministic: false, functionDataAccess: false, - functionSql: false, + functionSql: null, functionContext: false, functionLanguage: false, - triggerSql: false, + triggerSql: null, triggerStatementInCreation: false, triggerMultipleEvents: false, triggerTableInName: false, triggerUpdateColumns: false, triggerOnlyRename: false, triggerEnableDisable: false, - triggerFunctionSql: false, - triggerFunctionlanguages: false, + triggerFunctionSql: null, + triggerFunctionlanguages: null, parametersLength: false, - languages: false, + languages: null, readOnlyMode: false }; diff --git a/src/common/customizations/index.js b/src/common/customizations/index.js deleted file mode 100644 index 931e18f2..00000000 --- a/src/common/customizations/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - maria: require('./mysql'), - mysql: require('./mysql'), - pg: require('./postgresql'), - sqlite: require('./sqlite') -}; diff --git a/src/common/customizations/index.ts b/src/common/customizations/index.ts new file mode 100644 index 00000000..2a8f3726 --- /dev/null +++ b/src/common/customizations/index.ts @@ -0,0 +1,10 @@ +import * as mysql from 'common/customizations/mysql'; +import * as postgresql from 'common/customizations/postgresql'; +import * as sqlite from 'common/customizations/sqlite'; + +export default { + maria: mysql.customizations, + mysql: mysql.customizations, + pg: postgresql.customizations, + sqlite: sqlite.customizations +}; diff --git a/src/common/customizations/mysql.js b/src/common/customizations/mysql.ts similarity index 91% rename from src/common/customizations/mysql.js rename to src/common/customizations/mysql.ts index 5d47cac9..e5cd4526 100644 --- a/src/common/customizations/mysql.js +++ b/src/common/customizations/mysql.ts @@ -1,6 +1,7 @@ -const defaults = require('./defaults'); +import { Customizations } from '../interfaces/customizations'; +import { defaults } from './defaults'; -module.exports = { +export const customizations: Customizations = { ...defaults, // Defaults defaultPort: 3306, diff --git a/src/common/customizations/postgresql.js b/src/common/customizations/postgresql.ts similarity index 91% rename from src/common/customizations/postgresql.js rename to src/common/customizations/postgresql.ts index 9d8f1936..7bf06e8f 100644 --- a/src/common/customizations/postgresql.js +++ b/src/common/customizations/postgresql.ts @@ -1,6 +1,7 @@ -const defaults = require('./defaults'); +import { Customizations } from '../interfaces/customizations'; +import { defaults } from './defaults'; -module.exports = { +export const customizations: Customizations = { ...defaults, // Defaults defaultPort: 5432, diff --git a/src/common/customizations/sqlite.js b/src/common/customizations/sqlite.ts similarity index 76% rename from src/common/customizations/sqlite.js rename to src/common/customizations/sqlite.ts index 83c6cdb3..f9ac7f28 100644 --- a/src/common/customizations/sqlite.js +++ b/src/common/customizations/sqlite.ts @@ -1,4 +1,8 @@ -module.exports = { +import { Customizations } from '../interfaces/customizations'; +import { defaults } from './defaults'; + +export const customizations: Customizations = { + ...defaults, // Core fileConnection: true, // Structure diff --git a/src/common/data-types/mysql.js b/src/common/data-types/mysql.ts similarity index 99% rename from src/common/data-types/mysql.js rename to src/common/data-types/mysql.ts index f2e3a1b6..e4afc2eb 100644 --- a/src/common/data-types/mysql.js +++ b/src/common/data-types/mysql.ts @@ -1,4 +1,4 @@ -module.exports = [ +export default [ { group: 'integer', types: [ diff --git a/src/common/data-types/postgresql.js b/src/common/data-types/postgresql.ts similarity index 99% rename from src/common/data-types/postgresql.js rename to src/common/data-types/postgresql.ts index e666229b..547a021d 100644 --- a/src/common/data-types/postgresql.js +++ b/src/common/data-types/postgresql.ts @@ -1,4 +1,4 @@ -module.exports = [ +export default [ { group: 'integer', types: [ diff --git a/src/common/data-types/sqlite.js b/src/common/data-types/sqlite.ts similarity index 99% rename from src/common/data-types/sqlite.js rename to src/common/data-types/sqlite.ts index c7ac6b32..0afa316f 100644 --- a/src/common/data-types/sqlite.js +++ b/src/common/data-types/sqlite.ts @@ -1,4 +1,4 @@ -module.exports = [ +export default [ { group: 'integer', types: [ diff --git a/src/common/fieldTypes.js b/src/common/fieldTypes.ts similarity index 100% rename from src/common/fieldTypes.js rename to src/common/fieldTypes.ts diff --git a/src/common/index-types/mysql.js b/src/common/index-types/mysql.ts similarity index 74% rename from src/common/index-types/mysql.js rename to src/common/index-types/mysql.ts index a9e52124..103179d3 100644 --- a/src/common/index-types/mysql.js +++ b/src/common/index-types/mysql.ts @@ -1,4 +1,4 @@ -module.exports = [ +export default [ 'PRIMARY', 'INDEX', 'UNIQUE', diff --git a/src/common/index-types/postgresql.js b/src/common/index-types/postgresql.ts similarity index 68% rename from src/common/index-types/postgresql.js rename to src/common/index-types/postgresql.ts index edc2f2a3..cb7fa05c 100644 --- a/src/common/index-types/postgresql.js +++ b/src/common/index-types/postgresql.ts @@ -1,4 +1,4 @@ -module.exports = [ +export default [ 'PRIMARY', 'INDEX', 'UNIQUE' diff --git a/src/common/index-types/sqlite.js b/src/common/index-types/sqlite.ts similarity index 68% rename from src/common/index-types/sqlite.js rename to src/common/index-types/sqlite.ts index edc2f2a3..cb7fa05c 100644 --- a/src/common/index-types/sqlite.js +++ b/src/common/index-types/sqlite.ts @@ -1,4 +1,4 @@ -module.exports = [ +export default [ 'PRIMARY', 'INDEX', 'UNIQUE' diff --git a/src/common/interfaces/customizations.ts b/src/common/interfaces/customizations.ts new file mode 100644 index 00000000..de5041e8 --- /dev/null +++ b/src/common/interfaces/customizations.ts @@ -0,0 +1,91 @@ +export interface Customizations { + // Defaults + defaultPort?: number; + defaultUser?: string; + defaultDatabase?: string; + // Core + database?: boolean; + collations?: boolean; + engines?: boolean; + connectionSchema?: boolean; + sslConnection?: boolean; + sshConnection?: boolean; + fileConnection?: boolean; + cancelQueries?: boolean; + // Tools + processesList?: boolean; + usersManagement?: boolean; + variables?: boolean; + // Structure + schemas?: boolean; + tables?: boolean; + views?: boolean; + triggers?: boolean; + triggerFunctions?: boolean; + routines?: boolean; + functions?: boolean; + schedulers?: boolean; + // Settings + elementsWrapper: string; + stringsWrapper: string; + tableAdd?: boolean; + viewAdd?: boolean; + triggerAdd?: boolean; + triggerFunctionAdd?: boolean; + routineAdd?: boolean; + functionAdd?: boolean; + schedulerAdd?: boolean; + databaseEdit?: boolean; + schemaEdit?: boolean; + schemaDrop?: boolean; + schemaExport?: boolean; + exportByChunks?: boolean; + schemaImport?: boolean; + tableSettings?: boolean; + tableOptions?: boolean; + tableArray?: boolean; + tableRealCount?: boolean; + viewSettings?: boolean; + triggerSettings?: boolean; + triggerFunctionSettings?: boolean; + routineSettings?: boolean; + functionSettings?: boolean; + schedulerSettings?: boolean; + indexes?: boolean; + foreigns?: boolean; + sortableFields?: boolean; + unsigned?: boolean; + nullable?: boolean; + nullablePrimary?: boolean; + zerofill?: boolean; + autoIncrement?: boolean; + comment?: boolean; + collation?: boolean; + definer?: boolean; + onUpdate?: boolean; + viewAlgorithm?: boolean; + viewSqlSecurity?: boolean; + viewUpdateOption?: boolean; + procedureDeterministic?: boolean; + procedureDataAccess?: boolean; + procedureSql?: string; + procedureContext?: boolean; + procedureLanguage?: boolean; + functionDeterministic?: boolean; + functionDataAccess?: boolean; + functionSql?: string; + functionContext?: boolean; + functionLanguage?: boolean; + triggerSql?: string; + triggerStatementInCreation?: boolean; + triggerMultipleEvents?: boolean; + triggerTableInName?: boolean; + triggerUpdateColumns?: boolean; + triggerOnlyRename?: boolean; + triggerEnableDisable?: boolean; + triggerFunctionSql?: string; + triggerFunctionlanguages?: string[]; + parametersLength?: boolean; + languages?: string[]; + readOnlyMode?: boolean; +} diff --git a/src/common/libs/bufferToBase64.js b/src/common/libs/bufferToBase64.ts similarity index 56% rename from src/common/libs/bufferToBase64.js rename to src/common/libs/bufferToBase64.ts index 8106dec3..62db5d49 100644 --- a/src/common/libs/bufferToBase64.js +++ b/src/common/libs/bufferToBase64.ts @@ -1,7 +1,6 @@ -'use strict'; -export function bufferToBase64 (buf) { +export function bufferToBase64 (buf: Buffer) { const binstr = Array.prototype.map.call(buf, ch => { return String.fromCharCode(ch); }).join(''); - return btoa(binstr); + return Buffer.from(binstr, 'base64'); } diff --git a/src/common/libs/formatBytes.js b/src/common/libs/formatBytes.ts similarity index 82% rename from src/common/libs/formatBytes.js rename to src/common/libs/formatBytes.ts index e2f87942..4912c562 100644 --- a/src/common/libs/formatBytes.js +++ b/src/common/libs/formatBytes.ts @@ -1,5 +1,4 @@ -'use strict'; -export function formatBytes (bytes, decimals = 2) { +export function formatBytes (bytes: number, decimals = 2) { if (bytes === 0) return '0 Bytes'; const k = 1024; diff --git a/src/common/libs/getArrayDepth.js b/src/common/libs/getArrayDepth.js deleted file mode 100644 index 04e62e77..00000000 --- a/src/common/libs/getArrayDepth.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * - * @param {any[]} array - * @returns {number} - */ -export function getArrayDepth (array) { - return Array.isArray(array) - ? 1 + Math.max(0, ...array.map(getArrayDepth)) - : 0; -} diff --git a/src/common/libs/getArrayDepth.ts b/src/common/libs/getArrayDepth.ts new file mode 100644 index 00000000..b3b6254a --- /dev/null +++ b/src/common/libs/getArrayDepth.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +export function getArrayDepth (array: any[]): number { + return Array.isArray(array) + ? 1 + Math.max(0, ...array.map(getArrayDepth)) + : 0; +} diff --git a/src/common/libs/hexToBinary.js b/src/common/libs/hexToBinary.ts similarity index 69% rename from src/common/libs/hexToBinary.js rename to src/common/libs/hexToBinary.ts index 305bcf7e..a686c8ef 100644 --- a/src/common/libs/hexToBinary.js +++ b/src/common/libs/hexToBinary.ts @@ -1,5 +1,3 @@ -'use strict'; - const lookup = { 0: '0000', 1: '0001', @@ -23,15 +21,11 @@ const lookup = { D: '1101', E: '1110', F: '1111' -}; +} as const; -/** - * Converts hexadecimal string to binary string - * - * @param {string} hex Hexadecimal string - * @returns {string} Binary string - */ -export default function hexToBinary (hex) { +type HexChar = keyof typeof lookup + +export default function hexToBinary (hex: HexChar[]) { let binary = ''; for (let i = 0; i < hex.length; i++) binary += lookup[hex[i]]; diff --git a/src/common/libs/mimeFromHex.js b/src/common/libs/mimeFromHex.ts similarity index 95% rename from src/common/libs/mimeFromHex.js rename to src/common/libs/mimeFromHex.ts index 13613acf..9e4ecbff 100644 --- a/src/common/libs/mimeFromHex.js +++ b/src/common/libs/mimeFromHex.ts @@ -1,5 +1,4 @@ -'use strict'; -export function mimeFromHex (hex) { +export function mimeFromHex (hex: string) { switch (hex.substring(0, 4)) { // 2 bytes case '424D': return { ext: 'bmp', mime: 'image/bmp' }; @@ -23,7 +22,7 @@ export function mimeFromHex (hex) { case '425A68': return { ext: 'bz2', mime: 'application/x-bzip2' }; default: - switch (hex) { // 4 bytes + switch (hex) { // 4 bites case '89504E47': return { ext: 'png', mime: 'image/png' }; case '47494638': diff --git a/src/common/libs/sqlEscaper.js b/src/common/libs/sqlEscaper.ts similarity index 81% rename from src/common/libs/sqlEscaper.js rename to src/common/libs/sqlEscaper.ts index f9424122..956e12e2 100644 --- a/src/common/libs/sqlEscaper.js +++ b/src/common/libs/sqlEscaper.ts @@ -3,13 +3,7 @@ const pattern = /[\0\x08\x09\x1a\n\r"'\\\%]/gm; const regex = new RegExp(pattern); -/** - * Escapes a string - * - * @param {String} string - * @returns {String} - */ -function sqlEscaper (string) { +function sqlEscaper (string: string) { return string.replace(regex, char => { const m = ['\\0', '\\x08', '\\x09', '\\x1a', '\\n', '\\r', '\'', '\"', '\\', '\\\\', '%']; const r = ['\\\\0', '\\\\b', '\\\\t', '\\\\z', '\\\\n', '\\\\r', '\\\'', '\\\"', '\\\\', '\\\\\\\\', '\%']; diff --git a/src/common/libs/uidGen.js b/src/common/libs/uidGen.js deleted file mode 100644 index 929fc648..00000000 --- a/src/common/libs/uidGen.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @export - * @param {String} [prefix] - * @returns {String} Unique ID - */ -export function uidGen (prefix) { - return (prefix ? `${prefix}:` : '') + Math.random().toString(36).substr(2, 9).toUpperCase(); -} diff --git a/src/common/libs/uidGen.ts b/src/common/libs/uidGen.ts new file mode 100644 index 00000000..a9ee9042 --- /dev/null +++ b/src/common/libs/uidGen.ts @@ -0,0 +1,3 @@ +export function uidGen (prefix?: string) { + return (prefix ? `${prefix}:` : '') + Math.random().toString(36).substr(2, 9).toUpperCase(); +} diff --git a/tsconfig.json b/tsconfig.json index 606af9f9..6b3be750 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "allowJs": true, "module": "CommonJS", "noImplicitAny": true, + "jsx": "preserve", "types": [ "node" ], @@ -19,7 +20,8 @@ "resolveJsonModule": true, "removeComments": true, "paths": { - "common/*": ["./src/common/*"] + "common/*": ["./src/common/*"], + "@/*": ["./src/renderer/*"], } } } \ No newline at end of file diff --git a/webpack.renderer.config.js b/webpack.renderer.config.js index 5f7cf8f4..46730377 100644 --- a/webpack.renderer.config.js +++ b/webpack.renderer.config.js @@ -27,7 +27,7 @@ const config = { name: 'renderer', mode: process.env.NODE_ENV, devtool: isDevMode ? 'eval-source-map' : false, - entry: path.join(__dirname, './src/renderer/index.js'), + entry: path.join(__dirname, './src/renderer/index.ts'), target: 'electron-renderer', output: { path: path.resolve(__dirname, 'dist'),