Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use NodeConnectionType consistently across the code base (no-changelog) #10595

Merged
merged 12 commits into from
Aug 29, 2024
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import type {
ConnectionTypes,
INodeInputConfiguration,
INodeInputFilter,
IExecuteFunctions,
Expand Down Expand Up @@ -28,16 +27,16 @@ import { toolsAgentExecute } from './agents/ToolsAgent/execute';
function getInputs(
agent: 'toolsAgent' | 'conversationalAgent' | 'openAiFunctionsAgent' | 'reActAgent' | 'sqlAgent',
hasOutputParser?: boolean,
): Array<ConnectionTypes | INodeInputConfiguration> {
): Array<NodeConnectionType | INodeInputConfiguration> {
interface SpecialInput {
type: ConnectionTypes;
type: NodeConnectionType;
filter?: INodeInputFilter;
required?: boolean;
}

const getInputData = (
inputs: SpecialInput[],
): Array<ConnectionTypes | INodeInputConfiguration> => {
): Array<NodeConnectionType | INodeInputConfiguration> => {
const displayNames: { [key: string]: string } = {
[NodeConnectionType.AiLanguageModel]: 'Model',
[NodeConnectionType.AiMemory]: 'Memory',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ChatTrigger extends Node {
}
];
})() }}`,
outputs: ['main'],
outputs: [NodeConnectionType.Main],
credentials: [
{
// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const versionDescription: INodeTypeDescription = {
},
},
inputs: `={{(${configureNodeInputs})($parameter.resource, $parameter.operation, $parameter.hideTools)}}`,
outputs: ['main'],
outputs: [NodeConnectionType.Main],
credentials: [
{
name: 'openAiApi',
Expand Down
8 changes: 4 additions & 4 deletions packages/@n8n/nodes-langchain/utils/logWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NodeOperationError, NodeConnectionType } from 'n8n-workflow';
import type { ConnectionTypes, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';

import type { Tool } from '@langchain/core/tools';
import type { BaseMessage } from '@langchain/core/messages';
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function callMethodAsync<T>(
this: T,
parameters: {
executeFunctions: IExecuteFunctions;
connectionType: ConnectionTypes;
connectionType: NodeConnectionType;
currentNodeRunIndex: number;
method: (...args: any[]) => Promise<unknown>;
arguments: unknown[];
Expand Down Expand Up @@ -78,7 +78,7 @@ export function callMethodSync<T>(
this: T,
parameters: {
executeFunctions: IExecuteFunctions;
connectionType: ConnectionTypes;
connectionType: NodeConnectionType;
currentNodeRunIndex: number;
method: (...args: any[]) => T;
arguments: unknown[];
Expand Down Expand Up @@ -123,7 +123,7 @@ export function logWrapper(
) {
return new Proxy(originalInstance, {
get: (target, prop) => {
let connectionType: ConnectionTypes | undefined;
let connectionType: NodeConnectionType | undefined;
// ========== BaseChatMemory ==========
if (isBaseChatMemory(originalInstance)) {
if (prop === 'loadMemoryVariables' && 'loadMemoryVariables' in target) {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/credentials-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
INode,
INodeProperties,
} from 'n8n-workflow';
import { deepCopy } from 'n8n-workflow';
import { NodeConnectionType, deepCopy } from 'n8n-workflow';
import { Workflow } from 'n8n-workflow';
import { CredentialsHelper } from '@/credentials-helper';
import { NodeTypes } from '@/node-types';
Expand All @@ -34,8 +34,8 @@ describe('CredentialsHelper', () => {
name: 'Set',
color: '#0000FF',
},
inputs: ['main'],
outputs: ['main'],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
properties: [
{
displayName: 'Value1',
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/test/integration/webhooks.api.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { readFileSync } from 'fs';
import { agent as testAgent } from 'supertest';
import type { INodeType, INodeTypeDescription, IWebhookFunctions } from 'n8n-workflow';
import {
NodeConnectionType,
type INodeType,
type INodeTypeDescription,
type IWebhookFunctions,
} from 'n8n-workflow';

import { AbstractServer } from '@/abstract-server';
import { ExternalHooks } from '@/external-hooks';
Expand Down Expand Up @@ -182,7 +187,7 @@ describe('Webhook API', () => {
description: '',
defaults: {},
inputs: [],
outputs: ['main'],
outputs: [NodeConnectionType.Main],
webhooks: [
{
name: 'default',
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { extension, lookup } from 'mime-types';
import type {
BinaryHelperFunctions,
CloseFunction,
ConnectionTypes,
ContextType,
EventNamesAiNodesType,
FieldType,
Expand Down Expand Up @@ -105,6 +104,7 @@ import type {
SchedulingFunctions,
} from 'n8n-workflow';
import {
NodeConnectionType,
ExpressionError,
LoggerProxy as Logger,
NodeApiError,
Expand Down Expand Up @@ -2623,13 +2623,13 @@ const addExecutionDataFunctions = async (
nodeName: string,
data: INodeExecutionData[][] | ExecutionBaseError,
runExecutionData: IRunExecutionData,
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
additionalData: IWorkflowExecuteAdditionalData,
sourceNodeName: string,
sourceNodeRunIndex: number,
currentNodeRunIndex: number,
): Promise<void> => {
if (connectionType === 'main') {
if (connectionType === NodeConnectionType.Main) {
throw new ApplicationError('Setting type is not supported for main connection', {
extra: { type },
});
Expand Down Expand Up @@ -2732,7 +2732,7 @@ async function getInputConnectionData(
executeData: IExecuteData | undefined,
mode: WorkflowExecuteMode,
closeFunctions: CloseFunction[],
inputName: ConnectionTypes,
inputName: NodeConnectionType,
itemIndex: number,
): Promise<unknown> {
const node = this.getNode();
Expand Down Expand Up @@ -3676,7 +3676,7 @@ export function getExecuteFunctions(
},

async getInputConnectionData(
inputName: ConnectionTypes,
inputName: NodeConnectionType,
itemIndex: number,
): Promise<unknown> {
return await getInputConnectionData.call(
Expand Down Expand Up @@ -3817,7 +3817,7 @@ export function getExecuteFunctions(
},

addInputData(
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
data: INodeExecutionData[][] | ExecutionBaseError,
): { index: number } {
const nodeName = this.getNode().name;
Expand Down Expand Up @@ -3847,7 +3847,7 @@ export function getExecuteFunctions(
return { index: currentNodeRunIndex };
},
addOutputData(
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
currentNodeRunIndex: number,
data: INodeExecutionData[][] | ExecutionBaseError,
): void {
Expand Down Expand Up @@ -4238,7 +4238,7 @@ export function getExecuteWebhookFunctions(
return additionalData.httpRequest.headers;
},
async getInputConnectionData(
inputName: ConnectionTypes,
inputName: NodeConnectionType,
itemIndex: number,
): Promise<unknown> {
// To be able to use expressions like "$json.sessionId" set the
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/WorkflowExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,11 @@ export class WorkflowExecute {

// Check if any of the parent nodes does not have any inputs. That
// would mean that it has to get added to the list of nodes to process.
const parentNodes = workflow.getParentNodes(inputData.node, 'main', -1);
const parentNodes = workflow.getParentNodes(
inputData.node,
NodeConnectionType.Main,
-1,
);
let nodeToAdd: string | undefined = inputData.node;
parentNodes.push(inputData.node);
parentNodes.reverse();
Expand Down Expand Up @@ -988,7 +992,11 @@ export class WorkflowExecute {
connectionIndex++
) {
if (
workflow.getHighestNode(executionNode.name, 'main', connectionIndex).length === 0
workflow.getHighestNode(
executionNode.name,
NodeConnectionType.Main,
connectionIndex,
).length === 0
) {
// If there is no valid incoming node (if all are disabled)
// then ignore that it has inputs and simply execute it as it is without
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const predefinedNodesTypes: INodeTypeData = {
name: 'Version Test',
color: '#0000FF',
},
inputs: ['main'],
outputs: ['main'],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
properties: [
{
displayName: 'Display V1',
Expand Down
6 changes: 3 additions & 3 deletions packages/editor-ui/src/__tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
INodeTypeDescription,
INodeIssues,
} from 'n8n-workflow';
import { NodeHelpers, Workflow } from 'n8n-workflow';
import { NodeConnectionType, NodeHelpers, Workflow } from 'n8n-workflow';
import { uuid } from '@jsplumb/util';
import { mock } from 'vitest-mock-extended';

Expand Down Expand Up @@ -52,8 +52,8 @@ export const mockNodeTypeDescription = ({
name,
version = 1,
credentials = [],
inputs = ['main'],
outputs = ['main'],
inputs = [NodeConnectionType.Main],
outputs = [NodeConnectionType.Main],
}: {
name: INodeTypeDescription['name'];
version?: INodeTypeDescription['version'];
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/components/ExpressionEditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createExpressionTelemetryPayload } from '@/utils/telemetryUtils';
import { useTelemetry } from '@/composables/useTelemetry';
import type { Segment } from '@/types/expressions';
import type { INodeProperties } from 'n8n-workflow';
import { NodeConnectionType } from 'n8n-workflow';
import { outputTheme } from './ExpressionEditorModal/theme';
import ExpressionOutput from './InlineExpressionEditor/ExpressionOutput.vue';
import RunDataSchema from './RunDataSchema.vue';
Expand Down Expand Up @@ -152,7 +153,7 @@ async function onDrop(expression: string, event: MouseEvent) {
:nodes="parentNodes"
mapping-enabled
pane-type="input"
connection-type="main"
:connection-type="NodeConnectionType.Main"
/>
</div>

Expand Down
11 changes: 5 additions & 6 deletions packages/editor-ui/src/components/InputPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import type {
ConnectionTypes,
IConnectedNode,
INodeInputConfiguration,
INodeOutputConfiguration,
Expand Down Expand Up @@ -121,10 +120,10 @@ export default defineComponent({
} else {
// If we can not figure out the node type we set no outputs
if (!Array.isArray(inputs)) {
inputs = [] as ConnectionTypes[];
inputs = [] as NodeConnectionType[];
}
if (!Array.isArray(outputs)) {
outputs = [] as ConnectionTypes[];
outputs = [] as NodeConnectionType[];
}
}

Expand Down Expand Up @@ -184,7 +183,7 @@ export default defineComponent({
},
rootNodesParents() {
const workflow = this.workflow;
const parentNodes = [...workflow.getParentNodes(this.rootNode, 'main')]
const parentNodes = [...workflow.getParentNodes(this.rootNode, NodeConnectionType.Main)]
.reverse()
.map((parent): IConnectedNode => ({ name: parent, depth: 1, indicies: [] }));

Expand Down Expand Up @@ -274,8 +273,8 @@ export default defineComponent({
},
methods: {
filterOutConnectionType(
item: ConnectionTypes | INodeOutputConfiguration | INodeInputConfiguration,
type: ConnectionTypes,
item: NodeConnectionType | INodeOutputConfiguration | INodeInputConfiguration,
type: NodeConnectionType,
) {
if (!item) return false;

Expand Down
10 changes: 7 additions & 3 deletions packages/editor-ui/src/components/NDVFloatingNodes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { computed, onMounted, onBeforeUnmount } from 'vue';
import NodeIcon from '@/components/NodeIcon.vue';
import type { INodeTypeDescription } from 'n8n-workflow';
import { NodeConnectionType, type INodeTypeDescription } from 'n8n-workflow';

interface Props {
rootNode: INodeUi;
Expand Down Expand Up @@ -71,8 +71,12 @@ const connectedNodes = computed<
[FloatingNodePosition.top]: getINodesFromNames(
workflow.getChildNodes(rootName, 'ALL_NON_MAIN'),
),
[FloatingNodePosition.right]: getINodesFromNames(workflow.getChildNodes(rootName, 'main', 1)),
[FloatingNodePosition.left]: getINodesFromNames(workflow.getParentNodes(rootName, 'main', 1)),
[FloatingNodePosition.right]: getINodesFromNames(
workflow.getChildNodes(rootName, NodeConnectionType.Main, 1),
),
[FloatingNodePosition.left]: getINodesFromNames(
workflow.getParentNodes(rootName, NodeConnectionType.Main, 1),
),
};
});

Expand Down
Loading
Loading