From d5b9b0cb9596688b3bcad0010b65888428c297c6 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Thu, 28 Apr 2022 19:04:09 +0200 Subject: [PATCH] feat(core): Introduce simplified node versioning (#3205) * :sparkles: Introduce simple node versioning * :zap: Add example how to read version in node-code for custom logic * :bug: Fix setting of parameters * :bug: Fix another instance where it sets the wrong parameter * :zap: Remove unnecessary TOODs * :zap: Revert Set Node example changes * ;rotating_light: Add test --- packages/cli/src/CredentialsHelper.ts | 7 +- packages/core/src/NodeExecuteFunctions.ts | 1 + packages/core/test/Helpers.ts | 59 ++++++++ packages/core/test/WorkflowExecute.test.ts | 139 ++++++++++++++++++ .../src/components/CollectionParameter.vue | 6 +- .../CredentialEdit/CredentialEdit.vue | 2 + .../src/components/NodeCredentials.vue | 2 +- .../editor-ui/src/components/NodeSettings.vue | 4 +- .../src/components/ParameterInput.vue | 2 +- .../src/components/ParameterInputList.vue | 11 +- .../src/components/mixins/nodeHelpers.ts | 6 +- .../src/components/mixins/workflowHelpers.ts | 4 +- packages/editor-ui/src/store.ts | 8 +- packages/editor-ui/src/views/NodeView.vue | 13 +- packages/workflow/src/Interfaces.ts | 2 +- packages/workflow/src/NodeHelpers.ts | 28 +++- packages/workflow/src/RoutingNode.ts | 9 +- packages/workflow/src/Workflow.ts | 1 + packages/workflow/test/NodeHelpers.test.ts | 4 + 19 files changed, 277 insertions(+), 31 deletions(-) diff --git a/packages/cli/src/CredentialsHelper.ts b/packages/cli/src/CredentialsHelper.ts index c4278aaa6a..7707cd1a39 100644 --- a/packages/cli/src/CredentialsHelper.ts +++ b/packages/cli/src/CredentialsHelper.ts @@ -342,6 +342,7 @@ export class CredentialsHelper extends ICredentialsHelper { decryptedDataOriginal as INodeParameters, true, false, + null, ) as ICredentialDataDecryptedObject; if (decryptedDataOriginal.oauthTokenData !== undefined) { @@ -436,8 +437,6 @@ export class CredentialsHelper extends ICredentialsHelper { // Add special database related data newCredentialsData.updatedAt = new Date(); - // TODO: also add user automatically depending on who is logged in, if anybody is logged in - // Save the credentials in DB const findQuery = { id: credentials.id, @@ -562,7 +561,9 @@ export class CredentialsHelper extends ICredentialsHelper { parameters: {}, name: 'Temp-Node', type: nodeType.description.name, - typeVersion: nodeType.description.version, + typeVersion: Array.isArray(nodeType.description.version) + ? nodeType.description.version.slice(-1)[0] + : nodeType.description.version, position: [0, 0], }; diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 6dc23ed38e..e8038b7572 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -1298,6 +1298,7 @@ export async function getCredentials( !NodeHelpers.displayParameter( additionalData.currentNodeParameters || node.parameters, nodeCredentialDescription, + node, node.parameters, ) ) { diff --git a/packages/core/test/Helpers.ts b/packages/core/test/Helpers.ts index f40dcb4bf5..d719dd51eb 100644 --- a/packages/core/test/Helpers.ts +++ b/packages/core/test/Helpers.ts @@ -517,6 +517,65 @@ class NodeTypesClass implements INodeTypes { }, }, }, + 'n8n-nodes-base.versionTest': { + sourcePath: '', + type: { + description: { + displayName: 'Version Test', + name: 'versionTest', + group: ['input'], + version: 1, + description: 'Tests if versioning works', + defaults: { + name: 'Version Test', + color: '#0000FF', + }, + inputs: ['main'], + outputs: ['main'], + properties: [ + { + displayName: 'Display V1', + name: 'versionTest', + type: 'number', + displayOptions: { + show: { + '@version': [1], + }, + }, + default: 1, + }, + { + displayName: 'Display V2', + name: 'versionTest', + type: 'number', + displayOptions: { + show: { + '@version': [2], + }, + }, + default: 2, + }, + ], + }, + execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); + const returnData: INodeExecutionData[] = []; + + for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { + const newItem: INodeExecutionData = { + json: { + versionFromParameter: this.getNodeParameter('versionTest', itemIndex), + versionFromNode: this.getNode().typeVersion, + }, + }; + + returnData.push(newItem); + } + + return this.prepareOutputData(returnData); + }, + }, + }, 'n8n-nodes-base.set': { sourcePath: '', type: { diff --git a/packages/core/test/WorkflowExecute.test.ts b/packages/core/test/WorkflowExecute.test.ts index b1ac658dc6..f249ebe52f 100644 --- a/packages/core/test/WorkflowExecute.test.ts +++ b/packages/core/test/WorkflowExecute.test.ts @@ -1169,6 +1169,145 @@ describe('WorkflowExecute', () => { }, }, }, + + { + description: + 'should display the correct parameters and so correct data when simplified node-versioning is used', + input: { + workflowData: { + nodes: [ + { + parameters: {}, + name: 'Start', + type: 'n8n-nodes-base.start', + typeVersion: 1, + position: [240, 300], + }, + { + parameters: {}, + name: 'VersionTest1a', + type: 'n8n-nodes-base.versionTest', + typeVersion: 1, + position: [460, 300], + }, + { + parameters: { + versionTest: 11, + }, + name: 'VersionTest1b', + type: 'n8n-nodes-base.versionTest', + typeVersion: 1, + position: [680, 300], + }, + { + parameters: {}, + name: 'VersionTest2a', + type: 'n8n-nodes-base.versionTest', + typeVersion: 2, + position: [880, 300], + }, + { + parameters: { + versionTest: 22, + }, + name: 'VersionTest2b', + type: 'n8n-nodes-base.versionTest', + typeVersion: 2, + position: [1080, 300], + }, + ], + connections: { + Start: { + main: [ + [ + { + node: 'VersionTest1a', + type: 'main', + index: 0, + }, + ], + ], + }, + VersionTest1a: { + main: [ + [ + { + node: 'VersionTest1b', + type: 'main', + index: 0, + }, + ], + ], + }, + VersionTest1b: { + main: [ + [ + { + node: 'VersionTest2a', + type: 'main', + index: 0, + }, + ], + ], + }, + VersionTest2a: { + main: [ + [ + { + node: 'VersionTest2b', + type: 'main', + index: 0, + }, + ], + ], + }, + }, + }, + }, + output: { + nodeExecutionOrder: [ + 'Start', + 'VersionTest1a', + 'VersionTest1b', + 'VersionTest2a', + 'VersionTest2b', + ], + nodeData: { + VersionTest1a: [ + [ + { + versionFromNode: 1, + versionFromParameter: 1, + }, + ], + ], + VersionTest1b: [ + [ + { + versionFromNode: 1, + versionFromParameter: 11, + }, + ], + ], + VersionTest2a: [ + [ + { + versionFromNode: 2, + versionFromParameter: 2, + }, + ], + ], + VersionTest2b: [ + [ + { + versionFromNode: 2, + versionFromParameter: 22, + }, + ], + ], + }, + }, + }, ]; const fakeLogger = { diff --git a/packages/editor-ui/src/components/CollectionParameter.vue b/packages/editor-ui/src/components/CollectionParameter.vue index ae2dcbd2ba..b93e15987c 100644 --- a/packages/editor-ui/src/components/CollectionParameter.vue +++ b/packages/editor-ui/src/components/CollectionParameter.vue @@ -32,6 +32,7 @@