Skip to content

Commit 5d28b98

Browse files
feature(@nestjs/core) add async lifecycle hooks support
1 parent 52acfe4 commit 5d28b98

61 files changed

Lines changed: 2448 additions & 3622 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bundle

bundle/common/constants.d.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
export declare const metadata: {
2-
MODULES: string;
3-
IMPORTS: string;
4-
COMPONENTS: string;
5-
PROVIDERS: string;
6-
CONTROLLERS: string;
7-
EXPORTS: string;
2+
MODULES: string;
3+
IMPORTS: string;
4+
COMPONENTS: string;
5+
PROVIDERS: string;
6+
CONTROLLERS: string;
7+
EXPORTS: string;
88
};
9-
export declare const SHARED_MODULE_METADATA = "__sharedModule__";
10-
export declare const GLOBAL_MODULE_METADATA = "__globalModule__";
11-
export declare const PATH_METADATA = "path";
12-
export declare const PARAMTYPES_METADATA = "design:paramtypes";
13-
export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
14-
export declare const METHOD_METADATA = "method";
15-
export declare const ROUTE_ARGS_METADATA = "__routeArguments__";
16-
export declare const CUSTOM_ROUTE_AGRS_METADATA = "__customRouteArgs__";
17-
export declare const EXCEPTION_FILTERS_METADATA = "__exceptionFilters__";
18-
export declare const FILTER_CATCH_EXCEPTIONS = "__filterCatchExceptions__";
19-
export declare const PIPES_METADATA = "__pipes__";
20-
export declare const GUARDS_METADATA = "__guards__";
21-
export declare const RENDER_METADATA = "__renderTemplate__";
22-
export declare const INTERCEPTORS_METADATA = "__interceptors__";
23-
export declare const HTTP_CODE_METADATA = "__httpCode__";
24-
export declare const GATEWAY_MIDDLEWARES = "__gatewayMiddlewares";
25-
export declare const MODULE_PATH = "__module_path__";
9+
export declare const SHARED_MODULE_METADATA = '__sharedModule__';
10+
export declare const GLOBAL_MODULE_METADATA = '__globalModule__';
11+
export declare const PATH_METADATA = 'path';
12+
export declare const PARAMTYPES_METADATA = 'design:paramtypes';
13+
export declare const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
14+
export declare const METHOD_METADATA = 'method';
15+
export declare const ROUTE_ARGS_METADATA = '__routeArguments__';
16+
export declare const CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
17+
export declare const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
18+
export declare const FILTER_CATCH_EXCEPTIONS = '__filterCatchExceptions__';
19+
export declare const PIPES_METADATA = '__pipes__';
20+
export declare const GUARDS_METADATA = '__guards__';
21+
export declare const RENDER_METADATA = '__renderTemplate__';
22+
export declare const INTERCEPTORS_METADATA = '__interceptors__';
23+
export declare const HTTP_CODE_METADATA = '__httpCode__';
24+
export declare const GATEWAY_MIDDLEWARES = '__gatewayMiddlewares';
25+
export declare const MODULE_PATH = '__module_path__';

