mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat: Run once for each item tooltip (#9486)
Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { NodeParameterValue } from './Interfaces';
|
||||
|
||||
export const BINARY_ENCODING = 'base64';
|
||||
export const WAIT_TIME_UNLIMITED = '3000-01-01T00:00:00.000Z';
|
||||
|
||||
@@ -62,3 +64,32 @@ export const LANGCHAIN_CUSTOM_TOOLS = [
|
||||
CODE_TOOL_LANGCHAIN_NODE_TYPE,
|
||||
WORKFLOW_TOOL_LANGCHAIN_NODE_TYPE,
|
||||
];
|
||||
|
||||
//nodes that would execute only once with such parameters
|
||||
//add 'undefined' to parameters values if it is parameter's default value
|
||||
export const SINGLE_EXECUTION_NODES: { [key: string]: { [key: string]: NodeParameterValue[] } } = {
|
||||
'n8n-nodes-base.code': {
|
||||
mode: [undefined, 'runOnceForAllItems'],
|
||||
},
|
||||
'n8n-nodes-base.executeWorkflow': {
|
||||
mode: [undefined, 'once'],
|
||||
},
|
||||
'n8n-nodes-base.crateDb': {
|
||||
operation: [undefined, 'update'], // default insert
|
||||
},
|
||||
'n8n-nodes-base.timescaleDb': {
|
||||
operation: [undefined, 'update'], // default insert
|
||||
},
|
||||
'n8n-nodes-base.microsoftSql': {
|
||||
operation: [undefined, 'update', 'delete'], // default insert
|
||||
},
|
||||
'n8n-nodes-base.questDb': {
|
||||
operation: [undefined], // default insert
|
||||
},
|
||||
'n8n-nodes-base.mongoDb': {
|
||||
operation: ['insert', 'update'],
|
||||
},
|
||||
'n8n-nodes-base.redis': {
|
||||
operation: [undefined], // default info
|
||||
},
|
||||
};
|
||||
|
||||
@@ -56,6 +56,7 @@ import type { Workflow } from './Workflow';
|
||||
import { validateFilterParameter } from './NodeParameters/FilterParameter';
|
||||
import { validateFieldType } from './TypeValidation';
|
||||
import { ApplicationError } from './errors/application.error';
|
||||
import { SINGLE_EXECUTION_NODES } from './Constants';
|
||||
|
||||
export const cronNodeOptions: INodePropertyCollection[] = [
|
||||
{
|
||||
@@ -1748,3 +1749,19 @@ export function getCredentialsForNode(
|
||||
|
||||
return object.description.credentials ?? [];
|
||||
}
|
||||
|
||||
export function isSingleExecution(type: string, parameters: INodeParameters): boolean {
|
||||
const singleExecutionCase = SINGLE_EXECUTION_NODES[type];
|
||||
|
||||
if (singleExecutionCase) {
|
||||
for (const parameter of Object.keys(singleExecutionCase)) {
|
||||
if (!singleExecutionCase[parameter].includes(parameters[parameter] as NodeParameterValue)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { INode, INodeParameters, INodeProperties, INodeTypeDescription } from '@/Interfaces';
|
||||
import type { Workflow } from '../src';
|
||||
|
||||
import { getNodeParameters, getNodeHints } from '@/NodeHelpers';
|
||||
import { getNodeParameters, getNodeHints, isSingleExecution } from '@/NodeHelpers';
|
||||
|
||||
describe('NodeHelpers', () => {
|
||||
describe('getNodeParameters', () => {
|
||||
@@ -3528,4 +3528,31 @@ describe('NodeHelpers', () => {
|
||||
expect(hints).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
describe('isSingleExecution', () => {
|
||||
test('should determine based on node parameters if it would be executed once', () => {
|
||||
expect(isSingleExecution('n8n-nodes-base.code', {})).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.code', { mode: 'runOnceForEachItem' })).toEqual(
|
||||
false,
|
||||
);
|
||||
expect(isSingleExecution('n8n-nodes-base.executeWorkflow', {})).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.executeWorkflow', { mode: 'each' })).toEqual(false);
|
||||
expect(isSingleExecution('n8n-nodes-base.crateDb', {})).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.crateDb', { operation: 'update' })).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.timescaleDb', {})).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.timescaleDb', { operation: 'update' })).toEqual(
|
||||
true,
|
||||
);
|
||||
expect(isSingleExecution('n8n-nodes-base.microsoftSql', {})).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.microsoftSql', { operation: 'update' })).toEqual(
|
||||
true,
|
||||
);
|
||||
expect(isSingleExecution('n8n-nodes-base.microsoftSql', { operation: 'delete' })).toEqual(
|
||||
true,
|
||||
);
|
||||
expect(isSingleExecution('n8n-nodes-base.questDb', {})).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.mongoDb', { operation: 'insert' })).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.mongoDb', { operation: 'update' })).toEqual(true);
|
||||
expect(isSingleExecution('n8n-nodes-base.redis', {})).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user