@koalarx/nest-cli 1.1.2 → 1.1.4
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 +31 -6
- package/code-base/startup-project/package.json +4 -3
- package/code-base/startup-project/prisma/schema.prisma +1 -3
- package/code-base/startup-project/prisma.config.ts +8 -0
- package/code-base/startup-project/src/application/person/events/inactive-person/inactive-person-handler.ts +2 -2
- package/code-base/startup-project/src/application/person/events/person-event.job.ts +1 -1
- package/code-base/startup-project/src/host/controllers/person/person.controller.e2e-spec.ts +9 -5
- package/code-base/startup-project/src/host/main.ts +11 -0
- package/code-base/startup-project/src/test/create-e2e-test-app.ts +11 -0
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
# @koalarx/nest-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ferramenta oficial de CLI para scaffolding rápido de projetos NestJS estruturados com padrões DDD.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 📋 Sobre
|
|
6
|
+
|
|
7
|
+
`@koalarx/nest-cli` é a forma recomendada para inicializar novos projetos que utilizam a biblioteca [@koalarx/nest](https://github.com/igordrangel/koala-nest). Cria automaticamente a estrutura de diretórios, configurações de ambiente e setup inicial.
|
|
8
|
+
|
|
9
|
+
## 📦 Instalação
|
|
6
10
|
|
|
7
11
|
```bash
|
|
8
|
-
npm
|
|
12
|
+
npm install -g @koalarx/nest-cli
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
**Requisito:** Node.js 20.18.0+
|
|
12
16
|
|
|
13
|
-
## Uso
|
|
17
|
+
## 🚀 Uso Rápido
|
|
14
18
|
|
|
15
19
|
```bash
|
|
16
|
-
|
|
20
|
+
# Criar novo projeto
|
|
21
|
+
koala-nest new meu-projeto
|
|
22
|
+
|
|
23
|
+
# Entrar no diretório
|
|
24
|
+
cd meu-projeto
|
|
25
|
+
|
|
26
|
+
# Instalar dependências
|
|
27
|
+
npm install
|
|
28
|
+
|
|
29
|
+
# Iniciar desenvolvimento
|
|
30
|
+
npm run start:dev
|
|
17
31
|
```
|
|
32
|
+
|
|
33
|
+
## 📖 Documentação Completa
|
|
34
|
+
|
|
35
|
+
Para guias detalhados, exemplos avançados e referência de features, consulte:
|
|
36
|
+
|
|
37
|
+
- **[@koalarx/nest](https://github.com/igordrangel/koala-nest)** — Documentação da biblioteca principal
|
|
38
|
+
- **[Exemplo de Projeto](./code-base/startup-project)** — Estrutura padrão gerada pela CLI
|
|
39
|
+
|
|
40
|
+
## 📄 Licença
|
|
41
|
+
|
|
42
|
+
MIT
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@koalarx/utils": "^4.2.1",
|
|
24
|
-
"@koalarx/nest": "^1.16.
|
|
24
|
+
"@koalarx/nest": "^1.16.1",
|
|
25
25
|
"@nestjs/common": "^11.0.12",
|
|
26
26
|
"@nestjs/config": "^4.0.1",
|
|
27
27
|
"@nestjs/core": "^11.0.12",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"@nestjs/passport": "^11.0.5",
|
|
30
30
|
"@nestjs/platform-express": "^11.0.12",
|
|
31
31
|
"@nestjs/swagger": "^11.0.7",
|
|
32
|
-
"@prisma/
|
|
32
|
+
"@prisma/adapter-pg": "^7.2.0",
|
|
33
|
+
"@prisma/client": "^7.2.0",
|
|
33
34
|
"@scalar/nestjs-api-reference": "^0.4.3",
|
|
34
35
|
"dotenv": "^16.0.3",
|
|
35
36
|
"express-basic-auth": "^1.2.1",
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"eslint-plugin-vitest": "^0.2.8",
|
|
67
68
|
"eslint-plugin-vitest-globals": "^1.4.0",
|
|
68
69
|
"prettier": "^2.3.2",
|
|
69
|
-
"prisma": "^
|
|
70
|
+
"prisma": "^7.2.0",
|
|
70
71
|
"source-map-support": "^0.5.20",
|
|
71
72
|
"supertest": "^7.1.0",
|
|
72
73
|
"tsconfig-paths": "^4.2.0",
|
|
@@ -5,9 +5,9 @@ import { Injectable } from '@nestjs/common'
|
|
|
5
5
|
import { InactivePersonEvent } from './inactive-person-event'
|
|
6
6
|
|
|
7
7
|
@Injectable()
|
|
8
|
-
export class InactivePersonHandler extends EventHandlerBase
|
|
8
|
+
export class InactivePersonHandler extends EventHandlerBase {
|
|
9
9
|
constructor(private readonly repository: IPersonRepository) {
|
|
10
|
-
super()
|
|
10
|
+
super(InactivePersonEvent)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
async handleEvent(): Promise<void> {
|
|
@@ -5,7 +5,7 @@ import { Type } from '@nestjs/common'
|
|
|
5
5
|
import { InactivePersonHandler } from './inactive-person/inactive-person-handler'
|
|
6
6
|
|
|
7
7
|
export class PersonEventJob extends EventJob<Person> {
|
|
8
|
-
defineHandlers(): Type<EventHandlerBase
|
|
8
|
+
defineHandlers(): Type<EventHandlerBase>[] {
|
|
9
9
|
return [InactivePersonHandler]
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -6,6 +6,7 @@ import { PERSON_ROUTER_CONFIG } from './router.config'
|
|
|
6
6
|
describe(`CRUD OF PERSON`, () => {
|
|
7
7
|
let app: INestApplication
|
|
8
8
|
let personId: number
|
|
9
|
+
let addressId: number
|
|
9
10
|
|
|
10
11
|
beforeAll(async () => {
|
|
11
12
|
app = await createE2ETestApp()
|
|
@@ -35,13 +36,16 @@ describe(`CRUD OF PERSON`, () => {
|
|
|
35
36
|
`${PERSON_ROUTER_CONFIG.group}/${personId}`,
|
|
36
37
|
)
|
|
37
38
|
|
|
39
|
+
// Capturar o ID do endereço da resposta
|
|
40
|
+
addressId = response.body.address.id
|
|
41
|
+
|
|
38
42
|
expect(response.statusCode).toBe(200)
|
|
39
43
|
expect(response.body).toStrictEqual({
|
|
40
44
|
id: personId,
|
|
41
45
|
name: 'John Doe',
|
|
42
46
|
phones: [],
|
|
43
47
|
address: {
|
|
44
|
-
id:
|
|
48
|
+
id: expect.any(Number),
|
|
45
49
|
address: 'Streat 1',
|
|
46
50
|
},
|
|
47
51
|
active: true,
|
|
@@ -61,7 +65,7 @@ describe(`CRUD OF PERSON`, () => {
|
|
|
61
65
|
name: 'John Doe',
|
|
62
66
|
phones: [],
|
|
63
67
|
address: {
|
|
64
|
-
id:
|
|
68
|
+
id: addressId,
|
|
65
69
|
address: 'Streat 1',
|
|
66
70
|
},
|
|
67
71
|
active: true,
|
|
@@ -96,7 +100,7 @@ describe(`CRUD OF PERSON`, () => {
|
|
|
96
100
|
name: 'John Doe',
|
|
97
101
|
phones: [],
|
|
98
102
|
address: {
|
|
99
|
-
id:
|
|
103
|
+
id: addressId,
|
|
100
104
|
address: 'Streat 1',
|
|
101
105
|
},
|
|
102
106
|
active: true,
|
|
@@ -113,7 +117,7 @@ describe(`CRUD OF PERSON`, () => {
|
|
|
113
117
|
name: 'John Doe Updated',
|
|
114
118
|
phones: [],
|
|
115
119
|
address: {
|
|
116
|
-
id:
|
|
120
|
+
id: addressId,
|
|
117
121
|
address: 'Streat 2',
|
|
118
122
|
},
|
|
119
123
|
active: true,
|
|
@@ -130,7 +134,7 @@ describe(`CRUD OF PERSON`, () => {
|
|
|
130
134
|
name: 'John Doe Updated',
|
|
131
135
|
phones: [],
|
|
132
136
|
address: {
|
|
133
|
-
id:
|
|
137
|
+
id: addressId,
|
|
134
138
|
address: 'Streat 2',
|
|
135
139
|
},
|
|
136
140
|
active: true,
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
1
2
|
import { CreatePersonJob } from '@/application/person/create-person-job/create-person-job'
|
|
2
3
|
import { DeleteInactiveJob } from '@/application/person/delete-inative-job/delete-inactive-job'
|
|
3
4
|
import { InactivePersonHandler } from '@/application/person/events/inactive-person/inactive-person-handler'
|
|
4
5
|
import { DbTransactionContext } from '@/infra/database/db-transaction-context'
|
|
5
6
|
import { KoalaApp } from '@koalarx/nest/core/koala-app'
|
|
7
|
+
import { setPrismaClientOptions } from '@koalarx/nest/core/database/prisma.service'
|
|
8
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
9
|
+
import { Pool } from 'pg'
|
|
6
10
|
import { NestFactory } from '@nestjs/core'
|
|
7
11
|
import { AppModule } from './app.module'
|
|
8
12
|
|
|
9
13
|
async function bootstrap() {
|
|
14
|
+
// Configurar o adapter PostgreSQL antes de inicializar a aplicação
|
|
15
|
+
const pool = new Pool({
|
|
16
|
+
connectionString: process.env.DATABASE_URL,
|
|
17
|
+
})
|
|
18
|
+
const adapter = new PrismaPg(pool)
|
|
19
|
+
setPrismaClientOptions({ adapter })
|
|
20
|
+
|
|
10
21
|
return NestFactory.create(AppModule).then((app) =>
|
|
11
22
|
new KoalaApp(app)
|
|
12
23
|
.useDoc({
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
1
2
|
import { AppModule } from '@/host/app.module'
|
|
2
3
|
import { DbTransactionContext } from '@/infra/database/db-transaction-context'
|
|
3
4
|
import { KoalaAppTest } from '@koalarx/nest/test/koala-app-test'
|
|
5
|
+
import { setPrismaClientOptions } from '@koalarx/nest/core/database/prisma.service'
|
|
6
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
7
|
+
import { Pool } from 'pg'
|
|
4
8
|
import { Test } from '@nestjs/testing'
|
|
5
9
|
|
|
6
10
|
export async function createE2ETestApp() {
|
|
11
|
+
// Configurar o adapter PostgreSQL antes de criar o módulo de teste
|
|
12
|
+
const pool = new Pool({
|
|
13
|
+
connectionString: process.env.DATABASE_URL,
|
|
14
|
+
})
|
|
15
|
+
const adapter = new PrismaPg(pool)
|
|
16
|
+
setPrismaClientOptions({ adapter })
|
|
17
|
+
|
|
7
18
|
return Test.createTestingModule({ imports: [AppModule] })
|
|
8
19
|
.compile()
|
|
9
20
|
.then((moduleRef) => moduleRef.createNestApplication())
|
package/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var import_inquirer = __toESM(require("inquirer"));
|
|
|
30
30
|
// package.json
|
|
31
31
|
var package_default = {
|
|
32
32
|
name: "@koalarx/nest-cli",
|
|
33
|
-
version: "1.1.
|
|
33
|
+
version: "1.1.4",
|
|
34
34
|
description: "Biblioteca de CLI para cria\xE7\xE3o de projetos utilizando Koala Nest",
|
|
35
35
|
scripts: {
|
|
36
36
|
test: "vitest run",
|