UNPKG

6.46 kBTypeScriptView Raw
1import { INestApplicationContext, LoggerService, LogLevel, ShutdownSignal } from '@nestjs/common';
2import { DynamicModule, Type } from '@nestjs/common/interfaces';
3import { AbstractInstanceResolver } from './injector/abstract-instance-resolver';
4import { NestContainer } from './injector/container';
5import { Injector } from './injector/injector';
6import { InstanceLinksHost } from './injector/instance-links-host';
7import { ContextId } from './injector/instance-wrapper';
8import { Module } from './injector/module';
9/**
10 * @publicApi
11 */
12export declare class NestApplicationContext extends AbstractInstanceResolver implements INestApplicationContext {
13 protected readonly container: NestContainer;
14 private readonly scope;
15 private contextModule;
16 protected isInitialized: boolean;
17 protected readonly injector: Injector;
18 private shouldFlushLogsOnOverride;
19 private readonly activeShutdownSignals;
20 private readonly moduleCompiler;
21 private shutdownCleanupRef?;
22 private _instanceLinksHost;
23 private _moduleRefsByDistance?;
24 protected get instanceLinksHost(): InstanceLinksHost;
25 constructor(container: NestContainer, scope?: Type<any>[], contextModule?: Module);
26 selectContextModule(): void;
27 /**
28 * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
29 * @returns {INestApplicationContext}
30 */
31 select<T>(moduleType: Type<T> | DynamicModule): INestApplicationContext;
32 /**
33 * Retrieves an instance of either injectable or controller, otherwise, throws exception.
34 * @returns {TResult}
35 */
36 get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
37 /**
38 * Retrieves an instance of either injectable or controller, otherwise, throws exception.
39 * @returns {TResult}
40 */
41 get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
42 strict?: boolean;
43 each?: undefined | false;
44 }): TResult;
45 /**
46 * Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
47 * @returns {Array<TResult>}
48 */
49 get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
50 strict?: boolean;
51 each: true;
52 }): Array<TResult>;
53 /**
54 * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
55 * @returns {Array<TResult>}
56 */
57 resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
58 /**
59 * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
60 * @returns {Array<TResult>}
61 */
62 resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
63 id: number;
64 }): Promise<TResult>;
65 /**
66 * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
67 * @returns {Array<TResult>}
68 */
69 resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
70 id: number;
71 }, options?: {
72 strict?: boolean;
73 each?: undefined | false;
74 }): Promise<TResult>;
75 /**
76 * Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
77 * @returns {Array<TResult>}
78 */
79 resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
80 id: number;
81 }, options?: {
82 strict?: boolean;
83 each: true;
84 }): Promise<Array<TResult>>;
85 /**
86 * Registers the request/context object for a given context ID (DI container sub-tree).
87 * @returns {void}
88 */
89 registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
90 /**
91 * Initializes the Nest application.
92 * Calls the Nest lifecycle events.
93 *
94 * @returns {Promise<this>} The NestApplicationContext instance as Promise
95 */
96 init(): Promise<this>;
97 /**
98 * Terminates the application
99 * @returns {Promise<void>}
100 */
101 close(): Promise<void>;
102 /**
103 * Sets custom logger service.
104 * Flushes buffered logs if auto flush is on.
105 * @returns {void}
106 */
107 useLogger(logger: LoggerService | LogLevel[] | false): void;
108 /**
109 * Prints buffered logs and detaches buffer.
110 * @returns {void}
111 */
112 flushLogs(): void;
113 /**
114 * Define that it must flush logs right after defining a custom logger.
115 */
116 flushLogsOnOverride(): void;
117 /**
118 * Enables the usage of shutdown hooks. Will call the
119 * `onApplicationShutdown` function of a provider if the
120 * process receives a shutdown signal.
121 *
122 * @param {ShutdownSignal[]} [signals=[]] The system signals it should listen to
123 *
124 * @returns {this} The Nest application context instance
125 */
126 enableShutdownHooks(signals?: (ShutdownSignal | string)[]): this;
127 protected dispose(): Promise<void>;
128 /**
129 * Listens to shutdown signals by listening to
130 * process events
131 *
132 * @param {string[]} signals The system signals it should listen to
133 */
134 protected listenToShutdownSignals(signals: string[]): void;
135 /**
136 * Unsubscribes from shutdown signals (process events)
137 */
138 protected unsubscribeFromProcessSignals(): void;
139 /**
140 * Calls the `onModuleInit` function on the registered
141 * modules and its children.
142 */
143 protected callInitHook(): Promise<void>;
144 /**
145 * Calls the `onModuleDestroy` function on the registered
146 * modules and its children.
147 */
148 protected callDestroyHook(): Promise<void>;
149 /**
150 * Calls the `onApplicationBootstrap` function on the registered
151 * modules and its children.
152 */
153 protected callBootstrapHook(): Promise<void>;
154 /**
155 * Calls the `onApplicationShutdown` function on the registered
156 * modules and children.
157 */
158 protected callShutdownHook(signal?: string): Promise<void>;
159 /**
160 * Calls the `beforeApplicationShutdown` function on the registered
161 * modules and children.
162 */
163 protected callBeforeShutdownHook(signal?: string): Promise<void>;
164 private getModulesSortedByDistance;
165}