or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

constants.mddata-proxy.mderror-handling.mdexpression-system.mdextension-system.mdgraph-utilities.mdindex.mdnode-execution.mdspecialized-modules.mdtype-guards.mdtype-validation.mdutilities.mdworkflow-management.md
tile.json

tessl/npm-n8n-workflow

Workflow base code of n8n providing foundational workflow execution engine for automation platform

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/n8n-workflow@1.107.x

To install, run

npx @tessl/cli install tessl/npm-n8n-workflow@1.107.0

index.mddocs/

n8n-workflow

n8n-workflow is the foundational TypeScript library that provides the core workflow execution engine for the n8n automation platform. It implements workflow data structures, node execution logic, expression evaluation, type validation, and data transformation utilities that enable the creation and execution of automated workflows.

Package Information

  • Package Name: n8n-workflow
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install n8n-workflow

Core Imports

import { 
  Workflow, 
  Expression, 
  INode, 
  INodeExecutionData, 
  IExecuteFunctions,
  WorkflowDataProxy
} from "n8n-workflow";

For CommonJS:

const { 
  Workflow, 
  Expression, 
  INode, 
  INodeExecutionData, 
  IExecuteFunctions,
  WorkflowDataProxy 
} = require("n8n-workflow");

For common utilities and constants:

import * as common from "n8n-workflow/common";
import { 
  getChildNodes, 
  getParentNodes,
  MANUAL_TRIGGER_NODE_TYPE,
  START_NODE_TYPE,
  LOG_LEVELS
} from "n8n-workflow";

For type guards and specialized modules:

import { 
  isINodeProperties,
  isResourceMapperValue,
  LoggerProxy,
  NodeHelpers,
  ExpressionExtensions
} from "n8n-workflow";

Basic Usage

import { Workflow, Expression, INode, INodeExecutionData } from "n8n-workflow";

// Create a simple workflow
const nodes: INode[] = [
  {
    id: "start",
    name: "Start",
    type: "n8n-nodes-base.start",
    typeVersion: 1,
    position: [100, 200],
    parameters: {}
  }
];

const connections = {
  "Start": {
    "main": [
      [{ "node": "NextNode", "type": "main", "index": 0 }]
    ]
  }
};

const workflow = new Workflow({
  id: "workflow-1",
  name: "Example Workflow",
  nodes,
  connections,
  active: true,
  nodeTypes: {},
  staticData: {}
});

// Evaluate expressions
const expression = new Expression("{{ $json.name }}");
const result = expression.resolveSimpleParameterValue(
  "{{ $json.name }}", 
  { name: "John" }, 
  "string"
);

Architecture

n8n-workflow is built around several key components:

  • Workflow Engine: Core Workflow class managing node execution and data flow
  • Expression System: Powerful expression evaluation with sandboxing and extensions
  • Data Proxy System: Context-aware data access and parameter resolution
  • Type System: Comprehensive TypeScript interfaces for workflow components
  • Node Execution: Function contexts and helpers for node development
  • Validation Engine: Runtime type validation and schema checking
  • Error Handling: Comprehensive error classes for different failure scenarios

Capabilities

Workflow Management

Core workflow creation, execution, and management functionality including node orchestration and data flow control.

class Workflow {
  constructor(parameters: IWorkflowBase);
  execute(mode: WorkflowExecuteMode, startNode?: string): Promise<IRunExecutionData>;
  getNode(nodeName: string): INode | null;
  getNodes(): INode[];
  getConnections(): IConnections;
}

interface IWorkflowBase {
  id?: string;
  name: string;
  nodes: INode[];
  connections: IConnections;
  active: boolean;
  nodeTypes: INodeTypes;
  staticData?: IDataObject;
  settings?: IWorkflowSettings;
}

Workflow Management

Expression Evaluation

Powerful expression evaluation system with mathematical operations, data manipulation, and secure code execution in sandboxed environments.

class Expression {
  constructor(expression: string, workflow?: Workflow);
  resolveSimpleParameterValue(
    value: any,
    siblingParameters: IDataObject,
    returnType: string
  ): any;
  getParameterValue(
    parameterValue: any,
    runExecutionData: IRunExecutionData | null,
    runIndex: number,
    itemIndex: number,
    node: INode,
    connectionInputData: INodeExecutionData[]
  ): any;
}

Expression System

Node Execution Context

Execution contexts and helper functions that provide nodes with access to workflow data, credentials, HTTP requests, and other runtime services.

