UNPKG

fortify2-js

Version:

MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.

188 lines (185 loc) 5.75 kB
import { fortifiedLogger } from '../fortified-logger.js'; /** * API Manager - Handles all public API methods for the core * Part of the minimal modular architecture */ class ApiManager { constructor(functionId, statsManager, cacheManager, performanceMonitor, ultraFastCache, timingManager, options) { this.executionCount = 0; this.functionId = functionId; this.statsManager = statsManager; this.cacheManager = cacheManager; this.performanceMonitor = performanceMonitor; this.ultraFastCache = ultraFastCache; this.timingManager = timingManager; this.options = options; } /** * Update execution count */ incrementExecutionCount() { this.executionCount++; } /** * Get function statistics (combining both existing and new stats) */ getStats() { const existingStats = this.statsManager.getStats(); const performanceStats = this.performanceMonitor.getStats(); return { ...existingStats, ...performanceStats, executionCount: this.executionCount, functionId: this.functionId, timingStats: this.timingManager.getTimingStats(), }; } /** * Get audit log (combining both systems) */ getAuditLog() { const existingAudit = this.statsManager.getAuditLog(); const performanceAudit = this.performanceMonitor.getAuditLog(); return [...existingAudit, ...performanceAudit]; } /** * Get cache statistics */ getCacheStats() { return this.performanceMonitor.getCacheStats(); } /** * Clear cache (both systems) */ clearCache() { this.cacheManager.clearCache(); this.performanceMonitor.clearCache(); this.ultraFastCache.clear(); fortifiedLogger.info("CACHE", `Cache cleared for function: ${this.functionId}`); } /** * Get analytics data */ getAnalyticsData() { return this.performanceMonitor.getAnalyticsData(); } /** * Get optimization suggestions */ getOptimizationSuggestions() { return this.performanceMonitor.getOptimizationSuggestions(); } /** * Get performance trends */ getPerformanceTrends() { return this.performanceMonitor.getPerformanceTrends(); } /** * Detect anomalies */ detectAnomalies() { if (this.options.anomalyDetection) { const auditLog = this.performanceMonitor.getAuditLog(); const latestEntry = auditLog[auditLog.length - 1]; if (latestEntry) { return this.performanceMonitor.detectAnomalies(latestEntry); } } return []; } /** * Warm cache */ warmCache() { if (this.options.smartCaching) { this.performanceMonitor.warmCache(); } } /** * Handle memory pressure */ handleMemoryPressure(level) { if (this.options.memoryPressureHandling) { this.performanceMonitor.handleMemoryPressure(level); } } /** * Get detailed metrics */ getDetailedMetrics(globalMetrics) { if (!this.options.detailedMetrics) return null; return { stats: this.getStats(), cacheStats: this.getCacheStats(), analytics: this.getAnalyticsData(), suggestions: this.getOptimizationSuggestions(), trends: this.getPerformanceTrends(), anomalies: this.detectAnomalies(), functionId: this.functionId, globalMetrics, }; } /** * Auto-apply optimizations */ autoApplyOptimizations() { if (this.options.autoTuning) { const cacheStats = this.getCacheStats(); if (cacheStats.hitRate < 0.5 && this.options.maxCacheSize < 5000) { this.options.maxCacheSize = Math.min(this.options.maxCacheSize * 1.5, 5000); return true; // Optimization applied } } return false; // No optimization applied } /** * Clear audit log */ clearAuditLog() { this.statsManager.clearAuditLog?.(); this.performanceMonitor.clearAuditLog?.(); fortifiedLogger.info("AUDIT", `Audit log cleared for function: ${this.functionId}`); } /** * Get active executions count */ getActiveExecutionsCount() { return this.executionCount; // Simple implementation using current execution count } /** * Get ultra-fast component metrics */ getUltraFastMetrics() { return { cacheSize: this.ultraFastCache.size, cacheHitRate: this.getCacheStats().hitRate, functionId: this.functionId, executionCount: this.executionCount, }; } /** * Optimize performance by applying recommended settings */ optimizePerformance() { const suggestions = this.getOptimizationSuggestions(); let optimizationsApplied = 0; for (const suggestion of suggestions) { if (suggestion.priority === "high" || suggestion.priority === "critical") { this.autoApplyOptimizations(); optimizationsApplied++; } } fortifiedLogger.info("OPTIMIZATION", `Applied ${optimizationsApplied} performance optimizations for function: ${this.functionId}`); } /** * Cleanup resources */ destroy() { fortifiedLogger.debug("API", `API manager destroyed for function: ${this.functionId}`); } } export { ApiManager }; //# sourceMappingURL=api-manager.js.map