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.

213 lines (208 loc) 9.21 kB
'use strict'; var fortifiedFunctionCore = require('./core/fortified-function-core.js'); require('./core/fortified-config.js'); require('./core/fortified-logger.js'); require('events'); require('../../integrations/express/cache/CacheFactory.js'); var safeSerializer = require('./serializer/safe-serializer.js'); require('nehoid'); require('../../utils/memory/index.js'); require('crypto'); require('../../types/secure-memory.js'); require('../secure-string/advanced/entropy-analyzer.js'); require('../secure-string/advanced/quantum-safe.js'); require('../secure-string/advanced/performance-monitor.js'); require('../../core/hash/hash-core.js'); require('../../core/hash/hash-types.js'); require('../../core/hash/hash-security.js'); require('../../core/hash/hash-advanced.js'); require('../../algorithms/hash-algorithms.js'); require('../../core/random/random-types.js'); require('../../core/random/random-sources.js'); require('nehonix-uri-processor'); require('../../types.js'); require('../secure-array/utils/id-generator.js'); require('../../integrations/express/server/utils/Logger.js'); require('argon2'); require('child_process'); require('https'); require('../runtime-verification.js'); require('../tamper-evident-logging.js'); require('../../core/keys/keys-types.js'); require('../../core/keys/keys-logger.js'); require('../../core/keys/keys-utils.js'); require('../../core/keys/algorithms/mods/PBKDF2Algo.js'); require('../../core/password/index.js'); var ultraFastAllocator = require('./UFA/ultra-fast-allocator.js'); /*************************************************************************** * FortifyJS - Secure Array Types * * This file contains type definitions for the SecureArrayarchitecture * * @author Nehonix * @license MIT * * Copyright (c) 2025 Nehonix. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ***************************************************************************** */ // Export main optimized class from modular system (migrated to minimal architecture) /** * Zero-Configuration Smart Function Factory - EXTREME PERFORMANCE EDITION * * Creates ultra-fast fortified functions with enterprise-grade security, * extreme performance optimization, and intelligent caching enabled by default. * Optimized for sub-millisecond execution times while maintaining security. * * @param fn - The function to be fortified with extreme performance capabilities * @param options - Optional configuration overrides (performance-first defaults) * @returns A fortified function with extreme performance and security features * * @example * ```typescript * import { func } from 'fortify2-js'; * * // Zero configuration needed - extreme performance enabled by default * const ultraFastFunction = func(async (data: string) => { * return processData(data); * }); * * // Execute with sub-millisecond performance * const result = await ultraFastFunction('sensitive data'); * * // Optional: Override specific settings if needed * const customFunction = func(myFunction, { * ultraFast: "maximum", * maxCacheSize: 10000, * enableJIT: true * }); * * * const syncFn = func((x: number) => x * 2); // Returns number * syncFn(5).toFixed(2); // Type inference works! * const asyncFn = func(async (x: number) => x * 2); // Returns Promise<number> * asyncFn(5).then((result) => result.toFixed(2)); // Type inference works! * * ``` */ function func(fn, options = {}) { // Use the optimized modular system const fortifiedFunction = fortifiedFunctionCore.FortifiedFunctionCore.create(fn, { // EXTREME PERFORMANCE DEFAULTS ultraFast: "maximum", autoEncrypt: false, // Disabled for maximum speed, enable if needed smartCaching: true, predictiveAnalytics: false, // Disabled for speed, enable for analytics detailedMetrics: false, // Disabled for speed, enable for monitoring enableJIT: true, // NEW: Enable JIT compilation enableSIMD: true, // NEW: Enable SIMD optimizations enableWebAssembly: true, // NEW: Enable WebAssembly acceleration memoryOptimization: "aggressive", // NEW: Aggressive memory optimization cacheStrategy: "adaptive", // Adaptive caching for best performance maxCacheSize: 5000, // Larger cache for better hit rates cacheTTL: 600000, // 10 minutes for better cache utilization ...options, }); const enhancedFunc = ((...args) => { return fortifiedFunction.execute(...args); }); Object.assign(enhancedFunc, { getStats: () => fortifiedFunction.getStats(), getAnalyticsData: () => fortifiedFunction.getAnalyticsData(), getOptimizationSuggestions: () => fortifiedFunction.getOptimizationSuggestions(), getPerformanceTrends: () => fortifiedFunction.getPerformanceTrends(), detectAnomalies: () => fortifiedFunction.detectAnomalies(), getDetailedMetrics: () => fortifiedFunction.getDetailedMetrics(), clearCache: () => fortifiedFunction.clearCache(), getCacheStats: () => ({ hits: fortifiedFunction.getStats().cacheHits, misses: fortifiedFunction.getStats().cacheMisses, size: fortifiedFunction.getCacheStats().size || 0, }), warmCache: async (args) => { for (const argSet of args) { await fortifiedFunction.execute(...argSet); } }, handleMemoryPressure: (level) => fortifiedFunction.handleMemoryPressure(level), optimizePerformance: () => { fortifiedFunction.warmCache(); const suggestions = fortifiedFunction.getOptimizationSuggestions(); suggestions .filter((s) => s.priority === "high" || s.priority === "critical") .forEach(() => fortifiedFunction.warmCache()); }, updateOptions: (newOptions) => fortifiedFunction.updateOptions(newOptions), getConfiguration: () => ({ ...options }), startTimer: (label, metadata) => fortifiedFunction.startTimer(label, metadata), endTimer: (label, additionalMetadata) => fortifiedFunction.endTimer(label, additionalMetadata), measureDelay: (startPoint, endPoint) => fortifiedFunction.measureDelay(startPoint, endPoint), timeFunction: (label, fn, metadata) => fortifiedFunction.timeFunction(label, fn, metadata), getTimingStats: () => fortifiedFunction.getTimingStats(), clearTimings: () => fortifiedFunction.clearTimings(), _fortified: fortifiedFunction, }); return enhancedFunc; } /** * Create a fortified function with full access to smart analytics and optimization * Provides complete access to performance metrics, analytics, and optimization features * * @example * ```typescript * import { createFortifiedFunction } from 'fortify2-js'; * * const fortified = createFortifiedFunction(myFunction, { * autoEncrypt: true, * smartCaching: true, * predictiveAnalytics: true, * detailedMetrics: true * }); * * // Execute * const result = await fortified.execute('data'); * * // Access enhanced analytics * const analytics = fortified.getAnalyticsData(); * const suggestions = fortified.getOptimizationSuggestions(); * const trends = fortified.getPerformanceTrends(); * const anomalies = fortified.detectAnomalies(); * * // Smart actions * fortified.warmCache(); * fortified.handleMemoryPressure('medium'); * * // Get comprehensive metrics * const detailedMetrics = fortified.getDetailedMetrics(); * * // Clean up when done * fortified.destroy(); * ``` */ function createFortifiedFunction(fn, options = {}) { return fortifiedFunctionCore.FortifiedFunctionCore.create(fn, options); } exports.FortifiedFunctionCore = fortifiedFunctionCore.FortifiedFunctionCore; exports.OptimizedFortifiedFunction = fortifiedFunctionCore.FortifiedFunctionCore; exports.generateSafeCacheKey = safeSerializer.generateSafeCacheKey; exports.UltraFastAllocator = ultraFastAllocator.UltraFastAllocator; exports.createFortifiedFunction = createFortifiedFunction; exports.default = func; exports.func = func; //# sourceMappingURL=index.js.map