bundle/common/index.d.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
export * from './decorators';
22
export * from './enums';
3-
export { NestModule, INestApplication, INestMicroservice, NestMiddleware, FunctionMiddleware, MiddlewaresConsumer, OnModuleInit, ExceptionFilter, WebSocketAdapter, PipeTransform, Paramtype, ArgumentMetadata, OnModuleDestroy, ExecutionContext, CanActivate, RpcExceptionFilter, WsExceptionFilter, NestInterceptor, DynamicModule, INestApplicationContext, HttpServer, HttpServerFactory, ArgumentsHost, INestExpressApplication, INestFastifyApplication } from './interfaces';
3+
export {
4+
NestModule,
5+
INestApplication,
6+
INestMicroservice,
7+
NestMiddleware,
8+
FunctionMiddleware,
9+
MiddlewaresConsumer,
10+
OnModuleInit,
11+
ExceptionFilter,
12+
WebSocketAdapter,
13+
PipeTransform,
14+
Paramtype,
15+
ArgumentMetadata,
16+
OnModuleDestroy,
17+
ExecutionContext,
18+
CanActivate,
19+
RpcExceptionFilter,
20+
WsExceptionFilter,
21+
NestInterceptor,
22+
DynamicModule,
23+
INestApplicationContext,
24+
HttpServer,
25+
HttpServerFactory,
26+
ArgumentsHost,
27+
INestExpressApplication,
28+
INestFastifyApplication,
29+
} from './interfaces';
430
export * from './interceptors';
531
export * from './services/logger.service';
632
export * from './pipes';
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
import { PipeTransform, WebSocketAdapter, ExceptionFilter, NestInterceptor, CanActivate } from '@nestjs/common';
1+
import {
2+
PipeTransform,
3+
WebSocketAdapter,
4+
ExceptionFilter,
5+
NestInterceptor,
6+
CanActivate,
7+
} from '@nestjs/common';
28
import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface';
39
export declare class ApplicationConfig implements ConfigurationProvider {
4-
private ioAdapter;
5-
private globalPipes;
6-
private globalFilters;
7-
private globalInterceptors;
8-
private globalGuards;
9-
private globalPrefix;
10-
constructor(ioAdapter?: WebSocketAdapter | null);
11-
setGlobalPrefix(prefix: string): void;
12-
getGlobalPrefix(): string;
13-
setIoAdapter(ioAdapter: WebSocketAdapter): void;
14-
getIoAdapter(): WebSocketAdapter;
15-
addGlobalPipe(pipe: PipeTransform<any>): void;
16-
useGlobalPipes(...pipes: PipeTransform<any>[]): void;
17-
getGlobalFilters(): ExceptionFilter[];
18-
addGlobalFilter(filter: ExceptionFilter): void;
19-
useGlobalFilters(...filters: ExceptionFilter[]): void;
20-
getGlobalPipes(): PipeTransform<any>[];
21-
getGlobalInterceptors(): NestInterceptor[];
22-
addGlobalInterceptor(interceptor: NestInterceptor): void;
23-
useGlobalInterceptors(...interceptors: NestInterceptor[]): void;
24-
getGlobalGuards(): CanActivate[];
25-
addGlobalGuard(guard: CanActivate): void;
26-
useGlobalGuards(...guards: CanActivate[]): void;
10+
private ioAdapter;
11+
private globalPipes;
12+
private globalFilters;
13+
private globalInterceptors;
14+
private globalGuards;
15+
private globalPrefix;
16+
constructor(ioAdapter?: WebSocketAdapter | null);
17+
setGlobalPrefix(prefix: string): void;
18+
getGlobalPrefix(): string;
19+
setIoAdapter(ioAdapter: WebSocketAdapter): void;
20+
getIoAdapter(): WebSocketAdapter;
21+
addGlobalPipe(pipe: PipeTransform<any>): void;
22+
useGlobalPipes(...pipes: PipeTransform<any>[]): void;
23+
getGlobalFilters(): ExceptionFilter[];
24+
addGlobalFilter(filter: ExceptionFilter): void;
25+
useGlobalFilters(...filters: ExceptionFilter[]): void;
26+
getGlobalPipes(): PipeTransform<any>[];
27+
getGlobalInterceptors(): NestInterceptor[];
28+
addGlobalInterceptor(interceptor: NestInterceptor): void;
29+
useGlobalInterceptors(...interceptors: NestInterceptor[]): void;
30+
getGlobalGuards(): CanActivate[];
31+
addGlobalGuard(guard: CanActivate): void;
32+
useGlobalGuards(...guards: CanActivate[]): void;
2733
}

bundle/core/constants.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export declare const messages: {
2-
APPLICATION_START: string;
3-
APPLICATION_READY: string;
4-
MICROSERVICE_READY: string;
5-
UNKNOWN_EXCEPTION_MESSAGE: string;
2+
APPLICATION_START: string;
3+
APPLICATION_READY: string;
4+
MICROSERVICE_READY: string;
5+
UNKNOWN_EXCEPTION_MESSAGE: string;
66
};
7-
export declare const APP_INTERCEPTOR = "APP_INTERCEPTOR";
8-
export declare const APP_PIPE = "APP_PIPE";
9-
export declare const APP_GUARD = "APP_GUARD";
10-
export declare const APP_FILTER = "APP_FILTER";
7+
export declare const APP_INTERCEPTOR = 'APP_INTERCEPTOR';
8+
export declare const APP_PIPE = 'APP_PIPE';
9+
export declare const APP_GUARD = 'APP_GUARD';
10+
export declare const APP_FILTER = 'APP_FILTER';

bundle/core/metadata-scanner.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
22
export declare class MetadataScanner {
3-
scanFromPrototype<T extends Injectable, R>(instance: T, prototype: any, callback: (name: string) => R): R[];
4-
getAllFilteredMethodNames(prototype: any): IterableIterator<string>;
3+
scanFromPrototype<T extends Injectable, R>(
4+
instance: T,
5+
prototype: any,
6+
callback: (name: string) => R,
7+
): R[];
8+
getAllFilteredMethodNames(prototype: any): IterableIterator<string>;
59
}

