@adaas/a-server 0.0.20 → 0.0.22

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.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A_Component, A_Fragment, A_Error, A_TYPES__Entity_Serialized, A_TYPES__Error_Init, A_TYPES__Error_Serialized, A_Entity, A_Scope, A_Container, ASEID, A_TYPES__ComponentMeta } from '@adaas/a-concept';
2
- import { A_Channel, A_Logger, A_Config } from '@adaas/a-utils';
2
+ import { A_Channel, A_Logger, A_Config, A_Polyfill } from '@adaas/a-utils';
3
3
  import * as http from 'http';
4
4
  import { IncomingMessage, IncomingHttpHeaders, ServerResponse } from 'http';
5
5
  import { A_TYPES__Required } from '@adaas/a-concept/dist/src/types/A_Common.types';
@@ -299,7 +299,7 @@ declare class A_Service extends A_Container {
299
299
  req: A_Request;
300
300
  res: A_Response;
301
301
  }>;
302
- protected generateRequestId(method: string, url: string): string;
302
+ protected generateRequestId(method: string, url: string): Promise<string>;
303
303
  beforeStop(): Promise<void>;
304
304
  afterStop(): Promise<void>;
305
305
  }
@@ -370,16 +370,100 @@ declare class A_ProxyConfig extends A_Fragment {
370
370
  config(path: string): A_SERVER_TYPES__RoutesConfig | undefined;
371
371
  }
372
372
 
373
+ interface A_StaticAlias {
374
+ alias: string;
375
+ path: string;
376
+ directory: string;
377
+ enabled?: boolean;
378
+ }
379
+ interface A_StaticDirectoryConfig {
380
+ path: string;
381
+ directory: string;
382
+ alias?: string;
383
+ }
373
384
  declare class A_StaticConfig extends A_Fragment {
374
385
  readonly directories: Array<string>;
386
+ private _aliases;
387
+ private _directoryConfigs;
375
388
  constructor(
376
389
  /**
377
390
  * Setup directories to serve static files from, comma separated
378
391
  */
379
- directories?: string[]);
392
+ directories?: string[],
380
393
  /**
381
- * Checks if a given path is configured in the proxy
382
- *
394
+ * Custom directory configurations with aliases
395
+ */
396
+ directoryConfigs?: A_StaticDirectoryConfig[]);
397
+ private initializeDefaultAliases;
398
+ private initializeCustomAliases;
399
+ /**
400
+ * Add a custom static file alias
401
+ * @param alias - The URL path alias (e.g., '/assets')
402
+ * @param directory - The local directory path
403
+ * @param path - Optional custom path (defaults to alias)
404
+ */
405
+ addAlias(alias: string, directory: string, path?: string): void;
406
+ /**
407
+ * Remove a static file alias
408
+ * @param aliasPath - The path of the alias to remove
409
+ */
410
+ removeAlias(aliasPath: string): boolean;
411
+ /**
412
+ * Enable or disable an alias
413
+ * @param aliasPath - The path of the alias
414
+ * @param enabled - Whether to enable or disable
415
+ */
416
+ setAliasEnabled(aliasPath: string, enabled: boolean): boolean;
417
+ /**
418
+ * Get all configured aliases
419
+ */
420
+ getAliases(): A_StaticAlias[];
421
+ /**
422
+ * Get enabled aliases only
423
+ */
424
+ getEnabledAliases(): A_StaticAlias[];
425
+ /**
426
+ * Find the best matching alias for a given request path
427
+ * @param requestPath - The request path to match
428
+ */
429
+ findMatchingAlias(requestPath: string): A_StaticAlias | null;
430
+ /**
431
+ * Check if an alias exists
432
+ * @param aliasPath - The path to check
433
+ */
434
+ hasAlias(aliasPath: string): boolean;
435
+ /**
436
+ * Get a specific alias by path
437
+ * @param aliasPath - The path of the alias
438
+ */
439
+ getAlias(aliasPath: string): A_StaticAlias | undefined;
440
+ /**
441
+ * Add multiple aliases at once
442
+ * @param aliases - Array of alias configurations
443
+ */
444
+ addAliases(aliases: A_StaticDirectoryConfig[]): void;
445
+ /**
446
+ * Clear all aliases
447
+ */
448
+ clearAliases(): void;
449
+ /**
450
+ * Update an existing alias
451
+ * @param aliasPath - The path of the alias to update
452
+ * @param updates - Partial updates to apply
453
+ */
454
+ updateAlias(aliasPath: string, updates: Partial<A_StaticAlias>): boolean;
455
+ /**
456
+ * Get statistics about configured aliases
457
+ */
458
+ getStats(): {
459
+ total: number;
460
+ enabled: number;
461
+ disabled: number;
462
+ directories: string[];
463
+ };
464
+ /**
465
+ * Checks if a given path is configured in the proxy (legacy method)
466
+ * @deprecated Use findMatchingAlias instead
383
467
  * @param path
384
468
  * @returns
385
469
  */
