UNPKG

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