bundle/core/nest-application-context.d.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ import { Type } from '@nestjs/common/interfaces/type.interface';
33
import { INestApplicationContext, OnModuleInit } from '@nestjs/common';
44
import { Module } from './injector/module';
55
export declare class NestApplicationContext implements INestApplicationContext {
6-
protected readonly container: NestContainer;
7-
private readonly scope;
8-
protected contextModule: Module;
9-
private readonly moduleTokenFactory;
10-
private contextModuleFixture;
11-
constructor(container: NestContainer, scope: Type<any>[], contextModule: Module, isInitialized?: boolean);
12-
selectContextModule(): void;
13-
select<T>(module: Type<T>): INestApplicationContext;
14-
get<T>(typeOrToken: Type<T> | string | symbol, options?: {
15-
strict: boolean;
16-
}): T;
17-
find<T>(typeOrToken: Type<T> | string | symbol): T;
18-
protected callInitHook(): void;
19-
protected callModuleInitHook(module: Module): void;
20-
protected hasOnModuleInitHook(instance: any): instance is OnModuleInit;
21-
private findInstanceByPrototypeOrToken<T>(metatypeOrToken, contextModule);
22-
private initFlattenModule();
6+
protected readonly container: NestContainer;
7+
private readonly scope;
8+
protected contextModule: Module;
9+
private readonly moduleTokenFactory;
10+
private contextModuleFixture;
11+
constructor(
12+
container: NestContainer,
13+
scope: Type<any>[],
14+
contextModule: Module,
15+
isInitialized?: boolean,
16+
);
17+
selectContextModule(): void;
18+
select<T>(module: Type<T>): INestApplicationContext;
19+
get<T>(
20+
typeOrToken: Type<T> | string | symbol,
21+
options?: {
22+
strict: boolean;
23+
},
24+
): T;
25+
find<T>(typeOrToken: Type<T> | string | symbol): T;
26+
protected callInitHook(): void;
27+
protected callModuleInitHook(module: Module): void;
28+
protected hasOnModuleInitHook(instance: any): instance is OnModuleInit;
29+
private findInstanceByPrototypeOrToken<T>(metatypeOrToken, contextModule);
30+
private initFlattenModule();
2331
}

