@innv/nest-initializer
Version:
Uma plataforma fluente e opinativa para inicializar e configurar aplicações NestJS com as melhores práticas.
80 lines (79 loc) • 3.56 kB
TypeScript
import 'reflect-metadata';
import { CanActivate, ExceptionFilter, INestApplication, NestInterceptor, PipeTransform, Type, ValidationPipeOptions, VersioningOptions } from '@nestjs/common';
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
import { AbstractHttpAdapter } from '@nestjs/core';
import { SwaggerCustomOptions, SwaggerDocumentOptions } from '@nestjs/swagger';
import { TerminusHealthCheckOptions } from '../features';
import { CachingStarterOptions, MongooseStarterOptions, TypeOrmStarterOptions } from '../starters';
import { ResponseMapper } from '../interceptors/response-pattern.interceptor';
export interface AppInitializerPlugin {
apply(app: INestApplication): Promise<void> | void;
}
export type SwaggerDocumentTags = {
name: string;
description?: string;
};
export type SwaggerOptions = {
title: string;
description: string;
version: string;
tags?: SwaggerDocumentTags[];
path?: string;
documentOptions?: SwaggerDocumentOptions;
customOptions?: SwaggerCustomOptions;
};
type AppConfigurator<T extends INestApplication> = (app: AppInitializer<T>) => void;
export declare class AppInitializer<T extends INestApplication = INestApplication> {
private app;
private readonly module;
private readonly adapter?;
private readonly logger;
private port;
private globalPrefix?;
private versioningOptions?;
private corsOptions?;
private swaggerOptions?;
private readonly setupFunctions;
private readonly plugins;
private readonly featureModules;
private autoDiscoveredComponents?;
private readonly globalProviders;
private readonly nexusClientProviders;
private readonly globalInterceptors;
private readonly factoryGeneratedControllers;
private constructor();
useDevelopmentDefaults(swaggerOptions: Omit<SwaggerOptions, 'path'>): this;
useProductionDefaults(): this;
when(condition: boolean, configure: (builder: this) => void): this;
withHealthCheck(options: TerminusHealthCheckOptions): this;
withMetrics(): this;
static bootstrap<T extends INestApplication = INestApplication>(module: Type, configurator: AppConfigurator<T>): Promise<void>;
static bootstrap<T extends INestApplication = INestApplication>(module: Type, adapter: AbstractHttpAdapter, configurator: AppConfigurator<T>): Promise<void>;
onPort(port: number): this;
withPlugin(plugin: AppInitializerPlugin): this;
withVersioning(options: VersioningOptions): this;
withGlobalPrefix(prefix: string): this;
withCors(options?: CorsOptions): this;
withValidationPipe(options?: ValidationPipeOptions): this;
useGlobalPipe(pipe: Type<PipeTransform>): this;
useGlobalFilter(filter: Type<ExceptionFilter>): this;
useGlobalGuard(guard: Type<CanActivate>): this;
useGlobalInterceptor(interceptor: Type<NestInterceptor>): this;
withClassSerializer(): this;
withSwagger(options: SwaggerOptions): this;
withGracefulShutdown(): this;
useHelmet(): this;
enableCompression(): this;
withValidatedConfig<T extends object>(schema: Type<T>): this;
withTypeOrm(options?: TypeOrmStarterOptions): this;
withMongoose(options?: MongooseStarterOptions): this;
withCaching(options?: CachingStarterOptions): this;
getApp(): T;
withAutoDiscovery(options: {
basePath: string;
}): this;
addGlobalInterceptor(interceptor: NestInterceptor): this;
withResponseMapper<T>(mapper: ResponseMapper<T>): this;
private listen;
}
export {};