fragment-ts 1.0.2 → 1.0.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 +401 -0
- package/USAGE.md +1439 -0
- package/bin/fragment.js +2 -0
- package/dist/ai/ai.module.d.ts +27 -0
- package/dist/ai/ai.module.d.ts.map +1 -0
- package/dist/ai/ai.module.js +77 -0
- package/dist/ai/ai.module.js.map +1 -0
- package/dist/auth/auth.module.d.ts +18 -0
- package/dist/auth/auth.module.d.ts.map +1 -0
- package/dist/auth/auth.module.js +89 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/cli/commands/build.command.d.ts +6 -1
- package/dist/cli/commands/build.command.d.ts.map +1 -0
- package/dist/cli/commands/build.command.js +130 -10
- package/dist/cli/commands/build.command.js.map +1 -1
- package/dist/cli/commands/diagnostics.command.d.ts +16 -0
- package/dist/cli/commands/diagnostics.command.d.ts.map +1 -0
- package/dist/cli/commands/diagnostics.command.js +419 -0
- package/dist/cli/commands/diagnostics.command.js.map +1 -0
- package/dist/cli/commands/generate.command.d.ts +13 -6
- package/dist/cli/commands/generate.command.d.ts.map +1 -0
- package/dist/cli/commands/generate.command.js +200 -128
- package/dist/cli/commands/generate.command.js.map +1 -1
- package/dist/cli/commands/init.command.d.ts +11 -5
- package/dist/cli/commands/init.command.d.ts.map +1 -0
- package/dist/cli/commands/init.command.js +267 -305
- package/dist/cli/commands/init.command.js.map +1 -1
- package/dist/cli/commands/migrate.command.d.ts +12 -5
- package/dist/cli/commands/migrate.command.d.ts.map +1 -0
- package/dist/cli/commands/migrate.command.js +211 -83
- package/dist/cli/commands/migrate.command.js.map +1 -1
- package/dist/cli/commands/serve.command.d.ts +5 -4
- package/dist/cli/commands/serve.command.d.ts.map +1 -0
- package/dist/cli/commands/serve.command.js +178 -21
- package/dist/cli/commands/serve.command.js.map +1 -1
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +22 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/container/di-container.d.ts +13 -7
- package/dist/core/container/di-container.d.ts.map +1 -0
- package/dist/core/container/di-container.js +75 -25
- package/dist/core/container/di-container.js.map +1 -1
- package/dist/core/decorators/application.decorator.d.ts +8 -0
- package/dist/core/decorators/application.decorator.d.ts.map +1 -0
- package/dist/core/decorators/application.decorator.js +16 -0
- package/dist/core/decorators/application.decorator.js.map +1 -0
- package/dist/core/decorators/auto-configuration.decorator.d.ts +2 -0
- package/dist/core/decorators/auto-configuration.decorator.d.ts.map +1 -0
- package/dist/core/decorators/auto-configuration.decorator.js +19 -0
- package/dist/core/decorators/auto-configuration.decorator.js.map +1 -0
- package/dist/core/decorators/conditional.decorators.d.ts +4 -0
- package/dist/core/decorators/conditional.decorators.d.ts.map +1 -0
- package/dist/core/decorators/conditional.decorators.js +22 -0
- package/dist/core/decorators/conditional.decorators.js.map +1 -0
- package/dist/core/decorators/controller.decorator.d.ts +1 -3
- package/dist/core/decorators/controller.decorator.d.ts.map +1 -0
- package/dist/core/decorators/controller.decorator.js +12 -9
- package/dist/core/decorators/controller.decorator.js.map +1 -1
- package/dist/core/decorators/http.decorators.d.ts +12 -0
- package/dist/core/decorators/http.decorators.d.ts.map +1 -0
- package/dist/core/decorators/http.decorators.js +52 -0
- package/dist/core/decorators/http.decorators.js.map +1 -0
- package/dist/core/decorators/injectable.decorator.d.ts +3 -3
- package/dist/core/decorators/injectable.decorator.d.ts.map +1 -0
- package/dist/core/decorators/injectable.decorator.js +11 -8
- package/dist/core/decorators/injectable.decorator.js.map +1 -1
- package/dist/core/decorators/injection.decorators.d.ts +5 -0
- package/dist/core/decorators/injection.decorators.d.ts.map +1 -0
- package/dist/core/decorators/injection.decorators.js +29 -0
- package/dist/core/decorators/injection.decorators.js.map +1 -0
- package/dist/core/decorators/repository.decorator.d.ts +1 -0
- package/dist/core/decorators/repository.decorator.d.ts.map +1 -0
- package/dist/core/decorators/repository.decorator.js +12 -1
- package/dist/core/decorators/repository.decorator.js.map +1 -1
- package/dist/core/decorators/service.decorator.d.ts +1 -0
- package/dist/core/decorators/service.decorator.d.ts.map +1 -0
- package/dist/core/decorators/service.decorator.js +12 -1
- package/dist/core/decorators/service.decorator.js.map +1 -1
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +29 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/loader/file-loader.d.ts +5 -0
- package/dist/core/loader/file-loader.d.ts.map +1 -0
- package/dist/core/loader/file-loader.js +85 -0
- package/dist/core/loader/file-loader.js.map +1 -0
- package/dist/core/metadata/metadata-keys.d.ts +20 -0
- package/dist/core/metadata/metadata-keys.d.ts.map +1 -0
- package/dist/core/metadata/metadata-keys.js +23 -0
- package/dist/core/metadata/metadata-keys.js.map +1 -0
- package/dist/core/metadata/metadata-storage.d.ts +36 -0
- package/dist/core/metadata/metadata-storage.d.ts.map +1 -0
- package/dist/core/metadata/metadata-storage.js +53 -0
- package/dist/core/metadata/metadata-storage.js.map +1 -0
- package/dist/core/scanner/component-scanner.d.ts +16 -0
- package/dist/core/scanner/component-scanner.d.ts.map +1 -0
- package/dist/core/scanner/component-scanner.js +147 -0
- package/dist/core/scanner/component-scanner.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/plugin-manager.d.ts +14 -0
- package/dist/plugins/plugin-manager.d.ts.map +1 -0
- package/dist/{cli/utils/file-generator.js → plugins/plugin-manager.js} +32 -24
- package/dist/plugins/plugin-manager.js.map +1 -0
- package/dist/shared/errors.d.ts +18 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +41 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/testing/runner.d.ts +26 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +143 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/typeorm/typeorm-module.d.ts +36 -0
- package/dist/typeorm/typeorm-module.d.ts.map +1 -0
- package/dist/typeorm/typeorm-module.js +150 -0
- package/dist/typeorm/typeorm-module.js.map +1 -0
- package/dist/web/application.d.ts +29 -0
- package/dist/web/application.d.ts.map +1 -0
- package/dist/web/application.js +301 -0
- package/dist/web/application.js.map +1 -0
- package/dist/web/interfaces.d.ts +14 -0
- package/dist/web/interfaces.d.ts.map +1 -0
- package/dist/{auth/dto/login.dto.js → web/interfaces.js} +1 -1
- package/dist/web/interfaces.js.map +1 -0
- package/examples/blog-api/fragment.json +14 -0
- package/examples/blog-api/package-lock.json +3405 -0
- package/examples/blog-api/package.json +19 -0
- package/examples/blog-api/src/controllers/app.controller.ts +9 -0
- package/examples/blog-api/src/controllers/auth.controller.ts +17 -0
- package/examples/blog-api/src/controllers/category.controller.ts +29 -0
- package/examples/blog-api/src/controllers/comment.controller.ts +31 -0
- package/examples/blog-api/src/controllers/post.controller.ts +46 -0
- package/examples/blog-api/src/dto/create-category.dto.ts +6 -0
- package/examples/blog-api/src/dto/create-comment.dto.ts +6 -0
- package/examples/blog-api/src/dto/create-post.dto.ts +6 -0
- package/examples/blog-api/src/entities/category.entity.ts +16 -0
- package/examples/blog-api/src/entities/comment.entity.ts +29 -0
- package/examples/blog-api/src/entities/post.entity.ts +42 -0
- package/examples/blog-api/src/entities/user.entity.ts +25 -0
- package/examples/blog-api/src/main.ts +16 -0
- package/examples/blog-api/src/migrations/1767737463842-InitialSchema.ts +60 -0
- package/examples/blog-api/src/repositories/category.repository.ts +25 -0
- package/examples/blog-api/src/repositories/comment.repository.ts +25 -0
- package/examples/blog-api/src/repositories/post.repository.ts +29 -0
- package/examples/blog-api/src/seeds/SampleData.seed.ts +41 -0
- package/examples/blog-api/src/services/app.service.ts +8 -0
- package/examples/blog-api/src/services/auth.service.ts +15 -0
- package/examples/blog-api/src/services/category.service.ts +27 -0
- package/examples/blog-api/src/services/comment.service.ts +31 -0
- package/examples/blog-api/src/services/post.service.ts +35 -0
- package/examples/blog-api/tsconfig.json +23 -0
- package/package.json +55 -33
- package/src/ai/ai.module.ts +110 -0
- package/src/auth/auth.module.ts +77 -0
- package/src/cli/commands/build.command.ts +123 -13
- package/src/cli/commands/diagnostics.command.ts +438 -0
- package/src/cli/commands/generate.command.ts +206 -137
- package/src/cli/commands/init.command.ts +337 -349
- package/src/cli/commands/migrate.command.ts +203 -88
- package/src/cli/commands/serve.command.ts +176 -24
- package/src/cli/index.ts +23 -0
- package/src/core/container/di-container.ts +83 -26
- package/src/core/decorators/application.decorator.ts +26 -0
- package/src/core/decorators/auto-configuration.decorator.ts +17 -0
- package/src/core/decorators/conditional.decorators.ts +19 -0
- package/src/core/decorators/controller.decorator.ts +14 -11
- package/src/core/decorators/http.decorators.ts +71 -0
- package/src/core/decorators/injectable.decorator.ts +14 -9
- package/src/core/decorators/injection.decorators.ts +26 -0
- package/src/core/decorators/repository.decorator.ts +13 -2
- package/src/core/decorators/service.decorator.ts +13 -2
- package/src/core/index.ts +13 -0
- package/src/core/loader/file-loader.ts +55 -0
- package/src/core/metadata/metadata-keys.ts +19 -0
- package/src/core/metadata/metadata-storage.ts +91 -0
- package/src/core/scanner/component-scanner.ts +129 -0
- package/src/index.ts +45 -0
- package/src/plugins/plugin-manager.ts +52 -0
- package/src/shared/errors.ts +34 -0
- package/src/testing/runner.ts +143 -0
- package/src/typeorm/typeorm-module.ts +216 -0
- package/src/web/application.ts +348 -0
- package/src/web/interfaces.ts +17 -0
- package/tsconfig.json +8 -6
- package/.env.example +0 -0
- package/base.ts +0 -1810
- package/base2.ts +0 -968
- package/bin/frg.ts +0 -5
- package/config/fragment.lock.yaml +0 -0
- package/config/fragment.yaml +0 -0
- package/dist/app.d.ts +0 -15
- package/dist/app.js +0 -91
- package/dist/app.js.map +0 -1
- package/dist/auth/auth.controller.d.ts +0 -10
- package/dist/auth/auth.controller.js +0 -88
- package/dist/auth/auth.controller.js.map +0 -1
- package/dist/auth/auth.middleware.d.ts +0 -2
- package/dist/auth/auth.middleware.js +0 -25
- package/dist/auth/auth.middleware.js.map +0 -1
- package/dist/auth/auth.service.d.ts +0 -20
- package/dist/auth/auth.service.js +0 -144
- package/dist/auth/auth.service.js.map +0 -1
- package/dist/auth/dto/login.dto.d.ts +0 -9
- package/dist/auth/dto/login.dto.js.map +0 -1
- package/dist/cli/cli.d.ts +0 -12
- package/dist/cli/cli.js +0 -187
- package/dist/cli/cli.js.map +0 -1
- package/dist/cli/commands/config.command.d.ts +0 -6
- package/dist/cli/commands/config.command.js +0 -285
- package/dist/cli/commands/config.command.js.map +0 -1
- package/dist/cli/templates/controller.template.d.ts +0 -1
- package/dist/cli/templates/controller.template.js +0 -53
- package/dist/cli/templates/controller.template.js.map +0 -1
- package/dist/cli/templates/entity.template.d.ts +0 -1
- package/dist/cli/templates/entity.template.js +0 -24
- package/dist/cli/templates/entity.template.js.map +0 -1
- package/dist/cli/templates/repository.template.d.ts +0 -1
- package/dist/cli/templates/repository.template.js +0 -44
- package/dist/cli/templates/repository.template.js.map +0 -1
- package/dist/cli/templates/service.template.d.ts +0 -1
- package/dist/cli/templates/service.template.js +0 -44
- package/dist/cli/templates/service.template.js.map +0 -1
- package/dist/cli/utils/file-generator.d.ts +0 -9
- package/dist/cli/utils/file-generator.js.map +0 -1
- package/dist/cli/utils/logger.d.ts +0 -14
- package/dist/cli/utils/logger.js +0 -50
- package/dist/cli/utils/logger.js.map +0 -1
- package/dist/controllers/health.controller.d.ts +0 -13
- package/dist/controllers/health.controller.js +0 -51
- package/dist/controllers/health.controller.js.map +0 -1
- package/dist/core/config/config-loader.d.ts +0 -31
- package/dist/core/config/config-loader.js +0 -99
- package/dist/core/config/config-loader.js.map +0 -1
- package/dist/core/decorators/auth-guard.decorator.d.ts +0 -3
- package/dist/core/decorators/auth-guard.decorator.js +0 -19
- package/dist/core/decorators/auth-guard.decorator.js.map +0 -1
- package/dist/core/decorators/autowire.decorator.d.ts +0 -3
- package/dist/core/decorators/autowire.decorator.js +0 -18
- package/dist/core/decorators/autowire.decorator.js.map +0 -1
- package/dist/core/decorators/middleware.decorator.d.ts +0 -3
- package/dist/core/decorators/middleware.decorator.js +0 -21
- package/dist/core/decorators/middleware.decorator.js.map +0 -1
- package/dist/core/decorators/route.decorator.d.ts +0 -14
- package/dist/core/decorators/route.decorator.js +0 -33
- package/dist/core/decorators/route.decorator.js.map +0 -1
- package/dist/core/openai/openai-client.d.ts +0 -12
- package/dist/core/openai/openai-client.js +0 -94
- package/dist/core/openai/openai-client.js.map +0 -1
- package/dist/database/data-source.d.ts +0 -4
- package/dist/database/data-source.js +0 -27
- package/dist/database/data-source.js.map +0 -1
- package/dist/entities/session.entity.d.ts +0 -9
- package/dist/entities/session.entity.js +0 -46
- package/dist/entities/session.entity.js.map +0 -1
- package/dist/entities/user.entity.d.ts +0 -10
- package/dist/entities/user.entity.js +0 -49
- package/dist/entities/user.entity.js.map +0 -1
- package/dist/middlewares/logging.middleware.d.ts +0 -2
- package/dist/middlewares/logging.middleware.js +0 -29
- package/dist/middlewares/logging.middleware.js.map +0 -1
- package/dist/repositories/session.repository.d.ts +0 -9
- package/dist/repositories/session.repository.js +0 -51
- package/dist/repositories/session.repository.js.map +0 -1
- package/dist/repositories/user.repository.d.ts +0 -10
- package/dist/repositories/user.repository.js +0 -44
- package/dist/repositories/user.repository.js.map +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -31
- package/dist/server.js.map +0 -1
- package/dist/services/health.service.d.ts +0 -13
- package/dist/services/health.service.js +0 -45
- package/dist/services/health.service.js.map +0 -1
- package/readme.md +0 -120
- package/src/app.ts +0 -121
- package/src/auth/auth.controller.ts +0 -52
- package/src/auth/auth.middleware.ts +0 -27
- package/src/auth/auth.service.ts +0 -110
- package/src/auth/dto/login.dto.ts +0 -11
- package/src/cli/cli.ts +0 -212
- package/src/cli/commands/config.command.ts +0 -280
- package/src/cli/templates/controller.template.ts +0 -51
- package/src/cli/templates/entity.template.ts +0 -22
- package/src/cli/templates/repository.template.ts +0 -42
- package/src/cli/templates/service.template.ts +0 -42
- package/src/cli/utils/file-generator.ts +0 -37
- package/src/cli/utils/logger.ts +0 -52
- package/src/controllers/health.controller.ts +0 -24
- package/src/core/config/config-loader.ts +0 -98
- package/src/core/decorators/auth-guard.decorator.ts +0 -15
- package/src/core/decorators/autowire.decorator.ts +0 -18
- package/src/core/decorators/middleware.decorator.ts +0 -18
- package/src/core/decorators/route.decorator.ts +0 -33
- package/src/core/openai/openai-client.ts +0 -99
- package/src/database/data-source.ts +0 -29
- package/src/entities/session.entity.ts +0 -25
- package/src/entities/user.entity.ts +0 -27
- package/src/middlewares/logging.middleware.ts +0 -28
- package/src/repositories/session.repository.ts +0 -42
- package/src/repositories/user.repository.ts +0 -37
- package/src/server.ts +0 -32
- package/src/services/health.service.ts +0 -29
package/src/auth/auth.service.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import * as crypto from 'crypto';
|
|
3
|
-
import * as bcrypt from 'bcrypt';
|
|
4
|
-
import { Service } from '../core/decorators/service.decorator';
|
|
5
|
-
import { Autowire } from '../core/decorators/autowire.decorator';
|
|
6
|
-
import { UserRepository } from '../repositories/user.repository';
|
|
7
|
-
import { SessionRepository } from '../repositories/session.repository';
|
|
8
|
-
import { LoginDTO, RegisterDTO } from './dto/login.dto';
|
|
9
|
-
import { ConfigLoader } from '../core/config/config-loader';
|
|
10
|
-
|
|
11
|
-
@Service()
|
|
12
|
-
export class AuthService {
|
|
13
|
-
constructor(
|
|
14
|
-
@Autowire() private userRepository: UserRepository,
|
|
15
|
-
@Autowire() private sessionRepository: SessionRepository
|
|
16
|
-
) {}
|
|
17
|
-
|
|
18
|
-
async register(dto: RegisterDTO): Promise<{ user: any; token: string }> {
|
|
19
|
-
const existingUser = await this.userRepository.findByEmail(dto.email);
|
|
20
|
-
if (existingUser) {
|
|
21
|
-
throw new Error('User already exists');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const passwordHash = await bcrypt.hash(dto.password, 10);
|
|
25
|
-
const user = await this.userRepository.create({
|
|
26
|
-
name: dto.name,
|
|
27
|
-
email: dto.email,
|
|
28
|
-
passwordHash
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const token = await this.createSession(user.id);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
user: { id: user.id, name: user.name, email: user.email },
|
|
35
|
-
token
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async login(dto: LoginDTO): Promise<{ user: any; token: string }> {
|
|
40
|
-
const user = await this.userRepository.findByEmail(dto.email);
|
|
41
|
-
if (!user) {
|
|
42
|
-
throw new Error('Invalid credentials');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const isValidPassword = await bcrypt.compare(dto.password, user.passwordHash);
|
|
46
|
-
if (!isValidPassword) {
|
|
47
|
-
throw new Error('Invalid credentials');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const token = await this.createSession(user.id);
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
user: { id: user.id, name: user.name, email: user.email },
|
|
54
|
-
token
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async logout(token: string): Promise<void> {
|
|
59
|
-
await this.sessionRepository.deleteByToken(token);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async validateToken(token: string): Promise<any> {
|
|
63
|
-
const session = await this.sessionRepository.findByToken(token);
|
|
64
|
-
if (!session) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
id: session.user.id,
|
|
70
|
-
name: session.user.name,
|
|
71
|
-
email: session.user.email
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private async createSession(userId: number): Promise<string> {
|
|
76
|
-
const token = crypto.randomBytes(32).toString('hex');
|
|
77
|
-
const config = ConfigLoader.get();
|
|
78
|
-
|
|
79
|
-
// Parse token expiry (e.g., "7d" = 7 days)
|
|
80
|
-
const expiryMs = this.parseExpiry(config.auth.tokenExpiry);
|
|
81
|
-
const expiresAt = new Date(Date.now() + expiryMs);
|
|
82
|
-
|
|
83
|
-
await this.sessionRepository.create({
|
|
84
|
-
token,
|
|
85
|
-
userId,
|
|
86
|
-
expiresAt
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return token;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private parseExpiry(expiry: string): number {
|
|
93
|
-
const match = expiry.match(/^(\d+)([dhms])$/);
|
|
94
|
-
if (!match) {
|
|
95
|
-
return 7 * 24 * 60 * 60 * 1000; // default 7 days
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const value = parseInt(match[1]);
|
|
99
|
-
const unit = match[2];
|
|
100
|
-
|
|
101
|
-
const multipliers: { [key: string]: number } = {
|
|
102
|
-
's': 1000,
|
|
103
|
-
'm': 60 * 1000,
|
|
104
|
-
'h': 60 * 60 * 1000,
|
|
105
|
-
'd': 24 * 60 * 60 * 1000
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
return value * multipliers[unit];
|
|
109
|
-
}
|
|
110
|
-
}
|
package/src/cli/cli.ts
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { InitCommand } from './commands/init.command';
|
|
5
|
-
import { GenerateCommand } from './commands/generate.command';
|
|
6
|
-
import { ConfigCommand } from './commands/config.command';
|
|
7
|
-
import { ServeCommand } from './commands/serve.command';
|
|
8
|
-
import { BuildCommand } from './commands/build.command';
|
|
9
|
-
import { MigrateCommand } from './commands/migrate.command';
|
|
10
|
-
import { CLILogger } from './utils/logger';
|
|
11
|
-
|
|
12
|
-
export class CLI {
|
|
13
|
-
private program: Command;
|
|
14
|
-
private initCommand: InitCommand;
|
|
15
|
-
private generateCommand: GenerateCommand;
|
|
16
|
-
private configCommand: ConfigCommand;
|
|
17
|
-
private serveCommand: ServeCommand;
|
|
18
|
-
private buildCommand: BuildCommand;
|
|
19
|
-
private migrateCommand: MigrateCommand;
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
this.program = new Command();
|
|
23
|
-
this.initCommand = new InitCommand();
|
|
24
|
-
this.generateCommand = new GenerateCommand();
|
|
25
|
-
this.configCommand = new ConfigCommand();
|
|
26
|
-
this.serveCommand = new ServeCommand();
|
|
27
|
-
this.buildCommand = new BuildCommand();
|
|
28
|
-
this.migrateCommand = new MigrateCommand();
|
|
29
|
-
|
|
30
|
-
this.setupCommands();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private setupCommands(): void {
|
|
34
|
-
this.program
|
|
35
|
-
.name('frg')
|
|
36
|
-
.description('Fragment Framework CLI - Build powerful TypeScript backends')
|
|
37
|
-
.version('1.0.0');
|
|
38
|
-
|
|
39
|
-
// ASCII Art Banner
|
|
40
|
-
this.program
|
|
41
|
-
.addHelpText('beforeAll', () => {
|
|
42
|
-
return chalk.cyan(`
|
|
43
|
-
╔═══════════════════════════════════════════════════════════╗
|
|
44
|
-
║ ║
|
|
45
|
-
║ ███████╗██████╗ █████╗ ██████╗ ███╗ ███╗███████╗ ║
|
|
46
|
-
║ ██╔════╝██╔══██╗██╔══██╗██╔════╝ ████╗ ████║██╔════╝ ║
|
|
47
|
-
║ █████╗ ██████╔╝███████║██║ ███╗██╔████╔██║█████╗ ║
|
|
48
|
-
║ ██╔══╝ ██╔══██╗██╔══██║██║ ██║██║╚██╔╝██║██╔══╝ ║
|
|
49
|
-
║ ██║ ██║ ██║██║ ██║╚██████╔╝██║ ╚═╝ ██║███████╗ ║
|
|
50
|
-
║ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ║
|
|
51
|
-
║ ║
|
|
52
|
-
║ TypeScript Backend Framework (v1.0.0) ║
|
|
53
|
-
╚═══════════════════════════════════════════════════════════╝
|
|
54
|
-
`);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Init command
|
|
58
|
-
this.program
|
|
59
|
-
.command('init [project-name]')
|
|
60
|
-
.description('Initialize a new Fragment project')
|
|
61
|
-
.action(async (projectName) => {
|
|
62
|
-
await this.initCommand.execute(projectName);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// Generate commands
|
|
66
|
-
const generate = this.program
|
|
67
|
-
.command('generate')
|
|
68
|
-
.alias('g')
|
|
69
|
-
.description('Generate application components');
|
|
70
|
-
|
|
71
|
-
generate
|
|
72
|
-
.command('controller [name]')
|
|
73
|
-
.alias('c')
|
|
74
|
-
.description('Generate a new controller')
|
|
75
|
-
.action(async (name) => {
|
|
76
|
-
await this.generateCommand.execute('controller', name);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
generate
|
|
80
|
-
.command('service [name]')
|
|
81
|
-
.alias('s')
|
|
82
|
-
.description('Generate a new service')
|
|
83
|
-
.action(async (name) => {
|
|
84
|
-
await this.generateCommand.execute('service', name);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
generate
|
|
88
|
-
.command('repository [name]')
|
|
89
|
-
.alias('r')
|
|
90
|
-
.description('Generate a new repository')
|
|
91
|
-
.action(async (name) => {
|
|
92
|
-
await this.generateCommand.execute('repository', name);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
generate
|
|
96
|
-
.command('entity [name]')
|
|
97
|
-
.alias('e')
|
|
98
|
-
.description('Generate a new entity')
|
|
99
|
-
.action(async (name) => {
|
|
100
|
-
await this.generateCommand.execute('entity', name);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
generate
|
|
104
|
-
.command('resource [name]')
|
|
105
|
-
.alias('res')
|
|
106
|
-
.description('Generate a complete resource (controller, service, repository, entity)')
|
|
107
|
-
.action(async (name) => {
|
|
108
|
-
await this.generateCommand.execute('resource', name);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// Config commands
|
|
112
|
-
const config = this.program
|
|
113
|
-
.command('config')
|
|
114
|
-
.description('Configure Fragment application');
|
|
115
|
-
|
|
116
|
-
config
|
|
117
|
-
.command('ai')
|
|
118
|
-
.description('Configure OpenAI integration')
|
|
119
|
-
.action(async () => {
|
|
120
|
-
await this.configCommand.execute('ai');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
config
|
|
124
|
-
.command('db')
|
|
125
|
-
.alias('database')
|
|
126
|
-
.description('Configure database connection')
|
|
127
|
-
.action(async () => {
|
|
128
|
-
await this.configCommand.execute('db');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
config
|
|
132
|
-
.command('show')
|
|
133
|
-
.description('Show current configuration')
|
|
134
|
-
.action(async () => {
|
|
135
|
-
await this.configCommand.execute('show');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Serve command
|
|
139
|
-
this.program
|
|
140
|
-
.command('serve')
|
|
141
|
-
.alias('dev')
|
|
142
|
-
.description('Start development server')
|
|
143
|
-
.option('-p, --port <port>', 'Port number', parseInt)
|
|
144
|
-
.option('--no-watch', 'Disable file watching')
|
|
145
|
-
.action(async (options) => {
|
|
146
|
-
await this.serveCommand.execute(options);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Build command
|
|
150
|
-
this.program
|
|
151
|
-
.command('build')
|
|
152
|
-
.description('Build application for production')
|
|
153
|
-
.action(async () => {
|
|
154
|
-
await this.buildCommand.execute();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Migrate commands
|
|
158
|
-
const migrate = this.program
|
|
159
|
-
.command('migrate')
|
|
160
|
-
.alias('migration')
|
|
161
|
-
.description('Database migration commands');
|
|
162
|
-
|
|
163
|
-
migrate
|
|
164
|
-
.command('run')
|
|
165
|
-
.description('Run pending migrations')
|
|
166
|
-
.action(async () => {
|
|
167
|
-
await this.migrateCommand.execute('run');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
migrate
|
|
171
|
-
.command('generate')
|
|
172
|
-
.alias('create')
|
|
173
|
-
.description('Generate a new migration')
|
|
174
|
-
.action(async () => {
|
|
175
|
-
await this.migrateCommand.execute('generate');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
migrate
|
|
179
|
-
.command('revert')
|
|
180
|
-
.description('Revert last migration')
|
|
181
|
-
.action(async () => {
|
|
182
|
-
await this.migrateCommand.execute('revert');
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
migrate
|
|
186
|
-
.command('show')
|
|
187
|
-
.alias('status')
|
|
188
|
-
.description('Show migration status')
|
|
189
|
-
.action(async () => {
|
|
190
|
-
await this.migrateCommand.execute('show');
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// Info command
|
|
194
|
-
this.program
|
|
195
|
-
.command('info')
|
|
196
|
-
.description('Display Fragment CLI information')
|
|
197
|
-
.action(() => {
|
|
198
|
-
CLILogger.box('Fragment Framework CLI', [
|
|
199
|
-
'Version: 1.0.0',
|
|
200
|
-
'TypeScript Backend Framework',
|
|
201
|
-
'OOP + Decorators + DI',
|
|
202
|
-
'',
|
|
203
|
-
'Documentation: https://fragment-framework.dev',
|
|
204
|
-
'Repository: https://github.com/fragment/framework'
|
|
205
|
-
]);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
run(args: string[]): void {
|
|
210
|
-
this.program.parse(['node', 'frg', ...args]);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import * as yaml from 'js-yaml';
|
|
5
|
-
import { CLILogger } from '../utils/logger';
|
|
6
|
-
import { FileGenerator } from '../utils/file-generator';
|
|
7
|
-
import inquirer from 'inquirer';
|
|
8
|
-
|
|
9
|
-
export class ConfigCommand {
|
|
10
|
-
async execute(target: string): Promise<void> {
|
|
11
|
-
switch (target) {
|
|
12
|
-
case 'ai':
|
|
13
|
-
await this.configureAI();
|
|
14
|
-
break;
|
|
15
|
-
case 'db':
|
|
16
|
-
case 'database':
|
|
17
|
-
await this.configureDatabase();
|
|
18
|
-
break;
|
|
19
|
-
case 'show':
|
|
20
|
-
await this.showConfig();
|
|
21
|
-
break;
|
|
22
|
-
default:
|
|
23
|
-
CLILogger.error(`Unknown config target: ${target}`);
|
|
24
|
-
CLILogger.info('Available targets: ai, db, show');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private async configureAI(): Promise<void> {
|
|
29
|
-
CLILogger.title('🤖 OpenAI Configuration');
|
|
30
|
-
|
|
31
|
-
const answers = await inquirer.prompt([
|
|
32
|
-
{
|
|
33
|
-
type: 'password',
|
|
34
|
-
name: 'apiKey',
|
|
35
|
-
message: 'OpenAI API Key:',
|
|
36
|
-
mask: '*',
|
|
37
|
-
validate: (input: string) => {
|
|
38
|
-
if (!input || !input.startsWith('sk-')) {
|
|
39
|
-
return 'Please enter a valid OpenAI API key (starts with sk-)';
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
type: 'list',
|
|
46
|
-
name: 'model',
|
|
47
|
-
message: 'Default model:',
|
|
48
|
-
choices: [
|
|
49
|
-
'gpt-4-turbo',
|
|
50
|
-
'gpt-4',
|
|
51
|
-
'gpt-3.5-turbo',
|
|
52
|
-
'claude-sonnet-4-5-20250929',
|
|
53
|
-
'claude-opus-4-1-20250514'
|
|
54
|
-
],
|
|
55
|
-
default: 'gpt-4'
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
type: 'confirm',
|
|
59
|
-
name: 'saveToEnv',
|
|
60
|
-
message: 'Save API key to .env file?',
|
|
61
|
-
default: true
|
|
62
|
-
}
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
const configPath = path.join(process.cwd(), 'config/fragment.yaml');
|
|
66
|
-
|
|
67
|
-
if (!FileGenerator.fileExists(configPath)) {
|
|
68
|
-
CLILogger.error('fragment.yaml not found. Are you in a Fragment project?');
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const configContent = FileGenerator.readFile(configPath);
|
|
74
|
-
const config: any = yaml.load(configContent);
|
|
75
|
-
|
|
76
|
-
if (!config.openai) {
|
|
77
|
-
config.openai = {};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
config.openai.apiKey = answers.saveToEnv ? '${OPENAI_API_KEY}' : answers.apiKey;
|
|
81
|
-
config.openai.model = answers.model;
|
|
82
|
-
|
|
83
|
-
FileGenerator.writeFile(configPath, yaml.dump(config));
|
|
84
|
-
|
|
85
|
-
if (answers.saveToEnv) {
|
|
86
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
87
|
-
let envContent = '';
|
|
88
|
-
|
|
89
|
-
if (FileGenerator.fileExists(envPath)) {
|
|
90
|
-
envContent = FileGenerator.readFile(envPath);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Update or add OPENAI_API_KEY
|
|
94
|
-
if (envContent.includes('OPENAI_API_KEY=')) {
|
|
95
|
-
envContent = envContent.replace(
|
|
96
|
-
/OPENAI_API_KEY=.*/,
|
|
97
|
-
`OPENAI_API_KEY=${answers.apiKey}`
|
|
98
|
-
);
|
|
99
|
-
} else {
|
|
100
|
-
envContent += `\nOPENAI_API_KEY=${answers.apiKey}`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
FileGenerator.writeFile(envPath, envContent);
|
|
104
|
-
CLILogger.success('API key saved to .env file');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
CLILogger.success('OpenAI configuration updated');
|
|
108
|
-
CLILogger.table({
|
|
109
|
-
'Model': answers.model,
|
|
110
|
-
'API Key': answers.saveToEnv ? 'Stored in .env' : 'Stored in config'
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
} catch (error: any) {
|
|
114
|
-
CLILogger.error(`Failed to update configuration: ${error.message}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private async configureDatabase(): Promise<void> {
|
|
119
|
-
CLILogger.title('🗄️ Database Configuration');
|
|
120
|
-
|
|
121
|
-
const answers = await inquirer.prompt([
|
|
122
|
-
{
|
|
123
|
-
type: 'list',
|
|
124
|
-
name: 'type',
|
|
125
|
-
message: 'Database type:',
|
|
126
|
-
choices: ['postgres', 'mysql', 'sqlite', 'mongodb']
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
type: 'input',
|
|
130
|
-
name: 'host',
|
|
131
|
-
message: 'Host:',
|
|
132
|
-
default: 'localhost',
|
|
133
|
-
when: (answers) => answers.type !== 'sqlite'
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
type: 'input',
|
|
137
|
-
name: 'port',
|
|
138
|
-
message: 'Port:',
|
|
139
|
-
default: (answers: any) => {
|
|
140
|
-
const ports: any = { postgres: 5432, mysql: 3306, mongodb: 27017 };
|
|
141
|
-
return ports[answers.type] || 5432;
|
|
142
|
-
},
|
|
143
|
-
when: (answers) => answers.type !== 'sqlite'
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
type: 'input',
|
|
147
|
-
name: 'username',
|
|
148
|
-
message: 'Username:',
|
|
149
|
-
default: (answers: any) => answers.type === 'postgres' ? 'postgres' : 'root',
|
|
150
|
-
when: (answers) => answers.type !== 'sqlite'
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
type: 'password',
|
|
154
|
-
name: 'password',
|
|
155
|
-
message: 'Password:',
|
|
156
|
-
mask: '*',
|
|
157
|
-
when: (answers) => answers.type !== 'sqlite'
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
type: 'input',
|
|
161
|
-
name: 'database',
|
|
162
|
-
message: 'Database name:',
|
|
163
|
-
default: 'fragment_db'
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
type: 'confirm',
|
|
167
|
-
name: 'synchronize',
|
|
168
|
-
message: 'Auto-synchronize schema? (not recommended for production)',
|
|
169
|
-
default: true
|
|
170
|
-
}
|
|
171
|
-
]);
|
|
172
|
-
|
|
173
|
-
const configPath = path.join(process.cwd(), 'config/fragment.yaml');
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
const configContent = FileGenerator.readFile(configPath);
|
|
177
|
-
const config: any = yaml.load(configContent);
|
|
178
|
-
|
|
179
|
-
config.database = {
|
|
180
|
-
type: answers.type,
|
|
181
|
-
...(answers.type !== 'sqlite' && {
|
|
182
|
-
host: '${DB_HOST:' + answers.host + '}',
|
|
183
|
-
port: '${DB_PORT:' + answers.port + '}',
|
|
184
|
-
username: '${DB_USERNAME:' + answers.username + '}',
|
|
185
|
-
password: '${DB_PASSWORD}'
|
|
186
|
-
}),
|
|
187
|
-
database: '${DB_DATABASE:' + answers.database + '}',
|
|
188
|
-
synchronize: answers.synchronize,
|
|
189
|
-
logging: false
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
FileGenerator.writeFile(configPath, yaml.dump(config));
|
|
193
|
-
|
|
194
|
-
// Update .env
|
|
195
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
196
|
-
let envContent = FileGenerator.fileExists(envPath) ? FileGenerator.readFile(envPath) : '';
|
|
197
|
-
|
|
198
|
-
const envVars: any = {
|
|
199
|
-
DB_HOST: answers.host,
|
|
200
|
-
DB_PORT: answers.port,
|
|
201
|
-
DB_USERNAME: answers.username,
|
|
202
|
-
DB_PASSWORD: answers.password,
|
|
203
|
-
DB_DATABASE: answers.database
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
Object.entries(envVars).forEach(([key, value]) => {
|
|
207
|
-
if (value !== undefined) {
|
|
208
|
-
if (envContent.includes(`${key}=`)) {
|
|
209
|
-
envContent = envContent.replace(new RegExp(`${key}=.*`), `${key}=${value}`);
|
|
210
|
-
} else {
|
|
211
|
-
envContent += `\n${key}=${value}`;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
FileGenerator.writeFile(envPath, envContent.trim());
|
|
217
|
-
|
|
218
|
-
CLILogger.success('Database configuration updated');
|
|
219
|
-
CLILogger.table({
|
|
220
|
-
'Type': answers.type,
|
|
221
|
-
'Host': answers.host || 'N/A',
|
|
222
|
-
'Database': answers.database,
|
|
223
|
-
'Synchronize': answers.synchronize ? 'Yes' : 'No'
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
} catch (error: any) {
|
|
227
|
-
CLILogger.error(`Failed to update configuration: ${error.message}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private async showConfig(): Promise<void> {
|
|
232
|
-
CLILogger.title('📋 Current Configuration');
|
|
233
|
-
|
|
234
|
-
const configPath = path.join(process.cwd(), 'config/fragment.yaml');
|
|
235
|
-
|
|
236
|
-
if (!FileGenerator.fileExists(configPath)) {
|
|
237
|
-
CLILogger.error('fragment.yaml not found');
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
try {
|
|
242
|
-
const configContent = FileGenerator.readFile(configPath);
|
|
243
|
-
const config: any = yaml.load(configContent);
|
|
244
|
-
|
|
245
|
-
CLILogger.section('Application');
|
|
246
|
-
CLILogger.table({
|
|
247
|
-
'Name': config.app?.name || 'N/A',
|
|
248
|
-
'Port': config.app?.port || 'N/A',
|
|
249
|
-
'Environment': config.app?.env || 'N/A'
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
CLILogger.section('Database');
|
|
253
|
-
CLILogger.table({
|
|
254
|
-
'Type': config.database?.type || 'N/A',
|
|
255
|
-
'Host': config.database?.host || 'N/A',
|
|
256
|
-
'Database': config.database?.database || 'N/A',
|
|
257
|
-
'Synchronize': config.database?.synchronize ? 'Yes' : 'No'
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
if (config.openai) {
|
|
261
|
-
CLILogger.section('OpenAI');
|
|
262
|
-
CLILogger.table({
|
|
263
|
-
'Model': config.openai.model || 'N/A',
|
|
264
|
-
'API Key': config.openai.apiKey?.includes('${') ? 'From environment' : 'Configured'
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (config.auth) {
|
|
269
|
-
CLILogger.section('Authentication');
|
|
270
|
-
CLILogger.table({
|
|
271
|
-
'Token Expiry': config.auth.tokenExpiry || 'N/A',
|
|
272
|
-
'Session Expiry': config.auth.sessionExpiry || 'N/A'
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
} catch (error: any) {
|
|
277
|
-
CLILogger.error(`Failed to read configuration: ${error.message}`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function controllerTemplate(name: string, route: string): string {
|
|
3
|
-
const className = name.endsWith('Controller') ? name : `${name}Controller`;
|
|
4
|
-
const serviceName = name.replace('Controller', '') + 'Service';
|
|
5
|
-
|
|
6
|
-
return `import { Controller } from '../core/decorators/controller.decorator';
|
|
7
|
-
import { Get, Post, Put, Delete } from '../core/decorators/route.decorator';
|
|
8
|
-
import { Injectable } from '../core/decorators/injectable.decorator';
|
|
9
|
-
import { Autowire } from '../core/decorators/autowire.decorator';
|
|
10
|
-
import { ${serviceName} } from '../services/${name.toLowerCase()}.service';
|
|
11
|
-
import { Request, Response } from 'express';
|
|
12
|
-
|
|
13
|
-
@Controller('${route}')
|
|
14
|
-
@Injectable()
|
|
15
|
-
export class ${className} {
|
|
16
|
-
constructor(
|
|
17
|
-
@Autowire() private ${serviceName.charAt(0).toLowerCase() + serviceName.slice(1)}: ${serviceName}
|
|
18
|
-
) {}
|
|
19
|
-
|
|
20
|
-
@Get('/')
|
|
21
|
-
async findAll(req: Request, res: Response) {
|
|
22
|
-
const items = await this.${serviceName.charAt(0).toLowerCase() + serviceName.slice(1)}.findAll();
|
|
23
|
-
return res.json(items);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Get('/:id')
|
|
27
|
-
async findOne(req: Request, res: Response) {
|
|
28
|
-
const item = await this.${serviceName.charAt(0).toLowerCase() + serviceName.slice(1)}.findById(parseInt(req.params.id));
|
|
29
|
-
return res.json(item);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@Post('/')
|
|
33
|
-
async create(req: Request, res: Response) {
|
|
34
|
-
const item = await this.${serviceName.charAt(0).toLowerCase() + serviceName.slice(1)}.create(req.body);
|
|
35
|
-
return res.status(201).json(item);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@Put('/:id')
|
|
39
|
-
async update(req: Request, res: Response) {
|
|
40
|
-
const item = await this.${serviceName.charAt(0).toLowerCase() + serviceName.slice(1)}.update(parseInt(req.params.id), req.body);
|
|
41
|
-
return res.json(item);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@Delete('/:id')
|
|
45
|
-
async delete(req: Request, res: Response) {
|
|
46
|
-
await this.${serviceName.charAt(0).toLowerCase() + serviceName.slice(1)}.delete(parseInt(req.params.id));
|
|
47
|
-
return res.status(204).send();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
`;
|
|
51
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function entityTemplate(name: string): string {
|
|
3
|
-
const className = name.endsWith('Entity') ? name.replace('Entity', '') : name;
|
|
4
|
-
|
|
5
|
-
return `import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
|
|
6
|
-
|
|
7
|
-
@Entity('${className.toLowerCase()}s')
|
|
8
|
-
export class ${className} {
|
|
9
|
-
@PrimaryGeneratedColumn()
|
|
10
|
-
id!: number;
|
|
11
|
-
|
|
12
|
-
@Column({ length: 255 })
|
|
13
|
-
name!: string;
|
|
14
|
-
|
|
15
|
-
@CreateDateColumn()
|
|
16
|
-
createdAt!: Date;
|
|
17
|
-
|
|
18
|
-
@UpdateDateColumn()
|
|
19
|
-
updatedAt!: Date;
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
}
|