// Simple configuration validation script // This validates the wrangler.toml and Worker code without requiring API access const fs = require('fs'); const path = require('path'); console.log('šŸ” Validating Hyperdrive Configuration Files'); console.log('============================================'); // Check wrangler.toml console.log('\nšŸ“‹ Checking wrangler.toml...'); try { const wranglerContent = fs.readFileSync('wrangler.toml', 'utf8'); console.log('āœ… wrangler.toml exists'); // Check for required fields const checks = [ { field: 'name', regex: /name\s*=\s*["']([^"']+)["']/, required: true }, { field: 'main', regex: /main\s*=\s*["']([^"']+)["']/, required: true }, { field: 'compatibility_date', regex: /compatibility_date\s*=\s*["']([^"']+)["']/, required: true }, { field: 'nodejs_compat', regex: /nodejs_compat/, required: true }, { field: 'hyperdrive binding', regex: /binding\s*=\s*["']HYPERDRIVE["']/, required: true }, { field: 'hyperdrive id', regex: /id\s*=\s*["']ef43924d89064cddabfaccf06aadfab6["']/, required: true } ]; checks.forEach(check => { if (check.regex.test(wranglerContent)) { console.log(` āœ… ${check.field} configured`); } else { console.log(` āŒ ${check.field} missing or incorrect`); } }); } catch (error) { console.log('āŒ wrangler.toml not found or unreadable'); } // Check Worker code console.log('\nšŸ“ Checking Worker code...'); try { const workerContent = fs.readFileSync('src/index.ts', 'utf8'); console.log('āœ… src/index.ts exists'); const codeChecks = [ { name: 'Hyperdrive binding usage', regex: /env\.HYPERDRIVE/ }, { name: 'Test connection endpoint', regex: /\/test-connection/ }, { name: 'Test query endpoint', regex: /\/test-query/ }, { name: 'PostgreSQL import', regex: /pg/ }, { name: 'Error handling', regex: /try\s*{[\s\S]*catch/ } ]; codeChecks.forEach(check => { if (check.regex.test(workerContent)) { console.log(` āœ… ${check.name} implemented`); } else { console.log(` āš ļø ${check.name} not found`); } }); } catch (error) { console.log('āŒ src/index.ts not found or unreadable'); } // Check package.json console.log('\nšŸ“¦ Checking package.json...'); try { const packageContent = fs.readFileSync('package.json', 'utf8'); const packageJson = JSON.parse(packageContent); console.log('āœ… package.json exists and is valid JSON'); const deps = { 'pg': packageJson.dependencies?.pg, '@cloudflare/workers-types': packageJson.devDependencies?.['@cloudflare/workers-types'], '@types/pg': packageJson.devDependencies?.['@types/pg'], 'typescript': packageJson.devDependencies?.typescript, 'wrangler': packageJson.devDependencies?.wrangler }; Object.entries(deps).forEach(([dep, version]) => { if (version) { console.log(` āœ… ${dep}: ${version}`); } else { console.log(` āŒ ${dep}: not found`); } }); } catch (error) { console.log('āŒ package.json not found or invalid JSON'); } console.log('\nšŸ“Š Configuration Summary:'); console.log(' - Project: hyperdrive-neondb-test'); console.log(' - Hyperdrive ID: ef43924d89064cddabfaccf06aadfab6'); console.log(' - Database: NeonDB (PostgreSQL)'); console.log(' - Binding: HYPERDRIVE'); console.log(' - Compatibility: nodejs_compat enabled'); console.log('\nšŸš€ Next Steps:'); console.log(' 1. Ensure you have proper Cloudflare API permissions'); console.log(' 2. Verify the Hyperdrive configuration exists in your Cloudflare dashboard'); console.log(' 3. Deploy with: wrangler deploy'); console.log(' 4. Test endpoints after deployment'); console.log('\nšŸ’” Troubleshooting:'); console.log(' - If API token has insufficient permissions, use: wrangler login'); console.log(' - Check Hyperdrive exists: https://dash.cloudflare.com/[account-id]/workers/hyperdrive'); console.log(' - Verify NeonDB connection string is correct in Hyperdrive config');