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.
Files changed (254) hide show
  1. package/README.md +247 -408
  2. package/ddd.schema.json +111 -0
  3. package/dist/commands/aggregate-validator.d.ts +9 -0
  4. package/dist/commands/aggregate-validator.js +953 -0
  5. package/dist/commands/aggregate-validator.js.map +1 -0
  6. package/dist/commands/ai-assist.d.ts +8 -0
  7. package/dist/commands/ai-assist.js +337 -0
  8. package/dist/commands/ai-assist.js.map +1 -0
  9. package/dist/commands/api-contracts.d.ts +9 -0
  10. package/dist/commands/api-contracts.js +1368 -0
  11. package/dist/commands/api-contracts.js.map +1 -0
  12. package/dist/commands/api-docs.d.ts +8 -0
  13. package/dist/commands/api-docs.js +408 -0
  14. package/dist/commands/api-docs.js.map +1 -0
  15. package/dist/commands/api-versioning.d.ts +11 -0
  16. package/dist/commands/api-versioning.js +643 -0
  17. package/dist/commands/api-versioning.js.map +1 -0
  18. package/dist/commands/audit-logging.d.ts +9 -0
  19. package/dist/commands/audit-logging.js +1129 -0
  20. package/dist/commands/audit-logging.js.map +1 -0
  21. package/dist/commands/batch-generate.d.ts +10 -0
  22. package/dist/commands/batch-generate.js +405 -0
  23. package/dist/commands/batch-generate.js.map +1 -0
  24. package/dist/commands/caching-strategies.d.ts +9 -0
  25. package/dist/commands/caching-strategies.js +874 -0
  26. package/dist/commands/caching-strategies.js.map +1 -0
  27. package/dist/commands/code-analyzer.d.ts +42 -0
  28. package/dist/commands/code-analyzer.js +474 -0
  29. package/dist/commands/code-analyzer.js.map +1 -0
  30. package/dist/commands/database-seeding.d.ts +6 -0
  31. package/dist/commands/database-seeding.js +621 -0
  32. package/dist/commands/database-seeding.js.map +1 -0
  33. package/dist/commands/db-optimization.d.ts +7 -0
  34. package/dist/commands/db-optimization.js +687 -0
  35. package/dist/commands/db-optimization.js.map +1 -0
  36. package/dist/commands/dependency-graph.d.ts +6 -0
  37. package/dist/commands/dependency-graph.js +329 -0
  38. package/dist/commands/dependency-graph.js.map +1 -0
  39. package/dist/commands/doctor-enhanced.d.ts +22 -0
  40. package/dist/commands/doctor-enhanced.js +543 -0
  41. package/dist/commands/doctor-enhanced.js.map +1 -0
  42. package/dist/commands/doctor.d.ts +4 -0
  43. package/dist/commands/doctor.js +151 -0
  44. package/dist/commands/doctor.js.map +1 -0
  45. package/dist/commands/env-manager.d.ts +6 -0
  46. package/dist/commands/env-manager.js +419 -0
  47. package/dist/commands/env-manager.js.map +1 -0
  48. package/dist/commands/event-sourcing-full.d.ts +10 -0
  49. package/dist/commands/event-sourcing-full.js +1107 -0
  50. package/dist/commands/event-sourcing-full.js.map +1 -0
  51. package/dist/commands/feature-flags.d.ts +9 -0
  52. package/dist/commands/feature-flags.js +824 -0
  53. package/dist/commands/feature-flags.js.map +1 -0
  54. package/dist/commands/filter-dsl.d.ts +10 -0
  55. package/dist/commands/filter-dsl.js +1407 -0
  56. package/dist/commands/filter-dsl.js.map +1 -0
  57. package/dist/commands/generate-all.js +485 -32
  58. package/dist/commands/generate-all.js.map +1 -1
  59. package/dist/commands/generate-deployment.d.ts +8 -0
  60. package/dist/commands/generate-deployment.js +746 -0
  61. package/dist/commands/generate-deployment.js.map +1 -0
  62. package/dist/commands/generate-domain-service.d.ts +14 -0
  63. package/dist/commands/generate-domain-service.js +796 -0
  64. package/dist/commands/generate-domain-service.js.map +1 -0
  65. package/dist/commands/generate-entity.js +82 -24
  66. package/dist/commands/generate-entity.js.map +1 -1
  67. package/dist/commands/generate-from-schema.d.ts +56 -0
  68. package/dist/commands/generate-from-schema.js +222 -0
  69. package/dist/commands/generate-from-schema.js.map +1 -0
  70. package/dist/commands/generate-orchestrator.d.ts +14 -0
  71. package/dist/commands/generate-orchestrator.js +887 -0
  72. package/dist/commands/generate-orchestrator.js.map +1 -0
  73. package/dist/commands/generate-repository.d.ts +14 -0
  74. package/dist/commands/generate-repository.js +1019 -0
  75. package/dist/commands/generate-repository.js.map +1 -0
  76. package/dist/commands/generate-shared.d.ts +4 -0
  77. package/dist/commands/generate-shared.js +388 -0
  78. package/dist/commands/generate-shared.js.map +1 -0
  79. package/dist/commands/generate-value-object.d.ts +32 -0
  80. package/dist/commands/generate-value-object.js +700 -0
  81. package/dist/commands/generate-value-object.js.map +1 -0
  82. package/dist/commands/graphql-subscriptions.d.ts +6 -0
  83. package/dist/commands/graphql-subscriptions.js +607 -0
  84. package/dist/commands/graphql-subscriptions.js.map +1 -0
  85. package/dist/commands/graphql-types.d.ts +5 -0
  86. package/dist/commands/graphql-types.js +423 -0
  87. package/dist/commands/graphql-types.js.map +1 -0
  88. package/dist/commands/health-probes-advanced.d.ts +6 -0
  89. package/dist/commands/health-probes-advanced.js +655 -0
  90. package/dist/commands/health-probes-advanced.js.map +1 -0
  91. package/dist/commands/i18n-setup.d.ts +10 -0
  92. package/dist/commands/i18n-setup.js +677 -0
  93. package/dist/commands/i18n-setup.js.map +1 -0
  94. package/dist/commands/init-config.d.ts +6 -0
  95. package/dist/commands/init-config.js +370 -0
  96. package/dist/commands/init-config.js.map +1 -0
  97. package/dist/commands/init-project.js +56 -6
  98. package/dist/commands/init-project.js.map +1 -1
  99. package/dist/commands/interactive-scaffold.d.ts +5 -0
  100. package/dist/commands/interactive-scaffold.js +271 -0
  101. package/dist/commands/interactive-scaffold.js.map +1 -0
  102. package/dist/commands/metrics-prometheus.d.ts +6 -0
  103. package/dist/commands/metrics-prometheus.js +681 -0
  104. package/dist/commands/metrics-prometheus.js.map +1 -0
  105. package/dist/commands/migration-engine.d.ts +6 -0
  106. package/dist/commands/migration-engine.js +446 -0
  107. package/dist/commands/migration-engine.js.map +1 -0
  108. package/dist/commands/migration.d.ts +12 -0
  109. package/dist/commands/migration.js +484 -0
  110. package/dist/commands/migration.js.map +1 -0
  111. package/dist/commands/monorepo.d.ts +8 -0
  112. package/dist/commands/monorepo.js +483 -0
  113. package/dist/commands/monorepo.js.map +1 -0
  114. package/dist/commands/multi-database.d.ts +5 -0
  115. package/dist/commands/multi-database.js +439 -0
  116. package/dist/commands/multi-database.js.map +1 -0
  117. package/dist/commands/observability-tracing.d.ts +10 -0
  118. package/dist/commands/observability-tracing.js +740 -0
  119. package/dist/commands/observability-tracing.js.map +1 -0
  120. package/dist/commands/openapi-export.d.ts +8 -0
  121. package/dist/commands/openapi-export.js +359 -0
  122. package/dist/commands/openapi-export.js.map +1 -0
  123. package/dist/commands/perf-analyzer.d.ts +8 -0
  124. package/dist/commands/perf-analyzer.js +423 -0
  125. package/dist/commands/perf-analyzer.js.map +1 -0
  126. package/dist/commands/rate-limiting.d.ts +10 -0
  127. package/dist/commands/rate-limiting.js +953 -0
  128. package/dist/commands/rate-limiting.js.map +1 -0
  129. package/dist/commands/recipe-plugin.d.ts +56 -0
  130. package/dist/commands/recipe-plugin.js +315 -0
  131. package/dist/commands/recipe-plugin.js.map +1 -0
  132. package/dist/commands/recipe.d.ts +6 -0
  133. package/dist/commands/recipe.js +3941 -0
  134. package/dist/commands/recipe.js.map +1 -0
  135. package/dist/commands/recipes/elasticsearch.recipe.d.ts +1 -0
  136. package/dist/commands/recipes/elasticsearch.recipe.js +761 -0
  137. package/dist/commands/recipes/elasticsearch.recipe.js.map +1 -0
  138. package/dist/commands/recipes/event-sourcing.recipe.d.ts +1 -0
  139. package/dist/commands/recipes/event-sourcing.recipe.js +889 -0
  140. package/dist/commands/recipes/event-sourcing.recipe.js.map +1 -0
  141. package/dist/commands/recipes/index.d.ts +7 -0
  142. package/dist/commands/recipes/index.js +24 -0
  143. package/dist/commands/recipes/index.js.map +1 -0
  144. package/dist/commands/recipes/message-queue.recipe.d.ts +1 -0
  145. package/dist/commands/recipes/message-queue.recipe.js +706 -0
  146. package/dist/commands/recipes/message-queue.recipe.js.map +1 -0
  147. package/dist/commands/recipes/middleware.recipe.d.ts +1 -0
  148. package/dist/commands/recipes/middleware.recipe.js +383 -0
  149. package/dist/commands/recipes/middleware.recipe.js.map +1 -0
  150. package/dist/commands/recipes/multi-tenancy.recipe.d.ts +1 -0
  151. package/dist/commands/recipes/multi-tenancy.recipe.js +520 -0
  152. package/dist/commands/recipes/multi-tenancy.recipe.js.map +1 -0
  153. package/dist/commands/recipes/oauth2.recipe.d.ts +1 -0
  154. package/dist/commands/recipes/oauth2.recipe.js +472 -0
  155. package/dist/commands/recipes/oauth2.recipe.js.map +1 -0
  156. package/dist/commands/recipes/websocket.recipe.d.ts +1 -0
  157. package/dist/commands/recipes/websocket.recipe.js +453 -0
  158. package/dist/commands/recipes/websocket.recipe.js.map +1 -0
  159. package/dist/commands/resilience-patterns.d.ts +13 -0
  160. package/dist/commands/resilience-patterns.js +1029 -0
  161. package/dist/commands/resilience-patterns.js.map +1 -0
  162. package/dist/commands/security-patterns.d.ts +11 -0
  163. package/dist/commands/security-patterns.js +2233 -0
  164. package/dist/commands/security-patterns.js.map +1 -0
  165. package/dist/commands/template-debug.d.ts +27 -0
  166. package/dist/commands/template-debug.js +388 -0
  167. package/dist/commands/template-debug.js.map +1 -0
  168. package/dist/commands/test-factory-full.d.ts +9 -0
  169. package/dist/commands/test-factory-full.js +1570 -0
  170. package/dist/commands/test-factory-full.js.map +1 -0
  171. package/dist/commands/test-scaffold.d.ts +7 -0
  172. package/dist/commands/test-scaffold.js +621 -0
  173. package/dist/commands/test-scaffold.js.map +1 -0
  174. package/dist/index.js +1088 -0
  175. package/dist/index.js.map +1 -1
  176. package/dist/templates/ai-context/CLAUDE.md.hbs +158 -0
  177. package/dist/templates/ai-context/conventions.md.hbs +154 -0
  178. package/dist/templates/command/create-command.hbs +6 -14
  179. package/dist/templates/command/delete-command.hbs +19 -0
  180. package/dist/templates/command/update-command.hbs +24 -0
  181. package/dist/templates/controller/controller.hbs +64 -17
  182. package/dist/templates/dto/create-dto.hbs +29 -5
  183. package/dist/templates/dto/filter-dto.hbs +52 -0
  184. package/dist/templates/dto/filter-query.dto.hbs +148 -0
  185. package/dist/templates/dto/paginated-response.dto.hbs +29 -0
  186. package/dist/templates/dto/pagination-query.dto.hbs +30 -0
  187. package/dist/templates/dto/response-dto.hbs +38 -0
  188. package/dist/templates/dto/update-dto.hbs +11 -0
  189. package/dist/templates/entity/entity.hbs +32 -1
  190. package/dist/templates/event/domain-event.hbs +33 -7
  191. package/dist/templates/event/event-handler.hbs +40 -0
  192. package/dist/templates/exception/base-exceptions.hbs +69 -0
  193. package/dist/templates/exception/entity-not-found.exception.hbs +7 -0
  194. package/dist/templates/mapper/mapper.hbs +49 -24
  195. package/dist/templates/module/module.hbs +34 -10
  196. package/dist/templates/orm-entity/orm-entity.hbs +63 -12
  197. package/dist/templates/prisma/prisma-mapper.hbs +71 -0
  198. package/dist/templates/prisma/prisma-repository.hbs +114 -0
  199. package/dist/templates/prisma/prisma-schema.hbs +20 -0
  200. package/dist/templates/prisma/prisma-service.hbs +51 -0
  201. package/dist/templates/query/get-all.query.hbs +50 -0
  202. package/dist/templates/query/get-by-id.query.hbs +31 -0
  203. package/dist/templates/repository/repository.hbs +55 -13
  204. package/dist/templates/resolver/graphql-input.hbs +54 -0
  205. package/dist/templates/resolver/graphql-type.hbs +58 -0
  206. package/dist/templates/resolver/pagination-args.hbs +33 -0
  207. package/dist/templates/resolver/resolver.hbs +62 -0
  208. package/dist/templates/shared/prisma-query-builder.util.hbs +189 -0
  209. package/dist/templates/shared/query-builder.util.hbs +218 -0
  210. package/dist/templates/test/controller.spec.hbs +124 -0
  211. package/dist/templates/test/repository.spec.hbs +158 -0
  212. package/dist/templates/test/usecase.spec.hbs +116 -0
  213. package/dist/templates/usecase/create-usecase.hbs +19 -7
  214. package/dist/templates/usecase/delete-usecase.hbs +17 -0
  215. package/dist/templates/usecase/update-usecase.hbs +31 -0
  216. package/dist/utils/config.utils.d.ts +45 -0
  217. package/dist/utils/config.utils.js +211 -0
  218. package/dist/utils/config.utils.js.map +1 -0
  219. package/dist/utils/error.utils.d.ts +145 -0
  220. package/dist/utils/error.utils.js +422 -0
  221. package/dist/utils/error.utils.js.map +1 -0
  222. package/dist/utils/field.utils.d.ts +54 -0
  223. package/dist/utils/field.utils.js +389 -0
  224. package/dist/utils/field.utils.js.map +1 -0
  225. package/dist/utils/file.utils.d.ts +19 -8
  226. package/dist/utils/file.utils.js +135 -4
  227. package/dist/utils/file.utils.js.map +1 -1
  228. package/dist/utils/idempotency.utils.d.ts +123 -0
  229. package/dist/utils/idempotency.utils.js +444 -0
  230. package/dist/utils/idempotency.utils.js.map +1 -0
  231. package/dist/utils/naming.utils.js +24 -5
  232. package/dist/utils/naming.utils.js.map +1 -1
  233. package/dist/utils/performance.utils.d.ts +37 -0
  234. package/dist/utils/performance.utils.js +158 -0
  235. package/dist/utils/performance.utils.js.map +1 -0
  236. package/dist/utils/relation.utils.d.ts +92 -0
  237. package/dist/utils/relation.utils.js +388 -0
  238. package/dist/utils/relation.utils.js.map +1 -0
  239. package/dist/utils/rollback.utils.d.ts +49 -0
  240. package/dist/utils/rollback.utils.js +306 -0
  241. package/dist/utils/rollback.utils.js.map +1 -0
  242. package/dist/utils/schema.utils.d.ts +123 -0
  243. package/dist/utils/schema.utils.js +419 -0
  244. package/dist/utils/schema.utils.js.map +1 -0
  245. package/dist/utils/security.utils.d.ts +57 -0
  246. package/dist/utils/security.utils.js +315 -0
  247. package/dist/utils/security.utils.js.map +1 -0
  248. package/dist/utils/template-engine.utils.d.ts +80 -0
  249. package/dist/utils/template-engine.utils.js +463 -0
  250. package/dist/utils/template-engine.utils.js.map +1 -0
  251. package/dist/utils/validation-registry.utils.d.ts +160 -0
  252. package/dist/utils/validation-registry.utils.js +526 -0
  253. package/dist/utils/validation-registry.utils.js.map +1 -0
  254. package/package.json +3 -1
