create-dp-koa 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/package.json +1 -1
  2. package/template/.cursor/rules/00-backend-core.skill.md +1 -1
  3. package/template/.cursor/rules/01-backend-skill-router.skill.md +8 -2
  4. package/template/.cursor/rules/10-backend-api.skill.md +8 -0
  5. package/template/.cursor/rules/11-backend-controller-recipes.skill.md +12 -9
  6. package/template/.cursor/rules/21-backend-service.skill.md +14 -0
  7. package/template/.cursor/rules/30-backend-validation.skill.md +1 -1
  8. package/template/.cursor/rules/40-backend-error-logging.skill.md +9 -5
  9. package/template/.cursor/rules/50-backend-bootstrap-lifecycle.skill.md +4 -4
  10. package/template/.cursor/rules/60-backend-router-registration.skill.md +16 -6
  11. package/template/.cursor/rules/70-backend-middleware.skill.md +2 -2
  12. package/template/.cursor/rules/80-backend-utils-and-libs.skill.md +71 -14
  13. package/template/.cursor/rules/85-backend-plugins.rule.md +4 -4
  14. package/template/.cursor/rules/90-backend-testing.skill.md +26 -0
  15. package/template/.cursor/rules/README.md +2 -2
  16. package/template/.trae/skills/11-backend-controller-recipes.skill.md +12 -9
  17. package/template/.trae/skills/21-backend-service.skill.md +15 -1
  18. package/template/.trae/skills/40-backend-error-logging.skill.md +9 -5
  19. package/template/.trae/skills/80-backend-utils-and-libs.skill.md +77 -8
  20. package/template/.trae/skills/90-backend-testing.skill.md +26 -0
  21. package/template/scripts/sync-template.mjs +20 -0
  22. package/template/src/app.ts +1 -2
  23. package/template/src/{framework/plugins → plugins}/registry.ts +2 -2
  24. package/template/src/plugins/weboffice/http/routes.ts +1 -1
  25. package/template/src/plugins/weboffice/index.ts +3 -3
  26. package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +3 -4
  27. package/template/src/types/ctxState.ts +9 -0
  28. package/template/src/utils/testDataInitializer.ts +1 -1
  29. package/template/tsconfig.json +6 -0
  30. package/template/src/annotations/decorators/ConfigManagement.ts +0 -9
  31. package/template/src/annotations/decorators/DistributedTracing.ts +0 -9
  32. package/template/src/annotations/decorators/EnterprisePerformance.ts +0 -9
  33. package/template/src/annotations/decorators/PerformanceMonitor.ts +0 -32
  34. package/template/src/annotations/decorators/SecurityAudit.ts +0 -9
  35. package/template/src/annotations/index.ts +0 -50
  36. package/template/src/annotations/processors/ConfigManagementProcessor.ts +0 -369
  37. package/template/src/annotations/processors/DistributedTracingProcessor.ts +0 -288
  38. package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +0 -189
  39. package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +0 -101
  40. package/template/src/annotations/processors/SecurityAuditProcessor.ts +0 -345
  41. package/template/src/annotations/processors/SwaggerProcessor.ts +0 -612
  42. package/template/src/annotations/processors/index.ts +0 -10
  43. package/template/src/examples/InterceptorExampleRunner.ts +0 -284
  44. package/template/src/examples/ServiceInterceptorExample.ts +0 -214
  45. package/template/src/examples/cacheExamples.ts +0 -155
  46. package/template/src/framework/decorator/controller.ts +0 -311
  47. package/template/src/framework/decorator/processor/AnnotationDecorators.ts +0 -100
  48. package/template/src/framework/decorator/processor/AnnotationProcessor.ts +0 -160
  49. package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +0 -45
  50. package/template/src/framework/decorator/processor/AnnotationRegistry.ts +0 -117
  51. package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +0 -95
  52. package/template/src/framework/decorator/processor/ProcessorManager.ts +0 -76
  53. package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +0 -126
  54. package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +0 -207
  55. package/template/src/framework/decorator/refactored/DecoratorFactory.ts +0 -99
  56. package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +0 -125
  57. package/template/src/framework/decorator/refactored/DecoratorValidator.ts +0 -128
  58. package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +0 -139
  59. package/template/src/framework/decorator/refactored/index.ts +0 -98
  60. package/template/src/framework/decorator/swagger.ts +0 -150
  61. package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +0 -375
  62. package/template/src/framework/interceptors/ServiceCallInterceptor.ts +0 -348
  63. package/template/src/framework/interceptors/index.ts +0 -19
  64. package/template/src/framework/plugins/types.ts +0 -15
  65. package/template/src/framework/types/ServiceResult.ts +0 -151
  66. package/template/src/framework/types/index.ts +0 -16
  67. package/template/src/framework/utils/CacheManager.ts +0 -430
  68. package/template/src/framework/utils/CacheService.ts +0 -248
  69. package/template/src/framework/utils/DtoValidator.ts +0 -164
  70. package/template/src/framework/utils/MigrationHelper.ts +0 -179
  71. package/template/src/framework/utils/MigrationManager.ts +0 -256
  72. package/template/src/framework/utils/NewRouter.ts +0 -207
  73. package/template/src/framework/utils/TransactionManager.ts +0 -172
  74. package/template/src/framework/utils/bootstrap.ts +0 -445
  75. package/template/src/framework/utils/cache.ts +0 -269
  76. package/template/src/framework/utils/databaseConfig.ts +0 -148
  77. package/template/src/framework/utils/db.ts +0 -39
  78. package/template/src/framework/utils/dbMonitor.ts +0 -106
  79. package/template/src/framework/utils/function.ts +0 -61
  80. package/template/src/framework/utils/gracefulShutdown.ts +0 -131
  81. package/template/src/framework/utils/logger.ts +0 -388
  82. package/template/src/framework/utils/metrics.ts +0 -182
  83. package/template/src/framework/utils/router.ts +0 -417
  84. package/template/src/framework/utils/swagger.ts +0 -184
  85. package/template/src/framework/utils/testDb.ts +0 -19
  86. package/template/src/framework/utils/token.ts +0 -23
  87. package/template/src/framework/utils/transform.ts +0 -17
  88. package/template/src/libs/aokEmailSender.ts +0 -42
  89. package/template/src/libs/captcha.ts +0 -37
  90. package/template/src/libs/cos.ts +0 -45
  91. package/template/src/libs/mCache.ts +0 -7
  92. package/template/src/libs/serviceValidate.ts +0 -3
  93. package/template/src/libs/tecentSms.ts +0 -51
  94. package/template/src/middlewares/a.middleware.ts +0 -6
  95. package/template/src/middlewares/error.middleware.ts +0 -14
  96. package/template/src/middlewares/logging.middleware.ts +0 -187
  97. package/template/src/middlewares/static.middleware.ts +0 -79
  98. package/template/src/middlewares/swagger.middleware.ts +0 -70
  99. package/template/src/middlewares/token.middleware.ts +0 -32
  100. package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +0 -172
  101. package/template/src/migrations/index.ts +0 -6
  102. package/template/src/repository/base/BaseRepository.ts +0 -124
  103. package/template/src/repository/interfaces/IBaseRepository.ts +0 -67
  104. package/template/src/service/base.service.ts +0 -116
