nestjs-ddd-cli 2.2.1 → 3.2.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 +247 -408
- package/ddd.schema.json +111 -0
- package/dist/commands/aggregate-validator.d.ts +9 -0
- package/dist/commands/aggregate-validator.js +953 -0
- package/dist/commands/aggregate-validator.js.map +1 -0
- package/dist/commands/ai-assist.d.ts +8 -0
- package/dist/commands/ai-assist.js +337 -0
- package/dist/commands/ai-assist.js.map +1 -0
- package/dist/commands/api-contracts.d.ts +9 -0
- package/dist/commands/api-contracts.js +1368 -0
- package/dist/commands/api-contracts.js.map +1 -0
- package/dist/commands/api-docs.d.ts +8 -0
- package/dist/commands/api-docs.js +408 -0
- package/dist/commands/api-docs.js.map +1 -0
- package/dist/commands/api-versioning.d.ts +11 -0
- package/dist/commands/api-versioning.js +643 -0
- package/dist/commands/api-versioning.js.map +1 -0
- package/dist/commands/audit-logging.d.ts +9 -0
- package/dist/commands/audit-logging.js +1129 -0
- package/dist/commands/audit-logging.js.map +1 -0
- package/dist/commands/batch-generate.d.ts +10 -0
- package/dist/commands/batch-generate.js +405 -0
- package/dist/commands/batch-generate.js.map +1 -0
- package/dist/commands/caching-strategies.d.ts +9 -0
- package/dist/commands/caching-strategies.js +874 -0
- package/dist/commands/caching-strategies.js.map +1 -0
- package/dist/commands/code-analyzer.d.ts +42 -0
- package/dist/commands/code-analyzer.js +474 -0
- package/dist/commands/code-analyzer.js.map +1 -0
- package/dist/commands/database-seeding.d.ts +6 -0
- package/dist/commands/database-seeding.js +621 -0
- package/dist/commands/database-seeding.js.map +1 -0
- package/dist/commands/db-optimization.d.ts +7 -0
- package/dist/commands/db-optimization.js +687 -0
- package/dist/commands/db-optimization.js.map +1 -0
- package/dist/commands/dependency-graph.d.ts +6 -0
- package/dist/commands/dependency-graph.js +329 -0
- package/dist/commands/dependency-graph.js.map +1 -0
- package/dist/commands/doctor-enhanced.d.ts +22 -0
- package/dist/commands/doctor-enhanced.js +543 -0
- package/dist/commands/doctor-enhanced.js.map +1 -0
- package/dist/commands/doctor.d.ts +4 -0
- package/dist/commands/doctor.js +151 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/env-manager.d.ts +6 -0
- package/dist/commands/env-manager.js +419 -0
- package/dist/commands/env-manager.js.map +1 -0
- package/dist/commands/event-sourcing-full.d.ts +10 -0
- package/dist/commands/event-sourcing-full.js +1107 -0
- package/dist/commands/event-sourcing-full.js.map +1 -0
- package/dist/commands/feature-flags.d.ts +9 -0
- package/dist/commands/feature-flags.js +824 -0
- package/dist/commands/feature-flags.js.map +1 -0
- package/dist/commands/filter-dsl.d.ts +10 -0
- package/dist/commands/filter-dsl.js +1407 -0
- package/dist/commands/filter-dsl.js.map +1 -0
- package/dist/commands/generate-all.js +485 -32
- package/dist/commands/generate-all.js.map +1 -1
- package/dist/commands/generate-deployment.d.ts +8 -0
- package/dist/commands/generate-deployment.js +746 -0
- package/dist/commands/generate-deployment.js.map +1 -0
- package/dist/commands/generate-domain-service.d.ts +14 -0
- package/dist/commands/generate-domain-service.js +796 -0
- package/dist/commands/generate-domain-service.js.map +1 -0
- package/dist/commands/generate-entity.js +82 -24
- package/dist/commands/generate-entity.js.map +1 -1
- package/dist/commands/generate-from-schema.d.ts +56 -0
- package/dist/commands/generate-from-schema.js +222 -0
- package/dist/commands/generate-from-schema.js.map +1 -0
- package/dist/commands/generate-orchestrator.d.ts +14 -0
- package/dist/commands/generate-orchestrator.js +887 -0
- package/dist/commands/generate-orchestrator.js.map +1 -0
- package/dist/commands/generate-repository.d.ts +14 -0
- package/dist/commands/generate-repository.js +1019 -0
- package/dist/commands/generate-repository.js.map +1 -0
- package/dist/commands/generate-shared.d.ts +4 -0
- package/dist/commands/generate-shared.js +388 -0
- package/dist/commands/generate-shared.js.map +1 -0
- package/dist/commands/generate-value-object.d.ts +32 -0
- package/dist/commands/generate-value-object.js +700 -0
- package/dist/commands/generate-value-object.js.map +1 -0
- package/dist/commands/graphql-subscriptions.d.ts +6 -0
- package/dist/commands/graphql-subscriptions.js +607 -0
- package/dist/commands/graphql-subscriptions.js.map +1 -0
- package/dist/commands/graphql-types.d.ts +5 -0
- package/dist/commands/graphql-types.js +423 -0
- package/dist/commands/graphql-types.js.map +1 -0
- package/dist/commands/health-probes-advanced.d.ts +6 -0
- package/dist/commands/health-probes-advanced.js +655 -0
- package/dist/commands/health-probes-advanced.js.map +1 -0
- package/dist/commands/i18n-setup.d.ts +10 -0
- package/dist/commands/i18n-setup.js +677 -0
- package/dist/commands/i18n-setup.js.map +1 -0
- package/dist/commands/init-config.d.ts +6 -0
- package/dist/commands/init-config.js +370 -0
- package/dist/commands/init-config.js.map +1 -0
- package/dist/commands/init-project.js +56 -6
- package/dist/commands/init-project.js.map +1 -1
- package/dist/commands/interactive-scaffold.d.ts +5 -0
- package/dist/commands/interactive-scaffold.js +271 -0
- package/dist/commands/interactive-scaffold.js.map +1 -0
- package/dist/commands/metrics-prometheus.d.ts +6 -0
- package/dist/commands/metrics-prometheus.js +681 -0
- package/dist/commands/metrics-prometheus.js.map +1 -0
- package/dist/commands/migration-engine.d.ts +6 -0
- package/dist/commands/migration-engine.js +446 -0
- package/dist/commands/migration-engine.js.map +1 -0
- package/dist/commands/migration.d.ts +12 -0
- package/dist/commands/migration.js +484 -0
- package/dist/commands/migration.js.map +1 -0
- package/dist/commands/monorepo.d.ts +8 -0
- package/dist/commands/monorepo.js +483 -0
- package/dist/commands/monorepo.js.map +1 -0
- package/dist/commands/multi-database.d.ts +5 -0
- package/dist/commands/multi-database.js +439 -0
- package/dist/commands/multi-database.js.map +1 -0
- package/dist/commands/observability-tracing.d.ts +10 -0
- package/dist/commands/observability-tracing.js +740 -0
- package/dist/commands/observability-tracing.js.map +1 -0
- package/dist/commands/openapi-export.d.ts +8 -0
- package/dist/commands/openapi-export.js +359 -0
- package/dist/commands/openapi-export.js.map +1 -0
- package/dist/commands/perf-analyzer.d.ts +8 -0
- package/dist/commands/perf-analyzer.js +423 -0
- package/dist/commands/perf-analyzer.js.map +1 -0
- package/dist/commands/rate-limiting.d.ts +10 -0
- package/dist/commands/rate-limiting.js +953 -0
- package/dist/commands/rate-limiting.js.map +1 -0
- package/dist/commands/recipe-plugin.d.ts +56 -0
- package/dist/commands/recipe-plugin.js +315 -0
- package/dist/commands/recipe-plugin.js.map +1 -0
- package/dist/commands/recipe.d.ts +6 -0
- package/dist/commands/recipe.js +3941 -0
- package/dist/commands/recipe.js.map +1 -0
- package/dist/commands/recipes/elasticsearch.recipe.d.ts +1 -0
- package/dist/commands/recipes/elasticsearch.recipe.js +761 -0
- package/dist/commands/recipes/elasticsearch.recipe.js.map +1 -0
- package/dist/commands/recipes/event-sourcing.recipe.d.ts +1 -0
- package/dist/commands/recipes/event-sourcing.recipe.js +889 -0
- package/dist/commands/recipes/event-sourcing.recipe.js.map +1 -0
- package/dist/commands/recipes/index.d.ts +7 -0
- package/dist/commands/recipes/index.js +24 -0
- package/dist/commands/recipes/index.js.map +1 -0
- package/dist/commands/recipes/message-queue.recipe.d.ts +1 -0
- package/dist/commands/recipes/message-queue.recipe.js +706 -0
- package/dist/commands/recipes/message-queue.recipe.js.map +1 -0
- package/dist/commands/recipes/middleware.recipe.d.ts +1 -0
- package/dist/commands/recipes/middleware.recipe.js +383 -0
- package/dist/commands/recipes/middleware.recipe.js.map +1 -0
- package/dist/commands/recipes/multi-tenancy.recipe.d.ts +1 -0
- package/dist/commands/recipes/multi-tenancy.recipe.js +520 -0
- package/dist/commands/recipes/multi-tenancy.recipe.js.map +1 -0
- package/dist/commands/recipes/oauth2.recipe.d.ts +1 -0
- package/dist/commands/recipes/oauth2.recipe.js +472 -0
- package/dist/commands/recipes/oauth2.recipe.js.map +1 -0
- package/dist/commands/recipes/websocket.recipe.d.ts +1 -0
- package/dist/commands/recipes/websocket.recipe.js +453 -0
- package/dist/commands/recipes/websocket.recipe.js.map +1 -0
- package/dist/commands/resilience-patterns.d.ts +13 -0
- package/dist/commands/resilience-patterns.js +1029 -0
- package/dist/commands/resilience-patterns.js.map +1 -0
- package/dist/commands/security-patterns.d.ts +11 -0
- package/dist/commands/security-patterns.js +2233 -0
- package/dist/commands/security-patterns.js.map +1 -0
- package/dist/commands/template-debug.d.ts +27 -0
- package/dist/commands/template-debug.js +388 -0
- package/dist/commands/template-debug.js.map +1 -0
- package/dist/commands/test-factory-full.d.ts +9 -0
- package/dist/commands/test-factory-full.js +1570 -0
- package/dist/commands/test-factory-full.js.map +1 -0
- package/dist/commands/test-scaffold.d.ts +7 -0
- package/dist/commands/test-scaffold.js +621 -0
- package/dist/commands/test-scaffold.js.map +1 -0
- package/dist/index.js +1088 -0
- package/dist/index.js.map +1 -1
- package/dist/templates/ai-context/CLAUDE.md.hbs +158 -0
- package/dist/templates/ai-context/conventions.md.hbs +154 -0
- package/dist/templates/command/create-command.hbs +6 -14
- package/dist/templates/command/delete-command.hbs +19 -0
- package/dist/templates/command/update-command.hbs +24 -0
- package/dist/templates/controller/controller.hbs +64 -17
- package/dist/templates/dto/create-dto.hbs +29 -5
- package/dist/templates/dto/filter-dto.hbs +52 -0
- package/dist/templates/dto/filter-query.dto.hbs +148 -0
- package/dist/templates/dto/paginated-response.dto.hbs +29 -0
- package/dist/templates/dto/pagination-query.dto.hbs +30 -0
- package/dist/templates/dto/response-dto.hbs +38 -0
- package/dist/templates/dto/update-dto.hbs +11 -0
- package/dist/templates/entity/entity.hbs +32 -1
- package/dist/templates/event/domain-event.hbs +33 -7
- package/dist/templates/event/event-handler.hbs +40 -0
- package/dist/templates/exception/base-exceptions.hbs +69 -0
- package/dist/templates/exception/entity-not-found.exception.hbs +7 -0
- package/dist/templates/mapper/mapper.hbs +49 -24
- package/dist/templates/module/module.hbs +34 -10
- package/dist/templates/orm-entity/orm-entity.hbs +63 -12
- package/dist/templates/prisma/prisma-mapper.hbs +71 -0
- package/dist/templates/prisma/prisma-repository.hbs +114 -0
- package/dist/templates/prisma/prisma-schema.hbs +20 -0
- package/dist/templates/prisma/prisma-service.hbs +51 -0
- package/dist/templates/query/get-all.query.hbs +50 -0
- package/dist/templates/query/get-by-id.query.hbs +31 -0
- package/dist/templates/repository/repository.hbs +55 -13
- package/dist/templates/resolver/graphql-input.hbs +54 -0
- package/dist/templates/resolver/graphql-type.hbs +58 -0
- package/dist/templates/resolver/pagination-args.hbs +33 -0
- package/dist/templates/resolver/resolver.hbs +62 -0
- package/dist/templates/shared/prisma-query-builder.util.hbs +189 -0
- package/dist/templates/shared/query-builder.util.hbs +218 -0
- package/dist/templates/test/controller.spec.hbs +124 -0
- package/dist/templates/test/repository.spec.hbs +158 -0
- package/dist/templates/test/usecase.spec.hbs +116 -0
- package/dist/templates/usecase/create-usecase.hbs +19 -7
- package/dist/templates/usecase/delete-usecase.hbs +17 -0
- package/dist/templates/usecase/update-usecase.hbs +31 -0
- package/dist/utils/config.utils.d.ts +45 -0
- package/dist/utils/config.utils.js +211 -0
- package/dist/utils/config.utils.js.map +1 -0
- package/dist/utils/error.utils.d.ts +145 -0
- package/dist/utils/error.utils.js +422 -0
- package/dist/utils/error.utils.js.map +1 -0
- package/dist/utils/field.utils.d.ts +54 -0
- package/dist/utils/field.utils.js +389 -0
- package/dist/utils/field.utils.js.map +1 -0
- package/dist/utils/file.utils.d.ts +19 -8
- package/dist/utils/file.utils.js +135 -4
- package/dist/utils/file.utils.js.map +1 -1
- package/dist/utils/idempotency.utils.d.ts +123 -0
- package/dist/utils/idempotency.utils.js +444 -0
- package/dist/utils/idempotency.utils.js.map +1 -0
- package/dist/utils/naming.utils.js +24 -5
- package/dist/utils/naming.utils.js.map +1 -1
- package/dist/utils/performance.utils.d.ts +37 -0
- package/dist/utils/performance.utils.js +158 -0
- package/dist/utils/performance.utils.js.map +1 -0
- package/dist/utils/relation.utils.d.ts +92 -0
- package/dist/utils/relation.utils.js +388 -0
- package/dist/utils/relation.utils.js.map +1 -0
- package/dist/utils/rollback.utils.d.ts +49 -0
- package/dist/utils/rollback.utils.js +306 -0
- package/dist/utils/rollback.utils.js.map +1 -0
- package/dist/utils/schema.utils.d.ts +123 -0
- package/dist/utils/schema.utils.js +419 -0
- package/dist/utils/schema.utils.js.map +1 -0
- package/dist/utils/security.utils.d.ts +57 -0
- package/dist/utils/security.utils.js +315 -0
- package/dist/utils/security.utils.js.map +1 -0
- package/dist/utils/template-engine.utils.d.ts +80 -0
- package/dist/utils/template-engine.utils.js +463 -0
- package/dist/utils/template-engine.utils.js.map +1 -0
- package/dist/utils/validation-registry.utils.d.ts +160 -0
- package/dist/utils/validation-registry.utils.js +526 -0
- package/dist/utils/validation-registry.utils.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface FileOperation {
|
|
2
|
+
type: 'create' | 'modify' | 'delete';
|
|
3
|
+
path: string;
|
|
4
|
+
originalContent?: string;
|
|
5
|
+
newContent?: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
}
|
|
8
|
+
export interface Transaction {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
startedAt: Date;
|
|
12
|
+
operations: FileOperation[];
|
|
13
|
+
status: 'pending' | 'committed' | 'rolled_back' | 'failed';
|
|
14
|
+
}
|
|
15
|
+
declare class TransactionManager {
|
|
16
|
+
private currentTransaction;
|
|
17
|
+
private transactionHistory;
|
|
18
|
+
private enabled;
|
|
19
|
+
enable(): void;
|
|
20
|
+
disable(): void;
|
|
21
|
+
isEnabled(): boolean;
|
|
22
|
+
begin(name: string): string;
|
|
23
|
+
recordCreate(filePath: string): void;
|
|
24
|
+
recordModify(filePath: string, originalContent: string): void;
|
|
25
|
+
recordDelete(filePath: string, originalContent: string): void;
|
|
26
|
+
commit(): Promise<void>;
|
|
27
|
+
rollback(reason?: string): Promise<void>;
|
|
28
|
+
private cleanEmptyDirs;
|
|
29
|
+
getHistory(): Transaction[];
|
|
30
|
+
getCurrentTransaction(): Transaction | null;
|
|
31
|
+
printHistory(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare const txn: TransactionManager;
|
|
34
|
+
export declare function withTransaction<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
35
|
+
export declare function createFileWithRollback(filePath: string, content: string): void;
|
|
36
|
+
export declare function modifyFileWithRollback(filePath: string, content: string): void;
|
|
37
|
+
export declare function deleteFileWithRollback(filePath: string): void;
|
|
38
|
+
export interface RecoveryPoint {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
files: Array<{
|
|
43
|
+
path: string;
|
|
44
|
+
content: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createRecoveryPoint(basePath: string, name: string, patterns: string[]): RecoveryPoint;
|
|
48
|
+
export declare function restoreFromRecoveryPoint(point: RecoveryPoint): void;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,306 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.txn = void 0;
|
|
40
|
+
exports.withTransaction = withTransaction;
|
|
41
|
+
exports.createFileWithRollback = createFileWithRollback;
|
|
42
|
+
exports.modifyFileWithRollback = modifyFileWithRollback;
|
|
43
|
+
exports.deleteFileWithRollback = deleteFileWithRollback;
|
|
44
|
+
exports.createRecoveryPoint = createRecoveryPoint;
|
|
45
|
+
exports.restoreFromRecoveryPoint = restoreFromRecoveryPoint;
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
49
|
+
class TransactionManager {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.currentTransaction = null;
|
|
52
|
+
this.transactionHistory = [];
|
|
53
|
+
this.enabled = false;
|
|
54
|
+
}
|
|
55
|
+
enable() {
|
|
56
|
+
this.enabled = true;
|
|
57
|
+
}
|
|
58
|
+
disable() {
|
|
59
|
+
this.enabled = false;
|
|
60
|
+
}
|
|
61
|
+
isEnabled() {
|
|
62
|
+
return this.enabled;
|
|
63
|
+
}
|
|
64
|
+
begin(name) {
|
|
65
|
+
if (!this.enabled)
|
|
66
|
+
return '';
|
|
67
|
+
if (this.currentTransaction) {
|
|
68
|
+
throw new Error('Transaction already in progress. Commit or rollback first.');
|
|
69
|
+
}
|
|
70
|
+
const id = `txn_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
71
|
+
this.currentTransaction = {
|
|
72
|
+
id,
|
|
73
|
+
name,
|
|
74
|
+
startedAt: new Date(),
|
|
75
|
+
operations: [],
|
|
76
|
+
status: 'pending',
|
|
77
|
+
};
|
|
78
|
+
console.log(chalk_1.default.gray(` [Transaction: ${name}]`));
|
|
79
|
+
return id;
|
|
80
|
+
}
|
|
81
|
+
recordCreate(filePath) {
|
|
82
|
+
if (!this.enabled || !this.currentTransaction)
|
|
83
|
+
return;
|
|
84
|
+
this.currentTransaction.operations.push({
|
|
85
|
+
type: 'create',
|
|
86
|
+
path: filePath,
|
|
87
|
+
timestamp: Date.now(),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
recordModify(filePath, originalContent) {
|
|
91
|
+
if (!this.enabled || !this.currentTransaction)
|
|
92
|
+
return;
|
|
93
|
+
// Check if we already recorded this file
|
|
94
|
+
const existing = this.currentTransaction.operations.find(op => op.path === filePath && op.type === 'modify');
|
|
95
|
+
if (!existing) {
|
|
96
|
+
this.currentTransaction.operations.push({
|
|
97
|
+
type: 'modify',
|
|
98
|
+
path: filePath,
|
|
99
|
+
originalContent,
|
|
100
|
+
timestamp: Date.now(),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
recordDelete(filePath, originalContent) {
|
|
105
|
+
if (!this.enabled || !this.currentTransaction)
|
|
106
|
+
return;
|
|
107
|
+
this.currentTransaction.operations.push({
|
|
108
|
+
type: 'delete',
|
|
109
|
+
path: filePath,
|
|
110
|
+
originalContent,
|
|
111
|
+
timestamp: Date.now(),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async commit() {
|
|
115
|
+
if (!this.enabled || !this.currentTransaction)
|
|
116
|
+
return;
|
|
117
|
+
this.currentTransaction.status = 'committed';
|
|
118
|
+
this.transactionHistory.push(this.currentTransaction);
|
|
119
|
+
const opCount = this.currentTransaction.operations.length;
|
|
120
|
+
console.log(chalk_1.default.green(` ✓ Committed: ${opCount} file operations`));
|
|
121
|
+
this.currentTransaction = null;
|
|
122
|
+
}
|
|
123
|
+
async rollback(reason) {
|
|
124
|
+
if (!this.currentTransaction) {
|
|
125
|
+
console.log(chalk_1.default.yellow('No active transaction to rollback.'));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
console.log(chalk_1.default.yellow(`\n⚠️ Rolling back transaction: ${this.currentTransaction.name}`));
|
|
129
|
+
if (reason) {
|
|
130
|
+
console.log(chalk_1.default.yellow(` Reason: ${reason}`));
|
|
131
|
+
}
|
|
132
|
+
const operations = [...this.currentTransaction.operations].reverse();
|
|
133
|
+
let rolledBack = 0;
|
|
134
|
+
let failed = 0;
|
|
135
|
+
for (const op of operations) {
|
|
136
|
+
try {
|
|
137
|
+
switch (op.type) {
|
|
138
|
+
case 'create':
|
|
139
|
+
// Delete created file
|
|
140
|
+
if (fs.existsSync(op.path)) {
|
|
141
|
+
fs.unlinkSync(op.path);
|
|
142
|
+
// Try to remove empty parent directories
|
|
143
|
+
this.cleanEmptyDirs(path.dirname(op.path));
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case 'modify':
|
|
147
|
+
// Restore original content
|
|
148
|
+
if (op.originalContent !== undefined) {
|
|
149
|
+
fs.writeFileSync(op.path, op.originalContent);
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case 'delete':
|
|
153
|
+
// Recreate deleted file
|
|
154
|
+
if (op.originalContent !== undefined) {
|
|
155
|
+
const dir = path.dirname(op.path);
|
|
156
|
+
if (!fs.existsSync(dir)) {
|
|
157
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
158
|
+
}
|
|
159
|
+
fs.writeFileSync(op.path, op.originalContent);
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
rolledBack++;
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
failed++;
|
|
167
|
+
console.log(chalk_1.default.red(` Failed to rollback: ${op.path}`));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
this.currentTransaction.status = 'rolled_back';
|
|
171
|
+
this.transactionHistory.push(this.currentTransaction);
|
|
172
|
+
console.log(chalk_1.default.yellow(` Rolled back ${rolledBack} operations${failed > 0 ? `, ${failed} failed` : ''}`));
|
|
173
|
+
this.currentTransaction = null;
|
|
174
|
+
}
|
|
175
|
+
cleanEmptyDirs(dir) {
|
|
176
|
+
try {
|
|
177
|
+
const entries = fs.readdirSync(dir);
|
|
178
|
+
if (entries.length === 0) {
|
|
179
|
+
fs.rmdirSync(dir);
|
|
180
|
+
// Recursively check parent
|
|
181
|
+
const parent = path.dirname(dir);
|
|
182
|
+
if (parent !== dir) {
|
|
183
|
+
this.cleanEmptyDirs(parent);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
// Ignore errors
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
getHistory() {
|
|
192
|
+
return [...this.transactionHistory];
|
|
193
|
+
}
|
|
194
|
+
getCurrentTransaction() {
|
|
195
|
+
return this.currentTransaction;
|
|
196
|
+
}
|
|
197
|
+
printHistory() {
|
|
198
|
+
if (this.transactionHistory.length === 0) {
|
|
199
|
+
console.log(chalk_1.default.gray('No transaction history.'));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
console.log(chalk_1.default.bold.blue('\n📜 Transaction History\n'));
|
|
203
|
+
for (const txn of this.transactionHistory.slice(-10)) {
|
|
204
|
+
const statusIcon = txn.status === 'committed' ? '✓' :
|
|
205
|
+
txn.status === 'rolled_back' ? '↩' : '✗';
|
|
206
|
+
const statusColor = txn.status === 'committed' ? chalk_1.default.green :
|
|
207
|
+
txn.status === 'rolled_back' ? chalk_1.default.yellow : chalk_1.default.red;
|
|
208
|
+
console.log(statusColor(` ${statusIcon} ${txn.name}`));
|
|
209
|
+
console.log(chalk_1.default.gray(` ${txn.operations.length} operations at ${txn.startedAt.toISOString()}`));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Singleton instance
|
|
214
|
+
exports.txn = new TransactionManager();
|
|
215
|
+
// Wrapper for file operations with automatic rollback support
|
|
216
|
+
async function withTransaction(name, fn) {
|
|
217
|
+
exports.txn.begin(name);
|
|
218
|
+
try {
|
|
219
|
+
const result = await fn();
|
|
220
|
+
await exports.txn.commit();
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
await exports.txn.rollback(error instanceof Error ? error.message : 'Unknown error');
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Enhanced file utilities with transaction support
|
|
229
|
+
function createFileWithRollback(filePath, content) {
|
|
230
|
+
const dir = path.dirname(filePath);
|
|
231
|
+
if (!fs.existsSync(dir)) {
|
|
232
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
233
|
+
}
|
|
234
|
+
fs.writeFileSync(filePath, content);
|
|
235
|
+
exports.txn.recordCreate(filePath);
|
|
236
|
+
}
|
|
237
|
+
function modifyFileWithRollback(filePath, content) {
|
|
238
|
+
let originalContent = '';
|
|
239
|
+
if (fs.existsSync(filePath)) {
|
|
240
|
+
originalContent = fs.readFileSync(filePath, 'utf-8');
|
|
241
|
+
}
|
|
242
|
+
fs.writeFileSync(filePath, content);
|
|
243
|
+
exports.txn.recordModify(filePath, originalContent);
|
|
244
|
+
}
|
|
245
|
+
function deleteFileWithRollback(filePath) {
|
|
246
|
+
if (!fs.existsSync(filePath))
|
|
247
|
+
return;
|
|
248
|
+
const originalContent = fs.readFileSync(filePath, 'utf-8');
|
|
249
|
+
fs.unlinkSync(filePath);
|
|
250
|
+
exports.txn.recordDelete(filePath, originalContent);
|
|
251
|
+
}
|
|
252
|
+
function createRecoveryPoint(basePath, name, patterns) {
|
|
253
|
+
const point = {
|
|
254
|
+
id: `rp_${Date.now()}`,
|
|
255
|
+
name,
|
|
256
|
+
createdAt: new Date(),
|
|
257
|
+
files: [],
|
|
258
|
+
};
|
|
259
|
+
function scanDir(dir) {
|
|
260
|
+
if (!fs.existsSync(dir))
|
|
261
|
+
return;
|
|
262
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
263
|
+
for (const entry of entries) {
|
|
264
|
+
const fullPath = path.join(dir, entry.name);
|
|
265
|
+
if (entry.isDirectory()) {
|
|
266
|
+
if (!entry.name.startsWith('.') && entry.name !== 'node_modules') {
|
|
267
|
+
scanDir(fullPath);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
const matches = patterns.some(p => {
|
|
272
|
+
const regex = new RegExp(p.replace(/\*/g, '.*'));
|
|
273
|
+
return regex.test(fullPath);
|
|
274
|
+
});
|
|
275
|
+
if (matches) {
|
|
276
|
+
point.files.push({
|
|
277
|
+
path: fullPath,
|
|
278
|
+
content: fs.readFileSync(fullPath, 'utf-8'),
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
scanDir(basePath);
|
|
285
|
+
console.log(chalk_1.default.green(`✓ Recovery point created: ${name} (${point.files.length} files)`));
|
|
286
|
+
return point;
|
|
287
|
+
}
|
|
288
|
+
function restoreFromRecoveryPoint(point) {
|
|
289
|
+
console.log(chalk_1.default.yellow(`\n⚠️ Restoring from recovery point: ${point.name}`));
|
|
290
|
+
let restored = 0;
|
|
291
|
+
for (const file of point.files) {
|
|
292
|
+
try {
|
|
293
|
+
const dir = path.dirname(file.path);
|
|
294
|
+
if (!fs.existsSync(dir)) {
|
|
295
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
296
|
+
}
|
|
297
|
+
fs.writeFileSync(file.path, file.content);
|
|
298
|
+
restored++;
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
console.log(chalk_1.default.red(` Failed to restore: ${file.path}`));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
console.log(chalk_1.default.green(` Restored ${restored}/${point.files.length} files`));
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=rollback.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollback.utils.js","sourceRoot":"","sources":["../../src/utils/rollback.utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyNA,0CAcC;AAGD,wDAQC;AAED,wDAQC;AAED,wDAMC;AAUD,kDAuCC;AAED,4DAkBC;AAzUD,uCAAyB;AACzB,2CAA6B;AAC7B,kDAA0B;AAkB1B,MAAM,kBAAkB;IAAxB;QACU,uBAAkB,GAAuB,IAAI,CAAC;QAC9C,uBAAkB,GAAkB,EAAE,CAAC;QACvC,YAAO,GAAY,KAAK,CAAC;IA4LnC,CAAC;IA1LC,MAAM;QACJ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QAE7B,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;QAED,MAAM,EAAE,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAE1E,IAAI,CAAC,kBAAkB,GA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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-Safe Field Schema System
|
|
3
|
+
* Provides structured field definitions with validation guarantees
|
|
4
|
+
*/
|
|
5
|
+
export type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'text' | 'json' | 'uuid' | 'email' | 'url' | 'enum' | 'decimal' | 'float' | 'integer' | 'bigint';
|
|
6
|
+
export type FieldModifier = 'optional' | 'unique' | 'index' | 'primary' | 'generated' | 'nullable' | 'readonly';
|
|
7
|
+
export type RelationType = 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many';
|
|
8
|
+
export interface FieldValidation {
|
|
9
|
+
required?: boolean;
|
|
10
|
+
minLength?: number;
|
|
11
|
+
maxLength?: number;
|
|
12
|
+
min?: number;
|
|
13
|
+
max?: number;
|
|
14
|
+
pattern?: string;
|
|
15
|
+
email?: boolean;
|
|
16
|
+
url?: boolean;
|
|
17
|
+
uuid?: boolean;
|
|
18
|
+
enum?: string[];
|
|
19
|
+
custom?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface FieldSchema {
|
|
22
|
+
name: string;
|
|
23
|
+
type: FieldType;
|
|
24
|
+
modifiers: FieldModifier[];
|
|
25
|
+
validation: FieldValidation;
|
|
26
|
+
description?: string;
|
|
27
|
+
defaultValue?: string | number | boolean;
|
|
28
|
+
enumValues?: string[];
|
|
29
|
+
length?: number;
|
|
30
|
+
precision?: number;
|
|
31
|
+
scale?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface RelationSchema {
|
|
34
|
+
name: string;
|
|
35
|
+
type: RelationType;
|
|
36
|
+
target: string;
|
|
37
|
+
inverseSide?: string;
|
|
38
|
+
joinColumn?: string;
|
|
39
|
+
joinTable?: string;
|
|
40
|
+
cascade?: ('insert' | 'update' | 'remove' | 'soft-remove' | 'recover')[];
|
|
41
|
+
eager?: boolean;
|
|
42
|
+
nullable?: boolean;
|
|
43
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'NO ACTION' | 'RESTRICT';
|
|
44
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'NO ACTION' | 'RESTRICT';
|
|
45
|
+
}
|
|
46
|
+
export interface EntitySchema {
|
|
47
|
+
name: string;
|
|
48
|
+
tableName?: string;
|
|
49
|
+
fields: FieldSchema[];
|
|
50
|
+
relations: RelationSchema[];
|
|
51
|
+
indexes?: IndexSchema[];
|
|
52
|
+
timestamps?: boolean;
|
|
53
|
+
softDelete?: boolean;
|
|
54
|
+
audit?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface IndexSchema {
|
|
57
|
+
name?: string;
|
|
58
|
+
columns: string[];
|
|
59
|
+
unique?: boolean;
|
|
60
|
+
where?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface SchemaValidationResult {
|
|
63
|
+
valid: boolean;
|
|
64
|
+
errors: SchemaError[];
|
|
65
|
+
warnings: SchemaWarning[];
|
|
66
|
+
}
|
|
67
|
+
export interface SchemaError {
|
|
68
|
+
path: string;
|
|
69
|
+
message: string;
|
|
70
|
+
code: string;
|
|
71
|
+
}
|
|
72
|
+
export interface SchemaWarning {
|
|
73
|
+
path: string;
|
|
74
|
+
message: string;
|
|
75
|
+
suggestion?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse field string into structured FieldSchema
|
|
79
|
+
* Format: name:type:modifier1:modifier2
|
|
80
|
+
* Examples:
|
|
81
|
+
* - email:string:unique
|
|
82
|
+
* - age:number:optional
|
|
83
|
+
* - status:enum(active,inactive,pending)
|
|
84
|
+
* - price:decimal(10,2)
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseFieldString(fieldStr: string): FieldSchema;
|
|
87
|
+
/**
|
|
88
|
+
* Parse multiple field strings
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseFieldStrings(fieldsStr: string): FieldSchema[];
|
|
91
|
+
/**
|
|
92
|
+
* Convert FieldSchema to TypeScript type
|
|
93
|
+
*/
|
|
94
|
+
export declare function fieldToTypeScript(field: FieldSchema): string;
|
|
95
|
+
/**
|
|
96
|
+
* Convert FieldSchema to TypeORM column decorator
|
|
97
|
+
*/
|
|
98
|
+
export declare function fieldToTypeORMDecorator(field: FieldSchema): string;
|
|
99
|
+
/**
|
|
100
|
+
* Convert FieldSchema to class-validator decorators
|
|
101
|
+
*/
|
|
102
|
+
export declare function fieldToValidatorDecorators(field: FieldSchema): string[];
|
|
103
|
+
/**
|
|
104
|
+
* Validate an EntitySchema
|
|
105
|
+
*/
|
|
106
|
+
export declare function validateEntitySchema(schema: EntitySchema): SchemaValidationResult;
|
|
107
|
+
/**
|
|
108
|
+
* Generate complete EntitySchema from field strings
|
|
109
|
+
*/
|
|
110
|
+
export declare function createEntitySchema(name: string, fieldsStr: string, options?: {
|
|
111
|
+
timestamps?: boolean;
|
|
112
|
+
softDelete?: boolean;
|
|
113
|
+
audit?: boolean;
|
|
114
|
+
relations?: RelationSchema[];
|
|
115
|
+
}): EntitySchema;
|
|
116
|
+
/**
|
|
117
|
+
* Export schema to JSON format
|
|
118
|
+
*/
|
|
119
|
+
export declare function schemaToJSON(schema: EntitySchema): string;
|
|
120
|
+
/**
|
|
121
|
+
* Import schema from JSON
|
|
122
|
+
*/
|
|
123
|
+
export declare function schemaFromJSON(json: string): EntitySchema;
|