xypriss 3.2.3 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/cjs/mods/security/src/utils/memory/config-manager.js +53 -45
  2. package/dist/cjs/mods/security/src/utils/memory/config-manager.js.map +1 -1
  3. package/dist/cjs/src/FiUp.js +5 -2
  4. package/dist/cjs/src/FiUp.js.map +1 -1
  5. package/dist/cjs/src/config.js +169 -0
  6. package/dist/cjs/src/config.js.map +1 -0
  7. package/dist/cjs/src/file-upload.js +25 -5
  8. package/dist/cjs/src/file-upload.js.map +1 -1
  9. package/dist/cjs/src/index.js +3 -2
  10. package/dist/cjs/src/index.js.map +1 -1
  11. package/dist/cjs/src/server/FastServer.js +2 -1
  12. package/dist/cjs/src/server/FastServer.js.map +1 -1
  13. package/dist/cjs/src/server/ServerFactory.js +67 -32
  14. package/dist/cjs/src/server/ServerFactory.js.map +1 -1
  15. package/dist/cjs/src/server/components/fastapi/FileUploadManager.js +1 -1
  16. package/dist/cjs/src/server/components/fastapi/FileUploadManager.js.map +1 -1
  17. package/dist/cjs/src/server/components/fastapi/console/ConsoleInterceptor.js +9 -0
  18. package/dist/cjs/src/server/components/fastapi/console/ConsoleInterceptor.js.map +1 -1
  19. package/dist/esm/mods/security/src/utils/memory/config-manager.js +53 -45
  20. package/dist/esm/mods/security/src/utils/memory/config-manager.js.map +1 -1
  21. package/dist/esm/src/FiUp.js +5 -2
  22. package/dist/esm/src/FiUp.js.map +1 -1
  23. package/dist/esm/src/config.js +167 -0
  24. package/dist/esm/src/config.js.map +1 -0
  25. package/dist/esm/src/file-upload.js +25 -5
  26. package/dist/esm/src/file-upload.js.map +1 -1
  27. package/dist/esm/src/index.js +2 -2
  28. package/dist/esm/src/index.js.map +1 -1
  29. package/dist/esm/src/server/FastServer.js +2 -1
  30. package/dist/esm/src/server/FastServer.js.map +1 -1
  31. package/dist/esm/src/server/ServerFactory.js +67 -32
  32. package/dist/esm/src/server/ServerFactory.js.map +1 -1
  33. package/dist/esm/src/server/components/fastapi/FileUploadManager.js +1 -1
  34. package/dist/esm/src/server/components/fastapi/FileUploadManager.js.map +1 -1
  35. package/dist/esm/src/server/components/fastapi/console/ConsoleInterceptor.js +9 -0
  36. package/dist/esm/src/server/components/fastapi/console/ConsoleInterceptor.js.map +1 -1
  37. package/dist/index.d.ts +104 -33
  38. package/package.json +3 -2
