UNPKG

userface

Version:

Universal Data-Driven UI Engine with live data, validation, and multi-platform support

162 lines (161 loc) 6.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.componentRegistry = exports.ComponentRegistry = void 0; const real_ast_analyzer_1 = require("./real-ast-analyzer"); console.log('[REGISTRY] Component registry loaded'); class ComponentRegistry { constructor() { Object.defineProperty(this, "components", { enumerable: true, configurable: true, writable: true, value: new Map() }); Object.defineProperty(this, "analyzers", { enumerable: true, configurable: true, writable: true, value: new Map() }); console.log('[REGISTRY] ComponentRegistry constructed'); // Регистрируем анализатор по умолчанию this.registerAnalyzer('default', real_ast_analyzer_1.realASTAnalyzer); } async registerComponent(name, component, metadata) { console.log('[REGISTRY] Registering component:', name); try { // Анализируем компонент для получения схемы const schema = await real_ast_analyzer_1.realASTAnalyzer.analyzeComponent(component, name); // Объединяем с переданными метаданными const finalSchema = { ...schema, ...metadata }; const registration = { name, component, schema: finalSchema, registeredAt: new Date(), version: '1.0.0' }; this.components.set(name, registration); console.log('[REGISTRY] Component registered successfully:', name); } catch (error) { console.error('[REGISTRY] Error registering component:', error); throw error; } } getComponent(name) { return this.components.get(name); } getAllComponents() { return Array.from(this.components.values()); } async updateComponent(name, component, metadata) { console.log('[REGISTRY] Updating component:', name); if (!this.components.has(name)) { throw new Error(`Component ${name} not found`); } try { // Анализируем обновленный компонент const newSchema = await real_ast_analyzer_1.realASTAnalyzer.analyzeComponent(component, name); // Объединяем с переданными метаданными const finalSchema = { ...newSchema, ...metadata }; const existing = this.components.get(name); const updatedRegistration = { ...existing, component, schema: finalSchema, registeredAt: new Date() }; this.components.set(name, updatedRegistration); console.log('[REGISTRY] Component updated successfully:', name); } catch (error) { console.error('[REGISTRY] Error updating component:', error); throw error; } } removeComponent(name) { console.log('[REGISTRY] Removing component:', name); return this.components.delete(name); } hasComponent(name) { return this.components.has(name); } getComponentCount() { return this.components.size; } clear() { console.log('[REGISTRY] Clearing all components'); this.components.clear(); } // Методы для работы с анализаторами registerAnalyzer(name, analyzer) { console.log('[REGISTRY] Registering analyzer:', name); this.analyzers.set(name, analyzer); } getAnalyzer(name) { return this.analyzers.get(name) || this.analyzers.get('default'); } async analyzeComponent(component, name, analyzerName) { console.log('[REGISTRY] Analyzing component:', name, 'with analyzer:', analyzerName || 'default'); const analyzer = analyzerName ? this.getAnalyzer(analyzerName) : this.getAnalyzer('default'); if (!analyzer) { throw new Error('No analyzer available'); } return await real_ast_analyzer_1.realASTAnalyzer.analyzeComponent(component, name); } // Методы для поиска компонентов findComponentsByPlatform(platform) { return this.getAllComponents().filter(reg => reg.schema.detectedPlatform === platform); } findComponentsByType(type) { return this.getAllComponents().filter(reg => reg.schema.props.some(prop => prop.type === type)); } findComponentsByName(pattern) { const regex = new RegExp(pattern, 'i'); return this.getAllComponents().filter(reg => regex.test(reg.name)); } // Методы для экспорта/импорта exportRegistry() { return this.getAllComponents(); } importRegistry(registrations) { console.log('[REGISTRY] Importing registry with', registrations.length, 'components'); for (const registration of registrations) { this.components.set(registration.name, registration); } } // Методы для статистики getStatistics() { const components = this.getAllComponents(); const platforms = {}; const types = {}; let totalProps = 0; let totalEvents = 0; for (const reg of components) { const platform = reg.schema.detectedPlatform; platforms[platform] = (platforms[platform] || 0) + 1; for (const prop of reg.schema.props) { types[prop.type] = (types[prop.type] || 0) + 1; totalProps++; } totalEvents += reg.schema.events.length; } return { totalComponents: components.length, platforms, types, averageProps: components.length > 0 ? totalProps / components.length : 0, averageEvents: components.length > 0 ? totalEvents / components.length : 0 }; } } exports.ComponentRegistry = ComponentRegistry; // Создаем глобальный экземпляр реестра exports.componentRegistry = new ComponentRegistry();