refactor: Migrate NodeConnectionType to const object type (no-changelog) (#14078)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Alex Grozav
2025-03-21 14:01:26 +02:00
committed by GitHub
parent 7e8179b848
commit 8215e0b59f
703 changed files with 3104 additions and 3018 deletions

View File

@@ -348,6 +348,7 @@ export class Expression {
[Function, AsyncFunction].forEach(({ prototype }) =>
Object.defineProperty(prototype, 'constructor', { value: fnConstructors.mock }),
);
return evaluateExpression(expression, data);
} catch (error) {
if (isExpressionError(error)) throw error;

View File

@@ -1838,36 +1838,38 @@ export interface IPostReceiveSort extends IPostReceiveBase {
};
}
export const enum NodeConnectionType {
AiAgent = 'ai_agent',
AiChain = 'ai_chain',
AiDocument = 'ai_document',
AiEmbedding = 'ai_embedding',
AiLanguageModel = 'ai_languageModel',
AiMemory = 'ai_memory',
AiOutputParser = 'ai_outputParser',
AiRetriever = 'ai_retriever',
AiTextSplitter = 'ai_textSplitter',
AiTool = 'ai_tool',
AiVectorStore = 'ai_vectorStore',
Main = 'main',
}
export const NodeConnectionTypes = {
AiAgent: 'ai_agent',
AiChain: 'ai_chain',
AiDocument: 'ai_document',
AiEmbedding: 'ai_embedding',
AiLanguageModel: 'ai_languageModel',
AiMemory: 'ai_memory',
AiOutputParser: 'ai_outputParser',
AiRetriever: 'ai_retriever',
AiTextSplitter: 'ai_textSplitter',
AiTool: 'ai_tool',
AiVectorStore: 'ai_vectorStore',
Main: 'main',
} as const;
export type AINodeConnectionType = Exclude<NodeConnectionType, NodeConnectionType.Main>;
export type NodeConnectionType = (typeof NodeConnectionTypes)[keyof typeof NodeConnectionTypes];
export type AINodeConnectionType = Exclude<NodeConnectionType, typeof NodeConnectionTypes.Main>;
export const nodeConnectionTypes: NodeConnectionType[] = [
NodeConnectionType.AiAgent,
NodeConnectionType.AiChain,
NodeConnectionType.AiDocument,
NodeConnectionType.AiEmbedding,
NodeConnectionType.AiLanguageModel,
NodeConnectionType.AiMemory,
NodeConnectionType.AiOutputParser,
NodeConnectionType.AiRetriever,
NodeConnectionType.AiTextSplitter,
NodeConnectionType.AiTool,
NodeConnectionType.AiVectorStore,
NodeConnectionType.Main,
NodeConnectionTypes.AiAgent,
NodeConnectionTypes.AiChain,
NodeConnectionTypes.AiDocument,
NodeConnectionTypes.AiEmbedding,
NodeConnectionTypes.AiLanguageModel,
NodeConnectionTypes.AiMemory,
NodeConnectionTypes.AiOutputParser,
NodeConnectionTypes.AiRetriever,
NodeConnectionTypes.AiTextSplitter,
NodeConnectionTypes.AiTool,
NodeConnectionTypes.AiVectorStore,
NodeConnectionTypes.Main,
];
export interface INodeInputFilter {

View File

@@ -7,7 +7,7 @@ import get from 'lodash/get';
import isEqual from 'lodash/isEqual';
import { ApplicationError } from './errors/application.error';
import { NodeConnectionType } from './Interfaces';
import { NodeConnectionTypes } from './Interfaces';
import type {
FieldType,
IContextObject,
@@ -36,6 +36,7 @@ import type {
DisplayCondition,
NodeHint,
INodeExecutionData,
NodeConnectionType,
} from './Interfaces';
import { validateFilterParameter } from './NodeParameters/FilterParameter';
import {
@@ -327,7 +328,7 @@ export function isSubNodeType(
}
const outputTypes = getConnectionTypes(typeDescription.outputs);
return outputTypes
? outputTypes.filter((output) => output !== NodeConnectionType.Main).length > 0
? outputTypes.filter((output) => output !== NodeConnectionTypes.Main).length > 0
: false;
}
@@ -1217,7 +1218,7 @@ export function getNodeOutputs(
...outputs,
{
category: 'error',
type: NodeConnectionType.Main,
type: NodeConnectionTypes.Main,
displayName: 'Error',
},
];
@@ -1726,5 +1727,5 @@ export function isTriggerNode(nodeTypeData: INodeTypeDescription) {
export function isExecutable(workflow: Workflow, node: INode, nodeTypeData: INodeTypeDescription) {
const outputs = getNodeOutputs(workflow, node, nodeTypeData);
const outputNames = getConnectionTypes(outputs);
return outputNames.includes(NodeConnectionType.Main) || isTriggerNode(nodeTypeData);
return outputNames.includes(NodeConnectionTypes.Main) || isTriggerNode(nodeTypeData);
}

View File

@@ -27,8 +27,9 @@ import type {
IObservableObject,
NodeParameterValueType,
INodeOutputConfiguration,
NodeConnectionType,
} from './Interfaces';
import { NodeConnectionType } from './Interfaces';
import { NodeConnectionTypes } from './Interfaces';
import * as NodeHelpers from './NodeHelpers';
import * as ObservableObject from './ObservableObject';
@@ -495,7 +496,7 @@ export class Workflow {
return currentHighest;
}
if (!this.connectionsByDestinationNode[nodeName].hasOwnProperty(NodeConnectionType.Main)) {
if (!this.connectionsByDestinationNode[nodeName].hasOwnProperty(NodeConnectionTypes.Main)) {
// Node does not have incoming connections of given type
return currentHighest;
}
@@ -515,7 +516,8 @@ export class Workflow {
let connectionsByIndex: IConnection[] | null;
for (
let connectionIndex = 0;
connectionIndex < this.connectionsByDestinationNode[nodeName][NodeConnectionType.Main].length;
connectionIndex <
this.connectionsByDestinationNode[nodeName][NodeConnectionTypes.Main].length;
connectionIndex++
) {
if (nodeConnectionIndex !== undefined && nodeConnectionIndex !== connectionIndex) {
@@ -523,7 +525,7 @@ export class Workflow {
continue;
}
connectionsByIndex =
this.connectionsByDestinationNode[nodeName][NodeConnectionType.Main][connectionIndex];
this.connectionsByDestinationNode[nodeName][NodeConnectionTypes.Main][connectionIndex];
// eslint-disable-next-line @typescript-eslint/no-loop-func
connectionsByIndex?.forEach((connection) => {
if (checkedNodes.includes(connection.node)) {
@@ -564,7 +566,7 @@ export class Workflow {
*/
getChildNodes(
nodeName: string,
type: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionType.Main,
type: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionTypes.Main,
depth = -1,
): string[] {
return this.getConnectedNodes(this.connectionsBySourceNode, nodeName, type, depth);
@@ -578,7 +580,7 @@ export class Workflow {
*/
getParentNodes(
nodeName: string,
type: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionType.Main,
type: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionTypes.Main,
depth = -1,
): string[] {
return this.getConnectedNodes(this.connectionsByDestinationNode, nodeName, type, depth);
@@ -594,7 +596,7 @@ export class Workflow {
getConnectedNodes(
connections: IConnections,
nodeName: string,
connectionType: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionType.Main,
connectionType: NodeConnectionType | 'ALL' | 'ALL_NON_MAIN' = NodeConnectionTypes.Main,
depth = -1,
checkedNodesIncoming?: string[],
): string[] {
@@ -700,7 +702,7 @@ export class Workflow {
searchNodesBFS(connections: IConnections, sourceNode: string, maxDepth = -1): IConnectedNode[] {
const returnConns: IConnectedNode[] = [];
const type: NodeConnectionType = NodeConnectionType.Main;
const type: NodeConnectionType = NodeConnectionTypes.Main;
let queue: IConnectedNode[] = [];
queue.push({
name: sourceNode,
@@ -762,7 +764,7 @@ export class Workflow {
if (
!!outputs.find(
(output) =>
((output as INodeOutputConfiguration)?.type ?? output) !== NodeConnectionType.Main,
((output as INodeOutputConfiguration)?.type ?? output) !== NodeConnectionTypes.Main,
)
) {
// Get the first node which is connected to a non-main output
@@ -807,7 +809,7 @@ export class Workflow {
getNodeConnectionIndexes(
nodeName: string,
parentNodeName: string,
type: NodeConnectionType = NodeConnectionType.Main,
type: NodeConnectionType = NodeConnectionTypes.Main,
depth = -1,
checkedNodes?: string[],
): INodeConnection | undefined {

View File

@@ -25,7 +25,7 @@ import {
type NodeParameterValueType,
type WorkflowExecuteMode,
type ProxyInput,
NodeConnectionType,
NodeConnectionTypes,
} from './Interfaces';
import * as NodeHelpers from './NodeHelpers';
import { deepCopy } from './utils';
@@ -351,7 +351,7 @@ export class WorkflowDataProxy {
const nodeConnection = that.workflow.getNodeConnectionIndexes(
that.contextNodeName,
nodeName,
NodeConnectionType.Main,
NodeConnectionTypes.Main,
);
if (nodeConnection === undefined) {
@@ -970,7 +970,7 @@ export class WorkflowDataProxy {
const inputData =
that.runExecutionData?.resultData.runData[that.activeNodeName]?.[runIndex].inputOverride;
const placeholdersDataInputData =
inputData?.[NodeConnectionType.AiTool]?.[0]?.[itemIndex].json;
inputData?.[NodeConnectionTypes.AiTool]?.[0]?.[itemIndex].json;
if (Boolean(!placeholdersDataInputData)) {
throw new ExpressionError('No execution data available', {