@innv/nest-initializer 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -41
- package/dist/cjs/core/app-initializer.d.ts +81 -0
- package/dist/cjs/core/app-initializer.js +22 -162
- package/dist/cjs/core/app-initializer.js.map +1 -0
- package/dist/cjs/core/auto-discovery.helper.d.ts +10 -0
- package/dist/cjs/core/auto-discovery.helper.js +7 -9
- package/dist/cjs/core/auto-discovery.helper.js.map +1 -0
- package/dist/cjs/core/config-validator.helper.d.ts +2 -0
- package/dist/cjs/core/config-validator.helper.js +1 -7
- package/dist/cjs/core/config-validator.helper.js.map +1 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +3 -15
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/features/health.controller.d.ts +11 -0
- package/dist/cjs/features/health.controller.js +11 -54
- package/dist/cjs/features/health.controller.js.map +1 -0
- package/dist/cjs/features/index-page.factory.d.ts +8 -0
- package/dist/cjs/features/index-page.factory.js +30 -0
- package/dist/cjs/features/index-page.factory.js.map +1 -0
- package/dist/cjs/features/index.d.ts +2 -0
- package/dist/cjs/features/index.js +4 -16
- package/dist/cjs/features/index.js.map +1 -0
- package/dist/cjs/features/metrics/metrics.controller.d.ts +6 -0
- package/dist/cjs/features/metrics/metrics.controller.js +10 -20
- package/dist/cjs/features/metrics/metrics.controller.js.map +1 -0
- package/dist/cjs/features/metrics/metrics.interceptor.d.ts +8 -0
- package/dist/cjs/features/metrics/metrics.interceptor.js +5 -15
- package/dist/cjs/features/metrics/metrics.interceptor.js.map +1 -0
- package/dist/cjs/features/metrics/metrics.module.d.ts +4 -0
- package/dist/cjs/features/metrics/metrics.module.js +3 -7
- package/dist/cjs/features/metrics/metrics.module.js.map +1 -0
- package/dist/cjs/features/metrics/metrics.provider.d.ts +2 -0
- package/dist/cjs/features/metrics/metrics.provider.js +2 -1
- package/dist/cjs/features/metrics/metrics.provider.js.map +1 -0
- package/dist/cjs/features/metrics/metrics.tokens.d.ts +2 -0
- package/dist/cjs/features/metrics/metrics.tokens.js +1 -0
- package/dist/cjs/features/metrics/metrics.tokens.js.map +1 -0
- package/dist/cjs/features/terminus-health-check.module.d.ts +11 -0
- package/dist/cjs/features/terminus-health-check.module.js +3 -7
- package/dist/cjs/features/terminus-health-check.module.js.map +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +4 -16
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interceptors/response-pattern.interceptor.d.ts +8 -0
- package/dist/cjs/interceptors/response-pattern.interceptor.js +1 -0
- package/dist/cjs/interceptors/response-pattern.interceptor.js.map +1 -0
- package/dist/cjs/plugins/index.d.ts +3 -0
- package/dist/cjs/plugins/index.js +5 -17
- package/dist/cjs/plugins/index.js.map +1 -0
- package/dist/cjs/plugins/rate-limiter.plugin.d.ts +8 -0
- package/dist/cjs/plugins/rate-limiter.plugin.js +3 -4
- package/dist/cjs/plugins/rate-limiter.plugin.js.map +1 -0
- package/dist/cjs/plugins/request-logger.plugin.d.ts +5 -0
- package/dist/cjs/plugins/request-logger.plugin.js +3 -4
- package/dist/cjs/plugins/request-logger.plugin.js.map +1 -0
- package/dist/cjs/plugins/typeorm-migration.plugin.d.ts +6 -0
- package/dist/cjs/plugins/typeorm-migration.plugin.js +1 -9
- package/dist/cjs/plugins/typeorm-migration.plugin.js.map +1 -0
- package/dist/cjs/starters/caching.starter.d.ts +5 -0
- package/dist/cjs/starters/caching.starter.js +1 -4
- package/dist/cjs/starters/caching.starter.js.map +1 -0
- package/dist/cjs/starters/index.d.ts +3 -0
- package/dist/cjs/starters/index.js +5 -17
- package/dist/cjs/starters/index.js.map +1 -0
- package/dist/cjs/starters/mongoose.starter.d.ts +9 -0
- package/dist/cjs/starters/mongoose.starter.js +1 -4
- package/dist/cjs/starters/mongoose.starter.js.map +1 -0
- package/dist/cjs/starters/typeorm.starter.d.ts +12 -0
- package/dist/cjs/starters/typeorm.starter.js +1 -4
- package/dist/cjs/starters/typeorm.starter.js.map +1 -0
- package/dist/esm/core/app-initializer.d.ts +81 -0
- package/dist/esm/core/app-initializer.js +22 -162
- package/dist/esm/core/app-initializer.js.map +1 -0
- package/dist/esm/core/auto-discovery.helper.d.ts +10 -0
- package/dist/esm/core/auto-discovery.helper.js +7 -9
- package/dist/esm/core/auto-discovery.helper.js.map +1 -0
- package/dist/esm/core/config-validator.helper.d.ts +2 -0
- package/dist/esm/core/config-validator.helper.js +1 -7
- package/dist/esm/core/config-validator.helper.js.map +1 -0
- package/dist/esm/core/index.d.ts +1 -0
- package/dist/esm/core/index.js +3 -15
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/features/health.controller.d.ts +11 -0
- package/dist/esm/features/health.controller.js +11 -54
- package/dist/esm/features/health.controller.js.map +1 -0
- package/dist/esm/features/index-page.factory.d.ts +8 -0
- package/dist/esm/features/index-page.factory.js +30 -0
- package/dist/esm/features/index-page.factory.js.map +1 -0
- package/dist/esm/features/index.d.ts +2 -0
- package/dist/esm/features/index.js +4 -16
- package/dist/esm/features/index.js.map +1 -0
- package/dist/esm/features/metrics/metrics.controller.d.ts +6 -0
- package/dist/esm/features/metrics/metrics.controller.js +10 -20
- package/dist/esm/features/metrics/metrics.controller.js.map +1 -0
- package/dist/esm/features/metrics/metrics.interceptor.d.ts +8 -0
- package/dist/esm/features/metrics/metrics.interceptor.js +5 -15
- package/dist/esm/features/metrics/metrics.interceptor.js.map +1 -0
- package/dist/esm/features/metrics/metrics.module.d.ts +4 -0
- package/dist/esm/features/metrics/metrics.module.js +3 -7
- package/dist/esm/features/metrics/metrics.module.js.map +1 -0
- package/dist/esm/features/metrics/metrics.provider.d.ts +2 -0
- package/dist/esm/features/metrics/metrics.provider.js +2 -1
- package/dist/esm/features/metrics/metrics.provider.js.map +1 -0
- package/dist/esm/features/metrics/metrics.tokens.d.ts +2 -0
- package/dist/esm/features/metrics/metrics.tokens.js +1 -0
- package/dist/esm/features/metrics/metrics.tokens.js.map +1 -0
- package/dist/esm/features/terminus-health-check.module.d.ts +11 -0
- package/dist/esm/features/terminus-health-check.module.js +3 -7
- package/dist/esm/features/terminus-health-check.module.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +4 -16
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interceptors/response-pattern.interceptor.d.ts +8 -0
- package/dist/esm/interceptors/response-pattern.interceptor.js +1 -0
- package/dist/esm/interceptors/response-pattern.interceptor.js.map +1 -0
- package/dist/esm/plugins/index.d.ts +3 -0
- package/dist/esm/plugins/index.js +5 -17
- package/dist/esm/plugins/index.js.map +1 -0
- package/dist/esm/plugins/rate-limiter.plugin.d.ts +8 -0
- package/dist/esm/plugins/rate-limiter.plugin.js +3 -4
- package/dist/esm/plugins/rate-limiter.plugin.js.map +1 -0
- package/dist/esm/plugins/request-logger.plugin.d.ts +5 -0
- package/dist/esm/plugins/request-logger.plugin.js +3 -4
- package/dist/esm/plugins/request-logger.plugin.js.map +1 -0
- package/dist/esm/plugins/typeorm-migration.plugin.d.ts +6 -0
- package/dist/esm/plugins/typeorm-migration.plugin.js +1 -9
- package/dist/esm/plugins/typeorm-migration.plugin.js.map +1 -0
- package/dist/esm/starters/caching.starter.d.ts +5 -0
- package/dist/esm/starters/caching.starter.js +1 -4
- package/dist/esm/starters/caching.starter.js.map +1 -0
- package/dist/esm/starters/index.d.ts +3 -0
- package/dist/esm/starters/index.js +5 -17
- package/dist/esm/starters/index.js.map +1 -0
- package/dist/esm/starters/mongoose.starter.d.ts +9 -0
- package/dist/esm/starters/mongoose.starter.js +1 -4
- package/dist/esm/starters/mongoose.starter.js.map +1 -0
- package/dist/esm/starters/typeorm.starter.d.ts +12 -0
- package/dist/esm/starters/typeorm.starter.js +1 -4
- package/dist/esm/starters/typeorm.starter.js.map +1 -0
- package/dist/types/core/app-initializer.d.ts +4 -152
- package/dist/types/core/auto-discovery.helper.d.ts +1 -6
- package/dist/types/core/config-validator.helper.d.ts +0 -7
- package/dist/types/features/index-page.factory.d.ts +8 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/typeorm-migration.plugin.d.ts +0 -9
- package/dist/types/starters/caching.starter.d.ts +0 -15
- package/dist/types/starters/mongoose.starter.d.ts +0 -15
- package/dist/types/starters/typeorm.starter.d.ts +0 -7
- package/package.json +26 -30
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ Diga adeus ao boilerplate repetitivo no `main.ts` e `AppModule`!
|
|
|
19
19
|
- **Configuração Segura (Fail-Fast):** Valide variáveis de ambiente com `class-validator`. Sem mais erros em runtime!
|
|
20
20
|
- **Auto-Discovery ("Component Scanning"):** Detecta e registra automaticamente `@Injectable()` e `@Controller()`.
|
|
21
21
|
- **Produção Pronta por Padrão:**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
- Presets para desenvolvimento e produção (`useDevelopmentDefaults`, `useProductionDefaults`);
|
|
23
|
+
- Helmet, Compressão, Graceful Shutdown e Métricas Prometheus (`.withMetrics`);
|
|
24
|
+
- Health Checks (`.withHealthCheck`).
|
|
25
25
|
- **Extensível:** Sistema de Plugins (`.withPlugin`) para lógicas customizadas.
|
|
26
26
|
- **Flexível:** Suporte nativo a Express e Fastify.
|
|
27
27
|
|
|
@@ -53,6 +53,7 @@ yarn add --dev @types/compression @types/helmet
|
|
|
53
53
|
## 🚀 Quick Start (Exemplo Completo)
|
|
54
54
|
|
|
55
55
|
### 1️⃣ Defina seu Schema de Configuração
|
|
56
|
+
|
|
56
57
|
`src/config/env.schema.ts`:
|
|
57
58
|
|
|
58
59
|
```ts
|
|
@@ -118,9 +119,9 @@ async function bootstrap() {
|
|
|
118
119
|
builder.useProductionDefaults();
|
|
119
120
|
});
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
// Exemplos extras:
|
|
123
|
+
// .useGlobalGuard(JwtAuthGuard)
|
|
124
|
+
// .withPlugin(new MyCustomPlugin())
|
|
124
125
|
});
|
|
125
126
|
}
|
|
126
127
|
|
|
@@ -135,13 +136,13 @@ Pronto! Sua aplicação NestJS está configurada com **validação, banco, cache
|
|
|
135
136
|
|
|
136
137
|
### 🔧 Configuração Core
|
|
137
138
|
|
|
138
|
-
| Método
|
|
139
|
-
|
|
140
|
-
| `AppInitializer.bootstrap(AppModule, configurator)` | Ponto de entrada principal.
|
|
141
|
-
| `onPort(port)`
|
|
142
|
-
| `withGlobalPrefix(prefix)`
|
|
143
|
-
| `withVersioning(options)`
|
|
144
|
-
| `withCors(options)`
|
|
139
|
+
| Método | Descrição |
|
|
140
|
+
| --------------------------------------------------- | ------------------------------- |
|
|
141
|
+
| `AppInitializer.bootstrap(AppModule, configurator)` | Ponto de entrada principal. |
|
|
142
|
+
| `onPort(port)` | Define a porta. |
|
|
143
|
+
| `withGlobalPrefix(prefix)` | Prefixo global para rotas. |
|
|
144
|
+
| `withVersioning(options)` | Configura versionamento de API. |
|
|
145
|
+
| `withCors(options)` | Habilita CORS. |
|
|
145
146
|
|
|
146
147
|
---
|
|
147
148
|
|
|
@@ -167,6 +168,7 @@ Todos configuram seus módulos respectivos (`TypeOrmModule`, `MongooseModule`, `
|
|
|
167
168
|
|
|
168
169
|
`withAutoDiscovery({ basePath })`
|
|
169
170
|
Varre o diretório e registra automaticamente:
|
|
171
|
+
|
|
170
172
|
- `@Injectable()` como providers
|
|
171
173
|
- `@Controller()` como controllers
|
|
172
174
|
|
|
@@ -176,23 +178,23 @@ Ignora `*.module.*`, `*.spec.*`, `node_modules`, `features`, `plugins`.
|
|
|
176
178
|
|
|
177
179
|
### 🧱 Pipeline Global
|
|
178
180
|
|
|
179
|
-
| Método
|
|
180
|
-
|
|
181
|
-
| `withValidationPipe()`
|
|
182
|
-
| `useGlobalPipe(pipe)`
|
|
183
|
-
| `useGlobalFilter(filter)`
|
|
184
|
-
| `useGlobalGuard(guard)`
|
|
185
|
-
| `useGlobalInterceptor(interceptor)` | Interceptor global.
|
|
186
|
-
| `withClassSerializer()`
|
|
181
|
+
| Método | Função |
|
|
182
|
+
| ----------------------------------- | ----------------------------------- |
|
|
183
|
+
| `withValidationPipe()` | Registra `ValidationPipe` global. |
|
|
184
|
+
| `useGlobalPipe(pipe)` | Pipe customizado global. |
|
|
185
|
+
| `useGlobalFilter(filter)` | Filtro de exceção global. |
|
|
186
|
+
| `useGlobalGuard(guard)` | Guard global. |
|
|
187
|
+
| `useGlobalInterceptor(interceptor)` | Interceptor global. |
|
|
188
|
+
| `withClassSerializer()` | Ativa `ClassSerializerInterceptor`. |
|
|
187
189
|
|
|
188
190
|
---
|
|
189
191
|
|
|
190
192
|
### 🩺 Observabilidade ("Actuator")
|
|
191
193
|
|
|
192
|
-
| Método
|
|
193
|
-
|
|
194
|
+
| Método | Descrição |
|
|
195
|
+
| -------------------------- | -------------------------------------------------- |
|
|
194
196
|
| `withHealthCheck(options)` | Cria endpoint `/health` usando `@nestjs/terminus`. |
|
|
195
|
-
| `withMetrics()`
|
|
197
|
+
| `withMetrics()` | Cria endpoint `/metrics` no formato Prometheus. |
|
|
196
198
|
|
|
197
199
|
Suporte nativo a métricas HTTP (latência, contadores, etc).
|
|
198
200
|
|
|
@@ -200,38 +202,38 @@ Suporte nativo a métricas HTTP (latência, contadores, etc).
|
|
|
200
202
|
|
|
201
203
|
### 🧰 Middlewares e Hooks
|
|
202
204
|
|
|
203
|
-
| Método
|
|
204
|
-
|
|
205
|
-
| `withGracefulShutdown()` | Habilita `enableShutdownHooks()`.
|
|
206
|
-
| `useHelmet()`
|
|
207
|
-
| `enableCompression()`
|
|
205
|
+
| Método | Ação |
|
|
206
|
+
| ------------------------ | ----------------------------------- |
|
|
207
|
+
| `withGracefulShutdown()` | Habilita `enableShutdownHooks()`. |
|
|
208
|
+
| `useHelmet()` | Adiciona `helmet()` para segurança. |
|
|
209
|
+
| `enableCompression()` | Adiciona `compression()` para gzip. |
|
|
208
210
|
|
|
209
211
|
---
|
|
210
212
|
|
|
211
213
|
### 📘 Swagger (OpenAPI)
|
|
212
214
|
|
|
213
|
-
| Método
|
|
214
|
-
|
|
215
|
-
| `withSwagger(options)`
|
|
216
|
-
| `withAdvancedSwaggerUI()` | Tema escuro e UI aprimorada.
|
|
215
|
+
| Método | Descrição |
|
|
216
|
+
| ------------------------- | ------------------------------- |
|
|
217
|
+
| `withSwagger(options)` | Configura documentação Swagger. |
|
|
218
|
+
| `withAdvancedSwaggerUI()` | Tema escuro e UI aprimorada. |
|
|
217
219
|
|
|
218
220
|
---
|
|
219
221
|
|
|
220
222
|
### 🧩 Extensibilidade
|
|
221
223
|
|
|
222
|
-
| Método
|
|
223
|
-
|
|
224
|
-
| `withPlugin(plugin)`
|
|
225
|
-
| `when(condition, fn)` | Executa blocos condicionais.
|
|
224
|
+
| Método | Descrição |
|
|
225
|
+
| --------------------- | ------------------------------ |
|
|
226
|
+
| `withPlugin(plugin)` | Adiciona plugins customizados. |
|
|
227
|
+
| `when(condition, fn)` | Executa blocos condicionais. |
|
|
226
228
|
|
|
227
229
|
---
|
|
228
230
|
|
|
229
231
|
### 🪄 Presets
|
|
230
232
|
|
|
231
|
-
| Método
|
|
232
|
-
|
|
233
|
-
| `useDevelopmentDefaults(swaggerOptions)` | Atalho para Swagger + Logger.
|
|
234
|
-
| `useProductionDefaults()`
|
|
233
|
+
| Método | Descrição |
|
|
234
|
+
| ---------------------------------------- | -------------------------------------------------------- |
|
|
235
|
+
| `useDevelopmentDefaults(swaggerOptions)` | Atalho para Swagger + Logger. |
|
|
236
|
+
| `useProductionDefaults()` | Atalho para Helmet, Compression, Shutdown e RateLimiter. |
|
|
235
237
|
|
|
236
238
|
---
|
|
237
239
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { CanActivate, ExceptionFilter, INestApplication, NestInterceptor, PipeTransform, Type, ValidationPipeOptions, VersioningOptions } from '@nestjs/common';
|
|
3
|
+
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
|
+
import { AbstractHttpAdapter } from '@nestjs/core';
|
|
5
|
+
import { SwaggerCustomOptions, SwaggerDocumentOptions } from '@nestjs/swagger';
|
|
6
|
+
import { TerminusHealthCheckOptions } from '../features';
|
|
7
|
+
import { CachingStarterOptions, MongooseStarterOptions, TypeOrmStarterOptions } from '../starters';
|
|
8
|
+
import { ResponseMapper } from '../interceptors/response-pattern.interceptor';
|
|
9
|
+
import { IndexPageOptions } from '../features/index-page.factory';
|
|
10
|
+
export interface AppInitializerPlugin {
|
|
11
|
+
apply(app: INestApplication): Promise<void> | void;
|
|
12
|
+
}
|
|
13
|
+
export type SwaggerDocumentTags = {
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
};
|
|
17
|
+
export type SwaggerOptions = {
|
|
18
|
+
title: string;
|
|
19
|
+
description: string;
|
|
20
|
+
version: string;
|
|
21
|
+
tags?: SwaggerDocumentTags[];
|
|
22
|
+
path?: string;
|
|
23
|
+
documentOptions?: SwaggerDocumentOptions;
|
|
24
|
+
customOptions?: SwaggerCustomOptions;
|
|
25
|
+
};
|
|
26
|
+
type AppConfigurator<T extends INestApplication> = (app: AppInitializer<T>) => void;
|
|
27
|
+
export declare class AppInitializer<T extends INestApplication = INestApplication> {
|
|
28
|
+
private app;
|
|
29
|
+
private readonly module;
|
|
30
|
+
private readonly adapter?;
|
|
31
|
+
private readonly logger;
|
|
32
|
+
private port;
|
|
33
|
+
private globalPrefix?;
|
|
34
|
+
private versioningOptions?;
|
|
35
|
+
private corsOptions?;
|
|
36
|
+
private swaggerOptions?;
|
|
37
|
+
private readonly setupFunctions;
|
|
38
|
+
private readonly plugins;
|
|
39
|
+
private readonly featureModules;
|
|
40
|
+
private autoDiscoveredComponents?;
|
|
41
|
+
private readonly globalProviders;
|
|
42
|
+
private readonly nexusClientProviders;
|
|
43
|
+
private readonly globalInterceptors;
|
|
44
|
+
private readonly factoryGeneratedControllers;
|
|
45
|
+
private constructor();
|
|
46
|
+
useDevelopmentDefaults(swaggerOptions: Omit<SwaggerOptions, 'path'>): this;
|
|
47
|
+
useProductionDefaults(): this;
|
|
48
|
+
when(condition: boolean, configure: (builder: this) => void): this;
|
|
49
|
+
withHealthCheck(options: TerminusHealthCheckOptions): this;
|
|
50
|
+
withMetrics(): this;
|
|
51
|
+
static bootstrap<T extends INestApplication = INestApplication>(module: Type, configurator: AppConfigurator<T>): Promise<void>;
|
|
52
|
+
static bootstrap<T extends INestApplication = INestApplication>(module: Type, adapter: AbstractHttpAdapter, configurator: AppConfigurator<T>): Promise<void>;
|
|
53
|
+
onPort(port: number): this;
|
|
54
|
+
withPlugin(plugin: AppInitializerPlugin): this;
|
|
55
|
+
withVersioning(options: VersioningOptions): this;
|
|
56
|
+
withGlobalPrefix(prefix: string): this;
|
|
57
|
+
withCors(options?: CorsOptions): this;
|
|
58
|
+
withValidationPipe(options?: ValidationPipeOptions): this;
|
|
59
|
+
useGlobalPipe(pipe: Type<PipeTransform>): this;
|
|
60
|
+
useGlobalFilter(filter: Type<ExceptionFilter>): this;
|
|
61
|
+
useGlobalGuard(guard: Type<CanActivate>): this;
|
|
62
|
+
useGlobalInterceptor(interceptor: Type<NestInterceptor>): this;
|
|
63
|
+
withClassSerializer(): this;
|
|
64
|
+
withSwagger(options: SwaggerOptions): this;
|
|
65
|
+
withGracefulShutdown(): this;
|
|
66
|
+
useHelmet(): this;
|
|
67
|
+
enableCompression(): this;
|
|
68
|
+
withValidatedConfig<T extends object>(schema: Type<T>): this;
|
|
69
|
+
withTypeOrm(options?: TypeOrmStarterOptions): this;
|
|
70
|
+
withMongoose(options?: MongooseStarterOptions): this;
|
|
71
|
+
withCaching(options?: CachingStarterOptions): this;
|
|
72
|
+
getApp(): T;
|
|
73
|
+
withAutoDiscovery(options: {
|
|
74
|
+
basePath: string;
|
|
75
|
+
}): this;
|
|
76
|
+
withIndexPage(options?: IndexPageOptions): this;
|
|
77
|
+
addGlobalInterceptor(interceptor: NestInterceptor): this;
|
|
78
|
+
withResponseMapper<T>(mapper: ResponseMapper<T>): this;
|
|
79
|
+
private listen;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.AppInitializer = void 0;
|
|
13
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
const nexus_1 = require("@innv/nexus");
|
|
14
7
|
const common_1 = require("@nestjs/common");
|
|
15
8
|
const config_1 = require("@nestjs/config");
|
|
16
9
|
const core_1 = require("@nestjs/core");
|
|
17
10
|
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
-
const compression_1 = __importDefault(require("compression"));
|
|
19
|
-
const helmet_1 = __importDefault(require("helmet"));
|
|
11
|
+
const compression_1 = tslib_1.__importDefault(require("compression"));
|
|
12
|
+
const helmet_1 = tslib_1.__importDefault(require("helmet"));
|
|
20
13
|
const auto_discovery_helper_1 = require("./auto-discovery.helper");
|
|
21
14
|
const config_validator_helper_1 = require("./config-validator.helper");
|
|
22
15
|
const features_1 = require("../features");
|
|
23
16
|
const plugins_1 = require("../plugins");
|
|
24
17
|
const starters_1 = require("../starters");
|
|
25
18
|
const response_pattern_interceptor_1 = require("../interceptors/response-pattern.interceptor");
|
|
26
|
-
|
|
27
|
-
* Uma classe fluente (Builder) para inicializar uma aplicação NestJS de forma declarativa.
|
|
28
|
-
*/
|
|
19
|
+
const index_page_factory_1 = require("../features/index-page.factory");
|
|
29
20
|
class AppInitializer {
|
|
30
21
|
app;
|
|
31
22
|
module;
|
|
@@ -39,29 +30,20 @@ class AppInitializer {
|
|
|
39
30
|
setupFunctions = [];
|
|
40
31
|
plugins = [];
|
|
41
32
|
featureModules = [];
|
|
42
|
-
advancedSwaggerUiOptions;
|
|
43
33
|
autoDiscoveredComponents;
|
|
44
34
|
globalProviders = [];
|
|
35
|
+
nexusClientProviders = [];
|
|
45
36
|
globalInterceptors = [];
|
|
46
37
|
factoryGeneratedControllers = [];
|
|
47
38
|
constructor(module, adapter) {
|
|
48
39
|
this.module = module;
|
|
49
40
|
this.adapter = adapter;
|
|
50
41
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Aplica um conjunto de configurações padrão recomendadas para o ambiente de desenvolvimento.
|
|
53
|
-
* Inclui Swagger e um logger de requisições.
|
|
54
|
-
* @param swaggerOptions Opções para customizar a documentação Swagger.
|
|
55
|
-
*/
|
|
56
42
|
useDevelopmentDefaults(swaggerOptions) {
|
|
57
43
|
this.withSwagger({ ...swaggerOptions, path: 'docs' });
|
|
58
44
|
this.withPlugin(new plugins_1.RequestLoggerPlugin());
|
|
59
45
|
return this;
|
|
60
46
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Aplica um conjunto de configurações padrão recomendadas para o ambiente de produção.
|
|
63
|
-
* Inclui Helmet, compressão, graceful shutdown e um rate limiter básico.
|
|
64
|
-
*/
|
|
65
47
|
useProductionDefaults() {
|
|
66
48
|
this.useHelmet();
|
|
67
49
|
this.enableCompression();
|
|
@@ -69,11 +51,6 @@ class AppInitializer {
|
|
|
69
51
|
this.withPlugin(new plugins_1.RateLimiterPlugin());
|
|
70
52
|
return this;
|
|
71
53
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Aplica um bloco de configurações de forma condicional.
|
|
74
|
-
* @param condition A condição booleana. Se for `true`, o callback de configuração será executado.
|
|
75
|
-
* @param configure A função de callback que recebe o builder para aplicar as configurações.
|
|
76
|
-
*/
|
|
77
54
|
when(condition, configure) {
|
|
78
55
|
if (condition) {
|
|
79
56
|
configure(this);
|
|
@@ -84,21 +61,10 @@ class AppInitializer {
|
|
|
84
61
|
this.featureModules.push(features_1.TerminusHealthCheckModule.forRoot(options));
|
|
85
62
|
return this;
|
|
86
63
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Habilita a coleta e exposição de métricas no padrão Prometheus
|
|
89
|
-
* no endpoint /metrics. Inclui métricas padrão do Node.js
|
|
90
|
-
* e métricas de latência de requisições HTTP.
|
|
91
|
-
*/
|
|
92
64
|
withMetrics() {
|
|
93
65
|
this.featureModules.push(features_1.MetricsModule.forRoot());
|
|
94
66
|
return this;
|
|
95
67
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Ponto de entrada estático para criar, configurar e iniciar a aplicação.
|
|
98
|
-
* @param module O módulo raiz da aplicação (ex: AppModule).
|
|
99
|
-
* @param adapterOrConfigurator O adaptador HTTP ou a função de configuração.
|
|
100
|
-
* @param configurator Uma função de callback que recebe o builder para aplicar as configurações.
|
|
101
|
-
*/
|
|
102
68
|
static async bootstrap(module, adapterOrConfigurator, configurator) {
|
|
103
69
|
const isExpress = typeof adapterOrConfigurator === 'function';
|
|
104
70
|
const adapter = isExpress ? undefined : adapterOrConfigurator;
|
|
@@ -122,51 +88,26 @@ class AppInitializer {
|
|
|
122
88
|
process.exit(1);
|
|
123
89
|
}
|
|
124
90
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Define a porta em que a aplicação vai rodar.
|
|
127
|
-
* @param port O número da porta.
|
|
128
|
-
*/
|
|
129
91
|
onPort(port) {
|
|
130
92
|
this.port = port;
|
|
131
93
|
return this;
|
|
132
94
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Registra um plugin para ser executado durante a inicialização.
|
|
135
|
-
* @param plugin Uma instância de um objeto que implementa a interface AppInitializerPlugin.
|
|
136
|
-
*/
|
|
137
95
|
withPlugin(plugin) {
|
|
138
96
|
this.plugins.push(plugin);
|
|
139
97
|
return this;
|
|
140
98
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Habilita e configura o versionamento da API.
|
|
143
|
-
* @param options As opções de versionamento do NestJS.
|
|
144
|
-
*/
|
|
145
99
|
withVersioning(options) {
|
|
146
100
|
this.versioningOptions = options;
|
|
147
101
|
return this;
|
|
148
102
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Define um prefixo global para todas as rotas da aplicação (ex: /api/v1).
|
|
151
|
-
* @param prefix O prefixo a ser aplicado.
|
|
152
|
-
*/
|
|
153
103
|
withGlobalPrefix(prefix) {
|
|
154
104
|
this.globalPrefix = prefix.startsWith('/') ? prefix : `/${prefix}`;
|
|
155
105
|
return this;
|
|
156
106
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Habilita e configura o Cross-Origin Resource Sharing (CORS).
|
|
159
|
-
* @param options As opções de configuração do CORS.
|
|
160
|
-
*/
|
|
161
107
|
withCors(options = {}) {
|
|
162
108
|
this.corsOptions = options;
|
|
163
109
|
return this;
|
|
164
110
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Adiciona o ValidationPipe global com opções customizadas.
|
|
167
|
-
* Esta é a forma recomendada de habilitar a validação padrão.
|
|
168
|
-
* @param options Opções de configuração para o ValidationPipe.
|
|
169
|
-
*/
|
|
170
111
|
withValidationPipe(options = {}) {
|
|
171
112
|
const defaultOptions = {
|
|
172
113
|
whitelist: true,
|
|
@@ -181,11 +122,6 @@ class AppInitializer {
|
|
|
181
122
|
});
|
|
182
123
|
return this;
|
|
183
124
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Registra um Pipe global customizado (ex: um pipe de parsing).
|
|
186
|
-
* O pipe participará da Injeção de Dependência.
|
|
187
|
-
* @param pipe A *classe* do pipe a ser registrada.
|
|
188
|
-
*/
|
|
189
125
|
useGlobalPipe(pipe) {
|
|
190
126
|
this.globalProviders.push({
|
|
191
127
|
provide: core_1.APP_PIPE,
|
|
@@ -193,11 +129,6 @@ class AppInitializer {
|
|
|
193
129
|
});
|
|
194
130
|
return this;
|
|
195
131
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Registra um Filtro de Exceção global (ex: HttpExceptionFilter).
|
|
198
|
-
* O filtro participará da Injeção de Dependência.
|
|
199
|
-
* @param filter A *classe* do filtro a ser registrada.
|
|
200
|
-
*/
|
|
201
132
|
useGlobalFilter(filter) {
|
|
202
133
|
this.globalProviders.push({
|
|
203
134
|
provide: core_1.APP_FILTER,
|
|
@@ -205,11 +136,6 @@ class AppInitializer {
|
|
|
205
136
|
});
|
|
206
137
|
return this;
|
|
207
138
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Registra um Guard global (ex: JwtAuthGuard).
|
|
210
|
-
* O guard participará da Injeção de Dependência.
|
|
211
|
-
* @param guard A *classe* do guard a ser registrada.
|
|
212
|
-
*/
|
|
213
139
|
useGlobalGuard(guard) {
|
|
214
140
|
this.globalProviders.push({
|
|
215
141
|
provide: core_1.APP_GUARD,
|
|
@@ -217,11 +143,6 @@ class AppInitializer {
|
|
|
217
143
|
});
|
|
218
144
|
return this;
|
|
219
145
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Registra um Interceptor global (ex: LoggingInterceptor).
|
|
222
|
-
* O interceptor participará da Injeção de Dependência.
|
|
223
|
-
* @param interceptor A *classe* do interceptor a ser registrada.
|
|
224
|
-
*/
|
|
225
146
|
useGlobalInterceptor(interceptor) {
|
|
226
147
|
this.globalProviders.push({
|
|
227
148
|
provide: core_1.APP_INTERCEPTOR,
|
|
@@ -229,11 +150,6 @@ class AppInitializer {
|
|
|
229
150
|
});
|
|
230
151
|
return this;
|
|
231
152
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Registra o ClassSerializerInterceptor globalmente.
|
|
234
|
-
* Essencial para transformações de DTO (@Exclude, @Expose).
|
|
235
|
-
* Ele automaticamente recebe o Reflector via DI.
|
|
236
|
-
*/
|
|
237
153
|
withClassSerializer() {
|
|
238
154
|
this.globalProviders.push({
|
|
239
155
|
provide: core_1.APP_INTERCEPTOR,
|
|
@@ -241,56 +157,22 @@ class AppInitializer {
|
|
|
241
157
|
});
|
|
242
158
|
return this;
|
|
243
159
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Habilita e configura a documentação da API via Swagger (OpenAPI).
|
|
246
|
-
* @param options As opções para construir a documentação.
|
|
247
|
-
*/
|
|
248
160
|
withSwagger(options) {
|
|
249
161
|
this.swaggerOptions = { path: 'docs', ...options };
|
|
250
162
|
return this;
|
|
251
163
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Aplica customizações avançadas à interface do Swagger UI.
|
|
254
|
-
* Isso pode incluir temas, scripts e outras configurações visuais.
|
|
255
|
-
* Por padrão, aplica um tema escuro e algumas configurações de layout.
|
|
256
|
-
*/
|
|
257
|
-
withAdvancedSwaggerUI() {
|
|
258
|
-
// Aponta para os arquivos de customização que criamos.
|
|
259
|
-
// O __dirname aponta para o diretório compilado, que deve ser 'dist' ou 'build'.
|
|
260
|
-
// Os arquivos .css e .js devem estar lá também após a compilação.
|
|
261
|
-
this.advancedSwaggerUiOptions = {
|
|
262
|
-
customCss: (0, path_1.join)(__dirname, 'swagger-ui-customization', 'swagger-dark-theme.css'),
|
|
263
|
-
customJs: (0, path_1.join)(__dirname, 'swagger-ui-customization', 'swagger-custom.js'),
|
|
264
|
-
};
|
|
265
|
-
return this;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Habilita os 'shutdown hooks' do NestJS para um desligamento gracioso.
|
|
269
|
-
*/
|
|
270
164
|
withGracefulShutdown() {
|
|
271
165
|
this.setupFunctions.push((app) => app.enableShutdownHooks());
|
|
272
166
|
return this;
|
|
273
167
|
}
|
|
274
|
-
/**
|
|
275
|
-
* Adiciona o middleware de segurança Helmet com configurações padrão.
|
|
276
|
-
*/
|
|
277
168
|
useHelmet() {
|
|
278
169
|
this.setupFunctions.push((app) => app.use((0, helmet_1.default)()));
|
|
279
170
|
return this;
|
|
280
171
|
}
|
|
281
|
-
/**
|
|
282
|
-
* Adiciona o middleware de compressão (gzip) para as respostas.
|
|
283
|
-
*/
|
|
284
172
|
enableCompression() {
|
|
285
173
|
this.setupFunctions.push((app) => app.use((0, compression_1.default)()));
|
|
286
174
|
return this;
|
|
287
175
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Carrega e valida as variáveis de ambiente na inicialização
|
|
290
|
-
* usando um schema de validação (classe com decoradores class-validator).
|
|
291
|
-
* Se a validação falhar, a aplicação não será iniciada.
|
|
292
|
-
* @param schema A classe de schema para validar (ex: EnvironmentVariables).
|
|
293
|
-
*/
|
|
294
176
|
withValidatedConfig(schema) {
|
|
295
177
|
const configModule = config_1.ConfigModule.forRoot({
|
|
296
178
|
isGlobal: true,
|
|
@@ -299,10 +181,6 @@ class AppInitializer {
|
|
|
299
181
|
this.featureModules.push(configModule);
|
|
300
182
|
return this;
|
|
301
183
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Configura e registra automaticamente o TypeOrmModule (Estilo "Starter").
|
|
304
|
-
* @param options Opções para o "Starter" de TypeORM.
|
|
305
|
-
*/
|
|
306
184
|
withTypeOrm(options = {}) {
|
|
307
185
|
const starter = (0, starters_1.createTypeOrmStarter)(options);
|
|
308
186
|
this.featureModules.push(starter.module);
|
|
@@ -311,60 +189,40 @@ class AppInitializer {
|
|
|
311
189
|
}
|
|
312
190
|
return this;
|
|
313
191
|
}
|
|
314
|
-
/**
|
|
315
|
-
* Configura e registra automaticamente o MongooseModule (Estilo "Starter").
|
|
316
|
-
* Usa a configuração global (de .withValidatedConfig) para se conectar
|
|
317
|
-
* ao MongoDB e descobre schemas automaticamente.
|
|
318
|
-
*
|
|
319
|
-
* @param options Opções para o "Starter" de Mongoose.
|
|
320
|
-
*/
|
|
321
192
|
withMongoose(options = {}) {
|
|
322
193
|
const starter = (0, starters_1.createMongooseStarter)(options);
|
|
323
194
|
this.featureModules.push(starter.module);
|
|
324
195
|
return this;
|
|
325
196
|
}
|
|
326
|
-
/**
|
|
327
|
-
* Configura e registra automaticamente o CacheModule (Estilo "Starter").
|
|
328
|
-
* Usa a configuração global (de .withValidatedConfig) para se conectar
|
|
329
|
-
* ao Redis e torna o cache globalmente disponível.
|
|
330
|
-
*
|
|
331
|
-
* @param options Opções para o "Starter" de Cache.
|
|
332
|
-
*/
|
|
333
197
|
withCaching(options = {}) {
|
|
334
198
|
const cacheDynamicModule = (0, starters_1.createCachingStarter)(options);
|
|
335
199
|
this.featureModules.push(cacheDynamicModule);
|
|
336
200
|
return this;
|
|
337
201
|
}
|
|
338
|
-
/**
|
|
339
|
-
* Retorna a instância da aplicação NestJS (INestApplication) após a inicialização.
|
|
340
|
-
* @throws Error se a aplicação ainda não foi inicializada.
|
|
341
|
-
*/
|
|
342
202
|
getApp() {
|
|
343
203
|
return this.app;
|
|
344
204
|
}
|
|
345
|
-
/**
|
|
346
|
-
* Habilita a descoberta e registro automático de Providers e Controllers.
|
|
347
|
-
* Varre o projeto em busca de classes com @Injectable() e @Controller()
|
|
348
|
-
* e as adiciona ao módulo raiz.
|
|
349
|
-
* @param options Opções para configurar a descoberta.
|
|
350
|
-
*/
|
|
351
205
|
withAutoDiscovery(options) {
|
|
352
206
|
const reflector = new core_1.Reflector();
|
|
353
207
|
this.autoDiscoveredComponents = (0, auto_discovery_helper_1.discoverComponents)(options.basePath, reflector);
|
|
208
|
+
if (this.autoDiscoveredComponents.nexusClients.length > 0) {
|
|
209
|
+
this.logger.log(`[Initializer] Auto-discovery encontrou ${this.autoDiscoveredComponents.nexusClients.length} clientes Nexus.`);
|
|
210
|
+
this.featureModules.push(nexus_1.NexusModule);
|
|
211
|
+
for (const clientClass of this.autoDiscoveredComponents.nexusClients) {
|
|
212
|
+
this.nexusClientProviders.push((0, nexus_1.createNexusClientProvider)(clientClass));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
withIndexPage(options = {}) {
|
|
218
|
+
const IndexController = (0, index_page_factory_1.createIndexPageController)(options);
|
|
219
|
+
this.factoryGeneratedControllers.push(IndexController);
|
|
354
220
|
return this;
|
|
355
221
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Adiciona um Interceptor global diretamente (instância).
|
|
358
|
-
* @param interceptor
|
|
359
|
-
*/
|
|
360
222
|
addGlobalInterceptor(interceptor) {
|
|
361
223
|
this.globalInterceptors.push(interceptor);
|
|
362
224
|
return this;
|
|
363
225
|
}
|
|
364
|
-
/**
|
|
365
|
-
* Adiciona um ResponseMapper global para padronizar respostas.
|
|
366
|
-
* @param mapper
|
|
367
|
-
*/
|
|
368
226
|
withResponseMapper(mapper) {
|
|
369
227
|
this.globalInterceptors.push(new response_pattern_interceptor_1.ResponsePatternInterceptor(mapper));
|
|
370
228
|
return this;
|
|
@@ -375,6 +233,7 @@ class AppInitializer {
|
|
|
375
233
|
const allProviders = [
|
|
376
234
|
...(this.autoDiscoveredComponents?.providers ?? []),
|
|
377
235
|
...this.globalProviders,
|
|
236
|
+
...this.nexusClientProviders,
|
|
378
237
|
];
|
|
379
238
|
const allControllers = [
|
|
380
239
|
...(this.autoDiscoveredComponents?.controllers ?? []),
|
|
@@ -382,7 +241,7 @@ class AppInitializer {
|
|
|
382
241
|
];
|
|
383
242
|
let DynamicRootModule = class DynamicRootModule {
|
|
384
243
|
};
|
|
385
|
-
DynamicRootModule = __decorate([
|
|
244
|
+
DynamicRootModule = tslib_1.__decorate([
|
|
386
245
|
(0, common_1.Module)({
|
|
387
246
|
imports: rootImports,
|
|
388
247
|
controllers: allControllers,
|
|
@@ -431,3 +290,4 @@ class AppInitializer {
|
|
|
431
290
|
}
|
|
432
291
|
}
|
|
433
292
|
exports.AppInitializer = AppInitializer;
|
|
293
|
+
//# sourceMappingURL=app-initializ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GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;YACpD,CAAC;YAED,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC;YACvC,MAAM,QAAQ,GAAG,uBAAa,CAAC,cAAc,CAC3C,IAAI,CAAC,GAAG,EACR,MAAM,EACN,IAAI,CAAC,cAAc,CAAC,eAAe,CACpC,CAAC;YAEF,uBAAa,CAAC,KAAK,CACjB,IAAI,CAAC,cAAc,CAAC,IAAI,IAAI,MAAM,EAClC,IAAI,CAAC,GAAG,EACR,QAAQ,EACR,IAAI,CAAC,cAAc,CAAC,aAAa,CAClC,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,MAAM,EAAE,CAAC,CAAC;QAEtD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,IAAI,MAAM,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,0CAA0C,MAAM,IAAI,WAAW,EAAE,CAClE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxgBD,wCAwgBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
interface DiscoveredComponents {
|
|
4
|
+
providers: Type[];
|
|
5
|
+
controllers: Type[];
|
|
6
|
+
nexusClients: Type[];
|
|
7
|
+
}
|
|
8
|
+
type RequireFn = (id: string) => any;
|
|
9
|
+
export declare function discoverComponents(basePath: string, reflectorInst: Reflector, requireFn?: RequireFn): DiscoveredComponents;
|
|
10
|
+
export {};
|
|
@@ -3,15 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.discoverComponents = discoverComponents;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const glob_1 = require("glob");
|
|
6
|
-
|
|
7
|
-
* Descobre componentes NestJS (Providers e Controllers) em um diretório.
|
|
8
|
-
* @param basePath O diretório raiz para a varredura.
|
|
9
|
-
* @param reflectorInst Uma instância do Reflector.
|
|
10
|
-
* @param requireFn A função 'require' a ser usada (padrão: Node's require).
|
|
11
|
-
*/
|
|
6
|
+
const nexus_1 = require("@innv/nexus");
|
|
12
7
|
function discoverComponents(basePath, reflectorInst, requireFn = require) {
|
|
13
8
|
const providers = [];
|
|
14
9
|
const controllers = [];
|
|
10
|
+
const nexusClients = [];
|
|
15
11
|
const files = (0, glob_1.globSync)((0, path_1.join)(basePath, '**/*.{ts,js}'), {
|
|
16
12
|
ignore: [
|
|
17
13
|
'**/*.module.{ts,js}',
|
|
@@ -34,13 +30,15 @@ function discoverComponents(basePath, reflectorInst, requireFn = require) {
|
|
|
34
30
|
else if (reflectorInst.get('__injectable__', exportedClass)) {
|
|
35
31
|
providers.push(exportedClass);
|
|
36
32
|
}
|
|
33
|
+
else if (reflectorInst.get(nexus_1.API_CLIENT_META_KEY, exportedClass)) {
|
|
34
|
+
nexusClients.push(exportedClass);
|
|
35
|
+
}
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
38
|
}
|
|
41
39
|
catch (_) {
|
|
42
|
-
// Ignora erros
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
return { providers, controllers };
|
|
42
|
+
return { providers, controllers, nexusClients };
|
|
46
43
|
}
|
|
44
|
+
//# sourceMappingURL=auto-discovery.helper.js.map
|