Skip to content

Commit

Permalink
feature(@nestjs/core) add async lifecycle hooks support
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 21, 2018
1 parent 52acfe4 commit 5d28b98
Show file tree
Hide file tree
Showing 61 changed files with 2,448 additions and 3,622 deletions.
1 change: 1 addition & 0 deletions .prettierignore
@@ -0,0 +1 @@
/bundle
46 changes: 23 additions & 23 deletions bundle/common/constants.d.ts
@@ -1,25 +1,25 @@
export declare const metadata: {
MODULES: string;
IMPORTS: string;
COMPONENTS: string;
PROVIDERS: string;
CONTROLLERS: string;
EXPORTS: string;
MODULES: string;
IMPORTS: string;
COMPONENTS: string;
PROVIDERS: string;
CONTROLLERS: string;
EXPORTS: string;
};
export declare const SHARED_MODULE_METADATA = "__sharedModule__";
export declare const GLOBAL_MODULE_METADATA = "__globalModule__";
export declare const PATH_METADATA = "path";
export declare const PARAMTYPES_METADATA = "design:paramtypes";
export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
export declare const METHOD_METADATA = "method";
export declare const ROUTE_ARGS_METADATA = "__routeArguments__";
export declare const CUSTOM_ROUTE_AGRS_METADATA = "__customRouteArgs__";
export declare const EXCEPTION_FILTERS_METADATA = "__exceptionFilters__";
export declare const FILTER_CATCH_EXCEPTIONS = "__filterCatchExceptions__";
export declare const PIPES_METADATA = "__pipes__";
export declare const GUARDS_METADATA = "__guards__";
export declare const RENDER_METADATA = "__renderTemplate__";
export declare const INTERCEPTORS_METADATA = "__interceptors__";
export declare const HTTP_CODE_METADATA = "__httpCode__";
export declare const GATEWAY_MIDDLEWARES = "__gatewayMiddlewares";
export declare const MODULE_PATH = "__module_path__";
export declare const SHARED_MODULE_METADATA = '__sharedModule__';
export declare const GLOBAL_MODULE_METADATA = '__globalModule__';
export declare const PATH_METADATA = 'path';
export declare const PARAMTYPES_METADATA = 'design:paramtypes';
export declare const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
export declare const METHOD_METADATA = 'method';
export declare const ROUTE_ARGS_METADATA = '__routeArguments__';
export declare const CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
export declare const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
export declare const FILTER_CATCH_EXCEPTIONS = '__filterCatchExceptions__';
export declare const PIPES_METADATA = '__pipes__';
export declare const GUARDS_METADATA = '__guards__';
export declare const RENDER_METADATA = '__renderTemplate__';
export declare const INTERCEPTORS_METADATA = '__interceptors__';
export declare const HTTP_CODE_METADATA = '__httpCode__';
export declare const GATEWAY_MIDDLEWARES = '__gatewayMiddlewares';
export declare const MODULE_PATH = '__module_path__';
28 changes: 27 additions & 1 deletion bundle/common/index.d.ts
@@ -1,6 +1,32 @@
export * from './decorators';
export * from './enums';
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';
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';
export * from './interceptors';
export * from './services/logger.service';
export * from './pipes';
Expand Down
54 changes: 30 additions & 24 deletions bundle/core/application-config.d.ts
@@ -1,27 +1,33 @@
import { PipeTransform, WebSocketAdapter, ExceptionFilter, NestInterceptor, CanActivate } from '@nestjs/common';
import {
PipeTransform,
WebSocketAdapter,
ExceptionFilter,
NestInterceptor,
CanActivate,
} from '@nestjs/common';
import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface';
export declare class ApplicationConfig implements ConfigurationProvider {
private ioAdapter;
private globalPipes;
private globalFilters;
private globalInterceptors;
private globalGuards;
private globalPrefix;
constructor(ioAdapter?: WebSocketAdapter | null);
setGlobalPrefix(prefix: string): void;
getGlobalPrefix(): string;
setIoAdapter(ioAdapter: WebSocketAdapter): void;
getIoAdapter(): WebSocketAdapter;
addGlobalPipe(pipe: PipeTransform<any>): void;
useGlobalPipes(...pipes: PipeTransform<any>[]): void;
getGlobalFilters(): ExceptionFilter[];
addGlobalFilter(filter: ExceptionFilter): void;
useGlobalFilters(...filters: ExceptionFilter[]): void;
getGlobalPipes(): PipeTransform<any>[];
getGlobalInterceptors(): NestInterceptor[];
addGlobalInterceptor(interceptor: NestInterceptor): void;
useGlobalInterceptors(...interceptors: NestInterceptor[]): void;
getGlobalGuards(): CanActivate[];
addGlobalGuard(guard: CanActivate): void;
useGlobalGuards(...guards: CanActivate[]): void;
private ioAdapter;
private globalPipes;
private globalFilters;
private globalInterceptors;
private globalGuards;
private globalPrefix;
constructor(ioAdapter?: WebSocketAdapter | null);
setGlobalPrefix(prefix: string): void;
getGlobalPrefix(): string;
setIoAdapter(ioAdapter: WebSocketAdapter): void;
getIoAdapter(): WebSocketAdapter;
addGlobalPipe(pipe: PipeTransform<any>): void;
useGlobalPipes(...pipes: PipeTransform<any>[]): void;
getGlobalFilters(): ExceptionFilter[];
addGlobalFilter(filter: ExceptionFilter): void;
useGlobalFilters(...filters: ExceptionFilter[]): void;
getGlobalPipes(): PipeTransform<any>[];
getGlobalInterceptors(): NestInterceptor[];
addGlobalInterceptor(interceptor: NestInterceptor): void;
useGlobalInterceptors(...interceptors: NestInterceptor[]): void;
getGlobalGuards(): CanActivate[];
addGlobalGuard(guard: CanActivate): void;
useGlobalGuards(...guards: CanActivate[]): void;
}
16 changes: 8 additions & 8 deletions bundle/core/constants.d.ts
@@ -1,10 +1,10 @@
export declare const messages: {
APPLICATION_START: string;
APPLICATION_READY: string;
MICROSERVICE_READY: string;
UNKNOWN_EXCEPTION_MESSAGE: string;
APPLICATION_START: string;
APPLICATION_READY: string;
MICROSERVICE_READY: string;
UNKNOWN_EXCEPTION_MESSAGE: string;
};
export declare const APP_INTERCEPTOR = "APP_INTERCEPTOR";
export declare const APP_PIPE = "APP_PIPE";
export declare const APP_GUARD = "APP_GUARD";
export declare const APP_FILTER = "APP_FILTER";
export declare const APP_INTERCEPTOR = 'APP_INTERCEPTOR';
export declare const APP_PIPE = 'APP_PIPE';
export declare const APP_GUARD = 'APP_GUARD';
export declare const APP_FILTER = 'APP_FILTER';
8 changes: 6 additions & 2 deletions bundle/core/metadata-scanner.d.ts
@@ -1,5 +1,9 @@
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
export declare class MetadataScanner {
scanFromPrototype<T extends Injectable, R>(instance: T, prototype: any, callback: (name: string) => R): R[];
getAllFilteredMethodNames(prototype: any): IterableIterator<string>;
scanFromPrototype<T extends Injectable, R>(
instance: T,
prototype: any,
callback: (name: string) => R,
): R[];
getAllFilteredMethodNames(prototype: any): IterableIterator<string>;
}
42 changes: 25 additions & 17 deletions bundle/core/nest-application-context.d.ts
Expand Up @@ -3,21 +3,29 @@ import { Type } from '@nestjs/common/interfaces/type.interface';
import { INestApplicationContext, OnModuleInit } from '@nestjs/common';
import { Module } from './injector/module';
export declare class NestApplicationContext implements INestApplicationContext {
protected readonly container: NestContainer;
private readonly scope;
protected contextModule: Module;
private readonly moduleTokenFactory;
private contextModuleFixture;
constructor(container: NestContainer, scope: Type<any>[], contextModule: Module, isInitialized?: boolean);
selectContextModule(): void;
select<T>(module: Type<T>): INestApplicationContext;
get<T>(typeOrToken: Type<T> | string | symbol, options?: {
strict: boolean;
}): T;
find<T>(typeOrToken: Type<T> | string | symbol): T;
protected callInitHook(): void;
protected callModuleInitHook(module: Module): void;
protected hasOnModuleInitHook(instance: any): instance is OnModuleInit;
private findInstanceByPrototypeOrToken<T>(metatypeOrToken, contextModule);
private initFlattenModule();
protected readonly container: NestContainer;
private readonly scope;
protected contextModule: Module;
private readonly moduleTokenFactory;
private contextModuleFixture;
constructor(
container: NestContainer,
scope: Type<any>[],
contextModule: Module,
isInitialized?: boolean,
);
selectContextModule(): void;
select<T>(module: Type<T>): INestApplicationContext;
get<T>(
typeOrToken: Type<T> | string | symbol,
options?: {
strict: boolean;
},
): T;
find<T>(typeOrToken: Type<T> | string | symbol): T;
protected callInitHook(): void;
protected callModuleInitHook(module: Module): void;
protected hasOnModuleInitHook(instance: any): instance is OnModuleInit;
private findInstanceByPrototypeOrToken<T>(metatypeOrToken, contextModule);
private initFlattenModule();
}
130 changes: 72 additions & 58 deletions bundle/core/nest-application.d.ts
@@ -1,6 +1,12 @@
/// <reference types="node" />
import * as http from 'http';
import { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, WebSocketAdapter } from '@nestjs/common';
import {
CanActivate,
ExceptionFilter,
NestInterceptor,
PipeTransform,
WebSocketAdapter,
} from '@nestjs/common';
import { INestApplication, INestMicroservice } from '@nestjs/common';
import { MicroserviceOptions } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface';
import { ApplicationConfig } from './application-config';
Expand All @@ -12,61 +18,69 @@ import { HttpServer } from '@nestjs/common/interfaces';
import { INestExpressApplication } from '@nestjs/common/interfaces/nest-express-application.interface';
import { INestFastifyApplication } from '@nestjs/common/interfaces/nest-fastify-application.interface';
import { ServeStaticOptions } from '@nestjs/common/interfaces/external/serve-static-options.interface';
export declare class NestApplication extends NestApplicationContext implements INestApplication, INestExpressApplication, INestFastifyApplication {
private readonly httpAdapter;
private readonly config;
private readonly appOptions;
private readonly logger;
private readonly middlewaresModule;
private readonly middlewaresContainer;
private readonly microservicesModule;
private readonly socketModule;
private readonly routesResolver;
private readonly microservices;
private httpServer;
private isInitialized;
constructor(container: NestContainer, httpAdapter: HttpServer, config: ApplicationConfig, appOptions?: NestApplicationOptions);
registerHttpServer(): void;
applyOptions(): this;
createServer(): any;
getUnderlyingHttpServer(): any;
registerModules(): Promise<void>;
init(): Promise<this>;
registerParserMiddlewares(): any;
isMiddlewareApplied(httpAdapter: HttpServer, name: string): boolean;
registerRouter(): Promise<void>;
connectMicroservice(options: MicroserviceOptions): INestMicroservice;
getMicroservices(): INestMicroservice[];
getHttpServer(): http.Server;
startAllMicroservices(callback?: () => void): this;
startAllMicroservicesAsync(): Promise<void>;
use(...args: any[]): this;
engine(...args: any[]): this;
set(...args: any[]): this;
disable(...args: any[]): this;
enable(...args: any[]): this;
register(...args: any[]): this;
inject(...args: any[]): any;
enableCors(options?: CorsOptions): this;
listen(port: number | string, callback?: () => void): any;
listen(port: number | string, hostname: string, callback?: () => void): any;
listenAsync(port: number | string, hostname?: string): Promise<any>;
close(): void;
setGlobalPrefix(prefix: string): this;
useWebSocketAdapter(adapter: WebSocketAdapter): this;
useGlobalFilters(...filters: ExceptionFilter[]): this;
useGlobalPipes(...pipes: PipeTransform<any>[]): this;
useGlobalInterceptors(...interceptors: NestInterceptor[]): this;
useGlobalGuards(...guards: CanActivate[]): this;
useStaticAssets(options: any): this;
useStaticAssets(path: string, options?: ServeStaticOptions): any;
setBaseViewsDir(path: string): this;
setViewEngine(engineOrOptions: any): this;
private loadPackage(name, ctx);
private registerMiddlewares(instance);
private isExpress();
private listenToPromise(microservice);
private callDestroyHook();
private callModuleDestroyHook(module);
private hasOnModuleDestroyHook(instance);
export declare class NestApplication extends NestApplicationContext
implements INestApplication,
INestExpressApplication,
INestFastifyApplication {
private readonly httpAdapter;
private readonly config;
private readonly appOptions;
private readonly logger;
private readonly middlewaresModule;
private readonly middlewaresContainer;
private readonly microservicesModule;
private readonly socketModule;
private readonly routesResolver;
private readonly microservices;
private httpServer;
private isInitialized;
constructor(
container: NestContainer,
httpAdapter: HttpServer,
config: ApplicationConfig,
appOptions?: NestApplicationOptions,
);
registerHttpServer(): void;
applyOptions(): this;
createServer(): any;
getUnderlyingHttpServer(): any;
registerModules(): Promise<void>;
init(): Promise<this>;
registerParserMiddlewares(): any;
isMiddlewareApplied(httpAdapter: HttpServer, name: string): boolean;
registerRouter(): Promise<void>;
connectMicroservice(options: MicroserviceOptions): INestMicroservice;
getMicroservices(): INestMicroservice[];
getHttpServer(): http.Server;
startAllMicroservices(callback?: () => void): this;
startAllMicroservicesAsync(): Promise<void>;
use(...args: any[]): this;
engine(...args: any[]): this;
set(...args: any[]): this;
disable(...args: any[]): this;
enable(...args: any[]): this;
register(...args: any[]): this;
inject(...args: any[]): any;
enableCors(options?: CorsOptions): this;
listen(port: number | string, callback?: () => void): any;
listen(port: number | string, hostname: string, callback?: () => void): any;
listenAsync(port: number | string, hostname?: string): Promise<any>;
close(): void;
setGlobalPrefix(prefix: string): this;
useWebSocketAdapter(adapter: WebSocketAdapter): this;
useGlobalFilters(...filters: ExceptionFilter[]): this;
useGlobalPipes(...pipes: PipeTransform<any>[]): this;
useGlobalInterceptors(...interceptors: NestInterceptor[]): this;
useGlobalGuards(...guards: CanActivate[]): this;
useStaticAssets(options: any): this;
useStaticAssets(path: string, options?: ServeStaticOptions): any;
setBaseViewsDir(path: string): this;
setViewEngine(engineOrOptions: any): this;
private loadPackage(name, ctx);
private registerMiddlewares(instance);
private isExpress();
private listenToPromise(microservice);
private callDestroyHook();
private callModuleDestroyHook(module);
private hasOnModuleDestroyHook(instance);
}

0 comments on commit 5d28b98

Please sign in to comment.