@navios/core 1.0.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -11
- package/README.md +67 -220
- package/lib/async-context-6pdlnNLA.d.mts +237 -0
- package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
- package/lib/async-context-Dqk7pE-D.d.cts +237 -0
- package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
- package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
- package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
- package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
- package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
- package/lib/attribute-value-DMEA255r.mjs +119 -0
- package/lib/attribute-value-DMEA255r.mjs.map +1 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
- package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
- package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
- package/lib/execution-context-BPD3FeFb.d.mts +71 -0
- package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
- package/lib/execution-context-BTJdHhbf.d.cts +71 -0
- package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
- package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
- package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
- package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
- package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
- package/lib/index.cjs +1687 -4409
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +838 -3
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +838 -3
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +1573 -4219
- package/lib/index.mjs.map +1 -1
- package/lib/legacy-compat/index.cjs +72 -371
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +42 -382
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +41 -382
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +51 -345
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/module-Bha7GER_.mjs +135 -0
- package/lib/module-Bha7GER_.mjs.map +1 -0
- package/lib/module-DZewk_2r.cjs +164 -0
- package/lib/module-DZewk_2r.cjs.map +1 -0
- package/lib/module-graph-DCP9MHG0.cjs +147 -0
- package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
- package/lib/module-graph-xvVEykFM.mjs +142 -0
- package/lib/module-graph-xvVEykFM.mjs.map +1 -0
- package/lib/module-metadata-C8S92seK.cjs +95 -0
- package/lib/module-metadata-C8S92seK.cjs.map +1 -0
- package/lib/module-metadata-k3RTt20x.mjs +66 -0
- package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
- package/lib/module-options-Dmse0gii.d.mts +51 -0
- package/lib/module-options-Dmse0gii.d.mts.map +1 -0
- package/lib/module-options-IuDO-p8u.d.cts +51 -0
- package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
- package/lib/testing/index.cjs +96 -414
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +25 -385
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +24 -385
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +94 -408
- package/lib/testing/index.mjs.map +1 -1
- package/lib/transport.cjs +25 -0
- package/lib/transport.d.cts +190 -0
- package/lib/transport.d.cts.map +1 -0
- package/lib/transport.d.mts +190 -0
- package/lib/transport.d.mts.map +1 -0
- package/lib/transport.mjs +7 -0
- package/package.json +37 -17
- package/docs/README.md +0 -316
- package/docs/adapters.md +0 -308
- package/docs/application-setup.md +0 -524
- package/docs/attributes.md +0 -689
- package/docs/controllers.md +0 -373
- package/docs/endpoints.md +0 -444
- package/docs/exceptions.md +0 -352
- package/docs/guards.md +0 -550
- package/docs/legacy-compat.md +0 -356
- package/docs/modules.md +0 -377
- package/docs/quick-start.md +0 -290
- package/docs/services.md +0 -427
- package/docs/testing.md +0 -827
- package/lib/index-C0Sg16Eb.d.cts +0 -3365
- package/lib/index-C0Sg16Eb.d.cts.map +0 -1
- package/lib/index-DySQ6Dpd.d.mts +0 -3365
- package/lib/index-DySQ6Dpd.d.mts.map +0 -1
- package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
- package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
- package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
- package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
- package/lib/tokens-4J9sredA.mjs +0 -100
- package/lib/tokens-4J9sredA.mjs.map +0 -1
- package/lib/tokens-CWw9kyeD.cjs +0 -196
- package/lib/tokens-CWw9kyeD.cjs.map +0 -1
- package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
- package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
- package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
- package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
- package/project.json +0 -66
- package/src/__tests__/attribute.factory.spec.mts +0 -300
- package/src/__tests__/config.service.spec.mts +0 -43
- package/src/__tests__/console-logger.service.spec.mts +0 -312
- package/src/__tests__/controller-resolver.spec.mts +0 -229
- package/src/__tests__/controller.spec.mts +0 -58
- package/src/__tests__/guard-runner.service.spec.mts +0 -399
- package/src/__tests__/logger.service.spec.mts +0 -147
- package/src/__tests__/responders.spec.mts +0 -340
- package/src/__tests__/testing-module.spec.mts +0 -459
- package/src/__tests__/unit-testing-module.spec.mts +0 -424
- package/src/attribute.factory.mts +0 -325
- package/src/config/config-service.interface.mts +0 -47
- package/src/config/config.provider.mts +0 -69
- package/src/config/config.service.mts +0 -176
- package/src/config/index.mts +0 -5
- package/src/config/types.mts +0 -58
- package/src/config/utils/helpers.mts +0 -23
- package/src/config/utils/index.mts +0 -1
- package/src/decorators/controller.decorator.mts +0 -81
- package/src/decorators/endpoint.decorator.mts +0 -181
- package/src/decorators/header.decorator.mts +0 -38
- package/src/decorators/http-code.decorator.mts +0 -38
- package/src/decorators/index.mts +0 -8
- package/src/decorators/module.decorator.mts +0 -106
- package/src/decorators/multipart.decorator.mts +0 -169
- package/src/decorators/stream.decorator.mts +0 -155
- package/src/decorators/use-guards.decorator.mts +0 -73
- package/src/exceptions/bad-request.exception.mts +0 -28
- package/src/exceptions/conflict.exception.mts +0 -31
- package/src/exceptions/forbidden.exception.mts +0 -30
- package/src/exceptions/http.exception.mts +0 -33
- package/src/exceptions/index.mts +0 -7
- package/src/exceptions/internal-server-error.exception.mts +0 -33
- package/src/exceptions/not-found.exception.mts +0 -33
- package/src/exceptions/unauthorized.exception.mts +0 -30
- package/src/factories/adapter.factory.mts +0 -20
- package/src/factories/endpoint-adapter.factory.mts +0 -21
- package/src/factories/http-adapter.factory.mts +0 -20
- package/src/factories/index.mts +0 -8
- package/src/factories/multipart-adapter.factory.mts +0 -21
- package/src/factories/reply.factory.mts +0 -21
- package/src/factories/request.factory.mts +0 -21
- package/src/factories/stream-adapter.factory.mts +0 -20
- package/src/factories/xml-stream-adapter.factory.mts +0 -20
- package/src/index.mts +0 -16
- package/src/interfaces/abstract-adapter.interface.mts +0 -32
- package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
- package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
- package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
- package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
- package/src/interfaces/adapter-environment.interface.mts +0 -74
- package/src/interfaces/can-activate.mts +0 -38
- package/src/interfaces/http-header.mts +0 -18
- package/src/interfaces/index.mts +0 -11
- package/src/interfaces/navios-module.mts +0 -28
- package/src/interfaces/plugin.interface.mts +0 -139
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
- package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
- package/src/legacy-compat/attribute.factory.mts +0 -351
- package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
- package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
- package/src/legacy-compat/decorators/header.decorator.mts +0 -43
- package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
- package/src/legacy-compat/decorators/index.mts +0 -11
- package/src/legacy-compat/decorators/module.decorator.mts +0 -37
- package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
- package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
- package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
- package/src/legacy-compat/index.mts +0 -57
- package/src/logger/README.md +0 -3
- package/src/logger/console-logger.service.mts +0 -714
- package/src/logger/index.mts +0 -6
- package/src/logger/log-levels.mts +0 -21
- package/src/logger/logger-service.interface.mts +0 -42
- package/src/logger/logger.service.mts +0 -113
- package/src/logger/logger.tokens.mts +0 -44
- package/src/logger/utils/cli-colors.util.mts +0 -17
- package/src/logger/utils/filter-log-levelts.util.mts +0 -29
- package/src/logger/utils/index.mts +0 -5
- package/src/logger/utils/is-log-level-enabled.mts +0 -33
- package/src/logger/utils/is-log-level.util.mts +0 -10
- package/src/logger/utils/shared.utils.mts +0 -51
- package/src/metadata/controller.metadata.mts +0 -72
- package/src/metadata/handler.metadata.mts +0 -80
- package/src/metadata/index.mts +0 -4
- package/src/metadata/module.metadata.mts +0 -108
- package/src/metadata/navios-managed.metadata.mts +0 -42
- package/src/navios.application.mts +0 -484
- package/src/navios.environment.mts +0 -42
- package/src/navios.factory.mts +0 -158
- package/src/responders/enums/framework-error.enum.mts +0 -38
- package/src/responders/enums/index.mts +0 -1
- package/src/responders/index.mts +0 -4
- package/src/responders/interfaces/error-responder.interface.mts +0 -42
- package/src/responders/interfaces/error-response.interface.mts +0 -22
- package/src/responders/interfaces/index.mts +0 -3
- package/src/responders/interfaces/problem-details.interface.mts +0 -34
- package/src/responders/services/error-response-producer.service.mts +0 -143
- package/src/responders/services/forbidden-responder.service.mts +0 -77
- package/src/responders/services/index.mts +0 -5
- package/src/responders/services/internal-server-error-responder.service.mts +0 -57
- package/src/responders/services/not-found-responder.service.mts +0 -76
- package/src/responders/services/validation-error-responder.service.mts +0 -78
- package/src/responders/tokens/index.mts +0 -1
- package/src/responders/tokens/responder.tokens.mts +0 -84
- package/src/services/abstract-handler-adapter.service.mts +0 -366
- package/src/services/guard-runner.service.mts +0 -152
- package/src/services/index.mts +0 -4
- package/src/services/instance-resolver.service.mts +0 -177
- package/src/services/module-loader.service.mts +0 -252
- package/src/stores/index.mts +0 -1
- package/src/stores/request-id.store.mts +0 -85
- package/src/testing/index.mts +0 -3
- package/src/testing/testing-module.mts +0 -393
- package/src/testing/unit-testing-module.mts +0 -298
- package/src/tokens/adapter.token.mts +0 -6
- package/src/tokens/endpoint-adapter.token.mts +0 -8
- package/src/tokens/execution-context.token.mts +0 -9
- package/src/tokens/http-adapter.token.mts +0 -8
- package/src/tokens/index.mts +0 -10
- package/src/tokens/multipart-adapter.token.mts +0 -8
- package/src/tokens/navios-options.token.mts +0 -6
- package/src/tokens/reply.token.mts +0 -3
- package/src/tokens/request.token.mts +0 -3
- package/src/tokens/stream-adapter.token.mts +0 -8
- package/src/tokens/xml-stream-adapter.token.mts +0 -8
- package/src/utils/adapter-supports.util.mts +0 -47
- package/src/utils/index.mts +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -8
- package/tsconfig.spec.json +0 -15
- package/tsdown.config.mts +0 -35
- package/vitest.config.mts +0 -15
package/lib/index.d.mts
CHANGED
|
@@ -1,3 +1,838 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* What an application is made of whatever reaches it: dependency injection,
|
|
3
|
+
* modules, plugins, lifecycle, configuration, logging, and the contracts a
|
|
4
|
+
* transport builds on. Nothing here knows about HTTP; that is
|
|
5
|
+
* `@navios/server`.
|
|
6
|
+
*/
|
|
7
|
+
import { AnyInjectableType, AsyncResolve, BoundInjectionToken, ClassType, ClassType as ClassType$1, ClassTypeWithInstance, Container, Container as Container$1, ContainerOptions, DIError, DIErrorCode, Factorable, FactorableWithArgs, Factory, FactoryContext, FactoryInjectionToken, FactoryOptions, IContainer, InferInput, InferOutput, InferOutput as InferOutput$1, Injectable, InjectableOptions, InjectableScope, InjectionToken, InjectionToken as InjectionToken$1, InjectionTokenOptions, InjectionTokenType, OnServiceDestroy, OnServiceInit, OptionalResolve, Provider, Provider as Provider$1, ProviderInfo, ProviderInput, RegisterFactoryOptions, RegisterInjectableOptions, RegisterProviderOptions, ResolvedInstance, ScopedContainer, StandardSchemaIssue, StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1, SyncResolve, asyncInject, getInjectableToken, inject, optional, provide, registerFactory, registerInjectable, registerProvider } from "@navios/di";
|
|
8
|
+
import { a as Interceptor, i as AttributeValue, n as Guard, o as InterceptorClass, r as GuardClass, t as ModuleOptions } from "./module-options-Dmse0gii.mjs";
|
|
9
|
+
import { _ as LoggerService, b as filterLogLevels, c as TransportInstance, g as LoggerOutput, h as OptionsArgument, i as Transport, o as TransportFactory, t as currentContext, v as LOG_LEVELS, x as isLogLevel, y as LogLevel } from "./async-context-6pdlnNLA.mjs";
|
|
10
|
+
import { i as ClassSchemaAttribute, n as AttributeFactory, r as ClassAttribute, t as AttributeApplication } from "./attribute-factory-mKOXoVnV.mjs";
|
|
11
|
+
import { a as ContextValue, i as ContextKey, n as ExecutionContext, o as PlainContextKey, r as HandlerInfo, s as createContextKey, t as AttributeMap } from "./execution-context-BPD3FeFb.mjs";
|
|
12
|
+
import { InspectOptions } from "util";
|
|
13
|
+
/**
|
|
14
|
+
* Schema for logger options.
|
|
15
|
+
*/
|
|
16
|
+
type LoggerOptions = {
|
|
17
|
+
context?: string;
|
|
18
|
+
} | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Injection token for the Logger service.
|
|
21
|
+
*
|
|
22
|
+
* Use this token to inject a contextualized logger instance.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const logger = inject(Logger, { context: 'MyService' })
|
|
27
|
+
* logger.log('Hello world') // Logs with context: [MyService]
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const Logger: InjectionToken$1<LoggerInstance, import("@navios/di").StandardSchemaV1<LoggerOptions, LoggerOptions>, false>;
|
|
31
|
+
/**
|
|
32
|
+
* Logger service instance that can be injected into services and controllers.
|
|
33
|
+
*
|
|
34
|
+
* Provides contextualized logging with automatic context injection.
|
|
35
|
+
* The context is set when the logger is injected using the `inject` function.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* @Injectable()
|
|
40
|
+
* export class UserService {
|
|
41
|
+
* private logger = inject(Logger, { context: UserService.name })
|
|
42
|
+
*
|
|
43
|
+
* async findUser(id: string) {
|
|
44
|
+
* this.logger.log(`Finding user ${id}`)
|
|
45
|
+
* // Logs with context: [UserService]
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare class LoggerInstance implements LoggerService {
|
|
51
|
+
protected localInstance: LoggerService;
|
|
52
|
+
protected context?: string;
|
|
53
|
+
constructor(config?: LoggerOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Write an 'error' level log.
|
|
56
|
+
*/
|
|
57
|
+
error(message: any, stack?: string, context?: string): void;
|
|
58
|
+
error(message: any, ...optionalParams: [...any, string?, string?]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Write a 'log' level log.
|
|
61
|
+
*/
|
|
62
|
+
log(message: any, context?: string): void;
|
|
63
|
+
log(message: any, ...optionalParams: [...any, string?]): void;
|
|
64
|
+
/**
|
|
65
|
+
* Write a 'warn' level log.
|
|
66
|
+
*/
|
|
67
|
+
warn(message: any, context?: string): void;
|
|
68
|
+
warn(message: any, ...optionalParams: [...any, string?]): void;
|
|
69
|
+
/**
|
|
70
|
+
* Write a 'debug' level log.
|
|
71
|
+
*/
|
|
72
|
+
debug(message: any, context?: string): void;
|
|
73
|
+
debug(message: any, ...optionalParams: [...any, string?]): void;
|
|
74
|
+
/**
|
|
75
|
+
* Write a 'verbose' level log.
|
|
76
|
+
*/
|
|
77
|
+
verbose(message: any, context?: string): void;
|
|
78
|
+
verbose(message: any, ...optionalParams: [...any, string?]): void;
|
|
79
|
+
/**
|
|
80
|
+
* Write a 'fatal' level log.
|
|
81
|
+
*/
|
|
82
|
+
fatal(message: any, context?: string): void;
|
|
83
|
+
fatal(message: any, ...optionalParams: [...any, string?]): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What a plugin can do. Everything but `transport()` and `container` belongs
|
|
87
|
+
* into `setup`: afterwards it throws, because it could not take effect.
|
|
88
|
+
* `provide` and `decorate` apply at once, the rest at its point of `init()`.
|
|
89
|
+
*/
|
|
90
|
+
interface PluginApi {
|
|
91
|
+
readonly container: Container$1;
|
|
92
|
+
/**
|
|
93
|
+
* Supplies a provider. It wins over the providers of modules and over the
|
|
94
|
+
* default of the token. What the application itself provides, with its
|
|
95
|
+
* `providers` option or in its container, stays.
|
|
96
|
+
*/
|
|
97
|
+
readonly provide: Container$1['provide'];
|
|
98
|
+
/** Wraps every instance of a service after it is built. */
|
|
99
|
+
readonly decorate: Container$1['decorate'];
|
|
100
|
+
/** Adds an interceptor around every handler, on every transport. */
|
|
101
|
+
intercept(interceptor: InterceptorClass): void;
|
|
102
|
+
/**
|
|
103
|
+
* Adds a module, and so its handlers, to the application. What it provides
|
|
104
|
+
* is a default: the modules of the application override it.
|
|
105
|
+
*/
|
|
106
|
+
addModule(module: ClassType$1): void;
|
|
107
|
+
/**
|
|
108
|
+
* One of the application's transports, already created, or `undefined`
|
|
109
|
+
* when the application has none of this kind. What only one transport
|
|
110
|
+
* offers is reached through it.
|
|
111
|
+
*/
|
|
112
|
+
transport<T extends Transport>(factory: TransportFactory<any, T>, instanceName?: string): T | undefined;
|
|
113
|
+
/** Runs after every transport is set up and before any starts. */
|
|
114
|
+
onBootstrap(hook: () => void | Promise<void>): void;
|
|
115
|
+
/** Runs when the application closes, in reverse registration order. */
|
|
116
|
+
onShutdown(hook: (signal?: string) => void | Promise<void>): void;
|
|
117
|
+
}
|
|
118
|
+
interface PluginDefinition<Options = void> {
|
|
119
|
+
/**
|
|
120
|
+
* Unique name. One plugin registered twice with equal options is applied
|
|
121
|
+
* once; anything else under one name is an error.
|
|
122
|
+
*/
|
|
123
|
+
name: string;
|
|
124
|
+
/** Names of plugins that must be set up before this one. */
|
|
125
|
+
dependsOn?: string[];
|
|
126
|
+
setup(api: PluginApi, options: Options): void | Promise<void>;
|
|
127
|
+
}
|
|
128
|
+
interface PluginInstance {
|
|
129
|
+
readonly definition: PluginDefinition<any>;
|
|
130
|
+
/** `{}` when the plugin was given none. */
|
|
131
|
+
readonly options: unknown;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Defines a plugin.
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* export const tracing = definePlugin({
|
|
138
|
+
* name: 'tracing',
|
|
139
|
+
* setup(api, options: { serviceName: string }) {
|
|
140
|
+
* api.intercept(TracingInterceptor)
|
|
141
|
+
* api.onShutdown(() => flush())
|
|
142
|
+
* },
|
|
143
|
+
* })
|
|
144
|
+
*
|
|
145
|
+
* app.usePlugin(tracing({ serviceName: 'api' }))
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function definePlugin<Options = void>(definition: PluginDefinition<Options>): (...options: OptionsArgument<Options>) => PluginInstance;
|
|
149
|
+
interface ApplicationOptions {
|
|
150
|
+
/** How work reaches the application. None is valid, for a process that does its work in hooks. */
|
|
151
|
+
transports?: TransportInstance[];
|
|
152
|
+
/**
|
|
153
|
+
* Providers that replace or supply defaults, application-wide. They win over
|
|
154
|
+
* those of plugins and modules.
|
|
155
|
+
*/
|
|
156
|
+
providers?: Provider$1[];
|
|
157
|
+
plugins?: PluginInstance[];
|
|
158
|
+
/**
|
|
159
|
+
* Use an existing container instead of creating one. It backs one open
|
|
160
|
+
* application at a time, and `close()` disposes it. What it provides, or
|
|
161
|
+
* already holds because it was put there, wins over everything else: a test
|
|
162
|
+
* replaces a service by binding it there.
|
|
163
|
+
*/
|
|
164
|
+
container?: Container$1;
|
|
165
|
+
/**
|
|
166
|
+
* `false` disables logging, an array selects the levels of the console
|
|
167
|
+
* logger or of the output that is provided instead, and an object is used as
|
|
168
|
+
* the output.
|
|
169
|
+
*/
|
|
170
|
+
logger?: LoggerService | LogLevel[] | false;
|
|
171
|
+
/**
|
|
172
|
+
* Keep the current execution context in an `AsyncLocalStorage`, so that
|
|
173
|
+
* `currentContext()` works in code that cannot receive it as an argument.
|
|
174
|
+
* @default false
|
|
175
|
+
*/
|
|
176
|
+
asyncContext?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* What happens when a handler uses a service that is not a singleton through
|
|
179
|
+
* `ctx.use()` / `ctx.resolve()`, which needs a DI scope for the execution:
|
|
180
|
+
* nothing, a warning the first time, or an error.
|
|
181
|
+
* @default 'warn' outside production, 'allow' in production
|
|
182
|
+
*/
|
|
183
|
+
requestScopedServices?: 'allow' | 'warn' | 'forbid';
|
|
184
|
+
/**
|
|
185
|
+
* How long `close()` waits, in milliseconds: for work in flight, and for
|
|
186
|
+
* each further step, such as one shutdown hook. A step that takes longer is
|
|
187
|
+
* reported and left behind.
|
|
188
|
+
* @default 10000
|
|
189
|
+
*/
|
|
190
|
+
shutdownTimeout?: number;
|
|
191
|
+
}
|
|
192
|
+
interface ShutdownHooksOptions {
|
|
193
|
+
/**
|
|
194
|
+
* Whether the signal ends the process once every application has closed,
|
|
195
|
+
* as it would have without a listener. It does not when something else in
|
|
196
|
+
* the process listens to the signal.
|
|
197
|
+
* @default true
|
|
198
|
+
*/
|
|
199
|
+
exit?: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* An application: a module tree, one container, and the transports through
|
|
203
|
+
* which work reaches it.
|
|
204
|
+
*
|
|
205
|
+
* ```ts
|
|
206
|
+
* const app = createApplication(AppModule, {
|
|
207
|
+
* transports: [queueTransport({ url })],
|
|
208
|
+
* })
|
|
209
|
+
* await app.start()
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export declare class Application {
|
|
213
|
+
private readonly appModule;
|
|
214
|
+
private readonly applicationOptions;
|
|
215
|
+
readonly container: Container$1;
|
|
216
|
+
protected logger: LoggerInstance;
|
|
217
|
+
private readonly plugins;
|
|
218
|
+
private readonly slots;
|
|
219
|
+
private readonly extraModules;
|
|
220
|
+
private readonly globalInterceptors;
|
|
221
|
+
private readonly bootstrapHooks;
|
|
222
|
+
private readonly shutdownHooks;
|
|
223
|
+
/** What modules and plugins provide. Everything else is the caller's. */
|
|
224
|
+
private readonly supplied;
|
|
225
|
+
/** For the log, once there is one. */
|
|
226
|
+
private readonly notes;
|
|
227
|
+
/** What loggers write to until it is settled where the log goes. */
|
|
228
|
+
private pendingOutput;
|
|
229
|
+
private transportsCreated;
|
|
230
|
+
private settingUpPlugins;
|
|
231
|
+
private initialised;
|
|
232
|
+
private initialisation;
|
|
233
|
+
private startup;
|
|
234
|
+
private closed;
|
|
235
|
+
private closing;
|
|
236
|
+
private tearingDown;
|
|
237
|
+
private signal;
|
|
238
|
+
constructor(appModule: ClassType$1, applicationOptions?: ApplicationOptions);
|
|
239
|
+
/** Supplies what an option provides, unless the given container does. */
|
|
240
|
+
private provideOption;
|
|
241
|
+
/** Tells what nobody else receives. Never throws. */
|
|
242
|
+
private report;
|
|
243
|
+
private assertConfigurable;
|
|
244
|
+
usePlugin(plugin: PluginInstance): this;
|
|
245
|
+
/** Adds an interceptor around every handler, on every transport. */
|
|
246
|
+
intercept(interceptor: InterceptorClass): this;
|
|
247
|
+
get: Container$1['get'];
|
|
248
|
+
/**
|
|
249
|
+
* One of the application's transports. Transports are created by `init()`.
|
|
250
|
+
* Throws when the application has no such transport; `findTransport`
|
|
251
|
+
* returns `undefined` instead.
|
|
252
|
+
*/
|
|
253
|
+
transport<T extends Transport>(factory: TransportFactory<any, T>, instanceName?: string): T;
|
|
254
|
+
/** Like `transport`, but `undefined` when there is none, or not yet. */
|
|
255
|
+
findTransport<T extends Transport>(factory: TransportFactory<any, T>, instanceName?: string): T | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* Builds the application: transports, plugins, modules and each
|
|
258
|
+
* transport's handlers. Runs once, however often and from wherever it is
|
|
259
|
+
* called; every caller gets the outcome of that run. Only a hook that the
|
|
260
|
+
* run itself waits for cannot call it.
|
|
261
|
+
*
|
|
262
|
+
* An application that fails to initialise is closed before this rejects, and
|
|
263
|
+
* stays failed, because it is only partly built.
|
|
264
|
+
*/
|
|
265
|
+
init(): Promise<this>;
|
|
266
|
+
private assertOpen;
|
|
267
|
+
/**
|
|
268
|
+
* Rejects when the application has been closed, after that shutdown has
|
|
269
|
+
* finished: the process may end when the caller fails.
|
|
270
|
+
*/
|
|
271
|
+
protected assertStillOpen(): Promise<void>;
|
|
272
|
+
/** Calls code that the application waits for. */
|
|
273
|
+
private step;
|
|
274
|
+
/** A shutdown does not wait for a start-up that hangs; that one ends here. */
|
|
275
|
+
private assertNotTornDown;
|
|
276
|
+
private initialise;
|
|
277
|
+
/**
|
|
278
|
+
* Nothing may be left half-open when the start-up fails: what was created
|
|
279
|
+
* holds what it acquired, and background work would go on.
|
|
280
|
+
*/
|
|
281
|
+
private tearDownFailed;
|
|
282
|
+
private build;
|
|
283
|
+
/**
|
|
284
|
+
* Whether the caller provides a token: with the options of the application
|
|
285
|
+
* or in its container, where an instance may also have been put.
|
|
286
|
+
*/
|
|
287
|
+
private isProvidedByCaller;
|
|
288
|
+
/**
|
|
289
|
+
* Supplies what the modules provide, unless the application or a plugin
|
|
290
|
+
* provides it. Modules that disagree about a token are an error where one of
|
|
291
|
+
* them would have to be used, which is settled after the plugins.
|
|
292
|
+
*/
|
|
293
|
+
private applyModuleProviders;
|
|
294
|
+
private settleLogger;
|
|
295
|
+
/** What was logged so far is not lost, whatever becomes of the start-up. */
|
|
296
|
+
private settleLoggerNow;
|
|
297
|
+
private configureOutput;
|
|
298
|
+
private setupPlugins;
|
|
299
|
+
private pluginApi;
|
|
300
|
+
/**
|
|
301
|
+
* Initialises the application if needed, then starts every transport, in
|
|
302
|
+
* the order they were listed. A transport is started at most once, however
|
|
303
|
+
* often this is called. An application whose transports do not all start is
|
|
304
|
+
* closed before this rejects.
|
|
305
|
+
*
|
|
306
|
+
* Called from something `init()` waits for, it starts the application
|
|
307
|
+
* afterwards and returns a promise that rejects.
|
|
308
|
+
*/
|
|
309
|
+
start(): Promise<this>;
|
|
310
|
+
private startOnce;
|
|
311
|
+
private startTransports;
|
|
312
|
+
private startTransport;
|
|
313
|
+
/**
|
|
314
|
+
* Closes the application when the process receives one of the signals. Call
|
|
315
|
+
* it before `start()`, so that a signal during the start-up is seen.
|
|
316
|
+
*
|
|
317
|
+
* A signal that has a listener no longer ends the process. When everything
|
|
318
|
+
* the signal closes is closed, the process is therefore sent the signal
|
|
319
|
+
* again, or exits with its code when it is process 1, unless `exit` is
|
|
320
|
+
* `false` or something else listens to it. A second signal does not wait for
|
|
321
|
+
* the shutdown, unlike one during a `close()` that the application called.
|
|
322
|
+
*/
|
|
323
|
+
enableShutdownHooks(signals?: NodeJS.Signals[], options?: ShutdownHooksOptions): this;
|
|
324
|
+
/**
|
|
325
|
+
* Shuts down: every transport stops accepting work and waits for what is
|
|
326
|
+
* in flight, shutdown hooks run in reverse order, then the container is
|
|
327
|
+
* disposed, which runs `onServiceDestroy` hooks. Each step gets
|
|
328
|
+
* `shutdownTimeout`; one that takes longer is reported and left behind.
|
|
329
|
+
*
|
|
330
|
+
* Runs once, however often and from wherever it is called, and every caller
|
|
331
|
+
* gets the outcome of that run, with two exceptions, since they would wait
|
|
332
|
+
* for themselves. Called from something the shutdown waits for, it resolves
|
|
333
|
+
* at once. Called from something `init()` or `start()` waits for, it closes
|
|
334
|
+
* the application afterwards and returns a promise that rejects.
|
|
335
|
+
*/
|
|
336
|
+
close(signal?: string): Promise<void>;
|
|
337
|
+
/** Transports are given it, and may add to it, for a timer of theirs. */
|
|
338
|
+
private get shutdownTimeout();
|
|
339
|
+
private shutdown;
|
|
340
|
+
/** Takes down whatever was built so far, once. */
|
|
341
|
+
private teardown;
|
|
342
|
+
private takeDown;
|
|
343
|
+
/**
|
|
344
|
+
* Stops a transport that was created, once, however often and from
|
|
345
|
+
* wherever this is asked for.
|
|
346
|
+
*/
|
|
347
|
+
private stopTransport;
|
|
348
|
+
/** Runs one part of the shutdown. Whatever becomes of it, the rest follows. */
|
|
349
|
+
private shutdownStep;
|
|
350
|
+
private reportTimeout;
|
|
351
|
+
/** Alias of `close()`. */
|
|
352
|
+
dispose(): Promise<void>;
|
|
353
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Creates an application from its root module. Call `init()` to build it, or
|
|
357
|
+
* `start()` to build it and start its transports.
|
|
358
|
+
*/
|
|
359
|
+
export declare function createApplication(appModule: ClassType$1, options?: ApplicationOptions): Application;
|
|
360
|
+
interface OnModuleInit {
|
|
361
|
+
onModuleInit(): void | Promise<void>;
|
|
362
|
+
}
|
|
363
|
+
interface OnApplicationBootstrap {
|
|
364
|
+
onApplicationBootstrap(): void | Promise<void>;
|
|
365
|
+
}
|
|
366
|
+
interface OnApplicationShutdown {
|
|
367
|
+
onApplicationShutdown(signal?: string): void | Promise<void>;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Evaluates to `true` if `T` is `any`. `false` otherwise.
|
|
371
|
+
* (c) https://stackoverflow.com/a/68633327/5290447
|
|
372
|
+
*/
|
|
373
|
+
type IsAny<T> = unknown extends T ? ([keyof T] extends [never] ? false : true) : false;
|
|
374
|
+
/** Objects that are values of a configuration, not sections of it. */
|
|
375
|
+
type ObjectValue = readonly any[] | ((...args: any[]) => any) | Date | RegExp | ReadonlyMap<any, any> | ReadonlySet<any> | PromiseLike<any> | ArrayBufferView;
|
|
376
|
+
/** `T` if it is a section, which has paths of its own; `never` if it is a value. */
|
|
377
|
+
type Section<T> = IsAny<T> extends true ? never : [NonNullable<T>] extends [object] ? [NonNullable<T>] extends [ObjectValue] ? never : NonNullable<T> : never;
|
|
378
|
+
/** Deep enough for a configuration, and an end for a type that contains itself. */
|
|
379
|
+
type MaxDepth = 6;
|
|
380
|
+
type Paths<T, Depth extends unknown[]> = { [Key in keyof T & string]-?: Depth['length'] extends MaxDepth ? Key : Section<T[Key]> extends (infer S) ? [S] extends [never] ? Key : Key | `${Key}.${Paths<S, [...Depth, Key]>}` : never; }[keyof T & string];
|
|
381
|
+
/** The keys of a configuration, and those of its sections: `'database.host'`. */
|
|
382
|
+
type Path<T> = Paths<T, []>;
|
|
383
|
+
type ValueAt<T, P> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? ValueAt<NonNullable<T[Key]>, Rest> | (null extends T[Key] ? undefined : Extract<T[Key], undefined>) : never : P extends keyof T ? T[P] : never;
|
|
384
|
+
/** The type of the value at a path. */
|
|
385
|
+
type PathValue<T, P extends Path<T>> = ValueAt<T, P>;
|
|
386
|
+
/**
|
|
387
|
+
* Interface for configuration service implementations.
|
|
388
|
+
*
|
|
389
|
+
* Provides type-safe access to configuration values with support for nested paths.
|
|
390
|
+
*
|
|
391
|
+
* @typeParam Config - The configuration object type
|
|
392
|
+
*/
|
|
393
|
+
interface ConfigServiceInterface<Config extends object = Record<string, unknown>> {
|
|
394
|
+
/**
|
|
395
|
+
* Gets the entire configuration object.
|
|
396
|
+
*/
|
|
397
|
+
getConfig: () => Config;
|
|
398
|
+
/**
|
|
399
|
+
* Gets a configuration value by key path. Returns `null` if not found.
|
|
400
|
+
*
|
|
401
|
+
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
402
|
+
* @returns The configuration value or `null` if not found
|
|
403
|
+
*/
|
|
404
|
+
get: <Key extends Path<Config>>(key: Key) => NonNullable<PathValue<Config, Key>> | null;
|
|
405
|
+
/**
|
|
406
|
+
* Gets a configuration value by key path, or returns a default value if not found.
|
|
407
|
+
*
|
|
408
|
+
* @param key - Dot-separated path to the configuration value
|
|
409
|
+
* @param defaultValue - Default value to return if the key is not found
|
|
410
|
+
* @returns The configuration value or the default value
|
|
411
|
+
*/
|
|
412
|
+
getOrDefault: <Key extends Path<Config>>(key: Key, defaultValue: NonNullable<PathValue<Config, Key>>) => NonNullable<PathValue<Config, Key>>;
|
|
413
|
+
/**
|
|
414
|
+
* Gets a configuration value by key path, or throws an error if not found.
|
|
415
|
+
*
|
|
416
|
+
* @param key - Dot-separated path to the configuration value
|
|
417
|
+
* @param errorMessage - Optional custom error message
|
|
418
|
+
* @returns The configuration value
|
|
419
|
+
* @throws Error if the key is not found
|
|
420
|
+
*/
|
|
421
|
+
getOrThrow: <Key extends Path<Config>>(key: Key, errorMessage?: string) => NonNullable<PathValue<Config, Key>>;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Service for managing application configuration with type-safe access.
|
|
425
|
+
*
|
|
426
|
+
* Provides methods to access configuration values using dot-notation paths
|
|
427
|
+
* with full TypeScript type inference. `provideConfig()` gives the token of
|
|
428
|
+
* one; `new ConfigService({ ... })` is what a test provides for it.
|
|
429
|
+
*
|
|
430
|
+
* @typeParam Config - The configuration object type
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```typescript
|
|
434
|
+
* interface AppConfig {
|
|
435
|
+
* database: {
|
|
436
|
+
* host: string
|
|
437
|
+
* port: number
|
|
438
|
+
* }
|
|
439
|
+
* api: {
|
|
440
|
+
* timeout: number
|
|
441
|
+
* }
|
|
442
|
+
* }
|
|
443
|
+
*
|
|
444
|
+
* export const AppConfig = provideConfig<AppConfig>({ load: () => readConfig() })
|
|
445
|
+
*
|
|
446
|
+
* @Injectable()
|
|
447
|
+
* export class DatabaseService {
|
|
448
|
+
* private config = inject(AppConfig)
|
|
449
|
+
*
|
|
450
|
+
* connect() {
|
|
451
|
+
* const host = this.config.getOrThrow('database.host')
|
|
452
|
+
* const port = this.config.getOrDefault('database.port', 5432)
|
|
453
|
+
* // host is typed as string, port is typed as number
|
|
454
|
+
* }
|
|
455
|
+
* }
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
export declare class ConfigService<Config extends object = Record<string, unknown>> implements ConfigServiceInterface<Config> {
|
|
459
|
+
private readonly config;
|
|
460
|
+
/**
|
|
461
|
+
* Creates a new ConfigService instance.
|
|
462
|
+
*
|
|
463
|
+
* @param config - The configuration object
|
|
464
|
+
*/
|
|
465
|
+
constructor(config?: Config);
|
|
466
|
+
/**
|
|
467
|
+
* Gets the entire configuration object.
|
|
468
|
+
*
|
|
469
|
+
* @returns The complete configuration object
|
|
470
|
+
*/
|
|
471
|
+
getConfig(): Config;
|
|
472
|
+
/**
|
|
473
|
+
* Gets a configuration value by key path.
|
|
474
|
+
*
|
|
475
|
+
* Returns `null` if the key is not found or if any part of the path is invalid.
|
|
476
|
+
*
|
|
477
|
+
* @param key - Dot-separated path to the configuration value (e.g., 'database.host')
|
|
478
|
+
* @returns The configuration value or `null` if not found
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* const host = config.get('database.host') // string | null
|
|
483
|
+
* const port = config.get('database.port') // number | null
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
get<Key extends Path<Config>>(key: Key): NonNullable<PathValue<Config, Key>> | null;
|
|
487
|
+
/**
|
|
488
|
+
* Gets a configuration value by key path, or returns a default value if not found.
|
|
489
|
+
*
|
|
490
|
+
* @param key - Dot-separated path to the configuration value
|
|
491
|
+
* @param defaultValue - Default value to return if the key is not found
|
|
492
|
+
* @returns The configuration value or the default value
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* const port = config.getOrDefault('database.port', 5432) // number
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
getOrDefault<Key extends Path<Config>>(key: Key, defaultValue: NonNullable<PathValue<Config, Key>>): NonNullable<PathValue<Config, Key>>;
|
|
500
|
+
/**
|
|
501
|
+
* Gets a configuration value by key path, or throws an error if not found.
|
|
502
|
+
*
|
|
503
|
+
* @param key - Dot-separated path to the configuration value
|
|
504
|
+
* @param errorMessage - Optional custom error message
|
|
505
|
+
* @returns The configuration value
|
|
506
|
+
* @throws Error if the key is not found
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```typescript
|
|
510
|
+
* const host = config.getOrThrow('database.host') // string (throws if not found)
|
|
511
|
+
* const apiKey = config.getOrThrow('api.key', 'API key is required') // string
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
getOrThrow<Key extends Path<Config>>(key: Key, errorMessage?: string): NonNullable<PathValue<Config, Key>>;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Reads an integer. A variable that is missing or empty gives the default; one
|
|
518
|
+
* that is not an integer throws, because it is a mistake the default would hide.
|
|
519
|
+
*/
|
|
520
|
+
export declare function envInt(key: keyof NodeJS.ProcessEnv, defaultValue: number): number;
|
|
521
|
+
/** Reads a string. A variable that is missing or empty gives the default. */
|
|
522
|
+
export declare function envString(key: keyof NodeJS.ProcessEnv): string | undefined;
|
|
523
|
+
export declare function envString(key: keyof NodeJS.ProcessEnv, defaultValue: string): string;
|
|
524
|
+
export declare function envString(key: keyof NodeJS.ProcessEnv, defaultValue: string | undefined): string | undefined;
|
|
525
|
+
/**
|
|
526
|
+
* A `ConfigService` holding a snapshot of `process.env`, taken when a
|
|
527
|
+
* container first resolves it.
|
|
528
|
+
*/
|
|
529
|
+
export declare const EnvConfigProvider: InjectionToken$1<ConfigService<Record<string, string | undefined>>, undefined>;
|
|
530
|
+
interface ConfigProviderOptions<ConfigMap extends object> {
|
|
531
|
+
/** Names the token, for errors. @default 'Config' */
|
|
532
|
+
name?: string;
|
|
533
|
+
/** Loads the raw configuration. */
|
|
534
|
+
load: () => ConfigMap | Promise<ConfigMap>;
|
|
535
|
+
}
|
|
536
|
+
interface ValidatedConfigProviderOptions<Schema extends StandardSchemaV1$1> {
|
|
537
|
+
/** Names the token, for errors. @default 'Config' */
|
|
538
|
+
name?: string;
|
|
539
|
+
/** Loads the raw configuration. */
|
|
540
|
+
load: () => unknown;
|
|
541
|
+
/**
|
|
542
|
+
* Validates what `load` returned and types the service. Must validate
|
|
543
|
+
* synchronously.
|
|
544
|
+
*/
|
|
545
|
+
schema: Schema;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Creates the token of a `ConfigService` whose content comes from `load`,
|
|
549
|
+
* called once per container. With a `schema`, the loaded value is validated
|
|
550
|
+
* and the service is typed from the schema's output.
|
|
551
|
+
*/
|
|
552
|
+
export declare function provideConfig<Schema extends StandardSchemaV1$1<any, object>>(options: ValidatedConfigProviderOptions<Schema>): InjectionToken$1<ConfigService<InferOutput$1<Schema>>, undefined>;
|
|
553
|
+
export declare function provideConfig<ConfigMap extends object>(options: ConfigProviderOptions<ConfigMap>): InjectionToken$1<ConfigService<ConfigMap>, undefined>;
|
|
554
|
+
/**
|
|
555
|
+
* The context of the current execution, on any transport. Injectable in
|
|
556
|
+
* request-scoped services.
|
|
557
|
+
*/
|
|
558
|
+
export declare const ExecutionContextToken: InjectionToken$1<ExecutionContext, undefined, false>;
|
|
559
|
+
/**
|
|
560
|
+
* Adds guards to a module, a controller or a handler. Guards run in the
|
|
561
|
+
* order module, controller, handler, and within one level in the order given.
|
|
562
|
+
*
|
|
563
|
+
* On a class, place it above `@Controller` / `@Module`.
|
|
564
|
+
*/
|
|
565
|
+
export declare function UseGuards(...guards: GuardClass[]): (target: any, context: ClassDecoratorContext<abstract new (...args: any) => any> | ClassFieldDecoratorContext<unknown, unknown> | ClassMethodDecoratorContext<unknown, (this: unknown, ...args: any) => any>) => any;
|
|
566
|
+
/**
|
|
567
|
+
* Adds interceptors to a module, a controller or a handler. The first one
|
|
568
|
+
* given is the outermost. They run for what the guards let through, unlike the
|
|
569
|
+
* interceptors of the application.
|
|
570
|
+
*
|
|
571
|
+
* On a class, place it above `@Controller` / `@Module`.
|
|
572
|
+
*/
|
|
573
|
+
export declare function UseInterceptors(...interceptors: InterceptorClass[]): (target: any, context: ClassDecoratorContext<abstract new (...args: any) => any> | ClassFieldDecoratorContext<unknown, unknown> | ClassMethodDecoratorContext<unknown, (this: unknown, ...args: any) => any>) => any;
|
|
574
|
+
/**
|
|
575
|
+
* @publicApi
|
|
576
|
+
*/
|
|
577
|
+
interface ConsoleLoggerOptions {
|
|
578
|
+
/**
|
|
579
|
+
* Enabled log levels.
|
|
580
|
+
* Default every level, `log` and above when `NODE_ENV` is `production`.
|
|
581
|
+
*/
|
|
582
|
+
logLevels?: LogLevel[];
|
|
583
|
+
/**
|
|
584
|
+
* If enabled, will print timestamp difference between current and previous log message.
|
|
585
|
+
* Note: This option is not used when `json` is enabled.
|
|
586
|
+
* @default false
|
|
587
|
+
*/
|
|
588
|
+
showTimeDiff?: boolean;
|
|
589
|
+
/**
|
|
590
|
+
* A prefix to be used for each log message.
|
|
591
|
+
* Note: This option is not used when `json` is enabled.
|
|
592
|
+
*/
|
|
593
|
+
prefix?: string;
|
|
594
|
+
/**
|
|
595
|
+
* If true, will print the process ID in the log message.
|
|
596
|
+
* Note: This option is not used when `json` is enabled.
|
|
597
|
+
* @default true
|
|
598
|
+
*/
|
|
599
|
+
showPid?: boolean;
|
|
600
|
+
/**
|
|
601
|
+
* If true, will print the log level in the log message.
|
|
602
|
+
* Note: This option is not used when `json` is enabled.
|
|
603
|
+
* @default true
|
|
604
|
+
*/
|
|
605
|
+
showLogLevel?: boolean;
|
|
606
|
+
/**
|
|
607
|
+
* If true, will print the prefix/app name in the log message.
|
|
608
|
+
* Note: This option is not used when `json` is enabled.
|
|
609
|
+
* @default true
|
|
610
|
+
*/
|
|
611
|
+
showPrefix?: boolean;
|
|
612
|
+
/**
|
|
613
|
+
* If true, will print the context in the log message.
|
|
614
|
+
* Note: This option is not used when `json` is enabled.
|
|
615
|
+
* @default true
|
|
616
|
+
*/
|
|
617
|
+
showContext?: boolean;
|
|
618
|
+
/**
|
|
619
|
+
* If true, will print the absolute timestamp in the log message.
|
|
620
|
+
* Note: This option is not used when `json` is enabled.
|
|
621
|
+
* @default true
|
|
622
|
+
*/
|
|
623
|
+
showTimestamp?: boolean;
|
|
624
|
+
/**
|
|
625
|
+
* If enabled, will add a request ID to the log message.
|
|
626
|
+
*/
|
|
627
|
+
requestId?: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* If enabled, will print the log message in JSON format.
|
|
630
|
+
*/
|
|
631
|
+
json?: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* If enabled, will print the log message in color.
|
|
634
|
+
* Default true if json is disabled and stdout is a terminal, false otherwise.
|
|
635
|
+
*/
|
|
636
|
+
colors?: boolean;
|
|
637
|
+
/**
|
|
638
|
+
* The context of the logger.
|
|
639
|
+
*/
|
|
640
|
+
context?: string;
|
|
641
|
+
/**
|
|
642
|
+
* If enabled, will print the log message in a single line, even if it is an object with multiple properties.
|
|
643
|
+
* 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.
|
|
644
|
+
* Default true when `json` is enabled, false otherwise.
|
|
645
|
+
*/
|
|
646
|
+
compact?: boolean | number;
|
|
647
|
+
/**
|
|
648
|
+
* Specifies the maximum number of Array, TypedArray, Map, Set, WeakMap, and WeakSet elements to include when formatting.
|
|
649
|
+
* Set to null or Infinity to show all elements. Set to 0 or negative to show no elements.
|
|
650
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
651
|
+
* @default 100
|
|
652
|
+
*/
|
|
653
|
+
maxArrayLength?: number;
|
|
654
|
+
/**
|
|
655
|
+
* Specifies the maximum number of characters to include when formatting.
|
|
656
|
+
* Set to null or Infinity to show all elements. Set to 0 or negative to show no characters.
|
|
657
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
658
|
+
* @default 10000.
|
|
659
|
+
*/
|
|
660
|
+
maxStringLength?: number;
|
|
661
|
+
/**
|
|
662
|
+
* If enabled, will sort keys while formatting objects.
|
|
663
|
+
* Can also be a custom sorting function.
|
|
664
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
665
|
+
* @default false
|
|
666
|
+
*/
|
|
667
|
+
sorted?: boolean | ((a: string, b: string) => number);
|
|
668
|
+
/**
|
|
669
|
+
* Specifies the number of times to recurse while formatting object. T
|
|
670
|
+
* This is useful for inspecting large objects. To recurse up to the maximum call stack size pass Infinity or null.
|
|
671
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
672
|
+
* @default 5
|
|
673
|
+
*/
|
|
674
|
+
depth?: number;
|
|
675
|
+
/**
|
|
676
|
+
* If true, object's non-enumerable symbols and properties are included in the formatted result.
|
|
677
|
+
* WeakMap and WeakSet entries are also included as well as user defined prototype properties
|
|
678
|
+
* @default false
|
|
679
|
+
*/
|
|
680
|
+
showHidden?: boolean;
|
|
681
|
+
/**
|
|
682
|
+
* 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).
|
|
683
|
+
* Default Infinity when "compact" is true, 80 otherwise.
|
|
684
|
+
* Ignored when `json` is enabled, colors are disabled, and `compact` is set to true as it produces a parseable JSON output.
|
|
685
|
+
*/
|
|
686
|
+
breakLength?: number;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Prints to the console. Without options it prints every level, `log` and
|
|
690
|
+
* above when `NODE_ENV` is `production`, in colour when stdout is a terminal.
|
|
691
|
+
* @publicApi
|
|
692
|
+
*/
|
|
693
|
+
export declare class ConsoleLogger implements LoggerService {
|
|
694
|
+
/**
|
|
695
|
+
* Creates a new ConsoleLogger instance with the given options.
|
|
696
|
+
* This is a convenience method that instantiates and sets up the logger in one call.
|
|
697
|
+
*/
|
|
698
|
+
static create(): ConsoleLogger;
|
|
699
|
+
static create(context: string): ConsoleLogger;
|
|
700
|
+
static create(options: ConsoleLoggerOptions): ConsoleLogger;
|
|
701
|
+
static create(context: string, options: ConsoleLoggerOptions): ConsoleLogger;
|
|
702
|
+
/**
|
|
703
|
+
* The options in effect: those given so far, and the defaults.
|
|
704
|
+
*/
|
|
705
|
+
protected options: ConsoleLoggerOptions;
|
|
706
|
+
/**
|
|
707
|
+
* The context of the logger (can be set manually or automatically inferred).
|
|
708
|
+
*/
|
|
709
|
+
protected context?: string;
|
|
710
|
+
/**
|
|
711
|
+
* The original context of the logger (set by the constructor or `setup`).
|
|
712
|
+
*/
|
|
713
|
+
protected originalContext?: string;
|
|
714
|
+
/**
|
|
715
|
+
* The options used for the "inspect" method.
|
|
716
|
+
*/
|
|
717
|
+
protected inspectOptions: InspectOptions;
|
|
718
|
+
/**
|
|
719
|
+
* The last timestamp at which the log message was printed.
|
|
720
|
+
*/
|
|
721
|
+
protected lastTimestampAt?: number;
|
|
722
|
+
/**
|
|
723
|
+
* The options that were given.
|
|
724
|
+
*/
|
|
725
|
+
private given;
|
|
726
|
+
constructor();
|
|
727
|
+
constructor(context: string);
|
|
728
|
+
constructor(options: ConsoleLoggerOptions);
|
|
729
|
+
constructor(context: string, options: ConsoleLoggerOptions);
|
|
730
|
+
/**
|
|
731
|
+
* Changes the options that are given and leaves the others as they are.
|
|
732
|
+
*/
|
|
733
|
+
setup(): void;
|
|
734
|
+
setup(context: string): void;
|
|
735
|
+
setup(options: ConsoleLoggerOptions): void;
|
|
736
|
+
setup(context: string, options: ConsoleLoggerOptions): void;
|
|
737
|
+
private applyOptions;
|
|
738
|
+
/**
|
|
739
|
+
* Write a 'log' level log, if the configured level allows for it.
|
|
740
|
+
* Prints to `stdout` with newline.
|
|
741
|
+
*/
|
|
742
|
+
log(message: any, context?: string): void;
|
|
743
|
+
log(message: any, ...optionalParams: [...any, string?]): void;
|
|
744
|
+
/**
|
|
745
|
+
* Write an 'error' level log, if the configured level allows for it.
|
|
746
|
+
* Prints to `stderr` with newline.
|
|
747
|
+
*/
|
|
748
|
+
error(message: any, stackOrContext?: string): void;
|
|
749
|
+
error(message: any, stack?: string, context?: string): void;
|
|
750
|
+
error(message: any, ...optionalParams: [...any, string?, string?]): void;
|
|
751
|
+
/**
|
|
752
|
+
* Write a 'warn' level log, if the configured level allows for it.
|
|
753
|
+
* Prints to `stdout` with newline.
|
|
754
|
+
*/
|
|
755
|
+
warn(message: any, context?: string): void;
|
|
756
|
+
warn(message: any, ...optionalParams: [...any, string?]): void;
|
|
757
|
+
/**
|
|
758
|
+
* Write a 'debug' level log, if the configured level allows for it.
|
|
759
|
+
* Prints to `stdout` with newline.
|
|
760
|
+
*/
|
|
761
|
+
debug(message: any, context?: string): void;
|
|
762
|
+
debug(message: any, ...optionalParams: [...any, string?]): void;
|
|
763
|
+
/**
|
|
764
|
+
* Write a 'verbose' level log, if the configured level allows for it.
|
|
765
|
+
* Prints to `stdout` with newline.
|
|
766
|
+
*/
|
|
767
|
+
verbose(message: any, context?: string): void;
|
|
768
|
+
verbose(message: any, ...optionalParams: [...any, string?]): void;
|
|
769
|
+
/**
|
|
770
|
+
* Write a 'fatal' level log, if the configured level allows for it.
|
|
771
|
+
* Prints to `stdout` with newline.
|
|
772
|
+
*/
|
|
773
|
+
fatal(message: any, context?: string): void;
|
|
774
|
+
fatal(message: any, ...optionalParams: [...any, string?]): void;
|
|
775
|
+
/**
|
|
776
|
+
* Set log levels
|
|
777
|
+
* @param levels log levels
|
|
778
|
+
*/
|
|
779
|
+
setLogLevels(levels: LogLevel[]): void;
|
|
780
|
+
/**
|
|
781
|
+
* Set logger context
|
|
782
|
+
* @param context context
|
|
783
|
+
*/
|
|
784
|
+
setContext(context: string): void;
|
|
785
|
+
/**
|
|
786
|
+
* Resets the logger context to the value that was passed to the constructor or `setup`.
|
|
787
|
+
*/
|
|
788
|
+
resetContext(): void;
|
|
789
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
790
|
+
/**
|
|
791
|
+
* Gets the current request ID from the AsyncLocalStorage store.
|
|
792
|
+
* Only returns a value if the requestId option is enabled.
|
|
793
|
+
*/
|
|
794
|
+
protected getCurrentRequestId(): string | undefined;
|
|
795
|
+
protected getTimestamp(): string;
|
|
796
|
+
protected printMessages(messages: unknown[], context?: string, logLevel?: LogLevel, requestId?: string, writeStreamType?: 'stdout' | 'stderr', errorStack?: unknown): void;
|
|
797
|
+
/** A message and the error logged with it share a line. */
|
|
798
|
+
private toJsonLines;
|
|
799
|
+
/** Logging must not fail the code that logs. */
|
|
800
|
+
private guarded;
|
|
801
|
+
protected printAsJson(message: unknown, options: {
|
|
802
|
+
context: string;
|
|
803
|
+
logLevel: LogLevel;
|
|
804
|
+
writeStreamType?: 'stdout' | 'stderr';
|
|
805
|
+
errorStack?: unknown;
|
|
806
|
+
requestId?: string;
|
|
807
|
+
error?: Error;
|
|
808
|
+
}): void;
|
|
809
|
+
private stringify;
|
|
810
|
+
/** A field that JSON cannot hold must not cost the rest of an error. */
|
|
811
|
+
private encodable;
|
|
812
|
+
protected formatPid(pid: number): string;
|
|
813
|
+
protected formatContext(context: string): string;
|
|
814
|
+
protected formatMessage(logLevel: LogLevel, message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string, requestId?: string): string;
|
|
815
|
+
protected getRequestId(requestId?: string): string;
|
|
816
|
+
protected stringifyMessage(message: unknown, logLevel: LogLevel): string;
|
|
817
|
+
protected colorize(message: string, logLevel: LogLevel): string;
|
|
818
|
+
protected printStackTrace(stack: string): void;
|
|
819
|
+
protected updateAndGetTimestampDiff(): string;
|
|
820
|
+
protected formatTimestampDiff(timestampDiff: number): string;
|
|
821
|
+
protected getInspectOptions(): InspectOptions;
|
|
822
|
+
protected stringifyReplacer(key: string, value: unknown): unknown;
|
|
823
|
+
private getContextAndMessagesToPrint;
|
|
824
|
+
private getContextAndStackAndMessagesToPrint;
|
|
825
|
+
private isStackFormat;
|
|
826
|
+
private getColorByLogLevel;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Marks a class as a module: a group of handlers with shared guards,
|
|
830
|
+
* interceptors and attributes.
|
|
831
|
+
*/
|
|
832
|
+
export declare function Module(options?: ModuleOptions): <T extends ClassType$1>(target: T, context: ClassDecoratorContext) => T;
|
|
833
|
+
/**
|
|
834
|
+
* Registers a class as a module without decorator syntax.
|
|
835
|
+
*/
|
|
836
|
+
export declare function registerModule<T extends ClassType$1>(target: T, options?: ModuleOptions): T;
|
|
837
|
+
export { type AnyInjectableType, type ApplicationOptions, type AsyncResolve, type AttributeApplication, AttributeFactory, type AttributeMap, type AttributeValue, BoundInjectionToken, type ClassAttribute, type ClassSchemaAttribute, type ClassType, type ClassTypeWithInstance, type ConfigProviderOptions, type ConfigServiceInterface, type ConsoleLoggerOptions, Container, type ContainerOptions, type ContextKey, type ContextValue, DIError, DIErrorCode, type ExecutionContext, type Factorable, type FactorableWithArgs, Factory, type FactoryContext, FactoryInjectionToken, type FactoryOptions, type Guard, type GuardClass, type HandlerInfo, type IContainer, type InferInput, type InferOutput, Injectable, type InjectableOptions, InjectableScope, InjectionToken, type InjectionTokenOptions, type InjectionTokenType, type Interceptor, type InterceptorClass, LOG_LEVELS, type LogLevel, type LoggerOptions, LoggerOutput, type LoggerService, type ModuleOptions, type OnApplicationBootstrap, type OnApplicationShutdown, type OnModuleInit, type OnServiceDestroy, type OnServiceInit, type OptionalResolve, type Path, type PathValue, PlainContextKey, type PluginApi, type PluginDefinition, type PluginInstance, type Provider, type ProviderInfo, type ProviderInput, type RegisterFactoryOptions, type RegisterInjectableOptions, type RegisterProviderOptions, type ResolvedInstance, ScopedContainer, type ShutdownHooksOptions, type StandardSchemaIssue, type StandardSchemaV1, type SyncResolve, type Transport, type TransportFactory, type TransportInstance, type ValidatedConfigProviderOptions, asyncInject, createContextKey, currentContext, filterLogLevels, getInjectableToken, inject, isLogLevel, optional, provide, registerFactory, registerInjectable, registerProvider };
|
|
838
|
+
//# sourceMappingURL=index.d.mts.map
|