UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

248 lines 7.52 kB
"use strict"; /** * Extension Configuration System * Implements Task 3.5: Comprehensive extension configuration system with type-safe schemas, validation, and management utilities */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtensionConfigUtils = exports.ExtensionConfigManager = void 0; exports.createDefaultExtensionsConfig = createDefaultExtensionsConfig; /** * Extension configuration manager */ class ExtensionConfigManager { constructor(config) { this.config = config; } /** * Validate extension configuration */ validate() { const errors = []; const warnings = []; // Validate global settings if (!this.config.global.enabled && Object.keys(this.config.extensions).length > 0) { warnings.push('Extensions are configured but global extension system is disabled'); } // Validate each extension for (const [id, extension] of Object.entries(this.config.extensions)) { if (!extension) continue; // Check required fields if (!extension.id || !extension.name || !extension.version) { errors.push(`Extension ${id} is missing required fields (id, name, version)`); } // Check compatibility if (extension.compatibility) { if (!extension.compatibility.minSupaSeedVersion) { warnings.push(`Extension ${id} should specify minimum SupaSeed version`); } } // Check dependencies if (extension.dependencies) { for (const dep of extension.dependencies) { if (!this.config.extensions[dep]) { errors.push(`Extension ${id} depends on ${dep} which is not configured`); } } } } return { success: errors.length === 0, errors, warnings, appliedConfig: this.config }; } /** * Get extension by ID */ getExtension(id) { return this.config.extensions[id]; } /** * Enable extension */ enableExtension(id) { const extension = this.config.extensions[id]; if (!extension) { return { success: false, errors: [`Extension ${id} not found`], warnings: [] }; } extension.enabled = true; return { success: true, errors: [], warnings: [], data: extension }; } /** * Disable extension */ disableExtension(id) { const extension = this.config.extensions[id]; if (!extension) { return { success: false, errors: [`Extension ${id} not found`], warnings: [] }; } extension.enabled = false; return { success: true, errors: [], warnings: [], data: extension }; } /** * Get enabled extensions */ getEnabledExtensions() { return Object.values(this.config.extensions) .filter(ext => ext && ext.enabled); } /** * Get extensions by domain */ getExtensionsByDomain(domain) { return Object.values(this.config.extensions) .filter(ext => ext && ext.compatibility.domains.includes(domain)); } /** * Create extension from template */ createFromTemplate(templateId, variables = {}) { const template = this.config.templates.find(t => t.id === templateId); if (!template) { return { success: false, errors: [`Template ${templateId} not found`], warnings: [] }; } // Process template variables let processedTemplate = JSON.parse(JSON.stringify(template.template)); if (template.variables) { for (const [key, varConfig] of Object.entries(template.variables)) { const value = variables[key] ?? varConfig.default; if (varConfig.required && value === undefined) { return { success: false, errors: [`Required template variable ${key} not provided`], warnings: [] }; } // Simple variable substitution (in a real implementation, this would be more sophisticated) processedTemplate = this.substituteVariable(processedTemplate, key, value); } } return { success: true, errors: [], warnings: [], data: processedTemplate }; } /** * Simple variable substitution helper */ substituteVariable(obj, key, value) { if (typeof obj === 'string') { return obj.replace(new RegExp(`{{${key}}}`, 'g'), value); } if (Array.isArray(obj)) { return obj.map(item => this.substituteVariable(item, key, value)); } if (typeof obj === 'object' && obj !== null) { const result = {}; for (const [objKey, objValue] of Object.entries(obj)) { result[objKey] = this.substituteVariable(objValue, key, value); } return result; } return obj; } /** * Export configuration */ exportConfig() { return JSON.parse(JSON.stringify(this.config)); } } exports.ExtensionConfigManager = ExtensionConfigManager; /** * Create default extensions configuration */ function createDefaultExtensionsConfig() { return { metadata: { version: '1.0.0', lastUpdated: new Date(), author: 'SupaSeed' }, global: { enabled: true, maxActiveExtensions: 10, loadingTimeout: 30000, hotReload: false }, validation: { enabled: true, rules: { requireMandatoryFields: true, validateCompatibility: true, checkDependencies: true, validateBusinessLogic: true } }, templates: [], extensions: {}, loadOrder: [], conflictResolution: { strategy: 'last_wins' } }; } /** * Extension configuration utilities */ exports.ExtensionConfigUtils = { /** * Merge extension configurations */ mergeConfigs(base, override) { return { ...base, ...override, extensions: { ...base.extensions, ...override.extensions }, templates: [ ...base.templates, ...(override.templates || []) ] }; }, /** * Validate extension ID format */ validateExtensionId(id) { return /^[a-z][a-z0-9_-]*$/.test(id); }, /** * Check version compatibility */ isVersionCompatible(requiredVersion, currentVersion) { // Simple version comparison (in a real implementation, use semver) return currentVersion >= requiredVersion; } }; // Default export exports.default = ExtensionConfigManager; //# sourceMappingURL=extension-config.js.map