@navios/core 1.0.0-alpha.2 → 1.0.0-alpha.4
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/CHANGELOG.md +90 -0
- package/lib/{index-BJjk2X1S.d.mts → index-6S7veHKD.d.mts} +845 -294
- package/lib/index-6S7veHKD.d.mts.map +1 -0
- package/lib/{index-DZ6NU03y.d.cts → index-r0i2txmg.d.cts} +845 -294
- package/lib/index-r0i2txmg.d.cts.map +1 -0
- package/lib/index.cjs +4420 -84
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +4328 -3
- package/lib/index.mjs.map +1 -0
- package/lib/legacy-compat/index.cjs +41 -126
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +4 -60
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +4 -60
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +14 -119
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/navios.factory-BanZIvtR.cjs +4134 -0
- package/lib/navios.factory-BanZIvtR.cjs.map +1 -0
- package/lib/navios.factory-C75yZCoD.mjs +3831 -0
- package/lib/navios.factory-C75yZCoD.mjs.map +1 -0
- package/lib/testing/index.cjs +3 -3
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +1 -1
- package/lib/testing/index.d.mts +1 -1
- package/lib/testing/index.mjs +2 -2
- package/lib/tokens-4J9sredA.mjs +100 -0
- package/lib/tokens-4J9sredA.mjs.map +1 -0
- package/lib/tokens-BuXXB01L.cjs +196 -0
- package/lib/tokens-BuXXB01L.cjs.map +1 -0
- package/lib/{use-guards.decorator-Be_QUx6b.mjs → use-guards.decorator-BecoQSmE.mjs} +3 -70
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +1 -0
- package/lib/{use-guards.decorator-B6tghdxM.cjs → use-guards.decorator-DgD-kxF5.cjs} +7 -158
- package/lib/use-guards.decorator-DgD-kxF5.cjs.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/attribute.factory.spec.mts +300 -0
- package/src/__tests__/console-logger.service.spec.mts +312 -0
- package/src/__tests__/guard-runner.service.spec.mts +399 -0
- package/src/__tests__/logger.service.spec.mts +147 -0
- package/src/__tests__/responders.spec.mts +6 -5
- package/src/factories/adapter.factory.mts +20 -0
- package/src/factories/endpoint-adapter.factory.mts +1 -1
- package/src/factories/http-adapter.factory.mts +1 -1
- package/src/factories/index.mts +1 -0
- package/src/factories/multipart-adapter.factory.mts +1 -1
- package/src/factories/reply.factory.mts +1 -1
- package/src/factories/request.factory.mts +1 -1
- package/src/factories/stream-adapter.factory.mts +1 -1
- package/src/factories/xml-stream-adapter.factory.mts +1 -1
- package/src/index.mts +1 -0
- package/src/interfaces/abstract-adapter.interface.mts +32 -0
- package/src/interfaces/abstract-http-adapter.interface.mts +27 -20
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +86 -2
- package/src/interfaces/adapter-environment.interface.mts +74 -0
- package/src/interfaces/index.mts +2 -0
- package/src/interfaces/plugin.interface.mts +50 -16
- package/src/legacy-compat/attribute.factory.mts +2 -2
- package/src/legacy-compat/decorators/controller.decorator.mts +1 -1
- package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
- package/src/legacy-compat/decorators/header.decorator.mts +2 -1
- package/src/legacy-compat/decorators/http-code.decorator.mts +2 -1
- package/src/legacy-compat/decorators/index.mts +2 -2
- package/src/legacy-compat/decorators/module.decorator.mts +1 -1
- package/src/legacy-compat/decorators/multipart.decorator.mts +1 -1
- package/src/legacy-compat/decorators/stream.decorator.mts +1 -1
- package/src/legacy-compat/decorators/use-guards.decorator.mts +1 -1
- package/src/legacy-compat/index.mts +10 -5
- package/src/logger/console-logger.service.mts +97 -7
- package/src/metadata/module.metadata.mts +43 -0
- package/src/navios.application.mts +172 -60
- package/src/navios.environment.mts +22 -12
- package/src/navios.factory.mts +31 -10
- package/src/services/abstract-handler-adapter.service.mts +366 -0
- package/src/services/index.mts +1 -0
- package/src/services/module-loader.service.mts +1 -0
- package/src/tokens/adapter.token.mts +6 -0
- package/src/tokens/http-adapter.token.mts +1 -1
- package/src/tokens/index.mts +1 -0
- package/src/utils/adapter-supports.util.mts +47 -0
- package/src/utils/index.mts +1 -0
- package/lib/index-BJjk2X1S.d.mts.map +0 -1
- package/lib/index-DZ6NU03y.d.cts.map +0 -1
- package/lib/src-C46ePe3d.cjs +0 -8022
- package/lib/src-C46ePe3d.cjs.map +0 -1
- package/lib/src-K2k0riYJ.mjs +0 -7587
- package/lib/src-K2k0riYJ.mjs.map +0 -1
- package/lib/use-guards.decorator-B6tghdxM.cjs.map +0 -1
- package/lib/use-guards.decorator-Be_QUx6b.mjs.map +0 -1
- package/src/legacy-compat/context-compat.mts +0 -95
- package/src/legacy-compat/decorators/factory.decorator.mts +0 -37
- package/src/legacy-compat/decorators/injectable.decorator.mts +0 -41
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _navios_di0 from "@navios/di";
|
|
2
|
-
import { AnyInjectableType, ClassType, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectableScope, InjectionToken, Registry, ScopedContainer } from "@navios/di";
|
|
2
|
+
import { AnyInjectableType, BoundInjectionToken, ClassType, ClassTypeWithArgument, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectableScope, InjectionToken, InjectionTokenSchemaType, Registry, ScopedContainer } from "@navios/di";
|
|
3
3
|
import z, { ZodDiscriminatedUnion, ZodObject, ZodType, z as z$1 } from "zod/v4";
|
|
4
4
|
import { BaseEndpointOptions, EndpointHandler, EndpointOptions, HttpMethod, RequestArgs, StreamHandler } from "@navios/builder";
|
|
5
5
|
import { InspectOptions } from "util";
|
|
@@ -381,10 +381,42 @@ interface ModuleMetadata {
|
|
|
381
381
|
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
382
382
|
overrides: Set<ClassType>;
|
|
383
383
|
customAttributes: Map<string | symbol, any>;
|
|
384
|
+
/**
|
|
385
|
+
* Extensible entries for adapter-specific data.
|
|
386
|
+
* Adapters can store custom metadata using symbol keys.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* const CommandEntryKey = Symbol('CommandEntryKey')
|
|
391
|
+
* metadata.customEntries.set(CommandEntryKey, new Set([Command1, Command2]))
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
customEntries: Map<symbol, unknown>;
|
|
384
395
|
}
|
|
385
396
|
declare function getModuleMetadata(target: ClassType, context: ClassDecoratorContext): ModuleMetadata;
|
|
386
397
|
declare function extractModuleMetadata(target: ClassType): ModuleMetadata;
|
|
387
398
|
declare function hasModuleMetadata(target: ClassType): boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Type-safe helper to get or create a custom entry in module metadata.
|
|
401
|
+
* Adapters use this to store their own metadata in modules.
|
|
402
|
+
*
|
|
403
|
+
* @param metadata - The module metadata object
|
|
404
|
+
* @param key - Symbol key for the custom entry
|
|
405
|
+
* @param defaultValue - Factory function to create default value if entry doesn't exist
|
|
406
|
+
* @returns The existing or newly created entry value
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const CommandEntryKey = Symbol('CommandEntryKey')
|
|
411
|
+
* const commands = getModuleCustomEntry<Set<ClassType>>(
|
|
412
|
+
* metadata,
|
|
413
|
+
* CommandEntryKey,
|
|
414
|
+
* () => new Set(),
|
|
415
|
+
* )
|
|
416
|
+
* commands.add(MyCommand)
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
declare function getModuleCustomEntry<T>(metadata: ModuleMetadata, key: symbol, defaultValue: () => T): T;
|
|
388
420
|
//#endregion
|
|
389
421
|
//#region src/metadata/navios-managed.metadata.d.mts
|
|
390
422
|
/**
|
|
@@ -415,6 +447,35 @@ declare function getManagedMetadata(target: ClassType): ManagedMetadata | null;
|
|
|
415
447
|
*/
|
|
416
448
|
declare function hasManagedMetadata(target: ClassType): boolean;
|
|
417
449
|
//#endregion
|
|
450
|
+
//#region src/interfaces/abstract-adapter.interface.d.mts
|
|
451
|
+
/**
|
|
452
|
+
* Base interface for all Navios adapters (HTTP, CLI, etc.).
|
|
453
|
+
*
|
|
454
|
+
* Adapters implement this interface to provide runtime-specific functionality.
|
|
455
|
+
* This interface defines the common lifecycle methods shared across all adapter types.
|
|
456
|
+
*/
|
|
457
|
+
interface AbstractAdapterInterface {
|
|
458
|
+
/**
|
|
459
|
+
* Sets up the adapter with the provided options.
|
|
460
|
+
* Called during application initialization before modules are initialized.
|
|
461
|
+
*/
|
|
462
|
+
setupAdapter(options: unknown): Promise<void>;
|
|
463
|
+
/**
|
|
464
|
+
* Called after all modules are loaded.
|
|
465
|
+
* Adapters use this to register routes, commands, or other module-based functionality.
|
|
466
|
+
*/
|
|
467
|
+
onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* Signals that the adapter is ready to handle requests/commands.
|
|
470
|
+
* Called after onModulesInit completes.
|
|
471
|
+
*/
|
|
472
|
+
ready(): Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* Disposes of the adapter and cleans up resources.
|
|
475
|
+
*/
|
|
476
|
+
dispose(): Promise<void>;
|
|
477
|
+
}
|
|
478
|
+
//#endregion
|
|
418
479
|
//#region src/interfaces/abstract-execution-context.inteface.d.mts
|
|
419
480
|
/**
|
|
420
481
|
* Interface providing access to the execution context during request handling.
|
|
@@ -459,6 +520,140 @@ interface AbstractExecutionContext {
|
|
|
459
520
|
getReply(): any;
|
|
460
521
|
}
|
|
461
522
|
//#endregion
|
|
523
|
+
//#region src/interfaces/adapter-environment.interface.d.mts
|
|
524
|
+
/**
|
|
525
|
+
* Base interface for adapter environments.
|
|
526
|
+
*
|
|
527
|
+
* All adapter environments extend this interface to provide
|
|
528
|
+
* type-safe access to adapter-specific configuration options.
|
|
529
|
+
*/
|
|
530
|
+
interface AdapterEnvironment {
|
|
531
|
+
/**
|
|
532
|
+
* Adapter setup/configuration options type
|
|
533
|
+
*/
|
|
534
|
+
options: unknown;
|
|
535
|
+
/**
|
|
536
|
+
* Adapter type
|
|
537
|
+
*/
|
|
538
|
+
adapter: AbstractAdapterInterface;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Environment interface for HTTP adapters.
|
|
542
|
+
*
|
|
543
|
+
* Each HTTP adapter (Fastify, Bun, etc.) implements this interface to provide
|
|
544
|
+
* type-safe access to HTTP-specific types throughout the application.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```typescript
|
|
548
|
+
* // Using with a specific adapter
|
|
549
|
+
* import { FastifyEnvironment } from '@navios/adapter-fastify'
|
|
550
|
+
*
|
|
551
|
+
* const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
|
|
552
|
+
* adapter: defineFastifyEnvironment(),
|
|
553
|
+
* })
|
|
554
|
+
*
|
|
555
|
+
* // All methods are now type-safe for Fastify
|
|
556
|
+
* app.configure({ trustProxy: true })
|
|
557
|
+
* app.enableCors({ origin: true }) // FastifyCorsOptions
|
|
558
|
+
* const server = app.getServer() // FastifyInstance
|
|
559
|
+
* await app.listen({ port: 3000 }) // FastifyListenOptions
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
interface HttpAdapterEnvironment extends AdapterEnvironment {
|
|
563
|
+
/**
|
|
564
|
+
* The underlying HTTP server instance type (e.g., FastifyInstance, Bun.Server)
|
|
565
|
+
*/
|
|
566
|
+
server: unknown;
|
|
567
|
+
/**
|
|
568
|
+
* CORS configuration options type
|
|
569
|
+
*/
|
|
570
|
+
corsOptions: unknown;
|
|
571
|
+
/**
|
|
572
|
+
* Multipart form data configuration options type
|
|
573
|
+
*/
|
|
574
|
+
multipartOptions: unknown;
|
|
575
|
+
/**
|
|
576
|
+
* Server listen options type (port, host, etc.)
|
|
577
|
+
*/
|
|
578
|
+
listenOptions: unknown;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Default environment with unknown types.
|
|
582
|
+
*
|
|
583
|
+
* Forces users to specify an Environment generic for type-safe adapter access.
|
|
584
|
+
* When no generic is provided to `NaviosApplication` or `NaviosFactory.create()`,
|
|
585
|
+
* this default is used, resulting in `unknown` types for all adapter-specific
|
|
586
|
+
* methods.
|
|
587
|
+
*/
|
|
588
|
+
interface DefaultAdapterEnvironment extends AdapterEnvironment {
|
|
589
|
+
options: unknown;
|
|
590
|
+
}
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/interfaces/abstract-http-adapter.interface.d.mts
|
|
593
|
+
/**
|
|
594
|
+
* Interface for HTTP adapters extending the base adapter interface.
|
|
595
|
+
*
|
|
596
|
+
* Adapters implement this interface to provide runtime-specific HTTP server
|
|
597
|
+
* functionality (Fastify, Bun, etc.).
|
|
598
|
+
*
|
|
599
|
+
* @typeParam Environment - The adapter environment providing type-safe access to
|
|
600
|
+
* server instance, CORS options, listen options, etc.
|
|
601
|
+
*/
|
|
602
|
+
interface AbstractHttpAdapterInterface<Environment extends HttpAdapterEnvironment = HttpAdapterEnvironment> extends AbstractAdapterInterface {
|
|
603
|
+
/**
|
|
604
|
+
* Sets up the adapter with the provided options.
|
|
605
|
+
* Called during application initialization before modules are initialized.
|
|
606
|
+
*/
|
|
607
|
+
setupAdapter(options: Environment['options']): Promise<void>;
|
|
608
|
+
/**
|
|
609
|
+
* Called after all modules are loaded to register routes.
|
|
610
|
+
*/
|
|
611
|
+
onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>;
|
|
612
|
+
/**
|
|
613
|
+
* Signals that the server is ready to accept requests.
|
|
614
|
+
*/
|
|
615
|
+
ready(): Promise<void>;
|
|
616
|
+
/**
|
|
617
|
+
* Disposes of the server and cleans up resources.
|
|
618
|
+
*/
|
|
619
|
+
dispose(): Promise<void>;
|
|
620
|
+
/**
|
|
621
|
+
* Returns the underlying HTTP server instance.
|
|
622
|
+
*/
|
|
623
|
+
getServer(): Environment['server'];
|
|
624
|
+
/**
|
|
625
|
+
* Sets a global prefix for all routes.
|
|
626
|
+
*/
|
|
627
|
+
setGlobalPrefix(prefix: string): void;
|
|
628
|
+
/**
|
|
629
|
+
* Gets the current global prefix.
|
|
630
|
+
* Returns empty string if no prefix is set.
|
|
631
|
+
*/
|
|
632
|
+
getGlobalPrefix(): string;
|
|
633
|
+
/**
|
|
634
|
+
* Enables CORS with the specified options.
|
|
635
|
+
*/
|
|
636
|
+
enableCors(options: Environment['corsOptions']): void;
|
|
637
|
+
/**
|
|
638
|
+
* Enables multipart form data handling.
|
|
639
|
+
*/
|
|
640
|
+
enableMultipart(options: Environment['multipartOptions']): void;
|
|
641
|
+
/**
|
|
642
|
+
* Starts the server and listens for incoming requests.
|
|
643
|
+
*/
|
|
644
|
+
listen(options: Environment['listenOptions']): Promise<string>;
|
|
645
|
+
/**
|
|
646
|
+
* Configures the adapter with additional options before init.
|
|
647
|
+
*
|
|
648
|
+
* This method allows setting adapter-specific configuration options
|
|
649
|
+
* before the server is initialized. Options set via configure() are
|
|
650
|
+
* merged with options passed to setupAdapter().
|
|
651
|
+
*
|
|
652
|
+
* Must be called before setupAdapter().
|
|
653
|
+
*/
|
|
654
|
+
configure(options: Partial<Environment['options']>): void;
|
|
655
|
+
}
|
|
656
|
+
//#endregion
|
|
462
657
|
//#region src/logger/utils/cli-colors.util.d.mts
|
|
463
658
|
declare const clc: {
|
|
464
659
|
bold: (text: string) => string;
|
|
@@ -566,15 +761,46 @@ interface ConsoleLoggerOptions {
|
|
|
566
761
|
*/
|
|
567
762
|
logLevels?: LogLevel[];
|
|
568
763
|
/**
|
|
569
|
-
* If enabled, will print timestamp
|
|
764
|
+
* If enabled, will print timestamp difference between current and previous log message.
|
|
570
765
|
* Note: This option is not used when `json` is enabled.
|
|
766
|
+
* @default false
|
|
571
767
|
*/
|
|
572
|
-
|
|
768
|
+
showTimeDiff?: boolean;
|
|
573
769
|
/**
|
|
574
770
|
* A prefix to be used for each log message.
|
|
575
771
|
* Note: This option is not used when `json` is enabled.
|
|
576
772
|
*/
|
|
577
773
|
prefix?: string;
|
|
774
|
+
/**
|
|
775
|
+
* If true, will print the process ID in the log message.
|
|
776
|
+
* Note: This option is not used when `json` is enabled.
|
|
777
|
+
* @default true
|
|
778
|
+
*/
|
|
779
|
+
showPid?: boolean;
|
|
780
|
+
/**
|
|
781
|
+
* If true, will print the log level in the log message.
|
|
782
|
+
* Note: This option is not used when `json` is enabled.
|
|
783
|
+
* @default true
|
|
784
|
+
*/
|
|
785
|
+
showLogLevel?: boolean;
|
|
786
|
+
/**
|
|
787
|
+
* If true, will print the prefix/app name in the log message.
|
|
788
|
+
* Note: This option is not used when `json` is enabled.
|
|
789
|
+
* @default true
|
|
790
|
+
*/
|
|
791
|
+
showPrefix?: boolean;
|
|
792
|
+
/**
|
|
793
|
+
* If true, will print the context in the log message.
|
|
794
|
+
* Note: This option is not used when `json` is enabled.
|
|
795
|
+
* @default true
|
|
796
|
+
*/
|
|
797
|
+
showContext?: boolean;
|
|
798
|
+
/**
|
|
799
|
+
* If true, will print the absolute timestamp in the log message.
|
|
800
|
+
* Note: This option is not used when `json` is enabled.
|
|
801
|
+
* @default true
|
|
802
|
+
*/
|
|
803
|
+
showTimestamp?: boolean;
|
|
578
804
|
/**
|
|
579
805
|
* If enabled, will add a request ID to the log message.
|
|
580
806
|
*/
|
|
@@ -643,6 +869,14 @@ interface ConsoleLoggerOptions {
|
|
|
643
869
|
* @publicApi
|
|
644
870
|
*/
|
|
645
871
|
declare class ConsoleLogger implements LoggerService {
|
|
872
|
+
/**
|
|
873
|
+
* Creates a new ConsoleLogger instance with the given options.
|
|
874
|
+
* This is a convenience method that instantiates and sets up the logger in one call.
|
|
875
|
+
*/
|
|
876
|
+
static create(): ConsoleLogger;
|
|
877
|
+
static create(context: string): ConsoleLogger;
|
|
878
|
+
static create(options: ConsoleLoggerOptions): ConsoleLogger;
|
|
879
|
+
static create(context: string, options: ConsoleLoggerOptions): ConsoleLogger;
|
|
646
880
|
/**
|
|
647
881
|
* The options of the logger.
|
|
648
882
|
*/
|
|
@@ -895,68 +1129,6 @@ interface AbstractHttpCorsOptions {
|
|
|
895
1129
|
logLevel?: LogLevel;
|
|
896
1130
|
}
|
|
897
1131
|
//#endregion
|
|
898
|
-
//#region src/interfaces/abstract-http-listen-options.interface.d.mts
|
|
899
|
-
interface AbstractHttpListenOptions {
|
|
900
|
-
port: number;
|
|
901
|
-
host?: string;
|
|
902
|
-
}
|
|
903
|
-
//#endregion
|
|
904
|
-
//#region src/interfaces/abstract-http-adapter.interface.d.mts
|
|
905
|
-
/**
|
|
906
|
-
* Abstract interface for HTTP adapters.
|
|
907
|
-
*
|
|
908
|
-
* Adapters implement this interface to provide runtime-specific HTTP server
|
|
909
|
-
* functionality (Fastify, Bun, etc.).
|
|
910
|
-
*
|
|
911
|
-
* @typeParam ServerInstance - The underlying server type (e.g., FastifyInstance)
|
|
912
|
-
* @typeParam CorsOptions - CORS configuration options type
|
|
913
|
-
* @typeParam Options - Server setup options type
|
|
914
|
-
* @typeParam MultipartOptions - Multipart form handling options type
|
|
915
|
-
*/
|
|
916
|
-
interface AbstractHttpAdapterInterface<ServerInstance, CorsOptions = AbstractHttpCorsOptions, Options$1 = {}, MultipartOptions = {}> {
|
|
917
|
-
/**
|
|
918
|
-
* Sets up the HTTP server with the provided options.
|
|
919
|
-
*/
|
|
920
|
-
setupHttpServer(options: Options$1): Promise<void>;
|
|
921
|
-
/**
|
|
922
|
-
* Called after all modules are loaded to register routes.
|
|
923
|
-
*/
|
|
924
|
-
onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>;
|
|
925
|
-
/**
|
|
926
|
-
* Signals that the server is ready to accept requests.
|
|
927
|
-
*/
|
|
928
|
-
ready(): Promise<void>;
|
|
929
|
-
/**
|
|
930
|
-
* Returns the underlying HTTP server instance.
|
|
931
|
-
*/
|
|
932
|
-
getServer(): ServerInstance;
|
|
933
|
-
/**
|
|
934
|
-
* Sets a global prefix for all routes.
|
|
935
|
-
*/
|
|
936
|
-
setGlobalPrefix(prefix: string): void;
|
|
937
|
-
/**
|
|
938
|
-
* Gets the current global prefix.
|
|
939
|
-
* Returns empty string if no prefix is set.
|
|
940
|
-
*/
|
|
941
|
-
getGlobalPrefix(): string;
|
|
942
|
-
/**
|
|
943
|
-
* Enables CORS with the specified options.
|
|
944
|
-
*/
|
|
945
|
-
enableCors(options: CorsOptions): void;
|
|
946
|
-
/**
|
|
947
|
-
* Enables multipart form data handling.
|
|
948
|
-
*/
|
|
949
|
-
enableMultipart(options: MultipartOptions): void;
|
|
950
|
-
/**
|
|
951
|
-
* Starts the server and listens for incoming requests.
|
|
952
|
-
*/
|
|
953
|
-
listen(options: AbstractHttpListenOptions): Promise<string>;
|
|
954
|
-
/**
|
|
955
|
-
* Disposes of the server and cleans up resources.
|
|
956
|
-
*/
|
|
957
|
-
dispose(): Promise<void>;
|
|
958
|
-
}
|
|
959
|
-
//#endregion
|
|
960
1132
|
//#region src/interfaces/abstract-http-handler-adapter.interface.d.mts
|
|
961
1133
|
/**
|
|
962
1134
|
* Static handler result - handler can be called without a scoped container.
|
|
@@ -979,11 +1151,88 @@ type DynamicHandler<TRequest = any, TReply = any> = {
|
|
|
979
1151
|
* Can be either static (pre-resolved) or dynamic (needs scoped container).
|
|
980
1152
|
*/
|
|
981
1153
|
type HandlerResult<TRequest = any, TReply = any> = StaticHandler<TRequest, TReply> | DynamicHandler<TRequest, TReply>;
|
|
982
|
-
|
|
983
|
-
|
|
1154
|
+
/**
|
|
1155
|
+
* Function type for argument getters that extract data from requests.
|
|
1156
|
+
* Each getter populates a target object with data from the request.
|
|
1157
|
+
*/
|
|
1158
|
+
type ArgumentGetterFn<TRequest = any> = (target: Record<string, any>, request: TRequest) => void | Promise<void>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Function type for formatting arguments from a request.
|
|
1161
|
+
* Built from argument getters, optimized for sync/async handling.
|
|
1162
|
+
*/
|
|
1163
|
+
type FormatArgumentsFn$1<TRequest = any> = (request: TRequest) => Record<string, any> | Promise<Record<string, any>>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Interface for HTTP handler adapter services.
|
|
1166
|
+
*
|
|
1167
|
+
* Adapters handle different types of HTTP requests (REST, streaming, multipart)
|
|
1168
|
+
* and are responsible for:
|
|
1169
|
+
* - Parsing and validating request data
|
|
1170
|
+
* - Creating handler functions
|
|
1171
|
+
* - Formatting responses
|
|
1172
|
+
* - Providing schema information (for frameworks like Fastify)
|
|
1173
|
+
*/
|
|
1174
|
+
interface AbstractHttpHandlerAdapterInterface<TRequest = any> {
|
|
1175
|
+
/**
|
|
1176
|
+
* Prepares argument getters for parsing request data.
|
|
1177
|
+
*
|
|
1178
|
+
* Creates functions that extract and validate data from the request,
|
|
1179
|
+
* populating a target object with validated arguments.
|
|
1180
|
+
*
|
|
1181
|
+
* @param handlerMetadata - The handler metadata with schemas and configuration.
|
|
1182
|
+
* @returns An array of getter functions that populate request arguments.
|
|
1183
|
+
*/
|
|
1184
|
+
prepareArguments?: (handlerMetadata: HandlerMetadata<any>) => ArgumentGetterFn<TRequest>[];
|
|
1185
|
+
/**
|
|
1186
|
+
* Builds a formatArguments function from argument getters.
|
|
1187
|
+
*
|
|
1188
|
+
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
1189
|
+
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
1190
|
+
* - If any getter is async: returns async function with Promise.all
|
|
1191
|
+
* - If no getters: returns frozen empty object (zero allocation)
|
|
1192
|
+
*
|
|
1193
|
+
* This method is useful for composition-based adapters that need to
|
|
1194
|
+
* build formatArguments without duplicating the optimization logic.
|
|
1195
|
+
*
|
|
1196
|
+
* @param getters - Array of argument getter functions
|
|
1197
|
+
* @returns Function to format arguments from request
|
|
1198
|
+
*/
|
|
1199
|
+
buildFormatArguments?: (getters: ArgumentGetterFn<TRequest>[]) => FormatArgumentsFn$1<TRequest>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Checks if the handler has any validation schemas defined.
|
|
1202
|
+
*
|
|
1203
|
+
* @param handlerMetadata - The handler metadata containing configuration.
|
|
1204
|
+
* @returns `true` if the handler has any schemas (request, query, response).
|
|
1205
|
+
*/
|
|
1206
|
+
hasSchema?: (handlerMetadata: HandlerMetadata<any>) => boolean;
|
|
1207
|
+
/**
|
|
1208
|
+
* Provides schema information for the framework's validation system.
|
|
1209
|
+
*
|
|
1210
|
+
* For frameworks like Fastify, this returns route schema objects.
|
|
1211
|
+
* For frameworks like Bun, this typically returns an empty object.
|
|
1212
|
+
*
|
|
1213
|
+
* @param handlerMetadata - The handler metadata containing configuration.
|
|
1214
|
+
* @returns Schema information for framework registration.
|
|
1215
|
+
*/
|
|
1216
|
+
provideSchema?: (handlerMetadata: HandlerMetadata<any>) => Record<string, any>;
|
|
1217
|
+
/**
|
|
1218
|
+
* Creates a request handler function for the endpoint.
|
|
1219
|
+
*
|
|
1220
|
+
* This is the core method that generates the actual handler function
|
|
1221
|
+
* that will be called when a request matches the endpoint.
|
|
1222
|
+
*
|
|
1223
|
+
* @param controller - The controller class containing the handler method.
|
|
1224
|
+
* @param handlerMetadata - The handler metadata with configuration and schemas.
|
|
1225
|
+
* @returns A handler result that is either static or dynamic.
|
|
1226
|
+
*/
|
|
984
1227
|
provideHandler: (controller: ClassType, handlerMetadata: HandlerMetadata<any>) => Promise<HandlerResult>;
|
|
985
1228
|
}
|
|
986
1229
|
//#endregion
|
|
1230
|
+
//#region src/interfaces/abstract-http-listen-options.interface.d.mts
|
|
1231
|
+
interface AbstractHttpListenOptions {
|
|
1232
|
+
port: number;
|
|
1233
|
+
host?: string;
|
|
1234
|
+
}
|
|
1235
|
+
//#endregion
|
|
987
1236
|
//#region src/interfaces/can-activate.d.mts
|
|
988
1237
|
/**
|
|
989
1238
|
* Interface that guards must implement to control access to endpoints.
|
|
@@ -1124,28 +1373,40 @@ declare class ModuleLoaderService {
|
|
|
1124
1373
|
* Context provided to plugins during registration.
|
|
1125
1374
|
*
|
|
1126
1375
|
* This context gives plugins access to the application's modules,
|
|
1127
|
-
*
|
|
1376
|
+
* adapter instance, DI container, and module loader.
|
|
1377
|
+
*
|
|
1378
|
+
* @typeParam TAdapter - The adapter type, defaults to AbstractAdapterInterface
|
|
1379
|
+
*
|
|
1380
|
+
* @example
|
|
1381
|
+
* ```typescript
|
|
1382
|
+
* // Generic plugin that works with any adapter
|
|
1383
|
+
* async register(context: PluginContext) {
|
|
1384
|
+
* const modules = context.modules
|
|
1385
|
+
* // ...
|
|
1386
|
+
* }
|
|
1387
|
+
*
|
|
1388
|
+
* // Adapter-specific plugin with typed adapter
|
|
1389
|
+
* async register(context: PluginContext<BunApplicationService>) {
|
|
1390
|
+
* const server = context.adapter.getServer() // Typed as Bun.Server
|
|
1391
|
+
* // ...
|
|
1392
|
+
* }
|
|
1393
|
+
* ```
|
|
1128
1394
|
*/
|
|
1129
|
-
interface PluginContext {
|
|
1395
|
+
interface PluginContext<TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface> {
|
|
1130
1396
|
/**
|
|
1131
1397
|
* All loaded modules with their metadata.
|
|
1132
1398
|
* Keys are module class names, values are their metadata.
|
|
1133
1399
|
*/
|
|
1134
1400
|
modules: Map<string, ModuleMetadata>;
|
|
1135
1401
|
/**
|
|
1136
|
-
* The
|
|
1137
|
-
*
|
|
1402
|
+
* The current adapter instance.
|
|
1403
|
+
* Use type guards or cast to adapter-specific types for HTTP methods.
|
|
1138
1404
|
*/
|
|
1139
|
-
|
|
1405
|
+
adapter: TAdapter;
|
|
1140
1406
|
/**
|
|
1141
1407
|
* The dependency injection container.
|
|
1142
1408
|
*/
|
|
1143
1409
|
container: Container;
|
|
1144
|
-
/**
|
|
1145
|
-
* Global route prefix (e.g., '/api/v1').
|
|
1146
|
-
* Empty string if no prefix is set.
|
|
1147
|
-
*/
|
|
1148
|
-
globalPrefix: string;
|
|
1149
1410
|
/**
|
|
1150
1411
|
* Module loader service for extending the module tree.
|
|
1151
1412
|
* Use `moduleLoader.extendModules()` to add controllers dynamically.
|
|
@@ -1159,9 +1420,11 @@ interface PluginContext {
|
|
|
1159
1420
|
* after all modules are loaded but before the server starts listening.
|
|
1160
1421
|
*
|
|
1161
1422
|
* @typeParam TOptions - The type of options the plugin accepts
|
|
1423
|
+
* @typeParam TAdapter - The adapter type the plugin requires
|
|
1162
1424
|
*
|
|
1163
1425
|
* @example
|
|
1164
1426
|
* ```typescript
|
|
1427
|
+
* // Generic plugin
|
|
1165
1428
|
* const myPlugin: NaviosPlugin<{ enabled: boolean }> = {
|
|
1166
1429
|
* name: 'my-plugin',
|
|
1167
1430
|
* register: async (context, options) => {
|
|
@@ -1170,9 +1433,17 @@ interface PluginContext {
|
|
|
1170
1433
|
* }
|
|
1171
1434
|
* },
|
|
1172
1435
|
* }
|
|
1436
|
+
*
|
|
1437
|
+
* // Adapter-specific plugin
|
|
1438
|
+
* const fastifyPlugin: NaviosPlugin<Options, FastifyApplicationService> = {
|
|
1439
|
+
* name: 'fastify-plugin',
|
|
1440
|
+
* register: async (context, options) => {
|
|
1441
|
+
* const fastify = context.adapter.getServer() // Typed!
|
|
1442
|
+
* },
|
|
1443
|
+
* }
|
|
1173
1444
|
* ```
|
|
1174
1445
|
*/
|
|
1175
|
-
interface NaviosPlugin<TOptions = unknown> {
|
|
1446
|
+
interface NaviosPlugin<TOptions = unknown, TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface> {
|
|
1176
1447
|
/**
|
|
1177
1448
|
* Plugin name for identification and logging.
|
|
1178
1449
|
*/
|
|
@@ -1180,10 +1451,10 @@ interface NaviosPlugin<TOptions = unknown> {
|
|
|
1180
1451
|
/**
|
|
1181
1452
|
* Called after modules are loaded but before the server starts listening.
|
|
1182
1453
|
*
|
|
1183
|
-
* @param context - The plugin context with access to modules and
|
|
1454
|
+
* @param context - The plugin context with access to modules and adapter
|
|
1184
1455
|
* @param options - Plugin-specific configuration options
|
|
1185
1456
|
*/
|
|
1186
|
-
register(context: PluginContext
|
|
1457
|
+
register(context: PluginContext<TAdapter>, options: TOptions): Promise<void> | void;
|
|
1187
1458
|
}
|
|
1188
1459
|
/**
|
|
1189
1460
|
* Plugin definition combining a plugin with its options.
|
|
@@ -1191,6 +1462,7 @@ interface NaviosPlugin<TOptions = unknown> {
|
|
|
1191
1462
|
* This is the type returned by plugin factory functions like `defineOpenApiPlugin()`.
|
|
1192
1463
|
*
|
|
1193
1464
|
* @typeParam TOptions - The type of options the plugin accepts
|
|
1465
|
+
* @typeParam TAdapter - The adapter type the plugin requires
|
|
1194
1466
|
*
|
|
1195
1467
|
* @example
|
|
1196
1468
|
* ```typescript
|
|
@@ -1202,11 +1474,11 @@ interface NaviosPlugin<TOptions = unknown> {
|
|
|
1202
1474
|
* }
|
|
1203
1475
|
* ```
|
|
1204
1476
|
*/
|
|
1205
|
-
interface PluginDefinition<TOptions = unknown> {
|
|
1477
|
+
interface PluginDefinition<TOptions = unknown, TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface> {
|
|
1206
1478
|
/**
|
|
1207
1479
|
* The plugin instance.
|
|
1208
1480
|
*/
|
|
1209
|
-
plugin: NaviosPlugin<TOptions>;
|
|
1481
|
+
plugin: NaviosPlugin<TOptions, TAdapter>;
|
|
1210
1482
|
/**
|
|
1211
1483
|
* Options to pass to the plugin's register function.
|
|
1212
1484
|
*/
|
|
@@ -2104,197 +2376,23 @@ declare const ValidationErrorResponderToken: InjectionToken<ErrorResponder, unde
|
|
|
2104
2376
|
*/
|
|
2105
2377
|
declare const ForbiddenResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2106
2378
|
//#endregion
|
|
2107
|
-
//#region src/
|
|
2379
|
+
//#region src/navios.environment.d.mts
|
|
2380
|
+
interface NaviosEnvironmentOptions {
|
|
2381
|
+
tokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>;
|
|
2382
|
+
}
|
|
2383
|
+
//#endregion
|
|
2384
|
+
//#region src/navios.application.d.mts
|
|
2108
2385
|
/**
|
|
2109
|
-
*
|
|
2110
|
-
*
|
|
2111
|
-
* that can be used to get a fresh instance per request.
|
|
2386
|
+
* Options for configuring the Navios application context.
|
|
2387
|
+
* These options control the application configuration.
|
|
2112
2388
|
*/
|
|
2113
|
-
interface
|
|
2389
|
+
interface NaviosApplicationOptions {
|
|
2114
2390
|
/**
|
|
2115
|
-
*
|
|
2116
|
-
*
|
|
2117
|
-
*
|
|
2118
|
-
*
|
|
2119
|
-
|
|
2120
|
-
cached: boolean;
|
|
2121
|
-
/**
|
|
2122
|
-
* The cached instance (only available if `cached` is true).
|
|
2123
|
-
*/
|
|
2124
|
-
instance: T | null;
|
|
2125
|
-
/**
|
|
2126
|
-
* Resolves the instance from a scoped container.
|
|
2127
|
-
* Use this when `cached` is false to get a fresh instance per request.
|
|
2128
|
-
*/
|
|
2129
|
-
resolve: (scoped: ScopedContainer) => Promise<T>;
|
|
2130
|
-
}
|
|
2131
|
-
/**
|
|
2132
|
-
* Result of resolving multiple instances.
|
|
2133
|
-
* Contains either all cached singleton instances or a resolver function.
|
|
2134
|
-
*/
|
|
2135
|
-
interface MultiInstanceResolution<T = any> {
|
|
2136
|
-
/**
|
|
2137
|
-
* Whether ALL instances were successfully cached as singletons.
|
|
2138
|
-
* If true, `instances` contains all cached instances.
|
|
2139
|
-
* If false, at least one class has request-scoped dependencies.
|
|
2140
|
-
*/
|
|
2141
|
-
cached: boolean;
|
|
2142
|
-
/**
|
|
2143
|
-
* The cached instances (only available if `cached` is true).
|
|
2144
|
-
* Order matches the input array order.
|
|
2145
|
-
*/
|
|
2146
|
-
instances: T[] | null;
|
|
2147
|
-
/**
|
|
2148
|
-
* The original class types for dynamic resolution.
|
|
2149
|
-
*/
|
|
2150
|
-
classTypes: ClassType[];
|
|
2151
|
-
/**
|
|
2152
|
-
* Resolves all instances from a scoped container.
|
|
2153
|
-
* Use this when `cached` is false to get fresh instances per request.
|
|
2154
|
-
*/
|
|
2155
|
-
resolve: (scoped: ScopedContainer) => Promise<T[]>;
|
|
2156
|
-
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Service responsible for resolving class instances with automatic scope detection.
|
|
2159
|
-
*
|
|
2160
|
-
* This service attempts to resolve classes as singletons from the root container.
|
|
2161
|
-
* If resolution fails (because the class has request-scoped dependencies),
|
|
2162
|
-
* it automatically updates the class's scope to Request and provides a
|
|
2163
|
-
* resolver function for per-request instantiation.
|
|
2164
|
-
*
|
|
2165
|
-
* This enables optimal performance:
|
|
2166
|
-
* - Classes without request-scoped deps stay as singletons (faster)
|
|
2167
|
-
* - Classes with request-scoped deps are automatically promoted to request scope
|
|
2168
|
-
*
|
|
2169
|
-
* @example
|
|
2170
|
-
* ```ts
|
|
2171
|
-
* const resolution = await instanceResolver.resolve(UserController)
|
|
2172
|
-
*
|
|
2173
|
-
* if (resolution.cached) {
|
|
2174
|
-
* // Use cached singleton
|
|
2175
|
-
* return resolution.instance.handleRequest(req)
|
|
2176
|
-
* } else {
|
|
2177
|
-
* // Resolve per request
|
|
2178
|
-
* const controller = await resolution.resolve(scopedContainer)
|
|
2179
|
-
* return controller.handleRequest(req)
|
|
2180
|
-
* }
|
|
2181
|
-
* ```
|
|
2182
|
-
*/
|
|
2183
|
-
declare class InstanceResolverService {
|
|
2184
|
-
private container;
|
|
2185
|
-
/**
|
|
2186
|
-
* Attempts to resolve a class instance, automatically detecting if it needs
|
|
2187
|
-
* request scope based on its dependencies.
|
|
2188
|
-
*
|
|
2189
|
-
* @param classType - The class to resolve
|
|
2190
|
-
* @returns A resolution result containing either a cached instance or resolver function
|
|
2191
|
-
*/
|
|
2192
|
-
resolve<T>(classType: ClassType): Promise<InstanceResolution<T>>;
|
|
2193
|
-
/**
|
|
2194
|
-
* Attempts to resolve multiple class instances, automatically detecting if any need
|
|
2195
|
-
* request scope based on their dependencies.
|
|
2196
|
-
*
|
|
2197
|
-
* Returns `cached: true` only if ALL classes can be resolved as singletons.
|
|
2198
|
-
* If any class has request-scoped dependencies, returns `cached: false`.
|
|
2199
|
-
*
|
|
2200
|
-
* @param classTypes - The classes to resolve
|
|
2201
|
-
* @returns A resolution result containing either all cached instances or resolver function
|
|
2202
|
-
*/
|
|
2203
|
-
resolveMany<T>(classTypes: ClassType[]): Promise<MultiInstanceResolution<T>>;
|
|
2204
|
-
}
|
|
2205
|
-
/**
|
|
2206
|
-
* @deprecated Use InstanceResolverService instead
|
|
2207
|
-
*/
|
|
2208
|
-
declare const ControllerResolverService: typeof InstanceResolverService;
|
|
2209
|
-
/**
|
|
2210
|
-
* @deprecated Use InstanceResolution instead
|
|
2211
|
-
*/
|
|
2212
|
-
type ControllerResolution<T = any> = InstanceResolution<T>;
|
|
2213
|
-
//#endregion
|
|
2214
|
-
//#region src/services/guard-runner.service.d.mts
|
|
2215
|
-
declare class GuardRunnerService {
|
|
2216
|
-
private readonly errorProducer;
|
|
2217
|
-
private readonly logger;
|
|
2218
|
-
/**
|
|
2219
|
-
* Runs guards that need to be resolved from a scoped container.
|
|
2220
|
-
* Use this when guards have request-scoped dependencies.
|
|
2221
|
-
*/
|
|
2222
|
-
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
2223
|
-
/**
|
|
2224
|
-
* Runs pre-resolved guard instances.
|
|
2225
|
-
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
2226
|
-
*/
|
|
2227
|
-
runGuardsStatic(guardInstances: CanActivate[], executionContext: AbstractExecutionContext): Promise<boolean>;
|
|
2228
|
-
/**
|
|
2229
|
-
* Shared guard execution logic.
|
|
2230
|
-
* Iterates through guard instances and calls canActivate on each.
|
|
2231
|
-
*/
|
|
2232
|
-
private executeGuards;
|
|
2233
|
-
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
2234
|
-
}
|
|
2235
|
-
//#endregion
|
|
2236
|
-
//#region src/stores/request-id.store.d.mts
|
|
2237
|
-
/**
|
|
2238
|
-
* Generates a simple incremental request ID.
|
|
2239
|
-
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
2240
|
-
*
|
|
2241
|
-
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
2242
|
-
*/
|
|
2243
|
-
declare function generateRequestId(): string;
|
|
2244
|
-
/**
|
|
2245
|
-
* Enables or disables request ID propagation.
|
|
2246
|
-
* Called by NaviosFactory based on the enableRequestId option.
|
|
2247
|
-
*
|
|
2248
|
-
* @param enabled - Whether to enable request ID propagation
|
|
2249
|
-
*/
|
|
2250
|
-
declare function setRequestIdEnabled(enabled: boolean): void;
|
|
2251
|
-
/**
|
|
2252
|
-
* Runs a function with a request ID in the async local storage context.
|
|
2253
|
-
* If request ID propagation is disabled, the function is called directly
|
|
2254
|
-
* without AsyncLocalStorage overhead.
|
|
2255
|
-
*
|
|
2256
|
-
* @param requestId - The request ID to set for this context
|
|
2257
|
-
* @param fn - The function to run within this context
|
|
2258
|
-
* @returns The return value of the function
|
|
2259
|
-
*/
|
|
2260
|
-
declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
2261
|
-
/**
|
|
2262
|
-
* Gets the current request ID from the async local storage context.
|
|
2263
|
-
*
|
|
2264
|
-
* @returns The current request ID, or undefined if not in a request context
|
|
2265
|
-
*/
|
|
2266
|
-
declare function getRequestId(): string | undefined;
|
|
2267
|
-
//#endregion
|
|
2268
|
-
//#region src/tokens/endpoint-adapter.token.d.mts
|
|
2269
|
-
declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
2270
|
-
//#endregion
|
|
2271
|
-
//#region src/tokens/execution-context.token.d.mts
|
|
2272
|
-
declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
2273
|
-
declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
2274
|
-
//#endregion
|
|
2275
|
-
//#region src/tokens/http-adapter.token.d.mts
|
|
2276
|
-
declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<any, any, any, any>, undefined, false>;
|
|
2277
|
-
//#endregion
|
|
2278
|
-
//#region src/tokens/multipart-adapter.token.d.mts
|
|
2279
|
-
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
2280
|
-
//#endregion
|
|
2281
|
-
//#region src/navios.environment.d.mts
|
|
2282
|
-
interface NaviosEnvironmentOptions {
|
|
2283
|
-
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>;
|
|
2284
|
-
}
|
|
2285
|
-
//#endregion
|
|
2286
|
-
//#region src/navios.application.d.mts
|
|
2287
|
-
/**
|
|
2288
|
-
* Options for configuring the Navios application context.
|
|
2289
|
-
* These options control the application configuration.
|
|
2290
|
-
*/
|
|
2291
|
-
interface NaviosApplicationOptions {
|
|
2292
|
-
/**
|
|
2293
|
-
* Specifies the logger to use. Pass `false` to turn off logging.
|
|
2294
|
-
*
|
|
2295
|
-
* - `LoggerService` instance: Use a custom logger implementation
|
|
2296
|
-
* - `LogLevel[]`: Enable specific log levels (e.g., ['error', 'warn', 'log'])
|
|
2297
|
-
* - `false`: Disable logging completely
|
|
2391
|
+
* Specifies the logger to use. Pass `false` to turn off logging.
|
|
2392
|
+
*
|
|
2393
|
+
* - `LoggerService` instance: Use a custom logger implementation
|
|
2394
|
+
* - `LogLevel[]`: Enable specific log levels (e.g., ['error', 'warn', 'log'])
|
|
2395
|
+
* - `false`: Disable logging completely
|
|
2298
2396
|
*/
|
|
2299
2397
|
logger?: LoggerService | LogLevel[] | false;
|
|
2300
2398
|
/**
|
|
@@ -2308,14 +2406,14 @@ interface NaviosApplicationOptions {
|
|
|
2308
2406
|
*/
|
|
2309
2407
|
container?: Container;
|
|
2310
2408
|
/**
|
|
2311
|
-
*
|
|
2409
|
+
* Adapter environment(s) to use for the application.
|
|
2312
2410
|
* Can be a single adapter or an array of adapters.
|
|
2313
2411
|
*
|
|
2314
2412
|
* @example
|
|
2315
2413
|
* ```typescript
|
|
2316
2414
|
* adapter: defineFastifyEnvironment()
|
|
2317
2415
|
* // or
|
|
2318
|
-
* adapter: [defineFastifyEnvironment()
|
|
2416
|
+
* adapter: [defineFastifyEnvironment()]
|
|
2319
2417
|
* ```
|
|
2320
2418
|
*/
|
|
2321
2419
|
adapter: NaviosEnvironmentOptions | NaviosEnvironmentOptions[];
|
|
@@ -2336,7 +2434,7 @@ interface NaviosApplicationOptions {
|
|
|
2336
2434
|
* Main application class for Navios.
|
|
2337
2435
|
*
|
|
2338
2436
|
* This class represents a Navios application instance and provides methods
|
|
2339
|
-
* for initializing, configuring, and managing the
|
|
2437
|
+
* for initializing, configuring, and managing the application lifecycle.
|
|
2340
2438
|
*
|
|
2341
2439
|
* @example
|
|
2342
2440
|
* ```typescript
|
|
@@ -2350,10 +2448,10 @@ interface NaviosApplicationOptions {
|
|
|
2350
2448
|
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
2351
2449
|
* ```
|
|
2352
2450
|
*/
|
|
2353
|
-
declare class NaviosApplication {
|
|
2451
|
+
declare class NaviosApplication<Environment extends AdapterEnvironment = DefaultAdapterEnvironment> {
|
|
2354
2452
|
private environment;
|
|
2355
2453
|
private moduleLoader;
|
|
2356
|
-
private
|
|
2454
|
+
private adapter;
|
|
2357
2455
|
private logger;
|
|
2358
2456
|
protected container: Container;
|
|
2359
2457
|
private appModule;
|
|
@@ -2379,6 +2477,13 @@ declare class NaviosApplication {
|
|
|
2379
2477
|
* @returns The Container instance
|
|
2380
2478
|
*/
|
|
2381
2479
|
getContainer(): Container;
|
|
2480
|
+
/**
|
|
2481
|
+
* Returns the current adapter instance.
|
|
2482
|
+
*
|
|
2483
|
+
* @returns The adapter instance
|
|
2484
|
+
* @throws Error if adapter is not initialized
|
|
2485
|
+
*/
|
|
2486
|
+
getAdapter(): Environment['adapter'];
|
|
2382
2487
|
/**
|
|
2383
2488
|
* Registers a plugin to be initialized after modules are loaded.
|
|
2384
2489
|
*
|
|
@@ -2397,13 +2502,13 @@ declare class NaviosApplication {
|
|
|
2397
2502
|
* }))
|
|
2398
2503
|
* ```
|
|
2399
2504
|
*/
|
|
2400
|
-
usePlugin<TOptions>(definition: PluginDefinition<TOptions>): this;
|
|
2505
|
+
usePlugin<TOptions, TAdapter extends AbstractAdapterInterface>(definition: PluginDefinition<TOptions, TAdapter>): this;
|
|
2401
2506
|
/**
|
|
2402
2507
|
* Initializes the application.
|
|
2403
2508
|
*
|
|
2404
2509
|
* This method:
|
|
2405
2510
|
* - Loads all modules and their dependencies
|
|
2406
|
-
* - Sets up the
|
|
2511
|
+
* - Sets up the adapter if one is configured
|
|
2407
2512
|
* - Calls onModuleInit hooks on all modules
|
|
2408
2513
|
* - Initializes registered plugins
|
|
2409
2514
|
* - Marks the application as initialized
|
|
@@ -2424,11 +2529,52 @@ declare class NaviosApplication {
|
|
|
2424
2529
|
init(): Promise<void>;
|
|
2425
2530
|
private initModules;
|
|
2426
2531
|
private initPlugins;
|
|
2532
|
+
/**
|
|
2533
|
+
* Gets a service instance from the dependency injection container.
|
|
2534
|
+
*
|
|
2535
|
+
* This is a shorthand for `app.getContainer().get(token)`.
|
|
2536
|
+
*
|
|
2537
|
+
* @param token - The injection token or class to resolve
|
|
2538
|
+
* @returns Promise resolving to the service instance
|
|
2539
|
+
*
|
|
2540
|
+
* @example
|
|
2541
|
+
* ```typescript
|
|
2542
|
+
* const userService = await app.get(UserService)
|
|
2543
|
+
* const config = await app.get(ConfigToken)
|
|
2544
|
+
* ```
|
|
2545
|
+
*/
|
|
2546
|
+
get<T extends ClassType>(token: T): Promise<InstanceType<T>>;
|
|
2547
|
+
get<T extends ClassTypeWithArgument<R>, R>(token: T, args: R): Promise<InstanceType<T>>;
|
|
2548
|
+
get<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z$1.input<S>): Promise<T>;
|
|
2549
|
+
get<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): Promise<T>;
|
|
2550
|
+
get<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
2551
|
+
get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
2552
|
+
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
2553
|
+
/**
|
|
2554
|
+
* Configures the adapter with additional options before initialization.
|
|
2555
|
+
*
|
|
2556
|
+
* This method allows setting adapter-specific configuration options
|
|
2557
|
+
* before the adapter is initialized. Must be called before `init()`.
|
|
2558
|
+
*
|
|
2559
|
+
* @param options - Adapter-specific configuration options
|
|
2560
|
+
* @returns this for method chaining
|
|
2561
|
+
* @throws Error if called after init() or if adapter doesn't support configure
|
|
2562
|
+
*
|
|
2563
|
+
* @example
|
|
2564
|
+
* ```typescript
|
|
2565
|
+
* // With Fastify adapter
|
|
2566
|
+
* app.configure({ trustProxy: true, logger: true })
|
|
2567
|
+
*
|
|
2568
|
+
* // With Bun adapter
|
|
2569
|
+
* app.configure({ development: true })
|
|
2570
|
+
* ```
|
|
2571
|
+
*/
|
|
2572
|
+
configure(options: Partial<Environment['options']>): this;
|
|
2427
2573
|
/**
|
|
2428
2574
|
* Enables CORS (Cross-Origin Resource Sharing) for the application.
|
|
2429
2575
|
*
|
|
2430
2576
|
* @param options - CORS configuration options (adapter-specific)
|
|
2431
|
-
* @throws Error if
|
|
2577
|
+
* @throws Error if adapter doesn't support enableCors
|
|
2432
2578
|
*
|
|
2433
2579
|
* @example
|
|
2434
2580
|
* ```typescript
|
|
@@ -2439,12 +2585,12 @@ declare class NaviosApplication {
|
|
|
2439
2585
|
* })
|
|
2440
2586
|
* ```
|
|
2441
2587
|
*/
|
|
2442
|
-
enableCors(options:
|
|
2588
|
+
enableCors(options: Environment extends HttpAdapterEnvironment ? Environment['corsOptions'] : never): void;
|
|
2443
2589
|
/**
|
|
2444
2590
|
* Enables multipart/form-data support for file uploads.
|
|
2445
2591
|
*
|
|
2446
2592
|
* @param options - Multipart configuration options (adapter-specific)
|
|
2447
|
-
* @throws Error if
|
|
2593
|
+
* @throws Error if adapter doesn't support enableMultipart
|
|
2448
2594
|
*
|
|
2449
2595
|
* @example
|
|
2450
2596
|
* ```typescript
|
|
@@ -2455,12 +2601,12 @@ declare class NaviosApplication {
|
|
|
2455
2601
|
* })
|
|
2456
2602
|
* ```
|
|
2457
2603
|
*/
|
|
2458
|
-
enableMultipart(options:
|
|
2604
|
+
enableMultipart(options: Environment extends HttpAdapterEnvironment ? Environment['multipartOptions'] : never): void;
|
|
2459
2605
|
/**
|
|
2460
2606
|
* Sets a global prefix for all routes.
|
|
2461
2607
|
*
|
|
2462
2608
|
* @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
|
|
2463
|
-
* @throws Error if
|
|
2609
|
+
* @throws Error if adapter doesn't support setGlobalPrefix
|
|
2464
2610
|
*
|
|
2465
2611
|
* @example
|
|
2466
2612
|
* ```typescript
|
|
@@ -2477,7 +2623,7 @@ declare class NaviosApplication {
|
|
|
2477
2623
|
* - Bun adapter: Returns Bun.Server
|
|
2478
2624
|
*
|
|
2479
2625
|
* @returns The HTTP server instance
|
|
2480
|
-
* @throws Error if
|
|
2626
|
+
* @throws Error if adapter doesn't support getServer
|
|
2481
2627
|
*
|
|
2482
2628
|
* @example
|
|
2483
2629
|
* ```typescript
|
|
@@ -2485,23 +2631,23 @@ declare class NaviosApplication {
|
|
|
2485
2631
|
* // Use adapter-specific server methods
|
|
2486
2632
|
* ```
|
|
2487
2633
|
*/
|
|
2488
|
-
getServer():
|
|
2634
|
+
getServer(): Environment extends HttpAdapterEnvironment ? Environment['server'] : never;
|
|
2489
2635
|
/**
|
|
2490
2636
|
* Starts the HTTP server and begins listening for requests.
|
|
2491
2637
|
*
|
|
2492
2638
|
* @param options - Listen options (port, host, etc.)
|
|
2493
|
-
* @throws Error if
|
|
2639
|
+
* @throws Error if adapter doesn't support listen
|
|
2494
2640
|
*
|
|
2495
2641
|
* @example
|
|
2496
2642
|
* ```typescript
|
|
2497
2643
|
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
2498
2644
|
* ```
|
|
2499
2645
|
*/
|
|
2500
|
-
listen(options:
|
|
2646
|
+
listen(options: Environment extends HttpAdapterEnvironment ? Environment['listenOptions'] : never): Promise<string>;
|
|
2501
2647
|
/**
|
|
2502
2648
|
* Disposes of application resources.
|
|
2503
2649
|
*
|
|
2504
|
-
* Cleans up the
|
|
2650
|
+
* Cleans up the adapter and module loader.
|
|
2505
2651
|
* This method is called automatically by `close()`.
|
|
2506
2652
|
*/
|
|
2507
2653
|
dispose(): Promise<void>;
|
|
@@ -2522,6 +2668,367 @@ declare class NaviosApplication {
|
|
|
2522
2668
|
close(): Promise<void>;
|
|
2523
2669
|
}
|
|
2524
2670
|
//#endregion
|
|
2671
|
+
//#region src/services/instance-resolver.service.d.mts
|
|
2672
|
+
/**
|
|
2673
|
+
* Result of instance resolution attempt.
|
|
2674
|
+
* Contains either a cached singleton instance or a resolver function
|
|
2675
|
+
* that can be used to get a fresh instance per request.
|
|
2676
|
+
*/
|
|
2677
|
+
interface InstanceResolution<T = any> {
|
|
2678
|
+
/**
|
|
2679
|
+
* Whether the instance was successfully cached as a singleton.
|
|
2680
|
+
* If true, `instance` contains the cached instance.
|
|
2681
|
+
* If false, the class has request-scoped dependencies and
|
|
2682
|
+
* must be resolved per-request using `resolve()`.
|
|
2683
|
+
*/
|
|
2684
|
+
cached: boolean;
|
|
2685
|
+
/**
|
|
2686
|
+
* The cached instance (only available if `cached` is true).
|
|
2687
|
+
*/
|
|
2688
|
+
instance: T | null;
|
|
2689
|
+
/**
|
|
2690
|
+
* Resolves the instance from a scoped container.
|
|
2691
|
+
* Use this when `cached` is false to get a fresh instance per request.
|
|
2692
|
+
*/
|
|
2693
|
+
resolve: (scoped: ScopedContainer) => Promise<T>;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Result of resolving multiple instances.
|
|
2697
|
+
* Contains either all cached singleton instances or a resolver function.
|
|
2698
|
+
*/
|
|
2699
|
+
interface MultiInstanceResolution<T = any> {
|
|
2700
|
+
/**
|
|
2701
|
+
* Whether ALL instances were successfully cached as singletons.
|
|
2702
|
+
* If true, `instances` contains all cached instances.
|
|
2703
|
+
* If false, at least one class has request-scoped dependencies.
|
|
2704
|
+
*/
|
|
2705
|
+
cached: boolean;
|
|
2706
|
+
/**
|
|
2707
|
+
* The cached instances (only available if `cached` is true).
|
|
2708
|
+
* Order matches the input array order.
|
|
2709
|
+
*/
|
|
2710
|
+
instances: T[] | null;
|
|
2711
|
+
/**
|
|
2712
|
+
* The original class types for dynamic resolution.
|
|
2713
|
+
*/
|
|
2714
|
+
classTypes: ClassType[];
|
|
2715
|
+
/**
|
|
2716
|
+
* Resolves all instances from a scoped container.
|
|
2717
|
+
* Use this when `cached` is false to get fresh instances per request.
|
|
2718
|
+
*/
|
|
2719
|
+
resolve: (scoped: ScopedContainer) => Promise<T[]>;
|
|
2720
|
+
}
|
|
2721
|
+
/**
|
|
2722
|
+
* Service responsible for resolving class instances with automatic scope detection.
|
|
2723
|
+
*
|
|
2724
|
+
* This service attempts to resolve classes as singletons from the root container.
|
|
2725
|
+
* If resolution fails (because the class has request-scoped dependencies),
|
|
2726
|
+
* it automatically updates the class's scope to Request and provides a
|
|
2727
|
+
* resolver function for per-request instantiation.
|
|
2728
|
+
*
|
|
2729
|
+
* This enables optimal performance:
|
|
2730
|
+
* - Classes without request-scoped deps stay as singletons (faster)
|
|
2731
|
+
* - Classes with request-scoped deps are automatically promoted to request scope
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```ts
|
|
2735
|
+
* const resolution = await instanceResolver.resolve(UserController)
|
|
2736
|
+
*
|
|
2737
|
+
* if (resolution.cached) {
|
|
2738
|
+
* // Use cached singleton
|
|
2739
|
+
* return resolution.instance.handleRequest(req)
|
|
2740
|
+
* } else {
|
|
2741
|
+
* // Resolve per request
|
|
2742
|
+
* const controller = await resolution.resolve(scopedContainer)
|
|
2743
|
+
* return controller.handleRequest(req)
|
|
2744
|
+
* }
|
|
2745
|
+
* ```
|
|
2746
|
+
*/
|
|
2747
|
+
declare class InstanceResolverService {
|
|
2748
|
+
private container;
|
|
2749
|
+
/**
|
|
2750
|
+
* Attempts to resolve a class instance, automatically detecting if it needs
|
|
2751
|
+
* request scope based on its dependencies.
|
|
2752
|
+
*
|
|
2753
|
+
* @param classType - The class to resolve
|
|
2754
|
+
* @returns A resolution result containing either a cached instance or resolver function
|
|
2755
|
+
*/
|
|
2756
|
+
resolve<T>(classType: ClassType): Promise<InstanceResolution<T>>;
|
|
2757
|
+
/**
|
|
2758
|
+
* Attempts to resolve multiple class instances, automatically detecting if any need
|
|
2759
|
+
* request scope based on their dependencies.
|
|
2760
|
+
*
|
|
2761
|
+
* Returns `cached: true` only if ALL classes can be resolved as singletons.
|
|
2762
|
+
* If any class has request-scoped dependencies, returns `cached: false`.
|
|
2763
|
+
*
|
|
2764
|
+
* @param classTypes - The classes to resolve
|
|
2765
|
+
* @returns A resolution result containing either all cached instances or resolver function
|
|
2766
|
+
*/
|
|
2767
|
+
resolveMany<T>(classTypes: ClassType[]): Promise<MultiInstanceResolution<T>>;
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* @deprecated Use InstanceResolverService instead
|
|
2771
|
+
*/
|
|
2772
|
+
declare const ControllerResolverService: typeof InstanceResolverService;
|
|
2773
|
+
/**
|
|
2774
|
+
* @deprecated Use InstanceResolution instead
|
|
2775
|
+
*/
|
|
2776
|
+
type ControllerResolution<T = any> = InstanceResolution<T>;
|
|
2777
|
+
//#endregion
|
|
2778
|
+
//#region src/services/abstract-handler-adapter.service.d.mts
|
|
2779
|
+
/**
|
|
2780
|
+
* Function type for argument getters that extract data from requests.
|
|
2781
|
+
* Re-exported from interface for convenience in adapter implementations.
|
|
2782
|
+
*/
|
|
2783
|
+
type ArgumentGetter<TRequest> = ArgumentGetterFn<TRequest>;
|
|
2784
|
+
/**
|
|
2785
|
+
* Internal alias for FormatArgumentsFn from interface.
|
|
2786
|
+
* Not re-exported to avoid duplicate exports - use FormatArgumentsFn from interfaces instead.
|
|
2787
|
+
*/
|
|
2788
|
+
type FormatArgumentsFn<TRequest> = FormatArgumentsFn$1<TRequest>;
|
|
2789
|
+
/**
|
|
2790
|
+
* Static handler - can be called without a scoped container.
|
|
2791
|
+
*/
|
|
2792
|
+
type AbstractStaticHandler<TRequest, TReply = void> = {
|
|
2793
|
+
isStatic: true;
|
|
2794
|
+
handler: (request: TRequest, reply: TReply) => Promise<any>;
|
|
2795
|
+
};
|
|
2796
|
+
/**
|
|
2797
|
+
* Dynamic handler - requires a scoped container for resolution.
|
|
2798
|
+
*/
|
|
2799
|
+
type AbstractDynamicHandler<TRequest, TReply = void> = {
|
|
2800
|
+
isStatic: false;
|
|
2801
|
+
handler: (scoped: ScopedContainer, request: TRequest, reply: TReply) => Promise<any>;
|
|
2802
|
+
};
|
|
2803
|
+
/**
|
|
2804
|
+
* Handler result - either static or dynamic.
|
|
2805
|
+
*/
|
|
2806
|
+
type AbstractHandlerResult<TRequest, TReply = void> = AbstractStaticHandler<TRequest, TReply> | AbstractDynamicHandler<TRequest, TReply>;
|
|
2807
|
+
/**
|
|
2808
|
+
* Context passed to handler creation methods.
|
|
2809
|
+
*/
|
|
2810
|
+
interface HandlerContext<TConfig extends BaseEndpointOptions = BaseEndpointOptions> {
|
|
2811
|
+
methodName: string;
|
|
2812
|
+
statusCode: number;
|
|
2813
|
+
headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
|
|
2814
|
+
handlerMetadata: HandlerMetadata<TConfig>;
|
|
2815
|
+
hasArguments: boolean;
|
|
2816
|
+
}
|
|
2817
|
+
/**
|
|
2818
|
+
* Abstract base class for HTTP handler adapter services.
|
|
2819
|
+
*
|
|
2820
|
+
* Provides shared logic for:
|
|
2821
|
+
* - Controller resolution (singleton vs request-scoped)
|
|
2822
|
+
* - Argument formatting (sync/async detection)
|
|
2823
|
+
* - Handler generation with static/dynamic branching
|
|
2824
|
+
* - Standardized error handling
|
|
2825
|
+
*
|
|
2826
|
+
* Adapters implement abstract methods for framework-specific behavior:
|
|
2827
|
+
* - Request parsing (query, body, URL params)
|
|
2828
|
+
* - Response creation
|
|
2829
|
+
* - Schema provision
|
|
2830
|
+
*
|
|
2831
|
+
* Supports all adapter types:
|
|
2832
|
+
* - Endpoint adapters: JSON request/response with validation
|
|
2833
|
+
* - Stream adapters: Streaming responses with extra context
|
|
2834
|
+
* - Multipart adapters: Form data parsing (extends endpoint)
|
|
2835
|
+
*
|
|
2836
|
+
* @typeParam TRequest - Framework request type (BunRequest, FastifyRequest)
|
|
2837
|
+
* @typeParam TReply - Framework reply type (void for Bun, FastifyReply)
|
|
2838
|
+
* @typeParam TConfig - Endpoint configuration type
|
|
2839
|
+
*/
|
|
2840
|
+
declare abstract class AbstractHandlerAdapterService<TRequest, TReply = void, TConfig extends BaseEndpointOptions = BaseEndpointOptions> {
|
|
2841
|
+
protected instanceResolver: InstanceResolverService;
|
|
2842
|
+
protected options: NaviosApplicationOptions;
|
|
2843
|
+
/**
|
|
2844
|
+
* Creates argument getter functions for extracting data from requests.
|
|
2845
|
+
*
|
|
2846
|
+
* Each getter populates a target object with data from the request
|
|
2847
|
+
* (query params, body, URL params, etc.).
|
|
2848
|
+
*
|
|
2849
|
+
* Implementation varies by adapter type:
|
|
2850
|
+
* - Endpoint: JSON body parsing with schema validation
|
|
2851
|
+
* - Stream: Same as endpoint (body + query + url params)
|
|
2852
|
+
* - Multipart: FormData/multipart stream parsing
|
|
2853
|
+
*
|
|
2854
|
+
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
2855
|
+
* @returns Array of getter functions
|
|
2856
|
+
*/
|
|
2857
|
+
protected abstract createArgumentGetters(handlerMetadata: HandlerMetadata<TConfig>): ArgumentGetter<TRequest>[];
|
|
2858
|
+
/**
|
|
2859
|
+
* Creates a static handler for singleton controllers.
|
|
2860
|
+
*
|
|
2861
|
+
* Implementation varies by adapter type:
|
|
2862
|
+
* - Endpoint: Invoke method(args), serialize response as JSON
|
|
2863
|
+
* - Stream: Invoke method(args, streamContext), return Response/use reply
|
|
2864
|
+
*
|
|
2865
|
+
* @param boundMethod - Pre-bound controller method
|
|
2866
|
+
* @param formatArguments - Function to format request arguments
|
|
2867
|
+
* @param context - Handler context with metadata
|
|
2868
|
+
* @returns Static handler result
|
|
2869
|
+
*/
|
|
2870
|
+
protected abstract createStaticHandler(boundMethod: (...args: any[]) => Promise<any>, formatArguments: FormatArgumentsFn<TRequest>, context: HandlerContext<TConfig>): AbstractStaticHandler<TRequest, TReply>;
|
|
2871
|
+
/**
|
|
2872
|
+
* Creates a dynamic handler for request-scoped controllers.
|
|
2873
|
+
*
|
|
2874
|
+
* Implementation varies by adapter type:
|
|
2875
|
+
* - Endpoint: Resolve controller per-request, invoke method(args)
|
|
2876
|
+
* - Stream: Resolve controller per-request, invoke method(args, streamContext)
|
|
2877
|
+
*
|
|
2878
|
+
* @param resolution - Instance resolution with resolve function
|
|
2879
|
+
* @param formatArguments - Function to format request arguments
|
|
2880
|
+
* @param context - Handler context with metadata
|
|
2881
|
+
* @returns Dynamic handler result
|
|
2882
|
+
*/
|
|
2883
|
+
protected abstract createDynamicHandler(resolution: InstanceResolution, formatArguments: FormatArgumentsFn<TRequest>, context: HandlerContext<TConfig>): AbstractDynamicHandler<TRequest, TReply>;
|
|
2884
|
+
/**
|
|
2885
|
+
* Prepares argument getters for parsing request data.
|
|
2886
|
+
*
|
|
2887
|
+
* Public alias for createArgumentGetters to satisfy interface contracts.
|
|
2888
|
+
* Subclasses should override createArgumentGetters instead.
|
|
2889
|
+
*
|
|
2890
|
+
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
2891
|
+
* @returns Array of getter functions
|
|
2892
|
+
*/
|
|
2893
|
+
prepareArguments(handlerMetadata: HandlerMetadata<TConfig>): ArgumentGetter<TRequest>[];
|
|
2894
|
+
/**
|
|
2895
|
+
* Checks if the handler has any validation schemas defined.
|
|
2896
|
+
*
|
|
2897
|
+
* Override in subclasses to add additional schema checks
|
|
2898
|
+
* (e.g., response schema validation for endpoint adapters).
|
|
2899
|
+
*
|
|
2900
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
2901
|
+
* @returns true if handler has schemas
|
|
2902
|
+
*/
|
|
2903
|
+
hasSchema(handlerMetadata: HandlerMetadata<TConfig>): boolean;
|
|
2904
|
+
/**
|
|
2905
|
+
* Provides schema information for the framework's validation system.
|
|
2906
|
+
*
|
|
2907
|
+
* Override in subclasses for frameworks that support schema registration
|
|
2908
|
+
* (e.g., Fastify). Default returns empty object (suitable for Bun).
|
|
2909
|
+
*
|
|
2910
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
2911
|
+
* @returns Schema object for framework registration
|
|
2912
|
+
*/
|
|
2913
|
+
provideSchema(_handlerMetadata: HandlerMetadata<TConfig>): Record<string, any>;
|
|
2914
|
+
/**
|
|
2915
|
+
* Creates a request handler function for the endpoint.
|
|
2916
|
+
*
|
|
2917
|
+
* This method orchestrates the entire handler creation:
|
|
2918
|
+
* 1. Prepares argument getters for request parsing
|
|
2919
|
+
* 2. Builds optimized formatArguments function (sync/async)
|
|
2920
|
+
* 3. Resolves the controller (singleton vs request-scoped)
|
|
2921
|
+
* 4. Creates appropriate handler (static or dynamic)
|
|
2922
|
+
*
|
|
2923
|
+
* @param controller - Controller class containing the handler method
|
|
2924
|
+
* @param handlerMetadata - Handler metadata with configuration
|
|
2925
|
+
* @returns Handler result (static or dynamic)
|
|
2926
|
+
*/
|
|
2927
|
+
provideHandler(controller: ClassType, handlerMetadata: HandlerMetadata<TConfig>): Promise<AbstractHandlerResult<TRequest, TReply>>;
|
|
2928
|
+
/**
|
|
2929
|
+
* Builds a formatArguments function from argument getters.
|
|
2930
|
+
*
|
|
2931
|
+
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
2932
|
+
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
2933
|
+
* - If any getter is async: returns async function with Promise.all
|
|
2934
|
+
* - If no getters: returns frozen empty object (zero allocation)
|
|
2935
|
+
*
|
|
2936
|
+
* This method is public to allow composition-based adapters (like XML adapter)
|
|
2937
|
+
* to reuse the optimized formatArguments logic without inheritance.
|
|
2938
|
+
*
|
|
2939
|
+
* @param getters - Array of argument getter functions
|
|
2940
|
+
* @returns Function to format arguments from request
|
|
2941
|
+
*/
|
|
2942
|
+
buildFormatArguments(getters: ArgumentGetter<TRequest>[]): FormatArgumentsFn<TRequest>;
|
|
2943
|
+
/**
|
|
2944
|
+
* Checks if the URL pattern contains URL parameters.
|
|
2945
|
+
*
|
|
2946
|
+
* @param config - Endpoint configuration
|
|
2947
|
+
* @returns true if URL contains '$' parameter markers
|
|
2948
|
+
*/
|
|
2949
|
+
protected hasUrlParams(config: TConfig): boolean;
|
|
2950
|
+
/**
|
|
2951
|
+
* Wraps handler execution with standardized error handling.
|
|
2952
|
+
*
|
|
2953
|
+
* Re-throws HttpExceptions as-is for framework error handlers.
|
|
2954
|
+
* Other errors are re-thrown for global error handling.
|
|
2955
|
+
*
|
|
2956
|
+
* @param fn - Handler function to wrap
|
|
2957
|
+
* @returns Wrapped function with error handling
|
|
2958
|
+
*/
|
|
2959
|
+
protected wrapWithErrorHandling<T extends (...args: any[]) => Promise<any>>(fn: T): T;
|
|
2960
|
+
}
|
|
2961
|
+
//#endregion
|
|
2962
|
+
//#region src/services/guard-runner.service.d.mts
|
|
2963
|
+
declare class GuardRunnerService {
|
|
2964
|
+
private readonly errorProducer;
|
|
2965
|
+
private readonly logger;
|
|
2966
|
+
/**
|
|
2967
|
+
* Runs guards that need to be resolved from a scoped container.
|
|
2968
|
+
* Use this when guards have request-scoped dependencies.
|
|
2969
|
+
*/
|
|
2970
|
+
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
2971
|
+
/**
|
|
2972
|
+
* Runs pre-resolved guard instances.
|
|
2973
|
+
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
2974
|
+
*/
|
|
2975
|
+
runGuardsStatic(guardInstances: CanActivate[], executionContext: AbstractExecutionContext): Promise<boolean>;
|
|
2976
|
+
/**
|
|
2977
|
+
* Shared guard execution logic.
|
|
2978
|
+
* Iterates through guard instances and calls canActivate on each.
|
|
2979
|
+
*/
|
|
2980
|
+
private executeGuards;
|
|
2981
|
+
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
2982
|
+
}
|
|
2983
|
+
//#endregion
|
|
2984
|
+
//#region src/stores/request-id.store.d.mts
|
|
2985
|
+
/**
|
|
2986
|
+
* Generates a simple incremental request ID.
|
|
2987
|
+
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
2988
|
+
*
|
|
2989
|
+
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
2990
|
+
*/
|
|
2991
|
+
declare function generateRequestId(): string;
|
|
2992
|
+
/**
|
|
2993
|
+
* Enables or disables request ID propagation.
|
|
2994
|
+
* Called by NaviosFactory based on the enableRequestId option.
|
|
2995
|
+
*
|
|
2996
|
+
* @param enabled - Whether to enable request ID propagation
|
|
2997
|
+
*/
|
|
2998
|
+
declare function setRequestIdEnabled(enabled: boolean): void;
|
|
2999
|
+
/**
|
|
3000
|
+
* Runs a function with a request ID in the async local storage context.
|
|
3001
|
+
* If request ID propagation is disabled, the function is called directly
|
|
3002
|
+
* without AsyncLocalStorage overhead.
|
|
3003
|
+
*
|
|
3004
|
+
* @param requestId - The request ID to set for this context
|
|
3005
|
+
* @param fn - The function to run within this context
|
|
3006
|
+
* @returns The return value of the function
|
|
3007
|
+
*/
|
|
3008
|
+
declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
3009
|
+
/**
|
|
3010
|
+
* Gets the current request ID from the async local storage context.
|
|
3011
|
+
*
|
|
3012
|
+
* @returns The current request ID, or undefined if not in a request context
|
|
3013
|
+
*/
|
|
3014
|
+
declare function getRequestId(): string | undefined;
|
|
3015
|
+
//#endregion
|
|
3016
|
+
//#region src/tokens/adapter.token.d.mts
|
|
3017
|
+
declare const AdapterToken: InjectionToken<AbstractAdapterInterface, undefined, false>;
|
|
3018
|
+
//#endregion
|
|
3019
|
+
//#region src/tokens/endpoint-adapter.token.d.mts
|
|
3020
|
+
declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3021
|
+
//#endregion
|
|
3022
|
+
//#region src/tokens/execution-context.token.d.mts
|
|
3023
|
+
declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
3024
|
+
declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
3025
|
+
//#endregion
|
|
3026
|
+
//#region src/tokens/http-adapter.token.d.mts
|
|
3027
|
+
declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<HttpAdapterEnvironment>, undefined, false>;
|
|
3028
|
+
//#endregion
|
|
3029
|
+
//#region src/tokens/multipart-adapter.token.d.mts
|
|
3030
|
+
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3031
|
+
//#endregion
|
|
2525
3032
|
//#region src/tokens/navios-options.token.d.mts
|
|
2526
3033
|
declare const NaviosOptionsToken: InjectionToken<NaviosApplicationOptions, undefined, false>;
|
|
2527
3034
|
//#endregion
|
|
@@ -2532,10 +3039,35 @@ declare const Reply: InjectionToken<any, undefined, false>;
|
|
|
2532
3039
|
declare const Request: InjectionToken<any, undefined, false>;
|
|
2533
3040
|
//#endregion
|
|
2534
3041
|
//#region src/tokens/stream-adapter.token.d.mts
|
|
2535
|
-
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface
|
|
3042
|
+
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
2536
3043
|
//#endregion
|
|
2537
3044
|
//#region src/tokens/xml-stream-adapter.token.d.mts
|
|
2538
|
-
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface
|
|
3045
|
+
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3046
|
+
//#endregion
|
|
3047
|
+
//#region src/utils/adapter-supports.util.d.mts
|
|
3048
|
+
/**
|
|
3049
|
+
* Type guard to check if adapter implements a specific method.
|
|
3050
|
+
* Narrows the adapter type to include the method.
|
|
3051
|
+
*
|
|
3052
|
+
* @example
|
|
3053
|
+
* ```typescript
|
|
3054
|
+
* if (adapterSupports(adapter, 'getServer')) {
|
|
3055
|
+
* const server = adapter.getServer() // TypeScript knows this exists
|
|
3056
|
+
* }
|
|
3057
|
+
* ```
|
|
3058
|
+
*/
|
|
3059
|
+
declare function adapterSupports<TAdapter extends AbstractAdapterInterface, TMethod extends string>(adapter: TAdapter | null, method: TMethod): adapter is TAdapter & Record<TMethod, (...args: unknown[]) => unknown>;
|
|
3060
|
+
/**
|
|
3061
|
+
* Asserts adapter supports a method, throws if not.
|
|
3062
|
+
* Narrows type after assertion.
|
|
3063
|
+
*
|
|
3064
|
+
* @example
|
|
3065
|
+
* ```typescript
|
|
3066
|
+
* assertAdapterSupports(adapter, 'enableCors')
|
|
3067
|
+
* adapter.enableCors(options) // TypeScript knows this exists
|
|
3068
|
+
* ```
|
|
3069
|
+
*/
|
|
3070
|
+
declare function assertAdapterSupports<TAdapter extends AbstractAdapterInterface, TMethod extends string>(adapter: TAdapter | null, method: TMethod): asserts adapter is TAdapter & Record<TMethod, (...args: unknown[]) => unknown>;
|
|
2539
3071
|
//#endregion
|
|
2540
3072
|
//#region src/attribute.factory.d.mts
|
|
2541
3073
|
/**
|
|
@@ -2711,6 +3243,12 @@ declare class AttributeFactory {
|
|
|
2711
3243
|
static has<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
2712
3244
|
}
|
|
2713
3245
|
//#endregion
|
|
3246
|
+
//#region src/factories/adapter.factory.d.mts
|
|
3247
|
+
declare class AdapterFactory {
|
|
3248
|
+
private readonly environment;
|
|
3249
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
3250
|
+
}
|
|
3251
|
+
//#endregion
|
|
2714
3252
|
//#region src/factories/endpoint-adapter.factory.d.mts
|
|
2715
3253
|
declare class EndpointAdapterFactory {
|
|
2716
3254
|
private readonly environment;
|
|
@@ -2779,12 +3317,16 @@ declare class NaviosFactory {
|
|
|
2779
3317
|
/**
|
|
2780
3318
|
* Creates a new Navios application instance.
|
|
2781
3319
|
*
|
|
2782
|
-
* This method sets up the dependency injection container, registers the
|
|
3320
|
+
* This method sets up the dependency injection container, registers the adapter,
|
|
2783
3321
|
* configures logging, and initializes the application with the provided module.
|
|
2784
3322
|
*
|
|
3323
|
+
* @typeParam Environment - Adapter environment interface for type-safe access
|
|
3324
|
+
* to adapter-specific features. When specified, methods like `getServer()`,
|
|
3325
|
+
* `enableCors()`, `listen()`, and `configure()` will have proper types.
|
|
3326
|
+
*
|
|
2785
3327
|
* @param appModule - The root application module class decorated with @Module()
|
|
2786
3328
|
* @param options - Configuration options for the application
|
|
2787
|
-
* @param options.adapter -
|
|
3329
|
+
* @param options.adapter - Adapter environment (required for server functionality)
|
|
2788
3330
|
* @param options.logger - Logger configuration. Can be:
|
|
2789
3331
|
* - A LoggerService instance for custom logging
|
|
2790
3332
|
* - An array of LogLevel strings to enable specific log levels
|
|
@@ -2799,6 +3341,15 @@ declare class NaviosFactory {
|
|
|
2799
3341
|
* adapter: defineFastifyEnvironment(),
|
|
2800
3342
|
* })
|
|
2801
3343
|
*
|
|
3344
|
+
* // Type-safe setup with Fastify environment
|
|
3345
|
+
* import { FastifyEnvironment } from '@navios/adapter-fastify'
|
|
3346
|
+
*
|
|
3347
|
+
* const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
|
|
3348
|
+
* adapter: defineFastifyEnvironment(),
|
|
3349
|
+
* })
|
|
3350
|
+
* app.configure({ trustProxy: true })
|
|
3351
|
+
* const server = app.getServer() // FastifyInstance
|
|
3352
|
+
*
|
|
2802
3353
|
* // With custom logger configuration
|
|
2803
3354
|
* const app = await NaviosFactory.create(AppModule, {
|
|
2804
3355
|
* adapter: defineFastifyEnvironment(),
|
|
@@ -2813,10 +3364,10 @@ declare class NaviosFactory {
|
|
|
2813
3364
|
* })
|
|
2814
3365
|
* ```
|
|
2815
3366
|
*/
|
|
2816
|
-
static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<NaviosApplication
|
|
3367
|
+
static create<Environment extends AdapterEnvironment = DefaultAdapterEnvironment>(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<NaviosApplication<Environment>>;
|
|
2817
3368
|
private static registerEnvironment;
|
|
2818
3369
|
private static registerLoggerConfiguration;
|
|
2819
3370
|
}
|
|
2820
3371
|
//#endregion
|
|
2821
|
-
export {
|
|
2822
|
-
//# sourceMappingURL=index-
|
|
3372
|
+
export { ErrorResponder as $, envInt as $n, isString as $t, GuardRunnerService as A, getControllerMetadata as An, AbstractHttpHandlerAdapterInterface as At, InstanceResolverService as B, ControllerOptions as Bn, loggerOptionsSchema as Bt, ExecutionContextInjectionToken as C, extractModuleMetadata as Cn, ModuleExtension as Ct, getRequestId as D, ControllerMetadata as Dn, OmitIndexSignature as Dt, generateRequestId as E, hasModuleMetadata as En, HttpHeader as Et, ArgumentGetter as F, getEndpointMetadata as Fn, StaticHandler as Ft, InternalServerErrorResponderToken as G, ConfigServiceOptions as Gn, addLeadingSlash as Gt, NaviosApplication as H, EnvConfigProvider as Hn, ConsoleLogger as Ht, HandlerContext as I, Endpoint as In, AbstractHttpCorsOptions as It, ValidationErrorResponderService as J, ConfigServiceInterface as Jn, isFunction as Jt, NotFoundResponderToken as K, ConfigServiceOptionsSchema as Kn, isConstructor as Kt, ControllerResolution as L, EndpointParams as Ln, Logger as Lt, AbstractHandlerAdapterService as M, EndpointMetadataKey as Mn, DynamicHandler as Mt, AbstractHandlerResult as N, HandlerMetadata as Nn, FormatArgumentsFn$1 as Nt, runWithRequestId as O, ControllerMetadataKey as On, CanActivate as Ot, AbstractStaticHandler as P, getAllEndpointMetadata as Pn, HandlerResult as Pt, ErrorResponseProducerService as Q, PathValue as Qn, isPlainObject as Qt, ControllerResolverService as R, EndpointResult as Rn, LoggerOptions as Rt, ExecutionContext as S, ModuleMetadataKey as Sn, PluginDefinition as St, AdapterToken as T, getModuleMetadata as Tn, NaviosModule as Tt, NaviosApplicationOptions as U, provideConfig as Un, ConsoleLoggerOptions as Ut, MultiInstanceResolution as V, ConfigProviderOptions as Vn, LoggerInstance as Vt, ForbiddenResponderToken as W, ConfigService as Wn, LoggerService as Wt, InternalServerErrorResponderService as X, PathImpl as Xn, isNumber as Xt, NotFoundResponderService as Y, Path as Yn, isNil as Yt, ForbiddenResponderService as Z, PathImpl2 as Zn, isObject as Zt, Request as _, ManagedMetadata as _n, ModuleOptions as _t, RequestFactory as a, isLogLevel as an, NotFoundException as at, MultipartAdapterToken as b, hasManagedMetadata as bn, NaviosPlugin as bt, EndpointAdapterFactory as c, LogLevel as cn, BadRequestException as ct, ClassAttribute as d, AbstractHttpAdapterInterface as dn, Stream as dt, isSymbol as en, envString as er, ErrorResponse as et, ClassSchemaAttribute as f, AdapterEnvironment as fn, StreamParams as ft, StreamAdapterToken as g, AbstractAdapterInterface as gn, Module as gt, XmlStreamAdapterToken as h, AbstractExecutionContext as hn, MultipartResult as ht, ReplyFactory as i, isLogLevelEnabled as in, UnauthorizedException as it, AbstractDynamicHandler as j, hasControllerMetadata as jn, ArgumentGetterFn as jt, setRequestIdEnabled as k, extractControllerMetadata as kn, AbstractHttpListenOptions as kt, AdapterFactory as l, clc as ln, HttpException as lt, assertAdapterSupports as m, HttpAdapterEnvironment as mn, MultipartParams as mt, XmlStreamAdapterFactory as n, normalizePath as nn, FrameworkError as nt, MultipartAdapterFactory as o, filterLogLevels as on, InternalServerErrorException as ot, adapterSupports as p, DefaultAdapterEnvironment as pn, Multipart as pt, ValidationErrorResponderToken as q, ConfigServiceToken as qn, isEmpty as qt, StreamAdapterFactory as r, stripEndSlash as rn, ConflictException as rt, HttpAdapterFactory as s, LOG_LEVELS as sn, ForbiddenException as st, NaviosFactory as t, isUndefined as tn, ProblemDetails as tt, AttributeFactory as u, yellow as un, UseGuards as ut, Reply as v, NaviosManagedMetadataKey as vn, HttpCode as vt, EndpointAdapterToken as w, getModuleCustomEntry as wn, ModuleLoaderService as wt, HttpAdapterToken as x, ModuleMetadata as xn, PluginContext as xt, NaviosOptionsToken as y, getManagedMetadata as yn, Header as yt, InstanceResolution as z, Controller as zn, LoggerOutput as zt };
|
|
3373
|
+
//# sourceMappingURL=index-r0i2txmg.d.cts.map
|