diff --git a/packages/cli/src/CredentialsOverwrites.ts b/packages/cli/src/CredentialsOverwrites.ts index ff719218fb..0b4f5dcbbf 100644 --- a/packages/cli/src/CredentialsOverwrites.ts +++ b/packages/cli/src/CredentialsOverwrites.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable no-underscore-dangle */ -import { ICredentialDataDecryptedObject } from 'n8n-workflow'; +import { deepCopy, ICredentialDataDecryptedObject } from 'n8n-workflow'; // eslint-disable-next-line import/no-cycle import { CredentialTypes, GenericHelpers, ICredentialsOverwrite } from '.'; @@ -19,7 +19,7 @@ class CredentialsOverwritesClass { if (overwriteData !== undefined) { // If data is already given it can directly be set instead of // loaded from environment - this.__setData(JSON.parse(JSON.stringify(overwriteData))); + this.__setData(deepCopy(overwriteData)); return; } @@ -57,14 +57,11 @@ class CredentialsOverwritesClass { return data; } - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const returnData = JSON.parse(JSON.stringify(data)); + const returnData = deepCopy(data); // Overwrite only if there is currently no data set - // eslint-disable-next-line no-restricted-syntax for (const key of Object.keys(overwrites)) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + // @ts-ignore if ([null, undefined, ''].includes(returnData[key])) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access returnData[key] = overwrites[key]; } } diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index d52a24e7e6..6c6e37499f 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -63,6 +63,7 @@ import { NodeParameterValueType, NodeExecutionWithMetadata, IPairedItemData, + deepCopy, } from 'n8n-workflow'; import { Agent } from 'https'; @@ -1641,7 +1642,7 @@ export async function getCredentials( * */ export function getNode(node: INode): INode { - return JSON.parse(JSON.stringify(node)); + return deepCopy(node); } /** diff --git a/packages/core/src/UserSettings.ts b/packages/core/src/UserSettings.ts index 1f04a923ef..d434c46934 100644 --- a/packages/core/src/UserSettings.ts +++ b/packages/core/src/UserSettings.ts @@ -16,6 +16,7 @@ import { USER_SETTINGS_FILE_NAME, USER_SETTINGS_SUBFOLDER, } from '.'; +import { deepCopy } from 'n8n-workflow'; // eslint-disable-next-line @typescript-eslint/no-var-requires const { promisify } = require('util'); @@ -173,7 +174,7 @@ export async function writeUserSettings( } await fsWriteFile(settingsPath, JSON.stringify(settingsToWrite, null, '\t')); - settingsCache = JSON.parse(JSON.stringify(userSettings)); + settingsCache = deepCopy(userSettings); return userSettings; } diff --git a/packages/editor-ui/src/components/CollectionParameter.vue b/packages/editor-ui/src/components/CollectionParameter.vue index d5c4deac0f..0130248b02 100644 --- a/packages/editor-ui/src/components/CollectionParameter.vue +++ b/packages/editor-ui/src/components/CollectionParameter.vue @@ -38,6 +38,7 @@ import { } from '@/Interface'; import { + deepCopy, INodeProperties, INodePropertyOptions, } from 'n8n-workflow'; @@ -161,7 +162,7 @@ export default mixins( } else { // Everything else saves them directly as an array. newValue = get(this.nodeValues, `${this.path}.${optionName}`, []); - newValue.push(JSON.parse(JSON.stringify(option.default))); + newValue.push(deepCopy(option.default)); } parameterData = { @@ -172,7 +173,7 @@ export default mixins( // Add a new option parameterData = { name, - value: JSON.parse(JSON.stringify(option.default)), + value: deepCopy(option.default), }; } diff --git a/packages/editor-ui/src/components/FixedCollectionParameter.vue b/packages/editor-ui/src/components/FixedCollectionParameter.vue index 8a41462e26..63eca4c079 100644 --- a/packages/editor-ui/src/components/FixedCollectionParameter.vue +++ b/packages/editor-ui/src/components/FixedCollectionParameter.vue @@ -113,8 +113,10 @@ import { } from '@/Interface'; import { + deepCopy, INodeParameters, INodePropertyCollection, + NodeParameterValue, } from 'n8n-workflow'; import { get } from 'lodash'; @@ -249,13 +251,13 @@ export default mixins(genericHelpers) // Multiple values are allowed so append option to array newParameterValue[optionParameter.name] = get(this.nodeValues, `${this.path}.${optionParameter.name}`, []); if (Array.isArray(optionParameter.default)) { - (newParameterValue[optionParameter.name] as INodeParameters[]).push(...JSON.parse(JSON.stringify(optionParameter.default))); + (newParameterValue[optionParameter.name] as INodeParameters[]).push(...deepCopy(optionParameter.default as INodeParameters[])); } else if (optionParameter.default !== '' && typeof optionParameter.default !== 'object') { - (newParameterValue[optionParameter.name] as INodeParameters[]).push(JSON.parse(JSON.stringify(optionParameter.default))); + (newParameterValue[optionParameter.name] as NodeParameterValue[]).push(deepCopy(optionParameter.default)); } } else { // Add a new option - newParameterValue[optionParameter.name] = JSON.parse(JSON.stringify(optionParameter.default)); + newParameterValue[optionParameter.name] = deepCopy(optionParameter.default); } } diff --git a/packages/editor-ui/src/components/MultipleParameter.vue b/packages/editor-ui/src/components/MultipleParameter.vue index e4b3afc466..2b31969c9b 100644 --- a/packages/editor-ui/src/components/MultipleParameter.vue +++ b/packages/editor-ui/src/components/MultipleParameter.vue @@ -46,6 +46,7 @@ import { get } from 'lodash'; import { genericHelpers } from '@/components/mixins/genericHelpers'; import mixins from 'vue-typed-mixins'; +import { deepCopy } from "n8n-workflow"; export default mixins(genericHelpers) .extend({ @@ -87,7 +88,7 @@ export default mixins(genericHelpers) currentValue = []; } - currentValue.push(JSON.parse(JSON.stringify(this.parameter.default))); + currentValue.push(deepCopy(this.parameter.default)); const parameterData = { name, diff --git a/packages/editor-ui/src/components/NodeSettings.vue b/packages/editor-ui/src/components/NodeSettings.vue index 5d54994f71..ab115c80ec 100644 --- a/packages/editor-ui/src/components/NodeSettings.vue +++ b/packages/editor-ui/src/components/NodeSettings.vue @@ -122,6 +122,7 @@ import { INodeProperties, NodeHelpers, NodeParameterValue, + deepCopy, } from 'n8n-workflow'; import { INodeUi, INodeUpdatePropertiesInformation, IUpdateInformation } from '@/Interface'; @@ -427,7 +428,7 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers).extend({ // Value should be set if (typeof value === 'object') { // @ts-ignore - Vue.set(get(this.nodeValues, nameParts.join('.')), lastNamePart, JSON.parse(JSON.stringify(value))); + Vue.set(get(this.nodeValues, nameParts.join('.')), lastNamePart, deepCopy(value)); } else { // @ts-ignore Vue.set(get(this.nodeValues, nameParts.join('.')), lastNamePart, value); @@ -500,7 +501,7 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers).extend({ // Copy the data because it is the data of vuex so make sure that // we do not edit it directly - nodeParameters = JSON.parse(JSON.stringify(nodeParameters)); + nodeParameters = deepCopy(nodeParameters); for (const parameterName of Object.keys(parameterData.value)) { //@ts-ignore @@ -591,7 +592,7 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers).extend({ // Copy the data because it is the data of vuex so make sure that // we do not edit it directly - nodeParameters = JSON.parse(JSON.stringify(nodeParameters)); + nodeParameters = deepCopy(nodeParameters); // Remove the 'parameters.' from the beginning to just have the // actual parameter name @@ -734,7 +735,7 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers).extend({ } } - Vue.set(this.nodeValues, 'parameters', JSON.parse(JSON.stringify(this.node.parameters))); + Vue.set(this.nodeValues, 'parameters', deepCopy(this.node.parameters)); } else { this.nodeValid = false; } diff --git a/packages/editor-ui/src/components/ParameterInputList.vue b/packages/editor-ui/src/components/ParameterInputList.vue index 324ccd8669..e13fbbdc2d 100644 --- a/packages/editor-ui/src/components/ParameterInputList.vue +++ b/packages/editor-ui/src/components/ParameterInputList.vue @@ -97,6 +97,7 @@