@@ -1,348 +0,0 @@
1
- /**
2
- * Service调用拦截器插件
3
- * 用于监控和记录Service方法的完整调用周期
4
- */
5
-
6
- import { logger } from '@src/framework/utils/logger';
7
-
8
- /**
9
- * Service调用周期阶段
10
- */
11
- export enum ServiceCallPhase {
12
- BEFORE_CALL = 'BEFORE_CALL',
13
- METHOD_EXECUTION = 'METHOD_EXECUTION',
14
- AFTER_CALL = 'AFTER_CALL',
15
- ERROR_HANDLING = 'ERROR_HANDLING',
16
- FINALLY = 'FINALLY'
17
- }
18
-
19
- /**
20
- * Service调用信息
21
- */
22
- export interface ServiceCallInfo {
23
- serviceName: string;
24
- methodName: string;
25
- parameters: any[];
26
- startTime: number;
27
- endTime?: number;
28
- duration?: number;
29
- result?: any;
30
- error?: Error;
31
- phase: ServiceCallPhase;
32
- }
33
-
34
- /**
35
- * Service调用统计信息
36
- */
37
- export interface ServiceCallStats {
38
- totalCalls: number;
39
- successCalls: number;
40
- errorCalls: number;
41
- averageDuration: number;
42
- maxDuration: number;
43
- minDuration: number;
44
- methodStats: Map<string, {
45
- calls: number;
46
- successes: number;
47
- errors: number;
48
- avgDuration: number;
49
- }>;
50
- }
51
-
52
- /**
53
- * Service调用拦截器
54
- */
55
- export class ServiceCallInterceptor {
56
- private static instance: ServiceCallInterceptor;
57
- private callHistory: ServiceCallInfo[] = [];
58
- private stats: ServiceCallStats = {
59
- totalCalls: 0,
60
- successCalls: 0,
61
- errorCalls: 0,
62
- averageDuration: 0,
63
- maxDuration: 0,
64
- minDuration: Infinity,
65
- methodStats: new Map()
66
- };
67
- private maxHistorySize = 1000; // 最大历史记录数量
68
-
69
- /**
70
- * 获取单例实例
71
- */
72
- public static getInstance(): ServiceCallInterceptor {
73
- if (!ServiceCallInterceptor.instance) {
74
- ServiceCallInterceptor.instance = new ServiceCallInterceptor();
75
- }
76
- return ServiceCallInterceptor.instance;
77
- }
78
-
79
- /**
80
- * 创建拦截器函数
81
- * 符合dp-ioc2的Interceptor注解要求
82
- */
83
- public createInterceptor() {
84
- return (params: Array<any>, instance: any, fn: Function, done: (err: any, param: any) => void) => {
85
- const serviceName = instance.constructor.name;
86
- const methodName = fn.name;
87
- const startTime = Date.now();
88
-
89
- // 创建调用信息
90
- const callInfo: ServiceCallInfo = {
91
- serviceName,
92
- methodName,
93
- parameters: this.sanitizeParameters([...params]), // 存储脱敏后的参数
94
- startTime,
95
- phase: ServiceCallPhase.BEFORE_CALL
96
- };
97
-
98
- // 记录调用开始
99
- this.logCallStart(callInfo);
100
-
101
- // 更新统计信息
102
- this.updateStats(callInfo, 'start');
103
-
104
- // 执行原方法
105
- try {
106
- const result = fn.apply(instance, params);
107
-
108
- // 处理异步方法
109
- if (result && typeof result.then === 'function') {
110
- result
111
- .then((res: any) => {
112
- callInfo.phase = ServiceCallPhase.AFTER_CALL;
113
- callInfo.endTime = Date.now();
114
- callInfo.duration = callInfo.endTime - callInfo.startTime;
115
- callInfo.result = this.sanitizeResult(res); // 存储脱敏后的结果
116
-
117
- this.logCallSuccess(callInfo);
118
- this.updateStats(callInfo, 'success');
119
- this.addToHistory(callInfo);
120
-
121
- done(null, res);
122
- })
123
- .catch((error: Error) => {
124
- callInfo.phase = ServiceCallPhase.ERROR_HANDLING;
125
- callInfo.endTime = Date.now();
126
- callInfo.duration = callInfo.endTime - callInfo.startTime;
127
- callInfo.error = error;
128
-
129
- this.logCallError(callInfo);
130
- this.updateStats(callInfo, 'error');
131
- this.addToHistory(callInfo);
132
-
133
- done(error, null);
134
- });
135
- } else {
136
- // 处理同步方法
137
- callInfo.phase = ServiceCallPhase.AFTER_CALL;
138
- callInfo.endTime = Date.now();
139
- callInfo.duration = callInfo.endTime - callInfo.startTime;
140
- callInfo.result = this.sanitizeResult(result); // 存储脱敏后的结果
141
-
142
- this.logCallSuccess(callInfo);
143
- this.updateStats(callInfo, 'success');
144
- this.addToHistory(callInfo);
145
-
146
- done(null, result);
147
- }
148
- } catch (error) {
149
- callInfo.phase = ServiceCallPhase.ERROR_HANDLING;
150
- callInfo.endTime = Date.now();
151
- callInfo.duration = callInfo.endTime - callInfo.startTime;
152
- callInfo.error = error as Error;
153
-
154
- this.logCallError(callInfo);
155
- this.updateStats(callInfo, 'error');
156
- this.addToHistory(callInfo);
157
-
158
- done(error, null);
159
- }
160
- };
161
- }
162
-
163
- /**
164
- * 记录调用开始
165
- */
166
- private logCallStart(callInfo: ServiceCallInfo): void {
167
- logger.info(`🚀 Service调用开始: ${callInfo.serviceName}.${callInfo.methodName}`,
168
- `参数: ${JSON.stringify(this.sanitizeParameters(callInfo.parameters))}, 时间: ${new Date(callInfo.startTime).toISOString()}`);
169
- }
170
-
171
- /**
172
- * 记录调用成功
173
- */
174
- private logCallSuccess(callInfo: ServiceCallInfo): void {
175
- logger.info(`✅ Service调用成功: ${callInfo.serviceName}.${callInfo.methodName}`,
176
- `耗时: ${callInfo.duration}ms, 结果: ${JSON.stringify(this.sanitizeResult(callInfo.result))}, 时间: ${new Date(callInfo.endTime!).toISOString()}`);
177
- }
178
-
179
- /**
180
- * 记录调用错误
181
- */
182
- private logCallError(callInfo: ServiceCallInfo): void {
183
- logger.error(`❌ Service调用失败: ${callInfo.serviceName}.${callInfo.methodName}`,
184
- callInfo.error, `耗时: ${callInfo.duration}ms, 时间: ${new Date(callInfo.endTime!).toISOString()}`);
185
- }
186
-
187
- /**
188
- * 更新统计信息
189
- */
190
- private updateStats(callInfo: ServiceCallInfo, event: 'start' | 'success' | 'error'): void {
191
- if (event === 'start') {
192
- this.stats.totalCalls++;
193
- } else if (event === 'success') {
194
- this.stats.successCalls++;
195
- } else if (event === 'error') {
196
- this.stats.errorCalls++;
197
- }
198
-
199
- // 更新方法统计
200
- const methodKey = `${callInfo.serviceName}.${callInfo.methodName}`;
201
- if (!this.stats.methodStats.has(methodKey)) {
202
- this.stats.methodStats.set(methodKey, {
203
- calls: 0,
204
- successes: 0,
205
- errors: 0,
206
- avgDuration: 0
207
- });
208
- }
209
-
210
- const methodStat = this.stats.methodStats.get(methodKey)!;
211
- if (event === 'start') {
212
- methodStat.calls++;
213
- } else if (event === 'success') {
214
- methodStat.successes++;
215
- methodStat.avgDuration = (methodStat.avgDuration * (methodStat.successes - 1) + callInfo.duration!) / methodStat.successes;
216
- } else if (event === 'error') {
217
- methodStat.errors++;
218
- }
219
-
220
- // 更新全局统计
221
- if (callInfo.duration) {
222
- this.stats.maxDuration = Math.max(this.stats.maxDuration, callInfo.duration);
223
- this.stats.minDuration = Math.min(this.stats.minDuration, callInfo.duration);
224
- this.stats.averageDuration = (this.stats.averageDuration * (this.stats.successCalls - 1) + callInfo.duration) / this.stats.successCalls;
225
- }
226
- }
227
-
228
- /**
229
- * 添加到历史记录
230
- */
231
- private addToHistory(callInfo: ServiceCallInfo): void {
232
- this.callHistory.push(callInfo);
233
-
234
- // 限制历史记录大小
235
- if (this.callHistory.length > this.maxHistorySize) {
236
- this.callHistory.shift();
237
- }
238
- }
239
-
240
- /**
241
- * 清理敏感参数
242
- */
243
- private sanitizeParameters(params: any[]): any[] {
244
- return params.map(param => {
245
- if (typeof param === 'object' && param !== null) {
246
- const sanitized = { ...param };
247
- // 移除敏感字段
248
- if ('password' in sanitized) sanitized.password = '***';
249
- if ('token' in sanitized) sanitized.token = '***';
250
- if ('secret' in sanitized) sanitized.secret = '***';
251
- return sanitized;
252
- }
253
- return param;
254
- });
255
- }
256
-
257
- /**
258
- * 清理敏感结果
259
- */
260
- private sanitizeResult(result: any): any {
261
- if (typeof result === 'object' && result !== null) {
262
- const sanitized = { ...result };
263
- if ('password' in sanitized) sanitized.password = '***';
264
- if ('token' in sanitized) sanitized.token = '***';
265
- if ('secret' in sanitized) sanitized.secret = '***';
266
- return sanitized;
267
- }
268
- return result;
269
- }
270
-
271
- /**
272
- * 获取调用历史
273
- */
274
- public getCallHistory(): ServiceCallInfo[] {
275
- return [...this.callHistory];
276
- }
277
-
278
- /**
279
- * 获取统计信息
280
- */
281
- public getStats(): ServiceCallStats {
282
- return { ...this.stats };
283
- }
284
-
285
- /**
286
- * 获取方法统计
287
- */
288
- public getMethodStats(methodKey: string): any {
289
- return this.stats.methodStats.get(methodKey);
290
- }
291
-
292
- /**
293
- * 清空历史记录
294
- */
295
- public clearHistory(): void {
296
- this.callHistory = [];
297
- }
298
-
299
- /**
300
- * 重置统计信息
301
- */
302
- public resetStats(): void {
303
- this.stats = {
304
- totalCalls: 0,
305
- successCalls: 0,
306
- errorCalls: 0,
307
- averageDuration: 0,
308
- maxDuration: 0,
309
- minDuration: Infinity,
310
- methodStats: new Map()
311
- };
312
- }
313
-
314
- /**
315
- * 生成调用报告
316
- */
317
- public generateReport(): string {
318
- const stats = this.getStats();
319
- const report = `
320
- 📊 Service调用统计报告
321
- ====================
322
- 总调用次数: ${stats.totalCalls}
323
- 成功调用: ${stats.successCalls}
324
- 失败调用: ${stats.errorCalls}
325
- 成功率: ${stats.totalCalls > 0 ? ((stats.successCalls / stats.totalCalls) * 100).toFixed(2) : 0}%
326
- 平均耗时: ${stats.averageDuration.toFixed(2)}ms
327
- 最大耗时: ${stats.maxDuration}ms
328
- 最小耗时: ${stats.minDuration === Infinity ? 0 : stats.minDuration}ms
329
-
330
- 📈 方法统计:
331
- ${Array.from(stats.methodStats.entries()).map(([method, stat]) =>
332
- ` ${method}: 调用${stat.calls}次, 成功${stat.successes}次, 失败${stat.errors}次, 平均${stat.avgDuration.toFixed(2)}ms`
333
- ).join('\n')}
334
- `;
335
-
336
- return report.trim();
337
- }
338
- }
339
-
340
- /**
341
- * 创建拦截器实例
342
- */
343
- export const serviceCallInterceptor = ServiceCallInterceptor.getInstance();
344
-
345
- /**
346
- * 导出拦截器创建函数
347
- */
348
- export const createServiceCallInterceptor = () => serviceCallInterceptor.createInterceptor();
@@ -1,19 +0,0 @@
1
- /**
2
- * 拦截器导出文件
3
- */
4
-
5
- export {
6
- ServiceCallInterceptor,
7
- serviceCallInterceptor,
8
- createServiceCallInterceptor,
9
- ServiceCallPhase,
10
- ServiceCallInfo,
11
- ServiceCallStats
12
- } from './ServiceCallInterceptor';
13
-
14
- export {
15
- AdvancedServiceCallInterceptor,
16
- advancedServiceCallInterceptor,
17
- createAdvancedServiceCallInterceptor,
18
- InterceptorOptions
19
- } from './AdvancedServiceCallInterceptor';
@@ -1,15 +0,0 @@
1
- import type Koa from "koa";
2
- import type Router from "koa-router";
3
-
4
- export interface PluginDescriptor {
5
- id: string;
6
- displayName?: string;
7
- enabled?: boolean | ((env: NodeJS.ProcessEnv) => boolean);
8
-
9
- onBeforeBootstrap?(app: Koa): Promise<void> | void;
10
- onAfterBootstrap?(app: Koa): Promise<void> | void;
11
-
12
- registerRoutes?(router: Router): void;
13
- entities?: Function[];
14
- }
15
-
@@ -1,151 +0,0 @@
1
- /**
2
- * 通用服务结果代码枚举
3
- * 定义所有服务层可能返回的状态码
4
- */
5
- export enum CommonServiceResultCode {
6
- SUCCESS = "SUCCESS",
7
- FAIL = "FAIL",
8
- ERROR = "ERROR",
9
- NOT_FOUND = "NOT_FOUND",
10
- VALIDATION_ERROR = "VALIDATION_ERROR",
11
- UNAUTHORIZED = "UNAUTHORIZED",
12
- FORBIDDEN = "FORBIDDEN",
13
- CONFLICT = "CONFLICT",
14
- TIMEOUT = "TIMEOUT",
15
- RATE_LIMITED = "RATE_LIMITED",
16
- }
17
-
18
- /**
19
- * 通用服务结果类
20
- * 提供统一的服务层返回格式
21
- */
22
- export class CommonServiceResult<T> {
23
- data: T | null;
24
- message?: string;
25
- code: CommonServiceResultCode;
26
-
27
- constructor(code: CommonServiceResultCode, data: T | null = null, message = "") {
28
- this.code = code;
29
- this.data = data;
30
- this.message = message;
31
- }
32
-
33
- /**
34
- * 判断是否成功
35
- */
36
- isSuccess(): boolean {
37
- return this.code === CommonServiceResultCode.SUCCESS;
38
- }
39
-
40
- /**
41
- * 判断是否失败
42
- */
43
- isFailure(): boolean {
44
- return !this.isSuccess();
45
- }
46
-
47
- /**
48
- * 获取错误信息
49
- */
50
- getErrorMessage(): string {
51
- return this.message || this.getDefaultErrorMessage();
52
- }
53
-
54
- /**
55
- * 获取默认错误信息
56
- */
57
- private getDefaultErrorMessage(): string {
58
- switch (this.code) {
59
- case CommonServiceResultCode.NOT_FOUND:
60
- return "资源不存在";
61
- case CommonServiceResultCode.VALIDATION_ERROR:
62
- return "数据验证失败";
63
- case CommonServiceResultCode.UNAUTHORIZED:
64
- return "未授权访问";
65
- case CommonServiceResultCode.FORBIDDEN:
66
- return "禁止访问";
67
- case CommonServiceResultCode.CONFLICT:
68
- return "资源冲突";
69
- case CommonServiceResultCode.TIMEOUT:
70
- return "请求超时";
71
- case CommonServiceResultCode.RATE_LIMITED:
72
- return "请求频率过高";
73
- case CommonServiceResultCode.ERROR:
74
- return "服务器内部错误";
75
- case CommonServiceResultCode.FAIL:
76
- return "操作失败";
77
- default:
78
- return "未知错误";
79
- }
80
- }
81
-
82
- /**
83
- * 创建成功结果
84
- */
85
- static success<T>(data: T, message?: string): CommonServiceResult<T> {
86
- return new CommonServiceResult(CommonServiceResultCode.SUCCESS, data, message);
87
- }
88
-
89
- /**
90
- * 创建失败结果
91
- */
92
- static fail<T>(code: CommonServiceResultCode, message?: string, data: T | null = null): CommonServiceResult<T> {
93
- return new CommonServiceResult(code, data, message);
94
- }
95
-
96
- /**
97
- * 创建验证错误结果
98
- */
99
- static validationError<T>(message: string, data: T | null = null): CommonServiceResult<T> {
100
- return new CommonServiceResult(CommonServiceResultCode.VALIDATION_ERROR, data, message);
101
- }
102
-
103
- /**
104
- * 创建未找到结果
105
- */
106
- static notFound<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
107
- return new CommonServiceResult(CommonServiceResultCode.NOT_FOUND, data, message);
108
- }
109
-
110
- /**
111
- * 创建未授权结果
112
- */
113
- static unauthorized<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
114
- return new CommonServiceResult(CommonServiceResultCode.UNAUTHORIZED, data, message);
115
- }
116
-
117
- /**
118
- * 创建禁止访问结果
119
- */
120
- static forbidden<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
121
- return new CommonServiceResult(CommonServiceResultCode.FORBIDDEN, data, message);
122
- }
123
-
124
- /**
125
- * 创建冲突结果
126
- */
127
- static conflict<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
128
- return new CommonServiceResult(CommonServiceResultCode.CONFLICT, data, message);
129
- }
130
-
131
- /**
132
- * 创建超时结果
133
- */
134
- static timeout<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
135
- return new CommonServiceResult(CommonServiceResultCode.TIMEOUT, data, message);
136
- }
137
-
138
- /**
139
- * 创建限流结果
140
- */
141
- static rateLimited<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
142
- return new CommonServiceResult(CommonServiceResultCode.RATE_LIMITED, data, message);
143
- }
144
-
145
- /**
146
- * 创建服务器错误结果
147
- */
148
- static error<T>(message?: string, data: T | null = null): CommonServiceResult<T> {
149
- return new CommonServiceResult(CommonServiceResultCode.ERROR, data, message);
150
- }
151
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * 框架通用类型导出
3
- * 提供统一的类型定义和导出
4
- */
5
-
6
- // 服务结果类型
7
- export { CommonServiceResultCode, CommonServiceResult } from './ServiceResult';
8
-
9
- // 缓存相关类型
10
- export { ICache } from '../utils/CacheManager';
11
-
12
- // DTO 验证类型
13
- export { ValidationResult } from '../utils/DtoValidator';
14
-
15
- // 数据库相关类型
16
- export { IBaseRepository } from '../../repository/interfaces/IBaseRepository';