From e60789f3205a4e32cdcab034fb965a2c38f8a39a Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Fri, 22 Apr 2022 12:17:27 +0200 Subject: [PATCH] refactor: unproxify ipc params --- src/common/libs/unproxify.js | 14 ++++++++++++ src/renderer/ipc-api/Application.js | 5 +++-- src/renderer/ipc-api/Connection.js | 6 +++--- src/renderer/ipc-api/Functions.js | 13 ++++++------ src/renderer/ipc-api/Routines.js | 9 ++++---- src/renderer/ipc-api/Schedulers.js | 11 +++++----- src/renderer/ipc-api/Schema.js | 29 +++++++++++++------------ src/renderer/ipc-api/Tables.js | 33 +++++++++++++++-------------- src/renderer/ipc-api/Triggers.js | 11 +++++----- src/renderer/ipc-api/Users.js | 3 ++- src/renderer/ipc-api/Views.js | 9 ++++---- 11 files changed, 83 insertions(+), 60 deletions(-) create mode 100644 src/common/libs/unproxify.js diff --git a/src/common/libs/unproxify.js b/src/common/libs/unproxify.js new file mode 100644 index 00000000..41af79f2 --- /dev/null +++ b/src/common/libs/unproxify.js @@ -0,0 +1,14 @@ +/** + * @param {*} val + * @param {Boolean} json converts the value in JSON object (default true) + */ +export function unproxify (val, json = true) { + if (json)// JSON conversion + return JSON.parse(JSON.stringify(val)); + else if (!(Symbol.iterator in Object(val)))// If not iterable + return val; + else if (Array.isArray(val))// If array + return [...val]; + else // If object + return { ...val }; +} diff --git a/src/renderer/ipc-api/Application.js b/src/renderer/ipc-api/Application.js index c93b0c2e..02c25fc3 100644 --- a/src/renderer/ipc-api/Application.js +++ b/src/renderer/ipc-api/Application.js @@ -1,13 +1,14 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getKey (params) { - return ipcRenderer.sendSync('get-key', params); + return ipcRenderer.sendSync('get-key', unproxify(params)); } static showOpenDialog (options) { - return ipcRenderer.invoke('showOpenDialog', options); + return ipcRenderer.invoke('show-open-dialog', unproxify(options)); } static getDownloadPathDirectory () { diff --git a/src/renderer/ipc-api/Connection.js b/src/renderer/ipc-api/Connection.js index d601cc63..7bc70e3f 100644 --- a/src/renderer/ipc-api/Connection.js +++ b/src/renderer/ipc-api/Connection.js @@ -1,17 +1,17 @@ 'use strict'; import { ipcRenderer } from 'electron'; - +import { unproxify } from 'common/libs/unproxify'; import connStringConstruct from '../libs/connStringDecode'; export default class { static makeTest (params) { params = connStringConstruct(params); - return ipcRenderer.invoke('test-connection', { ...params }); + return ipcRenderer.invoke('test-connection', unproxify(params)); } static connect (params) { params = connStringConstruct(params); - return ipcRenderer.invoke('connect', { ...params }); + return ipcRenderer.invoke('connect', unproxify(params)); } static checkConnection (uid) { diff --git a/src/renderer/ipc-api/Functions.js b/src/renderer/ipc-api/Functions.js index 9d5da831..e35b75ca 100644 --- a/src/renderer/ipc-api/Functions.js +++ b/src/renderer/ipc-api/Functions.js @@ -1,28 +1,29 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getFunctionInformations (params) { - return ipcRenderer.invoke('get-function-informations', params); + return ipcRenderer.invoke('get-function-informations', unproxify(params)); } static dropFunction (params) { - return ipcRenderer.invoke('drop-function', params); + return ipcRenderer.invoke('drop-function', unproxify(params)); } static alterFunction (params) { - return ipcRenderer.invoke('alter-function', params); + return ipcRenderer.invoke('alter-function', unproxify(params)); } static alterTriggerFunction (params) { - return ipcRenderer.invoke('alter-trigger-function', params); + return ipcRenderer.invoke('alter-trigger-function', unproxify(params)); } static createFunction (params) { - return ipcRenderer.invoke('create-function', params); + return ipcRenderer.invoke('create-function', unproxify(params)); } static createTriggerFunction (params) { - return ipcRenderer.invoke('create-trigger-function', params); + return ipcRenderer.invoke('create-trigger-function', unproxify(params)); } } diff --git a/src/renderer/ipc-api/Routines.js b/src/renderer/ipc-api/Routines.js index 49ac3610..0c508c81 100644 --- a/src/renderer/ipc-api/Routines.js +++ b/src/renderer/ipc-api/Routines.js @@ -1,20 +1,21 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getRoutineInformations (params) { - return ipcRenderer.invoke('get-routine-informations', params); + return ipcRenderer.invoke('get-routine-informations', unproxify(params)); } static dropRoutine (params) { - return ipcRenderer.invoke('drop-routine', params); + return ipcRenderer.invoke('drop-routine', unproxify(params)); } static alterRoutine (params) { - return ipcRenderer.invoke('alter-routine', params); + return ipcRenderer.invoke('alter-routine', unproxify(params)); } static createRoutine (params) { - return ipcRenderer.invoke('create-routine', params); + return ipcRenderer.invoke('create-routine', unproxify(params)); } } diff --git a/src/renderer/ipc-api/Schedulers.js b/src/renderer/ipc-api/Schedulers.js index 628f1683..112ad68d 100644 --- a/src/renderer/ipc-api/Schedulers.js +++ b/src/renderer/ipc-api/Schedulers.js @@ -1,24 +1,25 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getSchedulerInformations (params) { - return ipcRenderer.invoke('get-scheduler-informations', params); + return ipcRenderer.invoke('get-scheduler-informations', unproxify(params)); } static dropScheduler (params) { - return ipcRenderer.invoke('drop-scheduler', params); + return ipcRenderer.invoke('drop-scheduler', unproxify(params)); } static alterScheduler (params) { - return ipcRenderer.invoke('alter-scheduler', params); + return ipcRenderer.invoke('alter-scheduler', unproxify(params)); } static createScheduler (params) { - return ipcRenderer.invoke('create-scheduler', params); + return ipcRenderer.invoke('create-scheduler', unproxify(params)); } static toggleScheduler (params) { - return ipcRenderer.invoke('toggle-scheduler', params); + return ipcRenderer.invoke('toggle-scheduler', unproxify(params)); } } diff --git a/src/renderer/ipc-api/Schema.js b/src/renderer/ipc-api/Schema.js index d9cfd77a..b56a5939 100644 --- a/src/renderer/ipc-api/Schema.js +++ b/src/renderer/ipc-api/Schema.js @@ -1,25 +1,26 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static createSchema (params) { - return ipcRenderer.invoke('create-schema', { ...params }); + return ipcRenderer.invoke('create-schema', unproxify(params)); } static updateSchema (params) { - return ipcRenderer.invoke('update-schema', { ...params }); + return ipcRenderer.invoke('update-schema', unproxify(params)); } static getDatabaseCollation (params) { - return ipcRenderer.invoke('get-schema-collation', { ...params }); + return ipcRenderer.invoke('get-schema-collation', unproxify(params)); } static deleteSchema (params) { - return ipcRenderer.invoke('delete-schema', { ...params }); + return ipcRenderer.invoke('delete-schema', unproxify(params)); } static getStructure (params) { - return ipcRenderer.invoke('get-structure', { ...params }); + return ipcRenderer.invoke('get-structure', unproxify(params, false)); } static getCollations (uid) { @@ -43,35 +44,35 @@ export default class { } static killProcess (params) { - return ipcRenderer.invoke('kill-process', { ...params }); + return ipcRenderer.invoke('kill-process', unproxify(params)); } static killTabQuery (params) { - return ipcRenderer.invoke('kill-tab-query', { ...params }); + return ipcRenderer.invoke('kill-tab-query', unproxify(params)); } static commitTab (params) { - return ipcRenderer.invoke('commit-tab', { ...params }); + return ipcRenderer.invoke('commit-tab', unproxify(params)); } static rollbackTab (params) { - return ipcRenderer.invoke('rollback-tab', { ...params }); + return ipcRenderer.invoke('rollback-tab', unproxify(params)); } static destroyConnectionToCommit (params) { - return ipcRenderer.invoke('destroy-connection-to-commit', { ...params }); + return ipcRenderer.invoke('destroy-connection-to-commit', unproxify(params)); } static useSchema (params) { - return ipcRenderer.invoke('use-schema', { ...params }); + return ipcRenderer.invoke('use-schema', unproxify(params)); } static rawQuery (params) { - return ipcRenderer.invoke('raw-query', { ...params }); + return ipcRenderer.invoke('raw-query', unproxify(params)); } static export (params) { - return ipcRenderer.invoke('export', { ...params }); + return ipcRenderer.invoke('export', unproxify(params)); } static abortExport () { @@ -79,7 +80,7 @@ export default class { } static import (params) { - return ipcRenderer.invoke('import-sql', { ...params }); + return ipcRenderer.invoke('import-sql', unproxify(params)); } static abortImport () { diff --git a/src/renderer/ipc-api/Tables.js b/src/renderer/ipc-api/Tables.js index 3e499aed..a51bfb9f 100644 --- a/src/renderer/ipc-api/Tables.js +++ b/src/renderer/ipc-api/Tables.js @@ -1,68 +1,69 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getTableColumns (params) { - return ipcRenderer.invoke('get-table-columns', { ...params }); + return ipcRenderer.invoke('get-table-columns', unproxify(params)); } static getTableData (params) { - return ipcRenderer.invoke('get-table-data', { ...params }); + return ipcRenderer.invoke('get-table-data', unproxify(params)); } static getTableApproximateCount (params) { - return ipcRenderer.invoke('get-table-count', { ...params }); + return ipcRenderer.invoke('get-table-count', unproxify(params)); } static getTableOptions (params) { - return ipcRenderer.invoke('get-table-options', { ...params }); + return ipcRenderer.invoke('get-table-options', unproxify(params)); } static getTableIndexes (params) { - return ipcRenderer.invoke('get-table-indexes', { ...params }); + return ipcRenderer.invoke('get-table-indexes', unproxify(params)); } static getKeyUsage (params) { - return ipcRenderer.invoke('get-key-usage', { ...params }); + return ipcRenderer.invoke('get-key-usage', unproxify(params)); } static updateTableCell (params) { - return ipcRenderer.invoke('update-table-cell', { ...params }); + return ipcRenderer.invoke('update-table-cell', unproxify(params)); } static deleteTableRows (params) { - return ipcRenderer.invoke('delete-table-rows', { ...params }); + return ipcRenderer.invoke('delete-table-rows', unproxify(params)); } static insertTableRows (params) { - return ipcRenderer.invoke('insert-table-rows', { ...params }); + return ipcRenderer.invoke('insert-table-rows', unproxify(params)); } static insertTableFakeRows (params) { - return ipcRenderer.invoke('insert-table-fake-rows', { ...params }); + return ipcRenderer.invoke('insert-table-fake-rows', unproxify(params)); } static getForeignList (params) { - return ipcRenderer.invoke('get-foreign-list', { ...params }); + return ipcRenderer.invoke('get-foreign-list', unproxify(params)); } static createTable (params) { - return ipcRenderer.invoke('create-table', { ...params }); + return ipcRenderer.invoke('create-table', unproxify(params)); } static alterTable (params) { - return ipcRenderer.invoke('alter-table', { ...params }); + return ipcRenderer.invoke('alter-table', unproxify(params)); } static duplicateTable (params) { - return ipcRenderer.invoke('duplicate-table', { ...params }); + return ipcRenderer.invoke('duplicate-table', unproxify(params)); } static truncateTable (params) { - return ipcRenderer.invoke('truncate-table', { ...params }); + return ipcRenderer.invoke('truncate-table', unproxify(params)); } static dropTable (params) { - return ipcRenderer.invoke('drop-table', { ...params }); + return ipcRenderer.invoke('drop-table', unproxify(params)); } } diff --git a/src/renderer/ipc-api/Triggers.js b/src/renderer/ipc-api/Triggers.js index c44c5f65..8b916393 100644 --- a/src/renderer/ipc-api/Triggers.js +++ b/src/renderer/ipc-api/Triggers.js @@ -1,24 +1,25 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getTriggerInformations (params) { - return ipcRenderer.invoke('get-trigger-informations', params); + return ipcRenderer.invoke('get-trigger-informations', unproxify(params)); } static dropTrigger (params) { - return ipcRenderer.invoke('drop-trigger', params); + return ipcRenderer.invoke('drop-trigger', unproxify(params)); } static alterTrigger (params) { - return ipcRenderer.invoke('alter-trigger', params); + return ipcRenderer.invoke('alter-trigger', unproxify(params)); } static createTrigger (params) { - return ipcRenderer.invoke('create-trigger', params); + return ipcRenderer.invoke('create-trigger', unproxify(params)); } static toggleTrigger (params) { - return ipcRenderer.invoke('toggle-trigger', params); + return ipcRenderer.invoke('toggle-trigger', unproxify(params)); } } diff --git a/src/renderer/ipc-api/Users.js b/src/renderer/ipc-api/Users.js index 3a243424..b4b14b2f 100644 --- a/src/renderer/ipc-api/Users.js +++ b/src/renderer/ipc-api/Users.js @@ -1,8 +1,9 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getUsers (params) { - return ipcRenderer.invoke('get-users', params); + return ipcRenderer.invoke('get-users', unproxify(params)); } } diff --git a/src/renderer/ipc-api/Views.js b/src/renderer/ipc-api/Views.js index db8b0e3e..6e01cd3f 100644 --- a/src/renderer/ipc-api/Views.js +++ b/src/renderer/ipc-api/Views.js @@ -1,20 +1,21 @@ 'use strict'; import { ipcRenderer } from 'electron'; +import { unproxify } from 'common/libs/unproxify'; export default class { static getViewInformations (params) { - return ipcRenderer.invoke('get-view-informations', params); + return ipcRenderer.invoke('get-view-informations', unproxify(params)); } static dropView (params) { - return ipcRenderer.invoke('drop-view', params); + return ipcRenderer.invoke('drop-view', unproxify(params)); } static alterView (params) { - return ipcRenderer.invoke('alter-view', params); + return ipcRenderer.invoke('alter-view', unproxify(params)); } static createView (params) { - return ipcRenderer.invoke('create-view', params); + return ipcRenderer.invoke('create-view', unproxify(params)); } }