@navios/core 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +115 -0
- package/README.md +18 -1
- package/docs/README.md +1 -0
- package/docs/legacy-compat.md +320 -0
- package/docs/testing.md +140 -17
- package/lib/index-DW9EPAE6.d.mts +2156 -0
- package/lib/index-DW9EPAE6.d.mts.map +1 -0
- package/lib/index-pHp-dIGt.d.cts +2156 -0
- package/lib/index-pHp-dIGt.d.cts.map +1 -0
- package/lib/index.cjs +157 -0
- package/lib/index.d.cts +3 -0
- package/lib/index.d.mts +3 -190
- package/lib/index.mjs +4 -1459
- package/lib/legacy-compat/index.cjs +315 -0
- package/lib/legacy-compat/index.cjs.map +1 -0
- package/lib/legacy-compat/index.d.cts +219 -0
- package/lib/legacy-compat/index.d.cts.map +1 -0
- package/lib/legacy-compat/index.d.mts +219 -0
- package/lib/legacy-compat/index.d.mts.map +1 -0
- package/lib/legacy-compat/index.mjs +308 -0
- package/lib/legacy-compat/index.mjs.map +1 -0
- package/lib/src-DyvCDuKO.mjs +5443 -0
- package/lib/src-DyvCDuKO.mjs.map +1 -0
- package/lib/src-QnxR5b7c.cjs +5800 -0
- package/lib/src-QnxR5b7c.cjs.map +1 -0
- package/lib/testing/index.cjs +106 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +156 -0
- package/lib/testing/index.d.cts.map +1 -0
- package/lib/testing/index.d.mts +156 -0
- package/lib/testing/index.d.mts.map +1 -0
- package/lib/testing/index.mjs +100 -0
- package/lib/testing/index.mjs.map +1 -0
- package/lib/use-guards.decorator-B6q_N0sf.cjs +622 -0
- package/lib/use-guards.decorator-B6q_N0sf.cjs.map +1 -0
- package/lib/use-guards.decorator-kZ3lNK8v.mjs +454 -0
- package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +1 -0
- package/package.json +28 -8
- package/project.json +2 -2
- package/src/attribute.factory.mts +154 -0
- package/src/config/config-service.interface.mts +31 -0
- package/src/config/config.provider.mts +36 -0
- package/src/config/config.service.mts +94 -4
- package/src/decorators/controller.decorator.mts +28 -0
- package/src/decorators/endpoint.decorator.mts +76 -0
- package/src/decorators/header.decorator.mts +19 -0
- package/src/decorators/http-code.decorator.mts +20 -0
- package/src/decorators/module.decorator.mts +34 -0
- package/src/decorators/multipart.decorator.mts +41 -0
- package/src/decorators/stream.decorator.mts +33 -0
- package/src/decorators/use-guards.decorator.mts +29 -0
- package/src/exceptions/bad-request.exception.mts +21 -0
- package/src/exceptions/conflict.exception.mts +24 -0
- package/src/exceptions/forbidden.exception.mts +23 -0
- package/src/exceptions/http.exception.mts +26 -0
- package/src/exceptions/internal-server-error.exception.mts +26 -0
- package/src/exceptions/not-found.exception.mts +23 -0
- package/src/exceptions/unauthorized.exception.mts +23 -0
- package/src/index.mts +1 -0
- package/src/interfaces/abstract-execution-context.inteface.mts +35 -0
- package/src/interfaces/abstract-http-adapter.interface.mts +52 -0
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +2 -2
- package/src/interfaces/can-activate.mts +31 -0
- package/src/interfaces/index.mts +1 -0
- package/src/interfaces/navios-module.mts +25 -0
- package/src/interfaces/plugin.interface.mts +105 -0
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +420 -0
- package/src/legacy-compat/__type-tests__/tsconfig.json +15 -0
- package/src/legacy-compat/context-compat.mts +93 -0
- package/src/legacy-compat/decorators/controller.decorator.mts +31 -0
- package/src/legacy-compat/decorators/endpoint.decorator.mts +99 -0
- package/src/legacy-compat/decorators/header.decorator.mts +42 -0
- package/src/legacy-compat/decorators/http-code.decorator.mts +38 -0
- package/src/legacy-compat/decorators/index.mts +9 -0
- package/src/legacy-compat/decorators/module.decorator.mts +37 -0
- package/src/legacy-compat/decorators/multipart.decorator.mts +93 -0
- package/src/legacy-compat/decorators/stream.decorator.mts +76 -0
- package/src/legacy-compat/decorators/use-guards.decorator.mts +80 -0
- package/src/legacy-compat/index.mts +40 -0
- package/src/logger/console-logger.service.mts +15 -2
- package/src/logger/log-levels.mts +9 -0
- package/src/logger/logger.service.mts +21 -0
- package/src/logger/logger.tokens.mts +23 -0
- package/src/navios.application.mts +228 -4
- package/src/navios.factory.mts +60 -1
- package/src/services/guard-runner.service.mts +12 -11
- package/src/services/module-loader.service.mts +118 -12
- package/src/stores/index.mts +1 -0
- package/src/stores/request-id.store.mts +43 -0
- package/src/testing/index.mts +2 -0
- package/src/testing/testing-module.mts +231 -0
- package/tsconfig.lib.json +1 -1
- package/tsconfig.spec.json +3 -0
- package/tsdown.config.mts +35 -0
- package/vitest.config.mts +6 -0
- package/lib/_tsup-dts-rollup.d.mts +0 -1365
- package/lib/_tsup-dts-rollup.d.ts +0 -1365
- package/lib/index.d.ts +0 -190
- package/lib/index.js +0 -1540
- package/lib/index.js.map +0 -1
- package/lib/index.mjs.map +0 -1
- package/tsup.config.mts +0 -13
|
@@ -0,0 +1,2156 @@
|
|
|
1
|
+
import * as _navios_di0 from "@navios/di";
|
|
2
|
+
import { AnyInjectableType, ClassType, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectionToken, ScopedContainer } from "@navios/di";
|
|
3
|
+
import z, { ZodDiscriminatedUnion, ZodObject, ZodType, z as z$1 } from "zod/v4";
|
|
4
|
+
import { BaseEndpointConfig, BaseStreamConfig, EndpointFunctionArgs, HttpMethod, Util_FlatObject } from "@navios/builder";
|
|
5
|
+
import { InspectOptions } from "util";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import { OutgoingHttpHeaders } from "http";
|
|
8
|
+
|
|
9
|
+
//#region src/config/utils/helpers.d.mts
|
|
10
|
+
declare function envInt(key: keyof NodeJS.ProcessEnv, defaultValue: number): number;
|
|
11
|
+
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;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/config/types.d.mts
|
|
14
|
+
/**
|
|
15
|
+
* Evaluates to `true` if `T` is `any`. `false` otherwise.
|
|
16
|
+
* (c) https://stackoverflow.com/a/68633327/5290447
|
|
17
|
+
*/
|
|
18
|
+
type IsAny<T> = unknown extends T ? [keyof T] extends [never] ? false : true : false;
|
|
19
|
+
type ExcludedParts = 'services' | 'mailer' | 'aws' | 'computedTimeRates' | 'aiModelsRates';
|
|
20
|
+
type ExcludedKeys = 'computedTimeRates' | 'aiModelsRates' | 'aiModel';
|
|
21
|
+
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;
|
|
22
|
+
type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
|
|
23
|
+
type Path<T> = keyof T extends string ? PathImpl2<T> extends infer P ? P extends string | keyof T ? P : keyof T : keyof T : never;
|
|
24
|
+
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;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/config/config-service.interface.d.mts
|
|
27
|
+
/**
|
|
28
|
+
* Interface for configuration service implementations.
|
|
29
|
+
*
|
|
30
|
+
* Provides type-safe access to configuration values with support for nested paths.
|
|
31
|
+
*
|
|
32
|
+
* @typeParam Config - The configuration object type
|
|
33
|
+
*/
|
|
34
|
+
interface ConfigServiceInterface<Config = Record<string, unknown>> {
|
|
35
|
+
/**
|
|
36
|
+
* Gets the entire configuration object.
|
|
37
|
+
*/
|
|
38
|
+
getConfig: () => Config;
|
|
39
|
+
/**
|
|
40
|
+
* Gets a configuration value by key path. Returns `null` if not found.
|
|
41
|
+
*
|
|
42
|
+
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
43
|
+
* @returns The configuration value or `null` if not found
|
|
44
|
+
*/
|
|
45
|
+
get: <Key$1 extends Path<Config>>(key: Key$1) => PathValue<Config, Key$1> | null;
|
|
46
|
+
/**
|
|
47
|
+
* Gets a configuration value by key path, or returns a default value if not found.
|
|
48
|
+
*
|
|
49
|
+
* @param key - Dot-separated path to the configuration value
|
|
50
|
+
* @param defaultValue - Default value to return if the key is not found
|
|
51
|
+
* @returns The configuration value or the default value
|
|
52
|
+
*/
|
|
53
|
+
getOrDefault: <Key$1 extends Path<Config>>(key: Key$1, defaultValue: PathValue<Config, Key$1>) => PathValue<Config, Key$1>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets a configuration value by key path, or throws an error if not found.
|
|
56
|
+
*
|
|
57
|
+
* @param key - Dot-separated path to the configuration value
|
|
58
|
+
* @param errorMessage - Optional custom error message
|
|
59
|
+
* @returns The configuration value
|
|
60
|
+
* @throws Error if the key is not found
|
|
61
|
+
*/
|
|
62
|
+
getOrThrow: <Key$1 extends Path<Config>>(key: Key$1, errorMessage?: string) => PathValue<Config, Key$1>;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/config/config.service.d.mts
|
|
66
|
+
/**
|
|
67
|
+
* Schema for validating configuration service options.
|
|
68
|
+
*/
|
|
69
|
+
declare const ConfigServiceOptionsSchema: z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>;
|
|
70
|
+
/**
|
|
71
|
+
* Type for configuration service options.
|
|
72
|
+
*/
|
|
73
|
+
type ConfigServiceOptions = z$1.infer<typeof ConfigServiceOptionsSchema>;
|
|
74
|
+
/**
|
|
75
|
+
* Injection token for ConfigService.
|
|
76
|
+
*/
|
|
77
|
+
declare const ConfigServiceToken: InjectionToken<ConfigServiceInterface<Record<string, unknown>>, z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>, true>;
|
|
78
|
+
/**
|
|
79
|
+
* Service for managing application configuration with type-safe access.
|
|
80
|
+
*
|
|
81
|
+
* Provides methods to access configuration values using dot-notation paths
|
|
82
|
+
* with full TypeScript type inference.
|
|
83
|
+
*
|
|
84
|
+
* @typeParam Config - The configuration object type
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* interface AppConfig {
|
|
89
|
+
* database: {
|
|
90
|
+
* host: string
|
|
91
|
+
* port: number
|
|
92
|
+
* }
|
|
93
|
+
* api: {
|
|
94
|
+
* timeout: number
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* @Injectable()
|
|
99
|
+
* export class DatabaseService {
|
|
100
|
+
* private config = inject(MyConfigService)
|
|
101
|
+
*
|
|
102
|
+
* connect() {
|
|
103
|
+
* const host = this.config.getOrThrow('database.host')
|
|
104
|
+
* const port = this.config.getOrDefault('database.port', 5432)
|
|
105
|
+
* // host is typed as string, port is typed as number
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare class ConfigService<Config extends ConfigServiceOptions = Record<string, unknown>> implements ConfigServiceInterface<Config> {
|
|
111
|
+
private config;
|
|
112
|
+
private readonly logger;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new ConfigService instance.
|
|
115
|
+
*
|
|
116
|
+
* @param config - The configuration object
|
|
117
|
+
*/
|
|
118
|
+
constructor(config?: Config);
|
|
119
|
+
/**
|
|
120
|
+
* Gets the entire configuration object.
|
|
121
|
+
*
|
|
122
|
+
* @returns The complete configuration object
|
|
123
|
+
*/
|
|
124
|
+
getConfig(): Config;
|
|
125
|
+
/**
|
|
126
|
+
* Gets a configuration value by key path.
|
|
127
|
+
*
|
|
128
|
+
* Returns `null` if the key is not found or if any part of the path is invalid.
|
|
129
|
+
*
|
|
130
|
+
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
131
|
+
* @returns The configuration value or `null` if not found
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const host = config.get('database.host') // string | null
|
|
136
|
+
* const port = config.get('database.port') // number | null
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
get<Key$1 extends Path<Config>>(key: Key$1): PathValue<Config, Key$1> | null;
|
|
140
|
+
/**
|
|
141
|
+
* Gets a configuration value by key path, or returns a default value if not found.
|
|
142
|
+
*
|
|
143
|
+
* @param key - Dot-separated path to the configuration value
|
|
144
|
+
* @param defaultValue - Default value to return if the key is not found
|
|
145
|
+
* @returns The configuration value or the default value
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const port = config.getOrDefault('database.port', 5432) // number
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
getOrDefault<Key$1 extends Path<Config>>(key: Key$1, defaultValue: PathValue<Config, Key$1>): PathValue<Config, Key$1>;
|
|
153
|
+
/**
|
|
154
|
+
* Gets a configuration value by key path, or throws an error if not found.
|
|
155
|
+
*
|
|
156
|
+
* @param key - Dot-separated path to the configuration value
|
|
157
|
+
* @param errorMessage - Optional custom error message
|
|
158
|
+
* @returns The configuration value
|
|
159
|
+
* @throws Error if the key is not found
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const host = config.getOrThrow('database.host') // string (throws if not found)
|
|
164
|
+
* const apiKey = config.getOrThrow('api.key', 'API key is required') // string
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
getOrThrow<Key$1 extends Path<Config>>(key: Key$1, errorMessage?: string): PathValue<Config, Key$1>;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/config/config.provider.d.mts
|
|
171
|
+
/**
|
|
172
|
+
* Schema for configuration provider options.
|
|
173
|
+
*/
|
|
174
|
+
declare const ConfigProviderOptions: z$1.ZodObject<{
|
|
175
|
+
load: z$1.ZodFunction<z$1.core.$ZodFunctionArgs, z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
176
|
+
}, z$1.core.$strip>;
|
|
177
|
+
/**
|
|
178
|
+
* Creates a factory injection token for ConfigService that loads configuration asynchronously.
|
|
179
|
+
*
|
|
180
|
+
* Use this when you need to load configuration from a file, database, or other async source.
|
|
181
|
+
*
|
|
182
|
+
* @param options - Configuration provider options
|
|
183
|
+
* @param options.load - Async function that loads and returns the configuration object
|
|
184
|
+
* @returns A factory injection token for ConfigService
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const MyConfigService = provideConfig({
|
|
189
|
+
* load: async () => {
|
|
190
|
+
* const config = await loadConfigFromFile('config.json')
|
|
191
|
+
* return config
|
|
192
|
+
* },
|
|
193
|
+
* })
|
|
194
|
+
*
|
|
195
|
+
* // Use in module setup
|
|
196
|
+
* container.bind(ConfigServiceToken).toFactory(configProvider)
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function provideConfig<ConfigMap extends ConfigServiceOptions>(options: z$1.input<typeof ConfigProviderOptions>): FactoryInjectionToken<ConfigService<ConfigMap>, typeof ConfigServiceOptionsSchema>;
|
|
200
|
+
/**
|
|
201
|
+
* Pre-configured ConfigService provider that uses environment variables.
|
|
202
|
+
*
|
|
203
|
+
* Provides a ConfigService instance bound to `process.env`.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Use environment variables as configuration
|
|
208
|
+
* container.bind(ConfigServiceToken).toValue(EnvConfigProvider)
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare const EnvConfigProvider: _navios_di0.BoundInjectionToken<ConfigService<Record<string, string>>, z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/decorators/controller.decorator.d.mts
|
|
214
|
+
/**
|
|
215
|
+
* Options for configuring a Navios controller.
|
|
216
|
+
*/
|
|
217
|
+
interface ControllerOptions {
|
|
218
|
+
/**
|
|
219
|
+
* Guards to apply to all endpoints in this controller.
|
|
220
|
+
* Guards are executed in reverse order (last guard first).
|
|
221
|
+
*/
|
|
222
|
+
guards?: ClassType[] | Set<ClassType>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Decorator that marks a class as a Navios controller.
|
|
226
|
+
*
|
|
227
|
+
* Controllers handle HTTP requests and define endpoints.
|
|
228
|
+
* They are request-scoped by default, meaning a new instance is created for each request.
|
|
229
|
+
*
|
|
230
|
+
* @param options - Controller configuration options
|
|
231
|
+
* @returns A class decorator
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* @Controller({ guards: [AuthGuard] })
|
|
236
|
+
* export class UserController {
|
|
237
|
+
* @Endpoint(getUserEndpoint)
|
|
238
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
239
|
+
* // Handle request
|
|
240
|
+
* }
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
declare function Controller({
|
|
245
|
+
guards
|
|
246
|
+
}?: ControllerOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/decorators/endpoint.decorator.d.mts
|
|
249
|
+
/**
|
|
250
|
+
* Extracts the typed parameters for an endpoint handler function.
|
|
251
|
+
*
|
|
252
|
+
* This utility type extracts URL parameters, query parameters, and request body
|
|
253
|
+
* from an endpoint declaration and flattens them into a single object.
|
|
254
|
+
*
|
|
255
|
+
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const getUserEndpoint = api.declareEndpoint({
|
|
260
|
+
* method: 'get',
|
|
261
|
+
* url: '/users/$userId',
|
|
262
|
+
* querySchema: z.object({ include: z.string().optional() }),
|
|
263
|
+
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
264
|
+
* })
|
|
265
|
+
*
|
|
266
|
+
* @Endpoint(getUserEndpoint)
|
|
267
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
268
|
+
* // request.urlParams.userId is typed as string
|
|
269
|
+
* // request.query.include is typed as string | undefined
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
type EndpointParams<EndpointDeclaration extends {
|
|
274
|
+
config: BaseEndpointConfig<any, any, any, any, any>;
|
|
275
|
+
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodType ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
|
|
276
|
+
/**
|
|
277
|
+
* Extracts the typed return value for an endpoint handler function.
|
|
278
|
+
*
|
|
279
|
+
* This utility type extracts the response schema from an endpoint declaration
|
|
280
|
+
* and returns the appropriate Promise type.
|
|
281
|
+
*
|
|
282
|
+
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const getUserEndpoint = api.declareEndpoint({
|
|
287
|
+
* method: 'get',
|
|
288
|
+
* url: '/users/$userId',
|
|
289
|
+
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
290
|
+
* })
|
|
291
|
+
*
|
|
292
|
+
* @Endpoint(getUserEndpoint)
|
|
293
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
|
|
294
|
+
* return { id: '1', name: 'John' } // Type-checked against responseSchema
|
|
295
|
+
* }
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
type EndpointResult<EndpointDeclaration extends {
|
|
299
|
+
config: BaseEndpointConfig<any, any, any, any, any>;
|
|
300
|
+
}> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z$1.input<Options[number]>> : Promise<z$1.input<EndpointDeclaration['config']['responseSchema']>>;
|
|
301
|
+
/**
|
|
302
|
+
* Decorator that marks a method as an HTTP endpoint.
|
|
303
|
+
*
|
|
304
|
+
* The endpoint must be defined using @navios/builder's `declareEndpoint` method.
|
|
305
|
+
* This ensures type safety and consistency between client and server.
|
|
306
|
+
*
|
|
307
|
+
* @param endpoint - The endpoint declaration from @navios/builder
|
|
308
|
+
* @returns A method decorator
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* import { builder } from '@navios/builder'
|
|
313
|
+
*
|
|
314
|
+
* const api = builder()
|
|
315
|
+
* const getUserEndpoint = api.declareEndpoint({
|
|
316
|
+
* method: 'get',
|
|
317
|
+
* url: '/users/$userId',
|
|
318
|
+
* responseSchema: z.object({ id: z.string(), name: z.string() }),
|
|
319
|
+
* })
|
|
320
|
+
*
|
|
321
|
+
* @Controller()
|
|
322
|
+
* export class UserController {
|
|
323
|
+
* @Endpoint(getUserEndpoint)
|
|
324
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
325
|
+
* const { userId } = request.urlParams
|
|
326
|
+
* return { id: userId, name: 'John' }
|
|
327
|
+
* }
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
|
|
332
|
+
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
333
|
+
}): (target: (params: QuerySchema extends ZodType ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>) => Promise<z$1.input<ResponseSchema>>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends ZodType ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>) => Promise<z$1.input<ResponseSchema>>;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/metadata/handler.metadata.d.mts
|
|
336
|
+
declare const EndpointMetadataKey: unique symbol;
|
|
337
|
+
interface HandlerMetadata<Config = null> {
|
|
338
|
+
classMethod: string;
|
|
339
|
+
url: string;
|
|
340
|
+
successStatusCode: number;
|
|
341
|
+
adapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined> | ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface> | null;
|
|
342
|
+
headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
|
|
343
|
+
httpMethod: HttpMethod;
|
|
344
|
+
config: Config;
|
|
345
|
+
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
346
|
+
customAttributes: Map<string | symbol, any>;
|
|
347
|
+
}
|
|
348
|
+
declare function getAllEndpointMetadata(context: ClassMethodDecoratorContext | ClassDecoratorContext): Set<HandlerMetadata<any>>;
|
|
349
|
+
declare function getEndpointMetadata<Config = any>(target: Function, context: ClassMethodDecoratorContext): HandlerMetadata<Config>;
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/metadata/controller.metadata.d.mts
|
|
352
|
+
declare const ControllerMetadataKey: unique symbol;
|
|
353
|
+
interface ControllerMetadata {
|
|
354
|
+
endpoints: Set<HandlerMetadata>;
|
|
355
|
+
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
356
|
+
customAttributes: Map<string | symbol, any>;
|
|
357
|
+
}
|
|
358
|
+
declare function getControllerMetadata(target: ClassType, context: ClassDecoratorContext): ControllerMetadata;
|
|
359
|
+
declare function extractControllerMetadata(target: ClassType): ControllerMetadata;
|
|
360
|
+
declare function hasControllerMetadata(target: ClassType): boolean;
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/metadata/module.metadata.d.mts
|
|
363
|
+
declare const ModuleMetadataKey: unique symbol;
|
|
364
|
+
interface ModuleMetadata {
|
|
365
|
+
controllers: Set<ClassType>;
|
|
366
|
+
imports: Set<ClassType>;
|
|
367
|
+
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
368
|
+
customAttributes: Map<string | symbol, any>;
|
|
369
|
+
}
|
|
370
|
+
declare function getModuleMetadata(target: ClassType, context: ClassDecoratorContext): ModuleMetadata;
|
|
371
|
+
declare function extractModuleMetadata(target: ClassType): ModuleMetadata;
|
|
372
|
+
declare function hasModuleMetadata(target: ClassType): boolean;
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/interfaces/abstract-execution-context.inteface.d.mts
|
|
375
|
+
/**
|
|
376
|
+
* Interface providing access to the execution context during request handling.
|
|
377
|
+
*
|
|
378
|
+
* The execution context provides access to metadata and request/reply objects
|
|
379
|
+
* for the current request. It is available in guards and can be injected into
|
|
380
|
+
* services if needed.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* @Injectable()
|
|
385
|
+
* export class AuthGuard implements CanActivate {
|
|
386
|
+
* async canActivate(context: AbstractExecutionContext): Promise<boolean> {
|
|
387
|
+
* const request = context.getRequest()
|
|
388
|
+
* const handler = context.getHandler()
|
|
389
|
+
* // Access request and handler metadata
|
|
390
|
+
* return true
|
|
391
|
+
* }
|
|
392
|
+
* }
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
interface AbstractExecutionContext {
|
|
396
|
+
/**
|
|
397
|
+
* Gets the metadata for the module containing the current endpoint.
|
|
398
|
+
*/
|
|
399
|
+
getModule(): ModuleMetadata;
|
|
400
|
+
/**
|
|
401
|
+
* Gets the metadata for the controller containing the current endpoint.
|
|
402
|
+
*/
|
|
403
|
+
getController(): ControllerMetadata;
|
|
404
|
+
/**
|
|
405
|
+
* Gets the metadata for the current endpoint handler.
|
|
406
|
+
*/
|
|
407
|
+
getHandler(): HandlerMetadata;
|
|
408
|
+
/**
|
|
409
|
+
* Gets the HTTP request object (adapter-specific).
|
|
410
|
+
*/
|
|
411
|
+
getRequest(): any;
|
|
412
|
+
/**
|
|
413
|
+
* Gets the HTTP reply object (adapter-specific).
|
|
414
|
+
*/
|
|
415
|
+
getReply(): any;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/logger/utils/cli-colors.util.d.mts
|
|
419
|
+
declare const clc: {
|
|
420
|
+
bold: (text: string) => string;
|
|
421
|
+
green: (text: string) => string;
|
|
422
|
+
yellow: (text: string) => string;
|
|
423
|
+
red: (text: string) => string;
|
|
424
|
+
magentaBright: (text: string) => string;
|
|
425
|
+
cyanBright: (text: string) => string;
|
|
426
|
+
};
|
|
427
|
+
declare const yellow: (text: string) => string;
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/logger/log-levels.d.mts
|
|
430
|
+
/**
|
|
431
|
+
* Available log levels in order of severity (lowest to highest).
|
|
432
|
+
*/
|
|
433
|
+
declare const LOG_LEVELS: ["verbose", "debug", "log", "warn", "error", "fatal"];
|
|
434
|
+
/**
|
|
435
|
+
* Log level type.
|
|
436
|
+
*
|
|
437
|
+
* Represents the severity level of a log message.
|
|
438
|
+
* Levels are: 'verbose', 'debug', 'log', 'warn', 'error', 'fatal'
|
|
439
|
+
*
|
|
440
|
+
* @publicApi
|
|
441
|
+
*/
|
|
442
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/logger/utils/filter-log-levelts.util.d.mts
|
|
445
|
+
/**
|
|
446
|
+
* @publicApi
|
|
447
|
+
*/
|
|
448
|
+
declare function filterLogLevels(parseableString?: string): LogLevel[];
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/logger/utils/is-log-level.util.d.mts
|
|
451
|
+
/**
|
|
452
|
+
* @publicApi
|
|
453
|
+
*/
|
|
454
|
+
declare function isLogLevel(maybeLogLevel: any): maybeLogLevel is LogLevel;
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/logger/utils/is-log-level-enabled.d.mts
|
|
457
|
+
/**
|
|
458
|
+
* Checks if target level is enabled.
|
|
459
|
+
* @param targetLevel target level
|
|
460
|
+
* @param logLevels array of enabled log levels
|
|
461
|
+
*/
|
|
462
|
+
declare function isLogLevelEnabled(targetLevel: LogLevel, logLevels: LogLevel[] | undefined): boolean;
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/logger/utils/shared.utils.d.mts
|
|
465
|
+
declare const isUndefined: (obj: any) => obj is undefined;
|
|
466
|
+
declare const isObject: (fn: any) => fn is object;
|
|
467
|
+
declare const isPlainObject: (fn: any) => fn is object;
|
|
468
|
+
declare const addLeadingSlash: (path?: string) => string;
|
|
469
|
+
declare const normalizePath: (path?: string) => string;
|
|
470
|
+
declare const stripEndSlash: (path: string) => string;
|
|
471
|
+
declare const isFunction: (val: any) => val is Function;
|
|
472
|
+
declare const isString: (val: any) => val is string;
|
|
473
|
+
declare const isNumber: (val: any) => val is number;
|
|
474
|
+
declare const isConstructor: (val: any) => boolean;
|
|
475
|
+
declare const isNil: (val: any) => val is null | undefined;
|
|
476
|
+
declare const isEmpty: (array: any) => boolean;
|
|
477
|
+
declare const isSymbol: (val: any) => val is symbol;
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/logger/logger-service.interface.d.mts
|
|
480
|
+
/**
|
|
481
|
+
* @publicApi
|
|
482
|
+
*/
|
|
483
|
+
interface LoggerService {
|
|
484
|
+
/**
|
|
485
|
+
* Write a 'log' level log.
|
|
486
|
+
*/
|
|
487
|
+
log(message: any, ...optionalParams: any[]): any;
|
|
488
|
+
/**
|
|
489
|
+
* Write an 'error' level log.
|
|
490
|
+
*/
|
|
491
|
+
error(message: any, ...optionalParams: any[]): any;
|
|
492
|
+
/**
|
|
493
|
+
* Write a 'warn' level log.
|
|
494
|
+
*/
|
|
495
|
+
warn(message: any, ...optionalParams: any[]): any;
|
|
496
|
+
/**
|
|
497
|
+
* Write a 'debug' level log.
|
|
498
|
+
*/
|
|
499
|
+
debug?(message: any, ...optionalParams: any[]): any;
|
|
500
|
+
/**
|
|
501
|
+
* Write a 'verbose' level log.
|
|
502
|
+
*/
|
|
503
|
+
verbose?(message: any, ...optionalParams: any[]): any;
|
|
504
|
+
/**
|
|
505
|
+
* Write a 'fatal' level log.
|
|
506
|
+
*/
|
|
507
|
+
fatal?(message: any, ...optionalParams: any[]): any;
|
|
508
|
+
/**
|
|
509
|
+
* Set log levels.
|
|
510
|
+
* @param levels log levels
|
|
511
|
+
*/
|
|
512
|
+
setLogLevels?(levels: LogLevel[]): any;
|
|
513
|
+
}
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/logger/console-logger.service.d.mts
|
|
516
|
+
/**
|
|
517
|
+
* @publicApi
|
|
518
|
+
*/
|
|
519
|
+
interface ConsoleLoggerOptions {
|
|
520
|
+
/**
|
|
521
|
+
* Enabled log levels.
|
|
522
|
+
*/
|
|
523
|
+
logLevels?: LogLevel[];
|
|
524
|
+
/**
|
|
525
|
+
* If enabled, will print timestamp (time difference) between current and previous log message.
|
|
526
|
+
* Note: This option is not used when `json` is enabled.
|
|
527
|
+
*/
|
|
528
|
+
timestamp?: boolean;
|
|
529
|
+
/**
|
|
530
|
+
* A prefix to be used for each log message.
|
|
531
|
+
* Note: This option is not used when `json` is enabled.
|
|
532
|
+
*/
|
|
533
|
+
prefix?: string;
|
|
534
|
+
/**
|
|
535
|
+
* If enabled, will add a request ID to the log message.
|
|
536
|
+
*/
|
|
537
|
+
requestId?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* If enabled, will print the log message in JSON format.
|
|
540
|
+
*/
|
|
541
|
+
json?: boolean;
|
|
542
|
+
/**
|
|
543
|
+
* If enabled, will print the log message in color.
|
|
544
|
+
* Default true if json is disabled, false otherwise
|
|
545
|
+
*/
|
|
546
|
+
colors?: boolean;
|
|
547
|
+
/**
|
|
548
|
+
* The context of the logger.
|
|
549
|
+
*/
|
|
550
|
+
context?: string;
|
|
551
|
+
/**
|
|
552
|
+
* If enabled, will print the log message in a single line, even if it is an object with multiple properties.
|
|
553
|
+
* 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.
|
|
554
|
+
* Default true when `json` is enabled, false otherwise.
|
|
555
|
+
*/
|
|
556
|
+
compact?: boolean | number;
|
|
557
|
+
/**
|
|
558
|
+
* Specifies the maximum number of Array, TypedArray, Map, Set, WeakMap, and WeakSet elements to include when formatting.
|
|
559
|
+
* Set to null or Infinity to show all elements. Set to 0 or negative to show no elements.
|
|
560
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
561
|
+
* @default 100
|
|
562
|
+
*/
|
|
563
|
+
maxArrayLength?: number;
|
|
564
|
+
/**
|
|
565
|
+
* Specifies the maximum number of characters to include when formatting.
|
|
566
|
+
* Set to null or Infinity to show all elements. Set to 0 or negative to show no characters.
|
|
567
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
568
|
+
* @default 10000.
|
|
569
|
+
*/
|
|
570
|
+
maxStringLength?: number;
|
|
571
|
+
/**
|
|
572
|
+
* If enabled, will sort keys while formatting objects.
|
|
573
|
+
* Can also be a custom sorting function.
|
|
574
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
575
|
+
* @default false
|
|
576
|
+
*/
|
|
577
|
+
sorted?: boolean | ((a: string, b: string) => number);
|
|
578
|
+
/**
|
|
579
|
+
* Specifies the number of times to recurse while formatting object. T
|
|
580
|
+
* This is useful for inspecting large objects. To recurse up to the maximum call stack size pass Infinity or null.
|
|
581
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
582
|
+
* @default 5
|
|
583
|
+
*/
|
|
584
|
+
depth?: number;
|
|
585
|
+
/**
|
|
586
|
+
* If true, object's non-enumerable symbols and properties are included in the formatted result.
|
|
587
|
+
* WeakMap and WeakSet entries are also included as well as user defined prototype properties
|
|
588
|
+
* @default false
|
|
589
|
+
*/
|
|
590
|
+
showHidden?: boolean;
|
|
591
|
+
/**
|
|
592
|
+
* 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).
|
|
593
|
+
* Default Infinity when "compact" is true, 80 otherwise.
|
|
594
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
595
|
+
*/
|
|
596
|
+
breakLength?: number;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* @publicApi
|
|
600
|
+
*/
|
|
601
|
+
declare class ConsoleLogger implements LoggerService {
|
|
602
|
+
/**
|
|
603
|
+
* The options of the logger.
|
|
604
|
+
*/
|
|
605
|
+
protected options: ConsoleLoggerOptions;
|
|
606
|
+
/**
|
|
607
|
+
* The context of the logger (can be set manually or automatically inferred).
|
|
608
|
+
*/
|
|
609
|
+
protected context?: string;
|
|
610
|
+
/**
|
|
611
|
+
* The original context of the logger (set in the constructor).
|
|
612
|
+
*/
|
|
613
|
+
protected originalContext?: string;
|
|
614
|
+
/**
|
|
615
|
+
* The options used for the "inspect" method.
|
|
616
|
+
*/
|
|
617
|
+
protected inspectOptions: InspectOptions;
|
|
618
|
+
/**
|
|
619
|
+
* The last timestamp at which the log message was printed.
|
|
620
|
+
*/
|
|
621
|
+
protected lastTimestampAt?: number;
|
|
622
|
+
setup(): void;
|
|
623
|
+
setup(context: string): void;
|
|
624
|
+
setup(options: ConsoleLoggerOptions): void;
|
|
625
|
+
setup(context: string, options: ConsoleLoggerOptions): void;
|
|
626
|
+
/**
|
|
627
|
+
* Write a 'log' level log, if the configured level allows for it.
|
|
628
|
+
* Prints to `stdout` with newline.
|
|
629
|
+
*/
|
|
630
|
+
log(message: any, context?: string): void;
|
|
631
|
+
log(message: any, ...optionalParams: [...any, string?]): void;
|
|
632
|
+
/**
|
|
633
|
+
* Write an 'error' level log, if the configured level allows for it.
|
|
634
|
+
* Prints to `stderr` with newline.
|
|
635
|
+
*/
|
|
636
|
+
error(message: any, stackOrContext?: string): void;
|
|
637
|
+
error(message: any, stack?: string, context?: string): void;
|
|
638
|
+
error(message: any, ...optionalParams: [...any, string?, string?]): void;
|
|
639
|
+
/**
|
|
640
|
+
* Write a 'warn' level log, if the configured level allows for it.
|
|
641
|
+
* Prints to `stdout` with newline.
|
|
642
|
+
*/
|
|
643
|
+
warn(message: any, context?: string): void;
|
|
644
|
+
warn(message: any, ...optionalParams: [...any, string?]): void;
|
|
645
|
+
/**
|
|
646
|
+
* Write a 'debug' level log, if the configured level allows for it.
|
|
647
|
+
* Prints to `stdout` with newline.
|
|
648
|
+
*/
|
|
649
|
+
debug(message: any, context?: string): void;
|
|
650
|
+
debug(message: any, ...optionalParams: [...any, string?]): void;
|
|
651
|
+
/**
|
|
652
|
+
* Write a 'verbose' level log, if the configured level allows for it.
|
|
653
|
+
* Prints to `stdout` with newline.
|
|
654
|
+
*/
|
|
655
|
+
verbose(message: any, context?: string): void;
|
|
656
|
+
verbose(message: any, ...optionalParams: [...any, string?]): void;
|
|
657
|
+
/**
|
|
658
|
+
* Write a 'fatal' level log, if the configured level allows for it.
|
|
659
|
+
* Prints to `stdout` with newline.
|
|
660
|
+
*/
|
|
661
|
+
fatal(message: any, context?: string): void;
|
|
662
|
+
fatal(message: any, ...optionalParams: [...any, string?]): void;
|
|
663
|
+
/**
|
|
664
|
+
* Set log levels
|
|
665
|
+
* @param levels log levels
|
|
666
|
+
*/
|
|
667
|
+
setLogLevels(levels: LogLevel[]): void;
|
|
668
|
+
/**
|
|
669
|
+
* Set logger context
|
|
670
|
+
* @param context context
|
|
671
|
+
*/
|
|
672
|
+
setContext(context: string): void;
|
|
673
|
+
/**
|
|
674
|
+
* Resets the logger context to the value that was passed in the constructor.
|
|
675
|
+
*/
|
|
676
|
+
resetContext(): void;
|
|
677
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
678
|
+
/**
|
|
679
|
+
* Gets the current request ID from the AsyncLocalStorage store.
|
|
680
|
+
* Only returns a value if the requestId option is enabled.
|
|
681
|
+
*/
|
|
682
|
+
protected getCurrentRequestId(): string | undefined;
|
|
683
|
+
protected getTimestamp(): string;
|
|
684
|
+
protected printMessages(messages: unknown[], context?: string, logLevel?: LogLevel, requestId?: string, writeStreamType?: 'stdout' | 'stderr', errorStack?: unknown): void;
|
|
685
|
+
protected printAsJson(message: unknown, options: {
|
|
686
|
+
context: string;
|
|
687
|
+
logLevel: LogLevel;
|
|
688
|
+
writeStreamType?: 'stdout' | 'stderr';
|
|
689
|
+
errorStack?: unknown;
|
|
690
|
+
requestId?: string;
|
|
691
|
+
}): void;
|
|
692
|
+
protected formatPid(pid: number): string;
|
|
693
|
+
protected formatContext(context: string): string;
|
|
694
|
+
protected formatMessage(logLevel: LogLevel, message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string, requestId?: string): string;
|
|
695
|
+
protected getRequestId(requestId?: string): string;
|
|
696
|
+
protected stringifyMessage(message: unknown, logLevel: LogLevel): string;
|
|
697
|
+
protected colorize(message: string, logLevel: LogLevel): string;
|
|
698
|
+
protected printStackTrace(stack: string): void;
|
|
699
|
+
protected updateAndGetTimestampDiff(): string;
|
|
700
|
+
protected formatTimestampDiff(timestampDiff: number): string;
|
|
701
|
+
protected getInspectOptions(): InspectOptions;
|
|
702
|
+
protected stringifyReplacer(key: string, value: unknown): unknown;
|
|
703
|
+
private getContextAndMessagesToPrint;
|
|
704
|
+
private getContextAndStackAndMessagesToPrint;
|
|
705
|
+
private isStackFormat;
|
|
706
|
+
private getColorByLogLevel;
|
|
707
|
+
}
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/logger/logger.service.d.mts
|
|
710
|
+
/**
|
|
711
|
+
* Logger service instance that can be injected into services and controllers.
|
|
712
|
+
*
|
|
713
|
+
* Provides contextualized logging with automatic context injection.
|
|
714
|
+
* The context is set when the logger is injected using the `inject` function.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```typescript
|
|
718
|
+
* @Injectable()
|
|
719
|
+
* export class UserService {
|
|
720
|
+
* private logger = inject(Logger, { context: UserService.name })
|
|
721
|
+
*
|
|
722
|
+
* async findUser(id: string) {
|
|
723
|
+
* this.logger.log(`Finding user ${id}`)
|
|
724
|
+
* // Logs with context: [UserService]
|
|
725
|
+
* }
|
|
726
|
+
* }
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
declare class LoggerInstance implements LoggerService {
|
|
730
|
+
protected localInstance: LoggerService;
|
|
731
|
+
protected context?: string;
|
|
732
|
+
constructor(config?: LoggerOptions);
|
|
733
|
+
/**
|
|
734
|
+
* Write an 'error' level log.
|
|
735
|
+
*/
|
|
736
|
+
error(message: any, stack?: string, context?: string): void;
|
|
737
|
+
error(message: any, ...optionalParams: [...any, string?, string?]): void;
|
|
738
|
+
/**
|
|
739
|
+
* Write a 'log' level log.
|
|
740
|
+
*/
|
|
741
|
+
log(message: any, context?: string): void;
|
|
742
|
+
log(message: any, ...optionalParams: [...any, string?]): void;
|
|
743
|
+
/**
|
|
744
|
+
* Write a 'warn' level log.
|
|
745
|
+
*/
|
|
746
|
+
warn(message: any, context?: string): void;
|
|
747
|
+
warn(message: any, ...optionalParams: [...any, string?]): void;
|
|
748
|
+
/**
|
|
749
|
+
* Write a 'debug' level log.
|
|
750
|
+
*/
|
|
751
|
+
debug(message: any, context?: string): void;
|
|
752
|
+
debug(message: any, ...optionalParams: [...any, string?]): void;
|
|
753
|
+
/**
|
|
754
|
+
* Write a 'verbose' level log.
|
|
755
|
+
*/
|
|
756
|
+
verbose(message: any, context?: string): void;
|
|
757
|
+
verbose(message: any, ...optionalParams: [...any, string?]): void;
|
|
758
|
+
/**
|
|
759
|
+
* Write a 'fatal' level log.
|
|
760
|
+
*/
|
|
761
|
+
fatal(message: any, context?: string): void;
|
|
762
|
+
fatal(message: any, ...optionalParams: [...any, string?]): void;
|
|
763
|
+
}
|
|
764
|
+
//#endregion
|
|
765
|
+
//#region src/logger/logger.tokens.d.mts
|
|
766
|
+
/**
|
|
767
|
+
* Injection token for the logger output service.
|
|
768
|
+
*
|
|
769
|
+
* This token is used to provide a custom logger implementation.
|
|
770
|
+
* By default, it's bound to ConsoleLogger.
|
|
771
|
+
*/
|
|
772
|
+
declare const LoggerOutput: InjectionToken<LoggerService, undefined, false>;
|
|
773
|
+
/**
|
|
774
|
+
* Schema for logger options.
|
|
775
|
+
*/
|
|
776
|
+
declare const loggerOptionsSchema: z.ZodOptional<z.ZodObject<{
|
|
777
|
+
context: z.ZodOptional<z.ZodString>;
|
|
778
|
+
}, z.core.$strip>>;
|
|
779
|
+
/**
|
|
780
|
+
* Options for creating a logger instance.
|
|
781
|
+
*/
|
|
782
|
+
type LoggerOptions = z.infer<typeof loggerOptionsSchema>;
|
|
783
|
+
/**
|
|
784
|
+
* Injection token for the Logger service.
|
|
785
|
+
*
|
|
786
|
+
* Use this token to inject a contextualized logger instance.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```typescript
|
|
790
|
+
* const logger = inject(Logger, { context: 'MyService' })
|
|
791
|
+
* logger.log('Hello world') // Logs with context: [MyService]
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
declare const Logger: InjectionToken<LoggerInstance, z.ZodOptional<z.ZodObject<{
|
|
795
|
+
context: z.ZodOptional<z.ZodString>;
|
|
796
|
+
}, z.core.$strip>>, false>;
|
|
797
|
+
//#endregion
|
|
798
|
+
//#region src/interfaces/abstract-http-cors-options.interface.d.mts
|
|
799
|
+
interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}
|
|
800
|
+
type OriginType = string | boolean | RegExp;
|
|
801
|
+
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;
|
|
802
|
+
interface AbstractHttpCorsOptions {
|
|
803
|
+
/**
|
|
804
|
+
* Configures the Access-Control-Allow-Origin CORS header.
|
|
805
|
+
*/
|
|
806
|
+
origin?: ValueOrArray<OriginType>;
|
|
807
|
+
/**
|
|
808
|
+
* Configures the Access-Control-Allow-Credentials CORS header.
|
|
809
|
+
* Set to true to pass the header, otherwise it is omitted.
|
|
810
|
+
*/
|
|
811
|
+
credentials?: boolean;
|
|
812
|
+
/**
|
|
813
|
+
* Configures the Access-Control-Expose-Headers CORS header.
|
|
814
|
+
* Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
|
|
815
|
+
* or an array (ex: ['Content-Range', 'X-Content-Range']).
|
|
816
|
+
* If not specified, no custom headers are exposed.
|
|
817
|
+
*/
|
|
818
|
+
exposedHeaders?: string | string[];
|
|
819
|
+
/**
|
|
820
|
+
* Configures the Access-Control-Allow-Headers CORS header.
|
|
821
|
+
* Expects a comma-delimited string (ex: 'Content-Type,Authorization')
|
|
822
|
+
* or an array (ex: ['Content-Type', 'Authorization']). If not
|
|
823
|
+
* specified, defaults to reflecting the headers specified in the
|
|
824
|
+
* request's Access-Control-Request-Headers header.
|
|
825
|
+
*/
|
|
826
|
+
allowedHeaders?: string | string[];
|
|
827
|
+
/**
|
|
828
|
+
* Configures the Access-Control-Allow-Methods CORS header.
|
|
829
|
+
* Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
|
|
830
|
+
*/
|
|
831
|
+
methods?: string | string[];
|
|
832
|
+
/**
|
|
833
|
+
* Configures the Access-Control-Max-Age CORS header.
|
|
834
|
+
* Set to an integer to pass the header, otherwise it is omitted.
|
|
835
|
+
*/
|
|
836
|
+
maxAge?: number;
|
|
837
|
+
/**
|
|
838
|
+
* Configures the Cache-Control header for CORS preflight responses.
|
|
839
|
+
* Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
|
|
840
|
+
* or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
|
|
841
|
+
* the header value), otherwise the header is omitted.
|
|
842
|
+
*/
|
|
843
|
+
cacheControl?: number | string;
|
|
844
|
+
/**
|
|
845
|
+
* Sets the Fastify log level specifically for the internal OPTIONS route
|
|
846
|
+
* used to handle CORS preflight requests. For example, setting this to `'silent'`
|
|
847
|
+
* will prevent these requests from being logged.
|
|
848
|
+
* Useful for reducing noise in application logs.
|
|
849
|
+
* Default: inherits Fastify's global log level.
|
|
850
|
+
*/
|
|
851
|
+
logLevel?: LogLevel;
|
|
852
|
+
}
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region src/interfaces/abstract-http-listen-options.interface.d.mts
|
|
855
|
+
interface AbstractHttpListenOptions {
|
|
856
|
+
port: number;
|
|
857
|
+
host?: string;
|
|
858
|
+
}
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region src/interfaces/abstract-http-adapter.interface.d.mts
|
|
861
|
+
/**
|
|
862
|
+
* Abstract interface for HTTP adapters.
|
|
863
|
+
*
|
|
864
|
+
* Adapters implement this interface to provide runtime-specific HTTP server
|
|
865
|
+
* functionality (Fastify, Bun, etc.).
|
|
866
|
+
*
|
|
867
|
+
* @typeParam ServerInstance - The underlying server type (e.g., FastifyInstance)
|
|
868
|
+
* @typeParam CorsOptions - CORS configuration options type
|
|
869
|
+
* @typeParam Options - Server setup options type
|
|
870
|
+
* @typeParam MultipartOptions - Multipart form handling options type
|
|
871
|
+
*/
|
|
872
|
+
interface AbstractHttpAdapterInterface<ServerInstance, CorsOptions = AbstractHttpCorsOptions, Options$1 = {}, MultipartOptions = {}> {
|
|
873
|
+
/**
|
|
874
|
+
* Sets up the HTTP server with the provided options.
|
|
875
|
+
*/
|
|
876
|
+
setupHttpServer(options: Options$1): Promise<void>;
|
|
877
|
+
/**
|
|
878
|
+
* Called after all modules are loaded to register routes.
|
|
879
|
+
*/
|
|
880
|
+
onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>;
|
|
881
|
+
/**
|
|
882
|
+
* Signals that the server is ready to accept requests.
|
|
883
|
+
*/
|
|
884
|
+
ready(): Promise<void>;
|
|
885
|
+
/**
|
|
886
|
+
* Returns the underlying HTTP server instance.
|
|
887
|
+
*/
|
|
888
|
+
getServer(): ServerInstance;
|
|
889
|
+
/**
|
|
890
|
+
* Sets a global prefix for all routes.
|
|
891
|
+
*/
|
|
892
|
+
setGlobalPrefix(prefix: string): void;
|
|
893
|
+
/**
|
|
894
|
+
* Gets the current global prefix.
|
|
895
|
+
* Returns empty string if no prefix is set.
|
|
896
|
+
*/
|
|
897
|
+
getGlobalPrefix(): string;
|
|
898
|
+
/**
|
|
899
|
+
* Enables CORS with the specified options.
|
|
900
|
+
*/
|
|
901
|
+
enableCors(options: CorsOptions): void;
|
|
902
|
+
/**
|
|
903
|
+
* Enables multipart form data handling.
|
|
904
|
+
*/
|
|
905
|
+
enableMultipart(options: MultipartOptions): void;
|
|
906
|
+
/**
|
|
907
|
+
* Starts the server and listens for incoming requests.
|
|
908
|
+
*/
|
|
909
|
+
listen(options: AbstractHttpListenOptions): Promise<string>;
|
|
910
|
+
/**
|
|
911
|
+
* Disposes of the server and cleans up resources.
|
|
912
|
+
*/
|
|
913
|
+
dispose(): Promise<void>;
|
|
914
|
+
}
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region src/interfaces/abstract-http-handler-adapter.interface.d.mts
|
|
917
|
+
interface AbstractHttpHandlerAdapterInterface {
|
|
918
|
+
prepareArguments?: (handlerMetadata: HandlerMetadata<any>) => ((target: Record<string, any>, request: any) => Promise<void> | void)[];
|
|
919
|
+
provideHandler: (controller: ClassType, handlerMetadata: HandlerMetadata<any>) => (context: ScopedContainer, request: any, reply: any) => Promise<any>;
|
|
920
|
+
}
|
|
921
|
+
//#endregion
|
|
922
|
+
//#region src/interfaces/can-activate.d.mts
|
|
923
|
+
/**
|
|
924
|
+
* Interface that guards must implement to control access to endpoints.
|
|
925
|
+
*
|
|
926
|
+
* Guards are used for authentication, authorization, and request validation.
|
|
927
|
+
* They are executed before the endpoint handler and can prevent the request
|
|
928
|
+
* from proceeding by returning `false` or throwing an exception.
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* @Injectable()
|
|
933
|
+
* export class AuthGuard implements CanActivate {
|
|
934
|
+
* async canActivate(context: AbstractExecutionContext): Promise<boolean> {
|
|
935
|
+
* const request = context.getRequest()
|
|
936
|
+
* const token = request.headers.authorization
|
|
937
|
+
*
|
|
938
|
+
* if (!token) {
|
|
939
|
+
* throw new UnauthorizedException('Authentication required')
|
|
940
|
+
* }
|
|
941
|
+
*
|
|
942
|
+
* // Validate token
|
|
943
|
+
* return true
|
|
944
|
+
* }
|
|
945
|
+
* }
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
interface CanActivate {
|
|
949
|
+
/**
|
|
950
|
+
* Determines if the current request can proceed to the endpoint handler.
|
|
951
|
+
*
|
|
952
|
+
* @param executionContext - The execution context containing request, reply, and metadata
|
|
953
|
+
* @returns `true` if the request can proceed, `false` otherwise. Can also throw an exception.
|
|
954
|
+
*/
|
|
955
|
+
canActivate(executionContext: AbstractExecutionContext): Promise<boolean> | boolean;
|
|
956
|
+
}
|
|
957
|
+
//#endregion
|
|
958
|
+
//#region src/interfaces/http-header.d.mts
|
|
959
|
+
type OmitIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
960
|
+
/**
|
|
961
|
+
* HTTP header strings
|
|
962
|
+
* Use this type only for input values, not for output values.
|
|
963
|
+
*/
|
|
964
|
+
type HttpHeader = keyof OmitIndexSignature<OutgoingHttpHeaders> | (string & Record<never, never>);
|
|
965
|
+
//#endregion
|
|
966
|
+
//#region src/interfaces/navios-module.d.mts
|
|
967
|
+
/**
|
|
968
|
+
* Interface that all Navios modules must implement.
|
|
969
|
+
*
|
|
970
|
+
* Modules decorated with @Module() should implement this interface to receive
|
|
971
|
+
* lifecycle hooks.
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```typescript
|
|
975
|
+
* @Module({
|
|
976
|
+
* controllers: [UserController],
|
|
977
|
+
* })
|
|
978
|
+
* export class AppModule implements NaviosModule {
|
|
979
|
+
* async onModuleInit() {
|
|
980
|
+
* console.log('AppModule initialized')
|
|
981
|
+
* // Perform initialization logic
|
|
982
|
+
* }
|
|
983
|
+
* }
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
interface NaviosModule {
|
|
987
|
+
/**
|
|
988
|
+
* Optional lifecycle hook called after the module is initialized.
|
|
989
|
+
*
|
|
990
|
+
* This is called after all modules are loaded and the HTTP server is set up
|
|
991
|
+
* (if an adapter is configured), but before the server starts listening.
|
|
992
|
+
*/
|
|
993
|
+
onModuleInit?: () => Promise<void> | void;
|
|
994
|
+
}
|
|
995
|
+
//#endregion
|
|
996
|
+
//#region src/services/module-loader.service.d.mts
|
|
997
|
+
/**
|
|
998
|
+
* Extension definition for dynamically adding to the module tree.
|
|
999
|
+
* Used by plugins to inject controllers or entire modules.
|
|
1000
|
+
*/
|
|
1001
|
+
interface ModuleExtension {
|
|
1002
|
+
/**
|
|
1003
|
+
* Module class to add. If provided, the module and all its
|
|
1004
|
+
* controllers/imports will be processed.
|
|
1005
|
+
*/
|
|
1006
|
+
module?: ClassTypeWithInstance<NaviosModule>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Controllers to add directly without a wrapper module.
|
|
1009
|
+
* Will be registered under a synthetic module named after the plugin.
|
|
1010
|
+
*/
|
|
1011
|
+
controllers?: ClassType[];
|
|
1012
|
+
/**
|
|
1013
|
+
* Name for the synthetic module when using controllers directly.
|
|
1014
|
+
* Required if `controllers` is provided without `module`.
|
|
1015
|
+
*/
|
|
1016
|
+
moduleName?: string;
|
|
1017
|
+
}
|
|
1018
|
+
declare class ModuleLoaderService {
|
|
1019
|
+
private logger;
|
|
1020
|
+
protected container: Container;
|
|
1021
|
+
private modulesMetadata;
|
|
1022
|
+
private loadedModules;
|
|
1023
|
+
private initialized;
|
|
1024
|
+
loadModules(appModule: ClassTypeWithInstance<NaviosModule>): Promise<void>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Extends the module tree with additional modules or controllers.
|
|
1027
|
+
*
|
|
1028
|
+
* This method is designed to be called by plugins during registration,
|
|
1029
|
+
* which happens after initial module loading but before route registration.
|
|
1030
|
+
*
|
|
1031
|
+
* @param extensions - Array of module extensions to add
|
|
1032
|
+
* @throws Error if not initialized (loadModules must be called first)
|
|
1033
|
+
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```typescript
|
|
1036
|
+
* // In plugin registration
|
|
1037
|
+
* const moduleLoader = await context.container.get(ModuleLoaderService)
|
|
1038
|
+
* await moduleLoader.extendModules([{
|
|
1039
|
+
* controllers: [OpenApiJsonController, OpenApiYamlController],
|
|
1040
|
+
* moduleName: 'OpenApiBunModule',
|
|
1041
|
+
* }])
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
extendModules(extensions: ModuleExtension[]): Promise<void>;
|
|
1045
|
+
/**
|
|
1046
|
+
* Registers controllers under a synthetic module.
|
|
1047
|
+
* Used when plugins want to add controllers without a full module class.
|
|
1048
|
+
*/
|
|
1049
|
+
private registerControllers;
|
|
1050
|
+
private traverseModules;
|
|
1051
|
+
private mergeMetadata;
|
|
1052
|
+
getAllModules(): Map<string, ModuleMetadata>;
|
|
1053
|
+
dispose(): void;
|
|
1054
|
+
}
|
|
1055
|
+
//#endregion
|
|
1056
|
+
//#region src/interfaces/plugin.interface.d.mts
|
|
1057
|
+
/**
|
|
1058
|
+
* Context provided to plugins during registration.
|
|
1059
|
+
*
|
|
1060
|
+
* This context gives plugins access to the application's modules,
|
|
1061
|
+
* server instance, DI container, and configuration.
|
|
1062
|
+
*/
|
|
1063
|
+
interface PluginContext {
|
|
1064
|
+
/**
|
|
1065
|
+
* All loaded modules with their metadata.
|
|
1066
|
+
* Keys are module class names, values are their metadata.
|
|
1067
|
+
*/
|
|
1068
|
+
modules: Map<string, ModuleMetadata>;
|
|
1069
|
+
/**
|
|
1070
|
+
* The underlying HTTP server instance.
|
|
1071
|
+
* Type depends on the adapter used (Fastify, Bun, etc.)
|
|
1072
|
+
*/
|
|
1073
|
+
server: any;
|
|
1074
|
+
/**
|
|
1075
|
+
* The dependency injection container.
|
|
1076
|
+
*/
|
|
1077
|
+
container: Container;
|
|
1078
|
+
/**
|
|
1079
|
+
* Global route prefix (e.g., '/api/v1').
|
|
1080
|
+
* Empty string if no prefix is set.
|
|
1081
|
+
*/
|
|
1082
|
+
globalPrefix: string;
|
|
1083
|
+
/**
|
|
1084
|
+
* Module loader service for extending the module tree.
|
|
1085
|
+
* Use `moduleLoader.extendModules()` to add controllers dynamically.
|
|
1086
|
+
*/
|
|
1087
|
+
moduleLoader: ModuleLoaderService;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Base interface for Navios plugins.
|
|
1091
|
+
*
|
|
1092
|
+
* Plugins are registered using `app.usePlugin()` and are initialized
|
|
1093
|
+
* after all modules are loaded but before the server starts listening.
|
|
1094
|
+
*
|
|
1095
|
+
* @typeParam TOptions - The type of options the plugin accepts
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```typescript
|
|
1099
|
+
* const myPlugin: NaviosPlugin<{ enabled: boolean }> = {
|
|
1100
|
+
* name: 'my-plugin',
|
|
1101
|
+
* register: async (context, options) => {
|
|
1102
|
+
* if (options.enabled) {
|
|
1103
|
+
* // Register routes, services, etc.
|
|
1104
|
+
* }
|
|
1105
|
+
* },
|
|
1106
|
+
* }
|
|
1107
|
+
* ```
|
|
1108
|
+
*/
|
|
1109
|
+
interface NaviosPlugin<TOptions = unknown> {
|
|
1110
|
+
/**
|
|
1111
|
+
* Plugin name for identification and logging.
|
|
1112
|
+
*/
|
|
1113
|
+
name: string;
|
|
1114
|
+
/**
|
|
1115
|
+
* Called after modules are loaded but before the server starts listening.
|
|
1116
|
+
*
|
|
1117
|
+
* @param context - The plugin context with access to modules and server
|
|
1118
|
+
* @param options - Plugin-specific configuration options
|
|
1119
|
+
*/
|
|
1120
|
+
register(context: PluginContext, options: TOptions): Promise<void> | void;
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Plugin definition combining a plugin with its options.
|
|
1124
|
+
*
|
|
1125
|
+
* This is the type returned by plugin factory functions like `defineOpenApiPlugin()`.
|
|
1126
|
+
*
|
|
1127
|
+
* @typeParam TOptions - The type of options the plugin accepts
|
|
1128
|
+
*
|
|
1129
|
+
* @example
|
|
1130
|
+
* ```typescript
|
|
1131
|
+
* function defineMyPlugin(options: MyPluginOptions): PluginDefinition<MyPluginOptions> {
|
|
1132
|
+
* return {
|
|
1133
|
+
* plugin: myPlugin,
|
|
1134
|
+
* options,
|
|
1135
|
+
* }
|
|
1136
|
+
* }
|
|
1137
|
+
* ```
|
|
1138
|
+
*/
|
|
1139
|
+
interface PluginDefinition<TOptions = unknown> {
|
|
1140
|
+
/**
|
|
1141
|
+
* The plugin instance.
|
|
1142
|
+
*/
|
|
1143
|
+
plugin: NaviosPlugin<TOptions>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Options to pass to the plugin's register function.
|
|
1146
|
+
*/
|
|
1147
|
+
options: TOptions;
|
|
1148
|
+
}
|
|
1149
|
+
//#endregion
|
|
1150
|
+
//#region src/decorators/header.decorator.d.mts
|
|
1151
|
+
/**
|
|
1152
|
+
* Decorator that sets a custom HTTP response header for an endpoint.
|
|
1153
|
+
*
|
|
1154
|
+
* @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
|
|
1155
|
+
* @param value - The header value (string, number, or array of strings)
|
|
1156
|
+
* @returns A method decorator
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```typescript
|
|
1160
|
+
* @Controller()
|
|
1161
|
+
* export class UserController {
|
|
1162
|
+
* @Endpoint(getUserEndpoint)
|
|
1163
|
+
* @Header('Cache-Control', 'max-age=3600')
|
|
1164
|
+
* async getUser() {
|
|
1165
|
+
* return { id: '1', name: 'John' }
|
|
1166
|
+
* }
|
|
1167
|
+
* }
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
declare function Header(name: HttpHeader, value: string | number | string[]): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/decorators/http-code.decorator.d.mts
|
|
1173
|
+
/**
|
|
1174
|
+
* Decorator that sets a custom HTTP status code for successful responses.
|
|
1175
|
+
*
|
|
1176
|
+
* By default, endpoints return 200 OK. Use this decorator to return a different status code.
|
|
1177
|
+
*
|
|
1178
|
+
* @param code - The HTTP status code to return (e.g., 201, 204, 202)
|
|
1179
|
+
* @returns A method decorator
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* ```typescript
|
|
1183
|
+
* @Controller()
|
|
1184
|
+
* export class UserController {
|
|
1185
|
+
* @Endpoint(createUserEndpoint)
|
|
1186
|
+
* @HttpCode(201)
|
|
1187
|
+
* async createUser() {
|
|
1188
|
+
* return { id: '1', name: 'John' }
|
|
1189
|
+
* }
|
|
1190
|
+
* }
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
declare function HttpCode(code: number): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region src/decorators/module.decorator.d.mts
|
|
1196
|
+
/**
|
|
1197
|
+
* Options for configuring a Navios module.
|
|
1198
|
+
*/
|
|
1199
|
+
interface ModuleOptions {
|
|
1200
|
+
/**
|
|
1201
|
+
* Controllers to register in this module.
|
|
1202
|
+
* Controllers handle HTTP requests and define endpoints.
|
|
1203
|
+
*/
|
|
1204
|
+
controllers?: ClassType[] | Set<ClassType>;
|
|
1205
|
+
/**
|
|
1206
|
+
* Other modules to import into this module.
|
|
1207
|
+
* Imported modules' controllers and services become available.
|
|
1208
|
+
*/
|
|
1209
|
+
imports?: ClassType[] | Set<ClassType>;
|
|
1210
|
+
/**
|
|
1211
|
+
* Guards to apply to all controllers in this module.
|
|
1212
|
+
* Guards are executed in reverse order (last guard first).
|
|
1213
|
+
*/
|
|
1214
|
+
guards?: ClassType[] | Set<ClassType>;
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Decorator that marks a class as a Navios module.
|
|
1218
|
+
*
|
|
1219
|
+
* Modules are the basic building blocks of a Navios application.
|
|
1220
|
+
* They organize controllers, services, and other modules into logical units.
|
|
1221
|
+
*
|
|
1222
|
+
* @param options - Module configuration options
|
|
1223
|
+
* @returns A class decorator
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* ```typescript
|
|
1227
|
+
* @Module({
|
|
1228
|
+
* controllers: [UserController, AuthController],
|
|
1229
|
+
* imports: [DatabaseModule],
|
|
1230
|
+
* guards: [AuthGuard],
|
|
1231
|
+
* })
|
|
1232
|
+
* export class AppModule {}
|
|
1233
|
+
* ```
|
|
1234
|
+
*/
|
|
1235
|
+
declare function Module({
|
|
1236
|
+
controllers,
|
|
1237
|
+
imports,
|
|
1238
|
+
guards
|
|
1239
|
+
}?: ModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
1240
|
+
//#endregion
|
|
1241
|
+
//#region src/decorators/multipart.decorator.d.mts
|
|
1242
|
+
/**
|
|
1243
|
+
* Extracts the typed parameters for a multipart endpoint handler function.
|
|
1244
|
+
*
|
|
1245
|
+
* Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.
|
|
1246
|
+
*
|
|
1247
|
+
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
1248
|
+
*/
|
|
1249
|
+
type MultipartParams<EndpointDeclaration extends {
|
|
1250
|
+
config: BaseEndpointConfig<any, any, any, any, any>;
|
|
1251
|
+
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Extracts the typed return value for a multipart endpoint handler function.
|
|
1254
|
+
*
|
|
1255
|
+
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
1256
|
+
*/
|
|
1257
|
+
type MultipartResult<EndpointDeclaration extends {
|
|
1258
|
+
config: BaseEndpointConfig<any, any, any, any, any>;
|
|
1259
|
+
}> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z$1.input<Options[number]>> : Promise<z$1.input<EndpointDeclaration['config']['responseSchema']>>;
|
|
1260
|
+
/**
|
|
1261
|
+
* Decorator that marks a method as a multipart/form-data endpoint.
|
|
1262
|
+
*
|
|
1263
|
+
* Use this decorator for endpoints that handle file uploads or form data.
|
|
1264
|
+
* The endpoint must be defined using @navios/builder's `declareMultipart` method.
|
|
1265
|
+
*
|
|
1266
|
+
* @param endpoint - The multipart endpoint declaration from @navios/builder
|
|
1267
|
+
* @returns A method decorator
|
|
1268
|
+
*
|
|
1269
|
+
* @example
|
|
1270
|
+
* ```typescript
|
|
1271
|
+
* const uploadFileEndpoint = api.declareMultipart({
|
|
1272
|
+
* method: 'post',
|
|
1273
|
+
* url: '/upload',
|
|
1274
|
+
* requestSchema: z.object({ file: z.instanceof(File) }),
|
|
1275
|
+
* responseSchema: z.object({ url: z.string() }),
|
|
1276
|
+
* })
|
|
1277
|
+
*
|
|
1278
|
+
* @Controller()
|
|
1279
|
+
* export class FileController {
|
|
1280
|
+
* @Multipart(uploadFileEndpoint)
|
|
1281
|
+
* async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
|
|
1282
|
+
* const { file } = request.data
|
|
1283
|
+
* // Handle file upload
|
|
1284
|
+
* return { url: 'https://example.com/file.jpg' }
|
|
1285
|
+
* }
|
|
1286
|
+
* }
|
|
1287
|
+
* ```
|
|
1288
|
+
*/
|
|
1289
|
+
declare function Multipart<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
|
|
1290
|
+
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
1291
|
+
}): (target: (params: QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z$1.input<ResponseSchema>>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z$1.input<ResponseSchema>>;
|
|
1292
|
+
//#endregion
|
|
1293
|
+
//#region src/decorators/stream.decorator.d.mts
|
|
1294
|
+
/**
|
|
1295
|
+
* Extracts the typed parameters for a stream endpoint handler function.
|
|
1296
|
+
*
|
|
1297
|
+
* Similar to `EndpointParams`, but specifically for streaming endpoints.
|
|
1298
|
+
*
|
|
1299
|
+
* @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder
|
|
1300
|
+
*/
|
|
1301
|
+
type StreamParams<EndpointDeclaration extends {
|
|
1302
|
+
config: BaseStreamConfig<any, any, any, any>;
|
|
1303
|
+
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
|
|
1304
|
+
/**
|
|
1305
|
+
* Decorator that marks a method as a streaming endpoint.
|
|
1306
|
+
*
|
|
1307
|
+
* Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
|
|
1308
|
+
* The endpoint must be defined using @navios/builder's `declareStream` method.
|
|
1309
|
+
*
|
|
1310
|
+
* @param endpoint - The stream endpoint declaration from @navios/builder
|
|
1311
|
+
* @returns A method decorator
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```typescript
|
|
1315
|
+
* const downloadFileEndpoint = api.declareStream({
|
|
1316
|
+
* method: 'get',
|
|
1317
|
+
* url: '/files/$fileId',
|
|
1318
|
+
* })
|
|
1319
|
+
*
|
|
1320
|
+
* @Controller()
|
|
1321
|
+
* export class FileController {
|
|
1322
|
+
* @Stream(downloadFileEndpoint)
|
|
1323
|
+
* async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
|
|
1324
|
+
* const { fileId } = request.urlParams
|
|
1325
|
+
* // Stream file data to reply
|
|
1326
|
+
* }
|
|
1327
|
+
* }
|
|
1328
|
+
* ```
|
|
1329
|
+
*/
|
|
1330
|
+
declare function Stream<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, RequestSchema = ZodType>(endpoint: {
|
|
1331
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
1332
|
+
}): (target: (params: QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>, reply: any) => Promise<void>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>, reply: any) => Promise<void>;
|
|
1333
|
+
//#endregion
|
|
1334
|
+
//#region src/decorators/use-guards.decorator.d.mts
|
|
1335
|
+
/**
|
|
1336
|
+
* Decorator that applies guards to a controller or endpoint.
|
|
1337
|
+
*
|
|
1338
|
+
* Guards are used for authentication, authorization, and request validation.
|
|
1339
|
+
* They implement the `CanActivate` interface and are executed before the endpoint handler.
|
|
1340
|
+
* Guards can be applied at the module, controller, or endpoint level.
|
|
1341
|
+
*
|
|
1342
|
+
* @param guards - Guard classes or injection tokens to apply
|
|
1343
|
+
* @returns A class or method decorator
|
|
1344
|
+
*
|
|
1345
|
+
* @example
|
|
1346
|
+
* ```typescript
|
|
1347
|
+
* // Apply to a controller
|
|
1348
|
+
* @Controller()
|
|
1349
|
+
* @UseGuards(AuthGuard, RoleGuard)
|
|
1350
|
+
* export class UserController {
|
|
1351
|
+
* @Endpoint(getUserEndpoint)
|
|
1352
|
+
* async getUser() { }
|
|
1353
|
+
* }
|
|
1354
|
+
*
|
|
1355
|
+
* // Apply to a specific endpoint
|
|
1356
|
+
* @Controller()
|
|
1357
|
+
* export class UserController {
|
|
1358
|
+
* @Endpoint(getUserEndpoint)
|
|
1359
|
+
* @UseGuards(AuthGuard)
|
|
1360
|
+
* async getUser() { }
|
|
1361
|
+
* }
|
|
1362
|
+
* ```
|
|
1363
|
+
*/
|
|
1364
|
+
declare function UseGuards(...guards: (ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>)[]): <T extends Function>(target: T, context: ClassMethodDecoratorContext | ClassDecoratorContext) => T;
|
|
1365
|
+
//#endregion
|
|
1366
|
+
//#region src/exceptions/http.exception.d.mts
|
|
1367
|
+
/**
|
|
1368
|
+
* Base exception class for all HTTP exceptions in Navios.
|
|
1369
|
+
*
|
|
1370
|
+
* All HTTP exception classes extend this base class. When thrown from an endpoint handler,
|
|
1371
|
+
* Navios will automatically convert it to an appropriate HTTP response with the specified
|
|
1372
|
+
* status code and response body.
|
|
1373
|
+
*
|
|
1374
|
+
* @example
|
|
1375
|
+
* ```typescript
|
|
1376
|
+
* @Endpoint(getUserEndpoint)
|
|
1377
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
1378
|
+
* const user = await this.userService.findById(request.urlParams.userId)
|
|
1379
|
+
* if (!user) {
|
|
1380
|
+
* throw new HttpException(404, 'User not found')
|
|
1381
|
+
* }
|
|
1382
|
+
* return user
|
|
1383
|
+
* }
|
|
1384
|
+
* ```
|
|
1385
|
+
*/
|
|
1386
|
+
declare class HttpException {
|
|
1387
|
+
readonly statusCode: number;
|
|
1388
|
+
readonly response: string | object;
|
|
1389
|
+
readonly error?: Error | undefined;
|
|
1390
|
+
/**
|
|
1391
|
+
* Creates a new HttpException instance.
|
|
1392
|
+
*
|
|
1393
|
+
* @param statusCode - HTTP status code (e.g., 400, 404, 500)
|
|
1394
|
+
* @param response - Response body (string or object)
|
|
1395
|
+
* @param error - Optional underlying error for logging/debugging
|
|
1396
|
+
*/
|
|
1397
|
+
constructor(statusCode: number, response: string | object, error?: Error | undefined);
|
|
1398
|
+
}
|
|
1399
|
+
//#endregion
|
|
1400
|
+
//#region src/exceptions/bad-request.exception.d.mts
|
|
1401
|
+
/**
|
|
1402
|
+
* Exception that represents a 400 Bad Request HTTP error.
|
|
1403
|
+
*
|
|
1404
|
+
* Use this exception when the client's request is malformed or invalid.
|
|
1405
|
+
*
|
|
1406
|
+
* @example
|
|
1407
|
+
* ```typescript
|
|
1408
|
+
* @Endpoint(createUserEndpoint)
|
|
1409
|
+
* async createUser(request: EndpointParams<typeof createUserEndpoint>) {
|
|
1410
|
+
* if (!request.data.email) {
|
|
1411
|
+
* throw new BadRequestException('Email is required')
|
|
1412
|
+
* }
|
|
1413
|
+
* // ...
|
|
1414
|
+
* }
|
|
1415
|
+
* ```
|
|
1416
|
+
*/
|
|
1417
|
+
declare class BadRequestException extends HttpException {
|
|
1418
|
+
/**
|
|
1419
|
+
* Creates a new BadRequestException.
|
|
1420
|
+
*
|
|
1421
|
+
* @param message - Error message or response object
|
|
1422
|
+
*/
|
|
1423
|
+
constructor(message: string | object);
|
|
1424
|
+
}
|
|
1425
|
+
//#endregion
|
|
1426
|
+
//#region src/exceptions/forbidden.exception.d.mts
|
|
1427
|
+
/**
|
|
1428
|
+
* Exception that represents a 403 Forbidden HTTP error.
|
|
1429
|
+
*
|
|
1430
|
+
* Use this exception when the client is authenticated but does not have
|
|
1431
|
+
* permission to access the requested resource.
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```typescript
|
|
1435
|
+
* @Endpoint(deleteUserEndpoint)
|
|
1436
|
+
* @UseGuards(AuthGuard, RoleGuard)
|
|
1437
|
+
* async deleteUser(request: EndpointParams<typeof deleteUserEndpoint>) {
|
|
1438
|
+
* if (!this.userService.hasPermission(request.user, 'delete')) {
|
|
1439
|
+
* throw new ForbiddenException('Insufficient permissions')
|
|
1440
|
+
* }
|
|
1441
|
+
* // ...
|
|
1442
|
+
* }
|
|
1443
|
+
* ```
|
|
1444
|
+
*/
|
|
1445
|
+
declare class ForbiddenException extends HttpException {
|
|
1446
|
+
/**
|
|
1447
|
+
* Creates a new ForbiddenException.
|
|
1448
|
+
*
|
|
1449
|
+
* @param message - Error message
|
|
1450
|
+
*/
|
|
1451
|
+
constructor(message: string);
|
|
1452
|
+
}
|
|
1453
|
+
//#endregion
|
|
1454
|
+
//#region src/exceptions/internal-server-error.exception.d.mts
|
|
1455
|
+
/**
|
|
1456
|
+
* Exception that represents a 500 Internal Server Error HTTP error.
|
|
1457
|
+
*
|
|
1458
|
+
* Use this exception when an unexpected error occurs on the server.
|
|
1459
|
+
* Generally, you should let unhandled errors bubble up rather than catching
|
|
1460
|
+
* and rethrowing as InternalServerErrorException, as Navios will handle them appropriately.
|
|
1461
|
+
*
|
|
1462
|
+
* @example
|
|
1463
|
+
* ```typescript
|
|
1464
|
+
* @Endpoint(processPaymentEndpoint)
|
|
1465
|
+
* async processPayment(request: EndpointParams<typeof processPaymentEndpoint>) {
|
|
1466
|
+
* try {
|
|
1467
|
+
* return await this.paymentService.process(request.data)
|
|
1468
|
+
* } catch (error) {
|
|
1469
|
+
* this.logger.error('Payment processing failed', error)
|
|
1470
|
+
* throw new InternalServerErrorException('Payment processing failed', error)
|
|
1471
|
+
* }
|
|
1472
|
+
* }
|
|
1473
|
+
* ```
|
|
1474
|
+
*/
|
|
1475
|
+
declare class InternalServerErrorException extends HttpException {
|
|
1476
|
+
/**
|
|
1477
|
+
* Creates a new InternalServerErrorException.
|
|
1478
|
+
*
|
|
1479
|
+
* @param message - Error message or response object
|
|
1480
|
+
* @param error - Optional underlying error for logging
|
|
1481
|
+
*/
|
|
1482
|
+
constructor(message: string | object, error?: Error);
|
|
1483
|
+
}
|
|
1484
|
+
//#endregion
|
|
1485
|
+
//#region src/exceptions/not-found.exception.d.mts
|
|
1486
|
+
/**
|
|
1487
|
+
* Exception that represents a 404 Not Found HTTP error.
|
|
1488
|
+
*
|
|
1489
|
+
* Use this exception when the requested resource does not exist.
|
|
1490
|
+
*
|
|
1491
|
+
* @example
|
|
1492
|
+
* ```typescript
|
|
1493
|
+
* @Endpoint(getUserEndpoint)
|
|
1494
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
1495
|
+
* const user = await this.userService.findById(request.urlParams.userId)
|
|
1496
|
+
* if (!user) {
|
|
1497
|
+
* throw new NotFoundException('User not found')
|
|
1498
|
+
* }
|
|
1499
|
+
* return user
|
|
1500
|
+
* }
|
|
1501
|
+
* ```
|
|
1502
|
+
*/
|
|
1503
|
+
declare class NotFoundException extends HttpException {
|
|
1504
|
+
readonly response: string | object;
|
|
1505
|
+
readonly error?: Error | undefined;
|
|
1506
|
+
/**
|
|
1507
|
+
* Creates a new NotFoundException.
|
|
1508
|
+
*
|
|
1509
|
+
* @param response - Error message or response object
|
|
1510
|
+
* @param error - Optional underlying error for logging
|
|
1511
|
+
*/
|
|
1512
|
+
constructor(response: string | object, error?: Error | undefined);
|
|
1513
|
+
}
|
|
1514
|
+
//#endregion
|
|
1515
|
+
//#region src/exceptions/unauthorized.exception.d.mts
|
|
1516
|
+
/**
|
|
1517
|
+
* Exception that represents a 401 Unauthorized HTTP error.
|
|
1518
|
+
*
|
|
1519
|
+
* Use this exception when the client is not authenticated or authentication failed.
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```typescript
|
|
1523
|
+
* @Endpoint(getUserEndpoint)
|
|
1524
|
+
* @UseGuards(AuthGuard)
|
|
1525
|
+
* async getUser(request: EndpointParams<typeof getUserEndpoint>) {
|
|
1526
|
+
* if (!request.headers.authorization) {
|
|
1527
|
+
* throw new UnauthorizedException('Authentication required')
|
|
1528
|
+
* }
|
|
1529
|
+
* // ...
|
|
1530
|
+
* }
|
|
1531
|
+
* ```
|
|
1532
|
+
*/
|
|
1533
|
+
declare class UnauthorizedException extends HttpException {
|
|
1534
|
+
/**
|
|
1535
|
+
* Creates a new UnauthorizedException.
|
|
1536
|
+
*
|
|
1537
|
+
* @param message - Error message or response object
|
|
1538
|
+
* @param error - Optional underlying error for logging
|
|
1539
|
+
*/
|
|
1540
|
+
constructor(message: string | object, error?: Error);
|
|
1541
|
+
}
|
|
1542
|
+
//#endregion
|
|
1543
|
+
//#region src/exceptions/conflict.exception.d.mts
|
|
1544
|
+
/**
|
|
1545
|
+
* Exception that represents a 409 Conflict HTTP error.
|
|
1546
|
+
*
|
|
1547
|
+
* Use this exception when the request conflicts with the current state of the resource
|
|
1548
|
+
* (e.g., trying to create a resource that already exists).
|
|
1549
|
+
*
|
|
1550
|
+
* @example
|
|
1551
|
+
* ```typescript
|
|
1552
|
+
* @Endpoint(createUserEndpoint)
|
|
1553
|
+
* async createUser(request: EndpointParams<typeof createUserEndpoint>) {
|
|
1554
|
+
* const existing = await this.userService.findByEmail(request.data.email)
|
|
1555
|
+
* if (existing) {
|
|
1556
|
+
* throw new ConflictException('User with this email already exists')
|
|
1557
|
+
* }
|
|
1558
|
+
* // ...
|
|
1559
|
+
* }
|
|
1560
|
+
* ```
|
|
1561
|
+
*/
|
|
1562
|
+
declare class ConflictException extends HttpException {
|
|
1563
|
+
/**
|
|
1564
|
+
* Creates a new ConflictException.
|
|
1565
|
+
*
|
|
1566
|
+
* @param message - Error message or response object
|
|
1567
|
+
* @param error - Optional underlying error for logging
|
|
1568
|
+
*/
|
|
1569
|
+
constructor(message: string | object, error?: Error);
|
|
1570
|
+
}
|
|
1571
|
+
//#endregion
|
|
1572
|
+
//#region src/services/guard-runner.service.d.mts
|
|
1573
|
+
declare class GuardRunnerService {
|
|
1574
|
+
private readonly logger;
|
|
1575
|
+
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
1576
|
+
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
1577
|
+
}
|
|
1578
|
+
//#endregion
|
|
1579
|
+
//#region src/stores/request-id.store.d.mts
|
|
1580
|
+
/**
|
|
1581
|
+
* AsyncLocalStorage store for the current request ID.
|
|
1582
|
+
*
|
|
1583
|
+
* This allows logging and other services to access the current request ID
|
|
1584
|
+
* without explicitly passing it through the call stack.
|
|
1585
|
+
*
|
|
1586
|
+
* @example
|
|
1587
|
+
* ```typescript
|
|
1588
|
+
* import { requestIdStore, runWithRequestId, getRequestId } from '@navios/core'
|
|
1589
|
+
*
|
|
1590
|
+
* // Run code with a request ID in context
|
|
1591
|
+
* runWithRequestId('req-123', () => {
|
|
1592
|
+
* // Inside this callback, getRequestId() returns 'req-123'
|
|
1593
|
+
* logger.log('Processing request') // Will include request ID if logger is configured
|
|
1594
|
+
* })
|
|
1595
|
+
*
|
|
1596
|
+
* // Get current request ID (returns undefined if not in a request context)
|
|
1597
|
+
* const currentId = getRequestId()
|
|
1598
|
+
* ```
|
|
1599
|
+
*/
|
|
1600
|
+
declare const requestIdStore: AsyncLocalStorage<string>;
|
|
1601
|
+
/**
|
|
1602
|
+
* Runs a function with a request ID in the async local storage context.
|
|
1603
|
+
*
|
|
1604
|
+
* @param requestId - The request ID to set for this context
|
|
1605
|
+
* @param fn - The function to run within this context
|
|
1606
|
+
* @returns The return value of the function
|
|
1607
|
+
*/
|
|
1608
|
+
declare function runWithRequestId<R>(requestId: string, fn: () => R): R;
|
|
1609
|
+
/**
|
|
1610
|
+
* Gets the current request ID from the async local storage context.
|
|
1611
|
+
*
|
|
1612
|
+
* @returns The current request ID, or undefined if not in a request context
|
|
1613
|
+
*/
|
|
1614
|
+
declare function getRequestId(): string | undefined;
|
|
1615
|
+
//#endregion
|
|
1616
|
+
//#region src/tokens/endpoint-adapter.token.d.mts
|
|
1617
|
+
declare const EndpointAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1618
|
+
//#endregion
|
|
1619
|
+
//#region src/tokens/execution-context.token.d.mts
|
|
1620
|
+
declare const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
1621
|
+
declare const ExecutionContext: InjectionToken<AbstractExecutionContext, undefined, false>;
|
|
1622
|
+
//#endregion
|
|
1623
|
+
//#region src/tokens/http-adapter.token.d.mts
|
|
1624
|
+
declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<any, any, any, any>, undefined, false>;
|
|
1625
|
+
//#endregion
|
|
1626
|
+
//#region src/tokens/multipart-adapter.token.d.mts
|
|
1627
|
+
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1628
|
+
//#endregion
|
|
1629
|
+
//#region src/tokens/reply.token.d.mts
|
|
1630
|
+
declare const Reply: InjectionToken<any, undefined, false>;
|
|
1631
|
+
//#endregion
|
|
1632
|
+
//#region src/tokens/request.token.d.mts
|
|
1633
|
+
declare const Request: InjectionToken<any, undefined, false>;
|
|
1634
|
+
//#endregion
|
|
1635
|
+
//#region src/tokens/stream-adapter.token.d.mts
|
|
1636
|
+
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1637
|
+
//#endregion
|
|
1638
|
+
//#region src/tokens/xml-stream-adapter.token.d.mts
|
|
1639
|
+
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1640
|
+
//#endregion
|
|
1641
|
+
//#region src/attribute.factory.d.mts
|
|
1642
|
+
/**
|
|
1643
|
+
* Type for a class attribute decorator without a value.
|
|
1644
|
+
*
|
|
1645
|
+
* Attributes are custom metadata decorators that can be applied to modules,
|
|
1646
|
+
* controllers, and endpoints.
|
|
1647
|
+
*/
|
|
1648
|
+
type ClassAttribute = (() => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
|
|
1649
|
+
token: symbol;
|
|
1650
|
+
};
|
|
1651
|
+
/**
|
|
1652
|
+
* Type for a class attribute decorator with a validated value.
|
|
1653
|
+
*
|
|
1654
|
+
* @typeParam T - The Zod schema type for validation
|
|
1655
|
+
*/
|
|
1656
|
+
type ClassSchemaAttribute<T extends ZodType> = ((value: z$1.input<T>) => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
|
|
1657
|
+
token: symbol;
|
|
1658
|
+
schema: ZodType;
|
|
1659
|
+
};
|
|
1660
|
+
/**
|
|
1661
|
+
* Factory for creating custom attribute decorators.
|
|
1662
|
+
*
|
|
1663
|
+
* Attributes allow you to add custom metadata to modules, controllers, and endpoints.
|
|
1664
|
+
* This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
|
|
1665
|
+
*
|
|
1666
|
+
* @example
|
|
1667
|
+
* ```typescript
|
|
1668
|
+
* // Create a simple boolean attribute
|
|
1669
|
+
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
1670
|
+
*
|
|
1671
|
+
* // Use it as a decorator
|
|
1672
|
+
* @Controller()
|
|
1673
|
+
* @Public()
|
|
1674
|
+
* export class PublicController { }
|
|
1675
|
+
*
|
|
1676
|
+
* // Check if attribute exists
|
|
1677
|
+
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
1678
|
+
* // Skip authentication
|
|
1679
|
+
* }
|
|
1680
|
+
* ```
|
|
1681
|
+
*
|
|
1682
|
+
* @example
|
|
1683
|
+
* ```typescript
|
|
1684
|
+
* // Create an attribute with a validated value
|
|
1685
|
+
* const RateLimit = AttributeFactory.createAttribute(
|
|
1686
|
+
* Symbol.for('RateLimit'),
|
|
1687
|
+
* z.object({ requests: z.number(), window: z.number() })
|
|
1688
|
+
* )
|
|
1689
|
+
*
|
|
1690
|
+
* // Use it with a value
|
|
1691
|
+
* @Endpoint(apiEndpoint)
|
|
1692
|
+
* @RateLimit({ requests: 100, window: 60000 })
|
|
1693
|
+
* async handler() { }
|
|
1694
|
+
*
|
|
1695
|
+
* // Get the value
|
|
1696
|
+
* const limit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
1697
|
+
* // limit is typed as { requests: number, window: number } | null
|
|
1698
|
+
* ```
|
|
1699
|
+
*/
|
|
1700
|
+
declare class AttributeFactory {
|
|
1701
|
+
/**
|
|
1702
|
+
* Creates a simple attribute decorator without a value.
|
|
1703
|
+
*
|
|
1704
|
+
* @param token - A unique symbol to identify this attribute
|
|
1705
|
+
* @returns A decorator function that can be applied to classes or methods
|
|
1706
|
+
*
|
|
1707
|
+
* @example
|
|
1708
|
+
* ```typescript
|
|
1709
|
+
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
1710
|
+
*
|
|
1711
|
+
* @Public()
|
|
1712
|
+
* @Controller()
|
|
1713
|
+
* export class PublicController { }
|
|
1714
|
+
* ```
|
|
1715
|
+
*/
|
|
1716
|
+
static createAttribute(token: symbol): ClassAttribute;
|
|
1717
|
+
/**
|
|
1718
|
+
* Creates an attribute decorator with a validated value.
|
|
1719
|
+
*
|
|
1720
|
+
* @param token - A unique symbol to identify this attribute
|
|
1721
|
+
* @param schema - A Zod schema to validate the attribute value
|
|
1722
|
+
* @returns A decorator function that accepts a value and can be applied to classes or methods
|
|
1723
|
+
*
|
|
1724
|
+
* @example
|
|
1725
|
+
* ```typescript
|
|
1726
|
+
* const RateLimit = AttributeFactory.createAttribute(
|
|
1727
|
+
* Symbol.for('RateLimit'),
|
|
1728
|
+
* z.object({ requests: z.number(), window: z.number() })
|
|
1729
|
+
* )
|
|
1730
|
+
*
|
|
1731
|
+
* @RateLimit({ requests: 100, window: 60000 })
|
|
1732
|
+
* @Endpoint(apiEndpoint)
|
|
1733
|
+
* async handler() { }
|
|
1734
|
+
* ```
|
|
1735
|
+
*/
|
|
1736
|
+
static createAttribute<T extends ZodType>(token: symbol, schema: T): ClassSchemaAttribute<T>;
|
|
1737
|
+
/**
|
|
1738
|
+
* Gets the value of an attribute from metadata.
|
|
1739
|
+
*
|
|
1740
|
+
* Returns `null` if the attribute is not present.
|
|
1741
|
+
* For simple attributes (without values), returns `true` if present.
|
|
1742
|
+
*
|
|
1743
|
+
* @param attribute - The attribute decorator
|
|
1744
|
+
* @param target - The metadata object (module, controller, or handler)
|
|
1745
|
+
* @returns The attribute value, `true` for simple attributes, or `null` if not found
|
|
1746
|
+
*
|
|
1747
|
+
* @example
|
|
1748
|
+
* ```typescript
|
|
1749
|
+
* const isPublic = AttributeFactory.get(Public, controllerMetadata)
|
|
1750
|
+
* // isPublic is true | null
|
|
1751
|
+
*
|
|
1752
|
+
* const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
1753
|
+
* // rateLimit is { requests: number, window: number } | null
|
|
1754
|
+
* ```
|
|
1755
|
+
*/
|
|
1756
|
+
static get(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): true | null;
|
|
1757
|
+
static get<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): z$1.output<T> | null;
|
|
1758
|
+
/**
|
|
1759
|
+
* Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
|
|
1760
|
+
*
|
|
1761
|
+
* Returns `null` if the attribute is not present.
|
|
1762
|
+
*
|
|
1763
|
+
* @param attribute - The attribute decorator
|
|
1764
|
+
* @param target - The metadata object (module, controller, or handler)
|
|
1765
|
+
* @returns An array of attribute values, or `null` if not found
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* ```typescript
|
|
1769
|
+
* const tags = AttributeFactory.getAll(Tag, endpointMetadata)
|
|
1770
|
+
* // tags is string[] | null
|
|
1771
|
+
* ```
|
|
1772
|
+
*/
|
|
1773
|
+
static getAll(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<true> | null;
|
|
1774
|
+
static getAll<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<z$1.output<T>> | null;
|
|
1775
|
+
/**
|
|
1776
|
+
* Gets the last value of an attribute from an array of metadata objects.
|
|
1777
|
+
*
|
|
1778
|
+
* Searches from the end of the array backwards, useful for finding the most
|
|
1779
|
+
* specific attribute value (e.g., endpoint-level overrides module-level).
|
|
1780
|
+
*
|
|
1781
|
+
* @param attribute - The attribute decorator
|
|
1782
|
+
* @param target - An array of metadata objects (typically [module, controller, handler])
|
|
1783
|
+
* @returns The last attribute value found, or `null` if not found
|
|
1784
|
+
*
|
|
1785
|
+
* @example
|
|
1786
|
+
* ```typescript
|
|
1787
|
+
* // Check attribute hierarchy: endpoint -> controller -> module
|
|
1788
|
+
* const rateLimit = AttributeFactory.getLast(RateLimit, [
|
|
1789
|
+
* moduleMetadata,
|
|
1790
|
+
* controllerMetadata,
|
|
1791
|
+
* endpointMetadata
|
|
1792
|
+
* ])
|
|
1793
|
+
* ```
|
|
1794
|
+
*/
|
|
1795
|
+
static getLast(attribute: ClassAttribute, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): true | null;
|
|
1796
|
+
static getLast<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): z$1.output<T> | null;
|
|
1797
|
+
/**
|
|
1798
|
+
* Checks if an attribute is present on the metadata object.
|
|
1799
|
+
*
|
|
1800
|
+
* @param attribute - The attribute decorator
|
|
1801
|
+
* @param target - The metadata object (module, controller, or handler)
|
|
1802
|
+
* @returns `true` if the attribute is present, `false` otherwise
|
|
1803
|
+
*
|
|
1804
|
+
* @example
|
|
1805
|
+
* ```typescript
|
|
1806
|
+
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
1807
|
+
* // Skip authentication
|
|
1808
|
+
* }
|
|
1809
|
+
* ```
|
|
1810
|
+
*/
|
|
1811
|
+
static has(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
1812
|
+
static has<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
1813
|
+
}
|
|
1814
|
+
//#endregion
|
|
1815
|
+
//#region src/factories/endpoint-adapter.factory.d.mts
|
|
1816
|
+
declare class EndpointAdapterFactory {
|
|
1817
|
+
private readonly environment;
|
|
1818
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1819
|
+
}
|
|
1820
|
+
//#endregion
|
|
1821
|
+
//#region src/factories/http-adapter.factory.d.mts
|
|
1822
|
+
declare class HttpAdapterFactory {
|
|
1823
|
+
private readonly environment;
|
|
1824
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1825
|
+
}
|
|
1826
|
+
//#endregion
|
|
1827
|
+
//#region src/factories/multipart-adapter.factory.d.mts
|
|
1828
|
+
declare class MultipartAdapterFactory {
|
|
1829
|
+
private readonly environment;
|
|
1830
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1831
|
+
}
|
|
1832
|
+
//#endregion
|
|
1833
|
+
//#region src/factories/request.factory.d.mts
|
|
1834
|
+
declare class RequestFactory {
|
|
1835
|
+
private readonly environment;
|
|
1836
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1837
|
+
}
|
|
1838
|
+
//#endregion
|
|
1839
|
+
//#region src/factories/reply.factory.d.mts
|
|
1840
|
+
declare class ReplyFactory {
|
|
1841
|
+
private readonly environment;
|
|
1842
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1843
|
+
}
|
|
1844
|
+
//#endregion
|
|
1845
|
+
//#region src/factories/stream-adapter.factory.d.mts
|
|
1846
|
+
declare class StreamAdapterFactory {
|
|
1847
|
+
private readonly environment;
|
|
1848
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1849
|
+
}
|
|
1850
|
+
//#endregion
|
|
1851
|
+
//#region src/factories/xml-stream-adapter.factory.d.mts
|
|
1852
|
+
declare class XmlStreamAdapterFactory {
|
|
1853
|
+
private readonly environment;
|
|
1854
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
1855
|
+
}
|
|
1856
|
+
//#endregion
|
|
1857
|
+
//#region src/navios.environment.d.mts
|
|
1858
|
+
interface NaviosEnvironmentOptions {
|
|
1859
|
+
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>;
|
|
1860
|
+
}
|
|
1861
|
+
//#endregion
|
|
1862
|
+
//#region src/navios.application.d.mts
|
|
1863
|
+
/**
|
|
1864
|
+
* Options for configuring the Navios application context.
|
|
1865
|
+
* These options control dependency injection and logging behavior.
|
|
1866
|
+
*/
|
|
1867
|
+
interface NaviosApplicationContextOptions {
|
|
1868
|
+
/**
|
|
1869
|
+
* Specifies the logger to use. Pass `false` to turn off logging.
|
|
1870
|
+
*
|
|
1871
|
+
* - `LoggerService` instance: Use a custom logger implementation
|
|
1872
|
+
* - `LogLevel[]`: Enable specific log levels (e.g., ['error', 'warn', 'log'])
|
|
1873
|
+
* - `false`: Disable logging completely
|
|
1874
|
+
*/
|
|
1875
|
+
logger?: LoggerService | LogLevel[] | false;
|
|
1876
|
+
/**
|
|
1877
|
+
* Specifies a custom container to use. Useful for testing.
|
|
1878
|
+
* If not provided, a new Container will be created.
|
|
1879
|
+
*/
|
|
1880
|
+
container?: Container;
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Complete options for creating a Navios application.
|
|
1884
|
+
* Extends NaviosApplicationContextOptions with adapter configuration.
|
|
1885
|
+
*/
|
|
1886
|
+
interface NaviosApplicationOptions extends NaviosApplicationContextOptions {
|
|
1887
|
+
/**
|
|
1888
|
+
* HTTP adapter environment(s) to use for the application.
|
|
1889
|
+
* Can be a single adapter or an array of adapters.
|
|
1890
|
+
*
|
|
1891
|
+
* @example
|
|
1892
|
+
* ```typescript
|
|
1893
|
+
* adapter: defineFastifyEnvironment()
|
|
1894
|
+
* // or
|
|
1895
|
+
* adapter: [defineFastifyEnvironment(), defineBunEnvironment()]
|
|
1896
|
+
* ```
|
|
1897
|
+
*/
|
|
1898
|
+
adapter: NaviosEnvironmentOptions | NaviosEnvironmentOptions[];
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Main application class for Navios.
|
|
1902
|
+
*
|
|
1903
|
+
* This class represents a Navios application instance and provides methods
|
|
1904
|
+
* for initializing, configuring, and managing the HTTP server.
|
|
1905
|
+
*
|
|
1906
|
+
* @example
|
|
1907
|
+
* ```typescript
|
|
1908
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
1909
|
+
* adapter: defineFastifyEnvironment(),
|
|
1910
|
+
* })
|
|
1911
|
+
*
|
|
1912
|
+
* app.setGlobalPrefix('/api')
|
|
1913
|
+
* app.enableCors({ origin: ['http://localhost:3000'] })
|
|
1914
|
+
* await app.init()
|
|
1915
|
+
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
1916
|
+
* ```
|
|
1917
|
+
*/
|
|
1918
|
+
declare class NaviosApplication {
|
|
1919
|
+
private environment;
|
|
1920
|
+
private moduleLoader;
|
|
1921
|
+
private httpApplication;
|
|
1922
|
+
private logger;
|
|
1923
|
+
protected container: Container;
|
|
1924
|
+
private appModule;
|
|
1925
|
+
private options;
|
|
1926
|
+
private plugins;
|
|
1927
|
+
/**
|
|
1928
|
+
* Indicates whether the application has been initialized.
|
|
1929
|
+
* Set to `true` after `init()` completes successfully.
|
|
1930
|
+
*/
|
|
1931
|
+
isInitialized: boolean;
|
|
1932
|
+
/**
|
|
1933
|
+
* Sets up the application with the provided module and options.
|
|
1934
|
+
* This is called automatically by NaviosFactory.create().
|
|
1935
|
+
*
|
|
1936
|
+
* @param appModule - The root application module
|
|
1937
|
+
* @param options - Application configuration options
|
|
1938
|
+
* @internal
|
|
1939
|
+
*/
|
|
1940
|
+
setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<void>;
|
|
1941
|
+
/**
|
|
1942
|
+
* Gets the dependency injection container used by this application.
|
|
1943
|
+
*
|
|
1944
|
+
* @returns The Container instance
|
|
1945
|
+
*/
|
|
1946
|
+
getContainer(): Container;
|
|
1947
|
+
/**
|
|
1948
|
+
* Registers a plugin to be initialized after modules are loaded.
|
|
1949
|
+
*
|
|
1950
|
+
* Plugins are initialized in the order they are registered,
|
|
1951
|
+
* after all modules are loaded but before the server starts listening.
|
|
1952
|
+
*
|
|
1953
|
+
* @param definition - Plugin definition with options
|
|
1954
|
+
* @returns this for method chaining
|
|
1955
|
+
*
|
|
1956
|
+
* @example
|
|
1957
|
+
* ```typescript
|
|
1958
|
+
* import { defineOpenApiPlugin } from '@navios/openapi-fastify'
|
|
1959
|
+
*
|
|
1960
|
+
* app.usePlugin(defineOpenApiPlugin({
|
|
1961
|
+
* info: { title: 'My API', version: '1.0.0' },
|
|
1962
|
+
* }))
|
|
1963
|
+
* ```
|
|
1964
|
+
*/
|
|
1965
|
+
usePlugin<TOptions>(definition: PluginDefinition<TOptions>): this;
|
|
1966
|
+
/**
|
|
1967
|
+
* Initializes the application.
|
|
1968
|
+
*
|
|
1969
|
+
* This method:
|
|
1970
|
+
* - Loads all modules and their dependencies
|
|
1971
|
+
* - Sets up the HTTP server if an adapter is configured
|
|
1972
|
+
* - Calls onModuleInit hooks on all modules
|
|
1973
|
+
* - Initializes registered plugins
|
|
1974
|
+
* - Marks the application as initialized
|
|
1975
|
+
*
|
|
1976
|
+
* Must be called before `listen()`.
|
|
1977
|
+
*
|
|
1978
|
+
* @throws Error if app module is not set
|
|
1979
|
+
*
|
|
1980
|
+
* @example
|
|
1981
|
+
* ```typescript
|
|
1982
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
1983
|
+
* adapter: defineFastifyEnvironment(),
|
|
1984
|
+
* })
|
|
1985
|
+
* await app.init()
|
|
1986
|
+
* await app.listen({ port: 3000 })
|
|
1987
|
+
* ```
|
|
1988
|
+
*/
|
|
1989
|
+
init(): Promise<void>;
|
|
1990
|
+
private initModules;
|
|
1991
|
+
private initPlugins;
|
|
1992
|
+
/**
|
|
1993
|
+
* Enables CORS (Cross-Origin Resource Sharing) for the application.
|
|
1994
|
+
*
|
|
1995
|
+
* @param options - CORS configuration options (adapter-specific)
|
|
1996
|
+
* @throws Error if HTTP application is not set
|
|
1997
|
+
*
|
|
1998
|
+
* @example
|
|
1999
|
+
* ```typescript
|
|
2000
|
+
* app.enableCors({
|
|
2001
|
+
* origin: ['http://localhost:3000', 'https://example.com'],
|
|
2002
|
+
* methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
2003
|
+
* credentials: true,
|
|
2004
|
+
* })
|
|
2005
|
+
* ```
|
|
2006
|
+
*/
|
|
2007
|
+
enableCors(options: any): void;
|
|
2008
|
+
/**
|
|
2009
|
+
* Enables multipart/form-data support for file uploads.
|
|
2010
|
+
*
|
|
2011
|
+
* @param options - Multipart configuration options (adapter-specific)
|
|
2012
|
+
* @throws Error if HTTP application is not set
|
|
2013
|
+
*
|
|
2014
|
+
* @example
|
|
2015
|
+
* ```typescript
|
|
2016
|
+
* app.enableMultipart({
|
|
2017
|
+
* limits: {
|
|
2018
|
+
* fileSize: 1024 * 1024 * 10, // 10MB
|
|
2019
|
+
* },
|
|
2020
|
+
* })
|
|
2021
|
+
* ```
|
|
2022
|
+
*/
|
|
2023
|
+
enableMultipart(options: any): void;
|
|
2024
|
+
/**
|
|
2025
|
+
* Sets a global prefix for all routes.
|
|
2026
|
+
*
|
|
2027
|
+
* @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
|
|
2028
|
+
* @throws Error if HTTP application is not set
|
|
2029
|
+
*
|
|
2030
|
+
* @example
|
|
2031
|
+
* ```typescript
|
|
2032
|
+
* app.setGlobalPrefix('/api/v1')
|
|
2033
|
+
* // All routes will be prefixed with /api/v1
|
|
2034
|
+
* ```
|
|
2035
|
+
*/
|
|
2036
|
+
setGlobalPrefix(prefix: string): void;
|
|
2037
|
+
/**
|
|
2038
|
+
* Gets the underlying HTTP server instance.
|
|
2039
|
+
*
|
|
2040
|
+
* The type of the returned server depends on the adapter used:
|
|
2041
|
+
* - Fastify adapter: Returns FastifyInstance
|
|
2042
|
+
* - Bun adapter: Returns Bun.Server
|
|
2043
|
+
*
|
|
2044
|
+
* @returns The HTTP server instance
|
|
2045
|
+
* @throws Error if HTTP application is not set
|
|
2046
|
+
*
|
|
2047
|
+
* @example
|
|
2048
|
+
* ```typescript
|
|
2049
|
+
* const server = app.getServer()
|
|
2050
|
+
* // Use adapter-specific server methods
|
|
2051
|
+
* ```
|
|
2052
|
+
*/
|
|
2053
|
+
getServer(): any;
|
|
2054
|
+
/**
|
|
2055
|
+
* Starts the HTTP server and begins listening for requests.
|
|
2056
|
+
*
|
|
2057
|
+
* @param options - Listen options (port, host, etc.)
|
|
2058
|
+
* @throws Error if HTTP application is not set
|
|
2059
|
+
*
|
|
2060
|
+
* @example
|
|
2061
|
+
* ```typescript
|
|
2062
|
+
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
2063
|
+
* ```
|
|
2064
|
+
*/
|
|
2065
|
+
listen(options: AbstractHttpListenOptions): Promise<void>;
|
|
2066
|
+
/**
|
|
2067
|
+
* Disposes of application resources.
|
|
2068
|
+
*
|
|
2069
|
+
* Cleans up the HTTP server and module loader.
|
|
2070
|
+
* This method is called automatically by `close()`.
|
|
2071
|
+
*/
|
|
2072
|
+
dispose(): Promise<void>;
|
|
2073
|
+
/**
|
|
2074
|
+
* Closes the application and cleans up all resources.
|
|
2075
|
+
*
|
|
2076
|
+
* This is an alias for `dispose()`.
|
|
2077
|
+
*
|
|
2078
|
+
* @example
|
|
2079
|
+
* ```typescript
|
|
2080
|
+
* // Graceful shutdown
|
|
2081
|
+
* process.on('SIGTERM', async () => {
|
|
2082
|
+
* await app.close()
|
|
2083
|
+
* process.exit(0)
|
|
2084
|
+
* })
|
|
2085
|
+
* ```
|
|
2086
|
+
*/
|
|
2087
|
+
close(): Promise<void>;
|
|
2088
|
+
}
|
|
2089
|
+
//#endregion
|
|
2090
|
+
//#region src/navios.factory.d.mts
|
|
2091
|
+
/**
|
|
2092
|
+
* Factory class for creating and configuring Navios applications.
|
|
2093
|
+
*
|
|
2094
|
+
* This is the main entry point for bootstrapping a Navios application.
|
|
2095
|
+
* It handles dependency injection container setup, adapter registration,
|
|
2096
|
+
* and logger configuration.
|
|
2097
|
+
*
|
|
2098
|
+
* @example
|
|
2099
|
+
* ```typescript
|
|
2100
|
+
* import { NaviosFactory } from '@navios/core'
|
|
2101
|
+
* import { defineFastifyEnvironment } from '@navios/adapter-fastify'
|
|
2102
|
+
*
|
|
2103
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
2104
|
+
* adapter: defineFastifyEnvironment(),
|
|
2105
|
+
* logger: ['log', 'error', 'warn'],
|
|
2106
|
+
* })
|
|
2107
|
+
*
|
|
2108
|
+
* await app.init()
|
|
2109
|
+
* await app.listen({ port: 3000 })
|
|
2110
|
+
* ```
|
|
2111
|
+
*/
|
|
2112
|
+
declare class NaviosFactory {
|
|
2113
|
+
/**
|
|
2114
|
+
* Creates a new Navios application instance.
|
|
2115
|
+
*
|
|
2116
|
+
* This method sets up the dependency injection container, registers the HTTP adapter,
|
|
2117
|
+
* configures logging, and initializes the application with the provided module.
|
|
2118
|
+
*
|
|
2119
|
+
* @param appModule - The root application module class decorated with @Module()
|
|
2120
|
+
* @param options - Configuration options for the application
|
|
2121
|
+
* @param options.adapter - HTTP adapter environment (required for HTTP server functionality)
|
|
2122
|
+
* @param options.logger - Logger configuration. Can be:
|
|
2123
|
+
* - A LoggerService instance for custom logging
|
|
2124
|
+
* - An array of LogLevel strings to enable specific log levels
|
|
2125
|
+
* - `false` to disable logging
|
|
2126
|
+
* @param options.container - Optional custom dependency injection container (useful for testing)
|
|
2127
|
+
* @returns A configured NaviosApplication instance ready to be initialized
|
|
2128
|
+
*
|
|
2129
|
+
* @example
|
|
2130
|
+
* ```typescript
|
|
2131
|
+
* // Basic setup with Fastify adapter
|
|
2132
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
2133
|
+
* adapter: defineFastifyEnvironment(),
|
|
2134
|
+
* })
|
|
2135
|
+
*
|
|
2136
|
+
* // With custom logger configuration
|
|
2137
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
2138
|
+
* adapter: defineFastifyEnvironment(),
|
|
2139
|
+
* logger: ['error', 'warn', 'log'],
|
|
2140
|
+
* })
|
|
2141
|
+
*
|
|
2142
|
+
* // With custom container for testing
|
|
2143
|
+
* const container = new Container()
|
|
2144
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
2145
|
+
* adapter: defineFastifyEnvironment(),
|
|
2146
|
+
* container,
|
|
2147
|
+
* })
|
|
2148
|
+
* ```
|
|
2149
|
+
*/
|
|
2150
|
+
static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<NaviosApplication>;
|
|
2151
|
+
private static registerEnvironment;
|
|
2152
|
+
private static registerLoggerConfiguration;
|
|
2153
|
+
}
|
|
2154
|
+
//#endregion
|
|
2155
|
+
export { CanActivate as $, EnvConfigProvider as $t, NotFoundException as A, clc as At, MultipartResult as B, extractControllerMetadata as Bt, EndpointAdapterToken as C, normalizePath as Ct, GuardRunnerService as D, filterLogLevels as Dt, runWithRequestId as E, isLogLevel as Et, UseGuards as F, extractModuleMetadata as Ft, NaviosPlugin as G, getAllEndpointMetadata as Gt, ModuleOptions as H, hasControllerMetadata as Ht, Stream as I, getModuleMetadata as It, ModuleExtension as J, EndpointParams as Jt, PluginContext as K, getEndpointMetadata as Kt, StreamParams as L, hasModuleMetadata as Lt, ForbiddenException as M, AbstractExecutionContext as Mt, BadRequestException as N, ModuleMetadata as Nt, ConflictException as O, LOG_LEVELS as Ot, HttpException as P, ModuleMetadataKey as Pt, OmitIndexSignature as Q, ConfigProviderOptions as Qt, Multipart as R, ControllerMetadata as Rt, ExecutionContextInjectionToken as S, isUndefined as St, requestIdStore as T, isLogLevelEnabled as Tt, HttpCode as U, EndpointMetadataKey as Ut, Module as V, getControllerMetadata as Vt, Header as W, HandlerMetadata as Wt, NaviosModule as X, Controller as Xt, ModuleLoaderService as Y, EndpointResult as Yt, HttpHeader as Z, ControllerOptions as Zt, Request as _, isNumber as _t, XmlStreamAdapterFactory as a, ConfigServiceInterface as an, LoggerOptions as at, HttpAdapterToken as b, isString as bt, RequestFactory as c, PathImpl2 as cn, LoggerInstance as ct, EndpointAdapterFactory as d, envString as dn, LoggerService as dt, provideConfig as en, AbstractHttpHandlerAdapterInterface as et, AttributeFactory as f, addLeadingSlash as ft, StreamAdapterToken as g, isNil as gt, XmlStreamAdapterToken as h, isFunction as ht, NaviosApplicationOptions as i, ConfigServiceToken as in, Logger as it, InternalServerErrorException as j, yellow as jt, UnauthorizedException as k, LogLevel as kt, MultipartAdapterFactory as l, PathValue as ln, ConsoleLogger as lt, ClassSchemaAttribute as m, isEmpty as mt, NaviosApplication as n, ConfigServiceOptions as nn, AbstractHttpListenOptions as nt, StreamAdapterFactory as o, Path as on, LoggerOutput as ot, ClassAttribute as p, isConstructor as pt, PluginDefinition as q, Endpoint as qt, NaviosApplicationContextOptions as r, ConfigServiceOptionsSchema as rn, AbstractHttpCorsOptions as rt, ReplyFactory as s, PathImpl as sn, loggerOptionsSchema as st, NaviosFactory as t, ConfigService as tn, AbstractHttpAdapterInterface as tt, HttpAdapterFactory as u, envInt as un, ConsoleLoggerOptions as ut, Reply as v, isObject as vt, getRequestId as w, stripEndSlash as wt, ExecutionContext as x, isSymbol as xt, MultipartAdapterToken as y, isPlainObject as yt, MultipartParams as z, ControllerMetadataKey as zt };
|
|
2156
|
+
//# sourceMappingURL=index-DW9EPAE6.d.mts.map
|