mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
/**
|
|
* Plugin Validator - Pre-execution validation for workflow nodes
|
|
* @packageDocumentation
|
|
*/
|
|
|
|
export interface ValidationResult {
|
|
valid: boolean;
|
|
errors: string[];
|
|
warnings: string[];
|
|
}
|
|
|
|
export class PluginValidator {
|
|
/**
|
|
* Validate node against plugin metadata
|
|
*/
|
|
validateNode(_nodeType: string, nodeConfig: any, _metadata?: any): ValidationResult {
|
|
const errors: string[] = [];
|
|
const warnings: string[] = [];
|
|
|
|
if (!nodeConfig) {
|
|
errors.push('Node configuration is required');
|
|
return { valid: false, errors, warnings };
|
|
}
|
|
|
|
if (!nodeConfig.id) errors.push('Node must have an id field');
|
|
if (!nodeConfig.name) errors.push('Node must have a name field');
|
|
if (!nodeConfig.type) errors.push('Node must have a type field');
|
|
|
|
if (nodeConfig.parameters) {
|
|
const paramStr = JSON.stringify(nodeConfig.parameters);
|
|
if (paramStr.includes('[object Object]')) {
|
|
errors.push('Parameters contain serialized objects');
|
|
}
|
|
if ('name' in nodeConfig.parameters || 'typeVersion' in nodeConfig.parameters) {
|
|
errors.push('Parameters contain node-level attributes');
|
|
}
|
|
}
|
|
|
|
return { valid: errors.length === 0, errors, warnings };
|
|
}
|
|
|
|
validateMetadata(metadata: any): ValidationResult {
|
|
const errors: string[] = [];
|
|
if (!metadata.nodeType) errors.push('Metadata missing nodeType');
|
|
if (!metadata.version) errors.push('Metadata missing version');
|
|
return { valid: errors.length === 0, errors, warnings: [] };
|
|
}
|
|
}
|