Spaces:
Sleeping
Sleeping
File size: 4,562 Bytes
da2e594 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | #!/usr/bin/env node
/**
* Copyright (c) 2024 AiAdvisors Romuald Czlonkowski
* Licensed under the Sustainable Use License v1.0
*/
import { createDatabaseAdapter } from '../database/database-adapter';
interface NodeRow {
node_type: string;
package_name: string;
display_name: string;
description?: string;
category?: string;
development_style?: string;
is_ai_tool: number;
is_trigger: number;
is_webhook: number;
is_versioned: number;
version?: string;
documentation?: string;
properties_schema?: string;
operations?: string;
credentials_required?: string;
updated_at: string;
}
async function validate() {
const db = await createDatabaseAdapter('./data/nodes.db');
console.log('๐ Validating critical nodes...\n');
const criticalChecks = [
{
type: 'nodes-base.httpRequest',
checks: {
hasDocumentation: true,
documentationContains: 'HTTP Request',
style: 'programmatic'
}
},
{
type: 'nodes-base.code',
checks: {
hasDocumentation: true,
documentationContains: 'Code'
}
},
{
type: 'nodes-base.slack',
checks: {
hasOperations: true,
style: 'programmatic'
}
},
{
type: 'nodes-langchain.agent',
checks: {
isAITool: false, // According to the database, it's not marked as AI tool
packageName: '@n8n/n8n-nodes-langchain'
}
}
];
let passed = 0;
let failed = 0;
for (const check of criticalChecks) {
const node = db.prepare('SELECT * FROM nodes WHERE node_type = ?').get(check.type) as NodeRow | undefined;
if (!node) {
console.log(`โ ${check.type}: NOT FOUND`);
failed++;
continue;
}
let nodeOk = true;
const issues: string[] = [];
// Run checks
if (check.checks.hasDocumentation && !node.documentation) {
nodeOk = false;
issues.push('missing documentation');
}
if (check.checks.documentationContains &&
!node.documentation?.includes(check.checks.documentationContains)) {
nodeOk = false;
issues.push(`documentation doesn't contain "${check.checks.documentationContains}"`);
}
if (check.checks.style && node.development_style !== check.checks.style) {
nodeOk = false;
issues.push(`wrong style: ${node.development_style}`);
}
if (check.checks.hasOperations) {
const operations = JSON.parse(node.operations || '[]');
if (!operations.length) {
nodeOk = false;
issues.push('no operations found');
}
}
if (check.checks.isAITool !== undefined && !!node.is_ai_tool !== check.checks.isAITool) {
nodeOk = false;
issues.push(`AI tool flag mismatch: expected ${check.checks.isAITool}, got ${!!node.is_ai_tool}`);
}
if ('isVersioned' in check.checks && check.checks.isVersioned && !node.is_versioned) {
nodeOk = false;
issues.push('not marked as versioned');
}
if (check.checks.packageName && node.package_name !== check.checks.packageName) {
nodeOk = false;
issues.push(`wrong package: ${node.package_name}`);
}
if (nodeOk) {
console.log(`โ
${check.type}`);
passed++;
} else {
console.log(`โ ${check.type}: ${issues.join(', ')}`);
failed++;
}
}
console.log(`\n๐ Results: ${passed} passed, ${failed} failed`);
// Additional statistics
const stats = db.prepare(`
SELECT
COUNT(*) as total,
SUM(is_ai_tool) as ai_tools,
SUM(is_trigger) as triggers,
SUM(is_versioned) as versioned,
COUNT(DISTINCT package_name) as packages
FROM nodes
`).get() as any;
console.log('\n๐ Database Statistics:');
console.log(` Total nodes: ${stats.total}`);
console.log(` AI tools: ${stats.ai_tools}`);
console.log(` Triggers: ${stats.triggers}`);
console.log(` Versioned: ${stats.versioned}`);
console.log(` Packages: ${stats.packages}`);
// Check documentation coverage
const docStats = db.prepare(`
SELECT
COUNT(*) as total,
SUM(CASE WHEN documentation IS NOT NULL THEN 1 ELSE 0 END) as with_docs
FROM nodes
`).get() as any;
console.log(`\n๐ Documentation Coverage:`);
console.log(` Nodes with docs: ${docStats.with_docs}/${docStats.total} (${Math.round(docStats.with_docs / docStats.total * 100)}%)`);
db.close();
process.exit(failed > 0 ? 1 : 0);
}
if (require.main === module) {
validate().catch(console.error);
} |