fragment-ts 1.0.0 → 1.0.1
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 +131 -10
- package/dist/cli/commands/build.command.js.map +1 -0
- 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 +201 -128
- package/dist/cli/commands/generate.command.js.map +1 -0
- 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 +268 -305
- package/dist/cli/commands/init.command.js.map +1 -0
- 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 +212 -83
- package/dist/cli/commands/migrate.command.js.map +1 -0
- 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 +179 -21
- package/dist/cli/commands/serve.command.js.map +1 -0
- 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 +76 -25
- package/dist/core/container/di-container.js.map +1 -0
- 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 +13 -9
- package/dist/core/decorators/controller.decorator.js.map +1 -0
- 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 +12 -8
- package/dist/core/decorators/injectable.decorator.js.map +1 -0
- 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 +13 -1
- package/dist/core/decorators/repository.decorator.js.map +1 -0
- 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 +13 -1
- package/dist/core/decorators/service.decorator.js.map +1 -0
- 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 -23
- 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 -0
- package/dist/web/interfaces.js.map +1 -0
- package/examples/ai-assistant/fragment.json +18 -0
- package/examples/ai-assistant/package-lock.json +2921 -0
- package/examples/ai-assistant/package.json +20 -0
- package/examples/ai-assistant/src/controllers/app.controller.ts +9 -0
- package/examples/ai-assistant/src/controllers/chat.controller.ts +69 -0
- package/examples/ai-assistant/src/controllers/conversation.controller.ts +29 -0
- package/examples/ai-assistant/src/controllers/message.controller.ts +29 -0
- package/examples/ai-assistant/src/controllers/search.controller.ts +16 -0
- package/examples/ai-assistant/src/dto/create-conversation.dto.ts +6 -0
- package/examples/ai-assistant/src/dto/create-message.dto.ts +6 -0
- package/examples/ai-assistant/src/entities/conversation.entity.ts +23 -0
- package/examples/ai-assistant/src/entities/message.entity.ts +27 -0
- package/examples/ai-assistant/src/entities/user.entity.ts +16 -0
- package/examples/ai-assistant/src/main.ts +15 -0
- package/examples/ai-assistant/src/migrations/1767738396740-CreateConversationTables.ts +37 -0
- package/examples/ai-assistant/src/repositories/conversation.repository.ts +32 -0
- package/examples/ai-assistant/src/repositories/message.repository.ts +30 -0
- package/examples/ai-assistant/src/services/ai.service.ts +41 -0
- package/examples/ai-assistant/src/services/app.service.ts +8 -0
- package/examples/ai-assistant/src/services/conversation.service.ts +75 -0
- package/examples/ai-assistant/src/services/message.service.ts +27 -0
- package/examples/ai-assistant/tsconfig.json +23 -0
- package/examples/blog-api/fragment.json +18 -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 +27 -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 +56 -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 -5
- 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 -90
- package/dist/auth/auth.controller.d.ts +0 -10
- package/dist/auth/auth.controller.js +0 -87
- package/dist/auth/auth.middleware.d.ts +0 -2
- package/dist/auth/auth.middleware.js +0 -24
- package/dist/auth/auth.service.d.ts +0 -20
- package/dist/auth/auth.service.js +0 -143
- package/dist/auth/dto/login.dto.d.ts +0 -9
- package/dist/cli/cli.d.ts +0 -12
- package/dist/cli/cli.js +0 -186
- package/dist/cli/commands/config.command.d.ts +0 -6
- package/dist/cli/commands/config.command.js +0 -284
- package/dist/cli/templates/controller.template.d.ts +0 -1
- package/dist/cli/templates/controller.template.js +0 -52
- package/dist/cli/templates/entity.template.d.ts +0 -1
- package/dist/cli/templates/entity.template.js +0 -23
- package/dist/cli/templates/repository.template.d.ts +0 -1
- package/dist/cli/templates/repository.template.js +0 -43
- package/dist/cli/templates/service.template.d.ts +0 -1
- package/dist/cli/templates/service.template.js +0 -43
- package/dist/cli/utils/file-generator.d.ts +0 -9
- package/dist/cli/utils/logger.d.ts +0 -14
- package/dist/cli/utils/logger.js +0 -49
- package/dist/controllers/health.controller.d.ts +0 -13
- package/dist/controllers/health.controller.js +0 -50
- package/dist/core/config/config-loader.d.ts +0 -31
- package/dist/core/config/config-loader.js +0 -98
- package/dist/core/decorators/auth-guard.decorator.d.ts +0 -3
- package/dist/core/decorators/auth-guard.decorator.js +0 -18
- package/dist/core/decorators/autowire.decorator.d.ts +0 -3
- package/dist/core/decorators/autowire.decorator.js +0 -17
- package/dist/core/decorators/middleware.decorator.d.ts +0 -3
- package/dist/core/decorators/middleware.decorator.js +0 -20
- package/dist/core/decorators/route.decorator.d.ts +0 -14
- package/dist/core/decorators/route.decorator.js +0 -32
- package/dist/core/openai/openai-client.d.ts +0 -12
- package/dist/core/openai/openai-client.js +0 -93
- package/dist/database/data-source.d.ts +0 -4
- package/dist/database/data-source.js +0 -26
- package/dist/entities/session.entity.d.ts +0 -9
- package/dist/entities/session.entity.js +0 -45
- package/dist/entities/user.entity.d.ts +0 -10
- package/dist/entities/user.entity.js +0 -48
- package/dist/middlewares/logging.middleware.d.ts +0 -2
- package/dist/middlewares/logging.middleware.js +0 -28
- package/dist/repositories/session.repository.d.ts +0 -9
- package/dist/repositories/session.repository.js +0 -50
- package/dist/repositories/user.repository.d.ts +0 -10
- package/dist/repositories/user.repository.js +0 -43
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -30
- package/dist/services/health.service.d.ts +0 -13
- package/dist/services/health.service.js +0 -44
- 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
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OpenAIClient } from '../core/openai/openai-client';
|
|
2
|
-
export declare class HealthService {
|
|
3
|
-
private openAIClient;
|
|
4
|
-
constructor(openAIClient: OpenAIClient);
|
|
5
|
-
getStatus(): Promise<{
|
|
6
|
-
status: string;
|
|
7
|
-
timestamp: string;
|
|
8
|
-
database: string;
|
|
9
|
-
}>;
|
|
10
|
-
generateHealthTip(): Promise<{
|
|
11
|
-
tip: string;
|
|
12
|
-
}>;
|
|
13
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.HealthService = void 0;
|
|
16
|
-
const service_decorator_1 = require("../core/decorators/service.decorator");
|
|
17
|
-
const autowire_decorator_1 = require("../core/decorators/autowire.decorator");
|
|
18
|
-
const openai_client_1 = require("../core/openai/openai-client");
|
|
19
|
-
let HealthService = class HealthService {
|
|
20
|
-
constructor(openAIClient) {
|
|
21
|
-
this.openAIClient = openAIClient;
|
|
22
|
-
}
|
|
23
|
-
async getStatus() {
|
|
24
|
-
return {
|
|
25
|
-
status: 'ok',
|
|
26
|
-
timestamp: new Date().toISOString(),
|
|
27
|
-
database: 'connected'
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
async generateHealthTip() {
|
|
31
|
-
const prompt = 'Give me a short health tip in one sentence.';
|
|
32
|
-
const tip = await this.openAIClient.complete(prompt, {
|
|
33
|
-
maxTokens: 50,
|
|
34
|
-
temperature: 0.9
|
|
35
|
-
});
|
|
36
|
-
return { tip };
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
exports.HealthService = HealthService;
|
|
40
|
-
exports.HealthService = HealthService = __decorate([
|
|
41
|
-
(0, service_decorator_1.Service)(),
|
|
42
|
-
__param(0, (0, autowire_decorator_1.Autowire)()),
|
|
43
|
-
__metadata("design:paramtypes", [openai_client_1.OpenAIClient])
|
|
44
|
-
], HealthService);
|
package/readme.md
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
#### **Project Initialization**
|
|
2
|
-
```bash
|
|
3
|
-
frg init my-app # Create new project with wizard
|
|
4
|
-
frg init # Interactive mode
|
|
5
|
-
```
|
|
6
|
-
Features:
|
|
7
|
-
- Database selection (PostgreSQL/MySQL/SQLite/MongoDB)
|
|
8
|
-
- Optional OpenAI integration
|
|
9
|
-
- Optional authentication system
|
|
10
|
-
- Package manager choice (npm/yarn/pnpm)
|
|
11
|
-
- Automatic dependency installation
|
|
12
|
-
|
|
13
|
-
#### **Code Generation**
|
|
14
|
-
```bash
|
|
15
|
-
frg generate controller User # Generate controller
|
|
16
|
-
frg g c User # Short alias
|
|
17
|
-
|
|
18
|
-
frg generate service User # Generate service
|
|
19
|
-
frg g s User # Short alias
|
|
20
|
-
|
|
21
|
-
frg generate repository User # Generate repository
|
|
22
|
-
frg g r User # Short alias
|
|
23
|
-
|
|
24
|
-
frg generate entity User # Generate entity
|
|
25
|
-
frg g e User # Short alias
|
|
26
|
-
|
|
27
|
-
frg generate resource Product # Generate everything at once!
|
|
28
|
-
frg g res Product # Controller + Service + Repository + Entity
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
#### **Configuration Management**
|
|
32
|
-
```bash
|
|
33
|
-
frg config ai # Configure OpenAI (interactive)
|
|
34
|
-
frg config db # Configure database (interactive)
|
|
35
|
-
frg config show # Display current configuration
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
#### **Development**
|
|
39
|
-
```bash
|
|
40
|
-
frg serve # Start dev server with hot-reload
|
|
41
|
-
frg dev # Alias
|
|
42
|
-
frg serve --port 8080 # Custom port
|
|
43
|
-
frg serve --no-watch # Disable auto-restart
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
#### **Production**
|
|
47
|
-
```bash
|
|
48
|
-
frg build # Build for production
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
#### **Database Migrations**
|
|
52
|
-
```bash
|
|
53
|
-
frg migrate run # Run pending migrations
|
|
54
|
-
frg migrate generate # Create new migration
|
|
55
|
-
frg migrate revert # Revert last migration
|
|
56
|
-
frg migrate show # Migration status
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### **🎨 CLI Features:**
|
|
60
|
-
|
|
61
|
-
1. **Beautiful ASCII Art** - Fragment logo on startup
|
|
62
|
-
2. **Color-Coded Output** - Success (green), errors (red), info (blue)
|
|
63
|
-
3. **Progress Spinners** - Visual feedback for long operations
|
|
64
|
-
4. **Interactive Prompts** - inquirer.js powered wizards
|
|
65
|
-
5. **Validation** - Input validation with helpful messages
|
|
66
|
-
6. **Smart Templates** - Auto-generates boilerplate code
|
|
67
|
-
7. **Configuration Boxes** - Formatted output tables
|
|
68
|
-
8. **Error Handling** - Graceful failures with helpful messages
|
|
69
|
-
|
|
70
|
-
### **📦 Template System:**
|
|
71
|
-
|
|
72
|
-
All generators use smart templates that:
|
|
73
|
-
- Auto-inject dependencies via `@Autowire()`
|
|
74
|
-
- Follow naming conventions
|
|
75
|
-
- Include CRUD operations
|
|
76
|
-
- Are fully typed with TypeScript
|
|
77
|
-
- Follow Fragment patterns
|
|
78
|
-
|
|
79
|
-
### **🚀 Example Workflow:**
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
# Initialize new project
|
|
83
|
-
frg init my-blog-api
|
|
84
|
-
✓ Select PostgreSQL
|
|
85
|
-
✓ Enable OpenAI
|
|
86
|
-
✓ Include auth system
|
|
87
|
-
|
|
88
|
-
# Configure OpenAI
|
|
89
|
-
frg config ai
|
|
90
|
-
✓ Enter API key
|
|
91
|
-
✓ Select model
|
|
92
|
-
|
|
93
|
-
# Generate complete resource
|
|
94
|
-
frg generate resource Post
|
|
95
|
-
✓ Creates controller, service, repository, entity
|
|
96
|
-
✓ Sets up routes at /api/posts
|
|
97
|
-
|
|
98
|
-
# Start server
|
|
99
|
-
frg serve
|
|
100
|
-
🔷 Fragment Framework Started
|
|
101
|
-
📍 Routes registered
|
|
102
|
-
✓ Ready on port 3000
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### **Project Structure:**
|
|
106
|
-
```
|
|
107
|
-
my-fragment-app/
|
|
108
|
-
├── bin/frg.ts # CLI entry point
|
|
109
|
-
├── src/
|
|
110
|
-
│ ├── cli/ # CLI commands & utils
|
|
111
|
-
│ ├── core/ # Framework core
|
|
112
|
-
│ ├── controllers/ # HTTP controllers
|
|
113
|
-
│ ├── services/ # Business logic
|
|
114
|
-
│ ├── repositories/ # Data access
|
|
115
|
-
│ ├── entities/ # TypeORM entities
|
|
116
|
-
│ └── app.ts # FragmentApplication
|
|
117
|
-
├── config/
|
|
118
|
-
│ └── fragment.yaml # Configuration
|
|
119
|
-
└── package.json
|
|
120
|
-
```
|
package/src/app.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import express, { Express, Request, Response, NextFunction } from 'express';
|
|
3
|
-
import { DIContainer } from './core/container/di-container';
|
|
4
|
-
import { ConfigLoader } from './core/config/config-loader';
|
|
5
|
-
import { initializeDataSource, AppDataSource } from './database/data-source';
|
|
6
|
-
import { loggingMiddleware } from './middlewares/logging.middleware';
|
|
7
|
-
import { authMiddleware } from './auth/auth.middleware';
|
|
8
|
-
import {
|
|
9
|
-
CONTROLLER_METADATA,
|
|
10
|
-
CONTROLLER_PATH
|
|
11
|
-
} from './core/decorators/controller.decorator';
|
|
12
|
-
import {
|
|
13
|
-
ROUTE_METADATA
|
|
14
|
-
} from './core/decorators/route.decorator';
|
|
15
|
-
import {
|
|
16
|
-
AUTH_GUARD_METADATA
|
|
17
|
-
} from './core/decorators/auth-guard.decorator';
|
|
18
|
-
import {
|
|
19
|
-
MIDDLEWARE_METADATA
|
|
20
|
-
} from './core/decorators/middleware.decorator';
|
|
21
|
-
|
|
22
|
-
// Import all controllers, services, repositories
|
|
23
|
-
import './controllers/health.controller';
|
|
24
|
-
import './auth/auth.controller';
|
|
25
|
-
import './services/health.service';
|
|
26
|
-
import './repositories/user.repository';
|
|
27
|
-
import './repositories/session.repository';
|
|
28
|
-
import './auth/auth.service';
|
|
29
|
-
import './core/openai/openai-client';
|
|
30
|
-
|
|
31
|
-
export class FragmentApplication {
|
|
32
|
-
private app: Express;
|
|
33
|
-
|
|
34
|
-
constructor() {
|
|
35
|
-
this.app = express();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async initialize(): Promise<Express> {
|
|
39
|
-
// Load configuration
|
|
40
|
-
ConfigLoader.load(true);
|
|
41
|
-
|
|
42
|
-
// Initialize database
|
|
43
|
-
const dataSource = initializeDataSource();
|
|
44
|
-
await dataSource.initialize();
|
|
45
|
-
console.log('✅ Database connected');
|
|
46
|
-
|
|
47
|
-
// Middleware
|
|
48
|
-
this.app.use(express.json());
|
|
49
|
-
this.app.use(express.urlencoded({ extended: true }));
|
|
50
|
-
this.app.use(loggingMiddleware);
|
|
51
|
-
|
|
52
|
-
// Register all controllers
|
|
53
|
-
this.registerControllers();
|
|
54
|
-
|
|
55
|
-
// Error handling
|
|
56
|
-
this.app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
|
|
57
|
-
console.error(err.stack);
|
|
58
|
-
res.status(500).json({ error: 'Internal server error' });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return this.app;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private registerControllers(): void {
|
|
65
|
-
const registeredClasses = DIContainer.getRegisteredClasses();
|
|
66
|
-
|
|
67
|
-
registeredClasses.forEach((controllerClass) => {
|
|
68
|
-
const isController = Reflect.getMetadata(CONTROLLER_METADATA, controllerClass);
|
|
69
|
-
if (!isController) return;
|
|
70
|
-
|
|
71
|
-
const basePath = Reflect.getMetadata(CONTROLLER_PATH, controllerClass) || '';
|
|
72
|
-
const routes = Reflect.getMetadata(ROUTE_METADATA, controllerClass) || [];
|
|
73
|
-
const classMiddlewares = Reflect.getMetadata(MIDDLEWARE_METADATA, controllerClass) || [];
|
|
74
|
-
const classAuthGuard = Reflect.getMetadata(AUTH_GUARD_METADATA, controllerClass);
|
|
75
|
-
|
|
76
|
-
const controllerInstance = DIContainer.resolve(controllerClass) as any;
|
|
77
|
-
|
|
78
|
-
routes.forEach((route: any) => {
|
|
79
|
-
const fullPath = basePath + route.path;
|
|
80
|
-
const handler = controllerInstance[route.handlerName].bind(controllerInstance);
|
|
81
|
-
|
|
82
|
-
const middlewares: any[] = [...classMiddlewares];
|
|
83
|
-
|
|
84
|
-
const methodAuthGuard = Reflect.getMetadata(
|
|
85
|
-
AUTH_GUARD_METADATA,
|
|
86
|
-
controllerClass,
|
|
87
|
-
route.handlerName
|
|
88
|
-
);
|
|
89
|
-
if (classAuthGuard || methodAuthGuard) {
|
|
90
|
-
middlewares.push(authMiddleware);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const methodMiddlewares = Reflect.getMetadata(
|
|
94
|
-
MIDDLEWARE_METADATA,
|
|
95
|
-
controllerClass,
|
|
96
|
-
route.handlerName
|
|
97
|
-
) || [];
|
|
98
|
-
middlewares.push(...methodMiddlewares);
|
|
99
|
-
|
|
100
|
-
const asyncHandler = async (req: Request, res: Response, next: NextFunction) => {
|
|
101
|
-
try {
|
|
102
|
-
const result = await handler(req, res, next);
|
|
103
|
-
if (result && !res.headersSent) {
|
|
104
|
-
res.json(result);
|
|
105
|
-
}
|
|
106
|
-
} catch (error) {
|
|
107
|
-
next(error);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
(this.app as any)[route.method](fullPath, ...middlewares, asyncHandler);
|
|
112
|
-
|
|
113
|
-
console.log(`📍 ${route.method.toUpperCase().padEnd(6)} ${fullPath}`);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
getExpressApp(): Express {
|
|
119
|
-
return this.app;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Controller } from '../core/decorators/controller.decorator';
|
|
3
|
-
import { Post, Get } from '../core/decorators/route.decorator';
|
|
4
|
-
import { Injectable } from '../core/decorators/injectable.decorator';
|
|
5
|
-
import { Autowire } from '../core/decorators/autowire.decorator';
|
|
6
|
-
import { AuthGuard } from '../core/decorators/auth-guard.decorator';
|
|
7
|
-
import { AuthService } from './auth.service';
|
|
8
|
-
import { Request, Response } from 'express';
|
|
9
|
-
|
|
10
|
-
@Controller('/api/auth')
|
|
11
|
-
@Injectable()
|
|
12
|
-
export class AuthController {
|
|
13
|
-
constructor(
|
|
14
|
-
@Autowire() private authService: AuthService
|
|
15
|
-
) {}
|
|
16
|
-
|
|
17
|
-
@Post('/register')
|
|
18
|
-
async register(req: Request, res: Response) {
|
|
19
|
-
try {
|
|
20
|
-
const result = await this.authService.register(req.body);
|
|
21
|
-
return res.json(result);
|
|
22
|
-
} catch (error: any) {
|
|
23
|
-
return res.status(400).json({ error: error.message });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@Post('/login')
|
|
28
|
-
async login(req: Request, res: Response) {
|
|
29
|
-
try {
|
|
30
|
-
const result = await this.authService.login(req.body);
|
|
31
|
-
return res.json(result);
|
|
32
|
-
} catch (error: any) {
|
|
33
|
-
return res.status(401).json({ error: error.message });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@Post('/logout')
|
|
38
|
-
@AuthGuard()
|
|
39
|
-
async logout(req: Request, res: Response) {
|
|
40
|
-
const token = req.headers.authorization?.replace('Bearer ', '');
|
|
41
|
-
if (token) {
|
|
42
|
-
await this.authService.logout(token);
|
|
43
|
-
}
|
|
44
|
-
return res.json({ message: 'Logged out successfully' });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@Get('/me')
|
|
48
|
-
@AuthGuard()
|
|
49
|
-
async getCurrentUser(req: Request, res: Response) {
|
|
50
|
-
return res.json({ user: (req as any).user });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Request, Response, NextFunction } from 'express';
|
|
3
|
-
import { DIContainer } from '../core/container/di-container';
|
|
4
|
-
import { AuthService } from './auth.service';
|
|
5
|
-
|
|
6
|
-
export async function authMiddleware(req: Request, res: Response, next: NextFunction) {
|
|
7
|
-
const authHeader = req.headers.authorization;
|
|
8
|
-
|
|
9
|
-
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
10
|
-
return res.status(401).json({ error: 'Unauthorized' });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const token = authHeader.replace('Bearer ', '');
|
|
14
|
-
const authService = DIContainer.resolve<AuthService>(AuthService);
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const user = await authService.validateToken(token);
|
|
18
|
-
if (!user) {
|
|
19
|
-
return res.status(401).json({ error: 'Invalid token' });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
(req as any).user = user;
|
|
23
|
-
next();
|
|
24
|
-
} catch (error) {
|
|
25
|
-
return res.status(401).json({ error: 'Unauthorized' });
|
|
26
|
-
}
|
|
27
|
-
}
|
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
|
-
}
|