userface
Version:
Universal Data-Driven UI Engine with live data, validation, and multi-platform support
71 lines (70 loc) • 3.14 kB
JavaScript
;
/**
* Node.js совместимая версия Engine
* Убирает зависимости от React и браузерных API
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeEngine = exports.NodeEngine = void 0;
const engine_1 = require("./engine");
const component_registry_1 = require("./component-registry");
const data_layer_1 = require("./data-layer");
const plugin_system_1 = require("./plugin-system");
const validation_1 = require("./validation");
const error_recovery_1 = require("./error-recovery");
const testing_infrastructure_1 = require("../testing-infrastructure");
const lifecycle_manager_1 = require("./lifecycle-manager");
const event_bus_1 = require("./event-bus");
// Node.js совместимый Logger
class NodeLogger {
info(message, context, data) {
console.log(`[INFO] ${context ? `[${context}]` : ''} ${message}`, data || '');
}
warn(message, context, data) {
console.warn(`[WARN] ${context ? `[${context}]` : ''} ${message}`, data || '');
}
error(message, context, data) {
console.error(`[ERROR] ${context ? `[${context}]` : ''} ${message}`, data || '');
}
debug(message, context, data) {
console.debug(`[DEBUG] ${context ? `[${context}]` : ''} ${message}`, data || '');
}
}
// Node.js совместимый Engine
class NodeEngine extends engine_1.Engine {
constructor() {
const logger = new NodeLogger();
const componentStore = new component_registry_1.ComponentRegistry();
const dataService = new data_layer_1.DataLayer();
const pluginManager = new plugin_system_1.PluginSystem(componentStore);
const validator = new validation_1.ValidationEngine();
const errorHandler = new error_recovery_1.ErrorRecovery();
const testRunner = new testing_infrastructure_1.TestingInfrastructure();
const lifecycle = new lifecycle_manager_1.LifecycleManager();
const events = new event_bus_1.EventBus();
super(componentStore, dataService, pluginManager, validator, errorHandler, testRunner, logger);
}
// Переопределяем методы которые требуют браузерные API
async render(userFace, adapterId) {
try {
// В Node.js просто возвращаем данные компонента
const component = this.getComponent(userFace.component);
if (!component) {
throw new Error(`Component not found: ${userFace.component}`);
}
return {
component: userFace.component,
props: userFace,
adapterId,
timestamp: Date.now(),
environment: 'node'
};
}
catch (error) {
console.error('Render error:', error);
return { error: error instanceof Error ? error.message : String(error), environment: 'node' };
}
}
}
exports.NodeEngine = NodeEngine;
// Создаем глобальный экземпляр для Node.js
exports.nodeEngine = new NodeEngine();