interface IExecuteFunctions {
  getContext(type: string): IContextObject;
  getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
  getInputData(inputIndex?: number): INodeExecutionData[];
  getNode(): INode;
  getWorkflow(): Workflow;
  helpers: {
    httpRequest(requestOptions: IHttpRequestOptions): Promise<any>;
    returnJsonArray(jsonData: IDataObject[]): INodeExecutionData[];
  };
}

Node Execution

Data Proxy and Parameter Resolution

Advanced data proxy system for accessing workflow data, resolving parameters, and handling complex data transformations with full context awareness.

class WorkflowDataProxy {
  static getDataProxy(
    workflow: Workflow,
    runExecutionData: IRunExecutionData,
    runIndex: number,
    itemIndex: number,
    node: INode,
    connectionInputData: INodeExecutionData[]
  ): IDataObject;
}

Data Proxy System

Type Validation

Comprehensive type validation system with runtime type checking and schema validation for ensuring data integrity.

function validateFieldType(
  field: string,
  value: any,
  type: FieldType
): ValidationResult;

function validateParameterValue(
  value: any,
  parameterDefinition: INodeProperties
): ValidationResult;

function isValidType(value: any, expectedType: string): boolean;

Type Validation

Error Handling

Structured error handling with specific error classes for different failure scenarios, including node errors, workflow errors, and expression errors.

class NodeOperationError extends NodeError {
  constructor(node: INode, message: string, options?: ErrorOptions);
}

class WorkflowOperationError extends WorkflowError {
  constructor(message: string, options?: ErrorOptions);
}

class ExpressionError extends Error {
  constructor(message: string, options?: ExpressionErrorOptions);
}

Error Handling

Utility Functions

Essential utility functions for object manipulation, async operations, data transformation, and common programming tasks.

function deepCopy<T>(source: T): T;
function isObjectEmpty(obj: object): boolean;
function jsonParse(jsonString: string): any;
function sleep(ms: number): Promise<void>;
function randomString(length: number): string;
function updateDisplayOptions(
  displayOptions: IDisplayOptions,
  properties: INodeProperties[]
): IDisplayOptions;

Utility Functions

Graph Analysis

Graph analysis utilities for workflow structure analysis, node relationship mapping, and workflow optimization operations.

function buildAdjacencyList(connections: IConnections): AdjacencyList;
function parseExtractableSubgraphSelection(
  selection: string
): ExtractableSubgraphData;

type AdjacencyList = Record<string, Array<{ node: string; type: string; index: number }>>;

Graph Utilities

Extension System

Comprehensive extension system providing data type extensions, native method access, and expression parsing capabilities for enhanced functionality.

class ExpressionExtensions {
  static readonly functions: Record<string, Extension>;
  static addExtension(name: string, extension: Extension): void;
}

interface Extension {
  doc: DocMetadata;
  transform: (value: any, ...args: any[]) => any;
}

Extension System

Constants and Enums

Essential constants and enumeration values used throughout the n8n workflow system for node types, execution modes, and configuration.

// Node type constants
const MANUAL_TRIGGER_NODE_TYPE = 'n8n-nodes-base.manualTrigger';
const START_NODE_TYPE = 'n8n-nodes-base.start';
const CODE_NODE_TYPE = 'n8n-nodes-base.code';

// Node type collections
const STARTING_NODE_TYPES: string[];
const SCRIPTING_NODE_TYPES: string[];

// Execution constants
const LOG_LEVELS: readonly ['silent', 'error', 'warn', 'info', 'debug'];
const CODE_LANGUAGES: readonly ['javaScript', 'python'];
const CODE_EXECUTION_MODES: readonly ['runOnceForAllItems', 'runOnceForEachItem'];

Constants and Enums

Type Guards

Runtime type checking functions that validate if values match specific n8n interface types, providing type safety for dynamic workflow data.

function isINodeProperties(value: any): value is INodeProperties;
function isINodePropertyOptions(value: any): value is INodePropertyOptions;
function isResourceMapperValue(value: any): value is IResourceMapperValue;
function isResourceLocatorValue(value: any): value is IResourceLocatorValue;
function isFilterValue(value: any): value is IFilterValue;

Type Guards

Specialized Modules

Specialized utility modules and namespaces providing logging, node helpers, telemetry, observable objects, and native method access.

namespace LoggerProxy {
  function info(message: string, meta?: object): void;
  function debug(message: string, meta?: object): void;
  function warn(message: string, meta?: object): void;
  function error(message: string, meta?: object): void;
}

namespace NodeHelpers {
  function getExecutionData(/*...*/): IExecuteData;
  function getNodeParameters(/*...*/): INodeParameters;
}

class NativeMethods {
  static getInstanceBaseClasses(): string[];
  static hasAccessToMethod(instanceName: string, methodName: string): boolean;
}

Specialized Modules