@nest-arch/tui 0.4.6 → 0.5.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/dist/cli.js +1 -1
- package/dist/constants-DX5wiqrq.js +1 -0
- package/dist/index.js +145 -133
- package/dist/templates/addons/husky/pre-commit.hbs +1 -1
- package/dist/templates/base/.env.example.hbs +7 -2
- package/dist/templates/base/.env.hbs +7 -2
- package/dist/templates/base/README.md.hbs +11 -2
- package/dist/templates/base/pnpm-workspace.yaml.hbs +9 -4
- package/dist/templates/base/prisma.config.ts.hbs +5 -0
- package/dist/templates/base/src/app.module.ts.hbs +5 -22
- package/dist/templates/base/src/database/adapters/mongo/raw-mongo.adapter.ts.hbs +4 -2
- package/dist/templates/base/src/database/db.module.ts.hbs +15 -1
- package/dist/templates/base/src/database/db.service.ts.hbs +6 -3
- package/dist/templates/base/src/database/entities/todo.entity.ts.hbs +2 -2
- package/dist/templates/base/src/database/index.ts.hbs +2 -0
- package/dist/templates/base/src/database/orm/drizzle/schema.ts.hbs +48 -12
- package/dist/templates/base/src/database/orm/typeorm/data-source.ts.hbs +26 -10
- package/dist/templates/base/src/libs/middlewares/graphql-throttler.guard.ts.hbs +22 -0
- package/dist/templates/base/src/libs/trpc/inner.context.ts.hbs +2 -2
- package/dist/templates/base/src/main.ts.hbs +2 -2
- package/dist/templates/base/test/app.e2e-spec.ts.hbs +368 -196
- package/dist/templates/extras/docker/Dockerfile.hbs +8 -1
- package/dist/templates/extras/health/src/health/health.controller.ts.hbs +7 -1
- package/dist/templates/extras/swagger/create-docs.ts.hbs +6 -1
- package/dist/templates/feature/graphql/src/graphql/models/todo.model.ts.hbs +1 -1
- package/dist/templates/feature/graphql/src/graphql/resolvers/todo.resolver.ts.hbs +1 -1
- package/dist/templates/feature/rest/todo-example/src/api/todo/todo.controller.ts.hbs +80 -7
- package/dist/templates/feature/rest/todo-example/src/api/todo/todo.service.ts.hbs +181 -25
- package/dist/templates/monorepo/apps/api-gateway/src/main.ts.hbs +2 -2
- package/dist/templates/monorepo/root/README.md.hbs +8 -13
- package/dist/templates/single-project/architecture/nest-api/.env.hbs +6 -2
- package/dist/templates/single-project/architecture/nest-api/pnpm-workspace.yaml.hbs +6 -0
- package/dist/templates/single-project/architecture/nest-api/src/main.ts.hbs +2 -2
- package/dist/templates/single-project/architecture/nest-gateway/src/main.ts.hbs +2 -2
- package/dist/templates/single-project/architecture/nest-microservice/.env.hbs +6 -0
- package/dist/templates/single-project/architecture/nest-microservice/src/app.controller.ts.hbs +2 -2
- package/dist/templates/single-project/architecture/nest-microservice/src/app.module.ts.hbs +28 -1
- package/dist/templates/single-project/architecture/nest-microservice/src/http-throttler.guard.ts.hbs +13 -0
- package/dist/templates/single-project/architecture/nest-microservice/src/main.ts.hbs +2 -2
- package/dist/templates/single-project/architecture/nest-microservice/test/microservice.e2e-spec.ts.hbs +35 -0
- package/package.json +5 -5
- package/dist/constants-DVhgS48N.js +0 -1
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
|
7
|
+
{{#if setupInstructions}}
|
|
8
|
+
{{{setupInstructions}}}
|
|
9
|
+
{{else}}
|
|
7
10
|
```bash
|
|
8
11
|
# Install dependencies
|
|
9
12
|
{{#if isPnpm}}pnpm install{{else if isYarn}}yarn install{{else if isBun}}bun install{{else}}npm install{{/if}}
|
|
10
13
|
```
|
|
14
|
+
{{/if}}
|
|
11
15
|
|
|
12
16
|
## Running the App
|
|
13
17
|
|
|
@@ -35,20 +39,11 @@
|
|
|
35
39
|
{{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
|
|
36
40
|
## Auth Setup
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
{{#if useDrizzle}}Then run Drizzle migrations:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
{{#if isPnpm}}pnpm drizzle-kit generate && pnpm drizzle-kit migrate{{else if isYarn}}yarn drizzle-kit generate && yarn drizzle-kit migrate{{else}}npx drizzle-kit generate && npx drizzle-kit migrate{{/if}}
|
|
48
|
-
```
|
|
49
|
-
|
|
42
|
+
{{#if (eq auth "better-auth:stateless")}}
|
|
43
|
+
Configure the Better Auth secret, URL and external OIDC provider settings. Register the callback URL with your provider. Stateless auth requires no authentication schema generation or database migration.
|
|
44
|
+
{{else}}
|
|
45
|
+
Follow the ordered steps in Setup. Run the generated `auth:generate` script in `apps/api-gateway` before applying the database schema and regenerating Prisma Client in `packages/db`. The script uses the installed CLI version and preserves application-owned models.
|
|
50
46
|
{{/if}}
|
|
51
|
-
See https://better-auth.com/docs/adapters/prisma for more details.
|
|
52
47
|
|
|
53
48
|
### Usage
|
|
54
49
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
CORS_ORIGIN=http://localhost:
|
|
1
|
+
CORS_ORIGIN=http://localhost:3000
|
|
2
2
|
PORT=3000
|
|
3
3
|
{{#if hasGraphql}}
|
|
4
4
|
GRAPHQL_PLAYGROUND=true
|
|
@@ -25,7 +25,11 @@ SQLSERVER_TRUST_SERVER_CERTIFICATE=true
|
|
|
25
25
|
{{#if hasMongodb}}
|
|
26
26
|
MONGODB_URL=mongodb://localhost:27017/{{projectNameKebab}}_db
|
|
27
27
|
{{/if}}
|
|
28
|
-
{{#if (eq auth "passport")}}
|
|
28
|
+
{{#if (and (eq auth "passport") (not hasDatabase))}}
|
|
29
|
+
OIDC_JWKS_URI=https://identity.example.com/.well-known/jwks.json
|
|
30
|
+
OIDC_ISSUER=https://identity.example.com/
|
|
31
|
+
OIDC_AUDIENCE=generated-resource-server
|
|
32
|
+
{{else if (eq auth "passport")}}
|
|
29
33
|
JWT_ACCESS_SECRET=change-me-to-a-random-secret-at-least-32-characters-long
|
|
30
34
|
{{#if hasDatabase}}
|
|
31
35
|
JWT_REFRESH_SECRET=change-me-to-a-different-random-secret-at-least-32-characters
|
|
@@ -12,5 +12,11 @@ allowBuilds:
|
|
|
12
12
|
{{#if hasSqlite}}
|
|
13
13
|
better-sqlite3: true
|
|
14
14
|
{{/if}}
|
|
15
|
+
{{#if hasTrpc}}
|
|
16
|
+
peerDependencyRules:
|
|
17
|
+
allowedVersions:
|
|
18
|
+
"nestjs-trpc>@nestjs/common": "^12.0.0"
|
|
19
|
+
"nestjs-trpc>@nestjs/core": "^12.0.0"
|
|
20
|
+
{{/if}}
|
|
15
21
|
catalog:
|
|
16
22
|
dotenv: ^17.2.2
|
|
@@ -71,8 +71,8 @@ async function bootstrap() {
|
|
|
71
71
|
{{/if}}
|
|
72
72
|
{{#if (includes apis "trpc")}}
|
|
73
73
|
trpc: {
|
|
74
|
-
routerFilePath: "./src/trpc/router.ts",
|
|
75
74
|
pathPrefix: "/trpc",
|
|
75
|
+
routerFilePath: "./{{trpcGeneratePath}}/server.ts",
|
|
76
76
|
},
|
|
77
77
|
{{/if}}
|
|
78
78
|
zod: {
|
|
@@ -99,8 +99,8 @@ async function bootstrap() {
|
|
|
99
99
|
{{/if}}
|
|
100
100
|
{{#if (includes apis "trpc")}}
|
|
101
101
|
trpc: {
|
|
102
|
-
routerFilePath: "./src/trpc/router.ts",
|
|
103
102
|
pathPrefix: "/trpc",
|
|
103
|
+
routerFilePath: "./{{trpcGeneratePath}}/server.ts",
|
|
104
104
|
},
|
|
105
105
|
{{/if}}
|
|
106
106
|
zod: {
|
|
@@ -43,7 +43,7 @@ async function bootstrap() {
|
|
|
43
43
|
{{/if}}
|
|
44
44
|
{{#if (includes apis "trpc")}}
|
|
45
45
|
trpc: {
|
|
46
|
-
routerFilePath: "./
|
|
46
|
+
routerFilePath: "./{{trpcGeneratePath}}/server.ts",
|
|
47
47
|
pathPrefix: "/trpc",
|
|
48
48
|
},
|
|
49
49
|
{{/if}}
|
|
@@ -71,7 +71,7 @@ async function bootstrap() {
|
|
|
71
71
|
{{/if}}
|
|
72
72
|
{{#if (includes apis "trpc")}}
|
|
73
73
|
trpc: {
|
|
74
|
-
routerFilePath: "./
|
|
74
|
+
routerFilePath: "./{{trpcGeneratePath}}/server.ts",
|
|
75
75
|
pathPrefix: "/trpc",
|
|
76
76
|
},
|
|
77
77
|
{{/if}}
|
|
@@ -2,21 +2,27 @@ PORT=3000
|
|
|
2
2
|
MICROSERVICE_PORT=3001
|
|
3
3
|
CORS_ORIGIN=http://localhost:3001
|
|
4
4
|
{{#if (includes microservices "redis")}}
|
|
5
|
+
REDIS_PORT=6379
|
|
5
6
|
REDIS_URL=redis://127.0.0.1:6379
|
|
6
7
|
{{/if}}
|
|
7
8
|
{{#if (includes microservices "mqtt")}}
|
|
9
|
+
MQTT_PORT=1883
|
|
8
10
|
MQTT_URL=mqtt://127.0.0.1:1883
|
|
9
11
|
{{/if}}
|
|
10
12
|
{{#if (includes microservices "nats")}}
|
|
13
|
+
NATS_PORT=4222
|
|
11
14
|
NATS_URL=nats://127.0.0.1:4222
|
|
12
15
|
{{/if}}
|
|
13
16
|
{{#if (includes microservices "rabbitmq")}}
|
|
17
|
+
RABBITMQ_PORT=5672
|
|
14
18
|
RABBITMQ_URL=amqp://127.0.0.1:5672
|
|
15
19
|
{{/if}}
|
|
16
20
|
{{#if (includes microservices "kafka")}}
|
|
21
|
+
KAFKA_PORT=9092
|
|
17
22
|
KAFKA_BROKER=127.0.0.1:9092
|
|
18
23
|
{{/if}}
|
|
19
24
|
{{#if (includes microservices "grpc")}}
|
|
25
|
+
GRPC_PORT=5000
|
|
20
26
|
GRPC_URL=0.0.0.0:5000
|
|
21
27
|
{{/if}}
|
|
22
28
|
{{#if hasGraphql}}
|
package/dist/templates/single-project/architecture/nest-microservice/src/app.controller.ts.hbs
CHANGED
|
@@ -9,11 +9,11 @@ import { EventPattern, MessagePattern } from "@nestjs/microservices";
|
|
|
9
9
|
import { AppService } from "./app.service.js";
|
|
10
10
|
|
|
11
11
|
{{#unless (includes microservices "grpc")}}
|
|
12
|
-
|
|
12
|
+
interface AuditEvent {
|
|
13
13
|
id: string;
|
|
14
14
|
payload: Record<string, unknown>;
|
|
15
15
|
source: string;
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
const isAuditEvent = (value: unknown): value is AuditEvent => {
|
|
19
19
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Module } from "@nestjs/common";
|
|
2
|
+
{{#if hasRateLimiting}}
|
|
3
|
+
import { APP_GUARD } from "@nestjs/core";
|
|
4
|
+
import { ThrottlerModule } from "@nestjs/throttler";
|
|
5
|
+
{{/if}}
|
|
2
6
|
{{#if (or hasDatabase hasOrm)}}
|
|
3
7
|
import { DbModule } from "./database/db.module.js";
|
|
4
8
|
import { env } from "./config/env.js";
|
|
@@ -9,6 +13,15 @@ import { AuthModule } from "./auth/auth.module.js";
|
|
|
9
13
|
|
|
10
14
|
import { AppController } from "./app.controller.js";
|
|
11
15
|
import { AppService } from "./app.service.js";
|
|
16
|
+
{{#if hasRateLimiting}}
|
|
17
|
+
import { HttpThrottlerGuard } from "./http-throttler.guard.js";
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{#if (and hasRest hasTodoExample)}}
|
|
20
|
+
import { TodoModule } from "./api/todo/todo.module.js";
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if hasHealthCheck}}
|
|
23
|
+
import { HealthModule } from "./health/health.module.js";
|
|
24
|
+
{{/if}}
|
|
12
25
|
|
|
13
26
|
@Module({
|
|
14
27
|
controllers: [AppController],
|
|
@@ -24,7 +37,21 @@ import { AppService } from "./app.service.js";
|
|
|
24
37
|
{{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
|
|
25
38
|
AuthModule,
|
|
26
39
|
{{/if}}
|
|
40
|
+
{{#if hasRateLimiting}}
|
|
41
|
+
ThrottlerModule.forRoot([{ limit: 60, ttl: 60_000 }]),
|
|
42
|
+
{{/if}}
|
|
43
|
+
{{#if (and hasRest hasTodoExample)}}
|
|
44
|
+
TodoModule,
|
|
45
|
+
{{/if}}
|
|
46
|
+
{{#if hasHealthCheck}}
|
|
47
|
+
HealthModule,
|
|
48
|
+
{{/if}}
|
|
49
|
+
],
|
|
50
|
+
providers: [
|
|
51
|
+
AppService,
|
|
52
|
+
{{#if hasRateLimiting}}
|
|
53
|
+
{ provide: APP_GUARD, useClass: HttpThrottlerGuard },
|
|
54
|
+
{{/if}}
|
|
27
55
|
],
|
|
28
|
-
providers: [AppService],
|
|
29
56
|
})
|
|
30
57
|
export class AppModule {}
|
package/dist/templates/single-project/architecture/nest-microservice/src/http-throttler.guard.ts.hbs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common";
|
|
2
|
+
import type { ExecutionContext } from "@nestjs/common";
|
|
3
|
+
import { ThrottlerGuard } from "@nestjs/throttler";
|
|
4
|
+
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class HttpThrottlerGuard extends ThrottlerGuard {
|
|
7
|
+
canActivate(context: ExecutionContext): Promise<boolean> {
|
|
8
|
+
if (context.getType() !== "http") {
|
|
9
|
+
return Promise.resolve(true);
|
|
10
|
+
}
|
|
11
|
+
return super.canActivate(context);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -78,7 +78,7 @@ async function bootstrap() {
|
|
|
78
78
|
{{/if}}
|
|
79
79
|
{{#if (includes apis "trpc")}}
|
|
80
80
|
trpc: {
|
|
81
|
-
routerFilePath: "./
|
|
81
|
+
routerFilePath: "./{{trpcGeneratePath}}/server.ts",
|
|
82
82
|
pathPrefix: "/trpc",
|
|
83
83
|
},
|
|
84
84
|
{{/if}}
|
|
@@ -106,7 +106,7 @@ async function bootstrap() {
|
|
|
106
106
|
{{/if}}
|
|
107
107
|
{{#if (includes apis "trpc")}}
|
|
108
108
|
trpc: {
|
|
109
|
-
routerFilePath: "./
|
|
109
|
+
routerFilePath: "./{{trpcGeneratePath}}/server.ts",
|
|
110
110
|
pathPrefix: "/trpc",
|
|
111
111
|
},
|
|
112
112
|
{{/if}}
|
|
@@ -6,6 +6,9 @@ import { Test } from "@nestjs/testing";
|
|
|
6
6
|
import { setTimeout as delay } from "node:timers/promises";
|
|
7
7
|
import request from "supertest";
|
|
8
8
|
{{/unless}}
|
|
9
|
+
{{#if (and (includes microservices "grpc") (or hasTodoExample hasHealthCheck hasRateLimiting))}}
|
|
10
|
+
import request from "supertest";
|
|
11
|
+
{{/if}}
|
|
9
12
|
import { firstValueFrom } from "rxjs";
|
|
10
13
|
{{#if (includes microservices "grpc")}}
|
|
11
14
|
import type { Observable } from "rxjs";
|
|
@@ -96,6 +99,38 @@ it("sends ping through the selected message transport", async () => {
|
|
|
96
99
|
{{/if}}
|
|
97
100
|
}, 60_000);
|
|
98
101
|
|
|
102
|
+
{{#if (or hasTodoExample hasHealthCheck hasRateLimiting)}}
|
|
103
|
+
it("serves the selected HTTP extras alongside the message transport", async () => {
|
|
104
|
+
const server = app.getHttpServer();
|
|
105
|
+
{{#if hasTodoExample}}
|
|
106
|
+
const created = await request(server)
|
|
107
|
+
.post("/api/todos")
|
|
108
|
+
.send({ completed: false, title: "Microservice todo" })
|
|
109
|
+
.expect(201);
|
|
110
|
+
const todo = created.body as { id: string };
|
|
111
|
+
const listed = await request(server).get("/api/todos").expect(200);
|
|
112
|
+
expect(listed.body).toEqual(
|
|
113
|
+
expect.arrayContaining([expect.objectContaining({ id: todo.id })])
|
|
114
|
+
);
|
|
115
|
+
await request(server)
|
|
116
|
+
.put(`/api/todos/${todo.id}`)
|
|
117
|
+
.send({ completed: true })
|
|
118
|
+
.expect(200);
|
|
119
|
+
await request(server).delete(`/api/todos/${todo.id}`).expect(200);
|
|
120
|
+
{{/if}}
|
|
121
|
+
{{#if hasHealthCheck}}
|
|
122
|
+
const health = await request(server).get("/api/health").expect(200);
|
|
123
|
+
expect(health.body.info.app.status).toBe("up");
|
|
124
|
+
{{/if}}
|
|
125
|
+
{{#if hasRateLimiting}}
|
|
126
|
+
const responses = await Promise.all(
|
|
127
|
+
Array.from({ length: 80 }, () => request(server).get("/api"))
|
|
128
|
+
);
|
|
129
|
+
expect(responses.some((response) => response.status === 429)).toBe(true);
|
|
130
|
+
{{/if}}
|
|
131
|
+
}, 60_000);
|
|
132
|
+
{{/if}}
|
|
133
|
+
|
|
99
134
|
afterAll(async () => {
|
|
100
135
|
await app?.close();
|
|
101
136
|
client.close();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-arch/tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Interactive terminal UI for generating NestJS projects",
|
|
6
6
|
"keywords": [
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
"zod": "^4.1.13"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@nest-arch/core": "0.4.3",
|
|
49
|
+
"@nest-arch/env": "0.0.0",
|
|
50
|
+
"@nest-arch/shared": "0.0.0",
|
|
48
51
|
"@types/react": "^18.3.12",
|
|
49
52
|
"@types/semver": "^7.8.0",
|
|
50
53
|
"ink-testing-library": "^4.0.0",
|
|
51
54
|
"pkgroll": "^2.5.2",
|
|
52
55
|
"tsx": "^4.19.2",
|
|
53
|
-
"vitest": "^4.1.7"
|
|
54
|
-
"@nest-arch/env": "0.0.0",
|
|
55
|
-
"@nest-arch/core": "0.4.3",
|
|
56
|
-
"@nest-arch/shared": "0.0.0"
|
|
56
|
+
"vitest": "^4.1.7"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"typescript": "^5"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var o="0.4.6",O={version:o};const s="Nest Arch",A=`v${O.version}`,n="Build production-ready NestJS projects.",t="#e54545",c="#A0A0A0",R="#6B6B6B",C="#E5E5E5",E="#61AFEF",_="#3A3A3A",e="#7FD99A",r="#E8C468",L="#e96142ff";export{s as APP_NAME,n as APP_TAGLINE,A as APP_VERSION,E as COLOR_ACCENT,c as COLOR_DIM,R as COLOR_DIMMER,_ as COLOR_DIVIDER,C as COLOR_FG,t as COLOR_RED,e as COLOR_SUCCESS,r as COLOR_WARM,L as COLOR_WARM_SECONDARY};
|