@koalarx/nest 1.16.2 → 1.17.1
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
CHANGED
|
@@ -4,333 +4,411 @@
|
|
|
4
4
|
|
|
5
5
|
<h1 align="center">@koalarx/nest</h1>
|
|
6
6
|
|
|
7
|
-
<p align="center">Uma abstração <a href="https://nestjs.com" target="_blank">
|
|
7
|
+
<p align="center">Uma abstração <a href="https://nestjs.com" target="_blank">NestJS</a> robusta para criar APIs escaláveis seguindo os princípios do Domain-Driven Design (DDD).</p>
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
1. [Introdução](#introdução)
|
|
11
|
-
2. [Estrutura do Projeto](#estrutura-do-projeto)
|
|
12
|
-
3. [Uso da CLI @koalarx/nest-cli](#uso-da-cli-koalarxnest-cli)
|
|
13
|
-
4. [Recursos Optionais](#recursos-opcionais)
|
|
9
|
+
<div align="center">
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
[](https://opensource.org/licenses/MIT)
|
|
12
|
+
[](https://nodejs.org/)
|
|
13
|
+
[](https://www.typescriptlang.org/)
|
|
14
|
+
[](https://www.npmjs.com/package/@koalarx/nest-cli)
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
</div>
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
## Documentação Completa
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
Toda a documentação está organizada em arquivos separados para facilitar a navegação:
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
| Documento | Descrição |
|
|
23
|
+
|-----------|-----------|
|
|
24
|
+
| [**CLI Reference**](./docs/00-cli-reference.md) | Guia da CLI oficial - Forma rápida de criar projetos |
|
|
25
|
+
| [**Guia de Instalação**](./docs/01-guia-instalacao.md) | Como instalar e configurar a biblioteca |
|
|
26
|
+
| [**Configuração Inicial**](./docs/02-configuracao-inicial.md) | Setup do projeto com KoalaNestModule e KoalaApp |
|
|
27
|
+
| [**Exemplo Prático**](./docs/03-exemplo-pratico.md) | Criar uma API completa de usuários passo a passo |
|
|
28
|
+
| [**Tratamento de Erros**](./docs/04-tratamento-erros.md) | Sistema robusto de tratamento e filtros de exceção |
|
|
29
|
+
| [**Features Avançadas**](./docs/05-features-avancadas.md) | Cron Jobs, Event Handlers, Guards, Redis, Transações |
|
|
30
|
+
| [**Decoradores**](./docs/06-decoradores.md) | @IsPublic, @Upload, @Cookies e mais |
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
## Quick Start
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
### Forma Rápida com CLI (Recomendado)
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
```bash
|
|
37
|
+
# Instalar a CLI globalmente
|
|
38
|
+
npm install -g @koalarx/nest-cli
|
|
32
39
|
|
|
33
|
-
|
|
40
|
+
# Criar novo projeto estruturado
|
|
41
|
+
koala-nest new meu-projeto
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
- **domain**: Entidades, DTOs, repositórios e serviços do domínio.
|
|
38
|
-
- **host**: Controladores e ponto de entrada da aplicação.
|
|
39
|
-
- **infra**: Implementações de infraestrutura, como banco de dados e serviços externos.
|
|
43
|
+
# Entrar na pasta
|
|
44
|
+
cd meu-projeto
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
# Iniciar em modo desenvolvimento
|
|
47
|
+
npm run start:dev
|
|
48
|
+
```
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
**Pronto!** Seu projeto está estruturado com:
|
|
51
|
+
- [x] Módulo DDD configurado
|
|
52
|
+
- [x] Documentação da API (Scalar UI)
|
|
53
|
+
- [x] Tratamento de erros robusto
|
|
54
|
+
- [x] Guards de autenticação (JWT + API Key)
|
|
55
|
+
- [x] Banco de dados Prisma
|
|
56
|
+
- [x] Redis para background services
|
|
44
57
|
|
|
45
|
-
###
|
|
58
|
+
### Forma Manual
|
|
46
59
|
|
|
47
|
-
|
|
60
|
+
> ⚠️ **Requisito Obrigatório**: A abstração de banco de dados da biblioteca requer **Prisma como ORM**. Siga a [Configuração Inicial - Prisma](./docs/02-configuracao-inicial.md#configurar-prisma-obrigatório) para setup correto.
|
|
48
61
|
|
|
49
62
|
```bash
|
|
50
|
-
npm install
|
|
63
|
+
npm install @koalarx/nest
|
|
51
64
|
```
|
|
52
65
|
|
|
53
|
-
###
|
|
66
|
+
### 2. Criar Módulo Principal
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
```typescript
|
|
69
|
+
// src/host/app.module.ts
|
|
70
|
+
import { KoalaNestModule } from '@koalarx/nest/core/koala-nest.module'
|
|
71
|
+
import { Module } from '@nestjs/common'
|
|
72
|
+
import { env } from '../core/env'
|
|
73
|
+
import { UserModule } from './controllers/user/user.module'
|
|
56
74
|
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
@Module({
|
|
76
|
+
imports: [
|
|
77
|
+
KoalaNestModule.register({
|
|
78
|
+
env,
|
|
79
|
+
controllers: [UserModule],
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
})
|
|
83
|
+
export class AppModule {}
|
|
59
84
|
```
|
|
60
85
|
|
|
61
|
-
|
|
86
|
+
### 3. Inicializar Aplicação
|
|
62
87
|
|
|
63
|
-
|
|
88
|
+
```typescript
|
|
89
|
+
// src/main.ts
|
|
90
|
+
import 'dotenv/config'
|
|
91
|
+
import { NestFactory } from '@nestjs/core'
|
|
92
|
+
import { KoalaApp } from '@koalarx/nest/core/koala-app'
|
|
93
|
+
import { AppModule } from './host/app.module'
|
|
64
94
|
|
|
65
|
-
|
|
95
|
+
async function bootstrap() {
|
|
96
|
+
const app = await NestFactory.create(AppModule)
|
|
97
|
+
|
|
98
|
+
await new KoalaApp(app)
|
|
99
|
+
.useDoc({
|
|
100
|
+
ui: 'scalar',
|
|
101
|
+
endpoint: '/doc',
|
|
102
|
+
title: 'Minha API',
|
|
103
|
+
version: '1.0.0',
|
|
104
|
+
})
|
|
105
|
+
.enableCors()
|
|
106
|
+
.buildAndServe()
|
|
107
|
+
}
|
|
66
108
|
|
|
67
|
-
|
|
109
|
+
bootstrap()
|
|
110
|
+
```
|
|
68
111
|
|
|
69
|
-
|
|
112
|
+
### 4. Executar
|
|
70
113
|
|
|
114
|
+
```bash
|
|
115
|
+
npm run start:dev
|
|
71
116
|
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
117
|
+
|
|
118
|
+
Acesse `http://localhost:3000/doc` para a documentação interativa!
|
|
119
|
+
|
|
120
|
+
## Principais Features
|
|
121
|
+
|
|
122
|
+
### Segurança
|
|
123
|
+
|
|
124
|
+
- **Guards**: Autenticação e autorização (JWT + API Key)
|
|
125
|
+
- **Estratégias Customizadas**: JwtStrategy e ApiKeyStrategy
|
|
126
|
+
- **@IsPublic()**: Marca endpoints como públicos
|
|
127
|
+
- **@RestrictByProfile()**: Restringe acesso por perfil de usuário
|
|
128
|
+
|
|
129
|
+
### Tratamento de Erros
|
|
130
|
+
|
|
131
|
+
Filtros automáticos para:
|
|
132
|
+
- **Domain Errors** (ConflictError, ResourceNotFoundError, etc)
|
|
133
|
+
- **Prisma Validation** (validação de banco de dados)
|
|
134
|
+
- **Zod Validation** (validação de dados de entrada)
|
|
135
|
+
- **Global Exceptions** (erros não capturados)
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
throw new ConflictError('Email já registrado') // 409
|
|
139
|
+
throw new ResourceNotFoundError('Usuário não encontrado') // 404
|
|
140
|
+
throw new BadRequestError('Dados inválidos') // 400
|
|
79
141
|
```
|
|
80
142
|
|
|
81
|
-
|
|
143
|
+
### Processamento em Background
|
|
82
144
|
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
145
|
+
**Cron Jobs** - Execute tarefas agendadas:
|
|
146
|
+
```typescript
|
|
147
|
+
@Injectable()
|
|
148
|
+
export class SendReportJob extends CronJobHandlerBase {
|
|
149
|
+
protected async settings() {
|
|
150
|
+
return { isActive: true, timeInMinutes: 1440 }
|
|
151
|
+
}
|
|
152
|
+
protected async run(): Promise<CronJobResponse> {
|
|
153
|
+
await emailService.sendReport()
|
|
154
|
+
return ok(null)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.addCronJob(SendReportJob)
|
|
159
|
+
```
|
|
92
160
|
|
|
161
|
+
**Event Jobs** - Processe eventos assincronamente:
|
|
162
|
+
```typescript
|
|
93
163
|
@Injectable()
|
|
94
|
-
export class
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
constructor() {
|
|
99
|
-
super({ header: 'ApiKey' })
|
|
164
|
+
export class UserCreatedHandler extends EventHandlerBase {
|
|
165
|
+
async handleEvent(): Promise<void> {
|
|
166
|
+
// Processar evento de criação de usuário
|
|
167
|
+
console.log('Usuário criado!')
|
|
100
168
|
}
|
|
169
|
+
}
|
|
101
170
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Se for válida, chame done com o objeto do usuário
|
|
107
|
-
return done(null, { userId: 1, username: 'testuser' })
|
|
108
|
-
} else {
|
|
109
|
-
// Se for inválida, chame done com false
|
|
110
|
-
return done(null, false)
|
|
111
|
-
}
|
|
171
|
+
// Registrar em EventJob
|
|
172
|
+
export class UserEventJob extends EventJob<User> {
|
|
173
|
+
defineHandlers(): Type<EventHandlerBase>[] {
|
|
174
|
+
return [UserCreatedHandler]
|
|
112
175
|
}
|
|
113
176
|
}
|
|
177
|
+
|
|
178
|
+
.addEventJob(UserEventJob)
|
|
114
179
|
```
|
|
115
180
|
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import { IS_PUBLIC_KEY } from '@koalarx/nest/decorators/is-public.decorator'
|
|
119
|
-
import { ExecutionContext, Injectable } from '@nestjs/common'
|
|
120
|
-
import { Reflector } from '@nestjs/core'
|
|
121
|
-
import { AuthGuard as NestAuthGuard } from '@nestjs/passport'
|
|
181
|
+
### Banco de Dados
|
|
122
182
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
super()
|
|
127
|
-
}
|
|
183
|
+
- **Prisma ORM** com suporte a todos os drivers (PostgreSQL, MySQL, SQLite, MariaDB, SQL Server, MongoDB)
|
|
184
|
+
- **Transações Automáticas** com context gerenciado
|
|
185
|
+
- **Query Logging** em desenvolvimento
|
|
128
186
|
|
|
129
|
-
|
|
130
|
-
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
|
131
|
-
context.getHandler(),
|
|
132
|
-
context.getClass(),
|
|
133
|
-
])
|
|
187
|
+
### Documentação
|
|
134
188
|
|
|
135
|
-
|
|
189
|
+
Dois UIs disponíveis:
|
|
190
|
+
- **Scalar** - Interface moderna e interativa
|
|
191
|
+
- **Swagger UI** - Documentação clássica
|
|
136
192
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
193
|
+
```typescript
|
|
194
|
+
.useDoc({
|
|
195
|
+
ui: 'scalar', // ou 'swagger'
|
|
196
|
+
endpoint: '/doc',
|
|
197
|
+
title: 'API Documentation',
|
|
198
|
+
version: '1.0.0',
|
|
199
|
+
})
|
|
200
|
+
```
|
|
140
201
|
|
|
141
|
-
|
|
202
|
+
### Funcionalidades Adicionais
|
|
142
203
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
204
|
+
- **Redis Integration** - Sincronização de Cron Jobs e Event Handlers (RedLock)
|
|
205
|
+
- **CORS** - Requisições cross-origin
|
|
206
|
+
- **Zod Validation** - Validação de dados com tipos
|
|
207
|
+
- **Ngrok** - Exposição segura em desenvolvimento
|
|
208
|
+
- **Decoradores Customizados** - @Upload, @Cookies, @ApiPropertyEnum
|
|
146
209
|
|
|
147
|
-
|
|
148
|
-
if (!request.user) {
|
|
149
|
-
const user = {} // busque o usuário aqui
|
|
210
|
+
## Exemplo Completo
|
|
150
211
|
|
|
151
|
-
|
|
152
|
-
request.user = user
|
|
153
|
-
}
|
|
154
|
-
}
|
|
212
|
+
Veja como criar um CRUD de usuários:
|
|
155
213
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
214
|
+
```typescript
|
|
215
|
+
// src/domain/entities/user.entity.ts
|
|
216
|
+
export interface UserEntity {
|
|
217
|
+
id: string
|
|
218
|
+
name: string
|
|
219
|
+
email: string
|
|
220
|
+
createdAt: Date
|
|
159
221
|
}
|
|
160
222
|
```
|
|
161
223
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
import {
|
|
165
|
-
import { Module } from '@nestjs/common'
|
|
166
|
-
import { PassportModule } from '@nestjs/passport'
|
|
167
|
-
import { ApiKeyStrategy } from './strategies/api-key.strategy'
|
|
224
|
+
```typescript
|
|
225
|
+
// src/domain/dtos/create-user.dto.ts
|
|
226
|
+
import { z } from 'zod'
|
|
168
227
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
228
|
+
export const CreateUserSchema = z.object({
|
|
229
|
+
name: z.string().min(1),
|
|
230
|
+
email: z.string().email(),
|
|
172
231
|
})
|
|
173
|
-
|
|
232
|
+
|
|
233
|
+
export type CreateUserDto = z.infer<typeof CreateUserSchema>
|
|
174
234
|
```
|
|
175
235
|
|
|
176
|
-
|
|
236
|
+
```typescript
|
|
237
|
+
// src/domain/services/user.service.ts
|
|
238
|
+
import { Injectable } from '@nestjs/common'
|
|
239
|
+
import { ConflictError } from '@koalarx/nest/core/errors/conflict.error'
|
|
240
|
+
import { ResourceNotFoundError } from '@koalarx/nest/core/errors/resource-not-found.error'
|
|
177
241
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
242
|
+
@Injectable()
|
|
243
|
+
export class UserService {
|
|
244
|
+
constructor(private readonly repository: IUserRepository) {}
|
|
245
|
+
|
|
246
|
+
async create(data: CreateUserDto): Promise<UserEntity> {
|
|
247
|
+
const exists = await this.repository.findByEmail(data.email)
|
|
248
|
+
if (exists) throw new ConflictError('Email já registrado')
|
|
249
|
+
|
|
250
|
+
return this.repository.create(data)
|
|
251
|
+
}
|
|
188
252
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
export class AppModule {}
|
|
253
|
+
async findById(id: string): Promise<UserEntity> {
|
|
254
|
+
const user = await this.repository.findById(id)
|
|
255
|
+
if (!user) throw new ResourceNotFoundError('Usuário não encontrado')
|
|
256
|
+
return user
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async delete(id: string): Promise<void> {
|
|
260
|
+
await this.findById(id) // Valida existência
|
|
261
|
+
await this.repository.delete(id)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
201
264
|
```
|
|
202
265
|
|
|
203
|
-
|
|
266
|
+
```typescript
|
|
267
|
+
// src/host/controllers/user/user.controller.ts
|
|
268
|
+
import { Controller, Get, Post, Delete, Body, Param } from '@nestjs/common'
|
|
269
|
+
import { ApiTags, ApiCreatedResponse } from '@nestjs/swagger'
|
|
270
|
+
import { IsPublic } from '@koalarx/nest/decorators/is-public.decorator'
|
|
271
|
+
|
|
272
|
+
@ApiTags('Users')
|
|
273
|
+
@Controller('users')
|
|
274
|
+
export class UserController {
|
|
275
|
+
constructor(private readonly service: UserService) {}
|
|
276
|
+
|
|
277
|
+
@Post()
|
|
278
|
+
@IsPublic()
|
|
279
|
+
@ApiCreatedResponse({ type: UserResponseDto })
|
|
280
|
+
async create(@Body() data: CreateUserRequestDto) {
|
|
281
|
+
const validated = CreateUserSchema.parse(data)
|
|
282
|
+
return this.service.create(validated)
|
|
283
|
+
}
|
|
204
284
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
import { InactivePersonHandler } from '@/application/person/events/inactive-person/inactive-person-handler'
|
|
210
|
-
import { DbTransactionContext } from '@/infra/database/db-transaction-context'
|
|
211
|
-
import { KoalaApp } from '@koalarx/nest/core/koala-app'
|
|
212
|
-
import { NestFactory } from '@nestjs/core'
|
|
213
|
-
import { AppModule } from './app.module'
|
|
214
|
-
import { AuthGuard } from './security/guards/auth.guard'
|
|
285
|
+
@Get(':id')
|
|
286
|
+
async findOne(@Param('id') id: string) {
|
|
287
|
+
return this.service.findById(id)
|
|
288
|
+
}
|
|
215
289
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
ui: 'scalar',
|
|
221
|
-
endpoint: '/doc',
|
|
222
|
-
title: 'API de Demonstração',
|
|
223
|
-
version: '1.0',
|
|
224
|
-
authorizations: [
|
|
225
|
-
{ name: 'ApiKey', config: { type: 'apiKey', name: 'ApiKey' } },
|
|
226
|
-
],
|
|
227
|
-
})
|
|
228
|
-
.addGlobalGuard(AuthGuard)
|
|
229
|
-
.addCronJob(CreatePersonJob)
|
|
230
|
-
.addCronJob(DeleteInactiveJob)
|
|
231
|
-
.addEventJob(InactivePersonHandler)
|
|
232
|
-
.setAppName('example')
|
|
233
|
-
.setInternalUserName('integration.bot')
|
|
234
|
-
.setDbTransactionContext(DbTransactionContext)
|
|
235
|
-
.enableCors()
|
|
236
|
-
.buildAndServe(),
|
|
237
|
-
)
|
|
290
|
+
@Delete(':id')
|
|
291
|
+
async delete(@Param('id') id: string) {
|
|
292
|
+
await this.service.delete(id)
|
|
293
|
+
}
|
|
238
294
|
}
|
|
239
|
-
bootstrap()
|
|
240
295
|
```
|
|
241
296
|
|
|
242
|
-
|
|
297
|
+
Erros são automaticamente transformados em respostas HTTP apropriadas!
|
|
243
298
|
|
|
244
|
-
|
|
299
|
+
## Estrutura de Projeto Recomendada
|
|
245
300
|
|
|
246
|
-
|
|
301
|
+
Seguindo DDD:
|
|
247
302
|
|
|
248
|
-
|
|
303
|
+
```
|
|
304
|
+
src/
|
|
305
|
+
├── application/ # Lógica de aplicação e mapeadores
|
|
306
|
+
├── core/ # Configurações globais
|
|
307
|
+
├── domain/ # Lógica de negócio
|
|
308
|
+
│ ├── entities/
|
|
309
|
+
│ ├── dtos/
|
|
310
|
+
│ ├── repositories/ # Interfaces
|
|
311
|
+
│ └── services/
|
|
312
|
+
├── host/ # Controladores e entrada
|
|
313
|
+
│ ├── controllers/
|
|
314
|
+
│ ├── security/ # Guards e estratégias
|
|
315
|
+
│ └── app.module.ts
|
|
316
|
+
├── infra/ # Implementações de infraestrutura
|
|
317
|
+
│ ├── database/
|
|
318
|
+
│ ├── repositories/ # Implementações
|
|
319
|
+
│ └── services/
|
|
320
|
+
└── main.ts
|
|
321
|
+
```
|
|
249
322
|
|
|
250
|
-
|
|
323
|
+
## Configuração de Ambiente
|
|
251
324
|
|
|
252
|
-
|
|
253
|
-
```ts
|
|
254
|
-
...
|
|
255
|
-
import { KoalaApp } from '@koalarx/nest/core/koala-app'
|
|
256
|
-
import { NestFactory } from '@nestjs/core'
|
|
257
|
-
import { AppModule } from './app.module'
|
|
325
|
+
A lib já valida automaticamente as variáveis padrão. Crie seu `.env` com:
|
|
258
326
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
327
|
+
```env
|
|
328
|
+
# Variáveis obrigatórias
|
|
329
|
+
NODE_ENV=develop
|
|
330
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/db
|
|
331
|
+
|
|
332
|
+
# Variáveis opcionais (padrão da lib)
|
|
333
|
+
REDIS_CONNECTION_STRING=redis://localhost:6379
|
|
334
|
+
SWAGGER_USERNAME=admin
|
|
335
|
+
SWAGGER_PASSWORD=password123
|
|
336
|
+
PRISMA_QUERY_LOG=false
|
|
337
|
+
|
|
338
|
+
# Suas variáveis customizadas
|
|
339
|
+
# CUSTOM_VAR=value
|
|
269
340
|
```
|
|
270
341
|
|
|
271
|
-
|
|
342
|
+
Ver [Configuração Inicial - Variáveis de Ambiente](./docs/02-configuracao-inicial.md#2-configurar-variáveis-de-ambiente) para detalhes.
|
|
272
343
|
|
|
273
|
-
|
|
344
|
+
## Índice da Documentação Original
|
|
274
345
|
|
|
275
|
-
|
|
346
|
+
A documentação abaixo foi mantida para referência de recursos específicos:
|
|
276
347
|
|
|
277
|
-
|
|
278
|
-
- **options.enum** - A enumeração a ser documentada. Deve ser um objeto onde as chaves são os nomes dos enums e os valores são suas representações numéricas.
|
|
279
|
-
- **options.required** - (Opcional) Indica se a propriedade é obrigatória.
|
|
348
|
+
### API Key Strategy
|
|
280
349
|
|
|
281
|
-
|
|
350
|
+
Uma estratégia de autenticação via chave de API integrada ao Passport.js:
|
|
282
351
|
|
|
283
|
-
|
|
284
|
-
import { ApiPropertyEnum } from './decorators/api-property-enum.decorator';
|
|
352
|
+
[Ver documentação completa →](./docs/01-guia-instalacao.md#api-key-strategy)
|
|
285
353
|
|
|
286
|
-
|
|
287
|
-
Ativo = 1,
|
|
288
|
-
Inativo = 2,
|
|
289
|
-
}
|
|
354
|
+
### Ngrok
|
|
290
355
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
356
|
+
Exponha sua aplicação local na internet com segurança:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
.useNgrok(process.env.NGROK_AUTH_TOKEN!)
|
|
295
360
|
```
|
|
296
361
|
|
|
297
|
-
|
|
362
|
+
[Ver documentação completa →](./docs/05-features-avancadas.md#10-ngrok-exposição-em-produção)
|
|
298
363
|
|
|
299
|
-
|
|
300
|
-
Ativo: 1
|
|
301
|
-
Inativo: 2
|
|
302
|
-
```
|
|
364
|
+
### Decoradores
|
|
303
365
|
|
|
304
|
-
|
|
366
|
+
- **@ApiPropertyEnum()** - Documento enums no Swagger
|
|
367
|
+
- **@ApiPropertyOnlyDevelop()** - Propriedades apenas em dev
|
|
368
|
+
- **@ApiExcludeEndpointDiffDevelop()** - Endpoints apenas em dev
|
|
369
|
+
- **@Upload()** - Documentação de upload de arquivos
|
|
370
|
+
- **@Cookies()** - Extrai cookies da requisição
|
|
371
|
+
- **@IsPublic()** - Marca endpoint como público
|
|
305
372
|
|
|
306
|
-
|
|
373
|
+
[Ver todos os decoradores →](./docs/06-decoradores.md)
|
|
307
374
|
|
|
308
|
-
|
|
375
|
+
## Arquitetura
|
|
309
376
|
|
|
310
|
-
|
|
311
|
-
- Caso contrário, o endpoint será excluído da documentação.
|
|
377
|
+
A biblioteca utiliza duas classes principais:
|
|
312
378
|
|
|
313
|
-
|
|
379
|
+
1. **KoalaNestModule** - Módulo NestJS com configuração
|
|
380
|
+
2. **KoalaApp** - Classe fluent para setup da aplicação
|
|
314
381
|
|
|
315
|
-
|
|
382
|
+
Ambas seguem o padrão de **Fluent Interface** para configuração clara e intuitiva.
|
|
316
383
|
|
|
317
|
-
|
|
384
|
+
## Dependências Principais
|
|
318
385
|
|
|
319
|
-
|
|
386
|
+
- `@nestjs/*` - Framework NestJS
|
|
387
|
+
- `@prisma/client` - ORM Prisma
|
|
388
|
+
- `zod` - Validação de dados
|
|
389
|
+
- `ioredis` - Cliente Redis
|
|
390
|
+
- `@nestjs/swagger` - Documentação automática
|
|
320
391
|
|
|
321
|
-
|
|
392
|
+
## Links Importantes
|
|
322
393
|
|
|
323
|
-
|
|
324
|
-
|
|
394
|
+
- **[CLI (@koalarx/nest-cli)](https://www.npmjs.com/package/@koalarx/nest-cli)** - Ferramenta oficial para criar projetos rapidamente
|
|
395
|
+
- **[GitHub da Library](https://github.com/igordrangel/koala-nest)** - Repositório principal
|
|
396
|
+
- **[GitHub da CLI](https://github.com/igordrangel/koala-nest-cli)** - Repositório da CLI
|
|
325
397
|
|
|
326
|
-
|
|
398
|
+
## Licença
|
|
327
399
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
```
|
|
400
|
+
MIT License © 2023-2025 Igor D. Rangel
|
|
401
|
+
|
|
402
|
+
## Contribuindo
|
|
403
|
+
|
|
404
|
+
Contribuições são bem-vindas! Abra uma issue ou pull request no repositório.
|
|
335
405
|
|
|
336
|
-
|
|
406
|
+
## Suporte
|
|
407
|
+
|
|
408
|
+
Para dúvidas, abra uma issue no repositório ou consulte a [documentação completa](./docs).
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
<p align="center">
|
|
413
|
+
Feito para desenvolvedores NestJS
|
|
414
|
+
</p>
|
|
@@ -2,6 +2,7 @@ import { EnvService } from '@koalarx/nest/env/env.service';
|
|
|
2
2
|
import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
3
3
|
import { Prisma, PrismaClient } from '@prisma/client';
|
|
4
4
|
import { PrismaClientWithCustomTransaction } from './prisma-client-with-custom-transaction.interface';
|
|
5
|
+
export declare function setPrismaClientOptions(options: Record<string, any>): void;
|
|
5
6
|
export declare class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy, PrismaClientWithCustomTransaction {
|
|
6
7
|
private readonly env;
|
|
7
8
|
constructor(env: EnvService);
|