refactor: use Record to type objects

This commit is contained in:
Fabio Di Stasio 2024-01-19 18:03:20 +01:00
parent eb5d3f14f1
commit 8928510fb5
40 changed files with 70 additions and 81 deletions

View File

@ -71,17 +71,6 @@ On macOS you can run `.dmg` distribution following [this guide](https://support.
[<img height='56' alt='Download on Flathub' src='https://dl.flathub.org/assets/badges/flathub-badge-en.svg'/>](https://flathub.org/apps/it.fabiodistasio.AntaresSQL) [![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/antares) [![Get it from AUR](https://raw.githubusercontent.com/antares-sql/antares/master/docs/aur-badge.svg)](https://aur.archlinux.org/packages/antares-sql-bin) [<img src="https://developer.microsoft.com/store/badges/images/English_get-it-from-MS.png" style="height: 56px">](https://www.microsoft.com/p/antares-sql-client/9nhtb9sq51r1?cid=storebadge&ocid=badge&rtc=1&activetab=pivot:overviewtab)
🚀 **[Other Downloads](https://github.com/antares-sql/antares/releases/latest)**
## Coming soon
This is a roadmap with major features will come in near future.
- Database tools.
- Users management (add/edit/delete).
- More context menu shortcuts.
- More keyboard shortcuts.
- Support for other databases.
- Apple Silicon distribution
## Currently supported
### Databases
@ -90,6 +79,7 @@ This is a roadmap with major features will come in near future.
- [x] PostgreSQL
- [x] SQLite
- [x] Firebird SQL
- [ ] DuckDB
- [ ] SQL Server
- [ ] More...

View File

@ -363,7 +363,7 @@ export interface QueryBuilderObject {
offset: number;
join: string[];
update: string[];
insert: {[key: string]: string | boolean | number }[];
insert: Record<string, string | boolean | number>[];
delete: boolean;
}

View File

@ -13,7 +13,7 @@ export interface ExportOptions {
includeContent: boolean;
includeDropStatement: boolean;
}[];
includes: {[key: string]: boolean};
includes: Record<string, boolean>;
outputFormat: 'sql' | 'sql.zip';
outputFile: string;
sqlInsertAfter: number;

View File

@ -18,7 +18,7 @@ export interface TableDeleteParams {
primary?: string;
field: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
rows: {[key: string]: any};
rows: Record<string, any>;
}
export type TableFilterOperator = '=' | '!=' | '>' | '<' | '>=' | '<=' | 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'RLIKE' | 'NOT RLIKE' | 'BETWEEN' | 'IS NULL' | 'IS NOT NULL'
@ -35,17 +35,16 @@ export interface InsertRowsParams {
uid: string;
schema: string;
table: string;
row: {[key: string]: {
group: string;
method: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
length: number;
};
};
row: Record<string, {
group: string;
method: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
length: number;
}>;
repeat: number;
fields: {[key: string]: string};
fields: Record<string, string>;
locale: UsableLocale;
}

View File

@ -41,7 +41,7 @@ export const escapeAndQuote = (val: string, client: ClientCode) => {
const { stringsWrapper: sw } = customizations[client];
// eslint-disable-next-line no-control-regex
const CHARS_TO_ESCAPE = /[\0\b\t\n\r\x1a"'\\]/g;
const CHARS_ESCAPE_MAP: {[key: string]: string} = {
const CHARS_ESCAPE_MAP: Record<string, string> = {
'\0': '\\0',
'\b': '\\b',
'\t': '\\t',
@ -153,9 +153,9 @@ export const valueToSqlString = (args: {
};
export const jsonToSqlInsert = (args: {
json: { [key: string]: any}[];
json: Record<string, any>[];
client: ClientCode;
fields: { [key: string]: {type: string; datePrecision: number}};
fields: Record<string, {type: string; datePrecision: number}>;
table: string;
options?: {sqlInsertAfter: number; sqlInsertDivider: 'bytes' | 'rows'};
}) => {

View File

@ -1,4 +1,4 @@
export const shortcutEvents: { [key: string]: { l18n: string; l18nParam?: string | number; context?: 'tab' }} = {
export const shortcutEvents: Record<string, { l18n: string; l18nParam?: string | number; context?: 'tab' }> = {
'run-or-reload': { l18n: 'application.runOrReload', context: 'tab' },
'open-new-tab': { l18n: 'application.openNewTab', context: 'tab' },
'close-tab': { l18n: 'application.closeTab', context: 'tab' },

View File

@ -6,7 +6,7 @@ import { SslOptions } from 'mysql2';
import { ClientsFactory } from '../libs/ClientsFactory';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('test-connection', async (event, conn: antares.ConnectionParams) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-databases', async (event, uid) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-function-informations', async (event, params) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -13,7 +13,7 @@ import updates from './updates';
import users from './users';
import views from './views';
const connections: {[key: string]: antares.Client} = {};
const connections: Record<string, antares.Client> = {};
export default () => {
connection(connections);

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-routine-informations', async (event, params) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-scheduler-informations', async (event, params) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -6,7 +6,7 @@ import { Worker } from 'worker_threads';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
let exporter: Worker = null;
let importer: Worker = null;

View File

@ -10,7 +10,7 @@ import * as moment from 'moment';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-table-columns', async (event, params) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
@ -249,7 +249,7 @@ export default (connections: {[key: string]: antares.Client}) => {
if (params.primary) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const idString = params.rows.map((row: {[key: string]: any}) => {
const idString = params.rows.map((row: Record<string, any>) => {
const fieldName = Object.keys(row)[0].includes('.') ? `${params.table}.${params.primary}` : params.primary;
return typeof row[fieldName] === 'string'
@ -304,10 +304,10 @@ export default (connections: {[key: string]: antares.Client}) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
try { // TODO: move to client classes
const rows: {[key: string]: string | number | boolean | Date | Buffer}[] = [];
const rows: Record<string, string | number | boolean | Date | Buffer>[] = [];
for (let i = 0; i < +params.repeat; i++) {
const insertObj: {[key: string]: string | number | boolean | Date | Buffer} = {};
const insertObj: Record<string, string | number | boolean | Date | Buffer> = {};
for (const key in params.row) {
const type = params.fields[key];
@ -367,7 +367,7 @@ export default (connections: {[key: string]: antares.Client}) => {
insertObj[key] = escapedParam;
}
else { // Faker value
const parsedParams: {[key: string]: string | number | boolean | Date | Buffer} = {};
const parsedParams: Record<string, string | number | boolean | Date | Buffer> = {};
let fakeValue;
if (params.locale)
@ -437,12 +437,12 @@ export default (connections: {[key: string]: antares.Client}) => {
if (description)
query.select(`LEFT(${description}, 20) AS foreign_description`);
const results = await query.run<{[key: string]: string}>();
const results = await query.run<Record<string, string>>();
const parsedResults: {[key: string]: string}[] = [];
const parsedResults: Record<string, string>[] = [];
for (const row of results.rows) {
const remappedRow: {[key: string]: string} = {};
const remappedRow: Record<string, string> = {};
for (const key in row)
remappedRow[key.toLowerCase()] = row[key];// Thanks Firebird -.-

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-trigger-informations', async (event, params) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-users', async (event, uid) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -3,7 +3,7 @@ import { ipcMain } from 'electron';
import { validateSender } from '../libs/misc/validateSender';
export default (connections: {[key: string]: antares.Client}) => {
export default (connections: Record<string, antares.Client>) => {
ipcMain.handle('get-view-informations', async (event, params) => {
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };

View File

@ -136,7 +136,7 @@ export abstract class BaseClient {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
insert (arr: {[key: string]: any}[]) {
insert (arr: Record<string, any>[]) {
this._query.insert = [...this._query.insert, ...arr];
return this;
}

View File

@ -13,7 +13,7 @@ export class FirebirdSQLClient extends BaseClient {
protected _connection?: firebird.Database | firebird.ConnectionPool;
_params: firebird.Options;
private _types: {[key: number]: string} ={
private _types: Record<number, string> ={
452: 'CHAR', // Array of char
448: 'VARCHAR',
500: 'SMALLINT',

View File

@ -15,7 +15,7 @@ export class MySQLClient extends BaseClient {
_connection?: mysql.Connection | mysql.Pool;
_params: mysql.ConnectionOptions & {schema: string; ssl?: mysql.SslOptions; ssh?: SSHConfig; readonly: boolean};
private types: {[key: number]: string} = {
private types: Record<number, string> = {
0: 'DECIMAL',
1: 'TINYINT',
2: 'SMALLINT',
@ -582,7 +582,7 @@ export class MySQLClient extends BaseClient {
}
})
.filter(Boolean)
.reduce((acc: {[key: string]: { name: string; type: string; length: string; default: string}}, curr) => {
.reduce((acc: Record<string, { name: string; type: string; length: string; default: string}>, curr) => {
acc[curr.name] = curr;
return acc;
}, {});

View File

@ -88,8 +88,8 @@ export class PostgreSQLClient extends BaseClient {
private _keepaliveTimer: NodeJS.Timer;
private _keepaliveMs: number;
protected _connection?: pg.Client | pg.Pool;
private types: {[key: string]: string} = {};
private _arrayTypes: {[key: string]: string} = {
private types: Record<string, string> = {};
private _arrayTypes: Record<string, string> = {
_int2: 'SMALLINT',
_int4: 'INTEGER',
_int8: 'BIGINT',
@ -656,7 +656,7 @@ export class PostgreSQLClient extends BaseClient {
let createSql = '';
const sequences = [];
const columnsSql = [];
const arrayTypes: {[key: string]: string} = {
const arrayTypes: Record<string, string> = {
_int2: 'smallint',
_int4: 'integer',
_int8: 'bigint',

View File

@ -658,7 +658,7 @@ export class SQLiteClient extends BaseClient {
let queryAllResult: any[];
let affectedRows;
let fields;
const detectedTypes: {[key: string]: string} = {};
const detectedTypes: Record<string, string> = {};
try {
const stmt = connection.prepare(query);

View File

@ -354,7 +354,7 @@ CREATE TABLE \`${view.Name}\`(
escapeAndQuote (val: string) {
// eslint-disable-next-line no-control-regex
const CHARS_TO_ESCAPE = /[\0\b\t\n\r\x1a"'\\]/g;
const CHARS_ESCAPE_MAP: {[key: string]: string} = {
const CHARS_ESCAPE_MAP: Record<string, string> = {
'\0': '\\0',
'\b': '\\b',
'\t': '\\t',

View File

@ -59,7 +59,7 @@ SET row_security = off;\n\n\n`;
let createSql = '';
const sequences = [];
const columnsSql = [];
const arrayTypes: {[key: string]: string} = {
const arrayTypes: Record<string, string> = {
_int2: 'smallint',
_int4: 'integer',
_int8: 'bigint',
@ -440,7 +440,7 @@ SET row_security = off;\n\n\n`;
escapeAndQuote (val: string) {
// eslint-disable-next-line no-control-regex
const CHARS_TO_ESCAPE = /[\0\b\t\n\r\x1a"'\\]/g;
const CHARS_ESCAPE_MAP: {[key: string]: string} = {
const CHARS_ESCAPE_MAP: Record<string, string> = {
'\0': '\\0',
'\b': '\\b',
'\t': '\\t',

View File

@ -113,7 +113,7 @@ const selectedGroup: Ref<string> = ref('manual');
const selectedMethod: Ref<string> = ref('');
const selectedValue: Ref<string> = ref('');
const debounceTimeout: Ref<NodeJS.Timeout> = ref(null);
const methodParams: Ref<{[key: string]: string}> = ref({});
const methodParams: Ref<Record<string, string>> = ref({});
const enumArray: Ref<string[]> = ref(null);
const fakerGroups = computed(() => {

View File

@ -73,7 +73,7 @@ const props = defineProps({
const emit = defineEmits(['confirm', 'close']);
const firstInput: Ref<HTMLInputElement[]> = ref(null);
const values: Ref<{[key: string]: string}> = ref({});
const values: Ref<Record<string, string>> = ref({});
const inParameters = computed(() => {
return props.localRoutine.parameters.filter(param => param.context === 'IN');

View File

@ -327,7 +327,7 @@ const tables: Ref<{
}[]> = ref([]);
const options: Ref<Partial<ExportOptions>> = ref({
schema: selectedSchema.value,
includes: {} as {[key: string]: boolean},
includes: {} as Record<string, boolean>,
outputFormat: 'sql' as 'sql' | 'sql.zip',
sqlInsertAfter: 250,
sqlInsertDivider: 'bytes' as 'bytes' | 'rows'

View File

@ -142,7 +142,7 @@ const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
const { trapRef } = useFocusTrap({ disableAutofocus: true });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const localRow: Ref<{[key: string]: any}> = ref({});
const localRow: Ref<Record<string, any>> = ref({});
const fieldsToExclude = ref([]);
const nInserts = ref(1);
const isInserting = ref(false);
@ -225,7 +225,7 @@ const insertRows = async () => {
delete rowToInsert[key];
});
const fieldTypes: {[key: string]: string} = {};
const fieldTypes: Record<string, string> = {};
props.fields.forEach(field => {
fieldTypes[field.name] = field.type;
});
@ -290,7 +290,7 @@ onMounted(() => {
}
}, 50);
const rowObj: {[key: string]: unknown} = {};
const rowObj: Record<string, unknown> = {};
if (!props.rowToDuplicate) {
// Set default values

View File

@ -67,7 +67,7 @@ const props = defineProps({
const emit = defineEmits(['select-row', 'contextmenu', 'stop-refresh']);
const isInlineEditor: Ref<{[key: string]: boolean}> = ref({});
const isInlineEditor: Ref<Record<string, boolean>> = ref({});
const isInfoModal = ref(false);
const editorMode = ref('sql');

View File

@ -32,7 +32,7 @@ const { removeNotification } = notificationsStore;
const { notifications } = storeToRefs(notificationsStore);
const { notificationsTimeout } = storeToRefs(settingsStore);
const timeouts: Ref<{[key: string]: NodeJS.Timeout}> = ref({});
const timeouts: Ref<Record<string, NodeJS.Timeout>> = ref({});
const latestNotifications = computed(() => notifications.value.slice(0, 10));

View File

@ -695,7 +695,7 @@ const openAsPermanentTab = (tab: WorkspaceTab) => {
routine: 'routine-props',
procedure: 'routine-props',
scheduler: 'scheduler-props'
} as {[key: string]: string};
} as Record<string, string>;
newTab({
uid: props.connection.uid,

View File

@ -572,11 +572,11 @@ const pathSelection = (event: Event & {target: {files: {path: string}[]}}, name:
const { files } = event.target;
if (!files.length) return;
(connection.value as unknown as {[key: string]: string})[name] = files[0].path as string;
(connection.value as unknown as Record<string, string>)[name] = files[0].path as string;
};
const pathClear = (name: keyof ConnectionParams) => {
(connection.value as unknown as {[key: string]: string})[name] = '';
(connection.value as unknown as Record<string, string>)[name] = '';
};
setDefaults();

View File

@ -569,11 +569,11 @@ const pathSelection = (event: Event & {target: {files: {path: string}[]}}, name:
const { files } = event.target;
if (!files.length) return;
(localConnection.value as unknown as {[key: string]: string})[name] = files[0].path;
(localConnection.value as unknown as Record<string, string>)[name] = files[0].path;
};
const pathClear = (name: keyof ConnectionParams) => {
(localConnection.value as unknown as {[key: string]: string})[name] = '';
(localConnection.value as unknown as Record<string, string>)[name] = '';
};
localConnection.value = JSON.parse(JSON.stringify(props.connection));

View File

@ -382,7 +382,7 @@ const getFieldsData = async () => {
if (status === 'success') {
const indexesObj = response
.filter((index: TableIndex) => index.type !== 'FOREIGN KEY')
.reduce((acc: {[key: string]: TableIndex[]}, curr: TableIndex) => {
.reduce((acc: Record<string, TableIndex[]>, curr: TableIndex) => {
acc[curr.name] = acc[curr.name] || [];
acc[curr.name].push(curr);
return acc;

View File

@ -258,7 +258,7 @@ const indexesPanel: Ref<HTMLDivElement> = ref(null);
const foreignProxy = ref([]);
const selectedForeignID = ref('');
const modalInnerHeight = ref(400);
const refFields = ref({} as {[key: string]: TableField[]});
const refFields = ref({} as Record<string, TableField[]>);
const foreignActions = computed(() => props.workspace.customizations.foreignActions);
const selectedForeignObj = computed(() => foreignProxy.value.find(foreign => foreign._antares_id === selectedForeignID.value));

View File

@ -28,7 +28,7 @@ export function useFilters () {
return `(${num})`;
};
const parseKeys = (keys: {[key: number]: string}[]) => {
const parseKeys = (keys: Record<number, string>[]) => {
const isMacOS = process.platform === 'darwin';
return (keys as string[]).map(k => (
k.split('+')

View File

@ -1,4 +1,4 @@
export const localesNames: {[key: string]: string} = {
export const localesNames: Record<string, string> = {
'en-US': 'English',
'it-IT': 'Italiano',
'ar-SA': 'العربية',

View File

@ -64,7 +64,7 @@ export default class {
primary?: string;
field: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
rows: {[key: string]: any};
rows: Record<string, any>;
}): Promise<IpcResponse> {
return ipcRenderer.invoke('delete-table-rows', unproxify(params));
}
@ -73,9 +73,9 @@ export default class {
uid: string;
schema: string;
table: string;
row: {[key: string]: string | number | boolean | Date | Buffer};
row: Record<string, string | number | boolean | Date | Buffer>;
repeat: number;
fields: {[key: string]: string};
fields: Record<string, string>;
locale: string;
}): Promise<IpcResponse> {
return ipcRenderer.invoke('insert-table-fake-rows', unproxify(params));

View File

@ -13,7 +13,7 @@ export interface HistoryRecord {
export const useHistoryStore = defineStore('history', {
state: () => ({
history: persistentStore.get('history', {}) as {[key: string]: HistoryRecord[]},
history: persistentStore.get('history', {}) as Record<string, HistoryRecord[]>,
favorites: persistentStore.get('favorites', {})
}),
getters: {

View File

@ -86,11 +86,11 @@ export interface Workspace {
arch: string;
os: string;
};
engines?: {[key: string]: string | boolean | number}[];
engines?: Record<string, string | boolean | number>[];
}
const persistentStore = new Store({ name: 'tabs' });
const tabIndex: {[key: string]: number} = {};
const tabIndex: Record<string, number> = {};
export const useWorkspacesStore = defineStore('workspaces', {
state: () => ({