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

This commit is contained in:
Ricardo Espinoza
2024-08-29 09:55:53 -04:00
committed by GitHub
parent 1491cbd228
commit c4eb3746d7
521 changed files with 2259 additions and 1999 deletions

View File

@@ -910,7 +910,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
parentCallbackManager?: CallbackManager,
): Promise<any>;
getInputConnectionData(
inputName: ConnectionTypes,
inputName: NodeConnectionType,
itemIndex: number,
inputIndex?: number,
): Promise<unknown>;
@@ -923,12 +923,12 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
// TODO: Make this one then only available in the new config one
addInputData(
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
data: INodeExecutionData[][] | ExecutionError,
runIndex?: number,
): { index: number };
addOutputData(
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
currentNodeRunIndex: number,
data: INodeExecutionData[][] | ExecutionError,
): void;
@@ -1049,7 +1049,7 @@ export interface IWebhookFunctions extends FunctionsBaseWithRequiredKeys<'getMod
getBodyData(): IDataObject;
getHeaderData(): IncomingHttpHeaders;
getInputConnectionData(
inputName: ConnectionTypes,
inputName: NodeConnectionType,
itemIndex: number,
inputIndex?: number,
): Promise<unknown>;
@@ -1758,21 +1758,6 @@ export interface IPostReceiveSort extends IPostReceiveBase {
};
}
export type ConnectionTypes =
| 'ai_agent'
| 'ai_chain'
| 'ai_document'
| 'ai_embedding'
| 'ai_languageModel'
| 'ai_memory'
| 'ai_outputParser'
| 'ai_retriever'
| 'ai_textSplitter'
| 'ai_tool'
| 'ai_vectorRetriever'
| 'ai_vectorStore'
| 'main';
export const enum NodeConnectionType {
AiAgent = 'ai_agent',
@@ -1825,7 +1810,7 @@ export interface INodeInputConfiguration {
category?: string;
displayName?: string;
required?: boolean;
type: ConnectionTypes;
type: NodeConnectionType;
filter?: INodeInputFilter;
maxConnections?: number;
}
@@ -1835,7 +1820,7 @@ export interface INodeOutputConfiguration {
displayName?: string;
maxConnections?: number;
required?: boolean;
type: ConnectionTypes;
type: NodeConnectionType;
}
export type ExpressionString = `={{${string}}}`;
@@ -1853,10 +1838,10 @@ export interface INodeTypeDescription extends INodeTypeBaseDescription {
defaults: NodeDefaults;
eventTriggerDescription?: string;
activationMessage?: string;
inputs: Array<ConnectionTypes | INodeInputConfiguration> | ExpressionString;
inputs: Array<NodeConnectionType | INodeInputConfiguration> | ExpressionString;
requiredInputs?: string | number[] | number; // Ony available with executionOrder => "v1"
inputNames?: string[];
outputs: Array<ConnectionTypes | INodeOutputConfiguration> | ExpressionString;
outputs: Array<NodeConnectionType | INodeOutputConfiguration> | ExpressionString;
outputNames?: string[];
properties: INodeProperties[];
credentials?: INodeCredentialDescription[];

View File

@@ -35,7 +35,6 @@ import type {
IWorkflowExecuteAdditionalData,
NodeParameterValue,
ResourceMapperValue,
ConnectionTypes,
INodeTypeDescription,
INodeOutputConfiguration,
INodeInputConfiguration,
@@ -1245,8 +1244,8 @@ export function getNodeWebhookUrl(
}
export function getConnectionTypes(
connections: Array<ConnectionTypes | INodeInputConfiguration | INodeOutputConfiguration>,
): ConnectionTypes[] {
connections: Array<NodeConnectionType | INodeInputConfiguration | INodeOutputConfiguration>,
): NodeConnectionType[] {
return connections
.map((connection) => {
if (typeof connection === 'string') {
@@ -1261,7 +1260,7 @@ export function getNodeInputs(
workflow: Workflow,
node: INode,
nodeTypeData: INodeTypeDescription,
): Array<ConnectionTypes | INodeInputConfiguration> {
): Array<NodeConnectionType | INodeInputConfiguration> {
if (Array.isArray(nodeTypeData?.inputs)) {
return nodeTypeData.inputs;
}
@@ -1273,7 +1272,7 @@ export function getNodeInputs(
nodeTypeData.inputs,
'internal',
{},
) || []) as ConnectionTypes[];
) || []) as NodeConnectionType[];
} catch (e) {
console.warn('Could not calculate inputs dynamically for node: ', node.name);
return [];
@@ -1353,8 +1352,8 @@ export function getNodeOutputs(
workflow: Workflow,
node: INode,
nodeTypeData: INodeTypeDescription,
): Array<ConnectionTypes | INodeOutputConfiguration> {
let outputs: Array<ConnectionTypes | INodeOutputConfiguration> = [];
): Array<NodeConnectionType | INodeOutputConfiguration> {
let outputs: Array<NodeConnectionType | INodeOutputConfiguration> = [];
if (Array.isArray(nodeTypeData.outputs)) {
outputs = nodeTypeData.outputs;
@@ -1366,7 +1365,7 @@ export function getNodeOutputs(
nodeTypeData.outputs,
'internal',
{},
) || []) as ConnectionTypes[];
) || []) as NodeConnectionType[];
} catch (e) {
console.warn('Could not calculate outputs dynamically for node: ', node.name);
}
@@ -1389,7 +1388,7 @@ export function getNodeOutputs(
...outputs,
{
category: 'error',
type: 'main',
type: NodeConnectionType.Main,
displayName: 'Error',
},
];

View File

@@ -41,7 +41,6 @@ import type {
IRun,
IRunNodeResponse,
NodeParameterValueType,
ConnectionTypes,
CloseFunction,
INodeOutputConfiguration,
} from './Interfaces';
@@ -580,11 +579,11 @@ export class Workflow {
/**
* Finds the highest parent nodes of the node with the given name
*
* @param {ConnectionTypes} [type='main']
* @param {NodeConnectionType} [type='main']
*/
getHighestNode(
nodeName: string,
type: ConnectionTypes = 'main',
type: NodeConnectionType = NodeConnectionType.Main,
nodeConnectionIndex?: number,
checkedNodes?: string[],
): string[] {
@@ -664,7 +663,7 @@ export class Workflow {
*/
getChildNodes(
nodeName: string,
type: ConnectionTypes | 'ALL' | 'ALL_NON_MAIN' = 'main',
type: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionType.Main,
depth = -1,
): string[] {
return this.getConnectedNodes(this.connectionsBySourceNode, nodeName, type, depth);
@@ -673,12 +672,12 @@ export class Workflow {
/**
* Returns all the nodes before the given one
*
* @param {ConnectionTypes} [type='main']
* @param {NodeConnectionType} [type='main']
* @param {*} [depth=-1]
*/
getParentNodes(
nodeName: string,
type: ConnectionTypes | 'ALL' | 'ALL_NON_MAIN' = 'main',
type: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionType.Main,
depth = -1,
): string[] {
return this.getConnectedNodes(this.connectionsByDestinationNode, nodeName, type, depth);
@@ -688,13 +687,13 @@ export class Workflow {
* Gets all the nodes which are connected nodes starting from
* the given one
*
* @param {ConnectionTypes} [type='main']
* @param {NodeConnectionType} [type='main']
* @param {*} [depth=-1]
*/
getConnectedNodes(
connections: IConnections,
nodeName: string,
connectionType: ConnectionTypes | 'ALL' | 'ALL_NON_MAIN' = 'main',
connectionType: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionType.Main,
depth = -1,
checkedNodesIncoming?: string[],
): string[] {
@@ -710,13 +709,13 @@ export class Workflow {
return [];
}
let types: ConnectionTypes[];
let types: NodeConnectionType[];
if (connectionType === 'ALL') {
types = Object.keys(connections[nodeName]) as ConnectionTypes[];
types = Object.keys(connections[nodeName]) as NodeConnectionType[];
} else if (connectionType === 'ALL_NON_MAIN') {
types = Object.keys(connections[nodeName]).filter(
(type) => type !== 'main',
) as ConnectionTypes[];
) as NodeConnectionType[];
} else {
types = [connectionType];
}
@@ -800,7 +799,7 @@ export class Workflow {
searchNodesBFS(connections: IConnections, sourceNode: string, maxDepth = -1): IConnectedNode[] {
const returnConns: IConnectedNode[] = [];
const type: ConnectionTypes = 'main';
const type: NodeConnectionType = NodeConnectionType.Main;
let queue: IConnectedNode[] = [];
queue.push({
name: sourceNode,
@@ -907,7 +906,7 @@ export class Workflow {
getNodeConnectionIndexes(
nodeName: string,
parentNodeName: string,
type: ConnectionTypes = 'main',
type: NodeConnectionType = NodeConnectionType.Main,
depth = -1,
checkedNodes?: string[],
): INodeConnection | undefined {

View File

@@ -5,21 +5,22 @@
import { DateTime, Duration, Interval, Settings } from 'luxon';
import * as jmespath from 'jmespath';
import type {
IDataObject,
IExecuteData,
INodeExecutionData,
INodeParameters,
IPairedItemData,
IRunExecutionData,
ISourceData,
ITaskData,
IWorkflowDataProxyAdditionalKeys,
IWorkflowDataProxyData,
INodeParameterResourceLocator,
NodeParameterValueType,
WorkflowExecuteMode,
ProxyInput,
import {
type IDataObject,
type IExecuteData,
type INodeExecutionData,
type INodeParameters,
type IPairedItemData,
type IRunExecutionData,
type ISourceData,
type ITaskData,
type IWorkflowDataProxyAdditionalKeys,
type IWorkflowDataProxyData,
type INodeParameterResourceLocator,
type NodeParameterValueType,
type WorkflowExecuteMode,
type ProxyInput,
NodeConnectionType,
} from './Interfaces';
import * as NodeHelpers from './NodeHelpers';
import { ExpressionError, type ExpressionErrorOptions } from './errors/expression.error';
@@ -346,7 +347,7 @@ export class WorkflowDataProxy {
const nodeConnection = that.workflow.getNodeConnectionIndexes(
that.contextNodeName,
nodeName,
'main',
NodeConnectionType.Main,
);
if (nodeConnection === undefined) {

View File

@@ -1,9 +1,10 @@
import type {
INode,
INodeParameters,
INodeProperties,
INodeType,
INodeTypeDescription,
import {
NodeConnectionType,
type INode,
type INodeParameters,
type INodeProperties,
type INodeType,
type INodeTypeDescription,
} from '@/Interfaces';
import type { Workflow } from '@/Workflow';
import {
@@ -3573,9 +3574,9 @@ describe('NodeHelpers', () => {
[false, null],
[false, { outputs: '={{random_expression}}' }],
[false, { outputs: [] }],
[false, { outputs: ['main'] }],
[true, { outputs: ['ai_agent'] }],
[true, { outputs: ['main', 'ai_agent'] }],
[false, { outputs: [NodeConnectionType.Main] }],
[true, { outputs: [NodeConnectionType.AiAgent] }],
[true, { outputs: [NodeConnectionType.Main, NodeConnectionType.AiAgent] }],
];
test.each(tests)('should return %p for %o', (expected, nodeType) => {
expect(isSubNodeType(nodeType)).toBe(expected);

View File

@@ -1,11 +1,12 @@
import { mock } from 'jest-mock-extended';
import type {
IDataObject,
INodeType,
INodeTypeData,
INodeTypes,
IVersionedNodeType,
LoadedClass,
import {
NodeConnectionType,
type IDataObject,
type INodeType,
type INodeTypeData,
type INodeTypes,
type IVersionedNodeType,
type LoadedClass,
} from '@/Interfaces';
import * as NodeHelpers from '@/NodeHelpers';
@@ -60,8 +61,8 @@ const googleSheetsNode: LoadedClass<IVersionedNodeType> = {
defaults: {
name: 'Google Sheets',
},
inputs: ['main'],
outputs: ['main'],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
credentials: [
{
name: 'googleApi',
@@ -286,9 +287,9 @@ const googleSheetsNode: LoadedClass<IVersionedNodeType> = {
displayName: 'Google Sheets',
group: ['input', 'output'],
icon: 'file:googleSheets.svg',
inputs: ['main'],
inputs: [NodeConnectionType.Main],
name: 'googleSheets',
outputs: ['main'],
outputs: [NodeConnectionType.Main],
properties: [
{
default: 'oAuth2',
@@ -551,8 +552,8 @@ const setNode: LoadedClass<INodeType> = {
name: 'Set',
color: '#0000FF',
},
inputs: ['main'],
outputs: ['main'],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
properties: [
{
displayName: 'Value1',
@@ -588,7 +589,7 @@ const manualTriggerNode: LoadedClass<INodeType> = {
color: '#909298',
},
inputs: [],
outputs: ['main'],
outputs: [NodeConnectionType.Main],
properties: [
{
displayName:
@@ -621,8 +622,8 @@ export class NodeTypes implements INodeTypes {
name: 'Set Multi',
color: '#0000FF',
},
inputs: ['main'],
outputs: ['main'],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
properties: [
{
displayName: 'Values',