@koalarx/nest 4.0.1 → 4.0.3
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 +34 -9
- package/cli/utils/patch-infra-module.js +68 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ Facilitador para criar APIs NestJS com arquitetura DDD, focado em manutenção,
|
|
|
4
4
|
|
|
5
5
|
Em vez de depender de uma biblioteca opaca, a CLI **copia módulos prontos para dentro do projeto** — abordagem semelhante ao [shadcn/ui](https://ui.shadcn.com). Você recebe código que pode ler, adaptar e manter sem amarras futuras.
|
|
6
6
|
|
|
7
|
+
**Documentação:** [nest.koalarx.com](https://nest.koalarx.com/) (PT e EN)
|
|
8
|
+
|
|
7
9
|
## O que está disponível hoje
|
|
8
10
|
|
|
9
11
|
| Recurso | Status |
|
|
@@ -14,8 +16,8 @@ Em vez de depender de uma biblioteca opaca, a CLI **copia módulos prontos para
|
|
|
14
16
|
| Template **Exemplo de CRUD** (Person) | Disponível |
|
|
15
17
|
| Autenticação (JWT, OAuth2) | Disponível na CLI |
|
|
16
18
|
| API Key | Em breve |
|
|
17
|
-
| Cache, health check, jobs internos | Disponível
|
|
18
|
-
| Comando `add` (
|
|
19
|
+
| Cache, health check, jobs internos | Disponível via `new` e `add` |
|
|
20
|
+
| Comando `add` (funcionalidades avulsas) | Disponível |
|
|
19
21
|
|
|
20
22
|
## Instalação e uso
|
|
21
23
|
|
|
@@ -57,11 +59,14 @@ npx @koalarx/nest@latest new
|
|
|
57
59
|
| Comando | Descrição |
|
|
58
60
|
| --- | --- |
|
|
59
61
|
| `kl-nest new` | Cria um novo projeto (fluxo interativo) |
|
|
62
|
+
| `kl-nest add` | Adiciona funcionalidades a um projeto existente |
|
|
60
63
|
| `kl-nest version` | Exibe a versão da CLI |
|
|
61
64
|
| `kl-nest help` | Lista comandos disponíveis |
|
|
62
65
|
|
|
63
66
|
```bash
|
|
64
67
|
kl-nest new
|
|
68
|
+
kl-nest add cache
|
|
69
|
+
kl-nest add auth jwt health
|
|
65
70
|
kl-nest version
|
|
66
71
|
kl-nest --help
|
|
67
72
|
|
|
@@ -75,7 +80,22 @@ O comando `new` pergunta:
|
|
|
75
80
|
- nome do projeto;
|
|
76
81
|
- gerenciador de pacotes (`bun`, `npm` ou `pnpm` — Bun recomendado);
|
|
77
82
|
- template (**Padrão** ou **Exemplo de CRUD**);
|
|
78
|
-
- estratégia de autenticação (**JWT**, **OAuth2** ou nenhuma) e funcionalidades extras (
|
|
83
|
+
- estratégia de autenticação (**JWT**, **OAuth2** ou nenhuma) e funcionalidades extras (cache, health, cron, eventos); **API Key** ainda aparece desabilitada no prompt;
|
|
84
|
+
|
|
85
|
+
O comando `add` instala funcionalidades em um projeto Koala Nest já existente (detecta o que já está presente e pula duplicatas):
|
|
86
|
+
|
|
87
|
+
- `auth jwt` / `auth oauth2` — autenticação
|
|
88
|
+
- `cache` — cache Redis (com exemplos no template CRUD)
|
|
89
|
+
- `health` — endpoint `GET /health`
|
|
90
|
+
- `cron` — jobs com expressão cron
|
|
91
|
+
- `events` — jobs reativos a eventos
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
cd meu-projeto
|
|
95
|
+
kl-nest add cache
|
|
96
|
+
kl-nest add auth jwt health --verbose
|
|
97
|
+
kl-nest add cron events
|
|
98
|
+
```
|
|
79
99
|
|
|
80
100
|
### Templates
|
|
81
101
|
|
|
@@ -115,7 +135,7 @@ Crie um `.env` na raiz do projeto gerado:
|
|
|
115
135
|
```env
|
|
116
136
|
PORT=3000
|
|
117
137
|
NODE_ENV=develop
|
|
118
|
-
DATABASE_URL=
|
|
138
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/my_api
|
|
119
139
|
```
|
|
120
140
|
|
|
121
141
|
### Scripts úteis no projeto gerado
|
|
@@ -127,11 +147,14 @@ bun run migration:run # aplica migrations pendentes
|
|
|
127
147
|
bun run migration:revert # reverte a última migration
|
|
128
148
|
```
|
|
129
149
|
|
|
130
|
-
## Documentação
|
|
150
|
+
## Documentação
|
|
151
|
+
|
|
152
|
+
Site completo: **[nest.koalarx.com](https://nest.koalarx.com/)** — guias de instalação, arquitetura DDD, autenticação, cache, jobs e fluxo CRUD (português e inglês).
|
|
131
153
|
|
|
132
|
-
|
|
154
|
+
### Índices para agentes de IA
|
|
133
155
|
|
|
134
|
-
https://nest.koalarx.com/llm.txt
|
|
156
|
+
- PT: https://nest.koalarx.com/llms.txt (alias: `/llm.txt`)
|
|
157
|
+
- EN: https://nest.koalarx.com/llms-en.txt (alias: `/llm-en.txt`)
|
|
135
158
|
|
|
136
159
|
## Repositório (desenvolvimento)
|
|
137
160
|
|
|
@@ -151,8 +174,9 @@ O script `bun kl-nest` no `package.json` compila o projeto e executa a CLI a par
|
|
|
151
174
|
koala-nest/
|
|
152
175
|
├── libs/
|
|
153
176
|
│ ├── cli/ # código-fonte da CLI (kl-nest)
|
|
177
|
+
│ ├── doc/ # markdown da documentação + site Angular
|
|
154
178
|
│ └── koala-nest/ # templates copiados para projetos gerados
|
|
155
|
-
├── scripts/ # build da CLI e
|
|
179
|
+
├── scripts/ # build da CLI, docs e templates
|
|
156
180
|
└── dist/ # saída do build (cli + koala-nest + package.json)
|
|
157
181
|
```
|
|
158
182
|
|
|
@@ -162,5 +186,6 @@ koala-nest/
|
|
|
162
186
|
bun run build # build completo (CLI + templates + dist/package.json)
|
|
163
187
|
bun run build:cli # apenas a CLI
|
|
164
188
|
bun run build:koala-nest # apenas os templates
|
|
165
|
-
bun
|
|
189
|
+
bun run build:docs # site de documentação
|
|
190
|
+
bun test # testes do monorepo (CLI, lib, docs)
|
|
166
191
|
```
|
|
@@ -1,61 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let patched = content.replace("import { ILoggingService } from '@/domain/common/ilogging.service';", `import { ICacheService } from '@/domain/common/icache.service';
|
|
7
|
-
import { ILoggingService } from '@/domain/common/ilogging.service';
|
|
8
|
-
import { IRedLockService } from '@/domain/common/ired-lock.service';`).replace("import { LoggingService } from '@/infra/common/logging.service';", `import { CacheServiceProvider } from '@/infra/common/cache-service.provider';
|
|
9
|
-
import { LoggingService } from '@/infra/common/logging.service';
|
|
10
|
-
import { RedLockService } from '@/infra/common/red-lock.service';`).replace(` providers: [
|
|
11
|
-
{ provide: ILoggingService, useClass: LoggingService },`, ` providers: [
|
|
12
|
-
CacheServiceProvider,
|
|
13
|
-
{ provide: ICacheService, useExisting: CacheServiceProvider },
|
|
14
|
-
{ provide: ILoggingService, useClass: LoggingService },
|
|
15
|
-
{ provide: IRedLockService, useClass: RedLockService },`);
|
|
16
|
-
if (withAuth) {
|
|
17
|
-
return patched.replace(" exports: [RepositoryModule, ILoggingService, ILoggedUserInfoService],", ` exports: [
|
|
18
|
-
RepositoryModule,
|
|
19
|
-
ICacheService,
|
|
20
|
-
ILoggingService,
|
|
21
|
-
IRedLockService,
|
|
22
|
-
ILoggedUserInfoService,
|
|
23
|
-
],`);
|
|
24
|
-
}
|
|
25
|
-
return patched.replace(" exports: [RepositoryModule, ILoggingService],", ` exports: [
|
|
26
|
-
RepositoryModule,
|
|
27
|
-
ICacheService,
|
|
28
|
-
ILoggingService,
|
|
29
|
-
IRedLockService,
|
|
30
|
-
],`);
|
|
1
|
+
function hasCacheProviders(content) {
|
|
2
|
+
return content.includes("{ provide: ICacheService, useExisting: CacheServiceProvider }");
|
|
3
|
+
}
|
|
4
|
+
function hasAuthProviders(content) {
|
|
5
|
+
return content.includes("{ provide: ILoggedUserInfoService, useClass: LoggedUserInfoService }");
|
|
31
6
|
}
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
7
|
+
export function buildInfraModule({ cache, auth }) {
|
|
8
|
+
const importLines = [
|
|
9
|
+
...cache ? ["import { ICacheService } from '@/domain/common/icache.service';"] : [],
|
|
10
|
+
"import { ILoggingService } from '@/domain/common/ilogging.service';",
|
|
11
|
+
...auth ? [
|
|
12
|
+
"import { ILoggedUserInfoService } from '@/domain/services/ilogged-user-info.service';"
|
|
13
|
+
] : [],
|
|
14
|
+
...cache ? ["import { IRedLockService } from '@/domain/common/ired-lock.service';"] : [],
|
|
15
|
+
"import { Module } from '@nestjs/common';",
|
|
16
|
+
...cache ? [
|
|
17
|
+
"import { CacheServiceProvider } from '@/infra/common/cache-service.provider';"
|
|
18
|
+
] : [],
|
|
19
|
+
"import { LoggingService } from '@/infra/common/logging.service';",
|
|
20
|
+
...auth ? [
|
|
21
|
+
"import { LoggedUserInfoService } from '@/infra/services/logged-user-info.service';"
|
|
22
|
+
] : [],
|
|
23
|
+
...cache ? ["import { RedLockService } from '@/infra/common/red-lock.service';"] : [],
|
|
24
|
+
"import { RepositoryModule } from '@/infra/repositories/repository.module';"
|
|
25
|
+
];
|
|
26
|
+
const providerLines = [
|
|
27
|
+
...cache ? [
|
|
28
|
+
" CacheServiceProvider,",
|
|
29
|
+
" { provide: ICacheService, useExisting: CacheServiceProvider },"
|
|
30
|
+
] : [],
|
|
31
|
+
" { provide: ILoggingService, useClass: LoggingService },",
|
|
32
|
+
...cache ? [" { provide: IRedLockService, useClass: RedLockService },"] : [],
|
|
33
|
+
...auth ? [
|
|
34
|
+
" { provide: ILoggedUserInfoService, useClass: LoggedUserInfoService },"
|
|
35
|
+
] : []
|
|
36
|
+
];
|
|
37
|
+
const exportLines = [
|
|
38
|
+
" RepositoryModule,",
|
|
39
|
+
...cache ? [" ICacheService,"] : [],
|
|
40
|
+
" ILoggingService,",
|
|
41
|
+
...cache ? [" IRedLockService,"] : [],
|
|
42
|
+
...auth ? [" ILoggedUserInfoService,"] : []
|
|
43
|
+
];
|
|
44
|
+
return `${importLines.join(`
|
|
45
|
+
`)}
|
|
36
46
|
|
|
37
47
|
@Module({
|
|
38
48
|
imports: [RepositoryModule],
|
|
39
|
-
providers: [
|
|
40
|
-
|
|
49
|
+
providers: [
|
|
50
|
+
${providerLines.join(`
|
|
51
|
+
`)}
|
|
52
|
+
],
|
|
53
|
+
exports: [
|
|
54
|
+
${exportLines.join(`
|
|
55
|
+
`)}
|
|
56
|
+
],
|
|
41
57
|
})
|
|
42
58
|
export class InfraModule {}
|
|
43
59
|
`;
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
}
|
|
61
|
+
export function patchInfraModuleForCache(content) {
|
|
62
|
+
if (hasCacheProviders(content)) {
|
|
46
63
|
return content;
|
|
47
64
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
return buildInfraModule({
|
|
66
|
+
cache: true,
|
|
67
|
+
auth: hasAuthProviders(content) || content.includes("ILoggedUserInfoService")
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export const SLIM_INFRA_MODULE = buildInfraModule({ cache: false, auth: false });
|
|
71
|
+
export function patchInfraModuleForAuth(content) {
|
|
72
|
+
if (hasAuthProviders(content)) {
|
|
73
|
+
return content;
|
|
57
74
|
}
|
|
58
|
-
return
|
|
75
|
+
return buildInfraModule({
|
|
76
|
+
cache: hasCacheProviders(content) || content.includes("ICacheService"),
|
|
77
|
+
auth: true
|
|
78
|
+
});
|
|
59
79
|
}
|
|
60
80
|
export function stripInfraModuleCache(_content) {
|
|
61
81
|
return SLIM_INFRA_MODULE;
|