@navios/core 1.0.0 → 2.0.0-alpha.0
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 +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
package/lib/index-DySQ6Dpd.d.mts
DELETED
|
@@ -1,3365 +0,0 @@
|
|
|
1
|
-
import * as _navios_di0 from "@navios/di";
|
|
2
|
-
import { AnyInjectableType, BoundInjectionToken, ClassType, ClassTypeWithArgument, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectableScope, InjectionToken, InjectionTokenSchemaType, Registry, ScopedContainer } from "@navios/di";
|
|
3
|
-
import z, { ZodDiscriminatedUnion, ZodObject, ZodType, z as z$1 } from "zod/v4";
|
|
4
|
-
import { BaseEndpointOptions, EndpointHandler, EndpointOptions, HttpMethod, RequestArgs, StreamHandler } from "@navios/builder";
|
|
5
|
-
import { InspectOptions } from "util";
|
|
6
|
-
import { OutgoingHttpHeaders } from "http";
|
|
7
|
-
|
|
8
|
-
//#region src/config/utils/helpers.d.mts
|
|
9
|
-
declare function envInt(key: keyof NodeJS.ProcessEnv, defaultValue: number): number;
|
|
10
|
-
declare function envString<DefaultValue extends string | undefined, Ensured = (DefaultValue extends string ? true : false)>(key: keyof NodeJS.ProcessEnv, defaultValue?: DefaultValue): Ensured extends true ? string : string | undefined;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/config/types.d.mts
|
|
13
|
-
/**
|
|
14
|
-
* Evaluates to `true` if `T` is `any`. `false` otherwise.
|
|
15
|
-
* (c) https://stackoverflow.com/a/68633327/5290447
|
|
16
|
-
*/
|
|
17
|
-
type IsAny<T> = unknown extends T ? [keyof T] extends [never] ? false : true : false;
|
|
18
|
-
type ExcludedParts = 'services' | 'mailer' | 'aws' | 'computedTimeRates' | 'aiModelsRates';
|
|
19
|
-
type ExcludedKeys = 'computedTimeRates' | 'aiModelsRates' | 'aiModel';
|
|
20
|
-
type PathImpl<T, Key$1 extends keyof T> = Key$1 extends string ? Key$1 extends ExcludedKeys ? never : IsAny<T[Key$1]> extends true ? never : T[Key$1] extends string ? never : T[Key$1] extends any[] ? never : T[Key$1] extends Record<string, any> ? Key$1 extends ExcludedParts ? `${Key$1}.${Exclude<keyof T[Key$1], keyof any[]> & string}` : `${Key$1}.${PathImpl<T[Key$1], Exclude<keyof T[Key$1], keyof any[]>> & string}` | `${Key$1}.${Exclude<keyof T[Key$1], keyof any[]> & string}` : never : never;
|
|
21
|
-
type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
|
|
22
|
-
type Path<T> = keyof T extends string ? PathImpl2<T> extends infer P ? P extends string | keyof T ? P : keyof T : keyof T : never;
|
|
23
|
-
type PathValue<T, P extends Path<T>> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends Path<T[Key]> ? PathValue<T[Key], Rest> : never : never : P extends keyof T ? T[P] : never;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/config/config-service.interface.d.mts
|
|
26
|
-
/**
|
|
27
|
-
* Interface for configuration service implementations.
|
|
28
|
-
*
|
|
29
|
-
* Provides type-safe access to configuration values with support for nested paths.
|
|
30
|
-
*
|
|
31
|
-
* @typeParam Config - The configuration object type
|
|
32
|
-
*/
|
|
33
|
-
interface ConfigServiceInterface<Config = Record<string, unknown>> {
|
|
34
|
-
/**
|
|
35
|
-
* Gets the entire configuration object.
|
|
36
|
-
*/
|
|
37
|
-
getConfig: () => Config;
|
|
38
|
-
/**
|
|
39
|
-
* Gets a configuration value by key path. Returns `null` if not found.
|
|
40
|
-
*
|
|
41
|
-
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
42
|
-
* @returns The configuration value or `null` if not found
|
|
43
|
-
*/
|
|
44
|
-
get: <Key$1 extends Path<Config>>(key: Key$1) => PathValue<Config, Key$1> | null;
|
|
45
|
-
/**
|
|
46
|
-
* Gets a configuration value by key path, or returns a default value if not found.
|
|
47
|
-
*
|
|
48
|
-
* @param key - Dot-separated path to the configuration value
|
|
49
|
-
* @param defaultValue - Default value to return if the key is not found
|
|
50
|
-
* @returns The configuration value or the default value
|
|
51
|
-
*/
|
|
52
|
-
getOrDefault: <Key$1 extends Path<Config>>(key: Key$1, defaultValue: PathValue<Config, Key$1>) => PathValue<Config, Key$1>;
|
|
53
|
-
/**
|
|
54
|
-
* Gets a configuration value by key path, or throws an error if not found.
|
|
55
|
-
*
|
|
56
|
-
* @param key - Dot-separated path to the configuration value
|
|
57
|
-
* @param errorMessage - Optional custom error message
|
|
58
|
-
* @returns The configuration value
|
|
59
|
-
* @throws Error if the key is not found
|
|
60
|
-
*/
|
|
61
|
-
getOrThrow: <Key$1 extends Path<Config>>(key: Key$1, errorMessage?: string) => PathValue<Config, Key$1>;
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/config/config.service.d.mts
|
|
65
|
-
/**
|
|
66
|
-
* Schema for validating configuration service options.
|
|
67
|
-
*/
|
|
68
|
-
declare const ConfigServiceOptionsSchema: z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>;
|
|
69
|
-
/**
|
|
70
|
-
* Type for configuration service options.
|
|
71
|
-
*/
|
|
72
|
-
type ConfigServiceOptions = z$1.infer<typeof ConfigServiceOptionsSchema>;
|
|
73
|
-
/**
|
|
74
|
-
* Injection token for ConfigService.
|
|
75
|
-
*/
|
|
76
|
-
declare const ConfigServiceToken: InjectionToken<ConfigServiceInterface<Record<string, unknown>>, z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>, true>;
|
|
77
|
-
/**
|
|
78
|
-
* Service for managing application configuration with type-safe access.
|
|
79
|
-
*
|
|
80
|
-
* Provides methods to access configuration values using dot-notation paths
|
|
81
|
-
* with full TypeScript type inference.
|
|
82
|
-
*
|
|
83
|
-
* @typeParam Config - The configuration object type
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```typescript
|
|
87
|
-
* interface AppConfig {
|
|
88
|
-
* database: {
|
|
89
|
-
* host: string
|
|
90
|
-
* port: number
|
|
91
|
-
* }
|
|
92
|
-
* api: {
|
|
93
|
-
* timeout: number
|
|
94
|
-
* }
|
|
95
|
-
* }
|
|
96
|
-
*
|
|
97
|
-
* @Injectable()
|
|
98
|
-
* export class DatabaseService {
|
|
99
|
-
* private config = inject(MyConfigService)
|
|
100
|
-
*
|
|
101
|
-
* connect() {
|
|
102
|
-
* const host = this.config.getOrThrow('database.host')
|
|
103
|
-
* const port = this.config.getOrDefault('database.port', 5432)
|
|
104
|
-
* // host is typed as string, port is typed as number
|
|
105
|
-
* }
|
|
106
|
-
* }
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare class ConfigService<Config extends ConfigServiceOptions = Record<string, unknown>> implements ConfigServiceInterface<Config> {
|
|
110
|
-
private config;
|
|
111
|
-
private readonly logger;
|
|
112
|
-
/**
|
|
113
|
-
* Creates a new ConfigService instance.
|
|
114
|
-
*
|
|
115
|
-
* @param config - The configuration object
|
|
116
|
-
*/
|
|
117
|
-
constructor(config?: Config);
|
|
118
|
-
/**
|
|
119
|
-
* Gets the entire configuration object.
|
|
120
|
-
*
|
|
121
|
-
* @returns The complete configuration object
|
|
122
|
-
*/
|
|
123
|
-
getConfig(): Config;
|
|
124
|
-
/**
|
|
125
|
-
* Gets a configuration value by key path.
|
|
126
|
-
*
|
|
127
|
-
* Returns `null` if the key is not found or if any part of the path is invalid.
|
|
128
|
-
*
|
|
129
|
-
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
130
|
-
* @returns The configuration value or `null` if not found
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* const host = config.get('database.host') // string | null
|
|
135
|
-
* const port = config.get('database.port') // number | null
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
get<Key$1 extends Path<Config>>(key: Key$1): PathValue<Config, Key$1> | null;
|
|
139
|
-
/**
|
|
140
|
-
* Gets a configuration value by key path, or returns a default value if not found.
|
|
141
|
-
*
|
|
142
|
-
* @param key - Dot-separated path to the configuration value
|
|
143
|
-
* @param defaultValue - Default value to return if the key is not found
|
|
144
|
-
* @returns The configuration value or the default value
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```typescript
|
|
148
|
-
* const port = config.getOrDefault('database.port', 5432) // number
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
getOrDefault<Key$1 extends Path<Config>>(key: Key$1, defaultValue: PathValue<Config, Key$1>): PathValue<Config, Key$1>;
|
|
152
|
-
/**
|
|
153
|
-
* Gets a configuration value by key path, or throws an error if not found.
|
|
154
|
-
*
|
|
155
|
-
* @param key - Dot-separated path to the configuration value
|
|
156
|
-
* @param errorMessage - Optional custom error message
|
|
157
|
-
* @returns The configuration value
|
|
158
|
-
* @throws Error if the key is not found
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```typescript
|
|
162
|
-
* const host = config.getOrThrow('database.host') // string (throws if not found)
|
|
163
|
-
* const apiKey = config.getOrThrow('api.key', 'API key is required') // string
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
getOrThrow<Key$1 extends Path<Config>>(key: Key$1, errorMessage?: string): PathValue<Config, Key$1>;
|
|
167
|
-
}
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/config/config.provider.d.mts
|
|
170
|
-
/**
|
|
171
|
-
* Schema for configuration provider options.
|
|
172
|
-
*/
|
|
173
|
-
declare const ConfigProviderOptions: z$1.ZodObject<{
|
|
174
|
-
load: z$1.ZodFunction<z$1.core.$ZodFunctionArgs, z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
175
|
-
}, z$1.core.$strip>;
|
|
176
|
-
/**
|
|
177
|
-
* Creates a factory injection token for ConfigService that loads configuration asynchronously.
|
|
178
|
-
*
|
|
179
|
-
* Use this when you need to load configuration from a file, database, or other async source.
|
|
180
|
-
*
|
|
181
|
-
* @param options - Configuration provider options
|
|
182
|
-
* @param options.load - Async function that loads and returns the configuration object
|
|
183
|
-
* @returns A factory injection token for ConfigService
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```typescript
|
|
187
|
-
* const MyConfigService = provideConfig({
|
|
188
|
-
* load: async () => {
|
|
189
|
-
* const config = await loadConfigFromFile('config.json')
|
|
190
|
-
* return config
|
|
191
|
-
* },
|
|
192
|
-
* })
|
|
193
|
-
*
|
|
194
|
-
* // Use in module setup
|
|
195
|
-
* container.bind(ConfigServiceToken).toFactory(configProvider)
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
declare function provideConfig<ConfigMap extends ConfigServiceOptions>(options: z$1.input<typeof ConfigProviderOptions>): FactoryInjectionToken<ConfigService<ConfigMap>, typeof ConfigServiceOptionsSchema>;
|
|
199
|
-
/**
|
|
200
|
-
* Pre-configured ConfigService provider that uses environment variables.
|
|
201
|
-
*
|
|
202
|
-
* Provides a ConfigService instance bound to `process.env`.
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* // Use environment variables as configuration
|
|
207
|
-
* container.bind(ConfigServiceToken).toValue(EnvConfigProvider)
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
declare const EnvConfigProvider: _navios_di0.BoundInjectionToken<ConfigService<Record<string, string>>, z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region src/decorators/controller.decorator.d.mts
|
|
213
|
-
/**
|
|
214
|
-
* Options for configuring a Navios controller.
|
|
215
|
-
*/
|
|
216
|
-
interface ControllerOptions {
|
|
217
|
-
/**
|
|
218
|
-
* Guards to apply to all endpoints in this controller.
|
|
219
|
-
* Guards are executed in reverse order (last guard first).
|
|
220
|
-
*/
|
|
221
|
-
guards?: ClassType[] | Set<ClassType>;
|
|
222
|
-
/**
|
|
223
|
-
* Registry to use for the controller.
|
|
224
|
-
* Registry is used to store the controller and its endpoints.
|
|
225
|
-
*/
|
|
226
|
-
registry?: Registry;
|
|
227
|
-
/**
|
|
228
|
-
* Priority to use for the controller.
|
|
229
|
-
* Priority is used to sort the controller in the registry.
|
|
230
|
-
*/
|
|
231
|
-
priority?: number;
|
|
232
|
-
/**
|
|
233
|
-
* Scope to use for the controller.
|
|
234
|
-
* Scope is used to determine the scope of the controller.
|
|
235
|
-
*/
|
|
236
|
-
scope?: InjectableScope;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Decorator that marks a class as a Navios controller.
|
|
240
|
-
*
|
|
241
|
-
* Controllers handle HTTP requests and define endpoints.
|
|
242
|
-
* They are request-scoped by default, meaning a new instance is created for each request.
|
|
243
|
-
*
|
|
244
|
-
* @param options - Controller configuration options
|
|
245
|
-
* @returns A class decorator
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```typescript
|
|
249
|
-
* @Controller({ guards: [AuthGuard] })
|
|
250
|
-
* export class UserController {
|
|
251
|
-
* @Endpoint(getUserEndpoint)
|
|
252
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
253
|
-
* // Handle request
|
|
254
|
-
* }
|
|
255
|
-
* }
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
declare function Controller({
|
|
259
|
-
guards,
|
|
260
|
-
registry,
|
|
261
|
-
priority,
|
|
262
|
-
scope
|
|
263
|
-
}?: ControllerOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/decorators/endpoint.decorator.d.mts
|
|
266
|
-
/**
|
|
267
|
-
* Extracts the typed parameters for an endpoint handler function.
|
|
268
|
-
*
|
|
269
|
-
* This utility type extracts URL parameters, query parameters, and request body
|
|
270
|
-
* from an endpoint declaration and flattens them into a single object.
|
|
271
|
-
*
|
|
272
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* ```typescript
|
|
276
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
277
|
-
* method: 'get',
|
|
278
|
-
* url: '/users/$userId',
|
|
279
|
-
* querySchema: z.object({ include: z.string().optional() }),
|
|
280
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
281
|
-
* })
|
|
282
|
-
*
|
|
283
|
-
* @Endpoint(getUserEndpoint)
|
|
284
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
285
|
-
* // request.urlParams.userId is typed as string
|
|
286
|
-
* // request.query.include is typed as string | undefined
|
|
287
|
-
* }
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
type EndpointParams<EndpointDeclaration extends EndpointHandler<Config, false>, Config extends EndpointOptions = EndpointDeclaration['config']> = RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>;
|
|
291
|
-
/**
|
|
292
|
-
* Extracts the typed return value for an endpoint handler function.
|
|
293
|
-
*
|
|
294
|
-
* This utility type extracts the response schema from an endpoint declaration
|
|
295
|
-
* and returns the appropriate Promise type.
|
|
296
|
-
*
|
|
297
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```typescript
|
|
301
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
302
|
-
* method: 'get',
|
|
303
|
-
* url: '/users/$userId',
|
|
304
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
305
|
-
* })
|
|
306
|
-
*
|
|
307
|
-
* @Endpoint(getUserEndpoint)
|
|
308
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
|
|
309
|
-
* return { id: '1', name: 'John' } // Type-checked against responseSchema
|
|
310
|
-
* }
|
|
311
|
-
* ```
|
|
312
|
-
*/
|
|
313
|
-
type EndpointResult<EndpointDeclaration extends {
|
|
314
|
-
config: EndpointOptions;
|
|
315
|
-
}> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z$1.input<Options[number]>> : Promise<z$1.input<EndpointDeclaration['config']['responseSchema']>>;
|
|
316
|
-
/**
|
|
317
|
-
* Decorator that marks a method as an HTTP endpoint.
|
|
318
|
-
*
|
|
319
|
-
* The endpoint must be defined using @navios/builder's `declareEndpoint` method.
|
|
320
|
-
* This ensures type safety and consistency between client and server.
|
|
321
|
-
*
|
|
322
|
-
* @param endpoint - The endpoint declaration from @navios/builder
|
|
323
|
-
* @returns A method decorator
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* ```typescript
|
|
327
|
-
* import { builder } from '@navios/builder'
|
|
328
|
-
*
|
|
329
|
-
* const api = builder()
|
|
330
|
-
* const getUserEndpoint = api.declareEndpoint({
|
|
331
|
-
* method: 'get',
|
|
332
|
-
* url: '/users/$userId',
|
|
333
|
-
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
334
|
-
* })
|
|
335
|
-
*
|
|
336
|
-
* @Controller()
|
|
337
|
-
* export class UserController {
|
|
338
|
-
* @Endpoint(getUserEndpoint)
|
|
339
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
340
|
-
* const { userId } = request.urlParams
|
|
341
|
-
* return { id: userId, name: 'John' }
|
|
342
|
-
* }
|
|
343
|
-
* }
|
|
344
|
-
* ```
|
|
345
|
-
*/
|
|
346
|
-
declare function Endpoint<const Config extends EndpointOptions>(endpoint: EndpointHandler<Config, false>): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
347
|
-
declare function Endpoint<const Config extends EndpointOptions>(endpoint: EndpointHandler<Config, false>): (target: () => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
348
|
-
//#endregion
|
|
349
|
-
//#region src/metadata/handler.metadata.d.mts
|
|
350
|
-
declare const EndpointMetadataKey: unique symbol;
|
|
351
|
-
interface HandlerMetadata<Config = null> {
|
|
352
|
-
classMethod: string;
|
|
353
|
-
url: string;
|
|
354
|
-
successStatusCode: number;
|
|
355
|
-
adapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined> | ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface> | null;
|
|
356
|
-
headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
|
|
357
|
-
httpMethod: HttpMethod;
|
|
358
|
-
config: Config;
|
|
359
|
-
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
360
|
-
customAttributes: Map<string | symbol, any>;
|
|
361
|
-
}
|
|
362
|
-
declare function getAllEndpointMetadata(context: ClassMethodDecoratorContext | ClassDecoratorContext): Set<HandlerMetadata<any>>;
|
|
363
|
-
declare function getEndpointMetadata<Config = any>(target: Function, context: ClassMethodDecoratorContext): HandlerMetadata<Config>;
|
|
364
|
-
//#endregion
|
|
365
|
-
//#region src/metadata/controller.metadata.d.mts
|
|
366
|
-
declare const ControllerMetadataKey: unique symbol;
|
|
367
|
-
interface ControllerMetadata {
|
|
368
|
-
endpoints: Set<HandlerMetadata>;
|
|
369
|
-
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
370
|
-
customAttributes: Map<string | symbol, any>;
|
|
371
|
-
}
|
|
372
|
-
declare function getControllerMetadata(target: ClassType, context: ClassDecoratorContext): ControllerMetadata;
|
|
373
|
-
declare function extractControllerMetadata(target: ClassType): ControllerMetadata;
|
|
374
|
-
declare function hasControllerMetadata(target: ClassType): boolean;
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region src/metadata/module.metadata.d.mts
|
|
377
|
-
declare const ModuleMetadataKey: unique symbol;
|
|
378
|
-
interface ModuleMetadata {
|
|
379
|
-
controllers: Set<ClassType>;
|
|
380
|
-
imports: Set<ClassType>;
|
|
381
|
-
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
382
|
-
overrides: Set<ClassType>;
|
|
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>;
|
|
395
|
-
}
|
|
396
|
-
declare function getModuleMetadata(target: ClassType, context: ClassDecoratorContext): ModuleMetadata;
|
|
397
|
-
declare function extractModuleMetadata(target: ClassType): ModuleMetadata;
|
|
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;
|
|
420
|
-
//#endregion
|
|
421
|
-
//#region src/metadata/navios-managed.metadata.d.mts
|
|
422
|
-
/**
|
|
423
|
-
* Symbol used to identify Navios-managed classes (Controller, Module, MessageController, etc.).
|
|
424
|
-
* This allows AttributeFactory to work with any Navios-managed class type generically.
|
|
425
|
-
*/
|
|
426
|
-
declare const NaviosManagedMetadataKey: unique symbol;
|
|
427
|
-
/**
|
|
428
|
-
* Interface for metadata that has custom attributes.
|
|
429
|
-
* Used by Navios-managed classes (Controller, Module, MessageController, etc.).
|
|
430
|
-
*/
|
|
431
|
-
interface ManagedMetadata {
|
|
432
|
-
customAttributes: Map<string | symbol, any>;
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Gets managed metadata from a class if it exists.
|
|
436
|
-
* This is a generic function that works with any Navios-managed class type.
|
|
437
|
-
*
|
|
438
|
-
* @param target - The class to check
|
|
439
|
-
* @returns The metadata with customAttributes, or null if not managed
|
|
440
|
-
*/
|
|
441
|
-
declare function getManagedMetadata(target: ClassType): ManagedMetadata | null;
|
|
442
|
-
/**
|
|
443
|
-
* Checks if a class is Navios-managed (has managed metadata).
|
|
444
|
-
*
|
|
445
|
-
* @param target - The class to check
|
|
446
|
-
* @returns true if the class is Navios-managed
|
|
447
|
-
*/
|
|
448
|
-
declare function hasManagedMetadata(target: ClassType): boolean;
|
|
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
|
|
479
|
-
//#region src/interfaces/abstract-execution-context.inteface.d.mts
|
|
480
|
-
/**
|
|
481
|
-
* Interface providing access to the execution context during request handling.
|
|
482
|
-
*
|
|
483
|
-
* The execution context provides access to metadata and request/reply objects
|
|
484
|
-
* for the current request. It is available in guards and can be injected into
|
|
485
|
-
* services if needed.
|
|
486
|
-
*
|
|
487
|
-
* @example
|
|
488
|
-
* ```typescript
|
|
489
|
-
* @Injectable()
|
|
490
|
-
* export class AuthGuard implements CanActivate {
|
|
491
|
-
* async canActivate(context: AbstractExecutionContext): Promise<boolean> {
|
|
492
|
-
* const request = context.getRequest()
|
|
493
|
-
* const handler = context.getHandler()
|
|
494
|
-
* // Access request and handler metadata
|
|
495
|
-
* return true
|
|
496
|
-
* }
|
|
497
|
-
* }
|
|
498
|
-
* ```
|
|
499
|
-
*/
|
|
500
|
-
interface AbstractExecutionContext {
|
|
501
|
-
/**
|
|
502
|
-
* Gets the metadata for the module containing the current endpoint.
|
|
503
|
-
*/
|
|
504
|
-
getModule(): ModuleMetadata;
|
|
505
|
-
/**
|
|
506
|
-
* Gets the metadata for the controller containing the current endpoint.
|
|
507
|
-
*/
|
|
508
|
-
getController(): ControllerMetadata;
|
|
509
|
-
/**
|
|
510
|
-
* Gets the metadata for the current endpoint handler.
|
|
511
|
-
*/
|
|
512
|
-
getHandler(): HandlerMetadata;
|
|
513
|
-
/**
|
|
514
|
-
* Gets the HTTP request object (adapter-specific).
|
|
515
|
-
*/
|
|
516
|
-
getRequest(): any;
|
|
517
|
-
/**
|
|
518
|
-
* Gets the HTTP reply object (adapter-specific).
|
|
519
|
-
*/
|
|
520
|
-
getReply(): any;
|
|
521
|
-
}
|
|
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
|
|
657
|
-
//#region src/logger/utils/cli-colors.util.d.mts
|
|
658
|
-
declare const clc: {
|
|
659
|
-
bold: (text: string) => string;
|
|
660
|
-
green: (text: string) => string;
|
|
661
|
-
yellow: (text: string) => string;
|
|
662
|
-
red: (text: string) => string;
|
|
663
|
-
magentaBright: (text: string) => string;
|
|
664
|
-
cyanBright: (text: string) => string;
|
|
665
|
-
};
|
|
666
|
-
declare const yellow: (text: string) => string;
|
|
667
|
-
//#endregion
|
|
668
|
-
//#region src/logger/log-levels.d.mts
|
|
669
|
-
/**
|
|
670
|
-
* Available log levels in order of severity (lowest to highest).
|
|
671
|
-
*/
|
|
672
|
-
declare const LOG_LEVELS: ["verbose", "debug", "log", "warn", "error", "fatal"];
|
|
673
|
-
/**
|
|
674
|
-
* Log level type.
|
|
675
|
-
*
|
|
676
|
-
* Represents the severity level of a log message.
|
|
677
|
-
* Levels are: 'verbose', 'debug', 'log', 'warn', 'error', 'fatal'
|
|
678
|
-
*
|
|
679
|
-
* @publicApi
|
|
680
|
-
*/
|
|
681
|
-
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
682
|
-
//#endregion
|
|
683
|
-
//#region src/logger/utils/filter-log-levelts.util.d.mts
|
|
684
|
-
/**
|
|
685
|
-
* @publicApi
|
|
686
|
-
*/
|
|
687
|
-
declare function filterLogLevels(parseableString?: string): LogLevel[];
|
|
688
|
-
//#endregion
|
|
689
|
-
//#region src/logger/utils/is-log-level.util.d.mts
|
|
690
|
-
/**
|
|
691
|
-
* @publicApi
|
|
692
|
-
*/
|
|
693
|
-
declare function isLogLevel(maybeLogLevel: any): maybeLogLevel is LogLevel;
|
|
694
|
-
//#endregion
|
|
695
|
-
//#region src/logger/utils/is-log-level-enabled.d.mts
|
|
696
|
-
/**
|
|
697
|
-
* Checks if target level is enabled.
|
|
698
|
-
* @param targetLevel target level
|
|
699
|
-
* @param logLevels array of enabled log levels
|
|
700
|
-
*/
|
|
701
|
-
declare function isLogLevelEnabled(targetLevel: LogLevel, logLevels: LogLevel[] | undefined): boolean;
|
|
702
|
-
//#endregion
|
|
703
|
-
//#region src/logger/utils/shared.utils.d.mts
|
|
704
|
-
declare const isUndefined: (obj: any) => obj is undefined;
|
|
705
|
-
declare const isObject: (fn: any) => fn is object;
|
|
706
|
-
declare const isPlainObject: (fn: any) => fn is object;
|
|
707
|
-
declare const addLeadingSlash: (path?: string) => string;
|
|
708
|
-
declare const normalizePath: (path?: string) => string;
|
|
709
|
-
declare const stripEndSlash: (path: string) => string;
|
|
710
|
-
declare const isFunction: (val: any) => val is Function;
|
|
711
|
-
declare const isString: (val: any) => val is string;
|
|
712
|
-
declare const isNumber: (val: any) => val is number;
|
|
713
|
-
declare const isConstructor: (val: any) => boolean;
|
|
714
|
-
declare const isNil: (val: any) => val is null | undefined;
|
|
715
|
-
declare const isEmpty: (array: any) => boolean;
|
|
716
|
-
declare const isSymbol: (val: any) => val is symbol;
|
|
717
|
-
//#endregion
|
|
718
|
-
//#region src/logger/logger-service.interface.d.mts
|
|
719
|
-
/**
|
|
720
|
-
* @publicApi
|
|
721
|
-
*/
|
|
722
|
-
interface LoggerService {
|
|
723
|
-
/**
|
|
724
|
-
* Write a 'log' level log.
|
|
725
|
-
*/
|
|
726
|
-
log(message: any, ...optionalParams: any[]): any;
|
|
727
|
-
/**
|
|
728
|
-
* Write an 'error' level log.
|
|
729
|
-
*/
|
|
730
|
-
error(message: any, ...optionalParams: any[]): any;
|
|
731
|
-
/**
|
|
732
|
-
* Write a 'warn' level log.
|
|
733
|
-
*/
|
|
734
|
-
warn(message: any, ...optionalParams: any[]): any;
|
|
735
|
-
/**
|
|
736
|
-
* Write a 'debug' level log.
|
|
737
|
-
*/
|
|
738
|
-
debug?(message: any, ...optionalParams: any[]): any;
|
|
739
|
-
/**
|
|
740
|
-
* Write a 'verbose' level log.
|
|
741
|
-
*/
|
|
742
|
-
verbose?(message: any, ...optionalParams: any[]): any;
|
|
743
|
-
/**
|
|
744
|
-
* Write a 'fatal' level log.
|
|
745
|
-
*/
|
|
746
|
-
fatal?(message: any, ...optionalParams: any[]): any;
|
|
747
|
-
/**
|
|
748
|
-
* Set log levels.
|
|
749
|
-
* @param levels log levels
|
|
750
|
-
*/
|
|
751
|
-
setLogLevels?(levels: LogLevel[]): any;
|
|
752
|
-
}
|
|
753
|
-
//#endregion
|
|
754
|
-
//#region src/logger/console-logger.service.d.mts
|
|
755
|
-
/**
|
|
756
|
-
* @publicApi
|
|
757
|
-
*/
|
|
758
|
-
interface ConsoleLoggerOptions {
|
|
759
|
-
/**
|
|
760
|
-
* Enabled log levels.
|
|
761
|
-
*/
|
|
762
|
-
logLevels?: LogLevel[];
|
|
763
|
-
/**
|
|
764
|
-
* If enabled, will print timestamp difference between current and previous log message.
|
|
765
|
-
* Note: This option is not used when `json` is enabled.
|
|
766
|
-
* @default false
|
|
767
|
-
*/
|
|
768
|
-
showTimeDiff?: boolean;
|
|
769
|
-
/**
|
|
770
|
-
* A prefix to be used for each log message.
|
|
771
|
-
* Note: This option is not used when `json` is enabled.
|
|
772
|
-
*/
|
|
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;
|
|
804
|
-
/**
|
|
805
|
-
* If enabled, will add a request ID to the log message.
|
|
806
|
-
*/
|
|
807
|
-
requestId?: boolean;
|
|
808
|
-
/**
|
|
809
|
-
* If enabled, will print the log message in JSON format.
|
|
810
|
-
*/
|
|
811
|
-
json?: boolean;
|
|
812
|
-
/**
|
|
813
|
-
* If enabled, will print the log message in color.
|
|
814
|
-
* Default true if json is disabled, false otherwise
|
|
815
|
-
*/
|
|
816
|
-
colors?: boolean;
|
|
817
|
-
/**
|
|
818
|
-
* The context of the logger.
|
|
819
|
-
*/
|
|
820
|
-
context?: string;
|
|
821
|
-
/**
|
|
822
|
-
* If enabled, will print the log message in a single line, even if it is an object with multiple properties.
|
|
823
|
-
* If set to a number, the most n inner elements are united on a single line as long as all properties fit into breakLength. Short array elements are also grouped together.
|
|
824
|
-
* Default true when `json` is enabled, false otherwise.
|
|
825
|
-
*/
|
|
826
|
-
compact?: boolean | number;
|
|
827
|
-
/**
|
|
828
|
-
* Specifies the maximum number of Array, TypedArray, Map, Set, WeakMap, and WeakSet elements to include when formatting.
|
|
829
|
-
* Set to null or Infinity to show all elements. Set to 0 or negative to show no elements.
|
|
830
|
-
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
831
|
-
* @default 100
|
|
832
|
-
*/
|
|
833
|
-
maxArrayLength?: number;
|
|
834
|
-
/**
|
|
835
|
-
* Specifies the maximum number of characters to include when formatting.
|
|
836
|
-
* Set to null or Infinity to show all elements. Set to 0 or negative to show no characters.
|
|
837
|
-
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
838
|
-
* @default 10000.
|
|
839
|
-
*/
|
|
840
|
-
maxStringLength?: number;
|
|
841
|
-
/**
|
|
842
|
-
* If enabled, will sort keys while formatting objects.
|
|
843
|
-
* Can also be a custom sorting function.
|
|
844
|
-
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
845
|
-
* @default false
|
|
846
|
-
*/
|
|
847
|
-
sorted?: boolean | ((a: string, b: string) => number);
|
|
848
|
-
/**
|
|
849
|
-
* Specifies the number of times to recurse while formatting object. T
|
|
850
|
-
* This is useful for inspecting large objects. To recurse up to the maximum call stack size pass Infinity or null.
|
|
851
|
-
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
852
|
-
* @default 5
|
|
853
|
-
*/
|
|
854
|
-
depth?: number;
|
|
855
|
-
/**
|
|
856
|
-
* If true, object's non-enumerable symbols and properties are included in the formatted result.
|
|
857
|
-
* WeakMap and WeakSet entries are also included as well as user defined prototype properties
|
|
858
|
-
* @default false
|
|
859
|
-
*/
|
|
860
|
-
showHidden?: boolean;
|
|
861
|
-
/**
|
|
862
|
-
* The length at which input values are split across multiple lines. Set to Infinity to format the input as a single line (in combination with "compact" set to true).
|
|
863
|
-
* Default Infinity when "compact" is true, 80 otherwise.
|
|
864
|
-
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
865
|
-
*/
|
|
866
|
-
breakLength?: number;
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* @publicApi
|
|
870
|
-
*/
|
|
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;
|
|
880
|
-
/**
|
|
881
|
-
* The options of the logger.
|
|
882
|
-
*/
|
|
883
|
-
protected options: ConsoleLoggerOptions;
|
|
884
|
-
/**
|
|
885
|
-
* The context of the logger (can be set manually or automatically inferred).
|
|
886
|
-
*/
|
|
887
|
-
protected context?: string;
|
|
888
|
-
/**
|
|
889
|
-
* The original context of the logger (set in the constructor).
|
|
890
|
-
*/
|
|
891
|
-
protected originalContext?: string;
|
|
892
|
-
/**
|
|
893
|
-
* The options used for the "inspect" method.
|
|
894
|
-
*/
|
|
895
|
-
protected inspectOptions: InspectOptions;
|
|
896
|
-
/**
|
|
897
|
-
* The last timestamp at which the log message was printed.
|
|
898
|
-
*/
|
|
899
|
-
protected lastTimestampAt?: number;
|
|
900
|
-
setup(): void;
|
|
901
|
-
setup(context: string): void;
|
|
902
|
-
setup(options: ConsoleLoggerOptions): void;
|
|
903
|
-
setup(context: string, options: ConsoleLoggerOptions): void;
|
|
904
|
-
/**
|
|
905
|
-
* Write a 'log' level log, if the configured level allows for it.
|
|
906
|
-
* Prints to `stdout` with newline.
|
|
907
|
-
*/
|
|
908
|
-
log(message: any, context?: string): void;
|
|
909
|
-
log(message: any, ...optionalParams: [...any, string?]): void;
|
|
910
|
-
/**
|
|
911
|
-
* Write an 'error' level log, if the configured level allows for it.
|
|
912
|
-
* Prints to `stderr` with newline.
|
|
913
|
-
*/
|
|
914
|
-
error(message: any, stackOrContext?: string): void;
|
|
915
|
-
error(message: any, stack?: string, context?: string): void;
|
|
916
|
-
error(message: any, ...optionalParams: [...any, string?, string?]): void;
|
|
917
|
-
/**
|
|
918
|
-
* Write a 'warn' level log, if the configured level allows for it.
|
|
919
|
-
* Prints to `stdout` with newline.
|
|
920
|
-
*/
|
|
921
|
-
warn(message: any, context?: string): void;
|
|
922
|
-
warn(message: any, ...optionalParams: [...any, string?]): void;
|
|
923
|
-
/**
|
|
924
|
-
* Write a 'debug' level log, if the configured level allows for it.
|
|
925
|
-
* Prints to `stdout` with newline.
|
|
926
|
-
*/
|
|
927
|
-
debug(message: any, context?: string): void;
|
|
928
|
-
debug(message: any, ...optionalParams: [...any, string?]): void;
|
|
929
|
-
/**
|
|
930
|
-
* Write a 'verbose' level log, if the configured level allows for it.
|
|
931
|
-
* Prints to `stdout` with newline.
|
|
932
|
-
*/
|
|
933
|
-
verbose(message: any, context?: string): void;
|
|
934
|
-
verbose(message: any, ...optionalParams: [...any, string?]): void;
|
|
935
|
-
/**
|
|
936
|
-
* Write a 'fatal' level log, if the configured level allows for it.
|
|
937
|
-
* Prints to `stdout` with newline.
|
|
938
|
-
*/
|
|
939
|
-
fatal(message: any, context?: string): void;
|
|
940
|
-
fatal(message: any, ...optionalParams: [...any, string?]): void;
|
|
941
|
-
/**
|
|
942
|
-
* Set log levels
|
|
943
|
-
* @param levels log levels
|
|
944
|
-
*/
|
|
945
|
-
setLogLevels(levels: LogLevel[]): void;
|
|
946
|
-
/**
|
|
947
|
-
* Set logger context
|
|
948
|
-
* @param context context
|
|
949
|
-
*/
|
|
950
|
-
setContext(context: string): void;
|
|
951
|
-
/**
|
|
952
|
-
* Resets the logger context to the value that was passed in the constructor.
|
|
953
|
-
*/
|
|
954
|
-
resetContext(): void;
|
|
955
|
-
isLevelEnabled(level: LogLevel): boolean;
|
|
956
|
-
/**
|
|
957
|
-
* Gets the current request ID from the AsyncLocalStorage store.
|
|
958
|
-
* Only returns a value if the requestId option is enabled.
|
|
959
|
-
*/
|
|
960
|
-
protected getCurrentRequestId(): string | undefined;
|
|
961
|
-
protected getTimestamp(): string;
|
|
962
|
-
protected printMessages(messages: unknown[], context?: string, logLevel?: LogLevel, requestId?: string, writeStreamType?: 'stdout' | 'stderr', errorStack?: unknown): void;
|
|
963
|
-
protected printAsJson(message: unknown, options: {
|
|
964
|
-
context: string;
|
|
965
|
-
logLevel: LogLevel;
|
|
966
|
-
writeStreamType?: 'stdout' | 'stderr';
|
|
967
|
-
errorStack?: unknown;
|
|
968
|
-
requestId?: string;
|
|
969
|
-
}): void;
|
|
970
|
-
protected formatPid(pid: number): string;
|
|
971
|
-
protected formatContext(context: string): string;
|
|
972
|
-
protected formatMessage(logLevel: LogLevel, message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string, requestId?: string): string;
|
|
973
|
-
protected getRequestId(requestId?: string): string;
|
|
974
|
-
protected stringifyMessage(message: unknown, logLevel: LogLevel): string;
|
|
975
|
-
protected colorize(message: string, logLevel: LogLevel): string;
|
|
976
|
-
protected printStackTrace(stack: string): void;
|
|
977
|
-
protected updateAndGetTimestampDiff(): string;
|
|
978
|
-
protected formatTimestampDiff(timestampDiff: number): string;
|
|
979
|
-
protected getInspectOptions(): InspectOptions;
|
|
980
|
-
protected stringifyReplacer(key: string, value: unknown): unknown;
|
|
981
|
-
private getContextAndMessagesToPrint;
|
|
982
|
-
private getContextAndStackAndMessagesToPrint;
|
|
983
|
-
private isStackFormat;
|
|
984
|
-
private getColorByLogLevel;
|
|
985
|
-
}
|
|
986
|
-
//#endregion
|
|
987
|
-
//#region src/logger/logger.service.d.mts
|
|
988
|
-
/**
|
|
989
|
-
* Logger service instance that can be injected into services and controllers.
|
|
990
|
-
*
|
|
991
|
-
* Provides contextualized logging with automatic context injection.
|
|
992
|
-
* The context is set when the logger is injected using the `inject` function.
|
|
993
|
-
*
|
|
994
|
-
* @example
|
|
995
|
-
* ```typescript
|
|
996
|
-
* @Injectable()
|
|
997
|
-
* export class UserService {
|
|
998
|
-
* private logger = inject(Logger, { context: UserService.name })
|
|
999
|
-
*
|
|
1000
|
-
* async findUser(id: string) {
|
|
1001
|
-
* this.logger.log(`Finding user ${id}`)
|
|
1002
|
-
* // Logs with context: [UserService]
|
|
1003
|
-
* }
|
|
1004
|
-
* }
|
|
1005
|
-
* ```
|
|
1006
|
-
*/
|
|
1007
|
-
declare class LoggerInstance implements LoggerService {
|
|
1008
|
-
protected localInstance: LoggerService;
|
|
1009
|
-
protected context?: string;
|
|
1010
|
-
constructor(config?: LoggerOptions);
|
|
1011
|
-
/**
|
|
1012
|
-
* Write an 'error' level log.
|
|
1013
|
-
*/
|
|
1014
|
-
error(message: any, stack?: string, context?: string): void;
|
|
1015
|
-
error(message: any, ...optionalParams: [...any, string?, string?]): void;
|
|
1016
|
-
/**
|
|
1017
|
-
* Write a 'log' level log.
|
|
1018
|
-
*/
|
|
1019
|
-
log(message: any, context?: string): void;
|
|
1020
|
-
log(message: any, ...optionalParams: [...any, string?]): void;
|
|
1021
|
-
/**
|
|
1022
|
-
* Write a 'warn' level log.
|
|
1023
|
-
*/
|
|
1024
|
-
warn(message: any, context?: string): void;
|
|
1025
|
-
warn(message: any, ...optionalParams: [...any, string?]): void;
|
|
1026
|
-
/**
|
|
1027
|
-
* Write a 'debug' level log.
|
|
1028
|
-
*/
|
|
1029
|
-
debug(message: any, context?: string): void;
|
|
1030
|
-
debug(message: any, ...optionalParams: [...any, string?]): void;
|
|
1031
|
-
/**
|
|
1032
|
-
* Write a 'verbose' level log.
|
|
1033
|
-
*/
|
|
1034
|
-
verbose(message: any, context?: string): void;
|
|
1035
|
-
verbose(message: any, ...optionalParams: [...any, string?]): void;
|
|
1036
|
-
/**
|
|
1037
|
-
* Write a 'fatal' level log.
|
|
1038
|
-
*/
|
|
1039
|
-
fatal(message: any, context?: string): void;
|
|
1040
|
-
fatal(message: any, ...optionalParams: [...any, string?]): void;
|
|
1041
|
-
}
|
|
1042
|
-
//#endregion
|
|
1043
|
-
//#region src/logger/logger.tokens.d.mts
|
|
1044
|
-
/**
|
|
1045
|
-
* Injection token for the logger output service.
|
|
1046
|
-
*
|
|
1047
|
-
* This token is used to provide a custom logger implementation.
|
|
1048
|
-
* By default, it's bound to ConsoleLogger.
|
|
1049
|
-
*/
|
|
1050
|
-
declare const LoggerOutput: InjectionToken<LoggerService, undefined, false>;
|
|
1051
|
-
/**
|
|
1052
|
-
* Schema for logger options.
|
|
1053
|
-
*/
|
|
1054
|
-
declare const loggerOptionsSchema: z.ZodOptional<z.ZodObject<{
|
|
1055
|
-
context: z.ZodOptional<z.ZodString>;
|
|
1056
|
-
}, z.core.$strip>>;
|
|
1057
|
-
/**
|
|
1058
|
-
* Options for creating a logger instance.
|
|
1059
|
-
*/
|
|
1060
|
-
type LoggerOptions = z.infer<typeof loggerOptionsSchema>;
|
|
1061
|
-
/**
|
|
1062
|
-
* Injection token for the Logger service.
|
|
1063
|
-
*
|
|
1064
|
-
* Use this token to inject a contextualized logger instance.
|
|
1065
|
-
*
|
|
1066
|
-
* @example
|
|
1067
|
-
* ```typescript
|
|
1068
|
-
* const logger = inject(Logger, { context: 'MyService' })
|
|
1069
|
-
* logger.log('Hello world') // Logs with context: [MyService]
|
|
1070
|
-
* ```
|
|
1071
|
-
*/
|
|
1072
|
-
declare const Logger: InjectionToken<LoggerInstance, z.ZodOptional<z.ZodObject<{
|
|
1073
|
-
context: z.ZodOptional<z.ZodString>;
|
|
1074
|
-
}, z.core.$strip>>, false>;
|
|
1075
|
-
//#endregion
|
|
1076
|
-
//#region src/interfaces/abstract-http-cors-options.interface.d.mts
|
|
1077
|
-
interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}
|
|
1078
|
-
type OriginType = string | boolean | RegExp;
|
|
1079
|
-
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;
|
|
1080
|
-
interface AbstractHttpCorsOptions {
|
|
1081
|
-
/**
|
|
1082
|
-
* Configures the Access-Control-Allow-Origin CORS header.
|
|
1083
|
-
*/
|
|
1084
|
-
origin?: ValueOrArray<OriginType>;
|
|
1085
|
-
/**
|
|
1086
|
-
* Configures the Access-Control-Allow-Credentials CORS header.
|
|
1087
|
-
* Set to true to pass the header, otherwise it is omitted.
|
|
1088
|
-
*/
|
|
1089
|
-
credentials?: boolean;
|
|
1090
|
-
/**
|
|
1091
|
-
* Configures the Access-Control-Expose-Headers CORS header.
|
|
1092
|
-
* Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
|
|
1093
|
-
* or an array (ex: ['Content-Range', 'X-Content-Range']).
|
|
1094
|
-
* If not specified, no custom headers are exposed.
|
|
1095
|
-
*/
|
|
1096
|
-
exposedHeaders?: string | string[];
|
|
1097
|
-
/**
|
|
1098
|
-
* Configures the Access-Control-Allow-Headers CORS header.
|
|
1099
|
-
* Expects a comma-delimited string (ex: 'Content-Type,Authorization')
|
|
1100
|
-
* or an array (ex: ['Content-Type', 'Authorization']). If not
|
|
1101
|
-
* specified, defaults to reflecting the headers specified in the
|
|
1102
|
-
* request's Access-Control-Request-Headers header.
|
|
1103
|
-
*/
|
|
1104
|
-
allowedHeaders?: string | string[];
|
|
1105
|
-
/**
|
|
1106
|
-
* Configures the Access-Control-Allow-Methods CORS header.
|
|
1107
|
-
* Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
|
|
1108
|
-
*/
|
|
1109
|
-
methods?: string | string[];
|
|
1110
|
-
/**
|
|
1111
|
-
* Configures the Access-Control-Max-Age CORS header.
|
|
1112
|
-
* Set to an integer to pass the header, otherwise it is omitted.
|
|
1113
|
-
*/
|
|
1114
|
-
maxAge?: number;
|
|
1115
|
-
/**
|
|
1116
|
-
* Configures the Cache-Control header for CORS preflight responses.
|
|
1117
|
-
* Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
|
|
1118
|
-
* or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
|
|
1119
|
-
* the header value), otherwise the header is omitted.
|
|
1120
|
-
*/
|
|
1121
|
-
cacheControl?: number | string;
|
|
1122
|
-
/**
|
|
1123
|
-
* Sets the Fastify log level specifically for the internal OPTIONS route
|
|
1124
|
-
* used to handle CORS preflight requests. For example, setting this to `'silent'`
|
|
1125
|
-
* will prevent these requests from being logged.
|
|
1126
|
-
* Useful for reducing noise in application logs.
|
|
1127
|
-
* Default: inherits Fastify's global log level.
|
|
1128
|
-
*/
|
|
1129
|
-
logLevel?: LogLevel;
|
|
1130
|
-
}
|
|
1131
|
-
//#endregion
|
|
1132
|
-
//#region src/interfaces/abstract-http-handler-adapter.interface.d.mts
|
|
1133
|
-
/**
|
|
1134
|
-
* Static handler result - handler can be called without a scoped container.
|
|
1135
|
-
* Used when the controller and all its dependencies are singletons.
|
|
1136
|
-
*/
|
|
1137
|
-
type StaticHandler<TRequest = any, TReply = any> = {
|
|
1138
|
-
isStatic: true;
|
|
1139
|
-
handler: (request: TRequest, reply: TReply) => Promise<any>;
|
|
1140
|
-
};
|
|
1141
|
-
/**
|
|
1142
|
-
* Dynamic handler result - handler requires a scoped container for resolution.
|
|
1143
|
-
* Used when the controller or its dependencies need per-request resolution.
|
|
1144
|
-
*/
|
|
1145
|
-
type DynamicHandler<TRequest = any, TReply = any> = {
|
|
1146
|
-
isStatic: false;
|
|
1147
|
-
handler: (scoped: ScopedContainer, request: TRequest, reply: TReply) => Promise<any>;
|
|
1148
|
-
};
|
|
1149
|
-
/**
|
|
1150
|
-
* Handler result returned by provideHandler.
|
|
1151
|
-
* Can be either static (pre-resolved) or dynamic (needs scoped container).
|
|
1152
|
-
*/
|
|
1153
|
-
type HandlerResult<TRequest = any, TReply = any> = StaticHandler<TRequest, TReply> | DynamicHandler<TRequest, TReply>;
|
|
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
|
-
*/
|
|
1227
|
-
provideHandler: (controller: ClassType, handlerMetadata: HandlerMetadata<any>) => Promise<HandlerResult>;
|
|
1228
|
-
}
|
|
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
|
|
1236
|
-
//#region src/interfaces/can-activate.d.mts
|
|
1237
|
-
/**
|
|
1238
|
-
* Interface that guards must implement to control access to endpoints.
|
|
1239
|
-
*
|
|
1240
|
-
* Guards are used for authentication, authorization, and request validation.
|
|
1241
|
-
* They are executed before the endpoint handler and can prevent the request
|
|
1242
|
-
* from proceeding by returning `false` or throwing an exception.
|
|
1243
|
-
*
|
|
1244
|
-
* @example
|
|
1245
|
-
* ```typescript
|
|
1246
|
-
* @Injectable()
|
|
1247
|
-
* export class AuthGuard implements CanActivate {
|
|
1248
|
-
* async canActivate(context: AbstractExecutionContext): Promise<boolean> {
|
|
1249
|
-
* const request = context.getRequest()
|
|
1250
|
-
* const token = request.headers.authorization
|
|
1251
|
-
*
|
|
1252
|
-
* if (!token) {
|
|
1253
|
-
* throw new UnauthorizedException('Authentication required')
|
|
1254
|
-
* }
|
|
1255
|
-
*
|
|
1256
|
-
* // Validate token
|
|
1257
|
-
* return true
|
|
1258
|
-
* }
|
|
1259
|
-
* }
|
|
1260
|
-
* ```
|
|
1261
|
-
*/
|
|
1262
|
-
interface CanActivate {
|
|
1263
|
-
/**
|
|
1264
|
-
* Determines if the current request can proceed to the endpoint handler.
|
|
1265
|
-
*
|
|
1266
|
-
* @param executionContext - The execution context containing request, reply, and metadata
|
|
1267
|
-
* @returns `true` if the request can proceed, `false` otherwise. Can also throw an exception.
|
|
1268
|
-
*/
|
|
1269
|
-
canActivate(executionContext: AbstractExecutionContext): Promise<boolean> | boolean;
|
|
1270
|
-
}
|
|
1271
|
-
//#endregion
|
|
1272
|
-
//#region src/interfaces/http-header.d.mts
|
|
1273
|
-
type OmitIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
1274
|
-
/**
|
|
1275
|
-
* HTTP header strings
|
|
1276
|
-
* Use this type only for input values, not for output values.
|
|
1277
|
-
*/
|
|
1278
|
-
type HttpHeader = keyof OmitIndexSignature<OutgoingHttpHeaders> | (string & Record<never, never>);
|
|
1279
|
-
//#endregion
|
|
1280
|
-
//#region src/interfaces/navios-module.d.mts
|
|
1281
|
-
/**
|
|
1282
|
-
* Interface that all Navios modules must implement.
|
|
1283
|
-
*
|
|
1284
|
-
* Modules decorated with @Module() should implement this interface to receive
|
|
1285
|
-
* lifecycle hooks.
|
|
1286
|
-
*
|
|
1287
|
-
* @example
|
|
1288
|
-
* ```typescript
|
|
1289
|
-
* @Module({
|
|
1290
|
-
* controllers: [UserController],
|
|
1291
|
-
* })
|
|
1292
|
-
* export class AppModule implements NaviosModule {
|
|
1293
|
-
* async onModuleInit() {
|
|
1294
|
-
* console.log('AppModule initialized')
|
|
1295
|
-
* // Perform initialization logic
|
|
1296
|
-
* }
|
|
1297
|
-
* }
|
|
1298
|
-
* ```
|
|
1299
|
-
*/
|
|
1300
|
-
interface NaviosModule {
|
|
1301
|
-
/**
|
|
1302
|
-
* Optional lifecycle hook called after the module is initialized.
|
|
1303
|
-
*
|
|
1304
|
-
* This is called after all modules are loaded and the HTTP server is set up
|
|
1305
|
-
* (if an adapter is configured), but before the server starts listening.
|
|
1306
|
-
*/
|
|
1307
|
-
onModuleInit?: () => Promise<void> | void;
|
|
1308
|
-
}
|
|
1309
|
-
//#endregion
|
|
1310
|
-
//#region src/services/module-loader.service.d.mts
|
|
1311
|
-
/**
|
|
1312
|
-
* Extension definition for dynamically adding to the module tree.
|
|
1313
|
-
* Used by plugins to inject controllers or entire modules.
|
|
1314
|
-
*/
|
|
1315
|
-
interface ModuleExtension {
|
|
1316
|
-
/**
|
|
1317
|
-
* Module class to add. If provided, the module and all its
|
|
1318
|
-
* controllers/imports will be processed.
|
|
1319
|
-
*/
|
|
1320
|
-
module?: ClassTypeWithInstance<NaviosModule>;
|
|
1321
|
-
/**
|
|
1322
|
-
* Controllers to add directly without a wrapper module.
|
|
1323
|
-
* Will be registered under a synthetic module named after the plugin.
|
|
1324
|
-
*/
|
|
1325
|
-
controllers?: ClassType[];
|
|
1326
|
-
/**
|
|
1327
|
-
* Name for the synthetic module when using controllers directly.
|
|
1328
|
-
* Required if `controllers` is provided without `module`.
|
|
1329
|
-
*/
|
|
1330
|
-
moduleName?: string;
|
|
1331
|
-
}
|
|
1332
|
-
declare class ModuleLoaderService {
|
|
1333
|
-
private logger;
|
|
1334
|
-
protected container: Container;
|
|
1335
|
-
private modulesMetadata;
|
|
1336
|
-
private loadedModules;
|
|
1337
|
-
private initialized;
|
|
1338
|
-
loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
|
|
1339
|
-
/**
|
|
1340
|
-
* Extends the module tree with additional modules or controllers.
|
|
1341
|
-
*
|
|
1342
|
-
* This method is designed to be called by plugins during registration,
|
|
1343
|
-
* which happens after initial module loading but before route registration.
|
|
1344
|
-
*
|
|
1345
|
-
* @param extensions - Array of module extensions to add
|
|
1346
|
-
* @throws Error if not initialized (loadModules must be called first)
|
|
1347
|
-
*
|
|
1348
|
-
* @example
|
|
1349
|
-
* ```typescript
|
|
1350
|
-
* // In plugin registration
|
|
1351
|
-
* const moduleLoader = await context.container.get(ModuleLoaderService)
|
|
1352
|
-
* await moduleLoader.extendModules([{
|
|
1353
|
-
* controllers: [OpenApiJsonController, OpenApiYamlController],
|
|
1354
|
-
* moduleName: 'OpenApiBunModule',
|
|
1355
|
-
* }])
|
|
1356
|
-
* ```
|
|
1357
|
-
*/
|
|
1358
|
-
extendModules(extensions: ModuleExtension[]): Promise<void>;
|
|
1359
|
-
/**
|
|
1360
|
-
* Registers controllers under a synthetic module.
|
|
1361
|
-
* Used when plugins want to add controllers without a full module class.
|
|
1362
|
-
*/
|
|
1363
|
-
private registerControllers;
|
|
1364
|
-
private traverseModules;
|
|
1365
|
-
private validateOverrides;
|
|
1366
|
-
private mergeMetadata;
|
|
1367
|
-
getAllModules(): Map<string, ModuleMetadata>;
|
|
1368
|
-
dispose(): void;
|
|
1369
|
-
}
|
|
1370
|
-
//#endregion
|
|
1371
|
-
//#region src/interfaces/plugin.interface.d.mts
|
|
1372
|
-
/**
|
|
1373
|
-
* Context provided to plugins during registration.
|
|
1374
|
-
*
|
|
1375
|
-
* This context gives plugins access to the application's modules,
|
|
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
|
-
* ```
|
|
1394
|
-
*/
|
|
1395
|
-
interface PluginContext<TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface> {
|
|
1396
|
-
/**
|
|
1397
|
-
* All loaded modules with their metadata.
|
|
1398
|
-
* Keys are module class names, values are their metadata.
|
|
1399
|
-
*/
|
|
1400
|
-
modules: Map<string, ModuleMetadata>;
|
|
1401
|
-
/**
|
|
1402
|
-
* The current adapter instance.
|
|
1403
|
-
* Use type guards or cast to adapter-specific types for HTTP methods.
|
|
1404
|
-
*/
|
|
1405
|
-
adapter: TAdapter;
|
|
1406
|
-
/**
|
|
1407
|
-
* The dependency injection container.
|
|
1408
|
-
*/
|
|
1409
|
-
container: Container;
|
|
1410
|
-
/**
|
|
1411
|
-
* Module loader service for extending the module tree.
|
|
1412
|
-
* Use `moduleLoader.extendModules()` to add controllers dynamically.
|
|
1413
|
-
*/
|
|
1414
|
-
moduleLoader: ModuleLoaderService;
|
|
1415
|
-
}
|
|
1416
|
-
/**
|
|
1417
|
-
* Base interface for Navios plugins.
|
|
1418
|
-
*
|
|
1419
|
-
* Plugins are registered using `app.usePlugin()` and are initialized
|
|
1420
|
-
* after all modules are loaded but before the server starts listening.
|
|
1421
|
-
*
|
|
1422
|
-
* @typeParam TOptions - The type of options the plugin accepts
|
|
1423
|
-
* @typeParam TAdapter - The adapter type the plugin requires
|
|
1424
|
-
*
|
|
1425
|
-
* @example
|
|
1426
|
-
* ```typescript
|
|
1427
|
-
* // Generic plugin
|
|
1428
|
-
* const myPlugin: NaviosPlugin<{ enabled: boolean }> = {
|
|
1429
|
-
* name: 'my-plugin',
|
|
1430
|
-
* register: async (context, options) => {
|
|
1431
|
-
* if (options.enabled) {
|
|
1432
|
-
* // Register routes, services, etc.
|
|
1433
|
-
* }
|
|
1434
|
-
* },
|
|
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
|
-
* }
|
|
1444
|
-
* ```
|
|
1445
|
-
*/
|
|
1446
|
-
interface NaviosPlugin<TOptions = unknown, TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface> {
|
|
1447
|
-
/**
|
|
1448
|
-
* Plugin name for identification and logging.
|
|
1449
|
-
*/
|
|
1450
|
-
name: string;
|
|
1451
|
-
/**
|
|
1452
|
-
* Called after modules are loaded but before the server starts listening.
|
|
1453
|
-
*
|
|
1454
|
-
* @param context - The plugin context with access to modules and adapter
|
|
1455
|
-
* @param options - Plugin-specific configuration options
|
|
1456
|
-
*/
|
|
1457
|
-
register(context: PluginContext<TAdapter>, options: TOptions): Promise<void> | void;
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
* Plugin definition combining a plugin with its options.
|
|
1461
|
-
*
|
|
1462
|
-
* This is the type returned by plugin factory functions like `defineOpenApiPlugin()`.
|
|
1463
|
-
*
|
|
1464
|
-
* @typeParam TOptions - The type of options the plugin accepts
|
|
1465
|
-
* @typeParam TAdapter - The adapter type the plugin requires
|
|
1466
|
-
*
|
|
1467
|
-
* @example
|
|
1468
|
-
* ```typescript
|
|
1469
|
-
* function defineMyPlugin(options: MyPluginOptions): PluginDefinition<MyPluginOptions> {
|
|
1470
|
-
* return {
|
|
1471
|
-
* plugin: myPlugin,
|
|
1472
|
-
* options,
|
|
1473
|
-
* }
|
|
1474
|
-
* }
|
|
1475
|
-
* ```
|
|
1476
|
-
*/
|
|
1477
|
-
interface PluginDefinition<TOptions = unknown, TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface> {
|
|
1478
|
-
/**
|
|
1479
|
-
* The plugin instance.
|
|
1480
|
-
*/
|
|
1481
|
-
plugin: NaviosPlugin<TOptions, TAdapter>;
|
|
1482
|
-
/**
|
|
1483
|
-
* Options to pass to the plugin's register function.
|
|
1484
|
-
*/
|
|
1485
|
-
options: TOptions;
|
|
1486
|
-
}
|
|
1487
|
-
//#endregion
|
|
1488
|
-
//#region src/decorators/header.decorator.d.mts
|
|
1489
|
-
/**
|
|
1490
|
-
* Decorator that sets a custom HTTP response header for an endpoint.
|
|
1491
|
-
*
|
|
1492
|
-
* @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
|
|
1493
|
-
* @param value - The header value (string, number, or array of strings)
|
|
1494
|
-
* @returns A method decorator
|
|
1495
|
-
*
|
|
1496
|
-
* @example
|
|
1497
|
-
* ```typescript
|
|
1498
|
-
* @Controller()
|
|
1499
|
-
* export class UserController {
|
|
1500
|
-
* @Endpoint(getUserEndpoint)
|
|
1501
|
-
* @Header('Cache-Control', 'max-age=3600')
|
|
1502
|
-
* async getUser() {
|
|
1503
|
-
* return { id: '1', name: 'John' }
|
|
1504
|
-
* }
|
|
1505
|
-
* }
|
|
1506
|
-
* ```
|
|
1507
|
-
*/
|
|
1508
|
-
declare function Header(name: HttpHeader, value: string | number | string[]): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
1509
|
-
//#endregion
|
|
1510
|
-
//#region src/decorators/http-code.decorator.d.mts
|
|
1511
|
-
/**
|
|
1512
|
-
* Decorator that sets a custom HTTP status code for successful responses.
|
|
1513
|
-
*
|
|
1514
|
-
* By default, endpoints return 200 OK. Use this decorator to return a different status code.
|
|
1515
|
-
*
|
|
1516
|
-
* @param code - The HTTP status code to return (e.g., 201, 204, 202)
|
|
1517
|
-
* @returns A method decorator
|
|
1518
|
-
*
|
|
1519
|
-
* @example
|
|
1520
|
-
* ```typescript
|
|
1521
|
-
* @Controller()
|
|
1522
|
-
* export class UserController {
|
|
1523
|
-
* @Endpoint(createUserEndpoint)
|
|
1524
|
-
* @HttpCode(201)
|
|
1525
|
-
* async createUser() {
|
|
1526
|
-
* return { id: '1', name: 'John' }
|
|
1527
|
-
* }
|
|
1528
|
-
* }
|
|
1529
|
-
* ```
|
|
1530
|
-
*/
|
|
1531
|
-
declare function HttpCode(code: number): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
1532
|
-
//#endregion
|
|
1533
|
-
//#region src/decorators/module.decorator.d.mts
|
|
1534
|
-
/**
|
|
1535
|
-
* Options for configuring a Navios module.
|
|
1536
|
-
*/
|
|
1537
|
-
interface ModuleOptions {
|
|
1538
|
-
/**
|
|
1539
|
-
* Controllers to register in this module.
|
|
1540
|
-
* Controllers handle HTTP requests and define endpoints.
|
|
1541
|
-
*/
|
|
1542
|
-
controllers?: ClassType[] | Set<ClassType>;
|
|
1543
|
-
/**
|
|
1544
|
-
* Other modules to import into this module.
|
|
1545
|
-
* Imported modules' controllers and services become available.
|
|
1546
|
-
*/
|
|
1547
|
-
imports?: ClassType[] | Set<ClassType>;
|
|
1548
|
-
/**
|
|
1549
|
-
* Guards to apply to all controllers in this module.
|
|
1550
|
-
* Guards are executed in reverse order (last guard first).
|
|
1551
|
-
*/
|
|
1552
|
-
guards?: ClassType[] | Set<ClassType>;
|
|
1553
|
-
/**
|
|
1554
|
-
* Service override classes to import for side effects.
|
|
1555
|
-
* These classes are imported to ensure their @Injectable decorators execute,
|
|
1556
|
-
* allowing them to register with the DI system. Overrides should use the same
|
|
1557
|
-
* InjectionToken as the original service with a higher priority.
|
|
1558
|
-
*/
|
|
1559
|
-
overrides?: ClassType[] | Set<ClassType>;
|
|
1560
|
-
/**
|
|
1561
|
-
* Priority to use for the module.
|
|
1562
|
-
* Priority is used to sort the module in the registry.
|
|
1563
|
-
*/
|
|
1564
|
-
priority?: number;
|
|
1565
|
-
/**
|
|
1566
|
-
* Registry to use for the module.
|
|
1567
|
-
* Registry is used to store the module and its controllers.
|
|
1568
|
-
*/
|
|
1569
|
-
registry?: Registry;
|
|
1570
|
-
}
|
|
1571
|
-
/**
|
|
1572
|
-
* Decorator that marks a class as a Navios module.
|
|
1573
|
-
*
|
|
1574
|
-
* Modules are the basic building blocks of a Navios application.
|
|
1575
|
-
* They organize controllers, services, and other modules into logical units.
|
|
1576
|
-
*
|
|
1577
|
-
* @param options - Module configuration options
|
|
1578
|
-
* @returns A class decorator
|
|
1579
|
-
*
|
|
1580
|
-
* @example
|
|
1581
|
-
* ```typescript
|
|
1582
|
-
* @Module({
|
|
1583
|
-
* controllers: [UserController, AuthController],
|
|
1584
|
-
* imports: [DatabaseModule],
|
|
1585
|
-
* guards: [AuthGuard],
|
|
1586
|
-
* })
|
|
1587
|
-
* export class AppModule {}
|
|
1588
|
-
* ```
|
|
1589
|
-
*/
|
|
1590
|
-
declare function Module({
|
|
1591
|
-
controllers,
|
|
1592
|
-
imports,
|
|
1593
|
-
guards,
|
|
1594
|
-
overrides,
|
|
1595
|
-
priority,
|
|
1596
|
-
registry
|
|
1597
|
-
}?: ModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
1598
|
-
//#endregion
|
|
1599
|
-
//#region src/decorators/multipart.decorator.d.mts
|
|
1600
|
-
/**
|
|
1601
|
-
* Extracts the typed parameters for a multipart endpoint handler function.
|
|
1602
|
-
*
|
|
1603
|
-
* Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.
|
|
1604
|
-
*
|
|
1605
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
1606
|
-
*/
|
|
1607
|
-
type MultipartParams<EndpointDeclaration extends {
|
|
1608
|
-
config: EndpointOptions;
|
|
1609
|
-
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, QuerySchema, undefined, EndpointDeclaration['config']['urlParamsSchema'], true> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, undefined, undefined, EndpointDeclaration['config']['urlParamsSchema'], true>;
|
|
1610
|
-
/**
|
|
1611
|
-
* Extracts the typed return value for a multipart endpoint handler function.
|
|
1612
|
-
*
|
|
1613
|
-
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
1614
|
-
*/
|
|
1615
|
-
type MultipartResult<EndpointDeclaration extends {
|
|
1616
|
-
config: EndpointOptions;
|
|
1617
|
-
}> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z$1.input<Options[number]>> : Promise<z$1.input<EndpointDeclaration['config']['responseSchema']>>;
|
|
1618
|
-
/**
|
|
1619
|
-
* Decorator that marks a method as a multipart/form-data endpoint.
|
|
1620
|
-
*
|
|
1621
|
-
* Use this decorator for endpoints that handle file uploads or form data.
|
|
1622
|
-
* The endpoint must be defined using @navios/builder's `declareMultipart` method.
|
|
1623
|
-
*
|
|
1624
|
-
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
1625
|
-
* @returns A method decorator
|
|
1626
|
-
*
|
|
1627
|
-
* @example
|
|
1628
|
-
* ```typescript
|
|
1629
|
-
* const uploadFileEndpoint = api.declareMultipart({
|
|
1630
|
-
* method: 'post',
|
|
1631
|
-
* url: '/upload',
|
|
1632
|
-
* requestSchema: z.object({ file: z.instanceof(File) }),
|
|
1633
|
-
* responseSchema: z.object({ url: z.string() }),
|
|
1634
|
-
* })
|
|
1635
|
-
*
|
|
1636
|
-
* @Controller()
|
|
1637
|
-
* export class FileController {
|
|
1638
|
-
* @Multipart(uploadFileEndpoint)
|
|
1639
|
-
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
|
|
1640
|
-
* const { file } = request.data
|
|
1641
|
-
* // Handle file upload
|
|
1642
|
-
* return { url: 'https://example.com/file.jpg' }
|
|
1643
|
-
* }
|
|
1644
|
-
* }
|
|
1645
|
-
* ```
|
|
1646
|
-
*/
|
|
1647
|
-
declare function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
1648
|
-
config: Config;
|
|
1649
|
-
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
1650
|
-
declare function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
1651
|
-
config: Config;
|
|
1652
|
-
}): (target: () => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
1653
|
-
//#endregion
|
|
1654
|
-
//#region src/decorators/stream.decorator.d.mts
|
|
1655
|
-
/**
|
|
1656
|
-
* Extracts the typed parameters for a stream endpoint handler function.
|
|
1657
|
-
*
|
|
1658
|
-
* Similar to `EndpointParams`, but specifically for streaming endpoints.
|
|
1659
|
-
*
|
|
1660
|
-
* @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder
|
|
1661
|
-
*/
|
|
1662
|
-
type StreamParams<EndpointDeclaration extends StreamHandler<Config, false>, Config extends BaseEndpointOptions = EndpointDeclaration['config'], Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, QuerySchema, undefined, EndpointDeclaration['config']['urlParamsSchema'], true> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, undefined, undefined, EndpointDeclaration['config']['urlParamsSchema'], true>;
|
|
1663
|
-
/**
|
|
1664
|
-
* Decorator that marks a method as a streaming endpoint.
|
|
1665
|
-
*
|
|
1666
|
-
* Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
|
|
1667
|
-
* The endpoint must be defined using @navios/builder's `declareStream` method.
|
|
1668
|
-
*
|
|
1669
|
-
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
1670
|
-
* @returns A method decorator
|
|
1671
|
-
*
|
|
1672
|
-
* @example
|
|
1673
|
-
* ```typescript
|
|
1674
|
-
* const downloadFileEndpoint = api.declareStream({
|
|
1675
|
-
* method: 'get',
|
|
1676
|
-
* url: '/files/$fileId',
|
|
1677
|
-
* })
|
|
1678
|
-
*
|
|
1679
|
-
* @Controller()
|
|
1680
|
-
* export class FileController {
|
|
1681
|
-
* @Stream(downloadFileEndpoint)
|
|
1682
|
-
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
1683
|
-
* const { fileId } = request.urlParams
|
|
1684
|
-
* // Stream file data to reply
|
|
1685
|
-
* }
|
|
1686
|
-
* }
|
|
1687
|
-
* ```
|
|
1688
|
-
*/
|
|
1689
|
-
declare function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
1690
|
-
config: Config;
|
|
1691
|
-
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>, reply: any) => any, context: ClassMethodDecoratorContext) => void;
|
|
1692
|
-
declare function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
1693
|
-
config: Config;
|
|
1694
|
-
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => any, context: ClassMethodDecoratorContext) => void;
|
|
1695
|
-
declare function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
1696
|
-
config: Config;
|
|
1697
|
-
}): (target: () => any, context: ClassMethodDecoratorContext) => void;
|
|
1698
|
-
//#endregion
|
|
1699
|
-
//#region src/decorators/use-guards.decorator.d.mts
|
|
1700
|
-
/**
|
|
1701
|
-
* Decorator that applies guards to a controller or endpoint.
|
|
1702
|
-
*
|
|
1703
|
-
* Guards are used for authentication, authorization, and request validation.
|
|
1704
|
-
* They implement the `CanActivate` interface and are executed before the endpoint handler.
|
|
1705
|
-
* Guards can be applied at the module, controller, or endpoint level.
|
|
1706
|
-
*
|
|
1707
|
-
* @param guards - Guard classes or injection tokens to apply
|
|
1708
|
-
* @returns A class or method decorator
|
|
1709
|
-
*
|
|
1710
|
-
* @example
|
|
1711
|
-
* ```typescript
|
|
1712
|
-
* // Apply to a controller
|
|
1713
|
-
* @Controller()
|
|
1714
|
-
* @UseGuards(AuthGuard, RoleGuard)
|
|
1715
|
-
* export class UserController {
|
|
1716
|
-
* @Endpoint(getUserEndpoint)
|
|
1717
|
-
* async getUser() { }
|
|
1718
|
-
* }
|
|
1719
|
-
*
|
|
1720
|
-
* // Apply to a specific endpoint
|
|
1721
|
-
* @Controller()
|
|
1722
|
-
* export class UserController {
|
|
1723
|
-
* @Endpoint(getUserEndpoint)
|
|
1724
|
-
* @UseGuards(AuthGuard)
|
|
1725
|
-
* async getUser() { }
|
|
1726
|
-
* }
|
|
1727
|
-
* ```
|
|
1728
|
-
*/
|
|
1729
|
-
declare function UseGuards(...guards: (ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>)[]): <T extends Function>(target: T, context: ClassMethodDecoratorContext | ClassDecoratorContext) => T;
|
|
1730
|
-
//#endregion
|
|
1731
|
-
//#region src/exceptions/http.exception.d.mts
|
|
1732
|
-
/**
|
|
1733
|
-
* Base exception class for all HTTP exceptions in Navios.
|
|
1734
|
-
*
|
|
1735
|
-
* All HTTP exception classes extend this base class. When thrown from an endpoint handler,
|
|
1736
|
-
* Navios will automatically convert it to an appropriate HTTP response with the specified
|
|
1737
|
-
* status code and response body.
|
|
1738
|
-
*
|
|
1739
|
-
* @example
|
|
1740
|
-
* ```typescript
|
|
1741
|
-
* @Endpoint(getUserEndpoint)
|
|
1742
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
1743
|
-
* const user = await this.userService.findById(request.urlParams.userId)
|
|
1744
|
-
* if (!user) {
|
|
1745
|
-
* throw new HttpException(404, 'User not found')
|
|
1746
|
-
* }
|
|
1747
|
-
* return user
|
|
1748
|
-
* }
|
|
1749
|
-
* ```
|
|
1750
|
-
*/
|
|
1751
|
-
declare class HttpException {
|
|
1752
|
-
readonly statusCode: number;
|
|
1753
|
-
readonly response: string | object;
|
|
1754
|
-
readonly error?: Error | undefined;
|
|
1755
|
-
/**
|
|
1756
|
-
* Creates a new HttpException instance.
|
|
1757
|
-
*
|
|
1758
|
-
* @param statusCode - HTTP status code (e.g., 400, 404, 500)
|
|
1759
|
-
* @param response - Response body (string or object)
|
|
1760
|
-
* @param error - Optional underlying error for logging/debugging
|
|
1761
|
-
*/
|
|
1762
|
-
constructor(statusCode: number, response: string | object, error?: Error | undefined);
|
|
1763
|
-
}
|
|
1764
|
-
//#endregion
|
|
1765
|
-
//#region src/exceptions/bad-request.exception.d.mts
|
|
1766
|
-
/**
|
|
1767
|
-
* Exception that represents a 400 Bad Request HTTP error.
|
|
1768
|
-
*
|
|
1769
|
-
* Use this exception when the client's request is malformed or invalid.
|
|
1770
|
-
*
|
|
1771
|
-
* @example
|
|
1772
|
-
* ```typescript
|
|
1773
|
-
* @Endpoint(createUserEndpoint)
|
|
1774
|
-
* async createUser(request: EndpointParams<typeof createUserEndpoint>) {
|
|
1775
|
-
* if (!request.data.email) {
|
|
1776
|
-
* throw new BadRequestException('Email is required')
|
|
1777
|
-
* }
|
|
1778
|
-
* // ...
|
|
1779
|
-
* }
|
|
1780
|
-
* ```
|
|
1781
|
-
*/
|
|
1782
|
-
declare class BadRequestException extends HttpException {
|
|
1783
|
-
/**
|
|
1784
|
-
* Creates a new BadRequestException.
|
|
1785
|
-
*
|
|
1786
|
-
* @param message - Error message or response object
|
|
1787
|
-
*/
|
|
1788
|
-
constructor(message: string | object);
|
|
1789
|
-
}
|
|
1790
|
-
//#endregion
|
|
1791
|
-
//#region src/exceptions/forbidden.exception.d.mts
|
|
1792
|
-
/**
|
|
1793
|
-
* Exception that represents a 403 Forbidden HTTP error.
|
|
1794
|
-
*
|
|
1795
|
-
* Use this exception when the client is authenticated but does not have
|
|
1796
|
-
* permission to access the requested resource.
|
|
1797
|
-
*
|
|
1798
|
-
* @example
|
|
1799
|
-
* ```typescript
|
|
1800
|
-
* @Endpoint(deleteUserEndpoint)
|
|
1801
|
-
* @UseGuards(AuthGuard, RoleGuard)
|
|
1802
|
-
* async deleteUser(request: EndpointParams<typeof deleteUserEndpoint>) {
|
|
1803
|
-
* if (!this.userService.hasPermission(request.user, 'delete')) {
|
|
1804
|
-
* throw new ForbiddenException('Insufficient permissions')
|
|
1805
|
-
* }
|
|
1806
|
-
* // ...
|
|
1807
|
-
* }
|
|
1808
|
-
* ```
|
|
1809
|
-
*/
|
|
1810
|
-
declare class ForbiddenException extends HttpException {
|
|
1811
|
-
/**
|
|
1812
|
-
* Creates a new ForbiddenException.
|
|
1813
|
-
*
|
|
1814
|
-
* @param message - Error message
|
|
1815
|
-
*/
|
|
1816
|
-
constructor(message: string);
|
|
1817
|
-
}
|
|
1818
|
-
//#endregion
|
|
1819
|
-
//#region src/exceptions/internal-server-error.exception.d.mts
|
|
1820
|
-
/**
|
|
1821
|
-
* Exception that represents a 500 Internal Server Error HTTP error.
|
|
1822
|
-
*
|
|
1823
|
-
* Use this exception when an unexpected error occurs on the server.
|
|
1824
|
-
* Generally, you should let unhandled errors bubble up rather than catching
|
|
1825
|
-
* and rethrowing as InternalServerErrorException, as Navios will handle them appropriately.
|
|
1826
|
-
*
|
|
1827
|
-
* @example
|
|
1828
|
-
* ```typescript
|
|
1829
|
-
* @Endpoint(processPaymentEndpoint)
|
|
1830
|
-
* async processPayment(request: EndpointParams<typeof processPaymentEndpoint>) {
|
|
1831
|
-
* try {
|
|
1832
|
-
* return await this.paymentService.process(request.data)
|
|
1833
|
-
* } catch (error) {
|
|
1834
|
-
* this.logger.error('Payment processing failed', error)
|
|
1835
|
-
* throw new InternalServerErrorException('Payment processing failed', error)
|
|
1836
|
-
* }
|
|
1837
|
-
* }
|
|
1838
|
-
* ```
|
|
1839
|
-
*/
|
|
1840
|
-
declare class InternalServerErrorException extends HttpException {
|
|
1841
|
-
/**
|
|
1842
|
-
* Creates a new InternalServerErrorException.
|
|
1843
|
-
*
|
|
1844
|
-
* @param message - Error message or response object
|
|
1845
|
-
* @param error - Optional underlying error for logging
|
|
1846
|
-
*/
|
|
1847
|
-
constructor(message: string | object, error?: Error);
|
|
1848
|
-
}
|
|
1849
|
-
//#endregion
|
|
1850
|
-
//#region src/exceptions/not-found.exception.d.mts
|
|
1851
|
-
/**
|
|
1852
|
-
* Exception that represents a 404 Not Found HTTP error.
|
|
1853
|
-
*
|
|
1854
|
-
* Use this exception when the requested resource does not exist.
|
|
1855
|
-
*
|
|
1856
|
-
* @example
|
|
1857
|
-
* ```typescript
|
|
1858
|
-
* @Endpoint(getUserEndpoint)
|
|
1859
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
1860
|
-
* const user = await this.userService.findById(request.urlParams.userId)
|
|
1861
|
-
* if (!user) {
|
|
1862
|
-
* throw new NotFoundException('User not found')
|
|
1863
|
-
* }
|
|
1864
|
-
* return user
|
|
1865
|
-
* }
|
|
1866
|
-
* ```
|
|
1867
|
-
*/
|
|
1868
|
-
declare class NotFoundException extends HttpException {
|
|
1869
|
-
readonly response: string | object;
|
|
1870
|
-
readonly error?: Error | undefined;
|
|
1871
|
-
/**
|
|
1872
|
-
* Creates a new NotFoundException.
|
|
1873
|
-
*
|
|
1874
|
-
* @param response - Error message or response object
|
|
1875
|
-
* @param error - Optional underlying error for logging
|
|
1876
|
-
*/
|
|
1877
|
-
constructor(response: string | object, error?: Error | undefined);
|
|
1878
|
-
}
|
|
1879
|
-
//#endregion
|
|
1880
|
-
//#region src/exceptions/unauthorized.exception.d.mts
|
|
1881
|
-
/**
|
|
1882
|
-
* Exception that represents a 401 Unauthorized HTTP error.
|
|
1883
|
-
*
|
|
1884
|
-
* Use this exception when the client is not authenticated or authentication failed.
|
|
1885
|
-
*
|
|
1886
|
-
* @example
|
|
1887
|
-
* ```typescript
|
|
1888
|
-
* @Endpoint(getUserEndpoint)
|
|
1889
|
-
* @UseGuards(AuthGuard)
|
|
1890
|
-
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
1891
|
-
* if (!request.headers.authorization) {
|
|
1892
|
-
* throw new UnauthorizedException('Authentication required')
|
|
1893
|
-
* }
|
|
1894
|
-
* // ...
|
|
1895
|
-
* }
|
|
1896
|
-
* ```
|
|
1897
|
-
*/
|
|
1898
|
-
declare class UnauthorizedException extends HttpException {
|
|
1899
|
-
/**
|
|
1900
|
-
* Creates a new UnauthorizedException.
|
|
1901
|
-
*
|
|
1902
|
-
* @param message - Error message or response object
|
|
1903
|
-
* @param error - Optional underlying error for logging
|
|
1904
|
-
*/
|
|
1905
|
-
constructor(message: string | object, error?: Error);
|
|
1906
|
-
}
|
|
1907
|
-
//#endregion
|
|
1908
|
-
//#region src/exceptions/conflict.exception.d.mts
|
|
1909
|
-
/**
|
|
1910
|
-
* Exception that represents a 409 Conflict HTTP error.
|
|
1911
|
-
*
|
|
1912
|
-
* Use this exception when the request conflicts with the current state of the resource
|
|
1913
|
-
* (e.g., trying to create a resource that already exists).
|
|
1914
|
-
*
|
|
1915
|
-
* @example
|
|
1916
|
-
* ```typescript
|
|
1917
|
-
* @Endpoint(createUserEndpoint)
|
|
1918
|
-
* async createUser(request: EndpointParams<typeof createUserEndpoint>) {
|
|
1919
|
-
* const existing = await this.userService.findByEmail(request.data.email)
|
|
1920
|
-
* if (existing) {
|
|
1921
|
-
* throw new ConflictException('User with this email already exists')
|
|
1922
|
-
* }
|
|
1923
|
-
* // ...
|
|
1924
|
-
* }
|
|
1925
|
-
* ```
|
|
1926
|
-
*/
|
|
1927
|
-
declare class ConflictException extends HttpException {
|
|
1928
|
-
/**
|
|
1929
|
-
* Creates a new ConflictException.
|
|
1930
|
-
*
|
|
1931
|
-
* @param message - Error message or response object
|
|
1932
|
-
* @param error - Optional underlying error for logging
|
|
1933
|
-
*/
|
|
1934
|
-
constructor(message: string | object, error?: Error);
|
|
1935
|
-
}
|
|
1936
|
-
//#endregion
|
|
1937
|
-
//#region src/responders/enums/framework-error.enum.d.mts
|
|
1938
|
-
/**
|
|
1939
|
-
* Enumeration of framework-level error types.
|
|
1940
|
-
* Used to explicitly specify which error responder should handle an error.
|
|
1941
|
-
*
|
|
1942
|
-
* @example
|
|
1943
|
-
* ```typescript
|
|
1944
|
-
* // In adapter error handling
|
|
1945
|
-
* if (error instanceof ZodError) {
|
|
1946
|
-
* return errorProducer.respond(FrameworkError.ValidationError, error)
|
|
1947
|
-
* }
|
|
1948
|
-
* return errorProducer.handleUnknown(error)
|
|
1949
|
-
* ```
|
|
1950
|
-
*/
|
|
1951
|
-
declare enum FrameworkError {
|
|
1952
|
-
/**
|
|
1953
|
-
* Resource not found (HTTP 404).
|
|
1954
|
-
* Use when a requested resource does not exist.
|
|
1955
|
-
*/
|
|
1956
|
-
NotFound = "NotFound",
|
|
1957
|
-
/**
|
|
1958
|
-
* Forbidden (HTTP 403).
|
|
1959
|
-
* Use when access to a resource is denied (e.g., guard rejection).
|
|
1960
|
-
*/
|
|
1961
|
-
Forbidden = "Forbidden",
|
|
1962
|
-
/**
|
|
1963
|
-
* Internal server error (HTTP 500).
|
|
1964
|
-
* Use for unexpected errors that don't fit other categories.
|
|
1965
|
-
*/
|
|
1966
|
-
InternalServerError = "InternalServerError",
|
|
1967
|
-
/**
|
|
1968
|
-
* Validation error (HTTP 400).
|
|
1969
|
-
* Use when request data fails validation (e.g., Zod errors).
|
|
1970
|
-
*/
|
|
1971
|
-
ValidationError = "ValidationError",
|
|
1972
|
-
}
|
|
1973
|
-
//#endregion
|
|
1974
|
-
//#region src/responders/interfaces/problem-details.interface.d.mts
|
|
1975
|
-
/**
|
|
1976
|
-
* RFC 7807 Problem Details for HTTP APIs
|
|
1977
|
-
* @see https://tools.ietf.org/html/rfc7807
|
|
1978
|
-
*/
|
|
1979
|
-
interface ProblemDetails {
|
|
1980
|
-
/**
|
|
1981
|
-
* A URI reference that identifies the problem type.
|
|
1982
|
-
* When dereferenced, it should provide human-readable documentation.
|
|
1983
|
-
* @default 'about:blank'
|
|
1984
|
-
*/
|
|
1985
|
-
type?: string;
|
|
1986
|
-
/**
|
|
1987
|
-
* A short, human-readable summary of the problem type.
|
|
1988
|
-
* It should not change from occurrence to occurrence.
|
|
1989
|
-
*/
|
|
1990
|
-
title: string;
|
|
1991
|
-
/**
|
|
1992
|
-
* The HTTP status code for this occurrence of the problem.
|
|
1993
|
-
*/
|
|
1994
|
-
status: number;
|
|
1995
|
-
/**
|
|
1996
|
-
* A human-readable explanation specific to this occurrence of the problem.
|
|
1997
|
-
*/
|
|
1998
|
-
detail?: string;
|
|
1999
|
-
/**
|
|
2000
|
-
* Additional extension members.
|
|
2001
|
-
* Custom properties can be added to provide more context.
|
|
2002
|
-
*/
|
|
2003
|
-
[key: string]: unknown;
|
|
2004
|
-
}
|
|
2005
|
-
//#endregion
|
|
2006
|
-
//#region src/responders/interfaces/error-response.interface.d.mts
|
|
2007
|
-
/**
|
|
2008
|
-
* Represents a complete error response that can be sent to the client.
|
|
2009
|
-
* Includes the status code, payload (RFC 7807 Problem Details), and headers.
|
|
2010
|
-
*/
|
|
2011
|
-
interface ErrorResponse {
|
|
2012
|
-
/**
|
|
2013
|
-
* HTTP status code for the response.
|
|
2014
|
-
*/
|
|
2015
|
-
statusCode: number;
|
|
2016
|
-
/**
|
|
2017
|
-
* RFC 7807 Problem Details payload.
|
|
2018
|
-
*/
|
|
2019
|
-
payload: ProblemDetails;
|
|
2020
|
-
/**
|
|
2021
|
-
* HTTP headers to include in the response.
|
|
2022
|
-
*/
|
|
2023
|
-
headers: Record<string, string>;
|
|
2024
|
-
}
|
|
2025
|
-
//#endregion
|
|
2026
|
-
//#region src/responders/interfaces/error-responder.interface.d.mts
|
|
2027
|
-
/**
|
|
2028
|
-
* Interface for error responders that convert errors to HTTP responses.
|
|
2029
|
-
* Each responder handles a specific type of framework error and produces
|
|
2030
|
-
* an RFC 7807 compliant response.
|
|
2031
|
-
*
|
|
2032
|
-
* Implementations are registered with low priority (-10) so they can be
|
|
2033
|
-
* easily overridden by consumers.
|
|
2034
|
-
*
|
|
2035
|
-
* @example
|
|
2036
|
-
* ```typescript
|
|
2037
|
-
* @Injectable({
|
|
2038
|
-
* token: InternalServerErrorResponderToken,
|
|
2039
|
-
* priority: 0, // Override default implementation
|
|
2040
|
-
* })
|
|
2041
|
-
* export class CustomInternalErrorResponder implements ErrorResponder {
|
|
2042
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2043
|
-
* return {
|
|
2044
|
-
* statusCode: 500,
|
|
2045
|
-
* payload: {
|
|
2046
|
-
* type: 'https://api.myapp.com/errors/server-error',
|
|
2047
|
-
* title: 'Server Error',
|
|
2048
|
-
* status: 500,
|
|
2049
|
-
* detail: description ?? 'An unexpected error occurred',
|
|
2050
|
-
* },
|
|
2051
|
-
* headers: { 'Content-Type': 'application/problem+json' },
|
|
2052
|
-
* }
|
|
2053
|
-
* }
|
|
2054
|
-
* }
|
|
2055
|
-
* ```
|
|
2056
|
-
*/
|
|
2057
|
-
interface ErrorResponder {
|
|
2058
|
-
/**
|
|
2059
|
-
* Converts an error to an ErrorResponse with RFC 7807 Problem Details.
|
|
2060
|
-
*
|
|
2061
|
-
* @param error - The original error that was thrown
|
|
2062
|
-
* @param description - Optional custom description to include in the response
|
|
2063
|
-
* @returns ErrorResponse with status code, payload, and headers
|
|
2064
|
-
*/
|
|
2065
|
-
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
2066
|
-
}
|
|
2067
|
-
//#endregion
|
|
2068
|
-
//#region src/responders/services/error-response-producer.service.d.mts
|
|
2069
|
-
/**
|
|
2070
|
-
* Service for producing standardized error responses.
|
|
2071
|
-
*
|
|
2072
|
-
* This service coordinates error responders to produce RFC 7807 compliant
|
|
2073
|
-
* Problem Details responses. Adapters use this service to convert errors
|
|
2074
|
-
* into standardized HTTP responses.
|
|
2075
|
-
*
|
|
2076
|
-
* The caller explicitly specifies which type of error response to produce
|
|
2077
|
-
* via the FrameworkError enum, giving full control to the adapter.
|
|
2078
|
-
*
|
|
2079
|
-
* @example Usage in an adapter:
|
|
2080
|
-
* ```typescript
|
|
2081
|
-
* @Injectable()
|
|
2082
|
-
* class MyAdapter {
|
|
2083
|
-
* private errorProducer = inject(ErrorResponseProducerService)
|
|
2084
|
-
*
|
|
2085
|
-
* handleError(error: unknown): Response {
|
|
2086
|
-
* if (error instanceof ZodError) {
|
|
2087
|
-
* const response = this.errorProducer.respond(
|
|
2088
|
-
* FrameworkError.ValidationError,
|
|
2089
|
-
* error,
|
|
2090
|
-
* )
|
|
2091
|
-
* return new Response(JSON.stringify(response.payload), {
|
|
2092
|
-
* status: response.statusCode,
|
|
2093
|
-
* headers: response.headers,
|
|
2094
|
-
* })
|
|
2095
|
-
* }
|
|
2096
|
-
*
|
|
2097
|
-
* // Fallback for unknown errors
|
|
2098
|
-
* const response = this.errorProducer.handleUnknown(error)
|
|
2099
|
-
* return new Response(JSON.stringify(response.payload), {
|
|
2100
|
-
* status: response.statusCode,
|
|
2101
|
-
* headers: response.headers,
|
|
2102
|
-
* })
|
|
2103
|
-
* }
|
|
2104
|
-
* }
|
|
2105
|
-
* ```
|
|
2106
|
-
*/
|
|
2107
|
-
declare class ErrorResponseProducerService {
|
|
2108
|
-
private readonly forbiddenResponder;
|
|
2109
|
-
private readonly internalServerErrorResponder;
|
|
2110
|
-
private readonly notFoundResponder;
|
|
2111
|
-
private readonly validationErrorResponder;
|
|
2112
|
-
/**
|
|
2113
|
-
* Produces an error response for a specific framework error type.
|
|
2114
|
-
*
|
|
2115
|
-
* @param type - The type of framework error (from FrameworkError enum)
|
|
2116
|
-
* @param error - The original error that was thrown
|
|
2117
|
-
* @param description - Optional custom description to include in the response
|
|
2118
|
-
* @returns ErrorResponse with status code, RFC 7807 payload, and headers
|
|
2119
|
-
*/
|
|
2120
|
-
respond(type: FrameworkError, error: unknown, description?: string): ErrorResponse;
|
|
2121
|
-
/**
|
|
2122
|
-
* Handles unknown errors by producing an Internal Server Error response.
|
|
2123
|
-
*
|
|
2124
|
-
* Use this as a fallback when the error type is not known or doesn't
|
|
2125
|
-
* match any specific framework error type.
|
|
2126
|
-
*
|
|
2127
|
-
* @param error - The original error that was thrown
|
|
2128
|
-
* @param description - Optional custom description to include in the response
|
|
2129
|
-
* @returns ErrorResponse with 500 status code
|
|
2130
|
-
*/
|
|
2131
|
-
handleUnknown(error: unknown, description?: string): ErrorResponse;
|
|
2132
|
-
/**
|
|
2133
|
-
* Convenience method to produce a Not Found error response.
|
|
2134
|
-
*
|
|
2135
|
-
* @param error - The original error that was thrown
|
|
2136
|
-
* @param description - Optional custom description
|
|
2137
|
-
* @returns ErrorResponse with 404 status code
|
|
2138
|
-
*/
|
|
2139
|
-
notFound(error: unknown, description?: string): ErrorResponse;
|
|
2140
|
-
/**
|
|
2141
|
-
* Convenience method to produce a Validation Error response.
|
|
2142
|
-
*
|
|
2143
|
-
* @param error - The original error (typically a ZodError)
|
|
2144
|
-
* @param description - Optional custom description
|
|
2145
|
-
* @returns ErrorResponse with 400 status code
|
|
2146
|
-
*/
|
|
2147
|
-
validationError(error: unknown, description?: string): ErrorResponse;
|
|
2148
|
-
/**
|
|
2149
|
-
* Convenience method to produce an Internal Server Error response.
|
|
2150
|
-
*
|
|
2151
|
-
* @param error - The original error
|
|
2152
|
-
* @param description - Optional custom description
|
|
2153
|
-
* @returns ErrorResponse with 500 status code
|
|
2154
|
-
*/
|
|
2155
|
-
internalServerError(error: unknown, description?: string): ErrorResponse;
|
|
2156
|
-
/**
|
|
2157
|
-
* Convenience method to produce a Forbidden error response.
|
|
2158
|
-
*
|
|
2159
|
-
* @param error - The original error
|
|
2160
|
-
* @param description - Optional custom description
|
|
2161
|
-
* @returns ErrorResponse with 403 status code
|
|
2162
|
-
*/
|
|
2163
|
-
forbidden(error: unknown, description?: string): ErrorResponse;
|
|
2164
|
-
}
|
|
2165
|
-
//#endregion
|
|
2166
|
-
//#region src/responders/services/forbidden-responder.service.d.mts
|
|
2167
|
-
/**
|
|
2168
|
-
* Default responder for forbidden errors (HTTP 403).
|
|
2169
|
-
*
|
|
2170
|
-
* Converts errors to RFC 7807 Problem Details format.
|
|
2171
|
-
* Used when access to a resource is denied (e.g., guard rejection).
|
|
2172
|
-
* Registered with low priority (-10) so it can be easily overridden.
|
|
2173
|
-
*
|
|
2174
|
-
* @example Override with custom implementation:
|
|
2175
|
-
* ```typescript
|
|
2176
|
-
* @Injectable({
|
|
2177
|
-
* token: ForbiddenResponderToken,
|
|
2178
|
-
* priority: 0,
|
|
2179
|
-
* })
|
|
2180
|
-
* export class CustomForbiddenResponder implements ErrorResponder {
|
|
2181
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2182
|
-
* return {
|
|
2183
|
-
* statusCode: 403,
|
|
2184
|
-
* payload: {
|
|
2185
|
-
* type: 'https://api.myapp.com/errors/forbidden',
|
|
2186
|
-
* title: 'Access Denied',
|
|
2187
|
-
* status: 403,
|
|
2188
|
-
* detail: description ?? 'You do not have permission to access this resource',
|
|
2189
|
-
* },
|
|
2190
|
-
* headers: { 'Content-Type': 'application/problem+json' },
|
|
2191
|
-
* }
|
|
2192
|
-
* }
|
|
2193
|
-
* }
|
|
2194
|
-
* ```
|
|
2195
|
-
*/
|
|
2196
|
-
declare class ForbiddenResponderService implements ErrorResponder {
|
|
2197
|
-
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
2198
|
-
private createResponse;
|
|
2199
|
-
}
|
|
2200
|
-
//#endregion
|
|
2201
|
-
//#region src/responders/services/internal-server-error-responder.service.d.mts
|
|
2202
|
-
/**
|
|
2203
|
-
* Default responder for internal server errors (HTTP 500).
|
|
2204
|
-
*
|
|
2205
|
-
* Converts generic errors to RFC 7807 Problem Details format.
|
|
2206
|
-
* Registered with low priority (-10) so it can be easily overridden.
|
|
2207
|
-
*
|
|
2208
|
-
* @example Override with custom implementation:
|
|
2209
|
-
* ```typescript
|
|
2210
|
-
* @Injectable({
|
|
2211
|
-
* token: InternalServerErrorResponderToken,
|
|
2212
|
-
* priority: 0,
|
|
2213
|
-
* })
|
|
2214
|
-
* export class CustomInternalErrorResponder implements ErrorResponder {
|
|
2215
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2216
|
-
* return {
|
|
2217
|
-
* statusCode: 500,
|
|
2218
|
-
* payload: {
|
|
2219
|
-
* type: 'https://api.myapp.com/errors/server-error',
|
|
2220
|
-
* title: 'Server Error',
|
|
2221
|
-
* status: 500,
|
|
2222
|
-
* detail: description ?? 'An unexpected error occurred',
|
|
2223
|
-
* },
|
|
2224
|
-
* headers: { 'Content-Type': 'application/problem+json' },
|
|
2225
|
-
* }
|
|
2226
|
-
* }
|
|
2227
|
-
* }
|
|
2228
|
-
* ```
|
|
2229
|
-
*/
|
|
2230
|
-
declare class InternalServerErrorResponderService implements ErrorResponder {
|
|
2231
|
-
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
2232
|
-
}
|
|
2233
|
-
//#endregion
|
|
2234
|
-
//#region src/responders/services/not-found-responder.service.d.mts
|
|
2235
|
-
/**
|
|
2236
|
-
* Default responder for not found errors (HTTP 404).
|
|
2237
|
-
*
|
|
2238
|
-
* Converts errors to RFC 7807 Problem Details format.
|
|
2239
|
-
* Registered with low priority (-10) so it can be easily overridden.
|
|
2240
|
-
*
|
|
2241
|
-
* @example Override with custom implementation:
|
|
2242
|
-
* ```typescript
|
|
2243
|
-
* @Injectable({
|
|
2244
|
-
* token: NotFoundResponderToken,
|
|
2245
|
-
* priority: 0,
|
|
2246
|
-
* })
|
|
2247
|
-
* export class CustomNotFoundResponder implements ErrorResponder {
|
|
2248
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2249
|
-
* return {
|
|
2250
|
-
* statusCode: 404,
|
|
2251
|
-
* payload: {
|
|
2252
|
-
* type: 'https://api.myapp.com/errors/not-found',
|
|
2253
|
-
* title: 'Resource Not Found',
|
|
2254
|
-
* status: 404,
|
|
2255
|
-
* detail: description ?? 'The requested resource was not found',
|
|
2256
|
-
* },
|
|
2257
|
-
* headers: { 'Content-Type': 'application/problem+json' },
|
|
2258
|
-
* }
|
|
2259
|
-
* }
|
|
2260
|
-
* }
|
|
2261
|
-
* ```
|
|
2262
|
-
*/
|
|
2263
|
-
declare class NotFoundResponderService implements ErrorResponder {
|
|
2264
|
-
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
2265
|
-
private createResponse;
|
|
2266
|
-
}
|
|
2267
|
-
//#endregion
|
|
2268
|
-
//#region src/responders/services/validation-error-responder.service.d.mts
|
|
2269
|
-
/**
|
|
2270
|
-
* Default responder for validation errors (HTTP 400).
|
|
2271
|
-
*
|
|
2272
|
-
* Converts Zod validation errors to RFC 7807 Problem Details format.
|
|
2273
|
-
* Includes the structured validation errors from treeifyError.
|
|
2274
|
-
* Registered with low priority (-10) so it can be easily overridden.
|
|
2275
|
-
*
|
|
2276
|
-
* @example Override with custom implementation:
|
|
2277
|
-
* ```typescript
|
|
2278
|
-
* @Injectable({
|
|
2279
|
-
* token: ValidationErrorResponderToken,
|
|
2280
|
-
* priority: 0,
|
|
2281
|
-
* })
|
|
2282
|
-
* export class CustomValidationResponder implements ErrorResponder {
|
|
2283
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2284
|
-
* const zodError = error as ZodError
|
|
2285
|
-
* return {
|
|
2286
|
-
* statusCode: 422, // Use 422 instead of 400
|
|
2287
|
-
* payload: {
|
|
2288
|
-
* type: 'https://api.myapp.com/errors/validation',
|
|
2289
|
-
* title: 'Unprocessable Entity',
|
|
2290
|
-
* status: 422,
|
|
2291
|
-
* detail: description ?? 'Validation failed',
|
|
2292
|
-
* issues: zodError.issues,
|
|
2293
|
-
* },
|
|
2294
|
-
* headers: { 'Content-Type': 'application/problem+json' },
|
|
2295
|
-
* }
|
|
2296
|
-
* }
|
|
2297
|
-
* }
|
|
2298
|
-
* ```
|
|
2299
|
-
*/
|
|
2300
|
-
declare class ValidationErrorResponderService implements ErrorResponder {
|
|
2301
|
-
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
2302
|
-
}
|
|
2303
|
-
//#endregion
|
|
2304
|
-
//#region src/responders/tokens/responder.tokens.d.mts
|
|
2305
|
-
/**
|
|
2306
|
-
* Injection token for the Internal Server Error responder.
|
|
2307
|
-
* Default implementation returns HTTP 500 with RFC 7807 Problem Details.
|
|
2308
|
-
*
|
|
2309
|
-
* @example Override with custom implementation:
|
|
2310
|
-
* ```typescript
|
|
2311
|
-
* @Injectable({
|
|
2312
|
-
* token: InternalServerErrorResponderToken,
|
|
2313
|
-
* priority: 0, // Higher than default -10
|
|
2314
|
-
* })
|
|
2315
|
-
* export class CustomInternalErrorResponder implements ErrorResponder {
|
|
2316
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2317
|
-
* // Custom implementation
|
|
2318
|
-
* }
|
|
2319
|
-
* }
|
|
2320
|
-
* ```
|
|
2321
|
-
*/
|
|
2322
|
-
declare const InternalServerErrorResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2323
|
-
/**
|
|
2324
|
-
* Injection token for the Not Found responder.
|
|
2325
|
-
* Default implementation returns HTTP 404 with RFC 7807 Problem Details.
|
|
2326
|
-
*
|
|
2327
|
-
* @example Override with custom implementation:
|
|
2328
|
-
* ```typescript
|
|
2329
|
-
* @Injectable({
|
|
2330
|
-
* token: NotFoundResponderToken,
|
|
2331
|
-
* priority: 0, // Higher than default -10
|
|
2332
|
-
* })
|
|
2333
|
-
* export class CustomNotFoundResponder implements ErrorResponder {
|
|
2334
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2335
|
-
* // Custom implementation
|
|
2336
|
-
* }
|
|
2337
|
-
* }
|
|
2338
|
-
* ```
|
|
2339
|
-
*/
|
|
2340
|
-
declare const NotFoundResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2341
|
-
/**
|
|
2342
|
-
* Injection token for the Validation Error responder.
|
|
2343
|
-
* Default implementation returns HTTP 400 with RFC 7807 Problem Details
|
|
2344
|
-
* and includes validation errors from ZodError.
|
|
2345
|
-
*
|
|
2346
|
-
* @example Override with custom implementation:
|
|
2347
|
-
* ```typescript
|
|
2348
|
-
* @Injectable({
|
|
2349
|
-
* token: ValidationErrorResponderToken,
|
|
2350
|
-
* priority: 0, // Higher than default -10
|
|
2351
|
-
* })
|
|
2352
|
-
* export class CustomValidationResponder implements ErrorResponder {
|
|
2353
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2354
|
-
* // Custom implementation
|
|
2355
|
-
* }
|
|
2356
|
-
* }
|
|
2357
|
-
* ```
|
|
2358
|
-
*/
|
|
2359
|
-
declare const ValidationErrorResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2360
|
-
/**
|
|
2361
|
-
* Injection token for the Forbidden responder.
|
|
2362
|
-
* Default implementation returns HTTP 403 with RFC 7807 Problem Details.
|
|
2363
|
-
*
|
|
2364
|
-
* @example Override with custom implementation:
|
|
2365
|
-
* ```typescript
|
|
2366
|
-
* @Injectable({
|
|
2367
|
-
* token: ForbiddenResponderToken,
|
|
2368
|
-
* priority: 0, // Higher than default -10
|
|
2369
|
-
* })
|
|
2370
|
-
* export class CustomForbiddenResponder implements ErrorResponder {
|
|
2371
|
-
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2372
|
-
* // Custom implementation
|
|
2373
|
-
* }
|
|
2374
|
-
* }
|
|
2375
|
-
* ```
|
|
2376
|
-
*/
|
|
2377
|
-
declare const ForbiddenResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2378
|
-
//#endregion
|
|
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
|
|
2385
|
-
/**
|
|
2386
|
-
* Options for configuring the Navios application context.
|
|
2387
|
-
* These options control the application configuration.
|
|
2388
|
-
*/
|
|
2389
|
-
interface NaviosApplicationOptions {
|
|
2390
|
-
/**
|
|
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
|
|
2396
|
-
*/
|
|
2397
|
-
logger?: LoggerService | LogLevel[] | false;
|
|
2398
|
-
/**
|
|
2399
|
-
* Specifies a custom registry to use. Useful for testing.
|
|
2400
|
-
* If not provided, a new Registry will be created.
|
|
2401
|
-
*/
|
|
2402
|
-
registry?: Registry;
|
|
2403
|
-
/**
|
|
2404
|
-
* Specifies a custom container to use. Useful for testing.
|
|
2405
|
-
* If not provided, a new Container will be created.
|
|
2406
|
-
*/
|
|
2407
|
-
container?: Container;
|
|
2408
|
-
/**
|
|
2409
|
-
* Adapter environment(s) to use for the application.
|
|
2410
|
-
* Can be a single adapter or an array of adapters.
|
|
2411
|
-
*
|
|
2412
|
-
* @example
|
|
2413
|
-
* ```typescript
|
|
2414
|
-
* adapter: defineFastifyEnvironment()
|
|
2415
|
-
* // or
|
|
2416
|
-
* adapter: [defineFastifyEnvironment()]
|
|
2417
|
-
* ```
|
|
2418
|
-
*/
|
|
2419
|
-
adapter: NaviosEnvironmentOptions | NaviosEnvironmentOptions[];
|
|
2420
|
-
/**
|
|
2421
|
-
* Whether to validate response schemas.
|
|
2422
|
-
* When `false`, response schema validation is skipped for better performance.
|
|
2423
|
-
* @default true
|
|
2424
|
-
*/
|
|
2425
|
-
validateResponses?: boolean;
|
|
2426
|
-
/**
|
|
2427
|
-
* Whether to enable request ID propagation via AsyncLocalStorage.
|
|
2428
|
-
* When `true`, request IDs are available via `getRequestId()` throughout the request.
|
|
2429
|
-
* @default false
|
|
2430
|
-
*/
|
|
2431
|
-
enableRequestId?: boolean;
|
|
2432
|
-
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Main application class for Navios.
|
|
2435
|
-
*
|
|
2436
|
-
* This class represents a Navios application instance and provides methods
|
|
2437
|
-
* for initializing, configuring, and managing the application lifecycle.
|
|
2438
|
-
*
|
|
2439
|
-
* @example
|
|
2440
|
-
* ```typescript
|
|
2441
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
2442
|
-
* adapter: defineFastifyEnvironment(),
|
|
2443
|
-
* })
|
|
2444
|
-
*
|
|
2445
|
-
* app.setGlobalPrefix('/api')
|
|
2446
|
-
* app.enableCors({ origin: ['http://localhost:3000'] })
|
|
2447
|
-
* await app.init()
|
|
2448
|
-
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
2449
|
-
* ```
|
|
2450
|
-
*/
|
|
2451
|
-
declare class NaviosApplication<Environment extends AdapterEnvironment = DefaultAdapterEnvironment> {
|
|
2452
|
-
private environment;
|
|
2453
|
-
private moduleLoader;
|
|
2454
|
-
private adapter;
|
|
2455
|
-
private logger;
|
|
2456
|
-
protected container: Container;
|
|
2457
|
-
private appModule;
|
|
2458
|
-
private options;
|
|
2459
|
-
private plugins;
|
|
2460
|
-
/**
|
|
2461
|
-
* Indicates whether the application has been initialized.
|
|
2462
|
-
* Set to `true` after `init()` completes successfully.
|
|
2463
|
-
*/
|
|
2464
|
-
isInitialized: boolean;
|
|
2465
|
-
/**
|
|
2466
|
-
* Sets up the application with the provided module and options.
|
|
2467
|
-
* This is called automatically by NaviosFactory.create().
|
|
2468
|
-
*
|
|
2469
|
-
* @param appModule - The root application module
|
|
2470
|
-
* @param options - Application configuration options
|
|
2471
|
-
* @internal
|
|
2472
|
-
*/
|
|
2473
|
-
setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<void>;
|
|
2474
|
-
/**
|
|
2475
|
-
* Gets the dependency injection container used by this application.
|
|
2476
|
-
*
|
|
2477
|
-
* @returns The Container instance
|
|
2478
|
-
*/
|
|
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'];
|
|
2487
|
-
/**
|
|
2488
|
-
* Registers a plugin to be initialized after modules are loaded.
|
|
2489
|
-
*
|
|
2490
|
-
* Plugins are initialized in the order they are registered,
|
|
2491
|
-
* after all modules are loaded but before the server starts listening.
|
|
2492
|
-
*
|
|
2493
|
-
* @param definition - Plugin definition with options
|
|
2494
|
-
* @returns this for method chaining
|
|
2495
|
-
*
|
|
2496
|
-
* @example
|
|
2497
|
-
* ```typescript
|
|
2498
|
-
* import { defineOpenApiPlugin } from '@navios/openapi-fastify'
|
|
2499
|
-
*
|
|
2500
|
-
* app.usePlugin(defineOpenApiPlugin({
|
|
2501
|
-
* info: { title: 'My API', version: '1.0.0' },
|
|
2502
|
-
* }))
|
|
2503
|
-
* ```
|
|
2504
|
-
*/
|
|
2505
|
-
usePlugin<TOptions, TAdapter extends AbstractAdapterInterface>(definition: PluginDefinition<TOptions, TAdapter>): this;
|
|
2506
|
-
/**
|
|
2507
|
-
* Initializes the application.
|
|
2508
|
-
*
|
|
2509
|
-
* This method:
|
|
2510
|
-
* - Loads all modules and their dependencies
|
|
2511
|
-
* - Sets up the adapter if one is configured
|
|
2512
|
-
* - Calls onModuleInit hooks on all modules
|
|
2513
|
-
* - Initializes registered plugins
|
|
2514
|
-
* - Marks the application as initialized
|
|
2515
|
-
*
|
|
2516
|
-
* Must be called before `listen()`.
|
|
2517
|
-
*
|
|
2518
|
-
* @throws Error if app module is not set
|
|
2519
|
-
*
|
|
2520
|
-
* @example
|
|
2521
|
-
* ```typescript
|
|
2522
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
2523
|
-
* adapter: defineFastifyEnvironment(),
|
|
2524
|
-
* })
|
|
2525
|
-
* await app.init()
|
|
2526
|
-
* await app.listen({ port: 3000 })
|
|
2527
|
-
* ```
|
|
2528
|
-
*/
|
|
2529
|
-
init(): Promise<void>;
|
|
2530
|
-
private initModules;
|
|
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;
|
|
2573
|
-
/**
|
|
2574
|
-
* Enables CORS (Cross-Origin Resource Sharing) for the application.
|
|
2575
|
-
*
|
|
2576
|
-
* @param options - CORS configuration options (adapter-specific)
|
|
2577
|
-
* @throws Error if adapter doesn't support enableCors
|
|
2578
|
-
*
|
|
2579
|
-
* @example
|
|
2580
|
-
* ```typescript
|
|
2581
|
-
* app.enableCors({
|
|
2582
|
-
* origin: ['http://localhost:3000', 'https://example.com'],
|
|
2583
|
-
* methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
2584
|
-
* credentials: true,
|
|
2585
|
-
* })
|
|
2586
|
-
* ```
|
|
2587
|
-
*/
|
|
2588
|
-
enableCors(options: Environment extends HttpAdapterEnvironment ? Environment['corsOptions'] : never): void;
|
|
2589
|
-
/**
|
|
2590
|
-
* Enables multipart/form-data support for file uploads.
|
|
2591
|
-
*
|
|
2592
|
-
* @param options - Multipart configuration options (adapter-specific)
|
|
2593
|
-
* @throws Error if adapter doesn't support enableMultipart
|
|
2594
|
-
*
|
|
2595
|
-
* @example
|
|
2596
|
-
* ```typescript
|
|
2597
|
-
* app.enableMultipart({
|
|
2598
|
-
* limits: {
|
|
2599
|
-
* fileSize: 1024 * 1024 * 10, // 10MB
|
|
2600
|
-
* },
|
|
2601
|
-
* })
|
|
2602
|
-
* ```
|
|
2603
|
-
*/
|
|
2604
|
-
enableMultipart(options: Environment extends HttpAdapterEnvironment ? Environment['multipartOptions'] : never): void;
|
|
2605
|
-
/**
|
|
2606
|
-
* Sets a global prefix for all routes.
|
|
2607
|
-
*
|
|
2608
|
-
* @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
|
|
2609
|
-
* @throws Error if adapter doesn't support setGlobalPrefix
|
|
2610
|
-
*
|
|
2611
|
-
* @example
|
|
2612
|
-
* ```typescript
|
|
2613
|
-
* app.setGlobalPrefix('/api/v1')
|
|
2614
|
-
* // All routes will be prefixed with /api/v1
|
|
2615
|
-
* ```
|
|
2616
|
-
*/
|
|
2617
|
-
setGlobalPrefix(prefix: string): void;
|
|
2618
|
-
/**
|
|
2619
|
-
* Gets the underlying HTTP server instance.
|
|
2620
|
-
*
|
|
2621
|
-
* The type of the returned server depends on the adapter used:
|
|
2622
|
-
* - Fastify adapter: Returns FastifyInstance
|
|
2623
|
-
* - Bun adapter: Returns Bun.Server
|
|
2624
|
-
*
|
|
2625
|
-
* @returns The HTTP server instance
|
|
2626
|
-
* @throws Error if adapter doesn't support getServer
|
|
2627
|
-
*
|
|
2628
|
-
* @example
|
|
2629
|
-
* ```typescript
|
|
2630
|
-
* const server = app.getServer()
|
|
2631
|
-
* // Use adapter-specific server methods
|
|
2632
|
-
* ```
|
|
2633
|
-
*/
|
|
2634
|
-
getServer(): Environment extends HttpAdapterEnvironment ? Environment['server'] : never;
|
|
2635
|
-
/**
|
|
2636
|
-
* Starts the HTTP server and begins listening for requests.
|
|
2637
|
-
*
|
|
2638
|
-
* @param options - Listen options (port, host, etc.)
|
|
2639
|
-
* @throws Error if adapter doesn't support listen
|
|
2640
|
-
*
|
|
2641
|
-
* @example
|
|
2642
|
-
* ```typescript
|
|
2643
|
-
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
2644
|
-
* ```
|
|
2645
|
-
*/
|
|
2646
|
-
listen(options: Environment extends HttpAdapterEnvironment ? Environment['listenOptions'] : never): Promise<string>;
|
|
2647
|
-
/**
|
|
2648
|
-
* Disposes of application resources.
|
|
2649
|
-
*
|
|
2650
|
-
* Cleans up the adapter and module loader.
|
|
2651
|
-
* This method is called automatically by `close()`.
|
|
2652
|
-
*/
|
|
2653
|
-
dispose(): Promise<void>;
|
|
2654
|
-
/**
|
|
2655
|
-
* Closes the application and cleans up all resources.
|
|
2656
|
-
*
|
|
2657
|
-
* This is an alias for `dispose()`.
|
|
2658
|
-
*
|
|
2659
|
-
* @example
|
|
2660
|
-
* ```typescript
|
|
2661
|
-
* // Graceful shutdown
|
|
2662
|
-
* process.on('SIGTERM', async () => {
|
|
2663
|
-
* await app.close()
|
|
2664
|
-
* process.exit(0)
|
|
2665
|
-
* })
|
|
2666
|
-
* ```
|
|
2667
|
-
*/
|
|
2668
|
-
close(): Promise<void>;
|
|
2669
|
-
}
|
|
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
|
-
//#endregion
|
|
2770
|
-
//#region src/services/abstract-handler-adapter.service.d.mts
|
|
2771
|
-
/**
|
|
2772
|
-
* Function type for argument getters that extract data from requests.
|
|
2773
|
-
* Re-exported from interface for convenience in adapter implementations.
|
|
2774
|
-
*/
|
|
2775
|
-
type ArgumentGetter<TRequest> = ArgumentGetterFn<TRequest>;
|
|
2776
|
-
/**
|
|
2777
|
-
* Internal alias for FormatArgumentsFn from interface.
|
|
2778
|
-
* Not re-exported to avoid duplicate exports - use FormatArgumentsFn from interfaces instead.
|
|
2779
|
-
*/
|
|
2780
|
-
type FormatArgumentsFn<TRequest> = FormatArgumentsFn$1<TRequest>;
|
|
2781
|
-
/**
|
|
2782
|
-
* Static handler - can be called without a scoped container.
|
|
2783
|
-
*/
|
|
2784
|
-
type AbstractStaticHandler<TRequest, TReply = void> = {
|
|
2785
|
-
isStatic: true;
|
|
2786
|
-
handler: (request: TRequest, reply: TReply) => Promise<any>;
|
|
2787
|
-
};
|
|
2788
|
-
/**
|
|
2789
|
-
* Dynamic handler - requires a scoped container for resolution.
|
|
2790
|
-
*/
|
|
2791
|
-
type AbstractDynamicHandler<TRequest, TReply = void> = {
|
|
2792
|
-
isStatic: false;
|
|
2793
|
-
handler: (scoped: ScopedContainer, request: TRequest, reply: TReply) => Promise<any>;
|
|
2794
|
-
};
|
|
2795
|
-
/**
|
|
2796
|
-
* Handler result - either static or dynamic.
|
|
2797
|
-
*/
|
|
2798
|
-
type AbstractHandlerResult<TRequest, TReply = void> = AbstractStaticHandler<TRequest, TReply> | AbstractDynamicHandler<TRequest, TReply>;
|
|
2799
|
-
/**
|
|
2800
|
-
* Context passed to handler creation methods.
|
|
2801
|
-
*/
|
|
2802
|
-
interface HandlerContext<TConfig extends BaseEndpointOptions = BaseEndpointOptions> {
|
|
2803
|
-
methodName: string;
|
|
2804
|
-
statusCode: number;
|
|
2805
|
-
headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
|
|
2806
|
-
handlerMetadata: HandlerMetadata<TConfig>;
|
|
2807
|
-
hasArguments: boolean;
|
|
2808
|
-
}
|
|
2809
|
-
/**
|
|
2810
|
-
* Abstract base class for HTTP handler adapter services.
|
|
2811
|
-
*
|
|
2812
|
-
* Provides shared logic for:
|
|
2813
|
-
* - Controller resolution (singleton vs request-scoped)
|
|
2814
|
-
* - Argument formatting (sync/async detection)
|
|
2815
|
-
* - Handler generation with static/dynamic branching
|
|
2816
|
-
* - Standardized error handling
|
|
2817
|
-
*
|
|
2818
|
-
* Adapters implement abstract methods for framework-specific behavior:
|
|
2819
|
-
* - Request parsing (query, body, URL params)
|
|
2820
|
-
* - Response creation
|
|
2821
|
-
* - Schema provision
|
|
2822
|
-
*
|
|
2823
|
-
* Supports all adapter types:
|
|
2824
|
-
* - Endpoint adapters: JSON request/response with validation
|
|
2825
|
-
* - Stream adapters: Streaming responses with extra context
|
|
2826
|
-
* - Multipart adapters: Form data parsing (extends endpoint)
|
|
2827
|
-
*
|
|
2828
|
-
* @typeParam TRequest - Framework request type (BunRequest, FastifyRequest)
|
|
2829
|
-
* @typeParam TReply - Framework reply type (void for Bun, FastifyReply)
|
|
2830
|
-
* @typeParam TConfig - Endpoint configuration type
|
|
2831
|
-
*/
|
|
2832
|
-
declare abstract class AbstractHandlerAdapterService<TRequest, TReply = void, TConfig extends BaseEndpointOptions = BaseEndpointOptions> {
|
|
2833
|
-
protected instanceResolver: InstanceResolverService;
|
|
2834
|
-
protected options: NaviosApplicationOptions;
|
|
2835
|
-
/**
|
|
2836
|
-
* Creates argument getter functions for extracting data from requests.
|
|
2837
|
-
*
|
|
2838
|
-
* Each getter populates a target object with data from the request
|
|
2839
|
-
* (query params, body, URL params, etc.).
|
|
2840
|
-
*
|
|
2841
|
-
* Implementation varies by adapter type:
|
|
2842
|
-
* - Endpoint: JSON body parsing with schema validation
|
|
2843
|
-
* - Stream: Same as endpoint (body + query + url params)
|
|
2844
|
-
* - Multipart: FormData/multipart stream parsing
|
|
2845
|
-
*
|
|
2846
|
-
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
2847
|
-
* @returns Array of getter functions
|
|
2848
|
-
*/
|
|
2849
|
-
protected abstract createArgumentGetters(handlerMetadata: HandlerMetadata<TConfig>): ArgumentGetter<TRequest>[];
|
|
2850
|
-
/**
|
|
2851
|
-
* Creates a static handler for singleton controllers.
|
|
2852
|
-
*
|
|
2853
|
-
* Implementation varies by adapter type:
|
|
2854
|
-
* - Endpoint: Invoke method(args), serialize response as JSON
|
|
2855
|
-
* - Stream: Invoke method(args, streamContext), return Response/use reply
|
|
2856
|
-
*
|
|
2857
|
-
* @param boundMethod - Pre-bound controller method
|
|
2858
|
-
* @param formatArguments - Function to format request arguments
|
|
2859
|
-
* @param context - Handler context with metadata
|
|
2860
|
-
* @returns Static handler result
|
|
2861
|
-
*/
|
|
2862
|
-
protected abstract createStaticHandler(boundMethod: (...args: any[]) => Promise<any>, formatArguments: FormatArgumentsFn<TRequest>, context: HandlerContext<TConfig>): AbstractStaticHandler<TRequest, TReply>;
|
|
2863
|
-
/**
|
|
2864
|
-
* Creates a dynamic handler for request-scoped controllers.
|
|
2865
|
-
*
|
|
2866
|
-
* Implementation varies by adapter type:
|
|
2867
|
-
* - Endpoint: Resolve controller per-request, invoke method(args)
|
|
2868
|
-
* - Stream: Resolve controller per-request, invoke method(args, streamContext)
|
|
2869
|
-
*
|
|
2870
|
-
* @param resolution - Instance resolution with resolve function
|
|
2871
|
-
* @param formatArguments - Function to format request arguments
|
|
2872
|
-
* @param context - Handler context with metadata
|
|
2873
|
-
* @returns Dynamic handler result
|
|
2874
|
-
*/
|
|
2875
|
-
protected abstract createDynamicHandler(resolution: InstanceResolution, formatArguments: FormatArgumentsFn<TRequest>, context: HandlerContext<TConfig>): AbstractDynamicHandler<TRequest, TReply>;
|
|
2876
|
-
/**
|
|
2877
|
-
* Prepares argument getters for parsing request data.
|
|
2878
|
-
*
|
|
2879
|
-
* Public alias for createArgumentGetters to satisfy interface contracts.
|
|
2880
|
-
* Subclasses should override createArgumentGetters instead.
|
|
2881
|
-
*
|
|
2882
|
-
* @param handlerMetadata - Handler metadata with schemas and configuration
|
|
2883
|
-
* @returns Array of getter functions
|
|
2884
|
-
*/
|
|
2885
|
-
prepareArguments(handlerMetadata: HandlerMetadata<TConfig>): ArgumentGetter<TRequest>[];
|
|
2886
|
-
/**
|
|
2887
|
-
* Checks if the handler has any validation schemas defined.
|
|
2888
|
-
*
|
|
2889
|
-
* Override in subclasses to add additional schema checks
|
|
2890
|
-
* (e.g., response schema validation for endpoint adapters).
|
|
2891
|
-
*
|
|
2892
|
-
* @param handlerMetadata - Handler metadata with configuration
|
|
2893
|
-
* @returns true if handler has schemas
|
|
2894
|
-
*/
|
|
2895
|
-
hasSchema(handlerMetadata: HandlerMetadata<TConfig>): boolean;
|
|
2896
|
-
/**
|
|
2897
|
-
* Provides schema information for the framework's validation system.
|
|
2898
|
-
*
|
|
2899
|
-
* Override in subclasses for frameworks that support schema registration
|
|
2900
|
-
* (e.g., Fastify). Default returns empty object (suitable for Bun).
|
|
2901
|
-
*
|
|
2902
|
-
* @param handlerMetadata - Handler metadata with configuration
|
|
2903
|
-
* @returns Schema object for framework registration
|
|
2904
|
-
*/
|
|
2905
|
-
provideSchema(_handlerMetadata: HandlerMetadata<TConfig>): Record<string, any>;
|
|
2906
|
-
/**
|
|
2907
|
-
* Creates a request handler function for the endpoint.
|
|
2908
|
-
*
|
|
2909
|
-
* This method orchestrates the entire handler creation:
|
|
2910
|
-
* 1. Prepares argument getters for request parsing
|
|
2911
|
-
* 2. Builds optimized formatArguments function (sync/async)
|
|
2912
|
-
* 3. Resolves the controller (singleton vs request-scoped)
|
|
2913
|
-
* 4. Creates appropriate handler (static or dynamic)
|
|
2914
|
-
*
|
|
2915
|
-
* @param controller - Controller class containing the handler method
|
|
2916
|
-
* @param handlerMetadata - Handler metadata with configuration
|
|
2917
|
-
* @returns Handler result (static or dynamic)
|
|
2918
|
-
*/
|
|
2919
|
-
provideHandler(controller: ClassType, handlerMetadata: HandlerMetadata<TConfig>): Promise<AbstractHandlerResult<TRequest, TReply>>;
|
|
2920
|
-
/**
|
|
2921
|
-
* Builds a formatArguments function from argument getters.
|
|
2922
|
-
*
|
|
2923
|
-
* Automatically detects sync vs async getters and optimizes accordingly:
|
|
2924
|
-
* - If all getters are sync: returns sync function (no Promise overhead)
|
|
2925
|
-
* - If any getter is async: returns async function with Promise.all
|
|
2926
|
-
* - If no getters: returns frozen empty object (zero allocation)
|
|
2927
|
-
*
|
|
2928
|
-
* This method is public to allow composition-based adapters (like XML adapter)
|
|
2929
|
-
* to reuse the optimized formatArguments logic without inheritance.
|
|
2930
|
-
*
|
|
2931
|
-
* @param getters - Array of argument getter functions
|
|
2932
|
-
* @returns Function to format arguments from request
|
|
2933
|
-
*/
|
|
2934
|
-
buildFormatArguments(getters: ArgumentGetter<TRequest>[]): FormatArgumentsFn<TRequest>;
|
|
2935
|
-
/**
|
|
2936
|
-
* Checks if the URL pattern contains URL parameters.
|
|
2937
|
-
*
|
|
2938
|
-
* @param config - Endpoint configuration
|
|
2939
|
-
* @returns true if URL contains '$' parameter markers
|
|
2940
|
-
*/
|
|
2941
|
-
protected hasUrlParams(config: TConfig): boolean;
|
|
2942
|
-
/**
|
|
2943
|
-
* Wraps handler execution with standardized error handling.
|
|
2944
|
-
*
|
|
2945
|
-
* Re-throws HttpExceptions as-is for framework error handlers.
|
|
2946
|
-
* Other errors are re-thrown for global error handling.
|
|
2947
|
-
*
|
|
2948
|
-
* @param fn - Handler function to wrap
|
|
2949
|
-
* @returns Wrapped function with error handling
|
|
2950
|
-
*/
|
|
2951
|
-
protected wrapWithErrorHandling<T extends (...args: any[]) => Promise<any>>(fn: T): T;
|
|
2952
|
-
}
|
|
2953
|
-
//#endregion
|
|
2954
|
-
//#region src/services/guard-runner.service.d.mts
|
|
2955
|
-
declare class GuardRunnerService {
|
|
2956
|
-
private readonly errorProducer;
|
|
2957
|
-
private readonly logger;
|
|
2958
|
-
/**
|
|
2959
|
-
* Runs guards that need to be resolved from a scoped container.
|
|
2960
|
-
* Use this when guards have request-scoped dependencies.
|
|
2961
|
-
*/
|
|
2962
|
-
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
2963
|
-
/**
|
|
2964
|
-
* Runs pre-resolved guard instances.
|
|
2965
|
-
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
2966
|
-
*/
|
|
2967
|
-
runGuardsStatic(guardInstances: CanActivate[], executionContext: AbstractExecutionContext): Promise<boolean>;
|
|
2968
|
-
/**
|
|
2969
|
-
* Shared guard execution logic.
|
|
2970
|
-
* Iterates through guard instances and calls canActivate on each.
|
|
2971
|
-
*/
|
|
2972
|
-
private executeGuards;
|
|
2973
|
-
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
2974
|
-
}
|
|
2975
|
-
//#endregion
|
|
2976
|
-
//#region src/stores/request-id.store.d.mts
|
|
2977
|
-
/**
|
|
2978
|
-
* Generates a simple incremental request ID.
|
|
2979
|
-
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
2980
|
-
*
|
|
2981
|
-
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
2982
|
-
*/
|
|
2983
|
-
declare function generateRequestId(): string;
|
|
2984
|
-
/**
|
|
2985
|
-
* Enables or disables request ID propagation.
|
|
2986
|
-
* Called by NaviosFactory based on the enableRequestId option.
|
|
2987
|
-
*
|
|
2988
|
-
* @param enabled - Whether to enable request ID propagation
|
|
2989
|
-
*/
|
|
2990
|
-
declare function setRequestIdEnabled(enabled: boolean): void;
|
|
2991
|
-
/**
|
|
2992
|
-
* Runs a function with a request ID in the async local storage context.
|
|
2993
|
-
* If request ID propagation is disabled, the function is called directly
|
|
2994
|
-
* without AsyncLocalStorage overhead.
|
|
2995
|
-
*
|
|
2996
|
-
* @param requestId - The request ID to set for this context
|
|
2997
|
-
* @param fn - The function to run within this context
|
|
2998
|
-
* @returns The return value of the function
|
|
2999
|
-
*/
|
|
3000
|
-
declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
3001
|
-
/**
|
|
3002
|
-
* Gets the current request ID from the async local storage context.
|
|
3003
|
-
*
|
|
3004
|
-
* @returns The current request ID, or undefined if not in a request context
|
|
3005
|
-
*/
|
|
3006
|
-
declare function getRequestId(): string | undefined;
|
|
3007
|
-
//#endregion
|
|
3008
|
-
//#region src/tokens/adapter.token.d.mts
|
|
3009
|
-
declare const AdapterToken: InjectionToken<AbstractAdapterInterface, undefined, false>;
|
|
3010
|
-
//#endregion
|
|
3011
|
-
//#region src/tokens/endpoint-adapter.token.d.mts
|
|
3012
|
-
declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3013
|
-
//#endregion
|
|
3014
|
-
//#region src/tokens/execution-context.token.d.mts
|
|
3015
|
-
declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
3016
|
-
declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
3017
|
-
//#endregion
|
|
3018
|
-
//#region src/tokens/http-adapter.token.d.mts
|
|
3019
|
-
declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<HttpAdapterEnvironment>, undefined, false>;
|
|
3020
|
-
//#endregion
|
|
3021
|
-
//#region src/tokens/multipart-adapter.token.d.mts
|
|
3022
|
-
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3023
|
-
//#endregion
|
|
3024
|
-
//#region src/tokens/navios-options.token.d.mts
|
|
3025
|
-
declare const NaviosOptionsToken: InjectionToken<NaviosApplicationOptions, undefined, false>;
|
|
3026
|
-
//#endregion
|
|
3027
|
-
//#region src/tokens/reply.token.d.mts
|
|
3028
|
-
declare const Reply: InjectionToken<any, undefined, false>;
|
|
3029
|
-
//#endregion
|
|
3030
|
-
//#region src/tokens/request.token.d.mts
|
|
3031
|
-
declare const Request: InjectionToken<any, undefined, false>;
|
|
3032
|
-
//#endregion
|
|
3033
|
-
//#region src/tokens/stream-adapter.token.d.mts
|
|
3034
|
-
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3035
|
-
//#endregion
|
|
3036
|
-
//#region src/tokens/xml-stream-adapter.token.d.mts
|
|
3037
|
-
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface<any>, undefined, false>;
|
|
3038
|
-
//#endregion
|
|
3039
|
-
//#region src/utils/adapter-supports.util.d.mts
|
|
3040
|
-
/**
|
|
3041
|
-
* Type guard to check if adapter implements a specific method.
|
|
3042
|
-
* Narrows the adapter type to include the method.
|
|
3043
|
-
*
|
|
3044
|
-
* @example
|
|
3045
|
-
* ```typescript
|
|
3046
|
-
* if (adapterSupports(adapter, 'getServer')) {
|
|
3047
|
-
* const server = adapter.getServer() // TypeScript knows this exists
|
|
3048
|
-
* }
|
|
3049
|
-
* ```
|
|
3050
|
-
*/
|
|
3051
|
-
declare function adapterSupports<TAdapter extends AbstractAdapterInterface, TMethod extends string>(adapter: TAdapter | null, method: TMethod): adapter is TAdapter & Record<TMethod, (...args: unknown[]) => unknown>;
|
|
3052
|
-
/**
|
|
3053
|
-
* Asserts adapter supports a method, throws if not.
|
|
3054
|
-
* Narrows type after assertion.
|
|
3055
|
-
*
|
|
3056
|
-
* @example
|
|
3057
|
-
* ```typescript
|
|
3058
|
-
* assertAdapterSupports(adapter, 'enableCors')
|
|
3059
|
-
* adapter.enableCors(options) // TypeScript knows this exists
|
|
3060
|
-
* ```
|
|
3061
|
-
*/
|
|
3062
|
-
declare function assertAdapterSupports<TAdapter extends AbstractAdapterInterface, TMethod extends string>(adapter: TAdapter | null, method: TMethod): asserts adapter is TAdapter & Record<TMethod, (...args: unknown[]) => unknown>;
|
|
3063
|
-
//#endregion
|
|
3064
|
-
//#region src/attribute.factory.d.mts
|
|
3065
|
-
/**
|
|
3066
|
-
* Type for a class attribute decorator without a value.
|
|
3067
|
-
*
|
|
3068
|
-
* Attributes are custom metadata decorators that can be applied to modules,
|
|
3069
|
-
* controllers, and endpoints.
|
|
3070
|
-
*/
|
|
3071
|
-
type ClassAttribute = (() => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
|
|
3072
|
-
token: symbol;
|
|
3073
|
-
};
|
|
3074
|
-
/**
|
|
3075
|
-
* Type for a class attribute decorator with a validated value.
|
|
3076
|
-
*
|
|
3077
|
-
* @typeParam T - The Zod schema type for validation
|
|
3078
|
-
*/
|
|
3079
|
-
type ClassSchemaAttribute<T extends ZodType> = ((value: z$1.input<T>) => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
|
|
3080
|
-
token: symbol;
|
|
3081
|
-
schema: ZodType;
|
|
3082
|
-
};
|
|
3083
|
-
/**
|
|
3084
|
-
* Factory for creating custom attribute decorators.
|
|
3085
|
-
*
|
|
3086
|
-
* Attributes allow you to add custom metadata to modules, controllers, and endpoints.
|
|
3087
|
-
* This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
|
|
3088
|
-
*
|
|
3089
|
-
* @example
|
|
3090
|
-
* ```typescript
|
|
3091
|
-
* // Create a simple boolean attribute
|
|
3092
|
-
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
3093
|
-
*
|
|
3094
|
-
* // Use it as a decorator
|
|
3095
|
-
* @Controller()
|
|
3096
|
-
* @Public()
|
|
3097
|
-
* export class PublicController { }
|
|
3098
|
-
*
|
|
3099
|
-
* // Check if attribute exists
|
|
3100
|
-
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
3101
|
-
* // Skip authentication
|
|
3102
|
-
* }
|
|
3103
|
-
* ```
|
|
3104
|
-
*
|
|
3105
|
-
* @example
|
|
3106
|
-
* ```typescript
|
|
3107
|
-
* // Create an attribute with a validated value
|
|
3108
|
-
* const RateLimit = AttributeFactory.createAttribute(
|
|
3109
|
-
* Symbol.for('RateLimit'),
|
|
3110
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
3111
|
-
* )
|
|
3112
|
-
*
|
|
3113
|
-
* // Use it with a value
|
|
3114
|
-
* @Endpoint(apiEndpoint)
|
|
3115
|
-
* @RateLimit({ requests: 100, window: 60000 })
|
|
3116
|
-
* async handler() { }
|
|
3117
|
-
*
|
|
3118
|
-
* // Get the value
|
|
3119
|
-
* const limit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
3120
|
-
* // limit is typed as { requests: number, window: number } | null
|
|
3121
|
-
* ```
|
|
3122
|
-
*/
|
|
3123
|
-
declare class AttributeFactory {
|
|
3124
|
-
/**
|
|
3125
|
-
* Creates a simple attribute decorator without a value.
|
|
3126
|
-
*
|
|
3127
|
-
* @param token - A unique symbol to identify this attribute
|
|
3128
|
-
* @returns A decorator function that can be applied to classes or methods
|
|
3129
|
-
*
|
|
3130
|
-
* @example
|
|
3131
|
-
* ```typescript
|
|
3132
|
-
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
3133
|
-
*
|
|
3134
|
-
* @Public()
|
|
3135
|
-
* @Controller()
|
|
3136
|
-
* export class PublicController { }
|
|
3137
|
-
* ```
|
|
3138
|
-
*/
|
|
3139
|
-
static createAttribute(token: symbol): ClassAttribute;
|
|
3140
|
-
/**
|
|
3141
|
-
* Creates an attribute decorator with a validated value.
|
|
3142
|
-
*
|
|
3143
|
-
* @param token - A unique symbol to identify this attribute
|
|
3144
|
-
* @param schema - A Zod schema to validate the attribute value
|
|
3145
|
-
* @returns A decorator function that accepts a value and can be applied to classes or methods
|
|
3146
|
-
*
|
|
3147
|
-
* @example
|
|
3148
|
-
* ```typescript
|
|
3149
|
-
* const RateLimit = AttributeFactory.createAttribute(
|
|
3150
|
-
* Symbol.for('RateLimit'),
|
|
3151
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
3152
|
-
* )
|
|
3153
|
-
*
|
|
3154
|
-
* @RateLimit({ requests: 100, window: 60000 })
|
|
3155
|
-
* @Endpoint(apiEndpoint)
|
|
3156
|
-
* async handler() { }
|
|
3157
|
-
* ```
|
|
3158
|
-
*/
|
|
3159
|
-
static createAttribute<T extends ZodType>(token: symbol, schema: T): ClassSchemaAttribute<T>;
|
|
3160
|
-
/**
|
|
3161
|
-
* Gets the value of an attribute from metadata.
|
|
3162
|
-
*
|
|
3163
|
-
* Returns `null` if the attribute is not present.
|
|
3164
|
-
* For simple attributes (without values), returns `true` if present.
|
|
3165
|
-
*
|
|
3166
|
-
* @param attribute - The attribute decorator
|
|
3167
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
3168
|
-
* @returns The attribute value, `true` for simple attributes, or `null` if not found
|
|
3169
|
-
*
|
|
3170
|
-
* @example
|
|
3171
|
-
* ```typescript
|
|
3172
|
-
* const isPublic = AttributeFactory.get(Public, controllerMetadata)
|
|
3173
|
-
* // isPublic is true | null
|
|
3174
|
-
*
|
|
3175
|
-
* const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
3176
|
-
* // rateLimit is { requests: number, window: number } | null
|
|
3177
|
-
* ```
|
|
3178
|
-
*/
|
|
3179
|
-
static get(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): true | null;
|
|
3180
|
-
static get<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): z$1.output<T> | null;
|
|
3181
|
-
/**
|
|
3182
|
-
* Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
|
|
3183
|
-
*
|
|
3184
|
-
* Returns `null` if the attribute is not present.
|
|
3185
|
-
*
|
|
3186
|
-
* @param attribute - The attribute decorator
|
|
3187
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
3188
|
-
* @returns An array of attribute values, or `null` if not found
|
|
3189
|
-
*
|
|
3190
|
-
* @example
|
|
3191
|
-
* ```typescript
|
|
3192
|
-
* const tags = AttributeFactory.getAll(Tag, endpointMetadata)
|
|
3193
|
-
* // tags is string[] | null
|
|
3194
|
-
* ```
|
|
3195
|
-
*/
|
|
3196
|
-
static getAll(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<true> | null;
|
|
3197
|
-
static getAll<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<z$1.output<T>> | null;
|
|
3198
|
-
/**
|
|
3199
|
-
* Gets the last value of an attribute from an array of metadata objects.
|
|
3200
|
-
*
|
|
3201
|
-
* Searches from the end of the array backwards, useful for finding the most
|
|
3202
|
-
* specific attribute value (e.g., endpoint-level overrides module-level).
|
|
3203
|
-
*
|
|
3204
|
-
* @param attribute - The attribute decorator
|
|
3205
|
-
* @param target - An array of metadata objects (typically [module, controller, handler])
|
|
3206
|
-
* @returns The last attribute value found, or `null` if not found
|
|
3207
|
-
*
|
|
3208
|
-
* @example
|
|
3209
|
-
* ```typescript
|
|
3210
|
-
* // Check attribute hierarchy: endpoint -> controller -> module
|
|
3211
|
-
* const rateLimit = AttributeFactory.getLast(RateLimit, [
|
|
3212
|
-
* moduleMetadata,
|
|
3213
|
-
* controllerMetadata,
|
|
3214
|
-
* endpointMetadata
|
|
3215
|
-
* ])
|
|
3216
|
-
* ```
|
|
3217
|
-
*/
|
|
3218
|
-
static getLast(attribute: ClassAttribute, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): true | null;
|
|
3219
|
-
static getLast<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): z$1.output<T> | null;
|
|
3220
|
-
/**
|
|
3221
|
-
* Checks if an attribute is present on the metadata object.
|
|
3222
|
-
*
|
|
3223
|
-
* @param attribute - The attribute decorator
|
|
3224
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
3225
|
-
* @returns `true` if the attribute is present, `false` otherwise
|
|
3226
|
-
*
|
|
3227
|
-
* @example
|
|
3228
|
-
* ```typescript
|
|
3229
|
-
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
3230
|
-
* // Skip authentication
|
|
3231
|
-
* }
|
|
3232
|
-
* ```
|
|
3233
|
-
*/
|
|
3234
|
-
static has(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
3235
|
-
static has<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
3236
|
-
}
|
|
3237
|
-
//#endregion
|
|
3238
|
-
//#region src/factories/adapter.factory.d.mts
|
|
3239
|
-
declare class AdapterFactory {
|
|
3240
|
-
private readonly environment;
|
|
3241
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3242
|
-
}
|
|
3243
|
-
//#endregion
|
|
3244
|
-
//#region src/factories/endpoint-adapter.factory.d.mts
|
|
3245
|
-
declare class EndpointAdapterFactory {
|
|
3246
|
-
private readonly environment;
|
|
3247
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3248
|
-
}
|
|
3249
|
-
//#endregion
|
|
3250
|
-
//#region src/factories/http-adapter.factory.d.mts
|
|
3251
|
-
declare class HttpAdapterFactory {
|
|
3252
|
-
private readonly environment;
|
|
3253
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3254
|
-
}
|
|
3255
|
-
//#endregion
|
|
3256
|
-
//#region src/factories/multipart-adapter.factory.d.mts
|
|
3257
|
-
declare class MultipartAdapterFactory {
|
|
3258
|
-
private readonly environment;
|
|
3259
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3260
|
-
}
|
|
3261
|
-
//#endregion
|
|
3262
|
-
//#region src/factories/request.factory.d.mts
|
|
3263
|
-
declare class RequestFactory {
|
|
3264
|
-
private readonly environment;
|
|
3265
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3266
|
-
}
|
|
3267
|
-
//#endregion
|
|
3268
|
-
//#region src/factories/reply.factory.d.mts
|
|
3269
|
-
declare class ReplyFactory {
|
|
3270
|
-
private readonly environment;
|
|
3271
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3272
|
-
}
|
|
3273
|
-
//#endregion
|
|
3274
|
-
//#region src/factories/stream-adapter.factory.d.mts
|
|
3275
|
-
declare class StreamAdapterFactory {
|
|
3276
|
-
private readonly environment;
|
|
3277
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3278
|
-
}
|
|
3279
|
-
//#endregion
|
|
3280
|
-
//#region src/factories/xml-stream-adapter.factory.d.mts
|
|
3281
|
-
declare class XmlStreamAdapterFactory {
|
|
3282
|
-
private readonly environment;
|
|
3283
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
3284
|
-
}
|
|
3285
|
-
//#endregion
|
|
3286
|
-
//#region src/navios.factory.d.mts
|
|
3287
|
-
/**
|
|
3288
|
-
* Factory class for creating and configuring Navios applications.
|
|
3289
|
-
*
|
|
3290
|
-
* This is the main entry point for bootstrapping a Navios application.
|
|
3291
|
-
* It handles dependency injection container setup, adapter registration,
|
|
3292
|
-
* and logger configuration.
|
|
3293
|
-
*
|
|
3294
|
-
* @example
|
|
3295
|
-
* ```typescript
|
|
3296
|
-
* import { NaviosFactory } from '@navios/core'
|
|
3297
|
-
* import { defineFastifyEnvironment } from '@navios/adapter-fastify'
|
|
3298
|
-
*
|
|
3299
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
3300
|
-
* adapter: defineFastifyEnvironment(),
|
|
3301
|
-
* logger: ['log', 'error', 'warn'],
|
|
3302
|
-
* })
|
|
3303
|
-
*
|
|
3304
|
-
* await app.init()
|
|
3305
|
-
* await app.listen({ port: 3000 })
|
|
3306
|
-
* ```
|
|
3307
|
-
*/
|
|
3308
|
-
declare class NaviosFactory {
|
|
3309
|
-
/**
|
|
3310
|
-
* Creates a new Navios application instance.
|
|
3311
|
-
*
|
|
3312
|
-
* This method sets up the dependency injection container, registers the adapter,
|
|
3313
|
-
* configures logging, and initializes the application with the provided module.
|
|
3314
|
-
*
|
|
3315
|
-
* @typeParam Environment - Adapter environment interface for type-safe access
|
|
3316
|
-
* to adapter-specific features. When specified, methods like `getServer()`,
|
|
3317
|
-
* `enableCors()`, `listen()`, and `configure()` will have proper types.
|
|
3318
|
-
*
|
|
3319
|
-
* @param appModule - The root application module class decorated with @Module()
|
|
3320
|
-
* @param options - Configuration options for the application
|
|
3321
|
-
* @param options.adapter - Adapter environment (required for server functionality)
|
|
3322
|
-
* @param options.logger - Logger configuration. Can be:
|
|
3323
|
-
* - A LoggerService instance for custom logging
|
|
3324
|
-
* - An array of LogLevel strings to enable specific log levels
|
|
3325
|
-
* - `false` to disable logging
|
|
3326
|
-
* @param options.container - Optional custom dependency injection container (useful for testing)
|
|
3327
|
-
* @returns A configured NaviosApplication instance ready to be initialized
|
|
3328
|
-
*
|
|
3329
|
-
* @example
|
|
3330
|
-
* ```typescript
|
|
3331
|
-
* // Basic setup with Fastify adapter
|
|
3332
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
3333
|
-
* adapter: defineFastifyEnvironment(),
|
|
3334
|
-
* })
|
|
3335
|
-
*
|
|
3336
|
-
* // Type-safe setup with Fastify environment
|
|
3337
|
-
* import { FastifyEnvironment } from '@navios/adapter-fastify'
|
|
3338
|
-
*
|
|
3339
|
-
* const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
|
|
3340
|
-
* adapter: defineFastifyEnvironment(),
|
|
3341
|
-
* })
|
|
3342
|
-
* app.configure({ trustProxy: true })
|
|
3343
|
-
* const server = app.getServer() // FastifyInstance
|
|
3344
|
-
*
|
|
3345
|
-
* // With custom logger configuration
|
|
3346
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
3347
|
-
* adapter: defineFastifyEnvironment(),
|
|
3348
|
-
* logger: ['error', 'warn', 'log'],
|
|
3349
|
-
* })
|
|
3350
|
-
*
|
|
3351
|
-
* // With custom container for testing
|
|
3352
|
-
* const container = new Container()
|
|
3353
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
3354
|
-
* adapter: defineFastifyEnvironment(),
|
|
3355
|
-
* container,
|
|
3356
|
-
* })
|
|
3357
|
-
* ```
|
|
3358
|
-
*/
|
|
3359
|
-
static create<Environment extends AdapterEnvironment = DefaultAdapterEnvironment>(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<NaviosApplication<Environment>>;
|
|
3360
|
-
private static registerEnvironment;
|
|
3361
|
-
private static registerLoggerConfiguration;
|
|
3362
|
-
}
|
|
3363
|
-
//#endregion
|
|
3364
|
-
export { ProblemDetails as $, isUndefined as $t, GuardRunnerService as A, EndpointMetadataKey as An, DynamicHandler as At, NaviosApplication as B, EnvConfigProvider as Bn, ConsoleLogger as Bt, ExecutionContextInjectionToken as C, getModuleMetadata as Cn, NaviosModule as Ct, getRequestId as D, extractControllerMetadata as Dn, AbstractHttpListenOptions as Dt, generateRequestId as E, ControllerMetadataKey as En, CanActivate as Et, ArgumentGetter as F, EndpointParams as Fn, Logger as Ft, ValidationErrorResponderToken as G, ConfigServiceToken as Gn, isEmpty as Gt, ForbiddenResponderToken as H, ConfigService as Hn, LoggerService as Ht, HandlerContext as I, EndpointResult as In, LoggerOptions as It, InternalServerErrorResponderService as J, PathImpl as Jn, isNumber as Jt, ValidationErrorResponderService as K, ConfigServiceInterface as Kn, isFunction as Kt, InstanceResolution as L, Controller as Ln, LoggerOutput as Lt, AbstractHandlerAdapterService as M, getAllEndpointMetadata as Mn, HandlerResult as Mt, AbstractHandlerResult as N, getEndpointMetadata as Nn, StaticHandler as Nt, runWithRequestId as O, getControllerMetadata as On, AbstractHttpHandlerAdapterInterface as Ot, AbstractStaticHandler as P, Endpoint as Pn, AbstractHttpCorsOptions as Pt, ErrorResponse as Q, envString as Qn, isSymbol as Qt, InstanceResolverService as R, ControllerOptions as Rn, loggerOptionsSchema as Rt, ExecutionContext as S, getModuleCustomEntry as Sn, ModuleLoaderService as St, AdapterToken as T, ControllerMetadata as Tn, OmitIndexSignature as Tt, InternalServerErrorResponderToken as U, ConfigServiceOptions as Un, addLeadingSlash as Ut, NaviosApplicationOptions as V, provideConfig as Vn, ConsoleLoggerOptions as Vt, NotFoundResponderToken as W, ConfigServiceOptionsSchema as Wn, isConstructor as Wt, ErrorResponseProducerService as X, PathValue as Xn, isPlainObject as Xt, ForbiddenResponderService as Y, PathImpl2 as Yn, isObject as Yt, ErrorResponder as Z, envInt as Zn, isString as Zt, Request as _, getManagedMetadata as _n, Header as _t, RequestFactory as a, LOG_LEVELS as an, ForbiddenException as at, MultipartAdapterToken as b, ModuleMetadataKey as bn, PluginDefinition as bt, EndpointAdapterFactory as c, yellow as cn, UseGuards as ct, ClassAttribute as d, DefaultAdapterEnvironment as dn, Multipart as dt, normalizePath as en, FrameworkError as et, ClassSchemaAttribute as f, HttpAdapterEnvironment as fn, MultipartParams as ft, StreamAdapterToken as g, NaviosManagedMetadataKey as gn, HttpCode as gt, XmlStreamAdapterToken as h, ManagedMetadata as hn, ModuleOptions as ht, ReplyFactory as i, filterLogLevels as in, InternalServerErrorException as it, AbstractDynamicHandler as j, HandlerMetadata as jn, FormatArgumentsFn$1 as jt, setRequestIdEnabled as k, hasControllerMetadata as kn, ArgumentGetterFn as kt, AdapterFactory as l, AbstractHttpAdapterInterface as ln, Stream as lt, assertAdapterSupports as m, AbstractAdapterInterface as mn, Module as mt, XmlStreamAdapterFactory as n, isLogLevelEnabled as nn, UnauthorizedException as nt, MultipartAdapterFactory as o, LogLevel as on, BadRequestException as ot, adapterSupports as p, AbstractExecutionContext as pn, MultipartResult as pt, NotFoundResponderService as q, Path as qn, isNil as qt, StreamAdapterFactory as r, isLogLevel as rn, NotFoundException as rt, HttpAdapterFactory as s, clc as sn, HttpException as st, NaviosFactory as t, stripEndSlash as tn, ConflictException as tt, AttributeFactory as u, AdapterEnvironment as un, StreamParams as ut, Reply as v, hasManagedMetadata as vn, NaviosPlugin as vt, EndpointAdapterToken as w, hasModuleMetadata as wn, HttpHeader as wt, HttpAdapterToken as x, extractModuleMetadata as xn, ModuleExtension as xt, NaviosOptionsToken as y, ModuleMetadata as yn, PluginContext as yt, MultiInstanceResolution as z, ConfigProviderOptions as zn, LoggerInstance as zt };
|
|
3365
|
-
//# sourceMappingURL=index-DySQ6Dpd.d.mts.map
|