supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
399 lines (396 loc) ⢠16.6 kB
JavaScript
;
/**
* Detection Reporting System for Epic 2: Smart Platform Detection Engine
* Provides CLI-friendly reporting of detection results and auto-configuration
* Part of Task 2.3.3: Create detection reporting and CLI integration
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_DETECTION_REPORT_OPTIONS = exports.DetectionCLI = exports.DetectionReporter = void 0;
const logger_1 = require("../../core/utils/logger");
/**
* Main Detection Reporter class
*/
class DetectionReporter {
/**
* Generate a comprehensive detection report
*/
static generateReport(detectionResults, autoConfiguration = undefined, options = {}) {
const fullOptions = this.mergeWithDefaults(options);
switch (fullOptions.format) {
case 'json':
return this.generateJSONReport(detectionResults, autoConfiguration);
case 'summary':
return this.generateSummaryReport(detectionResults, autoConfiguration, fullOptions);
case 'cli':
default:
return this.generateCLIReport(detectionResults, autoConfiguration, fullOptions);
}
}
/**
* Generate CLI-friendly report
*/
static generateCLIReport(detectionResults, autoConfiguration, options) {
const lines = [];
// Header
lines.push('');
lines.push('š Platform Detection Results');
lines.push('ā'.repeat(50));
lines.push('');
// Platform Architecture Section
lines.push('šļø Platform Architecture');
lines.push(` Type: ${detectionResults.architecture.architectureType}`);
lines.push(` Confidence: ${this.formatConfidence(detectionResults.architecture.confidence, options.useColors)}`);
if (options.showDetails && detectionResults.architecture.detectedFeatures.length > 0) {
lines.push(' Detected Features:');
detectionResults.architecture.detectedFeatures.forEach((feature) => {
lines.push(` ⢠${feature}`);
});
}
lines.push('');
// Content Domain Section
lines.push('šÆ Content Domain');
lines.push(` Primary Domain: ${detectionResults.domain.primaryDomain}`);
lines.push(` Confidence: ${this.formatConfidence(detectionResults.domain.confidence, options.useColors)}`);
if (options.showDetails && detectionResults.domain.detectedFeatures.length > 0) {
lines.push(' Detected Features:');
detectionResults.domain.detectedFeatures.forEach((feature) => {
lines.push(` ⢠${feature}`);
});
}
lines.push('');
// Integration Results Section
lines.push('š Detection Integration');
lines.push(` Overall Confidence: ${this.formatConfidence(detectionResults.integration.overallConfidence, options.useColors)}`);
lines.push(` Detection Agreement: ${this.formatConfidence(detectionResults.integration.crossValidation.overallAgreement, options.useColors)}`);
if (options.showConfidenceScores) {
lines.push(' Individual Engine Confidence:');
Object.entries(detectionResults.integration.crossValidation.engineAgreement).forEach(([engine, confidence]) => {
lines.push(` ⢠${engine}: ${this.formatConfidence(confidence, options.useColors)}`);
});
}
lines.push('');
// Auto-Configuration Section
if (autoConfiguration && options.showConfiguration) {
lines.push('āļø Auto-Configuration');
lines.push(` Strategy Used: ${autoConfiguration.generationMetrics.strategyUsed}`);
lines.push(` Configuration Confidence: ${this.formatConfidence(autoConfiguration.confidence, options.useColors)}`);
lines.push(` Templates Applied: ${autoConfiguration.generationMetrics.templatesApplied}`);
lines.push(` Generation Time: ${autoConfiguration.generationMetrics.executionTime}ms`);
lines.push('');
lines.push(' Generated Configuration:');
if (autoConfiguration.configuration.userCount) {
lines.push(` ⢠User Count: ${autoConfiguration.configuration.userCount}`);
}
if (autoConfiguration.configuration.setupsPerUser) {
lines.push(` ⢠Setups per User: ${autoConfiguration.configuration.setupsPerUser}`);
}
if (autoConfiguration.configuration.imagesPerSetup) {
lines.push(` ⢠Images per Setup: ${autoConfiguration.configuration.imagesPerSetup}`);
}
if (autoConfiguration.configuration.domain) {
lines.push(` ⢠Domain: ${autoConfiguration.configuration.domain}`);
}
if (autoConfiguration.configuration.createTeamAccounts !== undefined) {
lines.push(` ⢠Team Accounts: ${autoConfiguration.configuration.createTeamAccounts}`);
}
if (autoConfiguration.configuration.enableRealImages !== undefined) {
lines.push(` ⢠Real Images: ${autoConfiguration.configuration.enableRealImages}`);
}
lines.push('');
}
// Recommendations Section
if (options.showRecommendations) {
const allRecommendations = [
...detectionResults.architecture.recommendations,
...detectionResults.domain.recommendations,
...detectionResults.integration.recommendations
];
if (autoConfiguration) {
allRecommendations.push(...autoConfiguration.reasoning);
}
if (allRecommendations.length > 0) {
lines.push('š” Recommendations');
allRecommendations.forEach(rec => {
lines.push(` ⢠${rec}`);
});
lines.push('');
}
}
// Warnings Section
if (options.showWarnings) {
const allWarnings = [
...detectionResults.architecture.warnings,
...detectionResults.domain.warnings,
...detectionResults.integration.warnings
];
if (autoConfiguration) {
allWarnings.push(...autoConfiguration.warnings);
}
if (allWarnings.length > 0) {
lines.push('ā ļø Warnings');
allWarnings.forEach(warning => {
lines.push(` ⢠${warning}`);
});
lines.push('');
}
}
return lines.join('\n');
}
/**
* Generate JSON report for programmatic use
*/
static generateJSONReport(detectionResults, autoConfiguration) {
const report = {
timestamp: new Date().toISOString(),
detection: detectionResults,
autoConfiguration: autoConfiguration || null
};
return JSON.stringify(report, null, 2);
}
/**
* Generate summary report for quick overview
*/
static generateSummaryReport(detectionResults, autoConfiguration, options) {
const lines = [];
lines.push('š Detection Summary');
lines.push(`Platform: ${detectionResults.architecture.architectureType}/${detectionResults.domain.primaryDomain}`);
lines.push(`Confidence: ${this.formatConfidence(detectionResults.integration.overallConfidence, options.useColors)}`);
if (autoConfiguration) {
lines.push(`Auto-Config: ${autoConfiguration.generationMetrics.strategyUsed} (${this.formatConfidence(autoConfiguration.confidence, options.useColors)})`);
}
return lines.join(' | ');
}
/**
* Generate detection summary object
*/
static generateSummary(detectionResults, autoConfiguration = undefined) {
return {
architecture: {
type: detectionResults.architecture.architectureType,
confidence: detectionResults.architecture.confidence,
features: detectionResults.architecture.detectedFeatures
},
domain: {
primary: detectionResults.domain.primaryDomain,
confidence: detectionResults.domain.confidence,
features: detectionResults.domain.detectedFeatures
},
integration: {
overallConfidence: detectionResults.integration.overallConfidence,
detectionAgreement: detectionResults.integration.crossValidation.overallAgreement,
recommendations: detectionResults.integration.recommendations
},
configuration: autoConfiguration ? {
strategy: autoConfiguration.generationMetrics.strategyUsed,
confidence: autoConfiguration.confidence,
keySettings: {
userCount: autoConfiguration.configuration.userCount,
setupsPerUser: autoConfiguration.configuration.setupsPerUser,
domain: autoConfiguration.configuration.domain,
createTeamAccounts: autoConfiguration.configuration.createTeamAccounts
}
} : {
strategy: 'none',
confidence: 0,
keySettings: {}
}
};
}
/**
* Print detection results to console with formatting
*/
static printDetectionResults(detectionResults, autoConfiguration = undefined, options = {}) {
const report = this.generateReport(detectionResults, autoConfiguration, {
...options,
format: 'cli',
useColors: true
});
console.log(report);
}
/**
* Print quick summary to console
*/
static printSummary(detectionResults, autoConfiguration = undefined) {
const summary = this.generateSummaryReport(detectionResults, autoConfiguration, {
format: 'summary',
useColors: true,
showDetails: false,
showRecommendations: false,
showWarnings: false,
showConfidenceScores: false,
showConfiguration: false
});
logger_1.Logger.info(summary);
}
/**
* Format confidence score with colors
*/
static formatConfidence(confidence, useColors) {
const percentage = (confidence * 100).toFixed(1) + '%';
if (!useColors) {
return percentage;
}
// Color coding based on confidence level
if (confidence >= 0.9) {
return `\x1b[32m${percentage}\x1b[0m`; // Green
}
else if (confidence >= 0.7) {
return `\x1b[33m${percentage}\x1b[0m`; // Yellow
}
else if (confidence >= 0.5) {
return `\x1b[35m${percentage}\x1b[0m`; // Magenta
}
else {
return `\x1b[31m${percentage}\x1b[0m`; // Red
}
}
/**
* Merge options with defaults
*/
static mergeWithDefaults(options) {
return {
showDetails: true,
showRecommendations: true,
showWarnings: true,
showConfidenceScores: true,
showConfiguration: true,
format: 'cli',
useColors: true,
...options
};
}
}
exports.DetectionReporter = DetectionReporter;
/**
* CLI Command Integration for detection reporting
*/
class DetectionCLI {
/**
* Handle CLI command for detection analysis
*/
static async handleDetectionCommand(args) {
try {
// Parse command line arguments
const options = this.parseDetectionArgs(args);
logger_1.Logger.info('š Starting platform detection analysis...');
// Import and initialize detection system
const { DetectionIntegrationEngine } = await Promise.resolve().then(() => __importStar(require('./detection-integration')));
const { AutoConfigurator } = await Promise.resolve().then(() => __importStar(require('./auto-configurator')));
// Note: In real implementation, we would get client from configuration
// For now, we'll show the command structure
logger_1.Logger.info('Detection analysis would be performed here with configured Supabase client');
logger_1.Logger.info(`Options: ${JSON.stringify(options, null, 2)}`);
}
catch (error) {
logger_1.Logger.error('Detection command failed:', error);
process.exit(1);
}
}
/**
* Parse detection command arguments
*/
static parseDetectionArgs(args) {
const options = {
format: 'cli',
showDetails: true,
showConfiguration: true,
configurationStrategy: 'comprehensive'
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
switch (arg) {
case '--format':
case '-f':
if (i + 1 < args.length) {
const format = args[i + 1];
if (['cli', 'json', 'summary'].includes(format)) {
options.format = format;
}
i++;
}
break;
case '--no-details':
options.showDetails = false;
break;
case '--no-config':
options.showConfiguration = false;
break;
case '--strategy':
case '-s':
if (i + 1 < args.length) {
options.configurationStrategy = args[i + 1];
i++;
}
break;
}
}
return options;
}
/**
* Print CLI help for detection commands
*/
static printHelp() {
console.log(`
š Platform Detection Commands
supa-seed detect Run platform detection analysis
Options:
--format, -f <format> Output format: cli, json, summary (default: cli)
--no-details Hide detailed detection information
--no-config Hide auto-configuration results
--strategy, -s <strategy> Auto-configuration strategy: comprehensive, minimal, conservative, optimized
Examples:
supa-seed detect # Full CLI report
supa-seed detect --format json # JSON output for scripts
supa-seed detect --format summary # Quick summary
supa-seed detect --strategy minimal # Minimal auto-configuration
supa-seed detect --no-details --no-config # Basic results only
`);
}
}
exports.DetectionCLI = DetectionCLI;
/**
* Default detection report options
*/
exports.DEFAULT_DETECTION_REPORT_OPTIONS = {
showDetails: true,
showRecommendations: true,
showWarnings: true,
showConfidenceScores: true,
showConfiguration: true,
format: 'cli',
useColors: true
};
//# sourceMappingURL=detection-reporter.js.map