fragment-ts 1.0.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/.env.example +0 -0
- package/base.ts +1810 -0
- package/base2.ts +968 -0
- package/bin/frg.ts +5 -0
- package/config/fragment.lock.yaml +0 -0
- package/config/fragment.yaml +0 -0
- package/dist/app.d.ts +15 -0
- package/dist/app.js +90 -0
- package/dist/auth/auth.controller.d.ts +10 -0
- package/dist/auth/auth.controller.js +87 -0
- package/dist/auth/auth.middleware.d.ts +2 -0
- package/dist/auth/auth.middleware.js +24 -0
- package/dist/auth/auth.service.d.ts +20 -0
- package/dist/auth/auth.service.js +143 -0
- package/dist/auth/dto/login.dto.d.ts +9 -0
- package/dist/auth/dto/login.dto.js +2 -0
- package/dist/cli/cli.d.ts +12 -0
- package/dist/cli/cli.js +186 -0
- package/dist/cli/commands/build.command.d.ts +3 -0
- package/dist/cli/commands/build.command.js +23 -0
- package/dist/cli/commands/config.command.d.ts +6 -0
- package/dist/cli/commands/config.command.js +284 -0
- package/dist/cli/commands/generate.command.d.ts +8 -0
- package/dist/cli/commands/generate.command.js +180 -0
- package/dist/cli/commands/init.command.d.ts +7 -0
- package/dist/cli/commands/init.command.js +380 -0
- package/dist/cli/commands/migrate.command.d.ts +7 -0
- package/dist/cli/commands/migrate.command.js +116 -0
- package/dist/cli/commands/serve.command.d.ts +6 -0
- package/dist/cli/commands/serve.command.js +31 -0
- package/dist/cli/templates/controller.template.d.ts +1 -0
- package/dist/cli/templates/controller.template.js +52 -0
- package/dist/cli/templates/entity.template.d.ts +1 -0
- package/dist/cli/templates/entity.template.js +23 -0
- package/dist/cli/templates/repository.template.d.ts +1 -0
- package/dist/cli/templates/repository.template.js +43 -0
- package/dist/cli/templates/service.template.d.ts +1 -0
- package/dist/cli/templates/service.template.js +43 -0
- package/dist/cli/utils/file-generator.d.ts +9 -0
- package/dist/cli/utils/file-generator.js +67 -0
- package/dist/cli/utils/logger.d.ts +14 -0
- package/dist/cli/utils/logger.js +49 -0
- package/dist/controllers/health.controller.d.ts +13 -0
- package/dist/controllers/health.controller.js +50 -0
- package/dist/core/config/config-loader.d.ts +31 -0
- package/dist/core/config/config-loader.js +98 -0
- package/dist/core/container/di-container.d.ts +9 -0
- package/dist/core/container/di-container.js +37 -0
- package/dist/core/decorators/auth-guard.decorator.d.ts +3 -0
- package/dist/core/decorators/auth-guard.decorator.js +18 -0
- package/dist/core/decorators/autowire.decorator.d.ts +3 -0
- package/dist/core/decorators/autowire.decorator.js +17 -0
- package/dist/core/decorators/controller.decorator.d.ts +4 -0
- package/dist/core/decorators/controller.decorator.js +16 -0
- package/dist/core/decorators/injectable.decorator.d.ts +3 -0
- package/dist/core/decorators/injectable.decorator.js +14 -0
- package/dist/core/decorators/middleware.decorator.d.ts +3 -0
- package/dist/core/decorators/middleware.decorator.js +20 -0
- package/dist/core/decorators/repository.decorator.d.ts +1 -0
- package/dist/core/decorators/repository.decorator.js +7 -0
- package/dist/core/decorators/route.decorator.d.ts +14 -0
- package/dist/core/decorators/route.decorator.js +32 -0
- package/dist/core/decorators/service.decorator.d.ts +1 -0
- package/dist/core/decorators/service.decorator.js +7 -0
- package/dist/core/openai/openai-client.d.ts +12 -0
- package/dist/core/openai/openai-client.js +93 -0
- package/dist/database/data-source.d.ts +4 -0
- package/dist/database/data-source.js +26 -0
- package/dist/entities/session.entity.d.ts +9 -0
- package/dist/entities/session.entity.js +45 -0
- package/dist/entities/user.entity.d.ts +10 -0
- package/dist/entities/user.entity.js +48 -0
- package/dist/middlewares/logging.middleware.d.ts +2 -0
- package/dist/middlewares/logging.middleware.js +28 -0
- package/dist/repositories/session.repository.d.ts +9 -0
- package/dist/repositories/session.repository.js +50 -0
- package/dist/repositories/user.repository.d.ts +10 -0
- package/dist/repositories/user.repository.js +43 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +30 -0
- package/dist/services/health.service.d.ts +13 -0
- package/dist/services/health.service.js +44 -0
- package/package.json +46 -0
- package/readme.md +120 -0
- package/src/app.ts +121 -0
- package/src/auth/auth.controller.ts +52 -0
- package/src/auth/auth.middleware.ts +27 -0
- package/src/auth/auth.service.ts +110 -0
- package/src/auth/dto/login.dto.ts +11 -0
- package/src/cli/cli.ts +212 -0
- package/src/cli/commands/build.command.ts +24 -0
- package/src/cli/commands/config.command.ts +280 -0
- package/src/cli/commands/generate.command.ts +170 -0
- package/src/cli/commands/init.command.ts +395 -0
- package/src/cli/commands/migrate.command.ts +118 -0
- package/src/cli/commands/serve.command.ts +37 -0
- package/src/cli/templates/controller.template.ts +51 -0
- package/src/cli/templates/entity.template.ts +22 -0
- package/src/cli/templates/repository.template.ts +42 -0
- package/src/cli/templates/service.template.ts +42 -0
- package/src/cli/utils/file-generator.ts +37 -0
- package/src/cli/utils/logger.ts +52 -0
- package/src/controllers/health.controller.ts +24 -0
- package/src/core/config/config-loader.ts +98 -0
- package/src/core/container/di-container.ts +43 -0
- package/src/core/decorators/auth-guard.decorator.ts +15 -0
- package/src/core/decorators/autowire.decorator.ts +18 -0
- package/src/core/decorators/controller.decorator.ts +15 -0
- package/src/core/decorators/injectable.decorator.ts +13 -0
- package/src/core/decorators/middleware.decorator.ts +18 -0
- package/src/core/decorators/repository.decorator.ts +6 -0
- package/src/core/decorators/route.decorator.ts +33 -0
- package/src/core/decorators/service.decorator.ts +6 -0
- package/src/core/openai/openai-client.ts +99 -0
- package/src/database/data-source.ts +29 -0
- package/src/entities/session.entity.ts +25 -0
- package/src/entities/user.entity.ts +27 -0
- package/src/middlewares/logging.middleware.ts +28 -0
- package/src/repositories/session.repository.ts +42 -0
- package/src/repositories/user.repository.ts +37 -0
- package/src/server.ts +32 -0
- package/src/services/health.service.ts +29 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serviceTemplate = serviceTemplate;
|
|
4
|
+
function serviceTemplate(name) {
|
|
5
|
+
const className = name.endsWith('Service') ? name : `${name}Service`;
|
|
6
|
+
const repoName = name.replace('Service', '') + 'Repository';
|
|
7
|
+
return `import { Service } from '../core/decorators/service.decorator';
|
|
8
|
+
import { Autowire } from '../core/decorators/autowire.decorator';
|
|
9
|
+
import { ${repoName} } from '../repositories/${name.toLowerCase()}.repository';
|
|
10
|
+
|
|
11
|
+
@Service()
|
|
12
|
+
export class ${className} {
|
|
13
|
+
constructor(
|
|
14
|
+
@Autowire() private ${repoName.charAt(0).toLowerCase() + repoName.slice(1)}: ${repoName}
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
async findAll() {
|
|
18
|
+
// Implement business logic
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async findById(id: number) {
|
|
23
|
+
// Implement business logic
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async create(data: any) {
|
|
28
|
+
// Implement business logic
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async update(id: number, data: any) {
|
|
33
|
+
// Implement business logic
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async delete(id: number) {
|
|
38
|
+
// Implement business logic
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class FileGenerator {
|
|
2
|
+
static createDirectory(dirPath: string): void;
|
|
3
|
+
static writeFile(filePath: string, content: string): void;
|
|
4
|
+
static fileExists(filePath: string): boolean;
|
|
5
|
+
static readFile(filePath: string): string;
|
|
6
|
+
static toCamelCase(str: string): string;
|
|
7
|
+
static toPascalCase(str: string): string;
|
|
8
|
+
static toKebabCase(str: string): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FileGenerator = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
class FileGenerator {
|
|
40
|
+
static createDirectory(dirPath) {
|
|
41
|
+
if (!fs.existsSync(dirPath)) {
|
|
42
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
static writeFile(filePath, content) {
|
|
46
|
+
const dir = path.dirname(filePath);
|
|
47
|
+
this.createDirectory(dir);
|
|
48
|
+
fs.writeFileSync(filePath, content, 'utf-8');
|
|
49
|
+
}
|
|
50
|
+
static fileExists(filePath) {
|
|
51
|
+
return fs.existsSync(filePath);
|
|
52
|
+
}
|
|
53
|
+
static readFile(filePath) {
|
|
54
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
55
|
+
}
|
|
56
|
+
static toCamelCase(str) {
|
|
57
|
+
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
58
|
+
}
|
|
59
|
+
static toPascalCase(str) {
|
|
60
|
+
const camel = this.toCamelCase(str);
|
|
61
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
62
|
+
}
|
|
63
|
+
static toKebabCase(str) {
|
|
64
|
+
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.FileGenerator = FileGenerator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Ora } from 'ora';
|
|
2
|
+
export declare class CLILogger {
|
|
3
|
+
static success(message: string): void;
|
|
4
|
+
static error(message: string): void;
|
|
5
|
+
static info(message: string): void;
|
|
6
|
+
static warning(message: string): void;
|
|
7
|
+
static title(message: string): void;
|
|
8
|
+
static section(message: string): void;
|
|
9
|
+
static spinner(text: string): Ora;
|
|
10
|
+
static box(title: string, content: string[]): void;
|
|
11
|
+
static table(data: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
}): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CLILogger = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
class CLILogger {
|
|
10
|
+
static success(message) {
|
|
11
|
+
console.log(chalk_1.default.green('✓'), message);
|
|
12
|
+
}
|
|
13
|
+
static error(message) {
|
|
14
|
+
console.log(chalk_1.default.red('✗'), message);
|
|
15
|
+
}
|
|
16
|
+
static info(message) {
|
|
17
|
+
console.log(chalk_1.default.blue('ℹ'), message);
|
|
18
|
+
}
|
|
19
|
+
static warning(message) {
|
|
20
|
+
console.log(chalk_1.default.yellow('⚠'), message);
|
|
21
|
+
}
|
|
22
|
+
static title(message) {
|
|
23
|
+
console.log(chalk_1.default.bold.cyan(`\n${message}\n`));
|
|
24
|
+
}
|
|
25
|
+
static section(message) {
|
|
26
|
+
console.log(chalk_1.default.bold(`\n${message}`));
|
|
27
|
+
}
|
|
28
|
+
static spinner(text) {
|
|
29
|
+
return (0, ora_1.default)(text).start();
|
|
30
|
+
}
|
|
31
|
+
static box(title, content) {
|
|
32
|
+
const maxLength = Math.max(title.length, ...content.map(c => c.length)) + 4;
|
|
33
|
+
const border = '═'.repeat(maxLength);
|
|
34
|
+
console.log(chalk_1.default.cyan(`╔${border}╗`));
|
|
35
|
+
console.log(chalk_1.default.cyan('║') + chalk_1.default.bold(` ${title.padEnd(maxLength)} `) + chalk_1.default.cyan('║'));
|
|
36
|
+
console.log(chalk_1.default.cyan(`╠${border}╣`));
|
|
37
|
+
content.forEach(line => {
|
|
38
|
+
console.log(chalk_1.default.cyan('║') + ` ${line.padEnd(maxLength)} ` + chalk_1.default.cyan('║'));
|
|
39
|
+
});
|
|
40
|
+
console.log(chalk_1.default.cyan(`╚${border}╝`));
|
|
41
|
+
}
|
|
42
|
+
static table(data) {
|
|
43
|
+
const maxKeyLength = Math.max(...Object.keys(data).map(k => k.length));
|
|
44
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
45
|
+
console.log(` ${chalk_1.default.cyan(key.padEnd(maxKeyLength))} : ${value}`);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.CLILogger = CLILogger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HealthService } from '../services/health.service';
|
|
2
|
+
export declare class HealthController {
|
|
3
|
+
private healthService;
|
|
4
|
+
constructor(healthService: HealthService);
|
|
5
|
+
getStatus(): Promise<{
|
|
6
|
+
status: string;
|
|
7
|
+
timestamp: string;
|
|
8
|
+
database: string;
|
|
9
|
+
}>;
|
|
10
|
+
getHealthTip(): Promise<{
|
|
11
|
+
tip: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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.HealthController = void 0;
|
|
16
|
+
const controller_decorator_1 = require("../core/decorators/controller.decorator");
|
|
17
|
+
const route_decorator_1 = require("../core/decorators/route.decorator");
|
|
18
|
+
const injectable_decorator_1 = require("../core/decorators/injectable.decorator");
|
|
19
|
+
const autowire_decorator_1 = require("../core/decorators/autowire.decorator");
|
|
20
|
+
const health_service_1 = require("../services/health.service");
|
|
21
|
+
let HealthController = class HealthController {
|
|
22
|
+
constructor(healthService) {
|
|
23
|
+
this.healthService = healthService;
|
|
24
|
+
}
|
|
25
|
+
async getStatus() {
|
|
26
|
+
return await this.healthService.getStatus();
|
|
27
|
+
}
|
|
28
|
+
async getHealthTip() {
|
|
29
|
+
return await this.healthService.generateHealthTip();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.HealthController = HealthController;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, route_decorator_1.Get)('/'),
|
|
35
|
+
__metadata("design:type", Function),
|
|
36
|
+
__metadata("design:paramtypes", []),
|
|
37
|
+
__metadata("design:returntype", Promise)
|
|
38
|
+
], HealthController.prototype, "getStatus", null);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, route_decorator_1.Get)('/tip'),
|
|
41
|
+
__metadata("design:type", Function),
|
|
42
|
+
__metadata("design:paramtypes", []),
|
|
43
|
+
__metadata("design:returntype", Promise)
|
|
44
|
+
], HealthController.prototype, "getHealthTip", null);
|
|
45
|
+
exports.HealthController = HealthController = __decorate([
|
|
46
|
+
(0, controller_decorator_1.Controller)('/api/health'),
|
|
47
|
+
(0, injectable_decorator_1.Injectable)(),
|
|
48
|
+
__param(0, (0, autowire_decorator_1.Autowire)()),
|
|
49
|
+
__metadata("design:paramtypes", [health_service_1.HealthService])
|
|
50
|
+
], HealthController);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface AppConfig {
|
|
2
|
+
app: {
|
|
3
|
+
name: string;
|
|
4
|
+
port: number;
|
|
5
|
+
env: string;
|
|
6
|
+
};
|
|
7
|
+
database: {
|
|
8
|
+
type: string;
|
|
9
|
+
host: string;
|
|
10
|
+
port: number;
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
database: string;
|
|
14
|
+
synchronize: boolean;
|
|
15
|
+
logging: boolean;
|
|
16
|
+
};
|
|
17
|
+
openai: {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
model: string;
|
|
20
|
+
};
|
|
21
|
+
auth: {
|
|
22
|
+
tokenExpiry: string;
|
|
23
|
+
sessionExpiry: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare class ConfigLoader {
|
|
27
|
+
private static config;
|
|
28
|
+
static load(useYaml?: boolean): AppConfig;
|
|
29
|
+
private static mergeEnvVariables;
|
|
30
|
+
static get(): AppConfig;
|
|
31
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ConfigLoader = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const yaml = __importStar(require("js-yaml"));
|
|
40
|
+
class ConfigLoader {
|
|
41
|
+
static load(useYaml = true) {
|
|
42
|
+
if (this.config) {
|
|
43
|
+
return this.config;
|
|
44
|
+
}
|
|
45
|
+
const configDir = path.join(process.cwd(), 'config');
|
|
46
|
+
let configPath;
|
|
47
|
+
if (useYaml) {
|
|
48
|
+
// Try .lock.yaml first, then .yaml
|
|
49
|
+
const lockPath = path.join(configDir, 'app.lock.yaml');
|
|
50
|
+
const yamlPath = path.join(configDir, 'app.yaml');
|
|
51
|
+
configPath = fs.existsSync(lockPath) ? lockPath : yamlPath;
|
|
52
|
+
if (!fs.existsSync(configPath)) {
|
|
53
|
+
throw new Error('Configuration file not found');
|
|
54
|
+
}
|
|
55
|
+
const fileContent = fs.readFileSync(configPath, 'utf8');
|
|
56
|
+
this.config = yaml.load(fileContent);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// JSON fallback
|
|
60
|
+
configPath = path.join(configDir, 'app.json');
|
|
61
|
+
const fileContent = fs.readFileSync(configPath, 'utf8');
|
|
62
|
+
this.config = JSON.parse(fileContent);
|
|
63
|
+
}
|
|
64
|
+
// Override with environment variables
|
|
65
|
+
this.config = this.mergeEnvVariables(this.config);
|
|
66
|
+
return this.config;
|
|
67
|
+
}
|
|
68
|
+
static mergeEnvVariables(config) {
|
|
69
|
+
return {
|
|
70
|
+
...config,
|
|
71
|
+
app: {
|
|
72
|
+
...config.app,
|
|
73
|
+
port: process.env.PORT ? parseInt(process.env.PORT) : config.app.port,
|
|
74
|
+
env: process.env.NODE_ENV || config.app.env
|
|
75
|
+
},
|
|
76
|
+
database: {
|
|
77
|
+
...config.database,
|
|
78
|
+
host: process.env.DB_HOST || config.database.host,
|
|
79
|
+
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : config.database.port,
|
|
80
|
+
username: process.env.DB_USERNAME || config.database.username,
|
|
81
|
+
password: process.env.DB_PASSWORD || config.database.password,
|
|
82
|
+
database: process.env.DB_DATABASE || config.database.database
|
|
83
|
+
},
|
|
84
|
+
openai: {
|
|
85
|
+
...config.openai,
|
|
86
|
+
apiKey: process.env.OPENAI_API_KEY || config.openai.apiKey
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
static get() {
|
|
91
|
+
if (!this.config) {
|
|
92
|
+
throw new Error('Config not loaded. Call ConfigLoader.load() first.');
|
|
93
|
+
}
|
|
94
|
+
return this.config;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.ConfigLoader = ConfigLoader;
|
|
98
|
+
ConfigLoader.config = null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIContainer = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const autowire_decorator_1 = require("../decorators/autowire.decorator");
|
|
6
|
+
class DIContainer {
|
|
7
|
+
static register(target) {
|
|
8
|
+
this.classes.add(target);
|
|
9
|
+
}
|
|
10
|
+
static resolve(target) {
|
|
11
|
+
// Return existing singleton if available
|
|
12
|
+
if (this.instances.has(target)) {
|
|
13
|
+
return this.instances.get(target);
|
|
14
|
+
}
|
|
15
|
+
// Get constructor parameter metadata
|
|
16
|
+
const params = Reflect.getOwnMetadata(autowire_decorator_1.AUTOWIRE_METADATA, target) || [];
|
|
17
|
+
const sortedParams = params.sort((a, b) => a.index - b.index);
|
|
18
|
+
// Resolve dependencies recursively
|
|
19
|
+
const dependencies = sortedParams.map((param) => {
|
|
20
|
+
return this.resolve(param.type);
|
|
21
|
+
});
|
|
22
|
+
// Create instance
|
|
23
|
+
const instance = new target(...dependencies);
|
|
24
|
+
this.instances.set(target, instance);
|
|
25
|
+
return instance;
|
|
26
|
+
}
|
|
27
|
+
static getRegisteredClasses() {
|
|
28
|
+
return Array.from(this.classes);
|
|
29
|
+
}
|
|
30
|
+
static clear() {
|
|
31
|
+
this.instances.clear();
|
|
32
|
+
this.classes.clear();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.DIContainer = DIContainer;
|
|
36
|
+
DIContainer.instances = new Map();
|
|
37
|
+
DIContainer.classes = new Set();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUTH_GUARD_METADATA = void 0;
|
|
4
|
+
exports.AuthGuard = AuthGuard;
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
exports.AUTH_GUARD_METADATA = 'auth:guard';
|
|
7
|
+
function AuthGuard() {
|
|
8
|
+
return (target, propertyKey, descriptor) => {
|
|
9
|
+
if (propertyKey) {
|
|
10
|
+
// method decorator
|
|
11
|
+
Reflect.defineMetadata(exports.AUTH_GUARD_METADATA, true, target.constructor, propertyKey);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// class decorator
|
|
15
|
+
Reflect.defineMetadata(exports.AUTH_GUARD_METADATA, true, target);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUTOWIRE_METADATA = void 0;
|
|
4
|
+
exports.Autowire = Autowire;
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
exports.AUTOWIRE_METADATA = 'autowire:metadata';
|
|
7
|
+
function Autowire() {
|
|
8
|
+
return (target, propertyKey, parameterIndex) => {
|
|
9
|
+
const existingParams = Reflect.getOwnMetadata(exports.AUTOWIRE_METADATA, target) || [];
|
|
10
|
+
const types = Reflect.getMetadata('design:paramtypes', target) || [];
|
|
11
|
+
existingParams.push({
|
|
12
|
+
index: parameterIndex,
|
|
13
|
+
type: types[parameterIndex]
|
|
14
|
+
});
|
|
15
|
+
Reflect.defineMetadata(exports.AUTOWIRE_METADATA, existingParams, target);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTROLLER_PATH = exports.CONTROLLER_METADATA = void 0;
|
|
4
|
+
exports.Controller = Controller;
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
const di_container_1 = require("../container/di-container");
|
|
7
|
+
exports.CONTROLLER_METADATA = 'controller:metadata';
|
|
8
|
+
exports.CONTROLLER_PATH = 'controller:path';
|
|
9
|
+
function Controller(path = '') {
|
|
10
|
+
return (target) => {
|
|
11
|
+
Reflect.defineMetadata(exports.CONTROLLER_METADATA, true, target);
|
|
12
|
+
Reflect.defineMetadata(exports.CONTROLLER_PATH, path, target);
|
|
13
|
+
di_container_1.DIContainer.register(target);
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INJECTABLE_METADATA = void 0;
|
|
4
|
+
exports.Injectable = Injectable;
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
const di_container_1 = require("../container/di-container");
|
|
7
|
+
exports.INJECTABLE_METADATA = 'injectable:metadata';
|
|
8
|
+
function Injectable() {
|
|
9
|
+
return (target) => {
|
|
10
|
+
Reflect.defineMetadata(exports.INJECTABLE_METADATA, true, target);
|
|
11
|
+
di_container_1.DIContainer.register(target);
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MIDDLEWARE_METADATA = void 0;
|
|
4
|
+
exports.Middleware = Middleware;
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
exports.MIDDLEWARE_METADATA = 'middleware:metadata';
|
|
7
|
+
function Middleware(...middlewares) {
|
|
8
|
+
return (target, propertyKey, descriptor) => {
|
|
9
|
+
if (propertyKey) {
|
|
10
|
+
// Method-level middleware
|
|
11
|
+
const existing = Reflect.getOwnMetadata(exports.MIDDLEWARE_METADATA, target.constructor, propertyKey) || [];
|
|
12
|
+
Reflect.defineMetadata(exports.MIDDLEWARE_METADATA, [...existing, ...middlewares], target.constructor, propertyKey);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
// Class-level middleware
|
|
16
|
+
const existing = Reflect.getOwnMetadata(exports.MIDDLEWARE_METADATA, target) || [];
|
|
17
|
+
Reflect.defineMetadata(exports.MIDDLEWARE_METADATA, [...existing, ...middlewares], target);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Repository(): ClassDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export declare const ROUTE_METADATA = "route:metadata";
|
|
3
|
+
export declare enum HttpMethod {
|
|
4
|
+
GET = "get",
|
|
5
|
+
POST = "post",
|
|
6
|
+
PUT = "put",
|
|
7
|
+
DELETE = "delete",
|
|
8
|
+
PATCH = "patch"
|
|
9
|
+
}
|
|
10
|
+
export declare const Get: (path?: string) => MethodDecorator;
|
|
11
|
+
export declare const Post: (path?: string) => MethodDecorator;
|
|
12
|
+
export declare const Put: (path?: string) => MethodDecorator;
|
|
13
|
+
export declare const Delete: (path?: string) => MethodDecorator;
|
|
14
|
+
export declare const Patch: (path?: string) => MethodDecorator;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = exports.HttpMethod = exports.ROUTE_METADATA = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
exports.ROUTE_METADATA = 'route:metadata';
|
|
6
|
+
var HttpMethod;
|
|
7
|
+
(function (HttpMethod) {
|
|
8
|
+
HttpMethod["GET"] = "get";
|
|
9
|
+
HttpMethod["POST"] = "post";
|
|
10
|
+
HttpMethod["PUT"] = "put";
|
|
11
|
+
HttpMethod["DELETE"] = "delete";
|
|
12
|
+
HttpMethod["PATCH"] = "patch";
|
|
13
|
+
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
14
|
+
function createRouteDecorator(method) {
|
|
15
|
+
return (path = '') => {
|
|
16
|
+
return (target, propertyKey, descriptor) => {
|
|
17
|
+
const routes = Reflect.getOwnMetadata(exports.ROUTE_METADATA, target.constructor) || [];
|
|
18
|
+
routes.push({
|
|
19
|
+
method,
|
|
20
|
+
path,
|
|
21
|
+
handlerName: propertyKey
|
|
22
|
+
});
|
|
23
|
+
Reflect.defineMetadata(exports.ROUTE_METADATA, routes, target.constructor);
|
|
24
|
+
return descriptor;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.Get = createRouteDecorator(HttpMethod.GET);
|
|
29
|
+
exports.Post = createRouteDecorator(HttpMethod.POST);
|
|
30
|
+
exports.Put = createRouteDecorator(HttpMethod.PUT);
|
|
31
|
+
exports.Delete = createRouteDecorator(HttpMethod.DELETE);
|
|
32
|
+
exports.Patch = createRouteDecorator(HttpMethod.PATCH);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Service(): ClassDecorator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class OpenAIClient {
|
|
2
|
+
private apiKey;
|
|
3
|
+
private model;
|
|
4
|
+
private baseURL;
|
|
5
|
+
constructor();
|
|
6
|
+
complete(prompt: string, options?: {
|
|
7
|
+
model?: string;
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
temperature?: number;
|
|
10
|
+
}): Promise<string>;
|
|
11
|
+
streamComplete(prompt: string, onChunk: (chunk: string) => void): Promise<void>;
|
|
12
|
+
}
|