bundle/core/nest-application.d.ts

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/// <reference types="node" />
22
import * as http from 'http';
3-
import { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, WebSocketAdapter } from '@nestjs/common';
3+
import {
4+
CanActivate,
5+
ExceptionFilter,
6+
NestInterceptor,
7+
PipeTransform,
8+
WebSocketAdapter,
9+
} from '@nestjs/common';
410
import { INestApplication, INestMicroservice } from '@nestjs/common';
511
import { MicroserviceOptions } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface';
612
import { ApplicationConfig } from './application-config';
@@ -12,61 +18,69 @@ import { HttpServer } from '@nestjs/common/interfaces';
1218
import { INestExpressApplication } from '@nestjs/common/interfaces/nest-express-application.interface';
1319
import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface';
1420
import { ServeStaticOptions } from '@nestjs/common/interfaces/external/serve-static-options.interface';
15-
export declare class NestApplication extends NestApplicationContext implements INestApplication, INestExpressApplication, INestFastifyApplication {
16-
private readonly httpAdapter;
17-
private readonly config;
18-
private readonly appOptions;
19-
private readonly logger;
20-
private readonly middlewaresModule;
21-
private readonly middlewaresContainer;
22-
private readonly microservicesModule;
23-
private readonly socketModule;
24-
private readonly routesResolver;
25-
private readonly microservices;
26-
private httpServer;
27-
private isInitialized;
28-
constructor(container: NestContainer, httpAdapter: HttpServer, config: ApplicationConfig, appOptions?: NestApplicationOptions);
29-
registerHttpServer(): void;
30-
applyOptions(): this;
31-
createServer(): any;
32-
getUnderlyingHttpServer(): any;
33-
registerModules(): Promise<void>;
34-
init(): Promise<this>;
35-
registerParserMiddlewares(): any;
36-
isMiddlewareApplied(httpAdapter: HttpServer, name: string): boolean;
37-
registerRouter(): Promise<void>;
38-
connectMicroservice(options: MicroserviceOptions): INestMicroservice;
39-
getMicroservices(): INestMicroservice[];
40-
getHttpServer(): http.Server;
41-
startAllMicroservices(callback?: () => void): this;
42-
startAllMicroservicesAsync(): Promise<void>;
43-
use(...args: any[]): this;
44-
engine(...args: any[]): this;
45-
set(...args: any[]): this;
46-
disable(...args: any[]): this;
47-
enable(...args: any[]): this;
48-
register(...args: any[]): this;
49-
inject(...args: any[]): any;
50-
enableCors(options?: CorsOptions): this;
51-
listen(port: number | string, callback?: () => void): any;
52-
listen(port: number | string, hostname: string, callback?: () => void): any;
53-
listenAsync(port: number | string, hostname?: string): Promise<any>;
54-
close(): void;
55-
setGlobalPrefix(prefix: string): this;
56-
useWebSocketAdapter(adapter: WebSocketAdapter): this;
57-
useGlobalFilters(...filters: ExceptionFilter[]): this;
58-
useGlobalPipes(...pipes: PipeTransform<any>[]): this;
59-
useGlobalInterceptors(...interceptors: NestInterceptor[]): this;
60-
useGlobalGuards(...guards: CanActivate[]): this;
61-
useStaticAssets(options: any): this;
62-
useStaticAssets(path: string, options?: ServeStaticOptions): any;
63-
setBaseViewsDir(path: string): this;
64-
setViewEngine(engineOrOptions: any): this;
65-
private loadPackage(name, ctx);
66-
private registerMiddlewares(instance);
67-
private isExpress();
68-
private listenToPromise(microservice);
69-
private callDestroyHook();
70-
private callModuleDestroyHook(module);
71-
private hasOnModuleDestroyHook(instance);
21+
export declare class NestApplication extends NestApplicationContext
22+
implements INestApplication,
23+
INestExpressApplication,
24+
INestFastifyApplication {
25+
private readonly httpAdapter;
26+
private readonly config;
27+
private readonly appOptions;
28+
private readonly logger;
29+
private readonly middlewaresModule;
30+
private readonly middlewaresContainer;
31+
private readonly microservicesModule;
32+
private readonly socketModule;
33+
private readonly routesResolver;
34+
private readonly microservices;
35+
private httpServer;
36+
private isInitialized;
37+
constructor(
38+
container: NestContainer,
39+
httpAdapter: HttpServer,
40+
config: ApplicationConfig,
41+
appOptions?: NestApplicationOptions,
42+
);
43+
registerHttpServer(): void;
44+
applyOptions(): this;
45+
createServer(): any;
46+
getUnderlyingHttpServer(): any;
47+
registerModules(): Promise<void>;
48+
init(): Promise<this>;
49+
registerParserMiddlewares(): any;
50+
isMiddlewareApplied(httpAdapter: HttpServer, name: string): boolean;
51+
registerRouter(): Promise<void>;
52+
connectMicroservice(options: MicroserviceOptions): INestMicroservice;
53+
getMicroservices(): INestMicroservice[];
54+
getHttpServer(): http.Server;
55+
startAllMicroservices(callback?: () => void): this;
56+
startAllMicroservicesAsync(): Promise<void>;
57+
use(...args: any[]): this;
58+
engine(...args: any[]): this;
59+
set(...args: any[]): this;
60+
disable(...args: any[]): this;
61+
enable(...args: any[]): this;
62+
register(...args: any[]): this;
63+
inject(...args: any[]): any;
64+
enableCors(options?: CorsOptions): this;
65+
listen(port: number | string, callback?: () => void): any;
66+
listen(port: number | string, hostname: string, callback?: () => void): any;
67+
listenAsync(port: number | string, hostname?: string): Promise<any>;
68+
close(): void;
69+
setGlobalPrefix(prefix: string): this;
70+
useWebSocketAdapter(adapter: WebSocketAdapter): this;
71+
useGlobalFilters(...filters: ExceptionFilter[]): this;
72+
useGlobalPipes(...pipes: PipeTransform<any>[]): this;
73+
useGlobalInterceptors(...interceptors: NestInterceptor[]): this;
74+
useGlobalGuards(...guards: CanActivate[]): this;
75+
useStaticAssets(options: any): this;
76+
useStaticAssets(path: string, options?: ServeStaticOptions): any;
77+
setBaseViewsDir(path: string): this;
78+
setViewEngine(engineOrOptions: any): this;
79+
private loadPackage(name, ctx);
80+
private registerMiddlewares(instance);
81+
private isExpress();
82+
private listenToPromise(microservice);
83+
private callDestroyHook();
84+
private callModuleDestroyHook(module);
85+
private hasOnModuleDestroyHook(instance);
7286
}

0 commit comments

Comments
 (0)