package/dist/index.d.ts CHANGED
@@ -5176,7 +5176,7 @@ declare function createCacheMiddleware(cache: SecureCacheAdapter, options?: Rout
5176
5176
  * Multi-Server App interface for managing multiple server instances
5177
5177
  * Extends UltraFastApp to maintain API compatibility
5178
5178
  */
5179
- interface MultiServerApp extends Omit<UltraFastApp, 'start'> {
5179
+ interface MultiServerApp extends Omit<UltraFastApp, "start"> {
5180
5180
  /**
5181
5181
  * Start all server instances (simple API - hides complexity)
5182
5182
  * @param port - Port parameter (ignored in multi-server mode)
@@ -7436,63 +7436,119 @@ interface FileUploadConfig {
7436
7436
  }
7437
7437
 
7438
7438
  /**
7439
- * File Upload Manager for XyPriss Server
7440
- * Handles multer configuration and file upload middleware setup
7439
+ * XyPriss Configuration Manager
7440
+ *
7441
+ * Provides a safe way to access and update XyPriss configurations
7442
+ * without encountering "cannot access before initialization" errors.
7443
+ *
7444
+ * This class acts as a singleton configuration store that can be used
7445
+ * in modular structures where accessing `app.configs` directly might
7446
+ * cause initialization timing issues.
7447
+ *
7448
+ * @example
7449
+ * ```typescript
7450
+ * import { Configs } from 'xypriss';
7451
+ *
7452
+ * // Set configuration
7453
+ * Configs.set({
7454
+ * fileUpload: {
7455
+ * enabled: true,
7456
+ * maxFileSize: 5 * 1024 * 1024
7457
+ * }
7458
+ * });
7459
+ *
7460
+ * // Get configuration
7461
+ * const fileUploadConfig = Configs.get('fileUpload');
7462
+ *
7463
+ * // Get entire config
7464
+ * const allConfigs = Configs.getAll();
7465
+ *
7466
+ * // Update specific config
7467
+ * Configs.update('fileUpload', { maxFileSize: 10 * 1024 * 1024 });
7468
+ * ```
7441
7469
  */
7442
7470
 
7443
- declare class FileUploadManager {
7444
- private logger;
7471
+ /**
7472
+ * Configuration Manager Class
7473
+ * Singleton pattern for managing XyPriss configurations
7474
+ */
7475
+ declare class ConfigurationManager {
7476
+ private static instance;
7445
7477
  private config;
7446
- private multer;
7447
- private upload;
7448
- constructor(config: FileUploadConfig, logger: Logger);
7478
+ private initialized;
7449
7479
  /**
7450
- * Initialize the file upload manager
7480
+ * Private constructor to enforce singleton pattern
7451
7481
  */
7452
- initialize(): Promise<void>;
7482
+ private constructor();
7453
7483
  /**
7454
- * Create default file filter based on configuration
7484
+ * Get the singleton instance
7455
7485
  */
7456
- private createDefaultFileFilter;
7486
+ private static getInstance;
7457
7487
  /**
7458
- * Get the multer upload instance
7488
+ * Set the entire configuration
7489
+ * @param config - Server configuration options
7459
7490
  */
7460
- getUpload(): any;
7491
+ static set(config: ServerOptions): void;
7461
7492
  /**
7462
- * Get single file upload middleware
7493
+ * Get a specific configuration section
7494
+ * @param key - Configuration key (e.g., 'fileUpload', 'security', 'cache')
7495
+ * @returns The configuration value for the specified key
7463
7496
  */
7464
- single(fieldname: string): any;
7497
+ static get<K extends keyof ServerOptions>(key: K): ServerOptions[K] | undefined;
7465
7498
  /**
7466
- * Get array file upload middleware
7499
+ * Get the entire configuration object
7500
+ * @returns Complete server configuration
7467
7501
  */
7468
- array(fieldname: string, maxCount?: number): any;
7502
+ static getAll(): ServerOptions;
7469
7503
  /**
7470
- * Get fields file upload middleware
7504
+ * Update a specific configuration section
7505
+ * @param key - Configuration key to update
7506
+ * @param value - New value for the configuration section
7471
7507
  */
7472
- fields(fields: any[]): any;
7508
+ static update<K extends keyof ServerOptions>(key: K, value: ServerOptions[K]): void;
7473
7509
  /**
7474
- * Get any file upload middleware
7510
+ * Merge configuration with existing config
7511
+ * @param config - Partial configuration to merge
7475
7512
  */
7476
- any(): any;
7513
+ static merge(config: Partial<ServerOptions>): void;
7477
7514
  /**
7478
- * Get none file upload middleware (for form data without files)
7515
+ * Check if configuration has been initialized
7516
+ * @returns true if configuration has been set, false otherwise
7479
7517
  */
7480
- none(): any;
7518
+ static isInitialized(): boolean;
7481
7519
  /**
7482
- * Check if file upload is enabled
7520
+ * Reset configuration to empty state
7521
+ * Useful for testing or reinitializing
7483
7522
  */
7484
- isEnabled(): boolean;
7523
+ static reset(): void;
7524
+ /**
7525
+ * Check if a specific configuration section exists
7526
+ * @param key - Configuration key to check
7527
+ * @returns true if the configuration section exists
7528
+ */
7529
+ static has<K extends keyof ServerOptions>(key: K): boolean;
7530
+ /**
7531
+ * Get configuration with a default value if not set
7532
+ * @param key - Configuration key
7533
+ * @param defaultValue - Default value to return if key doesn't exist
7534
+ * @returns Configuration value or default value
7535
+ */
7536
+ static getOrDefault<K extends keyof ServerOptions>(key: K, defaultValue: ServerOptions[K]): ServerOptions[K];
7485
7537
  /**
7486
- * Get current configuration
7538
+ * Delete a specific configuration section
7539
+ * @param key - Configuration key to delete
7487
7540
  */
7488
- getConfig(): FileUploadConfig;
7541
+ static delete<K extends keyof ServerOptions>(key: K): void;
7489
7542
  }
7490
7543
 
7491
7544
  /**
7492
7545
  * Initialize the global file upload manager (legacy)
7493
7546
  * This is called automatically when the server starts with file upload enabled
7547
+ *
7548
+ * @param configManager - The Configs class for accessing configuration
7549
+ * @param logger - Logger instance
7494
7550
  */
7495
- declare function initializeFileUpload(options: any, logger: Logger): void;
7551
+ declare function initializeFileUpload(configManager: typeof ConfigurationManager, logger: Logger): void;
7496
7552
  /**
7497
7553
  * Create a middleware for uploading a single file (legacy)
7498
7554
  */
@@ -7541,9 +7597,22 @@ declare class FileUploadAPI {
7541
7597
  private initialized;
7542
7598
  constructor(logger?: Logger);
7543
7599
  /**
7544
- * Initialize the file upload API with configuration
7600
+ * Initialize the file upload API with configuration from Configs
7601
+ *
7602
+ * This method requires the Configs class to enforce a single source of truth.
7603
+ * Configuration is accessed internally from Configs.get('fileUpload').
7604
+ *
7605
+ * @param configManager - The Configs class (not an instance, the class itself)
7606
+ *
7607
+ * @example
7608
+ * ```typescript
7609
+ * import { Configs } from 'xypriss';
7610
+ *
7611
+ * const upload = new FileUploadAPI();
7612
+ * await upload.initialize(Configs);
7613
+ * ```
7545
7614
  */
7546
- initialize(options: any): Promise<void>;
7615
+ initialize(configManager: typeof ConfigurationManager): Promise<void>;
7547
7616
  /**
7548
7617
  * Check if the file upload API is enabled
7549
7618
  */
@@ -7585,6 +7654,8 @@ declare class FileUploadAPI {
7585
7654
  any(): (req: any, res: any, next: any) => any;
7586
7655
  }
7587
7656
 
7657
+ declare const Upload: FileUploadAPI;
7658
+
7588
7659
  interface RouteDefinition {
7589
7660
  method: string;
7590
7661
  path: string;
@@ -12486,5 +12557,5 @@ declare class TrustProxy {
12486
12557
  */
12487
12558
  declare function Router(): XyPrissRouter;
12488
12559
 
12489
- export { CachePlugin as CachePluginBase, CompressionPlugin, ConnectionPlugin, DEFAULT_PLUGIN_CONFIG, FileUploadAPI as FLA, FileUploadManager as FiUp, FileUploadAPI, JWTAuthPlugin, NetworkCategory, NetworkPlugin, NetworkPluginFactory, NetworkPluginUtils, PERFORMANCE_TARGETS, PLUGIN_SYSTEM_NAME, PLUGIN_SYSTEM_VERSION, PerformanceMonitor, PerformancePlugin as PerformancePluginBase, PluginDevelopmentHelpers, PluginEngine, PluginEventType, PluginPriority, PluginRegistry, PluginSystemFactory, PluginSystemUtils, PluginType, ProxyPlugin, RateLimitPlugin, ResponseTimePlugin, Route, Router, SecurityMiddleware, SecurityPlugin as SecurityPluginBase, SmartCachePlugin, TrustProxy, XyPrissRouter, createCacheMiddleware, createCircularRefDebugger, createOptimalCache, createSafeJsonMiddleware, createServer, createServerInstance, expressStringify, fastStringify, initializeFileUpload, quickServer, safeJsonStringify, safeStringify, sendSafeJson, setupSafeJson, uploadAny, uploadArray, uploadFields, uploadSingle };
12490
- export type { BasePlugin, CacheConfig, CachePlugin$1 as CachePlugin, CompressionAlgorithm, CompressionConfig, ConnectionConfig, FailoverConfig, FileUploadConfig as FiUpConfig, HTTPCacheConfig, HealthCheckConfig, CachePlugin$1 as ICachePlugin, PerformancePlugin$1 as IPerformancePlugin, SecurityPlugin$1 as ISecurityPlugin, LoadBalancingStrategy, MultiServerApp, MultiServerConfig, NativePlugin, NetworkExecutionContext, NetworkExecutionResult, NetworkHealthStatus, NetworkPluginConfig, NetworkSecurityConfig, NextFunction, PerformanceConfig, PerformanceMetrics, PerformancePlugin$1 as PerformancePlugin, PluginConfiguration, PluginEvent, PluginExecutionContext, PluginExecutionResult, PluginExecutionStats, PluginInitializationContext, PluginRegistryConfig, ProxyConfig, RateLimitConfig, RateLimitRule, RateLimitStrategy, RedisConfig, XyPrisRequest as Request, RequestHandler, XyPrisResponse as Response, RouteConfig, RouteOptions, SecurityConfig, SecurityPlugin$1 as SecurityPlugin, ServerOptions, SmartRouteConfig, TrustProxyValue$1 as TrustProxyValue, UltraFastApp, UpstreamServer, WebSocketConfig, MultiServerApp as XyPMS, XyPrisRequest as XyPrissRequest, XyPrisResponse as XyPrissResponse };
12560
+ export { CachePlugin as CachePluginBase, CompressionPlugin, ConfigurationManager as Configs, ConnectionPlugin, DEFAULT_PLUGIN_CONFIG, FileUploadAPI as FLA, FileUploadAPI, JWTAuthPlugin, NetworkCategory, NetworkPlugin, NetworkPluginFactory, NetworkPluginUtils, PERFORMANCE_TARGETS, PLUGIN_SYSTEM_NAME, PLUGIN_SYSTEM_VERSION, PerformanceMonitor, PerformancePlugin as PerformancePluginBase, PluginDevelopmentHelpers, PluginEngine, PluginEventType, PluginPriority, PluginRegistry, PluginSystemFactory, PluginSystemUtils, PluginType, ProxyPlugin, RateLimitPlugin, ResponseTimePlugin, Route, Router, SecurityMiddleware, SecurityPlugin as SecurityPluginBase, SmartCachePlugin, TrustProxy, Upload, XyPrissRouter, createCacheMiddleware, createCircularRefDebugger, createOptimalCache, createSafeJsonMiddleware, createServer, createServerInstance, expressStringify, fastStringify, initializeFileUpload, quickServer, safeJsonStringify, safeStringify, sendSafeJson, setupSafeJson, uploadAny, uploadArray, uploadFields, uploadSingle };
12561
+ export type { BasePlugin, CacheConfig, CachePlugin$1 as CachePlugin, CompressionAlgorithm, CompressionConfig, ConnectionConfig, FailoverConfig, FileUploadConfig as FiUpConfig, FileUploadConfig, HTTPCacheConfig, HealthCheckConfig, CachePlugin$1 as ICachePlugin, PerformancePlugin$1 as IPerformancePlugin, SecurityPlugin$1 as ISecurityPlugin, LoadBalancingStrategy, MultiServerApp, MultiServerConfig, NativePlugin, NetworkExecutionContext, NetworkExecutionResult, NetworkHealthStatus, NetworkPluginConfig, NetworkSecurityConfig, NextFunction, PerformanceConfig, PerformanceMetrics, PerformancePlugin$1 as PerformancePlugin, PluginConfiguration, PluginEvent, PluginExecutionContext, PluginExecutionResult, PluginExecutionStats, PluginInitializationContext, PluginRegistryConfig, ProxyConfig, RateLimitConfig, RateLimitRule, RateLimitStrategy, RedisConfig, XyPrisRequest as Request, RequestHandler, XyPrisResponse as Response, RouteConfig, RouteOptions, SecurityConfig, SecurityPlugin$1 as SecurityPlugin, ServerOptions, SmartRouteConfig, TrustProxyValue$1 as TrustProxyValue, UltraFastApp, UpstreamServer, WebSocketConfig, MultiServerApp as XyPMS, XyPrisRequest as XyPrissRequest, XyPrisResponse as XyPrissResponse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xypriss",
3
- "version": "3.2.3",
3
+ "version": "3.3.1",
4
4
  "description": "XyPriss is a lightweight, TypeScript-first, open-source Node.js web framework crafted for developers seeking a familiar Express-like API without Express dependencies. It features built-in security middleware, a robust routing system, and performance optimizations to build scalable, secure web applications effortlessly. Join our community and contribute on GitHub!",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -25,7 +25,8 @@
25
25
  "test": "jest",
26
26
  "test:watch": "jest --watch",
27
27
  "test:coverage": "jest --coverage",
28
- "benchmark": "node benchmarks/index.js"
28
+ "benchmark": "node benchmarks/index.js",
29
+ "prepublishOnly": "npm run build"
29
30
  },
30
31
  "exports": {
31
32
  ".": {