@@ -679,7 +763,7 @@ declare class A_ServerHealthMonitor extends A_Component {
679
763
 
680
764
  declare class A_ServerProxy extends A_Component {
681
765
  load(logger: A_Logger, config: A_ProxyConfig): Promise<void>;
682
- onRequest(req: A_Request, res: A_Response, proxyConfig: A_ProxyConfig, logger: A_Logger): Promise<void>;
766
+ onRequest(req: A_Request, res: A_Response, proxyConfig: A_ProxyConfig, logger: A_Logger, polyfill: A_Polyfill): Promise<void>;
683
767
  }
684
768
 
685
769
  declare class A_ServerCORS extends A_Component {
@@ -689,11 +773,43 @@ declare class A_ServerCORS extends A_Component {
689
773
  }
690
774
 
691
775
  declare class A_StaticLoader extends A_Component {
692
- load(logger: A_Logger, config: A_StaticConfig): Promise<void>;
693
- onRequest(req: A_Request, res: A_Response, logger: A_Logger, config: A_StaticConfig): Promise<void>;
776
+ private _fsPolyfill;
777
+ private _pathPolyfill;
778
+ load(logger: A_Logger, config: A_StaticConfig, polyfill: A_Polyfill): Promise<void>;
779
+ onRequest(req: A_Request, res: A_Response, logger: A_Logger, config: A_StaticConfig, polyfill: A_Polyfill): Promise<void>;
780
+ /**
781
+ * Add a custom static file alias through the config
782
+ * @param alias - The URL path alias (e.g., '/assets')
783
+ * @param directory - The local directory path
784
+ * @param path - Optional custom path (defaults to alias)
785
+ * @param config - Static config instance
786
+ * @param logger - Logger instance for logging
787
+ */
788
+ addAlias(alias: string, directory: string, config: A_StaticConfig, logger?: A_Logger, path?: string): void;
789
+ /**
790
+ * Remove a static file alias through the config
791
+ * @param aliasPath - The path of the alias to remove
792
+ * @param config - Static config instance
793
+ * @param logger - Logger instance for logging
794
+ */
795
+ removeAlias(aliasPath: string, config: A_StaticConfig, logger?: A_Logger): boolean;
796
+ /**
797
+ * Get all configured aliases from config
798
+ * @param config - Static config instance
799
+ */
800
+ getAliases(config: A_StaticConfig): A_StaticAlias[];
801
+ /**
802
+ * Enable or disable an alias
803
+ * @param aliasPath - The path of the alias
804
+ * @param enabled - Whether to enable or disable
805
+ * @param config - Static config instance
806
+ * @param logger - Logger instance for logging
807
+ */
808
+ setAliasEnabled(aliasPath: string, enabled: boolean, config: A_StaticConfig, logger?: A_Logger): boolean;
694
809
  protected getMimeType(ext: string): string;
695
- protected safeFilePath(staticDir: string, reqUrl: string, host?: string): string;
696
- protected serveFile(filePath: string, res: A_Response): Promise<void>;
810
+ protected safeFilePath(staticDir: string, reqUrl: string, host: string | undefined, pathPolyfill: any, fsPolyfill: any): string;
811
+ protected serveFile(filePath: string, res: A_Response, logger: A_Logger, fsPolyfill: any, pathPolyfill: any): Promise<void>;
812
+ protected getCacheControl(ext: string): string;
697
813
  }
698
814
 
699
815
  declare class A_Controller extends A_Component {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A_Component, A_Fragment, A_Error, A_TYPES__Entity_Serialized, A_TYPES__Error_Init, A_TYPES__Error_Serialized, A_Entity, A_Scope, A_Container, ASEID, A_TYPES__ComponentMeta } from '@adaas/a-concept';
2
- import { A_Channel, A_Logger, A_Config } from '@adaas/a-utils';
2
+ import { A_Channel, A_Logger, A_Config, A_Polyfill } from '@adaas/a-utils';
3
3
  import * as http from 'http';
4
4
  import { IncomingMessage, IncomingHttpHeaders, ServerResponse } from 'http';
5
5
  import { A_TYPES__Required } from '@adaas/a-concept/dist/src/types/A_Common.types';
@@ -299,7 +299,7 @@ declare class A_Service extends A_Container {
299
299
  req: A_Request;
300
300
  res: A_Response;
301
301
  }>;
302
- protected generateRequestId(method: string, url: string): string;
302
+ protected generateRequestId(method: string, url: string): Promise<string>;
303
303
  beforeStop(): Promise<void>;
304
304
  afterStop(): Promise<void>;
305
305
  }
@@ -370,16 +370,100 @@ declare class A_ProxyConfig extends A_Fragment {
370
370
  config(path: string): A_SERVER_TYPES__RoutesConfig | undefined;
371
371
  }
372
372
 
373
+ interface A_StaticAlias {
374
+ alias: string;
375
+ path: string;
376
+ directory: string;
377
+ enabled?: boolean;
378
+ }
379
+ interface A_StaticDirectoryConfig {
380
+ path: string;
381
+ directory: string;
382
+ alias?: string;
383
+ }
373
384
  declare class A_StaticConfig extends A_Fragment {
374
385
  readonly directories: Array<string>;
386
+ private _aliases;
387
+ private _directoryConfigs;
375
388
  constructor(
376
389
  /**
377
390
  * Setup directories to serve static files from, comma separated
378
391
  */
379
- directories?: string[]);
392
+ directories?: string[],
380
393
  /**
381
- * Checks if a given path is configured in the proxy
382
- *
394
+ * Custom directory configurations with aliases
395
+ */
396
+ directoryConfigs?: A_StaticDirectoryConfig[]);
397
+ private initializeDefaultAliases;
398
+ private initializeCustomAliases;
399
+ /**
400
+ * Add a custom static file alias
401
+ * @param alias - The URL path alias (e.g., '/assets')
402
+ * @param directory - The local directory path
403
+ * @param path - Optional custom path (defaults to alias)
404
+ */
405
+ addAlias(alias: string, directory: string, path?: string): void;
406
+ /**
407
+ * Remove a static file alias
408
+ * @param aliasPath - The path of the alias to remove
409
+ */
410
+ removeAlias(aliasPath: string): boolean;
411
+ /**
412
+ * Enable or disable an alias
413
+ * @param aliasPath - The path of the alias
414
+ * @param enabled - Whether to enable or disable
415
+ */
416
+ setAliasEnabled(aliasPath: string, enabled: boolean): boolean;
417
+ /**
418
+ * Get all configured aliases
419
+ */
420
+ getAliases(): A_StaticAlias[];
421
+ /**
422
+ * Get enabled aliases only
423
+ */
424
+ getEnabledAliases(): A_StaticAlias[];
425
+ /**
426
+ * Find the best matching alias for a given request path
427
+ * @param requestPath - The request path to match
428
+ */
429
+ findMatchingAlias(requestPath: string): A_StaticAlias | null;
430
+ /**
431
+ * Check if an alias exists
432
+ * @param aliasPath - The path to check
433
+ */
434
+ hasAlias(aliasPath: string): boolean;
435
+ /**
436
+ * Get a specific alias by path
437
+ * @param aliasPath - The path of the alias
438
+ */
439
+ getAlias(aliasPath: string): A_StaticAlias | undefined;
440
+ /**
441
+ * Add multiple aliases at once
442
+ * @param aliases - Array of alias configurations
443
+ */
444
+ addAliases(aliases: A_StaticDirectoryConfig[]): void;
445
+ /**
446
+ * Clear all aliases
447
+ */
448
+ clearAliases(): void;
449
+ /**
450
+ * Update an existing alias
451
+ * @param aliasPath - The path of the alias to update
452
+ * @param updates - Partial updates to apply
453
+ */
454
+ updateAlias(aliasPath: string, updates: Partial<A_StaticAlias>): boolean;
455
+ /**
456
+ * Get statistics about configured aliases
457
+ */
458
+ getStats(): {
459
+ total: number;
460
+ enabled: number;
461
+ disabled: number;
462
+ directories: string[];
463
+ };
464
+ /**
465
+ * Checks if a given path is configured in the proxy (legacy method)
466
+ * @deprecated Use findMatchingAlias instead
383
467
  * @param path
384
468
  * @returns
385
469
  */
@@ -679,7 +763,7 @@ declare class A_ServerHealthMonitor extends A_Component {
679
763
 
680
764
  declare class A_ServerProxy extends A_Component {
681
765
  load(logger: A_Logger, config: A_ProxyConfig): Promise<void>;
682
- onRequest(req: A_Request, res: A_Response, proxyConfig: A_ProxyConfig, logger: A_Logger): Promise<void>;
766
+ onRequest(req: A_Request, res: A_Response, proxyConfig: A_ProxyConfig, logger: A_Logger, polyfill: A_Polyfill): Promise<void>;
683
767
  }
684
768
 
685
769
  declare class A_ServerCORS extends A_Component {
@@ -689,11 +773,43 @@ declare class A_ServerCORS extends A_Component {
689
773
  }
690
774
 
691
775
  declare class A_StaticLoader extends A_Component {
692
- load(logger: A_Logger, config: A_StaticConfig): Promise<void>;
693
- onRequest(req: A_Request, res: A_Response, logger: A_Logger, config: A_StaticConfig): Promise<void>;
776
+ private _fsPolyfill;
777
+ private _pathPolyfill;
778
+ load(logger: A_Logger, config: A_StaticConfig, polyfill: A_Polyfill): Promise<void>;
779
+ onRequest(req: A_Request, res: A_Response, logger: A_Logger, config: A_StaticConfig, polyfill: A_Polyfill): Promise<void>;
780
+ /**
781
+ * Add a custom static file alias through the config
782
+ * @param alias - The URL path alias (e.g., '/assets')
783
+ * @param directory - The local directory path
784
+ * @param path - Optional custom path (defaults to alias)
785
+ * @param config - Static config instance
786
+ * @param logger - Logger instance for logging
787
+ */
788
+ addAlias(alias: string, directory: string, config: A_StaticConfig, logger?: A_Logger, path?: string): void;
789
+ /**
790
+ * Remove a static file alias through the config
791
+ * @param aliasPath - The path of the alias to remove
792
+ * @param config - Static config instance
793
+ * @param logger - Logger instance for logging
794
+ */
795
+ removeAlias(aliasPath: string, config: A_StaticConfig, logger?: A_Logger): boolean;
796
+ /**
797
+ * Get all configured aliases from config
798
+ * @param config - Static config instance
799
+ */
800
+ getAliases(config: A_StaticConfig): A_StaticAlias[];
801
+ /**
802
+ * Enable or disable an alias
803
+ * @param aliasPath - The path of the alias
804
+ * @param enabled - Whether to enable or disable
805
+ * @param config - Static config instance
806
+ * @param logger - Logger instance for logging
807
+ */
808
+ setAliasEnabled(aliasPath: string, enabled: boolean, config: A_StaticConfig, logger?: A_Logger): boolean;
694
809
  protected getMimeType(ext: string): string;
695
- protected safeFilePath(staticDir: string, reqUrl: string, host?: string): string;
696
- protected serveFile(filePath: string, res: A_Response): Promise<void>;
810
+ protected safeFilePath(staticDir: string, reqUrl: string, host: string | undefined, pathPolyfill: any, fsPolyfill: any): string;
811
+ protected serveFile(filePath: string, res: A_Response, logger: A_Logger, fsPolyfill: any, pathPolyfill: any): Promise<void>;
812
+ protected getCacheControl(ext: string): string;
697
813
  }
698
814
 
699
815
  declare class A_Controller extends A_Component {