supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
180 lines โข 8.75 kB
JavaScript
;
/**
* CLI Commands for Framework Strategy System
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FrameworkCommands = void 0;
const framework_adapter_1 = require("../../features/integration/framework-adapter");
const enhanced_supabase_client_1 = require("../../core/utils/enhanced-supabase-client");
class FrameworkCommands {
/**
* Detect framework and show strategy information
*/
static async detectFramework(options) {
const client = (0, enhanced_supabase_client_1.createEnhancedSupabaseClient)(options.url || process.env.SUPABASE_URL || 'http://127.0.0.1:54321', options.key || process.env.SUPABASE_SERVICE_ROLE_KEY || '');
try {
console.log('๐ Detecting framework and analyzing strategies...\n');
const adapter = new framework_adapter_1.FrameworkAdapter(client, undefined, {
debug: options.verbose || false,
frameworkOverride: options.framework
});
await adapter.initialize();
// Get strategy information
const currentStrategy = adapter.getCurrentStrategy();
const selection = adapter.getStrategySelection();
const recommendations = adapter.getRecommendations();
// Display results
console.log('๐ Framework Detection Results:');
console.log(` Framework: ${selection?.detection.framework || 'unknown'}`);
console.log(` Version: ${selection?.detection.version || 'N/A'}`);
console.log(` Confidence: ${((selection?.detection.confidence || 0) * 100).toFixed(1)}%`);
console.log(` Selected Strategy: ${currentStrategy?.name || 'none'}`);
console.log(` Selection Reason: ${selection?.reason || 'unknown'}`);
if (selection?.detection.detectedFeatures && selection.detection.detectedFeatures.length > 0) {
console.log('\n๐ง Detected Features:');
selection.detection.detectedFeatures.forEach(feature => {
console.log(` โข ${feature}`);
});
}
if (recommendations.length > 0) {
console.log('\n๐ก Recommendations:');
recommendations.forEach(rec => {
console.log(` โข ${rec}`);
});
}
// Show all available strategies if verbose
if (options.verbose) {
console.log('\n๐ All Strategy Detection Results:');
const allResults = await adapter.getAllDetectionResults();
for (const result of allResults) {
console.log(`\n ${result.strategy}:`);
console.log(` Confidence: ${(result.detection.confidence * 100).toFixed(1)}%`);
console.log(` Features: ${result.detection.detectedFeatures.join(', ') || 'none'}`);
}
console.log('\n๐ ๏ธ Available Strategies:');
const availableStrategies = adapter.getAvailableStrategies();
availableStrategies.forEach(strategy => {
console.log(` โข ${strategy}`);
});
}
console.log('\nโ
Framework detection completed');
}
catch (error) {
console.error('โ Framework detection failed:', error.message);
if (options.verbose) {
console.error('Debug details:', error);
}
process.exit(1);
}
}
/**
* Test a specific strategy
*/
static async testStrategy(strategyName, options) {
const client = (0, enhanced_supabase_client_1.createEnhancedSupabaseClient)(options.url || process.env.SUPABASE_URL || 'http://127.0.0.1:54321', options.key || process.env.SUPABASE_SERVICE_ROLE_KEY || '');
try {
console.log(`๐งช Testing strategy: ${strategyName}\n`);
const adapter = new framework_adapter_1.FrameworkAdapter(client, undefined, {
debug: options.verbose || false
});
await adapter.initialize();
// Override to the requested strategy
await adapter.overrideStrategy(strategyName);
// Validate strategy
const validation = await adapter.validateStrategy();
console.log('๐ Strategy Test Results:');
console.log(` Strategy: ${strategyName}`);
console.log(` Valid: ${validation.valid ? 'โ
' : 'โ'}`);
if (validation.issues.length > 0) {
console.log('\nโ ๏ธ Issues:');
validation.issues.forEach(issue => {
console.log(` โข ${issue}`);
});
}
if (validation.recommendations.length > 0) {
console.log('\n๐ก Recommendations:');
validation.recommendations.forEach(rec => {
console.log(` โข ${rec}`);
});
}
// Test basic user creation if validation passes
if (validation.valid && options.verbose) {
console.log('\n๐ง Testing user creation...');
try {
const result = await adapter.createUser({
email: 'test@framework-test.com',
name: 'Framework Test User',
username: 'testuser'
});
if (result.success) {
console.log(' โ
User creation test passed');
if (result.appliedFixes.length > 0) {
console.log(' ๐ง Applied fixes:');
result.appliedFixes.forEach(fix => {
console.log(` โข ${fix.reason}`);
});
}
}
else {
console.log(' โ User creation test failed');
result.errors.forEach(error => {
console.log(` โข ${error}`);
});
}
}
catch (testError) {
console.log(` โ ๏ธ User creation test error: ${testError.message}`);
}
}
console.log('\nโ
Strategy test completed');
}
catch (error) {
console.error('โ Strategy test failed:', error.message);
if (options.verbose) {
console.error('Debug details:', error);
}
process.exit(1);
}
}
/**
* List all available strategies
*/
static async listStrategies(options) {
const client = (0, enhanced_supabase_client_1.createEnhancedSupabaseClient)(options.url || process.env.SUPABASE_URL || 'http://127.0.0.1:54321', options.key || process.env.SUPABASE_SERVICE_ROLE_KEY || '');
try {
console.log('๐ Available Framework Strategies:\n');
const adapter = new framework_adapter_1.FrameworkAdapter(client, undefined, {
debug: options.verbose || false
});
await adapter.initialize();
const strategies = adapter.getAvailableStrategies();
const allResults = await adapter.getAllDetectionResults();
for (const strategyName of strategies) {
const result = allResults.find(r => r.strategy === strategyName);
const confidence = result ? (result.detection.confidence * 100).toFixed(1) : '0.0';
console.log(` ${strategyName}:`);
console.log(` Confidence: ${confidence}%`);
if (result && result.detection.detectedFeatures.length > 0) {
console.log(` Features: ${result.detection.detectedFeatures.join(', ')}`);
}
if (options.verbose && result) {
console.log(` Framework: ${result.detection.framework}`);
if (result.detection.version) {
console.log(` Version: ${result.detection.version}`);
}
}
console.log('');
}
console.log('โ
Strategy listing completed');
}
catch (error) {
console.error('โ Failed to list strategies:', error.message);
if (options.verbose) {
console.error('Debug details:', error);
}
process.exit(1);
}
}
}
exports.FrameworkCommands = FrameworkCommands;
//# sourceMappingURL=framework-commands.js.map