Workflow base code of n8n providing foundational workflow execution engine for automation platform
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive type validation system with runtime type checking, schema validation, and type guard functions for ensuring data integrity and type safety throughout workflow execution.
Core validation functions for validating field types and values.
/**
* Validate field type and value
* @param field - Field name for error reporting
* @param value - Value to validate
* @param type - Expected field type
* @returns Validation result with success status and errors
*/
function validateFieldType(
field: string,
value: any,
type: FieldType
): ValidationResult;
/**
* Validate multiple parameters against schema
* @param parameters - Parameters object to validate
* @param parameterTypes - Schema defining expected types
* @returns Validation result with detailed errors
*/
function validateParameters(
parameters: INodeParameters,
parameterTypes: IParameterTypeSchema
): ValidationResult;
interface ValidationResult {
isValid: boolean;
errors: ValidationError[];
}
interface ValidationError {
field: string;
message: string;
receivedType: string;
expectedType: string;
value?: any;
}
type FieldType =
| 'string'
| 'number'
| 'integer'
| 'boolean'
| 'array'
| 'object'
| 'null'
| 'undefined'
| 'dateTime'
| 'email'
| 'url'
| 'json'
| 'binary';Comprehensive type guards for checking interface and object types.
/**
* Check if value is valid node properties
* @param value - Value to check
* @returns Type guard for INodeProperties
*/
function isINodeProperties(value: any): value is INodeProperties;
/**
* Check if value is valid node property options
* @param value - Value to check
* @returns Type guard for INodePropertyOptions
*/
function isINodePropertyOptions(value: any): value is INodePropertyOptions;
/**
* Check if value is valid node property collection
* @param value - Value to check
* @returns Type guard for INodePropertyCollection
*/
function isINodePropertyCollection(value: any): value is INodePropertyCollection;
/**
* Check if value is valid node properties list
* @param value - Value to check
* @returns Type guard for INodePropertiesList
*/
function isINodePropertiesList(value: any): value is INodePropertiesList;
/**
* Check if value is valid collection list
* @param value - Value to check
* @returns Type guard for INodePropertyCollectionList
*/
function isINodePropertyCollectionList(value: any): value is INodePropertyCollectionList;
/**
* Check if value is valid options list
* @param value - Value to check
* @returns Type guard for INodePropertyOptionsList
*/
function isINodePropertyOptionsList(value: any): value is INodePropertyOptionsList;
/**
* Check if value is resource mapper value
* @param value - Value to check
* @returns Type guard for IResourceMapperValue
*/
function isResourceMapperValue(value: any): value is IResourceMapperValue;
/**
* Check if value is resource locator value
* @param value - Value to check
* @returns Type guard for IResourceLocatorValue
*/
function isResourceLocatorValue(value: any): value is IResourceLocatorValue;
/**
* Check if value is filter value
* @param value - Value to check
* @returns Type guard for IFilterValue
*/
function isFilterValue(value: any): value is IFilterValue;Schema-based validation for complex data structures and nested objects.
/**
* Validate object against JSON schema
* @param data - Object to validate
* @param schema - JSON schema definition
* @returns Validation result with detailed errors
*/
function validateSchema(
data: any,
schema: JSONSchema
): SchemaValidationResult;
/**
* Validate node parameter schema
* @param parameters - Node parameters to validate
* @param nodeType - Node type definition
* @returns Parameter validation result
*/
function validateNodeParameters(
parameters: INodeParameters,
nodeType: INodeTypeDescription
): ParameterValidationResult;
interface SchemaValidationResult {
isValid: boolean;
errors: SchemaValidationError[];
data?: any;
}
interface SchemaValidationError {
path: string;
message: string;
keyword: string;
params?: any;
schemaPath: string;
}
interface ParameterValidationResult {
isValid: boolean;
errors: ParameterValidationError[];
warnings: ParameterValidationWarning[];
}
interface ParameterValidationError {
parameter: string;
message: string;
type: 'missing' | 'invalid' | 'constraint';
value?: any;
}Runtime type checking utilities for dynamic type validation.
/**
* Get runtime type of value
* @param value - Value to check type of
* @returns Runtime type string
*/
function getRuntimeType(value: any): string;
/**
* Check if value matches expected type
* @param value - Value to check
* @param expectedType - Expected type string or constructor
* @returns Boolean indicating type match
*/
function isType(value: any, expectedType: string | Function): boolean;
/**
* Ensure value is of expected type or throw error
* @param value - Value to check
* @param expectedType - Expected type
* @param fieldName - Field name for error reporting
* @throws TypeError if type doesn't match
*/
function ensureType(
value: any,
expectedType: string | Function,
fieldName?: string
): void;
/**
* Convert value to specified type with validation
* @param value - Value to convert
* @param targetType - Target type for conversion
* @param strict - Strict conversion mode
* @returns Converted value
* @throws TypeError if conversion fails
*/
function convertToType<T>(
value: any,
targetType: string | Function,
strict?: boolean
): T;Specialized validation for node parameters and workflow configuration.
/**
* Validate parameter value against parameter definition
* @param parameterName - Parameter name
* @param value - Parameter value
* @param parameterDefinition - Parameter definition
* @returns Parameter validation result
*/
function validateParameterValue(
parameterName: string,
value: NodeParameterValue,
parameterDefinition: INodeProperties
): ParameterValueValidationResult;
/**
* Check parameter dependencies and display conditions
* @param parameters - All node parameters
* @param parameterDefinition - Parameter definition to check
* @returns Boolean indicating if parameter should be displayed
*/
function checkParameterDisplayConditions(
parameters: INodeParameters,
parameterDefinition: INodeProperties
): boolean;
interface ParameterValueValidationResult {
isValid: boolean;
error?: string;
warning?: string;
coercedValue?: any;
}
/**
* Validate collection parameter structure
* @param collectionValue - Collection parameter value
* @param collectionDefinition - Collection definition
* @returns Collection validation result
*/
function validateCollectionParameter(
collectionValue: INodeParameters[],
collectionDefinition: INodePropertyCollection
): CollectionValidationResult;
interface CollectionValidationResult {
isValid: boolean;
errors: CollectionValidationError[];
itemErrors: { [index: number]: ParameterValidationError[] };
}Advanced constraint validation for parameter values and data integrity.
/**
* Validate value constraints (min, max, pattern, etc.)
* @param value - Value to validate
* @param constraints - Constraint definition
* @returns Constraint validation result
*/
function validateConstraints(
value: any,
constraints: IParameterConstraints
): ConstraintValidationResult;
interface IParameterConstraints {
min?: number;
max?: number;
minLength?: number;
maxLength?: number;
pattern?: string | RegExp;
enum?: any[];
required?: boolean;
unique?: boolean;
format?: string;
}
interface ConstraintValidationResult {
isValid: boolean;
violations: ConstraintViolation[];
}
interface ConstraintViolation {
constraint: string;
message: string;
actualValue: any;
expectedValue?: any;
}
/**
* Validate email format
* @param email - Email string to validate
* @returns Boolean indicating valid email format
*/
function isValidEmail(email: string): boolean;
/**
* Validate URL format
* @param url - URL string to validate
* @returns Boolean indicating valid URL format
*/
function isValidUrl(url: string): boolean;
/**
* Validate JSON format
* @param jsonString - JSON string to validate
* @returns Boolean indicating valid JSON format
*/
function isValidJson(jsonString: string): boolean;Usage Examples:
import {
validateFieldType,
validateParameters,
isINodeProperties,
validateSchema,
ensureType,
validateParameterValue
} from "n8n-workflow";
// Basic field type validation
const stringValidation = validateFieldType('username', 'john_doe', 'string');
console.log('String validation:', stringValidation.isValid); // true
const numberValidation = validateFieldType('age', '25', 'number');
console.log('Number validation errors:', numberValidation.errors);
// Parameter validation
const parameterValidation = validateParameters(
{
apiUrl: 'https://api.example.com',
timeout: 5000,
retries: 3
},
{
apiUrl: { type: 'string', required: true, format: 'url' },
timeout: { type: 'number', min: 1000, max: 60000 },
retries: { type: 'integer', min: 0, max: 10 }
}
);
if (!parameterValidation.isValid) {
console.log('Parameter validation errors:', parameterValidation.errors);
}
// Type guard usage
const nodeProperty = {
displayName: 'API URL',
name: 'apiUrl',
type: 'string',
required: true
};
if (isINodeProperties(nodeProperty)) {
console.log('Valid node property:', nodeProperty.displayName);
} else {
console.log('Invalid node property structure');
}
// Schema validation
const schema = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1 },
age: { type: 'number', minimum: 0 },
email: { type: 'string', format: 'email' }
},
required: ['name', 'email']
};
const userData = {
name: 'John Doe',
age: 30,
email: 'john@example.com'
};
const schemaValidation = validateSchema(userData, schema);
if (schemaValidation.isValid) {
console.log('User data is valid');
} else {
console.log('Schema validation errors:', schemaValidation.errors);
}
// Runtime type checking
try {
ensureType('hello', 'string', 'message');
console.log('Type check passed');
ensureType(123, 'string', 'invalidField'); // Throws TypeError
} catch (error) {
console.log('Type check failed:', error.message);
}
// Parameter value validation
const parameterDefinition = {
displayName: 'Timeout',
name: 'timeout',
type: 'number',
default: 30000,
typeOptions: {
minValue: 1000,
maxValue: 300000
}
};
const parameterResult = validateParameterValue('timeout', 45000, parameterDefinition);
if (parameterResult.isValid) {
console.log('Parameter value is valid');
} else {
console.log('Parameter validation error:', parameterResult.error);
}
// Constraint validation with complex rules
const constraints = {
min: 1,
max: 100,
pattern: /^[a-zA-Z0-9_]+$/,
required: true
};
const constraintResult = validateConstraints('valid_name_123', constraints);
if (!constraintResult.isValid) {
constraintResult.violations.forEach(violation => {
console.log(`Constraint violation: ${violation.constraint} - ${violation.message}`);
});
}