refactor: toRaw to handle Proxy objects on ipc

This commit is contained in:
Fabio Di Stasio 2022-04-22 23:33:12 +02:00
parent c50cbc577f
commit 434b9f8284
11 changed files with 69 additions and 83 deletions

View File

@ -1,14 +0,0 @@
/**
* @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 };
}

View File

@ -1,14 +1,14 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getKey (params) { static getKey (params) {
return ipcRenderer.sendSync('get-key', unproxify(params)); return ipcRenderer.sendSync('get-key', toRaw(params));
} }
static showOpenDialog (options) { static showOpenDialog (options) {
return ipcRenderer.invoke('show-open-dialog', unproxify(options)); return ipcRenderer.invoke('show-open-dialog', toRaw(options));
} }
static getDownloadPathDirectory () { static getDownloadPathDirectory () {

View File

@ -1,17 +1,17 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
import connStringConstruct from '../libs/connStringDecode'; import connStringConstruct from '../libs/connStringDecode';
export default class { export default class {
static makeTest (params) { static makeTest (params) {
params = connStringConstruct(params); params = connStringConstruct(params);
return ipcRenderer.invoke('test-connection', unproxify(params)); return ipcRenderer.invoke('test-connection', toRaw(params));
} }
static connect (params) { static connect (params) {
params = connStringConstruct(params); params = connStringConstruct(params);
return ipcRenderer.invoke('connect', unproxify(params)); return ipcRenderer.invoke('connect', toRaw(params));
} }
static checkConnection (uid) { static checkConnection (uid) {

View File

@ -1,29 +1,29 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getFunctionInformations (params) { static getFunctionInformations (params) {
return ipcRenderer.invoke('get-function-informations', unproxify(params)); return ipcRenderer.invoke('get-function-informations', toRaw(params));
} }
static dropFunction (params) { static dropFunction (params) {
return ipcRenderer.invoke('drop-function', unproxify(params)); return ipcRenderer.invoke('drop-function', toRaw(params));
} }
static alterFunction (params) { static alterFunction (params) {
return ipcRenderer.invoke('alter-function', unproxify(params)); return ipcRenderer.invoke('alter-function', toRaw(params));
} }
static alterTriggerFunction (params) { static alterTriggerFunction (params) {
return ipcRenderer.invoke('alter-trigger-function', unproxify(params)); return ipcRenderer.invoke('alter-trigger-function', toRaw(params));
} }
static createFunction (params) { static createFunction (params) {
return ipcRenderer.invoke('create-function', unproxify(params)); return ipcRenderer.invoke('create-function', toRaw(params));
} }
static createTriggerFunction (params) { static createTriggerFunction (params) {
return ipcRenderer.invoke('create-trigger-function', unproxify(params)); return ipcRenderer.invoke('create-trigger-function', toRaw(params));
} }
} }

View File

@ -1,21 +1,21 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getRoutineInformations (params) { static getRoutineInformations (params) {
return ipcRenderer.invoke('get-routine-informations', unproxify(params)); return ipcRenderer.invoke('get-routine-informations', toRaw(params));
} }
static dropRoutine (params) { static dropRoutine (params) {
return ipcRenderer.invoke('drop-routine', unproxify(params)); return ipcRenderer.invoke('drop-routine', toRaw(params));
} }
static alterRoutine (params) { static alterRoutine (params) {
return ipcRenderer.invoke('alter-routine', unproxify(params)); return ipcRenderer.invoke('alter-routine', toRaw(params));
} }
static createRoutine (params) { static createRoutine (params) {
return ipcRenderer.invoke('create-routine', unproxify(params)); return ipcRenderer.invoke('create-routine', toRaw(params));
} }
} }

View File

@ -1,25 +1,25 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getSchedulerInformations (params) { static getSchedulerInformations (params) {
return ipcRenderer.invoke('get-scheduler-informations', unproxify(params)); return ipcRenderer.invoke('get-scheduler-informations', toRaw(params));
} }
static dropScheduler (params) { static dropScheduler (params) {
return ipcRenderer.invoke('drop-scheduler', unproxify(params)); return ipcRenderer.invoke('drop-scheduler', toRaw(params));
} }
static alterScheduler (params) { static alterScheduler (params) {
return ipcRenderer.invoke('alter-scheduler', unproxify(params)); return ipcRenderer.invoke('alter-scheduler', toRaw(params));
} }
static createScheduler (params) { static createScheduler (params) {
return ipcRenderer.invoke('create-scheduler', unproxify(params)); return ipcRenderer.invoke('create-scheduler', toRaw(params));
} }
static toggleScheduler (params) { static toggleScheduler (params) {
return ipcRenderer.invoke('toggle-scheduler', unproxify(params)); return ipcRenderer.invoke('toggle-scheduler', toRaw(params));
} }
} }

View File

@ -1,26 +1,26 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static createSchema (params) { static createSchema (params) {
return ipcRenderer.invoke('create-schema', unproxify(params)); return ipcRenderer.invoke('create-schema', toRaw(params));
} }
static updateSchema (params) { static updateSchema (params) {
return ipcRenderer.invoke('update-schema', unproxify(params)); return ipcRenderer.invoke('update-schema', toRaw(params));
} }
static getDatabaseCollation (params) { static getDatabaseCollation (params) {
return ipcRenderer.invoke('get-schema-collation', unproxify(params)); return ipcRenderer.invoke('get-schema-collation', toRaw(params));
} }
static deleteSchema (params) { static deleteSchema (params) {
return ipcRenderer.invoke('delete-schema', unproxify(params)); return ipcRenderer.invoke('delete-schema', toRaw(params));
} }
static getStructure (params) { static getStructure (params) {
return ipcRenderer.invoke('get-structure', unproxify(params, false)); return ipcRenderer.invoke('get-structure', toRaw(params));
} }
static getCollations (uid) { static getCollations (uid) {
@ -44,35 +44,35 @@ export default class {
} }
static killProcess (params) { static killProcess (params) {
return ipcRenderer.invoke('kill-process', unproxify(params)); return ipcRenderer.invoke('kill-process', toRaw(params));
} }
static killTabQuery (params) { static killTabQuery (params) {
return ipcRenderer.invoke('kill-tab-query', unproxify(params)); return ipcRenderer.invoke('kill-tab-query', toRaw(params));
} }
static commitTab (params) { static commitTab (params) {
return ipcRenderer.invoke('commit-tab', unproxify(params)); return ipcRenderer.invoke('commit-tab', toRaw(params));
} }
static rollbackTab (params) { static rollbackTab (params) {
return ipcRenderer.invoke('rollback-tab', unproxify(params)); return ipcRenderer.invoke('rollback-tab', toRaw(params));
} }
static destroyConnectionToCommit (params) { static destroyConnectionToCommit (params) {
return ipcRenderer.invoke('destroy-connection-to-commit', unproxify(params)); return ipcRenderer.invoke('destroy-connection-to-commit', toRaw(params));
} }
static useSchema (params) { static useSchema (params) {
return ipcRenderer.invoke('use-schema', unproxify(params)); return ipcRenderer.invoke('use-schema', toRaw(params));
} }
static rawQuery (params) { static rawQuery (params) {
return ipcRenderer.invoke('raw-query', unproxify(params)); return ipcRenderer.invoke('raw-query', toRaw(params));
} }
static export (params) { static export (params) {
return ipcRenderer.invoke('export', unproxify(params)); return ipcRenderer.invoke('export', toRaw(params));
} }
static abortExport () { static abortExport () {
@ -80,7 +80,7 @@ export default class {
} }
static import (params) { static import (params) {
return ipcRenderer.invoke('import-sql', unproxify(params)); return ipcRenderer.invoke('import-sql', toRaw(params));
} }
static abortImport () { static abortImport () {

View File

@ -1,69 +1,69 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getTableColumns (params) { static getTableColumns (params) {
return ipcRenderer.invoke('get-table-columns', unproxify(params)); return ipcRenderer.invoke('get-table-columns', toRaw(params));
} }
static getTableData (params) { static getTableData (params) {
return ipcRenderer.invoke('get-table-data', unproxify(params)); return ipcRenderer.invoke('get-table-data', toRaw(params));
} }
static getTableApproximateCount (params) { static getTableApproximateCount (params) {
return ipcRenderer.invoke('get-table-count', unproxify(params)); return ipcRenderer.invoke('get-table-count', toRaw(params));
} }
static getTableOptions (params) { static getTableOptions (params) {
return ipcRenderer.invoke('get-table-options', unproxify(params)); return ipcRenderer.invoke('get-table-options', toRaw(params));
} }
static getTableIndexes (params) { static getTableIndexes (params) {
return ipcRenderer.invoke('get-table-indexes', unproxify(params)); return ipcRenderer.invoke('get-table-indexes', toRaw(params));
} }
static getKeyUsage (params) { static getKeyUsage (params) {
return ipcRenderer.invoke('get-key-usage', unproxify(params)); return ipcRenderer.invoke('get-key-usage', toRaw(params));
} }
static updateTableCell (params) { static updateTableCell (params) {
return ipcRenderer.invoke('update-table-cell', unproxify(params)); return ipcRenderer.invoke('update-table-cell', toRaw(params));
} }
static deleteTableRows (params) { static deleteTableRows (params) {
return ipcRenderer.invoke('delete-table-rows', unproxify(params)); return ipcRenderer.invoke('delete-table-rows', toRaw(params));
} }
static insertTableRows (params) { static insertTableRows (params) {
return ipcRenderer.invoke('insert-table-rows', unproxify(params)); return ipcRenderer.invoke('insert-table-rows', toRaw(params));
} }
static insertTableFakeRows (params) { static insertTableFakeRows (params) {
return ipcRenderer.invoke('insert-table-fake-rows', unproxify(params)); return ipcRenderer.invoke('insert-table-fake-rows', toRaw(params));
} }
static getForeignList (params) { static getForeignList (params) {
return ipcRenderer.invoke('get-foreign-list', unproxify(params)); return ipcRenderer.invoke('get-foreign-list', toRaw(params));
} }
static createTable (params) { static createTable (params) {
return ipcRenderer.invoke('create-table', unproxify(params)); return ipcRenderer.invoke('create-table', toRaw(params));
} }
static alterTable (params) { static alterTable (params) {
return ipcRenderer.invoke('alter-table', unproxify(params)); return ipcRenderer.invoke('alter-table', toRaw(params));
} }
static duplicateTable (params) { static duplicateTable (params) {
return ipcRenderer.invoke('duplicate-table', unproxify(params)); return ipcRenderer.invoke('duplicate-table', toRaw(params));
} }
static truncateTable (params) { static truncateTable (params) {
return ipcRenderer.invoke('truncate-table', unproxify(params)); return ipcRenderer.invoke('truncate-table', toRaw(params));
} }
static dropTable (params) { static dropTable (params) {
return ipcRenderer.invoke('drop-table', unproxify(params)); return ipcRenderer.invoke('drop-table', toRaw(params));
} }
} }

View File

@ -1,25 +1,25 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getTriggerInformations (params) { static getTriggerInformations (params) {
return ipcRenderer.invoke('get-trigger-informations', unproxify(params)); return ipcRenderer.invoke('get-trigger-informations', toRaw(params));
} }
static dropTrigger (params) { static dropTrigger (params) {
return ipcRenderer.invoke('drop-trigger', unproxify(params)); return ipcRenderer.invoke('drop-trigger', toRaw(params));
} }
static alterTrigger (params) { static alterTrigger (params) {
return ipcRenderer.invoke('alter-trigger', unproxify(params)); return ipcRenderer.invoke('alter-trigger', toRaw(params));
} }
static createTrigger (params) { static createTrigger (params) {
return ipcRenderer.invoke('create-trigger', unproxify(params)); return ipcRenderer.invoke('create-trigger', toRaw(params));
} }
static toggleTrigger (params) { static toggleTrigger (params) {
return ipcRenderer.invoke('toggle-trigger', unproxify(params)); return ipcRenderer.invoke('toggle-trigger', toRaw(params));
} }
} }

View File

@ -1,9 +1,9 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getUsers (params) { static getUsers (params) {
return ipcRenderer.invoke('get-users', unproxify(params)); return ipcRenderer.invoke('get-users', toRaw(params));
} }
} }

View File

@ -1,21 +1,21 @@
'use strict'; 'use strict';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { unproxify } from 'common/libs/unproxify'; import { toRaw } from 'vue';
export default class { export default class {
static getViewInformations (params) { static getViewInformations (params) {
return ipcRenderer.invoke('get-view-informations', unproxify(params)); return ipcRenderer.invoke('get-view-informations', toRaw(params));
} }
static dropView (params) { static dropView (params) {
return ipcRenderer.invoke('drop-view', unproxify(params)); return ipcRenderer.invoke('drop-view', toRaw(params));
} }
static alterView (params) { static alterView (params) {
return ipcRenderer.invoke('alter-view', unproxify(params)); return ipcRenderer.invoke('alter-view', toRaw(params));
} }
static createView (params) { static createView (params) {
return ipcRenderer.invoke('create-view', unproxify(params)); return ipcRenderer.invoke('create-view', toRaw(params));
} }
} }