@@ -0,0 +1,643 @@
1
+ "use strict";
2
+ /**
3
+ * API Versioning & Backward Compatibility Engine
4
+ * Generates versioned APIs with deprecation handling
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.setupApiVersioning = setupApiVersioning;
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ const chalk_1 = __importDefault(require("chalk"));
47
+ async function setupApiVersioning(basePath, options = {}) {
48
+ console.log(chalk_1.default.bold.blue('\n📦 Setting up API Versioning\n'));
49
+ const sharedPath = path.join(basePath, 'src/shared/versioning');
50
+ if (!fs.existsSync(sharedPath)) {
51
+ fs.mkdirSync(sharedPath, { recursive: true });
52
+ }
53
+ // Generate versioning module
54
+ const moduleContent = generateVersioningModule(options);
55
+ fs.writeFileSync(path.join(sharedPath, 'versioning.module.ts'), moduleContent);
56
+ console.log(chalk_1.default.green(` ✓ Created versioning module`));
57
+ // Generate version interceptor
58
+ const interceptorContent = generateVersionInterceptor();
59
+ fs.writeFileSync(path.join(sharedPath, 'version.interceptor.ts'), interceptorContent);
60
+ console.log(chalk_1.default.green(` ✓ Created version interceptor`));
61
+ // Generate deprecation handler
62
+ const deprecationContent = generateDeprecationHandler();
63
+ fs.writeFileSync(path.join(sharedPath, 'deprecation.handler.ts'), deprecationContent);
64
+ console.log(chalk_1.default.green(` ✓ Created deprecation handler`));
65
+ // Generate versioned controller decorator
66
+ const decoratorContent = generateVersionedDecorator();
67
+ fs.writeFileSync(path.join(sharedPath, 'versioned.decorator.ts'), decoratorContent);
68
+ console.log(chalk_1.default.green(` ✓ Created versioned decorator`));
69
+ // Generate DTO migrator
70
+ const migratorContent = generateDtoMigrator();
71
+ fs.writeFileSync(path.join(sharedPath, 'dto-migrator.ts'), migratorContent);
72
+ console.log(chalk_1.default.green(` ✓ Created DTO migrator`));
73
+ // Generate version registry
74
+ const registryContent = generateVersionRegistry();
75
+ fs.writeFileSync(path.join(sharedPath, 'version.registry.ts'), registryContent);
76
+ console.log(chalk_1.default.green(` ✓ Created version registry`));
77
+ console.log(chalk_1.default.bold.green('\n✅ API versioning setup complete!\n'));
78
+ }
79
+ function generateVersioningModule(options) {
80
+ const strategy = options.strategy || 'uri';
81
+ const version = options.currentVersion || '1';
82
+ return `import { Module, Global, DynamicModule } from '@nestjs/common';
83
+ import { APP_INTERCEPTOR, APP_GUARD } from '@nestjs/core';
84
+ import { VersionInterceptor } from './version.interceptor';
85
+ import { DeprecationHandler } from './deprecation.handler';
86
+ import { VersionRegistry } from './version.registry';
87
+ import { DtoMigrator } from './dto-migrator';
88
+
89
+ export interface VersioningModuleOptions {
90
+ strategy: 'uri' | 'header' | 'query';
91
+ defaultVersion: string;
92
+ supportedVersions: string[];
93
+ deprecatedVersions?: string[];
94
+ sunsetVersions?: { version: string; sunsetDate: Date }[];
95
+ }
96
+
97
+ @Global()
98
+ @Module({})
99
+ export class VersioningModule {
100
+ static forRoot(options: VersioningModuleOptions): DynamicModule {
101
+ return {
102
+ module: VersioningModule,
103
+ providers: [
104
+ {
105
+ provide: 'VERSIONING_OPTIONS',
106
+ useValue: options,
107
+ },
108
+ VersionRegistry,
109
+ DtoMigrator,
110
+ DeprecationHandler,
111
+ {
112
+ provide: APP_INTERCEPTOR,
113
+ useClass: VersionInterceptor,
114
+ },
115
+ ],
116
+ exports: [VersionRegistry, DtoMigrator, DeprecationHandler],
117
+ };
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Default versioning configuration
123
+ */
124
+ export const DEFAULT_VERSIONING_OPTIONS: VersioningModuleOptions = {
125
+ strategy: '${strategy}',
126
+ defaultVersion: '${version}',
127
+ supportedVersions: ['1', '2'],
128
+ deprecatedVersions: [],
129
+ sunsetVersions: [],
130
+ };
131
+ `;
132
+ }
133
+ function generateVersionInterceptor() {
134
+ return `import {
135
+ Injectable,
136
+ NestInterceptor,
137
+ ExecutionContext,
138
+ CallHandler,
139
+ Inject,
140
+ } from '@nestjs/common';
141
+ import { Observable } from 'rxjs';
142
+ import { tap } from 'rxjs/operators';
143
+ import { DeprecationHandler } from './deprecation.handler';
144
+
145
+ @Injectable()
146
+ export class VersionInterceptor implements NestInterceptor {
147
+ constructor(
148
+ @Inject('VERSIONING_OPTIONS') private readonly options: any,
149
+ private readonly deprecationHandler: DeprecationHandler,
150
+ ) {}
151
+
152
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
153
+ const request = context.switchToHttp().getRequest();
154
+ const response = context.switchToHttp().getResponse();
155
+ const version = this.extractVersion(request);
156
+
157
+ // Set version header in response
158
+ response.setHeader('X-API-Version', version);
159
+
160
+ // Check for deprecation
161
+ const deprecationInfo = this.deprecationHandler.check(version);
162
+ if (deprecationInfo.deprecated) {
163
+ response.setHeader('X-API-Deprecated', 'true');
164
+ response.setHeader('X-API-Sunset', deprecationInfo.sunsetDate?.toISOString() || '');
165
+ response.setHeader('X-API-Deprecation-Notice', deprecationInfo.message || '');
166
+ }
167
+
168
+ // Add supported versions header
169
+ response.setHeader('X-API-Supported-Versions', this.options.supportedVersions.join(', '));
170
+
171
+ return next.handle().pipe(
172
+ tap(() => {
173
+ // Log version usage for analytics
174
+ this.logVersionUsage(version, request.path);
175
+ }),
176
+ );
177
+ }
178
+
179
+ private extractVersion(request: any): string {
180
+ switch (this.options.strategy) {
181
+ case 'header':
182
+ return request.headers['x-api-version'] || this.options.defaultVersion;
183
+ case 'query':
184
+ return request.query.version || this.options.defaultVersion;
185
+ case 'uri':
186
+ default:
187
+ // Extract from URL path like /v1/resource
188
+ const match = request.path.match(/\\/v(\\d+)\\//);
189
+ return match ? match[1] : this.options.defaultVersion;
190
+ }
191
+ }
192
+
193
+ private logVersionUsage(version: string, path: string): void {
194
+ // Implement version usage logging/analytics
195
+ }
196
+ }
197
+ `;
198
+ }
199
+ function generateDeprecationHandler() {
200
+ return `import { Injectable, Inject, Logger } from '@nestjs/common';
201
+
202
+ export interface DeprecationInfo {
203
+ deprecated: boolean;
204
+ sunsetDate?: Date;
205
+ message?: string;
206
+ replacementVersion?: string;
207
+ }
208
+
209
+ @Injectable()
210
+ export class DeprecationHandler {
211
+ private readonly logger = new Logger(DeprecationHandler.name);
212
+
213
+ constructor(@Inject('VERSIONING_OPTIONS') private readonly options: any) {}
214
+
215
+ /**
216
+ * Check if a version is deprecated
217
+ */
218
+ check(version: string): DeprecationInfo {
219
+ // Check if version is in deprecated list
220
+ if (this.options.deprecatedVersions?.includes(version)) {
221
+ const sunsetInfo = this.options.sunsetVersions?.find(
222
+ (s: any) => s.version === version,
223
+ );
224
+
225
+ return {
226
+ deprecated: true,
227
+ sunsetDate: sunsetInfo?.sunsetDate,
228
+ message: \`API version \${version} is deprecated. Please upgrade to version \${this.options.defaultVersion}.\`,
229
+ replacementVersion: this.options.defaultVersion,
230
+ };
231
+ }
232
+
233
+ return { deprecated: false };
234
+ }
235
+
236
+ /**
237
+ * Check if a version is sunsetted (no longer available)
238
+ */
239
+ isSunsetted(version: string): boolean {
240
+ const sunsetInfo = this.options.sunsetVersions?.find(
241
+ (s: any) => s.version === version,
242
+ );
243
+
244
+ if (sunsetInfo && new Date() > sunsetInfo.sunsetDate) {
245
+ return true;
246
+ }
247
+
248
+ return false;
249
+ }
250
+
251
+ /**
252
+ * Get deprecation notice for documentation
253
+ */
254
+ getDeprecationNotice(version: string): string | null {
255
+ const info = this.check(version);
256
+ if (!info.deprecated) return null;
257
+
258
+ let notice = \`This API version (\${version}) is deprecated.\`;
259
+
260
+ if (info.sunsetDate) {
261
+ notice += \` It will be removed on \${info.sunsetDate.toISOString().split('T')[0]}.\`;
262
+ }
263
+
264
+ if (info.replacementVersion) {
265
+ notice += \` Please migrate to version \${info.replacementVersion}.\`;
266
+ }
267
+
268
+ return notice;
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Deprecated decorator for marking deprecated endpoints
274
+ */
275
+ export function Deprecated(options?: {
276
+ version?: string;
277
+ replacement?: string;
278
+ sunsetDate?: Date;
279
+ }): MethodDecorator {
280
+ return function (
281
+ target: any,
282
+ propertyKey: string | symbol,
283
+ descriptor: PropertyDescriptor,
284
+ ) {
285
+ Reflect.defineMetadata('deprecated', true, target, propertyKey);
286
+ Reflect.defineMetadata('deprecatedOptions', options || {}, target, propertyKey);
287
+ return descriptor;
288
+ };
289
+ }
290
+ `;
291
+ }
292
+ function generateVersionedDecorator() {
293
+ return `import { Controller, applyDecorators, SetMetadata } from '@nestjs/common';
294
+ import { ApiTags, ApiHeader } from '@nestjs/swagger';
295
+
296
+ /**
297
+ * Versioned controller decorator
298
+ * Creates a controller with version prefix
299
+ */
300
+ export function VersionedController(
301
+ path: string,
302
+ version: string | string[],
303
+ options?: { deprecated?: boolean },
304
+ ): ClassDecorator {
305
+ const versions = Array.isArray(version) ? version : [version];
306
+
307
+ return applyDecorators(
308
+ Controller({
309
+ path,
310
+ version: versions,
311
+ }),
312
+ SetMetadata('apiVersion', versions),
313
+ ApiTags(\`v\${versions.join(', v')} - \${path}\`),
314
+ ApiHeader({
315
+ name: 'X-API-Version',
316
+ description: 'API version',
317
+ required: false,
318
+ }),
319
+ ...(options?.deprecated
320
+ ? [SetMetadata('deprecated', true)]
321
+ : []),
322
+ );
323
+ }
324
+
325
+ /**
326
+ * Version decorator for individual endpoints
327
+ */
328
+ export function Version(version: string | string[]): MethodDecorator {
329
+ return SetMetadata('version', Array.isArray(version) ? version : [version]);
330
+ }
331
+
332
+ /**
333
+ * Sunset decorator for endpoints being removed
334
+ */
335
+ export function Sunset(date: Date, message?: string): MethodDecorator {
336
+ return function (
337
+ target: any,
338
+ propertyKey: string | symbol,
339
+ descriptor: PropertyDescriptor,
340
+ ) {
341
+ Reflect.defineMetadata('sunsetDate', date, target, propertyKey);
342
+ Reflect.defineMetadata('sunsetMessage', message, target, propertyKey);
343
+ return descriptor;
344
+ };
345
+ }
346
+
347
+ /**
348
+ * Since decorator for documenting when an endpoint was added
349
+ */
350
+ export function Since(version: string): MethodDecorator {
351
+ return SetMetadata('sinceVersion', version);
352
+ }
353
+
354
+ /**
355
+ * Until decorator for documenting when an endpoint will be removed
356
+ */
357
+ export function Until(version: string): MethodDecorator {
358
+ return SetMetadata('untilVersion', version);
359
+ }
360
+ `;
361
+ }
362
+ function generateDtoMigrator() {
363
+ return `import { Injectable, Logger } from '@nestjs/common';
364
+
365
+ /**
366
+ * DTO Migrator
367
+ * Handles transformation between different API versions
368
+ */
369
+ @Injectable()
370
+ export class DtoMigrator {
371
+ private readonly logger = new Logger(DtoMigrator.name);
372
+ private readonly migrations = new Map<string, MigrationDefinition[]>();
373
+
374
+ /**
375
+ * Register a migration between versions
376
+ */
377
+ register<TFrom, TTo>(
378
+ dtoName: string,
379
+ fromVersion: string,
380
+ toVersion: string,
381
+ migrate: (data: TFrom) => TTo,
382
+ rollback?: (data: TTo) => TFrom,
383
+ ): void {
384
+ const key = \`\${dtoName}:\${fromVersion}:\${toVersion}\`;
385
+ const existing = this.migrations.get(dtoName) || [];
386
+
387
+ existing.push({
388
+ fromVersion,
389
+ toVersion,
390
+ migrate,
391
+ rollback,
392
+ });
393
+
394
+ this.migrations.set(dtoName, existing);
395
+ this.logger.debug(\`Registered migration: \${key}\`);
396
+ }
397
+
398
+ /**
399
+ * Migrate DTO from one version to another
400
+ */
401
+ migrate<T>(dtoName: string, data: any, fromVersion: string, toVersion: string): T {
402
+ if (fromVersion === toVersion) {
403
+ return data as T;
404
+ }
405
+
406
+ const migrations = this.migrations.get(dtoName);
407
+ if (!migrations) {
408
+ this.logger.warn(\`No migrations found for \${dtoName}\`);
409
+ return data as T;
410
+ }
411
+
412
+ // Find migration path
413
+ const path = this.findMigrationPath(migrations, fromVersion, toVersion);
414
+ if (!path.length) {
415
+ throw new Error(\`No migration path found from v\${fromVersion} to v\${toVersion} for \${dtoName}\`);
416
+ }
417
+
418
+ // Apply migrations in sequence
419
+ let result = data;
420
+ for (const migration of path) {
421
+ result = migration.migrate(result);
422
+ }
423
+
424
+ return result as T;
425
+ }
426
+
427
+ /**
428
+ * Rollback DTO from newer version to older
429
+ */
430
+ rollback<T>(dtoName: string, data: any, fromVersion: string, toVersion: string): T {
431
+ if (fromVersion === toVersion) {
432
+ return data as T;
433
+ }
434
+
435
+ const migrations = this.migrations.get(dtoName);
436
+ if (!migrations) {
437
+ return data as T;
438
+ }
439
+
440
+ // Find rollback path (reverse)
441
+ const path = this.findMigrationPath(migrations, toVersion, fromVersion);
442
+ if (!path.length) {
443
+ throw new Error(\`No rollback path found from v\${fromVersion} to v\${toVersion} for \${dtoName}\`);
444
+ }
445
+
446
+ // Apply rollbacks in reverse sequence
447
+ let result = data;
448
+ for (const migration of path.reverse()) {
449
+ if (!migration.rollback) {
450
+ throw new Error(\`Rollback not supported for \${dtoName} migration\`);
451
+ }
452
+ result = migration.rollback(result);
453
+ }
454
+
455
+ return result as T;
456
+ }
457
+
458
+ private findMigrationPath(
459
+ migrations: MigrationDefinition[],
460
+ fromVersion: string,
461
+ toVersion: string,
462
+ ): MigrationDefinition[] {
463
+ // Simple linear path finding (for more complex scenarios, use graph algorithms)
464
+ const path: MigrationDefinition[] = [];
465
+ let currentVersion = fromVersion;
466
+
467
+ while (currentVersion !== toVersion) {
468
+ const migration = migrations.find(m => m.fromVersion === currentVersion);
469
+ if (!migration) break;
470
+
471
+ path.push(migration);
472
+ currentVersion = migration.toVersion;
473
+ }
474
+
475
+ return path;
476
+ }
477
+ }
478
+
479
+ interface MigrationDefinition {
480
+ fromVersion: string;
481
+ toVersion: string;
482
+ migrate: (data: any) => any;
483
+ rollback?: (data: any) => any;
484
+ }
485
+
486
+ /**
487
+ * DTO version decorator
488
+ */
489
+ export function DtoVersion(version: string): ClassDecorator {
490
+ return function (target: Function) {
491
+ Reflect.defineMetadata('dtoVersion', version, target);
492
+ };
493
+ }
494
+
495
+ /**
496
+ * Property migration decorator
497
+ */
498
+ export function Migrated(options: {
499
+ from?: string;
500
+ to?: string;
501
+ transformer?: (value: any) => any;
502
+ }): PropertyDecorator {
503
+ return function (target: Object, propertyKey: string | symbol) {
504
+ const existing = Reflect.getMetadata('migratedProperties', target.constructor) || [];
505
+ existing.push({ propertyKey, ...options });
506
+ Reflect.defineMetadata('migratedProperties', existing, target.constructor);
507
+ };
508
+ }
509
+ `;
510
+ }
511
+ function generateVersionRegistry() {
512
+ return `import { Injectable, Inject, Logger } from '@nestjs/common';
513
+
514
+ /**
515
+ * Version Registry
516
+ * Tracks API versions and their metadata
517
+ */
518
+ @Injectable()
519
+ export class VersionRegistry {
520
+ private readonly logger = new Logger(VersionRegistry.name);
521
+ private readonly versions = new Map<string, VersionMetadata>();
522
+
523
+ constructor(@Inject('VERSIONING_OPTIONS') private readonly options: any) {
524
+ this.initializeVersions();
525
+ }
526
+
527
+ private initializeVersions(): void {
528
+ for (const version of this.options.supportedVersions) {
529
+ this.versions.set(version, {
530
+ version,
531
+ status: this.getVersionStatus(version),
532
+ releaseDate: new Date(), // Should be loaded from config
533
+ endpoints: [],
534
+ });
535
+ }
536
+ }
537
+
538
+ private getVersionStatus(version: string): VersionStatus {
539
+ if (this.options.deprecatedVersions?.includes(version)) {
540
+ return 'deprecated';
541
+ }
542
+ if (version === this.options.defaultVersion) {
543
+ return 'current';
544
+ }
545
+ return 'supported';
546
+ }
547
+
548
+ /**
549
+ * Register an endpoint for a version
550
+ */
551
+ registerEndpoint(version: string, endpoint: EndpointMetadata): void {
552
+ const versionMeta = this.versions.get(version);
553
+ if (versionMeta) {
554
+ versionMeta.endpoints.push(endpoint);
555
+ }
556
+ }
557
+
558
+ /**
559
+ * Get all versions with their metadata
560
+ */
561
+ getAllVersions(): VersionMetadata[] {
562
+ return Array.from(this.versions.values());
563
+ }
564
+
565
+ /**
566
+ * Get specific version metadata
567
+ */
568
+ getVersion(version: string): VersionMetadata | undefined {
569
+ return this.versions.get(version);
570
+ }
571
+
572
+ /**
573
+ * Check if version is supported
574
+ */
575
+ isSupported(version: string): boolean {
576
+ return this.options.supportedVersions.includes(version);
577
+ }
578
+
579
+ /**
580
+ * Get current/default version
581
+ */
582
+ getCurrentVersion(): string {
583
+ return this.options.defaultVersion;
584
+ }
585
+
586
+ /**
587
+ * Generate version documentation
588
+ */
589
+ generateDocs(): VersionDocumentation {
590
+ return {
591
+ currentVersion: this.options.defaultVersion,
592
+ supportedVersions: this.options.supportedVersions,
593
+ deprecatedVersions: this.options.deprecatedVersions || [],
594
+ versions: this.getAllVersions().map(v => ({
595
+ version: v.version,
596
+ status: v.status,
597
+ releaseDate: v.releaseDate?.toISOString(),
598
+ endpointCount: v.endpoints.length,
599
+ })),
600
+ };
601
+ }
602
+ }
603
+
604
+ export type VersionStatus = 'current' | 'supported' | 'deprecated' | 'sunset';
605
+
606
+ export interface VersionMetadata {
607
+ version: string;
608
+ status: VersionStatus;
609
+ releaseDate?: Date;
610
+ sunsetDate?: Date;
611
+ endpoints: EndpointMetadata[];
612
+ }
613
+
614
+ export interface EndpointMetadata {
615
+ path: string;
616
+ method: string;
617
+ handler: string;
618
+ deprecated?: boolean;
619
+ since?: string;
620
+ until?: string;
621
+ }
622
+
623
+ export interface VersionDocumentation {
624
+ currentVersion: string;
625
+ supportedVersions: string[];
626
+ deprecatedVersions: string[];
627
+ versions: {
628
+ version: string;
629
+ status: VersionStatus;
630
+ releaseDate?: string;
631
+ endpointCount: number;
632
+ }[];
633
+ }
634
+ `;
635
+ }
636
+ // Helper functions
637
+ function toKebabCase(str) {
638
+ return str
639
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
640
+ .replace(/[\s_]+/g, '-')
641
+ .toLowerCase();
642
+ }
643
+ //# sourceMappingURL=api-versioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-versioning.js","sourceRoot":"","sources":["../../src/commands/api-versioning.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaH,gDA2CC;AAtDD,uCAAyB;AACzB,2CAA6B;AAC7B,kDAA0B;AASnB,KAAK,UAAU,kBAAkB,CACtC,QAAgB,EAChB,UAAgC,EAAE;IAElC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC,CAAC;IAEjE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;IAEhE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,6BAA6B;IAC7B,MAAM,aAAa,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACxD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,sBAAsB,CAAC,EAAE,aAAa,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAA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;;;CA0HR,CAAC;AACF,CAAC;AAED,mBAAmB;AACnB,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG;SACP,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;SACnC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,WAAW,EAAE,CAAC;AACnB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Audit Logging & Compliance Framework Generator
3
+ * Generates comprehensive audit trail infrastructure
4
+ */
5
+ export interface AuditLoggingOptions {
6
+ path?: string;
7
+ storage?: 'database' | 'file' | 'elasticsearch';
8
+ }
9
+ export declare function setupAuditLogging(basePath: string, options?: AuditLoggingOptions): Promise<void>;