@koalarx/nest 1.17.0 → 1.18.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 CHANGED
@@ -9,7 +9,7 @@
9
9
  <div align="center">
10
10
 
11
11
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12
- [![Node.js](https://img.shields.io/badge/Node.js-20%2B-green)](https://nodejs.org/)
12
+ [![Bun](https://img.shields.io/badge/Bun-1.3%2B-black)](https://bun.sh)
13
13
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.1%2B-blue)](https://www.typescriptlang.org/)
14
14
  [![CLI](https://img.shields.io/badge/CLI-@koalarx/nest--cli-brightgreen)](https://www.npmjs.com/package/@koalarx/nest-cli)
15
15
 
@@ -31,6 +31,37 @@ Toda a documentação está organizada em arquivos separados para facilitar a na
31
31
 
32
32
  ## Quick Start
33
33
 
34
+ ### Usando Bun (Recomendado - Mais Rápido)
35
+
36
+ O projeto agora usa **Bun** como runtime JavaScript. Para instalar o Bun:
37
+
38
+ ```bash
39
+ # Instalar Bun (Windows, macOS, Linux)
40
+ curl -fsSL https://bun.sh/install | bash
41
+
42
+ # Ou em Windows com PowerShell:
43
+ powershell -Command "irm https://bun.sh/install.ps1 | iex"
44
+
45
+ # Instalar dependências
46
+ bun install
47
+
48
+ # Iniciar em modo desenvolvimento
49
+ bun run start:dev
50
+
51
+ # Executar testes
52
+ bun run test
53
+
54
+ # Fazer build
55
+ bun run build
56
+ ```
57
+
58
+ **Vantagens do Bun:**
59
+ - ⚡ Runtime ~3x mais rápido que Node.js
60
+ - 📦 Package manager integrado (mais rápido que npm)
61
+ - 🧪 Test runner nativo (compatível com Vitest)
62
+ - 🔄 Hot reload automático
63
+ - 💾 Menor consumo de memória
64
+
34
65
  ### Forma Rápida com CLI (Recomendado)
35
66
 
36
67
  ```bash
@@ -43,21 +74,27 @@ koala-nest new meu-projeto
43
74
  # Entrar na pasta
44
75
  cd meu-projeto
45
76
 
46
- # Iniciar em modo desenvolvimento
47
- npm run start:dev
77
+ # Iniciar em modo desenvolvimento (com Bun)
78
+ bun run start:dev
48
79
  ```
49
80
 
50
81
  **Pronto!** Seu projeto está estruturado com:
51
82
  - [x] Módulo DDD configurado
52
83
  - [x] Documentação da API (Scalar UI)
53
84
  - [x] Tratamento de erros robusto
54
- - [x] Autenticação JWT
85
+ - [x] Guards de autenticação (JWT + API Key)
55
86
  - [x] Banco de dados Prisma
56
87
  - [x] Redis para background services
57
88
 
58
89
  ### Forma Manual
59
90
 
91
+ > ⚠️ **Requisito Obrigatório**: A abstração de banco de dados da biblioteca requer **Prisma como ORM**.
92
+
60
93
  ```bash
94
+ # Com Bun (Recomendado - Mais rápido)
95
+ bun install @koalarx/nest
96
+
97
+ # Ou com npm (Alternativa)
61
98
  npm install @koalarx/nest
62
99
  ```
63
100
 
@@ -119,9 +156,10 @@ Acesse `http://localhost:3000/doc` para a documentação interativa!
119
156
 
120
157
  ### Segurança
121
158
 
122
- - **Guards Globais**: Proteja endpoints com autenticação
123
- - **API Key Strategy**: Autenticação via chave de API integrada
159
+ - **Guards**: Autenticação e autorização (JWT + API Key)
160
+ - **Estratégias Customizadas**: JwtStrategy e ApiKeyStrategy
124
161
  - **@IsPublic()**: Marca endpoints como públicos
162
+ - **@RestrictByProfile()**: Restringe acesso por perfil de usuário
125
163
 
126
164
  ### Tratamento de Erros
127
165
 
@@ -155,15 +193,24 @@ export class SendReportJob extends CronJobHandlerBase {
155
193
  .addCronJob(SendReportJob)
156
194
  ```
157
195
 
158
- **Event Handlers** - Processe eventos assincronamente:
196
+ **Event Jobs** - Processe eventos assincronamente:
159
197
  ```typescript
160
198
  @Injectable()
161
199
  export class UserCreatedHandler extends EventHandlerBase {
162
- get eventName(): string { return 'user:created' }
163
- async handle(data: any): Promise<void> { /* sua lógica */ }
200
+ async handleEvent(): Promise<void> {
201
+ // Processar evento de criação de usuário
202
+ console.log('Usuário criado!')
203
+ }
204
+ }
205
+
206
+ // Registrar em EventJob
207
+ export class UserEventJob extends EventJob<User> {
208
+ defineHandlers(): Type<EventHandlerBase>[] {
209
+ return [UserCreatedHandler]
210
+ }
164
211
  }
165
212
 
166
- .addEventJob(UserCreatedHandler)
213
+ .addEventJob(UserEventJob)
167
214
  ```
168
215
 
169
216
  ### Banco de Dados
@@ -310,14 +357,25 @@ src/
310
357
 
311
358
  ## Configuração de Ambiente
312
359
 
360
+ A lib já valida automaticamente as variáveis padrão. Crie seu `.env` com:
361
+
313
362
  ```env
363
+ # Variáveis obrigatórias
314
364
  NODE_ENV=develop
315
365
  DATABASE_URL=postgresql://user:password@localhost:5432/db
316
- REDIS_URL=redis://localhost:6379
366
+
367
+ # Variáveis opcionais (padrão da lib)
368
+ REDIS_CONNECTION_STRING=redis://localhost:6379
317
369
  SWAGGER_USERNAME=admin
318
370
  SWAGGER_PASSWORD=password123
371
+ PRISMA_QUERY_LOG=false
372
+
373
+ # Suas variáveis customizadas
374
+ # CUSTOM_VAR=value
319
375
  ```
320
376
 
377
+ Ver [Configuração Inicial - Variáveis de Ambiente](./docs/02-configuracao-inicial.md#2-configurar-variáveis-de-ambiente) para detalhes.
378
+
321
379
  ## Índice da Documentação Original
322
380
 
323
381
  A documentação abaixo foi mantida para referência de recursos específicos:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",